@secondlayer/subgraphs 4.1.4 → 4.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/src/index.d.ts +91 -31
- package/dist/src/index.js +3319 -3067
- package/dist/src/index.js.map +11 -9
- package/dist/src/runtime/block-processor.d.ts +72 -23
- package/dist/src/runtime/block-processor.js +867 -400
- package/dist/src/runtime/block-processor.js.map +9 -6
- package/dist/src/runtime/catchup.d.ts +72 -23
- package/dist/src/runtime/catchup.js +878 -411
- package/dist/src/runtime/catchup.js.map +9 -6
- package/dist/src/runtime/processor.js +943 -475
- package/dist/src/runtime/processor.js.map +10 -7
- package/dist/src/runtime/reindex.d.ts +72 -23
- package/dist/src/runtime/reindex.js +911 -444
- package/dist/src/runtime/reindex.js.map +9 -6
- package/dist/src/runtime/reorg.d.ts +72 -23
- package/dist/src/runtime/reorg.js +890 -422
- package/dist/src/runtime/reorg.js.map +10 -7
- package/dist/src/runtime/replay.js +12 -6
- package/dist/src/runtime/replay.js.map +4 -4
- package/dist/src/runtime/runner.d.ts +72 -23
- package/dist/src/runtime/runner.js +757 -28
- package/dist/src/runtime/runner.js.map +9 -5
- package/dist/src/runtime/source-matcher.d.ts +80 -24
- package/dist/src/runtime/source-matcher.js +12 -5
- package/dist/src/runtime/source-matcher.js.map +3 -3
- package/dist/src/schema/index.d.ts +72 -23
- package/dist/src/schema/index.js +115 -1
- package/dist/src/schema/index.js.map +3 -3
- package/dist/src/service.js +983 -515
- package/dist/src/service.js.map +10 -7
- package/dist/src/testing/index.d.ts +195 -24
- package/dist/src/testing/index.js +1049 -30
- package/dist/src/testing/index.js.map +10 -5
- package/dist/src/triggers/index.d.ts +83 -24
- package/dist/src/triggers/index.js +5 -2
- package/dist/src/triggers/index.js.map +3 -3
- package/dist/src/types.d.ts +73 -24
- package/dist/src/validate.d.ts +72 -23
- package/dist/src/validate.js +115 -1
- package/dist/src/validate.js.map +3 -3
- package/package.json +2 -2
package/dist/src/index.d.ts
CHANGED
|
@@ -190,7 +190,12 @@ type TraitScope = {
|
|
|
190
190
|
*
|
|
191
191
|
* ```ts
|
|
192
192
|
* sources: {
|
|
193
|
-
* registry: {
|
|
193
|
+
* registry: {
|
|
194
|
+
* type: "print_event",
|
|
195
|
+
* contractId: REGISTRY,
|
|
196
|
+
* topic: "pool-created",
|
|
197
|
+
* prints: { "pool-created": { pool: "principal" } },
|
|
198
|
+
* },
|
|
194
199
|
* swaps: {
|
|
195
200
|
* type: "print_event",
|
|
196
201
|
* topic: "swap",
|
|
@@ -315,6 +320,9 @@ interface ContractCallFilter extends TraitScope, FactoryScope {
|
|
|
315
320
|
* decoded function arguments. Dev-provided; serialized into the deployed
|
|
316
321
|
* definition and used at runtime to decode args by name. Omit to keep
|
|
317
322
|
* `event.args` as a positional `unknown[]`.
|
|
323
|
+
*
|
|
324
|
+
* Deploy validation requires `abi` whenever `functionName` is set
|
|
325
|
+
* (`normalizeAbi()` from `@secondlayer/stacks/clarity`).
|
|
318
326
|
*/
|
|
319
327
|
abi?: AbiContract2;
|
|
320
328
|
}
|
|
@@ -345,29 +353,70 @@ type PrintField = ColumnType | {
|
|
|
345
353
|
} | {
|
|
346
354
|
list: PrintField
|
|
347
355
|
};
|
|
348
|
-
|
|
349
|
-
|
|
350
|
-
|
|
351
|
-
|
|
352
|
-
|
|
353
|
-
|
|
354
|
-
|
|
355
|
-
|
|
356
|
-
|
|
357
|
-
|
|
358
|
-
|
|
359
|
-
|
|
360
|
-
|
|
361
|
-
|
|
362
|
-
|
|
363
|
-
|
|
364
|
-
|
|
365
|
-
|
|
366
|
-
|
|
367
|
-
|
|
368
|
-
|
|
369
|
-
|
|
356
|
+
/**
|
|
357
|
+
* Per-topic field schema for a print_event source. When declared, the handler's
|
|
358
|
+
* `event` is a discriminated union keyed by `topic` and `event.data` is typed
|
|
359
|
+
* per topic. Nested tuples, lists, and optional fields — see {@link PrintField}.
|
|
360
|
+
*
|
|
361
|
+
* Also opts the source into RUNTIME validation: a payload that does not match
|
|
362
|
+
* is skipped and logged rather than written as nulls.
|
|
363
|
+
*/
|
|
364
|
+
type PrintEventPrints = Record<string, Record<string, PrintField>>;
|
|
365
|
+
/**
|
|
366
|
+
* One column in a static identity map. Literals only — the bundler never
|
|
367
|
+
* executes user code, so `{ from: "tokenX" }` is valid and `from("tokenX")`
|
|
368
|
+
* is not.
|
|
369
|
+
*/
|
|
370
|
+
type MaterializeColumn = {
|
|
371
|
+
from: string
|
|
372
|
+
} | {
|
|
373
|
+
fromTx: "sender" | "txId"
|
|
374
|
+
} | {
|
|
375
|
+
fromBlock: "height" | "hash" | "timestamp"
|
|
376
|
+
};
|
|
377
|
+
/** Static insert from a source event — replaces a 1:1 handler. */
|
|
378
|
+
interface MaterializeSpec {
|
|
379
|
+
table: string;
|
|
380
|
+
/** Keys = schema column names (snake). */
|
|
381
|
+
columns: Record<string, MaterializeColumn>;
|
|
370
382
|
}
|
|
383
|
+
type PrintEventFields = FactoryScope & {
|
|
384
|
+
type: "print_event"
|
|
385
|
+
topic?: string
|
|
386
|
+
/** Identity map: insert without a handler function. XOR with handlers[name]. */
|
|
387
|
+
materialize?: MaterializeSpec
|
|
388
|
+
};
|
|
389
|
+
/**
|
|
390
|
+
* Pinned to one or more contract ids with no trait — `prints` is required so
|
|
391
|
+
* `event.data` is typed and empty-table handlers cannot typecheck.
|
|
392
|
+
*/
|
|
393
|
+
type PinnedPrintEventFilter = PrintEventFields & {
|
|
394
|
+
contractId: string | readonly string[]
|
|
395
|
+
trait?: undefined
|
|
396
|
+
prints: PrintEventPrints
|
|
397
|
+
};
|
|
398
|
+
/**
|
|
399
|
+
* Trait-scoped print source (optionally narrowed by contractId). No single
|
|
400
|
+
* schema — `prints` stays optional.
|
|
401
|
+
*/
|
|
402
|
+
type TraitPrintEventFilter = PrintEventFields & {
|
|
403
|
+
contractId?: string | readonly string[]
|
|
404
|
+
trait: string
|
|
405
|
+
prints?: PrintEventPrints
|
|
406
|
+
};
|
|
407
|
+
/**
|
|
408
|
+
* Unpinned / factory-only print source (no contractId). `prints` optional.
|
|
409
|
+
*/
|
|
410
|
+
type UnpinnedPrintEventFilter = PrintEventFields & {
|
|
411
|
+
contractId?: undefined
|
|
412
|
+
trait?: string
|
|
413
|
+
prints?: PrintEventPrints
|
|
414
|
+
};
|
|
415
|
+
/**
|
|
416
|
+
* Print-event filter. Pinned sources (contractId set, no trait) require
|
|
417
|
+
* `prints`; trait and unpinned sources may omit it.
|
|
418
|
+
*/
|
|
419
|
+
type PrintEventFilter = PinnedPrintEventFilter | TraitPrintEventFilter | UnpinnedPrintEventFilter;
|
|
371
420
|
/** All subgraph filter types — discriminated on `type` */
|
|
372
421
|
type SubgraphFilter = StxTransferFilter | StxMintFilter | StxBurnFilter | StxLockFilter | FtTransferFilter | FtMintFilter | FtBurnFilter | NftTransferFilter | NftMintFilter | NftBurnFilter | ContractCallFilter | ContractDeployFilter | PrintEventFilter;
|
|
373
422
|
/** Transaction metadata available in handlers */
|
|
@@ -909,19 +958,25 @@ type EventForFilter<F extends SubgraphFilter> = F extends {
|
|
|
909
958
|
} ? ContractDeployPayload : never;
|
|
910
959
|
/** Union of every event payload — the `"*"` catch-all handler receives this. */
|
|
911
960
|
type AnyEvent = FtTransferPayload | FtMintPayload | FtBurnPayload | NftTransferPayload | NftMintPayload | NftBurnPayload | StxTransferPayload | StxMintPayload | StxBurnPayload | StxLockPayload | PrintEventPayload | ContractCallEvent | ContractDeployPayload;
|
|
961
|
+
type HandlerFn<
|
|
962
|
+
F extends SubgraphFilter,
|
|
963
|
+
S extends SubgraphSchema
|
|
964
|
+
> = (event: EventForFilter<F>, ctx: TypedSubgraphContext<S>) => void | Promise<void>;
|
|
965
|
+
type SourceHasMaterialize<F> = F extends {
|
|
966
|
+
materialize: MaterializeSpec
|
|
967
|
+
} ? true : false;
|
|
912
968
|
/**
|
|
913
969
|
* Handlers keyed by source name. Each handler's `event` is typed from the
|
|
914
970
|
* matching source's filter `type` (e.g. a `print_event` source → `event.topic`
|
|
915
971
|
* is a `string`), and `ctx` is typed against the subgraph `schema` (table
|
|
916
|
-
* names + row columns checked).
|
|
917
|
-
*
|
|
918
|
-
*
|
|
919
|
-
* runtime), matching `handlers[name] ?? handlers["*"]` resolution.
|
|
972
|
+
* names + row columns checked). Sources with `materialize` may omit a
|
|
973
|
+
* handler; every other source key is required. Optional `"*"` catch-all
|
|
974
|
+
* receives any event (validate also accepts `*` alone).
|
|
920
975
|
*/
|
|
921
976
|
type TypedHandlers<
|
|
922
977
|
Sources extends Record<string, SubgraphFilter>,
|
|
923
978
|
S extends SubgraphSchema
|
|
924
|
-
> = { [K in keyof Sources]? :
|
|
979
|
+
> = { [K in keyof Sources as SourceHasMaterialize<Sources[K]> extends true ? never : K]-? : HandlerFn<Sources[K], S> } & { [K in keyof Sources as SourceHasMaterialize<Sources[K]> extends true ? K : never]? : HandlerFn<Sources[K], S> } & {
|
|
925
980
|
"*"?: (event: AnyEvent, ctx: TypedSubgraphContext<S>) => void | Promise<void>
|
|
926
981
|
};
|
|
927
982
|
/** Subgraph definition with `sources`/`schema` literals preserved for typed
|
|
@@ -1046,10 +1101,15 @@ interface InferredTopicSchema {
|
|
|
1046
1101
|
fields: InferredPrintField[];
|
|
1047
1102
|
}
|
|
1048
1103
|
/**
|
|
1049
|
-
* Kebab-case → camelCase
|
|
1050
|
-
*
|
|
1104
|
+
* Kebab-case → camelCase for print tuple keys. Canonical: the runner uses
|
|
1105
|
+
* this on `event.data`, and `camel_name` in inferred print schema is the
|
|
1106
|
+
* same function. Distinct from ABI `toCamelCase` (`transfer-STX` stays
|
|
1107
|
+
* `transfer-STX` here, becomes `transferSTX` there).
|
|
1051
1108
|
*/
|
|
1052
1109
|
declare function camelizeDataKey(str: string): string;
|
|
1110
|
+
/** Recursively camelize object keys with the print-payload helper (not ABI
|
|
1111
|
+
* `toCamelCase` — that one strips `-STX` and prefixes leading digits). */
|
|
1112
|
+
declare function camelizeKeys(obj: unknown): unknown;
|
|
1053
1113
|
/**
|
|
1054
1114
|
* Infers per-topic field schemas from sampled print events. Counts and
|
|
1055
1115
|
* height bounds cover ALL rows of a topic (cheap); only a bounded subset is
|
|
@@ -1208,4 +1268,4 @@ declare function deploySchema(db: AnyDb, def: SubgraphDefinition, handlerPath: s
|
|
|
1208
1268
|
/** Non-fatal caveats the caller should surface (e.g. handler grafts at tip). */
|
|
1209
1269
|
warnings?: string[]
|
|
1210
1270
|
}>;
|
|
1211
|
-
export { validateSubgraphDefinition, validatePrintPayload, sparseProbeTargets, resumeReindex, renderDeployPlan, reindexSubgraph, readContractAt, pgSchemaName, inferPrintTopics, hasBreakingChanges, generateSubgraphSQL, generatePrismaSchema, generateKyselySchema, generateIndexSchema, generateDrizzleSchema, filterFieldsByType, diffSchema, deploySchema, defineSubgraph, defineSchema, canSparseScan, camelizeDataKey, backfillSubgraph, WriteRow, WhereInput, TypedSubgraphDefinition, TypedSubgraphContext, TypedHandlers, TxMeta, TableDiff, SystemRow, SubscribeOptions, SubgraphTableClient, SubgraphTable, SubgraphSchema, SubgraphHandler, SubgraphFilter, SubgraphDefinition, SubgraphContext, SubgraphColumn, StxTransferPayload, StxTransferFilter, StxMintPayload, StxMintFilter, StxLockPayload, StxLockFilter, StxBurnPayload, StxBurnFilter, SparseProbeTarget, RowValue, ReindexOptions, PrismaGenOptions, PrintValidationResult, PrintSample, PrintFieldToTS, PrintField, PrintEventPayload, PrintEventFor, PrintEventFilter, PrintDataOf, NftTransferPayload, NftTransferFilter, NftMintPayload, NftMintFilter, NftBurnPayload, NftBurnFilter, KyselyGenOptions, InferredTopicSchema, InferredPrintField, InferTableRow, InferSubgraphClient, InferContext, InferColumnType, IndexCodegenTarget, IndexCodegenOptions, INDEX_CODEGEN_TABLES, GeneratedSQL, FtTransferPayload, FtTransferFilter, FtMintPayload, FtMintFilter, FtBurnPayload, FtBurnFilter, FindManyOptions, FactoryScope, EventForFilter, ErasedChainReadClient, DrizzleGenOptions, DeployPlan, DeployDiff, ContractDeployPayload, ContractDeployFilter, ContractCallPayload, ContractCallFilter, ContractCallEvent, ComputedValue, ComparisonFilter, ColumnType, ColumnToTS, ColumnDiff, ChainReadOptions, ChainReadMethods, ChainReadError, ChainReadClient, ChainReadCacheMode, AnyEvent, AggregateSpec, AggregateResult };
|
|
1271
|
+
export { validateSubgraphDefinition, validatePrintPayload, sparseProbeTargets, resumeReindex, renderDeployPlan, reindexSubgraph, readContractAt, pgSchemaName, inferPrintTopics, hasBreakingChanges, generateSubgraphSQL, generatePrismaSchema, generateKyselySchema, generateIndexSchema, generateDrizzleSchema, filterFieldsByType, diffSchema, deploySchema, defineSubgraph, defineSchema, canSparseScan, camelizeKeys, camelizeDataKey, backfillSubgraph, WriteRow, WhereInput, UnpinnedPrintEventFilter, TypedSubgraphDefinition, TypedSubgraphContext, TypedHandlers, TxMeta, TraitPrintEventFilter, TableDiff, SystemRow, SubscribeOptions, SubgraphTableClient, SubgraphTable, SubgraphSchema, SubgraphHandler, SubgraphFilter, SubgraphDefinition, SubgraphContext, SubgraphColumn, StxTransferPayload, StxTransferFilter, StxMintPayload, StxMintFilter, StxLockPayload, StxLockFilter, StxBurnPayload, StxBurnFilter, SparseProbeTarget, RowValue, ReindexOptions, PrismaGenOptions, PrintValidationResult, PrintSample, PrintFieldToTS, PrintField, PrintEventPrints, PrintEventPayload, PrintEventFor, PrintEventFilter, PrintDataOf, PinnedPrintEventFilter, NftTransferPayload, NftTransferFilter, NftMintPayload, NftMintFilter, NftBurnPayload, NftBurnFilter, MaterializeSpec, MaterializeColumn, KyselyGenOptions, InferredTopicSchema, InferredPrintField, InferTableRow, InferSubgraphClient, InferContext, InferColumnType, IndexCodegenTarget, IndexCodegenOptions, INDEX_CODEGEN_TABLES, GeneratedSQL, FtTransferPayload, FtTransferFilter, FtMintPayload, FtMintFilter, FtBurnPayload, FtBurnFilter, FindManyOptions, FactoryScope, EventForFilter, ErasedChainReadClient, DrizzleGenOptions, DeployPlan, DeployDiff, ContractDeployPayload, ContractDeployFilter, ContractCallPayload, ContractCallFilter, ContractCallEvent, ComputedValue, ComparisonFilter, ColumnType, ColumnToTS, ColumnDiff, ChainReadOptions, ChainReadMethods, ChainReadError, ChainReadClient, ChainReadCacheMode, AnyEvent, AggregateSpec, AggregateResult };
|