@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
|
@@ -9,10 +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 } from "./query-sparql";
|
|
15
|
-
import { pooledSubscribe } from "./subscription-pool";
|
|
16
14
|
|
|
17
15
|
/** Query builder for Ad4mModel queries.
|
|
18
16
|
* Allows building queries with a fluent interface and either running them once
|
|
@@ -40,7 +38,6 @@ export class ModelQueryBuilder<T extends Ad4mModel> {
|
|
|
40
38
|
private modelClassName: string | null = null;
|
|
41
39
|
private ctor: typeof Ad4mModel;
|
|
42
40
|
private currentSubscription?: any;
|
|
43
|
-
private engineFlag: 'sparql' | 'prolog' = 'sparql';
|
|
44
41
|
|
|
45
42
|
constructor(perspective: PerspectiveProxy, ctor: typeof Ad4mModel, query?: Query) {
|
|
46
43
|
this.perspective = perspective;
|
|
@@ -53,7 +50,7 @@ export class ModelQueryBuilder<T extends Ad4mModel> {
|
|
|
53
50
|
*
|
|
54
51
|
* This method:
|
|
55
52
|
* 1. Stops the keepalive signals to the subscription
|
|
56
|
-
* 2. Unsubscribes from
|
|
53
|
+
* 2. Unsubscribes from subscription updates
|
|
57
54
|
* 3. Notifies the backend to clean up subscription resources
|
|
58
55
|
* 4. Clears the subscription reference
|
|
59
56
|
*
|
|
@@ -226,6 +223,29 @@ export class ModelQueryBuilder<T extends Ad4mModel> {
|
|
|
226
223
|
return this;
|
|
227
224
|
}
|
|
228
225
|
|
|
226
|
+
/**
|
|
227
|
+
* Opts in to evaluating SPARQL property getters during collection hydration.
|
|
228
|
+
*
|
|
229
|
+
* By default, collection queries skip getter evaluation for performance.
|
|
230
|
+
* Call `.deepQuery()` when you need getter-backed properties in the result set.
|
|
231
|
+
*
|
|
232
|
+
* @returns The query builder for chaining
|
|
233
|
+
*
|
|
234
|
+
* @example
|
|
235
|
+
* ```typescript
|
|
236
|
+
* const messages = await Message.query(perspective)
|
|
237
|
+
* .parent(channel)
|
|
238
|
+
* .deepQuery()
|
|
239
|
+
* .limit(30)
|
|
240
|
+
* .get();
|
|
241
|
+
* // messages[i].replyingTo is populated
|
|
242
|
+
* ```
|
|
243
|
+
*/
|
|
244
|
+
deepQuery(): ModelQueryBuilder<T> {
|
|
245
|
+
(this.queryParams as any).deepQuery = true;
|
|
246
|
+
return this;
|
|
247
|
+
}
|
|
248
|
+
|
|
229
249
|
/**
|
|
230
250
|
* Specifies which relations to eager-load (hydrate into model instances).
|
|
231
251
|
*
|
|
@@ -264,9 +284,9 @@ export class ModelQueryBuilder<T extends Ad4mModel> {
|
|
|
264
284
|
|
|
265
285
|
/**
|
|
266
286
|
* Sets the query engine to use.
|
|
287
|
+
* @deprecated Prolog engine has been removed. All queries use SPARQL/Rust.
|
|
267
288
|
*/
|
|
268
|
-
engine(
|
|
269
|
-
this.engineFlag = eng;
|
|
289
|
+
engine(_eng: 'sparql' | 'prolog'): ModelQueryBuilder<T> {
|
|
270
290
|
return this;
|
|
271
291
|
}
|
|
272
292
|
|
|
@@ -283,16 +303,7 @@ export class ModelQueryBuilder<T extends Ad4mModel> {
|
|
|
283
303
|
* ```
|
|
284
304
|
*/
|
|
285
305
|
async get(): Promise<T[]> {
|
|
286
|
-
|
|
287
|
-
if (this.engineFlag === 'sparql') {
|
|
288
|
-
results = await this.executeSparqlQuery();
|
|
289
|
-
} else {
|
|
290
|
-
const query = await this.ctor.queryToProlog(this.perspective, this.queryParams, this.modelClassName);
|
|
291
|
-
const result = await this.perspective.infer(query);
|
|
292
|
-
({ results } = await this.ctor.instancesFromPrologResult(this.perspective, this.queryParams, result) as { results: T[] });
|
|
293
|
-
}
|
|
294
|
-
|
|
295
|
-
return results;
|
|
306
|
+
return await this.executeSparqlQuery();
|
|
296
307
|
}
|
|
297
308
|
|
|
298
309
|
/**
|
|
@@ -303,24 +314,13 @@ export class ModelQueryBuilder<T extends Ad4mModel> {
|
|
|
303
314
|
}
|
|
304
315
|
|
|
305
316
|
/**
|
|
306
|
-
* Shared
|
|
317
|
+
* Shared query execution logic — routes through the executor-side modelQuery endpoint.
|
|
307
318
|
*/
|
|
308
319
|
private async executeSparqlQuery(): Promise<T[]> {
|
|
309
|
-
const
|
|
310
|
-
const rawResult = await this.perspective.querySparql(sparqlQuery);
|
|
311
|
-
const { results } = await this.processSparqlResult(rawResult);
|
|
320
|
+
const { results } = await (this.ctor as any).executeModelQuery(this.perspective, this.queryParams, this.modelClassName);
|
|
312
321
|
return results;
|
|
313
322
|
}
|
|
314
323
|
|
|
315
|
-
/**
|
|
316
|
-
* Groups raw SPARQL results and hydrates them into model instances.
|
|
317
|
-
* Centralises the repeated groupSPARQLResults → instancesFromQueryResult pipeline.
|
|
318
|
-
*/
|
|
319
|
-
private async processSparqlResult(rawResult: any, queryOverride?: Query): Promise<{ results: T[], totalCount: number }> {
|
|
320
|
-
const grouped = groupSPARQLResults(Array.isArray(rawResult) ? rawResult : []);
|
|
321
|
-
return await this.ctor.instancesFromQueryResult(this.perspective, queryOverride || this.queryParams, grouped) as { results: T[], totalCount: number };
|
|
322
|
-
}
|
|
323
|
-
|
|
324
324
|
/**
|
|
325
325
|
* Returns the first matching instance, or `null` if none match.
|
|
326
326
|
*
|
|
@@ -368,9 +368,6 @@ export class ModelQueryBuilder<T extends Ad4mModel> {
|
|
|
368
368
|
* builder.dispose();
|
|
369
369
|
* ```
|
|
370
370
|
*
|
|
371
|
-
* @remarks
|
|
372
|
-
* By default, this uses SPARQL live queries for real-time updates.
|
|
373
|
-
* Prolog subscriptions remain available via `.useSPARQL(false)`.
|
|
374
371
|
*/
|
|
375
372
|
async subscribe(callback: (results: T[]) => void): Promise<T[]> {
|
|
376
373
|
// Clean up any existing subscription
|
|
@@ -378,81 +375,84 @@ export class ModelQueryBuilder<T extends Ad4mModel> {
|
|
|
378
375
|
|
|
379
376
|
const ctor = this.ctor;
|
|
380
377
|
|
|
381
|
-
|
|
382
|
-
|
|
383
|
-
|
|
384
|
-
|
|
385
|
-
let lastResultFingerprint: string | null = null;
|
|
386
|
-
|
|
387
|
-
const buildFingerprint = (results: any[]) => {
|
|
388
|
-
if (results.length === 0) return '0:';
|
|
389
|
-
const ids = results.map((r: any) => r.id || '').sort().join(',');
|
|
390
|
-
const ts = results.map((r: any) => r.updatedAt || r.timestamp || '').join(',');
|
|
391
|
-
return `${results.length}:${ids}:${ts}`;
|
|
392
|
-
};
|
|
393
|
-
|
|
394
|
-
const hydrate = async (rawResult: any) => {
|
|
395
|
-
const { results } = await this.processSparqlResult(rawResult);
|
|
396
|
-
return results;
|
|
397
|
-
};
|
|
398
|
-
|
|
399
|
-
const pooled = await pooledSubscribe(
|
|
400
|
-
this.perspective,
|
|
401
|
-
sparqlQuery,
|
|
402
|
-
hydrate,
|
|
403
|
-
(hydratedResults: T[]) => {
|
|
404
|
-
const fp = buildFingerprint(hydratedResults);
|
|
405
|
-
if (fp === lastResultFingerprint) return;
|
|
406
|
-
lastResultFingerprint = fp;
|
|
407
|
-
callback(hydratedResults);
|
|
408
|
-
},
|
|
409
|
-
);
|
|
378
|
+
// Build the model query params (className, queryJson, shapeJson)
|
|
379
|
+
const { className, queryJson, shapeJson } = (ctor as any).prepareModelQueryParams(
|
|
380
|
+
this.queryParams, this.modelClassName
|
|
381
|
+
);
|
|
410
382
|
|
|
411
|
-
|
|
412
|
-
|
|
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
|
+
);
|
|
413
388
|
|
|
414
|
-
|
|
415
|
-
|
|
416
|
-
|
|
417
|
-
}
|
|
418
|
-
|
|
419
|
-
|
|
420
|
-
|
|
421
|
-
|
|
422
|
-
|
|
423
|
-
|
|
424
|
-
|
|
425
|
-
|
|
426
|
-
|
|
427
|
-
|
|
428
|
-
|
|
429
|
-
|
|
430
|
-
|
|
431
|
-
|
|
432
|
-
|
|
433
|
-
|
|
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);
|
|
434
445
|
}
|
|
446
|
+
|
|
447
|
+
return initialResults;
|
|
435
448
|
}
|
|
436
449
|
|
|
437
450
|
/**
|
|
438
451
|
* Subscribes to the query and receives updates using SPARQL.
|
|
452
|
+
* @deprecated Use subscribe() instead — now routes through Rust model subscription.
|
|
439
453
|
*/
|
|
440
454
|
async subscribeSparql(callback: (results: T[]) => void): Promise<T[]> {
|
|
441
|
-
this.
|
|
442
|
-
|
|
443
|
-
const sparqlQuery = await this.ctor.queryToSPARQL(this.perspective, this.queryParams);
|
|
444
|
-
this.currentSubscription = await this.perspective.subscribeQuery(sparqlQuery);
|
|
445
|
-
|
|
446
|
-
const processResults = async (result: any) => {
|
|
447
|
-
const { results } = await this.processSparqlResult(result);
|
|
448
|
-
callback(results as T[]);
|
|
449
|
-
};
|
|
450
|
-
|
|
451
|
-
this.currentSubscription.onResult(processResults);
|
|
452
|
-
|
|
453
|
-
const { results } = await this.processSparqlResult(this.currentSubscription.result);
|
|
454
|
-
// Initial results returned via Promise only — callback is for subsequent updates
|
|
455
|
-
return results as T[];
|
|
455
|
+
return this.subscribe(callback);
|
|
456
456
|
}
|
|
457
457
|
|
|
458
458
|
/**
|
|
@@ -468,30 +468,16 @@ export class ModelQueryBuilder<T extends Ad4mModel> {
|
|
|
468
468
|
* ```
|
|
469
469
|
*/
|
|
470
470
|
async count(): Promise<number> {
|
|
471
|
-
|
|
472
|
-
|
|
473
|
-
const rawResult = await this.perspective.querySparql(sparqlQuery);
|
|
474
|
-
const { totalCount } = await this.processSparqlResult(rawResult);
|
|
475
|
-
return totalCount;
|
|
476
|
-
} else {
|
|
477
|
-
const query = await this.ctor.countQueryToProlog(this.perspective, this.queryParams, this.modelClassName);
|
|
478
|
-
const result = await this.perspective.infer(query);
|
|
479
|
-
return result?.[0]?.TotalCount || 0;
|
|
480
|
-
}
|
|
471
|
+
const { totalCount } = await (this.ctor as any).executeModelQuery(this.perspective, { ...this.queryParams, limit: 0 }, this.modelClassName);
|
|
472
|
+
return totalCount;
|
|
481
473
|
}
|
|
482
474
|
|
|
483
475
|
/**
|
|
484
476
|
* Gets the total count of matching entities using SPARQL.
|
|
485
|
-
* Delegates to count()
|
|
477
|
+
* Delegates to count().
|
|
486
478
|
*/
|
|
487
479
|
async countSparql(): Promise<number> {
|
|
488
|
-
|
|
489
|
-
this.engineFlag = 'sparql';
|
|
490
|
-
try {
|
|
491
|
-
return await this.count();
|
|
492
|
-
} finally {
|
|
493
|
-
this.engineFlag = prev;
|
|
494
|
-
}
|
|
480
|
+
return await this.count();
|
|
495
481
|
}
|
|
496
482
|
|
|
497
483
|
/**
|
|
@@ -521,61 +507,60 @@ export class ModelQueryBuilder<T extends Ad4mModel> {
|
|
|
521
507
|
* builder.dispose();
|
|
522
508
|
* ```
|
|
523
509
|
*
|
|
524
|
-
* @remarks
|
|
525
|
-
* By default, this uses SPARQL live queries for real-time updates.
|
|
526
|
-
* Prolog subscriptions remain available via `.useSPARQL(false)`.
|
|
527
510
|
*/
|
|
528
511
|
async countSubscribe(callback: (count: number) => void): Promise<number> {
|
|
529
512
|
// Clean up any existing subscription
|
|
530
513
|
this.dispose();
|
|
531
514
|
|
|
532
|
-
|
|
533
|
-
|
|
534
|
-
|
|
515
|
+
const countParams = { ...this.queryParams, limit: 0 };
|
|
516
|
+
const { className, queryJson, shapeJson } = (this.ctor as any).prepareModelQueryParams(
|
|
517
|
+
countParams, this.modelClassName
|
|
518
|
+
);
|
|
535
519
|
|
|
536
|
-
|
|
537
|
-
|
|
538
|
-
|
|
539
|
-
};
|
|
520
|
+
const { subscriptionId, result: initialModelResult } = await this.perspective.modelSubscribe(
|
|
521
|
+
className, queryJson, shapeJson
|
|
522
|
+
);
|
|
540
523
|
|
|
541
|
-
|
|
542
|
-
const
|
|
543
|
-
|
|
544
|
-
|
|
545
|
-
|
|
546
|
-
|
|
547
|
-
|
|
548
|
-
|
|
549
|
-
|
|
550
|
-
|
|
551
|
-
|
|
552
|
-
|
|
553
|
-
|
|
554
|
-
|
|
555
|
-
|
|
556
|
-
|
|
557
|
-
|
|
558
|
-
|
|
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;
|
|
559
556
|
}
|
|
560
557
|
|
|
561
558
|
/**
|
|
562
559
|
* Subscribes to count updates using SPARQL.
|
|
560
|
+
* @deprecated Use countSubscribe() instead — now routes through Rust model subscription.
|
|
563
561
|
*/
|
|
564
562
|
async countSubscribeSparql(callback: (count: number) => void): Promise<number> {
|
|
565
|
-
this.
|
|
566
|
-
|
|
567
|
-
const sparqlQuery = await this.ctor.queryToSPARQL(this.perspective, this.queryParams);
|
|
568
|
-
this.currentSubscription = await this.perspective.subscribeQuery(sparqlQuery);
|
|
569
|
-
|
|
570
|
-
const processResults = async (result: any) => {
|
|
571
|
-
const { totalCount } = await this.processSparqlResult(result);
|
|
572
|
-
callback(totalCount);
|
|
573
|
-
};
|
|
574
|
-
|
|
575
|
-
this.currentSubscription.onResult(processResults);
|
|
576
|
-
const { totalCount } = await this.processSparqlResult(this.currentSubscription.result);
|
|
577
|
-
// Initial count returned via Promise — callback for updates only
|
|
578
|
-
return totalCount;
|
|
563
|
+
return this.countSubscribe(callback);
|
|
579
564
|
}
|
|
580
565
|
|
|
581
566
|
/**
|
|
@@ -595,31 +580,16 @@ export class ModelQueryBuilder<T extends Ad4mModel> {
|
|
|
595
580
|
*/
|
|
596
581
|
async paginate(pageSize: number, pageNumber: number): Promise<PaginationResult<T>> {
|
|
597
582
|
const paginationQuery = { ...(this.queryParams || {}), limit: pageSize, offset: pageSize * (pageNumber - 1), count: true };
|
|
598
|
-
|
|
599
|
-
|
|
600
|
-
const result = await this.perspective.querySparql(sparqlQuery);
|
|
601
|
-
const { results, totalCount } = await this.processSparqlResult(result, paginationQuery) as ResultsWithTotalCount<T>;
|
|
602
|
-
return { results, totalCount, pageSize, pageNumber };
|
|
603
|
-
} else {
|
|
604
|
-
const prologQuery = await this.ctor.queryToProlog(this.perspective, paginationQuery, this.modelClassName);
|
|
605
|
-
const result = await this.perspective.infer(prologQuery);
|
|
606
|
-
const { results, totalCount } = (await this.ctor.instancesFromPrologResult(this.perspective, paginationQuery, result)) as ResultsWithTotalCount<T>;
|
|
607
|
-
return { results, totalCount, pageSize, pageNumber };
|
|
608
|
-
}
|
|
583
|
+
const { results, totalCount } = await (this.ctor as any).executeModelQuery(this.perspective, paginationQuery, this.modelClassName);
|
|
584
|
+
return { results, totalCount, pageSize, pageNumber };
|
|
609
585
|
}
|
|
610
586
|
|
|
611
587
|
/**
|
|
612
588
|
* Gets a page of results using SPARQL.
|
|
613
|
-
* Delegates to paginate()
|
|
589
|
+
* Delegates to paginate().
|
|
614
590
|
*/
|
|
615
591
|
async paginateSparql(pageSize: number, pageNumber: number): Promise<PaginationResult<T>> {
|
|
616
|
-
|
|
617
|
-
this.engineFlag = 'sparql';
|
|
618
|
-
try {
|
|
619
|
-
return await this.paginate(pageSize, pageNumber);
|
|
620
|
-
} finally {
|
|
621
|
-
this.engineFlag = prev;
|
|
622
|
-
}
|
|
592
|
+
return await this.paginate(pageSize, pageNumber);
|
|
623
593
|
}
|
|
624
594
|
|
|
625
595
|
/**
|
|
@@ -651,9 +621,6 @@ export class ModelQueryBuilder<T extends Ad4mModel> {
|
|
|
651
621
|
* builder.dispose();
|
|
652
622
|
* ```
|
|
653
623
|
*
|
|
654
|
-
* @remarks
|
|
655
|
-
* By default, this uses SPARQL live queries for real-time updates.
|
|
656
|
-
* Prolog subscriptions remain available via `.useSPARQL(false)`.
|
|
657
624
|
*/
|
|
658
625
|
async paginateSubscribe(
|
|
659
626
|
pageSize: number,
|
|
@@ -663,54 +630,69 @@ export class ModelQueryBuilder<T extends Ad4mModel> {
|
|
|
663
630
|
// Clean up any existing subscription
|
|
664
631
|
this.dispose();
|
|
665
632
|
|
|
666
|
-
const
|
|
633
|
+
const ctor = this.ctor;
|
|
667
634
|
|
|
668
|
-
|
|
669
|
-
|
|
670
|
-
|
|
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
|
+
};
|
|
671
656
|
|
|
672
|
-
|
|
673
|
-
|
|
674
|
-
|
|
675
|
-
|
|
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
|
+
};
|
|
676
661
|
|
|
677
|
-
|
|
678
|
-
|
|
679
|
-
|
|
680
|
-
|
|
681
|
-
|
|
682
|
-
|
|
683
|
-
|
|
684
|
-
|
|
685
|
-
|
|
686
|
-
|
|
687
|
-
|
|
688
|
-
|
|
689
|
-
|
|
690
|
-
|
|
691
|
-
|
|
692
|
-
|
|
693
|
-
|
|
694
|
-
|
|
695
|
-
|
|
696
|
-
|
|
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 };
|
|
697
685
|
}
|
|
698
686
|
|
|
699
687
|
/**
|
|
700
688
|
* Subscribes to paginated results updates using SPARQL.
|
|
701
|
-
* Delegates to paginateSubscribe()
|
|
689
|
+
* Delegates to paginateSubscribe().
|
|
702
690
|
*/
|
|
703
691
|
async paginateSubscribeSparql(
|
|
704
692
|
pageSize: number,
|
|
705
693
|
pageNumber: number,
|
|
706
694
|
callback: (results: PaginationResult<T>) => void
|
|
707
695
|
): Promise<PaginationResult<T>> {
|
|
708
|
-
|
|
709
|
-
this.engineFlag = 'sparql';
|
|
710
|
-
try {
|
|
711
|
-
return await this.paginateSubscribe(pageSize, pageNumber, callback);
|
|
712
|
-
} finally {
|
|
713
|
-
this.engineFlag = prev;
|
|
714
|
-
}
|
|
696
|
+
return await this.paginateSubscribe(pageSize, pageNumber, callback);
|
|
715
697
|
}
|
|
716
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, {});
|