@secondlayer/shared 11.7.1 → 11.8.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 (161) hide show
  1. package/dist/src/archive/copy-loader.d.ts +1 -1
  2. package/dist/src/archive/copy-loader.js +4 -20
  3. package/dist/src/archive/copy-loader.js.map +2 -2
  4. package/dist/src/archive/derived-stage-report.d.ts +1 -1
  5. package/dist/src/archive/derived-stage-report.js +3 -19
  6. package/dist/src/archive/derived-stage-report.js.map +2 -2
  7. package/dist/src/archive/disk-guard.d.ts +1 -1
  8. package/dist/src/archive/disk-guard.js +3 -19
  9. package/dist/src/archive/disk-guard.js.map +2 -2
  10. package/dist/src/archive/instance-diagnosis.d.ts +1 -1
  11. package/dist/src/archive/instance-diagnosis.js +6 -22
  12. package/dist/src/archive/instance-diagnosis.js.map +2 -2
  13. package/dist/src/archive/key-registry.d.ts +1 -1
  14. package/dist/src/archive/key-registry.js +12 -12
  15. package/dist/src/archive/key-registry.js.map +1 -1
  16. package/dist/src/archive/per-height-digest.d.ts +1 -1
  17. package/dist/src/archive/per-height-digest.js +3 -17
  18. package/dist/src/archive/per-height-digest.js.map +5 -5
  19. package/dist/src/archive/progress.d.ts +1 -1
  20. package/dist/src/archive/progress.js +4 -20
  21. package/dist/src/archive/progress.js.map +2 -2
  22. package/dist/src/archive/range-digest.d.ts +2 -3
  23. package/dist/src/archive/range-digest.js +4 -20
  24. package/dist/src/archive/range-digest.js.map +2 -2
  25. package/dist/src/archive/reference.d.ts +1 -1
  26. package/dist/src/archive/reference.js +14 -12
  27. package/dist/src/archive/reference.js.map +5 -5
  28. package/dist/src/archive/root-key.d.ts +1 -1
  29. package/dist/src/archive/root-key.js +3 -19
  30. package/dist/src/archive/root-key.js.map +2 -2
  31. package/dist/src/archive/semantic-digest-builder.d.ts +2 -3
  32. package/dist/src/archive/semantic-digest-builder.js +5 -19
  33. package/dist/src/archive/semantic-digest-builder.js.map +5 -5
  34. package/dist/src/archive/semantic-digest.d.ts +1 -1
  35. package/dist/src/archive/semantic-digest.js +4 -20
  36. package/dist/src/archive/semantic-digest.js.map +2 -2
  37. package/dist/src/archive/status.d.ts +1 -1
  38. package/dist/src/archive/status.js +4 -20
  39. package/dist/src/archive/status.js.map +2 -2
  40. package/dist/src/coverage/index.d.ts +1 -2
  41. package/dist/src/coverage/index.js +80 -96
  42. package/dist/src/coverage/index.js.map +2 -2
  43. package/dist/src/crypto/ed25519.d.ts +1 -1
  44. package/dist/src/crypto/ed25519.js +13 -13
  45. package/dist/src/crypto/ed25519.js.map +1 -1
  46. package/dist/src/crypto/hmac.d.ts +1 -1
  47. package/dist/src/crypto/hmac.js +9 -9
  48. package/dist/src/crypto/hmac.js.map +1 -1
  49. package/dist/src/crypto/secondlayer-webhook.d.ts +1 -1
  50. package/dist/src/crypto/secondlayer-webhook.js +14 -14
  51. package/dist/src/crypto/secondlayer-webhook.js.map +2 -2
  52. package/dist/src/crypto/secrets.d.ts +1 -1
  53. package/dist/src/crypto/secrets.js +15 -29
  54. package/dist/src/crypto/secrets.js.map +5 -5
  55. package/dist/src/crypto/standard-webhooks.d.ts +1 -1
  56. package/dist/src/crypto/standard-webhooks.js +3 -19
  57. package/dist/src/crypto/standard-webhooks.js.map +2 -2
  58. package/dist/src/db/index.d.ts +18 -19
  59. package/dist/src/db/index.js +40 -55
  60. package/dist/src/db/index.js.map +5 -5
  61. package/dist/src/db/jsonb.d.ts +1 -1
  62. package/dist/src/db/jsonb.js +3 -19
  63. package/dist/src/db/jsonb.js.map +2 -2
  64. package/dist/src/db/queries/chain-reorgs.d.ts +1 -2
  65. package/dist/src/db/queries/chain-reorgs.js +27 -42
  66. package/dist/src/db/queries/chain-reorgs.js.map +5 -5
  67. package/dist/src/db/queries/contracts.d.ts +1 -2
  68. package/dist/src/db/queries/contracts.js +9 -23
  69. package/dist/src/db/queries/contracts.js.map +5 -5
  70. package/dist/src/db/queries/instance.d.ts +1 -2
  71. package/dist/src/db/queries/instance.js +7 -23
  72. package/dist/src/db/queries/instance.js.map +2 -2
  73. package/dist/src/db/queries/integrity.d.ts +1 -2
  74. package/dist/src/db/queries/integrity.js +5 -21
  75. package/dist/src/db/queries/integrity.js.map +2 -2
  76. package/dist/src/db/queries/subgraph-gaps.d.ts +1 -2
  77. package/dist/src/db/queries/subgraph-gaps.js +5 -21
  78. package/dist/src/db/queries/subgraph-gaps.js.map +2 -2
  79. package/dist/src/db/queries/subgraph-operations.d.ts +1 -2
  80. package/dist/src/db/queries/subgraph-operations.js +17 -33
  81. package/dist/src/db/queries/subgraph-operations.js.map +2 -2
  82. package/dist/src/db/queries/subgraphs.d.ts +2 -14
  83. package/dist/src/db/queries/subgraphs.js +15 -37
  84. package/dist/src/db/queries/subgraphs.js.map +5 -5
  85. package/dist/src/db/queries/sync-scope.d.ts +1 -2
  86. package/dist/src/db/queries/sync-scope.js +6 -22
  87. package/dist/src/db/queries/sync-scope.js.map +2 -2
  88. package/dist/src/db/queries/webhooks.d.ts +1 -2
  89. package/dist/src/db/queries/webhooks.js +54 -50
  90. package/dist/src/db/queries/webhooks.js.map +5 -5
  91. package/dist/src/db/schema.d.ts +1 -2
  92. package/dist/src/env.d.ts +1 -1
  93. package/dist/src/env.js +7 -23
  94. package/dist/src/env.js.map +2 -2
  95. package/dist/src/errors.d.ts +1 -1
  96. package/dist/src/errors.js +15 -31
  97. package/dist/src/errors.js.map +2 -2
  98. package/dist/src/index-http.d.ts +1 -1
  99. package/dist/src/index-http.js +3 -19
  100. package/dist/src/index-http.js.map +2 -2
  101. package/dist/src/index-internal-auth.d.ts +1 -1
  102. package/dist/src/index-internal-auth.js +7 -23
  103. package/dist/src/index-internal-auth.js.map +2 -2
  104. package/dist/src/index.d.ts +136 -149
  105. package/dist/src/index.js +259 -313
  106. package/dist/src/index.js.map +12 -12
  107. package/dist/src/leader.d.ts +1 -1
  108. package/dist/src/leader.js +7 -21
  109. package/dist/src/leader.js.map +5 -5
  110. package/dist/src/logger.js +1 -17
  111. package/dist/src/logger.js.map +2 -2
  112. package/dist/src/mode.d.ts +1 -1
  113. package/dist/src/mode.js +5 -21
  114. package/dist/src/mode.js.map +2 -2
  115. package/dist/src/node/archive-client.d.ts +1 -1
  116. package/dist/src/node/archive-client.js +9 -23
  117. package/dist/src/node/archive-client.js.map +5 -5
  118. package/dist/src/node/client.d.ts +1 -1
  119. package/dist/src/node/client.js +4 -18
  120. package/dist/src/node/client.js.map +5 -5
  121. package/dist/src/node/consensus.d.ts +1 -1
  122. package/dist/src/node/consensus.js +5 -21
  123. package/dist/src/node/consensus.js.map +2 -2
  124. package/dist/src/node/hiro-client.d.ts +1 -1
  125. package/dist/src/node/hiro-client.js +1 -17
  126. package/dist/src/node/hiro-client.js.map +2 -2
  127. package/dist/src/node/hiro-pg-client.js +1 -17
  128. package/dist/src/node/hiro-pg-client.js.map +2 -2
  129. package/dist/src/node/local-client.d.ts +1 -2
  130. package/dist/src/node/local-client.js +3 -19
  131. package/dist/src/node/local-client.js.map +2 -2
  132. package/dist/src/node/nakamoto.d.ts +1 -1
  133. package/dist/src/node/nakamoto.js +12 -28
  134. package/dist/src/node/nakamoto.js.map +2 -2
  135. package/dist/src/queue/listener.d.ts +1 -1
  136. package/dist/src/queue/listener.js +4 -20
  137. package/dist/src/queue/listener.js.map +2 -2
  138. package/dist/src/runtime/index.d.ts +1 -1
  139. package/dist/src/runtime/index.js +51 -67
  140. package/dist/src/runtime/index.js.map +2 -2
  141. package/dist/src/schemas/index.d.ts +1 -4
  142. package/dist/src/schemas/index.js +19 -37
  143. package/dist/src/schemas/index.js.map +3 -3
  144. package/dist/src/schemas/subgraphs.d.ts +1 -4
  145. package/dist/src/schemas/subgraphs.js +1 -18
  146. package/dist/src/schemas/subgraphs.js.map +3 -3
  147. package/dist/src/schemas/webhooks.d.ts +1 -1
  148. package/dist/src/schemas/webhooks.js +21 -37
  149. package/dist/src/schemas/webhooks.js.map +2 -2
  150. package/dist/src/streams-bulk-manifest.d.ts +1 -1
  151. package/dist/src/streams-bulk-manifest.js +9 -9
  152. package/dist/src/streams-bulk-manifest.js.map +1 -1
  153. package/dist/src/streams-rows/index.d.ts +1 -1
  154. package/dist/src/streams-rows/index.js +32 -48
  155. package/dist/src/streams-rows/index.js.map +2 -2
  156. package/dist/src/subgraphs/spec.d.ts +1 -11
  157. package/dist/src/subgraphs/spec.js +27 -93
  158. package/dist/src/subgraphs/spec.js.map +3 -3
  159. package/dist/src/types.d.ts +1 -1
  160. package/migrations/0136_drop_subgraph_visibility.ts +34 -0
  161. package/package.json +1 -1
package/dist/src/index.js CHANGED
@@ -13,6 +13,70 @@ var __export = (target, all) => {
13
13
  set: __exportSetter.bind(all, name)
14
14
  });
15
15
  };
16
+ // src/event-types.ts
17
+ import {
18
+ DECODED_EVENT_TYPES
19
+ } from "@secondlayer/stacks/filters";
20
+ import {
21
+ DECODED_EVENT_TYPES as DECODED_EVENT_TYPES2,
22
+ VM_EVENT_TYPES,
23
+ VM_NODE_TO_STORED_TYPE
24
+ } from "@secondlayer/stacks/filters";
25
+ var VM_STORED_TO_NODE_TYPE = {
26
+ nested_contract_call: "contract_call_event",
27
+ var_set: "var_set_event",
28
+ map_set: "map_set_event",
29
+ map_insert: "map_insert_event",
30
+ map_delete: "map_delete_event"
31
+ };
32
+ var STREAMS_EVENT_TYPES = DECODED_EVENT_TYPES;
33
+ // src/db-event-types.ts
34
+ var STREAMS_DB_EVENT_TYPES = [
35
+ "stx_transfer_event",
36
+ "stx_mint_event",
37
+ "stx_burn_event",
38
+ "stx_lock_event",
39
+ "ft_transfer_event",
40
+ "ft_mint_event",
41
+ "ft_burn_event",
42
+ "nft_transfer_event",
43
+ "nft_mint_event",
44
+ "nft_burn_event",
45
+ "smart_contract_event",
46
+ "contract_event"
47
+ ];
48
+ var DB_TO_STREAMS_EVENT_TYPE = {
49
+ stx_transfer_event: "stx_transfer",
50
+ stx_mint_event: "stx_mint",
51
+ stx_burn_event: "stx_burn",
52
+ stx_lock_event: "stx_lock",
53
+ ft_transfer_event: "ft_transfer",
54
+ ft_mint_event: "ft_mint",
55
+ ft_burn_event: "ft_burn",
56
+ nft_transfer_event: "nft_transfer",
57
+ nft_mint_event: "nft_mint",
58
+ nft_burn_event: "nft_burn",
59
+ smart_contract_event: "print",
60
+ contract_event: "print"
61
+ };
62
+ var STREAMS_TO_DB_EVENT_TYPES = {
63
+ stx_transfer: ["stx_transfer_event"],
64
+ stx_mint: ["stx_mint_event"],
65
+ stx_burn: ["stx_burn_event"],
66
+ stx_lock: ["stx_lock_event"],
67
+ ft_transfer: ["ft_transfer_event"],
68
+ ft_mint: ["ft_mint_event"],
69
+ ft_burn: ["ft_burn_event"],
70
+ nft_transfer: ["nft_transfer_event"],
71
+ nft_mint: ["nft_mint_event"],
72
+ nft_burn: ["nft_burn_event"],
73
+ print: ["smart_contract_event", "contract_event"]
74
+ };
75
+ // src/db/index.ts
76
+ import { Kysely } from "kysely";
77
+ import { PostgresJSDialect } from "kysely-postgres-js";
78
+ import postgres from "postgres";
79
+
16
80
  // src/env.ts
17
81
  import { z } from "zod";
18
82
  var networksSchema = z.string().transform((val) => {
@@ -178,27 +242,7 @@ function isOssMode() {
178
242
  return getInstanceMode() === "oss";
179
243
  }
180
244
 
181
- // src/db/jsonb.ts
182
- import { sql } from "kysely";
183
- function jsonb(value) {
184
- const escaped = JSON.stringify(value, (_k, v) => typeof v === "bigint" ? v.toString() : v).replace(/'/g, "''");
185
- return sql`${sql.raw(`'${escaped}'::jsonb`)}`;
186
- }
187
- function parseJsonb(value) {
188
- if (typeof value === "string") {
189
- try {
190
- return JSON.parse(value);
191
- } catch {
192
- return value;
193
- }
194
- }
195
- return value ?? {};
196
- }
197
-
198
245
  // src/db/index.ts
199
- import { Kysely } from "kysely";
200
- import { PostgresJSDialect } from "kysely-postgres-js";
201
- import postgres from "postgres";
202
246
  import { sql as sql2 } from "kysely";
203
247
 
204
248
  // src/db/source-read-columns.ts
@@ -715,6 +759,22 @@ var SOURCE_READ_PKS = {
715
759
  events: ["tx_id", "event_index"],
716
760
  chain_reorgs: null
717
761
  };
762
+ // src/db/jsonb.ts
763
+ import { sql } from "kysely";
764
+ function jsonb(value) {
765
+ const escaped = JSON.stringify(value, (_k, v) => typeof v === "bigint" ? v.toString() : v).replace(/'/g, "''");
766
+ return sql`${sql.raw(`'${escaped}'::jsonb`)}`;
767
+ }
768
+ function parseJsonb(value) {
769
+ if (typeof value === "string") {
770
+ try {
771
+ return JSON.parse(value);
772
+ } catch {
773
+ return value;
774
+ }
775
+ }
776
+ return value ?? {};
777
+ }
718
778
  // src/db/migration-role.ts
719
779
  var currentRole = "both";
720
780
  function setMigrationRole(role) {
@@ -1098,12 +1158,58 @@ var CODE_TO_STATUS = {
1098
1158
  function getErrorMessage(err) {
1099
1159
  return err instanceof Error ? err.message : String(err);
1100
1160
  }
1101
-
1161
+ // src/finality.ts
1162
+ var DEFAULT_BTC_CONFIRMATIONS = 6;
1163
+ function finalizedBurnHeight(burnTipHeight, confirmations = DEFAULT_BTC_CONFIRMATIONS) {
1164
+ if (!Number.isInteger(burnTipHeight) || burnTipHeight < 0) {
1165
+ throw new Error("burnTipHeight must be a non-negative integer");
1166
+ }
1167
+ if (!Number.isInteger(confirmations) || confirmations < 0) {
1168
+ throw new Error("confirmations must be a non-negative integer");
1169
+ }
1170
+ return Math.max(0, burnTipHeight - confirmations);
1171
+ }
1172
+ // src/streams-cursor.ts
1173
+ var EMPTY_RANGE_EVENT_INDEX_SENTINEL = 2147483647;
1174
+ function encodeStreamsCursor(cursor) {
1175
+ return `${cursor.block_height}:${cursor.event_index}`;
1176
+ }
1177
+ function decodeStreamsCursor(cursor) {
1178
+ const match = /^(0|[1-9]\d*):(0|[1-9]\d*)$/.exec(cursor);
1179
+ if (!match) {
1180
+ throw new Error("Invalid Streams cursor");
1181
+ }
1182
+ const decoded = {
1183
+ block_height: Number(match[1]),
1184
+ event_index: Number(match[2])
1185
+ };
1186
+ if (!Number.isSafeInteger(decoded.block_height) || !Number.isSafeInteger(decoded.event_index)) {
1187
+ throw new Error("Invalid Streams cursor");
1188
+ }
1189
+ return decoded;
1190
+ }
1191
+ function compareStreamsCursor(a, b) {
1192
+ if (a.block_height !== b.block_height) {
1193
+ return a.block_height < b.block_height ? -1 : 1;
1194
+ }
1195
+ if (a.event_index !== b.event_index) {
1196
+ return a.event_index < b.event_index ? -1 : 1;
1197
+ }
1198
+ return 0;
1199
+ }
1200
+ function isEmptyRangeCursor(cursor) {
1201
+ return cursor.event_index === EMPTY_RANGE_EVENT_INDEX_SENTINEL;
1202
+ }
1203
+ function blockEndCursor(height) {
1204
+ return {
1205
+ block_height: height,
1206
+ event_index: EMPTY_RANGE_EVENT_INDEX_SENTINEL
1207
+ };
1208
+ }
1102
1209
  // src/schemas/subgraphs.ts
1103
1210
  import { z as z2 } from "zod";
1104
1211
  var DeploySubgraphRequestSchema = z2.object({
1105
1212
  name: z2.string().regex(/^[a-z0-9-]+$/, "lowercase alphanumeric + hyphens only").max(63),
1106
- version: z2.string().optional(),
1107
1213
  description: z2.string().optional(),
1108
1214
  sources: z2.record(z2.string(), z2.record(z2.string(), z2.unknown())).refine((s) => Object.keys(s).length > 0, "Must have at least one source"),
1109
1215
  schema: z2.record(z2.string(), z2.unknown()),
@@ -1112,7 +1218,6 @@ var DeploySubgraphRequestSchema = z2.object({
1112
1218
  sourceCode: z2.string().max(1048576, "source code exceeds 1MB limit").optional(),
1113
1219
  dryRun: z2.boolean().optional()
1114
1220
  });
1115
-
1116
1221
  // src/schemas/webhooks.ts
1117
1222
  import { z as z3 } from "zod";
1118
1223
  var WEBHOOK_FORMATS = [
@@ -1517,24 +1622,19 @@ function validateWebhookFilterForTable(input) {
1517
1622
  }
1518
1623
  // src/subgraphs/spec.ts
1519
1624
  var SYSTEM_COLUMNS = ["_id", "_block_height", "_tx_id", "_created_at"];
1520
- var BASE_QUERY_PARAMS = ["_limit", "_offset", "_sort", "_order", "_fields"];
1521
- var PUBLIC_BASE_QUERY_PARAMS = ["_limit", "cursor", "_order", "_fields"];
1625
+ var BASE_QUERY_PARAMS = ["_limit", "cursor", "_order", "_fields"];
1522
1626
  var COMPARISON_OPS = ["neq", "gt", "gte", "lt", "lte"];
1523
- function isPublicRead(detail, options) {
1524
- return options.forcePublicRead ?? detail.visibility === "public";
1525
- }
1526
1627
  function generatedAt(options) {
1527
1628
  return options.generatedAt ?? new Date().toISOString();
1528
1629
  }
1529
1630
  function normalizeServerUrl(serverUrl) {
1530
1631
  return (serverUrl ?? "http://127.0.0.1:3800").replace(/\/+$/, "");
1531
1632
  }
1532
- function tablePath(subgraphName, tableName, publicRead) {
1533
- const base = publicRead ? "/v1/subgraphs" : "/api/subgraphs";
1534
- return `${base}/${subgraphName}/${tableName}`;
1633
+ function tablePath(subgraphName, tableName) {
1634
+ return `/v1/subgraphs/${subgraphName}/${tableName}`;
1535
1635
  }
1536
- function countPath(subgraphName, tableName, publicRead) {
1537
- return `${tablePath(subgraphName, tableName, publicRead)}/count`;
1636
+ function countPath(subgraphName, tableName) {
1637
+ return `${tablePath(subgraphName, tableName)}/count`;
1538
1638
  }
1539
1639
  function isTextLike(type) {
1540
1640
  return type === "text" || type === "principal" || type === "timestamp";
@@ -1601,50 +1701,50 @@ function columnEntries(table) {
1601
1701
  return Object.entries(table.columns);
1602
1702
  }
1603
1703
  function selectableColumns(table) {
1604
- return columnEntries(table).map(([name2]) => name2);
1704
+ return columnEntries(table).map(([name]) => name);
1605
1705
  }
1606
1706
  function searchableColumns(table) {
1607
- return columnEntries(table).filter(([, col]) => col.searchable).map(([name2]) => name2);
1707
+ return columnEntries(table).filter(([, col]) => col.searchable).map(([name]) => name);
1608
1708
  }
1609
1709
  function filterNames(table) {
1610
1710
  const result = [];
1611
- for (const [name2, col] of columnEntries(table)) {
1612
- result.push(name2);
1613
- result.push(`${name2}.neq`);
1711
+ for (const [name, col] of columnEntries(table)) {
1712
+ result.push(name);
1713
+ result.push(`${name}.neq`);
1614
1714
  if (isComparable(col.type)) {
1615
- for (const op of COMPARISON_OPS.filter((op2) => op2 !== "neq")) {
1616
- result.push(`${name2}.${op}`);
1715
+ for (const op of COMPARISON_OPS.filter((op) => op !== "neq")) {
1716
+ result.push(`${name}.${op}`);
1617
1717
  }
1618
1718
  }
1619
1719
  if (isTextLike(col.type))
1620
- result.push(`${name2}.like`);
1720
+ result.push(`${name}.like`);
1621
1721
  }
1622
1722
  return result;
1623
1723
  }
1624
- function queryParameters(table, publicRead) {
1625
- const params = publicRead ? [...PUBLIC_BASE_QUERY_PARAMS] : [...BASE_QUERY_PARAMS];
1724
+ function queryParameters(table) {
1725
+ const params = [...BASE_QUERY_PARAMS];
1626
1726
  if (searchableColumns(table).length > 0)
1627
1727
  params.push("_search");
1628
1728
  return params;
1629
1729
  }
1630
1730
  function rowExample(table) {
1631
1731
  const row = {};
1632
- for (const [name2, col] of columnEntries(table)) {
1633
- row[name2] = exampleForColumn(col.type);
1732
+ for (const [name, col] of columnEntries(table)) {
1733
+ row[name] = exampleForColumn(col.type);
1634
1734
  }
1635
1735
  return row;
1636
1736
  }
1637
- function openApiParameter(name2, description, schema = { type: "string" }) {
1737
+ function openApiParameter(name, description, schema = { type: "string" }) {
1638
1738
  return {
1639
- name: name2,
1739
+ name,
1640
1740
  in: "query",
1641
1741
  required: false,
1642
1742
  description,
1643
1743
  schema
1644
1744
  };
1645
1745
  }
1646
- function tableParameters(table, publicRead) {
1647
- const parameters = publicRead ? [
1746
+ function tableParameters(table) {
1747
+ const parameters = [
1648
1748
  openApiParameter("_limit", "Maximum rows to return.", {
1649
1749
  type: "integer",
1650
1750
  default: 50,
@@ -1660,52 +1760,28 @@ function tableParameters(table, publicRead) {
1660
1760
  openApiParameter("_fields", "Comma-separated columns to include.", {
1661
1761
  type: "string"
1662
1762
  })
1663
- ] : [
1664
- openApiParameter("_limit", "Maximum rows to return.", {
1665
- type: "integer",
1666
- default: 50,
1667
- minimum: 1,
1668
- maximum: 1000
1669
- }),
1670
- openApiParameter("_offset", "Rows to skip for pagination.", {
1671
- type: "integer",
1672
- default: 0,
1673
- minimum: 0
1674
- }),
1675
- openApiParameter("_sort", "Column to sort by.", {
1676
- type: "string",
1677
- enum: selectableColumns(table)
1678
- }),
1679
- openApiParameter("_order", "Sort direction.", {
1680
- type: "string",
1681
- enum: ["asc", "desc"],
1682
- default: "asc"
1683
- }),
1684
- openApiParameter("_fields", "Comma-separated columns to include.", {
1685
- type: "string"
1686
- })
1687
1763
  ];
1688
1764
  if (searchableColumns(table).length > 0) {
1689
1765
  parameters.push(openApiParameter("_search", "Search across searchable columns.", {
1690
1766
  type: "string"
1691
1767
  }));
1692
1768
  }
1693
- for (const [name2, col] of columnEntries(table)) {
1694
- parameters.push(openApiParameter(name2, `Filter ${name2} by equality.`, {
1769
+ for (const [name, col] of columnEntries(table)) {
1770
+ parameters.push(openApiParameter(name, `Filter ${name} by equality.`, {
1695
1771
  type: "string"
1696
1772
  }));
1697
- parameters.push(openApiParameter(`${name2}.neq`, `Filter ${name2} by inequality.`, {
1773
+ parameters.push(openApiParameter(`${name}.neq`, `Filter ${name} by inequality.`, {
1698
1774
  type: "string"
1699
1775
  }));
1700
1776
  if (isComparable(col.type)) {
1701
1777
  for (const op of ["gt", "gte", "lt", "lte"]) {
1702
- parameters.push(openApiParameter(`${name2}.${op}`, `Filter ${name2} with ${op}.`, {
1778
+ parameters.push(openApiParameter(`${name}.${op}`, `Filter ${name} with ${op}.`, {
1703
1779
  type: "string"
1704
1780
  }));
1705
1781
  }
1706
1782
  }
1707
1783
  if (isTextLike(col.type)) {
1708
- parameters.push(openApiParameter(`${name2}.like`, `Case-insensitive contains filter for ${name2}.`, {
1784
+ parameters.push(openApiParameter(`${name}.like`, `Case-insensitive contains filter for ${name}.`, {
1709
1785
  type: "string"
1710
1786
  }));
1711
1787
  }
@@ -1714,24 +1790,21 @@ function tableParameters(table, publicRead) {
1714
1790
  }
1715
1791
  function generateSubgraphAgentSchema(detail, options = {}) {
1716
1792
  const serverUrl = normalizeServerUrl(options.serverUrl);
1717
- const publicRead = isPublicRead(detail, options);
1718
1793
  const tables = {};
1719
1794
  for (const [tableName, table] of Object.entries(detail.tables)) {
1720
- const path = tablePath(detail.name, tableName, publicRead);
1795
+ const path = tablePath(detail.name, tableName);
1721
1796
  tables[tableName] = {
1722
1797
  endpoint: `${serverUrl}${path}`,
1723
- countEndpoint: `${serverUrl}${countPath(detail.name, tableName, publicRead)}`,
1724
- ...publicRead ? {
1725
- aggregateEndpoint: `${serverUrl}${path}/aggregate`,
1726
- streamEndpoint: `${serverUrl}${path}/stream`
1727
- } : {},
1798
+ countEndpoint: `${serverUrl}${countPath(detail.name, tableName)}`,
1799
+ aggregateEndpoint: `${serverUrl}${path}/aggregate`,
1800
+ streamEndpoint: `${serverUrl}${path}/stream`,
1728
1801
  rowCount: table.rowCount,
1729
1802
  columns: table.columns,
1730
1803
  ...table.indexes ? { indexes: table.indexes } : {},
1731
1804
  ...table.uniqueKeys ? { uniqueKeys: table.uniqueKeys } : {},
1732
1805
  query: {
1733
- parameters: queryParameters(table, publicRead),
1734
- sortable: publicRead ? [] : selectableColumns(table),
1806
+ parameters: queryParameters(table),
1807
+ sortable: [],
1735
1808
  selectable: selectableColumns(table),
1736
1809
  searchable: searchableColumns(table),
1737
1810
  filters: filterNames(table)
@@ -1739,7 +1812,7 @@ function generateSubgraphAgentSchema(detail, options = {}) {
1739
1812
  examples: {
1740
1813
  list: rowExample(table),
1741
1814
  count: { count: table.rowCount },
1742
- curl: publicRead ? `curl '${serverUrl}${path}?_limit=10&_order=desc'` : `curl '${serverUrl}${path}?_limit=10&_sort=_block_height&_order=desc'`
1815
+ curl: `curl '${serverUrl}${path}?_limit=10&_order=desc'`
1743
1816
  }
1744
1817
  };
1745
1818
  }
@@ -1756,7 +1829,6 @@ function generateSubgraphAgentSchema(detail, options = {}) {
1756
1829
  }
1757
1830
  function generateSubgraphOpenApi(detail, options = {}) {
1758
1831
  const serverUrl = normalizeServerUrl(options.serverUrl);
1759
- const publicRead = isPublicRead(detail, options);
1760
1832
  const paths = {};
1761
1833
  const schemas = {};
1762
1834
  for (const [tableName, table] of Object.entries(detail.tables)) {
@@ -1774,7 +1846,7 @@ function generateSubgraphOpenApi(detail, options = {}) {
1774
1846
  required,
1775
1847
  example: rowExample(table)
1776
1848
  };
1777
- const responseSchema = publicRead ? {
1849
+ const responseSchema = {
1778
1850
  type: "object",
1779
1851
  properties: {
1780
1852
  rows: {
@@ -1791,28 +1863,12 @@ function generateSubgraphOpenApi(detail, options = {}) {
1791
1863
  }
1792
1864
  }
1793
1865
  }
1794
- } : {
1795
- type: "object",
1796
- properties: {
1797
- data: {
1798
- type: "array",
1799
- items: { $ref: `#/components/schemas/${schemaName}` }
1800
- },
1801
- meta: {
1802
- type: "object",
1803
- properties: {
1804
- total: { type: "integer" },
1805
- limit: { type: "integer" },
1806
- offset: { type: "integer" }
1807
- }
1808
- }
1809
- }
1810
1866
  };
1811
- paths[tablePath(detail.name, tableName, publicRead)] = {
1867
+ paths[tablePath(detail.name, tableName)] = {
1812
1868
  get: {
1813
1869
  summary: `Query ${detail.name}.${tableName}`,
1814
1870
  operationId: `query_${detail.name.replace(/-/g, "_")}_${tableName}`,
1815
- parameters: tableParameters(table, publicRead),
1871
+ parameters: tableParameters(table),
1816
1872
  responses: {
1817
1873
  "200": {
1818
1874
  description: "Rows returned from the subgraph table.",
@@ -1825,11 +1881,11 @@ function generateSubgraphOpenApi(detail, options = {}) {
1825
1881
  }
1826
1882
  }
1827
1883
  };
1828
- paths[countPath(detail.name, tableName, publicRead)] = {
1884
+ paths[countPath(detail.name, tableName)] = {
1829
1885
  get: {
1830
1886
  summary: `Count ${detail.name}.${tableName}`,
1831
1887
  operationId: `count_${detail.name.replace(/-/g, "_")}_${tableName}`,
1832
- parameters: tableParameters(table, publicRead),
1888
+ parameters: tableParameters(table),
1833
1889
  responses: {
1834
1890
  "200": {
1835
1891
  description: "Row count for the filtered table query.",
@@ -1868,14 +1924,13 @@ function generateSubgraphOpenApi(detail, options = {}) {
1868
1924
  }
1869
1925
  function generateSubgraphMarkdown(detail, options = {}) {
1870
1926
  const agent = generateSubgraphAgentSchema(detail, options);
1871
- const publicRead = isPublicRead(detail, options);
1872
1927
  const lines = [
1873
1928
  `# ${detail.name} Subgraph API`,
1874
1929
  "",
1875
1930
  `Version: ${detail.version}`,
1876
1931
  detail.schemaHash ? `Schema hash: ${detail.schemaHash}` : undefined,
1877
1932
  `Server: ${agent.serverUrl}`,
1878
- publicRead ? "Visibility: public — anon reads, no API key. Responses use the `{ rows, next_cursor, tip }` envelope; paginate with `?cursor=<next_cursor>` and `_order=asc|desc` (`_offset`/`_sort` are rejected)." : undefined,
1933
+ "Responses use the `{ rows, next_cursor, tip }` envelope; paginate with `?cursor=<next_cursor>` and `_order=asc|desc` (`_offset` is rejected).",
1879
1934
  "",
1880
1935
  detail.description
1881
1936
  ].filter((line) => line !== undefined && line !== "");
@@ -1903,15 +1958,14 @@ function generateSubgraphSpec(detail, format, options = {}) {
1903
1958
  return generateSubgraphAgentSchema(detail, options);
1904
1959
  return generateSubgraphMarkdown(detail, options);
1905
1960
  }
1906
-
1907
1961
  // src/crypto/hmac.ts
1908
1962
  var exports_hmac = {};
1909
1963
  __export(exports_hmac, {
1910
- verifySignatureHeader: () => verifySignatureHeader,
1911
- verifySignature: () => verifySignature,
1912
- signPayload: () => signPayload,
1964
+ createSignatureHeader: () => createSignatureHeader,
1913
1965
  generateSecret: () => generateSecret,
1914
- createSignatureHeader: () => createSignatureHeader
1966
+ signPayload: () => signPayload,
1967
+ verifySignature: () => verifySignature,
1968
+ verifySignatureHeader: () => verifySignatureHeader
1915
1969
  });
1916
1970
  import { createHmac, randomBytes } from "node:crypto";
1917
1971
  function generateSecret() {
@@ -1957,17 +2011,16 @@ function verifySignatureHeader(payload, header, secret, toleranceSeconds = 300)
1957
2011
  const signedPayload = `${ts}.${payload}`;
1958
2012
  return verifySignature(signedPayload, signature, secret);
1959
2013
  }
1960
-
1961
2014
  // src/crypto/ed25519.ts
1962
2015
  var exports_ed25519 = {};
1963
2016
  __export(exports_ed25519, {
1964
- verifyEd25519: () => verifyEd25519,
1965
- signEd25519: () => signEd25519,
1966
- publicKeyPemFromPrivate: () => publicKeyPemFromPrivate,
1967
- loadEd25519PublicKey: () => loadEd25519PublicKey,
1968
- loadEd25519PrivateKey: () => loadEd25519PrivateKey,
2017
+ ed25519KeyId: () => ed25519KeyId,
1969
2018
  generateEd25519KeyPair: () => generateEd25519KeyPair,
1970
- ed25519KeyId: () => ed25519KeyId
2019
+ loadEd25519PrivateKey: () => loadEd25519PrivateKey,
2020
+ loadEd25519PublicKey: () => loadEd25519PublicKey,
2021
+ publicKeyPemFromPrivate: () => publicKeyPemFromPrivate,
2022
+ signEd25519: () => signEd25519,
2023
+ verifyEd25519: () => verifyEd25519
1971
2024
  });
1972
2025
  import {
1973
2026
  createHash,
@@ -2010,197 +2063,90 @@ function verifyEd25519(payload, signatureBase64, publicKey) {
2010
2063
  return false;
2011
2064
  }
2012
2065
  }
2013
- // src/event-types.ts
2014
- import {
2015
- DECODED_EVENT_TYPES
2016
- } from "@secondlayer/stacks/filters";
2017
- import {
2018
- DECODED_EVENT_TYPES as DECODED_EVENT_TYPES2,
2019
- VM_EVENT_TYPES,
2020
- VM_NODE_TO_STORED_TYPE
2021
- } from "@secondlayer/stacks/filters";
2022
- var VM_STORED_TO_NODE_TYPE = {
2023
- nested_contract_call: "contract_call_event",
2024
- var_set: "var_set_event",
2025
- map_set: "map_set_event",
2026
- map_insert: "map_insert_event",
2027
- map_delete: "map_delete_event"
2028
- };
2029
- var STREAMS_EVENT_TYPES = DECODED_EVENT_TYPES;
2030
- // src/db-event-types.ts
2031
- var STREAMS_DB_EVENT_TYPES = [
2032
- "stx_transfer_event",
2033
- "stx_mint_event",
2034
- "stx_burn_event",
2035
- "stx_lock_event",
2036
- "ft_transfer_event",
2037
- "ft_mint_event",
2038
- "ft_burn_event",
2039
- "nft_transfer_event",
2040
- "nft_mint_event",
2041
- "nft_burn_event",
2042
- "smart_contract_event",
2043
- "contract_event"
2044
- ];
2045
- var DB_TO_STREAMS_EVENT_TYPE = {
2046
- stx_transfer_event: "stx_transfer",
2047
- stx_mint_event: "stx_mint",
2048
- stx_burn_event: "stx_burn",
2049
- stx_lock_event: "stx_lock",
2050
- ft_transfer_event: "ft_transfer",
2051
- ft_mint_event: "ft_mint",
2052
- ft_burn_event: "ft_burn",
2053
- nft_transfer_event: "nft_transfer",
2054
- nft_mint_event: "nft_mint",
2055
- nft_burn_event: "nft_burn",
2056
- smart_contract_event: "print",
2057
- contract_event: "print"
2058
- };
2059
- var STREAMS_TO_DB_EVENT_TYPES = {
2060
- stx_transfer: ["stx_transfer_event"],
2061
- stx_mint: ["stx_mint_event"],
2062
- stx_burn: ["stx_burn_event"],
2063
- stx_lock: ["stx_lock_event"],
2064
- ft_transfer: ["ft_transfer_event"],
2065
- ft_mint: ["ft_mint_event"],
2066
- ft_burn: ["ft_burn_event"],
2067
- nft_transfer: ["nft_transfer_event"],
2068
- nft_mint: ["nft_mint_event"],
2069
- nft_burn: ["nft_burn_event"],
2070
- print: ["smart_contract_event", "contract_event"]
2071
- };
2072
- // src/finality.ts
2073
- var DEFAULT_BTC_CONFIRMATIONS = 6;
2074
- function finalizedBurnHeight(burnTipHeight, confirmations = DEFAULT_BTC_CONFIRMATIONS) {
2075
- if (!Number.isInteger(burnTipHeight) || burnTipHeight < 0) {
2076
- throw new Error("burnTipHeight must be a non-negative integer");
2077
- }
2078
- if (!Number.isInteger(confirmations) || confirmations < 0) {
2079
- throw new Error("confirmations must be a non-negative integer");
2080
- }
2081
- return Math.max(0, burnTipHeight - confirmations);
2082
- }
2083
- // src/streams-cursor.ts
2084
- var EMPTY_RANGE_EVENT_INDEX_SENTINEL = 2147483647;
2085
- function encodeStreamsCursor(cursor) {
2086
- return `${cursor.block_height}:${cursor.event_index}`;
2087
- }
2088
- function decodeStreamsCursor(cursor) {
2089
- const match = /^(0|[1-9]\d*):(0|[1-9]\d*)$/.exec(cursor);
2090
- if (!match) {
2091
- throw new Error("Invalid Streams cursor");
2092
- }
2093
- const decoded = {
2094
- block_height: Number(match[1]),
2095
- event_index: Number(match[2])
2096
- };
2097
- if (!Number.isSafeInteger(decoded.block_height) || !Number.isSafeInteger(decoded.event_index)) {
2098
- throw new Error("Invalid Streams cursor");
2099
- }
2100
- return decoded;
2101
- }
2102
- function compareStreamsCursor(a, b) {
2103
- if (a.block_height !== b.block_height) {
2104
- return a.block_height < b.block_height ? -1 : 1;
2105
- }
2106
- if (a.event_index !== b.event_index) {
2107
- return a.event_index < b.event_index ? -1 : 1;
2108
- }
2109
- return 0;
2110
- }
2111
- function isEmptyRangeCursor(cursor) {
2112
- return cursor.event_index === EMPTY_RANGE_EVENT_INDEX_SENTINEL;
2113
- }
2114
- function blockEndCursor(height) {
2115
- return {
2116
- block_height: height,
2117
- event_index: EMPTY_RANGE_EVENT_INDEX_SENTINEL
2118
- };
2119
- }
2120
2066
  export {
2121
- validateWebhookFilterForTable,
2122
- sql2 as sql,
2123
- setMigrationRole,
2124
- parseJsonb,
2125
- onControlPlane,
2126
- onChainPlane,
2127
- logger,
2128
- jsonb,
2129
- isSbtcDecoderEnabled,
2130
- isPox5DecoderEnabled,
2131
- isPox4DecoderEnabled,
2132
- isEmptyRangeCursor,
2133
- isBnsDecoderEnabled,
2134
- getTargetDb,
2135
- getSourceDb,
2136
- getRawClientFor,
2137
- getRawClient,
2138
- getMigrationRole,
2139
- getErrorMessage,
2140
- getEnv,
2141
- getDbSplitStatus,
2142
- getDb,
2143
- generateSubgraphSpec,
2144
- generateSubgraphOpenApi,
2145
- generateSubgraphMarkdown,
2146
- generateSubgraphAgentSchema,
2147
- formatWebhookSchemaErrors,
2148
- finalizedBurnHeight,
2149
- encodeStreamsCursor,
2150
- exports_ed25519 as ed25519,
2151
- decodeStreamsCursor,
2152
- exports_hmac as crypto,
2153
- compareStreamsCursor,
2154
- closeDb,
2155
- blockEndCursor,
2156
- assertDbSplit,
2157
- applicationDatabaseUrl,
2158
- WebhookStatusSchema,
2159
- WebhookRuntimeSchema,
2160
- WebhookFormatSchema,
2161
- WebhookFilterSchema,
2162
- WebhookFilterPrimitiveSchema,
2163
- WebhookFilterOperatorSchema,
2164
- WebhookFilterClauseSchema,
2165
- WEBHOOK_STATUSES,
2166
- WEBHOOK_RUNTIMES,
2167
- WEBHOOK_FORMATS,
2168
- WEBHOOK_FILTER_OPERATORS,
2169
- VersionConflictError,
2170
- ValidationError,
2171
- VM_STORED_TO_NODE_TYPE,
2172
- VM_NODE_TO_STORED_TYPE,
2173
- VM_EVENT_TYPES,
2174
- UpdateWebhookRequestSchema,
2175
- TenantSuspendedError,
2176
- TABLE_TO_DB,
2177
- SecondLayerError,
2178
- STREAMS_TO_DB_EVENT_TYPES,
2179
- STREAMS_EVENT_TYPES,
2180
- STREAMS_DB_EVENT_TYPES,
2181
- SOURCE_READ_TYPES,
2182
- SOURCE_READ_PKS,
2183
- SOURCE_READ_COLUMNS,
2184
- ReplayWebhookRequestSchema,
2185
- RateLimitError,
2186
- PaymentRequiredError,
2187
- NotFoundError,
2188
- KeyRotatedError,
2189
- ForbiddenError,
2190
- ErrorCodes,
2191
- EMPTY_RANGE_EVENT_INDEX_SENTINEL,
2192
- DeploySubgraphRequestSchema,
2193
- DatabaseError,
2194
- DEFAULT_BTC_CONFIRMATIONS,
2195
- DECODED_EVENT_TYPES2 as DECODED_EVENT_TYPES,
2196
- DB_TO_STREAMS_EVENT_TYPE,
2197
- CreateWebhookRequestSchema,
2198
- CODE_TO_STATUS,
2199
- CHAIN_TRIGGER_TYPES,
2200
- CHAIN_TRIGGER_FIELDS,
2067
+ AuthenticationError,
2201
2068
  AuthorizationError,
2202
- AuthenticationError
2069
+ CHAIN_TRIGGER_FIELDS,
2070
+ CHAIN_TRIGGER_TYPES,
2071
+ CODE_TO_STATUS,
2072
+ CreateWebhookRequestSchema,
2073
+ DB_TO_STREAMS_EVENT_TYPE,
2074
+ DECODED_EVENT_TYPES2 as DECODED_EVENT_TYPES,
2075
+ DEFAULT_BTC_CONFIRMATIONS,
2076
+ DatabaseError,
2077
+ DeploySubgraphRequestSchema,
2078
+ EMPTY_RANGE_EVENT_INDEX_SENTINEL,
2079
+ ErrorCodes,
2080
+ ForbiddenError,
2081
+ KeyRotatedError,
2082
+ NotFoundError,
2083
+ PaymentRequiredError,
2084
+ RateLimitError,
2085
+ ReplayWebhookRequestSchema,
2086
+ SOURCE_READ_COLUMNS,
2087
+ SOURCE_READ_PKS,
2088
+ SOURCE_READ_TYPES,
2089
+ STREAMS_DB_EVENT_TYPES,
2090
+ STREAMS_EVENT_TYPES,
2091
+ STREAMS_TO_DB_EVENT_TYPES,
2092
+ SecondLayerError,
2093
+ TABLE_TO_DB,
2094
+ TenantSuspendedError,
2095
+ UpdateWebhookRequestSchema,
2096
+ VM_EVENT_TYPES,
2097
+ VM_NODE_TO_STORED_TYPE,
2098
+ VM_STORED_TO_NODE_TYPE,
2099
+ ValidationError,
2100
+ VersionConflictError,
2101
+ WEBHOOK_FILTER_OPERATORS,
2102
+ WEBHOOK_FORMATS,
2103
+ WEBHOOK_RUNTIMES,
2104
+ WEBHOOK_STATUSES,
2105
+ WebhookFilterClauseSchema,
2106
+ WebhookFilterOperatorSchema,
2107
+ WebhookFilterPrimitiveSchema,
2108
+ WebhookFilterSchema,
2109
+ WebhookFormatSchema,
2110
+ WebhookRuntimeSchema,
2111
+ WebhookStatusSchema,
2112
+ applicationDatabaseUrl,
2113
+ assertDbSplit,
2114
+ blockEndCursor,
2115
+ closeDb,
2116
+ compareStreamsCursor,
2117
+ exports_hmac as crypto,
2118
+ decodeStreamsCursor,
2119
+ exports_ed25519 as ed25519,
2120
+ encodeStreamsCursor,
2121
+ finalizedBurnHeight,
2122
+ formatWebhookSchemaErrors,
2123
+ generateSubgraphAgentSchema,
2124
+ generateSubgraphMarkdown,
2125
+ generateSubgraphOpenApi,
2126
+ generateSubgraphSpec,
2127
+ getDb,
2128
+ getDbSplitStatus,
2129
+ getEnv,
2130
+ getErrorMessage,
2131
+ getMigrationRole,
2132
+ getRawClient,
2133
+ getRawClientFor,
2134
+ getSourceDb,
2135
+ getTargetDb,
2136
+ isBnsDecoderEnabled,
2137
+ isEmptyRangeCursor,
2138
+ isPox4DecoderEnabled,
2139
+ isPox5DecoderEnabled,
2140
+ isSbtcDecoderEnabled,
2141
+ jsonb,
2142
+ logger,
2143
+ onChainPlane,
2144
+ onControlPlane,
2145
+ parseJsonb,
2146
+ setMigrationRole,
2147
+ sql2 as sql,
2148
+ validateWebhookFilterForTable
2203
2149
  };
2204
2150
 
2205
- //# debugId=A60A47C6792357BF64756E2164756E21
2151
+ //# debugId=920042D17F4879CF64756E2164756E21
2206
2152
  //# sourceMappingURL=index.js.map