@kairos-es/core 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 +3 -3
- package/dist/cjs/AppendCondition.js +1 -3
- package/dist/cjs/AppendCondition.js.map +1 -1
- package/dist/cjs/AppendIsOwned.js +6 -6
- package/dist/cjs/AppendIsOwned.js.map +1 -1
- package/dist/cjs/ContractStore.js +13 -4
- package/dist/cjs/ContractStore.js.map +1 -1
- package/dist/cjs/DcbEventStore.js +1 -1
- package/dist/cjs/DcbEventStore.js.map +1 -1
- package/dist/cjs/Event.js +87 -11
- package/dist/cjs/Event.js.map +1 -1
- package/dist/cjs/Projection.js +15 -9
- package/dist/cjs/Projection.js.map +1 -1
- package/dist/cjs/Query.js +59 -3
- package/dist/cjs/Query.js.map +1 -1
- package/dist/cjs/SubscribeMachine.js +20 -22
- package/dist/cjs/SubscribeMachine.js.map +1 -1
- package/dist/cjs/inMemory.js +113 -43
- package/dist/cjs/inMemory.js.map +1 -1
- package/dist/cjs/retryOnConflict.js +4 -10
- package/dist/cjs/retryOnConflict.js.map +1 -1
- package/dist/cjs/testing.js +2 -2
- package/dist/cjs/testing.js.map +1 -1
- package/dist/{dts → dts-cjs}/AppendCondition.d.ts +5 -7
- package/dist/{dts → dts-cjs}/AppendCondition.d.ts.map +1 -1
- package/dist/{dts → dts-cjs}/AppendIsOwned.d.ts +6 -6
- package/dist/{dts → dts-cjs}/AppendIsOwned.d.ts.map +1 -1
- package/dist/{dts → dts-cjs}/ContractStore.d.ts +7 -4
- package/dist/dts-cjs/ContractStore.d.ts.map +1 -0
- package/dist/{dts → dts-cjs}/DcbEventStore.d.ts +2 -2
- package/dist/{dts → dts-cjs}/DcbEventStore.d.ts.map +1 -1
- package/dist/dts-cjs/Event.d.ts +174 -0
- package/dist/dts-cjs/Event.d.ts.map +1 -0
- package/dist/{dts → dts-cjs}/Projection.d.ts +1 -1
- package/dist/{dts → dts-cjs}/Projection.d.ts.map +1 -1
- package/dist/{dts → dts-cjs}/Query.d.ts +19 -5
- package/dist/dts-cjs/Query.d.ts.map +1 -0
- package/dist/{dts → dts-cjs}/SubscribeMachine.d.ts +11 -15
- package/dist/dts-cjs/SubscribeMachine.d.ts.map +1 -0
- package/dist/{dts → dts-cjs}/inMemory.d.ts.map +1 -1
- package/dist/{dts → dts-cjs}/index.d.ts +1 -1
- package/dist/dts-cjs/package.json +3 -0
- package/dist/{dts → dts-cjs}/retryOnConflict.d.ts +1 -7
- package/dist/dts-cjs/retryOnConflict.d.ts.map +1 -0
- package/dist/{dts → dts-cjs}/testing.d.ts +1 -1
- package/dist/dts-esm/AppendCondition.d.ts +21 -0
- package/dist/dts-esm/AppendCondition.d.ts.map +1 -0
- package/dist/dts-esm/AppendIsOwned.d.ts +78 -0
- package/dist/dts-esm/AppendIsOwned.d.ts.map +1 -0
- package/dist/dts-esm/ContractStore.d.ts +62 -0
- package/dist/dts-esm/ContractStore.d.ts.map +1 -0
- package/dist/dts-esm/DcbEventStore.d.ts +64 -0
- package/dist/dts-esm/DcbEventStore.d.ts.map +1 -0
- package/dist/dts-esm/Event.d.ts +174 -0
- package/dist/dts-esm/Event.d.ts.map +1 -0
- package/dist/dts-esm/Projection.d.ts +124 -0
- package/dist/dts-esm/Projection.d.ts.map +1 -0
- package/dist/dts-esm/Query.d.ts +180 -0
- package/dist/dts-esm/Query.d.ts.map +1 -0
- package/dist/dts-esm/SubscribeMachine.d.ts +175 -0
- package/dist/dts-esm/SubscribeMachine.d.ts.map +1 -0
- package/dist/dts-esm/errors.d.ts +17 -0
- package/dist/dts-esm/errors.d.ts.map +1 -0
- package/dist/dts-esm/inMemory.d.ts +76 -0
- package/dist/dts-esm/inMemory.d.ts.map +1 -0
- package/dist/dts-esm/index.d.ts +40 -0
- package/dist/dts-esm/index.d.ts.map +1 -0
- package/dist/dts-esm/package.json +3 -0
- package/dist/dts-esm/retryOnConflict.d.ts +64 -0
- package/dist/dts-esm/retryOnConflict.d.ts.map +1 -0
- package/dist/dts-esm/testing.d.ts +39 -0
- package/dist/dts-esm/testing.d.ts.map +1 -0
- package/dist/esm/AppendCondition.js +1 -3
- package/dist/esm/AppendCondition.js.map +1 -1
- package/dist/esm/AppendIsOwned.js +6 -6
- package/dist/esm/AppendIsOwned.js.map +1 -1
- package/dist/esm/ContractStore.js +13 -4
- package/dist/esm/ContractStore.js.map +1 -1
- package/dist/esm/DcbEventStore.js +1 -1
- package/dist/esm/DcbEventStore.js.map +1 -1
- package/dist/esm/Event.js +87 -11
- package/dist/esm/Event.js.map +1 -1
- package/dist/esm/Projection.js +15 -9
- package/dist/esm/Projection.js.map +1 -1
- package/dist/esm/Query.js +56 -1
- package/dist/esm/Query.js.map +1 -1
- package/dist/esm/SubscribeMachine.js +21 -23
- package/dist/esm/SubscribeMachine.js.map +1 -1
- package/dist/esm/inMemory.js +114 -44
- package/dist/esm/inMemory.js.map +1 -1
- package/dist/esm/index.js +1 -1
- package/dist/esm/retryOnConflict.js +4 -10
- package/dist/esm/retryOnConflict.js.map +1 -1
- package/dist/esm/testing.js +2 -2
- package/dist/esm/testing.js.map +1 -1
- package/package.json +21 -11
- package/src/AppendCondition.ts +1 -1
- package/src/AppendIsOwned.ts +7 -7
- package/src/ContractStore.ts +25 -8
- package/src/DcbEventStore.ts +3 -3
- package/src/Event.ts +108 -11
- package/src/Projection.ts +19 -8
- package/src/Query.ts +74 -1
- package/src/SubscribeMachine.ts +38 -31
- package/src/inMemory.ts +123 -51
- package/src/index.ts +1 -1
- package/src/retryOnConflict.ts +6 -11
- package/src/testing.ts +2 -2
- package/testing/package.json +1 -1
- package/dist/dts/ContractStore.d.ts.map +0 -1
- package/dist/dts/Event.d.ts +0 -104
- package/dist/dts/Event.d.ts.map +0 -1
- package/dist/dts/Query.d.ts.map +0 -1
- package/dist/dts/SubscribeMachine.d.ts.map +0 -1
- package/dist/dts/retryOnConflict.d.ts.map +0 -1
- /package/dist/{dts → dts-cjs}/errors.d.ts +0 -0
- /package/dist/{dts → dts-cjs}/errors.d.ts.map +0 -0
- /package/dist/{dts → dts-cjs}/inMemory.d.ts +0 -0
- /package/dist/{dts → dts-cjs}/index.d.ts.map +0 -0
- /package/dist/{dts → dts-cjs}/testing.d.ts.map +0 -0
package/dist/esm/Event.js
CHANGED
|
@@ -6,17 +6,34 @@
|
|
|
6
6
|
* payloads into these bytes. Ordering is by `position` alone; `occurredAt` is
|
|
7
7
|
* producer-supplied domain time and is informational only.
|
|
8
8
|
*/
|
|
9
|
-
import { Schema } from 'effect';
|
|
9
|
+
import { BigInt as BigInt_, Effect, Option, Schema, SchemaIssue, SchemaTransformation } from 'effect';
|
|
10
10
|
/**
|
|
11
11
|
* A position in the single global event log: a branded, non-negative `bigint`.
|
|
12
12
|
*
|
|
13
13
|
* The log is 64-bit (`bigserial` in Postgres) and exceeds JS `number` safety at
|
|
14
14
|
* 2^53, so positions are a `bigint`. They are compared, never arithmetic'd.
|
|
15
|
-
*
|
|
15
|
+
* Encoded, a position is a decimal string (JSON-safe, `String(b)`); decoded, a
|
|
16
16
|
* `bigint`. `0n` is the "before the first event" sentinel used by `after` and by
|
|
17
17
|
* an empty store's head.
|
|
18
|
+
*
|
|
19
|
+
* The string-to-`bigint` step is hand-built rather than Effect 4's
|
|
20
|
+
* `Schema.BigIntFromString`, because that schema accepts only `^-?\d+$` and so
|
|
21
|
+
* refuses inputs the encoded side has always admitted — `" 5"`, `"+5"`,
|
|
22
|
+
* `"0x10"`. The decode here is the global `BigInt(s)` behind a blank-string
|
|
23
|
+
* refusal, which is `BigInt.fromString` and is exactly what Effect 3's
|
|
24
|
+
* `Schema.BigInt` ran, so a position string any earlier release decoded still
|
|
25
|
+
* decodes to the same value. The non-negative check then runs on the `bigint`,
|
|
26
|
+
* as it always did.
|
|
18
27
|
*/
|
|
19
|
-
export const Position = /*#__PURE__*/Schema.
|
|
28
|
+
export const Position = /*#__PURE__*/Schema.String.pipe(/*#__PURE__*/Schema.decodeTo(Schema.BigInt, /*#__PURE__*/SchemaTransformation.transformEffect({
|
|
29
|
+
decode: (s, options) => Option.match(BigInt_.fromString(s), {
|
|
30
|
+
onNone: () => Effect.fail(new SchemaIssue.InvalidValue({
|
|
31
|
+
message: `Unable to decode ${JSON.stringify(s)} into a bigint`
|
|
32
|
+
}, s, options)),
|
|
33
|
+
onSome: Effect.succeed
|
|
34
|
+
}),
|
|
35
|
+
encode: b => Effect.succeed(String(b))
|
|
36
|
+
})), /*#__PURE__*/Schema.check(/*#__PURE__*/Schema.isGreaterThanOrEqualToBigInt(0n)), /*#__PURE__*/Schema.brand('Position'));
|
|
20
37
|
/** The sentinel position meaning "before the first event". */
|
|
21
38
|
export const ORIGIN = /*#__PURE__*/Position.make(0n);
|
|
22
39
|
/**
|
|
@@ -25,9 +42,9 @@ export const ORIGIN = /*#__PURE__*/Position.make(0n);
|
|
|
25
42
|
* event sourcing; a query matches an event when the event carries all of an
|
|
26
43
|
* item's tags (superset test).
|
|
27
44
|
*/
|
|
28
|
-
export const Tag = /*#__PURE__*/Schema.String.pipe(/*#__PURE__*/Schema.
|
|
45
|
+
export const Tag = /*#__PURE__*/Schema.String.pipe(/*#__PURE__*/Schema.check(/*#__PURE__*/Schema.isPattern(/^[^:]+:.+/, {
|
|
29
46
|
identifier: 'Tag'
|
|
30
|
-
}), /*#__PURE__*/Schema.brand('Tag'));
|
|
47
|
+
})), /*#__PURE__*/Schema.brand('Tag'));
|
|
31
48
|
export const tagIdentity = key => {
|
|
32
49
|
if (key.length === 0 || key.includes(':')) {
|
|
33
50
|
throw new Error(`tagIdentity: key must be non-empty and contain no ':' (got ${JSON.stringify(key)})`);
|
|
@@ -52,26 +69,85 @@ export const tagIdentity = key => {
|
|
|
52
69
|
* error channel (`read` keeps `E = never`). Constructed at call sites with
|
|
53
70
|
* `ReadLimit.make(n)`.
|
|
54
71
|
*/
|
|
55
|
-
export const ReadLimit = /*#__PURE__*/Schema.Int.pipe(/*#__PURE__*/Schema.
|
|
72
|
+
export const ReadLimit = /*#__PURE__*/Schema.Int.pipe(/*#__PURE__*/Schema.check(/*#__PURE__*/Schema.isGreaterThanOrEqualTo(0)), /*#__PURE__*/Schema.brand('ReadLimit'));
|
|
56
73
|
/**
|
|
57
74
|
* An event type name, a branded non-empty string. Versioning is by convention
|
|
58
75
|
* in the name (e.g. `course-registered.v2`); only non-emptiness is enforced.
|
|
59
76
|
*/
|
|
60
|
-
export const EventType = /*#__PURE__*/Schema.String.pipe(/*#__PURE__*/Schema.
|
|
77
|
+
export const EventType = /*#__PURE__*/Schema.String.pipe(/*#__PURE__*/Schema.check(/*#__PURE__*/Schema.isNonEmpty()), /*#__PURE__*/Schema.brand('EventType'));
|
|
78
|
+
/**
|
|
79
|
+
* An event's metadata: a flat bag of strings carrying the circumstances under
|
|
80
|
+
* which the event was RECORDED, never anything the business asserts (ADR-0017).
|
|
81
|
+
* Payload is what happened; metadata is the context of the recording — a
|
|
82
|
+
* `traceparent`, a correlation or causation id, a deployment revision.
|
|
83
|
+
*
|
|
84
|
+
* Values are strings, not `unknown`, for cross-engine parity rather than taste:
|
|
85
|
+
* both SQL engines carry the bag as a JSON document, and `JSON.stringify` drops
|
|
86
|
+
* `undefined`, throws on `bigint` and turns `NaN` into `null`, none of which the
|
|
87
|
+
* in-memory oracle does.
|
|
88
|
+
*
|
|
89
|
+
* The key schema carries no refinement, deliberately: a refinement on a
|
|
90
|
+
* `Schema.Record` key acts as a FILTER on decode, silently dropping a key that
|
|
91
|
+
* fails it rather than failing the decode. Constraining keys, if ever wanted,
|
|
92
|
+
* has to be a validating step of its own.
|
|
93
|
+
*
|
|
94
|
+
* Two engine limits a consumer must know, because the bag is typically filled
|
|
95
|
+
* from outside the application at a request edge. Postgres refuses a NUL
|
|
96
|
+
* character (U+0000) and an unpaired surrogate in any string it stores, so an
|
|
97
|
+
* event whose bag holds one fails to append there while the in-memory and
|
|
98
|
+
* SQLite engines accept it; sanitise untrusted values before they reach the
|
|
99
|
+
* bag. And key ORDER is not preserved: Postgres stores an object's keys in an
|
|
100
|
+
* order of its own, so compare bags as unordered and never rely on the order
|
|
101
|
+
* `Object.keys` returns.
|
|
102
|
+
*
|
|
103
|
+
* Metadata is never part of a `Query` or an `AppendCondition` — a store refuses
|
|
104
|
+
* either when it carries a key the grammar does not define, so a metadata
|
|
105
|
+
* predicate cannot be written and silently ignored — never reaches a codec's
|
|
106
|
+
* `tagsFor`, and no store offers a way to rewrite it once appended. ADR-0017
|
|
107
|
+
* owns why each of those is mechanical rather than preferential.
|
|
108
|
+
*
|
|
109
|
+
* ## The one home of the shape rule
|
|
110
|
+
*
|
|
111
|
+
* The bag is a JSON OBJECT whose every value is a STRING, and this schema is
|
|
112
|
+
* where that rule is stated. At runtime it is checked in ONE place, at write: the
|
|
113
|
+
* codec's `toEvent` decodes every bag through this schema and refuses one that
|
|
114
|
+
* fails on its own error channel, so a value smuggled past the type (through an
|
|
115
|
+
* `any`) stops there. The schema judges a bag's OWN enumerable keys, so an object
|
|
116
|
+
* that keeps its entries anywhere else — a `Map`, a `Date` — reads as the empty
|
|
117
|
+
* bag rather than failing. A store checks no values: an event built by hand and handed
|
|
118
|
+
* to `append` directly carries whatever it carries, and what each engine then does
|
|
119
|
+
* with a non-string value differs — one may store it and read it back differently
|
|
120
|
+
* from another, and a `bigint` makes a SQL engine's append fail. Each
|
|
121
|
+
* SQL engine keeps a container check of its own on read — the column must hold a
|
|
122
|
+
* JSON object — because that defends against a writer outside the library and is
|
|
123
|
+
* about the column, not the values. A VALUE check must never be added on read
|
|
124
|
+
* alone: it would make an event the store accepted unreadable for ever, so a
|
|
125
|
+
* value check belongs at write or nowhere.
|
|
126
|
+
*/
|
|
127
|
+
export const Metadata = /*#__PURE__*/Schema.Record(Schema.String, Schema.String);
|
|
61
128
|
/**
|
|
62
129
|
* An event as stored: an opaque payload plus its type, tags, a
|
|
63
|
-
* producer-supplied `uuid`,
|
|
130
|
+
* producer-supplied `uuid`, producer-supplied `occurredAt` domain time, and its
|
|
131
|
+
* `metadata` bag.
|
|
64
132
|
*
|
|
65
133
|
* `data` is `Uint8Array` (opaque bytes); the store does not interpret it.
|
|
66
134
|
* `uuid` is producer-supplied to keep `core` deterministic (no RNG in core).
|
|
135
|
+
* It is checked for UUID SHAPE only (`isGUID`), not for a version nibble: a
|
|
136
|
+
* stricter check would refuse ids an existing log already holds.
|
|
67
137
|
* `occurredAt` is informational only; ordering is by position alone.
|
|
138
|
+
* `metadata` mirrors `tags` rather than `data`: REQUIRED, with an empty bag
|
|
139
|
+
* legal. Required because an absent-versus-empty divergence between engines is
|
|
140
|
+
* invisible to `toEqual`, which ignores `undefined` properties, so an optional
|
|
141
|
+
* field could drift across the three engines with the round-trip suite green.
|
|
142
|
+
* Core only carries it; the codec's `toEvent` is where it is resolved.
|
|
68
143
|
*/
|
|
69
144
|
export const DcbEvent = /*#__PURE__*/Schema.Struct({
|
|
70
145
|
type: EventType,
|
|
71
|
-
data: Schema.
|
|
146
|
+
data: Schema.Uint8Array,
|
|
72
147
|
tags: /*#__PURE__*/Schema.Array(Tag),
|
|
73
|
-
uuid: Schema.
|
|
74
|
-
occurredAt: Schema.
|
|
148
|
+
uuid: /*#__PURE__*/Schema.String.check(/*#__PURE__*/Schema.isGUID()),
|
|
149
|
+
occurredAt: Schema.DateTimeUtcFromString,
|
|
150
|
+
metadata: Metadata
|
|
75
151
|
});
|
|
76
152
|
/** A persisted event: the event together with the position it was written at. */
|
|
77
153
|
export const SequencedEvent = /*#__PURE__*/Schema.Struct({
|
package/dist/esm/Event.js.map
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"Event.js","names":["Schema","Position","
|
|
1
|
+
{"version":3,"file":"Event.js","names":["BigInt","BigInt_","Effect","Option","Schema","SchemaIssue","SchemaTransformation","Position","String","pipe","decodeTo","transformEffect","decode","s","options","match","fromString","onNone","fail","InvalidValue","message","JSON","stringify","onSome","succeed","encode","b","check","isGreaterThanOrEqualToBigInt","brand","ORIGIN","make","Tag","isPattern","identifier","tagIdentity","key","length","includes","Error","value","ReadLimit","Int","isGreaterThanOrEqualTo","EventType","isNonEmpty","Metadata","Record","DcbEvent","Struct","type","data","Uint8Array","tags","Array","uuid","isGUID","occurredAt","DateTimeUtcFromString","metadata","SequencedEvent","event","position"],"sources":["../../src/Event.ts"],"sourcesContent":[null],"mappings":"AAAA;;;;;;;;AAQA,SACEA,MAAM,IAAIC,OAAO,EACjBC,MAAM,EACNC,MAAM,EACNC,MAAM,EACNC,WAAW,EACXC,oBAAoB,QACf,QAAQ;AAEf;;;;;;;;;;;;;;;;;;AAkBA,OAAO,MAAMC,QAAQ,gBAAGH,MAAM,CAACI,MAAM,CAACC,IAAI,cACxCL,MAAM,CAACM,QAAQ,CACbN,MAAM,CAACJ,MAAM,eACbM,oBAAoB,CAACK,eAAe,CAAiB;EACnDC,MAAM,EAAEA,CAACC,CAAC,EAAEC,OAAO,KACjBX,MAAM,CAACY,KAAK,CAACd,OAAO,CAACe,UAAU,CAACH,CAAC,CAAC,EAAE;IAClCI,MAAM,EAAEA,CAAA,KACNf,MAAM,CAACgB,IAAI,CACT,IAAIb,WAAW,CAACc,YAAY,CAC1B;MACEC,OAAO,EAAE,oBAAoBC,IAAI,CAACC,SAAS,CAACT,CAAC,CAAC;KAC/C,EACDA,CAAC,EACDC,OAAO,CACR,CACF;IACHS,MAAM,EAAErB,MAAM,CAACsB;GAChB,CAAC;EACJC,MAAM,EAAGC,CAAC,IAAKxB,MAAM,CAACsB,OAAO,CAAChB,MAAM,CAACkB,CAAC,CAAC;CACxC,CAAC,CACH,eACDtB,MAAM,CAACuB,KAAK,cAACvB,MAAM,CAACwB,4BAA4B,CAAC,EAAE,CAAC,CAAC,eACrDxB,MAAM,CAACyB,KAAK,CAAC,UAAU,CAAC,CACzB;AAGD;AACA,OAAO,MAAMC,MAAM,gBAAavB,QAAQ,CAACwB,IAAI,CAAC,EAAE,CAAC;AAEjD;;;;;;AAMA,OAAO,MAAMC,GAAG,gBAAG5B,MAAM,C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;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;AAiDA,OAAO,MAAMiB,QAAQ,gBAAG1C,MAAM,CAAC2C,MAAM,CAAC3C,MAAM,CAACI,MAAM,EAAEJ,MAAM,CAACI,MAAM,CAAC;AAGnE;;;;;;;;;;;;;;;;AAgBA,OAAO,MAAMwC,QAAQ,gBAAG5C,MAAM,CAAC6C,MAAM,CAAC;EACpCC,IAAI,EAAEN,SAAS;EACfO,IAAI,EAAE/C,MAAM,CAACgD,UAAU;EACvBC,IAAI,eAAEjD,MAAM,CAACkD,KAAK,CAACtB,GAAG,CAAC;EACvBuB,IAAI,eAAEnD,MAAM,CAACI,MAAM,CAACmB,KAAK,cAACvB,MAAM,CAACoD,MAAM,EAAE,CAAC;EAC1CC,UAAU,EAAErD,MAAM,CAACsD,qBAAqB;EACxCC,QAAQ,EAAEb;CACX,CAAC;AAGF;AACA,OAAO,MAAMc,cAAc,gBAAGxD,MAAM,CAAC6C,MAAM,CAAC;EAC1CY,KAAK,EAAEb,QAAQ;EACfc,QAAQ,EAAEvD;CACX,CAAC","ignoreList":[]}
|
package/dist/esm/Projection.js
CHANGED
|
@@ -18,15 +18,21 @@ export const AnyProjection = {
|
|
|
18
18
|
*/
|
|
19
19
|
of: projection => projection
|
|
20
20
|
};
|
|
21
|
-
/**
|
|
22
|
-
|
|
23
|
-
|
|
24
|
-
|
|
25
|
-
|
|
26
|
-
|
|
27
|
-
|
|
28
|
-
|
|
29
|
-
|
|
21
|
+
/**
|
|
22
|
+
* Merge two queries by OR-ing their items; either wildcard yields a wildcard.
|
|
23
|
+
*
|
|
24
|
+
* Every other key on either envelope is carried into the result. The grammar's
|
|
25
|
+
* envelope has no key but `items`, so anything else is a key the store boundary
|
|
26
|
+
* refuses (`servableQueryFault`); a merge that rebuilt the envelope from `items`
|
|
27
|
+
* alone would drop that key before the boundary saw it, and a slice composed with
|
|
28
|
+
* another would then have its smuggled predicate ignored in silence — the outcome
|
|
29
|
+
* the refusal exists to prevent.
|
|
30
|
+
*/
|
|
31
|
+
const mergeQuery = (left, right) => ({
|
|
32
|
+
...left,
|
|
33
|
+
...right,
|
|
34
|
+
items: left.items.length === 0 || right.items.length === 0 ? WILDCARD.items : [...left.items, ...right.items]
|
|
35
|
+
});
|
|
30
36
|
/**
|
|
31
37
|
* OR-merge a list of queries into one. The empty list is the wildcard.
|
|
32
38
|
*
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"Projection.js","names":["matchesSequenced","WILDCARD","items","AnyProjection","of","projection","mergeQuery","left","right","length","unionQueries","queries","reduce","acc","q","composeProjections","projections","keys","Object","initialState","fromEntries","map","key","mergedQuery","query","evolve","state","decoded","next","sequenced"],"sources":["../../src/Projection.ts"],"sourcesContent":[null],"mappings":"AA4BA,SAASA,gBAAgB,QAAQ,YAAS;AAE1C;AACA;AACA;AACA;AACA;AACA;AACA,MAAMC,QAAQ,GAAU;EAAEC,KAAK,EAAE;AAAE,CAAE;AAqDrC,OAAO,MAAMC,aAAa,GAAG;EAC3B;;;;;;;EAOAC,EAAE,EAAMC,UAAyB,IAC/BA;CACM;AAaV
|
|
1
|
+
{"version":3,"file":"Projection.js","names":["matchesSequenced","WILDCARD","items","AnyProjection","of","projection","mergeQuery","left","right","length","unionQueries","queries","reduce","acc","q","composeProjections","projections","keys","Object","initialState","fromEntries","map","key","mergedQuery","query","evolve","state","decoded","next","sequenced"],"sources":["../../src/Projection.ts"],"sourcesContent":[null],"mappings":"AA4BA,SAASA,gBAAgB,QAAQ,YAAS;AAE1C;AACA;AACA;AACA;AACA;AACA;AACA,MAAMC,QAAQ,GAAU;EAAEC,KAAK,EAAE;AAAE,CAAE;AAqDrC,OAAO,MAAMC,aAAa,GAAG;EAC3B;;;;;;;EAOAC,EAAE,EAAMC,UAAyB,IAC/BA;CACM;AAaV;;;;;;;;;;AAUA,MAAMC,UAAU,GAAGA,CAACC,IAAW,EAAEC,KAAY,MAAa;EACxD,GAAGD,IAAI;EACP,GAAGC,KA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N,GAAG,CAAC,GAAGjB,UAAU,CAACoB,MAAM,CAACC,KAAK,CAACJ,GAAG,CAAC,EAAEK,OAAO,CAEhD;MACH;MACA,OAAOC,IAAI;IACb;GACD;AACH,CAAC","ignoreList":[]}
|
package/dist/esm/Query.js
CHANGED
|
@@ -68,6 +68,9 @@ export const matchesSequenced = (sequenced, query) => matchesQuery(sequenced.eve
|
|
|
68
68
|
* (`Query.ts` module docs) but which plain-data assembly — e.g. decision-model
|
|
69
69
|
* composition, `Projection.ts:31-36` — can still bypass.
|
|
70
70
|
*
|
|
71
|
+
* A query, or any of its items, carrying a key the grammar does not define is
|
|
72
|
+
* refused before anything else is judged (`unknownKeyFault` below says why).
|
|
73
|
+
*
|
|
71
74
|
* The servable grammar is exactly one of:
|
|
72
75
|
* - the wildcard (`items.length === 0`), which matches every event;
|
|
73
76
|
* - a *single* item (`items.length === 1`), any types/tags, including a
|
|
@@ -93,6 +96,54 @@ export const assertServableQuery = query => {
|
|
|
93
96
|
throw new Error(fault);
|
|
94
97
|
}
|
|
95
98
|
};
|
|
99
|
+
/**
|
|
100
|
+
* The refusal of a key `schemaFields` does not define, or `undefined` when `value`
|
|
101
|
+
* carries none. `where` names the level for the message.
|
|
102
|
+
*
|
|
103
|
+
* ## Why an unknown key is refused rather than ignored
|
|
104
|
+
*
|
|
105
|
+
* A `Query` is plain data, so nothing at runtime stops a caller adding a key the
|
|
106
|
+
* grammar does not have — a `metadata` predicate on an item is the one this repo
|
|
107
|
+
* expects, since metadata is the field an author most plausibly wants to filter on
|
|
108
|
+
* and must not (ADR-0017). Ignored, that key is a predicate the author believes they
|
|
109
|
+
* wrote and no engine honours, and on the append side it is worse: the Postgres
|
|
110
|
+
* guard embeds its match as literal plpgsql text that no type reaches, so a key a
|
|
111
|
+
* read path one day learned to honour would still be dropped by the guard, and the
|
|
112
|
+
* optimistic-concurrency check would escape in silence. Refusing every key the
|
|
113
|
+
* grammar does not define closes that route — a SMUGGLED key — at the one boundary
|
|
114
|
+
* every engine shares, before any engine could disagree. "Every key" means every
|
|
115
|
+
* key `Object.keys` returns: an own, enumerable, string key, which is what a plain
|
|
116
|
+
* object literal or a spread builds. A symbol key, a non-enumerable key or an
|
|
117
|
+
* inherited one is not judged, and no engine reads one either. Core's own query
|
|
118
|
+
* merge (`unionQueries`, `composeProjections`) carries an envelope's unknown key
|
|
119
|
+
* into the merged query rather than dropping it, so composing slices cannot launder
|
|
120
|
+
* a smuggled key past this check.
|
|
121
|
+
*
|
|
122
|
+
* It does not close the neighbouring one, and cannot: a field ADDED to the grammar's
|
|
123
|
+
* schema is a known key from that edit on and passes here, while the plpgsql guard
|
|
124
|
+
* still has to be taught it by hand. That exposure is the Postgres guard's, and its
|
|
125
|
+
* own comment in that engine's DDL says so.
|
|
126
|
+
*
|
|
127
|
+
* The known keys are read off the SCHEMA's own `fields` rather than listed here, so
|
|
128
|
+
* a field added to the grammar is admitted by the same edit that adds it. Only key
|
|
129
|
+
* NAMES are judged: an exact-optional key written as `undefined` is a known key and
|
|
130
|
+
* passes, because which values a key admits is the type's business, not this rule's.
|
|
131
|
+
*/
|
|
132
|
+
const unknownKeyFault = (where, value, schemaFields) => {
|
|
133
|
+
const unknown = Object.keys(value).find(key => !Object.hasOwn(schemaFields, key));
|
|
134
|
+
return unknown === undefined ? undefined : `assertServableQuery: ${where} carries the key ${JSON.stringify(unknown)}, which ` + 'the query grammar does not define; an unknown key would be silently ignored ' + 'by every engine rather than honoured, so it is refused';
|
|
135
|
+
};
|
|
136
|
+
/**
|
|
137
|
+
* The unknown-key half of `servableQueryFault`, on its own: the refusal of a key the
|
|
138
|
+
* grammar does not define on the envelope or on any item, or `undefined`.
|
|
139
|
+
*
|
|
140
|
+
* It is the same rule and not a second statement of it — `servableQueryFault` calls
|
|
141
|
+
* this first. It is exported because ONE caller has to tell the two halves apart:
|
|
142
|
+
* the codec's read ledger refuses an unservable SHAPE on its own error channel, and
|
|
143
|
+
* must not report an unknown key as one. An unknown key is not something a slice's
|
|
144
|
+
* tags can fix, so the ledger leaves it to the store, which refuses it as a defect.
|
|
145
|
+
*/
|
|
146
|
+
export const unknownQueryKeyFault = query => unknownKeyFault('a query', query, Query.fields) ?? query.items.reduce((fault, item) => fault ?? unknownKeyFault('a query item', item, QueryItem.fields), undefined);
|
|
96
147
|
/**
|
|
97
148
|
* The servable grammar as a TOTAL function: the reason `query` cannot be served,
|
|
98
149
|
* or `undefined` when it can.
|
|
@@ -114,6 +165,10 @@ export const assertServableQuery = query => {
|
|
|
114
165
|
* reason), so a fault is one exit route and one return type.
|
|
115
166
|
*/
|
|
116
167
|
export const servableQueryFault = query => {
|
|
168
|
+
const unknownKey = unknownQueryKeyFault(query);
|
|
169
|
+
if (unknownKey !== undefined) {
|
|
170
|
+
return unknownKey;
|
|
171
|
+
}
|
|
117
172
|
const {
|
|
118
173
|
items
|
|
119
174
|
} = query;
|
|
@@ -170,7 +225,7 @@ export const classifyServableQuery = query => {
|
|
|
170
225
|
}
|
|
171
226
|
const only = query.items.length === 1 ? query.items[0] : undefined;
|
|
172
227
|
if (only !== undefined && only.tags.length === 0) {
|
|
173
|
-
return Arr.
|
|
228
|
+
return Arr.isReadonlyArrayNonEmpty(only.types) ? {
|
|
174
229
|
kind: 'typeOnly',
|
|
175
230
|
types: only.types
|
|
176
231
|
} : {
|
package/dist/esm/Query.js.map
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"Query.js","names":["Array","Arr","Schema","EventType","Tag","QueryItem","Struct","types","tags","Query","items","matchesQueryItem","event","item","typeOk","length","includes","type","eventTags","Set","every","tag","has","matchesQuery","query","some","matchesSequenced","sequenced","assertServableQuery","fault","servableQueryFault","undefined","Error","
|
|
1
|
+
{"version":3,"file":"Query.js","names":["Array","Arr","Schema","EventType","Tag","QueryItem","Struct","types","tags","Query","items","matchesQueryItem","event","item","typeOk","length","includes","type","eventTags","Set","every","tag","has","matchesQuery","query","some","matchesSequenced","sequenced","assertServableQuery","fault","servableQueryFault","undefined","Error","unknownKeyFault","where","value","schemaFields","unknown","Object","keys","find","key","hasOwn","JSON","stringify","unknownQueryKeyFault","fields","reduce","unknownKey","classifyServableQuery","kind","only","isReadonlyArrayNonEmpty","all","or"],"sources":["../../src/Query.ts"],"sourcesContent":[null],"mappings":"AAAA;;;;;;;;;;;;;;;;;;;;;;;;AAwBA,SAASA,KAAK,IAAIC,GAAG,EAAEC,MAAM,QAAQ,QAAQ;AAC7C,SAAwBC,SAAS,EAAuBC,GAAG,QAAQ,YAAS;AAE5E;;;;AAIA,OAAO,MAAMC,SAAS,gBAAGH,MAAM,CAACI,MAAM,CAAC;EACrCC,KAAK,eAAEL,MAAM,CAACF,KAAK,CAACG,SAAS,CAAC;EAC9BK,IAAI,eAAEN,MAAM,CAACF,KAAK,CAACI,GAAG;CACvB,CAAC;AAGF;AACA,OAAO,MAAMK,KAAK,gBAAGP,MAAM,CAACI,MAAM,CAAC;EACjCI,KAAK,eAAER,MAAM,CAACF,KAAK,CAACK,SAAS;CAC9B,CAAC;AAGF;;;;AAIA,OAAO,MAAMM,gBAAgB,GAAGA,CAACC,KAAe,EAAEC,IAAe,KAAa;EAC5E,MAAMC,MAAM,GAAGD,IAAI,CAACN,KAAK,CAACQ,MAAM,KAAK,CAAC,IAAIF,IAAI,CAACN,KAAK,CAACS,QAAQ,CAACJ,KAAK,CAACK,IAAI,CAAC;EACzE,IAAI,CAACH,MAAM,EAAE;IACX,OAAO,KAAK;EACd;EACA,MAAMI,SAAS,GAAG,IAAIC,GAAG,CAASP,KAAK,CAACJ,IAAI,CAAC;EAC7C,OAAOK,IAAI,CAACL,IAAI,CAACY,KAAK,CAAEC,GAAG,IAAKH,SAAS,CAACI,GAAG,CAACD,GAAG,CAAC,CAAC;AACrD,CAAC;AAED;;;;;AAKA,OAAO,MAAME,YAAY,GAAGA,CAACX,KAAe,EAAEY,KAAY,KAAa;EACrE,IAAIA,KAAK,CAACd,KAAK,CAACK,MAAM,KAAK,CAAC,EAAE;IAC5B,OAAO,IAAI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,IAAI,GAAIiC,MAGb,KAAiB;EAChBvC,KAAK,EAAEuC,MAAM,CAACvC,KAAK,IAAI,EAAE;EACzBC,IAAI,EAAEsC,MAAM,CAACtC;CACd,CAAC;AAEF;AACA,MAAM6C,GAAG,GAAGA,CAAA,MAAc;EAAE3C,KAAK,EAAE;AAAE,CAAE,CAAC;AAExC;;;;AAIA,MAAMF,IAAI,GAAGA,CACXA,IAA2C,EAC3CD,KAAgC,MACrB;EACXG,KAAK,EAAE,CAACG,IAAI,CAAC;IAAEL,IAAI;IAAE,IAAID,KAAK,KAAKwB,SAAS,GAAG,EAAE,GAAG;MAAExB;IAAK,CAAE;EAAC,CAAE,CAAC;CAClE,CAAC;AAEF;;;;;AAKA,MAAMA,KAAK,GACTA,KAAwD,KAC7C;EAAEG,KAAK,EAAE,CAAC;IAAEH,KAAK;IAAEC,IAAI,EAAE;EAAE,CAAE;AAAC,CAAE,CAAC;AAE9C;;;;;AAKA,MAAM8C,EAAE,GACN5C,KAAwD,KAC7C;EACXA;CACD,CAAC;AAEF;AACA,OAAO,MAAMc,KAAK,GAAG;EACnB6B,GAAG;EACHxC,IAAI;EACJyC,EAAE;EACF9C,IAAI;EACJD;CACQ","ignoreList":[]}
|
|
@@ -68,7 +68,7 @@
|
|
|
68
68
|
* memory alone, and it lands hardest on the durable-log-with-in-memory-view mode,
|
|
69
69
|
* where an ephemeral view re-catches-up the entire log on every boot.
|
|
70
70
|
*/
|
|
71
|
-
import {
|
|
71
|
+
import { Effect, Option, Queue, Schedule, Schema, Stream } from 'effect';
|
|
72
72
|
import { ORIGIN, ReadLimit } from "./Event.js";
|
|
73
73
|
/**
|
|
74
74
|
* A short catch-up page size default for the reconcile loop. Reads page by page
|
|
@@ -107,12 +107,12 @@ export const DEFAULT_POLL_INTERVAL_MILLIS = 1000;
|
|
|
107
107
|
* the key NAME, the VALIDATION and the DEFAULT from one place, so a caller who has
|
|
108
108
|
* tuned one engine's subscribe reads another's without translating, and the two
|
|
109
109
|
* cannot drift in what they ACCEPT any more than in what they assume. Two engines
|
|
110
|
-
* hand-authoring the identical `Schema.
|
|
110
|
+
* hand-authoring the identical `Schema.optionalKey(…)` twice were identical only
|
|
111
111
|
* by inspection.
|
|
112
112
|
*
|
|
113
113
|
* The bounds differ between the two because the quantities do. `pollInterval` is a
|
|
114
|
-
* duration, so a fraction of a millisecond is meaningful and only `
|
|
115
|
-
* `
|
|
114
|
+
* duration, so a fraction of a millisecond is meaningful and only `isGreaterThan(0)`
|
|
115
|
+
* and `isFinite` matter: at zero or below the loop would spin without ever waiting for a
|
|
116
116
|
* wake, and at `Infinity` the periodic re-read — the half that carries delivery —
|
|
117
117
|
* would never come, which silently converts the wake source from an optimisation
|
|
118
118
|
* into the guarantee. `catchUpPageSize` is a COUNT, so it must be an integer
|
|
@@ -120,17 +120,13 @@ export const DEFAULT_POLL_INTERVAL_MILLIS = 1000;
|
|
|
120
120
|
* length against it to decide the tail is drained, and a page of zero would report
|
|
121
121
|
* "drained" forever without reading anything.
|
|
122
122
|
*
|
|
123
|
-
* `
|
|
123
|
+
* `optionalKey` on both keeps the decoded type at `key?: T` rather than
|
|
124
124
|
* `T | undefined`, matching the repo's `exactOptionalPropertyTypes` discipline — an
|
|
125
125
|
* absent key, never an explicit `undefined`.
|
|
126
126
|
*/
|
|
127
127
|
export const subscriptionTuningFields = {
|
|
128
|
-
pollInterval: /*#__PURE__*/Schema.
|
|
129
|
-
|
|
130
|
-
}),
|
|
131
|
-
catchUpPageSize: /*#__PURE__*/Schema.optionalWith(/*#__PURE__*/Schema.Int.pipe(/*#__PURE__*/Schema.positive()), {
|
|
132
|
-
exact: true
|
|
133
|
-
})
|
|
128
|
+
pollInterval: /*#__PURE__*/Schema.optionalKey(/*#__PURE__*/Schema.Number.check(/*#__PURE__*/Schema.isGreaterThan(0), /*#__PURE__*/Schema.isFinite())),
|
|
129
|
+
catchUpPageSize: /*#__PURE__*/Schema.optionalKey(/*#__PURE__*/Schema.Int.check(/*#__PURE__*/Schema.isGreaterThan(0)))
|
|
134
130
|
};
|
|
135
131
|
/**
|
|
136
132
|
* Retry a TRANSIENT poll fault (an `E` from one reconcile read) on a capped
|
|
@@ -139,16 +135,16 @@ export const subscriptionTuningFields = {
|
|
|
139
135
|
* past the cap propagates (the decorator dies it) — infrastructure stays off the
|
|
140
136
|
* contract channel while the stream survives ordinary transients.
|
|
141
137
|
*/
|
|
142
|
-
const POLL_RETRY_SCHEDULE = /*#__PURE__*/Schedule.exponential('100 millis', 2)
|
|
138
|
+
const POLL_RETRY_SCHEDULE = /*#__PURE__*/Schedule.max([/*#__PURE__*/Schedule.min([/*#__PURE__*/Schedule.exponential('100 millis', 2), /*#__PURE__*/Schedule.spaced('2 seconds')]), /*#__PURE__*/Schedule.recurs(20)]);
|
|
143
139
|
/**
|
|
144
140
|
* Build the subscription `Stream`: catch up from `after`, then track the live tail.
|
|
145
|
-
* The cursor threads through the `
|
|
146
|
-
*
|
|
147
|
-
*
|
|
148
|
-
* on close. An `E` mid-stream stays on the channel; `makeContractStore` dies it
|
|
141
|
+
* The cursor threads through the `Stream.paginate` state, starting at `after` and
|
|
142
|
+
* advancing to the last delivered position each batch; the stream never completes
|
|
143
|
+
* on its own (the next state is always `Option.some`), so the enclosing scope
|
|
144
|
+
* interrupts it on close. An `E` mid-stream stays on the channel; `makeContractStore` dies it
|
|
149
145
|
* (subscribe is `E = never` on the contract).
|
|
150
146
|
*/
|
|
151
|
-
export const subscribeStream = (deps, after) => Stream.
|
|
147
|
+
export const subscribeStream = (deps, after) => Stream.unwrap(Effect.gen(function* () {
|
|
152
148
|
// The wake primitive: a sliding(1) queue holding at most one pending
|
|
153
149
|
// signal. The wake source `offer`s an opaque wake on every notification;
|
|
154
150
|
// the poll loop `take`s (with a timeout). The lost-wakeup guard is
|
|
@@ -164,7 +160,7 @@ export const subscribeStream = (deps, after) => Stream.unwrapScoped(Effect.gen(f
|
|
|
164
160
|
// silently-dropped (and later re-established) wake source loses no
|
|
165
161
|
// positions. Absent a wake source entirely, `Stream.never` makes this a
|
|
166
162
|
// fibre that parks forever and delivery falls to the poll alone.
|
|
167
|
-
const listener = (deps.listen ?? Stream.never).pipe(Stream.tap(() => Queue.offer(wake, undefined)), Stream.retry(Schedule.exponential('50 millis')
|
|
163
|
+
const listener = (deps.listen ?? Stream.never).pipe(Stream.tap(() => Queue.offer(wake, undefined)), Stream.retry(Schedule.min([Schedule.exponential('50 millis'), Schedule.spaced('1 seconds')])));
|
|
168
164
|
// Drain the wake source into the wake queue on a background fibre; the
|
|
169
165
|
// scope releases it. We never read its elements directly — every
|
|
170
166
|
// notification is an opaque wake signal.
|
|
@@ -196,7 +192,7 @@ export const subscribeStream = (deps, after) => Stream.unwrapScoped(Effect.gen(f
|
|
|
196
192
|
}).pipe(Effect.retry(POLL_RETRY_SCHEDULE));
|
|
197
193
|
/**
|
|
198
194
|
* Produce the NEXT non-empty batch from a cursor position, together with
|
|
199
|
-
* the advanced cursor — a pure `Position → Effect<[
|
|
195
|
+
* the advanced cursor — a pure `Position → Effect<[events, next]>`. The
|
|
200
196
|
* `> boundary` de-dup is enforced by `fetch`'s exclusive lower bound, so a
|
|
201
197
|
* live re-read after a wake never re-emits an already-delivered position.
|
|
202
198
|
*
|
|
@@ -204,24 +200,26 @@ export const subscribeStream = (deps, after) => Stream.unwrapScoped(Effect.gen(f
|
|
|
204
200
|
* the cursor. If a drain yields nothing, wait for a wake but only up to the
|
|
205
201
|
* poll interval, then loop and re-read ANYWAY — the periodic position-based
|
|
206
202
|
* poll that makes delivery correct independently of any wake. This effect
|
|
207
|
-
* only completes by returning a non-empty
|
|
203
|
+
* only completes by returning a non-empty batch; the scope interrupts it on
|
|
208
204
|
* close.
|
|
209
205
|
*/
|
|
210
206
|
const nextBatch = from => Effect.gen(function* () {
|
|
211
207
|
while (true) {
|
|
212
|
-
|
|
208
|
+
// `Queue.clear` and not `Queue.takeAll`: the drain must NOT wait, and
|
|
209
|
+
// `takeAll` suspends until at least one signal is present.
|
|
210
|
+
yield* Queue.clear(wake);
|
|
213
211
|
const {
|
|
214
212
|
events,
|
|
215
213
|
last
|
|
216
214
|
} = yield* drainFrom(from);
|
|
217
215
|
if (events.length > 0) {
|
|
218
|
-
return [
|
|
216
|
+
return [events, last];
|
|
219
217
|
}
|
|
220
218
|
// Nothing new: block on a wake, but only up to the poll interval — on
|
|
221
219
|
// timeout we fall through and the loop re-reads regardless.
|
|
222
220
|
yield* Effect.ignore(Effect.timeout(Queue.take(wake), deps.pollInterval));
|
|
223
221
|
}
|
|
224
222
|
});
|
|
225
|
-
return Stream.
|
|
223
|
+
return Stream.paginate(after ?? ORIGIN, from => Effect.map(nextBatch(from), ([events, last]) => [events, Option.some(last)]));
|
|
226
224
|
}));
|
|
227
225
|
//# sourceMappingURL=SubscribeMachine.js.map
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"SubscribeMachine.js","names":["
|
|
1
|
+
{"version":3,"file":"SubscribeMachine.js","names":["Effect","Option","Queue","Schedule","Schema","Stream","ORIGIN","ReadLimit","DEFAULT_CATCH_UP_PAGE_SIZE","DEFAULT_POLL_INTERVAL_MILLIS","subscriptionTuningFields","pollInterval","optionalKey","Number","check","isGreaterThan","isFinite","catchUpPageSize","Int","POLL_RETRY_SCHEDULE","max","min","exponential","spaced","recurs","subscribeStream","deps","after","unwrap","gen","wake","sliding","listener","listen","never","pipe","tap","offer","undefined","retry","runDrain","forkScoped","drainFrom","from","collected","cursor","events","fetch","make","event","push","lastEvent","at","length","position","last","nextBatch","clear","ignore","timeout","take","paginate","map","some"],"sources":["../../src/SubscribeMachine.ts"],"sourcesContent":[null],"mappings":"AAAA;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;AAsEA,SACEA,MAAM,EACNC,MAAM,EACNC,KAAK,EACLC,QAAQ,EACRC,MAAM,EAENC,MAAM,QACD,QAAQ;AAEf,SAASC,MAAM,EAAEC,SAAS,QAAQ,YAAS;AA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