@coasys/ad4m 0.12.1-dev → 0.13.0-test-2

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 (97) hide show
  1. package/lib/index.cjs +1469 -781
  2. package/lib/index.js +1453 -779
  3. package/lib/src/Literal.js +6 -5
  4. package/lib/src/agent/AgentClient.d.ts +8 -1
  5. package/lib/src/agent/AgentClient.js +73 -2
  6. package/lib/src/expression/ExpressionRef.js +2 -2
  7. package/lib/src/language/Language.d.ts +41 -3
  8. package/lib/src/model/Ad4mModel.d.ts +28 -28
  9. package/lib/src/model/Ad4mModel.js +129 -101
  10. package/lib/src/model/Ad4mModel.test.js +1543 -535
  11. package/lib/src/model/ModelQueryBuilder.d.ts +48 -34
  12. package/lib/src/model/ModelQueryBuilder.js +163 -78
  13. package/lib/src/model/Subject.js +6 -6
  14. package/lib/src/model/decorators.d.ts +14 -8
  15. package/lib/src/model/decorators.js +41 -14
  16. package/lib/src/model/hydration-batch.d.ts +34 -0
  17. package/lib/src/model/hydration-batch.js +147 -0
  18. package/lib/src/model/hydration.d.ts +3 -3
  19. package/lib/src/model/hydration.js +106 -36
  20. package/lib/src/model/index.d.ts +4 -1
  21. package/lib/src/model/index.js +4 -1
  22. package/lib/src/model/json-schema.js +2 -2
  23. package/lib/src/model/query-cache.d.ts +30 -0
  24. package/lib/src/model/query-cache.js +66 -0
  25. package/lib/src/model/query-cache.test.d.ts +1 -0
  26. package/lib/src/model/query-cache.test.js +43 -0
  27. package/lib/src/model/query-common.d.ts +1 -1
  28. package/lib/src/model/query-common.js +1 -1
  29. package/lib/src/model/query-sparql-batch.d.ts +17 -0
  30. package/lib/src/model/query-sparql-batch.js +260 -0
  31. package/lib/src/model/query-sparql.d.ts +47 -0
  32. package/lib/src/model/query-sparql.js +336 -0
  33. package/lib/src/model/query-utils.d.ts +45 -0
  34. package/lib/src/model/query-utils.js +140 -0
  35. package/lib/src/model/relation-filtering.test.js +15 -15
  36. package/lib/src/model/sdna.js +1 -1
  37. package/lib/src/model/shacl-gen.js +42 -18
  38. package/lib/src/model/subscription-pool.d.ts +39 -0
  39. package/lib/src/model/subscription-pool.js +119 -0
  40. package/lib/src/model/types.d.ts +3 -3
  41. package/lib/src/model/types.js +1 -1
  42. package/lib/src/perspectives/PerspectiveClient.d.ts +1 -17
  43. package/lib/src/perspectives/PerspectiveClient.js +5 -57
  44. package/lib/src/perspectives/PerspectiveProxy.d.ts +51 -30
  45. package/lib/src/perspectives/PerspectiveProxy.js +224 -177
  46. package/lib/src/perspectives/PerspectiveResolver.d.ts +0 -1
  47. package/lib/src/perspectives/PerspectiveResolver.js +0 -11
  48. package/lib/src/perspectives/WakerSubscriptionManager.d.ts +3 -3
  49. package/lib/src/perspectives/WakerSubscriptionManager.js +7 -8
  50. package/lib/src/runtime/RuntimeClient.d.ts +2 -0
  51. package/lib/src/runtime/RuntimeClient.js +17 -0
  52. package/lib/src/runtime/RuntimeResolver.d.ts +14 -0
  53. package/lib/src/runtime/RuntimeResolver.js +84 -0
  54. package/lib/src/schema.gql +14 -1
  55. package/lib/src/shacl/SHACLFlow.d.ts +1 -1
  56. package/lib/src/shacl/SHACLFlow.js +9 -9
  57. package/lib/src/shacl/SHACLShape.d.ts +1 -1
  58. package/lib/src/shacl/SHACLShape.js +38 -38
  59. package/lib/src/typeDefs.js +14 -1
  60. package/lib/src/utils.d.ts +6 -6
  61. package/lib/src/utils.js +6 -6
  62. package/package.json +1 -1
  63. package/src/Literal.test.ts +10 -5
  64. package/src/Literal.ts +6 -5
  65. package/src/agent/AgentClient.ts +81 -1
  66. package/src/expression/ExpressionRef.ts +2 -2
  67. package/src/language/Language.ts +48 -3
  68. package/src/model/Ad4mModel.test.ts +1515 -565
  69. package/src/model/Ad4mModel.ts +142 -102
  70. package/src/model/ModelQueryBuilder.ts +185 -86
  71. package/src/model/Subject.ts +6 -6
  72. package/src/model/decorators.ts +51 -22
  73. package/src/model/hydration-batch.ts +205 -0
  74. package/src/model/hydration.ts +102 -39
  75. package/src/model/index.ts +4 -1
  76. package/src/model/json-schema.ts +2 -2
  77. package/src/model/query-cache.test.ts +54 -0
  78. package/src/model/query-cache.ts +79 -0
  79. package/src/model/query-common.ts +1 -1
  80. package/src/model/query-sparql-batch.ts +301 -0
  81. package/src/model/query-sparql.ts +363 -0
  82. package/src/model/{surreal-utils.ts → query-utils.ts} +40 -27
  83. package/src/model/relation-filtering.test.ts +15 -15
  84. package/src/model/sdna.ts +1 -1
  85. package/src/model/shacl-gen.ts +42 -17
  86. package/src/model/subscription-pool.ts +163 -0
  87. package/src/model/types.ts +3 -3
  88. package/src/perspectives/PerspectiveClient.ts +5 -61
  89. package/src/perspectives/PerspectiveProxy.ts +226 -181
  90. package/src/perspectives/PerspectiveResolver.ts +0 -8
  91. package/src/perspectives/WakerSubscriptionManager.ts +8 -9
  92. package/src/runtime/RuntimeClient.ts +19 -0
  93. package/src/runtime/RuntimeResolver.ts +58 -0
  94. package/src/shacl/SHACLFlow.ts +9 -9
  95. package/src/shacl/SHACLShape.ts +39 -39
  96. package/src/utils.ts +6 -6
  97. package/src/model/query-surreal.ts +0 -280
@@ -5,6 +5,7 @@ import { Perspective, PerspectiveExpression } from '../perspectives/Perspective'
5
5
  import { PerspectiveDiff } from '../perspectives/PerspectiveDiff';
6
6
  import { InputType, Field, ObjectType } from "type-graphql";
7
7
  import { PerspectiveState } from '../perspectives/PerspectiveHandle';
8
+ import { LinkQuery } from '../perspectives/LinkQuery';
8
9
 
9
10
  /** Interface of AD4M Languages
10
11
  *
@@ -41,8 +42,14 @@ export interface Language {
41
42
  /** Interface for getting UI/web components for rendering Expressions of this Language */
42
43
  readonly expressionUI?: ExpressionUI;
43
44
 
45
+ // TODO: Rename linksAdapter to perspectiveSyncAdapter needs a lot of changes elsewhere...
44
46
  /** Interface of LinkLanguages for the core implementation of Neighbourhoods */
45
- readonly linksAdapter?: LinkSyncAdapter;
47
+ readonly perspectiveSyncAdapter?: PerspectiveSyncAdapter;
48
+
49
+ /** Interface for Languages that implement a query return a Perspective (snapshot)
50
+ * Used for back-links and wrapping of APIs that implement queries.
51
+ */
52
+ readonly pespectiveQueryAdapter?: PerspectiveQueryAdapter;
46
53
 
47
54
  /** Additional Interface of LinkLanguages that support telepresence features,
48
55
  * that is:
@@ -156,11 +163,11 @@ export type SyncStateChangeObserver = (state: PerspectiveState)=>void;
156
163
  * The assumption is that every version of the shared Perspective
157
164
  * is labeled with a unique revision string.
158
165
  * Changes are committed and retrieved through diffs.
159
- * Think of a LinkSyncAdapter as a git branch to which agents commit
166
+ * Think of a PerspectiveSyncAdapter as a git branch to which agents commit
160
167
  * their changes to and pull diffs from their current revision
161
168
  * to the latest one.
162
169
  */
163
- export interface LinkSyncAdapter {
170
+ export interface PerspectiveSyncAdapter {
164
171
  writable(): boolean;
165
172
  public(): boolean;
166
173
  others(): Promise<DID[]>;
@@ -276,3 +283,41 @@ export interface TelepresenceAdapter {
276
283
  sendBroadcast(payload: PerspectiveExpression): Promise<object>;
277
284
  registerSignalCallback(callback: TelepresenceSignalCallback): Promise<void>;
278
285
  }
286
+
287
+
288
+ /** Interface for Languages that implement queries returning links, i.e. a Perspective (-snapshot)
289
+ * Main differentiation between these Languages and LinkLanguages is that this enables
290
+ * access to other shared perspectives without forcing a full-sync.
291
+ *
292
+ * All PerspectiveQuery Languages are supposed to implement `linkQuery` which is a simple graph query
293
+ * specifying non or all of source, predicate, target of the links we want to get.
294
+ * This is enough to implement simple back-links.
295
+ *
296
+ * Prolog queries are optional since this requires a Prolog engine to be available.
297
+ *
298
+ */
299
+ export interface PerspectiveQueryAdapter {
300
+ /** Same semantic as PerspectiveProxy.get(LinkQuery) */
301
+ linkQuery(query: LinkQuery): Promise<Perspective>;
302
+
303
+ /** Tells ADAM if Prolog queries are implemented by this Language.
304
+ * If not, prologQuery won't be used, instead in some circumstances,
305
+ * linkQuery() might be called with an all-query, followed by using
306
+ * ADAM's internal Prolog engine on the result.
307
+ */
308
+ supportsPrologQueries(): boolean;
309
+
310
+ /** Same semantic as PerspectiveProxy.infer, will return plain Prolog results */
311
+ infer(prologQuery: string): Promise<any>
312
+
313
+ /** Specify which links shall be returned through Prolog.
314
+ * Assumes unbound variables in query that describe a LinkExpression:
315
+ * - Source
316
+ * - Predicate
317
+ * - Target
318
+ * - Author
319
+ * - Timestamp
320
+ * Will construct a Perspective where each link is a solution to the query.
321
+ */
322
+ prologQuery(query: string): Promise<Perspective>;
323
+ }