@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
@@ -13,17 +13,29 @@ var _QuerySubscriptionProxy_instances, _QuerySubscriptionProxy_uuid, _QuerySubsc
13
13
  import { Link } from "../links/Links";
14
14
  import { LinkQuery } from "./LinkQuery";
15
15
  import { Literal } from "../Literal";
16
- import { Subject } from "../model/Subject";
17
16
  import { getPropertiesMetadata, getRelationsMetadata } from "../model/decorators";
18
17
  import { getCachedResult, setCachedResult, invalidatePerspectiveCache } from "../model/query-cache";
19
18
  import { SHACLShape } from "../shacl/SHACLShape";
20
19
  import { SHACLFlow } from "../shacl/SHACLFlow";
20
+ /** Extract namespace prefix from a URI (everything up to and including the last / or #) */
21
+ function extractNamespaceFromUri(uri) {
22
+ const hashIdx = uri.lastIndexOf('#');
23
+ if (hashIdx >= 0)
24
+ return uri.substring(0, hashIdx + 1);
25
+ const slashIdx = uri.lastIndexOf('/');
26
+ if (slashIdx >= 0)
27
+ return uri.substring(0, slashIdx + 1);
28
+ const colonIdx = uri.lastIndexOf(':');
29
+ if (colonIdx >= 0)
30
+ return uri.substring(0, colonIdx + 1);
31
+ return uri;
32
+ }
21
33
  /** Proxy object for a subscribed Prolog query that provides real-time updates
22
34
  *
23
35
  * This class handles:
24
36
  * - Keeping the subscription alive by sending periodic keepalive signals
25
37
  * - Managing callbacks for result updates
26
- * - Subscribing to query updates via GraphQL subscriptions
38
+ * - Subscribing to query updates via WebSocket subscriptions
27
39
  * - Maintaining the latest query result
28
40
  * - Ensuring subscription is fully initialized before allowing access
29
41
  * - Cleaning up resources when disposed
@@ -104,22 +116,31 @@ export class QuerySubscriptionProxy {
104
116
  let initialResult;
105
117
  initialResult = await __classPrivateFieldGet(this, _QuerySubscriptionProxy_client, "f").subscribeQuery(__classPrivateFieldGet(this, _QuerySubscriptionProxy_uuid, "f"), __classPrivateFieldGet(this, _QuerySubscriptionProxy_query, "f"));
106
118
  __classPrivateFieldSet(this, _QuerySubscriptionProxy_subscriptionId, initialResult.subscriptionId, "f");
107
- // Process the initial result immediately for fast UX
108
- if (initialResult.result) {
119
+ // Process the initial result immediately for fast UX.
120
+ // The subscribeQuery() RPC call already returns the initial result,
121
+ // so treat that as successful initialization instead of waiting for a
122
+ // follow-up WebSocket update that may never arrive until the query changes.
123
+ if (initialResult.result !== undefined) {
109
124
  __classPrivateFieldSet(this, _QuerySubscriptionProxy_latestResult, initialResult.result, "f");
110
125
  __classPrivateFieldGet(this, _QuerySubscriptionProxy_instances, "m", _QuerySubscriptionProxy_notifyCallbacks).call(this, initialResult.result);
126
+ if (__classPrivateFieldGet(this, _QuerySubscriptionProxy_initResolve, "f")) {
127
+ __classPrivateFieldGet(this, _QuerySubscriptionProxy_initResolve, "f").call(this, true);
128
+ __classPrivateFieldSet(this, _QuerySubscriptionProxy_initResolve, undefined, "f");
129
+ __classPrivateFieldSet(this, _QuerySubscriptionProxy_initReject, undefined, "f");
130
+ }
111
131
  }
112
132
  else {
113
133
  console.warn('⚠️ No initial result returned from subscribeQuery!');
134
+ // Only keep the initialization timeout when the backend did not
135
+ // provide an initial result up front.
136
+ __classPrivateFieldSet(this, _QuerySubscriptionProxy_initTimeoutId, setTimeout(() => {
137
+ console.error('Subscription initialization timed out after 30 seconds. Resubscribing...');
138
+ // Recursively retry subscription, catching any errors
139
+ this.subscribe().catch(error => {
140
+ console.error('Error during subscription retry after timeout:', error);
141
+ });
142
+ }, 30000), "f");
114
143
  }
115
- // Set up timeout for retry
116
- __classPrivateFieldSet(this, _QuerySubscriptionProxy_initTimeoutId, setTimeout(() => {
117
- console.error('Subscription initialization timed out after 30 seconds. Resubscribing...');
118
- // Recursively retry subscription, catching any errors
119
- this.subscribe().catch(error => {
120
- console.error('Error during subscription retry after timeout:', error);
121
- });
122
- }, 30000), "f");
123
144
  // Subscribe to query updates
124
145
  __classPrivateFieldSet(this, _QuerySubscriptionProxy_unsubscribe, __classPrivateFieldGet(this, _QuerySubscriptionProxy_client, "f").subscribeToQueryUpdates(__classPrivateFieldGet(this, _QuerySubscriptionProxy_subscriptionId, "f"), (updateResult) => {
125
146
  // Clear timeout on first message
@@ -242,7 +263,7 @@ export class QuerySubscriptionProxy {
242
263
  *
243
264
  * This method:
244
265
  * 1. Stops the keepalive timer
245
- * 2. Unsubscribes from GraphQL subscription updates
266
+ * 2. Unsubscribes from subscription updates
246
267
  * 3. Clears all registered callbacks
247
268
  * 4. Cleans up any pending initialization timeout
248
269
  *
@@ -317,6 +338,8 @@ _QuerySubscriptionProxy_uuid = new WeakMap(), _QuerySubscriptionProxy_subscripti
317
338
  * ```
318
339
  */
319
340
  export class PerspectiveProxy {
341
+ /** @internal Exposed for ModelQueryBuilder subscription management */
342
+ get client() { return __classPrivateFieldGet(this, _PerspectiveProxy_client, "f"); }
320
343
  /**
321
344
  * Creates a new PerspectiveProxy instance.
322
345
  * Note: Don't create this directly, use ad4m.perspective.add() instead.
@@ -517,6 +540,33 @@ export class PerspectiveProxy {
517
540
  setCachedResult(__classPrivateFieldGet(this, _PerspectiveProxy_handle, "f").uuid, query, result);
518
541
  return result;
519
542
  }
543
+ /**
544
+ * Execute a model query — the executor-side replacement for SPARQL query building + JS hydration.
545
+ *
546
+ * @param className - The model class name (e.g. "Recipe")
547
+ * @param queryJson - Structured query as JSON string
548
+ * @param shapeJson - Optional shape metadata JSON from the model class
549
+ * @returns Object with `instances` array and `totalCount`
550
+ */
551
+ async modelQuery(className, queryJson, shapeJson) {
552
+ return await __classPrivateFieldGet(this, _PerspectiveProxy_client, "f").modelQuery(__classPrivateFieldGet(this, _PerspectiveProxy_handle, "f").uuid, className, queryJson, shapeJson);
553
+ }
554
+ /**
555
+ * Subscribe to model query changes. Builds trigger SPARQL from the model shape
556
+ * internally in Rust, registers a subscription, runs the initial query, and
557
+ * pushes updated results when relevant links change.
558
+ *
559
+ * The subscription reuses the same GraphQL subscription channel as subscribeQuery().
560
+ * Use keepAliveQuery() / disposeQuerySubscription() with the returned subscriptionId.
561
+ *
562
+ * @param className - The model class name
563
+ * @param queryJson - JSON-serialized query parameters (same as modelQuery)
564
+ * @param shapeJson - Optional shape metadata JSON from the model class
565
+ * @returns Object with `subscriptionId` and initial `result`
566
+ */
567
+ async modelSubscribe(className, queryJson, shapeJson) {
568
+ return await __classPrivateFieldGet(this, _PerspectiveProxy_client, "f").modelSubscribe(__classPrivateFieldGet(this, _PerspectiveProxy_handle, "f").uuid, className, queryJson, shapeJson);
569
+ }
520
570
  /**
521
571
  * Adds a new link to the perspective.
522
572
  *
@@ -984,7 +1034,7 @@ export class PerspectiveProxy {
984
1034
  * Adds Social DNA code to the perspective.
985
1035
  *
986
1036
  * **Recommended:** Use {@link addShacl} instead, which accepts the `SHACLShape` type directly.
987
- * This method is primarily for the GraphQL layer and legacy Prolog code.
1037
+ * This method is primarily for the RPC API layer and legacy Prolog code.
988
1038
  *
989
1039
  * @param name - Unique name for this SDNA definition
990
1040
  * @param sdnaCode - Prolog SDNA code (legacy, can be empty string if shaclJson provided)
@@ -1219,7 +1269,7 @@ export class PerspectiveProxy {
1219
1269
  */
1220
1270
  async subjectClasses() {
1221
1271
  try {
1222
- // Query SHACL class links directly — no need for a separate GraphQL endpoint
1272
+ // Query SHACL class links directly — no need for a separate RPC endpoint
1223
1273
  const classLinks = await this.get(new LinkQuery({
1224
1274
  predicate: "rdf://type",
1225
1275
  target: "ad4m://SubjectClass"
@@ -1292,7 +1342,9 @@ export class PerspectiveProxy {
1292
1342
  if (batchId) {
1293
1343
  return exprAddr;
1294
1344
  }
1295
- return this.getSubjectProxy(exprAddr, subjectClass);
1345
+ // Return the expression address directly — callers should use Ad4mModel or
1346
+ // getSubjectData() to interact with the created instance.
1347
+ return exprAddr;
1296
1348
  }
1297
1349
  async getSubjectData(subjectClass, exprAddr) {
1298
1350
  if (typeof subjectClass === "string") {
@@ -1368,7 +1420,7 @@ export class PerspectiveProxy {
1368
1420
  async isSubjectInstance(expression, subjectClass) {
1369
1421
  let className = await this.stringOrTemplateObjectToSubjectClassName(subjectClass);
1370
1422
  // Get metadata from SHACL links
1371
- const metadata = await this.getSubjectClassMetadataFromSDNA(className);
1423
+ const metadata = await this.getSubjectClassMetadata(className);
1372
1424
  if (!metadata) {
1373
1425
  console.warn(`isSubjectInstance: No SHACL metadata found for class ${className}`);
1374
1426
  return false;
@@ -1378,49 +1430,19 @@ export class PerspectiveProxy {
1378
1430
  const links = await this.get(new LinkQuery({ source: expression }));
1379
1431
  return links.length > 0;
1380
1432
  }
1381
- // Check if the expression has all required triples (predicate + optional exact target)
1382
- for (const triple of metadata.requiredTriples) {
1383
- let query;
1384
- if (triple.target) {
1385
- query = new LinkQuery({ source: expression, predicate: triple.predicate, target: triple.target });
1386
- }
1387
- else {
1388
- query = new LinkQuery({ source: expression, predicate: triple.predicate });
1389
- }
1390
- const links = await this.get(query);
1391
- if (!links || links.length === 0) {
1392
- return false;
1393
- }
1394
- }
1395
- return true;
1396
- }
1397
- /** For an existing subject instance (existing in the perspective's links)
1398
- * this function returns a proxy object that can be used to access the subject's
1399
- * properties and methods.
1400
- *
1401
- * @param base URI of the subject's root expression
1402
- * @param subjectClass Either a string with the name of the subject class, or an object
1403
- * with the properties of the subject class. In the latter case, the first subject class
1404
- * that matches the given properties will be used.
1405
- */
1406
- async getSubjectProxy(base, subjectClass) {
1407
- if (!await this.isSubjectInstance(base, subjectClass)) {
1408
- throw `Expression ${base} is not a subject instance of given class: ${JSON.stringify(subjectClass)}`;
1409
- }
1410
- let className = await this.stringOrTemplateObjectToSubjectClassName(subjectClass);
1411
- let subject = new Subject(this, base, className);
1412
- await subject.init();
1413
- return subject;
1433
+ // Build a single SPARQL ASK query with all required triple patterns
1434
+ const patterns = metadata.requiredTriples.map((t, i) => {
1435
+ const target = t.target ? `<${t.target}>` : `?t${i}`;
1436
+ return `<${expression}> <${t.predicate}> ${target} .`;
1437
+ }).join('\n ');
1438
+ const result = await this.querySparql(`ASK WHERE {\n ${patterns}\n}`);
1439
+ return result === true;
1414
1440
  }
1415
1441
  /**
1416
1442
  * Gets subject class metadata from SHACL links using SHACLShape.fromLinks().
1417
1443
  * Retrieves the SHACL shape and extracts metadata for instance queries.
1418
1444
  */
1419
1445
  async getSubjectClassMetadata(className) {
1420
- return this.getSubjectClassMetadataFromSDNA(className);
1421
- }
1422
- /** @deprecated Use getSubjectClassMetadata() */
1423
- async getSubjectClassMetadataFromSDNA(className) {
1424
1446
  try {
1425
1447
  // Use getShacl() to retrieve the shape via SHACLShape.fromLinks()
1426
1448
  const shape = await this.getShacl(className);
@@ -1487,214 +1509,15 @@ export class PerspectiveProxy {
1487
1509
  const sources = new Set(allLinks.map(l => l.data.source));
1488
1510
  return Array.from(sources).map(s => ({ base: s }));
1489
1511
  }
1490
- // Use first required triple to get candidate set, then filter by rest
1491
- const first = metadata.requiredTriples[0];
1492
- let query;
1493
- if (first.target) {
1494
- query = new LinkQuery({ predicate: first.predicate, target: first.target });
1495
- }
1496
- else {
1497
- query = new LinkQuery({ predicate: first.predicate });
1498
- }
1499
- const candidateLinks = await this.get(query);
1500
- let candidates = [...new Set(candidateLinks.map(l => l.data.source))];
1501
- // Filter by remaining required triples
1502
- for (let i = 1; i < metadata.requiredTriples.length; i++) {
1503
- const triple = metadata.requiredTriples[i];
1504
- const remaining = [];
1505
- for (const expr of candidates) {
1506
- let q;
1507
- if (triple.target) {
1508
- q = new LinkQuery({ source: expr, predicate: triple.predicate, target: triple.target });
1509
- }
1510
- else {
1511
- q = new LinkQuery({ source: expr, predicate: triple.predicate });
1512
- }
1513
- const links = await this.get(q);
1514
- if (links.length > 0)
1515
- remaining.push(expr);
1516
- }
1517
- candidates = remaining;
1518
- }
1519
- return candidates.map(c => ({ base: c }));
1520
- }
1521
- /**
1522
- * Gets a property value using SPARQL when Prolog fails.
1523
- * This is used as a fallback in SdnaOnly mode where link data isn't in Prolog.
1524
- */
1525
- async getPropertyValueViaSparql(baseExpression, className, propertyName) {
1526
- const metadata = await this.getSubjectClassMetadataFromSDNA(className);
1527
- if (!metadata) {
1528
- return undefined;
1529
- }
1530
- const propMeta = metadata.properties.get(propertyName);
1531
- if (!propMeta) {
1532
- return undefined;
1533
- }
1534
- const links = await this.get(new LinkQuery({ source: baseExpression, predicate: propMeta.predicate }));
1535
- if (!links || links.length === 0) {
1536
- return undefined;
1537
- }
1538
- const value = links[0].data.target;
1539
- // Handle expression resolution if needed
1540
- if (propMeta.resolveLanguage && value) {
1541
- try {
1542
- const expression = await this.getExpression(value);
1543
- try {
1544
- return JSON.parse(expression.data);
1545
- }
1546
- catch (e) {
1547
- return expression.data;
1548
- }
1549
- }
1550
- catch (err) {
1551
- return value;
1552
- }
1553
- }
1554
- return value;
1555
- }
1556
- /**
1557
- * Gets relation values using SPARQL when Prolog fails.
1558
- * This is used as a fallback in SdnaOnly mode where link data isn't in Prolog.
1559
- * Note: This is used by Subject.ts (legacy pattern). Ad4mModel.ts uses getModelMetadata() instead.
1560
- */
1561
- async getRelationValuesViaSparql(baseExpression, className, relationName) {
1562
- const metadata = await this.getSubjectClassMetadataFromSDNA(className);
1563
- if (!metadata) {
1564
- return [];
1565
- }
1566
- const relMeta = metadata.relations.get(relationName);
1567
- if (!relMeta) {
1568
- return [];
1569
- }
1570
- const links = await this.get(new LinkQuery({ source: baseExpression, predicate: relMeta.predicate }));
1571
- if (!links || links.length === 0) {
1512
+ // Build a single SPARQL SELECT with all required triple patterns joined
1513
+ const patterns = metadata.requiredTriples.map((t, i) => {
1514
+ const target = t.target ? `<${t.target}>` : `?t${i}`;
1515
+ return `?base <${t.predicate}> ${target} .`;
1516
+ }).join('\n ');
1517
+ const results = await this.querySparql(`SELECT DISTINCT ?base WHERE {\n ${patterns}\n}`);
1518
+ if (!Array.isArray(results))
1572
1519
  return [];
1573
- }
1574
- // Sort by timestamp ascending
1575
- links.sort((a, b) => new Date(a.timestamp).getTime() - new Date(b.timestamp).getTime());
1576
- let values = links.map(l => l.data.target).filter(v => v !== "" && v !== '');
1577
- // Apply condition filtering if present
1578
- if (relMeta.condition && values.length > 0) {
1579
- try {
1580
- const filteredValues = [];
1581
- for (const value of values) {
1582
- let condition = relMeta.condition
1583
- .replace(/\$perspective/g, `'${this.uuid}'`)
1584
- .replace(/\$base/g, `'${baseExpression}'`)
1585
- .replace(/Target/g, `'${value.replace(/'/g, "\\'")}'`);
1586
- // Parse condition to extract link query parameters
1587
- // Conditions typically look like: WHERE in.uri = 'X' AND predicate = 'Y' AND out.uri = 'Z'
1588
- // or: array::len(SELECT * FROM link WHERE ...) > 0
1589
- // Convert to queryLinks calls
1590
- const sourceMatch = condition.match(/in\.uri\s*=\s*'([^']+)'/);
1591
- const predicateMatch = condition.match(/predicate\s*=\s*'([^']+)'/);
1592
- const targetMatch = condition.match(/out\.uri\s*=\s*'([^']+)'/);
1593
- if (sourceMatch || predicateMatch || targetMatch) {
1594
- const linkQuery = {};
1595
- if (sourceMatch)
1596
- linkQuery.source = sourceMatch[1];
1597
- if (predicateMatch)
1598
- linkQuery.predicate = predicateMatch[1];
1599
- if (targetMatch)
1600
- linkQuery.target = targetMatch[1];
1601
- const matchingLinks = await this.get(new LinkQuery(linkQuery));
1602
- if (matchingLinks.length > 0) {
1603
- filteredValues.push(value);
1604
- }
1605
- }
1606
- else {
1607
- // Can't parse condition, include by default
1608
- filteredValues.push(value);
1609
- }
1610
- }
1611
- values = filteredValues;
1612
- }
1613
- catch (error) {
1614
- console.warn(`Failed to apply condition filter for ${relationName}:`, error);
1615
- }
1616
- }
1617
- // Apply instance filter if present - batch-check all values at once
1618
- if (relMeta.instanceFilter) {
1619
- try {
1620
- const filterMetadata = await this.getSubjectClassMetadataFromSDNA(relMeta.instanceFilter);
1621
- if (!filterMetadata) {
1622
- // Fallback to sequential checks if metadata isn't available
1623
- return this.filterInstancesSequential(values, relMeta.instanceFilter);
1624
- }
1625
- return await this.batchCheckSubjectInstances(values, filterMetadata);
1626
- }
1627
- catch (err) {
1628
- // Fallback to sequential checks on error
1629
- return this.filterInstancesSequential(values, relMeta.instanceFilter);
1630
- }
1631
- }
1632
- return values;
1633
- }
1634
- /**
1635
- * Batch-checks multiple expressions against subject class metadata using a single or limited SPARQL queries.
1636
- * This avoids N+1 query problems by checking all values at once.
1637
- */
1638
- async batchCheckSubjectInstances(expressions, metadata) {
1639
- if (expressions.length === 0) {
1640
- return [];
1641
- }
1642
- // If no required triples, check which expressions have any links
1643
- if (metadata.requiredTriples.length === 0) {
1644
- const results = [];
1645
- for (const expr of expressions) {
1646
- const links = await this.get(new LinkQuery({ source: expr }));
1647
- if (links.length > 0)
1648
- results.push(expr);
1649
- }
1650
- return results;
1651
- }
1652
- // For each required triple, find which expressions match
1653
- const validExpressionSets = [];
1654
- for (const triple of metadata.requiredTriples) {
1655
- const matchingExprs = new Set();
1656
- for (const expr of expressions) {
1657
- let query;
1658
- if (triple.target) {
1659
- query = new LinkQuery({ source: expr, predicate: triple.predicate, target: triple.target });
1660
- }
1661
- else {
1662
- query = new LinkQuery({ source: expr, predicate: triple.predicate });
1663
- }
1664
- const links = await this.get(query);
1665
- if (links.length > 0)
1666
- matchingExprs.add(expr);
1667
- }
1668
- validExpressionSets.push(matchingExprs);
1669
- }
1670
- // Find intersection: expressions that passed ALL required triple checks
1671
- if (validExpressionSets.length === 0) {
1672
- return expressions;
1673
- }
1674
- const firstSet = validExpressionSets[0];
1675
- const validExpressions = expressions.filter(expr => {
1676
- return validExpressionSets.every(set => set.has(expr));
1677
- });
1678
- return validExpressions;
1679
- }
1680
- /**
1681
- * Fallback sequential instance checking when batch checking isn't available.
1682
- */
1683
- async filterInstancesSequential(values, instanceFilter) {
1684
- const filteredValues = [];
1685
- for (const value of values) {
1686
- try {
1687
- const isInstance = await this.isSubjectInstance(value, instanceFilter);
1688
- if (isInstance) {
1689
- filteredValues.push(value);
1690
- }
1691
- }
1692
- catch (err) {
1693
- // Skip values that fail instance check
1694
- continue;
1695
- }
1696
- }
1697
- return filteredValues;
1520
+ return results.map((row) => ({ base: row.base }));
1698
1521
  }
1699
1522
  /** Returns all subject instances of the given subject class as proxy objects.
1700
1523
  * @param subjectClass Either a string with the name of the subject class, or an object
@@ -1719,7 +1542,7 @@ export class PerspectiveProxy {
1719
1542
  for (let className of classes) {
1720
1543
  //console.log(`getAllSubjectInstances: Processing class ${className}`);
1721
1544
  // Query SDNA for metadata, then query SPARQL for instances
1722
- const metadata = await this.getSubjectClassMetadataFromSDNA(className);
1545
+ const metadata = await this.getSubjectClassMetadata(className);
1723
1546
  //console.log(`getAllSubjectInstances: Got metadata for ${className}:`, metadata);
1724
1547
  if (metadata) {
1725
1548
  const results = await this.findInstancesByMetadata(metadata);
@@ -1736,9 +1559,9 @@ export class PerspectiveProxy {
1736
1559
  await instance.get();
1737
1560
  }
1738
1561
  else {
1739
- // Legacy: Create a Subject proxy
1740
- instance = new Subject(this, result.base, className);
1741
- await instance.init();
1562
+ // Return plain data for string-based lookups
1563
+ const data = await this.getSubjectData(className, result.base);
1564
+ instance = { id: result.base, ...data };
1742
1565
  }
1743
1566
  instances.push(instance);
1744
1567
  //console.log(`getAllSubjectInstances: Successfully created subject for ${result.base}`);
@@ -1755,39 +1578,6 @@ export class PerspectiveProxy {
1755
1578
  //console.log(`getAllSubjectInstances: Returning ${instances.length} instances`);
1756
1579
  return instances;
1757
1580
  }
1758
- /** Returns all subject proxies of the given subject class as proxy objects.
1759
- * @param subjectClass Either a string with the name of the subject class, or an object
1760
- * with the properties of the subject class. In the latter case, all subject classes
1761
- * that match the given properties will be used.
1762
- */
1763
- async getAllSubjectProxies(subjectClass) {
1764
- let classes = [];
1765
- if (typeof subjectClass === "string") {
1766
- classes = [subjectClass];
1767
- }
1768
- else {
1769
- classes = await this.subjectClassesByTemplate(subjectClass);
1770
- }
1771
- let instances = [];
1772
- for (let className of classes) {
1773
- // Query SDNA for metadata, then query SPARQL for instances
1774
- const metadata = await this.getSubjectClassMetadataFromSDNA(className);
1775
- if (metadata) {
1776
- const results = await this.findInstancesByMetadata(metadata);
1777
- for (const result of results || []) {
1778
- try {
1779
- let subject = new Subject(this, result.base, className);
1780
- await subject.init();
1781
- instances.push(subject);
1782
- }
1783
- catch (e) {
1784
- // Skip subjects that fail to initialize
1785
- }
1786
- }
1787
- }
1788
- }
1789
- return instances;
1790
- }
1791
1581
  /**
1792
1582
  * Find a subject class by matching an object's properties/relations against SHACL shapes.
1793
1583
  * Queries SHACL links client-side to find a class whose properties contain all required ones.
@@ -1818,23 +1608,24 @@ export class PerspectiveProxy {
1818
1608
  if (properties.length === 0 && relations.length === 0) {
1819
1609
  return null;
1820
1610
  }
1821
- // Query links for class shapes using queryLinks
1822
- const typeLinks = await this.get(new LinkQuery({ predicate: 'rdf://type', target: 'ad4m://SubjectClass' }));
1823
- const propLinks = await this.get(new LinkQuery({ predicate: 'sh://property' }));
1824
- const collLinks = await this.get(new LinkQuery({ predicate: 'sh://collection' }));
1825
- const results = [
1826
- ...typeLinks.map(l => ({ shape_source: l.data.source, predicate: l.data.predicate, target: l.data.target })),
1827
- ...propLinks.map(l => ({ shape_source: l.data.source, predicate: l.data.predicate, target: l.data.target })),
1828
- ...collLinks.map(l => ({ shape_source: l.data.source, predicate: l.data.predicate, target: l.data.target })),
1829
- ];
1830
- if (results.length === 0)
1611
+ // Single SPARQL query to get all class shapes with their properties and collections
1612
+ const results = await this.querySparql(`
1613
+ SELECT ?shape ?predicate ?target WHERE {
1614
+ { ?shape <rdf://type> <ad4m://SubjectClass> . BIND(<rdf://type> AS ?predicate) BIND(<ad4m://SubjectClass> AS ?target) }
1615
+ UNION
1616
+ { ?shape <sh://property> ?target . BIND(<sh://property> AS ?predicate) }
1617
+ UNION
1618
+ { ?shape <sh://collection> ?target . BIND(<sh://collection> AS ?predicate) }
1619
+ }
1620
+ `);
1621
+ if (!Array.isArray(results) || results.length === 0)
1831
1622
  return null;
1832
1623
  // Build a map of className -> { properties, relations }
1833
1624
  const classShapes = new Map();
1834
1625
  // First pass: find all subject classes
1835
1626
  for (const r of results) {
1836
1627
  if (r.predicate === 'rdf://type' && r.target === 'ad4m://SubjectClass') {
1837
- const source = r.shape_source;
1628
+ const source = r.shape;
1838
1629
  const sepIdx = source.indexOf('://');
1839
1630
  if (sepIdx < 0)
1840
1631
  continue;
@@ -1849,7 +1640,7 @@ export class PerspectiveProxy {
1849
1640
  if (r.predicate === 'sh://property' || r.predicate === 'sh://collection') {
1850
1641
  // Match shape source to class (e.g., "recipe://RecipeShape" -> "Recipe")
1851
1642
  for (const [className, shape] of classShapes) {
1852
- if (r.shape_source.endsWith(`${className}Shape`)) {
1643
+ if (r.shape.endsWith(`${className}Shape`)) {
1853
1644
  const dotIdx = r.target.lastIndexOf('.');
1854
1645
  if (dotIdx < 0)
1855
1646
  continue;
@@ -1955,6 +1746,178 @@ export class PerspectiveProxy {
1955
1746
  clearEnsuredSubjectClasses() {
1956
1747
  __classPrivateFieldGet(this, _PerspectiveProxy_ensuredSubjectClasses, "f").clear();
1957
1748
  }
1749
+ /**
1750
+ * Returns a list of all class names that have been registered as SHACL
1751
+ * subject classes in this perspective (via `ensureSDNASubjectClass` or `addSdna`).
1752
+ *
1753
+ * @returns Array of class name strings (e.g. `["Channel", "Message", "Task"]`)
1754
+ */
1755
+ async listRegisteredClasses() {
1756
+ const results = await this.querySparql(`SELECT DISTINCT ?class WHERE { ?class <rdf://type> <ad4m://SubjectClass> . }`);
1757
+ if (!Array.isArray(results))
1758
+ return [];
1759
+ return results.map((row) => {
1760
+ const uri = row.class || '';
1761
+ // Extract class name from URI like "recipe://Recipe" or "flux://Channel"
1762
+ const hashIdx = uri.lastIndexOf('#');
1763
+ if (hashIdx >= 0)
1764
+ return uri.substring(hashIdx + 1);
1765
+ const slashIdx = uri.lastIndexOf('/');
1766
+ if (slashIdx >= 0)
1767
+ return uri.substring(slashIdx + 1);
1768
+ return uri;
1769
+ }).filter(Boolean);
1770
+ }
1771
+ /**
1772
+ * Returns the SHACL shape metadata for a registered class, including
1773
+ * property names, predicates, datatypes, and cardinality constraints.
1774
+ *
1775
+ * @param className - The name of the registered class
1776
+ * @returns Shape metadata or `null` if the class is not registered
1777
+ */
1778
+ async getClassShape(className) {
1779
+ // Find the shape URI for this class
1780
+ const safeName = className.replace(/['"\\]/g, '');
1781
+ const shapeResults = await this.querySparql(`SELECT ?shapeUri ?targetClass WHERE {
1782
+ ?targetClass <rdf://type> <ad4m://SubjectClass> .
1783
+ ?targetClass <ad4m://shape> ?shapeUri .
1784
+ FILTER(STRENDS(STR(?targetClass), "/${safeName}") || STRENDS(STR(?targetClass), "#${safeName}"))
1785
+ } LIMIT 1`);
1786
+ if (!Array.isArray(shapeResults) || shapeResults.length === 0)
1787
+ return null;
1788
+ const shapeUri = shapeResults[0].shapeUri;
1789
+ const classUri = shapeResults[0].targetClass;
1790
+ // Query all properties for this shape, including sh:in
1791
+ const propResults = await this.querySparql(`SELECT ?propShape ?path ?datatype ?minCount ?maxCount ?writable ?propType ?shIn WHERE {
1792
+ <${shapeUri}> <sh://property> ?propShape .
1793
+ ?propShape <sh://path> ?path .
1794
+ ?propShape <rdf://type> ?propType .
1795
+ OPTIONAL { ?propShape <sh://datatype> ?datatype }
1796
+ OPTIONAL { ?propShape <sh://minCount> ?minCount }
1797
+ OPTIONAL { ?propShape <sh://maxCount> ?maxCount }
1798
+ OPTIONAL { ?propShape <ad4m://writable> ?writable }
1799
+ OPTIONAL { ?propShape <sh://in> ?shIn }
1800
+ }`);
1801
+ const properties = (Array.isArray(propResults) ? propResults : []).map((row) => {
1802
+ // Extract property name from shape URI like "recipe://Recipe.name"
1803
+ const propUri = row.propShape || '';
1804
+ const dotIdx = propUri.lastIndexOf('.');
1805
+ const name = dotIdx >= 0 ? propUri.substring(dotIdx + 1) : propUri;
1806
+ const minCount = parseInt(row.minCount || '0', 10);
1807
+ const isCollection = row.propType === 'ad4m://CollectionShape';
1808
+ const writable = row.writable === 'true' || row.writable === 'literal:true';
1809
+ // Parse sh:in values if present
1810
+ let options;
1811
+ if (row.shIn) {
1812
+ try {
1813
+ let raw = row.shIn;
1814
+ // Strip literal: prefix if present, and URI-decode for robustness
1815
+ if (raw.startsWith('literal:string:')) {
1816
+ raw = decodeURIComponent(raw.substring('literal:string:'.length));
1817
+ }
1818
+ options = JSON.parse(raw);
1819
+ }
1820
+ catch { /* ignore parse errors */ }
1821
+ }
1822
+ return {
1823
+ name,
1824
+ predicate: row.path || '',
1825
+ datatype: row.datatype || undefined,
1826
+ required: minCount > 0,
1827
+ collection: isCollection,
1828
+ writable,
1829
+ ...(options && options.length > 0 ? { options } : {}),
1830
+ };
1831
+ });
1832
+ return { className: safeName, shapeUri, properties };
1833
+ }
1834
+ /**
1835
+ * Detects which registered subject classes a given instance conforms to,
1836
+ * based on its stored triples matching the class shapes' required properties.
1837
+ *
1838
+ * @param baseExpression - The instance's base expression / subject URI
1839
+ * @returns Array of class names the instance matches
1840
+ */
1841
+ async getInstanceClasses(baseExpression) {
1842
+ const safeId = baseExpression.replace(/['"\\]/g, '');
1843
+ // Get all registered classes and their required conformance properties
1844
+ const results = await this.querySparql(`SELECT DISTINCT ?class WHERE {
1845
+ ?class <rdf://type> <ad4m://SubjectClass> .
1846
+ ?class <ad4m://shape> ?shape .
1847
+ ?shape <sh://property> ?propShape .
1848
+ ?propShape <sh://minCount> ?mc .
1849
+ FILTER(?mc >= 1)
1850
+ ?propShape <sh://path> ?path .
1851
+ <${safeId}> ?path ?_val .
1852
+ }`);
1853
+ if (!Array.isArray(results))
1854
+ return [];
1855
+ return results.map((row) => {
1856
+ const uri = row.class || '';
1857
+ const hashIdx = uri.lastIndexOf('#');
1858
+ if (hashIdx >= 0)
1859
+ return uri.substring(hashIdx + 1);
1860
+ const slashIdx = uri.lastIndexOf('/');
1861
+ if (slashIdx >= 0)
1862
+ return uri.substring(slashIdx + 1);
1863
+ return uri;
1864
+ }).filter(Boolean);
1865
+ }
1866
+ /**
1867
+ * Returns all named options (sh:in values) for a registered class, grouped by property.
1868
+ *
1869
+ * @param className - The name of the registered class
1870
+ * @returns Record mapping property name → array of { value, label } options
1871
+ */
1872
+ async getNamedOptions(className) {
1873
+ const shape = await this.getClassShape(className);
1874
+ if (!shape)
1875
+ return {};
1876
+ const result = {};
1877
+ for (const prop of shape.properties) {
1878
+ if (prop.options && prop.options.length > 0) {
1879
+ result[prop.name] = prop.options;
1880
+ }
1881
+ }
1882
+ return result;
1883
+ }
1884
+ /**
1885
+ * Adds a named option (sh:in value) to a property of a registered class.
1886
+ * This appends to the existing sh:in list stored on the property shape.
1887
+ *
1888
+ * @param className - The registered class name
1889
+ * @param propertyName - The property to add the option to
1890
+ * @param value - The RDF value for the option
1891
+ * @param label - Optional human-readable label
1892
+ */
1893
+ async addNamedOption(className, propertyName, value, label) {
1894
+ const shape = await this.getClassShape(className);
1895
+ if (!shape)
1896
+ throw new Error(`Class "${className}" not found`);
1897
+ const prop = shape.properties.find(p => p.name === propertyName);
1898
+ if (!prop)
1899
+ throw new Error(`Property "${propertyName}" not found on class "${className}"`);
1900
+ // Build the property shape URI
1901
+ const ns = extractNamespaceFromUri(shape.shapeUri);
1902
+ const propShapeId = `${ns}${className}.${propertyName}`;
1903
+ // Get existing options
1904
+ const existing = prop.options || [];
1905
+ // Don't add duplicates
1906
+ if (existing.some(o => o.value === value))
1907
+ return;
1908
+ const updated = [...existing, { value, ...(label ? { label } : {}) }];
1909
+ // Remove old sh:in link if exists by querying for it
1910
+ const oldLinks = await this.get(new LinkQuery({ source: propShapeId, predicate: "sh://in" }));
1911
+ for (const oldLink of oldLinks) {
1912
+ await this.remove(oldLink);
1913
+ }
1914
+ // Add new sh:in link
1915
+ await this.add(new Link({
1916
+ source: propShapeId,
1917
+ predicate: "sh://in",
1918
+ target: `literal:string:${JSON.stringify(updated)}`
1919
+ }));
1920
+ }
1958
1921
  getNeighbourhoodProxy() {
1959
1922
  return __classPrivateFieldGet(this, _PerspectiveProxy_client, "f").getNeighbourhoodProxy(__classPrivateFieldGet(this, _PerspectiveProxy_handle, "f").uuid);
1960
1923
  }