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