@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
@@ -1,10 +1,9 @@
1
- import { ApolloClient, gql } from "@apollo/client/core";
1
+ import { ApiClient, RpcError } from "../apiClient";
2
2
  import { ExpressionRendered } from "../expression/Expression";
3
3
  import { ExpressionClient } from "../expression/ExpressionClient";
4
- import { Link, LinkExpressionInput, LinkExpression, LinkInput, LinkMutations, LinkExpressionMutations } from "../links/Links";
4
+ import { Link, LinkExpressionInput, LinkExpression, LinkMutations, LinkExpressionMutations } from "../links/Links";
5
5
  import { NeighbourhoodClient } from "../neighbourhood/NeighbourhoodClient";
6
6
  import { NeighbourhoodProxy } from "../neighbourhood/NeighbourhoodProxy";
7
- import unwrapApolloResult from "../unwrapApolloResult";
8
7
  import { LinkQuery } from "./LinkQuery";
9
8
  import { Perspective } from "./Perspective";
10
9
  import { PerspectiveHandle, PerspectiveState } from "./PerspectiveHandle";
@@ -12,44 +11,27 @@ import { LinkStatus, PerspectiveProxy } from './PerspectiveProxy';
12
11
  import { AIClient } from "../ai/AIClient";
13
12
  import { AllInstancesResult } from "../model/types";
14
13
 
15
- const LINK_EXPRESSION_FIELDS = `
16
- author
17
- timestamp
18
- status
19
- data { source, predicate, target }
20
- proof { valid, invalid, signature, key }
21
- `
22
-
23
- const PERSPECTIVE_HANDLE_FIELDS = `
24
- uuid
25
- name
26
- sharedUrl
27
- state
28
- owners
29
- neighbourhood {
30
- data {
31
- linkLanguage
32
- meta {
33
- links
34
- {
35
- author
36
- timestamp
37
- data { source, predicate, target }
38
- proof { valid, invalid, signature, key }
39
- }
40
- }
41
- }
42
- author
43
- }
44
- `
45
-
46
14
  export type PerspectiveHandleCallback = (perspective: PerspectiveHandle) => null
47
15
  export type UuidCallback = (uuid: string) => null
48
16
  export type LinkCallback = (link: LinkExpression) => null
49
17
  export type SyncStateChangeCallback = (state: PerspectiveState) => null
50
18
 
19
+ function normalizeQueryResult(raw: unknown, errorContext: string): AllInstancesResult {
20
+ let finalResult: unknown = raw
21
+
22
+ if (typeof finalResult === 'string') {
23
+ try {
24
+ finalResult = JSON.parse(finalResult)
25
+ } catch (e) {
26
+ console.error(errorContext, e)
27
+ }
28
+ }
29
+
30
+ return finalResult as AllInstancesResult
31
+ }
32
+
51
33
  export class PerspectiveClient {
52
- #apolloClient: ApolloClient<any>
34
+ #apiClient: ApiClient
53
35
  #perspectiveAddedCallbacks: PerspectiveHandleCallback[]
54
36
  #perspectiveUpdatedCallbacks: PerspectiveHandleCallback[]
55
37
  #perspectiveRemovedCallbacks: UuidCallback[]
@@ -57,13 +39,19 @@ export class PerspectiveClient {
57
39
  #expressionClient?: ExpressionClient
58
40
  #neighbourhoodClient?: NeighbourhoodClient
59
41
  #aiClient?: AIClient
42
+ #unsubscribers: (() => void)[]
43
+ #linkUnsubscribers: Map<string, (() => void)[]>
44
+ #querySubscriptionUnsubscribers: Map<string, () => void>
60
45
 
61
- constructor(client: ApolloClient<any>, subscribe: boolean = true) {
62
- this.#apolloClient = client
46
+ constructor(baseUrl: string, token?: string, subscribe: boolean = true, sharedApiClient?: ApiClient) {
47
+ this.#apiClient = sharedApiClient || new ApiClient(baseUrl, token)
63
48
  this.#perspectiveAddedCallbacks = []
64
49
  this.#perspectiveUpdatedCallbacks = []
65
50
  this.#perspectiveRemovedCallbacks = []
66
51
  this.#perspectiveSyncStateChangeCallbacks = []
52
+ this.#unsubscribers = []
53
+ this.#linkUnsubscribers = new Map()
54
+ this.#querySubscriptionUnsubscribers = new Map()
67
55
 
68
56
  if(subscribe) {
69
57
  this.subscribePerspectiveAdded()
@@ -85,335 +73,192 @@ export class PerspectiveClient {
85
73
  }
86
74
 
87
75
  get aiClient(): AIClient {
88
- return this.#aiClient
76
+ return this.#aiClient!
89
77
  }
90
78
 
91
79
  async all(): Promise<PerspectiveProxy[]> {
92
- const { perspectives } = unwrapApolloResult(await this.#apolloClient.query({
93
- query: gql`query perspectives {
94
- perspectives {
95
- ${PERSPECTIVE_HANDLE_FIELDS}
96
- }
97
- }`
98
- }))
80
+ const perspectives = await this.#apiClient.call<PerspectiveHandle[]>('perspective.all')
99
81
  return perspectives.map(handle => new PerspectiveProxy(handle, this))
100
82
  }
101
83
 
102
84
  async byUUID(uuid: string): Promise<PerspectiveProxy|null> {
103
- const { perspective } = unwrapApolloResult(await this.#apolloClient.query({
104
- query: gql`query perspective($uuid: String!) {
105
- perspective(uuid: $uuid) {
106
- ${PERSPECTIVE_HANDLE_FIELDS}
107
- }
108
- }`,
109
- variables: { uuid }
110
- }))
111
- if(!perspective) return null
112
- return new PerspectiveProxy(perspective, this)
85
+ try {
86
+ const perspective = await this.#apiClient.call<PerspectiveHandle>('perspective.get', { uuid })
87
+ if(!perspective) return null
88
+ return new PerspectiveProxy(perspective, this)
89
+ } catch(e) {
90
+ if (e instanceof RpcError && e.status === 404) return null
91
+ throw e
92
+ }
113
93
  }
114
94
 
115
95
  async snapshotByUUID(uuid: string): Promise<Perspective|null> {
116
- const { perspectiveSnapshot } = unwrapApolloResult(await this.#apolloClient.query({
117
- query: gql`query perspectiveSnapshot($uuid: String!) {
118
- perspectiveSnapshot(uuid: $uuid) {
119
- links { ${LINK_EXPRESSION_FIELDS} }
120
- }
121
- }`,
122
- variables: { uuid }
123
- }))
124
- return perspectiveSnapshot
96
+ return this.#apiClient.call<Perspective|null>('perspective.snapshot', { uuid })
125
97
  }
98
+
126
99
  async publishSnapshotByUUID(uuid: string): Promise<string|null> {
127
- const { perspectivePublishSnapshot } = unwrapApolloResult(await this.#apolloClient.mutate({
128
- mutation: gql`mutation perspectivePublishSnapshot($uuid: String!) {
129
- perspectivePublishSnapshot(uuid: $uuid)
130
- }`,
131
- variables: { uuid }
132
- }))
133
- return perspectivePublishSnapshot
100
+ return this.#apiClient.call<string|null>('perspective.publishSnapshot', { uuid })
134
101
  }
135
102
 
136
103
  async queryLinks(uuid: string, query: LinkQuery): Promise<LinkExpression[]> {
137
- const { perspectiveQueryLinks } = unwrapApolloResult(await this.#apolloClient.query({
138
- query: gql`query perspectiveQueryLinks($uuid: String!, $query: LinkQuery!) {
139
- perspectiveQueryLinks(query: $query, uuid: $uuid) {
140
- ${LINK_EXPRESSION_FIELDS}
141
- }
142
- }`,
143
- variables: { uuid, query }
144
- }))
145
- return perspectiveQueryLinks
146
- }
147
-
148
- async queryProlog(uuid: string, query: string): Promise<any> {
149
- const { perspectiveQueryProlog } = unwrapApolloResult(await this.#apolloClient.query({
150
- query: gql`query perspectiveQueryProlog($uuid: String!, $query: String!) {
151
- perspectiveQueryProlog(uuid: $uuid, query: $query)
152
- }`,
153
- variables: { uuid, query }
154
- }))
155
-
156
- return JSON.parse(perspectiveQueryProlog)
157
- }
158
-
159
- /**
160
- * Executes a read-only SurrealQL query against a perspective's link cache.
161
- *
162
- * Security: Only SELECT, RETURN, and other read-only queries are permitted.
163
- * Mutating operations (DELETE, UPDATE, INSERT, etc.) are blocked.
164
- *
165
- * Note: GraphQL field name is "perspectiveQuerySurrealDb" (lowercase "b" in "Db")
166
- * as generated from Rust method "perspective_query_surreal_db"
167
- */
168
- async querySurrealDB(uuid: string, query: string): Promise<any> {
169
- const { perspectiveQuerySurrealDb } = unwrapApolloResult(await this.#apolloClient.query({
170
- query: gql`query perspectiveQuerySurrealDb($uuid: String!, $query: String!) {
171
- perspectiveQuerySurrealDb(uuid: $uuid, query: $query)
172
- }`,
173
- variables: { uuid, query }
174
- }))
175
-
176
- return JSON.parse(perspectiveQuerySurrealDb)
177
- }
178
-
179
- async subscribeQuery(uuid: string, query: string): Promise<{ subscriptionId: string, result: AllInstancesResult, isInit?: boolean }> {
180
- const { perspectiveSubscribeQuery } = unwrapApolloResult(await this.#apolloClient.mutate({
181
- mutation: gql`mutation perspectiveSubscribeQuery($uuid: String!, $query: String!) {
182
- perspectiveSubscribeQuery(uuid: $uuid, query: $query) {
183
- subscriptionId
184
- result
185
- }
186
- }`,
187
- variables: { uuid, query }
188
- }))
189
- const { subscriptionId, result } = perspectiveSubscribeQuery
190
- let finalResult = result;
191
- let isInit = false;
192
- if(finalResult.startsWith("#init#")) {
193
- finalResult = finalResult.substring(6)
194
- isInit = true;
195
- }
196
- try {
197
- finalResult = JSON.parse(finalResult)
198
- } catch (e) {
199
- console.error('Error parsing perspectiveSubscribeQuery result:', e)
200
- }
201
- return { subscriptionId, result: finalResult, isInit }
104
+ const params: Record<string, unknown> = { uuid }
105
+ if (query.source) params.source = query.source
106
+ if (query.predicate) params.predicate = query.predicate
107
+ if (query.target) params.target = query.target
108
+ if (query.fromDate) params.fromDate = query.fromDate instanceof Date ? query.fromDate.toISOString() : String(query.fromDate)
109
+ if (query.untilDate) params.untilDate = query.untilDate instanceof Date ? query.untilDate.toISOString() : String(query.untilDate)
110
+ if (query.limit !== undefined) params.limit = query.limit
111
+ return this.#apiClient.call<LinkExpression[]>('perspective.queryLinks', params)
202
112
  }
203
113
 
204
- async perspectiveSubscribeSurrealQuery(uuid: string, query: string): Promise<{ subscriptionId: string, result: AllInstancesResult, isInit?: boolean }> {
205
- const { perspectiveSubscribeSurrealQuery } = unwrapApolloResult(await this.#apolloClient.mutate({
206
- mutation: gql`mutation perspectiveSubscribeSurrealQuery($uuid: String!, $query: String!) {
207
- perspectiveSubscribeSurrealQuery(uuid: $uuid, query: $query) {
208
- subscriptionId
209
- result
210
- }
211
- }`,
212
- variables: { uuid, query }
213
- }))
214
- const { subscriptionId, result } = perspectiveSubscribeSurrealQuery
215
- let finalResult = result;
216
- let isInit = false;
217
- if(finalResult.startsWith("#init#")) {
218
- finalResult = finalResult.substring(6)
219
- isInit = true;
220
- }
221
- try {
222
- finalResult = JSON.parse(finalResult)
223
- } catch (e) {
224
- console.error('Error parsing perspectiveSubscribeSurrealQuery result:', e)
225
- }
226
- return { subscriptionId, result: finalResult, isInit }
114
+ async queryProlog(uuid: string, query: string): Promise<unknown> {
115
+ const result = await this.#apiClient.call<string>('perspective.queryProlog', { uuid, query })
116
+ return JSON.parse(result)
227
117
  }
228
118
 
229
- async perspectiveKeepAliveSurrealQuery(uuid: string, subscriptionId: string): Promise<boolean> {
230
- const { perspectiveKeepAliveSurrealQuery } = unwrapApolloResult(await this.#apolloClient.mutate({
231
- mutation: gql`mutation perspectiveKeepAliveSurrealQuery($uuid: String!, $subscriptionId: String!) {
232
- perspectiveKeepAliveSurrealQuery(uuid: $uuid, subscriptionId: $subscriptionId)
233
- }`,
234
- variables: { uuid, subscriptionId }
235
- }))
119
+ async querySparql<T = any>(uuid: string, query: string): Promise<T> {
120
+ const result = await this.#apiClient.call<string>('perspective.querySparql', { uuid, engine: 'sparql', query })
121
+ return JSON.parse(result) as T
122
+ }
236
123
 
237
- return perspectiveKeepAliveSurrealQuery
124
+ async subscribeQuery(uuid: string, query: string): Promise<{ subscriptionId: string, result: AllInstancesResult }> {
125
+ const response = await this.#apiClient.call<{ subscriptionId: string, result: unknown }>(
126
+ 'perspective.subscribeQuery', { uuid, query }
127
+ )
128
+ const { subscriptionId, result } = response
129
+ const parsed = normalizeQueryResult(result, 'Error parsing subscribeQuery result:')
130
+ return { subscriptionId, result: parsed }
238
131
  }
239
132
 
240
- async perspectiveDisposeSurrealQuerySubscription(uuid: string, subscriptionId: string): Promise<boolean> {
241
- const { perspectiveDisposeSurrealQuerySubscription } = unwrapApolloResult(await this.#apolloClient.mutate({
242
- mutation: gql`mutation perspectiveDisposeSurrealQuerySubscription($uuid: String!, $subscriptionId: String!) {
243
- perspectiveDisposeSurrealQuerySubscription(uuid: $uuid, subscriptionId: $subscriptionId)
244
- }`,
245
- variables: { uuid, subscriptionId }
246
- }))
133
+ async perspectiveKeepAliveQuery(uuid: string, subscriptionId: string): Promise<boolean> {
134
+ return this.#apiClient.call<boolean>(
135
+ 'perspective.keepAliveQuery', { uuid, subscriptionId }
136
+ )
137
+ }
247
138
 
248
- return perspectiveDisposeSurrealQuerySubscription
139
+ async perspectiveDisposeQuerySubscription(uuid: string, subscriptionId: string): Promise<boolean> {
140
+ return this.#apiClient.call<boolean>(
141
+ 'perspective.disposeQuery', { uuid, subscriptionId }
142
+ )
249
143
  }
250
144
 
251
145
  subscribeToQueryUpdates(subscriptionId: string, onData: (result: AllInstancesResult) => void): () => void {
252
- const subscription = this.#apolloClient.subscribe({
253
- query: gql`
254
- subscription perspectiveQuerySubscription($subscriptionId: String!) {
255
- perspectiveQuerySubscription(subscriptionId: $subscriptionId)
256
- }
257
- `,
258
- variables: {
259
- subscriptionId
260
- }
261
- }).subscribe({
262
- next: (result) => {
263
- if (result.data && result.data.perspectiveQuerySubscription) {
264
- let finalResult = result.data.perspectiveQuerySubscription;
265
- let isInit = false;
266
- if(finalResult.startsWith("#init#")) {
267
- finalResult = finalResult.substring(6)
268
- isInit = true;
269
- }
270
- try {
271
- finalResult = JSON.parse(finalResult)
272
- if(isInit && typeof finalResult === 'object') {
273
- finalResult.isInit = true;
274
- }
275
- } catch (e) {
276
- console.error('Error parsing perspectiveQuerySubscription:', e)
277
- }
278
- onData(finalResult);
279
- }
280
- },
281
- error: (e) => console.error('Error in query subscription:', e)
282
- });
146
+ const unsub = this.#apiClient.subscribe(
147
+ (data) => {
148
+ const event = data as Record<string, unknown>
149
+ if (event.type !== 'query-subscription-update') return
150
+
151
+ const eventSubscriptionId = event.subscriptionId || event.subscription_id
152
+ if (eventSubscriptionId !== subscriptionId) return
283
153
 
284
- return () => subscription.unsubscribe();
154
+ const parsed = normalizeQueryResult(event.result, 'Error parsing query subscription:')
155
+ onData(parsed)
156
+ }
157
+ )
158
+ this.#querySubscriptionUnsubscribers.set(subscriptionId, unsub)
159
+ return unsub
285
160
  }
286
161
 
287
162
  async keepAliveQuery(uuid: string, subscriptionId: string): Promise<boolean> {
288
- const { perspectiveKeepAliveQuery } = unwrapApolloResult(await this.#apolloClient.mutate({
289
- mutation: gql`mutation perspectiveKeepAliveQuery($uuid: String!, $subscriptionId: String!) {
290
- perspectiveKeepAliveQuery(uuid: $uuid, subscriptionId: $subscriptionId)
291
- }`,
292
- variables: { uuid, subscriptionId }
293
- }))
294
-
295
- return perspectiveKeepAliveQuery
163
+ return this.#apiClient.call<boolean>(
164
+ 'perspective.keepAliveQuery', { uuid, subscriptionId }
165
+ )
296
166
  }
297
167
 
298
168
  async disposeQuerySubscription(uuid: string, subscriptionId: string): Promise<boolean> {
299
- const { perspectiveDisposeQuerySubscription } = unwrapApolloResult(await this.#apolloClient.mutate({
300
- mutation: gql`mutation perspectiveDisposeQuerySubscription($uuid: String!, $subscriptionId: String!) {
301
- perspectiveDisposeQuerySubscription(uuid: $uuid, subscriptionId: $subscriptionId)
302
- }`,
303
- variables: { uuid, subscriptionId }
304
- }))
169
+ const unsub = this.#querySubscriptionUnsubscribers.get(subscriptionId)
170
+ if (unsub) {
171
+ unsub()
172
+ this.#querySubscriptionUnsubscribers.delete(subscriptionId)
173
+ }
174
+ return this.#apiClient.call<boolean>(
175
+ 'perspective.disposeQuery', { uuid, subscriptionId }
176
+ )
177
+ }
178
+
179
+ async modelQuery(uuid: string, className: string, queryJson: string): Promise<any> {
180
+ const resultJson = await this.#apiClient.call<string>(
181
+ 'perspective.modelQuery', { uuid, class_name: className, query_json: queryJson }
182
+ )
183
+ return JSON.parse(resultJson)
184
+ }
185
+
186
+ async evaluateGetters(
187
+ uuid: string,
188
+ className: string,
189
+ instanceIds: string[],
190
+ propertyNames?: string[],
191
+ ): Promise<Record<string, Record<string, any>>> {
192
+ const resultJson = await this.#apiClient.call<string>(
193
+ 'perspective.evaluateGetters', {
194
+ uuid,
195
+ class_name: className,
196
+ instance_ids: instanceIds,
197
+ ...(propertyNames && { property_names: propertyNames }),
198
+ }
199
+ )
200
+ return JSON.parse(resultJson)
201
+ }
305
202
 
306
- return perspectiveDisposeQuerySubscription
203
+ async modelSubscribe(uuid: string, className: string, queryJson: string): Promise<{ subscriptionId: string, result: any }> {
204
+ const response = await this.#apiClient.call<{ subscription_id: string, result: string }>(
205
+ 'perspective.modelSubscribe', { uuid, class_name: className, query_json: queryJson }
206
+ )
207
+ return {
208
+ subscriptionId: response.subscription_id,
209
+ result: JSON.parse(response.result)
210
+ }
307
211
  }
308
212
 
309
213
  async add(name: string): Promise<PerspectiveProxy> {
310
- const { perspectiveAdd } = unwrapApolloResult(await this.#apolloClient.mutate({
311
- mutation: gql`mutation perspectiveAdd($name: String!) {
312
- perspectiveAdd(name: $name) {
313
- ${PERSPECTIVE_HANDLE_FIELDS}
314
- }
315
- }`,
316
- variables: { name }
317
- }))
318
- return new PerspectiveProxy(perspectiveAdd, this)
214
+ const handle = await this.#apiClient.call<PerspectiveHandle>('perspective.create', { name })
215
+ return new PerspectiveProxy(handle, this)
319
216
  }
320
217
 
321
218
  async update(uuid: string, name: string): Promise<PerspectiveProxy> {
322
- const { perspectiveUpdate } = unwrapApolloResult(await this.#apolloClient.mutate({
323
- mutation: gql`mutation perspectiveUpdate($uuid: String!, $name: String!) {
324
- perspectiveUpdate(uuid: $uuid, name: $name) {
325
- ${PERSPECTIVE_HANDLE_FIELDS}
326
- }
327
- }`,
328
- variables: { uuid, name }
329
- }))
330
- return new PerspectiveProxy(perspectiveUpdate, this)
219
+ const handle = await this.#apiClient.call<PerspectiveHandle>('perspective.update', { uuid, name })
220
+ return new PerspectiveProxy(handle, this)
331
221
  }
332
222
 
333
223
  async remove(uuid: string): Promise<{perspectiveRemove: boolean}> {
334
- return unwrapApolloResult(await this.#apolloClient.mutate({
335
- mutation: gql`mutation perspectiveRemove($uuid: String!) {
336
- perspectiveRemove(uuid: $uuid)
337
- }`,
338
- variables: { uuid }
339
- }))
224
+ const result = await this.#apiClient.call<boolean>('perspective.remove', { uuid })
225
+ return { perspectiveRemove: result }
340
226
  }
341
227
 
342
228
  async addLink(uuid: string, link: Link, status: LinkStatus = 'shared', batchId?: string): Promise<LinkExpression> {
343
- const { perspectiveAddLink } = unwrapApolloResult(await this.#apolloClient.mutate({
344
- mutation: gql`mutation perspectiveAddLink($uuid: String!, $link: LinkInput!, $status: String!, $batchId: String) {
345
- perspectiveAddLink(uuid: $uuid, link: $link, status: $status, batchId: $batchId) {
346
- ${LINK_EXPRESSION_FIELDS}
347
- }
348
- }`,
349
- variables: { uuid, link, status, batchId }
350
- }))
351
- return perspectiveAddLink
229
+ return this.#apiClient.call<LinkExpression>(
230
+ 'perspective.addLink', { uuid, link, status, batchId }
231
+ )
352
232
  }
353
233
 
354
234
  async addLinks(uuid: string, links: Link[], status: LinkStatus = 'shared', batchId?: string): Promise<LinkExpression[]> {
355
- const { perspectiveAddLinks } = unwrapApolloResult(await this.#apolloClient.mutate({
356
- mutation: gql`mutation perspectiveAddLinks($uuid: String!, $links: [LinkInput!]!, $status: String!, $batchId: String) {
357
- perspectiveAddLinks(uuid: $uuid, links: $links, status: $status, batchId: $batchId) {
358
- ${LINK_EXPRESSION_FIELDS}
359
- }
360
- }`,
361
- variables: { uuid, links, status, batchId }
362
- }))
363
- return perspectiveAddLinks
235
+ return this.#apiClient.call<LinkExpression[]>(
236
+ 'perspective.addLinks', { uuid, links, status, batchId }
237
+ )
364
238
  }
365
239
 
366
240
  async removeLinks(uuid: string, links: LinkExpressionInput[], batchId?: string): Promise<LinkExpression[]> {
367
- const { perspectiveRemoveLinks } = unwrapApolloResult(await this.#apolloClient.mutate({
368
- mutation: gql`mutation perspectiveRemoveLinks($uuid: String!, $links: [LinkExpressionInput!]!, $batchId: String) {
369
- perspectiveRemoveLinks(uuid: $uuid, links: $links, batchId: $batchId) {
370
- ${LINK_EXPRESSION_FIELDS}
371
- }
372
- }`,
373
- variables: { uuid, links, batchId }
374
- }))
375
- return perspectiveRemoveLinks
241
+ return this.#apiClient.call<LinkExpression[]>(
242
+ 'perspective.removeLinks', { uuid, links, batchId }
243
+ )
376
244
  }
377
245
 
378
246
  async linkMutations(uuid: string, mutations: LinkMutations, status?: LinkStatus): Promise<LinkExpressionMutations> {
379
- const { perspectiveLinkMutations } = unwrapApolloResult(await this.#apolloClient.mutate({
380
- mutation: gql`mutation perspectiveLinkMutations($uuid: String!, $mutations: LinkMutations!, $status: String){
381
- perspectiveLinkMutations(mutations: $mutations, uuid: $uuid, status: $status) {
382
- additions {
383
- ${LINK_EXPRESSION_FIELDS}
384
- }
385
- removals {
386
- ${LINK_EXPRESSION_FIELDS}
387
- }
388
- }
389
- }`,
390
- variables: { uuid, mutations, status }
391
- }))
392
- return perspectiveLinkMutations
247
+ return this.#apiClient.call<LinkExpressionMutations>(
248
+ 'perspective.linkMutations', { uuid, mutations, status }
249
+ )
393
250
  }
394
251
 
395
252
  async addLinkExpression(uuid: string, link: LinkExpression, status: LinkStatus = 'shared', batchId?: string): Promise<LinkExpression> {
396
- const { perspectiveAddLinkExpression } = unwrapApolloResult(await this.#apolloClient.mutate({
397
- mutation: gql`mutation perspectiveAddLinkExpression($uuid: String!, $link: LinkExpressionInput!, $status: String!, $batchId: String) {
398
- perspectiveAddLinkExpression(uuid: $uuid, link: $link, status: $status, batchId: $batchId) {
399
- ${LINK_EXPRESSION_FIELDS}
400
- }
401
- }`,
402
- variables: { uuid, link, status, batchId }
403
- }))
404
- return perspectiveAddLinkExpression
253
+ return this.#apiClient.call<LinkExpression>(
254
+ 'perspective.addLinkExpression', { uuid, link, status, batchId }
255
+ )
405
256
  }
406
257
 
407
258
  async updateLink(uuid: string, oldLink: LinkExpressionInput, newLink: Link, batchId?: string): Promise<LinkExpression> {
408
- const { perspectiveUpdateLink } = unwrapApolloResult(await this.#apolloClient.mutate({
409
- mutation: gql`mutation perspectiveUpdateLink($uuid: String!, $oldLink: LinkExpressionInput!, $newLink: LinkInput!, $batchId: String) {
410
- perspectiveUpdateLink(uuid: $uuid, oldLink: $oldLink, newLink: $newLink, batchId: $batchId) {
411
- ${LINK_EXPRESSION_FIELDS}
412
- }
413
- }`,
414
- variables: { uuid, oldLink, newLink, batchId }
415
- }))
416
- return perspectiveUpdateLink
259
+ return this.#apiClient.call<LinkExpression>(
260
+ 'perspective.updateLink', { uuid, oldLink, newLink, batchId }
261
+ )
417
262
  }
418
263
 
419
264
  async removeLink(uuid: string, link: LinkExpressionInput, batchId?: string): Promise<boolean> {
@@ -421,68 +266,48 @@ export class PerspectiveClient {
421
266
  delete link.data.__typename
422
267
  delete link.proof.__typename
423
268
  delete link.status
424
- const { perspectiveRemoveLink } = unwrapApolloResult(await this.#apolloClient.mutate({
425
- mutation: gql`mutation perspectiveRemoveLink($link: LinkExpressionInput!, $uuid: String!, $batchId: String) {
426
- perspectiveRemoveLink(link: $link, uuid: $uuid, batchId: $batchId)
427
- }`,
428
- variables: { uuid, link, batchId }
429
- }))
430
- return perspectiveRemoveLink
431
- }
432
-
433
- /**
434
- * Adds Social DNA code to a perspective.
435
- *
436
- * Preferred usage: pass shaclJson (from SHACLShape.toJSON()) as the primary schema definition.
437
- * The sdnaCode parameter is kept for backward compatibility but SHACL is the source of truth
438
- * for all SDNA operations. Prolog engines remain available for complex queries.
439
- *
440
- * @param sdnaCode - Legacy Prolog code (pass empty string when using shaclJson)
441
- * @param shaclJson - SHACL JSON string from SHACLShape.toJSON() (recommended)
442
- */
269
+ return this.#apiClient.call<boolean>(
270
+ 'perspective.removeLink', { uuid, link, batchId }
271
+ )
272
+ }
273
+
443
274
  async addSdna(uuid: string, name: string, sdnaCode: string | undefined, sdnaType: "subject_class" | "flow" | "custom", shaclJson?: string): Promise<boolean> {
444
- return unwrapApolloResult(await this.#apolloClient.mutate({
445
- mutation: gql`mutation perspectiveAddSdna($uuid: String!, $name: String!, $sdnaCode: String, $sdnaType: String!, $shaclJson: String) {
446
- perspectiveAddSdna(uuid: $uuid, name: $name, sdnaCode: $sdnaCode, sdnaType: $sdnaType, shaclJson: $shaclJson)
447
- }`,
448
- variables: { uuid, name, sdnaCode: sdnaCode || "", sdnaType, shaclJson }
449
- })).perspectiveAddSdna
275
+ return this.#apiClient.call<boolean>(
276
+ 'perspective.addSdna', { uuid, name, sdnaCode: sdnaCode || "", sdnaType, shaclJson }
277
+ )
278
+ }
279
+
280
+ async addSdnaBatch(uuid: string, entries: { name: string; sdnaCode?: string; sdnaType: "subject_class" | "flow" | "custom"; shaclJson?: string }[]): Promise<boolean[]> {
281
+ return this.#apiClient.call<boolean[]>(
282
+ 'perspective.addSdna', { uuid, entries: entries.map(e => ({ ...e, sdnaCode: e.sdnaCode || "" })) }
283
+ )
450
284
  }
451
285
 
452
286
  async executeCommands(uuid: string, commands: string, expression: string, parameters: string, batchId?: string): Promise<boolean> {
453
- return unwrapApolloResult(await this.#apolloClient.mutate({
454
- mutation: gql`mutation perspectiveExecuteCommands($uuid: String!, $commands: String!, $expression: String!, $parameters: String, $batchId: String) {
455
- perspectiveExecuteCommands(uuid: $uuid, commands: $commands, expression: $expression, parameters: $parameters, batchId: $batchId)
456
- }`,
457
- variables: { uuid, commands, expression, parameters, batchId }
458
- })).perspectiveExecuteCommands
287
+ return this.#apiClient.call<boolean>(
288
+ 'perspective.executeCommands', { uuid, commands, expression, parameters, batchId }
289
+ )
459
290
  }
460
291
 
461
292
  async createSubject(uuid: string, subjectClass: string, expressionAddress: string, initialValues?: string, batchId?: string): Promise<boolean> {
462
- return unwrapApolloResult(await this.#apolloClient.mutate({
463
- mutation: gql`mutation perspectiveCreateSubject($uuid: String!, $subjectClass: String!, $expressionAddress: String!, $initialValues: String, $batchId: String) {
464
- perspectiveCreateSubject(uuid: $uuid, subjectClass: $subjectClass, expressionAddress: $expressionAddress, initialValues: $initialValues, batchId: $batchId)
465
- }`,
466
- variables: { uuid, subjectClass, expressionAddress, initialValues, batchId }
467
- })).perspectiveCreateSubject
293
+ return this.#apiClient.call<boolean>(
294
+ 'perspective.createSubject', { uuid, subjectClass, expressionAddress, initialValues, batchId }
295
+ )
468
296
  }
469
297
 
470
298
  async getSubjectData(uuid: string, subjectClass: string, expressionAddress: string): Promise<string> {
471
- return unwrapApolloResult(await this.#apolloClient.mutate({
472
- mutation: gql`mutation perspectiveGetSubjectData($uuid: String!, $subjectClass: String!, $expressionAddress: String!) {
473
- perspectiveGetSubjectData(uuid: $uuid, subjectClass: $subjectClass, expressionAddress: $expressionAddress)
474
- }`,
475
- variables: { uuid, subjectClass, expressionAddress }
476
- })).perspectiveGetSubjectData
299
+ return this.#apiClient.call<string>(
300
+ 'perspective.getSubjectData', { uuid, subjectClass, expressionAddress }
301
+ )
477
302
  }
478
303
 
479
304
  // ExpressionClient functions, needed for Subjects:
480
305
  async getExpression(expressionURI: string): Promise<ExpressionRendered> {
481
- return await this.#expressionClient.get(expressionURI)
306
+ return await this.#expressionClient!.get(expressionURI)
482
307
  }
483
308
 
484
- async createExpression(content: any, languageAddress: string): Promise<string> {
485
- return await this.#expressionClient.create(content, languageAddress)
309
+ async createExpression(content: unknown, languageAddress: string): Promise<string> {
310
+ return await this.#expressionClient!.create(content, languageAddress)
486
311
  }
487
312
 
488
313
  // Subscriptions:
@@ -491,18 +316,12 @@ export class PerspectiveClient {
491
316
  }
492
317
 
493
318
  subscribePerspectiveAdded() {
494
- this.#apolloClient.subscribe({
495
- query: gql` subscription {
496
- perspectiveAdded { ${PERSPECTIVE_HANDLE_FIELDS} }
319
+ const unsub = this.#apiClient.subscribe((data) => {
320
+ if (data.type === 'perspective-added') {
321
+ this.#perspectiveAddedCallbacks.forEach(cb => cb(data.perspective as PerspectiveHandle))
497
322
  }
498
- `}).subscribe({
499
- next: result => {
500
- this.#perspectiveAddedCallbacks.forEach(cb => {
501
- cb(result.data.perspectiveAdded)
502
- })
503
- },
504
- error: (e) => console.error(e)
505
323
  })
324
+ this.#unsubscribers.push(unsub)
506
325
  }
507
326
 
508
327
  addPerspectiveUpdatedListener(cb: PerspectiveHandleCallback) {
@@ -510,18 +329,12 @@ export class PerspectiveClient {
510
329
  }
511
330
 
512
331
  subscribePerspectiveUpdated() {
513
- this.#apolloClient.subscribe({
514
- query: gql` subscription {
515
- perspectiveUpdated { ${PERSPECTIVE_HANDLE_FIELDS} }
332
+ const unsub = this.#apiClient.subscribe((data) => {
333
+ if (data.type === 'perspective-updated') {
334
+ this.#perspectiveUpdatedCallbacks.forEach(cb => cb(data.perspective as PerspectiveHandle))
516
335
  }
517
- `}).subscribe({
518
- next: result => {
519
- this.#perspectiveUpdatedCallbacks.forEach(cb => {
520
- cb(result.data.perspectiveUpdated)
521
- })
522
- },
523
- error: (e) => console.error(e)
524
336
  })
337
+ this.#unsubscribers.push(unsub)
525
338
  }
526
339
 
527
340
  addPerspectiveSyncedListener(cb: SyncStateChangeCallback) {
@@ -529,19 +342,14 @@ export class PerspectiveClient {
529
342
  }
530
343
 
531
344
  async addPerspectiveSyncStateChangeListener(uuid: String, cb: SyncStateChangeCallback[]): Promise<void> {
532
- this.#apolloClient.subscribe({
533
- query: gql` subscription {
534
- perspectiveSyncStateChange(uuid: "${uuid}")
345
+ const unsub = this.#apiClient.subscribe(
346
+ (data) => {
347
+ if (data.type === 'sync-state-change' && data.uuid === uuid) {
348
+ cb.forEach(c => c(data.state as PerspectiveState))
349
+ }
535
350
  }
536
- `}).subscribe({
537
- next: result => {
538
- cb.forEach(c => {
539
- c(result.data.perspectiveSyncStateChange)
540
- })
541
- },
542
- error: (e) => console.error(e)
543
- })
544
-
351
+ )
352
+ this.#unsubscribers.push(unsub)
545
353
  await new Promise<void>(resolve => setTimeout(resolve, 500))
546
354
  }
547
355
 
@@ -550,115 +358,91 @@ export class PerspectiveClient {
550
358
  }
551
359
 
552
360
  subscribePerspectiveRemoved() {
553
- this.#apolloClient.subscribe({
554
- query: gql` subscription {
555
- perspectiveRemoved
361
+ const unsub = this.#apiClient.subscribe((data) => {
362
+ if (data.type === 'perspective-removed') {
363
+ this.#perspectiveRemovedCallbacks.forEach(cb => cb(data.uuid as string))
556
364
  }
557
- `}).subscribe({
558
- next: result => {
559
- this.#perspectiveRemovedCallbacks.forEach(cb => {
560
- cb(result.data.perspectiveRemoved)
561
- })
562
- },
563
- error: (e) => console.error(e)
564
365
  })
366
+ this.#unsubscribers.push(unsub)
565
367
  }
566
368
 
567
369
  async addPerspectiveLinkAddedListener(uuid: String, cb: LinkCallback[]): Promise<void> {
568
- this.#apolloClient.subscribe({
569
- query: gql` subscription {
570
- perspectiveLinkAdded(uuid: "${uuid}") { ${LINK_EXPRESSION_FIELDS} }
370
+ const unsub = this.#apiClient.subscribe(
371
+ (data) => {
372
+ if (data.type === 'link-added' && data.perspectiveUuid === uuid) {
373
+ cb.forEach(c => c(data.link as LinkExpression))
374
+ }
571
375
  }
572
- `}).subscribe({
573
- next: result => {
574
- cb.forEach(c => {
575
- c(result.data.perspectiveLinkAdded)
576
- })
577
- },
578
- error: (e) => console.error(e)
579
- })
580
-
581
- await new Promise<void>(resolve => setTimeout(resolve, 500))
376
+ )
377
+ let existing = this.#linkUnsubscribers.get(uuid as string) || []
378
+ existing.push(unsub)
379
+ this.#linkUnsubscribers.set(uuid as string, existing)
380
+ await this.#apiClient.waitForSubscription()
582
381
  }
583
382
 
584
383
  async addPerspectiveLinkRemovedListener(uuid: String, cb: LinkCallback[]): Promise<void> {
585
- this.#apolloClient.subscribe({
586
- query: gql` subscription {
587
- perspectiveLinkRemoved(uuid: "${uuid}") { ${LINK_EXPRESSION_FIELDS} }
588
- }
589
- `}).subscribe({
590
- next: result => {
591
- cb.forEach(c => {
592
- if (!result.data.perspectiveLinkRemoved.status) {
593
- delete result.data.perspectiveLinkRemoved.status
384
+ const unsub = this.#apiClient.subscribe(
385
+ (data) => {
386
+ if (data.type === 'link-removed' && data.perspectiveUuid === uuid) {
387
+ const link = data.link as LinkExpression & { status?: unknown }
388
+ if (!link.status) {
389
+ delete link.status
594
390
  }
595
- c(result.data.perspectiveLinkRemoved)
596
- })
597
- },
598
- error: (e) => console.error(e)
599
- })
600
-
601
- await new Promise<void>(resolve => setTimeout(resolve, 500))
391
+ cb.forEach(c => c(link))
392
+ }
393
+ }
394
+ )
395
+ let existing = this.#linkUnsubscribers.get(uuid as string) || []
396
+ existing.push(unsub)
397
+ this.#linkUnsubscribers.set(uuid as string, existing)
398
+ await this.#apiClient.waitForSubscription()
602
399
  }
603
400
 
604
401
  async addPerspectiveLinkUpdatedListener(uuid: String, cb: LinkCallback[]): Promise<void> {
605
- this.#apolloClient.subscribe({
606
- query: gql` subscription {
607
- perspectiveLinkUpdated(uuid: "${uuid}") {
608
- oldLink {
609
- ${LINK_EXPRESSION_FIELDS}
402
+ const unsub = this.#apiClient.subscribe(
403
+ (data) => {
404
+ if (data.type === 'link-updated' && data.perspectiveUuid === uuid) {
405
+ const newLink = data.newLink as LinkExpression & { status?: unknown }
406
+ const oldLink = data.oldLink as LinkExpression & { status?: unknown }
407
+ if (!newLink.status) {
408
+ delete newLink.status
610
409
  }
611
- newLink {
612
- ${LINK_EXPRESSION_FIELDS}
410
+ if (!oldLink.status) {
411
+ delete oldLink.status
613
412
  }
413
+ cb.forEach(c => c(data as unknown as LinkExpression))
614
414
  }
615
415
  }
616
- `}).subscribe({
617
- next: result => {
618
- cb.forEach(c => {
619
- if (!result.data.perspectiveLinkUpdated.newLink.status) {
620
- delete result.data.perspectiveLinkUpdated.newLink.status
621
- }
622
- if (!result.data.perspectiveLinkUpdated.oldLink.status) {
623
- delete result.data.perspectiveLinkUpdated.oldLink.status
624
- }
625
- c(result.data.perspectiveLinkUpdated)
626
- })
627
- },
628
- error: (e) => console.error(e)
629
- })
630
-
631
- await new Promise<void>(resolve => setTimeout(resolve, 500))
416
+ )
417
+ let existing = this.#linkUnsubscribers.get(uuid as string) || []
418
+ existing.push(unsub)
419
+ this.#linkUnsubscribers.set(uuid as string, existing)
420
+ await this.#apiClient.waitForSubscription()
421
+ }
422
+
423
+ /** Unsubscribe all link/sync-state listeners registered for the given perspective UUID.
424
+ * Called by PerspectiveProxy.dispose() to prevent subscription leaks. */
425
+ removeAllListeners(uuid: string): void {
426
+ const unsubs = this.#linkUnsubscribers.get(uuid)
427
+ if (unsubs) {
428
+ for (const fn of unsubs) {
429
+ try { fn() } catch {}
430
+ }
431
+ this.#linkUnsubscribers.delete(uuid)
432
+ }
632
433
  }
633
434
 
634
435
  getNeighbourhoodProxy(uuid: string): NeighbourhoodProxy {
635
- return new NeighbourhoodProxy(this.#neighbourhoodClient, uuid)
436
+ return new NeighbourhoodProxy(this.#neighbourhoodClient!, uuid)
636
437
  }
637
438
 
638
439
  async createBatch(uuid: string): Promise<string> {
639
- const { perspectiveCreateBatch } = unwrapApolloResult(await this.#apolloClient.mutate({
640
- mutation: gql`mutation perspectiveCreateBatch($uuid: String!) {
641
- perspectiveCreateBatch(uuid: $uuid)
642
- }`,
643
- variables: { uuid }
644
- }))
645
- return perspectiveCreateBatch
440
+ return this.#apiClient.call<string>('perspective.createBatch', { uuid })
646
441
  }
647
442
 
648
443
  async commitBatch(uuid: string, batchId: string): Promise<LinkExpressionMutations> {
649
- const { perspectiveCommitBatch } = unwrapApolloResult(await this.#apolloClient.mutate({
650
- mutation: gql`mutation perspectiveCommitBatch($uuid: String!, $batchId: String!) {
651
- perspectiveCommitBatch(uuid: $uuid, batchId: $batchId) {
652
- additions {
653
- ${LINK_EXPRESSION_FIELDS}
654
- }
655
- removals {
656
- ${LINK_EXPRESSION_FIELDS}
657
- }
658
- }
659
- }`,
660
- variables: { uuid, batchId }
661
- }))
662
- return perspectiveCommitBatch
444
+ return this.#apiClient.call<LinkExpressionMutations>(
445
+ 'perspective.commitBatch', { uuid, batchId }
446
+ )
663
447
  }
664
- }
448
+ }