@kairos-es/codec 0.0.0
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/LICENSE +28 -0
- package/README.md +46 -0
- package/dist/cjs/Serializer.js +34 -0
- package/dist/cjs/Serializer.js.map +1 -0
- package/dist/cjs/Uuid.js +41 -0
- package/dist/cjs/Uuid.js.map +1 -0
- package/dist/cjs/decider.js +152 -0
- package/dist/cjs/decider.js.map +1 -0
- package/dist/cjs/decisionModel.js +155 -0
- package/dist/cjs/decisionModel.js.map +1 -0
- package/dist/cjs/decode.js +170 -0
- package/dist/cjs/decode.js.map +1 -0
- package/dist/cjs/deserialiseThenDecode.js +20 -0
- package/dist/cjs/deserialiseThenDecode.js.map +1 -0
- package/dist/cjs/errors.js +94 -0
- package/dist/cjs/errors.js.map +1 -0
- package/dist/cjs/event.js +26 -0
- package/dist/cjs/event.js.map +1 -0
- package/dist/cjs/index.js +112 -0
- package/dist/cjs/index.js.map +1 -0
- package/dist/cjs/projection.js +118 -0
- package/dist/cjs/projection.js.map +1 -0
- package/dist/cjs/registry.js +41 -0
- package/dist/cjs/registry.js.map +1 -0
- package/dist/cjs/toEvent.js +51 -0
- package/dist/cjs/toEvent.js.map +1 -0
- package/dist/dts/Serializer.d.ts +27 -0
- package/dist/dts/Serializer.d.ts.map +1 -0
- package/dist/dts/Uuid.d.ts +19 -0
- package/dist/dts/Uuid.d.ts.map +1 -0
- package/dist/dts/decider.d.ts +157 -0
- package/dist/dts/decider.d.ts.map +1 -0
- package/dist/dts/decisionModel.d.ts +129 -0
- package/dist/dts/decisionModel.d.ts.map +1 -0
- package/dist/dts/decode.d.ts +92 -0
- package/dist/dts/decode.d.ts.map +1 -0
- package/dist/dts/deserialiseThenDecode.d.ts +62 -0
- package/dist/dts/deserialiseThenDecode.d.ts.map +1 -0
- package/dist/dts/errors.d.ts +79 -0
- package/dist/dts/errors.d.ts.map +1 -0
- package/dist/dts/event.d.ts +71 -0
- package/dist/dts/event.d.ts.map +1 -0
- package/dist/dts/index.d.ts +63 -0
- package/dist/dts/index.d.ts.map +1 -0
- package/dist/dts/projection.d.ts +56 -0
- package/dist/dts/projection.d.ts.map +1 -0
- package/dist/dts/registry.d.ts +46 -0
- package/dist/dts/registry.d.ts.map +1 -0
- package/dist/dts/toEvent.d.ts +34 -0
- package/dist/dts/toEvent.d.ts.map +1 -0
- package/dist/esm/Serializer.js +26 -0
- package/dist/esm/Serializer.js.map +1 -0
- package/dist/esm/Uuid.js +33 -0
- package/dist/esm/Uuid.js.map +1 -0
- package/dist/esm/decider.js +143 -0
- package/dist/esm/decider.js.map +1 -0
- package/dist/esm/decisionModel.js +146 -0
- package/dist/esm/decisionModel.js.map +1 -0
- package/dist/esm/decode.js +163 -0
- package/dist/esm/decode.js.map +1 -0
- package/dist/esm/deserialiseThenDecode.js +13 -0
- package/dist/esm/deserialiseThenDecode.js.map +1 -0
- package/dist/esm/errors.js +85 -0
- package/dist/esm/errors.js.map +1 -0
- package/dist/esm/event.js +19 -0
- package/dist/esm/event.js.map +1 -0
- package/dist/esm/index.js +63 -0
- package/dist/esm/index.js.map +1 -0
- package/dist/esm/package.json +4 -0
- package/dist/esm/projection.js +110 -0
- package/dist/esm/projection.js.map +1 -0
- package/dist/esm/registry.js +34 -0
- package/dist/esm/registry.js.map +1 -0
- package/dist/esm/toEvent.js +44 -0
- package/dist/esm/toEvent.js.map +1 -0
- package/package.json +31 -0
- package/src/Serializer.ts +37 -0
- package/src/Uuid.ts +36 -0
- package/src/decider.ts +219 -0
- package/src/decisionModel.ts +182 -0
- package/src/decode.ts +256 -0
- package/src/deserialiseThenDecode.ts +76 -0
- package/src/errors.ts +91 -0
- package/src/event.ts +90 -0
- package/src/index.ts +71 -0
- package/src/projection.ts +163 -0
- package/src/registry.ts +87 -0
- package/src/toEvent.ts +63 -0
|
@@ -0,0 +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,IAC4D;EAC1E,MAAMC,OAAO,GAAG,IAAIC,GAAG,EAGpB;EACH;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,CACTN,IAAI,EACJC,MAA2D,CAC5D;MACDN,aAAa,CAACW,GAAG,CAACN,IAAI,EAAEJ,GAAG,CAAC;IAC9B;EACF;EACA,OAAOH,OAAO;AAChB,CAAC;AAED;;;;;;;;;;;;;;;;;;;;;;;;;;;;AA4BA,MAAMc,YAAY,GACXd,OAAiE,IAEpEe,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":[]}
|
|
@@ -0,0 +1,20 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
|
|
3
|
+
Object.defineProperty(exports, "__esModule", {
|
|
4
|
+
value: true
|
|
5
|
+
});
|
|
6
|
+
exports.deserialiseThenDecode = void 0;
|
|
7
|
+
var _effect = require("effect");
|
|
8
|
+
var _errors = require("./errors.js");
|
|
9
|
+
const deserialiseThenDecode = (serializer, schema, bytes) => _effect.Effect.try({
|
|
10
|
+
try: () => serializer.deserialise(bytes),
|
|
11
|
+
catch: cause => new _errors.CodecError({
|
|
12
|
+
reason: 'deserialise',
|
|
13
|
+
cause
|
|
14
|
+
})
|
|
15
|
+
}).pipe(_effect.Effect.flatMap(raw => _effect.Schema.decodeUnknown(schema)(raw).pipe(_effect.Effect.mapError(cause => new _errors.CodecError({
|
|
16
|
+
reason: 'decode',
|
|
17
|
+
cause
|
|
18
|
+
})))));
|
|
19
|
+
exports.deserialiseThenDecode = deserialiseThenDecode;
|
|
20
|
+
//# sourceMappingURL=deserialiseThenDecode.js.map
|
|
@@ -0,0 +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","decodeUnknown","mapError","exports"],"sources":["../../src/deserialiseThenDecode.ts"],"sourcesContent":[null],"mappings":";;;;;;AAyDA,IAAAA,OAAA,GAAAC,OAAA;AACA,IAAAC,OAAA,GAAAD,OAAA;AAGO,MAAME,qBAAqB,GAAGA,CACnCC,UAA2C,EAC3CC,MAA0C,EAC1CC,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,aAAa,CAACb,MAAM,CAAC,CAACW,GAAG,CAAC,CAACF,IAAI,CACpCP,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":[]}
|
|
@@ -0,0 +1,94 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
|
|
3
|
+
Object.defineProperty(exports, "__esModule", {
|
|
4
|
+
value: true
|
|
5
|
+
});
|
|
6
|
+
exports.UnknownEventType = exports.CodecError = void 0;
|
|
7
|
+
var _effect = require("effect");
|
|
8
|
+
/**
|
|
9
|
+
* Tagged errors for the codec. Decode failures are values on the error channel,
|
|
10
|
+
* never defects.
|
|
11
|
+
*
|
|
12
|
+
* `CodecError` covers every serialisation/`Schema` failure on the codec path
|
|
13
|
+
* (deserialise threw, `Schema.decode`/`encode` produced a `ParseError`, a
|
|
14
|
+
* wrong/absent encryption key surfaced through a `Schema` transform, or a
|
|
15
|
+
* `tagsFor` mapper threw while deriving an event's tags). It carries a
|
|
16
|
+
* human-readable `reason` and the underlying `cause` (exact-optional).
|
|
17
|
+
* `UnknownEventType` is raised only on the general (registry) path, when a wire
|
|
18
|
+
* event's runtime type string is outside the registered set — the home of
|
|
19
|
+
* ADR-0005 decode-totality.
|
|
20
|
+
*/
|
|
21
|
+
|
|
22
|
+
/** A serialisation or `Schema` decode/encode failure on the codec path. */
|
|
23
|
+
class CodecError extends /*#__PURE__*/_effect.Data.TaggedError('CodecError') {
|
|
24
|
+
/**
|
|
25
|
+
* `reason` again, as the `Error` field that says why — so the fault renders
|
|
26
|
+
* ITSELF.
|
|
27
|
+
*
|
|
28
|
+
* `Data.TaggedError` sets `name` to the tag and leaves `message` empty, so
|
|
29
|
+
* without this a `CodecError` stringifies to `'CodecError'`, and the sentence
|
|
30
|
+
* naming the schema, the event type or the missing key that failed reaches a log
|
|
31
|
+
* line only where the code doing the logging knows to reach in for `reason`.
|
|
32
|
+
* Filled, `Error.prototype.toString` yields `'CodecError: <reason>'`, which is
|
|
33
|
+
* what `Cause.pretty` (it reads `message` off anything `instanceof Error`) and the
|
|
34
|
+
* read side's projection supervisor both report — neither of them holding a table
|
|
35
|
+
* of this class's fields to keep in step with it.
|
|
36
|
+
*
|
|
37
|
+
* This class is on the package's PUBLISHED surface, so be exact about what the
|
|
38
|
+
* field moves. Everything that renders the error for a HUMAN: `String(err)`,
|
|
39
|
+
* `Cause.pretty` and therefore a failed fibre's `cause` annotation on every
|
|
40
|
+
* shipped logger, and an unhandled failure's report. Nothing that renders it for
|
|
41
|
+
* a MACHINE: `Data.Error` overrides `YieldableError`'s `toJSON` with
|
|
42
|
+
* `{ ...plainArgs, ...this }` — own enumerables plus the constructor args, and a
|
|
43
|
+
* prototype accessor is neither — so `JSON.stringify(err)` still emits the same
|
|
44
|
+
* `reason`/`_tag` and a structured log of a raw `CodecError` keeps its shape.
|
|
45
|
+
*
|
|
46
|
+
* A GETTER rather than a second field, so `reason` stays the single declaration.
|
|
47
|
+
* It is visible because `Data.TaggedError`'s constructor is
|
|
48
|
+
* `super(args?.message, …)` followed by `Object.assign(this, args)` (verified
|
|
49
|
+
* against `effect@3.22`'s `Data.ts`): the args above carry no `message`, so
|
|
50
|
+
* nothing shadows this prototype accessor with an own property.
|
|
51
|
+
*/
|
|
52
|
+
get message() {
|
|
53
|
+
return this.reason;
|
|
54
|
+
}
|
|
55
|
+
}
|
|
56
|
+
/** A wire event whose runtime type string is outside the registry's known set. */
|
|
57
|
+
exports.CodecError = CodecError;
|
|
58
|
+
class UnknownEventType extends /*#__PURE__*/_effect.Data.TaggedError('UnknownEventType') {
|
|
59
|
+
/**
|
|
60
|
+
* The offending type, in a sentence saying what the registry did with it — so the
|
|
61
|
+
* fault renders ITSELF, exactly as `CodecError` above does.
|
|
62
|
+
*
|
|
63
|
+
* `Data.TaggedError` sets `name` to the tag and leaves `message` empty, so without
|
|
64
|
+
* this a decode that met an unregistered type stringifies to `'UnknownEventType'`
|
|
65
|
+
* — the one datum that makes the failure actionable, the type string itself,
|
|
66
|
+
* reaching a log line only where the logging code knows to reach in for `type`.
|
|
67
|
+
* Filled, `Error.prototype.toString` yields the tag followed by
|
|
68
|
+
* `event type 'nope.v1' is not in the registry`, which is what `Cause.pretty`
|
|
69
|
+
* prints and what an operator greps for. It matters here in particular because
|
|
70
|
+
* this class is the home of ADR-0005 decode-totality: a wire event outside the
|
|
71
|
+
* registered set is the expected consequence of a deployment reading a log a newer
|
|
72
|
+
* writer has extended, and the first question is always WHICH type — which the tag
|
|
73
|
+
* alone cannot answer.
|
|
74
|
+
*
|
|
75
|
+
* The wording deliberately differs from `CodecError`'s. That one says there is no
|
|
76
|
+
* schema for a type, and is raised on the TYPED path, where a caller named the
|
|
77
|
+
* type and the schema map it supplied has no entry for it. This one is the general
|
|
78
|
+
* (registry) path, where the type arrived off the WIRE and the registry is what
|
|
79
|
+
* does not know it. Distinct sentences keep the two greppable apart, which a
|
|
80
|
+
* shared phrasing would cost for nothing.
|
|
81
|
+
*
|
|
82
|
+
* A GETTER rather than a second field, so `type` stays the single declaration.
|
|
83
|
+
* What filling this field reaches, what it deliberately leaves untouched, and why
|
|
84
|
+
* a prototype accessor is visible at all are argued once on `CodecError` above and
|
|
85
|
+
* not restated here — it is the same package, the same published surface and the
|
|
86
|
+
* same mechanism, and two copies of that paragraph would be two things to keep in
|
|
87
|
+
* step. The read side's four getters point at one home for the identical reason.
|
|
88
|
+
*/
|
|
89
|
+
get message() {
|
|
90
|
+
return `event type '${this.type}' is not in the registry`;
|
|
91
|
+
}
|
|
92
|
+
}
|
|
93
|
+
exports.UnknownEventType = UnknownEventType;
|
|
94
|
+
//# sourceMappingURL=errors.js.map
|
|
@@ -0,0 +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":";;;;;;AAaA,IAAAA,OAAA,GAAAC,OAAA;AAbA;;;;;;;;;;;;;;AAeA;AACM,MAAOC,UAAW,sBAAQC,YAAI,CAACC,WAAW,CAAC,YAAY,CAG3D;EACA;;;;;;;;;;;;;;;;;;;;;;;;;;;;EA4BA,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":[]}
|
|
@@ -0,0 +1,26 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
|
|
3
|
+
Object.defineProperty(exports, "__esModule", {
|
|
4
|
+
value: true
|
|
5
|
+
});
|
|
6
|
+
exports.event = void 0;
|
|
7
|
+
var _effect = require("effect");
|
|
8
|
+
/**
|
|
9
|
+
* Define an event from a versioned `type` literal, its payload `fields`, and its
|
|
10
|
+
* required `tagsFor` mapper. Builds `Schema.Struct(fields)` and brands the type
|
|
11
|
+
* literal *once* (the single sanctioned cast). The returned def is typed so
|
|
12
|
+
* `def.type` is a branded literal assignable to core's `EventType` with no
|
|
13
|
+
* consumer cast, `A`/`I`/`R` are inferred from the struct, and `tagsFor`
|
|
14
|
+
* receives the def's decoded payload type.
|
|
15
|
+
*/
|
|
16
|
+
const event = (type, fields, tagsFor) => {
|
|
17
|
+
const schema = _effect.Schema.Struct(fields);
|
|
18
|
+
return {
|
|
19
|
+
// The single EventType brand, applied once inside event(); no consumer casts.
|
|
20
|
+
type: type,
|
|
21
|
+
schema,
|
|
22
|
+
tagsFor
|
|
23
|
+
};
|
|
24
|
+
};
|
|
25
|
+
exports.event = event;
|
|
26
|
+
//# sourceMappingURL=event.js.map
|
|
@@ -0,0 +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;AA+BA;;;;;;;;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":[]}
|
|
@@ -0,0 +1,112 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
|
|
3
|
+
Object.defineProperty(exports, "__esModule", {
|
|
4
|
+
value: true
|
|
5
|
+
});
|
|
6
|
+
Object.defineProperty(exports, "CodecError", {
|
|
7
|
+
enumerable: true,
|
|
8
|
+
get: function () {
|
|
9
|
+
return _errors.CodecError;
|
|
10
|
+
}
|
|
11
|
+
});
|
|
12
|
+
Object.defineProperty(exports, "Serializer", {
|
|
13
|
+
enumerable: true,
|
|
14
|
+
get: function () {
|
|
15
|
+
return _Serializer.Serializer;
|
|
16
|
+
}
|
|
17
|
+
});
|
|
18
|
+
Object.defineProperty(exports, "SerializerDefault", {
|
|
19
|
+
enumerable: true,
|
|
20
|
+
get: function () {
|
|
21
|
+
return _Serializer.SerializerDefault;
|
|
22
|
+
}
|
|
23
|
+
});
|
|
24
|
+
Object.defineProperty(exports, "UnknownEventType", {
|
|
25
|
+
enumerable: true,
|
|
26
|
+
get: function () {
|
|
27
|
+
return _errors.UnknownEventType;
|
|
28
|
+
}
|
|
29
|
+
});
|
|
30
|
+
Object.defineProperty(exports, "Uuid", {
|
|
31
|
+
enumerable: true,
|
|
32
|
+
get: function () {
|
|
33
|
+
return _Uuid.Uuid;
|
|
34
|
+
}
|
|
35
|
+
});
|
|
36
|
+
Object.defineProperty(exports, "UuidLive", {
|
|
37
|
+
enumerable: true,
|
|
38
|
+
get: function () {
|
|
39
|
+
return _Uuid.UuidLive;
|
|
40
|
+
}
|
|
41
|
+
});
|
|
42
|
+
Object.defineProperty(exports, "UuidTest", {
|
|
43
|
+
enumerable: true,
|
|
44
|
+
get: function () {
|
|
45
|
+
return _Uuid.UuidTest;
|
|
46
|
+
}
|
|
47
|
+
});
|
|
48
|
+
Object.defineProperty(exports, "buildDecisionModel", {
|
|
49
|
+
enumerable: true,
|
|
50
|
+
get: function () {
|
|
51
|
+
return _decisionModel.buildDecisionModel;
|
|
52
|
+
}
|
|
53
|
+
});
|
|
54
|
+
Object.defineProperty(exports, "decider", {
|
|
55
|
+
enumerable: true,
|
|
56
|
+
get: function () {
|
|
57
|
+
return _decider.decider;
|
|
58
|
+
}
|
|
59
|
+
});
|
|
60
|
+
Object.defineProperty(exports, "decodeSlices", {
|
|
61
|
+
enumerable: true,
|
|
62
|
+
get: function () {
|
|
63
|
+
return _decode.decodeSlices;
|
|
64
|
+
}
|
|
65
|
+
});
|
|
66
|
+
Object.defineProperty(exports, "event", {
|
|
67
|
+
enumerable: true,
|
|
68
|
+
get: function () {
|
|
69
|
+
return _event.event;
|
|
70
|
+
}
|
|
71
|
+
});
|
|
72
|
+
Object.defineProperty(exports, "makeRegistry", {
|
|
73
|
+
enumerable: true,
|
|
74
|
+
get: function () {
|
|
75
|
+
return _registry.makeRegistry;
|
|
76
|
+
}
|
|
77
|
+
});
|
|
78
|
+
Object.defineProperty(exports, "modelAtHead", {
|
|
79
|
+
enumerable: true,
|
|
80
|
+
get: function () {
|
|
81
|
+
return _decisionModel.modelAtHead;
|
|
82
|
+
}
|
|
83
|
+
});
|
|
84
|
+
Object.defineProperty(exports, "projection", {
|
|
85
|
+
enumerable: true,
|
|
86
|
+
get: function () {
|
|
87
|
+
return _projection.projection;
|
|
88
|
+
}
|
|
89
|
+
});
|
|
90
|
+
Object.defineProperty(exports, "runDecider", {
|
|
91
|
+
enumerable: true,
|
|
92
|
+
get: function () {
|
|
93
|
+
return _decider.runDecider;
|
|
94
|
+
}
|
|
95
|
+
});
|
|
96
|
+
Object.defineProperty(exports, "toEvent", {
|
|
97
|
+
enumerable: true,
|
|
98
|
+
get: function () {
|
|
99
|
+
return _toEvent.toEvent;
|
|
100
|
+
}
|
|
101
|
+
});
|
|
102
|
+
var _decider = require("./decider.js");
|
|
103
|
+
var _decisionModel = require("./decisionModel.js");
|
|
104
|
+
var _decode = require("./decode.js");
|
|
105
|
+
var _errors = require("./errors.js");
|
|
106
|
+
var _event = require("./event.js");
|
|
107
|
+
var _projection = require("./projection.js");
|
|
108
|
+
var _registry = require("./registry.js");
|
|
109
|
+
var _Serializer = require("./Serializer.js");
|
|
110
|
+
var _toEvent = require("./toEvent.js");
|
|
111
|
+
var _Uuid = require("./Uuid.js");
|
|
112
|
+
//# sourceMappingURL=index.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"index.js","names":["_decider","require","_decisionModel","_decode","_errors","_event","_projection","_registry","_Serializer","_toEvent","_Uuid"],"sources":["../../src/index.ts"],"sourcesContent":[null],"mappings":";;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;AAqDA,IAAAA,QAAA,GAAAC,OAAA;AACA,IAAAC,cAAA,GAAAD,OAAA;AAKA,IAAAE,OAAA,GAAAF,OAAA;AACA,IAAAG,OAAA,GAAAH,OAAA;AACA,IAAAI,MAAA,GAAAJ,OAAA;AACA,IAAAK,WAAA,GAAAL,OAAA;AAKA,IAAAM,SAAA,GAAAN,OAAA;AACA,IAAAO,WAAA,GAAAP,OAAA;AACA,IAAAQ,QAAA,GAAAR,OAAA;AACA,IAAAS,KAAA,GAAAT,OAAA","ignoreList":[]}
|
|
@@ -0,0 +1,118 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
|
|
3
|
+
Object.defineProperty(exports, "__esModule", {
|
|
4
|
+
value: true
|
|
5
|
+
});
|
|
6
|
+
exports.projection = void 0;
|
|
7
|
+
var _core = require("@kairos-es/core");
|
|
8
|
+
/**
|
|
9
|
+
* The typed slice path (primary): a schema-backed projection and the fluent
|
|
10
|
+
* builder that produces it.
|
|
11
|
+
*
|
|
12
|
+
* A `SliceProjection<S, R>` is a core `AnyProjection<S>` (directly composable —
|
|
13
|
+
* its `evolve` folds a `DecodedEvent`) enriched with the `type -> Schema` map
|
|
14
|
+
* `decodeSlices` merges and decodes through. That map's value type carries `R`
|
|
15
|
+
* covariantly (`Schema<unknown, unknown, R>`), so the union of the defs'
|
|
16
|
+
* requirements flows to the decision model with no cast (and no phantom marker).
|
|
17
|
+
* Because `evolve` is already erased, a built slice drops straight into
|
|
18
|
+
* `composeProjections` — no `AnyProjection.of` ceremony.
|
|
19
|
+
*
|
|
20
|
+
* `projection(initialState).on(def, fold)...build()` infers the state `S` and
|
|
21
|
+
* the union `R` of the `.on`-ed defs' requirements, derives the read `Query`'s
|
|
22
|
+
* event-types from the defs' branded type literals (no `as EventType`), and
|
|
23
|
+
* hands each `fold` its decoded, typed payload. A handler for an un-imported
|
|
24
|
+
* event is therefore a compile error, and a mistyped type cannot silently match
|
|
25
|
+
* nothing.
|
|
26
|
+
*/
|
|
27
|
+
|
|
28
|
+
/**
|
|
29
|
+
* Start a slice for `initialState`. Returns a builder with no defs yet
|
|
30
|
+
* (`R = never`); each `.on(def, fold)` widens `R` by the def's requirement.
|
|
31
|
+
*/
|
|
32
|
+
const projection = initialState => {
|
|
33
|
+
// Persistent builder: `make` closes over the accumulated maps, and each
|
|
34
|
+
// `.on` copies them into a fresh builder rather than mutating in place, so
|
|
35
|
+
// no two derived builders ever share mutable state (reusing an intermediate
|
|
36
|
+
// builder can't cross-contaminate slices).
|
|
37
|
+
//
|
|
38
|
+
// `make` is generic in the accumulated requirement `R` — the parameter the
|
|
39
|
+
// builder is *about*. Pinning it to `never` and casting the result back would
|
|
40
|
+
// make the recursion typecheck by discarding the very thing each `.on` adds;
|
|
41
|
+
// threading `R` means the implementation states the same widening the
|
|
42
|
+
// `ProjectionBuilder` interface promises, and `on` returns without a cast.
|
|
43
|
+
const make = (schemas, folds) => ({
|
|
44
|
+
on: (def, fold) => {
|
|
45
|
+
// A repeated type WITHIN one chain is unambiguously a mistake, so this is
|
|
46
|
+
// a plain `has` rather than the reference-equality rule `mergeSliceSchemas`
|
|
47
|
+
// applies ACROSS slices. There, two entries for one type are the intended
|
|
48
|
+
// way to feed one event into two views, and the schemas being one object is
|
|
49
|
+
// what makes the collision harmless. Here there is only ever one fold per
|
|
50
|
+
// type — `evolve` dispatches by type into a single map — so a second `.on`
|
|
51
|
+
// cannot mean "as well as", only "instead of", and it silently discards
|
|
52
|
+
// the author's first fold along with its schema. The asymmetry is the
|
|
53
|
+
// point: the same `has` up there would outlaw the legitimate case.
|
|
54
|
+
if (schemas.has(def.type)) {
|
|
55
|
+
throw new Error(`duplicate event type '${def.type}' in slice: .on was called twice ` + 'for it, and the second fold would silently replace the first. ' + 'Handle both cases in one fold.');
|
|
56
|
+
}
|
|
57
|
+
// The entry type is annotated `R | R2` rather than inferred, and that
|
|
58
|
+
// annotation is what carries the requirement forward — `build` reads `R`
|
|
59
|
+
// straight off this map, so `RequirementOf` ultimately reads it from here.
|
|
60
|
+
// Widening the copied `R` entries into it costs nothing: `Schema` is
|
|
61
|
+
// declared `<in out A, in out I, out R>` upstream, hence covariant in its
|
|
62
|
+
// requirement.
|
|
63
|
+
const nextSchemas = new Map(schemas);
|
|
64
|
+
// Erasing `A`/`I` is the one unavoidable cast, and `as unknown as` is what
|
|
65
|
+
// it takes: `Schema` is INVARIANT in both, so `Schema<A, I, R2>` and
|
|
66
|
+
// `Schema<unknown, unknown, R2>` are unrelated in either direction. It is
|
|
67
|
+
// sound because the payload is only ever read back through `evolve`, which
|
|
68
|
+
// re-narrows by event type via the matching `fold`. The target names `R2`
|
|
69
|
+
// and not `never` because `R2` is what the def actually requires — an
|
|
70
|
+
// `Encrypted` field's `CipherKey` is not nothing — so the cast erases only
|
|
71
|
+
// what it has to and states the rest truthfully.
|
|
72
|
+
nextSchemas.set(def.type, def.schema);
|
|
73
|
+
const nextFolds = new Map(folds);
|
|
74
|
+
// Contravariance in the payload parameter, so this one is a cast too: the
|
|
75
|
+
// map holds folds over `unknown`, and `evolve` supplies the payload the
|
|
76
|
+
// matching def decoded, which is the `A` this fold was written against.
|
|
77
|
+
nextFolds.set(def.type, fold);
|
|
78
|
+
return make(nextSchemas, nextFolds);
|
|
79
|
+
},
|
|
80
|
+
build: options => {
|
|
81
|
+
// Internal-layer Query assembly from plain data (see core's Projection.ts
|
|
82
|
+
// note): a type-only-plus-optional-tags item the public surface withholds.
|
|
83
|
+
const types = [...schemas.keys()].map(t => _core.EventType.make(t));
|
|
84
|
+
const query = {
|
|
85
|
+
items: [{
|
|
86
|
+
types,
|
|
87
|
+
tags: options?.tags ?? []
|
|
88
|
+
}]
|
|
89
|
+
};
|
|
90
|
+
return {
|
|
91
|
+
initialState,
|
|
92
|
+
query,
|
|
93
|
+
// Defensive copy: hand out a fresh Map, not the builder's own. `schemas`
|
|
94
|
+
// is typed `ReadonlyMap`, but that is a compile-time guard only — a
|
|
95
|
+
// caller who casts it back to `Map` could otherwise mutate the slice's
|
|
96
|
+
// live decode table after `build`, desyncing it from `query` (whose
|
|
97
|
+
// event-types were snapshotted from these keys just above). The copy is
|
|
98
|
+
// cheap (a handful of keys) and makes the slice genuinely immutable.
|
|
99
|
+
schemas: new Map(schemas),
|
|
100
|
+
// Erased evolve: dispatch by the sequenced event's type to the matching
|
|
101
|
+
// fold over the decoded payload. Per the `AnyProjection.evolve` contract
|
|
102
|
+
// (core), a projection is only ever handed events matching its `query` —
|
|
103
|
+
// `composeProjections` gates each sub before dispatch — so this needs no
|
|
104
|
+
// second `matchesSequenced` check; the `fold === undefined` fallback is
|
|
105
|
+
// the honest total-function guard (evolve is typed over any DecodedEvent).
|
|
106
|
+
evolve: (state, decoded) => {
|
|
107
|
+
const fold = folds.get(decoded.sequenced.event.type);
|
|
108
|
+
return fold === undefined ? state : fold(state, decoded.payload);
|
|
109
|
+
}
|
|
110
|
+
};
|
|
111
|
+
}
|
|
112
|
+
});
|
|
113
|
+
// Explicit `never`: an empty `Map` literal gives inference nothing to read the
|
|
114
|
+
// requirement off, and "no defs yet" is exactly `never`, not `unknown`.
|
|
115
|
+
return make(new Map(), new Map());
|
|
116
|
+
};
|
|
117
|
+
exports.projection = projection;
|
|
118
|
+
//# sourceMappingURL=projection.js.map
|
|
@@ -0,0 +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,OAAgE,EAChEC,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;MACA;MACA;MACA;MACA;MACA;MACA,MAAME,WAAW,GAAG,IAAIC,GAAG,CAGzBT,OAAO,CAAC;MACV;MACA;MACA;MACA;MACA;MACA;MACA;MACA;MACAQ,WAAW,CAACE,GAAG,CACbP,GAAG,CAACG,IAAI,EACRH,GAAG,CAACQ,MAAwD,CAC7D;MACD,MAAMC,SAAS,GAAG,IAAIH,GAAG,CAACR,KAAK,CAAC;MAChC;MACA;MACA;MACAW,SAAS,CAACF,GAAG,CAACP,GAAG,CAACG,IAAI,EAAEF,IAAyC,CAAC;MAClE,OAAOL,IAAI,CAASS,WAAW,EAAEI,SAAS,CAAC;IAC7C,CAAC;IACDC,KAAK,EAAGC,OAAO,IAAI;MACjB;MACA;MACA,MAAMC,KAAK,GAAG,CAAC,GAAGf,OAAO,CAACgB,IAAI,EAAE,CAAC,CAACC,GAAG,CAAEC,CAAC,IAAKC,eAAS,CAACpB,IAAI,CAACmB,CAAC,CAAC,CAAC;MAC/D,MAAME,KAAK,GAAU;QACnBC,KAAK,EAAE,CAAC;UAAEN,KAAK;UAAEO,IAAI,EAAER,OAAO,EAAEQ,IAAI,IAAI;QAAE,CAAE;OAC7C;MACD,OAAO;QACLxB,YAAY;QACZsB,KAAK;QACL;QACA;QACA;QACA;QACA;QACA;QACApB,OAAO,EAAE,IAAIS,GAAG,CAACT,OAAO,CAAC;QACzB;QACA;QACA;QACA;QACA;QACA;QACAuB,MAAM,EAAEA,CAACC,KAAK,EAAEC,OAAqB,KAAI;UACvC,MAAMrB,IAAI,GAAGH,KAAK,CAACyB,GAAG,CAACD,OAAO,CAACE,SAAS,CAACC,KAAK,CAACtB,IAAI,CAAC;UACpD,OAAOF,IAAI,KAAKyB,SAAS,GAAGL,KAAK,GAAGpB,IAAI,CAACoB,KAAU,EAAEC,OAAO,CAACK,OAAO,CAAC;QACvE;OACD;IACH;GACD,CAAC;EACF;EACA;EACA,OAAO/B,IAAI,CAAQ,IAAIU,GAAG,EAAE,EAAE,IAAIA,GAAG,EAAE,CAAC;AAC1C,CAAC;AAAAsB,OAAA,CAAAlC,UAAA,GAAAA,UAAA","ignoreList":[]}
|
|
@@ -0,0 +1,41 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
|
|
3
|
+
Object.defineProperty(exports, "__esModule", {
|
|
4
|
+
value: true
|
|
5
|
+
});
|
|
6
|
+
exports.makeRegistry = void 0;
|
|
7
|
+
var _effect = require("effect");
|
|
8
|
+
var _deserialiseThenDecode = require("./deserialiseThenDecode.js");
|
|
9
|
+
var _errors = require("./errors.js");
|
|
10
|
+
var _Serializer = require("./Serializer.js");
|
|
11
|
+
const makeRegistry = defs => {
|
|
12
|
+
const map = new Map();
|
|
13
|
+
for (const def of defs) {
|
|
14
|
+
if (map.has(def.type)) {
|
|
15
|
+
throw new Error(`duplicate event type '${def.type}' in registry`);
|
|
16
|
+
}
|
|
17
|
+
map.set(def.type, def.schema);
|
|
18
|
+
}
|
|
19
|
+
return {
|
|
20
|
+
decode: event => _effect.Effect.gen(function* () {
|
|
21
|
+
const schema = map.get(event.type);
|
|
22
|
+
if (schema === undefined) {
|
|
23
|
+
return yield* _effect.Effect.fail(new _errors.UnknownEventType({
|
|
24
|
+
type: event.type
|
|
25
|
+
}));
|
|
26
|
+
}
|
|
27
|
+
const serializer = yield* _Serializer.Serializer;
|
|
28
|
+
const payload = yield* (0, _deserialiseThenDecode.deserialiseThenDecode)(serializer, schema, event.data);
|
|
29
|
+
return {
|
|
30
|
+
type: event.type,
|
|
31
|
+
payload
|
|
32
|
+
};
|
|
33
|
+
// The schema map erases `R` to `unknown`; the declared `R` is recovered
|
|
34
|
+
// from `Defs` at the type level, so the gen block's inferred requirement
|
|
35
|
+
// (`unknown`) is re-stated as `Serializer | R` here, which is this
|
|
36
|
+
// module's only cast.
|
|
37
|
+
})
|
|
38
|
+
};
|
|
39
|
+
};
|
|
40
|
+
exports.makeRegistry = makeRegistry;
|
|
41
|
+
//# sourceMappingURL=registry.js.map
|
|
@@ -0,0 +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,EAAoD;EACvE,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":[]}
|
|
@@ -0,0 +1,51 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
|
|
3
|
+
Object.defineProperty(exports, "__esModule", {
|
|
4
|
+
value: true
|
|
5
|
+
});
|
|
6
|
+
exports.toEvent = void 0;
|
|
7
|
+
var _effect = require("effect");
|
|
8
|
+
var _errors = require("./errors.js");
|
|
9
|
+
var _Serializer = require("./Serializer.js");
|
|
10
|
+
var _Uuid = require("./Uuid.js");
|
|
11
|
+
/**
|
|
12
|
+
* Encode `payload` under `def` and stamp it into a wire `DcbEvent`, deriving its
|
|
13
|
+
* `tags` from `def.tagsFor(payload)` (a throwing mapper surfaces as a
|
|
14
|
+
* `CodecError`, not a defect). The tags are stamped exactly as the mapper
|
|
15
|
+
* returns them — no dedup or reordering. `type` and `tags` are cleartext
|
|
16
|
+
* wire-envelope fields (the query surface), so a `tagsFor` mapper may only key
|
|
17
|
+
* off cleartext payload fields (ADR-0006). `uuid` / `occurredAt` are
|
|
18
|
+
* exact-optional overrides; absent, they come from the `Uuid` service and the
|
|
19
|
+
* Effect clock.
|
|
20
|
+
*/
|
|
21
|
+
const toEvent = (def, payload, options) => _effect.Effect.gen(function* () {
|
|
22
|
+
// Derive tags first. A mapper is app code that can throw (e.g. `Tag.make`
|
|
23
|
+
// rejects an ill-formed `key:value`), and the codec's contract is that such
|
|
24
|
+
// failures are values on the `CodecError` channel, never defects (errors.ts).
|
|
25
|
+
// Deriving before the uuid/clock effects also means a bad tag fails without
|
|
26
|
+
// consuming the `Uuid` sequence.
|
|
27
|
+
const tags = yield* _effect.Effect.try({
|
|
28
|
+
try: () => def.tagsFor(payload),
|
|
29
|
+
catch: cause => new _errors.CodecError({
|
|
30
|
+
reason: 'tags',
|
|
31
|
+
cause
|
|
32
|
+
})
|
|
33
|
+
});
|
|
34
|
+
const serializer = yield* _Serializer.Serializer;
|
|
35
|
+
const encoded = yield* _effect.Schema.encode(def.schema)(payload).pipe(_effect.Effect.mapError(cause => new _errors.CodecError({
|
|
36
|
+
reason: 'encode',
|
|
37
|
+
cause
|
|
38
|
+
})));
|
|
39
|
+
const data = serializer.serialise(encoded);
|
|
40
|
+
const uuid = options?.uuid ?? (yield* (yield* _Uuid.Uuid).generate);
|
|
41
|
+
const occurredAt = options?.occurredAt ?? (yield* _effect.DateTime.now);
|
|
42
|
+
return {
|
|
43
|
+
type: def.type,
|
|
44
|
+
data,
|
|
45
|
+
tags,
|
|
46
|
+
uuid,
|
|
47
|
+
occurredAt
|
|
48
|
+
};
|
|
49
|
+
});
|
|
50
|
+
exports.toEvent = toEvent;
|
|
51
|
+
//# sourceMappingURL=toEvent.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"toEvent.js","names":["_effect","require","_errors","_Serializer","_Uuid","toEvent","def","payload","options","Effect","gen","tags","try","tagsFor","catch","cause","CodecError","reason","serializer","Serializer","encoded","Schema","encode","schema","pipe","mapError","data","serialise","uuid","Uuid","generate","occurredAt","DateTime","now","type","exports"],"sources":["../../src/toEvent.ts"],"sourcesContent":[null],"mappings":";;;;;;AAcA,IAAAA,OAAA,GAAAC,OAAA;AACA,IAAAC,OAAA,GAAAD,OAAA;AAEA,IAAAE,WAAA,GAAAF,OAAA;AACA,IAAAG,KAAA,GAAAH,OAAA;AAEA;;;;;;;;;;AAUO,MAAMI,OAAO,GAAGA,CACrBC,GAAsB,EACtBC,OAAU,EACVC,OAGC,KAEDC,cAAM,CAACC,GAAG,CAAC,aAAS;EAClB;EACA;EACA;EACA;EACA;EACA,MAAMC,IAAI,GAAG,OAAOF,cAAM,CAACG,GAAG,CAAC;IAC7BA,GAAG,EAAEA,CAAA,KAAMN,GAAG,CAACO,OAAO,CAACN,OAAO,CAAC;IAC/BO,KAAK,EAAGC,KAAK,IAAK,IAAIC,kBAAU,CAAC;MAAEC,MAAM,EAAE,MAAM;MAAEF;IAAK,CAAE;GAC3D,CAAC;EACF,MAAMG,UAAU,GAAG,OAAOC,sBAAU;EACpC,MAAMC,OAAO,GAAG,OAAOC,cAAM,CAACC,MAAM,CAAChB,GAAG,CAACiB,MAAM,CAAC,CAAChB,OAAO,CAAC,CAACiB,IAAI,CAC5Df,cAAM,CAACgB,QAAQ,CAAEV,KAAK,IAAK,IAAIC,kBAAU,CAAC;IAAEC,MAAM,EAAE,QAAQ;IAAEF;EAAK,CAAE,CAAC,CAAC,CACxE;EACD,MAAMW,IAAI,GAAGR,UAAU,CAACS,SAAS,CAACP,OAAO,CAAC;EAC1C,MAAMQ,IAAI,GAAGpB,OAAO,EAAEoB,IAAI,KAAK,OAAO,CAAC,OAAOC,UAAI,EAAEC,QAAQ,CAAC;EAC7D,MAAMC,UAAU,GAAGvB,OAAO,EAAEuB,UAAU,KAAK,OAAOC,gBAAQ,CAACC,GAAG,CAAC;EAC/D,OAAO;IACLC,IAAI,EAAE5B,GAAG,CAAC4B,IAAI;IACdR,IAAI;IACJf,IAAI;IACJiB,IAAI;IACJG;GACD;AACH,CAAC,CAAC;AAAAI,OAAA,CAAA9B,OAAA,GAAAA,OAAA","ignoreList":[]}
|
|
@@ -0,0 +1,27 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* The pluggable serialiser: the `Uint8Array` <-> value boundary applied
|
|
3
|
+
* *outside* `Schema`. Encode is `Schema.encode` then `serialise`; decode is
|
|
4
|
+
* `deserialise` then `Schema.decodeUnknown`. Both codec paths read the same
|
|
5
|
+
* `Serializer` from context, so encode and decode cannot mismatch; swapping
|
|
6
|
+
* JSON for msgpack is a different layer with no schema or call-site changes.
|
|
7
|
+
*
|
|
8
|
+
* `deserialise` may throw synchronously (corrupt bytes): wrapping it as a
|
|
9
|
+
* `CodecError` is the *caller's* concern — every decode site wraps it in
|
|
10
|
+
* `Effect.try`. Keeping the service interface plain (no Effect) lets a layer be
|
|
11
|
+
* a trivial `Layer.succeed`.
|
|
12
|
+
*/
|
|
13
|
+
import { Context, Layer } from 'effect';
|
|
14
|
+
declare const Serializer_base: Context.TagClass<Serializer, "@kairos-es/codec/Serializer", {
|
|
15
|
+
readonly serialise: (v: unknown) => Uint8Array;
|
|
16
|
+
readonly deserialise: (b: Uint8Array) => unknown;
|
|
17
|
+
}>;
|
|
18
|
+
export declare class Serializer extends Serializer_base {
|
|
19
|
+
}
|
|
20
|
+
/**
|
|
21
|
+
* The shipped default: JSON over UTF-8. `serialise` = `JSON.stringify` then
|
|
22
|
+
* `TextEncoder`; `deserialise` = `TextDecoder` then `JSON.parse` (which throws
|
|
23
|
+
* synchronously on corrupt bytes, wrapped to `CodecError` at the call site).
|
|
24
|
+
*/
|
|
25
|
+
export declare const SerializerDefault: Layer.Layer<Serializer>;
|
|
26
|
+
export {};
|
|
27
|
+
//# sourceMappingURL=Serializer.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"Serializer.d.ts","sourceRoot":"","sources":["../../src/Serializer.ts"],"names":[],"mappings":"AAAA;;;;;;;;;;;GAWG;AACH,OAAO,EAAE,OAAO,EAAE,KAAK,EAAE,MAAM,QAAQ,CAAA;;wBAKf,CAAC,CAAC,EAAE,OAAO,KAAK,UAAU;0BACxB,CAAC,CAAC,EAAE,UAAU,KAAK,OAAO;;AAJpD,qBAAa,UAAW,SAAQ,eAM7B;CAAG;AAKN;;;;GAIG;AACH,eAAO,MAAM,iBAAiB,EAAE,KAAK,CAAC,KAAK,CAAC,UAAU,CAMrD,CAAA"}
|
|
@@ -0,0 +1,19 @@
|
|
|
1
|
+
import { Context, Effect, Layer } from 'effect';
|
|
2
|
+
declare const Uuid_base: Context.TagClass<Uuid, "@kairos-es/codec/Uuid", {
|
|
3
|
+
readonly generate: Effect.Effect<string>;
|
|
4
|
+
}>;
|
|
5
|
+
export declare class Uuid extends Uuid_base {
|
|
6
|
+
}
|
|
7
|
+
/** Live uuid generation via WebCrypto (no `node:crypto`). */
|
|
8
|
+
export declare const UuidLive: Layer.Layer<Uuid>;
|
|
9
|
+
/**
|
|
10
|
+
* A deterministic uuid layer for suites, wrapping core's shared
|
|
11
|
+
* `makeSequentialUuid` (the single source of truth for the counter scheme).
|
|
12
|
+
* Each layer instance builds a fresh generator, so it owns its own counter and
|
|
13
|
+
* yields a stable v4-shaped sequence `00000000-0000-4000-8000-<12 hex>` starting
|
|
14
|
+
* at `...000000000000`. Generation is wrapped in `Effect.sync` because the
|
|
15
|
+
* generator advances its counter (a side effect on each call).
|
|
16
|
+
*/
|
|
17
|
+
export declare const UuidTest: Layer.Layer<Uuid>;
|
|
18
|
+
export {};
|
|
19
|
+
//# sourceMappingURL=Uuid.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"Uuid.d.ts","sourceRoot":"","sources":["../../src/Uuid.ts"],"names":[],"mappings":"AAYA,OAAO,EAAE,OAAO,EAAE,MAAM,EAAE,KAAK,EAAE,MAAM,QAAQ,CAAA;;uBAIxB,MAAM,CAAC,MAAM,CAAC,MAAM,CAAC;;AAF5C,qBAAa,IAAK,SAAQ,SAGvB;CAAG;AAEN,6DAA6D;AAC7D,eAAO,MAAM,QAAQ,EAAE,KAAK,CAAC,KAAK,CAAC,IAAI,CAErC,CAAA;AAEF;;;;;;;GAOG;AACH,eAAO,MAAM,QAAQ,EAAE,KAAK,CAAC,KAAK,CAAC,IAAI,CAGrC,CAAA"}
|