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

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
Files changed (393) hide show
  1. package/README.md +2 -25
  2. package/jest-setup.ts +1 -1
  3. package/lib/index.cjs +8677 -15318
  4. package/lib/index.js +14507 -21223
  5. package/lib/src/Ad4mClient.d.ts +9 -3
  6. package/lib/src/Ad4mClient.js +40 -13
  7. package/lib/src/Literal.js +6 -5
  8. package/lib/src/agent/Agent.js +26 -272
  9. package/lib/src/agent/AgentClient.d.ts +33 -21
  10. package/lib/src/agent/AgentClient.js +180 -374
  11. package/lib/src/agent/AgentStatus.js +2 -37
  12. package/lib/src/ai/AIClient.d.ts +12 -4
  13. package/lib/src/ai/AIClient.js +81 -285
  14. package/lib/src/ai/AITypes.d.ts +55 -0
  15. package/lib/src/ai/AITypes.js +18 -0
  16. package/lib/src/ai/Tasks.js +10 -133
  17. package/lib/src/apiClient.d.ts +53 -0
  18. package/lib/src/apiClient.js +234 -0
  19. package/lib/src/cache/PersistentCache.d.ts +40 -0
  20. package/lib/src/cache/PersistentCache.js +139 -0
  21. package/lib/src/expression/Expression.d.ts +1 -1
  22. package/lib/src/expression/Expression.js +13 -122
  23. package/lib/src/expression/ExpressionClient.d.ts +11 -3
  24. package/lib/src/expression/ExpressionClient.js +120 -75
  25. package/lib/src/expression/ExpressionRef.js +4 -27
  26. package/lib/src/generated/api/AIModelLoadingStatus.d.ts +7 -0
  27. package/lib/src/generated/api/AIModelLoadingStatus.js +2 -0
  28. package/lib/src/generated/api/AddLinkExpressionRequest.d.ts +6 -0
  29. package/lib/src/generated/api/AddLinkExpressionRequest.js +1 -0
  30. package/lib/src/generated/api/AddLinkRequest.d.ts +6 -0
  31. package/lib/src/generated/api/AddLinkRequest.js +1 -0
  32. package/lib/src/generated/api/AddLinksBulkRequest.d.ts +6 -0
  33. package/lib/src/generated/api/AddLinksBulkRequest.js +1 -0
  34. package/lib/src/generated/api/AddSdnaRequest.d.ts +6 -0
  35. package/lib/src/generated/api/AddSdnaRequest.js +2 -0
  36. package/lib/src/generated/api/ApplyTemplateRequest.d.ts +4 -0
  37. package/lib/src/generated/api/ApplyTemplateRequest.js +2 -0
  38. package/lib/src/generated/api/AuthInfoInput.d.ts +10 -0
  39. package/lib/src/generated/api/AuthInfoInput.js +1 -0
  40. package/lib/src/generated/api/CapabilityInput.d.ts +5 -0
  41. package/lib/src/generated/api/CapabilityInput.js +1 -0
  42. package/lib/src/generated/api/CommitBatchRequest.d.ts +3 -0
  43. package/lib/src/generated/api/CommitBatchRequest.js +2 -0
  44. package/lib/src/generated/api/ComputeLogEntry.d.ts +9 -0
  45. package/lib/src/generated/api/ComputeLogEntry.js +2 -0
  46. package/lib/src/generated/api/CreateExpressionRequest.d.ts +4 -0
  47. package/lib/src/generated/api/CreateExpressionRequest.js +2 -0
  48. package/lib/src/generated/api/CreatePerspectiveRequest.d.ts +3 -0
  49. package/lib/src/generated/api/CreatePerspectiveRequest.js +2 -0
  50. package/lib/src/generated/api/CreateSubjectRequest.d.ts +6 -0
  51. package/lib/src/generated/api/CreateSubjectRequest.js +2 -0
  52. package/lib/src/generated/api/EmbedRequest.d.ts +4 -0
  53. package/lib/src/generated/api/EmbedRequest.js +2 -0
  54. package/lib/src/generated/api/EntanglementProofInput.d.ts +6 -0
  55. package/lib/src/generated/api/EntanglementProofInput.js +2 -0
  56. package/lib/src/generated/api/ExecuteCommandsRequest.d.ts +4 -0
  57. package/lib/src/generated/api/ExecuteCommandsRequest.js +2 -0
  58. package/lib/src/generated/api/ExportRequest.d.ts +5 -0
  59. package/lib/src/generated/api/ExportRequest.js +2 -0
  60. package/lib/src/generated/api/ExpressionManyRequest.d.ts +3 -0
  61. package/lib/src/generated/api/ExpressionManyRequest.js +2 -0
  62. package/lib/src/generated/api/ExpressionProof.d.ts +4 -0
  63. package/lib/src/generated/api/ExpressionProof.js +2 -0
  64. package/lib/src/generated/api/ExpressionProofInput.d.ts +6 -0
  65. package/lib/src/generated/api/ExpressionProofInput.js +2 -0
  66. package/lib/src/generated/api/FriendSendMessageRequest.d.ts +3 -0
  67. package/lib/src/generated/api/FriendSendMessageRequest.js +2 -0
  68. package/lib/src/generated/api/FriendsListRequest.d.ts +3 -0
  69. package/lib/src/generated/api/FriendsListRequest.js +2 -0
  70. package/lib/src/generated/api/GenerateAgentRequest.d.ts +3 -0
  71. package/lib/src/generated/api/GenerateAgentRequest.js +2 -0
  72. package/lib/src/generated/api/GenerateJwtRequest.d.ts +4 -0
  73. package/lib/src/generated/api/GenerateJwtRequest.js +2 -0
  74. package/lib/src/generated/api/GetSubjectDataRequest.d.ts +4 -0
  75. package/lib/src/generated/api/GetSubjectDataRequest.js +2 -0
  76. package/lib/src/generated/api/ImportAgentRequest.d.ts +6 -0
  77. package/lib/src/generated/api/ImportAgentRequest.js +2 -0
  78. package/lib/src/generated/api/ImportRequest.d.ts +4 -0
  79. package/lib/src/generated/api/ImportRequest.js +2 -0
  80. package/lib/src/generated/api/JoinNeighbourhoodRequest.d.ts +3 -0
  81. package/lib/src/generated/api/JoinNeighbourhoodRequest.js +2 -0
  82. package/lib/src/generated/api/LanguageMetaInput.d.ts +6 -0
  83. package/lib/src/generated/api/LanguageMetaInput.js +2 -0
  84. package/lib/src/generated/api/Link.d.ts +5 -0
  85. package/lib/src/generated/api/Link.js +2 -0
  86. package/lib/src/generated/api/LinkExpression.d.ts +10 -0
  87. package/lib/src/generated/api/LinkExpression.js +1 -0
  88. package/lib/src/generated/api/LinkExpressionInput.d.ts +10 -0
  89. package/lib/src/generated/api/LinkExpressionInput.js +1 -0
  90. package/lib/src/generated/api/LinkInput.d.ts +5 -0
  91. package/lib/src/generated/api/LinkInput.js +2 -0
  92. package/lib/src/generated/api/LinkLanguageTemplatesRequest.d.ts +3 -0
  93. package/lib/src/generated/api/LinkLanguageTemplatesRequest.js +2 -0
  94. package/lib/src/generated/api/LinkMutations.d.ts +6 -0
  95. package/lib/src/generated/api/LinkMutations.js +1 -0
  96. package/lib/src/generated/api/LinkStatus.d.ts +1 -0
  97. package/lib/src/generated/api/LinkStatus.js +2 -0
  98. package/lib/src/generated/api/LockAgentRequest.d.ts +3 -0
  99. package/lib/src/generated/api/LockAgentRequest.js +2 -0
  100. package/lib/src/generated/api/ModelType.d.ts +1 -0
  101. package/lib/src/generated/api/ModelType.js +2 -0
  102. package/lib/src/generated/api/NotificationInput.d.ts +10 -0
  103. package/lib/src/generated/api/NotificationInput.js +2 -0
  104. package/lib/src/generated/api/OpenLinkRequest.d.ts +3 -0
  105. package/lib/src/generated/api/OpenLinkRequest.js +2 -0
  106. package/lib/src/generated/api/PermitCapabilityRequest.d.ts +3 -0
  107. package/lib/src/generated/api/PermitCapabilityRequest.js +2 -0
  108. package/lib/src/generated/api/PerspectiveInput.d.ts +4 -0
  109. package/lib/src/generated/api/PerspectiveInput.js +1 -0
  110. package/lib/src/generated/api/PromptRequest.d.ts +4 -0
  111. package/lib/src/generated/api/PromptRequest.js +2 -0
  112. package/lib/src/generated/api/PublishLanguageRequest.d.ts +5 -0
  113. package/lib/src/generated/api/PublishLanguageRequest.js +1 -0
  114. package/lib/src/generated/api/PublishNeighbourhoodRequest.d.ts +6 -0
  115. package/lib/src/generated/api/PublishNeighbourhoodRequest.js +1 -0
  116. package/lib/src/generated/api/QueryRequest.d.ts +7 -0
  117. package/lib/src/generated/api/QueryRequest.js +2 -0
  118. package/lib/src/generated/api/RemoveLinkRequest.d.ts +5 -0
  119. package/lib/src/generated/api/RemoveLinkRequest.js +1 -0
  120. package/lib/src/generated/api/RemoveLinksBulkRequest.d.ts +5 -0
  121. package/lib/src/generated/api/RemoveLinksBulkRequest.js +1 -0
  122. package/lib/src/generated/api/ResourceInput.d.ts +4 -0
  123. package/lib/src/generated/api/ResourceInput.js +2 -0
  124. package/lib/src/generated/api/SetDefaultModelRequest.d.ts +4 -0
  125. package/lib/src/generated/api/SetDefaultModelRequest.js +1 -0
  126. package/lib/src/generated/api/SetFreeHostingEnabledRequest.d.ts +3 -0
  127. package/lib/src/generated/api/SetFreeHostingEnabledRequest.js +2 -0
  128. package/lib/src/generated/api/SetMultiUserRequest.d.ts +3 -0
  129. package/lib/src/generated/api/SetMultiUserRequest.js +2 -0
  130. package/lib/src/generated/api/SetStatusRequest.d.ts +3 -0
  131. package/lib/src/generated/api/SetStatusRequest.js +2 -0
  132. package/lib/src/generated/api/SignMessageRequest.d.ts +3 -0
  133. package/lib/src/generated/api/SignMessageRequest.js +2 -0
  134. package/lib/src/generated/api/TrustedAgentsRequest.d.ts +3 -0
  135. package/lib/src/generated/api/TrustedAgentsRequest.js +2 -0
  136. package/lib/src/generated/api/UnlockAgentRequest.d.ts +4 -0
  137. package/lib/src/generated/api/UnlockAgentRequest.js +2 -0
  138. package/lib/src/generated/api/UpdateLinkRequest.d.ts +7 -0
  139. package/lib/src/generated/api/UpdateLinkRequest.js +1 -0
  140. package/lib/src/generated/api/UpdatePerspectiveRequest.d.ts +3 -0
  141. package/lib/src/generated/api/UpdatePerspectiveRequest.js +2 -0
  142. package/lib/src/generated/api/UserStatistics.d.ts +9 -0
  143. package/lib/src/generated/api/UserStatistics.js +2 -0
  144. package/lib/src/generated/api/VerificationRequestResult.d.ts +6 -0
  145. package/lib/src/generated/api/VerificationRequestResult.js +2 -0
  146. package/lib/src/generated/api/VerifySignatureRequest.d.ts +5 -0
  147. package/lib/src/generated/api/VerifySignatureRequest.js +2 -0
  148. package/lib/src/generated/api/WriteSettingsRequest.d.ts +3 -0
  149. package/lib/src/generated/api/WriteSettingsRequest.js +2 -0
  150. package/lib/src/generated/api/index.d.ts +42 -0
  151. package/lib/src/generated/api/index.js +7 -0
  152. package/lib/src/index.d.ts +8 -2
  153. package/lib/src/index.js +8 -2
  154. package/lib/src/jestSetup.d.ts +0 -1
  155. package/lib/src/jestSetup.js +1 -1
  156. package/lib/src/language/Icon.js +2 -21
  157. package/lib/src/language/Language.d.ts +26 -176
  158. package/lib/src/language/Language.js +32 -72
  159. package/lib/src/language/LanguageClient.d.ts +2 -2
  160. package/lib/src/language/LanguageClient.js +15 -105
  161. package/lib/src/language/LanguageHandle.js +2 -41
  162. package/lib/src/language/LanguageMeta.js +4 -75
  163. package/lib/src/language/LanguageRef.js +2 -25
  164. package/lib/src/links/Links.js +14 -111
  165. package/lib/src/model/Ad4mModel.d.ts +143 -63
  166. package/lib/src/model/Ad4mModel.js +583 -425
  167. package/lib/src/model/Ad4mModel.test.js +1434 -688
  168. package/lib/src/model/ModelQueryBuilder.d.ts +61 -45
  169. package/lib/src/model/ModelQueryBuilder.js +315 -157
  170. package/lib/src/model/Subject.js +6 -6
  171. package/lib/src/model/decorators.d.ts +36 -8
  172. package/lib/src/model/decorators.js +41 -14
  173. package/lib/src/model/hydration-batch.d.ts +34 -0
  174. package/lib/src/model/hydration-batch.js +147 -0
  175. package/lib/src/model/hydration-batching.test.d.ts +7 -0
  176. package/lib/src/model/hydration-batching.test.js +456 -0
  177. package/lib/src/model/hydration.d.ts +3 -92
  178. package/lib/src/model/hydration.js +3 -691
  179. package/lib/src/model/index.d.ts +3 -4
  180. package/lib/src/model/index.js +3 -4
  181. package/lib/src/model/json-schema.js +2 -2
  182. package/lib/src/model/model-manifest.d.ts +41 -0
  183. package/lib/src/model/model-manifest.js +11 -0
  184. package/lib/src/model/query-cache.d.ts +30 -0
  185. package/lib/src/model/query-cache.js +66 -0
  186. package/lib/src/model/query-cache.test.d.ts +1 -0
  187. package/lib/src/model/query-cache.test.js +43 -0
  188. package/lib/src/model/query-common.d.ts +1 -1
  189. package/lib/src/model/query-common.js +1 -1
  190. package/lib/src/model/query-sparql-batch.d.ts +17 -0
  191. package/lib/src/model/query-sparql-batch.js +260 -0
  192. package/lib/src/model/query-sparql.d.ts +51 -0
  193. package/lib/src/model/query-sparql.js +466 -0
  194. package/lib/src/model/query-sparql.test.d.ts +1 -0
  195. package/lib/src/model/query-sparql.test.js +312 -0
  196. package/lib/src/model/{surreal-utils.d.ts → query-utils.d.ts} +13 -9
  197. package/lib/src/model/query-utils.js +189 -0
  198. package/lib/src/model/relation-filtering.test.js +15 -15
  199. package/lib/src/model/sdna.js +1 -1
  200. package/lib/src/model/shacl-gen.js +154 -57
  201. package/lib/src/model/subscription-delta.test.d.ts +24 -0
  202. package/lib/src/model/subscription-delta.test.js +180 -0
  203. package/lib/src/model/subscription-pool.d.ts +39 -0
  204. package/lib/src/model/subscription-pool.js +165 -0
  205. package/lib/src/model/types.d.ts +195 -5
  206. package/lib/src/model/types.js +5 -2
  207. package/lib/src/neighbourhood/Neighbourhood.js +4 -32
  208. package/lib/src/neighbourhood/NeighbourhoodClient.d.ts +3 -3
  209. package/lib/src/neighbourhood/NeighbourhoodClient.js +40 -203
  210. package/lib/src/perspectives/LinkQuery.js +2 -42
  211. package/lib/src/perspectives/Perspective.d.ts +1 -1
  212. package/lib/src/perspectives/Perspective.js +10 -52
  213. package/lib/src/perspectives/PerspectiveClient.d.ts +22 -32
  214. package/lib/src/perspectives/PerspectiveClient.js +188 -454
  215. package/lib/src/perspectives/PerspectiveClient.test.d.ts +1 -0
  216. package/lib/src/perspectives/PerspectiveClient.test.js +224 -0
  217. package/lib/src/perspectives/PerspectiveDiff.js +4 -31
  218. package/lib/src/perspectives/PerspectiveHandle.js +3 -43
  219. package/lib/src/perspectives/PerspectiveProxy.d.ts +157 -78
  220. package/lib/src/perspectives/PerspectiveProxy.js +475 -389
  221. package/lib/src/perspectives/PerspectiveResolver.d.ts +0 -1
  222. package/lib/src/perspectives/PerspectiveResolver.js +0 -11
  223. package/lib/src/perspectives/SparqlBindings.d.ts +47 -0
  224. package/lib/src/perspectives/SparqlBindings.js +65 -0
  225. package/lib/src/perspectives/WakerSubscriptionManager.d.ts +3 -3
  226. package/lib/src/perspectives/WakerSubscriptionManager.js +12 -12
  227. package/lib/src/runtime/RuntimeClient.d.ts +8 -6
  228. package/lib/src/runtime/RuntimeClient.js +97 -454
  229. package/lib/src/runtime/RuntimeResolver.d.ts +14 -0
  230. package/lib/src/runtime/RuntimeResolver.js +84 -0
  231. package/lib/src/runtime/RuntimeTypes.d.ts +101 -0
  232. package/lib/src/runtime/RuntimeTypes.js +45 -0
  233. package/lib/src/schema.gql +14 -1
  234. package/lib/src/shacl/SHACLFlow.d.ts +1 -1
  235. package/lib/src/shacl/SHACLFlow.js +9 -9
  236. package/lib/src/shacl/SHACLShape.d.ts +26 -1
  237. package/lib/src/shacl/SHACLShape.js +140 -38
  238. package/lib/src/shacl/SHACLShape.test.js +82 -0
  239. package/lib/src/typeDefs.js +3 -615
  240. package/lib/src/utils.d.ts +6 -6
  241. package/lib/src/utils.js +6 -6
  242. package/package.json +9 -24
  243. package/rollup.config.js +0 -7
  244. package/src/Ad4mClient.test.ts +1192 -1288
  245. package/src/Ad4mClient.ts +46 -15
  246. package/src/Literal.test.ts +10 -5
  247. package/src/Literal.ts +6 -5
  248. package/src/agent/Agent.ts +0 -99
  249. package/src/agent/AgentClient.ts +238 -467
  250. package/src/agent/AgentStatus.ts +0 -12
  251. package/src/ai/AIClient.ts +96 -296
  252. package/src/ai/AITypes.ts +66 -0
  253. package/src/ai/Tasks.ts +0 -52
  254. package/src/apiClient.ts +287 -0
  255. package/src/cache/PersistentCache.ts +145 -0
  256. package/src/cache/cache.test.ts +713 -0
  257. package/src/expression/Expression.ts +3 -43
  258. package/src/expression/ExpressionClient.ts +148 -77
  259. package/src/expression/ExpressionRef.ts +2 -8
  260. package/src/generated/api/AIModelLoadingStatus.ts +3 -0
  261. package/src/generated/api/AddLinkExpressionRequest.ts +4 -0
  262. package/src/generated/api/AddLinkRequest.ts +4 -0
  263. package/src/generated/api/AddLinksBulkRequest.ts +4 -0
  264. package/src/generated/api/AddSdnaRequest.ts +3 -0
  265. package/src/generated/api/ApplyTemplateRequest.ts +3 -0
  266. package/src/generated/api/AuthInfoInput.ts +4 -0
  267. package/src/generated/api/CapabilityInput.ts +4 -0
  268. package/src/generated/api/CommitBatchRequest.ts +3 -0
  269. package/src/generated/api/ComputeLogEntry.ts +3 -0
  270. package/src/generated/api/CreateExpressionRequest.ts +3 -0
  271. package/src/generated/api/CreatePerspectiveRequest.ts +3 -0
  272. package/src/generated/api/CreateSubjectRequest.ts +3 -0
  273. package/src/generated/api/EmbedRequest.ts +3 -0
  274. package/src/generated/api/EntanglementProofInput.ts +3 -0
  275. package/src/generated/api/ExecuteCommandsRequest.ts +3 -0
  276. package/src/generated/api/ExportRequest.ts +3 -0
  277. package/src/generated/api/ExpressionManyRequest.ts +3 -0
  278. package/src/generated/api/ExpressionProof.ts +3 -0
  279. package/src/generated/api/ExpressionProofInput.ts +3 -0
  280. package/src/generated/api/FriendSendMessageRequest.ts +3 -0
  281. package/src/generated/api/FriendsListRequest.ts +3 -0
  282. package/src/generated/api/GenerateAgentRequest.ts +3 -0
  283. package/src/generated/api/GenerateJwtRequest.ts +3 -0
  284. package/src/generated/api/GetSubjectDataRequest.ts +3 -0
  285. package/src/generated/api/ImportAgentRequest.ts +3 -0
  286. package/src/generated/api/ImportRequest.ts +3 -0
  287. package/src/generated/api/JoinNeighbourhoodRequest.ts +3 -0
  288. package/src/generated/api/LanguageMetaInput.ts +3 -0
  289. package/src/generated/api/Link.ts +3 -0
  290. package/src/generated/api/LinkExpression.ts +6 -0
  291. package/src/generated/api/LinkExpressionInput.ts +6 -0
  292. package/src/generated/api/LinkInput.ts +3 -0
  293. package/src/generated/api/LinkLanguageTemplatesRequest.ts +3 -0
  294. package/src/generated/api/LinkMutations.ts +5 -0
  295. package/src/generated/api/LinkStatus.ts +3 -0
  296. package/src/generated/api/LockAgentRequest.ts +3 -0
  297. package/src/generated/api/ModelType.ts +3 -0
  298. package/src/generated/api/NotificationInput.ts +3 -0
  299. package/src/generated/api/OpenLinkRequest.ts +3 -0
  300. package/src/generated/api/PermitCapabilityRequest.ts +3 -0
  301. package/src/generated/api/PerspectiveInput.ts +4 -0
  302. package/src/generated/api/PromptRequest.ts +3 -0
  303. package/src/generated/api/PublishLanguageRequest.ts +4 -0
  304. package/src/generated/api/PublishNeighbourhoodRequest.ts +4 -0
  305. package/src/generated/api/QueryRequest.ts +6 -0
  306. package/src/generated/api/RemoveLinkRequest.ts +4 -0
  307. package/src/generated/api/RemoveLinksBulkRequest.ts +4 -0
  308. package/src/generated/api/ResourceInput.ts +3 -0
  309. package/src/generated/api/SetDefaultModelRequest.ts +4 -0
  310. package/src/generated/api/SetFreeHostingEnabledRequest.ts +3 -0
  311. package/src/generated/api/SetMultiUserRequest.ts +3 -0
  312. package/src/generated/api/SetStatusRequest.ts +3 -0
  313. package/src/generated/api/SignMessageRequest.ts +3 -0
  314. package/src/generated/api/TrustedAgentsRequest.ts +3 -0
  315. package/src/generated/api/UnlockAgentRequest.ts +3 -0
  316. package/src/generated/api/UpdateLinkRequest.ts +5 -0
  317. package/src/generated/api/UpdatePerspectiveRequest.ts +3 -0
  318. package/src/generated/api/UserStatistics.ts +3 -0
  319. package/src/generated/api/VerificationRequestResult.ts +3 -0
  320. package/src/generated/api/VerifySignatureRequest.ts +3 -0
  321. package/src/generated/api/WriteSettingsRequest.ts +3 -0
  322. package/src/generated/api/index.ts +49 -0
  323. package/src/index.ts +8 -2
  324. package/src/jestSetup.ts +1 -1
  325. package/src/language/Icon.ts +0 -4
  326. package/src/language/Language.ts +51 -248
  327. package/src/language/LanguageClient.ts +21 -132
  328. package/src/language/LanguageHandle.ts +0 -14
  329. package/src/language/LanguageMeta.ts +0 -29
  330. package/src/language/LanguageRef.ts +0 -7
  331. package/src/links/Links.ts +0 -37
  332. package/src/model/Ad4mModel.test.ts +1664 -792
  333. package/src/model/Ad4mModel.ts +664 -499
  334. package/src/model/ModelQueryBuilder.ts +362 -183
  335. package/src/model/decorators.ts +71 -22
  336. package/src/model/hydration.ts +3 -772
  337. package/src/model/index.ts +3 -4
  338. package/src/model/json-schema.ts +2 -2
  339. package/src/model/query-cache.test.ts +54 -0
  340. package/src/model/query-cache.ts +79 -0
  341. package/src/model/query-common.ts +1 -1
  342. package/src/model/query-sparql.test.ts +376 -0
  343. package/src/model/query-sparql.ts +504 -0
  344. package/src/model/query-utils.ts +209 -0
  345. package/src/model/relation-filtering.test.ts +60 -53
  346. package/src/model/sdna.ts +1 -1
  347. package/src/model/shacl-gen.ts +163 -64
  348. package/src/model/shacl-roundtrip.test.ts +197 -0
  349. package/src/model/types-typed-query.test.ts +360 -0
  350. package/src/model/types.ts +256 -5
  351. package/src/neighbourhood/Neighbourhood.ts +0 -9
  352. package/src/neighbourhood/NeighbourhoodClient.ts +42 -207
  353. package/src/neighbourhood/NeighbourhoodProxy.test.ts +34 -36
  354. package/src/perspectives/LinkQuery.ts +0 -15
  355. package/src/perspectives/Perspective.ts +1 -12
  356. package/src/perspectives/PerspectiveClient.test.ts +262 -0
  357. package/src/perspectives/PerspectiveClient.ts +252 -468
  358. package/src/perspectives/PerspectiveDiff.ts +0 -8
  359. package/src/perspectives/PerspectiveHandle.ts +1 -12
  360. package/src/perspectives/PerspectiveProxy.test.ts +125 -0
  361. package/src/perspectives/PerspectiveProxy.ts +522 -434
  362. package/src/perspectives/SparqlBindings.ts +79 -0
  363. package/src/perspectives/WakerSubscriptionManager.ts +13 -13
  364. package/src/runtime/RuntimeClient.ts +118 -461
  365. package/src/runtime/RuntimeTypes.ts +144 -0
  366. package/src/shacl/SHACLFlow.ts +9 -9
  367. package/src/shacl/SHACLShape.test.ts +204 -0
  368. package/src/shacl/SHACLShape.ts +191 -39
  369. package/src/typeDefs.ts +3 -5
  370. package/src/utils.ts +6 -6
  371. package/tsconfig.json +3 -7
  372. package/lib/src/model/query-surreal.d.ts +0 -44
  373. package/lib/src/model/query-surreal.js +0 -249
  374. package/lib/src/model/surreal-utils.js +0 -128
  375. package/shims/reflect-metadata.ts +0 -0
  376. package/shims/type-graphql.ts +0 -75
  377. package/src/PubSub.ts +0 -17
  378. package/src/agent/AgentResolver.ts +0 -263
  379. package/src/ai/AIResolver.ts +0 -372
  380. package/src/buildSchema.ts +0 -43
  381. package/src/expression/ExpressionResolver.ts +0 -64
  382. package/src/language/LanguageContext.ts +0 -37
  383. package/src/language/LanguageResolver.ts +0 -98
  384. package/src/model/Subject.ts +0 -159
  385. package/src/model/prolog-facts.ts +0 -145
  386. package/src/model/query-prolog.ts +0 -148
  387. package/src/model/query-surreal.ts +0 -280
  388. package/src/model/surreal-utils.ts +0 -147
  389. package/src/neighbourhood/NeighbourhoodResolver.ts +0 -100
  390. package/src/perspectives/PerspectiveResolver.ts +0 -372
  391. package/src/runtime/RuntimeResolver.ts +0 -691
  392. package/src/unwrapApolloResult.ts +0 -16
  393. package/tsconfig-browser.json +0 -82
@@ -0,0 +1 @@
1
+ export {};
@@ -0,0 +1,224 @@
1
+ import { PerspectiveClient } from "./PerspectiveClient";
2
+ import { PerspectiveHandle, PerspectiveState } from "./PerspectiveHandle";
3
+ /**
4
+ * Focused unit tests for PerspectiveClient proxy cache behaviour.
5
+ * Uses a mock Apollo client to isolate cache logic from network.
6
+ */
7
+ // Minimal mock Apollo client that returns controllable results
8
+ function createMockApolloClient(overrides = {}) {
9
+ return {
10
+ query: overrides.query || jest.fn().mockResolvedValue({ data: {} }),
11
+ mutate: overrides.mutate || jest.fn().mockResolvedValue({ data: {} }),
12
+ subscribe: overrides.subscribe || jest.fn().mockReturnValue({
13
+ subscribe: jest.fn()
14
+ }),
15
+ };
16
+ }
17
+ function makeHandle(uuid, name, state = PerspectiveState.Private) {
18
+ const h = new PerspectiveHandle(uuid, name, state);
19
+ return h;
20
+ }
21
+ describe('PerspectiveClient proxy cache', () => {
22
+ it('byUUID returns the same proxy reference on cache hit', async () => {
23
+ const handle = makeHandle('uuid-1', 'Test');
24
+ const mockClient = createMockApolloClient({
25
+ query: jest.fn().mockResolvedValue({
26
+ data: { perspective: handle }
27
+ }),
28
+ });
29
+ const client = new PerspectiveClient(mockClient, false);
30
+ const p1 = await client.byUUID('uuid-1');
31
+ const p2 = await client.byUUID('uuid-1');
32
+ expect(p1).toBe(p2);
33
+ // Only one query should have been made (second is cache hit)
34
+ expect(mockClient.query).toHaveBeenCalledTimes(1);
35
+ });
36
+ it('byUUID returns null for non-existent perspectives', async () => {
37
+ const mockClient = createMockApolloClient({
38
+ query: jest.fn().mockResolvedValue({
39
+ data: { perspective: null }
40
+ }),
41
+ });
42
+ const client = new PerspectiveClient(mockClient, false);
43
+ const p = await client.byUUID('non-existent');
44
+ expect(p).toBeNull();
45
+ });
46
+ it('all() populates cache so subsequent byUUID is a hit', async () => {
47
+ const handles = [
48
+ makeHandle('uuid-a', 'A'),
49
+ makeHandle('uuid-b', 'B'),
50
+ ];
51
+ const queryFn = jest.fn()
52
+ .mockResolvedValueOnce({ data: { perspectives: handles } });
53
+ const mockClient = createMockApolloClient({ query: queryFn });
54
+ const client = new PerspectiveClient(mockClient, false);
55
+ const all = await client.all();
56
+ expect(all.length).toBe(2);
57
+ // byUUID should be a cache hit — no additional query
58
+ const pa = await client.byUUID('uuid-a');
59
+ expect(pa).toBe(all[0]);
60
+ expect(queryFn).toHaveBeenCalledTimes(1); // only the all() query
61
+ });
62
+ it('add() populates cache', async () => {
63
+ const handle = makeHandle('uuid-new', 'New');
64
+ const mockClient = createMockApolloClient({
65
+ mutate: jest.fn().mockResolvedValue({
66
+ data: { perspectiveAdd: handle }
67
+ }),
68
+ });
69
+ const client = new PerspectiveClient(mockClient, false);
70
+ const added = await client.add('New');
71
+ expect(added.uuid).toBe('uuid-new');
72
+ // byUUID should hit cache
73
+ const fetched = await client.byUUID('uuid-new');
74
+ expect(fetched).toBe(added);
75
+ });
76
+ it('update() evicts and recreates cached proxy', async () => {
77
+ const originalHandle = makeHandle('uuid-u', 'Original');
78
+ const updatedHandle = makeHandle('uuid-u', 'Updated');
79
+ const queryFn = jest.fn().mockResolvedValue({
80
+ data: { perspective: originalHandle }
81
+ });
82
+ const mutateFn = jest.fn().mockResolvedValue({
83
+ data: { perspectiveUpdate: updatedHandle }
84
+ });
85
+ const mockClient = createMockApolloClient({
86
+ query: queryFn,
87
+ mutate: mutateFn,
88
+ });
89
+ const client = new PerspectiveClient(mockClient, false);
90
+ const original = await client.byUUID('uuid-u');
91
+ expect(original.name).toBe('Original');
92
+ const updated = await client.update('uuid-u', 'Updated');
93
+ expect(updated).not.toBe(original); // new reference after eviction
94
+ expect(updated.name).toBe('Updated');
95
+ expect(original.name).toBe('Original'); // old reference retains stale data
96
+ });
97
+ it('remove() evicts from cache', async () => {
98
+ const handle = makeHandle('uuid-r', 'ToRemove');
99
+ const queryFn = jest.fn().mockResolvedValue({
100
+ data: { perspective: handle }
101
+ });
102
+ const mutateFn = jest.fn().mockResolvedValue({
103
+ data: { perspectiveRemove: true }
104
+ });
105
+ const mockClient = createMockApolloClient({
106
+ query: queryFn,
107
+ mutate: mutateFn,
108
+ });
109
+ const client = new PerspectiveClient(mockClient, false);
110
+ const p = await client.byUUID('uuid-r');
111
+ expect(p).toBeTruthy();
112
+ expect(queryFn).toHaveBeenCalledTimes(1);
113
+ await client.remove('uuid-r');
114
+ // byUUID should miss cache and query again
115
+ const handle2 = makeHandle('uuid-r', 'Recreated');
116
+ queryFn.mockResolvedValueOnce({ data: { perspective: handle2 } });
117
+ const p2 = await client.byUUID('uuid-r');
118
+ expect(p2).not.toBe(p);
119
+ expect(p2.name).toBe('Recreated');
120
+ expect(queryFn).toHaveBeenCalledTimes(2);
121
+ });
122
+ it('getOrCreateProxy does not re-register listeners on cache hit', async () => {
123
+ // Verify that getting the same proxy twice does not create duplicate subscriptions
124
+ const handle = makeHandle('uuid-dup', 'NoDuplicates');
125
+ const subscribeCalls = [];
126
+ const subscribeFn = jest.fn().mockImplementation((opts) => {
127
+ // Track subscription query names
128
+ const queryStr = opts.query?.loc?.source?.body || '';
129
+ subscribeCalls.push(queryStr);
130
+ return {
131
+ subscribe: jest.fn()
132
+ };
133
+ });
134
+ const queryFn = jest.fn()
135
+ .mockResolvedValueOnce({ data: { perspectives: [handle] } });
136
+ const mockClient = createMockApolloClient({
137
+ query: queryFn,
138
+ subscribe: subscribeFn,
139
+ });
140
+ const client = new PerspectiveClient(mockClient, false);
141
+ const all = await client.all();
142
+ const firstProxy = all[0];
143
+ // Record how many subscribe calls happened from PerspectiveProxy constructor
144
+ const callsAfterFirst = subscribeFn.mock.calls.length;
145
+ // Get same proxy again via all() — should be cache hit, no new constructor call
146
+ queryFn.mockResolvedValueOnce({ data: { perspectives: [handle] } });
147
+ const all2 = await client.all();
148
+ const secondProxy = all2[0];
149
+ expect(secondProxy).toBe(firstProxy);
150
+ // No additional subscribe calls should have been made
151
+ expect(subscribeFn.mock.calls.length).toBe(callsAfterFirst);
152
+ });
153
+ it('all() updates existing cached proxies with fresh data', async () => {
154
+ const handle1 = makeHandle('uuid-f', 'OldName');
155
+ const handle2 = makeHandle('uuid-f', 'FreshName');
156
+ const queryFn = jest.fn()
157
+ .mockResolvedValueOnce({ data: { perspective: handle1 } })
158
+ .mockResolvedValueOnce({ data: { perspectives: [handle2] } });
159
+ const mockClient = createMockApolloClient({ query: queryFn });
160
+ const client = new PerspectiveClient(mockClient, false);
161
+ const original = await client.byUUID('uuid-f');
162
+ expect(original.name).toBe('OldName');
163
+ const all = await client.all();
164
+ const refreshed = all.find(p => p.uuid === 'uuid-f');
165
+ expect(refreshed).toBe(original); // same reference
166
+ expect(refreshed.name).toBe('FreshName'); // updated in-place
167
+ expect(original.name).toBe('FreshName'); // original ref also updated
168
+ });
169
+ });
170
+ describe('PerspectiveProxy getClassShape sh:in URI-decoding', () => {
171
+ // This tests the sh:in parsing logic in getClassShape() which was fixed
172
+ // to URI-decode values from the Rust executor's SPARQL results
173
+ function parseShInValue(raw) {
174
+ // Reproduce the exact parsing logic from PerspectiveProxy.getClassShape()
175
+ try {
176
+ if (raw.startsWith('literal:string:')) {
177
+ raw = decodeURIComponent(raw.substring('literal:string:'.length));
178
+ }
179
+ return JSON.parse(raw);
180
+ }
181
+ catch {
182
+ return undefined;
183
+ }
184
+ }
185
+ it('parses plain JSON sh:in values', () => {
186
+ const result = parseShInValue('[{"value":"a"},{"value":"b","label":"B"}]');
187
+ expect(result).toEqual([
188
+ { value: 'a' },
189
+ { value: 'b', label: 'B' },
190
+ ]);
191
+ });
192
+ it('strips literal:string: prefix and parses', () => {
193
+ const result = parseShInValue('literal:string:[{"value":"x"},{"value":"y"}]');
194
+ expect(result).toEqual([
195
+ { value: 'x' },
196
+ { value: 'y' },
197
+ ]);
198
+ });
199
+ it('URI-decodes encoded sh:in values from Rust executor', () => {
200
+ // Rust executor may URI-encode the JSON when returning SPARQL results
201
+ const encoded = 'literal:string:' + encodeURIComponent('[{"value":"hello world"},{"value":"a&b"}]');
202
+ const result = parseShInValue(encoded);
203
+ expect(result).toEqual([
204
+ { value: 'hello world' },
205
+ { value: 'a&b' },
206
+ ]);
207
+ });
208
+ it('handles double-encoded brackets and quotes', () => {
209
+ const encoded = 'literal:string:%5B%7B%22value%22%3A%22active%22%7D%2C%7B%22value%22%3A%22inactive%22%7D%5D';
210
+ const result = parseShInValue(encoded);
211
+ expect(result).toEqual([
212
+ { value: 'active' },
213
+ { value: 'inactive' },
214
+ ]);
215
+ });
216
+ it('returns undefined for malformed JSON', () => {
217
+ const result = parseShInValue('literal:string:not-json');
218
+ expect(result).toBeUndefined();
219
+ });
220
+ it('handles already-decoded values without prefix', () => {
221
+ const result = parseShInValue('[{"value":"test"}]');
222
+ expect(result).toEqual([{ value: 'test' }]);
223
+ });
224
+ });
@@ -1,33 +1,6 @@
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 { LinkExpression } from "../links/Links";
13
- let PerspectiveDiff = class PerspectiveDiff {
14
- };
15
- __decorate([
16
- Field(type => [LinkExpression]),
17
- __metadata("design:type", Array)
18
- ], PerspectiveDiff.prototype, "additions", void 0);
19
- __decorate([
20
- Field(type => [LinkExpression]),
21
- __metadata("design:type", Array)
22
- ], PerspectiveDiff.prototype, "removals", void 0);
23
- PerspectiveDiff = __decorate([
24
- ObjectType()
25
- ], PerspectiveDiff);
26
- export { PerspectiveDiff };
27
- let PerspectiveDiffExpression = class PerspectiveDiffExpression extends ExpressionGeneric(PerspectiveDiff) {
28
- };
29
- PerspectiveDiffExpression = __decorate([
30
- ObjectType()
31
- ], PerspectiveDiffExpression);
32
- export { PerspectiveDiffExpression };
2
+ export class PerspectiveDiff {
3
+ }
4
+ export class PerspectiveDiffExpression extends ExpressionGeneric(PerspectiveDiff) {
5
+ }
33
6
  ;
@@ -1,14 +1,3 @@
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
- import { NeighbourhoodExpression } from "../neighbourhood/Neighbourhood";
12
1
  export var PerspectiveState;
13
2
  (function (PerspectiveState) {
14
3
  PerspectiveState["Private"] = "PRIVATE";
@@ -18,10 +7,10 @@ export var PerspectiveState;
18
7
  PerspectiveState["LinkLanguageInstalledButNotSynced"] = "LINK_LANGUAGE_INSTALLED_BUT_NOT_SYNCED";
19
8
  PerspectiveState["Synced"] = "SYNCED";
20
9
  })(PerspectiveState || (PerspectiveState = {}));
21
- // This type is used in the GraphQL interface to reference a mutable
10
+ // This type is used in the REST interface to reference a mutable
22
11
  // prespective that is implemented locally by the Ad4m runtime.
23
12
  // The UUID is used in mutations to identify the perspective that gets mutated.
24
- let PerspectiveHandle = class PerspectiveHandle {
13
+ export class PerspectiveHandle {
25
14
  constructor(uuid, name, state) {
26
15
  this.uuid = uuid;
27
16
  this.name = name;
@@ -32,33 +21,4 @@ let PerspectiveHandle = class PerspectiveHandle {
32
21
  this.state = PerspectiveState.Private;
33
22
  }
34
23
  }
35
- };
36
- __decorate([
37
- Field(),
38
- __metadata("design:type", String)
39
- ], PerspectiveHandle.prototype, "uuid", void 0);
40
- __decorate([
41
- Field(),
42
- __metadata("design:type", String)
43
- ], PerspectiveHandle.prototype, "name", void 0);
44
- __decorate([
45
- Field(),
46
- __metadata("design:type", String)
47
- ], PerspectiveHandle.prototype, "state", void 0);
48
- __decorate([
49
- Field(type => String, { nullable: true }),
50
- __metadata("design:type", String)
51
- ], PerspectiveHandle.prototype, "sharedUrl", void 0);
52
- __decorate([
53
- Field(type => NeighbourhoodExpression, { nullable: true }),
54
- __metadata("design:type", NeighbourhoodExpression)
55
- ], PerspectiveHandle.prototype, "neighbourhood", void 0);
56
- __decorate([
57
- Field(type => [String], { nullable: true }),
58
- __metadata("design:type", Array)
59
- ], PerspectiveHandle.prototype, "owners", void 0);
60
- PerspectiveHandle = __decorate([
61
- ObjectType(),
62
- __metadata("design:paramtypes", [String, String, String])
63
- ], PerspectiveHandle);
64
- export { PerspectiveHandle };
24
+ }
@@ -16,7 +16,7 @@ type QueryCallback = (result: AllInstancesResult) => void;
16
16
  * This class handles:
17
17
  * - Keeping the subscription alive by sending periodic keepalive signals
18
18
  * - Managing callbacks for result updates
19
- * - Subscribing to query updates via GraphQL subscriptions
19
+ * - Subscribing to query updates via WebSocket subscriptions
20
20
  * - Maintaining the latest query result
21
21
  * - Ensuring subscription is fully initialized before allowing access
22
22
  * - Cleaning up resources when disposed
@@ -46,7 +46,6 @@ type QueryCallback = (result: AllInstancesResult) => void;
46
46
  */
47
47
  export declare class QuerySubscriptionProxy {
48
48
  #private;
49
- isSurrealDB: boolean;
50
49
  /** Creates a new query subscription
51
50
  * @param uuid - The UUID of the perspective
52
51
  * @param query - The Prolog query to subscribe to
@@ -108,7 +107,7 @@ export declare class QuerySubscriptionProxy {
108
107
  *
109
108
  * This method:
110
109
  * 1. Stops the keepalive timer
111
- * 2. Unsubscribes from GraphQL subscription updates
110
+ * 2. Unsubscribes from subscription updates
112
111
  * 3. Clears all registered callbacks
113
112
  * 4. Cleans up any pending initialization timeout
114
113
  *
@@ -176,11 +175,16 @@ export declare class PerspectiveProxy {
176
175
  state: PerspectiveState | null;
177
176
  /** List of owners of this perspective */
178
177
  owners?: string[];
178
+ /** @internal Exposed for ModelQueryBuilder subscription management */
179
+ get client(): PerspectiveClient;
179
180
  /**
180
181
  * Creates a new PerspectiveProxy instance.
181
182
  * Note: Don't create this directly, use ad4m.perspective.add() instead.
182
183
  */
183
184
  constructor(handle: PerspectiveHandle, ad4m: PerspectiveClient);
185
+ /** Update the proxy's internal handle and public fields in-place.
186
+ * Keeps the same object reference so all holders see the update. */
187
+ updateHandle(handle: PerspectiveHandle): void;
184
188
  /**
185
189
  * Escapes special regex characters in a string to prevent ReDoS attacks
186
190
  * and regex injection when building dynamic regular expressions.
@@ -299,33 +303,66 @@ export declare class PerspectiveProxy {
299
303
  */
300
304
  infer(query: string): Promise<any>;
301
305
  /**
302
- * Executes a SurrealQL query against the perspective's link cache.
303
- * This allows powerful SQL-like queries on the link data stored in SurrealDB.
306
+ * Executes a SPARQL query against the perspective's link cache.
307
+ * This allows powerful SQL-like queries on the link data stored in SPARQL.
304
308
  *
305
309
  * **Security Note:** Only read-only queries (SELECT, RETURN, etc.) are permitted.
306
310
  * Mutating operations (DELETE, UPDATE, INSERT, CREATE, DROP, DEFINE, etc.) are
307
311
  * blocked for security reasons. Use the perspective's add/remove methods to modify links.
308
312
  *
309
- * @param query - SurrealQL query string (read-only operations only)
313
+ * @param query - SPARQL query string (read-only operations only)
310
314
  * @returns Query results as parsed JSON
311
315
  *
312
- * @example
313
- * ```typescript
314
- * // Get all links
315
- * const links = await perspective.querySurrealDB('SELECT * FROM link');
316
- *
317
- * // Filter links by predicate
318
- * const follows = await perspective.querySurrealDB(
319
- * "SELECT * FROM link WHERE predicate = 'follows'"
320
- * );
321
- *
322
- * // Complex aggregation query
323
- * const stats = await perspective.querySurrealDB(
324
- * "SELECT predicate, count() as total FROM link GROUP BY predicate"
325
- * );
326
- * ```
316
+ * Executes a SPARQL query against the perspective's RDF (Oxigraph) store.
317
+ *
318
+ * @param query - SPARQL query string
319
+ * @returns Query results as parsed JSON
320
+ */
321
+ querySparql<T = any>(query: string): Promise<T>;
322
+ /**
323
+ * Execute a model query — the executor-side replacement for SPARQL query building + JS hydration.
324
+ *
325
+ * The executor resolves the model's shape from the perspective's SHACL
326
+ * triples (written by `addSdna`). Callers no longer ship shape
327
+ * metadata with the query; the perspective is the source of truth.
328
+ *
329
+ * @param className - The model class name (e.g. "Recipe")
330
+ * @param queryJson - Structured query as JSON string
331
+ * @returns Object with `instances` array and `totalCount`
327
332
  */
328
- querySurrealDB(query: string): Promise<any>;
333
+ modelQuery(className: string, queryJson: string): Promise<{
334
+ instances: any[];
335
+ totalCount: number;
336
+ }>;
337
+ /**
338
+ * Evaluate property getters for a batch of instances in a single RPC call.
339
+ * Returns a map of `{ instanceId: { prop: value, ... } }`.
340
+ *
341
+ * Use this instead of `Ad4mModel.evaluateGetters()` for lazy-loading
342
+ * getter-backed properties on visible items (e.g. `replyingTo` on messages).
343
+ *
344
+ * @param className - The model class name (e.g. "Message")
345
+ * @param instanceIds - Array of instance base expression URIs
346
+ * @param propertyNames - Optional subset of property names to evaluate
347
+ * @returns Map of instance ID → evaluated property values
348
+ */
349
+ evaluateGetters(className: string, instanceIds: string[], propertyNames?: string[]): Promise<Record<string, Record<string, any>>>;
350
+ /**
351
+ * Subscribe to model query changes. Builds trigger SPARQL from the model shape
352
+ * internally in Rust, registers a subscription, runs the initial query, and
353
+ * pushes updated results when relevant links change.
354
+ *
355
+ * The subscription reuses the same GraphQL subscription channel as subscribeQuery().
356
+ * Use keepAliveQuery() / disposeQuerySubscription() with the returned subscriptionId.
357
+ *
358
+ * @param className - The model class name
359
+ * @param queryJson - JSON-serialized query parameters (same as modelQuery)
360
+ * @returns Object with `subscriptionId` and initial `result`
361
+ */
362
+ modelSubscribe(className: string, queryJson: string): Promise<{
363
+ subscriptionId: string;
364
+ result: any;
365
+ }>;
329
366
  /**
330
367
  * Adds a new link to the perspective.
331
368
  *
@@ -462,6 +499,10 @@ export declare class PerspectiveProxy {
462
499
  * @param cb - The callback function to remove
463
500
  */
464
501
  removeListener(type: PerspectiveListenerTypes, cb: LinkCallback): Promise<void>;
502
+ /** Clean up all subscriptions registered by this proxy.
503
+ * Call this when the proxy is no longer needed to prevent subscription leaks.
504
+ * After calling dispose(), the proxy should not be used. */
505
+ dispose(): void;
465
506
  /**
466
507
  * Creates a snapshot of the current perspective state.
467
508
  * Useful for backup or sharing.
@@ -535,7 +576,7 @@ export declare class PerspectiveProxy {
535
576
  * Adds Social DNA code to the perspective.
536
577
  *
537
578
  * **Recommended:** Use {@link addShacl} instead, which accepts the `SHACLShape` type directly.
538
- * This method is primarily for the GraphQL layer and legacy Prolog code.
579
+ * This method is primarily for the RPC API layer and legacy Prolog code.
539
580
  *
540
581
  * @param name - Unique name for this SDNA definition
541
582
  * @param sdnaCode - Prolog SDNA code (legacy, can be empty string if shaclJson provided)
@@ -552,6 +593,26 @@ export declare class PerspectiveProxy {
552
593
  * await perspective.addSdna('Recipe', prologCode, 'subject_class');
553
594
  */
554
595
  addSdna(name: string, sdnaCode: string, sdnaType: "subject_class" | "flow" | "custom", shaclJson?: string): Promise<boolean>;
596
+ /**
597
+ * Batch variant of addSdna — registers multiple SDNA entries in a single RPC call.
598
+ * Acquires the Rust-side mutex once for the entire batch.
599
+ */
600
+ addSdnaAll(entries: {
601
+ name: string;
602
+ sdnaCode?: string;
603
+ sdnaType: "subject_class" | "flow" | "custom";
604
+ shaclJson?: string;
605
+ }[]): Promise<boolean[]>;
606
+ /**
607
+ * Batch-registers multiple model classes as SHACL subject classes in a single RPC call.
608
+ * Skips classes already registered on this perspective instance.
609
+ */
610
+ ensureSubjectClasses(jsClasses: any[]): Promise<void>;
611
+ /**
612
+ * Adds a subject class to the perspective.
613
+ * Alias for addSdna() with sdnaType='subject_class'.
614
+ */
615
+ addSubjectClass(name: string, shaclJson: string): Promise<boolean>;
555
616
  /**
556
617
  * **Recommended way to add SDNA schemas.**
557
618
  *
@@ -679,21 +740,11 @@ export declare class PerspectiveProxy {
679
740
  * that matches the given properties will be used.
680
741
  */
681
742
  isSubjectInstance<T>(expression: string, subjectClass: T): Promise<boolean>;
682
- /** For an existing subject instance (existing in the perspective's links)
683
- * this function returns a proxy object that can be used to access the subject's
684
- * properties and methods.
685
- *
686
- * @param base URI of the subject's root expression
687
- * @param subjectClass Either a string with the name of the subject class, or an object
688
- * with the properties of the subject class. In the latter case, the first subject class
689
- * that matches the given properties will be used.
690
- */
691
- getSubjectProxy<T>(base: string, subjectClass: T): Promise<T>;
692
743
  /**
693
744
  * Gets subject class metadata from SHACL links using SHACLShape.fromLinks().
694
745
  * Retrieves the SHACL shape and extracts metadata for instance queries.
695
746
  */
696
- getSubjectClassMetadataFromSDNA(className: string): Promise<{
747
+ getSubjectClassMetadata(className: string): Promise<{
697
748
  requiredPredicates: string[];
698
749
  requiredTriples: Array<{
699
750
  predicate: string;
@@ -710,56 +761,19 @@ export declare class PerspectiveProxy {
710
761
  }>;
711
762
  } | null>;
712
763
  /**
713
- * Generates a SurrealDB query to find instances based on class metadata.
714
- */
715
- private generateSurrealInstanceQuery;
716
- /**
717
- * Gets a property value using SurrealDB when Prolog fails.
718
- * This is used as a fallback in SdnaOnly mode where link data isn't in Prolog.
719
- */
720
- getPropertyValueViaSurreal(baseExpression: string, className: string, propertyName: string): Promise<any>;
721
- /**
722
- * Gets relation values using SurrealDB when Prolog fails.
723
- * This is used as a fallback in SdnaOnly mode where link data isn't in Prolog.
724
- * Note: This is used by Subject.ts (legacy pattern). Ad4mModel.ts uses getModelMetadata() instead.
725
- */
726
- getRelationValuesViaSurreal(baseExpression: string, className: string, relationName: string): Promise<any[]>;
727
- /**
728
- * Batch-checks multiple expressions against subject class metadata using a single or limited SurrealDB queries.
729
- * This avoids N+1 query problems by checking all values at once.
764
+ * Generates a SPARQL query to find instances based on class metadata.
730
765
  */
731
- batchCheckSubjectInstances(expressions: string[], metadata: {
732
- requiredPredicates: string[];
733
- requiredTriples: Array<{
734
- predicate: string;
735
- target?: string;
736
- }>;
737
- properties: Map<string, {
738
- predicate: string;
739
- resolveLanguage?: string;
740
- }>;
741
- relations: Map<string, {
742
- predicate: string;
743
- instanceFilter?: string;
744
- condition?: string;
745
- }>;
746
- }): Promise<string[]>;
747
766
  /**
748
- * Fallback sequential instance checking when batch checking isn't available.
767
+ * Finds all instances matching subject class metadata by querying links.
768
+ * Returns base URIs of matching instances.
749
769
  */
750
- private filterInstancesSequential;
770
+ private findInstancesByMetadata;
751
771
  /** Returns all subject instances of the given subject class as proxy objects.
752
772
  * @param subjectClass Either a string with the name of the subject class, or an object
753
773
  * with the properties of the subject class. In the latter case, all subject classes
754
774
  * that match the given properties will be used.
755
775
  */
756
776
  getAllSubjectInstances<T>(subjectClass: T): Promise<T[]>;
757
- /** Returns all subject proxies of the given subject class as proxy objects.
758
- * @param subjectClass Either a string with the name of the subject class, or an object
759
- * with the properties of the subject class. In the latter case, all subject classes
760
- * that match the given properties will be used.
761
- */
762
- getAllSubjectProxies<T>(subjectClass: T): Promise<T[]>;
763
777
  /**
764
778
  * Find a subject class by matching an object's properties/relations against SHACL shapes.
765
779
  * Queries SHACL links client-side to find a class whose properties contain all required ones.
@@ -785,6 +799,70 @@ export declare class PerspectiveProxy {
785
799
  * static generateSDNA() function and adds it to the perspective's SDNA.
786
800
  */
787
801
  ensureSDNASubjectClass(jsClass: any): Promise<void>;
802
+ /** Takes a JS class (its constructor) and ensures the SHACL subject class exists. */
803
+ ensureSubjectClass(jsClass: any): Promise<void>;
804
+ /** Clear the per-instance ensured subject class cache.
805
+ * Call this after wiping a perspective's links so that
806
+ * subsequent register() calls re-add SHACL definitions. */
807
+ clearEnsuredSubjectClasses(): void;
808
+ /**
809
+ * Returns a list of all class names that have been registered as SHACL
810
+ * subject classes in this perspective (via `ensureSDNASubjectClass` or `addSdna`).
811
+ *
812
+ * @returns Array of class name strings (e.g. `["Channel", "Message", "Task"]`)
813
+ */
814
+ listRegisteredClasses(): Promise<string[]>;
815
+ /**
816
+ * Returns the SHACL shape metadata for a registered class, including
817
+ * property names, predicates, datatypes, and cardinality constraints.
818
+ *
819
+ * @param className - The name of the registered class
820
+ * @returns Shape metadata or `null` if the class is not registered
821
+ */
822
+ getClassShape(className: string): Promise<{
823
+ className: string;
824
+ shapeUri: string;
825
+ properties: Array<{
826
+ name: string;
827
+ predicate: string;
828
+ datatype?: string;
829
+ required: boolean;
830
+ collection: boolean;
831
+ writable: boolean;
832
+ options?: Array<{
833
+ value: string;
834
+ label?: string;
835
+ }>;
836
+ }>;
837
+ } | null>;
838
+ /**
839
+ * Detects which registered subject classes a given instance conforms to,
840
+ * based on its stored triples matching the class shapes' required properties.
841
+ *
842
+ * @param baseExpression - The instance's base expression / subject URI
843
+ * @returns Array of class names the instance matches
844
+ */
845
+ getInstanceClasses(baseExpression: string): Promise<string[]>;
846
+ /**
847
+ * Returns all named options (sh:in values) for a registered class, grouped by property.
848
+ *
849
+ * @param className - The name of the registered class
850
+ * @returns Record mapping property name → array of { value, label } options
851
+ */
852
+ getNamedOptions(className: string): Promise<Record<string, Array<{
853
+ value: string;
854
+ label?: string;
855
+ }>>>;
856
+ /**
857
+ * Adds a named option (sh:in value) to a property of a registered class.
858
+ * This appends to the existing sh:in list stored on the property shape.
859
+ *
860
+ * @param className - The registered class name
861
+ * @param propertyName - The property to add the option to
862
+ * @param value - The RDF value for the option
863
+ * @param label - Optional human-readable label
864
+ */
865
+ addNamedOption(className: string, propertyName: string, value: string, label?: string): Promise<void>;
788
866
  getNeighbourhoodProxy(): NeighbourhoodProxy;
789
867
  /**
790
868
  * Returns a proxy object for working with AI capabilities.
@@ -842,7 +920,7 @@ export declare class PerspectiveProxy {
842
920
  */
843
921
  subscribeInfer(query: string): Promise<QuerySubscriptionProxy>;
844
922
  /**
845
- * Creates a subscription for a SurrealQL query that updates in real-time.
923
+ * Creates a subscription for a SPARQL query that updates in real-time.
846
924
  *
847
925
  * This method:
848
926
  * 1. Creates the subscription on the Rust side
@@ -857,9 +935,10 @@ export declare class PerspectiveProxy {
857
935
  * when dispose() is called. Make sure to call dispose() when you're done to
858
936
  * prevent memory leaks and ensure proper cleanup of resources.
859
937
  *
860
- * @param query - SurrealQL query string
938
+ /** Subscribe to a query with live updates via the SPARQL subscription endpoint.
939
+ * @param query - Query string
861
940
  * @returns Initialized QuerySubscriptionProxy instance
862
941
  */
863
- subscribeSurrealDB(query: string): Promise<QuerySubscriptionProxy>;
942
+ subscribeQuery(query: string): Promise<QuerySubscriptionProxy>;
864
943
  }
865
944
  export {};