@kairos-es/core 1.0.0-alpha.4 → 1.0.0-alpha.5
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/README.md +3 -3
- package/dist/cjs/AppendCondition.js +1 -3
- package/dist/cjs/AppendCondition.js.map +1 -1
- package/dist/cjs/AppendIsOwned.js +6 -6
- package/dist/cjs/AppendIsOwned.js.map +1 -1
- package/dist/cjs/ContractStore.js +2 -2
- package/dist/cjs/ContractStore.js.map +1 -1
- package/dist/cjs/DcbEventStore.js +1 -1
- package/dist/cjs/DcbEventStore.js.map +1 -1
- package/dist/cjs/Event.js +29 -13
- package/dist/cjs/Event.js.map +1 -1
- package/dist/cjs/Query.js +1 -1
- package/dist/cjs/Query.js.map +1 -1
- package/dist/cjs/SubscribeMachine.js +20 -22
- package/dist/cjs/SubscribeMachine.js.map +1 -1
- package/dist/cjs/inMemory.js +4 -4
- package/dist/cjs/inMemory.js.map +1 -1
- package/dist/cjs/retryOnConflict.js +4 -10
- package/dist/cjs/retryOnConflict.js.map +1 -1
- package/dist/cjs/testing.js +2 -2
- package/dist/cjs/testing.js.map +1 -1
- package/dist/{dts → dts-cjs}/AppendCondition.d.ts +5 -7
- package/dist/{dts → dts-cjs}/AppendCondition.d.ts.map +1 -1
- package/dist/{dts → dts-cjs}/AppendIsOwned.d.ts +6 -6
- package/dist/{dts → dts-cjs}/AppendIsOwned.d.ts.map +1 -1
- package/dist/{dts → dts-cjs}/ContractStore.d.ts +3 -2
- package/dist/dts-cjs/ContractStore.d.ts.map +1 -0
- package/dist/{dts → dts-cjs}/DcbEventStore.d.ts +2 -2
- package/dist/{dts → dts-cjs}/DcbEventStore.d.ts.map +1 -1
- package/dist/{dts → dts-cjs}/Event.d.ts +31 -20
- package/dist/dts-cjs/Event.d.ts.map +1 -0
- package/dist/{dts → dts-cjs}/Query.d.ts +5 -5
- package/dist/{dts → dts-cjs}/SubscribeMachine.d.ts +11 -15
- package/dist/dts-cjs/SubscribeMachine.d.ts.map +1 -0
- package/dist/{dts → dts-cjs}/inMemory.d.ts.map +1 -1
- package/dist/{dts → dts-cjs}/index.d.ts +1 -1
- package/dist/dts-cjs/package.json +3 -0
- package/dist/{dts → dts-cjs}/retryOnConflict.d.ts +1 -7
- package/dist/dts-cjs/retryOnConflict.d.ts.map +1 -0
- package/dist/{dts → dts-cjs}/testing.d.ts +1 -1
- package/dist/dts-esm/AppendCondition.d.ts +21 -0
- package/dist/dts-esm/AppendCondition.d.ts.map +1 -0
- package/dist/dts-esm/AppendIsOwned.d.ts +78 -0
- package/dist/dts-esm/AppendIsOwned.d.ts.map +1 -0
- package/dist/dts-esm/ContractStore.d.ts +62 -0
- package/dist/dts-esm/ContractStore.d.ts.map +1 -0
- package/dist/dts-esm/DcbEventStore.d.ts +64 -0
- package/dist/dts-esm/DcbEventStore.d.ts.map +1 -0
- package/dist/dts-esm/Event.d.ts +174 -0
- package/dist/dts-esm/Event.d.ts.map +1 -0
- package/dist/dts-esm/Projection.d.ts +124 -0
- package/dist/dts-esm/Projection.d.ts.map +1 -0
- package/dist/dts-esm/Query.d.ts +180 -0
- package/dist/dts-esm/Query.d.ts.map +1 -0
- package/dist/dts-esm/SubscribeMachine.d.ts +175 -0
- package/dist/dts-esm/SubscribeMachine.d.ts.map +1 -0
- package/dist/dts-esm/errors.d.ts +17 -0
- package/dist/dts-esm/errors.d.ts.map +1 -0
- package/dist/dts-esm/inMemory.d.ts +76 -0
- package/dist/dts-esm/inMemory.d.ts.map +1 -0
- package/dist/dts-esm/index.d.ts +40 -0
- package/dist/dts-esm/index.d.ts.map +1 -0
- package/dist/dts-esm/package.json +3 -0
- package/dist/dts-esm/retryOnConflict.d.ts +64 -0
- package/dist/dts-esm/retryOnConflict.d.ts.map +1 -0
- package/dist/dts-esm/testing.d.ts +39 -0
- package/dist/dts-esm/testing.d.ts.map +1 -0
- package/dist/esm/AppendCondition.js +1 -3
- package/dist/esm/AppendCondition.js.map +1 -1
- package/dist/esm/AppendIsOwned.js +6 -6
- package/dist/esm/AppendIsOwned.js.map +1 -1
- package/dist/esm/ContractStore.js +2 -2
- package/dist/esm/ContractStore.js.map +1 -1
- package/dist/esm/DcbEventStore.js +1 -1
- package/dist/esm/DcbEventStore.js.map +1 -1
- package/dist/esm/Event.js +30 -14
- package/dist/esm/Event.js.map +1 -1
- package/dist/esm/Query.js +1 -1
- package/dist/esm/Query.js.map +1 -1
- package/dist/esm/SubscribeMachine.js +21 -23
- package/dist/esm/SubscribeMachine.js.map +1 -1
- package/dist/esm/inMemory.js +5 -5
- package/dist/esm/inMemory.js.map +1 -1
- package/dist/esm/index.js +1 -1
- package/dist/esm/retryOnConflict.js +4 -10
- package/dist/esm/retryOnConflict.js.map +1 -1
- package/dist/esm/testing.js +2 -2
- package/dist/esm/testing.js.map +1 -1
- package/package.json +21 -11
- package/src/AppendCondition.ts +1 -1
- package/src/AppendIsOwned.ts +7 -7
- package/src/ContractStore.ts +5 -4
- package/src/DcbEventStore.ts +3 -3
- package/src/Event.ts +49 -14
- package/src/Query.ts +1 -1
- package/src/SubscribeMachine.ts +38 -31
- package/src/inMemory.ts +6 -6
- package/src/index.ts +1 -1
- package/src/retryOnConflict.ts +6 -11
- package/src/testing.ts +2 -2
- package/testing/package.json +1 -1
- package/dist/dts/ContractStore.d.ts.map +0 -1
- package/dist/dts/Event.d.ts.map +0 -1
- package/dist/dts/SubscribeMachine.d.ts.map +0 -1
- package/dist/dts/retryOnConflict.d.ts.map +0 -1
- /package/dist/{dts → dts-cjs}/Projection.d.ts +0 -0
- /package/dist/{dts → dts-cjs}/Projection.d.ts.map +0 -0
- /package/dist/{dts → dts-cjs}/Query.d.ts.map +0 -0
- /package/dist/{dts → dts-cjs}/errors.d.ts +0 -0
- /package/dist/{dts → dts-cjs}/errors.d.ts.map +0 -0
- /package/dist/{dts → dts-cjs}/inMemory.d.ts +0 -0
- /package/dist/{dts → dts-cjs}/index.d.ts.map +0 -0
- /package/dist/{dts → dts-cjs}/testing.d.ts.map +0 -0
package/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,12 +69,12 @@ 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'));
|
|
61
78
|
/**
|
|
62
79
|
* An event's metadata: a flat bag of strings carrying the circumstances under
|
|
63
80
|
* which the event was RECORDED, never anything the business asserts (ADR-0017).
|
|
@@ -107,10 +124,7 @@ export const EventType = /*#__PURE__*/Schema.String.pipe(/*#__PURE__*/Schema.non
|
|
|
107
124
|
* alone: it would make an event the store accepted unreadable for ever, so a
|
|
108
125
|
* value check belongs at write or nowhere.
|
|
109
126
|
*/
|
|
110
|
-
export const Metadata = /*#__PURE__*/Schema.Record(
|
|
111
|
-
key: Schema.String,
|
|
112
|
-
value: Schema.String
|
|
113
|
-
});
|
|
127
|
+
export const Metadata = /*#__PURE__*/Schema.Record(Schema.String, Schema.String);
|
|
114
128
|
/**
|
|
115
129
|
* An event as stored: an opaque payload plus its type, tags, a
|
|
116
130
|
* producer-supplied `uuid`, producer-supplied `occurredAt` domain time, and its
|
|
@@ -118,6 +132,8 @@ export const Metadata = /*#__PURE__*/Schema.Record({
|
|
|
118
132
|
*
|
|
119
133
|
* `data` is `Uint8Array` (opaque bytes); the store does not interpret it.
|
|
120
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.
|
|
121
137
|
* `occurredAt` is informational only; ordering is by position alone.
|
|
122
138
|
* `metadata` mirrors `tags` rather than `data`: REQUIRED, with an empty bag
|
|
123
139
|
* legal. Required because an absent-versus-empty divergence between engines is
|
|
@@ -127,10 +143,10 @@ export const Metadata = /*#__PURE__*/Schema.Record({
|
|
|
127
143
|
*/
|
|
128
144
|
export const DcbEvent = /*#__PURE__*/Schema.Struct({
|
|
129
145
|
type: EventType,
|
|
130
|
-
data: Schema.
|
|
146
|
+
data: Schema.Uint8Array,
|
|
131
147
|
tags: /*#__PURE__*/Schema.Array(Tag),
|
|
132
|
-
uuid: Schema.
|
|
133
|
-
occurredAt: Schema.
|
|
148
|
+
uuid: /*#__PURE__*/Schema.String.check(/*#__PURE__*/Schema.isGUID()),
|
|
149
|
+
occurredAt: Schema.DateTimeUtcFromString,
|
|
134
150
|
metadata: Metadata
|
|
135
151
|
});
|
|
136
152
|
/** A persisted event: the event together with the position it was written at. */
|
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;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AAqB;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/Query.js
CHANGED
|
@@ -225,7 +225,7 @@ export const classifyServableQuery = query => {
|
|
|
225
225
|
}
|
|
226
226
|
const only = query.items.length === 1 ? query.items[0] : undefined;
|
|
227
227
|
if (only !== undefined && only.tags.length === 0) {
|
|
228
|
-
return Arr.
|
|
228
|
+
return Arr.isReadonlyArrayNonEmpty(only.types) ? {
|
|
229
229
|
kind: 'typeOnly',
|
|
230
230
|
types: only.types
|
|
231
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","unknownKeyFault","where","value","schemaFields","unknown","Object","keys","find","key","hasOwn","JSON","stringify","unknownQueryKeyFault","fields","reduce","unknownKey","classifyServableQuery","kind","only","
|
|
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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F,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;AAE3C;;;;;;;AAOA,OAAO,MAAMC,0BAA0B,GAAG,GAAG;AAE7C;;;;;;;;;;;;;;;;AAgBA,OAAO,MAAMC,4BAA4B,GAAG,IAAI;AAEhD;;;;;;;;;;;;;;;;;;;;;;;;;;;;;AA6BA,OAAO,MAAMC,wBAAwB,GAAG;EACtCC,YAAY,eAAEP,MAAM,CAACQ,WAAW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AM,GAAG,CAAC,EAAE;QACrB,OAAO,CAACP,MAAM,EAAES,IAAI,CAAU;MAChC;MACA;MACA;MACA,OAAOvD,MAAM,CAAC0D,MAAM,CAClB1D,MAAM,CAAC2D,OAAO,CAACzD,KAAK,CAAC0D,IAAI,CAAC9B,IAAI,CAAC,EAAEJ,IAAI,CAACf,YAAY,CAAC,CACpD;IACH;EACF,CAAC,CAAC;EAEJ,OAAON,MAAM,CAACwD,QAAQ,CAAClC,KAAK,IAAIrB,MAAM,EAAGqC,IAAI,IAC3C3C,MAAM,CAAC8D,GAAG,CACRN,SAAS,CAACb,IAAI,CAAC,EACf,CAAC,CAACG,MAAM,EAAES,IAAI,CAAC,KAAK,CAACT,MAAM,EAAE7C,MAAM,CAAC8D,IAAI,CAACR,IAAI,CAAC,CAAU,CACzD,CACF;AACH,CAAC,CAAC,CACH","ignoreList":[]}
|
package/dist/esm/inMemory.js
CHANGED
|
@@ -1,4 +1,4 @@
|
|
|
1
|
-
import { DateTime, Effect, Layer, PubSub, Ref, Stream } from 'effect';
|
|
1
|
+
import { DateTime, Effect, Layer, PubSub, Ref, Semaphore, Stream } from 'effect';
|
|
2
2
|
import { makeContractStore } from "./ContractStore.js";
|
|
3
3
|
import { DcbEventStore } from "./DcbEventStore.js";
|
|
4
4
|
import { ORIGIN } from "./Event.js";
|
|
@@ -37,7 +37,7 @@ const copyEvent = event => ({
|
|
|
37
37
|
data: new Uint8Array(event.data),
|
|
38
38
|
tags: [...event.tags],
|
|
39
39
|
uuid: event.uuid,
|
|
40
|
-
occurredAt: DateTime.
|
|
40
|
+
occurredAt: DateTime.makeUnsafe(DateTime.toEpochMillis(event.occurredAt)),
|
|
41
41
|
metadata: {
|
|
42
42
|
...event.metadata
|
|
43
43
|
}
|
|
@@ -152,7 +152,7 @@ const make = options => Effect.gen(function* () {
|
|
|
152
152
|
const catchUpPageSize = options?.catchUpPageSize ?? DEFAULT_CATCH_UP_PAGE_SIZE;
|
|
153
153
|
const pollInterval = options?.pollInterval ?? DEFAULT_POLL_INTERVAL_MILLIS;
|
|
154
154
|
const log = yield* Ref.make([]);
|
|
155
|
-
const mutex = yield*
|
|
155
|
+
const mutex = yield* Semaphore.make(1);
|
|
156
156
|
const hub = yield* PubSub.unbounded();
|
|
157
157
|
const nextPosition = yield* Ref.make(1n);
|
|
158
158
|
const read = (query, options) =>
|
|
@@ -219,14 +219,14 @@ const make = options => Effect.gen(function* () {
|
|
|
219
219
|
// exclusive cursor is what makes the catch-up/live seam exactly-once, so there
|
|
220
220
|
// is nothing left here for a critical section to protect. `append` keeps its
|
|
221
221
|
// permit, which is the whole exactly-one-wins guarantee.
|
|
222
|
-
Stream.
|
|
222
|
+
Stream.unwrap(Effect.gen(function* () {
|
|
223
223
|
// Taken when the subscription starts, as the SQL engines compile theirs
|
|
224
224
|
// (see `copyQuery`).
|
|
225
225
|
const judged = copyQuery(query);
|
|
226
226
|
const wakes = yield* PubSub.subscribe(hub);
|
|
227
227
|
return subscribeStream({
|
|
228
228
|
fetch: (from, limit) => Effect.map(Ref.get(log), snapshot => fetchPage(snapshot, judged, from, limit)),
|
|
229
|
-
listen: Stream.
|
|
229
|
+
listen: Stream.fromSubscription(wakes),
|
|
230
230
|
pollInterval,
|
|
231
231
|
catchUpPageSize
|
|
232
232
|
}, after);
|
package/dist/esm/inMemory.js.map
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"inMemory.js","names":["DateTime","Effect","Layer","PubSub","Ref","Stream","makeContractStore","DcbEventStore","ORIGIN","AppendConditionFailed","matchesSequenced","DEFAULT_CATCH_UP_PAGE_SIZE","DEFAULT_POLL_INTERVAL_MILLIS","subscribeStream","copyEvent","event","type","data","Uint8Array","tags","uuid","occurredAt","
|
|
1
|
+
{"version":3,"file":"inMemory.js","names":["DateTime","Effect","Layer","PubSub","Ref","Semaphore","Stream","makeContractStore","DcbEventStore","ORIGIN","AppendConditionFailed","matchesSequenced","DEFAULT_CATCH_UP_PAGE_SIZE","DEFAULT_POLL_INTERVAL_MILLIS","subscribeStream","copyEvent","event","type","data","Uint8Array","tags","uuid","occurredAt","makeUnsafe","toEpochMillis","metadata","copyQuery","query","items","map","item","types","copySequenced","sequenced","position","filterLog","log","after","filter","undefined","lastPosition","events","at","readSnapshot","options","matched","limited","limit","slice","head","fromIterable","firstIndexAfter","low","high","length","mid","fetchPage","from","page","index","push","make","gen","beforeCommit","void","suppressWake","catchUpPageSize","pollInterval","mutex","hub","unbounded","nextPosition","read","withPermits","get","snapshot","append","condition","suspend","owned","conflicts","failIfEventsMatch","start","appended","BigInt","end","set","publishAll","subscribe","unwrap","judged","wakes","fetch","listen","fromSubscription","DcbEventStoreInMemory","effect","makeInMemoryTestLayer"],"sources":["../../src/inMemory.ts"],"sourcesContent":[null],"mappings":"AA2BA,SAASA,QAAQ,EAAEC,MAAM,EAAEC,KAAK,EAAEC,MAAM,EAAEC,GAAG,EAAEC,SAAS,EAAEC,MAAM,QAAQ,QAAQ;AAEhF,SAASC,iBAAiB,QAA+B,oBAAiB;AAE1E,SAASC,aAAa,QAAQ,oBAAiB;AAE/C,SAASC,MAAM,QAAQ,YAAS;AAChC,SAASC,qBAAqB,QAAQ,aAAU;AAEhD,SAASC,gBAAgB,QAAQ,YAAS;AAC1C,SACEC,0BAA0B,EAC1BC,4BAA4B,EAC5BC,eAAe,QACV,uBAAoB;AAE3B;;;;;;;;;;;;;;;;;;;;;;;;;;;AA2BA,MAAMC,SAAS,GAAIC,KAAe,KAAgB;EAChDC,IAAI,EAAED,KAAK,CAACC,IAAI;EAChBC,IAAI,EAAE,IAAIC,UAAU,CAACH,KAAK,CAACE,IAAI,CAAC;EAChCE,IAAI,EAAE,CAAC,GAAGJ,KAAK,CAACI,IAAI,CAAC;EACrBC,IAAI,EAAEL,KAAK,CAACK,IAAI;EAChBC,UAAU,EAAEtB,QAAQ,CAACuB,UAAU,CAACvB,QAAQ,CAACwB,aAAa,CAACR,KAAK,CAACM,UAAU,CAAC,CAAC;EACzEG,QAAQ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AAM,GAAGhE,SAAS,CAACC,KAAK,CAAC;IAC/B,MAAMgE,KAAK,GAAG,OAAOxF,MAAM,CAACqF,SAAS,CAACnB,GAAG,CAAC;IAC1C,OAAOvD,eAAe,CACpB;MACE8E,KAAK,EAAEA,CAACnC,IAAI,EAAEV,KAAK,KACjB9C,MAAM,CAAC4B,GAAG,CAACzB,GAAG,CAACsE,GAAG,CAACtC,GAAG,CAAC,EAAGuC,QAAQ,IAChCnB,SAAS,CAACmB,QAAQ,EAAEe,MAAM,EAAEjC,IAAI,EAAEV,KAAK,CAAC,CACzC;MACH8C,MAAM,EAAEvF,MAAM,CAACwF,gBAAgB,CAACH,KAAK,CAAC;MACtCxB,YAAY;MACZD;KACD,EACD7B,KAAK,CACN;EACH,CAAC,CAAC,CACH;EAEH,OAAO;IAAEmC,IAAI;IAAEI,MAAM;IAAEY;EAAS,CAAW;AAC7C,CAAC,CAAC;AAEJ;AACA,OAAO,MAAMO,qBAAqB,gBAA+B7F,KAAK,CAAC8F,MAAM,CAC3ExF,aAAa,eACbP,MAAM,CAAC4B,GAAG,cAACgC,IAAI,EAAE,EAAEtD,iBAAiB,CAAC,CACtC;AAED;;;;;;;;;;;AAWA,OAAO,MAAM0F,qBAAqB,GAChCrD,OAA6B,IAE7B1C,KAAK,CAAC8F,MAAM,CAACxF,aAAa,EAAEP,MAAM,CAAC4B,GAAG,CAACgC,IAAI,CAACjB,OAAO,CAAC,EAAErC,iBAAiB,CAAC,CAAC","ignoreList":[]}
|
package/dist/esm/index.js
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
/**
|
|
2
2
|
* @kairos-es/core: DCB-first event-sourcing contract and in-memory store for
|
|
3
|
-
* Effect
|
|
3
|
+
* Effect.
|
|
4
4
|
*
|
|
5
5
|
* Exposes the domain types (`DcbEvent`, `SequencedEvent`, `Position`, `Tag`,
|
|
6
6
|
* `EventType`), the selection language (`Query`, `QueryItem`, the pure match
|
|
@@ -35,21 +35,15 @@
|
|
|
35
35
|
* jitter draws from `Random.next`, a default service on the same footing as the
|
|
36
36
|
* clock rather than a host `Math.random`. No `node:*`, no wall-clock reading, no
|
|
37
37
|
* ungoverned RNG.
|
|
38
|
-
*
|
|
39
|
-
* Effect v3 caveat: the `Schedule` API below is the THREE-type-parameter
|
|
40
|
-
* `Schedule<Out, In, R>` that `effect@3` exports, with `Schedule.intersect`. The
|
|
41
|
-
* currently-published docs show a newer four-type-parameter `Schedule` without
|
|
42
|
-
* `intersect` — do not copy them; this file is written against the installed
|
|
43
|
-
* `effect@3` type definitions.
|
|
44
38
|
*/
|
|
45
39
|
import { Effect, Predicate, Schedule } from 'effect';
|
|
46
40
|
/**
|
|
47
41
|
* The default conflict backoff: exponential from 20ms, jittered, capped at five
|
|
48
42
|
* retries.
|
|
49
43
|
*
|
|
50
|
-
* `Schedule.
|
|
51
|
-
* `recurs(5)` arm is what bounds the attempts and the
|
|
52
|
-
* spaces them. Jitter matters more here than in a typical backoff: contending
|
|
44
|
+
* `Schedule.max` continues only while BOTH schedules continue, waiting the longer
|
|
45
|
+
* of their two delays, so the `recurs(5)` arm is what bounds the attempts and the
|
|
46
|
+
* exponential arm is what spaces them. Jitter matters more here than in a typical backoff: contending
|
|
53
47
|
* deciders conflict precisely because they read the same boundary at the same
|
|
54
48
|
* time, so an unjittered backoff would re-synchronise them into the same conflict
|
|
55
49
|
* on every round. The figures are the conventional starting point (Emmett,
|
|
@@ -57,7 +51,7 @@ import { Effect, Predicate, Schedule } from 'effect';
|
|
|
57
51
|
* command with a tighter latency budget, or one contending harder, should pass its
|
|
58
52
|
* own schedule.
|
|
59
53
|
*/
|
|
60
|
-
const conflictBackoff = /*#__PURE__*/Schedule.
|
|
54
|
+
const conflictBackoff = /*#__PURE__*/Schedule.max([/*#__PURE__*/Schedule.jittered(/*#__PURE__*/Schedule.exponential('20 millis', 2)), /*#__PURE__*/Schedule.recurs(5)]);
|
|
61
55
|
/**
|
|
62
56
|
* Retry `command` while — and only while — it fails `AppendConditionFailed`.
|
|
63
57
|
*
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"retryOnConflict.js","names":["Effect","Predicate","Schedule","conflictBackoff","
|
|
1
|
+
{"version":3,"file":"retryOnConflict.js","names":["Effect","Predicate","Schedule","conflictBackoff","max","jittered","exponential","recurs","retryOnConflict","command","schedule","retry","while","isTagged"],"sources":["../../src/retryOnConflict.ts"],"sourcesContent":[null],"mappings":"AAAA;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;AAsCA,SAASA,MAAM,EAAEC,SAAS,EAAEC,QAAQ,QAAQ,QAAQ;AAGpD;;;;;;;;;;;;;;AAcA,MAAMC,eAAe,gBAAGD,QAAQ,CAACE,GAAG,CAAC,cACnCF,QAAQ,CAACG,QAAQ,cAACH,QAAQ,CAACI,WAAW,CAAC,WAAW,EAAE,CAAC,CAAC,CAAC,eACvDJ,QAAQ,CAACK,MAAM,CAAC,CAAC,CAAC,CACnB,CAAC;AAEF;;;;;;;;;;;;;;;;;;;;;;AAsBA,OAAO,MAAMC,eAAe,GAAGA,CAC7BC,OAAuD,EACvDC,QAAA,GAKIP,eAAe,KAEnBH,MAAM,CAACW,KAAK,CAACF,OAAO,EAAE;EACpBC,QAAQ;EACRE,KAAK,EAAEX,SAAS,CAACY,QAAQ,CAAC,uBAAuB;CAClD,CAAC","ignoreList":[]}
|
package/dist/esm/testing.js
CHANGED
|
@@ -20,10 +20,10 @@ import { DateTime } from 'effect';
|
|
|
20
20
|
*
|
|
21
21
|
* Ordering in the log is by `position` alone, so an event's `occurredAt` is
|
|
22
22
|
* informational; pinning it to the epoch keeps serialised bytes and comparisons
|
|
23
|
-
* stable across runs. Built via `DateTime.
|
|
23
|
+
* stable across runs. Built via `DateTime.makeUnsafe(0)` (the value is a
|
|
24
24
|
* compile-time constant, not read from the host clock).
|
|
25
25
|
*/
|
|
26
|
-
export const EPOCH = /*#__PURE__*/DateTime.
|
|
26
|
+
export const EPOCH = /*#__PURE__*/DateTime.makeUnsafe(0);
|
|
27
27
|
/**
|
|
28
28
|
* Build a fresh, deterministic uuid generator: a zero-based counter producing
|
|
29
29
|
* RFC-4122 v4-shaped ids `00000000-0000-4000-8000-<counter as 12 hex digits>`,
|
package/dist/esm/testing.js.map
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"testing.js","names":["DateTime","EPOCH","
|
|
1
|
+
{"version":3,"file":"testing.js","names":["DateTime","EPOCH","makeUnsafe","makeSequentialUuid","counter","suffix","toString","padStart"],"sources":["../../src/testing.ts"],"sourcesContent":[null],"mappings":"AAAA;;;;;;;;;;;;;;;;AAgBA,SAASA,QAAQ,QAAQ,QAAQ;AAEjC;;;;;;;;AAQA,OAAO,MAAMC,KAAK,gBAAGD,QAAQ,CAACE,UAAU,CAAC,CAAC,CAAC;AAE3C;;;;;;;;;;;AAWA,OAAO,MAAMC,kBAAkB,GAAGA,CAAA,KAAqB;EACrD,IAAIC,OAAO,GAAG,CAAC;EACf,OAAO,MAAK;IACV,MAAMC,MAAM,GAAGD,OAAO,CAACE,QAAQ,CAAC,EAAE,CAAC,CAACC,QAAQ,CAAC,EAAE,EAAE,GAAG,CAAC;IACrDH,OAAO,IAAI,CAAC;IACZ,OAAO,2BAA2BC,MAAM,EAAE;EAC5C,CAAC;AACH,CAAC","ignoreList":[]}
|
package/package.json
CHANGED
|
@@ -1,7 +1,7 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@kairos-es/core",
|
|
3
|
-
"version": "1.0.0-alpha.
|
|
4
|
-
"description": "DCB-first event-sourcing contract and in-memory store for Effect
|
|
3
|
+
"version": "1.0.0-alpha.5",
|
|
4
|
+
"description": "DCB-first event-sourcing contract and in-memory store for Effect 4",
|
|
5
5
|
"license": "BSD-3-Clause",
|
|
6
6
|
"repository": {
|
|
7
7
|
"type": "git",
|
|
@@ -11,28 +11,38 @@
|
|
|
11
11
|
"sideEffects": [],
|
|
12
12
|
"homepage": "https://github.com/neverbland/kairos-es",
|
|
13
13
|
"peerDependencies": {
|
|
14
|
-
"effect": "^
|
|
14
|
+
"effect": "^4.0.5"
|
|
15
15
|
},
|
|
16
16
|
"main": "./dist/cjs/index.js",
|
|
17
17
|
"module": "./dist/esm/index.js",
|
|
18
|
-
"types": "./dist/dts/index.d.ts",
|
|
18
|
+
"types": "./dist/dts-cjs/index.d.ts",
|
|
19
19
|
"exports": {
|
|
20
20
|
".": {
|
|
21
|
-
"
|
|
22
|
-
|
|
23
|
-
|
|
21
|
+
"import": {
|
|
22
|
+
"types": "./dist/dts-esm/index.d.ts",
|
|
23
|
+
"default": "./dist/esm/index.js"
|
|
24
|
+
},
|
|
25
|
+
"require": {
|
|
26
|
+
"types": "./dist/dts-cjs/index.d.ts",
|
|
27
|
+
"default": "./dist/cjs/index.js"
|
|
28
|
+
}
|
|
24
29
|
},
|
|
25
30
|
"./testing": {
|
|
26
|
-
"
|
|
27
|
-
|
|
28
|
-
|
|
31
|
+
"import": {
|
|
32
|
+
"types": "./dist/dts-esm/testing.d.ts",
|
|
33
|
+
"default": "./dist/esm/testing.js"
|
|
34
|
+
},
|
|
35
|
+
"require": {
|
|
36
|
+
"types": "./dist/dts-cjs/testing.d.ts",
|
|
37
|
+
"default": "./dist/cjs/testing.js"
|
|
38
|
+
}
|
|
29
39
|
},
|
|
30
40
|
"./package.json": "./package.json"
|
|
31
41
|
},
|
|
32
42
|
"typesVersions": {
|
|
33
43
|
"*": {
|
|
34
44
|
"testing": [
|
|
35
|
-
"./dist/dts/testing.d.ts"
|
|
45
|
+
"./dist/dts-cjs/testing.d.ts"
|
|
36
46
|
]
|
|
37
47
|
}
|
|
38
48
|
}
|
package/src/AppendCondition.ts
CHANGED
|
@@ -13,6 +13,6 @@ import { Query } from './Query'
|
|
|
13
13
|
|
|
14
14
|
export const AppendCondition = Schema.Struct({
|
|
15
15
|
failIfEventsMatch: Query,
|
|
16
|
-
after: Schema.
|
|
16
|
+
after: Schema.optionalKey(Position),
|
|
17
17
|
})
|
|
18
18
|
export type AppendCondition = typeof AppendCondition.Type
|
package/src/AppendIsOwned.ts
CHANGED
|
@@ -30,15 +30,15 @@
|
|
|
30
30
|
*
|
|
31
31
|
* ## Present means refused, so a sanctioned append REMOVES the marker
|
|
32
32
|
*
|
|
33
|
-
* The check reads the
|
|
33
|
+
* The check reads the service through `Effect.serviceOption`, so its ABSENCE is the
|
|
34
34
|
* normal case and costs the `append` signature nothing — `DcbEventStore.append`
|
|
35
35
|
* keeps `R = never` and no caller provides anything. Presence is what refuses.
|
|
36
36
|
*
|
|
37
37
|
* That shape decides how the two legitimate appends inside a bracket get through,
|
|
38
38
|
* and there is only one route: run with the marker STRIPPED from the context
|
|
39
|
-
* (`Effect.
|
|
39
|
+
* (`Effect.updateContext` over `Context.omit(AppendIsOwned)`). The bracket's own
|
|
40
40
|
* closing append is issued outside the scope it provided the marker in, and the
|
|
41
|
-
* codec's escape hatch strips it explicitly. Neither needs a second
|
|
41
|
+
* codec's escape hatch strips it explicitly. Neither needs a second service, a
|
|
42
42
|
* sanctioning flag or a mutable cell, and there is no way to be exempt by
|
|
43
43
|
* accident: an append is either lexically outside the marked region or it says in
|
|
44
44
|
* as many words that it is removing the marker.
|
|
@@ -50,13 +50,13 @@ import { Context, Effect } from 'effect'
|
|
|
50
50
|
* owns it.
|
|
51
51
|
*
|
|
52
52
|
* `by` is a human-readable owner name and exists for the defect message alone —
|
|
53
|
-
* the refusal is decided by the
|
|
53
|
+
* the refusal is decided by the service's PRESENCE, never by this value, so nothing
|
|
54
54
|
* branches on it and no caller need agree on a vocabulary for it.
|
|
55
55
|
*/
|
|
56
|
-
export class AppendIsOwned extends Context.
|
|
56
|
+
export class AppendIsOwned extends Context.Service<
|
|
57
57
|
AppendIsOwned,
|
|
58
58
|
{ readonly by: string }
|
|
59
|
-
>() {}
|
|
59
|
+
>()('@kairos-es/core/AppendIsOwned') {}
|
|
60
60
|
|
|
61
61
|
/**
|
|
62
62
|
* Die if an append is already owned here; do nothing otherwise.
|
|
@@ -70,7 +70,7 @@ export class AppendIsOwned extends Context.Tag('@kairos-es/core/AppendIsOwned')<
|
|
|
70
70
|
* its escape hatch for a deliberate second append — which is what makes a defect
|
|
71
71
|
* affordable here.
|
|
72
72
|
*
|
|
73
|
-
* `Effect.serviceOption` is what keeps this free: it reads the
|
|
73
|
+
* `Effect.serviceOption` is what keeps this free: it reads the service if present and
|
|
74
74
|
* adds NOTHING to the requirement channel, so every existing append is unchanged
|
|
75
75
|
* and unprovisioned.
|
|
76
76
|
*/
|
package/src/ContractStore.ts
CHANGED
|
@@ -8,7 +8,8 @@
|
|
|
8
8
|
* channel (`never` for the pure in-memory engine; `SqlError` for either SQL one).
|
|
9
9
|
* The decorator wraps those mechanics with the policy the contract demands — the
|
|
10
10
|
* policy the first two engines hand-duplicated, with the Postgres one even
|
|
11
|
-
* needing a bespoke `catchAll`/`instanceof
|
|
11
|
+
* needing a bespoke `catchAll`/`instanceof` (Effect 3's `catchAll`, which Effect 4
|
|
12
|
+
* names `catch`):
|
|
12
13
|
*
|
|
13
14
|
* - `assertServableQuery` at every verb's entry (read, the append condition's
|
|
14
15
|
* guard query, subscribe) — a non-servable query, or one carrying a key the
|
|
@@ -75,7 +76,7 @@ export interface RawDcbEventStore<E> {
|
|
|
75
76
|
*/
|
|
76
77
|
export const makeContractStore = <E>(
|
|
77
78
|
raw: RawDcbEventStore<E>,
|
|
78
|
-
): DcbEventStore['
|
|
79
|
+
): DcbEventStore['Service'] => ({
|
|
79
80
|
read: (query, options) =>
|
|
80
81
|
Effect.suspend(() => {
|
|
81
82
|
// Defects (surface when the Effect runs), keeping `read` at `E = never`.
|
|
@@ -90,7 +91,7 @@ export const makeContractStore = <E>(
|
|
|
90
91
|
append: (events, condition) =>
|
|
91
92
|
// The ownership refusal runs FIRST and sits OUTSIDE the suspend, because it is
|
|
92
93
|
// the only one of append's checks that is EFFECTFUL: it consults a
|
|
93
|
-
// `Context.
|
|
94
|
+
// `Context.Service` rather than inspecting the arguments. `Effect.flatMap` over an
|
|
94
95
|
// already-lazy effect defers it exactly as the suspend defers the throws below,
|
|
95
96
|
// so nothing runs at the call site either way; what it buys is that the
|
|
96
97
|
// "you are inside a bracket" defect arrives before any argument is judged, which
|
|
@@ -156,7 +157,7 @@ export const makeContractStore = <E>(
|
|
|
156
157
|
// engine's channel simply answers false and dies as it should. It also
|
|
157
158
|
// narrows the raw `AppendConditionFailed | E` to the contract's single
|
|
158
159
|
// error, which is what keeps `append` at `E = AppendConditionFailed`.
|
|
159
|
-
return Effect.
|
|
160
|
+
return Effect.catch(raw.append(events, condition), (error) =>
|
|
160
161
|
Predicate.isTagged('AppendConditionFailed')(error)
|
|
161
162
|
? Effect.fail(error)
|
|
162
163
|
: Effect.die(error),
|