@git-stunts/git-warp 11.2.1 → 11.5.0
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/README.md +24 -1
- package/bin/cli/commands/check.js +2 -2
- package/bin/cli/commands/doctor/checks.js +12 -12
- package/bin/cli/commands/doctor/index.js +2 -2
- package/bin/cli/commands/doctor/types.js +1 -1
- package/bin/cli/commands/history.js +12 -5
- package/bin/cli/commands/install-hooks.js +5 -5
- package/bin/cli/commands/materialize.js +2 -2
- package/bin/cli/commands/patch.js +142 -0
- package/bin/cli/commands/path.js +4 -4
- package/bin/cli/commands/query.js +54 -13
- package/bin/cli/commands/registry.js +4 -0
- package/bin/cli/commands/seek.js +17 -11
- package/bin/cli/commands/tree.js +230 -0
- package/bin/cli/commands/trust.js +3 -3
- package/bin/cli/commands/verify-audit.js +8 -7
- package/bin/cli/commands/view.js +6 -5
- package/bin/cli/infrastructure.js +26 -12
- package/bin/cli/shared.js +2 -2
- package/bin/cli/types.js +19 -8
- package/bin/presenters/index.js +35 -9
- package/bin/presenters/json.js +14 -12
- package/bin/presenters/text.js +155 -33
- package/index.d.ts +118 -22
- package/index.js +2 -0
- package/package.json +5 -3
- package/src/domain/WarpGraph.js +4 -1
- package/src/domain/crdt/ORSet.js +8 -8
- package/src/domain/errors/EmptyMessageError.js +2 -2
- package/src/domain/errors/ForkError.js +1 -1
- package/src/domain/errors/IndexError.js +1 -1
- package/src/domain/errors/OperationAbortedError.js +1 -1
- package/src/domain/errors/QueryError.js +1 -1
- package/src/domain/errors/SchemaUnsupportedError.js +1 -1
- package/src/domain/errors/ShardCorruptionError.js +2 -2
- package/src/domain/errors/ShardLoadError.js +2 -2
- package/src/domain/errors/ShardValidationError.js +4 -4
- package/src/domain/errors/StorageError.js +2 -2
- package/src/domain/errors/SyncError.js +1 -1
- package/src/domain/errors/TraversalError.js +1 -1
- package/src/domain/errors/TrustError.js +1 -1
- package/src/domain/errors/WarpError.js +2 -2
- package/src/domain/errors/WormholeError.js +1 -1
- package/src/domain/services/AuditReceiptService.js +6 -6
- package/src/domain/services/AuditVerifierService.js +52 -38
- package/src/domain/services/BitmapIndexBuilder.js +3 -3
- package/src/domain/services/BitmapIndexReader.js +28 -19
- package/src/domain/services/BoundaryTransitionRecord.js +18 -17
- package/src/domain/services/CheckpointSerializerV5.js +17 -16
- package/src/domain/services/CheckpointService.js +22 -3
- package/src/domain/services/CommitDagTraversalService.js +13 -13
- package/src/domain/services/DagPathFinding.js +7 -7
- package/src/domain/services/DagTopology.js +1 -1
- package/src/domain/services/DagTraversal.js +1 -1
- package/src/domain/services/HealthCheckService.js +1 -1
- package/src/domain/services/HookInstaller.js +1 -1
- package/src/domain/services/HttpSyncServer.js +92 -41
- package/src/domain/services/IndexRebuildService.js +7 -7
- package/src/domain/services/IndexStalenessChecker.js +4 -3
- package/src/domain/services/JoinReducer.js +26 -11
- package/src/domain/services/KeyCodec.js +7 -0
- package/src/domain/services/LogicalTraversal.js +1 -1
- package/src/domain/services/MessageCodecInternal.js +1 -1
- package/src/domain/services/MigrationService.js +1 -1
- package/src/domain/services/ObserverView.js +8 -8
- package/src/domain/services/PatchBuilderV2.js +96 -30
- package/src/domain/services/ProvenanceIndex.js +1 -1
- package/src/domain/services/ProvenancePayload.js +1 -1
- package/src/domain/services/QueryBuilder.js +3 -3
- package/src/domain/services/StateDiff.js +14 -11
- package/src/domain/services/StateSerializerV5.js +2 -2
- package/src/domain/services/StreamingBitmapIndexBuilder.js +26 -24
- package/src/domain/services/SyncAuthService.js +3 -2
- package/src/domain/services/SyncProtocol.js +25 -11
- package/src/domain/services/TemporalQuery.js +9 -6
- package/src/domain/services/TranslationCost.js +7 -5
- package/src/domain/services/WormholeService.js +16 -7
- package/src/domain/trust/TrustCanonical.js +3 -3
- package/src/domain/trust/TrustEvaluator.js +18 -3
- package/src/domain/trust/TrustRecordService.js +30 -23
- package/src/domain/trust/TrustStateBuilder.js +21 -8
- package/src/domain/trust/canonical.js +6 -6
- package/src/domain/types/TickReceipt.js +1 -1
- package/src/domain/types/WarpErrors.js +45 -0
- package/src/domain/types/WarpOptions.js +29 -0
- package/src/domain/types/WarpPersistence.js +41 -0
- package/src/domain/types/WarpTypes.js +2 -2
- package/src/domain/types/WarpTypesV2.js +2 -2
- package/src/domain/utils/MinHeap.js +6 -5
- package/src/domain/utils/canonicalStringify.js +5 -4
- package/src/domain/utils/roaring.js +31 -5
- package/src/domain/warp/PatchSession.js +40 -18
- package/src/domain/warp/_wiredMethods.d.ts +199 -45
- package/src/domain/warp/checkpoint.methods.js +5 -1
- package/src/domain/warp/fork.methods.js +2 -2
- package/src/domain/warp/materialize.methods.js +55 -5
- package/src/domain/warp/materializeAdvanced.methods.js +15 -4
- package/src/domain/warp/patch.methods.js +54 -29
- package/src/domain/warp/provenance.methods.js +5 -3
- package/src/domain/warp/query.methods.js +89 -6
- package/src/domain/warp/sync.methods.js +16 -11
- package/src/globals.d.ts +64 -0
- package/src/infrastructure/adapters/BunHttpAdapter.js +14 -9
- package/src/infrastructure/adapters/CasSeekCacheAdapter.js +9 -4
- package/src/infrastructure/adapters/DenoHttpAdapter.js +5 -6
- package/src/infrastructure/adapters/GitGraphAdapter.js +18 -13
- package/src/infrastructure/adapters/NodeHttpAdapter.js +2 -2
- package/src/infrastructure/adapters/WebCryptoAdapter.js +2 -2
- package/src/visualization/layouts/converters.js +2 -2
- package/src/visualization/layouts/elkAdapter.js +1 -1
- package/src/visualization/layouts/elkLayout.js +10 -7
- package/src/visualization/layouts/index.js +1 -1
- package/src/visualization/renderers/ascii/seek.js +16 -6
- package/src/visualization/renderers/svg/index.js +1 -1
|
@@ -8,6 +8,8 @@ import { getRoaringBitmap32 } from '../utils/roaring.js';
|
|
|
8
8
|
import { canonicalStringify } from '../utils/canonicalStringify.js';
|
|
9
9
|
import { SHARD_VERSION } from '../utils/shardVersion.js';
|
|
10
10
|
|
|
11
|
+
/** @typedef {import('../types/WarpPersistence.js').IndexStorage} IndexStorage */
|
|
12
|
+
|
|
11
13
|
// Re-export for backwards compatibility
|
|
12
14
|
export { SHARD_VERSION };
|
|
13
15
|
|
|
@@ -81,7 +83,7 @@ export default class StreamingBitmapIndexBuilder {
|
|
|
81
83
|
* Creates a new StreamingBitmapIndexBuilder instance.
|
|
82
84
|
*
|
|
83
85
|
* @param {Object} options - Configuration options
|
|
84
|
-
* @param {
|
|
86
|
+
* @param {import('../../ports/IndexStoragePort.js').default} options.storage - Storage adapter implementing IndexStoragePort.
|
|
85
87
|
* Required methods: writeBlob, writeTree, readBlob
|
|
86
88
|
* @param {number} [options.maxMemoryBytes=52428800] - Maximum bitmap memory before flush (default 50MB).
|
|
87
89
|
* Note: SHA→ID mappings are not counted against this limit as they must remain in memory.
|
|
@@ -106,8 +108,8 @@ export default class StreamingBitmapIndexBuilder {
|
|
|
106
108
|
/** @type {import('../../ports/CodecPort.js').default} */
|
|
107
109
|
this._codec = codec || defaultCodec;
|
|
108
110
|
|
|
109
|
-
/** @type {
|
|
110
|
-
this.storage = storage;
|
|
111
|
+
/** @type {IndexStorage} */
|
|
112
|
+
this.storage = /** @type {IndexStorage} */ (storage);
|
|
111
113
|
|
|
112
114
|
/** @type {number} */
|
|
113
115
|
this.maxMemoryBytes = maxMemoryBytes;
|
|
@@ -124,7 +126,7 @@ export default class StreamingBitmapIndexBuilder {
|
|
|
124
126
|
/** @type {string[]} ID → SHA reverse mapping (kept in memory) */
|
|
125
127
|
this.idToSha = [];
|
|
126
128
|
|
|
127
|
-
/** @type {Map<string,
|
|
129
|
+
/** @type {Map<string, import('../utils/roaring.js').RoaringBitmapSubset>} Current in-memory bitmaps */
|
|
128
130
|
this.bitmaps = new Map();
|
|
129
131
|
|
|
130
132
|
/** @type {number} Estimated bytes used by current bitmaps */
|
|
@@ -139,8 +141,8 @@ export default class StreamingBitmapIndexBuilder {
|
|
|
139
141
|
/** @type {number} Number of flush operations performed */
|
|
140
142
|
this.flushCount = 0;
|
|
141
143
|
|
|
142
|
-
/** @type {
|
|
143
|
-
this._RoaringBitmap32 = getRoaringBitmap32();
|
|
144
|
+
/** @type {typeof import('roaring').RoaringBitmap32} Cached Roaring bitmap constructor */
|
|
145
|
+
this._RoaringBitmap32 = getRoaringBitmap32();
|
|
144
146
|
}
|
|
145
147
|
|
|
146
148
|
/**
|
|
@@ -206,7 +208,7 @@ export default class StreamingBitmapIndexBuilder {
|
|
|
206
208
|
if (!bitmapShards[type][prefix]) {
|
|
207
209
|
bitmapShards[type][prefix] = {};
|
|
208
210
|
}
|
|
209
|
-
bitmapShards[type][prefix][sha] = bitmap.serialize(true).toString('base64');
|
|
211
|
+
bitmapShards[type][prefix][sha] = Buffer.from(bitmap.serialize(true)).toString('base64');
|
|
210
212
|
}
|
|
211
213
|
return bitmapShards;
|
|
212
214
|
}
|
|
@@ -238,7 +240,7 @@ export default class StreamingBitmapIndexBuilder {
|
|
|
238
240
|
data: shardData,
|
|
239
241
|
};
|
|
240
242
|
const buffer = Buffer.from(JSON.stringify(envelope));
|
|
241
|
-
const oid = await
|
|
243
|
+
const oid = await this.storage.writeBlob(buffer);
|
|
242
244
|
if (!this.flushedChunks.has(path)) {
|
|
243
245
|
this.flushedChunks.set(path, []);
|
|
244
246
|
}
|
|
@@ -348,7 +350,7 @@ export default class StreamingBitmapIndexBuilder {
|
|
|
348
350
|
data: map,
|
|
349
351
|
};
|
|
350
352
|
const buffer = Buffer.from(JSON.stringify(envelope));
|
|
351
|
-
const oid = await
|
|
353
|
+
const oid = await this.storage.writeBlob(buffer);
|
|
352
354
|
return `100644 blob ${oid}\t${path}`;
|
|
353
355
|
})
|
|
354
356
|
);
|
|
@@ -410,8 +412,8 @@ export default class StreamingBitmapIndexBuilder {
|
|
|
410
412
|
* @param {Object} [options] - Finalization options
|
|
411
413
|
* @param {AbortSignal} [options.signal] - Optional AbortSignal for cancellation.
|
|
412
414
|
* If aborted, throws an error with code 'ABORT_ERR'.
|
|
413
|
-
* @param {Map<string,
|
|
414
|
-
* (writerId →
|
|
415
|
+
* @param {Map<string, string>} [options.frontier] - Optional writer frontier
|
|
416
|
+
* (writerId → tip SHA) for staleness detection. If provided, frontier.cbor and
|
|
415
417
|
* frontier.json files are included in the tree.
|
|
416
418
|
* @returns {Promise<string>} OID of the created Git tree containing the complete index
|
|
417
419
|
* @throws {Error} If the operation is aborted via signal
|
|
@@ -440,19 +442,19 @@ export default class StreamingBitmapIndexBuilder {
|
|
|
440
442
|
|
|
441
443
|
// Store frontier metadata for staleness detection
|
|
442
444
|
if (frontier) {
|
|
443
|
-
/** @type {Record<string,
|
|
445
|
+
/** @type {Record<string, string|undefined>} */
|
|
444
446
|
const sorted = {};
|
|
445
447
|
for (const key of Array.from(frontier.keys()).sort()) {
|
|
446
448
|
sorted[key] = frontier.get(key);
|
|
447
449
|
}
|
|
448
450
|
const envelope = { version: 1, writerCount: frontier.size, frontier: sorted };
|
|
449
|
-
const cborOid = await
|
|
451
|
+
const cborOid = await this.storage.writeBlob(Buffer.from(this._codec.encode(envelope)));
|
|
450
452
|
flatEntries.push(`100644 blob ${cborOid}\tfrontier.cbor`);
|
|
451
|
-
const jsonOid = await
|
|
453
|
+
const jsonOid = await this.storage.writeBlob(Buffer.from(canonicalStringify(envelope)));
|
|
452
454
|
flatEntries.push(`100644 blob ${jsonOid}\tfrontier.json`);
|
|
453
455
|
}
|
|
454
456
|
|
|
455
|
-
const treeOid = await
|
|
457
|
+
const treeOid = await this.storage.writeTree(flatEntries);
|
|
456
458
|
|
|
457
459
|
this.logger.debug('Index finalized', {
|
|
458
460
|
operation: 'finalize',
|
|
@@ -539,7 +541,7 @@ export default class StreamingBitmapIndexBuilder {
|
|
|
539
541
|
this.estimatedBitmapBytes += BITMAP_BASE_OVERHEAD;
|
|
540
542
|
}
|
|
541
543
|
|
|
542
|
-
const bitmap = this.bitmaps.get(key);
|
|
544
|
+
const bitmap = /** @type {import('../utils/roaring.js').RoaringBitmapSubset} */ (this.bitmaps.get(key));
|
|
543
545
|
const sizeBefore = bitmap.size;
|
|
544
546
|
bitmap.add(id);
|
|
545
547
|
const sizeAfter = bitmap.size;
|
|
@@ -569,7 +571,7 @@ export default class StreamingBitmapIndexBuilder {
|
|
|
569
571
|
* @private
|
|
570
572
|
*/
|
|
571
573
|
async _loadAndValidateChunk(oid) {
|
|
572
|
-
const buffer = await
|
|
574
|
+
const buffer = await this.storage.readBlob(oid);
|
|
573
575
|
let envelope;
|
|
574
576
|
try {
|
|
575
577
|
envelope = JSON.parse(buffer.toString('utf-8'));
|
|
@@ -577,7 +579,7 @@ export default class StreamingBitmapIndexBuilder {
|
|
|
577
579
|
throw new ShardCorruptionError('Failed to parse shard JSON', {
|
|
578
580
|
oid,
|
|
579
581
|
reason: 'invalid_format',
|
|
580
|
-
context: { originalError:
|
|
582
|
+
context: { originalError: err instanceof Error ? err.message : String(err) },
|
|
581
583
|
});
|
|
582
584
|
}
|
|
583
585
|
|
|
@@ -614,7 +616,7 @@ export default class StreamingBitmapIndexBuilder {
|
|
|
614
616
|
* it using `orInPlace` to combine edge sets.
|
|
615
617
|
*
|
|
616
618
|
* @param {Object} opts - Options object
|
|
617
|
-
* @param {Record<string,
|
|
619
|
+
* @param {Record<string, import('../utils/roaring.js').RoaringBitmapSubset>} opts.merged - Object mapping SHA to
|
|
618
620
|
* RoaringBitmap32 instances (mutated in place)
|
|
619
621
|
* @param {string} opts.sha - The SHA key for this bitmap (40-character hex string)
|
|
620
622
|
* @param {string} opts.base64Bitmap - Base64-encoded serialized RoaringBitmap32 data
|
|
@@ -631,7 +633,7 @@ export default class StreamingBitmapIndexBuilder {
|
|
|
631
633
|
throw new ShardCorruptionError('Failed to deserialize bitmap', {
|
|
632
634
|
oid,
|
|
633
635
|
reason: 'invalid_bitmap',
|
|
634
|
-
context: { originalError:
|
|
636
|
+
context: { originalError: err instanceof Error ? err.message : String(err) },
|
|
635
637
|
});
|
|
636
638
|
}
|
|
637
639
|
|
|
@@ -675,7 +677,7 @@ export default class StreamingBitmapIndexBuilder {
|
|
|
675
677
|
*/
|
|
676
678
|
async _mergeChunks(oids, { signal } = {}) {
|
|
677
679
|
// Load all chunks and merge bitmaps by SHA
|
|
678
|
-
/** @type {Record<string,
|
|
680
|
+
/** @type {Record<string, import('../utils/roaring.js').RoaringBitmapSubset>} */
|
|
679
681
|
const merged = {};
|
|
680
682
|
|
|
681
683
|
for (const oid of oids) {
|
|
@@ -691,7 +693,7 @@ export default class StreamingBitmapIndexBuilder {
|
|
|
691
693
|
/** @type {Record<string, string>} */
|
|
692
694
|
const result = {};
|
|
693
695
|
for (const [sha, bitmap] of Object.entries(merged)) {
|
|
694
|
-
result[sha] = bitmap.serialize(true).toString('base64');
|
|
696
|
+
result[sha] = Buffer.from(bitmap.serialize(true)).toString('base64');
|
|
695
697
|
}
|
|
696
698
|
|
|
697
699
|
// Wrap merged result in envelope with version and checksum
|
|
@@ -707,9 +709,9 @@ export default class StreamingBitmapIndexBuilder {
|
|
|
707
709
|
} catch (err) {
|
|
708
710
|
throw new ShardCorruptionError('Failed to serialize merged shard', {
|
|
709
711
|
reason: 'serialization_error',
|
|
710
|
-
context: { originalError:
|
|
712
|
+
context: { originalError: err instanceof Error ? err.message : String(err) },
|
|
711
713
|
});
|
|
712
714
|
}
|
|
713
|
-
return
|
|
715
|
+
return await this.storage.writeBlob(serialized);
|
|
714
716
|
}
|
|
715
717
|
}
|
|
@@ -144,6 +144,7 @@ function _checkHeaderFormats(timestamp, nonce, signature) {
|
|
|
144
144
|
|
|
145
145
|
/**
|
|
146
146
|
* @param {Record<string, string>|undefined} keys
|
|
147
|
+
* @returns {asserts keys is Record<string, string>}
|
|
147
148
|
*/
|
|
148
149
|
function _validateKeys(keys) {
|
|
149
150
|
if (!keys || typeof keys !== 'object' || Object.keys(keys).length === 0) {
|
|
@@ -180,7 +181,7 @@ export default class SyncAuthService {
|
|
|
180
181
|
* @param {() => number} [options.wallClockMs] - Wall clock function
|
|
181
182
|
* @param {string[]} [options.allowedWriters] - Optional whitelist of allowed writer IDs. If set, sync requests with unlisted writers are rejected with 403.
|
|
182
183
|
*/
|
|
183
|
-
constructor({ keys, mode = 'enforce', nonceCapacity, maxClockSkewMs, crypto, logger, wallClockMs, allowedWriters } = /** @type {
|
|
184
|
+
constructor({ keys, mode = 'enforce', nonceCapacity, maxClockSkewMs, crypto, logger, wallClockMs, allowedWriters } = /** @type {{ keys: Record<string, string> }} */ ({})) {
|
|
184
185
|
_validateKeys(keys);
|
|
185
186
|
this._keys = keys;
|
|
186
187
|
this._mode = mode;
|
|
@@ -433,7 +434,7 @@ export default class SyncAuthService {
|
|
|
433
434
|
/**
|
|
434
435
|
* Records an auth failure and returns the result.
|
|
435
436
|
* @param {string} message
|
|
436
|
-
* @param {Record<string,
|
|
437
|
+
* @param {Record<string, unknown>} context
|
|
437
438
|
* @param {{ ok: false, reason: string, status: number }} result
|
|
438
439
|
* @returns {{ ok: false, reason: string, status: number }}
|
|
439
440
|
* @private
|
|
@@ -42,6 +42,16 @@ import { join, cloneStateV5 } from './JoinReducer.js';
|
|
|
42
42
|
import { cloneFrontier, updateFrontier } from './Frontier.js';
|
|
43
43
|
import { vvDeserialize } from '../crdt/VersionVector.js';
|
|
44
44
|
|
|
45
|
+
/**
|
|
46
|
+
* A decoded patch object after CBOR deserialization.
|
|
47
|
+
* @typedef {Object} DecodedPatch
|
|
48
|
+
* @property {Object | Map<string, number>} [context] - VersionVector (Map after normalization, plain object before)
|
|
49
|
+
* @property {import('../types/WarpTypesV2.js').OpV2[]} ops - Ordered array of operations
|
|
50
|
+
* @property {string} [writer] - Writer ID
|
|
51
|
+
* @property {number} [lamport] - Lamport timestamp
|
|
52
|
+
* @property {number} [schema] - Schema version
|
|
53
|
+
*/
|
|
54
|
+
|
|
45
55
|
// -----------------------------------------------------------------------------
|
|
46
56
|
// Patch Loading
|
|
47
57
|
// -----------------------------------------------------------------------------
|
|
@@ -56,9 +66,9 @@ import { vvDeserialize } from '../crdt/VersionVector.js';
|
|
|
56
66
|
* **Mutation**: This function mutates the input patch object for efficiency.
|
|
57
67
|
* The original object reference is returned.
|
|
58
68
|
*
|
|
59
|
-
* @param {
|
|
69
|
+
* @param {DecodedPatch} patch - The raw decoded patch from CBOR.
|
|
60
70
|
* If context is present as a plain object, it will be converted to a Map.
|
|
61
|
-
* @returns {
|
|
71
|
+
* @returns {DecodedPatch} The same patch object with context converted to Map
|
|
62
72
|
* @private
|
|
63
73
|
*/
|
|
64
74
|
function normalizePatch(patch) {
|
|
@@ -88,7 +98,7 @@ function normalizePatch(patch) {
|
|
|
88
98
|
* @param {string} sha - The 40-character commit SHA to load the patch from
|
|
89
99
|
* @param {Object} [options]
|
|
90
100
|
* @param {import('../../ports/CodecPort.js').default} [options.codec] - Codec for deserialization
|
|
91
|
-
* @returns {Promise<
|
|
101
|
+
* @returns {Promise<DecodedPatch>} The decoded and normalized patch object containing:
|
|
92
102
|
* - `ops`: Array of patch operations
|
|
93
103
|
* - `context`: VersionVector (Map) of causal dependencies
|
|
94
104
|
* - `writerId`: The writer who created this patch
|
|
@@ -99,7 +109,7 @@ function normalizePatch(patch) {
|
|
|
99
109
|
* @throws {Error} If the patch blob cannot be CBOR-decoded (corrupted data)
|
|
100
110
|
* @private
|
|
101
111
|
*/
|
|
102
|
-
async function loadPatchFromCommit(persistence, sha, { codec: codecOpt } = /** @type {
|
|
112
|
+
async function loadPatchFromCommit(persistence, sha, { codec: codecOpt } = /** @type {{ codec?: import('../../ports/CodecPort.js').default }} */ ({})) {
|
|
103
113
|
const codec = codecOpt || defaultCodec;
|
|
104
114
|
// Read commit message to extract patch OID
|
|
105
115
|
const message = await persistence.showNode(sha);
|
|
@@ -107,7 +117,7 @@ async function loadPatchFromCommit(persistence, sha, { codec: codecOpt } = /** @
|
|
|
107
117
|
|
|
108
118
|
// Read and decode the patch blob
|
|
109
119
|
const patchBuffer = await persistence.readBlob(decoded.patchOid);
|
|
110
|
-
const patch = /** @type {
|
|
120
|
+
const patch = /** @type {DecodedPatch} */ (codec.decode(patchBuffer));
|
|
111
121
|
|
|
112
122
|
// Normalize the patch (convert context from object to Map)
|
|
113
123
|
return normalizePatch(patch);
|
|
@@ -134,7 +144,9 @@ async function loadPatchFromCommit(persistence, sha, { codec: codecOpt } = /** @
|
|
|
134
144
|
* @param {string|null} fromSha - Start SHA (exclusive). Pass null to load ALL patches
|
|
135
145
|
* for this writer from the beginning of their chain.
|
|
136
146
|
* @param {string} toSha - End SHA (inclusive). This is typically the writer's current tip.
|
|
137
|
-
* @
|
|
147
|
+
* @param {Object} [options]
|
|
148
|
+
* @param {import('../../ports/CodecPort.js').default} [options.codec] - Codec for deserialization
|
|
149
|
+
* @returns {Promise<Array<{patch: DecodedPatch, sha: string}>>} Array of patch objects in
|
|
138
150
|
* chronological order (oldest first). Each entry contains:
|
|
139
151
|
* - `patch`: The decoded patch object
|
|
140
152
|
* - `sha`: The commit SHA this patch came from
|
|
@@ -152,7 +164,7 @@ async function loadPatchFromCommit(persistence, sha, { codec: codecOpt } = /** @
|
|
|
152
164
|
* // Load ALL patches for a new writer
|
|
153
165
|
* const patches = await loadPatchRange(persistence, 'events', 'new-writer', null, tipSha);
|
|
154
166
|
*/
|
|
155
|
-
export async function loadPatchRange(persistence, graphName, writerId, fromSha, toSha, { codec } = /** @type {
|
|
167
|
+
export async function loadPatchRange(persistence, graphName, writerId, fromSha, toSha, { codec } = /** @type {{ codec?: import('../../ports/CodecPort.js').default }} */ ({})) {
|
|
156
168
|
const patches = [];
|
|
157
169
|
let cur = toSha;
|
|
158
170
|
|
|
@@ -298,7 +310,7 @@ export function computeSyncDelta(localFrontier, remoteFrontier) {
|
|
|
298
310
|
* @property {'sync-response'} type - Message type discriminator for protocol parsing
|
|
299
311
|
* @property {Object.<string, string>} frontier - Responder's frontier as a plain object.
|
|
300
312
|
* Keys are writer IDs, values are SHAs.
|
|
301
|
-
* @property {Array<{writerId: string, sha: string, patch:
|
|
313
|
+
* @property {Array<{writerId: string, sha: string, patch: DecodedPatch}>} patches - Patches
|
|
302
314
|
* the requester needs, in chronological order per writer. Contains:
|
|
303
315
|
* - `writerId`: The writer who created this patch
|
|
304
316
|
* - `sha`: The commit SHA this patch came from (for frontier updates)
|
|
@@ -361,6 +373,8 @@ export function createSyncRequest(frontier) {
|
|
|
361
373
|
* @param {import('../../ports/GraphPersistencePort.js').default & import('../../ports/CommitPort.js').default & import('../../ports/BlobPort.js').default} persistence - Git persistence
|
|
362
374
|
* layer for loading patches (uses CommitPort + BlobPort methods)
|
|
363
375
|
* @param {string} graphName - Graph name for error messages and logging
|
|
376
|
+
* @param {Object} [options]
|
|
377
|
+
* @param {import('../../ports/CodecPort.js').default} [options.codec] - Codec for deserialization
|
|
364
378
|
* @returns {Promise<SyncResponse>} Response containing local frontier and patches.
|
|
365
379
|
* Patches are ordered chronologically within each writer.
|
|
366
380
|
* @throws {Error} If patch loading fails for reasons other than divergence
|
|
@@ -374,7 +388,7 @@ export function createSyncRequest(frontier) {
|
|
|
374
388
|
* res.json(response);
|
|
375
389
|
* });
|
|
376
390
|
*/
|
|
377
|
-
export async function processSyncRequest(request, localFrontier, persistence, graphName, { codec } = /** @type {
|
|
391
|
+
export async function processSyncRequest(request, localFrontier, persistence, graphName, { codec } = /** @type {{ codec?: import('../../ports/CodecPort.js').default }} */ ({})) {
|
|
378
392
|
// Convert incoming frontier from object to Map
|
|
379
393
|
const remoteFrontier = new Map(Object.entries(request.frontier));
|
|
380
394
|
|
|
@@ -401,7 +415,7 @@ export async function processSyncRequest(request, localFrontier, persistence, gr
|
|
|
401
415
|
} catch (err) {
|
|
402
416
|
// If we detect divergence, skip this writer
|
|
403
417
|
// The requester may need to handle this separately
|
|
404
|
-
if (/** @type {
|
|
418
|
+
if ((err instanceof Error && 'code' in err && /** @type {{ code: string }} */ (err).code === 'E_SYNC_DIVERGENCE') || (err instanceof Error && err.message?.includes('Divergence detected'))) {
|
|
405
419
|
continue;
|
|
406
420
|
}
|
|
407
421
|
throw err;
|
|
@@ -491,7 +505,7 @@ export function applySyncResponse(response, state, frontier) {
|
|
|
491
505
|
// will prevent silent data loss until the reader is upgraded.
|
|
492
506
|
assertOpsCompatible(normalizedPatch.ops, SCHEMA_V3);
|
|
493
507
|
// Apply patch to state
|
|
494
|
-
join(newState, /** @type {
|
|
508
|
+
join(newState, /** @type {Parameters<typeof join>[1]} */ (normalizedPatch), sha);
|
|
495
509
|
applied++;
|
|
496
510
|
}
|
|
497
511
|
|
|
@@ -36,13 +36,16 @@ import { orsetContains } from '../crdt/ORSet.js';
|
|
|
36
36
|
* InlineValue objects `{ type: 'inline', value: ... }` are unwrapped
|
|
37
37
|
* to their inner value. All other values pass through unchanged.
|
|
38
38
|
*
|
|
39
|
-
* @param {
|
|
40
|
-
* @returns {
|
|
39
|
+
* @param {unknown} value - Property value (potentially InlineValue-wrapped)
|
|
40
|
+
* @returns {unknown} The unwrapped value
|
|
41
41
|
* @private
|
|
42
42
|
*/
|
|
43
43
|
function unwrapValue(value) {
|
|
44
|
-
if (value && typeof value === 'object' &&
|
|
45
|
-
|
|
44
|
+
if (value && typeof value === 'object' && 'type' in value) {
|
|
45
|
+
const rec = /** @type {Record<string, unknown>} */ (value);
|
|
46
|
+
if (rec.type === 'inline') {
|
|
47
|
+
return rec.value;
|
|
48
|
+
}
|
|
46
49
|
}
|
|
47
50
|
return value;
|
|
48
51
|
}
|
|
@@ -60,11 +63,11 @@ function unwrapValue(value) {
|
|
|
60
63
|
*
|
|
61
64
|
* @param {import('./JoinReducer.js').WarpStateV5} state - Current state
|
|
62
65
|
* @param {string} nodeId - Node ID to extract
|
|
63
|
-
* @returns {{ id: string, exists: boolean, props: Record<string,
|
|
66
|
+
* @returns {{ id: string, exists: boolean, props: Record<string, unknown> }}
|
|
64
67
|
*/
|
|
65
68
|
function extractNodeSnapshot(state, nodeId) {
|
|
66
69
|
const exists = orsetContains(state.nodeAlive, nodeId);
|
|
67
|
-
/** @type {Record<string,
|
|
70
|
+
/** @type {Record<string, unknown>} */
|
|
68
71
|
const props = {};
|
|
69
72
|
|
|
70
73
|
if (exists) {
|
|
@@ -16,6 +16,8 @@
|
|
|
16
16
|
import { orsetElements, orsetContains } from '../crdt/ORSet.js';
|
|
17
17
|
import { decodeEdgeKey, decodePropKey, isEdgePropKey } from './KeyCodec.js';
|
|
18
18
|
|
|
19
|
+
/** @typedef {import('./JoinReducer.js').WarpStateV5} WarpStateV5 */
|
|
20
|
+
|
|
19
21
|
/**
|
|
20
22
|
* Tests whether a string matches a glob-style pattern.
|
|
21
23
|
*
|
|
@@ -38,7 +40,7 @@ function matchGlob(pattern, str) {
|
|
|
38
40
|
/**
|
|
39
41
|
* Computes the set of property keys visible under an observer config.
|
|
40
42
|
*
|
|
41
|
-
* @param {Map<string,
|
|
43
|
+
* @param {Map<string, unknown>} allNodeProps - Map of propKey -> placeholder
|
|
42
44
|
* @param {string[]|undefined} expose - Whitelist of property keys
|
|
43
45
|
* @param {string[]|undefined} redact - Blacklist of property keys
|
|
44
46
|
* @returns {Set<string>} Visible property keys
|
|
@@ -63,7 +65,7 @@ function visiblePropKeys(allNodeProps, expose, redact) {
|
|
|
63
65
|
/**
|
|
64
66
|
* Collects node property keys from state for a given node.
|
|
65
67
|
*
|
|
66
|
-
* @param {
|
|
68
|
+
* @param {WarpStateV5} state - WarpStateV5 materialized state
|
|
67
69
|
* @param {string} nodeId - The node ID
|
|
68
70
|
* @returns {Map<string, boolean>} Map of propKey -> true
|
|
69
71
|
*/
|
|
@@ -111,7 +113,7 @@ function countMissing(source, targetSet) {
|
|
|
111
113
|
/**
|
|
112
114
|
* Computes edge loss between two observer node sets.
|
|
113
115
|
*
|
|
114
|
-
* @param {
|
|
116
|
+
* @param {WarpStateV5} state
|
|
115
117
|
* @param {Set<string>} nodesASet - Nodes visible to A
|
|
116
118
|
* @param {Set<string>} nodesBSet - Nodes visible to B
|
|
117
119
|
* @returns {number} edgeLoss fraction
|
|
@@ -156,7 +158,7 @@ function countNodePropLoss(nodeProps, { configA, configB, nodeInB }) {
|
|
|
156
158
|
/**
|
|
157
159
|
* Computes property loss across all A-visible nodes.
|
|
158
160
|
*
|
|
159
|
-
* @param {
|
|
161
|
+
* @param {WarpStateV5} state - WarpStateV5
|
|
160
162
|
* @param {{ nodesA: string[], nodesBSet: Set<string>, configA: {expose?: string[], redact?: string[]}, configB: {expose?: string[], redact?: string[]} }} opts
|
|
161
163
|
* @returns {number} propLoss fraction
|
|
162
164
|
*/
|
|
@@ -193,7 +195,7 @@ function computePropLoss(state, { nodesA, nodesBSet, configA, configB }) {
|
|
|
193
195
|
* @param {string} configB.match - Glob pattern for visible nodes
|
|
194
196
|
* @param {string[]} [configB.expose] - Property keys to include
|
|
195
197
|
* @param {string[]} [configB.redact] - Property keys to exclude
|
|
196
|
-
* @param {
|
|
198
|
+
* @param {WarpStateV5} state - WarpStateV5 materialized state
|
|
197
199
|
* @returns {{ cost: number, breakdown: { nodeLoss: number, edgeLoss: number, propLoss: number } }}
|
|
198
200
|
*/
|
|
199
201
|
export function computeTranslationCost(configA, configB, state) {
|
|
@@ -27,7 +27,7 @@ import { detectMessageKind, decodePatchMessage } from './WarpMessageCodec.js';
|
|
|
27
27
|
|
|
28
28
|
/**
|
|
29
29
|
* Validates that a SHA parameter is a non-empty string.
|
|
30
|
-
* @param {
|
|
30
|
+
* @param {unknown} sha - The SHA to validate
|
|
31
31
|
* @param {string} paramName - Parameter name for error messages
|
|
32
32
|
* @throws {WormholeError} If SHA is invalid
|
|
33
33
|
* @private
|
|
@@ -321,7 +321,7 @@ export function deserializeWormhole(json) {
|
|
|
321
321
|
});
|
|
322
322
|
}
|
|
323
323
|
|
|
324
|
-
const /** @type {Record<string,
|
|
324
|
+
const /** @type {Record<string, unknown>} */ typedJson = /** @type {Record<string, unknown>} */ (json);
|
|
325
325
|
const requiredFields = ['fromSha', 'toSha', 'writerId', 'patchCount', 'payload'];
|
|
326
326
|
for (const field of requiredFields) {
|
|
327
327
|
if (typedJson[field] === undefined) {
|
|
@@ -332,6 +332,15 @@ export function deserializeWormhole(json) {
|
|
|
332
332
|
}
|
|
333
333
|
}
|
|
334
334
|
|
|
335
|
+
for (const field of ['fromSha', 'toSha', 'writerId']) {
|
|
336
|
+
if (typeof typedJson[field] !== 'string') {
|
|
337
|
+
throw new WormholeError(`Invalid wormhole JSON: '${field}' must be a string`, {
|
|
338
|
+
code: 'E_INVALID_WORMHOLE_JSON',
|
|
339
|
+
context: { [field]: typedJson[field] },
|
|
340
|
+
});
|
|
341
|
+
}
|
|
342
|
+
}
|
|
343
|
+
|
|
335
344
|
if (typeof typedJson.patchCount !== 'number' || typedJson.patchCount < 0) {
|
|
336
345
|
throw new WormholeError('Invalid wormhole JSON: patchCount must be a non-negative number', {
|
|
337
346
|
code: 'E_INVALID_WORMHOLE_JSON',
|
|
@@ -340,11 +349,11 @@ export function deserializeWormhole(json) {
|
|
|
340
349
|
}
|
|
341
350
|
|
|
342
351
|
return {
|
|
343
|
-
fromSha: typedJson.fromSha,
|
|
344
|
-
toSha: typedJson.toSha,
|
|
345
|
-
writerId: typedJson.writerId,
|
|
346
|
-
patchCount: typedJson.patchCount,
|
|
347
|
-
payload: ProvenancePayload.fromJSON(typedJson.payload),
|
|
352
|
+
fromSha: /** @type {string} */ (typedJson.fromSha),
|
|
353
|
+
toSha: /** @type {string} */ (typedJson.toSha),
|
|
354
|
+
writerId: /** @type {string} */ (typedJson.writerId),
|
|
355
|
+
patchCount: /** @type {number} */ (typedJson.patchCount),
|
|
356
|
+
payload: ProvenancePayload.fromJSON(/** @type {import('./ProvenancePayload.js').PatchEntry[]} */ (typedJson.payload)),
|
|
348
357
|
};
|
|
349
358
|
}
|
|
350
359
|
|
|
@@ -14,7 +14,7 @@ import { recordIdPayload, signaturePayload } from './canonical.js';
|
|
|
14
14
|
/**
|
|
15
15
|
* Computes the record ID (SHA-256 hex digest) for a trust record.
|
|
16
16
|
*
|
|
17
|
-
* @param {Record<string,
|
|
17
|
+
* @param {Record<string, unknown>} record - Full trust record
|
|
18
18
|
* @returns {string} 64-character lowercase hex string
|
|
19
19
|
*/
|
|
20
20
|
export function computeRecordId(record) {
|
|
@@ -24,7 +24,7 @@ export function computeRecordId(record) {
|
|
|
24
24
|
/**
|
|
25
25
|
* Computes the signature payload as a Buffer (UTF-8 bytes).
|
|
26
26
|
*
|
|
27
|
-
* @param {Record<string,
|
|
27
|
+
* @param {Record<string, unknown>} record - Full trust record (signature will be stripped)
|
|
28
28
|
* @returns {Buffer} UTF-8 encoded bytes of the domain-separated canonical string
|
|
29
29
|
*/
|
|
30
30
|
export function computeSignaturePayload(record) {
|
|
@@ -34,7 +34,7 @@ export function computeSignaturePayload(record) {
|
|
|
34
34
|
/**
|
|
35
35
|
* Verifies that a record's recordId matches its content.
|
|
36
36
|
*
|
|
37
|
-
* @param {Record<string,
|
|
37
|
+
* @param {Record<string, unknown>} record - Trust record with `recordId` field
|
|
38
38
|
* @returns {boolean} true if recordId matches computed value
|
|
39
39
|
*/
|
|
40
40
|
export function verifyRecordId(record) {
|
|
@@ -16,6 +16,21 @@ import { deriveTrustVerdict } from './verdict.js';
|
|
|
16
16
|
* @typedef {import('./TrustStateBuilder.js').TrustState} TrustState
|
|
17
17
|
*/
|
|
18
18
|
|
|
19
|
+
/**
|
|
20
|
+
* @typedef {Object} TrustAssessment
|
|
21
|
+
* @property {number} trustSchemaVersion
|
|
22
|
+
* @property {string} mode
|
|
23
|
+
* @property {string} trustVerdict
|
|
24
|
+
* @property {Object} trust
|
|
25
|
+
* @property {'configured'|'pinned'|'error'|'not_configured'} trust.status
|
|
26
|
+
* @property {string} trust.source
|
|
27
|
+
* @property {string|null} trust.sourceDetail
|
|
28
|
+
* @property {string[]} trust.evaluatedWriters
|
|
29
|
+
* @property {string[]} trust.untrustedWriters
|
|
30
|
+
* @property {ReadonlyArray<{writerId: string, trusted: boolean, reasonCode: string, reason: string}>} trust.explanations
|
|
31
|
+
* @property {Record<string, number> & {recordsScanned: number, activeKeys: number, revokedKeys: number, activeBindings: number, revokedBindings: number}} trust.evidenceSummary
|
|
32
|
+
*/
|
|
33
|
+
|
|
19
34
|
/**
|
|
20
35
|
* Evaluates trust status for a set of writers against the current trust state.
|
|
21
36
|
*
|
|
@@ -25,8 +40,8 @@ import { deriveTrustVerdict } from './verdict.js';
|
|
|
25
40
|
*
|
|
26
41
|
* @param {string[]} writerIds - Writer IDs to evaluate
|
|
27
42
|
* @param {TrustState} trustState - Built trust state from TrustStateBuilder
|
|
28
|
-
* @param {Record<string,
|
|
29
|
-
* @returns {
|
|
43
|
+
* @param {Record<string, unknown>} policy - Trust policy configuration
|
|
44
|
+
* @returns {TrustAssessment} Frozen TrustAssessment object
|
|
30
45
|
*/
|
|
31
46
|
export function evaluateWriters(writerIds, trustState, policy) {
|
|
32
47
|
const policyResult = TrustPolicySchema.safeParse(policy);
|
|
@@ -130,7 +145,7 @@ function evaluateSingleWriter(writerId, trustState) {
|
|
|
130
145
|
*
|
|
131
146
|
* @param {string[]} writerIds
|
|
132
147
|
* @param {string} reasonCode
|
|
133
|
-
* @returns {
|
|
148
|
+
* @returns {TrustAssessment}
|
|
134
149
|
*/
|
|
135
150
|
function buildErrorAssessment(writerIds, reasonCode) {
|
|
136
151
|
const sortedWriters = [...writerIds].sort();
|