@coasys/ad4m 0.13.0-test-8-profile-cache-fix → 0.13.0-test-9
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 +136 -18
- package/lib/index.js +136 -18
- 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/model/Ad4mModel.test.js +735 -480
- package/lib/src/model/decorators.d.ts +20 -1
- package/lib/src/model/decorators.js +33 -2
- package/lib/src/model/query-sparql.d.ts +1 -0
- package/lib/src/model/query-sparql.js +13 -0
- 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.d.ts +15 -1
- package/lib/src/model/shacl-gen.js +23 -1
- 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 +14 -3
- package/lib/src/neighbourhood/NeighbourhoodProxy.test.js +33 -33
- package/lib/src/perspectives/PerspectiveProxy.d.ts +17 -0
- package/lib/src/perspectives/PerspectiveProxy.js +67 -15
- package/lib/src/perspectives/PerspectiveProxy.test.d.ts +1 -0
- package/lib/src/perspectives/PerspectiveProxy.test.js +34 -0
- package/lib/src/restClient.d.ts +52 -0
- package/lib/src/restClient.js +227 -0
- package/lib/src/shacl/SHACLShape.test.js +0 -82
- package/package.json +11 -8
- package/src/model/Ad4mModel.test.ts +103 -0
- package/src/model/decorators.ts +37 -3
- package/src/model/query-sparql.test.ts +148 -0
- package/src/model/query-sparql.ts +15 -0
- package/src/model/shacl-gen.ts +23 -0
- package/src/model/types.ts +28 -6
- package/src/perspectives/PerspectiveProxy.ts +73 -20
- package/lib/src/model/model-manifest.d.ts +0 -41
- package/lib/src/model/model-manifest.js +0 -11
|
@@ -24,6 +24,7 @@ import type { Where, Query, ModelMetadata, PropertyMetadata } from "./types";
|
|
|
24
24
|
* - Literal-stored properties (equality, comparison, contains, etc.)
|
|
25
25
|
* - Reverse relations (belongsToOne / belongsToMany)
|
|
26
26
|
* - author / timestamp filters (skipped by buildSPARQLWhereFilters)
|
|
27
|
+
* - OR / AND / NOT combinators (skipped by buildSPARQLWhereFilters — see below)
|
|
27
28
|
*
|
|
28
29
|
* When JS-only filters exist, SPARQL-level LIMIT/OFFSET must NOT be applied
|
|
29
30
|
* because the database would cap the candidate set before JS filters run,
|
|
@@ -39,6 +40,15 @@ export function hasJsOnlyWhereFilters(
|
|
|
39
40
|
for (const [propertyName, condition] of Object.entries(where)) {
|
|
40
41
|
if (propertyName === "base" || propertyName === "id") continue;
|
|
41
42
|
|
|
43
|
+
// OR/AND/NOT: buildSPARQLWhereFilters never emits a SPARQL translation
|
|
44
|
+
// for these regardless of what their branches contain, so their mere
|
|
45
|
+
// presence — not just JS-only conditions within a branch — must block
|
|
46
|
+
// SPARQL-level pagination. Otherwise LIMIT/OFFSET would be applied
|
|
47
|
+
// before the (Rust-side, post-hydration) combinator filter ever runs.
|
|
48
|
+
if (propertyName === "OR" || propertyName === "AND" || propertyName === "NOT") {
|
|
49
|
+
return true;
|
|
50
|
+
}
|
|
51
|
+
|
|
42
52
|
// author/timestamp filters are handled in JS
|
|
43
53
|
if (propertyName === "author" || propertyName === "timestamp") return true;
|
|
44
54
|
|
|
@@ -381,6 +391,11 @@ function buildSPARQLWhereFilters(
|
|
|
381
391
|
const filters: string[] = [];
|
|
382
392
|
|
|
383
393
|
for (const [propertyName, condition] of Object.entries(where)) {
|
|
394
|
+
// OR/AND/NOT are evaluated Rust-side after hydration; no SPARQL emission needed.
|
|
395
|
+
if (propertyName === "OR" || propertyName === "AND" || propertyName === "NOT") {
|
|
396
|
+
continue;
|
|
397
|
+
}
|
|
398
|
+
|
|
384
399
|
// 'base' maps to ?source
|
|
385
400
|
if (propertyName === "base" || propertyName === "id") {
|
|
386
401
|
if (Array.isArray(condition)) {
|
package/src/model/shacl-gen.ts
CHANGED
|
@@ -34,6 +34,17 @@ export function buildSHACL(
|
|
|
34
34
|
properties: Record<string, PropertyMetadataEntry>,
|
|
35
35
|
allRelationsMeta: Record<string, RelationMetadataEntry>,
|
|
36
36
|
conformanceFilterFn: ConformanceFilterFn,
|
|
37
|
+
/**
|
|
38
|
+
* Optional early-cache seeding callback. When invoked with a
|
|
39
|
+
* partial `{ shape, name }`, any re-entrant `generateSHACL()`
|
|
40
|
+
* call on the same target — which happens when a relation's
|
|
41
|
+
* `target: () => SameClass` points at us, directly or
|
|
42
|
+
* transitively — observes the in-progress shape rather than
|
|
43
|
+
* re-entering this function infinitely. Provided by `@Model` via
|
|
44
|
+
* `getMemoizedSHACL`; safe to omit when calling `buildSHACL`
|
|
45
|
+
* directly (e.g. from a one-off SDNA build tool).
|
|
46
|
+
*/
|
|
47
|
+
seedCache?: (partial: { shape: SHACLShape; name: string }) => void,
|
|
37
48
|
): { shape: SHACLShape; name: string } {
|
|
38
49
|
const obj = target.prototype;
|
|
39
50
|
|
|
@@ -66,6 +77,18 @@ export function buildSHACL(
|
|
|
66
77
|
const targetClass = `${namespace}${subjectName}`;
|
|
67
78
|
const shape = new SHACLShape(shapeUri, targetClass);
|
|
68
79
|
|
|
80
|
+
// ── Seed the memoisation cache while we keep building ──────────────
|
|
81
|
+
// Any subsequent `target.generateSHACL()` call from inside this
|
|
82
|
+
// function (typically when walking a self-referential or
|
|
83
|
+
// mutually-recursive relation target) will now observe the
|
|
84
|
+
// already-allocated `shape` rather than re-entering `buildSHACL`
|
|
85
|
+
// and overflowing the stack. The shape is mutated in place as we
|
|
86
|
+
// populate it below, so the eventual cached value and the value
|
|
87
|
+
// recursive callers see are the same object.
|
|
88
|
+
if (seedCache) {
|
|
89
|
+
seedCache({ shape, name: subjectName });
|
|
90
|
+
}
|
|
91
|
+
|
|
69
92
|
// Detect @Model inheritance — if the parent class also has
|
|
70
93
|
// generateSHACL it is itself a @Model and we reference its shape
|
|
71
94
|
// via sh:node so SHACL validators can walk the hierarchy.
|
package/src/model/types.ts
CHANGED
|
@@ -25,8 +25,25 @@ export type WhereOps = {
|
|
|
25
25
|
gte: number; // greater than or equal to
|
|
26
26
|
contains: string | number; // substring/element check
|
|
27
27
|
};
|
|
28
|
-
export type WhereCondition =
|
|
29
|
-
|
|
28
|
+
export type WhereCondition =
|
|
29
|
+
| string
|
|
30
|
+
| number
|
|
31
|
+
| boolean
|
|
32
|
+
| string[]
|
|
33
|
+
| number[]
|
|
34
|
+
| { [K in keyof WhereOps]?: WhereOps[K] }
|
|
35
|
+
| Where[]
|
|
36
|
+
| Where;
|
|
37
|
+
|
|
38
|
+
export type Where = {
|
|
39
|
+
/** Logical OR: instance must satisfy at least one of the given sub-clauses. */
|
|
40
|
+
OR?: Where[];
|
|
41
|
+
/** Logical AND: instance must satisfy all of the given sub-clauses. */
|
|
42
|
+
AND?: Where[];
|
|
43
|
+
/** Logical NOT: instance must NOT satisfy the given sub-clause. */
|
|
44
|
+
NOT?: Where;
|
|
45
|
+
[propertyName: string]: WhereCondition | undefined;
|
|
46
|
+
};
|
|
30
47
|
export type Order = { [propertyName: string]: "ASC" | "DESC" };
|
|
31
48
|
|
|
32
49
|
/**
|
|
@@ -239,7 +256,7 @@ export type TypedWhereCondition<V> =
|
|
|
239
256
|
: WhereCondition;
|
|
240
257
|
|
|
241
258
|
/** Strict Where: keys constrained to T's properties, plus the well-known
|
|
242
|
-
* link-metadata fields (`id`/`author`/`timestamp`). */
|
|
259
|
+
* link-metadata fields (`id`/`author`/`timestamp`) and logical combinators. */
|
|
243
260
|
type StrictTypedWhere<T extends Ad4mModel> =
|
|
244
261
|
& { [K in PropertyKeysOf<T>]?: TypedWhereCondition<T[K]> }
|
|
245
262
|
& {
|
|
@@ -247,6 +264,9 @@ type StrictTypedWhere<T extends Ad4mModel> =
|
|
|
247
264
|
id?: string | string[];
|
|
248
265
|
author?: WhereCondition;
|
|
249
266
|
timestamp?: WhereCondition;
|
|
267
|
+
OR?: StrictTypedWhere<T>[];
|
|
268
|
+
AND?: StrictTypedWhere<T>[];
|
|
269
|
+
NOT?: StrictTypedWhere<T>;
|
|
250
270
|
};
|
|
251
271
|
|
|
252
272
|
/** Public typed `where` for a model class. Falls back to the loose `Where`
|
|
@@ -256,9 +276,11 @@ export type TypedWhere<T extends Ad4mModel> =
|
|
|
256
276
|
|
|
257
277
|
// ---- Typed order -------------------------------------------------------------
|
|
258
278
|
|
|
259
|
-
type StrictTypedOrder<T extends Ad4mModel> =
|
|
260
|
-
[K in PropertyKeysOf<T> | 'timestamp' | 'author' | 'createdAt' | 'updatedAt']?: 'ASC' | 'DESC'
|
|
261
|
-
|
|
279
|
+
type StrictTypedOrder<T extends Ad4mModel> =
|
|
280
|
+
& { [K in PropertyKeysOf<T> | 'timestamp' | 'author' | 'createdAt' | 'updatedAt']?: 'ASC' | 'DESC' }
|
|
281
|
+
// $-prefixed projection count keys (e.g. "$likeCount") — typed at the
|
|
282
|
+
// include map level but accepted here so callers can sort by them.
|
|
283
|
+
& { [K in `$${string}`]?: 'ASC' | 'DESC' };
|
|
262
284
|
|
|
263
285
|
export type TypedOrder<T extends Ad4mModel> =
|
|
264
286
|
HasNoTypedFields<T> extends true ? Order : StrictTypedOrder<T>;
|
|
@@ -1293,12 +1293,25 @@ export class PerspectiveProxy {
|
|
|
1293
1293
|
predicate: "sh://property"
|
|
1294
1294
|
}));
|
|
1295
1295
|
|
|
1296
|
-
// Fetch all links from the shape and its property shapes
|
|
1296
|
+
// Fetch all links from the shape and its property shapes. These reads are
|
|
1297
|
+
// independent of each other, so fire them concurrently rather than one RPC
|
|
1298
|
+
// round trip at a time — over a remote (non-loopback) connection, a shape with
|
|
1299
|
+
// a dozen properties otherwise pays a dozen sequential round trips just to load.
|
|
1297
1300
|
const sourceUris = [shapeUri, ...propertyLinks.map(l => l.data.target)];
|
|
1301
|
+
const linksByUri = await Promise.all(sourceUris.map(uri => this.get(new LinkQuery({ source: uri }))));
|
|
1302
|
+
// Dedupe by (source, predicate, target): a perspective that's accumulated duplicate
|
|
1303
|
+
// SDNA links (e.g. from repeated registration attempts, or executor-side sync bugs)
|
|
1304
|
+
// would otherwise feed the same triple into SHACLShape.fromLinks more than once —
|
|
1305
|
+
// harmless for scalar fields like targetClass (first match wins) but can surface as
|
|
1306
|
+
// visibly duplicated properties for repeated sh://property links. Cheap: this is an
|
|
1307
|
+
// in-memory pass over data already fetched, no extra round trips.
|
|
1308
|
+
const seenLinks = new Set<string>();
|
|
1298
1309
|
const allLinks: Array<{source: string, predicate: string, target: string}> = [];
|
|
1299
|
-
for (const
|
|
1300
|
-
const links = await this.get(new LinkQuery({ source: uri }));
|
|
1310
|
+
for (const links of linksByUri) {
|
|
1301
1311
|
for (const l of links) {
|
|
1312
|
+
const key = `${l.data.source} ${l.data.predicate} ${l.data.target}`;
|
|
1313
|
+
if (seenLinks.has(key)) continue;
|
|
1314
|
+
seenLinks.add(key);
|
|
1302
1315
|
allLinks.push({
|
|
1303
1316
|
source: l.data.source,
|
|
1304
1317
|
predicate: l.data.predicate,
|
|
@@ -1306,34 +1319,74 @@ export class PerspectiveProxy {
|
|
|
1306
1319
|
});
|
|
1307
1320
|
}
|
|
1308
1321
|
}
|
|
1309
|
-
|
|
1322
|
+
|
|
1310
1323
|
const shapeLinks = allLinks;
|
|
1311
|
-
|
|
1324
|
+
|
|
1312
1325
|
return SHACLShape.fromLinks(shapeLinks, shapeUri);
|
|
1313
1326
|
}
|
|
1314
1327
|
|
|
1315
1328
|
/**
|
|
1316
|
-
*
|
|
1329
|
+
* List the names of every SHACL shape stored in this Perspective, without fetching
|
|
1330
|
+
* each shape's full definition (properties, target class, etc.) — just the cheap
|
|
1331
|
+
* `ad4m://has_shacl` enumeration, one round trip regardless of how many shapes exist.
|
|
1332
|
+
* Use this to check which shapes are actually worth resolving via `getShacl()` before
|
|
1333
|
+
* paying for each one's full (multi-round-trip) fetch.
|
|
1317
1334
|
*/
|
|
1318
|
-
async
|
|
1335
|
+
async getShaclNames(): Promise<string[]> {
|
|
1319
1336
|
const nameLinks = await this.get(new LinkQuery({
|
|
1320
1337
|
source: "ad4m://self",
|
|
1321
1338
|
predicate: "ad4m://has_shacl"
|
|
1322
1339
|
}));
|
|
1323
|
-
|
|
1324
|
-
|
|
1325
|
-
|
|
1326
|
-
|
|
1327
|
-
const name = Literal.fromUrl(
|
|
1328
|
-
|
|
1329
|
-
|
|
1330
|
-
|
|
1331
|
-
|
|
1332
|
-
|
|
1333
|
-
|
|
1340
|
+
// Dedupe: a perspective with duplicate `has_shacl` links (see the dedup note in
|
|
1341
|
+
// getShacl()) would otherwise report the same name more than once, causing callers
|
|
1342
|
+
// to redundantly resolve (or redundantly disambiguate) it multiple times.
|
|
1343
|
+
const names = nameLinks.map((nameLink) => {
|
|
1344
|
+
const name = Literal.fromUrl(nameLink.data.target).get() as string;
|
|
1345
|
+
return name.replace('shacl://', '');
|
|
1346
|
+
});
|
|
1347
|
+
return [...new Set(names)];
|
|
1348
|
+
}
|
|
1349
|
+
|
|
1350
|
+
/**
|
|
1351
|
+
* Resolve just a shape's `sh:targetClass` by name, without fetching its properties —
|
|
1352
|
+
* two round trips (name → shapeUri, then shapeUri's own direct triples) instead of
|
|
1353
|
+
* `getShacl()`'s full walk (which also fetches every property sub-shape). Use this to
|
|
1354
|
+
* disambiguate a shape name that collides with another app's `@Model({ name })` string
|
|
1355
|
+
* (the bare `shacl://{name}` mapping ad4m-core uses is namespace-blind — see
|
|
1356
|
+
* `getShaclNames()` callers for why that matters) before paying for a full fetch.
|
|
1357
|
+
*/
|
|
1358
|
+
async getShaclTargetClass(name: string): Promise<string | undefined> {
|
|
1359
|
+
const nameMapping = Literal.fromUrl(`literal:string:shacl://${name}`);
|
|
1360
|
+
const shapeUriLinks = await this.get(new LinkQuery({
|
|
1361
|
+
source: nameMapping.toUrl(),
|
|
1362
|
+
predicate: "ad4m://shacl_shape_uri"
|
|
1363
|
+
}));
|
|
1364
|
+
if (shapeUriLinks.length === 0) {
|
|
1365
|
+
return undefined;
|
|
1334
1366
|
}
|
|
1335
|
-
|
|
1336
|
-
|
|
1367
|
+
const shapeUri = shapeUriLinks[0].data.target;
|
|
1368
|
+
|
|
1369
|
+
const shapeOwnLinks = await this.get(new LinkQuery({ source: shapeUri }));
|
|
1370
|
+
return shapeOwnLinks.find(l => l.data.predicate === "sh://targetClass")?.data.target;
|
|
1371
|
+
}
|
|
1372
|
+
|
|
1373
|
+
/**
|
|
1374
|
+
* Get all SHACL shapes stored in this Perspective
|
|
1375
|
+
*/
|
|
1376
|
+
async getAllShacl(): Promise<Array<{name: string, shape: SHACLShape}>> {
|
|
1377
|
+
const shapeNames = await this.getShaclNames();
|
|
1378
|
+
|
|
1379
|
+
// Each shape is fetched independently of the others — resolve them concurrently.
|
|
1380
|
+
// Sequentially awaiting getShacl() per shape means a perspective with N SDNA
|
|
1381
|
+
// models pays N times getShacl()'s own multi-round-trip cost one after another;
|
|
1382
|
+
// over a remote connection with real per-call latency that compounds into the
|
|
1383
|
+
// dominant cost of switching into a perspective at all.
|
|
1384
|
+
const results = await Promise.all(shapeNames.map(async (shapeName) => {
|
|
1385
|
+
const shape = await this.getShacl(shapeName);
|
|
1386
|
+
return shape ? { name: shapeName, shape } : null;
|
|
1387
|
+
}));
|
|
1388
|
+
|
|
1389
|
+
return results.filter((s): s is { name: string, shape: SHACLShape } => s !== null);
|
|
1337
1390
|
}
|
|
1338
1391
|
|
|
1339
1392
|
/**
|
|
@@ -1,41 +0,0 @@
|
|
|
1
|
-
/**
|
|
2
|
-
* Types for the perspective model manifest — a human-readable, AI-friendly summary
|
|
3
|
-
* of all Ad4mModel-compatible classes defined in a perspective's SHACL shapes.
|
|
4
|
-
*
|
|
5
|
-
* Used by `PerspectiveProxy.getModelManifest()` and consumed by WE's AI context
|
|
6
|
-
* injection (`formatManifestForPrompt`) to describe external perspective models
|
|
7
|
-
* to the schema-generation AI.
|
|
8
|
-
*
|
|
9
|
-
* @module
|
|
10
|
-
*/
|
|
11
|
-
/** Normalised description of a single property on a model class. */
|
|
12
|
-
export interface ModelManifestProperty {
|
|
13
|
-
/** Property name as declared in the SHACL shape (e.g. "name", "body", "participants"). */
|
|
14
|
-
name: string;
|
|
15
|
-
/** The exact RDF predicate URI (e.g. "flux://has_name"). */
|
|
16
|
-
predicate: string;
|
|
17
|
-
/** Normalised scalar type; inferred from xsd:/sh: datatype + nodeKind. */
|
|
18
|
-
type: 'string' | 'number' | 'boolean' | 'uri';
|
|
19
|
-
/** `true` when maxCount is absent or > 1 (i.e. returned as an array). */
|
|
20
|
-
isCollection: boolean;
|
|
21
|
-
/** `true` when minCount >= 1. */
|
|
22
|
-
required: boolean;
|
|
23
|
-
writable: boolean;
|
|
24
|
-
/** AD4M language used to resolve the value (e.g. "literal"). */
|
|
25
|
-
resolveLanguage?: string;
|
|
26
|
-
/**
|
|
27
|
-
* Local name of the related model class when this is a typed relation property.
|
|
28
|
-
* Derived from `SHACLPropertyShape.class` by stripping the URI prefix.
|
|
29
|
-
* E.g. `flux://Message` → `"Message"`.
|
|
30
|
-
*/
|
|
31
|
-
relatedModel?: string;
|
|
32
|
-
}
|
|
33
|
-
/** Normalised description of a single model class stored in a perspective. */
|
|
34
|
-
export interface ModelManifestEntry {
|
|
35
|
-
/** Class name — usable directly as the `model` field in a `$query` token. */
|
|
36
|
-
name: string;
|
|
37
|
-
/** The SHACL `targetClass` URI (e.g. "flux://Channel"). */
|
|
38
|
-
targetClass: string;
|
|
39
|
-
/** All data properties (flag/hasValue properties are excluded). */
|
|
40
|
-
properties: ModelManifestProperty[];
|
|
41
|
-
}
|
|
@@ -1,11 +0,0 @@
|
|
|
1
|
-
/**
|
|
2
|
-
* Types for the perspective model manifest — a human-readable, AI-friendly summary
|
|
3
|
-
* of all Ad4mModel-compatible classes defined in a perspective's SHACL shapes.
|
|
4
|
-
*
|
|
5
|
-
* Used by `PerspectiveProxy.getModelManifest()` and consumed by WE's AI context
|
|
6
|
-
* injection (`formatManifestForPrompt`) to describe external perspective models
|
|
7
|
-
* to the schema-generation AI.
|
|
8
|
-
*
|
|
9
|
-
* @module
|
|
10
|
-
*/
|
|
11
|
-
export {};
|