@voltro/plugin-cdc-out 0.85.0 → 0.87.0

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/dist/outbox.js ADDED
@@ -0,0 +1,72 @@
1
+ import { and as e, eq as t, generateId as n, id as r, integer as i, json as a, lt as o, table as s, text as c, timestamp as l } from "@voltro/database";
2
+ //#region src/outbox.ts
3
+ var u = "_voltro_cdcout_outbox", d = "_voltro_cdcout_leases", f = "_voltro_cdcout_claims", p = {
4
+ kind: "typeid",
5
+ prefix: "cdcout"
6
+ }, m = {
7
+ kind: "typeid",
8
+ prefix: "cdcoutclaim"
9
+ }, h = () => n(p, u), g = () => n(m, f), _ = s(u, {
10
+ id: r({ prefix: "cdcout" }),
11
+ pipe: c(),
12
+ sourceTable: c(),
13
+ op: c(),
14
+ key: c(),
15
+ payload: a().nullable(),
16
+ status: c(),
17
+ attempts: i().default(0),
18
+ nextAttemptAt: l(),
19
+ claimedBy: c().nullable(),
20
+ claimedAt: l().nullable(),
21
+ createdAt: l(),
22
+ deliveredAt: l().nullable(),
23
+ lastError: c().nullable()
24
+ }).index(["pipe", "status"]), v = s(f, {
25
+ id: r({ prefix: "cdcoutclaim" }),
26
+ pipe: c(),
27
+ changeKey: c(),
28
+ claimedBy: c(),
29
+ seenAt: l()
30
+ }).unique("cdcoutClaimKey", ["pipe", "changeKey"]).index(["seenAt"]), y = s(d, {
31
+ id: r({ scheme: "numeric" }),
32
+ key: c(),
33
+ holder: c(),
34
+ expiresAt: l(),
35
+ renewedAt: l()
36
+ }).unique("cdcoutLeaseKey", ["key"]), b = (e) => e instanceof Date ? e.getTime() : new Date(String(e)).getTime(), x = class {
37
+ opts;
38
+ held = !1;
39
+ constructor(e) {
40
+ this.opts = e;
41
+ }
42
+ get isLeader() {
43
+ return this.held;
44
+ }
45
+ async heartbeat(n) {
46
+ let r = (this.opts.now ?? Date.now)(), i = {
47
+ holder: this.opts.holder,
48
+ expiresAt: new Date(r + this.opts.ttlMs),
49
+ renewedAt: new Date(r)
50
+ };
51
+ try {
52
+ if (await n.updateMany("_voltro_cdcout_leases", i, { where: e(t("key", this.opts.key), t("holder", this.opts.holder)) }) === 1) return this.held = !0, !0;
53
+ let a = await n.insertIgnore(d, {
54
+ key: this.opts.key,
55
+ ...i
56
+ }, { conflictColumns: ["key"] });
57
+ if (a.holder === this.opts.holder) return this.held = !0, !0;
58
+ let s = await n.updateMany(d, i, { where: e(t("key", this.opts.key), t("holder", String(a.holder)), o("expiresAt", new Date(r))) });
59
+ return this.held = s === 1, this.held;
60
+ } catch {
61
+ return this.held = !1, !1;
62
+ }
63
+ }
64
+ async release(n) {
65
+ this.held = !1;
66
+ try {
67
+ await n.updateMany(d, { expiresAt: /* @__PURE__ */ new Date(0) }, { where: e(t("key", this.opts.key), t("holder", this.opts.holder)) });
68
+ } catch {}
69
+ }
70
+ };
71
+ //#endregion
72
+ export { f as CDCOUT_CLAIMS_TABLE, d as CDCOUT_LEASES_TABLE, u as CDCOUT_OUTBOX_TABLE, x as CdcLeaseManager, v as cdcOutClaimsTable, y as cdcOutLeasesTable, _ as cdcOutOutboxTable, g as nextClaimId, h as nextOutboxId, b as toMs };
package/dist/sinks.js ADDED
@@ -0,0 +1,46 @@
1
+ import { CdcConfigError as e, CdcDeliveryError as t } from "./errors.js";
2
+ //#region src/sinks.ts
3
+ var n = (e = "memory") => {
4
+ let t = [];
5
+ return {
6
+ name: e,
7
+ deliver: async (e) => {
8
+ t.push([...e]);
9
+ },
10
+ get batches() {
11
+ return t;
12
+ },
13
+ get delivered() {
14
+ return t.flat();
15
+ }
16
+ };
17
+ }, r = (n, r) => {
18
+ let i;
19
+ try {
20
+ i = new URL(n).host;
21
+ } catch {
22
+ throw new e({ message: `webhookSink: invalid url '${n}'` });
23
+ }
24
+ let a = `webhook(${i})`;
25
+ return {
26
+ name: a,
27
+ outboundHost: i,
28
+ deliver: async (e, i) => {
29
+ let o = await fetch(n, {
30
+ method: "POST",
31
+ headers: {
32
+ "content-type": "application/json",
33
+ ...r?.headers ?? {}
34
+ },
35
+ body: JSON.stringify({ records: e }),
36
+ signal: i.signal
37
+ });
38
+ if (!o.ok) throw new t({
39
+ sink: a,
40
+ reason: `${o.status} ${o.statusText}`
41
+ });
42
+ }
43
+ };
44
+ };
45
+ //#endregion
46
+ export { n as memorySink, r as webhookSink };
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@voltro/plugin-cdc-out",
3
- "version": "0.85.0",
3
+ "version": "0.87.0",
4
4
  "description": "Declarative reverse-ETL: mirror framework table changes outward to external sinks (webhook, Kafka via @voltro/plugin-queue's kafkaSink, plus a CdcSink interface for custom sinks) through a durable outbox — ordered per pipe, at-least-once from enqueue, retried with backoff, dead-lettered.",
5
5
  "keywords": [
6
6
  "voltro",
@@ -33,9 +33,9 @@
33
33
  "node": ">=24.0.0"
34
34
  },
35
35
  "dependencies": {
36
- "@voltro/database": "0.85.0",
37
- "@voltro/protocol": "0.85.0",
38
- "@voltro/runtime": "0.85.0"
36
+ "@voltro/database": "0.87.0",
37
+ "@voltro/protocol": "0.87.0",
38
+ "@voltro/runtime": "0.87.0"
39
39
  },
40
40
  "peerDependencies": {
41
41
  "effect": "4.0.1"