@coasys/ad4m 0.13.0-test-7 → 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 +1109 -828
- package/lib/index.js +1096 -828
- 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 -36
- package/lib/src/model/Ad4mModel.js +93 -382
- package/lib/src/model/Ad4mModel.test.js +735 -480
- package/lib/src/model/ModelQueryBuilder.d.ts +5 -10
- package/lib/src/model/ModelQueryBuilder.js +142 -62
- package/lib/src/model/decorators.d.ts +7 -4
- package/lib/src/model/decorators.js +0 -7
- 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.js +10 -92
- package/lib/src/model/query-surreal.d.ts +44 -0
- package/lib/src/model/query-surreal.js +249 -0
- package/lib/src/model/shacl-gen.js +120 -47
- package/lib/src/model/surreal-utils.d.ts +42 -0
- package/lib/src/model/surreal-utils.js +128 -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/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/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/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/SHACLShape.test.js +0 -82
- 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 +11 -8
- 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 +140 -420
- package/src/model/ModelQueryBuilder.ts +136 -71
- 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
- package/lib/src/model/model-manifest.d.ts +0 -41
- package/lib/src/model/model-manifest.js +0 -11
|
@@ -2,97 +2,15 @@ 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";
|
|
9
9
|
import { ModelQueryBuilder } from "./ModelQueryBuilder";
|
|
10
10
|
import { normalizeValue, } from "./hydration";
|
|
11
11
|
// ---------------------------------------------------------------------------
|
|
12
|
-
// Default decoder for file-storage (non-literal resolveLanguage) properties
|
|
13
|
-
// ---------------------------------------------------------------------------
|
|
14
|
-
/**
|
|
15
|
-
* When the Rust executor resolves a non-literal expression it may return a
|
|
16
|
-
* `FileData`-shaped object (`{ data_base64, file_type, ... }`) rather than a
|
|
17
|
-
* raw URI string. If the model class has no custom `transform` registered
|
|
18
|
-
* (e.g. it was synthesised from a SHACL shape at runtime) we still want to
|
|
19
|
-
* decode the content rather than passing raw `FileData` to callers.
|
|
20
|
-
*
|
|
21
|
-
* Decoding rules (mirrors the JS `decodeFileAsJson` / `decodeFileAsString` helpers):
|
|
22
|
-
* - `application/json` (default when `file_type` is absent) → JSON.parse
|
|
23
|
-
* - anything else → raw decoded string
|
|
24
|
-
*
|
|
25
|
-
* If `resolved` is not a `FileData` object the value is returned unchanged so
|
|
26
|
-
* that callers can use this as a safe unconditional fallback.
|
|
27
|
-
*/
|
|
28
|
-
function defaultFileDecode(resolved) {
|
|
29
|
-
if (resolved !== null &&
|
|
30
|
-
typeof resolved === 'object' &&
|
|
31
|
-
'data_base64' in resolved) {
|
|
32
|
-
const fd = resolved;
|
|
33
|
-
let raw;
|
|
34
|
-
try {
|
|
35
|
-
raw = atob(fd.data_base64);
|
|
36
|
-
}
|
|
37
|
-
catch {
|
|
38
|
-
return resolved; // malformed base64 — keep as-is
|
|
39
|
-
}
|
|
40
|
-
const isJson = !fd.file_type || fd.file_type === 'application/json';
|
|
41
|
-
if (isJson) {
|
|
42
|
-
try {
|
|
43
|
-
return JSON.parse(raw);
|
|
44
|
-
}
|
|
45
|
-
catch {
|
|
46
|
-
return raw;
|
|
47
|
-
}
|
|
48
|
-
}
|
|
49
|
-
return raw;
|
|
50
|
-
}
|
|
51
|
-
return resolved;
|
|
52
|
-
}
|
|
53
|
-
// ---------------------------------------------------------------------------
|
|
54
12
|
// Helpers for Rust-side include resolution
|
|
55
13
|
// ---------------------------------------------------------------------------
|
|
56
|
-
/**
|
|
57
|
-
* Recursively enrich relation metadata in the shape with target class shapes
|
|
58
|
-
* so the Rust endpoint can resolve includes in-process (no extra GraphQL
|
|
59
|
-
* round-trips per relation).
|
|
60
|
-
*/
|
|
61
|
-
function enrichShapeForIncludes(metadata, include, allRelMeta) {
|
|
62
|
-
for (const [relName, includeVal] of Object.entries(include)) {
|
|
63
|
-
if (!includeVal)
|
|
64
|
-
continue;
|
|
65
|
-
const meta = allRelMeta[relName];
|
|
66
|
-
if (!meta?.target)
|
|
67
|
-
continue;
|
|
68
|
-
const TargetClass = meta.target();
|
|
69
|
-
// Deep-copy so we don't mutate the cached metadata
|
|
70
|
-
const targetMeta = JSON.parse(JSON.stringify(TargetClass.getModelMetadata()));
|
|
71
|
-
// Ensure the relation is in metadata.relations (fallback for edge cases)
|
|
72
|
-
if (!metadata.relations[relName]) {
|
|
73
|
-
metadata.relations[relName] = {
|
|
74
|
-
name: relName,
|
|
75
|
-
predicate: meta.predicate,
|
|
76
|
-
direction: meta.kind === 'belongsToMany' || meta.kind === 'belongsToOne'
|
|
77
|
-
? 'reverse'
|
|
78
|
-
: 'forward',
|
|
79
|
-
};
|
|
80
|
-
}
|
|
81
|
-
const rel = metadata.relations[relName];
|
|
82
|
-
rel.kind = meta.kind;
|
|
83
|
-
rel.maxCount = meta.maxCount;
|
|
84
|
-
rel.targetShape = targetMeta;
|
|
85
|
-
rel.targetClassName = targetMeta.className;
|
|
86
|
-
// Recurse for nested includes
|
|
87
|
-
const nested = typeof includeVal === 'object' && includeVal !== null
|
|
88
|
-
? includeVal.include
|
|
89
|
-
: undefined;
|
|
90
|
-
if (nested) {
|
|
91
|
-
const targetRelMeta = getRelationsMetadata(TargetClass);
|
|
92
|
-
enrichShapeForIncludes(targetMeta, nested, targetRelMeta);
|
|
93
|
-
}
|
|
94
|
-
}
|
|
95
|
-
}
|
|
96
14
|
/**
|
|
97
15
|
* Construct a model class instance from a plain JSON object returned by the
|
|
98
16
|
* Rust endpoint. Recursively converts included relation values (which come
|
|
@@ -137,22 +55,6 @@ function jsonToModelInstance(ModelClass, perspective, json, include, properties)
|
|
|
137
55
|
}
|
|
138
56
|
instance[key] = value;
|
|
139
57
|
}
|
|
140
|
-
// Apply property transform functions from decorators (only for literal-resolved
|
|
141
|
-
// or no-resolveLanguage properties; non-literal properties are resolved + transformed
|
|
142
|
-
// asynchronously in executeModelQuery).
|
|
143
|
-
try {
|
|
144
|
-
const propsMeta = getPropertiesMetadata(ModelClass);
|
|
145
|
-
for (const [propName, opts] of Object.entries(propsMeta)) {
|
|
146
|
-
const o = opts;
|
|
147
|
-
if (typeof o.transform !== 'function' || !(propName in json))
|
|
148
|
-
continue;
|
|
149
|
-
// Skip non-literal resolveLanguage props — they need async expression resolution first
|
|
150
|
-
if (o.resolveLanguage != null && o.resolveLanguage !== 'literal')
|
|
151
|
-
continue;
|
|
152
|
-
instance[propName] = o.transform(instance[propName]);
|
|
153
|
-
}
|
|
154
|
-
}
|
|
155
|
-
catch (_) { /* no metadata available */ }
|
|
156
58
|
// Recursively convert included relation values to class instances
|
|
157
59
|
if (include) {
|
|
158
60
|
const relMeta = getRelationsMetadata(ModelClass);
|
|
@@ -390,8 +292,8 @@ export class Ad4mModel {
|
|
|
390
292
|
...(options.getter !== undefined && { getter: options.getter }),
|
|
391
293
|
...(options.prologSetter !== undefined && { prologSetter: options.prologSetter }),
|
|
392
294
|
...(options.local !== undefined && { local: options.local }),
|
|
393
|
-
...(options.
|
|
394
|
-
...(options.
|
|
295
|
+
...(options.flag !== undefined && { flag: options.flag }),
|
|
296
|
+
...(options.transform !== undefined && { transform: options.transform })
|
|
395
297
|
};
|
|
396
298
|
}
|
|
397
299
|
// Extract relations (relations) from WeakMap registry
|
|
@@ -576,6 +478,7 @@ export class Ad4mModel {
|
|
|
576
478
|
* • `null` / empty object — skip ALL relations (used by bare
|
|
577
479
|
* subscriptions that don't eagerly load relations).
|
|
578
480
|
*/
|
|
481
|
+
/** @internal */
|
|
579
482
|
takeSnapshot(includedRelations) {
|
|
580
483
|
const ctor = this.constructor;
|
|
581
484
|
const metadata = ctor.getModelMetadata();
|
|
@@ -771,164 +674,14 @@ export class Ad4mModel {
|
|
|
771
674
|
}
|
|
772
675
|
/**
|
|
773
676
|
* Build the JSON parameters needed for a model query/subscription endpoint.
|
|
774
|
-
* 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.
|
|
775
679
|
* @internal
|
|
776
680
|
*/
|
|
777
681
|
static prepareModelQueryParams(query = {}, classNameOverride) {
|
|
778
|
-
const metadata = this.getModelMetadata();
|
|
779
|
-
const className = classNameOverride || metadata.className;
|
|
780
|
-
const queryInput = {};
|
|
781
|
-
if (query.parent) {
|
|
782
|
-
const parentPredicate = resolveParentPredicate(query.parent, this);
|
|
783
|
-
queryInput.parent = { id: query.parent.id, predicate: parentPredicate };
|
|
784
|
-
}
|
|
785
|
-
if (query.properties)
|
|
786
|
-
queryInput.properties = query.properties;
|
|
787
|
-
if (query.include)
|
|
788
|
-
queryInput.include = query.include;
|
|
789
|
-
if (query.where)
|
|
790
|
-
queryInput.where = query.where;
|
|
791
|
-
if (query.order) {
|
|
792
|
-
queryInput.order = Object.entries(query.order).map(([k, v]) => [k, v]);
|
|
793
|
-
}
|
|
794
|
-
if (query.offset !== undefined)
|
|
795
|
-
queryInput.offset = query.offset;
|
|
796
|
-
if (query.limit !== undefined)
|
|
797
|
-
queryInput.limit = query.limit;
|
|
798
|
-
if (query.count !== undefined)
|
|
799
|
-
queryInput.count = query.count;
|
|
800
|
-
queryInput.deepQuery = query.deepQuery ?? true;
|
|
801
|
-
if (query.include) {
|
|
802
|
-
const allRelMeta = getRelationsMetadata(this);
|
|
803
|
-
enrichShapeForIncludes(metadata, query.include, allRelMeta);
|
|
804
|
-
}
|
|
805
|
-
// Pre-compute conformance getters for Rust-side evaluation.
|
|
806
|
-
// Where clauses are NOT compiled into getter SPARQL because stored
|
|
807
|
-
// property values are signed expression envelopes (literal:json:...),
|
|
808
|
-
// not simple literal:string:X values. Instead, where clauses are
|
|
809
|
-
// attached as metadata for Rust-side post-evaluation filtering.
|
|
810
|
-
{
|
|
811
|
-
const allRelMeta = getRelationsMetadata(this);
|
|
812
|
-
for (const [relName, relMeta] of Object.entries(metadata.relations)) {
|
|
813
|
-
const rel = relMeta;
|
|
814
|
-
if (rel.getter || rel.direction === 'reverse' || rel.filter === false)
|
|
815
|
-
continue;
|
|
816
|
-
const meta = allRelMeta[relName];
|
|
817
|
-
if (!meta?.target)
|
|
818
|
-
continue;
|
|
819
|
-
try {
|
|
820
|
-
const TargetClass = meta.target();
|
|
821
|
-
const filter = buildConformanceFilter(meta.predicate, TargetClass);
|
|
822
|
-
if (filter) {
|
|
823
|
-
rel.getter = filter.getter;
|
|
824
|
-
}
|
|
825
|
-
// Attach where-clause metadata for Rust-side post-getter filtering
|
|
826
|
-
if (rel.where) {
|
|
827
|
-
try {
|
|
828
|
-
const targetMetadata = TargetClass.getModelMetadata?.() ?? null;
|
|
829
|
-
if (targetMetadata) {
|
|
830
|
-
const predicates = {};
|
|
831
|
-
for (const propName of Object.keys(rel.where)) {
|
|
832
|
-
if (['id', 'author', 'timestamp'].includes(propName))
|
|
833
|
-
continue;
|
|
834
|
-
const propMeta = targetMetadata.properties[propName];
|
|
835
|
-
if (propMeta?.predicate) {
|
|
836
|
-
predicates[propName] = propMeta.predicate;
|
|
837
|
-
}
|
|
838
|
-
}
|
|
839
|
-
if (Object.keys(predicates).length > 0) {
|
|
840
|
-
rel.whereFilter = rel.where;
|
|
841
|
-
rel.wherePredicates = predicates;
|
|
842
|
-
}
|
|
843
|
-
}
|
|
844
|
-
}
|
|
845
|
-
catch (_) { }
|
|
846
|
-
}
|
|
847
|
-
}
|
|
848
|
-
catch (_) { }
|
|
849
|
-
}
|
|
850
|
-
}
|
|
851
|
-
return {
|
|
852
|
-
className,
|
|
853
|
-
queryJson: JSON.stringify(queryInput),
|
|
854
|
-
shapeJson: JSON.stringify(metadata),
|
|
855
|
-
};
|
|
856
|
-
}
|
|
857
|
-
/**
|
|
858
|
-
* Parse raw model query/subscription result JSON into typed model instances.
|
|
859
|
-
* Used by ModelQueryBuilder to convert subscription updates without circular imports.
|
|
860
|
-
* @internal
|
|
861
|
-
*/
|
|
862
|
-
static parseModelResult(perspective, raw, include, properties) {
|
|
863
|
-
const data = typeof raw === 'string' ? JSON.parse(raw) : raw;
|
|
864
|
-
const arr = data.instances || data;
|
|
865
|
-
if (!Array.isArray(arr))
|
|
866
|
-
return [];
|
|
867
|
-
return arr.map((json) => jsonToModelInstance(this, perspective, json, include, properties));
|
|
868
|
-
}
|
|
869
|
-
/**
|
|
870
|
-
* Resolve non-literal (file-language) properties on an array of already-constructed
|
|
871
|
-
* model instances. Handles two cases:
|
|
872
|
-
*
|
|
873
|
-
* 1. The Rust executor returned a raw URI string → fetch via `getExpression` then apply transform.
|
|
874
|
-
* 2. The Rust executor already resolved the expression and returned a `FileData` object
|
|
875
|
-
* (happens when the perspective backend eagerly fetches file content) → apply transform
|
|
876
|
-
* (or `defaultFileDecode` if no transform is registered on the class, e.g. for SHACL-
|
|
877
|
-
* synthesised model classes).
|
|
878
|
-
*
|
|
879
|
-
* Extracted as a public static so `ModelQueryBuilder.subscribe()` can reuse it without
|
|
880
|
-
* duplicating logic or introducing a circular dependency.
|
|
881
|
-
* @internal
|
|
882
|
-
*/
|
|
883
|
-
static async resolveNonLiteralProps(perspective, instances) {
|
|
884
|
-
const propsMeta = getPropertiesMetadata(this);
|
|
885
|
-
const resolveProps = Object.entries(propsMeta).filter(([, opts]) => opts.resolveLanguage != null &&
|
|
886
|
-
opts.resolveLanguage !== 'literal');
|
|
887
|
-
if (resolveProps.length === 0)
|
|
888
|
-
return;
|
|
889
|
-
await Promise.all(instances.map(async (inst) => {
|
|
890
|
-
for (const [propName, opts] of resolveProps) {
|
|
891
|
-
const val = inst[propName];
|
|
892
|
-
const transform = opts.transform;
|
|
893
|
-
const applyTransform = (resolved) => typeof transform === 'function' ? transform(resolved) : defaultFileDecode(resolved);
|
|
894
|
-
if (typeof val === 'string' && val && !val.startsWith('literal:')) {
|
|
895
|
-
// Case 1: raw URI — fetch from language runtime
|
|
896
|
-
try {
|
|
897
|
-
const expression = await perspective.getExpression(val);
|
|
898
|
-
if (expression) {
|
|
899
|
-
let resolved;
|
|
900
|
-
try {
|
|
901
|
-
resolved = JSON.parse(expression.data);
|
|
902
|
-
}
|
|
903
|
-
catch {
|
|
904
|
-
resolved = expression.data;
|
|
905
|
-
}
|
|
906
|
-
inst[propName] = applyTransform(resolved);
|
|
907
|
-
}
|
|
908
|
-
}
|
|
909
|
-
catch (_) { /* resolution failed — keep raw value */ }
|
|
910
|
-
}
|
|
911
|
-
else if (val !== null && val !== undefined && typeof val === 'object') {
|
|
912
|
-
// Case 2: already resolved by Rust — apply transform / default decode
|
|
913
|
-
inst[propName] = applyTransform(val);
|
|
914
|
-
}
|
|
915
|
-
}
|
|
916
|
-
}));
|
|
917
|
-
}
|
|
918
|
-
// instancesFromQueryResult — removed (superseded by Rust executeModelQuery pipeline)
|
|
919
|
-
/**
|
|
920
|
-
* Execute a model query via the executor-side endpoint.
|
|
921
|
-
*
|
|
922
|
-
* This replaces the old SPARQL-build → hydrate → JS-filter → JS-sort → JS-paginate pipeline
|
|
923
|
-
* with a single RPC to the executor that handles everything in Rust.
|
|
924
|
-
*
|
|
925
|
-
* @internal
|
|
926
|
-
*/
|
|
927
|
-
static async executeModelQuery(perspective, query = {}, classNameOverride) {
|
|
928
682
|
const metadata = this.getModelMetadata();
|
|
929
683
|
const className = classNameOverride || metadata.className;
|
|
930
684
|
// Expand includeAll: true to a full IncludeMap covering every forward relation.
|
|
931
|
-
// Done before queryInput is built so all downstream uses of query.include see the expansion.
|
|
932
685
|
if (query.includeAll) {
|
|
933
686
|
const allRelMeta = getRelationsMetadata(this);
|
|
934
687
|
const expanded = {};
|
|
@@ -937,11 +690,8 @@ export class Ad4mModel {
|
|
|
937
690
|
expanded[relName] = true;
|
|
938
691
|
}
|
|
939
692
|
}
|
|
940
|
-
// Explicit include entries take precedence over the expansion
|
|
941
693
|
query = { ...query, include: { ...expanded, ...query.include } };
|
|
942
694
|
}
|
|
943
|
-
// Build the query input that the Rust endpoint expects.
|
|
944
|
-
// Convert the TS Query type to the executor's ModelQueryInput format.
|
|
945
695
|
const queryInput = {};
|
|
946
696
|
if (query.parent) {
|
|
947
697
|
const parentPredicate = resolveParentPredicate(query.parent, this);
|
|
@@ -965,19 +715,23 @@ export class Ad4mModel {
|
|
|
965
715
|
if (Object.keys(normalIncludes).length > 0)
|
|
966
716
|
queryInput.include = normalIncludes;
|
|
967
717
|
if (Object.keys(projections).length > 0) {
|
|
968
|
-
//
|
|
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.
|
|
969
721
|
const allRelMeta = getRelationsMetadata(this);
|
|
970
722
|
for (const [, proj] of Object.entries(projections)) {
|
|
971
723
|
const relMeta = allRelMeta[proj.from];
|
|
972
|
-
if (!proj.
|
|
724
|
+
if (!proj.targetClassName && relMeta?.target) {
|
|
973
725
|
try {
|
|
974
726
|
const TargetClass = relMeta.target();
|
|
975
727
|
const targetMeta = TargetClass.getModelMetadata?.();
|
|
976
|
-
if (targetMeta) {
|
|
977
|
-
proj.
|
|
728
|
+
if (targetMeta?.className) {
|
|
729
|
+
proj.targetClassName = targetMeta.className;
|
|
978
730
|
}
|
|
979
731
|
}
|
|
980
|
-
catch (
|
|
732
|
+
catch (e) {
|
|
733
|
+
console.debug(`prepareModelQueryParams: target class unavailable for projection:`, e);
|
|
734
|
+
}
|
|
981
735
|
}
|
|
982
736
|
}
|
|
983
737
|
queryInput.projections = projections;
|
|
@@ -986,7 +740,6 @@ export class Ad4mModel {
|
|
|
986
740
|
if (query.where)
|
|
987
741
|
queryInput.where = query.where;
|
|
988
742
|
if (query.order) {
|
|
989
|
-
// Convert { propName: 'ASC' | 'DESC' } to [[propName, 'ASC'|'DESC'], ...]
|
|
990
743
|
queryInput.order = Object.entries(query.order).map(([k, v]) => [k, v]);
|
|
991
744
|
}
|
|
992
745
|
if (query.offset !== undefined)
|
|
@@ -996,88 +749,52 @@ export class Ad4mModel {
|
|
|
996
749
|
if (query.count !== undefined)
|
|
997
750
|
queryInput.count = query.count;
|
|
998
751
|
queryInput.deepQuery = query.deepQuery ?? true;
|
|
999
|
-
//
|
|
1000
|
-
//
|
|
1001
|
-
//
|
|
1002
|
-
|
|
1003
|
-
|
|
1004
|
-
|
|
1005
|
-
|
|
1006
|
-
|
|
1007
|
-
|
|
1008
|
-
|
|
1009
|
-
|
|
1010
|
-
|
|
1011
|
-
|
|
1012
|
-
|
|
1013
|
-
|
|
1014
|
-
|
|
1015
|
-
|
|
1016
|
-
|
|
1017
|
-
|
|
1018
|
-
|
|
1019
|
-
|
|
1020
|
-
|
|
1021
|
-
|
|
1022
|
-
|
|
1023
|
-
|
|
1024
|
-
|
|
1025
|
-
|
|
1026
|
-
|
|
1027
|
-
|
|
1028
|
-
|
|
1029
|
-
|
|
1030
|
-
|
|
1031
|
-
|
|
1032
|
-
|
|
1033
|
-
|
|
1034
|
-
if (rel.where) {
|
|
1035
|
-
try {
|
|
1036
|
-
const targetMetadata = TargetClass.getModelMetadata?.() ?? null;
|
|
1037
|
-
if (targetMetadata) {
|
|
1038
|
-
const predicates = {};
|
|
1039
|
-
for (const propName of Object.keys(rel.where)) {
|
|
1040
|
-
if (['id', 'author', 'timestamp'].includes(propName))
|
|
1041
|
-
continue;
|
|
1042
|
-
const propMeta = targetMetadata.properties[propName];
|
|
1043
|
-
if (propMeta?.predicate) {
|
|
1044
|
-
predicates[propName] = propMeta.predicate;
|
|
1045
|
-
}
|
|
1046
|
-
}
|
|
1047
|
-
if (Object.keys(predicates).length > 0) {
|
|
1048
|
-
rel.whereFilter = rel.where;
|
|
1049
|
-
rel.wherePredicates = predicates;
|
|
1050
|
-
}
|
|
1051
|
-
}
|
|
1052
|
-
}
|
|
1053
|
-
catch (_) { /* target metadata unavailable */ }
|
|
1054
|
-
}
|
|
1055
|
-
}
|
|
1056
|
-
catch (e) {
|
|
1057
|
-
// Target class may not be available; skip silently
|
|
1058
|
-
}
|
|
1059
|
-
}
|
|
1060
|
-
}
|
|
1061
|
-
// Send shape metadata to the executor so it knows the model structure.
|
|
1062
|
-
// This is more reliable than reading SHACL from the store because
|
|
1063
|
-
// the TS decorators are the definitive source of truth.
|
|
1064
|
-
const shapeJson = JSON.stringify(metadata);
|
|
1065
|
-
const queryJson = JSON.stringify(queryInput);
|
|
1066
|
-
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);
|
|
1067
787
|
// Convert JSON instances to model class instances, recursively constructing
|
|
1068
788
|
// class instances for any included relations resolved by Rust.
|
|
1069
789
|
const instances = result.instances.map((json) => {
|
|
1070
790
|
return jsonToModelInstance(this, perspective, json, query.include, query.properties);
|
|
1071
791
|
});
|
|
1072
|
-
//
|
|
1073
|
-
|
|
1074
|
-
|
|
1075
|
-
|
|
1076
|
-
await this.resolveNonLiteralProps(perspective, instances);
|
|
1077
|
-
// Take snapshots for dirty tracking
|
|
1078
|
-
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;
|
|
1079
796
|
for (const inst of instances) {
|
|
1080
|
-
inst.takeSnapshot(snapshotRelations);
|
|
797
|
+
inst.takeSnapshot(snapshotRelations && Object.keys(snapshotRelations).length > 0 ? snapshotRelations : undefined);
|
|
1081
798
|
}
|
|
1082
799
|
return {
|
|
1083
800
|
results: instances,
|
|
@@ -1089,15 +806,14 @@ export class Ad4mModel {
|
|
|
1089
806
|
*
|
|
1090
807
|
* @param perspective - The perspective to search in
|
|
1091
808
|
* @param query - Optional query parameters to filter results
|
|
1092
|
-
* @param
|
|
809
|
+
* @param _engine - **Deprecated.** Accepted for backward compatibility but ignored.
|
|
810
|
+
* All queries now use the Rust SPARQL pipeline.
|
|
1093
811
|
* @returns Array of matching models
|
|
1094
812
|
*
|
|
1095
813
|
* @example
|
|
1096
814
|
* ```typescript
|
|
1097
|
-
* // Get all recipes (uses SPARQL by default)
|
|
1098
815
|
* const allRecipes = await Recipe.findAll(perspective);
|
|
1099
816
|
*
|
|
1100
|
-
* // Get recipes with specific criteria (uses SPARQL)
|
|
1101
817
|
* const recipes = await Recipe.findAll(perspective, {
|
|
1102
818
|
* where: {
|
|
1103
819
|
* name: "Pasta",
|
|
@@ -1106,16 +822,14 @@ export class Ad4mModel {
|
|
|
1106
822
|
* order: { createdAt: "DESC" },
|
|
1107
823
|
* limit: 10
|
|
1108
824
|
* });
|
|
1109
|
-
*
|
|
1110
|
-
* // Explicitly use Prolog (legacy, for backward compatibility)
|
|
1111
|
-
* const recipesProlog = await Recipe.findAll(perspective, {}, false);
|
|
1112
825
|
* ```
|
|
1113
826
|
*/
|
|
1114
|
-
static async findAll(perspective, query
|
|
1115
|
-
|
|
827
|
+
static async findAll(perspective, query) {
|
|
828
|
+
const q = (query ?? {});
|
|
829
|
+
if (q.properties && q.properties.length === 0) {
|
|
1116
830
|
throw new Error("properties[] must not be empty — omit the field to return all properties, or specify at least one field name");
|
|
1117
831
|
}
|
|
1118
|
-
const { results } = await this.executeModelQuery(perspective,
|
|
832
|
+
const { results } = await this.executeModelQuery(perspective, q);
|
|
1119
833
|
return results;
|
|
1120
834
|
}
|
|
1121
835
|
/**
|
|
@@ -1125,7 +839,7 @@ export class Ad4mModel {
|
|
|
1125
839
|
*
|
|
1126
840
|
* @param perspective - The perspective to search in
|
|
1127
841
|
* @param query - Optional query parameters to filter results
|
|
1128
|
-
* @param
|
|
842
|
+
* @param _engine - **Deprecated.** Accepted for backward compatibility but ignored.
|
|
1129
843
|
* @returns The first matching instance, or `null`
|
|
1130
844
|
*
|
|
1131
845
|
* @example
|
|
@@ -1138,8 +852,8 @@ export class Ad4mModel {
|
|
|
1138
852
|
* }
|
|
1139
853
|
* ```
|
|
1140
854
|
*/
|
|
1141
|
-
static async findOne(perspective, query
|
|
1142
|
-
const limitedQuery = { ...query, limit: 1 };
|
|
855
|
+
static async findOne(perspective, query) {
|
|
856
|
+
const limitedQuery = { ...(query ?? {}), limit: 1 };
|
|
1143
857
|
const results = await this.findAll(perspective, limitedQuery);
|
|
1144
858
|
return results[0] ?? null;
|
|
1145
859
|
}
|
|
@@ -1148,7 +862,7 @@ export class Ad4mModel {
|
|
|
1148
862
|
*
|
|
1149
863
|
* @param perspective - The perspective to search in
|
|
1150
864
|
* @param query - Optional query parameters to filter results
|
|
1151
|
-
* @param
|
|
865
|
+
* @param _engine - **Deprecated.** Accepted for backward compatibility but ignored.
|
|
1152
866
|
* @returns Object containing results array and total count
|
|
1153
867
|
*
|
|
1154
868
|
* @example
|
|
@@ -1158,13 +872,11 @@ export class Ad4mModel {
|
|
|
1158
872
|
* limit: 10
|
|
1159
873
|
* });
|
|
1160
874
|
* console.log(`Showing 10 of ${totalCount} dessert recipes`);
|
|
1161
|
-
*
|
|
1162
|
-
* // Use Prolog explicitly (legacy)
|
|
1163
|
-
* const { results, totalCount } = await Recipe.findAllAndCount(perspective, {}, false);
|
|
1164
875
|
* ```
|
|
1165
876
|
*/
|
|
1166
|
-
static async findAllAndCount(perspective, query
|
|
1167
|
-
|
|
877
|
+
static async findAllAndCount(perspective, query) {
|
|
878
|
+
const out = await this.executeModelQuery(perspective, (query ?? {}));
|
|
879
|
+
return out;
|
|
1168
880
|
}
|
|
1169
881
|
/**
|
|
1170
882
|
* Helper function for pagination with explicit page size and number.
|
|
@@ -1183,10 +895,10 @@ export class Ad4mModel {
|
|
|
1183
895
|
* console.log(`Page ${page.pageNumber} of recipes, ${page.results.length} items`);
|
|
1184
896
|
* ```
|
|
1185
897
|
*/
|
|
1186
|
-
static async paginate(perspective, pageSize, pageNumber, query
|
|
1187
|
-
const paginationQuery = { ...(query
|
|
898
|
+
static async paginate(perspective, pageSize, pageNumber, query) {
|
|
899
|
+
const paginationQuery = { ...(query ?? {}), limit: pageSize, offset: pageSize * (pageNumber - 1), count: true };
|
|
1188
900
|
const { results, totalCount } = await this.executeModelQuery(perspective, paginationQuery);
|
|
1189
|
-
return { results, totalCount, pageSize, pageNumber };
|
|
901
|
+
return { results: results, totalCount, pageSize, pageNumber };
|
|
1190
902
|
}
|
|
1191
903
|
/**
|
|
1192
904
|
* Generates a SPARQL COUNT query for the model.
|
|
@@ -1213,8 +925,8 @@ export class Ad4mModel {
|
|
|
1213
925
|
* });
|
|
1214
926
|
* ```
|
|
1215
927
|
*/
|
|
1216
|
-
static async count(perspective, query
|
|
1217
|
-
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 });
|
|
1218
930
|
return totalCount;
|
|
1219
931
|
}
|
|
1220
932
|
async setProperty(key, value, batchId) {
|
|
@@ -1525,27 +1237,10 @@ export class Ad4mModel {
|
|
|
1525
1237
|
if (instances.length === 0)
|
|
1526
1238
|
return;
|
|
1527
1239
|
const metadata = this.getModelMetadata();
|
|
1528
|
-
// Pre-compute conformance getters so the shape sent to Rust includes them
|
|
1529
|
-
const allRelMeta = getRelationsMetadata(this);
|
|
1530
|
-
for (const [relName, relMeta] of Object.entries(metadata.relations)) {
|
|
1531
|
-
const rel = relMeta;
|
|
1532
|
-
if (rel.getter || rel.direction === 'reverse' || rel.filter === false)
|
|
1533
|
-
continue;
|
|
1534
|
-
const meta = allRelMeta[relName];
|
|
1535
|
-
if (!meta?.target)
|
|
1536
|
-
continue;
|
|
1537
|
-
try {
|
|
1538
|
-
const TargetClass = meta.target();
|
|
1539
|
-
const filter = buildConformanceFilter(meta.predicate, TargetClass);
|
|
1540
|
-
if (filter)
|
|
1541
|
-
rel.getter = filter.getter;
|
|
1542
|
-
}
|
|
1543
|
-
catch (_) { /* target class may not be available */ }
|
|
1544
|
-
}
|
|
1545
|
-
const shapeJson = JSON.stringify(metadata);
|
|
1546
1240
|
const instanceIds = instances.map(inst => inst.id || inst._baseExpression);
|
|
1547
|
-
//
|
|
1548
|
-
|
|
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);
|
|
1549
1244
|
// Determine which property names were evaluated for snapshot sync
|
|
1550
1245
|
const evaluatedPropertyNames = [];
|
|
1551
1246
|
for (const [propName, propMeta] of Object.entries(metadata.properties)) {
|
|
@@ -1836,6 +1531,22 @@ export class Ad4mModel {
|
|
|
1836
1531
|
static async register(perspective) {
|
|
1837
1532
|
await perspective.ensureSDNASubjectClass(this);
|
|
1838
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
|
+
}
|
|
1839
1550
|
/**
|
|
1840
1551
|
* Executes a set of model operations inside a single batch (transaction).
|
|
1841
1552
|
*
|
|
@@ -1893,7 +1604,7 @@ export class Ad4mModel {
|
|
|
1893
1604
|
* ```
|
|
1894
1605
|
*/
|
|
1895
1606
|
static query(perspective, query) {
|
|
1896
|
-
return new ModelQueryBuilder(perspective, this, query);
|
|
1607
|
+
return new ModelQueryBuilder(perspective, this, (query ?? {}));
|
|
1897
1608
|
}
|
|
1898
1609
|
/**
|
|
1899
1610
|
* Creates an Ad4mModel class from a JSON Schema definition.
|