@emseepea/server 0.23.1 → 0.24.1

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 (65) hide show
  1. package/dist/app-shutdown.d.ts +11 -0
  2. package/dist/app-shutdown.d.ts.map +1 -0
  3. package/dist/app-shutdown.js +46 -0
  4. package/dist/app-shutdown.js.map +1 -0
  5. package/dist/events-cloud-tasks-transport.d.ts +34 -0
  6. package/dist/events-cloud-tasks-transport.d.ts.map +1 -0
  7. package/dist/events-cloud-tasks-transport.js +232 -0
  8. package/dist/events-cloud-tasks-transport.js.map +1 -0
  9. package/dist/events-external.d.ts +62 -0
  10. package/dist/events-external.d.ts.map +1 -0
  11. package/dist/events-external.js +289 -0
  12. package/dist/events-external.js.map +1 -0
  13. package/dist/events-google-sdk-lifetime.d.ts +7 -0
  14. package/dist/events-google-sdk-lifetime.d.ts.map +1 -0
  15. package/dist/events-google-sdk-lifetime.js +70 -0
  16. package/dist/events-google-sdk-lifetime.js.map +1 -0
  17. package/dist/events-postgres-delivery-migrations.d.ts +18 -0
  18. package/dist/events-postgres-delivery-migrations.d.ts.map +1 -0
  19. package/dist/events-postgres-delivery-migrations.js +146 -0
  20. package/dist/events-postgres-delivery-migrations.js.map +1 -0
  21. package/dist/events-postgres-delivery-owned.d.ts +16 -0
  22. package/dist/events-postgres-delivery-owned.d.ts.map +1 -0
  23. package/dist/events-postgres-delivery-owned.js +178 -0
  24. package/dist/events-postgres-delivery-owned.js.map +1 -0
  25. package/dist/events-postgres-delivery.d.ts +29 -0
  26. package/dist/events-postgres-delivery.d.ts.map +1 -0
  27. package/dist/events-postgres-delivery.js +299 -0
  28. package/dist/events-postgres-delivery.js.map +1 -0
  29. package/dist/events-postgres-dispatch-migrations.d.ts +19 -0
  30. package/dist/events-postgres-dispatch-migrations.d.ts.map +1 -0
  31. package/dist/events-postgres-dispatch-migrations.js +162 -0
  32. package/dist/events-postgres-dispatch-migrations.js.map +1 -0
  33. package/dist/events-postgres-dispatch.d.ts +39 -0
  34. package/dist/events-postgres-dispatch.d.ts.map +1 -0
  35. package/dist/events-postgres-dispatch.js +270 -0
  36. package/dist/events-postgres-dispatch.js.map +1 -0
  37. package/dist/events-postgres-lifecycle-migrations.d.ts +17 -0
  38. package/dist/events-postgres-lifecycle-migrations.d.ts.map +1 -0
  39. package/dist/events-postgres-lifecycle-migrations.js +125 -0
  40. package/dist/events-postgres-lifecycle-migrations.js.map +1 -0
  41. package/dist/events-postgres-lifecycle.d.ts +13 -0
  42. package/dist/events-postgres-lifecycle.d.ts.map +1 -0
  43. package/dist/events-postgres-lifecycle.js +176 -0
  44. package/dist/events-postgres-lifecycle.js.map +1 -0
  45. package/dist/events-postgres-migrations.d.ts +32 -0
  46. package/dist/events-postgres-migrations.d.ts.map +1 -0
  47. package/dist/events-postgres-migrations.js +329 -0
  48. package/dist/events-postgres-migrations.js.map +1 -0
  49. package/dist/events-postgres-owned.d.ts +16 -0
  50. package/dist/events-postgres-owned.d.ts.map +1 -0
  51. package/dist/events-postgres-owned.js +161 -0
  52. package/dist/events-postgres-owned.js.map +1 -0
  53. package/dist/events-postgres.d.ts +53 -0
  54. package/dist/events-postgres.d.ts.map +1 -0
  55. package/dist/events-postgres.js +289 -0
  56. package/dist/events-postgres.js.map +1 -0
  57. package/dist/events.d.ts +30 -1
  58. package/dist/events.d.ts.map +1 -1
  59. package/dist/events.js +146 -134
  60. package/dist/events.js.map +1 -1
  61. package/dist/index.d.ts +7 -0
  62. package/dist/index.d.ts.map +1 -1
  63. package/dist/index.js +219 -90
  64. package/dist/index.js.map +1 -1
  65. package/package.json +31 -6
@@ -0,0 +1,329 @@
1
+ import { performance } from "node:perf_hooks";
2
+ import { createOwnedEventOperations } from './events-postgres-owned.js';
3
+ export class PostgresEventMigrationError extends Error {
4
+ code;
5
+ constructor(code) {
6
+ super(code);
7
+ this.code = code;
8
+ this.name = "PostgresEventMigrationError";
9
+ }
10
+ }
11
+ const VERSION = 1;
12
+ const REVISION = "capture-v1";
13
+ const TABLES = ["emseepea_event_capture_migrations", "emseepea_event_capture_subscriptions", "emseepea_event_sources", "emseepea_event_intents"];
14
+ const statements = Object.freeze([
15
+ `CREATE TABLE public.emseepea_event_capture_migrations (
16
+ singleton boolean PRIMARY KEY DEFAULT true CHECK(singleton),version integer NOT NULL,revision text NOT NULL)`,
17
+ `CREATE TABLE public.emseepea_event_capture_subscriptions (
18
+ namespace text NOT NULL,subscription_id text NOT NULL,generation text NOT NULL,
19
+ owner_key text NOT NULL,event_name text NOT NULL,arguments jsonb NOT NULL CHECK(jsonb_typeof(arguments)='object'),
20
+ active boolean NOT NULL,expires_at timestamptz NOT NULL,
21
+ PRIMARY KEY(namespace,subscription_id,generation))`,
22
+ `CREATE UNIQUE INDEX emseepea_event_capture_active_generation ON public.emseepea_event_capture_subscriptions(namespace,subscription_id) WHERE active`,
23
+ `CREATE INDEX emseepea_event_capture_candidates ON public.emseepea_event_capture_subscriptions(namespace,owner_key,event_name,subscription_id,generation) WHERE active`,
24
+ `CREATE TABLE public.emseepea_event_sources (
25
+ namespace text NOT NULL,source_kind text NOT NULL,source_id text NOT NULL,source_version text NOT NULL,
26
+ fingerprint text NOT NULL,event_id text NOT NULL UNIQUE,owner_key text NOT NULL,event_name text NOT NULL,
27
+ occurred_at timestamptz NOT NULL,eligibility_at timestamptz NOT NULL,
28
+ recipient_count integer NOT NULL CHECK(recipient_count>=0),payload jsonb NOT NULL CHECK(jsonb_typeof(payload)='object'),
29
+ PRIMARY KEY(namespace,source_kind,source_id))`,
30
+ `CREATE TABLE public.emseepea_event_intents (
31
+ namespace text NOT NULL,source_kind text NOT NULL,source_id text NOT NULL,
32
+ subscription_id text NOT NULL,generation text NOT NULL,delivery_id text NOT NULL UNIQUE,event_id text NOT NULL,
33
+ state text NOT NULL DEFAULT 'pending' CHECK(state IN ('pending','completed','revoked')),
34
+ PRIMARY KEY(namespace,source_kind,source_id,subscription_id,generation),
35
+ FOREIGN KEY(namespace,source_kind,source_id) REFERENCES public.emseepea_event_sources(namespace,source_kind,source_id) ON DELETE CASCADE)`,
36
+ ]);
37
+ /** Deployment migrations. `createPostgresEventCapture` never applies them. */
38
+ export const postgresEventCaptureMigrations = Object.freeze([Object.freeze({ version: VERSION, revision: REVISION, statements })]);
39
+ const EXPECTED = Object.freeze({
40
+ emseepea_event_capture_migrations: ["singleton:boolean", "version:integer", "revision:text"],
41
+ emseepea_event_capture_subscriptions: ["namespace:text", "subscription_id:text", "generation:text", "owner_key:text", "event_name:text", "arguments:jsonb", "active:boolean", "expires_at:timestamp with time zone"],
42
+ emseepea_event_sources: ["namespace:text", "source_kind:text", "source_id:text", "source_version:text", "fingerprint:text", "event_id:text", "owner_key:text", "event_name:text", "occurred_at:timestamp with time zone", "eligibility_at:timestamp with time zone", "recipient_count:integer", "payload:jsonb"],
43
+ emseepea_event_intents: ["namespace:text", "source_kind:text", "source_id:text", "subscription_id:text", "generation:text", "delivery_id:text", "event_id:text", "state:text"],
44
+ });
45
+ const CATALOG = `SELECT c.relname,pg_catalog.pg_get_userbyid(c.relowner) AS owner,current_user AS actor,c.relkind,
46
+ c.relrowsecurity,c.relforcerowsecurity,
47
+ pg_catalog.array_agg(a.attname||':'||pg_catalog.format_type(a.atttypid,a.atttypmod) ORDER BY a.attnum) AS columns,
48
+ pg_catalog.bool_and(a.attnotnull) AS all_not_null,
49
+ pg_catalog.jsonb_object_agg(a.attname,pg_catalog.pg_get_expr(d.adbin,d.adrelid)) AS defaults
50
+ FROM pg_catalog.pg_class c JOIN pg_catalog.pg_namespace n ON n.oid=c.relnamespace
51
+ JOIN pg_catalog.pg_attribute a ON a.attrelid=c.oid AND a.attnum>0 AND NOT a.attisdropped
52
+ LEFT JOIN pg_catalog.pg_attrdef d ON d.adrelid=c.oid AND d.adnum=a.attnum
53
+ WHERE n.nspname='public' AND c.relname=ANY($1::pg_catalog.text[]) GROUP BY c.oid,c.relname,c.relowner,c.relkind,c.relrowsecurity,c.relforcerowsecurity`;
54
+ const EXPECTED_CONSTRAINTS = [
55
+ [TABLES[0], "p", "PRIMARY KEY (singleton)"], [TABLES[0], "c", "CHECK (singleton)"],
56
+ [TABLES[1], "p", "PRIMARY KEY (namespace, subscription_id, generation)"],
57
+ [TABLES[1], "c", "CHECK ((jsonb_typeof(arguments) = 'object'::text))"],
58
+ [TABLES[2], "p", "PRIMARY KEY (namespace, source_kind, source_id)"], [TABLES[2], "u", "UNIQUE (event_id)"],
59
+ [TABLES[2], "c", "CHECK ((recipient_count >= 0))"], [TABLES[2], "c", "CHECK ((jsonb_typeof(payload) = 'object'::text))"],
60
+ [TABLES[3], "p", "PRIMARY KEY (namespace, source_kind, source_id, subscription_id, generation)"],
61
+ [TABLES[3], "u", "UNIQUE (delivery_id)"],
62
+ [TABLES[3], "f", "FOREIGN KEY (namespace, source_kind, source_id) REFERENCES emseepea_event_sources(namespace, source_kind, source_id) ON DELETE CASCADE"],
63
+ [TABLES[3], "c", "CHECK ((state = ANY (ARRAY['pending'::text, 'completed'::text, 'revoked'::text])))"],
64
+ ];
65
+ async function verify(run) {
66
+ const found = (await run(CATALOG, [TABLES])).rows;
67
+ if (found.length !== TABLES.length)
68
+ throw new PostgresEventMigrationError("INCOMPATIBLE_SCHEMA");
69
+ for (const item of found) {
70
+ if (typeof item.relname !== "string" || item.owner !== item.actor || item.relkind !== "r" || item.all_not_null !== true ||
71
+ item.relrowsecurity !== false || item.relforcerowsecurity !== false ||
72
+ JSON.stringify(item.columns) !== JSON.stringify(EXPECTED[item.relname]))
73
+ throw new PostgresEventMigrationError("INCOMPATIBLE_SCHEMA");
74
+ const defaults = item.defaults;
75
+ if (!defaults || typeof defaults !== "object")
76
+ throw new PostgresEventMigrationError("INCOMPATIBLE_SCHEMA");
77
+ for (const column of EXPECTED[item.relname]) {
78
+ const name = column.split(":")[0];
79
+ const expectedDefault = item.relname === TABLES[0] && name === "singleton" ? "true" :
80
+ item.relname === TABLES[3] && name === "state" ? "'pending'::text" : null;
81
+ if (defaults[name] !== expectedDefault)
82
+ throw new PostgresEventMigrationError("INCOMPATIBLE_SCHEMA");
83
+ }
84
+ }
85
+ const version = (await run("SELECT version,revision FROM public.emseepea_event_capture_migrations WHERE singleton")).rows;
86
+ if (version.length !== 1 || version[0]?.version !== VERSION || version[0]?.revision !== REVISION)
87
+ throw new PostgresEventMigrationError("INCOMPATIBLE_SCHEMA");
88
+ const constraints = (await run(`SELECT c.relname,t.contype,t.convalidated,t.condeferrable,t.condeferred,
89
+ pg_catalog.pg_get_constraintdef(t.oid) AS definition,
90
+ CASE WHEN t.contype IN ('p','u') THEN i.indisvalid AND i.indisready AND i.indisunique ELSE true END AS key_valid
91
+ FROM pg_catalog.pg_constraint t JOIN pg_catalog.pg_class c ON c.oid=t.conrelid
92
+ JOIN pg_catalog.pg_namespace n ON n.oid=c.relnamespace LEFT JOIN pg_catalog.pg_index i ON i.indexrelid=t.conindid
93
+ WHERE n.nspname='public' AND c.relname=ANY($1::pg_catalog.text[])`, [TABLES])).rows;
94
+ if (constraints.length !== EXPECTED_CONSTRAINTS.length)
95
+ throw new PostgresEventMigrationError("INCOMPATIBLE_SCHEMA");
96
+ const expected = new Set(EXPECTED_CONSTRAINTS.map((item) => JSON.stringify(item)));
97
+ for (const item of constraints) {
98
+ const key = JSON.stringify([item.relname, item.contype, item.definition]);
99
+ if (item.convalidated !== true || item.condeferrable !== false || item.condeferred !== false || item.key_valid !== true ||
100
+ !expected.delete(key))
101
+ throw new PostgresEventMigrationError("INCOMPATIBLE_SCHEMA");
102
+ }
103
+ if (expected.size)
104
+ throw new PostgresEventMigrationError("INCOMPATIBLE_SCHEMA");
105
+ const indexes = (await run(`SELECT ic.relname AS name,tc.relname AS target,tn.nspname AS target_schema,
106
+ pg_catalog.pg_get_userbyid(ic.relowner) AS owner,current_user AS actor,
107
+ i.indisvalid,i.indisready,i.indisunique,i.indnkeyatts,i.indnatts,
108
+ pg_catalog.pg_get_expr(i.indpred,i.indrelid) AS predicate,
109
+ ARRAY(SELECT a.attname::pg_catalog.text FROM pg_catalog.unnest(i.indkey) WITH ORDINALITY AS k(attnum,ordinal)
110
+ JOIN pg_catalog.pg_attribute a ON a.attrelid=i.indrelid AND a.attnum=k.attnum ORDER BY k.ordinal) AS keys
111
+ FROM pg_catalog.pg_index i JOIN pg_catalog.pg_class ic ON ic.oid=i.indexrelid
112
+ JOIN pg_catalog.pg_namespace n ON n.oid=ic.relnamespace JOIN pg_catalog.pg_class tc ON tc.oid=i.indrelid
113
+ JOIN pg_catalog.pg_namespace tn ON tn.oid=tc.relnamespace
114
+ WHERE n.nspname='public' AND ic.relname=ANY($1::pg_catalog.text[])`, [["emseepea_event_capture_active_generation", "emseepea_event_capture_candidates"]])).rows;
115
+ if (indexes.length !== 2)
116
+ throw new PostgresEventMigrationError("INCOMPATIBLE_SCHEMA");
117
+ for (const item of indexes) {
118
+ const unique = item.name === "emseepea_event_capture_active_generation";
119
+ const keys = unique ? ["namespace", "subscription_id"] : ["namespace", "owner_key", "event_name", "subscription_id", "generation"];
120
+ if (item.target !== TABLES[1] || item.target_schema !== "public" || item.owner !== item.actor ||
121
+ item.indisvalid !== true || item.indisready !== true || item.indisunique !== unique || item.predicate !== "active" ||
122
+ Number(item.indnkeyatts) !== keys.length || Number(item.indnatts) !== keys.length || JSON.stringify(item.keys) !== JSON.stringify(keys)) {
123
+ throw new PostgresEventMigrationError("INCOMPATIBLE_SCHEMA");
124
+ }
125
+ }
126
+ const triggers = (await run(`SELECT t.oid FROM pg_catalog.pg_trigger t JOIN pg_catalog.pg_class c ON c.oid=t.tgrelid
127
+ JOIN pg_catalog.pg_namespace n ON n.oid=c.relnamespace WHERE n.nspname='public' AND c.relname=ANY($1::pg_catalog.text[])
128
+ AND NOT t.tgisinternal`, [TABLES])).rows;
129
+ if (triggers.length)
130
+ throw new PostgresEventMigrationError("INCOMPATIBLE_SCHEMA");
131
+ }
132
+ /** Runs deployment migrations using only the acquired connection, which this function owns.
133
+ * Supported pools must also configure finite acquisition and query timeouts. A local timeout
134
+ * does not prove that PostgreSQL cancelled the operation. Connections with an uncertain outcome
135
+ * are discarded.
136
+ */
137
+ export async function migratePostgresEventCapture(pool, invocation) {
138
+ const failure = (code) => { throw new PostgresEventMigrationError(code); };
139
+ if (!pool || typeof pool.connect !== "function" || !invocation?.signal || !Number.isFinite(invocation.deadlineMs))
140
+ failure("INVALID_INPUT");
141
+ const remaining = Math.min(10000, invocation.deadlineMs - Date.now());
142
+ if (remaining <= 0)
143
+ failure("DEADLINE");
144
+ const end = performance.now() + remaining;
145
+ const check = () => { if (invocation.signal.aborted)
146
+ failure("ABORTED"); if (performance.now() >= end)
147
+ failure("DEADLINE"); };
148
+ check();
149
+ async function bounded(pending, maximum, observeAbort) {
150
+ let timer;
151
+ let aborted;
152
+ try {
153
+ return await Promise.race([pending, new Promise((_resolve, reject) => {
154
+ timer = setTimeout(() => reject(new PostgresEventMigrationError("DEADLINE")), Math.max(1, Math.min(maximum, end - performance.now())));
155
+ if (observeAbort) {
156
+ aborted = () => reject(new PostgresEventMigrationError("ABORTED"));
157
+ invocation.signal.addEventListener("abort", aborted, { once: true });
158
+ if (invocation.signal.aborted)
159
+ aborted();
160
+ }
161
+ })]);
162
+ }
163
+ finally {
164
+ if (timer)
165
+ clearTimeout(timer);
166
+ if (aborted)
167
+ invocation.signal.removeEventListener("abort", aborted);
168
+ }
169
+ }
170
+ function dispose(client, uncertain) {
171
+ try {
172
+ client.release(uncertain ? new Error("MIGRATION_OUTCOME_UNKNOWN") : undefined);
173
+ return true;
174
+ }
175
+ catch {
176
+ return false;
177
+ }
178
+ }
179
+ let abandoned = false;
180
+ let pending;
181
+ try {
182
+ pending = Promise.resolve(pool.connect());
183
+ }
184
+ catch {
185
+ failure("UNAVAILABLE");
186
+ }
187
+ void pending.then((value) => { if (abandoned)
188
+ dispose(value, true); }).catch(() => { });
189
+ let client;
190
+ try {
191
+ client = await bounded(pending, 1500, true);
192
+ }
193
+ catch {
194
+ abandoned = true;
195
+ throw new PostgresEventMigrationError("UNAVAILABLE");
196
+ }
197
+ let uncertain = false;
198
+ let committing = false;
199
+ const run = async (sql, values) => {
200
+ check();
201
+ try {
202
+ const result = await bounded(Promise.resolve().then(() => client.query(sql, values)), 3000, true);
203
+ check();
204
+ return result;
205
+ }
206
+ catch (error) {
207
+ if (error instanceof PostgresEventMigrationError) {
208
+ uncertain = true;
209
+ failure("OUTCOME_UNKNOWN");
210
+ }
211
+ const code = error && typeof error === "object" && "code" in error ? error.code : undefined;
212
+ if (typeof code !== "string" || !/^[0-9A-Z]{5}$/.test(code) || code.startsWith("08"))
213
+ uncertain = true;
214
+ throw error;
215
+ }
216
+ };
217
+ let resultError;
218
+ try {
219
+ await run("BEGIN");
220
+ await run("SET LOCAL search_path=pg_catalog,public,pg_temp; SET LOCAL statement_timeout='1500ms'; SET LOCAL lock_timeout='500ms'");
221
+ await run("SELECT pg_catalog.pg_advisory_xact_lock(1740125,1)");
222
+ const existing = (await run(CATALOG, [TABLES])).rows;
223
+ if (existing.length === 0) {
224
+ for (const statement of statements)
225
+ await run(statement);
226
+ await run("INSERT INTO public.emseepea_event_capture_migrations(singleton,version,revision) VALUES(true,$1,$2)", [VERSION, REVISION]);
227
+ }
228
+ await verify(run);
229
+ committing = true;
230
+ await run("COMMIT");
231
+ committing = false;
232
+ }
233
+ catch (error) {
234
+ uncertain ||= committing;
235
+ if (!uncertain) {
236
+ try {
237
+ await bounded(Promise.resolve().then(() => client.query("ROLLBACK")), 1000, false);
238
+ }
239
+ catch {
240
+ uncertain = true;
241
+ }
242
+ }
243
+ resultError = uncertain ? new PostgresEventMigrationError("OUTCOME_UNKNOWN") :
244
+ error instanceof PostgresEventMigrationError ? error : new PostgresEventMigrationError("UNAVAILABLE");
245
+ }
246
+ finally {
247
+ if (!dispose(client, uncertain))
248
+ resultError = new PostgresEventMigrationError("OUTCOME_UNKNOWN");
249
+ }
250
+ if (resultError)
251
+ throw resultError;
252
+ }
253
+ /** Creates lifecycle-managed migration operations for composed deployments. The standalone
254
+ * migration function retains its existing contract. This owner stops accepting work when
255
+ * shutdown begins, never closes the supplied pool, and does not treat a caller-facing
256
+ * deadline as proof of SQL cancellation. */
257
+ export function createPostgresEventCaptureMigrator(pool) {
258
+ if (!pool || typeof pool.connect !== 'function')
259
+ throw new PostgresEventMigrationError('INVALID_INPUT');
260
+ const owned = createOwnedEventOperations();
261
+ let closing = false, disposalFailed = false;
262
+ const retainedPool = {
263
+ async connect() {
264
+ const client = await pool.connect();
265
+ const queries = new Set();
266
+ let released = false;
267
+ return {
268
+ query: ((sql, values) => {
269
+ if (released)
270
+ return Promise.reject(new PostgresEventMigrationError('UNAVAILABLE'));
271
+ const pending = owned.track(Promise.resolve().then(() => client.query(sql, values)));
272
+ queries.add(pending);
273
+ void pending.then(() => queries.delete(pending), () => queries.delete(pending));
274
+ return pending;
275
+ }),
276
+ release(error) {
277
+ if (released) {
278
+ disposalFailed = true;
279
+ return;
280
+ }
281
+ released = true;
282
+ // release is synchronous in pg, but disposal must wait for actual raw
283
+ // query completion and remain retained independently of method outcome.
284
+ owned.track(Promise.allSettled([...queries]).then(() => {
285
+ try {
286
+ client.release(error);
287
+ }
288
+ catch {
289
+ disposalFailed = true;
290
+ }
291
+ }));
292
+ },
293
+ };
294
+ },
295
+ };
296
+ return Object.freeze({
297
+ async migrate(invocation) {
298
+ if (closing)
299
+ throw new PostgresEventMigrationError('UNAVAILABLE');
300
+ try {
301
+ await owned.run(retainedPool, invocation, async (run) => {
302
+ await run('SELECT pg_catalog.pg_advisory_xact_lock(1740125,1)');
303
+ // A missing capture catalog is not evidence of an empty Events store:
304
+ // views, partial objects and retained later families forbid recreation.
305
+ const reserved = (await run(`SELECT c.relname,c.relkind FROM pg_catalog.pg_class c
306
+ JOIN pg_catalog.pg_namespace n ON n.oid=c.relnamespace
307
+ WHERE n.nspname='public' AND pg_catalog.starts_with(c.relname::pg_catalog.text,'emseepea_event_')`)).rows;
308
+ if (reserved.length === 0) {
309
+ for (const statement of statements)
310
+ await run(statement);
311
+ await run('INSERT INTO public.emseepea_event_capture_migrations(singleton,version,revision) VALUES(true,$1,$2)', [VERSION, REVISION]);
312
+ }
313
+ await verify(run);
314
+ }, false, error => error instanceof PostgresEventMigrationError);
315
+ }
316
+ catch (error) {
317
+ if (error instanceof PostgresEventMigrationError)
318
+ throw error;
319
+ const code = error && typeof error === 'object' && 'code' in error ? error.code : undefined;
320
+ throw new PostgresEventMigrationError(code === 'OUTCOME_UNKNOWN' ? code : code === 'ABORTED' || code === 'DEADLINE' || code === 'INVALID_INPUT' ? code : 'UNAVAILABLE');
321
+ }
322
+ },
323
+ async settle(invocation) {
324
+ closing = true;
325
+ return await owned.settle(invocation) && !disposalFailed;
326
+ },
327
+ });
328
+ }
329
+ //# sourceMappingURL=events-postgres-migrations.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"events-postgres-migrations.js","sourceRoot":"","sources":["../src/events-postgres-migrations.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,WAAW,EAAE,MAAM,iBAAiB,CAAC;AAC9C,OAAO,EAAE,0BAA0B,EAAE,MAAM,4BAA4B,CAAC;AAKxE,MAAM,OAAO,2BAA4B,SAAQ,KAAK;IAC/B;IAArB,YAAqB,IAA0G;QAC7H,KAAK,CAAC,IAAI,CAAC,CAAC;QADO,SAAI,GAAJ,IAAI,CAAsG;QAChH,IAAI,CAAC,IAAI,GAAG,6BAA6B,CAAC;IACzD,CAAC;CACF;AACD,MAAM,OAAO,GAAG,CAAC,CAAC;AAClB,MAAM,QAAQ,GAAG,YAAY,CAAC;AAC9B,MAAM,MAAM,GAAG,CAAC,mCAAmC,EAAE,sCAAsC,EAAE,wBAAwB,EAAE,wBAAwB,CAAU,CAAC;AAC1J,MAAM,UAAU,GAAG,MAAM,CAAC,MAAM,CAAC;IAC/B;gHAC8G;IAC9G;;;;sDAIoD;IACpD,qJAAqJ;IACrJ,uKAAuK;IACvK;;;;;iDAK+C;IAC/C;;;;;6IAK2I;CAC5I,CAAC,CAAC;AACH,8EAA8E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IAAI,MAAM,IAAI,KAAK,CAAC,CAAC,CAAC,KAAK,CAAC,IAAI,CAAC,CAAC,CAAC,SAAS,CAAC;gBAC5F,MAAM,IAAI,2BAA2B,CAAC,IAAI,KAAK,iBAAiB,CAAC,CAAC,CAAC,IAAI,CAAC,CAAC,CAAC,IAAI,KAAK,SAAS,IAAI,IAAI,KAAK,UAAU,IAAI,IAAI,KAAK,eAAe,CAAC,CAAC,CAAC,IAAI,CAAC,CAAC,CAAC,aAAa,CAAC,CAAC;YAC1K,CAAC;QACH,CAAC;QACD,KAAK,CAAC,MAAM,CAAC,UAAmC;YAC9C,OAAO,GAAG,IAAI,CAAC;YACf,OAAO,MAAM,KAAK,CAAC,MAAM,CAAC,UAAU,CAAC,IAAI,CAAC,cAAc,CAAC;QAC3D,CAAC;KACF,CAAC,CAAC;AACL,CAAC"}
@@ -0,0 +1,16 @@
1
+ import { type ExternalMcpEventInvocation } from './events-external.js';
2
+ import type { PostgresEventClient } from './events-postgres.js';
3
+ export interface OwnedEventClient extends PostgresEventClient {
4
+ release(error?: Error): void;
5
+ }
6
+ export interface OwnedEventPool {
7
+ connect(): Promise<OwnedEventClient>;
8
+ }
9
+ export type EventSql = (sql: string, values?: readonly unknown[]) => ReturnType<PostgresEventClient['query']>;
10
+ /** Private operation owner. A local timeout is never a backend cancellation claim. */
11
+ export declare function createOwnedEventOperations(): {
12
+ track: <T>(promise: Promise<T>) => Promise<T>;
13
+ run<T>(pool: OwnedEventPool, invocation: ExternalMcpEventInvocation, work: (sql: EventSql) => Promise<T>, readOnly?: boolean, knownError?: (error: unknown) => boolean): Promise<T>;
14
+ settle(invocation: ExternalMcpEventInvocation): Promise<boolean>;
15
+ };
16
+ //# sourceMappingURL=events-postgres-owned.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"events-postgres-owned.d.ts","sourceRoot":"","sources":["../src/events-postgres-owned.ts"],"names":[],"mappings":"AACA,OAAO,EAAyB,KAAK,0BAA0B,EAAE,MAAM,sBAAsB,CAAC;AAC9F,OAAO,KAAK,EAAE,mBAAmB,EAAE,MAAM,sBAAsB,CAAC;AAChE,MAAM,WAAW,gBAAiB,SAAQ,mBAAmB;IAAG,OAAO,CAAC,KAAK,CAAC,EAAE,KAAK,GAAG,IAAI,CAAA;CAAE;AAC9F,MAAM,WAAW,cAAc;IAAG,OAAO,IAAI,OAAO,CAAC,gBAAgB,CAAC,CAAA;CAAE;AACxE,MAAM,MAAM,QAAQ,GAAG,CAAC,GAAG,EAAE,MAAM,EAAE,MAAM,CAAC,EAAE,SAAS,OAAO,EAAE,KAAK,UAAU,CAAC,mBAAmB,CAAC,OAAO,CAAC,CAAC,CAAC;AAC9G,sFAAsF;AACtF,wBAAgB,0BAA0B;YAGzB,CAAC,WAAW,OAAO,CAAC,CAAC,CAAC,KAAG,OAAO,CAAC,CAAC,CAAC;QAwE5C,CAAC,QAAO,cAAc,cAAY,0BAA0B,QAAM,CAAC,GAAG,EAAC,QAAQ,KAAG,OAAO,CAAC,CAAC,CAAC,mCAA2B,CAAC,KAAK,EAAC,OAAO,KAAG,OAAO,GAAY,OAAO,CAAC,CAAC,CAAC;uBAGjJ,0BAA0B,GAAE,OAAO,CAAC,OAAO,CAAC;EAiBvE"}
@@ -0,0 +1,161 @@
1
+ import { performance } from 'node:perf_hooks';
2
+ import { ExternalMcpEventError } from './events-external.js';
3
+ /** Private operation owner. A local timeout is never a backend cancellation claim. */
4
+ export function createOwnedEventOperations() {
5
+ const pending = new Set();
6
+ let closed = false, disposalFailed = false;
7
+ function track(promise) {
8
+ pending.add(promise);
9
+ void promise.then(() => pending.delete(promise), () => pending.delete(promise));
10
+ return promise;
11
+ }
12
+ function dispose(client, uncertain) {
13
+ try {
14
+ client.release(uncertain ? new Error('EVENT_OPERATION_UNKNOWN') : undefined);
15
+ }
16
+ catch {
17
+ disposalFailed = true;
18
+ }
19
+ }
20
+ async function operation(pool, invocation, work, readOnly, knownError) {
21
+ if (!invocation?.signal || !Number.isFinite(invocation.deadlineMs))
22
+ throw new ExternalMcpEventError('INVALID_INPUT');
23
+ const end = performance.now() + Math.min(5000, invocation.deadlineMs - Date.now());
24
+ const check = () => {
25
+ if (closed || invocation.signal.aborted)
26
+ throw new ExternalMcpEventError('ABORTED');
27
+ if (performance.now() >= end)
28
+ throw new ExternalMcpEventError('DEADLINE');
29
+ };
30
+ check();
31
+ async function wait(promise, cap, abort = true) {
32
+ let timer;
33
+ let stop;
34
+ try {
35
+ return await Promise.race([track(promise), new Promise((_resolve, reject) => {
36
+ timer = setTimeout(() => reject(new ExternalMcpEventError('DEADLINE')), Math.max(1, Math.min(cap, end - performance.now())));
37
+ if (abort) {
38
+ stop = () => reject(new ExternalMcpEventError('ABORTED'));
39
+ invocation.signal.addEventListener('abort', stop, { once: true });
40
+ if (invocation.signal.aborted)
41
+ stop();
42
+ }
43
+ })]);
44
+ }
45
+ finally {
46
+ if (timer)
47
+ clearTimeout(timer);
48
+ if (stop)
49
+ invocation.signal.removeEventListener('abort', stop);
50
+ }
51
+ }
52
+ const acquisition = Promise.resolve().then(() => pool.connect());
53
+ let client;
54
+ try {
55
+ client = await wait(acquisition, 500);
56
+ check();
57
+ }
58
+ catch (error) {
59
+ track(acquisition.then(value => dispose(value, true), () => { }));
60
+ if (error instanceof ExternalMcpEventError)
61
+ throw error;
62
+ throw new ExternalMcpEventError('UNAVAILABLE');
63
+ }
64
+ let uncertain = false, committing = false, began = false;
65
+ const raw = async (sql, values) => {
66
+ check();
67
+ try {
68
+ const result = await wait(Promise.resolve().then(() => client.query(sql, values)), 1000);
69
+ check();
70
+ return result;
71
+ }
72
+ catch (error) {
73
+ const code = error && typeof error === 'object' && 'code' in error ? error.code : undefined;
74
+ if (error instanceof ExternalMcpEventError || typeof code !== 'string' || !/^[0-9A-Z]{5}$/.test(code) || code.startsWith('08'))
75
+ uncertain = true;
76
+ throw error;
77
+ }
78
+ };
79
+ const run = async (sql, values) => {
80
+ check();
81
+ const ms = Math.max(1, Math.floor(Math.min(750, end - performance.now())));
82
+ await raw("SELECT pg_catalog.set_config('statement_timeout',$1,true),pg_catalog.set_config('lock_timeout',$2,true)", [`${ms}ms`, `${Math.min(ms, 250)}ms`]);
83
+ return raw(sql, values);
84
+ };
85
+ try {
86
+ await raw(readOnly ? 'BEGIN READ ONLY' : 'BEGIN');
87
+ began = true;
88
+ await raw('SET LOCAL search_path=pg_catalog,public,pg_temp');
89
+ const result = await work(run);
90
+ check();
91
+ committing = true;
92
+ await raw('COMMIT');
93
+ committing = false;
94
+ began = false;
95
+ return result;
96
+ }
97
+ catch (error) {
98
+ uncertain ||= committing;
99
+ if (began && !uncertain) {
100
+ // Cleanup has its own finite cap; it never races another query on this client.
101
+ try {
102
+ const rollback = track(Promise.resolve().then(() => client.query('ROLLBACK')));
103
+ let timer;
104
+ try {
105
+ await Promise.race([rollback, new Promise((_resolve, reject) => { timer = setTimeout(() => reject(new Error('ROLLBACK_UNKNOWN')), 500); })]);
106
+ }
107
+ finally {
108
+ if (timer)
109
+ clearTimeout(timer);
110
+ }
111
+ }
112
+ catch {
113
+ uncertain = true;
114
+ }
115
+ }
116
+ if (uncertain)
117
+ throw new ExternalMcpEventError(readOnly ? 'UNAVAILABLE' : 'OUTCOME_UNKNOWN');
118
+ if (error instanceof ExternalMcpEventError || knownError(error))
119
+ throw error;
120
+ throw new ExternalMcpEventError('UNAVAILABLE');
121
+ }
122
+ finally {
123
+ dispose(client, uncertain);
124
+ }
125
+ }
126
+ return {
127
+ track,
128
+ run(pool, invocation, work, readOnly = false, knownError = () => false) {
129
+ return track(operation(pool, invocation, work, readOnly, knownError));
130
+ },
131
+ async settle(invocation) {
132
+ closed = true;
133
+ const end = performance.now() + Math.max(0, invocation.deadlineMs - Date.now());
134
+ while (pending.size) {
135
+ if (invocation.signal.aborted || performance.now() >= end)
136
+ return false;
137
+ let timer;
138
+ let stop;
139
+ try {
140
+ const done = await Promise.race([Promise.allSettled([...pending]).then(() => true), new Promise(resolve => {
141
+ timer = setTimeout(() => resolve(false), Math.max(1, end - performance.now()));
142
+ stop = () => resolve(false);
143
+ invocation.signal.addEventListener('abort', stop, { once: true });
144
+ if (invocation.signal.aborted)
145
+ stop();
146
+ })]);
147
+ if (!done)
148
+ return false;
149
+ }
150
+ finally {
151
+ if (timer)
152
+ clearTimeout(timer);
153
+ if (stop)
154
+ invocation.signal.removeEventListener('abort', stop);
155
+ }
156
+ }
157
+ return !disposalFailed;
158
+ },
159
+ };
160
+ }
161
+ //# sourceMappingURL=events-postgres-owned.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"events-postgres-owned.js","sourceRoot":"","sources":["../src/events-postgres-owned.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,WAAW,EAAE,MAAM,iBAAiB,CAAC;AAC9C,OAAO,EAAE,qBAAqB,EAAmC,MAAM,sBAAsB,CAAC;AAK9F,sFAAsF;AACtF,MAAM,UAAU,0BAA0B;IACxC,MAAM,OAAO,GAAG,IAAI,GAAG,EAAoB,CAAC;IAC5C,IAAI,MAAM,GAAG,KAAK,EAAE,cAAc,GAAG,KAAK,CAAC;IAC3C,SAAS,KAAK,CAAI,OAAmB;QACnC,OAAO,CAAC,GAAG,CAAC,OAAO,CAAC,CAAC;QACrB,KAAK,OAAO,CAAC,IAAI,CAAC,GAAE,EAAE,CAAA,OAAO,CAAC,MAAM,CAAC,OAAO,CAAC,EAAC,GAAE,EAAE,CAAA,OAAO,CAAC,MAAM,CAAC,OAAO,CAAC,CAAC,CAAC;QAC3E,OAAO,OAAO,CAAC;IACjB,CAAC;IACD,SAAS,OAAO,CAAC,MAAwB,EAAE,SAAkB;QAC3D,IAAI,CAAC;YAAC,MAAM,CAAC,OAAO,CAAC,SAAS,CAAC,CAAC,CAAC,IAAI,KAAK,CAAC,yBAAyB,CAAC,CAAC,CAAC,CAAC,SAAS,CAAC,CAAC;QAAC,CAAC;QACrF,MAAM,CAAC;YAAC,cAAc,GAAG,IAAI,CAAC;QAAC,CAAC;IAClC,CAAC;IACD,KAAK,UAAU,SAA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AU,CAAC,GAAE,EAAE,CAAA,OAAO,CAAC,KAAK,CAAC,EAAC,IAAI,CAAC,GAAG,CAAC,CAAC,EAAC,GAAG,GAAC,WAAW,CAAC,GAAG,EAAE,CAAC,CAAC,CAAC;4BACvE,IAAI,GAAC,GAAE,EAAE,CAAA,OAAO,CAAC,KAAK,CAAC,CAAC;4BAAA,UAAU,CAAC,MAAM,CAAC,gBAAgB,CAAC,OAAO,EAAC,IAAI,EAAC,EAAC,IAAI,EAAC,IAAI,EAAC,CAAC,CAAC;4BAAA,IAAG,UAAU,CAAC,MAAM,CAAC,OAAO;gCAAC,IAAI,EAAE,CAAC;wBAC3H,CAAC,CAAC,CAAC,CAAC,CAAC;oBACL,IAAG,CAAC,IAAI;wBAAC,OAAO,KAAK,CAAC;gBACxB,CAAC;wBAAS,CAAC;oBAAA,IAAG,KAAK;wBAAC,YAAY,CAAC,KAAK,CAAC,CAAC;oBAAA,IAAG,IAAI;wBAAC,UAAU,CAAC,MAAM,CAAC,mBAAmB,CAAC,OAAO,EAAC,IAAI,CAAC,CAAC;gBAAA,CAAC;YACvG,CAAC;YACD,OAAO,CAAC,cAAc,CAAC;QACzB,CAAC;KACF,CAAC;AACJ,CAAC"}
@@ -0,0 +1,53 @@
1
+ import type { McpEventDefinition } from "./events.js";
2
+ export { postgresEventCaptureMigrations, migratePostgresEventCapture } from "./events-postgres-migrations.js";
3
+ export { createPostgresEventDelivery, createPostgresEventDeliveryMigrator, PostgresEventDeliveryMigrationError, type PostgresEventDelivery, type PostgresEventDeliveryOptions, type PostgresEventDeliveryOutcome, } from "./events-postgres-delivery.js";
4
+ export { createPostgresEventDispatchMigrator, PostgresEventDispatchMigrationError, } from "./events-postgres-dispatch-migrations.js";
5
+ export interface PostgresEventClient {
6
+ query<Row extends Record<string, unknown> = Record<string, unknown>>(text: string, values?: readonly unknown[]): Promise<{
7
+ readonly rows: readonly Row[];
8
+ readonly rowCount: number | null;
9
+ }>;
10
+ }
11
+ export interface PostgresEventInvocation {
12
+ readonly signal: AbortSignal;
13
+ /** Absolute Unix time in milliseconds. The operation also applies its own shorter maximum duration. */
14
+ readonly deadlineMs: number;
15
+ }
16
+ export interface PostgresSourcePublication {
17
+ readonly sourceEventId: string;
18
+ readonly sourceVersion: string;
19
+ readonly eventName: string;
20
+ readonly ownerKey: string;
21
+ readonly occurredAt: string;
22
+ readonly data: Readonly<Record<string, unknown>>;
23
+ }
24
+ declare const transactionBrand: unique symbol;
25
+ export interface PostgresEventTransaction {
26
+ readonly [transactionBrand]: true;
27
+ }
28
+ export interface PostgresCaptureOutcome {
29
+ readonly outcome: "captured" | "replayed";
30
+ readonly eventId: string;
31
+ readonly deliveryCount: number;
32
+ readonly eligibilityAt: string;
33
+ }
34
+ export type PostgresEventCaptureErrorCode = "INVALID_INPUT" | "ABORTED" | "DEADLINE" | "OUTCOME_UNKNOWN" | "TRANSACTION_NOT_BOUND" | "TRANSACTION_CHANGED" | "UNSUPPORTED_TRANSACTION_POLICY" | "CONCURRENT_USE" | "PUBLICATION_CONFLICT" | "WHOLE_TRANSACTION_RETRY_REQUIRED" | "UNAVAILABLE";
35
+ export declare class PostgresEventCaptureError extends Error {
36
+ readonly code: PostgresEventCaptureErrorCode;
37
+ constructor(code: PostgresEventCaptureErrorCode);
38
+ }
39
+ /** Captures publication state only. It does not configure or deliver native Events.
40
+ * Registered schemas and matchers must be side-effect-free and synchronous. A deadline
41
+ * check cannot interrupt a matcher after it starts. The caller exclusively owns the
42
+ * transaction. Ordinary deletion must retain deduplication identities. Administrative
43
+ * ledger erasure is governed separately and is not provided by this capture-only API.
44
+ */
45
+ export declare function createPostgresEventCapture(options: Readonly<{
46
+ namespace: string;
47
+ sourceKind: string;
48
+ definitions: readonly McpEventDefinition[];
49
+ }>): Readonly<{
50
+ bindTransaction(client: PostgresEventClient, invocation: PostgresEventInvocation): Promise<PostgresEventTransaction>;
51
+ captureInTransaction(handle: PostgresEventTransaction, publication: PostgresSourcePublication, invocation: PostgresEventInvocation): Promise<PostgresCaptureOutcome>;
52
+ }>;
53
+ //# sourceMappingURL=events-postgres.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"events-postgres.d.ts","sourceRoot":"","sources":["../src/events-postgres.ts"],"names":[],"mappings":"AAEA,OAAO,KAAK,EAAE,kBAAkB,EAAE,MAAM,aAAa,CAAC;AACtD,OAAO,EAAE,8BAA8B,EAAE,2BAA2B,EAAE,MAAM,iCAAiC,CAAC;AAC9G,OAAO,EACL,2BAA2B,EAC3B,mCAAmC,EACnC,mCAAmC,EACnC,KAAK,qBAAqB,EAC1B,KAAK,4BAA4B,EACjC,KAAK,4BAA4B,GAClC,MAAM,+BAA+B,CAAC;AACvC,OAAO,EACL,mCAAmC,EACnC,mCAAmC,GACpC,MAAM,0CAA0C,CAAC;AAElD,MAAM,WAAW,mBAAmB;IAClC,KAAK,CAAC,GAAG,SAAS,MAAM,CAAC,MAAM,EAAE,OAAO,CAAC,GAAG,MAAM,CAAC,MAAM,EAAE,OAAO,CAAC,EACjE,IAAI,EAAE,MAAM,EAAE,MAAM,CAAC,EAAE,SAAS,OAAO,EAAE,GACxC,OAAO,CAAC;QAAE,QAAQ,CAAC,IAAI,EAAE,SAAS,GAAG,EAAE,CAAC;QAAC,QAAQ,CAAC,QAAQ,EAAE,MAAM,GAAG,IAAI,CAAA;KAAE,CAAC,CAAC;CACjF;AACD,MAAM,WAAW,uBAAuB;IACtC,QAAQ,CAAC,MAAM,EAAE,WAAW,CAAC;IAC7B,uGAAuG;IACvG,QAAQ,CAAC,UAAU,EAAE,MAAM,CAAC;CAC7B;AACD,MAAM,WAAW,yBAAyB;IACxC,QAAQ,CAAC,aAAa,EAAE,MAAM,CAAC;IAC/B,QAAQ,CAAC,aAAa,EAAE,MAAM,CAAC;IAC/B,QAAQ,CAAC,SAAS,EAAE,MAAM,CAAC;IAC3B,QAAQ,CAAC,QAAQ,EAAE,MAAM,CAAC;IAC1B,QAAQ,CAAC,UAAU,EAAE,MAAM,CAAC;IAC5B,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