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

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
Files changed (388) hide show
  1. package/README.md +2 -25
  2. package/jest-setup.ts +1 -1
  3. package/lib/index.cjs +7444 -13939
  4. package/lib/index.js +5322 -11888
  5. package/lib/src/Ad4mClient.d.ts +9 -3
  6. package/lib/src/Ad4mClient.js +40 -13
  7. package/lib/src/Literal.js +6 -5
  8. package/lib/src/agent/Agent.js +26 -272
  9. package/lib/src/agent/AgentClient.d.ts +33 -21
  10. package/lib/src/agent/AgentClient.js +180 -373
  11. package/lib/src/agent/AgentStatus.js +2 -37
  12. package/lib/src/ai/AIClient.d.ts +12 -4
  13. package/lib/src/ai/AIClient.js +81 -285
  14. package/lib/src/ai/AITypes.d.ts +55 -0
  15. package/lib/src/ai/AITypes.js +18 -0
  16. package/lib/src/ai/Tasks.js +10 -133
  17. package/lib/src/apiClient.d.ts +53 -0
  18. package/lib/src/apiClient.js +234 -0
  19. package/lib/src/cache/PersistentCache.d.ts +40 -0
  20. package/lib/src/cache/PersistentCache.js +139 -0
  21. package/lib/src/expression/Expression.d.ts +1 -1
  22. package/lib/src/expression/Expression.js +13 -122
  23. package/lib/src/expression/ExpressionClient.d.ts +11 -3
  24. package/lib/src/expression/ExpressionClient.js +120 -75
  25. package/lib/src/expression/ExpressionRef.js +4 -27
  26. package/lib/src/generated/api/AIModelLoadingStatus.d.ts +7 -0
  27. package/lib/src/generated/api/AIModelLoadingStatus.js +2 -0
  28. package/lib/src/generated/api/AddLinkExpressionRequest.d.ts +6 -0
  29. package/lib/src/generated/api/AddLinkExpressionRequest.js +1 -0
  30. package/lib/src/generated/api/AddLinkRequest.d.ts +6 -0
  31. package/lib/src/generated/api/AddLinkRequest.js +1 -0
  32. package/lib/src/generated/api/AddLinksBulkRequest.d.ts +6 -0
  33. package/lib/src/generated/api/AddLinksBulkRequest.js +1 -0
  34. package/lib/src/generated/api/AddSdnaRequest.d.ts +6 -0
  35. package/lib/src/generated/api/AddSdnaRequest.js +2 -0
  36. package/lib/src/generated/api/ApplyTemplateRequest.d.ts +4 -0
  37. package/lib/src/generated/api/ApplyTemplateRequest.js +2 -0
  38. package/lib/src/generated/api/AuthInfoInput.d.ts +10 -0
  39. package/lib/src/generated/api/AuthInfoInput.js +1 -0
  40. package/lib/src/generated/api/CapabilityInput.d.ts +5 -0
  41. package/lib/src/generated/api/CapabilityInput.js +1 -0
  42. package/lib/src/generated/api/CommitBatchRequest.d.ts +3 -0
  43. package/lib/src/generated/api/CommitBatchRequest.js +2 -0
  44. package/lib/src/generated/api/ComputeLogEntry.d.ts +9 -0
  45. package/lib/src/generated/api/ComputeLogEntry.js +2 -0
  46. package/lib/src/generated/api/CreateExpressionRequest.d.ts +4 -0
  47. package/lib/src/generated/api/CreateExpressionRequest.js +2 -0
  48. package/lib/src/generated/api/CreatePerspectiveRequest.d.ts +3 -0
  49. package/lib/src/generated/api/CreatePerspectiveRequest.js +2 -0
  50. package/lib/src/generated/api/CreateSubjectRequest.d.ts +6 -0
  51. package/lib/src/generated/api/CreateSubjectRequest.js +2 -0
  52. package/lib/src/generated/api/EmbedRequest.d.ts +4 -0
  53. package/lib/src/generated/api/EmbedRequest.js +2 -0
  54. package/lib/src/generated/api/EntanglementProofInput.d.ts +6 -0
  55. package/lib/src/generated/api/EntanglementProofInput.js +2 -0
  56. package/lib/src/generated/api/ExecuteCommandsRequest.d.ts +4 -0
  57. package/lib/src/generated/api/ExecuteCommandsRequest.js +2 -0
  58. package/lib/src/generated/api/ExportRequest.d.ts +5 -0
  59. package/lib/src/generated/api/ExportRequest.js +2 -0
  60. package/lib/src/generated/api/ExpressionManyRequest.d.ts +3 -0
  61. package/lib/src/generated/api/ExpressionManyRequest.js +2 -0
  62. package/lib/src/generated/api/ExpressionProof.d.ts +4 -0
  63. package/lib/src/generated/api/ExpressionProof.js +2 -0
  64. package/lib/src/generated/api/ExpressionProofInput.d.ts +6 -0
  65. package/lib/src/generated/api/ExpressionProofInput.js +2 -0
  66. package/lib/src/generated/api/FriendSendMessageRequest.d.ts +3 -0
  67. package/lib/src/generated/api/FriendSendMessageRequest.js +2 -0
  68. package/lib/src/generated/api/FriendsListRequest.d.ts +3 -0
  69. package/lib/src/generated/api/FriendsListRequest.js +2 -0
  70. package/lib/src/generated/api/GenerateAgentRequest.d.ts +3 -0
  71. package/lib/src/generated/api/GenerateAgentRequest.js +2 -0
  72. package/lib/src/generated/api/GenerateJwtRequest.d.ts +4 -0
  73. package/lib/src/generated/api/GenerateJwtRequest.js +2 -0
  74. package/lib/src/generated/api/GetSubjectDataRequest.d.ts +4 -0
  75. package/lib/src/generated/api/GetSubjectDataRequest.js +2 -0
  76. package/lib/src/generated/api/ImportAgentRequest.d.ts +6 -0
  77. package/lib/src/generated/api/ImportAgentRequest.js +2 -0
  78. package/lib/src/generated/api/ImportRequest.d.ts +4 -0
  79. package/lib/src/generated/api/ImportRequest.js +2 -0
  80. package/lib/src/generated/api/JoinNeighbourhoodRequest.d.ts +3 -0
  81. package/lib/src/generated/api/JoinNeighbourhoodRequest.js +2 -0
  82. package/lib/src/generated/api/LanguageMetaInput.d.ts +6 -0
  83. package/lib/src/generated/api/LanguageMetaInput.js +2 -0
  84. package/lib/src/generated/api/Link.d.ts +5 -0
  85. package/lib/src/generated/api/Link.js +2 -0
  86. package/lib/src/generated/api/LinkExpression.d.ts +10 -0
  87. package/lib/src/generated/api/LinkExpression.js +1 -0
  88. package/lib/src/generated/api/LinkExpressionInput.d.ts +10 -0
  89. package/lib/src/generated/api/LinkExpressionInput.js +1 -0
  90. package/lib/src/generated/api/LinkInput.d.ts +5 -0
  91. package/lib/src/generated/api/LinkInput.js +2 -0
  92. package/lib/src/generated/api/LinkLanguageTemplatesRequest.d.ts +3 -0
  93. package/lib/src/generated/api/LinkLanguageTemplatesRequest.js +2 -0
  94. package/lib/src/generated/api/LinkMutations.d.ts +6 -0
  95. package/lib/src/generated/api/LinkMutations.js +1 -0
  96. package/lib/src/generated/api/LinkStatus.d.ts +1 -0
  97. package/lib/src/generated/api/LinkStatus.js +2 -0
  98. package/lib/src/generated/api/LockAgentRequest.d.ts +3 -0
  99. package/lib/src/generated/api/LockAgentRequest.js +2 -0
  100. package/lib/src/generated/api/ModelType.d.ts +1 -0
  101. package/lib/src/generated/api/ModelType.js +2 -0
  102. package/lib/src/generated/api/NotificationInput.d.ts +10 -0
  103. package/lib/src/generated/api/NotificationInput.js +2 -0
  104. package/lib/src/generated/api/OpenLinkRequest.d.ts +3 -0
  105. package/lib/src/generated/api/OpenLinkRequest.js +2 -0
  106. package/lib/src/generated/api/PermitCapabilityRequest.d.ts +3 -0
  107. package/lib/src/generated/api/PermitCapabilityRequest.js +2 -0
  108. package/lib/src/generated/api/PerspectiveInput.d.ts +4 -0
  109. package/lib/src/generated/api/PerspectiveInput.js +1 -0
  110. package/lib/src/generated/api/PromptRequest.d.ts +4 -0
  111. package/lib/src/generated/api/PromptRequest.js +2 -0
  112. package/lib/src/generated/api/PublishLanguageRequest.d.ts +5 -0
  113. package/lib/src/generated/api/PublishLanguageRequest.js +1 -0
  114. package/lib/src/generated/api/PublishNeighbourhoodRequest.d.ts +6 -0
  115. package/lib/src/generated/api/PublishNeighbourhoodRequest.js +1 -0
  116. package/lib/src/generated/api/QueryRequest.d.ts +7 -0
  117. package/lib/src/generated/api/QueryRequest.js +2 -0
  118. package/lib/src/generated/api/RemoveLinkRequest.d.ts +5 -0
  119. package/lib/src/generated/api/RemoveLinkRequest.js +1 -0
  120. package/lib/src/generated/api/RemoveLinksBulkRequest.d.ts +5 -0
  121. package/lib/src/generated/api/RemoveLinksBulkRequest.js +1 -0
  122. package/lib/src/generated/api/ResourceInput.d.ts +4 -0
  123. package/lib/src/generated/api/ResourceInput.js +2 -0
  124. package/lib/src/generated/api/SetDefaultModelRequest.d.ts +4 -0
  125. package/lib/src/generated/api/SetDefaultModelRequest.js +1 -0
  126. package/lib/src/generated/api/SetFreeHostingEnabledRequest.d.ts +3 -0
  127. package/lib/src/generated/api/SetFreeHostingEnabledRequest.js +2 -0
  128. package/lib/src/generated/api/SetMultiUserRequest.d.ts +3 -0
  129. package/lib/src/generated/api/SetMultiUserRequest.js +2 -0
  130. package/lib/src/generated/api/SetStatusRequest.d.ts +3 -0
  131. package/lib/src/generated/api/SetStatusRequest.js +2 -0
  132. package/lib/src/generated/api/SignMessageRequest.d.ts +3 -0
  133. package/lib/src/generated/api/SignMessageRequest.js +2 -0
  134. package/lib/src/generated/api/TrustedAgentsRequest.d.ts +3 -0
  135. package/lib/src/generated/api/TrustedAgentsRequest.js +2 -0
  136. package/lib/src/generated/api/UnlockAgentRequest.d.ts +4 -0
  137. package/lib/src/generated/api/UnlockAgentRequest.js +2 -0
  138. package/lib/src/generated/api/UpdateLinkRequest.d.ts +7 -0
  139. package/lib/src/generated/api/UpdateLinkRequest.js +1 -0
  140. package/lib/src/generated/api/UpdatePerspectiveRequest.d.ts +3 -0
  141. package/lib/src/generated/api/UpdatePerspectiveRequest.js +2 -0
  142. package/lib/src/generated/api/UserStatistics.d.ts +9 -0
  143. package/lib/src/generated/api/UserStatistics.js +2 -0
  144. package/lib/src/generated/api/VerificationRequestResult.d.ts +6 -0
  145. package/lib/src/generated/api/VerificationRequestResult.js +2 -0
  146. package/lib/src/generated/api/VerifySignatureRequest.d.ts +5 -0
  147. package/lib/src/generated/api/VerifySignatureRequest.js +2 -0
  148. package/lib/src/generated/api/WriteSettingsRequest.d.ts +3 -0
  149. package/lib/src/generated/api/WriteSettingsRequest.js +2 -0
  150. package/lib/src/generated/api/index.d.ts +42 -0
  151. package/lib/src/generated/api/index.js +7 -0
  152. package/lib/src/index.d.ts +7 -2
  153. package/lib/src/index.js +7 -2
  154. package/lib/src/jestSetup.d.ts +0 -1
  155. package/lib/src/jestSetup.js +1 -1
  156. package/lib/src/language/Icon.js +2 -21
  157. package/lib/src/language/Language.d.ts +26 -176
  158. package/lib/src/language/Language.js +32 -72
  159. package/lib/src/language/LanguageClient.d.ts +2 -2
  160. package/lib/src/language/LanguageClient.js +15 -105
  161. package/lib/src/language/LanguageHandle.js +2 -41
  162. package/lib/src/language/LanguageMeta.js +4 -75
  163. package/lib/src/language/LanguageRef.js +2 -25
  164. package/lib/src/links/Links.js +14 -111
  165. package/lib/src/model/Ad4mModel.d.ts +150 -62
  166. package/lib/src/model/Ad4mModel.js +689 -417
  167. package/lib/src/model/Ad4mModel.test.js +1434 -688
  168. package/lib/src/model/ModelQueryBuilder.d.ts +59 -38
  169. package/lib/src/model/ModelQueryBuilder.js +317 -153
  170. package/lib/src/model/Subject.js +6 -6
  171. package/lib/src/model/decorators.d.ts +36 -8
  172. package/lib/src/model/decorators.js +41 -14
  173. package/lib/src/model/hydration-batch.d.ts +34 -0
  174. package/lib/src/model/hydration-batch.js +147 -0
  175. package/lib/src/model/hydration-batching.test.d.ts +7 -0
  176. package/lib/src/model/hydration-batching.test.js +456 -0
  177. package/lib/src/model/hydration.d.ts +3 -92
  178. package/lib/src/model/hydration.js +3 -691
  179. package/lib/src/model/index.d.ts +3 -4
  180. package/lib/src/model/index.js +3 -4
  181. package/lib/src/model/json-schema.js +2 -2
  182. package/lib/src/model/model-manifest.d.ts +41 -0
  183. package/lib/src/model/model-manifest.js +11 -0
  184. package/lib/src/model/query-cache.d.ts +30 -0
  185. package/lib/src/model/query-cache.js +66 -0
  186. package/lib/src/model/query-cache.test.d.ts +1 -0
  187. package/lib/src/model/query-cache.test.js +43 -0
  188. package/lib/src/model/query-common.d.ts +1 -1
  189. package/lib/src/model/query-common.js +1 -1
  190. package/lib/src/model/query-sparql-batch.d.ts +17 -0
  191. package/lib/src/model/query-sparql-batch.js +260 -0
  192. package/lib/src/model/query-sparql.d.ts +51 -0
  193. package/lib/src/model/query-sparql.js +466 -0
  194. package/lib/src/model/query-sparql.test.d.ts +1 -0
  195. package/lib/src/model/query-sparql.test.js +312 -0
  196. package/lib/src/model/{surreal-utils.d.ts → query-utils.d.ts} +13 -9
  197. package/lib/src/model/query-utils.js +189 -0
  198. package/lib/src/model/relation-filtering.test.js +15 -15
  199. package/lib/src/model/sdna.js +1 -1
  200. package/lib/src/model/shacl-gen.js +46 -18
  201. package/lib/src/model/subscription-delta.test.d.ts +24 -0
  202. package/lib/src/model/subscription-delta.test.js +180 -0
  203. package/lib/src/model/subscription-pool.d.ts +39 -0
  204. package/lib/src/model/subscription-pool.js +165 -0
  205. package/lib/src/model/types.d.ts +60 -5
  206. package/lib/src/model/types.js +5 -2
  207. package/lib/src/neighbourhood/Neighbourhood.js +4 -32
  208. package/lib/src/neighbourhood/NeighbourhoodClient.d.ts +3 -3
  209. package/lib/src/neighbourhood/NeighbourhoodClient.js +40 -203
  210. package/lib/src/perspectives/LinkQuery.js +2 -42
  211. package/lib/src/perspectives/Perspective.d.ts +1 -1
  212. package/lib/src/perspectives/Perspective.js +10 -52
  213. package/lib/src/perspectives/PerspectiveClient.d.ts +22 -32
  214. package/lib/src/perspectives/PerspectiveClient.js +189 -454
  215. package/lib/src/perspectives/PerspectiveClient.test.d.ts +1 -0
  216. package/lib/src/perspectives/PerspectiveClient.test.js +224 -0
  217. package/lib/src/perspectives/PerspectiveDiff.js +4 -31
  218. package/lib/src/perspectives/PerspectiveHandle.js +3 -43
  219. package/lib/src/perspectives/PerspectiveProxy.d.ts +156 -78
  220. package/lib/src/perspectives/PerspectiveProxy.js +474 -389
  221. package/lib/src/perspectives/PerspectiveResolver.d.ts +0 -1
  222. package/lib/src/perspectives/PerspectiveResolver.js +0 -11
  223. package/lib/src/perspectives/WakerSubscriptionManager.d.ts +3 -3
  224. package/lib/src/perspectives/WakerSubscriptionManager.js +12 -12
  225. package/lib/src/runtime/RuntimeClient.d.ts +34 -6
  226. package/lib/src/runtime/RuntimeClient.js +131 -362
  227. package/lib/src/runtime/RuntimeResolver.d.ts +28 -1
  228. package/lib/src/runtime/RuntimeResolver.js +197 -4
  229. package/lib/src/runtime/RuntimeTypes.d.ts +101 -0
  230. package/lib/src/runtime/RuntimeTypes.js +45 -0
  231. package/lib/src/schema.gql +27 -1
  232. package/lib/src/shacl/SHACLFlow.d.ts +1 -1
  233. package/lib/src/shacl/SHACLFlow.js +9 -9
  234. package/lib/src/shacl/SHACLShape.d.ts +8 -1
  235. package/lib/src/shacl/SHACLShape.js +57 -38
  236. package/lib/src/shacl/SHACLShape.test.js +82 -0
  237. package/lib/src/typeDefs.js +3 -602
  238. package/lib/src/utils.d.ts +6 -6
  239. package/lib/src/utils.js +6 -6
  240. package/package.json +6 -18
  241. package/rollup.config.js +0 -7
  242. package/src/Ad4mClient.test.ts +1192 -1288
  243. package/src/Ad4mClient.ts +46 -15
  244. package/src/Literal.test.ts +10 -5
  245. package/src/Literal.ts +6 -5
  246. package/src/agent/Agent.ts +0 -99
  247. package/src/agent/AgentClient.ts +238 -465
  248. package/src/agent/AgentStatus.ts +0 -12
  249. package/src/ai/AIClient.ts +96 -296
  250. package/src/ai/AITypes.ts +66 -0
  251. package/src/ai/Tasks.ts +0 -52
  252. package/src/apiClient.ts +287 -0
  253. package/src/cache/PersistentCache.ts +145 -0
  254. package/src/cache/cache.test.ts +713 -0
  255. package/src/expression/Expression.ts +3 -43
  256. package/src/expression/ExpressionClient.ts +148 -77
  257. package/src/expression/ExpressionRef.ts +2 -8
  258. package/src/generated/api/AIModelLoadingStatus.ts +3 -0
  259. package/src/generated/api/AddLinkExpressionRequest.ts +4 -0
  260. package/src/generated/api/AddLinkRequest.ts +4 -0
  261. package/src/generated/api/AddLinksBulkRequest.ts +4 -0
  262. package/src/generated/api/AddSdnaRequest.ts +3 -0
  263. package/src/generated/api/ApplyTemplateRequest.ts +3 -0
  264. package/src/generated/api/AuthInfoInput.ts +4 -0
  265. package/src/generated/api/CapabilityInput.ts +4 -0
  266. package/src/generated/api/CommitBatchRequest.ts +3 -0
  267. package/src/generated/api/ComputeLogEntry.ts +3 -0
  268. package/src/generated/api/CreateExpressionRequest.ts +3 -0
  269. package/src/generated/api/CreatePerspectiveRequest.ts +3 -0
  270. package/src/generated/api/CreateSubjectRequest.ts +3 -0
  271. package/src/generated/api/EmbedRequest.ts +3 -0
  272. package/src/generated/api/EntanglementProofInput.ts +3 -0
  273. package/src/generated/api/ExecuteCommandsRequest.ts +3 -0
  274. package/src/generated/api/ExportRequest.ts +3 -0
  275. package/src/generated/api/ExpressionManyRequest.ts +3 -0
  276. package/src/generated/api/ExpressionProof.ts +3 -0
  277. package/src/generated/api/ExpressionProofInput.ts +3 -0
  278. package/src/generated/api/FriendSendMessageRequest.ts +3 -0
  279. package/src/generated/api/FriendsListRequest.ts +3 -0
  280. package/src/generated/api/GenerateAgentRequest.ts +3 -0
  281. package/src/generated/api/GenerateJwtRequest.ts +3 -0
  282. package/src/generated/api/GetSubjectDataRequest.ts +3 -0
  283. package/src/generated/api/ImportAgentRequest.ts +3 -0
  284. package/src/generated/api/ImportRequest.ts +3 -0
  285. package/src/generated/api/JoinNeighbourhoodRequest.ts +3 -0
  286. package/src/generated/api/LanguageMetaInput.ts +3 -0
  287. package/src/generated/api/Link.ts +3 -0
  288. package/src/generated/api/LinkExpression.ts +6 -0
  289. package/src/generated/api/LinkExpressionInput.ts +6 -0
  290. package/src/generated/api/LinkInput.ts +3 -0
  291. package/src/generated/api/LinkLanguageTemplatesRequest.ts +3 -0
  292. package/src/generated/api/LinkMutations.ts +5 -0
  293. package/src/generated/api/LinkStatus.ts +3 -0
  294. package/src/generated/api/LockAgentRequest.ts +3 -0
  295. package/src/generated/api/ModelType.ts +3 -0
  296. package/src/generated/api/NotificationInput.ts +3 -0
  297. package/src/generated/api/OpenLinkRequest.ts +3 -0
  298. package/src/generated/api/PermitCapabilityRequest.ts +3 -0
  299. package/src/generated/api/PerspectiveInput.ts +4 -0
  300. package/src/generated/api/PromptRequest.ts +3 -0
  301. package/src/generated/api/PublishLanguageRequest.ts +4 -0
  302. package/src/generated/api/PublishNeighbourhoodRequest.ts +4 -0
  303. package/src/generated/api/QueryRequest.ts +6 -0
  304. package/src/generated/api/RemoveLinkRequest.ts +4 -0
  305. package/src/generated/api/RemoveLinksBulkRequest.ts +4 -0
  306. package/src/generated/api/ResourceInput.ts +3 -0
  307. package/src/generated/api/SetDefaultModelRequest.ts +4 -0
  308. package/src/generated/api/SetFreeHostingEnabledRequest.ts +3 -0
  309. package/src/generated/api/SetMultiUserRequest.ts +3 -0
  310. package/src/generated/api/SetStatusRequest.ts +3 -0
  311. package/src/generated/api/SignMessageRequest.ts +3 -0
  312. package/src/generated/api/TrustedAgentsRequest.ts +3 -0
  313. package/src/generated/api/UnlockAgentRequest.ts +3 -0
  314. package/src/generated/api/UpdateLinkRequest.ts +5 -0
  315. package/src/generated/api/UpdatePerspectiveRequest.ts +3 -0
  316. package/src/generated/api/UserStatistics.ts +3 -0
  317. package/src/generated/api/VerificationRequestResult.ts +3 -0
  318. package/src/generated/api/VerifySignatureRequest.ts +3 -0
  319. package/src/generated/api/WriteSettingsRequest.ts +3 -0
  320. package/src/generated/api/index.ts +49 -0
  321. package/src/index.ts +7 -2
  322. package/src/jestSetup.ts +1 -1
  323. package/src/language/Icon.ts +0 -4
  324. package/src/language/Language.ts +51 -248
  325. package/src/language/LanguageClient.ts +21 -132
  326. package/src/language/LanguageHandle.ts +0 -14
  327. package/src/language/LanguageMeta.ts +0 -29
  328. package/src/language/LanguageRef.ts +0 -7
  329. package/src/links/Links.ts +0 -37
  330. package/src/model/Ad4mModel.test.ts +1690 -777
  331. package/src/model/Ad4mModel.ts +749 -477
  332. package/src/model/ModelQueryBuilder.ts +356 -171
  333. package/src/model/decorators.ts +71 -22
  334. package/src/model/hydration.ts +3 -772
  335. package/src/model/index.ts +3 -4
  336. package/src/model/json-schema.ts +2 -2
  337. package/src/model/query-cache.test.ts +54 -0
  338. package/src/model/query-cache.ts +79 -0
  339. package/src/model/query-common.ts +1 -1
  340. package/src/model/query-sparql.test.ts +376 -0
  341. package/src/model/query-sparql.ts +504 -0
  342. package/src/model/query-utils.ts +209 -0
  343. package/src/model/relation-filtering.test.ts +15 -15
  344. package/src/model/sdna.ts +1 -1
  345. package/src/model/shacl-gen.ts +47 -17
  346. package/src/model/types.ts +65 -5
  347. package/src/neighbourhood/Neighbourhood.ts +0 -9
  348. package/src/neighbourhood/NeighbourhoodClient.ts +42 -207
  349. package/src/neighbourhood/NeighbourhoodProxy.test.ts +34 -36
  350. package/src/perspectives/LinkQuery.ts +0 -15
  351. package/src/perspectives/Perspective.ts +1 -12
  352. package/src/perspectives/PerspectiveClient.test.ts +262 -0
  353. package/src/perspectives/PerspectiveClient.ts +254 -468
  354. package/src/perspectives/PerspectiveDiff.ts +0 -8
  355. package/src/perspectives/PerspectiveHandle.ts +1 -12
  356. package/src/perspectives/PerspectiveProxy.test.ts +125 -0
  357. package/src/perspectives/PerspectiveProxy.ts +522 -434
  358. package/src/perspectives/WakerSubscriptionManager.ts +13 -13
  359. package/src/runtime/RuntimeClient.ts +166 -369
  360. package/src/runtime/RuntimeTypes.ts +144 -0
  361. package/src/shacl/SHACLFlow.ts +9 -9
  362. package/src/shacl/SHACLShape.test.ts +94 -0
  363. package/src/shacl/SHACLShape.ts +66 -39
  364. package/src/typeDefs.ts +3 -5
  365. package/src/utils.ts +6 -6
  366. package/tsconfig.json +3 -7
  367. package/lib/src/model/query-surreal.d.ts +0 -44
  368. package/lib/src/model/query-surreal.js +0 -249
  369. package/lib/src/model/surreal-utils.js +0 -128
  370. package/shims/reflect-metadata.ts +0 -0
  371. package/shims/type-graphql.ts +0 -75
  372. package/src/PubSub.ts +0 -17
  373. package/src/agent/AgentResolver.ts +0 -263
  374. package/src/ai/AIResolver.ts +0 -372
  375. package/src/buildSchema.ts +0 -43
  376. package/src/expression/ExpressionResolver.ts +0 -64
  377. package/src/language/LanguageContext.ts +0 -37
  378. package/src/language/LanguageResolver.ts +0 -98
  379. package/src/model/Subject.ts +0 -159
  380. package/src/model/prolog-facts.ts +0 -145
  381. package/src/model/query-prolog.ts +0 -148
  382. package/src/model/query-surreal.ts +0 -280
  383. package/src/model/surreal-utils.ts +0 -147
  384. package/src/neighbourhood/NeighbourhoodResolver.ts +0 -100
  385. package/src/perspectives/PerspectiveResolver.ts +0 -372
  386. package/src/runtime/RuntimeResolver.ts +0 -617
  387. package/src/unwrapApolloResult.ts +0 -16
  388. package/tsconfig-browser.json +0 -82
@@ -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,194 @@ 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(uuid: string, query: string): Promise<unknown> {
120
+ const result = await this.#apiClient.call<string>('perspective.querySparql', { uuid, engine: 'sparql', query })
121
+ return JSON.parse(result)
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, shapeJson?: string): Promise<any> {
180
+ const resultJson = await this.#apiClient.call<string>(
181
+ 'perspective.modelQuery', { uuid, class_name: className, query_json: queryJson, shape_json: shapeJson }
182
+ )
183
+ return JSON.parse(resultJson)
184
+ }
185
+
186
+ async evaluateGetters(
187
+ uuid: string,
188
+ className: string,
189
+ instanceIds: string[],
190
+ shapeJson: string,
191
+ propertyNames?: string[],
192
+ ): Promise<Record<string, Record<string, any>>> {
193
+ const resultJson = await this.#apiClient.call<string>(
194
+ 'perspective.evaluateGetters', {
195
+ uuid,
196
+ class_name: className,
197
+ instance_ids: instanceIds,
198
+ shape_json: shapeJson,
199
+ ...(propertyNames && { property_names: propertyNames }),
200
+ }
201
+ )
202
+ return JSON.parse(resultJson)
203
+ }
305
204
 
306
- return perspectiveDisposeQuerySubscription
205
+ async modelSubscribe(uuid: string, className: string, queryJson: string, shapeJson?: string): Promise<{ subscriptionId: string, result: any }> {
206
+ const response = await this.#apiClient.call<{ subscription_id: string, result: string }>(
207
+ 'perspective.modelSubscribe', { uuid, class_name: className, query_json: queryJson, shape_json: shapeJson }
208
+ )
209
+ return {
210
+ subscriptionId: response.subscription_id,
211
+ result: JSON.parse(response.result)
212
+ }
307
213
  }
308
214
 
309
215
  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)
216
+ const handle = await this.#apiClient.call<PerspectiveHandle>('perspective.create', { name })
217
+ return new PerspectiveProxy(handle, this)
319
218
  }
320
219
 
321
220
  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)
221
+ const handle = await this.#apiClient.call<PerspectiveHandle>('perspective.update', { uuid, name })
222
+ return new PerspectiveProxy(handle, this)
331
223
  }
332
224
 
333
225
  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
- }))
226
+ const result = await this.#apiClient.call<boolean>('perspective.remove', { uuid })
227
+ return { perspectiveRemove: result }
340
228
  }
341
229
 
342
230
  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
231
+ return this.#apiClient.call<LinkExpression>(
232
+ 'perspective.addLink', { uuid, link, status, batchId }
233
+ )
352
234
  }
353
235
 
354
236
  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
237
+ return this.#apiClient.call<LinkExpression[]>(
238
+ 'perspective.addLinks', { uuid, links, status, batchId }
239
+ )
364
240
  }
365
241
 
366
242
  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
243
+ return this.#apiClient.call<LinkExpression[]>(
244
+ 'perspective.removeLinks', { uuid, links, batchId }
245
+ )
376
246
  }
377
247
 
378
248
  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
249
+ return this.#apiClient.call<LinkExpressionMutations>(
250
+ 'perspective.linkMutations', { uuid, mutations, status }
251
+ )
393
252
  }
394
253
 
395
254
  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
255
+ return this.#apiClient.call<LinkExpression>(
256
+ 'perspective.addLinkExpression', { uuid, link, status, batchId }
257
+ )
405
258
  }
406
259
 
407
260
  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
261
+ return this.#apiClient.call<LinkExpression>(
262
+ 'perspective.updateLink', { uuid, oldLink, newLink, batchId }
263
+ )
417
264
  }
418
265
 
419
266
  async removeLink(uuid: string, link: LinkExpressionInput, batchId?: string): Promise<boolean> {
@@ -421,68 +268,48 @@ export class PerspectiveClient {
421
268
  delete link.data.__typename
422
269
  delete link.proof.__typename
423
270
  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
- */
271
+ return this.#apiClient.call<boolean>(
272
+ 'perspective.removeLink', { uuid, link, batchId }
273
+ )
274
+ }
275
+
443
276
  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
277
+ return this.#apiClient.call<boolean>(
278
+ 'perspective.addSdna', { uuid, name, sdnaCode: sdnaCode || "", sdnaType, shaclJson }
279
+ )
280
+ }
281
+
282
+ async addSdnaBatch(uuid: string, entries: { name: string; sdnaCode?: string; sdnaType: "subject_class" | "flow" | "custom"; shaclJson?: string }[]): Promise<boolean[]> {
283
+ return this.#apiClient.call<boolean[]>(
284
+ 'perspective.addSdna', { uuid, entries: entries.map(e => ({ ...e, sdnaCode: e.sdnaCode || "" })) }
285
+ )
450
286
  }
451
287
 
452
288
  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
289
+ return this.#apiClient.call<boolean>(
290
+ 'perspective.executeCommands', { uuid, commands, expression, parameters, batchId }
291
+ )
459
292
  }
460
293
 
461
294
  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
295
+ return this.#apiClient.call<boolean>(
296
+ 'perspective.createSubject', { uuid, subjectClass, expressionAddress, initialValues, batchId }
297
+ )
468
298
  }
469
299
 
470
300
  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
301
+ return this.#apiClient.call<string>(
302
+ 'perspective.getSubjectData', { uuid, subjectClass, expressionAddress }
303
+ )
477
304
  }
478
305
 
479
306
  // ExpressionClient functions, needed for Subjects:
480
307
  async getExpression(expressionURI: string): Promise<ExpressionRendered> {
481
- return await this.#expressionClient.get(expressionURI)
308
+ return await this.#expressionClient!.get(expressionURI)
482
309
  }
483
310
 
484
- async createExpression(content: any, languageAddress: string): Promise<string> {
485
- return await this.#expressionClient.create(content, languageAddress)
311
+ async createExpression(content: unknown, languageAddress: string): Promise<string> {
312
+ return await this.#expressionClient!.create(content, languageAddress)
486
313
  }
487
314
 
488
315
  // Subscriptions:
@@ -491,18 +318,12 @@ export class PerspectiveClient {
491
318
  }
492
319
 
493
320
  subscribePerspectiveAdded() {
494
- this.#apolloClient.subscribe({
495
- query: gql` subscription {
496
- perspectiveAdded { ${PERSPECTIVE_HANDLE_FIELDS} }
321
+ const unsub = this.#apiClient.subscribe((data) => {
322
+ if (data.type === 'perspective-added') {
323
+ this.#perspectiveAddedCallbacks.forEach(cb => cb(data.perspective as PerspectiveHandle))
497
324
  }
498
- `}).subscribe({
499
- next: result => {
500
- this.#perspectiveAddedCallbacks.forEach(cb => {
501
- cb(result.data.perspectiveAdded)
502
- })
503
- },
504
- error: (e) => console.error(e)
505
325
  })
326
+ this.#unsubscribers.push(unsub)
506
327
  }
507
328
 
508
329
  addPerspectiveUpdatedListener(cb: PerspectiveHandleCallback) {
@@ -510,18 +331,12 @@ export class PerspectiveClient {
510
331
  }
511
332
 
512
333
  subscribePerspectiveUpdated() {
513
- this.#apolloClient.subscribe({
514
- query: gql` subscription {
515
- perspectiveUpdated { ${PERSPECTIVE_HANDLE_FIELDS} }
334
+ const unsub = this.#apiClient.subscribe((data) => {
335
+ if (data.type === 'perspective-updated') {
336
+ this.#perspectiveUpdatedCallbacks.forEach(cb => cb(data.perspective as PerspectiveHandle))
516
337
  }
517
- `}).subscribe({
518
- next: result => {
519
- this.#perspectiveUpdatedCallbacks.forEach(cb => {
520
- cb(result.data.perspectiveUpdated)
521
- })
522
- },
523
- error: (e) => console.error(e)
524
338
  })
339
+ this.#unsubscribers.push(unsub)
525
340
  }
526
341
 
527
342
  addPerspectiveSyncedListener(cb: SyncStateChangeCallback) {
@@ -529,19 +344,14 @@ export class PerspectiveClient {
529
344
  }
530
345
 
531
346
  async addPerspectiveSyncStateChangeListener(uuid: String, cb: SyncStateChangeCallback[]): Promise<void> {
532
- this.#apolloClient.subscribe({
533
- query: gql` subscription {
534
- perspectiveSyncStateChange(uuid: "${uuid}")
347
+ const unsub = this.#apiClient.subscribe(
348
+ (data) => {
349
+ if (data.type === 'sync-state-change' && data.uuid === uuid) {
350
+ cb.forEach(c => c(data.state as PerspectiveState))
351
+ }
535
352
  }
536
- `}).subscribe({
537
- next: result => {
538
- cb.forEach(c => {
539
- c(result.data.perspectiveSyncStateChange)
540
- })
541
- },
542
- error: (e) => console.error(e)
543
- })
544
-
353
+ )
354
+ this.#unsubscribers.push(unsub)
545
355
  await new Promise<void>(resolve => setTimeout(resolve, 500))
546
356
  }
547
357
 
@@ -550,115 +360,91 @@ export class PerspectiveClient {
550
360
  }
551
361
 
552
362
  subscribePerspectiveRemoved() {
553
- this.#apolloClient.subscribe({
554
- query: gql` subscription {
555
- perspectiveRemoved
363
+ const unsub = this.#apiClient.subscribe((data) => {
364
+ if (data.type === 'perspective-removed') {
365
+ this.#perspectiveRemovedCallbacks.forEach(cb => cb(data.uuid as string))
556
366
  }
557
- `}).subscribe({
558
- next: result => {
559
- this.#perspectiveRemovedCallbacks.forEach(cb => {
560
- cb(result.data.perspectiveRemoved)
561
- })
562
- },
563
- error: (e) => console.error(e)
564
367
  })
368
+ this.#unsubscribers.push(unsub)
565
369
  }
566
370
 
567
371
  async addPerspectiveLinkAddedListener(uuid: String, cb: LinkCallback[]): Promise<void> {
568
- this.#apolloClient.subscribe({
569
- query: gql` subscription {
570
- perspectiveLinkAdded(uuid: "${uuid}") { ${LINK_EXPRESSION_FIELDS} }
372
+ const unsub = this.#apiClient.subscribe(
373
+ (data) => {
374
+ if (data.type === 'link-added' && data.perspectiveUuid === uuid) {
375
+ cb.forEach(c => c(data.link as LinkExpression))
376
+ }
571
377
  }
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))
378
+ )
379
+ let existing = this.#linkUnsubscribers.get(uuid as string) || []
380
+ existing.push(unsub)
381
+ this.#linkUnsubscribers.set(uuid as string, existing)
382
+ await this.#apiClient.waitForSubscription()
582
383
  }
583
384
 
584
385
  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
386
+ const unsub = this.#apiClient.subscribe(
387
+ (data) => {
388
+ if (data.type === 'link-removed' && data.perspectiveUuid === uuid) {
389
+ const link = data.link as LinkExpression & { status?: unknown }
390
+ if (!link.status) {
391
+ delete link.status
594
392
  }
595
- c(result.data.perspectiveLinkRemoved)
596
- })
597
- },
598
- error: (e) => console.error(e)
599
- })
600
-
601
- await new Promise<void>(resolve => setTimeout(resolve, 500))
393
+ cb.forEach(c => c(link))
394
+ }
395
+ }
396
+ )
397
+ let existing = this.#linkUnsubscribers.get(uuid as string) || []
398
+ existing.push(unsub)
399
+ this.#linkUnsubscribers.set(uuid as string, existing)
400
+ await this.#apiClient.waitForSubscription()
602
401
  }
603
402
 
604
403
  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}
404
+ const unsub = this.#apiClient.subscribe(
405
+ (data) => {
406
+ if (data.type === 'link-updated' && data.perspectiveUuid === uuid) {
407
+ const newLink = data.newLink as LinkExpression & { status?: unknown }
408
+ const oldLink = data.oldLink as LinkExpression & { status?: unknown }
409
+ if (!newLink.status) {
410
+ delete newLink.status
610
411
  }
611
- newLink {
612
- ${LINK_EXPRESSION_FIELDS}
412
+ if (!oldLink.status) {
413
+ delete oldLink.status
613
414
  }
415
+ cb.forEach(c => c(data as unknown as LinkExpression))
614
416
  }
615
417
  }
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))
418
+ )
419
+ let existing = this.#linkUnsubscribers.get(uuid as string) || []
420
+ existing.push(unsub)
421
+ this.#linkUnsubscribers.set(uuid as string, existing)
422
+ await this.#apiClient.waitForSubscription()
423
+ }
424
+
425
+ /** Unsubscribe all link/sync-state listeners registered for the given perspective UUID.
426
+ * Called by PerspectiveProxy.dispose() to prevent subscription leaks. */
427
+ removeAllListeners(uuid: string): void {
428
+ const unsubs = this.#linkUnsubscribers.get(uuid)
429
+ if (unsubs) {
430
+ for (const fn of unsubs) {
431
+ try { fn() } catch {}
432
+ }
433
+ this.#linkUnsubscribers.delete(uuid)
434
+ }
632
435
  }
633
436
 
634
437
  getNeighbourhoodProxy(uuid: string): NeighbourhoodProxy {
635
- return new NeighbourhoodProxy(this.#neighbourhoodClient, uuid)
438
+ return new NeighbourhoodProxy(this.#neighbourhoodClient!, uuid)
636
439
  }
637
440
 
638
441
  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
442
+ return this.#apiClient.call<string>('perspective.createBatch', { uuid })
646
443
  }
647
444
 
648
445
  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
446
+ return this.#apiClient.call<LinkExpressionMutations>(
447
+ 'perspective.commitBatch', { uuid, batchId }
448
+ )
663
449
  }
664
- }
450
+ }