@secondlayer/subgraphs 3.19.10 → 3.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.
@@ -88,18 +88,45 @@ interface ContractDeployFilter {
88
88
  deployer?: string;
89
89
  contractName?: string;
90
90
  }
91
+ /**
92
+ * One declared field of a print payload.
93
+ *
94
+ * A bare {@link ColumnType} is a required scalar (`amount: "uint"`). The
95
+ * composite forms exist because real print payloads are not flat: BNS-V2
96
+ * emits `name` as a NESTED tuple, and a `prints` vocabulary that could only
97
+ * say `"jsonb"` is why a handler reading flat `data.name` type-checked,
98
+ * deployed, and then decoded to null on every event.
99
+ *
100
+ * - `{ type: F, optional: true }` — the KEY becomes optional on `event.data`
101
+ * (mirrors `always_present: false` in the inferred schema).
102
+ * - `{ tuple: { … } }` — a nested tuple, typed all the way down.
103
+ * - `{ list: F }` — a list of `F`.
104
+ */
105
+ type PrintField = ColumnType | {
106
+ type: PrintField
107
+ optional: true
108
+ } | {
109
+ tuple: Record<string, PrintField>
110
+ } | {
111
+ list: PrintField
112
+ };
91
113
  interface PrintEventFilter extends TraitScope {
92
114
  type: "print_event";
93
115
  contractId?: string;
94
116
  topic?: string;
95
117
  /**
96
- * Optional per-topic field schema. When declared, the handler's `event` is
97
- * a discriminated union keyed by `topic` and `event.data` is typed per topic
118
+ * Per-topic field schema. When declared, the handler's `event` is a
119
+ * discriminated union keyed by `topic` and `event.data` is typed per topic
98
120
  * (e.g. `{ "completed-deposit": { amount: "uint", sender: "principal" } }`).
99
- * Uses the same `ColumnType` vocab as `schema`; nested fields use `"jsonb"`.
100
- * Type-level only — not validated at runtime.
121
+ * Nested tuples, lists, and optional fields are expressible — see
122
+ * {@link PrintField}.
123
+ *
124
+ * Declaring `prints` also opts the source into RUNTIME validation: an
125
+ * event whose decoded payload does not match is skipped and logged rather
126
+ * than written as nulls (and the deploy-time field lint is promoted from
127
+ * a warning to an error).
101
128
  */
102
- prints?: Record<string, Record<string, ColumnType>>;
129
+ prints?: Record<string, Record<string, PrintField>>;
103
130
  }
104
131
  /** All subgraph filter types — discriminated on `type` */
105
132
  type SubgraphFilter = StxTransferFilter | StxMintFilter | StxBurnFilter | StxLockFilter | FtTransferFilter | FtMintFilter | FtBurnFilter | NftTransferFilter | NftMintFilter | NftBurnFilter | ContractCallFilter | ContractDeployFilter | PrintEventFilter;
@@ -165,18 +165,45 @@ interface ContractDeployFilter {
165
165
  deployer?: string;
166
166
  contractName?: string;
167
167
  }
168
+ /**
169
+ * One declared field of a print payload.
170
+ *
171
+ * A bare {@link ColumnType} is a required scalar (`amount: "uint"`). The
172
+ * composite forms exist because real print payloads are not flat: BNS-V2
173
+ * emits `name` as a NESTED tuple, and a `prints` vocabulary that could only
174
+ * say `"jsonb"` is why a handler reading flat `data.name` type-checked,
175
+ * deployed, and then decoded to null on every event.
176
+ *
177
+ * - `{ type: F, optional: true }` — the KEY becomes optional on `event.data`
178
+ * (mirrors `always_present: false` in the inferred schema).
179
+ * - `{ tuple: { … } }` — a nested tuple, typed all the way down.
180
+ * - `{ list: F }` — a list of `F`.
181
+ */
182
+ type PrintField = ColumnType | {
183
+ type: PrintField
184
+ optional: true
185
+ } | {
186
+ tuple: Record<string, PrintField>
187
+ } | {
188
+ list: PrintField
189
+ };
168
190
  interface PrintEventFilter extends TraitScope {
169
191
  type: "print_event";
170
192
  contractId?: string;
171
193
  topic?: string;
172
194
  /**
173
- * Optional per-topic field schema. When declared, the handler's `event` is
174
- * a discriminated union keyed by `topic` and `event.data` is typed per topic
195
+ * Per-topic field schema. When declared, the handler's `event` is a
196
+ * discriminated union keyed by `topic` and `event.data` is typed per topic
175
197
  * (e.g. `{ "completed-deposit": { amount: "uint", sender: "principal" } }`).
176
- * Uses the same `ColumnType` vocab as `schema`; nested fields use `"jsonb"`.
177
- * Type-level only — not validated at runtime.
198
+ * Nested tuples, lists, and optional fields are expressible — see
199
+ * {@link PrintField}.
200
+ *
201
+ * Declaring `prints` also opts the source into RUNTIME validation: an
202
+ * event whose decoded payload does not match is skipped and logged rather
203
+ * than written as nulls (and the deploy-time field lint is promoted from
204
+ * a warning to an error).
178
205
  */
179
- prints?: Record<string, Record<string, ColumnType>>;
206
+ prints?: Record<string, Record<string, PrintField>>;
180
207
  }
181
208
  /** All subgraph filter types — discriminated on `type` */
182
209
  type SubgraphFilter = StxTransferFilter | StxMintFilter | StxBurnFilter | StxLockFilter | FtTransferFilter | FtMintFilter | FtBurnFilter | NftTransferFilter | NftMintFilter | NftBurnFilter | ContractCallFilter | ContractDeployFilter | PrintEventFilter;
@@ -254,4 +281,4 @@ interface SubgraphDefinition {
254
281
  /** Handler functions — keys must match source names (or "*" for catch-all) */
255
282
  handlers: Record<string, SubgraphHandler>;
256
283
  }
257
- export { TxMeta, SubgraphTable, SubgraphSchema, SubgraphRelation, SubgraphHandler, SubgraphFilter, SubgraphDefinition, SubgraphContext, SubgraphColumn, StxTransferFilter, StxMintFilter, StxLockFilter, StxBurnFilter, RowValue, PrintEventFilter, NftTransferFilter, NftMintFilter, NftBurnFilter, FtTransferFilter, FtMintFilter, FtBurnFilter, ContractDeployFilter, ContractCallFilter, ContractCallEvent, ComputedValue, ColumnType };
284
+ export { TxMeta, SubgraphTable, SubgraphSchema, SubgraphRelation, SubgraphHandler, SubgraphFilter, SubgraphDefinition, SubgraphContext, SubgraphColumn, StxTransferFilter, StxMintFilter, StxLockFilter, StxBurnFilter, RowValue, PrintField, PrintEventFilter, NftTransferFilter, NftMintFilter, NftBurnFilter, FtTransferFilter, FtMintFilter, FtBurnFilter, ContractDeployFilter, ContractCallFilter, ContractCallEvent, ComputedValue, ColumnType };
@@ -124,18 +124,45 @@ interface ContractDeployFilter {
124
124
  deployer?: string;
125
125
  contractName?: string;
126
126
  }
127
+ /**
128
+ * One declared field of a print payload.
129
+ *
130
+ * A bare {@link ColumnType} is a required scalar (`amount: "uint"`). The
131
+ * composite forms exist because real print payloads are not flat: BNS-V2
132
+ * emits `name` as a NESTED tuple, and a `prints` vocabulary that could only
133
+ * say `"jsonb"` is why a handler reading flat `data.name` type-checked,
134
+ * deployed, and then decoded to null on every event.
135
+ *
136
+ * - `{ type: F, optional: true }` — the KEY becomes optional on `event.data`
137
+ * (mirrors `always_present: false` in the inferred schema).
138
+ * - `{ tuple: { … } }` — a nested tuple, typed all the way down.
139
+ * - `{ list: F }` — a list of `F`.
140
+ */
141
+ type PrintField = ColumnType | {
142
+ type: PrintField
143
+ optional: true
144
+ } | {
145
+ tuple: Record<string, PrintField>
146
+ } | {
147
+ list: PrintField
148
+ };
127
149
  interface PrintEventFilter extends TraitScope {
128
150
  type: "print_event";
129
151
  contractId?: string;
130
152
  topic?: string;
131
153
  /**
132
- * Optional per-topic field schema. When declared, the handler's `event` is
133
- * a discriminated union keyed by `topic` and `event.data` is typed per topic
154
+ * Per-topic field schema. When declared, the handler's `event` is a
155
+ * discriminated union keyed by `topic` and `event.data` is typed per topic
134
156
  * (e.g. `{ "completed-deposit": { amount: "uint", sender: "principal" } }`).
135
- * Uses the same `ColumnType` vocab as `schema`; nested fields use `"jsonb"`.
136
- * Type-level only — not validated at runtime.
157
+ * Nested tuples, lists, and optional fields are expressible — see
158
+ * {@link PrintField}.
159
+ *
160
+ * Declaring `prints` also opts the source into RUNTIME validation: an
161
+ * event whose decoded payload does not match is skipped and logged rather
162
+ * than written as nulls (and the deploy-time field lint is promoted from
163
+ * a warning to an error).
137
164
  */
138
- prints?: Record<string, Record<string, ColumnType>>;
165
+ prints?: Record<string, Record<string, PrintField>>;
139
166
  }
140
167
  /** All subgraph filter types — discriminated on `type` */
141
168
  type SubgraphFilter = StxTransferFilter | StxMintFilter | StxBurnFilter | StxLockFilter | FtTransferFilter | FtMintFilter | FtBurnFilter | NftTransferFilter | NftMintFilter | NftBurnFilter | ContractCallFilter | ContractDeployFilter | PrintEventFilter;
@@ -223,6 +250,24 @@ declare const SubgraphNameSchema: z.ZodType<string>;
223
250
  */
224
251
  declare const SqlIdentifierSchema: z.ZodType<string>;
225
252
  declare const ColumnTypeSchema: z.ZodType<ColumnType>;
253
+ /**
254
+ * One declared print field: a bare column type, or a composite (optional,
255
+ * nested tuple, list). Recursive — real print payloads nest, and a vocabulary
256
+ * that could only say `"jsonb"` is what let a flat-field declaration pass
257
+ * while every event decoded to null.
258
+ */
259
+ declare const PrintFieldSchema: z.ZodType<unknown>;
260
+ /**
261
+ * The canonical `AbiContract` shape, validated at deploy time.
262
+ *
263
+ * This used to be `z.record(z.string(), z.any())`, which accepted a raw
264
+ * Hiro/Clarinet ABI (`read_only` access, `buffer` types, outputs wrapped as
265
+ * `{ type: … }`) and let it through — the deploy succeeded and `event.input`
266
+ * then mis-decoded at RUNTIME, per event, forever. Reject it here instead,
267
+ * and name the fix: run it through `normalizeAbi` from
268
+ * `@secondlayer/stacks/clarity`.
269
+ */
270
+ declare const AbiContractSchema: z.ZodType<unknown>;
226
271
  declare const SubgraphColumnSchema: z.ZodType<SubgraphColumn>;
227
272
  declare const SubgraphTableSchema: z.ZodType<SubgraphTable>;
228
273
  declare const SubgraphSchemaSchema: z.ZodType<Record<string, SubgraphTable>>;
@@ -233,4 +278,4 @@ declare const SubgraphDefinitionSchema: z.ZodType<SubgraphDefinition>;
233
278
  * Validates a subgraph definition, returning the parsed result or throwing on failure.
234
279
  */
235
280
  declare function validateSubgraphDefinition(def: unknown): SubgraphDefinition;
236
- export { validateSubgraphDefinition, VALID_FILTER_TYPES, SubgraphTableSchema, SubgraphSchemaSchema, SubgraphNameSchema, SubgraphFilterSchema, SubgraphDefinitionSchema, SubgraphColumnSchema, SqlIdentifierSchema, ColumnTypeSchema };
281
+ export { validateSubgraphDefinition, VALID_FILTER_TYPES, SubgraphTableSchema, SubgraphSchemaSchema, SubgraphNameSchema, SubgraphFilterSchema, SubgraphDefinitionSchema, SubgraphColumnSchema, SqlIdentifierSchema, PrintFieldSchema, ColumnTypeSchema, AbiContractSchema };
@@ -14,6 +14,44 @@ var ColumnTypeSchema = z.enum([
14
14
  "timestamp",
15
15
  "jsonb"
16
16
  ]);
17
+ var PrintFieldSchema = z.lazy(() => z.union([
18
+ ColumnTypeSchema,
19
+ z.object({ type: PrintFieldSchema, optional: z.literal(true) }),
20
+ z.object({ tuple: z.record(z.string(), PrintFieldSchema) }),
21
+ z.object({ list: PrintFieldSchema })
22
+ ]));
23
+ var AbiTypeSchema = z.lazy(() => z.union([
24
+ z.string(),
25
+ z.object({ buff: z.object({ length: z.number() }) }),
26
+ z.object({ "string-ascii": z.object({ length: z.number() }) }),
27
+ z.object({ "string-utf8": z.object({ length: z.number() }) }),
28
+ z.object({ optional: AbiTypeSchema }),
29
+ z.object({
30
+ list: z.object({ type: AbiTypeSchema, length: z.number() })
31
+ }),
32
+ z.object({
33
+ tuple: z.array(z.object({ name: z.string(), type: AbiTypeSchema }))
34
+ }),
35
+ z.object({
36
+ response: z.object({ ok: AbiTypeSchema, error: AbiTypeSchema })
37
+ })
38
+ ]));
39
+ var AbiContractSchema = z.object({
40
+ functions: z.array(z.object({
41
+ name: z.string(),
42
+ access: z.enum(["public", "read-only", "private"], {
43
+ message: "ABI access must be public | read-only | private — a raw Hiro/Clarinet ABI uses `read_only`. Normalize it first: normalizeAbi() from @secondlayer/stacks/clarity."
44
+ }),
45
+ args: z.array(z.object({ name: z.string(), type: AbiTypeSchema })),
46
+ outputs: AbiTypeSchema
47
+ })),
48
+ maps: z.array(z.unknown()).optional(),
49
+ variables: z.array(z.unknown()).optional(),
50
+ fungible_tokens: z.array(z.unknown()).optional(),
51
+ non_fungible_tokens: z.array(z.unknown()).optional(),
52
+ implemented_traits: z.array(z.unknown()).optional(),
53
+ defined_traits: z.array(z.unknown()).optional()
54
+ });
17
55
  var SubgraphColumnSchema = z.object({
18
56
  type: ColumnTypeSchema,
19
57
  nullable: z.boolean().optional(),
@@ -62,9 +100,9 @@ var SubgraphFilterSchema = z.object({
62
100
  contractName: z.string().optional(),
63
101
  topic: z.string().optional(),
64
102
  lockedAddress: z.string().optional(),
65
- abi: z.record(z.string(), z.any()).optional(),
103
+ abi: AbiContractSchema.optional(),
66
104
  trait: z.string().optional(),
67
- prints: z.record(z.string(), z.record(z.string(), ColumnTypeSchema)).optional()
105
+ prints: z.record(z.string(), z.record(z.string(), PrintFieldSchema)).optional()
68
106
  }).strict();
69
107
  var SubgraphDefinitionSchema = z.object({
70
108
  name: SubgraphNameSchema,
@@ -89,8 +127,10 @@ export {
89
127
  SubgraphDefinitionSchema,
90
128
  SubgraphColumnSchema,
91
129
  SqlIdentifierSchema,
92
- ColumnTypeSchema
130
+ PrintFieldSchema,
131
+ ColumnTypeSchema,
132
+ AbiContractSchema
93
133
  };
94
134
 
95
- //# debugId=1EFFD69B94CEDB8D64756E2164756E21
135
+ //# debugId=E99182101593A8B264756E2164756E21
96
136
  //# sourceMappingURL=validate.js.map
@@ -2,9 +2,9 @@
2
2
  "version": 3,
3
3
  "sources": ["../src/validate.ts"],
4
4
  "sourcesContent": [
5
- "import { z } from \"zod\";\nimport type {\n\tColumnType,\n\tSubgraphColumn,\n\tSubgraphDefinition,\n\tSubgraphFilter,\n\tSubgraphTable,\n} from \"./types.ts\";\n\nexport const SubgraphNameSchema: z.ZodType<string> = z\n\t.string()\n\t.min(1)\n\t.max(63)\n\t.regex(\n\t\t/^[a-z][a-z0-9-]*$/,\n\t\t\"Must start with lowercase letter, contain only lowercase alphanumeric and hyphens\",\n\t);\n\n/**\n * A safe SQL identifier (table or column name). Mirrors the runtime guard in\n * runtime/context.ts (validateColumnName) so the schema validator can never\n * accept a name the runtime would reject — and closes the deploy-time DDL\n * injection path in schema/generator.ts, which interpolates these names raw.\n */\nexport const SqlIdentifierSchema: z.ZodType<string> = z\n\t.string()\n\t.min(1)\n\t.max(63) // Postgres truncates identifiers > 63 bytes; reject rather than collide.\n\t.regex(\n\t\t/^[a-z_][a-z0-9_]*$/i,\n\t\t\"Must be a valid SQL identifier: start with a letter or underscore, then letters/digits/underscores only\",\n\t);\n\nexport const ColumnTypeSchema: z.ZodType<ColumnType> = z.enum([\n\t\"text\",\n\t\"uint\",\n\t\"int\",\n\t\"principal\",\n\t\"boolean\",\n\t\"timestamp\",\n\t\"jsonb\",\n]);\n\nexport const SubgraphColumnSchema: z.ZodType<SubgraphColumn> = z.object({\n\ttype: ColumnTypeSchema,\n\tnullable: z.boolean().optional(),\n\tindexed: z.boolean().optional(),\n\tsearch: z.boolean().optional(),\n\tdefault: z.union([z.string(), z.number(), z.boolean()]).optional(),\n}) as z.ZodType<SubgraphColumn>;\n\nexport const SubgraphTableSchema: z.ZodType<SubgraphTable> = z.object({\n\tcolumns: z\n\t\t.record(SqlIdentifierSchema, SubgraphColumnSchema)\n\t\t.refine(\n\t\t\t(c) => Object.keys(c).length > 0,\n\t\t\t\"Table must have at least one column\",\n\t\t),\n\tindexes: z.array(z.array(SqlIdentifierSchema)).optional(),\n\tuniqueKeys: z.array(z.array(SqlIdentifierSchema)).optional(),\n\trelations: z\n\t\t.array(\n\t\t\tz.object({\n\t\t\t\tname: SqlIdentifierSchema,\n\t\t\t\treferences: SqlIdentifierSchema,\n\t\t\t\tfields: z.array(SqlIdentifierSchema).min(1),\n\t\t\t\treferencedColumns: z.array(SqlIdentifierSchema).min(1),\n\t\t\t}),\n\t\t)\n\t\t.optional(),\n}) as z.ZodType<SubgraphTable>;\n\nexport const SubgraphSchemaSchema: z.ZodType<Record<string, SubgraphTable>> = z\n\t.record(SqlIdentifierSchema, SubgraphTableSchema)\n\t.refine(\n\t\t(s) => Object.keys(s).length > 0,\n\t\t\"Schema must have at least one table\",\n\t) as z.ZodType<Record<string, SubgraphTable>>;\n\nexport const VALID_FILTER_TYPES = [\n\t\"stx_transfer\",\n\t\"stx_mint\",\n\t\"stx_burn\",\n\t\"stx_lock\",\n\t\"ft_transfer\",\n\t\"ft_mint\",\n\t\"ft_burn\",\n\t\"nft_transfer\",\n\t\"nft_mint\",\n\t\"nft_burn\",\n\t\"contract_call\",\n\t\"contract_deploy\",\n\t\"print_event\",\n] as const;\n\nexport const SubgraphFilterSchema: z.ZodType<SubgraphFilter> = z\n\t.object({\n\t\ttype: z.enum(VALID_FILTER_TYPES),\n\t\t// All optional fields across all filter types\n\t\tsender: z.string().optional(),\n\t\trecipient: z.string().optional(),\n\t\tminAmount: z.bigint().optional(),\n\t\tmaxAmount: z.bigint().optional(),\n\t\tassetIdentifier: z.string().optional(),\n\t\tcontractId: z.string().optional(),\n\t\tfunctionName: z.string().optional(),\n\t\tcaller: z.string().optional(),\n\t\tdeployer: z.string().optional(),\n\t\tcontractName: z.string().optional(),\n\t\ttopic: z.string().optional(),\n\t\tlockedAddress: z.string().optional(),\n\t\tabi: z.record(z.string(), z.any()).optional(),\n\t\ttrait: z.string().optional(),\n\t\t// print_event per-topic field schema (type-level hints; not enforced at runtime)\n\t\tprints: z\n\t\t\t.record(z.string(), z.record(z.string(), ColumnTypeSchema))\n\t\t\t.optional(),\n\t})\n\t.strict() as unknown as z.ZodType<SubgraphFilter>;\n\nexport const SubgraphDefinitionSchema: z.ZodType<SubgraphDefinition> = z.object(\n\t{\n\t\tname: SubgraphNameSchema,\n\t\tversion: z.string().optional(),\n\t\tdescription: z.string().optional(),\n\t\tstartBlock: z.number().int().nonnegative().optional(),\n\t\t// 'concurrent' = tip-first deploy: go live at tip immediately, fill\n\t\t// history via a background backfill. Only safe for order-tolerant\n\t\t// handlers (commutative or insert-only writes).\n\t\tbackfillMode: z.enum([\"blocking\", \"concurrent\"]).optional(),\n\t\tsources: z\n\t\t\t.record(z.string(), SubgraphFilterSchema)\n\t\t\t.refine(\n\t\t\t\t(s) => Object.keys(s).length > 0,\n\t\t\t\t\"Must have at least one source\",\n\t\t\t),\n\t\tschema: SubgraphSchemaSchema,\n\t\thandlers: z.record(z.string(), z.any()),\n\t},\n) as unknown as z.ZodType<SubgraphDefinition>;\n\n/**\n * Validates a subgraph definition, returning the parsed result or throwing on failure.\n */\nexport function validateSubgraphDefinition(def: unknown): SubgraphDefinition {\n\treturn SubgraphDefinitionSchema.parse(def);\n}\n"
5
+ "import { z } from \"zod\";\nimport type {\n\tColumnType,\n\tSubgraphColumn,\n\tSubgraphDefinition,\n\tSubgraphFilter,\n\tSubgraphTable,\n} from \"./types.ts\";\n\nexport const SubgraphNameSchema: z.ZodType<string> = z\n\t.string()\n\t.min(1)\n\t.max(63)\n\t.regex(\n\t\t/^[a-z][a-z0-9-]*$/,\n\t\t\"Must start with lowercase letter, contain only lowercase alphanumeric and hyphens\",\n\t);\n\n/**\n * A safe SQL identifier (table or column name). Mirrors the runtime guard in\n * runtime/context.ts (validateColumnName) so the schema validator can never\n * accept a name the runtime would reject — and closes the deploy-time DDL\n * injection path in schema/generator.ts, which interpolates these names raw.\n */\nexport const SqlIdentifierSchema: z.ZodType<string> = z\n\t.string()\n\t.min(1)\n\t.max(63) // Postgres truncates identifiers > 63 bytes; reject rather than collide.\n\t.regex(\n\t\t/^[a-z_][a-z0-9_]*$/i,\n\t\t\"Must be a valid SQL identifier: start with a letter or underscore, then letters/digits/underscores only\",\n\t);\n\nexport const ColumnTypeSchema: z.ZodType<ColumnType> = z.enum([\n\t\"text\",\n\t\"uint\",\n\t\"int\",\n\t\"principal\",\n\t\"boolean\",\n\t\"timestamp\",\n\t\"jsonb\",\n]);\n\n/**\n * One declared print field: a bare column type, or a composite (optional,\n * nested tuple, list). Recursive — real print payloads nest, and a vocabulary\n * that could only say `\"jsonb\"` is what let a flat-field declaration pass\n * while every event decoded to null.\n */\nexport const PrintFieldSchema: z.ZodType<unknown> = z.lazy(() =>\n\tz.union([\n\t\tColumnTypeSchema,\n\t\tz.object({ type: PrintFieldSchema, optional: z.literal(true) }),\n\t\tz.object({ tuple: z.record(z.string(), PrintFieldSchema) }),\n\t\tz.object({ list: PrintFieldSchema }),\n\t]),\n);\n\n/**\n * A Clarity ABI type: a primitive name, or one of the composite shapes.\n * Recursive, so nested tuples/lists/optionals are checked all the way down.\n */\nconst AbiTypeSchema: z.ZodType<unknown> = z.lazy(() =>\n\tz.union([\n\t\tz.string(),\n\t\tz.object({ buff: z.object({ length: z.number() }) }),\n\t\tz.object({ \"string-ascii\": z.object({ length: z.number() }) }),\n\t\tz.object({ \"string-utf8\": z.object({ length: z.number() }) }),\n\t\tz.object({ optional: AbiTypeSchema }),\n\t\tz.object({\n\t\t\tlist: z.object({ type: AbiTypeSchema, length: z.number() }),\n\t\t}),\n\t\tz.object({\n\t\t\ttuple: z.array(z.object({ name: z.string(), type: AbiTypeSchema })),\n\t\t}),\n\t\tz.object({\n\t\t\tresponse: z.object({ ok: AbiTypeSchema, error: AbiTypeSchema }),\n\t\t}),\n\t]),\n);\n\n/**\n * The canonical `AbiContract` shape, validated at deploy time.\n *\n * This used to be `z.record(z.string(), z.any())`, which accepted a raw\n * Hiro/Clarinet ABI (`read_only` access, `buffer` types, outputs wrapped as\n * `{ type: … }`) and let it through — the deploy succeeded and `event.input`\n * then mis-decoded at RUNTIME, per event, forever. Reject it here instead,\n * and name the fix: run it through `normalizeAbi` from\n * `@secondlayer/stacks/clarity`.\n */\nexport const AbiContractSchema: z.ZodType<unknown> = z.object({\n\tfunctions: z.array(\n\t\tz.object({\n\t\t\tname: z.string(),\n\t\t\taccess: z.enum([\"public\", \"read-only\", \"private\"], {\n\t\t\t\tmessage:\n\t\t\t\t\t\"ABI access must be public | read-only | private — a raw Hiro/Clarinet ABI uses `read_only`. Normalize it first: normalizeAbi() from @secondlayer/stacks/clarity.\",\n\t\t\t}),\n\t\t\targs: z.array(z.object({ name: z.string(), type: AbiTypeSchema })),\n\t\t\t// Canonical shape is a bare AbiType; raw ABIs wrap it as `{ type: … }`.\n\t\t\toutputs: AbiTypeSchema,\n\t\t}),\n\t),\n\tmaps: z.array(z.unknown()).optional(),\n\tvariables: z.array(z.unknown()).optional(),\n\tfungible_tokens: z.array(z.unknown()).optional(),\n\tnon_fungible_tokens: z.array(z.unknown()).optional(),\n\timplemented_traits: z.array(z.unknown()).optional(),\n\tdefined_traits: z.array(z.unknown()).optional(),\n});\n\nexport const SubgraphColumnSchema: z.ZodType<SubgraphColumn> = z.object({\n\ttype: ColumnTypeSchema,\n\tnullable: z.boolean().optional(),\n\tindexed: z.boolean().optional(),\n\tsearch: z.boolean().optional(),\n\tdefault: z.union([z.string(), z.number(), z.boolean()]).optional(),\n}) as z.ZodType<SubgraphColumn>;\n\nexport const SubgraphTableSchema: z.ZodType<SubgraphTable> = z.object({\n\tcolumns: z\n\t\t.record(SqlIdentifierSchema, SubgraphColumnSchema)\n\t\t.refine(\n\t\t\t(c) => Object.keys(c).length > 0,\n\t\t\t\"Table must have at least one column\",\n\t\t),\n\tindexes: z.array(z.array(SqlIdentifierSchema)).optional(),\n\tuniqueKeys: z.array(z.array(SqlIdentifierSchema)).optional(),\n\trelations: z\n\t\t.array(\n\t\t\tz.object({\n\t\t\t\tname: SqlIdentifierSchema,\n\t\t\t\treferences: SqlIdentifierSchema,\n\t\t\t\tfields: z.array(SqlIdentifierSchema).min(1),\n\t\t\t\treferencedColumns: z.array(SqlIdentifierSchema).min(1),\n\t\t\t}),\n\t\t)\n\t\t.optional(),\n}) as z.ZodType<SubgraphTable>;\n\nexport const SubgraphSchemaSchema: z.ZodType<Record<string, SubgraphTable>> = z\n\t.record(SqlIdentifierSchema, SubgraphTableSchema)\n\t.refine(\n\t\t(s) => Object.keys(s).length > 0,\n\t\t\"Schema must have at least one table\",\n\t) as z.ZodType<Record<string, SubgraphTable>>;\n\nexport const VALID_FILTER_TYPES = [\n\t\"stx_transfer\",\n\t\"stx_mint\",\n\t\"stx_burn\",\n\t\"stx_lock\",\n\t\"ft_transfer\",\n\t\"ft_mint\",\n\t\"ft_burn\",\n\t\"nft_transfer\",\n\t\"nft_mint\",\n\t\"nft_burn\",\n\t\"contract_call\",\n\t\"contract_deploy\",\n\t\"print_event\",\n] as const;\n\nexport const SubgraphFilterSchema: z.ZodType<SubgraphFilter> = z\n\t.object({\n\t\ttype: z.enum(VALID_FILTER_TYPES),\n\t\t// All optional fields across all filter types\n\t\tsender: z.string().optional(),\n\t\trecipient: z.string().optional(),\n\t\tminAmount: z.bigint().optional(),\n\t\tmaxAmount: z.bigint().optional(),\n\t\tassetIdentifier: z.string().optional(),\n\t\tcontractId: z.string().optional(),\n\t\tfunctionName: z.string().optional(),\n\t\tcaller: z.string().optional(),\n\t\tdeployer: z.string().optional(),\n\t\tcontractName: z.string().optional(),\n\t\ttopic: z.string().optional(),\n\t\tlockedAddress: z.string().optional(),\n\t\tabi: AbiContractSchema.optional(),\n\t\ttrait: z.string().optional(),\n\t\t// print_event per-topic field schema. Declaring it opts the source into\n\t\t// runtime payload validation (skip + log on mismatch).\n\t\tprints: z\n\t\t\t.record(z.string(), z.record(z.string(), PrintFieldSchema))\n\t\t\t.optional(),\n\t})\n\t.strict() as unknown as z.ZodType<SubgraphFilter>;\n\nexport const SubgraphDefinitionSchema: z.ZodType<SubgraphDefinition> = z.object(\n\t{\n\t\tname: SubgraphNameSchema,\n\t\tversion: z.string().optional(),\n\t\tdescription: z.string().optional(),\n\t\tstartBlock: z.number().int().nonnegative().optional(),\n\t\t// 'concurrent' = tip-first deploy: go live at tip immediately, fill\n\t\t// history via a background backfill. Only safe for order-tolerant\n\t\t// handlers (commutative or insert-only writes).\n\t\tbackfillMode: z.enum([\"blocking\", \"concurrent\"]).optional(),\n\t\tsources: z\n\t\t\t.record(z.string(), SubgraphFilterSchema)\n\t\t\t.refine(\n\t\t\t\t(s) => Object.keys(s).length > 0,\n\t\t\t\t\"Must have at least one source\",\n\t\t\t),\n\t\tschema: SubgraphSchemaSchema,\n\t\thandlers: z.record(z.string(), z.any()),\n\t},\n) as unknown as z.ZodType<SubgraphDefinition>;\n\n/**\n * Validates a subgraph definition, returning the parsed result or throwing on failure.\n */\nexport function validateSubgraphDefinition(def: unknown): SubgraphDefinition {\n\treturn SubgraphDefinitionSchema.parse(def);\n}\n"
6
6
  ],
7
- "mappings": ";;;;AAAA;AASO,IAAM,qBAAwC,EACnD,OAAO,EACP,IAAI,CAAC,EACL,IAAI,EAAE,EACN,MACA,qBACA,mFACD;AAQM,IAAM,sBAAyC,EACpD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": []
10
10
  }
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@secondlayer/subgraphs",
3
- "version": "3.19.10",
3
+ "version": "3.21.0",
4
4
  "license": "MIT",
5
5
  "repository": {
6
6
  "type": "git",
@@ -55,7 +55,7 @@
55
55
  },
56
56
  "dependencies": {
57
57
  "@secondlayer/shared": "^7.0.3",
58
- "@secondlayer/stacks": "^2.14.1",
58
+ "@secondlayer/stacks": "^2.21.0",
59
59
  "esbuild": "^0.27.4",
60
60
  "kysely": "0.28.17",
61
61
  "zod": "^4.3.6"