@kairos-es/core 1.0.0-alpha.2 → 1.0.0-alpha.4
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 +1 -1
- package/dist/cjs/ContractStore.js +11 -2
- package/dist/cjs/ContractStore.js.map +1 -1
- package/dist/cjs/Event.js +63 -3
- 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 +58 -2
- package/dist/cjs/Query.js.map +1 -1
- package/dist/cjs/inMemory.js +110 -40
- package/dist/cjs/inMemory.js.map +1 -1
- package/dist/dts/ContractStore.d.ts +4 -2
- package/dist/dts/ContractStore.d.ts.map +1 -1
- package/dist/dts/Event.d.ts +60 -1
- package/dist/dts/Event.d.ts.map +1 -1
- package/dist/dts/Projection.d.ts +1 -1
- package/dist/dts/Projection.d.ts.map +1 -1
- package/dist/dts/Query.d.ts +14 -0
- package/dist/dts/Query.d.ts.map +1 -1
- package/dist/dts/inMemory.d.ts.map +1 -1
- package/dist/esm/ContractStore.js +11 -2
- package/dist/esm/ContractStore.js.map +1 -1
- package/dist/esm/Event.js +62 -2
- 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 +55 -0
- package/dist/esm/Query.js.map +1 -1
- package/dist/esm/inMemory.js +111 -41
- package/dist/esm/inMemory.js.map +1 -1
- package/package.json +1 -1
- package/src/ContractStore.ts +20 -4
- package/src/Event.ts +63 -1
- package/src/Projection.ts +19 -8
- package/src/Query.ts +73 -0
- package/src/inMemory.ts +119 -47
package/README.md
CHANGED
|
@@ -8,7 +8,7 @@ DCB-first event-sourcing contract and in-memory store for Effect v3.
|
|
|
8
8
|
Effect instance (per [ADR-0003](../../docs/adr)):
|
|
9
9
|
|
|
10
10
|
```sh
|
|
11
|
-
pnpm add @kairos-es/core@alpha effect
|
|
11
|
+
pnpm add @kairos-es/core@alpha effect@^3.22.0
|
|
12
12
|
```
|
|
13
13
|
|
|
14
14
|
Provides the `DcbEventStore` contract (branded `Position` / `Tag` / `EventType`,
|
|
@@ -5,6 +5,7 @@ Object.defineProperty(exports, "__esModule", {
|
|
|
5
5
|
});
|
|
6
6
|
exports.makeContractStore = void 0;
|
|
7
7
|
var _effect = require("effect");
|
|
8
|
+
var _AppendCondition = require("./AppendCondition.js");
|
|
8
9
|
var _AppendIsOwned = require("./AppendIsOwned.js");
|
|
9
10
|
var _Event = require("./Event.js");
|
|
10
11
|
var _Query = require("./Query.js");
|
|
@@ -26,7 +27,7 @@ const makeContractStore = raw => ({
|
|
|
26
27
|
}),
|
|
27
28
|
append: (events, condition) =>
|
|
28
29
|
// The ownership refusal runs FIRST and sits OUTSIDE the suspend, because it is
|
|
29
|
-
// the only one of append's
|
|
30
|
+
// the only one of append's checks that is EFFECTFUL: it consults a
|
|
30
31
|
// `Context.Tag` rather than inspecting the arguments. `Effect.flatMap` over an
|
|
31
32
|
// already-lazy effect defers it exactly as the suspend defers the throws below,
|
|
32
33
|
// so nothing runs at the call site either way; what it buys is that the
|
|
@@ -47,8 +48,16 @@ const makeContractStore = raw => ({
|
|
|
47
48
|
if (events.length === 0) {
|
|
48
49
|
throw new Error('makeContractStore.append: the events batch is empty; append requires ' + 'at least one event (a NonEmptyReadonlyArray). An empty batch is a ' + 'plain-data caller bypassing the type — a defect, not a conflict.');
|
|
49
50
|
}
|
|
50
|
-
// A non-servable guard query is a defect in every engine
|
|
51
|
+
// A non-servable guard query is a defect in every engine, and so is a
|
|
52
|
+
// condition carrying a key `AppendCondition` does not define: an author
|
|
53
|
+
// who wrote one believes they added a condition, and every engine would
|
|
54
|
+
// ignore it. Known keys come off the schema, as `servableQueryFault`
|
|
55
|
+
// reads its own (`Query.ts` owns the argument).
|
|
51
56
|
if (condition !== undefined) {
|
|
57
|
+
const unknown = Object.keys(condition).find(key => !Object.hasOwn(_AppendCondition.AppendCondition.fields, key));
|
|
58
|
+
if (unknown !== undefined) {
|
|
59
|
+
throw new Error(`makeContractStore.append: the append condition carries the key ${JSON.stringify(unknown)}, ` + 'which `AppendCondition` does not define; an unknown key would be ' + 'silently ignored by every engine rather than honoured, so it is refused');
|
|
60
|
+
}
|
|
52
61
|
(0, _Query.assertServableQuery)(condition.failIfEventsMatch);
|
|
53
62
|
}
|
|
54
63
|
// Only `AppendConditionFailed` belongs on the contract error channel;
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"ContractStore.js","names":["_effect","require","_AppendIsOwned","_Event","_Query","decodeReadLimit","Schema","decodeUnknownSync","ReadLimit","makeContractStore","raw","read","query","options","Effect","suspend","assertServableQuery","limit","undefined","orDie","append","events","condition","flatMap","assertAppendNotOwned","length","Error","failIfEventsMatch","catchAll","error","Predicate","isTagged","fail","die","subscribe","after","Stream","unwrap","sync","exports"],"sources":["../../src/ContractStore.ts"],"sourcesContent":[null],"mappings":";;;;;;
|
|
1
|
+
{"version":3,"file":"ContractStore.js","names":["_effect","require","_AppendCondition","_AppendIsOwned","_Event","_Query","decodeReadLimit","Schema","decodeUnknownSync","ReadLimit","makeContractStore","raw","read","query","options","Effect","suspend","assertServableQuery","limit","undefined","orDie","append","events","condition","flatMap","assertAppendNotOwned","length","Error","unknown","Object","keys","find","key","hasOwn","AppendCondition","fields","JSON","stringify","failIfEventsMatch","catchAll","error","Predicate","isTagged","fail","die","subscribe","after","Stream","unwrap","sync","exports"],"sources":["../../src/ContractStore.ts"],"sourcesContent":[null],"mappings":";;;;;;AAqCA,IAAAA,OAAA,GAAAC,OAAA;AACA,IAAAC,gBAAA,GAAAD,OAAA;AACA,IAAAE,cAAA,GAAAF,OAAA;AAGA,IAAAG,MAAA,GAAAH,OAAA;AAEA,IAAAI,MAAA,GAAAJ,OAAA;AAEA;AACA,MAAMK,eAAe,gBAAGC,cAAM,CAACC,iBAAiB,CAACC,gBAAS,CAAC;AAwB3D;;;;AAIO,MAAMC,iBAAiB,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ACA;IACA;IACA;IACA;IACA;IACA;IACA;IACA;IACA;IACA;IACA,OAAOvB,cAAM,CAACwB,QAAQ,CAAC5B,GAAG,CAACU,MAAM,CAACC,MAAM,EAAEC,SAAS,CAAC,EAAGiB,KAAK,IAC1DC,iBAAS,CAACC,QAAQ,CAAC,uBAAuB,CAAC,CAACF,KAAK,CAAC,GAC9CzB,cAAM,CAAC4B,IAAI,CAACH,KAAK,CAAC,GAClBzB,cAAM,CAAC6B,GAAG,CAACJ,KAAK,CAAC,CACtB;EACH,CAAC,CAAC,CACH;EAEHK,SAAS,EAAEA,CAAChC,KAAK,EAAEiC,KAAK;EACtB;EACA;EACA;EACA;EACAC,cAAM,CAACC,MAAM,CACXjC,cAAM,CAACkC,IAAI,CAAC,MAAK;IACf,IAAAhC,0BAAmB,EAACJ,KAAK,CAAC;IAC1B,OAAOkC,cAAM,CAAC3B,KAAK,CAACT,GAAG,CAACkC,SAAS,CAAChC,KAAK,EAAEiC,KAAK,CAAC,CAAC;EAClD,CAAC,CAAC;CAEP,CAAC;AAAAI,OAAA,CAAAxC,iBAAA,GAAAA,iBAAA","ignoreList":[]}
|
package/dist/cjs/Event.js
CHANGED
|
@@ -3,7 +3,7 @@
|
|
|
3
3
|
Object.defineProperty(exports, "__esModule", {
|
|
4
4
|
value: true
|
|
5
5
|
});
|
|
6
|
-
exports.tagIdentity = exports.Tag = exports.SequencedEvent = exports.ReadLimit = exports.Position = exports.ORIGIN = exports.EventType = exports.DcbEvent = void 0;
|
|
6
|
+
exports.tagIdentity = exports.Tag = exports.SequencedEvent = exports.ReadLimit = exports.Position = exports.ORIGIN = exports.Metadata = exports.EventType = exports.DcbEvent = void 0;
|
|
7
7
|
var _effect = require("effect");
|
|
8
8
|
/**
|
|
9
9
|
* Core domain types for the DCB event log: branded scalars and the wire
|
|
@@ -66,20 +66,80 @@ const ReadLimit = exports.ReadLimit = /*#__PURE__*/_effect.Schema.Int.pipe(/*#__
|
|
|
66
66
|
* in the name (e.g. `course-registered.v2`); only non-emptiness is enforced.
|
|
67
67
|
*/
|
|
68
68
|
const EventType = exports.EventType = /*#__PURE__*/_effect.Schema.String.pipe(/*#__PURE__*/_effect.Schema.nonEmptyString(), /*#__PURE__*/_effect.Schema.brand('EventType'));
|
|
69
|
+
/**
|
|
70
|
+
* An event's metadata: a flat bag of strings carrying the circumstances under
|
|
71
|
+
* which the event was RECORDED, never anything the business asserts (ADR-0017).
|
|
72
|
+
* Payload is what happened; metadata is the context of the recording — a
|
|
73
|
+
* `traceparent`, a correlation or causation id, a deployment revision.
|
|
74
|
+
*
|
|
75
|
+
* Values are strings, not `unknown`, for cross-engine parity rather than taste:
|
|
76
|
+
* both SQL engines carry the bag as a JSON document, and `JSON.stringify` drops
|
|
77
|
+
* `undefined`, throws on `bigint` and turns `NaN` into `null`, none of which the
|
|
78
|
+
* in-memory oracle does.
|
|
79
|
+
*
|
|
80
|
+
* The key schema carries no refinement, deliberately: a refinement on a
|
|
81
|
+
* `Schema.Record` key acts as a FILTER on decode, silently dropping a key that
|
|
82
|
+
* fails it rather than failing the decode. Constraining keys, if ever wanted,
|
|
83
|
+
* has to be a validating step of its own.
|
|
84
|
+
*
|
|
85
|
+
* Two engine limits a consumer must know, because the bag is typically filled
|
|
86
|
+
* from outside the application at a request edge. Postgres refuses a NUL
|
|
87
|
+
* character (U+0000) and an unpaired surrogate in any string it stores, so an
|
|
88
|
+
* event whose bag holds one fails to append there while the in-memory and
|
|
89
|
+
* SQLite engines accept it; sanitise untrusted values before they reach the
|
|
90
|
+
* bag. And key ORDER is not preserved: Postgres stores an object's keys in an
|
|
91
|
+
* order of its own, so compare bags as unordered and never rely on the order
|
|
92
|
+
* `Object.keys` returns.
|
|
93
|
+
*
|
|
94
|
+
* Metadata is never part of a `Query` or an `AppendCondition` — a store refuses
|
|
95
|
+
* either when it carries a key the grammar does not define, so a metadata
|
|
96
|
+
* predicate cannot be written and silently ignored — never reaches a codec's
|
|
97
|
+
* `tagsFor`, and no store offers a way to rewrite it once appended. ADR-0017
|
|
98
|
+
* owns why each of those is mechanical rather than preferential.
|
|
99
|
+
*
|
|
100
|
+
* ## The one home of the shape rule
|
|
101
|
+
*
|
|
102
|
+
* The bag is a JSON OBJECT whose every value is a STRING, and this schema is
|
|
103
|
+
* where that rule is stated. At runtime it is checked in ONE place, at write: the
|
|
104
|
+
* codec's `toEvent` decodes every bag through this schema and refuses one that
|
|
105
|
+
* fails on its own error channel, so a value smuggled past the type (through an
|
|
106
|
+
* `any`) stops there. The schema judges a bag's OWN enumerable keys, so an object
|
|
107
|
+
* that keeps its entries anywhere else — a `Map`, a `Date` — reads as the empty
|
|
108
|
+
* bag rather than failing. A store checks no values: an event built by hand and handed
|
|
109
|
+
* to `append` directly carries whatever it carries, and what each engine then does
|
|
110
|
+
* with a non-string value differs — one may store it and read it back differently
|
|
111
|
+
* from another, and a `bigint` makes a SQL engine's append fail. Each
|
|
112
|
+
* SQL engine keeps a container check of its own on read — the column must hold a
|
|
113
|
+
* JSON object — because that defends against a writer outside the library and is
|
|
114
|
+
* about the column, not the values. A VALUE check must never be added on read
|
|
115
|
+
* alone: it would make an event the store accepted unreadable for ever, so a
|
|
116
|
+
* value check belongs at write or nowhere.
|
|
117
|
+
*/
|
|
118
|
+
const Metadata = exports.Metadata = /*#__PURE__*/_effect.Schema.Record({
|
|
119
|
+
key: _effect.Schema.String,
|
|
120
|
+
value: _effect.Schema.String
|
|
121
|
+
});
|
|
69
122
|
/**
|
|
70
123
|
* An event as stored: an opaque payload plus its type, tags, a
|
|
71
|
-
* producer-supplied `uuid`,
|
|
124
|
+
* producer-supplied `uuid`, producer-supplied `occurredAt` domain time, and its
|
|
125
|
+
* `metadata` bag.
|
|
72
126
|
*
|
|
73
127
|
* `data` is `Uint8Array` (opaque bytes); the store does not interpret it.
|
|
74
128
|
* `uuid` is producer-supplied to keep `core` deterministic (no RNG in core).
|
|
75
129
|
* `occurredAt` is informational only; ordering is by position alone.
|
|
130
|
+
* `metadata` mirrors `tags` rather than `data`: REQUIRED, with an empty bag
|
|
131
|
+
* legal. Required because an absent-versus-empty divergence between engines is
|
|
132
|
+
* invisible to `toEqual`, which ignores `undefined` properties, so an optional
|
|
133
|
+
* field could drift across the three engines with the round-trip suite green.
|
|
134
|
+
* Core only carries it; the codec's `toEvent` is where it is resolved.
|
|
76
135
|
*/
|
|
77
136
|
const DcbEvent = exports.DcbEvent = /*#__PURE__*/_effect.Schema.Struct({
|
|
78
137
|
type: EventType,
|
|
79
138
|
data: _effect.Schema.Uint8ArrayFromSelf,
|
|
80
139
|
tags: /*#__PURE__*/_effect.Schema.Array(Tag),
|
|
81
140
|
uuid: _effect.Schema.UUID,
|
|
82
|
-
occurredAt: _effect.Schema.DateTimeUtc
|
|
141
|
+
occurredAt: _effect.Schema.DateTimeUtc,
|
|
142
|
+
metadata: Metadata
|
|
83
143
|
});
|
|
84
144
|
/** A persisted event: the event together with the position it was written at. */
|
|
85
145
|
const SequencedEvent = exports.SequencedEvent = /*#__PURE__*/_effect.Schema.Struct({
|
package/dist/cjs/Event.js.map
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"Event.js","names":["_effect","require","Position","exports","Schema","BigInt","pipe","nonNegativeBigInt","brand","ORIGIN","make","Tag","String","pattern","identifier","tagIdentity","key","length","includes","Error","JSON","stringify","value","ReadLimit","Int","greaterThanOrEqualTo","EventType","nonEmptyString","DcbEvent","Struct","type","data","Uint8ArrayFromSelf","tags","Array","uuid","UUID","occurredAt","DateTimeUtc","SequencedEvent","event","position"],"sources":["../../src/Event.ts"],"sourcesContent":[null],"mappings":";;;;;;AAQA,IAAAA,OAAA,GAAAC,OAAA;AARA;;;;;;;;;AAUA;;;;;;;;;AASO,MAAMC,QAAQ,GAAAC,OAAA,CAAAD,QAAA,gBAAGE,cAAM,CAACC,MAAM,CAACC,IAAI,cACxCF,cAAM,CAACG,iBAAiB,EAAE,eAC1BH,cAAM,CAACI,KAAK,CAAC,UAAU,CAAC,CACzB;AAGD;AACO,MA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GtB,cAAM,CAACQ,MAAM,CAACN,IAAI,cACzCF,cAAM,CAACuB,cAAc,EAAE,eACvBvB,cAAM,CAACI,KAAK,CAAC,WAAW,CAAC,CAC1B;AAGD
|
|
1
|
+
{"version":3,"file":"Event.js","names":["_effect","require","Position","exports","Schema","BigInt","pipe","nonNegativeBigInt","brand","ORIGIN","make","Tag","String","pattern","identifier","tagIdentity","key","length","includes","Error","JSON","stringify","value","ReadLimit","Int","greaterThanOrEqualTo","EventType","nonEmptyString","Metadata","Record","DcbEvent","Struct","type","data","Uint8ArrayFromSelf","tags","Array","uuid","UUID","occurredAt","DateTimeUtc","metadata","SequencedEvent","event","position"],"sources":["../../src/Event.ts"],"sourcesContent":[null],"mappings":";;;;;;AAQA,IAAAA,OAAA,GAAAC,OAAA;AARA;;;;;;;;;AAUA;;;;;;;;;AASO,MAAMC,QAAQ,GAAAC,OAAA,CAAAD,QAAA,gBAAGE,cAAM,CAACC,MAAM,CAACC,IAAI,cACxCF,cAAM,CAACG,iBAAiB,EAAE,eAC1BH,cAAM,CAACI,KAAK,CAAC,UAAU,CAAC,CACzB;AAGD;AACO,MAAMC,MAAM,GAAAN,OAAA,CAAAM,MAAA,gBAAaP,QAAQ,CAACQ,IAAI,CAAC,EAAE,CAAC;AAEjD;;;;;;AAMO,MAAMC,GAAG,GAAAR,OAAA,CAAAQ,GAAA,gBAAGP,cAAM,CAACQ,MAAM,CAACN,IAAI,cACnCF,cAAM,CAACS,OAAO,CAAC,WAAW,EAAE;EAAEC,UAAU,EAAE;AAAK,CAAE,CAAC,eAClDV,cAAM,CAACI,KAAK,CAAC,KAAK,CAAC,CACpB;AA8BM,MAAMO,WAAW,GAAIC,GAAW,IAAiB;EACtD,IAAIA,GAAG,CAACC,MAAM,KAAK,CAAC,IAAID,GAAG,CAACE,QAAQ,CAAC,GAAG,CAAC,EAAE;IACzC,MAAM,IAAIC,KAAK,CACb,8DAA8DC,IAAI,CAACC,SAAS,CAACL,GAAG,CAAC,GAAG,CACr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;EAC/BC,IAAI,eAAE/B,cAAM,CAACgC,KAAK,CAACzB,GAAG,CAAC;EACvB0B,IAAI,EAAEjC,cAAM,CAACkC,IAAI;EACjBC,UAAU,EAAEnC,cAAM,CAACoC,WAAW;EAC9BC,QAAQ,EAAEb;CACX,CAAC;AAGF;AACO,MAAMc,cAAc,GAAAvC,OAAA,CAAAuC,cAAA,gBAAGtC,cAAM,CAAC2B,MAAM,CAAC;EAC1CY,KAAK,EAAEb,QAAQ;EACfc,QAAQ,EAAE1C;CACX,CAAC","ignoreList":[]}
|
package/dist/cjs/Projection.js
CHANGED
|
@@ -24,15 +24,21 @@ const AnyProjection = exports.AnyProjection = {
|
|
|
24
24
|
*/
|
|
25
25
|
of: projection => projection
|
|
26
26
|
};
|
|
27
|
-
/**
|
|
28
|
-
|
|
29
|
-
|
|
30
|
-
|
|
31
|
-
|
|
32
|
-
|
|
33
|
-
|
|
34
|
-
|
|
35
|
-
|
|
27
|
+
/**
|
|
28
|
+
* Merge two queries by OR-ing their items; either wildcard yields a wildcard.
|
|
29
|
+
*
|
|
30
|
+
* Every other key on either envelope is carried into the result. The grammar's
|
|
31
|
+
* envelope has no key but `items`, so anything else is a key the store boundary
|
|
32
|
+
* refuses (`servableQueryFault`); a merge that rebuilt the envelope from `items`
|
|
33
|
+
* alone would drop that key before the boundary saw it, and a slice composed with
|
|
34
|
+
* another would then have its smuggled predicate ignored in silence — the outcome
|
|
35
|
+
* the refusal exists to prevent.
|
|
36
|
+
*/
|
|
37
|
+
const mergeQuery = (left, right) => ({
|
|
38
|
+
...left,
|
|
39
|
+
...right,
|
|
40
|
+
items: left.items.length === 0 || right.items.length === 0 ? WILDCARD.items : [...left.items, ...right.items]
|
|
41
|
+
});
|
|
36
42
|
/**
|
|
37
43
|
* OR-merge a list of queries into one. The empty list is the wildcard.
|
|
38
44
|
*
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"Projection.js","names":["_Query","require","WILDCARD","items","AnyProjection","exports","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","matchesSequenced","sequenced"],"sources":["../../src/Projection.ts"],"sourcesContent":[null],"mappings":";;;;;;AA4BA,IAAAA,MAAA,GAAAC,OAAA;AAEA;AACA;AACA;AACA;AACA;AACA;AACA,MAAMC,QAAQ,GAAU;EAAEC,KAAK,EAAE;AAAE,CAAE;AAqD9B,MAAMC,aAAa,GAAAC,OAAA,CAAAD,aAAA,GAAG;EAC3B;;;;;;;EAOAE,EAAE,EAAMC,UAAyB,IAC/BA;CACM;AAaV
|
|
1
|
+
{"version":3,"file":"Projection.js","names":["_Query","require","WILDCARD","items","AnyProjection","exports","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","matchesSequenced","sequenced"],"sources":["../../src/Projection.ts"],"sourcesContent":[null],"mappings":";;;;;;AA4BA,IAAAA,MAAA,GAAAC,OAAA;AAEA;AACA;AACA;AACA;AACA;AACA;AACA,MAAMC,QAAQ,GAAU;EAAEC,KAAK,EAAE;AAAE,CAAE;AAqD9B,MAAMC,aAAa,GAAAC,OAAA,CAAAD,aAAA,GAAG;EAC3B;;;;;;;EAOAE,EAAE,EAAMC,UAAyB,IAC/BA;CACM;AAaV;;;;;;;;;;AAUA,MAAMC,UAAU,GAAGA,CAACC,IAAW,EAAEC,KAAY,MAAa;EACxD,GAAGD,IAAI;EACP,GAAGC,KAAK;EACRP,KAAK,EACHM,IAAI,CAACN,KAAK,CAACQ,MAAM,KAAK,CAAC,IAAID,KAAK,CAACP,KAAK,CAACQ,MAAM,KAAK,CAAC,GAC/CT,QAAQ,CAACC,KAAK,GACd,CAAC,GAAGM,IAAI,CAACN,KAAK,EAAE,GAAGO,KAAK,CAACP,KAAK;CACrC,CAAC;AAEF;;;;;;;;;;;;;;;AAeO,MAAMS,YAAY,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 +3,7 @@
|
|
|
3
3
|
Object.defineProperty(exports, "__esModule", {
|
|
4
4
|
value: true
|
|
5
5
|
});
|
|
6
|
-
exports.servableQueryFault = exports.query = exports.matchesSequenced = exports.matchesQueryItem = exports.matchesQuery = exports.classifyServableQuery = exports.assertServableQuery = exports.QueryItem = exports.Query = void 0;
|
|
6
|
+
exports.unknownQueryKeyFault = exports.servableQueryFault = exports.query = exports.matchesSequenced = exports.matchesQueryItem = exports.matchesQuery = exports.classifyServableQuery = exports.assertServableQuery = exports.QueryItem = exports.Query = void 0;
|
|
7
7
|
var _effect = require("effect");
|
|
8
8
|
var _Event = require("./Event.js");
|
|
9
9
|
/**
|
|
@@ -77,6 +77,9 @@ const matchesSequenced = (sequenced, query) => matchesQuery(sequenced.event, que
|
|
|
77
77
|
* (`Query.ts` module docs) but which plain-data assembly — e.g. decision-model
|
|
78
78
|
* composition, `Projection.ts:31-36` — can still bypass.
|
|
79
79
|
*
|
|
80
|
+
* A query, or any of its items, carrying a key the grammar does not define is
|
|
81
|
+
* refused before anything else is judged (`unknownKeyFault` below says why).
|
|
82
|
+
*
|
|
80
83
|
* The servable grammar is exactly one of:
|
|
81
84
|
* - the wildcard (`items.length === 0`), which matches every event;
|
|
82
85
|
* - a *single* item (`items.length === 1`), any types/tags, including a
|
|
@@ -103,6 +106,55 @@ const assertServableQuery = query => {
|
|
|
103
106
|
throw new Error(fault);
|
|
104
107
|
}
|
|
105
108
|
};
|
|
109
|
+
/**
|
|
110
|
+
* The refusal of a key `schemaFields` does not define, or `undefined` when `value`
|
|
111
|
+
* carries none. `where` names the level for the message.
|
|
112
|
+
*
|
|
113
|
+
* ## Why an unknown key is refused rather than ignored
|
|
114
|
+
*
|
|
115
|
+
* A `Query` is plain data, so nothing at runtime stops a caller adding a key the
|
|
116
|
+
* grammar does not have — a `metadata` predicate on an item is the one this repo
|
|
117
|
+
* expects, since metadata is the field an author most plausibly wants to filter on
|
|
118
|
+
* and must not (ADR-0017). Ignored, that key is a predicate the author believes they
|
|
119
|
+
* wrote and no engine honours, and on the append side it is worse: the Postgres
|
|
120
|
+
* guard embeds its match as literal plpgsql text that no type reaches, so a key a
|
|
121
|
+
* read path one day learned to honour would still be dropped by the guard, and the
|
|
122
|
+
* optimistic-concurrency check would escape in silence. Refusing every key the
|
|
123
|
+
* grammar does not define closes that route — a SMUGGLED key — at the one boundary
|
|
124
|
+
* every engine shares, before any engine could disagree. "Every key" means every
|
|
125
|
+
* key `Object.keys` returns: an own, enumerable, string key, which is what a plain
|
|
126
|
+
* object literal or a spread builds. A symbol key, a non-enumerable key or an
|
|
127
|
+
* inherited one is not judged, and no engine reads one either. Core's own query
|
|
128
|
+
* merge (`unionQueries`, `composeProjections`) carries an envelope's unknown key
|
|
129
|
+
* into the merged query rather than dropping it, so composing slices cannot launder
|
|
130
|
+
* a smuggled key past this check.
|
|
131
|
+
*
|
|
132
|
+
* It does not close the neighbouring one, and cannot: a field ADDED to the grammar's
|
|
133
|
+
* schema is a known key from that edit on and passes here, while the plpgsql guard
|
|
134
|
+
* still has to be taught it by hand. That exposure is the Postgres guard's, and its
|
|
135
|
+
* own comment in that engine's DDL says so.
|
|
136
|
+
*
|
|
137
|
+
* The known keys are read off the SCHEMA's own `fields` rather than listed here, so
|
|
138
|
+
* a field added to the grammar is admitted by the same edit that adds it. Only key
|
|
139
|
+
* NAMES are judged: an exact-optional key written as `undefined` is a known key and
|
|
140
|
+
* passes, because which values a key admits is the type's business, not this rule's.
|
|
141
|
+
*/
|
|
142
|
+
exports.assertServableQuery = assertServableQuery;
|
|
143
|
+
const unknownKeyFault = (where, value, schemaFields) => {
|
|
144
|
+
const unknown = Object.keys(value).find(key => !Object.hasOwn(schemaFields, key));
|
|
145
|
+
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';
|
|
146
|
+
};
|
|
147
|
+
/**
|
|
148
|
+
* The unknown-key half of `servableQueryFault`, on its own: the refusal of a key the
|
|
149
|
+
* grammar does not define on the envelope or on any item, or `undefined`.
|
|
150
|
+
*
|
|
151
|
+
* It is the same rule and not a second statement of it — `servableQueryFault` calls
|
|
152
|
+
* this first. It is exported because ONE caller has to tell the two halves apart:
|
|
153
|
+
* the codec's read ledger refuses an unservable SHAPE on its own error channel, and
|
|
154
|
+
* must not report an unknown key as one. An unknown key is not something a slice's
|
|
155
|
+
* tags can fix, so the ledger leaves it to the store, which refuses it as a defect.
|
|
156
|
+
*/
|
|
157
|
+
const unknownQueryKeyFault = query => unknownKeyFault('a query', query, Query.fields) ?? query.items.reduce((fault, item) => fault ?? unknownKeyFault('a query item', item, QueryItem.fields), undefined);
|
|
106
158
|
/**
|
|
107
159
|
* The servable grammar as a TOTAL function: the reason `query` cannot be served,
|
|
108
160
|
* or `undefined` when it can.
|
|
@@ -123,8 +175,12 @@ const assertServableQuery = query => {
|
|
|
123
175
|
* side's own (`projectionWiringFault` returns `string | undefined` for the same
|
|
124
176
|
* reason), so a fault is one exit route and one return type.
|
|
125
177
|
*/
|
|
126
|
-
exports.
|
|
178
|
+
exports.unknownQueryKeyFault = unknownQueryKeyFault;
|
|
127
179
|
const servableQueryFault = query => {
|
|
180
|
+
const unknownKey = unknownQueryKeyFault(query);
|
|
181
|
+
if (unknownKey !== undefined) {
|
|
182
|
+
return unknownKey;
|
|
183
|
+
}
|
|
128
184
|
const {
|
|
129
185
|
items
|
|
130
186
|
} = query;
|
package/dist/cjs/Query.js.map
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"Query.js","names":["_effect","require","_Event","QueryItem","exports","Schema","Struct","types","Array","EventType","tags","Tag","Query","items","matchesQueryItem","event","item","typeOk","length","includes","type","eventTags","Set","every","tag","has","matchesQuery","query","some","matchesSequenced","sequenced","assertServableQuery","fault","servableQueryFault","undefined","Error","classifyServableQuery","kind","only","Arr","isNonEmptyReadonlyArray","
|
|
1
|
+
{"version":3,"file":"Query.js","names":["_effect","require","_Event","QueryItem","exports","Schema","Struct","types","Array","EventType","tags","Tag","Query","items","matchesQueryItem","event","item","typeOk","length","includes","type","eventTags","Set","every","tag","has","matchesQuery","query","some","matchesSequenced","sequenced","assertServableQuery","fault","servableQueryFault","undefined","Error","unknownKeyFault","where","value","schemaFields","unknown","Object","keys","find","key","hasOwn","JSON","stringify","unknownQueryKeyFault","fields","reduce","unknownKey","classifyServableQuery","kind","only","Arr","isNonEmptyReadonlyArray","all","or"],"sources":["../../src/Query.ts"],"sourcesContent":[null],"mappings":";;;;;;AAwBA,IAAAA,OAAA,GAAAC,OAAA;AACA,IAAAC,MAAA,GAAAD,OAAA;AAzBA;;;;;;;;;;;;;;;;;;;;;;;;;AA2BA;;;;AAIO,MAAME,SAAS,GAAAC,OAAA,CAAAD,SAAA,gBAAGE,cAAM,CAACC,MAAM,CAAC;EACrCC,KAAK,eAAEF,cAAM,CAACG,KAAK,CAACC,gBAAS,CAAC;EAC9BC,IAAI,eAAEL,cAAM,CAACG,KAAK,CAACG,UAAG;CACvB,CAAC;AAGF;AACO,MAAMC,KAAK,GAAAR,OAAA,CAAAQ,KAAA,gBAAGP,cAAM,CAACC,MAAM,CAAC;EACjCO,KAAK,eAAER,cAAM,CAACG,KAAK,CAACL,SAAS;CAC9B,CAAC;AAGF;;;;AAIO,MAAMW,gBAAgB,GAAGA,CAACC,KAAe,EAAEC,IAAe,KAAa;EAC5E,MAAMC,MAAM,GAAGD,IAAI,CAACT,KAAK,CAACW,MAAM,KAAK,CAAC,IAAIF,IAAI,CAACT,KAAK,CAACY,QAAQ,CAACJ,KAAK,CAACK,IAAI,CAAC;EACzE,IAAI,CAACH,MAAM,EAAE;IACX,OAAO,KAAK;EACd;EACA,MAAMI,SAAS,GAAG,IAAIC,GAAG,CAASP,KAAK,CAACL,IAAI,CAAC;EAC7C,OAAOM,IAAI,CAACN,IAAI,CAACa,KAAK,CAAEC,GAAG,IAAKH,SAAS,CAACI,GAAG,CAACD,GAAG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]}
|
package/dist/cjs/inMemory.js
CHANGED
|
@@ -11,6 +11,67 @@ var _Event = require("./Event.js");
|
|
|
11
11
|
var _errors = require("./errors.js");
|
|
12
12
|
var _Query = require("./Query.js");
|
|
13
13
|
var _SubscribeMachine = require("./SubscribeMachine.js");
|
|
14
|
+
/**
|
|
15
|
+
* A copy of `event` that shares no mutable structure with it: fresh `data` bytes, a
|
|
16
|
+
* fresh `tags` array, a fresh `metadata` bag and a fresh `occurredAt`. Only `type`
|
|
17
|
+
* and `uuid`, which are strings, are carried as they are.
|
|
18
|
+
*
|
|
19
|
+
* Each copy is chosen for what it does on EVERY input the type admits, not on the
|
|
20
|
+
* common one. `data` is copied through the `Uint8Array` constructor and not with
|
|
21
|
+
* `slice`, because `DcbEvent` admits any `Uint8Array` subclass and a subclass may
|
|
22
|
+
* answer `slice` with a VIEW of the same memory — Node's `Buffer` does. A
|
|
23
|
+
* `DateTime.Utc` is an ordinary object whose fields can be written past its
|
|
24
|
+
* `readonly` type, so `occurredAt` is rebuilt from its instant rather than shared.
|
|
25
|
+
*
|
|
26
|
+
* ## Why the oracle copies at BOTH edges
|
|
27
|
+
*
|
|
28
|
+
* This store is the reference the SQL engines are judged against, and a SQL engine
|
|
29
|
+
* shares nothing with its caller: it serialises on the way in and builds fresh objects
|
|
30
|
+
* on the way out. A store that kept the caller's objects instead would let a caller
|
|
31
|
+
* rewrite the log AFTER the append — mutate a `Uint8Array`, push to a `tags` array,
|
|
32
|
+
* assign into a `metadata` bag — and every later read would see the rewritten event
|
|
33
|
+
* with no append, no position and no wake behind it. A reference that can be edited
|
|
34
|
+
* after the fact judges nothing.
|
|
35
|
+
*
|
|
36
|
+
* So `append` stores a copy (the log never holds a caller's object) and every read
|
|
37
|
+
* path hands out a copy (a reader cannot reach the log through what it was given).
|
|
38
|
+
* Copying on the way in alone would close the first route and leave the second open:
|
|
39
|
+
* the same object would then be shared by every reader of the log.
|
|
40
|
+
*/
|
|
41
|
+
const copyEvent = event => ({
|
|
42
|
+
type: event.type,
|
|
43
|
+
data: new Uint8Array(event.data),
|
|
44
|
+
tags: [...event.tags],
|
|
45
|
+
uuid: event.uuid,
|
|
46
|
+
occurredAt: _effect.DateTime.unsafeMake(_effect.DateTime.toEpochMillis(event.occurredAt)),
|
|
47
|
+
metadata: {
|
|
48
|
+
...event.metadata
|
|
49
|
+
}
|
|
50
|
+
});
|
|
51
|
+
/**
|
|
52
|
+
* A copy of `query` that shares no array with it, taking only the keys the grammar
|
|
53
|
+
* defines.
|
|
54
|
+
*
|
|
55
|
+
* `subscribe` is the one verb that holds a query beyond its own call: the fetch seam
|
|
56
|
+
* judges it again on every page for as long as the subscription runs. Each SQL engine
|
|
57
|
+
* compiles its plan once, when the subscription starts, so an edit the caller makes
|
|
58
|
+
* to its own object afterwards reaches nothing there. The oracle has to answer the
|
|
59
|
+
* same, for the reason it copies events (above): a reference that the caller can
|
|
60
|
+
* change mid-stream judges nothing. Only `types` and `tags` are carried because they
|
|
61
|
+
* are all `matchesQueryItem` reads, and a key the grammar does not define was
|
|
62
|
+
* already refused at the contract decorator before this runs.
|
|
63
|
+
*/
|
|
64
|
+
const copyQuery = query => ({
|
|
65
|
+
items: query.items.map(item => ({
|
|
66
|
+
types: [...item.types],
|
|
67
|
+
tags: [...item.tags]
|
|
68
|
+
}))
|
|
69
|
+
});
|
|
70
|
+
/** A `SequencedEvent` whose event is a `copyEvent` of the stored one. */
|
|
71
|
+
const copySequenced = sequenced => ({
|
|
72
|
+
event: copyEvent(sequenced.event),
|
|
73
|
+
position: sequenced.position
|
|
74
|
+
});
|
|
14
75
|
/** Filter a snapshot by `query` and `after` (strict `position > after`). */
|
|
15
76
|
const filterLog = (log, query, after) => log.filter(sequenced => (after === undefined || sequenced.position > after) && (0, _Query.matchesSequenced)(sequenced, query));
|
|
16
77
|
/** The position of the last event in a slice, or `undefined` when empty. */
|
|
@@ -28,7 +89,7 @@ const readSnapshot = (log, query, options) => {
|
|
|
28
89
|
// when there is nothing to report.
|
|
29
90
|
const head = (options?.limit === undefined ? lastPosition(log) : lastPosition(limited)) ?? _Event.ORIGIN;
|
|
30
91
|
return {
|
|
31
|
-
events: _effect.Stream.fromIterable(limited),
|
|
92
|
+
events: _effect.Stream.fromIterable(limited.map(copySequenced)),
|
|
32
93
|
head
|
|
33
94
|
};
|
|
34
95
|
};
|
|
@@ -80,7 +141,7 @@ const fetchPage = (log, query, from, limit) => {
|
|
|
80
141
|
for (let index = firstIndexAfter(log, from); index < log.length && page.length < limit; index += 1) {
|
|
81
142
|
const sequenced = log[index];
|
|
82
143
|
if ((0, _Query.matchesSequenced)(sequenced, query)) {
|
|
83
|
-
page.push(sequenced);
|
|
144
|
+
page.push(copySequenced(sequenced));
|
|
84
145
|
}
|
|
85
146
|
}
|
|
86
147
|
return page;
|
|
@@ -105,45 +166,51 @@ const make = options => _effect.Effect.gen(function* () {
|
|
|
105
166
|
// is reentrant, so append's inner read re-enters. Here append inlines the
|
|
106
167
|
// read logic instead, so a plain lock suffices.
|
|
107
168
|
mutex.withPermits(1)(_effect.Effect.map(_effect.Ref.get(log), snapshot => readSnapshot(snapshot, query, options)));
|
|
108
|
-
const append = (events, condition) =>
|
|
109
|
-
|
|
110
|
-
|
|
111
|
-
|
|
112
|
-
|
|
113
|
-
|
|
114
|
-
|
|
115
|
-
|
|
116
|
-
|
|
117
|
-
if (
|
|
118
|
-
|
|
119
|
-
|
|
120
|
-
|
|
169
|
+
const append = (events, condition) => _effect.Effect.suspend(() => {
|
|
170
|
+
// The events are copied when the append STARTS, before it waits for the
|
|
171
|
+
// permit, as each SQL engine serialises them before its first suspension:
|
|
172
|
+
// an edit the caller makes while this append is queued must not reach the
|
|
173
|
+
// log here when it could not reach theirs.
|
|
174
|
+
const owned = events.map(copyEvent);
|
|
175
|
+
// Critical section: check + commit are atomic (the exactly-one-wins guarantee).
|
|
176
|
+
return mutex.withPermits(1)(_effect.Effect.gen(function* () {
|
|
177
|
+
const snapshot = yield* _effect.Ref.get(log);
|
|
178
|
+
if (condition !== undefined) {
|
|
179
|
+
const conflicts = filterLog(snapshot, condition.failIfEventsMatch, condition.after);
|
|
180
|
+
// Detect by presence: any matching event after `condition.after`
|
|
181
|
+
// fails the append. The error carries only the condition (see
|
|
182
|
+
// `AppendConditionFailed`); a correct retry re-reads to the new head.
|
|
183
|
+
if (conflicts.length > 0) {
|
|
184
|
+
return yield* new _errors.AppendConditionFailed({
|
|
185
|
+
condition
|
|
186
|
+
});
|
|
187
|
+
}
|
|
121
188
|
}
|
|
122
|
-
|
|
123
|
-
|
|
124
|
-
|
|
125
|
-
|
|
126
|
-
|
|
127
|
-
|
|
128
|
-
|
|
129
|
-
|
|
130
|
-
|
|
131
|
-
|
|
132
|
-
|
|
189
|
+
// Optional test seam between the conflict-check and the commit (see
|
|
190
|
+
// `InMemoryStoreOptions.beforeCommit`). Defaults to `Effect.void`, a
|
|
191
|
+
// synchronous no-op, so the shipped critical section stays atomic by
|
|
192
|
+
// construction; the concurrency contract test injects `Effect.yieldNow()`
|
|
193
|
+
// here to make the exactly-one-wins guard genuinely depend on the mutex.
|
|
194
|
+
yield* beforeCommit;
|
|
195
|
+
const start = yield* _effect.Ref.get(nextPosition);
|
|
196
|
+
const appended = owned.map((event, index) => ({
|
|
197
|
+
event,
|
|
198
|
+
position: start + BigInt(index)
|
|
199
|
+
}));
|
|
200
|
+
const end = start + BigInt(events.length);
|
|
201
|
+
yield* _effect.Ref.set(log, [...snapshot, ...appended]);
|
|
202
|
+
yield* _effect.Ref.set(nextPosition, end);
|
|
203
|
+
// The hub is a WAKE SOURCE and nothing else: the subscribe machine never
|
|
204
|
+
// reads what it carries, and its poll delivers with or without one. That
|
|
205
|
+
// is why suppressing the publish is a legitimate test seam rather than a
|
|
206
|
+
// broken store (see `InMemoryStoreOptions.suppressWake`).
|
|
207
|
+
if (!suppressWake) {
|
|
208
|
+
yield* _effect.PubSub.publishAll(hub, appended);
|
|
209
|
+
}
|
|
210
|
+
// `events` is non-empty, so the last new position is `end - 1`.
|
|
211
|
+
return end - 1n;
|
|
133
212
|
}));
|
|
134
|
-
|
|
135
|
-
yield* _effect.Ref.set(log, [...snapshot, ...appended]);
|
|
136
|
-
yield* _effect.Ref.set(nextPosition, end);
|
|
137
|
-
// The hub is a WAKE SOURCE and nothing else: the subscribe machine never
|
|
138
|
-
// reads what it carries, and its poll delivers with or without one. That
|
|
139
|
-
// is why suppressing the publish is a legitimate test seam rather than a
|
|
140
|
-
// broken store (see `InMemoryStoreOptions.suppressWake`).
|
|
141
|
-
if (!suppressWake) {
|
|
142
|
-
yield* _effect.PubSub.publishAll(hub, appended);
|
|
143
|
-
}
|
|
144
|
-
// `events` is non-empty, so the last new position is `end - 1`.
|
|
145
|
-
return end - 1n;
|
|
146
|
-
}));
|
|
213
|
+
});
|
|
147
214
|
const subscribe = (query, after) =>
|
|
148
215
|
// Take the hub seat HERE, before handing the machine its wake source, so the
|
|
149
216
|
// subscription is established no later than the machine's first `fetch`. That
|
|
@@ -159,9 +226,12 @@ const make = options => _effect.Effect.gen(function* () {
|
|
|
159
226
|
// is nothing left here for a critical section to protect. `append` keeps its
|
|
160
227
|
// permit, which is the whole exactly-one-wins guarantee.
|
|
161
228
|
_effect.Stream.unwrapScoped(_effect.Effect.gen(function* () {
|
|
229
|
+
// Taken when the subscription starts, as the SQL engines compile theirs
|
|
230
|
+
// (see `copyQuery`).
|
|
231
|
+
const judged = copyQuery(query);
|
|
162
232
|
const wakes = yield* _effect.PubSub.subscribe(hub);
|
|
163
233
|
return (0, _SubscribeMachine.subscribeStream)({
|
|
164
|
-
fetch: (from, limit) => _effect.Effect.map(_effect.Ref.get(log), snapshot => fetchPage(snapshot,
|
|
234
|
+
fetch: (from, limit) => _effect.Effect.map(_effect.Ref.get(log), snapshot => fetchPage(snapshot, judged, from, limit)),
|
|
165
235
|
listen: _effect.Stream.fromQueue(wakes),
|
|
166
236
|
pollInterval,
|
|
167
237
|
catchUpPageSize
|
package/dist/cjs/inMemory.js.map
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"inMemory.js","names":["_effect","require","_ContractStore","_DcbEventStore","_Event","_errors","_Query","_SubscribeMachine","
|
|
1
|
+
{"version":3,"file":"inMemory.js","names":["_effect","require","_ContractStore","_DcbEventStore","_Event","_errors","_Query","_SubscribeMachine","copyEvent","event","type","data","Uint8Array","tags","uuid","occurredAt","DateTime","unsafeMake","toEpochMillis","metadata","copyQuery","query","items","map","item","types","copySequenced","sequenced","position","filterLog","log","after","filter","undefined","matchesSequenced","lastPosition","events","at","readSnapshot","options","matched","limited","limit","slice","head","ORIGIN","Stream","fromIterable","firstIndexAfter","low","high","length","mid","fetchPage","from","page","index","push","make","Effect","gen","beforeCommit","void","suppressWake","catchUpPageSize","DEFAULT_CATCH_UP_PAGE_SIZE","pollInterval","DEFAULT_POLL_INTERVAL_MILLIS","Ref","mutex","makeSemaphore","hub","PubSub","unbounded","nextPosition","read","withPermits","get","snapshot","append","condition","suspend","owned","conflicts","failIfEventsMatch","AppendConditionFailed","start","appended","BigInt","end","set","publishAll","subscribe","unwrapScoped","judged","wakes","subscribeStream","fetch","listen","fromQueue","DcbEventStoreInMemory","exports","Layer","effect","DcbEventStore","makeContractStore","makeInMemoryTestLayer"],"sources":["../../src/inMemory.ts"],"sourcesContent":[null],"mappings":";;;;;;AA2BA,IAAAA,OAAA,GAAAC,OAAA;AAEA,IAAAC,cAAA,GAAAD,OAAA;AAEA,IAAAE,cAAA,GAAAF,OAAA;AAEA,IAAAG,MAAA,GAAAH,OAAA;AACA,IAAAI,OAAA,GAAAJ,OAAA;AAEA,IAAAK,MAAA,GAAAL,OAAA;AACA,IAAAM,iBAAA,GAAAN,OAAA;AAMA;;;;;;;;;;;;;;;;;;;;;;;;;;;AA2BA,MAAMO,SAAS,GAAIC,KAAe,KAAgB;EAChDC,IAAI,EAAED,KAAK,CAACC,IAAI;EAChBC,IAAI,EAAE,IAAIC,UAAU,CAACH,KAAK,CAACE,IAAI,CAAC;EAChCE,IAAI,EAAE,CA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
12
|
*
|
|
13
13
|
* - `assertServableQuery` at every verb's entry (read, the append condition's
|
|
14
|
-
* guard query, subscribe) — a non-servable query
|
|
14
|
+
* guard query, subscribe) — a non-servable query, or one carrying a key the
|
|
15
|
+
* grammar does not define, is a DEFECT in every engine, and an append condition
|
|
16
|
+
* carrying a key `AppendCondition` does not define is refused alongside it;
|
|
15
17
|
* - `ReadLimit` decode on `read`'s `limit` — a negative/non-integer limit is a
|
|
16
18
|
* DEFECT (so `read` keeps `E = never`), validated through the branded schema
|
|
17
19
|
* even at an untyped boundary that reaches the store as `unknown`;
|
|
@@ -34,7 +36,7 @@
|
|
|
34
36
|
*/
|
|
35
37
|
import type { Array as Arr, Scope } from 'effect';
|
|
36
38
|
import { Effect, Stream } from 'effect';
|
|
37
|
-
import
|
|
39
|
+
import { AppendCondition } from './AppendCondition.js';
|
|
38
40
|
import type { DcbEventStore, ReadOptions, ReadResponse } from './DcbEventStore.js';
|
|
39
41
|
import type { DcbEvent, Position, SequencedEvent } from './Event.js';
|
|
40
42
|
import type { AppendConditionFailed } from './errors.js';
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"ContractStore.d.ts","sourceRoot":"","sources":["../../src/ContractStore.ts"],"names":[],"mappings":"AAAA
|
|
1
|
+
{"version":3,"file":"ContractStore.d.ts","sourceRoot":"","sources":["../../src/ContractStore.ts"],"names":[],"mappings":"AAAA;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;GAmCG;AACH,OAAO,KAAK,EAAE,KAAK,IAAI,GAAG,EAAE,KAAK,EAAE,MAAM,QAAQ,CAAA;AACjD,OAAO,EAAE,MAAM,EAAqB,MAAM,EAAE,MAAM,QAAQ,CAAA;AAC1D,OAAO,EAAE,eAAe,EAAE,MAAM,mBAAmB,CAAA;AAEnD,OAAO,KAAK,EAAE,aAAa,EAAE,WAAW,EAAE,YAAY,EAAE,MAAM,iBAAiB,CAAA;AAC/E,OAAO,KAAK,EAAE,QAAQ,EAAE,QAAQ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