@kairos-es/core 1.0.0-alpha.4 → 1.0.0-alpha.5
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/README.md +3 -3
- package/dist/cjs/AppendCondition.js +1 -3
- package/dist/cjs/AppendCondition.js.map +1 -1
- package/dist/cjs/AppendIsOwned.js +6 -6
- package/dist/cjs/AppendIsOwned.js.map +1 -1
- package/dist/cjs/ContractStore.js +2 -2
- package/dist/cjs/ContractStore.js.map +1 -1
- package/dist/cjs/DcbEventStore.js +1 -1
- package/dist/cjs/DcbEventStore.js.map +1 -1
- package/dist/cjs/Event.js +29 -13
- package/dist/cjs/Event.js.map +1 -1
- package/dist/cjs/Query.js +1 -1
- package/dist/cjs/Query.js.map +1 -1
- package/dist/cjs/SubscribeMachine.js +20 -22
- package/dist/cjs/SubscribeMachine.js.map +1 -1
- package/dist/cjs/inMemory.js +4 -4
- package/dist/cjs/inMemory.js.map +1 -1
- package/dist/cjs/retryOnConflict.js +4 -10
- package/dist/cjs/retryOnConflict.js.map +1 -1
- package/dist/cjs/testing.js +2 -2
- package/dist/cjs/testing.js.map +1 -1
- package/dist/{dts → dts-cjs}/AppendCondition.d.ts +5 -7
- package/dist/{dts → dts-cjs}/AppendCondition.d.ts.map +1 -1
- package/dist/{dts → dts-cjs}/AppendIsOwned.d.ts +6 -6
- package/dist/{dts → dts-cjs}/AppendIsOwned.d.ts.map +1 -1
- package/dist/{dts → dts-cjs}/ContractStore.d.ts +3 -2
- package/dist/dts-cjs/ContractStore.d.ts.map +1 -0
- package/dist/{dts → dts-cjs}/DcbEventStore.d.ts +2 -2
- package/dist/{dts → dts-cjs}/DcbEventStore.d.ts.map +1 -1
- package/dist/{dts → dts-cjs}/Event.d.ts +31 -20
- package/dist/dts-cjs/Event.d.ts.map +1 -0
- package/dist/{dts → dts-cjs}/Query.d.ts +5 -5
- package/dist/{dts → dts-cjs}/SubscribeMachine.d.ts +11 -15
- package/dist/dts-cjs/SubscribeMachine.d.ts.map +1 -0
- package/dist/{dts → dts-cjs}/inMemory.d.ts.map +1 -1
- package/dist/{dts → dts-cjs}/index.d.ts +1 -1
- package/dist/dts-cjs/package.json +3 -0
- package/dist/{dts → dts-cjs}/retryOnConflict.d.ts +1 -7
- package/dist/dts-cjs/retryOnConflict.d.ts.map +1 -0
- package/dist/{dts → dts-cjs}/testing.d.ts +1 -1
- package/dist/dts-esm/AppendCondition.d.ts +21 -0
- package/dist/dts-esm/AppendCondition.d.ts.map +1 -0
- package/dist/dts-esm/AppendIsOwned.d.ts +78 -0
- package/dist/dts-esm/AppendIsOwned.d.ts.map +1 -0
- package/dist/dts-esm/ContractStore.d.ts +62 -0
- package/dist/dts-esm/ContractStore.d.ts.map +1 -0
- package/dist/dts-esm/DcbEventStore.d.ts +64 -0
- package/dist/dts-esm/DcbEventStore.d.ts.map +1 -0
- package/dist/dts-esm/Event.d.ts +174 -0
- package/dist/dts-esm/Event.d.ts.map +1 -0
- package/dist/dts-esm/Projection.d.ts +124 -0
- package/dist/dts-esm/Projection.d.ts.map +1 -0
- package/dist/dts-esm/Query.d.ts +180 -0
- package/dist/dts-esm/Query.d.ts.map +1 -0
- package/dist/dts-esm/SubscribeMachine.d.ts +175 -0
- package/dist/dts-esm/SubscribeMachine.d.ts.map +1 -0
- package/dist/dts-esm/errors.d.ts +17 -0
- package/dist/dts-esm/errors.d.ts.map +1 -0
- package/dist/dts-esm/inMemory.d.ts +76 -0
- package/dist/dts-esm/inMemory.d.ts.map +1 -0
- package/dist/dts-esm/index.d.ts +40 -0
- package/dist/dts-esm/index.d.ts.map +1 -0
- package/dist/dts-esm/package.json +3 -0
- package/dist/dts-esm/retryOnConflict.d.ts +64 -0
- package/dist/dts-esm/retryOnConflict.d.ts.map +1 -0
- package/dist/dts-esm/testing.d.ts +39 -0
- package/dist/dts-esm/testing.d.ts.map +1 -0
- package/dist/esm/AppendCondition.js +1 -3
- package/dist/esm/AppendCondition.js.map +1 -1
- package/dist/esm/AppendIsOwned.js +6 -6
- package/dist/esm/AppendIsOwned.js.map +1 -1
- package/dist/esm/ContractStore.js +2 -2
- package/dist/esm/ContractStore.js.map +1 -1
- package/dist/esm/DcbEventStore.js +1 -1
- package/dist/esm/DcbEventStore.js.map +1 -1
- package/dist/esm/Event.js +30 -14
- package/dist/esm/Event.js.map +1 -1
- package/dist/esm/Query.js +1 -1
- package/dist/esm/Query.js.map +1 -1
- package/dist/esm/SubscribeMachine.js +21 -23
- package/dist/esm/SubscribeMachine.js.map +1 -1
- package/dist/esm/inMemory.js +5 -5
- package/dist/esm/inMemory.js.map +1 -1
- package/dist/esm/index.js +1 -1
- package/dist/esm/retryOnConflict.js +4 -10
- package/dist/esm/retryOnConflict.js.map +1 -1
- package/dist/esm/testing.js +2 -2
- package/dist/esm/testing.js.map +1 -1
- package/package.json +21 -11
- package/src/AppendCondition.ts +1 -1
- package/src/AppendIsOwned.ts +7 -7
- package/src/ContractStore.ts +5 -4
- package/src/DcbEventStore.ts +3 -3
- package/src/Event.ts +49 -14
- package/src/Query.ts +1 -1
- package/src/SubscribeMachine.ts +38 -31
- package/src/inMemory.ts +6 -6
- package/src/index.ts +1 -1
- package/src/retryOnConflict.ts +6 -11
- package/src/testing.ts +2 -2
- package/testing/package.json +1 -1
- package/dist/dts/ContractStore.d.ts.map +0 -1
- package/dist/dts/Event.d.ts.map +0 -1
- package/dist/dts/SubscribeMachine.d.ts.map +0 -1
- package/dist/dts/retryOnConflict.d.ts.map +0 -1
- /package/dist/{dts → dts-cjs}/Projection.d.ts +0 -0
- /package/dist/{dts → dts-cjs}/Projection.d.ts.map +0 -0
- /package/dist/{dts → dts-cjs}/Query.d.ts.map +0 -0
- /package/dist/{dts → dts-cjs}/errors.d.ts +0 -0
- /package/dist/{dts → dts-cjs}/errors.d.ts.map +0 -0
- /package/dist/{dts → dts-cjs}/inMemory.d.ts +0 -0
- /package/dist/{dts → dts-cjs}/index.d.ts.map +0 -0
- /package/dist/{dts → dts-cjs}/testing.d.ts.map +0 -0
package/README.md
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
# @kairos-es/core
|
|
2
2
|
|
|
3
|
-
DCB-first event-sourcing contract and in-memory store for Effect
|
|
3
|
+
DCB-first event-sourcing contract and in-memory store for Effect 4.
|
|
4
4
|
|
|
5
5
|
## Installation
|
|
6
6
|
|
|
@@ -8,12 +8,12 @@ DCB-first event-sourcing contract and in-memory store for Effect v3.
|
|
|
8
8
|
Effect instance (per [ADR-0003](../../docs/adr)):
|
|
9
9
|
|
|
10
10
|
```sh
|
|
11
|
-
pnpm add @kairos-es/core@alpha effect@^
|
|
11
|
+
pnpm add @kairos-es/core@alpha effect@^4.0.5
|
|
12
12
|
```
|
|
13
13
|
|
|
14
14
|
Provides the `DcbEventStore` contract (branded `Position` / `Tag` / `EventType`,
|
|
15
15
|
the `DcbEvent` / `Query` / `AppendCondition` schemas, the errors and the
|
|
16
|
-
`Context.
|
|
16
|
+
`Context.Service`), the pure `Projection` / `composeProjections` fold primitives
|
|
17
17
|
(plus `unionQueries`, the OR-merge `composeProjections` folds a record through,
|
|
18
18
|
reachable without one — a caller accumulating queries rather than projections
|
|
19
19
|
needs it, and hand-rolling that merge silently drops a wildcard, an empty item
|
|
@@ -19,8 +19,6 @@ var _Query = require("./Query.js");
|
|
|
19
19
|
|
|
20
20
|
const AppendCondition = exports.AppendCondition = /*#__PURE__*/_effect.Schema.Struct({
|
|
21
21
|
failIfEventsMatch: _Query.Query,
|
|
22
|
-
after: /*#__PURE__*/_effect.Schema.
|
|
23
|
-
exact: true
|
|
24
|
-
})
|
|
22
|
+
after: /*#__PURE__*/_effect.Schema.optionalKey(_Event.Position)
|
|
25
23
|
});
|
|
26
24
|
//# sourceMappingURL=AppendCondition.js.map
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"AppendCondition.js","names":["_effect","require","_Event","_Query","AppendCondition","exports","Schema","Struct","failIfEventsMatch","Query","after","
|
|
1
|
+
{"version":3,"file":"AppendCondition.js","names":["_effect","require","_Event","_Query","AppendCondition","exports","Schema","Struct","failIfEventsMatch","Query","after","optionalKey","Position"],"sources":["../../src/AppendCondition.ts"],"sourcesContent":[null],"mappings":";;;;;;AASA,IAAAA,OAAA,GAAAC,OAAA;AACA,IAAAC,MAAA,GAAAD,OAAA;AACA,IAAAE,MAAA,GAAAF,OAAA;AAXA;;;;;;;;;;AAaO,MAAMG,eAAe,GAAAC,OAAA,CAAAD,eAAA,gBAAGE,cAAM,CAACC,MAAM,CAAC;EAC3CC,iBAAiB,EAAEC,YAAK;EACxBC,KAAK,eAAEJ,cAAM,CAACK,WAAW,CAACC,eAAQ;CACnC,CAAC","ignoreList":[]}
|
|
@@ -37,15 +37,15 @@ var _effect = require("effect");
|
|
|
37
37
|
*
|
|
38
38
|
* ## Present means refused, so a sanctioned append REMOVES the marker
|
|
39
39
|
*
|
|
40
|
-
* The check reads the
|
|
40
|
+
* The check reads the service through `Effect.serviceOption`, so its ABSENCE is the
|
|
41
41
|
* normal case and costs the `append` signature nothing — `DcbEventStore.append`
|
|
42
42
|
* keeps `R = never` and no caller provides anything. Presence is what refuses.
|
|
43
43
|
*
|
|
44
44
|
* That shape decides how the two legitimate appends inside a bracket get through,
|
|
45
45
|
* and there is only one route: run with the marker STRIPPED from the context
|
|
46
|
-
* (`Effect.
|
|
46
|
+
* (`Effect.updateContext` over `Context.omit(AppendIsOwned)`). The bracket's own
|
|
47
47
|
* closing append is issued outside the scope it provided the marker in, and the
|
|
48
|
-
* codec's escape hatch strips it explicitly. Neither needs a second
|
|
48
|
+
* codec's escape hatch strips it explicitly. Neither needs a second service, a
|
|
49
49
|
* sanctioning flag or a mutable cell, and there is no way to be exempt by
|
|
50
50
|
* accident: an append is either lexically outside the marked region or it says in
|
|
51
51
|
* as many words that it is removing the marker.
|
|
@@ -56,10 +56,10 @@ var _effect = require("effect");
|
|
|
56
56
|
* owns it.
|
|
57
57
|
*
|
|
58
58
|
* `by` is a human-readable owner name and exists for the defect message alone —
|
|
59
|
-
* the refusal is decided by the
|
|
59
|
+
* the refusal is decided by the service's PRESENCE, never by this value, so nothing
|
|
60
60
|
* branches on it and no caller need agree on a vocabulary for it.
|
|
61
61
|
*/
|
|
62
|
-
class AppendIsOwned extends /*#__PURE__*/_effect.Context.
|
|
62
|
+
class AppendIsOwned extends /*#__PURE__*/_effect.Context.Service()('@kairos-es/core/AppendIsOwned') {}
|
|
63
63
|
/**
|
|
64
64
|
* Die if an append is already owned here; do nothing otherwise.
|
|
65
65
|
*
|
|
@@ -72,7 +72,7 @@ class AppendIsOwned extends /*#__PURE__*/_effect.Context.Tag('@kairos-es/core/Ap
|
|
|
72
72
|
* its escape hatch for a deliberate second append — which is what makes a defect
|
|
73
73
|
* affordable here.
|
|
74
74
|
*
|
|
75
|
-
* `Effect.serviceOption` is what keeps this free: it reads the
|
|
75
|
+
* `Effect.serviceOption` is what keeps this free: it reads the service if present and
|
|
76
76
|
* adds NOTHING to the requirement channel, so every existing append is unchanged
|
|
77
77
|
* and unprovisioned.
|
|
78
78
|
*/
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"AppendIsOwned.js","names":["_effect","require","AppendIsOwned","Context","
|
|
1
|
+
{"version":3,"file":"AppendIsOwned.js","names":["_effect","require","AppendIsOwned","Context","Service","exports","assertAppendNotOwned","Effect","flatMap","serviceOption","owner","_tag","void","die","Error","value","by"],"sources":["../../src/AppendIsOwned.ts"],"sourcesContent":[null],"mappings":";;;;;;AA6CA,IAAAA,OAAA,GAAAC,OAAA;AA7CA;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;AA+CA;;;;;;;;AAQM,MAAOC,aAAc,sBAAQC,eAAO,CAACC,OAAO,EAG/C,CAAC,+BAA+B,CAAC;AAEpC;;;;;;;;;;;;;;;;AAAAC,OAAA,CAAAH,aAAA,GAAAA,aAAA;AAgBO,MAAMI,oBAAoB,GAAAD,OAAA,CAAAC,oBAAA,gBAAwBC,cAAM,CAACC,OAAO,cACrED,cAAM,CAACE,aAAa,CAACP,aAAa,CAAC,EAClCQ,KAAK,IACJA,KAAK,CAACC,IAAI,KAAK,MAAM,GACjBJ,cAAM,CAACK,IAAI,GACXL,cAAM,CAACM,GAAG,CACR,IAAIC,KAAK,CACP,kEAAkEJ,KAAK,CAACK,KAAK,CAACC,EAAE,MAAM,GACpF,4EAA4E,GAC5E,0EAA0E,GAC1E,4EAA4E,GAC5E,0EAA0E,GAC1E,sEAAsE,CACzE,CACF,CACR","ignoreList":[]}
|
|
@@ -28,7 +28,7 @@ const makeContractStore = raw => ({
|
|
|
28
28
|
append: (events, condition) =>
|
|
29
29
|
// The ownership refusal runs FIRST and sits OUTSIDE the suspend, because it is
|
|
30
30
|
// the only one of append's checks that is EFFECTFUL: it consults a
|
|
31
|
-
// `Context.
|
|
31
|
+
// `Context.Service` rather than inspecting the arguments. `Effect.flatMap` over an
|
|
32
32
|
// already-lazy effect defers it exactly as the suspend defers the throws below,
|
|
33
33
|
// so nothing runs at the call site either way; what it buys is that the
|
|
34
34
|
// "you are inside a bracket" defect arrives before any argument is judged, which
|
|
@@ -83,7 +83,7 @@ const makeContractStore = raw => ({
|
|
|
83
83
|
// engine's channel simply answers false and dies as it should. It also
|
|
84
84
|
// narrows the raw `AppendConditionFailed | E` to the contract's single
|
|
85
85
|
// error, which is what keeps `append` at `E = AppendConditionFailed`.
|
|
86
|
-
return _effect.Effect.
|
|
86
|
+
return _effect.Effect.catch(raw.append(events, condition), error => _effect.Predicate.isTagged('AppendConditionFailed')(error) ? _effect.Effect.fail(error) : _effect.Effect.die(error));
|
|
87
87
|
})),
|
|
88
88
|
subscribe: (query, after) =>
|
|
89
89
|
// `Effect.sync` runs when the stream is executed; a throw from
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"ContractStore.js","names":["_effect","require","_AppendCondition","_AppendIsOwned","_Event","_Query","decodeReadLimit","Schema","decodeUnknownSync","ReadLimit","makeContractStore","raw","read","query","options","Effect","suspend","assertServableQuery","limit","undefined","orDie","append","events","condition","flatMap","assertAppendNotOwned","length","Error","unknown","Object","keys","find","key","hasOwn","AppendCondition","fields","JSON","stringify","failIfEventsMatch","
|
|
1
|
+
{"version":3,"file":"ContractStore.js","names":["_effect","require","_AppendCondition","_AppendIsOwned","_Event","_Query","decodeReadLimit","Schema","decodeUnknownSync","ReadLimit","makeContractStore","raw","read","query","options","Effect","suspend","assertServableQuery","limit","undefined","orDie","append","events","condition","flatMap","assertAppendNotOwned","length","Error","unknown","Object","keys","find","key","hasOwn","AppendCondition","fields","JSON","stringify","failIfEventsMatch","catch","error","Predicate","isTagged","fail","die","subscribe","after","Stream","unwrap","sync","exports"],"sources":["../../src/ContractStore.ts"],"sourcesContent":[null],"mappings":";;;;;;AAsCA,IAAAA,OAAA,GAAAC,OAAA;AACA,IAAAC,gBAAA,GAAAD,OAAA;AACA,IAAAE,cAAA,GAAAF,OAAA;AAGA,IAAAG,MAAA,GAAAH,OAAA;AAEA,IAAAI,MAAA,GAAAJ,OAAA;AAEA;AACA,MAAMK,eAAe,gBAAGC,cAAM,CAACC,iBAAiB,CAACC,gBAAS,CAAC;AAwB3D;;;;AAIO,MAAMC,iBAAiB,GAC5BC,GAAwB,KACM;EAC9BC,IAAI,EAAEA,CAACC,KAAK,EAAEC,OAAO,KACnBC,cAAM,CAACC,OAAO,CAAC,MAAK;IAClB;IACA,IAAAC,0BAAmB,EAACJ,KAAK,CAAC;IAC1B,IAAIC,OAAO,EAAEI,KAAK,KAAKC,SAAS,EAAE;MAChCb,eAAe,CAACQ,OAAO,CAACI,KAAK,CAAC;IAChC;IACA;IACA,OAAOH,cAAM,CAACK,KAAK,CAACT,GAAG,CAACC,IAAI,CAACC,KAAK,EAAEC,OAAO,CAAC,CAAC;EAC/C,CAAC,CAAC;EAEJO,MAAM,EAAEA,CAACC,MAAM,EAAEC,SAAS;EACxB;EACA;EACA;EACA;EACA;EACA;EACA;EACA;EACAR,cAAM,CAACS,OAAO,CAACC,m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0BAAmB,EAACJ,KAAK,CAAC;IAC1B,OAAOkC,cAAM,CAAC3B,KAAK,CAACT,GAAG,CAACkC,SAAS,CAAChC,KAAK,EAAEiC,KAAK,CAAC,CAAC;EAClD,CAAC,CAAC;CAEP,CAAC;AAAAI,OAAA,CAAAxC,iBAAA,GAAAA,iBAAA","ignoreList":[]}
|
|
@@ -5,6 +5,6 @@ Object.defineProperty(exports, "__esModule", {
|
|
|
5
5
|
});
|
|
6
6
|
exports.DcbEventStore = void 0;
|
|
7
7
|
var _effect = require("effect");
|
|
8
|
-
class DcbEventStore extends /*#__PURE__*/_effect.Context.
|
|
8
|
+
class DcbEventStore extends /*#__PURE__*/_effect.Context.Service()('@kairos-es/core/DcbEventStore') {}
|
|
9
9
|
exports.DcbEventStore = DcbEventStore;
|
|
10
10
|
//# sourceMappingURL=DcbEventStore.js.map
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"DcbEventStore.js","names":["_effect","require","DcbEventStore","Context","
|
|
1
|
+
{"version":3,"file":"DcbEventStore.js","names":["_effect","require","DcbEventStore","Context","Service","exports"],"sources":["../../src/DcbEventStore.ts"],"sourcesContent":[null],"mappings":";;;;;;AAiBA,IAAAA,OAAA,GAAAC,OAAA;AA2BM,MAAOC,aAAc,sBAAQC,eAAO,CAACC,OAAO,EAgC/C,CAAC,+BAA+B,CAAC;AAAAC,OAAA,CAAAH,aAAA,GAAAA,aAAA","ignoreList":[]}
|
package/dist/cjs/Event.js
CHANGED
|
@@ -19,11 +19,28 @@ var _effect = require("effect");
|
|
|
19
19
|
*
|
|
20
20
|
* The log is 64-bit (`bigserial` in Postgres) and exceeds JS `number` safety at
|
|
21
21
|
* 2^53, so positions are a `bigint`. They are compared, never arithmetic'd.
|
|
22
|
-
*
|
|
22
|
+
* Encoded, a position is a decimal string (JSON-safe, `String(b)`); decoded, a
|
|
23
23
|
* `bigint`. `0n` is the "before the first event" sentinel used by `after` and by
|
|
24
24
|
* an empty store's head.
|
|
25
|
+
*
|
|
26
|
+
* The string-to-`bigint` step is hand-built rather than Effect 4's
|
|
27
|
+
* `Schema.BigIntFromString`, because that schema accepts only `^-?\d+$` and so
|
|
28
|
+
* refuses inputs the encoded side has always admitted — `" 5"`, `"+5"`,
|
|
29
|
+
* `"0x10"`. The decode here is the global `BigInt(s)` behind a blank-string
|
|
30
|
+
* refusal, which is `BigInt.fromString` and is exactly what Effect 3's
|
|
31
|
+
* `Schema.BigInt` ran, so a position string any earlier release decoded still
|
|
32
|
+
* decodes to the same value. The non-negative check then runs on the `bigint`,
|
|
33
|
+
* as it always did.
|
|
25
34
|
*/
|
|
26
|
-
const Position = exports.Position = /*#__PURE__*/_effect.Schema.
|
|
35
|
+
const Position = exports.Position = /*#__PURE__*/_effect.Schema.String.pipe(/*#__PURE__*/_effect.Schema.decodeTo(_effect.Schema.BigInt, /*#__PURE__*/_effect.SchemaTransformation.transformEffect({
|
|
36
|
+
decode: (s, options) => _effect.Option.match(_effect.BigInt.fromString(s), {
|
|
37
|
+
onNone: () => _effect.Effect.fail(new _effect.SchemaIssue.InvalidValue({
|
|
38
|
+
message: `Unable to decode ${JSON.stringify(s)} into a bigint`
|
|
39
|
+
}, s, options)),
|
|
40
|
+
onSome: _effect.Effect.succeed
|
|
41
|
+
}),
|
|
42
|
+
encode: b => _effect.Effect.succeed(String(b))
|
|
43
|
+
})), /*#__PURE__*/_effect.Schema.check(/*#__PURE__*/_effect.Schema.isGreaterThanOrEqualToBigInt(0n)), /*#__PURE__*/_effect.Schema.brand('Position'));
|
|
27
44
|
/** The sentinel position meaning "before the first event". */
|
|
28
45
|
const ORIGIN = exports.ORIGIN = /*#__PURE__*/Position.make(0n);
|
|
29
46
|
/**
|
|
@@ -32,9 +49,9 @@ const ORIGIN = exports.ORIGIN = /*#__PURE__*/Position.make(0n);
|
|
|
32
49
|
* event sourcing; a query matches an event when the event carries all of an
|
|
33
50
|
* item's tags (superset test).
|
|
34
51
|
*/
|
|
35
|
-
const Tag = exports.Tag = /*#__PURE__*/_effect.Schema.String.pipe(/*#__PURE__*/_effect.Schema.
|
|
52
|
+
const Tag = exports.Tag = /*#__PURE__*/_effect.Schema.String.pipe(/*#__PURE__*/_effect.Schema.check(/*#__PURE__*/_effect.Schema.isPattern(/^[^:]+:.+/, {
|
|
36
53
|
identifier: 'Tag'
|
|
37
|
-
}), /*#__PURE__*/_effect.Schema.brand('Tag'));
|
|
54
|
+
})), /*#__PURE__*/_effect.Schema.brand('Tag'));
|
|
38
55
|
const tagIdentity = key => {
|
|
39
56
|
if (key.length === 0 || key.includes(':')) {
|
|
40
57
|
throw new Error(`tagIdentity: key must be non-empty and contain no ':' (got ${JSON.stringify(key)})`);
|
|
@@ -60,12 +77,12 @@ const tagIdentity = key => {
|
|
|
60
77
|
* `ReadLimit.make(n)`.
|
|
61
78
|
*/
|
|
62
79
|
exports.tagIdentity = tagIdentity;
|
|
63
|
-
const ReadLimit = exports.ReadLimit = /*#__PURE__*/_effect.Schema.Int.pipe(/*#__PURE__*/_effect.Schema.
|
|
80
|
+
const ReadLimit = exports.ReadLimit = /*#__PURE__*/_effect.Schema.Int.pipe(/*#__PURE__*/_effect.Schema.check(/*#__PURE__*/_effect.Schema.isGreaterThanOrEqualTo(0)), /*#__PURE__*/_effect.Schema.brand('ReadLimit'));
|
|
64
81
|
/**
|
|
65
82
|
* An event type name, a branded non-empty string. Versioning is by convention
|
|
66
83
|
* in the name (e.g. `course-registered.v2`); only non-emptiness is enforced.
|
|
67
84
|
*/
|
|
68
|
-
const EventType = exports.EventType = /*#__PURE__*/_effect.Schema.String.pipe(/*#__PURE__*/_effect.Schema.
|
|
85
|
+
const EventType = exports.EventType = /*#__PURE__*/_effect.Schema.String.pipe(/*#__PURE__*/_effect.Schema.check(/*#__PURE__*/_effect.Schema.isNonEmpty()), /*#__PURE__*/_effect.Schema.brand('EventType'));
|
|
69
86
|
/**
|
|
70
87
|
* An event's metadata: a flat bag of strings carrying the circumstances under
|
|
71
88
|
* which the event was RECORDED, never anything the business asserts (ADR-0017).
|
|
@@ -115,10 +132,7 @@ const EventType = exports.EventType = /*#__PURE__*/_effect.Schema.String.pipe(/*
|
|
|
115
132
|
* alone: it would make an event the store accepted unreadable for ever, so a
|
|
116
133
|
* value check belongs at write or nowhere.
|
|
117
134
|
*/
|
|
118
|
-
const Metadata = exports.Metadata = /*#__PURE__*/_effect.Schema.Record(
|
|
119
|
-
key: _effect.Schema.String,
|
|
120
|
-
value: _effect.Schema.String
|
|
121
|
-
});
|
|
135
|
+
const Metadata = exports.Metadata = /*#__PURE__*/_effect.Schema.Record(_effect.Schema.String, _effect.Schema.String);
|
|
122
136
|
/**
|
|
123
137
|
* An event as stored: an opaque payload plus its type, tags, a
|
|
124
138
|
* producer-supplied `uuid`, producer-supplied `occurredAt` domain time, and its
|
|
@@ -126,6 +140,8 @@ const Metadata = exports.Metadata = /*#__PURE__*/_effect.Schema.Record({
|
|
|
126
140
|
*
|
|
127
141
|
* `data` is `Uint8Array` (opaque bytes); the store does not interpret it.
|
|
128
142
|
* `uuid` is producer-supplied to keep `core` deterministic (no RNG in core).
|
|
143
|
+
* It is checked for UUID SHAPE only (`isGUID`), not for a version nibble: a
|
|
144
|
+
* stricter check would refuse ids an existing log already holds.
|
|
129
145
|
* `occurredAt` is informational only; ordering is by position alone.
|
|
130
146
|
* `metadata` mirrors `tags` rather than `data`: REQUIRED, with an empty bag
|
|
131
147
|
* legal. Required because an absent-versus-empty divergence between engines is
|
|
@@ -135,10 +151,10 @@ const Metadata = exports.Metadata = /*#__PURE__*/_effect.Schema.Record({
|
|
|
135
151
|
*/
|
|
136
152
|
const DcbEvent = exports.DcbEvent = /*#__PURE__*/_effect.Schema.Struct({
|
|
137
153
|
type: EventType,
|
|
138
|
-
data: _effect.Schema.
|
|
154
|
+
data: _effect.Schema.Uint8Array,
|
|
139
155
|
tags: /*#__PURE__*/_effect.Schema.Array(Tag),
|
|
140
|
-
uuid: _effect.Schema.
|
|
141
|
-
occurredAt: _effect.Schema.
|
|
156
|
+
uuid: /*#__PURE__*/_effect.Schema.String.check(/*#__PURE__*/_effect.Schema.isGUID()),
|
|
157
|
+
occurredAt: _effect.Schema.DateTimeUtcFromString,
|
|
142
158
|
metadata: Metadata
|
|
143
159
|
});
|
|
144
160
|
/** A persisted event: the event together with the position it was written at. */
|
package/dist/cjs/Event.js.map
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"Event.js","names":["_effect","require","Position","exports","Schema","
|
|
1
|
+
{"version":3,"file":"Event.js","names":["_effect","require","Position","exports","Schema","String","pipe","decodeTo","BigInt","SchemaTransformation","transformEffect","decode","s","options","Option","match","BigInt_","fromString","onNone","Effect","fail","SchemaIssue","InvalidValue","message","JSON","stringify","onSome","succeed","encode","b","check","isGreaterThanOrEqualToBigInt","brand","ORIGIN","make","Tag","isPattern","identifier","tagIdentity","key","length","includes","Error","value","ReadLimit","Int","isGreaterThanOrEqualTo","EventType","isNonEmpty","Metadata","Record","DcbEvent","Struct","type","data","Uint8Array","tags","Array","uuid","isGUID","occurredAt","DateTimeUtcFromString","metadata","SequencedEvent","event","position"],"sources":["../../src/Event.ts"],"sourcesContent":[null],"mappings":";;;;;;AAQA,IAAAA,OAAA,GAAAC,OAAA;AARA;;;;;;;;;AAiBA;;;;;;;;;;;;;;;;;;AAkBO,MAAMC,QAAQ,GAAAC,OAAA,CAAAD,QAAA,gBAAGE,cAAM,CAACC,MAAM,CAACC,IAAI,cACxCF,cAAM,CAACG,QAAQ,CACbH,cAAM,CAACI,MAAM,eACbC,4BAAoB,CAACC,eAAe,CAAiB;EACnDC,MAAM,EAAEA,CAACC,CAAC,EAAEC,OAAO,KACjBC,cAAM,CAACC,KAAK,CAACC,cAAO,CAACC,UAAU,CAACL,CAAC,CAAC,EAAE;IAClCM,MAAM,EAAEA,CAAA,KACNC,cAAM,CAACC,IAAI,CACT,IAAIC,mBAAW,CAACC,YAAY,CAC1B;MACEC,OAAO,EAAE,oBAAoBC,IAAI,CAACC,SAAS,CAACb,C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A,CAAA4D,cAAA,gBAAG3D,cAAM,CAACgD,MAAM,CAAC;EAC1CY,KAAK,EAAEb,QAAQ;EACfc,QAAQ,EAAE/D;CACX,CAAC","ignoreList":[]}
|
package/dist/cjs/Query.js
CHANGED
|
@@ -238,7 +238,7 @@ const classifyServableQuery = query => {
|
|
|
238
238
|
}
|
|
239
239
|
const only = query.items.length === 1 ? query.items[0] : undefined;
|
|
240
240
|
if (only !== undefined && only.tags.length === 0) {
|
|
241
|
-
return _effect.Array.
|
|
241
|
+
return _effect.Array.isReadonlyArrayNonEmpty(only.types) ? {
|
|
242
242
|
kind: 'typeOnly',
|
|
243
243
|
types: only.types
|
|
244
244
|
} : {
|
package/dist/cjs/Query.js.map
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"Query.js","names":["_effect","require","_Event","QueryItem","exports","Schema","Struct","types","Array","EventType","tags","Tag","Query","items","matchesQueryItem","event","item","typeOk","length","includes","type","eventTags","Set","every","tag","has","matchesQuery","query","some","matchesSequenced","sequenced","assertServableQuery","fault","servableQueryFault","undefined","Error","unknownKeyFault","where","value","schemaFields","unknown","Object","keys","find","key","hasOwn","JSON","stringify","unknownQueryKeyFault","fields","reduce","unknownKey","classifyServableQuery","kind","only","Arr","
|
|
1
|
+
{"version":3,"file":"Query.js","names":["_effect","require","_Event","QueryItem","exports","Schema","Struct","types","Array","EventType","tags","Tag","Query","items","matchesQueryItem","event","item","typeOk","length","includes","type","eventTags","Set","every","tag","has","matchesQuery","query","some","matchesSequenced","sequenced","assertServableQuery","fault","servableQueryFault","undefined","Error","unknownKeyFault","where","value","schemaFields","unknown","Object","keys","find","key","hasOwn","JSON","stringify","unknownQueryKeyFault","fields","reduce","unknownKey","classifyServableQuery","kind","only","Arr","isReadonlyArrayNonEmpty","all","or"],"sources":["../../src/Query.ts"],"sourcesContent":[null],"mappings":";;;;;;AAwBA,IAAAA,OAAA,GAAAC,OAAA;AACA,IAAAC,MAAA,GAAAD,OAAA;AAzBA;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GAAAA,qBAAA;AAMA,MAAMpC,IAAI,GAAIiC,MAGb,KAAiB;EAChB1C,KAAK,EAAE0C,MAAM,CAAC1C,KAAK,IAAI,EAAE;EACzBG,IAAI,EAAEuC,MAAM,CAACvC;CACd,CAAC;AAEF;AACA,MAAM+C,GAAG,GAAGA,CAAA,MAAc;EAAE5C,KAAK,EAAE;AAAE,CAAE,CAAC;AAExC;;;;AAIA,MAAMH,IAAI,GAAGA,CACXA,IAA2C,EAC3CH,KAAgC,MACrB;EACXM,KAAK,EAAE,CAACG,IAAI,CAAC;IAAEN,IAAI;IAAE,IAAIH,KAAK,KAAK2B,SAAS,GAAG,EAAE,GAAG;MAAE3B;IAAK,CAAE;EAAC,CAAE,CAAC;CAClE,CAAC;AAEF;;;;;AAKA,MAAMA,KAAK,GACTA,KAAwD,KAC7C;EAAEM,KAAK,EAAE,CAAC;IAAEN,KAAK;IAAEG,IAAI,EAAE;EAAE,CAAE;AAAC,CAAE,CAAC;AAE9C;;;;;AAKA,MAAMgD,EAAE,GACN7C,KAAwD,KAC7C;EACXA;CACD,CAAC;AAEF;AACO,MAAMc,KAAK,GAAAvB,OAAA,CAAAuB,KAAA,GAAG;EACnB8B,GAAG;EACHzC,IAAI;EACJ0C,EAAE;EACFhD,IAAI;EACJH;CACQ","ignoreList":[]}
|
|
@@ -114,12 +114,12 @@ const DEFAULT_POLL_INTERVAL_MILLIS = exports.DEFAULT_POLL_INTERVAL_MILLIS = 1000
|
|
|
114
114
|
* the key NAME, the VALIDATION and the DEFAULT from one place, so a caller who has
|
|
115
115
|
* tuned one engine's subscribe reads another's without translating, and the two
|
|
116
116
|
* cannot drift in what they ACCEPT any more than in what they assume. Two engines
|
|
117
|
-
* hand-authoring the identical `Schema.
|
|
117
|
+
* hand-authoring the identical `Schema.optionalKey(…)` twice were identical only
|
|
118
118
|
* by inspection.
|
|
119
119
|
*
|
|
120
120
|
* The bounds differ between the two because the quantities do. `pollInterval` is a
|
|
121
|
-
* duration, so a fraction of a millisecond is meaningful and only `
|
|
122
|
-
* `
|
|
121
|
+
* duration, so a fraction of a millisecond is meaningful and only `isGreaterThan(0)`
|
|
122
|
+
* and `isFinite` matter: at zero or below the loop would spin without ever waiting for a
|
|
123
123
|
* wake, and at `Infinity` the periodic re-read — the half that carries delivery —
|
|
124
124
|
* would never come, which silently converts the wake source from an optimisation
|
|
125
125
|
* into the guarantee. `catchUpPageSize` is a COUNT, so it must be an integer
|
|
@@ -127,17 +127,13 @@ const DEFAULT_POLL_INTERVAL_MILLIS = exports.DEFAULT_POLL_INTERVAL_MILLIS = 1000
|
|
|
127
127
|
* length against it to decide the tail is drained, and a page of zero would report
|
|
128
128
|
* "drained" forever without reading anything.
|
|
129
129
|
*
|
|
130
|
-
* `
|
|
130
|
+
* `optionalKey` on both keeps the decoded type at `key?: T` rather than
|
|
131
131
|
* `T | undefined`, matching the repo's `exactOptionalPropertyTypes` discipline — an
|
|
132
132
|
* absent key, never an explicit `undefined`.
|
|
133
133
|
*/
|
|
134
134
|
const subscriptionTuningFields = exports.subscriptionTuningFields = {
|
|
135
|
-
pollInterval: /*#__PURE__*/_effect.Schema.
|
|
136
|
-
|
|
137
|
-
}),
|
|
138
|
-
catchUpPageSize: /*#__PURE__*/_effect.Schema.optionalWith(/*#__PURE__*/_effect.Schema.Int.pipe(/*#__PURE__*/_effect.Schema.positive()), {
|
|
139
|
-
exact: true
|
|
140
|
-
})
|
|
135
|
+
pollInterval: /*#__PURE__*/_effect.Schema.optionalKey(/*#__PURE__*/_effect.Schema.Number.check(/*#__PURE__*/_effect.Schema.isGreaterThan(0), /*#__PURE__*/_effect.Schema.isFinite())),
|
|
136
|
+
catchUpPageSize: /*#__PURE__*/_effect.Schema.optionalKey(/*#__PURE__*/_effect.Schema.Int.check(/*#__PURE__*/_effect.Schema.isGreaterThan(0)))
|
|
141
137
|
};
|
|
142
138
|
/**
|
|
143
139
|
* Retry a TRANSIENT poll fault (an `E` from one reconcile read) on a capped
|
|
@@ -146,16 +142,16 @@ const subscriptionTuningFields = exports.subscriptionTuningFields = {
|
|
|
146
142
|
* past the cap propagates (the decorator dies it) — infrastructure stays off the
|
|
147
143
|
* contract channel while the stream survives ordinary transients.
|
|
148
144
|
*/
|
|
149
|
-
const POLL_RETRY_SCHEDULE = /*#__PURE__*/_effect.Schedule.
|
|
145
|
+
const POLL_RETRY_SCHEDULE = /*#__PURE__*/_effect.Schedule.max([/*#__PURE__*/_effect.Schedule.min([/*#__PURE__*/_effect.Schedule.exponential('100 millis', 2), /*#__PURE__*/_effect.Schedule.spaced('2 seconds')]), /*#__PURE__*/_effect.Schedule.recurs(20)]);
|
|
150
146
|
/**
|
|
151
147
|
* Build the subscription `Stream`: catch up from `after`, then track the live tail.
|
|
152
|
-
* The cursor threads through the `
|
|
153
|
-
*
|
|
154
|
-
*
|
|
155
|
-
* on close. An `E` mid-stream stays on the channel; `makeContractStore` dies it
|
|
148
|
+
* The cursor threads through the `Stream.paginate` state, starting at `after` and
|
|
149
|
+
* advancing to the last delivered position each batch; the stream never completes
|
|
150
|
+
* on its own (the next state is always `Option.some`), so the enclosing scope
|
|
151
|
+
* interrupts it on close. An `E` mid-stream stays on the channel; `makeContractStore` dies it
|
|
156
152
|
* (subscribe is `E = never` on the contract).
|
|
157
153
|
*/
|
|
158
|
-
const subscribeStream = (deps, after) => _effect.Stream.
|
|
154
|
+
const subscribeStream = (deps, after) => _effect.Stream.unwrap(_effect.Effect.gen(function* () {
|
|
159
155
|
// The wake primitive: a sliding(1) queue holding at most one pending
|
|
160
156
|
// signal. The wake source `offer`s an opaque wake on every notification;
|
|
161
157
|
// the poll loop `take`s (with a timeout). The lost-wakeup guard is
|
|
@@ -171,7 +167,7 @@ const subscribeStream = (deps, after) => _effect.Stream.unwrapScoped(_effect.Eff
|
|
|
171
167
|
// silently-dropped (and later re-established) wake source loses no
|
|
172
168
|
// positions. Absent a wake source entirely, `Stream.never` makes this a
|
|
173
169
|
// fibre that parks forever and delivery falls to the poll alone.
|
|
174
|
-
const listener = (deps.listen ?? _effect.Stream.never).pipe(_effect.Stream.tap(() => _effect.Queue.offer(wake, undefined)), _effect.Stream.retry(_effect.Schedule.exponential('50 millis')
|
|
170
|
+
const listener = (deps.listen ?? _effect.Stream.never).pipe(_effect.Stream.tap(() => _effect.Queue.offer(wake, undefined)), _effect.Stream.retry(_effect.Schedule.min([_effect.Schedule.exponential('50 millis'), _effect.Schedule.spaced('1 seconds')])));
|
|
175
171
|
// Drain the wake source into the wake queue on a background fibre; the
|
|
176
172
|
// scope releases it. We never read its elements directly — every
|
|
177
173
|
// notification is an opaque wake signal.
|
|
@@ -203,7 +199,7 @@ const subscribeStream = (deps, after) => _effect.Stream.unwrapScoped(_effect.Eff
|
|
|
203
199
|
}).pipe(_effect.Effect.retry(POLL_RETRY_SCHEDULE));
|
|
204
200
|
/**
|
|
205
201
|
* Produce the NEXT non-empty batch from a cursor position, together with
|
|
206
|
-
* the advanced cursor — a pure `Position → Effect<[
|
|
202
|
+
* the advanced cursor — a pure `Position → Effect<[events, next]>`. The
|
|
207
203
|
* `> boundary` de-dup is enforced by `fetch`'s exclusive lower bound, so a
|
|
208
204
|
* live re-read after a wake never re-emits an already-delivered position.
|
|
209
205
|
*
|
|
@@ -211,25 +207,27 @@ const subscribeStream = (deps, after) => _effect.Stream.unwrapScoped(_effect.Eff
|
|
|
211
207
|
* the cursor. If a drain yields nothing, wait for a wake but only up to the
|
|
212
208
|
* poll interval, then loop and re-read ANYWAY — the periodic position-based
|
|
213
209
|
* poll that makes delivery correct independently of any wake. This effect
|
|
214
|
-
* only completes by returning a non-empty
|
|
210
|
+
* only completes by returning a non-empty batch; the scope interrupts it on
|
|
215
211
|
* close.
|
|
216
212
|
*/
|
|
217
213
|
const nextBatch = from => _effect.Effect.gen(function* () {
|
|
218
214
|
while (true) {
|
|
219
|
-
|
|
215
|
+
// `Queue.clear` and not `Queue.takeAll`: the drain must NOT wait, and
|
|
216
|
+
// `takeAll` suspends until at least one signal is present.
|
|
217
|
+
yield* _effect.Queue.clear(wake);
|
|
220
218
|
const {
|
|
221
219
|
events,
|
|
222
220
|
last
|
|
223
221
|
} = yield* drainFrom(from);
|
|
224
222
|
if (events.length > 0) {
|
|
225
|
-
return [
|
|
223
|
+
return [events, last];
|
|
226
224
|
}
|
|
227
225
|
// Nothing new: block on a wake, but only up to the poll interval — on
|
|
228
226
|
// timeout we fall through and the loop re-reads regardless.
|
|
229
227
|
yield* _effect.Effect.ignore(_effect.Effect.timeout(_effect.Queue.take(wake), deps.pollInterval));
|
|
230
228
|
}
|
|
231
229
|
});
|
|
232
|
-
return _effect.Stream.
|
|
230
|
+
return _effect.Stream.paginate(after ?? _Event.ORIGIN, from => _effect.Effect.map(nextBatch(from), ([events, last]) => [events, _effect.Option.some(last)]));
|
|
233
231
|
}));
|
|
234
232
|
exports.subscribeStream = subscribeStream;
|
|
235
233
|
//# sourceMappingURL=SubscribeMachine.js.map
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"SubscribeMachine.js","names":["_effect","require","_Event","DEFAULT_CATCH_UP_PAGE_SIZE","exports","DEFAULT_POLL_INTERVAL_MILLIS","subscriptionTuningFields","pollInterval","Schema","
|
|
1
|
+
{"version":3,"file":"SubscribeMachine.js","names":["_effect","require","_Event","DEFAULT_CATCH_UP_PAGE_SIZE","exports","DEFAULT_POLL_INTERVAL_MILLIS","subscriptionTuningFields","pollInterval","Schema","optionalKey","Number","check","isGreaterThan","isFinite","catchUpPageSize","Int","POLL_RETRY_SCHEDULE","Schedule","max","min","exponential","spaced","recurs","subscribeStream","deps","after","Stream","unwrap","Effect","gen","wake","Queue","sliding","listener","listen","never","pipe","tap","offer","undefined","retry","runDrain","forkScoped","drainFrom","from","collected","cursor","events","fetch","ReadLimit","make","event","push","lastEvent","at","length","position","last","nextBatch","clear","ignore","timeout","take","paginate","ORIGIN","map","Option","some"],"sources":["../../src/SubscribeMachine.ts"],"sourcesContent":[null],"mappings":";;;;;;AAsEA,IAAAA,OAAA,GAAAC,OAAA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AAE;EACpC,CAAC,CAAC,CAACrB,IAAI,CAACR,cAAM,CAACY,KAAK,CAACxB,mBAAmB,CAAC,CAAC;EAE5C;;;;;;;;;;;;;EAaA,MAAM0C,SAAS,GACbd,IAAc,IAEdhB,cAAM,CAACC,GAAG,CAAC,aAAS;IAClB,OAAO,IAAI,EAAE;MACX;MACA;MACA,OAAOE,aAAK,CAAC4B,KAAK,CAAC7B,IAAI,CAAC;MACxB,MAAM;QAAEiB,MAAM;QAAEU;MAAI,CAAE,GAAG,OAAOd,SAAS,CAACC,IAAI,CAAC;MAC/C,IAAIG,MAAM,CAACQ,MAAM,GAAG,CAAC,EAAE;QACrB,OAAO,CAACR,MAAM,EAAEU,IAAI,CAAU;MAChC;MACA;MACA;MACA,OAAO7B,cAAM,CAACgC,MAAM,CAClBhC,cAAM,CAACiC,OAAO,CAAC9B,aAAK,CAAC+B,IAAI,CAAChC,IAAI,CAAC,EAAEN,IAAI,CAACjB,YAAY,CAAC,CACpD;IACH;EACF,CAAC,CAAC;EAEJ,OAAOmB,cAAM,CAACqC,QAAQ,CAACtC,KAAK,IAAIuC,aAAM,EAAGpB,IAAI,IAC3ChB,cAAM,CAACqC,GAAG,CACRP,SAAS,CAACd,IAAI,CAAC,EACf,CAAC,CAACG,MAAM,EAAEU,IAAI,CAAC,KAAK,CAACV,MAAM,EAAEmB,cAAM,CAACC,IAAI,CAACV,IAAI,CAAC,CAAU,CACzD,CACF;AACH,CAAC,CAAC,CACH;AAAArD,OAAA,CAAAmB,eAAA,GAAAA,eAAA","ignoreList":[]}
|
package/dist/cjs/inMemory.js
CHANGED
|
@@ -43,7 +43,7 @@ const copyEvent = event => ({
|
|
|
43
43
|
data: new Uint8Array(event.data),
|
|
44
44
|
tags: [...event.tags],
|
|
45
45
|
uuid: event.uuid,
|
|
46
|
-
occurredAt: _effect.DateTime.
|
|
46
|
+
occurredAt: _effect.DateTime.makeUnsafe(_effect.DateTime.toEpochMillis(event.occurredAt)),
|
|
47
47
|
metadata: {
|
|
48
48
|
...event.metadata
|
|
49
49
|
}
|
|
@@ -158,7 +158,7 @@ const make = options => _effect.Effect.gen(function* () {
|
|
|
158
158
|
const catchUpPageSize = options?.catchUpPageSize ?? _SubscribeMachine.DEFAULT_CATCH_UP_PAGE_SIZE;
|
|
159
159
|
const pollInterval = options?.pollInterval ?? _SubscribeMachine.DEFAULT_POLL_INTERVAL_MILLIS;
|
|
160
160
|
const log = yield* _effect.Ref.make([]);
|
|
161
|
-
const mutex = yield* _effect.
|
|
161
|
+
const mutex = yield* _effect.Semaphore.make(1);
|
|
162
162
|
const hub = yield* _effect.PubSub.unbounded();
|
|
163
163
|
const nextPosition = yield* _effect.Ref.make(1n);
|
|
164
164
|
const read = (query, options) =>
|
|
@@ -225,14 +225,14 @@ const make = options => _effect.Effect.gen(function* () {
|
|
|
225
225
|
// exclusive cursor is what makes the catch-up/live seam exactly-once, so there
|
|
226
226
|
// is nothing left here for a critical section to protect. `append` keeps its
|
|
227
227
|
// permit, which is the whole exactly-one-wins guarantee.
|
|
228
|
-
_effect.Stream.
|
|
228
|
+
_effect.Stream.unwrap(_effect.Effect.gen(function* () {
|
|
229
229
|
// Taken when the subscription starts, as the SQL engines compile theirs
|
|
230
230
|
// (see `copyQuery`).
|
|
231
231
|
const judged = copyQuery(query);
|
|
232
232
|
const wakes = yield* _effect.PubSub.subscribe(hub);
|
|
233
233
|
return (0, _SubscribeMachine.subscribeStream)({
|
|
234
234
|
fetch: (from, limit) => _effect.Effect.map(_effect.Ref.get(log), snapshot => fetchPage(snapshot, judged, from, limit)),
|
|
235
|
-
listen: _effect.Stream.
|
|
235
|
+
listen: _effect.Stream.fromSubscription(wakes),
|
|
236
236
|
pollInterval,
|
|
237
237
|
catchUpPageSize
|
|
238
238
|
}, after);
|
package/dist/cjs/inMemory.js.map
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"inMemory.js","names":["_effect","require","_ContractStore","_DcbEventStore","_Event","_errors","_Query","_SubscribeMachine","copyEvent","event","type","data","Uint8Array","tags","uuid","occurredAt","DateTime","
|
|
1
|
+
{"version":3,"file":"inMemory.js","names":["_effect","require","_ContractStore","_DcbEventStore","_Event","_errors","_Query","_SubscribeMachine","copyEvent","event","type","data","Uint8Array","tags","uuid","occurredAt","DateTime","makeUnsafe","toEpochMillis","metadata","copyQuery","query","items","map","item","types","copySequenced","sequenced","position","filterLog","log","after","filter","undefined","matchesSequenced","lastPosition","events","at","readSnapshot","options","matched","limited","limit","slice","head","ORIGIN","Stream","fromIterable","firstIndexAfter","low","high","length","mid","fetchPage","from","page","index","push","make","Effect","gen","beforeCommit","void","suppressWake","catchUpPageSize","DEFAULT_CATCH_UP_PAGE_SIZE","pollInterval","DEFAULT_POLL_INTERVAL_MILLIS","Ref","mutex","Semaphore","hub","PubSub","unbounded","nextPosition","read","withPermits","get","snapshot","append","condition","suspend","owned","conflicts","failIfEventsMatch","AppendConditionFailed","start","appended","BigInt","end","set","publishAll","subscribe","unwrap","judged","wakes","subscribeStream","fetch","listen","fromSubscription","DcbEventStoreInMemory","exports","Layer","effect","DcbEventStore","makeContractStore","makeInMemoryTestLayer"],"sources":["../../src/inMemory.ts"],"sourcesContent":[null],"mappings":";;;;;;AA2BA,IAAAA,OAAA,GAAAC,OAAA;AAEA,IAAAC,cAAA,GAAAD,OAAA;AAEA,IAAAE,cAAA,GAAAF,OAAA;AAEA,IAAAG,MAAA,GAAAH,OAAA;AACA,IAAAI,OAAA,GAAAJ,OAAA;AAEA,IAAAK,MAAA,GAAAL,OAAA;AACA,IAAAM,iBAAA,GAAAN,OAAA;AAMA;;;;;;;;;;;;;;;;;;;;;;;;;;;AA2BA,MAAMO,SAAS,GAAIC,KAAe,KAAgB;EAChDC,IAAI,EAAED,KAAK,CAACC,IAAI;EAChBC,IAAI,EAAE,IAAIC,UAAU,CAACH,KAAK,CAACE,IAAI,CAAC;EAChCE,IAAI,EAAE,CAAC,GAAGJ,KAAK,CAACI,IAAI,CAAC;EACrBC,IAAI,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;EACA;EACA;EACA;EACA;EACA;EACA;EACA;EACAe,cAAM,CAAC+C,MAAM,CACXlC,cAAM,CAACC,GAAG,CAAC,aAAS;IAClB;IACA;IACA,MAAMkC,MAAM,GAAG1E,SAAS,CAACC,KAAK,CAAC;IAC/B,MAAM0E,KAAK,GAAG,OAAOvB,cAAM,CAACoB,SAAS,CAACrB,GAAG,CAAC;IAC1C,OAAO,IAAAyB,iCAAe,EACpB;MACEC,KAAK,EAAEA,CAAC3C,IAAI,EAAEZ,KAAK,KACjBiB,cAAM,CAACpC,GAAG,CAAC6C,WAAG,CAACS,GAAG,CAAC/C,GAAG,CAAC,EAAGgD,QAAQ,IAChCzB,SAAS,CAACyB,QAAQ,EAAEgB,MAAM,EAAExC,IAAI,EAAEZ,KAAK,CAAC,CACzC;MACHwD,MAAM,EAAEpD,cAAM,CAACqD,gBAAgB,CAACJ,KAAK,CAAC;MACtC7B,YAAY;MACZF;KACD,EACDjC,KAAK,CACN;EACH,CAAC,CAAC,CACH;EAEH,OAAO;IAAE4C,IAAI;IAAEI,MAAM;IAAEa;EAAS,CAAW;AAC7C,CAAC,CAAC;AAEJ;AACO,MAAMQ,qBAAqB,GAAAC,OAAA,CAAAD,qBAAA,gBAA+BE,aAAK,CAACC,MAAM,CAC3EC,4BAAa,eACb7C,cAAM,CAACpC,GAAG,cAACmC,IAAI,EAAE,EAAE+C,gCAAiB,CAAC,CACtC;AAED;;;;;;;;;;;AAWO,MAAMC,qBAAqB,GAChCnE,OAA6B,IAE7B+D,aAAK,CAACC,MAAM,CAACC,4BAAa,EAAE7C,cAAM,CAACpC,GAAG,CAACmC,IAAI,CAACnB,OAAO,CAAC,EAAEkE,gCAAiB,CAAC,CAAC;AAAAJ,OAAA,CAAAK,qBAAA,GAAAA,qBAAA","ignoreList":[]}
|
|
@@ -42,21 +42,15 @@ var _effect = require("effect");
|
|
|
42
42
|
* jitter draws from `Random.next`, a default service on the same footing as the
|
|
43
43
|
* clock rather than a host `Math.random`. No `node:*`, no wall-clock reading, no
|
|
44
44
|
* ungoverned RNG.
|
|
45
|
-
*
|
|
46
|
-
* Effect v3 caveat: the `Schedule` API below is the THREE-type-parameter
|
|
47
|
-
* `Schedule<Out, In, R>` that `effect@3` exports, with `Schedule.intersect`. The
|
|
48
|
-
* currently-published docs show a newer four-type-parameter `Schedule` without
|
|
49
|
-
* `intersect` — do not copy them; this file is written against the installed
|
|
50
|
-
* `effect@3` type definitions.
|
|
51
45
|
*/
|
|
52
46
|
|
|
53
47
|
/**
|
|
54
48
|
* The default conflict backoff: exponential from 20ms, jittered, capped at five
|
|
55
49
|
* retries.
|
|
56
50
|
*
|
|
57
|
-
* `Schedule.
|
|
58
|
-
* `recurs(5)` arm is what bounds the attempts and the
|
|
59
|
-
* spaces them. Jitter matters more here than in a typical backoff: contending
|
|
51
|
+
* `Schedule.max` continues only while BOTH schedules continue, waiting the longer
|
|
52
|
+
* of their two delays, so the `recurs(5)` arm is what bounds the attempts and the
|
|
53
|
+
* exponential arm is what spaces them. Jitter matters more here than in a typical backoff: contending
|
|
60
54
|
* deciders conflict precisely because they read the same boundary at the same
|
|
61
55
|
* time, so an unjittered backoff would re-synchronise them into the same conflict
|
|
62
56
|
* on every round. The figures are the conventional starting point (Emmett,
|
|
@@ -64,7 +58,7 @@ var _effect = require("effect");
|
|
|
64
58
|
* command with a tighter latency budget, or one contending harder, should pass its
|
|
65
59
|
* own schedule.
|
|
66
60
|
*/
|
|
67
|
-
const conflictBackoff = /*#__PURE__*/_effect.Schedule.
|
|
61
|
+
const conflictBackoff = /*#__PURE__*/_effect.Schedule.max([/*#__PURE__*/_effect.Schedule.jittered(/*#__PURE__*/_effect.Schedule.exponential('20 millis', 2)), /*#__PURE__*/_effect.Schedule.recurs(5)]);
|
|
68
62
|
/**
|
|
69
63
|
* Retry `command` while — and only while — it fails `AppendConditionFailed`.
|
|
70
64
|
*
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"retryOnConflict.js","names":["_effect","require","conflictBackoff","Schedule","
|
|
1
|
+
{"version":3,"file":"retryOnConflict.js","names":["_effect","require","conflictBackoff","Schedule","max","jittered","exponential","recurs","retryOnConflict","command","schedule","Effect","retry","while","Predicate","isTagged","exports"],"sources":["../../src/retryOnConflict.ts"],"sourcesContent":[null],"mappings":";;;;;;AAsCA,IAAAA,OAAA,GAAAC,OAAA;AAtCA;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;AAyCA;;;;;;;;;;;;;;AAcA,MAAMC,eAAe,gBAAGC,gBAAQ,CAACC,GAAG,CAAC,cACnCD,gBAAQ,CAACE,QAAQ,cAACF,gBAAQ,CAACG,WAAW,CAAC,WAAW,EAAE,CAAC,CAAC,CAAC,eACvDH,gBAAQ,CAACI,MAAM,CAAC,CAAC,CAAC,CACnB,CAAC;AAEF;;;;;;;;;;;;;;;;;;;;;;AAsBO,MAAMC,eAAe,GAAGA,CAC7BC,OAAuD,EACvDC,QAAA,GAKIR,eAAe,KAEnBS,cAAM,CAACC,KAAK,CAACH,OAAO,EAAE;EACpBC,QAAQ;EACRG,KAAK,EAAEC,iBAAS,CAACC,QAAQ,CAAC,uBAAuB;CAClD,CAAC;AAAAC,OAAA,CAAAR,eAAA,GAAAA,eAAA","ignoreList":[]}
|
package/dist/cjs/testing.js
CHANGED
|
@@ -27,10 +27,10 @@ var _effect = require("effect");
|
|
|
27
27
|
*
|
|
28
28
|
* Ordering in the log is by `position` alone, so an event's `occurredAt` is
|
|
29
29
|
* informational; pinning it to the epoch keeps serialised bytes and comparisons
|
|
30
|
-
* stable across runs. Built via `DateTime.
|
|
30
|
+
* stable across runs. Built via `DateTime.makeUnsafe(0)` (the value is a
|
|
31
31
|
* compile-time constant, not read from the host clock).
|
|
32
32
|
*/
|
|
33
|
-
const EPOCH = exports.EPOCH = /*#__PURE__*/_effect.DateTime.
|
|
33
|
+
const EPOCH = exports.EPOCH = /*#__PURE__*/_effect.DateTime.makeUnsafe(0);
|
|
34
34
|
/**
|
|
35
35
|
* Build a fresh, deterministic uuid generator: a zero-based counter producing
|
|
36
36
|
* RFC-4122 v4-shaped ids `00000000-0000-4000-8000-<counter as 12 hex digits>`,
|
package/dist/cjs/testing.js.map
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"testing.js","names":["_effect","require","EPOCH","exports","DateTime","
|
|
1
|
+
{"version":3,"file":"testing.js","names":["_effect","require","EPOCH","exports","DateTime","makeUnsafe","makeSequentialUuid","counter","suffix","toString","padStart"],"sources":["../../src/testing.ts"],"sourcesContent":[null],"mappings":";;;;;;AAgBA,IAAAA,OAAA,GAAAC,OAAA;AAhBA;;;;;;;;;;;;;;;;;AAkBA;;;;;;;;AAQO,MAAMC,KAAK,GAAAC,OAAA,CAAAD,KAAA,gBAAGE,gBAAQ,CAACC,UAAU,CAAC,CAAC,CAAC;AAE3C;;;;;;;;;;;AAWO,MAAMC,kBAAkB,GAAGA,CAAA,KAAqB;EACrD,IAAIC,OAAO,GAAG,CAAC;EACf,OAAO,MAAK;IACV,MAAMC,MAAM,GAAGD,OAAO,CAACE,QAAQ,CAAC,EAAE,CAAC,CAACC,QAAQ,CAAC,EAAE,EAAE,GAAG,CAAC;IACrDH,OAAO,IAAI,CAAC;IACZ,OAAO,2BAA2BC,MAAM,EAAE;EAC5C,CAAC;AACH,CAAC;AAAAL,OAAA,CAAAG,kBAAA,GAAAA,kBAAA","ignoreList":[]}
|
|
@@ -9,15 +9,13 @@
|
|
|
9
9
|
*/
|
|
10
10
|
import { Schema } from 'effect';
|
|
11
11
|
export declare const AppendCondition: Schema.Struct<{
|
|
12
|
-
failIfEventsMatch: Schema.Struct<{
|
|
13
|
-
items: Schema
|
|
14
|
-
types: Schema
|
|
15
|
-
tags: Schema
|
|
12
|
+
readonly failIfEventsMatch: Schema.Struct<{
|
|
13
|
+
readonly items: Schema.$Array<Schema.Struct<{
|
|
14
|
+
readonly types: Schema.$Array<Schema.brand<Schema.String, "EventType">>;
|
|
15
|
+
readonly tags: Schema.$Array<Schema.brand<Schema.String, "Tag">>;
|
|
16
16
|
}>>;
|
|
17
17
|
}>;
|
|
18
|
-
after: Schema.
|
|
19
|
-
exact: true;
|
|
20
|
-
}>;
|
|
18
|
+
readonly after: Schema.optionalKey<Schema.brand<Schema.decodeTo<Schema.BigInt, Schema.String, never, never>, "Position">>;
|
|
21
19
|
}>;
|
|
22
20
|
export type AppendCondition = typeof AppendCondition.Type;
|
|
23
21
|
//# sourceMappingURL=AppendCondition.d.ts.map
|