@coasys/ad4m 0.13.0-test-7 → 0.13.0-test-8

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 (264) hide show
  1. package/lib/index.cjs +1109 -828
  2. package/lib/index.js +1096 -828
  3. package/lib/src/Ad4mClient.d.ts +4 -1
  4. package/lib/src/Ad4mClient.js +2 -2
  5. package/lib/src/agent/AgentClient.js +17 -0
  6. package/lib/src/ai/AIClient.js +1 -1
  7. package/lib/src/apiClient.d.ts +5 -1
  8. package/lib/src/apiClient.js +14 -6
  9. package/lib/src/generated/rest/AIModelLoadingStatus.d.ts +7 -0
  10. package/lib/src/generated/rest/AIModelLoadingStatus.js +2 -0
  11. package/lib/src/generated/rest/AddAgentInfosRequest.d.ts +3 -0
  12. package/lib/src/generated/rest/AddAgentInfosRequest.js +2 -0
  13. package/lib/src/generated/rest/AddLinkExpressionRequest.d.ts +6 -0
  14. package/lib/src/generated/rest/AddLinkExpressionRequest.js +1 -0
  15. package/lib/src/generated/rest/AddLinkRequest.d.ts +6 -0
  16. package/lib/src/generated/rest/AddLinkRequest.js +1 -0
  17. package/lib/src/generated/rest/AddLinksBulkRequest.d.ts +6 -0
  18. package/lib/src/generated/rest/AddLinksBulkRequest.js +1 -0
  19. package/lib/src/generated/rest/AddSdnaRequest.d.ts +6 -0
  20. package/lib/src/generated/rest/AddSdnaRequest.js +2 -0
  21. package/lib/src/generated/rest/ApplyTemplateRequest.d.ts +4 -0
  22. package/lib/src/generated/rest/ApplyTemplateRequest.js +2 -0
  23. package/lib/src/generated/rest/AuthInfoInput.d.ts +10 -0
  24. package/lib/src/generated/rest/AuthInfoInput.js +1 -0
  25. package/lib/src/generated/rest/BroadcastRequest.d.ts +6 -0
  26. package/lib/src/generated/rest/BroadcastRequest.js +1 -0
  27. package/lib/src/generated/rest/CapabilityInput.d.ts +5 -0
  28. package/lib/src/generated/rest/CapabilityInput.js +1 -0
  29. package/lib/src/generated/rest/CommitBatchRequest.d.ts +3 -0
  30. package/lib/src/generated/rest/CommitBatchRequest.js +2 -0
  31. package/lib/src/generated/rest/ComputeLogEntry.d.ts +9 -0
  32. package/lib/src/generated/rest/ComputeLogEntry.js +2 -0
  33. package/lib/src/generated/rest/CreateExpressionRequest.d.ts +4 -0
  34. package/lib/src/generated/rest/CreateExpressionRequest.js +2 -0
  35. package/lib/src/generated/rest/CreatePerspectiveRequest.d.ts +3 -0
  36. package/lib/src/generated/rest/CreatePerspectiveRequest.js +2 -0
  37. package/lib/src/generated/rest/CreateSubjectRequest.d.ts +6 -0
  38. package/lib/src/generated/rest/CreateSubjectRequest.js +2 -0
  39. package/lib/src/generated/rest/CreateUserRequest.d.ts +4 -0
  40. package/lib/src/generated/rest/CreateUserRequest.js +2 -0
  41. package/lib/src/generated/rest/CreateUserResponse.d.ts +5 -0
  42. package/lib/src/generated/rest/CreateUserResponse.js +2 -0
  43. package/lib/src/generated/rest/DecoratedExpressionProof.d.ts +6 -0
  44. package/lib/src/generated/rest/DecoratedExpressionProof.js +2 -0
  45. package/lib/src/generated/rest/DecoratedLinkExpression.d.ts +10 -0
  46. package/lib/src/generated/rest/DecoratedLinkExpression.js +1 -0
  47. package/lib/src/generated/rest/DisposeQueryRequest.d.ts +3 -0
  48. package/lib/src/generated/rest/DisposeQueryRequest.js +2 -0
  49. package/lib/src/generated/rest/EmailTestRequest.d.ts +6 -0
  50. package/lib/src/generated/rest/EmailTestRequest.js +2 -0
  51. package/lib/src/generated/rest/EmbedRequest.d.ts +4 -0
  52. package/lib/src/generated/rest/EmbedRequest.js +2 -0
  53. package/lib/src/generated/rest/EntanglementProofInput.d.ts +6 -0
  54. package/lib/src/generated/rest/EntanglementProofInput.js +2 -0
  55. package/lib/src/generated/rest/EntanglementProofPreflightRequest.d.ts +4 -0
  56. package/lib/src/generated/rest/EntanglementProofPreflightRequest.js +2 -0
  57. package/lib/src/generated/rest/ExecuteCommandsRequest.d.ts +4 -0
  58. package/lib/src/generated/rest/ExecuteCommandsRequest.js +2 -0
  59. package/lib/src/generated/rest/ExportRequest.d.ts +5 -0
  60. package/lib/src/generated/rest/ExportRequest.js +2 -0
  61. package/lib/src/generated/rest/ExpressionManyRequest.d.ts +3 -0
  62. package/lib/src/generated/rest/ExpressionManyRequest.js +2 -0
  63. package/lib/src/generated/rest/ExpressionProof.d.ts +4 -0
  64. package/lib/src/generated/rest/ExpressionProof.js +2 -0
  65. package/lib/src/generated/rest/ExpressionProofInput.d.ts +6 -0
  66. package/lib/src/generated/rest/ExpressionProofInput.js +2 -0
  67. package/lib/src/generated/rest/FriendSendMessageRequest.d.ts +3 -0
  68. package/lib/src/generated/rest/FriendSendMessageRequest.js +2 -0
  69. package/lib/src/generated/rest/FriendsListRequest.d.ts +3 -0
  70. package/lib/src/generated/rest/FriendsListRequest.js +2 -0
  71. package/lib/src/generated/rest/GenerateAgentRequest.d.ts +3 -0
  72. package/lib/src/generated/rest/GenerateAgentRequest.js +2 -0
  73. package/lib/src/generated/rest/GenerateJwtRequest.d.ts +4 -0
  74. package/lib/src/generated/rest/GenerateJwtRequest.js +2 -0
  75. package/lib/src/generated/rest/GetSubjectDataRequest.d.ts +4 -0
  76. package/lib/src/generated/rest/GetSubjectDataRequest.js +2 -0
  77. package/lib/src/generated/rest/HostingInfoResponse.d.ts +5 -0
  78. package/lib/src/generated/rest/HostingInfoResponse.js +2 -0
  79. package/lib/src/generated/rest/HostingWalletResponse.d.ts +4 -0
  80. package/lib/src/generated/rest/HostingWalletResponse.js +2 -0
  81. package/lib/src/generated/rest/ImportAgentRequest.d.ts +6 -0
  82. package/lib/src/generated/rest/ImportAgentRequest.js +2 -0
  83. package/lib/src/generated/rest/ImportRequest.d.ts +4 -0
  84. package/lib/src/generated/rest/ImportRequest.js +2 -0
  85. package/lib/src/generated/rest/JoinNeighbourhoodRequest.d.ts +3 -0
  86. package/lib/src/generated/rest/JoinNeighbourhoodRequest.js +2 -0
  87. package/lib/src/generated/rest/KeepAliveQueryRequest.d.ts +3 -0
  88. package/lib/src/generated/rest/KeepAliveQueryRequest.js +2 -0
  89. package/lib/src/generated/rest/LanguageMetaInput.d.ts +6 -0
  90. package/lib/src/generated/rest/LanguageMetaInput.js +2 -0
  91. package/lib/src/generated/rest/Link.d.ts +5 -0
  92. package/lib/src/generated/rest/Link.js +2 -0
  93. package/lib/src/generated/rest/LinkExpression.d.ts +10 -0
  94. package/lib/src/generated/rest/LinkExpression.js +1 -0
  95. package/lib/src/generated/rest/LinkExpressionInput.d.ts +10 -0
  96. package/lib/src/generated/rest/LinkExpressionInput.js +1 -0
  97. package/lib/src/generated/rest/LinkInput.d.ts +5 -0
  98. package/lib/src/generated/rest/LinkInput.js +2 -0
  99. package/lib/src/generated/rest/LinkLanguageTemplatesRequest.d.ts +3 -0
  100. package/lib/src/generated/rest/LinkLanguageTemplatesRequest.js +2 -0
  101. package/lib/src/generated/rest/LinkMutationRequest.d.ts +12 -0
  102. package/lib/src/generated/rest/LinkMutationRequest.js +1 -0
  103. package/lib/src/generated/rest/LinkMutationResponse.d.ts +9 -0
  104. package/lib/src/generated/rest/LinkMutationResponse.js +1 -0
  105. package/lib/src/generated/rest/LinkMutations.d.ts +6 -0
  106. package/lib/src/generated/rest/LinkMutations.js +1 -0
  107. package/lib/src/generated/rest/LinkMutationsRequest.d.ts +5 -0
  108. package/lib/src/generated/rest/LinkMutationsRequest.js +1 -0
  109. package/lib/src/generated/rest/LinkStatus.d.ts +1 -0
  110. package/lib/src/generated/rest/LinkStatus.js +2 -0
  111. package/lib/src/generated/rest/LinkUpdateInput.d.ts +5 -0
  112. package/lib/src/generated/rest/LinkUpdateInput.js +1 -0
  113. package/lib/src/generated/rest/LockAgentRequest.d.ts +3 -0
  114. package/lib/src/generated/rest/LockAgentRequest.js +2 -0
  115. package/lib/src/generated/rest/LoginUserRequest.d.ts +5 -0
  116. package/lib/src/generated/rest/LoginUserRequest.js +2 -0
  117. package/lib/src/generated/rest/ModelType.d.ts +1 -0
  118. package/lib/src/generated/rest/ModelType.js +2 -0
  119. package/lib/src/generated/rest/NotificationGrantRequest.d.ts +3 -0
  120. package/lib/src/generated/rest/NotificationGrantRequest.js +2 -0
  121. package/lib/src/generated/rest/NotificationInput.d.ts +10 -0
  122. package/lib/src/generated/rest/NotificationInput.js +2 -0
  123. package/lib/src/generated/rest/OpenLinkRequest.d.ts +3 -0
  124. package/lib/src/generated/rest/OpenLinkRequest.js +2 -0
  125. package/lib/src/generated/rest/PermitCapabilityRequest.d.ts +3 -0
  126. package/lib/src/generated/rest/PermitCapabilityRequest.js +2 -0
  127. package/lib/src/generated/rest/PerspectiveInput.d.ts +4 -0
  128. package/lib/src/generated/rest/PerspectiveInput.js +1 -0
  129. package/lib/src/generated/rest/PromptRequest.d.ts +4 -0
  130. package/lib/src/generated/rest/PromptRequest.js +2 -0
  131. package/lib/src/generated/rest/PublicPerspectiveInput.d.ts +4 -0
  132. package/lib/src/generated/rest/PublicPerspectiveInput.js +1 -0
  133. package/lib/src/generated/rest/PublishLanguageRequest.d.ts +5 -0
  134. package/lib/src/generated/rest/PublishLanguageRequest.js +1 -0
  135. package/lib/src/generated/rest/PublishNeighbourhoodRequest.d.ts +6 -0
  136. package/lib/src/generated/rest/PublishNeighbourhoodRequest.js +1 -0
  137. package/lib/src/generated/rest/QueryRequest.d.ts +7 -0
  138. package/lib/src/generated/rest/QueryRequest.js +2 -0
  139. package/lib/src/generated/rest/RemoveLinkRequest.d.ts +5 -0
  140. package/lib/src/generated/rest/RemoveLinkRequest.js +1 -0
  141. package/lib/src/generated/rest/RemoveLinksBulkRequest.d.ts +5 -0
  142. package/lib/src/generated/rest/RemoveLinksBulkRequest.js +1 -0
  143. package/lib/src/generated/rest/RequestCapabilityRequest.d.ts +4 -0
  144. package/lib/src/generated/rest/RequestCapabilityRequest.js +1 -0
  145. package/lib/src/generated/rest/RequestPaymentRequest.d.ts +3 -0
  146. package/lib/src/generated/rest/RequestPaymentRequest.js +2 -0
  147. package/lib/src/generated/rest/RequestVerificationRequest.d.ts +4 -0
  148. package/lib/src/generated/rest/RequestVerificationRequest.js +2 -0
  149. package/lib/src/generated/rest/ResourceInput.d.ts +4 -0
  150. package/lib/src/generated/rest/ResourceInput.js +2 -0
  151. package/lib/src/generated/rest/SetDefaultModelRequest.d.ts +4 -0
  152. package/lib/src/generated/rest/SetDefaultModelRequest.js +1 -0
  153. package/lib/src/generated/rest/SetFreeHostingEnabledRequest.d.ts +3 -0
  154. package/lib/src/generated/rest/SetFreeHostingEnabledRequest.js +2 -0
  155. package/lib/src/generated/rest/SetHotWalletAddressRequest.d.ts +3 -0
  156. package/lib/src/generated/rest/SetHotWalletAddressRequest.js +2 -0
  157. package/lib/src/generated/rest/SetMultiUserRequest.d.ts +3 -0
  158. package/lib/src/generated/rest/SetMultiUserRequest.js +2 -0
  159. package/lib/src/generated/rest/SetOnlineStatusRequest.d.ts +5 -0
  160. package/lib/src/generated/rest/SetOnlineStatusRequest.js +1 -0
  161. package/lib/src/generated/rest/SetStatusRequest.d.ts +3 -0
  162. package/lib/src/generated/rest/SetStatusRequest.js +2 -0
  163. package/lib/src/generated/rest/SetUserFreeAccessRequest.d.ts +4 -0
  164. package/lib/src/generated/rest/SetUserFreeAccessRequest.js +2 -0
  165. package/lib/src/generated/rest/SignMessageRequest.d.ts +3 -0
  166. package/lib/src/generated/rest/SignMessageRequest.js +2 -0
  167. package/lib/src/generated/rest/SignalRequest.d.ts +6 -0
  168. package/lib/src/generated/rest/SignalRequest.js +1 -0
  169. package/lib/src/generated/rest/SubscribeQueryRequest.d.ts +3 -0
  170. package/lib/src/generated/rest/SubscribeQueryRequest.js +2 -0
  171. package/lib/src/generated/rest/SubscribeQueryResponse.d.ts +4 -0
  172. package/lib/src/generated/rest/SubscribeQueryResponse.js +2 -0
  173. package/lib/src/generated/rest/TrustedAgentsRequest.d.ts +3 -0
  174. package/lib/src/generated/rest/TrustedAgentsRequest.js +2 -0
  175. package/lib/src/generated/rest/UnlockAgentRequest.d.ts +4 -0
  176. package/lib/src/generated/rest/UnlockAgentRequest.js +2 -0
  177. package/lib/src/generated/rest/UpdateLinkRequest.d.ts +7 -0
  178. package/lib/src/generated/rest/UpdateLinkRequest.js +1 -0
  179. package/lib/src/generated/rest/UpdatePerspectiveRequest.d.ts +3 -0
  180. package/lib/src/generated/rest/UpdatePerspectiveRequest.js +2 -0
  181. package/lib/src/generated/rest/UpdateProfileRequest.d.ts +5 -0
  182. package/lib/src/generated/rest/UpdateProfileRequest.js +1 -0
  183. package/lib/src/generated/rest/UserStatistics.d.ts +9 -0
  184. package/lib/src/generated/rest/UserStatistics.js +2 -0
  185. package/lib/src/generated/rest/VerificationRequestResult.d.ts +6 -0
  186. package/lib/src/generated/rest/VerificationRequestResult.js +2 -0
  187. package/lib/src/generated/rest/VerifyEmailRequest.d.ts +6 -0
  188. package/lib/src/generated/rest/VerifyEmailRequest.js +2 -0
  189. package/lib/src/generated/rest/VerifySignatureRequest.d.ts +5 -0
  190. package/lib/src/generated/rest/VerifySignatureRequest.js +2 -0
  191. package/lib/src/generated/rest/WriteSettingsRequest.d.ts +3 -0
  192. package/lib/src/generated/rest/WriteSettingsRequest.js +2 -0
  193. package/lib/src/generated/rest/index.d.ts +73 -0
  194. package/lib/src/generated/rest/index.js +8 -0
  195. package/lib/src/generated/rest/routes.d.ts +587 -0
  196. package/lib/src/generated/rest/routes.js +3 -0
  197. package/lib/src/index.d.ts +4 -0
  198. package/lib/src/index.js +4 -0
  199. package/lib/src/model/Ad4mModel.d.ts +30 -36
  200. package/lib/src/model/Ad4mModel.js +93 -382
  201. package/lib/src/model/Ad4mModel.test.js +735 -480
  202. package/lib/src/model/ModelQueryBuilder.d.ts +5 -10
  203. package/lib/src/model/ModelQueryBuilder.js +142 -62
  204. package/lib/src/model/decorators.d.ts +7 -4
  205. package/lib/src/model/decorators.js +0 -7
  206. package/lib/src/model/query-sparql.d.ts +0 -10
  207. package/lib/src/model/query-sparql.js +10 -15
  208. package/lib/src/model/query-sparql.test.js +10 -92
  209. package/lib/src/model/query-surreal.d.ts +44 -0
  210. package/lib/src/model/query-surreal.js +249 -0
  211. package/lib/src/model/shacl-gen.js +120 -47
  212. package/lib/src/model/surreal-utils.d.ts +42 -0
  213. package/lib/src/model/surreal-utils.js +128 -0
  214. package/lib/src/model/types.d.ts +140 -4
  215. package/lib/src/neighbourhood/NeighbourhoodProxy.test.js +33 -33
  216. package/lib/src/perspectives/PerspectiveClient.d.ts +13 -4
  217. package/lib/src/perspectives/PerspectiveClient.js +22 -6
  218. package/lib/src/perspectives/PerspectiveProxy.d.ts +27 -7
  219. package/lib/src/perspectives/PerspectiveProxy.js +60 -12
  220. package/lib/src/perspectives/PerspectiveProxy.test.d.ts +1 -0
  221. package/lib/src/perspectives/PerspectiveProxy.test.js +34 -0
  222. package/lib/src/perspectives/SparqlBindings.d.ts +47 -0
  223. package/lib/src/perspectives/SparqlBindings.js +65 -0
  224. package/lib/src/perspectives/WakerSubscriptionManager.js +5 -4
  225. package/lib/src/restClient.d.ts +52 -0
  226. package/lib/src/restClient.js +227 -0
  227. package/lib/src/shacl/NodeExpression.d.ts +44 -0
  228. package/lib/src/shacl/NodeExpression.js +39 -0
  229. package/lib/src/shacl/SHACLShape.d.ts +23 -0
  230. package/lib/src/shacl/SHACLShape.js +115 -1
  231. package/lib/src/shacl/SHACLShape.test.js +0 -82
  232. package/lib/src/shacl/builders.d.ts +58 -0
  233. package/lib/src/shacl/builders.js +76 -0
  234. package/lib/src/shacl/index.d.ts +36 -0
  235. package/lib/src/shacl/index.js +33 -0
  236. package/package.json +11 -8
  237. package/src/Ad4mClient.ts +7 -2
  238. package/src/agent/AgentClient.ts +23 -0
  239. package/src/ai/AIClient.ts +1 -1
  240. package/src/apiClient.ts +17 -6
  241. package/src/index.ts +4 -0
  242. package/src/model/Ad4mModel.test.ts +274 -72
  243. package/src/model/Ad4mModel.ts +140 -420
  244. package/src/model/ModelQueryBuilder.ts +136 -71
  245. package/src/model/decorators.ts +7 -13
  246. package/src/model/query-sparql.test.ts +35 -19
  247. package/src/model/query-sparql.ts +10 -16
  248. package/src/model/relation-filtering.test.ts +46 -39
  249. package/src/model/shacl-gen.ts +128 -54
  250. package/src/model/shacl-roundtrip.test.ts +197 -0
  251. package/src/model/types-typed-query.test.ts +360 -0
  252. package/src/model/types.ts +196 -4
  253. package/src/perspectives/PerspectiveClient.ts +24 -8
  254. package/src/perspectives/PerspectiveProxy.test.ts +85 -1
  255. package/src/perspectives/PerspectiveProxy.ts +65 -20
  256. package/src/perspectives/SparqlBindings.ts +79 -0
  257. package/src/perspectives/WakerSubscriptionManager.ts +5 -4
  258. package/src/shacl/NodeExpression.ts +54 -0
  259. package/src/shacl/SHACLShape.test.ts +172 -0
  260. package/src/shacl/SHACLShape.ts +173 -1
  261. package/src/shacl/builders.ts +86 -0
  262. package/src/shacl/index.ts +72 -0
  263. package/lib/src/model/model-manifest.d.ts +0 -41
  264. package/lib/src/model/model-manifest.js +0 -11
@@ -6,6 +6,7 @@
6
6
  * creating circular runtime dependencies on `Ad4mModel.ts`.
7
7
  */
8
8
  import type { Ad4mModel } from "./Ad4mModel";
9
+ import type { NodeExpression } from "../shacl/NodeExpression";
9
10
  export type WhereOps = {
10
11
  not: string | number | boolean | string[] | number[];
11
12
  between: [number, number];
@@ -89,11 +90,12 @@ export interface IncludeProjection {
89
90
  /** When true, attaches an integer count instead of a list. */
90
91
  count?: true;
91
92
  /**
92
- * Serialised target class shape. Set automatically by `executeModelQuery`
93
- * when a `where` clause is present and the target class is resolvable.
93
+ * Bare class name of the projection target. Set automatically by
94
+ * `prepareModelQueryParams`; the executor resolves the target's shape
95
+ * through its in-memory cache when applying projection where filters.
94
96
  * @internal
95
97
  */
96
- targetShape?: ModelMetadata;
98
+ targetClassName?: string;
97
99
  /** Post-hydration where clause applied to the target instances. */
98
100
  where?: Where;
99
101
  /** Limit results (when 1, the attached value is unwrapped to a scalar). */
@@ -142,6 +144,139 @@ export type Query = {
142
144
  * ```
143
145
  */
144
146
  export type RelationSubQuery = Omit<Query, 'parent' | 'count'>;
147
+ /** Keys of T that are user-declared (not methods, not inherited from Ad4mModel). */
148
+ export type ModelDataKeys<T extends Ad4mModel> = {
149
+ [K in keyof T]: K extends keyof Ad4mModel ? never : T[K] extends (...args: any[]) => any ? never : K;
150
+ }[keyof T];
151
+ /** Keys of T that can appear in a `where` clause — scalars and scalar arrays.
152
+ * Excludes typed Ad4mModel references (single or array); `string[]`/`number[]`
153
+ * remain included because they're often filterable even when also used as
154
+ * link targets.
155
+ *
156
+ * Iterates over `keyof T` directly (not `ModelDataKeys<T>`) to preserve the
157
+ * key constraint — mapped types over computed type aliases sometimes widen
158
+ * to `string | undefined` in the key position, which then breaks indexing. */
159
+ export type PropertyKeysOf<T extends Ad4mModel> = {
160
+ [K in keyof T]: K extends ModelDataKeys<T> ? NonNullable<T[K]> extends Ad4mModel ? never : NonNullable<T[K]> extends Ad4mModel[] ? never : K : never;
161
+ }[keyof T];
162
+ /** Keys of T that can appear in `include` — typed Ad4mModel references AND
163
+ * `string[]` link-target arrays (the `@HasMany` + `string[]` pattern that
164
+ * AD4M uses for relations without a target class thunk). Handles both
165
+ * `?: Foo` (optional → `Foo | undefined`) and `Foo | null` field shapes, and
166
+ * optional/nullable array variants (`?: Foo[]`, `Foo[] | null`). */
167
+ export type RelationKeysOf<T extends Ad4mModel> = {
168
+ [K in keyof T]: K extends ModelDataKeys<T> ? NonNullable<T[K]> extends Ad4mModel ? K : NonNullable<T[K]> extends Ad4mModel[] ? K : NonNullable<T[K]> extends string[] ? K : never : never;
169
+ }[keyof T];
170
+ /** The model type referenced by a relation field K on T.
171
+ * Falls back to `Ad4mModel` (loose) for the `string[]` relation pattern,
172
+ * since no target class is available at the type level. */
173
+ export type RelatedModel<T extends Ad4mModel, K extends RelationKeysOf<T>> = NonNullable<T[K]> extends (infer U)[] ? (U extends Ad4mModel ? U : Ad4mModel) : NonNullable<T[K]> extends Ad4mModel ? NonNullable<T[K]> : Ad4mModel;
174
+ /** True when T has no statically-declared data fields (e.g. fromSHACL classes). */
175
+ type HasNoTypedFields<T extends Ad4mModel> = [
176
+ PropertyKeysOf<T> | RelationKeysOf<T>
177
+ ] extends [never] ? true : false;
178
+ export type StringWhereOps = {
179
+ not?: string | string[];
180
+ contains?: string;
181
+ };
182
+ export type NumericWhereOps = {
183
+ not?: number | number[];
184
+ lt?: number;
185
+ lte?: number;
186
+ gt?: number;
187
+ gte?: number;
188
+ between?: [number, number];
189
+ };
190
+ export type TypedWhereCondition<V> = V extends string ? string | string[] | StringWhereOps : V extends number ? number | number[] | NumericWhereOps : V extends boolean ? boolean : V extends Array<infer U> ? U extends string ? string | string[] | StringWhereOps : U extends number ? number | number[] | NumericWhereOps : WhereCondition : WhereCondition;
191
+ /** Strict Where: keys constrained to T's properties, plus the well-known
192
+ * link-metadata fields (`id`/`author`/`timestamp`). */
193
+ type StrictTypedWhere<T extends Ad4mModel> = {
194
+ [K in PropertyKeysOf<T>]?: TypedWhereCondition<T[K]>;
195
+ } & {
196
+ base?: string | string[];
197
+ id?: string | string[];
198
+ author?: WhereCondition;
199
+ timestamp?: WhereCondition;
200
+ };
201
+ /** Public typed `where` for a model class. Falls back to the loose `Where`
202
+ * shape when T has no declared fields (e.g. fromSHACL-derived classes). */
203
+ export type TypedWhere<T extends Ad4mModel> = HasNoTypedFields<T> extends true ? Where : StrictTypedWhere<T>;
204
+ type StrictTypedOrder<T extends Ad4mModel> = {
205
+ [K in PropertyKeysOf<T> | 'timestamp' | 'author' | 'createdAt' | 'updatedAt']?: 'ASC' | 'DESC';
206
+ };
207
+ export type TypedOrder<T extends Ad4mModel> = HasNoTypedFields<T> extends true ? Order : StrictTypedOrder<T>;
208
+ /** Sub-query for an eager-loaded relation — inherits the target model's constraints. */
209
+ export type TypedRelationSubQuery<U extends Ad4mModel> = {
210
+ where?: TypedWhere<U>;
211
+ order?: TypedOrder<U>;
212
+ include?: TypedIncludeMap<U>;
213
+ limit?: number;
214
+ offset?: number;
215
+ };
216
+ /** Projection — `from` must be a real relation on T; `where`/`order` constrained to that target.
217
+ * Modelled as a discriminated union so the literal `count: true` and `limit: 1`
218
+ * variants narrow inference into `IncludeExtras` (count → number, limit-1 → scalar). */
219
+ export type TypedIncludeProjection<T extends Ad4mModel> = {
220
+ [K in RelationKeysOf<T>]: {
221
+ from: K;
222
+ count: true;
223
+ } | {
224
+ from: K;
225
+ limit: 1;
226
+ where?: TypedWhere<RelatedModel<T, K>>;
227
+ order?: TypedOrder<RelatedModel<T, K>>;
228
+ } | {
229
+ from: K;
230
+ limit?: number;
231
+ where?: TypedWhere<RelatedModel<T, K>>;
232
+ order?: TypedOrder<RelatedModel<T, K>>;
233
+ };
234
+ }[RelationKeysOf<T>];
235
+ type StrictTypedIncludeMap<T extends Ad4mModel> = {
236
+ [K in RelationKeysOf<T>]?: boolean | TypedRelationSubQuery<RelatedModel<T, K>>;
237
+ } & {
238
+ [K in `$${string}`]?: TypedIncludeProjection<T>;
239
+ };
240
+ export type TypedIncludeMap<T extends Ad4mModel> = HasNoTypedFields<T> extends true ? IncludeMap : StrictTypedIncludeMap<T>;
241
+ /**
242
+ * Given a model T and an `include` literal I, compute the extra fields
243
+ * contributed by `$`-prefixed projection keys.
244
+ *
245
+ * - `{ count: true }` → `number`
246
+ * - `{ from: R, limit: 1 }` → `RelatedModel<T,R> | null`
247
+ * - `{ from: R }` (no limit/1) → `RelatedModel<T,R>[]`
248
+ *
249
+ * Returns `unknown` (intersection-neutral) when `I` has no `$`-keys, so that
250
+ * `T & IncludeExtras<T, I>` collapses back to `T` and downstream type
251
+ * predicates (`(x): x is T => ...`) keep working unchanged.
252
+ */
253
+ export type IncludeExtras<T extends Ad4mModel, I> = I extends Record<string, any> ? Extract<keyof I, `$${string}`> extends never ? unknown : {
254
+ [K in Extract<keyof I, `$${string}`>]: I[K] extends {
255
+ count: true;
256
+ } ? number : I[K] extends {
257
+ from: infer R;
258
+ limit: 1;
259
+ } ? (R extends RelationKeysOf<T> ? RelatedModel<T, R> | null : never) : I[K] extends {
260
+ from: infer R;
261
+ } ? (R extends RelationKeysOf<T> ? RelatedModel<T, R>[] : never) : unknown;
262
+ } : unknown;
263
+ type StrictTypedQuery<T extends Ad4mModel> = {
264
+ parent?: ParentScope;
265
+ properties?: PropertyKeysOf<T>[];
266
+ include?: TypedIncludeMap<T>;
267
+ includeAll?: boolean;
268
+ where?: TypedWhere<T>;
269
+ order?: TypedOrder<T>;
270
+ offset?: number;
271
+ limit?: number;
272
+ count?: boolean;
273
+ deepQuery?: boolean;
274
+ };
275
+ export type TypedQuery<T extends Ad4mModel> = HasNoTypedFields<T> extends true ? Query : StrictTypedQuery<T>;
276
+ /** Helper that extracts the `include` literal from a TypedQuery for use with IncludeExtras. */
277
+ export type IncludeOf<Q> = Q extends {
278
+ include?: infer I;
279
+ } ? I : undefined;
145
280
  /**
146
281
  * Options accepted by the instance `get()` method.
147
282
  *
@@ -188,7 +323,7 @@ export interface PropertyMetadata {
188
323
  /** Whether stored locally only */
189
324
  local?: boolean;
190
325
  /** Transform function */
191
- transform?: (value: any) => any;
326
+ transform?: NodeExpression;
192
327
  /** Whether this is a flag property */
193
328
  flag?: boolean;
194
329
  }
@@ -227,3 +362,4 @@ export interface ModelMetadata {
227
362
  /** Map of relation name to metadata */
228
363
  relations: Record<string, RelationMetadata>;
229
364
  }
365
+ export {};
@@ -1,18 +1,21 @@
1
1
  import { NeighbourhoodClient } from "./NeighbourhoodClient";
2
2
  import { NeighbourhoodProxy } from "./NeighbourhoodProxy";
3
+ // Mock RestClient's subscribe to avoid real WebSocket connections
4
+ jest.mock('../restClient', () => {
5
+ return {
6
+ RestClient: jest.fn().mockImplementation(() => ({
7
+ get: jest.fn(),
8
+ post: jest.fn(),
9
+ put: jest.fn(),
10
+ delete: jest.fn(),
11
+ subscribe: jest.fn().mockReturnValue(() => { }),
12
+ }))
13
+ };
14
+ });
3
15
  describe("NeighbourhoodProxy", () => {
4
16
  it("should add multiple signal handlers", async () => {
5
17
  const neighbourhoodURI = "did://123";
6
- const mockApolloClient = {
7
- subscribe: () => ({
8
- subscribe: () => new Promise((resolve) => {
9
- setTimeout(() => {
10
- resolve({});
11
- }, 10);
12
- }),
13
- }),
14
- };
15
- const neighbourhoodClient = new NeighbourhoodClient(mockApolloClient);
18
+ const neighbourhoodClient = new NeighbourhoodClient("http://localhost:0", "test-token");
16
19
  const neighbourhoodProxy = new NeighbourhoodProxy(neighbourhoodClient, neighbourhoodURI);
17
20
  let callbacks = 0;
18
21
  const handler1 = () => {
@@ -21,7 +24,7 @@ describe("NeighbourhoodProxy", () => {
21
24
  const handler2 = () => {
22
25
  callbacks++;
23
26
  };
24
- // Add multiple signal handlers in paralell
27
+ // Add multiple signal handlers in parallel
25
28
  const promise = neighbourhoodProxy.addSignalHandler(handler1);
26
29
  neighbourhoodProxy.addSignalHandler(handler2);
27
30
  await promise;
@@ -30,21 +33,20 @@ describe("NeighbourhoodProxy", () => {
30
33
  });
31
34
  it("should not add multiple subscriptions when removing and adding another signal handler", async () => {
32
35
  const neighbourhoodURI = "did://123";
33
- const subscriptions = [];
34
- const subscribe = (args) => {
35
- subscriptions.push(args);
36
- new Promise((resolve) => {
37
- setTimeout(() => {
38
- resolve({});
39
- }, 10);
40
- });
41
- };
42
- const mockApolloClient = {
43
- subscribe: () => ({
44
- subscribe,
36
+ // Track subscribe calls via the mock
37
+ let subscribeCallCount = 0;
38
+ const { RestClient } = jest.requireMock('../restClient');
39
+ RestClient.mockImplementation(() => ({
40
+ get: jest.fn(),
41
+ post: jest.fn(),
42
+ put: jest.fn(),
43
+ delete: jest.fn(),
44
+ subscribe: jest.fn().mockImplementation(() => {
45
+ subscribeCallCount++;
46
+ return () => { };
45
47
  }),
46
- };
47
- const neighbourhoodClient = new NeighbourhoodClient(mockApolloClient);
48
+ }));
49
+ const neighbourhoodClient = new NeighbourhoodClient("http://localhost:0", "test-token");
48
50
  const neighbourhoodProxy = new NeighbourhoodProxy(neighbourhoodClient, neighbourhoodURI);
49
51
  let callbacks1 = 0;
50
52
  let callbacks2 = 0;
@@ -56,17 +58,15 @@ describe("NeighbourhoodProxy", () => {
56
58
  };
57
59
  // Add signal handler 1
58
60
  await neighbourhoodProxy.addSignalHandler(handler1);
59
- // Remove signal handler 2
61
+ // Remove signal handler 1
60
62
  neighbourhoodProxy.removeSignalHandler(handler1);
61
63
  // Add signal handler 2
62
64
  await neighbourhoodProxy.addSignalHandler(handler2);
63
- // Check that only one subscription was added
64
- expect(subscriptions.length).toBe(1);
65
- // mock trigger signal event
66
- for (const subscription of subscriptions) {
67
- subscription.next({ data: { signal: { neighbourhoodSignal: true } } });
68
- }
69
- // Check that only our second callback was called
65
+ // Check that only one subscription was added (handlers share subscription per perspective)
66
+ expect(subscribeCallCount).toBe(1);
67
+ // Dispatch signal
68
+ neighbourhoodClient.dispatchSignal(neighbourhoodURI, true);
69
+ // Check that only handler2 was called (handler1 was removed)
70
70
  expect(callbacks1).toBe(0);
71
71
  expect(callbacks2).toBe(1);
72
72
  });
@@ -27,7 +27,7 @@ export declare class PerspectiveClient {
27
27
  publishSnapshotByUUID(uuid: string): Promise<string | null>;
28
28
  queryLinks(uuid: string, query: LinkQuery): Promise<LinkExpression[]>;
29
29
  queryProlog(uuid: string, query: string): Promise<unknown>;
30
- querySparql(uuid: string, query: string): Promise<unknown>;
30
+ querySparql<T = any>(uuid: string, query: string): Promise<T>;
31
31
  subscribeQuery(uuid: string, query: string): Promise<{
32
32
  subscriptionId: string;
33
33
  result: AllInstancesResult;
@@ -37,9 +37,9 @@ export declare class PerspectiveClient {
37
37
  subscribeToQueryUpdates(subscriptionId: string, onData: (result: AllInstancesResult) => void): () => void;
38
38
  keepAliveQuery(uuid: string, subscriptionId: string): Promise<boolean>;
39
39
  disposeQuerySubscription(uuid: string, subscriptionId: string): Promise<boolean>;
40
- modelQuery(uuid: string, className: string, queryJson: string, shapeJson?: string): Promise<any>;
41
- evaluateGetters(uuid: string, className: string, instanceIds: string[], shapeJson: string, propertyNames?: string[]): Promise<Record<string, Record<string, any>>>;
42
- modelSubscribe(uuid: string, className: string, queryJson: string, shapeJson?: string): Promise<{
40
+ modelQuery(uuid: string, className: string, queryJson: string): Promise<any>;
41
+ evaluateGetters(uuid: string, className: string, instanceIds: string[], propertyNames?: string[]): Promise<Record<string, Record<string, any>>>;
42
+ modelSubscribe(uuid: string, className: string, queryJson: string): Promise<{
43
43
  subscriptionId: string;
44
44
  result: any;
45
45
  }>;
@@ -56,6 +56,12 @@ export declare class PerspectiveClient {
56
56
  updateLink(uuid: string, oldLink: LinkExpressionInput, newLink: Link, batchId?: string): Promise<LinkExpression>;
57
57
  removeLink(uuid: string, link: LinkExpressionInput, batchId?: string): Promise<boolean>;
58
58
  addSdna(uuid: string, name: string, sdnaCode: string | undefined, sdnaType: "subject_class" | "flow" | "custom", shaclJson?: string): Promise<boolean>;
59
+ addSdnaBatch(uuid: string, entries: {
60
+ name: string;
61
+ sdnaCode?: string;
62
+ sdnaType: "subject_class" | "flow" | "custom";
63
+ shaclJson?: string;
64
+ }[]): Promise<boolean[]>;
59
65
  executeCommands(uuid: string, commands: string, expression: string, parameters: string, batchId?: string): Promise<boolean>;
60
66
  createSubject(uuid: string, subjectClass: string, expressionAddress: string, initialValues?: string, batchId?: string): Promise<boolean>;
61
67
  getSubjectData(uuid: string, subjectClass: string, expressionAddress: string): Promise<string>;
@@ -72,6 +78,9 @@ export declare class PerspectiveClient {
72
78
  addPerspectiveLinkAddedListener(uuid: String, cb: LinkCallback[]): Promise<void>;
73
79
  addPerspectiveLinkRemovedListener(uuid: String, cb: LinkCallback[]): Promise<void>;
74
80
  addPerspectiveLinkUpdatedListener(uuid: String, cb: LinkCallback[]): Promise<void>;
81
+ /** Unsubscribe all link/sync-state listeners registered for the given perspective UUID.
82
+ * Called by PerspectiveProxy.dispose() to prevent subscription leaks. */
83
+ removeAllListeners(uuid: string): void;
75
84
  getNeighbourhoodProxy(uuid: string): NeighbourhoodProxy;
76
85
  createBatch(uuid: string): Promise<string>;
77
86
  commitBatch(uuid: string, batchId: string): Promise<LinkExpressionMutations>;
@@ -148,22 +148,21 @@ export class PerspectiveClient {
148
148
  }
149
149
  return __classPrivateFieldGet(this, _PerspectiveClient_apiClient, "f").call('perspective.disposeQuery', { uuid, subscriptionId });
150
150
  }
151
- async modelQuery(uuid, className, queryJson, shapeJson) {
152
- const resultJson = await __classPrivateFieldGet(this, _PerspectiveClient_apiClient, "f").call('perspective.modelQuery', { uuid, class_name: className, query_json: queryJson, shape_json: shapeJson });
151
+ async modelQuery(uuid, className, queryJson) {
152
+ const resultJson = await __classPrivateFieldGet(this, _PerspectiveClient_apiClient, "f").call('perspective.modelQuery', { uuid, class_name: className, query_json: queryJson });
153
153
  return JSON.parse(resultJson);
154
154
  }
155
- async evaluateGetters(uuid, className, instanceIds, shapeJson, propertyNames) {
155
+ async evaluateGetters(uuid, className, instanceIds, propertyNames) {
156
156
  const resultJson = await __classPrivateFieldGet(this, _PerspectiveClient_apiClient, "f").call('perspective.evaluateGetters', {
157
157
  uuid,
158
158
  class_name: className,
159
159
  instance_ids: instanceIds,
160
- shape_json: shapeJson,
161
160
  ...(propertyNames && { property_names: propertyNames }),
162
161
  });
163
162
  return JSON.parse(resultJson);
164
163
  }
165
- async modelSubscribe(uuid, className, queryJson, shapeJson) {
166
- const response = await __classPrivateFieldGet(this, _PerspectiveClient_apiClient, "f").call('perspective.modelSubscribe', { uuid, class_name: className, query_json: queryJson, shape_json: shapeJson });
164
+ async modelSubscribe(uuid, className, queryJson) {
165
+ const response = await __classPrivateFieldGet(this, _PerspectiveClient_apiClient, "f").call('perspective.modelSubscribe', { uuid, class_name: className, query_json: queryJson });
167
166
  return {
168
167
  subscriptionId: response.subscription_id,
169
168
  result: JSON.parse(response.result)
@@ -209,6 +208,9 @@ export class PerspectiveClient {
209
208
  async addSdna(uuid, name, sdnaCode, sdnaType, shaclJson) {
210
209
  return __classPrivateFieldGet(this, _PerspectiveClient_apiClient, "f").call('perspective.addSdna', { uuid, name, sdnaCode: sdnaCode || "", sdnaType, shaclJson });
211
210
  }
211
+ async addSdnaBatch(uuid, entries) {
212
+ return __classPrivateFieldGet(this, _PerspectiveClient_apiClient, "f").call('perspective.addSdna', { uuid, entries: entries.map(e => ({ ...e, sdnaCode: e.sdnaCode || "" })) });
213
+ }
212
214
  async executeCommands(uuid, commands, expression, parameters, batchId) {
213
215
  return __classPrivateFieldGet(this, _PerspectiveClient_apiClient, "f").call('perspective.executeCommands', { uuid, commands, expression, parameters, batchId });
214
216
  }
@@ -316,6 +318,20 @@ export class PerspectiveClient {
316
318
  __classPrivateFieldGet(this, _PerspectiveClient_linkUnsubscribers, "f").set(uuid, existing);
317
319
  await __classPrivateFieldGet(this, _PerspectiveClient_apiClient, "f").waitForSubscription();
318
320
  }
321
+ /** Unsubscribe all link/sync-state listeners registered for the given perspective UUID.
322
+ * Called by PerspectiveProxy.dispose() to prevent subscription leaks. */
323
+ removeAllListeners(uuid) {
324
+ const unsubs = __classPrivateFieldGet(this, _PerspectiveClient_linkUnsubscribers, "f").get(uuid);
325
+ if (unsubs) {
326
+ for (const fn of unsubs) {
327
+ try {
328
+ fn();
329
+ }
330
+ catch { }
331
+ }
332
+ __classPrivateFieldGet(this, _PerspectiveClient_linkUnsubscribers, "f").delete(uuid);
333
+ }
334
+ }
319
335
  getNeighbourhoodProxy(uuid) {
320
336
  return new NeighbourhoodProxy(__classPrivateFieldGet(this, _PerspectiveClient_neighbourhoodClient, "f"), uuid);
321
337
  }
@@ -318,16 +318,19 @@ export declare class PerspectiveProxy {
318
318
  * @param query - SPARQL query string
319
319
  * @returns Query results as parsed JSON
320
320
  */
321
- querySparql(query: string): Promise<any>;
321
+ querySparql<T = any>(query: string): Promise<T>;
322
322
  /**
323
323
  * Execute a model query — the executor-side replacement for SPARQL query building + JS hydration.
324
324
  *
325
+ * The executor resolves the model's shape from the perspective's SHACL
326
+ * triples (written by `addSdna`). Callers no longer ship shape
327
+ * metadata with the query; the perspective is the source of truth.
328
+ *
325
329
  * @param className - The model class name (e.g. "Recipe")
326
330
  * @param queryJson - Structured query as JSON string
327
- * @param shapeJson - Optional shape metadata JSON from the model class
328
331
  * @returns Object with `instances` array and `totalCount`
329
332
  */
330
- modelQuery(className: string, queryJson: string, shapeJson?: string): Promise<{
333
+ modelQuery(className: string, queryJson: string): Promise<{
331
334
  instances: any[];
332
335
  totalCount: number;
333
336
  }>;
@@ -340,11 +343,10 @@ export declare class PerspectiveProxy {
340
343
  *
341
344
  * @param className - The model class name (e.g. "Message")
342
345
  * @param instanceIds - Array of instance base expression URIs
343
- * @param shapeJson - Shape metadata JSON from the model class
344
346
  * @param propertyNames - Optional subset of property names to evaluate
345
347
  * @returns Map of instance ID → evaluated property values
346
348
  */
347
- evaluateGetters(className: string, instanceIds: string[], shapeJson: string, propertyNames?: string[]): Promise<Record<string, Record<string, any>>>;
349
+ evaluateGetters(className: string, instanceIds: string[], propertyNames?: string[]): Promise<Record<string, Record<string, any>>>;
348
350
  /**
349
351
  * Subscribe to model query changes. Builds trigger SPARQL from the model shape
350
352
  * internally in Rust, registers a subscription, runs the initial query, and
@@ -355,10 +357,9 @@ export declare class PerspectiveProxy {
355
357
  *
356
358
  * @param className - The model class name
357
359
  * @param queryJson - JSON-serialized query parameters (same as modelQuery)
358
- * @param shapeJson - Optional shape metadata JSON from the model class
359
360
  * @returns Object with `subscriptionId` and initial `result`
360
361
  */
361
- modelSubscribe(className: string, queryJson: string, shapeJson?: string): Promise<{
362
+ modelSubscribe(className: string, queryJson: string): Promise<{
362
363
  subscriptionId: string;
363
364
  result: any;
364
365
  }>;
@@ -498,6 +499,10 @@ export declare class PerspectiveProxy {
498
499
  * @param cb - The callback function to remove
499
500
  */
500
501
  removeListener(type: PerspectiveListenerTypes, cb: LinkCallback): Promise<void>;
502
+ /** Clean up all subscriptions registered by this proxy.
503
+ * Call this when the proxy is no longer needed to prevent subscription leaks.
504
+ * After calling dispose(), the proxy should not be used. */
505
+ dispose(): void;
501
506
  /**
502
507
  * Creates a snapshot of the current perspective state.
503
508
  * Useful for backup or sharing.
@@ -588,6 +593,21 @@ export declare class PerspectiveProxy {
588
593
  * await perspective.addSdna('Recipe', prologCode, 'subject_class');
589
594
  */
590
595
  addSdna(name: string, sdnaCode: string, sdnaType: "subject_class" | "flow" | "custom", shaclJson?: string): Promise<boolean>;
596
+ /**
597
+ * Batch variant of addSdna — registers multiple SDNA entries in a single RPC call.
598
+ * Acquires the Rust-side mutex once for the entire batch.
599
+ */
600
+ addSdnaAll(entries: {
601
+ name: string;
602
+ sdnaCode?: string;
603
+ sdnaType: "subject_class" | "flow" | "custom";
604
+ shaclJson?: string;
605
+ }[]): Promise<boolean[]>;
606
+ /**
607
+ * Batch-registers multiple model classes as SHACL subject classes in a single RPC call.
608
+ * Skips classes already registered on this perspective instance.
609
+ */
610
+ ensureSubjectClasses(jsClasses: any[]): Promise<void>;
591
611
  /**
592
612
  * Adds a subject class to the perspective.
593
613
  * Alias for addSdna() with sdnaType='subject_class'.
@@ -540,13 +540,16 @@ export class PerspectiveProxy {
540
540
  /**
541
541
  * Execute a model query — the executor-side replacement for SPARQL query building + JS hydration.
542
542
  *
543
+ * The executor resolves the model's shape from the perspective's SHACL
544
+ * triples (written by `addSdna`). Callers no longer ship shape
545
+ * metadata with the query; the perspective is the source of truth.
546
+ *
543
547
  * @param className - The model class name (e.g. "Recipe")
544
548
  * @param queryJson - Structured query as JSON string
545
- * @param shapeJson - Optional shape metadata JSON from the model class
546
549
  * @returns Object with `instances` array and `totalCount`
547
550
  */
548
- async modelQuery(className, queryJson, shapeJson) {
549
- return await __classPrivateFieldGet(this, _PerspectiveProxy_client, "f").modelQuery(__classPrivateFieldGet(this, _PerspectiveProxy_handle, "f").uuid, className, queryJson, shapeJson);
551
+ async modelQuery(className, queryJson) {
552
+ return await __classPrivateFieldGet(this, _PerspectiveProxy_client, "f").modelQuery(__classPrivateFieldGet(this, _PerspectiveProxy_handle, "f").uuid, className, queryJson);
550
553
  }
551
554
  /**
552
555
  * Evaluate property getters for a batch of instances in a single RPC call.
@@ -557,12 +560,11 @@ export class PerspectiveProxy {
557
560
  *
558
561
  * @param className - The model class name (e.g. "Message")
559
562
  * @param instanceIds - Array of instance base expression URIs
560
- * @param shapeJson - Shape metadata JSON from the model class
561
563
  * @param propertyNames - Optional subset of property names to evaluate
562
564
  * @returns Map of instance ID → evaluated property values
563
565
  */
564
- async evaluateGetters(className, instanceIds, shapeJson, propertyNames) {
565
- return await __classPrivateFieldGet(this, _PerspectiveProxy_client, "f").evaluateGetters(__classPrivateFieldGet(this, _PerspectiveProxy_handle, "f").uuid, className, instanceIds, shapeJson, propertyNames);
566
+ async evaluateGetters(className, instanceIds, propertyNames) {
567
+ return await __classPrivateFieldGet(this, _PerspectiveProxy_client, "f").evaluateGetters(__classPrivateFieldGet(this, _PerspectiveProxy_handle, "f").uuid, className, instanceIds, propertyNames);
566
568
  }
567
569
  /**
568
570
  * Subscribe to model query changes. Builds trigger SPARQL from the model shape
@@ -574,11 +576,10 @@ export class PerspectiveProxy {
574
576
  *
575
577
  * @param className - The model class name
576
578
  * @param queryJson - JSON-serialized query parameters (same as modelQuery)
577
- * @param shapeJson - Optional shape metadata JSON from the model class
578
579
  * @returns Object with `subscriptionId` and initial `result`
579
580
  */
580
- async modelSubscribe(className, queryJson, shapeJson) {
581
- return await __classPrivateFieldGet(this, _PerspectiveProxy_client, "f").modelSubscribe(__classPrivateFieldGet(this, _PerspectiveProxy_handle, "f").uuid, className, queryJson, shapeJson);
581
+ async modelSubscribe(className, queryJson) {
582
+ return await __classPrivateFieldGet(this, _PerspectiveProxy_client, "f").modelSubscribe(__classPrivateFieldGet(this, _PerspectiveProxy_handle, "f").uuid, className, queryJson);
582
583
  }
583
584
  /**
584
585
  * Adds a new link to the perspective.
@@ -766,17 +767,30 @@ export class PerspectiveProxy {
766
767
  async removeListener(type, cb) {
767
768
  if (type === 'link-added') {
768
769
  const index = __classPrivateFieldGet(this, _PerspectiveProxy_perspectiveLinkAddedCallbacks, "f").indexOf(cb);
769
- __classPrivateFieldGet(this, _PerspectiveProxy_perspectiveLinkAddedCallbacks, "f").splice(index, 1);
770
+ if (index >= 0)
771
+ __classPrivateFieldGet(this, _PerspectiveProxy_perspectiveLinkAddedCallbacks, "f").splice(index, 1);
770
772
  }
771
773
  else if (type === 'link-removed') {
772
774
  const index = __classPrivateFieldGet(this, _PerspectiveProxy_perspectiveLinkRemovedCallbacks, "f").indexOf(cb);
773
- __classPrivateFieldGet(this, _PerspectiveProxy_perspectiveLinkRemovedCallbacks, "f").splice(index, 1);
775
+ if (index >= 0)
776
+ __classPrivateFieldGet(this, _PerspectiveProxy_perspectiveLinkRemovedCallbacks, "f").splice(index, 1);
774
777
  }
775
778
  else if (type === 'link-updated') {
776
779
  const index = __classPrivateFieldGet(this, _PerspectiveProxy_perspectiveLinkUpdatedCallbacks, "f").indexOf(cb);
777
- __classPrivateFieldGet(this, _PerspectiveProxy_perspectiveLinkUpdatedCallbacks, "f").splice(index, 1);
780
+ if (index >= 0)
781
+ __classPrivateFieldGet(this, _PerspectiveProxy_perspectiveLinkUpdatedCallbacks, "f").splice(index, 1);
778
782
  }
779
783
  }
784
+ /** Clean up all subscriptions registered by this proxy.
785
+ * Call this when the proxy is no longer needed to prevent subscription leaks.
786
+ * After calling dispose(), the proxy should not be used. */
787
+ dispose() {
788
+ __classPrivateFieldGet(this, _PerspectiveProxy_client, "f").removeAllListeners(__classPrivateFieldGet(this, _PerspectiveProxy_handle, "f").uuid);
789
+ __classPrivateFieldGet(this, _PerspectiveProxy_perspectiveLinkAddedCallbacks, "f").length = 0;
790
+ __classPrivateFieldGet(this, _PerspectiveProxy_perspectiveLinkRemovedCallbacks, "f").length = 0;
791
+ __classPrivateFieldGet(this, _PerspectiveProxy_perspectiveLinkUpdatedCallbacks, "f").length = 0;
792
+ __classPrivateFieldGet(this, _PerspectiveProxy_perspectiveSyncStateChangeCallbacks, "f").length = 0;
793
+ }
780
794
  /**
781
795
  * Creates a snapshot of the current perspective state.
782
796
  * Useful for backup or sharing.
@@ -1066,6 +1080,40 @@ export class PerspectiveProxy {
1066
1080
  async addSdna(name, sdnaCode, sdnaType, shaclJson) {
1067
1081
  return __classPrivateFieldGet(this, _PerspectiveProxy_client, "f").addSdna(__classPrivateFieldGet(this, _PerspectiveProxy_handle, "f").uuid, name, sdnaCode, sdnaType, shaclJson);
1068
1082
  }
1083
+ /**
1084
+ * Batch variant of addSdna — registers multiple SDNA entries in a single RPC call.
1085
+ * Acquires the Rust-side mutex once for the entire batch.
1086
+ */
1087
+ async addSdnaAll(entries) {
1088
+ return __classPrivateFieldGet(this, _PerspectiveProxy_client, "f").addSdnaBatch(__classPrivateFieldGet(this, _PerspectiveProxy_handle, "f").uuid, entries);
1089
+ }
1090
+ /**
1091
+ * Batch-registers multiple model classes as SHACL subject classes in a single RPC call.
1092
+ * Skips classes already registered on this perspective instance.
1093
+ */
1094
+ async ensureSubjectClasses(jsClasses) {
1095
+ const entries = [];
1096
+ for (const jsClass of jsClasses) {
1097
+ const className = jsClass.className || jsClass.prototype?.className || jsClass.name;
1098
+ if (__classPrivateFieldGet(this, _PerspectiveProxy_ensuredSubjectClasses, "f").has(className))
1099
+ continue;
1100
+ if (!jsClass.generateSHACL) {
1101
+ throw new Error(`Class ${jsClass.name} must have generateSHACL(). Use @Model decorator.`);
1102
+ }
1103
+ const { shape } = jsClass.generateSHACL();
1104
+ entries.push({
1105
+ name: className,
1106
+ sdnaType: 'subject_class',
1107
+ shaclJson: JSON.stringify(shape.toJSON()),
1108
+ });
1109
+ }
1110
+ if (entries.length === 0)
1111
+ return;
1112
+ await this.addSdnaAll(entries);
1113
+ for (const entry of entries) {
1114
+ __classPrivateFieldGet(this, _PerspectiveProxy_ensuredSubjectClasses, "f").add(entry.name);
1115
+ }
1116
+ }
1069
1117
  /**
1070
1118
  * Adds a subject class to the perspective.
1071
1119
  * Alias for addSdna() with sdnaType='subject_class'.
@@ -0,0 +1 @@
1
+ export {};
@@ -0,0 +1,34 @@
1
+ import { QuerySubscriptionProxy } from './PerspectiveProxy';
2
+ describe('QuerySubscriptionProxy', () => {
3
+ it('treats the initial subscribeQuery() result as a completed initialization', async () => {
4
+ const initialResult = [
5
+ {
6
+ source: 'literal:string:test-channel',
7
+ predicate: 'flux://has_channel_name',
8
+ target: 'literal:string:Runtime Fix Channel',
9
+ },
10
+ ];
11
+ const unsubscribe = jest.fn();
12
+ const mockClient = {
13
+ subscribeQuery: jest.fn().mockResolvedValue({
14
+ subscriptionId: 'sub-1',
15
+ result: initialResult,
16
+ }),
17
+ subscribeToQueryUpdates: jest.fn().mockReturnValue(unsubscribe),
18
+ keepAliveQuery: jest.fn().mockResolvedValue(true),
19
+ disposeQuerySubscription: jest.fn().mockResolvedValue(true),
20
+ };
21
+ const subscription = new QuerySubscriptionProxy('perspective-1', 'SELECT * WHERE { ?s ?p ?o }', mockClient);
22
+ await subscription.subscribe();
23
+ const initialized = await Promise.race([
24
+ subscription.initialized.then(() => 'resolved'),
25
+ new Promise((resolve) => setTimeout(() => resolve('timeout'), 25)),
26
+ ]);
27
+ expect(initialized).toBe('resolved');
28
+ expect(subscription.result).toEqual(initialResult);
29
+ expect(mockClient.subscribeQuery).toHaveBeenCalledWith('perspective-1', 'SELECT * WHERE { ?s ?p ?o }');
30
+ expect(mockClient.subscribeToQueryUpdates).toHaveBeenCalledWith('sub-1', expect.any(Function));
31
+ subscription.dispose();
32
+ expect(unsubscribe).toHaveBeenCalled();
33
+ });
34
+ });