@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.
- package/PURPOSE.md +37 -2
- 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/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/index.d.ts +2 -0
- package/dist/records/index.d.ts.map +1 -1
- package/dist/records/index.js +2 -0
- package/dist/records/index.js.map +1 -1
- package/dist/records/rail.d.ts +97 -0
- package/dist/records/rail.d.ts.map +1 -0
- package/dist/records/rail.js +250 -0
- package/dist/records/rail.js.map +1 -0
- package/dist/records/wire.d.ts +63 -0
- package/dist/records/wire.d.ts.map +1 -0
- package/dist/records/wire.js +86 -0
- package/dist/records/wire.js.map +1 -0
- 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/index.js +1 -0
- package/dist-cjs/index.js.map +1 -1
- package/dist-cjs/records/index.js +2 -0
- package/dist-cjs/records/index.js.map +1 -1
- package/dist-cjs/records/rail.js +254 -0
- package/dist-cjs/records/rail.js.map +1 -0
- package/dist-cjs/records/wire.js +91 -0
- package/dist-cjs/records/wire.js.map +1 -0
- package/package.json +7 -1
|
@@ -0,0 +1,66 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
/** Gap-free per-entity Apply selection and complete-result coalescing. */
|
|
3
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
4
|
+
exports.selectEntityApply = selectEntityApply;
|
|
5
|
+
const cloud_js_1 = require("../entities/cloud.js");
|
|
6
|
+
const contracts_js_1 = require("../records/contracts.js");
|
|
7
|
+
const contracts_js_2 = require("./contracts.js");
|
|
8
|
+
/**
|
|
9
|
+
* Select the exact target named by a recovering intent, otherwise the newest
|
|
10
|
+
* contiguous complete result. The host may reveal only this target; every
|
|
11
|
+
* earlier selected row becomes resolved after target Verify succeeds.
|
|
12
|
+
*/
|
|
13
|
+
function selectEntityApply(work) {
|
|
14
|
+
if (!work.authorityId || !work.entityId
|
|
15
|
+
|| !Number.isSafeInteger(work.resolvedThrough) || work.resolvedThrough < 0
|
|
16
|
+
|| work.records.length === 0) {
|
|
17
|
+
throw new Error('entity Apply work is invalid');
|
|
18
|
+
}
|
|
19
|
+
let expected = work.resolvedThrough + 1;
|
|
20
|
+
for (const record of work.records) {
|
|
21
|
+
const checked = (0, contracts_js_1.checkAcceptedEntityRecord)(record);
|
|
22
|
+
if (!checked.ok)
|
|
23
|
+
throw new Error(checked.error);
|
|
24
|
+
if (record.authorityId !== work.authorityId || record.entityId !== work.entityId) {
|
|
25
|
+
throw new Error('one entity Apply batch cannot cross authority or UUID channels');
|
|
26
|
+
}
|
|
27
|
+
if (record.globalSequence !== expected) {
|
|
28
|
+
throw new Error(`entity Apply work has a gap before sequence ${record.globalSequence}`);
|
|
29
|
+
}
|
|
30
|
+
expected += 1;
|
|
31
|
+
}
|
|
32
|
+
if (work.materialized !== null) {
|
|
33
|
+
const current = (0, cloud_js_1.assertRecord)(work.materialized.record);
|
|
34
|
+
if (current.uuid !== work.entityId
|
|
35
|
+
|| !Number.isSafeInteger(work.materialized.globalSequence)
|
|
36
|
+
|| work.materialized.globalSequence < 1
|
|
37
|
+
|| work.materialized.globalSequence > work.resolvedThrough) {
|
|
38
|
+
throw new Error('entity Apply materialization proof is invalid');
|
|
39
|
+
}
|
|
40
|
+
}
|
|
41
|
+
let through = work.records.at(-1).globalSequence;
|
|
42
|
+
if (work.intent !== null) {
|
|
43
|
+
(0, contracts_js_2.assertApplyIntent)(work.intent);
|
|
44
|
+
if (work.intent.authorityId !== work.authorityId
|
|
45
|
+
|| work.intent.entityId !== work.entityId
|
|
46
|
+
|| work.intent.fromSequence !== work.resolvedThrough) {
|
|
47
|
+
throw new Error('entity Apply intent does not own this work range');
|
|
48
|
+
}
|
|
49
|
+
through = work.intent.throughSequence;
|
|
50
|
+
}
|
|
51
|
+
const index = through - work.resolvedThrough - 1;
|
|
52
|
+
const target = work.records[index];
|
|
53
|
+
if (!target)
|
|
54
|
+
throw new Error('entity Apply intent target is absent from Inbox work');
|
|
55
|
+
if (work.intent !== null
|
|
56
|
+
&& (target.mutationId !== work.intent.targetMutationId
|
|
57
|
+
|| target.resultState !== work.intent.targetState
|
|
58
|
+
|| target.change.result.type !== work.intent.targetType)) {
|
|
59
|
+
throw new Error('entity Apply intent target does not match its retained Inbox record');
|
|
60
|
+
}
|
|
61
|
+
return Object.freeze({
|
|
62
|
+
records: Object.freeze(work.records.slice(0, index + 1)),
|
|
63
|
+
target,
|
|
64
|
+
});
|
|
65
|
+
}
|
|
66
|
+
//# sourceMappingURL=selection.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"selection.js","sourceRoot":"","sources":["../../src/apply/selection.ts"],"names":[],"mappings":";AAAA,0EAA0E;;AAgB1E,8CAmDC;AAjED,mDAAoD;AACpD,0DAA+F;AAC/F,iDAAyE;AAOzE;;;;GAIG;AACH,SAAgB,iBAAiB,CAAC,IAAqB;IACr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IACzF,CAAC;IACD,OAAO,MAAM,CAAC,MAAM,CAAC;QACnB,OAAO,EAAE,MAAM,CAAC,MAAM,CAAC,IAAI,CAAC,OAAO,CAAC,KAAK,CAAC,CAAC,EAAE,KAAK,GAAG,CAAC,CAAC,CAAC;QACxD,MAAM;KACP,CAAC,CAAC;AACL,CAAC"}
|
|
@@ -0,0 +1,41 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
/** Bridge the canonical entity type registry to the Apply/Verify coordinator. */
|
|
3
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
4
|
+
exports.entityApplyEffects = entityApplyEffects;
|
|
5
|
+
exports.buildEntityApplyEffects = buildEntityApplyEffects;
|
|
6
|
+
const adapter_contract_js_1 = require("../detection/adapter-contract.js");
|
|
7
|
+
const types_js_1 = require("../entities/types.js");
|
|
8
|
+
/**
|
|
9
|
+
* Adapt the already-convicted one-type/one-adapter registry for Apply. The
|
|
10
|
+
* subsystem refuses partial support: every type selected at runtime must bind
|
|
11
|
+
* both complete sockets, never a generic fallback or a path-based guess.
|
|
12
|
+
*/
|
|
13
|
+
function entityApplyEffects(byType, captureLocal) {
|
|
14
|
+
const operational = new Map();
|
|
15
|
+
for (const [type, descriptor] of byType) {
|
|
16
|
+
if (!(0, types_js_1.isEntityType)(type)) {
|
|
17
|
+
throw new Error(`Apply adapter registry contains unknown entity type ${JSON.stringify(type)}`);
|
|
18
|
+
}
|
|
19
|
+
const { apply, verify } = descriptor.rails;
|
|
20
|
+
if (!apply || !verify) {
|
|
21
|
+
throw new Error(`adapter ${descriptor.name} cannot Apply ${type} until both Apply and Verify sockets are bound`);
|
|
22
|
+
}
|
|
23
|
+
operational.set(type, Object.freeze({ name: descriptor.name, apply, verify }));
|
|
24
|
+
}
|
|
25
|
+
return Object.freeze({
|
|
26
|
+
adapterFor(type) {
|
|
27
|
+
const adapter = operational.get(type);
|
|
28
|
+
if (!adapter)
|
|
29
|
+
throw new Error(`entity type ${type} has no operational Apply adapter`);
|
|
30
|
+
return adapter;
|
|
31
|
+
},
|
|
32
|
+
captureLocal(intent, plan, position) {
|
|
33
|
+
return captureLocal(intent, plan, position);
|
|
34
|
+
},
|
|
35
|
+
});
|
|
36
|
+
}
|
|
37
|
+
/** Build the universal physical-type registry, refusing any missing type. */
|
|
38
|
+
function buildEntityApplyEffects(adapters, captureLocal) {
|
|
39
|
+
return entityApplyEffects((0, adapter_contract_js_1.buildTypeMap)(adapters, types_js_1.ENTITY_TYPES), captureLocal);
|
|
40
|
+
}
|
|
41
|
+
//# sourceMappingURL=type-adapters.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"type-adapters.js","sourceRoot":"","sources":["../../src/apply/type-adapters.ts"],"names":[],"mappings":";AAAA,iFAAiF;;AAkBjF,gDA6BC;AAGD,0DAKC;AArDD,0EAAwF;AACxF,mDAAmF;AAUnF;;;;GAIG;AACH,SAAgB,kBAAkB,CAChC,MAA8C,EAC9C,YAAgC;IAEhC,MAAM,WAAW,GAAG,IAAI,GAAG,EAA6C,CAAC;IACzE,KAAK,MAAM,CAAC,IAAI,EAAE,UAAU,CAAC,IAAI,MAAM,EAAE,CAAC;QACxC,IAAI,CAAC,IAAA,uBAAY,EAAC,IAAI,CAAC,EAAE,CAAC;YACxB,MAAM,IAAI,KAAK,CAAC,uDAAuD,IAAI,CAAC,SAAS,CAAC,IAAI,CAAC,EAAE,CAAC,CAAC;QACjG,CAAC;QACD,MAAM,EAAE,KAAK,EAAE,MAAM,EAAE,GAAG,UAAU,CAAC,KAAK,CAAC;QAC3C,IAAI,CAAC,KAAK,IAAI,CAAC,MAAM,EAAE,CAAC;YACtB,MAAM,IAAI,KAAK,CAAC,WAAW,UAAU,CAAC,IAAI,iBAAiB,IAAI,gDAAgD,CAAC,CAAC;QACnH,CAAC;QACD,WAAW,CAAC,GAAG,CAAC,IAAI,EAAE,MAAM,CAAC,MAAM,CAAC,EAAE,IAAI,EAAE,UAAU,CAAC,IAAI,EAAE,KAAK,EAAE,MAAM,EAAE,CAAC,CAAC,CAAC;IACjF,CAAC;IACD,OAAO,MAAM,CAAC,MAAM,CAAC;QACnB,UAAU,CAAC,IAAgB;YACzB,MAAM,OAAO,GAAG,WAAW,CAAC,GAAG,CAAC,IAAI,CAAC,CAAC;YACtC,IAAI,CAAC,OAAO;gBAAE,MAAM,IAAI,KAAK,CAAC,eAAe,IAAI,mCAAmC,CAAC,CAAC;YACtF,OAAO,OAAO,CAAC;QACjB,CAAC;QACD,YAAY,CACV,MAAyB,EACzB,IAAqB,EACrB,QAA0C;YAE1C,OAAO,YAAY,CAAC,MAAM,EAAE,IAAI,EAAE,QAAQ,CAAC,CAAC;QAC9C,CAAC;KACF,CAAC,CAAC;AACL,CAAC;AAED,6EAA6E;AAC7E,SAAgB,uBAAuB,CACrC,QAA2B,EAC3B,YAAgC;IAEhC,OAAO,kBAAkB,CAAC,IAAA,kCAAY,EAAC,QAAQ,EAAE,uBAAY,CAAC,EAAE,YAAY,CAAC,CAAC;AAChF,CAAC"}
|
|
@@ -44,15 +44,15 @@ exports.RAILS = Object.freeze([
|
|
|
44
44
|
/**
|
|
45
45
|
* The ratified sockets — for each rail that has one, the exact surfaces
|
|
46
46
|
* every binding adapter implements. Same names, same shapes, every
|
|
47
|
-
* type.
|
|
48
|
-
*
|
|
49
|
-
*
|
|
50
|
-
* verify join only when the Send/Receive rails exist to derive their
|
|
51
|
-
* socket from. A socket is ratified from a real consumer or it is not
|
|
47
|
+
* type. Detect, Apply, and Verify are ratified from their real portable
|
|
48
|
+
* consumers. Watch, Record, Send, and Receive need no type-specific surface
|
|
49
|
+
* at this bar. A socket is ratified from a real consumer or it is not
|
|
52
50
|
* ratified at all.
|
|
53
51
|
*/
|
|
54
52
|
exports.SOCKETS = Object.freeze({
|
|
55
53
|
detect: Object.freeze(['truth']),
|
|
54
|
+
apply: Object.freeze(['prepare', 'guard', 'reveal', 'discard']),
|
|
55
|
+
verify: Object.freeze(['verify']),
|
|
56
56
|
});
|
|
57
57
|
/**
|
|
58
58
|
* Convict a malformed adapter descriptor loudly; return it (typed)
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"adapter-contract.js","sourceRoot":"","sources":["../../src/detection/adapter-contract.ts"],"names":[],"mappings":";AAAA;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;GAiCG;;;
|
|
1
|
+
{"version":3,"file":"adapter-contract.js","sourceRoot":"","sources":["../../src/detection/adapter-contract.ts"],"names":[],"mappings":";AAAA;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;GAiCG;;;AA0EH,sCA6CC;AAQD,oCAyBC;AAlJD,gEAAgE;AACnD,QAAA,KAAK,GAAoB,MAAM,CAAC,MAAM,CAAC;IAClD,OAAO,EAAE,QAAQ,EAAE,QAAQ,EAAE,MAAM,EAAE,SAAS,EAAE,OAAO,EAAE,QAAQ;CAClE,CAAC,CAAC;AA8BH;;;;;;;GAOG;AACU,QAAA,OAAO,GAAuD,MAAM,CAAC,MAAM,CAAC;IACvF,MAAM,EAAE,MAAM,CAAC,MAAM,CAAC,CAAC,OAAO,CAAC,CAAC;IAChC,KAAK,EAAE,MAAM,CAAC,MAAM,CAAC,CAAC,SAAS,EAAE,OAAO,EAAE,QAAQ,EAAE,SAAS,CAAC,CAAC;IAC/D,MAAM,EAAE,MAAM,CAAC,MAAM,CAAC,CAAC,QAAQ,CAAC,CAAC;CAClC,CAAC,CAAC;AAmBH;;;GAGG;AACH,SAAgB,aAAa,CAAC,OAAgB;IAC5C,MAAM,QAAQ,GAAG,CAAC,KAAc,EAAoC,EAAE,CACpE,OAAO,KAAK,KAAK,QAAQ,IAAI,KAAK,KAAK,IAAI,CAAC;IAC9C,MAAM,KAAK,GAAG,QAAQ,CAAC,OAAO,CAAC,IAAI,OAAO,OAAO,CAAC,MAAM,CAAC,KAAK,QAAQ,IAAI,OAAO,CAAC,MAAM,CAAC;QACvF,CAAC,CAAC,WAAW,IAAI,CAAC,SAAS,CAAC,OAAO,CAAC,MAA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I,CAAC,0CAA0C,CAAC,CAAC;QACjG,CAAC;IACH,CAAC;IACD,OAAO,MAAM,CAAC;AAChB,CAAC;AAOD;;;;;;;;;;GAUG;AACI,MAAM,UAAU,GAAG,CACxB,KAAiB,EACoF,EAAE,CACvG,KAAK,CAAC,IAAI,KAAK,QAAQ,IAAI,KAAK,CAAC,IAAI,KAAK,SAAS;IACjD,CAAC,CAAC,EAAE,KAAK,EAAE,QAAQ,EAAE;IACrB,CAAC,CAAC,EAAE,KAAK,EAAE,WAAW,EAAE,MAAM,EAAE,KAAK,CAAC,IAAI,EAAE,CAAC;AALpC,QAAA,UAAU,cAK0B;AAEjD;;;;;;;;;;GAUG;AACU,QAAA,gBAAgB,GAAsB,MAAM,CAAC,MAAM,CAAC;IAC/D,IAAI,EAAE,WAAW;IACjB,KAAK,EAAE,MAAM,CAAC,MAAM,CAAC;QACnB,SAAS,EAAE,4FAA4F;KACxG,CAAC;IACF,KAAK,EAAE,MAAM,CAAC,MAAM,CAAC,EAAE,CAAC;CACzB,CAAC,CAAC"}
|
|
@@ -16,7 +16,14 @@ function echoDecision(notebook, observed) {
|
|
|
16
16
|
: { kind: 'retry', reason: observed.reason };
|
|
17
17
|
}
|
|
18
18
|
if (notebook.status === 'active') {
|
|
19
|
-
|
|
19
|
+
const exactTransport = notebook.transportVersion === null
|
|
20
|
+
? observed.truth === 'present'
|
|
21
|
+
&& (observed.transportVersion === undefined || observed.transportVersion === null)
|
|
22
|
+
: observed.truth === 'present'
|
|
23
|
+
&& observed.transportVersion === notebook.transportVersion;
|
|
24
|
+
return observed.truth === 'present'
|
|
25
|
+
&& observed.version === notebook.version
|
|
26
|
+
&& exactTransport
|
|
20
27
|
? { kind: 'silence' }
|
|
21
28
|
: { kind: 'detect' };
|
|
22
29
|
}
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"echo.js","sourceRoot":"","sources":["../../src/detection/echo.ts"],"names":[],"mappings":";AAAA;;;;;;;GAOG;;AAUH,
|
|
1
|
+
{"version":3,"file":"echo.js","sourceRoot":"","sources":["../../src/detection/echo.ts"],"names":[],"mappings":";AAAA;;;;;;;GAOG;;AAUH,oCAsBC;AAtBD,SAAgB,YAAY,CAC1B,QAA4E,EAC5E,QAAsB;IAEtB,IAAI,QAAQ,CAAC,KAAK,KAAK,WAAW,EAAE,CAAC;QACnC,OAAO,QAAQ,CAAC,MAAM,KAAK,SAAS;YAClC,CAAC,CAAC,EAAE,IAAI,EAAE,OAAO,EAAE;YACnB,CAAC,CAAC,EAAE,IAAI,EAAE,OAAO,EAAE,MAAM,EAAE,QAAQ,CAAC,MAAM,EAAE,CAAC;IACjD,CAAC;IACD,IAAI,QAAQ,CAAC,MAAM,KAAK,QAAQ,EAAE,CAAC;QACjC,MAAM,cAAc,GAAG,QAAQ,CAAC,gBAAgB,KAAK,IAAI;YACvD,CAAC,CAAC,QAAQ,CAAC,KAAK,KAAK,SAAS;mBACzB,CAAC,QAAQ,CAAC,gBAAgB,KAAK,SAAS,IAAI,QAAQ,CAAC,gBAAgB,KAAK,IAAI,CAAC;YACpF,CAAC,CAAC,QAAQ,CAAC,KAAK,KAAK,SAAS;mBACzB,QAAQ,CAAC,gBAAgB,KAAK,QAAQ,CAAC,gBAAgB,CAAC;QAC/D,OAAO,QAAQ,CAAC,KAAK,KAAK,SAAS;eAC9B,QAAQ,CAAC,OAAO,KAAK,QAAQ,CAAC,OAAO;eACrC,cAAc;YACjB,CAAC,CAAC,EAAE,IAAI,EAAE,SAAS,EAAE;YACrB,CAAC,CAAC,EAAE,IAAI,EAAE,QAAQ,EAAE,CAAC;IACzB,CAAC;IACD,OAAO,QAAQ,CAAC,KAAK,KAAK,QAAQ,CAAC,CAAC,CAAC,EAAE,IAAI,EAAE,SAAS,EAAE,CAAC,CAAC,CAAC,EAAE,IAAI,EAAE,QAAQ,EAAE,CAAC;AAChF,CAAC"}
|
package/dist-cjs/index.js
CHANGED
|
@@ -31,6 +31,7 @@ __exportStar(require("./entities/index.js"), exports);
|
|
|
31
31
|
__exportStar(require("./watching/index.js"), exports);
|
|
32
32
|
__exportStar(require("./detection/index.js"), exports);
|
|
33
33
|
__exportStar(require("./records/index.js"), exports);
|
|
34
|
+
__exportStar(require("./apply/index.js"), exports);
|
|
34
35
|
__exportStar(require("./registration/index.js"), exports);
|
|
35
36
|
__exportStar(require("./files/index.js"), exports);
|
|
36
37
|
__exportStar(require("./transfer/index.js"), exports);
|
package/dist-cjs/index.js.map
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"index.js","sourceRoot":"","sources":["../src/index.ts"],"names":[],"mappings":";AAAA;;;;;;;;;;GAUG;;;;;;;;;;;;;;;;AAEH,uDAAqC;AACrC,sDAAoC;AACpC,sDAAoC;AACpC,sDAAoC;AACpC,uDAAqC;AACrC,qDAAmC;AACnC,0DAAwC;AACxC,mDAAiC;AACjC,sDAAoC;AACpC,mDAAiC;AACjC,uDAAqC"}
|
|
1
|
+
{"version":3,"file":"index.js","sourceRoot":"","sources":["../src/index.ts"],"names":[],"mappings":";AAAA;;;;;;;;;;GAUG;;;;;;;;;;;;;;;;AAEH,uDAAqC;AACrC,sDAAoC;AACpC,sDAAoC;AACpC,sDAAoC;AACpC,uDAAqC;AACrC,qDAAmC;AACnC,mDAAiC;AACjC,0DAAwC;AACxC,mDAAiC;AACjC,sDAAoC;AACpC,mDAAiC;AACjC,uDAAqC"}
|
|
@@ -20,4 +20,6 @@ __exportStar(require("./codec.js"), exports);
|
|
|
20
20
|
__exportStar(require("./contracts.js"), exports);
|
|
21
21
|
__exportStar(require("./inbox.js"), exports);
|
|
22
22
|
__exportStar(require("./outbox.js"), exports);
|
|
23
|
+
__exportStar(require("./rail.js"), exports);
|
|
24
|
+
__exportStar(require("./wire.js"), exports);
|
|
23
25
|
//# sourceMappingURL=index.js.map
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"index.js","sourceRoot":"","sources":["../../src/records/index.ts"],"names":[],"mappings":";AAAA,2EAA2E;;;;;;;;;;;;;;;;AAE3E,iDAA+B;AAC/B,6CAA2B;AAC3B,iDAA+B;AAC/B,6CAA2B;AAC3B,8CAA4B"}
|
|
1
|
+
{"version":3,"file":"index.js","sourceRoot":"","sources":["../../src/records/index.ts"],"names":[],"mappings":";AAAA,2EAA2E;;;;;;;;;;;;;;;;AAE3E,iDAA+B;AAC/B,6CAA2B;AAC3B,iDAA+B;AAC/B,6CAA2B;AAC3B,8CAA4B;AAC5B,4CAA0B;AAC1B,4CAA0B"}
|
|
@@ -0,0 +1,254 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
/** Portable, event-driven Send and Receive orchestration. Hosts inject effects. */
|
|
3
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
4
|
+
exports.EntityRecordRail = exports.ENTITY_RECORD_RETRY_MAX_MS = exports.ENTITY_RECORD_RETRY_BASE_MS = exports.ENTITY_RECORD_DELIVERY_LIMIT = void 0;
|
|
5
|
+
const outbox_js_1 = require("./outbox.js");
|
|
6
|
+
exports.ENTITY_RECORD_DELIVERY_LIMIT = 256;
|
|
7
|
+
exports.ENTITY_RECORD_RETRY_BASE_MS = 1_000;
|
|
8
|
+
exports.ENTITY_RECORD_RETRY_MAX_MS = 30_000;
|
|
9
|
+
/**
|
|
10
|
+
* One rail has only two reasons to run: local work exists, or authority work
|
|
11
|
+
* may exist. Repeated reasons coalesce while the current run is in flight.
|
|
12
|
+
*/
|
|
13
|
+
class EntityRecordRail {
|
|
14
|
+
#authorityId;
|
|
15
|
+
#store;
|
|
16
|
+
#cargo;
|
|
17
|
+
#authority;
|
|
18
|
+
#schedule;
|
|
19
|
+
#onInboxCommitted;
|
|
20
|
+
#onBackgroundError;
|
|
21
|
+
#started = false;
|
|
22
|
+
#stopped = false;
|
|
23
|
+
#subscribed = false;
|
|
24
|
+
#needsSubscribe = false;
|
|
25
|
+
#needsSend = false;
|
|
26
|
+
#running = null;
|
|
27
|
+
#retry = null;
|
|
28
|
+
#retryAttempt = 0;
|
|
29
|
+
#removeAvailable = null;
|
|
30
|
+
#removeDisconnect = null;
|
|
31
|
+
constructor(options) {
|
|
32
|
+
if (!options.authorityId.trim())
|
|
33
|
+
throw new Error('entity record authority is required');
|
|
34
|
+
this.#authorityId = options.authorityId;
|
|
35
|
+
this.#store = options.store;
|
|
36
|
+
this.#cargo = options.cargo;
|
|
37
|
+
this.#authority = options.authority;
|
|
38
|
+
this.#schedule = options.schedule;
|
|
39
|
+
this.#onInboxCommitted = options.onInboxCommitted ?? (() => undefined);
|
|
40
|
+
this.#onBackgroundError = options.onBackgroundError ?? (() => undefined);
|
|
41
|
+
}
|
|
42
|
+
/** Subscribe first, catch up from the durable cursor, then drain local work. */
|
|
43
|
+
async start() {
|
|
44
|
+
if (this.#started)
|
|
45
|
+
throw new Error('entity record rail already started');
|
|
46
|
+
if (this.#stopped)
|
|
47
|
+
throw new Error('entity record rail is stopped');
|
|
48
|
+
this.#started = true;
|
|
49
|
+
this.#removeAvailable = this.#authority.onAvailable((signal) => {
|
|
50
|
+
if (signal.authorityId !== this.#authorityId || this.#stopped)
|
|
51
|
+
return;
|
|
52
|
+
this.#needsSubscribe = true;
|
|
53
|
+
this.#kick();
|
|
54
|
+
});
|
|
55
|
+
this.#removeDisconnect = this.#authority.onDisconnect(() => {
|
|
56
|
+
if (this.#stopped)
|
|
57
|
+
return;
|
|
58
|
+
this.#subscribed = false;
|
|
59
|
+
this.#needsSubscribe = true;
|
|
60
|
+
this.#scheduleRetry();
|
|
61
|
+
});
|
|
62
|
+
this.#needsSubscribe = true;
|
|
63
|
+
this.#needsSend = true;
|
|
64
|
+
await this.#runExplicitly();
|
|
65
|
+
}
|
|
66
|
+
/** Record calls this only after its local outbox transaction commits. */
|
|
67
|
+
localRecordsAvailable() {
|
|
68
|
+
if (this.#stopped)
|
|
69
|
+
return;
|
|
70
|
+
this.#needsSend = true;
|
|
71
|
+
if (this.#started)
|
|
72
|
+
this.#kick();
|
|
73
|
+
}
|
|
74
|
+
/** Await all work known at this boundary; it never creates an idle query. */
|
|
75
|
+
async flush() {
|
|
76
|
+
if (!this.#started)
|
|
77
|
+
throw new Error('entity record rail has not started');
|
|
78
|
+
if (this.#stopped)
|
|
79
|
+
return;
|
|
80
|
+
this.#needsSend = true;
|
|
81
|
+
if (!this.#subscribed)
|
|
82
|
+
this.#needsSubscribe = true;
|
|
83
|
+
await this.#runExplicitly();
|
|
84
|
+
}
|
|
85
|
+
/** Stop accepting events. Closing the injected wire may interrupt a request. */
|
|
86
|
+
async stop() {
|
|
87
|
+
if (this.#stopped)
|
|
88
|
+
return;
|
|
89
|
+
this.#stopped = true;
|
|
90
|
+
this.#cancelRetry();
|
|
91
|
+
this.#removeAvailable?.();
|
|
92
|
+
this.#removeAvailable = null;
|
|
93
|
+
this.#removeDisconnect?.();
|
|
94
|
+
this.#removeDisconnect = null;
|
|
95
|
+
await this.#running?.catch(() => undefined);
|
|
96
|
+
}
|
|
97
|
+
async #runExplicitly() {
|
|
98
|
+
this.#cancelRetry();
|
|
99
|
+
try {
|
|
100
|
+
await this.#ensureRun();
|
|
101
|
+
this.#retryAttempt = 0;
|
|
102
|
+
}
|
|
103
|
+
catch (error) {
|
|
104
|
+
this.#scheduleRetry();
|
|
105
|
+
throw error;
|
|
106
|
+
}
|
|
107
|
+
}
|
|
108
|
+
#kick() {
|
|
109
|
+
if (!this.#started || this.#stopped)
|
|
110
|
+
return;
|
|
111
|
+
this.#cancelRetry();
|
|
112
|
+
void this.#ensureRun().then(() => {
|
|
113
|
+
this.#retryAttempt = 0;
|
|
114
|
+
}, (error) => {
|
|
115
|
+
this.#onBackgroundError(error);
|
|
116
|
+
this.#scheduleRetry();
|
|
117
|
+
});
|
|
118
|
+
}
|
|
119
|
+
#ensureRun() {
|
|
120
|
+
if (this.#running)
|
|
121
|
+
return this.#running;
|
|
122
|
+
const running = this.#drain();
|
|
123
|
+
this.#running = running;
|
|
124
|
+
void running.then(() => {
|
|
125
|
+
if (this.#running === running)
|
|
126
|
+
this.#running = null;
|
|
127
|
+
if (!this.#stopped && (this.#needsSubscribe || this.#needsSend))
|
|
128
|
+
this.#kick();
|
|
129
|
+
}, () => {
|
|
130
|
+
if (this.#running === running)
|
|
131
|
+
this.#running = null;
|
|
132
|
+
});
|
|
133
|
+
return running;
|
|
134
|
+
}
|
|
135
|
+
async #drain() {
|
|
136
|
+
while (!this.#stopped && (this.#needsSubscribe || this.#needsSend)) {
|
|
137
|
+
if (this.#needsSubscribe) {
|
|
138
|
+
this.#needsSubscribe = false;
|
|
139
|
+
try {
|
|
140
|
+
await this.#catchUp();
|
|
141
|
+
this.#subscribed = true;
|
|
142
|
+
}
|
|
143
|
+
catch (error) {
|
|
144
|
+
this.#subscribed = false;
|
|
145
|
+
this.#needsSubscribe = true;
|
|
146
|
+
throw error;
|
|
147
|
+
}
|
|
148
|
+
}
|
|
149
|
+
if (this.#stopped)
|
|
150
|
+
return;
|
|
151
|
+
if (this.#needsSend) {
|
|
152
|
+
this.#needsSend = false;
|
|
153
|
+
try {
|
|
154
|
+
if (await this.#sendPending())
|
|
155
|
+
this.#needsSubscribe = true;
|
|
156
|
+
}
|
|
157
|
+
catch (error) {
|
|
158
|
+
this.#needsSend = true;
|
|
159
|
+
throw error;
|
|
160
|
+
}
|
|
161
|
+
}
|
|
162
|
+
}
|
|
163
|
+
}
|
|
164
|
+
async #catchUp() {
|
|
165
|
+
let after = await this.#store.readDeliveryCursor(this.#authorityId);
|
|
166
|
+
while (!this.#stopped) {
|
|
167
|
+
const deliveries = await this.#authority.subscribe({
|
|
168
|
+
authorityId: this.#authorityId,
|
|
169
|
+
afterDeliverySequence: after,
|
|
170
|
+
limit: exports.ENTITY_RECORD_DELIVERY_LIMIT,
|
|
171
|
+
});
|
|
172
|
+
if (deliveries.length === 0)
|
|
173
|
+
return;
|
|
174
|
+
let stored = await this.#store.receive({
|
|
175
|
+
authorityId: this.#authorityId,
|
|
176
|
+
deliveries,
|
|
177
|
+
advanceDeliveryCursor: true,
|
|
178
|
+
});
|
|
179
|
+
if (stored.kind === 'stored')
|
|
180
|
+
this.#onInboxCommitted();
|
|
181
|
+
if (stored.kind === 'gap') {
|
|
182
|
+
const missing = await this.#authority.backfill({
|
|
183
|
+
authorityId: this.#authorityId,
|
|
184
|
+
entityId: stored.gap.entityId,
|
|
185
|
+
afterGlobalSequence: stored.gap.after,
|
|
186
|
+
throughGlobalSequence: stored.gap.received,
|
|
187
|
+
});
|
|
188
|
+
if (missing.length === 0) {
|
|
189
|
+
throw new Error(`entity ${stored.gap.entityId} is missing sequence ${stored.gap.after + 1}`);
|
|
190
|
+
}
|
|
191
|
+
const repaired = await this.#store.receive({
|
|
192
|
+
authorityId: this.#authorityId,
|
|
193
|
+
deliveries: missing,
|
|
194
|
+
advanceDeliveryCursor: false,
|
|
195
|
+
});
|
|
196
|
+
if (repaired.kind === 'gap') {
|
|
197
|
+
throw new Error(`entity ${repaired.gap.entityId} history remained gapped after backfill`);
|
|
198
|
+
}
|
|
199
|
+
this.#onInboxCommitted();
|
|
200
|
+
stored = await this.#store.receive({
|
|
201
|
+
authorityId: this.#authorityId,
|
|
202
|
+
deliveries,
|
|
203
|
+
advanceDeliveryCursor: true,
|
|
204
|
+
});
|
|
205
|
+
if (stored.kind === 'gap') {
|
|
206
|
+
throw new Error(`entity ${stored.gap.entityId} history did not reach ${stored.gap.received}`);
|
|
207
|
+
}
|
|
208
|
+
this.#onInboxCommitted();
|
|
209
|
+
}
|
|
210
|
+
after = stored.deliveryCursor;
|
|
211
|
+
if (deliveries.length < exports.ENTITY_RECORD_DELIVERY_LIMIT)
|
|
212
|
+
return;
|
|
213
|
+
}
|
|
214
|
+
}
|
|
215
|
+
async #sendPending() {
|
|
216
|
+
let sent = false;
|
|
217
|
+
while (!this.#stopped) {
|
|
218
|
+
const pending = await this.#store.readPending();
|
|
219
|
+
const selected = (0, outbox_js_1.nextEntitySends)(pending);
|
|
220
|
+
if (selected.length === 0)
|
|
221
|
+
return sent;
|
|
222
|
+
const results = await Promise.allSettled(selected.map(async (row) => {
|
|
223
|
+
await this.#cargo.ensure(row.record);
|
|
224
|
+
if (this.#stopped)
|
|
225
|
+
return;
|
|
226
|
+
const accepted = await this.#authority.submit(row.record);
|
|
227
|
+
await this.#store.stampAccepted(row, accepted);
|
|
228
|
+
sent = true;
|
|
229
|
+
}));
|
|
230
|
+
const failure = results.find((result) => result.status === 'rejected');
|
|
231
|
+
if (failure)
|
|
232
|
+
throw failure.reason;
|
|
233
|
+
}
|
|
234
|
+
return sent;
|
|
235
|
+
}
|
|
236
|
+
#scheduleRetry() {
|
|
237
|
+
if (this.#stopped || this.#retry)
|
|
238
|
+
return;
|
|
239
|
+
const base = Math.min(exports.ENTITY_RECORD_RETRY_MAX_MS, exports.ENTITY_RECORD_RETRY_BASE_MS * (2 ** Math.min(this.#retryAttempt, 16)));
|
|
240
|
+
const random = Math.max(0, Math.min(1, this.#schedule.random()));
|
|
241
|
+
const delay = Math.round(base * (0.5 + random));
|
|
242
|
+
this.#retryAttempt += 1;
|
|
243
|
+
this.#retry = this.#schedule.schedule(delay, () => {
|
|
244
|
+
this.#retry = null;
|
|
245
|
+
this.#kick();
|
|
246
|
+
});
|
|
247
|
+
}
|
|
248
|
+
#cancelRetry() {
|
|
249
|
+
this.#retry?.cancel();
|
|
250
|
+
this.#retry = null;
|
|
251
|
+
}
|
|
252
|
+
}
|
|
253
|
+
exports.EntityRecordRail = EntityRecordRail;
|
|
254
|
+
//# sourceMappingURL=rail.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"rail.js","sourceRoot":"","sources":["../../src/records/rail.ts"],"names":[],"mappings":";AAAA,mFAAmF;;;AAEnF,2CAA8D;AAGjD,QAAA,4BAA4B,GAAG,GAAG,CAAC;AACnC,QAAA,2BAA2B,GAAG,KAAK,CAAC;AACpC,QAAA,0BAA0B,GAAG,MAAM,CAAC;AA8EjD;;;GAGG;AACH,MAAa,gBAAgB;IAClB,YAAY,CAAS;IACrB,MAAM,CAAwB;IAC9B,MAA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AAC,SAAS,CAAC,MAAM,EAAE,CAAC,CAAC,CAAC;QACjE,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,SAAS,CAAC,QAAQ,CAAC,KAAK,EAAE,GAAG,EAAE;YAChD,IAAI,CAAC,MAAM,GAAG,IAAI,CAAC;YACnB,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;AApOD,4CAoOC"}
|
|
@@ -0,0 +1,91 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
/** Exact wire for the entity Record/Send/Receive rail. */
|
|
3
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
4
|
+
exports.decodeEntityRecordDeliveries = decodeEntityRecordDeliveries;
|
|
5
|
+
exports.decodeEntityRecordAvailability = decodeEntityRecordAvailability;
|
|
6
|
+
exports.createEntityRecordAuthorityPort = createEntityRecordAuthorityPort;
|
|
7
|
+
const validate_js_1 = require("../contracts/validate.js");
|
|
8
|
+
const codec_js_1 = require("./codec.js");
|
|
9
|
+
const positiveSequence = (value) => typeof value === 'number' && Number.isSafeInteger(value) && value > 0;
|
|
10
|
+
function decodeEntityRecordDeliveries(value) {
|
|
11
|
+
if (!Array.isArray(value))
|
|
12
|
+
throw new Error('entity record authority did not return a records array');
|
|
13
|
+
return Object.freeze(value.map((item) => {
|
|
14
|
+
if (!(0, validate_js_1.isRecord)(item)
|
|
15
|
+
|| !positiveSequence(item.delivery_sequence)
|
|
16
|
+
|| typeof item.record_json !== 'string') {
|
|
17
|
+
throw new Error('entity record authority returned an invalid delivery');
|
|
18
|
+
}
|
|
19
|
+
return Object.freeze({
|
|
20
|
+
deliverySequence: item.delivery_sequence,
|
|
21
|
+
record: (0, codec_js_1.decodeAcceptedEntityRecord)(item.record_json),
|
|
22
|
+
});
|
|
23
|
+
}));
|
|
24
|
+
}
|
|
25
|
+
function decodeEntityRecordAvailability(value) {
|
|
26
|
+
if (!(0, validate_js_1.isRecord)(value)
|
|
27
|
+
|| value.type !== 'entity.record.available'
|
|
28
|
+
|| typeof value.authority_id !== 'string'
|
|
29
|
+
|| !value.authority_id) {
|
|
30
|
+
throw new Error('entity record availability signal is invalid');
|
|
31
|
+
}
|
|
32
|
+
return Object.freeze({
|
|
33
|
+
authorityId: value.authority_id,
|
|
34
|
+
});
|
|
35
|
+
}
|
|
36
|
+
/** Map one authenticated request/event wire onto the portable authority port. */
|
|
37
|
+
function createEntityRecordAuthorityPort(wire) {
|
|
38
|
+
return {
|
|
39
|
+
async submit(record) {
|
|
40
|
+
const frame = await wire.request({
|
|
41
|
+
type: 'entity.record.submit',
|
|
42
|
+
record_json: (0, codec_js_1.encodeEntityRecord)(record),
|
|
43
|
+
}, ['entity.record.ack']);
|
|
44
|
+
if (!(0, validate_js_1.isRecord)(frame) || frame.type !== 'entity.record.ack' || typeof frame.record_json !== 'string') {
|
|
45
|
+
throw new Error('entity record acknowledgement is invalid');
|
|
46
|
+
}
|
|
47
|
+
return (0, codec_js_1.decodeAcceptedEntityRecord)(frame.record_json);
|
|
48
|
+
},
|
|
49
|
+
async subscribe(input) {
|
|
50
|
+
const frame = await wire.request({
|
|
51
|
+
type: 'entity.record.subscribe',
|
|
52
|
+
authority_id: input.authorityId,
|
|
53
|
+
after_delivery_sequence: input.afterDeliverySequence,
|
|
54
|
+
limit: input.limit,
|
|
55
|
+
}, ['entity.record.subscribed']);
|
|
56
|
+
if (!(0, validate_js_1.isRecord)(frame) || frame.type !== 'entity.record.subscribed') {
|
|
57
|
+
throw new Error('entity record subscription response is invalid');
|
|
58
|
+
}
|
|
59
|
+
return decodeEntityRecordDeliveries(frame.records);
|
|
60
|
+
},
|
|
61
|
+
async backfill(input) {
|
|
62
|
+
const frame = await wire.request({
|
|
63
|
+
type: 'entity.record.backfill',
|
|
64
|
+
authority_id: input.authorityId,
|
|
65
|
+
entity_id: input.entityId,
|
|
66
|
+
after_global_sequence: input.afterGlobalSequence,
|
|
67
|
+
through_global_sequence: input.throughGlobalSequence,
|
|
68
|
+
}, ['entity.record.backfill-result']);
|
|
69
|
+
if (!(0, validate_js_1.isRecord)(frame) || frame.type !== 'entity.record.backfill-result') {
|
|
70
|
+
throw new Error('entity record backfill response is invalid');
|
|
71
|
+
}
|
|
72
|
+
return decodeEntityRecordDeliveries(frame.records);
|
|
73
|
+
},
|
|
74
|
+
onAvailable(listener) {
|
|
75
|
+
return wire.onFrame((frame) => {
|
|
76
|
+
if (!(0, validate_js_1.isRecord)(frame) || frame.type !== 'entity.record.available')
|
|
77
|
+
return;
|
|
78
|
+
try {
|
|
79
|
+
listener(decodeEntityRecordAvailability(frame));
|
|
80
|
+
}
|
|
81
|
+
catch {
|
|
82
|
+
// A malformed unsolicited frame is not authority evidence.
|
|
83
|
+
}
|
|
84
|
+
});
|
|
85
|
+
},
|
|
86
|
+
onDisconnect(listener) {
|
|
87
|
+
return wire.onDisconnect(listener);
|
|
88
|
+
},
|
|
89
|
+
};
|
|
90
|
+
}
|
|
91
|
+
//# sourceMappingURL=wire.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"wire.js","sourceRoot":"","sources":["../../src/records/wire.ts"],"names":[],"mappings":";AAAA,0DAA0D;;AAyF1D,oEAaC;AAED,wEAUC;AAGD,0EAmDC;AAtKD,0DAAoD;AACpD,yCAA4E;AAmF5E,MAAM,gBAAgB,GAAG,CAAC,KAAc,EAAmB,EAAE,CAC3D,OAAO,KAAK,KAAK,QAAQ,IAAI,MAAM,CAAC,aAAa,CAAC,KAAK,CAAC,IAAI,KAAK,GAAG,CAAC,CAAC;AAExE,SAAgB,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C,IAAI,KAAK,+BAA+B,EAAE,CAAC;gBACvE,MAAM,IAAI,KAAK,CAAC,4CAA4C,CAAC,CAAC;YAChE,CAAC;YACD,OAAO,4BAA4B,CAAC,KAAK,CAAC,OAAO,CAAC,CAAC;QACrD,CAAC;QACD,WAAW,CAAC,QAAQ;YAClB,OAAO,IAAI,CAAC,OAAO,CAAC,CAAC,KAAK,EAAE,EAAE;gBAC5B,IAAI,CAAC,IAAA,sBAAQ,EAAC,KAAK,CAAC,IAAI,KAAK,CAAC,IAAI,KAAK,yBAAyB;oBAAE,OAAO;gBACzE,IAAI,CAAC;oBACH,QAAQ,CAAC,8BAA8B,CAAC,KAAK,CAAC,CAAC,CAAC;gBAClD,CAAC;gBAAC,MAAM,CAAC;oBACP,2DAA2D;gBAC7D,CAAC;YACH,CAAC,CAAC,CAAC;QACL,CAAC;QACD,YAAY,CAAC,QAAQ;YACnB,OAAO,IAAI,CAAC,YAAY,CAAC,QAAQ,CAAC,CAAC;QACrC,CAAC;KACF,CAAC;AACJ,CAAC"}
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@amalgm/live",
|
|
3
|
-
"version": "0.2.
|
|
3
|
+
"version": "0.2.31",
|
|
4
4
|
"description": "Portable realtime SDK for Amalgm — wire contracts, mutation discipline, and delivery state machines behind host-injected adapters.",
|
|
5
5
|
"type": "module",
|
|
6
6
|
"main": "./dist-cjs/index.js",
|
|
@@ -62,6 +62,12 @@
|
|
|
62
62
|
"require": "./dist-cjs/records/index.js",
|
|
63
63
|
"default": "./dist/records/index.js"
|
|
64
64
|
},
|
|
65
|
+
"./apply": {
|
|
66
|
+
"types": "./dist/apply/index.d.ts",
|
|
67
|
+
"import": "./dist/apply/index.js",
|
|
68
|
+
"require": "./dist-cjs/apply/index.js",
|
|
69
|
+
"default": "./dist/apply/index.js"
|
|
70
|
+
},
|
|
65
71
|
"./files": {
|
|
66
72
|
"types": "./dist/files/index.d.ts",
|
|
67
73
|
"import": "./dist/files/index.js",
|