Skip to content

Commit

Permalink
Merge pull request #498 from coasys/client-literal-get
Browse files Browse the repository at this point in the history
Process expression.get() on client for literals (no signature checking)
  • Loading branch information
fayeed authored Jul 5, 2024
2 parents 6926661 + d4a79af commit 18c5792
Show file tree
Hide file tree
Showing 2 changed files with 15 additions and 1 deletion.
1 change: 1 addition & 0 deletions CHANGELOG
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,7 @@ The format is based on [Keep a Changelog](https://keepachangelog.com/en/1.0.0/).
This project _loosely_ adheres to [Semantic Versioning](https://semver.org/spec/v2.0.0.html). More specifically:

## unreleased
- ad4m.expression.get() handles literal values client-side to avoid roundtrips, can be overridden with optional flag [PR#498](https://github.com/coasys/ad4m/pull/498)

### Fixed
- Prolog engine gets respawned when a query caused an error to clean the machine state [PR#483](https://github.com/coasys/ad4m/pull/483)
Expand Down
15 changes: 14 additions & 1 deletion core/src/expression/ExpressionClient.ts
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,7 @@ import { ApolloClient, gql } from "@apollo/client/core";
import { InteractionCall, InteractionMeta } from "../language/Language";
import unwrapApolloResult from "../unwrapApolloResult";
import { ExpressionRendered } from "./Expression";
import { Literal } from "../Literal";

export class ExpressionClient {
#apolloClient: ApolloClient<any>
Expand All @@ -10,7 +11,19 @@ export class ExpressionClient {
this.#apolloClient = client
}

async get(url: string): Promise<ExpressionRendered> {
async get(url: string, alwaysGet: boolean = false): Promise<ExpressionRendered> {
if(!alwaysGet){
try {
let literalValue = Literal.fromUrl(url).get();
if (typeof literalValue === 'object' && literalValue !== null) {
if ('author' in literalValue && 'timestamp' in literalValue && 'data' in literalValue && 'proof' in literalValue) {
return literalValue;
}
}
} catch(e) {}
}


const { expression } = unwrapApolloResult(await this.#apolloClient.query({
query: gql`query expression($url: String!) {
expression(url: $url) {
Expand Down

0 comments on commit 18c5792

Please sign in to comment.