@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
|
@@ -2,7 +2,7 @@ import { Literal } from "../Literal";
|
|
|
2
2
|
import { Link } from "../links/Links";
|
|
3
3
|
import { LinkQuery } from "../perspectives/LinkQuery";
|
|
4
4
|
import { makeRandomId } from "./util";
|
|
5
|
-
import { getPropertiesMetadata, getRelationsMetadata,
|
|
5
|
+
import { getPropertiesMetadata, getRelationsMetadata, setPropertyRegistryEntry, setRelationRegistryEntry, Model } from "./decorators";
|
|
6
6
|
import { resolveParentPredicate } from "./query-common";
|
|
7
7
|
import { isArrayType, determinePredicate, determineNamespace, buildModelFromJSONSchema } from "./json-schema";
|
|
8
8
|
import { buildSPARQLQuery } from "./query-sparql";
|
|
@@ -11,46 +11,6 @@ import { normalizeValue, } from "./hydration";
|
|
|
11
11
|
// ---------------------------------------------------------------------------
|
|
12
12
|
// Helpers for Rust-side include resolution
|
|
13
13
|
// ---------------------------------------------------------------------------
|
|
14
|
-
/**
|
|
15
|
-
* Recursively enrich relation metadata in the shape with target class shapes
|
|
16
|
-
* so the Rust endpoint can resolve includes in-process (no extra GraphQL
|
|
17
|
-
* round-trips per relation).
|
|
18
|
-
*/
|
|
19
|
-
function enrichShapeForIncludes(metadata, include, allRelMeta) {
|
|
20
|
-
for (const [relName, includeVal] of Object.entries(include)) {
|
|
21
|
-
if (!includeVal)
|
|
22
|
-
continue;
|
|
23
|
-
const meta = allRelMeta[relName];
|
|
24
|
-
if (!meta?.target)
|
|
25
|
-
continue;
|
|
26
|
-
const TargetClass = meta.target();
|
|
27
|
-
// Deep-copy so we don't mutate the cached metadata
|
|
28
|
-
const targetMeta = JSON.parse(JSON.stringify(TargetClass.getModelMetadata()));
|
|
29
|
-
// Ensure the relation is in metadata.relations (fallback for edge cases)
|
|
30
|
-
if (!metadata.relations[relName]) {
|
|
31
|
-
metadata.relations[relName] = {
|
|
32
|
-
name: relName,
|
|
33
|
-
predicate: meta.predicate,
|
|
34
|
-
direction: meta.kind === 'belongsToMany' || meta.kind === 'belongsToOne'
|
|
35
|
-
? 'reverse'
|
|
36
|
-
: 'forward',
|
|
37
|
-
};
|
|
38
|
-
}
|
|
39
|
-
const rel = metadata.relations[relName];
|
|
40
|
-
rel.kind = meta.kind;
|
|
41
|
-
rel.maxCount = meta.maxCount;
|
|
42
|
-
rel.targetShape = targetMeta;
|
|
43
|
-
rel.targetClassName = targetMeta.className;
|
|
44
|
-
// Recurse for nested includes
|
|
45
|
-
const nested = typeof includeVal === 'object' && includeVal !== null
|
|
46
|
-
? includeVal.include
|
|
47
|
-
: undefined;
|
|
48
|
-
if (nested) {
|
|
49
|
-
const targetRelMeta = getRelationsMetadata(TargetClass);
|
|
50
|
-
enrichShapeForIncludes(targetMeta, nested, targetRelMeta);
|
|
51
|
-
}
|
|
52
|
-
}
|
|
53
|
-
}
|
|
54
14
|
/**
|
|
55
15
|
* Construct a model class instance from a plain JSON object returned by the
|
|
56
16
|
* Rust endpoint. Recursively converts included relation values (which come
|
|
@@ -95,22 +55,6 @@ function jsonToModelInstance(ModelClass, perspective, json, include, properties)
|
|
|
95
55
|
}
|
|
96
56
|
instance[key] = value;
|
|
97
57
|
}
|
|
98
|
-
// Apply property transform functions from decorators (only for literal-resolved
|
|
99
|
-
// or no-resolveLanguage properties; non-literal properties are resolved + transformed
|
|
100
|
-
// asynchronously in executeModelQuery).
|
|
101
|
-
try {
|
|
102
|
-
const propsMeta = getPropertiesMetadata(ModelClass);
|
|
103
|
-
for (const [propName, opts] of Object.entries(propsMeta)) {
|
|
104
|
-
const o = opts;
|
|
105
|
-
if (typeof o.transform !== 'function' || !(propName in json))
|
|
106
|
-
continue;
|
|
107
|
-
// Skip non-literal resolveLanguage props — they need async expression resolution first
|
|
108
|
-
if (o.resolveLanguage != null && o.resolveLanguage !== 'literal')
|
|
109
|
-
continue;
|
|
110
|
-
instance[propName] = o.transform(instance[propName]);
|
|
111
|
-
}
|
|
112
|
-
}
|
|
113
|
-
catch (_) { /* no metadata available */ }
|
|
114
58
|
// Recursively convert included relation values to class instances
|
|
115
59
|
if (include) {
|
|
116
60
|
const relMeta = getRelationsMetadata(ModelClass);
|
|
@@ -348,8 +292,8 @@ export class Ad4mModel {
|
|
|
348
292
|
...(options.getter !== undefined && { getter: options.getter }),
|
|
349
293
|
...(options.prologSetter !== undefined && { prologSetter: options.prologSetter }),
|
|
350
294
|
...(options.local !== undefined && { local: options.local }),
|
|
351
|
-
...(options.
|
|
352
|
-
...(options.
|
|
295
|
+
...(options.flag !== undefined && { flag: options.flag }),
|
|
296
|
+
...(options.transform !== undefined && { transform: options.transform })
|
|
353
297
|
};
|
|
354
298
|
}
|
|
355
299
|
// Extract relations (relations) from WeakMap registry
|
|
@@ -534,6 +478,7 @@ export class Ad4mModel {
|
|
|
534
478
|
* • `null` / empty object — skip ALL relations (used by bare
|
|
535
479
|
* subscriptions that don't eagerly load relations).
|
|
536
480
|
*/
|
|
481
|
+
/** @internal */
|
|
537
482
|
takeSnapshot(includedRelations) {
|
|
538
483
|
const ctor = this.constructor;
|
|
539
484
|
const metadata = ctor.getModelMetadata();
|
|
@@ -729,115 +674,14 @@ export class Ad4mModel {
|
|
|
729
674
|
}
|
|
730
675
|
/**
|
|
731
676
|
* Build the JSON parameters needed for a model query/subscription endpoint.
|
|
732
|
-
* Returns the className
|
|
677
|
+
* Returns the className and queryJson that the Rust executor expects.
|
|
678
|
+
* Shape resolution happens server-side from the perspective's SHACL triples.
|
|
733
679
|
* @internal
|
|
734
680
|
*/
|
|
735
681
|
static prepareModelQueryParams(query = {}, classNameOverride) {
|
|
736
|
-
const metadata = this.getModelMetadata();
|
|
737
|
-
const className = classNameOverride || metadata.className;
|
|
738
|
-
const queryInput = {};
|
|
739
|
-
if (query.parent) {
|
|
740
|
-
const parentPredicate = resolveParentPredicate(query.parent, this);
|
|
741
|
-
queryInput.parent = { id: query.parent.id, predicate: parentPredicate };
|
|
742
|
-
}
|
|
743
|
-
if (query.properties)
|
|
744
|
-
queryInput.properties = query.properties;
|
|
745
|
-
if (query.include)
|
|
746
|
-
queryInput.include = query.include;
|
|
747
|
-
if (query.where)
|
|
748
|
-
queryInput.where = query.where;
|
|
749
|
-
if (query.order) {
|
|
750
|
-
queryInput.order = Object.entries(query.order).map(([k, v]) => [k, v]);
|
|
751
|
-
}
|
|
752
|
-
if (query.offset !== undefined)
|
|
753
|
-
queryInput.offset = query.offset;
|
|
754
|
-
if (query.limit !== undefined)
|
|
755
|
-
queryInput.limit = query.limit;
|
|
756
|
-
if (query.count !== undefined)
|
|
757
|
-
queryInput.count = query.count;
|
|
758
|
-
queryInput.deepQuery = query.deepQuery ?? true;
|
|
759
|
-
if (query.include) {
|
|
760
|
-
const allRelMeta = getRelationsMetadata(this);
|
|
761
|
-
enrichShapeForIncludes(metadata, query.include, allRelMeta);
|
|
762
|
-
}
|
|
763
|
-
// Pre-compute conformance getters for Rust-side evaluation.
|
|
764
|
-
// Where clauses are NOT compiled into getter SPARQL because stored
|
|
765
|
-
// property values are signed expression envelopes (literal:json:...),
|
|
766
|
-
// not simple literal:string:X values. Instead, where clauses are
|
|
767
|
-
// attached as metadata for Rust-side post-evaluation filtering.
|
|
768
|
-
{
|
|
769
|
-
const allRelMeta = getRelationsMetadata(this);
|
|
770
|
-
for (const [relName, relMeta] of Object.entries(metadata.relations)) {
|
|
771
|
-
const rel = relMeta;
|
|
772
|
-
if (rel.getter || rel.direction === 'reverse' || rel.filter === false)
|
|
773
|
-
continue;
|
|
774
|
-
const meta = allRelMeta[relName];
|
|
775
|
-
if (!meta?.target)
|
|
776
|
-
continue;
|
|
777
|
-
try {
|
|
778
|
-
const TargetClass = meta.target();
|
|
779
|
-
const filter = buildConformanceFilter(meta.predicate, TargetClass);
|
|
780
|
-
if (filter) {
|
|
781
|
-
rel.getter = filter.getter;
|
|
782
|
-
}
|
|
783
|
-
// Attach where-clause metadata for Rust-side post-getter filtering
|
|
784
|
-
if (rel.where) {
|
|
785
|
-
try {
|
|
786
|
-
const targetMetadata = TargetClass.getModelMetadata?.() ?? null;
|
|
787
|
-
if (targetMetadata) {
|
|
788
|
-
const predicates = {};
|
|
789
|
-
for (const propName of Object.keys(rel.where)) {
|
|
790
|
-
if (['id', 'author', 'timestamp'].includes(propName))
|
|
791
|
-
continue;
|
|
792
|
-
const propMeta = targetMetadata.properties[propName];
|
|
793
|
-
if (propMeta?.predicate) {
|
|
794
|
-
predicates[propName] = propMeta.predicate;
|
|
795
|
-
}
|
|
796
|
-
}
|
|
797
|
-
if (Object.keys(predicates).length > 0) {
|
|
798
|
-
rel.whereFilter = rel.where;
|
|
799
|
-
rel.wherePredicates = predicates;
|
|
800
|
-
}
|
|
801
|
-
}
|
|
802
|
-
}
|
|
803
|
-
catch (_) { }
|
|
804
|
-
}
|
|
805
|
-
}
|
|
806
|
-
catch (_) { }
|
|
807
|
-
}
|
|
808
|
-
}
|
|
809
|
-
return {
|
|
810
|
-
className,
|
|
811
|
-
queryJson: JSON.stringify(queryInput),
|
|
812
|
-
shapeJson: JSON.stringify(metadata),
|
|
813
|
-
};
|
|
814
|
-
}
|
|
815
|
-
/**
|
|
816
|
-
* Parse raw model query/subscription result JSON into typed model instances.
|
|
817
|
-
* Used by ModelQueryBuilder to convert subscription updates without circular imports.
|
|
818
|
-
* @internal
|
|
819
|
-
*/
|
|
820
|
-
static parseModelResult(perspective, raw, include, properties) {
|
|
821
|
-
const data = typeof raw === 'string' ? JSON.parse(raw) : raw;
|
|
822
|
-
const arr = data.instances || data;
|
|
823
|
-
if (!Array.isArray(arr))
|
|
824
|
-
return [];
|
|
825
|
-
return arr.map((json) => jsonToModelInstance(this, perspective, json, include, properties));
|
|
826
|
-
}
|
|
827
|
-
// instancesFromQueryResult — removed (superseded by Rust executeModelQuery pipeline)
|
|
828
|
-
/**
|
|
829
|
-
* Execute a model query via the executor-side endpoint.
|
|
830
|
-
*
|
|
831
|
-
* This replaces the old SPARQL-build → hydrate → JS-filter → JS-sort → JS-paginate pipeline
|
|
832
|
-
* with a single RPC to the executor that handles everything in Rust.
|
|
833
|
-
*
|
|
834
|
-
* @internal
|
|
835
|
-
*/
|
|
836
|
-
static async executeModelQuery(perspective, query = {}, classNameOverride) {
|
|
837
682
|
const metadata = this.getModelMetadata();
|
|
838
683
|
const className = classNameOverride || metadata.className;
|
|
839
684
|
// Expand includeAll: true to a full IncludeMap covering every forward relation.
|
|
840
|
-
// Done before queryInput is built so all downstream uses of query.include see the expansion.
|
|
841
685
|
if (query.includeAll) {
|
|
842
686
|
const allRelMeta = getRelationsMetadata(this);
|
|
843
687
|
const expanded = {};
|
|
@@ -846,11 +690,8 @@ export class Ad4mModel {
|
|
|
846
690
|
expanded[relName] = true;
|
|
847
691
|
}
|
|
848
692
|
}
|
|
849
|
-
// Explicit include entries take precedence over the expansion
|
|
850
693
|
query = { ...query, include: { ...expanded, ...query.include } };
|
|
851
694
|
}
|
|
852
|
-
// Build the query input that the Rust endpoint expects.
|
|
853
|
-
// Convert the TS Query type to the executor's ModelQueryInput format.
|
|
854
695
|
const queryInput = {};
|
|
855
696
|
if (query.parent) {
|
|
856
697
|
const parentPredicate = resolveParentPredicate(query.parent, this);
|
|
@@ -874,19 +715,23 @@ export class Ad4mModel {
|
|
|
874
715
|
if (Object.keys(normalIncludes).length > 0)
|
|
875
716
|
queryInput.include = normalIncludes;
|
|
876
717
|
if (Object.keys(projections).length > 0) {
|
|
877
|
-
//
|
|
718
|
+
// Tag each projection with its target class name so the executor can
|
|
719
|
+
// resolve the target shape through its in-memory cache when applying
|
|
720
|
+
// projection where-clause filters.
|
|
878
721
|
const allRelMeta = getRelationsMetadata(this);
|
|
879
722
|
for (const [, proj] of Object.entries(projections)) {
|
|
880
723
|
const relMeta = allRelMeta[proj.from];
|
|
881
|
-
if (!proj.
|
|
724
|
+
if (!proj.targetClassName && relMeta?.target) {
|
|
882
725
|
try {
|
|
883
726
|
const TargetClass = relMeta.target();
|
|
884
727
|
const targetMeta = TargetClass.getModelMetadata?.();
|
|
885
|
-
if (targetMeta) {
|
|
886
|
-
proj.
|
|
728
|
+
if (targetMeta?.className) {
|
|
729
|
+
proj.targetClassName = targetMeta.className;
|
|
887
730
|
}
|
|
888
731
|
}
|
|
889
|
-
catch (
|
|
732
|
+
catch (e) {
|
|
733
|
+
console.debug(`prepareModelQueryParams: target class unavailable for projection:`, e);
|
|
734
|
+
}
|
|
890
735
|
}
|
|
891
736
|
}
|
|
892
737
|
queryInput.projections = projections;
|
|
@@ -895,7 +740,6 @@ export class Ad4mModel {
|
|
|
895
740
|
if (query.where)
|
|
896
741
|
queryInput.where = query.where;
|
|
897
742
|
if (query.order) {
|
|
898
|
-
// Convert { propName: 'ASC' | 'DESC' } to [[propName, 'ASC'|'DESC'], ...]
|
|
899
743
|
queryInput.order = Object.entries(query.order).map(([k, v]) => [k, v]);
|
|
900
744
|
}
|
|
901
745
|
if (query.offset !== undefined)
|
|
@@ -905,113 +749,52 @@ export class Ad4mModel {
|
|
|
905
749
|
if (query.count !== undefined)
|
|
906
750
|
queryInput.count = query.count;
|
|
907
751
|
queryInput.deepQuery = query.deepQuery ?? true;
|
|
908
|
-
//
|
|
909
|
-
//
|
|
910
|
-
//
|
|
911
|
-
|
|
912
|
-
|
|
913
|
-
|
|
914
|
-
|
|
915
|
-
|
|
916
|
-
|
|
917
|
-
|
|
918
|
-
|
|
919
|
-
|
|
920
|
-
|
|
921
|
-
|
|
922
|
-
|
|
923
|
-
|
|
924
|
-
|
|
925
|
-
|
|
926
|
-
|
|
927
|
-
|
|
928
|
-
|
|
929
|
-
|
|
930
|
-
|
|
931
|
-
|
|
932
|
-
|
|
933
|
-
|
|
934
|
-
|
|
935
|
-
|
|
936
|
-
|
|
937
|
-
|
|
938
|
-
|
|
939
|
-
|
|
940
|
-
|
|
941
|
-
|
|
942
|
-
|
|
943
|
-
if (rel.where) {
|
|
944
|
-
try {
|
|
945
|
-
const targetMetadata = TargetClass.getModelMetadata?.() ?? null;
|
|
946
|
-
if (targetMetadata) {
|
|
947
|
-
const predicates = {};
|
|
948
|
-
for (const propName of Object.keys(rel.where)) {
|
|
949
|
-
if (['id', 'author', 'timestamp'].includes(propName))
|
|
950
|
-
continue;
|
|
951
|
-
const propMeta = targetMetadata.properties[propName];
|
|
952
|
-
if (propMeta?.predicate) {
|
|
953
|
-
predicates[propName] = propMeta.predicate;
|
|
954
|
-
}
|
|
955
|
-
}
|
|
956
|
-
if (Object.keys(predicates).length > 0) {
|
|
957
|
-
rel.whereFilter = rel.where;
|
|
958
|
-
rel.wherePredicates = predicates;
|
|
959
|
-
}
|
|
960
|
-
}
|
|
961
|
-
}
|
|
962
|
-
catch (_) { /* target metadata unavailable */ }
|
|
963
|
-
}
|
|
964
|
-
}
|
|
965
|
-
catch (e) {
|
|
966
|
-
// Target class may not be available; skip silently
|
|
967
|
-
}
|
|
968
|
-
}
|
|
969
|
-
}
|
|
970
|
-
// Send shape metadata to the executor so it knows the model structure.
|
|
971
|
-
// This is more reliable than reading SHACL from the store because
|
|
972
|
-
// the TS decorators are the definitive source of truth.
|
|
973
|
-
const shapeJson = JSON.stringify(metadata);
|
|
974
|
-
const queryJson = JSON.stringify(queryInput);
|
|
975
|
-
const result = await perspective.modelQuery(className, queryJson, shapeJson);
|
|
752
|
+
// Conformance getters, where filters, and target shapes for includes
|
|
753
|
+
// are all resolved by the executor from the perspective's SHACL triples
|
|
754
|
+
// — no client-side pre-computation is needed any more.
|
|
755
|
+
return {
|
|
756
|
+
className,
|
|
757
|
+
queryJson: JSON.stringify(queryInput),
|
|
758
|
+
metadata,
|
|
759
|
+
};
|
|
760
|
+
}
|
|
761
|
+
/**
|
|
762
|
+
* Parse raw model query/subscription result JSON into typed model instances.
|
|
763
|
+
* Used by ModelQueryBuilder to convert subscription updates without circular imports.
|
|
764
|
+
* @internal
|
|
765
|
+
*/
|
|
766
|
+
static parseModelResult(perspective, raw, include, properties) {
|
|
767
|
+
const data = typeof raw === 'string' ? JSON.parse(raw) : raw;
|
|
768
|
+
const arr = data.instances || data;
|
|
769
|
+
if (!Array.isArray(arr))
|
|
770
|
+
return [];
|
|
771
|
+
return arr.map((json) => jsonToModelInstance(this, perspective, json, include, properties));
|
|
772
|
+
}
|
|
773
|
+
// instancesFromQueryResult — removed (superseded by Rust executeModelQuery pipeline)
|
|
774
|
+
/**
|
|
775
|
+
* Execute a model query via the executor-side endpoint.
|
|
776
|
+
*
|
|
777
|
+
* This replaces the old SPARQL-build → hydrate → JS-filter → JS-sort → JS-paginate pipeline
|
|
778
|
+
* with a single RPC to the executor that handles everything in Rust.
|
|
779
|
+
*
|
|
780
|
+
* @internal
|
|
781
|
+
*/
|
|
782
|
+
static async executeModelQuery(perspective, query = {}, classNameOverride) {
|
|
783
|
+
// Delegate query input building to the shared prepareModelQueryParams
|
|
784
|
+
// helper. The executor resolves the shape from SHACL server-side.
|
|
785
|
+
const { className, queryJson } = this.prepareModelQueryParams(query, classNameOverride);
|
|
786
|
+
const result = await perspective.modelQuery(className, queryJson);
|
|
976
787
|
// Convert JSON instances to model class instances, recursively constructing
|
|
977
788
|
// class instances for any included relations resolved by Rust.
|
|
978
789
|
const instances = result.instances.map((json) => {
|
|
979
790
|
return jsonToModelInstance(this, perspective, json, query.include, query.properties);
|
|
980
791
|
});
|
|
981
|
-
//
|
|
982
|
-
|
|
983
|
-
|
|
984
|
-
|
|
985
|
-
const resolveProps = Object.entries(propsMeta).filter(([, opts]) => opts.resolveLanguage != null &&
|
|
986
|
-
opts.resolveLanguage !== 'literal');
|
|
987
|
-
if (resolveProps.length > 0) {
|
|
988
|
-
await Promise.all(instances.map(async (inst) => {
|
|
989
|
-
for (const [propName, opts] of resolveProps) {
|
|
990
|
-
const val = inst[propName];
|
|
991
|
-
if (typeof val !== 'string' || !val || val.startsWith('literal:'))
|
|
992
|
-
continue;
|
|
993
|
-
try {
|
|
994
|
-
const expression = await perspective.getExpression(val);
|
|
995
|
-
if (expression) {
|
|
996
|
-
let resolved;
|
|
997
|
-
try {
|
|
998
|
-
resolved = JSON.parse(expression.data);
|
|
999
|
-
}
|
|
1000
|
-
catch {
|
|
1001
|
-
resolved = expression.data;
|
|
1002
|
-
}
|
|
1003
|
-
const transform = opts.transform;
|
|
1004
|
-
inst[propName] = typeof transform === 'function' ? transform(resolved) : resolved;
|
|
1005
|
-
}
|
|
1006
|
-
}
|
|
1007
|
-
catch (_) { /* resolution failed — keep raw value */ }
|
|
1008
|
-
}
|
|
1009
|
-
}));
|
|
1010
|
-
}
|
|
1011
|
-
// Take snapshots for dirty tracking
|
|
1012
|
-
const snapshotRelations = queryInput.include;
|
|
792
|
+
// Take snapshots for dirty tracking (exclude $-prefixed projection keys)
|
|
793
|
+
const snapshotRelations = query.include
|
|
794
|
+
? Object.fromEntries(Object.entries(query.include).filter(([k]) => !k.startsWith('$')))
|
|
795
|
+
: undefined;
|
|
1013
796
|
for (const inst of instances) {
|
|
1014
|
-
inst.takeSnapshot(snapshotRelations);
|
|
797
|
+
inst.takeSnapshot(snapshotRelations && Object.keys(snapshotRelations).length > 0 ? snapshotRelations : undefined);
|
|
1015
798
|
}
|
|
1016
799
|
return {
|
|
1017
800
|
results: instances,
|
|
@@ -1023,15 +806,14 @@ export class Ad4mModel {
|
|
|
1023
806
|
*
|
|
1024
807
|
* @param perspective - The perspective to search in
|
|
1025
808
|
* @param query - Optional query parameters to filter results
|
|
1026
|
-
* @param
|
|
809
|
+
* @param _engine - **Deprecated.** Accepted for backward compatibility but ignored.
|
|
810
|
+
* All queries now use the Rust SPARQL pipeline.
|
|
1027
811
|
* @returns Array of matching models
|
|
1028
812
|
*
|
|
1029
813
|
* @example
|
|
1030
814
|
* ```typescript
|
|
1031
|
-
* // Get all recipes (uses SPARQL by default)
|
|
1032
815
|
* const allRecipes = await Recipe.findAll(perspective);
|
|
1033
816
|
*
|
|
1034
|
-
* // Get recipes with specific criteria (uses SPARQL)
|
|
1035
817
|
* const recipes = await Recipe.findAll(perspective, {
|
|
1036
818
|
* where: {
|
|
1037
819
|
* name: "Pasta",
|
|
@@ -1040,16 +822,14 @@ export class Ad4mModel {
|
|
|
1040
822
|
* order: { createdAt: "DESC" },
|
|
1041
823
|
* limit: 10
|
|
1042
824
|
* });
|
|
1043
|
-
*
|
|
1044
|
-
* // Explicitly use Prolog (legacy, for backward compatibility)
|
|
1045
|
-
* const recipesProlog = await Recipe.findAll(perspective, {}, false);
|
|
1046
825
|
* ```
|
|
1047
826
|
*/
|
|
1048
|
-
static async findAll(perspective, query
|
|
1049
|
-
|
|
827
|
+
static async findAll(perspective, query) {
|
|
828
|
+
const q = (query ?? {});
|
|
829
|
+
if (q.properties && q.properties.length === 0) {
|
|
1050
830
|
throw new Error("properties[] must not be empty — omit the field to return all properties, or specify at least one field name");
|
|
1051
831
|
}
|
|
1052
|
-
const { results } = await this.executeModelQuery(perspective,
|
|
832
|
+
const { results } = await this.executeModelQuery(perspective, q);
|
|
1053
833
|
return results;
|
|
1054
834
|
}
|
|
1055
835
|
/**
|
|
@@ -1059,7 +839,7 @@ export class Ad4mModel {
|
|
|
1059
839
|
*
|
|
1060
840
|
* @param perspective - The perspective to search in
|
|
1061
841
|
* @param query - Optional query parameters to filter results
|
|
1062
|
-
* @param
|
|
842
|
+
* @param _engine - **Deprecated.** Accepted for backward compatibility but ignored.
|
|
1063
843
|
* @returns The first matching instance, or `null`
|
|
1064
844
|
*
|
|
1065
845
|
* @example
|
|
@@ -1072,8 +852,8 @@ export class Ad4mModel {
|
|
|
1072
852
|
* }
|
|
1073
853
|
* ```
|
|
1074
854
|
*/
|
|
1075
|
-
static async findOne(perspective, query
|
|
1076
|
-
const limitedQuery = { ...query, limit: 1 };
|
|
855
|
+
static async findOne(perspective, query) {
|
|
856
|
+
const limitedQuery = { ...(query ?? {}), limit: 1 };
|
|
1077
857
|
const results = await this.findAll(perspective, limitedQuery);
|
|
1078
858
|
return results[0] ?? null;
|
|
1079
859
|
}
|
|
@@ -1082,7 +862,7 @@ export class Ad4mModel {
|
|
|
1082
862
|
*
|
|
1083
863
|
* @param perspective - The perspective to search in
|
|
1084
864
|
* @param query - Optional query parameters to filter results
|
|
1085
|
-
* @param
|
|
865
|
+
* @param _engine - **Deprecated.** Accepted for backward compatibility but ignored.
|
|
1086
866
|
* @returns Object containing results array and total count
|
|
1087
867
|
*
|
|
1088
868
|
* @example
|
|
@@ -1092,13 +872,11 @@ export class Ad4mModel {
|
|
|
1092
872
|
* limit: 10
|
|
1093
873
|
* });
|
|
1094
874
|
* console.log(`Showing 10 of ${totalCount} dessert recipes`);
|
|
1095
|
-
*
|
|
1096
|
-
* // Use Prolog explicitly (legacy)
|
|
1097
|
-
* const { results, totalCount } = await Recipe.findAllAndCount(perspective, {}, false);
|
|
1098
875
|
* ```
|
|
1099
876
|
*/
|
|
1100
|
-
static async findAllAndCount(perspective, query
|
|
1101
|
-
|
|
877
|
+
static async findAllAndCount(perspective, query) {
|
|
878
|
+
const out = await this.executeModelQuery(perspective, (query ?? {}));
|
|
879
|
+
return out;
|
|
1102
880
|
}
|
|
1103
881
|
/**
|
|
1104
882
|
* Helper function for pagination with explicit page size and number.
|
|
@@ -1117,10 +895,10 @@ export class Ad4mModel {
|
|
|
1117
895
|
* console.log(`Page ${page.pageNumber} of recipes, ${page.results.length} items`);
|
|
1118
896
|
* ```
|
|
1119
897
|
*/
|
|
1120
|
-
static async paginate(perspective, pageSize, pageNumber, query
|
|
1121
|
-
const paginationQuery = { ...(query
|
|
898
|
+
static async paginate(perspective, pageSize, pageNumber, query) {
|
|
899
|
+
const paginationQuery = { ...(query ?? {}), limit: pageSize, offset: pageSize * (pageNumber - 1), count: true };
|
|
1122
900
|
const { results, totalCount } = await this.executeModelQuery(perspective, paginationQuery);
|
|
1123
|
-
return { results, totalCount, pageSize, pageNumber };
|
|
901
|
+
return { results: results, totalCount, pageSize, pageNumber };
|
|
1124
902
|
}
|
|
1125
903
|
/**
|
|
1126
904
|
* Generates a SPARQL COUNT query for the model.
|
|
@@ -1147,8 +925,8 @@ export class Ad4mModel {
|
|
|
1147
925
|
* });
|
|
1148
926
|
* ```
|
|
1149
927
|
*/
|
|
1150
|
-
static async count(perspective, query
|
|
1151
|
-
const { totalCount } = await this.executeModelQuery(perspective, { ...query, limit: 0 });
|
|
928
|
+
static async count(perspective, query) {
|
|
929
|
+
const { totalCount } = await this.executeModelQuery(perspective, { ...(query ?? {}), limit: 0 });
|
|
1152
930
|
return totalCount;
|
|
1153
931
|
}
|
|
1154
932
|
async setProperty(key, value, batchId) {
|
|
@@ -1459,27 +1237,10 @@ export class Ad4mModel {
|
|
|
1459
1237
|
if (instances.length === 0)
|
|
1460
1238
|
return;
|
|
1461
1239
|
const metadata = this.getModelMetadata();
|
|
1462
|
-
// Pre-compute conformance getters so the shape sent to Rust includes them
|
|
1463
|
-
const allRelMeta = getRelationsMetadata(this);
|
|
1464
|
-
for (const [relName, relMeta] of Object.entries(metadata.relations)) {
|
|
1465
|
-
const rel = relMeta;
|
|
1466
|
-
if (rel.getter || rel.direction === 'reverse' || rel.filter === false)
|
|
1467
|
-
continue;
|
|
1468
|
-
const meta = allRelMeta[relName];
|
|
1469
|
-
if (!meta?.target)
|
|
1470
|
-
continue;
|
|
1471
|
-
try {
|
|
1472
|
-
const TargetClass = meta.target();
|
|
1473
|
-
const filter = buildConformanceFilter(meta.predicate, TargetClass);
|
|
1474
|
-
if (filter)
|
|
1475
|
-
rel.getter = filter.getter;
|
|
1476
|
-
}
|
|
1477
|
-
catch (_) { /* target class may not be available */ }
|
|
1478
|
-
}
|
|
1479
|
-
const shapeJson = JSON.stringify(metadata);
|
|
1480
1240
|
const instanceIds = instances.map(inst => inst.id || inst._baseExpression);
|
|
1481
|
-
//
|
|
1482
|
-
|
|
1241
|
+
// The executor reads getter SPARQL from the perspective's SHACL triples
|
|
1242
|
+
// (written by `addSdna`), so no shape JSON is shipped with the call.
|
|
1243
|
+
const result = await perspective.evaluateGetters(metadata.className, instanceIds, propertyNames);
|
|
1483
1244
|
// Determine which property names were evaluated for snapshot sync
|
|
1484
1245
|
const evaluatedPropertyNames = [];
|
|
1485
1246
|
for (const [propName, propMeta] of Object.entries(metadata.properties)) {
|
|
@@ -1770,6 +1531,22 @@ export class Ad4mModel {
|
|
|
1770
1531
|
static async register(perspective) {
|
|
1771
1532
|
await perspective.ensureSDNASubjectClass(this);
|
|
1772
1533
|
}
|
|
1534
|
+
/**
|
|
1535
|
+
* Batch-registers multiple model classes on a perspective in a single RPC call.
|
|
1536
|
+
* This is significantly faster than calling `register()` on each model individually
|
|
1537
|
+
* because it eliminates N-1 round-trips and mutex acquisitions.
|
|
1538
|
+
*
|
|
1539
|
+
* @param perspective - The perspective to register the models on
|
|
1540
|
+
* @param models - Array of Ad4mModel subclasses to register
|
|
1541
|
+
*
|
|
1542
|
+
* @example
|
|
1543
|
+
* ```typescript
|
|
1544
|
+
* await Ad4mModel.registerAll(perspective, [Community, Channel, Message, Task]);
|
|
1545
|
+
* ```
|
|
1546
|
+
*/
|
|
1547
|
+
static async registerAll(perspective, models) {
|
|
1548
|
+
await perspective.ensureSubjectClasses(models);
|
|
1549
|
+
}
|
|
1773
1550
|
/**
|
|
1774
1551
|
* Executes a set of model operations inside a single batch (transaction).
|
|
1775
1552
|
*
|
|
@@ -1827,7 +1604,7 @@ export class Ad4mModel {
|
|
|
1827
1604
|
* ```
|
|
1828
1605
|
*/
|
|
1829
1606
|
static query(perspective, query) {
|
|
1830
|
-
return new ModelQueryBuilder(perspective, this, query);
|
|
1607
|
+
return new ModelQueryBuilder(perspective, this, (query ?? {}));
|
|
1831
1608
|
}
|
|
1832
1609
|
/**
|
|
1833
1610
|
* Creates an Ad4mModel class from a JSON Schema definition.
|