@coasys/ad4m 0.12.1-dev → 0.13.0-postmessage-ws-proxy.3

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 (393) hide show
  1. package/README.md +2 -25
  2. package/jest-setup.ts +1 -1
  3. package/lib/index.cjs +8677 -15318
  4. package/lib/index.js +14507 -21223
  5. package/lib/src/Ad4mClient.d.ts +9 -3
  6. package/lib/src/Ad4mClient.js +40 -13
  7. package/lib/src/Literal.js +6 -5
  8. package/lib/src/agent/Agent.js +26 -272
  9. package/lib/src/agent/AgentClient.d.ts +33 -21
  10. package/lib/src/agent/AgentClient.js +180 -374
  11. package/lib/src/agent/AgentStatus.js +2 -37
  12. package/lib/src/ai/AIClient.d.ts +12 -4
  13. package/lib/src/ai/AIClient.js +81 -285
  14. package/lib/src/ai/AITypes.d.ts +55 -0
  15. package/lib/src/ai/AITypes.js +18 -0
  16. package/lib/src/ai/Tasks.js +10 -133
  17. package/lib/src/apiClient.d.ts +53 -0
  18. package/lib/src/apiClient.js +234 -0
  19. package/lib/src/cache/PersistentCache.d.ts +40 -0
  20. package/lib/src/cache/PersistentCache.js +139 -0
  21. package/lib/src/expression/Expression.d.ts +1 -1
  22. package/lib/src/expression/Expression.js +13 -122
  23. package/lib/src/expression/ExpressionClient.d.ts +11 -3
  24. package/lib/src/expression/ExpressionClient.js +120 -75
  25. package/lib/src/expression/ExpressionRef.js +4 -27
  26. package/lib/src/generated/api/AIModelLoadingStatus.d.ts +7 -0
  27. package/lib/src/generated/api/AIModelLoadingStatus.js +2 -0
  28. package/lib/src/generated/api/AddLinkExpressionRequest.d.ts +6 -0
  29. package/lib/src/generated/api/AddLinkExpressionRequest.js +1 -0
  30. package/lib/src/generated/api/AddLinkRequest.d.ts +6 -0
  31. package/lib/src/generated/api/AddLinkRequest.js +1 -0
  32. package/lib/src/generated/api/AddLinksBulkRequest.d.ts +6 -0
  33. package/lib/src/generated/api/AddLinksBulkRequest.js +1 -0
  34. package/lib/src/generated/api/AddSdnaRequest.d.ts +6 -0
  35. package/lib/src/generated/api/AddSdnaRequest.js +2 -0
  36. package/lib/src/generated/api/ApplyTemplateRequest.d.ts +4 -0
  37. package/lib/src/generated/api/ApplyTemplateRequest.js +2 -0
  38. package/lib/src/generated/api/AuthInfoInput.d.ts +10 -0
  39. package/lib/src/generated/api/AuthInfoInput.js +1 -0
  40. package/lib/src/generated/api/CapabilityInput.d.ts +5 -0
  41. package/lib/src/generated/api/CapabilityInput.js +1 -0
  42. package/lib/src/generated/api/CommitBatchRequest.d.ts +3 -0
  43. package/lib/src/generated/api/CommitBatchRequest.js +2 -0
  44. package/lib/src/generated/api/ComputeLogEntry.d.ts +9 -0
  45. package/lib/src/generated/api/ComputeLogEntry.js +2 -0
  46. package/lib/src/generated/api/CreateExpressionRequest.d.ts +4 -0
  47. package/lib/src/generated/api/CreateExpressionRequest.js +2 -0
  48. package/lib/src/generated/api/CreatePerspectiveRequest.d.ts +3 -0
  49. package/lib/src/generated/api/CreatePerspectiveRequest.js +2 -0
  50. package/lib/src/generated/api/CreateSubjectRequest.d.ts +6 -0
  51. package/lib/src/generated/api/CreateSubjectRequest.js +2 -0
  52. package/lib/src/generated/api/EmbedRequest.d.ts +4 -0
  53. package/lib/src/generated/api/EmbedRequest.js +2 -0
  54. package/lib/src/generated/api/EntanglementProofInput.d.ts +6 -0
  55. package/lib/src/generated/api/EntanglementProofInput.js +2 -0
  56. package/lib/src/generated/api/ExecuteCommandsRequest.d.ts +4 -0
  57. package/lib/src/generated/api/ExecuteCommandsRequest.js +2 -0
  58. package/lib/src/generated/api/ExportRequest.d.ts +5 -0
  59. package/lib/src/generated/api/ExportRequest.js +2 -0
  60. package/lib/src/generated/api/ExpressionManyRequest.d.ts +3 -0
  61. package/lib/src/generated/api/ExpressionManyRequest.js +2 -0
  62. package/lib/src/generated/api/ExpressionProof.d.ts +4 -0
  63. package/lib/src/generated/api/ExpressionProof.js +2 -0
  64. package/lib/src/generated/api/ExpressionProofInput.d.ts +6 -0
  65. package/lib/src/generated/api/ExpressionProofInput.js +2 -0
  66. package/lib/src/generated/api/FriendSendMessageRequest.d.ts +3 -0
  67. package/lib/src/generated/api/FriendSendMessageRequest.js +2 -0
  68. package/lib/src/generated/api/FriendsListRequest.d.ts +3 -0
  69. package/lib/src/generated/api/FriendsListRequest.js +2 -0
  70. package/lib/src/generated/api/GenerateAgentRequest.d.ts +3 -0
  71. package/lib/src/generated/api/GenerateAgentRequest.js +2 -0
  72. package/lib/src/generated/api/GenerateJwtRequest.d.ts +4 -0
  73. package/lib/src/generated/api/GenerateJwtRequest.js +2 -0
  74. package/lib/src/generated/api/GetSubjectDataRequest.d.ts +4 -0
  75. package/lib/src/generated/api/GetSubjectDataRequest.js +2 -0
  76. package/lib/src/generated/api/ImportAgentRequest.d.ts +6 -0
  77. package/lib/src/generated/api/ImportAgentRequest.js +2 -0
  78. package/lib/src/generated/api/ImportRequest.d.ts +4 -0
  79. package/lib/src/generated/api/ImportRequest.js +2 -0
  80. package/lib/src/generated/api/JoinNeighbourhoodRequest.d.ts +3 -0
  81. package/lib/src/generated/api/JoinNeighbourhoodRequest.js +2 -0
  82. package/lib/src/generated/api/LanguageMetaInput.d.ts +6 -0
  83. package/lib/src/generated/api/LanguageMetaInput.js +2 -0
  84. package/lib/src/generated/api/Link.d.ts +5 -0
  85. package/lib/src/generated/api/Link.js +2 -0
  86. package/lib/src/generated/api/LinkExpression.d.ts +10 -0
  87. package/lib/src/generated/api/LinkExpression.js +1 -0
  88. package/lib/src/generated/api/LinkExpressionInput.d.ts +10 -0
  89. package/lib/src/generated/api/LinkExpressionInput.js +1 -0
  90. package/lib/src/generated/api/LinkInput.d.ts +5 -0
  91. package/lib/src/generated/api/LinkInput.js +2 -0
  92. package/lib/src/generated/api/LinkLanguageTemplatesRequest.d.ts +3 -0
  93. package/lib/src/generated/api/LinkLanguageTemplatesRequest.js +2 -0
  94. package/lib/src/generated/api/LinkMutations.d.ts +6 -0
  95. package/lib/src/generated/api/LinkMutations.js +1 -0
  96. package/lib/src/generated/api/LinkStatus.d.ts +1 -0
  97. package/lib/src/generated/api/LinkStatus.js +2 -0
  98. package/lib/src/generated/api/LockAgentRequest.d.ts +3 -0
  99. package/lib/src/generated/api/LockAgentRequest.js +2 -0
  100. package/lib/src/generated/api/ModelType.d.ts +1 -0
  101. package/lib/src/generated/api/ModelType.js +2 -0
  102. package/lib/src/generated/api/NotificationInput.d.ts +10 -0
  103. package/lib/src/generated/api/NotificationInput.js +2 -0
  104. package/lib/src/generated/api/OpenLinkRequest.d.ts +3 -0
  105. package/lib/src/generated/api/OpenLinkRequest.js +2 -0
  106. package/lib/src/generated/api/PermitCapabilityRequest.d.ts +3 -0
  107. package/lib/src/generated/api/PermitCapabilityRequest.js +2 -0
  108. package/lib/src/generated/api/PerspectiveInput.d.ts +4 -0
  109. package/lib/src/generated/api/PerspectiveInput.js +1 -0
  110. package/lib/src/generated/api/PromptRequest.d.ts +4 -0
  111. package/lib/src/generated/api/PromptRequest.js +2 -0
  112. package/lib/src/generated/api/PublishLanguageRequest.d.ts +5 -0
  113. package/lib/src/generated/api/PublishLanguageRequest.js +1 -0
  114. package/lib/src/generated/api/PublishNeighbourhoodRequest.d.ts +6 -0
  115. package/lib/src/generated/api/PublishNeighbourhoodRequest.js +1 -0
  116. package/lib/src/generated/api/QueryRequest.d.ts +7 -0
  117. package/lib/src/generated/api/QueryRequest.js +2 -0
  118. package/lib/src/generated/api/RemoveLinkRequest.d.ts +5 -0
  119. package/lib/src/generated/api/RemoveLinkRequest.js +1 -0
  120. package/lib/src/generated/api/RemoveLinksBulkRequest.d.ts +5 -0
  121. package/lib/src/generated/api/RemoveLinksBulkRequest.js +1 -0
  122. package/lib/src/generated/api/ResourceInput.d.ts +4 -0
  123. package/lib/src/generated/api/ResourceInput.js +2 -0
  124. package/lib/src/generated/api/SetDefaultModelRequest.d.ts +4 -0
  125. package/lib/src/generated/api/SetDefaultModelRequest.js +1 -0
  126. package/lib/src/generated/api/SetFreeHostingEnabledRequest.d.ts +3 -0
  127. package/lib/src/generated/api/SetFreeHostingEnabledRequest.js +2 -0
  128. package/lib/src/generated/api/SetMultiUserRequest.d.ts +3 -0
  129. package/lib/src/generated/api/SetMultiUserRequest.js +2 -0
  130. package/lib/src/generated/api/SetStatusRequest.d.ts +3 -0
  131. package/lib/src/generated/api/SetStatusRequest.js +2 -0
  132. package/lib/src/generated/api/SignMessageRequest.d.ts +3 -0
  133. package/lib/src/generated/api/SignMessageRequest.js +2 -0
  134. package/lib/src/generated/api/TrustedAgentsRequest.d.ts +3 -0
  135. package/lib/src/generated/api/TrustedAgentsRequest.js +2 -0
  136. package/lib/src/generated/api/UnlockAgentRequest.d.ts +4 -0
  137. package/lib/src/generated/api/UnlockAgentRequest.js +2 -0
  138. package/lib/src/generated/api/UpdateLinkRequest.d.ts +7 -0
  139. package/lib/src/generated/api/UpdateLinkRequest.js +1 -0
  140. package/lib/src/generated/api/UpdatePerspectiveRequest.d.ts +3 -0
  141. package/lib/src/generated/api/UpdatePerspectiveRequest.js +2 -0
  142. package/lib/src/generated/api/UserStatistics.d.ts +9 -0
  143. package/lib/src/generated/api/UserStatistics.js +2 -0
  144. package/lib/src/generated/api/VerificationRequestResult.d.ts +6 -0
  145. package/lib/src/generated/api/VerificationRequestResult.js +2 -0
  146. package/lib/src/generated/api/VerifySignatureRequest.d.ts +5 -0
  147. package/lib/src/generated/api/VerifySignatureRequest.js +2 -0
  148. package/lib/src/generated/api/WriteSettingsRequest.d.ts +3 -0
  149. package/lib/src/generated/api/WriteSettingsRequest.js +2 -0
  150. package/lib/src/generated/api/index.d.ts +42 -0
  151. package/lib/src/generated/api/index.js +7 -0
  152. package/lib/src/index.d.ts +8 -2
  153. package/lib/src/index.js +8 -2
  154. package/lib/src/jestSetup.d.ts +0 -1
  155. package/lib/src/jestSetup.js +1 -1
  156. package/lib/src/language/Icon.js +2 -21
  157. package/lib/src/language/Language.d.ts +26 -176
  158. package/lib/src/language/Language.js +32 -72
  159. package/lib/src/language/LanguageClient.d.ts +2 -2
  160. package/lib/src/language/LanguageClient.js +15 -105
  161. package/lib/src/language/LanguageHandle.js +2 -41
  162. package/lib/src/language/LanguageMeta.js +4 -75
  163. package/lib/src/language/LanguageRef.js +2 -25
  164. package/lib/src/links/Links.js +14 -111
  165. package/lib/src/model/Ad4mModel.d.ts +143 -63
  166. package/lib/src/model/Ad4mModel.js +583 -425
  167. package/lib/src/model/Ad4mModel.test.js +1434 -688
  168. package/lib/src/model/ModelQueryBuilder.d.ts +61 -45
  169. package/lib/src/model/ModelQueryBuilder.js +315 -157
  170. package/lib/src/model/Subject.js +6 -6
  171. package/lib/src/model/decorators.d.ts +36 -8
  172. package/lib/src/model/decorators.js +41 -14
  173. package/lib/src/model/hydration-batch.d.ts +34 -0
  174. package/lib/src/model/hydration-batch.js +147 -0
  175. package/lib/src/model/hydration-batching.test.d.ts +7 -0
  176. package/lib/src/model/hydration-batching.test.js +456 -0
  177. package/lib/src/model/hydration.d.ts +3 -92
  178. package/lib/src/model/hydration.js +3 -691
  179. package/lib/src/model/index.d.ts +3 -4
  180. package/lib/src/model/index.js +3 -4
  181. package/lib/src/model/json-schema.js +2 -2
  182. package/lib/src/model/model-manifest.d.ts +41 -0
  183. package/lib/src/model/model-manifest.js +11 -0
  184. package/lib/src/model/query-cache.d.ts +30 -0
  185. package/lib/src/model/query-cache.js +66 -0
  186. package/lib/src/model/query-cache.test.d.ts +1 -0
  187. package/lib/src/model/query-cache.test.js +43 -0
  188. package/lib/src/model/query-common.d.ts +1 -1
  189. package/lib/src/model/query-common.js +1 -1
  190. package/lib/src/model/query-sparql-batch.d.ts +17 -0
  191. package/lib/src/model/query-sparql-batch.js +260 -0
  192. package/lib/src/model/query-sparql.d.ts +51 -0
  193. package/lib/src/model/query-sparql.js +466 -0
  194. package/lib/src/model/query-sparql.test.d.ts +1 -0
  195. package/lib/src/model/query-sparql.test.js +312 -0
  196. package/lib/src/model/{surreal-utils.d.ts → query-utils.d.ts} +13 -9
  197. package/lib/src/model/query-utils.js +189 -0
  198. package/lib/src/model/relation-filtering.test.js +15 -15
  199. package/lib/src/model/sdna.js +1 -1
  200. package/lib/src/model/shacl-gen.js +154 -57
  201. package/lib/src/model/subscription-delta.test.d.ts +24 -0
  202. package/lib/src/model/subscription-delta.test.js +180 -0
  203. package/lib/src/model/subscription-pool.d.ts +39 -0
  204. package/lib/src/model/subscription-pool.js +165 -0
  205. package/lib/src/model/types.d.ts +195 -5
  206. package/lib/src/model/types.js +5 -2
  207. package/lib/src/neighbourhood/Neighbourhood.js +4 -32
  208. package/lib/src/neighbourhood/NeighbourhoodClient.d.ts +3 -3
  209. package/lib/src/neighbourhood/NeighbourhoodClient.js +40 -203
  210. package/lib/src/perspectives/LinkQuery.js +2 -42
  211. package/lib/src/perspectives/Perspective.d.ts +1 -1
  212. package/lib/src/perspectives/Perspective.js +10 -52
  213. package/lib/src/perspectives/PerspectiveClient.d.ts +22 -32
  214. package/lib/src/perspectives/PerspectiveClient.js +188 -454
  215. package/lib/src/perspectives/PerspectiveClient.test.d.ts +1 -0
  216. package/lib/src/perspectives/PerspectiveClient.test.js +224 -0
  217. package/lib/src/perspectives/PerspectiveDiff.js +4 -31
  218. package/lib/src/perspectives/PerspectiveHandle.js +3 -43
  219. package/lib/src/perspectives/PerspectiveProxy.d.ts +157 -78
  220. package/lib/src/perspectives/PerspectiveProxy.js +475 -389
  221. package/lib/src/perspectives/PerspectiveResolver.d.ts +0 -1
  222. package/lib/src/perspectives/PerspectiveResolver.js +0 -11
  223. package/lib/src/perspectives/SparqlBindings.d.ts +47 -0
  224. package/lib/src/perspectives/SparqlBindings.js +65 -0
  225. package/lib/src/perspectives/WakerSubscriptionManager.d.ts +3 -3
  226. package/lib/src/perspectives/WakerSubscriptionManager.js +12 -12
  227. package/lib/src/runtime/RuntimeClient.d.ts +8 -6
  228. package/lib/src/runtime/RuntimeClient.js +97 -454
  229. package/lib/src/runtime/RuntimeResolver.d.ts +14 -0
  230. package/lib/src/runtime/RuntimeResolver.js +84 -0
  231. package/lib/src/runtime/RuntimeTypes.d.ts +101 -0
  232. package/lib/src/runtime/RuntimeTypes.js +45 -0
  233. package/lib/src/schema.gql +14 -1
  234. package/lib/src/shacl/SHACLFlow.d.ts +1 -1
  235. package/lib/src/shacl/SHACLFlow.js +9 -9
  236. package/lib/src/shacl/SHACLShape.d.ts +26 -1
  237. package/lib/src/shacl/SHACLShape.js +140 -38
  238. package/lib/src/shacl/SHACLShape.test.js +82 -0
  239. package/lib/src/typeDefs.js +3 -615
  240. package/lib/src/utils.d.ts +6 -6
  241. package/lib/src/utils.js +6 -6
  242. package/package.json +9 -24
  243. package/rollup.config.js +0 -7
  244. package/src/Ad4mClient.test.ts +1192 -1288
  245. package/src/Ad4mClient.ts +46 -15
  246. package/src/Literal.test.ts +10 -5
  247. package/src/Literal.ts +6 -5
  248. package/src/agent/Agent.ts +0 -99
  249. package/src/agent/AgentClient.ts +238 -467
  250. package/src/agent/AgentStatus.ts +0 -12
  251. package/src/ai/AIClient.ts +96 -296
  252. package/src/ai/AITypes.ts +66 -0
  253. package/src/ai/Tasks.ts +0 -52
  254. package/src/apiClient.ts +287 -0
  255. package/src/cache/PersistentCache.ts +145 -0
  256. package/src/cache/cache.test.ts +713 -0
  257. package/src/expression/Expression.ts +3 -43
  258. package/src/expression/ExpressionClient.ts +148 -77
  259. package/src/expression/ExpressionRef.ts +2 -8
  260. package/src/generated/api/AIModelLoadingStatus.ts +3 -0
  261. package/src/generated/api/AddLinkExpressionRequest.ts +4 -0
  262. package/src/generated/api/AddLinkRequest.ts +4 -0
  263. package/src/generated/api/AddLinksBulkRequest.ts +4 -0
  264. package/src/generated/api/AddSdnaRequest.ts +3 -0
  265. package/src/generated/api/ApplyTemplateRequest.ts +3 -0
  266. package/src/generated/api/AuthInfoInput.ts +4 -0
  267. package/src/generated/api/CapabilityInput.ts +4 -0
  268. package/src/generated/api/CommitBatchRequest.ts +3 -0
  269. package/src/generated/api/ComputeLogEntry.ts +3 -0
  270. package/src/generated/api/CreateExpressionRequest.ts +3 -0
  271. package/src/generated/api/CreatePerspectiveRequest.ts +3 -0
  272. package/src/generated/api/CreateSubjectRequest.ts +3 -0
  273. package/src/generated/api/EmbedRequest.ts +3 -0
  274. package/src/generated/api/EntanglementProofInput.ts +3 -0
  275. package/src/generated/api/ExecuteCommandsRequest.ts +3 -0
  276. package/src/generated/api/ExportRequest.ts +3 -0
  277. package/src/generated/api/ExpressionManyRequest.ts +3 -0
  278. package/src/generated/api/ExpressionProof.ts +3 -0
  279. package/src/generated/api/ExpressionProofInput.ts +3 -0
  280. package/src/generated/api/FriendSendMessageRequest.ts +3 -0
  281. package/src/generated/api/FriendsListRequest.ts +3 -0
  282. package/src/generated/api/GenerateAgentRequest.ts +3 -0
  283. package/src/generated/api/GenerateJwtRequest.ts +3 -0
  284. package/src/generated/api/GetSubjectDataRequest.ts +3 -0
  285. package/src/generated/api/ImportAgentRequest.ts +3 -0
  286. package/src/generated/api/ImportRequest.ts +3 -0
  287. package/src/generated/api/JoinNeighbourhoodRequest.ts +3 -0
  288. package/src/generated/api/LanguageMetaInput.ts +3 -0
  289. package/src/generated/api/Link.ts +3 -0
  290. package/src/generated/api/LinkExpression.ts +6 -0
  291. package/src/generated/api/LinkExpressionInput.ts +6 -0
  292. package/src/generated/api/LinkInput.ts +3 -0
  293. package/src/generated/api/LinkLanguageTemplatesRequest.ts +3 -0
  294. package/src/generated/api/LinkMutations.ts +5 -0
  295. package/src/generated/api/LinkStatus.ts +3 -0
  296. package/src/generated/api/LockAgentRequest.ts +3 -0
  297. package/src/generated/api/ModelType.ts +3 -0
  298. package/src/generated/api/NotificationInput.ts +3 -0
  299. package/src/generated/api/OpenLinkRequest.ts +3 -0
  300. package/src/generated/api/PermitCapabilityRequest.ts +3 -0
  301. package/src/generated/api/PerspectiveInput.ts +4 -0
  302. package/src/generated/api/PromptRequest.ts +3 -0
  303. package/src/generated/api/PublishLanguageRequest.ts +4 -0
  304. package/src/generated/api/PublishNeighbourhoodRequest.ts +4 -0
  305. package/src/generated/api/QueryRequest.ts +6 -0
  306. package/src/generated/api/RemoveLinkRequest.ts +4 -0
  307. package/src/generated/api/RemoveLinksBulkRequest.ts +4 -0
  308. package/src/generated/api/ResourceInput.ts +3 -0
  309. package/src/generated/api/SetDefaultModelRequest.ts +4 -0
  310. package/src/generated/api/SetFreeHostingEnabledRequest.ts +3 -0
  311. package/src/generated/api/SetMultiUserRequest.ts +3 -0
  312. package/src/generated/api/SetStatusRequest.ts +3 -0
  313. package/src/generated/api/SignMessageRequest.ts +3 -0
  314. package/src/generated/api/TrustedAgentsRequest.ts +3 -0
  315. package/src/generated/api/UnlockAgentRequest.ts +3 -0
  316. package/src/generated/api/UpdateLinkRequest.ts +5 -0
  317. package/src/generated/api/UpdatePerspectiveRequest.ts +3 -0
  318. package/src/generated/api/UserStatistics.ts +3 -0
  319. package/src/generated/api/VerificationRequestResult.ts +3 -0
  320. package/src/generated/api/VerifySignatureRequest.ts +3 -0
  321. package/src/generated/api/WriteSettingsRequest.ts +3 -0
  322. package/src/generated/api/index.ts +49 -0
  323. package/src/index.ts +8 -2
  324. package/src/jestSetup.ts +1 -1
  325. package/src/language/Icon.ts +0 -4
  326. package/src/language/Language.ts +51 -248
  327. package/src/language/LanguageClient.ts +21 -132
  328. package/src/language/LanguageHandle.ts +0 -14
  329. package/src/language/LanguageMeta.ts +0 -29
  330. package/src/language/LanguageRef.ts +0 -7
  331. package/src/links/Links.ts +0 -37
  332. package/src/model/Ad4mModel.test.ts +1664 -792
  333. package/src/model/Ad4mModel.ts +664 -499
  334. package/src/model/ModelQueryBuilder.ts +362 -183
  335. package/src/model/decorators.ts +71 -22
  336. package/src/model/hydration.ts +3 -772
  337. package/src/model/index.ts +3 -4
  338. package/src/model/json-schema.ts +2 -2
  339. package/src/model/query-cache.test.ts +54 -0
  340. package/src/model/query-cache.ts +79 -0
  341. package/src/model/query-common.ts +1 -1
  342. package/src/model/query-sparql.test.ts +376 -0
  343. package/src/model/query-sparql.ts +504 -0
  344. package/src/model/query-utils.ts +209 -0
  345. package/src/model/relation-filtering.test.ts +60 -53
  346. package/src/model/sdna.ts +1 -1
  347. package/src/model/shacl-gen.ts +163 -64
  348. package/src/model/shacl-roundtrip.test.ts +197 -0
  349. package/src/model/types-typed-query.test.ts +360 -0
  350. package/src/model/types.ts +256 -5
  351. package/src/neighbourhood/Neighbourhood.ts +0 -9
  352. package/src/neighbourhood/NeighbourhoodClient.ts +42 -207
  353. package/src/neighbourhood/NeighbourhoodProxy.test.ts +34 -36
  354. package/src/perspectives/LinkQuery.ts +0 -15
  355. package/src/perspectives/Perspective.ts +1 -12
  356. package/src/perspectives/PerspectiveClient.test.ts +262 -0
  357. package/src/perspectives/PerspectiveClient.ts +252 -468
  358. package/src/perspectives/PerspectiveDiff.ts +0 -8
  359. package/src/perspectives/PerspectiveHandle.ts +1 -12
  360. package/src/perspectives/PerspectiveProxy.test.ts +125 -0
  361. package/src/perspectives/PerspectiveProxy.ts +522 -434
  362. package/src/perspectives/SparqlBindings.ts +79 -0
  363. package/src/perspectives/WakerSubscriptionManager.ts +13 -13
  364. package/src/runtime/RuntimeClient.ts +118 -461
  365. package/src/runtime/RuntimeTypes.ts +144 -0
  366. package/src/shacl/SHACLFlow.ts +9 -9
  367. package/src/shacl/SHACLShape.test.ts +204 -0
  368. package/src/shacl/SHACLShape.ts +191 -39
  369. package/src/typeDefs.ts +3 -5
  370. package/src/utils.ts +6 -6
  371. package/tsconfig.json +3 -7
  372. package/lib/src/model/query-surreal.d.ts +0 -44
  373. package/lib/src/model/query-surreal.js +0 -249
  374. package/lib/src/model/surreal-utils.js +0 -128
  375. package/shims/reflect-metadata.ts +0 -0
  376. package/shims/type-graphql.ts +0 -75
  377. package/src/PubSub.ts +0 -17
  378. package/src/agent/AgentResolver.ts +0 -263
  379. package/src/ai/AIResolver.ts +0 -372
  380. package/src/buildSchema.ts +0 -43
  381. package/src/expression/ExpressionResolver.ts +0 -64
  382. package/src/language/LanguageContext.ts +0 -37
  383. package/src/language/LanguageResolver.ts +0 -98
  384. package/src/model/Subject.ts +0 -159
  385. package/src/model/prolog-facts.ts +0 -145
  386. package/src/model/query-prolog.ts +0 -148
  387. package/src/model/query-surreal.ts +0 -280
  388. package/src/model/surreal-utils.ts +0 -147
  389. package/src/neighbourhood/NeighbourhoodResolver.ts +0 -100
  390. package/src/perspectives/PerspectiveResolver.ts +0 -372
  391. package/src/runtime/RuntimeResolver.ts +0 -691
  392. package/src/unwrapApolloResult.ts +0 -16
  393. package/tsconfig-browser.json +0 -82
@@ -19,7 +19,7 @@ export interface RelationMetadataEntry {
19
19
  maxCount?: number;
20
20
  local?: boolean;
21
21
  /**
22
- * Custom SurrealQL getter to resolve the relation values.
22
+ * Custom getter to resolve the relation values.
23
23
  * The expression can reference 'Base' which will be replaced with the instance's base expression.
24
24
  */
25
25
  getter?: string;
@@ -39,13 +39,19 @@ export interface RelationMetadataEntry {
39
39
  /**
40
40
  * Retrieve property metadata for a given class constructor.
41
41
  * Walks the prototype chain so subclass decorators compose with parent decorators.
42
+ * Results are memoised per class constructor.
42
43
  */
43
44
  export declare function getPropertiesMetadata(ctor: Function): Record<string, PropertyMetadataEntry>;
44
45
  /**
45
46
  * Retrieve relation metadata for a given class constructor.
46
47
  * Walks the prototype chain so subclass decorators compose with parent decorators.
48
+ * Results are memoised per class constructor.
47
49
  */
48
50
  export declare function getRelationsMetadata(ctor: Function): Record<string, RelationMetadataEntry>;
51
+ /**
52
+ * Get or compute memoised SHACL for a class. Used by @Model decorator.
53
+ */
54
+ export declare function getMemoizedSHACL(target: Function, compute: () => any): any;
49
55
  /**
50
56
  * Programmatically register property metadata for a given constructor.
51
57
  * Used by `fromJSONSchema()` and other dynamic model builders.
@@ -72,7 +78,7 @@ export interface Ad4mModelLike {
72
78
  *
73
79
  * Inspects the target class's property metadata to derive:
74
80
  * - `conformanceConditions`: Structured, DB-agnostic conditions (flag & required checks)
75
- * - `getter`: Pre-computed SurrealQL expression that traverses outgoing links and filters
81
+ * - `getter`: Pre-computed graph traversal expression that traverses outgoing links and filters
76
82
  * target nodes to only those conforming to the target shape.
77
83
  *
78
84
  * @param relationPredicate - The relation's predicate URI (e.g. "flux://entry_type")
@@ -114,9 +120,9 @@ export interface PropertyOptions {
114
120
  */
115
121
  prologSetter?: string;
116
122
  /**
117
- * Custom SurrealQL getter to resolve the property value. Use this for custom graph traversals.
123
+ * Custom getter to resolve the property value. Use this for custom graph traversals.
118
124
  * The expression can reference 'Base' which will be replaced with the instance's base expression.
119
- * Example: "(<-link[WHERE predicate = 'flux://has_reply'].in.uri)[0]"
125
+ * Example: "SELECT ?target WHERE { <Base> <flux://has_reply> ?target . } LIMIT 1"
120
126
  */
121
127
  getter?: string;
122
128
  /**
@@ -129,6 +135,28 @@ export interface PropertyOptions {
129
135
  * The function takes the raw value as input and returns the transformed value.
130
136
  */
131
137
  transform?: (value: any) => any;
138
+ /**
139
+ * Allowed values for this property (enum constraint).
140
+ * Maps to SHACL `sh:in`. Each entry has a `value` (the stored RDF term)
141
+ * and an optional `label` (human-readable display name).
142
+ *
143
+ * @example
144
+ * ```typescript
145
+ * @Property({
146
+ * through: "task://status",
147
+ * options: [
148
+ * { value: "task://todo", label: "To Do" },
149
+ * { value: "task://doing", label: "Doing" },
150
+ * { value: "task://done", label: "Done" },
151
+ * ]
152
+ * })
153
+ * status: string = "task://todo";
154
+ * ```
155
+ */
156
+ options?: Array<{
157
+ value: string;
158
+ label?: string;
159
+ }>;
132
160
  }
133
161
  /**
134
162
  * Convenience decorator for defining optional (not required) properties.
@@ -294,7 +322,7 @@ export declare function Model(opts: ModelConfig): (target: any) => void;
294
322
  * Properties are optional by default. When a model instance is created without
295
323
  * providing a value for an optional property, no link is added to the graph.
296
324
  * Set `required: true` explicitly when a property must always be present (this
297
- * also adds a `"literal://string:uninitialized"` sentinel as the initial value
325
+ * also adds a `"literal:string:uninitialized"` sentinel as the initial value
298
326
  * so that the SDNA constructor creates a placeholder link).
299
327
  *
300
328
  * @example
@@ -333,7 +361,7 @@ export declare function Model(opts: ModelConfig): (target: any) => void;
333
361
  * @param {PropertyOptions} opts - Property configuration
334
362
  * @param {string} opts.through - The predicate URI for the property
335
363
  * @param {boolean} [opts.required=false] - Whether the property is required (adds query filters and sentinel initial value)
336
- * @param {string} [opts.initial] - Initial value (defaults to "literal://string:uninitialized" when required)
364
+ * @param {string} [opts.initial] - Initial value (defaults to "literal:string:uninitialized" when required)
337
365
  * @param {string} [opts.resolveLanguage] - Language to use for value resolution (e.g. "literal")
338
366
  * @param {string} [opts.prologGetter] - Custom Prolog code for getting the property value
339
367
  * @param {string} [opts.prologSetter] - Custom Prolog code for setting the property value
@@ -410,9 +438,9 @@ export interface RelationOptions {
410
438
  * Cannot be combined with `getter`. */
411
439
  target?: () => Ad4mModelLike;
412
440
  /**
413
- * Custom SurrealQL getter to resolve the relation values. Use this for custom graph traversals.
441
+ * Custom getter to resolve the relation values. Use this for custom graph traversals.
414
442
  * The expression can reference 'Base' which will be replaced with the instance's base expression.
415
- * Example: "(<-link[WHERE predicate = 'flux://has_reply'].out.uri)"
443
+ * Example: "SELECT ?target WHERE { ?target <flux://has_reply> <Base> . }"
416
444
  *
417
445
  * Mutually exclusive with `through` and `target`. When `getter` is provided the
418
446
  * relation is read-only (no adder/remover actions are generated).
@@ -1,16 +1,26 @@
1
1
  import { capitalize } from "./util";
2
2
  import { buildSDNA } from "./sdna";
3
3
  import { buildSHACL } from "./shacl-gen";
4
- import { escapeSurrealString } from "../utils";
4
+ import { escapeQueryString } from "../utils";
5
5
  /** Registry of property metadata keyed by constructor → { propName → metadata } */
6
6
  const propertyRegistry = new WeakMap();
7
7
  /** Registry of relation metadata keyed by constructor → { propName → metadata } */
8
8
  const relationRegistry = new WeakMap();
9
+ /** Memoisation cache for getPropertiesMetadata — avoids repeated prototype-chain walks */
10
+ const propertiesMetadataCache = new WeakMap();
11
+ /** Memoisation cache for getRelationsMetadata — avoids repeated prototype-chain walks */
12
+ const relationsMetadataCache = new WeakMap();
13
+ /** Memoisation cache for generateSHACL — avoids recomputing SHACL shapes */
14
+ const shaclCache = new WeakMap();
9
15
  /**
10
16
  * Retrieve property metadata for a given class constructor.
11
17
  * Walks the prototype chain so subclass decorators compose with parent decorators.
18
+ * Results are memoised per class constructor.
12
19
  */
13
20
  export function getPropertiesMetadata(ctor) {
21
+ const cached = propertiesMetadataCache.get(ctor);
22
+ if (cached)
23
+ return cached;
14
24
  const result = {};
15
25
  const chain = [];
16
26
  let current = ctor;
@@ -23,13 +33,18 @@ export function getPropertiesMetadata(ctor) {
23
33
  if (meta)
24
34
  Object.assign(result, meta);
25
35
  }
36
+ propertiesMetadataCache.set(ctor, result);
26
37
  return result;
27
38
  }
28
39
  /**
29
40
  * Retrieve relation metadata for a given class constructor.
30
41
  * Walks the prototype chain so subclass decorators compose with parent decorators.
42
+ * Results are memoised per class constructor.
31
43
  */
32
44
  export function getRelationsMetadata(ctor) {
45
+ const cached = relationsMetadataCache.get(ctor);
46
+ if (cached)
47
+ return cached;
33
48
  const result = {};
34
49
  const chain = [];
35
50
  let current = ctor;
@@ -42,6 +57,18 @@ export function getRelationsMetadata(ctor) {
42
57
  if (meta)
43
58
  Object.assign(result, meta);
44
59
  }
60
+ relationsMetadataCache.set(ctor, result);
61
+ return result;
62
+ }
63
+ /**
64
+ * Get or compute memoised SHACL for a class. Used by @Model decorator.
65
+ */
66
+ export function getMemoizedSHACL(target, compute) {
67
+ const cached = shaclCache.get(target);
68
+ if (cached)
69
+ return cached;
70
+ const result = compute();
71
+ shaclCache.set(target, result);
45
72
  return result;
46
73
  }
47
74
  /**
@@ -67,7 +94,7 @@ export function setRelationRegistryEntry(ctor, relName, meta) {
67
94
  *
68
95
  * Inspects the target class's property metadata to derive:
69
96
  * - `conformanceConditions`: Structured, DB-agnostic conditions (flag & required checks)
70
- * - `getter`: Pre-computed SurrealQL expression that traverses outgoing links and filters
97
+ * - `getter`: Pre-computed graph traversal expression that traverses outgoing links and filters
71
98
  * target nodes to only those conforming to the target shape.
72
99
  *
73
100
  * @param relationPredicate - The relation's predicate URI (e.g. "flux://entry_type")
@@ -78,7 +105,8 @@ export function buildConformanceFilter(relationPredicate, targetClass) {
78
105
  try {
79
106
  const targetProps = getPropertiesMetadata(targetClass);
80
107
  const conditions = [];
81
- const surrealConditions = [];
108
+ const sparqlConditions = [];
109
+ let varIdx = 0;
82
110
  // 1. Flags — check predicate + value
83
111
  for (const [_propName, propMeta] of Object.entries(targetProps)) {
84
112
  if (propMeta.flag && propMeta.initial && propMeta.through) {
@@ -87,7 +115,7 @@ export function buildConformanceFilter(relationPredicate, targetClass) {
87
115
  predicate: propMeta.through,
88
116
  value: propMeta.initial,
89
117
  });
90
- surrealConditions.push(`count(->link[WHERE predicate = '${escapeSurrealString(propMeta.through)}' AND out.uri = '${escapeSurrealString(propMeta.initial)}']) > 0`);
118
+ sparqlConditions.push(`?target <${escapeQueryString(propMeta.through)}> <${escapeQueryString(propMeta.initial)}> .`);
91
119
  }
92
120
  }
93
121
  // 2. Required (non-flag) properties — check predicate exists
@@ -98,14 +126,13 @@ export function buildConformanceFilter(relationPredicate, targetClass) {
98
126
  type: 'required',
99
127
  predicate: propMeta.through,
100
128
  });
101
- surrealConditions.push(`count(->link[WHERE predicate = '${escapeSurrealString(propMeta.through)}']) > 0`);
129
+ sparqlConditions.push(`?target <${escapeQueryString(propMeta.through)}> ?_v${varIdx++} .`);
102
130
  }
103
131
  }
104
132
  if (conditions.length === 0) {
105
133
  return undefined;
106
134
  }
107
- const escapedPredicate = escapeSurrealString(relationPredicate);
108
- const getter = `(->link[WHERE predicate = '${escapedPredicate}'].out[WHERE ${surrealConditions.join(' AND ')}].uri)`;
135
+ const getter = `SELECT ?target WHERE { <Base> <${escapeQueryString(relationPredicate)}> ?target . ${sparqlConditions.join(' ')} }`;
109
136
  return { getter, conformanceConditions: conditions };
110
137
  }
111
138
  catch (e) {
@@ -126,8 +153,8 @@ function applyPropertyMetadata(opts) {
126
153
  if (opts.required && !opts.initial) {
127
154
  throw new Error("SubjectProperty requires an 'initial' option if 'required' is true");
128
155
  }
129
- if (!opts.through && !opts.prologGetter) {
130
- throw new Error("SubjectProperty requires either 'through' or 'prologGetter' option");
156
+ if (!opts.through && !opts.prologGetter && !opts.getter) {
157
+ throw new Error("SubjectProperty requires either 'through' or 'prologGetter' or 'getter' option");
131
158
  }
132
159
  // Write to WeakMap registry (keyed by constructor)
133
160
  const ctor = target.constructor;
@@ -312,7 +339,7 @@ export function Model(opts) {
312
339
  return buildSDNA(opts.name, target.prototype, getPropertiesMetadata(target), getRelationsMetadata(target));
313
340
  };
314
341
  target.generateSHACL = function () {
315
- return buildSHACL(opts.name, target, getPropertiesMetadata(target), getRelationsMetadata(target), buildConformanceFilter);
342
+ return getMemoizedSHACL(target, () => buildSHACL(opts.name, target, getPropertiesMetadata(target), getRelationsMetadata(target), buildConformanceFilter));
316
343
  };
317
344
  Object.defineProperty(target, 'type', { configurable: true });
318
345
  };
@@ -335,7 +362,7 @@ export function Model(opts) {
335
362
  * Properties are optional by default. When a model instance is created without
336
363
  * providing a value for an optional property, no link is added to the graph.
337
364
  * Set `required: true` explicitly when a property must always be present (this
338
- * also adds a `"literal://string:uninitialized"` sentinel as the initial value
365
+ * also adds a `"literal:string:uninitialized"` sentinel as the initial value
339
366
  * so that the SDNA constructor creates a placeholder link).
340
367
  *
341
368
  * @example
@@ -374,7 +401,7 @@ export function Model(opts) {
374
401
  * @param {PropertyOptions} opts - Property configuration
375
402
  * @param {string} opts.through - The predicate URI for the property
376
403
  * @param {boolean} [opts.required=false] - Whether the property is required (adds query filters and sentinel initial value)
377
- * @param {string} [opts.initial] - Initial value (defaults to "literal://string:uninitialized" when required)
404
+ * @param {string} [opts.initial] - Initial value (defaults to "literal:string:uninitialized" when required)
378
405
  * @param {string} [opts.resolveLanguage] - Language to use for value resolution (e.g. "literal")
379
406
  * @param {string} [opts.prologGetter] - Custom Prolog code for getting the property value
380
407
  * @param {string} [opts.prologSetter] - Custom Prolog code for setting the property value
@@ -387,7 +414,7 @@ export function Property(opts) {
387
414
  required,
388
415
  readOnly: opts.readOnly ?? false,
389
416
  resolveLanguage: opts.resolveLanguage ?? "literal",
390
- initial: opts.initial ?? (required ? "literal://string:uninitialized" : undefined),
417
+ initial: opts.initial ?? (required ? "literal:string:uninitialized" : undefined),
391
418
  });
392
419
  }
393
420
  /**
@@ -476,7 +503,7 @@ function resolveRelationArgs(first, second) {
476
503
  }
477
504
  if (opts.where) {
478
505
  throw new Error('Relation decorator: `where` and `getter` are mutually exclusive. ' +
479
- 'Use `where` for DSL-based filtering, or `getter` for raw SurrealQL.');
506
+ 'Use `where` for DSL-based filtering, or `getter` for raw getter expression.');
480
507
  }
481
508
  return opts;
482
509
  }
@@ -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 {};