@secondlayer/subgraphs 7.0.4 → 7.2.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 +50 -7
- package/dist/index.js +11 -5
- package/dist/index.js.map +4 -4
- package/dist/runtime/replay.js +262 -27
- package/dist/runtime/replay.js.map +9 -7
- package/dist/schema/index.d.ts +18 -0
- package/dist/schema/index.js +11 -5
- package/dist/schema/index.js.map +3 -3
- package/dist/testing/index.d.ts +50 -6
- package/dist/testing/index.js +79 -14
- package/dist/testing/index.js.map +5 -5
- package/dist/types.d.ts +18 -0
- package/dist/validate.d.ts +18 -0
- package/dist/validate.js +7 -1
- package/dist/validate.js.map +3 -3
- package/dist/verification.d.ts +18 -0
- package/dist/verification.js +5 -5
- package/dist/verification.js.map +1 -1
- package/dist/verify/index.d.ts +18 -0
- package/dist/verify/index.js +70 -13
- package/dist/verify/index.js.map +4 -4
- package/package.json +4 -4
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.
|
|
@@ -378,6 +390,12 @@ type PrintEventPrints = Record<string, Record<string, PrintField>>;
|
|
|
378
390
|
type PrintEventFields = FactoryScope & {
|
|
379
391
|
type: "print_event";
|
|
380
392
|
topic?: string;
|
|
393
|
+
/** Equality on top-level keys of the decoded print tuple, spelled as the
|
|
394
|
+
* contract prints them (`signer-manager`). A value matches the field's
|
|
395
|
+
* JSON form: principals `SP…`, uints as decimal strings, bools
|
|
396
|
+
* `"true"`/`"false"`, buffers `0x…`. An array is any-of; keys AND.
|
|
397
|
+
* Nested tuples and lists never match. */
|
|
398
|
+
where?: Record<string, string | readonly string[]>;
|
|
381
399
|
};
|
|
382
400
|
/**
|
|
383
401
|
* Pinned to one or more contract ids with no trait — `prints` is required so
|
|
@@ -479,7 +497,7 @@ interface SubgraphDefinition {
|
|
|
479
497
|
/** Handler functions, one per source, keyed by source name */
|
|
480
498
|
handlers: Record<string, SubgraphHandler>;
|
|
481
499
|
}
|
|
482
|
-
import { AbiContract as AbiContract3, ExtractFunctionArgs as ExtractFunctionArgs2, ExtractFunctionNames } from "@secondlayer/stacks/clarity";
|
|
500
|
+
import { AbiContract as AbiContract3, ExtractFunctionArgs as ExtractFunctionArgs2, ExtractFunctionNames, ExtractMapKey, ExtractMapNames, ExtractMapValue, ExtractVariableNames, ExtractVariableType } from "@secondlayer/stacks/clarity";
|
|
483
501
|
/** Maps a ColumnType string literal to its TypeScript equivalent */
|
|
484
502
|
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
503
|
/** Infer TS type for a single column definition, respecting nullable */
|
|
@@ -837,14 +855,14 @@ interface NestedContractCallPayload {
|
|
|
837
855
|
result: unknown;
|
|
838
856
|
tx: TxMeta;
|
|
839
857
|
}
|
|
840
|
-
interface
|
|
858
|
+
interface VarSetEvent {
|
|
841
859
|
contractId: string;
|
|
842
860
|
varName: string;
|
|
843
861
|
rawValue: string;
|
|
844
862
|
value: unknown;
|
|
845
863
|
tx: TxMeta;
|
|
846
864
|
}
|
|
847
|
-
interface
|
|
865
|
+
interface MapWriteEvent {
|
|
848
866
|
contractId: string;
|
|
849
867
|
map: string;
|
|
850
868
|
rawKey: string;
|
|
@@ -853,7 +871,7 @@ interface MapWritePayload {
|
|
|
853
871
|
value: unknown;
|
|
854
872
|
tx: TxMeta;
|
|
855
873
|
}
|
|
856
|
-
interface
|
|
874
|
+
interface MapDeleteEvent {
|
|
857
875
|
contractId: string;
|
|
858
876
|
map: string;
|
|
859
877
|
rawKey: string;
|
|
@@ -861,6 +879,31 @@ interface MapDeletePayload {
|
|
|
861
879
|
tx: TxMeta;
|
|
862
880
|
}
|
|
863
881
|
/**
|
|
882
|
+
* State-write payloads. When the source carries a `const` `abi` and a known
|
|
883
|
+
* `varName` / `map`, `value` (and `key`) are typed from the contract's
|
|
884
|
+
* definition and decoded with it (camelCased tuple keys, `AbiToTS` shapes).
|
|
885
|
+
* Without an `abi`, or with a name the abi lacks, they stay `unknown`.
|
|
886
|
+
*/
|
|
887
|
+
type VarSetPayload<F = unknown> = F extends {
|
|
888
|
+
abi: infer A extends AbiContract3;
|
|
889
|
+
varName: infer N extends string;
|
|
890
|
+
} ? N extends ExtractVariableNames<A> ? Omit<VarSetEvent, "value"> & {
|
|
891
|
+
value: ExtractVariableType<A, N>;
|
|
892
|
+
} : VarSetEvent : VarSetEvent;
|
|
893
|
+
type MapWritePayload<F = unknown> = F extends {
|
|
894
|
+
abi: infer A extends AbiContract3;
|
|
895
|
+
map: infer N extends string;
|
|
896
|
+
} ? N extends ExtractMapNames<A> ? Omit<MapWriteEvent, "key" | "value"> & {
|
|
897
|
+
key: ExtractMapKey<A, N>;
|
|
898
|
+
value: ExtractMapValue<A, N>;
|
|
899
|
+
} : MapWriteEvent : MapWriteEvent;
|
|
900
|
+
type MapDeletePayload<F = unknown> = F extends {
|
|
901
|
+
abi: infer A extends AbiContract3;
|
|
902
|
+
map: infer N extends string;
|
|
903
|
+
} ? N extends ExtractMapNames<A> ? Omit<MapDeleteEvent, "key"> & {
|
|
904
|
+
key: ExtractMapKey<A, N>;
|
|
905
|
+
} : MapDeleteEvent : MapDeleteEvent;
|
|
906
|
+
/**
|
|
864
907
|
* Print event typed per topic. When a `print_event` source declares a `prints`
|
|
865
908
|
* map, the payload is a discriminated union keyed by `topic` with `data` typed
|
|
866
909
|
* per topic; otherwise it falls back to the untyped {@link PrintEventPayload}.
|
|
@@ -925,11 +968,11 @@ type EventForFilter<F extends SubgraphFilter> = F extends {
|
|
|
925
968
|
type: "nested_contract_call";
|
|
926
969
|
} ? NestedContractCallPayload : F extends {
|
|
927
970
|
type: "var_set";
|
|
928
|
-
} ? VarSetPayload : F extends {
|
|
971
|
+
} ? VarSetPayload<F> : F extends {
|
|
929
972
|
type: infer T extends "map_set" | "map_insert" | "map_delete";
|
|
930
|
-
} ? T extends "map_delete" ? MapDeletePayload : MapWritePayload : never;
|
|
973
|
+
} ? T extends "map_delete" ? MapDeletePayload<F> : MapWritePayload<F> : never;
|
|
931
974
|
/** Union of every event payload. */
|
|
932
|
-
type AnyEvent = FtTransferPayload | FtMintPayload | FtBurnPayload | NftTransferPayload | NftMintPayload | NftBurnPayload | StxTransferPayload | StxMintPayload | StxBurnPayload | StxLockPayload | PrintEventPayload | ContractCallEvent | ContractDeployPayload | NestedContractCallPayload |
|
|
975
|
+
type AnyEvent = FtTransferPayload | FtMintPayload | FtBurnPayload | NftTransferPayload | NftMintPayload | NftBurnPayload | StxTransferPayload | StxMintPayload | StxBurnPayload | StxLockPayload | PrintEventPayload | ContractCallEvent | ContractDeployPayload | NestedContractCallPayload | VarSetEvent | MapWriteEvent | MapDeleteEvent;
|
|
933
976
|
type HandlerFn<
|
|
934
977
|
F extends SubgraphFilter,
|
|
935
978
|
S extends SubgraphSchema
|
package/dist/index.js
CHANGED
|
@@ -6,6 +6,7 @@ function defineSchema(schema) {
|
|
|
6
6
|
return schema;
|
|
7
7
|
}
|
|
8
8
|
// src/validate.ts
|
|
9
|
+
import { PrintWhereSchema } from "@secondlayer/shared/schemas/webhooks";
|
|
9
10
|
import { z } from "zod";
|
|
10
11
|
var SubgraphNameSchema = z.string().min(1).max(63).regex(/^[a-z][a-z0-9-]*$/, "Must start with lowercase letter, contain only lowercase alphanumeric and hyphens");
|
|
11
12
|
var SqlIdentifierSchema = z.string().min(1).max(63).regex(/^[a-z_][a-z0-9_]*$/i, "Must be a valid SQL identifier: start with a letter or underscore, then letters/digits/underscores only");
|
|
@@ -182,6 +183,7 @@ var SubgraphFilterUnion = z.discriminatedUnion("type", [
|
|
|
182
183
|
type: z.literal("print_event"),
|
|
183
184
|
contractId: contractIdField.optional(),
|
|
184
185
|
topic: z.string().optional(),
|
|
186
|
+
where: PrintWhereSchema.optional(),
|
|
185
187
|
prints: z.record(z.string(), z.record(z.string(), PrintFieldSchema)).optional(),
|
|
186
188
|
...traitScope,
|
|
187
189
|
...factoryScope
|
|
@@ -199,6 +201,7 @@ var SubgraphFilterUnion = z.discriminatedUnion("type", [
|
|
|
199
201
|
type: z.literal("var_set"),
|
|
200
202
|
contractId: contractIdField.optional(),
|
|
201
203
|
varName: z.string().optional(),
|
|
204
|
+
abi: AbiContractSchema.optional(),
|
|
202
205
|
...traitScope,
|
|
203
206
|
...factoryScope
|
|
204
207
|
}).strict(),
|
|
@@ -206,6 +209,7 @@ var SubgraphFilterUnion = z.discriminatedUnion("type", [
|
|
|
206
209
|
type: z.literal("map_set"),
|
|
207
210
|
contractId: contractIdField.optional(),
|
|
208
211
|
map: z.string().optional(),
|
|
212
|
+
abi: AbiContractSchema.optional(),
|
|
209
213
|
...traitScope,
|
|
210
214
|
...factoryScope
|
|
211
215
|
}).strict(),
|
|
@@ -213,6 +217,7 @@ var SubgraphFilterUnion = z.discriminatedUnion("type", [
|
|
|
213
217
|
type: z.literal("map_insert"),
|
|
214
218
|
contractId: contractIdField.optional(),
|
|
215
219
|
map: z.string().optional(),
|
|
220
|
+
abi: AbiContractSchema.optional(),
|
|
216
221
|
...traitScope,
|
|
217
222
|
...factoryScope
|
|
218
223
|
}).strict(),
|
|
@@ -220,6 +225,7 @@ var SubgraphFilterUnion = z.discriminatedUnion("type", [
|
|
|
220
225
|
type: z.literal("map_delete"),
|
|
221
226
|
contractId: contractIdField.optional(),
|
|
222
227
|
map: z.string().optional(),
|
|
228
|
+
abi: AbiContractSchema.optional(),
|
|
223
229
|
...traitScope,
|
|
224
230
|
...factoryScope
|
|
225
231
|
}).strict()
|
|
@@ -787,7 +793,7 @@ import { createHash } from "node:crypto";
|
|
|
787
793
|
// package.json
|
|
788
794
|
var package_default = {
|
|
789
795
|
name: "@secondlayer/subgraphs",
|
|
790
|
-
version: "7.0
|
|
796
|
+
version: "7.2.0",
|
|
791
797
|
description: "Describe the Stacks data you want as one TypeScript file; it fills itself and survives reorgs.",
|
|
792
798
|
license: "MIT",
|
|
793
799
|
repository: {
|
|
@@ -847,9 +853,9 @@ var package_default = {
|
|
|
847
853
|
prepublishOnly: "bun run build"
|
|
848
854
|
},
|
|
849
855
|
dependencies: {
|
|
850
|
-
"@secondlayer/shared": "^13.
|
|
851
|
-
"@secondlayer/stacks": "^6.
|
|
852
|
-
"@secondlayer/verify": "^0.
|
|
856
|
+
"@secondlayer/shared": "^13.1.0",
|
|
857
|
+
"@secondlayer/stacks": "^6.4.0",
|
|
858
|
+
"@secondlayer/verify": "^0.6.0",
|
|
853
859
|
esbuild: "^0.28.2",
|
|
854
860
|
kysely: "0.28.17",
|
|
855
861
|
zod: "^4.3.6"
|
|
@@ -2949,5 +2955,5 @@ export {
|
|
|
2949
2955
|
validateSubgraphDefinition
|
|
2950
2956
|
};
|
|
2951
2957
|
|
|
2952
|
-
//# debugId=
|
|
2958
|
+
//# debugId=A0749A4C359E248364756E2164756E21
|
|
2953
2959
|
//# sourceMappingURL=index.js.map
|