@coasys/ad4m 0.12.0-rc1-dev.4 → 0.12.0-rc2

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 (166) hide show
  1. package/lib/index.cjs +5052 -4446
  2. package/lib/index.js +5019 -4442
  3. package/lib/src/agent/AgentClient.d.ts +4 -0
  4. package/lib/src/agent/AgentClient.js +34 -0
  5. package/lib/src/index.d.ts +2 -3
  6. package/lib/src/index.js +2 -3
  7. package/lib/src/model/Ad4mModel.d.ts +8 -782
  8. package/lib/src/model/Ad4mModel.js +160 -2354
  9. package/lib/src/model/ModelQueryBuilder.d.ts +370 -0
  10. package/lib/src/model/ModelQueryBuilder.js +556 -0
  11. package/lib/src/model/decorators.d.ts +71 -23
  12. package/lib/src/model/decorators.js +133 -384
  13. package/lib/src/model/hydration.d.ts +102 -0
  14. package/lib/src/model/hydration.js +709 -0
  15. package/lib/src/model/index.d.ts +20 -0
  16. package/lib/src/model/index.js +20 -0
  17. package/lib/src/model/{schema/fromJSONSchema.d.ts → json-schema.d.ts} +45 -12
  18. package/lib/src/model/json-schema.js +326 -0
  19. package/lib/src/model/prolog-facts.d.ts +37 -0
  20. package/lib/src/model/{prolog/generatePrologFacts.js → prolog-facts.js} +47 -52
  21. package/lib/src/model/query-common.d.ts +14 -0
  22. package/lib/src/model/query-common.js +36 -0
  23. package/lib/src/model/query-prolog.d.ts +15 -0
  24. package/lib/src/model/query-prolog.js +140 -0
  25. package/lib/src/model/query-surreal.d.ts +44 -0
  26. package/lib/src/model/query-surreal.js +249 -0
  27. package/lib/src/model/relation-filtering.test.js +838 -0
  28. package/lib/src/model/sdna.d.ts +14 -0
  29. package/lib/src/model/sdna.js +141 -0
  30. package/lib/src/model/shacl-gen.d.ts +31 -0
  31. package/lib/src/model/shacl-gen.js +246 -0
  32. package/lib/src/model/surreal-utils.d.ts +42 -0
  33. package/lib/src/model/surreal-utils.js +128 -0
  34. package/lib/src/model/types.d.ts +75 -96
  35. package/lib/src/model/types.js +4 -4
  36. package/lib/src/model/util.d.ts +4 -5
  37. package/lib/src/model/util.js +12 -32
  38. package/lib/src/perspectives/PerspectiveClient.d.ts +1 -1
  39. package/lib/src/perspectives/PerspectiveProxy.d.ts +1 -1
  40. package/lib/src/perspectives/WakerSubscriptionManager.d.ts +79 -0
  41. package/lib/src/perspectives/WakerSubscriptionManager.js +196 -0
  42. package/lib/src/runtime/RuntimeResolver.d.ts +14 -0
  43. package/lib/src/runtime/RuntimeResolver.js +73 -0
  44. package/lib/src/schema.gql +14 -0
  45. package/lib/src/shacl/SHACLShape.d.ts +23 -0
  46. package/lib/src/shacl/SHACLShape.js +45 -0
  47. package/lib/src/typeDefs.js +14 -0
  48. package/package.json +13 -8
  49. package/src/agent/AgentClient.ts +45 -0
  50. package/src/index.ts +2 -3
  51. package/src/model/Ad4mModel.ts +1089 -3686
  52. package/src/model/ModelQueryBuilder.ts +617 -0
  53. package/src/model/Subject.ts +1 -1
  54. package/src/model/decorators.ts +218 -453
  55. package/src/model/hydration.ts +796 -0
  56. package/src/model/index.ts +21 -0
  57. package/src/model/json-schema.ts +424 -0
  58. package/src/model/prolog-facts.ts +145 -0
  59. package/src/model/query-common.ts +48 -0
  60. package/src/model/query-prolog.ts +148 -0
  61. package/src/model/query-surreal.ts +280 -0
  62. package/src/model/relation-filtering.test.ts +803 -0
  63. package/src/model/sdna.ts +170 -0
  64. package/src/model/shacl-gen.ts +292 -0
  65. package/src/model/surreal-utils.ts +147 -0
  66. package/src/model/types.ts +182 -0
  67. package/src/model/util.ts +13 -36
  68. package/src/perspectives/PerspectiveClient.ts +1 -1
  69. package/src/perspectives/PerspectiveProxy.ts +1 -1
  70. package/src/perspectives/WakerSubscriptionManager.ts +292 -0
  71. package/src/runtime/RuntimeResolver.ts +53 -0
  72. package/src/shacl/SHACLShape.ts +83 -0
  73. package/lib/src/Ad4mClient.test.js +0 -1204
  74. package/lib/src/Literal.test.d.ts +0 -1
  75. package/lib/src/Literal.test.js +0 -41
  76. package/lib/src/model/mutation.d.ts +0 -81
  77. package/lib/src/model/mutation.js +0 -317
  78. package/lib/src/model/parentUtils.d.ts +0 -32
  79. package/lib/src/model/parentUtils.js +0 -64
  80. package/lib/src/model/prolog/generatePrologFacts.d.ts +0 -36
  81. package/lib/src/model/prolog/index.d.ts +0 -1
  82. package/lib/src/model/prolog/index.js +0 -1
  83. package/lib/src/model/query/ModelQueryBuilder.d.ts +0 -82
  84. package/lib/src/model/query/ModelQueryBuilder.js +0 -115
  85. package/lib/src/model/query/QueryBuilder.d.ts +0 -101
  86. package/lib/src/model/query/QueryBuilder.js +0 -193
  87. package/lib/src/model/query/SurrealQueryBuilder.d.ts +0 -48
  88. package/lib/src/model/query/SurrealQueryBuilder.js +0 -371
  89. package/lib/src/model/query/fetchInstance.d.ts +0 -24
  90. package/lib/src/model/query/fetchInstance.js +0 -144
  91. package/lib/src/model/query/hydration.d.ts +0 -54
  92. package/lib/src/model/query/hydration.js +0 -214
  93. package/lib/src/model/query/operations.d.ts +0 -59
  94. package/lib/src/model/query/operations.js +0 -384
  95. package/lib/src/model/query/snapshot.d.ts +0 -59
  96. package/lib/src/model/query/snapshot.js +0 -106
  97. package/lib/src/model/query/surrealCompiler.d.ts +0 -42
  98. package/lib/src/model/query/surrealCompiler.js +0 -304
  99. package/lib/src/model/schema/fromJSONSchema.js +0 -264
  100. package/lib/src/model/schema/metadata.d.ts +0 -15
  101. package/lib/src/model/schema/metadata.js +0 -112
  102. package/lib/src/model/subscription.d.ts +0 -47
  103. package/lib/src/model/subscription.js +0 -231
  104. package/lib/src/model/transaction.d.ts +0 -27
  105. package/lib/src/model/transaction.js +0 -32
  106. package/lib/src/shims/reflect-metadata.d.ts +0 -0
  107. package/lib/src/shims/type-graphql.d.ts +0 -32
  108. package/lib/src/src/Ad4mClient.d.ts +0 -28
  109. package/lib/src/src/Address.d.ts +0 -1
  110. package/lib/src/src/DID.d.ts +0 -1
  111. package/lib/src/src/Exception.d.ts +0 -7
  112. package/lib/src/src/Literal.d.ts +0 -7
  113. package/lib/src/src/PubSub.d.ts +0 -17
  114. package/lib/src/src/SmartLiteral.d.ts +0 -12
  115. package/lib/src/src/agent/Agent.d.ts +0 -110
  116. package/lib/src/src/agent/AgentClient.d.ts +0 -62
  117. package/lib/src/src/agent/AgentResolver.d.ts +0 -30
  118. package/lib/src/src/agent/AgentStatus.d.ts +0 -8
  119. package/lib/src/src/ai/AIClient.d.ts +0 -32
  120. package/lib/src/src/ai/AIResolver.d.ts +0 -75
  121. package/lib/src/src/ai/Tasks.d.ts +0 -37
  122. package/lib/src/src/buildSchema.d.ts +0 -1
  123. package/lib/src/src/expression/Expression.d.ts +0 -28
  124. package/lib/src/src/expression/ExpressionClient.d.ts +0 -13
  125. package/lib/src/src/expression/ExpressionRef.d.ts +0 -9
  126. package/lib/src/src/expression/ExpressionResolver.d.ts +0 -10
  127. package/lib/src/src/index.d.ts +0 -35
  128. package/lib/src/src/jestSetup.d.ts +0 -1
  129. package/lib/src/src/language/Icon.d.ts +0 -4
  130. package/lib/src/src/language/Language.d.ts +0 -206
  131. package/lib/src/src/language/LanguageClient.d.ts +0 -17
  132. package/lib/src/src/language/LanguageContext.d.ts +0 -37
  133. package/lib/src/src/language/LanguageHandle.d.ts +0 -9
  134. package/lib/src/src/language/LanguageMeta.d.ts +0 -35
  135. package/lib/src/src/language/LanguageRef.d.ts +0 -6
  136. package/lib/src/src/language/LanguageResolver.d.ts +0 -19
  137. package/lib/src/src/links/Links.d.ts +0 -39
  138. package/lib/src/src/links/Links.test.d.ts +0 -1
  139. package/lib/src/src/model/Ad4mModel.d.ts +0 -1438
  140. package/lib/src/src/model/Ad4mModel.test.d.ts +0 -1
  141. package/lib/src/src/model/Subject.d.ts +0 -25
  142. package/lib/src/src/model/decorators.d.ts +0 -545
  143. package/lib/src/src/model/util.d.ts +0 -12
  144. package/lib/src/src/neighbourhood/Neighbourhood.d.ts +0 -10
  145. package/lib/src/src/neighbourhood/NeighbourhoodClient.d.ts +0 -25
  146. package/lib/src/src/neighbourhood/NeighbourhoodProxy.d.ts +0 -19
  147. package/lib/src/src/neighbourhood/NeighbourhoodProxy.test.d.ts +0 -1
  148. package/lib/src/src/neighbourhood/NeighbourhoodResolver.d.ts +0 -24
  149. package/lib/src/src/perspectives/LinkQuery.d.ts +0 -11
  150. package/lib/src/src/perspectives/Perspective.d.ts +0 -38
  151. package/lib/src/src/perspectives/Perspective.test.d.ts +0 -1
  152. package/lib/src/src/perspectives/PerspectiveClient.d.ts +0 -97
  153. package/lib/src/src/perspectives/PerspectiveDiff.d.ts +0 -9
  154. package/lib/src/src/perspectives/PerspectiveHandle.d.ts +0 -18
  155. package/lib/src/src/perspectives/PerspectiveProxy.d.ts +0 -865
  156. package/lib/src/src/perspectives/PerspectiveResolver.d.ts +0 -57
  157. package/lib/src/src/runtime/RuntimeClient.d.ts +0 -56
  158. package/lib/src/src/runtime/RuntimeResolver.d.ts +0 -132
  159. package/lib/src/src/shacl/SHACLFlow.d.ts +0 -171
  160. package/lib/src/src/shacl/SHACLFlow.test.d.ts +0 -1
  161. package/lib/src/src/shacl/SHACLShape.d.ts +0 -117
  162. package/lib/src/src/shacl/SHACLShape.test.d.ts +0 -1
  163. package/lib/src/src/typeDefs.d.ts +0 -1
  164. package/lib/src/src/unwrapApolloResult.d.ts +0 -2
  165. package/lib/src/src/utils.d.ts +0 -25
  166. /package/lib/src/{Ad4mClient.test.d.ts → model/relation-filtering.test.d.ts} +0 -0
@@ -0,0 +1,102 @@
1
+ /**
2
+ * hydration.ts — Instance hydration helpers extracted from Ad4mModel.
3
+ *
4
+ * Pure / stateless functions that populate Ad4mModel instances from
5
+ * raw link arrays, Prolog tuples, or SurrealDB rows. None of these
6
+ * functions depend on the `Ad4mModel` class at runtime — they accept
7
+ * the instance, metadata, or perspective as explicit parameters.
8
+ */
9
+ import type { PerspectiveProxy } from "../perspectives/PerspectiveProxy";
10
+ import type { PropertyMetadata, ModelMetadata, ValueTuple, WhereCondition, IncludeMap } from "./types";
11
+ /**
12
+ * Normalize a value for snapshot storage.
13
+ * Arrays of model instances are reduced to their `.id` strings so that
14
+ * dirty-tracking compares stable identifiers instead of object references.
15
+ */
16
+ export declare function normalizeValue(value: any): any;
17
+ /**
18
+ * Checks if a value matches a where-condition (for post-query filtering).
19
+ */
20
+ export declare function matchesCondition(value: any, condition: WhereCondition): boolean;
21
+ /**
22
+ * Resolves a single property value from a raw link target string.
23
+ *
24
+ * Handles expression resolution, literal URI parsing, primitive
25
+ * type coercion, and optional transform functions.
26
+ *
27
+ * @param target - The raw target string from the link
28
+ * @param propMeta - Property metadata from the decorator registry
29
+ * @param perspective - The perspective for expression resolution
30
+ * @param expectedType - Optional JS typeof hint for coercion (e.g. 'number')
31
+ * @returns The resolved value
32
+ */
33
+ export declare function hydratePropertyValue(target: string, propMeta: PropertyMetadata, perspective: PerspectiveProxy, expectedType?: string): Promise<any>;
34
+ /**
35
+ * Hydrates an instance from an array of raw links.
36
+ *
37
+ * Processes properties (latest-wins semantics), relations
38
+ * (chronological accumulation), and timestamps/author in a single
39
+ * pass over the links array.
40
+ *
41
+ * @param instance - The blank model instance to populate
42
+ * @param links - Array of link objects (predicate, target, author?, timestamp?)
43
+ * @param metadata - Model metadata from `getModelMetadata()`
44
+ * @param perspective - The perspective for expression resolution
45
+ * @param requestedProperties - Optional sparse fieldset; when provided, only these
46
+ * property names are hydrated (relations are unaffected).
47
+ * Omit or pass `undefined` to hydrate all properties.
48
+ */
49
+ export declare function hydrateFromLinks(instance: any, links: Array<{
50
+ predicate: string;
51
+ target: string;
52
+ author?: string;
53
+ timestamp?: string | number;
54
+ }>, metadata: ModelMetadata, perspective: PerspectiveProxy, requestedProperties?: string[]): Promise<void>;
55
+ /**
56
+ * Assigns decoded Prolog property values to an instance.
57
+ *
58
+ * Handles UTF-8 byte sequence reconstruction, expression resolution,
59
+ * transform functions, and read-only property filtering.
60
+ */
61
+ export declare function assignValuesToInstance(perspective: PerspectiveProxy, instance: any, values: ValueTuple[]): Promise<void>;
62
+ /**
63
+ * Builds a SurrealQL conformance getter for a relation whose `target` model
64
+ * is known but no explicit `getter` string was supplied.
65
+ *
66
+ * The generated getter traverses outgoing links matching the relation's
67
+ * predicate and then filters the target nodes to only those that conform to
68
+ * the target model's shape (required properties / flags).
69
+ *
70
+ * Delegates to the shared `buildConformanceFilter()` utility in decorators.ts
71
+ * so the same logic is used at shape-definition time and at query time.
72
+ *
73
+ * @param relationPredicate - The relation's predicate URI (e.g. "flux://entry_type")
74
+ * @param targetClass - The target model class (result of calling the `target()` thunk)
75
+ * @returns A SurrealQL expression string, or `undefined` if no conformance
76
+ * conditions could be derived from the target model.
77
+ */
78
+ export declare function buildConformanceGetter(relationPredicate: string, targetClass: any): string | undefined;
79
+ /**
80
+ * Evaluates custom SurrealQL getters for properties and relations on a specific instance.
81
+ *
82
+ * For relations that declare a `target` but no explicit `getter`, a conformance
83
+ * getter is auto-generated from the target model's metadata (unless `filter: false`).
84
+ */
85
+ export declare function evaluateCustomGettersForInstance(instance: any, perspective: PerspectiveProxy, metadata: ModelMetadata, options?: {
86
+ requestedProperties?: string[];
87
+ include?: Record<string, any>;
88
+ }): Promise<void>;
89
+ /**
90
+ * Hydrates relation fields on instances according to the provided IncludeMap.
91
+ *
92
+ * For each relation listed in `includeMap`, the raw expression-URI strings
93
+ * stored on the instance are replaced with fully-hydrated model instances
94
+ * (fetched via the relation's `target()` class). Nested IncludeMaps are
95
+ * supported for multi-level eager loading.
96
+ *
97
+ * @param modelClass - The model class whose relation metadata to read
98
+ * @param instances - The instances whose relations should be hydrated
99
+ * @param perspective - The perspective to fetch related instances from
100
+ * @param includeMap - Describes which relations to hydrate
101
+ */
102
+ export declare function hydrateRelations<T>(modelClass: any, instances: T[], perspective: PerspectiveProxy, includeMap: IncludeMap | undefined): Promise<void>;