@powerhousedao/reactor 6.2.3-dev.24 → 6.2.3-dev.25
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/dist/{build-worker-executor-DxmDJ4QQ.js → build-worker-executor-DPGjh9Uc.js} +4 -4
- package/dist/{build-worker-executor-DxmDJ4QQ.js.map → build-worker-executor-DPGjh9Uc.js.map} +1 -1
- package/dist/{document-indexer-Dn9RB0sg.js → document-indexer-zbdzqZ3K.js} +18 -9
- package/dist/{document-indexer-Dn9RB0sg.js.map → document-indexer-zbdzqZ3K.js.map} +1 -1
- package/dist/entry.d.ts +2 -1
- package/dist/entry.js +2 -3
- package/dist/entry.js.map +1 -1
- package/dist/{errors-D3S6Eysd.js → errors-BM_ULVWd.js} +9 -1
- package/dist/{errors-D3S6Eysd.js.map → errors-BM_ULVWd.js.map} +1 -1
- package/dist/{drive-container-types-Be5-EY9W.js → forwarding-logger-CSsCJ38f.js} +247 -39
- package/dist/forwarding-logger-CSsCJ38f.js.map +1 -0
- package/dist/index.d.ts +359 -235
- package/dist/index.d.ts.map +1 -1
- package/dist/index.js +247 -171
- package/dist/index.js.map +1 -1
- package/dist/projection-entry.d.ts +2 -1
- package/dist/projection-entry.js +7 -13
- package/dist/projection-entry.js.map +1 -1
- package/dist/{projection-shard-manager-mQhfVipO.js → projection-shard-manager-B-j8VYzA.js} +2 -3
- package/dist/{projection-shard-manager-mQhfVipO.js.map → projection-shard-manager-B-j8VYzA.js.map} +1 -1
- package/dist/{projection-worker-wI4PwcV2.js → projection-worker-D8uNFdwX.js} +1 -1
- package/dist/{projection-worker-wI4PwcV2.js.map → projection-worker-D8uNFdwX.js.map} +1 -1
- package/dist/{transport-CuogVKN_.js → transport-B3G50KVd.js} +1 -1
- package/dist/{transport-CuogVKN_.js.map → transport-B3G50KVd.js.map} +1 -1
- package/dist/{transport-ByGviWdZ.js → transport-CZDHzfvy.js} +1 -1
- package/dist/{transport-ByGviWdZ.js.map → transport-CZDHzfvy.js.map} +1 -1
- package/dist/{worker-handle-B3p-nuqG.js → worker-handle-CwWNTpUg.js} +9 -8
- package/dist/{worker-handle-B3p-nuqG.js.map → worker-handle-CwWNTpUg.js.map} +1 -1
- package/package.json +5 -5
- package/dist/drive-container-types-Be5-EY9W.js.map +0 -1
- package/dist/error-info-Cpu4OY3o.js +0 -62
- package/dist/error-info-Cpu4OY3o.js.map +0 -1
- package/dist/forwarding-logger-BBkMSxuJ.js +0 -85
- package/dist/forwarding-logger-BBkMSxuJ.js.map +0 -1
- package/dist/types-DxDCmtId.js +0 -34
- package/dist/types-DxDCmtId.js.map +0 -1
- package/dist/worker-BDVzCtuf.js +0 -22
- package/dist/worker-BDVzCtuf.js.map +0 -1
|
@@ -1,4 +1,3 @@
|
|
|
1
|
-
import { n as ReactorEventTypes, t as EventBusAggregateError } from "./types-DxDCmtId.js";
|
|
2
1
|
import { AUTH_ACTION_TYPES, AUTH_DENIED_BY_GRANT_REASON, AUTH_NO_GRANT_REASON, AUTH_VERSION_UNSUPPORTED_REASON, DOCUMENT_DELETED_REASON, DOCUMENT_SCOPE_ACTION_TYPES, DowngradeNotSupportedError as DowngradeNotSupportedError$1, actionSignerIdentity, actionSigningTarget, appendWithoutApplying, applyAuthAction, applyDeleteDocumentAction, applyDeleteDocumentAction as applyDeleteDocumentAction$1, applyUpgradeDocumentAction, applyUpgradeDocumentAction as applyUpgradeDocumentAction$1, base58Decode, baseReducerVersion, buildOperationSignatureMessage, buildOperationSignatureParams, canonicalJson, createPresignedHeader, decide, defaultBaseState, deriveDocumentId, deriveOperationId, evaluate, garbageCollect, groupDocumentType, groupMembershipActionTypes, hashActionV2, hashBrowser, hashDocumentStateForScope, isDenied, isDerivedDocumentId, isUndoRedo, isV2ActionHash, mentionedGroupIds, normalizeDocumentModelVersion, operationOutcome, referencedGroupIds, signaturePolicyOf, sortOperations, targetDocumentId, v2TupleProblem, withProtocolVersions } from "@powerhousedao/shared/document-model";
|
|
3
2
|
import { v4 } from "uuid";
|
|
4
3
|
import { Migrator, sql } from "kysely";
|
|
@@ -52,6 +51,37 @@ function parsePagingOptions(paging, defaultLimit) {
|
|
|
52
51
|
};
|
|
53
52
|
}
|
|
54
53
|
//#endregion
|
|
54
|
+
//#region src/events/types.ts
|
|
55
|
+
/**
|
|
56
|
+
* Custom error class that aggregates multiple errors from event subscribers.
|
|
57
|
+
*/
|
|
58
|
+
var EventBusAggregateError = class extends Error {
|
|
59
|
+
errors;
|
|
60
|
+
constructor(errors) {
|
|
61
|
+
const message = `EventBus emit failed with ${errors.length} error(s): ${errors.map((e) => {
|
|
62
|
+
if (e && typeof e === "object" && "message" in e) return e.message;
|
|
63
|
+
return String(e);
|
|
64
|
+
}).join("; ")}`;
|
|
65
|
+
super(message);
|
|
66
|
+
this.name = "EventBusAggregateError";
|
|
67
|
+
this.errors = errors;
|
|
68
|
+
}
|
|
69
|
+
};
|
|
70
|
+
/**
|
|
71
|
+
* Event types for reactor lifecycle events.
|
|
72
|
+
*/
|
|
73
|
+
const ReactorEventTypes = {
|
|
74
|
+
JOB_PENDING: 10001,
|
|
75
|
+
JOB_RUNNING: 10002,
|
|
76
|
+
JOB_WRITE_READY: 10003,
|
|
77
|
+
JOB_READ_READY: 10004,
|
|
78
|
+
JOB_FAILED: 10005,
|
|
79
|
+
READMODEL_BATCH_COMPLETED: 10006,
|
|
80
|
+
READMODEL_INDEXED: 10007,
|
|
81
|
+
MODEL_LOADED: 10008,
|
|
82
|
+
SIGNATURE_REFUSED: 10009
|
|
83
|
+
};
|
|
84
|
+
//#endregion
|
|
55
85
|
//#region src/shared/errors.ts
|
|
56
86
|
/**
|
|
57
87
|
* Error thrown when attempting to access a deleted document.
|
|
@@ -329,6 +359,7 @@ const APPEND_CONDITION_FAILED_PREFIX = "Append condition failed: ";
|
|
|
329
359
|
* conflict, not a fault: the caller retries against the new stream heads.
|
|
330
360
|
*/
|
|
331
361
|
var AppendConditionFailedError = class extends Error {
|
|
362
|
+
condition;
|
|
332
363
|
constructor(condition) {
|
|
333
364
|
const streams = condition.streams.map((s) => `${s.documentId}:${s.scope}:${s.branch}@${s.revision}`).join(", ");
|
|
334
365
|
super(`${APPEND_CONDITION_FAILED_PREFIX}a read-set stream advanced [${streams}]`);
|
|
@@ -1033,6 +1064,7 @@ const JobExecutorEventTypes = {
|
|
|
1033
1064
|
//#endregion
|
|
1034
1065
|
//#region src/cache/collection-membership-cache.ts
|
|
1035
1066
|
var CollectionMembershipCache = class CollectionMembershipCache {
|
|
1067
|
+
operationIndex;
|
|
1036
1068
|
cache = /* @__PURE__ */ new Map();
|
|
1037
1069
|
constructor(operationIndex) {
|
|
1038
1070
|
this.operationIndex = operationIndex;
|
|
@@ -1328,6 +1360,7 @@ var KyselyOperationIndexTxn = class {
|
|
|
1328
1360
|
}
|
|
1329
1361
|
};
|
|
1330
1362
|
var KyselyOperationIndex = class KyselyOperationIndex {
|
|
1363
|
+
db;
|
|
1331
1364
|
trx;
|
|
1332
1365
|
constructor(db) {
|
|
1333
1366
|
this.db = db;
|
|
@@ -1667,21 +1700,6 @@ var RingBuffer = class {
|
|
|
1667
1700
|
}
|
|
1668
1701
|
};
|
|
1669
1702
|
//#endregion
|
|
1670
|
-
//#region src/cache/write-cache-types.ts
|
|
1671
|
-
/**
|
|
1672
|
-
* Where a snapshot sits in its stream.
|
|
1673
|
-
*
|
|
1674
|
-
* - `Head`: the newest revision of the stream when it was stored. Only these
|
|
1675
|
-
* can answer a read that asks for the head.
|
|
1676
|
-
* - `Historical`: state at an earlier revision. Usable as a starting point to
|
|
1677
|
-
* replay forward from, and as an answer to a read for that same revision.
|
|
1678
|
-
*/
|
|
1679
|
-
let SnapshotPosition = /* @__PURE__ */ function(SnapshotPosition) {
|
|
1680
|
-
SnapshotPosition["Head"] = "head";
|
|
1681
|
-
SnapshotPosition["Historical"] = "historical";
|
|
1682
|
-
return SnapshotPosition;
|
|
1683
|
-
}({});
|
|
1684
|
-
//#endregion
|
|
1685
1703
|
//#region src/cache/kysely-write-cache.ts
|
|
1686
1704
|
/**
|
|
1687
1705
|
* The last operation index a keyframe's document reflects for the scope. A
|
|
@@ -1820,13 +1838,13 @@ var KyselyWriteCache = class KyselyWriteCache {
|
|
|
1820
1838
|
const snapshots = stream.ringBuffer.getAll();
|
|
1821
1839
|
if (targetRevision === void 0) {
|
|
1822
1840
|
const newest = highestRevision(snapshots);
|
|
1823
|
-
if (newest?.position ===
|
|
1841
|
+
if (newest?.position === "head") {
|
|
1824
1842
|
this.lruTracker.touch(streamKey);
|
|
1825
1843
|
return copyDocument(newest.document);
|
|
1826
1844
|
}
|
|
1827
1845
|
if (newest) {
|
|
1828
1846
|
const document = await this.warmMissRebuild(newest.document, newest.revision, documentId, scope, branch, void 0, signal);
|
|
1829
|
-
this.store(documentId, scope, branch, (document.header.revision[scope] ?? 0) - 1, document,
|
|
1847
|
+
this.store(documentId, scope, branch, (document.header.revision[scope] ?? 0) - 1, document, "head");
|
|
1830
1848
|
this.lruTracker.touch(streamKey);
|
|
1831
1849
|
return document;
|
|
1832
1850
|
}
|
|
@@ -1839,7 +1857,7 @@ var KyselyWriteCache = class KyselyWriteCache {
|
|
|
1839
1857
|
const newestOlder = this.findNearestOlderSnapshot(snapshots, targetRevision);
|
|
1840
1858
|
if (newestOlder) {
|
|
1841
1859
|
const document = await this.warmMissRebuild(newestOlder.document, newestOlder.revision, documentId, scope, branch, targetRevision, signal);
|
|
1842
|
-
this.store(documentId, scope, branch, targetRevision, document,
|
|
1860
|
+
this.store(documentId, scope, branch, targetRevision, document, "historical");
|
|
1843
1861
|
this.lruTracker.touch(streamKey);
|
|
1844
1862
|
return document;
|
|
1845
1863
|
}
|
|
@@ -1847,7 +1865,7 @@ var KyselyWriteCache = class KyselyWriteCache {
|
|
|
1847
1865
|
}
|
|
1848
1866
|
const document = await this.coldMissRebuild(documentId, scope, branch, targetRevision, signal);
|
|
1849
1867
|
const revision = targetRevision ?? (document.header.revision[scope] ?? 0) - 1;
|
|
1850
|
-
this.store(documentId, scope, branch, revision, document, targetRevision === void 0 ?
|
|
1868
|
+
this.store(documentId, scope, branch, revision, document, targetRevision === void 0 ? "head" : "historical");
|
|
1851
1869
|
return document;
|
|
1852
1870
|
}
|
|
1853
1871
|
/**
|
|
@@ -1882,7 +1900,7 @@ var KyselyWriteCache = class KyselyWriteCache {
|
|
|
1882
1900
|
if (run.length === 0) return;
|
|
1883
1901
|
for (const entry of run.slice(0, -1)) this.persistKeyframe(documentId, scope, branch, entry.revision, entry.document);
|
|
1884
1902
|
const head = run[run.length - 1];
|
|
1885
|
-
this.store(documentId, scope, branch, head.revision, head.document,
|
|
1903
|
+
this.store(documentId, scope, branch, head.revision, head.document, "head");
|
|
1886
1904
|
}
|
|
1887
1905
|
store(documentId, scope, branch, revision, document, position) {
|
|
1888
1906
|
const streamKey = this.makeStreamKey(documentId, scope, branch);
|
|
@@ -2401,6 +2419,11 @@ function validateFeatureFlags(flags, prerequisites) {
|
|
|
2401
2419
|
//#endregion
|
|
2402
2420
|
//#region src/executor/execution-scope.ts
|
|
2403
2421
|
var DefaultExecutionScope = class {
|
|
2422
|
+
operationStore;
|
|
2423
|
+
operationIndex;
|
|
2424
|
+
writeCache;
|
|
2425
|
+
documentMetaCache;
|
|
2426
|
+
collectionMembershipCache;
|
|
2404
2427
|
constructor(operationStore, operationIndex, writeCache, documentMetaCache, collectionMembershipCache) {
|
|
2405
2428
|
this.operationStore = operationStore;
|
|
2406
2429
|
this.operationIndex = operationIndex;
|
|
@@ -2420,6 +2443,13 @@ var DefaultExecutionScope = class {
|
|
|
2420
2443
|
}
|
|
2421
2444
|
};
|
|
2422
2445
|
var KyselyExecutionScope = class {
|
|
2446
|
+
db;
|
|
2447
|
+
operationStore;
|
|
2448
|
+
operationIndex;
|
|
2449
|
+
keyframeStore;
|
|
2450
|
+
writeCache;
|
|
2451
|
+
documentMetaCache;
|
|
2452
|
+
collectionMembershipCache;
|
|
2423
2453
|
constructor(db, operationStore, operationIndex, keyframeStore, writeCache, documentMetaCache, collectionMembershipCache) {
|
|
2424
2454
|
this.db = db;
|
|
2425
2455
|
this.operationStore = operationStore;
|
|
@@ -2447,7 +2477,7 @@ var KyselyExecutionScope = class {
|
|
|
2447
2477
|
};
|
|
2448
2478
|
//#endregion
|
|
2449
2479
|
//#region src/utils/reshuffle.ts
|
|
2450
|
-
const STRICT_ORDER_ACTION_TYPES = new Set([
|
|
2480
|
+
const STRICT_ORDER_ACTION_TYPES = /* @__PURE__ */ new Set([
|
|
2451
2481
|
"CREATE_DOCUMENT",
|
|
2452
2482
|
"DELETE_DOCUMENT",
|
|
2453
2483
|
"UPGRADE_DOCUMENT",
|
|
@@ -2778,6 +2808,8 @@ const DRIVE_COLLECTION_PREFIX = "drive.";
|
|
|
2778
2808
|
* rows and persisted remotes remain valid without migration.
|
|
2779
2809
|
*/
|
|
2780
2810
|
var DriveCollectionId = class DriveCollectionId {
|
|
2811
|
+
driveId;
|
|
2812
|
+
branch;
|
|
2781
2813
|
constructor(driveId, branch) {
|
|
2782
2814
|
this.driveId = driveId;
|
|
2783
2815
|
this.branch = branch;
|
|
@@ -2810,6 +2842,11 @@ var DriveCollectionId = class DriveCollectionId {
|
|
|
2810
2842
|
//#endregion
|
|
2811
2843
|
//#region src/executor/document-action-handler.ts
|
|
2812
2844
|
var DocumentActionHandler = class {
|
|
2845
|
+
registry;
|
|
2846
|
+
logger;
|
|
2847
|
+
driveContainerTypes;
|
|
2848
|
+
featureFlags;
|
|
2849
|
+
decisionModel;
|
|
2813
2850
|
constructor(registry, logger, driveContainerTypes, featureFlags, decisionModel) {
|
|
2814
2851
|
this.registry = registry;
|
|
2815
2852
|
this.logger = logger;
|
|
@@ -2902,7 +2939,7 @@ var DocumentActionHandler = class {
|
|
|
2902
2939
|
[job.scope]: [...standing.operations[job.scope] ?? [], operation]
|
|
2903
2940
|
};
|
|
2904
2941
|
executing.touchedStreams.add(job.documentId, job.scope, job.branch);
|
|
2905
|
-
stores.writeCache.putState(job.documentId, job.scope, job.branch, operation.index, standing,
|
|
2942
|
+
stores.writeCache.putState(job.documentId, job.scope, job.branch, operation.index, standing, "head");
|
|
2906
2943
|
indexTxn.write([{
|
|
2907
2944
|
...operation,
|
|
2908
2945
|
documentId: job.documentId,
|
|
@@ -2956,7 +2993,7 @@ var DocumentActionHandler = class {
|
|
|
2956
2993
|
[job.scope]: [...document.operations[job.scope] ?? [], operation]
|
|
2957
2994
|
};
|
|
2958
2995
|
executing.touchedStreams.add(document.header.id, job.scope, job.branch);
|
|
2959
|
-
stores.writeCache.putState(document.header.id, job.scope, job.branch, operation.index, document,
|
|
2996
|
+
stores.writeCache.putState(document.header.id, job.scope, job.branch, operation.index, document, "head");
|
|
2960
2997
|
indexTxn.write([{
|
|
2961
2998
|
...operation,
|
|
2962
2999
|
documentId: document.header.id,
|
|
@@ -3017,7 +3054,7 @@ var DocumentActionHandler = class {
|
|
|
3017
3054
|
[job.scope]: [...document.operations[job.scope] ?? [], operation]
|
|
3018
3055
|
};
|
|
3019
3056
|
executing.touchedStreams.add(documentId, job.scope, job.branch);
|
|
3020
|
-
stores.writeCache.putState(documentId, job.scope, job.branch, operation.index, document,
|
|
3057
|
+
stores.writeCache.putState(documentId, job.scope, job.branch, operation.index, document, "head");
|
|
3021
3058
|
indexTxn.write([{
|
|
3022
3059
|
...operation,
|
|
3023
3060
|
documentId,
|
|
@@ -3068,7 +3105,7 @@ var DocumentActionHandler = class {
|
|
|
3068
3105
|
} catch (error) {
|
|
3069
3106
|
return buildErrorResult(job, /* @__PURE__ */ new Error(`Failed to fetch revisions for upgrade: ${error instanceof Error ? error.message : String(error)}`), startTime);
|
|
3070
3107
|
}
|
|
3071
|
-
const revisionScopes = new Set([...Object.keys(input.revision), ...Object.keys(actualRevisions)]);
|
|
3108
|
+
const revisionScopes = /* @__PURE__ */ new Set([...Object.keys(input.revision), ...Object.keys(actualRevisions)]);
|
|
3072
3109
|
for (const revisionScope of revisionScopes) {
|
|
3073
3110
|
const snapshot = input.revision[revisionScope] ?? 0;
|
|
3074
3111
|
const actual = actualRevisions[revisionScope] ?? 0;
|
|
@@ -3129,7 +3166,7 @@ var DocumentActionHandler = class {
|
|
|
3129
3166
|
[job.scope]: [...document.operations[job.scope] ?? [], operation]
|
|
3130
3167
|
};
|
|
3131
3168
|
executing.touchedStreams.add(documentId, job.scope, job.branch);
|
|
3132
|
-
stores.writeCache.putState(documentId, job.scope, job.branch, operation.index, document,
|
|
3169
|
+
stores.writeCache.putState(documentId, job.scope, job.branch, operation.index, document, "head");
|
|
3133
3170
|
for (const scope of otherScopes) executing.postCommitInvalidations.push({
|
|
3134
3171
|
documentId,
|
|
3135
3172
|
scope,
|
|
@@ -3216,7 +3253,7 @@ var DocumentActionHandler = class {
|
|
|
3216
3253
|
const resultingState = JSON.stringify(resultingStateObj);
|
|
3217
3254
|
executing.touchedStreams.add(input.sourceId, job.scope, job.branch);
|
|
3218
3255
|
executing.touchedStreams.add(input.targetId, job.scope, job.branch);
|
|
3219
|
-
stores.writeCache.putState(input.sourceId, job.scope, job.branch, operation.index, sourceDoc,
|
|
3256
|
+
stores.writeCache.putState(input.sourceId, job.scope, job.branch, operation.index, sourceDoc, "head");
|
|
3220
3257
|
indexTxn.write([{
|
|
3221
3258
|
...operation,
|
|
3222
3259
|
documentId: input.sourceId,
|
|
@@ -3272,7 +3309,7 @@ var DocumentActionHandler = class {
|
|
|
3272
3309
|
var PassthroughSigner = class {
|
|
3273
3310
|
publicKey = {};
|
|
3274
3311
|
sign() {
|
|
3275
|
-
return Promise.resolve(new Uint8Array(0));
|
|
3312
|
+
return Promise.resolve(/* @__PURE__ */ new Uint8Array(0));
|
|
3276
3313
|
}
|
|
3277
3314
|
verify() {
|
|
3278
3315
|
return Promise.resolve();
|
|
@@ -3360,7 +3397,7 @@ function decompressP256(compressed, did) {
|
|
|
3360
3397
|
let y = modPow(ySquared, (P + BigInt(1)) / BigInt(4), P);
|
|
3361
3398
|
if (y * y % P !== ySquared) throw new MalformedDidKeyError(did, "x is not on the curve");
|
|
3362
3399
|
if (y % BigInt(2) === BigInt(0) !== (prefix === 2)) y = P - y;
|
|
3363
|
-
const uncompressed = new Uint8Array(65);
|
|
3400
|
+
const uncompressed = /* @__PURE__ */ new Uint8Array(65);
|
|
3364
3401
|
uncompressed[0] = 4;
|
|
3365
3402
|
uncompressed.set(bigIntToBytes(x), 1);
|
|
3366
3403
|
uncompressed.set(bigIntToBytes(y), 33);
|
|
@@ -3378,7 +3415,7 @@ function modPow(base, exp, mod) {
|
|
|
3378
3415
|
return result;
|
|
3379
3416
|
}
|
|
3380
3417
|
function bigIntToBytes(value) {
|
|
3381
|
-
const bytes = new Uint8Array(32);
|
|
3418
|
+
const bytes = /* @__PURE__ */ new Uint8Array(32);
|
|
3382
3419
|
let v = value;
|
|
3383
3420
|
for (let i = 31; i >= 0; i--) {
|
|
3384
3421
|
bytes[i] = Number(v & BigInt(255));
|
|
@@ -3582,7 +3619,7 @@ function bytesToBase64(bytes) {
|
|
|
3582
3619
|
//#endregion
|
|
3583
3620
|
//#region src/executor/synthesized-signing.ts
|
|
3584
3621
|
/** Submitted types whose stored action the reducer writes in their place. */
|
|
3585
|
-
const SYNTHESIZING_TYPES = new Set(["UNDO", "REDO"]);
|
|
3622
|
+
const SYNTHESIZING_TYPES = /* @__PURE__ */ new Set(["UNDO", "REDO"]);
|
|
3586
3623
|
/**
|
|
3587
3624
|
* The id of the action synthesized from `submittedId`. Derived, so the stored
|
|
3588
3625
|
* operation answers for the submitted id at the live-id check.
|
|
@@ -3638,6 +3675,10 @@ async function signSynthesized(operation, submitted, target, signer, signal) {
|
|
|
3638
3675
|
const DEFAULT_TRUST_TIMEOUT_MS = 1e4;
|
|
3639
3676
|
/** Runs once per write, when this reactor first stores it; never on re-appends. */
|
|
3640
3677
|
var SignatureAdmission = class {
|
|
3678
|
+
mode;
|
|
3679
|
+
logger;
|
|
3680
|
+
eventBus;
|
|
3681
|
+
policySource;
|
|
3641
3682
|
trustPolicy;
|
|
3642
3683
|
trustTimeoutMs;
|
|
3643
3684
|
constructor(mode, logger, eventBus, policySource = "meta", trust = {
|
|
@@ -3823,8 +3864,12 @@ async function resolvePolicies(candidates, jobActions, stored) {
|
|
|
3823
3864
|
}
|
|
3824
3865
|
async function storedPolicy(stores, source, documentId, branch, signal) {
|
|
3825
3866
|
try {
|
|
3826
|
-
if (source === "write-cache")
|
|
3827
|
-
|
|
3867
|
+
if (source === "write-cache") {
|
|
3868
|
+
const document = await stores.writeCache.getState(documentId, "document", branch, void 0, signal);
|
|
3869
|
+
return signaturePolicyOf(document.header);
|
|
3870
|
+
}
|
|
3871
|
+
const meta = await stores.documentMetaCache.getDocumentMeta(documentId, branch, signal);
|
|
3872
|
+
return signaturePolicyOf(meta.protocolVersions);
|
|
3828
3873
|
} catch (error) {
|
|
3829
3874
|
if (DocumentNotFoundError.isError(error)) return;
|
|
3830
3875
|
throw error;
|
|
@@ -3899,6 +3944,7 @@ function isValidISOTimestamp(value) {
|
|
|
3899
3944
|
* every test expect a failed job to look like.
|
|
3900
3945
|
*/
|
|
3901
3946
|
var JobRollbackSignal = class extends Error {
|
|
3947
|
+
result;
|
|
3902
3948
|
constructor(result) {
|
|
3903
3949
|
super("job rolled back");
|
|
3904
3950
|
this.result = result;
|
|
@@ -3906,6 +3952,15 @@ var JobRollbackSignal = class extends Error {
|
|
|
3906
3952
|
}
|
|
3907
3953
|
};
|
|
3908
3954
|
var SimpleJobExecutor = class {
|
|
3955
|
+
logger;
|
|
3956
|
+
registry;
|
|
3957
|
+
operationStore;
|
|
3958
|
+
eventBus;
|
|
3959
|
+
writeCache;
|
|
3960
|
+
operationIndex;
|
|
3961
|
+
documentMetaCache;
|
|
3962
|
+
collectionMembershipCache;
|
|
3963
|
+
driveContainerTypes;
|
|
3909
3964
|
config;
|
|
3910
3965
|
featureFlags;
|
|
3911
3966
|
decisionModel;
|
|
@@ -5238,6 +5293,7 @@ var DocumentModelRegistry = class {
|
|
|
5238
5293
|
//#endregion
|
|
5239
5294
|
//#region src/storage/kysely/keyframe-store.ts
|
|
5240
5295
|
var KyselyKeyframeStore = class KyselyKeyframeStore {
|
|
5296
|
+
db;
|
|
5241
5297
|
trx;
|
|
5242
5298
|
constructor(db) {
|
|
5243
5299
|
this.db = db;
|
|
@@ -5322,6 +5378,11 @@ function paginateRows(rows, paging, cursorOf, toItem, refetch) {
|
|
|
5322
5378
|
//#endregion
|
|
5323
5379
|
//#region src/storage/txn.ts
|
|
5324
5380
|
var AtomicTransaction = class {
|
|
5381
|
+
documentId;
|
|
5382
|
+
documentType;
|
|
5383
|
+
scope;
|
|
5384
|
+
branch;
|
|
5385
|
+
baseRevision;
|
|
5325
5386
|
operations = [];
|
|
5326
5387
|
constructor(documentId, documentType, scope, branch, baseRevision) {
|
|
5327
5388
|
this.documentId = documentId;
|
|
@@ -5355,6 +5416,11 @@ var AtomicTransaction = class {
|
|
|
5355
5416
|
//#endregion
|
|
5356
5417
|
//#region src/storage/kysely/store.ts
|
|
5357
5418
|
var _UniqueConstraintContext = class extends Error {
|
|
5419
|
+
documentId;
|
|
5420
|
+
scope;
|
|
5421
|
+
branch;
|
|
5422
|
+
revision;
|
|
5423
|
+
stagedOps;
|
|
5358
5424
|
constructor(documentId, scope, branch, revision, stagedOps) {
|
|
5359
5425
|
super("unique constraint");
|
|
5360
5426
|
this.documentId = documentId;
|
|
@@ -5366,6 +5432,7 @@ var _UniqueConstraintContext = class extends Error {
|
|
|
5366
5432
|
}
|
|
5367
5433
|
};
|
|
5368
5434
|
var KyselyOperationStore = class KyselyOperationStore {
|
|
5435
|
+
db;
|
|
5369
5436
|
trx;
|
|
5370
5437
|
constructor(db) {
|
|
5371
5438
|
this.db = db;
|
|
@@ -5465,12 +5532,13 @@ var KyselyOperationStore = class KyselyOperationStore {
|
|
|
5465
5532
|
* otherwise read a snapshot taken before the locks were held.
|
|
5466
5533
|
*/
|
|
5467
5534
|
async acquireStreamLocks(trx, documentId, scope, branch, condition) {
|
|
5468
|
-
const keys = new Set([`${documentId}:${scope}:${branch}`]);
|
|
5535
|
+
const keys = /* @__PURE__ */ new Set([`${documentId}:${scope}:${branch}`]);
|
|
5469
5536
|
for (const stream of condition.streams) keys.add(`${stream.documentId}:${stream.scope}:${stream.branch}`);
|
|
5537
|
+
const sortedKeys = sql.join([...keys].sort());
|
|
5470
5538
|
await sql`
|
|
5471
5539
|
with ordered as materialized (
|
|
5472
5540
|
select key
|
|
5473
|
-
from unnest(array[${
|
|
5541
|
+
from unnest(array[${sortedKeys}]::text[]) with ordinality as t(key, ord)
|
|
5474
5542
|
order by ord
|
|
5475
5543
|
)
|
|
5476
5544
|
select pg_advisory_xact_lock(hashtext(key)) from ordered
|
|
@@ -6109,8 +6177,148 @@ async function getMigrationStatus(db, schema = REACTOR_SCHEMA) {
|
|
|
6109
6177
|
}
|
|
6110
6178
|
//#endregion
|
|
6111
6179
|
//#region src/core/drive-container-types.ts
|
|
6112
|
-
const DEFAULT_DRIVE_CONTAINER_TYPES = new Set(["powerhouse/document-drive", "powerhouse/reactor-drive"]);
|
|
6180
|
+
const DEFAULT_DRIVE_CONTAINER_TYPES = /* @__PURE__ */ new Set(["powerhouse/document-drive", "powerhouse/reactor-drive"]);
|
|
6181
|
+
//#endregion
|
|
6182
|
+
//#region src/executor/worker/error-info.ts
|
|
6183
|
+
const MAX_STACK_LENGTH = 8192;
|
|
6184
|
+
const MAX_CAUSE_DEPTH = 8;
|
|
6185
|
+
function toErrorInfo(err, depth = 0) {
|
|
6186
|
+
if (depth > MAX_CAUSE_DEPTH) return {
|
|
6187
|
+
name: "Error",
|
|
6188
|
+
message: "cause chain truncated"
|
|
6189
|
+
};
|
|
6190
|
+
if (err instanceof Error) {
|
|
6191
|
+
const info = {
|
|
6192
|
+
name: err.name || "Error",
|
|
6193
|
+
message: err.message
|
|
6194
|
+
};
|
|
6195
|
+
if (typeof err.stack === "string") info.stack = err.stack.length > MAX_STACK_LENGTH ? err.stack.slice(0, MAX_STACK_LENGTH) : err.stack;
|
|
6196
|
+
if (err.cause !== void 0) info.cause = toErrorInfo(err.cause, depth + 1);
|
|
6197
|
+
return info;
|
|
6198
|
+
}
|
|
6199
|
+
if (typeof err === "string") return {
|
|
6200
|
+
name: "Error",
|
|
6201
|
+
message: err
|
|
6202
|
+
};
|
|
6203
|
+
if (err && typeof err === "object") {
|
|
6204
|
+
const record = err;
|
|
6205
|
+
return {
|
|
6206
|
+
name: typeof record.name === "string" ? record.name : "Error",
|
|
6207
|
+
message: typeof record.message === "string" ? record.message : safeStringify(err)
|
|
6208
|
+
};
|
|
6209
|
+
}
|
|
6210
|
+
return {
|
|
6211
|
+
name: "Error",
|
|
6212
|
+
message: safeStringify(err)
|
|
6213
|
+
};
|
|
6214
|
+
}
|
|
6215
|
+
function safeStringify(value) {
|
|
6216
|
+
if (value === null || value === void 0) return String(value);
|
|
6217
|
+
if (typeof value === "string") return value;
|
|
6218
|
+
if (typeof value === "number" || typeof value === "boolean") return String(value);
|
|
6219
|
+
try {
|
|
6220
|
+
return JSON.stringify(value);
|
|
6221
|
+
} catch {
|
|
6222
|
+
return "[unserializable]";
|
|
6223
|
+
}
|
|
6224
|
+
}
|
|
6225
|
+
function fromErrorInfo(info) {
|
|
6226
|
+
const err = new Error(info.message);
|
|
6227
|
+
Object.defineProperty(err, "name", {
|
|
6228
|
+
value: info.name,
|
|
6229
|
+
configurable: true,
|
|
6230
|
+
writable: true
|
|
6231
|
+
});
|
|
6232
|
+
if (info.stack !== void 0) err.stack = info.stack;
|
|
6233
|
+
if (info.cause !== void 0) Object.defineProperty(err, "cause", {
|
|
6234
|
+
value: fromErrorInfo(info.cause),
|
|
6235
|
+
configurable: true,
|
|
6236
|
+
writable: true
|
|
6237
|
+
});
|
|
6238
|
+
return err;
|
|
6239
|
+
}
|
|
6240
|
+
//#endregion
|
|
6241
|
+
//#region src/executor/worker/sanitize.ts
|
|
6242
|
+
const MAX_DEPTH = 8;
|
|
6243
|
+
function errorToInfo(err) {
|
|
6244
|
+
return toErrorInfo(err);
|
|
6245
|
+
}
|
|
6246
|
+
function sanitizeArg(value, depth = 0, seen = /* @__PURE__ */ new WeakSet()) {
|
|
6247
|
+
if (depth > MAX_DEPTH) return "[Truncated]";
|
|
6248
|
+
if (value === null || value === void 0) return null;
|
|
6249
|
+
if (typeof value === "boolean") return value;
|
|
6250
|
+
if (typeof value === "number") return value;
|
|
6251
|
+
if (typeof value === "string") return value;
|
|
6252
|
+
if (typeof value === "bigint") return value.toString();
|
|
6253
|
+
if (typeof value === "function" || typeof value === "symbol") return null;
|
|
6254
|
+
if (value instanceof Error) return toErrorInfo(value);
|
|
6255
|
+
if (value instanceof Date) return value.toISOString();
|
|
6256
|
+
if (value instanceof Map) {
|
|
6257
|
+
const obj = {};
|
|
6258
|
+
for (const [k, v] of value.entries()) obj[String(k)] = sanitizeArg(v, depth + 1, seen);
|
|
6259
|
+
return obj;
|
|
6260
|
+
}
|
|
6261
|
+
if (value instanceof Set) {
|
|
6262
|
+
const arr = [];
|
|
6263
|
+
for (const v of value.values()) arr.push(sanitizeArg(v, depth + 1, seen));
|
|
6264
|
+
return arr;
|
|
6265
|
+
}
|
|
6266
|
+
if (Array.isArray(value)) {
|
|
6267
|
+
if (seen.has(value)) return "[Circular]";
|
|
6268
|
+
seen.add(value);
|
|
6269
|
+
const result = value.map((v) => sanitizeArg(v, depth + 1, seen));
|
|
6270
|
+
seen.delete(value);
|
|
6271
|
+
return result;
|
|
6272
|
+
}
|
|
6273
|
+
if (typeof value === "object") {
|
|
6274
|
+
const proto = Object.getPrototypeOf(value);
|
|
6275
|
+
if (proto !== Object.prototype && proto !== null) return { __nonClonable: value.constructor?.name || "Unknown" };
|
|
6276
|
+
if (seen.has(value)) return "[Circular]";
|
|
6277
|
+
seen.add(value);
|
|
6278
|
+
const result = {};
|
|
6279
|
+
for (const [k, v] of Object.entries(value)) result[k] = sanitizeArg(v, depth + 1, seen);
|
|
6280
|
+
seen.delete(value);
|
|
6281
|
+
return result;
|
|
6282
|
+
}
|
|
6283
|
+
return null;
|
|
6284
|
+
}
|
|
6285
|
+
//#endregion
|
|
6286
|
+
//#region src/executor/worker/forwarding-logger.ts
|
|
6287
|
+
function createForwardingLogger(post, level = "info", tags = []) {
|
|
6288
|
+
function safePost(msg) {
|
|
6289
|
+
try {
|
|
6290
|
+
post(msg);
|
|
6291
|
+
} catch {
|
|
6292
|
+
try {
|
|
6293
|
+
process.stderr.write(`[forwarding-logger] postMessage failed: ${msg.level} ${msg.message}\n`);
|
|
6294
|
+
} catch {}
|
|
6295
|
+
}
|
|
6296
|
+
}
|
|
6297
|
+
function emit(wireLevel, message, args) {
|
|
6298
|
+
const sanitizedArgs = args.map((a) => sanitizeArg(a));
|
|
6299
|
+
safePost({
|
|
6300
|
+
type: "log",
|
|
6301
|
+
level: wireLevel,
|
|
6302
|
+
message,
|
|
6303
|
+
args: tags.length > 0 ? [sanitizeArg({ tags }), ...sanitizedArgs] : sanitizedArgs,
|
|
6304
|
+
timestamp: Date.now()
|
|
6305
|
+
});
|
|
6306
|
+
}
|
|
6307
|
+
return {
|
|
6308
|
+
level,
|
|
6309
|
+
verbose: (message, ...args) => emit("debug", message, args),
|
|
6310
|
+
debug: (message, ...args) => emit("debug", message, args),
|
|
6311
|
+
info: (message, ...args) => emit("info", message, args),
|
|
6312
|
+
warn: (message, ...args) => emit("warn", message, args),
|
|
6313
|
+
error: (message, ...args) => emit("error", message, args),
|
|
6314
|
+
errorHandler: ((...data) => {
|
|
6315
|
+
const first = data[0];
|
|
6316
|
+
emit("error", typeof first === "string" ? first : "", data.slice(1));
|
|
6317
|
+
}),
|
|
6318
|
+
child: (childTags) => createForwardingLogger(post, level, [...tags, ...childTags])
|
|
6319
|
+
};
|
|
6320
|
+
}
|
|
6113
6321
|
//#endregion
|
|
6114
|
-
export {
|
|
6322
|
+
export { DocumentNotFoundError as $, ModuleNotFoundError as A, authDecisionModel as B, DocumentMetaCache as C, DuplicateManifestError as D, JobExecutorEventTypes as E, summarizeSubmittedActions as F, DocumentExistence as G, APPEND_CONDITION_FAILED_PREFIX as H, targetDocumentId as I, RevisionMismatchError as J, DuplicateOperationError as K, decideAtHead as L, createConsistencyToken as M, createEmptyConsistencyToken as N, DuplicateModuleError as O, submittedActionIds as P, DocumentDeletedError as Q, selectDecisionModel as R, KyselyOperationIndex as S, DEFAULT_DEFERRED_JOB_TTL_MS as T, AppendConditionFailedError as U, buildDecisionModel as V, DocumentAlreadyExistsError as W, AuthTimestampNotMonotonicError as X, AuthEnforcementDisabledError as Y, AuthorizationDeniedError as Z, DriveCollectionId as _, DEFAULT_DRIVE_CONTAINER_TYPES as a, EventBusAggregateError as at, EventBus as b, runMigrations as c, parsePagingOptions as ct, KyselyOperationStore as d, __exportAll as dt, ExcessiveReshuffleError as et, KyselyKeyframeStore as f, PassthroughSigner as g, verifyActionSignature as h, fromErrorInfo as i, UpgradePreconditionFailedError as it, GATED_DOCUMENT_ACTIONS as j, InvalidModuleError as k, createForwardingPoolInstrumentation as l, throwIfAborted as lt, SimpleJobExecutor as m, errorToInfo as n, InvalidSignatureError as nt, REACTOR_SCHEMA as o, ReactorEventTypes as ot, DocumentModelRegistry as p, OptimisticLockError as q, sanitizeArg as r, RelationshipNotFoundError as rt, getMigrationStatus as s, matchesScope as st, createForwardingLogger as t, InvalidOperationTimestampError as tt, instrumentPgPool as u, yieldToMain as ut, KyselyExecutionScope as v, CollectionMembershipCache as w, KyselyWriteCache as x, resolveFeatureFlags as y, documentDecisionModel as z };
|
|
6115
6323
|
|
|
6116
|
-
//# sourceMappingURL=
|
|
6324
|
+
//# sourceMappingURL=forwarding-logger-CSsCJ38f.js.map
|