@secondlayer/shared 6.20.0 → 6.21.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.
@@ -7,6 +7,18 @@ interface ListenOptions {
7
7
  */
8
8
  connectionString?: string;
9
9
  }
10
+ /**
11
+ * LISTEN/NOTIFY connection for indexer-fired channels (`indexer:new_block`,
12
+ * `subgraph_reorg`, `tx:confirmed`) — they fire on the SOURCE (chain) DB.
13
+ * `||` (not `??`) so an empty-string env (an unset `SOURCE_DATABASE_URL` passed
14
+ * through docker-compose as `""`) falls back to `DATABASE_URL`.
15
+ */
16
+ declare function sourceListenerUrl(): string | undefined;
17
+ /**
18
+ * LISTEN/NOTIFY connection for control-plane channels (`subscriptions:new_outbox`,
19
+ * `subscriptions:changed`, subgraph operations) — they fire on the TARGET DB.
20
+ */
21
+ declare function targetListenerUrl(): string | undefined;
10
22
  declare function listen(channel: string, callback: (payload?: string) => void, opts?: ListenOptions): Promise<() => Promise<void>>;
11
23
  declare function notify(channel: string, payload?: string, opts?: ListenOptions): Promise<void>;
12
- export { notify, listen };
24
+ export { targetListenerUrl, sourceListenerUrl, notify, listen };
@@ -16,6 +16,12 @@ var __export = (target, all) => {
16
16
 
17
17
  // src/queue/listener.ts
18
18
  import postgres from "postgres";
19
+ function sourceListenerUrl() {
20
+ return process.env.SOURCE_DATABASE_URL || process.env.DATABASE_URL;
21
+ }
22
+ function targetListenerUrl() {
23
+ return process.env.TARGET_DATABASE_URL || process.env.DATABASE_URL;
24
+ }
19
25
  function resolveUrl(opts) {
20
26
  const url = opts?.connectionString || process.env.DATABASE_URL;
21
27
  if (!url) {
@@ -48,9 +54,11 @@ async function notify(channel, payload, opts) {
48
54
  }
49
55
  }
50
56
  export {
57
+ targetListenerUrl,
58
+ sourceListenerUrl,
51
59
  notify,
52
60
  listen
53
61
  };
54
62
 
55
- //# debugId=B1060AE6BF370F9B64756E2164756E21
63
+ //# debugId=CDCEFCF2F72FC7C464756E2164756E21
56
64
  //# sourceMappingURL=listener.js.map
@@ -2,9 +2,9 @@
2
2
  "version": 3,
3
3
  "sources": ["../src/queue/listener.ts"],
4
4
  "sourcesContent": [
5
- "import postgres from \"postgres\";\n\ninterface ListenOptions {\n\t/**\n\t * Connection string to LISTEN on. Defaults to `process.env.DATABASE_URL`.\n\t * In dual-DB mode, pass `SOURCE_DATABASE_URL` for indexer-fired channels\n\t * (`indexer:new_block`, `subgraph_reorg`, `tx:confirmed`) and\n\t * `TARGET_DATABASE_URL` for tenant-local channels (`subgraph_changes`).\n\t */\n\tconnectionString?: string;\n}\n\nfunction resolveUrl(opts?: ListenOptions): string {\n\t// `||` not `??`: an empty-string connectionString (e.g. an unset\n\t// SOURCE_/TARGET_DATABASE_URL passed through docker-compose as \"\") must fall\n\t// back to DATABASE_URL, not be treated as a valid value.\n\tconst url = opts?.connectionString || process.env.DATABASE_URL;\n\tif (!url) {\n\t\tthrow new Error(\n\t\t\t\"listen/notify requires a connection string (opts.connectionString or DATABASE_URL)\",\n\t\t);\n\t}\n\treturn url;\n}\n\nexport async function listen(\n\tchannel: string,\n\tcallback: (payload?: string) => void,\n\topts?: ListenOptions,\n): Promise<() => Promise<void>> {\n\tconst client = postgres(resolveUrl(opts), {\n\t\tmax: 1,\n\t\tonnotice: () => {},\n\t});\n\n\tawait client.listen(channel, (payload) => {\n\t\tcallback(payload);\n\t});\n\n\treturn async () => {\n\t\tawait client.end();\n\t};\n}\n\nexport async function notify(\n\tchannel: string,\n\tpayload?: string,\n\topts?: ListenOptions,\n): Promise<void> {\n\tconst client = postgres(resolveUrl(opts), { max: 1 });\n\n\ttry {\n\t\tif (payload) {\n\t\t\tawait client`SELECT pg_notify(${channel}, ${payload})`;\n\t\t} else {\n\t\t\tawait client`SELECT pg_notify(${channel}, '')`;\n\t\t}\n\t} finally {\n\t\tawait client.end();\n\t}\n}\n"
5
+ "import postgres from \"postgres\";\n\ninterface ListenOptions {\n\t/**\n\t * Connection string to LISTEN on. Defaults to `process.env.DATABASE_URL`.\n\t * In dual-DB mode, pass `SOURCE_DATABASE_URL` for indexer-fired channels\n\t * (`indexer:new_block`, `subgraph_reorg`, `tx:confirmed`) and\n\t * `TARGET_DATABASE_URL` for tenant-local channels (`subgraph_changes`).\n\t */\n\tconnectionString?: string;\n}\n\n/**\n * LISTEN/NOTIFY connection for indexer-fired channels (`indexer:new_block`,\n * `subgraph_reorg`, `tx:confirmed`) — they fire on the SOURCE (chain) DB.\n * `||` (not `??`) so an empty-string env (an unset `SOURCE_DATABASE_URL` passed\n * through docker-compose as `\"\"`) falls back to `DATABASE_URL`.\n */\nexport function sourceListenerUrl(): string | undefined {\n\treturn process.env.SOURCE_DATABASE_URL || process.env.DATABASE_URL;\n}\n\n/**\n * LISTEN/NOTIFY connection for control-plane channels (`subscriptions:new_outbox`,\n * `subscriptions:changed`, subgraph operations) — they fire on the TARGET DB.\n */\nexport function targetListenerUrl(): string | undefined {\n\treturn process.env.TARGET_DATABASE_URL || process.env.DATABASE_URL;\n}\n\nfunction resolveUrl(opts?: ListenOptions): string {\n\t// `||` not `??`: an empty-string connectionString (e.g. an unset\n\t// SOURCE_/TARGET_DATABASE_URL passed through docker-compose as \"\") must fall\n\t// back to DATABASE_URL, not be treated as a valid value.\n\tconst url = opts?.connectionString || process.env.DATABASE_URL;\n\tif (!url) {\n\t\tthrow new Error(\n\t\t\t\"listen/notify requires a connection string (opts.connectionString or DATABASE_URL)\",\n\t\t);\n\t}\n\treturn url;\n}\n\nexport async function listen(\n\tchannel: string,\n\tcallback: (payload?: string) => void,\n\topts?: ListenOptions,\n): Promise<() => Promise<void>> {\n\tconst client = postgres(resolveUrl(opts), {\n\t\tmax: 1,\n\t\tonnotice: () => {},\n\t});\n\n\tawait client.listen(channel, (payload) => {\n\t\tcallback(payload);\n\t});\n\n\treturn async () => {\n\t\tawait client.end();\n\t};\n}\n\nexport async function notify(\n\tchannel: string,\n\tpayload?: string,\n\topts?: ListenOptions,\n): Promise<void> {\n\tconst client = postgres(resolveUrl(opts), { max: 1 });\n\n\ttry {\n\t\tif (payload) {\n\t\t\tawait client`SELECT pg_notify(${channel}, ${payload})`;\n\t\t} else {\n\t\t\tawait client`SELECT pg_notify(${channel}, '')`;\n\t\t}\n\t} finally {\n\t\tawait client.end();\n\t}\n}\n"
6
6
  ],
7
- "mappings": ";;;;;;;;;;;;;;;;;AAAA;AAYA,SAAS,UAAU,CAAC,MAA8B;AAAA,EAIjD,MAAM,MAAM,MAAM,oBAAoB,QAAQ,IAAI;AAAA,EAClD,IAAI,CAAC,KAAK;AAAA,IACT,MAAM,IAAI,MACT,oFACD;AAAA,EACD;AAAA,EACA,OAAO;AAAA;AAGR,eAAsB,MAAM,CAC3B,SACA,UACA,MAC+B;AAAA,EAC/B,MAAM,SAAS,SAAS,WAAW,IAAI,GAAG;AAAA,IACzC,KAAK;AAAA,IACL,UAAU,MAAM;AAAA,EACjB,CAAC;AAAA,EAED,MAAM,OAAO,OAAO,SAAS,CAAC,YAAY;AAAA,IACzC,SAAS,OAAO;AAAA,GAChB;AAAA,EAED,OAAO,YAAY;AAAA,IAClB,MAAM,OAAO,IAAI;AAAA;AAAA;AAInB,eAAsB,MAAM,CAC3B,SACA,SACA,MACgB;AAAA,EAChB,MAAM,SAAS,SAAS,WAAW,IAAI,GAAG,EAAE,KAAK,EAAE,CAAC;AAAA,EAEpD,IAAI;AAAA,IACH,IAAI,SAAS;AAAA,MACZ,MAAM,0BAA0B,YAAY;AAAA,IAC7C,EAAO;AAAA,MACN,MAAM,0BAA0B;AAAA;AAAA,YAEhC;AAAA,IACD,MAAM,OAAO,IAAI;AAAA;AAAA;",
8
- "debugId": "B1060AE6BF370F9B64756E2164756E21",
7
+ "mappings": ";;;;;;;;;;;;;;;;;AAAA;AAkBO,SAAS,iBAAiB,GAAuB;AAAA,EACvD,OAAO,QAAQ,IAAI,uBAAuB,QAAQ,IAAI;AAAA;AAOhD,SAAS,iBAAiB,GAAuB;AAAA,EACvD,OAAO,QAAQ,IAAI,uBAAuB,QAAQ,IAAI;AAAA;AAGvD,SAAS,UAAU,CAAC,MAA8B;AAAA,EAIjD,MAAM,MAAM,MAAM,oBAAoB,QAAQ,IAAI;AAAA,EAClD,IAAI,CAAC,KAAK;AAAA,IACT,MAAM,IAAI,MACT,oFACD;AAAA,EACD;AAAA,EACA,OAAO;AAAA;AAGR,eAAsB,MAAM,CAC3B,SACA,UACA,MAC+B;AAAA,EAC/B,MAAM,SAAS,SAAS,WAAW,IAAI,GAAG;AAAA,IACzC,KAAK;AAAA,IACL,UAAU,MAAM;AAAA,EACjB,CAAC;AAAA,EAED,MAAM,OAAO,OAAO,SAAS,CAAC,YAAY;AAAA,IACzC,SAAS,OAAO;AAAA,GAChB;AAAA,EAED,OAAO,YAAY;AAAA,IAClB,MAAM,OAAO,IAAI;AAAA;AAAA;AAInB,eAAsB,MAAM,CAC3B,SACA,SACA,MACgB;AAAA,EAChB,MAAM,SAAS,SAAS,WAAW,IAAI,GAAG,EAAE,KAAK,EAAE,CAAC;AAAA,EAEpD,IAAI;AAAA,IACH,IAAI,SAAS;AAAA,MACZ,MAAM,0BAA0B,YAAY;AAAA,IAC7C,EAAO;AAAA,MACN,MAAM,0BAA0B;AAAA;AAAA,YAEhC;AAAA,IACD,MAAM,OAAO,IAAI;AAAA;AAAA;",
8
+ "debugId": "CDCEFCF2F72FC7C464756E2164756E21",
9
9
  "names": []
10
10
  }
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@secondlayer/shared",
3
- "version": "6.20.0",
3
+ "version": "6.21.0",
4
4
  "license": "MIT",
5
5
  "repository": {
6
6
  "type": "git",