@coasys/ad4m 0.13.0-test-8-profile-cache-fix → 0.13.0-test-9

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 (221) hide show
  1. package/lib/index.cjs +136 -18
  2. package/lib/index.js +136 -18
  3. package/lib/src/generated/rest/AIModelLoadingStatus.d.ts +7 -0
  4. package/lib/src/generated/rest/AIModelLoadingStatus.js +2 -0
  5. package/lib/src/generated/rest/AddAgentInfosRequest.d.ts +3 -0
  6. package/lib/src/generated/rest/AddAgentInfosRequest.js +2 -0
  7. package/lib/src/generated/rest/AddLinkExpressionRequest.d.ts +6 -0
  8. package/lib/src/generated/rest/AddLinkExpressionRequest.js +1 -0
  9. package/lib/src/generated/rest/AddLinkRequest.d.ts +6 -0
  10. package/lib/src/generated/rest/AddLinkRequest.js +1 -0
  11. package/lib/src/generated/rest/AddLinksBulkRequest.d.ts +6 -0
  12. package/lib/src/generated/rest/AddLinksBulkRequest.js +1 -0
  13. package/lib/src/generated/rest/AddSdnaRequest.d.ts +6 -0
  14. package/lib/src/generated/rest/AddSdnaRequest.js +2 -0
  15. package/lib/src/generated/rest/ApplyTemplateRequest.d.ts +4 -0
  16. package/lib/src/generated/rest/ApplyTemplateRequest.js +2 -0
  17. package/lib/src/generated/rest/AuthInfoInput.d.ts +10 -0
  18. package/lib/src/generated/rest/AuthInfoInput.js +1 -0
  19. package/lib/src/generated/rest/BroadcastRequest.d.ts +6 -0
  20. package/lib/src/generated/rest/BroadcastRequest.js +1 -0
  21. package/lib/src/generated/rest/CapabilityInput.d.ts +5 -0
  22. package/lib/src/generated/rest/CapabilityInput.js +1 -0
  23. package/lib/src/generated/rest/CommitBatchRequest.d.ts +3 -0
  24. package/lib/src/generated/rest/CommitBatchRequest.js +2 -0
  25. package/lib/src/generated/rest/ComputeLogEntry.d.ts +9 -0
  26. package/lib/src/generated/rest/ComputeLogEntry.js +2 -0
  27. package/lib/src/generated/rest/CreateExpressionRequest.d.ts +4 -0
  28. package/lib/src/generated/rest/CreateExpressionRequest.js +2 -0
  29. package/lib/src/generated/rest/CreatePerspectiveRequest.d.ts +3 -0
  30. package/lib/src/generated/rest/CreatePerspectiveRequest.js +2 -0
  31. package/lib/src/generated/rest/CreateSubjectRequest.d.ts +6 -0
  32. package/lib/src/generated/rest/CreateSubjectRequest.js +2 -0
  33. package/lib/src/generated/rest/CreateUserRequest.d.ts +4 -0
  34. package/lib/src/generated/rest/CreateUserRequest.js +2 -0
  35. package/lib/src/generated/rest/CreateUserResponse.d.ts +5 -0
  36. package/lib/src/generated/rest/CreateUserResponse.js +2 -0
  37. package/lib/src/generated/rest/DecoratedExpressionProof.d.ts +6 -0
  38. package/lib/src/generated/rest/DecoratedExpressionProof.js +2 -0
  39. package/lib/src/generated/rest/DecoratedLinkExpression.d.ts +10 -0
  40. package/lib/src/generated/rest/DecoratedLinkExpression.js +1 -0
  41. package/lib/src/generated/rest/DisposeQueryRequest.d.ts +3 -0
  42. package/lib/src/generated/rest/DisposeQueryRequest.js +2 -0
  43. package/lib/src/generated/rest/EmailTestRequest.d.ts +6 -0
  44. package/lib/src/generated/rest/EmailTestRequest.js +2 -0
  45. package/lib/src/generated/rest/EmbedRequest.d.ts +4 -0
  46. package/lib/src/generated/rest/EmbedRequest.js +2 -0
  47. package/lib/src/generated/rest/EntanglementProofInput.d.ts +6 -0
  48. package/lib/src/generated/rest/EntanglementProofInput.js +2 -0
  49. package/lib/src/generated/rest/EntanglementProofPreflightRequest.d.ts +4 -0
  50. package/lib/src/generated/rest/EntanglementProofPreflightRequest.js +2 -0
  51. package/lib/src/generated/rest/ExecuteCommandsRequest.d.ts +4 -0
  52. package/lib/src/generated/rest/ExecuteCommandsRequest.js +2 -0
  53. package/lib/src/generated/rest/ExportRequest.d.ts +5 -0
  54. package/lib/src/generated/rest/ExportRequest.js +2 -0
  55. package/lib/src/generated/rest/ExpressionManyRequest.d.ts +3 -0
  56. package/lib/src/generated/rest/ExpressionManyRequest.js +2 -0
  57. package/lib/src/generated/rest/ExpressionProof.d.ts +4 -0
  58. package/lib/src/generated/rest/ExpressionProof.js +2 -0
  59. package/lib/src/generated/rest/ExpressionProofInput.d.ts +6 -0
  60. package/lib/src/generated/rest/ExpressionProofInput.js +2 -0
  61. package/lib/src/generated/rest/FriendSendMessageRequest.d.ts +3 -0
  62. package/lib/src/generated/rest/FriendSendMessageRequest.js +2 -0
  63. package/lib/src/generated/rest/FriendsListRequest.d.ts +3 -0
  64. package/lib/src/generated/rest/FriendsListRequest.js +2 -0
  65. package/lib/src/generated/rest/GenerateAgentRequest.d.ts +3 -0
  66. package/lib/src/generated/rest/GenerateAgentRequest.js +2 -0
  67. package/lib/src/generated/rest/GenerateJwtRequest.d.ts +4 -0
  68. package/lib/src/generated/rest/GenerateJwtRequest.js +2 -0
  69. package/lib/src/generated/rest/GetSubjectDataRequest.d.ts +4 -0
  70. package/lib/src/generated/rest/GetSubjectDataRequest.js +2 -0
  71. package/lib/src/generated/rest/HostingInfoResponse.d.ts +5 -0
  72. package/lib/src/generated/rest/HostingInfoResponse.js +2 -0
  73. package/lib/src/generated/rest/HostingWalletResponse.d.ts +4 -0
  74. package/lib/src/generated/rest/HostingWalletResponse.js +2 -0
  75. package/lib/src/generated/rest/ImportAgentRequest.d.ts +6 -0
  76. package/lib/src/generated/rest/ImportAgentRequest.js +2 -0
  77. package/lib/src/generated/rest/ImportRequest.d.ts +4 -0
  78. package/lib/src/generated/rest/ImportRequest.js +2 -0
  79. package/lib/src/generated/rest/JoinNeighbourhoodRequest.d.ts +3 -0
  80. package/lib/src/generated/rest/JoinNeighbourhoodRequest.js +2 -0
  81. package/lib/src/generated/rest/KeepAliveQueryRequest.d.ts +3 -0
  82. package/lib/src/generated/rest/KeepAliveQueryRequest.js +2 -0
  83. package/lib/src/generated/rest/LanguageMetaInput.d.ts +6 -0
  84. package/lib/src/generated/rest/LanguageMetaInput.js +2 -0
  85. package/lib/src/generated/rest/Link.d.ts +5 -0
  86. package/lib/src/generated/rest/Link.js +2 -0
  87. package/lib/src/generated/rest/LinkExpression.d.ts +10 -0
  88. package/lib/src/generated/rest/LinkExpression.js +1 -0
  89. package/lib/src/generated/rest/LinkExpressionInput.d.ts +10 -0
  90. package/lib/src/generated/rest/LinkExpressionInput.js +1 -0
  91. package/lib/src/generated/rest/LinkInput.d.ts +5 -0
  92. package/lib/src/generated/rest/LinkInput.js +2 -0
  93. package/lib/src/generated/rest/LinkLanguageTemplatesRequest.d.ts +3 -0
  94. package/lib/src/generated/rest/LinkLanguageTemplatesRequest.js +2 -0
  95. package/lib/src/generated/rest/LinkMutationRequest.d.ts +12 -0
  96. package/lib/src/generated/rest/LinkMutationRequest.js +1 -0
  97. package/lib/src/generated/rest/LinkMutationResponse.d.ts +9 -0
  98. package/lib/src/generated/rest/LinkMutationResponse.js +1 -0
  99. package/lib/src/generated/rest/LinkMutations.d.ts +6 -0
  100. package/lib/src/generated/rest/LinkMutations.js +1 -0
  101. package/lib/src/generated/rest/LinkMutationsRequest.d.ts +5 -0
  102. package/lib/src/generated/rest/LinkMutationsRequest.js +1 -0
  103. package/lib/src/generated/rest/LinkStatus.d.ts +1 -0
  104. package/lib/src/generated/rest/LinkStatus.js +2 -0
  105. package/lib/src/generated/rest/LinkUpdateInput.d.ts +5 -0
  106. package/lib/src/generated/rest/LinkUpdateInput.js +1 -0
  107. package/lib/src/generated/rest/LockAgentRequest.d.ts +3 -0
  108. package/lib/src/generated/rest/LockAgentRequest.js +2 -0
  109. package/lib/src/generated/rest/LoginUserRequest.d.ts +5 -0
  110. package/lib/src/generated/rest/LoginUserRequest.js +2 -0
  111. package/lib/src/generated/rest/ModelType.d.ts +1 -0
  112. package/lib/src/generated/rest/ModelType.js +2 -0
  113. package/lib/src/generated/rest/NotificationGrantRequest.d.ts +3 -0
  114. package/lib/src/generated/rest/NotificationGrantRequest.js +2 -0
  115. package/lib/src/generated/rest/NotificationInput.d.ts +10 -0
  116. package/lib/src/generated/rest/NotificationInput.js +2 -0
  117. package/lib/src/generated/rest/OpenLinkRequest.d.ts +3 -0
  118. package/lib/src/generated/rest/OpenLinkRequest.js +2 -0
  119. package/lib/src/generated/rest/PermitCapabilityRequest.d.ts +3 -0
  120. package/lib/src/generated/rest/PermitCapabilityRequest.js +2 -0
  121. package/lib/src/generated/rest/PerspectiveInput.d.ts +4 -0
  122. package/lib/src/generated/rest/PerspectiveInput.js +1 -0
  123. package/lib/src/generated/rest/PromptRequest.d.ts +4 -0
  124. package/lib/src/generated/rest/PromptRequest.js +2 -0
  125. package/lib/src/generated/rest/PublicPerspectiveInput.d.ts +4 -0
  126. package/lib/src/generated/rest/PublicPerspectiveInput.js +1 -0
  127. package/lib/src/generated/rest/PublishLanguageRequest.d.ts +5 -0
  128. package/lib/src/generated/rest/PublishLanguageRequest.js +1 -0
  129. package/lib/src/generated/rest/PublishNeighbourhoodRequest.d.ts +6 -0
  130. package/lib/src/generated/rest/PublishNeighbourhoodRequest.js +1 -0
  131. package/lib/src/generated/rest/QueryRequest.d.ts +7 -0
  132. package/lib/src/generated/rest/QueryRequest.js +2 -0
  133. package/lib/src/generated/rest/RemoveLinkRequest.d.ts +5 -0
  134. package/lib/src/generated/rest/RemoveLinkRequest.js +1 -0
  135. package/lib/src/generated/rest/RemoveLinksBulkRequest.d.ts +5 -0
  136. package/lib/src/generated/rest/RemoveLinksBulkRequest.js +1 -0
  137. package/lib/src/generated/rest/RequestCapabilityRequest.d.ts +4 -0
  138. package/lib/src/generated/rest/RequestCapabilityRequest.js +1 -0
  139. package/lib/src/generated/rest/RequestPaymentRequest.d.ts +3 -0
  140. package/lib/src/generated/rest/RequestPaymentRequest.js +2 -0
  141. package/lib/src/generated/rest/RequestVerificationRequest.d.ts +4 -0
  142. package/lib/src/generated/rest/RequestVerificationRequest.js +2 -0
  143. package/lib/src/generated/rest/ResourceInput.d.ts +4 -0
  144. package/lib/src/generated/rest/ResourceInput.js +2 -0
  145. package/lib/src/generated/rest/SetDefaultModelRequest.d.ts +4 -0
  146. package/lib/src/generated/rest/SetDefaultModelRequest.js +1 -0
  147. package/lib/src/generated/rest/SetFreeHostingEnabledRequest.d.ts +3 -0
  148. package/lib/src/generated/rest/SetFreeHostingEnabledRequest.js +2 -0
  149. package/lib/src/generated/rest/SetHotWalletAddressRequest.d.ts +3 -0
  150. package/lib/src/generated/rest/SetHotWalletAddressRequest.js +2 -0
  151. package/lib/src/generated/rest/SetMultiUserRequest.d.ts +3 -0
  152. package/lib/src/generated/rest/SetMultiUserRequest.js +2 -0
  153. package/lib/src/generated/rest/SetOnlineStatusRequest.d.ts +5 -0
  154. package/lib/src/generated/rest/SetOnlineStatusRequest.js +1 -0
  155. package/lib/src/generated/rest/SetStatusRequest.d.ts +3 -0
  156. package/lib/src/generated/rest/SetStatusRequest.js +2 -0
  157. package/lib/src/generated/rest/SetUserFreeAccessRequest.d.ts +4 -0
  158. package/lib/src/generated/rest/SetUserFreeAccessRequest.js +2 -0
  159. package/lib/src/generated/rest/SignMessageRequest.d.ts +3 -0
  160. package/lib/src/generated/rest/SignMessageRequest.js +2 -0
  161. package/lib/src/generated/rest/SignalRequest.d.ts +6 -0
  162. package/lib/src/generated/rest/SignalRequest.js +1 -0
  163. package/lib/src/generated/rest/SubscribeQueryRequest.d.ts +3 -0
  164. package/lib/src/generated/rest/SubscribeQueryRequest.js +2 -0
  165. package/lib/src/generated/rest/SubscribeQueryResponse.d.ts +4 -0
  166. package/lib/src/generated/rest/SubscribeQueryResponse.js +2 -0
  167. package/lib/src/generated/rest/TrustedAgentsRequest.d.ts +3 -0
  168. package/lib/src/generated/rest/TrustedAgentsRequest.js +2 -0
  169. package/lib/src/generated/rest/UnlockAgentRequest.d.ts +4 -0
  170. package/lib/src/generated/rest/UnlockAgentRequest.js +2 -0
  171. package/lib/src/generated/rest/UpdateLinkRequest.d.ts +7 -0
  172. package/lib/src/generated/rest/UpdateLinkRequest.js +1 -0
  173. package/lib/src/generated/rest/UpdatePerspectiveRequest.d.ts +3 -0
  174. package/lib/src/generated/rest/UpdatePerspectiveRequest.js +2 -0
  175. package/lib/src/generated/rest/UpdateProfileRequest.d.ts +5 -0
  176. package/lib/src/generated/rest/UpdateProfileRequest.js +1 -0
  177. package/lib/src/generated/rest/UserStatistics.d.ts +9 -0
  178. package/lib/src/generated/rest/UserStatistics.js +2 -0
  179. package/lib/src/generated/rest/VerificationRequestResult.d.ts +6 -0
  180. package/lib/src/generated/rest/VerificationRequestResult.js +2 -0
  181. package/lib/src/generated/rest/VerifyEmailRequest.d.ts +6 -0
  182. package/lib/src/generated/rest/VerifyEmailRequest.js +2 -0
  183. package/lib/src/generated/rest/VerifySignatureRequest.d.ts +5 -0
  184. package/lib/src/generated/rest/VerifySignatureRequest.js +2 -0
  185. package/lib/src/generated/rest/WriteSettingsRequest.d.ts +3 -0
  186. package/lib/src/generated/rest/WriteSettingsRequest.js +2 -0
  187. package/lib/src/generated/rest/index.d.ts +73 -0
  188. package/lib/src/generated/rest/index.js +8 -0
  189. package/lib/src/generated/rest/routes.d.ts +587 -0
  190. package/lib/src/generated/rest/routes.js +3 -0
  191. package/lib/src/model/Ad4mModel.test.js +735 -480
  192. package/lib/src/model/decorators.d.ts +20 -1
  193. package/lib/src/model/decorators.js +33 -2
  194. package/lib/src/model/query-sparql.d.ts +1 -0
  195. package/lib/src/model/query-sparql.js +13 -0
  196. package/lib/src/model/query-sparql.test.js +10 -92
  197. package/lib/src/model/query-surreal.d.ts +44 -0
  198. package/lib/src/model/query-surreal.js +249 -0
  199. package/lib/src/model/shacl-gen.d.ts +15 -1
  200. package/lib/src/model/shacl-gen.js +23 -1
  201. package/lib/src/model/surreal-utils.d.ts +42 -0
  202. package/lib/src/model/surreal-utils.js +128 -0
  203. package/lib/src/model/types.d.ts +14 -3
  204. package/lib/src/neighbourhood/NeighbourhoodProxy.test.js +33 -33
  205. package/lib/src/perspectives/PerspectiveProxy.d.ts +17 -0
  206. package/lib/src/perspectives/PerspectiveProxy.js +67 -15
  207. package/lib/src/perspectives/PerspectiveProxy.test.d.ts +1 -0
  208. package/lib/src/perspectives/PerspectiveProxy.test.js +34 -0
  209. package/lib/src/restClient.d.ts +52 -0
  210. package/lib/src/restClient.js +227 -0
  211. package/lib/src/shacl/SHACLShape.test.js +0 -82
  212. package/package.json +11 -8
  213. package/src/model/Ad4mModel.test.ts +103 -0
  214. package/src/model/decorators.ts +37 -3
  215. package/src/model/query-sparql.test.ts +148 -0
  216. package/src/model/query-sparql.ts +15 -0
  217. package/src/model/shacl-gen.ts +23 -0
  218. package/src/model/types.ts +28 -6
  219. package/src/perspectives/PerspectiveProxy.ts +73 -20
  220. package/lib/src/model/model-manifest.d.ts +0 -41
  221. package/lib/src/model/model-manifest.js +0 -11
@@ -24,6 +24,7 @@ import type { Where, Query, ModelMetadata, PropertyMetadata } from "./types";
24
24
  * - Literal-stored properties (equality, comparison, contains, etc.)
25
25
  * - Reverse relations (belongsToOne / belongsToMany)
26
26
  * - author / timestamp filters (skipped by buildSPARQLWhereFilters)
27
+ * - OR / AND / NOT combinators (skipped by buildSPARQLWhereFilters — see below)
27
28
  *
28
29
  * When JS-only filters exist, SPARQL-level LIMIT/OFFSET must NOT be applied
29
30
  * because the database would cap the candidate set before JS filters run,
@@ -39,6 +40,15 @@ export function hasJsOnlyWhereFilters(
39
40
  for (const [propertyName, condition] of Object.entries(where)) {
40
41
  if (propertyName === "base" || propertyName === "id") continue;
41
42
 
43
+ // OR/AND/NOT: buildSPARQLWhereFilters never emits a SPARQL translation
44
+ // for these regardless of what their branches contain, so their mere
45
+ // presence — not just JS-only conditions within a branch — must block
46
+ // SPARQL-level pagination. Otherwise LIMIT/OFFSET would be applied
47
+ // before the (Rust-side, post-hydration) combinator filter ever runs.
48
+ if (propertyName === "OR" || propertyName === "AND" || propertyName === "NOT") {
49
+ return true;
50
+ }
51
+
42
52
  // author/timestamp filters are handled in JS
43
53
  if (propertyName === "author" || propertyName === "timestamp") return true;
44
54
 
@@ -381,6 +391,11 @@ function buildSPARQLWhereFilters(
381
391
  const filters: string[] = [];
382
392
 
383
393
  for (const [propertyName, condition] of Object.entries(where)) {
394
+ // OR/AND/NOT are evaluated Rust-side after hydration; no SPARQL emission needed.
395
+ if (propertyName === "OR" || propertyName === "AND" || propertyName === "NOT") {
396
+ continue;
397
+ }
398
+
384
399
  // 'base' maps to ?source
385
400
  if (propertyName === "base" || propertyName === "id") {
386
401
  if (Array.isArray(condition)) {
@@ -34,6 +34,17 @@ export function buildSHACL(
34
34
  properties: Record<string, PropertyMetadataEntry>,
35
35
  allRelationsMeta: Record<string, RelationMetadataEntry>,
36
36
  conformanceFilterFn: ConformanceFilterFn,
37
+ /**
38
+ * Optional early-cache seeding callback. When invoked with a
39
+ * partial `{ shape, name }`, any re-entrant `generateSHACL()`
40
+ * call on the same target — which happens when a relation's
41
+ * `target: () => SameClass` points at us, directly or
42
+ * transitively — observes the in-progress shape rather than
43
+ * re-entering this function infinitely. Provided by `@Model` via
44
+ * `getMemoizedSHACL`; safe to omit when calling `buildSHACL`
45
+ * directly (e.g. from a one-off SDNA build tool).
46
+ */
47
+ seedCache?: (partial: { shape: SHACLShape; name: string }) => void,
37
48
  ): { shape: SHACLShape; name: string } {
38
49
  const obj = target.prototype;
39
50
 
@@ -66,6 +77,18 @@ export function buildSHACL(
66
77
  const targetClass = `${namespace}${subjectName}`;
67
78
  const shape = new SHACLShape(shapeUri, targetClass);
68
79
 
80
+ // ── Seed the memoisation cache while we keep building ──────────────
81
+ // Any subsequent `target.generateSHACL()` call from inside this
82
+ // function (typically when walking a self-referential or
83
+ // mutually-recursive relation target) will now observe the
84
+ // already-allocated `shape` rather than re-entering `buildSHACL`
85
+ // and overflowing the stack. The shape is mutated in place as we
86
+ // populate it below, so the eventual cached value and the value
87
+ // recursive callers see are the same object.
88
+ if (seedCache) {
89
+ seedCache({ shape, name: subjectName });
90
+ }
91
+
69
92
  // Detect @Model inheritance — if the parent class also has
70
93
  // generateSHACL it is itself a @Model and we reference its shape
71
94
  // via sh:node so SHACL validators can walk the hierarchy.
@@ -25,8 +25,25 @@ export type WhereOps = {
25
25
  gte: number; // greater than or equal to
26
26
  contains: string | number; // substring/element check
27
27
  };
28
- export type WhereCondition = string | number | boolean | string[] | number[] | { [K in keyof WhereOps]?: WhereOps[K] };
29
- export type Where = { [propertyName: string]: WhereCondition };
28
+ export type WhereCondition =
29
+ | string
30
+ | number
31
+ | boolean
32
+ | string[]
33
+ | number[]
34
+ | { [K in keyof WhereOps]?: WhereOps[K] }
35
+ | Where[]
36
+ | Where;
37
+
38
+ export type Where = {
39
+ /** Logical OR: instance must satisfy at least one of the given sub-clauses. */
40
+ OR?: Where[];
41
+ /** Logical AND: instance must satisfy all of the given sub-clauses. */
42
+ AND?: Where[];
43
+ /** Logical NOT: instance must NOT satisfy the given sub-clause. */
44
+ NOT?: Where;
45
+ [propertyName: string]: WhereCondition | undefined;
46
+ };
30
47
  export type Order = { [propertyName: string]: "ASC" | "DESC" };
31
48
 
32
49
  /**
@@ -239,7 +256,7 @@ export type TypedWhereCondition<V> =
239
256
  : WhereCondition;
240
257
 
241
258
  /** Strict Where: keys constrained to T's properties, plus the well-known
242
- * link-metadata fields (`id`/`author`/`timestamp`). */
259
+ * link-metadata fields (`id`/`author`/`timestamp`) and logical combinators. */
243
260
  type StrictTypedWhere<T extends Ad4mModel> =
244
261
  & { [K in PropertyKeysOf<T>]?: TypedWhereCondition<T[K]> }
245
262
  & {
@@ -247,6 +264,9 @@ type StrictTypedWhere<T extends Ad4mModel> =
247
264
  id?: string | string[];
248
265
  author?: WhereCondition;
249
266
  timestamp?: WhereCondition;
267
+ OR?: StrictTypedWhere<T>[];
268
+ AND?: StrictTypedWhere<T>[];
269
+ NOT?: StrictTypedWhere<T>;
250
270
  };
251
271
 
252
272
  /** Public typed `where` for a model class. Falls back to the loose `Where`
@@ -256,9 +276,11 @@ export type TypedWhere<T extends Ad4mModel> =
256
276
 
257
277
  // ---- Typed order -------------------------------------------------------------
258
278
 
259
- type StrictTypedOrder<T extends Ad4mModel> = {
260
- [K in PropertyKeysOf<T> | 'timestamp' | 'author' | 'createdAt' | 'updatedAt']?: 'ASC' | 'DESC';
261
- };
279
+ type StrictTypedOrder<T extends Ad4mModel> =
280
+ & { [K in PropertyKeysOf<T> | 'timestamp' | 'author' | 'createdAt' | 'updatedAt']?: 'ASC' | 'DESC' }
281
+ // $-prefixed projection count keys (e.g. "$likeCount") — typed at the
282
+ // include map level but accepted here so callers can sort by them.
283
+ & { [K in `$${string}`]?: 'ASC' | 'DESC' };
262
284
 
263
285
  export type TypedOrder<T extends Ad4mModel> =
264
286
  HasNoTypedFields<T> extends true ? Order : StrictTypedOrder<T>;
@@ -1293,12 +1293,25 @@ export class PerspectiveProxy {
1293
1293
  predicate: "sh://property"
1294
1294
  }));
1295
1295
 
1296
- // Fetch all links from the shape and its property shapes
1296
+ // Fetch all links from the shape and its property shapes. These reads are
1297
+ // independent of each other, so fire them concurrently rather than one RPC
1298
+ // round trip at a time — over a remote (non-loopback) connection, a shape with
1299
+ // a dozen properties otherwise pays a dozen sequential round trips just to load.
1297
1300
  const sourceUris = [shapeUri, ...propertyLinks.map(l => l.data.target)];
1301
+ const linksByUri = await Promise.all(sourceUris.map(uri => this.get(new LinkQuery({ source: uri }))));
1302
+ // Dedupe by (source, predicate, target): a perspective that's accumulated duplicate
1303
+ // SDNA links (e.g. from repeated registration attempts, or executor-side sync bugs)
1304
+ // would otherwise feed the same triple into SHACLShape.fromLinks more than once —
1305
+ // harmless for scalar fields like targetClass (first match wins) but can surface as
1306
+ // visibly duplicated properties for repeated sh://property links. Cheap: this is an
1307
+ // in-memory pass over data already fetched, no extra round trips.
1308
+ const seenLinks = new Set<string>();
1298
1309
  const allLinks: Array<{source: string, predicate: string, target: string}> = [];
1299
- for (const uri of sourceUris) {
1300
- const links = await this.get(new LinkQuery({ source: uri }));
1310
+ for (const links of linksByUri) {
1301
1311
  for (const l of links) {
1312
+ const key = `${l.data.source} ${l.data.predicate} ${l.data.target}`;
1313
+ if (seenLinks.has(key)) continue;
1314
+ seenLinks.add(key);
1302
1315
  allLinks.push({
1303
1316
  source: l.data.source,
1304
1317
  predicate: l.data.predicate,
@@ -1306,34 +1319,74 @@ export class PerspectiveProxy {
1306
1319
  });
1307
1320
  }
1308
1321
  }
1309
-
1322
+
1310
1323
  const shapeLinks = allLinks;
1311
-
1324
+
1312
1325
  return SHACLShape.fromLinks(shapeLinks, shapeUri);
1313
1326
  }
1314
1327
 
1315
1328
  /**
1316
- * Get all SHACL shapes stored in this Perspective
1329
+ * List the names of every SHACL shape stored in this Perspective, without fetching
1330
+ * each shape's full definition (properties, target class, etc.) — just the cheap
1331
+ * `ad4m://has_shacl` enumeration, one round trip regardless of how many shapes exist.
1332
+ * Use this to check which shapes are actually worth resolving via `getShacl()` before
1333
+ * paying for each one's full (multi-round-trip) fetch.
1317
1334
  */
1318
- async getAllShacl(): Promise<Array<{name: string, shape: SHACLShape}>> {
1335
+ async getShaclNames(): Promise<string[]> {
1319
1336
  const nameLinks = await this.get(new LinkQuery({
1320
1337
  source: "ad4m://self",
1321
1338
  predicate: "ad4m://has_shacl"
1322
1339
  }));
1323
-
1324
- const shapes = [];
1325
- for (const nameLink of nameLinks) {
1326
- const nameUrl = nameLink.data.target;
1327
- const name = Literal.fromUrl(nameUrl).get() as string;
1328
- const shapeName = name.replace('shacl://', '');
1329
-
1330
- const shape = await this.getShacl(shapeName);
1331
- if (shape) {
1332
- shapes.push({ name: shapeName, shape });
1333
- }
1340
+ // Dedupe: a perspective with duplicate `has_shacl` links (see the dedup note in
1341
+ // getShacl()) would otherwise report the same name more than once, causing callers
1342
+ // to redundantly resolve (or redundantly disambiguate) it multiple times.
1343
+ const names = nameLinks.map((nameLink) => {
1344
+ const name = Literal.fromUrl(nameLink.data.target).get() as string;
1345
+ return name.replace('shacl://', '');
1346
+ });
1347
+ return [...new Set(names)];
1348
+ }
1349
+
1350
+ /**
1351
+ * Resolve just a shape's `sh:targetClass` by name, without fetching its properties —
1352
+ * two round trips (name → shapeUri, then shapeUri's own direct triples) instead of
1353
+ * `getShacl()`'s full walk (which also fetches every property sub-shape). Use this to
1354
+ * disambiguate a shape name that collides with another app's `@Model({ name })` string
1355
+ * (the bare `shacl://{name}` mapping ad4m-core uses is namespace-blind — see
1356
+ * `getShaclNames()` callers for why that matters) before paying for a full fetch.
1357
+ */
1358
+ async getShaclTargetClass(name: string): Promise<string | undefined> {
1359
+ const nameMapping = Literal.fromUrl(`literal:string:shacl://${name}`);
1360
+ const shapeUriLinks = await this.get(new LinkQuery({
1361
+ source: nameMapping.toUrl(),
1362
+ predicate: "ad4m://shacl_shape_uri"
1363
+ }));
1364
+ if (shapeUriLinks.length === 0) {
1365
+ return undefined;
1334
1366
  }
1335
-
1336
- return shapes;
1367
+ const shapeUri = shapeUriLinks[0].data.target;
1368
+
1369
+ const shapeOwnLinks = await this.get(new LinkQuery({ source: shapeUri }));
1370
+ return shapeOwnLinks.find(l => l.data.predicate === "sh://targetClass")?.data.target;
1371
+ }
1372
+
1373
+ /**
1374
+ * Get all SHACL shapes stored in this Perspective
1375
+ */
1376
+ async getAllShacl(): Promise<Array<{name: string, shape: SHACLShape}>> {
1377
+ const shapeNames = await this.getShaclNames();
1378
+
1379
+ // Each shape is fetched independently of the others — resolve them concurrently.
1380
+ // Sequentially awaiting getShacl() per shape means a perspective with N SDNA
1381
+ // models pays N times getShacl()'s own multi-round-trip cost one after another;
1382
+ // over a remote connection with real per-call latency that compounds into the
1383
+ // dominant cost of switching into a perspective at all.
1384
+ const results = await Promise.all(shapeNames.map(async (shapeName) => {
1385
+ const shape = await this.getShacl(shapeName);
1386
+ return shape ? { name: shapeName, shape } : null;
1387
+ }));
1388
+
1389
+ return results.filter((s): s is { name: string, shape: SHACLShape } => s !== null);
1337
1390
  }
1338
1391
 
1339
1392
  /**
@@ -1,41 +0,0 @@
1
- /**
2
- * Types for the perspective model manifest — a human-readable, AI-friendly summary
3
- * of all Ad4mModel-compatible classes defined in a perspective's SHACL shapes.
4
- *
5
- * Used by `PerspectiveProxy.getModelManifest()` and consumed by WE's AI context
6
- * injection (`formatManifestForPrompt`) to describe external perspective models
7
- * to the schema-generation AI.
8
- *
9
- * @module
10
- */
11
- /** Normalised description of a single property on a model class. */
12
- export interface ModelManifestProperty {
13
- /** Property name as declared in the SHACL shape (e.g. "name", "body", "participants"). */
14
- name: string;
15
- /** The exact RDF predicate URI (e.g. "flux://has_name"). */
16
- predicate: string;
17
- /** Normalised scalar type; inferred from xsd:/sh: datatype + nodeKind. */
18
- type: 'string' | 'number' | 'boolean' | 'uri';
19
- /** `true` when maxCount is absent or > 1 (i.e. returned as an array). */
20
- isCollection: boolean;
21
- /** `true` when minCount >= 1. */
22
- required: boolean;
23
- writable: boolean;
24
- /** AD4M language used to resolve the value (e.g. "literal"). */
25
- resolveLanguage?: string;
26
- /**
27
- * Local name of the related model class when this is a typed relation property.
28
- * Derived from `SHACLPropertyShape.class` by stripping the URI prefix.
29
- * E.g. `flux://Message` → `"Message"`.
30
- */
31
- relatedModel?: string;
32
- }
33
- /** Normalised description of a single model class stored in a perspective. */
34
- export interface ModelManifestEntry {
35
- /** Class name — usable directly as the `model` field in a `$query` token. */
36
- name: string;
37
- /** The SHACL `targetClass` URI (e.g. "flux://Channel"). */
38
- targetClass: string;
39
- /** All data properties (flag/hasValue properties are excluded). */
40
- properties: ModelManifestProperty[];
41
- }
@@ -1,11 +0,0 @@
1
- /**
2
- * Types for the perspective model manifest — a human-readable, AI-friendly summary
3
- * of all Ad4mModel-compatible classes defined in a perspective's SHACL shapes.
4
- *
5
- * Used by `PerspectiveProxy.getModelManifest()` and consumed by WE's AI context
6
- * injection (`formatManifestForPrompt`) to describe external perspective models
7
- * to the schema-generation AI.
8
- *
9
- * @module
10
- */
11
- export {};