@amalgm/live 0.2.29 → 0.2.31

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.
Files changed (93) hide show
  1. package/PURPOSE.md +37 -2
  2. package/README.md +1 -0
  3. package/dist/apply/content-results.d.ts +26 -0
  4. package/dist/apply/content-results.d.ts.map +1 -0
  5. package/dist/apply/content-results.js +52 -0
  6. package/dist/apply/content-results.js.map +1 -0
  7. package/dist/apply/contracts.d.ts +191 -0
  8. package/dist/apply/contracts.d.ts.map +1 -0
  9. package/dist/apply/contracts.js +47 -0
  10. package/dist/apply/contracts.js.map +1 -0
  11. package/dist/apply/index.d.ts +10 -0
  12. package/dist/apply/index.d.ts.map +1 -0
  13. package/dist/apply/index.js +10 -0
  14. package/dist/apply/index.js.map +1 -0
  15. package/dist/apply/local-work.d.ts +10 -0
  16. package/dist/apply/local-work.d.ts.map +1 -0
  17. package/dist/apply/local-work.js +17 -0
  18. package/dist/apply/local-work.js.map +1 -0
  19. package/dist/apply/plans.d.ts +14 -0
  20. package/dist/apply/plans.d.ts.map +1 -0
  21. package/dist/apply/plans.js +183 -0
  22. package/dist/apply/plans.js.map +1 -0
  23. package/dist/apply/rail.d.ts +25 -0
  24. package/dist/apply/rail.d.ts.map +1 -0
  25. package/dist/apply/rail.js +304 -0
  26. package/dist/apply/rail.js.map +1 -0
  27. package/dist/apply/repository-result.d.ts +25 -0
  28. package/dist/apply/repository-result.d.ts.map +1 -0
  29. package/dist/apply/repository-result.js +83 -0
  30. package/dist/apply/repository-result.js.map +1 -0
  31. package/dist/apply/selection.d.ts +14 -0
  32. package/dist/apply/selection.d.ts.map +1 -0
  33. package/dist/apply/selection.js +63 -0
  34. package/dist/apply/selection.js.map +1 -0
  35. package/dist/apply/type-adapters.d.ts +13 -0
  36. package/dist/apply/type-adapters.d.ts.map +1 -0
  37. package/dist/apply/type-adapters.js +37 -0
  38. package/dist/apply/type-adapters.js.map +1 -0
  39. package/dist/detection/adapter-contract.d.ts +11 -8
  40. package/dist/detection/adapter-contract.d.ts.map +1 -1
  41. package/dist/detection/adapter-contract.js +5 -5
  42. package/dist/detection/adapter-contract.js.map +1 -1
  43. package/dist/detection/echo.d.ts +1 -1
  44. package/dist/detection/echo.d.ts.map +1 -1
  45. package/dist/detection/echo.js +8 -1
  46. package/dist/detection/echo.js.map +1 -1
  47. package/dist/index.d.ts +1 -0
  48. package/dist/index.d.ts.map +1 -1
  49. package/dist/index.js +1 -0
  50. package/dist/index.js.map +1 -1
  51. package/dist/records/index.d.ts +2 -0
  52. package/dist/records/index.d.ts.map +1 -1
  53. package/dist/records/index.js +2 -0
  54. package/dist/records/index.js.map +1 -1
  55. package/dist/records/rail.d.ts +97 -0
  56. package/dist/records/rail.d.ts.map +1 -0
  57. package/dist/records/rail.js +250 -0
  58. package/dist/records/rail.js.map +1 -0
  59. package/dist/records/wire.d.ts +63 -0
  60. package/dist/records/wire.d.ts.map +1 -0
  61. package/dist/records/wire.js +86 -0
  62. package/dist/records/wire.js.map +1 -0
  63. package/dist-cjs/apply/content-results.js +57 -0
  64. package/dist-cjs/apply/content-results.js.map +1 -0
  65. package/dist-cjs/apply/contracts.js +53 -0
  66. package/dist-cjs/apply/contracts.js.map +1 -0
  67. package/dist-cjs/apply/index.js +28 -0
  68. package/dist-cjs/apply/index.js.map +1 -0
  69. package/dist-cjs/apply/local-work.js +20 -0
  70. package/dist-cjs/apply/local-work.js.map +1 -0
  71. package/dist-cjs/apply/plans.js +187 -0
  72. package/dist-cjs/apply/plans.js.map +1 -0
  73. package/dist-cjs/apply/rail.js +308 -0
  74. package/dist-cjs/apply/rail.js.map +1 -0
  75. package/dist-cjs/apply/repository-result.js +86 -0
  76. package/dist-cjs/apply/repository-result.js.map +1 -0
  77. package/dist-cjs/apply/selection.js +66 -0
  78. package/dist-cjs/apply/selection.js.map +1 -0
  79. package/dist-cjs/apply/type-adapters.js +41 -0
  80. package/dist-cjs/apply/type-adapters.js.map +1 -0
  81. package/dist-cjs/detection/adapter-contract.js +5 -5
  82. package/dist-cjs/detection/adapter-contract.js.map +1 -1
  83. package/dist-cjs/detection/echo.js +8 -1
  84. package/dist-cjs/detection/echo.js.map +1 -1
  85. package/dist-cjs/index.js +1 -0
  86. package/dist-cjs/index.js.map +1 -1
  87. package/dist-cjs/records/index.js +2 -0
  88. package/dist-cjs/records/index.js.map +1 -1
  89. package/dist-cjs/records/rail.js +254 -0
  90. package/dist-cjs/records/rail.js.map +1 -0
  91. package/dist-cjs/records/wire.js +91 -0
  92. package/dist-cjs/records/wire.js.map +1 -0
  93. package/package.json +7 -1
@@ -0,0 +1,187 @@
1
+ "use strict";
2
+ /** Type-sensitive Apply plan derivation from one accepted complete result. */
3
+ Object.defineProperty(exports, "__esModule", { value: true });
4
+ exports.planEntityApply = planEntityApply;
5
+ exports.planSelectedEntityApply = planSelectedEntityApply;
6
+ const content_js_1 = require("../contracts/content.js");
7
+ const cloud_js_1 = require("../entities/cloud.js");
8
+ const bytes_js_1 = require("../entities/bytes.js");
9
+ const types_js_1 = require("../entities/types.js");
10
+ const artifacts_js_1 = require("../transfer/artifacts.js");
11
+ const selection_js_1 = require("./selection.js");
12
+ const HASH = /^[0-9a-f]{64}$/;
13
+ const sameArtifact = (left, right) => (0, cloud_js_1.stableJson)(left) === (0, cloud_js_1.stableJson)(right);
14
+ const requireNoCargo = (cargo) => {
15
+ if (cargo.length !== 0)
16
+ throw new Error('structural Apply cannot carry immutable cargo');
17
+ };
18
+ const requireArtifact = (target, cargo) => {
19
+ const expected = (0, artifacts_js_1.artifactForRecord)(target);
20
+ if (expected === null)
21
+ throw new Error(`active ${target.type} Apply has no immutable artifact`);
22
+ (0, artifacts_js_1.assertTransferArtifact)(expected);
23
+ if (cargo.length !== 1 || !sameArtifact(cargo[0], expected)) {
24
+ throw new Error('Apply cargo does not exactly name its complete result artifact');
25
+ }
26
+ return Object.freeze(expected);
27
+ };
28
+ const textPlan = (base, replay, cargo, materializedPayload) => {
29
+ const artifact = requireArtifact(base.target, cargo);
30
+ if (replay.kind !== 'file.text'
31
+ || replay.resultPayloadVersion !== base.target.payloadVersion
32
+ || !HASH.test(replay.resultPayloadVersion)
33
+ || (replay.basePayloadVersion !== null && !HASH.test(replay.basePayloadVersion))
34
+ || (replay.mode === 'delta') !== (replay.delta !== null)
35
+ || !['delta', 'snapshot'].includes(replay.mode)) {
36
+ throw new Error('text Apply replay does not describe its complete result');
37
+ }
38
+ if (replay.delta !== null
39
+ && (!Number.isSafeInteger(replay.delta.offset) || replay.delta.offset < 0
40
+ || !Number.isSafeInteger(replay.delta.deleteBytes) || replay.delta.deleteBytes < 0
41
+ || !(replay.delta.insert instanceof Uint8Array))) {
42
+ throw new Error('text Apply replay has an invalid byte splice');
43
+ }
44
+ const useDelta = replay.mode === 'delta'
45
+ && replay.delta !== null
46
+ && replay.basePayloadVersion !== null
47
+ && materializedPayload === replay.basePayloadVersion;
48
+ return Object.freeze({
49
+ ...base,
50
+ kind: 'file.text',
51
+ artifact,
52
+ strategy: useDelta
53
+ ? Object.freeze({
54
+ kind: 'delta',
55
+ basePayloadVersion: replay.basePayloadVersion,
56
+ delta: Object.freeze({
57
+ ...replay.delta,
58
+ insert: replay.delta.insert.slice(),
59
+ }),
60
+ })
61
+ : Object.freeze({ kind: 'snapshot' }),
62
+ });
63
+ };
64
+ const binaryPlan = (base, replay, cargo) => {
65
+ const artifact = requireArtifact(base.target, cargo);
66
+ const manifest = (0, content_js_1.checkContentManifest)(replay.manifest, base.target.payloadVersion);
67
+ if (replay.kind !== 'file.binary'
68
+ || replay.resultPayloadVersion !== base.target.payloadVersion
69
+ || !manifest.ok) {
70
+ throw new Error('binary Apply replay does not describe its complete result manifest');
71
+ }
72
+ return Object.freeze({
73
+ ...base,
74
+ kind: 'file.binary',
75
+ artifact,
76
+ manifest: Object.freeze({
77
+ ...manifest.value,
78
+ chunks: Object.freeze(manifest.value.chunks.map((chunk) => Object.freeze({ ...chunk }))),
79
+ }),
80
+ });
81
+ };
82
+ const linkPlan = (base, replay, cargo, sha256Hex) => {
83
+ const artifact = requireArtifact(base.target, cargo);
84
+ if (replay.kind !== 'link'
85
+ || replay.resultPayloadVersion !== base.target.payloadVersion
86
+ || sha256Hex((0, bytes_js_1.utf8Encode)(replay.target)) !== replay.resultPayloadVersion) {
87
+ throw new Error('link Apply replay does not describe its literal target result');
88
+ }
89
+ return Object.freeze({
90
+ ...base,
91
+ kind: 'link',
92
+ artifact,
93
+ targetText: replay.target,
94
+ });
95
+ };
96
+ const repositoryPlan = (base, replay, cargo) => {
97
+ const artifact = requireArtifact(base.target, cargo);
98
+ if (replay.kind !== 'repo.git'
99
+ || replay.stateId !== base.target.payloadVersion
100
+ || replay.transportVersion !== base.target.transportVersion
101
+ || ![replay.stateId, replay.cardId, replay.checkpointId, replay.transportVersion]
102
+ .every((value) => HASH.test(value))
103
+ || (replay.parentTransportVersion !== null && !HASH.test(replay.parentTransportVersion))
104
+ || typeof replay.cardChanged !== 'boolean'
105
+ || typeof replay.checkpointChanged !== 'boolean') {
106
+ throw new Error('repository Apply replay does not describe its Card + Checkpoint result');
107
+ }
108
+ return Object.freeze({
109
+ ...base,
110
+ kind: 'repo.git',
111
+ artifact,
112
+ stateId: replay.stateId,
113
+ cardId: replay.cardId,
114
+ checkpointId: replay.checkpointId,
115
+ parentTransportVersion: replay.parentTransportVersion,
116
+ transportVersion: replay.transportVersion,
117
+ cardChanged: replay.cardChanged,
118
+ checkpointChanged: replay.checkpointChanged,
119
+ });
120
+ };
121
+ /**
122
+ * Validate the target's replay/cargo seam and derive the one plan a host may
123
+ * execute. Type is never rediscovered from path, extension, or downloaded
124
+ * bytes. A structural-only record stays structural even when its target is a
125
+ * leaf; its existing immutable head is only repair fallback.
126
+ */
127
+ function planEntityApply(work, sha256Hex) {
128
+ return planSelectedEntityApply(work, (0, selection_js_1.selectEntityApply)(work), sha256Hex);
129
+ }
130
+ /** Derive a plan from the exact selection this coordinator already validated. */
131
+ function planSelectedEntityApply(work, selected, sha256Hex) {
132
+ const accepted = selected.target;
133
+ const target = Object.freeze((0, cloud_js_1.assertRecord)(accepted.change.result));
134
+ const common = Object.freeze({
135
+ entityId: accepted.entityId,
136
+ fromSequence: work.resolvedThrough,
137
+ throughSequence: accepted.globalSequence,
138
+ targetMutationId: accepted.mutationId,
139
+ target,
140
+ facets: Object.freeze([...accepted.change.facets]),
141
+ });
142
+ if (target.status !== 'active') {
143
+ if (accepted.change.replay.kind !== 'structure') {
144
+ throw new Error('non-active Apply must be a structural lifecycle result');
145
+ }
146
+ requireNoCargo(accepted.change.cargo);
147
+ return Object.freeze({
148
+ ...common,
149
+ kind: 'lifecycle',
150
+ status: target.status,
151
+ });
152
+ }
153
+ if (accepted.change.replay.kind === 'structure') {
154
+ requireNoCargo(accepted.change.cargo);
155
+ if (target.type === 'reference') {
156
+ if (target.payloadVersion === null || !types_js_1.UUID_PATTERN.test(target.payloadVersion)) {
157
+ throw new Error('managed reference Apply has no target entity UUID');
158
+ }
159
+ return Object.freeze({
160
+ ...common,
161
+ kind: 'reference',
162
+ targetEntityId: target.payloadVersion.toLowerCase(),
163
+ });
164
+ }
165
+ return Object.freeze({
166
+ ...common,
167
+ kind: 'structure',
168
+ repairArtifact: (0, artifacts_js_1.artifactForRecord)(target),
169
+ });
170
+ }
171
+ const materializedPayload = work.materialized?.record.payloadVersion ?? null;
172
+ switch (target.type) {
173
+ case 'file.text':
174
+ return textPlan(common, accepted.change.replay, accepted.change.cargo, materializedPayload);
175
+ case 'file.binary':
176
+ return binaryPlan(common, accepted.change.replay, accepted.change.cargo);
177
+ case 'link':
178
+ return linkPlan(common, accepted.change.replay, accepted.change.cargo, sha256Hex);
179
+ case 'repo.git':
180
+ return repositoryPlan(common, accepted.change.replay, accepted.change.cargo);
181
+ case 'workspace':
182
+ case 'folder':
183
+ case 'reference':
184
+ throw new Error(`${target.type} Apply cannot carry content replay`);
185
+ }
186
+ }
187
+ //# sourceMappingURL=plans.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"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AAM,CAAC;SAC1C,CAAC,CAAC;IACL,CAAC;IAED,MAAM,mBAAmB,GAAG,IAAI,CAAC,YAAY,EAAE,MAAM,CAAC,cAAc,IAAI,IAAI,CAAC;IAC7E,QAAQ,MAAM,CAAC,IAAI,EAAE,CAAC;QACpB,KAAK,WAAW;YACd,OAAO,QAAQ,CAAC,MAAM,EAAE,QAAQ,CAAC,MAAM,CAAC,MAAoB,EAAE,QAAQ,CAAC,MAAM,CAAC,KAAK,EAAE,mBAAmB,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,308 @@
1
+ "use strict";
2
+ /** Event-driven portable Apply/Verify orchestration. */
3
+ Object.defineProperty(exports, "__esModule", { value: true });
4
+ exports.EntityApplyRail = exports.ENTITY_APPLY_RETRY_MAX_MS = exports.ENTITY_APPLY_RETRY_BASE_MS = exports.ENTITY_APPLY_DEFAULT_WORK_LIMIT = exports.ENTITY_APPLY_DEFAULT_CONCURRENCY = void 0;
5
+ const contracts_js_1 = require("./contracts.js");
6
+ const plans_js_1 = require("./plans.js");
7
+ const selection_js_1 = require("./selection.js");
8
+ exports.ENTITY_APPLY_DEFAULT_CONCURRENCY = 8;
9
+ exports.ENTITY_APPLY_DEFAULT_WORK_LIMIT = 64;
10
+ exports.ENTITY_APPLY_RETRY_BASE_MS = 1_000;
11
+ exports.ENTITY_APPLY_RETRY_MAX_MS = 30_000;
12
+ async function boundedMap(values, concurrency, visit) {
13
+ const results = new Array(values.length);
14
+ let cursor = 0;
15
+ const workers = Array.from({ length: Math.min(concurrency, values.length) }, async () => {
16
+ while (true) {
17
+ const index = cursor;
18
+ cursor += 1;
19
+ if (index >= values.length)
20
+ return;
21
+ results[index] = await visit(values[index]);
22
+ }
23
+ });
24
+ await Promise.all(workers);
25
+ return results;
26
+ }
27
+ /**
28
+ * Apply has only two wake sources: Receive committed new Inbox work, or local
29
+ * state changed in a way that may release a pending-local gate. Unsettled
30
+ * machine truth alone schedules bounded retry; an idle rail never polls.
31
+ */
32
+ class EntityApplyRail {
33
+ #options;
34
+ #concurrency;
35
+ #workLimit;
36
+ #onBackgroundError;
37
+ #started = false;
38
+ #stopped = false;
39
+ #needsApply = false;
40
+ #retryRequested = false;
41
+ #running = null;
42
+ #retry = null;
43
+ #retryAttempt = 0;
44
+ constructor(options) {
45
+ this.#options = options;
46
+ this.#concurrency = options.concurrency ?? exports.ENTITY_APPLY_DEFAULT_CONCURRENCY;
47
+ this.#workLimit = options.workLimit ?? exports.ENTITY_APPLY_DEFAULT_WORK_LIMIT;
48
+ this.#onBackgroundError = options.onBackgroundError ?? (() => undefined);
49
+ if (!Number.isSafeInteger(this.#concurrency) || this.#concurrency < 1
50
+ || !Number.isSafeInteger(this.#workLimit) || this.#workLimit < 1) {
51
+ throw new Error('entity Apply concurrency and work limit must be positive integers');
52
+ }
53
+ }
54
+ /** Resume durable intents and then consume already-received Inbox work. */
55
+ async start() {
56
+ if (this.#started)
57
+ throw new Error('entity Apply rail already started');
58
+ if (this.#stopped)
59
+ throw new Error('entity Apply rail is stopped');
60
+ this.#started = true;
61
+ this.#needsApply = true;
62
+ await this.#runExplicitly();
63
+ }
64
+ /** Receive calls only after its Inbox transaction commits. */
65
+ recordsAvailable() {
66
+ if (this.#stopped)
67
+ return;
68
+ this.#needsApply = true;
69
+ if (this.#started)
70
+ this.#kick();
71
+ }
72
+ /** Record/Send or Detect calls after a local gate may have changed. */
73
+ localStateChanged() {
74
+ this.recordsAvailable();
75
+ }
76
+ /** Await work known at this boundary. It never creates an idle query loop. */
77
+ async flush() {
78
+ if (!this.#started)
79
+ throw new Error('entity Apply rail has not started');
80
+ if (this.#stopped)
81
+ return;
82
+ this.#needsApply = true;
83
+ await this.#runExplicitly();
84
+ }
85
+ async stop() {
86
+ if (this.#stopped)
87
+ return;
88
+ this.#stopped = true;
89
+ this.#cancelRetry();
90
+ await this.#running?.catch(() => undefined);
91
+ }
92
+ async #runExplicitly() {
93
+ this.#cancelRetry();
94
+ try {
95
+ // A finishing drain can hand a late flag to a successor from its final
96
+ // microtask. An explicit caller owns that successor as well.
97
+ do {
98
+ await this.#ensureRun();
99
+ } while (!this.#stopped && (this.#needsApply || this.#running !== null));
100
+ if (this.#retryRequested)
101
+ this.#scheduleRetry();
102
+ else
103
+ this.#retryAttempt = 0;
104
+ }
105
+ catch (error) {
106
+ this.#scheduleRetry();
107
+ throw error;
108
+ }
109
+ }
110
+ #kick() {
111
+ if (!this.#started || this.#stopped)
112
+ return;
113
+ this.#cancelRetry();
114
+ void this.#ensureRun().then(() => {
115
+ if (this.#retryRequested)
116
+ this.#scheduleRetry();
117
+ else
118
+ this.#retryAttempt = 0;
119
+ }, (error) => {
120
+ this.#onBackgroundError(error);
121
+ this.#scheduleRetry();
122
+ });
123
+ }
124
+ #ensureRun() {
125
+ if (this.#running)
126
+ return this.#running;
127
+ const running = this.#drain();
128
+ this.#running = running;
129
+ void running.finally(() => {
130
+ if (this.#running === running)
131
+ this.#running = null;
132
+ if (!this.#stopped && this.#needsApply)
133
+ this.#kick();
134
+ }).catch(() => undefined);
135
+ return running;
136
+ }
137
+ async #drain() {
138
+ this.#retryRequested = false;
139
+ while (!this.#stopped && this.#needsApply) {
140
+ this.#needsApply = false;
141
+ const entities = new Set();
142
+ const cursors = new Set();
143
+ let afterCursor = null;
144
+ let madeProgress = false;
145
+ do {
146
+ const page = await this.#options.store.readApplyWork(this.#workLimit, afterCursor);
147
+ if (!page || !Array.isArray(page.work)
148
+ || (page.nextCursor !== null
149
+ && (typeof page.nextCursor !== 'string' || page.nextCursor.length === 0))) {
150
+ throw new Error('entity Apply store returned an invalid work page');
151
+ }
152
+ if (page.work.length > this.#workLimit
153
+ || (page.work.length === 0 && page.nextCursor !== null)) {
154
+ throw new Error('entity Apply store violated its work-page bound');
155
+ }
156
+ for (const item of page.work) {
157
+ if (entities.has(item.entityId)) {
158
+ throw new Error(`entity Apply store returned ${item.entityId} twice in one scan`);
159
+ }
160
+ entities.add(item.entityId);
161
+ }
162
+ const results = await boundedMap(page.work, this.#concurrency, (item) => this.#applyOne(item));
163
+ if (results.includes('retry'))
164
+ this.#retryRequested = true;
165
+ if (results.includes('progress'))
166
+ madeProgress = true;
167
+ afterCursor = page.nextCursor;
168
+ if (afterCursor !== null && cursors.has(afterCursor)) {
169
+ throw new Error('entity Apply store repeated a work-page cursor');
170
+ }
171
+ if (afterCursor !== null)
172
+ cursors.add(afterCursor);
173
+ } while (!this.#stopped && afterCursor !== null);
174
+ if (madeProgress)
175
+ this.#needsApply = true;
176
+ }
177
+ }
178
+ async #applyOne(work) {
179
+ const selected = (0, selection_js_1.selectEntityApply)(work);
180
+ if (work.intent === null) {
181
+ if (await this.#options.store.hasLocalWorkAfter(work.authorityId, work.entityId, selected.target.globalSequence)) {
182
+ return 'blocked';
183
+ }
184
+ }
185
+ const plan = (0, plans_js_1.planSelectedEntityApply)(work, selected, this.#options.sha256Hex);
186
+ const adapter = this.#options.effects.adapterFor(plan.target.type);
187
+ let intent;
188
+ if (work.intent === null) {
189
+ intent = (0, contracts_js_1.createApplyIntent)({
190
+ authorityId: work.authorityId,
191
+ entityId: work.entityId,
192
+ fromSequence: work.resolvedThrough,
193
+ target: selected.target,
194
+ createdAt: this.#options.now(),
195
+ });
196
+ await this.#options.store.beginIntent(intent);
197
+ }
198
+ else {
199
+ intent = work.intent;
200
+ }
201
+ if (intent.phase !== 'revealed'
202
+ && await this.#options.store.hasLocalWorkAfter(intent.authorityId, intent.entityId, intent.throughSequence)) {
203
+ await this.#abandon(intent, plan, adapter);
204
+ return 'progress';
205
+ }
206
+ if (intent.phase === 'declared') {
207
+ const guard = await adapter.apply.guard(intent, plan);
208
+ if (guard.kind === 'retry')
209
+ return 'retry';
210
+ if (guard.kind === 'local-change') {
211
+ if (!await this.#options.store.hasLocalWorkAfter(intent.authorityId, intent.entityId, intent.throughSequence)) {
212
+ await this.#options.effects.captureLocal(intent, plan, 'before-reveal');
213
+ }
214
+ if (!await this.#options.store.hasLocalWorkAfter(intent.authorityId, intent.entityId, intent.throughSequence)) {
215
+ throw new Error('Apply local capture returned without durable Outbox work after its target');
216
+ }
217
+ await this.#abandon(intent, plan, adapter);
218
+ return 'progress';
219
+ }
220
+ if (guard.kind === 'already-target') {
221
+ // Revealed means visible ground owns the target, whether this pass
222
+ // installed it or the early guard proved it was already present.
223
+ intent = (0, contracts_js_1.advanceApplyIntent)((0, contracts_js_1.advanceApplyIntent)(intent, 'prepared'), 'revealed');
224
+ await this.#options.store.setIntentPhase(intent);
225
+ }
226
+ else {
227
+ if (await this.#options.store.hasLocalWorkAfter(intent.authorityId, intent.entityId, intent.throughSequence)) {
228
+ await this.#abandon(intent, plan, adapter);
229
+ return 'progress';
230
+ }
231
+ await adapter.apply.prepare(intent, plan);
232
+ intent = (0, contracts_js_1.advanceApplyIntent)(intent, 'prepared');
233
+ await this.#options.store.setIntentPhase(intent);
234
+ }
235
+ }
236
+ if (intent.phase === 'prepared') {
237
+ if (await this.#options.store.hasLocalWorkAfter(intent.authorityId, intent.entityId, intent.throughSequence)) {
238
+ await this.#abandon(intent, plan, adapter);
239
+ return 'progress';
240
+ }
241
+ const guard = await adapter.apply.guard(intent, plan);
242
+ if (guard.kind === 'retry')
243
+ return 'retry';
244
+ if (guard.kind === 'local-change') {
245
+ if (!await this.#options.store.hasLocalWorkAfter(intent.authorityId, intent.entityId, intent.throughSequence)) {
246
+ await this.#options.effects.captureLocal(intent, plan, 'before-reveal');
247
+ }
248
+ if (!await this.#options.store.hasLocalWorkAfter(intent.authorityId, intent.entityId, intent.throughSequence)) {
249
+ throw new Error('Apply local capture returned without durable Outbox work after its target');
250
+ }
251
+ await this.#abandon(intent, plan, adapter);
252
+ return 'progress';
253
+ }
254
+ if (guard.kind === 'safe') {
255
+ // Close the window between the disk guard and the reveal as far as the
256
+ // durable local queue can prove. The host's recoverable replacement
257
+ // owns the remaining syscall-sized race.
258
+ if (await this.#options.store.hasLocalWorkAfter(intent.authorityId, intent.entityId, intent.throughSequence)) {
259
+ await this.#abandon(intent, plan, adapter);
260
+ return 'progress';
261
+ }
262
+ await adapter.apply.reveal(intent, plan);
263
+ }
264
+ intent = (0, contracts_js_1.advanceApplyIntent)(intent, 'revealed');
265
+ await this.#options.store.setIntentPhase(intent);
266
+ }
267
+ const verification = await adapter.verify.verify(intent, plan);
268
+ if (verification.kind === 'retry')
269
+ return 'retry';
270
+ if (verification.kind === 'local-change') {
271
+ if (!await this.#options.store.hasLocalWorkAfter(intent.authorityId, intent.entityId, intent.throughSequence)) {
272
+ await this.#options.effects.captureLocal(intent, plan, 'after-reveal');
273
+ }
274
+ if (!await this.#options.store.hasLocalWorkAfter(intent.authorityId, intent.entityId, intent.throughSequence)) {
275
+ throw new Error('Apply post-reveal capture returned without durable Outbox work after its target');
276
+ }
277
+ await adapter.apply.discard(intent, plan);
278
+ await this.#options.store.completeIntent(intent, { kind: 'superseded-by-local' });
279
+ return 'progress';
280
+ }
281
+ await adapter.apply.discard(intent, plan);
282
+ await this.#options.store.completeIntent(intent, { kind: 'materialized' });
283
+ return 'progress';
284
+ }
285
+ async #abandon(intent, plan, adapter) {
286
+ await adapter.apply.discard(intent, plan);
287
+ await this.#options.store.cancelIntent(intent);
288
+ }
289
+ #scheduleRetry() {
290
+ if (this.#stopped || this.#retry)
291
+ return;
292
+ const base = Math.min(exports.ENTITY_APPLY_RETRY_MAX_MS, exports.ENTITY_APPLY_RETRY_BASE_MS * (2 ** Math.min(this.#retryAttempt, 16)));
293
+ const random = Math.max(0, Math.min(1, this.#options.schedule.random()));
294
+ const delay = Math.round(base * (0.5 + random));
295
+ this.#retryAttempt += 1;
296
+ this.#retry = this.#options.schedule.schedule(delay, () => {
297
+ this.#retry = null;
298
+ this.#needsApply = true;
299
+ this.#kick();
300
+ });
301
+ }
302
+ #cancelRetry() {
303
+ this.#retry?.cancel();
304
+ this.#retry = null;
305
+ }
306
+ }
307
+ exports.EntityApplyRail = EntityApplyRail;
308
+ //# sourceMappingURL=rail.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"rail.js","sourceRoot":"","sources":["../../src/apply/rail.ts"],"names":[],"mappings":";AAAA,wDAAwD;;;AAExD,iDAQwB;AACxB,yCAAqD;AACrD,iDAAmD;AAEtC,QAAA,gCAAgC,GAAG,CAAC,CAAC;AACrC,QAAA,+BAA+B,GAAG,EAAE,CAAC;AACrC,QAAA,0BAA0B,GAAG,KAAK,CAAC;AACnC,QAAA,yBAAyB,GAAG,MAAM,CAAC;AAIhD,KAAK,UAAU,UAAU,CACvB,MAAoB,EACpB,WAAmB,EACnB,KAAoC;IAEpC,MAAM,OAAO,GAAG,IAAI,KAAK,CAAS,MAAM,CAAC,MAAM,CAAC,CAAC;IACjD,IAAI,MAAM,GAAG,CAAC,CAAC;IACf,MAAM,OAAO,GAAG,KAAK,CAAC,IAAI,CAAC,EAAE,MAAM,EAAE,IAAI,CAAC,GAAG,CAAC,WAAW,EAAE,MAAM,CAAC,MAAM,CAAC,EAAE,EAAE,KAAK,IAAI,EAAE;QACtF,OAAO,IAAI,EAAE,CAAC;YACZ,MAAM,KAAK,GAAG,MAAM,CAAC;YACrB,MAAM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AC,MAAM,CAAC,CAAC;IACjD,CAAC;IAED,cAAc;QACZ,IAAI,IAAI,CAAC,QAAQ,IAAI,IAAI,CAAC,MAAM;YAAE,OAAO;QACzC,MAAM,IAAI,GAAG,IAAI,CAAC,GAAG,CACnB,iCAAyB,EACzB,kCAA0B,GAAG,CAAC,CAAC,IAAI,IAAI,CAAC,GAAG,CAAC,IAAI,CAAC,aAAa,EAAE,EAAE,CAAC,CAAC,CACrE,CAAC;QACF,MAAM,MAAM,GAAG,IAAI,CAAC,GAAG,CAAC,CAAC,EAAE,IAAI,CAAC,GAAG,CAAC,CAAC,EAAE,IAAI,CAAC,QAAQ,CAAC,QAAQ,CAAC,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;AA7SD,0CA6SC"}
@@ -0,0 +1,86 @@
1
+ "use strict";
2
+ /** Portable proof of one incremental Git Card + Checkpoint transport chain. */
3
+ Object.defineProperty(exports, "__esModule", { value: true });
4
+ exports.prepareRepositoryResult = prepareRepositoryResult;
5
+ const repo_states_js_1 = require("../entities/repo-states.js");
6
+ const portableRepositoryPath = (path) => path.length > 0
7
+ && !path.startsWith('/')
8
+ && !path.includes('\0')
9
+ && path.split('/').every((part) => part !== '' && part !== '.' && part !== '..');
10
+ function assertTransportTruth(state, sha256Hex) {
11
+ const cardId = (0, repo_states_js_1.deriveCardId)(state.card, sha256Hex);
12
+ const checkpointId = (0, repo_states_js_1.deriveCheckpointId)(state.checkpoint, sha256Hex);
13
+ const stateId = (0, repo_states_js_1.deriveStateId)(cardId, checkpointId, sha256Hex);
14
+ if (state.cardId !== cardId || state.checkpointId !== checkpointId || state.stateId !== stateId) {
15
+ throw new Error('repository Apply transport IDs do not describe its Card + Checkpoint');
16
+ }
17
+ if (state.pack !== null && sha256Hex(state.pack.bytes) !== state.pack.sha256) {
18
+ throw new Error('repository Apply Git pack failed verification');
19
+ }
20
+ const paths = new Set();
21
+ for (const file of state.checkpoint.untracked) {
22
+ if (!portableRepositoryPath(file.path) || paths.has(file.path)
23
+ || !['100644', '100755', '120000'].includes(file.mode)) {
24
+ throw new Error('repository Apply Checkpoint has an invalid untracked path or mode');
25
+ }
26
+ paths.add(file.path);
27
+ if (file.content !== null && sha256Hex(file.content) !== file.sha256) {
28
+ throw new Error(`repository Apply Checkpoint content failed verification for ${file.path}`);
29
+ }
30
+ }
31
+ for (const entry of state.identityDelta.upsert) {
32
+ if (!portableRepositoryPath(entry.path)) {
33
+ throw new Error('repository Apply identity map has an unsafe path');
34
+ }
35
+ }
36
+ if (state.identityDelta.remove.some((path) => !portableRepositoryPath(path))) {
37
+ throw new Error('repository Apply identity map has an unsafe removal path');
38
+ }
39
+ }
40
+ /**
41
+ * Verify a sealed transport suffix before a host invokes Git. With a null
42
+ * base the chain must be complete from its reset node. With a durable local
43
+ * base, the first incremental node must name that exact transport frontier.
44
+ */
45
+ function prepareRepositoryResult(plan, nodes, base, sha256Hex) {
46
+ if (nodes.length === 0)
47
+ throw new Error('repository Apply transport chain is empty');
48
+ let priorVersion = base.transportVersion;
49
+ let identity = base.identity;
50
+ if ((base.transportVersion === null) !== (base.identity === null)) {
51
+ throw new Error('repository Apply base frontier is incomplete');
52
+ }
53
+ const transports = [];
54
+ for (const node of nodes) {
55
+ if (sha256Hex(node.bytes) !== node.transportVersion) {
56
+ throw new Error('repository Apply transport failed its immutable hash');
57
+ }
58
+ const state = (0, repo_states_js_1.decodeRepositoryTransport)(node.bytes);
59
+ if (state.parentTransportVersion !== priorVersion) {
60
+ throw new Error('repository Apply transport chain is discontinuous');
61
+ }
62
+ assertTransportTruth(state, sha256Hex);
63
+ identity = (0, repo_states_js_1.applyRepositoryIdentity)(identity, state, sha256Hex);
64
+ transports.push(state);
65
+ priorVersion = node.transportVersion;
66
+ }
67
+ const latest = transports.at(-1);
68
+ if (priorVersion !== plan.transportVersion
69
+ || latest.parentTransportVersion !== plan.parentTransportVersion
70
+ || latest.stateId !== plan.stateId
71
+ || latest.cardId !== plan.cardId
72
+ || latest.checkpointId !== plan.checkpointId) {
73
+ throw new Error('repository Apply chain does not produce its accepted complete result');
74
+ }
75
+ const missingUntracked = latest.checkpoint.untracked.find((file) => file.content === null);
76
+ if (missingUntracked) {
77
+ throw new Error(`repository Apply Checkpoint omitted untracked content for ${missingUntracked.path}`);
78
+ }
79
+ return Object.freeze({
80
+ transports: Object.freeze(transports),
81
+ latest,
82
+ transportVersion: priorVersion,
83
+ identity: Object.freeze([...identity]),
84
+ });
85
+ }
86
+ //# sourceMappingURL=repository-result.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"repository-result.js","sourceRoot":"","sources":["../../src/apply/repository-result.ts"],"names":[],"mappings":";AAAA,+EAA+E;;AAwE/E,0DA4CC;AAlHD,+DAQoC;AAqBpC,MAAM,sBAAsB,GAAG,CAAC,IAAY,EAAW,EAAE,CAAC,IAAI,CAAC,MAAM,GAAG,CAAC;OACpE,CAAC,IAAI,CAAC,UAAU,CAAC,GAAG,CAAC;OACrB,CAAC,IAAI,CAAC,QAAQ,CAAC,IAAI,CAAC;OACpB,IAAI,CAAC,KAAK,CAAC,GAAG,CAAC,CAAC,KAAK,CAAC,CAAC,IAAI,EAAE,EAAE,CAA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