@secondlayer/subgraphs 7.0.3 → 7.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.
package/dist/index.d.ts CHANGED
@@ -338,11 +338,23 @@ interface VarSetFilter extends TraitScope, FactoryScope {
338
338
  type: "var_set";
339
339
  contractId?: string | readonly string[];
340
340
  varName?: string;
341
+ /**
342
+ * Contract ABI. With a `varName` the abi defines, `event.value` is typed
343
+ * and decoded from the variable's type. Pass it yourself
344
+ * (`normalizeAbi()` from `@secondlayer/stacks/clarity`).
345
+ */
346
+ abi?: AbiContract2;
341
347
  }
342
348
  interface MapWriteFilter extends TraitScope, FactoryScope {
343
349
  type: "map_set" | "map_insert" | "map_delete";
344
350
  contractId?: string | readonly string[];
345
351
  map?: string;
352
+ /**
353
+ * Contract ABI. With a `map` the abi defines, `event.key` and
354
+ * `event.value` are typed and decoded from the map's types. Pass it
355
+ * yourself (`normalizeAbi()` from `@secondlayer/stacks/clarity`).
356
+ */
357
+ abi?: AbiContract2;
346
358
  }
347
359
  /**
348
360
  * One declared field of a print payload.
@@ -479,7 +491,7 @@ interface SubgraphDefinition {
479
491
  /** Handler functions, one per source, keyed by source name */
480
492
  handlers: Record<string, SubgraphHandler>;
481
493
  }
482
- import { AbiContract as AbiContract3, ExtractFunctionArgs as ExtractFunctionArgs2, ExtractFunctionNames } from "@secondlayer/stacks/clarity";
494
+ import { AbiContract as AbiContract3, ExtractFunctionArgs as ExtractFunctionArgs2, ExtractFunctionNames, ExtractMapKey, ExtractMapNames, ExtractMapValue, ExtractVariableNames, ExtractVariableType } from "@secondlayer/stacks/clarity";
483
495
  /** Maps a ColumnType string literal to its TypeScript equivalent */
484
496
  type ColumnToTS<T extends string> = T extends "uint" | "int" ? bigint : T extends "text" | "principal" | "timestamp" ? string : T extends "boolean" ? boolean : T extends "jsonb" ? Record<string, unknown> : unknown;
485
497
  /** Infer TS type for a single column definition, respecting nullable */
@@ -837,14 +849,14 @@ interface NestedContractCallPayload {
837
849
  result: unknown;
838
850
  tx: TxMeta;
839
851
  }
840
- interface VarSetPayload {
852
+ interface VarSetEvent {
841
853
  contractId: string;
842
854
  varName: string;
843
855
  rawValue: string;
844
856
  value: unknown;
845
857
  tx: TxMeta;
846
858
  }
847
- interface MapWritePayload {
859
+ interface MapWriteEvent {
848
860
  contractId: string;
849
861
  map: string;
850
862
  rawKey: string;
@@ -853,7 +865,7 @@ interface MapWritePayload {
853
865
  value: unknown;
854
866
  tx: TxMeta;
855
867
  }
856
- interface MapDeletePayload {
868
+ interface MapDeleteEvent {
857
869
  contractId: string;
858
870
  map: string;
859
871
  rawKey: string;
@@ -861,6 +873,31 @@ interface MapDeletePayload {
861
873
  tx: TxMeta;
862
874
  }
863
875
  /**
876
+ * State-write payloads. When the source carries a `const` `abi` and a known
877
+ * `varName` / `map`, `value` (and `key`) are typed from the contract's
878
+ * definition and decoded with it (camelCased tuple keys, `AbiToTS` shapes).
879
+ * Without an `abi`, or with a name the abi lacks, they stay `unknown`.
880
+ */
881
+ type VarSetPayload<F = unknown> = F extends {
882
+ abi: infer A extends AbiContract3;
883
+ varName: infer N extends string;
884
+ } ? N extends ExtractVariableNames<A> ? Omit<VarSetEvent, "value"> & {
885
+ value: ExtractVariableType<A, N>;
886
+ } : VarSetEvent : VarSetEvent;
887
+ type MapWritePayload<F = unknown> = F extends {
888
+ abi: infer A extends AbiContract3;
889
+ map: infer N extends string;
890
+ } ? N extends ExtractMapNames<A> ? Omit<MapWriteEvent, "key" | "value"> & {
891
+ key: ExtractMapKey<A, N>;
892
+ value: ExtractMapValue<A, N>;
893
+ } : MapWriteEvent : MapWriteEvent;
894
+ type MapDeletePayload<F = unknown> = F extends {
895
+ abi: infer A extends AbiContract3;
896
+ map: infer N extends string;
897
+ } ? N extends ExtractMapNames<A> ? Omit<MapDeleteEvent, "key"> & {
898
+ key: ExtractMapKey<A, N>;
899
+ } : MapDeleteEvent : MapDeleteEvent;
900
+ /**
864
901
  * Print event typed per topic. When a `print_event` source declares a `prints`
865
902
  * map, the payload is a discriminated union keyed by `topic` with `data` typed
866
903
  * per topic; otherwise it falls back to the untyped {@link PrintEventPayload}.
@@ -925,11 +962,11 @@ type EventForFilter<F extends SubgraphFilter> = F extends {
925
962
  type: "nested_contract_call";
926
963
  } ? NestedContractCallPayload : F extends {
927
964
  type: "var_set";
928
- } ? VarSetPayload : F extends {
965
+ } ? VarSetPayload<F> : F extends {
929
966
  type: infer T extends "map_set" | "map_insert" | "map_delete";
930
- } ? T extends "map_delete" ? MapDeletePayload : MapWritePayload : never;
967
+ } ? T extends "map_delete" ? MapDeletePayload<F> : MapWritePayload<F> : never;
931
968
  /** Union of every event payload. */
932
- type AnyEvent = FtTransferPayload | FtMintPayload | FtBurnPayload | NftTransferPayload | NftMintPayload | NftBurnPayload | StxTransferPayload | StxMintPayload | StxBurnPayload | StxLockPayload | PrintEventPayload | ContractCallEvent | ContractDeployPayload | NestedContractCallPayload | VarSetPayload | MapWritePayload | MapDeletePayload;
969
+ type AnyEvent = FtTransferPayload | FtMintPayload | FtBurnPayload | NftTransferPayload | NftMintPayload | NftBurnPayload | StxTransferPayload | StxMintPayload | StxBurnPayload | StxLockPayload | PrintEventPayload | ContractCallEvent | ContractDeployPayload | NestedContractCallPayload | VarSetEvent | MapWriteEvent | MapDeleteEvent;
933
970
  type HandlerFn<
934
971
  F extends SubgraphFilter,
935
972
  S extends SubgraphSchema
package/dist/index.js CHANGED
@@ -199,6 +199,7 @@ var SubgraphFilterUnion = z.discriminatedUnion("type", [
199
199
  type: z.literal("var_set"),
200
200
  contractId: contractIdField.optional(),
201
201
  varName: z.string().optional(),
202
+ abi: AbiContractSchema.optional(),
202
203
  ...traitScope,
203
204
  ...factoryScope
204
205
  }).strict(),
@@ -206,6 +207,7 @@ var SubgraphFilterUnion = z.discriminatedUnion("type", [
206
207
  type: z.literal("map_set"),
207
208
  contractId: contractIdField.optional(),
208
209
  map: z.string().optional(),
210
+ abi: AbiContractSchema.optional(),
209
211
  ...traitScope,
210
212
  ...factoryScope
211
213
  }).strict(),
@@ -213,6 +215,7 @@ var SubgraphFilterUnion = z.discriminatedUnion("type", [
213
215
  type: z.literal("map_insert"),
214
216
  contractId: contractIdField.optional(),
215
217
  map: z.string().optional(),
218
+ abi: AbiContractSchema.optional(),
216
219
  ...traitScope,
217
220
  ...factoryScope
218
221
  }).strict(),
@@ -220,6 +223,7 @@ var SubgraphFilterUnion = z.discriminatedUnion("type", [
220
223
  type: z.literal("map_delete"),
221
224
  contractId: contractIdField.optional(),
222
225
  map: z.string().optional(),
226
+ abi: AbiContractSchema.optional(),
223
227
  ...traitScope,
224
228
  ...factoryScope
225
229
  }).strict()
@@ -787,7 +791,7 @@ import { createHash } from "node:crypto";
787
791
  // package.json
788
792
  var package_default = {
789
793
  name: "@secondlayer/subgraphs",
790
- version: "7.0.3",
794
+ version: "7.1.0",
791
795
  description: "Describe the Stacks data you want as one TypeScript file; it fills itself and survives reorgs.",
792
796
  license: "MIT",
793
797
  repository: {
@@ -847,9 +851,9 @@ var package_default = {
847
851
  prepublishOnly: "bun run build"
848
852
  },
849
853
  dependencies: {
850
- "@secondlayer/shared": "^12.1.2",
851
- "@secondlayer/stacks": "^6.2.2",
852
- "@secondlayer/verify": "^0.5.4",
854
+ "@secondlayer/shared": "^13.0.0",
855
+ "@secondlayer/stacks": "^6.3.0",
856
+ "@secondlayer/verify": "^0.6.0",
853
857
  esbuild: "^0.28.2",
854
858
  kysely: "0.28.17",
855
859
  zod: "^4.3.6"
@@ -2949,5 +2953,5 @@ export {
2949
2953
  validateSubgraphDefinition
2950
2954
  };
2951
2955
 
2952
- //# debugId=E3F910C01BB06DA264756E2164756E21
2956
+ //# debugId=DC950AFB0608338264756E2164756E21
2953
2957
  //# sourceMappingURL=index.js.map