@kairos-es/codec 1.0.0-alpha.3 → 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 +27 -2
- package/dist/cjs/MetadataSource.js +10 -0
- package/dist/cjs/MetadataSource.js.map +1 -0
- package/dist/cjs/Serializer.js +3 -3
- package/dist/cjs/Serializer.js.map +1 -1
- package/dist/cjs/Uuid.js +6 -3
- package/dist/cjs/Uuid.js.map +1 -1
- package/dist/cjs/decider.js +1 -1
- package/dist/cjs/decisionModel.js +1 -1
- package/dist/cjs/decisionModel.js.map +1 -1
- package/dist/cjs/decode.js +5 -5
- package/dist/cjs/decode.js.map +1 -1
- package/dist/cjs/deserialiseThenDecode.js +1 -1
- package/dist/cjs/deserialiseThenDecode.js.map +1 -1
- package/dist/cjs/errors.js +6 -4
- package/dist/cjs/errors.js.map +1 -1
- package/dist/cjs/event.js.map +1 -1
- package/dist/cjs/index.js +7 -0
- package/dist/cjs/index.js.map +1 -1
- package/dist/cjs/precondition.js +2 -2
- package/dist/cjs/precondition.js.map +1 -1
- package/dist/cjs/projection.js +9 -10
- package/dist/cjs/projection.js.map +1 -1
- package/dist/cjs/readLedger.js +20 -5
- package/dist/cjs/readLedger.js.map +1 -1
- package/dist/cjs/registry.js.map +1 -1
- package/dist/cjs/toEvent.js +58 -4
- package/dist/cjs/toEvent.js.map +1 -1
- package/dist/dts-cjs/MetadataSource.d.ts +8 -0
- package/dist/dts-cjs/MetadataSource.d.ts.map +1 -0
- package/dist/{dts → dts-cjs}/Serializer.d.ts +3 -3
- package/dist/{dts → dts-cjs}/Serializer.d.ts.map +1 -1
- package/dist/{dts → dts-cjs}/Uuid.d.ts +6 -3
- package/dist/{dts → dts-cjs}/Uuid.d.ts.map +1 -1
- package/dist/{dts → dts-cjs}/decider.d.ts +7 -7
- package/dist/{dts → dts-cjs}/decider.d.ts.map +1 -1
- package/dist/{dts → dts-cjs}/decision.d.ts +2 -2
- package/dist/{dts → dts-cjs}/decode.d.ts +3 -3
- package/dist/{dts → dts-cjs}/decode.d.ts.map +1 -1
- package/dist/{dts → dts-cjs}/deserialiseThenDecode.d.ts +3 -3
- package/dist/{dts → dts-cjs}/deserialiseThenDecode.d.ts.map +1 -1
- package/dist/{dts → dts-cjs}/errors.d.ts +4 -3
- package/dist/dts-cjs/errors.d.ts.map +1 -0
- package/dist/{dts → dts-cjs}/event.d.ts +18 -8
- package/dist/dts-cjs/event.d.ts.map +1 -0
- package/dist/{dts → dts-cjs}/index.d.ts +4 -2
- package/dist/dts-cjs/index.d.ts.map +1 -0
- package/dist/dts-cjs/package.json +3 -0
- package/dist/{dts → dts-cjs}/precondition.d.ts +2 -2
- package/dist/{dts → dts-cjs}/projection.d.ts +2 -2
- package/dist/dts-cjs/projection.d.ts.map +1 -0
- package/dist/{dts → dts-cjs}/readLedger.d.ts +4 -4
- package/dist/{dts → dts-cjs}/readLedger.d.ts.map +1 -1
- package/dist/{dts → dts-cjs}/toEvent.d.ts +15 -4
- package/dist/dts-cjs/toEvent.d.ts.map +1 -0
- package/dist/dts-esm/MetadataSource.d.ts +8 -0
- package/dist/dts-esm/MetadataSource.d.ts.map +1 -0
- package/dist/dts-esm/Serializer.d.ts +27 -0
- package/dist/dts-esm/Serializer.d.ts.map +1 -0
- package/dist/dts-esm/Uuid.d.ts +22 -0
- package/dist/dts-esm/Uuid.d.ts.map +1 -0
- package/dist/dts-esm/decider.d.ts +206 -0
- package/dist/dts-esm/decider.d.ts.map +1 -0
- package/dist/dts-esm/decision.d.ts +161 -0
- package/dist/dts-esm/decision.d.ts.map +1 -0
- package/dist/dts-esm/decisionModel.d.ts +149 -0
- package/dist/dts-esm/decisionModel.d.ts.map +1 -0
- package/dist/dts-esm/decode.d.ts +92 -0
- package/dist/dts-esm/decode.d.ts.map +1 -0
- package/dist/dts-esm/deserialiseThenDecode.d.ts +62 -0
- package/dist/dts-esm/deserialiseThenDecode.d.ts.map +1 -0
- package/dist/dts-esm/errors.d.ts +80 -0
- package/dist/dts-esm/errors.d.ts.map +1 -0
- package/dist/dts-esm/event.d.ts +81 -0
- package/dist/dts-esm/event.d.ts.map +1 -0
- package/dist/dts-esm/index.d.ts +134 -0
- package/dist/dts-esm/index.d.ts.map +1 -0
- package/dist/dts-esm/package.json +3 -0
- package/dist/dts-esm/precondition.d.ts +244 -0
- package/dist/dts-esm/precondition.d.ts.map +1 -0
- package/dist/dts-esm/projection.d.ts +56 -0
- package/dist/dts-esm/projection.d.ts.map +1 -0
- package/dist/dts-esm/readLedger.d.ts +263 -0
- package/dist/dts-esm/readLedger.d.ts.map +1 -0
- package/dist/dts-esm/registry.d.ts +46 -0
- package/dist/dts-esm/registry.d.ts.map +1 -0
- package/dist/dts-esm/toEvent.d.ts +45 -0
- package/dist/dts-esm/toEvent.d.ts.map +1 -0
- package/dist/esm/MetadataSource.js +3 -0
- package/dist/esm/MetadataSource.js.map +1 -0
- package/dist/esm/Serializer.js +3 -3
- package/dist/esm/Serializer.js.map +1 -1
- package/dist/esm/Uuid.js +6 -3
- package/dist/esm/Uuid.js.map +1 -1
- package/dist/esm/decider.js +1 -1
- package/dist/esm/decisionModel.js +1 -1
- package/dist/esm/decisionModel.js.map +1 -1
- package/dist/esm/decode.js +5 -5
- package/dist/esm/decode.js.map +1 -1
- package/dist/esm/deserialiseThenDecode.js +1 -1
- package/dist/esm/deserialiseThenDecode.js.map +1 -1
- package/dist/esm/errors.js +6 -4
- package/dist/esm/errors.js.map +1 -1
- package/dist/esm/event.js.map +1 -1
- package/dist/esm/index.js +4 -2
- package/dist/esm/index.js.map +1 -1
- package/dist/esm/precondition.js +2 -2
- package/dist/esm/precondition.js.map +1 -1
- package/dist/esm/projection.js +9 -10
- package/dist/esm/projection.js.map +1 -1
- package/dist/esm/readLedger.js +21 -6
- package/dist/esm/readLedger.js.map +1 -1
- package/dist/esm/registry.js.map +1 -1
- package/dist/esm/toEvent.js +58 -5
- package/dist/esm/toEvent.js.map +1 -1
- package/package.json +12 -7
- package/src/MetadataSource.ts +43 -0
- package/src/Serializer.ts +4 -4
- package/src/Uuid.ts +7 -4
- package/src/decider.ts +9 -9
- package/src/decision.ts +1 -1
- package/src/decisionModel.ts +1 -1
- package/src/decode.ts +12 -18
- package/src/deserialiseThenDecode.ts +5 -5
- package/src/errors.ts +6 -4
- package/src/event.ts +19 -9
- package/src/index.ts +4 -2
- package/src/precondition.ts +3 -3
- package/src/projection.ts +15 -20
- package/src/readLedger.ts +28 -12
- package/src/registry.ts +1 -1
- package/src/toEvent.ts +54 -7
- package/dist/dts/errors.d.ts.map +0 -1
- package/dist/dts/event.d.ts.map +0 -1
- package/dist/dts/index.d.ts.map +0 -1
- package/dist/dts/projection.d.ts.map +0 -1
- package/dist/dts/toEvent.d.ts.map +0 -1
- /package/dist/{dts → dts-cjs}/decision.d.ts.map +0 -0
- /package/dist/{dts → dts-cjs}/decisionModel.d.ts +0 -0
- /package/dist/{dts → dts-cjs}/decisionModel.d.ts.map +0 -0
- /package/dist/{dts → dts-cjs}/precondition.d.ts.map +0 -0
- /package/dist/{dts → dts-cjs}/registry.d.ts +0 -0
- /package/dist/{dts → dts-cjs}/registry.d.ts.map +0 -0
package/README.md
CHANGED
|
@@ -8,7 +8,7 @@ Schema-first codec with an encryption seam for kairos-es (ADR-0004).
|
|
|
8
8
|
single shared Effect instance (per [ADR-0003](../../docs/adr)):
|
|
9
9
|
|
|
10
10
|
```sh
|
|
11
|
-
pnpm add @kairos-es/codec@alpha @kairos-es/core@alpha effect@^
|
|
11
|
+
pnpm add @kairos-es/codec@alpha @kairos-es/core@alpha effect@^4.0.5
|
|
12
12
|
```
|
|
13
13
|
|
|
14
14
|
The typed-payload to opaque-bytes seam: `event(type, fields, tagsFor)` defines a
|
|
@@ -18,7 +18,32 @@ decision model or a read model folds through; `modelAtHead(slices)` reads, decod
|
|
|
18
18
|
through each def's `Schema`, and folds purely, returning `{ state, head }`;
|
|
19
19
|
`buildDecisionModel(slices)` is that same read plus the `AppendCondition` a write
|
|
20
20
|
needs; and `toEvent` produces a wire event (encode, serialise, tags derived, clock
|
|
21
|
-
and uuid from services).
|
|
21
|
+
and uuid from services, and a metadata bag).
|
|
22
|
+
|
|
23
|
+
Every event carries `metadata`, a flat bag of strings (core's `Metadata`) of context about the
|
|
24
|
+
recording — a `traceparent`, a correlation id — never anything the business asserts.
|
|
25
|
+
Pass it per call as `toEvent(def, payload, { metadata })`, or provide it once at the
|
|
26
|
+
edge of a request with `Effect.provideService(MetadataSource, bag)`; a per-call bag
|
|
27
|
+
replaces the ambient one, and with neither the event carries `{}`. A bag core's
|
|
28
|
+
`Metadata` schema refuses, such as one holding a value that is not a string, fails
|
|
29
|
+
`toEvent` with a `CodecError` (`reason: 'metadata'`). Metadata is cleartext, never
|
|
30
|
+
queryable and never seen by `tagsFor` or by a builder fold (`.on(def, fold)`). A
|
|
31
|
+
read model's `apply` sees it on each decoded event as `decoded.sequenced.event.metadata`.
|
|
32
|
+
|
|
33
|
+
To read metadata in a FOLD, leave the builder and write the `SliceProjection` by
|
|
34
|
+
hand: an `initialState`, a `query`, a `schemas` map from each event type it folds to
|
|
35
|
+
that def's schema, and an erased `evolve(state, decoded)` that reads
|
|
36
|
+
`decoded.sequenced.event.metadata`. It goes everywhere a built slice goes. Three
|
|
37
|
+
things the builder does for you, a hand-written slice must do itself:
|
|
38
|
+
|
|
39
|
+
- **Keep the def's requirement in the schema cast** —
|
|
40
|
+
`def.schema as unknown as Schema.Decoder<unknown, R>` with the def's own
|
|
41
|
+
`R`. Cast a def that needs a service to `never` instead, and the slice compiles
|
|
42
|
+
without that service and dies at run time.
|
|
43
|
+
- **Check `decoded.sequenced.event.type` in `evolve`.** It is handed every event its
|
|
44
|
+
query matches, decoded through the schemas of every slice in the record, so an
|
|
45
|
+
event your `schemas` never named can still arrive, decoded by a neighbour's.
|
|
46
|
+
- **Cast `state` back to its own type**, since `evolve` is erased.
|
|
22
47
|
|
|
23
48
|
`modelAtHead` is the read side's third materialisation KIND — checkpoint-free and
|
|
24
49
|
read-time, no table, no runner, nothing maintained — and `head` is its consistency
|
|
@@ -0,0 +1,10 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
|
|
3
|
+
Object.defineProperty(exports, "__esModule", {
|
|
4
|
+
value: true
|
|
5
|
+
});
|
|
6
|
+
exports.MetadataSource = void 0;
|
|
7
|
+
var _effect = require("effect");
|
|
8
|
+
class MetadataSource extends /*#__PURE__*/_effect.Context.Service()('@kairos-es/codec/MetadataSource') {}
|
|
9
|
+
exports.MetadataSource = MetadataSource;
|
|
10
|
+
//# sourceMappingURL=MetadataSource.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"MetadataSource.js","names":["_effect","require","MetadataSource","Context","Service","exports"],"sources":["../../src/MetadataSource.ts"],"sourcesContent":[null],"mappings":";;;;;;AAsCA,IAAAA,OAAA,GAAAC,OAAA;AAEM,MAAOC,cAAe,sBAAQC,eAAO,CAACC,OAAO,EAA4B,CAC7E,iCAAiC,CAClC;AAAAC,OAAA,CAAAH,cAAA,GAAAA,cAAA","ignoreList":[]}
|
package/dist/cjs/Serializer.js
CHANGED
|
@@ -7,8 +7,8 @@ exports.SerializerDefault = exports.Serializer = void 0;
|
|
|
7
7
|
var _effect = require("effect");
|
|
8
8
|
/**
|
|
9
9
|
* The pluggable serialiser: the `Uint8Array` <-> value boundary applied
|
|
10
|
-
* *outside* `Schema`. Encode is `Schema.
|
|
11
|
-
* `deserialise` then `Schema.
|
|
10
|
+
* *outside* `Schema`. Encode is `Schema.encodeEffect` then `serialise`; decode is
|
|
11
|
+
* `deserialise` then `Schema.decodeUnknownEffect`. Both codec paths read the same
|
|
12
12
|
* `Serializer` from context, so encode and decode cannot mismatch; swapping
|
|
13
13
|
* JSON for msgpack is a different layer with no schema or call-site changes.
|
|
14
14
|
*
|
|
@@ -18,7 +18,7 @@ var _effect = require("effect");
|
|
|
18
18
|
* a trivial `Layer.succeed`.
|
|
19
19
|
*/
|
|
20
20
|
|
|
21
|
-
class Serializer extends /*#__PURE__*/_effect.Context.
|
|
21
|
+
class Serializer extends /*#__PURE__*/_effect.Context.Service()('@kairos-es/codec/Serializer') {}
|
|
22
22
|
exports.Serializer = Serializer;
|
|
23
23
|
const encoder = /*#__PURE__*/new TextEncoder();
|
|
24
24
|
const decoder = /*#__PURE__*/new TextDecoder();
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"Serializer.js","names":["_effect","require","Serializer","Context","
|
|
1
|
+
{"version":3,"file":"Serializer.js","names":["_effect","require","Serializer","Context","Service","exports","encoder","TextEncoder","decoder","TextDecoder","SerializerDefault","Layer","succeed","serialise","v","encode","JSON","stringify","deserialise","b","parse","decode"],"sources":["../../src/Serializer.ts"],"sourcesContent":[null],"mappings":";;;;;;AAYA,IAAAA,OAAA,GAAAC,OAAA;AAZA;;;;;;;;;;;;;AAcM,MAAOC,UAAW,sBAAQC,eAAO,CAACC,OAAO,EAM5C,CAAC,6BAA6B,CAAC;AAAAC,OAAA,CAAAH,UAAA,GAAAA,UAAA;AAElC,MAAMI,OAAO,gBAAG,IAAIC,WAAW,EAAE;AACjC,MAAMC,OAAO,gBAAG,IAAIC,WAAW,EAAE;AAEjC;;;;;AAKO,MAAMC,iBAAiB,GAAAL,OAAA,CAAAK,iBAAA,gBAA4BC,aAAK,CAACC,OAAO,CACrEV,UAAU,EACV;EACEW,SAAS,EAAGC,CAAC,IAAKR,OAAO,CAACS,MAAM,CAACC,IAAI,CAACC,SAAS,CAACH,CAAC,CAAC,CAAC;EACnDI,WAAW,EAAGC,CAAC,IAAKH,IAAI,CAACI,KAAK,CAACZ,OAAO,CAACa,MAAM,CAACF,CAAC,CAAC;CACjD,CACF","ignoreList":[]}
|
package/dist/cjs/Uuid.js
CHANGED
|
@@ -18,7 +18,7 @@ var _effect = require("effect");
|
|
|
18
18
|
* layer gets a repeatable sequence.
|
|
19
19
|
*/
|
|
20
20
|
|
|
21
|
-
class Uuid extends /*#__PURE__*/_effect.Context.
|
|
21
|
+
class Uuid extends /*#__PURE__*/_effect.Context.Service()('@kairos-es/codec/Uuid') {}
|
|
22
22
|
/** Live uuid generation via WebCrypto (no `node:crypto`). */
|
|
23
23
|
exports.Uuid = Uuid;
|
|
24
24
|
const UuidLive = exports.UuidLive = /*#__PURE__*/_effect.Layer.succeed(Uuid, {
|
|
@@ -27,9 +27,12 @@ const UuidLive = exports.UuidLive = /*#__PURE__*/_effect.Layer.succeed(Uuid, {
|
|
|
27
27
|
/**
|
|
28
28
|
* A deterministic uuid layer for suites, wrapping core's shared
|
|
29
29
|
* `makeSequentialUuid` (the single source of truth for the counter scheme).
|
|
30
|
-
* Each layer
|
|
30
|
+
* Each BUILD of the layer makes a fresh generator, so it owns its own counter and
|
|
31
31
|
* yields a stable v4-shaped sequence `00000000-0000-4000-8000-<12 hex>` starting
|
|
32
|
-
* at `...000000000000`.
|
|
32
|
+
* at `...000000000000`. A build is not one per `Effect.provide`: Effect memoises
|
|
33
|
+
* a layer across the provisions that share a memo map, so a nested second
|
|
34
|
+
* provision of this layer continues the counter rather than restarting it, and
|
|
35
|
+
* `Layer.fresh` is the way to ask for a restart. Generation is wrapped in `Effect.sync` because the
|
|
33
36
|
* generator advances its counter (a side effect on each call).
|
|
34
37
|
*/
|
|
35
38
|
const UuidTest = exports.UuidTest = /*#__PURE__*/_effect.Layer.sync(Uuid, () => {
|
package/dist/cjs/Uuid.js.map
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"Uuid.js","names":["_testing","require","_effect","Uuid","Context","
|
|
1
|
+
{"version":3,"file":"Uuid.js","names":["_testing","require","_effect","Uuid","Context","Service","exports","UuidLive","Layer","succeed","generate","Effect","sync","globalThis","crypto","randomUUID","UuidTest","next","makeSequentialUuid"],"sources":["../../src/Uuid.ts"],"sourcesContent":[null],"mappings":";;;;;;AAWA,IAAAA,QAAA,GAAAC,OAAA;AACA,IAAAC,OAAA,GAAAD,OAAA;AAZA;;;;;;;;;;;;AAcM,MAAOE,IAAK,sBAAQC,eAAO,CAACC,OAAO,EAGtC,CAAC,uBAAuB,CAAC;AAE5B;AAAAC,OAAA,CAAAH,IAAA,GAAAA,IAAA;AACO,MAAMI,QAAQ,GAAAD,OAAA,CAAAC,QAAA,gBAAsBC,aAAK,CAACC,OAAO,CAACN,IAAI,EAAE;EAC7DO,QAAQ,eAAEC,cAAM,CAACC,IAAI,CAAC,MAAMC,UAAU,CAACC,MAAM,CAACC,UAAU,EAAE;CAC3D,CAAC;AAEF;;;;;;;;;;;AAWO,MAAMC,QAAQ,GAAAV,OAAA,CAAAU,QAAA,gBAAsBR,aAAK,CAACI,IAAI,CAACT,IAAI,EAAE,MAAK;EAC/D,MAAMc,IAAI,GAAG,IAAAC,2BAAkB,GAAE;EACjC,OAAO;IAAER,QAAQ,EAAEC,cAAM,CAACC,IAAI,CAACK,IAAI;EAAC,CAAE;AACxC,CAAC,CAAC","ignoreList":[]}
|
package/dist/cjs/decider.js
CHANGED
|
@@ -50,7 +50,7 @@ var _decisionModel = require("./decisionModel.js");
|
|
|
50
50
|
* append condition the read produced. That IS the optimistic-concurrency
|
|
51
51
|
* contract, in production and in a scenario alike — which is also why the
|
|
52
52
|
* Given/When/Then surface built on it exercises the real fold and the real store
|
|
53
|
-
* rather than a mock. It is a free function rather than a `Context.
|
|
53
|
+
* rather than a mock. It is a free function rather than a `Context.Service`,
|
|
54
54
|
* so it is still not the "production command-runner service method" a retrying
|
|
55
55
|
* `Layer` would need (ADR-0008): the correct retry remains
|
|
56
56
|
* `retryOnConflict(runDecider(...))`, wrapping the whole cycle so a fresh read
|
|
@@ -124,7 +124,7 @@ const modelAtHead = projections => _effect.Effect.gen(function* () {
|
|
|
124
124
|
head
|
|
125
125
|
} = yield* store.read(composite.query);
|
|
126
126
|
const decoded = decode(events);
|
|
127
|
-
const state = yield* _effect.Stream.runFold(decoded, composite.initialState, (acc, event) => composite.evolve(acc, event));
|
|
127
|
+
const state = yield* _effect.Stream.runFold(decoded, () => composite.initialState, (acc, event) => composite.evolve(acc, event));
|
|
128
128
|
// LAZY: only once the fold has run to completion. A read that failed
|
|
129
129
|
// part-way folded a PREFIX, and a head recorded for it is a claim it did not
|
|
130
130
|
// earn — so the line below is unreachable on that path, deliberately.
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"decisionModel.js","names":["_core","require","_effect","_decode","_readLedger","modelAtHead","projections","Effect","gen","store","DcbEventStore","decode","decodeSlices","composite","composeProjections","assertServableAddition","closeHop","recordQuery","query","events","head","read","decoded","state","Stream","runFold","initialState","acc","event","evolve","exports","buildDecisionModel","ambient","ambientLayeredCondition","Option","isSome","appendCondition","value","failIfEventsMatch","after"],"sources":["../../src/decisionModel.ts"],"sourcesContent":[null],"mappings":";;;;;;AAiCA,IAAAA,KAAA,GAAAC,OAAA;AAQA,IAAAC,OAAA,GAAAD,OAAA;AACA,IAAAE,OAAA,GAAAF,OAAA;AAGA,IAAAG,WAAA,GAAAH,OAAA;AA7CA;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;AAyDA;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;AAyDO,MAAMI,WAAW,GACtBC,WAAc,IAMdC,cAAM,CAACC,GAAG,CAAC,aAAS;EAClB,MAAMC,KAAK,GAAG,OAAOC,mBAAa;EAElC;EACA;EACA;EACA,MAAMC,MAAM,GAAG,IAAAC,oBAAY,EAACN,WAAW,CAAC;EAExC;EACA,MAAMO,SAAS,GAAG,IAAAC,wBAAkB,EAClCR,WAA4C,CAC7C;EAED;EACA;EACA;EACA;EACA;EACA;EACA;EACA,OAAO,IAAAS,kCAAsB,EAACT,WAA4C,CAAC;EAE3E;EACA;EACA;EACA,MAAMU,QAAQ,GAAG,OAAO,IAAAC,uBAAW,EAACJ,SAAS,CAACK,KAAK,CAAC;EAEpD,MAAM;IAAEC,MAAM;IAAEC;EAAI,CAAE,GAAG,OAAOX,KAAK,CAACY,IAAI,CAACR,SAAS,CAACK,KAAK,CAAC;EAE3D,MAAMI,OAAO,GAAGX,MAAM,CAACQ,MAAM,CAAC;EAE9B,MAAMI,KAAK,GAAI,OAAOC,cAAM,CAACC,OAAO,CAClCH,OAAO,
|
|
1
|
+
{"version":3,"file":"decisionModel.js","names":["_core","require","_effect","_decode","_readLedger","modelAtHead","projections","Effect","gen","store","DcbEventStore","decode","decodeSlices","composite","composeProjections","assertServableAddition","closeHop","recordQuery","query","events","head","read","decoded","state","Stream","runFold","initialState","acc","event","evolve","exports","buildDecisionModel","ambient","ambientLayeredCondition","Option","isSome","appendCondition","value","failIfEventsMatch","after"],"sources":["../../src/decisionModel.ts"],"sourcesContent":[null],"mappings":";;;;;;AAiCA,IAAAA,KAAA,GAAAC,OAAA;AAQA,IAAAC,OAAA,GAAAD,OAAA;AACA,IAAAE,OAAA,GAAAF,OAAA;AAGA,IAAAG,WAAA,GAAAH,OAAA;AA7CA;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;AAyDA;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;AAyDO,MAAMI,WAAW,GACtBC,WAAc,IAMdC,cAAM,CAACC,GAAG,CAAC,aAAS;EAClB,MAAMC,KAAK,GAAG,OAAOC,mBAAa;EAElC;EACA;EACA;EACA,MAAMC,MAAM,GAAG,IAAAC,oBAAY,EAACN,WAAW,CAAC;EAExC;EACA,MAAMO,SAAS,GAAG,IAAAC,wBAAkB,EAClCR,WAA4C,CAC7C;EAED;EACA;EACA;EACA;EACA;EACA;EACA;EACA,OAAO,IAAAS,kCAAsB,EAACT,WAA4C,CAAC;EAE3E;EACA;EACA;EACA,MAAMU,QAAQ,GAAG,OAAO,IAAAC,uBAAW,EAACJ,SAAS,CAACK,KAAK,CAAC;EAEpD,MAAM;IAAEC,MAAM;IAAEC;EAAI,CAAE,GAAG,OAAOX,KAAK,CAACY,IAAI,CAACR,SAAS,CAACK,KAAK,CAAC;EAE3D,MAAMI,OAAO,GAAGX,MAAM,CAACQ,MAAM,CAAC;EAE9B,MAAMI,KAAK,GAAI,OAAOC,cAAM,CAACC,OAAO,CAClCH,OAAO,EACP,MAAMT,SAAS,CAACa,YAAY,EAC5B,CAACC,GAAG,EAAEC,KAAK,KAAKf,SAAS,CAACgB,MAAM,CAACF,GAAG,EAAEC,KAAK,CAAC,CACvB;EAEvB;EACA;EACA;EACA,OAAOZ,QAAQ,CAACI,IAAI,CAAC;EAErB,OAAO;IAAEG,KAAK;IAAEH;EAAI,CAAE;AACxB,CAAC,CAAC;AAEJ;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;AAAAU,OAAA,CAAAzB,WAAA,GAAAA,WAAA;AA0CO,MAAM0B,kBAAkB,GAC7BzB,WAAc,IASdC,cAAM,CAACC,GAAG,CAAC,aAAS;EAClB,MAAM;IAAEe,KAAK;IAAEH;EAAI,CAAE,GAAG,OAAOf,WAAW,CAACC,WAAW,CAAC;EAEvD;EACA;EACA;EACA;EACA;EACA;EACA;EACA;EACA;EACA,MAAM0B,OAAO,GAAG,OAAOC,mCAAuB;EAC9C,IAAIC,cAAM,CAACC,MAAM,CAACH,OAAO,CAAC,EAAE;IAC1B,OAAO;MAAET,KAAK;MAAEa,eAAe,EAAEJ,OAAO,CAACK;IAAK,CAAE;EAClD;EAEA;EACA,OAAO;IACLd,KAAK;IACLa,eAAe,EAAE;MACfE,iBAAiB,EAAE,IAAAxB,wBAAkB,EACnCR,WAA4C,CAC7C,CAACY,KAAK;MACPqB,KAAK,EAAEnB;;GAEV;AACH,CAAC,CAAC;AAAAU,OAAA,CAAAC,kBAAA,GAAAA,kBAAA","ignoreList":[]}
|
package/dist/cjs/decode.js
CHANGED
|
@@ -35,9 +35,9 @@ var _Serializer = require("./Serializer.js");
|
|
|
35
35
|
* last, an ordering the record does not express and its author never chose.
|
|
36
36
|
* Every event of that type is then decoded against the wrong def for one of the
|
|
37
37
|
* slices, and where the two shapes overlap that failure is SILENT rather than a
|
|
38
|
-
* `CodecError`: `Schema.
|
|
39
|
-
* (`effect@
|
|
40
|
-
* `'error'`
|
|
38
|
+
* `CodecError`: `Schema.decodeUnknownEffect` defaults `onExcessProperty` to
|
|
39
|
+
* `'ignore'` (`effect@4`'s `SchemaAST.ts` runs its excess-key loop only under
|
|
40
|
+
* `'error'`), so a field the other def declared is dropped, not
|
|
41
41
|
* reported, and the fold downstream is handed a payload quietly missing it.
|
|
42
42
|
*
|
|
43
43
|
* **Why a throw, and why here rather than at the read side's wiring gate.**
|
|
@@ -51,8 +51,8 @@ var _Serializer = require("./Serializer.js");
|
|
|
51
51
|
* the write path merges before its first `store.read`, and the read side
|
|
52
52
|
* merges after that gate and before it forks the pipeline — and inside
|
|
53
53
|
* their `Effect.gen`s a throw becomes a DEFECT rather than an escaping exception
|
|
54
|
-
* (`effect@
|
|
55
|
-
* `
|
|
54
|
+
* (`effect@4`'s fibre run loop catches a thrown value and converts it with
|
|
55
|
+
* `exitDie`), which is the classification a mis-wiring already has on both
|
|
56
56
|
* sides of the library.
|
|
57
57
|
*
|
|
58
58
|
* The sentence names BOTH slices. The two halves of this mistake are in
|
package/dist/cjs/decode.js.map
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"decode.js","names":["_effect","require","_deserialiseThenDecode","_errors","_Serializer","mergeSliceSchemas","projections","schemas","Map","contributedBy","key","Object","keys","slice","type","schema","owner","get","undefined","Error","set","decodeEvents","events","Stream","unwrap","Effect","map","Serializer","serializer","pipe","mapEffect","sequenced","event","fail","CodecError","reason","deserialiseThenDecode","data","payload","decodeSlices","slices","exports"],"sources":["../../src/decode.ts"],"sourcesContent":[null],"mappings":";;;;;;AAiDA,IAAAA,OAAA,GAAAC,OAAA;AAKA,IAAAC,sBAAA,GAAAD,OAAA;AACA,IAAAE,OAAA,GAAAF,OAAA;AAEA,IAAAG,WAAA,GAAAH,OAAA;AAEA;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;AA6DA,MAAMI,iBAAiB,GACrBC,WAAc,
|
|
1
|
+
{"version":3,"file":"decode.js","names":["_effect","require","_deserialiseThenDecode","_errors","_Serializer","mergeSliceSchemas","projections","schemas","Map","contributedBy","key","Object","keys","slice","type","schema","owner","get","undefined","Error","set","decodeEvents","events","Stream","unwrap","Effect","map","Serializer","serializer","pipe","mapEffect","sequenced","event","fail","CodecError","reason","deserialiseThenDecode","data","payload","decodeSlices","slices","exports"],"sources":["../../src/decode.ts"],"sourcesContent":[null],"mappings":";;;;;;AAiDA,IAAAA,OAAA,GAAAC,OAAA;AAKA,IAAAC,sBAAA,GAAAD,OAAA;AACA,IAAAE,OAAA,GAAAF,OAAA;AAEA,IAAAG,WAAA,GAAAH,OAAA;AAEA;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;AA6DA,MAAMI,iBAAiB,GACrBC,WAAc,IACoD;EAClE,MAAMC,OAAO,GAAG,IAAIC,GAAG,EAAqD;EAC5E;EACA;EACA;EACA;EACA,MAAMC,aAAa,GAAG,IAAID,GAAG,EAAkB;EAC/C,KAAK,MAAME,GAAG,IAAIC,MAAM,CAACC,IAAI,CAACN,WAAW,CAAC,EAAE;IAC1C,MAAMO,KAAK,GAAGP,WAAW,CAACI,GAAG,CAAC;IAC9B,KAAK,MAAM,CAACI,IAAI,EAAEC,MAAM,CAAC,IAAIF,KAAK,CAACN,OAAO,EAAE;MAC1C,MAAMS,KAAK,GAAGP,aAAa,CAACQ,GAAG,CAACH,IAAI,CAAC;MACrC,IAAIE,KAAK,KAAKE,SAAS,IAAIX,OAAO,CAACU,GAAG,CAACH,IAAI,CAAC,KAAKC,MAAM,EAAE;QACvD,MAAM,IAAII,KAAK,CACb,yBAAyBL,IAAI,gBAAgBE,KAAK,UAAUN,GAAG,KAAK,GAClE,gEAAgE,GAChE,kEAAkE,GAClE,+BAA+B,CAClC;MACH;MACAH,OAAO,CAACa,GAAG,CAACN,IAAI,EAAEC,MAAmD,CAAC;MACtEN,aAAa,CAACW,GAAG,CAACN,IAAI,EAAEJ,GAAG,CAAC;IAC9B;EACF;EACA,OAAOH,OAAO;AAChB,CAAC;AAED;;;;;;;;;;;;;;;;;;;;;;;;;;;;AA4BA,MAAMc,YAAY,GACXd,OAAyD,IAE5De,MAA2C,IAE3CC,cAAM,CAACC,MAAM,CACXC,cAAM,CAACC,GAAG,CAACC,sBAAU,EAAGC,UAAU,IAChCN,MAAM,CAACO,IAAI,CACTN,cAAM,CAACO,SAAS,CAAEC,SAAS,IAAI;EAC7B,MAAMhB,MAAM,GAAGR,OAAO,CAACU,GAAG,CAACc,SAAS,CAACC,KAAK,CAAClB,IAAI,CAAC;EAChD,IAAIC,MAAM,KAAKG,SAAS,EAAE;IACxB,OAAOO,cAAM,CAACQ,IAAI,CAChB,IAAIC,kBAAU,CAAC;MACbC,MAAM,EAAE,6BAA6BJ,SAAS,CAACC,KAAK,CAAClB,IAAI;KAC1D,CAAC,CACH;EACH;EACA,OAAO,IAAAsB,4CAAqB,EAC1BR,UAAU,EACVb,MAAM,EACNgB,SAAS,CAACC,KAAK,CAACK,IAAI,CACrB,CAACR,IAAI,CACJJ,cAAM,CAACC,GAAG,CAAEY,OAAO,KAAoB;IAAEP,SAAS;IAAEO;EAAO,CAAE,CAAC,CAAC,CAChE;AACH,CAAC,CAAC,CACH,CACF,CACF;AAEL;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;AAoCO,MAAMC,YAAY,GACvBC,MAAS,IAOLnB,YAAY,CAAChB,iBAAiB,CAACmC,MAAM,CAAC,CAAC;AAAAC,OAAA,CAAAF,YAAA,GAAAA,YAAA","ignoreList":[]}
|
|
@@ -12,7 +12,7 @@ const deserialiseThenDecode = (serializer, schema, bytes) => _effect.Effect.try(
|
|
|
12
12
|
reason: 'deserialise',
|
|
13
13
|
cause
|
|
14
14
|
})
|
|
15
|
-
}).pipe(_effect.Effect.flatMap(raw => _effect.Schema.
|
|
15
|
+
}).pipe(_effect.Effect.flatMap(raw => _effect.Schema.decodeUnknownEffect(schema)(raw).pipe(_effect.Effect.mapError(cause => new _errors.CodecError({
|
|
16
16
|
reason: 'decode',
|
|
17
17
|
cause
|
|
18
18
|
})))));
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"deserialiseThenDecode.js","names":["_effect","require","_errors","deserialiseThenDecode","serializer","schema","bytes","Effect","try","deserialise","catch","cause","CodecError","reason","pipe","flatMap","raw","Schema","
|
|
1
|
+
{"version":3,"file":"deserialiseThenDecode.js","names":["_effect","require","_errors","deserialiseThenDecode","serializer","schema","bytes","Effect","try","deserialise","catch","cause","CodecError","reason","pipe","flatMap","raw","Schema","decodeUnknownEffect","mapError","exports"],"sources":["../../src/deserialiseThenDecode.ts"],"sourcesContent":[null],"mappings":";;;;;;AAyDA,IAAAA,OAAA,GAAAC,OAAA;AACA,IAAAC,OAAA,GAAAD,OAAA;AAGO,MAAME,qBAAqB,GAAGA,CACnCC,UAAoD,EACpDC,MAAkC,EAClCC,KAAiB,KAEjBC,cAAM,CAACC,GAAG,CAAC;EACTA,GAAG,EAAEA,CAAA,KAAMJ,UAAU,CAACK,WAAW,CAACH,KAAK,CAAC;EACxCI,KAAK,EAAGC,KAAK,IAAK,IAAIC,kBAAU,CAAC;IAAEC,MAAM,EAAE,aAAa;IAAEF;EAAK,CAAE;CAClE,CAAC,CAACG,IAAI,CACLP,cAAM,CAACQ,OAAO,CAAEC,GAAG,IACjBC,cAAM,CAACC,mBAAmB,CAACb,MAAM,CAAC,CAACW,GAAG,CAAC,CAACF,IAAI,CAC1CP,cAAM,CAACY,QAAQ,CAAER,KAAK,IAAK,IAAIC,kBAAU,CAAC;EAAEC,MAAM,EAAE,QAAQ;EAAEF;AAAK,CAAE,CAAC,CAAC,CACxE,CACF,CACF;AAAAS,OAAA,CAAAjB,qBAAA,GAAAA,qBAAA","ignoreList":[]}
|
package/dist/cjs/errors.js
CHANGED
|
@@ -10,7 +10,8 @@ var _effect = require("effect");
|
|
|
10
10
|
* never defects.
|
|
11
11
|
*
|
|
12
12
|
* `CodecError` covers every serialisation/`Schema` failure on the codec path
|
|
13
|
-
* (deserialise threw, `Schema.
|
|
13
|
+
* (deserialise threw, `Schema.decodeUnknownEffect`/`encodeEffect` produced a
|
|
14
|
+
* `SchemaError`, a
|
|
14
15
|
* wrong/absent encryption key surfaced through a `Schema` transform, or a
|
|
15
16
|
* `tagsFor` mapper threw while deriving an event's tags). It carries a
|
|
16
17
|
* human-readable `reason` and the underlying `cause` (exact-optional).
|
|
@@ -45,9 +46,10 @@ class CodecError extends /*#__PURE__*/_effect.Data.TaggedError('CodecError') {
|
|
|
45
46
|
*
|
|
46
47
|
* A GETTER rather than a second field, so `reason` stays the single declaration.
|
|
47
48
|
* It is visible because `Data.TaggedError`'s constructor is
|
|
48
|
-
* `super(args?.message, …)` followed by
|
|
49
|
-
* against `effect@
|
|
50
|
-
* nothing shadows this prototype accessor
|
|
49
|
+
* `super(args?.message, …)` followed by copying the args' own enumerable keys
|
|
50
|
+
* onto the instance (verified against `effect@4`'s `internal/core.ts`): the
|
|
51
|
+
* args above carry no `message`, so nothing shadows this prototype accessor
|
|
52
|
+
* with an own property.
|
|
51
53
|
*/
|
|
52
54
|
get message() {
|
|
53
55
|
return this.reason;
|
package/dist/cjs/errors.js.map
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"errors.js","names":["_effect","require","CodecError","Data","TaggedError","message","reason","exports","UnknownEventType","type"],"sources":["../../src/errors.ts"],"sourcesContent":[null],"mappings":";;;;;;
|
|
1
|
+
{"version":3,"file":"errors.js","names":["_effect","require","CodecError","Data","TaggedError","message","reason","exports","UnknownEventType","type"],"sources":["../../src/errors.ts"],"sourcesContent":[null],"mappings":";;;;;;AAcA,IAAAA,OAAA,GAAAC,OAAA;AAdA;;;;;;;;;;;;;;;AAgBA;AACM,MAAOC,UAAW,sBAAQC,YAAI,CAACC,WAAW,CAAC,YAAY,CAG3D;EACA;;;;;;;;;;;;;;;;;;;;;;;;;;;;;EA6BA,IAAaC,OAAOA,CAAA;IAClB,OAAO,IAAI,CAACC,MAAM;EACpB;;AAGF;AAAAC,OAAA,CAAAL,UAAA,GAAAA,UAAA;AACM,MAAOM,gBAAiB,sBAAQL,YAAI,CAACC,WAAW,CAAC,kBAAkB,CAEvE;EACA;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;EA8BA,IAAaC,OAAOA,CAAA;IAClB,OAAO,eAAe,IAAI,CAACI,IAAI,0BAA0B;EAC3D","ignoreList":[]}
|
package/dist/cjs/event.js.map
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"event.js","names":["_effect","require","event","type","fields","tagsFor","schema","Schema","Struct","exports"],"sources":["../../src/event.ts"],"sourcesContent":[null],"mappings":";;;;;;AA+BA,IAAAA,OAAA,GAAAC,OAAA;
|
|
1
|
+
{"version":3,"file":"event.js","names":["_effect","require","event","type","fields","tagsFor","schema","Schema","Struct","exports"],"sources":["../../src/event.ts"],"sourcesContent":[null],"mappings":";;;;;;AA+BA,IAAAA,OAAA,GAAAC,OAAA;AAyCA;;;;;;;;AAQO,MAAMC,KAAK,GAAGA,CAInBC,IAAU,EACVC,MAAc,EACdC,OAA4C,KAK1C;EACF,MAAMC,MAAM,GAAGC,cAAM,CAACC,MAAM,CAACJ,MAAM,CAAC;EACpC,OAAO;IACL;IACAD,IAAI,EAAEA,IAAwB;IAC9BG,MAAM;IACND;GACD;AACH,CAAC;AAAAI,OAAA,CAAAP,KAAA,GAAAA,KAAA","ignoreList":[]}
|
package/dist/cjs/index.js
CHANGED
|
@@ -15,6 +15,12 @@ Object.defineProperty(exports, "Decision", {
|
|
|
15
15
|
return _decision.Decision;
|
|
16
16
|
}
|
|
17
17
|
});
|
|
18
|
+
Object.defineProperty(exports, "MetadataSource", {
|
|
19
|
+
enumerable: true,
|
|
20
|
+
get: function () {
|
|
21
|
+
return _MetadataSource.MetadataSource;
|
|
22
|
+
}
|
|
23
|
+
});
|
|
18
24
|
Object.defineProperty(exports, "NoReadsRecorded", {
|
|
19
25
|
enumerable: true,
|
|
20
26
|
get: function () {
|
|
@@ -165,6 +171,7 @@ var _decisionModel = require("./decisionModel.js");
|
|
|
165
171
|
var _decode = require("./decode.js");
|
|
166
172
|
var _errors = require("./errors.js");
|
|
167
173
|
var _event = require("./event.js");
|
|
174
|
+
var _MetadataSource = require("./MetadataSource.js");
|
|
168
175
|
var _precondition = require("./precondition.js");
|
|
169
176
|
var _projection = require("./projection.js");
|
|
170
177
|
var _readLedger = require("./readLedger.js");
|
package/dist/cjs/index.js.map
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"index.js","names":["_decider","require","_decision","_decisionModel","_decode","_errors","_event","_precondition","_projection","_readLedger","_registry","_Serializer","_toEvent","_Uuid"],"sources":["../../src/index.ts"],"sourcesContent":[null],"mappings":"
|
|
1
|
+
{"version":3,"file":"index.js","names":["_decider","require","_decision","_decisionModel","_decode","_errors","_event","_MetadataSource","_precondition","_projection","_readLedger","_registry","_Serializer","_toEvent","_Uuid"],"sources":["../../src/index.ts"],"sourcesContent":[null],"mappings":";;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;AAwHA,IAAAA,QAAA,GAAAC,OAAA;AACA,IAAAC,SAAA,GAAAD,OAAA;AAQA,IAAAE,cAAA,GAAAF,OAAA;AAKA,IAAAG,OAAA,GAAAH,OAAA;AACA,IAAAI,OAAA,GAAAJ,OAAA;AACA,IAAAK,MAAA,GAAAL,OAAA;AACA,IAAAM,eAAA,GAAAN,OAAA;AACA,IAAAO,aAAA,GAAAP,OAAA;AAMA,IAAAQ,WAAA,GAAAR,OAAA;AAKA,IAAAS,WAAA,GAAAT,OAAA;AAOA,IAAAU,SAAA,GAAAV,OAAA;AACA,IAAAW,WAAA,GAAAX,OAAA;AACA,IAAAY,QAAA,GAAAZ,OAAA;AACA,IAAAa,KAAA,GAAAb,OAAA","ignoreList":[]}
|
package/dist/cjs/precondition.js
CHANGED
|
@@ -86,7 +86,7 @@ const decideOnly = (decider, command) => _effect.Effect.gen(function* () {
|
|
|
86
86
|
* condition here. If that turns up in practice, a composing override is the
|
|
87
87
|
* additive answer and this hatch is not it.
|
|
88
88
|
*
|
|
89
|
-
* `Effect.
|
|
89
|
+
* `Effect.updateContext` over
|
|
90
90
|
* `Context.omit(AppendIsOwned)` is what lets it through the store's ownership
|
|
91
91
|
* refusal — the one route, and `AppendIsOwned.ts` owns why removing the marker is
|
|
92
92
|
* the shape rather than a second tag or a sanctioning flag.
|
|
@@ -116,7 +116,7 @@ reason) => _effect.Effect.flatMap(_core.DcbEventStore, store =>
|
|
|
116
116
|
// channel), so nothing here will fail to compile if this is deleted — what
|
|
117
117
|
// catches it is `test/appendOwnership.test.ts` in the source repository, not the
|
|
118
118
|
// type checker.
|
|
119
|
-
_effect.Effect.
|
|
119
|
+
_effect.Effect.updateContext(store.append(events), context => _effect.Context.omit(_core.AppendIsOwned)(context)));
|
|
120
120
|
/**
|
|
121
121
|
* Open a bracket over ONE decision: evaluate the precondition inside it, hand its
|
|
122
122
|
* output to the body under the precondition's tag, and append what the body
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"precondition.js","names":["_core","require","_effect","_decision","_decisionModel","_readLedger","decideOnly","decider","command","Effect","gen","ReadLedger","state","modelAtHead","projections","decide","exports","unsafeAppend","events","reason","flatMap","DcbEventStore","store","
|
|
1
|
+
{"version":3,"file":"precondition.js","names":["_core","require","_effect","_decision","_decisionModel","_readLedger","decideOnly","decider","command","Effect","gen","ReadLedger","state","modelAtHead","projections","decide","exports","unsafeAppend","events","reason","flatMap","DcbEventStore","store","updateContext","append","context","Context","omit","AppendIsOwned","transact","precondition","body","ledger","makeReadLedger","output","proof","evaluate","pipe","provideService","tag","provide","Layer","merge","layer","succeed","by","isUnchanged","condition","deriveLayeredCondition","hops","undefined","NoReadsRecorded"],"sources":["../../src/precondition.ts"],"sourcesContent":[null],"mappings":";;;;;;AAwGA,IAAAA,KAAA,GAAAC,OAAA;AAEA,IAAAC,OAAA,GAAAD,OAAA;AAEA,IAAAE,SAAA,GAAAF,OAAA;AAKA,IAAAG,cAAA,GAAAH,OAAA;AAGA,IAAAI,WAAA,GAAAJ,OAAA;AAsCA;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;AAqDO,MAAMK,UAAU,GAAGA,CAOxBC,OAAqC,EACrCC,OAAgB,KAMhBC,cAAM,CAACC,GAAG,CAAC,aAAS;EAClB,OAAOC,sBAAU;EAEjB,MAAM;IAAEC;EAAK,CAAE,GAAG,OAAO,IAAAC,0BAAW,EAACN,OAAO,CAACO,WAAW,CAACN,OAAO,CAAC,CAAC;EAClE,OAAO,OAAOD,OAAO,CAACQ,MAAM,CAACH,KAAK,EAAEJ,OAAO,CAAC;AAC9C,CAAC,CAAC;AAEJ;;;;;;;;;;;;;;;;;;;;;;AAAAQ,OAAA,CAAAV,UAAA,GAAAA,UAAA;AAsBO,MAAMW,YAAY,GAAGA,CAC1BC,MAA2C;AAC3C;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACAC,MAAc,KAEdV,cAAM,CAACW,OAAO,CAACC,mBAAa,EAAGC,KAAK;AAClC;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACAb,cAAM,CAACc,aAAa,CAClBD,KAAK,CAACE,MAAM,CAACN,MAAM,CAAC,EACnBO,OAA+B,IAAKC,eAAO,CAACC,IAAI,CAACC,mBAAa,CAAC,CAACH,OAAO,CAAC,CAC1E,CACF;AAEH;;;;;;;;;;;;;;;;;;;;;;;AAAAT,OAAA,CAAAC,YAAA,GAAAA,YAAA;AAuBO,MAAMY,QAAQ,GACGC,YAA+C,IAEnEC,IAA4B,IAQ5BtB,cAAM,CAACC,GAAG,CAAC,aAAS;EAClB,MAAMY,KAAK,GAAG,OAAOD,mBAAa;EAClC,MAAMW,MAAM,GAAG,OAAOC,0BAAc;EAEpC,MAAMC,MAAM,GAAmB,OAAOzB,cAAM,CAACC,GAAG,CAAC,aAAS;IACxD;IACA;IACA;IACA,MAAMyB,KAAK,GAAG,OAAOL,YAAY,CAACM,QAAQ;IAC1C,OAAO,OAAOL,IAAI,CAACM,IAAI,CAAC5B,cAAM,CAAC6B,cAAc,CAACR,YAAY,CAACS,GAAG,EAAEJ,KAAK,CAAC,CAAC;EACzE,CAAC,CAAC,CAACE,IAAI;EACL;EACA;EACA;EACA;EACA;EACA;EACA;EACA;EACA;EACA;EACA;EACA;EACA;EACA;EACA;EACA;EACA;EACA;EACA5B,cAAM,CAAC+B,OAAO,CACZC,aAAK,CAACC,KAAK,CACTV,MAAM,CAACW,KAAK,EACZF,aAAK,CAACG,OAAO,CAAChB,mBAAa,EAAE;IAAEiB,EAAE,EAAE;EAAU,CAAE,CAAC,CACjD,CACF,CACF;EAED;EACA;EACA;EACA;EACA;EACA;EACA,IAAI,IAAAC,qBAAW,EAACZ,MAAM,CAAC,EAAE;IACvB,OAAOA,MAA2B;EACpC;EAEA,MAAMa,SAAS,GAAG,IAAAC,kCAAsB,EAAC,OAAOhB,MAAM,CAACiB,IAAI,CAAC;EAC5D,IAAIF,SAAS,KAAKG,SAAS,EAAE;IAC3B,OAAO,OAAO,IAAIC,2BAAe,EAAE;EACrC;EAEA,OAAQ,OAAO7B,KAAK,CAACE,MAAM,CAACU,MAAM,EAAEa,SAAS,CAAC;AAChD,CAAC,CAAC;AAAA/B,OAAA,CAAAa,QAAA,GAAAA,QAAA","ignoreList":[]}
|
package/dist/cjs/projection.js
CHANGED
|
@@ -12,7 +12,7 @@ var _core = require("@kairos-es/core");
|
|
|
12
12
|
* A `SliceProjection<S, R>` is a core `AnyProjection<S>` (directly composable —
|
|
13
13
|
* its `evolve` folds a `DecodedEvent`) enriched with the `type -> Schema` map
|
|
14
14
|
* `decodeSlices` merges and decodes through. That map's value type carries `R`
|
|
15
|
-
* covariantly (`Schema<unknown,
|
|
15
|
+
* covariantly (`Schema.Decoder<unknown, R>`), so the union of the defs'
|
|
16
16
|
* requirements flows to the decision model with no cast (and no phantom marker).
|
|
17
17
|
* Because `evolve` is already erased, a built slice drops straight into
|
|
18
18
|
* `composeProjections` — no `AnyProjection.of` ceremony.
|
|
@@ -57,18 +57,17 @@ const projection = initialState => {
|
|
|
57
57
|
// The entry type is annotated `R | R2` rather than inferred, and that
|
|
58
58
|
// annotation is what carries the requirement forward — `build` reads `R`
|
|
59
59
|
// straight off this map, so `RequirementOf` ultimately reads it from here.
|
|
60
|
-
// Widening the copied `R` entries into it costs nothing: `Schema`
|
|
61
|
-
// declared `<
|
|
60
|
+
// Widening the copied `R` entries into it costs nothing: `Schema.Decoder`
|
|
61
|
+
// is declared `<out T, out RD>` upstream, hence covariant in its
|
|
62
62
|
// requirement.
|
|
63
63
|
const nextSchemas = new Map(schemas);
|
|
64
|
-
// Erasing `A`/`I`
|
|
65
|
-
//
|
|
66
|
-
// `Schema<unknown, unknown, R2>` are unrelated in either direction. It is
|
|
64
|
+
// Erasing `A`/`I` needs no cast: a `Schema.Codec` is covariant in both, so
|
|
65
|
+
// `Codec<A, I, R2, R2>` is already a `Decoder<unknown, R2>`. The erasure is
|
|
67
66
|
// sound because the payload is only ever read back through `evolve`, which
|
|
68
|
-
// re-narrows by event type via the matching `fold`.
|
|
69
|
-
//
|
|
70
|
-
//
|
|
71
|
-
//
|
|
67
|
+
// re-narrows by event type via the matching `fold`. What survives it is
|
|
68
|
+
// `R2`, the def's DECODING requirement — an `Encrypted` field's `CipherKey`
|
|
69
|
+
// is not nothing — and that is the half a slice ever spends, since a slice
|
|
70
|
+
// decodes and never encodes.
|
|
72
71
|
nextSchemas.set(def.type, def.schema);
|
|
73
72
|
const nextFolds = new Map(folds);
|
|
74
73
|
// Contravariance in the payload parameter, so this one is a cast too: the
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"projection.js","names":["_core","require","projection","initialState","make","schemas","folds","on","def","fold","has","type","Error","nextSchemas","Map","set","schema","nextFolds","build","options","types","keys","map","t","EventType","query","items","tags","evolve","state","decoded","get","sequenced","event","undefined","payload","exports"],"sources":["../../src/projection.ts"],"sourcesContent":[null],"mappings":";;;;;;AAmBA,IAAAA,KAAA,GAAAC,OAAA;AAnBA;;;;;;;;;;;;;;;;;;;;AA6DA;;;;AAIO,MAAMC,UAAU,GAAOC,YAAe,IAAiC;EAC5E;EACA;EACA;EACA;EACA;EACA;EACA;EACA;EACA;EACA;EACA,MAAMC,IAAI,GAAGA,CACXC,
|
|
1
|
+
{"version":3,"file":"projection.js","names":["_core","require","projection","initialState","make","schemas","folds","on","def","fold","has","type","Error","nextSchemas","Map","set","schema","nextFolds","build","options","types","keys","map","t","EventType","query","items","tags","evolve","state","decoded","get","sequenced","event","undefined","payload","exports"],"sources":["../../src/projection.ts"],"sourcesContent":[null],"mappings":";;;;;;AAmBA,IAAAA,KAAA,GAAAC,OAAA;AAnBA;;;;;;;;;;;;;;;;;;;;AA6DA;;;;AAIO,MAAMC,UAAU,GAAOC,YAAe,IAAiC;EAC5E;EACA;EACA;EACA;EACA;EACA;EACA;EACA;EACA;EACA;EACA,MAAMC,IAAI,GAAGA,CACXC,OAAwD,EACxDC,KAA6D,MAChC;IAC7BC,EAAE,EAAEA,CACFC,GAAuB,EACvBC,IAAiC,KACD;MAChC;MACA;MACA;MACA;MACA;MACA;MACA;MACA;MACA;MACA,IAAIJ,OAAO,CAACK,GAAG,CAACF,GAAG,CAACG,IAAI,CAAC,EAAE;QACzB,MAAM,IAAIC,KAAK,CACb,yBAAyBJ,GAAG,CAACG,IAAI,mCAAmC,GAClE,gEAAgE,GAChE,gCAAgC,CACnC;MACH;MACA;MAC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AAC1C,CAAC;AAAAsB,OAAA,CAAAlC,UAAA,GAAAA,UAAA","ignoreList":[]}
|
package/dist/cjs/readLedger.js
CHANGED
|
@@ -14,7 +14,7 @@ var _effect = require("effect");
|
|
|
14
14
|
* requirement channel nothing is exactly what makes this change additive.
|
|
15
15
|
* `modelAtHead` is that path and is why the rule exists.
|
|
16
16
|
*
|
|
17
|
-
* A BRACKET-ONLY function is the opposite case and yields the
|
|
17
|
+
* A BRACKET-ONLY function is the opposite case and yields the service deliberately.
|
|
18
18
|
* `decideOnly` does, and naming the requirement is what turns *"call me inside a
|
|
19
19
|
* bracket"* from a runtime defect into a compile error — presence being the one
|
|
20
20
|
* direction the type system can decide here. So the test is what the function
|
|
@@ -24,7 +24,7 @@ var _effect = require("effect");
|
|
|
24
24
|
* Recording is two-phase, and `record`'s own doc below owns why and what shape the
|
|
25
25
|
* second phase takes.
|
|
26
26
|
*/
|
|
27
|
-
class ReadLedger extends /*#__PURE__*/_effect.Context.
|
|
27
|
+
class ReadLedger extends /*#__PURE__*/_effect.Context.Service()('@kairos-es/codec/ReadLedger') {}
|
|
28
28
|
/**
|
|
29
29
|
* Raised when a bracket closes having recorded no read at all.
|
|
30
30
|
*
|
|
@@ -174,8 +174,23 @@ const recordQuery = query => withLedger(NO_CLOSE, ledger => ledger.record(query)
|
|
|
174
174
|
/** The tagless slice keys in a record, in declaration order. */
|
|
175
175
|
exports.recordQuery = recordQuery;
|
|
176
176
|
const taglessKeys = projections => Object.entries(projections).filter(([, projection]) => projection.query.items.some(item => item.tags.length === 0)).map(([key]) => key);
|
|
177
|
-
/**
|
|
178
|
-
|
|
177
|
+
/**
|
|
178
|
+
* Would recording this record's query leave the accumulated union unservable in
|
|
179
|
+
* its SHAPE — the one fault a slice's tags can fix, and so the one this ledger
|
|
180
|
+
* reports?
|
|
181
|
+
*
|
|
182
|
+
* An unknown key anywhere in the union answers no. It is not a tagless slice and no
|
|
183
|
+
* slice's tags would fix it, and the store refuses it as a defect naming the key at
|
|
184
|
+
* the read of the hop that carries it, so an earlier hop's key has already been
|
|
185
|
+
* refused once by the time a later record is judged. Judged here it would surface
|
|
186
|
+
* as this ledger's error, on the error channel, naming a slice with nothing wrong
|
|
187
|
+
* with it — and a hop is recorded before its read runs, so an earlier hop's key
|
|
188
|
+
* would go on doing that to every clean read after it.
|
|
189
|
+
*/
|
|
190
|
+
const unionWouldBeUnservable = (existing, incoming) => {
|
|
191
|
+
const union = (0, _core.unionQueries)([...existing.map(h => h.query), incoming]);
|
|
192
|
+
return (0, _core.unknownQueryKeyFault)(union) === undefined && (0, _core.servableQueryFault)(union) !== undefined;
|
|
193
|
+
};
|
|
179
194
|
/**
|
|
180
195
|
* Refuse a read that would leave the bracket's accumulated union unservable,
|
|
181
196
|
* BEFORE the read is paid for.
|
|
@@ -220,5 +235,5 @@ const assertServableAddition = projections => withLedger(undefined, ledger => _e
|
|
|
220
235
|
* than from its own single read.
|
|
221
236
|
*/
|
|
222
237
|
exports.assertServableAddition = assertServableAddition;
|
|
223
|
-
const ambientLayeredCondition = exports.ambientLayeredCondition = /*#__PURE__*/withLedger(/*#__PURE__*/_effect.Option.none(), ledger => _effect.Effect.map(ledger.hops, hops => _effect.Option.
|
|
238
|
+
const ambientLayeredCondition = exports.ambientLayeredCondition = /*#__PURE__*/withLedger(/*#__PURE__*/_effect.Option.none(), ledger => _effect.Effect.map(ledger.hops, hops => _effect.Option.fromNullishOr(deriveLayeredCondition(hops))));
|
|
224
239
|
//# sourceMappingURL=readLedger.js.map
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"readLedger.js","names":["_core","require","_effect","ReadLedger","Context","
|
|
1
|
+
{"version":3,"file":"readLedger.js","names":["_core","require","_effect","ReadLedger","Context","Service","exports","NoReadsRecorded","Data","TaggedError","message","TaglessSliceInLedger","sliceKey","deriveLayeredCondition","hops","length","undefined","merged","unionQueries","map","hop","query","arrived","flatMap","head","after","reduce","a","b","ORIGIN","failIfEventsMatch","makeReadLedger","Effect","gen","ref","Ref","make","layer","Layer","succeed","record","modify","update","current","index","get","withLedger","absent","f","serviceOption","ledger","Option","isNone","value","NO_CLOSE","void","recordQuery","taglessKeys","projections","Object","entries","filter","projection","items","some","item","tags","key","unionWouldBeUnservable","existing","incoming","union","h","unknownQueryKeyFault","servableQueryFault","assertServableAddition","composeProjections","offending","ambientLayeredCondition","none","fromNullishOr"],"sources":["../../src/readLedger.ts"],"sourcesContent":[null],"mappings":";;;;;;AAsEA,IAAAA,KAAA,GAAAC,OAAA;AAOA,IAAAC,OAAA,GAAAD,OAAA;AAeA;;;;;;;;;;;;;;;;;;AAkBM,MAAOE,UAAW,sBAAQC,eAAO,CAACC,OAAO,EAmB5C,CAAC,6BAA6B,CAAC;AAYlC;;;;;;;;;;;;;;;;;;;AAAAC,OAAA,CAAAH,UAAA,GAAAA,UAAA;AAmBM,MAAOI,eAAgB,sBAAQC,YAAI,CAACC,WAAW,CAAC,iBAAiB,CAEtE;EACC;;;;;;;;EAQA,IAAaC,OAAOA,CAAA;IAClB,OACE,8EAA8E,GAC9E,8EAA8E,GAC9E,uEAAuE;EAE3E;;AAGF;;;;;;;;;;;;;;;;;AAAAJ,OAAA,CAAAC,eAAA,GAAAA,eAAA;AAiBM,MAAOI,oBAAqB,sBAAQH,YAAI,CAACC,WAAW,CACxD,sBAAsB,CACQ;EAC9B;EACA,IAAaC,OAAOA,CAAA;IAClB,OACE,UAAU,IAAI,CAACE,QAAQ,uDAAuD,GAC9E,wEAAwE,GACxE,6EAA6E,GAC7E,+CAA+C;EAEnD;;AAGF;;;;;;;;;;;;;;;;;;;;;;;;;;;AAAAN,OAAA,CAAAK,oBAAA,GAAAA,oBAAA;AA2BO,MAAME,sBAAsB,GACjCC,IAAwB,IACO;EAC/B,IAAIA,IAAI,CAACC,MAAM,KAAK,CAAC,EAAE;IACrB,OAAOC,SAAS;EAClB;EACA,MAAMC,MAAM,GAAG,IAAAC,kBAAY,EAACJ,IAAI,CAACK,GAAG,CAAEC,GAAG,IA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SAAS,IACzC,IAAA0D,wBAAkB,EAACH,KAAK,CAAC,KAAKvD,SAAS;AAE3C,CAAC;AAED;;;;;;;;;;;;;;;;;;;;;;;AAuBO,MAAM2D,sBAAsB,GACjCjB,WAA0C,IAE1CZ,UAAU,CAA6B9B,SAAS,EAAGkC,MAAM,IACvDlB,cAAM,CAACT,OAAO,CAAC2B,MAAM,CAACpC,IAAI,EAAGuD,QAAQ,IAAI;EACvC,MAAMC,QAAQ,GAAG,IAAAM,wBAAkB,EAAClB,WAAW,CAAC,CAACrC,KAAK;EACtD,IAAI,CAAC+C,sBAAsB,CAACC,QAAQ,EAAEC,QAAQ,CAAC,EAAE;IAC/C,OAAOtC,cAAM,CAACuB,IAAI;EACpB;EACA;EACA;EACA;EACA,MAAMsB,SAAS,GAAGpB,WAAW,CAACC,WAAW,CAAC,CAAC,CAAC,CAAC,IAAI,kBAAkB;EACnE,OAAO,IAAI/C,oBAAoB,CAAC;IAAEC,QAAQ,EAAEiE;EAAS,CAAE,CAAC;AAC1D,CAAC,CAAC,CACH;AAEH;;;;;;;AAAAvE,OAAA,CAAAqE,sBAAA,GAAAA,sBAAA;AAOO,MAAMG,uBAAuB,GAAAxE,OAAA,CAAAwE,uBAAA,gBAEhChC,UAAU,cAACK,cAAM,CAAC4B,IAAI,EAAmB,EAAG7B,MAAM,IACpDlB,cAAM,CAACb,GAAG,CAAC+B,MAAM,CAACpC,IAAI,EAAGA,IAAI,IAC3BqC,cAAM,CAAC6B,aAAa,CAACnE,sBAAsB,CAACC,IAAI,CAAC,CAAC,CACnD,CACF","ignoreList":[]}
|
package/dist/cjs/registry.js.map
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"registry.js","names":["_effect","require","_deserialiseThenDecode","_errors","_Serializer","makeRegistry","defs","map","Map","def","has","type","Error","set","schema","decode","event","Effect","gen","get","undefined","fail","UnknownEventType","serializer","Serializer","payload","deserialiseThenDecode","data","exports"],"sources":["../../src/registry.ts"],"sourcesContent":[null],"mappings":";;;;;;AA2BA,IAAAA,OAAA,GAAAC,OAAA;AACA,IAAAC,sBAAA,GAAAD,OAAA;AACA,IAAAE,OAAA,GAAAF,OAAA;AAEA,IAAAG,WAAA,GAAAH,OAAA;AAqBO,MAAMI,YAAY,GACvBC,IAAU,IAC2B;EACrC,MAAMC,GAAG,GAAG,IAAIC,GAAG,
|
|
1
|
+
{"version":3,"file":"registry.js","names":["_effect","require","_deserialiseThenDecode","_errors","_Serializer","makeRegistry","defs","map","Map","def","has","type","Error","set","schema","decode","event","Effect","gen","get","undefined","fail","UnknownEventType","serializer","Serializer","payload","deserialiseThenDecode","data","exports"],"sources":["../../src/registry.ts"],"sourcesContent":[null],"mappings":";;;;;;AA2BA,IAAAA,OAAA,GAAAC,OAAA;AACA,IAAAC,sBAAA,GAAAD,OAAA;AACA,IAAAE,OAAA,GAAAF,OAAA;AAEA,IAAAG,WAAA,GAAAH,OAAA;AAqBO,MAAMI,YAAY,GACvBC,IAAU,IAC2B;EACrC,MAAMC,GAAG,GAAG,IAAIC,GAAG,EAA4C;EAC/D,KAAK,MAAMC,GAAG,IAAIH,IAAI,EAAE;IACtB,IAAIC,GAAG,CAACG,GAAG,CAACD,GAAG,CAACE,IAAI,CAAC,EAAE;MACrB,MAAM,IAAIC,KAAK,CAAC,yBAAyBH,GAAG,CAACE,IAAI,eAAe,CAAC;IACnE;IACAJ,GAAG,CAACM,GAAG,CAACJ,GAAG,CAACE,IAAI,EAAEF,GAAG,CAACK,MAAM,CAAC;EAC/B;EACA,OAAO;IACLC,MAAM,EAAGC,KAAK,IACZC,cAAM,CAACC,GAAG,CAAC,aAAS;MAClB,MAAMJ,MAAM,GAAGP,GAAG,CAACY,GAAG,CAACH,KAAK,CAACL,IAAI,CAAC;MAClC,IAAIG,MAAM,KAAKM,SAAS,EAAE;QACxB,OAAO,OAAOH,cAAM,CAACI,IAAI,CAAC,IAAIC,wBAAgB,CAAC;UAAEX,IAAI,EAAEK,KAAK,CAACL;QAAI,CAAE,CAAC,CAAC;MACvE;MACA,MAAMY,UAAU,GAAG,OAAOC,sBAAU;MACpC,MAAMC,OAAO,GAAG,OAAO,IAAAC,4CAAqB,EAC1CH,UAAU,EACVT,MAAM,EACNE,KAAK,CAACW,IAAI,CACX;MACD,OAAO;QAAEhB,IAAI,EAAEK,KAAK,CAACL,IAAI;QAAEc;MAAO,CAAE;MACpC;MACA;MACA;MACA;IACF,CAAC;GAKJ;AACH,CAAC;AAAAG,OAAA,CAAAvB,YAAA,GAAAA,YAAA","ignoreList":[]}
|
package/dist/cjs/toEvent.js
CHANGED
|
@@ -4,10 +4,33 @@ Object.defineProperty(exports, "__esModule", {
|
|
|
4
4
|
value: true
|
|
5
5
|
});
|
|
6
6
|
exports.toEvent = void 0;
|
|
7
|
+
var _core = require("@kairos-es/core");
|
|
7
8
|
var _effect = require("effect");
|
|
8
9
|
var _errors = require("./errors.js");
|
|
10
|
+
var _MetadataSource = require("./MetadataSource.js");
|
|
9
11
|
var _Serializer = require("./Serializer.js");
|
|
10
12
|
var _Uuid = require("./Uuid.js");
|
|
13
|
+
/**
|
|
14
|
+
* Event production (codec edge-helper): turn a typed payload into a wire
|
|
15
|
+
* `DcbEvent`. Encode is `Schema.encodeEffect(def.schema)` (a `SchemaError`
|
|
16
|
+
* becomes a `CodecError`; any encryption transform runs here, *before* serialisation)
|
|
17
|
+
* then `serialiser.serialise`. The wire `tags` are derived from the def's
|
|
18
|
+
* required `tagsFor` mapper (ADR-0006) — they are never hand-passed, so two
|
|
19
|
+
* command sites emitting the same event type cannot tag it differently. A mapper
|
|
20
|
+
* that throws (e.g. an ill-formed `key:value` rejected by `Tag.make`) is
|
|
21
|
+
* surfaced on the `CodecError` channel, not as a defect. `uuid`
|
|
22
|
+
* comes from `options.uuid` or the `Uuid` service; `occurredAt` from
|
|
23
|
+
* `options.occurredAt` or the Effect clock (`DateTime.now`), keeping `core`
|
|
24
|
+
* clock- and RNG-free while staying overridable for backdated imports.
|
|
25
|
+
* `metadata` comes from `options.metadata` or the OPTIONAL ambient
|
|
26
|
+
* `MetadataSource` service, and is `{}` when neither supplies it (ADR-0017). A
|
|
27
|
+
* bag core's `Metadata` schema refuses, such as one holding a value that is not a
|
|
28
|
+
* string, fails on the `CodecError` channel (`reason: 'metadata'`), whichever of
|
|
29
|
+
* the two supplied it. It never reaches `tagsFor`, the
|
|
30
|
+
* event's schema or the serialiser, so it can enter neither the tag junction
|
|
31
|
+
* table nor the encryption seam.
|
|
32
|
+
*/
|
|
33
|
+
|
|
11
34
|
/**
|
|
12
35
|
* Encode `payload` under `def` and stamp it into a wire `DcbEvent`, deriving its
|
|
13
36
|
* `tags` from `def.tagsFor(payload)` (a throwing mapper surfaces as a
|
|
@@ -16,10 +39,40 @@ var _Uuid = require("./Uuid.js");
|
|
|
16
39
|
* wire-envelope fields (the query surface), so a `tagsFor` mapper may only key
|
|
17
40
|
* off cleartext payload fields (ADR-0006). `uuid` / `occurredAt` are
|
|
18
41
|
* exact-optional overrides; absent, they come from the `Uuid` service and the
|
|
19
|
-
* Effect clock.
|
|
42
|
+
* Effect clock. `metadata` is an exact-optional override too; absent, it comes
|
|
43
|
+
* from the ambient `MetadataSource` if one is provided and is `{}` otherwise.
|
|
44
|
+
* The ambient read adds nothing to the requirement channel. A bag core's
|
|
45
|
+
* `Metadata` schema refuses fails as a `CodecError` with `reason: 'metadata'`.
|
|
20
46
|
*/
|
|
21
47
|
const toEvent = (def, payload, options) => _effect.Effect.gen(function* () {
|
|
22
|
-
//
|
|
48
|
+
// Resolve metadata before anything else. Per-call wins, ambient fills,
|
|
49
|
+
// absent yields `{}`. `serviceOption` keeps `MetadataSource` out of the
|
|
50
|
+
// requirement channel.
|
|
51
|
+
//
|
|
52
|
+
// The bag is then CHECKED against core's `Metadata` schema, whichever arm
|
|
53
|
+
// supplied it. The type holds a typed caller to a bag of strings, but an
|
|
54
|
+
// `any` or untyped JavaScript gets past it, and the engines then disagree
|
|
55
|
+
// about what they stored: the cross-engine parity of this field rests on its
|
|
56
|
+
// values being strings, and this is the one place a value is refused. It is
|
|
57
|
+
// refused HERE, at write, and never on read: a read-side check would make an
|
|
58
|
+
// event the store had accepted unreadable for ever. A bad bag is the
|
|
59
|
+
// caller's mistake, so it fails on the `CodecError` channel exactly as a
|
|
60
|
+
// throwing `tagsFor` does, never as a defect. Checking consumes no sequence,
|
|
61
|
+
// so placing it above the tag derivation leaves the property below intact.
|
|
62
|
+
//
|
|
63
|
+
// The bag is COPIED, never stamped by reference: an ambient bag would
|
|
64
|
+
// otherwise be ONE object shared by every event of a request, and the
|
|
65
|
+
// caller's own object would be shared with the event it built, so a mutation
|
|
66
|
+
// of either before the append would rewrite the other. (After the append no
|
|
67
|
+
// store shares anything with its caller; that is each store's guarantee.)
|
|
68
|
+
const given = options?.metadata === undefined ? _effect.Option.getOrElse(yield* _effect.Effect.serviceOption(_MetadataSource.MetadataSource), () => ({})) : options.metadata;
|
|
69
|
+
const metadata = {
|
|
70
|
+
...(yield* _effect.Schema.decodeUnknownEffect(_core.Metadata)(given).pipe(_effect.Effect.mapError(cause => new _errors.CodecError({
|
|
71
|
+
reason: 'metadata',
|
|
72
|
+
cause
|
|
73
|
+
}))))
|
|
74
|
+
};
|
|
75
|
+
// Derive tags next. A mapper is app code that can throw (e.g. `Tag.make`
|
|
23
76
|
// rejects an ill-formed `key:value`), and the codec's contract is that such
|
|
24
77
|
// failures are values on the `CodecError` channel, never defects (errors.ts).
|
|
25
78
|
// Deriving before the uuid/clock effects also means a bad tag fails without
|
|
@@ -32,7 +85,7 @@ const toEvent = (def, payload, options) => _effect.Effect.gen(function* () {
|
|
|
32
85
|
})
|
|
33
86
|
});
|
|
34
87
|
const serializer = yield* _Serializer.Serializer;
|
|
35
|
-
const encoded = yield* _effect.Schema.
|
|
88
|
+
const encoded = yield* _effect.Schema.encodeEffect(def.schema)(payload).pipe(_effect.Effect.mapError(cause => new _errors.CodecError({
|
|
36
89
|
reason: 'encode',
|
|
37
90
|
cause
|
|
38
91
|
})));
|
|
@@ -44,7 +97,8 @@ const toEvent = (def, payload, options) => _effect.Effect.gen(function* () {
|
|
|
44
97
|
data,
|
|
45
98
|
tags,
|
|
46
99
|
uuid,
|
|
47
|
-
occurredAt
|
|
100
|
+
occurredAt,
|
|
101
|
+
metadata
|
|
48
102
|
};
|
|
49
103
|
});
|
|
50
104
|
exports.toEvent = toEvent;
|
package/dist/cjs/toEvent.js.map
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"toEvent.js","names":["
|
|
1
|
+
{"version":3,"file":"toEvent.js","names":["_core","require","_effect","_errors","_MetadataSource","_Serializer","_Uuid","toEvent","def","payload","options","Effect","gen","given","metadata","undefined","Option","getOrElse","serviceOption","MetadataSource","Schema","decodeUnknownEffect","Metadata","pipe","mapError","cause","CodecError","reason","tags","try","tagsFor","catch","serializer","Serializer","encoded","encodeEffect","schema","data","serialise","uuid","Uuid","generate","occurredAt","DateTime","now","type","exports"],"sources":["../../src/toEvent.ts"],"sourcesContent":[null],"mappings":";;;;;;AAoBA,IAAAA,KAAA,GAAAC,OAAA;AACA,IAAAC,OAAA,GAAAD,OAAA;AACA,IAAAE,OAAA,GAAAF,OAAA;AAEA,IAAAG,eAAA,GAAAH,OAAA;AACA,IAAAI,WAAA,GAAAJ,OAAA;AACA,IAAAK,KAAA,GAAAL,OAAA;AA1BA;;;;;;;;;;;;;;;;;;;;;AA4BA;;;;;;;;;;;;;AAaO,MAAMM,OAAO,GAAGA,CACrBC,GAAsB,EACtBC,OAAU,EACVC,OAIC,KAEDC,cAAM,CAACC,GAAG,CAAC,aAAS;EAClB;EACA;EACA;EACA;EACA;EACA;EACA;EACA;EACA;EACA;EACA;EACA;EACA;EACA;EACA;EACA;EACA;EACA;EACA;EACA;EACA,MAAMC,KAAK,GACTH,OAAO,EAAEI,QAAQ,KAAKC,SAAS,GAC3BC,cAAM,CAACC,SAAS,CACd,OAAON,cAAM,CAACO,aAAa,CAACC,8BAAc,CAAC,EAC3C,OAAiB,EA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gC,OAAA,CAAAvC,OAAA,GAAAA,OAAA","ignoreList":[]}
|
|
@@ -0,0 +1,8 @@
|
|
|
1
|
+
import { Context } from 'effect';
|
|
2
|
+
declare const MetadataSource_base: Context.ServiceClass<MetadataSource, "@kairos-es/codec/MetadataSource", {
|
|
3
|
+
readonly [x: string]: string;
|
|
4
|
+
}>;
|
|
5
|
+
export declare class MetadataSource extends MetadataSource_base {
|
|
6
|
+
}
|
|
7
|
+
export {};
|
|
8
|
+
//# sourceMappingURL=MetadataSource.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"MetadataSource.d.ts","sourceRoot":"","sources":["../../src/MetadataSource.ts"],"names":[],"mappings":"AAsCA,OAAO,EAAE,OAAO,EAAE,MAAM,QAAQ,CAAA;;;;AAEhC,qBAAa,cAAe,SAAQ,mBAEnC;CAAG"}
|