@coasys/ad4m 0.13.0-test-2 → 0.13.0-test-4
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/README.md +2 -25
- package/jest-setup.ts +1 -1
- package/lib/index.cjs +2805 -10556
- package/lib/index.js +2513 -10322
- 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 -2
- package/lib/src/index.js +6 -2
- 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 +26 -214
- package/lib/src/language/Language.js +32 -72
- 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 +81 -38
- package/lib/src/model/Ad4mModel.js +651 -408
- package/lib/src/model/Ad4mModel.test.js +488 -750
- package/lib/src/model/ModelQueryBuilder.d.ts +28 -21
- package/lib/src/model/ModelQueryBuilder.js +160 -195
- package/lib/src/model/decorators.d.ts +22 -0
- package/lib/src/model/decorators.js +7 -0
- package/lib/src/model/hydration-batching.test.d.ts +7 -0
- package/lib/src/model/hydration-batching.test.js +456 -0
- package/lib/src/model/hydration.d.ts +8 -60
- package/lib/src/model/hydration.js +41 -541
- 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 +36 -22
- package/lib/src/model/query-sparql.js +188 -53
- package/lib/src/model/query-sparql.test.d.ts +1 -0
- package/lib/src/model/query-sparql.test.js +312 -0
- package/lib/src/model/query-utils.js +4 -0
- package/lib/src/model/shacl-gen.js +4 -0
- package/lib/src/model/subscription-delta.test.d.ts +24 -0
- package/lib/src/model/subscription-delta.test.js +180 -0
- package/lib/src/model/subscription-pool.js +48 -2
- package/lib/src/model/types.d.ts +58 -1
- 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 -15
- package/lib/src/perspectives/PerspectiveClient.js +168 -400
- package/lib/src/perspectives/PerspectiveClient.test.d.ts +1 -0
- package/lib/src/perspectives/PerspectiveClient.test.js +224 -0
- package/lib/src/perspectives/PerspectiveDiff.js +4 -31
- package/lib/src/perspectives/PerspectiveHandle.js +3 -43
- package/lib/src/perspectives/PerspectiveProxy.d.ts +95 -71
- package/lib/src/perspectives/PerspectiveProxy.js +288 -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 +1182 -1288
- 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 -2
- package/src/jestSetup.ts +1 -1
- package/src/language/Icon.ts +0 -4
- package/src/language/Language.ts +50 -292
- 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 +827 -808
- package/src/model/Ad4mModel.ts +676 -457
- package/src/model/ModelQueryBuilder.ts +199 -217
- package/src/model/decorators.ts +29 -0
- package/src/model/hydration.ts +17 -572
- package/src/model/index.ts +0 -4
- package/src/model/query-sparql.test.ts +360 -0
- package/src/model/query-sparql.ts +203 -56
- package/src/model/query-utils.ts +4 -0
- package/src/model/shacl-gen.ts +5 -0
- package/src/model/types.ts +62 -1
- 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 +262 -0
- package/src/perspectives/PerspectiveClient.ts +227 -412
- 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 +325 -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/lib/src/model/query-surreal.d.ts +0 -44
- package/lib/src/model/query-surreal.js +0 -249
- package/lib/src/model/surreal-utils.d.ts +0 -42
- package/lib/src/model/surreal-utils.js +0 -128
- 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/LanguageContext.ts +0 -37
- 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/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-pool.ts +0 -163
- 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
- package/tsconfig-browser.json +0 -82
|
@@ -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
|
*
|
|
@@ -158,6 +157,25 @@ export declare class ModelQueryBuilder<T extends Ad4mModel> {
|
|
|
158
157
|
* ```
|
|
159
158
|
*/
|
|
160
159
|
properties(properties: string[]): ModelQueryBuilder<T>;
|
|
160
|
+
/**
|
|
161
|
+
* Opts in to evaluating SPARQL property getters during collection hydration.
|
|
162
|
+
*
|
|
163
|
+
* By default, collection queries skip getter evaluation for performance.
|
|
164
|
+
* Call `.deepQuery()` when you need getter-backed properties in the result set.
|
|
165
|
+
*
|
|
166
|
+
* @returns The query builder for chaining
|
|
167
|
+
*
|
|
168
|
+
* @example
|
|
169
|
+
* ```typescript
|
|
170
|
+
* const messages = await Message.query(perspective)
|
|
171
|
+
* .parent(channel)
|
|
172
|
+
* .deepQuery()
|
|
173
|
+
* .limit(30)
|
|
174
|
+
* .get();
|
|
175
|
+
* // messages[i].replyingTo is populated
|
|
176
|
+
* ```
|
|
177
|
+
*/
|
|
178
|
+
deepQuery(): ModelQueryBuilder<T>;
|
|
161
179
|
/**
|
|
162
180
|
* Specifies which relations to eager-load (hydrate into model instances).
|
|
163
181
|
*
|
|
@@ -188,8 +206,9 @@ export declare class ModelQueryBuilder<T extends Ad4mModel> {
|
|
|
188
206
|
overrideModelClassName(className: string): ModelQueryBuilder<T>;
|
|
189
207
|
/**
|
|
190
208
|
* Sets the query engine to use.
|
|
209
|
+
* @deprecated Prolog engine has been removed. All queries use SPARQL/Rust.
|
|
191
210
|
*/
|
|
192
|
-
engine(
|
|
211
|
+
engine(_eng: 'sparql' | 'prolog'): ModelQueryBuilder<T>;
|
|
193
212
|
/**
|
|
194
213
|
* Executes the query once and returns the results.
|
|
195
214
|
*
|
|
@@ -208,14 +227,9 @@ export declare class ModelQueryBuilder<T extends Ad4mModel> {
|
|
|
208
227
|
*/
|
|
209
228
|
getSparql(): Promise<T[]>;
|
|
210
229
|
/**
|
|
211
|
-
* Shared
|
|
230
|
+
* Shared query execution logic — routes through the executor-side modelQuery endpoint.
|
|
212
231
|
*/
|
|
213
232
|
private executeSparqlQuery;
|
|
214
|
-
/**
|
|
215
|
-
* Groups raw SPARQL results and hydrates them into model instances.
|
|
216
|
-
* Centralises the repeated groupSPARQLResults → instancesFromQueryResult pipeline.
|
|
217
|
-
*/
|
|
218
|
-
private processSparqlResult;
|
|
219
233
|
/**
|
|
220
234
|
* Returns the first matching instance, or `null` if none match.
|
|
221
235
|
*
|
|
@@ -258,13 +272,11 @@ export declare class ModelQueryBuilder<T extends Ad4mModel> {
|
|
|
258
272
|
* builder.dispose();
|
|
259
273
|
* ```
|
|
260
274
|
*
|
|
261
|
-
* @remarks
|
|
262
|
-
* By default, this uses SPARQL live queries for real-time updates.
|
|
263
|
-
* Prolog subscriptions remain available via `.useSPARQL(false)`.
|
|
264
275
|
*/
|
|
265
276
|
subscribe(callback: (results: T[]) => void): Promise<T[]>;
|
|
266
277
|
/**
|
|
267
278
|
* Subscribes to the query and receives updates using SPARQL.
|
|
279
|
+
* @deprecated Use subscribe() instead — now routes through Rust model subscription.
|
|
268
280
|
*/
|
|
269
281
|
subscribeSparql(callback: (results: T[]) => void): Promise<T[]>;
|
|
270
282
|
/**
|
|
@@ -282,7 +294,7 @@ export declare class ModelQueryBuilder<T extends Ad4mModel> {
|
|
|
282
294
|
count(): Promise<number>;
|
|
283
295
|
/**
|
|
284
296
|
* Gets the total count of matching entities using SPARQL.
|
|
285
|
-
* Delegates to count()
|
|
297
|
+
* Delegates to count().
|
|
286
298
|
*/
|
|
287
299
|
countSparql(): Promise<number>;
|
|
288
300
|
/**
|
|
@@ -312,13 +324,11 @@ export declare class ModelQueryBuilder<T extends Ad4mModel> {
|
|
|
312
324
|
* builder.dispose();
|
|
313
325
|
* ```
|
|
314
326
|
*
|
|
315
|
-
* @remarks
|
|
316
|
-
* By default, this uses SPARQL live queries for real-time updates.
|
|
317
|
-
* Prolog subscriptions remain available via `.useSPARQL(false)`.
|
|
318
327
|
*/
|
|
319
328
|
countSubscribe(callback: (count: number) => void): Promise<number>;
|
|
320
329
|
/**
|
|
321
330
|
* Subscribes to count updates using SPARQL.
|
|
331
|
+
* @deprecated Use countSubscribe() instead — now routes through Rust model subscription.
|
|
322
332
|
*/
|
|
323
333
|
countSubscribeSparql(callback: (count: number) => void): Promise<number>;
|
|
324
334
|
/**
|
|
@@ -339,7 +349,7 @@ export declare class ModelQueryBuilder<T extends Ad4mModel> {
|
|
|
339
349
|
paginate(pageSize: number, pageNumber: number): Promise<PaginationResult<T>>;
|
|
340
350
|
/**
|
|
341
351
|
* Gets a page of results using SPARQL.
|
|
342
|
-
* Delegates to paginate()
|
|
352
|
+
* Delegates to paginate().
|
|
343
353
|
*/
|
|
344
354
|
paginateSparql(pageSize: number, pageNumber: number): Promise<PaginationResult<T>>;
|
|
345
355
|
/**
|
|
@@ -371,14 +381,11 @@ export declare class ModelQueryBuilder<T extends Ad4mModel> {
|
|
|
371
381
|
* builder.dispose();
|
|
372
382
|
* ```
|
|
373
383
|
*
|
|
374
|
-
* @remarks
|
|
375
|
-
* By default, this uses SPARQL live queries for real-time updates.
|
|
376
|
-
* Prolog subscriptions remain available via `.useSPARQL(false)`.
|
|
377
384
|
*/
|
|
378
385
|
paginateSubscribe(pageSize: number, pageNumber: number, callback: (results: PaginationResult<T>) => void): Promise<PaginationResult<T>>;
|
|
379
386
|
/**
|
|
380
387
|
* Subscribes to paginated results updates using SPARQL.
|
|
381
|
-
* Delegates to paginateSubscribe()
|
|
388
|
+
* Delegates to paginateSubscribe().
|
|
382
389
|
*/
|
|
383
390
|
paginateSubscribeSparql(pageSize: number, pageNumber: number, callback: (results: PaginationResult<T>) => void): Promise<PaginationResult<T>>;
|
|
384
391
|
}
|
|
@@ -4,8 +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 } from "./query-sparql";
|
|
8
|
-
import { pooledSubscribe } from "./subscription-pool";
|
|
9
7
|
/** Query builder for Ad4mModel queries.
|
|
10
8
|
* Allows building queries with a fluent interface and either running them once
|
|
11
9
|
* or subscribing to updates.
|
|
@@ -30,7 +28,6 @@ export class ModelQueryBuilder {
|
|
|
30
28
|
constructor(perspective, ctor, query) {
|
|
31
29
|
this.queryParams = {};
|
|
32
30
|
this.modelClassName = null;
|
|
33
|
-
this.engineFlag = 'sparql';
|
|
34
31
|
this.perspective = perspective;
|
|
35
32
|
this.ctor = ctor;
|
|
36
33
|
if (query)
|
|
@@ -41,7 +38,7 @@ export class ModelQueryBuilder {
|
|
|
41
38
|
*
|
|
42
39
|
* This method:
|
|
43
40
|
* 1. Stops the keepalive signals to the subscription
|
|
44
|
-
* 2. Unsubscribes from
|
|
41
|
+
* 2. Unsubscribes from subscription updates
|
|
45
42
|
* 3. Notifies the backend to clean up subscription resources
|
|
46
43
|
* 4. Clears the subscription reference
|
|
47
44
|
*
|
|
@@ -203,6 +200,28 @@ export class ModelQueryBuilder {
|
|
|
203
200
|
this.queryParams.properties = properties;
|
|
204
201
|
return this;
|
|
205
202
|
}
|
|
203
|
+
/**
|
|
204
|
+
* Opts in to evaluating SPARQL property getters during collection hydration.
|
|
205
|
+
*
|
|
206
|
+
* By default, collection queries skip getter evaluation for performance.
|
|
207
|
+
* Call `.deepQuery()` when you need getter-backed properties in the result set.
|
|
208
|
+
*
|
|
209
|
+
* @returns The query builder for chaining
|
|
210
|
+
*
|
|
211
|
+
* @example
|
|
212
|
+
* ```typescript
|
|
213
|
+
* const messages = await Message.query(perspective)
|
|
214
|
+
* .parent(channel)
|
|
215
|
+
* .deepQuery()
|
|
216
|
+
* .limit(30)
|
|
217
|
+
* .get();
|
|
218
|
+
* // messages[i].replyingTo is populated
|
|
219
|
+
* ```
|
|
220
|
+
*/
|
|
221
|
+
deepQuery() {
|
|
222
|
+
this.queryParams.deepQuery = true;
|
|
223
|
+
return this;
|
|
224
|
+
}
|
|
206
225
|
/**
|
|
207
226
|
* Specifies which relations to eager-load (hydrate into model instances).
|
|
208
227
|
*
|
|
@@ -239,9 +258,9 @@ export class ModelQueryBuilder {
|
|
|
239
258
|
}
|
|
240
259
|
/**
|
|
241
260
|
* Sets the query engine to use.
|
|
261
|
+
* @deprecated Prolog engine has been removed. All queries use SPARQL/Rust.
|
|
242
262
|
*/
|
|
243
|
-
engine(
|
|
244
|
-
this.engineFlag = eng;
|
|
263
|
+
engine(_eng) {
|
|
245
264
|
return this;
|
|
246
265
|
}
|
|
247
266
|
/**
|
|
@@ -257,16 +276,7 @@ export class ModelQueryBuilder {
|
|
|
257
276
|
* ```
|
|
258
277
|
*/
|
|
259
278
|
async get() {
|
|
260
|
-
|
|
261
|
-
if (this.engineFlag === 'sparql') {
|
|
262
|
-
results = await this.executeSparqlQuery();
|
|
263
|
-
}
|
|
264
|
-
else {
|
|
265
|
-
const query = await this.ctor.queryToProlog(this.perspective, this.queryParams, this.modelClassName);
|
|
266
|
-
const result = await this.perspective.infer(query);
|
|
267
|
-
({ results } = await this.ctor.instancesFromPrologResult(this.perspective, this.queryParams, result));
|
|
268
|
-
}
|
|
269
|
-
return results;
|
|
279
|
+
return await this.executeSparqlQuery();
|
|
270
280
|
}
|
|
271
281
|
/**
|
|
272
282
|
* Executes the query once using SPARQL and returns the results.
|
|
@@ -275,22 +285,12 @@ export class ModelQueryBuilder {
|
|
|
275
285
|
return this.executeSparqlQuery();
|
|
276
286
|
}
|
|
277
287
|
/**
|
|
278
|
-
* Shared
|
|
288
|
+
* Shared query execution logic — routes through the executor-side modelQuery endpoint.
|
|
279
289
|
*/
|
|
280
290
|
async executeSparqlQuery() {
|
|
281
|
-
const
|
|
282
|
-
const rawResult = await this.perspective.querySparql(sparqlQuery);
|
|
283
|
-
const { results } = await this.processSparqlResult(rawResult);
|
|
291
|
+
const { results } = await this.ctor.executeModelQuery(this.perspective, this.queryParams, this.modelClassName);
|
|
284
292
|
return results;
|
|
285
293
|
}
|
|
286
|
-
/**
|
|
287
|
-
* Groups raw SPARQL results and hydrates them into model instances.
|
|
288
|
-
* Centralises the repeated groupSPARQLResults → instancesFromQueryResult pipeline.
|
|
289
|
-
*/
|
|
290
|
-
async processSparqlResult(rawResult, queryOverride) {
|
|
291
|
-
const grouped = groupSPARQLResults(Array.isArray(rawResult) ? rawResult : []);
|
|
292
|
-
return await this.ctor.instancesFromQueryResult(this.perspective, queryOverride || this.queryParams, grouped);
|
|
293
|
-
}
|
|
294
294
|
/**
|
|
295
295
|
* Returns the first matching instance, or `null` if none match.
|
|
296
296
|
*
|
|
@@ -337,70 +337,74 @@ export class ModelQueryBuilder {
|
|
|
337
337
|
* builder.dispose();
|
|
338
338
|
* ```
|
|
339
339
|
*
|
|
340
|
-
* @remarks
|
|
341
|
-
* By default, this uses SPARQL live queries for real-time updates.
|
|
342
|
-
* Prolog subscriptions remain available via `.useSPARQL(false)`.
|
|
343
340
|
*/
|
|
344
341
|
async subscribe(callback) {
|
|
345
342
|
// Clean up any existing subscription
|
|
346
343
|
this.dispose();
|
|
347
344
|
const ctor = this.ctor;
|
|
348
|
-
|
|
349
|
-
|
|
350
|
-
|
|
351
|
-
|
|
352
|
-
|
|
353
|
-
|
|
354
|
-
|
|
355
|
-
|
|
356
|
-
|
|
357
|
-
|
|
358
|
-
|
|
359
|
-
|
|
360
|
-
|
|
361
|
-
|
|
362
|
-
|
|
363
|
-
|
|
364
|
-
|
|
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);
|
|
365
375
|
if (fp === lastResultFingerprint)
|
|
366
376
|
return;
|
|
367
377
|
lastResultFingerprint = fp;
|
|
368
|
-
callback(hydratedResults);
|
|
369
|
-
});
|
|
370
|
-
// Store dispose function as subscription
|
|
371
|
-
this.currentSubscription = { dispose: pooled.dispose };
|
|
372
|
-
const initialResults = pooled.initialResult;
|
|
373
|
-
lastResultFingerprint = buildFingerprint(initialResults);
|
|
374
|
-
return initialResults;
|
|
375
|
-
}
|
|
376
|
-
else {
|
|
377
|
-
const query = await ctor.queryToProlog(this.perspective, this.queryParams, this.modelClassName);
|
|
378
|
-
this.currentSubscription = await this.perspective.subscribeInfer(query);
|
|
379
|
-
const processResults = async (result) => {
|
|
380
|
-
const { results } = await ctor.instancesFromPrologResult(this.perspective, this.queryParams, result);
|
|
381
378
|
callback(results);
|
|
382
|
-
}
|
|
383
|
-
|
|
384
|
-
|
|
385
|
-
|
|
386
|
-
|
|
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);
|
|
387
399
|
}
|
|
400
|
+
return initialResults;
|
|
388
401
|
}
|
|
389
402
|
/**
|
|
390
403
|
* Subscribes to the query and receives updates using SPARQL.
|
|
404
|
+
* @deprecated Use subscribe() instead — now routes through Rust model subscription.
|
|
391
405
|
*/
|
|
392
406
|
async subscribeSparql(callback) {
|
|
393
|
-
this.
|
|
394
|
-
const sparqlQuery = await this.ctor.queryToSPARQL(this.perspective, this.queryParams);
|
|
395
|
-
this.currentSubscription = await this.perspective.subscribeQuery(sparqlQuery);
|
|
396
|
-
const processResults = async (result) => {
|
|
397
|
-
const { results } = await this.processSparqlResult(result);
|
|
398
|
-
callback(results);
|
|
399
|
-
};
|
|
400
|
-
this.currentSubscription.onResult(processResults);
|
|
401
|
-
const { results } = await this.processSparqlResult(this.currentSubscription.result);
|
|
402
|
-
// Initial results returned via Promise only — callback is for subsequent updates
|
|
403
|
-
return results;
|
|
407
|
+
return this.subscribe(callback);
|
|
404
408
|
}
|
|
405
409
|
/**
|
|
406
410
|
* Gets the total count of matching entities.
|
|
@@ -415,31 +419,15 @@ export class ModelQueryBuilder {
|
|
|
415
419
|
* ```
|
|
416
420
|
*/
|
|
417
421
|
async count() {
|
|
418
|
-
|
|
419
|
-
|
|
420
|
-
const rawResult = await this.perspective.querySparql(sparqlQuery);
|
|
421
|
-
const { totalCount } = await this.processSparqlResult(rawResult);
|
|
422
|
-
return totalCount;
|
|
423
|
-
}
|
|
424
|
-
else {
|
|
425
|
-
const query = await this.ctor.countQueryToProlog(this.perspective, this.queryParams, this.modelClassName);
|
|
426
|
-
const result = await this.perspective.infer(query);
|
|
427
|
-
return result?.[0]?.TotalCount || 0;
|
|
428
|
-
}
|
|
422
|
+
const { totalCount } = await this.ctor.executeModelQuery(this.perspective, { ...this.queryParams, limit: 0 }, this.modelClassName);
|
|
423
|
+
return totalCount;
|
|
429
424
|
}
|
|
430
425
|
/**
|
|
431
426
|
* Gets the total count of matching entities using SPARQL.
|
|
432
|
-
* Delegates to count()
|
|
427
|
+
* Delegates to count().
|
|
433
428
|
*/
|
|
434
429
|
async countSparql() {
|
|
435
|
-
|
|
436
|
-
this.engineFlag = 'sparql';
|
|
437
|
-
try {
|
|
438
|
-
return await this.count();
|
|
439
|
-
}
|
|
440
|
-
finally {
|
|
441
|
-
this.engineFlag = prev;
|
|
442
|
-
}
|
|
430
|
+
return await this.count();
|
|
443
431
|
}
|
|
444
432
|
/**
|
|
445
433
|
* Subscribes to count updates for matching entities.
|
|
@@ -468,53 +456,46 @@ export class ModelQueryBuilder {
|
|
|
468
456
|
* builder.dispose();
|
|
469
457
|
* ```
|
|
470
458
|
*
|
|
471
|
-
* @remarks
|
|
472
|
-
* By default, this uses SPARQL live queries for real-time updates.
|
|
473
|
-
* Prolog subscriptions remain available via `.useSPARQL(false)`.
|
|
474
459
|
*/
|
|
475
460
|
async countSubscribe(callback) {
|
|
476
461
|
// Clean up any existing subscription
|
|
477
462
|
this.dispose();
|
|
478
|
-
|
|
479
|
-
|
|
480
|
-
|
|
481
|
-
|
|
482
|
-
|
|
483
|
-
|
|
484
|
-
|
|
485
|
-
|
|
486
|
-
|
|
487
|
-
|
|
488
|
-
|
|
489
|
-
|
|
490
|
-
|
|
491
|
-
|
|
492
|
-
|
|
493
|
-
|
|
494
|
-
|
|
495
|
-
|
|
496
|
-
|
|
497
|
-
this.
|
|
498
|
-
|
|
499
|
-
|
|
500
|
-
|
|
501
|
-
|
|
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;
|
|
502
492
|
}
|
|
503
493
|
/**
|
|
504
494
|
* Subscribes to count updates using SPARQL.
|
|
495
|
+
* @deprecated Use countSubscribe() instead — now routes through Rust model subscription.
|
|
505
496
|
*/
|
|
506
497
|
async countSubscribeSparql(callback) {
|
|
507
|
-
this.
|
|
508
|
-
const sparqlQuery = await this.ctor.queryToSPARQL(this.perspective, this.queryParams);
|
|
509
|
-
this.currentSubscription = await this.perspective.subscribeQuery(sparqlQuery);
|
|
510
|
-
const processResults = async (result) => {
|
|
511
|
-
const { totalCount } = await this.processSparqlResult(result);
|
|
512
|
-
callback(totalCount);
|
|
513
|
-
};
|
|
514
|
-
this.currentSubscription.onResult(processResults);
|
|
515
|
-
const { totalCount } = await this.processSparqlResult(this.currentSubscription.result);
|
|
516
|
-
// Initial count returned via Promise — callback for updates only
|
|
517
|
-
return totalCount;
|
|
498
|
+
return this.countSubscribe(callback);
|
|
518
499
|
}
|
|
519
500
|
/**
|
|
520
501
|
* Gets a page of results with pagination metadata.
|
|
@@ -533,32 +514,15 @@ export class ModelQueryBuilder {
|
|
|
533
514
|
*/
|
|
534
515
|
async paginate(pageSize, pageNumber) {
|
|
535
516
|
const paginationQuery = { ...(this.queryParams || {}), limit: pageSize, offset: pageSize * (pageNumber - 1), count: true };
|
|
536
|
-
|
|
537
|
-
|
|
538
|
-
const result = await this.perspective.querySparql(sparqlQuery);
|
|
539
|
-
const { results, totalCount } = await this.processSparqlResult(result, paginationQuery);
|
|
540
|
-
return { results, totalCount, pageSize, pageNumber };
|
|
541
|
-
}
|
|
542
|
-
else {
|
|
543
|
-
const prologQuery = await this.ctor.queryToProlog(this.perspective, paginationQuery, this.modelClassName);
|
|
544
|
-
const result = await this.perspective.infer(prologQuery);
|
|
545
|
-
const { results, totalCount } = (await this.ctor.instancesFromPrologResult(this.perspective, paginationQuery, result));
|
|
546
|
-
return { results, totalCount, pageSize, pageNumber };
|
|
547
|
-
}
|
|
517
|
+
const { results, totalCount } = await this.ctor.executeModelQuery(this.perspective, paginationQuery, this.modelClassName);
|
|
518
|
+
return { results, totalCount, pageSize, pageNumber };
|
|
548
519
|
}
|
|
549
520
|
/**
|
|
550
521
|
* Gets a page of results using SPARQL.
|
|
551
|
-
* Delegates to paginate()
|
|
522
|
+
* Delegates to paginate().
|
|
552
523
|
*/
|
|
553
524
|
async paginateSparql(pageSize, pageNumber) {
|
|
554
|
-
|
|
555
|
-
this.engineFlag = 'sparql';
|
|
556
|
-
try {
|
|
557
|
-
return await this.paginate(pageSize, pageNumber);
|
|
558
|
-
}
|
|
559
|
-
finally {
|
|
560
|
-
this.engineFlag = prev;
|
|
561
|
-
}
|
|
525
|
+
return await this.paginate(pageSize, pageNumber);
|
|
562
526
|
}
|
|
563
527
|
/**
|
|
564
528
|
* Subscribes to paginated results updates.
|
|
@@ -589,53 +553,54 @@ export class ModelQueryBuilder {
|
|
|
589
553
|
* builder.dispose();
|
|
590
554
|
* ```
|
|
591
555
|
*
|
|
592
|
-
* @remarks
|
|
593
|
-
* By default, this uses SPARQL live queries for real-time updates.
|
|
594
|
-
* Prolog subscriptions remain available via `.useSPARQL(false)`.
|
|
595
556
|
*/
|
|
596
557
|
async paginateSubscribe(pageSize, pageNumber, callback) {
|
|
597
558
|
// Clean up any existing subscription
|
|
598
559
|
this.dispose();
|
|
599
|
-
const
|
|
600
|
-
|
|
601
|
-
|
|
602
|
-
|
|
603
|
-
|
|
604
|
-
|
|
605
|
-
|
|
606
|
-
|
|
607
|
-
|
|
608
|
-
|
|
609
|
-
|
|
610
|
-
|
|
611
|
-
|
|
612
|
-
|
|
613
|
-
|
|
614
|
-
|
|
615
|
-
|
|
616
|
-
const
|
|
617
|
-
|
|
618
|
-
|
|
619
|
-
|
|
620
|
-
|
|
621
|
-
|
|
622
|
-
|
|
623
|
-
|
|
624
|
-
|
|
625
|
-
|
|
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 };
|
|
626
598
|
}
|
|
627
599
|
/**
|
|
628
600
|
* Subscribes to paginated results updates using SPARQL.
|
|
629
|
-
* Delegates to paginateSubscribe()
|
|
601
|
+
* Delegates to paginateSubscribe().
|
|
630
602
|
*/
|
|
631
603
|
async paginateSubscribeSparql(pageSize, pageNumber, callback) {
|
|
632
|
-
|
|
633
|
-
this.engineFlag = 'sparql';
|
|
634
|
-
try {
|
|
635
|
-
return await this.paginateSubscribe(pageSize, pageNumber, callback);
|
|
636
|
-
}
|
|
637
|
-
finally {
|
|
638
|
-
this.engineFlag = prev;
|
|
639
|
-
}
|
|
604
|
+
return await this.paginateSubscribe(pageSize, pageNumber, callback);
|
|
640
605
|
}
|
|
641
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))
|