@amalgm/live 0.2.30 → 0.2.32
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/PURPOSE.md +30 -1
- package/README.md +1 -0
- package/dist/apply/content-results.d.ts +26 -0
- package/dist/apply/content-results.d.ts.map +1 -0
- package/dist/apply/content-results.js +52 -0
- package/dist/apply/content-results.js.map +1 -0
- package/dist/apply/contracts.d.ts +191 -0
- package/dist/apply/contracts.d.ts.map +1 -0
- package/dist/apply/contracts.js +47 -0
- package/dist/apply/contracts.js.map +1 -0
- package/dist/apply/index.d.ts +10 -0
- package/dist/apply/index.d.ts.map +1 -0
- package/dist/apply/index.js +10 -0
- package/dist/apply/index.js.map +1 -0
- package/dist/apply/local-work.d.ts +10 -0
- package/dist/apply/local-work.d.ts.map +1 -0
- package/dist/apply/local-work.js +17 -0
- package/dist/apply/local-work.js.map +1 -0
- package/dist/apply/plans.d.ts +14 -0
- package/dist/apply/plans.d.ts.map +1 -0
- package/dist/apply/plans.js +183 -0
- package/dist/apply/plans.js.map +1 -0
- package/dist/apply/rail.d.ts +25 -0
- package/dist/apply/rail.d.ts.map +1 -0
- package/dist/apply/rail.js +304 -0
- package/dist/apply/rail.js.map +1 -0
- package/dist/apply/repository-result.d.ts +25 -0
- package/dist/apply/repository-result.d.ts.map +1 -0
- package/dist/apply/repository-result.js +83 -0
- package/dist/apply/repository-result.js.map +1 -0
- package/dist/apply/selection.d.ts +14 -0
- package/dist/apply/selection.d.ts.map +1 -0
- package/dist/apply/selection.js +63 -0
- package/dist/apply/selection.js.map +1 -0
- package/dist/apply/type-adapters.d.ts +13 -0
- package/dist/apply/type-adapters.d.ts.map +1 -0
- package/dist/apply/type-adapters.js +37 -0
- package/dist/apply/type-adapters.js.map +1 -0
- package/dist/detection/adapter-contract.d.ts +11 -8
- package/dist/detection/adapter-contract.d.ts.map +1 -1
- package/dist/detection/adapter-contract.js +5 -5
- package/dist/detection/adapter-contract.js.map +1 -1
- package/dist/detection/echo.d.ts +1 -1
- package/dist/detection/echo.d.ts.map +1 -1
- package/dist/detection/echo.js +8 -1
- package/dist/detection/echo.js.map +1 -1
- package/dist/detection/territory.d.ts +19 -0
- package/dist/detection/territory.d.ts.map +1 -1
- package/dist/detection/territory.js +50 -0
- package/dist/detection/territory.js.map +1 -1
- package/dist/index.d.ts +1 -0
- package/dist/index.d.ts.map +1 -1
- package/dist/index.js +1 -0
- package/dist/index.js.map +1 -1
- package/dist/records/rail.d.ts +2 -0
- package/dist/records/rail.d.ts.map +1 -1
- package/dist/records/rail.js +6 -0
- package/dist/records/rail.js.map +1 -1
- package/dist-cjs/apply/content-results.js +57 -0
- package/dist-cjs/apply/content-results.js.map +1 -0
- package/dist-cjs/apply/contracts.js +53 -0
- package/dist-cjs/apply/contracts.js.map +1 -0
- package/dist-cjs/apply/index.js +28 -0
- package/dist-cjs/apply/index.js.map +1 -0
- package/dist-cjs/apply/local-work.js +20 -0
- package/dist-cjs/apply/local-work.js.map +1 -0
- package/dist-cjs/apply/plans.js +187 -0
- package/dist-cjs/apply/plans.js.map +1 -0
- package/dist-cjs/apply/rail.js +308 -0
- package/dist-cjs/apply/rail.js.map +1 -0
- package/dist-cjs/apply/repository-result.js +86 -0
- package/dist-cjs/apply/repository-result.js.map +1 -0
- package/dist-cjs/apply/selection.js +66 -0
- package/dist-cjs/apply/selection.js.map +1 -0
- package/dist-cjs/apply/type-adapters.js +41 -0
- package/dist-cjs/apply/type-adapters.js.map +1 -0
- package/dist-cjs/detection/adapter-contract.js +5 -5
- package/dist-cjs/detection/adapter-contract.js.map +1 -1
- package/dist-cjs/detection/echo.js +8 -1
- package/dist-cjs/detection/echo.js.map +1 -1
- package/dist-cjs/detection/territory.js +51 -0
- package/dist-cjs/detection/territory.js.map +1 -1
- package/dist-cjs/index.js +1 -0
- package/dist-cjs/index.js.map +1 -1
- package/dist-cjs/records/rail.js +6 -0
- package/dist-cjs/records/rail.js.map +1 -1
- package/package.json +7 -1
|
@@ -0,0 +1,183 @@
|
|
|
1
|
+
/** Type-sensitive Apply plan derivation from one accepted complete result. */
|
|
2
|
+
import { checkContentManifest } from '../contracts/content.js';
|
|
3
|
+
import { assertRecord, stableJson } from '../entities/cloud.js';
|
|
4
|
+
import { utf8Encode } from '../entities/bytes.js';
|
|
5
|
+
import { UUID_PATTERN } from '../entities/types.js';
|
|
6
|
+
import { artifactForRecord, assertTransferArtifact } from '../transfer/artifacts.js';
|
|
7
|
+
import { selectEntityApply } from './selection.js';
|
|
8
|
+
const HASH = /^[0-9a-f]{64}$/;
|
|
9
|
+
const sameArtifact = (left, right) => stableJson(left) === stableJson(right);
|
|
10
|
+
const requireNoCargo = (cargo) => {
|
|
11
|
+
if (cargo.length !== 0)
|
|
12
|
+
throw new Error('structural Apply cannot carry immutable cargo');
|
|
13
|
+
};
|
|
14
|
+
const requireArtifact = (target, cargo) => {
|
|
15
|
+
const expected = artifactForRecord(target);
|
|
16
|
+
if (expected === null)
|
|
17
|
+
throw new Error(`active ${target.type} Apply has no immutable artifact`);
|
|
18
|
+
assertTransferArtifact(expected);
|
|
19
|
+
if (cargo.length !== 1 || !sameArtifact(cargo[0], expected)) {
|
|
20
|
+
throw new Error('Apply cargo does not exactly name its complete result artifact');
|
|
21
|
+
}
|
|
22
|
+
return Object.freeze(expected);
|
|
23
|
+
};
|
|
24
|
+
const textPlan = (base, replay, cargo, materializedPayload) => {
|
|
25
|
+
const artifact = requireArtifact(base.target, cargo);
|
|
26
|
+
if (replay.kind !== 'file.text'
|
|
27
|
+
|| replay.resultPayloadVersion !== base.target.payloadVersion
|
|
28
|
+
|| !HASH.test(replay.resultPayloadVersion)
|
|
29
|
+
|| (replay.basePayloadVersion !== null && !HASH.test(replay.basePayloadVersion))
|
|
30
|
+
|| (replay.mode === 'delta') !== (replay.delta !== null)
|
|
31
|
+
|| !['delta', 'snapshot'].includes(replay.mode)) {
|
|
32
|
+
throw new Error('text Apply replay does not describe its complete result');
|
|
33
|
+
}
|
|
34
|
+
if (replay.delta !== null
|
|
35
|
+
&& (!Number.isSafeInteger(replay.delta.offset) || replay.delta.offset < 0
|
|
36
|
+
|| !Number.isSafeInteger(replay.delta.deleteBytes) || replay.delta.deleteBytes < 0
|
|
37
|
+
|| !(replay.delta.insert instanceof Uint8Array))) {
|
|
38
|
+
throw new Error('text Apply replay has an invalid byte splice');
|
|
39
|
+
}
|
|
40
|
+
const useDelta = replay.mode === 'delta'
|
|
41
|
+
&& replay.delta !== null
|
|
42
|
+
&& replay.basePayloadVersion !== null
|
|
43
|
+
&& materializedPayload === replay.basePayloadVersion;
|
|
44
|
+
return Object.freeze({
|
|
45
|
+
...base,
|
|
46
|
+
kind: 'file.text',
|
|
47
|
+
artifact,
|
|
48
|
+
strategy: useDelta
|
|
49
|
+
? Object.freeze({
|
|
50
|
+
kind: 'delta',
|
|
51
|
+
basePayloadVersion: replay.basePayloadVersion,
|
|
52
|
+
delta: Object.freeze({
|
|
53
|
+
...replay.delta,
|
|
54
|
+
insert: replay.delta.insert.slice(),
|
|
55
|
+
}),
|
|
56
|
+
})
|
|
57
|
+
: Object.freeze({ kind: 'snapshot' }),
|
|
58
|
+
});
|
|
59
|
+
};
|
|
60
|
+
const binaryPlan = (base, replay, cargo) => {
|
|
61
|
+
const artifact = requireArtifact(base.target, cargo);
|
|
62
|
+
const manifest = checkContentManifest(replay.manifest, base.target.payloadVersion);
|
|
63
|
+
if (replay.kind !== 'file.binary'
|
|
64
|
+
|| replay.resultPayloadVersion !== base.target.payloadVersion
|
|
65
|
+
|| !manifest.ok) {
|
|
66
|
+
throw new Error('binary Apply replay does not describe its complete result manifest');
|
|
67
|
+
}
|
|
68
|
+
return Object.freeze({
|
|
69
|
+
...base,
|
|
70
|
+
kind: 'file.binary',
|
|
71
|
+
artifact,
|
|
72
|
+
manifest: Object.freeze({
|
|
73
|
+
...manifest.value,
|
|
74
|
+
chunks: Object.freeze(manifest.value.chunks.map((chunk) => Object.freeze({ ...chunk }))),
|
|
75
|
+
}),
|
|
76
|
+
});
|
|
77
|
+
};
|
|
78
|
+
const linkPlan = (base, replay, cargo, sha256Hex) => {
|
|
79
|
+
const artifact = requireArtifact(base.target, cargo);
|
|
80
|
+
if (replay.kind !== 'link'
|
|
81
|
+
|| replay.resultPayloadVersion !== base.target.payloadVersion
|
|
82
|
+
|| sha256Hex(utf8Encode(replay.target)) !== replay.resultPayloadVersion) {
|
|
83
|
+
throw new Error('link Apply replay does not describe its literal target result');
|
|
84
|
+
}
|
|
85
|
+
return Object.freeze({
|
|
86
|
+
...base,
|
|
87
|
+
kind: 'link',
|
|
88
|
+
artifact,
|
|
89
|
+
targetText: replay.target,
|
|
90
|
+
});
|
|
91
|
+
};
|
|
92
|
+
const repositoryPlan = (base, replay, cargo) => {
|
|
93
|
+
const artifact = requireArtifact(base.target, cargo);
|
|
94
|
+
if (replay.kind !== 'repo.git'
|
|
95
|
+
|| replay.stateId !== base.target.payloadVersion
|
|
96
|
+
|| replay.transportVersion !== base.target.transportVersion
|
|
97
|
+
|| ![replay.stateId, replay.cardId, replay.checkpointId, replay.transportVersion]
|
|
98
|
+
.every((value) => HASH.test(value))
|
|
99
|
+
|| (replay.parentTransportVersion !== null && !HASH.test(replay.parentTransportVersion))
|
|
100
|
+
|| typeof replay.cardChanged !== 'boolean'
|
|
101
|
+
|| typeof replay.checkpointChanged !== 'boolean') {
|
|
102
|
+
throw new Error('repository Apply replay does not describe its Card + Checkpoint result');
|
|
103
|
+
}
|
|
104
|
+
return Object.freeze({
|
|
105
|
+
...base,
|
|
106
|
+
kind: 'repo.git',
|
|
107
|
+
artifact,
|
|
108
|
+
stateId: replay.stateId,
|
|
109
|
+
cardId: replay.cardId,
|
|
110
|
+
checkpointId: replay.checkpointId,
|
|
111
|
+
parentTransportVersion: replay.parentTransportVersion,
|
|
112
|
+
transportVersion: replay.transportVersion,
|
|
113
|
+
cardChanged: replay.cardChanged,
|
|
114
|
+
checkpointChanged: replay.checkpointChanged,
|
|
115
|
+
});
|
|
116
|
+
};
|
|
117
|
+
/**
|
|
118
|
+
* Validate the target's replay/cargo seam and derive the one plan a host may
|
|
119
|
+
* execute. Type is never rediscovered from path, extension, or downloaded
|
|
120
|
+
* bytes. A structural-only record stays structural even when its target is a
|
|
121
|
+
* leaf; its existing immutable head is only repair fallback.
|
|
122
|
+
*/
|
|
123
|
+
export function planEntityApply(work, sha256Hex) {
|
|
124
|
+
return planSelectedEntityApply(work, selectEntityApply(work), sha256Hex);
|
|
125
|
+
}
|
|
126
|
+
/** Derive a plan from the exact selection this coordinator already validated. */
|
|
127
|
+
export function planSelectedEntityApply(work, selected, sha256Hex) {
|
|
128
|
+
const accepted = selected.target;
|
|
129
|
+
const target = Object.freeze(assertRecord(accepted.change.result));
|
|
130
|
+
const common = Object.freeze({
|
|
131
|
+
entityId: accepted.entityId,
|
|
132
|
+
fromSequence: work.resolvedThrough,
|
|
133
|
+
throughSequence: accepted.globalSequence,
|
|
134
|
+
targetMutationId: accepted.mutationId,
|
|
135
|
+
target,
|
|
136
|
+
facets: Object.freeze([...accepted.change.facets]),
|
|
137
|
+
});
|
|
138
|
+
if (target.status !== 'active') {
|
|
139
|
+
if (accepted.change.replay.kind !== 'structure') {
|
|
140
|
+
throw new Error('non-active Apply must be a structural lifecycle result');
|
|
141
|
+
}
|
|
142
|
+
requireNoCargo(accepted.change.cargo);
|
|
143
|
+
return Object.freeze({
|
|
144
|
+
...common,
|
|
145
|
+
kind: 'lifecycle',
|
|
146
|
+
status: target.status,
|
|
147
|
+
});
|
|
148
|
+
}
|
|
149
|
+
if (accepted.change.replay.kind === 'structure') {
|
|
150
|
+
requireNoCargo(accepted.change.cargo);
|
|
151
|
+
if (target.type === 'reference') {
|
|
152
|
+
if (target.payloadVersion === null || !UUID_PATTERN.test(target.payloadVersion)) {
|
|
153
|
+
throw new Error('managed reference Apply has no target entity UUID');
|
|
154
|
+
}
|
|
155
|
+
return Object.freeze({
|
|
156
|
+
...common,
|
|
157
|
+
kind: 'reference',
|
|
158
|
+
targetEntityId: target.payloadVersion.toLowerCase(),
|
|
159
|
+
});
|
|
160
|
+
}
|
|
161
|
+
return Object.freeze({
|
|
162
|
+
...common,
|
|
163
|
+
kind: 'structure',
|
|
164
|
+
repairArtifact: artifactForRecord(target),
|
|
165
|
+
});
|
|
166
|
+
}
|
|
167
|
+
const materializedPayload = work.materialized?.record.payloadVersion ?? null;
|
|
168
|
+
switch (target.type) {
|
|
169
|
+
case 'file.text':
|
|
170
|
+
return textPlan(common, accepted.change.replay, accepted.change.cargo, materializedPayload);
|
|
171
|
+
case 'file.binary':
|
|
172
|
+
return binaryPlan(common, accepted.change.replay, accepted.change.cargo);
|
|
173
|
+
case 'link':
|
|
174
|
+
return linkPlan(common, accepted.change.replay, accepted.change.cargo, sha256Hex);
|
|
175
|
+
case 'repo.git':
|
|
176
|
+
return repositoryPlan(common, accepted.change.replay, accepted.change.cargo);
|
|
177
|
+
case 'workspace':
|
|
178
|
+
case 'folder':
|
|
179
|
+
case 'reference':
|
|
180
|
+
throw new Error(`${target.type} Apply cannot carry content replay`);
|
|
181
|
+
}
|
|
182
|
+
}
|
|
183
|
+
//# sourceMappingURL=plans.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"plans.js","sourceRoot":"","sources":["../../src/apply/plans.ts"],"names":[],"mappings":"AAAA,8EAA8E;AAE9E,OAAO,EAAE,oBAAoB,EAAE,MAAM,yBAAyB,CAAC;AAC/D,OAAO,EAAE,YAAY,EAAE,UAAU,EAAE,MAAM,sBAAsB,CAAC;AAChE,OAAO,EAAE,UAAU,EAAE,MAAM,sBAAsB,CAAC;AAClD,OAAO,EAAE,YAAY,EAAkB,MAAM,sBAAsB,CAAC;AAOpE,OAAO,EAAE,iBAAiB,EAAE,sBAAsB,EAAyB,MAAM,0BAA0B,CAAC;AAS5G,OAAO,EAAE,iBAAiB,EAA4B,MAAM,gBAAgB,CAAC;AAE7E,MAAM,IAAI,GAAG,gBAAgB,CAAC;AAE9B,MAAM,YAAY,GAA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BAAmB,CAAC,CAAC;QAC5G,KAAK,aAAa;YAChB,OAAO,UAAU,CAAC,MAAM,EAAE,QAAQ,CAAC,MAAM,CAAC,MAAsB,EAAE,QAAQ,CAAC,MAAM,CAAC,KAAK,CAAC,CAAC;QAC3F,KAAK,MAAM;YACT,OAAO,QAAQ,CAAC,MAAM,EAAE,QAAQ,CAAC,MAAM,CAAC,MAAoB,EAAE,QAAQ,CAAC,MAAM,CAAC,KAAK,EAAE,SAAS,CAAC,CAAC;QAClG,KAAK,UAAU;YACb,OAAO,cAAc,CAAC,MAAM,EAAE,QAAQ,CAAC,MAAM,CAAC,MAA0B,EAAE,QAAQ,CAAC,MAAM,CAAC,KAAK,CAAC,CAAC;QACnG,KAAK,WAAW,CAAC;QACjB,KAAK,QAAQ,CAAC;QACd,KAAK,WAAW;YACd,MAAM,IAAI,KAAK,CAAC,GAAG,MAAM,CAAC,IAAI,oCAAoC,CAAC,CAAC;IACxE,CAAC;AACH,CAAC"}
|
|
@@ -0,0 +1,25 @@
|
|
|
1
|
+
/** Event-driven portable Apply/Verify orchestration. */
|
|
2
|
+
import { type EntityApplyRailOptions } from './contracts.js';
|
|
3
|
+
export declare const ENTITY_APPLY_DEFAULT_CONCURRENCY = 8;
|
|
4
|
+
export declare const ENTITY_APPLY_DEFAULT_WORK_LIMIT = 64;
|
|
5
|
+
export declare const ENTITY_APPLY_RETRY_BASE_MS = 1000;
|
|
6
|
+
export declare const ENTITY_APPLY_RETRY_MAX_MS = 30000;
|
|
7
|
+
/**
|
|
8
|
+
* Apply has only two wake sources: Receive committed new Inbox work, or local
|
|
9
|
+
* state changed in a way that may release a pending-local gate. Unsettled
|
|
10
|
+
* machine truth alone schedules bounded retry; an idle rail never polls.
|
|
11
|
+
*/
|
|
12
|
+
export declare class EntityApplyRail {
|
|
13
|
+
#private;
|
|
14
|
+
constructor(options: EntityApplyRailOptions);
|
|
15
|
+
/** Resume durable intents and then consume already-received Inbox work. */
|
|
16
|
+
start(): Promise<void>;
|
|
17
|
+
/** Receive calls only after its Inbox transaction commits. */
|
|
18
|
+
recordsAvailable(): void;
|
|
19
|
+
/** Record/Send or Detect calls after a local gate may have changed. */
|
|
20
|
+
localStateChanged(): void;
|
|
21
|
+
/** Await work known at this boundary. It never creates an idle query loop. */
|
|
22
|
+
flush(): Promise<void>;
|
|
23
|
+
stop(): Promise<void>;
|
|
24
|
+
}
|
|
25
|
+
//# sourceMappingURL=rail.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"rail.d.ts","sourceRoot":"","sources":["../../src/apply/rail.ts"],"names":[],"mappings":"AAAA,wDAAwD;AAExD,OAAO,EAKL,KAAK,sBAAsB,EAG5B,MAAM,gBAAgB,CAAC;AAIxB,eAAO,MAAM,gCAAgC,IAAI,CAAC;AAClD,eAAO,MAAM,+BAA+B,KAAK,CAAC;AAClD,eAAO,MAAM,0BAA0B,OAAQ,CAAC;AAChD,eAAO,MAAM,yBAAyB,QAAS,CAAC;AAuBhD;;;;GAIG;AACH,qBAAa,eAAe;;gBAcd,OAAO,EAAE,sBAAsB;IAW3C,2EAA2E;IACrE,KAAK,IAAI,OAAO,CAAC,IAAI,CAAC;IAQ5B,8DAA8D;IAC9D,gBAAgB,IAAI,IAAI;IAMxB,uEAAuE;IACvE,iBAAiB,IAAI,IAAI;IAIzB,8EAA8E;IACxE,KAAK,IAAI,OAAO,CAAC,IAAI,CAAC;IAOtB,IAAI,IAAI,OAAO,CAAC,IAAI,CAAC;CAuP5B"}
|
|
@@ -0,0 +1,304 @@
|
|
|
1
|
+
/** Event-driven portable Apply/Verify orchestration. */
|
|
2
|
+
import { advanceApplyIntent, createApplyIntent, } from './contracts.js';
|
|
3
|
+
import { planSelectedEntityApply } from './plans.js';
|
|
4
|
+
import { selectEntityApply } from './selection.js';
|
|
5
|
+
export const ENTITY_APPLY_DEFAULT_CONCURRENCY = 8;
|
|
6
|
+
export const ENTITY_APPLY_DEFAULT_WORK_LIMIT = 64;
|
|
7
|
+
export const ENTITY_APPLY_RETRY_BASE_MS = 1_000;
|
|
8
|
+
export const ENTITY_APPLY_RETRY_MAX_MS = 30_000;
|
|
9
|
+
async function boundedMap(values, concurrency, visit) {
|
|
10
|
+
const results = new Array(values.length);
|
|
11
|
+
let cursor = 0;
|
|
12
|
+
const workers = Array.from({ length: Math.min(concurrency, values.length) }, async () => {
|
|
13
|
+
while (true) {
|
|
14
|
+
const index = cursor;
|
|
15
|
+
cursor += 1;
|
|
16
|
+
if (index >= values.length)
|
|
17
|
+
return;
|
|
18
|
+
results[index] = await visit(values[index]);
|
|
19
|
+
}
|
|
20
|
+
});
|
|
21
|
+
await Promise.all(workers);
|
|
22
|
+
return results;
|
|
23
|
+
}
|
|
24
|
+
/**
|
|
25
|
+
* Apply has only two wake sources: Receive committed new Inbox work, or local
|
|
26
|
+
* state changed in a way that may release a pending-local gate. Unsettled
|
|
27
|
+
* machine truth alone schedules bounded retry; an idle rail never polls.
|
|
28
|
+
*/
|
|
29
|
+
export class EntityApplyRail {
|
|
30
|
+
#options;
|
|
31
|
+
#concurrency;
|
|
32
|
+
#workLimit;
|
|
33
|
+
#onBackgroundError;
|
|
34
|
+
#started = false;
|
|
35
|
+
#stopped = false;
|
|
36
|
+
#needsApply = false;
|
|
37
|
+
#retryRequested = false;
|
|
38
|
+
#running = null;
|
|
39
|
+
#retry = null;
|
|
40
|
+
#retryAttempt = 0;
|
|
41
|
+
constructor(options) {
|
|
42
|
+
this.#options = options;
|
|
43
|
+
this.#concurrency = options.concurrency ?? ENTITY_APPLY_DEFAULT_CONCURRENCY;
|
|
44
|
+
this.#workLimit = options.workLimit ?? ENTITY_APPLY_DEFAULT_WORK_LIMIT;
|
|
45
|
+
this.#onBackgroundError = options.onBackgroundError ?? (() => undefined);
|
|
46
|
+
if (!Number.isSafeInteger(this.#concurrency) || this.#concurrency < 1
|
|
47
|
+
|| !Number.isSafeInteger(this.#workLimit) || this.#workLimit < 1) {
|
|
48
|
+
throw new Error('entity Apply concurrency and work limit must be positive integers');
|
|
49
|
+
}
|
|
50
|
+
}
|
|
51
|
+
/** Resume durable intents and then consume already-received Inbox work. */
|
|
52
|
+
async start() {
|
|
53
|
+
if (this.#started)
|
|
54
|
+
throw new Error('entity Apply rail already started');
|
|
55
|
+
if (this.#stopped)
|
|
56
|
+
throw new Error('entity Apply rail is stopped');
|
|
57
|
+
this.#started = true;
|
|
58
|
+
this.#needsApply = true;
|
|
59
|
+
await this.#runExplicitly();
|
|
60
|
+
}
|
|
61
|
+
/** Receive calls only after its Inbox transaction commits. */
|
|
62
|
+
recordsAvailable() {
|
|
63
|
+
if (this.#stopped)
|
|
64
|
+
return;
|
|
65
|
+
this.#needsApply = true;
|
|
66
|
+
if (this.#started)
|
|
67
|
+
this.#kick();
|
|
68
|
+
}
|
|
69
|
+
/** Record/Send or Detect calls after a local gate may have changed. */
|
|
70
|
+
localStateChanged() {
|
|
71
|
+
this.recordsAvailable();
|
|
72
|
+
}
|
|
73
|
+
/** Await work known at this boundary. It never creates an idle query loop. */
|
|
74
|
+
async flush() {
|
|
75
|
+
if (!this.#started)
|
|
76
|
+
throw new Error('entity Apply rail has not started');
|
|
77
|
+
if (this.#stopped)
|
|
78
|
+
return;
|
|
79
|
+
this.#needsApply = true;
|
|
80
|
+
await this.#runExplicitly();
|
|
81
|
+
}
|
|
82
|
+
async stop() {
|
|
83
|
+
if (this.#stopped)
|
|
84
|
+
return;
|
|
85
|
+
this.#stopped = true;
|
|
86
|
+
this.#cancelRetry();
|
|
87
|
+
await this.#running?.catch(() => undefined);
|
|
88
|
+
}
|
|
89
|
+
async #runExplicitly() {
|
|
90
|
+
this.#cancelRetry();
|
|
91
|
+
try {
|
|
92
|
+
// A finishing drain can hand a late flag to a successor from its final
|
|
93
|
+
// microtask. An explicit caller owns that successor as well.
|
|
94
|
+
do {
|
|
95
|
+
await this.#ensureRun();
|
|
96
|
+
} while (!this.#stopped && (this.#needsApply || this.#running !== null));
|
|
97
|
+
if (this.#retryRequested)
|
|
98
|
+
this.#scheduleRetry();
|
|
99
|
+
else
|
|
100
|
+
this.#retryAttempt = 0;
|
|
101
|
+
}
|
|
102
|
+
catch (error) {
|
|
103
|
+
this.#scheduleRetry();
|
|
104
|
+
throw error;
|
|
105
|
+
}
|
|
106
|
+
}
|
|
107
|
+
#kick() {
|
|
108
|
+
if (!this.#started || this.#stopped)
|
|
109
|
+
return;
|
|
110
|
+
this.#cancelRetry();
|
|
111
|
+
void this.#ensureRun().then(() => {
|
|
112
|
+
if (this.#retryRequested)
|
|
113
|
+
this.#scheduleRetry();
|
|
114
|
+
else
|
|
115
|
+
this.#retryAttempt = 0;
|
|
116
|
+
}, (error) => {
|
|
117
|
+
this.#onBackgroundError(error);
|
|
118
|
+
this.#scheduleRetry();
|
|
119
|
+
});
|
|
120
|
+
}
|
|
121
|
+
#ensureRun() {
|
|
122
|
+
if (this.#running)
|
|
123
|
+
return this.#running;
|
|
124
|
+
const running = this.#drain();
|
|
125
|
+
this.#running = running;
|
|
126
|
+
void running.finally(() => {
|
|
127
|
+
if (this.#running === running)
|
|
128
|
+
this.#running = null;
|
|
129
|
+
if (!this.#stopped && this.#needsApply)
|
|
130
|
+
this.#kick();
|
|
131
|
+
}).catch(() => undefined);
|
|
132
|
+
return running;
|
|
133
|
+
}
|
|
134
|
+
async #drain() {
|
|
135
|
+
this.#retryRequested = false;
|
|
136
|
+
while (!this.#stopped && this.#needsApply) {
|
|
137
|
+
this.#needsApply = false;
|
|
138
|
+
const entities = new Set();
|
|
139
|
+
const cursors = new Set();
|
|
140
|
+
let afterCursor = null;
|
|
141
|
+
let madeProgress = false;
|
|
142
|
+
do {
|
|
143
|
+
const page = await this.#options.store.readApplyWork(this.#workLimit, afterCursor);
|
|
144
|
+
if (!page || !Array.isArray(page.work)
|
|
145
|
+
|| (page.nextCursor !== null
|
|
146
|
+
&& (typeof page.nextCursor !== 'string' || page.nextCursor.length === 0))) {
|
|
147
|
+
throw new Error('entity Apply store returned an invalid work page');
|
|
148
|
+
}
|
|
149
|
+
if (page.work.length > this.#workLimit
|
|
150
|
+
|| (page.work.length === 0 && page.nextCursor !== null)) {
|
|
151
|
+
throw new Error('entity Apply store violated its work-page bound');
|
|
152
|
+
}
|
|
153
|
+
for (const item of page.work) {
|
|
154
|
+
if (entities.has(item.entityId)) {
|
|
155
|
+
throw new Error(`entity Apply store returned ${item.entityId} twice in one scan`);
|
|
156
|
+
}
|
|
157
|
+
entities.add(item.entityId);
|
|
158
|
+
}
|
|
159
|
+
const results = await boundedMap(page.work, this.#concurrency, (item) => this.#applyOne(item));
|
|
160
|
+
if (results.includes('retry'))
|
|
161
|
+
this.#retryRequested = true;
|
|
162
|
+
if (results.includes('progress'))
|
|
163
|
+
madeProgress = true;
|
|
164
|
+
afterCursor = page.nextCursor;
|
|
165
|
+
if (afterCursor !== null && cursors.has(afterCursor)) {
|
|
166
|
+
throw new Error('entity Apply store repeated a work-page cursor');
|
|
167
|
+
}
|
|
168
|
+
if (afterCursor !== null)
|
|
169
|
+
cursors.add(afterCursor);
|
|
170
|
+
} while (!this.#stopped && afterCursor !== null);
|
|
171
|
+
if (madeProgress)
|
|
172
|
+
this.#needsApply = true;
|
|
173
|
+
}
|
|
174
|
+
}
|
|
175
|
+
async #applyOne(work) {
|
|
176
|
+
const selected = selectEntityApply(work);
|
|
177
|
+
if (work.intent === null) {
|
|
178
|
+
if (await this.#options.store.hasLocalWorkAfter(work.authorityId, work.entityId, selected.target.globalSequence)) {
|
|
179
|
+
return 'blocked';
|
|
180
|
+
}
|
|
181
|
+
}
|
|
182
|
+
const plan = planSelectedEntityApply(work, selected, this.#options.sha256Hex);
|
|
183
|
+
const adapter = this.#options.effects.adapterFor(plan.target.type);
|
|
184
|
+
let intent;
|
|
185
|
+
if (work.intent === null) {
|
|
186
|
+
intent = createApplyIntent({
|
|
187
|
+
authorityId: work.authorityId,
|
|
188
|
+
entityId: work.entityId,
|
|
189
|
+
fromSequence: work.resolvedThrough,
|
|
190
|
+
target: selected.target,
|
|
191
|
+
createdAt: this.#options.now(),
|
|
192
|
+
});
|
|
193
|
+
await this.#options.store.beginIntent(intent);
|
|
194
|
+
}
|
|
195
|
+
else {
|
|
196
|
+
intent = work.intent;
|
|
197
|
+
}
|
|
198
|
+
if (intent.phase !== 'revealed'
|
|
199
|
+
&& await this.#options.store.hasLocalWorkAfter(intent.authorityId, intent.entityId, intent.throughSequence)) {
|
|
200
|
+
await this.#abandon(intent, plan, adapter);
|
|
201
|
+
return 'progress';
|
|
202
|
+
}
|
|
203
|
+
if (intent.phase === 'declared') {
|
|
204
|
+
const guard = await adapter.apply.guard(intent, plan);
|
|
205
|
+
if (guard.kind === 'retry')
|
|
206
|
+
return 'retry';
|
|
207
|
+
if (guard.kind === 'local-change') {
|
|
208
|
+
if (!await this.#options.store.hasLocalWorkAfter(intent.authorityId, intent.entityId, intent.throughSequence)) {
|
|
209
|
+
await this.#options.effects.captureLocal(intent, plan, 'before-reveal');
|
|
210
|
+
}
|
|
211
|
+
if (!await this.#options.store.hasLocalWorkAfter(intent.authorityId, intent.entityId, intent.throughSequence)) {
|
|
212
|
+
throw new Error('Apply local capture returned without durable Outbox work after its target');
|
|
213
|
+
}
|
|
214
|
+
await this.#abandon(intent, plan, adapter);
|
|
215
|
+
return 'progress';
|
|
216
|
+
}
|
|
217
|
+
if (guard.kind === 'already-target') {
|
|
218
|
+
// Revealed means visible ground owns the target, whether this pass
|
|
219
|
+
// installed it or the early guard proved it was already present.
|
|
220
|
+
intent = advanceApplyIntent(advanceApplyIntent(intent, 'prepared'), 'revealed');
|
|
221
|
+
await this.#options.store.setIntentPhase(intent);
|
|
222
|
+
}
|
|
223
|
+
else {
|
|
224
|
+
if (await this.#options.store.hasLocalWorkAfter(intent.authorityId, intent.entityId, intent.throughSequence)) {
|
|
225
|
+
await this.#abandon(intent, plan, adapter);
|
|
226
|
+
return 'progress';
|
|
227
|
+
}
|
|
228
|
+
await adapter.apply.prepare(intent, plan);
|
|
229
|
+
intent = advanceApplyIntent(intent, 'prepared');
|
|
230
|
+
await this.#options.store.setIntentPhase(intent);
|
|
231
|
+
}
|
|
232
|
+
}
|
|
233
|
+
if (intent.phase === 'prepared') {
|
|
234
|
+
if (await this.#options.store.hasLocalWorkAfter(intent.authorityId, intent.entityId, intent.throughSequence)) {
|
|
235
|
+
await this.#abandon(intent, plan, adapter);
|
|
236
|
+
return 'progress';
|
|
237
|
+
}
|
|
238
|
+
const guard = await adapter.apply.guard(intent, plan);
|
|
239
|
+
if (guard.kind === 'retry')
|
|
240
|
+
return 'retry';
|
|
241
|
+
if (guard.kind === 'local-change') {
|
|
242
|
+
if (!await this.#options.store.hasLocalWorkAfter(intent.authorityId, intent.entityId, intent.throughSequence)) {
|
|
243
|
+
await this.#options.effects.captureLocal(intent, plan, 'before-reveal');
|
|
244
|
+
}
|
|
245
|
+
if (!await this.#options.store.hasLocalWorkAfter(intent.authorityId, intent.entityId, intent.throughSequence)) {
|
|
246
|
+
throw new Error('Apply local capture returned without durable Outbox work after its target');
|
|
247
|
+
}
|
|
248
|
+
await this.#abandon(intent, plan, adapter);
|
|
249
|
+
return 'progress';
|
|
250
|
+
}
|
|
251
|
+
if (guard.kind === 'safe') {
|
|
252
|
+
// Close the window between the disk guard and the reveal as far as the
|
|
253
|
+
// durable local queue can prove. The host's recoverable replacement
|
|
254
|
+
// owns the remaining syscall-sized race.
|
|
255
|
+
if (await this.#options.store.hasLocalWorkAfter(intent.authorityId, intent.entityId, intent.throughSequence)) {
|
|
256
|
+
await this.#abandon(intent, plan, adapter);
|
|
257
|
+
return 'progress';
|
|
258
|
+
}
|
|
259
|
+
await adapter.apply.reveal(intent, plan);
|
|
260
|
+
}
|
|
261
|
+
intent = advanceApplyIntent(intent, 'revealed');
|
|
262
|
+
await this.#options.store.setIntentPhase(intent);
|
|
263
|
+
}
|
|
264
|
+
const verification = await adapter.verify.verify(intent, plan);
|
|
265
|
+
if (verification.kind === 'retry')
|
|
266
|
+
return 'retry';
|
|
267
|
+
if (verification.kind === 'local-change') {
|
|
268
|
+
if (!await this.#options.store.hasLocalWorkAfter(intent.authorityId, intent.entityId, intent.throughSequence)) {
|
|
269
|
+
await this.#options.effects.captureLocal(intent, plan, 'after-reveal');
|
|
270
|
+
}
|
|
271
|
+
if (!await this.#options.store.hasLocalWorkAfter(intent.authorityId, intent.entityId, intent.throughSequence)) {
|
|
272
|
+
throw new Error('Apply post-reveal capture returned without durable Outbox work after its target');
|
|
273
|
+
}
|
|
274
|
+
await adapter.apply.discard(intent, plan);
|
|
275
|
+
await this.#options.store.completeIntent(intent, { kind: 'superseded-by-local' });
|
|
276
|
+
return 'progress';
|
|
277
|
+
}
|
|
278
|
+
await adapter.apply.discard(intent, plan);
|
|
279
|
+
await this.#options.store.completeIntent(intent, { kind: 'materialized' });
|
|
280
|
+
return 'progress';
|
|
281
|
+
}
|
|
282
|
+
async #abandon(intent, plan, adapter) {
|
|
283
|
+
await adapter.apply.discard(intent, plan);
|
|
284
|
+
await this.#options.store.cancelIntent(intent);
|
|
285
|
+
}
|
|
286
|
+
#scheduleRetry() {
|
|
287
|
+
if (this.#stopped || this.#retry)
|
|
288
|
+
return;
|
|
289
|
+
const base = Math.min(ENTITY_APPLY_RETRY_MAX_MS, ENTITY_APPLY_RETRY_BASE_MS * (2 ** Math.min(this.#retryAttempt, 16)));
|
|
290
|
+
const random = Math.max(0, Math.min(1, this.#options.schedule.random()));
|
|
291
|
+
const delay = Math.round(base * (0.5 + random));
|
|
292
|
+
this.#retryAttempt += 1;
|
|
293
|
+
this.#retry = this.#options.schedule.schedule(delay, () => {
|
|
294
|
+
this.#retry = null;
|
|
295
|
+
this.#needsApply = true;
|
|
296
|
+
this.#kick();
|
|
297
|
+
});
|
|
298
|
+
}
|
|
299
|
+
#cancelRetry() {
|
|
300
|
+
this.#retry?.cancel();
|
|
301
|
+
this.#retry = null;
|
|
302
|
+
}
|
|
303
|
+
}
|
|
304
|
+
//# sourceMappingURL=rail.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,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C,MAAM,EAAE,CAAC,CAAC,CAAC;QACzE,MAAM,KAAK,GAAG,IAAI,CAAC,KAAK,CAAC,IAAI,GAAG,CAAC,GAAG,GAAG,MAAM,CAAC,CAAC,CAAC;QAChD,IAAI,CAAC,aAAa,IAAI,CAAC,CAAC;QACxB,IAAI,CAAC,MAAM,GAAG,IAAI,CAAC,QAAQ,CAAC,QAAQ,CAAC,QAAQ,CAAC,KAAK,EAAE,GAAG,EAAE;YACxD,IAAI,CAAC,MAAM,GAAG,IAAI,CAAC;YACnB,IAAI,CAAC,WAAW,GAAG,IAAI,CAAC;YACxB,IAAI,CAAC,KAAK,EAAE,CAAC;QACf,CAAC,CAAC,CAAC;IACL,CAAC;IAED,YAAY;QACV,IAAI,CAAC,MAAM,EAAE,MAAM,EAAE,CAAC;QACtB,IAAI,CAAC,MAAM,GAAG,IAAI,CAAC;IACrB,CAAC;CACF"}
|
|
@@ -0,0 +1,25 @@
|
|
|
1
|
+
/** Portable proof of one incremental Git Card + Checkpoint transport chain. */
|
|
2
|
+
import { type RepoIdentityEntry, type RepositoryTransport } from '../entities/repo-states.js';
|
|
3
|
+
import type { Sha256Hex } from '../entities/types.js';
|
|
4
|
+
import type { RepositoryApplyPlan } from './contracts.js';
|
|
5
|
+
export interface SealedRepositoryApplyNode {
|
|
6
|
+
readonly transportVersion: string;
|
|
7
|
+
readonly bytes: Uint8Array;
|
|
8
|
+
}
|
|
9
|
+
export interface RepositoryApplyBase {
|
|
10
|
+
readonly transportVersion: string | null;
|
|
11
|
+
readonly identity: readonly RepoIdentityEntry[] | null;
|
|
12
|
+
}
|
|
13
|
+
export interface PreparedRepositoryResult {
|
|
14
|
+
readonly transports: readonly RepositoryTransport[];
|
|
15
|
+
readonly latest: RepositoryTransport;
|
|
16
|
+
readonly transportVersion: string;
|
|
17
|
+
readonly identity: readonly RepoIdentityEntry[];
|
|
18
|
+
}
|
|
19
|
+
/**
|
|
20
|
+
* Verify a sealed transport suffix before a host invokes Git. With a null
|
|
21
|
+
* base the chain must be complete from its reset node. With a durable local
|
|
22
|
+
* base, the first incremental node must name that exact transport frontier.
|
|
23
|
+
*/
|
|
24
|
+
export declare function prepareRepositoryResult(plan: RepositoryApplyPlan, nodes: readonly SealedRepositoryApplyNode[], base: RepositoryApplyBase, sha256Hex: Sha256Hex): PreparedRepositoryResult;
|
|
25
|
+
//# sourceMappingURL=repository-result.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"repository-result.d.ts","sourceRoot":"","sources":["../../src/apply/repository-result.ts"],"names":[],"mappings":"AAAA,+EAA+E;AAE/E,OAAO,EAML,KAAK,iBAAiB,EACtB,KAAK,mBAAmB,EACzB,MAAM,4BAA4B,CAAC;AACpC,OAAO,KAAK,EAAE,SAAS,EAAE,MAAM,sBAAsB,CAAC;AACtD,OAAO,KAAK,EAAE,mBAAmB,EAAE,MAAM,gBAAgB,CAAC;AAE1D,MAAM,WAAW,yBAAyB;IACxC,QAAQ,CAAC,gBAAgB,EAAE,MAAM,CAAC;IAClC,QAAQ,CAAC,KAAK,EAAE,UAAU,CAAC;CAC5B;AAED,MAAM,WAAW,mBAAmB;IAClC,QAAQ,CAAC,gBAAgB,EAAE,MAAM,GAAG,IAAI,CAAC;IACzC,QAAQ,CAAC,QAAQ,EAAE,SAAS,iBAAiB,EAAE,GAAG,IAAI,CAAC;CACxD;AAED,MAAM,WAAW,wBAAwB;IACvC,QAAQ,CAAC,UAAU,EAAE,SAAS,mBAAmB,EAAE,CAAC;IACpD,QAAQ,CAAC,MAAM,EAAE,mBAAmB,CAAC;IACrC,QAAQ,CAAC,gBAAgB,EAAE,MAAM,CAAC;IAClC,QAAQ,CAAC,QAAQ,EAAE,SAAS,iBAAiB,EAAE,CAAC;CACjD;AAsCD;;;;GAIG;AACH,wBAAgB,uBAAuB,CACrC,IAAI,EAAE,mBAAmB,EACzB,KAAK,EAAE,SAAS,yBAAyB,EAAE,EAC3C,IAAI,EAAE,mBAAmB,EACzB,SAAS,EAAE,SAAS,GACnB,wBAAwB,CAuC1B"}
|