@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
@@ -10,6 +10,7 @@ import type { PerspectiveProxy } from "../perspectives/PerspectiveProxy";
10
10
  import type {
11
11
  Where, Order, IncludeMap, Query,
12
12
  ResultsWithTotalCount, PaginationResult,
13
+ TypedWhere, TypedOrder, TypedIncludeMap, PropertyKeysOf,
13
14
  } from "./types";
14
15
 
15
16
  /** Query builder for Ad4mModel queries.
@@ -80,8 +81,8 @@ export class ModelQueryBuilder<T extends Ad4mModel> {
80
81
  * })
81
82
  * ```
82
83
  */
83
- where(conditions: Where): ModelQueryBuilder<T> {
84
- this.queryParams.where = conditions;
84
+ where(conditions: TypedWhere<T>): ModelQueryBuilder<T> {
85
+ this.queryParams.where = conditions as Where;
85
86
  return this;
86
87
  }
87
88
 
@@ -96,8 +97,8 @@ export class ModelQueryBuilder<T extends Ad4mModel> {
96
97
  * .order({ createdAt: "DESC" })
97
98
  * ```
98
99
  */
99
- order(orderBy: Order): ModelQueryBuilder<T> {
100
- this.queryParams.order = orderBy;
100
+ order(orderBy: TypedOrder<T>): ModelQueryBuilder<T> {
101
+ this.queryParams.order = orderBy as Order;
101
102
  return this;
102
103
  }
103
104
 
@@ -218,8 +219,8 @@ export class ModelQueryBuilder<T extends Ad4mModel> {
218
219
  * .properties(["name", "description", "rating"])
219
220
  * ```
220
221
  */
221
- properties(properties: string[]): ModelQueryBuilder<T> {
222
- this.queryParams.properties = properties;
222
+ properties(properties: PropertyKeysOf<T>[] | string[]): ModelQueryBuilder<T> {
223
+ this.queryParams.properties = properties as string[];
223
224
  return this;
224
225
  }
225
226
 
@@ -272,8 +273,8 @@ export class ModelQueryBuilder<T extends Ad4mModel> {
272
273
  * .run();
273
274
  * ```
274
275
  */
275
- include(map: IncludeMap): ModelQueryBuilder<T> {
276
- this.queryParams.include = map;
276
+ include(map: TypedIncludeMap<T>): ModelQueryBuilder<T> {
277
+ this.queryParams.include = map as IncludeMap;
277
278
  return this;
278
279
  }
279
280
 
@@ -282,14 +283,6 @@ export class ModelQueryBuilder<T extends Ad4mModel> {
282
283
  return this;
283
284
  }
284
285
 
285
- /**
286
- * Sets the query engine to use.
287
- * @deprecated Prolog engine has been removed. All queries use SPARQL/Rust.
288
- */
289
- engine(_eng: 'sparql' | 'prolog'): ModelQueryBuilder<T> {
290
- return this;
291
- }
292
-
293
286
  /**
294
287
  * Executes the query once and returns the results.
295
288
  *
@@ -336,8 +329,10 @@ export class ModelQueryBuilder<T extends Ad4mModel> {
336
329
  * ```
337
330
  */
338
331
  async first(): Promise<T | null> {
332
+ const savedLimit = this.queryParams.limit;
339
333
  this.queryParams.limit = 1;
340
334
  const results = await this.get();
335
+ this.queryParams.limit = savedLimit;
341
336
  return results[0] ?? null;
342
337
  }
343
338
 
@@ -375,15 +370,16 @@ export class ModelQueryBuilder<T extends Ad4mModel> {
375
370
 
376
371
  const ctor = this.ctor;
377
372
 
378
- // Build the model query params (className, queryJson, shapeJson)
379
- const { className, queryJson, shapeJson } = (ctor as any).prepareModelQueryParams(
373
+ // Build the model query params (className, queryJson). The executor
374
+ // resolves the shape from the perspective's SHACL triples.
375
+ const { className, queryJson } = (ctor as any).prepareModelQueryParams(
380
376
  this.queryParams, this.modelClassName
381
377
  );
382
378
 
383
379
  // Register model subscription via Rust — this builds trigger SPARQL internally,
384
380
  // registers the subscription, and runs the initial query in one call.
385
381
  const { subscriptionId, result: initialModelResult } = await this.perspective.modelSubscribe(
386
- className, queryJson, shapeJson
382
+ className, queryJson
387
383
  );
388
384
 
389
385
  // Convert JSON instances to model class instances
@@ -391,7 +387,7 @@ export class ModelQueryBuilder<T extends Ad4mModel> {
391
387
  return (ctor as any).parseModelResult(this.perspective, raw, this.queryParams.include, this.queryParams.properties);
392
388
  };
393
389
 
394
- // Parse initial results
390
+ // Transforms are now applied by the Rust executor during hydration
395
391
  const initialResults = parseResults(initialModelResult);
396
392
 
397
393
  // Track last emitted result fingerprint to suppress duplicate callbacks
@@ -411,8 +407,13 @@ export class ModelQueryBuilder<T extends Ad4mModel> {
411
407
  (rawResult: any) => {
412
408
  try {
413
409
  const results = parseResults(rawResult);
410
+ console.debug(`[ModelQueryBuilder.subscribe] Update received for ${subscriptionId}: ${results.length} instances`);
414
411
  const fp = buildFingerprint(results);
415
- if (fp === lastResultFingerprint) return;
412
+ if (fp === lastResultFingerprint) {
413
+ console.debug(`[ModelQueryBuilder.subscribe] Fingerprint unchanged, skipping callback`);
414
+ return;
415
+ }
416
+ console.debug(`[ModelQueryBuilder.subscribe] Fingerprint changed, calling callback with ${results.length} results`);
416
417
  lastResultFingerprint = fp;
417
418
  callback(results);
418
419
  } catch (e) {
@@ -421,21 +422,46 @@ export class ModelQueryBuilder<T extends Ad4mModel> {
421
422
  },
422
423
  );
423
424
 
424
- // Set up keepalive with failure tracking
425
- let keepaliveFailures = 0;
426
- const keepaliveTimer = setInterval(() => {
427
- this.perspective.client.keepAliveQuery(this.perspective.uuid, subscriptionId).then(() => {
428
- keepaliveFailures = 0;
429
- }).catch((e: any) => {
430
- keepaliveFailures++;
431
- console.warn(`Model subscription keepalive failed (attempt ${keepaliveFailures}) for ${subscriptionId}:`, e);
432
- });
433
- }, 30000);
425
+ // Set up keepalive with recovery — uses setTimeout loop so we can
426
+ // break out and resubscribe when the server evicts the subscription.
427
+ let disposed = false;
428
+ let keepaliveTimer: ReturnType<typeof setTimeout> | undefined;
429
+ let resubscribeAttempts = 0;
430
+ const MAX_RESUBSCRIBE_ATTEMPTS = 5;
431
+ const keepaliveLoop = async () => {
432
+ if (disposed) return;
433
+ try {
434
+ await this.perspective.client.keepAliveQuery(this.perspective.uuid, subscriptionId);
435
+ resubscribeAttempts = 0; // Reset on success
436
+ } catch (e: any) {
437
+ console.warn(`Model subscription keepalive failed for ${subscriptionId}:`, e);
438
+ if (!disposed && resubscribeAttempts < MAX_RESUBSCRIBE_ATTEMPTS) {
439
+ resubscribeAttempts++;
440
+ const backoffMs = Math.min(1000 * Math.pow(2, resubscribeAttempts), 60000);
441
+ console.warn(`Resubscribing (attempt ${resubscribeAttempts}/${MAX_RESUBSCRIBE_ATTEMPTS}, backoff ${backoffMs}ms)...`);
442
+ await new Promise(r => setTimeout(r, backoffMs));
443
+ try {
444
+ unsubscribe();
445
+ await this.subscribe(callback);
446
+ } catch (resubErr) {
447
+ console.error('Model subscription resubscribe failed:', resubErr);
448
+ }
449
+ } else if (resubscribeAttempts >= MAX_RESUBSCRIBE_ATTEMPTS) {
450
+ console.error(`Model subscription ${subscriptionId}: max resubscribe attempts reached, giving up.`);
451
+ }
452
+ return; // new subscription owns its own keepalive loop
453
+ }
454
+ if (!disposed) {
455
+ keepaliveTimer = setTimeout(keepaliveLoop, 30000);
456
+ }
457
+ };
458
+ keepaliveTimer = setTimeout(keepaliveLoop, 30000);
434
459
 
435
460
  // Store dispose function
436
461
  this.currentSubscription = {
437
462
  dispose: () => {
438
- clearInterval(keepaliveTimer);
463
+ disposed = true;
464
+ if (keepaliveTimer) clearTimeout(keepaliveTimer);
439
465
  unsubscribe();
440
466
  this.perspective.client.disposeQuerySubscription(this.perspective.uuid, subscriptionId).catch(() => {});
441
467
  },
@@ -515,12 +541,12 @@ export class ModelQueryBuilder<T extends Ad4mModel> {
515
541
  this.dispose();
516
542
 
517
543
  const countParams = { ...this.queryParams, limit: 0 };
518
- const { className, queryJson, shapeJson } = (this.ctor as any).prepareModelQueryParams(
544
+ const { className, queryJson } = (this.ctor as any).prepareModelQueryParams(
519
545
  countParams, this.modelClassName
520
546
  );
521
547
 
522
548
  const { subscriptionId, result: initialModelResult } = await this.perspective.modelSubscribe(
523
- className, queryJson, shapeJson
549
+ className, queryJson
524
550
  );
525
551
 
526
552
  const parseCount = (raw: any): number => {
@@ -541,19 +567,43 @@ export class ModelQueryBuilder<T extends Ad4mModel> {
541
567
  },
542
568
  );
543
569
 
544
- let keepaliveFailures = 0;
545
- const keepaliveTimer = setInterval(() => {
546
- this.perspective.client.keepAliveQuery(this.perspective.uuid, subscriptionId).then(() => {
547
- keepaliveFailures = 0;
548
- }).catch((e: any) => {
549
- keepaliveFailures++;
550
- console.warn(`Count subscription keepalive failed (attempt ${keepaliveFailures}) for ${subscriptionId}:`, e);
551
- });
552
- }, 30000);
570
+ let disposed = false;
571
+ let keepaliveTimer: ReturnType<typeof setTimeout> | undefined;
572
+ let resubscribeAttempts = 0;
573
+ const MAX_RESUBSCRIBE_ATTEMPTS = 5;
574
+ const keepaliveLoop = async () => {
575
+ if (disposed) return;
576
+ try {
577
+ await this.perspective.client.keepAliveQuery(this.perspective.uuid, subscriptionId);
578
+ resubscribeAttempts = 0;
579
+ } catch (e: any) {
580
+ console.warn(`Count subscription keepalive failed for ${subscriptionId}:`, e);
581
+ if (!disposed && resubscribeAttempts < MAX_RESUBSCRIBE_ATTEMPTS) {
582
+ resubscribeAttempts++;
583
+ const backoffMs = Math.min(1000 * Math.pow(2, resubscribeAttempts), 60000);
584
+ console.warn(`Count resubscribing (attempt ${resubscribeAttempts}/${MAX_RESUBSCRIBE_ATTEMPTS}, backoff ${backoffMs}ms)...`);
585
+ await new Promise(r => setTimeout(r, backoffMs));
586
+ try {
587
+ unsubscribe();
588
+ await this.countSubscribe(callback);
589
+ } catch (resubErr) {
590
+ console.error('Count subscription resubscribe failed:', resubErr);
591
+ }
592
+ } else if (resubscribeAttempts >= MAX_RESUBSCRIBE_ATTEMPTS) {
593
+ console.error(`Count subscription ${subscriptionId}: max resubscribe attempts reached, giving up.`);
594
+ }
595
+ return;
596
+ }
597
+ if (!disposed) {
598
+ keepaliveTimer = setTimeout(keepaliveLoop, 30000);
599
+ }
600
+ };
601
+ keepaliveTimer = setTimeout(keepaliveLoop, 30000);
553
602
 
554
603
  this.currentSubscription = {
555
604
  dispose: () => {
556
- clearInterval(keepaliveTimer);
605
+ disposed = true;
606
+ if (keepaliveTimer) clearTimeout(keepaliveTimer);
557
607
  unsubscribe();
558
608
  this.perspective.client.disposeQuerySubscription(this.perspective.uuid, subscriptionId).catch(() => {});
559
609
  },
@@ -645,12 +695,12 @@ export class ModelQueryBuilder<T extends Ad4mModel> {
645
695
  const subscriptionParams = { ...(this.queryParams || {}) };
646
696
  delete subscriptionParams.limit;
647
697
  delete subscriptionParams.offset;
648
- const { className, queryJson, shapeJson } = (ctor as any).prepareModelQueryParams(
698
+ const { className, queryJson } = (ctor as any).prepareModelQueryParams(
649
699
  subscriptionParams, this.modelClassName
650
700
  );
651
701
 
652
702
  const { subscriptionId } = await this.perspective.modelSubscribe(
653
- className, queryJson, shapeJson
703
+ className, queryJson
654
704
  );
655
705
 
656
706
  // Build the paginated query for Rust endpoint (count: true fetches both results and totalCount in one call)
@@ -669,23 +719,48 @@ export class ModelQueryBuilder<T extends Ad4mModel> {
669
719
  const unsubscribe = this.perspective.client.subscribeToQueryUpdates(
670
720
  subscriptionId,
671
721
  (rawResult: any) => {
722
+ console.debug(`[ModelQueryBuilder.paginateSubscribe] Update received for ${subscriptionId}, re-fetching paginated data...`);
672
723
  processResults().catch(e => console.error('Paginate subscription error:', e));
673
724
  },
674
725
  );
675
726
 
676
- let keepaliveFailures = 0;
677
- const keepaliveTimer = setInterval(() => {
678
- this.perspective.client.keepAliveQuery(this.perspective.uuid, subscriptionId).then(() => {
679
- keepaliveFailures = 0;
680
- }).catch((e: any) => {
681
- keepaliveFailures++;
682
- console.warn(`Paginate subscription keepalive failed (attempt ${keepaliveFailures}) for ${subscriptionId}:`, e);
683
- });
684
- }, 30000);
727
+ let disposed = false;
728
+ let keepaliveTimer: ReturnType<typeof setTimeout> | undefined;
729
+ let resubscribeAttempts = 0;
730
+ const MAX_RESUBSCRIBE_ATTEMPTS = 5;
731
+ const keepaliveLoop = async () => {
732
+ if (disposed) return;
733
+ try {
734
+ await this.perspective.client.keepAliveQuery(this.perspective.uuid, subscriptionId);
735
+ resubscribeAttempts = 0;
736
+ } catch (e: any) {
737
+ console.warn(`Paginate subscription keepalive failed for ${subscriptionId}:`, e);
738
+ if (!disposed && resubscribeAttempts < MAX_RESUBSCRIBE_ATTEMPTS) {
739
+ resubscribeAttempts++;
740
+ const backoffMs = Math.min(1000 * Math.pow(2, resubscribeAttempts), 60000);
741
+ console.warn(`Paginate resubscribing (attempt ${resubscribeAttempts}/${MAX_RESUBSCRIBE_ATTEMPTS}, backoff ${backoffMs}ms)...`);
742
+ await new Promise(r => setTimeout(r, backoffMs));
743
+ try {
744
+ unsubscribe();
745
+ await this.paginateSubscribe(pageSize, pageNumber, callback);
746
+ } catch (resubErr) {
747
+ console.error('Paginate subscription resubscribe failed:', resubErr);
748
+ }
749
+ } else if (resubscribeAttempts >= MAX_RESUBSCRIBE_ATTEMPTS) {
750
+ console.error(`Paginate subscription ${subscriptionId}: max resubscribe attempts reached, giving up.`);
751
+ }
752
+ return;
753
+ }
754
+ if (!disposed) {
755
+ keepaliveTimer = setTimeout(keepaliveLoop, 30000);
756
+ }
757
+ };
758
+ keepaliveTimer = setTimeout(keepaliveLoop, 30000);
685
759
 
686
760
  this.currentSubscription = {
687
761
  dispose: () => {
688
- clearInterval(keepaliveTimer);
762
+ disposed = true;
763
+ if (keepaliveTimer) clearTimeout(keepaliveTimer);
689
764
  unsubscribe();
690
765
  this.perspective.client.disposeQuerySubscription(this.perspective.uuid, subscriptionId).catch(() => {});
691
766
  },
@@ -274,11 +274,14 @@ export interface PropertyOptions {
274
274
  local?: boolean;
275
275
 
276
276
  /**
277
- * Optional transform function to modify the property value after it is retrieved.
278
- * This is useful for transforming raw data into a more usable format.
279
- * The function takes the raw value as input and returns the transformed value.
277
+ * Optional transform expression to modify the property value.
278
+ * This is a SHACL-AF Node Expression that runs in the Rust model query engine.
279
+ * Examples: `fileToDataUri`, `concat(literal('prefix_'), focus())`, etc.
280
+ * Builders (`focus`, `literal`, `path`, `exists`, `ifExpr`, `concat`,
281
+ * `coalesce`, `fn`) and the `fileToDataUri` built-in are exported from
282
+ * the package root: `import { concat, literal, focus } from '@coasys/ad4m'`.
280
283
  */
281
- transform?: (value: any) => any;
284
+ transform?: import('../shacl/NodeExpression').NodeExpression;
282
285
 
283
286
  /**
284
287
  * Allowed values for this property (enum constraint).
@@ -858,17 +861,8 @@ export function HasMany(
858
861
  first: (() => Ad4mModelLike) | RelationOptions,
859
862
  second?: Omit<RelationOptions, 'target'>,
860
863
  ): PropertyDecorator {
861
- const explicitThrough = typeof first === 'function' ? second?.through : (first as RelationOptions).through;
862
864
  const opts = resolveRelationArgs(first, second);
863
865
  return function <T>(target: T, key: keyof T) {
864
- if (!explicitThrough && !opts.getter) {
865
- const className = ((target as any).constructor?.name) ?? 'unknown';
866
- console.warn(
867
- `@HasMany on ${className}.${String(key)} has no 'through' predicate — defaulting to 'ad4m://has_child'. ` +
868
- `Add { through: 'ad4m://has_child' } to silence this warning, or use a semantic predicate ` +
869
- `like { through: 'myns://has_${String(key)}' } for efficient targeted queries.`
870
- );
871
- }
872
866
  // --- relation registry ---
873
867
  const ctor = (target as any).constructor;
874
868
  if (!relationRegistry.has(ctor)) relationRegistry.set(ctor, {});
@@ -1,6 +1,6 @@
1
- import { buildSPARQLOrderLimitOffset, buildSPARQLQuery, buildPaginationSubquery, hasJsOnlyWhereFilters } from './query-sparql';
1
+ import { buildSPARQLQuery, buildPaginationSubquery, hasJsOnlyWhereFilters } from './query-sparql';
2
2
 
3
- // Minimal stubs for ModelMetadata — buildSPARQLOrderLimitOffset only uses the query arg
3
+ // Minimal stubs for ModelMetadata
4
4
  const emptyMetadata: any = { properties: {}, relations: {} };
5
5
 
6
6
  // Metadata with a required (non-literal) property and a literal-stored property
@@ -87,19 +87,6 @@ describe('buildSPARQLQuery — SPARQL-level pagination via subquery', () => {
87
87
  });
88
88
  });
89
89
 
90
- describe('buildSPARQLOrderLimitOffset', () => {
91
- it('always returns empty string (pagination uses subquery pattern instead)', () => {
92
- expect(buildSPARQLOrderLimitOffset(emptyMetadata, {})).toBe('');
93
- expect(buildSPARQLOrderLimitOffset(emptyMetadata, { limit: 50 })).toBe('');
94
- expect(buildSPARQLOrderLimitOffset(emptyMetadata, { limit: 50, offset: 100 })).toBe('');
95
- expect(buildSPARQLOrderLimitOffset(emptyMetadata, { order: { timestamp: 'DESC' } })).toBe('');
96
- expect(buildSPARQLOrderLimitOffset(emptyMetadata, {
97
- order: { timestamp: 'DESC' },
98
- limit: 50,
99
- offset: 100,
100
- })).toBe('');
101
- });
102
- });
103
90
 
104
91
  describe('buildSPARQLQuery — parse_literal push-down filters', () => {
105
92
  const modelClass: any = {};
@@ -161,13 +148,42 @@ describe('buildSPARQLQuery — structural correctness', () => {
161
148
  expect(sparql).toContain('SELECT DISTINCT ?source');
162
149
  });
163
150
 
164
- it('does not allow injection through where clause IRI values', () => {
151
+ it('rejects injection attempts through where clause IRI values', () => {
165
152
  const query = {
166
153
  where: { category: 'some://uri"> . } UNION { SELECT * WHERE { ?s ?p ?o' },
167
154
  };
168
- const sparql = buildSPARQLQuery(richMetadata, emptyRelations, query, modelClass);
169
- // Value should be wrapped in angle brackets as an IRI
170
- expect(sparql).toContain('<some://uri');
155
+ expect(() => buildSPARQLQuery(richMetadata, emptyRelations, query, modelClass))
156
+ .toThrow('Invalid IRI component');
157
+ });
158
+
159
+ it('rejects angle brackets in IRI values', () => {
160
+ const query = { where: { category: 'foo<bar>' } };
161
+ expect(() => buildSPARQLQuery(richMetadata, emptyRelations, query, modelClass))
162
+ .toThrow('Invalid IRI component');
163
+ });
164
+
165
+ it('rejects curly braces in IRI values', () => {
166
+ const query = { where: { category: 'foo{bar}' } };
167
+ expect(() => buildSPARQLQuery(richMetadata, emptyRelations, query, modelClass))
168
+ .toThrow('Invalid IRI component');
169
+ });
170
+
171
+ it('rejects spaces in IRI values', () => {
172
+ const query = { where: { category: 'foo bar' } };
173
+ expect(() => buildSPARQLQuery(richMetadata, emptyRelations, query, modelClass))
174
+ .toThrow('Invalid IRI component');
175
+ });
176
+
177
+ it('rejects double quotes in IRI values', () => {
178
+ const query = { where: { category: 'foo"bar' } };
179
+ expect(() => buildSPARQLQuery(richMetadata, emptyRelations, query, modelClass))
180
+ .toThrow('Invalid IRI component');
181
+ });
182
+
183
+ it('allows valid URIs through iri()', () => {
184
+ const query = { where: { category: 'https://example.com/category/food' } };
185
+ expect(() => buildSPARQLQuery(richMetadata, emptyRelations, query, modelClass))
186
+ .not.toThrow();
171
187
  });
172
188
  });
173
189
 
@@ -119,7 +119,9 @@ function escapeSPARQL(value: string): string {
119
119
  .replace(/"/g, '\\"')
120
120
  .replace(/\n/g, "\\n")
121
121
  .replace(/\r/g, "\\r")
122
- .replace(/\t/g, "\\t");
122
+ .replace(/\t/g, "\\t")
123
+ .replace(/\0/g, "")
124
+ .replace(/\f/g, "\\u000C");
123
125
  }
124
126
 
125
127
  /**
@@ -136,8 +138,14 @@ export function formatSPARQLValue(value: any): string {
136
138
  * Format an AD4M URI as an RDF IRI for use in SPARQL triple patterns.
137
139
  * All AD4M link source/predicate/target values become IRIs in angle brackets.
138
140
  * The Rust SPARQL service transparently transforms these to valid IRI format.
141
+ *
142
+ * Rejects characters that would break or inject into a SPARQL IRI token,
143
+ * matching the Rust-side `validate_iri()` function.
139
144
  */
140
145
  function iri(value: string): string {
146
+ if (/[<>{}" ]/.test(value)) {
147
+ throw new Error(`Invalid IRI component: '${value}'`);
148
+ }
141
149
  return `<${value}>`;
142
150
  }
143
151
 
@@ -297,23 +305,9 @@ export function buildSPARQLQuery(
297
305
  ?_reifier <ad4m://ontology/timestamp> ?timestamp .
298
306
  ${filterClause}
299
307
  }
300
- ${buildSPARQLOrderLimitOffset(metadata, query)}
301
308
  `.trim();
302
309
  }
303
310
 
304
- /**
305
- * Build ORDER BY / LIMIT / OFFSET clauses for the SPARQL query.
306
- *
307
- * NOTE: The outer SELECT returns multiple rows per instance (one per link),
308
- * so LIMIT/OFFSET at the outer level would cut off links mid-instance.
309
- * This function is kept for backward compatibility and always returns "".
310
- * SPARQL-level pagination is handled via a subquery in buildSPARQLQuery
311
- * using buildPaginationSubquery().
312
- */
313
- export function buildSPARQLOrderLimitOffset(_metadata: ModelMetadata, query: Query): string {
314
- return "";
315
- }
316
-
317
311
  /**
318
312
  * Build an inner subquery that selects DISTINCT ?source URIs with
319
313
  * ORDER BY, LIMIT, and OFFSET applied at the instance level.
@@ -369,7 +363,7 @@ export function buildPaginationSubquery(
369
363
  { SELECT DISTINCT ?source${tsSelect} WHERE {${innerJoin}${orderJoinPatterns.join('')}${tsPattern}
370
364
  FILTER(isIRI(?source))
371
365
  ${innerFilter}
372
- } GROUP BY ?source ${orderByClause} ${limitClause} ${offsetClause} }\n`;
366
+ } ${orderByClause} ${limitClause} ${offsetClause} }\n`;
373
367
  }
374
368
 
375
369
  /**
@@ -270,11 +270,18 @@ describe("generateSHACL() relation getter population", () => {
270
270
  it("should use explicit getter when provided (ignoring auto-generation)", () => {
271
271
  const { shape } = (ParentWithRelations as any).generateSHACL();
272
272
 
273
- // Getter-only relations have no predicate and are excluded from SHACL shapes
273
+ // Getter-only relations have no `through` predicate but must still
274
+ // appear in the SHACL shape so the executor can find the getter; the
275
+ // writer synthesises a deterministic IRI for `sh:path`.
274
276
  const customProp = shape.properties.find(
275
277
  (p: SHACLPropertyShape) => p.name === "customItems"
276
278
  );
277
- expect(customProp).toBeUndefined();
279
+ expect(customProp).toBeDefined();
280
+ expect(customProp!.getter).toBe(
281
+ "SELECT ?target WHERE { ?target <test://custom> ?source . }"
282
+ );
283
+ expect(customProp!.path).toBeDefined();
284
+ expect(customProp!.path).toContain("ad4m://getter/");
278
285
  });
279
286
 
280
287
  it("should survive full round-trip: generateSHACL → toLinks → fromLinks", () => {
@@ -299,11 +306,15 @@ describe("generateSHACL() relation getter population", () => {
299
306
  expect(flaggedProp!.conformanceConditions).toBeDefined();
300
307
  expect(flaggedProp!.conformanceConditions!.length).toBeGreaterThan(0);
301
308
 
302
- // The custom getter-only relation should NOT be in the SHACL shape
309
+ // Getter-only relations now round-trip too — the synthesised path
310
+ // lets the SHACL graph carry the entry through links/fromLinks.
303
311
  const customProp = reconstructed.properties.find(
304
312
  (p: SHACLPropertyShape) => p.name === "customItems"
305
313
  );
306
- expect(customProp).toBeUndefined();
314
+ expect(customProp).toBeDefined();
315
+ expect(customProp!.getter).toBe(
316
+ "SELECT ?target WHERE { ?target <test://custom> ?source . }"
317
+ );
307
318
  });
308
319
  });
309
320
 
@@ -574,7 +585,13 @@ describe("where clause validation", () => {
574
585
  });
575
586
 
576
587
  describe("where clause compilation", () => {
577
- it("should compile where clause to SPARQL getter", () => {
588
+ // Under the source-of-truth refactor the SHACL writer no longer inlines
589
+ // `where` conditions into the relation's SPARQL getter. Instead it emits
590
+ // `ad4m://whereFilter` + `ad4m://wherePredicates` triples that the
591
+ // Rust executor evaluates as a post-getter pass at query time. These
592
+ // tests assert that contract on the writer side.
593
+
594
+ it("should emit whereFilter and wherePredicates on the relation shape", () => {
578
595
  @Model({ name: "WhereTarget" })
579
596
  class WhereTarget extends Ad4mModel {
580
597
  @Property({ through: "test://status", required: true })
@@ -595,13 +612,11 @@ describe("where clause compilation", () => {
595
612
  (p: SHACLPropertyShape) => p.name === "items"
596
613
  );
597
614
  expect(itemsProp).toBeDefined();
598
- expect(itemsProp!.getter).toBeDefined();
599
- expect(itemsProp!.getter).toContain("test://has_item");
600
- expect(itemsProp!.getter).toContain("test://status");
601
- expect(itemsProp!.getter).toContain("active");
615
+ expect(itemsProp!.whereFilter).toEqual({ status: "active" });
616
+ expect(itemsProp!.wherePredicates).toEqual({ status: "test://status" });
602
617
  });
603
618
 
604
- it("should use where clause instead of auto-derived conformance when both target and where are set", () => {
619
+ it("should set whereFilter alongside an auto-derived conformance getter when target is provided", () => {
605
620
  @Model({ name: "WhereOverrideParent" })
606
621
  class WhereOverrideParent extends Ad4mModel {
607
622
  @HasMany(() => FlaggedTarget, {
@@ -616,16 +631,15 @@ describe("where clause compilation", () => {
616
631
  (p: SHACLPropertyShape) => p.name === "flaggedItems"
617
632
  );
618
633
  expect(prop).toBeDefined();
634
+ // whereFilter / wherePredicates carry the post-getter filter; type
635
+ // filtering stays on the auto-derived conformance getter.
636
+ expect(prop!.whereFilter).toEqual({ name: "specific" });
637
+ expect(prop!.wherePredicates).toEqual({ name: "test://name" });
619
638
  expect(prop!.getter).toBeDefined();
620
- // Should contain the where condition (name = specific)
621
- expect(prop!.getter).toContain("test://name");
622
- expect(prop!.getter).toContain("specific");
623
- // Should NOT contain the auto-derived flag condition
624
- // (where overrides auto-conformance)
625
- expect(prop!.getter).not.toContain("test://flagged_type");
639
+ expect(prop!.getter).toContain("test://flagged_type");
626
640
  });
627
641
 
628
- it("should compile where clause with not operator", () => {
642
+ it("should emit whereFilter with a not operator unchanged", () => {
629
643
  @Model({ name: "WhereNotTarget" })
630
644
  class WhereNotTarget extends Ad4mModel {
631
645
  @Property({ through: "test://status" })
@@ -646,13 +660,11 @@ describe("where clause compilation", () => {
646
660
  (p: SHACLPropertyShape) => p.name === "items"
647
661
  );
648
662
  expect(prop).toBeDefined();
649
- expect(prop!.getter).toBeDefined();
650
- // Should contain a negation condition
651
- expect(prop!.getter).toContain("test://status");
652
- expect(prop!.getter).toContain("archived");
663
+ expect(prop!.whereFilter).toEqual({ status: { not: "archived" } });
664
+ expect(prop!.wherePredicates).toEqual({ status: "test://status" });
653
665
  });
654
666
 
655
- it("should compile where clause with array values (IN)", () => {
667
+ it("should emit whereFilter with array (IN) values unchanged", () => {
656
668
  @Model({ name: "WhereArrayTarget" })
657
669
  class WhereArrayTarget extends Ad4mModel {
658
670
  @Property({ through: "test://category" })
@@ -673,13 +685,11 @@ describe("where clause compilation", () => {
673
685
  (p: SHACLPropertyShape) => p.name === "items"
674
686
  );
675
687
  expect(prop).toBeDefined();
676
- expect(prop!.getter).toBeDefined();
677
- expect(prop!.getter).toContain("test://category");
678
- expect(prop!.getter).toContain("food");
679
- expect(prop!.getter).toContain("drink");
688
+ expect(prop!.whereFilter).toEqual({ category: ["food", "drink"] });
689
+ expect(prop!.wherePredicates).toEqual({ category: "test://category" });
680
690
  });
681
691
 
682
- it("should compile where clause without target using raw predicate URIs", () => {
692
+ it("should emit whereFilter without wherePredicates when target metadata is absent", () => {
683
693
  @Model({ name: "WhereNoTargetParent" })
684
694
  class WhereNoTargetParent extends Ad4mModel {
685
695
  @HasMany({
@@ -694,12 +704,13 @@ describe("where clause compilation", () => {
694
704
  (p: SHACLPropertyShape) => p.name === "items"
695
705
  );
696
706
  expect(prop).toBeDefined();
697
- expect(prop!.getter).toBeDefined();
698
- expect(prop!.getter).toContain("test://status");
699
- expect(prop!.getter).toContain("active");
707
+ expect(prop!.whereFilter).toEqual({ "test://status": "active" });
708
+ // Without target metadata the writer cannot resolve property→predicate;
709
+ // the executor falls back to interpreting keys as raw IRIs.
710
+ expect(prop!.wherePredicates).toBeUndefined();
700
711
  });
701
712
 
702
- it("should set both where-compiled getter and sh:class when target is present", () => {
713
+ it("should set both whereFilter and sh:class when target is present", () => {
703
714
  @Model({ name: "WherePlusClassParent" })
704
715
  class WherePlusClassParent extends Ad4mModel {
705
716
  @HasMany(() => FlaggedTarget, {
@@ -714,15 +725,12 @@ describe("where clause compilation", () => {
714
725
  (p: SHACLPropertyShape) => p.name === "flaggedItems"
715
726
  );
716
727
  expect(prop).toBeDefined();
717
- // where-compiled getter
718
- expect(prop!.getter).toBeDefined();
719
- expect(prop!.getter).toContain("specific");
720
- // sh:class still set (target is present)
728
+ expect(prop!.whereFilter).toEqual({ name: "specific" });
721
729
  expect(prop!.class).toBeDefined();
722
730
  expect(prop!.class).toContain("FlaggedTarget");
723
731
  });
724
732
 
725
- it("should round-trip where-compiled getter through toLinks/fromLinks", () => {
733
+ it("should round-trip whereFilter and wherePredicates through toLinks/fromLinks", () => {
726
734
  @Model({ name: "WhereRoundTripTarget" })
727
735
  class WhereRoundTripTarget extends Ad4mModel {
728
736
  @Property({ through: "test://status", required: true })
@@ -749,9 +757,8 @@ describe("where clause compilation", () => {
749
757
  (p: SHACLPropertyShape) => p.name === "items"
750
758
  );
751
759
  expect(prop).toBeDefined();
752
- expect(prop!.getter).toBeDefined();
753
- expect(prop!.getter).toContain("test://status");
754
- expect(prop!.getter).toContain("active");
760
+ expect(prop!.whereFilter).toEqual({ status: "active" });
761
+ expect(prop!.wherePredicates).toEqual({ status: "test://status" });
755
762
  });
756
763
  });
757
764