@amalgm/live 0.2.30 → 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 (81) hide show
  1. package/PURPOSE.md +30 -1
  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/rail.d.ts +2 -0
  52. package/dist/records/rail.d.ts.map +1 -1
  53. package/dist/records/rail.js +6 -0
  54. package/dist/records/rail.js.map +1 -1
  55. package/dist-cjs/apply/content-results.js +57 -0
  56. package/dist-cjs/apply/content-results.js.map +1 -0
  57. package/dist-cjs/apply/contracts.js +53 -0
  58. package/dist-cjs/apply/contracts.js.map +1 -0
  59. package/dist-cjs/apply/index.js +28 -0
  60. package/dist-cjs/apply/index.js.map +1 -0
  61. package/dist-cjs/apply/local-work.js +20 -0
  62. package/dist-cjs/apply/local-work.js.map +1 -0
  63. package/dist-cjs/apply/plans.js +187 -0
  64. package/dist-cjs/apply/plans.js.map +1 -0
  65. package/dist-cjs/apply/rail.js +308 -0
  66. package/dist-cjs/apply/rail.js.map +1 -0
  67. package/dist-cjs/apply/repository-result.js +86 -0
  68. package/dist-cjs/apply/repository-result.js.map +1 -0
  69. package/dist-cjs/apply/selection.js +66 -0
  70. package/dist-cjs/apply/selection.js.map +1 -0
  71. package/dist-cjs/apply/type-adapters.js +41 -0
  72. package/dist-cjs/apply/type-adapters.js.map +1 -0
  73. package/dist-cjs/detection/adapter-contract.js +5 -5
  74. package/dist-cjs/detection/adapter-contract.js.map +1 -1
  75. package/dist-cjs/detection/echo.js +8 -1
  76. package/dist-cjs/detection/echo.js.map +1 -1
  77. package/dist-cjs/index.js +1 -0
  78. package/dist-cjs/index.js.map +1 -1
  79. package/dist-cjs/records/rail.js +6 -0
  80. package/dist-cjs/records/rail.js.map +1 -1
  81. package/package.json +7 -1
@@ -0,0 +1,53 @@
1
+ "use strict";
2
+ /** Portable contracts at the Inbox -> Apply -> Verify boundary. */
3
+ Object.defineProperty(exports, "__esModule", { value: true });
4
+ exports.ENTITY_APPLY_INTENT_CONTRACT = void 0;
5
+ exports.assertApplyIntent = assertApplyIntent;
6
+ exports.createApplyIntent = createApplyIntent;
7
+ exports.advanceApplyIntent = advanceApplyIntent;
8
+ const types_js_1 = require("../entities/types.js");
9
+ exports.ENTITY_APPLY_INTENT_CONTRACT = 'amalgm.entity-apply-intent@1';
10
+ const HASH = /^[0-9a-f]{64}$/;
11
+ const PHASES = new Set(['declared', 'prepared', 'revealed']);
12
+ const sequence = (value, positive = false) => Number.isSafeInteger(value) && value >= (positive ? 1 : 0);
13
+ function assertApplyIntent(intent) {
14
+ if (intent.contract !== exports.ENTITY_APPLY_INTENT_CONTRACT
15
+ || !intent.authorityId
16
+ || !types_js_1.UUID_PATTERN.test(intent.entityId)
17
+ || !sequence(intent.fromSequence)
18
+ || !sequence(intent.throughSequence, true)
19
+ || intent.throughSequence < intent.fromSequence + 1
20
+ || !intent.targetMutationId
21
+ || !HASH.test(intent.targetState)
22
+ || !(0, types_js_1.isEntityType)(intent.targetType)
23
+ || !PHASES.has(intent.phase)
24
+ || !sequence(intent.createdAt)) {
25
+ throw new Error('entity Apply intent is invalid');
26
+ }
27
+ }
28
+ function createApplyIntent(input) {
29
+ const intent = Object.freeze({
30
+ contract: exports.ENTITY_APPLY_INTENT_CONTRACT,
31
+ authorityId: input.authorityId,
32
+ entityId: input.entityId,
33
+ fromSequence: input.fromSequence,
34
+ throughSequence: input.target.globalSequence,
35
+ targetMutationId: input.target.mutationId,
36
+ targetState: input.target.resultState,
37
+ targetType: input.target.change.result.type,
38
+ phase: 'declared',
39
+ createdAt: input.createdAt,
40
+ });
41
+ assertApplyIntent(intent);
42
+ return intent;
43
+ }
44
+ function advanceApplyIntent(intent, phase) {
45
+ assertApplyIntent(intent);
46
+ const legal = intent.phase === phase
47
+ || (intent.phase === 'declared' && phase === 'prepared')
48
+ || (intent.phase === 'prepared' && phase === 'revealed');
49
+ if (!legal)
50
+ throw new Error(`entity Apply intent cannot move from ${intent.phase} to ${phase}`);
51
+ return Object.freeze({ ...intent, phase });
52
+ }
53
+ //# sourceMappingURL=contracts.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"contracts.js","sourceRoot":"","sources":["../../src/apply/contracts.ts"],"names":[],"mappings":";AAAA,mEAAmE;;;AA2NnE,8CAcC;AAED,8CAqBC;AAED,gDAUC;AAzQD,mDAAmG;AAMtF,QAAA,4BAA4B,GAAG,8BAA8B,CAAC;AA4M3E,MAAM,IAAI,GAAG,gBAAgB,CAAC;AAC9B,MAAM,MAAM,GAAG,IAAI,GAAG,CAAmB,CAAC,UAAU,EAAE,UAAU,EAAE,UAAU,CAAC,CAAC,CAAC;AAE/E,MAAM,QAAQ,GAAG,CAAC,KAAa,EAAE,QAAQ,GAAG,KAAK,EAAW,EAAE,CAC5D,MAAM,CAAC,aAAa,CAAC,KAAK,CAAC,IAAI,KAAK,IAAI,CAAC,QAAQ,CAAC,CAAC,CAAC,CAAC,CAAC,CAAC,CAAC,CAAC,CAAC,CAAC;AAE7D,SAAgB,iBAAiB,CAAC,MAAyB;IACzD,IAAI,MAAM,CAAC,QAAQ,KAAK,oCAA4B;WAC/C,CAAC,MAAM,CAAC,WAAW;WACnB,CAAC,uBAAY,CAAC,IAAI,CAAC,MAAM,CAAC,QAAQ,CAAC;WACnC,CAAC,QAAQ,CAAC,MAAM,CAAC,YAAY,CAAC;WAC9B,CAAC,QAAQ,CAAC,MAAM,CAAC,eAAe,EAAE,IAAI,CAAC;WACvC,MAAM,CAAC,eAAe,GAAG,MAAM,CAAC,YAAY,GAAG,CAAC;WAChD,CAAC,MAAM,CAAC,gBAAgB;WACxB,CAAC,IAAI,CAAC,IAAI,CAAC,MAAM,CAAC,WAAW,CAAC;WAC9B,CAAC,IAA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,CAAC;IAChG,OAAO,MAAM,CAAC,MAAM,CAAC,EAAE,GAAG,MAAM,EAAE,KAAK,EAAE,CAAC,CAAC;AAC7C,CAAC"}
@@ -0,0 +1,28 @@
1
+ "use strict";
2
+ /** Entity Apply and Verify subsystem. */
3
+ var __createBinding = (this && this.__createBinding) || (Object.create ? (function(o, m, k, k2) {
4
+ if (k2 === undefined) k2 = k;
5
+ var desc = Object.getOwnPropertyDescriptor(m, k);
6
+ if (!desc || ("get" in desc ? !m.__esModule : desc.writable || desc.configurable)) {
7
+ desc = { enumerable: true, get: function() { return m[k]; } };
8
+ }
9
+ Object.defineProperty(o, k2, desc);
10
+ }) : (function(o, m, k, k2) {
11
+ if (k2 === undefined) k2 = k;
12
+ o[k2] = m[k];
13
+ }));
14
+ var __exportStar = (this && this.__exportStar) || function(m, exports) {
15
+ for (var p in m) if (p !== "default" && !Object.prototype.hasOwnProperty.call(exports, p)) __createBinding(exports, m, p);
16
+ };
17
+ Object.defineProperty(exports, "__esModule", { value: true });
18
+ exports.planEntityApply = void 0;
19
+ __exportStar(require("./contracts.js"), exports);
20
+ __exportStar(require("./content-results.js"), exports);
21
+ __exportStar(require("./local-work.js"), exports);
22
+ var plans_js_1 = require("./plans.js");
23
+ Object.defineProperty(exports, "planEntityApply", { enumerable: true, get: function () { return plans_js_1.planEntityApply; } });
24
+ __exportStar(require("./rail.js"), exports);
25
+ __exportStar(require("./repository-result.js"), exports);
26
+ __exportStar(require("./selection.js"), exports);
27
+ __exportStar(require("./type-adapters.js"), exports);
28
+ //# sourceMappingURL=index.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"index.js","sourceRoot":"","sources":["../../src/apply/index.ts"],"names":[],"mappings":";AAAA,yCAAyC;;;;;;;;;;;;;;;;;AAEzC,iDAA+B;AAC/B,uDAAqC;AACrC,kDAAgC;AAChC,uCAA6C;AAApC,2GAAA,eAAe,OAAA;AACxB,4CAA0B;AAC1B,yDAAuC;AACvC,iDAA+B;AAC/B,qDAAmC"}
@@ -0,0 +1,20 @@
1
+ "use strict";
2
+ /** Pure form of the Outbox gate used by the Apply store transaction. */
3
+ Object.defineProperty(exports, "__esModule", { value: true });
4
+ exports.hasLocalWorkAfter = hasLocalWorkAfter;
5
+ /**
6
+ * A local result protects working ground when cloud has not sequenced it yet,
7
+ * or when its accepted sequence is later than the incoming target. An
8
+ * accepted local row at the target is no longer a blocker: that is the
9
+ * official position Apply should Verify against the already-equal disk.
10
+ */
11
+ function hasLocalWorkAfter(rows, authorityId, entityId, targetSequence) {
12
+ if (!authorityId || !entityId
13
+ || !Number.isSafeInteger(targetSequence) || targetSequence < 1) {
14
+ throw new Error('Apply local-work target is invalid');
15
+ }
16
+ return rows.some((row) => row.record.authorityId === authorityId
17
+ && row.record.entityId === entityId
18
+ && (row.status === 'pending' || row.globalSequence > targetSequence));
19
+ }
20
+ //# sourceMappingURL=local-work.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"local-work.js","sourceRoot":"","sources":["../../src/apply/local-work.ts"],"names":[],"mappings":";AAAA,wEAAwE;;AAUxE,8CAaC;AAnBD;;;;;GAKG;AACH,SAAgB,iBAAiB,CAC/B,IAA0B,EAC1B,WAAmB,EACnB,QAAgB,EAChB,cAAsB;IAEtB,IAAI,CAAC,WAAW,IAAI,CAAC,QAAQ;WACxB,CAAC,MAAM,CAAC,aAAa,CAAC,cAAc,CAAC,IAAI,cAAc,GAAG,CAAC,EAAE,CAAC;QACjE,MAAM,IAAI,KAAK,CAAC,oCAAoC,CAAC,CAAC;IACxD,CAAC;IACD,OAAO,IAAI,CAAC,IAAI,CAAC,CAAC,GAAG,EAAE,EAAE,CAAC,GAAG,CAAC,MAAM,CAAC,WAAW,KAAK,WAAW;WAC3D,GAAG,CAAC,MAAM,CAAC,QAAQ,KAAK,QAAQ;WAChC,CAAC,GAAG,CAAC,MAAM,KAAK,SAAS,IAAI,GAAG,CAAC,cAAc,GAAG,cAAc,CAAC,CAAC,CAAC;AAC1E,CAAC"}
@@ -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":"plans.js","sourceRoot":"","sources":["../../src/apply/plans.ts"],"names":[],"mappings":";AAAA,8EAA8E;;AAwK9E,0CAEC;AAGD,0DA6DC;AAxOD,wDAA+D;AAC/D,mDAAgE;AAChE,mDAAkD;AAClD,mDAAoE;AAOpE,2DAA4G;AAS5G,iDAA6E;AAE7E,MAAM,IAAI,GAAG,gBAAgB,CAAC;AAE9B,MAAM,YAAY,GAAG,CAAC,IAAsB,EAAE,KAAuB,EAAW,EAAE,CAChF,IAAA,qBAAU,EAAC,IAAI,CAAC,KAAK,IAAA,qBAAU,EAAC,KAAK,CAAC,CAAC;AAEz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AAQ,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,IAAI,CAAC,CAAC;YACZ,IAAI,KAAK,IAAI,MAAM,CAAC,MAAM;gBAAE,OAAO;YACnC,OAAO,CAAC,KAAK,CAAC,GAAG,MAAM,KAAK,CAAC,MAAM,CAAC,KAAK,CAAE,CAAC,CAAC;QAC/C,CAAC;IACH,CAAC,CAAC,CAAC;IACH,MAAM,OAAO,CAAC,GAAG,CAAC,OAAO,CAAC,CAAC;IAC3B,OAAO,OAAO,CAAC;AACjB,CAAC;AAED;;;;GAIG;AACH,MAAa,eAAe;IACjB,QAAQ,CAAyB;IACjC,YAAY,CAAS;IACrB,UAAU,CAAS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