@coasys/ad4m 0.12.0 → 0.13.0-postmessage-ws-proxy.0

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 (388) hide show
  1. package/README.md +2 -25
  2. package/jest-setup.ts +1 -1
  3. package/lib/index.cjs +7444 -13939
  4. package/lib/index.js +5322 -11888
  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 -373
  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 +7 -2
  153. package/lib/src/index.js +7 -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 +150 -62
  166. package/lib/src/model/Ad4mModel.js +689 -417
  167. package/lib/src/model/Ad4mModel.test.js +1434 -688
  168. package/lib/src/model/ModelQueryBuilder.d.ts +59 -38
  169. package/lib/src/model/ModelQueryBuilder.js +317 -153
  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 +46 -18
  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 +60 -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 +189 -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 +156 -78
  220. package/lib/src/perspectives/PerspectiveProxy.js +474 -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/WakerSubscriptionManager.d.ts +3 -3
  224. package/lib/src/perspectives/WakerSubscriptionManager.js +12 -12
  225. package/lib/src/runtime/RuntimeClient.d.ts +34 -6
  226. package/lib/src/runtime/RuntimeClient.js +131 -362
  227. package/lib/src/runtime/RuntimeResolver.d.ts +28 -1
  228. package/lib/src/runtime/RuntimeResolver.js +197 -4
  229. package/lib/src/runtime/RuntimeTypes.d.ts +101 -0
  230. package/lib/src/runtime/RuntimeTypes.js +45 -0
  231. package/lib/src/schema.gql +27 -1
  232. package/lib/src/shacl/SHACLFlow.d.ts +1 -1
  233. package/lib/src/shacl/SHACLFlow.js +9 -9
  234. package/lib/src/shacl/SHACLShape.d.ts +8 -1
  235. package/lib/src/shacl/SHACLShape.js +57 -38
  236. package/lib/src/shacl/SHACLShape.test.js +82 -0
  237. package/lib/src/typeDefs.js +3 -602
  238. package/lib/src/utils.d.ts +6 -6
  239. package/lib/src/utils.js +6 -6
  240. package/package.json +6 -18
  241. package/rollup.config.js +0 -7
  242. package/src/Ad4mClient.test.ts +1192 -1288
  243. package/src/Ad4mClient.ts +46 -15
  244. package/src/Literal.test.ts +10 -5
  245. package/src/Literal.ts +6 -5
  246. package/src/agent/Agent.ts +0 -99
  247. package/src/agent/AgentClient.ts +238 -465
  248. package/src/agent/AgentStatus.ts +0 -12
  249. package/src/ai/AIClient.ts +96 -296
  250. package/src/ai/AITypes.ts +66 -0
  251. package/src/ai/Tasks.ts +0 -52
  252. package/src/apiClient.ts +287 -0
  253. package/src/cache/PersistentCache.ts +145 -0
  254. package/src/cache/cache.test.ts +713 -0
  255. package/src/expression/Expression.ts +3 -43
  256. package/src/expression/ExpressionClient.ts +148 -77
  257. package/src/expression/ExpressionRef.ts +2 -8
  258. package/src/generated/api/AIModelLoadingStatus.ts +3 -0
  259. package/src/generated/api/AddLinkExpressionRequest.ts +4 -0
  260. package/src/generated/api/AddLinkRequest.ts +4 -0
  261. package/src/generated/api/AddLinksBulkRequest.ts +4 -0
  262. package/src/generated/api/AddSdnaRequest.ts +3 -0
  263. package/src/generated/api/ApplyTemplateRequest.ts +3 -0
  264. package/src/generated/api/AuthInfoInput.ts +4 -0
  265. package/src/generated/api/CapabilityInput.ts +4 -0
  266. package/src/generated/api/CommitBatchRequest.ts +3 -0
  267. package/src/generated/api/ComputeLogEntry.ts +3 -0
  268. package/src/generated/api/CreateExpressionRequest.ts +3 -0
  269. package/src/generated/api/CreatePerspectiveRequest.ts +3 -0
  270. package/src/generated/api/CreateSubjectRequest.ts +3 -0
  271. package/src/generated/api/EmbedRequest.ts +3 -0
  272. package/src/generated/api/EntanglementProofInput.ts +3 -0
  273. package/src/generated/api/ExecuteCommandsRequest.ts +3 -0
  274. package/src/generated/api/ExportRequest.ts +3 -0
  275. package/src/generated/api/ExpressionManyRequest.ts +3 -0
  276. package/src/generated/api/ExpressionProof.ts +3 -0
  277. package/src/generated/api/ExpressionProofInput.ts +3 -0
  278. package/src/generated/api/FriendSendMessageRequest.ts +3 -0
  279. package/src/generated/api/FriendsListRequest.ts +3 -0
  280. package/src/generated/api/GenerateAgentRequest.ts +3 -0
  281. package/src/generated/api/GenerateJwtRequest.ts +3 -0
  282. package/src/generated/api/GetSubjectDataRequest.ts +3 -0
  283. package/src/generated/api/ImportAgentRequest.ts +3 -0
  284. package/src/generated/api/ImportRequest.ts +3 -0
  285. package/src/generated/api/JoinNeighbourhoodRequest.ts +3 -0
  286. package/src/generated/api/LanguageMetaInput.ts +3 -0
  287. package/src/generated/api/Link.ts +3 -0
  288. package/src/generated/api/LinkExpression.ts +6 -0
  289. package/src/generated/api/LinkExpressionInput.ts +6 -0
  290. package/src/generated/api/LinkInput.ts +3 -0
  291. package/src/generated/api/LinkLanguageTemplatesRequest.ts +3 -0
  292. package/src/generated/api/LinkMutations.ts +5 -0
  293. package/src/generated/api/LinkStatus.ts +3 -0
  294. package/src/generated/api/LockAgentRequest.ts +3 -0
  295. package/src/generated/api/ModelType.ts +3 -0
  296. package/src/generated/api/NotificationInput.ts +3 -0
  297. package/src/generated/api/OpenLinkRequest.ts +3 -0
  298. package/src/generated/api/PermitCapabilityRequest.ts +3 -0
  299. package/src/generated/api/PerspectiveInput.ts +4 -0
  300. package/src/generated/api/PromptRequest.ts +3 -0
  301. package/src/generated/api/PublishLanguageRequest.ts +4 -0
  302. package/src/generated/api/PublishNeighbourhoodRequest.ts +4 -0
  303. package/src/generated/api/QueryRequest.ts +6 -0
  304. package/src/generated/api/RemoveLinkRequest.ts +4 -0
  305. package/src/generated/api/RemoveLinksBulkRequest.ts +4 -0
  306. package/src/generated/api/ResourceInput.ts +3 -0
  307. package/src/generated/api/SetDefaultModelRequest.ts +4 -0
  308. package/src/generated/api/SetFreeHostingEnabledRequest.ts +3 -0
  309. package/src/generated/api/SetMultiUserRequest.ts +3 -0
  310. package/src/generated/api/SetStatusRequest.ts +3 -0
  311. package/src/generated/api/SignMessageRequest.ts +3 -0
  312. package/src/generated/api/TrustedAgentsRequest.ts +3 -0
  313. package/src/generated/api/UnlockAgentRequest.ts +3 -0
  314. package/src/generated/api/UpdateLinkRequest.ts +5 -0
  315. package/src/generated/api/UpdatePerspectiveRequest.ts +3 -0
  316. package/src/generated/api/UserStatistics.ts +3 -0
  317. package/src/generated/api/VerificationRequestResult.ts +3 -0
  318. package/src/generated/api/VerifySignatureRequest.ts +3 -0
  319. package/src/generated/api/WriteSettingsRequest.ts +3 -0
  320. package/src/generated/api/index.ts +49 -0
  321. package/src/index.ts +7 -2
  322. package/src/jestSetup.ts +1 -1
  323. package/src/language/Icon.ts +0 -4
  324. package/src/language/Language.ts +51 -248
  325. package/src/language/LanguageClient.ts +21 -132
  326. package/src/language/LanguageHandle.ts +0 -14
  327. package/src/language/LanguageMeta.ts +0 -29
  328. package/src/language/LanguageRef.ts +0 -7
  329. package/src/links/Links.ts +0 -37
  330. package/src/model/Ad4mModel.test.ts +1690 -777
  331. package/src/model/Ad4mModel.ts +749 -477
  332. package/src/model/ModelQueryBuilder.ts +356 -171
  333. package/src/model/decorators.ts +71 -22
  334. package/src/model/hydration.ts +3 -772
  335. package/src/model/index.ts +3 -4
  336. package/src/model/json-schema.ts +2 -2
  337. package/src/model/query-cache.test.ts +54 -0
  338. package/src/model/query-cache.ts +79 -0
  339. package/src/model/query-common.ts +1 -1
  340. package/src/model/query-sparql.test.ts +376 -0
  341. package/src/model/query-sparql.ts +504 -0
  342. package/src/model/query-utils.ts +209 -0
  343. package/src/model/relation-filtering.test.ts +15 -15
  344. package/src/model/sdna.ts +1 -1
  345. package/src/model/shacl-gen.ts +47 -17
  346. package/src/model/types.ts +65 -5
  347. package/src/neighbourhood/Neighbourhood.ts +0 -9
  348. package/src/neighbourhood/NeighbourhoodClient.ts +42 -207
  349. package/src/neighbourhood/NeighbourhoodProxy.test.ts +34 -36
  350. package/src/perspectives/LinkQuery.ts +0 -15
  351. package/src/perspectives/Perspective.ts +1 -12
  352. package/src/perspectives/PerspectiveClient.test.ts +262 -0
  353. package/src/perspectives/PerspectiveClient.ts +254 -468
  354. package/src/perspectives/PerspectiveDiff.ts +0 -8
  355. package/src/perspectives/PerspectiveHandle.ts +1 -12
  356. package/src/perspectives/PerspectiveProxy.test.ts +125 -0
  357. package/src/perspectives/PerspectiveProxy.ts +522 -434
  358. package/src/perspectives/WakerSubscriptionManager.ts +13 -13
  359. package/src/runtime/RuntimeClient.ts +166 -369
  360. package/src/runtime/RuntimeTypes.ts +144 -0
  361. package/src/shacl/SHACLFlow.ts +9 -9
  362. package/src/shacl/SHACLShape.test.ts +94 -0
  363. package/src/shacl/SHACLShape.ts +66 -39
  364. package/src/typeDefs.ts +3 -5
  365. package/src/utils.ts +6 -6
  366. package/tsconfig.json +3 -7
  367. package/lib/src/model/query-surreal.d.ts +0 -44
  368. package/lib/src/model/query-surreal.js +0 -249
  369. package/lib/src/model/surreal-utils.js +0 -128
  370. package/shims/reflect-metadata.ts +0 -0
  371. package/shims/type-graphql.ts +0 -75
  372. package/src/PubSub.ts +0 -17
  373. package/src/agent/AgentResolver.ts +0 -263
  374. package/src/ai/AIResolver.ts +0 -372
  375. package/src/buildSchema.ts +0 -43
  376. package/src/expression/ExpressionResolver.ts +0 -64
  377. package/src/language/LanguageContext.ts +0 -37
  378. package/src/language/LanguageResolver.ts +0 -98
  379. package/src/model/Subject.ts +0 -159
  380. package/src/model/prolog-facts.ts +0 -145
  381. package/src/model/query-prolog.ts +0 -148
  382. package/src/model/query-surreal.ts +0 -280
  383. package/src/model/surreal-utils.ts +0 -147
  384. package/src/neighbourhood/NeighbourhoodResolver.ts +0 -100
  385. package/src/perspectives/PerspectiveResolver.ts +0 -372
  386. package/src/runtime/RuntimeResolver.ts +0 -617
  387. package/src/unwrapApolloResult.ts +0 -16
  388. package/tsconfig-browser.json +0 -82
@@ -8,13 +8,12 @@
8
8
  export * from "./types";
9
9
  export * from "./Ad4mModel";
10
10
  export * from "./decorators";
11
- export * from "./Subject";
12
11
  export * from "./query-common";
13
- export * from "./query-prolog";
14
- export * from "./prolog-facts";
15
12
  export * from "./json-schema";
16
- export * from "./query-surreal";
13
+ export * from "./query-utils";
14
+ export * from "./query-sparql";
17
15
  export * from "./hydration";
18
16
  export * from "./ModelQueryBuilder";
19
17
  export * from "./sdna";
20
18
  export * from "./shacl-gen";
19
+ export * from "./query-cache";
@@ -8,13 +8,12 @@
8
8
  export * from "./types";
9
9
  export * from "./Ad4mModel";
10
10
  export * from "./decorators";
11
- export * from "./Subject";
12
11
  export * from "./query-common";
13
- export * from "./query-prolog";
14
- export * from "./prolog-facts";
15
12
  export * from "./json-schema";
16
- export * from "./query-surreal";
13
+ export * from "./query-utils";
14
+ export * from "./query-sparql";
17
15
  export * from "./hydration";
18
16
  export * from "./ModelQueryBuilder";
19
17
  export * from "./sdna";
20
18
  export * from "./shacl-gen";
19
+ export * from "./query-cache";
@@ -263,14 +263,14 @@ export function buildModelFromJSONSchema(BaseClass, schema, options) {
263
263
  }
264
264
  // Default resolveLanguage to 'literal' for all remaining property types,
265
265
  // matching the @Property decorator behaviour. Without this, string values
266
- // stored as literal:// URLs are returned unparsed.
266
+ // stored as literal: URLs are returned unparsed.
267
267
  if (resolveLanguage === undefined || resolveLanguage === null) {
268
268
  resolveLanguage = 'literal';
269
269
  }
270
270
  // If property is required, ensure it has an initial value
271
271
  if (isRequired && !initial) {
272
272
  if (isObjectType(propertySchema)) {
273
- initial = 'literal://json:{}';
273
+ initial = 'literal:json:{}';
274
274
  }
275
275
  else {
276
276
  initial = "ad4m://undefined";
@@ -0,0 +1,41 @@
1
+ /**
2
+ * Types for the perspective model manifest — a human-readable, AI-friendly summary
3
+ * of all Ad4mModel-compatible classes defined in a perspective's SHACL shapes.
4
+ *
5
+ * Used by `PerspectiveProxy.getModelManifest()` and consumed by WE's AI context
6
+ * injection (`formatManifestForPrompt`) to describe external perspective models
7
+ * to the schema-generation AI.
8
+ *
9
+ * @module
10
+ */
11
+ /** Normalised description of a single property on a model class. */
12
+ export interface ModelManifestProperty {
13
+ /** Property name as declared in the SHACL shape (e.g. "name", "body", "participants"). */
14
+ name: string;
15
+ /** The exact RDF predicate URI (e.g. "flux://has_name"). */
16
+ predicate: string;
17
+ /** Normalised scalar type; inferred from xsd:/sh: datatype + nodeKind. */
18
+ type: 'string' | 'number' | 'boolean' | 'uri';
19
+ /** `true` when maxCount is absent or > 1 (i.e. returned as an array). */
20
+ isCollection: boolean;
21
+ /** `true` when minCount >= 1. */
22
+ required: boolean;
23
+ writable: boolean;
24
+ /** AD4M language used to resolve the value (e.g. "literal"). */
25
+ resolveLanguage?: string;
26
+ /**
27
+ * Local name of the related model class when this is a typed relation property.
28
+ * Derived from `SHACLPropertyShape.class` by stripping the URI prefix.
29
+ * E.g. `flux://Message` → `"Message"`.
30
+ */
31
+ relatedModel?: string;
32
+ }
33
+ /** Normalised description of a single model class stored in a perspective. */
34
+ export interface ModelManifestEntry {
35
+ /** Class name — usable directly as the `model` field in a `$query` token. */
36
+ name: string;
37
+ /** The SHACL `targetClass` URI (e.g. "flux://Channel"). */
38
+ targetClass: string;
39
+ /** All data properties (flag/hasValue properties are excluded). */
40
+ properties: ModelManifestProperty[];
41
+ }
@@ -0,0 +1,11 @@
1
+ /**
2
+ * Types for the perspective model manifest — a human-readable, AI-friendly summary
3
+ * of all Ad4mModel-compatible classes defined in a perspective's SHACL shapes.
4
+ *
5
+ * Used by `PerspectiveProxy.getModelManifest()` and consumed by WE's AI context
6
+ * injection (`formatManifestForPrompt`) to describe external perspective models
7
+ * to the schema-generation AI.
8
+ *
9
+ * @module
10
+ */
11
+ export {};
@@ -0,0 +1,30 @@
1
+ /**
2
+ * Query Result TTL Cache
3
+ *
4
+ * Short-lived cache (200ms TTL) for SPARQL query results.
5
+ * Prevents redundant queries during rapid render cycles where
6
+ * multiple components issue the same query within milliseconds.
7
+ *
8
+ * Key: `perspectiveUUID + queryText`
9
+ */
10
+ /**
11
+ * Get a cached query result if it exists and hasn't expired.
12
+ */
13
+ export declare function getCachedResult(perspectiveUUID: string, queryText: string): any | undefined;
14
+ /**
15
+ * Store a query result in the cache with TTL.
16
+ */
17
+ export declare function setCachedResult(perspectiveUUID: string, queryText: string, result: any, ttlMs?: number): void;
18
+ /**
19
+ * Invalidate all cache entries for a given perspective.
20
+ * Called after write operations to ensure stale data isn't served.
21
+ */
22
+ export declare function invalidatePerspectiveCache(perspectiveUUID: string): void;
23
+ /**
24
+ * Clear all cache entries (useful for testing).
25
+ */
26
+ export declare function clearQueryCache(): void;
27
+ /**
28
+ * Get the current size of the cache (useful for testing).
29
+ */
30
+ export declare function queryCacheSize(): number;
@@ -0,0 +1,66 @@
1
+ /**
2
+ * Query Result TTL Cache
3
+ *
4
+ * Short-lived cache (200ms TTL) for SPARQL query results.
5
+ * Prevents redundant queries during rapid render cycles where
6
+ * multiple components issue the same query within milliseconds.
7
+ *
8
+ * Key: `perspectiveUUID + queryText`
9
+ */
10
+ const cache = new Map();
11
+ const DEFAULT_TTL_MS = 200;
12
+ function makeKey(perspectiveUUID, queryText) {
13
+ return `${perspectiveUUID}:${queryText}`;
14
+ }
15
+ /**
16
+ * Get a cached query result if it exists and hasn't expired.
17
+ */
18
+ export function getCachedResult(perspectiveUUID, queryText) {
19
+ const key = makeKey(perspectiveUUID, queryText);
20
+ const entry = cache.get(key);
21
+ if (!entry)
22
+ return undefined;
23
+ if (Date.now() > entry.expiry) {
24
+ cache.delete(key);
25
+ return undefined;
26
+ }
27
+ return entry.result;
28
+ }
29
+ /**
30
+ * Store a query result in the cache with TTL.
31
+ */
32
+ export function setCachedResult(perspectiveUUID, queryText, result, ttlMs = DEFAULT_TTL_MS) {
33
+ // Lazy eviction of expired entries
34
+ const now = Date.now();
35
+ for (const [key, entry] of cache) {
36
+ if (now > entry.expiry) {
37
+ cache.delete(key);
38
+ }
39
+ }
40
+ const cacheKey = makeKey(perspectiveUUID, queryText);
41
+ cache.set(cacheKey, { result, expiry: now + ttlMs });
42
+ }
43
+ /**
44
+ * Invalidate all cache entries for a given perspective.
45
+ * Called after write operations to ensure stale data isn't served.
46
+ */
47
+ export function invalidatePerspectiveCache(perspectiveUUID) {
48
+ const prefix = perspectiveUUID + ':';
49
+ for (const [key] of cache) {
50
+ if (key.startsWith(prefix)) {
51
+ cache.delete(key);
52
+ }
53
+ }
54
+ }
55
+ /**
56
+ * Clear all cache entries (useful for testing).
57
+ */
58
+ export function clearQueryCache() {
59
+ cache.clear();
60
+ }
61
+ /**
62
+ * Get the current size of the cache (useful for testing).
63
+ */
64
+ export function queryCacheSize() {
65
+ return cache.size;
66
+ }
@@ -0,0 +1 @@
1
+ export {};
@@ -0,0 +1,43 @@
1
+ import { getCachedResult, setCachedResult, invalidatePerspectiveCache, clearQueryCache, queryCacheSize } from './query-cache';
2
+ describe('query-cache', () => {
3
+ beforeEach(() => {
4
+ clearQueryCache();
5
+ });
6
+ describe('lazy eviction', () => {
7
+ it('should remove expired entries when setting a new one', () => {
8
+ // Insert with a very short TTL
9
+ setCachedResult('p1', 'SELECT ?x', 'result1', 1);
10
+ expect(queryCacheSize()).toBe(1);
11
+ // Wait for expiry
12
+ const start = Date.now();
13
+ while (Date.now() - start < 5) { /* busy wait 5ms */ }
14
+ // Expired entry should still be in the map (not yet evicted)
15
+ // but getCachedResult should return undefined
16
+ expect(getCachedResult('p1', 'SELECT ?x')).toBeUndefined();
17
+ // Setting a new entry should evict the expired one
18
+ setCachedResult('p2', 'SELECT ?y', 'result2', 10000);
19
+ // Only the new entry should remain
20
+ expect(queryCacheSize()).toBe(1);
21
+ expect(getCachedResult('p2', 'SELECT ?y')).toBe('result2');
22
+ });
23
+ });
24
+ describe('invalidatePerspectiveCache', () => {
25
+ it('should remove all entries for a specific perspective', () => {
26
+ setCachedResult('p1', 'query1', 'r1', 10000);
27
+ setCachedResult('p1', 'query2', 'r2', 10000);
28
+ setCachedResult('p2', 'query1', 'r3', 10000);
29
+ expect(queryCacheSize()).toBe(3);
30
+ invalidatePerspectiveCache('p1');
31
+ expect(queryCacheSize()).toBe(1);
32
+ expect(getCachedResult('p1', 'query1')).toBeUndefined();
33
+ expect(getCachedResult('p1', 'query2')).toBeUndefined();
34
+ expect(getCachedResult('p2', 'query1')).toBe('r3');
35
+ });
36
+ it('should not affect other perspectives', () => {
37
+ setCachedResult('p1', 'q', 'r1', 10000);
38
+ setCachedResult('p2', 'q', 'r2', 10000);
39
+ invalidatePerspectiveCache('p3');
40
+ expect(queryCacheSize()).toBe(2);
41
+ });
42
+ });
43
+ });
@@ -1,5 +1,5 @@
1
1
  /**
2
- * Shared query helpers used by both the Prolog and SurrealQL query pipelines.
2
+ * Shared query helpers used by both the Prolog and SPARQL query pipelines.
3
3
  */
4
4
  import type { ParentScope } from "./types";
5
5
  /**
@@ -1,5 +1,5 @@
1
1
  /**
2
- * Shared query helpers used by both the Prolog and SurrealQL query pipelines.
2
+ * Shared query helpers used by both the Prolog and SPARQL query pipelines.
3
3
  */
4
4
  import { getRelationsMetadata } from "./decorators";
5
5
  /**
@@ -0,0 +1,17 @@
1
+ /**
2
+ * Batch SPARQL query builder for Ad4mModel eager-loading (includes).
3
+ *
4
+ * Uses direct triple + named graph storage model.
5
+ * Each AD4M link is stored as: <source> <predicate> <target> in a named graph
6
+ * with metadata in the default graph keyed by graph IRI.
7
+ *
8
+ * @module
9
+ */
10
+ import type { Query, ModelMetadata } from "./types";
11
+ /**
12
+ * Build a single SPARQL query that fetches root instances plus all
13
+ * included relations in one query using UNION branches.
14
+ *
15
+ * Uses direct triple patterns in named graphs with metadata in default graph.
16
+ */
17
+ export declare function buildBatchSPARQLQuery(rootMetadata: ModelMetadata, query: Query, rootModelClass: any): string;
@@ -0,0 +1,260 @@
1
+ /**
2
+ * Batch SPARQL query builder for Ad4mModel eager-loading (includes).
3
+ *
4
+ * Uses direct triple + named graph storage model.
5
+ * Each AD4M link is stored as: <source> <predicate> <target> in a named graph
6
+ * with metadata in the default graph keyed by graph IRI.
7
+ *
8
+ * @module
9
+ */
10
+ import { resolveParentPredicate } from "./query-common";
11
+ import { getRelationsMetadata } from "./decorators";
12
+ import { Literal } from "../Literal";
13
+ // ──────────────────────────────────────────────────────────
14
+ // Helpers
15
+ // ──────────────────────────────────────────────────────────
16
+ function iri(value) {
17
+ return `<${value}>`;
18
+ }
19
+ /**
20
+ * Check if a string value looks like a URI (has a scheme).
21
+ */
22
+ function looksLikeUri(value) {
23
+ return /^[a-zA-Z][a-zA-Z0-9+\-._]*:/.test(value);
24
+ }
25
+ /**
26
+ * Convert a JS value to its literal: IRI form.
27
+ */
28
+ function valueToLiteralIri(value) {
29
+ if (typeof value === 'string') {
30
+ if (looksLikeUri(value))
31
+ return value;
32
+ return Literal.from(value).toUrl();
33
+ }
34
+ if (typeof value === 'number')
35
+ return Literal.from(value).toUrl();
36
+ if (typeof value === 'boolean')
37
+ return Literal.from(value).toUrl();
38
+ return Literal.from(String(value)).toUrl();
39
+ }
40
+ /**
41
+ * Determine if a property stores values as literal: IRIs.
42
+ */
43
+ function isLiteralStoredProperty(propMeta) {
44
+ if (propMeta.flag)
45
+ return false;
46
+ if (propMeta.resolveLanguage && propMeta.resolveLanguage !== "literal")
47
+ return false;
48
+ return true;
49
+ }
50
+ function buildConformanceJoins(metadata, sourceVar, prefix) {
51
+ const joins = [];
52
+ const filters = [];
53
+ let hasConformance = false;
54
+ for (const [, propMeta] of Object.entries(metadata.properties)) {
55
+ if (propMeta.required) {
56
+ if (propMeta.getter)
57
+ continue;
58
+ hasConformance = true;
59
+ if (propMeta.flag && propMeta.initial) {
60
+ joins.push(`
61
+ ${sourceVar} ${iri(propMeta.predicate)} ${iri(propMeta.initial)} .`);
62
+ }
63
+ else {
64
+ joins.push(`
65
+ ${sourceVar} ${iri(propMeta.predicate)} ?${prefix}_cfTarget_${propMeta.name} .`);
66
+ }
67
+ }
68
+ }
69
+ if (!hasConformance) {
70
+ for (const [, propMeta] of Object.entries(metadata.properties)) {
71
+ if (propMeta.initial) {
72
+ if (propMeta.flag) {
73
+ joins.push(`
74
+ ${sourceVar} ${iri(propMeta.predicate)} ${iri(propMeta.initial)} .`);
75
+ }
76
+ else {
77
+ joins.push(`
78
+ ${sourceVar} ${iri(propMeta.predicate)} ?${prefix}_cfInitAny_${propMeta.name} .`);
79
+ }
80
+ break;
81
+ }
82
+ }
83
+ }
84
+ return { joins, filters };
85
+ }
86
+ function flattenIncludeTree(parentDepth, parentClass, includeMap, nextDepth) {
87
+ const branches = [];
88
+ const relMeta = getRelationsMetadata(parentClass);
89
+ for (const [relName, includeValue] of Object.entries(includeMap)) {
90
+ const meta = relMeta[relName];
91
+ if (!meta || !meta.target)
92
+ continue;
93
+ const TargetClass = meta.target();
94
+ const targetMetadata = TargetClass.getModelMetadata
95
+ ? TargetClass.getModelMetadata()
96
+ : { className: "Unknown", properties: {}, relations: {} };
97
+ const depth = nextDepth.value++;
98
+ const direction = meta.kind === 'belongsToOne' || meta.kind === 'belongsToMany'
99
+ ? 'reverse' : 'forward';
100
+ const nestedInclude = typeof includeValue === 'object' && includeValue !== null
101
+ ? includeValue.include
102
+ : undefined;
103
+ branches.push({
104
+ depth,
105
+ relationName: relName,
106
+ parentDepth,
107
+ parentPredicate: meta.predicate,
108
+ targetClass: TargetClass,
109
+ targetMetadata,
110
+ includeMap: nestedInclude,
111
+ direction,
112
+ });
113
+ if (nestedInclude) {
114
+ branches.push(...flattenIncludeTree(depth, TargetClass, nestedInclude, nextDepth));
115
+ }
116
+ }
117
+ return branches;
118
+ }
119
+ // ──────────────────────────────────────────────────────────
120
+ // Main entry point
121
+ // ──────────────────────────────────────────────────────────
122
+ /**
123
+ * Build a single SPARQL query that fetches root instances plus all
124
+ * included relations in one query using UNION branches.
125
+ *
126
+ * Uses direct triple patterns in named graphs with metadata in default graph.
127
+ */
128
+ export function buildBatchSPARQLQuery(rootMetadata, query, rootModelClass) {
129
+ const includeMap = query.include;
130
+ if (!includeMap || Object.keys(includeMap).length === 0) {
131
+ throw new Error("buildBatchSPARQLQuery requires query.include to be non-empty");
132
+ }
133
+ const nextDepth = { value: 1 };
134
+ const branches = flattenIncludeTree(0, rootModelClass, includeMap, nextDepth);
135
+ // Root conformance
136
+ const rootConformance = buildConformanceJoins(rootMetadata, "?source", "root");
137
+ const rootJoins = [...rootConformance.joins];
138
+ const rootFilters = [...rootConformance.filters];
139
+ if (query.parent) {
140
+ const parentPredicate = resolveParentPredicate(query.parent, rootModelClass);
141
+ rootJoins.push(`
142
+ ${iri(query.parent.id)} ${iri(parentPredicate)} ?source .`);
143
+ }
144
+ if (query.where) {
145
+ for (const [propertyName, condition] of Object.entries(query.where)) {
146
+ if (propertyName === "base" || propertyName === "id") {
147
+ if (Array.isArray(condition)) {
148
+ const formatted = condition.map(v => iri(v)).join(", ");
149
+ rootFilters.push(`?source IN (${formatted})`);
150
+ }
151
+ else if (typeof condition === "string") {
152
+ rootFilters.push(`?source = ${iri(condition)}`);
153
+ }
154
+ continue;
155
+ }
156
+ if (propertyName === "author" || propertyName === "timestamp")
157
+ continue;
158
+ const propMeta = rootMetadata.properties[propertyName];
159
+ if (!propMeta)
160
+ continue;
161
+ const useParseLiteral = isLiteralStoredProperty(propMeta);
162
+ if (typeof condition === "string" || typeof condition === "number" || typeof condition === "boolean") {
163
+ if (useParseLiteral) {
164
+ // For literal-stored properties, just add a join for conformance — filtering is done in JS
165
+ rootJoins.push(`
166
+ ?source ${iri(propMeta.predicate)} ?root_wTarget_eq_${propertyName} .`);
167
+ }
168
+ else {
169
+ rootJoins.push(`
170
+ ?source ${iri(propMeta.predicate)} ${iri(String(condition))} .`);
171
+ }
172
+ }
173
+ else if (Array.isArray(condition)) {
174
+ if (useParseLiteral) {
175
+ // For literal-stored properties, just add a join for conformance — filtering is done in JS
176
+ rootJoins.push(`
177
+ ?source ${iri(propMeta.predicate)} ?root_wTarget_${propertyName} .`);
178
+ }
179
+ else {
180
+ const formatted = condition.map(v => iri(v)).join(", ");
181
+ rootJoins.push(`
182
+ ?source ${iri(propMeta.predicate)} ?root_wTarget_${propertyName} .`);
183
+ rootFilters.push(`?root_wTarget_${propertyName} IN (${formatted})`);
184
+ }
185
+ }
186
+ }
187
+ }
188
+ const rootJoinClause = rootJoins.join("\n");
189
+ const rootFilterClause = rootFilters.length > 0
190
+ ? `FILTER(\n ${rootFilters.join(" &&\n ")}\n )`
191
+ : "";
192
+ const unionBranches = [];
193
+ // Depth 0: root — direct triple pattern with named graph
194
+ unionBranches.push(`
195
+ {
196
+ ${rootJoinClause}
197
+ GRAPH ?linkGraph { ?source ?predicate ?target . }
198
+ FILTER(isIRI(?source) && isIRI(?predicate))
199
+ ?linkGraph <ad4m://ontology/author> ?author .
200
+ ?linkGraph <ad4m://ontology/timestamp> ?timestamp .
201
+ ${rootFilterClause}
202
+ BIND("0" AS ?depth)
203
+ BIND("" AS ?parentBase)
204
+ BIND("" AS ?relationName)
205
+ }
206
+ `);
207
+ // Depth N: include branches
208
+ for (const branch of branches) {
209
+ const childConformance = buildConformanceJoins(branch.targetMetadata, "?source", `d${branch.depth}`);
210
+ const childJoinClause = childConformance.joins.join("\n");
211
+ const childFilterClause = childConformance.filters.length > 0
212
+ ? `FILTER(\n ${childConformance.filters.join(" &&\n ")}\n )`
213
+ : "";
214
+ const parentJoinClause = branch.parentDepth === 0 ? rootJoinClause.replace(/\?source/g, '?parentBase') : '';
215
+ const parentFilterClause = branch.parentDepth === 0 ? rootFilterClause.replace(/\?source/g, '?parentBase') : '';
216
+ if (branch.direction === 'forward') {
217
+ // Forward: parent --predicate--> child (source)
218
+ unionBranches.push(`
219
+ {
220
+ # Depth ${branch.depth}: ${branch.relationName} (forward)
221
+ ?parentBase ${iri(branch.parentPredicate)} ?source .
222
+ ${childJoinClause}
223
+ GRAPH ?linkGraph { ?source ?predicate ?target . }
224
+ FILTER(isIRI(?source) && isIRI(?predicate))
225
+ ?linkGraph <ad4m://ontology/author> ?author .
226
+ ?linkGraph <ad4m://ontology/timestamp> ?timestamp .
227
+ ${childFilterClause}
228
+ ${parentJoinClause}
229
+ ${parentFilterClause}
230
+ BIND("${branch.depth}" AS ?depth)
231
+ BIND("${branch.relationName}" AS ?relationName)
232
+ }
233
+ `);
234
+ }
235
+ else {
236
+ // Reverse: child (source) --predicate--> parent
237
+ unionBranches.push(`
238
+ {
239
+ # Depth ${branch.depth}: ${branch.relationName} (reverse)
240
+ ?source ${iri(branch.parentPredicate)} ?parentBase .
241
+ ${childJoinClause}
242
+ GRAPH ?linkGraph { ?source ?predicate ?target . }
243
+ FILTER(isIRI(?source) && isIRI(?predicate))
244
+ ?linkGraph <ad4m://ontology/author> ?author .
245
+ ?linkGraph <ad4m://ontology/timestamp> ?timestamp .
246
+ ${childFilterClause}
247
+ ${parentJoinClause}
248
+ ${parentFilterClause}
249
+ BIND("${branch.depth}" AS ?depth)
250
+ BIND("${branch.relationName}" AS ?relationName)
251
+ }
252
+ `);
253
+ }
254
+ }
255
+ return `
256
+ SELECT ?depth ?parentBase ?relationName ?source ?predicate ?target ?author ?timestamp WHERE {
257
+ ${unionBranches.join("\n UNION\n")}
258
+ }
259
+ `.trim();
260
+ }
@@ -0,0 +1,51 @@
1
+ /**
2
+ * SPARQL query building utilities for Ad4mModel.
3
+ *
4
+ * Uses the RDF 1.2 reifier storage model where each AD4M link is stored as:
5
+ * 1. Direct triple: <source> <predicate> <target> . (default graph)
6
+ * 2. Reifier: <link:HASH> <http://www.w3.org/1999/02/22-rdf-syntax-ns#reifies> <<( source predicate target )>> .
7
+ * 3. Metadata: <link:HASH> ad4m://ontology/* "value" . (default graph)
8
+ *
9
+ * All AD4M URIs (source, predicate, target) become RDF IRIs.
10
+ *
11
+ * @module
12
+ */
13
+ import type { RelationMetadataEntry } from "./decorators";
14
+ import type { Where, Query, ModelMetadata } from "./types";
15
+ /**
16
+ * Check whether a `where` clause contains filters that cannot be pushed down
17
+ * to SPARQL and must be evaluated in JS after hydration.
18
+ *
19
+ * JS-only filters include:
20
+ * - Literal-stored properties (equality, comparison, contains, etc.)
21
+ * - Reverse relations (belongsToOne / belongsToMany)
22
+ * - author / timestamp filters (skipped by buildSPARQLWhereFilters)
23
+ *
24
+ * When JS-only filters exist, SPARQL-level LIMIT/OFFSET must NOT be applied
25
+ * because the database would cap the candidate set before JS filters run,
26
+ * potentially discarding matches beyond the LIMIT.
27
+ */
28
+ export declare function hasJsOnlyWhereFilters(metadata: ModelMetadata, allRelationsMetadata: Record<string, RelationMetadataEntry>, where?: Where): boolean;
29
+ /**
30
+ * Format a value as a SPARQL string literal (double-quoted).
31
+ */
32
+ export declare function formatSPARQLValue(value: any): string;
33
+ /**
34
+ * Build a SPARQL query that returns all links belonging to instances of
35
+ * the given model class, optionally filtered by `where` conditions.
36
+ *
37
+ * Uses direct triple patterns: ?source ?predicate ?target
38
+ * with named graph storage and metadata keyed by graph IRI.
39
+ */
40
+ export declare function buildSPARQLQuery(metadata: ModelMetadata, allRelationsMetadata: Record<string, RelationMetadataEntry>, query: Query, modelClass: any): string;
41
+ /**
42
+ * Build an inner subquery that selects DISTINCT ?source URIs with
43
+ * ORDER BY, LIMIT, and OFFSET applied at the instance level.
44
+ *
45
+ * Because the outer SELECT returns multiple rows per instance (one per link),
46
+ * we cannot apply LIMIT/OFFSET there. Instead this subquery constrains
47
+ * ?source to only the instances on the requested page.
48
+ *
49
+ * @internal — used by buildSPARQLQuery when SPARQL-level pagination is safe.
50
+ */
51
+ export declare function buildPaginationSubquery(joinPatterns: string[], filterExpressions: string[], metadata: ModelMetadata, query: Query): string;