@coasys/ad4m 0.13.0-test-6 → 0.13.0-test-8
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 +1103 -747
- package/lib/index.js +1090 -747
- package/lib/src/Ad4mClient.d.ts +4 -1
- package/lib/src/Ad4mClient.js +2 -2
- package/lib/src/agent/AgentClient.js +17 -0
- package/lib/src/ai/AIClient.js +1 -1
- package/lib/src/apiClient.d.ts +5 -1
- package/lib/src/apiClient.js +14 -6
- package/lib/src/generated/rest/AIModelLoadingStatus.d.ts +7 -0
- package/lib/src/generated/rest/AIModelLoadingStatus.js +2 -0
- package/lib/src/generated/rest/AddAgentInfosRequest.d.ts +3 -0
- package/lib/src/generated/rest/AddAgentInfosRequest.js +2 -0
- package/lib/src/generated/rest/AddLinkExpressionRequest.d.ts +6 -0
- package/lib/src/generated/rest/AddLinkExpressionRequest.js +1 -0
- package/lib/src/generated/rest/AddLinkRequest.d.ts +6 -0
- package/lib/src/generated/rest/AddLinkRequest.js +1 -0
- package/lib/src/generated/rest/AddLinksBulkRequest.d.ts +6 -0
- package/lib/src/generated/rest/AddLinksBulkRequest.js +1 -0
- package/lib/src/generated/rest/AddSdnaRequest.d.ts +6 -0
- package/lib/src/generated/rest/AddSdnaRequest.js +2 -0
- package/lib/src/generated/rest/ApplyTemplateRequest.d.ts +4 -0
- package/lib/src/generated/rest/ApplyTemplateRequest.js +2 -0
- package/lib/src/generated/rest/AuthInfoInput.d.ts +10 -0
- package/lib/src/generated/rest/AuthInfoInput.js +1 -0
- package/lib/src/generated/rest/BroadcastRequest.d.ts +6 -0
- package/lib/src/generated/rest/BroadcastRequest.js +1 -0
- package/lib/src/generated/rest/CapabilityInput.d.ts +5 -0
- package/lib/src/generated/rest/CapabilityInput.js +1 -0
- package/lib/src/generated/rest/CommitBatchRequest.d.ts +3 -0
- package/lib/src/generated/rest/CommitBatchRequest.js +2 -0
- package/lib/src/generated/rest/ComputeLogEntry.d.ts +9 -0
- package/lib/src/generated/rest/ComputeLogEntry.js +2 -0
- package/lib/src/generated/rest/CreateExpressionRequest.d.ts +4 -0
- package/lib/src/generated/rest/CreateExpressionRequest.js +2 -0
- package/lib/src/generated/rest/CreatePerspectiveRequest.d.ts +3 -0
- package/lib/src/generated/rest/CreatePerspectiveRequest.js +2 -0
- package/lib/src/generated/rest/CreateSubjectRequest.d.ts +6 -0
- package/lib/src/generated/rest/CreateSubjectRequest.js +2 -0
- package/lib/src/generated/rest/CreateUserRequest.d.ts +4 -0
- package/lib/src/generated/rest/CreateUserRequest.js +2 -0
- package/lib/src/generated/rest/CreateUserResponse.d.ts +5 -0
- package/lib/src/generated/rest/CreateUserResponse.js +2 -0
- package/lib/src/generated/rest/DecoratedExpressionProof.d.ts +6 -0
- package/lib/src/generated/rest/DecoratedExpressionProof.js +2 -0
- package/lib/src/generated/rest/DecoratedLinkExpression.d.ts +10 -0
- package/lib/src/generated/rest/DecoratedLinkExpression.js +1 -0
- package/lib/src/generated/rest/DisposeQueryRequest.d.ts +3 -0
- package/lib/src/generated/rest/DisposeQueryRequest.js +2 -0
- package/lib/src/generated/rest/EmailTestRequest.d.ts +6 -0
- package/lib/src/generated/rest/EmailTestRequest.js +2 -0
- package/lib/src/generated/rest/EmbedRequest.d.ts +4 -0
- package/lib/src/generated/rest/EmbedRequest.js +2 -0
- package/lib/src/generated/rest/EntanglementProofInput.d.ts +6 -0
- package/lib/src/generated/rest/EntanglementProofInput.js +2 -0
- package/lib/src/generated/rest/EntanglementProofPreflightRequest.d.ts +4 -0
- package/lib/src/generated/rest/EntanglementProofPreflightRequest.js +2 -0
- package/lib/src/generated/rest/ExecuteCommandsRequest.d.ts +4 -0
- package/lib/src/generated/rest/ExecuteCommandsRequest.js +2 -0
- package/lib/src/generated/rest/ExportRequest.d.ts +5 -0
- package/lib/src/generated/rest/ExportRequest.js +2 -0
- package/lib/src/generated/rest/ExpressionManyRequest.d.ts +3 -0
- package/lib/src/generated/rest/ExpressionManyRequest.js +2 -0
- package/lib/src/generated/rest/ExpressionProof.d.ts +4 -0
- package/lib/src/generated/rest/ExpressionProof.js +2 -0
- package/lib/src/generated/rest/ExpressionProofInput.d.ts +6 -0
- package/lib/src/generated/rest/ExpressionProofInput.js +2 -0
- package/lib/src/generated/rest/FriendSendMessageRequest.d.ts +3 -0
- package/lib/src/generated/rest/FriendSendMessageRequest.js +2 -0
- package/lib/src/generated/rest/FriendsListRequest.d.ts +3 -0
- package/lib/src/generated/rest/FriendsListRequest.js +2 -0
- package/lib/src/generated/rest/GenerateAgentRequest.d.ts +3 -0
- package/lib/src/generated/rest/GenerateAgentRequest.js +2 -0
- package/lib/src/generated/rest/GenerateJwtRequest.d.ts +4 -0
- package/lib/src/generated/rest/GenerateJwtRequest.js +2 -0
- package/lib/src/generated/rest/GetSubjectDataRequest.d.ts +4 -0
- package/lib/src/generated/rest/GetSubjectDataRequest.js +2 -0
- package/lib/src/generated/rest/HostingInfoResponse.d.ts +5 -0
- package/lib/src/generated/rest/HostingInfoResponse.js +2 -0
- package/lib/src/generated/rest/HostingWalletResponse.d.ts +4 -0
- package/lib/src/generated/rest/HostingWalletResponse.js +2 -0
- package/lib/src/generated/rest/ImportAgentRequest.d.ts +6 -0
- package/lib/src/generated/rest/ImportAgentRequest.js +2 -0
- package/lib/src/generated/rest/ImportRequest.d.ts +4 -0
- package/lib/src/generated/rest/ImportRequest.js +2 -0
- package/lib/src/generated/rest/JoinNeighbourhoodRequest.d.ts +3 -0
- package/lib/src/generated/rest/JoinNeighbourhoodRequest.js +2 -0
- package/lib/src/generated/rest/KeepAliveQueryRequest.d.ts +3 -0
- package/lib/src/generated/rest/KeepAliveQueryRequest.js +2 -0
- package/lib/src/generated/rest/LanguageMetaInput.d.ts +6 -0
- package/lib/src/generated/rest/LanguageMetaInput.js +2 -0
- package/lib/src/generated/rest/Link.d.ts +5 -0
- package/lib/src/generated/rest/Link.js +2 -0
- package/lib/src/generated/rest/LinkExpression.d.ts +10 -0
- package/lib/src/generated/rest/LinkExpression.js +1 -0
- package/lib/src/generated/rest/LinkExpressionInput.d.ts +10 -0
- package/lib/src/generated/rest/LinkExpressionInput.js +1 -0
- package/lib/src/generated/rest/LinkInput.d.ts +5 -0
- package/lib/src/generated/rest/LinkInput.js +2 -0
- package/lib/src/generated/rest/LinkLanguageTemplatesRequest.d.ts +3 -0
- package/lib/src/generated/rest/LinkLanguageTemplatesRequest.js +2 -0
- package/lib/src/generated/rest/LinkMutationRequest.d.ts +12 -0
- package/lib/src/generated/rest/LinkMutationRequest.js +1 -0
- package/lib/src/generated/rest/LinkMutationResponse.d.ts +9 -0
- package/lib/src/generated/rest/LinkMutationResponse.js +1 -0
- package/lib/src/generated/rest/LinkMutations.d.ts +6 -0
- package/lib/src/generated/rest/LinkMutations.js +1 -0
- package/lib/src/generated/rest/LinkMutationsRequest.d.ts +5 -0
- package/lib/src/generated/rest/LinkMutationsRequest.js +1 -0
- package/lib/src/generated/rest/LinkStatus.d.ts +1 -0
- package/lib/src/generated/rest/LinkStatus.js +2 -0
- package/lib/src/generated/rest/LinkUpdateInput.d.ts +5 -0
- package/lib/src/generated/rest/LinkUpdateInput.js +1 -0
- package/lib/src/generated/rest/LockAgentRequest.d.ts +3 -0
- package/lib/src/generated/rest/LockAgentRequest.js +2 -0
- package/lib/src/generated/rest/LoginUserRequest.d.ts +5 -0
- package/lib/src/generated/rest/LoginUserRequest.js +2 -0
- package/lib/src/generated/rest/ModelType.d.ts +1 -0
- package/lib/src/generated/rest/ModelType.js +2 -0
- package/lib/src/generated/rest/NotificationGrantRequest.d.ts +3 -0
- package/lib/src/generated/rest/NotificationGrantRequest.js +2 -0
- package/lib/src/generated/rest/NotificationInput.d.ts +10 -0
- package/lib/src/generated/rest/NotificationInput.js +2 -0
- package/lib/src/generated/rest/OpenLinkRequest.d.ts +3 -0
- package/lib/src/generated/rest/OpenLinkRequest.js +2 -0
- package/lib/src/generated/rest/PermitCapabilityRequest.d.ts +3 -0
- package/lib/src/generated/rest/PermitCapabilityRequest.js +2 -0
- package/lib/src/generated/rest/PerspectiveInput.d.ts +4 -0
- package/lib/src/generated/rest/PerspectiveInput.js +1 -0
- package/lib/src/generated/rest/PromptRequest.d.ts +4 -0
- package/lib/src/generated/rest/PromptRequest.js +2 -0
- package/lib/src/generated/rest/PublicPerspectiveInput.d.ts +4 -0
- package/lib/src/generated/rest/PublicPerspectiveInput.js +1 -0
- package/lib/src/generated/rest/PublishLanguageRequest.d.ts +5 -0
- package/lib/src/generated/rest/PublishLanguageRequest.js +1 -0
- package/lib/src/generated/rest/PublishNeighbourhoodRequest.d.ts +6 -0
- package/lib/src/generated/rest/PublishNeighbourhoodRequest.js +1 -0
- package/lib/src/generated/rest/QueryRequest.d.ts +7 -0
- package/lib/src/generated/rest/QueryRequest.js +2 -0
- package/lib/src/generated/rest/RemoveLinkRequest.d.ts +5 -0
- package/lib/src/generated/rest/RemoveLinkRequest.js +1 -0
- package/lib/src/generated/rest/RemoveLinksBulkRequest.d.ts +5 -0
- package/lib/src/generated/rest/RemoveLinksBulkRequest.js +1 -0
- package/lib/src/generated/rest/RequestCapabilityRequest.d.ts +4 -0
- package/lib/src/generated/rest/RequestCapabilityRequest.js +1 -0
- package/lib/src/generated/rest/RequestPaymentRequest.d.ts +3 -0
- package/lib/src/generated/rest/RequestPaymentRequest.js +2 -0
- package/lib/src/generated/rest/RequestVerificationRequest.d.ts +4 -0
- package/lib/src/generated/rest/RequestVerificationRequest.js +2 -0
- package/lib/src/generated/rest/ResourceInput.d.ts +4 -0
- package/lib/src/generated/rest/ResourceInput.js +2 -0
- package/lib/src/generated/rest/SetDefaultModelRequest.d.ts +4 -0
- package/lib/src/generated/rest/SetDefaultModelRequest.js +1 -0
- package/lib/src/generated/rest/SetFreeHostingEnabledRequest.d.ts +3 -0
- package/lib/src/generated/rest/SetFreeHostingEnabledRequest.js +2 -0
- package/lib/src/generated/rest/SetHotWalletAddressRequest.d.ts +3 -0
- package/lib/src/generated/rest/SetHotWalletAddressRequest.js +2 -0
- package/lib/src/generated/rest/SetMultiUserRequest.d.ts +3 -0
- package/lib/src/generated/rest/SetMultiUserRequest.js +2 -0
- package/lib/src/generated/rest/SetOnlineStatusRequest.d.ts +5 -0
- package/lib/src/generated/rest/SetOnlineStatusRequest.js +1 -0
- package/lib/src/generated/rest/SetStatusRequest.d.ts +3 -0
- package/lib/src/generated/rest/SetStatusRequest.js +2 -0
- package/lib/src/generated/rest/SetUserFreeAccessRequest.d.ts +4 -0
- package/lib/src/generated/rest/SetUserFreeAccessRequest.js +2 -0
- package/lib/src/generated/rest/SignMessageRequest.d.ts +3 -0
- package/lib/src/generated/rest/SignMessageRequest.js +2 -0
- package/lib/src/generated/rest/SignalRequest.d.ts +6 -0
- package/lib/src/generated/rest/SignalRequest.js +1 -0
- package/lib/src/generated/rest/SubscribeQueryRequest.d.ts +3 -0
- package/lib/src/generated/rest/SubscribeQueryRequest.js +2 -0
- package/lib/src/generated/rest/SubscribeQueryResponse.d.ts +4 -0
- package/lib/src/generated/rest/SubscribeQueryResponse.js +2 -0
- package/lib/src/generated/rest/TrustedAgentsRequest.d.ts +3 -0
- package/lib/src/generated/rest/TrustedAgentsRequest.js +2 -0
- package/lib/src/generated/rest/UnlockAgentRequest.d.ts +4 -0
- package/lib/src/generated/rest/UnlockAgentRequest.js +2 -0
- package/lib/src/generated/rest/UpdateLinkRequest.d.ts +7 -0
- package/lib/src/generated/rest/UpdateLinkRequest.js +1 -0
- package/lib/src/generated/rest/UpdatePerspectiveRequest.d.ts +3 -0
- package/lib/src/generated/rest/UpdatePerspectiveRequest.js +2 -0
- package/lib/src/generated/rest/UpdateProfileRequest.d.ts +5 -0
- package/lib/src/generated/rest/UpdateProfileRequest.js +1 -0
- package/lib/src/generated/rest/UserStatistics.d.ts +9 -0
- package/lib/src/generated/rest/UserStatistics.js +2 -0
- package/lib/src/generated/rest/VerificationRequestResult.d.ts +6 -0
- package/lib/src/generated/rest/VerificationRequestResult.js +2 -0
- package/lib/src/generated/rest/VerifyEmailRequest.d.ts +6 -0
- package/lib/src/generated/rest/VerifyEmailRequest.js +2 -0
- package/lib/src/generated/rest/VerifySignatureRequest.d.ts +5 -0
- package/lib/src/generated/rest/VerifySignatureRequest.js +2 -0
- package/lib/src/generated/rest/WriteSettingsRequest.d.ts +3 -0
- package/lib/src/generated/rest/WriteSettingsRequest.js +2 -0
- package/lib/src/generated/rest/index.d.ts +73 -0
- package/lib/src/generated/rest/index.js +8 -0
- package/lib/src/generated/rest/routes.d.ts +587 -0
- package/lib/src/generated/rest/routes.js +3 -0
- package/lib/src/index.d.ts +4 -0
- package/lib/src/index.js +4 -0
- package/lib/src/model/Ad4mModel.d.ts +30 -21
- package/lib/src/model/Ad4mModel.js +93 -316
- package/lib/src/model/Ad4mModel.test.js +1536 -535
- package/lib/src/model/ModelQueryBuilder.d.ts +5 -10
- package/lib/src/model/ModelQueryBuilder.js +136 -47
- package/lib/src/model/Subject.js +6 -6
- package/lib/src/model/decorators.d.ts +7 -4
- package/lib/src/model/decorators.js +0 -7
- package/lib/src/model/hydration-batch.d.ts +34 -0
- package/lib/src/model/hydration-batch.js +147 -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/query-cache.test.d.ts +1 -0
- package/lib/src/model/query-cache.test.js +43 -0
- package/lib/src/model/query-sparql-batch.d.ts +17 -0
- package/lib/src/model/query-sparql-batch.js +260 -0
- package/lib/src/model/query-sparql.d.ts +0 -10
- package/lib/src/model/query-sparql.js +10 -15
- package/lib/src/model/query-sparql.test.d.ts +1 -0
- package/lib/src/model/query-sparql.test.js +230 -0
- package/lib/src/model/relation-filtering.test.js +15 -15
- package/lib/src/model/shacl-gen.js +120 -47
- 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.d.ts +39 -0
- package/lib/src/model/subscription-pool.js +165 -0
- package/lib/src/model/types.d.ts +140 -4
- package/lib/src/neighbourhood/NeighbourhoodProxy.test.js +33 -33
- package/lib/src/perspectives/PerspectiveClient.d.ts +13 -4
- package/lib/src/perspectives/PerspectiveClient.js +22 -6
- package/lib/src/perspectives/PerspectiveClient.test.d.ts +1 -0
- package/lib/src/perspectives/PerspectiveClient.test.js +224 -0
- package/lib/src/perspectives/PerspectiveProxy.d.ts +27 -7
- package/lib/src/perspectives/PerspectiveProxy.js +60 -12
- package/lib/src/perspectives/PerspectiveProxy.test.d.ts +1 -0
- package/lib/src/perspectives/PerspectiveProxy.test.js +34 -0
- package/lib/src/perspectives/PerspectiveResolver.d.ts +0 -1
- package/lib/src/perspectives/PerspectiveResolver.js +0 -11
- package/lib/src/perspectives/SparqlBindings.d.ts +47 -0
- package/lib/src/perspectives/SparqlBindings.js +65 -0
- package/lib/src/perspectives/WakerSubscriptionManager.js +5 -4
- package/lib/src/restClient.d.ts +52 -0
- package/lib/src/restClient.js +227 -0
- package/lib/src/runtime/RuntimeResolver.d.ts +28 -1
- package/lib/src/runtime/RuntimeResolver.js +197 -4
- package/lib/src/schema.gql +27 -1
- package/lib/src/shacl/NodeExpression.d.ts +44 -0
- package/lib/src/shacl/NodeExpression.js +39 -0
- package/lib/src/shacl/SHACLShape.d.ts +23 -0
- package/lib/src/shacl/SHACLShape.js +115 -1
- package/lib/src/shacl/builders.d.ts +58 -0
- package/lib/src/shacl/builders.js +76 -0
- package/lib/src/shacl/index.d.ts +36 -0
- package/lib/src/shacl/index.js +33 -0
- package/package.json +1 -1
- package/src/Ad4mClient.ts +7 -2
- package/src/agent/AgentClient.ts +23 -0
- package/src/ai/AIClient.ts +1 -1
- package/src/apiClient.ts +17 -6
- package/src/index.ts +4 -0
- package/src/model/Ad4mModel.test.ts +274 -72
- package/src/model/Ad4mModel.ts +141 -350
- package/src/model/ModelQueryBuilder.ts +131 -56
- package/src/model/decorators.ts +7 -13
- package/src/model/query-sparql.test.ts +35 -19
- package/src/model/query-sparql.ts +10 -16
- package/src/model/relation-filtering.test.ts +46 -39
- package/src/model/shacl-gen.ts +128 -54
- package/src/model/shacl-roundtrip.test.ts +197 -0
- package/src/model/types-typed-query.test.ts +360 -0
- package/src/model/types.ts +196 -4
- package/src/perspectives/PerspectiveClient.ts +24 -8
- package/src/perspectives/PerspectiveProxy.test.ts +85 -1
- package/src/perspectives/PerspectiveProxy.ts +65 -20
- package/src/perspectives/SparqlBindings.ts +79 -0
- package/src/perspectives/WakerSubscriptionManager.ts +5 -4
- package/src/shacl/NodeExpression.ts +54 -0
- package/src/shacl/SHACLShape.test.ts +172 -0
- package/src/shacl/SHACLShape.ts +173 -1
- package/src/shacl/builders.ts +86 -0
- package/src/shacl/index.ts +72 -0
|
@@ -10,6 +10,7 @@ import type { PerspectiveProxy } from "../perspectives/PerspectiveProxy";
|
|
|
10
10
|
import type {
|
|
11
11
|
Where, Order, IncludeMap, Query,
|
|
12
12
|
ResultsWithTotalCount, PaginationResult,
|
|
13
|
+
TypedWhere, TypedOrder, TypedIncludeMap, PropertyKeysOf,
|
|
13
14
|
} from "./types";
|
|
14
15
|
|
|
15
16
|
/** Query builder for Ad4mModel queries.
|
|
@@ -80,8 +81,8 @@ export class ModelQueryBuilder<T extends Ad4mModel> {
|
|
|
80
81
|
* })
|
|
81
82
|
* ```
|
|
82
83
|
*/
|
|
83
|
-
where(conditions:
|
|
84
|
-
this.queryParams.where = conditions;
|
|
84
|
+
where(conditions: TypedWhere<T>): ModelQueryBuilder<T> {
|
|
85
|
+
this.queryParams.where = conditions as Where;
|
|
85
86
|
return this;
|
|
86
87
|
}
|
|
87
88
|
|
|
@@ -96,8 +97,8 @@ export class ModelQueryBuilder<T extends Ad4mModel> {
|
|
|
96
97
|
* .order({ createdAt: "DESC" })
|
|
97
98
|
* ```
|
|
98
99
|
*/
|
|
99
|
-
order(orderBy:
|
|
100
|
-
this.queryParams.order = orderBy;
|
|
100
|
+
order(orderBy: TypedOrder<T>): ModelQueryBuilder<T> {
|
|
101
|
+
this.queryParams.order = orderBy as Order;
|
|
101
102
|
return this;
|
|
102
103
|
}
|
|
103
104
|
|
|
@@ -218,8 +219,8 @@ export class ModelQueryBuilder<T extends Ad4mModel> {
|
|
|
218
219
|
* .properties(["name", "description", "rating"])
|
|
219
220
|
* ```
|
|
220
221
|
*/
|
|
221
|
-
properties(properties: string[]): ModelQueryBuilder<T> {
|
|
222
|
-
this.queryParams.properties = properties;
|
|
222
|
+
properties(properties: PropertyKeysOf<T>[] | string[]): ModelQueryBuilder<T> {
|
|
223
|
+
this.queryParams.properties = properties as string[];
|
|
223
224
|
return this;
|
|
224
225
|
}
|
|
225
226
|
|
|
@@ -272,8 +273,8 @@ export class ModelQueryBuilder<T extends Ad4mModel> {
|
|
|
272
273
|
* .run();
|
|
273
274
|
* ```
|
|
274
275
|
*/
|
|
275
|
-
include(map:
|
|
276
|
-
this.queryParams.include = map;
|
|
276
|
+
include(map: TypedIncludeMap<T>): ModelQueryBuilder<T> {
|
|
277
|
+
this.queryParams.include = map as IncludeMap;
|
|
277
278
|
return this;
|
|
278
279
|
}
|
|
279
280
|
|
|
@@ -282,14 +283,6 @@ export class ModelQueryBuilder<T extends Ad4mModel> {
|
|
|
282
283
|
return this;
|
|
283
284
|
}
|
|
284
285
|
|
|
285
|
-
/**
|
|
286
|
-
* Sets the query engine to use.
|
|
287
|
-
* @deprecated Prolog engine has been removed. All queries use SPARQL/Rust.
|
|
288
|
-
*/
|
|
289
|
-
engine(_eng: 'sparql' | 'prolog'): ModelQueryBuilder<T> {
|
|
290
|
-
return this;
|
|
291
|
-
}
|
|
292
|
-
|
|
293
286
|
/**
|
|
294
287
|
* Executes the query once and returns the results.
|
|
295
288
|
*
|
|
@@ -336,8 +329,10 @@ export class ModelQueryBuilder<T extends Ad4mModel> {
|
|
|
336
329
|
* ```
|
|
337
330
|
*/
|
|
338
331
|
async first(): Promise<T | null> {
|
|
332
|
+
const savedLimit = this.queryParams.limit;
|
|
339
333
|
this.queryParams.limit = 1;
|
|
340
334
|
const results = await this.get();
|
|
335
|
+
this.queryParams.limit = savedLimit;
|
|
341
336
|
return results[0] ?? null;
|
|
342
337
|
}
|
|
343
338
|
|
|
@@ -375,15 +370,16 @@ export class ModelQueryBuilder<T extends Ad4mModel> {
|
|
|
375
370
|
|
|
376
371
|
const ctor = this.ctor;
|
|
377
372
|
|
|
378
|
-
// Build the model query params (className, queryJson
|
|
379
|
-
|
|
373
|
+
// Build the model query params (className, queryJson). The executor
|
|
374
|
+
// resolves the shape from the perspective's SHACL triples.
|
|
375
|
+
const { className, queryJson } = (ctor as any).prepareModelQueryParams(
|
|
380
376
|
this.queryParams, this.modelClassName
|
|
381
377
|
);
|
|
382
378
|
|
|
383
379
|
// Register model subscription via Rust — this builds trigger SPARQL internally,
|
|
384
380
|
// registers the subscription, and runs the initial query in one call.
|
|
385
381
|
const { subscriptionId, result: initialModelResult } = await this.perspective.modelSubscribe(
|
|
386
|
-
className, queryJson
|
|
382
|
+
className, queryJson
|
|
387
383
|
);
|
|
388
384
|
|
|
389
385
|
// Convert JSON instances to model class instances
|
|
@@ -391,7 +387,7 @@ export class ModelQueryBuilder<T extends Ad4mModel> {
|
|
|
391
387
|
return (ctor as any).parseModelResult(this.perspective, raw, this.queryParams.include, this.queryParams.properties);
|
|
392
388
|
};
|
|
393
389
|
|
|
394
|
-
//
|
|
390
|
+
// Transforms are now applied by the Rust executor during hydration
|
|
395
391
|
const initialResults = parseResults(initialModelResult);
|
|
396
392
|
|
|
397
393
|
// Track last emitted result fingerprint to suppress duplicate callbacks
|
|
@@ -411,8 +407,13 @@ export class ModelQueryBuilder<T extends Ad4mModel> {
|
|
|
411
407
|
(rawResult: any) => {
|
|
412
408
|
try {
|
|
413
409
|
const results = parseResults(rawResult);
|
|
410
|
+
console.debug(`[ModelQueryBuilder.subscribe] Update received for ${subscriptionId}: ${results.length} instances`);
|
|
414
411
|
const fp = buildFingerprint(results);
|
|
415
|
-
if (fp === lastResultFingerprint)
|
|
412
|
+
if (fp === lastResultFingerprint) {
|
|
413
|
+
console.debug(`[ModelQueryBuilder.subscribe] Fingerprint unchanged, skipping callback`);
|
|
414
|
+
return;
|
|
415
|
+
}
|
|
416
|
+
console.debug(`[ModelQueryBuilder.subscribe] Fingerprint changed, calling callback with ${results.length} results`);
|
|
416
417
|
lastResultFingerprint = fp;
|
|
417
418
|
callback(results);
|
|
418
419
|
} catch (e) {
|
|
@@ -421,21 +422,46 @@ export class ModelQueryBuilder<T extends Ad4mModel> {
|
|
|
421
422
|
},
|
|
422
423
|
);
|
|
423
424
|
|
|
424
|
-
// Set up keepalive with
|
|
425
|
-
|
|
426
|
-
|
|
427
|
-
|
|
428
|
-
|
|
429
|
-
|
|
430
|
-
|
|
431
|
-
|
|
432
|
-
|
|
433
|
-
|
|
425
|
+
// Set up keepalive with recovery — uses setTimeout loop so we can
|
|
426
|
+
// break out and resubscribe when the server evicts the subscription.
|
|
427
|
+
let disposed = false;
|
|
428
|
+
let keepaliveTimer: ReturnType<typeof setTimeout> | undefined;
|
|
429
|
+
let resubscribeAttempts = 0;
|
|
430
|
+
const MAX_RESUBSCRIBE_ATTEMPTS = 5;
|
|
431
|
+
const keepaliveLoop = async () => {
|
|
432
|
+
if (disposed) return;
|
|
433
|
+
try {
|
|
434
|
+
await this.perspective.client.keepAliveQuery(this.perspective.uuid, subscriptionId);
|
|
435
|
+
resubscribeAttempts = 0; // Reset on success
|
|
436
|
+
} catch (e: any) {
|
|
437
|
+
console.warn(`Model subscription keepalive failed for ${subscriptionId}:`, e);
|
|
438
|
+
if (!disposed && resubscribeAttempts < MAX_RESUBSCRIBE_ATTEMPTS) {
|
|
439
|
+
resubscribeAttempts++;
|
|
440
|
+
const backoffMs = Math.min(1000 * Math.pow(2, resubscribeAttempts), 60000);
|
|
441
|
+
console.warn(`Resubscribing (attempt ${resubscribeAttempts}/${MAX_RESUBSCRIBE_ATTEMPTS}, backoff ${backoffMs}ms)...`);
|
|
442
|
+
await new Promise(r => setTimeout(r, backoffMs));
|
|
443
|
+
try {
|
|
444
|
+
unsubscribe();
|
|
445
|
+
await this.subscribe(callback);
|
|
446
|
+
} catch (resubErr) {
|
|
447
|
+
console.error('Model subscription resubscribe failed:', resubErr);
|
|
448
|
+
}
|
|
449
|
+
} else if (resubscribeAttempts >= MAX_RESUBSCRIBE_ATTEMPTS) {
|
|
450
|
+
console.error(`Model subscription ${subscriptionId}: max resubscribe attempts reached, giving up.`);
|
|
451
|
+
}
|
|
452
|
+
return; // new subscription owns its own keepalive loop
|
|
453
|
+
}
|
|
454
|
+
if (!disposed) {
|
|
455
|
+
keepaliveTimer = setTimeout(keepaliveLoop, 30000);
|
|
456
|
+
}
|
|
457
|
+
};
|
|
458
|
+
keepaliveTimer = setTimeout(keepaliveLoop, 30000);
|
|
434
459
|
|
|
435
460
|
// Store dispose function
|
|
436
461
|
this.currentSubscription = {
|
|
437
462
|
dispose: () => {
|
|
438
|
-
|
|
463
|
+
disposed = true;
|
|
464
|
+
if (keepaliveTimer) clearTimeout(keepaliveTimer);
|
|
439
465
|
unsubscribe();
|
|
440
466
|
this.perspective.client.disposeQuerySubscription(this.perspective.uuid, subscriptionId).catch(() => {});
|
|
441
467
|
},
|
|
@@ -515,12 +541,12 @@ export class ModelQueryBuilder<T extends Ad4mModel> {
|
|
|
515
541
|
this.dispose();
|
|
516
542
|
|
|
517
543
|
const countParams = { ...this.queryParams, limit: 0 };
|
|
518
|
-
const { className, queryJson
|
|
544
|
+
const { className, queryJson } = (this.ctor as any).prepareModelQueryParams(
|
|
519
545
|
countParams, this.modelClassName
|
|
520
546
|
);
|
|
521
547
|
|
|
522
548
|
const { subscriptionId, result: initialModelResult } = await this.perspective.modelSubscribe(
|
|
523
|
-
className, queryJson
|
|
549
|
+
className, queryJson
|
|
524
550
|
);
|
|
525
551
|
|
|
526
552
|
const parseCount = (raw: any): number => {
|
|
@@ -541,19 +567,43 @@ export class ModelQueryBuilder<T extends Ad4mModel> {
|
|
|
541
567
|
},
|
|
542
568
|
);
|
|
543
569
|
|
|
544
|
-
let
|
|
545
|
-
|
|
546
|
-
|
|
547
|
-
|
|
548
|
-
|
|
549
|
-
|
|
550
|
-
|
|
551
|
-
|
|
552
|
-
|
|
570
|
+
let disposed = false;
|
|
571
|
+
let keepaliveTimer: ReturnType<typeof setTimeout> | undefined;
|
|
572
|
+
let resubscribeAttempts = 0;
|
|
573
|
+
const MAX_RESUBSCRIBE_ATTEMPTS = 5;
|
|
574
|
+
const keepaliveLoop = async () => {
|
|
575
|
+
if (disposed) return;
|
|
576
|
+
try {
|
|
577
|
+
await this.perspective.client.keepAliveQuery(this.perspective.uuid, subscriptionId);
|
|
578
|
+
resubscribeAttempts = 0;
|
|
579
|
+
} catch (e: any) {
|
|
580
|
+
console.warn(`Count subscription keepalive failed for ${subscriptionId}:`, e);
|
|
581
|
+
if (!disposed && resubscribeAttempts < MAX_RESUBSCRIBE_ATTEMPTS) {
|
|
582
|
+
resubscribeAttempts++;
|
|
583
|
+
const backoffMs = Math.min(1000 * Math.pow(2, resubscribeAttempts), 60000);
|
|
584
|
+
console.warn(`Count resubscribing (attempt ${resubscribeAttempts}/${MAX_RESUBSCRIBE_ATTEMPTS}, backoff ${backoffMs}ms)...`);
|
|
585
|
+
await new Promise(r => setTimeout(r, backoffMs));
|
|
586
|
+
try {
|
|
587
|
+
unsubscribe();
|
|
588
|
+
await this.countSubscribe(callback);
|
|
589
|
+
} catch (resubErr) {
|
|
590
|
+
console.error('Count subscription resubscribe failed:', resubErr);
|
|
591
|
+
}
|
|
592
|
+
} else if (resubscribeAttempts >= MAX_RESUBSCRIBE_ATTEMPTS) {
|
|
593
|
+
console.error(`Count subscription ${subscriptionId}: max resubscribe attempts reached, giving up.`);
|
|
594
|
+
}
|
|
595
|
+
return;
|
|
596
|
+
}
|
|
597
|
+
if (!disposed) {
|
|
598
|
+
keepaliveTimer = setTimeout(keepaliveLoop, 30000);
|
|
599
|
+
}
|
|
600
|
+
};
|
|
601
|
+
keepaliveTimer = setTimeout(keepaliveLoop, 30000);
|
|
553
602
|
|
|
554
603
|
this.currentSubscription = {
|
|
555
604
|
dispose: () => {
|
|
556
|
-
|
|
605
|
+
disposed = true;
|
|
606
|
+
if (keepaliveTimer) clearTimeout(keepaliveTimer);
|
|
557
607
|
unsubscribe();
|
|
558
608
|
this.perspective.client.disposeQuerySubscription(this.perspective.uuid, subscriptionId).catch(() => {});
|
|
559
609
|
},
|
|
@@ -645,12 +695,12 @@ export class ModelQueryBuilder<T extends Ad4mModel> {
|
|
|
645
695
|
const subscriptionParams = { ...(this.queryParams || {}) };
|
|
646
696
|
delete subscriptionParams.limit;
|
|
647
697
|
delete subscriptionParams.offset;
|
|
648
|
-
const { className, queryJson
|
|
698
|
+
const { className, queryJson } = (ctor as any).prepareModelQueryParams(
|
|
649
699
|
subscriptionParams, this.modelClassName
|
|
650
700
|
);
|
|
651
701
|
|
|
652
702
|
const { subscriptionId } = await this.perspective.modelSubscribe(
|
|
653
|
-
className, queryJson
|
|
703
|
+
className, queryJson
|
|
654
704
|
);
|
|
655
705
|
|
|
656
706
|
// Build the paginated query for Rust endpoint (count: true fetches both results and totalCount in one call)
|
|
@@ -669,23 +719,48 @@ export class ModelQueryBuilder<T extends Ad4mModel> {
|
|
|
669
719
|
const unsubscribe = this.perspective.client.subscribeToQueryUpdates(
|
|
670
720
|
subscriptionId,
|
|
671
721
|
(rawResult: any) => {
|
|
722
|
+
console.debug(`[ModelQueryBuilder.paginateSubscribe] Update received for ${subscriptionId}, re-fetching paginated data...`);
|
|
672
723
|
processResults().catch(e => console.error('Paginate subscription error:', e));
|
|
673
724
|
},
|
|
674
725
|
);
|
|
675
726
|
|
|
676
|
-
let
|
|
677
|
-
|
|
678
|
-
|
|
679
|
-
|
|
680
|
-
|
|
681
|
-
|
|
682
|
-
|
|
683
|
-
|
|
684
|
-
|
|
727
|
+
let disposed = false;
|
|
728
|
+
let keepaliveTimer: ReturnType<typeof setTimeout> | undefined;
|
|
729
|
+
let resubscribeAttempts = 0;
|
|
730
|
+
const MAX_RESUBSCRIBE_ATTEMPTS = 5;
|
|
731
|
+
const keepaliveLoop = async () => {
|
|
732
|
+
if (disposed) return;
|
|
733
|
+
try {
|
|
734
|
+
await this.perspective.client.keepAliveQuery(this.perspective.uuid, subscriptionId);
|
|
735
|
+
resubscribeAttempts = 0;
|
|
736
|
+
} catch (e: any) {
|
|
737
|
+
console.warn(`Paginate subscription keepalive failed for ${subscriptionId}:`, e);
|
|
738
|
+
if (!disposed && resubscribeAttempts < MAX_RESUBSCRIBE_ATTEMPTS) {
|
|
739
|
+
resubscribeAttempts++;
|
|
740
|
+
const backoffMs = Math.min(1000 * Math.pow(2, resubscribeAttempts), 60000);
|
|
741
|
+
console.warn(`Paginate resubscribing (attempt ${resubscribeAttempts}/${MAX_RESUBSCRIBE_ATTEMPTS}, backoff ${backoffMs}ms)...`);
|
|
742
|
+
await new Promise(r => setTimeout(r, backoffMs));
|
|
743
|
+
try {
|
|
744
|
+
unsubscribe();
|
|
745
|
+
await this.paginateSubscribe(pageSize, pageNumber, callback);
|
|
746
|
+
} catch (resubErr) {
|
|
747
|
+
console.error('Paginate subscription resubscribe failed:', resubErr);
|
|
748
|
+
}
|
|
749
|
+
} else if (resubscribeAttempts >= MAX_RESUBSCRIBE_ATTEMPTS) {
|
|
750
|
+
console.error(`Paginate subscription ${subscriptionId}: max resubscribe attempts reached, giving up.`);
|
|
751
|
+
}
|
|
752
|
+
return;
|
|
753
|
+
}
|
|
754
|
+
if (!disposed) {
|
|
755
|
+
keepaliveTimer = setTimeout(keepaliveLoop, 30000);
|
|
756
|
+
}
|
|
757
|
+
};
|
|
758
|
+
keepaliveTimer = setTimeout(keepaliveLoop, 30000);
|
|
685
759
|
|
|
686
760
|
this.currentSubscription = {
|
|
687
761
|
dispose: () => {
|
|
688
|
-
|
|
762
|
+
disposed = true;
|
|
763
|
+
if (keepaliveTimer) clearTimeout(keepaliveTimer);
|
|
689
764
|
unsubscribe();
|
|
690
765
|
this.perspective.client.disposeQuerySubscription(this.perspective.uuid, subscriptionId).catch(() => {});
|
|
691
766
|
},
|
package/src/model/decorators.ts
CHANGED
|
@@ -274,11 +274,14 @@ export interface PropertyOptions {
|
|
|
274
274
|
local?: boolean;
|
|
275
275
|
|
|
276
276
|
/**
|
|
277
|
-
* Optional transform
|
|
278
|
-
* This is
|
|
279
|
-
*
|
|
277
|
+
* Optional transform expression to modify the property value.
|
|
278
|
+
* This is a SHACL-AF Node Expression that runs in the Rust model query engine.
|
|
279
|
+
* Examples: `fileToDataUri`, `concat(literal('prefix_'), focus())`, etc.
|
|
280
|
+
* Builders (`focus`, `literal`, `path`, `exists`, `ifExpr`, `concat`,
|
|
281
|
+
* `coalesce`, `fn`) and the `fileToDataUri` built-in are exported from
|
|
282
|
+
* the package root: `import { concat, literal, focus } from '@coasys/ad4m'`.
|
|
280
283
|
*/
|
|
281
|
-
transform?: (
|
|
284
|
+
transform?: import('../shacl/NodeExpression').NodeExpression;
|
|
282
285
|
|
|
283
286
|
/**
|
|
284
287
|
* Allowed values for this property (enum constraint).
|
|
@@ -858,17 +861,8 @@ export function HasMany(
|
|
|
858
861
|
first: (() => Ad4mModelLike) | RelationOptions,
|
|
859
862
|
second?: Omit<RelationOptions, 'target'>,
|
|
860
863
|
): PropertyDecorator {
|
|
861
|
-
const explicitThrough = typeof first === 'function' ? second?.through : (first as RelationOptions).through;
|
|
862
864
|
const opts = resolveRelationArgs(first, second);
|
|
863
865
|
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
|
-
}
|
|
872
866
|
// --- relation registry ---
|
|
873
867
|
const ctor = (target as any).constructor;
|
|
874
868
|
if (!relationRegistry.has(ctor)) relationRegistry.set(ctor, {});
|
|
@@ -1,6 +1,6 @@
|
|
|
1
|
-
import {
|
|
1
|
+
import { buildSPARQLQuery, buildPaginationSubquery, hasJsOnlyWhereFilters } from './query-sparql';
|
|
2
2
|
|
|
3
|
-
// Minimal stubs for ModelMetadata
|
|
3
|
+
// Minimal stubs for ModelMetadata
|
|
4
4
|
const emptyMetadata: any = { properties: {}, relations: {} };
|
|
5
5
|
|
|
6
6
|
// Metadata with a required (non-literal) property and a literal-stored property
|
|
@@ -87,19 +87,6 @@ describe('buildSPARQLQuery — SPARQL-level pagination via subquery', () => {
|
|
|
87
87
|
});
|
|
88
88
|
});
|
|
89
89
|
|
|
90
|
-
describe('buildSPARQLOrderLimitOffset', () => {
|
|
91
|
-
it('always returns empty string (pagination uses subquery pattern instead)', () => {
|
|
92
|
-
expect(buildSPARQLOrderLimitOffset(emptyMetadata, {})).toBe('');
|
|
93
|
-
expect(buildSPARQLOrderLimitOffset(emptyMetadata, { limit: 50 })).toBe('');
|
|
94
|
-
expect(buildSPARQLOrderLimitOffset(emptyMetadata, { limit: 50, offset: 100 })).toBe('');
|
|
95
|
-
expect(buildSPARQLOrderLimitOffset(emptyMetadata, { order: { timestamp: 'DESC' } })).toBe('');
|
|
96
|
-
expect(buildSPARQLOrderLimitOffset(emptyMetadata, {
|
|
97
|
-
order: { timestamp: 'DESC' },
|
|
98
|
-
limit: 50,
|
|
99
|
-
offset: 100,
|
|
100
|
-
})).toBe('');
|
|
101
|
-
});
|
|
102
|
-
});
|
|
103
90
|
|
|
104
91
|
describe('buildSPARQLQuery — parse_literal push-down filters', () => {
|
|
105
92
|
const modelClass: any = {};
|
|
@@ -161,13 +148,42 @@ describe('buildSPARQLQuery — structural correctness', () => {
|
|
|
161
148
|
expect(sparql).toContain('SELECT DISTINCT ?source');
|
|
162
149
|
});
|
|
163
150
|
|
|
164
|
-
it('
|
|
151
|
+
it('rejects injection attempts through where clause IRI values', () => {
|
|
165
152
|
const query = {
|
|
166
153
|
where: { category: 'some://uri"> . } UNION { SELECT * WHERE { ?s ?p ?o' },
|
|
167
154
|
};
|
|
168
|
-
|
|
169
|
-
|
|
170
|
-
|
|
155
|
+
expect(() => buildSPARQLQuery(richMetadata, emptyRelations, query, modelClass))
|
|
156
|
+
.toThrow('Invalid IRI component');
|
|
157
|
+
});
|
|
158
|
+
|
|
159
|
+
it('rejects angle brackets in IRI values', () => {
|
|
160
|
+
const query = { where: { category: 'foo<bar>' } };
|
|
161
|
+
expect(() => buildSPARQLQuery(richMetadata, emptyRelations, query, modelClass))
|
|
162
|
+
.toThrow('Invalid IRI component');
|
|
163
|
+
});
|
|
164
|
+
|
|
165
|
+
it('rejects curly braces in IRI values', () => {
|
|
166
|
+
const query = { where: { category: 'foo{bar}' } };
|
|
167
|
+
expect(() => buildSPARQLQuery(richMetadata, emptyRelations, query, modelClass))
|
|
168
|
+
.toThrow('Invalid IRI component');
|
|
169
|
+
});
|
|
170
|
+
|
|
171
|
+
it('rejects spaces in IRI values', () => {
|
|
172
|
+
const query = { where: { category: 'foo bar' } };
|
|
173
|
+
expect(() => buildSPARQLQuery(richMetadata, emptyRelations, query, modelClass))
|
|
174
|
+
.toThrow('Invalid IRI component');
|
|
175
|
+
});
|
|
176
|
+
|
|
177
|
+
it('rejects double quotes in IRI values', () => {
|
|
178
|
+
const query = { where: { category: 'foo"bar' } };
|
|
179
|
+
expect(() => buildSPARQLQuery(richMetadata, emptyRelations, query, modelClass))
|
|
180
|
+
.toThrow('Invalid IRI component');
|
|
181
|
+
});
|
|
182
|
+
|
|
183
|
+
it('allows valid URIs through iri()', () => {
|
|
184
|
+
const query = { where: { category: 'https://example.com/category/food' } };
|
|
185
|
+
expect(() => buildSPARQLQuery(richMetadata, emptyRelations, query, modelClass))
|
|
186
|
+
.not.toThrow();
|
|
171
187
|
});
|
|
172
188
|
});
|
|
173
189
|
|
|
@@ -119,7 +119,9 @@ function escapeSPARQL(value: string): string {
|
|
|
119
119
|
.replace(/"/g, '\\"')
|
|
120
120
|
.replace(/\n/g, "\\n")
|
|
121
121
|
.replace(/\r/g, "\\r")
|
|
122
|
-
.replace(/\t/g, "\\t")
|
|
122
|
+
.replace(/\t/g, "\\t")
|
|
123
|
+
.replace(/\0/g, "")
|
|
124
|
+
.replace(/\f/g, "\\u000C");
|
|
123
125
|
}
|
|
124
126
|
|
|
125
127
|
/**
|
|
@@ -136,8 +138,14 @@ export function formatSPARQLValue(value: any): string {
|
|
|
136
138
|
* Format an AD4M URI as an RDF IRI for use in SPARQL triple patterns.
|
|
137
139
|
* All AD4M link source/predicate/target values become IRIs in angle brackets.
|
|
138
140
|
* The Rust SPARQL service transparently transforms these to valid IRI format.
|
|
141
|
+
*
|
|
142
|
+
* Rejects characters that would break or inject into a SPARQL IRI token,
|
|
143
|
+
* matching the Rust-side `validate_iri()` function.
|
|
139
144
|
*/
|
|
140
145
|
function iri(value: string): string {
|
|
146
|
+
if (/[<>{}" ]/.test(value)) {
|
|
147
|
+
throw new Error(`Invalid IRI component: '${value}'`);
|
|
148
|
+
}
|
|
141
149
|
return `<${value}>`;
|
|
142
150
|
}
|
|
143
151
|
|
|
@@ -297,23 +305,9 @@ export function buildSPARQLQuery(
|
|
|
297
305
|
?_reifier <ad4m://ontology/timestamp> ?timestamp .
|
|
298
306
|
${filterClause}
|
|
299
307
|
}
|
|
300
|
-
${buildSPARQLOrderLimitOffset(metadata, query)}
|
|
301
308
|
`.trim();
|
|
302
309
|
}
|
|
303
310
|
|
|
304
|
-
/**
|
|
305
|
-
* Build ORDER BY / LIMIT / OFFSET clauses for the SPARQL query.
|
|
306
|
-
*
|
|
307
|
-
* NOTE: The outer SELECT returns multiple rows per instance (one per link),
|
|
308
|
-
* so LIMIT/OFFSET at the outer level would cut off links mid-instance.
|
|
309
|
-
* This function is kept for backward compatibility and always returns "".
|
|
310
|
-
* SPARQL-level pagination is handled via a subquery in buildSPARQLQuery
|
|
311
|
-
* using buildPaginationSubquery().
|
|
312
|
-
*/
|
|
313
|
-
export function buildSPARQLOrderLimitOffset(_metadata: ModelMetadata, query: Query): string {
|
|
314
|
-
return "";
|
|
315
|
-
}
|
|
316
|
-
|
|
317
311
|
/**
|
|
318
312
|
* Build an inner subquery that selects DISTINCT ?source URIs with
|
|
319
313
|
* ORDER BY, LIMIT, and OFFSET applied at the instance level.
|
|
@@ -369,7 +363,7 @@ export function buildPaginationSubquery(
|
|
|
369
363
|
{ SELECT DISTINCT ?source${tsSelect} WHERE {${innerJoin}${orderJoinPatterns.join('')}${tsPattern}
|
|
370
364
|
FILTER(isIRI(?source))
|
|
371
365
|
${innerFilter}
|
|
372
|
-
}
|
|
366
|
+
} ${orderByClause} ${limitClause} ${offsetClause} }\n`;
|
|
373
367
|
}
|
|
374
368
|
|
|
375
369
|
/**
|
|
@@ -270,11 +270,18 @@ describe("generateSHACL() relation getter population", () => {
|
|
|
270
270
|
it("should use explicit getter when provided (ignoring auto-generation)", () => {
|
|
271
271
|
const { shape } = (ParentWithRelations as any).generateSHACL();
|
|
272
272
|
|
|
273
|
-
// Getter-only relations have no predicate
|
|
273
|
+
// Getter-only relations have no `through` predicate but must still
|
|
274
|
+
// appear in the SHACL shape so the executor can find the getter; the
|
|
275
|
+
// writer synthesises a deterministic IRI for `sh:path`.
|
|
274
276
|
const customProp = shape.properties.find(
|
|
275
277
|
(p: SHACLPropertyShape) => p.name === "customItems"
|
|
276
278
|
);
|
|
277
|
-
expect(customProp).
|
|
279
|
+
expect(customProp).toBeDefined();
|
|
280
|
+
expect(customProp!.getter).toBe(
|
|
281
|
+
"SELECT ?target WHERE { ?target <test://custom> ?source . }"
|
|
282
|
+
);
|
|
283
|
+
expect(customProp!.path).toBeDefined();
|
|
284
|
+
expect(customProp!.path).toContain("ad4m://getter/");
|
|
278
285
|
});
|
|
279
286
|
|
|
280
287
|
it("should survive full round-trip: generateSHACL → toLinks → fromLinks", () => {
|
|
@@ -299,11 +306,15 @@ describe("generateSHACL() relation getter population", () => {
|
|
|
299
306
|
expect(flaggedProp!.conformanceConditions).toBeDefined();
|
|
300
307
|
expect(flaggedProp!.conformanceConditions!.length).toBeGreaterThan(0);
|
|
301
308
|
|
|
302
|
-
//
|
|
309
|
+
// Getter-only relations now round-trip too — the synthesised path
|
|
310
|
+
// lets the SHACL graph carry the entry through links/fromLinks.
|
|
303
311
|
const customProp = reconstructed.properties.find(
|
|
304
312
|
(p: SHACLPropertyShape) => p.name === "customItems"
|
|
305
313
|
);
|
|
306
|
-
expect(customProp).
|
|
314
|
+
expect(customProp).toBeDefined();
|
|
315
|
+
expect(customProp!.getter).toBe(
|
|
316
|
+
"SELECT ?target WHERE { ?target <test://custom> ?source . }"
|
|
317
|
+
);
|
|
307
318
|
});
|
|
308
319
|
});
|
|
309
320
|
|
|
@@ -574,7 +585,13 @@ describe("where clause validation", () => {
|
|
|
574
585
|
});
|
|
575
586
|
|
|
576
587
|
describe("where clause compilation", () => {
|
|
577
|
-
|
|
588
|
+
// Under the source-of-truth refactor the SHACL writer no longer inlines
|
|
589
|
+
// `where` conditions into the relation's SPARQL getter. Instead it emits
|
|
590
|
+
// `ad4m://whereFilter` + `ad4m://wherePredicates` triples that the
|
|
591
|
+
// Rust executor evaluates as a post-getter pass at query time. These
|
|
592
|
+
// tests assert that contract on the writer side.
|
|
593
|
+
|
|
594
|
+
it("should emit whereFilter and wherePredicates on the relation shape", () => {
|
|
578
595
|
@Model({ name: "WhereTarget" })
|
|
579
596
|
class WhereTarget extends Ad4mModel {
|
|
580
597
|
@Property({ through: "test://status", required: true })
|
|
@@ -595,13 +612,11 @@ describe("where clause compilation", () => {
|
|
|
595
612
|
(p: SHACLPropertyShape) => p.name === "items"
|
|
596
613
|
);
|
|
597
614
|
expect(itemsProp).toBeDefined();
|
|
598
|
-
expect(itemsProp!.
|
|
599
|
-
expect(itemsProp!.
|
|
600
|
-
expect(itemsProp!.getter).toContain("test://status");
|
|
601
|
-
expect(itemsProp!.getter).toContain("active");
|
|
615
|
+
expect(itemsProp!.whereFilter).toEqual({ status: "active" });
|
|
616
|
+
expect(itemsProp!.wherePredicates).toEqual({ status: "test://status" });
|
|
602
617
|
});
|
|
603
618
|
|
|
604
|
-
it("should
|
|
619
|
+
it("should set whereFilter alongside an auto-derived conformance getter when target is provided", () => {
|
|
605
620
|
@Model({ name: "WhereOverrideParent" })
|
|
606
621
|
class WhereOverrideParent extends Ad4mModel {
|
|
607
622
|
@HasMany(() => FlaggedTarget, {
|
|
@@ -616,16 +631,15 @@ describe("where clause compilation", () => {
|
|
|
616
631
|
(p: SHACLPropertyShape) => p.name === "flaggedItems"
|
|
617
632
|
);
|
|
618
633
|
expect(prop).toBeDefined();
|
|
634
|
+
// whereFilter / wherePredicates carry the post-getter filter; type
|
|
635
|
+
// filtering stays on the auto-derived conformance getter.
|
|
636
|
+
expect(prop!.whereFilter).toEqual({ name: "specific" });
|
|
637
|
+
expect(prop!.wherePredicates).toEqual({ name: "test://name" });
|
|
619
638
|
expect(prop!.getter).toBeDefined();
|
|
620
|
-
|
|
621
|
-
expect(prop!.getter).toContain("test://name");
|
|
622
|
-
expect(prop!.getter).toContain("specific");
|
|
623
|
-
// Should NOT contain the auto-derived flag condition
|
|
624
|
-
// (where overrides auto-conformance)
|
|
625
|
-
expect(prop!.getter).not.toContain("test://flagged_type");
|
|
639
|
+
expect(prop!.getter).toContain("test://flagged_type");
|
|
626
640
|
});
|
|
627
641
|
|
|
628
|
-
it("should
|
|
642
|
+
it("should emit whereFilter with a not operator unchanged", () => {
|
|
629
643
|
@Model({ name: "WhereNotTarget" })
|
|
630
644
|
class WhereNotTarget extends Ad4mModel {
|
|
631
645
|
@Property({ through: "test://status" })
|
|
@@ -646,13 +660,11 @@ describe("where clause compilation", () => {
|
|
|
646
660
|
(p: SHACLPropertyShape) => p.name === "items"
|
|
647
661
|
);
|
|
648
662
|
expect(prop).toBeDefined();
|
|
649
|
-
expect(prop!.
|
|
650
|
-
|
|
651
|
-
expect(prop!.getter).toContain("test://status");
|
|
652
|
-
expect(prop!.getter).toContain("archived");
|
|
663
|
+
expect(prop!.whereFilter).toEqual({ status: { not: "archived" } });
|
|
664
|
+
expect(prop!.wherePredicates).toEqual({ status: "test://status" });
|
|
653
665
|
});
|
|
654
666
|
|
|
655
|
-
it("should
|
|
667
|
+
it("should emit whereFilter with array (IN) values unchanged", () => {
|
|
656
668
|
@Model({ name: "WhereArrayTarget" })
|
|
657
669
|
class WhereArrayTarget extends Ad4mModel {
|
|
658
670
|
@Property({ through: "test://category" })
|
|
@@ -673,13 +685,11 @@ describe("where clause compilation", () => {
|
|
|
673
685
|
(p: SHACLPropertyShape) => p.name === "items"
|
|
674
686
|
);
|
|
675
687
|
expect(prop).toBeDefined();
|
|
676
|
-
expect(prop!.
|
|
677
|
-
expect(prop!.
|
|
678
|
-
expect(prop!.getter).toContain("food");
|
|
679
|
-
expect(prop!.getter).toContain("drink");
|
|
688
|
+
expect(prop!.whereFilter).toEqual({ category: ["food", "drink"] });
|
|
689
|
+
expect(prop!.wherePredicates).toEqual({ category: "test://category" });
|
|
680
690
|
});
|
|
681
691
|
|
|
682
|
-
it("should
|
|
692
|
+
it("should emit whereFilter without wherePredicates when target metadata is absent", () => {
|
|
683
693
|
@Model({ name: "WhereNoTargetParent" })
|
|
684
694
|
class WhereNoTargetParent extends Ad4mModel {
|
|
685
695
|
@HasMany({
|
|
@@ -694,12 +704,13 @@ describe("where clause compilation", () => {
|
|
|
694
704
|
(p: SHACLPropertyShape) => p.name === "items"
|
|
695
705
|
);
|
|
696
706
|
expect(prop).toBeDefined();
|
|
697
|
-
expect(prop!.
|
|
698
|
-
|
|
699
|
-
|
|
707
|
+
expect(prop!.whereFilter).toEqual({ "test://status": "active" });
|
|
708
|
+
// Without target metadata the writer cannot resolve property→predicate;
|
|
709
|
+
// the executor falls back to interpreting keys as raw IRIs.
|
|
710
|
+
expect(prop!.wherePredicates).toBeUndefined();
|
|
700
711
|
});
|
|
701
712
|
|
|
702
|
-
it("should set both
|
|
713
|
+
it("should set both whereFilter and sh:class when target is present", () => {
|
|
703
714
|
@Model({ name: "WherePlusClassParent" })
|
|
704
715
|
class WherePlusClassParent extends Ad4mModel {
|
|
705
716
|
@HasMany(() => FlaggedTarget, {
|
|
@@ -714,15 +725,12 @@ describe("where clause compilation", () => {
|
|
|
714
725
|
(p: SHACLPropertyShape) => p.name === "flaggedItems"
|
|
715
726
|
);
|
|
716
727
|
expect(prop).toBeDefined();
|
|
717
|
-
|
|
718
|
-
expect(prop!.getter).toBeDefined();
|
|
719
|
-
expect(prop!.getter).toContain("specific");
|
|
720
|
-
// sh:class still set (target is present)
|
|
728
|
+
expect(prop!.whereFilter).toEqual({ name: "specific" });
|
|
721
729
|
expect(prop!.class).toBeDefined();
|
|
722
730
|
expect(prop!.class).toContain("FlaggedTarget");
|
|
723
731
|
});
|
|
724
732
|
|
|
725
|
-
it("should round-trip
|
|
733
|
+
it("should round-trip whereFilter and wherePredicates through toLinks/fromLinks", () => {
|
|
726
734
|
@Model({ name: "WhereRoundTripTarget" })
|
|
727
735
|
class WhereRoundTripTarget extends Ad4mModel {
|
|
728
736
|
@Property({ through: "test://status", required: true })
|
|
@@ -749,9 +757,8 @@ describe("where clause compilation", () => {
|
|
|
749
757
|
(p: SHACLPropertyShape) => p.name === "items"
|
|
750
758
|
);
|
|
751
759
|
expect(prop).toBeDefined();
|
|
752
|
-
expect(prop!.
|
|
753
|
-
expect(prop!.
|
|
754
|
-
expect(prop!.getter).toContain("active");
|
|
760
|
+
expect(prop!.whereFilter).toEqual({ status: "active" });
|
|
761
|
+
expect(prop!.wherePredicates).toEqual({ status: "test://status" });
|
|
755
762
|
});
|
|
756
763
|
});
|
|
757
764
|
|