@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
@@ -6,7 +6,7 @@
6
6
  */
7
7
  import type { Ad4mModel } from "./Ad4mModel";
8
8
  import type { PerspectiveProxy } from "../perspectives/PerspectiveProxy";
9
- import type { Where, Order, IncludeMap, Query, PaginationResult } from "./types";
9
+ import type { Query, PaginationResult, TypedWhere, TypedOrder, TypedIncludeMap, PropertyKeysOf } from "./types";
10
10
  /** Query builder for Ad4mModel queries.
11
11
  * Allows building queries with a fluent interface and either running them once
12
12
  * or subscribing to updates.
@@ -63,7 +63,7 @@ export declare class ModelQueryBuilder<T extends Ad4mModel> {
63
63
  * })
64
64
  * ```
65
65
  */
66
- where(conditions: Where): ModelQueryBuilder<T>;
66
+ where(conditions: TypedWhere<T>): ModelQueryBuilder<T>;
67
67
  /**
68
68
  * Sets the order for the query results.
69
69
  *
@@ -75,7 +75,7 @@ export declare class ModelQueryBuilder<T extends Ad4mModel> {
75
75
  * .order({ createdAt: "DESC" })
76
76
  * ```
77
77
  */
78
- order(orderBy: Order): ModelQueryBuilder<T>;
78
+ order(orderBy: TypedOrder<T>): ModelQueryBuilder<T>;
79
79
  /**
80
80
  * Sets the maximum number of results to return.
81
81
  *
@@ -156,7 +156,7 @@ export declare class ModelQueryBuilder<T extends Ad4mModel> {
156
156
  * .properties(["name", "description", "rating"])
157
157
  * ```
158
158
  */
159
- properties(properties: string[]): ModelQueryBuilder<T>;
159
+ properties(properties: PropertyKeysOf<T>[] | string[]): ModelQueryBuilder<T>;
160
160
  /**
161
161
  * Controls whether SPARQL property getters are evaluated during hydration.
162
162
  *
@@ -202,13 +202,8 @@ export declare class ModelQueryBuilder<T extends Ad4mModel> {
202
202
  * .run();
203
203
  * ```
204
204
  */
205
- include(map: IncludeMap): ModelQueryBuilder<T>;
205
+ include(map: TypedIncludeMap<T>): ModelQueryBuilder<T>;
206
206
  overrideModelClassName(className: string): ModelQueryBuilder<T>;
207
- /**
208
- * Sets the query engine to use.
209
- * @deprecated Prolog engine has been removed. All queries use SPARQL/Rust.
210
- */
211
- engine(_eng: 'sparql' | 'prolog'): ModelQueryBuilder<T>;
212
207
  /**
213
208
  * Executes the query once and returns the results.
214
209
  *
@@ -256,13 +256,6 @@ export class ModelQueryBuilder {
256
256
  this.modelClassName = className;
257
257
  return this;
258
258
  }
259
- /**
260
- * Sets the query engine to use.
261
- * @deprecated Prolog engine has been removed. All queries use SPARQL/Rust.
262
- */
263
- engine(_eng) {
264
- return this;
265
- }
266
259
  /**
267
260
  * Executes the query once and returns the results.
268
261
  *
@@ -306,8 +299,10 @@ export class ModelQueryBuilder {
306
299
  * ```
307
300
  */
308
301
  async first() {
302
+ const savedLimit = this.queryParams.limit;
309
303
  this.queryParams.limit = 1;
310
304
  const results = await this.get();
305
+ this.queryParams.limit = savedLimit;
311
306
  return results[0] ?? null;
312
307
  }
313
308
  /**
@@ -342,16 +337,17 @@ export class ModelQueryBuilder {
342
337
  // Clean up any existing subscription
343
338
  this.dispose();
344
339
  const ctor = this.ctor;
345
- // Build the model query params (className, queryJson, shapeJson)
346
- const { className, queryJson, shapeJson } = ctor.prepareModelQueryParams(this.queryParams, this.modelClassName);
340
+ // Build the model query params (className, queryJson). The executor
341
+ // resolves the shape from the perspective's SHACL triples.
342
+ const { className, queryJson } = ctor.prepareModelQueryParams(this.queryParams, this.modelClassName);
347
343
  // Register model subscription via Rust — this builds trigger SPARQL internally,
348
344
  // registers the subscription, and runs the initial query in one call.
349
- const { subscriptionId, result: initialModelResult } = await this.perspective.modelSubscribe(className, queryJson, shapeJson);
345
+ const { subscriptionId, result: initialModelResult } = await this.perspective.modelSubscribe(className, queryJson);
350
346
  // Convert JSON instances to model class instances
351
347
  const parseResults = (raw) => {
352
348
  return ctor.parseModelResult(this.perspective, raw, this.queryParams.include, this.queryParams.properties);
353
349
  };
354
- // Parse initial results
350
+ // Transforms are now applied by the Rust executor during hydration
355
351
  const initialResults = parseResults(initialModelResult);
356
352
  // Track last emitted result fingerprint to suppress duplicate callbacks
357
353
  let lastResultFingerprint = null;
@@ -366,9 +362,13 @@ export class ModelQueryBuilder {
366
362
  const unsubscribe = this.perspective.client.subscribeToQueryUpdates(subscriptionId, (rawResult) => {
367
363
  try {
368
364
  const results = parseResults(rawResult);
365
+ console.debug(`[ModelQueryBuilder.subscribe] Update received for ${subscriptionId}: ${results.length} instances`);
369
366
  const fp = buildFingerprint(results);
370
- if (fp === lastResultFingerprint)
367
+ if (fp === lastResultFingerprint) {
368
+ console.debug(`[ModelQueryBuilder.subscribe] Fingerprint unchanged, skipping callback`);
371
369
  return;
370
+ }
371
+ console.debug(`[ModelQueryBuilder.subscribe] Fingerprint changed, calling callback with ${results.length} results`);
372
372
  lastResultFingerprint = fp;
373
373
  callback(results);
374
374
  }
@@ -376,20 +376,50 @@ export class ModelQueryBuilder {
376
376
  console.error('Model subscription update parse error:', e);
377
377
  }
378
378
  });
379
- // Set up keepalive with failure tracking
380
- let keepaliveFailures = 0;
381
- const keepaliveTimer = setInterval(() => {
382
- this.perspective.client.keepAliveQuery(this.perspective.uuid, subscriptionId).then(() => {
383
- keepaliveFailures = 0;
384
- }).catch((e) => {
385
- keepaliveFailures++;
386
- console.warn(`Model subscription keepalive failed (attempt ${keepaliveFailures}) for ${subscriptionId}:`, e);
387
- });
388
- }, 30000);
379
+ // Set up keepalive with recovery — uses setTimeout loop so we can
380
+ // break out and resubscribe when the server evicts the subscription.
381
+ let disposed = false;
382
+ let keepaliveTimer;
383
+ let resubscribeAttempts = 0;
384
+ const MAX_RESUBSCRIBE_ATTEMPTS = 5;
385
+ const keepaliveLoop = async () => {
386
+ if (disposed)
387
+ return;
388
+ try {
389
+ await this.perspective.client.keepAliveQuery(this.perspective.uuid, subscriptionId);
390
+ resubscribeAttempts = 0; // Reset on success
391
+ }
392
+ catch (e) {
393
+ console.warn(`Model subscription keepalive failed for ${subscriptionId}:`, e);
394
+ if (!disposed && resubscribeAttempts < MAX_RESUBSCRIBE_ATTEMPTS) {
395
+ resubscribeAttempts++;
396
+ const backoffMs = Math.min(1000 * Math.pow(2, resubscribeAttempts), 60000);
397
+ console.warn(`Resubscribing (attempt ${resubscribeAttempts}/${MAX_RESUBSCRIBE_ATTEMPTS}, backoff ${backoffMs}ms)...`);
398
+ await new Promise(r => setTimeout(r, backoffMs));
399
+ try {
400
+ unsubscribe();
401
+ await this.subscribe(callback);
402
+ }
403
+ catch (resubErr) {
404
+ console.error('Model subscription resubscribe failed:', resubErr);
405
+ }
406
+ }
407
+ else if (resubscribeAttempts >= MAX_RESUBSCRIBE_ATTEMPTS) {
408
+ console.error(`Model subscription ${subscriptionId}: max resubscribe attempts reached, giving up.`);
409
+ }
410
+ return; // new subscription owns its own keepalive loop
411
+ }
412
+ if (!disposed) {
413
+ keepaliveTimer = setTimeout(keepaliveLoop, 30000);
414
+ }
415
+ };
416
+ keepaliveTimer = setTimeout(keepaliveLoop, 30000);
389
417
  // Store dispose function
390
418
  this.currentSubscription = {
391
419
  dispose: () => {
392
- clearInterval(keepaliveTimer);
420
+ disposed = true;
421
+ if (keepaliveTimer)
422
+ clearTimeout(keepaliveTimer);
393
423
  unsubscribe();
394
424
  this.perspective.client.disposeQuerySubscription(this.perspective.uuid, subscriptionId).catch(() => { });
395
425
  },
@@ -462,8 +492,8 @@ export class ModelQueryBuilder {
462
492
  // Clean up any existing subscription
463
493
  this.dispose();
464
494
  const countParams = { ...this.queryParams, limit: 0 };
465
- const { className, queryJson, shapeJson } = this.ctor.prepareModelQueryParams(countParams, this.modelClassName);
466
- const { subscriptionId, result: initialModelResult } = await this.perspective.modelSubscribe(className, queryJson, shapeJson);
495
+ const { className, queryJson } = this.ctor.prepareModelQueryParams(countParams, this.modelClassName);
496
+ const { subscriptionId, result: initialModelResult } = await this.perspective.modelSubscribe(className, queryJson);
467
497
  const parseCount = (raw) => {
468
498
  const data = typeof raw === 'string' ? JSON.parse(raw) : raw;
469
499
  return data.totalCount ?? 0;
@@ -477,18 +507,47 @@ export class ModelQueryBuilder {
477
507
  console.error('Count subscription update parse error:', e);
478
508
  }
479
509
  });
480
- let keepaliveFailures = 0;
481
- const keepaliveTimer = setInterval(() => {
482
- this.perspective.client.keepAliveQuery(this.perspective.uuid, subscriptionId).then(() => {
483
- keepaliveFailures = 0;
484
- }).catch((e) => {
485
- keepaliveFailures++;
486
- console.warn(`Count subscription keepalive failed (attempt ${keepaliveFailures}) for ${subscriptionId}:`, e);
487
- });
488
- }, 30000);
510
+ let disposed = false;
511
+ let keepaliveTimer;
512
+ let resubscribeAttempts = 0;
513
+ const MAX_RESUBSCRIBE_ATTEMPTS = 5;
514
+ const keepaliveLoop = async () => {
515
+ if (disposed)
516
+ return;
517
+ try {
518
+ await this.perspective.client.keepAliveQuery(this.perspective.uuid, subscriptionId);
519
+ resubscribeAttempts = 0;
520
+ }
521
+ catch (e) {
522
+ console.warn(`Count subscription keepalive failed for ${subscriptionId}:`, e);
523
+ if (!disposed && resubscribeAttempts < MAX_RESUBSCRIBE_ATTEMPTS) {
524
+ resubscribeAttempts++;
525
+ const backoffMs = Math.min(1000 * Math.pow(2, resubscribeAttempts), 60000);
526
+ console.warn(`Count resubscribing (attempt ${resubscribeAttempts}/${MAX_RESUBSCRIBE_ATTEMPTS}, backoff ${backoffMs}ms)...`);
527
+ await new Promise(r => setTimeout(r, backoffMs));
528
+ try {
529
+ unsubscribe();
530
+ await this.countSubscribe(callback);
531
+ }
532
+ catch (resubErr) {
533
+ console.error('Count subscription resubscribe failed:', resubErr);
534
+ }
535
+ }
536
+ else if (resubscribeAttempts >= MAX_RESUBSCRIBE_ATTEMPTS) {
537
+ console.error(`Count subscription ${subscriptionId}: max resubscribe attempts reached, giving up.`);
538
+ }
539
+ return;
540
+ }
541
+ if (!disposed) {
542
+ keepaliveTimer = setTimeout(keepaliveLoop, 30000);
543
+ }
544
+ };
545
+ keepaliveTimer = setTimeout(keepaliveLoop, 30000);
489
546
  this.currentSubscription = {
490
547
  dispose: () => {
491
- clearInterval(keepaliveTimer);
548
+ disposed = true;
549
+ if (keepaliveTimer)
550
+ clearTimeout(keepaliveTimer);
492
551
  unsubscribe();
493
552
  this.perspective.client.disposeQuerySubscription(this.perspective.uuid, subscriptionId).catch(() => { });
494
553
  },
@@ -569,8 +628,8 @@ export class ModelQueryBuilder {
569
628
  const subscriptionParams = { ...(this.queryParams || {}) };
570
629
  delete subscriptionParams.limit;
571
630
  delete subscriptionParams.offset;
572
- const { className, queryJson, shapeJson } = ctor.prepareModelQueryParams(subscriptionParams, this.modelClassName);
573
- const { subscriptionId } = await this.perspective.modelSubscribe(className, queryJson, shapeJson);
631
+ const { className, queryJson } = ctor.prepareModelQueryParams(subscriptionParams, this.modelClassName);
632
+ const { subscriptionId } = await this.perspective.modelSubscribe(className, queryJson);
574
633
  // Build the paginated query for Rust endpoint (count: true fetches both results and totalCount in one call)
575
634
  const paginatedQuery = {
576
635
  ...(this.queryParams || {}),
@@ -583,20 +642,50 @@ export class ModelQueryBuilder {
583
642
  callback({ results, totalCount, pageSize, pageNumber });
584
643
  };
585
644
  const unsubscribe = this.perspective.client.subscribeToQueryUpdates(subscriptionId, (rawResult) => {
645
+ console.debug(`[ModelQueryBuilder.paginateSubscribe] Update received for ${subscriptionId}, re-fetching paginated data...`);
586
646
  processResults().catch(e => console.error('Paginate subscription error:', e));
587
647
  });
588
- let keepaliveFailures = 0;
589
- const keepaliveTimer = setInterval(() => {
590
- this.perspective.client.keepAliveQuery(this.perspective.uuid, subscriptionId).then(() => {
591
- keepaliveFailures = 0;
592
- }).catch((e) => {
593
- keepaliveFailures++;
594
- console.warn(`Paginate subscription keepalive failed (attempt ${keepaliveFailures}) for ${subscriptionId}:`, e);
595
- });
596
- }, 30000);
648
+ let disposed = false;
649
+ let keepaliveTimer;
650
+ let resubscribeAttempts = 0;
651
+ const MAX_RESUBSCRIBE_ATTEMPTS = 5;
652
+ const keepaliveLoop = async () => {
653
+ if (disposed)
654
+ return;
655
+ try {
656
+ await this.perspective.client.keepAliveQuery(this.perspective.uuid, subscriptionId);
657
+ resubscribeAttempts = 0;
658
+ }
659
+ catch (e) {
660
+ console.warn(`Paginate subscription keepalive failed for ${subscriptionId}:`, e);
661
+ if (!disposed && resubscribeAttempts < MAX_RESUBSCRIBE_ATTEMPTS) {
662
+ resubscribeAttempts++;
663
+ const backoffMs = Math.min(1000 * Math.pow(2, resubscribeAttempts), 60000);
664
+ console.warn(`Paginate resubscribing (attempt ${resubscribeAttempts}/${MAX_RESUBSCRIBE_ATTEMPTS}, backoff ${backoffMs}ms)...`);
665
+ await new Promise(r => setTimeout(r, backoffMs));
666
+ try {
667
+ unsubscribe();
668
+ await this.paginateSubscribe(pageSize, pageNumber, callback);
669
+ }
670
+ catch (resubErr) {
671
+ console.error('Paginate subscription resubscribe failed:', resubErr);
672
+ }
673
+ }
674
+ else if (resubscribeAttempts >= MAX_RESUBSCRIBE_ATTEMPTS) {
675
+ console.error(`Paginate subscription ${subscriptionId}: max resubscribe attempts reached, giving up.`);
676
+ }
677
+ return;
678
+ }
679
+ if (!disposed) {
680
+ keepaliveTimer = setTimeout(keepaliveLoop, 30000);
681
+ }
682
+ };
683
+ keepaliveTimer = setTimeout(keepaliveLoop, 30000);
597
684
  this.currentSubscription = {
598
685
  dispose: () => {
599
- clearInterval(keepaliveTimer);
686
+ disposed = true;
687
+ if (keepaliveTimer)
688
+ clearTimeout(keepaliveTimer);
600
689
  unsubscribe();
601
690
  this.perspective.client.disposeQuerySubscription(this.perspective.uuid, subscriptionId).catch(() => { });
602
691
  },
@@ -55,12 +55,12 @@ export class Subject {
55
55
  Object.defineProperty(this, p, {
56
56
  configurable: true,
57
57
  get: async () => {
58
- // Use SurrealDB for data queries
58
+ // Use SPARQL for data queries
59
59
  try {
60
- return await __classPrivateFieldGet(this, _Subject_perspective, "f").getPropertyValueViaSurreal(__classPrivateFieldGet(this, _Subject_baseExpression, "f"), __classPrivateFieldGet(this, _Subject_subjectClassName, "f"), p);
60
+ return await __classPrivateFieldGet(this, _Subject_perspective, "f").getPropertyValueViaSparql(__classPrivateFieldGet(this, _Subject_baseExpression, "f"), __classPrivateFieldGet(this, _Subject_subjectClassName, "f"), p);
61
61
  }
62
62
  catch (err) {
63
- console.warn(`Failed to get property ${p} via SurrealDB:`, err);
63
+ console.warn(`Failed to get property ${p} via SPARQL:`, err);
64
64
  return undefined;
65
65
  }
66
66
  }
@@ -94,12 +94,12 @@ export class Subject {
94
94
  Object.defineProperty(this, c, {
95
95
  configurable: true,
96
96
  get: async () => {
97
- // Use SurrealDB for data queries
97
+ // Use SPARQL for data queries
98
98
  try {
99
- return await __classPrivateFieldGet(this, _Subject_perspective, "f").getRelationValuesViaSurreal(__classPrivateFieldGet(this, _Subject_baseExpression, "f"), __classPrivateFieldGet(this, _Subject_subjectClassName, "f"), c);
99
+ return await __classPrivateFieldGet(this, _Subject_perspective, "f").getRelationValuesViaSparql(__classPrivateFieldGet(this, _Subject_baseExpression, "f"), __classPrivateFieldGet(this, _Subject_subjectClassName, "f"), c);
100
100
  }
101
101
  catch (err) {
102
- console.warn(`Failed to get relation ${c} via SurrealDB:`, err);
102
+ console.warn(`Failed to get relation ${c} via SPARQL:`, err);
103
103
  return [];
104
104
  }
105
105
  }
@@ -130,11 +130,14 @@ export interface PropertyOptions {
130
130
  */
131
131
  local?: boolean;
132
132
  /**
133
- * Optional transform function to modify the property value after it is retrieved.
134
- * This is useful for transforming raw data into a more usable format.
135
- * The function takes the raw value as input and returns the transformed value.
133
+ * Optional transform expression to modify the property value.
134
+ * This is a SHACL-AF Node Expression that runs in the Rust model query engine.
135
+ * Examples: `fileToDataUri`, `concat(literal('prefix_'), focus())`, etc.
136
+ * Builders (`focus`, `literal`, `path`, `exists`, `ifExpr`, `concat`,
137
+ * `coalesce`, `fn`) and the `fileToDataUri` built-in are exported from
138
+ * the package root: `import { concat, literal, focus } from '@coasys/ad4m'`.
136
139
  */
137
- transform?: (value: any) => any;
140
+ transform?: import('../shacl/NodeExpression').NodeExpression;
138
141
  /**
139
142
  * Allowed values for this property (enum constraint).
140
143
  * Maps to SHACL `sh:in`. Each entry has a `value` (the stored RDF term)
@@ -521,15 +521,8 @@ function resolveRelationArgs(first, second) {
521
521
  return opts;
522
522
  }
523
523
  export function HasMany(first, second) {
524
- const explicitThrough = typeof first === 'function' ? second?.through : first.through;
525
524
  const opts = resolveRelationArgs(first, second);
526
525
  return function (target, key) {
527
- if (!explicitThrough && !opts.getter) {
528
- const className = (target.constructor?.name) ?? 'unknown';
529
- console.warn(`@HasMany on ${className}.${String(key)} has no 'through' predicate — defaulting to 'ad4m://has_child'. ` +
530
- `Add { through: 'ad4m://has_child' } to silence this warning, or use a semantic predicate ` +
531
- `like { through: 'myns://has_${String(key)}' } for efficient targeted queries.`);
532
- }
533
526
  // --- relation registry ---
534
527
  const ctor = target.constructor;
535
528
  if (!relationRegistry.has(ctor))
@@ -0,0 +1,34 @@
1
+ /**
2
+ * Batch hydration for SPARQL batch query results.
3
+ *
4
+ * Takes the flat rows returned by `buildBatchSPARQLQuery()` (each tagged
5
+ * with ?depth, ?parentBase, ?relationName) and reconstructs a tree of
6
+ * model instances.
7
+ *
8
+ * @module
9
+ */
10
+ import type { IncludeMap } from "./types";
11
+ /**
12
+ * A row returned by the batch SPARQL query.
13
+ */
14
+ interface BatchRow {
15
+ depth: string;
16
+ parentBase: string;
17
+ relationName: string;
18
+ source: string;
19
+ predicate: string;
20
+ target: string;
21
+ author: string;
22
+ timestamp: string;
23
+ }
24
+ /**
25
+ * Hydrate batch SPARQL results into a tree of model instances.
26
+ *
27
+ * @param rows - Flat rows from the batch SPARQL query
28
+ * @param rootClass - The root model class (extends Ad4mModel)
29
+ * @param includeMap - The include specification from the query
30
+ * @param perspective - The PerspectiveProxy for creating instances
31
+ * @returns Array of hydrated root instances with relations populated
32
+ */
33
+ export declare function hydrateBatchResult<T>(rows: BatchRow[], rootClass: any, includeMap: IncludeMap, perspective: any): Promise<T[]>;
34
+ export {};
@@ -0,0 +1,147 @@
1
+ /**
2
+ * Batch hydration for SPARQL batch query results.
3
+ *
4
+ * Takes the flat rows returned by `buildBatchSPARQLQuery()` (each tagged
5
+ * with ?depth, ?parentBase, ?relationName) and reconstructs a tree of
6
+ * model instances.
7
+ *
8
+ * @module
9
+ */
10
+ import { hydrateFromLinks, evaluateCustomGettersForInstance } from "./hydration";
11
+ import { getRelationsMetadata } from "./decorators";
12
+ /**
13
+ * Group batch rows by (depth, source) → array of links, preserving parentBase/relationName.
14
+ */
15
+ function groupBatchRows(rows) {
16
+ const byDepth = new Map();
17
+ for (const row of rows) {
18
+ const depth = parseInt(row.depth, 10);
19
+ if (!byDepth.has(depth))
20
+ byDepth.set(depth, new Map());
21
+ const depthMap = byDepth.get(depth);
22
+ const key = row.source;
23
+ if (!depthMap.has(key)) {
24
+ depthMap.set(key, {
25
+ source_uri: key,
26
+ parentBase: row.parentBase,
27
+ relationName: row.relationName,
28
+ links: [],
29
+ });
30
+ }
31
+ depthMap.get(key).links.push({
32
+ predicate: row.predicate,
33
+ target: row.target,
34
+ author: row.author,
35
+ timestamp: row.timestamp,
36
+ });
37
+ }
38
+ const result = new Map();
39
+ for (const [depth, map] of byDepth) {
40
+ result.set(depth, Array.from(map.values()));
41
+ }
42
+ return result;
43
+ }
44
+ /**
45
+ * Hydrate batch SPARQL results into a tree of model instances.
46
+ *
47
+ * @param rows - Flat rows from the batch SPARQL query
48
+ * @param rootClass - The root model class (extends Ad4mModel)
49
+ * @param includeMap - The include specification from the query
50
+ * @param perspective - The PerspectiveProxy for creating instances
51
+ * @returns Array of hydrated root instances with relations populated
52
+ */
53
+ export async function hydrateBatchResult(rows, rootClass, includeMap, perspective) {
54
+ if (!rows || rows.length === 0)
55
+ return [];
56
+ const grouped = groupBatchRows(rows);
57
+ // Hydrate root instances (depth 0)
58
+ const rootInstances = grouped.get(0) || [];
59
+ const metadata = rootClass.getModelMetadata();
60
+ const instances = [];
61
+ const instanceMap = new Map();
62
+ for (const group of rootInstances) {
63
+ const instance = new rootClass(perspective, group.source_uri);
64
+ await hydrateFromLinks(instance, group.links, metadata, perspective);
65
+ await evaluateCustomGettersForInstance(instance, perspective, metadata);
66
+ instances.push(instance);
67
+ instanceMap.set(group.source_uri, instance);
68
+ }
69
+ // Hydrate each depth level and wire to parents
70
+ const relMeta = getRelationsMetadata(rootClass);
71
+ const maxDepth = Math.max(...Array.from(grouped.keys()), 0);
72
+ // Build a map of depth → (class, relMetadata, parentInstanceMap)
73
+ // For depth 1, parents are root instances; for deeper depths, we need
74
+ // the instances from the previous level.
75
+ const depthInstanceMaps = new Map();
76
+ depthInstanceMaps.set(0, instanceMap);
77
+ // Build depth→class mapping from include tree
78
+ const depthClassMap = new Map();
79
+ buildDepthClassMap(rootClass, includeMap, 0, { value: 1 }, depthClassMap);
80
+ for (let depth = 1; depth <= maxDepth; depth++) {
81
+ const depthGroups = grouped.get(depth) || [];
82
+ if (depthGroups.length === 0)
83
+ continue;
84
+ const depthInfo = depthClassMap.get(depth);
85
+ if (!depthInfo)
86
+ continue;
87
+ const TargetClass = depthInfo.targetClass;
88
+ const targetMetadata = TargetClass.getModelMetadata
89
+ ? TargetClass.getModelMetadata()
90
+ : { className: "Unknown", properties: {}, relations: {} };
91
+ const currentDepthInstances = new Map();
92
+ // Group by parentBase to wire children to parents
93
+ for (const group of depthGroups) {
94
+ const instance = new TargetClass(perspective, group.source_uri);
95
+ await hydrateFromLinks(instance, group.links, targetMetadata, perspective);
96
+ await evaluateCustomGettersForInstance(instance, perspective, targetMetadata);
97
+ currentDepthInstances.set(group.source_uri, instance);
98
+ // Wire to parent
99
+ // Find the parent depth's instance map
100
+ // The parentBase should exist in one of the prior depth maps
101
+ for (let pd = depth - 1; pd >= 0; pd--) {
102
+ const parentMap = depthInstanceMaps.get(pd);
103
+ if (parentMap && parentMap.has(group.parentBase)) {
104
+ const parent = parentMap.get(group.parentBase);
105
+ const relName = group.relationName;
106
+ // Determine relation metadata to know if it's an array or single
107
+ const parentRelMeta = getRelationsMetadata(pd === 0 ? rootClass : (depthClassMap.get(pd)?.targetClass || rootClass));
108
+ const rel = parentRelMeta[relName];
109
+ if (rel) {
110
+ if (rel.kind === 'hasMany' || rel.kind === 'belongsToMany') {
111
+ if (!Array.isArray(parent[relName])) {
112
+ parent[relName] = [];
113
+ }
114
+ parent[relName].push(instance);
115
+ }
116
+ else {
117
+ parent[relName] = instance;
118
+ }
119
+ }
120
+ break;
121
+ }
122
+ }
123
+ }
124
+ depthInstanceMaps.set(depth, currentDepthInstances);
125
+ }
126
+ return instances;
127
+ }
128
+ /**
129
+ * Build a mapping from depth number to target class info.
130
+ */
131
+ function buildDepthClassMap(parentClass, includeMap, _parentDepth, nextDepth, result) {
132
+ const relMeta = getRelationsMetadata(parentClass);
133
+ for (const [relName, includeValue] of Object.entries(includeMap)) {
134
+ const meta = relMeta[relName];
135
+ if (!meta || !meta.target)
136
+ continue;
137
+ const TargetClass = meta.target();
138
+ const depth = nextDepth.value++;
139
+ const nestedInclude = typeof includeValue === 'object' && includeValue !== null
140
+ ? includeValue.include
141
+ : undefined;
142
+ result.set(depth, { targetClass: TargetClass, includeMap: nestedInclude });
143
+ if (nestedInclude) {
144
+ buildDepthClassMap(TargetClass, nestedInclude, depth, nextDepth, result);
145
+ }
146
+ }
147
+ }
@@ -0,0 +1,7 @@
1
+ /**
2
+ * Tests for batched hydrateRelations() — verifies the N+1 → 1 SPARQL optimisation.
3
+ *
4
+ * We mock PerspectiveProxy to count querySparql / get calls and verify
5
+ * that the batched path issues 1 SPARQL query instead of N perspective.get() calls.
6
+ */
7
+ export {};