@secondlayer/shared 19.0.0 → 19.1.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 (37) hide show
  1. package/dist/src/archive/range-digest.d.ts +10 -0
  2. package/dist/src/archive/semantic-digest-builder.d.ts +10 -0
  3. package/dist/src/coverage/index.d.ts +10 -0
  4. package/dist/src/db/index.d.ts +12 -1
  5. package/dist/src/db/index.js +2 -1
  6. package/dist/src/db/index.js.map +4 -4
  7. package/dist/src/db/queries/chain-reorgs.d.ts +10 -0
  8. package/dist/src/db/queries/chain-reorgs.js +2 -1
  9. package/dist/src/db/queries/chain-reorgs.js.map +4 -4
  10. package/dist/src/db/queries/contracts.d.ts +10 -0
  11. package/dist/src/db/queries/contracts.js.map +1 -1
  12. package/dist/src/db/queries/instance.d.ts +10 -0
  13. package/dist/src/db/queries/integrity.d.ts +10 -0
  14. package/dist/src/db/queries/subgraph-gaps.d.ts +10 -0
  15. package/dist/src/db/queries/subgraph-operations.d.ts +10 -0
  16. package/dist/src/db/queries/subgraphs.d.ts +10 -0
  17. package/dist/src/db/queries/sync-scope.d.ts +10 -0
  18. package/dist/src/db/queries/webhook-replays.d.ts +10 -0
  19. package/dist/src/db/queries/webhooks.d.ts +10 -0
  20. package/dist/src/db/schema.d.ts +11 -1
  21. package/dist/src/db/schema.js.map +1 -1
  22. package/dist/src/index.d.ts +12 -1
  23. package/dist/src/index.js +22 -1
  24. package/dist/src/index.js.map +5 -5
  25. package/dist/src/insights/index.d.ts +10 -0
  26. package/dist/src/leader.js +2 -1
  27. package/dist/src/leader.js.map +4 -4
  28. package/dist/src/node/local-client.d.ts +10 -0
  29. package/dist/src/queue/listener.js +2 -1
  30. package/dist/src/queue/listener.js.map +4 -4
  31. package/dist/src/schemas/index.js +21 -1
  32. package/dist/src/schemas/index.js.map +3 -3
  33. package/dist/src/schemas/webhooks.d.ts +5 -0
  34. package/dist/src/schemas/webhooks.js +21 -1
  35. package/dist/src/schemas/webhooks.js.map +3 -3
  36. package/migrations/0217_usage_monthly_totals.ts +41 -0
  37. package/package.json +1 -1
@@ -0,0 +1,41 @@
1
+ import { type Kysely, sql } from "kysely";
2
+ import { onControlPlane } from "../src/db/migration-role.ts";
3
+
4
+ /**
5
+ * Running `usage_ledger` total per account, unit and UTC month (`YYYY-MM` of
6
+ * `occurred_at`). `claimLedgerEntry` bumps it in the same transaction that
7
+ * writes the ledger row, so allowance checks read one row instead of summing
8
+ * the month's ledger. Backfills the last 3 months — `/internal/meters` takes
9
+ * items up to 35 days old, so no write lands further back.
10
+ */
11
+ export async function up(db: Kysely<unknown>): Promise<void> {
12
+ await sql`SET lock_timeout = '30s'`.execute(db);
13
+ await onControlPlane(async () => {
14
+ await sql`
15
+ CREATE TABLE IF NOT EXISTS usage_monthly_totals (
16
+ account_id uuid NOT NULL REFERENCES accounts(id) ON DELETE CASCADE,
17
+ unit text NOT NULL,
18
+ month text NOT NULL,
19
+ quantity numeric NOT NULL DEFAULT 0,
20
+ PRIMARY KEY (account_id, unit, month)
21
+ )
22
+ `.execute(db);
23
+ await sql`
24
+ INSERT INTO usage_monthly_totals (account_id, unit, month, quantity)
25
+ SELECT account_id, unit,
26
+ to_char(occurred_at AT TIME ZONE 'UTC', 'YYYY-MM'),
27
+ sum(quantity)
28
+ FROM usage_ledger
29
+ WHERE occurred_at >= date_trunc('month', now() AT TIME ZONE 'UTC') AT TIME ZONE 'UTC' - interval '2 months'
30
+ GROUP BY 1, 2, 3
31
+ ON CONFLICT (account_id, unit, month)
32
+ DO UPDATE SET quantity = EXCLUDED.quantity
33
+ `.execute(db);
34
+ });
35
+ }
36
+
37
+ export async function down(db: Kysely<unknown>): Promise<void> {
38
+ await onControlPlane(async () => {
39
+ await sql`DROP TABLE IF EXISTS usage_monthly_totals`.execute(db);
40
+ });
41
+ }
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@secondlayer/shared",
3
- "version": "19.0.0",
3
+ "version": "19.1.0",
4
4
  "description": "Internal building blocks shared across Secondlayer packages.",
5
5
  "license": "MIT",
6
6
  "repository": {