@secondlayer/shared 11.24.1 → 12.0.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.
Files changed (32) hide show
  1. package/dist/src/archive/range-digest.d.ts +8 -19
  2. package/dist/src/archive/semantic-digest-builder.d.ts +8 -19
  3. package/dist/src/coverage/index.d.ts +8 -19
  4. package/dist/src/db/index.d.ts +9 -20
  5. package/dist/src/db/queries/chain-reorgs.d.ts +8 -19
  6. package/dist/src/db/queries/contracts.d.ts +8 -19
  7. package/dist/src/db/queries/instance.d.ts +8 -19
  8. package/dist/src/db/queries/integrity.d.ts +8 -19
  9. package/dist/src/db/queries/subgraph-gaps.d.ts +8 -19
  10. package/dist/src/db/queries/subgraph-operations.d.ts +8 -19
  11. package/dist/src/db/queries/subgraphs.d.ts +8 -19
  12. package/dist/src/db/queries/subgraphs.js +1 -7
  13. package/dist/src/db/queries/subgraphs.js.map +4 -4
  14. package/dist/src/db/queries/sync-scope.d.ts +8 -19
  15. package/dist/src/db/queries/webhooks.d.ts +11 -33
  16. package/dist/src/db/queries/webhooks.js +3 -12
  17. package/dist/src/db/queries/webhooks.js.map +3 -3
  18. package/dist/src/db/schema.d.ts +9 -20
  19. package/dist/src/index.d.ts +15 -81
  20. package/dist/src/index.js +3 -108
  21. package/dist/src/index.js.map +4 -4
  22. package/dist/src/node/local-client.d.ts +8 -19
  23. package/dist/src/schemas/index.d.ts +7 -62
  24. package/dist/src/schemas/index.js +3 -108
  25. package/dist/src/schemas/index.js.map +4 -4
  26. package/dist/src/schemas/subgraphs.d.ts +0 -2
  27. package/dist/src/schemas/subgraphs.js.map +1 -1
  28. package/dist/src/schemas/webhooks.d.ts +10 -65
  29. package/dist/src/schemas/webhooks.js +2 -107
  30. package/dist/src/schemas/webhooks.js.map +3 -3
  31. package/migrations/0159_drop_subgraph_row_webhooks.ts +91 -0
  32. package/package.json +1 -1
@@ -0,0 +1,91 @@
1
+ import { type Kysely, sql } from "kysely";
2
+ import { onControlPlane } from "../src/db/migration-role.ts";
3
+
4
+ /**
5
+ * Webhooks fire on chain events only. Delete subgraph-row webhooks (their
6
+ * outbox and delivery rows cascade) and drop the columns that described them:
7
+ * `subgraph_name`, `table_name`, `filter`, `runtime` on `webhooks` and
8
+ * `subgraph_name`, `table_name` on `webhook_outbox`. `kind` stays, narrowed to
9
+ * `'chain'` by CHECK. Control plane only (tables are TARGET).
10
+ *
11
+ * `down` restores the columns, defaults and constraints. The deleted rows are
12
+ * not restored.
13
+ */
14
+ export async function up(db: Kysely<unknown>): Promise<void> {
15
+ await sql`SET lock_timeout = '30s'`.execute(db);
16
+ await onControlPlane(async () => {
17
+ const { rows } = await sql<{ name: string }>`
18
+ SELECT name FROM webhooks WHERE kind = 'subgraph' ORDER BY name
19
+ `.execute(db);
20
+ if (rows.length > 0) {
21
+ console.warn(
22
+ `[0159] Deleted ${rows.length} subgraph webhook(s): ${rows.map((r) => r.name).join(", ")}. Subgraph webhooks were removed; react to rows from your Postgres or the subgraph API: https://www.secondlayer.tools/docs/subgraphs/reading#react-to-your-rows`,
23
+ );
24
+ }
25
+ // FK ON DELETE CASCADE removes their outbox (0057) and delivery rows (0140).
26
+ await sql`DELETE FROM webhooks WHERE kind = 'subgraph'`.execute(db);
27
+ await sql`DELETE FROM webhook_outbox WHERE kind = 'subgraph'`.execute(db);
28
+ await sql`DROP INDEX webhooks_matcher_idx`.execute(db);
29
+ await sql`ALTER TABLE webhooks DROP CONSTRAINT webhooks_kind_shape`.execute(
30
+ db,
31
+ );
32
+ await sql`ALTER TABLE webhooks DROP COLUMN subgraph_name, DROP COLUMN table_name, DROP COLUMN filter, DROP COLUMN runtime`.execute(
33
+ db,
34
+ );
35
+ await sql`ALTER TABLE webhooks ALTER COLUMN kind SET DEFAULT 'chain', ALTER COLUMN triggers SET NOT NULL`.execute(
36
+ db,
37
+ );
38
+ await sql`ALTER TABLE webhooks ADD CONSTRAINT webhooks_kind_shape CHECK (kind = 'chain')`.execute(
39
+ db,
40
+ );
41
+ await sql`ALTER TABLE webhook_outbox DROP COLUMN subgraph_name, DROP COLUMN table_name`.execute(
42
+ db,
43
+ );
44
+ await sql`ALTER TABLE webhook_outbox ALTER COLUMN kind SET DEFAULT 'chain'`.execute(
45
+ db,
46
+ );
47
+ await sql`ALTER TABLE webhook_outbox ADD CONSTRAINT webhook_outbox_kind_chain CHECK (kind = 'chain')`.execute(
48
+ db,
49
+ );
50
+ });
51
+ }
52
+
53
+ export async function down(db: Kysely<unknown>): Promise<void> {
54
+ await sql`SET lock_timeout = '30s'`.execute(db);
55
+ await onControlPlane(async () => {
56
+ await sql`ALTER TABLE webhook_outbox DROP CONSTRAINT webhook_outbox_kind_chain`.execute(
57
+ db,
58
+ );
59
+ await sql`ALTER TABLE webhook_outbox ALTER COLUMN kind SET DEFAULT 'subgraph'`.execute(
60
+ db,
61
+ );
62
+ await sql`ALTER TABLE webhook_outbox ADD COLUMN subgraph_name TEXT, ADD COLUMN table_name TEXT`.execute(
63
+ db,
64
+ );
65
+ await sql`ALTER TABLE webhooks DROP CONSTRAINT webhooks_kind_shape`.execute(
66
+ db,
67
+ );
68
+ await sql`ALTER TABLE webhooks ALTER COLUMN triggers DROP NOT NULL, ALTER COLUMN kind SET DEFAULT 'subgraph'`.execute(
69
+ db,
70
+ );
71
+ await sql`
72
+ ALTER TABLE webhooks
73
+ ADD COLUMN subgraph_name TEXT,
74
+ ADD COLUMN table_name TEXT,
75
+ ADD COLUMN filter JSONB NOT NULL DEFAULT '{}'::jsonb,
76
+ ADD COLUMN runtime TEXT
77
+ `.execute(db);
78
+ await sql`
79
+ ALTER TABLE webhooks ADD CONSTRAINT webhooks_kind_shape CHECK (
80
+ (kind = 'subgraph' AND subgraph_name IS NOT NULL AND table_name IS NOT NULL AND triggers IS NULL)
81
+ OR
82
+ (kind = 'chain' AND triggers IS NOT NULL AND subgraph_name IS NULL AND table_name IS NULL)
83
+ )
84
+ `.execute(db);
85
+ await sql`
86
+ CREATE INDEX webhooks_matcher_idx
87
+ ON webhooks (subgraph_name, table_name, status)
88
+ WHERE status = 'active'
89
+ `.execute(db);
90
+ });
91
+ }
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@secondlayer/shared",
3
- "version": "11.24.1",
3
+ "version": "12.0.0",
4
4
  "description": "Internal building blocks shared across Secondlayer packages.",
5
5
  "license": "MIT",
6
6
  "repository": {