@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.
- package/README.md +2 -25
- package/jest-setup.ts +1 -1
- package/lib/index.cjs +2406 -11070
- package/lib/index.js +2209 -10925
- package/lib/src/Ad4mClient.d.ts +7 -3
- package/lib/src/Ad4mClient.js +29 -13
- package/lib/src/agent/Agent.js +26 -272
- package/lib/src/agent/AgentClient.d.ts +10 -21
- package/lib/src/agent/AgentClient.js +75 -427
- package/lib/src/agent/AgentStatus.js +2 -37
- package/lib/src/ai/AIClient.d.ts +12 -4
- package/lib/src/ai/AIClient.js +81 -285
- package/lib/src/ai/AITypes.d.ts +55 -0
- package/lib/src/ai/AITypes.js +18 -0
- package/lib/src/ai/Tasks.js +10 -133
- package/lib/src/apiClient.d.ts +52 -0
- package/lib/src/apiClient.js +231 -0
- package/lib/src/expression/Expression.d.ts +1 -1
- package/lib/src/expression/Expression.js +13 -122
- package/lib/src/expression/ExpressionClient.d.ts +3 -3
- package/lib/src/expression/ExpressionClient.js +13 -76
- package/lib/src/expression/ExpressionRef.js +2 -25
- package/lib/src/generated/api/AIModelLoadingStatus.d.ts +7 -0
- package/lib/src/generated/api/AIModelLoadingStatus.js +2 -0
- package/lib/src/generated/api/AddLinkExpressionRequest.d.ts +6 -0
- package/lib/src/generated/api/AddLinkExpressionRequest.js +1 -0
- package/lib/src/generated/api/AddLinkRequest.d.ts +6 -0
- package/lib/src/generated/api/AddLinkRequest.js +1 -0
- package/lib/src/generated/api/AddLinksBulkRequest.d.ts +6 -0
- package/lib/src/generated/api/AddLinksBulkRequest.js +1 -0
- package/lib/src/generated/api/AddSdnaRequest.d.ts +6 -0
- package/lib/src/generated/api/AddSdnaRequest.js +2 -0
- package/lib/src/generated/api/ApplyTemplateRequest.d.ts +4 -0
- package/lib/src/generated/api/ApplyTemplateRequest.js +2 -0
- package/lib/src/generated/api/AuthInfoInput.d.ts +10 -0
- package/lib/src/generated/api/AuthInfoInput.js +1 -0
- package/lib/src/generated/api/CapabilityInput.d.ts +5 -0
- package/lib/src/generated/api/CapabilityInput.js +1 -0
- package/lib/src/generated/api/CommitBatchRequest.d.ts +3 -0
- package/lib/src/generated/api/CommitBatchRequest.js +2 -0
- package/lib/src/generated/api/ComputeLogEntry.d.ts +9 -0
- package/lib/src/generated/api/ComputeLogEntry.js +2 -0
- package/lib/src/generated/api/CreateExpressionRequest.d.ts +4 -0
- package/lib/src/generated/api/CreateExpressionRequest.js +2 -0
- package/lib/src/generated/api/CreatePerspectiveRequest.d.ts +3 -0
- package/lib/src/generated/api/CreatePerspectiveRequest.js +2 -0
- package/lib/src/generated/api/CreateSubjectRequest.d.ts +6 -0
- package/lib/src/generated/api/CreateSubjectRequest.js +2 -0
- package/lib/src/generated/api/EmbedRequest.d.ts +4 -0
- package/lib/src/generated/api/EmbedRequest.js +2 -0
- package/lib/src/generated/api/EntanglementProofInput.d.ts +6 -0
- package/lib/src/generated/api/EntanglementProofInput.js +2 -0
- package/lib/src/generated/api/ExecuteCommandsRequest.d.ts +4 -0
- package/lib/src/generated/api/ExecuteCommandsRequest.js +2 -0
- package/lib/src/generated/api/ExportRequest.d.ts +5 -0
- package/lib/src/generated/api/ExportRequest.js +2 -0
- package/lib/src/generated/api/ExpressionManyRequest.d.ts +3 -0
- package/lib/src/generated/api/ExpressionManyRequest.js +2 -0
- package/lib/src/generated/api/ExpressionProof.d.ts +4 -0
- package/lib/src/generated/api/ExpressionProof.js +2 -0
- package/lib/src/generated/api/ExpressionProofInput.d.ts +6 -0
- package/lib/src/generated/api/ExpressionProofInput.js +2 -0
- package/lib/src/generated/api/FriendSendMessageRequest.d.ts +3 -0
- package/lib/src/generated/api/FriendSendMessageRequest.js +2 -0
- package/lib/src/generated/api/FriendsListRequest.d.ts +3 -0
- package/lib/src/generated/api/FriendsListRequest.js +2 -0
- package/lib/src/generated/api/GenerateAgentRequest.d.ts +3 -0
- package/lib/src/generated/api/GenerateAgentRequest.js +2 -0
- package/lib/src/generated/api/GenerateJwtRequest.d.ts +4 -0
- package/lib/src/generated/api/GenerateJwtRequest.js +2 -0
- package/lib/src/generated/api/GetSubjectDataRequest.d.ts +4 -0
- package/lib/src/generated/api/GetSubjectDataRequest.js +2 -0
- package/lib/src/generated/api/ImportAgentRequest.d.ts +6 -0
- package/lib/src/generated/api/ImportAgentRequest.js +2 -0
- package/lib/src/generated/api/ImportRequest.d.ts +4 -0
- package/lib/src/generated/api/ImportRequest.js +2 -0
- package/lib/src/generated/api/JoinNeighbourhoodRequest.d.ts +3 -0
- package/lib/src/generated/api/JoinNeighbourhoodRequest.js +2 -0
- package/lib/src/generated/api/LanguageMetaInput.d.ts +6 -0
- package/lib/src/generated/api/LanguageMetaInput.js +2 -0
- package/lib/src/generated/api/Link.d.ts +5 -0
- package/lib/src/generated/api/Link.js +2 -0
- package/lib/src/generated/api/LinkExpression.d.ts +10 -0
- package/lib/src/generated/api/LinkExpression.js +1 -0
- package/lib/src/generated/api/LinkExpressionInput.d.ts +10 -0
- package/lib/src/generated/api/LinkExpressionInput.js +1 -0
- package/lib/src/generated/api/LinkInput.d.ts +5 -0
- package/lib/src/generated/api/LinkInput.js +2 -0
- package/lib/src/generated/api/LinkLanguageTemplatesRequest.d.ts +3 -0
- package/lib/src/generated/api/LinkLanguageTemplatesRequest.js +2 -0
- package/lib/src/generated/api/LinkMutations.d.ts +6 -0
- package/lib/src/generated/api/LinkMutations.js +1 -0
- package/lib/src/generated/api/LinkStatus.d.ts +1 -0
- package/lib/src/generated/api/LinkStatus.js +2 -0
- package/lib/src/generated/api/LockAgentRequest.d.ts +3 -0
- package/lib/src/generated/api/LockAgentRequest.js +2 -0
- package/lib/src/generated/api/ModelType.d.ts +1 -0
- package/lib/src/generated/api/ModelType.js +2 -0
- package/lib/src/generated/api/NotificationInput.d.ts +10 -0
- package/lib/src/generated/api/NotificationInput.js +2 -0
- package/lib/src/generated/api/OpenLinkRequest.d.ts +3 -0
- package/lib/src/generated/api/OpenLinkRequest.js +2 -0
- package/lib/src/generated/api/PermitCapabilityRequest.d.ts +3 -0
- package/lib/src/generated/api/PermitCapabilityRequest.js +2 -0
- package/lib/src/generated/api/PerspectiveInput.d.ts +4 -0
- package/lib/src/generated/api/PerspectiveInput.js +1 -0
- package/lib/src/generated/api/PromptRequest.d.ts +4 -0
- package/lib/src/generated/api/PromptRequest.js +2 -0
- package/lib/src/generated/api/PublishLanguageRequest.d.ts +5 -0
- package/lib/src/generated/api/PublishLanguageRequest.js +1 -0
- package/lib/src/generated/api/PublishNeighbourhoodRequest.d.ts +6 -0
- package/lib/src/generated/api/PublishNeighbourhoodRequest.js +1 -0
- package/lib/src/generated/api/QueryRequest.d.ts +7 -0
- package/lib/src/generated/api/QueryRequest.js +2 -0
- package/lib/src/generated/api/RemoveLinkRequest.d.ts +5 -0
- package/lib/src/generated/api/RemoveLinkRequest.js +1 -0
- package/lib/src/generated/api/RemoveLinksBulkRequest.d.ts +5 -0
- package/lib/src/generated/api/RemoveLinksBulkRequest.js +1 -0
- package/lib/src/generated/api/ResourceInput.d.ts +4 -0
- package/lib/src/generated/api/ResourceInput.js +2 -0
- package/lib/src/generated/api/SetDefaultModelRequest.d.ts +4 -0
- package/lib/src/generated/api/SetDefaultModelRequest.js +1 -0
- package/lib/src/generated/api/SetFreeHostingEnabledRequest.d.ts +3 -0
- package/lib/src/generated/api/SetFreeHostingEnabledRequest.js +2 -0
- package/lib/src/generated/api/SetMultiUserRequest.d.ts +3 -0
- package/lib/src/generated/api/SetMultiUserRequest.js +2 -0
- package/lib/src/generated/api/SetStatusRequest.d.ts +3 -0
- package/lib/src/generated/api/SetStatusRequest.js +2 -0
- package/lib/src/generated/api/SignMessageRequest.d.ts +3 -0
- package/lib/src/generated/api/SignMessageRequest.js +2 -0
- package/lib/src/generated/api/TrustedAgentsRequest.d.ts +3 -0
- package/lib/src/generated/api/TrustedAgentsRequest.js +2 -0
- package/lib/src/generated/api/UnlockAgentRequest.d.ts +4 -0
- package/lib/src/generated/api/UnlockAgentRequest.js +2 -0
- package/lib/src/generated/api/UpdateLinkRequest.d.ts +7 -0
- package/lib/src/generated/api/UpdateLinkRequest.js +1 -0
- package/lib/src/generated/api/UpdatePerspectiveRequest.d.ts +3 -0
- package/lib/src/generated/api/UpdatePerspectiveRequest.js +2 -0
- package/lib/src/generated/api/UserStatistics.d.ts +9 -0
- package/lib/src/generated/api/UserStatistics.js +2 -0
- package/lib/src/generated/api/VerificationRequestResult.d.ts +6 -0
- package/lib/src/generated/api/VerificationRequestResult.js +2 -0
- package/lib/src/generated/api/VerifySignatureRequest.d.ts +5 -0
- package/lib/src/generated/api/VerifySignatureRequest.js +2 -0
- package/lib/src/generated/api/WriteSettingsRequest.d.ts +3 -0
- package/lib/src/generated/api/WriteSettingsRequest.js +2 -0
- package/lib/src/generated/api/index.d.ts +42 -0
- package/lib/src/generated/api/index.js +7 -0
- package/lib/src/index.d.ts +6 -1
- package/lib/src/index.js +6 -1
- package/lib/src/jestSetup.d.ts +0 -1
- package/lib/src/jestSetup.js +1 -1
- package/lib/src/language/Icon.js +2 -21
- package/lib/src/language/Language.d.ts +1 -1
- package/lib/src/language/Language.js +10 -76
- package/lib/src/language/LanguageClient.d.ts +2 -2
- package/lib/src/language/LanguageClient.js +15 -105
- package/lib/src/language/LanguageHandle.js +2 -41
- package/lib/src/language/LanguageMeta.js +4 -75
- package/lib/src/language/LanguageRef.js +2 -25
- package/lib/src/links/Links.js +14 -111
- package/lib/src/model/Ad4mModel.d.ts +57 -38
- package/lib/src/model/Ad4mModel.js +594 -460
- package/lib/src/model/Ad4mModel.test.js +371 -815
- package/lib/src/model/ModelQueryBuilder.d.ts +9 -21
- package/lib/src/model/ModelQueryBuilder.js +138 -217
- package/lib/src/model/decorators.d.ts +22 -0
- package/lib/src/model/decorators.js +7 -0
- package/lib/src/model/hydration.d.ts +7 -60
- package/lib/src/model/hydration.js +7 -716
- package/lib/src/model/index.d.ts +0 -4
- package/lib/src/model/index.js +0 -4
- package/lib/src/model/model-manifest.d.ts +41 -0
- package/lib/src/model/model-manifest.js +11 -0
- package/lib/src/model/query-sparql.d.ts +4 -67
- package/lib/src/model/query-sparql.js +26 -322
- package/lib/src/model/query-sparql.test.js +35 -218
- package/lib/src/model/shacl-gen.js +4 -0
- package/lib/src/model/types.d.ts +47 -38
- package/lib/src/model/types.js +4 -1
- package/lib/src/neighbourhood/Neighbourhood.js +4 -32
- package/lib/src/neighbourhood/NeighbourhoodClient.d.ts +3 -3
- package/lib/src/neighbourhood/NeighbourhoodClient.js +40 -203
- package/lib/src/perspectives/LinkQuery.js +2 -42
- package/lib/src/perspectives/Perspective.d.ts +1 -1
- package/lib/src/perspectives/Perspective.js +10 -52
- package/lib/src/perspectives/PerspectiveClient.d.ts +12 -17
- package/lib/src/perspectives/PerspectiveClient.js +169 -429
- package/lib/src/perspectives/PerspectiveClient.test.js +55 -0
- package/lib/src/perspectives/PerspectiveDiff.js +4 -31
- package/lib/src/perspectives/PerspectiveHandle.js +3 -43
- package/lib/src/perspectives/PerspectiveProxy.d.ts +92 -71
- package/lib/src/perspectives/PerspectiveProxy.js +273 -310
- package/lib/src/runtime/RuntimeClient.d.ts +6 -6
- package/lib/src/runtime/RuntimeClient.js +93 -467
- package/lib/src/runtime/RuntimeTypes.d.ts +101 -0
- package/lib/src/runtime/RuntimeTypes.js +45 -0
- package/lib/src/shacl/SHACLShape.d.ts +7 -0
- package/lib/src/shacl/SHACLShape.js +19 -0
- package/lib/src/shacl/SHACLShape.test.js +82 -0
- package/lib/src/typeDefs.js +3 -628
- package/package.json +9 -24
- package/rollup.config.js +0 -7
- package/src/Ad4mClient.test.ts +1179 -1340
- package/src/Ad4mClient.ts +30 -15
- package/src/agent/Agent.ts +0 -99
- package/src/agent/AgentClient.ts +112 -526
- package/src/agent/AgentStatus.ts +0 -12
- package/src/ai/AIClient.ts +96 -296
- package/src/ai/AITypes.ts +66 -0
- package/src/ai/Tasks.ts +0 -52
- package/src/apiClient.ts +283 -0
- package/src/expression/Expression.ts +3 -43
- package/src/expression/ExpressionClient.ts +14 -77
- package/src/expression/ExpressionRef.ts +0 -6
- package/src/generated/api/AIModelLoadingStatus.ts +3 -0
- package/src/generated/api/AddLinkExpressionRequest.ts +4 -0
- package/src/generated/api/AddLinkRequest.ts +4 -0
- package/src/generated/api/AddLinksBulkRequest.ts +4 -0
- package/src/generated/api/AddSdnaRequest.ts +3 -0
- package/src/generated/api/ApplyTemplateRequest.ts +3 -0
- package/src/generated/api/AuthInfoInput.ts +4 -0
- package/src/generated/api/CapabilityInput.ts +4 -0
- package/src/generated/api/CommitBatchRequest.ts +3 -0
- package/src/generated/api/ComputeLogEntry.ts +3 -0
- package/src/generated/api/CreateExpressionRequest.ts +3 -0
- package/src/generated/api/CreatePerspectiveRequest.ts +3 -0
- package/src/generated/api/CreateSubjectRequest.ts +3 -0
- package/src/generated/api/EmbedRequest.ts +3 -0
- package/src/generated/api/EntanglementProofInput.ts +3 -0
- package/src/generated/api/ExecuteCommandsRequest.ts +3 -0
- package/src/generated/api/ExportRequest.ts +3 -0
- package/src/generated/api/ExpressionManyRequest.ts +3 -0
- package/src/generated/api/ExpressionProof.ts +3 -0
- package/src/generated/api/ExpressionProofInput.ts +3 -0
- package/src/generated/api/FriendSendMessageRequest.ts +3 -0
- package/src/generated/api/FriendsListRequest.ts +3 -0
- package/src/generated/api/GenerateAgentRequest.ts +3 -0
- package/src/generated/api/GenerateJwtRequest.ts +3 -0
- package/src/generated/api/GetSubjectDataRequest.ts +3 -0
- package/src/generated/api/ImportAgentRequest.ts +3 -0
- package/src/generated/api/ImportRequest.ts +3 -0
- package/src/generated/api/JoinNeighbourhoodRequest.ts +3 -0
- package/src/generated/api/LanguageMetaInput.ts +3 -0
- package/src/generated/api/Link.ts +3 -0
- package/src/generated/api/LinkExpression.ts +6 -0
- package/src/generated/api/LinkExpressionInput.ts +6 -0
- package/src/generated/api/LinkInput.ts +3 -0
- package/src/generated/api/LinkLanguageTemplatesRequest.ts +3 -0
- package/src/generated/api/LinkMutations.ts +5 -0
- package/src/generated/api/LinkStatus.ts +3 -0
- package/src/generated/api/LockAgentRequest.ts +3 -0
- package/src/generated/api/ModelType.ts +3 -0
- package/src/generated/api/NotificationInput.ts +3 -0
- package/src/generated/api/OpenLinkRequest.ts +3 -0
- package/src/generated/api/PermitCapabilityRequest.ts +3 -0
- package/src/generated/api/PerspectiveInput.ts +4 -0
- package/src/generated/api/PromptRequest.ts +3 -0
- package/src/generated/api/PublishLanguageRequest.ts +4 -0
- package/src/generated/api/PublishNeighbourhoodRequest.ts +4 -0
- package/src/generated/api/QueryRequest.ts +6 -0
- package/src/generated/api/RemoveLinkRequest.ts +4 -0
- package/src/generated/api/RemoveLinksBulkRequest.ts +4 -0
- package/src/generated/api/ResourceInput.ts +3 -0
- package/src/generated/api/SetDefaultModelRequest.ts +4 -0
- package/src/generated/api/SetFreeHostingEnabledRequest.ts +3 -0
- package/src/generated/api/SetMultiUserRequest.ts +3 -0
- package/src/generated/api/SetStatusRequest.ts +3 -0
- package/src/generated/api/SignMessageRequest.ts +3 -0
- package/src/generated/api/TrustedAgentsRequest.ts +3 -0
- package/src/generated/api/UnlockAgentRequest.ts +3 -0
- package/src/generated/api/UpdateLinkRequest.ts +5 -0
- package/src/generated/api/UpdatePerspectiveRequest.ts +3 -0
- package/src/generated/api/UserStatistics.ts +3 -0
- package/src/generated/api/VerificationRequestResult.ts +3 -0
- package/src/generated/api/VerifySignatureRequest.ts +3 -0
- package/src/generated/api/WriteSettingsRequest.ts +3 -0
- package/src/generated/api/index.ts +49 -0
- package/src/index.ts +6 -1
- package/src/jestSetup.ts +1 -1
- package/src/language/Icon.ts +0 -4
- package/src/language/Language.ts +2 -23
- package/src/language/LanguageClient.ts +21 -132
- package/src/language/LanguageHandle.ts +0 -14
- package/src/language/LanguageMeta.ts +0 -29
- package/src/language/LanguageRef.ts +0 -7
- package/src/links/Links.ts +0 -37
- package/src/model/Ad4mModel.test.ts +708 -876
- package/src/model/Ad4mModel.ts +613 -508
- package/src/model/ModelQueryBuilder.ts +178 -244
- package/src/model/decorators.ts +29 -0
- package/src/model/hydration.ts +9 -766
- package/src/model/index.ts +0 -4
- package/src/model/query-sparql.test.ts +34 -242
- package/src/model/query-sparql.ts +27 -337
- package/src/model/shacl-gen.ts +5 -0
- package/src/model/types.ts +51 -39
- package/src/neighbourhood/Neighbourhood.ts +0 -9
- package/src/neighbourhood/NeighbourhoodClient.ts +42 -207
- package/src/neighbourhood/NeighbourhoodProxy.test.ts +34 -36
- package/src/perspectives/LinkQuery.ts +0 -15
- package/src/perspectives/Perspective.ts +1 -12
- package/src/perspectives/PerspectiveClient.test.ts +206 -148
- package/src/perspectives/PerspectiveClient.ts +228 -442
- package/src/perspectives/PerspectiveDiff.ts +0 -8
- package/src/perspectives/PerspectiveHandle.ts +1 -12
- package/src/perspectives/PerspectiveProxy.test.ts +41 -0
- package/src/perspectives/PerspectiveProxy.ts +307 -348
- package/src/runtime/RuntimeClient.ts +112 -474
- package/src/runtime/RuntimeTypes.ts +144 -0
- package/src/shacl/SHACLShape.test.ts +94 -0
- package/src/shacl/SHACLShape.ts +27 -0
- package/src/typeDefs.ts +3 -5
- package/tsconfig.json +3 -7
- package/shims/reflect-metadata.ts +0 -0
- package/shims/type-graphql.ts +0 -75
- package/src/PubSub.ts +0 -17
- package/src/agent/AgentResolver.ts +0 -263
- package/src/ai/AIResolver.ts +0 -372
- package/src/buildSchema.ts +0 -43
- package/src/expression/ExpressionResolver.ts +0 -64
- package/src/language/LanguageResolver.ts +0 -98
- package/src/model/Subject.ts +0 -159
- package/src/model/hydration-batch.ts +0 -205
- package/src/model/hydration-batching.test.ts +0 -563
- package/src/model/prolog-facts.ts +0 -145
- package/src/model/query-prolog.ts +0 -148
- package/src/model/query-sparql-batch.ts +0 -301
- package/src/model/subscription-delta.test.ts +0 -207
- package/src/model/subscription-pool.ts +0 -211
- package/src/neighbourhood/NeighbourhoodResolver.ts +0 -100
- package/src/perspectives/PerspectiveResolver.ts +0 -364
- package/src/runtime/RuntimeResolver.ts +0 -749
- package/src/unwrapApolloResult.ts +0 -16
|
@@ -33,14 +33,13 @@ export declare class ModelQueryBuilder<T extends Ad4mModel> {
|
|
|
33
33
|
private modelClassName;
|
|
34
34
|
private ctor;
|
|
35
35
|
private currentSubscription?;
|
|
36
|
-
private engineFlag;
|
|
37
36
|
constructor(perspective: PerspectiveProxy, ctor: typeof Ad4mModel, query?: Query);
|
|
38
37
|
/**
|
|
39
38
|
* Disposes of the current subscription if one exists.
|
|
40
39
|
*
|
|
41
40
|
* This method:
|
|
42
41
|
* 1. Stops the keepalive signals to the subscription
|
|
43
|
-
* 2. Unsubscribes from
|
|
42
|
+
* 2. Unsubscribes from subscription updates
|
|
44
43
|
* 3. Notifies the backend to clean up subscription resources
|
|
45
44
|
* 4. Clears the subscription reference
|
|
46
45
|
*
|
|
@@ -207,8 +206,9 @@ export declare class ModelQueryBuilder<T extends Ad4mModel> {
|
|
|
207
206
|
overrideModelClassName(className: string): ModelQueryBuilder<T>;
|
|
208
207
|
/**
|
|
209
208
|
* Sets the query engine to use.
|
|
209
|
+
* @deprecated Prolog engine has been removed. All queries use SPARQL/Rust.
|
|
210
210
|
*/
|
|
211
|
-
engine(
|
|
211
|
+
engine(_eng: 'sparql' | 'prolog'): ModelQueryBuilder<T>;
|
|
212
212
|
/**
|
|
213
213
|
* Executes the query once and returns the results.
|
|
214
214
|
*
|
|
@@ -227,14 +227,9 @@ export declare class ModelQueryBuilder<T extends Ad4mModel> {
|
|
|
227
227
|
*/
|
|
228
228
|
getSparql(): Promise<T[]>;
|
|
229
229
|
/**
|
|
230
|
-
* Shared
|
|
230
|
+
* Shared query execution logic — routes through the executor-side modelQuery endpoint.
|
|
231
231
|
*/
|
|
232
232
|
private executeSparqlQuery;
|
|
233
|
-
/**
|
|
234
|
-
* Groups raw SPARQL results and hydrates them into model instances.
|
|
235
|
-
* Centralises the repeated groupSPARQLResults → instancesFromQueryResult pipeline.
|
|
236
|
-
*/
|
|
237
|
-
private processSparqlResult;
|
|
238
233
|
/**
|
|
239
234
|
* Returns the first matching instance, or `null` if none match.
|
|
240
235
|
*
|
|
@@ -277,13 +272,11 @@ export declare class ModelQueryBuilder<T extends Ad4mModel> {
|
|
|
277
272
|
* builder.dispose();
|
|
278
273
|
* ```
|
|
279
274
|
*
|
|
280
|
-
* @remarks
|
|
281
|
-
* By default, this uses SPARQL live queries for real-time updates.
|
|
282
|
-
* Prolog subscriptions remain available via `.useSPARQL(false)`.
|
|
283
275
|
*/
|
|
284
276
|
subscribe(callback: (results: T[]) => void): Promise<T[]>;
|
|
285
277
|
/**
|
|
286
278
|
* Subscribes to the query and receives updates using SPARQL.
|
|
279
|
+
* @deprecated Use subscribe() instead — now routes through Rust model subscription.
|
|
287
280
|
*/
|
|
288
281
|
subscribeSparql(callback: (results: T[]) => void): Promise<T[]>;
|
|
289
282
|
/**
|
|
@@ -301,7 +294,7 @@ export declare class ModelQueryBuilder<T extends Ad4mModel> {
|
|
|
301
294
|
count(): Promise<number>;
|
|
302
295
|
/**
|
|
303
296
|
* Gets the total count of matching entities using SPARQL.
|
|
304
|
-
* Delegates to count()
|
|
297
|
+
* Delegates to count().
|
|
305
298
|
*/
|
|
306
299
|
countSparql(): Promise<number>;
|
|
307
300
|
/**
|
|
@@ -331,13 +324,11 @@ export declare class ModelQueryBuilder<T extends Ad4mModel> {
|
|
|
331
324
|
* builder.dispose();
|
|
332
325
|
* ```
|
|
333
326
|
*
|
|
334
|
-
* @remarks
|
|
335
|
-
* By default, this uses SPARQL live queries for real-time updates.
|
|
336
|
-
* Prolog subscriptions remain available via `.useSPARQL(false)`.
|
|
337
327
|
*/
|
|
338
328
|
countSubscribe(callback: (count: number) => void): Promise<number>;
|
|
339
329
|
/**
|
|
340
330
|
* Subscribes to count updates using SPARQL.
|
|
331
|
+
* @deprecated Use countSubscribe() instead — now routes through Rust model subscription.
|
|
341
332
|
*/
|
|
342
333
|
countSubscribeSparql(callback: (count: number) => void): Promise<number>;
|
|
343
334
|
/**
|
|
@@ -358,7 +349,7 @@ export declare class ModelQueryBuilder<T extends Ad4mModel> {
|
|
|
358
349
|
paginate(pageSize: number, pageNumber: number): Promise<PaginationResult<T>>;
|
|
359
350
|
/**
|
|
360
351
|
* Gets a page of results using SPARQL.
|
|
361
|
-
* Delegates to paginate()
|
|
352
|
+
* Delegates to paginate().
|
|
362
353
|
*/
|
|
363
354
|
paginateSparql(pageSize: number, pageNumber: number): Promise<PaginationResult<T>>;
|
|
364
355
|
/**
|
|
@@ -390,14 +381,11 @@ export declare class ModelQueryBuilder<T extends Ad4mModel> {
|
|
|
390
381
|
* builder.dispose();
|
|
391
382
|
* ```
|
|
392
383
|
*
|
|
393
|
-
* @remarks
|
|
394
|
-
* By default, this uses SPARQL live queries for real-time updates.
|
|
395
|
-
* Prolog subscriptions remain available via `.useSPARQL(false)`.
|
|
396
384
|
*/
|
|
397
385
|
paginateSubscribe(pageSize: number, pageNumber: number, callback: (results: PaginationResult<T>) => void): Promise<PaginationResult<T>>;
|
|
398
386
|
/**
|
|
399
387
|
* Subscribes to paginated results updates using SPARQL.
|
|
400
|
-
* Delegates to paginateSubscribe()
|
|
388
|
+
* Delegates to paginateSubscribe().
|
|
401
389
|
*/
|
|
402
390
|
paginateSubscribeSparql(pageSize: number, pageNumber: number, callback: (results: PaginationResult<T>) => void): Promise<PaginationResult<T>>;
|
|
403
391
|
}
|
|
@@ -4,9 +4,6 @@
|
|
|
4
4
|
* Allows building queries with a chainable interface and either
|
|
5
5
|
* running them once or subscribing to real-time updates.
|
|
6
6
|
*/
|
|
7
|
-
import { groupSPARQLResults, hasJsOnlyWhereFilters, parseSparqlCount } from "./query-sparql";
|
|
8
|
-
import { getRelationsMetadata } from "./decorators";
|
|
9
|
-
import { pooledSubscribe } from "./subscription-pool";
|
|
10
7
|
/** Query builder for Ad4mModel queries.
|
|
11
8
|
* Allows building queries with a fluent interface and either running them once
|
|
12
9
|
* or subscribing to updates.
|
|
@@ -31,7 +28,6 @@ export class ModelQueryBuilder {
|
|
|
31
28
|
constructor(perspective, ctor, query) {
|
|
32
29
|
this.queryParams = {};
|
|
33
30
|
this.modelClassName = null;
|
|
34
|
-
this.engineFlag = 'sparql';
|
|
35
31
|
this.perspective = perspective;
|
|
36
32
|
this.ctor = ctor;
|
|
37
33
|
if (query)
|
|
@@ -42,7 +38,7 @@ export class ModelQueryBuilder {
|
|
|
42
38
|
*
|
|
43
39
|
* This method:
|
|
44
40
|
* 1. Stops the keepalive signals to the subscription
|
|
45
|
-
* 2. Unsubscribes from
|
|
41
|
+
* 2. Unsubscribes from subscription updates
|
|
46
42
|
* 3. Notifies the backend to clean up subscription resources
|
|
47
43
|
* 4. Clears the subscription reference
|
|
48
44
|
*
|
|
@@ -262,9 +258,9 @@ export class ModelQueryBuilder {
|
|
|
262
258
|
}
|
|
263
259
|
/**
|
|
264
260
|
* Sets the query engine to use.
|
|
261
|
+
* @deprecated Prolog engine has been removed. All queries use SPARQL/Rust.
|
|
265
262
|
*/
|
|
266
|
-
engine(
|
|
267
|
-
this.engineFlag = eng;
|
|
263
|
+
engine(_eng) {
|
|
268
264
|
return this;
|
|
269
265
|
}
|
|
270
266
|
/**
|
|
@@ -280,16 +276,7 @@ export class ModelQueryBuilder {
|
|
|
280
276
|
* ```
|
|
281
277
|
*/
|
|
282
278
|
async get() {
|
|
283
|
-
|
|
284
|
-
if (this.engineFlag === 'sparql') {
|
|
285
|
-
results = await this.executeSparqlQuery();
|
|
286
|
-
}
|
|
287
|
-
else {
|
|
288
|
-
const query = await this.ctor.queryToProlog(this.perspective, this.queryParams, this.modelClassName);
|
|
289
|
-
const result = await this.perspective.infer(query);
|
|
290
|
-
({ results } = await this.ctor.instancesFromPrologResult(this.perspective, this.queryParams, result));
|
|
291
|
-
}
|
|
292
|
-
return results;
|
|
279
|
+
return await this.executeSparqlQuery();
|
|
293
280
|
}
|
|
294
281
|
/**
|
|
295
282
|
* Executes the query once using SPARQL and returns the results.
|
|
@@ -298,22 +285,12 @@ export class ModelQueryBuilder {
|
|
|
298
285
|
return this.executeSparqlQuery();
|
|
299
286
|
}
|
|
300
287
|
/**
|
|
301
|
-
* Shared
|
|
288
|
+
* Shared query execution logic — routes through the executor-side modelQuery endpoint.
|
|
302
289
|
*/
|
|
303
290
|
async executeSparqlQuery() {
|
|
304
|
-
const
|
|
305
|
-
const rawResult = await this.perspective.querySparql(sparqlQuery);
|
|
306
|
-
const { results } = await this.processSparqlResult(rawResult);
|
|
291
|
+
const { results } = await this.ctor.executeModelQuery(this.perspective, this.queryParams, this.modelClassName);
|
|
307
292
|
return results;
|
|
308
293
|
}
|
|
309
|
-
/**
|
|
310
|
-
* Groups raw SPARQL results and hydrates them into model instances.
|
|
311
|
-
* Centralises the repeated groupSPARQLResults → instancesFromQueryResult pipeline.
|
|
312
|
-
*/
|
|
313
|
-
async processSparqlResult(rawResult, queryOverride, computeTotalCount = false) {
|
|
314
|
-
const grouped = groupSPARQLResults(Array.isArray(rawResult) ? rawResult : []);
|
|
315
|
-
return await this.ctor.instancesFromQueryResult(this.perspective, queryOverride || this.queryParams, grouped, computeTotalCount);
|
|
316
|
-
}
|
|
317
294
|
/**
|
|
318
295
|
* Returns the first matching instance, or `null` if none match.
|
|
319
296
|
*
|
|
@@ -360,70 +337,74 @@ export class ModelQueryBuilder {
|
|
|
360
337
|
* builder.dispose();
|
|
361
338
|
* ```
|
|
362
339
|
*
|
|
363
|
-
* @remarks
|
|
364
|
-
* By default, this uses SPARQL live queries for real-time updates.
|
|
365
|
-
* Prolog subscriptions remain available via `.useSPARQL(false)`.
|
|
366
340
|
*/
|
|
367
341
|
async subscribe(callback) {
|
|
368
342
|
// Clean up any existing subscription
|
|
369
343
|
this.dispose();
|
|
370
344
|
const ctor = this.ctor;
|
|
371
|
-
|
|
372
|
-
|
|
373
|
-
|
|
374
|
-
|
|
375
|
-
|
|
376
|
-
|
|
377
|
-
|
|
378
|
-
|
|
379
|
-
|
|
380
|
-
|
|
381
|
-
|
|
382
|
-
|
|
383
|
-
|
|
384
|
-
|
|
385
|
-
|
|
386
|
-
|
|
387
|
-
|
|
345
|
+
// Build the model query params (className, queryJson, shapeJson)
|
|
346
|
+
const { className, queryJson, shapeJson } = ctor.prepareModelQueryParams(this.queryParams, this.modelClassName);
|
|
347
|
+
// Register model subscription via Rust — this builds trigger SPARQL internally,
|
|
348
|
+
// registers the subscription, and runs the initial query in one call.
|
|
349
|
+
const { subscriptionId, result: initialModelResult } = await this.perspective.modelSubscribe(className, queryJson, shapeJson);
|
|
350
|
+
// Convert JSON instances to model class instances
|
|
351
|
+
const parseResults = (raw) => {
|
|
352
|
+
return ctor.parseModelResult(this.perspective, raw, this.queryParams.include, this.queryParams.properties);
|
|
353
|
+
};
|
|
354
|
+
// Parse initial results
|
|
355
|
+
const initialResults = parseResults(initialModelResult);
|
|
356
|
+
// Track last emitted result fingerprint to suppress duplicate callbacks
|
|
357
|
+
let lastResultFingerprint = null;
|
|
358
|
+
const buildFingerprint = (results) => {
|
|
359
|
+
if (results.length === 0)
|
|
360
|
+
return '0:';
|
|
361
|
+
return JSON.stringify(results, (_, v) => typeof v === 'function' ? undefined : v);
|
|
362
|
+
};
|
|
363
|
+
lastResultFingerprint = buildFingerprint(initialResults);
|
|
364
|
+
// Listen for subscription updates via the same GraphQL subscription channel.
|
|
365
|
+
// When Rust re-runs the model query and finds changed results, it pushes them.
|
|
366
|
+
const unsubscribe = this.perspective.client.subscribeToQueryUpdates(subscriptionId, (rawResult) => {
|
|
367
|
+
// Skip delayed #init# messages — initial data was already returned
|
|
368
|
+
// synchronously from modelSubscribe(). Late init messages contain stale
|
|
369
|
+
// data that would overwrite real subscription updates.
|
|
370
|
+
if (rawResult && rawResult.isInit)
|
|
371
|
+
return;
|
|
372
|
+
try {
|
|
373
|
+
const results = parseResults(rawResult);
|
|
374
|
+
const fp = buildFingerprint(results);
|
|
388
375
|
if (fp === lastResultFingerprint)
|
|
389
376
|
return;
|
|
390
377
|
lastResultFingerprint = fp;
|
|
391
|
-
callback(hydratedResults);
|
|
392
|
-
});
|
|
393
|
-
// Store dispose function as subscription
|
|
394
|
-
this.currentSubscription = { dispose: pooled.dispose };
|
|
395
|
-
const initialResults = pooled.initialResult;
|
|
396
|
-
lastResultFingerprint = buildFingerprint(initialResults);
|
|
397
|
-
return initialResults;
|
|
398
|
-
}
|
|
399
|
-
else {
|
|
400
|
-
const query = await ctor.queryToProlog(this.perspective, this.queryParams, this.modelClassName);
|
|
401
|
-
this.currentSubscription = await this.perspective.subscribeInfer(query);
|
|
402
|
-
const processResults = async (result) => {
|
|
403
|
-
const { results } = await ctor.instancesFromPrologResult(this.perspective, this.queryParams, result);
|
|
404
378
|
callback(results);
|
|
405
|
-
}
|
|
406
|
-
|
|
407
|
-
|
|
408
|
-
|
|
409
|
-
|
|
379
|
+
}
|
|
380
|
+
catch (e) {
|
|
381
|
+
console.error('Model subscription update parse error:', e);
|
|
382
|
+
}
|
|
383
|
+
});
|
|
384
|
+
// Set up keepalive
|
|
385
|
+
const keepaliveTimer = setInterval(() => {
|
|
386
|
+
this.perspective.client.keepAliveQuery(this.perspective.uuid, subscriptionId).catch(() => { });
|
|
387
|
+
}, 30000);
|
|
388
|
+
// Store dispose function
|
|
389
|
+
this.currentSubscription = {
|
|
390
|
+
dispose: () => {
|
|
391
|
+
clearInterval(keepaliveTimer);
|
|
392
|
+
unsubscribe();
|
|
393
|
+
this.perspective.client.disposeQuerySubscription(this.perspective.uuid, subscriptionId).catch(() => { });
|
|
394
|
+
},
|
|
395
|
+
};
|
|
396
|
+
// Take snapshots for dirty tracking
|
|
397
|
+
for (const inst of initialResults) {
|
|
398
|
+
inst.takeSnapshot?.(this.queryParams.include);
|
|
410
399
|
}
|
|
400
|
+
return initialResults;
|
|
411
401
|
}
|
|
412
402
|
/**
|
|
413
403
|
* Subscribes to the query and receives updates using SPARQL.
|
|
404
|
+
* @deprecated Use subscribe() instead — now routes through Rust model subscription.
|
|
414
405
|
*/
|
|
415
406
|
async subscribeSparql(callback) {
|
|
416
|
-
this.
|
|
417
|
-
const sparqlQuery = await this.ctor.queryToSPARQL(this.perspective, this.queryParams);
|
|
418
|
-
this.currentSubscription = await this.perspective.subscribeQuery(sparqlQuery);
|
|
419
|
-
const processResults = async (result) => {
|
|
420
|
-
const { results } = await this.processSparqlResult(result);
|
|
421
|
-
callback(results);
|
|
422
|
-
};
|
|
423
|
-
this.currentSubscription.onResult(processResults);
|
|
424
|
-
const { results } = await this.processSparqlResult(this.currentSubscription.result);
|
|
425
|
-
// Initial results returned via Promise only — callback is for subsequent updates
|
|
426
|
-
return results;
|
|
407
|
+
return this.subscribe(callback);
|
|
427
408
|
}
|
|
428
409
|
/**
|
|
429
410
|
* Gets the total count of matching entities.
|
|
@@ -438,40 +419,15 @@ export class ModelQueryBuilder {
|
|
|
438
419
|
* ```
|
|
439
420
|
*/
|
|
440
421
|
async count() {
|
|
441
|
-
|
|
442
|
-
|
|
443
|
-
const metadata = this.ctor.getModelMetadata();
|
|
444
|
-
const allRelMeta = getRelationsMetadata(this.ctor);
|
|
445
|
-
if (hasJsOnlyWhereFilters(metadata, allRelMeta, this.queryParams.where)) {
|
|
446
|
-
const sparqlQuery = await this.ctor.queryToSPARQL(this.perspective, this.queryParams);
|
|
447
|
-
const rawResult = await this.perspective.querySparql(sparqlQuery);
|
|
448
|
-
const { totalCount } = await this.processSparqlResult(rawResult, undefined, true);
|
|
449
|
-
return totalCount;
|
|
450
|
-
}
|
|
451
|
-
// Use efficient COUNT query — no hydration
|
|
452
|
-
const countSparql = await this.ctor.countQueryToSPARQL(this.perspective, this.queryParams);
|
|
453
|
-
const countResult = await this.perspective.querySparql(countSparql);
|
|
454
|
-
return parseSparqlCount(countResult) ?? 0;
|
|
455
|
-
}
|
|
456
|
-
else {
|
|
457
|
-
const query = await this.ctor.countQueryToProlog(this.perspective, this.queryParams, this.modelClassName);
|
|
458
|
-
const result = await this.perspective.infer(query);
|
|
459
|
-
return result?.[0]?.TotalCount || 0;
|
|
460
|
-
}
|
|
422
|
+
const { totalCount } = await this.ctor.executeModelQuery(this.perspective, { ...this.queryParams, limit: 0 }, this.modelClassName);
|
|
423
|
+
return totalCount;
|
|
461
424
|
}
|
|
462
425
|
/**
|
|
463
426
|
* Gets the total count of matching entities using SPARQL.
|
|
464
|
-
* Delegates to count()
|
|
427
|
+
* Delegates to count().
|
|
465
428
|
*/
|
|
466
429
|
async countSparql() {
|
|
467
|
-
|
|
468
|
-
this.engineFlag = 'sparql';
|
|
469
|
-
try {
|
|
470
|
-
return await this.count();
|
|
471
|
-
}
|
|
472
|
-
finally {
|
|
473
|
-
this.engineFlag = prev;
|
|
474
|
-
}
|
|
430
|
+
return await this.count();
|
|
475
431
|
}
|
|
476
432
|
/**
|
|
477
433
|
* Subscribes to count updates for matching entities.
|
|
@@ -500,53 +456,46 @@ export class ModelQueryBuilder {
|
|
|
500
456
|
* builder.dispose();
|
|
501
457
|
* ```
|
|
502
458
|
*
|
|
503
|
-
* @remarks
|
|
504
|
-
* By default, this uses SPARQL live queries for real-time updates.
|
|
505
|
-
* Prolog subscriptions remain available via `.useSPARQL(false)`.
|
|
506
459
|
*/
|
|
507
460
|
async countSubscribe(callback) {
|
|
508
461
|
// Clean up any existing subscription
|
|
509
462
|
this.dispose();
|
|
510
|
-
|
|
511
|
-
|
|
512
|
-
|
|
513
|
-
|
|
514
|
-
|
|
515
|
-
|
|
516
|
-
|
|
517
|
-
|
|
518
|
-
|
|
519
|
-
|
|
520
|
-
|
|
521
|
-
|
|
522
|
-
|
|
523
|
-
|
|
524
|
-
|
|
525
|
-
|
|
526
|
-
|
|
527
|
-
|
|
528
|
-
|
|
529
|
-
this.
|
|
530
|
-
|
|
531
|
-
|
|
532
|
-
|
|
533
|
-
|
|
463
|
+
const countParams = { ...this.queryParams, limit: 0 };
|
|
464
|
+
const { className, queryJson, shapeJson } = this.ctor.prepareModelQueryParams(countParams, this.modelClassName);
|
|
465
|
+
const { subscriptionId, result: initialModelResult } = await this.perspective.modelSubscribe(className, queryJson, shapeJson);
|
|
466
|
+
const parseCount = (raw) => {
|
|
467
|
+
const data = typeof raw === 'string' ? JSON.parse(raw) : raw;
|
|
468
|
+
return data.totalCount ?? 0;
|
|
469
|
+
};
|
|
470
|
+
const initialCount = parseCount(initialModelResult);
|
|
471
|
+
const unsubscribe = this.perspective.client.subscribeToQueryUpdates(subscriptionId, (rawResult) => {
|
|
472
|
+
if (rawResult && rawResult.isInit)
|
|
473
|
+
return;
|
|
474
|
+
try {
|
|
475
|
+
callback(parseCount(rawResult));
|
|
476
|
+
}
|
|
477
|
+
catch (e) {
|
|
478
|
+
console.error('Count subscription update parse error:', e);
|
|
479
|
+
}
|
|
480
|
+
});
|
|
481
|
+
const keepaliveTimer = setInterval(() => {
|
|
482
|
+
this.perspective.client.keepAliveQuery(this.perspective.uuid, subscriptionId).catch(() => { });
|
|
483
|
+
}, 30000);
|
|
484
|
+
this.currentSubscription = {
|
|
485
|
+
dispose: () => {
|
|
486
|
+
clearInterval(keepaliveTimer);
|
|
487
|
+
unsubscribe();
|
|
488
|
+
this.perspective.client.disposeQuerySubscription(this.perspective.uuid, subscriptionId).catch(() => { });
|
|
489
|
+
},
|
|
490
|
+
};
|
|
491
|
+
return initialCount;
|
|
534
492
|
}
|
|
535
493
|
/**
|
|
536
494
|
* Subscribes to count updates using SPARQL.
|
|
495
|
+
* @deprecated Use countSubscribe() instead — now routes through Rust model subscription.
|
|
537
496
|
*/
|
|
538
497
|
async countSubscribeSparql(callback) {
|
|
539
|
-
this.
|
|
540
|
-
const sparqlQuery = await this.ctor.queryToSPARQL(this.perspective, this.queryParams);
|
|
541
|
-
this.currentSubscription = await this.perspective.subscribeQuery(sparqlQuery);
|
|
542
|
-
const processResults = async (result) => {
|
|
543
|
-
const { totalCount } = await this.processSparqlResult(result, undefined, true);
|
|
544
|
-
callback(totalCount);
|
|
545
|
-
};
|
|
546
|
-
this.currentSubscription.onResult(processResults);
|
|
547
|
-
const { totalCount } = await this.processSparqlResult(this.currentSubscription.result, undefined, true);
|
|
548
|
-
// Initial count returned via Promise — callback for updates only
|
|
549
|
-
return totalCount;
|
|
498
|
+
return this.countSubscribe(callback);
|
|
550
499
|
}
|
|
551
500
|
/**
|
|
552
501
|
* Gets a page of results with pagination metadata.
|
|
@@ -565,32 +514,15 @@ export class ModelQueryBuilder {
|
|
|
565
514
|
*/
|
|
566
515
|
async paginate(pageSize, pageNumber) {
|
|
567
516
|
const paginationQuery = { ...(this.queryParams || {}), limit: pageSize, offset: pageSize * (pageNumber - 1), count: true };
|
|
568
|
-
|
|
569
|
-
|
|
570
|
-
const result = await this.perspective.querySparql(sparqlQuery);
|
|
571
|
-
const { results, totalCount } = await this.processSparqlResult(result, paginationQuery, true);
|
|
572
|
-
return { results, totalCount, pageSize, pageNumber };
|
|
573
|
-
}
|
|
574
|
-
else {
|
|
575
|
-
const prologQuery = await this.ctor.queryToProlog(this.perspective, paginationQuery, this.modelClassName);
|
|
576
|
-
const result = await this.perspective.infer(prologQuery);
|
|
577
|
-
const { results, totalCount } = (await this.ctor.instancesFromPrologResult(this.perspective, paginationQuery, result));
|
|
578
|
-
return { results, totalCount, pageSize, pageNumber };
|
|
579
|
-
}
|
|
517
|
+
const { results, totalCount } = await this.ctor.executeModelQuery(this.perspective, paginationQuery, this.modelClassName);
|
|
518
|
+
return { results, totalCount, pageSize, pageNumber };
|
|
580
519
|
}
|
|
581
520
|
/**
|
|
582
521
|
* Gets a page of results using SPARQL.
|
|
583
|
-
* Delegates to paginate()
|
|
522
|
+
* Delegates to paginate().
|
|
584
523
|
*/
|
|
585
524
|
async paginateSparql(pageSize, pageNumber) {
|
|
586
|
-
|
|
587
|
-
this.engineFlag = 'sparql';
|
|
588
|
-
try {
|
|
589
|
-
return await this.paginate(pageSize, pageNumber);
|
|
590
|
-
}
|
|
591
|
-
finally {
|
|
592
|
-
this.engineFlag = prev;
|
|
593
|
-
}
|
|
525
|
+
return await this.paginate(pageSize, pageNumber);
|
|
594
526
|
}
|
|
595
527
|
/**
|
|
596
528
|
* Subscribes to paginated results updates.
|
|
@@ -621,65 +553,54 @@ export class ModelQueryBuilder {
|
|
|
621
553
|
* builder.dispose();
|
|
622
554
|
* ```
|
|
623
555
|
*
|
|
624
|
-
* @remarks
|
|
625
|
-
* By default, this uses SPARQL live queries for real-time updates.
|
|
626
|
-
* Prolog subscriptions remain available via `.useSPARQL(false)`.
|
|
627
556
|
*/
|
|
628
557
|
async paginateSubscribe(pageSize, pageNumber, callback) {
|
|
629
558
|
// Clean up any existing subscription
|
|
630
559
|
this.dispose();
|
|
631
|
-
const
|
|
632
|
-
|
|
633
|
-
|
|
634
|
-
|
|
635
|
-
|
|
636
|
-
|
|
637
|
-
|
|
638
|
-
|
|
639
|
-
|
|
640
|
-
|
|
641
|
-
|
|
642
|
-
|
|
643
|
-
|
|
644
|
-
|
|
645
|
-
|
|
646
|
-
|
|
647
|
-
|
|
648
|
-
};
|
|
649
|
-
|
|
650
|
-
|
|
651
|
-
|
|
652
|
-
|
|
653
|
-
|
|
654
|
-
|
|
655
|
-
|
|
656
|
-
|
|
657
|
-
|
|
658
|
-
|
|
659
|
-
|
|
660
|
-
|
|
661
|
-
|
|
662
|
-
|
|
663
|
-
|
|
664
|
-
|
|
665
|
-
|
|
666
|
-
|
|
667
|
-
|
|
668
|
-
|
|
669
|
-
}
|
|
560
|
+
const ctor = this.ctor;
|
|
561
|
+
// Subscribe to the full result set (no limit/offset) so the subscription
|
|
562
|
+
// detects changes anywhere in the dataset. Rust builds trigger SPARQL
|
|
563
|
+
// from the shape predicates.
|
|
564
|
+
const subscriptionParams = { ...(this.queryParams || {}) };
|
|
565
|
+
delete subscriptionParams.limit;
|
|
566
|
+
delete subscriptionParams.offset;
|
|
567
|
+
const { className, queryJson, shapeJson } = ctor.prepareModelQueryParams(subscriptionParams, this.modelClassName);
|
|
568
|
+
const { subscriptionId } = await this.perspective.modelSubscribe(className, queryJson, shapeJson);
|
|
569
|
+
// Build the paginated query for Rust endpoint (count: true fetches both results and totalCount in one call)
|
|
570
|
+
const paginatedQuery = {
|
|
571
|
+
...(this.queryParams || {}),
|
|
572
|
+
limit: pageSize,
|
|
573
|
+
offset: pageSize * (pageNumber - 1),
|
|
574
|
+
count: true,
|
|
575
|
+
};
|
|
576
|
+
const processResults = async () => {
|
|
577
|
+
const { results, totalCount } = await ctor.executeModelQuery(this.perspective, paginatedQuery, this.modelClassName);
|
|
578
|
+
callback({ results, totalCount, pageSize, pageNumber });
|
|
579
|
+
};
|
|
580
|
+
const unsubscribe = this.perspective.client.subscribeToQueryUpdates(subscriptionId, (rawResult) => {
|
|
581
|
+
if (rawResult && rawResult.isInit)
|
|
582
|
+
return;
|
|
583
|
+
processResults().catch(e => console.error('Paginate subscription error:', e));
|
|
584
|
+
});
|
|
585
|
+
const keepaliveTimer = setInterval(() => {
|
|
586
|
+
this.perspective.client.keepAliveQuery(this.perspective.uuid, subscriptionId).catch(() => { });
|
|
587
|
+
}, 30000);
|
|
588
|
+
this.currentSubscription = {
|
|
589
|
+
dispose: () => {
|
|
590
|
+
clearInterval(keepaliveTimer);
|
|
591
|
+
unsubscribe();
|
|
592
|
+
this.perspective.client.disposeQuerySubscription(this.perspective.uuid, subscriptionId).catch(() => { });
|
|
593
|
+
},
|
|
594
|
+
};
|
|
595
|
+
// Initial fetch (single call with count: true)
|
|
596
|
+
const { results, totalCount } = await ctor.executeModelQuery(this.perspective, paginatedQuery, this.modelClassName);
|
|
597
|
+
return { results, totalCount, pageSize, pageNumber };
|
|
670
598
|
}
|
|
671
599
|
/**
|
|
672
600
|
* Subscribes to paginated results updates using SPARQL.
|
|
673
|
-
* Delegates to paginateSubscribe()
|
|
601
|
+
* Delegates to paginateSubscribe().
|
|
674
602
|
*/
|
|
675
603
|
async paginateSubscribeSparql(pageSize, pageNumber, callback) {
|
|
676
|
-
|
|
677
|
-
this.engineFlag = 'sparql';
|
|
678
|
-
try {
|
|
679
|
-
return await this.paginateSubscribe(pageSize, pageNumber, callback);
|
|
680
|
-
}
|
|
681
|
-
finally {
|
|
682
|
-
this.engineFlag = prev;
|
|
683
|
-
}
|
|
604
|
+
return await this.paginateSubscribe(pageSize, pageNumber, callback);
|
|
684
605
|
}
|
|
685
606
|
}
|
|
@@ -135,6 +135,28 @@ export interface PropertyOptions {
|
|
|
135
135
|
* The function takes the raw value as input and returns the transformed value.
|
|
136
136
|
*/
|
|
137
137
|
transform?: (value: any) => any;
|
|
138
|
+
/**
|
|
139
|
+
* Allowed values for this property (enum constraint).
|
|
140
|
+
* Maps to SHACL `sh:in`. Each entry has a `value` (the stored RDF term)
|
|
141
|
+
* and an optional `label` (human-readable display name).
|
|
142
|
+
*
|
|
143
|
+
* @example
|
|
144
|
+
* ```typescript
|
|
145
|
+
* @Property({
|
|
146
|
+
* through: "task://status",
|
|
147
|
+
* options: [
|
|
148
|
+
* { value: "task://todo", label: "To Do" },
|
|
149
|
+
* { value: "task://doing", label: "Doing" },
|
|
150
|
+
* { value: "task://done", label: "Done" },
|
|
151
|
+
* ]
|
|
152
|
+
* })
|
|
153
|
+
* status: string = "task://todo";
|
|
154
|
+
* ```
|
|
155
|
+
*/
|
|
156
|
+
options?: Array<{
|
|
157
|
+
value: string;
|
|
158
|
+
label?: string;
|
|
159
|
+
}>;
|
|
138
160
|
}
|
|
139
161
|
/**
|
|
140
162
|
* Convenience decorator for defining optional (not required) properties.
|
|
@@ -521,8 +521,15 @@ function resolveRelationArgs(first, second) {
|
|
|
521
521
|
return opts;
|
|
522
522
|
}
|
|
523
523
|
export function HasMany(first, second) {
|
|
524
|
+
const explicitThrough = typeof first === 'function' ? second?.through : first.through;
|
|
524
525
|
const opts = resolveRelationArgs(first, second);
|
|
525
526
|
return function (target, key) {
|
|
527
|
+
if (!explicitThrough && !opts.getter) {
|
|
528
|
+
const className = (target.constructor?.name) ?? 'unknown';
|
|
529
|
+
console.warn(`@HasMany on ${className}.${String(key)} has no 'through' predicate — defaulting to 'ad4m://has_child'. ` +
|
|
530
|
+
`Add { through: 'ad4m://has_child' } to silence this warning, or use a semantic predicate ` +
|
|
531
|
+
`like { through: 'myns://has_${String(key)}' } for efficient targeted queries.`);
|
|
532
|
+
}
|
|
526
533
|
// --- relation registry ---
|
|
527
534
|
const ctor = target.constructor;
|
|
528
535
|
if (!relationRegistry.has(ctor))
|