@coasys/ad4m 0.13.0-test-7 → 0.13.0-test-8
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/lib/index.cjs +1109 -828
- package/lib/index.js +1096 -828
- package/lib/src/Ad4mClient.d.ts +4 -1
- package/lib/src/Ad4mClient.js +2 -2
- package/lib/src/agent/AgentClient.js +17 -0
- package/lib/src/ai/AIClient.js +1 -1
- package/lib/src/apiClient.d.ts +5 -1
- package/lib/src/apiClient.js +14 -6
- package/lib/src/generated/rest/AIModelLoadingStatus.d.ts +7 -0
- package/lib/src/generated/rest/AIModelLoadingStatus.js +2 -0
- package/lib/src/generated/rest/AddAgentInfosRequest.d.ts +3 -0
- package/lib/src/generated/rest/AddAgentInfosRequest.js +2 -0
- package/lib/src/generated/rest/AddLinkExpressionRequest.d.ts +6 -0
- package/lib/src/generated/rest/AddLinkExpressionRequest.js +1 -0
- package/lib/src/generated/rest/AddLinkRequest.d.ts +6 -0
- package/lib/src/generated/rest/AddLinkRequest.js +1 -0
- package/lib/src/generated/rest/AddLinksBulkRequest.d.ts +6 -0
- package/lib/src/generated/rest/AddLinksBulkRequest.js +1 -0
- package/lib/src/generated/rest/AddSdnaRequest.d.ts +6 -0
- package/lib/src/generated/rest/AddSdnaRequest.js +2 -0
- package/lib/src/generated/rest/ApplyTemplateRequest.d.ts +4 -0
- package/lib/src/generated/rest/ApplyTemplateRequest.js +2 -0
- package/lib/src/generated/rest/AuthInfoInput.d.ts +10 -0
- package/lib/src/generated/rest/AuthInfoInput.js +1 -0
- package/lib/src/generated/rest/BroadcastRequest.d.ts +6 -0
- package/lib/src/generated/rest/BroadcastRequest.js +1 -0
- package/lib/src/generated/rest/CapabilityInput.d.ts +5 -0
- package/lib/src/generated/rest/CapabilityInput.js +1 -0
- package/lib/src/generated/rest/CommitBatchRequest.d.ts +3 -0
- package/lib/src/generated/rest/CommitBatchRequest.js +2 -0
- package/lib/src/generated/rest/ComputeLogEntry.d.ts +9 -0
- package/lib/src/generated/rest/ComputeLogEntry.js +2 -0
- package/lib/src/generated/rest/CreateExpressionRequest.d.ts +4 -0
- package/lib/src/generated/rest/CreateExpressionRequest.js +2 -0
- package/lib/src/generated/rest/CreatePerspectiveRequest.d.ts +3 -0
- package/lib/src/generated/rest/CreatePerspectiveRequest.js +2 -0
- package/lib/src/generated/rest/CreateSubjectRequest.d.ts +6 -0
- package/lib/src/generated/rest/CreateSubjectRequest.js +2 -0
- package/lib/src/generated/rest/CreateUserRequest.d.ts +4 -0
- package/lib/src/generated/rest/CreateUserRequest.js +2 -0
- package/lib/src/generated/rest/CreateUserResponse.d.ts +5 -0
- package/lib/src/generated/rest/CreateUserResponse.js +2 -0
- package/lib/src/generated/rest/DecoratedExpressionProof.d.ts +6 -0
- package/lib/src/generated/rest/DecoratedExpressionProof.js +2 -0
- package/lib/src/generated/rest/DecoratedLinkExpression.d.ts +10 -0
- package/lib/src/generated/rest/DecoratedLinkExpression.js +1 -0
- package/lib/src/generated/rest/DisposeQueryRequest.d.ts +3 -0
- package/lib/src/generated/rest/DisposeQueryRequest.js +2 -0
- package/lib/src/generated/rest/EmailTestRequest.d.ts +6 -0
- package/lib/src/generated/rest/EmailTestRequest.js +2 -0
- package/lib/src/generated/rest/EmbedRequest.d.ts +4 -0
- package/lib/src/generated/rest/EmbedRequest.js +2 -0
- package/lib/src/generated/rest/EntanglementProofInput.d.ts +6 -0
- package/lib/src/generated/rest/EntanglementProofInput.js +2 -0
- package/lib/src/generated/rest/EntanglementProofPreflightRequest.d.ts +4 -0
- package/lib/src/generated/rest/EntanglementProofPreflightRequest.js +2 -0
- package/lib/src/generated/rest/ExecuteCommandsRequest.d.ts +4 -0
- package/lib/src/generated/rest/ExecuteCommandsRequest.js +2 -0
- package/lib/src/generated/rest/ExportRequest.d.ts +5 -0
- package/lib/src/generated/rest/ExportRequest.js +2 -0
- package/lib/src/generated/rest/ExpressionManyRequest.d.ts +3 -0
- package/lib/src/generated/rest/ExpressionManyRequest.js +2 -0
- package/lib/src/generated/rest/ExpressionProof.d.ts +4 -0
- package/lib/src/generated/rest/ExpressionProof.js +2 -0
- package/lib/src/generated/rest/ExpressionProofInput.d.ts +6 -0
- package/lib/src/generated/rest/ExpressionProofInput.js +2 -0
- package/lib/src/generated/rest/FriendSendMessageRequest.d.ts +3 -0
- package/lib/src/generated/rest/FriendSendMessageRequest.js +2 -0
- package/lib/src/generated/rest/FriendsListRequest.d.ts +3 -0
- package/lib/src/generated/rest/FriendsListRequest.js +2 -0
- package/lib/src/generated/rest/GenerateAgentRequest.d.ts +3 -0
- package/lib/src/generated/rest/GenerateAgentRequest.js +2 -0
- package/lib/src/generated/rest/GenerateJwtRequest.d.ts +4 -0
- package/lib/src/generated/rest/GenerateJwtRequest.js +2 -0
- package/lib/src/generated/rest/GetSubjectDataRequest.d.ts +4 -0
- package/lib/src/generated/rest/GetSubjectDataRequest.js +2 -0
- package/lib/src/generated/rest/HostingInfoResponse.d.ts +5 -0
- package/lib/src/generated/rest/HostingInfoResponse.js +2 -0
- package/lib/src/generated/rest/HostingWalletResponse.d.ts +4 -0
- package/lib/src/generated/rest/HostingWalletResponse.js +2 -0
- package/lib/src/generated/rest/ImportAgentRequest.d.ts +6 -0
- package/lib/src/generated/rest/ImportAgentRequest.js +2 -0
- package/lib/src/generated/rest/ImportRequest.d.ts +4 -0
- package/lib/src/generated/rest/ImportRequest.js +2 -0
- package/lib/src/generated/rest/JoinNeighbourhoodRequest.d.ts +3 -0
- package/lib/src/generated/rest/JoinNeighbourhoodRequest.js +2 -0
- package/lib/src/generated/rest/KeepAliveQueryRequest.d.ts +3 -0
- package/lib/src/generated/rest/KeepAliveQueryRequest.js +2 -0
- package/lib/src/generated/rest/LanguageMetaInput.d.ts +6 -0
- package/lib/src/generated/rest/LanguageMetaInput.js +2 -0
- package/lib/src/generated/rest/Link.d.ts +5 -0
- package/lib/src/generated/rest/Link.js +2 -0
- package/lib/src/generated/rest/LinkExpression.d.ts +10 -0
- package/lib/src/generated/rest/LinkExpression.js +1 -0
- package/lib/src/generated/rest/LinkExpressionInput.d.ts +10 -0
- package/lib/src/generated/rest/LinkExpressionInput.js +1 -0
- package/lib/src/generated/rest/LinkInput.d.ts +5 -0
- package/lib/src/generated/rest/LinkInput.js +2 -0
- package/lib/src/generated/rest/LinkLanguageTemplatesRequest.d.ts +3 -0
- package/lib/src/generated/rest/LinkLanguageTemplatesRequest.js +2 -0
- package/lib/src/generated/rest/LinkMutationRequest.d.ts +12 -0
- package/lib/src/generated/rest/LinkMutationRequest.js +1 -0
- package/lib/src/generated/rest/LinkMutationResponse.d.ts +9 -0
- package/lib/src/generated/rest/LinkMutationResponse.js +1 -0
- package/lib/src/generated/rest/LinkMutations.d.ts +6 -0
- package/lib/src/generated/rest/LinkMutations.js +1 -0
- package/lib/src/generated/rest/LinkMutationsRequest.d.ts +5 -0
- package/lib/src/generated/rest/LinkMutationsRequest.js +1 -0
- package/lib/src/generated/rest/LinkStatus.d.ts +1 -0
- package/lib/src/generated/rest/LinkStatus.js +2 -0
- package/lib/src/generated/rest/LinkUpdateInput.d.ts +5 -0
- package/lib/src/generated/rest/LinkUpdateInput.js +1 -0
- package/lib/src/generated/rest/LockAgentRequest.d.ts +3 -0
- package/lib/src/generated/rest/LockAgentRequest.js +2 -0
- package/lib/src/generated/rest/LoginUserRequest.d.ts +5 -0
- package/lib/src/generated/rest/LoginUserRequest.js +2 -0
- package/lib/src/generated/rest/ModelType.d.ts +1 -0
- package/lib/src/generated/rest/ModelType.js +2 -0
- package/lib/src/generated/rest/NotificationGrantRequest.d.ts +3 -0
- package/lib/src/generated/rest/NotificationGrantRequest.js +2 -0
- package/lib/src/generated/rest/NotificationInput.d.ts +10 -0
- package/lib/src/generated/rest/NotificationInput.js +2 -0
- package/lib/src/generated/rest/OpenLinkRequest.d.ts +3 -0
- package/lib/src/generated/rest/OpenLinkRequest.js +2 -0
- package/lib/src/generated/rest/PermitCapabilityRequest.d.ts +3 -0
- package/lib/src/generated/rest/PermitCapabilityRequest.js +2 -0
- package/lib/src/generated/rest/PerspectiveInput.d.ts +4 -0
- package/lib/src/generated/rest/PerspectiveInput.js +1 -0
- package/lib/src/generated/rest/PromptRequest.d.ts +4 -0
- package/lib/src/generated/rest/PromptRequest.js +2 -0
- package/lib/src/generated/rest/PublicPerspectiveInput.d.ts +4 -0
- package/lib/src/generated/rest/PublicPerspectiveInput.js +1 -0
- package/lib/src/generated/rest/PublishLanguageRequest.d.ts +5 -0
- package/lib/src/generated/rest/PublishLanguageRequest.js +1 -0
- package/lib/src/generated/rest/PublishNeighbourhoodRequest.d.ts +6 -0
- package/lib/src/generated/rest/PublishNeighbourhoodRequest.js +1 -0
- package/lib/src/generated/rest/QueryRequest.d.ts +7 -0
- package/lib/src/generated/rest/QueryRequest.js +2 -0
- package/lib/src/generated/rest/RemoveLinkRequest.d.ts +5 -0
- package/lib/src/generated/rest/RemoveLinkRequest.js +1 -0
- package/lib/src/generated/rest/RemoveLinksBulkRequest.d.ts +5 -0
- package/lib/src/generated/rest/RemoveLinksBulkRequest.js +1 -0
- package/lib/src/generated/rest/RequestCapabilityRequest.d.ts +4 -0
- package/lib/src/generated/rest/RequestCapabilityRequest.js +1 -0
- package/lib/src/generated/rest/RequestPaymentRequest.d.ts +3 -0
- package/lib/src/generated/rest/RequestPaymentRequest.js +2 -0
- package/lib/src/generated/rest/RequestVerificationRequest.d.ts +4 -0
- package/lib/src/generated/rest/RequestVerificationRequest.js +2 -0
- package/lib/src/generated/rest/ResourceInput.d.ts +4 -0
- package/lib/src/generated/rest/ResourceInput.js +2 -0
- package/lib/src/generated/rest/SetDefaultModelRequest.d.ts +4 -0
- package/lib/src/generated/rest/SetDefaultModelRequest.js +1 -0
- package/lib/src/generated/rest/SetFreeHostingEnabledRequest.d.ts +3 -0
- package/lib/src/generated/rest/SetFreeHostingEnabledRequest.js +2 -0
- package/lib/src/generated/rest/SetHotWalletAddressRequest.d.ts +3 -0
- package/lib/src/generated/rest/SetHotWalletAddressRequest.js +2 -0
- package/lib/src/generated/rest/SetMultiUserRequest.d.ts +3 -0
- package/lib/src/generated/rest/SetMultiUserRequest.js +2 -0
- package/lib/src/generated/rest/SetOnlineStatusRequest.d.ts +5 -0
- package/lib/src/generated/rest/SetOnlineStatusRequest.js +1 -0
- package/lib/src/generated/rest/SetStatusRequest.d.ts +3 -0
- package/lib/src/generated/rest/SetStatusRequest.js +2 -0
- package/lib/src/generated/rest/SetUserFreeAccessRequest.d.ts +4 -0
- package/lib/src/generated/rest/SetUserFreeAccessRequest.js +2 -0
- package/lib/src/generated/rest/SignMessageRequest.d.ts +3 -0
- package/lib/src/generated/rest/SignMessageRequest.js +2 -0
- package/lib/src/generated/rest/SignalRequest.d.ts +6 -0
- package/lib/src/generated/rest/SignalRequest.js +1 -0
- package/lib/src/generated/rest/SubscribeQueryRequest.d.ts +3 -0
- package/lib/src/generated/rest/SubscribeQueryRequest.js +2 -0
- package/lib/src/generated/rest/SubscribeQueryResponse.d.ts +4 -0
- package/lib/src/generated/rest/SubscribeQueryResponse.js +2 -0
- package/lib/src/generated/rest/TrustedAgentsRequest.d.ts +3 -0
- package/lib/src/generated/rest/TrustedAgentsRequest.js +2 -0
- package/lib/src/generated/rest/UnlockAgentRequest.d.ts +4 -0
- package/lib/src/generated/rest/UnlockAgentRequest.js +2 -0
- package/lib/src/generated/rest/UpdateLinkRequest.d.ts +7 -0
- package/lib/src/generated/rest/UpdateLinkRequest.js +1 -0
- package/lib/src/generated/rest/UpdatePerspectiveRequest.d.ts +3 -0
- package/lib/src/generated/rest/UpdatePerspectiveRequest.js +2 -0
- package/lib/src/generated/rest/UpdateProfileRequest.d.ts +5 -0
- package/lib/src/generated/rest/UpdateProfileRequest.js +1 -0
- package/lib/src/generated/rest/UserStatistics.d.ts +9 -0
- package/lib/src/generated/rest/UserStatistics.js +2 -0
- package/lib/src/generated/rest/VerificationRequestResult.d.ts +6 -0
- package/lib/src/generated/rest/VerificationRequestResult.js +2 -0
- package/lib/src/generated/rest/VerifyEmailRequest.d.ts +6 -0
- package/lib/src/generated/rest/VerifyEmailRequest.js +2 -0
- package/lib/src/generated/rest/VerifySignatureRequest.d.ts +5 -0
- package/lib/src/generated/rest/VerifySignatureRequest.js +2 -0
- package/lib/src/generated/rest/WriteSettingsRequest.d.ts +3 -0
- package/lib/src/generated/rest/WriteSettingsRequest.js +2 -0
- package/lib/src/generated/rest/index.d.ts +73 -0
- package/lib/src/generated/rest/index.js +8 -0
- package/lib/src/generated/rest/routes.d.ts +587 -0
- package/lib/src/generated/rest/routes.js +3 -0
- package/lib/src/index.d.ts +4 -0
- package/lib/src/index.js +4 -0
- package/lib/src/model/Ad4mModel.d.ts +30 -36
- package/lib/src/model/Ad4mModel.js +93 -382
- package/lib/src/model/Ad4mModel.test.js +735 -480
- package/lib/src/model/ModelQueryBuilder.d.ts +5 -10
- package/lib/src/model/ModelQueryBuilder.js +142 -62
- package/lib/src/model/decorators.d.ts +7 -4
- package/lib/src/model/decorators.js +0 -7
- package/lib/src/model/query-sparql.d.ts +0 -10
- package/lib/src/model/query-sparql.js +10 -15
- package/lib/src/model/query-sparql.test.js +10 -92
- package/lib/src/model/query-surreal.d.ts +44 -0
- package/lib/src/model/query-surreal.js +249 -0
- package/lib/src/model/shacl-gen.js +120 -47
- package/lib/src/model/surreal-utils.d.ts +42 -0
- package/lib/src/model/surreal-utils.js +128 -0
- package/lib/src/model/types.d.ts +140 -4
- package/lib/src/neighbourhood/NeighbourhoodProxy.test.js +33 -33
- package/lib/src/perspectives/PerspectiveClient.d.ts +13 -4
- package/lib/src/perspectives/PerspectiveClient.js +22 -6
- package/lib/src/perspectives/PerspectiveProxy.d.ts +27 -7
- package/lib/src/perspectives/PerspectiveProxy.js +60 -12
- package/lib/src/perspectives/PerspectiveProxy.test.d.ts +1 -0
- package/lib/src/perspectives/PerspectiveProxy.test.js +34 -0
- package/lib/src/perspectives/SparqlBindings.d.ts +47 -0
- package/lib/src/perspectives/SparqlBindings.js +65 -0
- package/lib/src/perspectives/WakerSubscriptionManager.js +5 -4
- package/lib/src/restClient.d.ts +52 -0
- package/lib/src/restClient.js +227 -0
- package/lib/src/shacl/NodeExpression.d.ts +44 -0
- package/lib/src/shacl/NodeExpression.js +39 -0
- package/lib/src/shacl/SHACLShape.d.ts +23 -0
- package/lib/src/shacl/SHACLShape.js +115 -1
- package/lib/src/shacl/SHACLShape.test.js +0 -82
- package/lib/src/shacl/builders.d.ts +58 -0
- package/lib/src/shacl/builders.js +76 -0
- package/lib/src/shacl/index.d.ts +36 -0
- package/lib/src/shacl/index.js +33 -0
- package/package.json +11 -8
- package/src/Ad4mClient.ts +7 -2
- package/src/agent/AgentClient.ts +23 -0
- package/src/ai/AIClient.ts +1 -1
- package/src/apiClient.ts +17 -6
- package/src/index.ts +4 -0
- package/src/model/Ad4mModel.test.ts +274 -72
- package/src/model/Ad4mModel.ts +140 -420
- package/src/model/ModelQueryBuilder.ts +136 -71
- package/src/model/decorators.ts +7 -13
- package/src/model/query-sparql.test.ts +35 -19
- package/src/model/query-sparql.ts +10 -16
- package/src/model/relation-filtering.test.ts +46 -39
- package/src/model/shacl-gen.ts +128 -54
- package/src/model/shacl-roundtrip.test.ts +197 -0
- package/src/model/types-typed-query.test.ts +360 -0
- package/src/model/types.ts +196 -4
- package/src/perspectives/PerspectiveClient.ts +24 -8
- package/src/perspectives/PerspectiveProxy.test.ts +85 -1
- package/src/perspectives/PerspectiveProxy.ts +65 -20
- package/src/perspectives/SparqlBindings.ts +79 -0
- package/src/perspectives/WakerSubscriptionManager.ts +5 -4
- package/src/shacl/NodeExpression.ts +54 -0
- package/src/shacl/SHACLShape.test.ts +172 -0
- package/src/shacl/SHACLShape.ts +173 -1
- package/src/shacl/builders.ts +86 -0
- package/src/shacl/index.ts +72 -0
- package/lib/src/model/model-manifest.d.ts +0 -41
- package/lib/src/model/model-manifest.js +0 -11
|
@@ -1,3 +1,4 @@
|
|
|
1
|
+
import { isNodeExpression } from "./NodeExpression";
|
|
1
2
|
/**
|
|
2
3
|
* Extract namespace from a URI
|
|
3
4
|
* Examples:
|
|
@@ -328,7 +329,7 @@ export class SHACLShape {
|
|
|
328
329
|
target: `literal:${prop.writable}`
|
|
329
330
|
});
|
|
330
331
|
}
|
|
331
|
-
if (prop.resolveLanguage) {
|
|
332
|
+
if (prop.resolveLanguage != null) {
|
|
332
333
|
links.push({
|
|
333
334
|
source: propShapeId,
|
|
334
335
|
predicate: "ad4m://resolveLanguage",
|
|
@@ -385,6 +386,48 @@ export class SHACLShape {
|
|
|
385
386
|
target: `literal:string:${JSON.stringify(prop.in)}`
|
|
386
387
|
});
|
|
387
388
|
}
|
|
389
|
+
if (prop.relationKind) {
|
|
390
|
+
links.push({
|
|
391
|
+
source: propShapeId,
|
|
392
|
+
predicate: "ad4m://relationKind",
|
|
393
|
+
target: `literal:string:${prop.relationKind}`
|
|
394
|
+
});
|
|
395
|
+
}
|
|
396
|
+
if (prop.targetClassName) {
|
|
397
|
+
links.push({
|
|
398
|
+
source: propShapeId,
|
|
399
|
+
predicate: "ad4m://targetClassName",
|
|
400
|
+
target: `literal:string:${prop.targetClassName}`
|
|
401
|
+
});
|
|
402
|
+
}
|
|
403
|
+
if (prop.whereFilter !== undefined && prop.whereFilter !== null) {
|
|
404
|
+
links.push({
|
|
405
|
+
source: propShapeId,
|
|
406
|
+
predicate: "ad4m://whereFilter",
|
|
407
|
+
target: `literal:string:${JSON.stringify(prop.whereFilter)}`
|
|
408
|
+
});
|
|
409
|
+
}
|
|
410
|
+
if (prop.wherePredicates && Object.keys(prop.wherePredicates).length > 0) {
|
|
411
|
+
links.push({
|
|
412
|
+
source: propShapeId,
|
|
413
|
+
predicate: "ad4m://wherePredicates",
|
|
414
|
+
target: `literal:string:${JSON.stringify(prop.wherePredicates)}`
|
|
415
|
+
});
|
|
416
|
+
}
|
|
417
|
+
if (prop.filter !== undefined) {
|
|
418
|
+
links.push({
|
|
419
|
+
source: propShapeId,
|
|
420
|
+
predicate: "ad4m://filter",
|
|
421
|
+
target: `literal:${prop.filter}`
|
|
422
|
+
});
|
|
423
|
+
}
|
|
424
|
+
if (prop.transform && typeof prop.transform === 'object') {
|
|
425
|
+
links.push({
|
|
426
|
+
source: propShapeId,
|
|
427
|
+
predicate: "ad4m://transform",
|
|
428
|
+
target: `literal:string:${JSON.stringify(prop.transform)}`
|
|
429
|
+
});
|
|
430
|
+
}
|
|
388
431
|
}
|
|
389
432
|
return links;
|
|
390
433
|
}
|
|
@@ -566,6 +609,60 @@ export class SHACLShape {
|
|
|
566
609
|
// Ignore parse errors
|
|
567
610
|
}
|
|
568
611
|
}
|
|
612
|
+
const relationKindLink = links.find(l => l.source === propShapeId && l.predicate === "ad4m://relationKind");
|
|
613
|
+
if (relationKindLink) {
|
|
614
|
+
const val = relationKindLink.target.replace(/^literal:\/\/string:|^literal:string:/, '');
|
|
615
|
+
if (val === 'hasMany' || val === 'hasOne' || val === 'belongsToOne' || val === 'belongsToMany') {
|
|
616
|
+
prop.relationKind = val;
|
|
617
|
+
}
|
|
618
|
+
}
|
|
619
|
+
const targetClassNameLink = links.find(l => l.source === propShapeId && l.predicate === "ad4m://targetClassName");
|
|
620
|
+
if (targetClassNameLink) {
|
|
621
|
+
prop.targetClassName = targetClassNameLink.target.replace(/^literal:\/\/string:|^literal:string:/, '');
|
|
622
|
+
}
|
|
623
|
+
const whereFilterLink = links.find(l => l.source === propShapeId && l.predicate === "ad4m://whereFilter");
|
|
624
|
+
if (whereFilterLink) {
|
|
625
|
+
try {
|
|
626
|
+
const jsonStr = whereFilterLink.target.replace(/^literal:\/\/string:|^literal:string:/, '');
|
|
627
|
+
prop.whereFilter = JSON.parse(jsonStr);
|
|
628
|
+
}
|
|
629
|
+
catch (e) {
|
|
630
|
+
// Ignore parse errors
|
|
631
|
+
}
|
|
632
|
+
}
|
|
633
|
+
const wherePredicatesLink = links.find(l => l.source === propShapeId && l.predicate === "ad4m://wherePredicates");
|
|
634
|
+
if (wherePredicatesLink) {
|
|
635
|
+
try {
|
|
636
|
+
const jsonStr = wherePredicatesLink.target.replace(/^literal:\/\/string:|^literal:string:/, '');
|
|
637
|
+
prop.wherePredicates = JSON.parse(jsonStr);
|
|
638
|
+
}
|
|
639
|
+
catch (e) {
|
|
640
|
+
// Ignore parse errors
|
|
641
|
+
}
|
|
642
|
+
}
|
|
643
|
+
const filterLink = links.find(l => l.source === propShapeId && l.predicate === "ad4m://filter");
|
|
644
|
+
if (filterLink) {
|
|
645
|
+
let val = filterLink.target.replace(/^literal:\/\/|^literal:/, '');
|
|
646
|
+
if (val.startsWith('boolean:'))
|
|
647
|
+
val = val.substring(8);
|
|
648
|
+
prop.filter = val === 'true';
|
|
649
|
+
}
|
|
650
|
+
const transformLink = links.find(l => l.source === propShapeId && l.predicate === "ad4m://transform");
|
|
651
|
+
if (transformLink) {
|
|
652
|
+
const jsonStr = transformLink.target.replace(/^literal:\/\/string:|^literal:string:/, '');
|
|
653
|
+
try {
|
|
654
|
+
const parsed = JSON.parse(jsonStr);
|
|
655
|
+
if (!isNodeExpression(parsed)) {
|
|
656
|
+
throw new Error(`Invalid transform for property ${propShapeId}: ` +
|
|
657
|
+
`payload is not a valid NodeExpression. Received: ${jsonStr}`);
|
|
658
|
+
}
|
|
659
|
+
prop.transform = parsed;
|
|
660
|
+
}
|
|
661
|
+
catch (e) {
|
|
662
|
+
throw new Error(`Failed to deserialize transform for property ${propShapeId}: ` +
|
|
663
|
+
`${e instanceof Error ? e.message : String(e)}. Payload: ${jsonStr}`);
|
|
664
|
+
}
|
|
665
|
+
}
|
|
569
666
|
shape.addProperty(prop);
|
|
570
667
|
}
|
|
571
668
|
return shape;
|
|
@@ -602,6 +699,12 @@ export class SHACLShape {
|
|
|
602
699
|
conformance_conditions: p.conformanceConditions,
|
|
603
700
|
class: p.class,
|
|
604
701
|
in: p.in,
|
|
702
|
+
relation_kind: p.relationKind,
|
|
703
|
+
target_class_name: p.targetClassName,
|
|
704
|
+
where_filter: p.whereFilter,
|
|
705
|
+
where_predicates: p.wherePredicates,
|
|
706
|
+
filter: p.filter,
|
|
707
|
+
transform: p.transform,
|
|
605
708
|
})),
|
|
606
709
|
constructor_actions: this.constructor_actions,
|
|
607
710
|
destructor_actions: this.destructor_actions,
|
|
@@ -615,6 +718,11 @@ export class SHACLShape {
|
|
|
615
718
|
? new SHACLShape(json.node_shape_uri, json.target_class)
|
|
616
719
|
: new SHACLShape(json.target_class);
|
|
617
720
|
for (const p of json.properties || []) {
|
|
721
|
+
// Validate transform if present
|
|
722
|
+
if (p.transform && !isNodeExpression(p.transform)) {
|
|
723
|
+
throw new Error(`Invalid transform for property ${p.name}: ` +
|
|
724
|
+
`payload is not a valid NodeExpression. Received: ${JSON.stringify(p.transform)}`);
|
|
725
|
+
}
|
|
618
726
|
shape.addProperty({
|
|
619
727
|
path: p.path,
|
|
620
728
|
name: p.name,
|
|
@@ -636,6 +744,12 @@ export class SHACLShape {
|
|
|
636
744
|
conformanceConditions: p.conformance_conditions,
|
|
637
745
|
class: p.class,
|
|
638
746
|
in: p.in,
|
|
747
|
+
relationKind: p.relation_kind,
|
|
748
|
+
targetClassName: p.target_class_name,
|
|
749
|
+
whereFilter: p.where_filter,
|
|
750
|
+
wherePredicates: p.where_predicates,
|
|
751
|
+
filter: p.filter,
|
|
752
|
+
transform: p.transform,
|
|
639
753
|
});
|
|
640
754
|
}
|
|
641
755
|
if (json.constructor_actions) {
|
|
@@ -333,86 +333,4 @@ describe('SHACLShape', () => {
|
|
|
333
333
|
expect(prop.remover).toEqual(original.properties[0].remover);
|
|
334
334
|
});
|
|
335
335
|
});
|
|
336
|
-
describe('sh:in round-trip', () => {
|
|
337
|
-
it('preserves sh:in enum values through toLinks() → fromLinks()', () => {
|
|
338
|
-
const original = new SHACLShape('test://Model');
|
|
339
|
-
original.addProperty({
|
|
340
|
-
name: 'status',
|
|
341
|
-
path: 'test://status',
|
|
342
|
-
datatype: 'xsd:string',
|
|
343
|
-
in: [
|
|
344
|
-
{ value: 'active', label: 'Active' },
|
|
345
|
-
{ value: 'inactive', label: 'Inactive' },
|
|
346
|
-
{ value: 'archived' },
|
|
347
|
-
],
|
|
348
|
-
});
|
|
349
|
-
const links = original.toLinks();
|
|
350
|
-
// Verify sh:in link was created
|
|
351
|
-
const inLink = links.find(l => l.predicate === 'sh://in');
|
|
352
|
-
expect(inLink).toBeDefined();
|
|
353
|
-
expect(inLink.target).toContain('literal:string:');
|
|
354
|
-
// Reconstruct and verify
|
|
355
|
-
const reconstructed = SHACLShape.fromLinks(links, 'test://ModelShape');
|
|
356
|
-
expect(reconstructed.properties[0].in).toBeDefined();
|
|
357
|
-
expect(reconstructed.properties[0].in).toEqual([
|
|
358
|
-
{ value: 'active', label: 'Active' },
|
|
359
|
-
{ value: 'inactive', label: 'Inactive' },
|
|
360
|
-
{ value: 'archived' },
|
|
361
|
-
]);
|
|
362
|
-
});
|
|
363
|
-
it('handles sh:in with special characters in values', () => {
|
|
364
|
-
const original = new SHACLShape('test://Model');
|
|
365
|
-
original.addProperty({
|
|
366
|
-
name: 'category',
|
|
367
|
-
path: 'test://category',
|
|
368
|
-
in: [
|
|
369
|
-
{ value: 'food & drink', label: 'Food & Drink' },
|
|
370
|
-
{ value: 'arts/crafts' },
|
|
371
|
-
],
|
|
372
|
-
});
|
|
373
|
-
const links = original.toLinks();
|
|
374
|
-
const reconstructed = SHACLShape.fromLinks(links, 'test://ModelShape');
|
|
375
|
-
expect(reconstructed.properties[0].in).toEqual(original.properties[0].in);
|
|
376
|
-
});
|
|
377
|
-
it('handles sh:in with empty array (no link created)', () => {
|
|
378
|
-
const original = new SHACLShape('test://Model');
|
|
379
|
-
original.addProperty({
|
|
380
|
-
name: 'field',
|
|
381
|
-
path: 'test://field',
|
|
382
|
-
in: [],
|
|
383
|
-
});
|
|
384
|
-
const links = original.toLinks();
|
|
385
|
-
const inLink = links.find(l => l.predicate === 'sh://in');
|
|
386
|
-
expect(inLink).toBeUndefined();
|
|
387
|
-
});
|
|
388
|
-
it('handles sh:in with literal://string: prefix variant', () => {
|
|
389
|
-
// fromLinks should handle both `literal:string:` and `literal://string:` prefixes
|
|
390
|
-
const links = [
|
|
391
|
-
{ source: 'test://ModelShape', predicate: 'sh://targetClass', target: 'test://Model' },
|
|
392
|
-
{ source: 'test://ModelShape', predicate: 'sh://property', target: 'test://Model.status' },
|
|
393
|
-
{ source: 'test://Model.status', predicate: 'sh://path', target: 'test://status' },
|
|
394
|
-
{ source: 'test://Model.status', predicate: 'sh://in', target: 'literal://string:[{"value":"a"},{"value":"b"}]' },
|
|
395
|
-
];
|
|
396
|
-
const reconstructed = SHACLShape.fromLinks(links, 'test://ModelShape');
|
|
397
|
-
expect(reconstructed.properties[0].in).toEqual([
|
|
398
|
-
{ value: 'a' },
|
|
399
|
-
{ value: 'b' },
|
|
400
|
-
]);
|
|
401
|
-
});
|
|
402
|
-
it('preserves sh:in through toJSON() → fromJSON()', () => {
|
|
403
|
-
const original = new SHACLShape('test://Model');
|
|
404
|
-
original.addProperty({
|
|
405
|
-
name: 'priority',
|
|
406
|
-
path: 'test://priority',
|
|
407
|
-
in: [
|
|
408
|
-
{ value: 'high', label: 'High' },
|
|
409
|
-
{ value: 'medium', label: 'Medium' },
|
|
410
|
-
{ value: 'low', label: 'Low' },
|
|
411
|
-
],
|
|
412
|
-
});
|
|
413
|
-
const json = original.toJSON();
|
|
414
|
-
const reconstructed = SHACLShape.fromJSON(json);
|
|
415
|
-
expect(reconstructed.properties[0].in).toEqual(original.properties[0].in);
|
|
416
|
-
});
|
|
417
|
-
});
|
|
418
336
|
});
|
|
@@ -0,0 +1,58 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Builder functions for SHACL-AF Node Expressions.
|
|
3
|
+
*
|
|
4
|
+
* These functions construct JSON-serializable expression trees for property transforms.
|
|
5
|
+
* All builders return frozen objects to prevent accidental mutation.
|
|
6
|
+
*/
|
|
7
|
+
import type { NodeExpression } from './NodeExpression';
|
|
8
|
+
/**
|
|
9
|
+
* Identity expression: pass the focus node through unchanged.
|
|
10
|
+
*/
|
|
11
|
+
export declare function focus(): NodeExpression;
|
|
12
|
+
/**
|
|
13
|
+
* Literal constant expression.
|
|
14
|
+
*/
|
|
15
|
+
export declare function literal(value: string | number | boolean): NodeExpression;
|
|
16
|
+
/**
|
|
17
|
+
* Path expression: navigate to a property on the resolved object.
|
|
18
|
+
* The predicate can be a full IRI (e.g., "file_storage://data_base64")
|
|
19
|
+
* or a simple property name. The Rust evaluator will strip the namespace.
|
|
20
|
+
*/
|
|
21
|
+
export declare function path(predicate: string): NodeExpression;
|
|
22
|
+
/**
|
|
23
|
+
* Existence check: returns true if the inner expression is non-null and non-empty.
|
|
24
|
+
*/
|
|
25
|
+
export declare function exists(expr: NodeExpression): NodeExpression;
|
|
26
|
+
/**
|
|
27
|
+
* Conditional expression with optional else branch.
|
|
28
|
+
* Returns a chainable builder that supports `.then()` and `.else()`.
|
|
29
|
+
*/
|
|
30
|
+
export declare function ifExpr(cond: NodeExpression): {
|
|
31
|
+
then: (thenExpr: NodeExpression) => {
|
|
32
|
+
else: (elseExpr?: NodeExpression) => Readonly<{
|
|
33
|
+
readonly else: NodeExpression;
|
|
34
|
+
readonly type: "if";
|
|
35
|
+
readonly cond: NodeExpression;
|
|
36
|
+
readonly then: NodeExpression;
|
|
37
|
+
}>;
|
|
38
|
+
toExpression: () => Readonly<{
|
|
39
|
+
readonly type: "if";
|
|
40
|
+
readonly cond: NodeExpression;
|
|
41
|
+
readonly then: NodeExpression;
|
|
42
|
+
}>;
|
|
43
|
+
};
|
|
44
|
+
};
|
|
45
|
+
/**
|
|
46
|
+
* String concatenation: joins evaluated arguments as strings.
|
|
47
|
+
* Null/undefined arguments are skipped.
|
|
48
|
+
*/
|
|
49
|
+
export declare function concat(...args: NodeExpression[]): NodeExpression;
|
|
50
|
+
/**
|
|
51
|
+
* Coalesce: returns the first non-null evaluated argument.
|
|
52
|
+
*/
|
|
53
|
+
export declare function coalesce(...args: NodeExpression[]): NodeExpression;
|
|
54
|
+
/**
|
|
55
|
+
* Function call: invoke a named transform function by IRI.
|
|
56
|
+
* Primarily used for built-in functions like "ad4m://fn/defaultFileDecode".
|
|
57
|
+
*/
|
|
58
|
+
export declare function fn(iri: string, args?: NodeExpression[]): NodeExpression;
|
|
@@ -0,0 +1,76 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Builder functions for SHACL-AF Node Expressions.
|
|
3
|
+
*
|
|
4
|
+
* These functions construct JSON-serializable expression trees for property transforms.
|
|
5
|
+
* All builders return frozen objects to prevent accidental mutation.
|
|
6
|
+
*/
|
|
7
|
+
/**
|
|
8
|
+
* Identity expression: pass the focus node through unchanged.
|
|
9
|
+
*/
|
|
10
|
+
export function focus() {
|
|
11
|
+
return Object.freeze({ type: 'focus' });
|
|
12
|
+
}
|
|
13
|
+
/**
|
|
14
|
+
* Literal constant expression.
|
|
15
|
+
*/
|
|
16
|
+
export function literal(value) {
|
|
17
|
+
return Object.freeze({ type: 'literal', value });
|
|
18
|
+
}
|
|
19
|
+
/**
|
|
20
|
+
* Path expression: navigate to a property on the resolved object.
|
|
21
|
+
* The predicate can be a full IRI (e.g., "file_storage://data_base64")
|
|
22
|
+
* or a simple property name. The Rust evaluator will strip the namespace.
|
|
23
|
+
*/
|
|
24
|
+
export function path(predicate) {
|
|
25
|
+
return Object.freeze({ type: 'path', predicate });
|
|
26
|
+
}
|
|
27
|
+
/**
|
|
28
|
+
* Existence check: returns true if the inner expression is non-null and non-empty.
|
|
29
|
+
*/
|
|
30
|
+
export function exists(expr) {
|
|
31
|
+
return Object.freeze({ type: 'exists', expr });
|
|
32
|
+
}
|
|
33
|
+
/**
|
|
34
|
+
* Conditional expression with optional else branch.
|
|
35
|
+
* Returns a chainable builder that supports `.then()` and `.else()`.
|
|
36
|
+
*/
|
|
37
|
+
export function ifExpr(cond) {
|
|
38
|
+
return {
|
|
39
|
+
then: (thenExpr) => ({
|
|
40
|
+
else: (elseExpr) => {
|
|
41
|
+
return Object.freeze({
|
|
42
|
+
type: 'if',
|
|
43
|
+
cond,
|
|
44
|
+
then: thenExpr,
|
|
45
|
+
...(elseExpr !== undefined && { else: elseExpr }),
|
|
46
|
+
});
|
|
47
|
+
},
|
|
48
|
+
// Allow chaining without explicit else()
|
|
49
|
+
toExpression: () => Object.freeze({
|
|
50
|
+
type: 'if',
|
|
51
|
+
cond,
|
|
52
|
+
then: thenExpr,
|
|
53
|
+
}),
|
|
54
|
+
}),
|
|
55
|
+
};
|
|
56
|
+
}
|
|
57
|
+
/**
|
|
58
|
+
* String concatenation: joins evaluated arguments as strings.
|
|
59
|
+
* Null/undefined arguments are skipped.
|
|
60
|
+
*/
|
|
61
|
+
export function concat(...args) {
|
|
62
|
+
return Object.freeze({ type: 'concat', args });
|
|
63
|
+
}
|
|
64
|
+
/**
|
|
65
|
+
* Coalesce: returns the first non-null evaluated argument.
|
|
66
|
+
*/
|
|
67
|
+
export function coalesce(...args) {
|
|
68
|
+
return Object.freeze({ type: 'coalesce', args });
|
|
69
|
+
}
|
|
70
|
+
/**
|
|
71
|
+
* Function call: invoke a named transform function by IRI.
|
|
72
|
+
* Primarily used for built-in functions like "ad4m://fn/defaultFileDecode".
|
|
73
|
+
*/
|
|
74
|
+
export function fn(iri, args = []) {
|
|
75
|
+
return Object.freeze({ type: 'function', iri, args });
|
|
76
|
+
}
|
|
@@ -0,0 +1,36 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* SHACL-AF Transform DSL — public API
|
|
3
|
+
*
|
|
4
|
+
* Re-exports builder functions and provides common built-in transforms.
|
|
5
|
+
*/
|
|
6
|
+
import { focus, literal, path, exists, ifExpr, concat, coalesce, fn } from './builders';
|
|
7
|
+
export type { NodeExpression } from './NodeExpression';
|
|
8
|
+
export { isNodeExpression } from './NodeExpression';
|
|
9
|
+
export { focus, literal, path, exists, ifExpr, concat, coalesce, fn, };
|
|
10
|
+
/**
|
|
11
|
+
* Built-in transform: FileData → data: URI
|
|
12
|
+
*
|
|
13
|
+
* Converts a file stored via FILE_STORAGE_LANGUAGE into a data: URL.
|
|
14
|
+
* If the object has a `data_base64` field, returns:
|
|
15
|
+
* `data:{file_type};base64,{data_base64}`
|
|
16
|
+
* Otherwise passes through the input unchanged.
|
|
17
|
+
*
|
|
18
|
+
* This is the Rust equivalent of the JS `defaultFileDecode` function.
|
|
19
|
+
*
|
|
20
|
+
* Usage:
|
|
21
|
+
* ```typescript
|
|
22
|
+
* @Property({
|
|
23
|
+
* through: 'we://image',
|
|
24
|
+
* resolveLanguage: FILE_STORAGE_LANGUAGE,
|
|
25
|
+
* transform: fileToDataUri,
|
|
26
|
+
* })
|
|
27
|
+
* avatar?: string;
|
|
28
|
+
* ```
|
|
29
|
+
*/
|
|
30
|
+
export declare const fileToDataUri: Readonly<{
|
|
31
|
+
readonly else: import("./NodeExpression").NodeExpression;
|
|
32
|
+
readonly type: "if";
|
|
33
|
+
readonly cond: import("./NodeExpression").NodeExpression;
|
|
34
|
+
readonly then: import("./NodeExpression").NodeExpression;
|
|
35
|
+
}>;
|
|
36
|
+
export { SHACLShape, SHACLPropertyShape, AD4MAction, ConformanceCondition, } from './SHACLShape';
|
|
@@ -0,0 +1,33 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* SHACL-AF Transform DSL — public API
|
|
3
|
+
*
|
|
4
|
+
* Re-exports builder functions and provides common built-in transforms.
|
|
5
|
+
*/
|
|
6
|
+
import { focus, literal, path, exists, ifExpr, concat, coalesce, fn, } from './builders';
|
|
7
|
+
export { isNodeExpression } from './NodeExpression';
|
|
8
|
+
export { focus, literal, path, exists, ifExpr, concat, coalesce, fn, };
|
|
9
|
+
/**
|
|
10
|
+
* Built-in transform: FileData → data: URI
|
|
11
|
+
*
|
|
12
|
+
* Converts a file stored via FILE_STORAGE_LANGUAGE into a data: URL.
|
|
13
|
+
* If the object has a `data_base64` field, returns:
|
|
14
|
+
* `data:{file_type};base64,{data_base64}`
|
|
15
|
+
* Otherwise passes through the input unchanged.
|
|
16
|
+
*
|
|
17
|
+
* This is the Rust equivalent of the JS `defaultFileDecode` function.
|
|
18
|
+
*
|
|
19
|
+
* Usage:
|
|
20
|
+
* ```typescript
|
|
21
|
+
* @Property({
|
|
22
|
+
* through: 'we://image',
|
|
23
|
+
* resolveLanguage: FILE_STORAGE_LANGUAGE,
|
|
24
|
+
* transform: fileToDataUri,
|
|
25
|
+
* })
|
|
26
|
+
* avatar?: string;
|
|
27
|
+
* ```
|
|
28
|
+
*/
|
|
29
|
+
export const fileToDataUri = ifExpr(exists(path('file_storage://data_base64')))
|
|
30
|
+
.then(concat(literal('data:'), coalesce(path('file_storage://file_type'), literal('image/png')), literal(';base64,'), path('file_storage://data_base64')))
|
|
31
|
+
.else(focus());
|
|
32
|
+
// Re-export SHACL types for convenience
|
|
33
|
+
export { SHACLShape, } from './SHACLShape';
|
package/package.json
CHANGED
|
@@ -5,6 +5,12 @@
|
|
|
5
5
|
"module": "lib/index.js",
|
|
6
6
|
"types": "lib/src/index.d.ts",
|
|
7
7
|
"type": "module",
|
|
8
|
+
"scripts": {
|
|
9
|
+
"build": "patch-package && tsc && pnpm run bundle",
|
|
10
|
+
"bundle": "rollup -c rollup.config.js",
|
|
11
|
+
"test": "jest --forceExit",
|
|
12
|
+
"generate:api-types": "cd ../rust-executor && TS_RS_EXPORT_DIR=../core/src/generated/api/ cargo test --lib 2>/dev/null && echo \"API types generated to core/src/generated/api/\""
|
|
13
|
+
},
|
|
8
14
|
"repository": {
|
|
9
15
|
"type": "git",
|
|
10
16
|
"url": "git+https://github.com/coasys/ad4m.git"
|
|
@@ -48,11 +54,8 @@
|
|
|
48
54
|
"ws": "8.13.0"
|
|
49
55
|
},
|
|
50
56
|
"patchedDependencies": {},
|
|
51
|
-
"
|
|
52
|
-
|
|
53
|
-
|
|
54
|
-
|
|
55
|
-
|
|
56
|
-
"generate:api-types": "cd ../rust-executor && TS_RS_EXPORT_DIR=../core/src/generated/api/ cargo test --lib 2>/dev/null && echo \"API types generated to core/src/generated/api/\""
|
|
57
|
-
}
|
|
58
|
-
}
|
|
57
|
+
"pnpm": {
|
|
58
|
+
"patchedDependencies": {}
|
|
59
|
+
},
|
|
60
|
+
"version": "0.13.0-test-8"
|
|
61
|
+
}
|
package/src/Ad4mClient.ts
CHANGED
|
@@ -29,10 +29,15 @@ export class Ad4mClient {
|
|
|
29
29
|
#runtimeClient: RuntimeClient
|
|
30
30
|
#aiClient: AIClient
|
|
31
31
|
|
|
32
|
-
constructor(
|
|
32
|
+
constructor(
|
|
33
|
+
baseUrl: string,
|
|
34
|
+
token?: string,
|
|
35
|
+
subscribe: boolean = true,
|
|
36
|
+
options?: { webSocketImpl?: new (url: string) => WebSocket; fetchImpl?: typeof fetch }
|
|
37
|
+
) {
|
|
33
38
|
this.#baseUrl = baseUrl
|
|
34
39
|
this.#token = token
|
|
35
|
-
this.#apiClient = new ApiClient(baseUrl, token)
|
|
40
|
+
this.#apiClient = new ApiClient(baseUrl, token, options?.webSocketImpl, options?.fetchImpl)
|
|
36
41
|
this.#agentClient = new AgentClient(baseUrl, token, subscribe, this.#apiClient)
|
|
37
42
|
this.#expressionClient = new ExpressionClient(baseUrl, token, this.#apiClient)
|
|
38
43
|
this.#languageClient = new LanguageClient(baseUrl, token, this.#apiClient)
|
package/src/agent/AgentClient.ts
CHANGED
|
@@ -82,6 +82,13 @@ export class AgentClient {
|
|
|
82
82
|
const agent = await this.#apiClient.call<Agent>('agent.get');
|
|
83
83
|
let agentObject = new Agent(agent.did, agent.perspective);
|
|
84
84
|
agentObject.directMessageLanguage = agent.directMessageLanguage;
|
|
85
|
+
|
|
86
|
+
// Auto-set selfDid so event-driven cache invalidation works
|
|
87
|
+
// without requiring apps to call setSelfDid() manually
|
|
88
|
+
if (agentObject.did && !this.#selfDid) {
|
|
89
|
+
this.#selfDid = agentObject.did;
|
|
90
|
+
}
|
|
91
|
+
|
|
85
92
|
return agentObject;
|
|
86
93
|
}
|
|
87
94
|
|
|
@@ -186,6 +193,14 @@ export class AgentClient {
|
|
|
186
193
|
const a = await this.#apiClient.call<Agent>('agent.updateProfile', { publicPerspective: cleanedPerspective });
|
|
187
194
|
const agent = new Agent(a.did, a.perspective);
|
|
188
195
|
agent.directMessageLanguage = a.directMessageLanguage;
|
|
196
|
+
|
|
197
|
+
// Immediately update byDID cache so subsequent byDID() calls
|
|
198
|
+
// return fresh data without waiting for the subscription event
|
|
199
|
+
if (agent.did) {
|
|
200
|
+
this.#memCache.set(agent.did, { promise: Promise.resolve(agent), ts: Date.now() });
|
|
201
|
+
this.#persistent.put(agent.did, agent); // fire-and-forget
|
|
202
|
+
}
|
|
203
|
+
|
|
189
204
|
return agent;
|
|
190
205
|
}
|
|
191
206
|
|
|
@@ -216,6 +231,14 @@ export class AgentClient {
|
|
|
216
231
|
const a = await this.#apiClient.call<Agent>('agent.updateProfile', { dmLanguage: directMessageLanguage });
|
|
217
232
|
const agent = new Agent(a.did, a.perspective);
|
|
218
233
|
agent.directMessageLanguage = a.directMessageLanguage;
|
|
234
|
+
|
|
235
|
+
// Immediately update byDID cache so subsequent byDID() calls
|
|
236
|
+
// return fresh data without waiting for the subscription event
|
|
237
|
+
if (agent.did) {
|
|
238
|
+
this.#memCache.set(agent.did, { promise: Promise.resolve(agent), ts: Date.now() });
|
|
239
|
+
this.#persistent.put(agent.did, agent); // fire-and-forget
|
|
240
|
+
}
|
|
241
|
+
|
|
219
242
|
return agent;
|
|
220
243
|
}
|
|
221
244
|
|
package/src/ai/AIClient.ts
CHANGED
|
@@ -156,7 +156,7 @@ export class AIClient {
|
|
|
156
156
|
typedAudio.byteOffset + typedAudio.byteLength
|
|
157
157
|
);
|
|
158
158
|
|
|
159
|
-
const response = await
|
|
159
|
+
const response = await this.#apiClient.doFetch(`${baseUrl}/api/v1/ai/transcription/feed`, {
|
|
160
160
|
method: 'POST',
|
|
161
161
|
headers: {
|
|
162
162
|
'Content-Type': 'application/octet-stream',
|
package/src/apiClient.ts
CHANGED
|
@@ -43,15 +43,24 @@ interface PendingCall {
|
|
|
43
43
|
export class ApiClient {
|
|
44
44
|
private baseUrl: string
|
|
45
45
|
private token?: string
|
|
46
|
+
private readonly _webSocketImpl?: new (url: string) => WebSocket
|
|
47
|
+
private readonly _fetchImpl?: typeof fetch
|
|
46
48
|
|
|
47
|
-
constructor(baseUrl: string, token?: string) {
|
|
49
|
+
constructor(baseUrl: string, token?: string, webSocketImpl?: new (url: string) => WebSocket, fetchImpl?: typeof fetch) {
|
|
48
50
|
this.baseUrl = baseUrl
|
|
49
51
|
this.token = token
|
|
52
|
+
this._webSocketImpl = webSocketImpl
|
|
53
|
+
this._fetchImpl = fetchImpl
|
|
50
54
|
}
|
|
51
55
|
|
|
52
56
|
getBaseUrl(): string { return this.baseUrl }
|
|
53
57
|
getToken(): string | undefined { return this.token }
|
|
54
58
|
|
|
59
|
+
/** Perform an HTTP request, using an injected fetch implementation if provided. */
|
|
60
|
+
doFetch(url: string, init: RequestInit): Promise<Response> {
|
|
61
|
+
return this._fetchImpl ? this._fetchImpl(url, init) : fetch(url, init)
|
|
62
|
+
}
|
|
63
|
+
|
|
55
64
|
setToken(token: string) {
|
|
56
65
|
this.token = token
|
|
57
66
|
}
|
|
@@ -78,7 +87,7 @@ export class ApiClient {
|
|
|
78
87
|
}
|
|
79
88
|
|
|
80
89
|
private _ensureWs(): void {
|
|
81
|
-
if (this._ws && (this._ws.readyState ===
|
|
90
|
+
if (this._ws && (this._ws.readyState === 1 /* OPEN */ || this._ws.readyState === 0 /* CONNECTING */)) {
|
|
82
91
|
return
|
|
83
92
|
}
|
|
84
93
|
// Prevent duplicate connections from concurrent callers
|
|
@@ -91,7 +100,8 @@ export class ApiClient {
|
|
|
91
100
|
})
|
|
92
101
|
|
|
93
102
|
const url = this._getWsUrl()
|
|
94
|
-
const
|
|
103
|
+
const WsImpl = this._webSocketImpl ?? WebSocket
|
|
104
|
+
const ws = new WsImpl(url)
|
|
95
105
|
this._ws = ws
|
|
96
106
|
|
|
97
107
|
ws.onopen = () => {
|
|
@@ -144,13 +154,14 @@ export class ApiClient {
|
|
|
144
154
|
this._wsReady = null
|
|
145
155
|
|
|
146
156
|
// Reject all pending calls
|
|
157
|
+
const hadPendingCalls = this._pendingCalls.size > 0
|
|
147
158
|
for (const [id, pending] of this._pendingCalls) {
|
|
148
159
|
clearTimeout(pending.timer)
|
|
149
160
|
pending.reject(new RpcError(503, 'WebSocket connection closed'))
|
|
150
161
|
}
|
|
151
162
|
this._pendingCalls.clear()
|
|
152
163
|
|
|
153
|
-
if (!this._wsClosed && (this._wsCallbacks.size > 0 ||
|
|
164
|
+
if (!this._wsClosed && (this._wsCallbacks.size > 0 || hadPendingCalls)) {
|
|
154
165
|
this._scheduleReconnect()
|
|
155
166
|
}
|
|
156
167
|
}
|
|
@@ -159,7 +170,7 @@ export class ApiClient {
|
|
|
159
170
|
private _startPing(): void {
|
|
160
171
|
this._stopPing()
|
|
161
172
|
this._wsPingTimer = setInterval(() => {
|
|
162
|
-
if (this._ws && this._ws.readyState ===
|
|
173
|
+
if (this._ws && this._ws.readyState === 1 /* OPEN */) {
|
|
163
174
|
this._ws.send(JSON.stringify({ type: 'ping' }))
|
|
164
175
|
}
|
|
165
176
|
}, 30_000)
|
|
@@ -219,7 +230,7 @@ export class ApiClient {
|
|
|
219
230
|
timer,
|
|
220
231
|
})
|
|
221
232
|
|
|
222
|
-
if (this._ws && this._ws.readyState ===
|
|
233
|
+
if (this._ws && this._ws.readyState === 1 /* OPEN */) {
|
|
223
234
|
this._ws.send(JSON.stringify(message))
|
|
224
235
|
} else {
|
|
225
236
|
this._pendingCalls.delete(id)
|
package/src/index.ts
CHANGED
|
@@ -16,6 +16,7 @@ export * from "./Literal";
|
|
|
16
16
|
export * from "./perspectives/Perspective";
|
|
17
17
|
export * from "./perspectives/PerspectiveHandle";
|
|
18
18
|
export * from "./perspectives/PerspectiveProxy";
|
|
19
|
+
export * from "./perspectives/SparqlBindings";
|
|
19
20
|
export * from "./perspectives/WakerSubscriptionManager";
|
|
20
21
|
export * from "./perspectives/PerspectiveDiff";
|
|
21
22
|
export * from "./perspectives/LinkQuery";
|
|
@@ -33,6 +34,9 @@ export * from "./runtime/RuntimeTypes"
|
|
|
33
34
|
export { Model as AIModel, ModelApi, TokenizerSource, LocalModel, ModelType, ModelApiInput, TokenizerSourceInput, LocalModelInput, ModelInput, VoiceActivityParamsInput } from "./ai/AITypes"
|
|
34
35
|
export * from './shacl/SHACLShape'
|
|
35
36
|
export { SHACLFlow, FlowState, FlowTransition, LinkPattern, FlowableCondition } from './shacl/SHACLFlow'
|
|
37
|
+
export * from './shacl/NodeExpression'
|
|
38
|
+
export * from './shacl/builders'
|
|
39
|
+
export { fileToDataUri } from './shacl/index'
|
|
36
40
|
export * from "./generated/api";
|
|
37
41
|
export { RpcError } from "./apiClient";
|
|
38
42
|
/** @deprecated Use `RpcError` instead. */
|