@coasys/ad4m 0.13.0-test-2 → 0.13.0-test-4

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 (347) hide show
  1. package/README.md +2 -25
  2. package/jest-setup.ts +1 -1
  3. package/lib/index.cjs +2805 -10556
  4. package/lib/index.js +2513 -10322
  5. package/lib/src/Ad4mClient.d.ts +7 -3
  6. package/lib/src/Ad4mClient.js +29 -13
  7. package/lib/src/agent/Agent.js +26 -272
  8. package/lib/src/agent/AgentClient.d.ts +10 -21
  9. package/lib/src/agent/AgentClient.js +75 -427
  10. package/lib/src/agent/AgentStatus.js +2 -37
  11. package/lib/src/ai/AIClient.d.ts +12 -4
  12. package/lib/src/ai/AIClient.js +81 -285
  13. package/lib/src/ai/AITypes.d.ts +55 -0
  14. package/lib/src/ai/AITypes.js +18 -0
  15. package/lib/src/ai/Tasks.js +10 -133
  16. package/lib/src/apiClient.d.ts +52 -0
  17. package/lib/src/apiClient.js +231 -0
  18. package/lib/src/expression/Expression.d.ts +1 -1
  19. package/lib/src/expression/Expression.js +13 -122
  20. package/lib/src/expression/ExpressionClient.d.ts +3 -3
  21. package/lib/src/expression/ExpressionClient.js +13 -76
  22. package/lib/src/expression/ExpressionRef.js +2 -25
  23. package/lib/src/generated/api/AIModelLoadingStatus.d.ts +7 -0
  24. package/lib/src/generated/api/AIModelLoadingStatus.js +2 -0
  25. package/lib/src/generated/api/AddLinkExpressionRequest.d.ts +6 -0
  26. package/lib/src/generated/api/AddLinkExpressionRequest.js +1 -0
  27. package/lib/src/generated/api/AddLinkRequest.d.ts +6 -0
  28. package/lib/src/generated/api/AddLinkRequest.js +1 -0
  29. package/lib/src/generated/api/AddLinksBulkRequest.d.ts +6 -0
  30. package/lib/src/generated/api/AddLinksBulkRequest.js +1 -0
  31. package/lib/src/generated/api/AddSdnaRequest.d.ts +6 -0
  32. package/lib/src/generated/api/AddSdnaRequest.js +2 -0
  33. package/lib/src/generated/api/ApplyTemplateRequest.d.ts +4 -0
  34. package/lib/src/generated/api/ApplyTemplateRequest.js +2 -0
  35. package/lib/src/generated/api/AuthInfoInput.d.ts +10 -0
  36. package/lib/src/generated/api/AuthInfoInput.js +1 -0
  37. package/lib/src/generated/api/CapabilityInput.d.ts +5 -0
  38. package/lib/src/generated/api/CapabilityInput.js +1 -0
  39. package/lib/src/generated/api/CommitBatchRequest.d.ts +3 -0
  40. package/lib/src/generated/api/CommitBatchRequest.js +2 -0
  41. package/lib/src/generated/api/ComputeLogEntry.d.ts +9 -0
  42. package/lib/src/generated/api/ComputeLogEntry.js +2 -0
  43. package/lib/src/generated/api/CreateExpressionRequest.d.ts +4 -0
  44. package/lib/src/generated/api/CreateExpressionRequest.js +2 -0
  45. package/lib/src/generated/api/CreatePerspectiveRequest.d.ts +3 -0
  46. package/lib/src/generated/api/CreatePerspectiveRequest.js +2 -0
  47. package/lib/src/generated/api/CreateSubjectRequest.d.ts +6 -0
  48. package/lib/src/generated/api/CreateSubjectRequest.js +2 -0
  49. package/lib/src/generated/api/EmbedRequest.d.ts +4 -0
  50. package/lib/src/generated/api/EmbedRequest.js +2 -0
  51. package/lib/src/generated/api/EntanglementProofInput.d.ts +6 -0
  52. package/lib/src/generated/api/EntanglementProofInput.js +2 -0
  53. package/lib/src/generated/api/ExecuteCommandsRequest.d.ts +4 -0
  54. package/lib/src/generated/api/ExecuteCommandsRequest.js +2 -0
  55. package/lib/src/generated/api/ExportRequest.d.ts +5 -0
  56. package/lib/src/generated/api/ExportRequest.js +2 -0
  57. package/lib/src/generated/api/ExpressionManyRequest.d.ts +3 -0
  58. package/lib/src/generated/api/ExpressionManyRequest.js +2 -0
  59. package/lib/src/generated/api/ExpressionProof.d.ts +4 -0
  60. package/lib/src/generated/api/ExpressionProof.js +2 -0
  61. package/lib/src/generated/api/ExpressionProofInput.d.ts +6 -0
  62. package/lib/src/generated/api/ExpressionProofInput.js +2 -0
  63. package/lib/src/generated/api/FriendSendMessageRequest.d.ts +3 -0
  64. package/lib/src/generated/api/FriendSendMessageRequest.js +2 -0
  65. package/lib/src/generated/api/FriendsListRequest.d.ts +3 -0
  66. package/lib/src/generated/api/FriendsListRequest.js +2 -0
  67. package/lib/src/generated/api/GenerateAgentRequest.d.ts +3 -0
  68. package/lib/src/generated/api/GenerateAgentRequest.js +2 -0
  69. package/lib/src/generated/api/GenerateJwtRequest.d.ts +4 -0
  70. package/lib/src/generated/api/GenerateJwtRequest.js +2 -0
  71. package/lib/src/generated/api/GetSubjectDataRequest.d.ts +4 -0
  72. package/lib/src/generated/api/GetSubjectDataRequest.js +2 -0
  73. package/lib/src/generated/api/ImportAgentRequest.d.ts +6 -0
  74. package/lib/src/generated/api/ImportAgentRequest.js +2 -0
  75. package/lib/src/generated/api/ImportRequest.d.ts +4 -0
  76. package/lib/src/generated/api/ImportRequest.js +2 -0
  77. package/lib/src/generated/api/JoinNeighbourhoodRequest.d.ts +3 -0
  78. package/lib/src/generated/api/JoinNeighbourhoodRequest.js +2 -0
  79. package/lib/src/generated/api/LanguageMetaInput.d.ts +6 -0
  80. package/lib/src/generated/api/LanguageMetaInput.js +2 -0
  81. package/lib/src/generated/api/Link.d.ts +5 -0
  82. package/lib/src/generated/api/Link.js +2 -0
  83. package/lib/src/generated/api/LinkExpression.d.ts +10 -0
  84. package/lib/src/generated/api/LinkExpression.js +1 -0
  85. package/lib/src/generated/api/LinkExpressionInput.d.ts +10 -0
  86. package/lib/src/generated/api/LinkExpressionInput.js +1 -0
  87. package/lib/src/generated/api/LinkInput.d.ts +5 -0
  88. package/lib/src/generated/api/LinkInput.js +2 -0
  89. package/lib/src/generated/api/LinkLanguageTemplatesRequest.d.ts +3 -0
  90. package/lib/src/generated/api/LinkLanguageTemplatesRequest.js +2 -0
  91. package/lib/src/generated/api/LinkMutations.d.ts +6 -0
  92. package/lib/src/generated/api/LinkMutations.js +1 -0
  93. package/lib/src/generated/api/LinkStatus.d.ts +1 -0
  94. package/lib/src/generated/api/LinkStatus.js +2 -0
  95. package/lib/src/generated/api/LockAgentRequest.d.ts +3 -0
  96. package/lib/src/generated/api/LockAgentRequest.js +2 -0
  97. package/lib/src/generated/api/ModelType.d.ts +1 -0
  98. package/lib/src/generated/api/ModelType.js +2 -0
  99. package/lib/src/generated/api/NotificationInput.d.ts +10 -0
  100. package/lib/src/generated/api/NotificationInput.js +2 -0
  101. package/lib/src/generated/api/OpenLinkRequest.d.ts +3 -0
  102. package/lib/src/generated/api/OpenLinkRequest.js +2 -0
  103. package/lib/src/generated/api/PermitCapabilityRequest.d.ts +3 -0
  104. package/lib/src/generated/api/PermitCapabilityRequest.js +2 -0
  105. package/lib/src/generated/api/PerspectiveInput.d.ts +4 -0
  106. package/lib/src/generated/api/PerspectiveInput.js +1 -0
  107. package/lib/src/generated/api/PromptRequest.d.ts +4 -0
  108. package/lib/src/generated/api/PromptRequest.js +2 -0
  109. package/lib/src/generated/api/PublishLanguageRequest.d.ts +5 -0
  110. package/lib/src/generated/api/PublishLanguageRequest.js +1 -0
  111. package/lib/src/generated/api/PublishNeighbourhoodRequest.d.ts +6 -0
  112. package/lib/src/generated/api/PublishNeighbourhoodRequest.js +1 -0
  113. package/lib/src/generated/api/QueryRequest.d.ts +7 -0
  114. package/lib/src/generated/api/QueryRequest.js +2 -0
  115. package/lib/src/generated/api/RemoveLinkRequest.d.ts +5 -0
  116. package/lib/src/generated/api/RemoveLinkRequest.js +1 -0
  117. package/lib/src/generated/api/RemoveLinksBulkRequest.d.ts +5 -0
  118. package/lib/src/generated/api/RemoveLinksBulkRequest.js +1 -0
  119. package/lib/src/generated/api/ResourceInput.d.ts +4 -0
  120. package/lib/src/generated/api/ResourceInput.js +2 -0
  121. package/lib/src/generated/api/SetDefaultModelRequest.d.ts +4 -0
  122. package/lib/src/generated/api/SetDefaultModelRequest.js +1 -0
  123. package/lib/src/generated/api/SetFreeHostingEnabledRequest.d.ts +3 -0
  124. package/lib/src/generated/api/SetFreeHostingEnabledRequest.js +2 -0
  125. package/lib/src/generated/api/SetMultiUserRequest.d.ts +3 -0
  126. package/lib/src/generated/api/SetMultiUserRequest.js +2 -0
  127. package/lib/src/generated/api/SetStatusRequest.d.ts +3 -0
  128. package/lib/src/generated/api/SetStatusRequest.js +2 -0
  129. package/lib/src/generated/api/SignMessageRequest.d.ts +3 -0
  130. package/lib/src/generated/api/SignMessageRequest.js +2 -0
  131. package/lib/src/generated/api/TrustedAgentsRequest.d.ts +3 -0
  132. package/lib/src/generated/api/TrustedAgentsRequest.js +2 -0
  133. package/lib/src/generated/api/UnlockAgentRequest.d.ts +4 -0
  134. package/lib/src/generated/api/UnlockAgentRequest.js +2 -0
  135. package/lib/src/generated/api/UpdateLinkRequest.d.ts +7 -0
  136. package/lib/src/generated/api/UpdateLinkRequest.js +1 -0
  137. package/lib/src/generated/api/UpdatePerspectiveRequest.d.ts +3 -0
  138. package/lib/src/generated/api/UpdatePerspectiveRequest.js +2 -0
  139. package/lib/src/generated/api/UserStatistics.d.ts +9 -0
  140. package/lib/src/generated/api/UserStatistics.js +2 -0
  141. package/lib/src/generated/api/VerificationRequestResult.d.ts +6 -0
  142. package/lib/src/generated/api/VerificationRequestResult.js +2 -0
  143. package/lib/src/generated/api/VerifySignatureRequest.d.ts +5 -0
  144. package/lib/src/generated/api/VerifySignatureRequest.js +2 -0
  145. package/lib/src/generated/api/WriteSettingsRequest.d.ts +3 -0
  146. package/lib/src/generated/api/WriteSettingsRequest.js +2 -0
  147. package/lib/src/generated/api/index.d.ts +42 -0
  148. package/lib/src/generated/api/index.js +7 -0
  149. package/lib/src/index.d.ts +6 -2
  150. package/lib/src/index.js +6 -2
  151. package/lib/src/jestSetup.d.ts +0 -1
  152. package/lib/src/jestSetup.js +1 -1
  153. package/lib/src/language/Icon.js +2 -21
  154. package/lib/src/language/Language.d.ts +26 -214
  155. package/lib/src/language/Language.js +32 -72
  156. package/lib/src/language/LanguageClient.d.ts +2 -2
  157. package/lib/src/language/LanguageClient.js +15 -105
  158. package/lib/src/language/LanguageHandle.js +2 -41
  159. package/lib/src/language/LanguageMeta.js +4 -75
  160. package/lib/src/language/LanguageRef.js +2 -25
  161. package/lib/src/links/Links.js +14 -111
  162. package/lib/src/model/Ad4mModel.d.ts +81 -38
  163. package/lib/src/model/Ad4mModel.js +651 -408
  164. package/lib/src/model/Ad4mModel.test.js +488 -750
  165. package/lib/src/model/ModelQueryBuilder.d.ts +28 -21
  166. package/lib/src/model/ModelQueryBuilder.js +160 -195
  167. package/lib/src/model/decorators.d.ts +22 -0
  168. package/lib/src/model/decorators.js +7 -0
  169. package/lib/src/model/hydration-batching.test.d.ts +7 -0
  170. package/lib/src/model/hydration-batching.test.js +456 -0
  171. package/lib/src/model/hydration.d.ts +8 -60
  172. package/lib/src/model/hydration.js +41 -541
  173. package/lib/src/model/index.d.ts +0 -4
  174. package/lib/src/model/index.js +0 -4
  175. package/lib/src/model/model-manifest.d.ts +41 -0
  176. package/lib/src/model/model-manifest.js +11 -0
  177. package/lib/src/model/query-sparql.d.ts +36 -22
  178. package/lib/src/model/query-sparql.js +188 -53
  179. package/lib/src/model/query-sparql.test.d.ts +1 -0
  180. package/lib/src/model/query-sparql.test.js +312 -0
  181. package/lib/src/model/query-utils.js +4 -0
  182. package/lib/src/model/shacl-gen.js +4 -0
  183. package/lib/src/model/subscription-delta.test.d.ts +24 -0
  184. package/lib/src/model/subscription-delta.test.js +180 -0
  185. package/lib/src/model/subscription-pool.js +48 -2
  186. package/lib/src/model/types.d.ts +58 -1
  187. package/lib/src/model/types.js +4 -1
  188. package/lib/src/neighbourhood/Neighbourhood.js +4 -32
  189. package/lib/src/neighbourhood/NeighbourhoodClient.d.ts +3 -3
  190. package/lib/src/neighbourhood/NeighbourhoodClient.js +40 -203
  191. package/lib/src/perspectives/LinkQuery.js +2 -42
  192. package/lib/src/perspectives/Perspective.d.ts +1 -1
  193. package/lib/src/perspectives/Perspective.js +10 -52
  194. package/lib/src/perspectives/PerspectiveClient.d.ts +12 -15
  195. package/lib/src/perspectives/PerspectiveClient.js +168 -400
  196. package/lib/src/perspectives/PerspectiveClient.test.d.ts +1 -0
  197. package/lib/src/perspectives/PerspectiveClient.test.js +224 -0
  198. package/lib/src/perspectives/PerspectiveDiff.js +4 -31
  199. package/lib/src/perspectives/PerspectiveHandle.js +3 -43
  200. package/lib/src/perspectives/PerspectiveProxy.d.ts +95 -71
  201. package/lib/src/perspectives/PerspectiveProxy.js +288 -310
  202. package/lib/src/runtime/RuntimeClient.d.ts +6 -6
  203. package/lib/src/runtime/RuntimeClient.js +93 -467
  204. package/lib/src/runtime/RuntimeTypes.d.ts +101 -0
  205. package/lib/src/runtime/RuntimeTypes.js +45 -0
  206. package/lib/src/shacl/SHACLShape.d.ts +7 -0
  207. package/lib/src/shacl/SHACLShape.js +19 -0
  208. package/lib/src/shacl/SHACLShape.test.js +82 -0
  209. package/lib/src/typeDefs.js +3 -628
  210. package/package.json +9 -24
  211. package/rollup.config.js +0 -7
  212. package/src/Ad4mClient.test.ts +1182 -1288
  213. package/src/Ad4mClient.ts +30 -15
  214. package/src/agent/Agent.ts +0 -99
  215. package/src/agent/AgentClient.ts +112 -526
  216. package/src/agent/AgentStatus.ts +0 -12
  217. package/src/ai/AIClient.ts +96 -296
  218. package/src/ai/AITypes.ts +66 -0
  219. package/src/ai/Tasks.ts +0 -52
  220. package/src/apiClient.ts +283 -0
  221. package/src/expression/Expression.ts +3 -43
  222. package/src/expression/ExpressionClient.ts +14 -77
  223. package/src/expression/ExpressionRef.ts +0 -6
  224. package/src/generated/api/AIModelLoadingStatus.ts +3 -0
  225. package/src/generated/api/AddLinkExpressionRequest.ts +4 -0
  226. package/src/generated/api/AddLinkRequest.ts +4 -0
  227. package/src/generated/api/AddLinksBulkRequest.ts +4 -0
  228. package/src/generated/api/AddSdnaRequest.ts +3 -0
  229. package/src/generated/api/ApplyTemplateRequest.ts +3 -0
  230. package/src/generated/api/AuthInfoInput.ts +4 -0
  231. package/src/generated/api/CapabilityInput.ts +4 -0
  232. package/src/generated/api/CommitBatchRequest.ts +3 -0
  233. package/src/generated/api/ComputeLogEntry.ts +3 -0
  234. package/src/generated/api/CreateExpressionRequest.ts +3 -0
  235. package/src/generated/api/CreatePerspectiveRequest.ts +3 -0
  236. package/src/generated/api/CreateSubjectRequest.ts +3 -0
  237. package/src/generated/api/EmbedRequest.ts +3 -0
  238. package/src/generated/api/EntanglementProofInput.ts +3 -0
  239. package/src/generated/api/ExecuteCommandsRequest.ts +3 -0
  240. package/src/generated/api/ExportRequest.ts +3 -0
  241. package/src/generated/api/ExpressionManyRequest.ts +3 -0
  242. package/src/generated/api/ExpressionProof.ts +3 -0
  243. package/src/generated/api/ExpressionProofInput.ts +3 -0
  244. package/src/generated/api/FriendSendMessageRequest.ts +3 -0
  245. package/src/generated/api/FriendsListRequest.ts +3 -0
  246. package/src/generated/api/GenerateAgentRequest.ts +3 -0
  247. package/src/generated/api/GenerateJwtRequest.ts +3 -0
  248. package/src/generated/api/GetSubjectDataRequest.ts +3 -0
  249. package/src/generated/api/ImportAgentRequest.ts +3 -0
  250. package/src/generated/api/ImportRequest.ts +3 -0
  251. package/src/generated/api/JoinNeighbourhoodRequest.ts +3 -0
  252. package/src/generated/api/LanguageMetaInput.ts +3 -0
  253. package/src/generated/api/Link.ts +3 -0
  254. package/src/generated/api/LinkExpression.ts +6 -0
  255. package/src/generated/api/LinkExpressionInput.ts +6 -0
  256. package/src/generated/api/LinkInput.ts +3 -0
  257. package/src/generated/api/LinkLanguageTemplatesRequest.ts +3 -0
  258. package/src/generated/api/LinkMutations.ts +5 -0
  259. package/src/generated/api/LinkStatus.ts +3 -0
  260. package/src/generated/api/LockAgentRequest.ts +3 -0
  261. package/src/generated/api/ModelType.ts +3 -0
  262. package/src/generated/api/NotificationInput.ts +3 -0
  263. package/src/generated/api/OpenLinkRequest.ts +3 -0
  264. package/src/generated/api/PermitCapabilityRequest.ts +3 -0
  265. package/src/generated/api/PerspectiveInput.ts +4 -0
  266. package/src/generated/api/PromptRequest.ts +3 -0
  267. package/src/generated/api/PublishLanguageRequest.ts +4 -0
  268. package/src/generated/api/PublishNeighbourhoodRequest.ts +4 -0
  269. package/src/generated/api/QueryRequest.ts +6 -0
  270. package/src/generated/api/RemoveLinkRequest.ts +4 -0
  271. package/src/generated/api/RemoveLinksBulkRequest.ts +4 -0
  272. package/src/generated/api/ResourceInput.ts +3 -0
  273. package/src/generated/api/SetDefaultModelRequest.ts +4 -0
  274. package/src/generated/api/SetFreeHostingEnabledRequest.ts +3 -0
  275. package/src/generated/api/SetMultiUserRequest.ts +3 -0
  276. package/src/generated/api/SetStatusRequest.ts +3 -0
  277. package/src/generated/api/SignMessageRequest.ts +3 -0
  278. package/src/generated/api/TrustedAgentsRequest.ts +3 -0
  279. package/src/generated/api/UnlockAgentRequest.ts +3 -0
  280. package/src/generated/api/UpdateLinkRequest.ts +5 -0
  281. package/src/generated/api/UpdatePerspectiveRequest.ts +3 -0
  282. package/src/generated/api/UserStatistics.ts +3 -0
  283. package/src/generated/api/VerificationRequestResult.ts +3 -0
  284. package/src/generated/api/VerifySignatureRequest.ts +3 -0
  285. package/src/generated/api/WriteSettingsRequest.ts +3 -0
  286. package/src/generated/api/index.ts +49 -0
  287. package/src/index.ts +6 -2
  288. package/src/jestSetup.ts +1 -1
  289. package/src/language/Icon.ts +0 -4
  290. package/src/language/Language.ts +50 -292
  291. package/src/language/LanguageClient.ts +21 -132
  292. package/src/language/LanguageHandle.ts +0 -14
  293. package/src/language/LanguageMeta.ts +0 -29
  294. package/src/language/LanguageRef.ts +0 -7
  295. package/src/links/Links.ts +0 -37
  296. package/src/model/Ad4mModel.test.ts +827 -808
  297. package/src/model/Ad4mModel.ts +676 -457
  298. package/src/model/ModelQueryBuilder.ts +199 -217
  299. package/src/model/decorators.ts +29 -0
  300. package/src/model/hydration.ts +17 -572
  301. package/src/model/index.ts +0 -4
  302. package/src/model/query-sparql.test.ts +360 -0
  303. package/src/model/query-sparql.ts +203 -56
  304. package/src/model/query-utils.ts +4 -0
  305. package/src/model/shacl-gen.ts +5 -0
  306. package/src/model/types.ts +62 -1
  307. package/src/neighbourhood/Neighbourhood.ts +0 -9
  308. package/src/neighbourhood/NeighbourhoodClient.ts +42 -207
  309. package/src/neighbourhood/NeighbourhoodProxy.test.ts +34 -36
  310. package/src/perspectives/LinkQuery.ts +0 -15
  311. package/src/perspectives/Perspective.ts +1 -12
  312. package/src/perspectives/PerspectiveClient.test.ts +262 -0
  313. package/src/perspectives/PerspectiveClient.ts +227 -412
  314. package/src/perspectives/PerspectiveDiff.ts +0 -8
  315. package/src/perspectives/PerspectiveHandle.ts +1 -12
  316. package/src/perspectives/PerspectiveProxy.test.ts +41 -0
  317. package/src/perspectives/PerspectiveProxy.ts +325 -348
  318. package/src/runtime/RuntimeClient.ts +112 -474
  319. package/src/runtime/RuntimeTypes.ts +144 -0
  320. package/src/shacl/SHACLShape.test.ts +94 -0
  321. package/src/shacl/SHACLShape.ts +27 -0
  322. package/src/typeDefs.ts +3 -5
  323. package/tsconfig.json +3 -7
  324. package/lib/src/model/query-surreal.d.ts +0 -44
  325. package/lib/src/model/query-surreal.js +0 -249
  326. package/lib/src/model/surreal-utils.d.ts +0 -42
  327. package/lib/src/model/surreal-utils.js +0 -128
  328. package/shims/reflect-metadata.ts +0 -0
  329. package/shims/type-graphql.ts +0 -75
  330. package/src/PubSub.ts +0 -17
  331. package/src/agent/AgentResolver.ts +0 -263
  332. package/src/ai/AIResolver.ts +0 -372
  333. package/src/buildSchema.ts +0 -43
  334. package/src/expression/ExpressionResolver.ts +0 -64
  335. package/src/language/LanguageContext.ts +0 -37
  336. package/src/language/LanguageResolver.ts +0 -98
  337. package/src/model/Subject.ts +0 -159
  338. package/src/model/hydration-batch.ts +0 -205
  339. package/src/model/prolog-facts.ts +0 -145
  340. package/src/model/query-prolog.ts +0 -148
  341. package/src/model/query-sparql-batch.ts +0 -301
  342. package/src/model/subscription-pool.ts +0 -163
  343. package/src/neighbourhood/NeighbourhoodResolver.ts +0 -100
  344. package/src/perspectives/PerspectiveResolver.ts +0 -364
  345. package/src/runtime/RuntimeResolver.ts +0 -749
  346. package/src/unwrapApolloResult.ts +0 -16
  347. package/tsconfig-browser.json +0 -82
@@ -1,22 +1,21 @@
1
1
  /**
2
2
  * hydration.ts — Instance hydration helpers extracted from Ad4mModel.
3
3
  *
4
- * Pure / stateless functions that populate Ad4mModel instances from
5
- * raw link arrays, Prolog tuples, or query results. None of these
6
- * functions depend on the `Ad4mModel` class at runtime — they accept
7
- * the instance, metadata, or perspective as explicit parameters.
4
+ * After the Rust model_query pipeline migration (Phases 1-13), most hydration
5
+ * logic moved to Rust. This file retains:
6
+ * - normalizeValue() — snapshot dirty-tracking
7
+ * - matchesCondition() — JS-side post-filter (used by evaluateCustomGettersForInstance)
8
+ * - evaluateCustomGettersForInstance() — lazy getter evaluation (Ad4mModel.evaluateGetters)
9
+ * - buildConformanceGetter() — conformance SPARQL generation for relation getters
8
10
  */
9
11
 
10
- import { Literal } from "../Literal";
11
- import { LinkQuery } from "../perspectives/LinkQuery";
12
12
  import type { PerspectiveProxy } from "../perspectives/PerspectiveProxy";
13
- import { getPropertiesMetadata, getRelationsMetadata, buildConformanceFilter } from "./decorators";
14
- import type { RelationMetadataEntry } from "./decorators";
13
+ import { buildConformanceFilter } from "./decorators";
15
14
  import { compileWhereClause } from "./query-utils";
16
15
  import { escapeQueryString } from "../utils";
17
16
  import type {
18
- PropertyMetadata, RelationMetadata, ModelMetadata,
19
- ValueTuple, WhereCondition, IncludeMap, RelationSubQuery,
17
+ RelationMetadata, ModelMetadata,
18
+ WhereCondition,
20
19
  } from "./types";
21
20
 
22
21
  // ──────────────────────────────────────────────────────────
@@ -101,317 +100,6 @@ export function matchesCondition(value: any, condition: WhereCondition): boolean
101
100
  return value === condition;
102
101
  }
103
102
 
104
- // ──────────────────────────────────────────────────────────
105
- // Property / link hydration
106
- // ──────────────────────────────────────────────────────────
107
-
108
- /**
109
- * Resolves a single property value from a raw link target string.
110
- *
111
- * Handles expression resolution, literal URI parsing, primitive
112
- * type coercion, and optional transform functions.
113
- *
114
- * @param target - The raw target string from the link
115
- * @param propMeta - Property metadata from the decorator registry
116
- * @param perspective - The perspective for expression resolution
117
- * @param expectedType - Optional JS typeof hint for coercion (e.g. 'number')
118
- * @returns The resolved value
119
- */
120
- export async function hydratePropertyValue(
121
- target: string,
122
- propMeta: PropertyMetadata,
123
- perspective: PerspectiveProxy,
124
- expectedType?: string,
125
- ): Promise<any> {
126
- let value: any = target;
127
-
128
- if (target !== undefined && target !== null && target !== '') {
129
- // Non-literal expression resolution
130
- if (
131
- propMeta.resolveLanguage != null &&
132
- propMeta.resolveLanguage !== 'literal' &&
133
- typeof target === 'string' &&
134
- !target.startsWith('literal:')
135
- ) {
136
- try {
137
- const expression = await perspective.getExpression(target);
138
- if (expression) {
139
- try { value = JSON.parse(expression.data); } catch { value = expression.data; }
140
- }
141
- } catch (e) {
142
- console.warn(`hydratePropertyValue: failed to resolve expression for "${propMeta.name}":`, e);
143
- }
144
- }
145
- // Literal URI parsing
146
- else if (
147
- propMeta.resolveLanguage === 'literal' &&
148
- typeof target === 'string' &&
149
- target.startsWith('literal:')
150
- ) {
151
- try {
152
- const parsed = Literal.fromUrl(target).get();
153
- value = parsed.data !== undefined ? parsed.data : parsed;
154
- } catch {
155
- // Keep raw value
156
- }
157
- }
158
- // Primitive type coercion
159
- else if (typeof target === 'string' && expectedType) {
160
- if (expectedType === 'number') value = Number(target);
161
- else if (expectedType === 'boolean') value = target === 'true' || target === '1';
162
- }
163
- }
164
-
165
- // Transform function
166
- if (propMeta.transform && typeof propMeta.transform === 'function') {
167
- value = propMeta.transform(value);
168
- }
169
-
170
- return value;
171
- }
172
-
173
- /**
174
- * Hydrates an instance from an array of raw links.
175
- *
176
- * Processes properties (latest-wins semantics), relations
177
- * (chronological accumulation), and timestamps/author in a single
178
- * pass over the links array.
179
- *
180
- * @param instance - The blank model instance to populate
181
- * @param links - Array of link objects (predicate, target, author?, timestamp?)
182
- * @param metadata - Model metadata from `getModelMetadata()`
183
- * @param perspective - The perspective for expression resolution
184
- * @param requestedProperties - Optional sparse fieldset; when provided, only these
185
- * property names are hydrated (relations are unaffected).
186
- * Omit or pass `undefined` to hydrate all properties.
187
- */
188
- export async function hydrateFromLinks(
189
- instance: any,
190
- links: Array<{ predicate: string; target: string; author?: string; timestamp?: string | number }>,
191
- metadata: ModelMetadata,
192
- perspective: PerspectiveProxy,
193
- requestedProperties?: string[],
194
- ): Promise<void> {
195
- if (!links || links.length === 0) return;
196
-
197
- let minTimestamp: string | number | null = null;
198
- let maxTimestamp: string | number | null = null;
199
- let originalAuthor: string | null = null;
200
- let latestAuthor: string | null = null;
201
-
202
- // Build predicate→propName and predicate→relName lookup maps for O(1) matching
203
- // When requestedProperties is provided, only include those properties in the map
204
- const propFilter = requestedProperties && requestedProperties.length > 0
205
- ? new Set(requestedProperties)
206
- : null;
207
-
208
- const predToProperty = new Map<string, [string, PropertyMetadata]>();
209
- for (const [propName, propMeta] of Object.entries(metadata.properties)) {
210
- if (propMeta.getter) continue; // Handled via custom getter evaluation
211
- if (propFilter && !propFilter.has(propName)) continue; // Skip unrequested properties
212
- predToProperty.set(propMeta.predicate, [propName, propMeta]);
213
- }
214
-
215
- const predToRelation = new Map<string, [string, RelationMetadata]>();
216
-
217
- // Two-pass approach: first add all non-getter, non-target-filtered relations,
218
- // then try to add target+filter relations only if their predicate isn't
219
- // already claimed. This prevents predicate collisions (e.g. entries +
220
- // messages sharing the same predicate) while still populating unique-
221
- // predicate relations normally via link hydration.
222
- const deferredTargetRelations: [string, RelationMetadata][] = [];
223
- for (const [relName, relMeta] of Object.entries(metadata.relations)) {
224
- if (relMeta.getter) continue; // Handled via explicit custom getter evaluation
225
- if (relMeta.target && relMeta.filter !== false) {
226
- deferredTargetRelations.push([relName, relMeta]);
227
- continue;
228
- }
229
- predToRelation.set(relMeta.predicate, [relName, relMeta]);
230
- }
231
- // Second pass: add deferred target+filter relations only if their predicate
232
- // is not already claimed by a base relation. When a collision exists, the
233
- // conformance getter will handle the filtered view instead.
234
- for (const [relName, relMeta] of deferredTargetRelations) {
235
- if (!predToRelation.has(relMeta.predicate)) {
236
- predToRelation.set(relMeta.predicate, [relName, relMeta]);
237
- }
238
- }
239
-
240
- // Per-property accumulator: track all matching targets so we can pick the last (latest-wins)
241
- const propertyLatest = new Map<string, { target: string; timestamp?: string | number }>();
242
-
243
- // Per-relation accumulator: ordered targets with metadata for sorting
244
- const relationAccum = new Map<string, Array<{ target: string; timestamp: string | number; index: number }>>();
245
-
246
- // Single pass over all links
247
- for (let i = 0; i < links.length; i++) {
248
- const link = links[i];
249
- const { predicate, target, author, timestamp } = link;
250
- if (target === 'None' || target === undefined || target === null) continue;
251
-
252
- // Track timestamps/authors
253
- if (timestamp != null) {
254
- if (minTimestamp == null || timestamp < minTimestamp) {
255
- minTimestamp = timestamp;
256
- originalAuthor = author ?? null;
257
- }
258
- if (maxTimestamp == null || timestamp > maxTimestamp) {
259
- maxTimestamp = timestamp;
260
- latestAuthor = author ?? null;
261
- }
262
- }
263
-
264
- // Property match — accumulate for latest-wins
265
- const propEntry = predToProperty.get(predicate);
266
- if (propEntry) {
267
- const existing = propertyLatest.get(propEntry[0]);
268
- // Latest-wins: always overwrite (links are ordered ASC so last = latest)
269
- propertyLatest.set(propEntry[0], { target, timestamp });
270
- continue;
271
- }
272
-
273
- // Relation match — accumulate all
274
- const relEntry = predToRelation.get(predicate);
275
- if (relEntry) {
276
- const [relName] = relEntry;
277
- let arr = relationAccum.get(relName);
278
- if (!arr) {
279
- arr = [];
280
- relationAccum.set(relName, arr);
281
- }
282
- arr.push({ target, timestamp: timestamp ?? '', index: i });
283
- }
284
- }
285
-
286
- // Resolve properties
287
- for (const [propName, { target }] of propertyLatest) {
288
- const [, propMeta] = predToProperty.get(
289
- metadata.properties[propName].predicate
290
- )!;
291
- const expectedType = typeof instance[propName];
292
- instance[propName] = await hydratePropertyValue(
293
- target,
294
- propMeta,
295
- perspective,
296
- expectedType !== 'undefined' ? expectedType : undefined,
297
- );
298
- }
299
-
300
- // Resolve relations: sort by timestamp (stable via index tiebreaker), filter empties
301
- for (const [relName, items] of relationAccum) {
302
- items.sort((a, b) => {
303
- const cmp = String(a.timestamp).localeCompare(String(b.timestamp));
304
- return cmp !== 0 ? cmp : a.index - b.index;
305
- });
306
- instance[relName] = items
307
- .map(i => i.target)
308
- .filter((v: any) => v !== undefined && v !== null && v !== '' && v !== 'None');
309
- }
310
-
311
- // Assign author / timestamps
312
- if (originalAuthor) instance.author = originalAuthor;
313
- if (minTimestamp != null) {
314
- instance.createdAt = typeof minTimestamp === 'string' && minTimestamp.includes('T')
315
- ? new Date(minTimestamp).getTime()
316
- : typeof minTimestamp === 'string'
317
- ? (isNaN(parseInt(minTimestamp, 10)) ? minTimestamp : parseInt(minTimestamp, 10))
318
- : minTimestamp;
319
- }
320
- if (maxTimestamp != null) {
321
- instance.updatedAt = typeof maxTimestamp === 'string' && maxTimestamp.includes('T')
322
- ? new Date(maxTimestamp).getTime()
323
- : typeof maxTimestamp === 'string'
324
- ? (isNaN(parseInt(maxTimestamp, 10)) ? maxTimestamp : parseInt(maxTimestamp, 10))
325
- : maxTimestamp;
326
- }
327
- }
328
-
329
- // ──────────────────────────────────────────────────────────
330
- // Prolog result hydration (assignValuesToInstance)
331
- // ──────────────────────────────────────────────────────────
332
-
333
- /**
334
- * Assigns decoded Prolog property values to an instance.
335
- *
336
- * Handles UTF-8 byte sequence reconstruction, expression resolution,
337
- * transform functions, and read-only property filtering.
338
- */
339
- export async function assignValuesToInstance(
340
- perspective: PerspectiveProxy,
341
- instance: any,
342
- values: ValueTuple[],
343
- ): Promise<void> {
344
- // Map properties to object
345
- const propsObject = Object.fromEntries(
346
- await Promise.all(
347
- values.map(async ([name, value, resolve]) => {
348
- let finalValue = value;
349
-
350
- // Handle UTF-8 byte sequences from Prolog URL decoding
351
- if (!resolve && typeof value === 'string') {
352
- // Only attempt reconstruction if the string looks like a byte string (all code points <= 0xFF)
353
- // and contains at least one high byte (>= 0x80). This avoids mangling valid Unicode.
354
- const codePoints = Array.from(value, ch => ch.codePointAt(0)!);
355
- const looksByteString = codePoints.every(cp => cp <= 0xFF);
356
- const hasHighByte = codePoints.some(cp => cp >= 0x80);
357
- if (looksByteString && hasHighByte) {
358
- try {
359
- const bytes = Uint8Array.from(codePoints);
360
- const decoded = new TextDecoder('utf-8', { fatal: true }).decode(bytes);
361
- if (decoded !== value) finalValue = decoded;
362
- } catch (error) {
363
- // If UTF-8 conversion fails, keep the original value
364
- console.warn(`UTF-8 byte reconstruction failed for property "${name}"`, { value, error });
365
- }
366
- }
367
- }
368
-
369
- // Resolve the value if necessary
370
- if (resolve) {
371
- let resolvedExpression = await perspective.getExpression(value);
372
- if (resolvedExpression) {
373
- try {
374
- // Attempt to parse the data as JSON
375
- finalValue = JSON.parse(resolvedExpression.data);
376
- } catch (error) {
377
- // If parsing fails, keep the original data
378
- finalValue = resolvedExpression.data;
379
- }
380
- }
381
- }
382
- // Apply transform function if it exists
383
- const propsMeta = getPropertiesMetadata(instance.constructor);
384
- const transform = propsMeta[name]?.transform;
385
- if (transform && typeof transform === "function") {
386
- finalValue = transform(finalValue);
387
- }
388
- return [name, finalValue];
389
- })
390
- )
391
- );
392
- // Filter out properties that are read-only (getters without setters)
393
- const writableProps = Object.fromEntries(
394
- Object.entries(propsObject).filter(([key]) => {
395
- const descriptor = Object.getOwnPropertyDescriptor(Object.getPrototypeOf(instance), key);
396
- if (!descriptor) {
397
- // No descriptor means it's a regular property on the instance, allow it
398
- return true;
399
- }
400
- // Check if it's an accessor descriptor (has get/set) vs data descriptor (has value/writable)
401
- const isAccessor = descriptor.get !== undefined || descriptor.set !== undefined;
402
- if (isAccessor) {
403
- // Accessor descriptor: only allow if it has a setter
404
- return descriptor.set !== undefined;
405
- } else {
406
- // Data descriptor: only allow if writable is not explicitly false
407
- return descriptor.writable !== false;
408
- }
409
- })
410
- );
411
- // Assign properties to instance
412
- Object.assign(instance, writableProps);
413
- }
414
-
415
103
  // ──────────────────────────────────────────────────────────
416
104
  // SPARQL custom getter evaluation
417
105
  // ──────────────────────────────────────────────────────────
@@ -456,7 +144,7 @@ export async function evaluateCustomGettersForInstance(
456
144
  instance: any,
457
145
  perspective: PerspectiveProxy,
458
146
  metadata: ModelMetadata,
459
- options?: { requestedProperties?: string[]; include?: Record<string, any> }
147
+ options?: { requestedProperties?: string[]; include?: Record<string, any>; skipPropertyGetters?: boolean }
460
148
  ): Promise<void> {
461
149
  const safeBaseExpression = `<${instance.id}>`;
462
150
 
@@ -465,7 +153,8 @@ export async function evaluateCustomGettersForInstance(
465
153
  const projectionActive = options?.requestedProperties && options.requestedProperties.length > 0;
466
154
  const projectionSet = projectionActive ? new Set(options!.requestedProperties) : null;
467
155
 
468
- // Evaluate property getters
156
+ // Evaluate property getters (skip when caller only wants relation type-filtering)
157
+ if (!options?.skipPropertyGetters) {
469
158
  for (const [propName, propMeta] of Object.entries(metadata.properties)) {
470
159
  if (projectionSet && !projectionSet.has(propName)) continue;
471
160
  if ((propMeta as any).getter) {
@@ -489,7 +178,8 @@ export async function evaluateCustomGettersForInstance(
489
178
  }
490
179
  }
491
180
  } else {
492
- // Legacy SurrealDB-style getter — no longer supported
181
+ // Legacy SurrealDB-style getter — safety guard for getters that don't match
182
+ // SPARQL patterns (SELECT/ASK). Logs a warning but does not crash.
493
183
  console.warn(`Unsupported legacy getter syntax for property ${propName} — use native SPARQL (SELECT/ASK): ${rawGetter.slice(0, 100)}`);
494
184
  }
495
185
  } catch (error) {
@@ -497,6 +187,7 @@ export async function evaluateCustomGettersForInstance(
497
187
  }
498
188
  }
499
189
  }
190
+ } // end skipPropertyGetters guard
500
191
 
501
192
  // Evaluate relation getters (explicit or auto-generated from target)
502
193
  for (const [relName, relMeta] of Object.entries(metadata.relations)) {
@@ -576,7 +267,8 @@ export async function evaluateCustomGettersForInstance(
576
267
  instance[relName] = values;
577
268
  }
578
269
  } else {
579
- // Legacy SurrealDB-style getter — no longer supported
270
+ // Legacy SurrealDB-style getter — safety guard for relation getters that don't
271
+ // match SPARQL patterns (SELECT/ASK). Logs a warning but does not crash.
580
272
  console.warn(`Unsupported legacy getter syntax for relation ${relName} — use native SPARQL (SELECT/ASK): ${getter.slice(0, 100)}`);
581
273
  }
582
274
  } catch (error) {
@@ -610,250 +302,3 @@ export async function evaluateCustomGettersForInstance(
610
302
  }
611
303
  }
612
304
  }
613
-
614
- /**
615
- * Hydrates relation fields on instances according to the provided IncludeMap.
616
- *
617
- * For each relation listed in `includeMap`, the raw expression-URI strings
618
- * stored on the instance are replaced with fully-hydrated model instances
619
- * (fetched via the relation's `target()` class). Nested IncludeMaps are
620
- * supported for multi-level eager loading.
621
- *
622
- * @param modelClass - The model class whose relation metadata to read
623
- * @param instances - The instances whose relations should be hydrated
624
- * @param perspective - The perspective to fetch related instances from
625
- * @param includeMap - Describes which relations to hydrate
626
- */
627
- export async function hydrateRelations<T>(
628
- modelClass: any,
629
- instances: T[],
630
- perspective: PerspectiveProxy,
631
- includeMap: IncludeMap | undefined,
632
- ): Promise<void> {
633
- if (!includeMap || Object.keys(includeMap).length === 0) return;
634
-
635
- const relMeta = getRelationsMetadata(modelClass);
636
-
637
- for (const [relName, includeValue] of Object.entries(includeMap)) {
638
- const meta: RelationMetadataEntry | undefined = relMeta[relName];
639
- if (!meta) {
640
- console.warn(`include: relation "${relName}" not found in metadata, skipping`);
641
- continue;
642
- }
643
-
644
- const TargetClass = meta.target() as any;
645
-
646
- // Determine if a RelationSubQuery was supplied (object) vs a plain `true`
647
- const subQuery: RelationSubQuery | undefined =
648
- typeof includeValue === 'object' && includeValue !== null
649
- ? (includeValue as RelationSubQuery)
650
- : undefined;
651
- const nestedInclude: IncludeMap | undefined = subQuery?.include;
652
-
653
- // ── Reverse relations (belongsToOne / belongsToMany) ──────────────────
654
- // The link goes target→instance, so we query backwards:
655
- // predicate = meta.predicate, target = inst.id → source is the related id
656
- if (meta.kind === 'belongsToOne' || meta.kind === 'belongsToMany') {
657
- // Per-instance reverse lookup (can't batch easily across instances)
658
- for (const inst of instances) {
659
- const reverseLinks = await perspective.get(
660
- new LinkQuery({ predicate: meta.predicate, target: (inst as any).id })
661
- );
662
- // Defensive filter: perspective.get may return extra results; ensure
663
- // we only use links that genuinely point to this instance.
664
- const sourceIds = reverseLinks
665
- .filter(l => l.data.target === (inst as any).id)
666
- .map(l => l.data.source);
667
-
668
- if (meta.kind === 'belongsToOne') {
669
- if (sourceIds.length === 0) {
670
- (inst as any)[relName] = null;
671
- continue;
672
- }
673
- const sourceId = sourceIds[sourceIds.length - 1]; // latest-wins
674
- try {
675
- const related = new TargetClass(perspective, sourceId);
676
- await related.get();
677
- (inst as any)[relName] = related;
678
- } catch {
679
- (inst as any)[relName] = null;
680
- }
681
- } else {
682
- // belongsToMany — return array of hydrated instances
683
- let hydrated: any[] = [];
684
-
685
- // If there's a where/order sub-query, delegate to findAll for filtering
686
- if (subQuery && (subQuery.where || subQuery.order || subQuery.properties)) {
687
- const whereWithIds: Record<string, any> = {
688
- id: sourceIds,
689
- ...(subQuery.where ?? {}),
690
- };
691
- hydrated = await TargetClass.findAll(perspective, {
692
- where: whereWithIds as any,
693
- ...(subQuery.order && { order: subQuery.order as any }),
694
- ...(subQuery.properties && { properties: subQuery.properties }),
695
- });
696
- } else {
697
- await Promise.all(sourceIds.map(async (sid: string) => {
698
- try {
699
- const related = new TargetClass(perspective, sid);
700
- await related.get(
701
- subQuery?.properties ? { properties: subQuery.properties } : undefined
702
- );
703
- hydrated.push(related);
704
- } catch { /* skip */ }
705
- }));
706
- }
707
-
708
- // Apply order (client-side, if not already handled by findAll above)
709
- if (subQuery?.order && !(subQuery.where || subQuery.properties)) {
710
- const orderEntries = Object.entries(subQuery.order);
711
- hydrated = hydrated.sort((a: any, b: any) => {
712
- for (const [field, dir] of orderEntries) {
713
- const av = String(a[field] ?? '');
714
- const bv = String(b[field] ?? '');
715
- const diff = av.localeCompare(bv);
716
- if (diff !== 0) return dir === 'DESC' ? -diff : diff;
717
- }
718
- return 0;
719
- });
720
- }
721
-
722
- // Apply offset and limit
723
- if (subQuery?.offset != null || subQuery?.limit != null) {
724
- const start = subQuery.offset ?? 0;
725
- const end = subQuery.limit != null ? start + subQuery.limit : undefined;
726
- hydrated = hydrated.slice(start, end);
727
- }
728
-
729
- (inst as any)[relName] = hydrated;
730
-
731
- // Recurse for nested includes
732
- if (nestedInclude && hydrated.length > 0) {
733
- await hydrateRelations(TargetClass, hydrated, perspective, nestedInclude);
734
- }
735
- }
736
- }
737
- continue; // skip the forward-relation path below
738
- }
739
-
740
- // ── Forward relations (hasMany / hasOne) ──────────────────────────────
741
- // Collect all unique URIs across all instances for batch-friendly lookup.
742
- // IMPORTANT: We cache each instance's raw value NOW (before the async
743
- // findAll) so that concurrent getData() calls on the same instance can't
744
- // overwrite the relation field between the uriSet relation and the
745
- // post-await assignment loop. Without this cache, a concurrent call
746
- // can replace the raw URI strings with hydrated model objects, causing
747
- // the `typeof v === 'string'` check to fail and the array to end up empty.
748
- const uriSet = new Set<string>();
749
- const rawCache = new Map<T, any>();
750
- for (const inst of instances) {
751
- const raw = (inst as any)[relName];
752
- rawCache.set(inst, Array.isArray(raw) ? [...raw] : raw);
753
- if (raw == null) continue;
754
- if (Array.isArray(raw)) {
755
- for (const v of raw) {
756
- if (typeof v === 'string') uriSet.add(v);
757
- // Handle already-hydrated instances (from a concurrent call)
758
- else if (v && typeof v === 'object' && typeof v.id === 'string') uriSet.add(v.id);
759
- }
760
- } else if (typeof raw === 'string') {
761
- uriSet.add(raw);
762
- } else if (raw && typeof raw === 'object' && typeof raw.id === 'string') {
763
- uriSet.add(raw.id);
764
- }
765
- }
766
-
767
- if (uriSet.size === 0) continue;
768
-
769
- // Hydrate related instances using findAll to ensure conformance checking.
770
- // findAll validates model membership via graph traversal (required predicates / flags),
771
- // so non-conforming linked URIs are silently dropped — matching the documented behaviour.
772
- const hydrated = new Map<string, any>();
773
-
774
- const whereWithIds: Record<string, any> = {
775
- id: Array.from(uriSet),
776
- ...(subQuery?.where ?? {}),
777
- };
778
- const fetchQuery: any = {
779
- where: whereWithIds,
780
- ...(subQuery?.order && { order: subQuery.order }),
781
- ...(subQuery?.properties && { properties: subQuery.properties }),
782
- };
783
- const results = await TargetClass.findAll(perspective, fetchQuery);
784
- for (const result of results) {
785
- hydrated.set(result.id, result);
786
- }
787
-
788
- // Replace raw URIs with hydrated instances on each parent instance.
789
- // Use the cached raw values captured BEFORE the async findAll to avoid
790
- // the race condition where a concurrent getData() already replaced the
791
- // strings with hydrated objects.
792
- for (const inst of instances) {
793
- const raw = rawCache.get(inst);
794
- if (raw == null) continue;
795
- if (Array.isArray(raw)) {
796
- // Map URIs → instances; handle both raw strings and already-hydrated objects
797
- let resolved: any[] = raw
798
- .map((v: any) => {
799
- if (typeof v === 'string') {
800
- return hydrated.has(v) ? hydrated.get(v)! : null;
801
- }
802
- // Already a hydrated model instance (from a concurrent call)
803
- if (v && typeof v === 'object' && typeof v.id === 'string') {
804
- return hydrated.has(v.id) ? hydrated.get(v.id)! : v;
805
- }
806
- return null;
807
- })
808
- .filter((v: any): v is any => v !== null);
809
-
810
- // Per-instance sort (client-side, after filtering)
811
- if (subQuery?.order) {
812
- const orderEntries = Object.entries(subQuery.order);
813
- resolved = resolved.sort((a: any, b: any) => {
814
- for (const [field, dir] of orderEntries) {
815
- const av = String(a[field] ?? '');
816
- const bv = String(b[field] ?? '');
817
- const diff = av.localeCompare(bv);
818
- if (diff !== 0) return dir === 'DESC' ? -diff : diff;
819
- }
820
- return 0;
821
- });
822
- }
823
-
824
- // Per-instance limit / offset
825
- if (subQuery?.offset != null || subQuery?.limit != null) {
826
- const start = subQuery.offset ?? 0;
827
- const end =
828
- subQuery.limit != null ? start + subQuery.limit : undefined;
829
- resolved = resolved.slice(start, end);
830
- }
831
-
832
- // Enforce maxCount guard — single-valued relations keep only the last item
833
- if (meta.maxCount === 1) {
834
- if (resolved.length > 1) {
835
- console.warn(
836
- `include: relation "${relName}" has maxCount 1 but ${resolved.length} values found; keeping the last`,
837
- );
838
- }
839
- (inst as any)[relName] = resolved.length > 0
840
- ? resolved[resolved.length - 1]
841
- : null;
842
- } else {
843
- (inst as any)[relName] = resolved;
844
- }
845
- } else if (typeof raw === 'string' && hydrated.has(raw)) {
846
- (inst as any)[relName] = hydrated.get(raw);
847
- } else if (raw && typeof raw === 'object' && typeof raw.id === 'string') {
848
- // Already-hydrated object — look up refreshed version or keep as-is
849
- (inst as any)[relName] = hydrated.has(raw.id) ? hydrated.get(raw.id) : raw;
850
- }
851
- }
852
-
853
- // Recurse for nested includes
854
- if (nestedInclude) {
855
- const hydratedInstances = Array.from(hydrated.values());
856
- await hydrateRelations(TargetClass, hydratedInstances, perspective, nestedInclude);
857
- }
858
- }
859
- }
@@ -9,10 +9,7 @@
9
9
  export * from "./types";
10
10
  export * from "./Ad4mModel";
11
11
  export * from "./decorators";
12
- export * from "./Subject";
13
12
  export * from "./query-common";
14
- export * from "./query-prolog";
15
- export * from "./prolog-facts";
16
13
  export * from "./json-schema";
17
14
  export * from "./query-utils";
18
15
  export * from "./query-sparql";
@@ -21,4 +18,3 @@ export * from "./ModelQueryBuilder";
21
18
  export * from "./sdna";
22
19
  export * from "./shacl-gen";
23
20
  export * from "./query-cache";
24
- export * from "./subscription-pool";