@coasys/ad4m 0.13.0-test-3 → 0.13.0-test-5

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 (337) hide show
  1. package/README.md +2 -25
  2. package/jest-setup.ts +1 -1
  3. package/lib/index.cjs +6717 -15519
  4. package/lib/index.js +4811 -13662
  5. package/lib/src/Ad4mClient.d.ts +7 -3
  6. package/lib/src/Ad4mClient.js +39 -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 -1
  150. package/lib/src/index.js +6 -1
  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 +1 -1
  155. package/lib/src/language/Language.js +10 -76
  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 +76 -44
  163. package/lib/src/model/Ad4mModel.js +635 -479
  164. package/lib/src/model/Ad4mModel.test.js +371 -815
  165. package/lib/src/model/ModelQueryBuilder.d.ts +15 -27
  166. package/lib/src/model/ModelQueryBuilder.js +163 -224
  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.d.ts +3 -93
  170. package/lib/src/model/hydration.js +3 -970
  171. package/lib/src/model/index.d.ts +0 -4
  172. package/lib/src/model/index.js +0 -4
  173. package/lib/src/model/model-manifest.d.ts +41 -0
  174. package/lib/src/model/model-manifest.js +11 -0
  175. package/lib/src/model/query-sparql.d.ts +4 -67
  176. package/lib/src/model/query-sparql.js +26 -322
  177. package/lib/src/model/query-sparql.test.js +35 -218
  178. package/lib/src/model/query-utils.d.ts +1 -0
  179. package/lib/src/model/query-utils.js +46 -1
  180. package/lib/src/model/shacl-gen.js +4 -0
  181. package/lib/src/model/types.d.ts +51 -43
  182. package/lib/src/model/types.js +4 -1
  183. package/lib/src/neighbourhood/Neighbourhood.js +4 -32
  184. package/lib/src/neighbourhood/NeighbourhoodClient.d.ts +3 -3
  185. package/lib/src/neighbourhood/NeighbourhoodClient.js +40 -203
  186. package/lib/src/perspectives/LinkQuery.js +2 -42
  187. package/lib/src/perspectives/Perspective.d.ts +1 -1
  188. package/lib/src/perspectives/Perspective.js +10 -52
  189. package/lib/src/perspectives/PerspectiveClient.d.ts +13 -17
  190. package/lib/src/perspectives/PerspectiveClient.js +179 -429
  191. package/lib/src/perspectives/PerspectiveClient.test.js +55 -0
  192. package/lib/src/perspectives/PerspectiveDiff.js +4 -31
  193. package/lib/src/perspectives/PerspectiveHandle.js +3 -43
  194. package/lib/src/perspectives/PerspectiveProxy.d.ts +106 -71
  195. package/lib/src/perspectives/PerspectiveProxy.js +289 -310
  196. package/lib/src/runtime/RuntimeClient.d.ts +6 -6
  197. package/lib/src/runtime/RuntimeClient.js +93 -467
  198. package/lib/src/runtime/RuntimeTypes.d.ts +101 -0
  199. package/lib/src/runtime/RuntimeTypes.js +45 -0
  200. package/lib/src/shacl/SHACLShape.d.ts +7 -0
  201. package/lib/src/shacl/SHACLShape.js +19 -0
  202. package/lib/src/shacl/SHACLShape.test.js +82 -0
  203. package/lib/src/typeDefs.js +3 -628
  204. package/package.json +6 -18
  205. package/rollup.config.js +0 -7
  206. package/src/Ad4mClient.test.ts +1179 -1340
  207. package/src/Ad4mClient.ts +40 -15
  208. package/src/agent/Agent.ts +0 -99
  209. package/src/agent/AgentClient.ts +112 -526
  210. package/src/agent/AgentStatus.ts +0 -12
  211. package/src/ai/AIClient.ts +96 -296
  212. package/src/ai/AITypes.ts +66 -0
  213. package/src/ai/Tasks.ts +0 -52
  214. package/src/apiClient.ts +283 -0
  215. package/src/expression/Expression.ts +3 -43
  216. package/src/expression/ExpressionClient.ts +14 -77
  217. package/src/expression/ExpressionRef.ts +0 -6
  218. package/src/generated/api/AIModelLoadingStatus.ts +3 -0
  219. package/src/generated/api/AddLinkExpressionRequest.ts +4 -0
  220. package/src/generated/api/AddLinkRequest.ts +4 -0
  221. package/src/generated/api/AddLinksBulkRequest.ts +4 -0
  222. package/src/generated/api/AddSdnaRequest.ts +3 -0
  223. package/src/generated/api/ApplyTemplateRequest.ts +3 -0
  224. package/src/generated/api/AuthInfoInput.ts +4 -0
  225. package/src/generated/api/CapabilityInput.ts +4 -0
  226. package/src/generated/api/CommitBatchRequest.ts +3 -0
  227. package/src/generated/api/ComputeLogEntry.ts +3 -0
  228. package/src/generated/api/CreateExpressionRequest.ts +3 -0
  229. package/src/generated/api/CreatePerspectiveRequest.ts +3 -0
  230. package/src/generated/api/CreateSubjectRequest.ts +3 -0
  231. package/src/generated/api/EmbedRequest.ts +3 -0
  232. package/src/generated/api/EntanglementProofInput.ts +3 -0
  233. package/src/generated/api/ExecuteCommandsRequest.ts +3 -0
  234. package/src/generated/api/ExportRequest.ts +3 -0
  235. package/src/generated/api/ExpressionManyRequest.ts +3 -0
  236. package/src/generated/api/ExpressionProof.ts +3 -0
  237. package/src/generated/api/ExpressionProofInput.ts +3 -0
  238. package/src/generated/api/FriendSendMessageRequest.ts +3 -0
  239. package/src/generated/api/FriendsListRequest.ts +3 -0
  240. package/src/generated/api/GenerateAgentRequest.ts +3 -0
  241. package/src/generated/api/GenerateJwtRequest.ts +3 -0
  242. package/src/generated/api/GetSubjectDataRequest.ts +3 -0
  243. package/src/generated/api/ImportAgentRequest.ts +3 -0
  244. package/src/generated/api/ImportRequest.ts +3 -0
  245. package/src/generated/api/JoinNeighbourhoodRequest.ts +3 -0
  246. package/src/generated/api/LanguageMetaInput.ts +3 -0
  247. package/src/generated/api/Link.ts +3 -0
  248. package/src/generated/api/LinkExpression.ts +6 -0
  249. package/src/generated/api/LinkExpressionInput.ts +6 -0
  250. package/src/generated/api/LinkInput.ts +3 -0
  251. package/src/generated/api/LinkLanguageTemplatesRequest.ts +3 -0
  252. package/src/generated/api/LinkMutations.ts +5 -0
  253. package/src/generated/api/LinkStatus.ts +3 -0
  254. package/src/generated/api/LockAgentRequest.ts +3 -0
  255. package/src/generated/api/ModelType.ts +3 -0
  256. package/src/generated/api/NotificationInput.ts +3 -0
  257. package/src/generated/api/OpenLinkRequest.ts +3 -0
  258. package/src/generated/api/PermitCapabilityRequest.ts +3 -0
  259. package/src/generated/api/PerspectiveInput.ts +4 -0
  260. package/src/generated/api/PromptRequest.ts +3 -0
  261. package/src/generated/api/PublishLanguageRequest.ts +4 -0
  262. package/src/generated/api/PublishNeighbourhoodRequest.ts +4 -0
  263. package/src/generated/api/QueryRequest.ts +6 -0
  264. package/src/generated/api/RemoveLinkRequest.ts +4 -0
  265. package/src/generated/api/RemoveLinksBulkRequest.ts +4 -0
  266. package/src/generated/api/ResourceInput.ts +3 -0
  267. package/src/generated/api/SetDefaultModelRequest.ts +4 -0
  268. package/src/generated/api/SetFreeHostingEnabledRequest.ts +3 -0
  269. package/src/generated/api/SetMultiUserRequest.ts +3 -0
  270. package/src/generated/api/SetStatusRequest.ts +3 -0
  271. package/src/generated/api/SignMessageRequest.ts +3 -0
  272. package/src/generated/api/TrustedAgentsRequest.ts +3 -0
  273. package/src/generated/api/UnlockAgentRequest.ts +3 -0
  274. package/src/generated/api/UpdateLinkRequest.ts +5 -0
  275. package/src/generated/api/UpdatePerspectiveRequest.ts +3 -0
  276. package/src/generated/api/UserStatistics.ts +3 -0
  277. package/src/generated/api/VerificationRequestResult.ts +3 -0
  278. package/src/generated/api/VerifySignatureRequest.ts +3 -0
  279. package/src/generated/api/WriteSettingsRequest.ts +3 -0
  280. package/src/generated/api/index.ts +49 -0
  281. package/src/index.ts +6 -1
  282. package/src/jestSetup.ts +1 -1
  283. package/src/language/Icon.ts +0 -4
  284. package/src/language/Language.ts +2 -23
  285. package/src/language/LanguageClient.ts +21 -132
  286. package/src/language/LanguageHandle.ts +0 -14
  287. package/src/language/LanguageMeta.ts +0 -29
  288. package/src/language/LanguageRef.ts +0 -7
  289. package/src/links/Links.ts +0 -37
  290. package/src/model/Ad4mModel.test.ts +766 -1173
  291. package/src/model/Ad4mModel.ts +664 -529
  292. package/src/model/ModelQueryBuilder.ts +203 -251
  293. package/src/model/decorators.ts +29 -0
  294. package/src/model/hydration.ts +3 -1037
  295. package/src/model/index.ts +0 -4
  296. package/src/model/query-sparql.test.ts +34 -242
  297. package/src/model/query-sparql.ts +27 -337
  298. package/src/model/query-utils.ts +47 -2
  299. package/src/model/shacl-gen.ts +5 -0
  300. package/src/model/types.ts +55 -44
  301. package/src/neighbourhood/Neighbourhood.ts +0 -9
  302. package/src/neighbourhood/NeighbourhoodClient.ts +42 -207
  303. package/src/neighbourhood/NeighbourhoodProxy.test.ts +34 -36
  304. package/src/perspectives/LinkQuery.ts +0 -15
  305. package/src/perspectives/Perspective.ts +1 -12
  306. package/src/perspectives/PerspectiveClient.test.ts +206 -148
  307. package/src/perspectives/PerspectiveClient.ts +247 -442
  308. package/src/perspectives/PerspectiveDiff.ts +0 -8
  309. package/src/perspectives/PerspectiveHandle.ts +1 -12
  310. package/src/perspectives/PerspectiveProxy.test.ts +41 -0
  311. package/src/perspectives/PerspectiveProxy.ts +331 -348
  312. package/src/runtime/RuntimeClient.ts +112 -474
  313. package/src/runtime/RuntimeTypes.ts +144 -0
  314. package/src/shacl/SHACLShape.test.ts +94 -0
  315. package/src/shacl/SHACLShape.ts +27 -0
  316. package/src/typeDefs.ts +3 -5
  317. package/tsconfig.json +3 -7
  318. package/shims/reflect-metadata.ts +0 -0
  319. package/shims/type-graphql.ts +0 -75
  320. package/src/PubSub.ts +0 -17
  321. package/src/agent/AgentResolver.ts +0 -263
  322. package/src/ai/AIResolver.ts +0 -372
  323. package/src/buildSchema.ts +0 -43
  324. package/src/expression/ExpressionResolver.ts +0 -64
  325. package/src/language/LanguageResolver.ts +0 -98
  326. package/src/model/Subject.ts +0 -159
  327. package/src/model/hydration-batch.ts +0 -205
  328. package/src/model/hydration-batching.test.ts +0 -563
  329. package/src/model/prolog-facts.ts +0 -145
  330. package/src/model/query-prolog.ts +0 -148
  331. package/src/model/query-sparql-batch.ts +0 -301
  332. package/src/model/subscription-delta.test.ts +0 -207
  333. package/src/model/subscription-pool.ts +0 -211
  334. package/src/neighbourhood/NeighbourhoodResolver.ts +0 -100
  335. package/src/perspectives/PerspectiveResolver.ts +0 -364
  336. package/src/runtime/RuntimeResolver.ts +0 -749
  337. package/src/unwrapApolloResult.ts +0 -16
@@ -1,4 +1,4 @@
1
- import { buildSPARQLOrderLimitOffset, buildSPARQLQuery, buildSPARQLCountQuery, hasJsOnlyWhereFilters, buildSPARQLGroupedCountQuery, parseSparqlGroupedCount } from './query-sparql';
1
+ import { buildSPARQLOrderLimitOffset, buildSPARQLQuery, hasJsOnlyWhereFilters } from './query-sparql';
2
2
  // Minimal stubs for ModelMetadata — buildSPARQLOrderLimitOffset only uses the query arg
3
3
  const emptyMetadata = { properties: {}, relations: {} };
4
4
  // Metadata with a required (non-literal) property and a literal-stored property
@@ -41,10 +41,10 @@ describe('hasJsOnlyWhereFilters', () => {
41
41
  it('returns false when where only has non-literal property filter', () => {
42
42
  expect(hasJsOnlyWhereFilters(richMetadata, emptyRelations, { category: 'some://uri' })).toBe(false);
43
43
  });
44
- it('returns true when where has author filter (count() fast path is unsafe — buildSPARQLCountQuery has no named graph)', () => {
44
+ it('returns true when where has author filter', () => {
45
45
  expect(hasJsOnlyWhereFilters(richMetadata, emptyRelations, { author: 'did:key:abc' })).toBe(true);
46
46
  });
47
- it('returns true when where has timestamp filter (same reason — guards the COUNT fast path)', () => {
47
+ it('returns true when where has timestamp filter', () => {
48
48
  expect(hasJsOnlyWhereFilters(richMetadata, emptyRelations, { timestamp: { gt: 100 } })).toBe(true);
49
49
  });
50
50
  it('returns true for belongsToOne reverse relation', () => {
@@ -55,8 +55,8 @@ describe('hasJsOnlyWhereFilters', () => {
55
55
  });
56
56
  describe('buildSPARQLQuery — SPARQL-level pagination via subquery', () => {
57
57
  const modelClass = {};
58
- it('includes LIMIT/OFFSET in a pagination subquery when query has them, no JS-only filters, and ORDER BY', () => {
59
- const query = { limit: 10, offset: 0, where: { category: 'some://uri' }, order: { name: 'ASC' } };
58
+ it('includes LIMIT/OFFSET in a pagination subquery when query has them and no JS-only filters', () => {
59
+ const query = { limit: 10, offset: 0, where: { category: 'some://uri' } };
60
60
  const sparql = buildSPARQLQuery(richMetadata, emptyRelations, query, modelClass);
61
61
  // SPARQL should contain LIMIT inside the pagination subquery
62
62
  expect(sparql).toContain('LIMIT 10');
@@ -65,20 +65,10 @@ describe('buildSPARQLQuery — SPARQL-level pagination via subquery', () => {
65
65
  // Should have a subquery pattern
66
66
  expect(sparql).toContain('SELECT DISTINCT ?source');
67
67
  });
68
- it('does NOT use SPARQL-level pagination when limit/offset present but no ORDER BY', () => {
69
- const query = { limit: 10, offset: 0, where: { category: 'some://uri' } };
68
+ it('does NOT include LIMIT/OFFSET when JS-only where filters exist', () => {
69
+ // author is a JS-only filter
70
+ const query = { limit: 10, offset: 0, where: { author: 'did:key:abc' } };
70
71
  const sparql = buildSPARQLQuery(richMetadata, emptyRelations, query, modelClass);
71
- // Without ORDER BY, SPARQL pagination is not used — JS-level slicing handles it
72
- expect(sparql).not.toContain('LIMIT');
73
- expect(sparql).not.toContain('OFFSET');
74
- // No subquery needed
75
- expect(sparql).not.toContain('SELECT DISTINCT');
76
- });
77
- it('does NOT include LIMIT/OFFSET when JS-only where filters exist (literal gt operator)', () => {
78
- // gt on a literal-stored property is JS-only, so pagination must not be pushed to SPARQL
79
- const meta = { properties: { rating: { name: 'rating', predicate: 'flux://rating', required: true, resolveLanguage: 'literal' } }, relations: {} };
80
- const query = { limit: 10, offset: 0, where: { rating: { gt: 3 } } };
81
- const sparql = buildSPARQLQuery(meta, emptyRelations, query, modelClass);
82
72
  expect(sparql).not.toContain('LIMIT');
83
73
  expect(sparql).not.toContain('OFFSET');
84
74
  });
@@ -141,7 +131,6 @@ describe('buildSPARQLQuery — structural correctness', () => {
141
131
  offset: 0,
142
132
  parent: { id: 'flux://channel-123', predicate: 'flux://has_message' },
143
133
  where: { category: 'some://uri' },
144
- order: { name: 'ASC' },
145
134
  };
146
135
  const sparql = buildSPARQLQuery(richMetadata, emptyRelations, query, modelClass);
147
136
  expect(sparql).toContain('<flux://channel-123>');
@@ -227,28 +216,21 @@ describe('buildSPARQLQuery — IRI correctness', () => {
227
216
  // ──────────────────────────────────────────────────────────
228
217
  describe('SPARQL-level pagination', () => {
229
218
  const modelClass = {};
230
- it('includes LIMIT in SPARQL when query specifies limit + order', () => {
231
- const query = { limit: 30, order: { name: 'ASC' } };
232
- const sparql = buildSPARQLQuery(richMetadata, emptyRelations, query, modelClass);
219
+ it('includes LIMIT in SPARQL when query specifies limit', () => {
220
+ const query = { limit: 30 };
221
+ const sparql = buildSPARQLQuery(emptyMetadata, emptyRelations, query, modelClass);
233
222
  expect(sparql).toContain('LIMIT 30');
234
223
  expect(sparql).toContain('SELECT DISTINCT ?source');
235
224
  });
236
- it('does NOT push LIMIT to SPARQL when no ORDER BY is specified', () => {
237
- const query = { limit: 30 };
225
+ it('includes OFFSET in SPARQL when query specifies offset > 0', () => {
226
+ const query = { limit: 20, offset: 40 };
238
227
  const sparql = buildSPARQLQuery(emptyMetadata, emptyRelations, query, modelClass);
239
- // Without ORDER BY, SPARQL-level pagination is not used
240
- expect(sparql).not.toContain('LIMIT');
241
- expect(sparql).not.toContain('SELECT DISTINCT');
242
- });
243
- it('includes OFFSET in SPARQL when query specifies offset > 0 with order', () => {
244
- const query = { limit: 20, offset: 40, order: { name: 'ASC' } };
245
- const sparql = buildSPARQLQuery(richMetadata, emptyRelations, query, modelClass);
246
228
  expect(sparql).toContain('LIMIT 20');
247
229
  expect(sparql).toContain('OFFSET 40');
248
230
  });
249
231
  it('does NOT include OFFSET when offset is 0', () => {
250
- const query = { limit: 10, offset: 0, order: { name: 'ASC' } };
251
- const sparql = buildSPARQLQuery(richMetadata, emptyRelations, query, modelClass);
232
+ const query = { limit: 10, offset: 0 };
233
+ const sparql = buildSPARQLQuery(emptyMetadata, emptyRelations, query, modelClass);
252
234
  expect(sparql).toContain('LIMIT 10');
253
235
  expect(sparql).not.toContain('OFFSET');
254
236
  });
@@ -258,38 +240,15 @@ describe('SPARQL-level pagination', () => {
258
240
  expect(sparql).toContain('ORDER BY DESC(');
259
241
  expect(sparql).toContain('LIMIT 10');
260
242
  });
261
- it('uses SAMPLE() aggregate for ORDER BY variables in pagination subquery (SPARQL 1.1 compliance)', () => {
262
- const query = { limit: 5, order: { name: 'ASC' } };
263
- const sparql = buildSPARQLQuery(richMetadata, emptyRelations, query, modelClass);
264
- // Must use SAMPLE() to aggregate the order variable under GROUP BY
265
- expect(sparql).toMatch(/SAMPLE\(/);
266
- expect(sparql).toMatch(/AS \?pg_sort_0/);
267
- expect(sparql).toContain('GROUP BY ?source');
268
- expect(sparql).toContain('ORDER BY ASC(?pg_sort_0)');
269
- });
270
- it('omits GROUP BY when ORDER BY is present (uses SAMPLE() aggregate instead)', () => {
271
- // When ORDER BY is present, GROUP BY ?source is used with SAMPLE() aggregates.
272
- // The old redundant GROUP BY (without ORDER BY) no longer applies because
273
- // SPARQL-level pagination is only used when ORDER BY is present.
274
- const query = { limit: 10, order: { name: 'ASC' } };
275
- const sparql = buildSPARQLQuery(richMetadata, emptyRelations, query, modelClass);
276
- expect(sparql).toContain('GROUP BY ?source');
277
- expect(sparql).toContain('SAMPLE(');
278
- expect(sparql).toContain('SELECT DISTINCT ?source');
279
- expect(sparql).toContain('LIMIT 10');
280
- });
281
243
  it('does NOT default to ORDER BY timestamp when paginating without explicit order', () => {
282
244
  const query = { limit: 30 };
283
245
  const sparql = buildSPARQLQuery(emptyMetadata, emptyRelations, query, modelClass);
284
246
  expect(sparql).not.toContain('ORDER BY');
285
247
  expect(sparql).not.toContain('pg_minTs');
286
- expect(sparql).not.toContain('GRAPH ?pg_g');
287
248
  });
288
- it('does NOT push pagination to SPARQL when JS-only where filters exist (literal gt operator)', () => {
289
- // author equality is now SPARQL-pushable; use a literal gt which remains JS-only
290
- const meta = { properties: { rating: { name: 'rating', predicate: 'flux://rating', required: true, resolveLanguage: 'literal' } }, relations: {} };
291
- const query = { limit: 10, where: { rating: { gt: 5 } } };
292
- const sparql = buildSPARQLQuery(meta, emptyRelations, query, modelClass);
249
+ it('does NOT push pagination to SPARQL when JS-only where filters exist (author)', () => {
250
+ const query = { limit: 10, where: { author: 'did:key:abc' } };
251
+ const sparql = buildSPARQLQuery(emptyMetadata, emptyRelations, query, modelClass);
293
252
  expect(sparql).not.toContain('LIMIT');
294
253
  expect(sparql).not.toContain('OFFSET');
295
254
  });
@@ -305,38 +264,13 @@ describe('SPARQL-level pagination', () => {
305
264
  expect(sparql).not.toContain('LIMIT');
306
265
  });
307
266
  it('wraps pagination in a subquery (outer SELECT fetches all links for the page)', () => {
308
- const query = { limit: 5, offset: 10, order: { name: 'DESC' } };
309
- const sparql = buildSPARQLQuery(richMetadata, emptyRelations, query, modelClass);
267
+ const query = { limit: 5, offset: 10 };
268
+ const sparql = buildSPARQLQuery(emptyMetadata, emptyRelations, query, modelClass);
310
269
  expect(sparql).toContain('SELECT ?source ?predicate ?target ?author ?timestamp');
311
270
  expect(sparql).toContain('SELECT DISTINCT ?source');
312
271
  expect(sparql).toContain('LIMIT 5');
313
272
  expect(sparql).toContain('OFFSET 10');
314
273
  });
315
- it('does NOT wrap pagination in a subquery when no ORDER BY (JS slicing preserves natural order)', () => {
316
- const query = { limit: 5, offset: 10 };
317
- const sparql = buildSPARQLQuery(emptyMetadata, emptyRelations, query, modelClass);
318
- // Should be a plain SELECT without subquery
319
- expect(sparql).toContain('SELECT ?source ?predicate ?target ?author ?timestamp');
320
- expect(sparql).not.toContain('SELECT DISTINCT');
321
- expect(sparql).not.toContain('LIMIT');
322
- expect(sparql).not.toContain('OFFSET');
323
- });
324
- describe('buildSPARQLCountQuery', () => {
325
- it('returns a COUNT(DISTINCT ?source) query', () => {
326
- const query = { parent: { id: 'flux://ch-1', predicate: 'flux://has_child' } };
327
- const countSparql = buildSPARQLCountQuery(emptyMetadata, emptyRelations, query, modelClass);
328
- expect(countSparql).toContain('COUNT(DISTINCT ?source)');
329
- expect(countSparql).toContain('?count');
330
- expect(countSparql).toContain('<flux://ch-1>');
331
- });
332
- it('does NOT include LIMIT/OFFSET (counts full result set)', () => {
333
- const query = { limit: 10, offset: 20, parent: { id: 'flux://ch-1', predicate: 'flux://has_child' } };
334
- const countSparql = buildSPARQLCountQuery(emptyMetadata, emptyRelations, query, modelClass);
335
- expect(countSparql).not.toContain('LIMIT');
336
- expect(countSparql).not.toContain('OFFSET');
337
- expect(countSparql).toContain('COUNT(DISTINCT ?source)');
338
- });
339
- });
340
274
  });
341
275
  describe('buildSPARQLQuery — set-difference patterns', () => {
342
276
  const modelClass = {};
@@ -358,138 +292,21 @@ describe('buildSPARQLQuery — set-difference patterns', () => {
358
292
  expect(sparql).toContain('SELECT ?source ?predicate ?target');
359
293
  });
360
294
  });
361
- // ─────────────────────────────────────────────────────────────
362
- // buildSPARQLWhereFilters — author / timestamp SPARQL push
363
- // ─────────────────────────────────────────────────────────────
364
- describe('buildSPARQLQuery — author/timestamp SPARQL filter push', () => {
295
+ describe('buildSPARQLQuery — RDF 1.2 reifier patterns', () => {
365
296
  const modelClass = {};
366
- it('pushes author equality into SPARQL FILTER using STR(?author)', () => {
367
- const query = { where: { author: 'did:key:zABC' } };
368
- const sparql = buildSPARQLQuery(emptyMetadata, emptyRelations, query, modelClass);
369
- expect(sparql).toContain('STR(?author) = "did:key:zABC"');
370
- expect(sparql).toContain('?author');
371
- });
372
- it('pushes author IN array into SPARQL FILTER', () => {
373
- const query = { where: { author: ['did:key:zABC', 'did:key:zDEF'] } };
374
- const sparql = buildSPARQLQuery(emptyMetadata, emptyRelations, query, modelClass);
375
- expect(sparql).toContain('STR(?author) IN');
376
- expect(sparql).toContain('"did:key:zABC"');
377
- expect(sparql).toContain('"did:key:zDEF"');
378
- });
379
- it('pushes author NOT into SPARQL FILTER', () => {
380
- const query = { where: { author: { not: 'did:key:zABC' } } };
381
- const sparql = buildSPARQLQuery(emptyMetadata, emptyRelations, query, modelClass);
382
- expect(sparql).toContain('STR(?author) != "did:key:zABC"');
383
- });
384
- it('pushes timestamp gt/lt into SPARQL FILTER', () => {
385
- const query = { where: { timestamp: { gt: 1000, lt: 9000 } } };
386
- const sparql = buildSPARQLQuery(emptyMetadata, emptyRelations, query, modelClass);
387
- expect(sparql).toContain('?timestamp > 1000');
388
- expect(sparql).toContain('?timestamp < 9000');
389
- });
390
- it('pushes timestamp between into SPARQL FILTER', () => {
391
- const query = { where: { timestamp: { between: [100, 200] } } };
392
- const sparql = buildSPARQLQuery(emptyMetadata, emptyRelations, query, modelClass);
393
- expect(sparql).toContain('?timestamp >= 100');
394
- expect(sparql).toContain('?timestamp <= 200');
395
- });
396
- it('pushes timestamp equality into SPARQL FILTER', () => {
397
- const query = { where: { timestamp: 1714000000000 } };
398
- const sparql = buildSPARQLQuery(emptyMetadata, emptyRelations, query, modelClass);
399
- expect(sparql).toContain('?timestamp = 1714000000000');
400
- });
401
- });
402
- // ─────────────────────────────────────────────────────────────
403
- // buildSPARQLGroupedCountQuery
404
- // ─────────────────────────────────────────────────────────────
405
- describe('buildSPARQLGroupedCountQuery', () => {
406
- const signalMetadata = {
407
- properties: {
408
- signalTypeId: {
409
- name: 'signalTypeId',
410
- predicate: 'flux://signalTypeId',
411
- required: true,
412
- resolveLanguage: 'literal',
413
- },
414
- },
415
- relations: {},
416
- };
417
- it('selects ?parent and COUNT(DISTINCT ?source)', () => {
418
- const sparql = buildSPARQLGroupedCountQuery(signalMetadata, emptyRelations, 'flux://has-signal', ['flux://post/1'], undefined);
419
- expect(sparql).toContain('SELECT ?parent (COUNT(DISTINCT ?source) AS ?count)');
420
- });
421
- it('groups by ?parent', () => {
422
- const sparql = buildSPARQLGroupedCountQuery(signalMetadata, emptyRelations, 'flux://has-signal', ['flux://post/1'], undefined);
423
- expect(sparql).toContain('GROUP BY ?parent');
424
- });
425
- it('includes parent → child join with the supplied predicate', () => {
426
- const sparql = buildSPARQLGroupedCountQuery(signalMetadata, emptyRelations, 'flux://has-signal', ['flux://post/1', 'flux://post/2'], undefined);
427
- expect(sparql).toContain('?parent <flux://has-signal> ?source');
428
- });
429
- it('includes FILTER(?parent IN (...)) for the supplied parent IDs', () => {
430
- const sparql = buildSPARQLGroupedCountQuery(signalMetadata, emptyRelations, 'flux://has-signal', ['flux://post/1', 'flux://post/2'], undefined);
431
- expect(sparql).toContain('?parent IN (<flux://post/1>, <flux://post/2>)');
432
- });
433
- it('includes the full named graph block (GRAPH ?linkGraph + author + timestamp)', () => {
434
- const sparql = buildSPARQLGroupedCountQuery(signalMetadata, emptyRelations, 'flux://has-signal', ['flux://post/1'], undefined);
435
- expect(sparql).toContain('GRAPH ?linkGraph');
436
- expect(sparql).toContain('?linkGraph <ad4m://ontology/author> ?author');
437
- expect(sparql).toContain('?linkGraph <ad4m://ontology/timestamp> ?timestamp');
438
- });
439
- it('includes conformance join for required properties', () => {
440
- const sparql = buildSPARQLGroupedCountQuery(signalMetadata, emptyRelations, 'flux://has-signal', ['flux://post/1'], undefined);
441
- expect(sparql).toContain('<flux://signalTypeId>');
442
- });
443
- it('applies a where clause filter (author equality) via SPARQL FILTER', () => {
444
- const sparql = buildSPARQLGroupedCountQuery(signalMetadata, emptyRelations, 'flux://has-signal', ['flux://post/1'], { author: 'did:key:zABC' });
445
- expect(sparql).toContain('STR(?author) = "did:key:zABC"');
446
- });
447
- it('applies a where clause filter (required property equality) via parse_literal', () => {
448
- const sparql = buildSPARQLGroupedCountQuery(signalMetadata, emptyRelations, 'flux://has-signal', ['flux://post/1'], { signalTypeId: 'like' });
449
- expect(sparql).toContain('parse_literal');
450
- expect(sparql).toContain('"like"');
451
- });
452
- });
453
- // ─────────────────────────────────────────────────────────────
454
- // parseSparqlGroupedCount
455
- // ─────────────────────────────────────────────────────────────
456
- describe('parseSparqlGroupedCount', () => {
457
- it('returns an empty map for empty input', () => {
458
- expect(parseSparqlGroupedCount([]).size).toBe(0);
459
- });
460
- it('returns an empty map for non-array input', () => {
461
- expect(parseSparqlGroupedCount(null).size).toBe(0);
462
- });
463
- it('parses RDF binding objects ({ parent: { value: ... }, count: { value: ... } })', () => {
464
- const rows = [
465
- { parent: { value: 'flux://post/1' }, count: { value: '3' } },
466
- { parent: { value: 'flux://post/2' }, count: { value: '0' } },
467
- ];
468
- const map = parseSparqlGroupedCount(rows);
469
- expect(map.get('flux://post/1')).toBe(3);
470
- expect(map.get('flux://post/2')).toBe(0);
471
- });
472
- it('parses plain string/number values (non-RDF binding format)', () => {
473
- const rows = [
474
- { parent: 'flux://post/1', count: 5 },
475
- { parent: 'flux://post/2', count: '2' },
476
- ];
477
- const map = parseSparqlGroupedCount(rows);
478
- expect(map.get('flux://post/1')).toBe(5);
479
- expect(map.get('flux://post/2')).toBe(2);
480
- });
481
- it('skips rows with missing parent or count', () => {
482
- const rows = [
483
- { parent: { value: 'flux://post/1' } },
484
- { count: { value: '3' } },
485
- { parent: { value: 'flux://post/3' }, count: { value: '1' } },
486
- ];
487
- const map = parseSparqlGroupedCount(rows);
488
- expect(map.size).toBe(1);
489
- expect(map.get('flux://post/3')).toBe(1);
490
- });
491
- it('skips rows with NaN count', () => {
492
- const rows = [{ parent: { value: 'flux://post/1' }, count: { value: 'not-a-number' } }];
493
- expect(parseSparqlGroupedCount(rows).size).toBe(0);
297
+ it('uses rdf:reifies instead of GRAPH for link metadata', () => {
298
+ const query = { limit: 10 };
299
+ const sparql = buildSPARQLQuery(richMetadata, emptyRelations, query, modelClass);
300
+ expect(sparql).toContain('<http://www.w3.org/1999/02/22-rdf-syntax-ns#reifies>');
301
+ expect(sparql).toContain('<http://www.w3.org/1999/02/22-rdf-syntax-ns#reifies> <<(');
302
+ expect(sparql).toContain('?_reifier');
303
+ expect(sparql).not.toContain('GRAPH');
304
+ expect(sparql).not.toContain('?linkGraph');
305
+ });
306
+ it('binds author and timestamp on the reifier node', () => {
307
+ const query = {};
308
+ const sparql = buildSPARQLQuery(richMetadata, emptyRelations, query, modelClass);
309
+ expect(sparql).toContain('?_reifier <ad4m://ontology/author> ?author');
310
+ expect(sparql).toContain('?_reifier <ad4m://ontology/timestamp> ?timestamp');
494
311
  });
495
312
  });
@@ -30,6 +30,7 @@ export declare function formatQueryValue(value: any): string;
30
30
  */
31
31
  export declare function buildWhereCondition(predicate: string, condition: WhereCondition, opts?: {
32
32
  resolveLanguage?: string;
33
+ varIndex?: number;
33
34
  }): string;
34
35
  /**
35
36
  * Compile a full `Where` clause to an array of SPARQL condition strings.
@@ -56,6 +56,7 @@ export function buildWhereCondition(predicate, condition, opts) {
56
56
  // For literal-resolved properties, values are stored as IRIs like <literal:string:VALUE>
57
57
  // For language-resolved properties, values are plain URIs
58
58
  const isLiteral = !opts?.resolveLanguage || opts.resolveLanguage === 'literal';
59
+ const varSuffix = opts?.varIndex ?? 0;
59
60
  function formatValue(v) {
60
61
  if (typeof v === 'string') {
61
62
  return isLiteral
@@ -65,8 +66,46 @@ export function buildWhereCondition(predicate, condition, opts) {
65
66
  // Numbers/booleans — also stored as literal:string: in AD4M
66
67
  return `<literal:string:${v}>`;
67
68
  }
69
+ /**
70
+ * For literal properties, generate a FILTER-based match that handles both
71
+ * the raw value and the literal-encoded value. This mirrors the Rust
72
+ * `build_projection_where_patterns` approach which uses:
73
+ * FILTER(STR(?var) = "value" || STR(?var) = "literal:string:encodedValue")
74
+ * This is more robust than exact IRI matching because it handles edge cases
75
+ * where the stored format might vary.
76
+ */
77
+ function formatLiteralFilter(varName, v) {
78
+ const raw = escapeQueryString(String(v));
79
+ const encoded = encodeURIComponent(String(v))
80
+ .replace(/!/g, '%21')
81
+ .replace(/'/g, '%27')
82
+ .replace(/\(/g, '%28')
83
+ .replace(/\)/g, '%29')
84
+ .replace(/\*/g, '%2A');
85
+ if (typeof v === 'string') {
86
+ return `FILTER(STR(${varName}) = "${raw}" || STR(${varName}) = "literal:string:${encoded}")`;
87
+ }
88
+ else if (typeof v === 'number') {
89
+ return `FILTER(STR(${varName}) = "${v}" || STR(${varName}) = "literal:number:${v}")`;
90
+ }
91
+ else if (typeof v === 'boolean') {
92
+ return `FILTER(STR(${varName}) = "${v}" || STR(${varName}) = "literal:boolean:${v}")`;
93
+ }
94
+ return `FILTER(STR(${varName}) = "${raw}")`;
95
+ }
68
96
  if (Array.isArray(condition)) {
69
97
  // Array values → FILTER IN
98
+ if (isLiteral) {
99
+ const varName = `?_wc${varSuffix}`;
100
+ const inValues = condition.flatMap(v => {
101
+ const raw = escapeQueryString(String(v));
102
+ const encoded = encodeURIComponent(String(v))
103
+ .replace(/!/g, '%21').replace(/'/g, '%27')
104
+ .replace(/\(/g, '%28').replace(/\)/g, '%29').replace(/\*/g, '%2A');
105
+ return [`"${raw}"`, `"literal:string:${encoded}"`];
106
+ }).join(', ');
107
+ return `?target <${escapedPredicate}> ${varName} . FILTER(STR(${varName}) IN (${inValues}))`;
108
+ }
70
109
  const formattedValues = condition.map(formatValue).join(', ');
71
110
  return `FILTER EXISTS { ?target <${escapedPredicate}> ?_val . FILTER(?_val IN (${formattedValues})) }`;
72
111
  }
@@ -98,6 +137,12 @@ export function buildWhereCondition(predicate, condition, opts) {
98
137
  }
99
138
  else {
100
139
  // Simple equality
140
+ if (isLiteral) {
141
+ // Use FILTER matching (mirrors Rust build_projection_where_patterns)
142
+ // to handle both raw values and literal-encoded IRIs robustly.
143
+ const varName = `?_wc${varSuffix}`;
144
+ return `?target <${escapedPredicate}> ${varName} . ${formatLiteralFilter(varName, condition)}`;
145
+ }
101
146
  return `?target <${escapedPredicate}> ${formatValue(condition)} .`;
102
147
  }
103
148
  }
@@ -135,7 +180,7 @@ export function compileWhereClause(where, metadata) {
135
180
  // No metadata — treat name as raw predicate URI
136
181
  predicate = propertyName;
137
182
  }
138
- const cond = buildWhereCondition(predicate, condition, { resolveLanguage });
183
+ const cond = buildWhereCondition(predicate, condition, { resolveLanguage, varIndex: conditions.length });
139
184
  if (cond) {
140
185
  conditions.push(cond);
141
186
  }
@@ -101,6 +101,10 @@ export function buildSHACL(subjectName, target, properties, allRelationsMeta, co
101
101
  if (propMeta.flag && propMeta.initial) {
102
102
  propShape.hasValue = propMeta.initial;
103
103
  }
104
+ // sh:in — allowed values (enum constraint)
105
+ if (propMeta.options && propMeta.options.length > 0) {
106
+ propShape.in = propMeta.options;
107
+ }
104
108
  // AD4M-specific metadata
105
109
  if (propMeta.local !== undefined) {
106
110
  propShape.local = propMeta.local;
@@ -41,47 +41,12 @@ export type ParentScope = {
41
41
  id: string;
42
42
  predicate: string;
43
43
  };
44
- /**
45
- * Descriptor for a user-named projection — a derived field computed from a
46
- * relation that is attached to the parent instance under a custom `$`-prefixed
47
- * key in the `IncludeMap`.
48
- *
49
- * The `from` field must name a declared relation on the model.
50
- *
51
- * @example
52
- * ```typescript
53
- * include: {
54
- * $signalCount: { from: 'signals', count: true },
55
- * $mySignal: { from: 'signals', where: { author: myDid }, limit: 1 },
56
- * $likeSignals: { from: 'signals', where: { signalTypeId: 'like' } },
57
- * }
58
- * ```
59
- */
60
- export interface IncludeProjection {
61
- /** Declared relation name on the model to derive the projection from. */
62
- from: string;
63
- /**
64
- * When true, the projection result is the count of matching instances
65
- * as a `number`. All other options (`where`, `limit`) are still applied
66
- * before counting. `count: true` → result type is `number`.
67
- */
68
- count?: true;
69
- /** Filter applied to the related instances before the projection result is produced. */
70
- where?: Where;
71
- /**
72
- * Maximum number of results to include.
73
- * When `limit` is `1`, the result type is `T | null` (unwrapped single instance)
74
- * rather than `T[]`.
75
- */
76
- limit?: number;
77
- }
78
44
  /**
79
45
  * Describes which relations to eager-load when querying.
80
46
  *
81
47
  * Each value is either:
82
48
  * - `true` — hydrate the relation one level deep
83
49
  * - A `RelationSubQuery` — scoped sub-query (filter / sort / paginate / nested include)
84
- * - An `IncludeProjection` — user-named derived field (count, filtered subset, single item)
85
50
  *
86
51
  * @example
87
52
  * ```typescript
@@ -93,19 +58,63 @@ export interface IncludeProjection {
93
58
  *
94
59
  * // Nested eager-load
95
60
  * { comments: { include: { author: true } } }
96
- *
97
- * // Projection: count + filtered single item
98
- * { $signalCount: { from: 'signals', count: true }, $mySignal: { from: 'signals', where: { author: myDid }, limit: 1 } }
99
61
  * ```
100
62
  */
101
63
  export interface IncludeMap {
102
64
  [relation: string]: boolean | RelationSubQuery | IncludeProjection;
103
65
  }
66
+ /**
67
+ * A lightweight projection that computes a scalar or list value from a relation
68
+ * without fully hydrating the linked instances.
69
+ *
70
+ * Keys in `IncludeMap` that begin with `$` are treated as projections.
71
+ * Results are attached directly to each queried instance under the same key.
72
+ *
73
+ * @example
74
+ * ```typescript
75
+ * // Attach a like-count to each post
76
+ * const posts = await Post.findAll(perspective, {
77
+ * include: {
78
+ * $likeCount: { from: 'likes', count: true },
79
+ * $myLike: { from: 'likes', limit: 1 },
80
+ * }
81
+ * });
82
+ * posts[0].$likeCount // number
83
+ * posts[0].$myLike // string ID or null
84
+ * ```
85
+ */
86
+ export interface IncludeProjection {
87
+ /** The relation name on the parent model to project over. */
88
+ from: string;
89
+ /** When true, attaches an integer count instead of a list. */
90
+ count?: true;
91
+ /**
92
+ * Serialised target class shape. Set automatically by `executeModelQuery`
93
+ * when a `where` clause is present and the target class is resolvable.
94
+ * @internal
95
+ */
96
+ targetShape?: ModelMetadata;
97
+ /** Post-hydration where clause applied to the target instances. */
98
+ where?: Where;
99
+ /** Limit results (when 1, the attached value is unwrapped to a scalar). */
100
+ limit?: number;
101
+ /** Order results before applying limit. */
102
+ order?: Order;
103
+ }
104
+ /** Type guard for IncludeProjection objects. */
105
+ export declare function isIncludeProjection(val: unknown): val is IncludeProjection;
104
106
  export type Query = {
105
107
  /** Filter to instances that are the target of a link from a given parent. */
106
108
  parent?: ParentScope;
107
109
  properties?: string[];
108
110
  include?: IncludeMap;
111
+ /**
112
+ * When true, eager-loads every declared forward relation on the model.
113
+ * Equivalent to listing all relation field names in `include: {}` explicitly.
114
+ * Useful for tree-walking and manifest-style inspections.
115
+ * Individual relations can still be overridden via `include` (explicit entries take precedence).
116
+ */
117
+ includeAll?: boolean;
109
118
  where?: Where;
110
119
  order?: Order;
111
120
  offset?: number;
@@ -113,12 +122,11 @@ export type Query = {
113
122
  count?: boolean;
114
123
  /**
115
124
  * When true, SPARQL property getters (@Property with `getter`) ARE evaluated
116
- * during collection hydration. By default, collection queries skip getter
117
- * evaluation for performance — getters run only on single-instance get().
125
+ * during collection hydration. Defaults to true — getters run post-pagination
126
+ * via batched VALUES queries so the cost is O(getters), not O(instances × getters).
118
127
  *
119
- * Use this when you need getter-backed properties (e.g. `replyingTo`,
120
- * `isPopular`) in a list query. For most list/feed UIs, leave this off
121
- * and use `Ad4mModel.evaluateGetters()` on visible items only.
128
+ * Set to false to explicitly skip getter evaluation for performance-sensitive
129
+ * queries where getter-backed properties are not needed.
122
130
  */
123
131
  deepQuery?: boolean;
124
132
  };
@@ -5,4 +5,7 @@
5
5
  * (`query-utils.ts`, `decorators.ts`, etc.) can import types without
6
6
  * creating circular runtime dependencies on `Ad4mModel.ts`.
7
7
  */
8
- export {};
8
+ /** Type guard for IncludeProjection objects. */
9
+ export function isIncludeProjection(val) {
10
+ return typeof val === 'object' && val !== null && 'from' in val;
11
+ }
@@ -1,38 +1,10 @@
1
- var __decorate = (this && this.__decorate) || function (decorators, target, key, desc) {
2
- var c = arguments.length, r = c < 3 ? target : desc === null ? desc = Object.getOwnPropertyDescriptor(target, key) : desc, d;
3
- if (typeof Reflect === "object" && typeof Reflect.decorate === "function") r = Reflect.decorate(decorators, target, key, desc);
4
- else for (var i = decorators.length - 1; i >= 0; i--) if (d = decorators[i]) r = (c < 3 ? d(r) : c > 3 ? d(target, key, r) : d(target, key)) || r;
5
- return c > 3 && r && Object.defineProperty(target, key, r), r;
6
- };
7
- var __metadata = (this && this.__metadata) || function (k, v) {
8
- if (typeof Reflect === "object" && typeof Reflect.metadata === "function") return Reflect.metadata(k, v);
9
- };
10
- import { Field, ObjectType } from "type-graphql";
11
1
  import { ExpressionGeneric } from "../expression/Expression";
12
- import { Perspective } from "../perspectives/Perspective";
13
- let Neighbourhood = class Neighbourhood {
2
+ export class Neighbourhood {
14
3
  constructor(linkLanguage, meta) {
15
4
  this.linkLanguage = linkLanguage;
16
5
  this.meta = meta;
17
6
  }
18
- };
19
- __decorate([
20
- Field(),
21
- __metadata("design:type", String)
22
- ], Neighbourhood.prototype, "linkLanguage", void 0);
23
- __decorate([
24
- Field(),
25
- __metadata("design:type", Perspective)
26
- ], Neighbourhood.prototype, "meta", void 0);
27
- Neighbourhood = __decorate([
28
- ObjectType(),
29
- __metadata("design:paramtypes", [String, Perspective])
30
- ], Neighbourhood);
31
- export { Neighbourhood };
32
- let NeighbourhoodExpression = class NeighbourhoodExpression extends ExpressionGeneric(Neighbourhood) {
33
- };
34
- NeighbourhoodExpression = __decorate([
35
- ObjectType()
36
- ], NeighbourhoodExpression);
37
- export { NeighbourhoodExpression };
7
+ }
8
+ export class NeighbourhoodExpression extends ExpressionGeneric(Neighbourhood) {
9
+ }
38
10
  ;
@@ -1,4 +1,4 @@
1
- import { ApolloClient } from "@apollo/client/core";
1
+ import { ApiClient } from "../apiClient";
2
2
  import { Address } from "../Address";
3
3
  import { DID } from "../DID";
4
4
  import { OnlineAgent, TelepresenceSignalCallback } from "../language/Language";
@@ -6,7 +6,7 @@ import { Perspective, PerspectiveUnsignedInput } from "../perspectives/Perspecti
6
6
  import { PerspectiveHandle } from "../perspectives/PerspectiveHandle";
7
7
  export declare class NeighbourhoodClient {
8
8
  #private;
9
- constructor(client: ApolloClient<any>);
9
+ constructor(baseUrl: string, token?: string, sharedApiClient?: ApiClient);
10
10
  publishFromPerspective(perspectiveUUID: string, linkLanguage: Address, meta: Perspective): Promise<string>;
11
11
  joinFromUrl(url: string): Promise<PerspectiveHandle>;
12
12
  otherAgents(perspectiveUUID: string): Promise<DID[]>;
@@ -18,7 +18,7 @@ export declare class NeighbourhoodClient {
18
18
  sendSignalU(perspectiveUUID: string, remoteAgentDid: string, payload: PerspectiveUnsignedInput): Promise<boolean>;
19
19
  sendBroadcast(perspectiveUUID: string, payload: Perspective, loopback?: boolean): Promise<boolean>;
20
20
  sendBroadcastU(perspectiveUUID: string, payload: PerspectiveUnsignedInput, loopback?: boolean): Promise<boolean>;
21
- dispatchSignal(perspectiveUUID: string, signal: any): void;
21
+ dispatchSignal(perspectiveUUID: string, signal: unknown): void;
22
22
  subscribeToSignals(perspectiveUUID: string): Promise<void>;
23
23
  addSignalHandler(perspectiveUUID: string, handler: TelepresenceSignalCallback): Promise<void>;
24
24
  removeSignalHandler(perspectiveUUID: string, handler: TelepresenceSignalCallback): void;