@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.
Files changed (115) hide show
  1. package/lib/index.cjs +2377 -849
  2. package/lib/index.js +2354 -846
  3. package/lib/src/Literal.js +6 -5
  4. package/lib/src/agent/AgentClient.d.ts +5 -1
  5. package/lib/src/agent/AgentClient.js +48 -2
  6. package/lib/src/expression/ExpressionRef.js +2 -2
  7. package/lib/src/index.d.ts +0 -1
  8. package/lib/src/index.js +0 -1
  9. package/lib/src/language/Language.d.ts +26 -176
  10. package/lib/src/language/Language.js +28 -2
  11. package/lib/src/model/Ad4mModel.d.ts +52 -28
  12. package/lib/src/model/Ad4mModel.js +255 -118
  13. package/lib/src/model/Ad4mModel.test.js +1727 -537
  14. package/lib/src/model/ModelQueryBuilder.d.ts +67 -34
  15. package/lib/src/model/ModelQueryBuilder.js +208 -79
  16. package/lib/src/model/Subject.js +6 -6
  17. package/lib/src/model/decorators.d.ts +14 -8
  18. package/lib/src/model/decorators.js +41 -14
  19. package/lib/src/model/hydration-batch.d.ts +34 -0
  20. package/lib/src/model/hydration-batch.js +147 -0
  21. package/lib/src/model/hydration-batching.test.d.ts +7 -0
  22. package/lib/src/model/hydration-batching.test.js +456 -0
  23. package/lib/src/model/hydration.d.ts +4 -3
  24. package/lib/src/model/hydration.js +365 -86
  25. package/lib/src/model/index.d.ts +4 -1
  26. package/lib/src/model/index.js +4 -1
  27. package/lib/src/model/json-schema.js +2 -2
  28. package/lib/src/model/query-cache.d.ts +30 -0
  29. package/lib/src/model/query-cache.js +66 -0
  30. package/lib/src/model/query-cache.test.d.ts +1 -0
  31. package/lib/src/model/query-cache.test.js +43 -0
  32. package/lib/src/model/query-common.d.ts +1 -1
  33. package/lib/src/model/query-common.js +1 -1
  34. package/lib/src/model/query-sparql-batch.d.ts +17 -0
  35. package/lib/src/model/query-sparql-batch.js +260 -0
  36. package/lib/src/model/query-sparql.d.ts +124 -0
  37. package/lib/src/model/query-sparql.js +767 -0
  38. package/lib/src/model/query-sparql.test.d.ts +1 -0
  39. package/lib/src/model/query-sparql.test.js +495 -0
  40. package/lib/src/model/{surreal-utils.d.ts → query-utils.d.ts} +12 -9
  41. package/lib/src/model/{surreal-utils.js → query-utils.js} +43 -27
  42. package/lib/src/model/relation-filtering.test.js +15 -15
  43. package/lib/src/model/sdna.js +1 -1
  44. package/lib/src/model/shacl-gen.js +42 -18
  45. package/lib/src/model/subscription-delta.test.d.ts +24 -0
  46. package/lib/src/model/subscription-delta.test.js +180 -0
  47. package/lib/src/model/subscription-pool.d.ts +39 -0
  48. package/lib/src/model/subscription-pool.js +165 -0
  49. package/lib/src/model/types.d.ts +52 -4
  50. package/lib/src/model/types.js +1 -1
  51. package/lib/src/perspectives/PerspectiveClient.d.ts +3 -17
  52. package/lib/src/perspectives/PerspectiveClient.js +42 -66
  53. package/lib/src/perspectives/PerspectiveClient.test.d.ts +1 -0
  54. package/lib/src/perspectives/PerspectiveClient.test.js +169 -0
  55. package/lib/src/perspectives/PerspectiveProxy.d.ts +54 -30
  56. package/lib/src/perspectives/PerspectiveProxy.js +239 -177
  57. package/lib/src/perspectives/PerspectiveResolver.d.ts +0 -1
  58. package/lib/src/perspectives/PerspectiveResolver.js +0 -11
  59. package/lib/src/perspectives/WakerSubscriptionManager.d.ts +3 -3
  60. package/lib/src/perspectives/WakerSubscriptionManager.js +7 -8
  61. package/lib/src/runtime/RuntimeResolver.d.ts +11 -0
  62. package/lib/src/runtime/RuntimeResolver.js +56 -0
  63. package/lib/src/schema.gql +11 -1
  64. package/lib/src/shacl/SHACLFlow.d.ts +1 -1
  65. package/lib/src/shacl/SHACLFlow.js +9 -9
  66. package/lib/src/shacl/SHACLShape.d.ts +1 -1
  67. package/lib/src/shacl/SHACLShape.js +38 -38
  68. package/lib/src/typeDefs.js +11 -1
  69. package/lib/src/utils.d.ts +6 -6
  70. package/lib/src/utils.js +6 -6
  71. package/package.json +1 -1
  72. package/src/Ad4mClient.test.ts +56 -1
  73. package/src/Literal.test.ts +10 -5
  74. package/src/Literal.ts +6 -5
  75. package/src/agent/AgentClient.ts +53 -1
  76. package/src/expression/ExpressionRef.ts +2 -2
  77. package/src/index.ts +0 -1
  78. package/src/language/Language.ts +55 -231
  79. package/src/model/Ad4mModel.test.ts +1709 -572
  80. package/src/model/Ad4mModel.ts +274 -120
  81. package/src/model/ModelQueryBuilder.ts +234 -87
  82. package/src/model/Subject.ts +6 -6
  83. package/src/model/decorators.ts +51 -22
  84. package/src/model/hydration-batch.ts +205 -0
  85. package/src/model/hydration-batching.test.ts +563 -0
  86. package/src/model/hydration.ts +349 -84
  87. package/src/model/index.ts +4 -1
  88. package/src/model/json-schema.ts +2 -2
  89. package/src/model/query-cache.test.ts +54 -0
  90. package/src/model/query-cache.ts +79 -0
  91. package/src/model/query-common.ts +1 -1
  92. package/src/model/query-sparql-batch.ts +301 -0
  93. package/src/model/query-sparql.test.ts +568 -0
  94. package/src/model/query-sparql.ts +820 -0
  95. package/src/model/{surreal-utils.ts → query-utils.ts} +44 -27
  96. package/src/model/relation-filtering.test.ts +15 -15
  97. package/src/model/sdna.ts +1 -1
  98. package/src/model/shacl-gen.ts +42 -17
  99. package/src/model/subscription-delta.test.ts +207 -0
  100. package/src/model/subscription-pool.ts +211 -0
  101. package/src/model/types.ts +53 -4
  102. package/src/perspectives/PerspectiveClient.test.ts +204 -0
  103. package/src/perspectives/PerspectiveClient.ts +41 -68
  104. package/src/perspectives/PerspectiveProxy.ts +244 -181
  105. package/src/perspectives/PerspectiveResolver.ts +0 -8
  106. package/src/perspectives/WakerSubscriptionManager.ts +8 -9
  107. package/src/runtime/RuntimeResolver.ts +43 -0
  108. package/src/shacl/SHACLFlow.ts +9 -9
  109. package/src/shacl/SHACLShape.ts +39 -39
  110. package/src/utils.ts +6 -6
  111. package/lib/src/model/query-surreal.d.ts +0 -44
  112. package/lib/src/model/query-surreal.js +0 -249
  113. package/src/language/LanguageContext.ts +0 -37
  114. package/src/model/query-surreal.ts +0 -280
  115. package/tsconfig-browser.json +0 -82
@@ -1,227 +1,41 @@
1
- import type { Address } from '../Address'
2
- import { DID } from '../DID';
3
- import type { Expression } from '../expression/Expression'
4
- import { Perspective, PerspectiveExpression } from '../perspectives/Perspective';
5
- import { PerspectiveDiff } from '../perspectives/PerspectiveDiff';
1
+ import { DID } from "../DID";
2
+ import { PerspectiveExpression } from "../perspectives/Perspective";
6
3
  import { InputType, Field, ObjectType } from "type-graphql";
7
- import { PerspectiveState } from '../perspectives/PerspectiveHandle';
8
4
 
9
- /** Interface of AD4M Languages
10
- *
11
- * Any JavaScript module that implements a create() function that returns an object that implements this interface
12
- * is a valid AD4M language.
13
- * So the AD4M-internal representation of a language is an object that implements this interface.
14
- *
15
- * Since there are a few different kinds of languages, this interface is split into optional sub-interfaces.
16
- * The only required property is the name of the language.
17
- *
18
- * The most usual kind of language is the "Expression Language", which is a language that can be used to create
19
- * and share Expressions.
20
- * For that, implement the expressionsAdapter and expressionUI interface.
21
- *
22
- * The second most common kind of language is the "Link Language", which is a language that builds the core
23
- * of AD4M Neighbourhoods.
24
- * For that, implement the linksAdapter interface.
5
+ /**
6
+ * # AD4M Language — client-side types
7
+ *
8
+ * This file only contains the client-visible types that the AD4M GraphQL
9
+ * API exposes on top of a running Language — interaction metadata, online
10
+ * agent records, and the telepresence-signal callback shape.
11
+ *
12
+ * **If you're authoring an AD4M Language**, you don't consume types from
13
+ * here — use [`@coasys/ad4m-ldk`](https://www.npmjs.com/package/@coasys/ad4m-ldk)
14
+ * (or the [Rust ALDK](https://crates.io/crates/ad4m-ldk)), which provide
15
+ * the capability traits, typed runtime-import wrappers, and authoring
16
+ * macros/helpers.
17
+ *
18
+ * The normative interface definition lives in
19
+ * [`docs-src/ad4m-lang.wit`](https://github.com/coasys/ad4m/blob/dev/docs-src/ad4m-lang.wit).
20
+ * The prose spec is
21
+ * [`docs-src/language-interface-spec.md`](https://github.com/coasys/ad4m/blob/dev/docs-src/language-interface-spec.md).
25
22
  */
26
- export interface Language {
27
- readonly name: string;
28
-
29
- /** Flagging expressions as immutable to enable
30
- * expression caching in the ad4m-executor
31
- */
32
- isImmutableExpression?(expression: Address): boolean;
33
-
34
- // Adapter implementations:
35
-
36
- /** ExpressionAdapter implements means of getting an Expression
37
- * by address and putting an expression
38
- */
39
- readonly expressionAdapter?: ExpressionAdapter;
40
-
41
- /** Interface for getting UI/web components for rendering Expressions of this Language */
42
- readonly expressionUI?: ExpressionUI;
43
-
44
- /** Interface of LinkLanguages for the core implementation of Neighbourhoods */
45
- readonly linksAdapter?: LinkSyncAdapter;
46
-
47
- /** Additional Interface of LinkLanguages that support telepresence features,
48
- * that is:
49
- * - seeing who is online and getting a status
50
- * - sending/receiveing p2p signals to other online agents without affecting
51
- * the shared Perspective of the Neighbourhood
52
- * (see TelepresenceAdapter for more details)
53
- */
54
- readonly telepresenceAdapter?: TelepresenceAdapter;
55
-
56
- /** Implementation of a Language that defines and stores Languages*/
57
- readonly languageAdapter?: LanguageAdapter;
58
-
59
- /** Optional adapter for getting Expressions by author */
60
- readonly getByAuthorAdapter?: GetByAuthorAdapter;
61
- /** Optional adapter for getting all Expressions */
62
- readonly getAllAdapter?: GetAllAdapter;
63
-
64
- /** Optional adapter for direct messaging between agents */
65
- readonly directMessageAdapter?: DirectMessageAdapter;
66
-
67
- /** Interface for providing UI components for the settings of this Language */
68
- readonly settingsUI?: SettingsUI;
69
-
70
- /** Optional function to make any cleanup/teardown if your language gets deleting in the ad4m-executor */
71
- readonly teardown?: () => void;
72
-
73
- /** All available interactions this agent could execute on given expression */
74
- interactions(expression: Address): Interaction[];
75
- }
76
-
77
- /** UI factories returning web components */
78
- export interface ExpressionUI {
79
- /** Returns JS code of a web component that renders the given expression */
80
- icon(): string;
81
- /** Returns JS code of a web component used to create new expressions */
82
- constructorIcon(): string;
83
- }
84
-
85
- export interface SettingsUI {
86
- settingsIcon(): string;
87
- }
88
- /** Interface for the most common Expression Languages */
89
- export interface ExpressionAdapter {
90
- /** Returns an Expression by address, or null if there is no Expression
91
- * with that given address
92
- */
93
- get(address: Address): Promise<Expression | null>;
94
-
95
- /** Strategy for putting an expression with needs to be different
96
- * for those two cases:
97
- * 1. PublicSharing means that this language supports the creation
98
- * and sharing of Expressions, which is the common use-case
99
- * 2. ReadOnlyLanguage means that the Language implements a pre-defined
100
- * set of expressions (which can be infinite or finite).
101
- * For example the url-iframe Language which directly maps URLs to
102
- * addresses - meaning every well formed URL is an address in this
103
- * Language. Or a potential Language implementing the verbs/predicates
104
- * of a spec like FOAF.
105
- */
106
- putAdapter: PublicSharing | ReadOnlyLanguage;
107
- }
108
-
109
- /** Implement this interface if your Language supports creation of sharing
110
- * of Expressions.
111
- * See ExpressionAdapter
112
- */
113
- export interface PublicSharing {
114
- /** Create an Expression and shares it.
115
- * Return the Expression's address.
116
- * @param content is the object created by the constructorIcon component
117
- */
118
- createPublic(content: object): Promise<Address>;
119
- }
120
-
121
- /** Implement this interface if your Language is defined over a static
122
- * set of pre-defined Expressions.
123
- */
124
- export interface ReadOnlyLanguage {
125
- /** This just calculates the address of an object
126
- * @param content is the object created by the constructorIcon component
127
- */
128
- addressOf(content: object): Promise<Address>;
129
- }
130
-
131
- export interface LanguageAdapter {
132
- getLanguageSource(address: Address): Promise<string>;
133
- }
134
23
 
135
- // Implement this if your Language supports retrieval of all Expressions
136
- // authored by a given agent
137
- export interface GetByAuthorAdapter {
138
- /// Get expressions authored by a given Agent/Identity
139
- getByAuthor(author: DID, count: number, page: number): Promise<Expression[] | null>;
140
- }
141
-
142
- // Implement this if your Language supports retrieval of all Expressions
143
- // stored in the space of that Language.
144
- // Might not be trivial (without trade-off) for Holochain or DHTs
145
- // in general - hence not a required interface.
146
- export interface GetAllAdapter {
147
- /// Get expressions authored by a given Agent/Identity
148
- getAll(filter: any, count: number, page: number): Promise<Expression[] | null>;
149
- }
150
-
151
- export type PerspectiveDiffObserver = (diff: PerspectiveDiff)=>void;
152
- export type SyncStateChangeObserver = (state: PerspectiveState)=>void;
153
-
154
- /** Interface for "Link Languages" that facilitate the synchronization
155
- * between agents' local Perspectives inside a Neighbourhood.
156
- * The assumption is that every version of the shared Perspective
157
- * is labeled with a unique revision string.
158
- * Changes are committed and retrieved through diffs.
159
- * Think of a LinkSyncAdapter as a git branch to which agents commit
160
- * their changes to and pull diffs from their current revision
161
- * to the latest one.
162
- */
163
- export interface LinkSyncAdapter {
164
- writable(): boolean;
165
- public(): boolean;
166
- others(): Promise<DID[]>;
167
-
168
- /** What revision are we on now -> what changes are included in output of render() */
169
- currentRevision(): Promise<string>;
170
-
171
- /**
172
- * Check for and get new changes,
173
- * notify others of local changes.
174
- * This function will be called every
175
- * few seconds by the ad4m-executor.
176
- * */
177
- sync(): Promise<PerspectiveDiff>;
178
-
179
- /** Returns the full, rendered Perspective at currentRevision */
180
- render(): Promise<Perspective>;
181
-
182
- /** Publish changes */
183
- commit(diff: PerspectiveDiff): Promise<string>;
184
-
185
- /** Get push notification when a diff got published */
186
- addCallback(callback: PerspectiveDiffObserver);
187
-
188
- /** Add a sync state callback method */
189
- addSyncStateChangeCallback(callback: SyncStateChangeObserver);
190
-
191
- /**
192
- * Set the local agents (DIDs) that own this perspective/neighbourhood.
193
- * This is used to determine which agents should be registered in the DHT.
194
- * Optional - if not implemented, all local agents may be registered.
195
- *
196
- * This is a temporary hack to support multiple users on one node joining the same neighbourhood.
197
- * Once we migrate the LanguageController to Rust and run Languages per user, each user will get their
198
- * own language instance and we won't need to explicitly set local agents. This will provide better
199
- * isolation and avoid the need to share language state between users.
200
- */
201
- setLocalAgents?(agents: DID[]): void;
202
- }
203
-
204
- export type MessageCallback = (message: PerspectiveExpression) => void;
205
- export type StatusCallback = (caller: DID) => Perspective;
206
- export interface DirectMessageAdapter {
207
- recipient(): DID;
208
-
209
- status(): Promise<PerspectiveExpression | void>;
210
- sendP2P(message: Perspective): Promise<PerspectiveExpression|void>;
211
- sendInbox(message: Perspective): Promise<PerspectiveExpression|void>;
212
-
213
- setStatus(status: PerspectiveExpression);
214
- inbox(filter?: string): Promise<PerspectiveExpression[]>
215
- addMessageCallback(callback: MessageCallback);
216
- }
24
+ // ----- Interaction metadata --------------------------------------------------
25
+ //
26
+ // Languages optionally publish a list of user-invocable actions per
27
+ // Expression ("interactions"). The runtime surfaces these to UIs via
28
+ // GraphQL, which is why `InteractionParameter` / `InteractionMeta` /
29
+ // `InteractionCall` need the type-graphql decorators — they cross the
30
+ // GraphQL boundary as first-class objects.
217
31
 
218
32
  @ObjectType()
219
33
  export class InteractionParameter {
220
34
  @Field()
221
- name: string
35
+ name: string;
222
36
 
223
37
  @Field()
224
- type: string
38
+ type: string;
225
39
  }
226
40
 
227
41
  @ObjectType()
@@ -232,47 +46,57 @@ export class InteractionMeta {
232
46
  @Field()
233
47
  name: string;
234
48
 
235
- @Field(type => [InteractionParameter])
236
- parameters: InteractionParameter[]
49
+ @Field(() => [InteractionParameter])
50
+ parameters: InteractionParameter[];
237
51
  }
52
+
53
+ /**
54
+ * Runtime-side interaction object. The runtime constructs one of these
55
+ * from a Language's `interactions(address)` description and exposes
56
+ * `execute()` to UI callers. Language authors describe interactions
57
+ * via the ALDK, not by constructing this type directly.
58
+ */
238
59
  export interface Interaction {
239
60
  readonly label: string;
240
61
  readonly name: string;
241
62
  readonly parameters: InteractionParameter[];
242
- execute(parameters: object): Promise<string|null>;
63
+ execute(parameters: object): Promise<string | null>;
243
64
  }
244
65
 
245
66
  @InputType()
246
67
  export class InteractionCall {
247
68
  @Field()
248
69
  name: string;
70
+
249
71
  @Field()
250
72
  parametersStringified: string;
251
73
 
252
74
  public get parameters(): object {
253
- return JSON.parse(this.parametersStringified)
75
+ return JSON.parse(this.parametersStringified);
254
76
  }
255
77
 
256
78
  constructor(name: string, parameters: object) {
257
- this.name = name
258
- this.parametersStringified = JSON.stringify(parameters)
79
+ this.name = name;
80
+ this.parametersStringified = JSON.stringify(parameters);
259
81
  }
260
82
  }
261
83
 
84
+ // ----- Telepresence ----------------------------------------------------------
85
+
262
86
  @ObjectType()
263
87
  export class OnlineAgent {
264
88
  @Field()
265
- did: DID
89
+ did: DID;
90
+
266
91
  @Field()
267
- status: PerspectiveExpression
92
+ status: PerspectiveExpression;
268
93
  }
269
94
 
270
- export type TelepresenceSignalCallback = (payload: PerspectiveExpression, recipientDid?: string) => void;
271
- export interface TelepresenceAdapter {
272
- setOnlineStatus(status: PerspectiveExpression): Promise<void>;
273
- getOnlineAgents(): Promise<OnlineAgent[]>;
274
-
275
- sendSignal(remoteAgentDid: string, payload: PerspectiveExpression): Promise<object>;
276
- sendBroadcast(payload: PerspectiveExpression): Promise<object>;
277
- registerSignalCallback(callback: TelepresenceSignalCallback): Promise<void>;
278
- }
95
+ /**
96
+ * Callback shape used by the client to receive telepresence signals
97
+ * from a Neighbourhood's link Language.
98
+ */
99
+ export type TelepresenceSignalCallback = (
100
+ payload: PerspectiveExpression,
101
+ recipientDid?: string,
102
+ ) => void;