@coasys/ad4m 0.13.0-test-3 → 0.13.0-test-5
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 +6717 -15519
- package/lib/index.js +4811 -13662
- package/lib/src/Ad4mClient.d.ts +7 -3
- package/lib/src/Ad4mClient.js +39 -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 +76 -44
- package/lib/src/model/Ad4mModel.js +635 -479
- package/lib/src/model/Ad4mModel.test.js +371 -815
- package/lib/src/model/ModelQueryBuilder.d.ts +15 -27
- package/lib/src/model/ModelQueryBuilder.js +163 -224
- package/lib/src/model/decorators.d.ts +22 -0
- package/lib/src/model/decorators.js +7 -0
- package/lib/src/model/hydration.d.ts +3 -93
- package/lib/src/model/hydration.js +3 -970
- 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/query-utils.d.ts +1 -0
- package/lib/src/model/query-utils.js +46 -1
- package/lib/src/model/shacl-gen.js +4 -0
- package/lib/src/model/types.d.ts +51 -43
- 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 +13 -17
- package/lib/src/perspectives/PerspectiveClient.js +179 -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 +106 -71
- package/lib/src/perspectives/PerspectiveProxy.js +289 -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 +6 -18
- package/rollup.config.js +0 -7
- package/src/Ad4mClient.test.ts +1179 -1340
- package/src/Ad4mClient.ts +40 -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 +766 -1173
- package/src/model/Ad4mModel.ts +664 -529
- package/src/model/ModelQueryBuilder.ts +203 -251
- package/src/model/decorators.ts +29 -0
- package/src/model/hydration.ts +3 -1037
- 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/query-utils.ts +47 -2
- package/src/model/shacl-gen.ts +5 -0
- package/src/model/types.ts +55 -44
- 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 +247 -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 +331 -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
|
@@ -9,11 +9,8 @@ import type { Ad4mModel } from "./Ad4mModel";
|
|
|
9
9
|
import type { PerspectiveProxy } from "../perspectives/PerspectiveProxy";
|
|
10
10
|
import type {
|
|
11
11
|
Where, Order, IncludeMap, Query,
|
|
12
|
-
|
|
12
|
+
ResultsWithTotalCount, PaginationResult,
|
|
13
13
|
} from "./types";
|
|
14
|
-
import { groupSPARQLResults, hasJsOnlyWhereFilters, parseSparqlCount } from "./query-sparql";
|
|
15
|
-
import { getRelationsMetadata } from "./decorators";
|
|
16
|
-
import { pooledSubscribe } from "./subscription-pool";
|
|
17
14
|
|
|
18
15
|
/** Query builder for Ad4mModel queries.
|
|
19
16
|
* Allows building queries with a fluent interface and either running them once
|
|
@@ -41,7 +38,6 @@ export class ModelQueryBuilder<T extends Ad4mModel> {
|
|
|
41
38
|
private modelClassName: string | null = null;
|
|
42
39
|
private ctor: typeof Ad4mModel;
|
|
43
40
|
private currentSubscription?: any;
|
|
44
|
-
private engineFlag: 'sparql' | 'prolog' = 'sparql';
|
|
45
41
|
|
|
46
42
|
constructor(perspective: PerspectiveProxy, ctor: typeof Ad4mModel, query?: Query) {
|
|
47
43
|
this.perspective = perspective;
|
|
@@ -54,7 +50,7 @@ export class ModelQueryBuilder<T extends Ad4mModel> {
|
|
|
54
50
|
*
|
|
55
51
|
* This method:
|
|
56
52
|
* 1. Stops the keepalive signals to the subscription
|
|
57
|
-
* 2. Unsubscribes from
|
|
53
|
+
* 2. Unsubscribes from subscription updates
|
|
58
54
|
* 3. Notifies the backend to clean up subscription resources
|
|
59
55
|
* 4. Clears the subscription reference
|
|
60
56
|
*
|
|
@@ -228,25 +224,25 @@ export class ModelQueryBuilder<T extends Ad4mModel> {
|
|
|
228
224
|
}
|
|
229
225
|
|
|
230
226
|
/**
|
|
231
|
-
*
|
|
227
|
+
* Controls whether SPARQL property getters are evaluated during hydration.
|
|
232
228
|
*
|
|
233
|
-
* By default, collection queries
|
|
234
|
-
* Call `.deepQuery()`
|
|
229
|
+
* By default, collection queries evaluate property getters (deepQuery=true).
|
|
230
|
+
* Call `.deepQuery(false)` to skip getter evaluation for performance.
|
|
235
231
|
*
|
|
232
|
+
* @param enabled - Whether to evaluate property getters (default: true)
|
|
236
233
|
* @returns The query builder for chaining
|
|
237
234
|
*
|
|
238
235
|
* @example
|
|
239
236
|
* ```typescript
|
|
240
237
|
* const messages = await Message.query(perspective)
|
|
241
238
|
* .parent(channel)
|
|
242
|
-
* .deepQuery()
|
|
239
|
+
* .deepQuery(false) // skip property getters for performance
|
|
243
240
|
* .limit(30)
|
|
244
241
|
* .get();
|
|
245
|
-
* // messages[i].replyingTo is populated
|
|
246
242
|
* ```
|
|
247
243
|
*/
|
|
248
|
-
deepQuery(): ModelQueryBuilder<T> {
|
|
249
|
-
|
|
244
|
+
deepQuery(enabled: boolean = true): ModelQueryBuilder<T> {
|
|
245
|
+
this.queryParams.deepQuery = enabled;
|
|
250
246
|
return this;
|
|
251
247
|
}
|
|
252
248
|
|
|
@@ -288,9 +284,9 @@ export class ModelQueryBuilder<T extends Ad4mModel> {
|
|
|
288
284
|
|
|
289
285
|
/**
|
|
290
286
|
* Sets the query engine to use.
|
|
287
|
+
* @deprecated Prolog engine has been removed. All queries use SPARQL/Rust.
|
|
291
288
|
*/
|
|
292
|
-
engine(
|
|
293
|
-
this.engineFlag = eng;
|
|
289
|
+
engine(_eng: 'sparql' | 'prolog'): ModelQueryBuilder<T> {
|
|
294
290
|
return this;
|
|
295
291
|
}
|
|
296
292
|
|
|
@@ -307,16 +303,7 @@ export class ModelQueryBuilder<T extends Ad4mModel> {
|
|
|
307
303
|
* ```
|
|
308
304
|
*/
|
|
309
305
|
async get(): Promise<T[]> {
|
|
310
|
-
|
|
311
|
-
if (this.engineFlag === 'sparql') {
|
|
312
|
-
results = await this.executeSparqlQuery();
|
|
313
|
-
} else {
|
|
314
|
-
const query = await this.ctor.queryToProlog(this.perspective, this.queryParams, this.modelClassName);
|
|
315
|
-
const result = await this.perspective.infer(query);
|
|
316
|
-
({ results } = await this.ctor.instancesFromPrologResult(this.perspective, this.queryParams, result) as { results: T[] });
|
|
317
|
-
}
|
|
318
|
-
|
|
319
|
-
return results;
|
|
306
|
+
return await this.executeSparqlQuery();
|
|
320
307
|
}
|
|
321
308
|
|
|
322
309
|
/**
|
|
@@ -327,24 +314,13 @@ export class ModelQueryBuilder<T extends Ad4mModel> {
|
|
|
327
314
|
}
|
|
328
315
|
|
|
329
316
|
/**
|
|
330
|
-
* Shared
|
|
317
|
+
* Shared query execution logic — routes through the executor-side modelQuery endpoint.
|
|
331
318
|
*/
|
|
332
319
|
private async executeSparqlQuery(): Promise<T[]> {
|
|
333
|
-
const
|
|
334
|
-
const rawResult = await this.perspective.querySparql(sparqlQuery);
|
|
335
|
-
const { results } = await this.processSparqlResult(rawResult);
|
|
320
|
+
const { results } = await (this.ctor as any).executeModelQuery(this.perspective, this.queryParams, this.modelClassName);
|
|
336
321
|
return results;
|
|
337
322
|
}
|
|
338
323
|
|
|
339
|
-
/**
|
|
340
|
-
* Groups raw SPARQL results and hydrates them into model instances.
|
|
341
|
-
* Centralises the repeated groupSPARQLResults → instancesFromQueryResult pipeline.
|
|
342
|
-
*/
|
|
343
|
-
private async processSparqlResult(rawResult: any, queryOverride?: Query, computeTotalCount: boolean = false): Promise<{ results: T[], totalCount: number }> {
|
|
344
|
-
const grouped = groupSPARQLResults(Array.isArray(rawResult) ? rawResult : []);
|
|
345
|
-
return await this.ctor.instancesFromQueryResult(this.perspective, queryOverride || this.queryParams, grouped, computeTotalCount) as { results: T[], totalCount: number };
|
|
346
|
-
}
|
|
347
|
-
|
|
348
324
|
/**
|
|
349
325
|
* Returns the first matching instance, or `null` if none match.
|
|
350
326
|
*
|
|
@@ -392,9 +368,6 @@ export class ModelQueryBuilder<T extends Ad4mModel> {
|
|
|
392
368
|
* builder.dispose();
|
|
393
369
|
* ```
|
|
394
370
|
*
|
|
395
|
-
* @remarks
|
|
396
|
-
* By default, this uses SPARQL live queries for real-time updates.
|
|
397
|
-
* Prolog subscriptions remain available via `.useSPARQL(false)`.
|
|
398
371
|
*/
|
|
399
372
|
async subscribe(callback: (results: T[]) => void): Promise<T[]> {
|
|
400
373
|
// Clean up any existing subscription
|
|
@@ -402,83 +375,90 @@ export class ModelQueryBuilder<T extends Ad4mModel> {
|
|
|
402
375
|
|
|
403
376
|
const ctor = this.ctor;
|
|
404
377
|
|
|
405
|
-
|
|
406
|
-
|
|
407
|
-
|
|
408
|
-
|
|
409
|
-
let lastResultFingerprint: string | null = null;
|
|
410
|
-
|
|
411
|
-
const buildFingerprint = (results: any[]) => {
|
|
412
|
-
if (results.length === 0) return '0:';
|
|
413
|
-
// Must include relation data (e.g. tags) — not just id/timestamp.
|
|
414
|
-
// Otherwise @HasMany changes on existing instances are suppressed as duplicates.
|
|
415
|
-
return JSON.stringify(results, (_, v) =>
|
|
416
|
-
typeof v === 'function' ? undefined : v
|
|
417
|
-
);
|
|
418
|
-
};
|
|
419
|
-
|
|
420
|
-
const hydrate = async (rawResult: any) => {
|
|
421
|
-
const { results } = await this.processSparqlResult(rawResult);
|
|
422
|
-
return results;
|
|
423
|
-
};
|
|
424
|
-
|
|
425
|
-
const pooled = await pooledSubscribe(
|
|
426
|
-
this.perspective,
|
|
427
|
-
sparqlQuery,
|
|
428
|
-
hydrate,
|
|
429
|
-
(hydratedResults: T[]) => {
|
|
430
|
-
const fp = buildFingerprint(hydratedResults);
|
|
431
|
-
if (fp === lastResultFingerprint) return;
|
|
432
|
-
lastResultFingerprint = fp;
|
|
433
|
-
callback(hydratedResults);
|
|
434
|
-
},
|
|
435
|
-
);
|
|
378
|
+
// Build the model query params (className, queryJson, shapeJson)
|
|
379
|
+
const { className, queryJson, shapeJson } = (ctor as any).prepareModelQueryParams(
|
|
380
|
+
this.queryParams, this.modelClassName
|
|
381
|
+
);
|
|
436
382
|
|
|
437
|
-
|
|
438
|
-
|
|
383
|
+
// Register model subscription via Rust — this builds trigger SPARQL internally,
|
|
384
|
+
// registers the subscription, and runs the initial query in one call.
|
|
385
|
+
const { subscriptionId, result: initialModelResult } = await this.perspective.modelSubscribe(
|
|
386
|
+
className, queryJson, shapeJson
|
|
387
|
+
);
|
|
439
388
|
|
|
440
|
-
|
|
441
|
-
|
|
442
|
-
|
|
443
|
-
}
|
|
444
|
-
|
|
445
|
-
|
|
446
|
-
|
|
447
|
-
|
|
448
|
-
|
|
449
|
-
|
|
450
|
-
|
|
451
|
-
|
|
452
|
-
|
|
453
|
-
|
|
454
|
-
|
|
455
|
-
|
|
456
|
-
|
|
457
|
-
|
|
458
|
-
|
|
459
|
-
|
|
389
|
+
// Convert JSON instances to model class instances
|
|
390
|
+
const parseResults = (raw: any): T[] => {
|
|
391
|
+
return (ctor as any).parseModelResult(this.perspective, raw, this.queryParams.include, this.queryParams.properties);
|
|
392
|
+
};
|
|
393
|
+
|
|
394
|
+
// Parse initial results
|
|
395
|
+
const initialResults = parseResults(initialModelResult);
|
|
396
|
+
|
|
397
|
+
// Track last emitted result fingerprint to suppress duplicate callbacks
|
|
398
|
+
let lastResultFingerprint: string | null = null;
|
|
399
|
+
const buildFingerprint = (results: any[]) => {
|
|
400
|
+
if (results.length === 0) return '0:';
|
|
401
|
+
return JSON.stringify(results, (_, v) =>
|
|
402
|
+
typeof v === 'function' ? undefined : v
|
|
403
|
+
);
|
|
404
|
+
};
|
|
405
|
+
lastResultFingerprint = buildFingerprint(initialResults);
|
|
406
|
+
|
|
407
|
+
// Listen for subscription updates via the same GraphQL subscription channel.
|
|
408
|
+
// When Rust re-runs the model query and finds changed results, it pushes them.
|
|
409
|
+
const unsubscribe = this.perspective.client.subscribeToQueryUpdates(
|
|
410
|
+
subscriptionId,
|
|
411
|
+
(rawResult: any) => {
|
|
412
|
+
// Skip delayed #init# messages — initial data was already returned
|
|
413
|
+
// synchronously from modelSubscribe(). Late init messages contain stale
|
|
414
|
+
// data that would overwrite real subscription updates.
|
|
415
|
+
if (rawResult && rawResult.isInit) return;
|
|
416
|
+
try {
|
|
417
|
+
const results = parseResults(rawResult);
|
|
418
|
+
const fp = buildFingerprint(results);
|
|
419
|
+
if (fp === lastResultFingerprint) return;
|
|
420
|
+
lastResultFingerprint = fp;
|
|
421
|
+
callback(results);
|
|
422
|
+
} catch (e) {
|
|
423
|
+
console.error('Model subscription update parse error:', e);
|
|
424
|
+
}
|
|
425
|
+
},
|
|
426
|
+
);
|
|
427
|
+
|
|
428
|
+
// Set up keepalive with failure tracking
|
|
429
|
+
let keepaliveFailures = 0;
|
|
430
|
+
const keepaliveTimer = setInterval(() => {
|
|
431
|
+
this.perspective.client.keepAliveQuery(this.perspective.uuid, subscriptionId).then(() => {
|
|
432
|
+
keepaliveFailures = 0;
|
|
433
|
+
}).catch((e: any) => {
|
|
434
|
+
keepaliveFailures++;
|
|
435
|
+
console.warn(`Model subscription keepalive failed (attempt ${keepaliveFailures}) for ${subscriptionId}:`, e);
|
|
436
|
+
});
|
|
437
|
+
}, 30000);
|
|
438
|
+
|
|
439
|
+
// Store dispose function
|
|
440
|
+
this.currentSubscription = {
|
|
441
|
+
dispose: () => {
|
|
442
|
+
clearInterval(keepaliveTimer);
|
|
443
|
+
unsubscribe();
|
|
444
|
+
this.perspective.client.disposeQuerySubscription(this.perspective.uuid, subscriptionId).catch(() => {});
|
|
445
|
+
},
|
|
446
|
+
};
|
|
447
|
+
|
|
448
|
+
// Take snapshots for dirty tracking
|
|
449
|
+
for (const inst of initialResults) {
|
|
450
|
+
(inst as any).takeSnapshot?.(this.queryParams.include);
|
|
460
451
|
}
|
|
452
|
+
|
|
453
|
+
return initialResults;
|
|
461
454
|
}
|
|
462
455
|
|
|
463
456
|
/**
|
|
464
457
|
* Subscribes to the query and receives updates using SPARQL.
|
|
458
|
+
* @deprecated Use subscribe() instead — now routes through Rust model subscription.
|
|
465
459
|
*/
|
|
466
460
|
async subscribeSparql(callback: (results: T[]) => void): Promise<T[]> {
|
|
467
|
-
this.
|
|
468
|
-
|
|
469
|
-
const sparqlQuery = await this.ctor.queryToSPARQL(this.perspective, this.queryParams);
|
|
470
|
-
this.currentSubscription = await this.perspective.subscribeQuery(sparqlQuery);
|
|
471
|
-
|
|
472
|
-
const processResults = async (result: any) => {
|
|
473
|
-
const { results } = await this.processSparqlResult(result);
|
|
474
|
-
callback(results as T[]);
|
|
475
|
-
};
|
|
476
|
-
|
|
477
|
-
this.currentSubscription.onResult(processResults);
|
|
478
|
-
|
|
479
|
-
const { results } = await this.processSparqlResult(this.currentSubscription.result);
|
|
480
|
-
// Initial results returned via Promise only — callback is for subsequent updates
|
|
481
|
-
return results as T[];
|
|
461
|
+
return this.subscribe(callback);
|
|
482
462
|
}
|
|
483
463
|
|
|
484
464
|
/**
|
|
@@ -494,39 +474,16 @@ export class ModelQueryBuilder<T extends Ad4mModel> {
|
|
|
494
474
|
* ```
|
|
495
475
|
*/
|
|
496
476
|
async count(): Promise<number> {
|
|
497
|
-
|
|
498
|
-
|
|
499
|
-
const metadata = this.ctor.getModelMetadata();
|
|
500
|
-
const allRelMeta = getRelationsMetadata(this.ctor as any);
|
|
501
|
-
if (hasJsOnlyWhereFilters(metadata, allRelMeta, this.queryParams.where)) {
|
|
502
|
-
const sparqlQuery = await this.ctor.queryToSPARQL(this.perspective, this.queryParams);
|
|
503
|
-
const rawResult = await this.perspective.querySparql(sparqlQuery);
|
|
504
|
-
const { totalCount } = await this.processSparqlResult(rawResult, undefined, true);
|
|
505
|
-
return totalCount;
|
|
506
|
-
}
|
|
507
|
-
// Use efficient COUNT query — no hydration
|
|
508
|
-
const countSparql = await this.ctor.countQueryToSPARQL(this.perspective, this.queryParams);
|
|
509
|
-
const countResult = await this.perspective.querySparql(countSparql);
|
|
510
|
-
return parseSparqlCount(countResult) ?? 0;
|
|
511
|
-
} else {
|
|
512
|
-
const query = await this.ctor.countQueryToProlog(this.perspective, this.queryParams, this.modelClassName);
|
|
513
|
-
const result = await this.perspective.infer(query);
|
|
514
|
-
return result?.[0]?.TotalCount || 0;
|
|
515
|
-
}
|
|
477
|
+
const { totalCount } = await (this.ctor as any).executeModelQuery(this.perspective, { ...this.queryParams, limit: 0 }, this.modelClassName);
|
|
478
|
+
return totalCount;
|
|
516
479
|
}
|
|
517
480
|
|
|
518
481
|
/**
|
|
519
482
|
* Gets the total count of matching entities using SPARQL.
|
|
520
|
-
* Delegates to count()
|
|
483
|
+
* Delegates to count().
|
|
521
484
|
*/
|
|
522
485
|
async countSparql(): Promise<number> {
|
|
523
|
-
|
|
524
|
-
this.engineFlag = 'sparql';
|
|
525
|
-
try {
|
|
526
|
-
return await this.count();
|
|
527
|
-
} finally {
|
|
528
|
-
this.engineFlag = prev;
|
|
529
|
-
}
|
|
486
|
+
return await this.count();
|
|
530
487
|
}
|
|
531
488
|
|
|
532
489
|
/**
|
|
@@ -556,61 +513,66 @@ export class ModelQueryBuilder<T extends Ad4mModel> {
|
|
|
556
513
|
* builder.dispose();
|
|
557
514
|
* ```
|
|
558
515
|
*
|
|
559
|
-
* @remarks
|
|
560
|
-
* By default, this uses SPARQL live queries for real-time updates.
|
|
561
|
-
* Prolog subscriptions remain available via `.useSPARQL(false)`.
|
|
562
516
|
*/
|
|
563
517
|
async countSubscribe(callback: (count: number) => void): Promise<number> {
|
|
564
518
|
// Clean up any existing subscription
|
|
565
519
|
this.dispose();
|
|
566
520
|
|
|
567
|
-
|
|
568
|
-
|
|
569
|
-
|
|
521
|
+
const countParams = { ...this.queryParams, limit: 0 };
|
|
522
|
+
const { className, queryJson, shapeJson } = (this.ctor as any).prepareModelQueryParams(
|
|
523
|
+
countParams, this.modelClassName
|
|
524
|
+
);
|
|
570
525
|
|
|
571
|
-
|
|
572
|
-
|
|
573
|
-
|
|
574
|
-
};
|
|
526
|
+
const { subscriptionId, result: initialModelResult } = await this.perspective.modelSubscribe(
|
|
527
|
+
className, queryJson, shapeJson
|
|
528
|
+
);
|
|
575
529
|
|
|
576
|
-
|
|
577
|
-
const
|
|
578
|
-
|
|
579
|
-
|
|
580
|
-
|
|
581
|
-
|
|
582
|
-
|
|
583
|
-
|
|
584
|
-
|
|
585
|
-
|
|
586
|
-
|
|
587
|
-
|
|
588
|
-
|
|
589
|
-
|
|
590
|
-
|
|
591
|
-
|
|
592
|
-
|
|
593
|
-
|
|
530
|
+
const parseCount = (raw: any): number => {
|
|
531
|
+
const data = typeof raw === 'string' ? JSON.parse(raw) : raw;
|
|
532
|
+
return data.totalCount ?? 0;
|
|
533
|
+
};
|
|
534
|
+
|
|
535
|
+
const initialCount = parseCount(initialModelResult);
|
|
536
|
+
|
|
537
|
+
const unsubscribe = this.perspective.client.subscribeToQueryUpdates(
|
|
538
|
+
subscriptionId,
|
|
539
|
+
(rawResult: any) => {
|
|
540
|
+
if (rawResult && rawResult.isInit) return;
|
|
541
|
+
try {
|
|
542
|
+
callback(parseCount(rawResult));
|
|
543
|
+
} catch (e) {
|
|
544
|
+
console.error('Count subscription update parse error:', e);
|
|
545
|
+
}
|
|
546
|
+
},
|
|
547
|
+
);
|
|
548
|
+
|
|
549
|
+
let keepaliveFailures = 0;
|
|
550
|
+
const keepaliveTimer = setInterval(() => {
|
|
551
|
+
this.perspective.client.keepAliveQuery(this.perspective.uuid, subscriptionId).then(() => {
|
|
552
|
+
keepaliveFailures = 0;
|
|
553
|
+
}).catch((e: any) => {
|
|
554
|
+
keepaliveFailures++;
|
|
555
|
+
console.warn(`Count subscription keepalive failed (attempt ${keepaliveFailures}) for ${subscriptionId}:`, e);
|
|
556
|
+
});
|
|
557
|
+
}, 30000);
|
|
558
|
+
|
|
559
|
+
this.currentSubscription = {
|
|
560
|
+
dispose: () => {
|
|
561
|
+
clearInterval(keepaliveTimer);
|
|
562
|
+
unsubscribe();
|
|
563
|
+
this.perspective.client.disposeQuerySubscription(this.perspective.uuid, subscriptionId).catch(() => {});
|
|
564
|
+
},
|
|
565
|
+
};
|
|
566
|
+
|
|
567
|
+
return initialCount;
|
|
594
568
|
}
|
|
595
569
|
|
|
596
570
|
/**
|
|
597
571
|
* Subscribes to count updates using SPARQL.
|
|
572
|
+
* @deprecated Use countSubscribe() instead — now routes through Rust model subscription.
|
|
598
573
|
*/
|
|
599
574
|
async countSubscribeSparql(callback: (count: number) => void): Promise<number> {
|
|
600
|
-
this.
|
|
601
|
-
|
|
602
|
-
const sparqlQuery = await this.ctor.queryToSPARQL(this.perspective, this.queryParams);
|
|
603
|
-
this.currentSubscription = await this.perspective.subscribeQuery(sparqlQuery);
|
|
604
|
-
|
|
605
|
-
const processResults = async (result: any) => {
|
|
606
|
-
const { totalCount } = await this.processSparqlResult(result, undefined, true);
|
|
607
|
-
callback(totalCount);
|
|
608
|
-
};
|
|
609
|
-
|
|
610
|
-
this.currentSubscription.onResult(processResults);
|
|
611
|
-
const { totalCount } = await this.processSparqlResult(this.currentSubscription.result, undefined, true);
|
|
612
|
-
// Initial count returned via Promise — callback for updates only
|
|
613
|
-
return totalCount;
|
|
575
|
+
return this.countSubscribe(callback);
|
|
614
576
|
}
|
|
615
577
|
|
|
616
578
|
/**
|
|
@@ -630,31 +592,16 @@ export class ModelQueryBuilder<T extends Ad4mModel> {
|
|
|
630
592
|
*/
|
|
631
593
|
async paginate(pageSize: number, pageNumber: number): Promise<PaginationResult<T>> {
|
|
632
594
|
const paginationQuery = { ...(this.queryParams || {}), limit: pageSize, offset: pageSize * (pageNumber - 1), count: true };
|
|
633
|
-
|
|
634
|
-
|
|
635
|
-
const result = await this.perspective.querySparql(sparqlQuery);
|
|
636
|
-
const { results, totalCount } = await this.processSparqlResult(result, paginationQuery, true) as ResultsWithTotalCount<T>;
|
|
637
|
-
return { results, totalCount, pageSize, pageNumber };
|
|
638
|
-
} else {
|
|
639
|
-
const prologQuery = await this.ctor.queryToProlog(this.perspective, paginationQuery, this.modelClassName);
|
|
640
|
-
const result = await this.perspective.infer(prologQuery);
|
|
641
|
-
const { results, totalCount } = (await this.ctor.instancesFromPrologResult(this.perspective, paginationQuery, result)) as ResultsWithTotalCount<T>;
|
|
642
|
-
return { results, totalCount, pageSize, pageNumber };
|
|
643
|
-
}
|
|
595
|
+
const { results, totalCount } = await (this.ctor as any).executeModelQuery(this.perspective, paginationQuery, this.modelClassName);
|
|
596
|
+
return { results, totalCount, pageSize, pageNumber };
|
|
644
597
|
}
|
|
645
598
|
|
|
646
599
|
/**
|
|
647
600
|
* Gets a page of results using SPARQL.
|
|
648
|
-
* Delegates to paginate()
|
|
601
|
+
* Delegates to paginate().
|
|
649
602
|
*/
|
|
650
603
|
async paginateSparql(pageSize: number, pageNumber: number): Promise<PaginationResult<T>> {
|
|
651
|
-
|
|
652
|
-
this.engineFlag = 'sparql';
|
|
653
|
-
try {
|
|
654
|
-
return await this.paginate(pageSize, pageNumber);
|
|
655
|
-
} finally {
|
|
656
|
-
this.engineFlag = prev;
|
|
657
|
-
}
|
|
604
|
+
return await this.paginate(pageSize, pageNumber);
|
|
658
605
|
}
|
|
659
606
|
|
|
660
607
|
/**
|
|
@@ -686,9 +633,6 @@ export class ModelQueryBuilder<T extends Ad4mModel> {
|
|
|
686
633
|
* builder.dispose();
|
|
687
634
|
* ```
|
|
688
635
|
*
|
|
689
|
-
* @remarks
|
|
690
|
-
* By default, this uses SPARQL live queries for real-time updates.
|
|
691
|
-
* Prolog subscriptions remain available via `.useSPARQL(false)`.
|
|
692
636
|
*/
|
|
693
637
|
async paginateSubscribe(
|
|
694
638
|
pageSize: number,
|
|
@@ -698,67 +642,75 @@ export class ModelQueryBuilder<T extends Ad4mModel> {
|
|
|
698
642
|
// Clean up any existing subscription
|
|
699
643
|
this.dispose();
|
|
700
644
|
|
|
701
|
-
const
|
|
645
|
+
const ctor = this.ctor;
|
|
702
646
|
|
|
703
|
-
|
|
704
|
-
|
|
705
|
-
|
|
706
|
-
|
|
707
|
-
|
|
708
|
-
|
|
709
|
-
|
|
710
|
-
|
|
711
|
-
|
|
712
|
-
|
|
713
|
-
|
|
714
|
-
|
|
715
|
-
|
|
716
|
-
|
|
717
|
-
|
|
718
|
-
|
|
719
|
-
|
|
720
|
-
|
|
721
|
-
|
|
722
|
-
|
|
723
|
-
|
|
724
|
-
|
|
725
|
-
|
|
726
|
-
const results =
|
|
727
|
-
|
|
728
|
-
|
|
729
|
-
|
|
730
|
-
|
|
731
|
-
|
|
732
|
-
|
|
733
|
-
|
|
734
|
-
|
|
735
|
-
|
|
736
|
-
|
|
737
|
-
|
|
738
|
-
|
|
739
|
-
|
|
740
|
-
|
|
741
|
-
|
|
742
|
-
|
|
743
|
-
|
|
744
|
-
|
|
647
|
+
// Subscribe to the full result set (no limit/offset) so the subscription
|
|
648
|
+
// detects changes anywhere in the dataset. Rust builds trigger SPARQL
|
|
649
|
+
// from the shape predicates.
|
|
650
|
+
const subscriptionParams = { ...(this.queryParams || {}) };
|
|
651
|
+
delete subscriptionParams.limit;
|
|
652
|
+
delete subscriptionParams.offset;
|
|
653
|
+
const { className, queryJson, shapeJson } = (ctor as any).prepareModelQueryParams(
|
|
654
|
+
subscriptionParams, this.modelClassName
|
|
655
|
+
);
|
|
656
|
+
|
|
657
|
+
const { subscriptionId } = await this.perspective.modelSubscribe(
|
|
658
|
+
className, queryJson, shapeJson
|
|
659
|
+
);
|
|
660
|
+
|
|
661
|
+
// Build the paginated query for Rust endpoint (count: true fetches both results and totalCount in one call)
|
|
662
|
+
const paginatedQuery = {
|
|
663
|
+
...(this.queryParams || {}),
|
|
664
|
+
limit: pageSize,
|
|
665
|
+
offset: pageSize * (pageNumber - 1),
|
|
666
|
+
count: true,
|
|
667
|
+
};
|
|
668
|
+
|
|
669
|
+
const processResults = async () => {
|
|
670
|
+
const { results, totalCount } = await (ctor as any).executeModelQuery(this.perspective, paginatedQuery, this.modelClassName);
|
|
671
|
+
callback({ results, totalCount, pageSize, pageNumber });
|
|
672
|
+
};
|
|
673
|
+
|
|
674
|
+
const unsubscribe = this.perspective.client.subscribeToQueryUpdates(
|
|
675
|
+
subscriptionId,
|
|
676
|
+
(rawResult: any) => {
|
|
677
|
+
if (rawResult && rawResult.isInit) return;
|
|
678
|
+
processResults().catch(e => console.error('Paginate subscription error:', e));
|
|
679
|
+
},
|
|
680
|
+
);
|
|
681
|
+
|
|
682
|
+
let keepaliveFailures = 0;
|
|
683
|
+
const keepaliveTimer = setInterval(() => {
|
|
684
|
+
this.perspective.client.keepAliveQuery(this.perspective.uuid, subscriptionId).then(() => {
|
|
685
|
+
keepaliveFailures = 0;
|
|
686
|
+
}).catch((e: any) => {
|
|
687
|
+
keepaliveFailures++;
|
|
688
|
+
console.warn(`Paginate subscription keepalive failed (attempt ${keepaliveFailures}) for ${subscriptionId}:`, e);
|
|
689
|
+
});
|
|
690
|
+
}, 30000);
|
|
691
|
+
|
|
692
|
+
this.currentSubscription = {
|
|
693
|
+
dispose: () => {
|
|
694
|
+
clearInterval(keepaliveTimer);
|
|
695
|
+
unsubscribe();
|
|
696
|
+
this.perspective.client.disposeQuerySubscription(this.perspective.uuid, subscriptionId).catch(() => {});
|
|
697
|
+
},
|
|
698
|
+
};
|
|
699
|
+
|
|
700
|
+
// Initial fetch (single call with count: true)
|
|
701
|
+
const { results, totalCount } = await (ctor as any).executeModelQuery(this.perspective, paginatedQuery, this.modelClassName);
|
|
702
|
+
return { results, totalCount, pageSize, pageNumber };
|
|
745
703
|
}
|
|
746
704
|
|
|
747
705
|
/**
|
|
748
706
|
* Subscribes to paginated results updates using SPARQL.
|
|
749
|
-
* Delegates to paginateSubscribe()
|
|
707
|
+
* Delegates to paginateSubscribe().
|
|
750
708
|
*/
|
|
751
709
|
async paginateSubscribeSparql(
|
|
752
710
|
pageSize: number,
|
|
753
711
|
pageNumber: number,
|
|
754
712
|
callback: (results: PaginationResult<T>) => void
|
|
755
713
|
): Promise<PaginationResult<T>> {
|
|
756
|
-
|
|
757
|
-
this.engineFlag = 'sparql';
|
|
758
|
-
try {
|
|
759
|
-
return await this.paginateSubscribe(pageSize, pageNumber, callback);
|
|
760
|
-
} finally {
|
|
761
|
-
this.engineFlag = prev;
|
|
762
|
-
}
|
|
714
|
+
return await this.paginateSubscribe(pageSize, pageNumber, callback);
|
|
763
715
|
}
|
|
764
716
|
}
|
package/src/model/decorators.ts
CHANGED
|
@@ -279,6 +279,26 @@ export interface PropertyOptions {
|
|
|
279
279
|
* The function takes the raw value as input and returns the transformed value.
|
|
280
280
|
*/
|
|
281
281
|
transform?: (value: any) => any;
|
|
282
|
+
|
|
283
|
+
/**
|
|
284
|
+
* Allowed values for this property (enum constraint).
|
|
285
|
+
* Maps to SHACL `sh:in`. Each entry has a `value` (the stored RDF term)
|
|
286
|
+
* and an optional `label` (human-readable display name).
|
|
287
|
+
*
|
|
288
|
+
* @example
|
|
289
|
+
* ```typescript
|
|
290
|
+
* @Property({
|
|
291
|
+
* through: "task://status",
|
|
292
|
+
* options: [
|
|
293
|
+
* { value: "task://todo", label: "To Do" },
|
|
294
|
+
* { value: "task://doing", label: "Doing" },
|
|
295
|
+
* { value: "task://done", label: "Done" },
|
|
296
|
+
* ]
|
|
297
|
+
* })
|
|
298
|
+
* status: string = "task://todo";
|
|
299
|
+
* ```
|
|
300
|
+
*/
|
|
301
|
+
options?: Array<{ value: string; label?: string }>;
|
|
282
302
|
}
|
|
283
303
|
|
|
284
304
|
|
|
@@ -838,8 +858,17 @@ export function HasMany(
|
|
|
838
858
|
first: (() => Ad4mModelLike) | RelationOptions,
|
|
839
859
|
second?: Omit<RelationOptions, 'target'>,
|
|
840
860
|
): PropertyDecorator {
|
|
861
|
+
const explicitThrough = typeof first === 'function' ? second?.through : (first as RelationOptions).through;
|
|
841
862
|
const opts = resolveRelationArgs(first, second);
|
|
842
863
|
return function <T>(target: T, key: keyof T) {
|
|
864
|
+
if (!explicitThrough && !opts.getter) {
|
|
865
|
+
const className = ((target as any).constructor?.name) ?? 'unknown';
|
|
866
|
+
console.warn(
|
|
867
|
+
`@HasMany on ${className}.${String(key)} has no 'through' predicate — defaulting to 'ad4m://has_child'. ` +
|
|
868
|
+
`Add { through: 'ad4m://has_child' } to silence this warning, or use a semantic predicate ` +
|
|
869
|
+
`like { through: 'myns://has_${String(key)}' } for efficient targeted queries.`
|
|
870
|
+
);
|
|
871
|
+
}
|
|
843
872
|
// --- relation registry ---
|
|
844
873
|
const ctor = (target as any).constructor;
|
|
845
874
|
if (!relationRegistry.has(ctor)) relationRegistry.set(ctor, {});
|