@coasys/ad4m 0.13.0-test-4 → 0.13.0-test-6
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 +1507 -1372
- package/lib/index.js +1505 -1370
- package/lib/src/Ad4mClient.d.ts +1 -1
- package/lib/src/Ad4mClient.js +12 -1
- package/lib/src/agent/AgentClient.d.ts +16 -0
- package/lib/src/agent/AgentClient.js +74 -4
- package/lib/src/cache/PersistentCache.d.ts +40 -0
- package/lib/src/cache/PersistentCache.js +139 -0
- package/lib/src/expression/ExpressionClient.d.ts +8 -0
- package/lib/src/expression/ExpressionClient.js +113 -5
- package/lib/src/index.d.ts +1 -0
- package/lib/src/index.js +1 -0
- package/lib/src/model/Ad4mModel.d.ts +20 -7
- package/lib/src/model/Ad4mModel.js +102 -108
- package/lib/src/model/Ad4mModel.test.js +688 -1434
- package/lib/src/model/ModelQueryBuilder.d.ts +6 -6
- package/lib/src/model/ModelQueryBuilder.js +29 -20
- package/lib/src/model/Subject.js +6 -6
- package/lib/src/model/hydration.d.ts +2 -39
- package/lib/src/model/hydration.js +2 -260
- package/lib/src/model/query-surreal.d.ts +44 -0
- package/lib/src/model/query-surreal.js +249 -0
- package/lib/src/model/query-utils.d.ts +1 -0
- package/lib/src/model/query-utils.js +46 -1
- package/lib/src/model/relation-filtering.test.js +15 -15
- 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 +4 -6
- package/lib/src/perspectives/PerspectiveClient.d.ts +1 -1
- package/lib/src/perspectives/PerspectiveClient.js +15 -13
- package/lib/src/perspectives/PerspectiveProxy.d.ts +14 -0
- package/lib/src/perspectives/PerspectiveProxy.js +16 -3
- package/lib/src/perspectives/PerspectiveResolver.d.ts +1 -0
- package/lib/src/perspectives/PerspectiveResolver.js +11 -0
- package/lib/src/runtime/RuntimeResolver.d.ts +1 -28
- package/lib/src/runtime/RuntimeResolver.js +4 -197
- package/lib/src/schema.gql +1 -27
- package/lib/src/shacl/SHACLShape.test.js +0 -82
- package/package.json +11 -8
- package/src/Ad4mClient.test.ts +14 -4
- package/src/Ad4mClient.ts +12 -1
- package/src/agent/AgentClient.ts +84 -2
- package/src/cache/PersistentCache.ts +145 -0
- package/src/cache/cache.test.ts +713 -0
- package/src/expression/ExpressionClient.ts +137 -3
- package/src/index.ts +1 -0
- package/src/model/Ad4mModel.test.ts +59 -358
- package/src/model/Ad4mModel.ts +112 -108
- package/src/model/ModelQueryBuilder.ts +29 -17
- package/src/model/hydration.ts +2 -279
- package/src/model/query-utils.ts +47 -2
- package/src/model/types.ts +5 -6
- package/src/perspectives/PerspectiveClient.ts +26 -17
- package/src/perspectives/PerspectiveProxy.ts +24 -3
- package/lib/src/model/hydration-batch.d.ts +0 -34
- package/lib/src/model/hydration-batch.js +0 -147
- package/lib/src/model/hydration-batching.test.d.ts +0 -7
- package/lib/src/model/hydration-batching.test.js +0 -456
- package/lib/src/model/model-manifest.d.ts +0 -41
- package/lib/src/model/model-manifest.js +0 -11
- package/lib/src/model/query-cache.test.d.ts +0 -1
- package/lib/src/model/query-cache.test.js +0 -43
- package/lib/src/model/query-sparql-batch.d.ts +0 -17
- package/lib/src/model/query-sparql-batch.js +0 -260
- package/lib/src/model/query-sparql.test.d.ts +0 -1
- package/lib/src/model/query-sparql.test.js +0 -312
- package/lib/src/model/subscription-delta.test.d.ts +0 -24
- package/lib/src/model/subscription-delta.test.js +0 -180
- package/lib/src/model/subscription-pool.d.ts +0 -39
- package/lib/src/model/subscription-pool.js +0 -165
- package/lib/src/perspectives/PerspectiveClient.test.d.ts +0 -1
- package/lib/src/perspectives/PerspectiveClient.test.js +0 -224
package/lib/index.js
CHANGED
|
@@ -551,13 +551,13 @@ class AgentStatus {
|
|
|
551
551
|
}
|
|
552
552
|
}
|
|
553
553
|
|
|
554
|
-
var __classPrivateFieldSet$
|
|
554
|
+
var __classPrivateFieldSet$c = (undefined && undefined.__classPrivateFieldSet) || function (receiver, state, value, kind, f) {
|
|
555
555
|
if (kind === "m") throw new TypeError("Private method is not writable");
|
|
556
556
|
if (kind === "a" && !f) throw new TypeError("Private accessor was defined without a setter");
|
|
557
557
|
if (typeof state === "function" ? receiver !== state || !f : !state.has(receiver)) throw new TypeError("Cannot write private member to an object whose class did not declare it");
|
|
558
558
|
return (kind === "a" ? f.call(receiver, value) : f ? f.value = value : state.set(receiver, value)), value;
|
|
559
559
|
};
|
|
560
|
-
var __classPrivateFieldGet$
|
|
560
|
+
var __classPrivateFieldGet$c = (undefined && undefined.__classPrivateFieldGet) || function (receiver, state, kind, f) {
|
|
561
561
|
if (kind === "a" && !f) throw new TypeError("Private accessor was defined without a getter");
|
|
562
562
|
if (typeof state === "function" ? receiver !== state || !f : !state.has(receiver)) throw new TypeError("Cannot read private member from an object whose class did not declare it");
|
|
563
563
|
return kind === "m" ? f : kind === "a" ? f.call(receiver) : f ? f.value : state.get(receiver);
|
|
@@ -567,41 +567,41 @@ class NeighbourhoodProxy {
|
|
|
567
567
|
constructor(client, pID) {
|
|
568
568
|
_NeighbourhoodProxy_client.set(this, void 0);
|
|
569
569
|
_NeighbourhoodProxy_pID.set(this, void 0);
|
|
570
|
-
__classPrivateFieldSet$
|
|
571
|
-
__classPrivateFieldSet$
|
|
570
|
+
__classPrivateFieldSet$c(this, _NeighbourhoodProxy_client, client, "f");
|
|
571
|
+
__classPrivateFieldSet$c(this, _NeighbourhoodProxy_pID, pID, "f");
|
|
572
572
|
}
|
|
573
573
|
async otherAgents() {
|
|
574
|
-
return await __classPrivateFieldGet$
|
|
574
|
+
return await __classPrivateFieldGet$c(this, _NeighbourhoodProxy_client, "f").otherAgents(__classPrivateFieldGet$c(this, _NeighbourhoodProxy_pID, "f"));
|
|
575
575
|
}
|
|
576
576
|
async hasTelepresenceAdapter() {
|
|
577
|
-
return await __classPrivateFieldGet$
|
|
577
|
+
return await __classPrivateFieldGet$c(this, _NeighbourhoodProxy_client, "f").hasTelepresenceAdapter(__classPrivateFieldGet$c(this, _NeighbourhoodProxy_pID, "f"));
|
|
578
578
|
}
|
|
579
579
|
async onlineAgents() {
|
|
580
|
-
return await __classPrivateFieldGet$
|
|
580
|
+
return await __classPrivateFieldGet$c(this, _NeighbourhoodProxy_client, "f").onlineAgents(__classPrivateFieldGet$c(this, _NeighbourhoodProxy_pID, "f"));
|
|
581
581
|
}
|
|
582
582
|
async setOnlineStatus(status) {
|
|
583
|
-
return await __classPrivateFieldGet$
|
|
583
|
+
return await __classPrivateFieldGet$c(this, _NeighbourhoodProxy_client, "f").setOnlineStatus(__classPrivateFieldGet$c(this, _NeighbourhoodProxy_pID, "f"), status);
|
|
584
584
|
}
|
|
585
585
|
async setOnlineStatusU(status) {
|
|
586
|
-
return await __classPrivateFieldGet$
|
|
586
|
+
return await __classPrivateFieldGet$c(this, _NeighbourhoodProxy_client, "f").setOnlineStatusU(__classPrivateFieldGet$c(this, _NeighbourhoodProxy_pID, "f"), status);
|
|
587
587
|
}
|
|
588
588
|
async sendSignal(remoteAgentDid, payload) {
|
|
589
|
-
return await __classPrivateFieldGet$
|
|
589
|
+
return await __classPrivateFieldGet$c(this, _NeighbourhoodProxy_client, "f").sendSignal(__classPrivateFieldGet$c(this, _NeighbourhoodProxy_pID, "f"), remoteAgentDid, payload);
|
|
590
590
|
}
|
|
591
591
|
async sendSignalU(remoteAgentDid, payload) {
|
|
592
|
-
return await __classPrivateFieldGet$
|
|
592
|
+
return await __classPrivateFieldGet$c(this, _NeighbourhoodProxy_client, "f").sendSignalU(__classPrivateFieldGet$c(this, _NeighbourhoodProxy_pID, "f"), remoteAgentDid, payload);
|
|
593
593
|
}
|
|
594
594
|
async sendBroadcast(payload, loopback = false) {
|
|
595
|
-
return await __classPrivateFieldGet$
|
|
595
|
+
return await __classPrivateFieldGet$c(this, _NeighbourhoodProxy_client, "f").sendBroadcast(__classPrivateFieldGet$c(this, _NeighbourhoodProxy_pID, "f"), payload, loopback);
|
|
596
596
|
}
|
|
597
597
|
async sendBroadcastU(payload, loopback = false) {
|
|
598
|
-
return await __classPrivateFieldGet$
|
|
598
|
+
return await __classPrivateFieldGet$c(this, _NeighbourhoodProxy_client, "f").sendBroadcastU(__classPrivateFieldGet$c(this, _NeighbourhoodProxy_pID, "f"), payload, loopback);
|
|
599
599
|
}
|
|
600
600
|
async addSignalHandler(handler) {
|
|
601
|
-
await __classPrivateFieldGet$
|
|
601
|
+
await __classPrivateFieldGet$c(this, _NeighbourhoodProxy_client, "f").addSignalHandler(__classPrivateFieldGet$c(this, _NeighbourhoodProxy_pID, "f"), handler);
|
|
602
602
|
}
|
|
603
603
|
removeSignalHandler(handler) {
|
|
604
|
-
__classPrivateFieldGet$
|
|
604
|
+
__classPrivateFieldGet$c(this, _NeighbourhoodProxy_client, "f").removeSignalHandler(__classPrivateFieldGet$c(this, _NeighbourhoodProxy_pID, "f"), handler);
|
|
605
605
|
}
|
|
606
606
|
}
|
|
607
607
|
_NeighbourhoodProxy_client = new WeakMap(), _NeighbourhoodProxy_pID = new WeakMap();
|
|
@@ -695,13 +695,13 @@ class LinkQuery {
|
|
|
695
695
|
}
|
|
696
696
|
}
|
|
697
697
|
|
|
698
|
-
var __classPrivateFieldSet$
|
|
698
|
+
var __classPrivateFieldSet$b = (undefined && undefined.__classPrivateFieldSet) || function (receiver, state, value, kind, f) {
|
|
699
699
|
if (kind === "m") throw new TypeError("Private method is not writable");
|
|
700
700
|
if (kind === "a" && !f) throw new TypeError("Private accessor was defined without a setter");
|
|
701
701
|
if (typeof state === "function" ? receiver !== state || !f : !state.has(receiver)) throw new TypeError("Cannot write private member to an object whose class did not declare it");
|
|
702
702
|
return (kind === "a" ? f.call(receiver, value) : f ? f.value = value : state.set(receiver, value)), value;
|
|
703
703
|
};
|
|
704
|
-
var __classPrivateFieldGet$
|
|
704
|
+
var __classPrivateFieldGet$b = (undefined && undefined.__classPrivateFieldGet) || function (receiver, state, kind, f) {
|
|
705
705
|
if (kind === "a" && !f) throw new TypeError("Private accessor was defined without a getter");
|
|
706
706
|
if (typeof state === "function" ? receiver !== state || !f : !state.has(receiver)) throw new TypeError("Cannot read private member from an object whose class did not declare it");
|
|
707
707
|
return kind === "m" ? f : kind === "a" ? f.call(receiver) : f ? f.value : state.get(receiver);
|
|
@@ -722,44 +722,44 @@ class Literal {
|
|
|
722
722
|
if (url.startsWith("literal://"))
|
|
723
723
|
throw new Error("literal:// format is no longer supported. Use literal: instead.");
|
|
724
724
|
const l = new Literal();
|
|
725
|
-
__classPrivateFieldSet$
|
|
725
|
+
__classPrivateFieldSet$b(l, _Literal_url, url, "f");
|
|
726
726
|
return l;
|
|
727
727
|
}
|
|
728
728
|
static from(literal) {
|
|
729
729
|
const l = new Literal();
|
|
730
|
-
__classPrivateFieldSet$
|
|
730
|
+
__classPrivateFieldSet$b(l, _Literal_literal, literal, "f");
|
|
731
731
|
return l;
|
|
732
732
|
}
|
|
733
733
|
toUrl() {
|
|
734
|
-
if (__classPrivateFieldGet$
|
|
735
|
-
return __classPrivateFieldGet$
|
|
736
|
-
if (!__classPrivateFieldGet$
|
|
734
|
+
if (__classPrivateFieldGet$b(this, _Literal_url, "f") && !__classPrivateFieldGet$b(this, _Literal_literal, "f"))
|
|
735
|
+
return __classPrivateFieldGet$b(this, _Literal_url, "f");
|
|
736
|
+
if (!__classPrivateFieldGet$b(this, _Literal_url, "f") && (__classPrivateFieldGet$b(this, _Literal_literal, "f") === undefined || __classPrivateFieldGet$b(this, _Literal_literal, "f") === "" || __classPrivateFieldGet$b(this, _Literal_literal, "f") === null))
|
|
737
737
|
throw new Error("Can't turn empty Literal into URL");
|
|
738
738
|
let encoded;
|
|
739
|
-
switch (typeof __classPrivateFieldGet$
|
|
739
|
+
switch (typeof __classPrivateFieldGet$b(this, _Literal_literal, "f")) {
|
|
740
740
|
case 'string':
|
|
741
|
-
encoded = `string:${encodeRFC3986URIComponent(__classPrivateFieldGet$
|
|
741
|
+
encoded = `string:${encodeRFC3986URIComponent(__classPrivateFieldGet$b(this, _Literal_literal, "f"))}`;
|
|
742
742
|
break;
|
|
743
743
|
case 'number':
|
|
744
|
-
encoded = `number:${encodeRFC3986URIComponent(__classPrivateFieldGet$
|
|
744
|
+
encoded = `number:${encodeRFC3986URIComponent(__classPrivateFieldGet$b(this, _Literal_literal, "f"))}`;
|
|
745
745
|
break;
|
|
746
746
|
case 'boolean':
|
|
747
|
-
encoded = `boolean:${encodeRFC3986URIComponent(__classPrivateFieldGet$
|
|
747
|
+
encoded = `boolean:${encodeRFC3986URIComponent(__classPrivateFieldGet$b(this, _Literal_literal, "f"))}`;
|
|
748
748
|
break;
|
|
749
749
|
case 'object':
|
|
750
|
-
encoded = `json:${encodeRFC3986URIComponent(JSON.stringify(__classPrivateFieldGet$
|
|
750
|
+
encoded = `json:${encodeRFC3986URIComponent(JSON.stringify(__classPrivateFieldGet$b(this, _Literal_literal, "f")))}`;
|
|
751
751
|
break;
|
|
752
752
|
}
|
|
753
753
|
return `literal:${encoded}`;
|
|
754
754
|
}
|
|
755
755
|
get() {
|
|
756
|
-
if (__classPrivateFieldGet$
|
|
757
|
-
return __classPrivateFieldGet$
|
|
758
|
-
if (!__classPrivateFieldGet$
|
|
756
|
+
if (__classPrivateFieldGet$b(this, _Literal_literal, "f"))
|
|
757
|
+
return __classPrivateFieldGet$b(this, _Literal_literal, "f");
|
|
758
|
+
if (!__classPrivateFieldGet$b(this, _Literal_url, "f"))
|
|
759
759
|
throw new Error("Can't render empty Literal");
|
|
760
|
-
if (!__classPrivateFieldGet$
|
|
760
|
+
if (!__classPrivateFieldGet$b(this, _Literal_url, "f").startsWith("literal:"))
|
|
761
761
|
throw new Error("Can't render Literal from non-literal URL");
|
|
762
|
-
const body = __classPrivateFieldGet$
|
|
762
|
+
const body = __classPrivateFieldGet$b(this, _Literal_url, "f").substring(8);
|
|
763
763
|
if (body.startsWith("string:")) {
|
|
764
764
|
return decodeURIComponent(body.substring(7));
|
|
765
765
|
}
|
|
@@ -1715,6 +1715,7 @@ function buildWhereCondition(predicate, condition, opts) {
|
|
|
1715
1715
|
// For literal-resolved properties, values are stored as IRIs like <literal:string:VALUE>
|
|
1716
1716
|
// For language-resolved properties, values are plain URIs
|
|
1717
1717
|
const isLiteral = !opts?.resolveLanguage || opts.resolveLanguage === 'literal';
|
|
1718
|
+
const varSuffix = opts?.varIndex ?? 0;
|
|
1718
1719
|
function formatValue(v) {
|
|
1719
1720
|
if (typeof v === 'string') {
|
|
1720
1721
|
return isLiteral
|
|
@@ -1724,8 +1725,46 @@ function buildWhereCondition(predicate, condition, opts) {
|
|
|
1724
1725
|
// Numbers/booleans — also stored as literal:string: in AD4M
|
|
1725
1726
|
return `<literal:string:${v}>`;
|
|
1726
1727
|
}
|
|
1728
|
+
/**
|
|
1729
|
+
* For literal properties, generate a FILTER-based match that handles both
|
|
1730
|
+
* the raw value and the literal-encoded value. This mirrors the Rust
|
|
1731
|
+
* `build_projection_where_patterns` approach which uses:
|
|
1732
|
+
* FILTER(STR(?var) = "value" || STR(?var) = "literal:string:encodedValue")
|
|
1733
|
+
* This is more robust than exact IRI matching because it handles edge cases
|
|
1734
|
+
* where the stored format might vary.
|
|
1735
|
+
*/
|
|
1736
|
+
function formatLiteralFilter(varName, v) {
|
|
1737
|
+
const raw = escapeQueryString(String(v));
|
|
1738
|
+
const encoded = encodeURIComponent(String(v))
|
|
1739
|
+
.replace(/!/g, '%21')
|
|
1740
|
+
.replace(/'/g, '%27')
|
|
1741
|
+
.replace(/\(/g, '%28')
|
|
1742
|
+
.replace(/\)/g, '%29')
|
|
1743
|
+
.replace(/\*/g, '%2A');
|
|
1744
|
+
if (typeof v === 'string') {
|
|
1745
|
+
return `FILTER(STR(${varName}) = "${raw}" || STR(${varName}) = "literal:string:${encoded}")`;
|
|
1746
|
+
}
|
|
1747
|
+
else if (typeof v === 'number') {
|
|
1748
|
+
return `FILTER(STR(${varName}) = "${v}" || STR(${varName}) = "literal:number:${v}")`;
|
|
1749
|
+
}
|
|
1750
|
+
else if (typeof v === 'boolean') {
|
|
1751
|
+
return `FILTER(STR(${varName}) = "${v}" || STR(${varName}) = "literal:boolean:${v}")`;
|
|
1752
|
+
}
|
|
1753
|
+
return `FILTER(STR(${varName}) = "${raw}")`;
|
|
1754
|
+
}
|
|
1727
1755
|
if (Array.isArray(condition)) {
|
|
1728
1756
|
// Array values → FILTER IN
|
|
1757
|
+
if (isLiteral) {
|
|
1758
|
+
const varName = `?_wc${varSuffix}`;
|
|
1759
|
+
const inValues = condition.flatMap(v => {
|
|
1760
|
+
const raw = escapeQueryString(String(v));
|
|
1761
|
+
const encoded = encodeURIComponent(String(v))
|
|
1762
|
+
.replace(/!/g, '%21').replace(/'/g, '%27')
|
|
1763
|
+
.replace(/\(/g, '%28').replace(/\)/g, '%29').replace(/\*/g, '%2A');
|
|
1764
|
+
return [`"${raw}"`, `"literal:string:${encoded}"`];
|
|
1765
|
+
}).join(', ');
|
|
1766
|
+
return `?target <${escapedPredicate}> ${varName} . FILTER(STR(${varName}) IN (${inValues}))`;
|
|
1767
|
+
}
|
|
1729
1768
|
const formattedValues = condition.map(formatValue).join(', ');
|
|
1730
1769
|
return `FILTER EXISTS { ?target <${escapedPredicate}> ?_val . FILTER(?_val IN (${formattedValues})) }`;
|
|
1731
1770
|
}
|
|
@@ -1757,6 +1796,12 @@ function buildWhereCondition(predicate, condition, opts) {
|
|
|
1757
1796
|
}
|
|
1758
1797
|
else {
|
|
1759
1798
|
// Simple equality
|
|
1799
|
+
if (isLiteral) {
|
|
1800
|
+
// Use FILTER matching (mirrors Rust build_projection_where_patterns)
|
|
1801
|
+
// to handle both raw values and literal-encoded IRIs robustly.
|
|
1802
|
+
const varName = `?_wc${varSuffix}`;
|
|
1803
|
+
return `?target <${escapedPredicate}> ${varName} . ${formatLiteralFilter(varName, condition)}`;
|
|
1804
|
+
}
|
|
1760
1805
|
return `?target <${escapedPredicate}> ${formatValue(condition)} .`;
|
|
1761
1806
|
}
|
|
1762
1807
|
}
|
|
@@ -1794,7 +1839,7 @@ function compileWhereClause(where, metadata) {
|
|
|
1794
1839
|
// No metadata — treat name as raw predicate URI
|
|
1795
1840
|
predicate = propertyName;
|
|
1796
1841
|
}
|
|
1797
|
-
const cond = buildWhereCondition(predicate, condition, { resolveLanguage });
|
|
1842
|
+
const cond = buildWhereCondition(predicate, condition, { resolveLanguage, varIndex: conditions.length });
|
|
1798
1843
|
if (cond) {
|
|
1799
1844
|
conditions.push(cond);
|
|
1800
1845
|
}
|
|
@@ -3161,13 +3206,13 @@ class SHACLFlow {
|
|
|
3161
3206
|
}
|
|
3162
3207
|
}
|
|
3163
3208
|
|
|
3164
|
-
var __classPrivateFieldSet$
|
|
3209
|
+
var __classPrivateFieldSet$a = (undefined && undefined.__classPrivateFieldSet) || function (receiver, state, value, kind, f) {
|
|
3165
3210
|
if (kind === "m") throw new TypeError("Private method is not writable");
|
|
3166
3211
|
if (kind === "a" && !f) throw new TypeError("Private accessor was defined without a setter");
|
|
3167
3212
|
if (typeof state === "function" ? receiver !== state || !f : !state.has(receiver)) throw new TypeError("Cannot write private member to an object whose class did not declare it");
|
|
3168
3213
|
return (kind === "a" ? f.call(receiver, value) : f ? f.value = value : state.set(receiver, value)), value;
|
|
3169
3214
|
};
|
|
3170
|
-
var __classPrivateFieldGet$
|
|
3215
|
+
var __classPrivateFieldGet$a = (undefined && undefined.__classPrivateFieldGet) || function (receiver, state, kind, f) {
|
|
3171
3216
|
if (kind === "a" && !f) throw new TypeError("Private accessor was defined without a getter");
|
|
3172
3217
|
if (typeof state === "function" ? receiver !== state || !f : !state.has(receiver)) throw new TypeError("Cannot read private member from an object whose class did not declare it");
|
|
3173
3218
|
return kind === "m" ? f : kind === "a" ? f.call(receiver) : f ? f.value : state.get(receiver);
|
|
@@ -3240,56 +3285,56 @@ class QuerySubscriptionProxy {
|
|
|
3240
3285
|
_QuerySubscriptionProxy_initReject.set(this, void 0);
|
|
3241
3286
|
_QuerySubscriptionProxy_initTimeoutId.set(this, void 0);
|
|
3242
3287
|
_QuerySubscriptionProxy_query.set(this, void 0);
|
|
3243
|
-
__classPrivateFieldSet$
|
|
3244
|
-
__classPrivateFieldSet$
|
|
3245
|
-
__classPrivateFieldSet$
|
|
3246
|
-
__classPrivateFieldSet$
|
|
3247
|
-
__classPrivateFieldSet$
|
|
3288
|
+
__classPrivateFieldSet$a(this, _QuerySubscriptionProxy_uuid, uuid, "f");
|
|
3289
|
+
__classPrivateFieldSet$a(this, _QuerySubscriptionProxy_query, query, "f");
|
|
3290
|
+
__classPrivateFieldSet$a(this, _QuerySubscriptionProxy_client, client, "f");
|
|
3291
|
+
__classPrivateFieldSet$a(this, _QuerySubscriptionProxy_callbacks, new Set(), "f");
|
|
3292
|
+
__classPrivateFieldSet$a(this, _QuerySubscriptionProxy_latestResult, null, "f");
|
|
3248
3293
|
// Create the promise once and store its resolve/reject
|
|
3249
|
-
__classPrivateFieldSet$
|
|
3250
|
-
__classPrivateFieldSet$
|
|
3251
|
-
__classPrivateFieldSet$
|
|
3294
|
+
__classPrivateFieldSet$a(this, _QuerySubscriptionProxy_initialized, new Promise((resolve, reject) => {
|
|
3295
|
+
__classPrivateFieldSet$a(this, _QuerySubscriptionProxy_initResolve, resolve, "f");
|
|
3296
|
+
__classPrivateFieldSet$a(this, _QuerySubscriptionProxy_initReject, reject, "f");
|
|
3252
3297
|
}), "f");
|
|
3253
3298
|
}
|
|
3254
3299
|
async subscribe() {
|
|
3255
3300
|
// Clean up previous subscription attempt if retrying
|
|
3256
|
-
if (__classPrivateFieldGet$
|
|
3257
|
-
__classPrivateFieldGet$
|
|
3258
|
-
__classPrivateFieldSet$
|
|
3301
|
+
if (__classPrivateFieldGet$a(this, _QuerySubscriptionProxy_unsubscribe, "f")) {
|
|
3302
|
+
__classPrivateFieldGet$a(this, _QuerySubscriptionProxy_unsubscribe, "f").call(this);
|
|
3303
|
+
__classPrivateFieldSet$a(this, _QuerySubscriptionProxy_unsubscribe, undefined, "f");
|
|
3259
3304
|
}
|
|
3260
3305
|
// Clear any existing timeout
|
|
3261
|
-
if (__classPrivateFieldGet$
|
|
3262
|
-
clearTimeout(__classPrivateFieldGet$
|
|
3263
|
-
__classPrivateFieldSet$
|
|
3306
|
+
if (__classPrivateFieldGet$a(this, _QuerySubscriptionProxy_initTimeoutId, "f")) {
|
|
3307
|
+
clearTimeout(__classPrivateFieldGet$a(this, _QuerySubscriptionProxy_initTimeoutId, "f"));
|
|
3308
|
+
__classPrivateFieldSet$a(this, _QuerySubscriptionProxy_initTimeoutId, undefined, "f");
|
|
3264
3309
|
}
|
|
3265
3310
|
// Clear any existing keepalive timer to prevent accumulation
|
|
3266
|
-
if (__classPrivateFieldGet$
|
|
3267
|
-
clearTimeout(__classPrivateFieldGet$
|
|
3268
|
-
__classPrivateFieldSet$
|
|
3311
|
+
if (__classPrivateFieldGet$a(this, _QuerySubscriptionProxy_keepaliveTimer, "f")) {
|
|
3312
|
+
clearTimeout(__classPrivateFieldGet$a(this, _QuerySubscriptionProxy_keepaliveTimer, "f"));
|
|
3313
|
+
__classPrivateFieldSet$a(this, _QuerySubscriptionProxy_keepaliveTimer, undefined, "f");
|
|
3269
3314
|
}
|
|
3270
3315
|
try {
|
|
3271
3316
|
// Initialize the query subscription
|
|
3272
3317
|
let initialResult;
|
|
3273
|
-
initialResult = await __classPrivateFieldGet$
|
|
3274
|
-
__classPrivateFieldSet$
|
|
3318
|
+
initialResult = await __classPrivateFieldGet$a(this, _QuerySubscriptionProxy_client, "f").subscribeQuery(__classPrivateFieldGet$a(this, _QuerySubscriptionProxy_uuid, "f"), __classPrivateFieldGet$a(this, _QuerySubscriptionProxy_query, "f"));
|
|
3319
|
+
__classPrivateFieldSet$a(this, _QuerySubscriptionProxy_subscriptionId, initialResult.subscriptionId, "f");
|
|
3275
3320
|
// Process the initial result immediately for fast UX.
|
|
3276
3321
|
// The subscribeQuery() RPC call already returns the initial result,
|
|
3277
3322
|
// so treat that as successful initialization instead of waiting for a
|
|
3278
3323
|
// follow-up WebSocket update that may never arrive until the query changes.
|
|
3279
3324
|
if (initialResult.result !== undefined) {
|
|
3280
|
-
__classPrivateFieldSet$
|
|
3281
|
-
__classPrivateFieldGet$
|
|
3282
|
-
if (__classPrivateFieldGet$
|
|
3283
|
-
__classPrivateFieldGet$
|
|
3284
|
-
__classPrivateFieldSet$
|
|
3285
|
-
__classPrivateFieldSet$
|
|
3325
|
+
__classPrivateFieldSet$a(this, _QuerySubscriptionProxy_latestResult, initialResult.result, "f");
|
|
3326
|
+
__classPrivateFieldGet$a(this, _QuerySubscriptionProxy_instances, "m", _QuerySubscriptionProxy_notifyCallbacks).call(this, initialResult.result);
|
|
3327
|
+
if (__classPrivateFieldGet$a(this, _QuerySubscriptionProxy_initResolve, "f")) {
|
|
3328
|
+
__classPrivateFieldGet$a(this, _QuerySubscriptionProxy_initResolve, "f").call(this, true);
|
|
3329
|
+
__classPrivateFieldSet$a(this, _QuerySubscriptionProxy_initResolve, undefined, "f");
|
|
3330
|
+
__classPrivateFieldSet$a(this, _QuerySubscriptionProxy_initReject, undefined, "f");
|
|
3286
3331
|
}
|
|
3287
3332
|
}
|
|
3288
3333
|
else {
|
|
3289
3334
|
console.warn('⚠️ No initial result returned from subscribeQuery!');
|
|
3290
3335
|
// Only keep the initialization timeout when the backend did not
|
|
3291
3336
|
// provide an initial result up front.
|
|
3292
|
-
__classPrivateFieldSet$
|
|
3337
|
+
__classPrivateFieldSet$a(this, _QuerySubscriptionProxy_initTimeoutId, setTimeout(() => {
|
|
3293
3338
|
console.error('Subscription initialization timed out after 30 seconds. Resubscribing...');
|
|
3294
3339
|
// Recursively retry subscription, catching any errors
|
|
3295
3340
|
this.subscribe().catch(error => {
|
|
@@ -3298,46 +3343,43 @@ class QuerySubscriptionProxy {
|
|
|
3298
3343
|
}, 30000), "f");
|
|
3299
3344
|
}
|
|
3300
3345
|
// Subscribe to query updates
|
|
3301
|
-
__classPrivateFieldSet$
|
|
3346
|
+
__classPrivateFieldSet$a(this, _QuerySubscriptionProxy_unsubscribe, __classPrivateFieldGet$a(this, _QuerySubscriptionProxy_client, "f").subscribeToQueryUpdates(__classPrivateFieldGet$a(this, _QuerySubscriptionProxy_subscriptionId, "f"), (updateResult) => {
|
|
3302
3347
|
// Clear timeout on first message
|
|
3303
|
-
if (__classPrivateFieldGet$
|
|
3304
|
-
clearTimeout(__classPrivateFieldGet$
|
|
3305
|
-
__classPrivateFieldSet$
|
|
3348
|
+
if (__classPrivateFieldGet$a(this, _QuerySubscriptionProxy_initTimeoutId, "f")) {
|
|
3349
|
+
clearTimeout(__classPrivateFieldGet$a(this, _QuerySubscriptionProxy_initTimeoutId, "f"));
|
|
3350
|
+
__classPrivateFieldSet$a(this, _QuerySubscriptionProxy_initTimeoutId, undefined, "f");
|
|
3306
3351
|
}
|
|
3307
3352
|
// Resolve the initialization promise (only resolves once)
|
|
3308
|
-
if (__classPrivateFieldGet$
|
|
3309
|
-
__classPrivateFieldGet$
|
|
3310
|
-
__classPrivateFieldSet$
|
|
3311
|
-
__classPrivateFieldSet$
|
|
3353
|
+
if (__classPrivateFieldGet$a(this, _QuerySubscriptionProxy_initResolve, "f")) {
|
|
3354
|
+
__classPrivateFieldGet$a(this, _QuerySubscriptionProxy_initResolve, "f").call(this, true);
|
|
3355
|
+
__classPrivateFieldSet$a(this, _QuerySubscriptionProxy_initResolve, undefined, "f"); // Prevent double-resolve
|
|
3356
|
+
__classPrivateFieldSet$a(this, _QuerySubscriptionProxy_initReject, undefined, "f");
|
|
3312
3357
|
}
|
|
3313
|
-
|
|
3314
|
-
|
|
3315
|
-
return;
|
|
3316
|
-
__classPrivateFieldSet$9(this, _QuerySubscriptionProxy_latestResult, updateResult, "f");
|
|
3317
|
-
__classPrivateFieldGet$9(this, _QuerySubscriptionProxy_instances, "m", _QuerySubscriptionProxy_notifyCallbacks).call(this, updateResult);
|
|
3358
|
+
__classPrivateFieldSet$a(this, _QuerySubscriptionProxy_latestResult, updateResult, "f");
|
|
3359
|
+
__classPrivateFieldGet$a(this, _QuerySubscriptionProxy_instances, "m", _QuerySubscriptionProxy_notifyCallbacks).call(this, updateResult);
|
|
3318
3360
|
}), "f");
|
|
3319
3361
|
}
|
|
3320
3362
|
catch (error) {
|
|
3321
3363
|
console.error('Error setting up subscription:', error);
|
|
3322
3364
|
// Reject the promise if this is the first attempt
|
|
3323
|
-
if (__classPrivateFieldGet$
|
|
3324
|
-
__classPrivateFieldGet$
|
|
3325
|
-
__classPrivateFieldSet$
|
|
3326
|
-
__classPrivateFieldSet$
|
|
3365
|
+
if (__classPrivateFieldGet$a(this, _QuerySubscriptionProxy_initReject, "f")) {
|
|
3366
|
+
__classPrivateFieldGet$a(this, _QuerySubscriptionProxy_initReject, "f").call(this, error);
|
|
3367
|
+
__classPrivateFieldSet$a(this, _QuerySubscriptionProxy_initResolve, undefined, "f");
|
|
3368
|
+
__classPrivateFieldSet$a(this, _QuerySubscriptionProxy_initReject, undefined, "f");
|
|
3327
3369
|
}
|
|
3328
3370
|
throw error; // Re-throw so caller knows it failed
|
|
3329
3371
|
}
|
|
3330
3372
|
// Start keepalive loop using platform-agnostic setTimeout
|
|
3331
3373
|
const keepaliveLoop = async () => {
|
|
3332
|
-
if (__classPrivateFieldGet$
|
|
3374
|
+
if (__classPrivateFieldGet$a(this, _QuerySubscriptionProxy_disposed, "f"))
|
|
3333
3375
|
return;
|
|
3334
3376
|
try {
|
|
3335
|
-
await __classPrivateFieldGet$
|
|
3377
|
+
await __classPrivateFieldGet$a(this, _QuerySubscriptionProxy_client, "f").keepAliveQuery(__classPrivateFieldGet$a(this, _QuerySubscriptionProxy_uuid, "f"), __classPrivateFieldGet$a(this, _QuerySubscriptionProxy_subscriptionId, "f"));
|
|
3336
3378
|
}
|
|
3337
3379
|
catch (e) {
|
|
3338
3380
|
console.error('Error in keepalive:', e);
|
|
3339
3381
|
// try to reinitialize the subscription
|
|
3340
|
-
console.log('Reinitializing subscription for query:', __classPrivateFieldGet$
|
|
3382
|
+
console.log('Reinitializing subscription for query:', __classPrivateFieldGet$a(this, _QuerySubscriptionProxy_query, "f"));
|
|
3341
3383
|
try {
|
|
3342
3384
|
await this.subscribe();
|
|
3343
3385
|
console.log('Subscription reinitialized');
|
|
@@ -3349,12 +3391,12 @@ class QuerySubscriptionProxy {
|
|
|
3349
3391
|
}
|
|
3350
3392
|
}
|
|
3351
3393
|
// Schedule next keepalive if not disposed
|
|
3352
|
-
if (!__classPrivateFieldGet$
|
|
3353
|
-
__classPrivateFieldSet$
|
|
3394
|
+
if (!__classPrivateFieldGet$a(this, _QuerySubscriptionProxy_disposed, "f")) {
|
|
3395
|
+
__classPrivateFieldSet$a(this, _QuerySubscriptionProxy_keepaliveTimer, setTimeout(keepaliveLoop, 30000), "f");
|
|
3354
3396
|
}
|
|
3355
3397
|
};
|
|
3356
3398
|
// Start the first keepalive loop
|
|
3357
|
-
__classPrivateFieldSet$
|
|
3399
|
+
__classPrivateFieldSet$a(this, _QuerySubscriptionProxy_keepaliveTimer, setTimeout(keepaliveLoop, 30000), "f");
|
|
3358
3400
|
}
|
|
3359
3401
|
/** Get the subscription ID for this query subscription
|
|
3360
3402
|
*
|
|
@@ -3365,7 +3407,7 @@ class QuerySubscriptionProxy {
|
|
|
3365
3407
|
* @returns The subscription ID string
|
|
3366
3408
|
*/
|
|
3367
3409
|
get id() {
|
|
3368
|
-
return __classPrivateFieldGet$
|
|
3410
|
+
return __classPrivateFieldGet$a(this, _QuerySubscriptionProxy_subscriptionId, "f");
|
|
3369
3411
|
}
|
|
3370
3412
|
/** Promise that resolves when the subscription has received its first result
|
|
3371
3413
|
* through the subscription channel. This ensures the subscription is fully
|
|
@@ -3379,7 +3421,7 @@ class QuerySubscriptionProxy {
|
|
|
3379
3421
|
* creation methods (like subscribeInfer) already wait for initialization.
|
|
3380
3422
|
*/
|
|
3381
3423
|
get initialized() {
|
|
3382
|
-
return __classPrivateFieldGet$
|
|
3424
|
+
return __classPrivateFieldGet$a(this, _QuerySubscriptionProxy_initialized, "f");
|
|
3383
3425
|
}
|
|
3384
3426
|
/** Get the latest query result
|
|
3385
3427
|
*
|
|
@@ -3390,7 +3432,7 @@ class QuerySubscriptionProxy {
|
|
|
3390
3432
|
* @returns The latest query result as a string (usually a JSON array of bindings)
|
|
3391
3433
|
*/
|
|
3392
3434
|
get result() {
|
|
3393
|
-
return __classPrivateFieldGet$
|
|
3435
|
+
return __classPrivateFieldGet$a(this, _QuerySubscriptionProxy_latestResult, "f");
|
|
3394
3436
|
}
|
|
3395
3437
|
/** Add a callback that will be called whenever new results arrive
|
|
3396
3438
|
*
|
|
@@ -3412,8 +3454,8 @@ class QuerySubscriptionProxy {
|
|
|
3412
3454
|
* ```
|
|
3413
3455
|
*/
|
|
3414
3456
|
onResult(callback) {
|
|
3415
|
-
__classPrivateFieldGet$
|
|
3416
|
-
return () => __classPrivateFieldGet$
|
|
3457
|
+
__classPrivateFieldGet$a(this, _QuerySubscriptionProxy_callbacks, "f").add(callback);
|
|
3458
|
+
return () => __classPrivateFieldGet$a(this, _QuerySubscriptionProxy_callbacks, "f").delete(callback);
|
|
3417
3459
|
}
|
|
3418
3460
|
/** Clean up the subscription and stop keepalive signals
|
|
3419
3461
|
*
|
|
@@ -3427,25 +3469,25 @@ class QuerySubscriptionProxy {
|
|
|
3427
3469
|
* will not receive any more updates. The instance should be discarded.
|
|
3428
3470
|
*/
|
|
3429
3471
|
dispose() {
|
|
3430
|
-
__classPrivateFieldSet$
|
|
3431
|
-
clearTimeout(__classPrivateFieldGet$
|
|
3432
|
-
if (__classPrivateFieldGet$
|
|
3433
|
-
__classPrivateFieldGet$
|
|
3472
|
+
__classPrivateFieldSet$a(this, _QuerySubscriptionProxy_disposed, true, "f");
|
|
3473
|
+
clearTimeout(__classPrivateFieldGet$a(this, _QuerySubscriptionProxy_keepaliveTimer, "f"));
|
|
3474
|
+
if (__classPrivateFieldGet$a(this, _QuerySubscriptionProxy_unsubscribe, "f")) {
|
|
3475
|
+
__classPrivateFieldGet$a(this, _QuerySubscriptionProxy_unsubscribe, "f").call(this);
|
|
3434
3476
|
}
|
|
3435
|
-
__classPrivateFieldGet$
|
|
3436
|
-
if (__classPrivateFieldGet$
|
|
3437
|
-
clearTimeout(__classPrivateFieldGet$
|
|
3438
|
-
__classPrivateFieldSet$
|
|
3477
|
+
__classPrivateFieldGet$a(this, _QuerySubscriptionProxy_callbacks, "f").clear();
|
|
3478
|
+
if (__classPrivateFieldGet$a(this, _QuerySubscriptionProxy_initTimeoutId, "f")) {
|
|
3479
|
+
clearTimeout(__classPrivateFieldGet$a(this, _QuerySubscriptionProxy_initTimeoutId, "f"));
|
|
3480
|
+
__classPrivateFieldSet$a(this, _QuerySubscriptionProxy_initTimeoutId, undefined, "f");
|
|
3439
3481
|
}
|
|
3440
3482
|
// Tell the backend to dispose of the subscription
|
|
3441
|
-
if (__classPrivateFieldGet$
|
|
3442
|
-
__classPrivateFieldGet$
|
|
3483
|
+
if (__classPrivateFieldGet$a(this, _QuerySubscriptionProxy_subscriptionId, "f")) {
|
|
3484
|
+
__classPrivateFieldGet$a(this, _QuerySubscriptionProxy_client, "f").disposeQuerySubscription(__classPrivateFieldGet$a(this, _QuerySubscriptionProxy_uuid, "f"), __classPrivateFieldGet$a(this, _QuerySubscriptionProxy_subscriptionId, "f"))
|
|
3443
3485
|
.catch(e => console.error('Error disposing query subscription:', e));
|
|
3444
3486
|
}
|
|
3445
3487
|
}
|
|
3446
3488
|
}
|
|
3447
3489
|
_QuerySubscriptionProxy_uuid = new WeakMap(), _QuerySubscriptionProxy_subscriptionId = new WeakMap(), _QuerySubscriptionProxy_client = new WeakMap(), _QuerySubscriptionProxy_callbacks = new WeakMap(), _QuerySubscriptionProxy_keepaliveTimer = new WeakMap(), _QuerySubscriptionProxy_unsubscribe = new WeakMap(), _QuerySubscriptionProxy_latestResult = new WeakMap(), _QuerySubscriptionProxy_disposed = new WeakMap(), _QuerySubscriptionProxy_initialized = new WeakMap(), _QuerySubscriptionProxy_initResolve = new WeakMap(), _QuerySubscriptionProxy_initReject = new WeakMap(), _QuerySubscriptionProxy_initTimeoutId = new WeakMap(), _QuerySubscriptionProxy_query = new WeakMap(), _QuerySubscriptionProxy_instances = new WeakSet(), _QuerySubscriptionProxy_notifyCallbacks = function _QuerySubscriptionProxy_notifyCallbacks(result) {
|
|
3448
|
-
for (const callback of __classPrivateFieldGet$
|
|
3490
|
+
for (const callback of __classPrivateFieldGet$a(this, _QuerySubscriptionProxy_callbacks, "f")) {
|
|
3449
3491
|
try {
|
|
3450
3492
|
callback(result);
|
|
3451
3493
|
}
|
|
@@ -3495,7 +3537,7 @@ _QuerySubscriptionProxy_uuid = new WeakMap(), _QuerySubscriptionProxy_subscripti
|
|
|
3495
3537
|
*/
|
|
3496
3538
|
class PerspectiveProxy {
|
|
3497
3539
|
/** @internal Exposed for ModelQueryBuilder subscription management */
|
|
3498
|
-
get client() { return __classPrivateFieldGet$
|
|
3540
|
+
get client() { return __classPrivateFieldGet$a(this, _PerspectiveProxy_client, "f"); }
|
|
3499
3541
|
/**
|
|
3500
3542
|
* Creates a new PerspectiveProxy instance.
|
|
3501
3543
|
* Note: Don't create this directly, use ad4m.perspective.add() instead.
|
|
@@ -3513,31 +3555,31 @@ class PerspectiveProxy {
|
|
|
3513
3555
|
* Note: Don't create this directly, use ad4m.perspective.add() instead.
|
|
3514
3556
|
*/
|
|
3515
3557
|
);
|
|
3516
|
-
__classPrivateFieldSet$
|
|
3517
|
-
__classPrivateFieldSet$
|
|
3518
|
-
__classPrivateFieldSet$
|
|
3519
|
-
__classPrivateFieldSet$
|
|
3520
|
-
__classPrivateFieldSet$
|
|
3521
|
-
__classPrivateFieldSet$
|
|
3522
|
-
this.uuid = __classPrivateFieldGet$
|
|
3523
|
-
this.name = __classPrivateFieldGet$
|
|
3524
|
-
this.owners = __classPrivateFieldGet$
|
|
3525
|
-
this.sharedUrl = __classPrivateFieldGet$
|
|
3526
|
-
this.neighbourhood = __classPrivateFieldGet$
|
|
3527
|
-
this.state = __classPrivateFieldGet$
|
|
3528
|
-
__classPrivateFieldGet$
|
|
3529
|
-
__classPrivateFieldGet$
|
|
3530
|
-
__classPrivateFieldGet$
|
|
3531
|
-
__classPrivateFieldGet$
|
|
3558
|
+
__classPrivateFieldSet$a(this, _PerspectiveProxy_perspectiveLinkAddedCallbacks, [], "f");
|
|
3559
|
+
__classPrivateFieldSet$a(this, _PerspectiveProxy_perspectiveLinkRemovedCallbacks, [], "f");
|
|
3560
|
+
__classPrivateFieldSet$a(this, _PerspectiveProxy_perspectiveLinkUpdatedCallbacks, [], "f");
|
|
3561
|
+
__classPrivateFieldSet$a(this, _PerspectiveProxy_perspectiveSyncStateChangeCallbacks, [], "f");
|
|
3562
|
+
__classPrivateFieldSet$a(this, _PerspectiveProxy_handle, handle, "f");
|
|
3563
|
+
__classPrivateFieldSet$a(this, _PerspectiveProxy_client, ad4m, "f");
|
|
3564
|
+
this.uuid = __classPrivateFieldGet$a(this, _PerspectiveProxy_handle, "f").uuid;
|
|
3565
|
+
this.name = __classPrivateFieldGet$a(this, _PerspectiveProxy_handle, "f").name;
|
|
3566
|
+
this.owners = __classPrivateFieldGet$a(this, _PerspectiveProxy_handle, "f").owners;
|
|
3567
|
+
this.sharedUrl = __classPrivateFieldGet$a(this, _PerspectiveProxy_handle, "f").sharedUrl;
|
|
3568
|
+
this.neighbourhood = __classPrivateFieldGet$a(this, _PerspectiveProxy_handle, "f").neighbourhood;
|
|
3569
|
+
this.state = __classPrivateFieldGet$a(this, _PerspectiveProxy_handle, "f").state;
|
|
3570
|
+
__classPrivateFieldGet$a(this, _PerspectiveProxy_client, "f").addPerspectiveLinkAddedListener(__classPrivateFieldGet$a(this, _PerspectiveProxy_handle, "f").uuid, __classPrivateFieldGet$a(this, _PerspectiveProxy_perspectiveLinkAddedCallbacks, "f"));
|
|
3571
|
+
__classPrivateFieldGet$a(this, _PerspectiveProxy_client, "f").addPerspectiveLinkRemovedListener(__classPrivateFieldGet$a(this, _PerspectiveProxy_handle, "f").uuid, __classPrivateFieldGet$a(this, _PerspectiveProxy_perspectiveLinkRemovedCallbacks, "f"));
|
|
3572
|
+
__classPrivateFieldGet$a(this, _PerspectiveProxy_client, "f").addPerspectiveLinkUpdatedListener(__classPrivateFieldGet$a(this, _PerspectiveProxy_handle, "f").uuid, __classPrivateFieldGet$a(this, _PerspectiveProxy_perspectiveLinkUpdatedCallbacks, "f"));
|
|
3573
|
+
__classPrivateFieldGet$a(this, _PerspectiveProxy_client, "f").addPerspectiveSyncStateChangeListener(__classPrivateFieldGet$a(this, _PerspectiveProxy_handle, "f").uuid, __classPrivateFieldGet$a(this, _PerspectiveProxy_perspectiveSyncStateChangeCallbacks, "f"));
|
|
3532
3574
|
}
|
|
3533
3575
|
/** Update the proxy's internal handle and public fields in-place.
|
|
3534
3576
|
* Keeps the same object reference so all holders see the update. */
|
|
3535
3577
|
updateHandle(handle) {
|
|
3536
|
-
if (handle.uuid !== __classPrivateFieldGet$
|
|
3537
|
-
throw new Error(`PerspectiveProxy.updateHandle: UUID mismatch — proxy is bound to "${__classPrivateFieldGet$
|
|
3578
|
+
if (handle.uuid !== __classPrivateFieldGet$a(this, _PerspectiveProxy_handle, "f").uuid) {
|
|
3579
|
+
throw new Error(`PerspectiveProxy.updateHandle: UUID mismatch — proxy is bound to "${__classPrivateFieldGet$a(this, _PerspectiveProxy_handle, "f").uuid}" but received handle with UUID "${handle.uuid}". ` +
|
|
3538
3580
|
`This would silently diverge from listeners registered under the original UUID.`);
|
|
3539
3581
|
}
|
|
3540
|
-
__classPrivateFieldSet$
|
|
3582
|
+
__classPrivateFieldSet$a(this, _PerspectiveProxy_handle, handle, "f");
|
|
3541
3583
|
this.uuid = handle.uuid;
|
|
3542
3584
|
this.name = handle.name;
|
|
3543
3585
|
this.owners = handle.owners;
|
|
@@ -3618,8 +3660,8 @@ class PerspectiveProxy {
|
|
|
3618
3660
|
* @param batchId - Optional batch ID to group this operation with others
|
|
3619
3661
|
*/
|
|
3620
3662
|
async executeAction(actions, expression, parameters, batchId) {
|
|
3621
|
-
const result = await __classPrivateFieldGet$
|
|
3622
|
-
invalidatePerspectiveCache(__classPrivateFieldGet$
|
|
3663
|
+
const result = await __classPrivateFieldGet$a(this, _PerspectiveProxy_client, "f").executeCommands(__classPrivateFieldGet$a(this, _PerspectiveProxy_handle, "f").uuid, JSON.stringify(actions), expression, JSON.stringify(parameters), batchId);
|
|
3664
|
+
invalidatePerspectiveCache(__classPrivateFieldGet$a(this, _PerspectiveProxy_handle, "f").uuid);
|
|
3623
3665
|
return result;
|
|
3624
3666
|
}
|
|
3625
3667
|
/**
|
|
@@ -3644,7 +3686,7 @@ class PerspectiveProxy {
|
|
|
3644
3686
|
* ```
|
|
3645
3687
|
*/
|
|
3646
3688
|
async get(query) {
|
|
3647
|
-
return await __classPrivateFieldGet$
|
|
3689
|
+
return await __classPrivateFieldGet$a(this, _PerspectiveProxy_client, "f").queryLinks(__classPrivateFieldGet$a(this, _PerspectiveProxy_handle, "f").uuid, query);
|
|
3648
3690
|
}
|
|
3649
3691
|
/**
|
|
3650
3692
|
* Executes a Prolog query against the perspective's knowledge base.
|
|
@@ -3670,7 +3712,7 @@ class PerspectiveProxy {
|
|
|
3670
3712
|
* ```
|
|
3671
3713
|
*/
|
|
3672
3714
|
async infer(query) {
|
|
3673
|
-
return await __classPrivateFieldGet$
|
|
3715
|
+
return await __classPrivateFieldGet$a(this, _PerspectiveProxy_client, "f").queryProlog(__classPrivateFieldGet$a(this, _PerspectiveProxy_handle, "f").uuid, query);
|
|
3674
3716
|
}
|
|
3675
3717
|
/**
|
|
3676
3718
|
* Executes a SPARQL query against the perspective's link cache.
|
|
@@ -3689,11 +3731,11 @@ class PerspectiveProxy {
|
|
|
3689
3731
|
* @returns Query results as parsed JSON
|
|
3690
3732
|
*/
|
|
3691
3733
|
async querySparql(query) {
|
|
3692
|
-
const cached = getCachedResult(__classPrivateFieldGet$
|
|
3734
|
+
const cached = getCachedResult(__classPrivateFieldGet$a(this, _PerspectiveProxy_handle, "f").uuid, query);
|
|
3693
3735
|
if (cached !== undefined)
|
|
3694
3736
|
return cached;
|
|
3695
|
-
const result = await __classPrivateFieldGet$
|
|
3696
|
-
setCachedResult(__classPrivateFieldGet$
|
|
3737
|
+
const result = await __classPrivateFieldGet$a(this, _PerspectiveProxy_client, "f").querySparql(__classPrivateFieldGet$a(this, _PerspectiveProxy_handle, "f").uuid, query);
|
|
3738
|
+
setCachedResult(__classPrivateFieldGet$a(this, _PerspectiveProxy_handle, "f").uuid, query, result);
|
|
3697
3739
|
return result;
|
|
3698
3740
|
}
|
|
3699
3741
|
/**
|
|
@@ -3705,7 +3747,23 @@ class PerspectiveProxy {
|
|
|
3705
3747
|
* @returns Object with `instances` array and `totalCount`
|
|
3706
3748
|
*/
|
|
3707
3749
|
async modelQuery(className, queryJson, shapeJson) {
|
|
3708
|
-
return await __classPrivateFieldGet$
|
|
3750
|
+
return await __classPrivateFieldGet$a(this, _PerspectiveProxy_client, "f").modelQuery(__classPrivateFieldGet$a(this, _PerspectiveProxy_handle, "f").uuid, className, queryJson, shapeJson);
|
|
3751
|
+
}
|
|
3752
|
+
/**
|
|
3753
|
+
* Evaluate property getters for a batch of instances in a single RPC call.
|
|
3754
|
+
* Returns a map of `{ instanceId: { prop: value, ... } }`.
|
|
3755
|
+
*
|
|
3756
|
+
* Use this instead of `Ad4mModel.evaluateGetters()` for lazy-loading
|
|
3757
|
+
* getter-backed properties on visible items (e.g. `replyingTo` on messages).
|
|
3758
|
+
*
|
|
3759
|
+
* @param className - The model class name (e.g. "Message")
|
|
3760
|
+
* @param instanceIds - Array of instance base expression URIs
|
|
3761
|
+
* @param shapeJson - Shape metadata JSON from the model class
|
|
3762
|
+
* @param propertyNames - Optional subset of property names to evaluate
|
|
3763
|
+
* @returns Map of instance ID → evaluated property values
|
|
3764
|
+
*/
|
|
3765
|
+
async evaluateGetters(className, instanceIds, shapeJson, propertyNames) {
|
|
3766
|
+
return await __classPrivateFieldGet$a(this, _PerspectiveProxy_client, "f").evaluateGetters(__classPrivateFieldGet$a(this, _PerspectiveProxy_handle, "f").uuid, className, instanceIds, shapeJson, propertyNames);
|
|
3709
3767
|
}
|
|
3710
3768
|
/**
|
|
3711
3769
|
* Subscribe to model query changes. Builds trigger SPARQL from the model shape
|
|
@@ -3721,7 +3779,7 @@ class PerspectiveProxy {
|
|
|
3721
3779
|
* @returns Object with `subscriptionId` and initial `result`
|
|
3722
3780
|
*/
|
|
3723
3781
|
async modelSubscribe(className, queryJson, shapeJson) {
|
|
3724
|
-
return await __classPrivateFieldGet$
|
|
3782
|
+
return await __classPrivateFieldGet$a(this, _PerspectiveProxy_client, "f").modelSubscribe(__classPrivateFieldGet$a(this, _PerspectiveProxy_handle, "f").uuid, className, queryJson, shapeJson);
|
|
3725
3783
|
}
|
|
3726
3784
|
/**
|
|
3727
3785
|
* Adds a new link to the perspective.
|
|
@@ -3749,8 +3807,8 @@ class PerspectiveProxy {
|
|
|
3749
3807
|
* ```
|
|
3750
3808
|
*/
|
|
3751
3809
|
async add(link, status = 'shared', batchId) {
|
|
3752
|
-
const result = await __classPrivateFieldGet$
|
|
3753
|
-
invalidatePerspectiveCache(__classPrivateFieldGet$
|
|
3810
|
+
const result = await __classPrivateFieldGet$a(this, _PerspectiveProxy_client, "f").addLink(__classPrivateFieldGet$a(this, _PerspectiveProxy_handle, "f").uuid, link, status, batchId);
|
|
3811
|
+
invalidatePerspectiveCache(__classPrivateFieldGet$a(this, _PerspectiveProxy_handle, "f").uuid);
|
|
3754
3812
|
return result;
|
|
3755
3813
|
}
|
|
3756
3814
|
/**
|
|
@@ -3763,8 +3821,8 @@ class PerspectiveProxy {
|
|
|
3763
3821
|
* @returns Array of created LinkExpressions
|
|
3764
3822
|
*/
|
|
3765
3823
|
async addLinks(links, status = 'shared', batchId) {
|
|
3766
|
-
const result = await __classPrivateFieldGet$
|
|
3767
|
-
invalidatePerspectiveCache(__classPrivateFieldGet$
|
|
3824
|
+
const result = await __classPrivateFieldGet$a(this, _PerspectiveProxy_client, "f").addLinks(__classPrivateFieldGet$a(this, _PerspectiveProxy_handle, "f").uuid, links, status, batchId);
|
|
3825
|
+
invalidatePerspectiveCache(__classPrivateFieldGet$a(this, _PerspectiveProxy_handle, "f").uuid);
|
|
3768
3826
|
return result;
|
|
3769
3827
|
}
|
|
3770
3828
|
/**
|
|
@@ -3775,8 +3833,8 @@ class PerspectiveProxy {
|
|
|
3775
3833
|
* @returns Array of removed LinkExpressions
|
|
3776
3834
|
*/
|
|
3777
3835
|
async removeLinks(links, batchId) {
|
|
3778
|
-
const result = await __classPrivateFieldGet$
|
|
3779
|
-
invalidatePerspectiveCache(__classPrivateFieldGet$
|
|
3836
|
+
const result = await __classPrivateFieldGet$a(this, _PerspectiveProxy_client, "f").removeLinks(__classPrivateFieldGet$a(this, _PerspectiveProxy_handle, "f").uuid, links, batchId);
|
|
3837
|
+
invalidatePerspectiveCache(__classPrivateFieldGet$a(this, _PerspectiveProxy_handle, "f").uuid);
|
|
3780
3838
|
return result;
|
|
3781
3839
|
}
|
|
3782
3840
|
/**
|
|
@@ -3788,8 +3846,8 @@ class PerspectiveProxy {
|
|
|
3788
3846
|
* @returns Object containing results of the mutations
|
|
3789
3847
|
*/
|
|
3790
3848
|
async linkMutations(mutations, status = 'shared') {
|
|
3791
|
-
const result = await __classPrivateFieldGet$
|
|
3792
|
-
invalidatePerspectiveCache(__classPrivateFieldGet$
|
|
3849
|
+
const result = await __classPrivateFieldGet$a(this, _PerspectiveProxy_client, "f").linkMutations(__classPrivateFieldGet$a(this, _PerspectiveProxy_handle, "f").uuid, mutations, status);
|
|
3850
|
+
invalidatePerspectiveCache(__classPrivateFieldGet$a(this, _PerspectiveProxy_handle, "f").uuid);
|
|
3793
3851
|
return result;
|
|
3794
3852
|
}
|
|
3795
3853
|
/**
|
|
@@ -3801,7 +3859,7 @@ class PerspectiveProxy {
|
|
|
3801
3859
|
* @returns The added LinkExpression
|
|
3802
3860
|
*/
|
|
3803
3861
|
async addLinkExpression(link, status = 'shared', batchId) {
|
|
3804
|
-
return await __classPrivateFieldGet$
|
|
3862
|
+
return await __classPrivateFieldGet$a(this, _PerspectiveProxy_client, "f").addLinkExpression(__classPrivateFieldGet$a(this, _PerspectiveProxy_handle, "f").uuid, link, status, batchId);
|
|
3805
3863
|
}
|
|
3806
3864
|
/**
|
|
3807
3865
|
* Updates an existing link with new data.
|
|
@@ -3811,8 +3869,8 @@ class PerspectiveProxy {
|
|
|
3811
3869
|
* @param batchId - Optional batch ID to group this operation with others
|
|
3812
3870
|
*/
|
|
3813
3871
|
async update(oldLink, newLink, batchId) {
|
|
3814
|
-
const result = await __classPrivateFieldGet$
|
|
3815
|
-
invalidatePerspectiveCache(__classPrivateFieldGet$
|
|
3872
|
+
const result = await __classPrivateFieldGet$a(this, _PerspectiveProxy_client, "f").updateLink(__classPrivateFieldGet$a(this, _PerspectiveProxy_handle, "f").uuid, oldLink, newLink, batchId);
|
|
3873
|
+
invalidatePerspectiveCache(__classPrivateFieldGet$a(this, _PerspectiveProxy_handle, "f").uuid);
|
|
3816
3874
|
return result;
|
|
3817
3875
|
}
|
|
3818
3876
|
/**
|
|
@@ -3822,18 +3880,18 @@ class PerspectiveProxy {
|
|
|
3822
3880
|
* @param batchId - Optional batch ID to group this operation with others
|
|
3823
3881
|
*/
|
|
3824
3882
|
async remove(link, batchId) {
|
|
3825
|
-
const result = await __classPrivateFieldGet$
|
|
3826
|
-
invalidatePerspectiveCache(__classPrivateFieldGet$
|
|
3883
|
+
const result = await __classPrivateFieldGet$a(this, _PerspectiveProxy_client, "f").removeLink(__classPrivateFieldGet$a(this, _PerspectiveProxy_handle, "f").uuid, link, batchId);
|
|
3884
|
+
invalidatePerspectiveCache(__classPrivateFieldGet$a(this, _PerspectiveProxy_handle, "f").uuid);
|
|
3827
3885
|
return result;
|
|
3828
3886
|
}
|
|
3829
3887
|
/** Creates a new batch for grouping operations */
|
|
3830
3888
|
async createBatch() {
|
|
3831
|
-
return await __classPrivateFieldGet$
|
|
3889
|
+
return await __classPrivateFieldGet$a(this, _PerspectiveProxy_client, "f").createBatch(__classPrivateFieldGet$a(this, _PerspectiveProxy_handle, "f").uuid);
|
|
3832
3890
|
}
|
|
3833
3891
|
/** Commits a batch of operations */
|
|
3834
3892
|
async commitBatch(batchId) {
|
|
3835
|
-
const result = await __classPrivateFieldGet$
|
|
3836
|
-
invalidatePerspectiveCache(__classPrivateFieldGet$
|
|
3893
|
+
const result = await __classPrivateFieldGet$a(this, _PerspectiveProxy_client, "f").commitBatch(__classPrivateFieldGet$a(this, _PerspectiveProxy_handle, "f").uuid, batchId);
|
|
3894
|
+
invalidatePerspectiveCache(__classPrivateFieldGet$a(this, _PerspectiveProxy_handle, "f").uuid);
|
|
3837
3895
|
return result;
|
|
3838
3896
|
}
|
|
3839
3897
|
/**
|
|
@@ -3843,7 +3901,7 @@ class PerspectiveProxy {
|
|
|
3843
3901
|
* @returns The rendered Expression
|
|
3844
3902
|
*/
|
|
3845
3903
|
async getExpression(expressionURI) {
|
|
3846
|
-
return await __classPrivateFieldGet$
|
|
3904
|
+
return await __classPrivateFieldGet$a(this, _PerspectiveProxy_client, "f").getExpression(expressionURI);
|
|
3847
3905
|
}
|
|
3848
3906
|
/**
|
|
3849
3907
|
* Creates a new Expression in the specified Language.
|
|
@@ -3853,7 +3911,7 @@ class PerspectiveProxy {
|
|
|
3853
3911
|
* @returns URI of the created Expression
|
|
3854
3912
|
*/
|
|
3855
3913
|
async createExpression(content, languageAddress) {
|
|
3856
|
-
return await __classPrivateFieldGet$
|
|
3914
|
+
return await __classPrivateFieldGet$a(this, _PerspectiveProxy_client, "f").createExpression(content, languageAddress);
|
|
3857
3915
|
}
|
|
3858
3916
|
/**
|
|
3859
3917
|
* Subscribes to link changes in the perspective.
|
|
@@ -3876,13 +3934,13 @@ class PerspectiveProxy {
|
|
|
3876
3934
|
*/
|
|
3877
3935
|
async addListener(type, cb) {
|
|
3878
3936
|
if (type === 'link-added') {
|
|
3879
|
-
__classPrivateFieldGet$
|
|
3937
|
+
__classPrivateFieldGet$a(this, _PerspectiveProxy_perspectiveLinkAddedCallbacks, "f").push(cb);
|
|
3880
3938
|
}
|
|
3881
3939
|
else if (type === 'link-removed') {
|
|
3882
|
-
__classPrivateFieldGet$
|
|
3940
|
+
__classPrivateFieldGet$a(this, _PerspectiveProxy_perspectiveLinkRemovedCallbacks, "f").push(cb);
|
|
3883
3941
|
}
|
|
3884
3942
|
else if (type === 'link-updated') {
|
|
3885
|
-
__classPrivateFieldGet$
|
|
3943
|
+
__classPrivateFieldGet$a(this, _PerspectiveProxy_perspectiveLinkUpdatedCallbacks, "f").push(cb);
|
|
3886
3944
|
}
|
|
3887
3945
|
}
|
|
3888
3946
|
/**
|
|
@@ -3898,7 +3956,7 @@ class PerspectiveProxy {
|
|
|
3898
3956
|
* ```
|
|
3899
3957
|
*/
|
|
3900
3958
|
async addSyncStateChangeListener(cb) {
|
|
3901
|
-
__classPrivateFieldGet$
|
|
3959
|
+
__classPrivateFieldGet$a(this, _PerspectiveProxy_perspectiveSyncStateChangeCallbacks, "f").push(cb);
|
|
3902
3960
|
}
|
|
3903
3961
|
/**
|
|
3904
3962
|
* Unsubscribes from link changes.
|
|
@@ -3908,16 +3966,16 @@ class PerspectiveProxy {
|
|
|
3908
3966
|
*/
|
|
3909
3967
|
async removeListener(type, cb) {
|
|
3910
3968
|
if (type === 'link-added') {
|
|
3911
|
-
const index = __classPrivateFieldGet$
|
|
3912
|
-
__classPrivateFieldGet$
|
|
3969
|
+
const index = __classPrivateFieldGet$a(this, _PerspectiveProxy_perspectiveLinkAddedCallbacks, "f").indexOf(cb);
|
|
3970
|
+
__classPrivateFieldGet$a(this, _PerspectiveProxy_perspectiveLinkAddedCallbacks, "f").splice(index, 1);
|
|
3913
3971
|
}
|
|
3914
3972
|
else if (type === 'link-removed') {
|
|
3915
|
-
const index = __classPrivateFieldGet$
|
|
3916
|
-
__classPrivateFieldGet$
|
|
3973
|
+
const index = __classPrivateFieldGet$a(this, _PerspectiveProxy_perspectiveLinkRemovedCallbacks, "f").indexOf(cb);
|
|
3974
|
+
__classPrivateFieldGet$a(this, _PerspectiveProxy_perspectiveLinkRemovedCallbacks, "f").splice(index, 1);
|
|
3917
3975
|
}
|
|
3918
3976
|
else if (type === 'link-updated') {
|
|
3919
|
-
const index = __classPrivateFieldGet$
|
|
3920
|
-
__classPrivateFieldGet$
|
|
3977
|
+
const index = __classPrivateFieldGet$a(this, _PerspectiveProxy_perspectiveLinkUpdatedCallbacks, "f").indexOf(cb);
|
|
3978
|
+
__classPrivateFieldGet$a(this, _PerspectiveProxy_perspectiveLinkUpdatedCallbacks, "f").splice(index, 1);
|
|
3921
3979
|
}
|
|
3922
3980
|
}
|
|
3923
3981
|
/**
|
|
@@ -3927,7 +3985,7 @@ class PerspectiveProxy {
|
|
|
3927
3985
|
* @returns Perspective object containing all links
|
|
3928
3986
|
*/
|
|
3929
3987
|
async snapshot() {
|
|
3930
|
-
return __classPrivateFieldGet$
|
|
3988
|
+
return __classPrivateFieldGet$a(this, _PerspectiveProxy_client, "f").snapshotByUUID(__classPrivateFieldGet$a(this, _PerspectiveProxy_handle, "f").uuid);
|
|
3931
3989
|
}
|
|
3932
3990
|
/**
|
|
3933
3991
|
* Loads a perspective snapshot, replacing current content.
|
|
@@ -4207,7 +4265,7 @@ class PerspectiveProxy {
|
|
|
4207
4265
|
* await perspective.addSdna('Recipe', prologCode, 'subject_class');
|
|
4208
4266
|
*/
|
|
4209
4267
|
async addSdna(name, sdnaCode, sdnaType, shaclJson) {
|
|
4210
|
-
return __classPrivateFieldGet$
|
|
4268
|
+
return __classPrivateFieldGet$a(this, _PerspectiveProxy_client, "f").addSdna(__classPrivateFieldGet$a(this, _PerspectiveProxy_handle, "f").uuid, name, sdnaCode, sdnaType, shaclJson);
|
|
4211
4269
|
}
|
|
4212
4270
|
/**
|
|
4213
4271
|
* Adds a subject class to the perspective.
|
|
@@ -4477,7 +4535,7 @@ class PerspectiveProxy {
|
|
|
4477
4535
|
let className;
|
|
4478
4536
|
if (typeof subjectClass === "string") {
|
|
4479
4537
|
className = subjectClass;
|
|
4480
|
-
await __classPrivateFieldGet$
|
|
4538
|
+
await __classPrivateFieldGet$a(this, _PerspectiveProxy_client, "f").createSubject(__classPrivateFieldGet$a(this, _PerspectiveProxy_handle, "f").uuid, JSON.stringify({
|
|
4481
4539
|
className,
|
|
4482
4540
|
initialValues
|
|
4483
4541
|
}), exprAddr, initialValues ? JSON.stringify(initialValues) : undefined, batchId);
|
|
@@ -4489,7 +4547,7 @@ class PerspectiveProxy {
|
|
|
4489
4547
|
if (!resolvedClassName) {
|
|
4490
4548
|
throw new Error("Could not resolve subject class name from object. Use a decorated class or pass a className string.");
|
|
4491
4549
|
}
|
|
4492
|
-
await __classPrivateFieldGet$
|
|
4550
|
+
await __classPrivateFieldGet$a(this, _PerspectiveProxy_client, "f").createSubject(__classPrivateFieldGet$a(this, _PerspectiveProxy_handle, "f").uuid, JSON.stringify({
|
|
4493
4551
|
className: resolvedClassName,
|
|
4494
4552
|
initialValues
|
|
4495
4553
|
}), exprAddr, initialValues ? JSON.stringify(initialValues) : undefined, batchId);
|
|
@@ -4504,7 +4562,7 @@ class PerspectiveProxy {
|
|
|
4504
4562
|
}
|
|
4505
4563
|
async getSubjectData(subjectClass, exprAddr) {
|
|
4506
4564
|
if (typeof subjectClass === "string") {
|
|
4507
|
-
return JSON.parse(await __classPrivateFieldGet$
|
|
4565
|
+
return JSON.parse(await __classPrivateFieldGet$a(this, _PerspectiveProxy_client, "f").getSubjectData(__classPrivateFieldGet$a(this, _PerspectiveProxy_handle, "f").uuid, JSON.stringify({ className: subjectClass }), exprAddr));
|
|
4508
4566
|
}
|
|
4509
4567
|
const obj = subjectClass;
|
|
4510
4568
|
const resolvedClassName = obj.className || obj.constructor?.className || obj.constructor?.prototype?.className
|
|
@@ -4512,7 +4570,7 @@ class PerspectiveProxy {
|
|
|
4512
4570
|
if (!resolvedClassName) {
|
|
4513
4571
|
throw new Error("Could not resolve subject class name from object. Use a decorated class or pass a className string.");
|
|
4514
4572
|
}
|
|
4515
|
-
return JSON.parse(await __classPrivateFieldGet$
|
|
4573
|
+
return JSON.parse(await __classPrivateFieldGet$a(this, _PerspectiveProxy_client, "f").getSubjectData(__classPrivateFieldGet$a(this, _PerspectiveProxy_handle, "f").uuid, JSON.stringify({ className: resolvedClassName }), exprAddr));
|
|
4516
4574
|
}
|
|
4517
4575
|
/**
|
|
4518
4576
|
* Gets actions from SHACL links for a given predicate (e.g., ad4m://constructor, ad4m://destructor).
|
|
@@ -4876,7 +4934,7 @@ class PerspectiveProxy {
|
|
|
4876
4934
|
// Get the class name from the JS class
|
|
4877
4935
|
const className = jsClass.className || jsClass.prototype?.className || jsClass.name;
|
|
4878
4936
|
// Skip if already registered for this perspective instance
|
|
4879
|
-
if (__classPrivateFieldGet$
|
|
4937
|
+
if (__classPrivateFieldGet$a(this, _PerspectiveProxy_ensuredSubjectClasses, "f").has(className))
|
|
4880
4938
|
return;
|
|
4881
4939
|
// Note: Duplicate checking is handled on the Rust side in add_sdna
|
|
4882
4940
|
// Generate SHACL SDNA (Prolog-free)
|
|
@@ -4891,13 +4949,13 @@ class PerspectiveProxy {
|
|
|
4891
4949
|
// Backend stores SHACL links directly
|
|
4892
4950
|
await this.addSdna(className, '', 'subject_class', shaclJson);
|
|
4893
4951
|
// Mark as registered for this perspective instance
|
|
4894
|
-
__classPrivateFieldGet$
|
|
4952
|
+
__classPrivateFieldGet$a(this, _PerspectiveProxy_ensuredSubjectClasses, "f").add(className);
|
|
4895
4953
|
}
|
|
4896
4954
|
/** Clear the per-instance ensured subject class cache.
|
|
4897
4955
|
* Call this after wiping a perspective's links so that
|
|
4898
4956
|
* subsequent register() calls re-add SHACL definitions. */
|
|
4899
4957
|
clearEnsuredSubjectClasses() {
|
|
4900
|
-
__classPrivateFieldGet$
|
|
4958
|
+
__classPrivateFieldGet$a(this, _PerspectiveProxy_ensuredSubjectClasses, "f").clear();
|
|
4901
4959
|
}
|
|
4902
4960
|
/**
|
|
4903
4961
|
* Returns a list of all class names that have been registered as SHACL
|
|
@@ -5072,7 +5130,7 @@ class PerspectiveProxy {
|
|
|
5072
5130
|
}));
|
|
5073
5131
|
}
|
|
5074
5132
|
getNeighbourhoodProxy() {
|
|
5075
|
-
return __classPrivateFieldGet$
|
|
5133
|
+
return __classPrivateFieldGet$a(this, _PerspectiveProxy_client, "f").getNeighbourhoodProxy(__classPrivateFieldGet$a(this, _PerspectiveProxy_handle, "f").uuid);
|
|
5076
5134
|
}
|
|
5077
5135
|
/**
|
|
5078
5136
|
* Returns a proxy object for working with AI capabilities.
|
|
@@ -5089,7 +5147,7 @@ class PerspectiveProxy {
|
|
|
5089
5147
|
* ```
|
|
5090
5148
|
*/
|
|
5091
5149
|
get ai() {
|
|
5092
|
-
return __classPrivateFieldGet$
|
|
5150
|
+
return __classPrivateFieldGet$a(this, _PerspectiveProxy_client, "f").aiClient;
|
|
5093
5151
|
}
|
|
5094
5152
|
/**
|
|
5095
5153
|
* Creates a subscription for a Prolog query that updates in real-time.
|
|
@@ -5131,7 +5189,7 @@ class PerspectiveProxy {
|
|
|
5131
5189
|
* ```
|
|
5132
5190
|
*/
|
|
5133
5191
|
async subscribeInfer(query) {
|
|
5134
|
-
const subscriptionProxy = new QuerySubscriptionProxy(this.uuid, query, __classPrivateFieldGet$
|
|
5192
|
+
const subscriptionProxy = new QuerySubscriptionProxy(this.uuid, query, __classPrivateFieldGet$a(this, _PerspectiveProxy_client, "f"));
|
|
5135
5193
|
// Start the subscription on the Rust side first to get the real subscription ID
|
|
5136
5194
|
await subscriptionProxy.subscribe();
|
|
5137
5195
|
// Wait for the initial result
|
|
@@ -5159,7 +5217,7 @@ class PerspectiveProxy {
|
|
|
5159
5217
|
* @returns Initialized QuerySubscriptionProxy instance
|
|
5160
5218
|
*/
|
|
5161
5219
|
async subscribeQuery(query) {
|
|
5162
|
-
const subscriptionProxy = new QuerySubscriptionProxy(this.uuid, query, __classPrivateFieldGet$
|
|
5220
|
+
const subscriptionProxy = new QuerySubscriptionProxy(this.uuid, query, __classPrivateFieldGet$a(this, _PerspectiveProxy_client, "f"));
|
|
5163
5221
|
// Start the subscription on the Rust side first to get the real subscription ID
|
|
5164
5222
|
await subscriptionProxy.subscribe();
|
|
5165
5223
|
// Wait for the initial result
|
|
@@ -5169,13 +5227,13 @@ class PerspectiveProxy {
|
|
|
5169
5227
|
}
|
|
5170
5228
|
_PerspectiveProxy_handle = new WeakMap(), _PerspectiveProxy_client = new WeakMap(), _PerspectiveProxy_perspectiveLinkAddedCallbacks = new WeakMap(), _PerspectiveProxy_perspectiveLinkRemovedCallbacks = new WeakMap(), _PerspectiveProxy_perspectiveLinkUpdatedCallbacks = new WeakMap(), _PerspectiveProxy_perspectiveSyncStateChangeCallbacks = new WeakMap(), _PerspectiveProxy_ensuredSubjectClasses = new WeakMap();
|
|
5171
5229
|
|
|
5172
|
-
var __classPrivateFieldSet$
|
|
5230
|
+
var __classPrivateFieldSet$9 = (undefined && undefined.__classPrivateFieldSet) || function (receiver, state, value, kind, f) {
|
|
5173
5231
|
if (kind === "m") throw new TypeError("Private method is not writable");
|
|
5174
5232
|
if (kind === "a" && !f) throw new TypeError("Private accessor was defined without a setter");
|
|
5175
5233
|
if (typeof state === "function" ? receiver !== state || !f : !state.has(receiver)) throw new TypeError("Cannot write private member to an object whose class did not declare it");
|
|
5176
5234
|
return (kind === "a" ? f.call(receiver, value) : f ? f.value = value : state.set(receiver, value)), value;
|
|
5177
5235
|
};
|
|
5178
|
-
var __classPrivateFieldGet$
|
|
5236
|
+
var __classPrivateFieldGet$9 = (undefined && undefined.__classPrivateFieldGet) || function (receiver, state, kind, f) {
|
|
5179
5237
|
if (kind === "a" && !f) throw new TypeError("Private accessor was defined without a getter");
|
|
5180
5238
|
if (typeof state === "function" ? receiver !== state || !f : !state.has(receiver)) throw new TypeError("Cannot read private member from an object whose class did not declare it");
|
|
5181
5239
|
return kind === "m" ? f : kind === "a" ? f.call(receiver) : f ? f.value : state.get(receiver);
|
|
@@ -5183,11 +5241,6 @@ var __classPrivateFieldGet$8 = (undefined && undefined.__classPrivateFieldGet) |
|
|
|
5183
5241
|
var _PerspectiveClient_apiClient, _PerspectiveClient_perspectiveAddedCallbacks, _PerspectiveClient_perspectiveUpdatedCallbacks, _PerspectiveClient_perspectiveRemovedCallbacks, _PerspectiveClient_perspectiveSyncStateChangeCallbacks, _PerspectiveClient_expressionClient, _PerspectiveClient_neighbourhoodClient, _PerspectiveClient_aiClient, _PerspectiveClient_unsubscribers, _PerspectiveClient_linkUnsubscribers, _PerspectiveClient_querySubscriptionUnsubscribers;
|
|
5184
5242
|
function normalizeQueryResult(raw, errorContext) {
|
|
5185
5243
|
let finalResult = raw;
|
|
5186
|
-
let isInit = false;
|
|
5187
|
-
if (typeof finalResult === 'string' && finalResult.startsWith('#init#')) {
|
|
5188
|
-
finalResult = finalResult.substring(6);
|
|
5189
|
-
isInit = true;
|
|
5190
|
-
}
|
|
5191
5244
|
if (typeof finalResult === 'string') {
|
|
5192
5245
|
try {
|
|
5193
5246
|
finalResult = JSON.parse(finalResult);
|
|
@@ -5196,10 +5249,7 @@ function normalizeQueryResult(raw, errorContext) {
|
|
|
5196
5249
|
console.error(errorContext, e);
|
|
5197
5250
|
}
|
|
5198
5251
|
}
|
|
5199
|
-
|
|
5200
|
-
finalResult.isInit = true;
|
|
5201
|
-
}
|
|
5202
|
-
return { result: finalResult, isInit };
|
|
5252
|
+
return finalResult;
|
|
5203
5253
|
}
|
|
5204
5254
|
class PerspectiveClient {
|
|
5205
5255
|
constructor(baseUrl, token, subscribe = true, sharedApiClient) {
|
|
@@ -5214,14 +5264,14 @@ class PerspectiveClient {
|
|
|
5214
5264
|
_PerspectiveClient_unsubscribers.set(this, void 0);
|
|
5215
5265
|
_PerspectiveClient_linkUnsubscribers.set(this, void 0);
|
|
5216
5266
|
_PerspectiveClient_querySubscriptionUnsubscribers.set(this, void 0);
|
|
5217
|
-
__classPrivateFieldSet$
|
|
5218
|
-
__classPrivateFieldSet$
|
|
5219
|
-
__classPrivateFieldSet$
|
|
5220
|
-
__classPrivateFieldSet$
|
|
5221
|
-
__classPrivateFieldSet$
|
|
5222
|
-
__classPrivateFieldSet$
|
|
5223
|
-
__classPrivateFieldSet$
|
|
5224
|
-
__classPrivateFieldSet$
|
|
5267
|
+
__classPrivateFieldSet$9(this, _PerspectiveClient_apiClient, sharedApiClient || new ApiClient(baseUrl, token), "f");
|
|
5268
|
+
__classPrivateFieldSet$9(this, _PerspectiveClient_perspectiveAddedCallbacks, [], "f");
|
|
5269
|
+
__classPrivateFieldSet$9(this, _PerspectiveClient_perspectiveUpdatedCallbacks, [], "f");
|
|
5270
|
+
__classPrivateFieldSet$9(this, _PerspectiveClient_perspectiveRemovedCallbacks, [], "f");
|
|
5271
|
+
__classPrivateFieldSet$9(this, _PerspectiveClient_perspectiveSyncStateChangeCallbacks, [], "f");
|
|
5272
|
+
__classPrivateFieldSet$9(this, _PerspectiveClient_unsubscribers, [], "f");
|
|
5273
|
+
__classPrivateFieldSet$9(this, _PerspectiveClient_linkUnsubscribers, new Map(), "f");
|
|
5274
|
+
__classPrivateFieldSet$9(this, _PerspectiveClient_querySubscriptionUnsubscribers, new Map(), "f");
|
|
5225
5275
|
if (subscribe) {
|
|
5226
5276
|
this.subscribePerspectiveAdded();
|
|
5227
5277
|
this.subscribePerspectiveUpdated();
|
|
@@ -5229,24 +5279,24 @@ class PerspectiveClient {
|
|
|
5229
5279
|
}
|
|
5230
5280
|
}
|
|
5231
5281
|
setExpressionClient(client) {
|
|
5232
|
-
__classPrivateFieldSet$
|
|
5282
|
+
__classPrivateFieldSet$9(this, _PerspectiveClient_expressionClient, client, "f");
|
|
5233
5283
|
}
|
|
5234
5284
|
setNeighbourhoodClient(client) {
|
|
5235
|
-
__classPrivateFieldSet$
|
|
5285
|
+
__classPrivateFieldSet$9(this, _PerspectiveClient_neighbourhoodClient, client, "f");
|
|
5236
5286
|
}
|
|
5237
5287
|
setAIClient(client) {
|
|
5238
|
-
__classPrivateFieldSet$
|
|
5288
|
+
__classPrivateFieldSet$9(this, _PerspectiveClient_aiClient, client, "f");
|
|
5239
5289
|
}
|
|
5240
5290
|
get aiClient() {
|
|
5241
|
-
return __classPrivateFieldGet$
|
|
5291
|
+
return __classPrivateFieldGet$9(this, _PerspectiveClient_aiClient, "f");
|
|
5242
5292
|
}
|
|
5243
5293
|
async all() {
|
|
5244
|
-
const perspectives = await __classPrivateFieldGet$
|
|
5294
|
+
const perspectives = await __classPrivateFieldGet$9(this, _PerspectiveClient_apiClient, "f").call('perspective.all');
|
|
5245
5295
|
return perspectives.map(handle => new PerspectiveProxy(handle, this));
|
|
5246
5296
|
}
|
|
5247
5297
|
async byUUID(uuid) {
|
|
5248
5298
|
try {
|
|
5249
|
-
const perspective = await __classPrivateFieldGet$
|
|
5299
|
+
const perspective = await __classPrivateFieldGet$9(this, _PerspectiveClient_apiClient, "f").call('perspective.get', { uuid });
|
|
5250
5300
|
if (!perspective)
|
|
5251
5301
|
return null;
|
|
5252
5302
|
return new PerspectiveProxy(perspective, this);
|
|
@@ -5258,10 +5308,10 @@ class PerspectiveClient {
|
|
|
5258
5308
|
}
|
|
5259
5309
|
}
|
|
5260
5310
|
async snapshotByUUID(uuid) {
|
|
5261
|
-
return __classPrivateFieldGet$
|
|
5311
|
+
return __classPrivateFieldGet$9(this, _PerspectiveClient_apiClient, "f").call('perspective.snapshot', { uuid });
|
|
5262
5312
|
}
|
|
5263
5313
|
async publishSnapshotByUUID(uuid) {
|
|
5264
|
-
return __classPrivateFieldGet$
|
|
5314
|
+
return __classPrivateFieldGet$9(this, _PerspectiveClient_apiClient, "f").call('perspective.publishSnapshot', { uuid });
|
|
5265
5315
|
}
|
|
5266
5316
|
async queryLinks(uuid, query) {
|
|
5267
5317
|
const params = { uuid };
|
|
@@ -5277,179 +5327,189 @@ class PerspectiveClient {
|
|
|
5277
5327
|
params.untilDate = query.untilDate instanceof Date ? query.untilDate.toISOString() : String(query.untilDate);
|
|
5278
5328
|
if (query.limit !== undefined)
|
|
5279
5329
|
params.limit = query.limit;
|
|
5280
|
-
return __classPrivateFieldGet$
|
|
5330
|
+
return __classPrivateFieldGet$9(this, _PerspectiveClient_apiClient, "f").call('perspective.queryLinks', params);
|
|
5281
5331
|
}
|
|
5282
5332
|
async queryProlog(uuid, query) {
|
|
5283
|
-
const result = await __classPrivateFieldGet$
|
|
5333
|
+
const result = await __classPrivateFieldGet$9(this, _PerspectiveClient_apiClient, "f").call('perspective.queryProlog', { uuid, query });
|
|
5284
5334
|
return JSON.parse(result);
|
|
5285
5335
|
}
|
|
5286
5336
|
async querySparql(uuid, query) {
|
|
5287
|
-
const result = await __classPrivateFieldGet$
|
|
5337
|
+
const result = await __classPrivateFieldGet$9(this, _PerspectiveClient_apiClient, "f").call('perspective.querySparql', { uuid, engine: 'sparql', query });
|
|
5288
5338
|
return JSON.parse(result);
|
|
5289
5339
|
}
|
|
5290
5340
|
async subscribeQuery(uuid, query) {
|
|
5291
|
-
const response = await __classPrivateFieldGet$
|
|
5341
|
+
const response = await __classPrivateFieldGet$9(this, _PerspectiveClient_apiClient, "f").call('perspective.subscribeQuery', { uuid, query });
|
|
5292
5342
|
const { subscriptionId, result } = response;
|
|
5293
|
-
const
|
|
5294
|
-
return { subscriptionId, result:
|
|
5343
|
+
const parsed = normalizeQueryResult(result, 'Error parsing subscribeQuery result:');
|
|
5344
|
+
return { subscriptionId, result: parsed };
|
|
5295
5345
|
}
|
|
5296
5346
|
async perspectiveKeepAliveQuery(uuid, subscriptionId) {
|
|
5297
|
-
return __classPrivateFieldGet$
|
|
5347
|
+
return __classPrivateFieldGet$9(this, _PerspectiveClient_apiClient, "f").call('perspective.keepAliveQuery', { uuid, subscriptionId });
|
|
5298
5348
|
}
|
|
5299
5349
|
async perspectiveDisposeQuerySubscription(uuid, subscriptionId) {
|
|
5300
|
-
return __classPrivateFieldGet$
|
|
5350
|
+
return __classPrivateFieldGet$9(this, _PerspectiveClient_apiClient, "f").call('perspective.disposeQuery', { uuid, subscriptionId });
|
|
5301
5351
|
}
|
|
5302
5352
|
subscribeToQueryUpdates(subscriptionId, onData) {
|
|
5303
|
-
const unsub = __classPrivateFieldGet$
|
|
5353
|
+
const unsub = __classPrivateFieldGet$9(this, _PerspectiveClient_apiClient, "f").subscribe((data) => {
|
|
5304
5354
|
const event = data;
|
|
5305
5355
|
if (event.type !== 'query-subscription-update')
|
|
5306
5356
|
return;
|
|
5307
5357
|
const eventSubscriptionId = event.subscriptionId || event.subscription_id;
|
|
5308
5358
|
if (eventSubscriptionId !== subscriptionId)
|
|
5309
5359
|
return;
|
|
5310
|
-
const
|
|
5311
|
-
onData(
|
|
5360
|
+
const parsed = normalizeQueryResult(event.result, 'Error parsing query subscription:');
|
|
5361
|
+
onData(parsed);
|
|
5312
5362
|
});
|
|
5313
|
-
__classPrivateFieldGet$
|
|
5363
|
+
__classPrivateFieldGet$9(this, _PerspectiveClient_querySubscriptionUnsubscribers, "f").set(subscriptionId, unsub);
|
|
5314
5364
|
return unsub;
|
|
5315
5365
|
}
|
|
5316
5366
|
async keepAliveQuery(uuid, subscriptionId) {
|
|
5317
|
-
return __classPrivateFieldGet$
|
|
5367
|
+
return __classPrivateFieldGet$9(this, _PerspectiveClient_apiClient, "f").call('perspective.keepAliveQuery', { uuid, subscriptionId });
|
|
5318
5368
|
}
|
|
5319
5369
|
async disposeQuerySubscription(uuid, subscriptionId) {
|
|
5320
|
-
const unsub = __classPrivateFieldGet$
|
|
5370
|
+
const unsub = __classPrivateFieldGet$9(this, _PerspectiveClient_querySubscriptionUnsubscribers, "f").get(subscriptionId);
|
|
5321
5371
|
if (unsub) {
|
|
5322
5372
|
unsub();
|
|
5323
|
-
__classPrivateFieldGet$
|
|
5373
|
+
__classPrivateFieldGet$9(this, _PerspectiveClient_querySubscriptionUnsubscribers, "f").delete(subscriptionId);
|
|
5324
5374
|
}
|
|
5325
|
-
return __classPrivateFieldGet$
|
|
5375
|
+
return __classPrivateFieldGet$9(this, _PerspectiveClient_apiClient, "f").call('perspective.disposeQuery', { uuid, subscriptionId });
|
|
5326
5376
|
}
|
|
5327
5377
|
async modelQuery(uuid, className, queryJson, shapeJson) {
|
|
5328
|
-
const resultJson = await __classPrivateFieldGet$
|
|
5378
|
+
const resultJson = await __classPrivateFieldGet$9(this, _PerspectiveClient_apiClient, "f").call('perspective.modelQuery', { uuid, class_name: className, query_json: queryJson, shape_json: shapeJson });
|
|
5379
|
+
return JSON.parse(resultJson);
|
|
5380
|
+
}
|
|
5381
|
+
async evaluateGetters(uuid, className, instanceIds, shapeJson, propertyNames) {
|
|
5382
|
+
const resultJson = await __classPrivateFieldGet$9(this, _PerspectiveClient_apiClient, "f").call('perspective.evaluateGetters', {
|
|
5383
|
+
uuid,
|
|
5384
|
+
class_name: className,
|
|
5385
|
+
instance_ids: instanceIds,
|
|
5386
|
+
shape_json: shapeJson,
|
|
5387
|
+
...(propertyNames && { property_names: propertyNames }),
|
|
5388
|
+
});
|
|
5329
5389
|
return JSON.parse(resultJson);
|
|
5330
5390
|
}
|
|
5331
5391
|
async modelSubscribe(uuid, className, queryJson, shapeJson) {
|
|
5332
|
-
const response = await __classPrivateFieldGet$
|
|
5392
|
+
const response = await __classPrivateFieldGet$9(this, _PerspectiveClient_apiClient, "f").call('perspective.modelSubscribe', { uuid, class_name: className, query_json: queryJson, shape_json: shapeJson });
|
|
5333
5393
|
return {
|
|
5334
5394
|
subscriptionId: response.subscription_id,
|
|
5335
5395
|
result: JSON.parse(response.result)
|
|
5336
5396
|
};
|
|
5337
5397
|
}
|
|
5338
5398
|
async add(name) {
|
|
5339
|
-
const handle = await __classPrivateFieldGet$
|
|
5399
|
+
const handle = await __classPrivateFieldGet$9(this, _PerspectiveClient_apiClient, "f").call('perspective.create', { name });
|
|
5340
5400
|
return new PerspectiveProxy(handle, this);
|
|
5341
5401
|
}
|
|
5342
5402
|
async update(uuid, name) {
|
|
5343
|
-
const handle = await __classPrivateFieldGet$
|
|
5403
|
+
const handle = await __classPrivateFieldGet$9(this, _PerspectiveClient_apiClient, "f").call('perspective.update', { uuid, name });
|
|
5344
5404
|
return new PerspectiveProxy(handle, this);
|
|
5345
5405
|
}
|
|
5346
5406
|
async remove(uuid) {
|
|
5347
|
-
const result = await __classPrivateFieldGet$
|
|
5407
|
+
const result = await __classPrivateFieldGet$9(this, _PerspectiveClient_apiClient, "f").call('perspective.remove', { uuid });
|
|
5348
5408
|
return { perspectiveRemove: result };
|
|
5349
5409
|
}
|
|
5350
5410
|
async addLink(uuid, link, status = 'shared', batchId) {
|
|
5351
|
-
return __classPrivateFieldGet$
|
|
5411
|
+
return __classPrivateFieldGet$9(this, _PerspectiveClient_apiClient, "f").call('perspective.addLink', { uuid, link, status, batchId });
|
|
5352
5412
|
}
|
|
5353
5413
|
async addLinks(uuid, links, status = 'shared', batchId) {
|
|
5354
|
-
return __classPrivateFieldGet$
|
|
5414
|
+
return __classPrivateFieldGet$9(this, _PerspectiveClient_apiClient, "f").call('perspective.addLinks', { uuid, links, status, batchId });
|
|
5355
5415
|
}
|
|
5356
5416
|
async removeLinks(uuid, links, batchId) {
|
|
5357
|
-
return __classPrivateFieldGet$
|
|
5417
|
+
return __classPrivateFieldGet$9(this, _PerspectiveClient_apiClient, "f").call('perspective.removeLinks', { uuid, links, batchId });
|
|
5358
5418
|
}
|
|
5359
5419
|
async linkMutations(uuid, mutations, status) {
|
|
5360
|
-
return __classPrivateFieldGet$
|
|
5420
|
+
return __classPrivateFieldGet$9(this, _PerspectiveClient_apiClient, "f").call('perspective.linkMutations', { uuid, mutations, status });
|
|
5361
5421
|
}
|
|
5362
5422
|
async addLinkExpression(uuid, link, status = 'shared', batchId) {
|
|
5363
|
-
return __classPrivateFieldGet$
|
|
5423
|
+
return __classPrivateFieldGet$9(this, _PerspectiveClient_apiClient, "f").call('perspective.addLinkExpression', { uuid, link, status, batchId });
|
|
5364
5424
|
}
|
|
5365
5425
|
async updateLink(uuid, oldLink, newLink, batchId) {
|
|
5366
|
-
return __classPrivateFieldGet$
|
|
5426
|
+
return __classPrivateFieldGet$9(this, _PerspectiveClient_apiClient, "f").call('perspective.updateLink', { uuid, oldLink, newLink, batchId });
|
|
5367
5427
|
}
|
|
5368
5428
|
async removeLink(uuid, link, batchId) {
|
|
5369
5429
|
delete link.__typename;
|
|
5370
5430
|
delete link.data.__typename;
|
|
5371
5431
|
delete link.proof.__typename;
|
|
5372
5432
|
delete link.status;
|
|
5373
|
-
return __classPrivateFieldGet$
|
|
5433
|
+
return __classPrivateFieldGet$9(this, _PerspectiveClient_apiClient, "f").call('perspective.removeLink', { uuid, link, batchId });
|
|
5374
5434
|
}
|
|
5375
5435
|
async addSdna(uuid, name, sdnaCode, sdnaType, shaclJson) {
|
|
5376
|
-
return __classPrivateFieldGet$
|
|
5436
|
+
return __classPrivateFieldGet$9(this, _PerspectiveClient_apiClient, "f").call('perspective.addSdna', { uuid, name, sdnaCode: sdnaCode || "", sdnaType, shaclJson });
|
|
5377
5437
|
}
|
|
5378
5438
|
async executeCommands(uuid, commands, expression, parameters, batchId) {
|
|
5379
|
-
return __classPrivateFieldGet$
|
|
5439
|
+
return __classPrivateFieldGet$9(this, _PerspectiveClient_apiClient, "f").call('perspective.executeCommands', { uuid, commands, expression, parameters, batchId });
|
|
5380
5440
|
}
|
|
5381
5441
|
async createSubject(uuid, subjectClass, expressionAddress, initialValues, batchId) {
|
|
5382
|
-
return __classPrivateFieldGet$
|
|
5442
|
+
return __classPrivateFieldGet$9(this, _PerspectiveClient_apiClient, "f").call('perspective.createSubject', { uuid, subjectClass, expressionAddress, initialValues, batchId });
|
|
5383
5443
|
}
|
|
5384
5444
|
async getSubjectData(uuid, subjectClass, expressionAddress) {
|
|
5385
|
-
return __classPrivateFieldGet$
|
|
5445
|
+
return __classPrivateFieldGet$9(this, _PerspectiveClient_apiClient, "f").call('perspective.getSubjectData', { uuid, subjectClass, expressionAddress });
|
|
5386
5446
|
}
|
|
5387
5447
|
// ExpressionClient functions, needed for Subjects:
|
|
5388
5448
|
async getExpression(expressionURI) {
|
|
5389
|
-
return await __classPrivateFieldGet$
|
|
5449
|
+
return await __classPrivateFieldGet$9(this, _PerspectiveClient_expressionClient, "f").get(expressionURI);
|
|
5390
5450
|
}
|
|
5391
5451
|
async createExpression(content, languageAddress) {
|
|
5392
|
-
return await __classPrivateFieldGet$
|
|
5452
|
+
return await __classPrivateFieldGet$9(this, _PerspectiveClient_expressionClient, "f").create(content, languageAddress);
|
|
5393
5453
|
}
|
|
5394
5454
|
// Subscriptions:
|
|
5395
5455
|
addPerspectiveAddedListener(cb) {
|
|
5396
|
-
__classPrivateFieldGet$
|
|
5456
|
+
__classPrivateFieldGet$9(this, _PerspectiveClient_perspectiveAddedCallbacks, "f").push(cb);
|
|
5397
5457
|
}
|
|
5398
5458
|
subscribePerspectiveAdded() {
|
|
5399
|
-
const unsub = __classPrivateFieldGet$
|
|
5459
|
+
const unsub = __classPrivateFieldGet$9(this, _PerspectiveClient_apiClient, "f").subscribe((data) => {
|
|
5400
5460
|
if (data.type === 'perspective-added') {
|
|
5401
|
-
__classPrivateFieldGet$
|
|
5461
|
+
__classPrivateFieldGet$9(this, _PerspectiveClient_perspectiveAddedCallbacks, "f").forEach(cb => cb(data.perspective));
|
|
5402
5462
|
}
|
|
5403
5463
|
});
|
|
5404
|
-
__classPrivateFieldGet$
|
|
5464
|
+
__classPrivateFieldGet$9(this, _PerspectiveClient_unsubscribers, "f").push(unsub);
|
|
5405
5465
|
}
|
|
5406
5466
|
addPerspectiveUpdatedListener(cb) {
|
|
5407
|
-
__classPrivateFieldGet$
|
|
5467
|
+
__classPrivateFieldGet$9(this, _PerspectiveClient_perspectiveUpdatedCallbacks, "f").push(cb);
|
|
5408
5468
|
}
|
|
5409
5469
|
subscribePerspectiveUpdated() {
|
|
5410
|
-
const unsub = __classPrivateFieldGet$
|
|
5470
|
+
const unsub = __classPrivateFieldGet$9(this, _PerspectiveClient_apiClient, "f").subscribe((data) => {
|
|
5411
5471
|
if (data.type === 'perspective-updated') {
|
|
5412
|
-
__classPrivateFieldGet$
|
|
5472
|
+
__classPrivateFieldGet$9(this, _PerspectiveClient_perspectiveUpdatedCallbacks, "f").forEach(cb => cb(data.perspective));
|
|
5413
5473
|
}
|
|
5414
5474
|
});
|
|
5415
|
-
__classPrivateFieldGet$
|
|
5475
|
+
__classPrivateFieldGet$9(this, _PerspectiveClient_unsubscribers, "f").push(unsub);
|
|
5416
5476
|
}
|
|
5417
5477
|
addPerspectiveSyncedListener(cb) {
|
|
5418
|
-
__classPrivateFieldGet$
|
|
5478
|
+
__classPrivateFieldGet$9(this, _PerspectiveClient_perspectiveSyncStateChangeCallbacks, "f").push(cb);
|
|
5419
5479
|
}
|
|
5420
5480
|
async addPerspectiveSyncStateChangeListener(uuid, cb) {
|
|
5421
|
-
const unsub = __classPrivateFieldGet$
|
|
5481
|
+
const unsub = __classPrivateFieldGet$9(this, _PerspectiveClient_apiClient, "f").subscribe((data) => {
|
|
5422
5482
|
if (data.type === 'sync-state-change' && data.uuid === uuid) {
|
|
5423
5483
|
cb.forEach(c => c(data.state));
|
|
5424
5484
|
}
|
|
5425
5485
|
});
|
|
5426
|
-
__classPrivateFieldGet$
|
|
5486
|
+
__classPrivateFieldGet$9(this, _PerspectiveClient_unsubscribers, "f").push(unsub);
|
|
5427
5487
|
await new Promise(resolve => setTimeout(resolve, 500));
|
|
5428
5488
|
}
|
|
5429
5489
|
addPerspectiveRemovedListener(cb) {
|
|
5430
|
-
__classPrivateFieldGet$
|
|
5490
|
+
__classPrivateFieldGet$9(this, _PerspectiveClient_perspectiveRemovedCallbacks, "f").push(cb);
|
|
5431
5491
|
}
|
|
5432
5492
|
subscribePerspectiveRemoved() {
|
|
5433
|
-
const unsub = __classPrivateFieldGet$
|
|
5493
|
+
const unsub = __classPrivateFieldGet$9(this, _PerspectiveClient_apiClient, "f").subscribe((data) => {
|
|
5434
5494
|
if (data.type === 'perspective-removed') {
|
|
5435
|
-
__classPrivateFieldGet$
|
|
5495
|
+
__classPrivateFieldGet$9(this, _PerspectiveClient_perspectiveRemovedCallbacks, "f").forEach(cb => cb(data.uuid));
|
|
5436
5496
|
}
|
|
5437
5497
|
});
|
|
5438
|
-
__classPrivateFieldGet$
|
|
5498
|
+
__classPrivateFieldGet$9(this, _PerspectiveClient_unsubscribers, "f").push(unsub);
|
|
5439
5499
|
}
|
|
5440
5500
|
async addPerspectiveLinkAddedListener(uuid, cb) {
|
|
5441
|
-
const unsub = __classPrivateFieldGet$
|
|
5501
|
+
const unsub = __classPrivateFieldGet$9(this, _PerspectiveClient_apiClient, "f").subscribe((data) => {
|
|
5442
5502
|
if (data.type === 'link-added' && data.perspectiveUuid === uuid) {
|
|
5443
5503
|
cb.forEach(c => c(data.link));
|
|
5444
5504
|
}
|
|
5445
5505
|
});
|
|
5446
|
-
let existing = __classPrivateFieldGet$
|
|
5506
|
+
let existing = __classPrivateFieldGet$9(this, _PerspectiveClient_linkUnsubscribers, "f").get(uuid) || [];
|
|
5447
5507
|
existing.push(unsub);
|
|
5448
|
-
__classPrivateFieldGet$
|
|
5449
|
-
await __classPrivateFieldGet$
|
|
5508
|
+
__classPrivateFieldGet$9(this, _PerspectiveClient_linkUnsubscribers, "f").set(uuid, existing);
|
|
5509
|
+
await __classPrivateFieldGet$9(this, _PerspectiveClient_apiClient, "f").waitForSubscription();
|
|
5450
5510
|
}
|
|
5451
5511
|
async addPerspectiveLinkRemovedListener(uuid, cb) {
|
|
5452
|
-
const unsub = __classPrivateFieldGet$
|
|
5512
|
+
const unsub = __classPrivateFieldGet$9(this, _PerspectiveClient_apiClient, "f").subscribe((data) => {
|
|
5453
5513
|
if (data.type === 'link-removed' && data.perspectiveUuid === uuid) {
|
|
5454
5514
|
const link = data.link;
|
|
5455
5515
|
if (!link.status) {
|
|
@@ -5458,13 +5518,13 @@ class PerspectiveClient {
|
|
|
5458
5518
|
cb.forEach(c => c(link));
|
|
5459
5519
|
}
|
|
5460
5520
|
});
|
|
5461
|
-
let existing = __classPrivateFieldGet$
|
|
5521
|
+
let existing = __classPrivateFieldGet$9(this, _PerspectiveClient_linkUnsubscribers, "f").get(uuid) || [];
|
|
5462
5522
|
existing.push(unsub);
|
|
5463
|
-
__classPrivateFieldGet$
|
|
5464
|
-
await __classPrivateFieldGet$
|
|
5523
|
+
__classPrivateFieldGet$9(this, _PerspectiveClient_linkUnsubscribers, "f").set(uuid, existing);
|
|
5524
|
+
await __classPrivateFieldGet$9(this, _PerspectiveClient_apiClient, "f").waitForSubscription();
|
|
5465
5525
|
}
|
|
5466
5526
|
async addPerspectiveLinkUpdatedListener(uuid, cb) {
|
|
5467
|
-
const unsub = __classPrivateFieldGet$
|
|
5527
|
+
const unsub = __classPrivateFieldGet$9(this, _PerspectiveClient_apiClient, "f").subscribe((data) => {
|
|
5468
5528
|
if (data.type === 'link-updated' && data.perspectiveUuid === uuid) {
|
|
5469
5529
|
const newLink = data.newLink;
|
|
5470
5530
|
const oldLink = data.oldLink;
|
|
@@ -5477,23 +5537,163 @@ class PerspectiveClient {
|
|
|
5477
5537
|
cb.forEach(c => c(data));
|
|
5478
5538
|
}
|
|
5479
5539
|
});
|
|
5480
|
-
let existing = __classPrivateFieldGet$
|
|
5540
|
+
let existing = __classPrivateFieldGet$9(this, _PerspectiveClient_linkUnsubscribers, "f").get(uuid) || [];
|
|
5481
5541
|
existing.push(unsub);
|
|
5482
|
-
__classPrivateFieldGet$
|
|
5483
|
-
await __classPrivateFieldGet$
|
|
5542
|
+
__classPrivateFieldGet$9(this, _PerspectiveClient_linkUnsubscribers, "f").set(uuid, existing);
|
|
5543
|
+
await __classPrivateFieldGet$9(this, _PerspectiveClient_apiClient, "f").waitForSubscription();
|
|
5484
5544
|
}
|
|
5485
5545
|
getNeighbourhoodProxy(uuid) {
|
|
5486
|
-
return new NeighbourhoodProxy(__classPrivateFieldGet$
|
|
5546
|
+
return new NeighbourhoodProxy(__classPrivateFieldGet$9(this, _PerspectiveClient_neighbourhoodClient, "f"), uuid);
|
|
5487
5547
|
}
|
|
5488
5548
|
async createBatch(uuid) {
|
|
5489
|
-
return __classPrivateFieldGet$
|
|
5549
|
+
return __classPrivateFieldGet$9(this, _PerspectiveClient_apiClient, "f").call('perspective.createBatch', { uuid });
|
|
5490
5550
|
}
|
|
5491
5551
|
async commitBatch(uuid, batchId) {
|
|
5492
|
-
return __classPrivateFieldGet$
|
|
5552
|
+
return __classPrivateFieldGet$9(this, _PerspectiveClient_apiClient, "f").call('perspective.commitBatch', { uuid, batchId });
|
|
5493
5553
|
}
|
|
5494
5554
|
}
|
|
5495
5555
|
_PerspectiveClient_apiClient = new WeakMap(), _PerspectiveClient_perspectiveAddedCallbacks = new WeakMap(), _PerspectiveClient_perspectiveUpdatedCallbacks = new WeakMap(), _PerspectiveClient_perspectiveRemovedCallbacks = new WeakMap(), _PerspectiveClient_perspectiveSyncStateChangeCallbacks = new WeakMap(), _PerspectiveClient_expressionClient = new WeakMap(), _PerspectiveClient_neighbourhoodClient = new WeakMap(), _PerspectiveClient_aiClient = new WeakMap(), _PerspectiveClient_unsubscribers = new WeakMap(), _PerspectiveClient_linkUnsubscribers = new WeakMap(), _PerspectiveClient_querySubscriptionUnsubscribers = new WeakMap();
|
|
5496
5556
|
|
|
5557
|
+
/**
|
|
5558
|
+
* PersistentCache — two-tier persistent key-value cache abstraction.
|
|
5559
|
+
*
|
|
5560
|
+
* Provides an IndexedDB-backed implementation for browsers and a no-op
|
|
5561
|
+
* NullCache fallback for Node.js / environments without IndexedDB.
|
|
5562
|
+
*
|
|
5563
|
+
* Design goals:
|
|
5564
|
+
* - Lazy open: IDB connection is deferred until first access
|
|
5565
|
+
* - Fire-and-forget writes: put() resolves immediately (best-effort persistence)
|
|
5566
|
+
* - Graceful degradation: all IDB errors resolve (never reject), so callers
|
|
5567
|
+
* never need try/catch around cache operations
|
|
5568
|
+
* - Tree-shakeable: import only what you need
|
|
5569
|
+
*/
|
|
5570
|
+
var __classPrivateFieldSet$8 = (undefined && undefined.__classPrivateFieldSet) || function (receiver, state, value, kind, f) {
|
|
5571
|
+
if (kind === "m") throw new TypeError("Private method is not writable");
|
|
5572
|
+
if (kind === "a" && !f) throw new TypeError("Private accessor was defined without a setter");
|
|
5573
|
+
if (typeof state === "function" ? receiver !== state || !f : !state.has(receiver)) throw new TypeError("Cannot write private member to an object whose class did not declare it");
|
|
5574
|
+
return (kind === "a" ? f.call(receiver, value) : f ? f.value = value : state.set(receiver, value)), value;
|
|
5575
|
+
};
|
|
5576
|
+
var __classPrivateFieldGet$8 = (undefined && undefined.__classPrivateFieldGet) || function (receiver, state, kind, f) {
|
|
5577
|
+
if (kind === "a" && !f) throw new TypeError("Private accessor was defined without a getter");
|
|
5578
|
+
if (typeof state === "function" ? receiver !== state || !f : !state.has(receiver)) throw new TypeError("Cannot read private member from an object whose class did not declare it");
|
|
5579
|
+
return kind === "m" ? f : kind === "a" ? f.call(receiver) : f ? f.value : state.get(receiver);
|
|
5580
|
+
};
|
|
5581
|
+
var _IDBCache_instances, _IDBCache_dbName, _IDBCache_storeName, _IDBCache_dbPromise, _IDBCache_version, _IDBCache_open;
|
|
5582
|
+
// ── IndexedDB Implementation ─────────────────────────────────────────
|
|
5583
|
+
class IDBCache {
|
|
5584
|
+
constructor(dbName, storeName) {
|
|
5585
|
+
_IDBCache_instances.add(this);
|
|
5586
|
+
_IDBCache_dbName.set(this, void 0);
|
|
5587
|
+
_IDBCache_storeName.set(this, void 0);
|
|
5588
|
+
_IDBCache_dbPromise.set(this, null);
|
|
5589
|
+
_IDBCache_version.set(this, 1);
|
|
5590
|
+
__classPrivateFieldSet$8(this, _IDBCache_dbName, dbName, "f");
|
|
5591
|
+
__classPrivateFieldSet$8(this, _IDBCache_storeName, storeName, "f");
|
|
5592
|
+
}
|
|
5593
|
+
async get(key) {
|
|
5594
|
+
try {
|
|
5595
|
+
const db = await __classPrivateFieldGet$8(this, _IDBCache_instances, "m", _IDBCache_open).call(this);
|
|
5596
|
+
return new Promise((resolve) => {
|
|
5597
|
+
const tx = db.transaction(__classPrivateFieldGet$8(this, _IDBCache_storeName, "f"), 'readonly');
|
|
5598
|
+
const store = tx.objectStore(__classPrivateFieldGet$8(this, _IDBCache_storeName, "f"));
|
|
5599
|
+
const req = store.get(key);
|
|
5600
|
+
req.onsuccess = () => resolve(req.result ?? undefined);
|
|
5601
|
+
req.onerror = () => resolve(undefined);
|
|
5602
|
+
});
|
|
5603
|
+
}
|
|
5604
|
+
catch {
|
|
5605
|
+
return undefined;
|
|
5606
|
+
}
|
|
5607
|
+
}
|
|
5608
|
+
async put(key, value) {
|
|
5609
|
+
try {
|
|
5610
|
+
const db = await __classPrivateFieldGet$8(this, _IDBCache_instances, "m", _IDBCache_open).call(this);
|
|
5611
|
+
return new Promise((resolve) => {
|
|
5612
|
+
const tx = db.transaction(__classPrivateFieldGet$8(this, _IDBCache_storeName, "f"), 'readwrite');
|
|
5613
|
+
const store = tx.objectStore(__classPrivateFieldGet$8(this, _IDBCache_storeName, "f"));
|
|
5614
|
+
store.put(value, key);
|
|
5615
|
+
tx.oncomplete = () => resolve();
|
|
5616
|
+
tx.onerror = () => resolve(); // fire-and-forget
|
|
5617
|
+
});
|
|
5618
|
+
}
|
|
5619
|
+
catch {
|
|
5620
|
+
// degrade gracefully
|
|
5621
|
+
}
|
|
5622
|
+
}
|
|
5623
|
+
async delete(key) {
|
|
5624
|
+
try {
|
|
5625
|
+
const db = await __classPrivateFieldGet$8(this, _IDBCache_instances, "m", _IDBCache_open).call(this);
|
|
5626
|
+
return new Promise((resolve) => {
|
|
5627
|
+
const tx = db.transaction(__classPrivateFieldGet$8(this, _IDBCache_storeName, "f"), 'readwrite');
|
|
5628
|
+
const store = tx.objectStore(__classPrivateFieldGet$8(this, _IDBCache_storeName, "f"));
|
|
5629
|
+
store.delete(key);
|
|
5630
|
+
tx.oncomplete = () => resolve();
|
|
5631
|
+
tx.onerror = () => resolve();
|
|
5632
|
+
});
|
|
5633
|
+
}
|
|
5634
|
+
catch {
|
|
5635
|
+
// degrade gracefully
|
|
5636
|
+
}
|
|
5637
|
+
}
|
|
5638
|
+
async clear() {
|
|
5639
|
+
try {
|
|
5640
|
+
const db = await __classPrivateFieldGet$8(this, _IDBCache_instances, "m", _IDBCache_open).call(this);
|
|
5641
|
+
return new Promise((resolve) => {
|
|
5642
|
+
const tx = db.transaction(__classPrivateFieldGet$8(this, _IDBCache_storeName, "f"), 'readwrite');
|
|
5643
|
+
const store = tx.objectStore(__classPrivateFieldGet$8(this, _IDBCache_storeName, "f"));
|
|
5644
|
+
store.clear();
|
|
5645
|
+
tx.oncomplete = () => resolve();
|
|
5646
|
+
tx.onerror = () => resolve();
|
|
5647
|
+
});
|
|
5648
|
+
}
|
|
5649
|
+
catch {
|
|
5650
|
+
// degrade gracefully
|
|
5651
|
+
}
|
|
5652
|
+
}
|
|
5653
|
+
}
|
|
5654
|
+
_IDBCache_dbName = new WeakMap(), _IDBCache_storeName = new WeakMap(), _IDBCache_dbPromise = new WeakMap(), _IDBCache_version = new WeakMap(), _IDBCache_instances = new WeakSet(), _IDBCache_open = function _IDBCache_open() {
|
|
5655
|
+
if (!__classPrivateFieldGet$8(this, _IDBCache_dbPromise, "f")) {
|
|
5656
|
+
__classPrivateFieldSet$8(this, _IDBCache_dbPromise, new Promise((resolve, reject) => {
|
|
5657
|
+
const storeName = __classPrivateFieldGet$8(this, _IDBCache_storeName, "f");
|
|
5658
|
+
const req = indexedDB.open(__classPrivateFieldGet$8(this, _IDBCache_dbName, "f"), __classPrivateFieldGet$8(this, _IDBCache_version, "f"));
|
|
5659
|
+
req.onupgradeneeded = () => {
|
|
5660
|
+
const db = req.result;
|
|
5661
|
+
if (!db.objectStoreNames.contains(storeName)) {
|
|
5662
|
+
db.createObjectStore(storeName);
|
|
5663
|
+
}
|
|
5664
|
+
};
|
|
5665
|
+
req.onsuccess = () => resolve(req.result);
|
|
5666
|
+
req.onerror = () => reject(req.error);
|
|
5667
|
+
}), "f");
|
|
5668
|
+
}
|
|
5669
|
+
return __classPrivateFieldGet$8(this, _IDBCache_dbPromise, "f");
|
|
5670
|
+
};
|
|
5671
|
+
// ── NullCache (no-op fallback for Node.js) ───────────────────────────
|
|
5672
|
+
class NullCache {
|
|
5673
|
+
async get(_key) { return undefined; }
|
|
5674
|
+
async put(_key, _value) { }
|
|
5675
|
+
async delete(_key) { }
|
|
5676
|
+
async clear() { }
|
|
5677
|
+
}
|
|
5678
|
+
// ── Factory ──────────────────────────────────────────────────────────
|
|
5679
|
+
/**
|
|
5680
|
+
* Create a PersistentCache backed by IndexedDB (browser) or NullCache (Node.js).
|
|
5681
|
+
*
|
|
5682
|
+
* @param dbName - IndexedDB database name
|
|
5683
|
+
* @param storeName - IndexedDB object store name
|
|
5684
|
+
*/
|
|
5685
|
+
function createPersistentCache(dbName, storeName) {
|
|
5686
|
+
try {
|
|
5687
|
+
if (typeof indexedDB !== 'undefined') {
|
|
5688
|
+
return new IDBCache(dbName, storeName);
|
|
5689
|
+
}
|
|
5690
|
+
}
|
|
5691
|
+
catch {
|
|
5692
|
+
// indexedDB access threw (e.g. in a worker with restricted globals)
|
|
5693
|
+
}
|
|
5694
|
+
return new NullCache();
|
|
5695
|
+
}
|
|
5696
|
+
|
|
5497
5697
|
var __classPrivateFieldSet$7 = (undefined && undefined.__classPrivateFieldSet) || function (receiver, state, value, kind, f) {
|
|
5498
5698
|
if (kind === "m") throw new TypeError("Private method is not writable");
|
|
5499
5699
|
if (kind === "a" && !f) throw new TypeError("Private accessor was defined without a setter");
|
|
@@ -5505,7 +5705,7 @@ var __classPrivateFieldGet$7 = (undefined && undefined.__classPrivateFieldGet) |
|
|
|
5505
5705
|
if (typeof state === "function" ? receiver !== state || !f : !state.has(receiver)) throw new TypeError("Cannot read private member from an object whose class did not declare it");
|
|
5506
5706
|
return kind === "m" ? f : kind === "a" ? f.call(receiver) : f ? f.value : state.get(receiver);
|
|
5507
5707
|
};
|
|
5508
|
-
var _AgentClient_apiClient, _AgentClient_baseUrl, _AgentClient_token, _AgentClient_appsChangedCallback, _AgentClient_updatedCallbacks, _AgentClient_agentStatusChangedCallbacks, _AgentClient_hostingUserInfoChangedCallbacks, _AgentClient_computeLogUpdatedCallbacks, _AgentClient_unsubscribers;
|
|
5708
|
+
var _AgentClient_apiClient, _AgentClient_baseUrl, _AgentClient_token, _AgentClient_appsChangedCallback, _AgentClient_updatedCallbacks, _AgentClient_agentStatusChangedCallbacks, _AgentClient_hostingUserInfoChangedCallbacks, _AgentClient_computeLogUpdatedCallbacks, _AgentClient_unsubscribers, _AgentClient_memCache, _AgentClient_persistent, _AgentClient_selfDid;
|
|
5509
5709
|
class AgentClient {
|
|
5510
5710
|
constructor(baseUrl, token, subscribe = true, sharedApiClient) {
|
|
5511
5711
|
_AgentClient_apiClient.set(this, void 0);
|
|
@@ -5517,6 +5717,13 @@ class AgentClient {
|
|
|
5517
5717
|
_AgentClient_hostingUserInfoChangedCallbacks.set(this, void 0);
|
|
5518
5718
|
_AgentClient_computeLogUpdatedCallbacks.set(this, void 0);
|
|
5519
5719
|
_AgentClient_unsubscribers.set(this, void 0);
|
|
5720
|
+
// ── byDID cache ────────────────────────────────────────────────────
|
|
5721
|
+
// L1: in-memory promise cache with timestamps for TTL
|
|
5722
|
+
_AgentClient_memCache.set(this, new Map());
|
|
5723
|
+
// L2: persistent cache (IndexedDB in browser, NullCache in Node)
|
|
5724
|
+
_AgentClient_persistent.set(this, void 0);
|
|
5725
|
+
// Self-DID for event-driven invalidation (no TTL for own profile)
|
|
5726
|
+
_AgentClient_selfDid.set(this, null);
|
|
5520
5727
|
__classPrivateFieldSet$7(this, _AgentClient_baseUrl, baseUrl, "f");
|
|
5521
5728
|
__classPrivateFieldSet$7(this, _AgentClient_token, token, "f");
|
|
5522
5729
|
__classPrivateFieldSet$7(this, _AgentClient_apiClient, sharedApiClient || new ApiClient(baseUrl, token), "f");
|
|
@@ -5526,6 +5733,7 @@ class AgentClient {
|
|
|
5526
5733
|
__classPrivateFieldSet$7(this, _AgentClient_hostingUserInfoChangedCallbacks, [], "f");
|
|
5527
5734
|
__classPrivateFieldSet$7(this, _AgentClient_computeLogUpdatedCallbacks, [], "f");
|
|
5528
5735
|
__classPrivateFieldSet$7(this, _AgentClient_unsubscribers, [], "f");
|
|
5736
|
+
__classPrivateFieldSet$7(this, _AgentClient_persistent, createPersistentCache('ad4m-agent-cache', 'agents'), "f");
|
|
5529
5737
|
if (subscribe) {
|
|
5530
5738
|
this.subscribeAgentUpdated();
|
|
5531
5739
|
this.subscribeAgentStatusChanged();
|
|
@@ -5559,7 +5767,57 @@ class AgentClient {
|
|
|
5559
5767
|
return new AgentStatus(result);
|
|
5560
5768
|
}
|
|
5561
5769
|
async byDID(did) {
|
|
5562
|
-
|
|
5770
|
+
const now = Date.now();
|
|
5771
|
+
const cached = __classPrivateFieldGet$7(this, _AgentClient_memCache, "f").get(did);
|
|
5772
|
+
if (cached) {
|
|
5773
|
+
const isSelf = did === __classPrivateFieldGet$7(this, _AgentClient_selfDid, "f");
|
|
5774
|
+
// Self-DID: L1 always valid (event-driven invalidation)
|
|
5775
|
+
// Remote DID: L1 valid within TTL
|
|
5776
|
+
if (isSelf || (now - cached.ts) < AgentClient.REMOTE_AGENT_TTL_MS) {
|
|
5777
|
+
return cached.promise;
|
|
5778
|
+
}
|
|
5779
|
+
}
|
|
5780
|
+
// Deduplicate: store the promise immediately so concurrent calls share one RPC
|
|
5781
|
+
const promise = (async () => {
|
|
5782
|
+
// L2: check persistent cache before network
|
|
5783
|
+
const persisted = await __classPrivateFieldGet$7(this, _AgentClient_persistent, "f").get(did);
|
|
5784
|
+
if (persisted) {
|
|
5785
|
+
return persisted;
|
|
5786
|
+
}
|
|
5787
|
+
// L3: network fetch
|
|
5788
|
+
const result = await __classPrivateFieldGet$7(this, _AgentClient_apiClient, "f").call('agent.byDid', { did });
|
|
5789
|
+
__classPrivateFieldGet$7(this, _AgentClient_persistent, "f").put(did, result); // fire-and-forget write to L2
|
|
5790
|
+
return result;
|
|
5791
|
+
})();
|
|
5792
|
+
__classPrivateFieldGet$7(this, _AgentClient_memCache, "f").set(did, { promise, ts: now });
|
|
5793
|
+
// Clean up on failure so next call retries
|
|
5794
|
+
promise.catch(() => {
|
|
5795
|
+
if (__classPrivateFieldGet$7(this, _AgentClient_memCache, "f").get(did)?.promise === promise) {
|
|
5796
|
+
__classPrivateFieldGet$7(this, _AgentClient_memCache, "f").delete(did);
|
|
5797
|
+
}
|
|
5798
|
+
});
|
|
5799
|
+
return promise;
|
|
5800
|
+
}
|
|
5801
|
+
/**
|
|
5802
|
+
* Set the current agent's own DID.
|
|
5803
|
+
* The self-DID receives event-driven invalidation and is never TTL-expired.
|
|
5804
|
+
*/
|
|
5805
|
+
setSelfDid(did) {
|
|
5806
|
+
__classPrivateFieldSet$7(this, _AgentClient_selfDid, did, "f");
|
|
5807
|
+
}
|
|
5808
|
+
/**
|
|
5809
|
+
* Invalidate a specific DID's cache entry in both L1 and L2.
|
|
5810
|
+
*/
|
|
5811
|
+
invalidateByDid(did) {
|
|
5812
|
+
__classPrivateFieldGet$7(this, _AgentClient_memCache, "f").delete(did);
|
|
5813
|
+
__classPrivateFieldGet$7(this, _AgentClient_persistent, "f").delete(did); // fire-and-forget
|
|
5814
|
+
}
|
|
5815
|
+
/**
|
|
5816
|
+
* Clear the entire L1 (memory) byDID cache.
|
|
5817
|
+
* L2 (IndexedDB) is preserved — agent data remains valid across sessions.
|
|
5818
|
+
*/
|
|
5819
|
+
clearByDidCache() {
|
|
5820
|
+
__classPrivateFieldGet$7(this, _AgentClient_memCache, "f").clear();
|
|
5563
5821
|
}
|
|
5564
5822
|
async updatePublicPerspective(perspective) {
|
|
5565
5823
|
const cleanedPerspective = JSON.parse(JSON.stringify(perspective));
|
|
@@ -5620,7 +5878,16 @@ class AgentClient {
|
|
|
5620
5878
|
subscribeAgentUpdated() {
|
|
5621
5879
|
const unsub = __classPrivateFieldGet$7(this, _AgentClient_apiClient, "f").subscribe((data) => {
|
|
5622
5880
|
if (data.type === 'agent-updated') {
|
|
5623
|
-
|
|
5881
|
+
const agent = (data.agent || data);
|
|
5882
|
+
// Update L1 and L2 cache from the event payload
|
|
5883
|
+
if (agent.did) {
|
|
5884
|
+
__classPrivateFieldGet$7(this, _AgentClient_memCache, "f").set(agent.did, {
|
|
5885
|
+
promise: Promise.resolve(agent),
|
|
5886
|
+
ts: Date.now(),
|
|
5887
|
+
});
|
|
5888
|
+
__classPrivateFieldGet$7(this, _AgentClient_persistent, "f").put(agent.did, agent); // fire-and-forget
|
|
5889
|
+
}
|
|
5890
|
+
__classPrivateFieldGet$7(this, _AgentClient_updatedCallbacks, "f").forEach((cb) => cb(agent));
|
|
5624
5891
|
}
|
|
5625
5892
|
});
|
|
5626
5893
|
__classPrivateFieldGet$7(this, _AgentClient_unsubscribers, "f").push(unsub);
|
|
@@ -5719,7 +5986,9 @@ class AgentClient {
|
|
|
5719
5986
|
return __classPrivateFieldGet$7(this, _AgentClient_apiClient, "f").call('hosting.requestPayment', { amountHOT });
|
|
5720
5987
|
}
|
|
5721
5988
|
}
|
|
5722
|
-
_AgentClient_apiClient = new WeakMap(), _AgentClient_baseUrl = new WeakMap(), _AgentClient_token = new WeakMap(), _AgentClient_appsChangedCallback = new WeakMap(), _AgentClient_updatedCallbacks = new WeakMap(), _AgentClient_agentStatusChangedCallbacks = new WeakMap(), _AgentClient_hostingUserInfoChangedCallbacks = new WeakMap(), _AgentClient_computeLogUpdatedCallbacks = new WeakMap(), _AgentClient_unsubscribers = new WeakMap();
|
|
5989
|
+
_AgentClient_apiClient = new WeakMap(), _AgentClient_baseUrl = new WeakMap(), _AgentClient_token = new WeakMap(), _AgentClient_appsChangedCallback = new WeakMap(), _AgentClient_updatedCallbacks = new WeakMap(), _AgentClient_agentStatusChangedCallbacks = new WeakMap(), _AgentClient_hostingUserInfoChangedCallbacks = new WeakMap(), _AgentClient_computeLogUpdatedCallbacks = new WeakMap(), _AgentClient_unsubscribers = new WeakMap(), _AgentClient_memCache = new WeakMap(), _AgentClient_persistent = new WeakMap(), _AgentClient_selfDid = new WeakMap();
|
|
5990
|
+
/** TTL for remote (non-self) agent profiles in L1 cache (ms). */
|
|
5991
|
+
AgentClient.REMOTE_AGENT_TTL_MS = 5 * 60000; // 5 minutes
|
|
5723
5992
|
|
|
5724
5993
|
var __classPrivateFieldSet$6 = (undefined && undefined.__classPrivateFieldSet) || function (receiver, state, value, kind, f) {
|
|
5725
5994
|
if (kind === "m") throw new TypeError("Private method is not writable");
|
|
@@ -6148,13 +6417,22 @@ var __classPrivateFieldGet$3 = (undefined && undefined.__classPrivateFieldGet) |
|
|
|
6148
6417
|
if (typeof state === "function" ? receiver !== state || !f : !state.has(receiver)) throw new TypeError("Cannot read private member from an object whose class did not declare it");
|
|
6149
6418
|
return kind === "m" ? f : kind === "a" ? f.call(receiver) : f ? f.value : state.get(receiver);
|
|
6150
6419
|
};
|
|
6151
|
-
var _ExpressionClient_apiClient;
|
|
6420
|
+
var _ExpressionClient_instances, _ExpressionClient_apiClient, _ExpressionClient_memCache, _ExpressionClient_inflight, _ExpressionClient_totalMemBytes, _ExpressionClient_persistent, _ExpressionClient_memCacheResult;
|
|
6152
6421
|
class ExpressionClient {
|
|
6153
6422
|
constructor(baseUrl, token, sharedApiClient) {
|
|
6423
|
+
_ExpressionClient_instances.add(this);
|
|
6154
6424
|
_ExpressionClient_apiClient.set(this, void 0);
|
|
6425
|
+
// L1: in-memory LRU cache (hot path, sub-ms)
|
|
6426
|
+
_ExpressionClient_memCache.set(this, new Map());
|
|
6427
|
+
_ExpressionClient_inflight.set(this, new Map());
|
|
6428
|
+
_ExpressionClient_totalMemBytes.set(this, 0);
|
|
6429
|
+
// L2: persistent cache (IndexedDB in browser, NullCache in Node)
|
|
6430
|
+
_ExpressionClient_persistent.set(this, void 0);
|
|
6155
6431
|
__classPrivateFieldSet$3(this, _ExpressionClient_apiClient, sharedApiClient || new ApiClient(baseUrl, token), "f");
|
|
6432
|
+
__classPrivateFieldSet$3(this, _ExpressionClient_persistent, createPersistentCache('ad4m-expression-cache', 'expressions'), "f");
|
|
6156
6433
|
}
|
|
6157
6434
|
async get(url, alwaysGet = false) {
|
|
6435
|
+
// Existing literal fast-path
|
|
6158
6436
|
if (!alwaysGet) {
|
|
6159
6437
|
try {
|
|
6160
6438
|
let literalValue = Literal.fromUrl(url).get();
|
|
@@ -6166,10 +6444,85 @@ class ExpressionClient {
|
|
|
6166
6444
|
}
|
|
6167
6445
|
catch (e) { }
|
|
6168
6446
|
}
|
|
6169
|
-
|
|
6447
|
+
// L1: memory hit
|
|
6448
|
+
if (!alwaysGet) {
|
|
6449
|
+
const memHit = __classPrivateFieldGet$3(this, _ExpressionClient_memCache, "f").get(url);
|
|
6450
|
+
if (memHit)
|
|
6451
|
+
return memHit.data;
|
|
6452
|
+
}
|
|
6453
|
+
// Deduplicate in-flight requests
|
|
6454
|
+
if (!alwaysGet) {
|
|
6455
|
+
const existing = __classPrivateFieldGet$3(this, _ExpressionClient_inflight, "f").get(url);
|
|
6456
|
+
if (existing)
|
|
6457
|
+
return existing;
|
|
6458
|
+
}
|
|
6459
|
+
// L2 check + L3 network
|
|
6460
|
+
const promise = (async () => {
|
|
6461
|
+
if (!alwaysGet) {
|
|
6462
|
+
const persisted = await __classPrivateFieldGet$3(this, _ExpressionClient_persistent, "f").get(url);
|
|
6463
|
+
if (persisted) {
|
|
6464
|
+
__classPrivateFieldGet$3(this, _ExpressionClient_instances, "m", _ExpressionClient_memCacheResult).call(this, url, persisted); // promote to L1
|
|
6465
|
+
return persisted;
|
|
6466
|
+
}
|
|
6467
|
+
}
|
|
6468
|
+
// L3: network fetch
|
|
6469
|
+
const result = await __classPrivateFieldGet$3(this, _ExpressionClient_apiClient, "f").call('expression.get', { url });
|
|
6470
|
+
__classPrivateFieldGet$3(this, _ExpressionClient_instances, "m", _ExpressionClient_memCacheResult).call(this, url, result);
|
|
6471
|
+
__classPrivateFieldGet$3(this, _ExpressionClient_persistent, "f").put(url, result); // fire-and-forget write to L2
|
|
6472
|
+
return result;
|
|
6473
|
+
})();
|
|
6474
|
+
__classPrivateFieldGet$3(this, _ExpressionClient_inflight, "f").set(url, promise);
|
|
6475
|
+
try {
|
|
6476
|
+
return await promise;
|
|
6477
|
+
}
|
|
6478
|
+
finally {
|
|
6479
|
+
__classPrivateFieldGet$3(this, _ExpressionClient_inflight, "f").delete(url);
|
|
6480
|
+
}
|
|
6170
6481
|
}
|
|
6171
6482
|
async getMany(urls) {
|
|
6172
|
-
|
|
6483
|
+
// Check L1 first
|
|
6484
|
+
const results = urls.map(u => __classPrivateFieldGet$3(this, _ExpressionClient_memCache, "f").get(u)?.data ?? null);
|
|
6485
|
+
let uncachedIndices = results
|
|
6486
|
+
.map((r, i) => r === null ? i : -1)
|
|
6487
|
+
.filter(i => i >= 0);
|
|
6488
|
+
if (uncachedIndices.length === 0)
|
|
6489
|
+
return results;
|
|
6490
|
+
// Check L2 for remaining misses
|
|
6491
|
+
const l2Results = await Promise.all(uncachedIndices.map(i => __classPrivateFieldGet$3(this, _ExpressionClient_persistent, "f").get(urls[i])));
|
|
6492
|
+
const stillMissing = [];
|
|
6493
|
+
for (let j = 0; j < uncachedIndices.length; j++) {
|
|
6494
|
+
const idx = uncachedIndices[j];
|
|
6495
|
+
if (l2Results[j]) {
|
|
6496
|
+
results[idx] = l2Results[j];
|
|
6497
|
+
__classPrivateFieldGet$3(this, _ExpressionClient_instances, "m", _ExpressionClient_memCacheResult).call(this, urls[idx], l2Results[j]); // promote to L1
|
|
6498
|
+
}
|
|
6499
|
+
else {
|
|
6500
|
+
stillMissing.push(idx);
|
|
6501
|
+
}
|
|
6502
|
+
}
|
|
6503
|
+
if (stillMissing.length === 0)
|
|
6504
|
+
return results;
|
|
6505
|
+
// L3: fetch only truly uncached URLs
|
|
6506
|
+
const uncachedUrls = stillMissing.map(i => urls[i]);
|
|
6507
|
+
const fetched = await __classPrivateFieldGet$3(this, _ExpressionClient_apiClient, "f").call('expression.getMany', { urls: uncachedUrls });
|
|
6508
|
+
for (let i = 0; i < stillMissing.length; i++) {
|
|
6509
|
+
const idx = stillMissing[i];
|
|
6510
|
+
results[idx] = fetched[i];
|
|
6511
|
+
if (fetched[i]) {
|
|
6512
|
+
__classPrivateFieldGet$3(this, _ExpressionClient_instances, "m", _ExpressionClient_memCacheResult).call(this, uncachedUrls[i], fetched[i]);
|
|
6513
|
+
__classPrivateFieldGet$3(this, _ExpressionClient_persistent, "f").put(uncachedUrls[i], fetched[i]); // fire-and-forget
|
|
6514
|
+
}
|
|
6515
|
+
}
|
|
6516
|
+
return results;
|
|
6517
|
+
}
|
|
6518
|
+
/**
|
|
6519
|
+
* Clear both L1 (memory) and L2 (persistent) expression caches.
|
|
6520
|
+
*/
|
|
6521
|
+
clearCache() {
|
|
6522
|
+
__classPrivateFieldGet$3(this, _ExpressionClient_memCache, "f").clear();
|
|
6523
|
+
__classPrivateFieldGet$3(this, _ExpressionClient_inflight, "f").clear();
|
|
6524
|
+
__classPrivateFieldSet$3(this, _ExpressionClient_totalMemBytes, 0, "f");
|
|
6525
|
+
__classPrivateFieldGet$3(this, _ExpressionClient_persistent, "f").clear(); // fire-and-forget
|
|
6173
6526
|
}
|
|
6174
6527
|
async getRaw(url) {
|
|
6175
6528
|
return __classPrivateFieldGet$3(this, _ExpressionClient_apiClient, "f").call('expression.get', { url, raw: true });
|
|
@@ -6182,10 +6535,33 @@ class ExpressionClient {
|
|
|
6182
6535
|
return __classPrivateFieldGet$3(this, _ExpressionClient_apiClient, "f").call('expression.interactions', { url });
|
|
6183
6536
|
}
|
|
6184
6537
|
async interact(url, interactionCall) {
|
|
6185
|
-
|
|
6538
|
+
const result = await __classPrivateFieldGet$3(this, _ExpressionClient_apiClient, "f").call('expression.interact', { url, interactionCall });
|
|
6539
|
+
// Interactions can mutate the expression — invalidate cache so next get() fetches fresh
|
|
6540
|
+
__classPrivateFieldGet$3(this, _ExpressionClient_memCache, "f").delete(url);
|
|
6541
|
+
__classPrivateFieldGet$3(this, _ExpressionClient_inflight, "f").delete(url);
|
|
6542
|
+
__classPrivateFieldGet$3(this, _ExpressionClient_persistent, "f").delete(url); // fire-and-forget
|
|
6543
|
+
return result;
|
|
6186
6544
|
}
|
|
6187
6545
|
}
|
|
6188
|
-
_ExpressionClient_apiClient = new WeakMap()
|
|
6546
|
+
_ExpressionClient_apiClient = new WeakMap(), _ExpressionClient_memCache = new WeakMap(), _ExpressionClient_inflight = new WeakMap(), _ExpressionClient_totalMemBytes = new WeakMap(), _ExpressionClient_persistent = new WeakMap(), _ExpressionClient_instances = new WeakSet(), _ExpressionClient_memCacheResult = function _ExpressionClient_memCacheResult(url, data) {
|
|
6547
|
+
const size = JSON.stringify(data).length;
|
|
6548
|
+
// Evict oldest entries if we'd exceed limits
|
|
6549
|
+
while (__classPrivateFieldGet$3(this, _ExpressionClient_memCache, "f").size >= ExpressionClient.MAX_MEM_ENTRIES ||
|
|
6550
|
+
__classPrivateFieldGet$3(this, _ExpressionClient_totalMemBytes, "f") + size > ExpressionClient.MAX_MEM_BYTES) {
|
|
6551
|
+
const oldest = __classPrivateFieldGet$3(this, _ExpressionClient_memCache, "f").keys().next().value;
|
|
6552
|
+
if (!oldest)
|
|
6553
|
+
break;
|
|
6554
|
+
const entry = __classPrivateFieldGet$3(this, _ExpressionClient_memCache, "f").get(oldest);
|
|
6555
|
+
__classPrivateFieldSet$3(this, _ExpressionClient_totalMemBytes, __classPrivateFieldGet$3(this, _ExpressionClient_totalMemBytes, "f") - entry.size, "f");
|
|
6556
|
+
__classPrivateFieldGet$3(this, _ExpressionClient_memCache, "f").delete(oldest);
|
|
6557
|
+
}
|
|
6558
|
+
__classPrivateFieldGet$3(this, _ExpressionClient_memCache, "f").set(url, { data, size });
|
|
6559
|
+
__classPrivateFieldSet$3(this, _ExpressionClient_totalMemBytes, __classPrivateFieldGet$3(this, _ExpressionClient_totalMemBytes, "f") + size, "f");
|
|
6560
|
+
};
|
|
6561
|
+
/** Maximum number of entries in the L1 memory cache. */
|
|
6562
|
+
ExpressionClient.MAX_MEM_ENTRIES = 200;
|
|
6563
|
+
/** Maximum total size (in bytes) of L1 memory cache values. */
|
|
6564
|
+
ExpressionClient.MAX_MEM_BYTES = 5 * 1024 * 1024; // 5 MB
|
|
6189
6565
|
|
|
6190
6566
|
var base64Js = {};
|
|
6191
6567
|
|
|
@@ -13391,721 +13767,202 @@ class AIClient {
|
|
|
13391
13767
|
}
|
|
13392
13768
|
_AIClient_apiClient = new WeakMap(), _AIClient_transcriptionUnsubscribers = new WeakMap(), _AIClient_pendingStreamIds = new WeakMap();
|
|
13393
13769
|
|
|
13394
|
-
var __classPrivateFieldSet$1 = (undefined && undefined.__classPrivateFieldSet) || function (receiver, state, value, kind, f) {
|
|
13395
|
-
if (kind === "m") throw new TypeError("Private method is not writable");
|
|
13396
|
-
if (kind === "a" && !f) throw new TypeError("Private accessor was defined without a setter");
|
|
13397
|
-
if (typeof state === "function" ? receiver !== state || !f : !state.has(receiver)) throw new TypeError("Cannot write private member to an object whose class did not declare it");
|
|
13398
|
-
return (kind === "a" ? f.call(receiver, value) : f ? f.value = value : state.set(receiver, value)), value;
|
|
13399
|
-
};
|
|
13400
|
-
var __classPrivateFieldGet$1 = (undefined && undefined.__classPrivateFieldGet) || function (receiver, state, kind, f) {
|
|
13401
|
-
if (kind === "a" && !f) throw new TypeError("Private accessor was defined without a getter");
|
|
13402
|
-
if (typeof state === "function" ? receiver !== state || !f : !state.has(receiver)) throw new TypeError("Cannot read private member from an object whose class did not declare it");
|
|
13403
|
-
return kind === "m" ? f : kind === "a" ? f.call(receiver) : f ? f.value : state.get(receiver);
|
|
13404
|
-
};
|
|
13405
|
-
var _Ad4mClient_baseUrl, _Ad4mClient_token, _Ad4mClient_apiClient, _Ad4mClient_agentClient, _Ad4mClient_expressionClient, _Ad4mClient_languageClient, _Ad4mClient_neighbourhoodClient, _Ad4mClient_perspectiveClient, _Ad4mClient_runtimeClient, _Ad4mClient_aiClient;
|
|
13406
13770
|
/**
|
|
13407
|
-
*
|
|
13408
|
-
|
|
13771
|
+
* Shared query helpers used by both the Prolog and SPARQL query pipelines.
|
|
13772
|
+
*/
|
|
13773
|
+
/**
|
|
13774
|
+
* Resolves the predicate for a parent query.
|
|
13409
13775
|
*
|
|
13410
|
-
*
|
|
13411
|
-
*
|
|
13412
|
-
*
|
|
13413
|
-
*
|
|
13776
|
+
* Uses TS discriminated union narrowing:
|
|
13777
|
+
* - Raw form (`{ id, predicate }`) → predicate used as-is
|
|
13778
|
+
* - Model form (`{ model, id, field? }`) → lookup from relation metadata
|
|
13779
|
+
* - With `field`: direct key lookup
|
|
13780
|
+
* - Without `field`: scan for a relation whose `target()` matches `childCtor`
|
|
13414
13781
|
*/
|
|
13415
|
-
|
|
13416
|
-
|
|
13417
|
-
|
|
13418
|
-
|
|
13419
|
-
|
|
13420
|
-
|
|
13421
|
-
|
|
13422
|
-
|
|
13423
|
-
|
|
13424
|
-
|
|
13425
|
-
|
|
13426
|
-
|
|
13427
|
-
|
|
13428
|
-
|
|
13429
|
-
__classPrivateFieldSet$1(this, _Ad4mClient_apiClient, new ApiClient(baseUrl, token), "f");
|
|
13430
|
-
__classPrivateFieldSet$1(this, _Ad4mClient_agentClient, new AgentClient(baseUrl, token, subscribe, __classPrivateFieldGet$1(this, _Ad4mClient_apiClient, "f")), "f");
|
|
13431
|
-
__classPrivateFieldSet$1(this, _Ad4mClient_expressionClient, new ExpressionClient(baseUrl, token, __classPrivateFieldGet$1(this, _Ad4mClient_apiClient, "f")), "f");
|
|
13432
|
-
__classPrivateFieldSet$1(this, _Ad4mClient_languageClient, new LanguageClient(baseUrl, token, __classPrivateFieldGet$1(this, _Ad4mClient_apiClient, "f")), "f");
|
|
13433
|
-
__classPrivateFieldSet$1(this, _Ad4mClient_neighbourhoodClient, new NeighbourhoodClient(baseUrl, token, __classPrivateFieldGet$1(this, _Ad4mClient_apiClient, "f")), "f");
|
|
13434
|
-
__classPrivateFieldSet$1(this, _Ad4mClient_aiClient, new AIClient(baseUrl, token, subscribe, __classPrivateFieldGet$1(this, _Ad4mClient_apiClient, "f")), "f");
|
|
13435
|
-
__classPrivateFieldSet$1(this, _Ad4mClient_perspectiveClient, new PerspectiveClient(baseUrl, token, subscribe, __classPrivateFieldGet$1(this, _Ad4mClient_apiClient, "f")), "f");
|
|
13436
|
-
__classPrivateFieldGet$1(this, _Ad4mClient_perspectiveClient, "f").setExpressionClient(__classPrivateFieldGet$1(this, _Ad4mClient_expressionClient, "f"));
|
|
13437
|
-
__classPrivateFieldGet$1(this, _Ad4mClient_perspectiveClient, "f").setNeighbourhoodClient(__classPrivateFieldGet$1(this, _Ad4mClient_neighbourhoodClient, "f"));
|
|
13438
|
-
__classPrivateFieldGet$1(this, _Ad4mClient_perspectiveClient, "f").setAIClient(__classPrivateFieldGet$1(this, _Ad4mClient_aiClient, "f"));
|
|
13439
|
-
__classPrivateFieldSet$1(this, _Ad4mClient_runtimeClient, new RuntimeClient(baseUrl, token, subscribe, __classPrivateFieldGet$1(this, _Ad4mClient_apiClient, "f")), "f");
|
|
13440
|
-
}
|
|
13441
|
-
get agent() {
|
|
13442
|
-
return __classPrivateFieldGet$1(this, _Ad4mClient_agentClient, "f");
|
|
13443
|
-
}
|
|
13444
|
-
get expression() {
|
|
13445
|
-
return __classPrivateFieldGet$1(this, _Ad4mClient_expressionClient, "f");
|
|
13446
|
-
}
|
|
13447
|
-
get languages() {
|
|
13448
|
-
return __classPrivateFieldGet$1(this, _Ad4mClient_languageClient, "f");
|
|
13449
|
-
}
|
|
13450
|
-
get neighbourhood() {
|
|
13451
|
-
return __classPrivateFieldGet$1(this, _Ad4mClient_neighbourhoodClient, "f");
|
|
13452
|
-
}
|
|
13453
|
-
get perspective() {
|
|
13454
|
-
return __classPrivateFieldGet$1(this, _Ad4mClient_perspectiveClient, "f");
|
|
13455
|
-
}
|
|
13456
|
-
get runtime() {
|
|
13457
|
-
return __classPrivateFieldGet$1(this, _Ad4mClient_runtimeClient, "f");
|
|
13782
|
+
function resolveParentPredicate(parent, childCtor) {
|
|
13783
|
+
// Raw form — explicit predicate
|
|
13784
|
+
if ('predicate' in parent)
|
|
13785
|
+
return parent.predicate;
|
|
13786
|
+
// Model form — resolve from relation metadata
|
|
13787
|
+
const { model } = parent;
|
|
13788
|
+
const relMeta = getRelationsMetadata(model);
|
|
13789
|
+
// Direct lookup by field name when provided
|
|
13790
|
+
if (parent.field) {
|
|
13791
|
+
const entry = relMeta[parent.field];
|
|
13792
|
+
if (!entry) {
|
|
13793
|
+
throw new Error(`parent(): field "${parent.field}" is not a registered relation on ${model.name}`);
|
|
13794
|
+
}
|
|
13795
|
+
return entry.predicate;
|
|
13458
13796
|
}
|
|
13459
|
-
|
|
13460
|
-
|
|
13797
|
+
// Fallback: scan for a relation whose target matches the child class
|
|
13798
|
+
for (const [, entry] of Object.entries(relMeta)) {
|
|
13799
|
+
if (entry.target && entry.target() === childCtor) {
|
|
13800
|
+
return entry.predicate;
|
|
13801
|
+
}
|
|
13461
13802
|
}
|
|
13462
|
-
|
|
13463
|
-
|
|
13464
|
-
|
|
13465
|
-
|
|
13466
|
-
|
|
13467
|
-
|
|
13803
|
+
throw new Error(`parent(): could not resolve predicate — no relation on ${model.name} targets ${childCtor.name || 'the queried class'}`);
|
|
13804
|
+
}
|
|
13805
|
+
|
|
13806
|
+
/**
|
|
13807
|
+
* JSON Schema → Ad4mModel class builder and related utilities.
|
|
13808
|
+
*
|
|
13809
|
+
* Contains:
|
|
13810
|
+
* - JSON Schema type definitions (JSONSchemaProperty, JSONSchema, JSONSchemaToModelOptions)
|
|
13811
|
+
* - Schema type helpers (normalizeNamespaceString, isArrayType, etc.)
|
|
13812
|
+
* - Predicate / namespace resolution helpers
|
|
13813
|
+
* - `buildModelFromJSONSchema()` — core implementation of `Ad4mModel.fromJSONSchema()`
|
|
13814
|
+
*
|
|
13815
|
+
* @module
|
|
13816
|
+
*/
|
|
13817
|
+
// ─── Schema Type Helpers ─────────────────────────────────────────────────────
|
|
13818
|
+
function normalizeNamespaceString(namespace) {
|
|
13819
|
+
if (!namespace)
|
|
13820
|
+
return '';
|
|
13821
|
+
if (namespace.includes('://')) {
|
|
13822
|
+
const [scheme, rest] = namespace.split('://');
|
|
13823
|
+
const path = (rest || '').replace(/\/+$/, '');
|
|
13824
|
+
return `${scheme}://${path}`;
|
|
13468
13825
|
}
|
|
13469
|
-
|
|
13470
|
-
|
|
13471
|
-
__classPrivateFieldGet$1(this, _Ad4mClient_apiClient, "f").closeAll();
|
|
13826
|
+
else {
|
|
13827
|
+
return namespace.replace(/\/+$/, '');
|
|
13472
13828
|
}
|
|
13473
13829
|
}
|
|
13474
|
-
|
|
13475
|
-
|
|
13476
|
-
|
|
13477
|
-
(
|
|
13478
|
-
|
|
13479
|
-
|
|
13480
|
-
|
|
13481
|
-
|
|
13482
|
-
ExceptionType["InstallNotificationRequest"] = "INSTALL_NOTIFICATION_REQUEST";
|
|
13483
|
-
})(ExceptionType || (ExceptionType = {}));
|
|
13484
|
-
|
|
13485
|
-
// Unique Language ID with option type
|
|
13486
|
-
class LanguageRef {
|
|
13487
|
-
constructor(address, name) {
|
|
13488
|
-
this.address = address;
|
|
13489
|
-
this.name = name;
|
|
13830
|
+
function normalizeSchemaType(type) {
|
|
13831
|
+
if (!type)
|
|
13832
|
+
return undefined;
|
|
13833
|
+
if (typeof type === "string")
|
|
13834
|
+
return type;
|
|
13835
|
+
if (Array.isArray(type) && type.length > 0) {
|
|
13836
|
+
const nonNull = type.find((t) => t !== "null");
|
|
13837
|
+
return nonNull || type[0];
|
|
13490
13838
|
}
|
|
13839
|
+
return undefined;
|
|
13491
13840
|
}
|
|
13492
|
-
|
|
13493
|
-
|
|
13494
|
-
class ExpressionRef {
|
|
13495
|
-
constructor(lang, expr) {
|
|
13496
|
-
this.language = lang;
|
|
13497
|
-
this.expression = expr;
|
|
13498
|
-
}
|
|
13841
|
+
function isSchemaType(schema, expectedType) {
|
|
13842
|
+
return normalizeSchemaType(schema.type) === expectedType;
|
|
13499
13843
|
}
|
|
13500
|
-
|
|
13501
|
-
|
|
13502
|
-
function exprRef2String(ref) {
|
|
13503
|
-
if (ref.language.address === 'did')
|
|
13504
|
-
return ref.expression.toString();
|
|
13505
|
-
else
|
|
13506
|
-
return `${ref.language.address}://${ref.expression}`;
|
|
13844
|
+
function isArrayType(schema) {
|
|
13845
|
+
return isSchemaType(schema, "array");
|
|
13507
13846
|
}
|
|
13508
|
-
function
|
|
13509
|
-
|
|
13510
|
-
const languageRef = new LanguageRef();
|
|
13511
|
-
languageRef.address = 'literal';
|
|
13512
|
-
languageRef.name = 'literal';
|
|
13513
|
-
const content = url.substring(8);
|
|
13514
|
-
return new ExpressionRef(languageRef, content);
|
|
13515
|
-
}
|
|
13516
|
-
const URIregexp = /^([^:^\s]+):\/\/([\s\S]+)$/;
|
|
13517
|
-
const URImatches = URIregexp.exec(url);
|
|
13518
|
-
if (URImatches && URImatches.length == 3) {
|
|
13519
|
-
const language = URImatches[1];
|
|
13520
|
-
const expression = URImatches[2];
|
|
13521
|
-
const languageRef = new LanguageRef();
|
|
13522
|
-
languageRef.address = language;
|
|
13523
|
-
const ref = new ExpressionRef(languageRef, expression);
|
|
13524
|
-
return ref;
|
|
13525
|
-
}
|
|
13526
|
-
const DIDregexp = /^did:([^\s]+)$/;
|
|
13527
|
-
const DIDmatches = DIDregexp.exec(url);
|
|
13528
|
-
if (DIDmatches && DIDmatches.length == 2) {
|
|
13529
|
-
const languageRef = new LanguageRef();
|
|
13530
|
-
languageRef.address = 'did';
|
|
13531
|
-
const ref = new ExpressionRef(languageRef, url);
|
|
13532
|
-
return ref;
|
|
13533
|
-
}
|
|
13534
|
-
throw new Error("Couldn't parse string as expression URL or DID: " + url);
|
|
13847
|
+
function isObjectType(schema) {
|
|
13848
|
+
return isSchemaType(schema, "object");
|
|
13535
13849
|
}
|
|
13536
|
-
|
|
13537
|
-
|
|
13538
|
-
|
|
13539
|
-
this.code = code;
|
|
13540
|
-
}
|
|
13850
|
+
function isNumericType(schema) {
|
|
13851
|
+
const normalized = normalizeSchemaType(schema.type);
|
|
13852
|
+
return normalized === "number" || normalized === "integer";
|
|
13541
13853
|
}
|
|
13542
|
-
|
|
13854
|
+
// ─── Predicate / Namespace Resolution ────────────────────────────────────────
|
|
13543
13855
|
/**
|
|
13544
|
-
*
|
|
13545
|
-
*
|
|
13546
|
-
*
|
|
13547
|
-
*
|
|
13548
|
-
*
|
|
13549
|
-
*
|
|
13550
|
-
* **If you're authoring an AD4M Language**, you don't consume types from
|
|
13551
|
-
* here — use [`@coasys/ad4m-ldk`](https://www.npmjs.com/package/@coasys/ad4m-ldk)
|
|
13552
|
-
* (or the [Rust ALDK](https://crates.io/crates/ad4m-ldk)), which provide
|
|
13553
|
-
* the capability traits, typed runtime-import wrappers, and authoring
|
|
13554
|
-
* macros/helpers.
|
|
13555
|
-
*
|
|
13556
|
-
* The normative interface definition lives in
|
|
13557
|
-
* [`docs-src/ad4m-lang.wit`](https://github.com/coasys/ad4m/blob/dev/docs-src/ad4m-lang.wit).
|
|
13558
|
-
* The prose spec is
|
|
13559
|
-
* [`docs-src/language-interface-spec.md`](https://github.com/coasys/ad4m/blob/dev/docs-src/language-interface-spec.md).
|
|
13856
|
+
* Determines the namespace for predicates using cascading precedence:
|
|
13857
|
+
* 1. Explicit namespace in options
|
|
13858
|
+
* 2. x-ad4m metadata in schema
|
|
13859
|
+
* 3. Infer from schema title
|
|
13860
|
+
* 4. Try to extract from $id
|
|
13861
|
+
* 5. Error if nothing works
|
|
13560
13862
|
*/
|
|
13561
|
-
|
|
13562
|
-
//
|
|
13563
|
-
|
|
13564
|
-
|
|
13565
|
-
// the API as first-class objects.
|
|
13566
|
-
class InteractionParameter {
|
|
13567
|
-
}
|
|
13568
|
-
class InteractionMeta {
|
|
13569
|
-
}
|
|
13570
|
-
class InteractionCall {
|
|
13571
|
-
get parameters() {
|
|
13572
|
-
return JSON.parse(this.parametersStringified);
|
|
13863
|
+
function determineNamespace(schema, options) {
|
|
13864
|
+
// 1. Explicit namespace in options (highest precedence)
|
|
13865
|
+
if (options.namespace) {
|
|
13866
|
+
return options.namespace;
|
|
13573
13867
|
}
|
|
13574
|
-
|
|
13575
|
-
|
|
13576
|
-
|
|
13868
|
+
// 2. x-ad4m metadata in schema
|
|
13869
|
+
if (schema["x-ad4m"]?.namespace) {
|
|
13870
|
+
return schema["x-ad4m"].namespace;
|
|
13577
13871
|
}
|
|
13578
|
-
|
|
13579
|
-
|
|
13580
|
-
|
|
13581
|
-
}
|
|
13582
|
-
|
|
13583
|
-
class LanguageHandle {
|
|
13584
|
-
}
|
|
13585
|
-
|
|
13586
|
-
class LanguageMeta {
|
|
13587
|
-
}
|
|
13588
|
-
class LanguageMetaInput {
|
|
13589
|
-
constructor(name, description) {
|
|
13590
|
-
this.name = name;
|
|
13591
|
-
this.description = description;
|
|
13592
|
-
if (!this.description)
|
|
13593
|
-
this.description = "";
|
|
13872
|
+
// 3. Infer from schema title
|
|
13873
|
+
if (schema.title) {
|
|
13874
|
+
return `${schema.title.toLowerCase()}://`;
|
|
13594
13875
|
}
|
|
13595
|
-
|
|
13596
|
-
|
|
13597
|
-
|
|
13598
|
-
|
|
13599
|
-
|
|
13600
|
-
|
|
13601
|
-
|
|
13602
|
-
|
|
13603
|
-
|
|
13604
|
-
|
|
13605
|
-
PerspectiveState["Private"] = "PRIVATE";
|
|
13606
|
-
PerspectiveState["NeighboudhoodCreationInitiated"] = "NEIGHBOURHOOD_CREATION_INITIATED";
|
|
13607
|
-
PerspectiveState["NeighbourhoodJoinInitiated"] = "NEIGHBOURHOOD_JOIN_INITIATED";
|
|
13608
|
-
PerspectiveState["LinkLanguageFailedToInstall"] = "LINK_LANGUAGE_FAILED_TO_INSTALL";
|
|
13609
|
-
PerspectiveState["LinkLanguageInstalledButNotSynced"] = "LINK_LANGUAGE_INSTALLED_BUT_NOT_SYNCED";
|
|
13610
|
-
PerspectiveState["Synced"] = "SYNCED";
|
|
13611
|
-
})(PerspectiveState || (PerspectiveState = {}));
|
|
13612
|
-
// This type is used in the REST interface to reference a mutable
|
|
13613
|
-
// prespective that is implemented locally by the Ad4m runtime.
|
|
13614
|
-
// The UUID is used in mutations to identify the perspective that gets mutated.
|
|
13615
|
-
class PerspectiveHandle {
|
|
13616
|
-
constructor(uuid, name, state) {
|
|
13617
|
-
this.uuid = uuid;
|
|
13618
|
-
this.name = name;
|
|
13619
|
-
if (state) {
|
|
13620
|
-
this.state = state;
|
|
13876
|
+
// 4. Try to extract from $id if it's a URL
|
|
13877
|
+
if (schema.$id) {
|
|
13878
|
+
try {
|
|
13879
|
+
const url = new URL(schema.$id);
|
|
13880
|
+
const pathParts = url.pathname.split('/').filter(p => p);
|
|
13881
|
+
if (pathParts.length > 0) {
|
|
13882
|
+
const lastPart = pathParts[pathParts.length - 1];
|
|
13883
|
+
const baseName = lastPart.replace(/\.schema\.json$/, '').replace(/\.json$/, '');
|
|
13884
|
+
return `${baseName.toLowerCase()}://`;
|
|
13885
|
+
}
|
|
13621
13886
|
}
|
|
13622
|
-
|
|
13623
|
-
|
|
13887
|
+
catch {
|
|
13888
|
+
// If $id is not a valid URL, continue to error
|
|
13624
13889
|
}
|
|
13625
13890
|
}
|
|
13891
|
+
// 5. Error if no namespace can be determined
|
|
13892
|
+
throw new Error(`Cannot infer namespace for JSON Schema. Please provide one of:
|
|
13893
|
+
- options.namespace
|
|
13894
|
+
- schema["x-ad4m"].namespace
|
|
13895
|
+
- schema.title
|
|
13896
|
+
- valid schema.$id`);
|
|
13626
13897
|
}
|
|
13627
|
-
|
|
13628
13898
|
/**
|
|
13629
|
-
*
|
|
13630
|
-
*
|
|
13631
|
-
*
|
|
13632
|
-
*
|
|
13633
|
-
*
|
|
13634
|
-
*
|
|
13899
|
+
* Determines the predicate for a specific property using cascading precedence:
|
|
13900
|
+
* 1. Explicit property mapping
|
|
13901
|
+
* 2. x-ad4m metadata in property schema
|
|
13902
|
+
* 3. Predicate template
|
|
13903
|
+
* 4. Custom predicate generator
|
|
13904
|
+
* 5. Default: namespace + property name
|
|
13635
13905
|
*/
|
|
13636
|
-
|
|
13637
|
-
|
|
13638
|
-
|
|
13639
|
-
|
|
13640
|
-
this.debounceTimers = new Map();
|
|
13641
|
-
/** Per-subscription set of already-processed message addresses (for mention subs)
|
|
13642
|
-
* or serialized result hash (for channel-messages subs). */
|
|
13643
|
-
this.seenMessages = new Map();
|
|
13644
|
-
this.perspectiveClient = options.perspectiveClient;
|
|
13645
|
-
this.logger = options.logger;
|
|
13646
|
-
this.debounceMs = options.debounceMs ?? 2000;
|
|
13647
|
-
this.onWake = options.onWake;
|
|
13648
|
-
this.onPersist = options.onPersist;
|
|
13649
|
-
this.QuerySubscriptionProxyCtor = options.QuerySubscriptionProxy ?? null;
|
|
13650
|
-
this.previousSeenMessages = options.previousSeenMessages ?? {};
|
|
13906
|
+
function determinePredicate(schema, propertyName, propertySchema, namespace, options) {
|
|
13907
|
+
// 1. Explicit property mapping (highest precedence)
|
|
13908
|
+
if (options.propertyMapping?.[propertyName]) {
|
|
13909
|
+
return options.propertyMapping[propertyName];
|
|
13651
13910
|
}
|
|
13652
|
-
|
|
13653
|
-
|
|
13654
|
-
|
|
13655
|
-
*/
|
|
13656
|
-
async subscribe(sub) {
|
|
13657
|
-
// Dispose existing subscription with same id if any
|
|
13658
|
-
this.dispose(sub.id, false);
|
|
13659
|
-
if (!this.QuerySubscriptionProxyCtor) {
|
|
13660
|
-
throw new Error("WakerSubscriptionManager: QuerySubscriptionProxy must be provided via constructor options");
|
|
13661
|
-
}
|
|
13662
|
-
const QuerySubscriptionProxy = this.QuerySubscriptionProxyCtor;
|
|
13663
|
-
this.logger.info(`[waker] ${sub.id}: creating subscription (perspective=${sub.perspective}, type=${sub.type})`);
|
|
13664
|
-
this.logger.info(`[waker] ${sub.id}: SPARQL query:\n${sub.query}`);
|
|
13665
|
-
const proxy = new QuerySubscriptionProxy(sub.perspective, sub.query, this.perspectiveClient);
|
|
13666
|
-
proxy.isSPARQL = true;
|
|
13667
|
-
// Suppress unhandled rejection from proxy.initialized — QuerySubscriptionProxy
|
|
13668
|
-
// rejects this promise internally when subscribe() fails, and if nobody catches
|
|
13669
|
-
// it before the next microtask it crashes the process.
|
|
13670
|
-
if (proxy.initialized && typeof proxy.initialized.catch === "function") {
|
|
13671
|
-
proxy.initialized.catch(() => { });
|
|
13672
|
-
}
|
|
13673
|
-
try {
|
|
13674
|
-
await proxy.subscribe();
|
|
13675
|
-
await proxy.initialized;
|
|
13676
|
-
}
|
|
13677
|
-
catch (err) {
|
|
13678
|
-
const msg = err?.message ?? String(err);
|
|
13679
|
-
this.logger.warn(`[waker] ${sub.id}: subscription failed — ${msg}`);
|
|
13680
|
-
try {
|
|
13681
|
-
proxy.dispose();
|
|
13682
|
-
}
|
|
13683
|
-
catch { }
|
|
13684
|
-
// Remove from active state so it doesn't get persisted/retried
|
|
13685
|
-
this.activeSubscriptions.delete(sub.id);
|
|
13686
|
-
this.seenMessages.delete(sub.id);
|
|
13687
|
-
this.persist();
|
|
13688
|
-
return; // Don't throw — caller should not crash
|
|
13689
|
-
}
|
|
13690
|
-
this.logger.info(`[waker] ${sub.id}: subscription initialized successfully`);
|
|
13691
|
-
// Seed from persisted seen messages so we don't re-wake after restart
|
|
13692
|
-
const seen = new Set(this.previousSeenMessages[sub.id] ?? []);
|
|
13693
|
-
this.seenMessages.set(sub.id, seen);
|
|
13694
|
-
if (seen.size > 0) {
|
|
13695
|
-
this.logger.info(`[waker] ${sub.id}: seeded ${seen.size} seen message(s) from persisted state`);
|
|
13696
|
-
}
|
|
13697
|
-
proxy.onResult(async (result) => {
|
|
13698
|
-
this.logger.info(`[waker] ${sub.id}: onResult fired — type=${typeof result}, isArray=${Array.isArray(result)}, value=${String(JSON.stringify(result)).substring(0, 500)}`);
|
|
13699
|
-
// Query engine can deliver non-array values (e.g. false) on disconnect/reconnect — ignore them
|
|
13700
|
-
if (!Array.isArray(result)) {
|
|
13701
|
-
this.logger.warn(`[waker] ${sub.id}: ignoring non-array result: ${JSON.stringify(result)}`);
|
|
13702
|
-
return;
|
|
13703
|
-
}
|
|
13704
|
-
if (sub.type === "mention") {
|
|
13705
|
-
// For mention subscriptions: track seen message addresses.
|
|
13706
|
-
// Only wake for messages we haven't seen before.
|
|
13707
|
-
const currentSeen = this.seenMessages.get(sub.id) ?? new Set();
|
|
13708
|
-
const newMessages = [];
|
|
13709
|
-
for (const item of result) {
|
|
13710
|
-
if (item && item.source && !currentSeen.has(item.source)) {
|
|
13711
|
-
newMessages.push(item.source);
|
|
13712
|
-
}
|
|
13713
|
-
}
|
|
13714
|
-
if (newMessages.length === 0) {
|
|
13715
|
-
this.logger.info(`[waker] ${sub.id}: all ${result.length} items already seen, skipping`);
|
|
13716
|
-
return;
|
|
13717
|
-
}
|
|
13718
|
-
this.logger.info(`[waker] ${sub.id}: ${newMessages.length} new message(s) out of ${result.length} total`);
|
|
13719
|
-
// Resolve parents per new message
|
|
13720
|
-
const mentions = [];
|
|
13721
|
-
for (const msgAddr of newMessages) {
|
|
13722
|
-
const parents = [];
|
|
13723
|
-
try {
|
|
13724
|
-
const parentQuery = `SELECT ?source WHERE { ?source <ad4m://has_child> <${msgAddr}> . }`;
|
|
13725
|
-
this.logger.info(`[waker] ${sub.id}: resolving parents for ${msgAddr}`);
|
|
13726
|
-
const parentResult = await this.perspectiveClient.querySparql(sub.perspective, parentQuery);
|
|
13727
|
-
if (Array.isArray(parentResult)) {
|
|
13728
|
-
for (const link of parentResult) {
|
|
13729
|
-
if (link && link.source) {
|
|
13730
|
-
parents.push(link.source);
|
|
13731
|
-
}
|
|
13732
|
-
}
|
|
13733
|
-
}
|
|
13734
|
-
}
|
|
13735
|
-
catch (err) {
|
|
13736
|
-
this.logger.warn(`[waker] ${sub.id}: parent resolution failed for ${msgAddr} — ${err?.message ?? err}`);
|
|
13737
|
-
}
|
|
13738
|
-
this.logger.info(`[waker] ${sub.id}: message ${msgAddr} has ${parents.length} parent(s): ${parents.join(", ")}`);
|
|
13739
|
-
mentions.push({ address: msgAddr, parents });
|
|
13740
|
-
}
|
|
13741
|
-
// Mark all new messages as seen
|
|
13742
|
-
for (const addr of newMessages) {
|
|
13743
|
-
currentSeen.add(addr);
|
|
13744
|
-
}
|
|
13745
|
-
this.seenMessages.set(sub.id, currentSeen);
|
|
13746
|
-
// Debounce the wake callback
|
|
13747
|
-
const existing = this.debounceTimers.get(sub.id);
|
|
13748
|
-
if (existing)
|
|
13749
|
-
clearTimeout(existing);
|
|
13750
|
-
this.debounceTimers.set(sub.id, setTimeout(() => {
|
|
13751
|
-
this.onWake(sub, result, mentions);
|
|
13752
|
-
this.debounceTimers.delete(sub.id);
|
|
13753
|
-
this.persist();
|
|
13754
|
-
}, this.debounceMs));
|
|
13755
|
-
}
|
|
13756
|
-
else {
|
|
13757
|
-
// For channel-messages: always notify the agent on every subscription push.
|
|
13758
|
-
// No deduplication — the agent reads recent messages itself.
|
|
13759
|
-
this.logger.info(`[waker] ${sub.id}: channel update (${result.length} items)`);
|
|
13760
|
-
const existing = this.debounceTimers.get(sub.id);
|
|
13761
|
-
if (existing)
|
|
13762
|
-
clearTimeout(existing);
|
|
13763
|
-
this.debounceTimers.set(sub.id, setTimeout(() => {
|
|
13764
|
-
this.onWake(sub, result);
|
|
13765
|
-
this.debounceTimers.delete(sub.id);
|
|
13766
|
-
}, this.debounceMs));
|
|
13767
|
-
}
|
|
13768
|
-
});
|
|
13769
|
-
this.proxies.set(sub.id, proxy);
|
|
13770
|
-
this.activeSubscriptions.set(sub.id, sub);
|
|
13771
|
-
this.persist();
|
|
13772
|
-
this.logger.info(`[waker] Subscription ${sub.id} active (type=${sub.type}, perspective=${sub.perspective})`);
|
|
13773
|
-
}
|
|
13774
|
-
/**
|
|
13775
|
-
* Dispose a single subscription.
|
|
13776
|
-
* @param persist — if false, skip calling onPersist (used during batch cleanup).
|
|
13777
|
-
*/
|
|
13778
|
-
dispose(id, persist = true) {
|
|
13779
|
-
const proxy = this.proxies.get(id);
|
|
13780
|
-
if (proxy) {
|
|
13781
|
-
try {
|
|
13782
|
-
proxy.dispose();
|
|
13783
|
-
}
|
|
13784
|
-
catch {
|
|
13785
|
-
/* ignore */
|
|
13786
|
-
}
|
|
13787
|
-
this.proxies.delete(id);
|
|
13788
|
-
}
|
|
13789
|
-
const timer = this.debounceTimers.get(id);
|
|
13790
|
-
if (timer) {
|
|
13791
|
-
clearTimeout(timer);
|
|
13792
|
-
this.debounceTimers.delete(id);
|
|
13793
|
-
}
|
|
13794
|
-
this.activeSubscriptions.delete(id);
|
|
13795
|
-
this.seenMessages.delete(id);
|
|
13796
|
-
if (persist)
|
|
13797
|
-
this.persist();
|
|
13798
|
-
}
|
|
13799
|
-
/** Dispose all active subscriptions. */
|
|
13800
|
-
disposeAll() {
|
|
13801
|
-
for (const [id] of this.proxies) {
|
|
13802
|
-
this.dispose(id, false);
|
|
13803
|
-
}
|
|
13911
|
+
// 2. x-ad4m metadata in property schema
|
|
13912
|
+
if (propertySchema["x-ad4m"]?.through) {
|
|
13913
|
+
return propertySchema["x-ad4m"].through;
|
|
13804
13914
|
}
|
|
13805
|
-
|
|
13806
|
-
|
|
13807
|
-
|
|
13915
|
+
// 3. Generate from namespace + property name
|
|
13916
|
+
if (options.predicateTemplate) {
|
|
13917
|
+
const normalizedNs = normalizeNamespaceString(namespace);
|
|
13918
|
+
const [scheme, rest] = normalizedNs.includes('://') ? normalizedNs.split('://') : ['', normalizedNs];
|
|
13919
|
+
const nsNoScheme = rest || '';
|
|
13920
|
+
return options.predicateTemplate
|
|
13921
|
+
.replace('${namespace}', nsNoScheme)
|
|
13922
|
+
.replace('${scheme}', scheme)
|
|
13923
|
+
.replace('${ns}', nsNoScheme)
|
|
13924
|
+
.replace('${title}', schema.title || '')
|
|
13925
|
+
.replace('${property}', propertyName);
|
|
13808
13926
|
}
|
|
13809
|
-
|
|
13810
|
-
|
|
13811
|
-
return
|
|
13927
|
+
// 4. Custom predicate generator
|
|
13928
|
+
if (options.predicateGenerator) {
|
|
13929
|
+
return options.predicateGenerator(schema.title || '', propertyName);
|
|
13812
13930
|
}
|
|
13813
|
-
|
|
13814
|
-
|
|
13815
|
-
|
|
13816
|
-
|
|
13817
|
-
|
|
13818
|
-
}
|
|
13819
|
-
this.onPersist(this.getActive(), seen);
|
|
13820
|
-
}
|
|
13931
|
+
// 5. Default: namespace + property name
|
|
13932
|
+
const normalizedNs = normalizeNamespaceString(namespace);
|
|
13933
|
+
if (normalizedNs.includes('://')) {
|
|
13934
|
+
// For namespaces like "product://", append property directly
|
|
13935
|
+
return `${normalizedNs}${propertyName}`;
|
|
13821
13936
|
}
|
|
13822
|
-
|
|
13823
|
-
|
|
13824
|
-
class PerspectiveDiff {
|
|
13825
|
-
}
|
|
13826
|
-
class PerspectiveDiffExpression extends ExpressionGeneric() {
|
|
13827
|
-
}
|
|
13828
|
-
|
|
13829
|
-
var __classPrivateFieldSet = (undefined && undefined.__classPrivateFieldSet) || function (receiver, state, value, kind, f) {
|
|
13830
|
-
if (kind === "m") throw new TypeError("Private method is not writable");
|
|
13831
|
-
if (kind === "a" && !f) throw new TypeError("Private accessor was defined without a setter");
|
|
13832
|
-
if (typeof state === "function" ? receiver !== state || !f : !state.has(receiver)) throw new TypeError("Cannot write private member to an object whose class did not declare it");
|
|
13833
|
-
return (kind === "a" ? f.call(receiver, value) : f ? f.value = value : state.set(receiver, value)), value;
|
|
13834
|
-
};
|
|
13835
|
-
var __classPrivateFieldGet = (undefined && undefined.__classPrivateFieldGet) || function (receiver, state, kind, f) {
|
|
13836
|
-
if (kind === "a" && !f) throw new TypeError("Private accessor was defined without a getter");
|
|
13837
|
-
if (typeof state === "function" ? receiver !== state || !f : !state.has(receiver)) throw new TypeError("Cannot read private member from an object whose class did not declare it");
|
|
13838
|
-
return kind === "m" ? f : kind === "a" ? f.call(receiver) : f ? f.value : state.get(receiver);
|
|
13839
|
-
};
|
|
13840
|
-
var _SmartLiteral_perspective, _SmartLiteral_base;
|
|
13841
|
-
const SMART_LITERAL_CONTENT_PREDICATE = "smart_literal://content";
|
|
13842
|
-
function makeRandomStringID(length) {
|
|
13843
|
-
let result = '';
|
|
13844
|
-
let characters = 'ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz0123456789';
|
|
13845
|
-
let charactersLength = characters.length;
|
|
13846
|
-
for (let i = 0; i < length; i++) {
|
|
13847
|
-
result += characters.charAt(Math.floor(Math.random() * charactersLength));
|
|
13937
|
+
else {
|
|
13938
|
+
return `${normalizedNs}://${propertyName}`;
|
|
13848
13939
|
}
|
|
13849
|
-
return result;
|
|
13850
13940
|
}
|
|
13851
|
-
|
|
13852
|
-
|
|
13853
|
-
|
|
13854
|
-
|
|
13855
|
-
|
|
13856
|
-
|
|
13857
|
-
|
|
13858
|
-
|
|
13859
|
-
|
|
13860
|
-
|
|
13861
|
-
|
|
13862
|
-
const base = Literal.from(makeRandomStringID(10)).toUrl();
|
|
13863
|
-
const smartLiteral = new SmartLiteral(perspective, base);
|
|
13864
|
-
await smartLiteral.set(literal);
|
|
13865
|
-
return smartLiteral;
|
|
13866
|
-
}
|
|
13867
|
-
static async isSmartLiteralBase(perspective, base) {
|
|
13868
|
-
let links = await perspective.get(new LinkQuery({
|
|
13869
|
-
source: base,
|
|
13870
|
-
predicate: SMART_LITERAL_CONTENT_PREDICATE
|
|
13871
|
-
}));
|
|
13872
|
-
return links.length > 0;
|
|
13873
|
-
}
|
|
13874
|
-
static async getAllSmartLiterals(perspective) {
|
|
13875
|
-
let links = await perspective.get(new LinkQuery({
|
|
13876
|
-
predicate: SMART_LITERAL_CONTENT_PREDICATE
|
|
13877
|
-
}));
|
|
13878
|
-
return links.map(link => new SmartLiteral(perspective, link.data.source));
|
|
13941
|
+
/**
|
|
13942
|
+
* Gets property-specific options using cascading precedence:
|
|
13943
|
+
* 1. Property-specific options
|
|
13944
|
+
* 2. x-ad4m metadata in property
|
|
13945
|
+
* 3. Global option
|
|
13946
|
+
* 4. Default value
|
|
13947
|
+
*/
|
|
13948
|
+
function getPropertyOption(propertyName, propertySchema, options, optionName, defaultValue) {
|
|
13949
|
+
// 1. Property-specific options
|
|
13950
|
+
if (options.propertyOptions?.[propertyName]?.[optionName] !== undefined) {
|
|
13951
|
+
return options.propertyOptions[propertyName][optionName];
|
|
13879
13952
|
}
|
|
13880
|
-
|
|
13881
|
-
|
|
13882
|
-
|
|
13883
|
-
predicate: SMART_LITERAL_CONTENT_PREDICATE
|
|
13884
|
-
}));
|
|
13885
|
-
if (!link) {
|
|
13886
|
-
throw `No content for smart literal ${__classPrivateFieldGet(this, _SmartLiteral_base, "f")}`;
|
|
13887
|
-
}
|
|
13888
|
-
return Literal.fromUrl(link).get();
|
|
13953
|
+
// 2. x-ad4m metadata in property
|
|
13954
|
+
if (propertySchema["x-ad4m"]?.[optionName] !== undefined) {
|
|
13955
|
+
return propertySchema["x-ad4m"][optionName];
|
|
13889
13956
|
}
|
|
13890
|
-
|
|
13891
|
-
|
|
13892
|
-
|
|
13893
|
-
source: __classPrivateFieldGet(this, _SmartLiteral_base, "f"),
|
|
13894
|
-
predicate: SMART_LITERAL_CONTENT_PREDICATE,
|
|
13895
|
-
target: literal.toUrl()
|
|
13896
|
-
}));
|
|
13957
|
+
// 3. Global option
|
|
13958
|
+
if (options[optionName] !== undefined) {
|
|
13959
|
+
return options[optionName];
|
|
13897
13960
|
}
|
|
13961
|
+
// 4. Default value
|
|
13962
|
+
return defaultValue;
|
|
13898
13963
|
}
|
|
13899
|
-
_SmartLiteral_perspective = new WeakMap(), _SmartLiteral_base = new WeakMap();
|
|
13900
|
-
|
|
13901
13964
|
/**
|
|
13902
|
-
*
|
|
13903
|
-
*
|
|
13904
|
-
* Extracted into a standalone module so that utility files
|
|
13905
|
-
* (`query-utils.ts`, `decorators.ts`, etc.) can import types without
|
|
13906
|
-
* creating circular runtime dependencies on `Ad4mModel.ts`.
|
|
13907
|
-
*/
|
|
13908
|
-
/** Type guard for IncludeProjection objects. */
|
|
13909
|
-
function isIncludeProjection(val) {
|
|
13910
|
-
return typeof val === 'object' && val !== null && 'from' in val;
|
|
13911
|
-
}
|
|
13912
|
-
|
|
13913
|
-
/**
|
|
13914
|
-
* Shared query helpers used by both the Prolog and SPARQL query pipelines.
|
|
13915
|
-
*/
|
|
13916
|
-
/**
|
|
13917
|
-
* Resolves the predicate for a parent query.
|
|
13918
|
-
*
|
|
13919
|
-
* Uses TS discriminated union narrowing:
|
|
13920
|
-
* - Raw form (`{ id, predicate }`) → predicate used as-is
|
|
13921
|
-
* - Model form (`{ model, id, field? }`) → lookup from relation metadata
|
|
13922
|
-
* - With `field`: direct key lookup
|
|
13923
|
-
* - Without `field`: scan for a relation whose `target()` matches `childCtor`
|
|
13924
|
-
*/
|
|
13925
|
-
function resolveParentPredicate(parent, childCtor) {
|
|
13926
|
-
// Raw form — explicit predicate
|
|
13927
|
-
if ('predicate' in parent)
|
|
13928
|
-
return parent.predicate;
|
|
13929
|
-
// Model form — resolve from relation metadata
|
|
13930
|
-
const { model } = parent;
|
|
13931
|
-
const relMeta = getRelationsMetadata(model);
|
|
13932
|
-
// Direct lookup by field name when provided
|
|
13933
|
-
if (parent.field) {
|
|
13934
|
-
const entry = relMeta[parent.field];
|
|
13935
|
-
if (!entry) {
|
|
13936
|
-
throw new Error(`parent(): field "${parent.field}" is not a registered relation on ${model.name}`);
|
|
13937
|
-
}
|
|
13938
|
-
return entry.predicate;
|
|
13939
|
-
}
|
|
13940
|
-
// Fallback: scan for a relation whose target matches the child class
|
|
13941
|
-
for (const [, entry] of Object.entries(relMeta)) {
|
|
13942
|
-
if (entry.target && entry.target() === childCtor) {
|
|
13943
|
-
return entry.predicate;
|
|
13944
|
-
}
|
|
13945
|
-
}
|
|
13946
|
-
throw new Error(`parent(): could not resolve predicate — no relation on ${model.name} targets ${childCtor.name || 'the queried class'}`);
|
|
13947
|
-
}
|
|
13948
|
-
|
|
13949
|
-
/**
|
|
13950
|
-
* JSON Schema → Ad4mModel class builder and related utilities.
|
|
13951
|
-
*
|
|
13952
|
-
* Contains:
|
|
13953
|
-
* - JSON Schema type definitions (JSONSchemaProperty, JSONSchema, JSONSchemaToModelOptions)
|
|
13954
|
-
* - Schema type helpers (normalizeNamespaceString, isArrayType, etc.)
|
|
13955
|
-
* - Predicate / namespace resolution helpers
|
|
13956
|
-
* - `buildModelFromJSONSchema()` — core implementation of `Ad4mModel.fromJSONSchema()`
|
|
13957
|
-
*
|
|
13958
|
-
* @module
|
|
13959
|
-
*/
|
|
13960
|
-
// ─── Schema Type Helpers ─────────────────────────────────────────────────────
|
|
13961
|
-
function normalizeNamespaceString(namespace) {
|
|
13962
|
-
if (!namespace)
|
|
13963
|
-
return '';
|
|
13964
|
-
if (namespace.includes('://')) {
|
|
13965
|
-
const [scheme, rest] = namespace.split('://');
|
|
13966
|
-
const path = (rest || '').replace(/\/+$/, '');
|
|
13967
|
-
return `${scheme}://${path}`;
|
|
13968
|
-
}
|
|
13969
|
-
else {
|
|
13970
|
-
return namespace.replace(/\/+$/, '');
|
|
13971
|
-
}
|
|
13972
|
-
}
|
|
13973
|
-
function normalizeSchemaType(type) {
|
|
13974
|
-
if (!type)
|
|
13975
|
-
return undefined;
|
|
13976
|
-
if (typeof type === "string")
|
|
13977
|
-
return type;
|
|
13978
|
-
if (Array.isArray(type) && type.length > 0) {
|
|
13979
|
-
const nonNull = type.find((t) => t !== "null");
|
|
13980
|
-
return nonNull || type[0];
|
|
13981
|
-
}
|
|
13982
|
-
return undefined;
|
|
13983
|
-
}
|
|
13984
|
-
function isSchemaType(schema, expectedType) {
|
|
13985
|
-
return normalizeSchemaType(schema.type) === expectedType;
|
|
13986
|
-
}
|
|
13987
|
-
function isArrayType(schema) {
|
|
13988
|
-
return isSchemaType(schema, "array");
|
|
13989
|
-
}
|
|
13990
|
-
function isObjectType(schema) {
|
|
13991
|
-
return isSchemaType(schema, "object");
|
|
13992
|
-
}
|
|
13993
|
-
function isNumericType(schema) {
|
|
13994
|
-
const normalized = normalizeSchemaType(schema.type);
|
|
13995
|
-
return normalized === "number" || normalized === "integer";
|
|
13996
|
-
}
|
|
13997
|
-
// ─── Predicate / Namespace Resolution ────────────────────────────────────────
|
|
13998
|
-
/**
|
|
13999
|
-
* Determines the namespace for predicates using cascading precedence:
|
|
14000
|
-
* 1. Explicit namespace in options
|
|
14001
|
-
* 2. x-ad4m metadata in schema
|
|
14002
|
-
* 3. Infer from schema title
|
|
14003
|
-
* 4. Try to extract from $id
|
|
14004
|
-
* 5. Error if nothing works
|
|
14005
|
-
*/
|
|
14006
|
-
function determineNamespace(schema, options) {
|
|
14007
|
-
// 1. Explicit namespace in options (highest precedence)
|
|
14008
|
-
if (options.namespace) {
|
|
14009
|
-
return options.namespace;
|
|
14010
|
-
}
|
|
14011
|
-
// 2. x-ad4m metadata in schema
|
|
14012
|
-
if (schema["x-ad4m"]?.namespace) {
|
|
14013
|
-
return schema["x-ad4m"].namespace;
|
|
14014
|
-
}
|
|
14015
|
-
// 3. Infer from schema title
|
|
14016
|
-
if (schema.title) {
|
|
14017
|
-
return `${schema.title.toLowerCase()}://`;
|
|
14018
|
-
}
|
|
14019
|
-
// 4. Try to extract from $id if it's a URL
|
|
14020
|
-
if (schema.$id) {
|
|
14021
|
-
try {
|
|
14022
|
-
const url = new URL(schema.$id);
|
|
14023
|
-
const pathParts = url.pathname.split('/').filter(p => p);
|
|
14024
|
-
if (pathParts.length > 0) {
|
|
14025
|
-
const lastPart = pathParts[pathParts.length - 1];
|
|
14026
|
-
const baseName = lastPart.replace(/\.schema\.json$/, '').replace(/\.json$/, '');
|
|
14027
|
-
return `${baseName.toLowerCase()}://`;
|
|
14028
|
-
}
|
|
14029
|
-
}
|
|
14030
|
-
catch {
|
|
14031
|
-
// If $id is not a valid URL, continue to error
|
|
14032
|
-
}
|
|
14033
|
-
}
|
|
14034
|
-
// 5. Error if no namespace can be determined
|
|
14035
|
-
throw new Error(`Cannot infer namespace for JSON Schema. Please provide one of:
|
|
14036
|
-
- options.namespace
|
|
14037
|
-
- schema["x-ad4m"].namespace
|
|
14038
|
-
- schema.title
|
|
14039
|
-
- valid schema.$id`);
|
|
14040
|
-
}
|
|
14041
|
-
/**
|
|
14042
|
-
* Determines the predicate for a specific property using cascading precedence:
|
|
14043
|
-
* 1. Explicit property mapping
|
|
14044
|
-
* 2. x-ad4m metadata in property schema
|
|
14045
|
-
* 3. Predicate template
|
|
14046
|
-
* 4. Custom predicate generator
|
|
14047
|
-
* 5. Default: namespace + property name
|
|
14048
|
-
*/
|
|
14049
|
-
function determinePredicate(schema, propertyName, propertySchema, namespace, options) {
|
|
14050
|
-
// 1. Explicit property mapping (highest precedence)
|
|
14051
|
-
if (options.propertyMapping?.[propertyName]) {
|
|
14052
|
-
return options.propertyMapping[propertyName];
|
|
14053
|
-
}
|
|
14054
|
-
// 2. x-ad4m metadata in property schema
|
|
14055
|
-
if (propertySchema["x-ad4m"]?.through) {
|
|
14056
|
-
return propertySchema["x-ad4m"].through;
|
|
14057
|
-
}
|
|
14058
|
-
// 3. Generate from namespace + property name
|
|
14059
|
-
if (options.predicateTemplate) {
|
|
14060
|
-
const normalizedNs = normalizeNamespaceString(namespace);
|
|
14061
|
-
const [scheme, rest] = normalizedNs.includes('://') ? normalizedNs.split('://') : ['', normalizedNs];
|
|
14062
|
-
const nsNoScheme = rest || '';
|
|
14063
|
-
return options.predicateTemplate
|
|
14064
|
-
.replace('${namespace}', nsNoScheme)
|
|
14065
|
-
.replace('${scheme}', scheme)
|
|
14066
|
-
.replace('${ns}', nsNoScheme)
|
|
14067
|
-
.replace('${title}', schema.title || '')
|
|
14068
|
-
.replace('${property}', propertyName);
|
|
14069
|
-
}
|
|
14070
|
-
// 4. Custom predicate generator
|
|
14071
|
-
if (options.predicateGenerator) {
|
|
14072
|
-
return options.predicateGenerator(schema.title || '', propertyName);
|
|
14073
|
-
}
|
|
14074
|
-
// 5. Default: namespace + property name
|
|
14075
|
-
const normalizedNs = normalizeNamespaceString(namespace);
|
|
14076
|
-
if (normalizedNs.includes('://')) {
|
|
14077
|
-
// For namespaces like "product://", append property directly
|
|
14078
|
-
return `${normalizedNs}${propertyName}`;
|
|
14079
|
-
}
|
|
14080
|
-
else {
|
|
14081
|
-
return `${normalizedNs}://${propertyName}`;
|
|
14082
|
-
}
|
|
14083
|
-
}
|
|
14084
|
-
/**
|
|
14085
|
-
* Gets property-specific options using cascading precedence:
|
|
14086
|
-
* 1. Property-specific options
|
|
14087
|
-
* 2. x-ad4m metadata in property
|
|
14088
|
-
* 3. Global option
|
|
14089
|
-
* 4. Default value
|
|
14090
|
-
*/
|
|
14091
|
-
function getPropertyOption(propertyName, propertySchema, options, optionName, defaultValue) {
|
|
14092
|
-
// 1. Property-specific options
|
|
14093
|
-
if (options.propertyOptions?.[propertyName]?.[optionName] !== undefined) {
|
|
14094
|
-
return options.propertyOptions[propertyName][optionName];
|
|
14095
|
-
}
|
|
14096
|
-
// 2. x-ad4m metadata in property
|
|
14097
|
-
if (propertySchema["x-ad4m"]?.[optionName] !== undefined) {
|
|
14098
|
-
return propertySchema["x-ad4m"][optionName];
|
|
14099
|
-
}
|
|
14100
|
-
// 3. Global option
|
|
14101
|
-
if (options[optionName] !== undefined) {
|
|
14102
|
-
return options[optionName];
|
|
14103
|
-
}
|
|
14104
|
-
// 4. Default value
|
|
14105
|
-
return defaultValue;
|
|
14106
|
-
}
|
|
14107
|
-
/**
|
|
14108
|
-
* Gets default value for a JSON Schema type.
|
|
13965
|
+
* Gets default value for a JSON Schema type.
|
|
14109
13966
|
*/
|
|
14110
13967
|
function getDefaultValueForType(type) {
|
|
14111
13968
|
switch (type) {
|
|
@@ -14919,25 +14776,25 @@ class ModelQueryBuilder {
|
|
|
14919
14776
|
return this;
|
|
14920
14777
|
}
|
|
14921
14778
|
/**
|
|
14922
|
-
*
|
|
14779
|
+
* Controls whether SPARQL property getters are evaluated during hydration.
|
|
14923
14780
|
*
|
|
14924
|
-
* By default, collection queries
|
|
14925
|
-
* Call `.deepQuery()`
|
|
14781
|
+
* By default, collection queries evaluate property getters (deepQuery=true).
|
|
14782
|
+
* Call `.deepQuery(false)` to skip getter evaluation for performance.
|
|
14926
14783
|
*
|
|
14784
|
+
* @param enabled - Whether to evaluate property getters (default: true)
|
|
14927
14785
|
* @returns The query builder for chaining
|
|
14928
14786
|
*
|
|
14929
14787
|
* @example
|
|
14930
14788
|
* ```typescript
|
|
14931
14789
|
* const messages = await Message.query(perspective)
|
|
14932
14790
|
* .parent(channel)
|
|
14933
|
-
* .deepQuery()
|
|
14791
|
+
* .deepQuery(false) // skip property getters for performance
|
|
14934
14792
|
* .limit(30)
|
|
14935
14793
|
* .get();
|
|
14936
|
-
* // messages[i].replyingTo is populated
|
|
14937
14794
|
* ```
|
|
14938
14795
|
*/
|
|
14939
|
-
deepQuery() {
|
|
14940
|
-
this.queryParams.deepQuery =
|
|
14796
|
+
deepQuery(enabled = true) {
|
|
14797
|
+
this.queryParams.deepQuery = enabled;
|
|
14941
14798
|
return this;
|
|
14942
14799
|
}
|
|
14943
14800
|
/**
|
|
@@ -15082,11 +14939,6 @@ class ModelQueryBuilder {
|
|
|
15082
14939
|
// Listen for subscription updates via the same GraphQL subscription channel.
|
|
15083
14940
|
// When Rust re-runs the model query and finds changed results, it pushes them.
|
|
15084
14941
|
const unsubscribe = this.perspective.client.subscribeToQueryUpdates(subscriptionId, (rawResult) => {
|
|
15085
|
-
// Skip delayed #init# messages — initial data was already returned
|
|
15086
|
-
// synchronously from modelSubscribe(). Late init messages contain stale
|
|
15087
|
-
// data that would overwrite real subscription updates.
|
|
15088
|
-
if (rawResult && rawResult.isInit)
|
|
15089
|
-
return;
|
|
15090
14942
|
try {
|
|
15091
14943
|
const results = parseResults(rawResult);
|
|
15092
14944
|
const fp = buildFingerprint(results);
|
|
@@ -15099,9 +14951,15 @@ class ModelQueryBuilder {
|
|
|
15099
14951
|
console.error('Model subscription update parse error:', e);
|
|
15100
14952
|
}
|
|
15101
14953
|
});
|
|
15102
|
-
// Set up keepalive
|
|
14954
|
+
// Set up keepalive with failure tracking
|
|
14955
|
+
let keepaliveFailures = 0;
|
|
15103
14956
|
const keepaliveTimer = setInterval(() => {
|
|
15104
|
-
this.perspective.client.keepAliveQuery(this.perspective.uuid, subscriptionId).
|
|
14957
|
+
this.perspective.client.keepAliveQuery(this.perspective.uuid, subscriptionId).then(() => {
|
|
14958
|
+
keepaliveFailures = 0;
|
|
14959
|
+
}).catch((e) => {
|
|
14960
|
+
keepaliveFailures++;
|
|
14961
|
+
console.warn(`Model subscription keepalive failed (attempt ${keepaliveFailures}) for ${subscriptionId}:`, e);
|
|
14962
|
+
});
|
|
15105
14963
|
}, 30000);
|
|
15106
14964
|
// Store dispose function
|
|
15107
14965
|
this.currentSubscription = {
|
|
@@ -15187,8 +15045,6 @@ class ModelQueryBuilder {
|
|
|
15187
15045
|
};
|
|
15188
15046
|
const initialCount = parseCount(initialModelResult);
|
|
15189
15047
|
const unsubscribe = this.perspective.client.subscribeToQueryUpdates(subscriptionId, (rawResult) => {
|
|
15190
|
-
if (rawResult && rawResult.isInit)
|
|
15191
|
-
return;
|
|
15192
15048
|
try {
|
|
15193
15049
|
callback(parseCount(rawResult));
|
|
15194
15050
|
}
|
|
@@ -15196,8 +15052,14 @@ class ModelQueryBuilder {
|
|
|
15196
15052
|
console.error('Count subscription update parse error:', e);
|
|
15197
15053
|
}
|
|
15198
15054
|
});
|
|
15055
|
+
let keepaliveFailures = 0;
|
|
15199
15056
|
const keepaliveTimer = setInterval(() => {
|
|
15200
|
-
this.perspective.client.keepAliveQuery(this.perspective.uuid, subscriptionId).
|
|
15057
|
+
this.perspective.client.keepAliveQuery(this.perspective.uuid, subscriptionId).then(() => {
|
|
15058
|
+
keepaliveFailures = 0;
|
|
15059
|
+
}).catch((e) => {
|
|
15060
|
+
keepaliveFailures++;
|
|
15061
|
+
console.warn(`Count subscription keepalive failed (attempt ${keepaliveFailures}) for ${subscriptionId}:`, e);
|
|
15062
|
+
});
|
|
15201
15063
|
}, 30000);
|
|
15202
15064
|
this.currentSubscription = {
|
|
15203
15065
|
dispose: () => {
|
|
@@ -15296,12 +15158,16 @@ class ModelQueryBuilder {
|
|
|
15296
15158
|
callback({ results, totalCount, pageSize, pageNumber });
|
|
15297
15159
|
};
|
|
15298
15160
|
const unsubscribe = this.perspective.client.subscribeToQueryUpdates(subscriptionId, (rawResult) => {
|
|
15299
|
-
if (rawResult && rawResult.isInit)
|
|
15300
|
-
return;
|
|
15301
15161
|
processResults().catch(e => console.error('Paginate subscription error:', e));
|
|
15302
15162
|
});
|
|
15163
|
+
let keepaliveFailures = 0;
|
|
15303
15164
|
const keepaliveTimer = setInterval(() => {
|
|
15304
|
-
this.perspective.client.keepAliveQuery(this.perspective.uuid, subscriptionId).
|
|
15165
|
+
this.perspective.client.keepAliveQuery(this.perspective.uuid, subscriptionId).then(() => {
|
|
15166
|
+
keepaliveFailures = 0;
|
|
15167
|
+
}).catch((e) => {
|
|
15168
|
+
keepaliveFailures++;
|
|
15169
|
+
console.warn(`Paginate subscription keepalive failed (attempt ${keepaliveFailures}) for ${subscriptionId}:`, e);
|
|
15170
|
+
});
|
|
15305
15171
|
}, 30000);
|
|
15306
15172
|
this.currentSubscription = {
|
|
15307
15173
|
dispose: () => {
|
|
@@ -15326,12 +15192,9 @@ class ModelQueryBuilder {
|
|
|
15326
15192
|
/**
|
|
15327
15193
|
* hydration.ts — Instance hydration helpers extracted from Ad4mModel.
|
|
15328
15194
|
*
|
|
15329
|
-
* After the Rust model_query pipeline migration
|
|
15330
|
-
*
|
|
15195
|
+
* After the Rust model_query pipeline migration, most hydration logic moved
|
|
15196
|
+
* to Rust. This file retains:
|
|
15331
15197
|
* - normalizeValue() — snapshot dirty-tracking
|
|
15332
|
-
* - matchesCondition() — JS-side post-filter (used by evaluateCustomGettersForInstance)
|
|
15333
|
-
* - evaluateCustomGettersForInstance() — lazy getter evaluation (Ad4mModel.evaluateGetters)
|
|
15334
|
-
* - buildConformanceGetter() — conformance SPARQL generation for relation getters
|
|
15335
15198
|
*/
|
|
15336
15199
|
// ──────────────────────────────────────────────────────────
|
|
15337
15200
|
// Pure helpers
|
|
@@ -15347,299 +15210,47 @@ function normalizeValue(value) {
|
|
|
15347
15210
|
}
|
|
15348
15211
|
return value;
|
|
15349
15212
|
}
|
|
15213
|
+
|
|
15214
|
+
// ---------------------------------------------------------------------------
|
|
15215
|
+
// Helpers for Rust-side include resolution
|
|
15216
|
+
// ---------------------------------------------------------------------------
|
|
15350
15217
|
/**
|
|
15351
|
-
*
|
|
15218
|
+
* Recursively enrich relation metadata in the shape with target class shapes
|
|
15219
|
+
* so the Rust endpoint can resolve includes in-process (no extra GraphQL
|
|
15220
|
+
* round-trips per relation).
|
|
15352
15221
|
*/
|
|
15353
|
-
function
|
|
15354
|
-
|
|
15355
|
-
|
|
15356
|
-
|
|
15357
|
-
|
|
15358
|
-
|
|
15359
|
-
|
|
15360
|
-
const
|
|
15361
|
-
//
|
|
15362
|
-
|
|
15363
|
-
|
|
15364
|
-
|
|
15365
|
-
|
|
15366
|
-
|
|
15367
|
-
|
|
15368
|
-
|
|
15369
|
-
|
|
15370
|
-
|
|
15371
|
-
|
|
15372
|
-
return value >= ops.between[0] && value <= ops.between[1];
|
|
15373
|
-
}
|
|
15374
|
-
// For all other operators (gt, gte, lt, lte, contains), we need to check ALL of them
|
|
15375
|
-
// and return true only if ALL conditions are satisfied
|
|
15376
|
-
let allConditionsMet = true;
|
|
15377
|
-
if (ops.gt !== undefined) {
|
|
15378
|
-
allConditionsMet = allConditionsMet && (value > ops.gt);
|
|
15379
|
-
}
|
|
15380
|
-
if (ops.gte !== undefined) {
|
|
15381
|
-
allConditionsMet = allConditionsMet && (value >= ops.gte);
|
|
15382
|
-
}
|
|
15383
|
-
if (ops.lt !== undefined) {
|
|
15384
|
-
allConditionsMet = allConditionsMet && (value < ops.lt);
|
|
15222
|
+
function enrichShapeForIncludes(metadata, include, allRelMeta) {
|
|
15223
|
+
for (const [relName, includeVal] of Object.entries(include)) {
|
|
15224
|
+
if (!includeVal)
|
|
15225
|
+
continue;
|
|
15226
|
+
const meta = allRelMeta[relName];
|
|
15227
|
+
if (!meta?.target)
|
|
15228
|
+
continue;
|
|
15229
|
+
const TargetClass = meta.target();
|
|
15230
|
+
// Deep-copy so we don't mutate the cached metadata
|
|
15231
|
+
const targetMeta = JSON.parse(JSON.stringify(TargetClass.getModelMetadata()));
|
|
15232
|
+
// Ensure the relation is in metadata.relations (fallback for edge cases)
|
|
15233
|
+
if (!metadata.relations[relName]) {
|
|
15234
|
+
metadata.relations[relName] = {
|
|
15235
|
+
name: relName,
|
|
15236
|
+
predicate: meta.predicate,
|
|
15237
|
+
direction: meta.kind === 'belongsToMany' || meta.kind === 'belongsToOne'
|
|
15238
|
+
? 'reverse'
|
|
15239
|
+
: 'forward',
|
|
15240
|
+
};
|
|
15385
15241
|
}
|
|
15386
|
-
|
|
15387
|
-
|
|
15388
|
-
|
|
15389
|
-
|
|
15390
|
-
|
|
15391
|
-
|
|
15392
|
-
|
|
15393
|
-
|
|
15394
|
-
|
|
15395
|
-
|
|
15396
|
-
|
|
15397
|
-
|
|
15398
|
-
}
|
|
15399
|
-
}
|
|
15400
|
-
return allConditionsMet;
|
|
15401
|
-
}
|
|
15402
|
-
// Simple equality
|
|
15403
|
-
return value === condition;
|
|
15404
|
-
}
|
|
15405
|
-
// ──────────────────────────────────────────────────────────
|
|
15406
|
-
// SPARQL custom getter evaluation
|
|
15407
|
-
// ──────────────────────────────────────────────────────────
|
|
15408
|
-
/**
|
|
15409
|
-
* Builds a SPARQL conformance getter for a relation whose `target` model
|
|
15410
|
-
* is known but no explicit `getter` string was supplied.
|
|
15411
|
-
*
|
|
15412
|
-
* The generated getter traverses outgoing links matching the relation's
|
|
15413
|
-
* predicate and then filters the target nodes to only those that conform to
|
|
15414
|
-
* the target model's shape (required properties / flags).
|
|
15415
|
-
*
|
|
15416
|
-
* Delegates to the shared `buildConformanceFilter()` utility in decorators.ts
|
|
15417
|
-
* so the same logic is used at shape-definition time and at query time.
|
|
15418
|
-
*
|
|
15419
|
-
* @param relationPredicate - The relation's predicate URI (e.g. "flux://entry_type")
|
|
15420
|
-
* @param targetClass - The target model class (result of calling the `target()` thunk)
|
|
15421
|
-
* @returns A SPARQL expression string, or `undefined` if no conformance
|
|
15422
|
-
* conditions could be derived from the target model.
|
|
15423
|
-
*/
|
|
15424
|
-
function buildConformanceGetter(relationPredicate, targetClass) {
|
|
15425
|
-
const filter = buildConformanceFilter(relationPredicate, targetClass);
|
|
15426
|
-
if (!filter) {
|
|
15427
|
-
const targetName = targetClass?.prototype?.className || targetClass?.name || 'unknown';
|
|
15428
|
-
console.warn(`[Ad4mModel] buildConformanceGetter: no conditions found for target "${targetName}".`);
|
|
15429
|
-
return undefined;
|
|
15430
|
-
}
|
|
15431
|
-
return filter.getter;
|
|
15432
|
-
}
|
|
15433
|
-
/**
|
|
15434
|
-
* Evaluates custom SurrealQL getters for properties and relations on a specific instance.
|
|
15435
|
-
*
|
|
15436
|
-
* For relations that declare a `target` but no explicit `getter`, a conformance
|
|
15437
|
-
* getter is auto-generated from the target model's metadata (unless `filter: false`).
|
|
15438
|
-
*/
|
|
15439
|
-
async function evaluateCustomGettersForInstance(instance, perspective, metadata, options) {
|
|
15440
|
-
`<${instance.id}>`;
|
|
15441
|
-
// Build projection filter — when requestedProperties is active, only
|
|
15442
|
-
// evaluate getters for fields that are requested (or included).
|
|
15443
|
-
const projectionActive = options?.requestedProperties && options.requestedProperties.length > 0;
|
|
15444
|
-
const projectionSet = projectionActive ? new Set(options.requestedProperties) : null;
|
|
15445
|
-
// Evaluate property getters (skip when caller only wants relation type-filtering)
|
|
15446
|
-
if (!options?.skipPropertyGetters) {
|
|
15447
|
-
for (const [propName, propMeta] of Object.entries(metadata.properties)) {
|
|
15448
|
-
if (projectionSet && !projectionSet.has(propName))
|
|
15449
|
-
continue;
|
|
15450
|
-
if (propMeta.getter) {
|
|
15451
|
-
try {
|
|
15452
|
-
const rawGetter = propMeta.getter;
|
|
15453
|
-
const getterWithBase = rawGetter.replace(/\?source\b/g, `<${instance.id}>`).replace(/<Base>/g, `<${instance.id}>`).replace(/Base/g, `<${instance.id}>`);
|
|
15454
|
-
// If the getter is already SPARQL (starts with SELECT/ASK/CONSTRUCT), execute directly
|
|
15455
|
-
const trimmed = getterWithBase.trim().toUpperCase();
|
|
15456
|
-
if (trimmed.startsWith('SELECT') || trimmed.startsWith('ASK') || trimmed.startsWith('CONSTRUCT')) {
|
|
15457
|
-
const result = await perspective.querySparql(getterWithBase);
|
|
15458
|
-
if (trimmed.startsWith('ASK')) {
|
|
15459
|
-
instance[propName] = result === true || result === 'true';
|
|
15460
|
-
}
|
|
15461
|
-
else if (result && result.length > 0) {
|
|
15462
|
-
// Get first binding's first value
|
|
15463
|
-
const firstRow = result[0];
|
|
15464
|
-
const firstKey = Object.keys(firstRow)[0];
|
|
15465
|
-
const val = firstRow[firstKey]?.value ?? firstRow[firstKey];
|
|
15466
|
-
if (val !== undefined && val !== null && val !== 'None' && val !== '') {
|
|
15467
|
-
instance[propName] = val;
|
|
15468
|
-
}
|
|
15469
|
-
}
|
|
15470
|
-
}
|
|
15471
|
-
else {
|
|
15472
|
-
// Legacy SurrealDB-style getter — safety guard for getters that don't match
|
|
15473
|
-
// SPARQL patterns (SELECT/ASK). Logs a warning but does not crash.
|
|
15474
|
-
console.warn(`Unsupported legacy getter syntax for property ${propName} — use native SPARQL (SELECT/ASK): ${rawGetter.slice(0, 100)}`);
|
|
15475
|
-
}
|
|
15476
|
-
}
|
|
15477
|
-
catch (error) {
|
|
15478
|
-
console.warn(`Failed to evaluate getter for ${propName}:`, error);
|
|
15479
|
-
}
|
|
15480
|
-
}
|
|
15481
|
-
}
|
|
15482
|
-
} // end skipPropertyGetters guard
|
|
15483
|
-
// Evaluate relation getters (explicit or auto-generated from target)
|
|
15484
|
-
for (const [relName, relMeta] of Object.entries(metadata.relations)) {
|
|
15485
|
-
// Skip relations excluded by property projection (unless in include map)
|
|
15486
|
-
if (projectionSet && !projectionSet.has(relName) && !(options?.include && relName in options.include))
|
|
15487
|
-
continue;
|
|
15488
|
-
const meta = relMeta;
|
|
15489
|
-
// Determine the getter to execute:
|
|
15490
|
-
// 1. Explicit `getter` always wins
|
|
15491
|
-
// 2. If `target` is set and `filter !== false`, auto-generate conformance getter
|
|
15492
|
-
// BUT skip auto-generation for reverse relations (belongsToMany / belongsToOne)
|
|
15493
|
-
// because buildConformanceGetter traverses outgoing links which is wrong for
|
|
15494
|
-
// reverse relations. Their values are already populated by the reverse link
|
|
15495
|
-
// lookup in instancesFromQueryResult / getData.
|
|
15496
|
-
let getter = meta.getter;
|
|
15497
|
-
if (!getter && meta.where && meta.direction !== 'reverse') {
|
|
15498
|
-
try {
|
|
15499
|
-
const TargetClass = meta.target?.();
|
|
15500
|
-
const targetMetadata = TargetClass
|
|
15501
|
-
? TargetClass.getModelMetadata?.() ?? null
|
|
15502
|
-
: null;
|
|
15503
|
-
// Check if all where conditions can be SPARQL-filtered.
|
|
15504
|
-
// literal-resolved properties store signed expressions (literal:json:{…}),
|
|
15505
|
-
// not raw literal:string: IRIs, so SPARQL exact-match fails for them.
|
|
15506
|
-
let allSparqlFilterable = true;
|
|
15507
|
-
if (targetMetadata) {
|
|
15508
|
-
for (const propName of Object.keys(meta.where)) {
|
|
15509
|
-
if (['id', 'author', 'timestamp'].includes(propName))
|
|
15510
|
-
continue;
|
|
15511
|
-
const propMeta = targetMetadata.properties[propName];
|
|
15512
|
-
if (propMeta && (!propMeta.resolveLanguage || propMeta.resolveLanguage === 'literal')) {
|
|
15513
|
-
allSparqlFilterable = false;
|
|
15514
|
-
break;
|
|
15515
|
-
}
|
|
15516
|
-
}
|
|
15517
|
-
}
|
|
15518
|
-
else {
|
|
15519
|
-
allSparqlFilterable = false;
|
|
15520
|
-
}
|
|
15521
|
-
if (allSparqlFilterable) {
|
|
15522
|
-
const conditions = compileWhereClause(meta.where, targetMetadata);
|
|
15523
|
-
if (conditions.length > 0) {
|
|
15524
|
-
const escapedPredicate = escapeQueryString(meta.predicate);
|
|
15525
|
-
getter = `SELECT ?target WHERE { <Base> <${escapedPredicate}> ?target . ${conditions.join(' ')} }`;
|
|
15526
|
-
}
|
|
15527
|
-
}
|
|
15528
|
-
// If not filterable, fall through to buildConformanceGetter + JS post-filter below
|
|
15529
|
-
}
|
|
15530
|
-
catch (e) {
|
|
15531
|
-
console.warn(`[Ad4mModel] where-clause compilation failed for relation "${relName}":`, e);
|
|
15532
|
-
}
|
|
15533
|
-
}
|
|
15534
|
-
if (!getter && meta.target && meta.filter !== false && meta.direction !== 'reverse') {
|
|
15535
|
-
try {
|
|
15536
|
-
const TargetClass = meta.target();
|
|
15537
|
-
getter = buildConformanceGetter(meta.predicate, TargetClass);
|
|
15538
|
-
if (!getter) {
|
|
15539
|
-
console.warn(`[Ad4mModel] buildConformanceGetter returned undefined for relation "${relName}" (predicate: "${meta.predicate}")`);
|
|
15540
|
-
}
|
|
15541
|
-
}
|
|
15542
|
-
catch (e) {
|
|
15543
|
-
console.warn(`[Ad4mModel] auto-generation failed for relation "${relName}":`, e);
|
|
15544
|
-
}
|
|
15545
|
-
}
|
|
15546
|
-
if (getter) {
|
|
15547
|
-
try {
|
|
15548
|
-
const getterWithBase = getter.replace(/\?source\b/g, `<${instance.id}>`).replace(/<Base>/g, `<${instance.id}>`).replace(/\bBase\b/g, `<${instance.id}>`);
|
|
15549
|
-
const trimmed = getterWithBase.trim().toUpperCase();
|
|
15550
|
-
if (trimmed.startsWith('SELECT') || trimmed.startsWith('ASK') || trimmed.startsWith('CONSTRUCT')) {
|
|
15551
|
-
// Native SPARQL getter — execute directly
|
|
15552
|
-
const result = await perspective.querySparql(getterWithBase);
|
|
15553
|
-
if (result && result.length > 0) {
|
|
15554
|
-
const values = result.map((r) => {
|
|
15555
|
-
const firstKey = Object.keys(r)[0];
|
|
15556
|
-
return r[firstKey]?.value ?? r[firstKey];
|
|
15557
|
-
}).filter((v) => v !== undefined && v !== null && v !== '' && v !== 'None');
|
|
15558
|
-
instance[relName] = values;
|
|
15559
|
-
}
|
|
15560
|
-
}
|
|
15561
|
-
else {
|
|
15562
|
-
// Legacy SurrealDB-style getter — safety guard for relation getters that don't
|
|
15563
|
-
// match SPARQL patterns (SELECT/ASK). Logs a warning but does not crash.
|
|
15564
|
-
console.warn(`Unsupported legacy getter syntax for relation ${relName} — use native SPARQL (SELECT/ASK): ${getter.slice(0, 100)}`);
|
|
15565
|
-
}
|
|
15566
|
-
}
|
|
15567
|
-
catch (error) {
|
|
15568
|
-
console.warn(`Failed to evaluate getter for ${relName}:`, error);
|
|
15569
|
-
}
|
|
15570
|
-
}
|
|
15571
|
-
// JS post-filter for where conditions that couldn't be SPARQL-filtered
|
|
15572
|
-
// (e.g. literal-resolved properties storing signed expressions)
|
|
15573
|
-
const currentValues = instance[relName];
|
|
15574
|
-
if (meta.where && Array.isArray(currentValues) && currentValues.length > 0) {
|
|
15575
|
-
const TargetClass = meta.target?.();
|
|
15576
|
-
if (TargetClass) {
|
|
15577
|
-
const filtered = [];
|
|
15578
|
-
for (const targetId of currentValues) {
|
|
15579
|
-
try {
|
|
15580
|
-
const inst = new TargetClass(perspective, targetId);
|
|
15581
|
-
await inst.get();
|
|
15582
|
-
let matches = true;
|
|
15583
|
-
for (const [prop, expected] of Object.entries(meta.where)) {
|
|
15584
|
-
if (inst[prop] !== expected) {
|
|
15585
|
-
matches = false;
|
|
15586
|
-
break;
|
|
15587
|
-
}
|
|
15588
|
-
}
|
|
15589
|
-
if (matches)
|
|
15590
|
-
filtered.push(targetId);
|
|
15591
|
-
}
|
|
15592
|
-
catch {
|
|
15593
|
-
// If we can't hydrate, keep the value (conservative)
|
|
15594
|
-
filtered.push(targetId);
|
|
15595
|
-
}
|
|
15596
|
-
}
|
|
15597
|
-
instance[relName] = filtered;
|
|
15598
|
-
}
|
|
15599
|
-
}
|
|
15600
|
-
}
|
|
15601
|
-
}
|
|
15602
|
-
|
|
15603
|
-
// ---------------------------------------------------------------------------
|
|
15604
|
-
// Helpers for Rust-side include resolution
|
|
15605
|
-
// ---------------------------------------------------------------------------
|
|
15606
|
-
/**
|
|
15607
|
-
* Recursively enrich relation metadata in the shape with target class shapes
|
|
15608
|
-
* so the Rust endpoint can resolve includes in-process (no extra GraphQL
|
|
15609
|
-
* round-trips per relation).
|
|
15610
|
-
*/
|
|
15611
|
-
function enrichShapeForIncludes(metadata, include, allRelMeta) {
|
|
15612
|
-
for (const [relName, includeVal] of Object.entries(include)) {
|
|
15613
|
-
if (!includeVal)
|
|
15614
|
-
continue;
|
|
15615
|
-
const meta = allRelMeta[relName];
|
|
15616
|
-
if (!meta?.target)
|
|
15617
|
-
continue;
|
|
15618
|
-
const TargetClass = meta.target();
|
|
15619
|
-
// Deep-copy so we don't mutate the cached metadata
|
|
15620
|
-
const targetMeta = JSON.parse(JSON.stringify(TargetClass.getModelMetadata()));
|
|
15621
|
-
// Ensure the relation is in metadata.relations (fallback for edge cases)
|
|
15622
|
-
if (!metadata.relations[relName]) {
|
|
15623
|
-
metadata.relations[relName] = {
|
|
15624
|
-
name: relName,
|
|
15625
|
-
predicate: meta.predicate,
|
|
15626
|
-
direction: meta.kind === 'belongsToMany' || meta.kind === 'belongsToOne'
|
|
15627
|
-
? 'reverse'
|
|
15628
|
-
: 'forward',
|
|
15629
|
-
};
|
|
15630
|
-
}
|
|
15631
|
-
const rel = metadata.relations[relName];
|
|
15632
|
-
rel.kind = meta.kind;
|
|
15633
|
-
rel.maxCount = meta.maxCount;
|
|
15634
|
-
rel.targetShape = targetMeta;
|
|
15635
|
-
rel.targetClassName = targetMeta.className;
|
|
15636
|
-
// Recurse for nested includes
|
|
15637
|
-
const nested = typeof includeVal === 'object' && includeVal !== null
|
|
15638
|
-
? includeVal.include
|
|
15639
|
-
: undefined;
|
|
15640
|
-
if (nested) {
|
|
15641
|
-
const targetRelMeta = getRelationsMetadata(TargetClass);
|
|
15642
|
-
enrichShapeForIncludes(targetMeta, nested, targetRelMeta);
|
|
15242
|
+
const rel = metadata.relations[relName];
|
|
15243
|
+
rel.kind = meta.kind;
|
|
15244
|
+
rel.maxCount = meta.maxCount;
|
|
15245
|
+
rel.targetShape = targetMeta;
|
|
15246
|
+
rel.targetClassName = targetMeta.className;
|
|
15247
|
+
// Recurse for nested includes
|
|
15248
|
+
const nested = typeof includeVal === 'object' && includeVal !== null
|
|
15249
|
+
? includeVal.include
|
|
15250
|
+
: undefined;
|
|
15251
|
+
if (nested) {
|
|
15252
|
+
const targetRelMeta = getRelationsMetadata(TargetClass);
|
|
15253
|
+
enrichShapeForIncludes(targetMeta, nested, targetRelMeta);
|
|
15643
15254
|
}
|
|
15644
15255
|
}
|
|
15645
15256
|
}
|
|
@@ -16238,6 +15849,7 @@ class Ad4mModel {
|
|
|
16238
15849
|
const query = {
|
|
16239
15850
|
where: { id: this._baseExpression },
|
|
16240
15851
|
limit: 1,
|
|
15852
|
+
deepQuery: true, // Single-instance get() always evaluates property getters
|
|
16241
15853
|
};
|
|
16242
15854
|
if (opts?.properties)
|
|
16243
15855
|
query.properties = opts.properties;
|
|
@@ -16346,11 +15958,16 @@ class Ad4mModel {
|
|
|
16346
15958
|
queryInput.limit = query.limit;
|
|
16347
15959
|
if (query.count !== undefined)
|
|
16348
15960
|
queryInput.count = query.count;
|
|
15961
|
+
queryInput.deepQuery = query.deepQuery ?? true;
|
|
16349
15962
|
if (query.include) {
|
|
16350
15963
|
const allRelMeta = getRelationsMetadata(this);
|
|
16351
15964
|
enrichShapeForIncludes(metadata, query.include, allRelMeta);
|
|
16352
15965
|
}
|
|
16353
|
-
// Pre-compute conformance getters
|
|
15966
|
+
// Pre-compute conformance getters for Rust-side evaluation.
|
|
15967
|
+
// Where clauses are NOT compiled into getter SPARQL because stored
|
|
15968
|
+
// property values are signed expression envelopes (literal:json:...),
|
|
15969
|
+
// not simple literal:string:X values. Instead, where clauses are
|
|
15970
|
+
// attached as metadata for Rust-side post-evaluation filtering.
|
|
16354
15971
|
{
|
|
16355
15972
|
const allRelMeta = getRelationsMetadata(this);
|
|
16356
15973
|
for (const [relName, relMeta] of Object.entries(metadata.relations)) {
|
|
@@ -16363,46 +15980,31 @@ class Ad4mModel {
|
|
|
16363
15980
|
try {
|
|
16364
15981
|
const TargetClass = meta.target();
|
|
16365
15982
|
const filter = buildConformanceFilter(meta.predicate, TargetClass);
|
|
16366
|
-
|
|
16367
|
-
|
|
16368
|
-
|
|
16369
|
-
//
|
|
16370
|
-
let whereConditions = [];
|
|
15983
|
+
if (filter) {
|
|
15984
|
+
rel.getter = filter.getter;
|
|
15985
|
+
}
|
|
15986
|
+
// Attach where-clause metadata for Rust-side post-getter filtering
|
|
16371
15987
|
if (rel.where) {
|
|
16372
15988
|
try {
|
|
16373
15989
|
const targetMetadata = TargetClass.getModelMetadata?.() ?? null;
|
|
16374
|
-
let allSparqlFilterable = true;
|
|
16375
15990
|
if (targetMetadata) {
|
|
15991
|
+
const predicates = {};
|
|
16376
15992
|
for (const propName of Object.keys(rel.where)) {
|
|
16377
15993
|
if (['id', 'author', 'timestamp'].includes(propName))
|
|
16378
15994
|
continue;
|
|
16379
15995
|
const propMeta = targetMetadata.properties[propName];
|
|
16380
|
-
if (propMeta
|
|
16381
|
-
|
|
16382
|
-
break;
|
|
15996
|
+
if (propMeta?.predicate) {
|
|
15997
|
+
predicates[propName] = propMeta.predicate;
|
|
16383
15998
|
}
|
|
16384
15999
|
}
|
|
16385
|
-
|
|
16386
|
-
|
|
16387
|
-
|
|
16388
|
-
|
|
16389
|
-
if (allSparqlFilterable) {
|
|
16390
|
-
whereConditions = compileWhereClause(rel.where, targetMetadata);
|
|
16000
|
+
if (Object.keys(predicates).length > 0) {
|
|
16001
|
+
rel.whereFilter = rel.where;
|
|
16002
|
+
rel.wherePredicates = predicates;
|
|
16003
|
+
}
|
|
16391
16004
|
}
|
|
16392
16005
|
}
|
|
16393
16006
|
catch (_) { }
|
|
16394
16007
|
}
|
|
16395
|
-
if (filter) {
|
|
16396
|
-
let getter = filter.getter;
|
|
16397
|
-
if (whereConditions.length > 0) {
|
|
16398
|
-
getter = getter.replace(/ \}$/, ` ${whereConditions.join(' ')} }`);
|
|
16399
|
-
}
|
|
16400
|
-
rel.getter = getter;
|
|
16401
|
-
}
|
|
16402
|
-
else if (whereConditions.length > 0) {
|
|
16403
|
-
const escapedPred = meta.predicate.replace(/[<>"{}|\\^`\u0000-\u0020]/g, '');
|
|
16404
|
-
rel.getter = `SELECT ?target WHERE { <Base> <${escapedPred}> ?target . ${whereConditions.join(' ')} }`;
|
|
16405
|
-
}
|
|
16406
16008
|
}
|
|
16407
16009
|
catch (_) { }
|
|
16408
16010
|
}
|
|
@@ -16505,6 +16107,7 @@ class Ad4mModel {
|
|
|
16505
16107
|
queryInput.limit = query.limit;
|
|
16506
16108
|
if (query.count !== undefined)
|
|
16507
16109
|
queryInput.count = query.count;
|
|
16110
|
+
queryInput.deepQuery = query.deepQuery ?? true;
|
|
16508
16111
|
// Enrich relation metadata with target class shapes for Rust-side
|
|
16509
16112
|
// include resolution. This eliminates per-relation GraphQL round-trips
|
|
16510
16113
|
// by letting the Rust endpoint resolve includes in-process.
|
|
@@ -16534,48 +16137,33 @@ class Ad4mModel {
|
|
|
16534
16137
|
try {
|
|
16535
16138
|
const TargetClass = meta.target();
|
|
16536
16139
|
const filter = buildConformanceFilter(meta.predicate, TargetClass);
|
|
16537
|
-
|
|
16538
|
-
|
|
16539
|
-
|
|
16540
|
-
//
|
|
16541
|
-
|
|
16140
|
+
if (filter) {
|
|
16141
|
+
rel.getter = filter.getter;
|
|
16142
|
+
}
|
|
16143
|
+
// Attach where-clause metadata for Rust-side post-getter filtering.
|
|
16144
|
+
// Property values are signed expression envelopes (literal:json:...)
|
|
16145
|
+
// and cannot be matched by SPARQL FILTER on the raw IRI.
|
|
16542
16146
|
if (rel.where) {
|
|
16543
16147
|
try {
|
|
16544
16148
|
const targetMetadata = TargetClass.getModelMetadata?.() ?? null;
|
|
16545
|
-
let allSparqlFilterable = true;
|
|
16546
16149
|
if (targetMetadata) {
|
|
16150
|
+
const predicates = {};
|
|
16547
16151
|
for (const propName of Object.keys(rel.where)) {
|
|
16548
16152
|
if (['id', 'author', 'timestamp'].includes(propName))
|
|
16549
16153
|
continue;
|
|
16550
16154
|
const propMeta = targetMetadata.properties[propName];
|
|
16551
|
-
if (propMeta
|
|
16552
|
-
|
|
16553
|
-
break;
|
|
16155
|
+
if (propMeta?.predicate) {
|
|
16156
|
+
predicates[propName] = propMeta.predicate;
|
|
16554
16157
|
}
|
|
16555
16158
|
}
|
|
16556
|
-
|
|
16557
|
-
|
|
16558
|
-
|
|
16559
|
-
|
|
16560
|
-
if (allSparqlFilterable) {
|
|
16561
|
-
whereConditions = compileWhereClause(rel.where, targetMetadata);
|
|
16159
|
+
if (Object.keys(predicates).length > 0) {
|
|
16160
|
+
rel.whereFilter = rel.where;
|
|
16161
|
+
rel.wherePredicates = predicates;
|
|
16162
|
+
}
|
|
16562
16163
|
}
|
|
16563
16164
|
}
|
|
16564
16165
|
catch (_) { /* target metadata unavailable */ }
|
|
16565
16166
|
}
|
|
16566
|
-
if (filter) {
|
|
16567
|
-
let getter = filter.getter;
|
|
16568
|
-
if (whereConditions.length > 0) {
|
|
16569
|
-
// Append where conditions before the closing }
|
|
16570
|
-
getter = getter.replace(/ \}$/, ` ${whereConditions.join(' ')} }`);
|
|
16571
|
-
}
|
|
16572
|
-
rel.getter = getter;
|
|
16573
|
-
}
|
|
16574
|
-
else if (whereConditions.length > 0) {
|
|
16575
|
-
// No conformance filter but where clause exists — build getter from where alone
|
|
16576
|
-
const escapedPred = meta.predicate.replace(/[<>"{}|\\^`\u0000-\u0020]/g, '');
|
|
16577
|
-
rel.getter = `SELECT ?target WHERE { <Base> <${escapedPred}> ?target . ${whereConditions.join(' ')} }`;
|
|
16578
|
-
}
|
|
16579
16167
|
}
|
|
16580
16168
|
catch (e) {
|
|
16581
16169
|
// Target class may not be available; skip silently
|
|
@@ -16623,40 +16211,6 @@ class Ad4mModel {
|
|
|
16623
16211
|
}
|
|
16624
16212
|
}));
|
|
16625
16213
|
}
|
|
16626
|
-
// Relation conformance getters are evaluated Rust-side via evaluate_getters()
|
|
16627
|
-
// in model_query.rs. However, for relations with non-SPARQL-filterable where
|
|
16628
|
-
// clauses (e.g. properties stored as signed expressions), we still need
|
|
16629
|
-
// TS-side evaluation as a fallback. Running evaluateCustomGettersForInstance
|
|
16630
|
-
// with skipPropertyGetters ensures conformance + JS post-filtering for
|
|
16631
|
-
// where clauses that couldn't be compiled to SPARQL.
|
|
16632
|
-
const includedRelNames = queryInput.include ? new Set(Object.keys(queryInput.include)) : new Set();
|
|
16633
|
-
for (const inst of instances) {
|
|
16634
|
-
// Save included relation values that came from Rust hydration
|
|
16635
|
-
const savedIncluded = {};
|
|
16636
|
-
for (const relName of includedRelNames) {
|
|
16637
|
-
if (inst[relName] !== undefined) {
|
|
16638
|
-
savedIncluded[relName] = inst[relName];
|
|
16639
|
-
}
|
|
16640
|
-
}
|
|
16641
|
-
await evaluateCustomGettersForInstance(inst, perspective, metadata, {
|
|
16642
|
-
skipPropertyGetters: true,
|
|
16643
|
-
});
|
|
16644
|
-
// Restore hydrated include objects that were overwritten by conformance getters
|
|
16645
|
-
for (const [relName, value] of Object.entries(savedIncluded)) {
|
|
16646
|
-
inst[relName] = value;
|
|
16647
|
-
}
|
|
16648
|
-
// Fix cardinality for non-included HasOne/BelongsToOne relations:
|
|
16649
|
-
// The conformance getter always produces arrays; unwrap to scalar.
|
|
16650
|
-
for (const [relName, relMeta] of Object.entries(metadata.relations)) {
|
|
16651
|
-
if (includedRelNames.has(relName))
|
|
16652
|
-
continue;
|
|
16653
|
-
const kind = relMeta.kind;
|
|
16654
|
-
if ((kind === 'hasOne' || kind === 'belongsToOne') && Array.isArray(inst[relName])) {
|
|
16655
|
-
const arr = inst[relName];
|
|
16656
|
-
inst[relName] = arr.length > 0 ? arr[0] : null;
|
|
16657
|
-
}
|
|
16658
|
-
}
|
|
16659
|
-
}
|
|
16660
16214
|
// Take snapshots for dirty tracking
|
|
16661
16215
|
const snapshotRelations = queryInput.include;
|
|
16662
16216
|
for (const inst of instances) {
|
|
@@ -17084,10 +16638,10 @@ class Ad4mModel {
|
|
|
17084
16638
|
/**
|
|
17085
16639
|
* Evaluate SPARQL getters for a batch of instances on demand.
|
|
17086
16640
|
*
|
|
17087
|
-
*
|
|
17088
|
-
*
|
|
17089
|
-
*
|
|
17090
|
-
* a
|
|
16641
|
+
* Since deepQuery defaults to true, property getters are evaluated
|
|
16642
|
+
* automatically during collection queries. Use this method when
|
|
16643
|
+
* deepQuery was explicitly set to false and you want to lazily
|
|
16644
|
+
* resolve getter-backed properties for a subset of instances.
|
|
17091
16645
|
*
|
|
17092
16646
|
* @param instances - Array of model instances to evaluate getters on
|
|
17093
16647
|
* @param perspective - The perspective to query against
|
|
@@ -17096,8 +16650,8 @@ class Ad4mModel {
|
|
|
17096
16650
|
*
|
|
17097
16651
|
* @example
|
|
17098
16652
|
* ```typescript
|
|
17099
|
-
* const messages = await Message.
|
|
17100
|
-
* // messages[i].replyingTo is undefined (getter skipped
|
|
16653
|
+
* const messages = await Message.query(perspective).deepQuery(false).limit(30).get();
|
|
16654
|
+
* // messages[i].replyingTo is undefined (getter skipped)
|
|
17101
16655
|
*
|
|
17102
16656
|
* // Evaluate getters for the visible subset
|
|
17103
16657
|
* await Message.evaluateGetters(messages.slice(0, 10), perspective, ['replyingTo']);
|
|
@@ -17108,10 +16662,28 @@ class Ad4mModel {
|
|
|
17108
16662
|
if (instances.length === 0)
|
|
17109
16663
|
return;
|
|
17110
16664
|
const metadata = this.getModelMetadata();
|
|
17111
|
-
|
|
17112
|
-
|
|
17113
|
-
|
|
17114
|
-
|
|
16665
|
+
// Pre-compute conformance getters so the shape sent to Rust includes them
|
|
16666
|
+
const allRelMeta = getRelationsMetadata(this);
|
|
16667
|
+
for (const [relName, relMeta] of Object.entries(metadata.relations)) {
|
|
16668
|
+
const rel = relMeta;
|
|
16669
|
+
if (rel.getter || rel.direction === 'reverse' || rel.filter === false)
|
|
16670
|
+
continue;
|
|
16671
|
+
const meta = allRelMeta[relName];
|
|
16672
|
+
if (!meta?.target)
|
|
16673
|
+
continue;
|
|
16674
|
+
try {
|
|
16675
|
+
const TargetClass = meta.target();
|
|
16676
|
+
const filter = buildConformanceFilter(meta.predicate, TargetClass);
|
|
16677
|
+
if (filter)
|
|
16678
|
+
rel.getter = filter.getter;
|
|
16679
|
+
}
|
|
16680
|
+
catch (_) { /* target class may not be available */ }
|
|
16681
|
+
}
|
|
16682
|
+
const shapeJson = JSON.stringify(metadata);
|
|
16683
|
+
const instanceIds = instances.map(inst => inst.id || inst._baseExpression);
|
|
16684
|
+
// Single RPC call evaluates all getters in-process on the executor
|
|
16685
|
+
const result = await perspective.evaluateGetters(metadata.className, instanceIds, shapeJson, propertyNames);
|
|
16686
|
+
// Determine which property names were evaluated for snapshot sync
|
|
17115
16687
|
const evaluatedPropertyNames = [];
|
|
17116
16688
|
for (const [propName, propMeta] of Object.entries(metadata.properties)) {
|
|
17117
16689
|
if (propMeta.getter) {
|
|
@@ -17120,13 +16692,24 @@ class Ad4mModel {
|
|
|
17120
16692
|
}
|
|
17121
16693
|
}
|
|
17122
16694
|
}
|
|
16695
|
+
// Also include relation getters
|
|
16696
|
+
for (const [relName, relMeta] of Object.entries(metadata.relations)) {
|
|
16697
|
+
if (relMeta.getter) {
|
|
16698
|
+
if (!propertyNames || propertyNames.length === 0 || propertyNames.includes(relName)) {
|
|
16699
|
+
evaluatedPropertyNames.push(relName);
|
|
16700
|
+
}
|
|
16701
|
+
}
|
|
16702
|
+
}
|
|
16703
|
+
// Apply results to instances and sync snapshots
|
|
17123
16704
|
for (const instance of instances) {
|
|
17124
|
-
|
|
17125
|
-
|
|
17126
|
-
|
|
17127
|
-
|
|
17128
|
-
|
|
17129
|
-
|
|
16705
|
+
const id = instance.id || instance._baseExpression;
|
|
16706
|
+
const props = result[id];
|
|
16707
|
+
if (props) {
|
|
16708
|
+
for (const [key, value] of Object.entries(props)) {
|
|
16709
|
+
instance[key] = value;
|
|
16710
|
+
}
|
|
16711
|
+
}
|
|
16712
|
+
// Sync snapshot so isDirty() doesn't flag getter-only changes
|
|
17130
16713
|
const modelInstance = instance;
|
|
17131
16714
|
if (modelInstance._snapshot) {
|
|
17132
16715
|
for (const propName of evaluatedPropertyNames) {
|
|
@@ -17527,7 +17110,20 @@ class Ad4mModel {
|
|
|
17527
17110
|
* @param name - Class name to assign (e.g. "Channel")
|
|
17528
17111
|
* @returns Generated Ad4mModel subclass, ready for querying
|
|
17529
17112
|
*/
|
|
17530
|
-
|
|
17113
|
+
/**
|
|
17114
|
+
* Synthesise an `Ad4mModel` subclass from a SHACL shape.
|
|
17115
|
+
*
|
|
17116
|
+
* @param shape - The SHACL shape to synthesise from.
|
|
17117
|
+
* @param name - The model name (e.g. "Channel").
|
|
17118
|
+
* @param classResolver - Optional thunk factory. When provided, any collection
|
|
17119
|
+
* property that carries a `sh:class` URI will have its `target` wired up lazily:
|
|
17120
|
+
* `target: () => classResolver(localName)`. Because `target` is only called at
|
|
17121
|
+
* query time (inside `enrichShapeForIncludes` / `jsonToModelInstance`), the
|
|
17122
|
+
* resolver just needs to return the correct class by the time a query runs —
|
|
17123
|
+
* making it safe to pass a closure over a registry object that is still being
|
|
17124
|
+
* populated (e.g. the `result` record inside `getModelClasses`).
|
|
17125
|
+
*/
|
|
17126
|
+
static fromSHACL(shape, name, classResolver) {
|
|
17531
17127
|
const DynamicModelClass = class extends this {
|
|
17532
17128
|
};
|
|
17533
17129
|
DynamicModelClass.className = name;
|
|
@@ -17566,9 +17162,19 @@ class Ad4mModel {
|
|
|
17566
17162
|
continue;
|
|
17567
17163
|
const isCollection = prop.maxCount === undefined || prop.maxCount > 1;
|
|
17568
17164
|
if (isCollection) {
|
|
17165
|
+
// Derive a lazy `target` thunk when a sh:class URI is present and a
|
|
17166
|
+
// classResolver was supplied. The thunk is evaluated at query time so
|
|
17167
|
+
// it is safe even if the target class hasn't been registered yet.
|
|
17168
|
+
let targetThunk;
|
|
17169
|
+
if (prop.class && classResolver) {
|
|
17170
|
+
const sep = Math.max(prop.class.lastIndexOf('#'), prop.class.lastIndexOf('/'));
|
|
17171
|
+
const localName = sep >= 0 ? prop.class.slice(sep + 1) : prop.class;
|
|
17172
|
+
targetThunk = () => classResolver(localName);
|
|
17173
|
+
}
|
|
17569
17174
|
setRelationRegistryEntry(DynamicModelClass, prop.name, {
|
|
17570
17175
|
predicate: prop.path,
|
|
17571
17176
|
kind: 'hasMany',
|
|
17177
|
+
...(targetThunk !== undefined && { target: targetThunk }),
|
|
17572
17178
|
...(prop.local !== undefined && { local: prop.local }),
|
|
17573
17179
|
...(prop.getter !== undefined && { getter: prop.getter }),
|
|
17574
17180
|
});
|
|
@@ -17589,6 +17195,535 @@ class Ad4mModel {
|
|
|
17589
17195
|
}
|
|
17590
17196
|
Ad4mModel.classNamesByClass = new WeakMap();
|
|
17591
17197
|
|
|
17198
|
+
var __classPrivateFieldSet$1 = (undefined && undefined.__classPrivateFieldSet) || function (receiver, state, value, kind, f) {
|
|
17199
|
+
if (kind === "m") throw new TypeError("Private method is not writable");
|
|
17200
|
+
if (kind === "a" && !f) throw new TypeError("Private accessor was defined without a setter");
|
|
17201
|
+
if (typeof state === "function" ? receiver !== state || !f : !state.has(receiver)) throw new TypeError("Cannot write private member to an object whose class did not declare it");
|
|
17202
|
+
return (kind === "a" ? f.call(receiver, value) : f ? f.value = value : state.set(receiver, value)), value;
|
|
17203
|
+
};
|
|
17204
|
+
var __classPrivateFieldGet$1 = (undefined && undefined.__classPrivateFieldGet) || function (receiver, state, kind, f) {
|
|
17205
|
+
if (kind === "a" && !f) throw new TypeError("Private accessor was defined without a getter");
|
|
17206
|
+
if (typeof state === "function" ? receiver !== state || !f : !state.has(receiver)) throw new TypeError("Cannot read private member from an object whose class did not declare it");
|
|
17207
|
+
return kind === "m" ? f : kind === "a" ? f.call(receiver) : f ? f.value : state.get(receiver);
|
|
17208
|
+
};
|
|
17209
|
+
var _Ad4mClient_baseUrl, _Ad4mClient_token, _Ad4mClient_apiClient, _Ad4mClient_agentClient, _Ad4mClient_expressionClient, _Ad4mClient_languageClient, _Ad4mClient_neighbourhoodClient, _Ad4mClient_perspectiveClient, _Ad4mClient_runtimeClient, _Ad4mClient_aiClient;
|
|
17210
|
+
/**
|
|
17211
|
+
* Client for the Ad4m interface wrapping WebSocket RPC calls
|
|
17212
|
+
* for convenient use in user facing code.
|
|
17213
|
+
*
|
|
17214
|
+
* Aggregates the six sub-clients:
|
|
17215
|
+
* AgentClient, ExpressionClient, LanguageClient,
|
|
17216
|
+
* NeighbourhoodClient, PerspectiveClient and RuntimeClient
|
|
17217
|
+
* for the respective functionality.
|
|
17218
|
+
*/
|
|
17219
|
+
class Ad4mClient {
|
|
17220
|
+
constructor(baseUrl, token, subscribe = true) {
|
|
17221
|
+
_Ad4mClient_baseUrl.set(this, void 0);
|
|
17222
|
+
_Ad4mClient_token.set(this, void 0);
|
|
17223
|
+
_Ad4mClient_apiClient.set(this, void 0);
|
|
17224
|
+
_Ad4mClient_agentClient.set(this, void 0);
|
|
17225
|
+
_Ad4mClient_expressionClient.set(this, void 0);
|
|
17226
|
+
_Ad4mClient_languageClient.set(this, void 0);
|
|
17227
|
+
_Ad4mClient_neighbourhoodClient.set(this, void 0);
|
|
17228
|
+
_Ad4mClient_perspectiveClient.set(this, void 0);
|
|
17229
|
+
_Ad4mClient_runtimeClient.set(this, void 0);
|
|
17230
|
+
_Ad4mClient_aiClient.set(this, void 0);
|
|
17231
|
+
__classPrivateFieldSet$1(this, _Ad4mClient_baseUrl, baseUrl, "f");
|
|
17232
|
+
__classPrivateFieldSet$1(this, _Ad4mClient_token, token, "f");
|
|
17233
|
+
__classPrivateFieldSet$1(this, _Ad4mClient_apiClient, new ApiClient(baseUrl, token), "f");
|
|
17234
|
+
__classPrivateFieldSet$1(this, _Ad4mClient_agentClient, new AgentClient(baseUrl, token, subscribe, __classPrivateFieldGet$1(this, _Ad4mClient_apiClient, "f")), "f");
|
|
17235
|
+
__classPrivateFieldSet$1(this, _Ad4mClient_expressionClient, new ExpressionClient(baseUrl, token, __classPrivateFieldGet$1(this, _Ad4mClient_apiClient, "f")), "f");
|
|
17236
|
+
__classPrivateFieldSet$1(this, _Ad4mClient_languageClient, new LanguageClient(baseUrl, token, __classPrivateFieldGet$1(this, _Ad4mClient_apiClient, "f")), "f");
|
|
17237
|
+
__classPrivateFieldSet$1(this, _Ad4mClient_neighbourhoodClient, new NeighbourhoodClient(baseUrl, token, __classPrivateFieldGet$1(this, _Ad4mClient_apiClient, "f")), "f");
|
|
17238
|
+
__classPrivateFieldSet$1(this, _Ad4mClient_aiClient, new AIClient(baseUrl, token, subscribe, __classPrivateFieldGet$1(this, _Ad4mClient_apiClient, "f")), "f");
|
|
17239
|
+
__classPrivateFieldSet$1(this, _Ad4mClient_perspectiveClient, new PerspectiveClient(baseUrl, token, subscribe, __classPrivateFieldGet$1(this, _Ad4mClient_apiClient, "f")), "f");
|
|
17240
|
+
__classPrivateFieldGet$1(this, _Ad4mClient_perspectiveClient, "f").setExpressionClient(__classPrivateFieldGet$1(this, _Ad4mClient_expressionClient, "f"));
|
|
17241
|
+
__classPrivateFieldGet$1(this, _Ad4mClient_perspectiveClient, "f").setNeighbourhoodClient(__classPrivateFieldGet$1(this, _Ad4mClient_neighbourhoodClient, "f"));
|
|
17242
|
+
__classPrivateFieldGet$1(this, _Ad4mClient_perspectiveClient, "f").setAIClient(__classPrivateFieldGet$1(this, _Ad4mClient_aiClient, "f"));
|
|
17243
|
+
__classPrivateFieldSet$1(this, _Ad4mClient_runtimeClient, new RuntimeClient(baseUrl, token, subscribe, __classPrivateFieldGet$1(this, _Ad4mClient_apiClient, "f")), "f");
|
|
17244
|
+
// Register with AD4M DevTools if the bridge is installed (e.g. browser extension)
|
|
17245
|
+
try {
|
|
17246
|
+
const dt = globalThis.__AD4M_DEVTOOLS__;
|
|
17247
|
+
if (dt) {
|
|
17248
|
+
dt._client = this;
|
|
17249
|
+
dt._Ad4mModel = Ad4mModel;
|
|
17250
|
+
}
|
|
17251
|
+
}
|
|
17252
|
+
catch { }
|
|
17253
|
+
}
|
|
17254
|
+
get agent() {
|
|
17255
|
+
return __classPrivateFieldGet$1(this, _Ad4mClient_agentClient, "f");
|
|
17256
|
+
}
|
|
17257
|
+
get expression() {
|
|
17258
|
+
return __classPrivateFieldGet$1(this, _Ad4mClient_expressionClient, "f");
|
|
17259
|
+
}
|
|
17260
|
+
get languages() {
|
|
17261
|
+
return __classPrivateFieldGet$1(this, _Ad4mClient_languageClient, "f");
|
|
17262
|
+
}
|
|
17263
|
+
get neighbourhood() {
|
|
17264
|
+
return __classPrivateFieldGet$1(this, _Ad4mClient_neighbourhoodClient, "f");
|
|
17265
|
+
}
|
|
17266
|
+
get perspective() {
|
|
17267
|
+
return __classPrivateFieldGet$1(this, _Ad4mClient_perspectiveClient, "f");
|
|
17268
|
+
}
|
|
17269
|
+
get runtime() {
|
|
17270
|
+
return __classPrivateFieldGet$1(this, _Ad4mClient_runtimeClient, "f");
|
|
17271
|
+
}
|
|
17272
|
+
get ai() {
|
|
17273
|
+
return __classPrivateFieldGet$1(this, _Ad4mClient_aiClient, "f");
|
|
17274
|
+
}
|
|
17275
|
+
/** Start event subscriptions (agent-updated, agent-status-changed, apps-changed).
|
|
17276
|
+
* Safe to call if subscriptions were deferred at construction (subscribe=false). */
|
|
17277
|
+
startSubscriptions() {
|
|
17278
|
+
__classPrivateFieldGet$1(this, _Ad4mClient_agentClient, "f").subscribeAgentUpdated();
|
|
17279
|
+
__classPrivateFieldGet$1(this, _Ad4mClient_agentClient, "f").subscribeAgentStatusChanged();
|
|
17280
|
+
__classPrivateFieldGet$1(this, _Ad4mClient_agentClient, "f").subscribeAppsChanged();
|
|
17281
|
+
}
|
|
17282
|
+
/** Close all event connections and clear in-memory caches */
|
|
17283
|
+
close() {
|
|
17284
|
+
__classPrivateFieldGet$1(this, _Ad4mClient_agentClient, "f").clearByDidCache();
|
|
17285
|
+
__classPrivateFieldGet$1(this, _Ad4mClient_apiClient, "f").closeAll();
|
|
17286
|
+
}
|
|
17287
|
+
}
|
|
17288
|
+
_Ad4mClient_baseUrl = new WeakMap(), _Ad4mClient_token = new WeakMap(), _Ad4mClient_apiClient = new WeakMap(), _Ad4mClient_agentClient = new WeakMap(), _Ad4mClient_expressionClient = new WeakMap(), _Ad4mClient_languageClient = new WeakMap(), _Ad4mClient_neighbourhoodClient = new WeakMap(), _Ad4mClient_perspectiveClient = new WeakMap(), _Ad4mClient_runtimeClient = new WeakMap(), _Ad4mClient_aiClient = new WeakMap();
|
|
17289
|
+
|
|
17290
|
+
var ExceptionType;
|
|
17291
|
+
(function (ExceptionType) {
|
|
17292
|
+
ExceptionType["LanguageIsNotLoaded"] = "LANGUAGE_IS_NOT_LOADED";
|
|
17293
|
+
ExceptionType["ExpressionIsNotVerified"] = "EXPRESSION_IS_NOT_VERIFIED";
|
|
17294
|
+
ExceptionType["AgentIsUntrusted"] = "AGENT_IS_UNTRUSTED";
|
|
17295
|
+
ExceptionType["CapabilityRequested"] = "CAPABILITY_REQUESTED";
|
|
17296
|
+
ExceptionType["InstallNotificationRequest"] = "INSTALL_NOTIFICATION_REQUEST";
|
|
17297
|
+
})(ExceptionType || (ExceptionType = {}));
|
|
17298
|
+
|
|
17299
|
+
// Unique Language ID with option type
|
|
17300
|
+
class LanguageRef {
|
|
17301
|
+
constructor(address, name) {
|
|
17302
|
+
this.address = address;
|
|
17303
|
+
this.name = name;
|
|
17304
|
+
}
|
|
17305
|
+
}
|
|
17306
|
+
|
|
17307
|
+
// Expression address + unique Language ID = global expression URL
|
|
17308
|
+
class ExpressionRef {
|
|
17309
|
+
constructor(lang, expr) {
|
|
17310
|
+
this.language = lang;
|
|
17311
|
+
this.expression = expr;
|
|
17312
|
+
}
|
|
17313
|
+
}
|
|
17314
|
+
// Creates unique expression URI like this:
|
|
17315
|
+
// expr:Qm3490gfwe489hf34:Qm90ghjoaw4iehioefwe4ort
|
|
17316
|
+
function exprRef2String(ref) {
|
|
17317
|
+
if (ref.language.address === 'did')
|
|
17318
|
+
return ref.expression.toString();
|
|
17319
|
+
else
|
|
17320
|
+
return `${ref.language.address}://${ref.expression}`;
|
|
17321
|
+
}
|
|
17322
|
+
function parseExprUrl(url) {
|
|
17323
|
+
if (url.startsWith("literal:")) {
|
|
17324
|
+
const languageRef = new LanguageRef();
|
|
17325
|
+
languageRef.address = 'literal';
|
|
17326
|
+
languageRef.name = 'literal';
|
|
17327
|
+
const content = url.substring(8);
|
|
17328
|
+
return new ExpressionRef(languageRef, content);
|
|
17329
|
+
}
|
|
17330
|
+
const URIregexp = /^([^:^\s]+):\/\/([\s\S]+)$/;
|
|
17331
|
+
const URImatches = URIregexp.exec(url);
|
|
17332
|
+
if (URImatches && URImatches.length == 3) {
|
|
17333
|
+
const language = URImatches[1];
|
|
17334
|
+
const expression = URImatches[2];
|
|
17335
|
+
const languageRef = new LanguageRef();
|
|
17336
|
+
languageRef.address = language;
|
|
17337
|
+
const ref = new ExpressionRef(languageRef, expression);
|
|
17338
|
+
return ref;
|
|
17339
|
+
}
|
|
17340
|
+
const DIDregexp = /^did:([^\s]+)$/;
|
|
17341
|
+
const DIDmatches = DIDregexp.exec(url);
|
|
17342
|
+
if (DIDmatches && DIDmatches.length == 2) {
|
|
17343
|
+
const languageRef = new LanguageRef();
|
|
17344
|
+
languageRef.address = 'did';
|
|
17345
|
+
const ref = new ExpressionRef(languageRef, url);
|
|
17346
|
+
return ref;
|
|
17347
|
+
}
|
|
17348
|
+
throw new Error("Couldn't parse string as expression URL or DID: " + url);
|
|
17349
|
+
}
|
|
17350
|
+
|
|
17351
|
+
class Icon {
|
|
17352
|
+
constructor(code) {
|
|
17353
|
+
this.code = code;
|
|
17354
|
+
}
|
|
17355
|
+
}
|
|
17356
|
+
|
|
17357
|
+
/**
|
|
17358
|
+
* # AD4M Language — client-side types
|
|
17359
|
+
*
|
|
17360
|
+
* This file only contains the client-visible types that the AD4M REST
|
|
17361
|
+
* API exposes on top of a running Language — interaction metadata, online
|
|
17362
|
+
* agent records, and the telepresence-signal callback shape.
|
|
17363
|
+
*
|
|
17364
|
+
* **If you're authoring an AD4M Language**, you don't consume types from
|
|
17365
|
+
* here — use [`@coasys/ad4m-ldk`](https://www.npmjs.com/package/@coasys/ad4m-ldk)
|
|
17366
|
+
* (or the [Rust ALDK](https://crates.io/crates/ad4m-ldk)), which provide
|
|
17367
|
+
* the capability traits, typed runtime-import wrappers, and authoring
|
|
17368
|
+
* macros/helpers.
|
|
17369
|
+
*
|
|
17370
|
+
* The normative interface definition lives in
|
|
17371
|
+
* [`docs-src/ad4m-lang.wit`](https://github.com/coasys/ad4m/blob/dev/docs-src/ad4m-lang.wit).
|
|
17372
|
+
* The prose spec is
|
|
17373
|
+
* [`docs-src/language-interface-spec.md`](https://github.com/coasys/ad4m/blob/dev/docs-src/language-interface-spec.md).
|
|
17374
|
+
*/
|
|
17375
|
+
// ----- Interaction metadata --------------------------------------------------
|
|
17376
|
+
//
|
|
17377
|
+
// Languages optionally publish a list of user-invocable actions per
|
|
17378
|
+
// Expression ("interactions"). The runtime surfaces these to UIs via
|
|
17379
|
+
// the API as first-class objects.
|
|
17380
|
+
class InteractionParameter {
|
|
17381
|
+
}
|
|
17382
|
+
class InteractionMeta {
|
|
17383
|
+
}
|
|
17384
|
+
class InteractionCall {
|
|
17385
|
+
get parameters() {
|
|
17386
|
+
return JSON.parse(this.parametersStringified);
|
|
17387
|
+
}
|
|
17388
|
+
constructor(name, parameters) {
|
|
17389
|
+
this.name = name;
|
|
17390
|
+
this.parametersStringified = JSON.stringify(parameters);
|
|
17391
|
+
}
|
|
17392
|
+
}
|
|
17393
|
+
// ----- Telepresence ----------------------------------------------------------
|
|
17394
|
+
class OnlineAgent {
|
|
17395
|
+
}
|
|
17396
|
+
|
|
17397
|
+
class LanguageHandle {
|
|
17398
|
+
}
|
|
17399
|
+
|
|
17400
|
+
class LanguageMeta {
|
|
17401
|
+
}
|
|
17402
|
+
class LanguageMetaInput {
|
|
17403
|
+
constructor(name, description) {
|
|
17404
|
+
this.name = name;
|
|
17405
|
+
this.description = description;
|
|
17406
|
+
if (!this.description)
|
|
17407
|
+
this.description = "";
|
|
17408
|
+
}
|
|
17409
|
+
}
|
|
17410
|
+
class LanguageMetaInternal {
|
|
17411
|
+
}
|
|
17412
|
+
class LanguageExpression extends ExpressionGeneric() {
|
|
17413
|
+
}
|
|
17414
|
+
class LanguageLanguageInput {
|
|
17415
|
+
}
|
|
17416
|
+
|
|
17417
|
+
var PerspectiveState;
|
|
17418
|
+
(function (PerspectiveState) {
|
|
17419
|
+
PerspectiveState["Private"] = "PRIVATE";
|
|
17420
|
+
PerspectiveState["NeighboudhoodCreationInitiated"] = "NEIGHBOURHOOD_CREATION_INITIATED";
|
|
17421
|
+
PerspectiveState["NeighbourhoodJoinInitiated"] = "NEIGHBOURHOOD_JOIN_INITIATED";
|
|
17422
|
+
PerspectiveState["LinkLanguageFailedToInstall"] = "LINK_LANGUAGE_FAILED_TO_INSTALL";
|
|
17423
|
+
PerspectiveState["LinkLanguageInstalledButNotSynced"] = "LINK_LANGUAGE_INSTALLED_BUT_NOT_SYNCED";
|
|
17424
|
+
PerspectiveState["Synced"] = "SYNCED";
|
|
17425
|
+
})(PerspectiveState || (PerspectiveState = {}));
|
|
17426
|
+
// This type is used in the REST interface to reference a mutable
|
|
17427
|
+
// prespective that is implemented locally by the Ad4m runtime.
|
|
17428
|
+
// The UUID is used in mutations to identify the perspective that gets mutated.
|
|
17429
|
+
class PerspectiveHandle {
|
|
17430
|
+
constructor(uuid, name, state) {
|
|
17431
|
+
this.uuid = uuid;
|
|
17432
|
+
this.name = name;
|
|
17433
|
+
if (state) {
|
|
17434
|
+
this.state = state;
|
|
17435
|
+
}
|
|
17436
|
+
else {
|
|
17437
|
+
this.state = PerspectiveState.Private;
|
|
17438
|
+
}
|
|
17439
|
+
}
|
|
17440
|
+
}
|
|
17441
|
+
|
|
17442
|
+
/**
|
|
17443
|
+
* WakerSubscriptionManager — manages live query subscriptions for the waker.
|
|
17444
|
+
*
|
|
17445
|
+
* Lives in core so it can be imported by both the plugin and integration tests
|
|
17446
|
+
* without ESM/CJS import issues.
|
|
17447
|
+
*
|
|
17448
|
+
* NOTE: keep in sync with plugins/ad4m/wakerSubscriptionManager.ts
|
|
17449
|
+
*/
|
|
17450
|
+
class WakerSubscriptionManager {
|
|
17451
|
+
constructor(options) {
|
|
17452
|
+
this.proxies = new Map();
|
|
17453
|
+
this.activeSubscriptions = new Map();
|
|
17454
|
+
this.debounceTimers = new Map();
|
|
17455
|
+
/** Per-subscription set of already-processed message addresses (for mention subs)
|
|
17456
|
+
* or serialized result hash (for channel-messages subs). */
|
|
17457
|
+
this.seenMessages = new Map();
|
|
17458
|
+
this.perspectiveClient = options.perspectiveClient;
|
|
17459
|
+
this.logger = options.logger;
|
|
17460
|
+
this.debounceMs = options.debounceMs ?? 2000;
|
|
17461
|
+
this.onWake = options.onWake;
|
|
17462
|
+
this.onPersist = options.onPersist;
|
|
17463
|
+
this.QuerySubscriptionProxyCtor = options.QuerySubscriptionProxy ?? null;
|
|
17464
|
+
this.previousSeenMessages = options.previousSeenMessages ?? {};
|
|
17465
|
+
}
|
|
17466
|
+
/**
|
|
17467
|
+
* Create a live SPARQL subscription.
|
|
17468
|
+
* If a subscription with the same id already exists, it is disposed first.
|
|
17469
|
+
*/
|
|
17470
|
+
async subscribe(sub) {
|
|
17471
|
+
// Dispose existing subscription with same id if any
|
|
17472
|
+
this.dispose(sub.id, false);
|
|
17473
|
+
if (!this.QuerySubscriptionProxyCtor) {
|
|
17474
|
+
throw new Error("WakerSubscriptionManager: QuerySubscriptionProxy must be provided via constructor options");
|
|
17475
|
+
}
|
|
17476
|
+
const QuerySubscriptionProxy = this.QuerySubscriptionProxyCtor;
|
|
17477
|
+
this.logger.info(`[waker] ${sub.id}: creating subscription (perspective=${sub.perspective}, type=${sub.type})`);
|
|
17478
|
+
this.logger.info(`[waker] ${sub.id}: SPARQL query:\n${sub.query}`);
|
|
17479
|
+
const proxy = new QuerySubscriptionProxy(sub.perspective, sub.query, this.perspectiveClient);
|
|
17480
|
+
proxy.isSPARQL = true;
|
|
17481
|
+
// Suppress unhandled rejection from proxy.initialized — QuerySubscriptionProxy
|
|
17482
|
+
// rejects this promise internally when subscribe() fails, and if nobody catches
|
|
17483
|
+
// it before the next microtask it crashes the process.
|
|
17484
|
+
if (proxy.initialized && typeof proxy.initialized.catch === "function") {
|
|
17485
|
+
proxy.initialized.catch(() => { });
|
|
17486
|
+
}
|
|
17487
|
+
try {
|
|
17488
|
+
await proxy.subscribe();
|
|
17489
|
+
await proxy.initialized;
|
|
17490
|
+
}
|
|
17491
|
+
catch (err) {
|
|
17492
|
+
const msg = err?.message ?? String(err);
|
|
17493
|
+
this.logger.warn(`[waker] ${sub.id}: subscription failed — ${msg}`);
|
|
17494
|
+
try {
|
|
17495
|
+
proxy.dispose();
|
|
17496
|
+
}
|
|
17497
|
+
catch { }
|
|
17498
|
+
// Remove from active state so it doesn't get persisted/retried
|
|
17499
|
+
this.activeSubscriptions.delete(sub.id);
|
|
17500
|
+
this.seenMessages.delete(sub.id);
|
|
17501
|
+
this.persist();
|
|
17502
|
+
return; // Don't throw — caller should not crash
|
|
17503
|
+
}
|
|
17504
|
+
this.logger.info(`[waker] ${sub.id}: subscription initialized successfully`);
|
|
17505
|
+
// Seed from persisted seen messages so we don't re-wake after restart
|
|
17506
|
+
const seen = new Set(this.previousSeenMessages[sub.id] ?? []);
|
|
17507
|
+
this.seenMessages.set(sub.id, seen);
|
|
17508
|
+
if (seen.size > 0) {
|
|
17509
|
+
this.logger.info(`[waker] ${sub.id}: seeded ${seen.size} seen message(s) from persisted state`);
|
|
17510
|
+
}
|
|
17511
|
+
proxy.onResult(async (result) => {
|
|
17512
|
+
this.logger.info(`[waker] ${sub.id}: onResult fired — type=${typeof result}, isArray=${Array.isArray(result)}, value=${String(JSON.stringify(result)).substring(0, 500)}`);
|
|
17513
|
+
// Query engine can deliver non-array values (e.g. false) on disconnect/reconnect — ignore them
|
|
17514
|
+
if (!Array.isArray(result)) {
|
|
17515
|
+
this.logger.warn(`[waker] ${sub.id}: ignoring non-array result: ${JSON.stringify(result)}`);
|
|
17516
|
+
return;
|
|
17517
|
+
}
|
|
17518
|
+
if (sub.type === "mention") {
|
|
17519
|
+
// For mention subscriptions: track seen message addresses.
|
|
17520
|
+
// Only wake for messages we haven't seen before.
|
|
17521
|
+
const currentSeen = this.seenMessages.get(sub.id) ?? new Set();
|
|
17522
|
+
const newMessages = [];
|
|
17523
|
+
for (const item of result) {
|
|
17524
|
+
if (item && item.source && !currentSeen.has(item.source)) {
|
|
17525
|
+
newMessages.push(item.source);
|
|
17526
|
+
}
|
|
17527
|
+
}
|
|
17528
|
+
if (newMessages.length === 0) {
|
|
17529
|
+
this.logger.info(`[waker] ${sub.id}: all ${result.length} items already seen, skipping`);
|
|
17530
|
+
return;
|
|
17531
|
+
}
|
|
17532
|
+
this.logger.info(`[waker] ${sub.id}: ${newMessages.length} new message(s) out of ${result.length} total`);
|
|
17533
|
+
// Resolve parents per new message
|
|
17534
|
+
const mentions = [];
|
|
17535
|
+
for (const msgAddr of newMessages) {
|
|
17536
|
+
const parents = [];
|
|
17537
|
+
try {
|
|
17538
|
+
const parentQuery = `SELECT ?source WHERE { ?source <ad4m://has_child> <${msgAddr}> . }`;
|
|
17539
|
+
this.logger.info(`[waker] ${sub.id}: resolving parents for ${msgAddr}`);
|
|
17540
|
+
const parentResult = await this.perspectiveClient.querySparql(sub.perspective, parentQuery);
|
|
17541
|
+
if (Array.isArray(parentResult)) {
|
|
17542
|
+
for (const link of parentResult) {
|
|
17543
|
+
if (link && link.source) {
|
|
17544
|
+
parents.push(link.source);
|
|
17545
|
+
}
|
|
17546
|
+
}
|
|
17547
|
+
}
|
|
17548
|
+
}
|
|
17549
|
+
catch (err) {
|
|
17550
|
+
this.logger.warn(`[waker] ${sub.id}: parent resolution failed for ${msgAddr} — ${err?.message ?? err}`);
|
|
17551
|
+
}
|
|
17552
|
+
this.logger.info(`[waker] ${sub.id}: message ${msgAddr} has ${parents.length} parent(s): ${parents.join(", ")}`);
|
|
17553
|
+
mentions.push({ address: msgAddr, parents });
|
|
17554
|
+
}
|
|
17555
|
+
// Mark all new messages as seen
|
|
17556
|
+
for (const addr of newMessages) {
|
|
17557
|
+
currentSeen.add(addr);
|
|
17558
|
+
}
|
|
17559
|
+
this.seenMessages.set(sub.id, currentSeen);
|
|
17560
|
+
// Debounce the wake callback
|
|
17561
|
+
const existing = this.debounceTimers.get(sub.id);
|
|
17562
|
+
if (existing)
|
|
17563
|
+
clearTimeout(existing);
|
|
17564
|
+
this.debounceTimers.set(sub.id, setTimeout(() => {
|
|
17565
|
+
this.onWake(sub, result, mentions);
|
|
17566
|
+
this.debounceTimers.delete(sub.id);
|
|
17567
|
+
this.persist();
|
|
17568
|
+
}, this.debounceMs));
|
|
17569
|
+
}
|
|
17570
|
+
else {
|
|
17571
|
+
// For channel-messages: always notify the agent on every subscription push.
|
|
17572
|
+
// No deduplication — the agent reads recent messages itself.
|
|
17573
|
+
this.logger.info(`[waker] ${sub.id}: channel update (${result.length} items)`);
|
|
17574
|
+
const existing = this.debounceTimers.get(sub.id);
|
|
17575
|
+
if (existing)
|
|
17576
|
+
clearTimeout(existing);
|
|
17577
|
+
this.debounceTimers.set(sub.id, setTimeout(() => {
|
|
17578
|
+
this.onWake(sub, result);
|
|
17579
|
+
this.debounceTimers.delete(sub.id);
|
|
17580
|
+
}, this.debounceMs));
|
|
17581
|
+
}
|
|
17582
|
+
});
|
|
17583
|
+
this.proxies.set(sub.id, proxy);
|
|
17584
|
+
this.activeSubscriptions.set(sub.id, sub);
|
|
17585
|
+
this.persist();
|
|
17586
|
+
this.logger.info(`[waker] Subscription ${sub.id} active (type=${sub.type}, perspective=${sub.perspective})`);
|
|
17587
|
+
}
|
|
17588
|
+
/**
|
|
17589
|
+
* Dispose a single subscription.
|
|
17590
|
+
* @param persist — if false, skip calling onPersist (used during batch cleanup).
|
|
17591
|
+
*/
|
|
17592
|
+
dispose(id, persist = true) {
|
|
17593
|
+
const proxy = this.proxies.get(id);
|
|
17594
|
+
if (proxy) {
|
|
17595
|
+
try {
|
|
17596
|
+
proxy.dispose();
|
|
17597
|
+
}
|
|
17598
|
+
catch {
|
|
17599
|
+
/* ignore */
|
|
17600
|
+
}
|
|
17601
|
+
this.proxies.delete(id);
|
|
17602
|
+
}
|
|
17603
|
+
const timer = this.debounceTimers.get(id);
|
|
17604
|
+
if (timer) {
|
|
17605
|
+
clearTimeout(timer);
|
|
17606
|
+
this.debounceTimers.delete(id);
|
|
17607
|
+
}
|
|
17608
|
+
this.activeSubscriptions.delete(id);
|
|
17609
|
+
this.seenMessages.delete(id);
|
|
17610
|
+
if (persist)
|
|
17611
|
+
this.persist();
|
|
17612
|
+
}
|
|
17613
|
+
/** Dispose all active subscriptions. */
|
|
17614
|
+
disposeAll() {
|
|
17615
|
+
for (const [id] of this.proxies) {
|
|
17616
|
+
this.dispose(id, false);
|
|
17617
|
+
}
|
|
17618
|
+
}
|
|
17619
|
+
/** Get all active subscriptions. */
|
|
17620
|
+
getActive() {
|
|
17621
|
+
return Array.from(this.activeSubscriptions.values());
|
|
17622
|
+
}
|
|
17623
|
+
/** Check if a subscription exists. */
|
|
17624
|
+
has(id) {
|
|
17625
|
+
return this.activeSubscriptions.has(id);
|
|
17626
|
+
}
|
|
17627
|
+
persist() {
|
|
17628
|
+
if (this.onPersist) {
|
|
17629
|
+
const seen = {};
|
|
17630
|
+
for (const [id, set] of this.seenMessages) {
|
|
17631
|
+
seen[id] = Array.from(set);
|
|
17632
|
+
}
|
|
17633
|
+
this.onPersist(this.getActive(), seen);
|
|
17634
|
+
}
|
|
17635
|
+
}
|
|
17636
|
+
}
|
|
17637
|
+
|
|
17638
|
+
class PerspectiveDiff {
|
|
17639
|
+
}
|
|
17640
|
+
class PerspectiveDiffExpression extends ExpressionGeneric() {
|
|
17641
|
+
}
|
|
17642
|
+
|
|
17643
|
+
var __classPrivateFieldSet = (undefined && undefined.__classPrivateFieldSet) || function (receiver, state, value, kind, f) {
|
|
17644
|
+
if (kind === "m") throw new TypeError("Private method is not writable");
|
|
17645
|
+
if (kind === "a" && !f) throw new TypeError("Private accessor was defined without a setter");
|
|
17646
|
+
if (typeof state === "function" ? receiver !== state || !f : !state.has(receiver)) throw new TypeError("Cannot write private member to an object whose class did not declare it");
|
|
17647
|
+
return (kind === "a" ? f.call(receiver, value) : f ? f.value = value : state.set(receiver, value)), value;
|
|
17648
|
+
};
|
|
17649
|
+
var __classPrivateFieldGet = (undefined && undefined.__classPrivateFieldGet) || function (receiver, state, kind, f) {
|
|
17650
|
+
if (kind === "a" && !f) throw new TypeError("Private accessor was defined without a getter");
|
|
17651
|
+
if (typeof state === "function" ? receiver !== state || !f : !state.has(receiver)) throw new TypeError("Cannot read private member from an object whose class did not declare it");
|
|
17652
|
+
return kind === "m" ? f : kind === "a" ? f.call(receiver) : f ? f.value : state.get(receiver);
|
|
17653
|
+
};
|
|
17654
|
+
var _SmartLiteral_perspective, _SmartLiteral_base;
|
|
17655
|
+
const SMART_LITERAL_CONTENT_PREDICATE = "smart_literal://content";
|
|
17656
|
+
function makeRandomStringID(length) {
|
|
17657
|
+
let result = '';
|
|
17658
|
+
let characters = 'ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz0123456789';
|
|
17659
|
+
let charactersLength = characters.length;
|
|
17660
|
+
for (let i = 0; i < length; i++) {
|
|
17661
|
+
result += characters.charAt(Math.floor(Math.random() * charactersLength));
|
|
17662
|
+
}
|
|
17663
|
+
return result;
|
|
17664
|
+
}
|
|
17665
|
+
class SmartLiteral {
|
|
17666
|
+
constructor(perspective, base) {
|
|
17667
|
+
_SmartLiteral_perspective.set(this, void 0);
|
|
17668
|
+
_SmartLiteral_base.set(this, void 0);
|
|
17669
|
+
__classPrivateFieldSet(this, _SmartLiteral_perspective, perspective, "f");
|
|
17670
|
+
__classPrivateFieldSet(this, _SmartLiteral_base, base, "f");
|
|
17671
|
+
}
|
|
17672
|
+
get base() {
|
|
17673
|
+
return __classPrivateFieldGet(this, _SmartLiteral_base, "f");
|
|
17674
|
+
}
|
|
17675
|
+
static async create(perspective, literal) {
|
|
17676
|
+
const base = Literal.from(makeRandomStringID(10)).toUrl();
|
|
17677
|
+
const smartLiteral = new SmartLiteral(perspective, base);
|
|
17678
|
+
await smartLiteral.set(literal);
|
|
17679
|
+
return smartLiteral;
|
|
17680
|
+
}
|
|
17681
|
+
static async isSmartLiteralBase(perspective, base) {
|
|
17682
|
+
let links = await perspective.get(new LinkQuery({
|
|
17683
|
+
source: base,
|
|
17684
|
+
predicate: SMART_LITERAL_CONTENT_PREDICATE
|
|
17685
|
+
}));
|
|
17686
|
+
return links.length > 0;
|
|
17687
|
+
}
|
|
17688
|
+
static async getAllSmartLiterals(perspective) {
|
|
17689
|
+
let links = await perspective.get(new LinkQuery({
|
|
17690
|
+
predicate: SMART_LITERAL_CONTENT_PREDICATE
|
|
17691
|
+
}));
|
|
17692
|
+
return links.map(link => new SmartLiteral(perspective, link.data.source));
|
|
17693
|
+
}
|
|
17694
|
+
async get() {
|
|
17695
|
+
let link = await __classPrivateFieldGet(this, _SmartLiteral_perspective, "f").getSingleTarget(new LinkQuery({
|
|
17696
|
+
source: __classPrivateFieldGet(this, _SmartLiteral_base, "f"),
|
|
17697
|
+
predicate: SMART_LITERAL_CONTENT_PREDICATE
|
|
17698
|
+
}));
|
|
17699
|
+
if (!link) {
|
|
17700
|
+
throw `No content for smart literal ${__classPrivateFieldGet(this, _SmartLiteral_base, "f")}`;
|
|
17701
|
+
}
|
|
17702
|
+
return Literal.fromUrl(link).get();
|
|
17703
|
+
}
|
|
17704
|
+
async set(content) {
|
|
17705
|
+
let literal = Literal.from(content);
|
|
17706
|
+
await __classPrivateFieldGet(this, _SmartLiteral_perspective, "f").setSingleTarget(new Link({
|
|
17707
|
+
source: __classPrivateFieldGet(this, _SmartLiteral_base, "f"),
|
|
17708
|
+
predicate: SMART_LITERAL_CONTENT_PREDICATE,
|
|
17709
|
+
target: literal.toUrl()
|
|
17710
|
+
}));
|
|
17711
|
+
}
|
|
17712
|
+
}
|
|
17713
|
+
_SmartLiteral_perspective = new WeakMap(), _SmartLiteral_base = new WeakMap();
|
|
17714
|
+
|
|
17715
|
+
/**
|
|
17716
|
+
* Shared type definitions for the Ad4mModel system.
|
|
17717
|
+
*
|
|
17718
|
+
* Extracted into a standalone module so that utility files
|
|
17719
|
+
* (`query-utils.ts`, `decorators.ts`, etc.) can import types without
|
|
17720
|
+
* creating circular runtime dependencies on `Ad4mModel.ts`.
|
|
17721
|
+
*/
|
|
17722
|
+
/** Type guard for IncludeProjection objects. */
|
|
17723
|
+
function isIncludeProjection(val) {
|
|
17724
|
+
return typeof val === 'object' && val !== null && 'from' in val;
|
|
17725
|
+
}
|
|
17726
|
+
|
|
17592
17727
|
class Neighbourhood {
|
|
17593
17728
|
constructor(linkLanguage, meta) {
|
|
17594
17729
|
this.linkLanguage = linkLanguage;
|
|
@@ -17621,4 +17756,4 @@ class ModelInput {
|
|
|
17621
17756
|
class VoiceActivityParamsInput {
|
|
17622
17757
|
}
|
|
17623
17758
|
|
|
17624
|
-
export { AIClient, Model as AIModel, AIModelLoadingStatus, AIPromptExamples, AIPromptExamplesInput, AITask, AITaskInput, Ad4mClient, Ad4mModel, Agent, AgentClient, AgentExpression, AgentSignature, AgentStatus, Apps, AuthInfo, AuthInfoInput, BelongsToMany, BelongsToOne, Capability, CapabilityInput, ComputeLogEntry, EntanglementProof, EntanglementProofInput, ExceptionInfo, ExceptionType, Expression, ExpressionGeneric, ExpressionGenericInput, ExpressionProof, ExpressionProofInput, ExpressionRef, ExpressionRendered, Flag, HasMany, HasOne, HostingUserInfo, Icon, ImportResult, ImportStats, InteractionCall, InteractionMeta, InteractionParameter, LanguageExpression, LanguageHandle, LanguageLanguageInput, LanguageMeta, LanguageMetaInput, LanguageMetaInternal, LanguageRef, Link, LinkExpression, LinkExpressionInput, LinkExpressionMutations, LinkExpressionUpdated, LinkInput, LinkMutations, LinkQuery, Literal, LocalModel, LocalModelInput, Model$1 as Model, ModelApi, ModelApiInput, ModelInput, ModelQueryBuilder, Neighbourhood, NeighbourhoodExpression, NeighbourhoodProxy, Notification, NotificationInput, OnlineAgent, Optional, PaymentRequestResult, Perspective, PerspectiveDiff, PerspectiveDiffExpression, PerspectiveExpression, PerspectiveHandle, PerspectiveInput, PerspectiveProxy, PerspectiveState, PerspectiveUnsignedInput, Property, QuerySubscriptionProxy, ReadOnly, Resource, ResourceInput, RpcError as RestError, RpcError, RuntimeInfo, SHACLFlow, SHACLShape, SMART_LITERAL_CONTENT_PREDICATE, SentMessage, SmartLiteral, TokenizerSource, TokenizerSourceInput, TriggeredNotification, UserCreationResult, UserStatistics, VerificationRequestResult, VoiceActivityParamsInput, WakerSubscriptionManager, buildConformanceFilter,
|
|
17759
|
+
export { AIClient, Model as AIModel, AIModelLoadingStatus, AIPromptExamples, AIPromptExamplesInput, AITask, AITaskInput, Ad4mClient, Ad4mModel, Agent, AgentClient, AgentExpression, AgentSignature, AgentStatus, Apps, AuthInfo, AuthInfoInput, BelongsToMany, BelongsToOne, Capability, CapabilityInput, ComputeLogEntry, EntanglementProof, EntanglementProofInput, ExceptionInfo, ExceptionType, Expression, ExpressionGeneric, ExpressionGenericInput, ExpressionProof, ExpressionProofInput, ExpressionRef, ExpressionRendered, Flag, HasMany, HasOne, HostingUserInfo, IDBCache, Icon, ImportResult, ImportStats, InteractionCall, InteractionMeta, InteractionParameter, LanguageExpression, LanguageHandle, LanguageLanguageInput, LanguageMeta, LanguageMetaInput, LanguageMetaInternal, LanguageRef, Link, LinkExpression, LinkExpressionInput, LinkExpressionMutations, LinkExpressionUpdated, LinkInput, LinkMutations, LinkQuery, Literal, LocalModel, LocalModelInput, Model$1 as Model, ModelApi, ModelApiInput, ModelInput, ModelQueryBuilder, Neighbourhood, NeighbourhoodExpression, NeighbourhoodProxy, Notification, NotificationInput, NullCache, OnlineAgent, Optional, PaymentRequestResult, Perspective, PerspectiveDiff, PerspectiveDiffExpression, PerspectiveExpression, PerspectiveHandle, PerspectiveInput, PerspectiveProxy, PerspectiveState, PerspectiveUnsignedInput, Property, QuerySubscriptionProxy, ReadOnly, Resource, ResourceInput, RpcError as RestError, RpcError, RuntimeInfo, SHACLFlow, SHACLShape, SMART_LITERAL_CONTENT_PREDICATE, SentMessage, SmartLiteral, TokenizerSource, TokenizerSourceInput, TriggeredNotification, UserCreationResult, UserStatistics, VerificationRequestResult, VoiceActivityParamsInput, WakerSubscriptionManager, buildConformanceFilter, buildModelFromJSONSchema, buildPaginationSubquery, buildSDNA, buildSHACL, buildSPARQLOrderLimitOffset, buildSPARQLQuery, buildWhereCondition, capSentence, clearQueryCache, compileWhereClause, createPersistentCache, determineNamespace, determinePredicate, escapeQueryString, exprRef2String, formatList, formatQueryValue, formatSPARQLValue, getCachedResult, getDefaultValueForType, getMemoizedSHACL, getPropertiesMetadata, getPropertyOption, getRelationsMetadata, hasJsOnlyWhereFilters, invalidatePerspectiveCache, isArrayType, isExpression, isIncludeProjection, isLink, isNumericType, isObjectType, isSchemaType, linkEqual, normalizeNamespaceString, normalizeSchemaType, normalizeValue, parseExprUrl, queryCacheSize, resolveParentPredicate, setCachedResult, setPropertyRegistryEntry, setRelationRegistryEntry, typeDefsString };
|