@coasys/ad4m 0.13.0-test-1 → 0.13.0-test-3
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/lib/index.cjs +2377 -849
- package/lib/index.js +2354 -846
- package/lib/src/Literal.js +6 -5
- package/lib/src/agent/AgentClient.d.ts +5 -1
- package/lib/src/agent/AgentClient.js +48 -2
- package/lib/src/expression/ExpressionRef.js +2 -2
- package/lib/src/index.d.ts +0 -1
- package/lib/src/index.js +0 -1
- package/lib/src/language/Language.d.ts +26 -176
- package/lib/src/language/Language.js +28 -2
- package/lib/src/model/Ad4mModel.d.ts +52 -28
- package/lib/src/model/Ad4mModel.js +255 -118
- package/lib/src/model/Ad4mModel.test.js +1727 -537
- package/lib/src/model/ModelQueryBuilder.d.ts +67 -34
- package/lib/src/model/ModelQueryBuilder.js +208 -79
- package/lib/src/model/Subject.js +6 -6
- package/lib/src/model/decorators.d.ts +14 -8
- package/lib/src/model/decorators.js +41 -14
- package/lib/src/model/hydration-batch.d.ts +34 -0
- package/lib/src/model/hydration-batch.js +147 -0
- package/lib/src/model/hydration-batching.test.d.ts +7 -0
- package/lib/src/model/hydration-batching.test.js +456 -0
- package/lib/src/model/hydration.d.ts +4 -3
- package/lib/src/model/hydration.js +365 -86
- package/lib/src/model/index.d.ts +4 -1
- package/lib/src/model/index.js +4 -1
- package/lib/src/model/json-schema.js +2 -2
- package/lib/src/model/query-cache.d.ts +30 -0
- package/lib/src/model/query-cache.js +66 -0
- package/lib/src/model/query-cache.test.d.ts +1 -0
- package/lib/src/model/query-cache.test.js +43 -0
- package/lib/src/model/query-common.d.ts +1 -1
- package/lib/src/model/query-common.js +1 -1
- package/lib/src/model/query-sparql-batch.d.ts +17 -0
- package/lib/src/model/query-sparql-batch.js +260 -0
- package/lib/src/model/query-sparql.d.ts +124 -0
- package/lib/src/model/query-sparql.js +767 -0
- package/lib/src/model/query-sparql.test.d.ts +1 -0
- package/lib/src/model/query-sparql.test.js +495 -0
- package/lib/src/model/{surreal-utils.d.ts → query-utils.d.ts} +12 -9
- package/lib/src/model/{surreal-utils.js → query-utils.js} +43 -27
- package/lib/src/model/relation-filtering.test.js +15 -15
- package/lib/src/model/sdna.js +1 -1
- package/lib/src/model/shacl-gen.js +42 -18
- package/lib/src/model/subscription-delta.test.d.ts +24 -0
- package/lib/src/model/subscription-delta.test.js +180 -0
- package/lib/src/model/subscription-pool.d.ts +39 -0
- package/lib/src/model/subscription-pool.js +165 -0
- package/lib/src/model/types.d.ts +52 -4
- package/lib/src/model/types.js +1 -1
- package/lib/src/perspectives/PerspectiveClient.d.ts +3 -17
- package/lib/src/perspectives/PerspectiveClient.js +42 -66
- package/lib/src/perspectives/PerspectiveClient.test.d.ts +1 -0
- package/lib/src/perspectives/PerspectiveClient.test.js +169 -0
- package/lib/src/perspectives/PerspectiveProxy.d.ts +54 -30
- package/lib/src/perspectives/PerspectiveProxy.js +239 -177
- package/lib/src/perspectives/PerspectiveResolver.d.ts +0 -1
- package/lib/src/perspectives/PerspectiveResolver.js +0 -11
- package/lib/src/perspectives/WakerSubscriptionManager.d.ts +3 -3
- package/lib/src/perspectives/WakerSubscriptionManager.js +7 -8
- package/lib/src/runtime/RuntimeResolver.d.ts +11 -0
- package/lib/src/runtime/RuntimeResolver.js +56 -0
- package/lib/src/schema.gql +11 -1
- package/lib/src/shacl/SHACLFlow.d.ts +1 -1
- package/lib/src/shacl/SHACLFlow.js +9 -9
- package/lib/src/shacl/SHACLShape.d.ts +1 -1
- package/lib/src/shacl/SHACLShape.js +38 -38
- package/lib/src/typeDefs.js +11 -1
- package/lib/src/utils.d.ts +6 -6
- package/lib/src/utils.js +6 -6
- package/package.json +1 -1
- package/src/Ad4mClient.test.ts +56 -1
- package/src/Literal.test.ts +10 -5
- package/src/Literal.ts +6 -5
- package/src/agent/AgentClient.ts +53 -1
- package/src/expression/ExpressionRef.ts +2 -2
- package/src/index.ts +0 -1
- package/src/language/Language.ts +55 -231
- package/src/model/Ad4mModel.test.ts +1709 -572
- package/src/model/Ad4mModel.ts +274 -120
- package/src/model/ModelQueryBuilder.ts +234 -87
- package/src/model/Subject.ts +6 -6
- package/src/model/decorators.ts +51 -22
- package/src/model/hydration-batch.ts +205 -0
- package/src/model/hydration-batching.test.ts +563 -0
- package/src/model/hydration.ts +349 -84
- package/src/model/index.ts +4 -1
- package/src/model/json-schema.ts +2 -2
- package/src/model/query-cache.test.ts +54 -0
- package/src/model/query-cache.ts +79 -0
- package/src/model/query-common.ts +1 -1
- package/src/model/query-sparql-batch.ts +301 -0
- package/src/model/query-sparql.test.ts +568 -0
- package/src/model/query-sparql.ts +820 -0
- package/src/model/{surreal-utils.ts → query-utils.ts} +44 -27
- package/src/model/relation-filtering.test.ts +15 -15
- package/src/model/sdna.ts +1 -1
- package/src/model/shacl-gen.ts +42 -17
- package/src/model/subscription-delta.test.ts +207 -0
- package/src/model/subscription-pool.ts +211 -0
- package/src/model/types.ts +53 -4
- package/src/perspectives/PerspectiveClient.test.ts +204 -0
- package/src/perspectives/PerspectiveClient.ts +41 -68
- package/src/perspectives/PerspectiveProxy.ts +244 -181
- package/src/perspectives/PerspectiveResolver.ts +0 -8
- package/src/perspectives/WakerSubscriptionManager.ts +8 -9
- package/src/runtime/RuntimeResolver.ts +43 -0
- package/src/shacl/SHACLFlow.ts +9 -9
- package/src/shacl/SHACLShape.ts +39 -39
- package/src/utils.ts +6 -6
- package/lib/src/model/query-surreal.d.ts +0 -44
- package/lib/src/model/query-surreal.js +0 -249
- package/src/language/LanguageContext.ts +0 -37
- package/src/model/query-surreal.ts +0 -280
- package/tsconfig-browser.json +0 -82
package/lib/src/utils.d.ts
CHANGED
|
@@ -1,25 +1,25 @@
|
|
|
1
1
|
export declare function formatList(list: any): any;
|
|
2
2
|
export declare function capSentence(cap: any): string;
|
|
3
3
|
/**
|
|
4
|
-
* Escapes a string value for safe use in
|
|
4
|
+
* Escapes a string value for safe use in query strings.
|
|
5
5
|
*
|
|
6
6
|
* @description
|
|
7
7
|
* Prevents SQL injection by properly escaping special characters in string values
|
|
8
|
-
* that will be interpolated into
|
|
8
|
+
* that will be interpolated into query strings. This handles the most common
|
|
9
9
|
* special characters that could break SQL queries or enable injection attacks.
|
|
10
10
|
*
|
|
11
11
|
* Single quotes, backslashes, and other special characters are escaped using
|
|
12
|
-
* backslash notation, which is the standard escaping mechanism for
|
|
12
|
+
* backslash notation, which is the standard escaping mechanism for query.
|
|
13
13
|
*
|
|
14
14
|
* @param value - The string value to escape
|
|
15
|
-
* @returns The escaped string safe for
|
|
15
|
+
* @returns The escaped string safe for query interpolation (without surrounding quotes)
|
|
16
16
|
*
|
|
17
17
|
* @example
|
|
18
18
|
* ```typescript
|
|
19
19
|
* const userInput = "user's input with 'quotes'";
|
|
20
|
-
* const escaped =
|
|
20
|
+
* const escaped = escapeQueryString(userInput);
|
|
21
21
|
* const query = `SELECT * FROM link WHERE uri = '${escaped}'`;
|
|
22
22
|
* // Results in: SELECT * FROM link WHERE uri = 'user\'s input with \'quotes\''
|
|
23
23
|
* ```
|
|
24
24
|
*/
|
|
25
|
-
export declare function
|
|
25
|
+
export declare function escapeQueryString(value: string): string;
|
package/lib/src/utils.js
CHANGED
|
@@ -20,28 +20,28 @@ export function capSentence(cap) {
|
|
|
20
20
|
return `${formatList(can)} your ${domain} actions, with access to ${formatList(pointers)}`;
|
|
21
21
|
}
|
|
22
22
|
/**
|
|
23
|
-
* Escapes a string value for safe use in
|
|
23
|
+
* Escapes a string value for safe use in query strings.
|
|
24
24
|
*
|
|
25
25
|
* @description
|
|
26
26
|
* Prevents SQL injection by properly escaping special characters in string values
|
|
27
|
-
* that will be interpolated into
|
|
27
|
+
* that will be interpolated into query strings. This handles the most common
|
|
28
28
|
* special characters that could break SQL queries or enable injection attacks.
|
|
29
29
|
*
|
|
30
30
|
* Single quotes, backslashes, and other special characters are escaped using
|
|
31
|
-
* backslash notation, which is the standard escaping mechanism for
|
|
31
|
+
* backslash notation, which is the standard escaping mechanism for query.
|
|
32
32
|
*
|
|
33
33
|
* @param value - The string value to escape
|
|
34
|
-
* @returns The escaped string safe for
|
|
34
|
+
* @returns The escaped string safe for query interpolation (without surrounding quotes)
|
|
35
35
|
*
|
|
36
36
|
* @example
|
|
37
37
|
* ```typescript
|
|
38
38
|
* const userInput = "user's input with 'quotes'";
|
|
39
|
-
* const escaped =
|
|
39
|
+
* const escaped = escapeQueryString(userInput);
|
|
40
40
|
* const query = `SELECT * FROM link WHERE uri = '${escaped}'`;
|
|
41
41
|
* // Results in: SELECT * FROM link WHERE uri = 'user\'s input with \'quotes\''
|
|
42
42
|
* ```
|
|
43
43
|
*/
|
|
44
|
-
export function
|
|
44
|
+
export function escapeQueryString(value) {
|
|
45
45
|
return value
|
|
46
46
|
.replace(/\\/g, '\\\\') // Backslash -> \\
|
|
47
47
|
.replace(/'/g, "\\'") // Single quote -> \'
|
package/package.json
CHANGED
package/src/Ad4mClient.test.ts
CHANGED
|
@@ -32,6 +32,19 @@ import { PerspectiveState } from "./perspectives/PerspectiveHandle";
|
|
|
32
32
|
|
|
33
33
|
jest.setTimeout(15000)
|
|
34
34
|
|
|
35
|
+
/** Wait for a mock function to reach the expected call count (with timeout). */
|
|
36
|
+
async function waitForCalls(fn: jest.Mock, count: number, timeoutMs = 2000): Promise<void> {
|
|
37
|
+
const start = Date.now();
|
|
38
|
+
while (fn.mock.calls.length < count) {
|
|
39
|
+
if (Date.now() - start > timeoutMs) {
|
|
40
|
+
throw new Error(
|
|
41
|
+
`waitForCalls timed out after ${timeoutMs}ms: expected ${count} calls but received ${fn.mock.calls.length}`
|
|
42
|
+
);
|
|
43
|
+
}
|
|
44
|
+
await new Promise(r => setTimeout(r, 50));
|
|
45
|
+
}
|
|
46
|
+
}
|
|
47
|
+
|
|
35
48
|
async function createGqlServer(port: number) {
|
|
36
49
|
const schema = await buildSchema({
|
|
37
50
|
resolvers: [
|
|
@@ -730,6 +743,7 @@ describe('Ad4mClient', () => {
|
|
|
730
743
|
link.target = 'perspective://Qm34589a3ccc0'
|
|
731
744
|
await perspective.add(link)
|
|
732
745
|
|
|
746
|
+
await waitForCalls(linkAdded, 1)
|
|
733
747
|
expect(linkAdded).toBeCalledTimes(1)
|
|
734
748
|
expect(linkRemoved).toBeCalledTimes(0)
|
|
735
749
|
|
|
@@ -738,6 +752,7 @@ describe('Ad4mClient', () => {
|
|
|
738
752
|
await perspective.addListener('link-removed', linkRemoved)
|
|
739
753
|
await perspective.remove(testLink)
|
|
740
754
|
|
|
755
|
+
await waitForCalls(linkRemoved, 1)
|
|
741
756
|
expect(linkAdded).toBeCalledTimes(1)
|
|
742
757
|
expect(linkRemoved).toBeCalledTimes(1)
|
|
743
758
|
})
|
|
@@ -750,6 +765,7 @@ describe('Ad4mClient', () => {
|
|
|
750
765
|
await perspective.addListener('link-added', linkAdded)
|
|
751
766
|
await perspective.add({source: 'root', target: 'neighbourhood://Qm12345'})
|
|
752
767
|
|
|
768
|
+
await waitForCalls(linkAdded, 1)
|
|
753
769
|
expect(linkAdded).toBeCalledTimes(1)
|
|
754
770
|
|
|
755
771
|
linkAdded.mockClear();
|
|
@@ -759,7 +775,10 @@ describe('Ad4mClient', () => {
|
|
|
759
775
|
await perspective.removeListener('link-added', linkAdded)
|
|
760
776
|
await perspective.add({source: 'root', target: 'neighbourhood://Qm123456'})
|
|
761
777
|
|
|
762
|
-
|
|
778
|
+
// With proxy caching, removeListener operates on the same proxy,
|
|
779
|
+
// so the callback should NOT fire after removal.
|
|
780
|
+
await new Promise<void>(resolve => setTimeout(resolve, 500))
|
|
781
|
+
expect(linkAdded).toBeCalledTimes(0)
|
|
763
782
|
})
|
|
764
783
|
|
|
765
784
|
it('addSyncStateChangeListener() smoke test', async () => {
|
|
@@ -770,6 +789,7 @@ describe('Ad4mClient', () => {
|
|
|
770
789
|
await perspective.addSyncStateChangeListener(syncState)
|
|
771
790
|
await perspective.add({source: 'root', target: 'neighbourhood://Qm12345'})
|
|
772
791
|
|
|
792
|
+
await waitForCalls(syncState, 1)
|
|
773
793
|
expect(syncState).toBeCalledTimes(1)
|
|
774
794
|
expect(syncState).toBeCalledWith(PerspectiveState.Synced)
|
|
775
795
|
})
|
|
@@ -818,6 +838,41 @@ describe('Ad4mClient', () => {
|
|
|
818
838
|
);
|
|
819
839
|
expect(result).toBeTruthy();
|
|
820
840
|
})
|
|
841
|
+
|
|
842
|
+
it('byUUID() returns same reference on repeated calls (proxy cache hit)', async () => {
|
|
843
|
+
const p1 = await ad4mClient.perspective.byUUID('00001')
|
|
844
|
+
const p2 = await ad4mClient.perspective.byUUID('00001')
|
|
845
|
+
expect(p1).toBe(p2) // strict reference equality
|
|
846
|
+
})
|
|
847
|
+
|
|
848
|
+
it('update() then byUUID() returns updated name (in-place update)', async () => {
|
|
849
|
+
const updated = await ad4mClient.perspective.update('00001', 'updated-name')
|
|
850
|
+
expect(updated.name).toBe('updated-name')
|
|
851
|
+
const fetched = await ad4mClient.perspective.byUUID('00001')
|
|
852
|
+
expect(fetched).toBe(updated) // same reference
|
|
853
|
+
expect(fetched.name).toBe('updated-name')
|
|
854
|
+
})
|
|
855
|
+
|
|
856
|
+
it('remove() evicts proxy from cache (new reference on next fetch)', async () => {
|
|
857
|
+
// First populate cache
|
|
858
|
+
const p = await ad4mClient.perspective.byUUID('00003')
|
|
859
|
+
expect(p).toBeTruthy()
|
|
860
|
+
// Remove evicts from cache
|
|
861
|
+
await ad4mClient.perspective.remove('00003')
|
|
862
|
+
// Now byUUID should query server — server returns a new handle for any uuid
|
|
863
|
+
// but the cache was cleared, so a new proxy is created
|
|
864
|
+
const p2 = await ad4mClient.perspective.byUUID('00003')
|
|
865
|
+
expect(p2).not.toBe(p) // different reference after eviction + re-fetch
|
|
866
|
+
})
|
|
867
|
+
|
|
868
|
+
it('all() returns cached proxies for known UUIDs', async () => {
|
|
869
|
+
// First get a proxy via byUUID
|
|
870
|
+
const p1 = await ad4mClient.perspective.byUUID('00001')
|
|
871
|
+
// all() should return the same cached proxy for '00001'
|
|
872
|
+
const allPerspectives = await ad4mClient.perspective.all()
|
|
873
|
+
const match = allPerspectives.find(p => p.uuid === '00001')
|
|
874
|
+
expect(match).toBe(p1) // same reference
|
|
875
|
+
})
|
|
821
876
|
})
|
|
822
877
|
|
|
823
878
|
describe('.runtime', () => {
|
package/src/Literal.test.ts
CHANGED
|
@@ -3,29 +3,34 @@ import { Literal } from './Literal'
|
|
|
3
3
|
describe("Literal", () => {
|
|
4
4
|
it("can handle strings", () => {
|
|
5
5
|
const testString = "test string"
|
|
6
|
-
const testUrl = "literal
|
|
6
|
+
const testUrl = "literal:string:test%20string"
|
|
7
7
|
expect(Literal.from(testString).toUrl()).toBe(testUrl)
|
|
8
8
|
expect(Literal.fromUrl(testUrl).get()).toBe(testString)
|
|
9
9
|
})
|
|
10
10
|
|
|
11
11
|
it("can handle numbers", () => {
|
|
12
12
|
const testNumber = 3.1415
|
|
13
|
-
const testUrl = "literal
|
|
13
|
+
const testUrl = "literal:number:3.1415"
|
|
14
14
|
expect(Literal.from(testNumber).toUrl()).toBe(testUrl)
|
|
15
15
|
expect(Literal.fromUrl(testUrl).get()).toBe(testNumber)
|
|
16
16
|
})
|
|
17
17
|
|
|
18
18
|
it("can handle objects", () => {
|
|
19
19
|
const testObject = {testNumber: "1337", testString: "test"}
|
|
20
|
-
const testUrl = "literal
|
|
20
|
+
const testUrl = "literal:json:%7B%22testNumber%22%3A%221337%22%2C%22testString%22%3A%22test%22%7D"
|
|
21
21
|
expect(Literal.from(testObject).toUrl()).toBe(testUrl)
|
|
22
22
|
expect(Literal.fromUrl(testUrl).get()).toStrictEqual(testObject)
|
|
23
23
|
})
|
|
24
24
|
|
|
25
25
|
it("can handle special characters", () => {
|
|
26
26
|
const testString = "message(X) :- triple('ad4m://self', _, X)."
|
|
27
|
-
const testUrl = "literal
|
|
27
|
+
const testUrl = "literal:string:message%28X%29%20%3A-%20triple%28%27ad4m%3A%2F%2Fself%27%2C%20_%2C%20X%29."
|
|
28
28
|
expect(Literal.from(testString).toUrl()).toBe(testUrl)
|
|
29
29
|
expect(Literal.fromUrl(testUrl).get()).toBe(testString)
|
|
30
30
|
})
|
|
31
|
-
|
|
31
|
+
|
|
32
|
+
it("rejects legacy literal:// URLs", () => {
|
|
33
|
+
expect(() => Literal.fromUrl("literal://string:hello")).toThrow("literal:// format is no longer supported")
|
|
34
|
+
expect(() => Literal.fromUrl("literal://number:42")).toThrow("literal:// format is no longer supported")
|
|
35
|
+
})
|
|
36
|
+
})
|
package/src/Literal.ts
CHANGED
|
@@ -11,8 +11,10 @@ export class Literal {
|
|
|
11
11
|
#url?: string
|
|
12
12
|
|
|
13
13
|
public static fromUrl(url: string) {
|
|
14
|
-
if(!url || !url.startsWith("literal
|
|
14
|
+
if(!url || !url.startsWith("literal:"))
|
|
15
15
|
throw new Error("Can't create Literal from non-literal URL")
|
|
16
|
+
if(url.startsWith("literal://"))
|
|
17
|
+
throw new Error("literal:// format is no longer supported. Use literal: instead.")
|
|
16
18
|
const l = new Literal()
|
|
17
19
|
l.#url = url
|
|
18
20
|
return l
|
|
@@ -46,7 +48,7 @@ export class Literal {
|
|
|
46
48
|
break;
|
|
47
49
|
}
|
|
48
50
|
|
|
49
|
-
return `literal
|
|
51
|
+
return `literal:${encoded}`
|
|
50
52
|
}
|
|
51
53
|
|
|
52
54
|
get(): any {
|
|
@@ -56,11 +58,10 @@ export class Literal {
|
|
|
56
58
|
if(!this.#url)
|
|
57
59
|
throw new Error("Can't render empty Literal")
|
|
58
60
|
|
|
59
|
-
if(!this.#url.startsWith("literal
|
|
61
|
+
if(!this.#url.startsWith("literal:"))
|
|
60
62
|
throw new Error("Can't render Literal from non-literal URL")
|
|
61
63
|
|
|
62
|
-
|
|
63
|
-
const body = this.#url.substring(10)
|
|
64
|
+
const body = this.#url.substring(8)
|
|
64
65
|
|
|
65
66
|
|
|
66
67
|
if(body.startsWith("string:")) {
|
package/src/agent/AgentClient.ts
CHANGED
|
@@ -10,7 +10,7 @@ import {
|
|
|
10
10
|
EntanglementProofInput,
|
|
11
11
|
UserCreationResult,
|
|
12
12
|
} from "./Agent";
|
|
13
|
-
import { HostingUserInfo, PaymentRequestResult } from "../runtime/RuntimeResolver";
|
|
13
|
+
import { HostingUserInfo, PaymentRequestResult, ComputeLogEntry } from "../runtime/RuntimeResolver";
|
|
14
14
|
import { AgentStatus } from "./AgentStatus";
|
|
15
15
|
import { LinkMutations } from "../links/Links";
|
|
16
16
|
import { PerspectiveClient } from "../perspectives/PerspectiveClient";
|
|
@@ -83,6 +83,7 @@ export type AgentUpdatedCallback = (agent: Agent) => null;
|
|
|
83
83
|
export type AgentStatusChangedCallback = (agent: Agent) => null;
|
|
84
84
|
export type AgentAppsUpdatedCallback = () => null;
|
|
85
85
|
export type HostingUserInfoChangedCallback = (info: HostingUserInfo) => void;
|
|
86
|
+
export type ComputeLogUpdatedCallback = (entry: ComputeLogEntry) => void;
|
|
86
87
|
/**
|
|
87
88
|
* Provides access to all functions regarding the local agent,
|
|
88
89
|
* such as generating, locking, unlocking, importing the DID keystore,
|
|
@@ -94,6 +95,7 @@ export class AgentClient {
|
|
|
94
95
|
#updatedCallbacks: AgentUpdatedCallback[];
|
|
95
96
|
#agentStatusChangedCallbacks: AgentStatusChangedCallback[];
|
|
96
97
|
#hostingUserInfoChangedCallbacks: HostingUserInfoChangedCallback[];
|
|
98
|
+
#computeLogUpdatedCallbacks: ComputeLogUpdatedCallback[];
|
|
97
99
|
|
|
98
100
|
constructor(client: ApolloClient<any>, subscribe: boolean = true) {
|
|
99
101
|
this.#apolloClient = client;
|
|
@@ -101,6 +103,7 @@ export class AgentClient {
|
|
|
101
103
|
this.#agentStatusChangedCallbacks = [];
|
|
102
104
|
this.#appsChangedCallback = [];
|
|
103
105
|
this.#hostingUserInfoChangedCallbacks = [];
|
|
106
|
+
this.#computeLogUpdatedCallbacks = [];
|
|
104
107
|
|
|
105
108
|
if (subscribe) {
|
|
106
109
|
this.subscribeAgentUpdated();
|
|
@@ -450,6 +453,34 @@ export class AgentClient {
|
|
|
450
453
|
});
|
|
451
454
|
}
|
|
452
455
|
|
|
456
|
+
addComputeLogUpdatedListener(listener: ComputeLogUpdatedCallback) {
|
|
457
|
+
this.#computeLogUpdatedCallbacks.push(listener);
|
|
458
|
+
}
|
|
459
|
+
|
|
460
|
+
subscribeComputeLogUpdated() {
|
|
461
|
+
this.#apolloClient
|
|
462
|
+
.subscribe({
|
|
463
|
+
query: gql`subscription {
|
|
464
|
+
runtimeComputeLogUpdated {
|
|
465
|
+
id
|
|
466
|
+
userEmail
|
|
467
|
+
timestamp
|
|
468
|
+
operation
|
|
469
|
+
summary
|
|
470
|
+
cost
|
|
471
|
+
creditsAfter
|
|
472
|
+
}
|
|
473
|
+
}`,
|
|
474
|
+
})
|
|
475
|
+
.subscribe({
|
|
476
|
+
next: (result) => {
|
|
477
|
+
const entry = result.data.runtimeComputeLogUpdated;
|
|
478
|
+
this.#computeLogUpdatedCallbacks.forEach((cb) => cb(entry));
|
|
479
|
+
},
|
|
480
|
+
error: (e) => console.error(e),
|
|
481
|
+
});
|
|
482
|
+
}
|
|
483
|
+
|
|
453
484
|
async requestCapability(authInfo: AuthInfoInput): Promise<string> {
|
|
454
485
|
const { agentRequestCapability } = unwrapApolloResult(
|
|
455
486
|
await this.#apolloClient.mutate({
|
|
@@ -636,6 +667,27 @@ export class AgentClient {
|
|
|
636
667
|
return runtimeHostingUserInfo;
|
|
637
668
|
}
|
|
638
669
|
|
|
670
|
+
async computeLog(since?: string, limit?: number, userEmail?: string): Promise<ComputeLogEntry[]> {
|
|
671
|
+
const { runtimeComputeLog } = unwrapApolloResult(
|
|
672
|
+
await this.#apolloClient.query({
|
|
673
|
+
query: gql`query runtimeComputeLog($since: String, $limit: Int, $userEmail: String) {
|
|
674
|
+
runtimeComputeLog(since: $since, limit: $limit, userEmail: $userEmail) {
|
|
675
|
+
id
|
|
676
|
+
userEmail
|
|
677
|
+
timestamp
|
|
678
|
+
operation
|
|
679
|
+
summary
|
|
680
|
+
cost
|
|
681
|
+
creditsAfter
|
|
682
|
+
}
|
|
683
|
+
}`,
|
|
684
|
+
variables: { since, limit, userEmail },
|
|
685
|
+
fetchPolicy: 'network-only',
|
|
686
|
+
})
|
|
687
|
+
);
|
|
688
|
+
return runtimeComputeLog;
|
|
689
|
+
}
|
|
690
|
+
|
|
639
691
|
async setHotWalletAddress(address: string): Promise<boolean> {
|
|
640
692
|
const { runtimeSetHotWalletAddress } = unwrapApolloResult(
|
|
641
693
|
await this.#apolloClient.mutate({
|
|
@@ -27,11 +27,11 @@ export function exprRef2String(ref: ExpressionRef): string {
|
|
|
27
27
|
}
|
|
28
28
|
|
|
29
29
|
export function parseExprUrl(url: string): ExpressionRef {
|
|
30
|
-
if(url.startsWith("literal
|
|
30
|
+
if(url.startsWith("literal:")) {
|
|
31
31
|
const languageRef = new LanguageRef()
|
|
32
32
|
languageRef.address = 'literal'
|
|
33
33
|
languageRef.name = 'literal'
|
|
34
|
-
const content = url.substring(
|
|
34
|
+
const content = url.substring(8)
|
|
35
35
|
return new ExpressionRef(languageRef, content)
|
|
36
36
|
}
|
|
37
37
|
|
package/src/index.ts
CHANGED
|
@@ -8,7 +8,6 @@ export * from "./expression/ExpressionRef";
|
|
|
8
8
|
export * from "./language/Icon";
|
|
9
9
|
export * from "./language/Language";
|
|
10
10
|
export * from "./language/LanguageRef";
|
|
11
|
-
export * from "./language/LanguageContext";
|
|
12
11
|
export * from "./language/LanguageHandle";
|
|
13
12
|
export * from "./language/LanguageMeta";
|
|
14
13
|
export * from "./links/Links";
|