@coasys/ad4m 0.13.0-test-3 → 0.13.0-test-4
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/README.md +2 -25
- package/jest-setup.ts +1 -1
- package/lib/index.cjs +2406 -11070
- package/lib/index.js +2209 -10925
- package/lib/src/Ad4mClient.d.ts +7 -3
- package/lib/src/Ad4mClient.js +29 -13
- package/lib/src/agent/Agent.js +26 -272
- package/lib/src/agent/AgentClient.d.ts +10 -21
- package/lib/src/agent/AgentClient.js +75 -427
- package/lib/src/agent/AgentStatus.js +2 -37
- package/lib/src/ai/AIClient.d.ts +12 -4
- package/lib/src/ai/AIClient.js +81 -285
- package/lib/src/ai/AITypes.d.ts +55 -0
- package/lib/src/ai/AITypes.js +18 -0
- package/lib/src/ai/Tasks.js +10 -133
- package/lib/src/apiClient.d.ts +52 -0
- package/lib/src/apiClient.js +231 -0
- package/lib/src/expression/Expression.d.ts +1 -1
- package/lib/src/expression/Expression.js +13 -122
- package/lib/src/expression/ExpressionClient.d.ts +3 -3
- package/lib/src/expression/ExpressionClient.js +13 -76
- package/lib/src/expression/ExpressionRef.js +2 -25
- package/lib/src/generated/api/AIModelLoadingStatus.d.ts +7 -0
- package/lib/src/generated/api/AIModelLoadingStatus.js +2 -0
- package/lib/src/generated/api/AddLinkExpressionRequest.d.ts +6 -0
- package/lib/src/generated/api/AddLinkExpressionRequest.js +1 -0
- package/lib/src/generated/api/AddLinkRequest.d.ts +6 -0
- package/lib/src/generated/api/AddLinkRequest.js +1 -0
- package/lib/src/generated/api/AddLinksBulkRequest.d.ts +6 -0
- package/lib/src/generated/api/AddLinksBulkRequest.js +1 -0
- package/lib/src/generated/api/AddSdnaRequest.d.ts +6 -0
- package/lib/src/generated/api/AddSdnaRequest.js +2 -0
- package/lib/src/generated/api/ApplyTemplateRequest.d.ts +4 -0
- package/lib/src/generated/api/ApplyTemplateRequest.js +2 -0
- package/lib/src/generated/api/AuthInfoInput.d.ts +10 -0
- package/lib/src/generated/api/AuthInfoInput.js +1 -0
- package/lib/src/generated/api/CapabilityInput.d.ts +5 -0
- package/lib/src/generated/api/CapabilityInput.js +1 -0
- package/lib/src/generated/api/CommitBatchRequest.d.ts +3 -0
- package/lib/src/generated/api/CommitBatchRequest.js +2 -0
- package/lib/src/generated/api/ComputeLogEntry.d.ts +9 -0
- package/lib/src/generated/api/ComputeLogEntry.js +2 -0
- package/lib/src/generated/api/CreateExpressionRequest.d.ts +4 -0
- package/lib/src/generated/api/CreateExpressionRequest.js +2 -0
- package/lib/src/generated/api/CreatePerspectiveRequest.d.ts +3 -0
- package/lib/src/generated/api/CreatePerspectiveRequest.js +2 -0
- package/lib/src/generated/api/CreateSubjectRequest.d.ts +6 -0
- package/lib/src/generated/api/CreateSubjectRequest.js +2 -0
- package/lib/src/generated/api/EmbedRequest.d.ts +4 -0
- package/lib/src/generated/api/EmbedRequest.js +2 -0
- package/lib/src/generated/api/EntanglementProofInput.d.ts +6 -0
- package/lib/src/generated/api/EntanglementProofInput.js +2 -0
- package/lib/src/generated/api/ExecuteCommandsRequest.d.ts +4 -0
- package/lib/src/generated/api/ExecuteCommandsRequest.js +2 -0
- package/lib/src/generated/api/ExportRequest.d.ts +5 -0
- package/lib/src/generated/api/ExportRequest.js +2 -0
- package/lib/src/generated/api/ExpressionManyRequest.d.ts +3 -0
- package/lib/src/generated/api/ExpressionManyRequest.js +2 -0
- package/lib/src/generated/api/ExpressionProof.d.ts +4 -0
- package/lib/src/generated/api/ExpressionProof.js +2 -0
- package/lib/src/generated/api/ExpressionProofInput.d.ts +6 -0
- package/lib/src/generated/api/ExpressionProofInput.js +2 -0
- package/lib/src/generated/api/FriendSendMessageRequest.d.ts +3 -0
- package/lib/src/generated/api/FriendSendMessageRequest.js +2 -0
- package/lib/src/generated/api/FriendsListRequest.d.ts +3 -0
- package/lib/src/generated/api/FriendsListRequest.js +2 -0
- package/lib/src/generated/api/GenerateAgentRequest.d.ts +3 -0
- package/lib/src/generated/api/GenerateAgentRequest.js +2 -0
- package/lib/src/generated/api/GenerateJwtRequest.d.ts +4 -0
- package/lib/src/generated/api/GenerateJwtRequest.js +2 -0
- package/lib/src/generated/api/GetSubjectDataRequest.d.ts +4 -0
- package/lib/src/generated/api/GetSubjectDataRequest.js +2 -0
- package/lib/src/generated/api/ImportAgentRequest.d.ts +6 -0
- package/lib/src/generated/api/ImportAgentRequest.js +2 -0
- package/lib/src/generated/api/ImportRequest.d.ts +4 -0
- package/lib/src/generated/api/ImportRequest.js +2 -0
- package/lib/src/generated/api/JoinNeighbourhoodRequest.d.ts +3 -0
- package/lib/src/generated/api/JoinNeighbourhoodRequest.js +2 -0
- package/lib/src/generated/api/LanguageMetaInput.d.ts +6 -0
- package/lib/src/generated/api/LanguageMetaInput.js +2 -0
- package/lib/src/generated/api/Link.d.ts +5 -0
- package/lib/src/generated/api/Link.js +2 -0
- package/lib/src/generated/api/LinkExpression.d.ts +10 -0
- package/lib/src/generated/api/LinkExpression.js +1 -0
- package/lib/src/generated/api/LinkExpressionInput.d.ts +10 -0
- package/lib/src/generated/api/LinkExpressionInput.js +1 -0
- package/lib/src/generated/api/LinkInput.d.ts +5 -0
- package/lib/src/generated/api/LinkInput.js +2 -0
- package/lib/src/generated/api/LinkLanguageTemplatesRequest.d.ts +3 -0
- package/lib/src/generated/api/LinkLanguageTemplatesRequest.js +2 -0
- package/lib/src/generated/api/LinkMutations.d.ts +6 -0
- package/lib/src/generated/api/LinkMutations.js +1 -0
- package/lib/src/generated/api/LinkStatus.d.ts +1 -0
- package/lib/src/generated/api/LinkStatus.js +2 -0
- package/lib/src/generated/api/LockAgentRequest.d.ts +3 -0
- package/lib/src/generated/api/LockAgentRequest.js +2 -0
- package/lib/src/generated/api/ModelType.d.ts +1 -0
- package/lib/src/generated/api/ModelType.js +2 -0
- package/lib/src/generated/api/NotificationInput.d.ts +10 -0
- package/lib/src/generated/api/NotificationInput.js +2 -0
- package/lib/src/generated/api/OpenLinkRequest.d.ts +3 -0
- package/lib/src/generated/api/OpenLinkRequest.js +2 -0
- package/lib/src/generated/api/PermitCapabilityRequest.d.ts +3 -0
- package/lib/src/generated/api/PermitCapabilityRequest.js +2 -0
- package/lib/src/generated/api/PerspectiveInput.d.ts +4 -0
- package/lib/src/generated/api/PerspectiveInput.js +1 -0
- package/lib/src/generated/api/PromptRequest.d.ts +4 -0
- package/lib/src/generated/api/PromptRequest.js +2 -0
- package/lib/src/generated/api/PublishLanguageRequest.d.ts +5 -0
- package/lib/src/generated/api/PublishLanguageRequest.js +1 -0
- package/lib/src/generated/api/PublishNeighbourhoodRequest.d.ts +6 -0
- package/lib/src/generated/api/PublishNeighbourhoodRequest.js +1 -0
- package/lib/src/generated/api/QueryRequest.d.ts +7 -0
- package/lib/src/generated/api/QueryRequest.js +2 -0
- package/lib/src/generated/api/RemoveLinkRequest.d.ts +5 -0
- package/lib/src/generated/api/RemoveLinkRequest.js +1 -0
- package/lib/src/generated/api/RemoveLinksBulkRequest.d.ts +5 -0
- package/lib/src/generated/api/RemoveLinksBulkRequest.js +1 -0
- package/lib/src/generated/api/ResourceInput.d.ts +4 -0
- package/lib/src/generated/api/ResourceInput.js +2 -0
- package/lib/src/generated/api/SetDefaultModelRequest.d.ts +4 -0
- package/lib/src/generated/api/SetDefaultModelRequest.js +1 -0
- package/lib/src/generated/api/SetFreeHostingEnabledRequest.d.ts +3 -0
- package/lib/src/generated/api/SetFreeHostingEnabledRequest.js +2 -0
- package/lib/src/generated/api/SetMultiUserRequest.d.ts +3 -0
- package/lib/src/generated/api/SetMultiUserRequest.js +2 -0
- package/lib/src/generated/api/SetStatusRequest.d.ts +3 -0
- package/lib/src/generated/api/SetStatusRequest.js +2 -0
- package/lib/src/generated/api/SignMessageRequest.d.ts +3 -0
- package/lib/src/generated/api/SignMessageRequest.js +2 -0
- package/lib/src/generated/api/TrustedAgentsRequest.d.ts +3 -0
- package/lib/src/generated/api/TrustedAgentsRequest.js +2 -0
- package/lib/src/generated/api/UnlockAgentRequest.d.ts +4 -0
- package/lib/src/generated/api/UnlockAgentRequest.js +2 -0
- package/lib/src/generated/api/UpdateLinkRequest.d.ts +7 -0
- package/lib/src/generated/api/UpdateLinkRequest.js +1 -0
- package/lib/src/generated/api/UpdatePerspectiveRequest.d.ts +3 -0
- package/lib/src/generated/api/UpdatePerspectiveRequest.js +2 -0
- package/lib/src/generated/api/UserStatistics.d.ts +9 -0
- package/lib/src/generated/api/UserStatistics.js +2 -0
- package/lib/src/generated/api/VerificationRequestResult.d.ts +6 -0
- package/lib/src/generated/api/VerificationRequestResult.js +2 -0
- package/lib/src/generated/api/VerifySignatureRequest.d.ts +5 -0
- package/lib/src/generated/api/VerifySignatureRequest.js +2 -0
- package/lib/src/generated/api/WriteSettingsRequest.d.ts +3 -0
- package/lib/src/generated/api/WriteSettingsRequest.js +2 -0
- package/lib/src/generated/api/index.d.ts +42 -0
- package/lib/src/generated/api/index.js +7 -0
- package/lib/src/index.d.ts +6 -1
- package/lib/src/index.js +6 -1
- package/lib/src/jestSetup.d.ts +0 -1
- package/lib/src/jestSetup.js +1 -1
- package/lib/src/language/Icon.js +2 -21
- package/lib/src/language/Language.d.ts +1 -1
- package/lib/src/language/Language.js +10 -76
- package/lib/src/language/LanguageClient.d.ts +2 -2
- package/lib/src/language/LanguageClient.js +15 -105
- package/lib/src/language/LanguageHandle.js +2 -41
- package/lib/src/language/LanguageMeta.js +4 -75
- package/lib/src/language/LanguageRef.js +2 -25
- package/lib/src/links/Links.js +14 -111
- package/lib/src/model/Ad4mModel.d.ts +57 -38
- package/lib/src/model/Ad4mModel.js +594 -460
- package/lib/src/model/Ad4mModel.test.js +371 -815
- package/lib/src/model/ModelQueryBuilder.d.ts +9 -21
- package/lib/src/model/ModelQueryBuilder.js +138 -217
- package/lib/src/model/decorators.d.ts +22 -0
- package/lib/src/model/decorators.js +7 -0
- package/lib/src/model/hydration.d.ts +7 -60
- package/lib/src/model/hydration.js +7 -716
- package/lib/src/model/index.d.ts +0 -4
- package/lib/src/model/index.js +0 -4
- package/lib/src/model/model-manifest.d.ts +41 -0
- package/lib/src/model/model-manifest.js +11 -0
- package/lib/src/model/query-sparql.d.ts +4 -67
- package/lib/src/model/query-sparql.js +26 -322
- package/lib/src/model/query-sparql.test.js +35 -218
- package/lib/src/model/shacl-gen.js +4 -0
- package/lib/src/model/types.d.ts +47 -38
- package/lib/src/model/types.js +4 -1
- package/lib/src/neighbourhood/Neighbourhood.js +4 -32
- package/lib/src/neighbourhood/NeighbourhoodClient.d.ts +3 -3
- package/lib/src/neighbourhood/NeighbourhoodClient.js +40 -203
- package/lib/src/perspectives/LinkQuery.js +2 -42
- package/lib/src/perspectives/Perspective.d.ts +1 -1
- package/lib/src/perspectives/Perspective.js +10 -52
- package/lib/src/perspectives/PerspectiveClient.d.ts +12 -17
- package/lib/src/perspectives/PerspectiveClient.js +169 -429
- package/lib/src/perspectives/PerspectiveClient.test.js +55 -0
- package/lib/src/perspectives/PerspectiveDiff.js +4 -31
- package/lib/src/perspectives/PerspectiveHandle.js +3 -43
- package/lib/src/perspectives/PerspectiveProxy.d.ts +92 -71
- package/lib/src/perspectives/PerspectiveProxy.js +273 -310
- package/lib/src/runtime/RuntimeClient.d.ts +6 -6
- package/lib/src/runtime/RuntimeClient.js +93 -467
- package/lib/src/runtime/RuntimeTypes.d.ts +101 -0
- package/lib/src/runtime/RuntimeTypes.js +45 -0
- package/lib/src/shacl/SHACLShape.d.ts +7 -0
- package/lib/src/shacl/SHACLShape.js +19 -0
- package/lib/src/shacl/SHACLShape.test.js +82 -0
- package/lib/src/typeDefs.js +3 -628
- package/package.json +9 -24
- package/rollup.config.js +0 -7
- package/src/Ad4mClient.test.ts +1179 -1340
- package/src/Ad4mClient.ts +30 -15
- package/src/agent/Agent.ts +0 -99
- package/src/agent/AgentClient.ts +112 -526
- package/src/agent/AgentStatus.ts +0 -12
- package/src/ai/AIClient.ts +96 -296
- package/src/ai/AITypes.ts +66 -0
- package/src/ai/Tasks.ts +0 -52
- package/src/apiClient.ts +283 -0
- package/src/expression/Expression.ts +3 -43
- package/src/expression/ExpressionClient.ts +14 -77
- package/src/expression/ExpressionRef.ts +0 -6
- package/src/generated/api/AIModelLoadingStatus.ts +3 -0
- package/src/generated/api/AddLinkExpressionRequest.ts +4 -0
- package/src/generated/api/AddLinkRequest.ts +4 -0
- package/src/generated/api/AddLinksBulkRequest.ts +4 -0
- package/src/generated/api/AddSdnaRequest.ts +3 -0
- package/src/generated/api/ApplyTemplateRequest.ts +3 -0
- package/src/generated/api/AuthInfoInput.ts +4 -0
- package/src/generated/api/CapabilityInput.ts +4 -0
- package/src/generated/api/CommitBatchRequest.ts +3 -0
- package/src/generated/api/ComputeLogEntry.ts +3 -0
- package/src/generated/api/CreateExpressionRequest.ts +3 -0
- package/src/generated/api/CreatePerspectiveRequest.ts +3 -0
- package/src/generated/api/CreateSubjectRequest.ts +3 -0
- package/src/generated/api/EmbedRequest.ts +3 -0
- package/src/generated/api/EntanglementProofInput.ts +3 -0
- package/src/generated/api/ExecuteCommandsRequest.ts +3 -0
- package/src/generated/api/ExportRequest.ts +3 -0
- package/src/generated/api/ExpressionManyRequest.ts +3 -0
- package/src/generated/api/ExpressionProof.ts +3 -0
- package/src/generated/api/ExpressionProofInput.ts +3 -0
- package/src/generated/api/FriendSendMessageRequest.ts +3 -0
- package/src/generated/api/FriendsListRequest.ts +3 -0
- package/src/generated/api/GenerateAgentRequest.ts +3 -0
- package/src/generated/api/GenerateJwtRequest.ts +3 -0
- package/src/generated/api/GetSubjectDataRequest.ts +3 -0
- package/src/generated/api/ImportAgentRequest.ts +3 -0
- package/src/generated/api/ImportRequest.ts +3 -0
- package/src/generated/api/JoinNeighbourhoodRequest.ts +3 -0
- package/src/generated/api/LanguageMetaInput.ts +3 -0
- package/src/generated/api/Link.ts +3 -0
- package/src/generated/api/LinkExpression.ts +6 -0
- package/src/generated/api/LinkExpressionInput.ts +6 -0
- package/src/generated/api/LinkInput.ts +3 -0
- package/src/generated/api/LinkLanguageTemplatesRequest.ts +3 -0
- package/src/generated/api/LinkMutations.ts +5 -0
- package/src/generated/api/LinkStatus.ts +3 -0
- package/src/generated/api/LockAgentRequest.ts +3 -0
- package/src/generated/api/ModelType.ts +3 -0
- package/src/generated/api/NotificationInput.ts +3 -0
- package/src/generated/api/OpenLinkRequest.ts +3 -0
- package/src/generated/api/PermitCapabilityRequest.ts +3 -0
- package/src/generated/api/PerspectiveInput.ts +4 -0
- package/src/generated/api/PromptRequest.ts +3 -0
- package/src/generated/api/PublishLanguageRequest.ts +4 -0
- package/src/generated/api/PublishNeighbourhoodRequest.ts +4 -0
- package/src/generated/api/QueryRequest.ts +6 -0
- package/src/generated/api/RemoveLinkRequest.ts +4 -0
- package/src/generated/api/RemoveLinksBulkRequest.ts +4 -0
- package/src/generated/api/ResourceInput.ts +3 -0
- package/src/generated/api/SetDefaultModelRequest.ts +4 -0
- package/src/generated/api/SetFreeHostingEnabledRequest.ts +3 -0
- package/src/generated/api/SetMultiUserRequest.ts +3 -0
- package/src/generated/api/SetStatusRequest.ts +3 -0
- package/src/generated/api/SignMessageRequest.ts +3 -0
- package/src/generated/api/TrustedAgentsRequest.ts +3 -0
- package/src/generated/api/UnlockAgentRequest.ts +3 -0
- package/src/generated/api/UpdateLinkRequest.ts +5 -0
- package/src/generated/api/UpdatePerspectiveRequest.ts +3 -0
- package/src/generated/api/UserStatistics.ts +3 -0
- package/src/generated/api/VerificationRequestResult.ts +3 -0
- package/src/generated/api/VerifySignatureRequest.ts +3 -0
- package/src/generated/api/WriteSettingsRequest.ts +3 -0
- package/src/generated/api/index.ts +49 -0
- package/src/index.ts +6 -1
- package/src/jestSetup.ts +1 -1
- package/src/language/Icon.ts +0 -4
- package/src/language/Language.ts +2 -23
- package/src/language/LanguageClient.ts +21 -132
- package/src/language/LanguageHandle.ts +0 -14
- package/src/language/LanguageMeta.ts +0 -29
- package/src/language/LanguageRef.ts +0 -7
- package/src/links/Links.ts +0 -37
- package/src/model/Ad4mModel.test.ts +708 -876
- package/src/model/Ad4mModel.ts +613 -508
- package/src/model/ModelQueryBuilder.ts +178 -244
- package/src/model/decorators.ts +29 -0
- package/src/model/hydration.ts +9 -766
- package/src/model/index.ts +0 -4
- package/src/model/query-sparql.test.ts +34 -242
- package/src/model/query-sparql.ts +27 -337
- package/src/model/shacl-gen.ts +5 -0
- package/src/model/types.ts +51 -39
- package/src/neighbourhood/Neighbourhood.ts +0 -9
- package/src/neighbourhood/NeighbourhoodClient.ts +42 -207
- package/src/neighbourhood/NeighbourhoodProxy.test.ts +34 -36
- package/src/perspectives/LinkQuery.ts +0 -15
- package/src/perspectives/Perspective.ts +1 -12
- package/src/perspectives/PerspectiveClient.test.ts +206 -148
- package/src/perspectives/PerspectiveClient.ts +228 -442
- package/src/perspectives/PerspectiveDiff.ts +0 -8
- package/src/perspectives/PerspectiveHandle.ts +1 -12
- package/src/perspectives/PerspectiveProxy.test.ts +41 -0
- package/src/perspectives/PerspectiveProxy.ts +307 -348
- package/src/runtime/RuntimeClient.ts +112 -474
- package/src/runtime/RuntimeTypes.ts +144 -0
- package/src/shacl/SHACLShape.test.ts +94 -0
- package/src/shacl/SHACLShape.ts +27 -0
- package/src/typeDefs.ts +3 -5
- package/tsconfig.json +3 -7
- package/shims/reflect-metadata.ts +0 -0
- package/shims/type-graphql.ts +0 -75
- package/src/PubSub.ts +0 -17
- package/src/agent/AgentResolver.ts +0 -263
- package/src/ai/AIResolver.ts +0 -372
- package/src/buildSchema.ts +0 -43
- package/src/expression/ExpressionResolver.ts +0 -64
- package/src/language/LanguageResolver.ts +0 -98
- package/src/model/Subject.ts +0 -159
- package/src/model/hydration-batch.ts +0 -205
- package/src/model/hydration-batching.test.ts +0 -563
- package/src/model/prolog-facts.ts +0 -145
- package/src/model/query-prolog.ts +0 -148
- package/src/model/query-sparql-batch.ts +0 -301
- package/src/model/subscription-delta.test.ts +0 -207
- package/src/model/subscription-pool.ts +0 -211
- package/src/neighbourhood/NeighbourhoodResolver.ts +0 -100
- package/src/perspectives/PerspectiveResolver.ts +0 -364
- package/src/runtime/RuntimeResolver.ts +0 -749
- package/src/unwrapApolloResult.ts +0 -16
|
@@ -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
|
*
|
|
@@ -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,84 @@ 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
|
|
429
|
+
const keepaliveTimer = setInterval(() => {
|
|
430
|
+
this.perspective.client.keepAliveQuery(this.perspective.uuid, subscriptionId).catch(() => {});
|
|
431
|
+
}, 30000);
|
|
432
|
+
|
|
433
|
+
// Store dispose function
|
|
434
|
+
this.currentSubscription = {
|
|
435
|
+
dispose: () => {
|
|
436
|
+
clearInterval(keepaliveTimer);
|
|
437
|
+
unsubscribe();
|
|
438
|
+
this.perspective.client.disposeQuerySubscription(this.perspective.uuid, subscriptionId).catch(() => {});
|
|
439
|
+
},
|
|
440
|
+
};
|
|
441
|
+
|
|
442
|
+
// Take snapshots for dirty tracking
|
|
443
|
+
for (const inst of initialResults) {
|
|
444
|
+
(inst as any).takeSnapshot?.(this.queryParams.include);
|
|
460
445
|
}
|
|
446
|
+
|
|
447
|
+
return initialResults;
|
|
461
448
|
}
|
|
462
449
|
|
|
463
450
|
/**
|
|
464
451
|
* Subscribes to the query and receives updates using SPARQL.
|
|
452
|
+
* @deprecated Use subscribe() instead — now routes through Rust model subscription.
|
|
465
453
|
*/
|
|
466
454
|
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[];
|
|
455
|
+
return this.subscribe(callback);
|
|
482
456
|
}
|
|
483
457
|
|
|
484
458
|
/**
|
|
@@ -494,39 +468,16 @@ export class ModelQueryBuilder<T extends Ad4mModel> {
|
|
|
494
468
|
* ```
|
|
495
469
|
*/
|
|
496
470
|
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
|
-
}
|
|
471
|
+
const { totalCount } = await (this.ctor as any).executeModelQuery(this.perspective, { ...this.queryParams, limit: 0 }, this.modelClassName);
|
|
472
|
+
return totalCount;
|
|
516
473
|
}
|
|
517
474
|
|
|
518
475
|
/**
|
|
519
476
|
* Gets the total count of matching entities using SPARQL.
|
|
520
|
-
* Delegates to count()
|
|
477
|
+
* Delegates to count().
|
|
521
478
|
*/
|
|
522
479
|
async countSparql(): Promise<number> {
|
|
523
|
-
|
|
524
|
-
this.engineFlag = 'sparql';
|
|
525
|
-
try {
|
|
526
|
-
return await this.count();
|
|
527
|
-
} finally {
|
|
528
|
-
this.engineFlag = prev;
|
|
529
|
-
}
|
|
480
|
+
return await this.count();
|
|
530
481
|
}
|
|
531
482
|
|
|
532
483
|
/**
|
|
@@ -556,61 +507,60 @@ export class ModelQueryBuilder<T extends Ad4mModel> {
|
|
|
556
507
|
* builder.dispose();
|
|
557
508
|
* ```
|
|
558
509
|
*
|
|
559
|
-
* @remarks
|
|
560
|
-
* By default, this uses SPARQL live queries for real-time updates.
|
|
561
|
-
* Prolog subscriptions remain available via `.useSPARQL(false)`.
|
|
562
510
|
*/
|
|
563
511
|
async countSubscribe(callback: (count: number) => void): Promise<number> {
|
|
564
512
|
// Clean up any existing subscription
|
|
565
513
|
this.dispose();
|
|
566
514
|
|
|
567
|
-
|
|
568
|
-
|
|
569
|
-
|
|
515
|
+
const countParams = { ...this.queryParams, limit: 0 };
|
|
516
|
+
const { className, queryJson, shapeJson } = (this.ctor as any).prepareModelQueryParams(
|
|
517
|
+
countParams, this.modelClassName
|
|
518
|
+
);
|
|
570
519
|
|
|
571
|
-
|
|
572
|
-
|
|
573
|
-
|
|
574
|
-
};
|
|
520
|
+
const { subscriptionId, result: initialModelResult } = await this.perspective.modelSubscribe(
|
|
521
|
+
className, queryJson, shapeJson
|
|
522
|
+
);
|
|
575
523
|
|
|
576
|
-
|
|
577
|
-
const
|
|
578
|
-
|
|
579
|
-
|
|
580
|
-
|
|
581
|
-
|
|
582
|
-
|
|
583
|
-
|
|
584
|
-
|
|
585
|
-
|
|
586
|
-
|
|
587
|
-
|
|
588
|
-
|
|
589
|
-
|
|
590
|
-
|
|
591
|
-
|
|
592
|
-
|
|
593
|
-
|
|
524
|
+
const parseCount = (raw: any): number => {
|
|
525
|
+
const data = typeof raw === 'string' ? JSON.parse(raw) : raw;
|
|
526
|
+
return data.totalCount ?? 0;
|
|
527
|
+
};
|
|
528
|
+
|
|
529
|
+
const initialCount = parseCount(initialModelResult);
|
|
530
|
+
|
|
531
|
+
const unsubscribe = this.perspective.client.subscribeToQueryUpdates(
|
|
532
|
+
subscriptionId,
|
|
533
|
+
(rawResult: any) => {
|
|
534
|
+
if (rawResult && rawResult.isInit) return;
|
|
535
|
+
try {
|
|
536
|
+
callback(parseCount(rawResult));
|
|
537
|
+
} catch (e) {
|
|
538
|
+
console.error('Count subscription update parse error:', e);
|
|
539
|
+
}
|
|
540
|
+
},
|
|
541
|
+
);
|
|
542
|
+
|
|
543
|
+
const keepaliveTimer = setInterval(() => {
|
|
544
|
+
this.perspective.client.keepAliveQuery(this.perspective.uuid, subscriptionId).catch(() => {});
|
|
545
|
+
}, 30000);
|
|
546
|
+
|
|
547
|
+
this.currentSubscription = {
|
|
548
|
+
dispose: () => {
|
|
549
|
+
clearInterval(keepaliveTimer);
|
|
550
|
+
unsubscribe();
|
|
551
|
+
this.perspective.client.disposeQuerySubscription(this.perspective.uuid, subscriptionId).catch(() => {});
|
|
552
|
+
},
|
|
553
|
+
};
|
|
554
|
+
|
|
555
|
+
return initialCount;
|
|
594
556
|
}
|
|
595
557
|
|
|
596
558
|
/**
|
|
597
559
|
* Subscribes to count updates using SPARQL.
|
|
560
|
+
* @deprecated Use countSubscribe() instead — now routes through Rust model subscription.
|
|
598
561
|
*/
|
|
599
562
|
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;
|
|
563
|
+
return this.countSubscribe(callback);
|
|
614
564
|
}
|
|
615
565
|
|
|
616
566
|
/**
|
|
@@ -630,31 +580,16 @@ export class ModelQueryBuilder<T extends Ad4mModel> {
|
|
|
630
580
|
*/
|
|
631
581
|
async paginate(pageSize: number, pageNumber: number): Promise<PaginationResult<T>> {
|
|
632
582
|
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
|
-
}
|
|
583
|
+
const { results, totalCount } = await (this.ctor as any).executeModelQuery(this.perspective, paginationQuery, this.modelClassName);
|
|
584
|
+
return { results, totalCount, pageSize, pageNumber };
|
|
644
585
|
}
|
|
645
586
|
|
|
646
587
|
/**
|
|
647
588
|
* Gets a page of results using SPARQL.
|
|
648
|
-
* Delegates to paginate()
|
|
589
|
+
* Delegates to paginate().
|
|
649
590
|
*/
|
|
650
591
|
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
|
-
}
|
|
592
|
+
return await this.paginate(pageSize, pageNumber);
|
|
658
593
|
}
|
|
659
594
|
|
|
660
595
|
/**
|
|
@@ -686,9 +621,6 @@ export class ModelQueryBuilder<T extends Ad4mModel> {
|
|
|
686
621
|
* builder.dispose();
|
|
687
622
|
* ```
|
|
688
623
|
*
|
|
689
|
-
* @remarks
|
|
690
|
-
* By default, this uses SPARQL live queries for real-time updates.
|
|
691
|
-
* Prolog subscriptions remain available via `.useSPARQL(false)`.
|
|
692
624
|
*/
|
|
693
625
|
async paginateSubscribe(
|
|
694
626
|
pageSize: number,
|
|
@@ -698,67 +630,69 @@ export class ModelQueryBuilder<T extends Ad4mModel> {
|
|
|
698
630
|
// Clean up any existing subscription
|
|
699
631
|
this.dispose();
|
|
700
632
|
|
|
701
|
-
const
|
|
633
|
+
const ctor = this.ctor;
|
|
702
634
|
|
|
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
|
-
this.
|
|
740
|
-
|
|
741
|
-
|
|
742
|
-
|
|
743
|
-
|
|
744
|
-
|
|
635
|
+
// Subscribe to the full result set (no limit/offset) so the subscription
|
|
636
|
+
// detects changes anywhere in the dataset. Rust builds trigger SPARQL
|
|
637
|
+
// from the shape predicates.
|
|
638
|
+
const subscriptionParams = { ...(this.queryParams || {}) };
|
|
639
|
+
delete subscriptionParams.limit;
|
|
640
|
+
delete subscriptionParams.offset;
|
|
641
|
+
const { className, queryJson, shapeJson } = (ctor as any).prepareModelQueryParams(
|
|
642
|
+
subscriptionParams, this.modelClassName
|
|
643
|
+
);
|
|
644
|
+
|
|
645
|
+
const { subscriptionId } = await this.perspective.modelSubscribe(
|
|
646
|
+
className, queryJson, shapeJson
|
|
647
|
+
);
|
|
648
|
+
|
|
649
|
+
// Build the paginated query for Rust endpoint (count: true fetches both results and totalCount in one call)
|
|
650
|
+
const paginatedQuery = {
|
|
651
|
+
...(this.queryParams || {}),
|
|
652
|
+
limit: pageSize,
|
|
653
|
+
offset: pageSize * (pageNumber - 1),
|
|
654
|
+
count: true,
|
|
655
|
+
};
|
|
656
|
+
|
|
657
|
+
const processResults = async () => {
|
|
658
|
+
const { results, totalCount } = await (ctor as any).executeModelQuery(this.perspective, paginatedQuery, this.modelClassName);
|
|
659
|
+
callback({ results, totalCount, pageSize, pageNumber });
|
|
660
|
+
};
|
|
661
|
+
|
|
662
|
+
const unsubscribe = this.perspective.client.subscribeToQueryUpdates(
|
|
663
|
+
subscriptionId,
|
|
664
|
+
(rawResult: any) => {
|
|
665
|
+
if (rawResult && rawResult.isInit) return;
|
|
666
|
+
processResults().catch(e => console.error('Paginate subscription error:', e));
|
|
667
|
+
},
|
|
668
|
+
);
|
|
669
|
+
|
|
670
|
+
const keepaliveTimer = setInterval(() => {
|
|
671
|
+
this.perspective.client.keepAliveQuery(this.perspective.uuid, subscriptionId).catch(() => {});
|
|
672
|
+
}, 30000);
|
|
673
|
+
|
|
674
|
+
this.currentSubscription = {
|
|
675
|
+
dispose: () => {
|
|
676
|
+
clearInterval(keepaliveTimer);
|
|
677
|
+
unsubscribe();
|
|
678
|
+
this.perspective.client.disposeQuerySubscription(this.perspective.uuid, subscriptionId).catch(() => {});
|
|
679
|
+
},
|
|
680
|
+
};
|
|
681
|
+
|
|
682
|
+
// Initial fetch (single call with count: true)
|
|
683
|
+
const { results, totalCount } = await (ctor as any).executeModelQuery(this.perspective, paginatedQuery, this.modelClassName);
|
|
684
|
+
return { results, totalCount, pageSize, pageNumber };
|
|
745
685
|
}
|
|
746
686
|
|
|
747
687
|
/**
|
|
748
688
|
* Subscribes to paginated results updates using SPARQL.
|
|
749
|
-
* Delegates to paginateSubscribe()
|
|
689
|
+
* Delegates to paginateSubscribe().
|
|
750
690
|
*/
|
|
751
691
|
async paginateSubscribeSparql(
|
|
752
692
|
pageSize: number,
|
|
753
693
|
pageNumber: number,
|
|
754
694
|
callback: (results: PaginationResult<T>) => void
|
|
755
695
|
): 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
|
-
}
|
|
696
|
+
return await this.paginateSubscribe(pageSize, pageNumber, callback);
|
|
763
697
|
}
|
|
764
698
|
}
|
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, {});
|