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

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 (334) hide show
  1. package/README.md +2 -25
  2. package/jest-setup.ts +1 -1
  3. package/lib/index.cjs +2406 -11070
  4. package/lib/index.js +2209 -10925
  5. package/lib/src/Ad4mClient.d.ts +7 -3
  6. package/lib/src/Ad4mClient.js +29 -13
  7. package/lib/src/agent/Agent.js +26 -272
  8. package/lib/src/agent/AgentClient.d.ts +10 -21
  9. package/lib/src/agent/AgentClient.js +75 -427
  10. package/lib/src/agent/AgentStatus.js +2 -37
  11. package/lib/src/ai/AIClient.d.ts +12 -4
  12. package/lib/src/ai/AIClient.js +81 -285
  13. package/lib/src/ai/AITypes.d.ts +55 -0
  14. package/lib/src/ai/AITypes.js +18 -0
  15. package/lib/src/ai/Tasks.js +10 -133
  16. package/lib/src/apiClient.d.ts +52 -0
  17. package/lib/src/apiClient.js +231 -0
  18. package/lib/src/expression/Expression.d.ts +1 -1
  19. package/lib/src/expression/Expression.js +13 -122
  20. package/lib/src/expression/ExpressionClient.d.ts +3 -3
  21. package/lib/src/expression/ExpressionClient.js +13 -76
  22. package/lib/src/expression/ExpressionRef.js +2 -25
  23. package/lib/src/generated/api/AIModelLoadingStatus.d.ts +7 -0
  24. package/lib/src/generated/api/AIModelLoadingStatus.js +2 -0
  25. package/lib/src/generated/api/AddLinkExpressionRequest.d.ts +6 -0
  26. package/lib/src/generated/api/AddLinkExpressionRequest.js +1 -0
  27. package/lib/src/generated/api/AddLinkRequest.d.ts +6 -0
  28. package/lib/src/generated/api/AddLinkRequest.js +1 -0
  29. package/lib/src/generated/api/AddLinksBulkRequest.d.ts +6 -0
  30. package/lib/src/generated/api/AddLinksBulkRequest.js +1 -0
  31. package/lib/src/generated/api/AddSdnaRequest.d.ts +6 -0
  32. package/lib/src/generated/api/AddSdnaRequest.js +2 -0
  33. package/lib/src/generated/api/ApplyTemplateRequest.d.ts +4 -0
  34. package/lib/src/generated/api/ApplyTemplateRequest.js +2 -0
  35. package/lib/src/generated/api/AuthInfoInput.d.ts +10 -0
  36. package/lib/src/generated/api/AuthInfoInput.js +1 -0
  37. package/lib/src/generated/api/CapabilityInput.d.ts +5 -0
  38. package/lib/src/generated/api/CapabilityInput.js +1 -0
  39. package/lib/src/generated/api/CommitBatchRequest.d.ts +3 -0
  40. package/lib/src/generated/api/CommitBatchRequest.js +2 -0
  41. package/lib/src/generated/api/ComputeLogEntry.d.ts +9 -0
  42. package/lib/src/generated/api/ComputeLogEntry.js +2 -0
  43. package/lib/src/generated/api/CreateExpressionRequest.d.ts +4 -0
  44. package/lib/src/generated/api/CreateExpressionRequest.js +2 -0
  45. package/lib/src/generated/api/CreatePerspectiveRequest.d.ts +3 -0
  46. package/lib/src/generated/api/CreatePerspectiveRequest.js +2 -0
  47. package/lib/src/generated/api/CreateSubjectRequest.d.ts +6 -0
  48. package/lib/src/generated/api/CreateSubjectRequest.js +2 -0
  49. package/lib/src/generated/api/EmbedRequest.d.ts +4 -0
  50. package/lib/src/generated/api/EmbedRequest.js +2 -0
  51. package/lib/src/generated/api/EntanglementProofInput.d.ts +6 -0
  52. package/lib/src/generated/api/EntanglementProofInput.js +2 -0
  53. package/lib/src/generated/api/ExecuteCommandsRequest.d.ts +4 -0
  54. package/lib/src/generated/api/ExecuteCommandsRequest.js +2 -0
  55. package/lib/src/generated/api/ExportRequest.d.ts +5 -0
  56. package/lib/src/generated/api/ExportRequest.js +2 -0
  57. package/lib/src/generated/api/ExpressionManyRequest.d.ts +3 -0
  58. package/lib/src/generated/api/ExpressionManyRequest.js +2 -0
  59. package/lib/src/generated/api/ExpressionProof.d.ts +4 -0
  60. package/lib/src/generated/api/ExpressionProof.js +2 -0
  61. package/lib/src/generated/api/ExpressionProofInput.d.ts +6 -0
  62. package/lib/src/generated/api/ExpressionProofInput.js +2 -0
  63. package/lib/src/generated/api/FriendSendMessageRequest.d.ts +3 -0
  64. package/lib/src/generated/api/FriendSendMessageRequest.js +2 -0
  65. package/lib/src/generated/api/FriendsListRequest.d.ts +3 -0
  66. package/lib/src/generated/api/FriendsListRequest.js +2 -0
  67. package/lib/src/generated/api/GenerateAgentRequest.d.ts +3 -0
  68. package/lib/src/generated/api/GenerateAgentRequest.js +2 -0
  69. package/lib/src/generated/api/GenerateJwtRequest.d.ts +4 -0
  70. package/lib/src/generated/api/GenerateJwtRequest.js +2 -0
  71. package/lib/src/generated/api/GetSubjectDataRequest.d.ts +4 -0
  72. package/lib/src/generated/api/GetSubjectDataRequest.js +2 -0
  73. package/lib/src/generated/api/ImportAgentRequest.d.ts +6 -0
  74. package/lib/src/generated/api/ImportAgentRequest.js +2 -0
  75. package/lib/src/generated/api/ImportRequest.d.ts +4 -0
  76. package/lib/src/generated/api/ImportRequest.js +2 -0
  77. package/lib/src/generated/api/JoinNeighbourhoodRequest.d.ts +3 -0
  78. package/lib/src/generated/api/JoinNeighbourhoodRequest.js +2 -0
  79. package/lib/src/generated/api/LanguageMetaInput.d.ts +6 -0
  80. package/lib/src/generated/api/LanguageMetaInput.js +2 -0
  81. package/lib/src/generated/api/Link.d.ts +5 -0
  82. package/lib/src/generated/api/Link.js +2 -0
  83. package/lib/src/generated/api/LinkExpression.d.ts +10 -0
  84. package/lib/src/generated/api/LinkExpression.js +1 -0
  85. package/lib/src/generated/api/LinkExpressionInput.d.ts +10 -0
  86. package/lib/src/generated/api/LinkExpressionInput.js +1 -0
  87. package/lib/src/generated/api/LinkInput.d.ts +5 -0
  88. package/lib/src/generated/api/LinkInput.js +2 -0
  89. package/lib/src/generated/api/LinkLanguageTemplatesRequest.d.ts +3 -0
  90. package/lib/src/generated/api/LinkLanguageTemplatesRequest.js +2 -0
  91. package/lib/src/generated/api/LinkMutations.d.ts +6 -0
  92. package/lib/src/generated/api/LinkMutations.js +1 -0
  93. package/lib/src/generated/api/LinkStatus.d.ts +1 -0
  94. package/lib/src/generated/api/LinkStatus.js +2 -0
  95. package/lib/src/generated/api/LockAgentRequest.d.ts +3 -0
  96. package/lib/src/generated/api/LockAgentRequest.js +2 -0
  97. package/lib/src/generated/api/ModelType.d.ts +1 -0
  98. package/lib/src/generated/api/ModelType.js +2 -0
  99. package/lib/src/generated/api/NotificationInput.d.ts +10 -0
  100. package/lib/src/generated/api/NotificationInput.js +2 -0
  101. package/lib/src/generated/api/OpenLinkRequest.d.ts +3 -0
  102. package/lib/src/generated/api/OpenLinkRequest.js +2 -0
  103. package/lib/src/generated/api/PermitCapabilityRequest.d.ts +3 -0
  104. package/lib/src/generated/api/PermitCapabilityRequest.js +2 -0
  105. package/lib/src/generated/api/PerspectiveInput.d.ts +4 -0
  106. package/lib/src/generated/api/PerspectiveInput.js +1 -0
  107. package/lib/src/generated/api/PromptRequest.d.ts +4 -0
  108. package/lib/src/generated/api/PromptRequest.js +2 -0
  109. package/lib/src/generated/api/PublishLanguageRequest.d.ts +5 -0
  110. package/lib/src/generated/api/PublishLanguageRequest.js +1 -0
  111. package/lib/src/generated/api/PublishNeighbourhoodRequest.d.ts +6 -0
  112. package/lib/src/generated/api/PublishNeighbourhoodRequest.js +1 -0
  113. package/lib/src/generated/api/QueryRequest.d.ts +7 -0
  114. package/lib/src/generated/api/QueryRequest.js +2 -0
  115. package/lib/src/generated/api/RemoveLinkRequest.d.ts +5 -0
  116. package/lib/src/generated/api/RemoveLinkRequest.js +1 -0
  117. package/lib/src/generated/api/RemoveLinksBulkRequest.d.ts +5 -0
  118. package/lib/src/generated/api/RemoveLinksBulkRequest.js +1 -0
  119. package/lib/src/generated/api/ResourceInput.d.ts +4 -0
  120. package/lib/src/generated/api/ResourceInput.js +2 -0
  121. package/lib/src/generated/api/SetDefaultModelRequest.d.ts +4 -0
  122. package/lib/src/generated/api/SetDefaultModelRequest.js +1 -0
  123. package/lib/src/generated/api/SetFreeHostingEnabledRequest.d.ts +3 -0
  124. package/lib/src/generated/api/SetFreeHostingEnabledRequest.js +2 -0
  125. package/lib/src/generated/api/SetMultiUserRequest.d.ts +3 -0
  126. package/lib/src/generated/api/SetMultiUserRequest.js +2 -0
  127. package/lib/src/generated/api/SetStatusRequest.d.ts +3 -0
  128. package/lib/src/generated/api/SetStatusRequest.js +2 -0
  129. package/lib/src/generated/api/SignMessageRequest.d.ts +3 -0
  130. package/lib/src/generated/api/SignMessageRequest.js +2 -0
  131. package/lib/src/generated/api/TrustedAgentsRequest.d.ts +3 -0
  132. package/lib/src/generated/api/TrustedAgentsRequest.js +2 -0
  133. package/lib/src/generated/api/UnlockAgentRequest.d.ts +4 -0
  134. package/lib/src/generated/api/UnlockAgentRequest.js +2 -0
  135. package/lib/src/generated/api/UpdateLinkRequest.d.ts +7 -0
  136. package/lib/src/generated/api/UpdateLinkRequest.js +1 -0
  137. package/lib/src/generated/api/UpdatePerspectiveRequest.d.ts +3 -0
  138. package/lib/src/generated/api/UpdatePerspectiveRequest.js +2 -0
  139. package/lib/src/generated/api/UserStatistics.d.ts +9 -0
  140. package/lib/src/generated/api/UserStatistics.js +2 -0
  141. package/lib/src/generated/api/VerificationRequestResult.d.ts +6 -0
  142. package/lib/src/generated/api/VerificationRequestResult.js +2 -0
  143. package/lib/src/generated/api/VerifySignatureRequest.d.ts +5 -0
  144. package/lib/src/generated/api/VerifySignatureRequest.js +2 -0
  145. package/lib/src/generated/api/WriteSettingsRequest.d.ts +3 -0
  146. package/lib/src/generated/api/WriteSettingsRequest.js +2 -0
  147. package/lib/src/generated/api/index.d.ts +42 -0
  148. package/lib/src/generated/api/index.js +7 -0
  149. package/lib/src/index.d.ts +6 -1
  150. package/lib/src/index.js +6 -1
  151. package/lib/src/jestSetup.d.ts +0 -1
  152. package/lib/src/jestSetup.js +1 -1
  153. package/lib/src/language/Icon.js +2 -21
  154. package/lib/src/language/Language.d.ts +1 -1
  155. package/lib/src/language/Language.js +10 -76
  156. package/lib/src/language/LanguageClient.d.ts +2 -2
  157. package/lib/src/language/LanguageClient.js +15 -105
  158. package/lib/src/language/LanguageHandle.js +2 -41
  159. package/lib/src/language/LanguageMeta.js +4 -75
  160. package/lib/src/language/LanguageRef.js +2 -25
  161. package/lib/src/links/Links.js +14 -111
  162. package/lib/src/model/Ad4mModel.d.ts +57 -38
  163. package/lib/src/model/Ad4mModel.js +594 -460
  164. package/lib/src/model/Ad4mModel.test.js +371 -815
  165. package/lib/src/model/ModelQueryBuilder.d.ts +9 -21
  166. package/lib/src/model/ModelQueryBuilder.js +138 -217
  167. package/lib/src/model/decorators.d.ts +22 -0
  168. package/lib/src/model/decorators.js +7 -0
  169. package/lib/src/model/hydration.d.ts +7 -60
  170. package/lib/src/model/hydration.js +7 -716
  171. package/lib/src/model/index.d.ts +0 -4
  172. package/lib/src/model/index.js +0 -4
  173. package/lib/src/model/model-manifest.d.ts +41 -0
  174. package/lib/src/model/model-manifest.js +11 -0
  175. package/lib/src/model/query-sparql.d.ts +4 -67
  176. package/lib/src/model/query-sparql.js +26 -322
  177. package/lib/src/model/query-sparql.test.js +35 -218
  178. package/lib/src/model/shacl-gen.js +4 -0
  179. package/lib/src/model/types.d.ts +47 -38
  180. package/lib/src/model/types.js +4 -1
  181. package/lib/src/neighbourhood/Neighbourhood.js +4 -32
  182. package/lib/src/neighbourhood/NeighbourhoodClient.d.ts +3 -3
  183. package/lib/src/neighbourhood/NeighbourhoodClient.js +40 -203
  184. package/lib/src/perspectives/LinkQuery.js +2 -42
  185. package/lib/src/perspectives/Perspective.d.ts +1 -1
  186. package/lib/src/perspectives/Perspective.js +10 -52
  187. package/lib/src/perspectives/PerspectiveClient.d.ts +12 -17
  188. package/lib/src/perspectives/PerspectiveClient.js +169 -429
  189. package/lib/src/perspectives/PerspectiveClient.test.js +55 -0
  190. package/lib/src/perspectives/PerspectiveDiff.js +4 -31
  191. package/lib/src/perspectives/PerspectiveHandle.js +3 -43
  192. package/lib/src/perspectives/PerspectiveProxy.d.ts +92 -71
  193. package/lib/src/perspectives/PerspectiveProxy.js +273 -310
  194. package/lib/src/runtime/RuntimeClient.d.ts +6 -6
  195. package/lib/src/runtime/RuntimeClient.js +93 -467
  196. package/lib/src/runtime/RuntimeTypes.d.ts +101 -0
  197. package/lib/src/runtime/RuntimeTypes.js +45 -0
  198. package/lib/src/shacl/SHACLShape.d.ts +7 -0
  199. package/lib/src/shacl/SHACLShape.js +19 -0
  200. package/lib/src/shacl/SHACLShape.test.js +82 -0
  201. package/lib/src/typeDefs.js +3 -628
  202. package/package.json +9 -24
  203. package/rollup.config.js +0 -7
  204. package/src/Ad4mClient.test.ts +1179 -1340
  205. package/src/Ad4mClient.ts +30 -15
  206. package/src/agent/Agent.ts +0 -99
  207. package/src/agent/AgentClient.ts +112 -526
  208. package/src/agent/AgentStatus.ts +0 -12
  209. package/src/ai/AIClient.ts +96 -296
  210. package/src/ai/AITypes.ts +66 -0
  211. package/src/ai/Tasks.ts +0 -52
  212. package/src/apiClient.ts +283 -0
  213. package/src/expression/Expression.ts +3 -43
  214. package/src/expression/ExpressionClient.ts +14 -77
  215. package/src/expression/ExpressionRef.ts +0 -6
  216. package/src/generated/api/AIModelLoadingStatus.ts +3 -0
  217. package/src/generated/api/AddLinkExpressionRequest.ts +4 -0
  218. package/src/generated/api/AddLinkRequest.ts +4 -0
  219. package/src/generated/api/AddLinksBulkRequest.ts +4 -0
  220. package/src/generated/api/AddSdnaRequest.ts +3 -0
  221. package/src/generated/api/ApplyTemplateRequest.ts +3 -0
  222. package/src/generated/api/AuthInfoInput.ts +4 -0
  223. package/src/generated/api/CapabilityInput.ts +4 -0
  224. package/src/generated/api/CommitBatchRequest.ts +3 -0
  225. package/src/generated/api/ComputeLogEntry.ts +3 -0
  226. package/src/generated/api/CreateExpressionRequest.ts +3 -0
  227. package/src/generated/api/CreatePerspectiveRequest.ts +3 -0
  228. package/src/generated/api/CreateSubjectRequest.ts +3 -0
  229. package/src/generated/api/EmbedRequest.ts +3 -0
  230. package/src/generated/api/EntanglementProofInput.ts +3 -0
  231. package/src/generated/api/ExecuteCommandsRequest.ts +3 -0
  232. package/src/generated/api/ExportRequest.ts +3 -0
  233. package/src/generated/api/ExpressionManyRequest.ts +3 -0
  234. package/src/generated/api/ExpressionProof.ts +3 -0
  235. package/src/generated/api/ExpressionProofInput.ts +3 -0
  236. package/src/generated/api/FriendSendMessageRequest.ts +3 -0
  237. package/src/generated/api/FriendsListRequest.ts +3 -0
  238. package/src/generated/api/GenerateAgentRequest.ts +3 -0
  239. package/src/generated/api/GenerateJwtRequest.ts +3 -0
  240. package/src/generated/api/GetSubjectDataRequest.ts +3 -0
  241. package/src/generated/api/ImportAgentRequest.ts +3 -0
  242. package/src/generated/api/ImportRequest.ts +3 -0
  243. package/src/generated/api/JoinNeighbourhoodRequest.ts +3 -0
  244. package/src/generated/api/LanguageMetaInput.ts +3 -0
  245. package/src/generated/api/Link.ts +3 -0
  246. package/src/generated/api/LinkExpression.ts +6 -0
  247. package/src/generated/api/LinkExpressionInput.ts +6 -0
  248. package/src/generated/api/LinkInput.ts +3 -0
  249. package/src/generated/api/LinkLanguageTemplatesRequest.ts +3 -0
  250. package/src/generated/api/LinkMutations.ts +5 -0
  251. package/src/generated/api/LinkStatus.ts +3 -0
  252. package/src/generated/api/LockAgentRequest.ts +3 -0
  253. package/src/generated/api/ModelType.ts +3 -0
  254. package/src/generated/api/NotificationInput.ts +3 -0
  255. package/src/generated/api/OpenLinkRequest.ts +3 -0
  256. package/src/generated/api/PermitCapabilityRequest.ts +3 -0
  257. package/src/generated/api/PerspectiveInput.ts +4 -0
  258. package/src/generated/api/PromptRequest.ts +3 -0
  259. package/src/generated/api/PublishLanguageRequest.ts +4 -0
  260. package/src/generated/api/PublishNeighbourhoodRequest.ts +4 -0
  261. package/src/generated/api/QueryRequest.ts +6 -0
  262. package/src/generated/api/RemoveLinkRequest.ts +4 -0
  263. package/src/generated/api/RemoveLinksBulkRequest.ts +4 -0
  264. package/src/generated/api/ResourceInput.ts +3 -0
  265. package/src/generated/api/SetDefaultModelRequest.ts +4 -0
  266. package/src/generated/api/SetFreeHostingEnabledRequest.ts +3 -0
  267. package/src/generated/api/SetMultiUserRequest.ts +3 -0
  268. package/src/generated/api/SetStatusRequest.ts +3 -0
  269. package/src/generated/api/SignMessageRequest.ts +3 -0
  270. package/src/generated/api/TrustedAgentsRequest.ts +3 -0
  271. package/src/generated/api/UnlockAgentRequest.ts +3 -0
  272. package/src/generated/api/UpdateLinkRequest.ts +5 -0
  273. package/src/generated/api/UpdatePerspectiveRequest.ts +3 -0
  274. package/src/generated/api/UserStatistics.ts +3 -0
  275. package/src/generated/api/VerificationRequestResult.ts +3 -0
  276. package/src/generated/api/VerifySignatureRequest.ts +3 -0
  277. package/src/generated/api/WriteSettingsRequest.ts +3 -0
  278. package/src/generated/api/index.ts +49 -0
  279. package/src/index.ts +6 -1
  280. package/src/jestSetup.ts +1 -1
  281. package/src/language/Icon.ts +0 -4
  282. package/src/language/Language.ts +2 -23
  283. package/src/language/LanguageClient.ts +21 -132
  284. package/src/language/LanguageHandle.ts +0 -14
  285. package/src/language/LanguageMeta.ts +0 -29
  286. package/src/language/LanguageRef.ts +0 -7
  287. package/src/links/Links.ts +0 -37
  288. package/src/model/Ad4mModel.test.ts +708 -876
  289. package/src/model/Ad4mModel.ts +613 -508
  290. package/src/model/ModelQueryBuilder.ts +178 -244
  291. package/src/model/decorators.ts +29 -0
  292. package/src/model/hydration.ts +9 -766
  293. package/src/model/index.ts +0 -4
  294. package/src/model/query-sparql.test.ts +34 -242
  295. package/src/model/query-sparql.ts +27 -337
  296. package/src/model/shacl-gen.ts +5 -0
  297. package/src/model/types.ts +51 -39
  298. package/src/neighbourhood/Neighbourhood.ts +0 -9
  299. package/src/neighbourhood/NeighbourhoodClient.ts +42 -207
  300. package/src/neighbourhood/NeighbourhoodProxy.test.ts +34 -36
  301. package/src/perspectives/LinkQuery.ts +0 -15
  302. package/src/perspectives/Perspective.ts +1 -12
  303. package/src/perspectives/PerspectiveClient.test.ts +206 -148
  304. package/src/perspectives/PerspectiveClient.ts +228 -442
  305. package/src/perspectives/PerspectiveDiff.ts +0 -8
  306. package/src/perspectives/PerspectiveHandle.ts +1 -12
  307. package/src/perspectives/PerspectiveProxy.test.ts +41 -0
  308. package/src/perspectives/PerspectiveProxy.ts +307 -348
  309. package/src/runtime/RuntimeClient.ts +112 -474
  310. package/src/runtime/RuntimeTypes.ts +144 -0
  311. package/src/shacl/SHACLShape.test.ts +94 -0
  312. package/src/shacl/SHACLShape.ts +27 -0
  313. package/src/typeDefs.ts +3 -5
  314. package/tsconfig.json +3 -7
  315. package/shims/reflect-metadata.ts +0 -0
  316. package/shims/type-graphql.ts +0 -75
  317. package/src/PubSub.ts +0 -17
  318. package/src/agent/AgentResolver.ts +0 -263
  319. package/src/ai/AIResolver.ts +0 -372
  320. package/src/buildSchema.ts +0 -43
  321. package/src/expression/ExpressionResolver.ts +0 -64
  322. package/src/language/LanguageResolver.ts +0 -98
  323. package/src/model/Subject.ts +0 -159
  324. package/src/model/hydration-batch.ts +0 -205
  325. package/src/model/hydration-batching.test.ts +0 -563
  326. package/src/model/prolog-facts.ts +0 -145
  327. package/src/model/query-prolog.ts +0 -148
  328. package/src/model/query-sparql-batch.ts +0 -301
  329. package/src/model/subscription-delta.test.ts +0 -207
  330. package/src/model/subscription-pool.ts +0 -211
  331. package/src/neighbourhood/NeighbourhoodResolver.ts +0 -100
  332. package/src/perspectives/PerspectiveResolver.ts +0 -364
  333. package/src/runtime/RuntimeResolver.ts +0 -749
  334. package/src/unwrapApolloResult.ts +0 -16
@@ -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,37 @@ 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): { result: AllInstancesResult; isInit: boolean } {
20
+ let finalResult: unknown = raw
21
+ let isInit = false
22
+
23
+ if (typeof finalResult === 'string' && finalResult.startsWith('#init#')) {
24
+ finalResult = finalResult.substring(6)
25
+ isInit = true
26
+ }
27
+
28
+ if (typeof finalResult === 'string') {
29
+ try {
30
+ finalResult = JSON.parse(finalResult)
31
+ } catch (e) {
32
+ console.error(errorContext, e)
33
+ }
34
+ }
35
+
36
+ if (isInit && typeof finalResult === 'object' && finalResult !== null) {
37
+ (finalResult as Record<string, unknown>).isInit = true
38
+ }
39
+
40
+ return { result: finalResult as AllInstancesResult, isInit }
41
+ }
42
+
51
43
  export class PerspectiveClient {
52
- #apolloClient: ApolloClient<any>
44
+ #apiClient: ApiClient
53
45
  #perspectiveAddedCallbacks: PerspectiveHandleCallback[]
54
46
  #perspectiveUpdatedCallbacks: PerspectiveHandleCallback[]
55
47
  #perspectiveRemovedCallbacks: UuidCallback[]
@@ -57,14 +49,19 @@ export class PerspectiveClient {
57
49
  #expressionClient?: ExpressionClient
58
50
  #neighbourhoodClient?: NeighbourhoodClient
59
51
  #aiClient?: AIClient
60
- #proxyCache: Map<string, PerspectiveProxy> = new Map()
52
+ #unsubscribers: (() => void)[]
53
+ #linkUnsubscribers: Map<string, (() => void)[]>
54
+ #querySubscriptionUnsubscribers: Map<string, () => void>
61
55
 
62
- constructor(client: ApolloClient<any>, subscribe: boolean = true) {
63
- this.#apolloClient = client
56
+ constructor(baseUrl: string, token?: string, subscribe: boolean = true, sharedApiClient?: ApiClient) {
57
+ this.#apiClient = sharedApiClient || new ApiClient(baseUrl, token)
64
58
  this.#perspectiveAddedCallbacks = []
65
59
  this.#perspectiveUpdatedCallbacks = []
66
60
  this.#perspectiveRemovedCallbacks = []
67
61
  this.#perspectiveSyncStateChangeCallbacks = []
62
+ this.#unsubscribers = []
63
+ this.#linkUnsubscribers = new Map()
64
+ this.#querySubscriptionUnsubscribers = new Map()
68
65
 
69
66
  if(subscribe) {
70
67
  this.subscribePerspectiveAdded()
@@ -73,18 +70,6 @@ export class PerspectiveClient {
73
70
  }
74
71
  }
75
72
 
76
- /** Get or create a proxy for a UUID. If the proxy exists in cache, update its handle and return it. */
77
- private getOrCreateProxy(handle: PerspectiveHandle): PerspectiveProxy {
78
- const existing = this.#proxyCache.get(handle.uuid)
79
- if (existing) {
80
- existing.updateHandle(handle)
81
- return existing
82
- }
83
- const proxy = new PerspectiveProxy(handle, this)
84
- this.#proxyCache.set(handle.uuid, proxy)
85
- return proxy
86
- }
87
-
88
73
  setExpressionClient(client: ExpressionClient) {
89
74
  this.#expressionClient = client
90
75
  }
@@ -98,285 +83,175 @@ export class PerspectiveClient {
98
83
  }
99
84
 
100
85
  get aiClient(): AIClient {
101
- return this.#aiClient
86
+ return this.#aiClient!
102
87
  }
103
88
 
104
89
  async all(): Promise<PerspectiveProxy[]> {
105
- const { perspectives } = unwrapApolloResult(await this.#apolloClient.query({
106
- query: gql`query perspectives {
107
- perspectives {
108
- ${PERSPECTIVE_HANDLE_FIELDS}
109
- }
110
- }`
111
- }))
112
- return perspectives.map(handle => this.getOrCreateProxy(handle))
90
+ const perspectives = await this.#apiClient.call<PerspectiveHandle[]>('perspective.all')
91
+ return perspectives.map(handle => new PerspectiveProxy(handle, this))
113
92
  }
114
93
 
115
94
  async byUUID(uuid: string): Promise<PerspectiveProxy|null> {
116
- const cached = this.#proxyCache.get(uuid)
117
- if (cached) return cached
118
-
119
- const { perspective } = unwrapApolloResult(await this.#apolloClient.query({
120
- query: gql`query perspective($uuid: String!) {
121
- perspective(uuid: $uuid) {
122
- ${PERSPECTIVE_HANDLE_FIELDS}
123
- }
124
- }`,
125
- variables: { uuid }
126
- }))
127
- if(!perspective) return null
128
- return this.getOrCreateProxy(perspective)
95
+ try {
96
+ const perspective = await this.#apiClient.call<PerspectiveHandle>('perspective.get', { uuid })
97
+ if(!perspective) return null
98
+ return new PerspectiveProxy(perspective, this)
99
+ } catch(e) {
100
+ if (e instanceof RpcError && e.status === 404) return null
101
+ throw e
102
+ }
129
103
  }
130
104
 
131
105
  async snapshotByUUID(uuid: string): Promise<Perspective|null> {
132
- const { perspectiveSnapshot } = unwrapApolloResult(await this.#apolloClient.query({
133
- query: gql`query perspectiveSnapshot($uuid: String!) {
134
- perspectiveSnapshot(uuid: $uuid) {
135
- links { ${LINK_EXPRESSION_FIELDS} }
136
- }
137
- }`,
138
- variables: { uuid }
139
- }))
140
- return perspectiveSnapshot
106
+ return this.#apiClient.call<Perspective|null>('perspective.snapshot', { uuid })
141
107
  }
108
+
142
109
  async publishSnapshotByUUID(uuid: string): Promise<string|null> {
143
- const { perspectivePublishSnapshot } = unwrapApolloResult(await this.#apolloClient.mutate({
144
- mutation: gql`mutation perspectivePublishSnapshot($uuid: String!) {
145
- perspectivePublishSnapshot(uuid: $uuid)
146
- }`,
147
- variables: { uuid }
148
- }))
149
- return perspectivePublishSnapshot
110
+ return this.#apiClient.call<string|null>('perspective.publishSnapshot', { uuid })
150
111
  }
151
112
 
152
113
  async queryLinks(uuid: string, query: LinkQuery): Promise<LinkExpression[]> {
153
- const { perspectiveQueryLinks } = unwrapApolloResult(await this.#apolloClient.query({
154
- query: gql`query perspectiveQueryLinks($uuid: String!, $query: LinkQuery!) {
155
- perspectiveQueryLinks(query: $query, uuid: $uuid) {
156
- ${LINK_EXPRESSION_FIELDS}
157
- }
158
- }`,
159
- variables: { uuid, query }
160
- }))
161
- return perspectiveQueryLinks
114
+ const params: Record<string, unknown> = { uuid }
115
+ if (query.source) params.source = query.source
116
+ if (query.predicate) params.predicate = query.predicate
117
+ if (query.target) params.target = query.target
118
+ if (query.fromDate) params.fromDate = query.fromDate instanceof Date ? query.fromDate.toISOString() : String(query.fromDate)
119
+ if (query.untilDate) params.untilDate = query.untilDate instanceof Date ? query.untilDate.toISOString() : String(query.untilDate)
120
+ if (query.limit !== undefined) params.limit = query.limit
121
+ return this.#apiClient.call<LinkExpression[]>('perspective.queryLinks', params)
162
122
  }
163
123
 
164
- async queryProlog(uuid: string, query: string): Promise<any> {
165
- const { perspectiveQueryProlog } = unwrapApolloResult(await this.#apolloClient.query({
166
- query: gql`query perspectiveQueryProlog($uuid: String!, $query: String!) {
167
- perspectiveQueryProlog(uuid: $uuid, query: $query)
168
- }`,
169
- variables: { uuid, query }
170
- }))
124
+ async queryProlog(uuid: string, query: string): Promise<unknown> {
125
+ const result = await this.#apiClient.call<string>('perspective.queryProlog', { uuid, query })
126
+ return JSON.parse(result)
127
+ }
171
128
 
172
- return JSON.parse(perspectiveQueryProlog)
129
+ async querySparql(uuid: string, query: string): Promise<unknown> {
130
+ const result = await this.#apiClient.call<string>('perspective.querySparql', { uuid, engine: 'sparql', query })
131
+ return JSON.parse(result)
173
132
  }
174
133
 
175
- async querySparql(uuid: string, query: string): Promise<any> {
176
- const { perspectiveQuerySparql } = unwrapApolloResult(await this.#apolloClient.query({
177
- query: gql`query perspectiveQuerySparql($uuid: String!, $query: String!) {
178
- perspectiveQuerySparql(uuid: $uuid, query: $query)
179
- }`,
180
- variables: { uuid, query }
181
- }))
134
+ async subscribeQuery(uuid: string, query: string): Promise<{ subscriptionId: string, result: AllInstancesResult, isInit?: boolean }> {
135
+ const response = await this.#apiClient.call<{ subscriptionId: string, result: unknown }>(
136
+ 'perspective.subscribeQuery', { uuid, query }
137
+ )
138
+ const { subscriptionId, result } = response
139
+ const normalized = normalizeQueryResult(result, 'Error parsing subscribeQuery result:')
140
+ return { subscriptionId, result: normalized.result, isInit: normalized.isInit }
141
+ }
182
142
 
183
- return JSON.parse(perspectiveQuerySparql)
143
+ async perspectiveKeepAliveQuery(uuid: string, subscriptionId: string): Promise<boolean> {
144
+ return this.#apiClient.call<boolean>(
145
+ 'perspective.keepAliveQuery', { uuid, subscriptionId }
146
+ )
184
147
  }
185
148
 
186
- async subscribeQuery(uuid: string, query: string): Promise<{ subscriptionId: string, result: AllInstancesResult, isInit?: boolean }> {
187
- const { perspectiveSubscribeQuery } = unwrapApolloResult(await this.#apolloClient.mutate({
188
- mutation: gql`mutation perspectiveSubscribeQuery($uuid: String!, $query: String!) {
189
- perspectiveSubscribeQuery(uuid: $uuid, query: $query) {
190
- subscriptionId
191
- result
192
- }
193
- }`,
194
- variables: { uuid, query }
195
- }))
196
- const { subscriptionId, result } = perspectiveSubscribeQuery
197
- let finalResult = result;
198
- let isInit = false;
199
- if(finalResult.startsWith("#init#")) {
200
- finalResult = finalResult.substring(6)
201
- isInit = true;
202
- }
203
- try {
204
- finalResult = JSON.parse(finalResult)
205
- } catch (e) {
206
- console.error('Error parsing perspectiveSubscribeQuery result:', e)
207
- }
208
- return { subscriptionId, result: finalResult, isInit }
149
+ async perspectiveDisposeQuerySubscription(uuid: string, subscriptionId: string): Promise<boolean> {
150
+ return this.#apiClient.call<boolean>(
151
+ 'perspective.disposeQuery', { uuid, subscriptionId }
152
+ )
209
153
  }
210
154
 
211
155
  subscribeToQueryUpdates(subscriptionId: string, onData: (result: AllInstancesResult) => void): () => void {
212
- const subscription = this.#apolloClient.subscribe({
213
- query: gql`
214
- subscription perspectiveQuerySubscription($subscriptionId: String!) {
215
- perspectiveQuerySubscription(subscriptionId: $subscriptionId)
216
- }
217
- `,
218
- variables: {
219
- subscriptionId
220
- }
221
- }).subscribe({
222
- next: (result) => {
223
- if (result.data && result.data.perspectiveQuerySubscription) {
224
- let finalResult = result.data.perspectiveQuerySubscription;
225
- let isInit = false;
226
- if(finalResult.startsWith("#init#")) {
227
- finalResult = finalResult.substring(6)
228
- isInit = true;
229
- }
230
- try {
231
- finalResult = JSON.parse(finalResult)
232
- if(isInit && typeof finalResult === 'object') {
233
- finalResult.isInit = true;
234
- }
235
- } catch (e) {
236
- console.error('Error parsing perspectiveQuerySubscription:', e)
237
- }
238
- onData(finalResult);
239
- }
240
- },
241
- error: (e) => console.error('Error in query subscription:', e)
242
- });
156
+ const unsub = this.#apiClient.subscribe(
157
+ (data) => {
158
+ const event = data as Record<string, unknown>
159
+ if (event.type !== 'query-subscription-update') return
160
+
161
+ const eventSubscriptionId = event.subscriptionId || event.subscription_id
162
+ if (eventSubscriptionId !== subscriptionId) return
243
163
 
244
- return () => subscription.unsubscribe();
164
+ const normalized = normalizeQueryResult(event.result, 'Error parsing query subscription:')
165
+ onData(normalized.result)
166
+ }
167
+ )
168
+ this.#querySubscriptionUnsubscribers.set(subscriptionId, unsub)
169
+ return unsub
245
170
  }
246
171
 
247
172
  async keepAliveQuery(uuid: string, subscriptionId: string): Promise<boolean> {
248
- const { perspectiveKeepAliveQuery } = unwrapApolloResult(await this.#apolloClient.mutate({
249
- mutation: gql`mutation perspectiveKeepAliveQuery($uuid: String!, $subscriptionId: String!) {
250
- perspectiveKeepAliveQuery(uuid: $uuid, subscriptionId: $subscriptionId)
251
- }`,
252
- variables: { uuid, subscriptionId }
253
- }))
254
-
255
- return perspectiveKeepAliveQuery
173
+ return this.#apiClient.call<boolean>(
174
+ 'perspective.keepAliveQuery', { uuid, subscriptionId }
175
+ )
256
176
  }
257
177
 
258
178
  async disposeQuerySubscription(uuid: string, subscriptionId: string): Promise<boolean> {
259
- const { perspectiveDisposeQuerySubscription } = unwrapApolloResult(await this.#apolloClient.mutate({
260
- mutation: gql`mutation perspectiveDisposeQuerySubscription($uuid: String!, $subscriptionId: String!) {
261
- perspectiveDisposeQuerySubscription(uuid: $uuid, subscriptionId: $subscriptionId)
262
- }`,
263
- variables: { uuid, subscriptionId }
264
- }))
179
+ const unsub = this.#querySubscriptionUnsubscribers.get(subscriptionId)
180
+ if (unsub) {
181
+ unsub()
182
+ this.#querySubscriptionUnsubscribers.delete(subscriptionId)
183
+ }
184
+ return this.#apiClient.call<boolean>(
185
+ 'perspective.disposeQuery', { uuid, subscriptionId }
186
+ )
187
+ }
265
188
 
266
- return perspectiveDisposeQuerySubscription
189
+ async modelQuery(uuid: string, className: string, queryJson: string, shapeJson?: string): Promise<any> {
190
+ const resultJson = await this.#apiClient.call<string>(
191
+ 'perspective.modelQuery', { uuid, class_name: className, query_json: queryJson, shape_json: shapeJson }
192
+ )
193
+ return JSON.parse(resultJson)
194
+ }
195
+
196
+ async modelSubscribe(uuid: string, className: string, queryJson: string, shapeJson?: string): Promise<{ subscriptionId: string, result: any }> {
197
+ const response = await this.#apiClient.call<{ subscription_id: string, result: string }>(
198
+ 'perspective.modelSubscribe', { uuid, class_name: className, query_json: queryJson, shape_json: shapeJson }
199
+ )
200
+ return {
201
+ subscriptionId: response.subscription_id,
202
+ result: JSON.parse(response.result)
203
+ }
267
204
  }
268
205
 
269
206
  async add(name: string): Promise<PerspectiveProxy> {
270
- const { perspectiveAdd } = unwrapApolloResult(await this.#apolloClient.mutate({
271
- mutation: gql`mutation perspectiveAdd($name: String!) {
272
- perspectiveAdd(name: $name) {
273
- ${PERSPECTIVE_HANDLE_FIELDS}
274
- }
275
- }`,
276
- variables: { name }
277
- }))
278
- return this.getOrCreateProxy(perspectiveAdd)
207
+ const handle = await this.#apiClient.call<PerspectiveHandle>('perspective.create', { name })
208
+ return new PerspectiveProxy(handle, this)
279
209
  }
280
210
 
281
211
  async update(uuid: string, name: string): Promise<PerspectiveProxy> {
282
- const { perspectiveUpdate } = unwrapApolloResult(await this.#apolloClient.mutate({
283
- mutation: gql`mutation perspectiveUpdate($uuid: String!, $name: String!) {
284
- perspectiveUpdate(uuid: $uuid, name: $name) {
285
- ${PERSPECTIVE_HANDLE_FIELDS}
286
- }
287
- }`,
288
- variables: { uuid, name }
289
- }))
290
- // Evict stale proxy — getOrCreateProxy will create a fresh one with updated handle
291
- this.#proxyCache.delete(uuid)
292
- return this.getOrCreateProxy(perspectiveUpdate)
212
+ const handle = await this.#apiClient.call<PerspectiveHandle>('perspective.update', { uuid, name })
213
+ return new PerspectiveProxy(handle, this)
293
214
  }
294
215
 
295
216
  async remove(uuid: string): Promise<{perspectiveRemove: boolean}> {
296
- this.#proxyCache.delete(uuid)
297
- return unwrapApolloResult(await this.#apolloClient.mutate({
298
- mutation: gql`mutation perspectiveRemove($uuid: String!) {
299
- perspectiveRemove(uuid: $uuid)
300
- }`,
301
- variables: { uuid }
302
- }))
217
+ const result = await this.#apiClient.call<boolean>('perspective.remove', { uuid })
218
+ return { perspectiveRemove: result }
303
219
  }
304
220
 
305
221
  async addLink(uuid: string, link: Link, status: LinkStatus = 'shared', batchId?: string): Promise<LinkExpression> {
306
- const { perspectiveAddLink } = unwrapApolloResult(await this.#apolloClient.mutate({
307
- mutation: gql`mutation perspectiveAddLink($uuid: String!, $link: LinkInput!, $status: String!, $batchId: String) {
308
- perspectiveAddLink(uuid: $uuid, link: $link, status: $status, batchId: $batchId) {
309
- ${LINK_EXPRESSION_FIELDS}
310
- }
311
- }`,
312
- variables: { uuid, link, status, batchId }
313
- }))
314
- return perspectiveAddLink
222
+ return this.#apiClient.call<LinkExpression>(
223
+ 'perspective.addLink', { uuid, link, status, batchId }
224
+ )
315
225
  }
316
226
 
317
227
  async addLinks(uuid: string, links: Link[], status: LinkStatus = 'shared', batchId?: string): Promise<LinkExpression[]> {
318
- const { perspectiveAddLinks } = unwrapApolloResult(await this.#apolloClient.mutate({
319
- mutation: gql`mutation perspectiveAddLinks($uuid: String!, $links: [LinkInput!]!, $status: String!, $batchId: String) {
320
- perspectiveAddLinks(uuid: $uuid, links: $links, status: $status, batchId: $batchId) {
321
- ${LINK_EXPRESSION_FIELDS}
322
- }
323
- }`,
324
- variables: { uuid, links, status, batchId }
325
- }))
326
- return perspectiveAddLinks
228
+ return this.#apiClient.call<LinkExpression[]>(
229
+ 'perspective.addLinks', { uuid, links, status, batchId }
230
+ )
327
231
  }
328
232
 
329
233
  async removeLinks(uuid: string, links: LinkExpressionInput[], batchId?: string): Promise<LinkExpression[]> {
330
- const { perspectiveRemoveLinks } = unwrapApolloResult(await this.#apolloClient.mutate({
331
- mutation: gql`mutation perspectiveRemoveLinks($uuid: String!, $links: [LinkExpressionInput!]!, $batchId: String) {
332
- perspectiveRemoveLinks(uuid: $uuid, links: $links, batchId: $batchId) {
333
- ${LINK_EXPRESSION_FIELDS}
334
- }
335
- }`,
336
- variables: { uuid, links, batchId }
337
- }))
338
- return perspectiveRemoveLinks
234
+ return this.#apiClient.call<LinkExpression[]>(
235
+ 'perspective.removeLinks', { uuid, links, batchId }
236
+ )
339
237
  }
340
238
 
341
239
  async linkMutations(uuid: string, mutations: LinkMutations, status?: LinkStatus): Promise<LinkExpressionMutations> {
342
- const { perspectiveLinkMutations } = unwrapApolloResult(await this.#apolloClient.mutate({
343
- mutation: gql`mutation perspectiveLinkMutations($uuid: String!, $mutations: LinkMutations!, $status: String){
344
- perspectiveLinkMutations(mutations: $mutations, uuid: $uuid, status: $status) {
345
- additions {
346
- ${LINK_EXPRESSION_FIELDS}
347
- }
348
- removals {
349
- ${LINK_EXPRESSION_FIELDS}
350
- }
351
- }
352
- }`,
353
- variables: { uuid, mutations, status }
354
- }))
355
- return perspectiveLinkMutations
240
+ return this.#apiClient.call<LinkExpressionMutations>(
241
+ 'perspective.linkMutations', { uuid, mutations, status }
242
+ )
356
243
  }
357
244
 
358
245
  async addLinkExpression(uuid: string, link: LinkExpression, status: LinkStatus = 'shared', batchId?: string): Promise<LinkExpression> {
359
- const { perspectiveAddLinkExpression } = unwrapApolloResult(await this.#apolloClient.mutate({
360
- mutation: gql`mutation perspectiveAddLinkExpression($uuid: String!, $link: LinkExpressionInput!, $status: String!, $batchId: String) {
361
- perspectiveAddLinkExpression(uuid: $uuid, link: $link, status: $status, batchId: $batchId) {
362
- ${LINK_EXPRESSION_FIELDS}
363
- }
364
- }`,
365
- variables: { uuid, link, status, batchId }
366
- }))
367
- return perspectiveAddLinkExpression
246
+ return this.#apiClient.call<LinkExpression>(
247
+ 'perspective.addLinkExpression', { uuid, link, status, batchId }
248
+ )
368
249
  }
369
250
 
370
251
  async updateLink(uuid: string, oldLink: LinkExpressionInput, newLink: Link, batchId?: string): Promise<LinkExpression> {
371
- const { perspectiveUpdateLink } = unwrapApolloResult(await this.#apolloClient.mutate({
372
- mutation: gql`mutation perspectiveUpdateLink($uuid: String!, $oldLink: LinkExpressionInput!, $newLink: LinkInput!, $batchId: String) {
373
- perspectiveUpdateLink(uuid: $uuid, oldLink: $oldLink, newLink: $newLink, batchId: $batchId) {
374
- ${LINK_EXPRESSION_FIELDS}
375
- }
376
- }`,
377
- variables: { uuid, oldLink, newLink, batchId }
378
- }))
379
- return perspectiveUpdateLink
252
+ return this.#apiClient.call<LinkExpression>(
253
+ 'perspective.updateLink', { uuid, oldLink, newLink, batchId }
254
+ )
380
255
  }
381
256
 
382
257
  async removeLink(uuid: string, link: LinkExpressionInput, batchId?: string): Promise<boolean> {
@@ -384,68 +259,42 @@ export class PerspectiveClient {
384
259
  delete link.data.__typename
385
260
  delete link.proof.__typename
386
261
  delete link.status
387
- const { perspectiveRemoveLink } = unwrapApolloResult(await this.#apolloClient.mutate({
388
- mutation: gql`mutation perspectiveRemoveLink($link: LinkExpressionInput!, $uuid: String!, $batchId: String) {
389
- perspectiveRemoveLink(link: $link, uuid: $uuid, batchId: $batchId)
390
- }`,
391
- variables: { uuid, link, batchId }
392
- }))
393
- return perspectiveRemoveLink
394
- }
395
-
396
- /**
397
- * Adds Social DNA code to a perspective.
398
- *
399
- * Preferred usage: pass shaclJson (from SHACLShape.toJSON()) as the primary schema definition.
400
- * The sdnaCode parameter is kept for backward compatibility but SHACL is the source of truth
401
- * for all SDNA operations. Prolog engines remain available for complex queries.
402
- *
403
- * @param sdnaCode - Legacy Prolog code (pass empty string when using shaclJson)
404
- * @param shaclJson - SHACL JSON string from SHACLShape.toJSON() (recommended)
405
- */
262
+ return this.#apiClient.call<boolean>(
263
+ 'perspective.removeLink', { uuid, link, batchId }
264
+ )
265
+ }
266
+
406
267
  async addSdna(uuid: string, name: string, sdnaCode: string | undefined, sdnaType: "subject_class" | "flow" | "custom", shaclJson?: string): Promise<boolean> {
407
- return unwrapApolloResult(await this.#apolloClient.mutate({
408
- mutation: gql`mutation perspectiveAddSdna($uuid: String!, $name: String!, $sdnaCode: String, $sdnaType: String!, $shaclJson: String) {
409
- perspectiveAddSdna(uuid: $uuid, name: $name, sdnaCode: $sdnaCode, sdnaType: $sdnaType, shaclJson: $shaclJson)
410
- }`,
411
- variables: { uuid, name, sdnaCode: sdnaCode || "", sdnaType, shaclJson }
412
- })).perspectiveAddSdna
268
+ return this.#apiClient.call<boolean>(
269
+ 'perspective.addSdna', { uuid, name, sdnaCode: sdnaCode || "", sdnaType, shaclJson }
270
+ )
413
271
  }
414
272
 
415
273
  async executeCommands(uuid: string, commands: string, expression: string, parameters: string, batchId?: string): Promise<boolean> {
416
- return unwrapApolloResult(await this.#apolloClient.mutate({
417
- mutation: gql`mutation perspectiveExecuteCommands($uuid: String!, $commands: String!, $expression: String!, $parameters: String, $batchId: String) {
418
- perspectiveExecuteCommands(uuid: $uuid, commands: $commands, expression: $expression, parameters: $parameters, batchId: $batchId)
419
- }`,
420
- variables: { uuid, commands, expression, parameters, batchId }
421
- })).perspectiveExecuteCommands
274
+ return this.#apiClient.call<boolean>(
275
+ 'perspective.executeCommands', { uuid, commands, expression, parameters, batchId }
276
+ )
422
277
  }
423
278
 
424
279
  async createSubject(uuid: string, subjectClass: string, expressionAddress: string, initialValues?: string, batchId?: string): Promise<boolean> {
425
- return unwrapApolloResult(await this.#apolloClient.mutate({
426
- mutation: gql`mutation perspectiveCreateSubject($uuid: String!, $subjectClass: String!, $expressionAddress: String!, $initialValues: String, $batchId: String) {
427
- perspectiveCreateSubject(uuid: $uuid, subjectClass: $subjectClass, expressionAddress: $expressionAddress, initialValues: $initialValues, batchId: $batchId)
428
- }`,
429
- variables: { uuid, subjectClass, expressionAddress, initialValues, batchId }
430
- })).perspectiveCreateSubject
280
+ return this.#apiClient.call<boolean>(
281
+ 'perspective.createSubject', { uuid, subjectClass, expressionAddress, initialValues, batchId }
282
+ )
431
283
  }
432
284
 
433
285
  async getSubjectData(uuid: string, subjectClass: string, expressionAddress: string): Promise<string> {
434
- return unwrapApolloResult(await this.#apolloClient.mutate({
435
- mutation: gql`mutation perspectiveGetSubjectData($uuid: String!, $subjectClass: String!, $expressionAddress: String!) {
436
- perspectiveGetSubjectData(uuid: $uuid, subjectClass: $subjectClass, expressionAddress: $expressionAddress)
437
- }`,
438
- variables: { uuid, subjectClass, expressionAddress }
439
- })).perspectiveGetSubjectData
286
+ return this.#apiClient.call<string>(
287
+ 'perspective.getSubjectData', { uuid, subjectClass, expressionAddress }
288
+ )
440
289
  }
441
290
 
442
291
  // ExpressionClient functions, needed for Subjects:
443
292
  async getExpression(expressionURI: string): Promise<ExpressionRendered> {
444
- return await this.#expressionClient.get(expressionURI)
293
+ return await this.#expressionClient!.get(expressionURI)
445
294
  }
446
295
 
447
- async createExpression(content: any, languageAddress: string): Promise<string> {
448
- return await this.#expressionClient.create(content, languageAddress)
296
+ async createExpression(content: unknown, languageAddress: string): Promise<string> {
297
+ return await this.#expressionClient!.create(content, languageAddress)
449
298
  }
450
299
 
451
300
  // Subscriptions:
@@ -454,21 +303,12 @@ export class PerspectiveClient {
454
303
  }
455
304
 
456
305
  subscribePerspectiveAdded() {
457
- this.#apolloClient.subscribe({
458
- query: gql` subscription {
459
- perspectiveAdded { ${PERSPECTIVE_HANDLE_FIELDS} }
306
+ const unsub = this.#apiClient.subscribe((data) => {
307
+ if (data.type === 'perspective-added') {
308
+ this.#perspectiveAddedCallbacks.forEach(cb => cb(data.perspective as PerspectiveHandle))
460
309
  }
461
- `}).subscribe({
462
- next: result => {
463
- const handle = result.data.perspectiveAdded
464
- this.#perspectiveAddedCallbacks.forEach(cb => {
465
- cb(handle)
466
- })
467
- // Populate cache so subsequent byUUID() calls get a hit
468
- this.getOrCreateProxy(handle)
469
- },
470
- error: (e) => console.error(e)
471
310
  })
311
+ this.#unsubscribers.push(unsub)
472
312
  }
473
313
 
474
314
  addPerspectiveUpdatedListener(cb: PerspectiveHandleCallback) {
@@ -476,22 +316,12 @@ export class PerspectiveClient {
476
316
  }
477
317
 
478
318
  subscribePerspectiveUpdated() {
479
- this.#apolloClient.subscribe({
480
- query: gql` subscription {
481
- perspectiveUpdated { ${PERSPECTIVE_HANDLE_FIELDS} }
319
+ const unsub = this.#apiClient.subscribe((data) => {
320
+ if (data.type === 'perspective-updated') {
321
+ this.#perspectiveUpdatedCallbacks.forEach(cb => cb(data.perspective as PerspectiveHandle))
482
322
  }
483
- `}).subscribe({
484
- next: result => {
485
- const handle = result.data.perspectiveUpdated
486
- this.#perspectiveUpdatedCallbacks.forEach(cb => {
487
- cb(handle)
488
- })
489
- // Evict stale proxy and create fresh one with updated handle
490
- this.#proxyCache.delete(handle.uuid)
491
- this.getOrCreateProxy(handle)
492
- },
493
- error: (e) => console.error(e)
494
323
  })
324
+ this.#unsubscribers.push(unsub)
495
325
  }
496
326
 
497
327
  addPerspectiveSyncedListener(cb: SyncStateChangeCallback) {
@@ -499,19 +329,14 @@ export class PerspectiveClient {
499
329
  }
500
330
 
501
331
  async addPerspectiveSyncStateChangeListener(uuid: String, cb: SyncStateChangeCallback[]): Promise<void> {
502
- this.#apolloClient.subscribe({
503
- query: gql` subscription {
504
- perspectiveSyncStateChange(uuid: "${uuid}")
332
+ const unsub = this.#apiClient.subscribe(
333
+ (data) => {
334
+ if (data.type === 'sync-state-change' && data.uuid === uuid) {
335
+ cb.forEach(c => c(data.state as PerspectiveState))
336
+ }
505
337
  }
506
- `}).subscribe({
507
- next: result => {
508
- cb.forEach(c => {
509
- c(result.data.perspectiveSyncStateChange)
510
- })
511
- },
512
- error: (e) => console.error(e)
513
- })
514
-
338
+ )
339
+ this.#unsubscribers.push(unsub)
515
340
  await new Promise<void>(resolve => setTimeout(resolve, 500))
516
341
  }
517
342
 
@@ -520,118 +345,79 @@ export class PerspectiveClient {
520
345
  }
521
346
 
522
347
  subscribePerspectiveRemoved() {
523
- this.#apolloClient.subscribe({
524
- query: gql` subscription {
525
- perspectiveRemoved
348
+ const unsub = this.#apiClient.subscribe((data) => {
349
+ if (data.type === 'perspective-removed') {
350
+ this.#perspectiveRemovedCallbacks.forEach(cb => cb(data.uuid as string))
526
351
  }
527
- `}).subscribe({
528
- next: result => {
529
- const uuid = result.data.perspectiveRemoved
530
- this.#perspectiveRemovedCallbacks.forEach(cb => {
531
- cb(uuid)
532
- })
533
- // Evict from cache
534
- this.#proxyCache.delete(uuid)
535
- },
536
- error: (e) => console.error(e)
537
352
  })
353
+ this.#unsubscribers.push(unsub)
538
354
  }
539
355
 
540
356
  async addPerspectiveLinkAddedListener(uuid: String, cb: LinkCallback[]): Promise<void> {
541
- this.#apolloClient.subscribe({
542
- query: gql` subscription {
543
- perspectiveLinkAdded(uuid: "${uuid}") { ${LINK_EXPRESSION_FIELDS} }
357
+ const unsub = this.#apiClient.subscribe(
358
+ (data) => {
359
+ if (data.type === 'link-added' && data.perspectiveUuid === uuid) {
360
+ cb.forEach(c => c(data.link as LinkExpression))
361
+ }
544
362
  }
545
- `}).subscribe({
546
- next: result => {
547
- cb.forEach(c => {
548
- c(result.data.perspectiveLinkAdded)
549
- })
550
- },
551
- error: (e) => console.error(e)
552
- })
553
-
554
- await new Promise<void>(resolve => setTimeout(resolve, 500))
363
+ )
364
+ let existing = this.#linkUnsubscribers.get(uuid as string) || []
365
+ existing.push(unsub)
366
+ this.#linkUnsubscribers.set(uuid as string, existing)
367
+ await this.#apiClient.waitForSubscription()
555
368
  }
556
369
 
557
370
  async addPerspectiveLinkRemovedListener(uuid: String, cb: LinkCallback[]): Promise<void> {
558
- this.#apolloClient.subscribe({
559
- query: gql` subscription {
560
- perspectiveLinkRemoved(uuid: "${uuid}") { ${LINK_EXPRESSION_FIELDS} }
561
- }
562
- `}).subscribe({
563
- next: result => {
564
- cb.forEach(c => {
565
- if (!result.data.perspectiveLinkRemoved.status) {
566
- delete result.data.perspectiveLinkRemoved.status
371
+ const unsub = this.#apiClient.subscribe(
372
+ (data) => {
373
+ if (data.type === 'link-removed' && data.perspectiveUuid === uuid) {
374
+ const link = data.link as LinkExpression & { status?: unknown }
375
+ if (!link.status) {
376
+ delete link.status
567
377
  }
568
- c(result.data.perspectiveLinkRemoved)
569
- })
570
- },
571
- error: (e) => console.error(e)
572
- })
573
-
574
- await new Promise<void>(resolve => setTimeout(resolve, 500))
378
+ cb.forEach(c => c(link))
379
+ }
380
+ }
381
+ )
382
+ let existing = this.#linkUnsubscribers.get(uuid as string) || []
383
+ existing.push(unsub)
384
+ this.#linkUnsubscribers.set(uuid as string, existing)
385
+ await this.#apiClient.waitForSubscription()
575
386
  }
576
387
 
577
388
  async addPerspectiveLinkUpdatedListener(uuid: String, cb: LinkCallback[]): Promise<void> {
578
- this.#apolloClient.subscribe({
579
- query: gql` subscription {
580
- perspectiveLinkUpdated(uuid: "${uuid}") {
581
- oldLink {
582
- ${LINK_EXPRESSION_FIELDS}
389
+ const unsub = this.#apiClient.subscribe(
390
+ (data) => {
391
+ if (data.type === 'link-updated' && data.perspectiveUuid === uuid) {
392
+ const newLink = data.newLink as LinkExpression & { status?: unknown }
393
+ const oldLink = data.oldLink as LinkExpression & { status?: unknown }
394
+ if (!newLink.status) {
395
+ delete newLink.status
583
396
  }
584
- newLink {
585
- ${LINK_EXPRESSION_FIELDS}
397
+ if (!oldLink.status) {
398
+ delete oldLink.status
586
399
  }
400
+ cb.forEach(c => c(data as unknown as LinkExpression))
587
401
  }
588
402
  }
589
- `}).subscribe({
590
- next: result => {
591
- cb.forEach(c => {
592
- if (!result.data.perspectiveLinkUpdated.newLink.status) {
593
- delete result.data.perspectiveLinkUpdated.newLink.status
594
- }
595
- if (!result.data.perspectiveLinkUpdated.oldLink.status) {
596
- delete result.data.perspectiveLinkUpdated.oldLink.status
597
- }
598
- c(result.data.perspectiveLinkUpdated)
599
- })
600
- },
601
- error: (e) => console.error(e)
602
- })
603
-
604
- await new Promise<void>(resolve => setTimeout(resolve, 500))
403
+ )
404
+ let existing = this.#linkUnsubscribers.get(uuid as string) || []
405
+ existing.push(unsub)
406
+ this.#linkUnsubscribers.set(uuid as string, existing)
407
+ await this.#apiClient.waitForSubscription()
605
408
  }
606
409
 
607
410
  getNeighbourhoodProxy(uuid: string): NeighbourhoodProxy {
608
- return new NeighbourhoodProxy(this.#neighbourhoodClient, uuid)
411
+ return new NeighbourhoodProxy(this.#neighbourhoodClient!, uuid)
609
412
  }
610
413
 
611
414
  async createBatch(uuid: string): Promise<string> {
612
- const { perspectiveCreateBatch } = unwrapApolloResult(await this.#apolloClient.mutate({
613
- mutation: gql`mutation perspectiveCreateBatch($uuid: String!) {
614
- perspectiveCreateBatch(uuid: $uuid)
615
- }`,
616
- variables: { uuid }
617
- }))
618
- return perspectiveCreateBatch
415
+ return this.#apiClient.call<string>('perspective.createBatch', { uuid })
619
416
  }
620
417
 
621
418
  async commitBatch(uuid: string, batchId: string): Promise<LinkExpressionMutations> {
622
- const { perspectiveCommitBatch } = unwrapApolloResult(await this.#apolloClient.mutate({
623
- mutation: gql`mutation perspectiveCommitBatch($uuid: String!, $batchId: String!) {
624
- perspectiveCommitBatch(uuid: $uuid, batchId: $batchId) {
625
- additions {
626
- ${LINK_EXPRESSION_FIELDS}
627
- }
628
- removals {
629
- ${LINK_EXPRESSION_FIELDS}
630
- }
631
- }
632
- }`,
633
- variables: { uuid, batchId }
634
- }))
635
- return perspectiveCommitBatch
419
+ return this.#apiClient.call<LinkExpressionMutations>(
420
+ 'perspective.commitBatch', { uuid, batchId }
421
+ )
636
422
  }
637
- }
423
+ }