@coasys/ad4m 0.13.0-test-interpretation-1 → 0.13.0-test-model-layer
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/lib/index.cjs +2409 -625
- package/lib/index.js +2406 -626
- package/lib/src/Literal.js +8 -0
- package/lib/src/ai/AIClient.js +6 -3
- package/lib/src/apiClient.d.ts +40 -4
- package/lib/src/apiClient.js +149 -9
- package/lib/src/generated/api/RunInterpretationRequest.d.ts +16 -0
- package/lib/src/index.d.ts +3 -1
- package/lib/src/index.js +2 -0
- package/lib/src/model/Ad4mModel.d.ts +34 -16
- package/lib/src/model/Ad4mModel.js +302 -63
- package/lib/src/model/Ad4mModel.test.js +480 -735
- package/lib/src/model/ModelQueryBuilder.js +2 -2
- package/lib/src/model/decorators.d.ts +199 -12
- package/lib/src/model/decorators.js +88 -32
- package/lib/src/model/json-schema.js +7 -21
- package/lib/src/model/model-manifest.d.ts +41 -0
- package/lib/src/model/model-manifest.js +11 -0
- package/lib/src/model/query-common.d.ts +2 -2
- package/lib/src/model/query-sparql.d.ts +62 -0
- package/lib/src/model/query-sparql.js +78 -15
- package/lib/src/model/query-sparql.test.js +92 -10
- package/lib/src/model/query-utils.d.ts +7 -2
- package/lib/src/model/query-utils.js +21 -11
- package/lib/src/model/shacl-gen.js +77 -15
- package/lib/src/model/types.d.ts +32 -8
- package/lib/src/neighbourhood/NeighbourhoodProxy.test.js +33 -33
- package/lib/src/perspectives/AutoProcessor.d.ts +198 -2
- package/lib/src/perspectives/FlowInstance.d.ts +187 -0
- package/lib/src/perspectives/FlowInstance.js +336 -0
- package/lib/src/perspectives/FlowModels.d.ts +94 -0
- package/lib/src/perspectives/FlowModels.js +182 -0
- package/lib/src/perspectives/InterpretationModels.d.ts +41 -3
- package/lib/src/perspectives/InterpretationModels.js +60 -26
- package/lib/src/perspectives/PerspectiveClient.d.ts +88 -7
- package/lib/src/perspectives/PerspectiveClient.js +138 -11
- package/lib/src/perspectives/PerspectiveProxy.d.ts +150 -57
- package/lib/src/perspectives/PerspectiveProxy.js +411 -287
- package/lib/src/perspectives/SparqlBindings.d.ts +24 -3
- package/lib/src/perspectives/SparqlBindings.js +57 -6
- package/lib/src/shacl/SHACLFlow.d.ts +273 -47
- package/lib/src/shacl/SHACLFlow.js +397 -88
- package/lib/src/shacl/SHACLShape.d.ts +19 -3
- package/lib/src/shacl/SHACLShape.js +30 -1
- package/lib/src/shacl/SHACLShape.test.js +82 -0
- package/lib/src/shacl/index.d.ts +1 -1
- package/lib/src/shacl/index.js +1 -1
- package/package.json +3 -3
- package/src/Literal.ts +7 -0
- package/src/ai/AIClient.ts +6 -3
- package/src/apiClient.test.ts +227 -0
- package/src/apiClient.ts +185 -9
- package/src/generated/api/RunInterpretationRequest.ts +19 -3
- package/src/index.ts +3 -1
- package/src/model/Ad4mModel.test.ts +729 -22
- package/src/model/Ad4mModel.ts +305 -66
- package/src/model/ModelQueryBuilder.ts +2 -2
- package/src/model/decorators.ts +278 -44
- package/src/model/json-schema.ts +10 -25
- package/src/model/query-common.ts +2 -2
- package/src/model/query-sparql.test.ts +114 -13
- package/src/model/query-sparql.ts +83 -14
- package/src/model/query-utils.ts +22 -12
- package/src/model/relation-filtering.test.ts +70 -20
- package/src/model/shacl-gen.ts +78 -13
- package/src/model/shacl-roundtrip.test.ts +134 -2
- package/src/model/types.ts +30 -8
- package/src/perspectives/AutoProcessor.ts +204 -2
- package/src/perspectives/FlowInstance.ts +369 -0
- package/src/perspectives/FlowModels.ts +157 -0
- package/src/perspectives/InterpretationModels.ts +91 -21
- package/src/perspectives/PerspectiveClient.test.ts +67 -6
- package/src/perspectives/PerspectiveClient.ts +190 -14
- package/src/perspectives/PerspectiveProxy.test.ts +406 -0
- package/src/perspectives/PerspectiveProxy.ts +494 -308
- package/src/perspectives/SparqlBindings.test.ts +134 -0
- package/src/perspectives/SparqlBindings.ts +57 -6
- package/src/perspectives/shacl-rpc.test.ts +258 -0
- package/src/shacl/SHACLFlow.test.ts +762 -35
- package/src/shacl/SHACLFlow.ts +680 -112
- package/src/shacl/SHACLShape.test.ts +30 -4
- package/src/shacl/SHACLShape.ts +59 -6
- package/src/shacl/index.ts +1 -1
- package/lib/src/generated/rest/AIModelLoadingStatus.d.ts +0 -7
- package/lib/src/generated/rest/AIModelLoadingStatus.js +0 -2
- package/lib/src/generated/rest/AddAgentInfosRequest.d.ts +0 -3
- package/lib/src/generated/rest/AddAgentInfosRequest.js +0 -2
- package/lib/src/generated/rest/AddLinkExpressionRequest.d.ts +0 -6
- package/lib/src/generated/rest/AddLinkExpressionRequest.js +0 -1
- package/lib/src/generated/rest/AddLinkRequest.d.ts +0 -6
- package/lib/src/generated/rest/AddLinkRequest.js +0 -1
- package/lib/src/generated/rest/AddLinksBulkRequest.d.ts +0 -6
- package/lib/src/generated/rest/AddLinksBulkRequest.js +0 -1
- package/lib/src/generated/rest/AddSdnaRequest.d.ts +0 -6
- package/lib/src/generated/rest/AddSdnaRequest.js +0 -2
- package/lib/src/generated/rest/ApplyTemplateRequest.d.ts +0 -4
- package/lib/src/generated/rest/ApplyTemplateRequest.js +0 -2
- package/lib/src/generated/rest/AuthInfoInput.d.ts +0 -10
- package/lib/src/generated/rest/AuthInfoInput.js +0 -1
- package/lib/src/generated/rest/BroadcastRequest.d.ts +0 -6
- package/lib/src/generated/rest/BroadcastRequest.js +0 -1
- package/lib/src/generated/rest/CapabilityInput.d.ts +0 -5
- package/lib/src/generated/rest/CapabilityInput.js +0 -1
- package/lib/src/generated/rest/CommitBatchRequest.d.ts +0 -3
- package/lib/src/generated/rest/CommitBatchRequest.js +0 -2
- package/lib/src/generated/rest/ComputeLogEntry.d.ts +0 -9
- package/lib/src/generated/rest/ComputeLogEntry.js +0 -2
- package/lib/src/generated/rest/CreateExpressionRequest.d.ts +0 -4
- package/lib/src/generated/rest/CreateExpressionRequest.js +0 -2
- package/lib/src/generated/rest/CreatePerspectiveRequest.d.ts +0 -3
- package/lib/src/generated/rest/CreatePerspectiveRequest.js +0 -2
- package/lib/src/generated/rest/CreateSubjectRequest.d.ts +0 -6
- package/lib/src/generated/rest/CreateSubjectRequest.js +0 -2
- package/lib/src/generated/rest/CreateUserRequest.d.ts +0 -4
- package/lib/src/generated/rest/CreateUserRequest.js +0 -2
- package/lib/src/generated/rest/CreateUserResponse.d.ts +0 -5
- package/lib/src/generated/rest/CreateUserResponse.js +0 -2
- package/lib/src/generated/rest/DecoratedExpressionProof.d.ts +0 -6
- package/lib/src/generated/rest/DecoratedExpressionProof.js +0 -2
- package/lib/src/generated/rest/DecoratedLinkExpression.d.ts +0 -10
- package/lib/src/generated/rest/DecoratedLinkExpression.js +0 -1
- package/lib/src/generated/rest/DisposeQueryRequest.d.ts +0 -3
- package/lib/src/generated/rest/DisposeQueryRequest.js +0 -2
- package/lib/src/generated/rest/EmailTestRequest.d.ts +0 -6
- package/lib/src/generated/rest/EmailTestRequest.js +0 -2
- package/lib/src/generated/rest/EmbedRequest.d.ts +0 -4
- package/lib/src/generated/rest/EmbedRequest.js +0 -2
- package/lib/src/generated/rest/EntanglementProofInput.d.ts +0 -6
- package/lib/src/generated/rest/EntanglementProofInput.js +0 -2
- package/lib/src/generated/rest/EntanglementProofPreflightRequest.d.ts +0 -4
- package/lib/src/generated/rest/EntanglementProofPreflightRequest.js +0 -2
- package/lib/src/generated/rest/ExecuteCommandsRequest.d.ts +0 -4
- package/lib/src/generated/rest/ExecuteCommandsRequest.js +0 -2
- package/lib/src/generated/rest/ExportRequest.d.ts +0 -5
- package/lib/src/generated/rest/ExportRequest.js +0 -2
- package/lib/src/generated/rest/ExpressionManyRequest.d.ts +0 -3
- package/lib/src/generated/rest/ExpressionManyRequest.js +0 -2
- package/lib/src/generated/rest/ExpressionProof.d.ts +0 -4
- package/lib/src/generated/rest/ExpressionProof.js +0 -2
- package/lib/src/generated/rest/ExpressionProofInput.d.ts +0 -6
- package/lib/src/generated/rest/ExpressionProofInput.js +0 -2
- package/lib/src/generated/rest/FriendSendMessageRequest.d.ts +0 -3
- package/lib/src/generated/rest/FriendSendMessageRequest.js +0 -2
- package/lib/src/generated/rest/FriendsListRequest.d.ts +0 -3
- package/lib/src/generated/rest/FriendsListRequest.js +0 -2
- package/lib/src/generated/rest/GenerateAgentRequest.d.ts +0 -3
- package/lib/src/generated/rest/GenerateAgentRequest.js +0 -2
- package/lib/src/generated/rest/GenerateJwtRequest.d.ts +0 -4
- package/lib/src/generated/rest/GenerateJwtRequest.js +0 -2
- package/lib/src/generated/rest/GetSubjectDataRequest.d.ts +0 -4
- package/lib/src/generated/rest/GetSubjectDataRequest.js +0 -2
- package/lib/src/generated/rest/HostingInfoResponse.d.ts +0 -5
- package/lib/src/generated/rest/HostingInfoResponse.js +0 -2
- package/lib/src/generated/rest/HostingWalletResponse.d.ts +0 -4
- package/lib/src/generated/rest/HostingWalletResponse.js +0 -2
- package/lib/src/generated/rest/ImportAgentRequest.d.ts +0 -6
- package/lib/src/generated/rest/ImportAgentRequest.js +0 -2
- package/lib/src/generated/rest/ImportRequest.d.ts +0 -4
- package/lib/src/generated/rest/ImportRequest.js +0 -2
- package/lib/src/generated/rest/JoinNeighbourhoodRequest.d.ts +0 -3
- package/lib/src/generated/rest/JoinNeighbourhoodRequest.js +0 -2
- package/lib/src/generated/rest/KeepAliveQueryRequest.d.ts +0 -3
- package/lib/src/generated/rest/KeepAliveQueryRequest.js +0 -2
- package/lib/src/generated/rest/LanguageMetaInput.d.ts +0 -6
- package/lib/src/generated/rest/LanguageMetaInput.js +0 -2
- package/lib/src/generated/rest/Link.d.ts +0 -5
- package/lib/src/generated/rest/Link.js +0 -2
- package/lib/src/generated/rest/LinkExpression.d.ts +0 -10
- package/lib/src/generated/rest/LinkExpression.js +0 -1
- package/lib/src/generated/rest/LinkExpressionInput.d.ts +0 -10
- package/lib/src/generated/rest/LinkExpressionInput.js +0 -1
- package/lib/src/generated/rest/LinkInput.d.ts +0 -5
- package/lib/src/generated/rest/LinkInput.js +0 -2
- package/lib/src/generated/rest/LinkLanguageTemplatesRequest.d.ts +0 -3
- package/lib/src/generated/rest/LinkLanguageTemplatesRequest.js +0 -2
- package/lib/src/generated/rest/LinkMutationRequest.d.ts +0 -12
- package/lib/src/generated/rest/LinkMutationRequest.js +0 -1
- package/lib/src/generated/rest/LinkMutationResponse.d.ts +0 -9
- package/lib/src/generated/rest/LinkMutationResponse.js +0 -1
- package/lib/src/generated/rest/LinkMutations.d.ts +0 -6
- package/lib/src/generated/rest/LinkMutations.js +0 -1
- package/lib/src/generated/rest/LinkMutationsRequest.d.ts +0 -5
- package/lib/src/generated/rest/LinkMutationsRequest.js +0 -1
- package/lib/src/generated/rest/LinkStatus.d.ts +0 -1
- package/lib/src/generated/rest/LinkStatus.js +0 -2
- package/lib/src/generated/rest/LinkUpdateInput.d.ts +0 -5
- package/lib/src/generated/rest/LinkUpdateInput.js +0 -1
- package/lib/src/generated/rest/LockAgentRequest.d.ts +0 -3
- package/lib/src/generated/rest/LockAgentRequest.js +0 -2
- package/lib/src/generated/rest/LoginUserRequest.d.ts +0 -5
- package/lib/src/generated/rest/LoginUserRequest.js +0 -2
- package/lib/src/generated/rest/ModelType.d.ts +0 -1
- package/lib/src/generated/rest/ModelType.js +0 -2
- package/lib/src/generated/rest/NotificationGrantRequest.d.ts +0 -3
- package/lib/src/generated/rest/NotificationGrantRequest.js +0 -2
- package/lib/src/generated/rest/NotificationInput.d.ts +0 -10
- package/lib/src/generated/rest/NotificationInput.js +0 -2
- package/lib/src/generated/rest/OpenLinkRequest.d.ts +0 -3
- package/lib/src/generated/rest/OpenLinkRequest.js +0 -2
- package/lib/src/generated/rest/PermitCapabilityRequest.d.ts +0 -3
- package/lib/src/generated/rest/PermitCapabilityRequest.js +0 -2
- package/lib/src/generated/rest/PerspectiveInput.d.ts +0 -4
- package/lib/src/generated/rest/PerspectiveInput.js +0 -1
- package/lib/src/generated/rest/PromptRequest.d.ts +0 -4
- package/lib/src/generated/rest/PromptRequest.js +0 -2
- package/lib/src/generated/rest/PublicPerspectiveInput.d.ts +0 -4
- package/lib/src/generated/rest/PublicPerspectiveInput.js +0 -1
- package/lib/src/generated/rest/PublishLanguageRequest.d.ts +0 -5
- package/lib/src/generated/rest/PublishLanguageRequest.js +0 -1
- package/lib/src/generated/rest/PublishNeighbourhoodRequest.d.ts +0 -6
- package/lib/src/generated/rest/PublishNeighbourhoodRequest.js +0 -1
- package/lib/src/generated/rest/QueryRequest.d.ts +0 -7
- package/lib/src/generated/rest/QueryRequest.js +0 -2
- package/lib/src/generated/rest/RemoveLinkRequest.d.ts +0 -5
- package/lib/src/generated/rest/RemoveLinkRequest.js +0 -1
- package/lib/src/generated/rest/RemoveLinksBulkRequest.d.ts +0 -5
- package/lib/src/generated/rest/RemoveLinksBulkRequest.js +0 -1
- package/lib/src/generated/rest/RequestCapabilityRequest.d.ts +0 -4
- package/lib/src/generated/rest/RequestCapabilityRequest.js +0 -1
- package/lib/src/generated/rest/RequestPaymentRequest.d.ts +0 -3
- package/lib/src/generated/rest/RequestPaymentRequest.js +0 -2
- package/lib/src/generated/rest/RequestVerificationRequest.d.ts +0 -4
- package/lib/src/generated/rest/RequestVerificationRequest.js +0 -2
- package/lib/src/generated/rest/ResourceInput.d.ts +0 -4
- package/lib/src/generated/rest/ResourceInput.js +0 -2
- package/lib/src/generated/rest/SetDefaultModelRequest.d.ts +0 -4
- package/lib/src/generated/rest/SetDefaultModelRequest.js +0 -1
- package/lib/src/generated/rest/SetFreeHostingEnabledRequest.d.ts +0 -3
- package/lib/src/generated/rest/SetFreeHostingEnabledRequest.js +0 -2
- package/lib/src/generated/rest/SetHotWalletAddressRequest.d.ts +0 -3
- package/lib/src/generated/rest/SetHotWalletAddressRequest.js +0 -2
- package/lib/src/generated/rest/SetMultiUserRequest.d.ts +0 -3
- package/lib/src/generated/rest/SetMultiUserRequest.js +0 -2
- package/lib/src/generated/rest/SetOnlineStatusRequest.d.ts +0 -5
- package/lib/src/generated/rest/SetOnlineStatusRequest.js +0 -1
- package/lib/src/generated/rest/SetStatusRequest.d.ts +0 -3
- package/lib/src/generated/rest/SetStatusRequest.js +0 -2
- package/lib/src/generated/rest/SetUserFreeAccessRequest.d.ts +0 -4
- package/lib/src/generated/rest/SetUserFreeAccessRequest.js +0 -2
- package/lib/src/generated/rest/SignMessageRequest.d.ts +0 -3
- package/lib/src/generated/rest/SignMessageRequest.js +0 -2
- package/lib/src/generated/rest/SignalRequest.d.ts +0 -6
- package/lib/src/generated/rest/SignalRequest.js +0 -1
- package/lib/src/generated/rest/SubscribeQueryRequest.d.ts +0 -3
- package/lib/src/generated/rest/SubscribeQueryRequest.js +0 -2
- package/lib/src/generated/rest/SubscribeQueryResponse.d.ts +0 -4
- package/lib/src/generated/rest/SubscribeQueryResponse.js +0 -2
- package/lib/src/generated/rest/TrustedAgentsRequest.d.ts +0 -3
- package/lib/src/generated/rest/TrustedAgentsRequest.js +0 -2
- package/lib/src/generated/rest/UnlockAgentRequest.d.ts +0 -4
- package/lib/src/generated/rest/UnlockAgentRequest.js +0 -2
- package/lib/src/generated/rest/UpdateLinkRequest.d.ts +0 -7
- package/lib/src/generated/rest/UpdateLinkRequest.js +0 -1
- package/lib/src/generated/rest/UpdatePerspectiveRequest.d.ts +0 -3
- package/lib/src/generated/rest/UpdatePerspectiveRequest.js +0 -2
- package/lib/src/generated/rest/UpdateProfileRequest.d.ts +0 -5
- package/lib/src/generated/rest/UpdateProfileRequest.js +0 -1
- package/lib/src/generated/rest/UserStatistics.d.ts +0 -9
- package/lib/src/generated/rest/UserStatistics.js +0 -2
- package/lib/src/generated/rest/VerificationRequestResult.d.ts +0 -6
- package/lib/src/generated/rest/VerificationRequestResult.js +0 -2
- package/lib/src/generated/rest/VerifyEmailRequest.d.ts +0 -6
- package/lib/src/generated/rest/VerifyEmailRequest.js +0 -2
- package/lib/src/generated/rest/VerifySignatureRequest.d.ts +0 -5
- package/lib/src/generated/rest/VerifySignatureRequest.js +0 -2
- package/lib/src/generated/rest/WriteSettingsRequest.d.ts +0 -3
- package/lib/src/generated/rest/WriteSettingsRequest.js +0 -2
- package/lib/src/generated/rest/index.d.ts +0 -73
- package/lib/src/generated/rest/index.js +0 -8
- package/lib/src/generated/rest/routes.d.ts +0 -587
- package/lib/src/generated/rest/routes.js +0 -3
- 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/lib/src/perspectives/PerspectiveProxy.test.d.ts +0 -1
- package/lib/src/perspectives/PerspectiveProxy.test.js +0 -34
- package/lib/src/restClient.d.ts +0 -52
- package/lib/src/restClient.js +0 -227
|
@@ -1,44 +0,0 @@
|
|
|
1
|
-
/**
|
|
2
|
-
* SurrealQL query building utilities for Ad4mModel.
|
|
3
|
-
*
|
|
4
|
-
* Contains the graph-traversal WHERE clause builder, legacy
|
|
5
|
-
* subquery-based clause builders, SELECT-field builders, and
|
|
6
|
-
* the main `buildSurrealQLQuery()` function that produces a
|
|
7
|
-
* complete SurrealQL query string from a `Query` object.
|
|
8
|
-
*
|
|
9
|
-
* All functions are stateless — model metadata and relation metadata
|
|
10
|
-
* are passed in as parameters instead of accessed via `this`.
|
|
11
|
-
*
|
|
12
|
-
* @module
|
|
13
|
-
*/
|
|
14
|
-
import type { RelationMetadataEntry } from "./decorators";
|
|
15
|
-
import type { Where, Query, ModelMetadata } from "./types";
|
|
16
|
-
/**
|
|
17
|
-
* Builds WHERE clause filters using SurrealDB graph traversal syntax.
|
|
18
|
-
*
|
|
19
|
-
* Translates where conditions into `->link[WHERE ...]` / `<-link[WHERE ...]`
|
|
20
|
-
* filters that SurrealDB can optimize via graph indexes.
|
|
21
|
-
*
|
|
22
|
-
* @param metadata - Model metadata from `getModelMetadata()`
|
|
23
|
-
* @param allRelationsMetadata - Full relation metadata (needed for belongs-to
|
|
24
|
-
* direction detection)
|
|
25
|
-
* @param where - User-supplied where conditions
|
|
26
|
-
* @returns Combined AND-joined condition string, or empty string
|
|
27
|
-
*/
|
|
28
|
-
export declare function buildGraphTraversalWhereClause(metadata: ModelMetadata, allRelationsMetadata: Record<string, RelationMetadataEntry>, where?: Where): string;
|
|
29
|
-
/**
|
|
30
|
-
* Builds a complete SurrealQL query from a Query object and model metadata.
|
|
31
|
-
*
|
|
32
|
-
* This is the core implementation behind `Ad4mModel.queryToSurrealQL()`.
|
|
33
|
-
* It produces a graph-traversal query that:
|
|
34
|
-
* 1. Filters nodes by required predicates (conformance check)
|
|
35
|
-
* 2. Applies user WHERE conditions
|
|
36
|
-
* 3. Fetches all outgoing links for hydration
|
|
37
|
-
*
|
|
38
|
-
* @param metadata - Model metadata from `getModelMetadata()`
|
|
39
|
-
* @param allRelationsMetadata - Full relation registry (for belongs-to detection)
|
|
40
|
-
* @param query - Query parameters
|
|
41
|
-
* @param modelClass - The model class (for `resolveParentPredicate`)
|
|
42
|
-
* @returns Complete SurrealQL query string
|
|
43
|
-
*/
|
|
44
|
-
export declare function buildSurrealQLQuery(metadata: ModelMetadata, allRelationsMetadata: Record<string, RelationMetadataEntry>, query: Query, modelClass: any): string;
|
|
@@ -1,249 +0,0 @@
|
|
|
1
|
-
/**
|
|
2
|
-
* SurrealQL query building utilities for Ad4mModel.
|
|
3
|
-
*
|
|
4
|
-
* Contains the graph-traversal WHERE clause builder, legacy
|
|
5
|
-
* subquery-based clause builders, SELECT-field builders, and
|
|
6
|
-
* the main `buildSurrealQLQuery()` function that produces a
|
|
7
|
-
* complete SurrealQL query string from a `Query` object.
|
|
8
|
-
*
|
|
9
|
-
* All functions are stateless — model metadata and relation metadata
|
|
10
|
-
* are passed in as parameters instead of accessed via `this`.
|
|
11
|
-
*
|
|
12
|
-
* @module
|
|
13
|
-
*/
|
|
14
|
-
import { escapeSurrealString } from "../utils";
|
|
15
|
-
import { formatSurrealValue } from "./surreal-utils";
|
|
16
|
-
import { resolveParentPredicate } from "./query-common";
|
|
17
|
-
// ─── Graph Traversal WHERE Clause ────────────────────────────────────────────
|
|
18
|
-
/**
|
|
19
|
-
* Builds WHERE clause filters using SurrealDB graph traversal syntax.
|
|
20
|
-
*
|
|
21
|
-
* Translates where conditions into `->link[WHERE ...]` / `<-link[WHERE ...]`
|
|
22
|
-
* filters that SurrealDB can optimize via graph indexes.
|
|
23
|
-
*
|
|
24
|
-
* @param metadata - Model metadata from `getModelMetadata()`
|
|
25
|
-
* @param allRelationsMetadata - Full relation metadata (needed for belongs-to
|
|
26
|
-
* direction detection)
|
|
27
|
-
* @param where - User-supplied where conditions
|
|
28
|
-
* @returns Combined AND-joined condition string, or empty string
|
|
29
|
-
*/
|
|
30
|
-
export function buildGraphTraversalWhereClause(metadata, allRelationsMetadata, where) {
|
|
31
|
-
if (!where)
|
|
32
|
-
return '';
|
|
33
|
-
const conditions = [];
|
|
34
|
-
for (const [propertyName, condition] of Object.entries(where)) {
|
|
35
|
-
const isSpecial = ['id', 'author', 'timestamp'].includes(propertyName);
|
|
36
|
-
if (isSpecial) {
|
|
37
|
-
if (propertyName === 'author' || propertyName === 'timestamp') {
|
|
38
|
-
continue; // Filtered post-query in JS
|
|
39
|
-
}
|
|
40
|
-
const columnName = 'uri';
|
|
41
|
-
if (Array.isArray(condition)) {
|
|
42
|
-
const formattedValues = condition.map(v => formatSurrealValue(v)).join(', ');
|
|
43
|
-
conditions.push(`${columnName} IN [${formattedValues}]`);
|
|
44
|
-
}
|
|
45
|
-
else if (typeof condition === 'object' && condition !== null) {
|
|
46
|
-
const ops = condition;
|
|
47
|
-
if (ops.not !== undefined) {
|
|
48
|
-
if (Array.isArray(ops.not)) {
|
|
49
|
-
const formattedValues = ops.not.map(v => formatSurrealValue(v)).join(', ');
|
|
50
|
-
conditions.push(`${columnName} NOT IN [${formattedValues}]`);
|
|
51
|
-
}
|
|
52
|
-
else {
|
|
53
|
-
conditions.push(`${columnName} != ${formatSurrealValue(ops.not)}`);
|
|
54
|
-
}
|
|
55
|
-
}
|
|
56
|
-
if (ops.between !== undefined && Array.isArray(ops.between) && ops.between.length === 2) {
|
|
57
|
-
conditions.push(`${columnName} >= ${formatSurrealValue(ops.between[0])} AND ${columnName} <= ${formatSurrealValue(ops.between[1])}`);
|
|
58
|
-
}
|
|
59
|
-
if (ops.gt !== undefined) {
|
|
60
|
-
conditions.push(`${columnName} > ${formatSurrealValue(ops.gt)}`);
|
|
61
|
-
}
|
|
62
|
-
if (ops.gte !== undefined) {
|
|
63
|
-
conditions.push(`${columnName} >= ${formatSurrealValue(ops.gte)}`);
|
|
64
|
-
}
|
|
65
|
-
if (ops.lt !== undefined) {
|
|
66
|
-
conditions.push(`${columnName} < ${formatSurrealValue(ops.lt)}`);
|
|
67
|
-
}
|
|
68
|
-
if (ops.lte !== undefined) {
|
|
69
|
-
conditions.push(`${columnName} <= ${formatSurrealValue(ops.lte)}`);
|
|
70
|
-
}
|
|
71
|
-
if (ops.contains !== undefined) {
|
|
72
|
-
conditions.push(`${columnName} CONTAINS ${formatSurrealValue(ops.contains)}`);
|
|
73
|
-
}
|
|
74
|
-
}
|
|
75
|
-
else {
|
|
76
|
-
conditions.push(`${columnName} = ${formatSurrealValue(condition)}`);
|
|
77
|
-
}
|
|
78
|
-
}
|
|
79
|
-
else {
|
|
80
|
-
// Regular properties — check relation metadata first for direction
|
|
81
|
-
const relMeta = allRelationsMetadata[propertyName];
|
|
82
|
-
const isBelongs = relMeta?.kind === 'belongsToOne' || relMeta?.kind === 'belongsToMany';
|
|
83
|
-
if (relMeta) {
|
|
84
|
-
const predicate = escapeSurrealString(relMeta.predicate);
|
|
85
|
-
if (Array.isArray(condition)) {
|
|
86
|
-
const formattedValues = condition.map(v => formatSurrealValue(v)).join(', ');
|
|
87
|
-
if (isBelongs) {
|
|
88
|
-
conditions.push(`count(<-link[WHERE predicate = '${predicate}' AND in.uri IN [${formattedValues}]]) > 0`);
|
|
89
|
-
}
|
|
90
|
-
else {
|
|
91
|
-
conditions.push(`count(->link[WHERE predicate = '${predicate}' AND out.uri IN [${formattedValues}]]) > 0`);
|
|
92
|
-
}
|
|
93
|
-
}
|
|
94
|
-
else if (typeof condition === 'object' && condition !== null) {
|
|
95
|
-
const ops = condition;
|
|
96
|
-
if (ops.not !== undefined) {
|
|
97
|
-
if (Array.isArray(ops.not)) {
|
|
98
|
-
const formattedValues = ops.not.map(v => formatSurrealValue(v)).join(', ');
|
|
99
|
-
if (isBelongs) {
|
|
100
|
-
conditions.push(`count(<-link[WHERE predicate = '${predicate}' AND in.uri IN [${formattedValues}]]) = 0`);
|
|
101
|
-
}
|
|
102
|
-
else {
|
|
103
|
-
conditions.push(`count(->link[WHERE predicate = '${predicate}' AND out.uri IN [${formattedValues}]]) = 0`);
|
|
104
|
-
}
|
|
105
|
-
}
|
|
106
|
-
else {
|
|
107
|
-
if (isBelongs) {
|
|
108
|
-
conditions.push(`count(<-link[WHERE predicate = '${predicate}' AND in.uri = ${formatSurrealValue(ops.not)}]) = 0`);
|
|
109
|
-
}
|
|
110
|
-
else {
|
|
111
|
-
conditions.push(`count(->link[WHERE predicate = '${predicate}' AND out.uri = ${formatSurrealValue(ops.not)}]) = 0`);
|
|
112
|
-
}
|
|
113
|
-
}
|
|
114
|
-
}
|
|
115
|
-
}
|
|
116
|
-
else {
|
|
117
|
-
if (isBelongs) {
|
|
118
|
-
conditions.push(`count(<-link[WHERE predicate = '${predicate}' AND in.uri = ${formatSurrealValue(condition)}]) > 0`);
|
|
119
|
-
}
|
|
120
|
-
else {
|
|
121
|
-
conditions.push(`count(->link[WHERE predicate = '${predicate}' AND out.uri = ${formatSurrealValue(condition)}]) > 0`);
|
|
122
|
-
}
|
|
123
|
-
}
|
|
124
|
-
continue;
|
|
125
|
-
}
|
|
126
|
-
const propMeta = metadata.properties[propertyName];
|
|
127
|
-
if (!propMeta)
|
|
128
|
-
continue;
|
|
129
|
-
const predicate = escapeSurrealString(propMeta.predicate);
|
|
130
|
-
const targetField = propMeta.resolveLanguage === 'literal' ? 'fn::parse_literal(out.uri)' : 'out.uri';
|
|
131
|
-
if (Array.isArray(condition)) {
|
|
132
|
-
const formattedValues = condition.map(v => formatSurrealValue(v)).join(', ');
|
|
133
|
-
conditions.push(`count(->link[WHERE predicate = '${predicate}' AND ${targetField} IN [${formattedValues}]]) > 0`);
|
|
134
|
-
}
|
|
135
|
-
else if (typeof condition === 'object' && condition !== null) {
|
|
136
|
-
const ops = condition;
|
|
137
|
-
if (ops.not !== undefined) {
|
|
138
|
-
if (Array.isArray(ops.not)) {
|
|
139
|
-
const formattedValues = ops.not.map(v => formatSurrealValue(v)).join(', ');
|
|
140
|
-
conditions.push(`count(->link[WHERE predicate = '${predicate}' AND ${targetField} IN [${formattedValues}]]) = 0`);
|
|
141
|
-
}
|
|
142
|
-
else {
|
|
143
|
-
conditions.push(`count(->link[WHERE predicate = '${predicate}' AND ${targetField} = ${formatSurrealValue(ops.not)}]) = 0`);
|
|
144
|
-
}
|
|
145
|
-
}
|
|
146
|
-
const hasComparisonOps = ops.gt !== undefined || ops.gte !== undefined ||
|
|
147
|
-
ops.lt !== undefined || ops.lte !== undefined ||
|
|
148
|
-
ops.between !== undefined || ops.contains !== undefined;
|
|
149
|
-
if (hasComparisonOps) {
|
|
150
|
-
conditions.push(`count(->link[WHERE predicate = '${predicate}']) > 0`);
|
|
151
|
-
}
|
|
152
|
-
}
|
|
153
|
-
else {
|
|
154
|
-
conditions.push(`count(->link[WHERE predicate = '${predicate}' AND ${targetField} = ${formatSurrealValue(condition)}]) > 0`);
|
|
155
|
-
}
|
|
156
|
-
}
|
|
157
|
-
}
|
|
158
|
-
return conditions.join(' AND ');
|
|
159
|
-
}
|
|
160
|
-
// ─── Main Query Builder ─────────────────────────────────────────────────────
|
|
161
|
-
/**
|
|
162
|
-
* Builds a complete SurrealQL query from a Query object and model metadata.
|
|
163
|
-
*
|
|
164
|
-
* This is the core implementation behind `Ad4mModel.queryToSurrealQL()`.
|
|
165
|
-
* It produces a graph-traversal query that:
|
|
166
|
-
* 1. Filters nodes by required predicates (conformance check)
|
|
167
|
-
* 2. Applies user WHERE conditions
|
|
168
|
-
* 3. Fetches all outgoing links for hydration
|
|
169
|
-
*
|
|
170
|
-
* @param metadata - Model metadata from `getModelMetadata()`
|
|
171
|
-
* @param allRelationsMetadata - Full relation registry (for belongs-to detection)
|
|
172
|
-
* @param query - Query parameters
|
|
173
|
-
* @param modelClass - The model class (for `resolveParentPredicate`)
|
|
174
|
-
* @returns Complete SurrealQL query string
|
|
175
|
-
*/
|
|
176
|
-
export function buildSurrealQLQuery(metadata, allRelationsMetadata, query, modelClass) {
|
|
177
|
-
const { where } = query;
|
|
178
|
-
// Build graph traversal filters for required predicates
|
|
179
|
-
const graphTraversalFilters = [];
|
|
180
|
-
// Parent filter
|
|
181
|
-
if (query.parent) {
|
|
182
|
-
const parentPredicate = resolveParentPredicate(query.parent, modelClass);
|
|
183
|
-
graphTraversalFilters.push(`count(<-link[WHERE in.uri = ${formatSurrealValue(query.parent.id)} AND predicate = '${escapeSurrealString(parentPredicate)}']) > 0`);
|
|
184
|
-
}
|
|
185
|
-
// Required property filters
|
|
186
|
-
for (const [, propMeta] of Object.entries(metadata.properties)) {
|
|
187
|
-
if (propMeta.required) {
|
|
188
|
-
if (propMeta.getter)
|
|
189
|
-
continue;
|
|
190
|
-
if (propMeta.flag && propMeta.initial) {
|
|
191
|
-
graphTraversalFilters.push(`count(->link[WHERE predicate = '${escapeSurrealString(propMeta.predicate)}' AND out.uri = '${escapeSurrealString(propMeta.initial)}']) > 0`);
|
|
192
|
-
}
|
|
193
|
-
else {
|
|
194
|
-
graphTraversalFilters.push(`count(->link[WHERE predicate = '${escapeSurrealString(propMeta.predicate)}']) > 0`);
|
|
195
|
-
}
|
|
196
|
-
}
|
|
197
|
-
}
|
|
198
|
-
// Fallback: initial-value filters
|
|
199
|
-
if (graphTraversalFilters.length === 0) {
|
|
200
|
-
for (const [, propMeta] of Object.entries(metadata.properties)) {
|
|
201
|
-
if (propMeta.initial) {
|
|
202
|
-
if (propMeta.flag) {
|
|
203
|
-
graphTraversalFilters.push(`count(->link[WHERE predicate = '${escapeSurrealString(propMeta.predicate)}' AND out.uri = '${escapeSurrealString(propMeta.initial)}']) > 0`);
|
|
204
|
-
}
|
|
205
|
-
else {
|
|
206
|
-
graphTraversalFilters.push(`count(->link[WHERE predicate = '${escapeSurrealString(propMeta.predicate)}']) > 0`);
|
|
207
|
-
}
|
|
208
|
-
break;
|
|
209
|
-
}
|
|
210
|
-
}
|
|
211
|
-
}
|
|
212
|
-
// Fallback: open-world structural matching
|
|
213
|
-
if (graphTraversalFilters.length === 0) {
|
|
214
|
-
const structuralPredicates = [];
|
|
215
|
-
for (const [, propMeta] of Object.entries(metadata.properties)) {
|
|
216
|
-
if (propMeta.predicate) {
|
|
217
|
-
structuralPredicates.push(`predicate = '${escapeSurrealString(propMeta.predicate)}'`);
|
|
218
|
-
}
|
|
219
|
-
}
|
|
220
|
-
if (metadata.relations) {
|
|
221
|
-
for (const [, relMeta] of Object.entries(metadata.relations)) {
|
|
222
|
-
if (relMeta.predicate) {
|
|
223
|
-
structuralPredicates.push(`predicate = '${escapeSurrealString(relMeta.predicate)}'`);
|
|
224
|
-
}
|
|
225
|
-
}
|
|
226
|
-
}
|
|
227
|
-
if (structuralPredicates.length > 0) {
|
|
228
|
-
graphTraversalFilters.push(`count(->link[WHERE (${structuralPredicates.join(' OR ')})]) > 0`);
|
|
229
|
-
}
|
|
230
|
-
}
|
|
231
|
-
// User WHERE clause
|
|
232
|
-
const userWhereClause = buildGraphTraversalWhereClause(metadata, allRelationsMetadata, where);
|
|
233
|
-
const whereConditions = [];
|
|
234
|
-
whereConditions.push(...graphTraversalFilters);
|
|
235
|
-
if (userWhereClause) {
|
|
236
|
-
whereConditions.push(userWhereClause);
|
|
237
|
-
}
|
|
238
|
-
whereConditions.push(`count(->link) > 0`);
|
|
239
|
-
const fullQuery = `
|
|
240
|
-
SELECT
|
|
241
|
-
id AS source,
|
|
242
|
-
uri AS source_uri,
|
|
243
|
-
->link AS links
|
|
244
|
-
FROM node
|
|
245
|
-
WHERE ${whereConditions.join(' AND ')}
|
|
246
|
-
FETCH links
|
|
247
|
-
`.trim();
|
|
248
|
-
return fullQuery;
|
|
249
|
-
}
|
|
@@ -1,42 +0,0 @@
|
|
|
1
|
-
/**
|
|
2
|
-
* Shared SurrealQL compilation utilities.
|
|
3
|
-
*
|
|
4
|
-
* These functions are used by both the runtime query builder (`Ad4mModel`) and
|
|
5
|
-
* the compile-time SHACL generator (`decorators.ts`).
|
|
6
|
-
*/
|
|
7
|
-
import type { WhereCondition, Where, ModelMetadata } from "./types";
|
|
8
|
-
/**
|
|
9
|
-
* Format a JavaScript value for embedding in a SurrealQL expression.
|
|
10
|
-
*
|
|
11
|
-
* - Strings are single-quoted with backslash / quote / newline escaping
|
|
12
|
-
* - Numbers and booleans are passed through as-is
|
|
13
|
-
* - Arrays are recursed
|
|
14
|
-
*/
|
|
15
|
-
export declare function formatSurrealValue(value: any): string;
|
|
16
|
-
/**
|
|
17
|
-
* Compile a single Where condition for a property into a SurrealQL
|
|
18
|
-
* graph-traversal sub-expression.
|
|
19
|
-
*
|
|
20
|
-
* Operates on the **target node** — generates `count(->link[WHERE ...]) > 0`
|
|
21
|
-
* style checks that can be used inside a `[WHERE ...]` filter on nodes.
|
|
22
|
-
*
|
|
23
|
-
* @param predicate - The predicate URI for the property
|
|
24
|
-
* @param condition - The Where condition value
|
|
25
|
-
* @param opts - Optional settings (e.g. `resolveLanguage`)
|
|
26
|
-
* @returns A single SurrealQL condition string
|
|
27
|
-
*/
|
|
28
|
-
export declare function buildWhereCondition(predicate: string, condition: WhereCondition, opts?: {
|
|
29
|
-
resolveLanguage?: string;
|
|
30
|
-
}): string;
|
|
31
|
-
/**
|
|
32
|
-
* Compile a full `Where` clause to an array of SurrealQL condition strings.
|
|
33
|
-
*
|
|
34
|
-
* When `metadata` is provided, property names are resolved to predicates
|
|
35
|
-
* using the model's property metadata. When `metadata` is `null`, property
|
|
36
|
-
* names are treated as raw predicate URIs.
|
|
37
|
-
*
|
|
38
|
-
* Only handles **regular properties** — special fields (`id`, `author`,
|
|
39
|
-
* `timestamp`) and relation fields are skipped (they are only relevant at
|
|
40
|
-
* runtime query time, not for compile-time getter generation).
|
|
41
|
-
*/
|
|
42
|
-
export declare function compileWhereClause(where: Where, metadata: ModelMetadata | null): string[];
|
|
@@ -1,128 +0,0 @@
|
|
|
1
|
-
/**
|
|
2
|
-
* Shared SurrealQL compilation utilities.
|
|
3
|
-
*
|
|
4
|
-
* These functions are used by both the runtime query builder (`Ad4mModel`) and
|
|
5
|
-
* the compile-time SHACL generator (`decorators.ts`).
|
|
6
|
-
*/
|
|
7
|
-
import { escapeSurrealString } from "../utils";
|
|
8
|
-
/**
|
|
9
|
-
* Format a JavaScript value for embedding in a SurrealQL expression.
|
|
10
|
-
*
|
|
11
|
-
* - Strings are single-quoted with backslash / quote / newline escaping
|
|
12
|
-
* - Numbers and booleans are passed through as-is
|
|
13
|
-
* - Arrays are recursed
|
|
14
|
-
*/
|
|
15
|
-
export function formatSurrealValue(value) {
|
|
16
|
-
if (typeof value === 'string') {
|
|
17
|
-
// Escape backslashes first, then single quotes and other special characters
|
|
18
|
-
const escaped = value
|
|
19
|
-
.replace(/\\/g, '\\\\') // Backslash -> \\
|
|
20
|
-
.replace(/'/g, "\\'") // Single quote -> \'
|
|
21
|
-
.replace(/"/g, '\\"') // Double quote -> \"
|
|
22
|
-
.replace(/\n/g, '\\n') // Newline -> \n
|
|
23
|
-
.replace(/\r/g, '\\r') // Carriage return -> \r
|
|
24
|
-
.replace(/\t/g, '\\t'); // Tab -> \t
|
|
25
|
-
return `'${escaped}'`;
|
|
26
|
-
}
|
|
27
|
-
else if (typeof value === 'number' || typeof value === 'boolean') {
|
|
28
|
-
return String(value);
|
|
29
|
-
}
|
|
30
|
-
else if (Array.isArray(value)) {
|
|
31
|
-
return `[${value.map(v => formatSurrealValue(v)).join(', ')}]`;
|
|
32
|
-
}
|
|
33
|
-
else {
|
|
34
|
-
return String(value);
|
|
35
|
-
}
|
|
36
|
-
}
|
|
37
|
-
/**
|
|
38
|
-
* Compile a single Where condition for a property into a SurrealQL
|
|
39
|
-
* graph-traversal sub-expression.
|
|
40
|
-
*
|
|
41
|
-
* Operates on the **target node** — generates `count(->link[WHERE ...]) > 0`
|
|
42
|
-
* style checks that can be used inside a `[WHERE ...]` filter on nodes.
|
|
43
|
-
*
|
|
44
|
-
* @param predicate - The predicate URI for the property
|
|
45
|
-
* @param condition - The Where condition value
|
|
46
|
-
* @param opts - Optional settings (e.g. `resolveLanguage`)
|
|
47
|
-
* @returns A single SurrealQL condition string
|
|
48
|
-
*/
|
|
49
|
-
export function buildWhereCondition(predicate, condition, opts) {
|
|
50
|
-
const escapedPredicate = escapeSurrealString(predicate);
|
|
51
|
-
const targetField = opts?.resolveLanguage === 'literal'
|
|
52
|
-
? 'fn::parse_literal(out.uri)'
|
|
53
|
-
: 'out.uri';
|
|
54
|
-
if (Array.isArray(condition)) {
|
|
55
|
-
// Array values → IN clause
|
|
56
|
-
const formattedValues = condition.map(v => formatSurrealValue(v)).join(', ');
|
|
57
|
-
return `count(->link[WHERE predicate = '${escapedPredicate}' AND ${targetField} IN [${formattedValues}]]) > 0`;
|
|
58
|
-
}
|
|
59
|
-
else if (typeof condition === 'object' && condition !== null) {
|
|
60
|
-
// Operator object
|
|
61
|
-
const ops = condition;
|
|
62
|
-
const parts = [];
|
|
63
|
-
if (ops.not !== undefined) {
|
|
64
|
-
if (Array.isArray(ops.not)) {
|
|
65
|
-
const formattedValues = ops.not.map((v) => formatSurrealValue(v)).join(', ');
|
|
66
|
-
parts.push(`count(->link[WHERE predicate = '${escapedPredicate}' AND ${targetField} IN [${formattedValues}]]) = 0`);
|
|
67
|
-
}
|
|
68
|
-
else {
|
|
69
|
-
parts.push(`count(->link[WHERE predicate = '${escapedPredicate}' AND ${targetField} = ${formatSurrealValue(ops.not)}]) = 0`);
|
|
70
|
-
}
|
|
71
|
-
}
|
|
72
|
-
// Comparison operators — ensure property exists (actual comparison
|
|
73
|
-
// may be post-filtered in JS at runtime, but the SurrealQL condition
|
|
74
|
-
// is valid for compile-time getter generation too).
|
|
75
|
-
const hasComparisonOps = ops.gt !== undefined || ops.gte !== undefined ||
|
|
76
|
-
ops.lt !== undefined || ops.lte !== undefined ||
|
|
77
|
-
ops.between !== undefined || ops.contains !== undefined;
|
|
78
|
-
if (hasComparisonOps) {
|
|
79
|
-
parts.push(`count(->link[WHERE predicate = '${escapedPredicate}']) > 0`);
|
|
80
|
-
}
|
|
81
|
-
return parts.join(' AND ');
|
|
82
|
-
}
|
|
83
|
-
else {
|
|
84
|
-
// Simple equality
|
|
85
|
-
return `count(->link[WHERE predicate = '${escapedPredicate}' AND ${targetField} = ${formatSurrealValue(condition)}]) > 0`;
|
|
86
|
-
}
|
|
87
|
-
}
|
|
88
|
-
/**
|
|
89
|
-
* Compile a full `Where` clause to an array of SurrealQL condition strings.
|
|
90
|
-
*
|
|
91
|
-
* When `metadata` is provided, property names are resolved to predicates
|
|
92
|
-
* using the model's property metadata. When `metadata` is `null`, property
|
|
93
|
-
* names are treated as raw predicate URIs.
|
|
94
|
-
*
|
|
95
|
-
* Only handles **regular properties** — special fields (`id`, `author`,
|
|
96
|
-
* `timestamp`) and relation fields are skipped (they are only relevant at
|
|
97
|
-
* runtime query time, not for compile-time getter generation).
|
|
98
|
-
*/
|
|
99
|
-
export function compileWhereClause(where, metadata) {
|
|
100
|
-
const conditions = [];
|
|
101
|
-
for (const [propertyName, condition] of Object.entries(where)) {
|
|
102
|
-
// Skip special fields that don't apply at compile time
|
|
103
|
-
if (['id', 'author', 'timestamp'].includes(propertyName))
|
|
104
|
-
continue;
|
|
105
|
-
let predicate;
|
|
106
|
-
let resolveLanguage;
|
|
107
|
-
if (metadata) {
|
|
108
|
-
const propMeta = metadata.properties[propertyName];
|
|
109
|
-
if (propMeta) {
|
|
110
|
-
predicate = propMeta.predicate;
|
|
111
|
-
resolveLanguage = propMeta.resolveLanguage;
|
|
112
|
-
}
|
|
113
|
-
else {
|
|
114
|
-
// Property not found in metadata — treat name as raw predicate URI
|
|
115
|
-
predicate = propertyName;
|
|
116
|
-
}
|
|
117
|
-
}
|
|
118
|
-
else {
|
|
119
|
-
// No metadata — treat name as raw predicate URI
|
|
120
|
-
predicate = propertyName;
|
|
121
|
-
}
|
|
122
|
-
const cond = buildWhereCondition(predicate, condition, { resolveLanguage });
|
|
123
|
-
if (cond) {
|
|
124
|
-
conditions.push(cond);
|
|
125
|
-
}
|
|
126
|
-
}
|
|
127
|
-
return conditions;
|
|
128
|
-
}
|
|
@@ -1 +0,0 @@
|
|
|
1
|
-
export {};
|
|
@@ -1,34 +0,0 @@
|
|
|
1
|
-
import { QuerySubscriptionProxy } from './PerspectiveProxy';
|
|
2
|
-
describe('QuerySubscriptionProxy', () => {
|
|
3
|
-
it('treats the initial subscribeQuery() result as a completed initialization', async () => {
|
|
4
|
-
const initialResult = [
|
|
5
|
-
{
|
|
6
|
-
source: 'literal:string:test-channel',
|
|
7
|
-
predicate: 'flux://has_channel_name',
|
|
8
|
-
target: 'literal:string:Runtime Fix Channel',
|
|
9
|
-
},
|
|
10
|
-
];
|
|
11
|
-
const unsubscribe = jest.fn();
|
|
12
|
-
const mockClient = {
|
|
13
|
-
subscribeQuery: jest.fn().mockResolvedValue({
|
|
14
|
-
subscriptionId: 'sub-1',
|
|
15
|
-
result: initialResult,
|
|
16
|
-
}),
|
|
17
|
-
subscribeToQueryUpdates: jest.fn().mockReturnValue(unsubscribe),
|
|
18
|
-
keepAliveQuery: jest.fn().mockResolvedValue(true),
|
|
19
|
-
disposeQuerySubscription: jest.fn().mockResolvedValue(true),
|
|
20
|
-
};
|
|
21
|
-
const subscription = new QuerySubscriptionProxy('perspective-1', 'SELECT * WHERE { ?s ?p ?o }', mockClient);
|
|
22
|
-
await subscription.subscribe();
|
|
23
|
-
const initialized = await Promise.race([
|
|
24
|
-
subscription.initialized.then(() => 'resolved'),
|
|
25
|
-
new Promise((resolve) => setTimeout(() => resolve('timeout'), 25)),
|
|
26
|
-
]);
|
|
27
|
-
expect(initialized).toBe('resolved');
|
|
28
|
-
expect(subscription.result).toEqual(initialResult);
|
|
29
|
-
expect(mockClient.subscribeQuery).toHaveBeenCalledWith('perspective-1', 'SELECT * WHERE { ?s ?p ?o }');
|
|
30
|
-
expect(mockClient.subscribeToQueryUpdates).toHaveBeenCalledWith('sub-1', expect.any(Function));
|
|
31
|
-
subscription.dispose();
|
|
32
|
-
expect(unsubscribe).toHaveBeenCalled();
|
|
33
|
-
});
|
|
34
|
-
});
|
package/lib/src/restClient.d.ts
DELETED
|
@@ -1,52 +0,0 @@
|
|
|
1
|
-
/** Shape of event data parsed from JSON. Callers can narrow via generics. */
|
|
2
|
-
export interface SseEvent {
|
|
3
|
-
type: string;
|
|
4
|
-
[key: string]: unknown;
|
|
5
|
-
}
|
|
6
|
-
/** Error thrown by RestClient when an RPC call fails. */
|
|
7
|
-
export declare class RestError extends Error {
|
|
8
|
-
/** Error code (maps to HTTP status semantics: 400, 401, 403, 404, 500). */
|
|
9
|
-
readonly status: number;
|
|
10
|
-
/** Raw error message from server. */
|
|
11
|
-
readonly body: string;
|
|
12
|
-
constructor(status: number, body: string);
|
|
13
|
-
}
|
|
14
|
-
export declare class RestClient {
|
|
15
|
-
private baseUrl;
|
|
16
|
-
private token?;
|
|
17
|
-
constructor(baseUrl: string, token?: string);
|
|
18
|
-
getBaseUrl(): string;
|
|
19
|
-
getToken(): string | undefined;
|
|
20
|
-
setToken(token: string): void;
|
|
21
|
-
private _ws;
|
|
22
|
-
private _wsCallbacks;
|
|
23
|
-
private _pendingCalls;
|
|
24
|
-
private _wsReady;
|
|
25
|
-
private _wsReadyResolve;
|
|
26
|
-
private _wsReconnectTimer;
|
|
27
|
-
private _wsReconnectDelay;
|
|
28
|
-
private _wsClosed;
|
|
29
|
-
private _wsPingTimer;
|
|
30
|
-
private _getWsUrl;
|
|
31
|
-
private _ensureWs;
|
|
32
|
-
private _startPing;
|
|
33
|
-
private _stopPing;
|
|
34
|
-
private _scheduleReconnect;
|
|
35
|
-
/** Ensure WS is connected and ready. Lazy — connects on first use. */
|
|
36
|
-
private _ready;
|
|
37
|
-
/**
|
|
38
|
-
* Send an RPC call over the WebSocket connection.
|
|
39
|
-
* @param type - The operation type (e.g. 'agent.get', 'perspective.all')
|
|
40
|
-
* @param params - Optional parameters to include in the message
|
|
41
|
-
* @returns Promise that resolves with the result from the server
|
|
42
|
-
*/
|
|
43
|
-
call<T>(type: string, params?: Record<string, unknown>): Promise<T>;
|
|
44
|
-
subscribe<T = SseEvent>(path: string, callback: (data: T) => void): () => void;
|
|
45
|
-
/** Wait until the WebSocket connection is established. */
|
|
46
|
-
waitForSubscription(path: string): Promise<void>;
|
|
47
|
-
/** Explicitly connect the WebSocket (optional — connection is lazy). */
|
|
48
|
-
connect(): void;
|
|
49
|
-
private _closeWs;
|
|
50
|
-
/** Close all open WebSocket connections and reject pending calls. */
|
|
51
|
-
closeAll(): void;
|
|
52
|
-
}
|