@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
|
@@ -0,0 +1,165 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Subscription Pool — deduplicates identical SPARQL subscriptions.
|
|
3
|
+
*
|
|
4
|
+
* When multiple UI components subscribe to the same SPARQL query on the same
|
|
5
|
+
* perspective, the pool shares a single `subscribeQuery()` call and distributes
|
|
6
|
+
* results to all registered callbacks. Hydration happens once per result set,
|
|
7
|
+
* then is shared across all subscribers.
|
|
8
|
+
*
|
|
9
|
+
* Key: `perspectiveUUID + sparqlQuery`
|
|
10
|
+
*/
|
|
11
|
+
const pool = new Map();
|
|
12
|
+
function makeKey(perspectiveUUID, sparqlQuery) {
|
|
13
|
+
return `${perspectiveUUID}::${sparqlQuery}`;
|
|
14
|
+
}
|
|
15
|
+
/**
|
|
16
|
+
* Subscribe to a SPARQL query, sharing the underlying subscription
|
|
17
|
+
* with any other subscribers using the same perspective + query.
|
|
18
|
+
*
|
|
19
|
+
* @param perspective - The perspective proxy
|
|
20
|
+
* @param sparqlQuery - The SPARQL query text
|
|
21
|
+
* @param hydrate - Async function that takes raw SPARQL results and returns hydrated results
|
|
22
|
+
* @param onResult - Callback for subsequent result updates (hydrated)
|
|
23
|
+
* @returns PooledSubscription with initial result and dispose function
|
|
24
|
+
*/
|
|
25
|
+
export async function pooledSubscribe(perspective, sparqlQuery, hydrate, onResult) {
|
|
26
|
+
const uuid = perspective.uuid || perspective.handle?.uuid || '';
|
|
27
|
+
const key = makeKey(uuid, sparqlQuery);
|
|
28
|
+
const entry = pool.get(key);
|
|
29
|
+
const subscriber = { onResult, hydrate };
|
|
30
|
+
if (entry) {
|
|
31
|
+
// Join existing subscription
|
|
32
|
+
entry.callbacks.add(subscriber);
|
|
33
|
+
entry.refCount++;
|
|
34
|
+
// Hydrate latest result for this new subscriber
|
|
35
|
+
let initialResult;
|
|
36
|
+
if (entry.latestHydrated !== undefined) {
|
|
37
|
+
initialResult = entry.latestHydrated;
|
|
38
|
+
}
|
|
39
|
+
else if (entry.latestRaw !== undefined) {
|
|
40
|
+
initialResult = await hydrate(entry.latestRaw);
|
|
41
|
+
}
|
|
42
|
+
return {
|
|
43
|
+
initialResult,
|
|
44
|
+
dispose: () => disposeSubscriber(key, subscriber),
|
|
45
|
+
};
|
|
46
|
+
}
|
|
47
|
+
// Create new subscription
|
|
48
|
+
const subscription = await perspective.subscribeQuery(sparqlQuery);
|
|
49
|
+
const newEntry = {
|
|
50
|
+
subscription,
|
|
51
|
+
callbacks: new Set([subscriber]),
|
|
52
|
+
latestRaw: subscription.result,
|
|
53
|
+
latestHydrated: undefined,
|
|
54
|
+
hydrating: false,
|
|
55
|
+
refCount: 1,
|
|
56
|
+
};
|
|
57
|
+
pool.set(key, newEntry);
|
|
58
|
+
// Set up shared result handler with delta optimization
|
|
59
|
+
subscription.onResult(async (rawResult) => {
|
|
60
|
+
const prevRaw = newEntry.latestRaw;
|
|
61
|
+
newEntry.latestRaw = rawResult;
|
|
62
|
+
newEntry.hydrating = true;
|
|
63
|
+
try {
|
|
64
|
+
const firstSub = newEntry.callbacks.values().next().value;
|
|
65
|
+
if (firstSub) {
|
|
66
|
+
// Delta optimization: if the new result is strictly an addition
|
|
67
|
+
// (all previous rows still present + new rows), only hydrate the
|
|
68
|
+
// new rows and append them to the cached hydrated result.
|
|
69
|
+
const prevArr = Array.isArray(prevRaw) ? prevRaw : [];
|
|
70
|
+
const newArr = Array.isArray(rawResult) ? rawResult : [];
|
|
71
|
+
const prevHydrated = newEntry.latestHydrated;
|
|
72
|
+
if (prevHydrated &&
|
|
73
|
+
Array.isArray(prevHydrated) &&
|
|
74
|
+
newArr.length > prevArr.length &&
|
|
75
|
+
newArr.length - prevArr.length <= 5 // small delta — worth optimizing
|
|
76
|
+
) {
|
|
77
|
+
// Build a set of source URIs from previous results for quick lookup
|
|
78
|
+
const prevSources = new Set(prevArr.map((r) => `${r.source}|${r.predicate}|${r.target}`));
|
|
79
|
+
const addedRows = newArr.filter((r) => !prevSources.has(`${r.source}|${r.predicate}|${r.target}`));
|
|
80
|
+
// Check that no rows were removed (pure addition)
|
|
81
|
+
const newSources = new Set(newArr.map((r) => `${r.source}|${r.predicate}|${r.target}`));
|
|
82
|
+
const removedRows = prevArr.filter((r) => !newSources.has(`${r.source}|${r.predicate}|${r.target}`));
|
|
83
|
+
if (removedRows.length === 0 && addedRows.length > 0) {
|
|
84
|
+
// Verify ALL added rows have sources not in previous results.
|
|
85
|
+
// If any added row's source matches an existing source, it means
|
|
86
|
+
// an existing instance got new links — we need full rehydration.
|
|
87
|
+
const prevSourceIds = new Set(prevArr.map((r) => r.source));
|
|
88
|
+
const allNewSources = addedRows.every((r) => !prevSourceIds.has(r.source));
|
|
89
|
+
if (allNewSources) {
|
|
90
|
+
// Pure addition of new instances — hydrate only the new rows
|
|
91
|
+
try {
|
|
92
|
+
const deltaHydrated = await firstSub.hydrate(addedRows);
|
|
93
|
+
if (Array.isArray(deltaHydrated)) {
|
|
94
|
+
const merged = [...prevHydrated, ...deltaHydrated];
|
|
95
|
+
newEntry.latestHydrated = merged;
|
|
96
|
+
for (const cb of newEntry.callbacks) {
|
|
97
|
+
try {
|
|
98
|
+
cb.onResult(merged);
|
|
99
|
+
}
|
|
100
|
+
catch (e) { /* subscriber error */ }
|
|
101
|
+
}
|
|
102
|
+
return; // Delta path succeeded
|
|
103
|
+
}
|
|
104
|
+
}
|
|
105
|
+
catch {
|
|
106
|
+
// Delta hydration failed — fall through to full hydration
|
|
107
|
+
}
|
|
108
|
+
}
|
|
109
|
+
}
|
|
110
|
+
}
|
|
111
|
+
// Full hydration fallback
|
|
112
|
+
const hydrated = await firstSub.hydrate(rawResult);
|
|
113
|
+
newEntry.latestHydrated = hydrated;
|
|
114
|
+
// Distribute to all callbacks
|
|
115
|
+
for (const cb of newEntry.callbacks) {
|
|
116
|
+
try {
|
|
117
|
+
cb.onResult(hydrated);
|
|
118
|
+
}
|
|
119
|
+
catch (e) { /* subscriber error */ }
|
|
120
|
+
}
|
|
121
|
+
}
|
|
122
|
+
}
|
|
123
|
+
finally {
|
|
124
|
+
newEntry.hydrating = false;
|
|
125
|
+
}
|
|
126
|
+
});
|
|
127
|
+
// Hydrate initial result
|
|
128
|
+
const initialResult = await hydrate(subscription.result);
|
|
129
|
+
newEntry.latestHydrated = initialResult;
|
|
130
|
+
return {
|
|
131
|
+
initialResult,
|
|
132
|
+
dispose: () => disposeSubscriber(key, subscriber),
|
|
133
|
+
};
|
|
134
|
+
}
|
|
135
|
+
function disposeSubscriber(key, subscriber) {
|
|
136
|
+
const entry = pool.get(key);
|
|
137
|
+
if (!entry)
|
|
138
|
+
return;
|
|
139
|
+
entry.callbacks.delete(subscriber);
|
|
140
|
+
entry.refCount--;
|
|
141
|
+
if (entry.refCount <= 0) {
|
|
142
|
+
// Last subscriber — tear down the underlying subscription
|
|
143
|
+
if (entry.subscription?.dispose) {
|
|
144
|
+
entry.subscription.dispose();
|
|
145
|
+
}
|
|
146
|
+
pool.delete(key);
|
|
147
|
+
}
|
|
148
|
+
}
|
|
149
|
+
/**
|
|
150
|
+
* Clear the entire pool (for testing).
|
|
151
|
+
*/
|
|
152
|
+
export function clearSubscriptionPool() {
|
|
153
|
+
for (const entry of pool.values()) {
|
|
154
|
+
if (entry.subscription?.dispose) {
|
|
155
|
+
entry.subscription.dispose();
|
|
156
|
+
}
|
|
157
|
+
}
|
|
158
|
+
pool.clear();
|
|
159
|
+
}
|
|
160
|
+
/**
|
|
161
|
+
* Get the current pool size (for testing).
|
|
162
|
+
*/
|
|
163
|
+
export function subscriptionPoolSize() {
|
|
164
|
+
return pool.size;
|
|
165
|
+
}
|
package/lib/src/model/types.d.ts
CHANGED
|
@@ -6,6 +6,7 @@
|
|
|
6
6
|
* creating circular runtime dependencies on `Ad4mModel.ts`.
|
|
7
7
|
*/
|
|
8
8
|
import type { Ad4mModel } from "./Ad4mModel";
|
|
9
|
+
import type { NodeExpression } from "../shacl/NodeExpression";
|
|
9
10
|
export type WhereOps = {
|
|
10
11
|
not: string | number | boolean | string[] | number[];
|
|
11
12
|
between: [number, number];
|
|
@@ -89,11 +90,12 @@ export interface IncludeProjection {
|
|
|
89
90
|
/** When true, attaches an integer count instead of a list. */
|
|
90
91
|
count?: true;
|
|
91
92
|
/**
|
|
92
|
-
*
|
|
93
|
-
*
|
|
93
|
+
* Bare class name of the projection target. Set automatically by
|
|
94
|
+
* `prepareModelQueryParams`; the executor resolves the target's shape
|
|
95
|
+
* through its in-memory cache when applying projection where filters.
|
|
94
96
|
* @internal
|
|
95
97
|
*/
|
|
96
|
-
|
|
98
|
+
targetClassName?: string;
|
|
97
99
|
/** Post-hydration where clause applied to the target instances. */
|
|
98
100
|
where?: Where;
|
|
99
101
|
/** Limit results (when 1, the attached value is unwrapped to a scalar). */
|
|
@@ -142,6 +144,139 @@ export type Query = {
|
|
|
142
144
|
* ```
|
|
143
145
|
*/
|
|
144
146
|
export type RelationSubQuery = Omit<Query, 'parent' | 'count'>;
|
|
147
|
+
/** Keys of T that are user-declared (not methods, not inherited from Ad4mModel). */
|
|
148
|
+
export type ModelDataKeys<T extends Ad4mModel> = {
|
|
149
|
+
[K in keyof T]: K extends keyof Ad4mModel ? never : T[K] extends (...args: any[]) => any ? never : K;
|
|
150
|
+
}[keyof T];
|
|
151
|
+
/** Keys of T that can appear in a `where` clause — scalars and scalar arrays.
|
|
152
|
+
* Excludes typed Ad4mModel references (single or array); `string[]`/`number[]`
|
|
153
|
+
* remain included because they're often filterable even when also used as
|
|
154
|
+
* link targets.
|
|
155
|
+
*
|
|
156
|
+
* Iterates over `keyof T` directly (not `ModelDataKeys<T>`) to preserve the
|
|
157
|
+
* key constraint — mapped types over computed type aliases sometimes widen
|
|
158
|
+
* to `string | undefined` in the key position, which then breaks indexing. */
|
|
159
|
+
export type PropertyKeysOf<T extends Ad4mModel> = {
|
|
160
|
+
[K in keyof T]: K extends ModelDataKeys<T> ? NonNullable<T[K]> extends Ad4mModel ? never : NonNullable<T[K]> extends Ad4mModel[] ? never : K : never;
|
|
161
|
+
}[keyof T];
|
|
162
|
+
/** Keys of T that can appear in `include` — typed Ad4mModel references AND
|
|
163
|
+
* `string[]` link-target arrays (the `@HasMany` + `string[]` pattern that
|
|
164
|
+
* AD4M uses for relations without a target class thunk). Handles both
|
|
165
|
+
* `?: Foo` (optional → `Foo | undefined`) and `Foo | null` field shapes, and
|
|
166
|
+
* optional/nullable array variants (`?: Foo[]`, `Foo[] | null`). */
|
|
167
|
+
export type RelationKeysOf<T extends Ad4mModel> = {
|
|
168
|
+
[K in keyof T]: K extends ModelDataKeys<T> ? NonNullable<T[K]> extends Ad4mModel ? K : NonNullable<T[K]> extends Ad4mModel[] ? K : NonNullable<T[K]> extends string[] ? K : never : never;
|
|
169
|
+
}[keyof T];
|
|
170
|
+
/** The model type referenced by a relation field K on T.
|
|
171
|
+
* Falls back to `Ad4mModel` (loose) for the `string[]` relation pattern,
|
|
172
|
+
* since no target class is available at the type level. */
|
|
173
|
+
export type RelatedModel<T extends Ad4mModel, K extends RelationKeysOf<T>> = NonNullable<T[K]> extends (infer U)[] ? (U extends Ad4mModel ? U : Ad4mModel) : NonNullable<T[K]> extends Ad4mModel ? NonNullable<T[K]> : Ad4mModel;
|
|
174
|
+
/** True when T has no statically-declared data fields (e.g. fromSHACL classes). */
|
|
175
|
+
type HasNoTypedFields<T extends Ad4mModel> = [
|
|
176
|
+
PropertyKeysOf<T> | RelationKeysOf<T>
|
|
177
|
+
] extends [never] ? true : false;
|
|
178
|
+
export type StringWhereOps = {
|
|
179
|
+
not?: string | string[];
|
|
180
|
+
contains?: string;
|
|
181
|
+
};
|
|
182
|
+
export type NumericWhereOps = {
|
|
183
|
+
not?: number | number[];
|
|
184
|
+
lt?: number;
|
|
185
|
+
lte?: number;
|
|
186
|
+
gt?: number;
|
|
187
|
+
gte?: number;
|
|
188
|
+
between?: [number, number];
|
|
189
|
+
};
|
|
190
|
+
export type TypedWhereCondition<V> = V extends string ? string | string[] | StringWhereOps : V extends number ? number | number[] | NumericWhereOps : V extends boolean ? boolean : V extends Array<infer U> ? U extends string ? string | string[] | StringWhereOps : U extends number ? number | number[] | NumericWhereOps : WhereCondition : WhereCondition;
|
|
191
|
+
/** Strict Where: keys constrained to T's properties, plus the well-known
|
|
192
|
+
* link-metadata fields (`id`/`author`/`timestamp`). */
|
|
193
|
+
type StrictTypedWhere<T extends Ad4mModel> = {
|
|
194
|
+
[K in PropertyKeysOf<T>]?: TypedWhereCondition<T[K]>;
|
|
195
|
+
} & {
|
|
196
|
+
base?: string | string[];
|
|
197
|
+
id?: string | string[];
|
|
198
|
+
author?: WhereCondition;
|
|
199
|
+
timestamp?: WhereCondition;
|
|
200
|
+
};
|
|
201
|
+
/** Public typed `where` for a model class. Falls back to the loose `Where`
|
|
202
|
+
* shape when T has no declared fields (e.g. fromSHACL-derived classes). */
|
|
203
|
+
export type TypedWhere<T extends Ad4mModel> = HasNoTypedFields<T> extends true ? Where : StrictTypedWhere<T>;
|
|
204
|
+
type StrictTypedOrder<T extends Ad4mModel> = {
|
|
205
|
+
[K in PropertyKeysOf<T> | 'timestamp' | 'author' | 'createdAt' | 'updatedAt']?: 'ASC' | 'DESC';
|
|
206
|
+
};
|
|
207
|
+
export type TypedOrder<T extends Ad4mModel> = HasNoTypedFields<T> extends true ? Order : StrictTypedOrder<T>;
|
|
208
|
+
/** Sub-query for an eager-loaded relation — inherits the target model's constraints. */
|
|
209
|
+
export type TypedRelationSubQuery<U extends Ad4mModel> = {
|
|
210
|
+
where?: TypedWhere<U>;
|
|
211
|
+
order?: TypedOrder<U>;
|
|
212
|
+
include?: TypedIncludeMap<U>;
|
|
213
|
+
limit?: number;
|
|
214
|
+
offset?: number;
|
|
215
|
+
};
|
|
216
|
+
/** Projection — `from` must be a real relation on T; `where`/`order` constrained to that target.
|
|
217
|
+
* Modelled as a discriminated union so the literal `count: true` and `limit: 1`
|
|
218
|
+
* variants narrow inference into `IncludeExtras` (count → number, limit-1 → scalar). */
|
|
219
|
+
export type TypedIncludeProjection<T extends Ad4mModel> = {
|
|
220
|
+
[K in RelationKeysOf<T>]: {
|
|
221
|
+
from: K;
|
|
222
|
+
count: true;
|
|
223
|
+
} | {
|
|
224
|
+
from: K;
|
|
225
|
+
limit: 1;
|
|
226
|
+
where?: TypedWhere<RelatedModel<T, K>>;
|
|
227
|
+
order?: TypedOrder<RelatedModel<T, K>>;
|
|
228
|
+
} | {
|
|
229
|
+
from: K;
|
|
230
|
+
limit?: number;
|
|
231
|
+
where?: TypedWhere<RelatedModel<T, K>>;
|
|
232
|
+
order?: TypedOrder<RelatedModel<T, K>>;
|
|
233
|
+
};
|
|
234
|
+
}[RelationKeysOf<T>];
|
|
235
|
+
type StrictTypedIncludeMap<T extends Ad4mModel> = {
|
|
236
|
+
[K in RelationKeysOf<T>]?: boolean | TypedRelationSubQuery<RelatedModel<T, K>>;
|
|
237
|
+
} & {
|
|
238
|
+
[K in `$${string}`]?: TypedIncludeProjection<T>;
|
|
239
|
+
};
|
|
240
|
+
export type TypedIncludeMap<T extends Ad4mModel> = HasNoTypedFields<T> extends true ? IncludeMap : StrictTypedIncludeMap<T>;
|
|
241
|
+
/**
|
|
242
|
+
* Given a model T and an `include` literal I, compute the extra fields
|
|
243
|
+
* contributed by `$`-prefixed projection keys.
|
|
244
|
+
*
|
|
245
|
+
* - `{ count: true }` → `number`
|
|
246
|
+
* - `{ from: R, limit: 1 }` → `RelatedModel<T,R> | null`
|
|
247
|
+
* - `{ from: R }` (no limit/1) → `RelatedModel<T,R>[]`
|
|
248
|
+
*
|
|
249
|
+
* Returns `unknown` (intersection-neutral) when `I` has no `$`-keys, so that
|
|
250
|
+
* `T & IncludeExtras<T, I>` collapses back to `T` and downstream type
|
|
251
|
+
* predicates (`(x): x is T => ...`) keep working unchanged.
|
|
252
|
+
*/
|
|
253
|
+
export type IncludeExtras<T extends Ad4mModel, I> = I extends Record<string, any> ? Extract<keyof I, `$${string}`> extends never ? unknown : {
|
|
254
|
+
[K in Extract<keyof I, `$${string}`>]: I[K] extends {
|
|
255
|
+
count: true;
|
|
256
|
+
} ? number : I[K] extends {
|
|
257
|
+
from: infer R;
|
|
258
|
+
limit: 1;
|
|
259
|
+
} ? (R extends RelationKeysOf<T> ? RelatedModel<T, R> | null : never) : I[K] extends {
|
|
260
|
+
from: infer R;
|
|
261
|
+
} ? (R extends RelationKeysOf<T> ? RelatedModel<T, R>[] : never) : unknown;
|
|
262
|
+
} : unknown;
|
|
263
|
+
type StrictTypedQuery<T extends Ad4mModel> = {
|
|
264
|
+
parent?: ParentScope;
|
|
265
|
+
properties?: PropertyKeysOf<T>[];
|
|
266
|
+
include?: TypedIncludeMap<T>;
|
|
267
|
+
includeAll?: boolean;
|
|
268
|
+
where?: TypedWhere<T>;
|
|
269
|
+
order?: TypedOrder<T>;
|
|
270
|
+
offset?: number;
|
|
271
|
+
limit?: number;
|
|
272
|
+
count?: boolean;
|
|
273
|
+
deepQuery?: boolean;
|
|
274
|
+
};
|
|
275
|
+
export type TypedQuery<T extends Ad4mModel> = HasNoTypedFields<T> extends true ? Query : StrictTypedQuery<T>;
|
|
276
|
+
/** Helper that extracts the `include` literal from a TypedQuery for use with IncludeExtras. */
|
|
277
|
+
export type IncludeOf<Q> = Q extends {
|
|
278
|
+
include?: infer I;
|
|
279
|
+
} ? I : undefined;
|
|
145
280
|
/**
|
|
146
281
|
* Options accepted by the instance `get()` method.
|
|
147
282
|
*
|
|
@@ -188,7 +323,7 @@ export interface PropertyMetadata {
|
|
|
188
323
|
/** Whether stored locally only */
|
|
189
324
|
local?: boolean;
|
|
190
325
|
/** Transform function */
|
|
191
|
-
transform?:
|
|
326
|
+
transform?: NodeExpression;
|
|
192
327
|
/** Whether this is a flag property */
|
|
193
328
|
flag?: boolean;
|
|
194
329
|
}
|
|
@@ -227,3 +362,4 @@ export interface ModelMetadata {
|
|
|
227
362
|
/** Map of relation name to metadata */
|
|
228
363
|
relations: Record<string, RelationMetadata>;
|
|
229
364
|
}
|
|
365
|
+
export {};
|
|
@@ -1,18 +1,21 @@
|
|
|
1
1
|
import { NeighbourhoodClient } from "./NeighbourhoodClient";
|
|
2
2
|
import { NeighbourhoodProxy } from "./NeighbourhoodProxy";
|
|
3
|
+
// Mock RestClient's subscribe to avoid real WebSocket connections
|
|
4
|
+
jest.mock('../restClient', () => {
|
|
5
|
+
return {
|
|
6
|
+
RestClient: jest.fn().mockImplementation(() => ({
|
|
7
|
+
get: jest.fn(),
|
|
8
|
+
post: jest.fn(),
|
|
9
|
+
put: jest.fn(),
|
|
10
|
+
delete: jest.fn(),
|
|
11
|
+
subscribe: jest.fn().mockReturnValue(() => { }),
|
|
12
|
+
}))
|
|
13
|
+
};
|
|
14
|
+
});
|
|
3
15
|
describe("NeighbourhoodProxy", () => {
|
|
4
16
|
it("should add multiple signal handlers", async () => {
|
|
5
17
|
const neighbourhoodURI = "did://123";
|
|
6
|
-
const
|
|
7
|
-
subscribe: () => ({
|
|
8
|
-
subscribe: () => new Promise((resolve) => {
|
|
9
|
-
setTimeout(() => {
|
|
10
|
-
resolve({});
|
|
11
|
-
}, 10);
|
|
12
|
-
}),
|
|
13
|
-
}),
|
|
14
|
-
};
|
|
15
|
-
const neighbourhoodClient = new NeighbourhoodClient(mockApolloClient);
|
|
18
|
+
const neighbourhoodClient = new NeighbourhoodClient("http://localhost:0", "test-token");
|
|
16
19
|
const neighbourhoodProxy = new NeighbourhoodProxy(neighbourhoodClient, neighbourhoodURI);
|
|
17
20
|
let callbacks = 0;
|
|
18
21
|
const handler1 = () => {
|
|
@@ -21,7 +24,7 @@ describe("NeighbourhoodProxy", () => {
|
|
|
21
24
|
const handler2 = () => {
|
|
22
25
|
callbacks++;
|
|
23
26
|
};
|
|
24
|
-
// Add multiple signal handlers in
|
|
27
|
+
// Add multiple signal handlers in parallel
|
|
25
28
|
const promise = neighbourhoodProxy.addSignalHandler(handler1);
|
|
26
29
|
neighbourhoodProxy.addSignalHandler(handler2);
|
|
27
30
|
await promise;
|
|
@@ -30,21 +33,20 @@ describe("NeighbourhoodProxy", () => {
|
|
|
30
33
|
});
|
|
31
34
|
it("should not add multiple subscriptions when removing and adding another signal handler", async () => {
|
|
32
35
|
const neighbourhoodURI = "did://123";
|
|
33
|
-
|
|
34
|
-
|
|
35
|
-
|
|
36
|
-
|
|
37
|
-
|
|
38
|
-
|
|
39
|
-
|
|
40
|
-
|
|
41
|
-
|
|
42
|
-
|
|
43
|
-
|
|
44
|
-
subscribe,
|
|
36
|
+
// Track subscribe calls via the mock
|
|
37
|
+
let subscribeCallCount = 0;
|
|
38
|
+
const { RestClient } = jest.requireMock('../restClient');
|
|
39
|
+
RestClient.mockImplementation(() => ({
|
|
40
|
+
get: jest.fn(),
|
|
41
|
+
post: jest.fn(),
|
|
42
|
+
put: jest.fn(),
|
|
43
|
+
delete: jest.fn(),
|
|
44
|
+
subscribe: jest.fn().mockImplementation(() => {
|
|
45
|
+
subscribeCallCount++;
|
|
46
|
+
return () => { };
|
|
45
47
|
}),
|
|
46
|
-
};
|
|
47
|
-
const neighbourhoodClient = new NeighbourhoodClient(
|
|
48
|
+
}));
|
|
49
|
+
const neighbourhoodClient = new NeighbourhoodClient("http://localhost:0", "test-token");
|
|
48
50
|
const neighbourhoodProxy = new NeighbourhoodProxy(neighbourhoodClient, neighbourhoodURI);
|
|
49
51
|
let callbacks1 = 0;
|
|
50
52
|
let callbacks2 = 0;
|
|
@@ -56,17 +58,15 @@ describe("NeighbourhoodProxy", () => {
|
|
|
56
58
|
};
|
|
57
59
|
// Add signal handler 1
|
|
58
60
|
await neighbourhoodProxy.addSignalHandler(handler1);
|
|
59
|
-
// Remove signal handler
|
|
61
|
+
// Remove signal handler 1
|
|
60
62
|
neighbourhoodProxy.removeSignalHandler(handler1);
|
|
61
63
|
// Add signal handler 2
|
|
62
64
|
await neighbourhoodProxy.addSignalHandler(handler2);
|
|
63
|
-
// Check that only one subscription was added
|
|
64
|
-
expect(
|
|
65
|
-
//
|
|
66
|
-
|
|
67
|
-
|
|
68
|
-
}
|
|
69
|
-
// Check that only our second callback was called
|
|
65
|
+
// Check that only one subscription was added (handlers share subscription per perspective)
|
|
66
|
+
expect(subscribeCallCount).toBe(1);
|
|
67
|
+
// Dispatch signal
|
|
68
|
+
neighbourhoodClient.dispatchSignal(neighbourhoodURI, true);
|
|
69
|
+
// Check that only handler2 was called (handler1 was removed)
|
|
70
70
|
expect(callbacks1).toBe(0);
|
|
71
71
|
expect(callbacks2).toBe(1);
|
|
72
72
|
});
|
|
@@ -27,7 +27,7 @@ export declare class PerspectiveClient {
|
|
|
27
27
|
publishSnapshotByUUID(uuid: string): Promise<string | null>;
|
|
28
28
|
queryLinks(uuid: string, query: LinkQuery): Promise<LinkExpression[]>;
|
|
29
29
|
queryProlog(uuid: string, query: string): Promise<unknown>;
|
|
30
|
-
querySparql(uuid: string, query: string): Promise<
|
|
30
|
+
querySparql<T = any>(uuid: string, query: string): Promise<T>;
|
|
31
31
|
subscribeQuery(uuid: string, query: string): Promise<{
|
|
32
32
|
subscriptionId: string;
|
|
33
33
|
result: AllInstancesResult;
|
|
@@ -37,9 +37,9 @@ export declare class PerspectiveClient {
|
|
|
37
37
|
subscribeToQueryUpdates(subscriptionId: string, onData: (result: AllInstancesResult) => void): () => void;
|
|
38
38
|
keepAliveQuery(uuid: string, subscriptionId: string): Promise<boolean>;
|
|
39
39
|
disposeQuerySubscription(uuid: string, subscriptionId: string): Promise<boolean>;
|
|
40
|
-
modelQuery(uuid: string, className: string, queryJson: string
|
|
41
|
-
evaluateGetters(uuid: string, className: string, instanceIds: string[],
|
|
42
|
-
modelSubscribe(uuid: string, className: string, queryJson: string
|
|
40
|
+
modelQuery(uuid: string, className: string, queryJson: string): Promise<any>;
|
|
41
|
+
evaluateGetters(uuid: string, className: string, instanceIds: string[], propertyNames?: string[]): Promise<Record<string, Record<string, any>>>;
|
|
42
|
+
modelSubscribe(uuid: string, className: string, queryJson: string): Promise<{
|
|
43
43
|
subscriptionId: string;
|
|
44
44
|
result: any;
|
|
45
45
|
}>;
|
|
@@ -56,6 +56,12 @@ export declare class PerspectiveClient {
|
|
|
56
56
|
updateLink(uuid: string, oldLink: LinkExpressionInput, newLink: Link, batchId?: string): Promise<LinkExpression>;
|
|
57
57
|
removeLink(uuid: string, link: LinkExpressionInput, batchId?: string): Promise<boolean>;
|
|
58
58
|
addSdna(uuid: string, name: string, sdnaCode: string | undefined, sdnaType: "subject_class" | "flow" | "custom", shaclJson?: string): Promise<boolean>;
|
|
59
|
+
addSdnaBatch(uuid: string, entries: {
|
|
60
|
+
name: string;
|
|
61
|
+
sdnaCode?: string;
|
|
62
|
+
sdnaType: "subject_class" | "flow" | "custom";
|
|
63
|
+
shaclJson?: string;
|
|
64
|
+
}[]): Promise<boolean[]>;
|
|
59
65
|
executeCommands(uuid: string, commands: string, expression: string, parameters: string, batchId?: string): Promise<boolean>;
|
|
60
66
|
createSubject(uuid: string, subjectClass: string, expressionAddress: string, initialValues?: string, batchId?: string): Promise<boolean>;
|
|
61
67
|
getSubjectData(uuid: string, subjectClass: string, expressionAddress: string): Promise<string>;
|
|
@@ -72,6 +78,9 @@ export declare class PerspectiveClient {
|
|
|
72
78
|
addPerspectiveLinkAddedListener(uuid: String, cb: LinkCallback[]): Promise<void>;
|
|
73
79
|
addPerspectiveLinkRemovedListener(uuid: String, cb: LinkCallback[]): Promise<void>;
|
|
74
80
|
addPerspectiveLinkUpdatedListener(uuid: String, cb: LinkCallback[]): Promise<void>;
|
|
81
|
+
/** Unsubscribe all link/sync-state listeners registered for the given perspective UUID.
|
|
82
|
+
* Called by PerspectiveProxy.dispose() to prevent subscription leaks. */
|
|
83
|
+
removeAllListeners(uuid: string): void;
|
|
75
84
|
getNeighbourhoodProxy(uuid: string): NeighbourhoodProxy;
|
|
76
85
|
createBatch(uuid: string): Promise<string>;
|
|
77
86
|
commitBatch(uuid: string, batchId: string): Promise<LinkExpressionMutations>;
|
|
@@ -148,22 +148,21 @@ export class PerspectiveClient {
|
|
|
148
148
|
}
|
|
149
149
|
return __classPrivateFieldGet(this, _PerspectiveClient_apiClient, "f").call('perspective.disposeQuery', { uuid, subscriptionId });
|
|
150
150
|
}
|
|
151
|
-
async modelQuery(uuid, className, queryJson
|
|
152
|
-
const resultJson = await __classPrivateFieldGet(this, _PerspectiveClient_apiClient, "f").call('perspective.modelQuery', { uuid, class_name: className, query_json: queryJson
|
|
151
|
+
async modelQuery(uuid, className, queryJson) {
|
|
152
|
+
const resultJson = await __classPrivateFieldGet(this, _PerspectiveClient_apiClient, "f").call('perspective.modelQuery', { uuid, class_name: className, query_json: queryJson });
|
|
153
153
|
return JSON.parse(resultJson);
|
|
154
154
|
}
|
|
155
|
-
async evaluateGetters(uuid, className, instanceIds,
|
|
155
|
+
async evaluateGetters(uuid, className, instanceIds, propertyNames) {
|
|
156
156
|
const resultJson = await __classPrivateFieldGet(this, _PerspectiveClient_apiClient, "f").call('perspective.evaluateGetters', {
|
|
157
157
|
uuid,
|
|
158
158
|
class_name: className,
|
|
159
159
|
instance_ids: instanceIds,
|
|
160
|
-
shape_json: shapeJson,
|
|
161
160
|
...(propertyNames && { property_names: propertyNames }),
|
|
162
161
|
});
|
|
163
162
|
return JSON.parse(resultJson);
|
|
164
163
|
}
|
|
165
|
-
async modelSubscribe(uuid, className, queryJson
|
|
166
|
-
const response = await __classPrivateFieldGet(this, _PerspectiveClient_apiClient, "f").call('perspective.modelSubscribe', { uuid, class_name: className, query_json: queryJson
|
|
164
|
+
async modelSubscribe(uuid, className, queryJson) {
|
|
165
|
+
const response = await __classPrivateFieldGet(this, _PerspectiveClient_apiClient, "f").call('perspective.modelSubscribe', { uuid, class_name: className, query_json: queryJson });
|
|
167
166
|
return {
|
|
168
167
|
subscriptionId: response.subscription_id,
|
|
169
168
|
result: JSON.parse(response.result)
|
|
@@ -209,6 +208,9 @@ export class PerspectiveClient {
|
|
|
209
208
|
async addSdna(uuid, name, sdnaCode, sdnaType, shaclJson) {
|
|
210
209
|
return __classPrivateFieldGet(this, _PerspectiveClient_apiClient, "f").call('perspective.addSdna', { uuid, name, sdnaCode: sdnaCode || "", sdnaType, shaclJson });
|
|
211
210
|
}
|
|
211
|
+
async addSdnaBatch(uuid, entries) {
|
|
212
|
+
return __classPrivateFieldGet(this, _PerspectiveClient_apiClient, "f").call('perspective.addSdna', { uuid, entries: entries.map(e => ({ ...e, sdnaCode: e.sdnaCode || "" })) });
|
|
213
|
+
}
|
|
212
214
|
async executeCommands(uuid, commands, expression, parameters, batchId) {
|
|
213
215
|
return __classPrivateFieldGet(this, _PerspectiveClient_apiClient, "f").call('perspective.executeCommands', { uuid, commands, expression, parameters, batchId });
|
|
214
216
|
}
|
|
@@ -316,6 +318,20 @@ export class PerspectiveClient {
|
|
|
316
318
|
__classPrivateFieldGet(this, _PerspectiveClient_linkUnsubscribers, "f").set(uuid, existing);
|
|
317
319
|
await __classPrivateFieldGet(this, _PerspectiveClient_apiClient, "f").waitForSubscription();
|
|
318
320
|
}
|
|
321
|
+
/** Unsubscribe all link/sync-state listeners registered for the given perspective UUID.
|
|
322
|
+
* Called by PerspectiveProxy.dispose() to prevent subscription leaks. */
|
|
323
|
+
removeAllListeners(uuid) {
|
|
324
|
+
const unsubs = __classPrivateFieldGet(this, _PerspectiveClient_linkUnsubscribers, "f").get(uuid);
|
|
325
|
+
if (unsubs) {
|
|
326
|
+
for (const fn of unsubs) {
|
|
327
|
+
try {
|
|
328
|
+
fn();
|
|
329
|
+
}
|
|
330
|
+
catch { }
|
|
331
|
+
}
|
|
332
|
+
__classPrivateFieldGet(this, _PerspectiveClient_linkUnsubscribers, "f").delete(uuid);
|
|
333
|
+
}
|
|
334
|
+
}
|
|
319
335
|
getNeighbourhoodProxy(uuid) {
|
|
320
336
|
return new NeighbourhoodProxy(__classPrivateFieldGet(this, _PerspectiveClient_neighbourhoodClient, "f"), uuid);
|
|
321
337
|
}
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
export {};
|