@kairos-es/store-postgres 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.
Files changed (91) hide show
  1. package/README.md +61 -29
  2. package/dist/cjs/clients.js +34 -24
  3. package/dist/cjs/clients.js.map +1 -1
  4. package/dist/cjs/config.js +9 -15
  5. package/dist/cjs/config.js.map +1 -1
  6. package/dist/cjs/ensureSchema.js +8 -3
  7. package/dist/cjs/ensureSchema.js.map +1 -1
  8. package/dist/cjs/index.js.map +1 -1
  9. package/dist/cjs/internal/ddl.js +29 -12
  10. package/dist/cjs/internal/ddl.js.map +1 -1
  11. package/dist/cjs/internal/matchSql.js +57 -4
  12. package/dist/cjs/internal/matchSql.js.map +1 -1
  13. package/dist/cjs/internal/readPlan.js +33 -5
  14. package/dist/cjs/internal/readPlan.js.map +1 -1
  15. package/dist/cjs/internal/transport.js +42 -15
  16. package/dist/cjs/internal/transport.js.map +1 -1
  17. package/dist/cjs/store.js +30 -25
  18. package/dist/cjs/store.js.map +1 -1
  19. package/dist/dts-cjs/clients.d.ts +66 -0
  20. package/dist/dts-cjs/clients.d.ts.map +1 -0
  21. package/dist/{dts → dts-cjs}/config.d.ts +9 -19
  22. package/dist/{dts → dts-cjs}/config.d.ts.map +1 -1
  23. package/dist/{dts → dts-cjs}/ensureSchema.d.ts +8 -3
  24. package/dist/dts-cjs/ensureSchema.d.ts.map +1 -0
  25. package/dist/{dts → dts-cjs}/index.d.ts +4 -3
  26. package/dist/dts-cjs/index.d.ts.map +1 -0
  27. package/dist/{dts → dts-cjs}/internal/ddl.d.ts +1 -1
  28. package/dist/{dts → dts-cjs}/internal/ddl.d.ts.map +1 -1
  29. package/dist/{dts → dts-cjs}/internal/matchSql.d.ts +26 -2
  30. package/dist/dts-cjs/internal/matchSql.d.ts.map +1 -0
  31. package/dist/{dts → dts-cjs}/internal/readPlan.d.ts +1 -1
  32. package/dist/{dts → dts-cjs}/internal/readPlan.d.ts.map +1 -1
  33. package/dist/{dts → dts-cjs}/internal/transport.d.ts +34 -19
  34. package/dist/dts-cjs/internal/transport.d.ts.map +1 -0
  35. package/dist/dts-cjs/package.json +3 -0
  36. package/dist/dts-cjs/store.d.ts.map +1 -0
  37. package/dist/dts-esm/clients.d.ts +66 -0
  38. package/dist/dts-esm/clients.d.ts.map +1 -0
  39. package/dist/dts-esm/config.d.ts +48 -0
  40. package/dist/dts-esm/config.d.ts.map +1 -0
  41. package/dist/dts-esm/ensureSchema.d.ts +40 -0
  42. package/dist/dts-esm/ensureSchema.d.ts.map +1 -0
  43. package/dist/dts-esm/index.d.ts +42 -0
  44. package/dist/dts-esm/index.d.ts.map +1 -0
  45. package/dist/dts-esm/internal/ddl.d.ts +174 -0
  46. package/dist/dts-esm/internal/ddl.d.ts.map +1 -0
  47. package/dist/dts-esm/internal/matchSql.d.ts +164 -0
  48. package/dist/dts-esm/internal/matchSql.d.ts.map +1 -0
  49. package/dist/dts-esm/internal/readPlan.d.ts +72 -0
  50. package/dist/dts-esm/internal/readPlan.d.ts.map +1 -0
  51. package/dist/dts-esm/internal/transport.d.ts +131 -0
  52. package/dist/dts-esm/internal/transport.d.ts.map +1 -0
  53. package/dist/dts-esm/package.json +3 -0
  54. package/dist/dts-esm/store.d.ts +17 -0
  55. package/dist/dts-esm/store.d.ts.map +1 -0
  56. package/dist/esm/clients.js +34 -24
  57. package/dist/esm/clients.js.map +1 -1
  58. package/dist/esm/config.js +9 -15
  59. package/dist/esm/config.js.map +1 -1
  60. package/dist/esm/ensureSchema.js +8 -3
  61. package/dist/esm/ensureSchema.js.map +1 -1
  62. package/dist/esm/index.js +4 -3
  63. package/dist/esm/index.js.map +1 -1
  64. package/dist/esm/internal/ddl.js +30 -13
  65. package/dist/esm/internal/ddl.js.map +1 -1
  66. package/dist/esm/internal/matchSql.js +55 -2
  67. package/dist/esm/internal/matchSql.js.map +1 -1
  68. package/dist/esm/internal/readPlan.js +32 -5
  69. package/dist/esm/internal/readPlan.js.map +1 -1
  70. package/dist/esm/internal/transport.js +42 -15
  71. package/dist/esm/internal/transport.js.map +1 -1
  72. package/dist/esm/store.js +30 -25
  73. package/dist/esm/store.js.map +1 -1
  74. package/package.json +13 -11
  75. package/src/clients.ts +43 -31
  76. package/src/config.ts +12 -13
  77. package/src/ensureSchema.ts +8 -3
  78. package/src/index.ts +4 -3
  79. package/src/internal/ddl.ts +33 -13
  80. package/src/internal/matchSql.ts +63 -1
  81. package/src/internal/readPlan.ts +11 -6
  82. package/src/internal/transport.ts +71 -24
  83. package/src/store.ts +35 -28
  84. package/dist/dts/clients.d.ts +0 -34
  85. package/dist/dts/clients.d.ts.map +0 -1
  86. package/dist/dts/ensureSchema.d.ts.map +0 -1
  87. package/dist/dts/index.d.ts.map +0 -1
  88. package/dist/dts/internal/matchSql.d.ts.map +0 -1
  89. package/dist/dts/internal/transport.d.ts.map +0 -1
  90. package/dist/dts/store.d.ts.map +0 -1
  91. /package/dist/{dts → dts-cjs}/store.d.ts +0 -0
@@ -1,4 +1,4 @@
1
- import { allowedTypesPredicate, eventRecordsetColumns, qualifiedRows, taggedMatchChain } from "./matchSql.js";
1
+ import { allowedTypesPredicate, eventColumnList, eventInsertSelectList, eventRecordsetColumns, qualifiedRows, RECORDSET_ALIAS, taggedMatchChain } from "./matchSql.js";
2
2
  /** Default schema when the config omits one. */
3
3
  export const DEFAULT_SCHEMA = 'public';
4
4
  /** Default table prefix when the config omits one. */
@@ -120,6 +120,16 @@ const lockClause = names => `LOCK TABLE ${quoteQualified(names.mainTable)} IN EX
120
120
  * preserves batch order, and `RETURNING id, tags` is captured into a temp
121
121
  * result set so the tag fan-out and the head can both read it. `data` arrives as
122
122
  * a base64 text field and is `decode(…, 'base64')`-restored to `bytea`.
123
+ *
124
+ * The recordset definition, its projection, the `INSERT INTO (…)` target list and
125
+ * the `SELECT` list are all derived from the one `EVENT_COLUMNS` descriptor in
126
+ * `matchSql.ts`, never written out here. The last two must agree POSITIONALLY and a
127
+ * mismatch is not an error, so deriving both from one walk is what keeps them from
128
+ * falling out of step; a column added without a source is a compile error there.
129
+ * What the compiler does NOT reach is whether the source READS the right field, or
130
+ * whether the column comes back out on the read; the round-trip contract group run
131
+ * against this engine is what proves a new column, and only with a value distinct
132
+ * per column, which is what makes a swap visible.
123
133
  */
124
134
  const insertFanoutNotify = (names, options = {}) => {
125
135
  const main = quoteQualified(names.mainTable);
@@ -137,18 +147,18 @@ const insertFanoutNotify = (names, options = {}) => {
137
147
  IF new_head IS NOT NULL THEN
138
148
  PERFORM pg_notify(${channel}, '1');
139
149
  END IF;` : '';
140
- return ` WITH ne AS (
141
- SELECT type, data, tags, uuid, occurred_at, ordinality
150
+ const ne = RECORDSET_ALIAS;
151
+ return ` WITH ${ne} AS (
152
+ SELECT ${eventColumnList}, ordinality
142
153
  FROM ROWS FROM(
143
154
  jsonb_to_recordset(new_events) AS (${eventRecordsetColumns})
144
155
  ) WITH ORDINALITY
145
156
  ),
146
157
  inserted AS (
147
- INSERT INTO ${main} (type, data, tags, uuid, occurred_at)
148
- SELECT ne.type, decode(ne.data, 'base64'), ne.tags, ne.uuid,
149
- ne.occurred_at
150
- FROM ne
151
- ORDER BY ne.ordinality
158
+ INSERT INTO ${main} (${eventColumnList})
159
+ SELECT ${eventInsertSelectList}
160
+ FROM ${ne}
161
+ ORDER BY ${ne}.ordinality
152
162
  RETURNING id, tags
153
163
  ),
154
164
  fanned AS (
@@ -197,9 +207,12 @@ const conditionalAppendBody = (names, options = {}) => {
197
207
  // its ITEMS — none at all, an item carrying no tags, an item carrying tags —
198
208
  // which between them cover every `Query` value the grammar can express, so a new
199
209
  // SHAPE changes which SQL the read compiles without changing what this body has
200
- // to match. The exposure is the GRAMMAR itself: a new `QueryItem` field, or a new
201
- // meaning for an existing one, is something this body ignores rather than fails
202
- // on, and no `switch` over the shape union would have caught that either.
210
+ // to match. The exposure is the GRAMMAR itself: a field ADDED to `QueryItem`, or a
211
+ // new meaning for an existing one, is something this body ignores rather than
212
+ // fails on, and no `switch` over the shape union would have caught that either. A
213
+ // key the grammar does NOT define never reaches this body: core's
214
+ // `servableQueryFault` refuses it at the contract boundary, which is what keeps a
215
+ // smuggled predicate from being dropped here in silence.
203
216
  const after = 'COALESCE(after_id, 0)';
204
217
  return `
205
218
  DECLARE
@@ -368,14 +381,18 @@ export const ddlStatements = names => {
368
381
  // positions — a rolled-back insert permanently consumes its id, which is
369
382
  // fine: ordering is by id alone and the store is never made gapless.
370
383
  // `data` is NULLABLE (a payload-less event is valid); `occurred_at` is
371
- // informational domain time, never an ordering key.
384
+ // informational domain time, never an ordering key. `metadata` is the
385
+ // event's cleartext context bag (ADR-0017): `jsonb` only so a containment
386
+ // index stays possible without a rewrite, though nothing queries it and no
387
+ // index is built; `NOT NULL DEFAULT '{}'` gives an empty bag one shape.
372
388
  `CREATE TABLE IF NOT EXISTS ${main} (
373
389
  id bigserial,
374
390
  type text NOT NULL,
375
391
  data bytea,
376
392
  tags text[] NOT NULL,
377
393
  uuid text NOT NULL,
378
- occurred_at timestamptz NOT NULL
394
+ occurred_at timestamptz NOT NULL,
395
+ metadata jsonb NOT NULL DEFAULT '{}'::jsonb
379
396
  ) WITH (${AUTOVACUUM_WITH});`,
380
397
  // Covering unique index: uniqueness on id plus INCLUDE(type) so the read
381
398
  // path's id→type lookups are index-only.
@@ -1 +1 @@
1
- {"version":3,"file":"ddl.js","names":["allowedTypesPredicate","eventRecordsetColumns","qualifiedRows","taggedMatchChain","DEFAULT_SCHEMA","DEFAULT_TABLE_PREFIX","MAX_IDENTIFIER_BYTES","utf8ByteLength","value","TextEncoder","encode","length","derivedAtoms","config","schema","tablePrefix","replace","oversizedIdentifier","label","atom","bytes","undefined","resolveNames","problem","Error","mainTable","tagTable","mainIndex","tagIndex","appendFn","appendUnconditionalFn","channel","quoteQualified","name","split","map","join","quoteAtom","quoteLiteral","AUTOVACUUM_WITH","lockClause","names","insertFanoutNotify","options","main","tag","notify","conditionalAppendBody","lock","after","queryItemsExpr","afterExpr","unconditionalAppendBody","appendFunctionStatement","qualifiedName","argList","body","kind","ddlStatements","runDdl","sql","statement","unsafe"],"sources":["../../../src/internal/ddl.ts"],"sourcesContent":[null],"mappings":"AA4BA,SACEA,qBAAqB,EACrBC,qBAAqB,EACrBC,aAAa,EACbC,gBAAgB,QACX,eAAY;AAqCnB;AACA,OAAO,MAAMC,cAAc,GAAG,QAAQ;AACtC;AACA,OAAO,MAAMC,oBAAoB,GAAG,YAAY;AAEhD;;;;;;;AAOA,MAAMC,oBAAoB,GAAG,EAAE;AAE/B;AACA,MAAMC,cAAc,GAAIC,KAAa,IACnC,IAAIC,WAAW,EAAE,CAACC,MAAM,CAACF,KAAK,CAAC,CAACG,MAAM;AAExC;;;;;;AAMA,MAAMC,YAAY,GAAIC,MAGrB,IAA8C;EAC7C,MAAMC,MAAM,GAAGD,MAAM,CAACC,MAAM,IAAIV,cAAc;EAC9C,MAAMW,WAAW,GAAGF,MAAM,CAACE,WAAW,IAAIV,oBAAoB;EAC9D,OAAO,CACL,CAAC,QAAQ,EAAES,MAAM,CAAC,EAClB,CAAC,cAAc,EAAEC,WAAW,CAAC,EAC7B,CAAC,WAAW,EAAE,GAAGA,WAAW,OAAO,CAAC,EACpC,CAAC,YAAY,EAAE,GAAGA,WAAW,cAAc,CAAC,EAC5C,CAAC,WAAW,EAAE,GAAGA,WAAW,kBAAkB,CAAC,EAC/C,CAAC,iBAAiB,EAAE,GAAGA,WAAW,SAAS,CAAC,EAC5C,CAAC,+BAA+B,EAAE,GAAGA,WAAW,uBAAuB,CAAC,EACxE,CAAC,gBAAgB,EAAE,GAAGD,MAAM,IAAIC,WAAW,EAAE,CAACC,OAAO,CAAC,KAAK,EAAE,GAAG,CAAC,CAAC,CACnE;AACH,CAAC;AAED;;;;;;;AAOA,OAAO,MAAMC,mBAAmB,GAAIJ,MAGnC,IAAwB;EACvB,KAAK,MAAM,CAACK,KAAK,EAAEC,IAAI,CAAC,IAAIP,YAAY,CAACC,MAA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MAAME,MAAM,GAAGA,CACpBC,GAAwB,EACxBnB,KAAoB,KAEpBiB,aAAa,CAACjB,KAAK,CAAC,CAACN,GAAG,CAAE0B,SAAS,IAAKD,GAAG,CAACE,MAAM,CAACD,SAAS,CAAC,CAAC","ignoreList":[]}
1
+ {"version":3,"file":"ddl.js","names":["allowedTypesPredicate","eventColumnList","eventInsertSelectList","eventRecordsetColumns","qualifiedRows","RECORDSET_ALIAS","taggedMatchChain","DEFAULT_SCHEMA","DEFAULT_TABLE_PREFIX","MAX_IDENTIFIER_BYTES","utf8ByteLength","value","TextEncoder","encode","length","derivedAtoms","config","schema","tablePrefix","replace","oversizedIdentifier","label","atom","bytes","undefined","resolveNames","problem","Error","mainTable","tagTable","mainIndex","tagIndex","appendFn","appendUnconditionalFn","channel","quoteQualified","name","split","map","join","quoteAtom","quoteLiteral","AUTOVACUUM_WITH","lockClause","names","insertFanoutNotify","options","main","tag","notify","ne","conditionalAppendBody","lock","after","queryItemsExpr","afterExpr","unconditionalAppendBody","appendFunctionStatement","qualifiedName","argList","body","kind","ddlStatements","runDdl","sql","statement","unsafe"],"sources":["../../../src/internal/ddl.ts"],"sourcesContent":[null],"mappings":"AA4BA,SACEA,qBAAqB,EACrBC,eAAe,EACfC,qBAAqB,EACrBC,qBAAqB,EACrBC,aAAa,EACbC,eAAe,EACfC,gBAAgB,QACX,eAAY;AAqCnB;AACA,OAAO,MAAMC,cAAc,GAAG,QAAQ;AACtC;AACA,OAAO,MAAMC,oBAAoB,GAAG,YAAY;AAEhD;;;;;;;AAOA,MAAMC,oBAAoB,GAAG,EAAE;AAE/B;AACA,MAAMC,cAAc,GAAIC,KAAa,IACnC,IAAIC,WAAW,EAAE,CAACC,MAAM,CAACF,KAAK,CAAC,CAACG,MAAM;AAExC;;;;;;AAMA,MAAMC,YAAY,GAAIC,MAGrB,IAA8C;EAC7C,MAAMC,MAAM,GAAGD,MAAM,CAACC,MAAM,IAAIV,cAAc;EAC9C,MAAMW,WAAW,GAAGF,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,CAAC;EAC1C,MAAMZ,MAAM,GAAGuB,SAAS,CAACI,KAAK,CAAC3B,MAAM,CAAC;EACtC,MAAMa,SAAS,GAAGU,SAAS,CAACI,KAAK,CAACd,SAAS,CAAC;EAC5C,MAAMC,QAAQ,GAAGS,SAAS,CAACI,KAAK,CAACb,QAAQ,CAAC;EAE1C,OAAO;EACL;EACA;EACA,+BAA+Bd,MAAM,GAAG;EAExC;EACA;EACA;EACA;EACA;EACA;EACA;EACA;EACA,8BAA8B8B,IAAI;;;;;;;;eAQvBL,eAAe,IAAI;EAE9B;EACA;EACA,qCAAqCZ,SAAS;YACtCiB,IAAI,uBAAuB;EAEnC;EACA;EACA;EACA;EACA;EACA;EACA;EACA;EACA;EACA;EACA;EACA;EACA;EACA;EACA;EACA;EACA,8BAA8BC,GAAG;;mCAEFD,IAAI;eACxBL,eAAe,IAAI;EAE9B;EACA;EACA,8BAA8BX,QAAQ;YAC9BiB,GAAG,kBAAkB;EAE7B;EACAS,uBAAuB,CAACb,KAAK,EAAE;IAAEiB,IAAI,EAAE;EAAa,CAAE,CAAC;EAEvD;EACAJ,uBAAuB,CAACb,KAAK,EAAE;IAAEiB,IAAI,EAAE;EAAe,CAAE,CAAC,CAC1D;AACH,CAAC;AAED;;;;;;AAMA,OAAO,MAAME,MAAM,GAAGA,CACpBC,GAAwB,EACxBpB,KAAoB,KAEpBkB,aAAa,CAAClB,KAAK,CAAC,CAACN,GAAG,CAAE2B,SAAS,IAAKD,GAAG,CAACE,MAAM,CAACD,SAAS,CAAC,CAAC","ignoreList":[]}
@@ -32,10 +32,11 @@
32
32
  * that union, so a column rename here is a COMPILE error there, not a silent drift
33
33
  * the lax read boundary (ADR-0006) would only surface as corrupt data under test.
34
34
  */
35
- const EVENT_COLUMNS = [['type', 'text'], ['data', 'text'], ['tags', 'text[]'], ['uuid', 'text'], ['occurred_at', 'timestamptz']];
35
+ const EVENT_COLUMNS = [['type', 'text'], ['data', 'text'], ['tags', 'text[]'], ['uuid', 'text'], ['occurred_at', 'timestamptz'], ['metadata', 'jsonb']];
36
36
  /**
37
37
  * The `jsonb_to_recordset(new_events) AS (…)` column definitions —
38
- * `type text, data text, tags text[], uuid text, occurred_at timestamptz`. The
38
+ * `type text, data text, tags text[], uuid text, occurred_at timestamptz,
39
+ * metadata jsonb`. The
39
40
  * transport `data` is base64 TEXT (restored to `bytea` by `decode(…, 'base64')`
40
41
  * at insert), which is why it is `text` here, not `bytea`.
41
42
  */
@@ -46,6 +47,58 @@ export const eventRecordsetColumns = /*#__PURE__*/EVENT_COLUMNS.map(([name, type
46
47
  * cannot drift from the recordset.
47
48
  */
48
49
  export const readColumns = (prefix = '') => [`${prefix}id`, ...EVENT_COLUMNS.map(([name]) => `${prefix}${name}`)].join(', ');
50
+ /**
51
+ * The alias the append body gives the expanded `new_events` recordset — the `ne`
52
+ * CTE in `ddl.ts` — which every expression in `EVENT_COLUMN_SOURCE` reads from.
53
+ * Exported so the CTE is declared under the one name its readers assume.
54
+ */
55
+ export const RECORDSET_ALIAS = 'ne';
56
+ /**
57
+ * What the append body inserts into each event column, read from the recordset row.
58
+ *
59
+ * Typed as a `Record` over `EventColumnName` so that adding a column to
60
+ * `EVENT_COLUMNS` without saying where its value comes from is a COMPILE error,
61
+ * rather than a column the insert silently leaves at its default. Every column but
62
+ * `data` and `metadata` passes through as the recordset already types it — `text[]`
63
+ * tags, `timestamptz` — because `jsonb_to_recordset` did the casting; `data`
64
+ * crosses as base64 TEXT and is restored to `bytea` here, its one decode.
65
+ *
66
+ * `metadata` is wrapped in `COALESCE(…, '{}'::jsonb)`, for a caller this package's
67
+ * own client never is. `ensureSchema` replaces each append function with
68
+ * `CREATE OR REPLACE`, which keeps its argument signature, so a client from before
69
+ * the column existed (`1.0.0-alpha.3` and earlier) goes on calling the current body
70
+ * with events JSON that has no `metadata` key. `jsonb_to_recordset` reads an absent
71
+ * key as `NULL`, and an insert that names the column inserts that `NULL` rather than
72
+ * the column's `DEFAULT`, so `NOT NULL` would refuse every such append. The
73
+ * `COALESCE` gives that row the empty bag the `DEFAULT` would have, which is what
74
+ * makes "migrate, then deploy" a safe order from those versions. An event sent WITH
75
+ * a bag passes through unchanged, so what is stored for it does not move.
76
+ */
77
+ const EVENT_COLUMN_SOURCE = {
78
+ type: `${RECORDSET_ALIAS}.type`,
79
+ data: `decode(${RECORDSET_ALIAS}.data, 'base64')`,
80
+ tags: `${RECORDSET_ALIAS}.tags`,
81
+ uuid: `${RECORDSET_ALIAS}.uuid`,
82
+ occurred_at: `${RECORDSET_ALIAS}.occurred_at`,
83
+ metadata: `COALESCE(${RECORDSET_ALIAS}.metadata, '{}'::jsonb)`
84
+ };
85
+ /**
86
+ * The bare event column names — `type, data, tags, uuid, occurred_at, metadata` —
87
+ * which the append body uses twice: as the recordset CTE's projection and as the
88
+ * `INSERT INTO t (…)` target list.
89
+ */
90
+ export const eventColumnList = /*#__PURE__*/EVENT_COLUMNS.map(([name]) => name).join(', ');
91
+ /**
92
+ * The append insert's SELECT list: one source expression per column, in the SAME
93
+ * ORDER as `eventColumnList`.
94
+ *
95
+ * The two halves of `INSERT INTO t (a, b) SELECT x, y` agree POSITION BY POSITION
96
+ * and nothing checks that they do: two columns of compatible type swap without an
97
+ * error at any layer and the data lands in the wrong one. Both halves are therefore
98
+ * one walk of the one descriptor, so the append body has no second ordering to keep
99
+ * in step and no hand-written list for a new column to be missing from.
100
+ */
101
+ export const eventInsertSelectList = /*#__PURE__*/EVENT_COLUMNS.map(([name]) => EVENT_COLUMN_SOURCE[name]).join(', ');
49
102
  /**
50
103
  * The allowed-types filter for a candidate row aliased `m`: an item with no
51
104
  * types matches ANY type; otherwise the event's type must be one of them.
@@ -1 +1 @@
1
- {"version":3,"file":"matchSql.js","names":["EVENT_COLUMNS","eventRecordsetColumns","map","name","type","join","readColumns","prefix","allowedTypesPredicate","typesCol","taggedMatchChain","tokens","queryItemsExpr","tag","afterExpr","qualifiedRows","main","wildcardReadSql","typeOnlyReadSql","taggedReadSql"],"sources":["../../../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A,OAAO,MAAMS,eAAe,GAAID,IAAY,IAC1C,UAAUV,WAAW,EAAE;UACfU,IAAI;;;YAGF;AAEZ;AACA,OAAO,MAAME,eAAe,GAAIF,IAAY,IAC1C,UAAUV,WAAW,EAAE;UACfU,IAAI;;;YAGF;AAEZ;;;;;;AAMA,OAAO,MAAMG,aAAa,GAAGA,CAACH,IAAY,EAAEH,GAAW,KACrD,QAAQH,gBAAgB,CAAC;EAAEE,cAAc,EAAE,WAAW;EAAEE,SAAS,EAAE,IAAI;EAAEE,IAAI;EAAEH;AAAG,CAAE,CAAC;;;MAGjFE,aAAa,CAAC;EAAEC,IAAI;EAAEF,SAAS,EAAE;AAAI,CAAE,CAAC;;;;WAInCR,WAAW,CAAC,IAAI,CAAC;SACnBU,IAAI;;oBAEO","ignoreList":[]}
1
+ {"version":3,"file":"matchSql.js","names":["EVENT_COLUMNS","eventRecordsetColumns","map","name","type","join","readColumns","prefix","RECORDSET_ALIAS","EVENT_COLUMN_SOURCE","data","tags","uuid","occurred_at","metadata","eventColumnList","eventInsertSelectList","allowedTypesPredicate","typesCol","taggedMatchChain","tokens","queryItemsExpr","tag","afterExpr","qualifiedRows","main","wildcardReadSql","typeOnlyReadSql","taggedReadSql"],"sources":["../../../src/internal/matchSql.ts"],"sourcesContent":[null],"mappings":"AAAA;;;;;;;;;;;;;;;;;;;;;;;AAwBA;;;;;;;;;;;AAWA,MAAMA,aAAa,GAAG,CACpB,CAAC,MAAM,EAAE,MAAM,CAAC,EAChB,CAAC,MAAM,EAAE,MAAM,CAAC,EAChB,CAAC,MAAM,EAAE,QAAQ,CAAC,EAClB,CAAC,MAAM,EAAE,MAAM,CAAC,EAChB,CAAC,aAAa,EAAE,aAAa,CAAC,EAC9B,CAAC,UAAU,EAAE,OAAO,CAAC,CAGtB;AAYD;;;;;;;AAOA,OAAO,MAAMC,qBAAqB,gBAAWD,aAAa,CAACE,GAAG,CAC5D,CAAC,CAACC,IAAI,EAAEC,IAAI,CAAC,KAAK,GAA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;;;;;;WAOrCD,MAAM,CAACE,GAAG;wBACGF,MAAM,CAACG,SAAS;;;;;;;;;;;;;IAapC;AAEJ;;;;;;AAMA,OAAO,MAAMC,aAAa,GACxBJ,MAA+C,IAE/C;WACSA,MAAM,CAACK,IAAI;mBACHL,MAAM,CAACG,SAAS;YACvBN,qBAAqB,CAAC,iBAAiB,CAAC,EAAE;AAEtD;AACA,OAAO,MAAMS,eAAe,GAAID,IAAY,IAC1C,UAAUnB,WAAW,EAAE;UACfmB,IAAI;;;YAGF;AAEZ;AACA,OAAO,MAAME,eAAe,GAAIF,IAAY,IAC1C,UAAUnB,WAAW,EAAE;UACfmB,IAAI;;;YAGF;AAEZ;;;;;;AAMA,OAAO,MAAMG,aAAa,GAAGA,CAACH,IAAY,EAAEH,GAAW,KACrD,QAAQH,gBAAgB,CAAC;EAAEE,cAAc,EAAE,WAAW;EAAEE,SAAS,EAAE,IAAI;EAAEE,IAAI;EAAEH;AAAG,CAAE,CAAC;;;MAGjFE,aAAa,CAAC;EAAEC,IAAI;EAAEF,SAAS,EAAE;AAAI,CAAE,CAAC;;;;WAInCjB,WAAW,CAAC,IAAI,CAAC;SACnBmB,IAAI;;oBAEO","ignoreList":[]}
@@ -1,3 +1,26 @@
1
+ /**
2
+ * The read-plan compiler for the Postgres engine, extracted from `store.ts` so it
3
+ * is a self-contained unit depending only on the PRE-QUOTED table names — never on
4
+ * the SQL clients. `store.ts`'s `read` and its `subscribe` — the latter feeding the
5
+ * plan to core's subscribe machine as that machine's `fetch` seam — both compile a
6
+ * plan here and run it against whichever client they hold.
7
+ *
8
+ * `compileFetchPlan` turns a servable `Query` into prepared SQL text plus a
9
+ * cursor-only `bind`, so a long-lived subscription re-binds only the cursor rather
10
+ * than re-dispatching the shape and re-serialising the query JSON on every poll.
11
+ * Which shape a query IS is not decided here: core's `classifyServableQuery` owns
12
+ * that dispatch beside the grammar it dispatches over (`Query.ts`), including the
13
+ * degenerate empty item's routing. The JSON/JSONB transport shapes and
14
+ * (de)serialisers — `EventRow`, `jsonbText`, `toQueryItemsJson`, `rowToSequenced`
15
+ * — live in `internal/transport.ts`, and this module only compiles plans.
16
+ *
17
+ * A plan compiled here is therefore the one place the Postgres engine dispatches
18
+ * a shape in TypeScript, and the exhaustiveness below protects BOTH verbs that
19
+ * compile one — `read`, and the `subscribe` poll sharing its plan. What it cannot
20
+ * reach is the append: its conflict guard covers the same three shapes inside its
21
+ * plpgsql body, where no compiler follows, and `ddl.ts` owns what that rests on
22
+ * instead.
23
+ */
1
24
  import { classifyServableQuery, ORIGIN } from '@kairos-es/core';
2
25
  import { taggedReadSql, typeOnlyReadSql, wildcardReadSql } from "./matchSql.js";
3
26
  import { jsonbText, toQueryItemsJson } from "./transport.js";
@@ -29,11 +52,15 @@ export const compileFetchPlan = (tables, query) => {
29
52
  };
30
53
  case 'typeOnly':
31
54
  {
32
- // node-postgres binds a JS array param as a Postgres array literal, so
33
- // `type = ANY($2)` matches any of the item's types. The item's own list is
34
- // bound as it stands: a branded `EventType` IS its string to the driver, so
35
- // nothing here has to unwrap or copy it.
36
- const types = shape.types;
55
+ // `@effect/sql-pg` binds a JS array of strings as a `text[]` param, so
56
+ // `type = ANY($2)` matches any of the item's types. A branded `EventType` IS
57
+ // its string to the driver, so nothing has to be unwrapped — but the list is
58
+ // COPIED here, at compile time. The driver serialises the array afresh on
59
+ // every `bind`, and a subscription re-binds on every poll, so binding the
60
+ // caller's own array would let an edit the caller makes after subscribing
61
+ // reach the next fetch. The tagged arm is immune by construction, since it
62
+ // serialises once below; this copy is what makes the two arms agree.
63
+ const types = [...shape.types];
37
64
  return {
38
65
  text: typeOnlyReadSql(tables.main),
39
66
  bind: (after, limit) => [after, types, limit]
@@ -1 +1 @@
1
- {"version":3,"file":"readPlan.js","names":["classifyServableQuery","ORIGIN","taggedReadSql","typeOnlyReadSql","wildcardReadSql","jsonbText","toQueryItemsJson","compileFetchPlan","tables","query","shape","kind","text","main","bind","after","limit","types","itemsJson","tag","runFetch","sql","plan","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5BK,GAAG,CAACE,MAAM,CAAWD,IAAI,CAACV,IAAI,EAAEU,IAAI,CAACR,IAAI,CAACC,KAAK,IAAId,MAAM,EAAEe,KAAK,IAAI,IAAI,CAAC,CAAC","ignoreList":[]}
1
+ {"version":3,"file":"readPlan.js","names":["classifyServableQuery","ORIGIN","taggedReadSql","typeOnlyReadSql","wildcardReadSql","jsonbText","toQueryItemsJson","compileFetchPlan","tables","query","shape","kind","text","main","bind","after","limit","types","itemsJson","tag","runFetch","sql","plan","unsafe"],"sources":["../../../src/internal/readPlan.ts"],"sourcesContent":[null],"mappings":"AAAA;;;;;;;;;;;;;;;;;;;;;;;AAyBA,SAASA,qBAAqB,EAAEC,MAAM,QAAoB,iBAAiB;AAG3E,SAASC,aAAa,EAAEC,eAAe,EAAEC,eAAe,QAAQ,eAAY;AAC5E,SAAwBC,SAAS,EAAEC,gBAAgB,QAAQ,gBAAa;AA0BxE;;;;;;;;;;;;;;;;;;AAkBA,OAAO,MAAMC,gBAAgB,GAAGA,CAC9BC,MAAkB,EAClBC,KAAY,KACC;EACb,MAAMC,KAAK,GAAGV,qBAAqB,CAACS,KAAK,CAAC;EAC1C,QAAQC,KAAK,CAACC,IAAI;IAChB,KAAK,UAAU;MACb,OAAO;QACLC,IAAI,EAAER,eAAe,CAACI,MAAM,CAACK,IAAI,CAAC;QAClCC,IAAI,EAAEA,CAACC,KAAK,EAAEC,KAAK,KAAK,CAACD,KAAK,EAAEC,KAAK;OACtC;IACH,KAAK,UAAU;MAAE;QACf;QACA;QACA;QACA;QACA;QACA;QACA;QACA;QACA,MAAMC,KAAK,GAAG,CAAC,GAAGP,KAAK,CAACO,KAAK,CAAC;QAC9B,OAAO;UACLL,IAAI,EAAET,eAAe,CAACK,MAAM,CAACK,IAAI,CAAC;UAClCC,IAAI,EAAEA,CAACC,KAAK,EAAEC,KAAK,KAAK,CAACD,KAAK,EAAEE,KAAK,EAAED,KAAK;SAC7C;MACH;IACA,KAAK,QAAQ;MAAE;QACb;QACA;QACA,MAAME,SAAS,GAAGb,SAAS,CAACC,gBAAgB,CAACG,KAAK,CAAC,CAAC;QACpD,OAAO;UACLG,IAAI,EAAEV,aAAa,CAACM,MAAM,CAACK,IAAI,EAAEL,MAAM,CAACW,GAAG,CAAC;UAC5CL,IAAI,EAAEA,CAACC,KAAK,EAAEC,KAAK,KAAK,CAACE,SAAS,EAAEH,KAAK,EAAEC,KAAK;SACjD;MACH;EACF;AACF,CAAC;AAED;;;;AAIA,OAAO,MAAMI,QAAQ,GAAGA,CACtBC,GAAwB,EACxBC,IAAe,EACfP,KAA2B,EAC3BC,KAA4B,KAE5BK,GAAG,CAACE,MAAM,CAAWD,IAAI,CAACV,IAAI,EAAEU,IAAI,CAACR,IAAI,CAACC,KAAK,IAAId,MAAM,EAAEe,KAAK,IAAI,IAAI,CAAC,CAAC","ignoreList":[]}
@@ -1,16 +1,18 @@
1
- import { DateTime, Encoding } from 'effect';
1
+ import { DateTime } from 'effect';
2
+ import { Base64 } from 'effect/encoding';
2
3
  /**
3
4
  * Serialise a value to a JSON STRING for transport as a `::jsonb`-cast bound
4
5
  * parameter.
5
6
  *
6
- * WHY not `sql.json(value)`: `@effect/sql-pg`'s `json` helper binds the RAW
7
- * value, and node-postgres serialises a JS *array* bound param as a Postgres
8
- * ARRAY literal (`{…}`), not JSON — so `sql.json([...])::jsonb` fails with a
9
- * `22P02` invalid-JSON error (an array literal is not valid JSON). Passing a
10
- * pre-stringified JSON string and casting `::jsonb` sends plain text that
11
- * Postgres parses as JSON, which round-trips reliably for both objects and
12
- * arrays. Kept as a named helper so every JSON-transport call site is consistent
13
- * and the reasoning lives in one place.
7
+ * WHY a string and not `sql.json(value)`: the read plan runs through
8
+ * `sql.unsafe(text, params)` with POSITIONAL parameters, and a positional
9
+ * parameter must be a plain scalar or a flat array of scalars — `@effect/sql-pg`
10
+ * cannot infer a Postgres type for an object or an array of objects, and a
11
+ * `sql.json` fragment is not a value that list can carry. A pre-stringified
12
+ * JSON string binds untyped and the `::jsonb` cast has Postgres parse it, which
13
+ * round-trips reliably for both objects and arrays on the positional path and
14
+ * the tagged-template path alike. Kept as a named helper so every
15
+ * JSON-transport call site is consistent and the reasoning lives in one place.
14
16
  */
15
17
  export const jsonbText = value => JSON.stringify(value);
16
18
  /** Serialise a `Query`'s items into their transport JSON shape. */
@@ -21,17 +23,41 @@ export const toQueryItemsJson = query => query.items.map(item => ({
21
23
  /** Serialise one core `DcbEvent` into its transport JSON shape. */
22
24
  export const toEventJson = event => ({
23
25
  type: event.type,
24
- // `Encoding.encodeBase64` (from `effect`) keeps this dependency-free and pure
25
- // — no `Buffer`, so no `@types/node` and no browser/runtime coupling.
26
- data: Encoding.encodeBase64(event.data),
26
+ // `Base64.encode` (from `effect/encoding`) keeps this dependency-free and pure
27
+ // — no `Buffer`, so no `@types/node` and no browser/runtime coupling. It emits
28
+ // the standard RFC 4648 alphabet with `=` padding, which is what plpgsql's
29
+ // `decode(…, 'base64')` reads.
30
+ data: Base64.encode(event.data),
27
31
  tags: [...event.tags],
28
32
  uuid: event.uuid,
29
- occurred_at: DateTime.formatIso(event.occurredAt)
33
+ occurred_at: DateTime.formatIso(event.occurredAt),
34
+ metadata: event.metadata
30
35
  });
36
+ /**
37
+ * The `metadata` column as the event's bag, checked to be a JSON OBJECT.
38
+ *
39
+ * The store only ever writes an object, but `jsonb` admits any JSON value — an
40
+ * array, a string, a number, a boolean, JSON `null` (which `NOT NULL` does not
41
+ * exclude) — so a hand-written row can hold one. Such a row is corrupt, and
42
+ * handing an event whose `metadata` is not a bag to every projection
43
+ * downstream is worse than stopping at the read. This is the CONTAINER check
44
+ * only; the shape rule itself has one home, core's `Metadata` doc. The VALUES
45
+ * are deliberately not re-checked as strings, because a value check on read
46
+ * alone would make an event the store accepted unreadable for ever.
47
+ */
48
+ const metadataFrom = value => {
49
+ if (typeof value !== 'object' || value === null || Array.isArray(value)) {
50
+ throw new Error(`@kairos-es/store-postgres: the \`metadata\` column did not hold a JSON object (got ${JSON.stringify(value)}).`);
51
+ }
52
+ return value;
53
+ };
31
54
  /**
32
55
  * Map a raw main-table row to a core `SequencedEvent`. `data` NULL → empty bytes
33
56
  * (a payload-less event round-trips to a zero-length `Uint8Array`); `occurred_at`
34
- * Date → `DateTime.Utc`; `id` string → branded `Position`.
57
+ * Date → `DateTime.Utc`; `id` → branded `Position`; `metadata` through
58
+ * `metadataFrom`. The column is `NOT NULL DEFAULT '{}'`, so there is no absent
59
+ * case to reconcile: an event appended with an empty bag reads back as `{}` on
60
+ * this engine exactly as on the in-memory oracle.
35
61
  *
36
62
  * The branded scalars (`type`, `tags`, `uuid`, `position`) are minted by trusted
37
63
  * `as`-cast, NOT by re-running `EventType.make` / `Tag.make` etc. This is
@@ -49,7 +75,8 @@ export const rowToSequenced = row => ({
49
75
  data: row.data ?? new Uint8Array(0),
50
76
  tags: row.tags,
51
77
  uuid: row.uuid,
52
- occurredAt: DateTime.unsafeFromDate(row.occurred_at)
78
+ occurredAt: DateTime.fromDateUnsafe(row.occurred_at),
79
+ metadata: metadataFrom(row.metadata)
53
80
  },
54
81
  position: BigInt(row.id)
55
82
  });
@@ -1 +1 @@
1
- {"version":3,"file":"transport.js","names":["DateTime","Encoding","jsonbText","value","JSON","stringify","toQueryItemsJson","query","items","map","item","types","tags","toEventJson","event","type","data","encodeBase64","uuid","occurred_at","formatIso","occurredAt","rowToSequenced","row","Uint8Array","unsafeFromDate","position","BigInt","id"],"sources":["../../../src/internal/transport.ts"],"sourcesContent":[null],"mappings":"AAsBA,SAASA,QAAQ,EAAEC,QAAQ,QAAQ,QAAQ;AAG3C;;;;;;;;;;;;;AAaA,OAAO,MAAMC,SAAS,GAAIC,KAAc,IAAaC,IAAI,CAACC,SAAS,CAACF,KAAK,CAAC;AAQ1E;AACA,OAAO,MAAMG,gBAAgB,GAAIC,KAAY,IAC3CA,KAAK,CAACC,KAAK,CAACC,GAAG,CAAEC,IAAI,KAAM;EACzBC,KAAK,EAAE,CAAC,GAAGD,IAAI,CAACC,KAAK,CAAC;EACtBC,IAAI,EAAE,CAAC,GAAGF,IAAI,CAACE,IAAI;CACpB,CAAC,CAAC;AA4BL;AACA,OAAO,MAAMC,WAAW,GAAIC,KAAe,KAAiB;EAC1DC,IAAI,EAAED,KAAK,CAACC,IAAI;EAChB;EACA;EACAC,IAAI,EAAEf,QAAQ,CAACgB,YAAY,CAACH,KAAK,CAACE,IAAI,CAAC;EACvCJ,IAAI,EAAE,CAAC,GAAGE,KAAK,CAACF,IAAI,CAAC;EACrBM,IAAI,EAAEJ,KAAK,CAACI,IAAI;EAChBC,WAAW,EAAEnB,QAAQ,CAACoB,SAAS,CAACN,KAAK,CAACO,UAAU;CACjD,CAAC;AA4BF;;;;;;;;;;;;;;;AAeA,OAAO,MAAMC,cAAc,GAAIC,GAAa,KAAsB;EAChET,KAAK,EAAE;IACLC,IAAI,EAAEQ,GAAG,CAACR,IAAwB;IAClCC,IAAI,EAAEO,GAAG,CAACP,IAAI,IAAI,IAAIQ,UAAU,CAAC,CAAC,CAAC;IACnCZ,IAAI,EAAEW,GAAG,CAACX,IAAmC;IAC7CM,IAAI,EAAEK,GAAG,CAACL,IAAwB;IAClCG,UAAU,EAAErB,QAAQ,CAACyB,cAAc,CAACF,GAAG,CAACJ,WAAW;GACpD;EACDO,QAAQ,EAAEC,MAAM,CAACJ,GAAG,CAACK,EAAE;CACxB,CAAC","ignoreList":[]}
1
+ {"version":3,"file":"transport.js","names":["DateTime","Base64","jsonbText","value","JSON","stringify","toQueryItemsJson","query","items","map","item","types","tags","toEventJson","event","type","data","encode","uuid","occurred_at","formatIso","occurredAt","metadata","metadataFrom","Array","isArray","Error","rowToSequenced","row","Uint8Array","fromDateUnsafe","position","BigInt","id"],"sources":["../../../src/internal/transport.ts"],"sourcesContent":[null],"mappings":"AA4BA,SAASA,QAAQ,QAAQ,QAAQ;AACjC,SAASC,MAAM,QAAQ,iBAAiB;AAGxC;;;;;;;;;;;;;;AAcA,OAAO,MAAMC,SAAS,GAAIC,KAAc,I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IAAI,EAAEU,GAAG,CAACV,IAAwB;IAClCG,UAAU,EAAErB,QAAQ,CAAC8B,cAAc,CAACF,GAAG,CAACT,WAAW,CAAC;IACpDG,QAAQ,EAAEC,YAAY,CAACK,GAAG,CAACN,QAAQ;GACpC;EACDS,QAAQ,EAAEC,MAAM,CAACJ,GAAG,CAACK,EAAE;CACxB,CAAC","ignoreList":[]}
package/dist/esm/store.js CHANGED
@@ -46,15 +46,19 @@ const make = (config, names) => Effect.gen(function* () {
46
46
  * Nor would such a parameter be load-bearing for the REPEATABLE READ
47
47
  * transaction this runs inside, which is the trap worth naming, since a
48
48
  * closed-over client LOOKS like it must escape to its own snapshot.
49
- * `@effect/sql` resolves a statement's connection when the statement RUNS,
50
- * from the FIBRE CONTEXT rather than from the client value: `withTransaction`
51
- * acquires one connection and `Effect.locally`s it into
52
- * `FiberRef.currentContext` under its `TransactionConnection` tag, and every
53
- * statement a client builds resolves through a `getConnection` that reads
54
- * that tag first, falling back to the pool acquirer only when it is absent
55
- * (`@effect/sql@0.52` `src/internal/client.ts`). A statement therefore joins
56
- * a transaction by being RUN inside it, and passing the client along the call
57
- * chain neither adds to that nor is required by it. `read-postgres`'s
49
+ * `effect/sql` resolves a statement's connection when the statement RUNS,
50
+ * from the FIBRE CONTEXT: `withTransaction` acquires one connection and
51
+ * provides it under that client's OWN `TransactionConnection` key — one key
52
+ * per `SqlClient` instance — and every statement that client builds resolves
53
+ * through a `getConnection` that reads that key first, falling back to the
54
+ * pool only when it is absent (`effect/sql`'s `SqlClient.make`). So a
55
+ * statement joins a transaction by being RUN inside it AND by being built from
56
+ * the SAME client value that opened it; a statement from any other client,
57
+ * even one over the same database, runs on its own pooled connection outside
58
+ * the transaction. Here every statement in the frame — the isolation `SET`,
59
+ * the row fetch and this `MAX(id)` — comes from `pooled`, the client that
60
+ * opened it, so all three share its connection and its snapshot, and passing
61
+ * the client along the call chain would add nothing. `read-postgres`'s
58
62
  * `pinnedConnection` test observes the same fact from the SERVER: two
59
63
  * statements issued inside one transaction report one `pg_backend_pid()`.
60
64
  *
@@ -130,7 +134,7 @@ const make = (config, names) => Effect.gen(function* () {
130
134
  * conflict (zero rows) vs head (`MAX(id)`) is read from the returned rows by
131
135
  * the caller, never from a caught error.
132
136
  */
133
- const callAppendFn = select => pooled.withTransaction(setLocalLockTimeout(pooled, lockTimeout).pipe(Effect.zipRight(select)));
137
+ const callAppendFn = select => pooled.withTransaction(setLocalLockTimeout(pooled, lockTimeout).pipe(Effect.andThen(select)));
134
138
  const append = (events, condition) => {
135
139
  const eventsJson = events.map(toEventJson);
136
140
  // Raw mechanics: a CONFLICT is `AppendConditionFailed`; a `SqlError` (incl.
@@ -193,22 +197,23 @@ const make = (config, names) => Effect.gen(function* () {
193
197
  /**
194
198
  * Wire core's subscribe machine to the live clients: `fetch` is the
195
199
  * per-subscription compiled read plan run against the pooled client and mapped
196
- * to `SequencedEvent`s; `listen` is the direct client's ref-counted, non-pooled
197
- * LISTEN on this store's channel (the Neon-safe path — `clients.ts` owns why
198
- * there are two clients at all). The plan is compiled ONCE here so the poll
199
- * loop re-binds only the cursor.
200
+ * to `SequencedEvent`s; `listen` is the direct client's LISTEN on this store's
201
+ * channel (the Neon-safe path — `clients.ts` owns why there are two clients at
202
+ * all), which reserves one of that client's connections for as long as the
203
+ * subscription's wake fibre runs and drains its notification queue as a
204
+ * stream. The plan is compiled ONCE here so the poll loop re-binds only the
205
+ * cursor.
200
206
  *
201
207
  * The wake source is `NOTIFY`, and it is a LATENCY optimisation only: the
202
- * machine's periodic position-based poll is what makes delivery correct, which
203
- * matters more here than the general argument for it suggests. The
204
- * `@effect/sql-pg` listen client SWALLOWS connection errors and does not
205
- * auto-reconnect, so a dropped LISTEN typically goes quiet rather than
206
- * erroring — the machine's listen-side retry then never fires, and the poll is
207
- * the ONLY thing that recovers the subscription. The same silence is what a
208
- * Neon pooled endpoint produces if `PgClientDirect` is misconfigured: the
209
- * pooler drops `LISTEN`/`NOTIFY` without complaint and delivery degrades to
210
- * poll-rate rather than failing, which is why that trap is a deployment-time
211
- * wiring choice and not a runtime error.
208
+ * machine's periodic position-based poll is what makes delivery correct. A
209
+ * listening connection that DROPS fails its queue with the `SqlError` it died
210
+ * of, so the machine's listen-side retry re-subscribes on a fresh connection
211
+ * — but the notifications sent while it was down are gone, and only the poll
212
+ * recovers the events they announced. And some failures are silent: a Neon
213
+ * pooled endpoint, if `PgClientDirect` is misconfigured, accepts `LISTEN` and
214
+ * then never delivers a `NOTIFY`, so delivery degrades to poll-rate rather
215
+ * than failing, which is why that trap is a deployment-time wiring choice and
216
+ * not a runtime error.
212
217
  *
213
218
  * `E` is `SqlError.SqlError` — both seams fail with it, so the machine's single
214
219
  * error parameter carries it straight through to `makeContractStore`.
@@ -217,7 +222,7 @@ const make = (config, names) => Effect.gen(function* () {
217
222
  const plan = compileFetchPlan(tables, query);
218
223
  return subscribeStream({
219
224
  fetch: (from, limit) => runFetch(pooled, plan, from, limit).pipe(Effect.map(rows => rows.map(rowToSequenced))),
220
- listen: direct.listen(names.channel),
225
+ listen: Stream.unwrap(Effect.map(direct.listen(names.channel), Stream.fromQueue)),
221
226
  pollInterval,
222
227
  catchUpPageSize
223
228
  }, after);
@@ -1 +1 @@
1
- {"version":3,"file":"store.js","names":["AppendConditionFailed","DcbEventStore","DEFAULT_CATCH_UP_PAGE_SIZE","DEFAULT_POLL_INTERVAL_MILLIS","makeContractStore","ORIGIN","subscribeStream","Effect","Layer","Stream","PgClientDirect","PgClientPooled","decodePostgresStoreConfig","quoteQualified","resolveNames","compileFetchPlan","runFetch","jsonbText","rowToSequenced","toEventJson","toQueryItemsJson","setLocalLockTimeout","sql","lockTimeout","make","config","names","gen","pooled","direct","pollInterval","catchUpPageSize","tables","main","mainTable","tag","tagTable","globalHead","pipe","map","rows","max","undefined","BigInt","readRowsAndHead","query","options","plan","limit","after","lastRow","at","head","id","withTransaction","unsafe","read","events","fromIterable","callAppendFn","select","zipRight","append","condition","eventsJson","appendUnconditionalFn","headFromRows","queryItems","failIfEventsMatch","afterId","appendFn","length","Error","subscribe","fetch","from","listen","channel","layer","decoded","effect"],"sources":["../../src/store.ts"],"sourcesContent":[null],"mappings":"AAkDA,SAEEA,qBAAqB,EACrBC,aAAa,EACbC,0BAA0B,EAC1BC,4BAA4B,EAC5BC,iBAAiB,EACjBC,MAAM,EAGNC,eAAe,QACV,iBAAiB;AACxB,SAA4BC,MAAM,EAAEC,KAAK,EAAcC,MAAM,QAAQ,QAAQ;AAC7E,SAASC,cAAc,EAAEC,cAAc,QAAQ,cAAW;AAC1D,SAASC,yBAAyB,QAAkC,aAAU;AAC9E,SACEC,cAAc,EAEdC,YAAY,QACP,mBAAgB;AACvB,SACEC,gBAAgB,EAEhBC,QAAQ,QACH,wBAAqB;AAC5B,SAEEC,SAAS,EACTC,cAAc,EACdC,WAAW,EACXC,gBAAgB,QACX,yBAAsB;AAE7B;;;;;;;;;AASA,MAAMC,mBAAmB,GAAGA,CAC1BC,GAAwB,EACxBC,WAAmB,KAEnBD,GAAG,qCAAqC,GAAGC,WAAW,GAAG,SAAS;AAEpE;;;;;;AAMA,MAAMC,IAAI,GAAGA,CACXC,MAA2B,EAC3BC,KAAoB,KAMpBnB,MAAM,CAACoB,GAAG,CAAC,aAAS;EAClB,MAAMC,MAAM,GAAG,OAAOjB,cAAc;EACpC,MAAMkB,MAAM,GAAG,OAAOnB,cAAc;EACpC,MAAMa,WAAW,GAAGE,MAAM,CAACF,WAAW,IAAI,CAAC;EAC3C,MAAMO,YAAY,GAAGL,MAAM,CAACK,YAAY,IAAI3B,4BAA4B;EACxE,MAAM4B,eAAe,GAAGN,MAAM,CAACM,eAAe,IAAI7B,0BAA0B;EAE5E;EACA,MAAM8B,MAAM,GAAe;IACzBC,IAAI,EAAEpB,cAAc,CAACa,KAAK,CAACQ,SAAS,CAAC;IACrCC,GAAG,EAAEtB,cAAc,CAACa,KAAK,CAACU,QAAQ;GACnC;EAED;EAEA;;;;;;;;;;;;;;;;;;;;;;;;;;;;EA4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CAACmD,OAAO,CAAC;MACpC/C,YAAY;MACZC;KACD,EACDkB,KAAK,CACN;EACH,CAAC;EAED,OAAO;IAAEO,IAAI;IAAEM,MAAM;IAAEW;EAAS,CAAW;AAC7C,CAAC,CAAC;AAEJ;;;;;;;;;;;AAWA,OAAO,MAAMK,KAAK,GAAGA,CACnBrD,MAAA,GAA8B,EAAE,KACsC;EACtE;EACA;EACA;EACA,MAAMsD,OAAO,GAAGnE,yBAAyB,CAACa,MAAM,CAAC;EACjD,OAAOjB,KAAK,CAACwE,MAAM,CACjB/E,aAAa,EACbM,MAAM,CAACgC,GAAG,CAACf,IAAI,CAACuD,OAAO,EAAEjE,YAAY,CAACiE,OAAO,CAAC,CAAC,EAAE3E,iBAAiB,CAAC,CACpE;AACH,CAAC","ignoreList":[]}
1
+ {"version":3,"file":"store.js","names":["AppendConditionFailed","DcbEventStore","DEFAULT_CATCH_UP_PAGE_SIZE","DEFAULT_POLL_INTERVAL_MILLIS","makeContractStore","ORIGIN","subscribeStream","Effect","Layer","Stream","PgClientDirect","PgClientPooled","decodePostgresStoreConfig","quoteQualified","resolveNames","compileFetchPlan","runFetch","jsonbText","rowToSequenced","toEventJson","toQueryItemsJson","setLocalLockTimeout","sql","lockTimeout","make","config","names","gen","pooled","direct","pollInterval","catchUpPageSize","tables","main","mainTable","tag","tagTable","globalHead","pipe","map","rows","max","undefined","BigInt","readRowsAndHead","query","options","plan","limit","after","lastRow","at","head","id","withTransaction","unsafe","read","events","fromIterable","callAppendFn","select","andThen","append","condition","eventsJson","appendUnconditionalFn","headFromRows","queryItems","failIfEventsMatch","afterId","appendFn","length","Error","subscribe","fetch","from","listen","unwrap","channel","fromQueue","layer","decoded","effect"],"sources":["../../src/store.ts"],"sourcesContent":[null],"mappings":"AAiDA,SAEEA,qBAAqB,EACrBC,aAAa,EACbC,0BAA0B,EAC1BC,4BAA4B,EAC5BC,iBAAiB,EACjBC,MAAM,EAGNC,eAAe,QACV,iBAAiB;AACxB,SAA4BC,MA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EJ;;;;;;;;;;;AAWA,OAAO,MAAMO,KAAK,GAAGA,CACnBvD,MAAA,GAA8B,EAAE,KACsC;EACtE;EACA;EACA;EACA,MAAMwD,OAAO,GAAGrE,yBAAyB,CAACa,MAAM,CAAC;EACjD,OAAOjB,KAAK,CAAC0E,MAAM,CACjBjF,aAAa,EACbM,MAAM,CAACgC,GAAG,CAACf,IAAI,CAACyD,OAAO,EAAEnE,YAAY,CAACmE,OAAO,CAAC,CAAC,EAAE7E,iBAAiB,CAAC,CACpE;AACH,CAAC","ignoreList":[]}
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@kairos-es/store-postgres",
3
- "version": "1.0.0-alpha.3",
3
+ "version": "1.0.0-alpha.5",
4
4
  "description": "Postgres DcbEventStore backend for kairos-es",
5
5
  "license": "BSD-3-Clause",
6
6
  "repository": {
@@ -11,21 +11,23 @@
11
11
  "sideEffects": [],
12
12
  "homepage": "https://github.com/neverbland/kairos-es",
13
13
  "peerDependencies": {
14
- "@effect/experimental": "^0.61.0",
15
- "@effect/platform": "^0.97.0",
16
- "@effect/sql": "^0.52.0",
17
- "@effect/sql-pg": "^0.53.0",
18
- "effect": "^3.22.0",
19
- "@kairos-es/core": "^1.0.0-alpha.3"
14
+ "@effect/sql-pg": "^4.0.5",
15
+ "effect": "^4.0.5",
16
+ "@kairos-es/core": "^1.0.0-alpha.5"
20
17
  },
21
18
  "main": "./dist/cjs/index.js",
22
19
  "module": "./dist/esm/index.js",
23
- "types": "./dist/dts/index.d.ts",
20
+ "types": "./dist/dts-cjs/index.d.ts",
24
21
  "exports": {
25
22
  ".": {
26
- "types": "./dist/dts/index.d.ts",
27
- "import": "./dist/esm/index.js",
28
- "default": "./dist/cjs/index.js"
23
+ "import": {
24
+ "types": "./dist/dts-esm/index.d.ts",
25
+ "default": "./dist/esm/index.js"
26
+ },
27
+ "require": {
28
+ "types": "./dist/dts-cjs/index.d.ts",
29
+ "default": "./dist/cjs/index.js"
30
+ }
29
31
  },
30
32
  "./package.json": "./package.json"
31
33
  },