@coasys/ad4m 0.13.0-test-6 → 0.13.0-test-8

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 (279) hide show
  1. package/lib/index.cjs +1103 -747
  2. package/lib/index.js +1090 -747
  3. package/lib/src/Ad4mClient.d.ts +4 -1
  4. package/lib/src/Ad4mClient.js +2 -2
  5. package/lib/src/agent/AgentClient.js +17 -0
  6. package/lib/src/ai/AIClient.js +1 -1
  7. package/lib/src/apiClient.d.ts +5 -1
  8. package/lib/src/apiClient.js +14 -6
  9. package/lib/src/generated/rest/AIModelLoadingStatus.d.ts +7 -0
  10. package/lib/src/generated/rest/AIModelLoadingStatus.js +2 -0
  11. package/lib/src/generated/rest/AddAgentInfosRequest.d.ts +3 -0
  12. package/lib/src/generated/rest/AddAgentInfosRequest.js +2 -0
  13. package/lib/src/generated/rest/AddLinkExpressionRequest.d.ts +6 -0
  14. package/lib/src/generated/rest/AddLinkExpressionRequest.js +1 -0
  15. package/lib/src/generated/rest/AddLinkRequest.d.ts +6 -0
  16. package/lib/src/generated/rest/AddLinkRequest.js +1 -0
  17. package/lib/src/generated/rest/AddLinksBulkRequest.d.ts +6 -0
  18. package/lib/src/generated/rest/AddLinksBulkRequest.js +1 -0
  19. package/lib/src/generated/rest/AddSdnaRequest.d.ts +6 -0
  20. package/lib/src/generated/rest/AddSdnaRequest.js +2 -0
  21. package/lib/src/generated/rest/ApplyTemplateRequest.d.ts +4 -0
  22. package/lib/src/generated/rest/ApplyTemplateRequest.js +2 -0
  23. package/lib/src/generated/rest/AuthInfoInput.d.ts +10 -0
  24. package/lib/src/generated/rest/AuthInfoInput.js +1 -0
  25. package/lib/src/generated/rest/BroadcastRequest.d.ts +6 -0
  26. package/lib/src/generated/rest/BroadcastRequest.js +1 -0
  27. package/lib/src/generated/rest/CapabilityInput.d.ts +5 -0
  28. package/lib/src/generated/rest/CapabilityInput.js +1 -0
  29. package/lib/src/generated/rest/CommitBatchRequest.d.ts +3 -0
  30. package/lib/src/generated/rest/CommitBatchRequest.js +2 -0
  31. package/lib/src/generated/rest/ComputeLogEntry.d.ts +9 -0
  32. package/lib/src/generated/rest/ComputeLogEntry.js +2 -0
  33. package/lib/src/generated/rest/CreateExpressionRequest.d.ts +4 -0
  34. package/lib/src/generated/rest/CreateExpressionRequest.js +2 -0
  35. package/lib/src/generated/rest/CreatePerspectiveRequest.d.ts +3 -0
  36. package/lib/src/generated/rest/CreatePerspectiveRequest.js +2 -0
  37. package/lib/src/generated/rest/CreateSubjectRequest.d.ts +6 -0
  38. package/lib/src/generated/rest/CreateSubjectRequest.js +2 -0
  39. package/lib/src/generated/rest/CreateUserRequest.d.ts +4 -0
  40. package/lib/src/generated/rest/CreateUserRequest.js +2 -0
  41. package/lib/src/generated/rest/CreateUserResponse.d.ts +5 -0
  42. package/lib/src/generated/rest/CreateUserResponse.js +2 -0
  43. package/lib/src/generated/rest/DecoratedExpressionProof.d.ts +6 -0
  44. package/lib/src/generated/rest/DecoratedExpressionProof.js +2 -0
  45. package/lib/src/generated/rest/DecoratedLinkExpression.d.ts +10 -0
  46. package/lib/src/generated/rest/DecoratedLinkExpression.js +1 -0
  47. package/lib/src/generated/rest/DisposeQueryRequest.d.ts +3 -0
  48. package/lib/src/generated/rest/DisposeQueryRequest.js +2 -0
  49. package/lib/src/generated/rest/EmailTestRequest.d.ts +6 -0
  50. package/lib/src/generated/rest/EmailTestRequest.js +2 -0
  51. package/lib/src/generated/rest/EmbedRequest.d.ts +4 -0
  52. package/lib/src/generated/rest/EmbedRequest.js +2 -0
  53. package/lib/src/generated/rest/EntanglementProofInput.d.ts +6 -0
  54. package/lib/src/generated/rest/EntanglementProofInput.js +2 -0
  55. package/lib/src/generated/rest/EntanglementProofPreflightRequest.d.ts +4 -0
  56. package/lib/src/generated/rest/EntanglementProofPreflightRequest.js +2 -0
  57. package/lib/src/generated/rest/ExecuteCommandsRequest.d.ts +4 -0
  58. package/lib/src/generated/rest/ExecuteCommandsRequest.js +2 -0
  59. package/lib/src/generated/rest/ExportRequest.d.ts +5 -0
  60. package/lib/src/generated/rest/ExportRequest.js +2 -0
  61. package/lib/src/generated/rest/ExpressionManyRequest.d.ts +3 -0
  62. package/lib/src/generated/rest/ExpressionManyRequest.js +2 -0
  63. package/lib/src/generated/rest/ExpressionProof.d.ts +4 -0
  64. package/lib/src/generated/rest/ExpressionProof.js +2 -0
  65. package/lib/src/generated/rest/ExpressionProofInput.d.ts +6 -0
  66. package/lib/src/generated/rest/ExpressionProofInput.js +2 -0
  67. package/lib/src/generated/rest/FriendSendMessageRequest.d.ts +3 -0
  68. package/lib/src/generated/rest/FriendSendMessageRequest.js +2 -0
  69. package/lib/src/generated/rest/FriendsListRequest.d.ts +3 -0
  70. package/lib/src/generated/rest/FriendsListRequest.js +2 -0
  71. package/lib/src/generated/rest/GenerateAgentRequest.d.ts +3 -0
  72. package/lib/src/generated/rest/GenerateAgentRequest.js +2 -0
  73. package/lib/src/generated/rest/GenerateJwtRequest.d.ts +4 -0
  74. package/lib/src/generated/rest/GenerateJwtRequest.js +2 -0
  75. package/lib/src/generated/rest/GetSubjectDataRequest.d.ts +4 -0
  76. package/lib/src/generated/rest/GetSubjectDataRequest.js +2 -0
  77. package/lib/src/generated/rest/HostingInfoResponse.d.ts +5 -0
  78. package/lib/src/generated/rest/HostingInfoResponse.js +2 -0
  79. package/lib/src/generated/rest/HostingWalletResponse.d.ts +4 -0
  80. package/lib/src/generated/rest/HostingWalletResponse.js +2 -0
  81. package/lib/src/generated/rest/ImportAgentRequest.d.ts +6 -0
  82. package/lib/src/generated/rest/ImportAgentRequest.js +2 -0
  83. package/lib/src/generated/rest/ImportRequest.d.ts +4 -0
  84. package/lib/src/generated/rest/ImportRequest.js +2 -0
  85. package/lib/src/generated/rest/JoinNeighbourhoodRequest.d.ts +3 -0
  86. package/lib/src/generated/rest/JoinNeighbourhoodRequest.js +2 -0
  87. package/lib/src/generated/rest/KeepAliveQueryRequest.d.ts +3 -0
  88. package/lib/src/generated/rest/KeepAliveQueryRequest.js +2 -0
  89. package/lib/src/generated/rest/LanguageMetaInput.d.ts +6 -0
  90. package/lib/src/generated/rest/LanguageMetaInput.js +2 -0
  91. package/lib/src/generated/rest/Link.d.ts +5 -0
  92. package/lib/src/generated/rest/Link.js +2 -0
  93. package/lib/src/generated/rest/LinkExpression.d.ts +10 -0
  94. package/lib/src/generated/rest/LinkExpression.js +1 -0
  95. package/lib/src/generated/rest/LinkExpressionInput.d.ts +10 -0
  96. package/lib/src/generated/rest/LinkExpressionInput.js +1 -0
  97. package/lib/src/generated/rest/LinkInput.d.ts +5 -0
  98. package/lib/src/generated/rest/LinkInput.js +2 -0
  99. package/lib/src/generated/rest/LinkLanguageTemplatesRequest.d.ts +3 -0
  100. package/lib/src/generated/rest/LinkLanguageTemplatesRequest.js +2 -0
  101. package/lib/src/generated/rest/LinkMutationRequest.d.ts +12 -0
  102. package/lib/src/generated/rest/LinkMutationRequest.js +1 -0
  103. package/lib/src/generated/rest/LinkMutationResponse.d.ts +9 -0
  104. package/lib/src/generated/rest/LinkMutationResponse.js +1 -0
  105. package/lib/src/generated/rest/LinkMutations.d.ts +6 -0
  106. package/lib/src/generated/rest/LinkMutations.js +1 -0
  107. package/lib/src/generated/rest/LinkMutationsRequest.d.ts +5 -0
  108. package/lib/src/generated/rest/LinkMutationsRequest.js +1 -0
  109. package/lib/src/generated/rest/LinkStatus.d.ts +1 -0
  110. package/lib/src/generated/rest/LinkStatus.js +2 -0
  111. package/lib/src/generated/rest/LinkUpdateInput.d.ts +5 -0
  112. package/lib/src/generated/rest/LinkUpdateInput.js +1 -0
  113. package/lib/src/generated/rest/LockAgentRequest.d.ts +3 -0
  114. package/lib/src/generated/rest/LockAgentRequest.js +2 -0
  115. package/lib/src/generated/rest/LoginUserRequest.d.ts +5 -0
  116. package/lib/src/generated/rest/LoginUserRequest.js +2 -0
  117. package/lib/src/generated/rest/ModelType.d.ts +1 -0
  118. package/lib/src/generated/rest/ModelType.js +2 -0
  119. package/lib/src/generated/rest/NotificationGrantRequest.d.ts +3 -0
  120. package/lib/src/generated/rest/NotificationGrantRequest.js +2 -0
  121. package/lib/src/generated/rest/NotificationInput.d.ts +10 -0
  122. package/lib/src/generated/rest/NotificationInput.js +2 -0
  123. package/lib/src/generated/rest/OpenLinkRequest.d.ts +3 -0
  124. package/lib/src/generated/rest/OpenLinkRequest.js +2 -0
  125. package/lib/src/generated/rest/PermitCapabilityRequest.d.ts +3 -0
  126. package/lib/src/generated/rest/PermitCapabilityRequest.js +2 -0
  127. package/lib/src/generated/rest/PerspectiveInput.d.ts +4 -0
  128. package/lib/src/generated/rest/PerspectiveInput.js +1 -0
  129. package/lib/src/generated/rest/PromptRequest.d.ts +4 -0
  130. package/lib/src/generated/rest/PromptRequest.js +2 -0
  131. package/lib/src/generated/rest/PublicPerspectiveInput.d.ts +4 -0
  132. package/lib/src/generated/rest/PublicPerspectiveInput.js +1 -0
  133. package/lib/src/generated/rest/PublishLanguageRequest.d.ts +5 -0
  134. package/lib/src/generated/rest/PublishLanguageRequest.js +1 -0
  135. package/lib/src/generated/rest/PublishNeighbourhoodRequest.d.ts +6 -0
  136. package/lib/src/generated/rest/PublishNeighbourhoodRequest.js +1 -0
  137. package/lib/src/generated/rest/QueryRequest.d.ts +7 -0
  138. package/lib/src/generated/rest/QueryRequest.js +2 -0
  139. package/lib/src/generated/rest/RemoveLinkRequest.d.ts +5 -0
  140. package/lib/src/generated/rest/RemoveLinkRequest.js +1 -0
  141. package/lib/src/generated/rest/RemoveLinksBulkRequest.d.ts +5 -0
  142. package/lib/src/generated/rest/RemoveLinksBulkRequest.js +1 -0
  143. package/lib/src/generated/rest/RequestCapabilityRequest.d.ts +4 -0
  144. package/lib/src/generated/rest/RequestCapabilityRequest.js +1 -0
  145. package/lib/src/generated/rest/RequestPaymentRequest.d.ts +3 -0
  146. package/lib/src/generated/rest/RequestPaymentRequest.js +2 -0
  147. package/lib/src/generated/rest/RequestVerificationRequest.d.ts +4 -0
  148. package/lib/src/generated/rest/RequestVerificationRequest.js +2 -0
  149. package/lib/src/generated/rest/ResourceInput.d.ts +4 -0
  150. package/lib/src/generated/rest/ResourceInput.js +2 -0
  151. package/lib/src/generated/rest/SetDefaultModelRequest.d.ts +4 -0
  152. package/lib/src/generated/rest/SetDefaultModelRequest.js +1 -0
  153. package/lib/src/generated/rest/SetFreeHostingEnabledRequest.d.ts +3 -0
  154. package/lib/src/generated/rest/SetFreeHostingEnabledRequest.js +2 -0
  155. package/lib/src/generated/rest/SetHotWalletAddressRequest.d.ts +3 -0
  156. package/lib/src/generated/rest/SetHotWalletAddressRequest.js +2 -0
  157. package/lib/src/generated/rest/SetMultiUserRequest.d.ts +3 -0
  158. package/lib/src/generated/rest/SetMultiUserRequest.js +2 -0
  159. package/lib/src/generated/rest/SetOnlineStatusRequest.d.ts +5 -0
  160. package/lib/src/generated/rest/SetOnlineStatusRequest.js +1 -0
  161. package/lib/src/generated/rest/SetStatusRequest.d.ts +3 -0
  162. package/lib/src/generated/rest/SetStatusRequest.js +2 -0
  163. package/lib/src/generated/rest/SetUserFreeAccessRequest.d.ts +4 -0
  164. package/lib/src/generated/rest/SetUserFreeAccessRequest.js +2 -0
  165. package/lib/src/generated/rest/SignMessageRequest.d.ts +3 -0
  166. package/lib/src/generated/rest/SignMessageRequest.js +2 -0
  167. package/lib/src/generated/rest/SignalRequest.d.ts +6 -0
  168. package/lib/src/generated/rest/SignalRequest.js +1 -0
  169. package/lib/src/generated/rest/SubscribeQueryRequest.d.ts +3 -0
  170. package/lib/src/generated/rest/SubscribeQueryRequest.js +2 -0
  171. package/lib/src/generated/rest/SubscribeQueryResponse.d.ts +4 -0
  172. package/lib/src/generated/rest/SubscribeQueryResponse.js +2 -0
  173. package/lib/src/generated/rest/TrustedAgentsRequest.d.ts +3 -0
  174. package/lib/src/generated/rest/TrustedAgentsRequest.js +2 -0
  175. package/lib/src/generated/rest/UnlockAgentRequest.d.ts +4 -0
  176. package/lib/src/generated/rest/UnlockAgentRequest.js +2 -0
  177. package/lib/src/generated/rest/UpdateLinkRequest.d.ts +7 -0
  178. package/lib/src/generated/rest/UpdateLinkRequest.js +1 -0
  179. package/lib/src/generated/rest/UpdatePerspectiveRequest.d.ts +3 -0
  180. package/lib/src/generated/rest/UpdatePerspectiveRequest.js +2 -0
  181. package/lib/src/generated/rest/UpdateProfileRequest.d.ts +5 -0
  182. package/lib/src/generated/rest/UpdateProfileRequest.js +1 -0
  183. package/lib/src/generated/rest/UserStatistics.d.ts +9 -0
  184. package/lib/src/generated/rest/UserStatistics.js +2 -0
  185. package/lib/src/generated/rest/VerificationRequestResult.d.ts +6 -0
  186. package/lib/src/generated/rest/VerificationRequestResult.js +2 -0
  187. package/lib/src/generated/rest/VerifyEmailRequest.d.ts +6 -0
  188. package/lib/src/generated/rest/VerifyEmailRequest.js +2 -0
  189. package/lib/src/generated/rest/VerifySignatureRequest.d.ts +5 -0
  190. package/lib/src/generated/rest/VerifySignatureRequest.js +2 -0
  191. package/lib/src/generated/rest/WriteSettingsRequest.d.ts +3 -0
  192. package/lib/src/generated/rest/WriteSettingsRequest.js +2 -0
  193. package/lib/src/generated/rest/index.d.ts +73 -0
  194. package/lib/src/generated/rest/index.js +8 -0
  195. package/lib/src/generated/rest/routes.d.ts +587 -0
  196. package/lib/src/generated/rest/routes.js +3 -0
  197. package/lib/src/index.d.ts +4 -0
  198. package/lib/src/index.js +4 -0
  199. package/lib/src/model/Ad4mModel.d.ts +30 -21
  200. package/lib/src/model/Ad4mModel.js +93 -316
  201. package/lib/src/model/Ad4mModel.test.js +1536 -535
  202. package/lib/src/model/ModelQueryBuilder.d.ts +5 -10
  203. package/lib/src/model/ModelQueryBuilder.js +136 -47
  204. package/lib/src/model/Subject.js +6 -6
  205. package/lib/src/model/decorators.d.ts +7 -4
  206. package/lib/src/model/decorators.js +0 -7
  207. package/lib/src/model/hydration-batch.d.ts +34 -0
  208. package/lib/src/model/hydration-batch.js +147 -0
  209. package/lib/src/model/hydration-batching.test.d.ts +7 -0
  210. package/lib/src/model/hydration-batching.test.js +456 -0
  211. package/lib/src/model/query-cache.test.d.ts +1 -0
  212. package/lib/src/model/query-cache.test.js +43 -0
  213. package/lib/src/model/query-sparql-batch.d.ts +17 -0
  214. package/lib/src/model/query-sparql-batch.js +260 -0
  215. package/lib/src/model/query-sparql.d.ts +0 -10
  216. package/lib/src/model/query-sparql.js +10 -15
  217. package/lib/src/model/query-sparql.test.d.ts +1 -0
  218. package/lib/src/model/query-sparql.test.js +230 -0
  219. package/lib/src/model/relation-filtering.test.js +15 -15
  220. package/lib/src/model/shacl-gen.js +120 -47
  221. package/lib/src/model/subscription-delta.test.d.ts +24 -0
  222. package/lib/src/model/subscription-delta.test.js +180 -0
  223. package/lib/src/model/subscription-pool.d.ts +39 -0
  224. package/lib/src/model/subscription-pool.js +165 -0
  225. package/lib/src/model/types.d.ts +140 -4
  226. package/lib/src/neighbourhood/NeighbourhoodProxy.test.js +33 -33
  227. package/lib/src/perspectives/PerspectiveClient.d.ts +13 -4
  228. package/lib/src/perspectives/PerspectiveClient.js +22 -6
  229. package/lib/src/perspectives/PerspectiveClient.test.d.ts +1 -0
  230. package/lib/src/perspectives/PerspectiveClient.test.js +224 -0
  231. package/lib/src/perspectives/PerspectiveProxy.d.ts +27 -7
  232. package/lib/src/perspectives/PerspectiveProxy.js +60 -12
  233. package/lib/src/perspectives/PerspectiveProxy.test.d.ts +1 -0
  234. package/lib/src/perspectives/PerspectiveProxy.test.js +34 -0
  235. package/lib/src/perspectives/PerspectiveResolver.d.ts +0 -1
  236. package/lib/src/perspectives/PerspectiveResolver.js +0 -11
  237. package/lib/src/perspectives/SparqlBindings.d.ts +47 -0
  238. package/lib/src/perspectives/SparqlBindings.js +65 -0
  239. package/lib/src/perspectives/WakerSubscriptionManager.js +5 -4
  240. package/lib/src/restClient.d.ts +52 -0
  241. package/lib/src/restClient.js +227 -0
  242. package/lib/src/runtime/RuntimeResolver.d.ts +28 -1
  243. package/lib/src/runtime/RuntimeResolver.js +197 -4
  244. package/lib/src/schema.gql +27 -1
  245. package/lib/src/shacl/NodeExpression.d.ts +44 -0
  246. package/lib/src/shacl/NodeExpression.js +39 -0
  247. package/lib/src/shacl/SHACLShape.d.ts +23 -0
  248. package/lib/src/shacl/SHACLShape.js +115 -1
  249. package/lib/src/shacl/builders.d.ts +58 -0
  250. package/lib/src/shacl/builders.js +76 -0
  251. package/lib/src/shacl/index.d.ts +36 -0
  252. package/lib/src/shacl/index.js +33 -0
  253. package/package.json +1 -1
  254. package/src/Ad4mClient.ts +7 -2
  255. package/src/agent/AgentClient.ts +23 -0
  256. package/src/ai/AIClient.ts +1 -1
  257. package/src/apiClient.ts +17 -6
  258. package/src/index.ts +4 -0
  259. package/src/model/Ad4mModel.test.ts +274 -72
  260. package/src/model/Ad4mModel.ts +141 -350
  261. package/src/model/ModelQueryBuilder.ts +131 -56
  262. package/src/model/decorators.ts +7 -13
  263. package/src/model/query-sparql.test.ts +35 -19
  264. package/src/model/query-sparql.ts +10 -16
  265. package/src/model/relation-filtering.test.ts +46 -39
  266. package/src/model/shacl-gen.ts +128 -54
  267. package/src/model/shacl-roundtrip.test.ts +197 -0
  268. package/src/model/types-typed-query.test.ts +360 -0
  269. package/src/model/types.ts +196 -4
  270. package/src/perspectives/PerspectiveClient.ts +24 -8
  271. package/src/perspectives/PerspectiveProxy.test.ts +85 -1
  272. package/src/perspectives/PerspectiveProxy.ts +65 -20
  273. package/src/perspectives/SparqlBindings.ts +79 -0
  274. package/src/perspectives/WakerSubscriptionManager.ts +5 -4
  275. package/src/shacl/NodeExpression.ts +54 -0
  276. package/src/shacl/SHACLShape.test.ts +172 -0
  277. package/src/shacl/SHACLShape.ts +173 -1
  278. package/src/shacl/builders.ts +86 -0
  279. package/src/shacl/index.ts +72 -0
@@ -3,7 +3,7 @@ import { Link } from "../links/Links";
3
3
  import { LinkQuery } from "../perspectives/LinkQuery";
4
4
  import { PerspectiveProxy } from "../perspectives/PerspectiveProxy";
5
5
  import { makeRandomId } from "./util";
6
- import { getPropertiesMetadata, getRelationsMetadata, buildConformanceFilter, setPropertyRegistryEntry, setRelationRegistryEntry, Model } from "./decorators";
6
+ import { getPropertiesMetadata, getRelationsMetadata, setPropertyRegistryEntry, setRelationRegistryEntry, Model } from "./decorators";
7
7
  import type { PropertyOptions, PropertyMetadataEntry, RelationMetadataEntry } from "./decorators";
8
8
  import { formatQueryValue, compileWhereClause } from "./query-utils";
9
9
  import { resolveParentPredicate } from "./query-common";
@@ -21,61 +21,15 @@ import type {
21
21
  GetOptions, AllInstancesResult, ResultsWithTotalCount,
22
22
  PaginationResult, PropertyMetadata, RelationMetadata, ModelMetadata,
23
23
  IncludeProjection,
24
+ TypedQuery, IncludeExtras, IncludeOf,
24
25
  } from "./types";
25
26
 
26
27
 
28
+
27
29
  // ---------------------------------------------------------------------------
28
30
  // Helpers for Rust-side include resolution
29
31
  // ---------------------------------------------------------------------------
30
32
 
31
- /**
32
- * Recursively enrich relation metadata in the shape with target class shapes
33
- * so the Rust endpoint can resolve includes in-process (no extra GraphQL
34
- * round-trips per relation).
35
- */
36
- function enrichShapeForIncludes(
37
- metadata: ModelMetadata,
38
- include: IncludeMap,
39
- allRelMeta: Record<string, RelationMetadataEntry>,
40
- ): void {
41
- for (const [relName, includeVal] of Object.entries(include)) {
42
- if (!includeVal) continue;
43
- const meta = allRelMeta[relName];
44
- if (!meta?.target) continue;
45
-
46
- const TargetClass = meta.target() as typeof Ad4mModel;
47
- // Deep-copy so we don't mutate the cached metadata
48
- const targetMeta = JSON.parse(JSON.stringify(TargetClass.getModelMetadata()));
49
-
50
- // Ensure the relation is in metadata.relations (fallback for edge cases)
51
- if (!metadata.relations[relName]) {
52
- metadata.relations[relName] = {
53
- name: relName,
54
- predicate: meta.predicate,
55
- direction:
56
- meta.kind === 'belongsToMany' || meta.kind === 'belongsToOne'
57
- ? 'reverse'
58
- : 'forward',
59
- };
60
- }
61
- const rel = metadata.relations[relName] as any;
62
- rel.kind = meta.kind;
63
- rel.maxCount = meta.maxCount;
64
- rel.targetShape = targetMeta;
65
- rel.targetClassName = targetMeta.className;
66
-
67
- // Recurse for nested includes
68
- const nested =
69
- typeof includeVal === 'object' && includeVal !== null
70
- ? (includeVal as any).include
71
- : undefined;
72
- if (nested) {
73
- const targetRelMeta = getRelationsMetadata(TargetClass as any);
74
- enrichShapeForIncludes(targetMeta, nested, targetRelMeta);
75
- }
76
- }
77
- }
78
-
79
33
  /**
80
34
  * Construct a model class instance from a plain JSON object returned by the
81
35
  * Rust endpoint. Recursively converts included relation values (which come
@@ -126,19 +80,6 @@ function jsonToModelInstance<T extends Ad4mModel>(
126
80
  instance[key] = value;
127
81
  }
128
82
 
129
- // Apply property transform functions from decorators (only for literal-resolved
130
- // or no-resolveLanguage properties; non-literal properties are resolved + transformed
131
- // asynchronously in executeModelQuery).
132
- try {
133
- const propsMeta = getPropertiesMetadata(ModelClass as any);
134
- for (const [propName, opts] of Object.entries(propsMeta)) {
135
- const o = opts as any;
136
- if (typeof o.transform !== 'function' || !(propName in json)) continue;
137
- // Skip non-literal resolveLanguage props — they need async expression resolution first
138
- if (o.resolveLanguage != null && o.resolveLanguage !== 'literal') continue;
139
- instance[propName] = o.transform(instance[propName]);
140
- }
141
- } catch (_) { /* no metadata available */ }
142
83
 
143
84
  // Recursively convert included relation values to class instances
144
85
  if (include) {
@@ -402,8 +343,8 @@ export class Ad4mModel {
402
343
  ...(options.getter !== undefined && { getter: options.getter }),
403
344
  ...(options.prologSetter !== undefined && { prologSetter: options.prologSetter }),
404
345
  ...(options.local !== undefined && { local: options.local }),
405
- ...(options.transform !== undefined && { transform: options.transform }),
406
- ...(options.flag !== undefined && { flag: options.flag })
346
+ ...(options.flag !== undefined && { flag: options.flag }),
347
+ ...(options.transform !== undefined && { transform: options.transform })
407
348
  };
408
349
  }
409
350
 
@@ -619,7 +560,8 @@ export class Ad4mModel {
619
560
  * • `null` / empty object — skip ALL relations (used by bare
620
561
  * subscriptions that don't eagerly load relations).
621
562
  */
622
- private takeSnapshot(includedRelations?: Record<string, any> | null): void {
563
+ /** @internal */
564
+ protected takeSnapshot(includedRelations?: Record<string, any> | null): void {
623
565
  const ctor = this.constructor as typeof Ad4mModel;
624
566
  const metadata = ctor.getModelMetadata();
625
567
  const snap: Record<string, any> = {};
@@ -826,127 +768,18 @@ export class Ad4mModel {
826
768
 
827
769
  /**
828
770
  * Build the JSON parameters needed for a model query/subscription endpoint.
829
- * Returns the className, queryJson, and shapeJson that the Rust executor expects.
771
+ * Returns the className and queryJson that the Rust executor expects.
772
+ * Shape resolution happens server-side from the perspective's SHACL triples.
830
773
  * @internal
831
774
  */
832
775
  static prepareModelQueryParams(
833
776
  query: Query = {},
834
777
  classNameOverride?: string | null,
835
- ): { className: string; queryJson: string; shapeJson: string } {
836
- const metadata = this.getModelMetadata();
837
- const className = classNameOverride || metadata.className;
838
-
839
- const queryInput: any = {};
840
- if (query.parent) {
841
- const parentPredicate = resolveParentPredicate(query.parent, this);
842
- queryInput.parent = { id: query.parent.id, predicate: parentPredicate };
843
- }
844
- if (query.properties) queryInput.properties = query.properties;
845
- if (query.include) queryInput.include = query.include;
846
- if (query.where) queryInput.where = query.where;
847
- if (query.order) {
848
- queryInput.order = Object.entries(query.order).map(([k, v]) => [k, v]);
849
- }
850
- if (query.offset !== undefined) queryInput.offset = query.offset;
851
- if (query.limit !== undefined) queryInput.limit = query.limit;
852
- if (query.count !== undefined) queryInput.count = query.count;
853
- queryInput.deepQuery = query.deepQuery ?? true;
854
-
855
- if (query.include) {
856
- const allRelMeta = getRelationsMetadata(this as any);
857
- enrichShapeForIncludes(metadata, query.include, allRelMeta);
858
- }
859
-
860
- // Pre-compute conformance getters for Rust-side evaluation.
861
- // Where clauses are NOT compiled into getter SPARQL because stored
862
- // property values are signed expression envelopes (literal:json:...),
863
- // not simple literal:string:X values. Instead, where clauses are
864
- // attached as metadata for Rust-side post-evaluation filtering.
865
- {
866
- const allRelMeta = getRelationsMetadata(this as any);
867
- for (const [relName, relMeta] of Object.entries(metadata.relations)) {
868
- const rel = relMeta as any;
869
- if (rel.getter || rel.direction === 'reverse' || rel.filter === false) continue;
870
- const meta = allRelMeta[relName];
871
- if (!meta?.target) continue;
872
- try {
873
- const TargetClass = meta.target();
874
- const filter = buildConformanceFilter(meta.predicate, TargetClass);
875
-
876
- if (filter) {
877
- rel.getter = filter.getter;
878
- }
879
-
880
- // Attach where-clause metadata for Rust-side post-getter filtering
881
- if (rel.where) {
882
- try {
883
- const targetMetadata = (TargetClass as any).getModelMetadata?.() ?? null;
884
- if (targetMetadata) {
885
- const predicates: Record<string, string> = {};
886
- for (const propName of Object.keys(rel.where)) {
887
- if (['id', 'author', 'timestamp'].includes(propName)) continue;
888
- const propMeta = targetMetadata.properties[propName];
889
- if (propMeta?.predicate) {
890
- predicates[propName] = propMeta.predicate;
891
- }
892
- }
893
- if (Object.keys(predicates).length > 0) {
894
- rel.whereFilter = rel.where;
895
- rel.wherePredicates = predicates;
896
- }
897
- }
898
- } catch (_) {}
899
- }
900
- } catch (_) {}
901
- }
902
- }
903
-
904
- return {
905
- className,
906
- queryJson: JSON.stringify(queryInput),
907
- shapeJson: JSON.stringify(metadata),
908
- };
909
- }
910
-
911
- /**
912
- * Parse raw model query/subscription result JSON into typed model instances.
913
- * Used by ModelQueryBuilder to convert subscription updates without circular imports.
914
- * @internal
915
- */
916
- static parseModelResult<T extends Ad4mModel>(
917
- this: typeof Ad4mModel & (new (...args: any[]) => T),
918
- perspective: PerspectiveProxy,
919
- raw: any,
920
- include?: IncludeMap,
921
- properties?: string[],
922
- ): T[] {
923
- const data = typeof raw === 'string' ? JSON.parse(raw) : raw;
924
- const arr = data.instances || data;
925
- if (!Array.isArray(arr)) return [];
926
- return arr.map((json: any) => jsonToModelInstance(this, perspective, json, include, properties));
927
- }
928
-
929
- // instancesFromQueryResult — removed (superseded by Rust executeModelQuery pipeline)
930
-
931
- /**
932
- * Execute a model query via the executor-side endpoint.
933
- *
934
- * This replaces the old SPARQL-build → hydrate → JS-filter → JS-sort → JS-paginate pipeline
935
- * with a single RPC to the executor that handles everything in Rust.
936
- *
937
- * @internal
938
- */
939
- private static async executeModelQuery<T extends Ad4mModel>(
940
- this: typeof Ad4mModel & (new (...args: any[]) => T),
941
- perspective: PerspectiveProxy,
942
- query: Query = {},
943
- classNameOverride?: string | null,
944
- ): Promise<ResultsWithTotalCount<T>> {
778
+ ): { className: string; queryJson: string; metadata: ModelMetadata } {
945
779
  const metadata = this.getModelMetadata();
946
780
  const className = classNameOverride || metadata.className;
947
781
 
948
782
  // Expand includeAll: true to a full IncludeMap covering every forward relation.
949
- // Done before queryInput is built so all downstream uses of query.include see the expansion.
950
783
  if (query.includeAll) {
951
784
  const allRelMeta = getRelationsMetadata(this as any);
952
785
  const expanded: IncludeMap = {};
@@ -955,12 +788,9 @@ export class Ad4mModel {
955
788
  expanded[relName] = true;
956
789
  }
957
790
  }
958
- // Explicit include entries take precedence over the expansion
959
791
  query = { ...query, include: { ...expanded, ...query.include } };
960
792
  }
961
793
 
962
- // Build the query input that the Rust endpoint expects.
963
- // Convert the TS Query type to the executor's ModelQueryInput format.
964
794
  const queryInput: any = {};
965
795
  if (query.parent) {
966
796
  const parentPredicate = resolveParentPredicate(query.parent, this);
@@ -981,18 +811,20 @@ export class Ad4mModel {
981
811
  }
982
812
  if (Object.keys(normalIncludes).length > 0) queryInput.include = normalIncludes;
983
813
  if (Object.keys(projections).length > 0) {
984
- // Enrich projections with target shapes so Rust can apply where clause filtering
814
+ // Tag each projection with its target class name so the executor can
815
+ // resolve the target shape through its in-memory cache when applying
816
+ // projection where-clause filters.
985
817
  const allRelMeta = getRelationsMetadata(this as any);
986
818
  for (const [, proj] of Object.entries(projections)) {
987
819
  const relMeta = allRelMeta[proj.from];
988
- if (!proj.targetShape && relMeta?.target) {
820
+ if (!proj.targetClassName && relMeta?.target) {
989
821
  try {
990
822
  const TargetClass = relMeta.target();
991
823
  const targetMeta = (TargetClass as any).getModelMetadata?.();
992
- if (targetMeta) {
993
- proj.targetShape = targetMeta;
824
+ if (targetMeta?.className) {
825
+ proj.targetClassName = targetMeta.className;
994
826
  }
995
- } catch (_) { /* target class may not be available */ }
827
+ } catch (e) { console.debug(`prepareModelQueryParams: target class unavailable for projection:`, e); }
996
828
  }
997
829
  }
998
830
  queryInput.projections = projections;
@@ -1000,7 +832,6 @@ export class Ad4mModel {
1000
832
  }
1001
833
  if (query.where) queryInput.where = query.where;
1002
834
  if (query.order) {
1003
- // Convert { propName: 'ASC' | 'DESC' } to [[propName, 'ASC'|'DESC'], ...]
1004
835
  queryInput.order = Object.entries(query.order).map(([k, v]) => [k, v]);
1005
836
  }
1006
837
  if (query.offset !== undefined) queryInput.offset = query.offset;
@@ -1008,74 +839,59 @@ export class Ad4mModel {
1008
839
  if (query.count !== undefined) queryInput.count = query.count;
1009
840
  queryInput.deepQuery = query.deepQuery ?? true;
1010
841
 
1011
- // Enrich relation metadata with target class shapes for Rust-side
1012
- // include resolution. This eliminates per-relation GraphQL round-trips
1013
- // by letting the Rust endpoint resolve includes in-process.
1014
- if (queryInput.include) {
1015
- const allRelMeta = getRelationsMetadata(this as any);
1016
- enrichShapeForIncludes(metadata, queryInput.include, allRelMeta);
1017
- }
842
+ // Conformance getters, where filters, and target shapes for includes
843
+ // are all resolved by the executor from the perspective's SHACL triples
844
+ // — no client-side pre-computation is needed any more.
1018
845
 
1019
- // ── Pre-compute conformance getters for Rust-side evaluation ──────
1020
- // For each relation with a target class and filter !== false, compute
1021
- // the conformance getter SPARQL so Rust can evaluate it in-process
1022
- // (eliminating N × querySparql round-trips per instance).
1023
- // When a relation has a `where` clause, compile the where conditions
1024
- // into the getter SPARQL so Rust applies them during evaluation.
1025
- {
1026
- const allRelMeta = getRelationsMetadata(this as any);
1027
- for (const [relName, relMeta] of Object.entries(metadata.relations)) {
1028
- const rel = relMeta as any;
1029
- if (rel.getter) continue; // explicit getter already set
1030
- if (rel.direction === 'reverse') continue; // reverse relations use reverse link lookup
1031
- if (rel.filter === false) continue; // opt-out of conformance filtering
1032
-
1033
- const meta = allRelMeta[relName];
1034
- if (!meta?.target) continue;
846
+ return {
847
+ className,
848
+ queryJson: JSON.stringify(queryInput),
849
+ metadata,
850
+ };
851
+ }
1035
852
 
1036
- try {
1037
- const TargetClass = meta.target();
1038
- const filter = buildConformanceFilter(meta.predicate, TargetClass);
853
+ /**
854
+ * Parse raw model query/subscription result JSON into typed model instances.
855
+ * Used by ModelQueryBuilder to convert subscription updates without circular imports.
856
+ * @internal
857
+ */
858
+ static parseModelResult<T extends Ad4mModel>(
859
+ this: typeof Ad4mModel & (new (...args: any[]) => T),
860
+ perspective: PerspectiveProxy,
861
+ raw: any,
862
+ include?: IncludeMap,
863
+ properties?: string[],
864
+ ): T[] {
865
+ const data = typeof raw === 'string' ? JSON.parse(raw) : raw;
866
+ const arr = data.instances || data;
867
+ if (!Array.isArray(arr)) return [];
868
+ return arr.map((json: any) => jsonToModelInstance(this, perspective, json, include, properties));
869
+ }
1039
870
 
1040
- if (filter) {
1041
- rel.getter = filter.getter;
1042
- }
1043
871
 
1044
- // Attach where-clause metadata for Rust-side post-getter filtering.
1045
- // Property values are signed expression envelopes (literal:json:...)
1046
- // and cannot be matched by SPARQL FILTER on the raw IRI.
1047
- if (rel.where) {
1048
- try {
1049
- const targetMetadata = (TargetClass as any).getModelMetadata?.() ?? null;
1050
- if (targetMetadata) {
1051
- const predicates: Record<string, string> = {};
1052
- for (const propName of Object.keys(rel.where)) {
1053
- if (['id', 'author', 'timestamp'].includes(propName)) continue;
1054
- const propMeta = targetMetadata.properties[propName];
1055
- if (propMeta?.predicate) {
1056
- predicates[propName] = propMeta.predicate;
1057
- }
1058
- }
1059
- if (Object.keys(predicates).length > 0) {
1060
- rel.whereFilter = rel.where;
1061
- rel.wherePredicates = predicates;
1062
- }
1063
- }
1064
- } catch (_) { /* target metadata unavailable */ }
1065
- }
1066
- } catch (e) {
1067
- // Target class may not be available; skip silently
1068
- }
1069
- }
1070
- }
872
+ // instancesFromQueryResult — removed (superseded by Rust executeModelQuery pipeline)
1071
873
 
1072
- // Send shape metadata to the executor so it knows the model structure.
1073
- // This is more reliable than reading SHACL from the store because
1074
- // the TS decorators are the definitive source of truth.
1075
- const shapeJson = JSON.stringify(metadata);
1076
- const queryJson = JSON.stringify(queryInput);
874
+ /**
875
+ * Execute a model query via the executor-side endpoint.
876
+ *
877
+ * This replaces the old SPARQL-build → hydrate → JS-filter → JS-sort → JS-paginate pipeline
878
+ * with a single RPC to the executor that handles everything in Rust.
879
+ *
880
+ * @internal
881
+ */
882
+ private static async executeModelQuery<T extends Ad4mModel>(
883
+ this: typeof Ad4mModel & (new (...args: any[]) => T),
884
+ perspective: PerspectiveProxy,
885
+ query: Query = {},
886
+ classNameOverride?: string | null,
887
+ ): Promise<ResultsWithTotalCount<T>> {
888
+ // Delegate query input building to the shared prepareModelQueryParams
889
+ // helper. The executor resolves the shape from SHACL server-side.
890
+ const { className, queryJson } = this.prepareModelQueryParams(
891
+ query, classNameOverride,
892
+ );
1077
893
 
1078
- const result = await perspective.modelQuery(className, queryJson, shapeJson);
894
+ const result = await perspective.modelQuery(className, queryJson);
1079
895
 
1080
896
  // Convert JSON instances to model class instances, recursively constructing
1081
897
  // class instances for any included relations resolved by Rust.
@@ -1083,39 +899,14 @@ export class Ad4mModel {
1083
899
  return jsonToModelInstance(this, perspective, json, query.include, query.properties);
1084
900
  });
1085
901
 
1086
- // Resolve non-literal expressions (e.g. file languages where the stored
1087
- // value is a content-addressed hash that must be fetched from the language
1088
- // runtime). The Rust endpoint returns raw target URIs; we resolve them here.
1089
- const propsMeta = getPropertiesMetadata(this as any);
1090
- const resolveProps = Object.entries(propsMeta).filter(
1091
- ([, opts]: [string, any]) =>
1092
- opts.resolveLanguage != null &&
1093
- opts.resolveLanguage !== 'literal',
1094
- );
1095
- if (resolveProps.length > 0) {
1096
- await Promise.all(
1097
- instances.map(async (inst: any) => {
1098
- for (const [propName, opts] of resolveProps) {
1099
- const val = inst[propName];
1100
- if (typeof val !== 'string' || !val || val.startsWith('literal:')) continue;
1101
- try {
1102
- const expression = await perspective.getExpression(val);
1103
- if (expression) {
1104
- let resolved: any;
1105
- try { resolved = JSON.parse(expression.data); } catch { resolved = expression.data; }
1106
- const transform = (opts as any).transform;
1107
- inst[propName] = typeof transform === 'function' ? transform(resolved) : resolved;
1108
- }
1109
- } catch (_) { /* resolution failed — keep raw value */ }
1110
- }
1111
- }),
1112
- );
1113
- }
1114
-
1115
- // Take snapshots for dirty tracking
1116
- const snapshotRelations = queryInput.include;
902
+ // Take snapshots for dirty tracking (exclude $-prefixed projection keys)
903
+ const snapshotRelations = query.include
904
+ ? Object.fromEntries(Object.entries(query.include).filter(([k]) => !k.startsWith('$')))
905
+ : undefined;
1117
906
  for (const inst of instances) {
1118
- (inst as Ad4mModel).takeSnapshot(snapshotRelations);
907
+ (inst as Ad4mModel).takeSnapshot(
908
+ snapshotRelations && Object.keys(snapshotRelations).length > 0 ? snapshotRelations : undefined,
909
+ );
1119
910
  }
1120
911
 
1121
912
  return {
@@ -1129,40 +920,36 @@ export class Ad4mModel {
1129
920
  *
1130
921
  * @param perspective - The perspective to search in
1131
922
  * @param query - Optional query parameters to filter results
1132
- * @param useSPARQL - Whether to use SPARQL (default: true, 10-100x faster) or Prolog (legacy)
923
+ * @param _engine - **Deprecated.** Accepted for backward compatibility but ignored.
924
+ * All queries now use the Rust SPARQL pipeline.
1133
925
  * @returns Array of matching models
1134
- *
926
+ *
1135
927
  * @example
1136
928
  * ```typescript
1137
- * // Get all recipes (uses SPARQL by default)
1138
929
  * const allRecipes = await Recipe.findAll(perspective);
1139
- *
1140
- * // Get recipes with specific criteria (uses SPARQL)
930
+ *
1141
931
  * const recipes = await Recipe.findAll(perspective, {
1142
- * where: {
932
+ * where: {
1143
933
  * name: "Pasta",
1144
934
  * rating: { gt: 4 }
1145
935
  * },
1146
936
  * order: { createdAt: "DESC" },
1147
937
  * limit: 10
1148
938
  * });
1149
- *
1150
- * // Explicitly use Prolog (legacy, for backward compatibility)
1151
- * const recipesProlog = await Recipe.findAll(perspective, {}, false);
1152
939
  * ```
1153
940
  */
1154
- static async findAll<T extends Ad4mModel>(
1155
- this: typeof Ad4mModel & (new (...args: any[]) => T),
1156
- perspective: PerspectiveProxy,
1157
- query: Query = {},
1158
- _engine?: 'sparql' | 'prolog' | boolean
1159
- ): Promise<T[]> {
1160
- if (query.properties && query.properties.length === 0) {
941
+ static async findAll<T extends Ad4mModel, Q extends TypedQuery<T> = {}>(
942
+ this: typeof Ad4mModel & (new (...args: any[]) => T),
943
+ perspective: PerspectiveProxy,
944
+ query?: Q,
945
+ ): Promise<(T & IncludeExtras<T, IncludeOf<Q>>)[]> {
946
+ const q = (query ?? {}) as Query;
947
+ if (q.properties && q.properties.length === 0) {
1161
948
  throw new Error("properties[] must not be empty — omit the field to return all properties, or specify at least one field name");
1162
949
  }
1163
950
 
1164
- const { results } = await this.executeModelQuery(perspective, query);
1165
- return results;
951
+ const { results } = await this.executeModelQuery(perspective, q);
952
+ return results as (T & IncludeExtras<T, IncludeOf<Q>>)[];
1166
953
  }
1167
954
 
1168
955
  /**
@@ -1172,7 +959,7 @@ export class Ad4mModel {
1172
959
  *
1173
960
  * @param perspective - The perspective to search in
1174
961
  * @param query - Optional query parameters to filter results
1175
- * @param useSPARQL - Whether to use SPARQL (default: true) or Prolog (legacy)
962
+ * @param _engine - **Deprecated.** Accepted for backward compatibility but ignored.
1176
963
  * @returns The first matching instance, or `null`
1177
964
  *
1178
965
  * @example
@@ -1185,14 +972,13 @@ export class Ad4mModel {
1185
972
  * }
1186
973
  * ```
1187
974
  */
1188
- static async findOne<T extends Ad4mModel>(
975
+ static async findOne<T extends Ad4mModel, Q extends TypedQuery<T> = {}>(
1189
976
  this: typeof Ad4mModel & (new (...args: any[]) => T),
1190
977
  perspective: PerspectiveProxy,
1191
- query: Query = {},
1192
- _engine?: 'sparql' | 'prolog' | boolean,
1193
- ): Promise<T | null> {
1194
- const limitedQuery = { ...query, limit: 1 };
1195
- const results = await this.findAll(perspective, limitedQuery);
978
+ query?: Q,
979
+ ): Promise<(T & IncludeExtras<T, IncludeOf<Q>>) | null> {
980
+ const limitedQuery = { ...((query ?? {}) as Query), limit: 1 } as Q;
981
+ const results = await this.findAll<T, Q>(perspective, limitedQuery);
1196
982
  return results[0] ?? null;
1197
983
  }
1198
984
 
@@ -1201,9 +987,9 @@ export class Ad4mModel {
1201
987
  *
1202
988
  * @param perspective - The perspective to search in
1203
989
  * @param query - Optional query parameters to filter results
1204
- * @param useSPARQL - Whether to use SPARQL (default: true, 10-100x faster) or Prolog (legacy)
990
+ * @param _engine - **Deprecated.** Accepted for backward compatibility but ignored.
1205
991
  * @returns Object containing results array and total count
1206
- *
992
+ *
1207
993
  * @example
1208
994
  * ```typescript
1209
995
  * const { results, totalCount } = await Recipe.findAllAndCount(perspective, {
@@ -1211,18 +997,15 @@ export class Ad4mModel {
1211
997
  * limit: 10
1212
998
  * });
1213
999
  * console.log(`Showing 10 of ${totalCount} dessert recipes`);
1214
- *
1215
- * // Use Prolog explicitly (legacy)
1216
- * const { results, totalCount } = await Recipe.findAllAndCount(perspective, {}, false);
1217
1000
  * ```
1218
1001
  */
1219
- static async findAllAndCount<T extends Ad4mModel>(
1220
- this: typeof Ad4mModel & (new (...args: any[]) => T),
1221
- perspective: PerspectiveProxy,
1222
- query: Query = {},
1223
- _engine?: 'sparql' | 'prolog' | boolean
1224
- ): Promise<ResultsWithTotalCount<T>> {
1225
- return await this.executeModelQuery(perspective, query);
1002
+ static async findAllAndCount<T extends Ad4mModel, Q extends TypedQuery<T> = {}>(
1003
+ this: typeof Ad4mModel & (new (...args: any[]) => T),
1004
+ perspective: PerspectiveProxy,
1005
+ query?: Q,
1006
+ ): Promise<ResultsWithTotalCount<T & IncludeExtras<T, IncludeOf<Q>>>> {
1007
+ const out = await this.executeModelQuery(perspective, (query ?? {}) as Query);
1008
+ return out as ResultsWithTotalCount<T & IncludeExtras<T, IncludeOf<Q>>>;
1226
1009
  }
1227
1010
 
1228
1011
  /**
@@ -1242,17 +1025,16 @@ export class Ad4mModel {
1242
1025
  * console.log(`Page ${page.pageNumber} of recipes, ${page.results.length} items`);
1243
1026
  * ```
1244
1027
  */
1245
- static async paginate<T extends Ad4mModel>(
1246
- this: typeof Ad4mModel & (new (...args: any[]) => T),
1247
- perspective: PerspectiveProxy,
1248
- pageSize: number,
1249
- pageNumber: number,
1250
- query?: Query,
1251
- _engine?: 'sparql' | 'prolog' | boolean
1252
- ): Promise<PaginationResult<T>> {
1253
- const paginationQuery = { ...(query || {}), limit: pageSize, offset: pageSize * (pageNumber - 1), count: true };
1028
+ static async paginate<T extends Ad4mModel, Q extends TypedQuery<T> = {}>(
1029
+ this: typeof Ad4mModel & (new (...args: any[]) => T),
1030
+ perspective: PerspectiveProxy,
1031
+ pageSize: number,
1032
+ pageNumber: number,
1033
+ query?: Q,
1034
+ ): Promise<PaginationResult<T & IncludeExtras<T, IncludeOf<Q>>>> {
1035
+ const paginationQuery = { ...((query ?? {}) as Query), limit: pageSize, offset: pageSize * (pageNumber - 1), count: true };
1254
1036
  const { results, totalCount } = await this.executeModelQuery(perspective, paginationQuery);
1255
- return { results, totalCount, pageSize, pageNumber };
1037
+ return { results: results as (T & IncludeExtras<T, IncludeOf<Q>>)[], totalCount, pageSize, pageNumber };
1256
1038
  }
1257
1039
 
1258
1040
  /**
@@ -1281,8 +1063,12 @@ export class Ad4mModel {
1281
1063
  * });
1282
1064
  * ```
1283
1065
  */
1284
- static async count(perspective: PerspectiveProxy, query: Query = {}): Promise<number> {
1285
- const { totalCount } = await this.executeModelQuery(perspective, { ...query, limit: 0 });
1066
+ static async count<T extends Ad4mModel>(
1067
+ this: typeof Ad4mModel & (new (...args: any[]) => T),
1068
+ perspective: PerspectiveProxy,
1069
+ query?: TypedQuery<T>,
1070
+ ): Promise<number> {
1071
+ const { totalCount } = await this.executeModelQuery(perspective, { ...((query ?? {}) as Query), limit: 0 });
1286
1072
  return totalCount;
1287
1073
  }
1288
1074
 
@@ -1646,28 +1432,13 @@ export class Ad4mModel {
1646
1432
  if (instances.length === 0) return;
1647
1433
  const metadata = this.getModelMetadata();
1648
1434
 
1649
- // Pre-compute conformance getters so the shape sent to Rust includes them
1650
- const allRelMeta = getRelationsMetadata(this as any);
1651
- for (const [relName, relMeta] of Object.entries(metadata.relations)) {
1652
- const rel = relMeta as any;
1653
- if (rel.getter || rel.direction === 'reverse' || rel.filter === false) continue;
1654
- const meta = allRelMeta[relName];
1655
- if (!meta?.target) continue;
1656
- try {
1657
- const TargetClass = meta.target();
1658
- const filter = buildConformanceFilter(meta.predicate, TargetClass);
1659
- if (filter) rel.getter = filter.getter;
1660
- } catch (_) { /* target class may not be available */ }
1661
- }
1662
-
1663
- const shapeJson = JSON.stringify(metadata);
1664
1435
  const instanceIds = instances.map(inst => inst.id || (inst as any)._baseExpression);
1665
1436
 
1666
- // Single RPC call evaluates all getters in-process on the executor
1437
+ // The executor reads getter SPARQL from the perspective's SHACL triples
1438
+ // (written by `addSdna`), so no shape JSON is shipped with the call.
1667
1439
  const result = await perspective.evaluateGetters(
1668
1440
  metadata.className,
1669
1441
  instanceIds,
1670
- shapeJson,
1671
1442
  propertyNames,
1672
1443
  );
1673
1444
 
@@ -1997,6 +1768,26 @@ export class Ad4mModel {
1997
1768
  await perspective.ensureSDNASubjectClass(this);
1998
1769
  }
1999
1770
 
1771
+ /**
1772
+ * Batch-registers multiple model classes on a perspective in a single RPC call.
1773
+ * This is significantly faster than calling `register()` on each model individually
1774
+ * because it eliminates N-1 round-trips and mutex acquisitions.
1775
+ *
1776
+ * @param perspective - The perspective to register the models on
1777
+ * @param models - Array of Ad4mModel subclasses to register
1778
+ *
1779
+ * @example
1780
+ * ```typescript
1781
+ * await Ad4mModel.registerAll(perspective, [Community, Channel, Message, Task]);
1782
+ * ```
1783
+ */
1784
+ static async registerAll(
1785
+ perspective: PerspectiveProxy,
1786
+ models: (typeof Ad4mModel)[],
1787
+ ): Promise<void> {
1788
+ await perspective.ensureSubjectClasses(models);
1789
+ }
1790
+
2000
1791
  /**
2001
1792
  * Executes a set of model operations inside a single batch (transaction).
2002
1793
  *
@@ -2058,11 +1849,11 @@ export class Ad4mModel {
2058
1849
  * ```
2059
1850
  */
2060
1851
  static query<T extends Ad4mModel>(
2061
- this: typeof Ad4mModel & (new (...args: any[]) => T),
2062
- perspective: PerspectiveProxy,
2063
- query?: Query
1852
+ this: typeof Ad4mModel & (new (...args: any[]) => T),
1853
+ perspective: PerspectiveProxy,
1854
+ query?: TypedQuery<T>,
2064
1855
  ): ModelQueryBuilder<T> {
2065
- return new ModelQueryBuilder<T>(perspective, this as any, query);
1856
+ return new ModelQueryBuilder<T>(perspective, this as any, (query ?? {}) as Query);
2066
1857
  }
2067
1858
 
2068
1859
  /**