@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/Literal.js
CHANGED
|
@@ -20,8 +20,10 @@ export class Literal {
|
|
|
20
20
|
_Literal_url.set(this, void 0);
|
|
21
21
|
}
|
|
22
22
|
static fromUrl(url) {
|
|
23
|
-
if (!url || !url.startsWith("literal
|
|
23
|
+
if (!url || !url.startsWith("literal:"))
|
|
24
24
|
throw new Error("Can't create Literal from non-literal URL");
|
|
25
|
+
if (url.startsWith("literal://"))
|
|
26
|
+
throw new Error("literal:// format is no longer supported. Use literal: instead.");
|
|
25
27
|
const l = new Literal();
|
|
26
28
|
__classPrivateFieldSet(l, _Literal_url, url, "f");
|
|
27
29
|
return l;
|
|
@@ -51,17 +53,16 @@ export class Literal {
|
|
|
51
53
|
encoded = `json:${encodeRFC3986URIComponent(JSON.stringify(__classPrivateFieldGet(this, _Literal_literal, "f")))}`;
|
|
52
54
|
break;
|
|
53
55
|
}
|
|
54
|
-
return `literal
|
|
56
|
+
return `literal:${encoded}`;
|
|
55
57
|
}
|
|
56
58
|
get() {
|
|
57
59
|
if (__classPrivateFieldGet(this, _Literal_literal, "f"))
|
|
58
60
|
return __classPrivateFieldGet(this, _Literal_literal, "f");
|
|
59
61
|
if (!__classPrivateFieldGet(this, _Literal_url, "f"))
|
|
60
62
|
throw new Error("Can't render empty Literal");
|
|
61
|
-
if (!__classPrivateFieldGet(this, _Literal_url, "f").startsWith("literal
|
|
63
|
+
if (!__classPrivateFieldGet(this, _Literal_url, "f").startsWith("literal:"))
|
|
62
64
|
throw new Error("Can't render Literal from non-literal URL");
|
|
63
|
-
|
|
64
|
-
const body = __classPrivateFieldGet(this, _Literal_url, "f").substring(10);
|
|
65
|
+
const body = __classPrivateFieldGet(this, _Literal_url, "f").substring(8);
|
|
65
66
|
if (body.startsWith("string:")) {
|
|
66
67
|
return decodeURIComponent(body.substring(7));
|
|
67
68
|
}
|
|
@@ -1,7 +1,7 @@
|
|
|
1
1
|
import { ApolloClient } from "@apollo/client/core";
|
|
2
2
|
import { PerspectiveInput } from "../perspectives/Perspective";
|
|
3
3
|
import { Agent, Apps, AuthInfoInput, EntanglementProof, EntanglementProofInput, UserCreationResult } from "./Agent";
|
|
4
|
-
import { HostingUserInfo, PaymentRequestResult } from "../runtime/RuntimeResolver";
|
|
4
|
+
import { HostingUserInfo, PaymentRequestResult, ComputeLogEntry } from "../runtime/RuntimeResolver";
|
|
5
5
|
import { AgentStatus } from "./AgentStatus";
|
|
6
6
|
import { LinkMutations } from "../links/Links";
|
|
7
7
|
import { VerificationRequestResult } from "../runtime/RuntimeResolver";
|
|
@@ -15,6 +15,7 @@ export type AgentUpdatedCallback = (agent: Agent) => null;
|
|
|
15
15
|
export type AgentStatusChangedCallback = (agent: Agent) => null;
|
|
16
16
|
export type AgentAppsUpdatedCallback = () => null;
|
|
17
17
|
export type HostingUserInfoChangedCallback = (info: HostingUserInfo) => void;
|
|
18
|
+
export type ComputeLogUpdatedCallback = (entry: ComputeLogEntry) => void;
|
|
18
19
|
/**
|
|
19
20
|
* Provides access to all functions regarding the local agent,
|
|
20
21
|
* such as generating, locking, unlocking, importing the DID keystore,
|
|
@@ -51,6 +52,8 @@ export declare class AgentClient {
|
|
|
51
52
|
subscribeAgentStatusChanged(): void;
|
|
52
53
|
addHostingUserInfoChangedListener(listener: HostingUserInfoChangedCallback): void;
|
|
53
54
|
subscribeHostingUserInfoChanged(): void;
|
|
55
|
+
addComputeLogUpdatedListener(listener: ComputeLogUpdatedCallback): void;
|
|
56
|
+
subscribeComputeLogUpdated(): void;
|
|
54
57
|
requestCapability(authInfo: AuthInfoInput): Promise<string>;
|
|
55
58
|
permitCapability(auth: string): Promise<string>;
|
|
56
59
|
generateJwt(requestId: string, rand: string): Promise<string>;
|
|
@@ -64,6 +67,7 @@ export declare class AgentClient {
|
|
|
64
67
|
requestLoginVerification(email: string, appInfo?: AuthInfoInput): Promise<VerificationRequestResult>;
|
|
65
68
|
verifyEmailCode(email: string, code: string, verificationType: string): Promise<string>;
|
|
66
69
|
hostingUserInfo(): Promise<HostingUserInfo>;
|
|
70
|
+
computeLog(since?: string, limit?: number, userEmail?: string): Promise<ComputeLogEntry[]>;
|
|
67
71
|
setHotWalletAddress(address: string): Promise<boolean>;
|
|
68
72
|
requestPayment(amountHOT: string): Promise<PaymentRequestResult>;
|
|
69
73
|
}
|
|
@@ -9,7 +9,7 @@ var __classPrivateFieldGet = (this && this.__classPrivateFieldGet) || function (
|
|
|
9
9
|
if (typeof state === "function" ? receiver !== state || !f : !state.has(receiver)) throw new TypeError("Cannot read private member from an object whose class did not declare it");
|
|
10
10
|
return kind === "m" ? f : kind === "a" ? f.call(receiver) : f ? f.value : state.get(receiver);
|
|
11
11
|
};
|
|
12
|
-
var _AgentClient_apolloClient, _AgentClient_appsChangedCallback, _AgentClient_updatedCallbacks, _AgentClient_agentStatusChangedCallbacks, _AgentClient_hostingUserInfoChangedCallbacks;
|
|
12
|
+
var _AgentClient_apolloClient, _AgentClient_appsChangedCallback, _AgentClient_updatedCallbacks, _AgentClient_agentStatusChangedCallbacks, _AgentClient_hostingUserInfoChangedCallbacks, _AgentClient_computeLogUpdatedCallbacks;
|
|
13
13
|
import { gql } from "@apollo/client/core";
|
|
14
14
|
import unwrapApolloResult from "../unwrapApolloResult";
|
|
15
15
|
import { Agent, } from "./Agent";
|
|
@@ -78,11 +78,13 @@ export class AgentClient {
|
|
|
78
78
|
_AgentClient_updatedCallbacks.set(this, void 0);
|
|
79
79
|
_AgentClient_agentStatusChangedCallbacks.set(this, void 0);
|
|
80
80
|
_AgentClient_hostingUserInfoChangedCallbacks.set(this, void 0);
|
|
81
|
+
_AgentClient_computeLogUpdatedCallbacks.set(this, void 0);
|
|
81
82
|
__classPrivateFieldSet(this, _AgentClient_apolloClient, client, "f");
|
|
82
83
|
__classPrivateFieldSet(this, _AgentClient_updatedCallbacks, [], "f");
|
|
83
84
|
__classPrivateFieldSet(this, _AgentClient_agentStatusChangedCallbacks, [], "f");
|
|
84
85
|
__classPrivateFieldSet(this, _AgentClient_appsChangedCallback, [], "f");
|
|
85
86
|
__classPrivateFieldSet(this, _AgentClient_hostingUserInfoChangedCallbacks, [], "f");
|
|
87
|
+
__classPrivateFieldSet(this, _AgentClient_computeLogUpdatedCallbacks, [], "f");
|
|
86
88
|
if (subscribe) {
|
|
87
89
|
this.subscribeAgentUpdated();
|
|
88
90
|
this.subscribeAgentStatusChanged();
|
|
@@ -366,6 +368,32 @@ export class AgentClient {
|
|
|
366
368
|
error: (e) => console.error(e),
|
|
367
369
|
});
|
|
368
370
|
}
|
|
371
|
+
addComputeLogUpdatedListener(listener) {
|
|
372
|
+
__classPrivateFieldGet(this, _AgentClient_computeLogUpdatedCallbacks, "f").push(listener);
|
|
373
|
+
}
|
|
374
|
+
subscribeComputeLogUpdated() {
|
|
375
|
+
__classPrivateFieldGet(this, _AgentClient_apolloClient, "f")
|
|
376
|
+
.subscribe({
|
|
377
|
+
query: gql `subscription {
|
|
378
|
+
runtimeComputeLogUpdated {
|
|
379
|
+
id
|
|
380
|
+
userEmail
|
|
381
|
+
timestamp
|
|
382
|
+
operation
|
|
383
|
+
summary
|
|
384
|
+
cost
|
|
385
|
+
creditsAfter
|
|
386
|
+
}
|
|
387
|
+
}`,
|
|
388
|
+
})
|
|
389
|
+
.subscribe({
|
|
390
|
+
next: (result) => {
|
|
391
|
+
const entry = result.data.runtimeComputeLogUpdated;
|
|
392
|
+
__classPrivateFieldGet(this, _AgentClient_computeLogUpdatedCallbacks, "f").forEach((cb) => cb(entry));
|
|
393
|
+
},
|
|
394
|
+
error: (e) => console.error(e),
|
|
395
|
+
});
|
|
396
|
+
}
|
|
369
397
|
async requestCapability(authInfo) {
|
|
370
398
|
const { agentRequestCapability } = unwrapApolloResult(await __classPrivateFieldGet(this, _AgentClient_apolloClient, "f").mutate({
|
|
371
399
|
mutation: gql `
|
|
@@ -512,6 +540,24 @@ export class AgentClient {
|
|
|
512
540
|
}));
|
|
513
541
|
return runtimeHostingUserInfo;
|
|
514
542
|
}
|
|
543
|
+
async computeLog(since, limit, userEmail) {
|
|
544
|
+
const { runtimeComputeLog } = unwrapApolloResult(await __classPrivateFieldGet(this, _AgentClient_apolloClient, "f").query({
|
|
545
|
+
query: gql `query runtimeComputeLog($since: String, $limit: Int, $userEmail: String) {
|
|
546
|
+
runtimeComputeLog(since: $since, limit: $limit, userEmail: $userEmail) {
|
|
547
|
+
id
|
|
548
|
+
userEmail
|
|
549
|
+
timestamp
|
|
550
|
+
operation
|
|
551
|
+
summary
|
|
552
|
+
cost
|
|
553
|
+
creditsAfter
|
|
554
|
+
}
|
|
555
|
+
}`,
|
|
556
|
+
variables: { since, limit, userEmail },
|
|
557
|
+
fetchPolicy: 'network-only',
|
|
558
|
+
}));
|
|
559
|
+
return runtimeComputeLog;
|
|
560
|
+
}
|
|
515
561
|
async setHotWalletAddress(address) {
|
|
516
562
|
const { runtimeSetHotWalletAddress } = unwrapApolloResult(await __classPrivateFieldGet(this, _AgentClient_apolloClient, "f").mutate({
|
|
517
563
|
mutation: gql `mutation runtimeSetHotWalletAddress($address: String!) {
|
|
@@ -534,4 +580,4 @@ export class AgentClient {
|
|
|
534
580
|
return runtimeRequestPayment;
|
|
535
581
|
}
|
|
536
582
|
}
|
|
537
|
-
_AgentClient_apolloClient = new WeakMap(), _AgentClient_appsChangedCallback = new WeakMap(), _AgentClient_updatedCallbacks = new WeakMap(), _AgentClient_agentStatusChangedCallbacks = new WeakMap(), _AgentClient_hostingUserInfoChangedCallbacks = new WeakMap();
|
|
583
|
+
_AgentClient_apolloClient = new WeakMap(), _AgentClient_appsChangedCallback = new WeakMap(), _AgentClient_updatedCallbacks = new WeakMap(), _AgentClient_agentStatusChangedCallbacks = new WeakMap(), _AgentClient_hostingUserInfoChangedCallbacks = new WeakMap(), _AgentClient_computeLogUpdatedCallbacks = new WeakMap();
|
|
@@ -38,11 +38,11 @@ export function exprRef2String(ref) {
|
|
|
38
38
|
return `${ref.language.address}://${ref.expression}`;
|
|
39
39
|
}
|
|
40
40
|
export function parseExprUrl(url) {
|
|
41
|
-
if (url.startsWith("literal
|
|
41
|
+
if (url.startsWith("literal:")) {
|
|
42
42
|
const languageRef = new LanguageRef();
|
|
43
43
|
languageRef.address = 'literal';
|
|
44
44
|
languageRef.name = 'literal';
|
|
45
|
-
const content = url.substring(
|
|
45
|
+
const content = url.substring(8);
|
|
46
46
|
return new ExpressionRef(languageRef, content);
|
|
47
47
|
}
|
|
48
48
|
const URIregexp = /^([^:^\s]+):\/\/([\s\S]+)$/;
|
package/lib/src/index.d.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";
|
package/lib/src/index.js
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";
|
|
@@ -1,176 +1,23 @@
|
|
|
1
|
-
import
|
|
2
|
-
import {
|
|
3
|
-
|
|
4
|
-
|
|
5
|
-
import { PerspectiveDiff } from '../perspectives/PerspectiveDiff';
|
|
6
|
-
import { PerspectiveState } from '../perspectives/PerspectiveHandle';
|
|
7
|
-
/** Interface of AD4M Languages
|
|
1
|
+
import { DID } from "../DID";
|
|
2
|
+
import { PerspectiveExpression } from "../perspectives/Perspective";
|
|
3
|
+
/**
|
|
4
|
+
* # AD4M Language — client-side types
|
|
8
5
|
*
|
|
9
|
-
*
|
|
10
|
-
*
|
|
11
|
-
*
|
|
6
|
+
* This file only contains the client-visible types that the AD4M GraphQL
|
|
7
|
+
* API exposes on top of a running Language — interaction metadata, online
|
|
8
|
+
* agent records, and the telepresence-signal callback shape.
|
|
12
9
|
*
|
|
13
|
-
*
|
|
14
|
-
*
|
|
10
|
+
* **If you're authoring an AD4M Language**, you don't consume types from
|
|
11
|
+
* here — use [`@coasys/ad4m-ldk`](https://www.npmjs.com/package/@coasys/ad4m-ldk)
|
|
12
|
+
* (or the [Rust ALDK](https://crates.io/crates/ad4m-ldk)), which provide
|
|
13
|
+
* the capability traits, typed runtime-import wrappers, and authoring
|
|
14
|
+
* macros/helpers.
|
|
15
15
|
*
|
|
16
|
-
* The
|
|
17
|
-
*
|
|
18
|
-
*
|
|
19
|
-
*
|
|
20
|
-
* The second most common kind of language is the "Link Language", which is a language that builds the core
|
|
21
|
-
* of AD4M Neighbourhoods.
|
|
22
|
-
* For that, implement the linksAdapter interface.
|
|
23
|
-
*/
|
|
24
|
-
export interface Language {
|
|
25
|
-
readonly name: string;
|
|
26
|
-
/** Flagging expressions as immutable to enable
|
|
27
|
-
* expression caching in the ad4m-executor
|
|
28
|
-
*/
|
|
29
|
-
isImmutableExpression?(expression: Address): boolean;
|
|
30
|
-
/** ExpressionAdapter implements means of getting an Expression
|
|
31
|
-
* by address and putting an expression
|
|
32
|
-
*/
|
|
33
|
-
readonly expressionAdapter?: ExpressionAdapter;
|
|
34
|
-
/** Interface for getting UI/web components for rendering Expressions of this Language */
|
|
35
|
-
readonly expressionUI?: ExpressionUI;
|
|
36
|
-
/** Interface of LinkLanguages for the core implementation of Neighbourhoods */
|
|
37
|
-
readonly linksAdapter?: LinkSyncAdapter;
|
|
38
|
-
/** Additional Interface of LinkLanguages that support telepresence features,
|
|
39
|
-
* that is:
|
|
40
|
-
* - seeing who is online and getting a status
|
|
41
|
-
* - sending/receiveing p2p signals to other online agents without affecting
|
|
42
|
-
* the shared Perspective of the Neighbourhood
|
|
43
|
-
* (see TelepresenceAdapter for more details)
|
|
44
|
-
*/
|
|
45
|
-
readonly telepresenceAdapter?: TelepresenceAdapter;
|
|
46
|
-
/** Implementation of a Language that defines and stores Languages*/
|
|
47
|
-
readonly languageAdapter?: LanguageAdapter;
|
|
48
|
-
/** Optional adapter for getting Expressions by author */
|
|
49
|
-
readonly getByAuthorAdapter?: GetByAuthorAdapter;
|
|
50
|
-
/** Optional adapter for getting all Expressions */
|
|
51
|
-
readonly getAllAdapter?: GetAllAdapter;
|
|
52
|
-
/** Optional adapter for direct messaging between agents */
|
|
53
|
-
readonly directMessageAdapter?: DirectMessageAdapter;
|
|
54
|
-
/** Interface for providing UI components for the settings of this Language */
|
|
55
|
-
readonly settingsUI?: SettingsUI;
|
|
56
|
-
/** Optional function to make any cleanup/teardown if your language gets deleting in the ad4m-executor */
|
|
57
|
-
readonly teardown?: () => void;
|
|
58
|
-
/** All available interactions this agent could execute on given expression */
|
|
59
|
-
interactions(expression: Address): Interaction[];
|
|
60
|
-
}
|
|
61
|
-
/** UI factories returning web components */
|
|
62
|
-
export interface ExpressionUI {
|
|
63
|
-
/** Returns JS code of a web component that renders the given expression */
|
|
64
|
-
icon(): string;
|
|
65
|
-
/** Returns JS code of a web component used to create new expressions */
|
|
66
|
-
constructorIcon(): string;
|
|
67
|
-
}
|
|
68
|
-
export interface SettingsUI {
|
|
69
|
-
settingsIcon(): string;
|
|
70
|
-
}
|
|
71
|
-
/** Interface for the most common Expression Languages */
|
|
72
|
-
export interface ExpressionAdapter {
|
|
73
|
-
/** Returns an Expression by address, or null if there is no Expression
|
|
74
|
-
* with that given address
|
|
75
|
-
*/
|
|
76
|
-
get(address: Address): Promise<Expression | null>;
|
|
77
|
-
/** Strategy for putting an expression with needs to be different
|
|
78
|
-
* for those two cases:
|
|
79
|
-
* 1. PublicSharing means that this language supports the creation
|
|
80
|
-
* and sharing of Expressions, which is the common use-case
|
|
81
|
-
* 2. ReadOnlyLanguage means that the Language implements a pre-defined
|
|
82
|
-
* set of expressions (which can be infinite or finite).
|
|
83
|
-
* For example the url-iframe Language which directly maps URLs to
|
|
84
|
-
* addresses - meaning every well formed URL is an address in this
|
|
85
|
-
* Language. Or a potential Language implementing the verbs/predicates
|
|
86
|
-
* of a spec like FOAF.
|
|
87
|
-
*/
|
|
88
|
-
putAdapter: PublicSharing | ReadOnlyLanguage;
|
|
89
|
-
}
|
|
90
|
-
/** Implement this interface if your Language supports creation of sharing
|
|
91
|
-
* of Expressions.
|
|
92
|
-
* See ExpressionAdapter
|
|
16
|
+
* The normative interface definition lives in
|
|
17
|
+
* [`docs-src/ad4m-lang.wit`](https://github.com/coasys/ad4m/blob/dev/docs-src/ad4m-lang.wit).
|
|
18
|
+
* The prose spec is
|
|
19
|
+
* [`docs-src/language-interface-spec.md`](https://github.com/coasys/ad4m/blob/dev/docs-src/language-interface-spec.md).
|
|
93
20
|
*/
|
|
94
|
-
export interface PublicSharing {
|
|
95
|
-
/** Create an Expression and shares it.
|
|
96
|
-
* Return the Expression's address.
|
|
97
|
-
* @param content is the object created by the constructorIcon component
|
|
98
|
-
*/
|
|
99
|
-
createPublic(content: object): Promise<Address>;
|
|
100
|
-
}
|
|
101
|
-
/** Implement this interface if your Language is defined over a static
|
|
102
|
-
* set of pre-defined Expressions.
|
|
103
|
-
*/
|
|
104
|
-
export interface ReadOnlyLanguage {
|
|
105
|
-
/** This just calculates the address of an object
|
|
106
|
-
* @param content is the object created by the constructorIcon component
|
|
107
|
-
*/
|
|
108
|
-
addressOf(content: object): Promise<Address>;
|
|
109
|
-
}
|
|
110
|
-
export interface LanguageAdapter {
|
|
111
|
-
getLanguageSource(address: Address): Promise<string>;
|
|
112
|
-
}
|
|
113
|
-
export interface GetByAuthorAdapter {
|
|
114
|
-
getByAuthor(author: DID, count: number, page: number): Promise<Expression[] | null>;
|
|
115
|
-
}
|
|
116
|
-
export interface GetAllAdapter {
|
|
117
|
-
getAll(filter: any, count: number, page: number): Promise<Expression[] | null>;
|
|
118
|
-
}
|
|
119
|
-
export type PerspectiveDiffObserver = (diff: PerspectiveDiff) => void;
|
|
120
|
-
export type SyncStateChangeObserver = (state: PerspectiveState) => void;
|
|
121
|
-
/** Interface for "Link Languages" that facilitate the synchronization
|
|
122
|
-
* between agents' local Perspectives inside a Neighbourhood.
|
|
123
|
-
* The assumption is that every version of the shared Perspective
|
|
124
|
-
* is labeled with a unique revision string.
|
|
125
|
-
* Changes are committed and retrieved through diffs.
|
|
126
|
-
* Think of a LinkSyncAdapter as a git branch to which agents commit
|
|
127
|
-
* their changes to and pull diffs from their current revision
|
|
128
|
-
* to the latest one.
|
|
129
|
-
*/
|
|
130
|
-
export interface LinkSyncAdapter {
|
|
131
|
-
writable(): boolean;
|
|
132
|
-
public(): boolean;
|
|
133
|
-
others(): Promise<DID[]>;
|
|
134
|
-
/** What revision are we on now -> what changes are included in output of render() */
|
|
135
|
-
currentRevision(): Promise<string>;
|
|
136
|
-
/**
|
|
137
|
-
* Check for and get new changes,
|
|
138
|
-
* notify others of local changes.
|
|
139
|
-
* This function will be called every
|
|
140
|
-
* few seconds by the ad4m-executor.
|
|
141
|
-
* */
|
|
142
|
-
sync(): Promise<PerspectiveDiff>;
|
|
143
|
-
/** Returns the full, rendered Perspective at currentRevision */
|
|
144
|
-
render(): Promise<Perspective>;
|
|
145
|
-
/** Publish changes */
|
|
146
|
-
commit(diff: PerspectiveDiff): Promise<string>;
|
|
147
|
-
/** Get push notification when a diff got published */
|
|
148
|
-
addCallback(callback: PerspectiveDiffObserver): any;
|
|
149
|
-
/** Add a sync state callback method */
|
|
150
|
-
addSyncStateChangeCallback(callback: SyncStateChangeObserver): any;
|
|
151
|
-
/**
|
|
152
|
-
* Set the local agents (DIDs) that own this perspective/neighbourhood.
|
|
153
|
-
* This is used to determine which agents should be registered in the DHT.
|
|
154
|
-
* Optional - if not implemented, all local agents may be registered.
|
|
155
|
-
*
|
|
156
|
-
* This is a temporary hack to support multiple users on one node joining the same neighbourhood.
|
|
157
|
-
* Once we migrate the LanguageController to Rust and run Languages per user, each user will get their
|
|
158
|
-
* own language instance and we won't need to explicitly set local agents. This will provide better
|
|
159
|
-
* isolation and avoid the need to share language state between users.
|
|
160
|
-
*/
|
|
161
|
-
setLocalAgents?(agents: DID[]): void;
|
|
162
|
-
}
|
|
163
|
-
export type MessageCallback = (message: PerspectiveExpression) => void;
|
|
164
|
-
export type StatusCallback = (caller: DID) => Perspective;
|
|
165
|
-
export interface DirectMessageAdapter {
|
|
166
|
-
recipient(): DID;
|
|
167
|
-
status(): Promise<PerspectiveExpression | void>;
|
|
168
|
-
sendP2P(message: Perspective): Promise<PerspectiveExpression | void>;
|
|
169
|
-
sendInbox(message: Perspective): Promise<PerspectiveExpression | void>;
|
|
170
|
-
setStatus(status: PerspectiveExpression): any;
|
|
171
|
-
inbox(filter?: string): Promise<PerspectiveExpression[]>;
|
|
172
|
-
addMessageCallback(callback: MessageCallback): any;
|
|
173
|
-
}
|
|
174
21
|
export declare class InteractionParameter {
|
|
175
22
|
name: string;
|
|
176
23
|
type: string;
|
|
@@ -180,6 +27,12 @@ export declare class InteractionMeta {
|
|
|
180
27
|
name: string;
|
|
181
28
|
parameters: InteractionParameter[];
|
|
182
29
|
}
|
|
30
|
+
/**
|
|
31
|
+
* Runtime-side interaction object. The runtime constructs one of these
|
|
32
|
+
* from a Language's `interactions(address)` description and exposes
|
|
33
|
+
* `execute()` to UI callers. Language authors describe interactions
|
|
34
|
+
* via the ALDK, not by constructing this type directly.
|
|
35
|
+
*/
|
|
183
36
|
export interface Interaction {
|
|
184
37
|
readonly label: string;
|
|
185
38
|
readonly name: string;
|
|
@@ -196,11 +49,8 @@ export declare class OnlineAgent {
|
|
|
196
49
|
did: DID;
|
|
197
50
|
status: PerspectiveExpression;
|
|
198
51
|
}
|
|
52
|
+
/**
|
|
53
|
+
* Callback shape used by the client to receive telepresence signals
|
|
54
|
+
* from a Neighbourhood's link Language.
|
|
55
|
+
*/
|
|
199
56
|
export type TelepresenceSignalCallback = (payload: PerspectiveExpression, recipientDid?: string) => void;
|
|
200
|
-
export interface TelepresenceAdapter {
|
|
201
|
-
setOnlineStatus(status: PerspectiveExpression): Promise<void>;
|
|
202
|
-
getOnlineAgents(): Promise<OnlineAgent[]>;
|
|
203
|
-
sendSignal(remoteAgentDid: string, payload: PerspectiveExpression): Promise<object>;
|
|
204
|
-
sendBroadcast(payload: PerspectiveExpression): Promise<object>;
|
|
205
|
-
registerSignalCallback(callback: TelepresenceSignalCallback): Promise<void>;
|
|
206
|
-
}
|
|
@@ -7,8 +7,33 @@ var __decorate = (this && this.__decorate) || function (decorators, target, key,
|
|
|
7
7
|
var __metadata = (this && this.__metadata) || function (k, v) {
|
|
8
8
|
if (typeof Reflect === "object" && typeof Reflect.metadata === "function") return Reflect.metadata(k, v);
|
|
9
9
|
};
|
|
10
|
-
import { PerspectiveExpression } from
|
|
10
|
+
import { PerspectiveExpression } from "../perspectives/Perspective";
|
|
11
11
|
import { InputType, Field, ObjectType } from "type-graphql";
|
|
12
|
+
/**
|
|
13
|
+
* # AD4M Language — client-side types
|
|
14
|
+
*
|
|
15
|
+
* This file only contains the client-visible types that the AD4M GraphQL
|
|
16
|
+
* API exposes on top of a running Language — interaction metadata, online
|
|
17
|
+
* agent records, and the telepresence-signal callback shape.
|
|
18
|
+
*
|
|
19
|
+
* **If you're authoring an AD4M Language**, you don't consume types from
|
|
20
|
+
* here — use [`@coasys/ad4m-ldk`](https://www.npmjs.com/package/@coasys/ad4m-ldk)
|
|
21
|
+
* (or the [Rust ALDK](https://crates.io/crates/ad4m-ldk)), which provide
|
|
22
|
+
* the capability traits, typed runtime-import wrappers, and authoring
|
|
23
|
+
* macros/helpers.
|
|
24
|
+
*
|
|
25
|
+
* The normative interface definition lives in
|
|
26
|
+
* [`docs-src/ad4m-lang.wit`](https://github.com/coasys/ad4m/blob/dev/docs-src/ad4m-lang.wit).
|
|
27
|
+
* The prose spec is
|
|
28
|
+
* [`docs-src/language-interface-spec.md`](https://github.com/coasys/ad4m/blob/dev/docs-src/language-interface-spec.md).
|
|
29
|
+
*/
|
|
30
|
+
// ----- Interaction metadata --------------------------------------------------
|
|
31
|
+
//
|
|
32
|
+
// Languages optionally publish a list of user-invocable actions per
|
|
33
|
+
// Expression ("interactions"). The runtime surfaces these to UIs via
|
|
34
|
+
// GraphQL, which is why `InteractionParameter` / `InteractionMeta` /
|
|
35
|
+
// `InteractionCall` need the type-graphql decorators — they cross the
|
|
36
|
+
// GraphQL boundary as first-class objects.
|
|
12
37
|
let InteractionParameter = class InteractionParameter {
|
|
13
38
|
};
|
|
14
39
|
__decorate([
|
|
@@ -34,7 +59,7 @@ __decorate([
|
|
|
34
59
|
__metadata("design:type", String)
|
|
35
60
|
], InteractionMeta.prototype, "name", void 0);
|
|
36
61
|
__decorate([
|
|
37
|
-
Field(
|
|
62
|
+
Field(() => [InteractionParameter]),
|
|
38
63
|
__metadata("design:type", Array)
|
|
39
64
|
], InteractionMeta.prototype, "parameters", void 0);
|
|
40
65
|
InteractionMeta = __decorate([
|
|
@@ -63,6 +88,7 @@ InteractionCall = __decorate([
|
|
|
63
88
|
__metadata("design:paramtypes", [String, Object])
|
|
64
89
|
], InteractionCall);
|
|
65
90
|
export { InteractionCall };
|
|
91
|
+
// ----- Telepresence ----------------------------------------------------------
|
|
66
92
|
let OnlineAgent = class OnlineAgent {
|
|
67
93
|
};
|
|
68
94
|
__decorate([
|