@secondlayer/subgraphs 3.2.1 → 3.3.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/README.md +81 -0
- package/dist/src/index.d.ts +71 -9
- package/dist/src/index.js +461 -54
- package/dist/src/index.js.map +11 -9
- package/dist/src/runtime/block-processor.d.ts +37 -9
- package/dist/src/runtime/block-processor.js +127 -37
- package/dist/src/runtime/block-processor.js.map +5 -5
- package/dist/src/runtime/catchup.d.ts +34 -8
- package/dist/src/runtime/catchup.js +125 -36
- package/dist/src/runtime/catchup.js.map +5 -5
- package/dist/src/runtime/context.d.ts +27 -1
- package/dist/src/runtime/context.js +13 -2
- package/dist/src/runtime/context.js.map +3 -3
- package/dist/src/runtime/processor.js +143 -39
- package/dist/src/runtime/processor.js.map +8 -8
- package/dist/src/runtime/reindex.d.ts +34 -8
- package/dist/src/runtime/reindex.js +131 -36
- package/dist/src/runtime/reindex.js.map +6 -6
- package/dist/src/runtime/reorg.d.ts +34 -8
- package/dist/src/runtime/reorg.js +131 -39
- package/dist/src/runtime/reorg.js.map +6 -6
- package/dist/src/runtime/runner.d.ts +43 -9
- package/dist/src/runtime/source-matcher.d.ts +19 -10
- package/dist/src/runtime/source-matcher.js +26 -6
- package/dist/src/runtime/source-matcher.js.map +3 -3
- package/dist/src/schema/index.d.ts +42 -8
- package/dist/src/schema/index.js +57 -19
- package/dist/src/schema/index.js.map +5 -5
- package/dist/src/service.js +143 -39
- package/dist/src/service.js.map +8 -8
- package/dist/src/triggers/index.d.ts +16 -8
- package/dist/src/types.d.ts +35 -9
- package/dist/src/validate.d.ts +34 -8
- package/dist/src/validate.js +10 -3
- package/dist/src/validate.js.map +3 -3
- package/package.json +3 -3
|
@@ -24,45 +24,53 @@ interface StxLockFilter {
|
|
|
24
24
|
lockedAddress?: string;
|
|
25
25
|
minAmount?: bigint;
|
|
26
26
|
}
|
|
27
|
+
/**
|
|
28
|
+
* Restrict a source to contracts conforming to a trait/standard (e.g. "sip-010")
|
|
29
|
+
* instead of a fixed contract — resolved from the contract registry at match time,
|
|
30
|
+
* as-of each processed block. Lets a source index "all SIP-010 tokens" etc.
|
|
31
|
+
*/
|
|
32
|
+
type TraitScope = {
|
|
33
|
+
trait?: string
|
|
34
|
+
};
|
|
27
35
|
/** FT event filters */
|
|
28
|
-
interface FtTransferFilter {
|
|
36
|
+
interface FtTransferFilter extends TraitScope {
|
|
29
37
|
type: "ft_transfer";
|
|
30
38
|
assetIdentifier?: string;
|
|
31
39
|
sender?: string;
|
|
32
40
|
recipient?: string;
|
|
33
41
|
minAmount?: bigint;
|
|
34
42
|
}
|
|
35
|
-
interface FtMintFilter {
|
|
43
|
+
interface FtMintFilter extends TraitScope {
|
|
36
44
|
type: "ft_mint";
|
|
37
45
|
assetIdentifier?: string;
|
|
38
46
|
recipient?: string;
|
|
39
47
|
minAmount?: bigint;
|
|
40
48
|
}
|
|
41
|
-
interface FtBurnFilter {
|
|
49
|
+
interface FtBurnFilter extends TraitScope {
|
|
42
50
|
type: "ft_burn";
|
|
43
51
|
assetIdentifier?: string;
|
|
44
52
|
sender?: string;
|
|
45
53
|
minAmount?: bigint;
|
|
46
54
|
}
|
|
47
55
|
/** NFT event filters */
|
|
48
|
-
interface NftTransferFilter {
|
|
56
|
+
interface NftTransferFilter extends TraitScope {
|
|
49
57
|
type: "nft_transfer";
|
|
50
58
|
assetIdentifier?: string;
|
|
51
59
|
sender?: string;
|
|
52
60
|
recipient?: string;
|
|
53
61
|
}
|
|
54
|
-
interface NftMintFilter {
|
|
62
|
+
interface NftMintFilter extends TraitScope {
|
|
55
63
|
type: "nft_mint";
|
|
56
64
|
assetIdentifier?: string;
|
|
57
65
|
recipient?: string;
|
|
58
66
|
}
|
|
59
|
-
interface NftBurnFilter {
|
|
67
|
+
interface NftBurnFilter extends TraitScope {
|
|
60
68
|
type: "nft_burn";
|
|
61
69
|
assetIdentifier?: string;
|
|
62
70
|
sender?: string;
|
|
63
71
|
}
|
|
64
72
|
/** Contract event filters */
|
|
65
|
-
interface ContractCallFilter {
|
|
73
|
+
interface ContractCallFilter extends TraitScope {
|
|
66
74
|
type: "contract_call";
|
|
67
75
|
contractId?: string;
|
|
68
76
|
functionName?: string;
|
|
@@ -80,7 +88,7 @@ interface ContractDeployFilter {
|
|
|
80
88
|
deployer?: string;
|
|
81
89
|
contractName?: string;
|
|
82
90
|
}
|
|
83
|
-
interface PrintEventFilter {
|
|
91
|
+
interface PrintEventFilter extends TraitScope {
|
|
84
92
|
type: "print_event";
|
|
85
93
|
contractId?: string;
|
|
86
94
|
topic?: string;
|
package/dist/src/types.d.ts
CHANGED
|
@@ -9,6 +9,22 @@ interface SubgraphColumn {
|
|
|
9
9
|
search?: boolean;
|
|
10
10
|
default?: string | number | boolean;
|
|
11
11
|
}
|
|
12
|
+
/**
|
|
13
|
+
* A foreign-key relation to another table in the same subgraph. Drives DDL FK
|
|
14
|
+
* constraints and ORM codegen (`@relation` in Prisma, `relations()` in Drizzle)
|
|
15
|
+
* so generated clients get typed joins. The referenced columns must form a
|
|
16
|
+
* `uniqueKeys` entry on the target table.
|
|
17
|
+
*/
|
|
18
|
+
interface SubgraphRelation {
|
|
19
|
+
/** Relation field name on this table's generated model (e.g. "pool"). */
|
|
20
|
+
name: string;
|
|
21
|
+
/** Target table name in this subgraph. */
|
|
22
|
+
references: string;
|
|
23
|
+
/** Local column(s) holding the foreign key. */
|
|
24
|
+
fields: string[];
|
|
25
|
+
/** Target column(s) the fields point at (a uniqueKeys entry on the target). */
|
|
26
|
+
referencedColumns: string[];
|
|
27
|
+
}
|
|
12
28
|
/** Table definition within a subgraph schema */
|
|
13
29
|
interface SubgraphTable {
|
|
14
30
|
columns: Record<string, SubgraphColumn>;
|
|
@@ -16,6 +32,8 @@ interface SubgraphTable {
|
|
|
16
32
|
indexes?: string[][];
|
|
17
33
|
/** Unique key constraints (each entry is an array of column names). Required for upsert. */
|
|
18
34
|
uniqueKeys?: string[][];
|
|
35
|
+
/** Foreign-key relations to other tables (for typed ORM joins). */
|
|
36
|
+
relations?: SubgraphRelation[];
|
|
19
37
|
}
|
|
20
38
|
/** Subgraph schema — maps table names to table definitions */
|
|
21
39
|
type SubgraphSchema = Record<string, SubgraphTable>;
|
|
@@ -42,39 +60,47 @@ interface StxLockFilter {
|
|
|
42
60
|
lockedAddress?: string;
|
|
43
61
|
minAmount?: bigint;
|
|
44
62
|
}
|
|
63
|
+
/**
|
|
64
|
+
* Restrict a source to contracts conforming to a trait/standard (e.g. "sip-010")
|
|
65
|
+
* instead of a fixed contract — resolved from the contract registry at match time,
|
|
66
|
+
* as-of each processed block. Lets a source index "all SIP-010 tokens" etc.
|
|
67
|
+
*/
|
|
68
|
+
type TraitScope = {
|
|
69
|
+
trait?: string
|
|
70
|
+
};
|
|
45
71
|
/** FT event filters */
|
|
46
|
-
interface FtTransferFilter {
|
|
72
|
+
interface FtTransferFilter extends TraitScope {
|
|
47
73
|
type: "ft_transfer";
|
|
48
74
|
assetIdentifier?: string;
|
|
49
75
|
sender?: string;
|
|
50
76
|
recipient?: string;
|
|
51
77
|
minAmount?: bigint;
|
|
52
78
|
}
|
|
53
|
-
interface FtMintFilter {
|
|
79
|
+
interface FtMintFilter extends TraitScope {
|
|
54
80
|
type: "ft_mint";
|
|
55
81
|
assetIdentifier?: string;
|
|
56
82
|
recipient?: string;
|
|
57
83
|
minAmount?: bigint;
|
|
58
84
|
}
|
|
59
|
-
interface FtBurnFilter {
|
|
85
|
+
interface FtBurnFilter extends TraitScope {
|
|
60
86
|
type: "ft_burn";
|
|
61
87
|
assetIdentifier?: string;
|
|
62
88
|
sender?: string;
|
|
63
89
|
minAmount?: bigint;
|
|
64
90
|
}
|
|
65
91
|
/** NFT event filters */
|
|
66
|
-
interface NftTransferFilter {
|
|
92
|
+
interface NftTransferFilter extends TraitScope {
|
|
67
93
|
type: "nft_transfer";
|
|
68
94
|
assetIdentifier?: string;
|
|
69
95
|
sender?: string;
|
|
70
96
|
recipient?: string;
|
|
71
97
|
}
|
|
72
|
-
interface NftMintFilter {
|
|
98
|
+
interface NftMintFilter extends TraitScope {
|
|
73
99
|
type: "nft_mint";
|
|
74
100
|
assetIdentifier?: string;
|
|
75
101
|
recipient?: string;
|
|
76
102
|
}
|
|
77
|
-
interface NftBurnFilter {
|
|
103
|
+
interface NftBurnFilter extends TraitScope {
|
|
78
104
|
type: "nft_burn";
|
|
79
105
|
assetIdentifier?: string;
|
|
80
106
|
sender?: string;
|
|
@@ -121,7 +147,7 @@ interface ContractCallEvent {
|
|
|
121
147
|
};
|
|
122
148
|
}
|
|
123
149
|
/** Contract event filters */
|
|
124
|
-
interface ContractCallFilter {
|
|
150
|
+
interface ContractCallFilter extends TraitScope {
|
|
125
151
|
type: "contract_call";
|
|
126
152
|
contractId?: string;
|
|
127
153
|
functionName?: string;
|
|
@@ -139,7 +165,7 @@ interface ContractDeployFilter {
|
|
|
139
165
|
deployer?: string;
|
|
140
166
|
contractName?: string;
|
|
141
167
|
}
|
|
142
|
-
interface PrintEventFilter {
|
|
168
|
+
interface PrintEventFilter extends TraitScope {
|
|
143
169
|
type: "print_event";
|
|
144
170
|
contractId?: string;
|
|
145
171
|
topic?: string;
|
|
@@ -218,4 +244,4 @@ interface SubgraphDefinition {
|
|
|
218
244
|
/** Handler functions — keys must match source names (or "*" for catch-all) */
|
|
219
245
|
handlers: Record<string, SubgraphHandler>;
|
|
220
246
|
}
|
|
221
|
-
export { TxMeta, SubgraphTable, SubgraphSchema, SubgraphHandler, SubgraphFilter, SubgraphDefinition, SubgraphContext, SubgraphColumn, StxTransferFilter, StxMintFilter, StxLockFilter, StxBurnFilter, RowValue, PrintEventFilter, NftTransferFilter, NftMintFilter, NftBurnFilter, FtTransferFilter, FtMintFilter, FtBurnFilter, ContractDeployFilter, ContractCallFilter, ContractCallEvent, ComputedValue, ColumnType };
|
|
247
|
+
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 };
|
package/dist/src/validate.d.ts
CHANGED
|
@@ -9,6 +9,22 @@ interface SubgraphColumn {
|
|
|
9
9
|
search?: boolean;
|
|
10
10
|
default?: string | number | boolean;
|
|
11
11
|
}
|
|
12
|
+
/**
|
|
13
|
+
* A foreign-key relation to another table in the same subgraph. Drives DDL FK
|
|
14
|
+
* constraints and ORM codegen (`@relation` in Prisma, `relations()` in Drizzle)
|
|
15
|
+
* so generated clients get typed joins. The referenced columns must form a
|
|
16
|
+
* `uniqueKeys` entry on the target table.
|
|
17
|
+
*/
|
|
18
|
+
interface SubgraphRelation {
|
|
19
|
+
/** Relation field name on this table's generated model (e.g. "pool"). */
|
|
20
|
+
name: string;
|
|
21
|
+
/** Target table name in this subgraph. */
|
|
22
|
+
references: string;
|
|
23
|
+
/** Local column(s) holding the foreign key. */
|
|
24
|
+
fields: string[];
|
|
25
|
+
/** Target column(s) the fields point at (a uniqueKeys entry on the target). */
|
|
26
|
+
referencedColumns: string[];
|
|
27
|
+
}
|
|
12
28
|
/** Table definition within a subgraph schema */
|
|
13
29
|
interface SubgraphTable {
|
|
14
30
|
columns: Record<string, SubgraphColumn>;
|
|
@@ -16,6 +32,8 @@ interface SubgraphTable {
|
|
|
16
32
|
indexes?: string[][];
|
|
17
33
|
/** Unique key constraints (each entry is an array of column names). Required for upsert. */
|
|
18
34
|
uniqueKeys?: string[][];
|
|
35
|
+
/** Foreign-key relations to other tables (for typed ORM joins). */
|
|
36
|
+
relations?: SubgraphRelation[];
|
|
19
37
|
}
|
|
20
38
|
/** Subgraph schema — maps table names to table definitions */
|
|
21
39
|
type SubgraphSchema = Record<string, SubgraphTable>;
|
|
@@ -42,45 +60,53 @@ interface StxLockFilter {
|
|
|
42
60
|
lockedAddress?: string;
|
|
43
61
|
minAmount?: bigint;
|
|
44
62
|
}
|
|
63
|
+
/**
|
|
64
|
+
* Restrict a source to contracts conforming to a trait/standard (e.g. "sip-010")
|
|
65
|
+
* instead of a fixed contract — resolved from the contract registry at match time,
|
|
66
|
+
* as-of each processed block. Lets a source index "all SIP-010 tokens" etc.
|
|
67
|
+
*/
|
|
68
|
+
type TraitScope = {
|
|
69
|
+
trait?: string
|
|
70
|
+
};
|
|
45
71
|
/** FT event filters */
|
|
46
|
-
interface FtTransferFilter {
|
|
72
|
+
interface FtTransferFilter extends TraitScope {
|
|
47
73
|
type: "ft_transfer";
|
|
48
74
|
assetIdentifier?: string;
|
|
49
75
|
sender?: string;
|
|
50
76
|
recipient?: string;
|
|
51
77
|
minAmount?: bigint;
|
|
52
78
|
}
|
|
53
|
-
interface FtMintFilter {
|
|
79
|
+
interface FtMintFilter extends TraitScope {
|
|
54
80
|
type: "ft_mint";
|
|
55
81
|
assetIdentifier?: string;
|
|
56
82
|
recipient?: string;
|
|
57
83
|
minAmount?: bigint;
|
|
58
84
|
}
|
|
59
|
-
interface FtBurnFilter {
|
|
85
|
+
interface FtBurnFilter extends TraitScope {
|
|
60
86
|
type: "ft_burn";
|
|
61
87
|
assetIdentifier?: string;
|
|
62
88
|
sender?: string;
|
|
63
89
|
minAmount?: bigint;
|
|
64
90
|
}
|
|
65
91
|
/** NFT event filters */
|
|
66
|
-
interface NftTransferFilter {
|
|
92
|
+
interface NftTransferFilter extends TraitScope {
|
|
67
93
|
type: "nft_transfer";
|
|
68
94
|
assetIdentifier?: string;
|
|
69
95
|
sender?: string;
|
|
70
96
|
recipient?: string;
|
|
71
97
|
}
|
|
72
|
-
interface NftMintFilter {
|
|
98
|
+
interface NftMintFilter extends TraitScope {
|
|
73
99
|
type: "nft_mint";
|
|
74
100
|
assetIdentifier?: string;
|
|
75
101
|
recipient?: string;
|
|
76
102
|
}
|
|
77
|
-
interface NftBurnFilter {
|
|
103
|
+
interface NftBurnFilter extends TraitScope {
|
|
78
104
|
type: "nft_burn";
|
|
79
105
|
assetIdentifier?: string;
|
|
80
106
|
sender?: string;
|
|
81
107
|
}
|
|
82
108
|
/** Contract event filters */
|
|
83
|
-
interface ContractCallFilter {
|
|
109
|
+
interface ContractCallFilter extends TraitScope {
|
|
84
110
|
type: "contract_call";
|
|
85
111
|
contractId?: string;
|
|
86
112
|
functionName?: string;
|
|
@@ -98,7 +124,7 @@ interface ContractDeployFilter {
|
|
|
98
124
|
deployer?: string;
|
|
99
125
|
contractName?: string;
|
|
100
126
|
}
|
|
101
|
-
interface PrintEventFilter {
|
|
127
|
+
interface PrintEventFilter extends TraitScope {
|
|
102
128
|
type: "print_event";
|
|
103
129
|
contractId?: string;
|
|
104
130
|
topic?: string;
|
package/dist/src/validate.js
CHANGED
|
@@ -23,7 +23,13 @@ var SubgraphColumnSchema = z.object({
|
|
|
23
23
|
var SubgraphTableSchema = z.object({
|
|
24
24
|
columns: z.record(z.string(), SubgraphColumnSchema).refine((c) => Object.keys(c).length > 0, "Table must have at least one column"),
|
|
25
25
|
indexes: z.array(z.array(z.string())).optional(),
|
|
26
|
-
uniqueKeys: z.array(z.array(z.string())).optional()
|
|
26
|
+
uniqueKeys: z.array(z.array(z.string())).optional(),
|
|
27
|
+
relations: z.array(z.object({
|
|
28
|
+
name: z.string(),
|
|
29
|
+
references: z.string(),
|
|
30
|
+
fields: z.array(z.string()).min(1),
|
|
31
|
+
referencedColumns: z.array(z.string()).min(1)
|
|
32
|
+
})).optional()
|
|
27
33
|
});
|
|
28
34
|
var SubgraphSchemaSchema = z.record(z.string(), SubgraphTableSchema).refine((s) => Object.keys(s).length > 0, "Schema must have at least one table");
|
|
29
35
|
var VALID_FILTER_TYPES = [
|
|
@@ -55,7 +61,8 @@ var SubgraphFilterSchema = z.object({
|
|
|
55
61
|
contractName: z.string().optional(),
|
|
56
62
|
topic: z.string().optional(),
|
|
57
63
|
lockedAddress: z.string().optional(),
|
|
58
|
-
abi: z.record(z.string(), z.any()).optional()
|
|
64
|
+
abi: z.record(z.string(), z.any()).optional(),
|
|
65
|
+
trait: z.string().optional()
|
|
59
66
|
}).strict();
|
|
60
67
|
var SubgraphDefinitionSchema = z.object({
|
|
61
68
|
name: SubgraphNameSchema,
|
|
@@ -80,5 +87,5 @@ export {
|
|
|
80
87
|
ColumnTypeSchema
|
|
81
88
|
};
|
|
82
89
|
|
|
83
|
-
//# debugId=
|
|
90
|
+
//# debugId=6E82F2545E8F0C1F64756E2164756E21
|
|
84
91
|
//# sourceMappingURL=validate.js.map
|
package/dist/src/validate.js.map
CHANGED
|
@@ -2,9 +2,9 @@
|
|
|
2
2
|
"version": 3,
|
|
3
3
|
"sources": ["../src/validate.ts"],
|
|
4
4
|
"sourcesContent": [
|
|
5
|
-
"import { z } from \"zod/v4\";\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\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(z.string(), 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(z.string())).optional(),\n\tuniqueKeys: z.array(z.array(z.string())).optional(),\n}) as z.ZodType<SubgraphTable>;\n\nexport const SubgraphSchemaSchema: z.ZodType<Record<string, SubgraphTable>> = z\n\t.record(z.string(), 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\nconst 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})\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\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/v4\";\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\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(z.string(), 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(z.string())).optional(),\n\tuniqueKeys: z.array(z.array(z.string())).optional(),\n\trelations: z\n\t\t.array(\n\t\t\tz.object({\n\t\t\t\tname: z.string(),\n\t\t\t\treferences: z.string(),\n\t\t\t\tfields: z.array(z.string()).min(1),\n\t\t\t\treferencedColumns: z.array(z.string()).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(z.string(), 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\nconst 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})\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\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;AAEM,IAAM,mBAA0C,EAAE,KAAK;AAAA,EAC7D;AAAA,EACA;AAAA,EACA;AAAA,EACA;AAAA,EACA;AAAA,EACA;AAAA,EACA;AACD,CAAC;AAEM,IAAM,uBAAkD,EAAE,OAAO;AAAA,EACvE,MAAM;AAAA,EACN,UAAU,EAAE,QAAQ,EAAE,SAAS;AAAA,EAC/B,SAAS,EAAE,QAAQ,EAAE,SAAS;AAAA,EAC9B,QAAQ,EAAE,QAAQ,EAAE,SAAS;AAAA,EAC7B,SAAS,EAAE,MAAM,CAAC,EAAE,OAAO,GAAG,EAAE,OAAO,GAAG,EAAE,QAAQ,CAAC,CAAC,EAAE,SAAS;AAClE,CAAC;AAEM,IAAM,sBAAgD,EAAE,OAAO;AAAA,EACrE,SAAS,EACP,OAAO,EAAE,OAAO,GAAG,oBAAoB,EACvC,OACA,CAAC,MAAM,OAAO,KAAK,CAAC,EAAE,SAAS,GAC/B,qCACD;AAAA,EACD,SAAS,EAAE,MAAM,EAAE,MAAM,EAAE,OAAO,CAAC,CAAC,EAAE,SAAS;AAAA,EAC/C,YAAY,EAAE,MAAM,EAAE,MAAM,EAAE,OAAO,CAAC,CAAC,EAAE,SAAS;
|
|
8
|
-
"debugId": "
|
|
7
|
+
"mappings": ";;;;AAAA;AASO,IAAM,qBAAwC,EACnD,OAAO,EACP,IAAI,CAAC,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O,GAAG,EAAE,IAAI,CAAC;AACvC,CACD;AAKO,SAAS,0BAA0B,CAAC,KAAkC;AAAA,EAC5E,OAAO,yBAAyB,MAAM,GAAG;AAAA;",
|
|
8
|
+
"debugId": "6E82F2545E8F0C1F64756E2164756E21",
|
|
9
9
|
"names": []
|
|
10
10
|
}
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@secondlayer/subgraphs",
|
|
3
|
-
"version": "3.
|
|
3
|
+
"version": "3.3.0",
|
|
4
4
|
"license": "MIT",
|
|
5
5
|
"repository": {
|
|
6
6
|
"type": "git",
|
|
@@ -52,8 +52,8 @@
|
|
|
52
52
|
"prepublishOnly": "bun run build"
|
|
53
53
|
},
|
|
54
54
|
"dependencies": {
|
|
55
|
-
"@secondlayer/shared": "^6.
|
|
56
|
-
"@secondlayer/stacks": "^2.
|
|
55
|
+
"@secondlayer/shared": "^6.9.0",
|
|
56
|
+
"@secondlayer/stacks": "^2.3.0",
|
|
57
57
|
"kysely": "0.28.15",
|
|
58
58
|
"zod": "^4.3.6"
|
|
59
59
|
},
|