@coasys/ad4m 0.13.1-staging.13 → 0.13.1-staging.14
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 +548 -477
- package/lib/index.js +548 -473
- package/lib/src/agent/AgentClient.d.ts +9 -8
- package/lib/src/agent/AgentClient.js +46 -67
- package/lib/src/cache/KeyedCache.d.ts +51 -0
- package/lib/src/cache/KeyedCache.js +142 -0
- package/lib/src/expression/ExpressionClient.d.ts +14 -3
- package/lib/src/expression/ExpressionClient.js +49 -111
- package/lib/src/generated/api/ExpressionLookupError.d.ts +7 -0
- package/lib/src/generated/api/ExpressionLookupError.js +2 -0
- package/lib/src/generated/api/ExpressionManyEntry.d.ts +6 -0
- package/lib/src/generated/api/ExpressionManyEntry.js +1 -0
- package/lib/src/generated/api/FlowFiredEntry.d.ts +11 -0
- package/lib/src/generated/api/FlowFiredEntry.js +2 -0
- package/lib/src/generated/api/PerspectiveFlowFiredParams.d.ts +3 -3
- package/lib/src/generated/api/RpcMethods.d.ts +4 -2
- package/lib/src/model/Ad4mModel.d.ts +26 -2
- package/lib/src/model/Ad4mModel.js +125 -82
- package/lib/src/model/ModelQueryBuilder.d.ts +3 -0
- package/lib/src/model/ModelQueryBuilder.js +42 -14
- package/lib/src/model/index.d.ts +0 -1
- package/lib/src/model/index.js +0 -1
- package/lib/src/model/query-common.d.ts +8 -0
- package/lib/src/model/query-common.js +12 -0
- package/lib/src/model/types.d.ts +12 -3
- package/lib/src/perspectives/FlowModels.js +1 -1
- package/lib/src/perspectives/LiveQuery.d.ts +1 -1
- package/lib/src/perspectives/PerspectiveClient.d.ts +17 -6
- package/lib/src/perspectives/PerspectiveClient.js +83 -44
- package/lib/src/perspectives/PerspectiveProxy.d.ts +19 -10
- package/lib/src/perspectives/PerspectiveProxy.js +31 -69
- package/package.json +2 -2
- package/src/Ad4mClient.test.ts +17 -6
- package/src/agent/AgentClient.ts +46 -74
- package/src/cache/KeyedCache.test.ts +162 -0
- package/src/cache/KeyedCache.ts +179 -0
- package/src/cache/cache.test.ts +294 -71
- package/src/expression/ExpressionClient.ts +46 -131
- package/src/generated/api/ExpressionLookupError.ts +6 -0
- package/src/generated/api/ExpressionManyEntry.ts +8 -0
- package/src/generated/api/FlowFiredEntry.ts +11 -0
- package/src/generated/api/PerspectiveFlowFiredParams.ts +3 -3
- package/src/generated/api/RpcMethods.ts +4 -2
- package/src/model/Ad4mModel.test.ts +237 -43
- package/src/model/Ad4mModel.ts +132 -98
- package/src/model/ModelQueryBuilder.ts +41 -15
- package/src/model/count-result-type.test.ts +72 -0
- package/src/model/index.ts +0 -1
- package/src/model/query-common.ts +13 -0
- package/src/model/relation-filtering.test.ts +3 -5
- package/src/model/types.ts +9 -3
- package/src/model/write-round-trips.test.ts +30 -6
- package/src/perspectives/FlowModels.ts +1 -1
- package/src/perspectives/LiveQuery.ts +1 -1
- package/src/perspectives/PerspectiveClient.test.ts +287 -0
- package/src/perspectives/PerspectiveClient.ts +101 -66
- package/src/perspectives/PerspectiveProxy.test.ts +6 -14
- package/src/perspectives/PerspectiveProxy.ts +33 -67
- package/src/perspectives/TextContent.test.ts +0 -16
- package/src/perspectives/shacl-rpc.test.ts +1 -1
- package/lib/src/model/query-cache.d.ts +0 -30
- package/lib/src/model/query-cache.js +0 -66
- package/src/model/query-cache.test.ts +0 -54
- package/src/model/query-cache.ts +0 -79
package/lib/index.js
CHANGED
|
@@ -1332,13 +1332,13 @@ function isBot(agent) {
|
|
|
1332
1332
|
* never need try/catch around cache operations
|
|
1333
1333
|
* - Tree-shakeable: import only what you need
|
|
1334
1334
|
*/
|
|
1335
|
-
var __classPrivateFieldSet$
|
|
1335
|
+
var __classPrivateFieldSet$f = (undefined && undefined.__classPrivateFieldSet) || function (receiver, state, value, kind, f) {
|
|
1336
1336
|
if (kind === "m") throw new TypeError("Private method is not writable");
|
|
1337
1337
|
if (kind === "a" && !f) throw new TypeError("Private accessor was defined without a setter");
|
|
1338
1338
|
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");
|
|
1339
1339
|
return (kind === "a" ? f.call(receiver, value) : f ? f.value = value : state.set(receiver, value)), value;
|
|
1340
1340
|
};
|
|
1341
|
-
var __classPrivateFieldGet$
|
|
1341
|
+
var __classPrivateFieldGet$f = (undefined && undefined.__classPrivateFieldGet) || function (receiver, state, kind, f) {
|
|
1342
1342
|
if (kind === "a" && !f) throw new TypeError("Private accessor was defined without a getter");
|
|
1343
1343
|
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");
|
|
1344
1344
|
return kind === "m" ? f : kind === "a" ? f.call(receiver) : f ? f.value : state.get(receiver);
|
|
@@ -1352,15 +1352,15 @@ class IDBCache {
|
|
|
1352
1352
|
_IDBCache_storeName.set(this, void 0);
|
|
1353
1353
|
_IDBCache_dbPromise.set(this, null);
|
|
1354
1354
|
_IDBCache_version.set(this, 1);
|
|
1355
|
-
__classPrivateFieldSet$
|
|
1356
|
-
__classPrivateFieldSet$
|
|
1355
|
+
__classPrivateFieldSet$f(this, _IDBCache_dbName, dbName, "f");
|
|
1356
|
+
__classPrivateFieldSet$f(this, _IDBCache_storeName, storeName, "f");
|
|
1357
1357
|
}
|
|
1358
1358
|
async get(key) {
|
|
1359
1359
|
try {
|
|
1360
|
-
const db = await __classPrivateFieldGet$
|
|
1360
|
+
const db = await __classPrivateFieldGet$f(this, _IDBCache_instances, "m", _IDBCache_open).call(this);
|
|
1361
1361
|
return new Promise((resolve) => {
|
|
1362
|
-
const tx = db.transaction(__classPrivateFieldGet$
|
|
1363
|
-
const store = tx.objectStore(__classPrivateFieldGet$
|
|
1362
|
+
const tx = db.transaction(__classPrivateFieldGet$f(this, _IDBCache_storeName, "f"), 'readonly');
|
|
1363
|
+
const store = tx.objectStore(__classPrivateFieldGet$f(this, _IDBCache_storeName, "f"));
|
|
1364
1364
|
const req = store.get(key);
|
|
1365
1365
|
req.onsuccess = () => resolve(req.result ?? undefined);
|
|
1366
1366
|
req.onerror = () => resolve(undefined);
|
|
@@ -1372,10 +1372,10 @@ class IDBCache {
|
|
|
1372
1372
|
}
|
|
1373
1373
|
async put(key, value) {
|
|
1374
1374
|
try {
|
|
1375
|
-
const db = await __classPrivateFieldGet$
|
|
1375
|
+
const db = await __classPrivateFieldGet$f(this, _IDBCache_instances, "m", _IDBCache_open).call(this);
|
|
1376
1376
|
return new Promise((resolve) => {
|
|
1377
|
-
const tx = db.transaction(__classPrivateFieldGet$
|
|
1378
|
-
const store = tx.objectStore(__classPrivateFieldGet$
|
|
1377
|
+
const tx = db.transaction(__classPrivateFieldGet$f(this, _IDBCache_storeName, "f"), 'readwrite');
|
|
1378
|
+
const store = tx.objectStore(__classPrivateFieldGet$f(this, _IDBCache_storeName, "f"));
|
|
1379
1379
|
store.put(value, key);
|
|
1380
1380
|
tx.oncomplete = () => resolve();
|
|
1381
1381
|
tx.onerror = () => resolve(); // fire-and-forget
|
|
@@ -1387,10 +1387,10 @@ class IDBCache {
|
|
|
1387
1387
|
}
|
|
1388
1388
|
async delete(key) {
|
|
1389
1389
|
try {
|
|
1390
|
-
const db = await __classPrivateFieldGet$
|
|
1390
|
+
const db = await __classPrivateFieldGet$f(this, _IDBCache_instances, "m", _IDBCache_open).call(this);
|
|
1391
1391
|
return new Promise((resolve) => {
|
|
1392
|
-
const tx = db.transaction(__classPrivateFieldGet$
|
|
1393
|
-
const store = tx.objectStore(__classPrivateFieldGet$
|
|
1392
|
+
const tx = db.transaction(__classPrivateFieldGet$f(this, _IDBCache_storeName, "f"), 'readwrite');
|
|
1393
|
+
const store = tx.objectStore(__classPrivateFieldGet$f(this, _IDBCache_storeName, "f"));
|
|
1394
1394
|
store.delete(key);
|
|
1395
1395
|
tx.oncomplete = () => resolve();
|
|
1396
1396
|
tx.onerror = () => resolve();
|
|
@@ -1402,10 +1402,10 @@ class IDBCache {
|
|
|
1402
1402
|
}
|
|
1403
1403
|
async clear() {
|
|
1404
1404
|
try {
|
|
1405
|
-
const db = await __classPrivateFieldGet$
|
|
1405
|
+
const db = await __classPrivateFieldGet$f(this, _IDBCache_instances, "m", _IDBCache_open).call(this);
|
|
1406
1406
|
return new Promise((resolve) => {
|
|
1407
|
-
const tx = db.transaction(__classPrivateFieldGet$
|
|
1408
|
-
const store = tx.objectStore(__classPrivateFieldGet$
|
|
1407
|
+
const tx = db.transaction(__classPrivateFieldGet$f(this, _IDBCache_storeName, "f"), 'readwrite');
|
|
1408
|
+
const store = tx.objectStore(__classPrivateFieldGet$f(this, _IDBCache_storeName, "f"));
|
|
1409
1409
|
store.clear();
|
|
1410
1410
|
tx.oncomplete = () => resolve();
|
|
1411
1411
|
tx.onerror = () => resolve();
|
|
@@ -1417,10 +1417,10 @@ class IDBCache {
|
|
|
1417
1417
|
}
|
|
1418
1418
|
}
|
|
1419
1419
|
_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() {
|
|
1420
|
-
if (!__classPrivateFieldGet$
|
|
1421
|
-
__classPrivateFieldSet$
|
|
1422
|
-
const storeName = __classPrivateFieldGet$
|
|
1423
|
-
const req = indexedDB.open(__classPrivateFieldGet$
|
|
1420
|
+
if (!__classPrivateFieldGet$f(this, _IDBCache_dbPromise, "f")) {
|
|
1421
|
+
__classPrivateFieldSet$f(this, _IDBCache_dbPromise, new Promise((resolve, reject) => {
|
|
1422
|
+
const storeName = __classPrivateFieldGet$f(this, _IDBCache_storeName, "f");
|
|
1423
|
+
const req = indexedDB.open(__classPrivateFieldGet$f(this, _IDBCache_dbName, "f"), __classPrivateFieldGet$f(this, _IDBCache_version, "f"));
|
|
1424
1424
|
req.onupgradeneeded = () => {
|
|
1425
1425
|
const db = req.result;
|
|
1426
1426
|
if (!db.objectStoreNames.contains(storeName)) {
|
|
@@ -1431,7 +1431,7 @@ _IDBCache_dbName = new WeakMap(), _IDBCache_storeName = new WeakMap(), _IDBCache
|
|
|
1431
1431
|
req.onerror = () => reject(req.error);
|
|
1432
1432
|
}), "f");
|
|
1433
1433
|
}
|
|
1434
|
-
return __classPrivateFieldGet$
|
|
1434
|
+
return __classPrivateFieldGet$f(this, _IDBCache_dbPromise, "f");
|
|
1435
1435
|
};
|
|
1436
1436
|
// ── NullCache (no-op fallback for Node.js) ───────────────────────────
|
|
1437
1437
|
class NullCache {
|
|
@@ -1459,6 +1459,149 @@ function createPersistentCache(dbName, storeName) {
|
|
|
1459
1459
|
return new NullCache();
|
|
1460
1460
|
}
|
|
1461
1461
|
|
|
1462
|
+
var __classPrivateFieldSet$e = (undefined && undefined.__classPrivateFieldSet) || function (receiver, state, value, kind, f) {
|
|
1463
|
+
if (kind === "m") throw new TypeError("Private method is not writable");
|
|
1464
|
+
if (kind === "a" && !f) throw new TypeError("Private accessor was defined without a setter");
|
|
1465
|
+
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");
|
|
1466
|
+
return (kind === "a" ? f.call(receiver, value) : f ? f.value = value : state.set(receiver, value)), value;
|
|
1467
|
+
};
|
|
1468
|
+
var __classPrivateFieldGet$e = (undefined && undefined.__classPrivateFieldGet) || function (receiver, state, kind, f) {
|
|
1469
|
+
if (kind === "a" && !f) throw new TypeError("Private accessor was defined without a getter");
|
|
1470
|
+
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");
|
|
1471
|
+
return kind === "m" ? f : kind === "a" ? f.call(receiver) : f ? f.value : state.get(receiver);
|
|
1472
|
+
};
|
|
1473
|
+
var _KeyedCache_instances, _KeyedCache_opts, _KeyedCache_values, _KeyedCache_bytes, _KeyedCache_pending, _KeyedCache_batch, _KeyedCache_read, _KeyedCache_enqueue, _KeyedCache_loadOne, _KeyedCache_loadBatch, _KeyedCache_stored, _KeyedCache_remember, _KeyedCache_forget;
|
|
1474
|
+
/**
|
|
1475
|
+
* Keyed read cache shared by profile and expression lookups. Concurrent reads
|
|
1476
|
+
* of one key share one request; misses of one tick go out in one `loadMany`
|
|
1477
|
+
* call, except a `get()` miss when the options have `load`. A `null` (not
|
|
1478
|
+
* found) is returned but not kept.
|
|
1479
|
+
*/
|
|
1480
|
+
class KeyedCache {
|
|
1481
|
+
constructor(opts) {
|
|
1482
|
+
_KeyedCache_instances.add(this);
|
|
1483
|
+
_KeyedCache_opts.set(this, void 0);
|
|
1484
|
+
_KeyedCache_values.set(this, new Map());
|
|
1485
|
+
_KeyedCache_bytes.set(this, 0);
|
|
1486
|
+
_KeyedCache_pending.set(this, new Map());
|
|
1487
|
+
_KeyedCache_batch.set(this, null);
|
|
1488
|
+
__classPrivateFieldSet$e(this, _KeyedCache_opts, opts, "f");
|
|
1489
|
+
}
|
|
1490
|
+
get(key) {
|
|
1491
|
+
const load = __classPrivateFieldGet$e(this, _KeyedCache_opts, "f").load;
|
|
1492
|
+
return __classPrivateFieldGet$e(this, _KeyedCache_instances, "m", _KeyedCache_read).call(this, key, load ? k => __classPrivateFieldGet$e(this, _KeyedCache_instances, "m", _KeyedCache_loadOne).call(this, k, load) : k => __classPrivateFieldGet$e(this, _KeyedCache_instances, "m", _KeyedCache_enqueue).call(this, k));
|
|
1493
|
+
}
|
|
1494
|
+
getMany(keys) {
|
|
1495
|
+
return Promise.all(keys.map(key => __classPrivateFieldGet$e(this, _KeyedCache_instances, "m", _KeyedCache_read).call(this, key, k => __classPrivateFieldGet$e(this, _KeyedCache_instances, "m", _KeyedCache_enqueue).call(this, k))));
|
|
1496
|
+
}
|
|
1497
|
+
/** Stores a value known to be current; a read in flight for the key is not kept. */
|
|
1498
|
+
set(key, value) {
|
|
1499
|
+
__classPrivateFieldGet$e(this, _KeyedCache_pending, "f").delete(key);
|
|
1500
|
+
__classPrivateFieldGet$e(this, _KeyedCache_instances, "m", _KeyedCache_remember).call(this, key, value, true);
|
|
1501
|
+
}
|
|
1502
|
+
/** Forgets a key in memory and in the persistent store. */
|
|
1503
|
+
delete(key) {
|
|
1504
|
+
__classPrivateFieldGet$e(this, _KeyedCache_pending, "f").delete(key);
|
|
1505
|
+
__classPrivateFieldGet$e(this, _KeyedCache_instances, "m", _KeyedCache_forget).call(this, key);
|
|
1506
|
+
__classPrivateFieldGet$e(this, _KeyedCache_opts, "f").persistent?.delete(key); // fire-and-forget
|
|
1507
|
+
}
|
|
1508
|
+
/** Forgets every key in memory, and in the persistent store when `persistent` is set. */
|
|
1509
|
+
clear(persistent = false) {
|
|
1510
|
+
__classPrivateFieldGet$e(this, _KeyedCache_pending, "f").clear();
|
|
1511
|
+
__classPrivateFieldGet$e(this, _KeyedCache_values, "f").clear();
|
|
1512
|
+
__classPrivateFieldSet$e(this, _KeyedCache_bytes, 0, "f");
|
|
1513
|
+
if (persistent)
|
|
1514
|
+
__classPrivateFieldGet$e(this, _KeyedCache_opts, "f").persistent?.clear(); // fire-and-forget
|
|
1515
|
+
}
|
|
1516
|
+
}
|
|
1517
|
+
_KeyedCache_opts = new WeakMap(), _KeyedCache_values = new WeakMap(), _KeyedCache_bytes = new WeakMap(), _KeyedCache_pending = new WeakMap(), _KeyedCache_batch = new WeakMap(), _KeyedCache_instances = new WeakSet(), _KeyedCache_read = function _KeyedCache_read(key, fetch) {
|
|
1518
|
+
const hit = __classPrivateFieldGet$e(this, _KeyedCache_values, "f").get(key);
|
|
1519
|
+
if (hit && Date.now() - hit.ts < (__classPrivateFieldGet$e(this, _KeyedCache_opts, "f").maxAgeMs?.(key) ?? Infinity))
|
|
1520
|
+
return Promise.resolve(hit.value);
|
|
1521
|
+
const inFlight = __classPrivateFieldGet$e(this, _KeyedCache_pending, "f").get(key);
|
|
1522
|
+
if (inFlight)
|
|
1523
|
+
return inFlight;
|
|
1524
|
+
const loading = fetch(key);
|
|
1525
|
+
const promise = loading.then(({ value, stored }) => {
|
|
1526
|
+
// A set(), delete() or clear() since the read started wins over its result.
|
|
1527
|
+
if (__classPrivateFieldGet$e(this, _KeyedCache_pending, "f").get(key) === promise) {
|
|
1528
|
+
__classPrivateFieldGet$e(this, _KeyedCache_pending, "f").delete(key);
|
|
1529
|
+
if (value !== null)
|
|
1530
|
+
__classPrivateFieldGet$e(this, _KeyedCache_instances, "m", _KeyedCache_remember).call(this, key, value, !stored);
|
|
1531
|
+
}
|
|
1532
|
+
return value;
|
|
1533
|
+
}, (error) => {
|
|
1534
|
+
if (__classPrivateFieldGet$e(this, _KeyedCache_pending, "f").get(key) === promise)
|
|
1535
|
+
__classPrivateFieldGet$e(this, _KeyedCache_pending, "f").delete(key);
|
|
1536
|
+
throw error;
|
|
1537
|
+
});
|
|
1538
|
+
__classPrivateFieldGet$e(this, _KeyedCache_pending, "f").set(key, promise);
|
|
1539
|
+
return promise;
|
|
1540
|
+
}, _KeyedCache_enqueue = function _KeyedCache_enqueue(key) {
|
|
1541
|
+
if (!__classPrivateFieldGet$e(this, _KeyedCache_batch, "f")) {
|
|
1542
|
+
const keys = [];
|
|
1543
|
+
const done = Promise.resolve().then(() => {
|
|
1544
|
+
__classPrivateFieldSet$e(this, _KeyedCache_batch, null, "f");
|
|
1545
|
+
return __classPrivateFieldGet$e(this, _KeyedCache_instances, "m", _KeyedCache_loadBatch).call(this, keys);
|
|
1546
|
+
});
|
|
1547
|
+
__classPrivateFieldSet$e(this, _KeyedCache_batch, { keys, done }, "f");
|
|
1548
|
+
}
|
|
1549
|
+
__classPrivateFieldGet$e(this, _KeyedCache_batch, "f").keys.push(key);
|
|
1550
|
+
return __classPrivateFieldGet$e(this, _KeyedCache_batch, "f").done.then(loaded => {
|
|
1551
|
+
const entry = loaded.get(key);
|
|
1552
|
+
if (entry.value instanceof Error)
|
|
1553
|
+
throw entry.value;
|
|
1554
|
+
return entry;
|
|
1555
|
+
});
|
|
1556
|
+
}, _KeyedCache_loadOne = async function _KeyedCache_loadOne(key, load) {
|
|
1557
|
+
return (await __classPrivateFieldGet$e(this, _KeyedCache_instances, "m", _KeyedCache_stored).call(this, key)) ?? { value: await load(key), stored: false };
|
|
1558
|
+
}, _KeyedCache_loadBatch = async function _KeyedCache_loadBatch(keys) {
|
|
1559
|
+
const loaded = new Map();
|
|
1560
|
+
const stored = await Promise.all(keys.map(key => __classPrivateFieldGet$e(this, _KeyedCache_instances, "m", _KeyedCache_stored).call(this, key)));
|
|
1561
|
+
const misses = keys.filter((key, i) => {
|
|
1562
|
+
if (stored[i])
|
|
1563
|
+
loaded.set(key, stored[i]);
|
|
1564
|
+
return !stored[i];
|
|
1565
|
+
});
|
|
1566
|
+
const size = __classPrivateFieldGet$e(this, _KeyedCache_opts, "f").maxBatch ?? Infinity;
|
|
1567
|
+
const chunks = [];
|
|
1568
|
+
for (let i = 0; i < misses.length; i += size)
|
|
1569
|
+
chunks.push(misses.slice(i, i + size));
|
|
1570
|
+
await Promise.all(chunks.map(async (chunk) => {
|
|
1571
|
+
const values = await __classPrivateFieldGet$e(this, _KeyedCache_opts, "f").loadMany(chunk);
|
|
1572
|
+
chunk.forEach((key, i) => loaded.set(key, { value: values[i] ?? null, stored: false }));
|
|
1573
|
+
}));
|
|
1574
|
+
return loaded;
|
|
1575
|
+
}, _KeyedCache_stored = async function _KeyedCache_stored(key) {
|
|
1576
|
+
const entry = await __classPrivateFieldGet$e(this, _KeyedCache_opts, "f").persistent?.get(key);
|
|
1577
|
+
// An entry without `value` was written in an older format: a miss.
|
|
1578
|
+
if (entry?.value == null || !(Date.now() - (entry.ts ?? 0) < (__classPrivateFieldGet$e(this, _KeyedCache_opts, "f").persistentMaxAgeMs?.() ?? Infinity)))
|
|
1579
|
+
return null;
|
|
1580
|
+
return { value: entry.value, stored: true };
|
|
1581
|
+
}, _KeyedCache_remember = function _KeyedCache_remember(key, value, persist) {
|
|
1582
|
+
const limits = __classPrivateFieldGet$e(this, _KeyedCache_opts, "f").limits?.();
|
|
1583
|
+
const size = limits ? JSON.stringify(value).length : 0;
|
|
1584
|
+
__classPrivateFieldGet$e(this, _KeyedCache_instances, "m", _KeyedCache_forget).call(this, key);
|
|
1585
|
+
if (limits) {
|
|
1586
|
+
for (const oldest of __classPrivateFieldGet$e(this, _KeyedCache_values, "f").keys()) {
|
|
1587
|
+
if (__classPrivateFieldGet$e(this, _KeyedCache_values, "f").size < limits.entries && __classPrivateFieldGet$e(this, _KeyedCache_bytes, "f") + size <= limits.bytes)
|
|
1588
|
+
break;
|
|
1589
|
+
__classPrivateFieldGet$e(this, _KeyedCache_instances, "m", _KeyedCache_forget).call(this, oldest);
|
|
1590
|
+
}
|
|
1591
|
+
}
|
|
1592
|
+
const ts = Date.now();
|
|
1593
|
+
__classPrivateFieldGet$e(this, _KeyedCache_values, "f").set(key, { value, ts, size });
|
|
1594
|
+
__classPrivateFieldSet$e(this, _KeyedCache_bytes, __classPrivateFieldGet$e(this, _KeyedCache_bytes, "f") + size, "f");
|
|
1595
|
+
if (persist)
|
|
1596
|
+
__classPrivateFieldGet$e(this, _KeyedCache_opts, "f").persistent?.put(key, { value, ts }); // fire-and-forget
|
|
1597
|
+
}, _KeyedCache_forget = function _KeyedCache_forget(key) {
|
|
1598
|
+
const entry = __classPrivateFieldGet$e(this, _KeyedCache_values, "f").get(key);
|
|
1599
|
+
if (!entry)
|
|
1600
|
+
return;
|
|
1601
|
+
__classPrivateFieldSet$e(this, _KeyedCache_bytes, __classPrivateFieldGet$e(this, _KeyedCache_bytes, "f") - entry.size, "f");
|
|
1602
|
+
__classPrivateFieldGet$e(this, _KeyedCache_values, "f").delete(key);
|
|
1603
|
+
};
|
|
1604
|
+
|
|
1462
1605
|
var __classPrivateFieldSet$d = (undefined && undefined.__classPrivateFieldSet) || function (receiver, state, value, kind, f) {
|
|
1463
1606
|
if (kind === "m") throw new TypeError("Private method is not writable");
|
|
1464
1607
|
if (kind === "a" && !f) throw new TypeError("Private accessor was defined without a setter");
|
|
@@ -1470,36 +1613,32 @@ var __classPrivateFieldGet$d = (undefined && undefined.__classPrivateFieldGet) |
|
|
|
1470
1613
|
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");
|
|
1471
1614
|
return kind === "m" ? f : kind === "a" ? f.call(receiver) : f ? f.value : state.get(receiver);
|
|
1472
1615
|
};
|
|
1473
|
-
var _AgentClient_instances, _AgentClient_apiClient,
|
|
1616
|
+
var _AgentClient_instances, _AgentClient_apiClient, _AgentClient_agents, _AgentClient_loadAgents, _AgentClient_cacheAgent, _AgentClient_signLinks, _AgentClient_listen, _AgentClient_onAgentUpdated;
|
|
1474
1617
|
function toAgent(data) {
|
|
1475
1618
|
return data ? Agent.fromWire(data) : null;
|
|
1476
1619
|
}
|
|
1620
|
+
/** Most DIDs the executor takes in one `agent.byDIDs` call. */
|
|
1621
|
+
const MAX_DIDS_PER_CALL = 200;
|
|
1477
1622
|
class AgentClient {
|
|
1478
1623
|
constructor(baseUrl, token, sharedApiClient) {
|
|
1479
1624
|
_AgentClient_instances.add(this);
|
|
1480
1625
|
_AgentClient_apiClient.set(this, void 0);
|
|
1481
|
-
//
|
|
1482
|
-
|
|
1483
|
-
_AgentClient_memCache.set(this, new Map());
|
|
1484
|
-
// L2: persistent cache (IndexedDB in browser, NullCache in Node)
|
|
1485
|
-
// Entries are wrapped with a timestamp so the TTL can be enforced across restarts.
|
|
1486
|
-
_AgentClient_persistent.set(this, void 0);
|
|
1487
|
-
// Self-DID for event-driven invalidation (no TTL for own profile)
|
|
1488
|
-
_AgentClient_selfDid.set(this, null);
|
|
1626
|
+
// byDID cache: concurrent misses go out in one `agent.byDIDs` call.
|
|
1627
|
+
_AgentClient_agents.set(this, void 0);
|
|
1489
1628
|
_AgentClient_onAgentUpdated.set(this, (event) => {
|
|
1490
1629
|
__classPrivateFieldGet$d(this, _AgentClient_instances, "m", _AgentClient_cacheAgent).call(this, Agent.fromWire(event.agent));
|
|
1491
1630
|
});
|
|
1492
1631
|
__classPrivateFieldSet$d(this, _AgentClient_apiClient, sharedApiClient || new ApiClient(baseUrl, token), "f");
|
|
1493
|
-
__classPrivateFieldSet$d(this,
|
|
1632
|
+
__classPrivateFieldSet$d(this, _AgentClient_agents, new KeyedCache({
|
|
1633
|
+
loadMany: (dids) => __classPrivateFieldGet$d(this, _AgentClient_instances, "m", _AgentClient_loadAgents).call(this, dids),
|
|
1634
|
+
maxBatch: MAX_DIDS_PER_CALL,
|
|
1635
|
+
persistent: createPersistentCache('ad4m-agent-cache', 'agents'),
|
|
1636
|
+
maxAgeMs: () => AgentClient.REMOTE_AGENT_TTL_MS,
|
|
1637
|
+
persistentMaxAgeMs: () => AgentClient.REMOTE_AGENT_TTL_MS,
|
|
1638
|
+
}), "f");
|
|
1494
1639
|
}
|
|
1495
1640
|
async me() {
|
|
1496
|
-
|
|
1497
|
-
// Auto-set selfDid so event-driven cache invalidation works
|
|
1498
|
-
// without requiring apps to call setSelfDid() manually
|
|
1499
|
-
if (agentObject.did && !__classPrivateFieldGet$d(this, _AgentClient_selfDid, "f")) {
|
|
1500
|
-
__classPrivateFieldSet$d(this, _AgentClient_selfDid, agentObject.did, "f");
|
|
1501
|
-
}
|
|
1502
|
-
return agentObject;
|
|
1641
|
+
return toAgent(await __classPrivateFieldGet$d(this, _AgentClient_apiClient, "f").call('agent.get', {}));
|
|
1503
1642
|
}
|
|
1504
1643
|
async status() {
|
|
1505
1644
|
const agentStatus = await __classPrivateFieldGet$d(this, _AgentClient_apiClient, "f").call('agent.status', {});
|
|
@@ -1524,61 +1663,27 @@ class AgentClient {
|
|
|
1524
1663
|
const result = await __classPrivateFieldGet$d(this, _AgentClient_apiClient, "f").call('agent.unlock', { passphrase, holochain }, options);
|
|
1525
1664
|
return new AgentStatus(result);
|
|
1526
1665
|
}
|
|
1527
|
-
async byDID(did) {
|
|
1528
|
-
// agent-updated events keep cached entries fresh (the self-DID entry has no TTL).
|
|
1529
|
-
__classPrivateFieldGet$d(this, _AgentClient_instances, "m", _AgentClient_listen).call(this);
|
|
1530
|
-
const now = Date.now();
|
|
1531
|
-
const cached = __classPrivateFieldGet$d(this, _AgentClient_memCache, "f").get(did);
|
|
1532
|
-
if (cached) {
|
|
1533
|
-
const isSelf = did === __classPrivateFieldGet$d(this, _AgentClient_selfDid, "f");
|
|
1534
|
-
// Self-DID: L1 always valid (event-driven invalidation)
|
|
1535
|
-
// Remote DID: L1 valid within TTL
|
|
1536
|
-
if (isSelf || (now - cached.ts) < AgentClient.REMOTE_AGENT_TTL_MS) {
|
|
1537
|
-
return cached.promise;
|
|
1538
|
-
}
|
|
1539
|
-
}
|
|
1540
|
-
// Deduplicate: store the promise immediately so concurrent calls share one RPC
|
|
1541
|
-
const promise = (async () => {
|
|
1542
|
-
// L2: check persistent cache before network
|
|
1543
|
-
const entry = await __classPrivateFieldGet$d(this, _AgentClient_persistent, "f").get(did);
|
|
1544
|
-
// entry.agent may be undefined for pre-TTL cache entries (migration) — treat as expired
|
|
1545
|
-
if (entry?.agent && (now - (entry.ts ?? 0)) < AgentClient.REMOTE_AGENT_TTL_L2_MS) {
|
|
1546
|
-
return entry.agent;
|
|
1547
|
-
}
|
|
1548
|
-
// L3: network fetch
|
|
1549
|
-
const result = toAgent(await __classPrivateFieldGet$d(this, _AgentClient_apiClient, "f").call('agent.byDid', { did }));
|
|
1550
|
-
__classPrivateFieldGet$d(this, _AgentClient_persistent, "f").put(did, { agent: result, ts: Date.now() }); // fire-and-forget write to L2
|
|
1551
|
-
return result;
|
|
1552
|
-
})();
|
|
1553
|
-
__classPrivateFieldGet$d(this, _AgentClient_memCache, "f").set(did, { promise, ts: now });
|
|
1554
|
-
// Clean up on failure so next call retries
|
|
1555
|
-
promise.catch(() => {
|
|
1556
|
-
if (__classPrivateFieldGet$d(this, _AgentClient_memCache, "f").get(did)?.promise === promise) {
|
|
1557
|
-
__classPrivateFieldGet$d(this, _AgentClient_memCache, "f").delete(did);
|
|
1558
|
-
}
|
|
1559
|
-
});
|
|
1560
|
-
return promise;
|
|
1561
|
-
}
|
|
1562
1666
|
/**
|
|
1563
|
-
*
|
|
1564
|
-
*
|
|
1667
|
+
* The agent with this DID, or `null` when it is unknown. Concurrent calls
|
|
1668
|
+
* for any DIDs share one `agent.byDIDs` request.
|
|
1565
1669
|
*/
|
|
1566
|
-
|
|
1567
|
-
|
|
1670
|
+
async byDID(did) {
|
|
1671
|
+
// agent-updated events refresh cached entries before their TTL runs out.
|
|
1672
|
+
__classPrivateFieldGet$d(this, _AgentClient_instances, "m", _AgentClient_listen).call(this);
|
|
1673
|
+
return __classPrivateFieldGet$d(this, _AgentClient_agents, "f").get(did);
|
|
1568
1674
|
}
|
|
1569
1675
|
/**
|
|
1570
1676
|
* Invalidate a specific DID's cache entry in both L1 and L2.
|
|
1571
1677
|
*/
|
|
1572
1678
|
invalidateByDid(did) {
|
|
1573
|
-
__classPrivateFieldGet$d(this,
|
|
1574
|
-
__classPrivateFieldGet$d(this, _AgentClient_persistent, "f").delete(did); // fire-and-forget
|
|
1679
|
+
__classPrivateFieldGet$d(this, _AgentClient_agents, "f").delete(did);
|
|
1575
1680
|
}
|
|
1576
1681
|
/**
|
|
1577
1682
|
* Clear the entire L1 (memory) byDID cache.
|
|
1578
1683
|
* L2 (IndexedDB) is preserved — agent data remains valid across sessions.
|
|
1579
1684
|
*/
|
|
1580
1685
|
clearByDidCache() {
|
|
1581
|
-
__classPrivateFieldGet$d(this,
|
|
1686
|
+
__classPrivateFieldGet$d(this, _AgentClient_agents, "f").clear();
|
|
1582
1687
|
}
|
|
1583
1688
|
async updatePublicPerspective(perspective) {
|
|
1584
1689
|
// Send only the signed fields: the public perspective carries no link status.
|
|
@@ -1710,11 +1815,25 @@ class AgentClient {
|
|
|
1710
1815
|
return __classPrivateFieldGet$d(this, _AgentClient_apiClient, "f").call('hosting.requestPayment', { amountHOT });
|
|
1711
1816
|
}
|
|
1712
1817
|
}
|
|
1713
|
-
_AgentClient_apiClient = new WeakMap(),
|
|
1818
|
+
_AgentClient_apiClient = new WeakMap(), _AgentClient_agents = new WeakMap(), _AgentClient_onAgentUpdated = new WeakMap(), _AgentClient_instances = new WeakSet(), _AgentClient_loadAgents =
|
|
1819
|
+
/**
|
|
1820
|
+
* One `agent.byDIDs` call for the misses of one tick. The executor fails
|
|
1821
|
+
* that call when one DID's lookup fails (500), so the DIDs of a failed
|
|
1822
|
+
* batch are then read alone: each caller gets what a lone `byDID` gives.
|
|
1823
|
+
*/
|
|
1824
|
+
async function _AgentClient_loadAgents(dids) {
|
|
1825
|
+
try {
|
|
1826
|
+
return (await __classPrivateFieldGet$d(this, _AgentClient_apiClient, "f").call('agent.byDIDs', { dids })).map(toAgent);
|
|
1827
|
+
}
|
|
1828
|
+
catch (error) {
|
|
1829
|
+
if (dids.length === 1 || !(error instanceof RpcError) || error.status !== 500)
|
|
1830
|
+
throw error;
|
|
1831
|
+
return Promise.all(dids.map(did => __classPrivateFieldGet$d(this, _AgentClient_apiClient, "f").call('agent.byDid', { did }).then(toAgent, (failure) => failure instanceof Error ? failure : new Error(String(failure)))));
|
|
1832
|
+
}
|
|
1833
|
+
}, _AgentClient_cacheAgent = function _AgentClient_cacheAgent(agent) {
|
|
1714
1834
|
if (!agent.did)
|
|
1715
1835
|
return;
|
|
1716
|
-
__classPrivateFieldGet$d(this,
|
|
1717
|
-
__classPrivateFieldGet$d(this, _AgentClient_persistent, "f").put(agent.did, { agent, ts: Date.now() }); // fire-and-forget
|
|
1836
|
+
__classPrivateFieldGet$d(this, _AgentClient_agents, "f").set(agent.did, agent);
|
|
1718
1837
|
__classPrivateFieldGet$d(this, _AgentClient_instances, "m", _AgentClient_listen).call(this);
|
|
1719
1838
|
}, _AgentClient_signLinks =
|
|
1720
1839
|
/** Has the executor sign `links` as this agent, in a throwaway perspective. */
|
|
@@ -1729,11 +1848,13 @@ async function _AgentClient_signLinks(links) {
|
|
|
1729
1848
|
}, _AgentClient_listen = function _AgentClient_listen() {
|
|
1730
1849
|
__classPrivateFieldGet$d(this, _AgentClient_apiClient, "f").on('agent-updated', __classPrivateFieldGet$d(this, _AgentClient_onAgentUpdated, "f"));
|
|
1731
1850
|
};
|
|
1732
|
-
/**
|
|
1851
|
+
/**
|
|
1852
|
+
* TTL of every cached profile, the own one too, in memory and in the
|
|
1853
|
+
* persistent cache (ms). `agent-updated` only comes from this executor, so
|
|
1854
|
+
* a profile changed through another executor of the same agent shows up
|
|
1855
|
+
* when the entry expires.
|
|
1856
|
+
*/
|
|
1733
1857
|
AgentClient.REMOTE_AGENT_TTL_MS = 5 * 60000; // 5 minutes
|
|
1734
|
-
/** TTL for remote agent profiles in the L2 (IndexedDB) cache (ms).
|
|
1735
|
-
* After this window any restart triggers a fresh network fetch. */
|
|
1736
|
-
AgentClient.REMOTE_AGENT_TTL_L2_MS = 5 * 60000; // 5 minutes
|
|
1737
1858
|
|
|
1738
1859
|
var __classPrivateFieldSet$c = (undefined && undefined.__classPrivateFieldSet) || function (receiver, state, value, kind, f) {
|
|
1739
1860
|
if (kind === "m") throw new TypeError("Private method is not writable");
|
|
@@ -7643,73 +7764,6 @@ function BelongsToMany(first, second) {
|
|
|
7643
7764
|
};
|
|
7644
7765
|
}
|
|
7645
7766
|
|
|
7646
|
-
/**
|
|
7647
|
-
* Query Result TTL Cache
|
|
7648
|
-
*
|
|
7649
|
-
* Short-lived cache (200ms TTL) for SPARQL query results.
|
|
7650
|
-
* Prevents redundant queries during rapid render cycles where
|
|
7651
|
-
* multiple components issue the same query within milliseconds.
|
|
7652
|
-
*
|
|
7653
|
-
* Key: `perspectiveUUID + queryText`
|
|
7654
|
-
*/
|
|
7655
|
-
const cache = new Map();
|
|
7656
|
-
const DEFAULT_TTL_MS = 200;
|
|
7657
|
-
function makeKey(perspectiveUUID, queryText) {
|
|
7658
|
-
return `${perspectiveUUID}:${queryText}`;
|
|
7659
|
-
}
|
|
7660
|
-
/**
|
|
7661
|
-
* Get a cached query result if it exists and hasn't expired.
|
|
7662
|
-
*/
|
|
7663
|
-
function getCachedResult(perspectiveUUID, queryText) {
|
|
7664
|
-
const key = makeKey(perspectiveUUID, queryText);
|
|
7665
|
-
const entry = cache.get(key);
|
|
7666
|
-
if (!entry)
|
|
7667
|
-
return undefined;
|
|
7668
|
-
if (Date.now() > entry.expiry) {
|
|
7669
|
-
cache.delete(key);
|
|
7670
|
-
return undefined;
|
|
7671
|
-
}
|
|
7672
|
-
return entry.result;
|
|
7673
|
-
}
|
|
7674
|
-
/**
|
|
7675
|
-
* Store a query result in the cache with TTL.
|
|
7676
|
-
*/
|
|
7677
|
-
function setCachedResult(perspectiveUUID, queryText, result, ttlMs = DEFAULT_TTL_MS) {
|
|
7678
|
-
// Lazy eviction of expired entries
|
|
7679
|
-
const now = Date.now();
|
|
7680
|
-
for (const [key, entry] of cache) {
|
|
7681
|
-
if (now > entry.expiry) {
|
|
7682
|
-
cache.delete(key);
|
|
7683
|
-
}
|
|
7684
|
-
}
|
|
7685
|
-
const cacheKey = makeKey(perspectiveUUID, queryText);
|
|
7686
|
-
cache.set(cacheKey, { result, expiry: now + ttlMs });
|
|
7687
|
-
}
|
|
7688
|
-
/**
|
|
7689
|
-
* Invalidate all cache entries for a given perspective.
|
|
7690
|
-
* Called after write operations to ensure stale data isn't served.
|
|
7691
|
-
*/
|
|
7692
|
-
function invalidatePerspectiveCache(perspectiveUUID) {
|
|
7693
|
-
const prefix = perspectiveUUID + ':';
|
|
7694
|
-
for (const [key] of cache) {
|
|
7695
|
-
if (key.startsWith(prefix)) {
|
|
7696
|
-
cache.delete(key);
|
|
7697
|
-
}
|
|
7698
|
-
}
|
|
7699
|
-
}
|
|
7700
|
-
/**
|
|
7701
|
-
* Clear all cache entries (useful for testing).
|
|
7702
|
-
*/
|
|
7703
|
-
function clearQueryCache() {
|
|
7704
|
-
cache.clear();
|
|
7705
|
-
}
|
|
7706
|
-
/**
|
|
7707
|
-
* Get the current size of the cache (useful for testing).
|
|
7708
|
-
*/
|
|
7709
|
-
function queryCacheSize() {
|
|
7710
|
-
return cache.size;
|
|
7711
|
-
}
|
|
7712
|
-
|
|
7713
7767
|
var __classPrivateFieldSet$8 = (undefined && undefined.__classPrivateFieldSet) || function (receiver, state, value, kind, f) {
|
|
7714
7768
|
if (kind === "m") throw new TypeError("Private method is not writable");
|
|
7715
7769
|
if (kind === "a" && !f) throw new TypeError("Private accessor was defined without a setter");
|
|
@@ -9085,9 +9139,7 @@ class PerspectiveProxy {
|
|
|
9085
9139
|
* @param batchId - Optional batch ID to group this operation with others
|
|
9086
9140
|
*/
|
|
9087
9141
|
async executeAction(actions, expression, parameters, batchId) {
|
|
9088
|
-
|
|
9089
|
-
invalidatePerspectiveCache(__classPrivateFieldGet$7(this, _PerspectiveProxy_handle, "f").uuid);
|
|
9090
|
-
return result;
|
|
9142
|
+
return __classPrivateFieldGet$7(this, _PerspectiveProxy_client, "f").executeCommands(__classPrivateFieldGet$7(this, _PerspectiveProxy_handle, "f").uuid, JSON.stringify(actions), expression, JSON.stringify(parameters), batchId);
|
|
9091
9143
|
}
|
|
9092
9144
|
/**
|
|
9093
9145
|
* Retrieves links from the perspective that match the given query.
|
|
@@ -9315,12 +9367,15 @@ class PerspectiveProxy {
|
|
|
9315
9367
|
return await __classPrivateFieldGet$7(this, _PerspectiveProxy_client, "f").flowStates(__classPrivateFieldGet$7(this, _PerspectiveProxy_handle, "f").uuid, instances);
|
|
9316
9368
|
}
|
|
9317
9369
|
/**
|
|
9318
|
-
*
|
|
9319
|
-
* agent's executor recorded them — the flow's history,
|
|
9370
|
+
* For each of `instances`, in order, the proposals whose votes settled an
|
|
9371
|
+
* edge, as this agent's executor recorded them — the flow's history,
|
|
9372
|
+
* sorted by URI (`fired: []` when none). One call covers up to 200
|
|
9373
|
+
* instances (the executor refuses more with a 400); split a longer list
|
|
9374
|
+
* into batches of 200.
|
|
9320
9375
|
* Replaces the `resolvedAs` property proposals used to carry.
|
|
9321
9376
|
*/
|
|
9322
|
-
async flowFired(
|
|
9323
|
-
return await __classPrivateFieldGet$7(this, _PerspectiveProxy_client, "f").flowFired(__classPrivateFieldGet$7(this, _PerspectiveProxy_handle, "f").uuid,
|
|
9377
|
+
async flowFired(instances) {
|
|
9378
|
+
return await __classPrivateFieldGet$7(this, _PerspectiveProxy_client, "f").flowFired(__classPrivateFieldGet$7(this, _PerspectiveProxy_handle, "f").uuid, instances);
|
|
9324
9379
|
}
|
|
9325
9380
|
/**
|
|
9326
9381
|
* Called whenever a flow instance on this perspective changes state on
|
|
@@ -9384,20 +9439,18 @@ class PerspectiveProxy {
|
|
|
9384
9439
|
* keep its blocking thread busy until it completes; what's saved is the
|
|
9385
9440
|
* serialise + network + client-deserialise tax on the result. Aborted
|
|
9386
9441
|
* calls reject with `DOMException('Aborted', 'AbortError')` — match
|
|
9387
|
-
* `fetch()` for handling.
|
|
9388
|
-
*
|
|
9442
|
+
* `fetch()` for handling. A call with `options` makes its own RPC.
|
|
9443
|
+
*
|
|
9444
|
+
* **Sharing:** concurrent identical calls without `options` share one RPC;
|
|
9445
|
+
* each caller gets its own result object. Nothing is cached once the
|
|
9446
|
+
* call settles: use a live query for repeated reads of the same data.
|
|
9389
9447
|
*
|
|
9390
9448
|
* @param query - SPARQL query string (read-only operations only)
|
|
9391
9449
|
* @param options - Optional call options (e.g. AbortSignal for cancellation)
|
|
9392
9450
|
* @returns Query results as parsed JSON
|
|
9393
9451
|
*/
|
|
9394
9452
|
async querySparql(query, options) {
|
|
9395
|
-
|
|
9396
|
-
if (cached !== undefined)
|
|
9397
|
-
return cached;
|
|
9398
|
-
const result = await __classPrivateFieldGet$7(this, _PerspectiveProxy_client, "f").querySparql(__classPrivateFieldGet$7(this, _PerspectiveProxy_handle, "f").uuid, query, options);
|
|
9399
|
-
setCachedResult(__classPrivateFieldGet$7(this, _PerspectiveProxy_handle, "f").uuid, query, result);
|
|
9400
|
-
return result;
|
|
9453
|
+
return __classPrivateFieldGet$7(this, _PerspectiveProxy_client, "f").querySparql(__classPrivateFieldGet$7(this, _PerspectiveProxy_handle, "f").uuid, query, options);
|
|
9401
9454
|
}
|
|
9402
9455
|
/**
|
|
9403
9456
|
* Execute a model query — the executor-side replacement for SPARQL query building + JS hydration.
|
|
@@ -9410,7 +9463,7 @@ class PerspectiveProxy {
|
|
|
9410
9463
|
* query over their union, whose rows carry `__subjectClass` and
|
|
9411
9464
|
* `__subjectClasses` (#1238)
|
|
9412
9465
|
* @param queryJson - Structured query as JSON string
|
|
9413
|
-
* @returns Object with `instances` array and `totalCount`
|
|
9466
|
+
* @returns Object with `instances` array, and `totalCount` when the query sets `count: true`
|
|
9414
9467
|
*/
|
|
9415
9468
|
async modelQuery(className, queryJson, options) {
|
|
9416
9469
|
return await __classPrivateFieldGet$7(this, _PerspectiveProxy_client, "f").modelQuery(__classPrivateFieldGet$7(this, _PerspectiveProxy_handle, "f").uuid, className, queryJson, options);
|
|
@@ -9504,9 +9557,7 @@ class PerspectiveProxy {
|
|
|
9504
9557
|
* ```
|
|
9505
9558
|
*/
|
|
9506
9559
|
async add(link, status = 'shared', batchId) {
|
|
9507
|
-
|
|
9508
|
-
invalidatePerspectiveCache(__classPrivateFieldGet$7(this, _PerspectiveProxy_handle, "f").uuid);
|
|
9509
|
-
return result;
|
|
9560
|
+
return __classPrivateFieldGet$7(this, _PerspectiveProxy_client, "f").addLink(__classPrivateFieldGet$7(this, _PerspectiveProxy_handle, "f").uuid, link, status, batchId);
|
|
9510
9561
|
}
|
|
9511
9562
|
/**
|
|
9512
9563
|
* Adds multiple links to the perspective in a single operation.
|
|
@@ -9518,9 +9569,7 @@ class PerspectiveProxy {
|
|
|
9518
9569
|
* @returns Array of created LinkExpressions
|
|
9519
9570
|
*/
|
|
9520
9571
|
async addLinks(links, status = 'shared', batchId) {
|
|
9521
|
-
|
|
9522
|
-
invalidatePerspectiveCache(__classPrivateFieldGet$7(this, _PerspectiveProxy_handle, "f").uuid);
|
|
9523
|
-
return result;
|
|
9572
|
+
return __classPrivateFieldGet$7(this, _PerspectiveProxy_client, "f").addLinks(__classPrivateFieldGet$7(this, _PerspectiveProxy_handle, "f").uuid, links, status, batchId);
|
|
9524
9573
|
}
|
|
9525
9574
|
/**
|
|
9526
9575
|
* Removes multiple links from the perspective.
|
|
@@ -9530,9 +9579,7 @@ class PerspectiveProxy {
|
|
|
9530
9579
|
* @returns Array of removed LinkExpressions
|
|
9531
9580
|
*/
|
|
9532
9581
|
async removeLinks(links, batchId) {
|
|
9533
|
-
|
|
9534
|
-
invalidatePerspectiveCache(__classPrivateFieldGet$7(this, _PerspectiveProxy_handle, "f").uuid);
|
|
9535
|
-
return result;
|
|
9582
|
+
return __classPrivateFieldGet$7(this, _PerspectiveProxy_client, "f").removeLinks(__classPrivateFieldGet$7(this, _PerspectiveProxy_handle, "f").uuid, links, batchId);
|
|
9536
9583
|
}
|
|
9537
9584
|
/**
|
|
9538
9585
|
* Applies a set of link mutations (adds and removes) in a single operation.
|
|
@@ -9543,9 +9590,7 @@ class PerspectiveProxy {
|
|
|
9543
9590
|
* @returns Object containing results of the mutations
|
|
9544
9591
|
*/
|
|
9545
9592
|
async linkMutations(mutations, status = 'shared') {
|
|
9546
|
-
|
|
9547
|
-
invalidatePerspectiveCache(__classPrivateFieldGet$7(this, _PerspectiveProxy_handle, "f").uuid);
|
|
9548
|
-
return result;
|
|
9593
|
+
return __classPrivateFieldGet$7(this, _PerspectiveProxy_client, "f").linkMutations(__classPrivateFieldGet$7(this, _PerspectiveProxy_handle, "f").uuid, mutations, status);
|
|
9549
9594
|
}
|
|
9550
9595
|
/**
|
|
9551
9596
|
* Adds a pre-signed LinkExpression to the perspective.
|
|
@@ -9572,9 +9617,7 @@ class PerspectiveProxy {
|
|
|
9572
9617
|
* @param batchId - Optional batch ID to group this operation with others
|
|
9573
9618
|
*/
|
|
9574
9619
|
async update(oldLink, newLink, batchId) {
|
|
9575
|
-
|
|
9576
|
-
invalidatePerspectiveCache(__classPrivateFieldGet$7(this, _PerspectiveProxy_handle, "f").uuid);
|
|
9577
|
-
return result;
|
|
9620
|
+
return __classPrivateFieldGet$7(this, _PerspectiveProxy_client, "f").updateLink(__classPrivateFieldGet$7(this, _PerspectiveProxy_handle, "f").uuid, oldLink, newLink, batchId);
|
|
9578
9621
|
}
|
|
9579
9622
|
/**
|
|
9580
9623
|
* Removes a link from the perspective.
|
|
@@ -9620,9 +9663,7 @@ class PerspectiveProxy {
|
|
|
9620
9663
|
else {
|
|
9621
9664
|
resolvedLink = link;
|
|
9622
9665
|
}
|
|
9623
|
-
|
|
9624
|
-
invalidatePerspectiveCache(__classPrivateFieldGet$7(this, _PerspectiveProxy_handle, "f").uuid);
|
|
9625
|
-
return result;
|
|
9666
|
+
return __classPrivateFieldGet$7(this, _PerspectiveProxy_client, "f").removeLink(__classPrivateFieldGet$7(this, _PerspectiveProxy_handle, "f").uuid, resolvedLink, batchId);
|
|
9626
9667
|
}
|
|
9627
9668
|
/** Creates a new batch for grouping operations */
|
|
9628
9669
|
async createBatch() {
|
|
@@ -9630,9 +9671,7 @@ class PerspectiveProxy {
|
|
|
9630
9671
|
}
|
|
9631
9672
|
/** Commits a batch of operations */
|
|
9632
9673
|
async commitBatch(batchId) {
|
|
9633
|
-
|
|
9634
|
-
invalidatePerspectiveCache(__classPrivateFieldGet$7(this, _PerspectiveProxy_handle, "f").uuid);
|
|
9635
|
-
return result;
|
|
9674
|
+
return __classPrivateFieldGet$7(this, _PerspectiveProxy_client, "f").commitBatch(__classPrivateFieldGet$7(this, _PerspectiveProxy_handle, "f").uuid, batchId);
|
|
9636
9675
|
}
|
|
9637
9676
|
/**
|
|
9638
9677
|
* Drops an open batch without committing it — the recovery for a failed batched call:
|
|
@@ -10000,13 +10039,13 @@ class PerspectiveProxy {
|
|
|
10000
10039
|
return __classPrivateFieldGet$7(this, _PerspectiveProxy_client, "f").getShaclTargetClass(__classPrivateFieldGet$7(this, _PerspectiveProxy_handle, "f").uuid, name);
|
|
10001
10040
|
}
|
|
10002
10041
|
/**
|
|
10003
|
-
* Get
|
|
10004
|
-
*
|
|
10042
|
+
* Get the SHACL shapes stored in this Perspective in one RPC call: all of
|
|
10043
|
+
* them, or only those named in `names` (unknown names are left out).
|
|
10005
10044
|
* A shape that fails to decode is skipped with a `console.warn`, so it
|
|
10006
10045
|
* does not hide the others.
|
|
10007
10046
|
*/
|
|
10008
|
-
async getAllShacl() {
|
|
10009
|
-
const entries = await __classPrivateFieldGet$7(this, _PerspectiveProxy_client, "f").getAllShacl(__classPrivateFieldGet$7(this, _PerspectiveProxy_handle, "f").uuid);
|
|
10047
|
+
async getAllShacl(options) {
|
|
10048
|
+
const entries = await __classPrivateFieldGet$7(this, _PerspectiveProxy_client, "f").getAllShacl(__classPrivateFieldGet$7(this, _PerspectiveProxy_handle, "f").uuid, options?.names);
|
|
10010
10049
|
const shapes = [];
|
|
10011
10050
|
for (const { name, shapeUri, links } of entries) {
|
|
10012
10051
|
try {
|
|
@@ -10247,7 +10286,6 @@ class PerspectiveProxy {
|
|
|
10247
10286
|
* record that the abstract class reads, under its own name. */
|
|
10248
10287
|
async updateSubject(className, exprAddr, values, batchId) {
|
|
10249
10288
|
await __classPrivateFieldGet$7(this, _PerspectiveProxy_client, "f").updateSubject(__classPrivateFieldGet$7(this, _PerspectiveProxy_handle, "f").uuid, className, exprAddr, JSON.stringify(values), batchId);
|
|
10250
|
-
invalidatePerspectiveCache(__classPrivateFieldGet$7(this, _PerspectiveProxy_handle, "f").uuid);
|
|
10251
10289
|
}
|
|
10252
10290
|
/**
|
|
10253
10291
|
* Creates an instance of a subject class, validated by the executor against the class's
|
|
@@ -10266,42 +10304,23 @@ class PerspectiveProxy {
|
|
|
10266
10304
|
* const { baseUri } = await perspective.instanceCreate({ className: "Task", properties: { title: "Write" } });
|
|
10267
10305
|
*/
|
|
10268
10306
|
async instanceCreate(body) {
|
|
10269
|
-
|
|
10270
|
-
invalidatePerspectiveCache(__classPrivateFieldGet$7(this, _PerspectiveProxy_handle, "f").uuid);
|
|
10271
|
-
return created;
|
|
10307
|
+
return __classPrivateFieldGet$7(this, _PerspectiveProxy_client, "f").instanceCreate(__classPrivateFieldGet$7(this, _PerspectiveProxy_handle, "f").uuid, body);
|
|
10272
10308
|
}
|
|
10273
10309
|
/** Sets single-valued properties of an instance, validated; the others stay. See {@link instanceCreate}. */
|
|
10274
10310
|
async instanceUpdate(body) {
|
|
10275
|
-
|
|
10276
|
-
invalidatePerspectiveCache(__classPrivateFieldGet$7(this, _PerspectiveProxy_handle, "f").uuid);
|
|
10277
|
-
return updated;
|
|
10311
|
+
return __classPrivateFieldGet$7(this, _PerspectiveProxy_client, "f").instanceUpdate(__classPrivateFieldGet$7(this, _PerspectiveProxy_handle, "f").uuid, body);
|
|
10278
10312
|
}
|
|
10279
10313
|
/** Removes an instance and every link to and from it. See {@link instanceCreate}. */
|
|
10280
10314
|
async instanceRemove(body) {
|
|
10281
|
-
|
|
10282
|
-
// come after some are gone: invalidate either way.
|
|
10283
|
-
try {
|
|
10284
|
-
return await __classPrivateFieldGet$7(this, _PerspectiveProxy_client, "f").instanceRemove(__classPrivateFieldGet$7(this, _PerspectiveProxy_handle, "f").uuid, body);
|
|
10285
|
-
}
|
|
10286
|
-
finally {
|
|
10287
|
-
invalidatePerspectiveCache(__classPrivateFieldGet$7(this, _PerspectiveProxy_handle, "f").uuid);
|
|
10288
|
-
}
|
|
10315
|
+
return __classPrivateFieldGet$7(this, _PerspectiveProxy_client, "f").instanceRemove(__classPrivateFieldGet$7(this, _PerspectiveProxy_handle, "f").uuid, body);
|
|
10289
10316
|
}
|
|
10290
10317
|
/** Adds an item to a collection of an instance, validated. See {@link instanceCreate}. */
|
|
10291
10318
|
async instanceAddToCollection(body) {
|
|
10292
|
-
|
|
10293
|
-
invalidatePerspectiveCache(__classPrivateFieldGet$7(this, _PerspectiveProxy_handle, "f").uuid);
|
|
10294
|
-
return added;
|
|
10319
|
+
return __classPrivateFieldGet$7(this, _PerspectiveProxy_client, "f").instanceAddToCollection(__classPrivateFieldGet$7(this, _PerspectiveProxy_handle, "f").uuid, body);
|
|
10295
10320
|
}
|
|
10296
10321
|
/** Removes an item from a collection of an instance. See {@link instanceCreate}. */
|
|
10297
10322
|
async instanceRemoveFromCollection(body) {
|
|
10298
|
-
|
|
10299
|
-
try {
|
|
10300
|
-
return await __classPrivateFieldGet$7(this, _PerspectiveProxy_client, "f").instanceRemoveFromCollection(__classPrivateFieldGet$7(this, _PerspectiveProxy_handle, "f").uuid, body);
|
|
10301
|
-
}
|
|
10302
|
-
finally {
|
|
10303
|
-
invalidatePerspectiveCache(__classPrivateFieldGet$7(this, _PerspectiveProxy_handle, "f").uuid);
|
|
10304
|
-
}
|
|
10323
|
+
return __classPrivateFieldGet$7(this, _PerspectiveProxy_client, "f").instanceRemoveFromCollection(__classPrivateFieldGet$7(this, _PerspectiveProxy_handle, "f").uuid, body);
|
|
10305
10324
|
}
|
|
10306
10325
|
async getSubjectData(subjectClass, exprAddr) {
|
|
10307
10326
|
if (typeof subjectClass === "string") {
|
|
@@ -10365,7 +10384,6 @@ class PerspectiveProxy {
|
|
|
10365
10384
|
const ctor = subjectClass?.constructor;
|
|
10366
10385
|
if (typeof subjectClass === "object" && ctor && Object.prototype.hasOwnProperty.call(ctor, 'builtinUri')) {
|
|
10367
10386
|
await __classPrivateFieldGet$7(this, _PerspectiveProxy_client, "f").removeSubject(__classPrivateFieldGet$7(this, _PerspectiveProxy_handle, "f").uuid, ctor.builtinUri, exprAddr, batchId);
|
|
10368
|
-
invalidatePerspectiveCache(__classPrivateFieldGet$7(this, _PerspectiveProxy_handle, "f").uuid);
|
|
10369
10387
|
return;
|
|
10370
10388
|
}
|
|
10371
10389
|
let className = await this.stringOrTemplateObjectToSubjectClassName(subjectClass);
|
|
@@ -10375,7 +10393,6 @@ class PerspectiveProxy {
|
|
|
10375
10393
|
const markers = await this.get(new LinkQuery({ predicate: "ad4m://abstract" }));
|
|
10376
10394
|
if (markers.some((link) => shapePattern.test(link.data.source))) {
|
|
10377
10395
|
await __classPrivateFieldGet$7(this, _PerspectiveProxy_client, "f").removeSubject(__classPrivateFieldGet$7(this, _PerspectiveProxy_handle, "f").uuid, className, exprAddr, batchId);
|
|
10378
|
-
invalidatePerspectiveCache(__classPrivateFieldGet$7(this, _PerspectiveProxy_handle, "f").uuid);
|
|
10379
10396
|
return;
|
|
10380
10397
|
}
|
|
10381
10398
|
// Get destructor actions from SHACL links (Prolog-free)
|
|
@@ -10944,7 +10961,7 @@ var __classPrivateFieldGet$6 = (undefined && undefined.__classPrivateFieldGet) |
|
|
|
10944
10961
|
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");
|
|
10945
10962
|
return kind === "m" ? f : kind === "a" ? f.call(receiver) : f ? f.value : state.get(receiver);
|
|
10946
10963
|
};
|
|
10947
|
-
var _PerspectiveClient_instances, _PerspectiveClient_apiClient, _PerspectiveClient_expressionClient, _PerspectiveClient_neighbourhoodClient, _PerspectiveClient_aiClient, _PerspectiveClient_released;
|
|
10964
|
+
var _PerspectiveClient_instances, _PerspectiveClient_apiClient, _PerspectiveClient_expressionClient, _PerspectiveClient_neighbourhoodClient, _PerspectiveClient_aiClient, _PerspectiveClient_sparqlInFlight, _PerspectiveClient_writeGeneration, _PerspectiveClient_wrote, _PerspectiveClient_released;
|
|
10948
10965
|
/** The wire form of a model query's classes: `class_name` for one, `class_names` for a union. */
|
|
10949
10966
|
function classParams(className) {
|
|
10950
10967
|
return Array.isArray(className) ? { class_names: className } : { class_name: className };
|
|
@@ -10966,6 +10983,11 @@ class PerspectiveClient {
|
|
|
10966
10983
|
_PerspectiveClient_expressionClient.set(this, void 0);
|
|
10967
10984
|
_PerspectiveClient_neighbourhoodClient.set(this, void 0);
|
|
10968
10985
|
_PerspectiveClient_aiClient.set(this, void 0);
|
|
10986
|
+
_PerspectiveClient_sparqlInFlight.set(this, new Map()
|
|
10987
|
+
/** Per perspective, how many writes through this client have settled; part of the in-flight key. */
|
|
10988
|
+
);
|
|
10989
|
+
/** Per perspective, how many writes through this client have settled; part of the in-flight key. */
|
|
10990
|
+
_PerspectiveClient_writeGeneration.set(this, new Map());
|
|
10969
10991
|
__classPrivateFieldSet$6(this, _PerspectiveClient_apiClient, sharedApiClient || new ApiClient(baseUrl, token), "f");
|
|
10970
10992
|
}
|
|
10971
10993
|
setExpressionClient(client) {
|
|
@@ -11025,9 +11047,24 @@ class PerspectiveClient {
|
|
|
11025
11047
|
const result = await __classPrivateFieldGet$6(this, _PerspectiveClient_apiClient, "f").call('perspective.queryProlog', { uuid, query }, options);
|
|
11026
11048
|
return JSON.parse(result);
|
|
11027
11049
|
}
|
|
11050
|
+
/**
|
|
11051
|
+
* Concurrent identical calls (same perspective and query, no `options`)
|
|
11052
|
+
* share one RPC. Each caller parses its own copy of the reply, and a call
|
|
11053
|
+
* made after the shared one settled makes a new RPC. So does a call made
|
|
11054
|
+
* after a write through this client settled: the shared RPC may have been
|
|
11055
|
+
* answered before the write (see `#wrote`).
|
|
11056
|
+
*/
|
|
11028
11057
|
async querySparql(uuid, query, options) {
|
|
11029
|
-
|
|
11030
|
-
|
|
11058
|
+
if (options)
|
|
11059
|
+
return JSON.parse(await __classPrivateFieldGet$6(this, _PerspectiveClient_apiClient, "f").call('perspective.querySparql', { uuid, engine: 'sparql', query }, options));
|
|
11060
|
+
const key = `${uuid}\n${__classPrivateFieldGet$6(this, _PerspectiveClient_writeGeneration, "f").get(uuid) ?? 0}\n${query}`;
|
|
11061
|
+
let reply = __classPrivateFieldGet$6(this, _PerspectiveClient_sparqlInFlight, "f").get(key);
|
|
11062
|
+
if (!reply) {
|
|
11063
|
+
reply = __classPrivateFieldGet$6(this, _PerspectiveClient_apiClient, "f").call('perspective.querySparql', { uuid, engine: 'sparql', query })
|
|
11064
|
+
.finally(() => __classPrivateFieldGet$6(this, _PerspectiveClient_sparqlInFlight, "f").delete(key));
|
|
11065
|
+
__classPrivateFieldGet$6(this, _PerspectiveClient_sparqlInFlight, "f").set(key, reply);
|
|
11066
|
+
}
|
|
11067
|
+
return JSON.parse(await reply);
|
|
11031
11068
|
}
|
|
11032
11069
|
/** Open a live SPARQL query. Updates arrive through {@link onQueryUpdate}. */
|
|
11033
11070
|
/** `options.signal` cancels the call, and the executor stops computing the first result. */
|
|
@@ -11084,19 +11121,19 @@ class PerspectiveClient {
|
|
|
11084
11121
|
return { perspectiveRemove: result };
|
|
11085
11122
|
}
|
|
11086
11123
|
async addLink(uuid, link, status = 'shared', batchId) {
|
|
11087
|
-
const added = await __classPrivateFieldGet$6(this, _PerspectiveClient_apiClient, "f").call('perspective.addLink', { uuid, link, status, batchId });
|
|
11124
|
+
const added = await __classPrivateFieldGet$6(this, _PerspectiveClient_instances, "m", _PerspectiveClient_wrote).call(this, uuid, __classPrivateFieldGet$6(this, _PerspectiveClient_apiClient, "f").call('perspective.addLink', { uuid, link, status, batchId }));
|
|
11088
11125
|
return LinkExpression.fromWire(added);
|
|
11089
11126
|
}
|
|
11090
11127
|
async addLinks(uuid, links, status = 'shared', batchId) {
|
|
11091
|
-
const added = await __classPrivateFieldGet$6(this, _PerspectiveClient_apiClient, "f").call('perspective.addLinks', { uuid, links, status, batchId });
|
|
11128
|
+
const added = await __classPrivateFieldGet$6(this, _PerspectiveClient_instances, "m", _PerspectiveClient_wrote).call(this, uuid, __classPrivateFieldGet$6(this, _PerspectiveClient_apiClient, "f").call('perspective.addLinks', { uuid, links, status, batchId }));
|
|
11092
11129
|
return added.map(LinkExpression.fromWire);
|
|
11093
11130
|
}
|
|
11094
11131
|
async removeLinks(uuid, links, batchId) {
|
|
11095
|
-
const removed = await __classPrivateFieldGet$6(this, _PerspectiveClient_apiClient, "f").call('perspective.removeLinks', { uuid, links: links.map(linkExpressionInputToWire), batchId });
|
|
11132
|
+
const removed = await __classPrivateFieldGet$6(this, _PerspectiveClient_instances, "m", _PerspectiveClient_wrote).call(this, uuid, __classPrivateFieldGet$6(this, _PerspectiveClient_apiClient, "f").call('perspective.removeLinks', { uuid, links: links.map(linkExpressionInputToWire), batchId }));
|
|
11096
11133
|
return removed.map(LinkExpression.fromWire);
|
|
11097
11134
|
}
|
|
11098
11135
|
async linkMutations(uuid, mutations, status) {
|
|
11099
|
-
const diff = await __classPrivateFieldGet$6(this, _PerspectiveClient_apiClient, "f").call('perspective.linkMutations', { uuid, mutations: linkMutationsToWire(mutations), status });
|
|
11136
|
+
const diff = await __classPrivateFieldGet$6(this, _PerspectiveClient_instances, "m", _PerspectiveClient_wrote).call(this, uuid, __classPrivateFieldGet$6(this, _PerspectiveClient_apiClient, "f").call('perspective.linkMutations', { uuid, mutations: linkMutationsToWire(mutations), status }));
|
|
11100
11137
|
return LinkExpressionMutations.fromWire(diff);
|
|
11101
11138
|
}
|
|
11102
11139
|
/**
|
|
@@ -11116,11 +11153,11 @@ class PerspectiveClient {
|
|
|
11116
11153
|
* are NOT re-parented — same rule as the watcher).
|
|
11117
11154
|
*/
|
|
11118
11155
|
async runInterpretation(uuid, transcript, basePrefix, classes, existingScope, mintScope, observe, options) {
|
|
11119
|
-
return __classPrivateFieldGet$6(this, _PerspectiveClient_apiClient, "f").call('perspective.runInterpretation', {
|
|
11156
|
+
return __classPrivateFieldGet$6(this, _PerspectiveClient_instances, "m", _PerspectiveClient_wrote).call(this, uuid, __classPrivateFieldGet$6(this, _PerspectiveClient_apiClient, "f").call('perspective.runInterpretation', {
|
|
11120
11157
|
uuid, transcript, basePrefix, classes, existingScope, mintScope,
|
|
11121
11158
|
observationId: observe?.observationId,
|
|
11122
11159
|
emitDebugEvents: observe?.emitDebugEvents,
|
|
11123
|
-
}, options);
|
|
11160
|
+
}, options));
|
|
11124
11161
|
}
|
|
11125
11162
|
/**
|
|
11126
11163
|
* Tool-calling counterpart to {@link runInterpretation}. The LLM sees a
|
|
@@ -11143,7 +11180,7 @@ class PerspectiveClient {
|
|
|
11143
11180
|
// `emitDebugEvents` is a dead-letter without an observationId
|
|
11144
11181
|
// (nothing to key against); the server gates on both.
|
|
11145
11182
|
observationId, emitDebugEvents, options) {
|
|
11146
|
-
return __classPrivateFieldGet$6(this, _PerspectiveClient_apiClient, "f").call('perspective.runInterpretationWithHarness', {
|
|
11183
|
+
return __classPrivateFieldGet$6(this, _PerspectiveClient_instances, "m", _PerspectiveClient_wrote).call(this, uuid, __classPrivateFieldGet$6(this, _PerspectiveClient_apiClient, "f").call('perspective.runInterpretationWithHarness', {
|
|
11147
11184
|
uuid,
|
|
11148
11185
|
transcript,
|
|
11149
11186
|
basePrefix,
|
|
@@ -11153,7 +11190,7 @@ class PerspectiveClient {
|
|
|
11153
11190
|
existingScope,
|
|
11154
11191
|
observationId,
|
|
11155
11192
|
emitDebugEvents,
|
|
11156
|
-
}, options);
|
|
11193
|
+
}, options));
|
|
11157
11194
|
}
|
|
11158
11195
|
/**
|
|
11159
11196
|
* A conversation with a model in this perspective, using the executor's own tools: the tools
|
|
@@ -11166,7 +11203,9 @@ class PerspectiveClient {
|
|
|
11166
11203
|
* calls before it answers.
|
|
11167
11204
|
*/
|
|
11168
11205
|
async runAgent(uuid, messages, settings, options) {
|
|
11169
|
-
|
|
11206
|
+
const reply = __classPrivateFieldGet$6(this, _PerspectiveClient_apiClient, "f").call('perspective.runAgent', { uuid, messages, ...settings }, options);
|
|
11207
|
+
// Without write tools the session only reads.
|
|
11208
|
+
return settings?.writeTools?.length ? __classPrivateFieldGet$6(this, _PerspectiveClient_instances, "m", _PerspectiveClient_wrote).call(this, uuid, reply) : reply;
|
|
11170
11209
|
}
|
|
11171
11210
|
/**
|
|
11172
11211
|
* Register a neighbourhood auto-processor on this perspective. The executor's
|
|
@@ -11177,11 +11216,11 @@ class PerspectiveClient {
|
|
|
11177
11216
|
* Returns the processor id.
|
|
11178
11217
|
*/
|
|
11179
11218
|
async addAutoProcessor(uuid, config) {
|
|
11180
|
-
return __classPrivateFieldGet$6(this, _PerspectiveClient_apiClient, "f").call('perspective.addAutoProcessor', { ...config, uuid });
|
|
11219
|
+
return __classPrivateFieldGet$6(this, _PerspectiveClient_instances, "m", _PerspectiveClient_wrote).call(this, uuid, __classPrivateFieldGet$6(this, _PerspectiveClient_apiClient, "f").call('perspective.addAutoProcessor', { ...config, uuid }));
|
|
11181
11220
|
}
|
|
11182
11221
|
/** Delete an auto-processor's config. `false` when there was none to delete. */
|
|
11183
11222
|
async removeAutoProcessor(uuid, processorId) {
|
|
11184
|
-
return __classPrivateFieldGet$6(this, _PerspectiveClient_apiClient, "f").call('perspective.removeAutoProcessor', { uuid, processorId });
|
|
11223
|
+
return __classPrivateFieldGet$6(this, _PerspectiveClient_instances, "m", _PerspectiveClient_wrote).call(this, uuid, __classPrivateFieldGet$6(this, _PerspectiveClient_apiClient, "f").call('perspective.removeAutoProcessor', { uuid, processorId }));
|
|
11185
11224
|
}
|
|
11186
11225
|
/** Pending interpretation overlays (LLM suggestions awaiting human accept/reject). */
|
|
11187
11226
|
async interpretationOverlays(uuid) {
|
|
@@ -11193,18 +11232,18 @@ class PerspectiveClient {
|
|
|
11193
11232
|
/** Accept an overlay's suggestion(s): the LLM value becomes the real value and
|
|
11194
11233
|
* the overlay is deleted. Omit `property` to accept the whole base. */
|
|
11195
11234
|
async acceptInterpretation(uuid, base, property) {
|
|
11196
|
-
return __classPrivateFieldGet$6(this, _PerspectiveClient_apiClient, "f").call('perspective.acceptInterpretation', { uuid, base, property });
|
|
11235
|
+
return __classPrivateFieldGet$6(this, _PerspectiveClient_instances, "m", _PerspectiveClient_wrote).call(this, uuid, __classPrivateFieldGet$6(this, _PerspectiveClient_apiClient, "f").call('perspective.acceptInterpretation', { uuid, base, property }));
|
|
11197
11236
|
}
|
|
11198
11237
|
/** Reject an overlay's suggestion(s). Omit `property` to reject the whole base
|
|
11199
11238
|
* (a rejected `create` deletes the suggested instance). */
|
|
11200
11239
|
async rejectInterpretation(uuid, base, property) {
|
|
11201
|
-
return __classPrivateFieldGet$6(this, _PerspectiveClient_apiClient, "f").call('perspective.rejectInterpretation', { uuid, base, property });
|
|
11240
|
+
return __classPrivateFieldGet$6(this, _PerspectiveClient_instances, "m", _PerspectiveClient_wrote).call(this, uuid, __classPrivateFieldGet$6(this, _PerspectiveClient_apiClient, "f").call('perspective.rejectInterpretation', { uuid, base, property }));
|
|
11202
11241
|
}
|
|
11203
11242
|
async proposeFlowTransition(uuid, instanceUri, toState, rationale, outputs) {
|
|
11204
|
-
return __classPrivateFieldGet$6(this, _PerspectiveClient_apiClient, "f").call('perspective.proposeFlowTransition', { uuid, instanceUri, toState, rationale, outputs });
|
|
11243
|
+
return __classPrivateFieldGet$6(this, _PerspectiveClient_instances, "m", _PerspectiveClient_wrote).call(this, uuid, __classPrivateFieldGet$6(this, _PerspectiveClient_apiClient, "f").call('perspective.proposeFlowTransition', { uuid, instanceUri, toState, rationale, outputs }));
|
|
11205
11244
|
}
|
|
11206
11245
|
async acceptFlowProposal(uuid, proposalUri) {
|
|
11207
|
-
return __classPrivateFieldGet$6(this, _PerspectiveClient_apiClient, "f").call('perspective.acceptFlowProposal', { uuid, proposalUri });
|
|
11246
|
+
return __classPrivateFieldGet$6(this, _PerspectiveClient_instances, "m", _PerspectiveClient_wrote).call(this, uuid, __classPrivateFieldGet$6(this, _PerspectiveClient_apiClient, "f").call('perspective.acceptFlowProposal', { uuid, proposalUri }));
|
|
11208
11247
|
}
|
|
11209
11248
|
/**
|
|
11210
11249
|
* Withdraw this agent's own links from a proposal. Resolves to how many
|
|
@@ -11212,7 +11251,7 @@ class PerspectiveClient {
|
|
|
11212
11251
|
* proposal this agent opened.
|
|
11213
11252
|
*/
|
|
11214
11253
|
async rejectFlowProposal(uuid, proposalUri) {
|
|
11215
|
-
const result = await __classPrivateFieldGet$6(this, _PerspectiveClient_apiClient, "f").call('perspective.rejectFlowProposal', { uuid, proposalUri });
|
|
11254
|
+
const result = await __classPrivateFieldGet$6(this, _PerspectiveClient_instances, "m", _PerspectiveClient_wrote).call(this, uuid, __classPrivateFieldGet$6(this, _PerspectiveClient_apiClient, "f").call('perspective.rejectFlowProposal', { uuid, proposalUri }));
|
|
11216
11255
|
return result.retractedLinks;
|
|
11217
11256
|
}
|
|
11218
11257
|
/** Re-decide a flow receipt under this perspective's own flow catalogue. */
|
|
@@ -11229,49 +11268,51 @@ class PerspectiveClient {
|
|
|
11229
11268
|
async flowStates(uuid, instances) {
|
|
11230
11269
|
return __classPrivateFieldGet$6(this, _PerspectiveClient_apiClient, "f").call('perspective.flowStates', { uuid, instances });
|
|
11231
11270
|
}
|
|
11232
|
-
/**
|
|
11233
|
-
* fired, sorted.
|
|
11234
|
-
|
|
11235
|
-
|
|
11271
|
+
/** For each of `instances`, in order, the proposals the calling agent's
|
|
11272
|
+
* replica recorded as fired, sorted. One call covers up to 200
|
|
11273
|
+
* instances (more is refused with a 400); split a longer list into
|
|
11274
|
+
* batches of 200. */
|
|
11275
|
+
async flowFired(uuid, instances) {
|
|
11276
|
+
return __classPrivateFieldGet$6(this, _PerspectiveClient_apiClient, "f").call('perspective.flowFired', { uuid, instances });
|
|
11236
11277
|
}
|
|
11237
11278
|
/** Mint and store the receipt for a completed flow run. Fails while the
|
|
11238
11279
|
* run has not settled into a terminal state, and when an output's
|
|
11239
11280
|
* content no longer matches what the quorum committed to. */
|
|
11240
11281
|
async mintFlowReceipt(uuid, instanceUri) {
|
|
11241
|
-
return __classPrivateFieldGet$6(this, _PerspectiveClient_apiClient, "f").call('perspective.mintFlowReceipt', { uuid, instanceUri });
|
|
11282
|
+
return __classPrivateFieldGet$6(this, _PerspectiveClient_instances, "m", _PerspectiveClient_wrote).call(this, uuid, __classPrivateFieldGet$6(this, _PerspectiveClient_apiClient, "f").call('perspective.mintFlowReceipt', { uuid, instanceUri }));
|
|
11242
11283
|
}
|
|
11243
11284
|
async addLinkExpression(uuid, link, status = 'shared', batchId) {
|
|
11244
|
-
const added = await __classPrivateFieldGet$6(this, _PerspectiveClient_apiClient, "f").call('perspective.addLinkExpression', { uuid, link: linkExpressionToWire(link), status, batchId });
|
|
11285
|
+
const added = await __classPrivateFieldGet$6(this, _PerspectiveClient_instances, "m", _PerspectiveClient_wrote).call(this, uuid, __classPrivateFieldGet$6(this, _PerspectiveClient_apiClient, "f").call('perspective.addLinkExpression', { uuid, link: linkExpressionToWire(link), status, batchId }));
|
|
11245
11286
|
return LinkExpression.fromWire(added);
|
|
11246
11287
|
}
|
|
11247
11288
|
async updateLink(uuid, oldLink, newLink, batchId) {
|
|
11248
|
-
const updated = await __classPrivateFieldGet$6(this, _PerspectiveClient_apiClient, "f").call('perspective.updateLink', { uuid, oldLink: linkExpressionInputToWire(oldLink), newLink, batchId });
|
|
11289
|
+
const updated = await __classPrivateFieldGet$6(this, _PerspectiveClient_instances, "m", _PerspectiveClient_wrote).call(this, uuid, __classPrivateFieldGet$6(this, _PerspectiveClient_apiClient, "f").call('perspective.updateLink', { uuid, oldLink: linkExpressionInputToWire(oldLink), newLink, batchId }));
|
|
11249
11290
|
return LinkExpression.fromWire(updated);
|
|
11250
11291
|
}
|
|
11251
11292
|
async removeLink(uuid, link, batchId) {
|
|
11252
11293
|
const { status, ...wire } = linkExpressionInputToWire(link);
|
|
11253
|
-
return __classPrivateFieldGet$6(this, _PerspectiveClient_apiClient, "f").call('perspective.removeLink', { uuid, link: wire, batchId });
|
|
11294
|
+
return __classPrivateFieldGet$6(this, _PerspectiveClient_instances, "m", _PerspectiveClient_wrote).call(this, uuid, __classPrivateFieldGet$6(this, _PerspectiveClient_apiClient, "f").call('perspective.removeLink', { uuid, link: wire, batchId }));
|
|
11254
11295
|
}
|
|
11255
11296
|
async addSdna(uuid, name, sdnaCode, sdnaType, shaclJson) {
|
|
11256
|
-
const result = await __classPrivateFieldGet$6(this, _PerspectiveClient_apiClient, "f").call('perspective.addSdna', { uuid, name, sdnaCode: sdnaCode || "", sdnaType, shaclJson });
|
|
11297
|
+
const result = await __classPrivateFieldGet$6(this, _PerspectiveClient_instances, "m", _PerspectiveClient_wrote).call(this, uuid, __classPrivateFieldGet$6(this, _PerspectiveClient_apiClient, "f").call('perspective.addSdna', { uuid, name, sdnaCode: sdnaCode || "", sdnaType, shaclJson }));
|
|
11257
11298
|
return typeof result === 'boolean' ? result : result.every(Boolean);
|
|
11258
11299
|
}
|
|
11259
11300
|
async addSdnaBatch(uuid, entries) {
|
|
11260
|
-
const result = await __classPrivateFieldGet$6(this, _PerspectiveClient_apiClient, "f").call('perspective.addSdna', { uuid, entries: entries.map(e => ({ ...e, sdnaCode: e.sdnaCode || "" })) });
|
|
11301
|
+
const result = await __classPrivateFieldGet$6(this, _PerspectiveClient_instances, "m", _PerspectiveClient_wrote).call(this, uuid, __classPrivateFieldGet$6(this, _PerspectiveClient_apiClient, "f").call('perspective.addSdna', { uuid, entries: entries.map(e => ({ ...e, sdnaCode: e.sdnaCode || "" })) }));
|
|
11261
11302
|
return typeof result === 'boolean' ? [result] : result;
|
|
11262
11303
|
}
|
|
11263
11304
|
async executeCommands(uuid, commands, expression, parameters, batchId) {
|
|
11264
|
-
return __classPrivateFieldGet$6(this, _PerspectiveClient_apiClient, "f").call('perspective.executeCommands', { uuid, commands, expression, parameters, batchId });
|
|
11305
|
+
return __classPrivateFieldGet$6(this, _PerspectiveClient_instances, "m", _PerspectiveClient_wrote).call(this, uuid, __classPrivateFieldGet$6(this, _PerspectiveClient_apiClient, "f").call('perspective.executeCommands', { uuid, commands, expression, parameters, batchId }));
|
|
11265
11306
|
}
|
|
11266
11307
|
async createSubject(uuid, subjectClass, expressionAddress, initialValues, batchId) {
|
|
11267
|
-
return __classPrivateFieldGet$6(this, _PerspectiveClient_apiClient, "f").call('perspective.createSubject', { uuid, subjectClass, expressionAddress, initialValues, batchId });
|
|
11308
|
+
return __classPrivateFieldGet$6(this, _PerspectiveClient_instances, "m", _PerspectiveClient_wrote).call(this, uuid, __classPrivateFieldGet$6(this, _PerspectiveClient_apiClient, "f").call('perspective.createSubject', { uuid, subjectClass, expressionAddress, initialValues, batchId }));
|
|
11268
11309
|
}
|
|
11269
11310
|
/** Through an abstract class (#1435), the executor writes to the record's own classes. */
|
|
11270
11311
|
async updateSubject(uuid, subjectClass, expressionAddress, values, batchId) {
|
|
11271
|
-
return __classPrivateFieldGet$6(this, _PerspectiveClient_apiClient, "f").call('perspective.updateSubject', { uuid, subjectClass, expressionAddress, values, batchId });
|
|
11312
|
+
return __classPrivateFieldGet$6(this, _PerspectiveClient_instances, "m", _PerspectiveClient_wrote).call(this, uuid, __classPrivateFieldGet$6(this, _PerspectiveClient_apiClient, "f").call('perspective.updateSubject', { uuid, subjectClass, expressionAddress, values, batchId }));
|
|
11272
11313
|
}
|
|
11273
11314
|
async removeSubject(uuid, subjectClass, expressionAddress, batchId) {
|
|
11274
|
-
return __classPrivateFieldGet$6(this, _PerspectiveClient_apiClient, "f").call('perspective.removeSubject', { uuid, subjectClass, expressionAddress, batchId });
|
|
11315
|
+
return __classPrivateFieldGet$6(this, _PerspectiveClient_instances, "m", _PerspectiveClient_wrote).call(this, uuid, __classPrivateFieldGet$6(this, _PerspectiveClient_apiClient, "f").call('perspective.removeSubject', { uuid, subjectClass, expressionAddress, batchId }));
|
|
11275
11316
|
}
|
|
11276
11317
|
/**
|
|
11277
11318
|
* Validated writes (`perspective.instance*`): the executor checks each against the class's
|
|
@@ -11291,23 +11332,23 @@ class PerspectiveClient {
|
|
|
11291
11332
|
* it to keep the calls that succeeded.
|
|
11292
11333
|
*/
|
|
11293
11334
|
async instanceCreate(uuid, body) {
|
|
11294
|
-
return __classPrivateFieldGet$6(this, _PerspectiveClient_apiClient, "f").call('perspective.instanceCreate', { uuid, ...body });
|
|
11335
|
+
return __classPrivateFieldGet$6(this, _PerspectiveClient_instances, "m", _PerspectiveClient_wrote).call(this, uuid, __classPrivateFieldGet$6(this, _PerspectiveClient_apiClient, "f").call('perspective.instanceCreate', { uuid, ...body }));
|
|
11295
11336
|
}
|
|
11296
11337
|
/** Sets the given single-valued properties; the others stay. See {@link instanceCreate}. */
|
|
11297
11338
|
async instanceUpdate(uuid, body) {
|
|
11298
|
-
return __classPrivateFieldGet$6(this, _PerspectiveClient_apiClient, "f").call('perspective.instanceUpdate', { uuid, ...body });
|
|
11339
|
+
return __classPrivateFieldGet$6(this, _PerspectiveClient_instances, "m", _PerspectiveClient_wrote).call(this, uuid, __classPrivateFieldGet$6(this, _PerspectiveClient_apiClient, "f").call('perspective.instanceUpdate', { uuid, ...body }));
|
|
11299
11340
|
}
|
|
11300
11341
|
/** Removes the instance and every link to and from it. See {@link instanceCreate}. */
|
|
11301
11342
|
async instanceRemove(uuid, body) {
|
|
11302
|
-
return __classPrivateFieldGet$6(this, _PerspectiveClient_apiClient, "f").call('perspective.instanceRemove', { uuid, ...body });
|
|
11343
|
+
return __classPrivateFieldGet$6(this, _PerspectiveClient_instances, "m", _PerspectiveClient_wrote).call(this, uuid, __classPrivateFieldGet$6(this, _PerspectiveClient_apiClient, "f").call('perspective.instanceRemove', { uuid, ...body }));
|
|
11303
11344
|
}
|
|
11304
11345
|
/** Adds an item to a collection (a no-op when it is a member). See {@link instanceCreate}. */
|
|
11305
11346
|
async instanceAddToCollection(uuid, body) {
|
|
11306
|
-
return __classPrivateFieldGet$6(this, _PerspectiveClient_apiClient, "f").call('perspective.instanceAddToCollection', { uuid, ...body });
|
|
11347
|
+
return __classPrivateFieldGet$6(this, _PerspectiveClient_instances, "m", _PerspectiveClient_wrote).call(this, uuid, __classPrivateFieldGet$6(this, _PerspectiveClient_apiClient, "f").call('perspective.instanceAddToCollection', { uuid, ...body }));
|
|
11307
11348
|
}
|
|
11308
11349
|
/** Removes an item's membership link from a collection. See {@link instanceCreate}. */
|
|
11309
11350
|
async instanceRemoveFromCollection(uuid, body) {
|
|
11310
|
-
return __classPrivateFieldGet$6(this, _PerspectiveClient_apiClient, "f").call('perspective.instanceRemoveFromCollection', { uuid, ...body });
|
|
11351
|
+
return __classPrivateFieldGet$6(this, _PerspectiveClient_instances, "m", _PerspectiveClient_wrote).call(this, uuid, __classPrivateFieldGet$6(this, _PerspectiveClient_apiClient, "f").call('perspective.instanceRemoveFromCollection', { uuid, ...body }));
|
|
11311
11352
|
}
|
|
11312
11353
|
async getSubjectData(uuid, subjectClass, expressionAddress) {
|
|
11313
11354
|
return __classPrivateFieldGet$6(this, _PerspectiveClient_apiClient, "f").call('perspective.getSubjectData', { uuid, subjectClass, expressionAddress });
|
|
@@ -11343,11 +11384,12 @@ class PerspectiveClient {
|
|
|
11343
11384
|
return __classPrivateFieldGet$6(this, _PerspectiveClient_apiClient, "f").call('perspective.getShacl', { uuid, name });
|
|
11344
11385
|
}
|
|
11345
11386
|
/**
|
|
11346
|
-
* Retrieve
|
|
11347
|
-
* `{name, shapeUri, links}`
|
|
11387
|
+
* Retrieve SHACL shapes in one call: every shape, or only those in
|
|
11388
|
+
* `names` (unknown names are left out). Returns `{name, shapeUri, links}`
|
|
11389
|
+
* per shape.
|
|
11348
11390
|
*/
|
|
11349
|
-
async getAllShacl(uuid) {
|
|
11350
|
-
return __classPrivateFieldGet$6(this, _PerspectiveClient_apiClient, "f").call('perspective.getAllShacl', { uuid });
|
|
11391
|
+
async getAllShacl(uuid, names) {
|
|
11392
|
+
return __classPrivateFieldGet$6(this, _PerspectiveClient_apiClient, "f").call('perspective.getAllShacl', { uuid, names });
|
|
11351
11393
|
}
|
|
11352
11394
|
// ExpressionClient functions, needed for Subjects:
|
|
11353
11395
|
async getExpression(expressionURI) {
|
|
@@ -11367,7 +11409,7 @@ class PerspectiveClient {
|
|
|
11367
11409
|
return __classPrivateFieldGet$6(this, _PerspectiveClient_apiClient, "f").call('perspective.createBatch', { uuid });
|
|
11368
11410
|
}
|
|
11369
11411
|
async commitBatch(uuid, batchId) {
|
|
11370
|
-
const diff = await __classPrivateFieldGet$6(this, _PerspectiveClient_apiClient, "f").call('perspective.commitBatch', { uuid, batchId });
|
|
11412
|
+
const diff = await __classPrivateFieldGet$6(this, _PerspectiveClient_instances, "m", _PerspectiveClient_wrote).call(this, uuid, __classPrivateFieldGet$6(this, _PerspectiveClient_apiClient, "f").call('perspective.commitBatch', { uuid, batchId }));
|
|
11371
11413
|
return LinkExpressionMutations.fromWire(diff);
|
|
11372
11414
|
}
|
|
11373
11415
|
/**
|
|
@@ -11385,7 +11427,21 @@ class PerspectiveClient {
|
|
|
11385
11427
|
return __classPrivateFieldGet$6(this, _PerspectiveClient_apiClient, "f").onReconnect(callback);
|
|
11386
11428
|
}
|
|
11387
11429
|
}
|
|
11388
|
-
_PerspectiveClient_apiClient = new WeakMap(), _PerspectiveClient_expressionClient = new WeakMap(), _PerspectiveClient_neighbourhoodClient = new WeakMap(), _PerspectiveClient_aiClient = new WeakMap(), _PerspectiveClient_instances = new WeakSet(),
|
|
11430
|
+
_PerspectiveClient_apiClient = new WeakMap(), _PerspectiveClient_expressionClient = new WeakMap(), _PerspectiveClient_neighbourhoodClient = new WeakMap(), _PerspectiveClient_aiClient = new WeakMap(), _PerspectiveClient_sparqlInFlight = new WeakMap(), _PerspectiveClient_writeGeneration = new WeakMap(), _PerspectiveClient_instances = new WeakSet(), _PerspectiveClient_wrote =
|
|
11431
|
+
/**
|
|
11432
|
+
* Await a write to `uuid`, then start a new write generation for it
|
|
11433
|
+
* (also when the write failed: it may still have changed the perspective).
|
|
11434
|
+
* Calls of {@link querySparql} already waiting keep sharing their RPC; an
|
|
11435
|
+
* identical call started from now on makes its own.
|
|
11436
|
+
*/
|
|
11437
|
+
async function _PerspectiveClient_wrote(uuid, write) {
|
|
11438
|
+
try {
|
|
11439
|
+
return await write;
|
|
11440
|
+
}
|
|
11441
|
+
finally {
|
|
11442
|
+
__classPrivateFieldGet$6(this, _PerspectiveClient_writeGeneration, "f").set(uuid, (__classPrivateFieldGet$6(this, _PerspectiveClient_writeGeneration, "f").get(uuid) ?? 0) + 1);
|
|
11443
|
+
}
|
|
11444
|
+
}, _PerspectiveClient_released =
|
|
11389
11445
|
/** A subscribe call that failed (timed out, aborted, refused) leaves no live
|
|
11390
11446
|
* query on the executor that nobody holds. The client minted its id, so it
|
|
11391
11447
|
* disposes it without the reply. A timeout or an abort sends `request.cancel`
|
|
@@ -11633,112 +11689,59 @@ var __classPrivateFieldGet$4 = (undefined && undefined.__classPrivateFieldGet) |
|
|
|
11633
11689
|
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");
|
|
11634
11690
|
return kind === "m" ? f : kind === "a" ? f.call(receiver) : f ? f.value : state.get(receiver);
|
|
11635
11691
|
};
|
|
11636
|
-
var
|
|
11692
|
+
var _ExpressionClient_apiClient, _ExpressionClient_expressions;
|
|
11693
|
+
/** Most URLs the executor takes in one `expression.getMany` call. */
|
|
11694
|
+
const MAX_URLS_PER_CALL = 200;
|
|
11637
11695
|
class ExpressionClient {
|
|
11638
11696
|
constructor(baseUrl, token, sharedApiClient) {
|
|
11639
|
-
_ExpressionClient_instances.add(this);
|
|
11640
11697
|
_ExpressionClient_apiClient.set(this, void 0);
|
|
11641
|
-
//
|
|
11642
|
-
|
|
11643
|
-
|
|
11644
|
-
|
|
11645
|
-
|
|
11646
|
-
_ExpressionClient_persistent.set(this, void 0);
|
|
11698
|
+
// A `get` miss is its own `expression.get`, so it waits for no slower
|
|
11699
|
+
// expression and has its own call timeout. The misses of the `getMany`
|
|
11700
|
+
// calls made in one tick go out in `expression.getMany` calls of at most
|
|
11701
|
+
// MAX_URLS_PER_CALL URLs, which answer per URL what `expression.get` would.
|
|
11702
|
+
_ExpressionClient_expressions.set(this, void 0);
|
|
11647
11703
|
__classPrivateFieldSet$4(this, _ExpressionClient_apiClient, sharedApiClient || new ApiClient(baseUrl, token), "f");
|
|
11648
|
-
__classPrivateFieldSet$4(this,
|
|
11704
|
+
__classPrivateFieldSet$4(this, _ExpressionClient_expressions, new KeyedCache({
|
|
11705
|
+
load: (url) => __classPrivateFieldGet$4(this, _ExpressionClient_apiClient, "f").call('expression.get', { url }),
|
|
11706
|
+
loadMany: async (urls) => (await __classPrivateFieldGet$4(this, _ExpressionClient_apiClient, "f").call('expression.getMany', { urls })).map(entry => entry && 'code' in entry ? new RpcError(entry.code, entry.message) : entry),
|
|
11707
|
+
maxBatch: MAX_URLS_PER_CALL,
|
|
11708
|
+
persistent: createPersistentCache('ad4m-expression-cache', 'expressions'),
|
|
11709
|
+
maxAgeMs: () => ExpressionClient.EXPRESSION_TTL_MS,
|
|
11710
|
+
persistentMaxAgeMs: () => ExpressionClient.EXPRESSION_TTL_MS,
|
|
11711
|
+
limits: () => ({ entries: ExpressionClient.MAX_MEM_ENTRIES, bytes: ExpressionClient.MAX_MEM_BYTES }),
|
|
11712
|
+
}), "f");
|
|
11649
11713
|
}
|
|
11714
|
+
/** The expression at `url`; `alwaysGet` skips the literal fast path and the cache. */
|
|
11650
11715
|
async get(url, alwaysGet = false) {
|
|
11651
|
-
|
|
11652
|
-
if (!alwaysGet) {
|
|
11653
|
-
try {
|
|
11654
|
-
let literalValue = Literal.fromUrl(url).get();
|
|
11655
|
-
if (typeof literalValue === 'object' && literalValue !== null) {
|
|
11656
|
-
if ('author' in literalValue && 'timestamp' in literalValue && 'data' in literalValue && 'proof' in literalValue) {
|
|
11657
|
-
return literalValue;
|
|
11658
|
-
}
|
|
11659
|
-
}
|
|
11660
|
-
}
|
|
11661
|
-
catch (e) { }
|
|
11662
|
-
}
|
|
11663
|
-
// L1: memory hit
|
|
11664
|
-
if (!alwaysGet) {
|
|
11665
|
-
const memHit = __classPrivateFieldGet$4(this, _ExpressionClient_memCache, "f").get(url);
|
|
11666
|
-
if (memHit)
|
|
11667
|
-
return memHit.data;
|
|
11668
|
-
}
|
|
11669
|
-
// Deduplicate in-flight requests
|
|
11670
|
-
if (!alwaysGet) {
|
|
11671
|
-
const existing = __classPrivateFieldGet$4(this, _ExpressionClient_inflight, "f").get(url);
|
|
11672
|
-
if (existing)
|
|
11673
|
-
return existing;
|
|
11674
|
-
}
|
|
11675
|
-
// L2 check + L3 network
|
|
11676
|
-
const promise = (async () => {
|
|
11677
|
-
if (!alwaysGet) {
|
|
11678
|
-
const persisted = await __classPrivateFieldGet$4(this, _ExpressionClient_persistent, "f").get(url);
|
|
11679
|
-
if (persisted) {
|
|
11680
|
-
__classPrivateFieldGet$4(this, _ExpressionClient_instances, "m", _ExpressionClient_memCacheResult).call(this, url, persisted); // promote to L1
|
|
11681
|
-
return persisted;
|
|
11682
|
-
}
|
|
11683
|
-
}
|
|
11684
|
-
// L3: network fetch
|
|
11716
|
+
if (alwaysGet) {
|
|
11685
11717
|
const result = await __classPrivateFieldGet$4(this, _ExpressionClient_apiClient, "f").call('expression.get', { url });
|
|
11686
|
-
|
|
11687
|
-
|
|
11718
|
+
if (result)
|
|
11719
|
+
__classPrivateFieldGet$4(this, _ExpressionClient_expressions, "f").set(url, result);
|
|
11688
11720
|
return result;
|
|
11689
|
-
})();
|
|
11690
|
-
__classPrivateFieldGet$4(this, _ExpressionClient_inflight, "f").set(url, promise);
|
|
11691
|
-
try {
|
|
11692
|
-
return await promise;
|
|
11693
11721
|
}
|
|
11694
|
-
|
|
11695
|
-
|
|
11722
|
+
try {
|
|
11723
|
+
let literalValue = Literal.fromUrl(url).get();
|
|
11724
|
+
if (typeof literalValue === 'object' && literalValue !== null) {
|
|
11725
|
+
if ('author' in literalValue && 'timestamp' in literalValue && 'data' in literalValue && 'proof' in literalValue) {
|
|
11726
|
+
return literalValue;
|
|
11727
|
+
}
|
|
11728
|
+
}
|
|
11696
11729
|
}
|
|
11730
|
+
catch (e) { }
|
|
11731
|
+
return __classPrivateFieldGet$4(this, _ExpressionClient_expressions, "f").get(url);
|
|
11697
11732
|
}
|
|
11733
|
+
/**
|
|
11734
|
+
* The expressions at `urls`, in order (`null` when not found); the misses go
|
|
11735
|
+
* out in calls of at most 200 URLs. Rejects with the `RpcError` `get` gives when a URL's read fails.
|
|
11736
|
+
*/
|
|
11698
11737
|
async getMany(urls) {
|
|
11699
|
-
|
|
11700
|
-
const results = urls.map(u => __classPrivateFieldGet$4(this, _ExpressionClient_memCache, "f").get(u)?.data ?? null);
|
|
11701
|
-
let uncachedIndices = results
|
|
11702
|
-
.map((r, i) => r === null ? i : -1)
|
|
11703
|
-
.filter(i => i >= 0);
|
|
11704
|
-
if (uncachedIndices.length === 0)
|
|
11705
|
-
return results;
|
|
11706
|
-
// Check L2 for remaining misses
|
|
11707
|
-
const l2Results = await Promise.all(uncachedIndices.map(i => __classPrivateFieldGet$4(this, _ExpressionClient_persistent, "f").get(urls[i])));
|
|
11708
|
-
const stillMissing = [];
|
|
11709
|
-
for (let j = 0; j < uncachedIndices.length; j++) {
|
|
11710
|
-
const idx = uncachedIndices[j];
|
|
11711
|
-
if (l2Results[j]) {
|
|
11712
|
-
results[idx] = l2Results[j];
|
|
11713
|
-
__classPrivateFieldGet$4(this, _ExpressionClient_instances, "m", _ExpressionClient_memCacheResult).call(this, urls[idx], l2Results[j]); // promote to L1
|
|
11714
|
-
}
|
|
11715
|
-
else {
|
|
11716
|
-
stillMissing.push(idx);
|
|
11717
|
-
}
|
|
11718
|
-
}
|
|
11719
|
-
if (stillMissing.length === 0)
|
|
11720
|
-
return results;
|
|
11721
|
-
// L3: fetch only truly uncached URLs
|
|
11722
|
-
const uncachedUrls = stillMissing.map(i => urls[i]);
|
|
11723
|
-
const fetched = await __classPrivateFieldGet$4(this, _ExpressionClient_apiClient, "f").call('expression.getMany', { urls: uncachedUrls });
|
|
11724
|
-
for (let i = 0; i < stillMissing.length; i++) {
|
|
11725
|
-
const idx = stillMissing[i];
|
|
11726
|
-
results[idx] = fetched[i];
|
|
11727
|
-
if (fetched[i]) {
|
|
11728
|
-
__classPrivateFieldGet$4(this, _ExpressionClient_instances, "m", _ExpressionClient_memCacheResult).call(this, uncachedUrls[i], fetched[i]);
|
|
11729
|
-
__classPrivateFieldGet$4(this, _ExpressionClient_persistent, "f").put(uncachedUrls[i], fetched[i]); // fire-and-forget
|
|
11730
|
-
}
|
|
11731
|
-
}
|
|
11732
|
-
return results;
|
|
11738
|
+
return __classPrivateFieldGet$4(this, _ExpressionClient_expressions, "f").getMany(urls);
|
|
11733
11739
|
}
|
|
11734
11740
|
/**
|
|
11735
|
-
* Clear both
|
|
11741
|
+
* Clear both the memory and the persistent expression caches.
|
|
11736
11742
|
*/
|
|
11737
11743
|
clearCache() {
|
|
11738
|
-
__classPrivateFieldGet$4(this,
|
|
11739
|
-
__classPrivateFieldGet$4(this, _ExpressionClient_inflight, "f").clear();
|
|
11740
|
-
__classPrivateFieldSet$4(this, _ExpressionClient_totalMemBytes, 0, "f");
|
|
11741
|
-
__classPrivateFieldGet$4(this, _ExpressionClient_persistent, "f").clear(); // fire-and-forget
|
|
11744
|
+
__classPrivateFieldGet$4(this, _ExpressionClient_expressions, "f").clear(true);
|
|
11742
11745
|
}
|
|
11743
11746
|
async getRaw(url) {
|
|
11744
11747
|
return __classPrivateFieldGet$4(this, _ExpressionClient_apiClient, "f").call('expression.getRaw', { url });
|
|
@@ -11753,31 +11756,21 @@ class ExpressionClient {
|
|
|
11753
11756
|
async interact(url, interactionCall) {
|
|
11754
11757
|
const result = await __classPrivateFieldGet$4(this, _ExpressionClient_apiClient, "f").call('expression.interact', { url, interactionCall });
|
|
11755
11758
|
// Interactions can mutate the expression — invalidate cache so next get() fetches fresh
|
|
11756
|
-
__classPrivateFieldGet$4(this,
|
|
11757
|
-
__classPrivateFieldGet$4(this, _ExpressionClient_inflight, "f").delete(url);
|
|
11758
|
-
__classPrivateFieldGet$4(this, _ExpressionClient_persistent, "f").delete(url); // fire-and-forget
|
|
11759
|
+
__classPrivateFieldGet$4(this, _ExpressionClient_expressions, "f").delete(url);
|
|
11759
11760
|
return result;
|
|
11760
11761
|
}
|
|
11761
11762
|
}
|
|
11762
|
-
_ExpressionClient_apiClient = new WeakMap(),
|
|
11763
|
-
|
|
11764
|
-
// Evict oldest entries if we'd exceed limits
|
|
11765
|
-
while (__classPrivateFieldGet$4(this, _ExpressionClient_memCache, "f").size >= ExpressionClient.MAX_MEM_ENTRIES ||
|
|
11766
|
-
__classPrivateFieldGet$4(this, _ExpressionClient_totalMemBytes, "f") + size > ExpressionClient.MAX_MEM_BYTES) {
|
|
11767
|
-
const oldest = __classPrivateFieldGet$4(this, _ExpressionClient_memCache, "f").keys().next().value;
|
|
11768
|
-
if (!oldest)
|
|
11769
|
-
break;
|
|
11770
|
-
const entry = __classPrivateFieldGet$4(this, _ExpressionClient_memCache, "f").get(oldest);
|
|
11771
|
-
__classPrivateFieldSet$4(this, _ExpressionClient_totalMemBytes, __classPrivateFieldGet$4(this, _ExpressionClient_totalMemBytes, "f") - entry.size, "f");
|
|
11772
|
-
__classPrivateFieldGet$4(this, _ExpressionClient_memCache, "f").delete(oldest);
|
|
11773
|
-
}
|
|
11774
|
-
__classPrivateFieldGet$4(this, _ExpressionClient_memCache, "f").set(url, { data, size });
|
|
11775
|
-
__classPrivateFieldSet$4(this, _ExpressionClient_totalMemBytes, __classPrivateFieldGet$4(this, _ExpressionClient_totalMemBytes, "f") + size, "f");
|
|
11776
|
-
};
|
|
11777
|
-
/** Maximum number of entries in the L1 memory cache. */
|
|
11763
|
+
_ExpressionClient_apiClient = new WeakMap(), _ExpressionClient_expressions = new WeakMap();
|
|
11764
|
+
/** Maximum number of expressions kept in memory. */
|
|
11778
11765
|
ExpressionClient.MAX_MEM_ENTRIES = 200;
|
|
11779
|
-
/** Maximum total size (in bytes) of
|
|
11766
|
+
/** Maximum total size (in bytes of JSON) of the expressions kept in memory. */
|
|
11780
11767
|
ExpressionClient.MAX_MEM_BYTES = 5 * 1024 * 1024; // 5 MB
|
|
11768
|
+
/**
|
|
11769
|
+
* TTL of every cached expression, in memory and in the persistent cache
|
|
11770
|
+
* (ms). A language may change what a URL returns, and no event tells the
|
|
11771
|
+
* client, so a cached expression expires instead of staying stale.
|
|
11772
|
+
*/
|
|
11773
|
+
ExpressionClient.EXPRESSION_TTL_MS = 5 * 60000; // 5 minutes
|
|
11781
11774
|
|
|
11782
11775
|
var base64Js = {};
|
|
11783
11776
|
|
|
@@ -19294,6 +19287,18 @@ function isIncludeProjection(val) {
|
|
|
19294
19287
|
/**
|
|
19295
19288
|
* Shared query helpers used by both the Prolog and SPARQL query pipelines.
|
|
19296
19289
|
*/
|
|
19290
|
+
/**
|
|
19291
|
+
* The `totalCount` of a model query sent with `count: true`. The executor
|
|
19292
|
+
* answers such a query with a count, so an answer without one is an error,
|
|
19293
|
+
* not zero matches.
|
|
19294
|
+
*/
|
|
19295
|
+
function requireTotalCount(answer) {
|
|
19296
|
+
const totalCount = answer?.totalCount;
|
|
19297
|
+
if (typeof totalCount !== "number") {
|
|
19298
|
+
throw new Error("model query asked for a count (count: true) but the answer has no totalCount");
|
|
19299
|
+
}
|
|
19300
|
+
return totalCount;
|
|
19301
|
+
}
|
|
19297
19302
|
/**
|
|
19298
19303
|
* Resolves the predicate for a parent query.
|
|
19299
19304
|
*
|
|
@@ -20376,12 +20381,17 @@ class ModelQueryBuilder {
|
|
|
20376
20381
|
return { live, initial: await live.start() };
|
|
20377
20382
|
}
|
|
20378
20383
|
catch (e) {
|
|
20379
|
-
|
|
20380
|
-
if (this.currentSubscription === live)
|
|
20381
|
-
this.currentSubscription = undefined;
|
|
20384
|
+
this.endFailed(live);
|
|
20382
20385
|
throw e;
|
|
20383
20386
|
}
|
|
20384
20387
|
}
|
|
20388
|
+
/** End `live` after its call failed. A later call may already own
|
|
20389
|
+
* `currentSubscription`, so only clear it if it is still `live`. */
|
|
20390
|
+
endFailed(live) {
|
|
20391
|
+
live.dispose();
|
|
20392
|
+
if (this.currentSubscription === live)
|
|
20393
|
+
this.currentSubscription = undefined;
|
|
20394
|
+
}
|
|
20385
20395
|
/**
|
|
20386
20396
|
* Adds where conditions to the query.
|
|
20387
20397
|
*
|
|
@@ -20768,8 +20778,7 @@ class ModelQueryBuilder {
|
|
|
20768
20778
|
* ```
|
|
20769
20779
|
*/
|
|
20770
20780
|
async count() {
|
|
20771
|
-
|
|
20772
|
-
return totalCount;
|
|
20781
|
+
return requireTotalCount(await this.execute({ ...this.queryParams, limit: 0, count: true }));
|
|
20773
20782
|
}
|
|
20774
20783
|
/**
|
|
20775
20784
|
* Gets the total count of matching entities using SPARQL.
|
|
@@ -20808,8 +20817,23 @@ class ModelQueryBuilder {
|
|
|
20808
20817
|
*/
|
|
20809
20818
|
async countSubscribe(callback) {
|
|
20810
20819
|
this.dispose();
|
|
20811
|
-
|
|
20812
|
-
|
|
20820
|
+
// As paginateSubscribe: a push without the asked-for count is logged and
|
|
20821
|
+
// skipped, since a throw here would reach the client's update dispatch.
|
|
20822
|
+
const { live, initial } = await this.live({ ...this.queryParams, limit: 0, count: true }, (raw) => {
|
|
20823
|
+
try {
|
|
20824
|
+
callback(requireTotalCount(raw));
|
|
20825
|
+
}
|
|
20826
|
+
catch (e) {
|
|
20827
|
+
console.error('Count subscription error:', e);
|
|
20828
|
+
}
|
|
20829
|
+
});
|
|
20830
|
+
try {
|
|
20831
|
+
return requireTotalCount(initial);
|
|
20832
|
+
}
|
|
20833
|
+
catch (e) {
|
|
20834
|
+
this.endFailed(live);
|
|
20835
|
+
throw e;
|
|
20836
|
+
}
|
|
20813
20837
|
}
|
|
20814
20838
|
/**
|
|
20815
20839
|
* Subscribes to count updates using SPARQL.
|
|
@@ -20835,8 +20859,8 @@ class ModelQueryBuilder {
|
|
|
20835
20859
|
*/
|
|
20836
20860
|
async paginate(pageSize, pageNumber) {
|
|
20837
20861
|
const paginationQuery = { ...(this.queryParams || {}), limit: pageSize, offset: pageSize * (pageNumber - 1), count: true };
|
|
20838
|
-
const
|
|
20839
|
-
return { results, totalCount, pageSize, pageNumber };
|
|
20862
|
+
const answer = await this.execute(paginationQuery);
|
|
20863
|
+
return { results: answer.results, totalCount: requireTotalCount(answer), pageSize, pageNumber };
|
|
20840
20864
|
}
|
|
20841
20865
|
/**
|
|
20842
20866
|
* Gets a page of results using SPARQL.
|
|
@@ -20899,9 +20923,10 @@ class ModelQueryBuilder {
|
|
|
20899
20923
|
const results = this.parse(raw);
|
|
20900
20924
|
const fp = fingerprint([results, raw?.totalCount]);
|
|
20901
20925
|
this.takeSnapshots(results);
|
|
20902
|
-
|
|
20926
|
+
// `count: true` is set above, so the executor sends a total.
|
|
20927
|
+
return { page: { results, totalCount: requireTotalCount(raw), pageSize, pageNumber }, fp };
|
|
20903
20928
|
};
|
|
20904
|
-
const { initial } = await this.live(paginatedQuery, (raw) => {
|
|
20929
|
+
const { live, initial } = await this.live(paginatedQuery, (raw) => {
|
|
20905
20930
|
try {
|
|
20906
20931
|
const { page, fp } = toPage(raw);
|
|
20907
20932
|
if (fp === lastFingerprint)
|
|
@@ -20913,9 +20938,16 @@ class ModelQueryBuilder {
|
|
|
20913
20938
|
console.error('Paginate subscription error:', e);
|
|
20914
20939
|
}
|
|
20915
20940
|
});
|
|
20916
|
-
|
|
20917
|
-
|
|
20918
|
-
|
|
20941
|
+
let first;
|
|
20942
|
+
try {
|
|
20943
|
+
first = toPage(initial);
|
|
20944
|
+
}
|
|
20945
|
+
catch (e) {
|
|
20946
|
+
this.endFailed(live);
|
|
20947
|
+
throw e;
|
|
20948
|
+
}
|
|
20949
|
+
lastFingerprint = first.fp;
|
|
20950
|
+
return first.page;
|
|
20919
20951
|
}
|
|
20920
20952
|
/**
|
|
20921
20953
|
* Subscribes to paginated results updates using SPARQL.
|
|
@@ -21288,6 +21320,8 @@ function jsonToModelInstance(ModelClass, perspective, json, include, properties)
|
|
|
21288
21320
|
}
|
|
21289
21321
|
return instance;
|
|
21290
21322
|
}
|
|
21323
|
+
/** The most writes `sendWrites` joins into one `executeAction` call. */
|
|
21324
|
+
const MAX_WRITES_PER_CALL = 200;
|
|
21291
21325
|
/**
|
|
21292
21326
|
* Put `childId` under `parent`. A containment scope `{ id }` writes through the
|
|
21293
21327
|
* built-in `Container` (#1446): the executor runs the adder of the parent's own
|
|
@@ -22343,8 +22377,8 @@ class Ad4mModel {
|
|
|
22343
22377
|
* ```
|
|
22344
22378
|
*/
|
|
22345
22379
|
static async findAllAndCount(perspective, query, options) {
|
|
22346
|
-
const
|
|
22347
|
-
return
|
|
22380
|
+
const answer = await this.executeModelQuery(perspective, { ...(query ?? {}), count: true }, undefined, options);
|
|
22381
|
+
return { results: answer.results, totalCount: requireTotalCount(answer) };
|
|
22348
22382
|
}
|
|
22349
22383
|
/**
|
|
22350
22384
|
* Helper function for pagination with explicit page size and number.
|
|
@@ -22365,8 +22399,8 @@ class Ad4mModel {
|
|
|
22365
22399
|
*/
|
|
22366
22400
|
static async paginate(perspective, pageSize, pageNumber, query, options) {
|
|
22367
22401
|
const paginationQuery = { ...(query ?? {}), limit: pageSize, offset: pageSize * (pageNumber - 1), count: true };
|
|
22368
|
-
const
|
|
22369
|
-
return { results: results, totalCount, pageSize, pageNumber };
|
|
22402
|
+
const answer = await this.executeModelQuery(perspective, paginationQuery, undefined, options);
|
|
22403
|
+
return { results: answer.results, totalCount: requireTotalCount(answer), pageSize, pageNumber };
|
|
22370
22404
|
}
|
|
22371
22405
|
/**
|
|
22372
22406
|
* Generates a SPARQL COUNT query for the model.
|
|
@@ -22394,20 +22428,20 @@ class Ad4mModel {
|
|
|
22394
22428
|
* ```
|
|
22395
22429
|
*/
|
|
22396
22430
|
static async count(perspective, query, options) {
|
|
22397
|
-
|
|
22398
|
-
return totalCount;
|
|
22431
|
+
return requireTotalCount(await this.executeModelQuery(perspective, { ...(query ?? {}), limit: 0, count: true }, undefined, options));
|
|
22399
22432
|
}
|
|
22400
|
-
|
|
22433
|
+
/** The `executeAction` write that sets property `key` to `value`; none for an empty value. */
|
|
22434
|
+
async planProperty(key, value) {
|
|
22401
22435
|
const metadata = this.getPropertyMetadata(key);
|
|
22402
22436
|
if (!metadata) {
|
|
22403
22437
|
console.warn(`Property "${key}" has no metadata, skipping`);
|
|
22404
|
-
return;
|
|
22438
|
+
return [];
|
|
22405
22439
|
}
|
|
22406
22440
|
// Generate actions from metadata (replaces Prolog query)
|
|
22407
22441
|
const actions = this.generatePropertySetterAction(key, metadata);
|
|
22408
22442
|
// Skip storing empty/null/undefined values to avoid invalid empty literals (e.g. literal:string:)
|
|
22409
22443
|
if (value === undefined || value === null || value === "") {
|
|
22410
|
-
return;
|
|
22444
|
+
return [];
|
|
22411
22445
|
}
|
|
22412
22446
|
const mode = effectiveLiteralStorage(metadata);
|
|
22413
22447
|
if (mode.kind === "custom") {
|
|
@@ -22422,7 +22456,77 @@ class Ad4mModel {
|
|
|
22422
22456
|
// Deterministic literal: IRI (POS-index friendly).
|
|
22423
22457
|
value = valueToLiteralIri(value);
|
|
22424
22458
|
}
|
|
22425
|
-
|
|
22459
|
+
return [{ commands: actions, parameters: [{ name: "value", value }] }];
|
|
22460
|
+
}
|
|
22461
|
+
/**
|
|
22462
|
+
* The `executeAction` writes of a relation change: one for a set (its
|
|
22463
|
+
* `collectionSetter` takes every value), one per value for an add or remove.
|
|
22464
|
+
*/
|
|
22465
|
+
planRelation(key, kind, value) {
|
|
22466
|
+
const metadata = this.getRelationOptions(key);
|
|
22467
|
+
if (!metadata) {
|
|
22468
|
+
console.warn(`Relation "${key}" has no metadata, skipping`);
|
|
22469
|
+
return [];
|
|
22470
|
+
}
|
|
22471
|
+
// Generate actions from metadata (replaces Prolog query)
|
|
22472
|
+
const actions = this.generateRelationAction(key, kind);
|
|
22473
|
+
if (value == null)
|
|
22474
|
+
return [];
|
|
22475
|
+
const values = Array.isArray(value) ? value : [value];
|
|
22476
|
+
const param = (v) => ({ name: "value", value: this.resolveRelationId(v) });
|
|
22477
|
+
if (kind === 'setter')
|
|
22478
|
+
return [{ commands: actions, parameters: values.map(param) }];
|
|
22479
|
+
return values.map(v => ({ commands: actions, parameters: [param(v)] }));
|
|
22480
|
+
}
|
|
22481
|
+
/**
|
|
22482
|
+
* Sends writes in as few `executeAction` calls as keep their links: the
|
|
22483
|
+
* executor runs a call's commands in order, so consecutive writes share one
|
|
22484
|
+
* call, each with its own parameter names. A `collectionSetter` takes every
|
|
22485
|
+
* parameter of its call as a member, so it goes in a call of its own. A
|
|
22486
|
+
* command's `local` flag is per command, so Local and Shared links mix. The
|
|
22487
|
+
* executor tries every parameter name at each position of each command, so
|
|
22488
|
+
* a call holds at most `MAX_WRITES_PER_CALL` writes.
|
|
22489
|
+
*/
|
|
22490
|
+
async sendWrites(writes, batchId) {
|
|
22491
|
+
let group = [];
|
|
22492
|
+
const flush = async () => {
|
|
22493
|
+
if (group.length === 1) {
|
|
22494
|
+
await this._perspective.executeAction(group[0].commands, this._baseExpression, group[0].parameters, batchId);
|
|
22495
|
+
}
|
|
22496
|
+
else if (group.length > 1) {
|
|
22497
|
+
const commands = [];
|
|
22498
|
+
const parameters = [];
|
|
22499
|
+
group.forEach((write, i) => {
|
|
22500
|
+
// The executor substitutes a parameter name wherever it occurs in a
|
|
22501
|
+
// command's source, predicate or target; rename `value` the same way.
|
|
22502
|
+
const name = `ad4m-model-write-${i}-value`;
|
|
22503
|
+
const rename = (s) => (typeof s === "string" && write.parameters.length ? s.split("value").join(name) : s);
|
|
22504
|
+
for (const c of write.commands) {
|
|
22505
|
+
commands.push({ ...c, source: rename(c.source), predicate: rename(c.predicate), target: rename(c.target) });
|
|
22506
|
+
}
|
|
22507
|
+
for (const p of write.parameters)
|
|
22508
|
+
parameters.push({ name, value: p.value });
|
|
22509
|
+
});
|
|
22510
|
+
await this._perspective.executeAction(commands, this._baseExpression, parameters, batchId);
|
|
22511
|
+
}
|
|
22512
|
+
group = [];
|
|
22513
|
+
};
|
|
22514
|
+
for (const write of writes) {
|
|
22515
|
+
if (write.commands.some((c) => c.action === "collectionSetter")) {
|
|
22516
|
+
await flush();
|
|
22517
|
+
group = [write];
|
|
22518
|
+
await flush();
|
|
22519
|
+
}
|
|
22520
|
+
else {
|
|
22521
|
+
group.push(write);
|
|
22522
|
+
if (group.length >= MAX_WRITES_PER_CALL)
|
|
22523
|
+
await flush();
|
|
22524
|
+
}
|
|
22525
|
+
}
|
|
22526
|
+
await flush();
|
|
22527
|
+
}
|
|
22528
|
+
async setProperty(key, value, batchId) {
|
|
22529
|
+
await this.sendWrites(await this.planProperty(key, value), batchId);
|
|
22426
22530
|
}
|
|
22427
22531
|
/** Resolve a relation argument to a plain string ID. Accepts either a raw
|
|
22428
22532
|
* string ID or an Ad4mModel instance (in which case `.id` is used). */
|
|
@@ -22442,75 +22546,33 @@ class Ad4mModel {
|
|
|
22442
22546
|
await this._perspective.updateSubject(abstractName, this._baseExpression, { [key]: { action, value: ids } }, batchId);
|
|
22443
22547
|
}
|
|
22444
22548
|
async setRelationValues(key, value, batchId) {
|
|
22445
|
-
|
|
22446
|
-
if (!metadata) {
|
|
22447
|
-
console.warn(`Relation "${key}" has no metadata, skipping`);
|
|
22448
|
-
return;
|
|
22449
|
-
}
|
|
22450
|
-
this._relationsWritten.add(metadata.predicate);
|
|
22451
|
-
const abstractName = this.abstractName();
|
|
22452
|
-
if (abstractName) {
|
|
22453
|
-
if (value != null)
|
|
22454
|
-
await this.relationThroughAbstract(abstractName, key, 'setter', value, batchId);
|
|
22455
|
-
return;
|
|
22456
|
-
}
|
|
22457
|
-
// Generate actions from metadata (replaces Prolog query)
|
|
22458
|
-
const actions = this.generateRelationAction(key, 'setter');
|
|
22459
|
-
if (value != null) {
|
|
22460
|
-
if (Array.isArray(value)) {
|
|
22461
|
-
await this._perspective.executeAction(actions, this._baseExpression, value.map((v) => ({ name: "value", value: this.resolveRelationId(v) })), batchId);
|
|
22462
|
-
}
|
|
22463
|
-
else {
|
|
22464
|
-
await this._perspective.executeAction(actions, this._baseExpression, [{ name: "value", value: this.resolveRelationId(value) }], batchId);
|
|
22465
|
-
}
|
|
22466
|
-
}
|
|
22549
|
+
await this.writeRelation(key, 'setter', value, batchId);
|
|
22467
22550
|
}
|
|
22468
22551
|
async addRelationValue(key, value, batchId) {
|
|
22469
|
-
|
|
22470
|
-
if (!metadata) {
|
|
22471
|
-
console.warn(`Relation "${key}" has no metadata, skipping`);
|
|
22472
|
-
return;
|
|
22473
|
-
}
|
|
22474
|
-
this._relationsWritten.add(metadata.predicate);
|
|
22475
|
-
const abstractName = this.abstractName();
|
|
22476
|
-
if (abstractName) {
|
|
22477
|
-
if (value != null)
|
|
22478
|
-
await this.relationThroughAbstract(abstractName, key, 'adder', value, batchId);
|
|
22479
|
-
return;
|
|
22480
|
-
}
|
|
22481
|
-
// Generate actions from metadata (replaces Prolog query)
|
|
22482
|
-
const actions = this.generateRelationAction(key, 'adder');
|
|
22483
|
-
if (value != null) {
|
|
22484
|
-
if (Array.isArray(value)) {
|
|
22485
|
-
await Promise.all(value.map((v) => this._perspective.executeAction(actions, this._baseExpression, [{ name: "value", value: this.resolveRelationId(v) }], batchId)));
|
|
22486
|
-
}
|
|
22487
|
-
else {
|
|
22488
|
-
await this._perspective.executeAction(actions, this._baseExpression, [{ name: "value", value: this.resolveRelationId(value) }], batchId);
|
|
22489
|
-
}
|
|
22490
|
-
}
|
|
22552
|
+
await this.writeRelation(key, 'adder', value, batchId);
|
|
22491
22553
|
}
|
|
22492
22554
|
async removeRelationValue(key, value, batchId) {
|
|
22493
|
-
|
|
22494
|
-
|
|
22495
|
-
|
|
22496
|
-
|
|
22497
|
-
|
|
22555
|
+
await this.writeRelation(key, 'remover', value, batchId);
|
|
22556
|
+
}
|
|
22557
|
+
/** A relation setter, adder or remover call: on a row read through an
|
|
22558
|
+
* abstract class it dispatches through the executor (see
|
|
22559
|
+
* {@link relationThroughAbstract}); otherwise its writes go out in as few
|
|
22560
|
+
* `executeAction` calls as {@link sendWrites} allows. */
|
|
22561
|
+
async writeRelation(key, kind, value, batchId) {
|
|
22562
|
+
const predicate = this.getRelationOptions(key)?.predicate;
|
|
22563
|
+
if (predicate && kind !== 'remover')
|
|
22564
|
+
this._relationsWritten.add(predicate);
|
|
22498
22565
|
const abstractName = this.abstractName();
|
|
22499
|
-
if (abstractName) {
|
|
22500
|
-
|
|
22501
|
-
await this.relationThroughAbstract(abstractName, key, 'remover', value, batchId);
|
|
22566
|
+
if (!abstractName) {
|
|
22567
|
+
await this.sendWrites(this.planRelation(key, kind, value), batchId);
|
|
22502
22568
|
return;
|
|
22503
22569
|
}
|
|
22504
|
-
|
|
22505
|
-
|
|
22506
|
-
|
|
22507
|
-
if (Array.isArray(value)) {
|
|
22508
|
-
await Promise.all(value.map((v) => this._perspective.executeAction(actions, this._baseExpression, [{ name: "value", value: this.resolveRelationId(v) }], batchId)));
|
|
22509
|
-
}
|
|
22510
|
-
else {
|
|
22511
|
-
await this._perspective.executeAction(actions, this._baseExpression, [{ name: "value", value: this.resolveRelationId(value) }], batchId);
|
|
22512
|
-
}
|
|
22570
|
+
if (!this.getRelationOptions(key)) {
|
|
22571
|
+
console.warn(`Relation "${key}" has no metadata, skipping`);
|
|
22572
|
+
return;
|
|
22513
22573
|
}
|
|
22574
|
+
if (value != null)
|
|
22575
|
+
await this.relationThroughAbstract(abstractName, key, kind, value, batchId);
|
|
22514
22576
|
}
|
|
22515
22577
|
/**
|
|
22516
22578
|
* Saves the model instance to the perspective.
|
|
@@ -22600,13 +22662,14 @@ class Ad4mModel {
|
|
|
22600
22662
|
const className = await this.perspective.stringOrTemplateObjectToSubjectClassName(this);
|
|
22601
22663
|
await this.perspective.createSubject(className, this._baseExpression, initialValues, batchId);
|
|
22602
22664
|
// Relations via innerUpdate; createSubject wrote the scalar properties.
|
|
22603
|
-
await this.
|
|
22665
|
+
const writes = await this.updateWrites(false);
|
|
22604
22666
|
for (const key of deferredExpressionProps) {
|
|
22605
22667
|
const value = this[key];
|
|
22606
22668
|
if (value !== undefined && value !== null) {
|
|
22607
|
-
await this.
|
|
22669
|
+
writes.push(...await this.planProperty(key, value));
|
|
22608
22670
|
}
|
|
22609
22671
|
}
|
|
22672
|
+
await this.sendWrites(writes, batchId);
|
|
22610
22673
|
// If we got a batchId passed in, we let the caller decide when to commit.
|
|
22611
22674
|
// We can't call getData() since the instance won't exist in the perspective
|
|
22612
22675
|
// until the batch is committed.
|
|
@@ -22668,6 +22731,11 @@ class Ad4mModel {
|
|
|
22668
22731
|
return cleanCopy;
|
|
22669
22732
|
}
|
|
22670
22733
|
async innerUpdate(setProperties = true, batchId) {
|
|
22734
|
+
await this.sendWrites(await this.updateWrites(setProperties), batchId);
|
|
22735
|
+
}
|
|
22736
|
+
/** The writes of the changed fields, in field order (see {@link sendWrites}). */
|
|
22737
|
+
async updateWrites(setProperties = true) {
|
|
22738
|
+
const writes = [];
|
|
22671
22739
|
const ctor = this.constructor;
|
|
22672
22740
|
// Determine which fields actually changed (skip unchanged when snapshot exists)
|
|
22673
22741
|
const dirty = this._snapshot ? new Set(this.changedFields()) : null;
|
|
@@ -22704,18 +22772,21 @@ class Ad4mModel {
|
|
|
22704
22772
|
}
|
|
22705
22773
|
if (value !== undefined && value !== null) {
|
|
22706
22774
|
if (value?.action) {
|
|
22775
|
+
const envelopePredicate = this.getRelationOptions(key)?.predicate;
|
|
22776
|
+
if (envelopePredicate && value.action !== "remover")
|
|
22777
|
+
this._relationsWritten.add(envelopePredicate);
|
|
22707
22778
|
switch (value.action) {
|
|
22708
22779
|
case "setter":
|
|
22709
|
-
|
|
22780
|
+
writes.push(...this.planRelation(key, 'setter', value.value));
|
|
22710
22781
|
break;
|
|
22711
22782
|
case "adder":
|
|
22712
|
-
|
|
22783
|
+
writes.push(...this.planRelation(key, 'adder', value.value));
|
|
22713
22784
|
break;
|
|
22714
22785
|
case "remover":
|
|
22715
|
-
|
|
22786
|
+
writes.push(...this.planRelation(key, 'remover', value.value));
|
|
22716
22787
|
break;
|
|
22717
22788
|
default:
|
|
22718
|
-
|
|
22789
|
+
writes.push(...this.planRelation(key, 'setter', value.value));
|
|
22719
22790
|
break;
|
|
22720
22791
|
}
|
|
22721
22792
|
}
|
|
@@ -22723,9 +22794,11 @@ class Ad4mModel {
|
|
|
22723
22794
|
// Handle all arrays as relations, including empty ones (which clears the relation).
|
|
22724
22795
|
// A record being created under an id minted here has no links to
|
|
22725
22796
|
// clear, so an empty relation there costs a round trip and writes nothing.
|
|
22726
|
-
|
|
22797
|
+
const predicate = this.getRelationOptions(key)?.predicate ?? key;
|
|
22798
|
+
if (value.length === 0 && !this._snapshot && this._idMinted && !this._relationsWritten.has(predicate))
|
|
22727
22799
|
continue;
|
|
22728
|
-
|
|
22800
|
+
this._relationsWritten.add(predicate);
|
|
22801
|
+
writes.push(...this.planRelation(key, 'setter', value));
|
|
22729
22802
|
}
|
|
22730
22803
|
else if (value !== undefined && value !== null && value !== "") {
|
|
22731
22804
|
// A scalar handed to a relation field is a single-member relation.
|
|
@@ -22754,7 +22827,8 @@ class Ad4mModel {
|
|
|
22754
22827
|
// both paths at once.
|
|
22755
22828
|
const relationMeta = this.getRelationOptions(key);
|
|
22756
22829
|
if (relationMeta) {
|
|
22757
|
-
|
|
22830
|
+
this._relationsWritten.add(relationMeta.predicate);
|
|
22831
|
+
writes.push(...this.planRelation(key, 'setter', [value]));
|
|
22758
22832
|
continue;
|
|
22759
22833
|
}
|
|
22760
22834
|
if (setProperties) {
|
|
@@ -22763,11 +22837,12 @@ class Ad4mModel {
|
|
|
22763
22837
|
if (propMeta?.flag) {
|
|
22764
22838
|
continue;
|
|
22765
22839
|
}
|
|
22766
|
-
await this.
|
|
22840
|
+
writes.push(...await this.planProperty(key, value));
|
|
22767
22841
|
}
|
|
22768
22842
|
}
|
|
22769
22843
|
}
|
|
22770
22844
|
}
|
|
22845
|
+
return writes;
|
|
22771
22846
|
}
|
|
22772
22847
|
/**
|
|
22773
22848
|
* Evaluate SPARQL getters for a batch of instances on demand.
|
|
@@ -23914,7 +23989,7 @@ let FlowTransitionProposal = class FlowTransitionProposal extends Ad4mModel {
|
|
|
23914
23989
|
this.acceptedBy = [];
|
|
23915
23990
|
// Whether this proposal settled an edge is not on the record: the
|
|
23916
23991
|
// executor keeps that per agent, outside the graph (#1424). Ask
|
|
23917
|
-
// `PerspectiveProxy.flowFired(
|
|
23992
|
+
// `PerspectiveProxy.flowFired(instances)` for the proposals your replica
|
|
23918
23993
|
// recorded as fired, or listen with `onFlowStateChanged`.
|
|
23919
23994
|
// "When was this proposal written?" is answered by `Ad4mModel`'s built-in
|
|
23920
23995
|
// `createdAt`, synthesized on hydration from the earliest link timestamp
|
|
@@ -26189,4 +26264,4 @@ const SCOPED_EVENTS = new Set([
|
|
|
26189
26264
|
"flow-state-changed",
|
|
26190
26265
|
]);
|
|
26191
26266
|
|
|
26192
|
-
export { ACCEPTED_BY_GETTER, AGENT_KIND, AGENT_KIND_BOT, AIClient, AIPromptExamples, AIPromptExamplesInput, AITask, AITaskInput, AI_RECOMMENDED_MODELS, AI_SERVER_INSTALL_LINKS, Ad4mClient, Ad4mModel, Agent, AgentClient, AgentExpression, AgentSignature, AgentStatus, Apps, AuthInfo, AuthInfoInput, AutoProcessorConfig, BelongsToMany, BelongsToOne, CALL_PROTOCOL_VERSION, Capability, CapabilityInput, ComputeLogEntry, Container, DEFAULT_ICE_SERVERS, EntanglementProof, EntanglementProofInput, ExceptionInfo, ExceptionType, Expression, ExpressionGeneric, ExpressionGenericInput, ExpressionProof, ExpressionProofInput, ExpressionRef, ExpressionRendered, Flag, FlowInstance, FlowInstanceRecord, FlowTransitionProposal, HasMany, HasOne, HostingUserInfo, IDBCache, Icon, IdentityClient, ImportResult, ImportStats, InteractionCall, InteractionMeta, InteractionParameter, InterpretationOverlay, InterpretationRun, LOCAL_INSTALL_TIMEOUT_MS, LONG_METHODS, LONG_TIMEOUT_MS, LanguageExpression, LanguageHandle, LanguageLanguageInput, LanguageMeta, LanguageMetaInput, LanguageMetaInternal, LanguageRef, Link, LinkExpression, LinkExpressionInput, LinkExpressionMutations, LinkExpressionUpdated, LinkInput, LinkMutations, LinkQuery, Literal, LiveQuery, MENTION_TEXT_LIMIT, Mentioning, MeshManager, Model, ModelQueryBuilder, Neighbourhood, NeighbourhoodExpression, NeighbourhoodProxy, Notification, NotificationInput, NullCache, OPENS_METHODS, OnlineAgent, Optional, PROPOSER_GETTER, PaymentRequestResult, Perspective, PerspectiveDiff, PerspectiveDiffExpression, PerspectiveExpression, PerspectiveHandle, PerspectiveInput, PerspectiveProxy, PerspectiveState, PerspectiveUnsignedInput, Property, QuerySubscriptionProxy, READ_METHODS, REOPEN_BASE_DELAY_MS, REOPEN_MAX_DELAY_MS, ReadOnly, Resource, ResourceInput, RpcError, RuntimeInfo, SCOPED_EVENTS, SHACLFlow, SHACLShape, SMART_LITERAL_CONTENT_PREDICATE, SentMessage, SmartLiteral, TextContent, TriggeredNotification, UserCreationResult, UserStatistics, VerificationRequestResult, WakerSubscriptionManager, agentKind, applyUpdate, buildConformanceFilter, buildModelFromJSONSchema, buildPaginationSubquery, buildSDNA, buildSHACL, buildSPARQLQuery, buildWhereCondition, capSentence,
|
|
26267
|
+
export { ACCEPTED_BY_GETTER, AGENT_KIND, AGENT_KIND_BOT, AIClient, AIPromptExamples, AIPromptExamplesInput, AITask, AITaskInput, AI_RECOMMENDED_MODELS, AI_SERVER_INSTALL_LINKS, Ad4mClient, Ad4mModel, Agent, AgentClient, AgentExpression, AgentSignature, AgentStatus, Apps, AuthInfo, AuthInfoInput, AutoProcessorConfig, BelongsToMany, BelongsToOne, CALL_PROTOCOL_VERSION, Capability, CapabilityInput, ComputeLogEntry, Container, DEFAULT_ICE_SERVERS, EntanglementProof, EntanglementProofInput, ExceptionInfo, ExceptionType, Expression, ExpressionGeneric, ExpressionGenericInput, ExpressionProof, ExpressionProofInput, ExpressionRef, ExpressionRendered, Flag, FlowInstance, FlowInstanceRecord, FlowTransitionProposal, HasMany, HasOne, HostingUserInfo, IDBCache, Icon, IdentityClient, ImportResult, ImportStats, InteractionCall, InteractionMeta, InteractionParameter, InterpretationOverlay, InterpretationRun, LOCAL_INSTALL_TIMEOUT_MS, LONG_METHODS, LONG_TIMEOUT_MS, LanguageExpression, LanguageHandle, LanguageLanguageInput, LanguageMeta, LanguageMetaInput, LanguageMetaInternal, LanguageRef, Link, LinkExpression, LinkExpressionInput, LinkExpressionMutations, LinkExpressionUpdated, LinkInput, LinkMutations, LinkQuery, Literal, LiveQuery, MENTION_TEXT_LIMIT, Mentioning, MeshManager, Model, ModelQueryBuilder, Neighbourhood, NeighbourhoodExpression, NeighbourhoodProxy, Notification, NotificationInput, NullCache, OPENS_METHODS, OnlineAgent, Optional, PROPOSER_GETTER, PaymentRequestResult, Perspective, PerspectiveDiff, PerspectiveDiffExpression, PerspectiveExpression, PerspectiveHandle, PerspectiveInput, PerspectiveProxy, PerspectiveState, PerspectiveUnsignedInput, Property, QuerySubscriptionProxy, READ_METHODS, REOPEN_BASE_DELAY_MS, REOPEN_MAX_DELAY_MS, ReadOnly, Resource, ResourceInput, RpcError, RuntimeInfo, SCOPED_EVENTS, SHACLFlow, SHACLShape, SMART_LITERAL_CONTENT_PREDICATE, SentMessage, SmartLiteral, TextContent, TriggeredNotification, UserCreationResult, UserStatistics, VerificationRequestResult, WakerSubscriptionManager, agentKind, applyUpdate, buildConformanceFilter, buildModelFromJSONSchema, buildPaginationSubquery, buildSDNA, buildSHACL, buildSPARQLQuery, buildWhereCondition, capSentence, coalesce, compileWhereClause, concat, createPersistentCache, createTelepresenceChannel, determineNamespace, determinePredicate, effectiveLiteralStorage, escapeQueryString, exists, exprRef2String, fileToDataUri, fn, focus, formatList, formatQueryValue, formatSPARQLValue, getDefaultValueForType, getMemoizedSHACL, getPropertiesMetadata, getPropertyOption, getRelationsMetadata, hasJsOnlyWhereFilters, hintFor, holdsAWholeWordTerm, ifExpr, isArrayType, isBot, isContainedScope, isContainmentTraversal, isExpression, isIncludeProjection, isLink, isNodeExpression, isNumericType, isObjectType, isSchemaType, isTraverseScope, linkEqual, linkExpressionInputToWire, linkExpressionToWire, linkMutationsToWire, literal, looksLikeUri, mentionOf, neighbourhoodExpressionFromWire, normalizeNamespaceString, normalizeSchemaType, normalizeValue, normalizeWhereForSparql, parseCallMessage, parseExprUrl, parseLit, parseLitBoolean, parseLitNumber, parseSparqlCount, path, reopenDelay, requireSingleParent, requireTotalCount, resolveParentPredicate, setPropertyRegistryEntry, setRelationRegistryEntry, typeDefsString, valueToLiteralIri };
|