@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
|
@@ -0,0 +1,42 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Shared SurrealQL compilation utilities.
|
|
3
|
+
*
|
|
4
|
+
* These functions are used by both the runtime query builder (`Ad4mModel`) and
|
|
5
|
+
* the compile-time SHACL generator (`decorators.ts`).
|
|
6
|
+
*/
|
|
7
|
+
import type { WhereCondition, Where, ModelMetadata } from "./types";
|
|
8
|
+
/**
|
|
9
|
+
* Format a JavaScript value for embedding in a SurrealQL expression.
|
|
10
|
+
*
|
|
11
|
+
* - Strings are single-quoted with backslash / quote / newline escaping
|
|
12
|
+
* - Numbers and booleans are passed through as-is
|
|
13
|
+
* - Arrays are recursed
|
|
14
|
+
*/
|
|
15
|
+
export declare function formatSurrealValue(value: any): string;
|
|
16
|
+
/**
|
|
17
|
+
* Compile a single Where condition for a property into a SurrealQL
|
|
18
|
+
* graph-traversal sub-expression.
|
|
19
|
+
*
|
|
20
|
+
* Operates on the **target node** — generates `count(->link[WHERE ...]) > 0`
|
|
21
|
+
* style checks that can be used inside a `[WHERE ...]` filter on nodes.
|
|
22
|
+
*
|
|
23
|
+
* @param predicate - The predicate URI for the property
|
|
24
|
+
* @param condition - The Where condition value
|
|
25
|
+
* @param opts - Optional settings (e.g. `resolveLanguage`)
|
|
26
|
+
* @returns A single SurrealQL condition string
|
|
27
|
+
*/
|
|
28
|
+
export declare function buildWhereCondition(predicate: string, condition: WhereCondition, opts?: {
|
|
29
|
+
resolveLanguage?: string;
|
|
30
|
+
}): string;
|
|
31
|
+
/**
|
|
32
|
+
* Compile a full `Where` clause to an array of SurrealQL condition strings.
|
|
33
|
+
*
|
|
34
|
+
* When `metadata` is provided, property names are resolved to predicates
|
|
35
|
+
* using the model's property metadata. When `metadata` is `null`, property
|
|
36
|
+
* names are treated as raw predicate URIs.
|
|
37
|
+
*
|
|
38
|
+
* Only handles **regular properties** — special fields (`id`, `author`,
|
|
39
|
+
* `timestamp`) and relation fields are skipped (they are only relevant at
|
|
40
|
+
* runtime query time, not for compile-time getter generation).
|
|
41
|
+
*/
|
|
42
|
+
export declare function compileWhereClause(where: Where, metadata: ModelMetadata | null): string[];
|
|
@@ -0,0 +1,128 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Shared SurrealQL compilation utilities.
|
|
3
|
+
*
|
|
4
|
+
* These functions are used by both the runtime query builder (`Ad4mModel`) and
|
|
5
|
+
* the compile-time SHACL generator (`decorators.ts`).
|
|
6
|
+
*/
|
|
7
|
+
import { escapeSurrealString } from "../utils";
|
|
8
|
+
/**
|
|
9
|
+
* Format a JavaScript value for embedding in a SurrealQL expression.
|
|
10
|
+
*
|
|
11
|
+
* - Strings are single-quoted with backslash / quote / newline escaping
|
|
12
|
+
* - Numbers and booleans are passed through as-is
|
|
13
|
+
* - Arrays are recursed
|
|
14
|
+
*/
|
|
15
|
+
export function formatSurrealValue(value) {
|
|
16
|
+
if (typeof value === 'string') {
|
|
17
|
+
// Escape backslashes first, then single quotes and other special characters
|
|
18
|
+
const escaped = value
|
|
19
|
+
.replace(/\\/g, '\\\\') // Backslash -> \\
|
|
20
|
+
.replace(/'/g, "\\'") // Single quote -> \'
|
|
21
|
+
.replace(/"/g, '\\"') // Double quote -> \"
|
|
22
|
+
.replace(/\n/g, '\\n') // Newline -> \n
|
|
23
|
+
.replace(/\r/g, '\\r') // Carriage return -> \r
|
|
24
|
+
.replace(/\t/g, '\\t'); // Tab -> \t
|
|
25
|
+
return `'${escaped}'`;
|
|
26
|
+
}
|
|
27
|
+
else if (typeof value === 'number' || typeof value === 'boolean') {
|
|
28
|
+
return String(value);
|
|
29
|
+
}
|
|
30
|
+
else if (Array.isArray(value)) {
|
|
31
|
+
return `[${value.map(v => formatSurrealValue(v)).join(', ')}]`;
|
|
32
|
+
}
|
|
33
|
+
else {
|
|
34
|
+
return String(value);
|
|
35
|
+
}
|
|
36
|
+
}
|
|
37
|
+
/**
|
|
38
|
+
* Compile a single Where condition for a property into a SurrealQL
|
|
39
|
+
* graph-traversal sub-expression.
|
|
40
|
+
*
|
|
41
|
+
* Operates on the **target node** — generates `count(->link[WHERE ...]) > 0`
|
|
42
|
+
* style checks that can be used inside a `[WHERE ...]` filter on nodes.
|
|
43
|
+
*
|
|
44
|
+
* @param predicate - The predicate URI for the property
|
|
45
|
+
* @param condition - The Where condition value
|
|
46
|
+
* @param opts - Optional settings (e.g. `resolveLanguage`)
|
|
47
|
+
* @returns A single SurrealQL condition string
|
|
48
|
+
*/
|
|
49
|
+
export function buildWhereCondition(predicate, condition, opts) {
|
|
50
|
+
const escapedPredicate = escapeSurrealString(predicate);
|
|
51
|
+
const targetField = opts?.resolveLanguage === 'literal'
|
|
52
|
+
? 'fn::parse_literal(out.uri)'
|
|
53
|
+
: 'out.uri';
|
|
54
|
+
if (Array.isArray(condition)) {
|
|
55
|
+
// Array values → IN clause
|
|
56
|
+
const formattedValues = condition.map(v => formatSurrealValue(v)).join(', ');
|
|
57
|
+
return `count(->link[WHERE predicate = '${escapedPredicate}' AND ${targetField} IN [${formattedValues}]]) > 0`;
|
|
58
|
+
}
|
|
59
|
+
else if (typeof condition === 'object' && condition !== null) {
|
|
60
|
+
// Operator object
|
|
61
|
+
const ops = condition;
|
|
62
|
+
const parts = [];
|
|
63
|
+
if (ops.not !== undefined) {
|
|
64
|
+
if (Array.isArray(ops.not)) {
|
|
65
|
+
const formattedValues = ops.not.map((v) => formatSurrealValue(v)).join(', ');
|
|
66
|
+
parts.push(`count(->link[WHERE predicate = '${escapedPredicate}' AND ${targetField} IN [${formattedValues}]]) = 0`);
|
|
67
|
+
}
|
|
68
|
+
else {
|
|
69
|
+
parts.push(`count(->link[WHERE predicate = '${escapedPredicate}' AND ${targetField} = ${formatSurrealValue(ops.not)}]) = 0`);
|
|
70
|
+
}
|
|
71
|
+
}
|
|
72
|
+
// Comparison operators — ensure property exists (actual comparison
|
|
73
|
+
// may be post-filtered in JS at runtime, but the SurrealQL condition
|
|
74
|
+
// is valid for compile-time getter generation too).
|
|
75
|
+
const hasComparisonOps = ops.gt !== undefined || ops.gte !== undefined ||
|
|
76
|
+
ops.lt !== undefined || ops.lte !== undefined ||
|
|
77
|
+
ops.between !== undefined || ops.contains !== undefined;
|
|
78
|
+
if (hasComparisonOps) {
|
|
79
|
+
parts.push(`count(->link[WHERE predicate = '${escapedPredicate}']) > 0`);
|
|
80
|
+
}
|
|
81
|
+
return parts.join(' AND ');
|
|
82
|
+
}
|
|
83
|
+
else {
|
|
84
|
+
// Simple equality
|
|
85
|
+
return `count(->link[WHERE predicate = '${escapedPredicate}' AND ${targetField} = ${formatSurrealValue(condition)}]) > 0`;
|
|
86
|
+
}
|
|
87
|
+
}
|
|
88
|
+
/**
|
|
89
|
+
* Compile a full `Where` clause to an array of SurrealQL condition strings.
|
|
90
|
+
*
|
|
91
|
+
* When `metadata` is provided, property names are resolved to predicates
|
|
92
|
+
* using the model's property metadata. When `metadata` is `null`, property
|
|
93
|
+
* names are treated as raw predicate URIs.
|
|
94
|
+
*
|
|
95
|
+
* Only handles **regular properties** — special fields (`id`, `author`,
|
|
96
|
+
* `timestamp`) and relation fields are skipped (they are only relevant at
|
|
97
|
+
* runtime query time, not for compile-time getter generation).
|
|
98
|
+
*/
|
|
99
|
+
export function compileWhereClause(where, metadata) {
|
|
100
|
+
const conditions = [];
|
|
101
|
+
for (const [propertyName, condition] of Object.entries(where)) {
|
|
102
|
+
// Skip special fields that don't apply at compile time
|
|
103
|
+
if (['id', 'author', 'timestamp'].includes(propertyName))
|
|
104
|
+
continue;
|
|
105
|
+
let predicate;
|
|
106
|
+
let resolveLanguage;
|
|
107
|
+
if (metadata) {
|
|
108
|
+
const propMeta = metadata.properties[propertyName];
|
|
109
|
+
if (propMeta) {
|
|
110
|
+
predicate = propMeta.predicate;
|
|
111
|
+
resolveLanguage = propMeta.resolveLanguage;
|
|
112
|
+
}
|
|
113
|
+
else {
|
|
114
|
+
// Property not found in metadata — treat name as raw predicate URI
|
|
115
|
+
predicate = propertyName;
|
|
116
|
+
}
|
|
117
|
+
}
|
|
118
|
+
else {
|
|
119
|
+
// No metadata — treat name as raw predicate URI
|
|
120
|
+
predicate = propertyName;
|
|
121
|
+
}
|
|
122
|
+
const cond = buildWhereCondition(predicate, condition, { resolveLanguage });
|
|
123
|
+
if (cond) {
|
|
124
|
+
conditions.push(cond);
|
|
125
|
+
}
|
|
126
|
+
}
|
|
127
|
+
return conditions;
|
|
128
|
+
}
|
package/lib/src/model/types.d.ts
CHANGED
|
@@ -18,9 +18,15 @@ export type WhereOps = {
|
|
|
18
18
|
};
|
|
19
19
|
export type WhereCondition = string | number | boolean | string[] | number[] | {
|
|
20
20
|
[K in keyof WhereOps]?: WhereOps[K];
|
|
21
|
-
};
|
|
21
|
+
} | Where[] | Where;
|
|
22
22
|
export type Where = {
|
|
23
|
-
|
|
23
|
+
/** Logical OR: instance must satisfy at least one of the given sub-clauses. */
|
|
24
|
+
OR?: Where[];
|
|
25
|
+
/** Logical AND: instance must satisfy all of the given sub-clauses. */
|
|
26
|
+
AND?: Where[];
|
|
27
|
+
/** Logical NOT: instance must NOT satisfy the given sub-clause. */
|
|
28
|
+
NOT?: Where;
|
|
29
|
+
[propertyName: string]: WhereCondition | undefined;
|
|
24
30
|
};
|
|
25
31
|
export type Order = {
|
|
26
32
|
[propertyName: string]: "ASC" | "DESC";
|
|
@@ -189,7 +195,7 @@ export type NumericWhereOps = {
|
|
|
189
195
|
};
|
|
190
196
|
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
197
|
/** Strict Where: keys constrained to T's properties, plus the well-known
|
|
192
|
-
* link-metadata fields (`id`/`author`/`timestamp`). */
|
|
198
|
+
* link-metadata fields (`id`/`author`/`timestamp`) and logical combinators. */
|
|
193
199
|
type StrictTypedWhere<T extends Ad4mModel> = {
|
|
194
200
|
[K in PropertyKeysOf<T>]?: TypedWhereCondition<T[K]>;
|
|
195
201
|
} & {
|
|
@@ -197,12 +203,17 @@ type StrictTypedWhere<T extends Ad4mModel> = {
|
|
|
197
203
|
id?: string | string[];
|
|
198
204
|
author?: WhereCondition;
|
|
199
205
|
timestamp?: WhereCondition;
|
|
206
|
+
OR?: StrictTypedWhere<T>[];
|
|
207
|
+
AND?: StrictTypedWhere<T>[];
|
|
208
|
+
NOT?: StrictTypedWhere<T>;
|
|
200
209
|
};
|
|
201
210
|
/** Public typed `where` for a model class. Falls back to the loose `Where`
|
|
202
211
|
* shape when T has no declared fields (e.g. fromSHACL-derived classes). */
|
|
203
212
|
export type TypedWhere<T extends Ad4mModel> = HasNoTypedFields<T> extends true ? Where : StrictTypedWhere<T>;
|
|
204
213
|
type StrictTypedOrder<T extends Ad4mModel> = {
|
|
205
214
|
[K in PropertyKeysOf<T> | 'timestamp' | 'author' | 'createdAt' | 'updatedAt']?: 'ASC' | 'DESC';
|
|
215
|
+
} & {
|
|
216
|
+
[K in `$${string}`]?: 'ASC' | 'DESC';
|
|
206
217
|
};
|
|
207
218
|
export type TypedOrder<T extends Ad4mModel> = HasNoTypedFields<T> extends true ? Order : StrictTypedOrder<T>;
|
|
208
219
|
/** Sub-query for an eager-loaded relation — inherits the target model's constraints. */
|
|
@@ -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
|
});
|
|
@@ -645,6 +645,23 @@ export declare class PerspectiveProxy {
|
|
|
645
645
|
* Retrieve a SHACL shape by name from this Perspective
|
|
646
646
|
*/
|
|
647
647
|
getShacl(name: string): Promise<SHACLShape | null>;
|
|
648
|
+
/**
|
|
649
|
+
* List the names of every SHACL shape stored in this Perspective, without fetching
|
|
650
|
+
* each shape's full definition (properties, target class, etc.) — just the cheap
|
|
651
|
+
* `ad4m://has_shacl` enumeration, one round trip regardless of how many shapes exist.
|
|
652
|
+
* Use this to check which shapes are actually worth resolving via `getShacl()` before
|
|
653
|
+
* paying for each one's full (multi-round-trip) fetch.
|
|
654
|
+
*/
|
|
655
|
+
getShaclNames(): Promise<string[]>;
|
|
656
|
+
/**
|
|
657
|
+
* Resolve just a shape's `sh:targetClass` by name, without fetching its properties —
|
|
658
|
+
* two round trips (name → shapeUri, then shapeUri's own direct triples) instead of
|
|
659
|
+
* `getShacl()`'s full walk (which also fetches every property sub-shape). Use this to
|
|
660
|
+
* disambiguate a shape name that collides with another app's `@Model({ name })` string
|
|
661
|
+
* (the bare `shacl://{name}` mapping ad4m-core uses is namespace-blind — see
|
|
662
|
+
* `getShaclNames()` callers for why that matters) before paying for a full fetch.
|
|
663
|
+
*/
|
|
664
|
+
getShaclTargetClass(name: string): Promise<string | undefined>;
|
|
648
665
|
/**
|
|
649
666
|
* Get all SHACL shapes stored in this Perspective
|
|
650
667
|
*/
|
|
@@ -1192,12 +1192,26 @@ export class PerspectiveProxy {
|
|
|
1192
1192
|
source: shapeUri,
|
|
1193
1193
|
predicate: "sh://property"
|
|
1194
1194
|
}));
|
|
1195
|
-
// Fetch all links from the shape and its property shapes
|
|
1195
|
+
// Fetch all links from the shape and its property shapes. These reads are
|
|
1196
|
+
// independent of each other, so fire them concurrently rather than one RPC
|
|
1197
|
+
// round trip at a time — over a remote (non-loopback) connection, a shape with
|
|
1198
|
+
// a dozen properties otherwise pays a dozen sequential round trips just to load.
|
|
1196
1199
|
const sourceUris = [shapeUri, ...propertyLinks.map(l => l.data.target)];
|
|
1200
|
+
const linksByUri = await Promise.all(sourceUris.map(uri => this.get(new LinkQuery({ source: uri }))));
|
|
1201
|
+
// Dedupe by (source, predicate, target): a perspective that's accumulated duplicate
|
|
1202
|
+
// SDNA links (e.g. from repeated registration attempts, or executor-side sync bugs)
|
|
1203
|
+
// would otherwise feed the same triple into SHACLShape.fromLinks more than once —
|
|
1204
|
+
// harmless for scalar fields like targetClass (first match wins) but can surface as
|
|
1205
|
+
// visibly duplicated properties for repeated sh://property links. Cheap: this is an
|
|
1206
|
+
// in-memory pass over data already fetched, no extra round trips.
|
|
1207
|
+
const seenLinks = new Set();
|
|
1197
1208
|
const allLinks = [];
|
|
1198
|
-
for (const
|
|
1199
|
-
const links = await this.get(new LinkQuery({ source: uri }));
|
|
1209
|
+
for (const links of linksByUri) {
|
|
1200
1210
|
for (const l of links) {
|
|
1211
|
+
const key = `${l.data.source} ${l.data.predicate} ${l.data.target}`;
|
|
1212
|
+
if (seenLinks.has(key))
|
|
1213
|
+
continue;
|
|
1214
|
+
seenLinks.add(key);
|
|
1201
1215
|
allLinks.push({
|
|
1202
1216
|
source: l.data.source,
|
|
1203
1217
|
predicate: l.data.predicate,
|
|
@@ -1209,24 +1223,62 @@ export class PerspectiveProxy {
|
|
|
1209
1223
|
return SHACLShape.fromLinks(shapeLinks, shapeUri);
|
|
1210
1224
|
}
|
|
1211
1225
|
/**
|
|
1212
|
-
*
|
|
1226
|
+
* List the names of every SHACL shape stored in this Perspective, without fetching
|
|
1227
|
+
* each shape's full definition (properties, target class, etc.) — just the cheap
|
|
1228
|
+
* `ad4m://has_shacl` enumeration, one round trip regardless of how many shapes exist.
|
|
1229
|
+
* Use this to check which shapes are actually worth resolving via `getShacl()` before
|
|
1230
|
+
* paying for each one's full (multi-round-trip) fetch.
|
|
1213
1231
|
*/
|
|
1214
|
-
async
|
|
1232
|
+
async getShaclNames() {
|
|
1215
1233
|
const nameLinks = await this.get(new LinkQuery({
|
|
1216
1234
|
source: "ad4m://self",
|
|
1217
1235
|
predicate: "ad4m://has_shacl"
|
|
1218
1236
|
}));
|
|
1219
|
-
|
|
1220
|
-
|
|
1221
|
-
|
|
1222
|
-
|
|
1223
|
-
const
|
|
1224
|
-
|
|
1225
|
-
|
|
1226
|
-
|
|
1227
|
-
|
|
1237
|
+
// Dedupe: a perspective with duplicate `has_shacl` links (see the dedup note in
|
|
1238
|
+
// getShacl()) would otherwise report the same name more than once, causing callers
|
|
1239
|
+
// to redundantly resolve (or redundantly disambiguate) it multiple times.
|
|
1240
|
+
const names = nameLinks.map((nameLink) => {
|
|
1241
|
+
const name = Literal.fromUrl(nameLink.data.target).get();
|
|
1242
|
+
return name.replace('shacl://', '');
|
|
1243
|
+
});
|
|
1244
|
+
return [...new Set(names)];
|
|
1245
|
+
}
|
|
1246
|
+
/**
|
|
1247
|
+
* Resolve just a shape's `sh:targetClass` by name, without fetching its properties —
|
|
1248
|
+
* two round trips (name → shapeUri, then shapeUri's own direct triples) instead of
|
|
1249
|
+
* `getShacl()`'s full walk (which also fetches every property sub-shape). Use this to
|
|
1250
|
+
* disambiguate a shape name that collides with another app's `@Model({ name })` string
|
|
1251
|
+
* (the bare `shacl://{name}` mapping ad4m-core uses is namespace-blind — see
|
|
1252
|
+
* `getShaclNames()` callers for why that matters) before paying for a full fetch.
|
|
1253
|
+
*/
|
|
1254
|
+
async getShaclTargetClass(name) {
|
|
1255
|
+
const nameMapping = Literal.fromUrl(`literal:string:shacl://${name}`);
|
|
1256
|
+
const shapeUriLinks = await this.get(new LinkQuery({
|
|
1257
|
+
source: nameMapping.toUrl(),
|
|
1258
|
+
predicate: "ad4m://shacl_shape_uri"
|
|
1259
|
+
}));
|
|
1260
|
+
if (shapeUriLinks.length === 0) {
|
|
1261
|
+
return undefined;
|
|
1228
1262
|
}
|
|
1229
|
-
|
|
1263
|
+
const shapeUri = shapeUriLinks[0].data.target;
|
|
1264
|
+
const shapeOwnLinks = await this.get(new LinkQuery({ source: shapeUri }));
|
|
1265
|
+
return shapeOwnLinks.find(l => l.data.predicate === "sh://targetClass")?.data.target;
|
|
1266
|
+
}
|
|
1267
|
+
/**
|
|
1268
|
+
* Get all SHACL shapes stored in this Perspective
|
|
1269
|
+
*/
|
|
1270
|
+
async getAllShacl() {
|
|
1271
|
+
const shapeNames = await this.getShaclNames();
|
|
1272
|
+
// Each shape is fetched independently of the others — resolve them concurrently.
|
|
1273
|
+
// Sequentially awaiting getShacl() per shape means a perspective with N SDNA
|
|
1274
|
+
// models pays N times getShacl()'s own multi-round-trip cost one after another;
|
|
1275
|
+
// over a remote connection with real per-call latency that compounds into the
|
|
1276
|
+
// dominant cost of switching into a perspective at all.
|
|
1277
|
+
const results = await Promise.all(shapeNames.map(async (shapeName) => {
|
|
1278
|
+
const shape = await this.getShacl(shapeName);
|
|
1279
|
+
return shape ? { name: shapeName, shape } : null;
|
|
1280
|
+
}));
|
|
1281
|
+
return results.filter((s) => s !== null);
|
|
1230
1282
|
}
|
|
1231
1283
|
/**
|
|
1232
1284
|
* **Recommended way to add Flow definitions.**
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
export {};
|
|
@@ -0,0 +1,34 @@
|
|
|
1
|
+
import { QuerySubscriptionProxy } from './PerspectiveProxy';
|
|
2
|
+
describe('QuerySubscriptionProxy', () => {
|
|
3
|
+
it('treats the initial subscribeQuery() result as a completed initialization', async () => {
|
|
4
|
+
const initialResult = [
|
|
5
|
+
{
|
|
6
|
+
source: 'literal:string:test-channel',
|
|
7
|
+
predicate: 'flux://has_channel_name',
|
|
8
|
+
target: 'literal:string:Runtime Fix Channel',
|
|
9
|
+
},
|
|
10
|
+
];
|
|
11
|
+
const unsubscribe = jest.fn();
|
|
12
|
+
const mockClient = {
|
|
13
|
+
subscribeQuery: jest.fn().mockResolvedValue({
|
|
14
|
+
subscriptionId: 'sub-1',
|
|
15
|
+
result: initialResult,
|
|
16
|
+
}),
|
|
17
|
+
subscribeToQueryUpdates: jest.fn().mockReturnValue(unsubscribe),
|
|
18
|
+
keepAliveQuery: jest.fn().mockResolvedValue(true),
|
|
19
|
+
disposeQuerySubscription: jest.fn().mockResolvedValue(true),
|
|
20
|
+
};
|
|
21
|
+
const subscription = new QuerySubscriptionProxy('perspective-1', 'SELECT * WHERE { ?s ?p ?o }', mockClient);
|
|
22
|
+
await subscription.subscribe();
|
|
23
|
+
const initialized = await Promise.race([
|
|
24
|
+
subscription.initialized.then(() => 'resolved'),
|
|
25
|
+
new Promise((resolve) => setTimeout(() => resolve('timeout'), 25)),
|
|
26
|
+
]);
|
|
27
|
+
expect(initialized).toBe('resolved');
|
|
28
|
+
expect(subscription.result).toEqual(initialResult);
|
|
29
|
+
expect(mockClient.subscribeQuery).toHaveBeenCalledWith('perspective-1', 'SELECT * WHERE { ?s ?p ?o }');
|
|
30
|
+
expect(mockClient.subscribeToQueryUpdates).toHaveBeenCalledWith('sub-1', expect.any(Function));
|
|
31
|
+
subscription.dispose();
|
|
32
|
+
expect(unsubscribe).toHaveBeenCalled();
|
|
33
|
+
});
|
|
34
|
+
});
|
|
@@ -0,0 +1,52 @@
|
|
|
1
|
+
/** Shape of event data parsed from JSON. Callers can narrow via generics. */
|
|
2
|
+
export interface SseEvent {
|
|
3
|
+
type: string;
|
|
4
|
+
[key: string]: unknown;
|
|
5
|
+
}
|
|
6
|
+
/** Error thrown by RestClient when an RPC call fails. */
|
|
7
|
+
export declare class RestError extends Error {
|
|
8
|
+
/** Error code (maps to HTTP status semantics: 400, 401, 403, 404, 500). */
|
|
9
|
+
readonly status: number;
|
|
10
|
+
/** Raw error message from server. */
|
|
11
|
+
readonly body: string;
|
|
12
|
+
constructor(status: number, body: string);
|
|
13
|
+
}
|
|
14
|
+
export declare class RestClient {
|
|
15
|
+
private baseUrl;
|
|
16
|
+
private token?;
|
|
17
|
+
constructor(baseUrl: string, token?: string);
|
|
18
|
+
getBaseUrl(): string;
|
|
19
|
+
getToken(): string | undefined;
|
|
20
|
+
setToken(token: string): void;
|
|
21
|
+
private _ws;
|
|
22
|
+
private _wsCallbacks;
|
|
23
|
+
private _pendingCalls;
|
|
24
|
+
private _wsReady;
|
|
25
|
+
private _wsReadyResolve;
|
|
26
|
+
private _wsReconnectTimer;
|
|
27
|
+
private _wsReconnectDelay;
|
|
28
|
+
private _wsClosed;
|
|
29
|
+
private _wsPingTimer;
|
|
30
|
+
private _getWsUrl;
|
|
31
|
+
private _ensureWs;
|
|
32
|
+
private _startPing;
|
|
33
|
+
private _stopPing;
|
|
34
|
+
private _scheduleReconnect;
|
|
35
|
+
/** Ensure WS is connected and ready. Lazy — connects on first use. */
|
|
36
|
+
private _ready;
|
|
37
|
+
/**
|
|
38
|
+
* Send an RPC call over the WebSocket connection.
|
|
39
|
+
* @param type - The operation type (e.g. 'agent.get', 'perspective.all')
|
|
40
|
+
* @param params - Optional parameters to include in the message
|
|
41
|
+
* @returns Promise that resolves with the result from the server
|
|
42
|
+
*/
|
|
43
|
+
call<T>(type: string, params?: Record<string, unknown>): Promise<T>;
|
|
44
|
+
subscribe<T = SseEvent>(path: string, callback: (data: T) => void): () => void;
|
|
45
|
+
/** Wait until the WebSocket connection is established. */
|
|
46
|
+
waitForSubscription(path: string): Promise<void>;
|
|
47
|
+
/** Explicitly connect the WebSocket (optional — connection is lazy). */
|
|
48
|
+
connect(): void;
|
|
49
|
+
private _closeWs;
|
|
50
|
+
/** Close all open WebSocket connections and reject pending calls. */
|
|
51
|
+
closeAll(): void;
|
|
52
|
+
}
|