@secondlayer/subgraphs 3.11.0 → 3.13.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 +36 -1
- package/dist/src/index.js +542 -180
- package/dist/src/index.js.map +12 -12
- package/dist/src/runtime/block-processor.d.ts +34 -1
- package/dist/src/runtime/block-processor.js +501 -72
- package/dist/src/runtime/block-processor.js.map +9 -8
- package/dist/src/runtime/catchup.d.ts +10 -0
- package/dist/src/runtime/catchup.js +520 -118
- package/dist/src/runtime/catchup.js.map +10 -9
- package/dist/src/runtime/context.d.ts +65 -3
- package/dist/src/runtime/context.js +390 -8
- package/dist/src/runtime/context.js.map +6 -4
- package/dist/src/runtime/processor.js +590 -230
- package/dist/src/runtime/processor.js.map +13 -13
- package/dist/src/runtime/reindex.d.ts +14 -0
- package/dist/src/runtime/reindex.js +538 -180
- package/dist/src/runtime/reindex.js.map +10 -10
- package/dist/src/runtime/reorg.d.ts +10 -0
- package/dist/src/runtime/reorg.js +521 -73
- package/dist/src/runtime/reorg.js.map +10 -9
- package/dist/src/runtime/replay.js.map +2 -2
- package/dist/src/runtime/runner.d.ts +73 -2
- package/dist/src/runtime/runner.js +56 -58
- package/dist/src/runtime/runner.js.map +3 -3
- package/dist/src/runtime/source-matcher.d.ts +2 -0
- package/dist/src/runtime/source-matcher.js.map +2 -2
- package/dist/src/schema/index.d.ts +10 -0
- package/dist/src/schema/index.js +19 -1
- package/dist/src/schema/index.js.map +5 -5
- package/dist/src/service.js +590 -230
- package/dist/src/service.js.map +13 -13
- package/dist/src/types.d.ts +10 -0
- package/dist/src/validate.d.ts +10 -0
- package/dist/src/validate.js +2 -1
- package/dist/src/validate.js.map +3 -3
- package/package.json +2 -2
|
@@ -2,7 +2,7 @@
|
|
|
2
2
|
"version": 3,
|
|
3
3
|
"sources": ["../src/runtime/source-matcher.ts", "../src/runtime/replay.ts", "../src/schema/utils.ts", "../src/runtime/block-source.ts", "../src/runtime/batch-loader.ts", "../src/runtime/reconstruct.ts", "../src/runtime/trigger-evaluator.ts"],
|
|
4
4
|
"sourcesContent": [
|
|
5
|
-
"import type { SubgraphFilter } from \"../types.ts\";\n\nexport interface MatchedTx {\n\ttx: TxRecord;\n\tevents: EventRecord[];\n\t/** Source object key — used for handler dispatch */\n\tsourceName: string;\n}\n\ntype TxRecord = {\n\ttx_id: string;\n\ttype: string;\n\tsender: string;\n\tstatus: string;\n\tcontract_id?: string | null;\n\tfunction_name?: string | null;\n\tfunction_args?: unknown | null;\n\traw_result?: string | null;\n};\n\ntype EventRecord = {\n\tid: string;\n\ttx_id: string;\n\ttype: string;\n\tevent_index: number;\n\tdata: unknown;\n};\n\n// ── Wildcard matching (shared with v1) ──────────────────────────────\n\nconst patternCache = new Map<string, RegExp>();\n\nfunction matchPattern(value: string, pattern: string): boolean {\n\tif (!pattern.includes(\"*\")) return value === pattern;\n\tlet re = patternCache.get(pattern);\n\tif (!re) {\n\t\tconst regex = pattern\n\t\t\t.replace(/[.+^${}()|[\\]\\\\]/g, \"\\\\$&\")\n\t\t\t.replace(/\\*/g, \".*\");\n\t\tre = new RegExp(`^${regex}$`);\n\t\tpatternCache.set(pattern, re);\n\t}\n\treturn re.test(value);\n}\n\n// Trait → set of conforming contract IDs, resolved per block by the caller\n// (block-processor) from the contract registry. Kept as injected data so this\n// module stays pure/sync/DB-less.\nexport type TraitContracts = Map<string, ReadonlySet<string>>;\nconst EMPTY_SET: ReadonlySet<string> = new Set();\n\n/**\n * True when a filter's optional `trait` admits this contract: no trait → always\n * allowed; trait set → the contract must be in the resolved conforming set.\n */\nfunction traitAllows(\n\tfilter: SubgraphFilter,\n\tcontractId: string | undefined | null,\n\ttraitContracts: TraitContracts,\n): boolean {\n\tconst trait = (filter as { trait?: string }).trait;\n\tif (!trait) return true;\n\tif (!contractId) return false;\n\treturn (traitContracts.get(trait) ?? EMPTY_SET).has(contractId);\n}\n\n/** Extract the contract id from an asset identifier (`<contract>::<token>`). */\nfunction assetContract(assetId: string | undefined): string | undefined {\n\treturn assetId?.split(\"::\")[0];\n}\n\n// ── Per-filter-type matchers ────────────────────────────────────────\n\nfunction matchFilter(\n\tfilter: SubgraphFilter,\n\ttransactions: TxRecord[],\n\teventsByTx: Map<string, EventRecord[]>,\n\ttraitContracts: TraitContracts,\n): { tx: TxRecord; events: EventRecord[] }[] {\n\tconst results: { tx: TxRecord; events: EventRecord[] }[] = [];\n\n\tswitch (filter.type) {\n\t\t// ── STX events ──\n\t\tcase \"stx_transfer\":\n\t\tcase \"stx_mint\":\n\t\tcase \"stx_burn\":\n\t\tcase \"stx_lock\": {\n\t\t\tconst eventType = `${filter.type}_event`;\n\t\t\tfor (const tx of transactions) {\n\t\t\t\tconst txEvents = eventsByTx.get(tx.tx_id) ?? [];\n\t\t\t\tconst matched = txEvents.filter((e) => e.type === eventType);\n\t\t\t\tif (matched.length === 0) continue;\n\n\t\t\t\t// Apply address filters\n\t\t\t\tconst filtered = matched.filter((e) => {\n\t\t\t\t\tconst data = e.data as Record<string, unknown> | null;\n\t\t\t\t\tif (!data) return false;\n\t\t\t\t\tif (\"sender\" in filter && filter.sender) {\n\t\t\t\t\t\tif (!matchPattern(data.sender as string, filter.sender))\n\t\t\t\t\t\t\treturn false;\n\t\t\t\t\t}\n\t\t\t\t\tif (\"recipient\" in filter && filter.recipient) {\n\t\t\t\t\t\tif (!matchPattern(data.recipient as string, filter.recipient))\n\t\t\t\t\t\t\treturn false;\n\t\t\t\t\t}\n\t\t\t\t\tif (\"lockedAddress\" in filter && filter.lockedAddress) {\n\t\t\t\t\t\tif (\n\t\t\t\t\t\t\t!matchPattern(data.locked_address as string, filter.lockedAddress)\n\t\t\t\t\t\t)\n\t\t\t\t\t\t\treturn false;\n\t\t\t\t\t}\n\t\t\t\t\t// Amount filters\n\t\t\t\t\tif (\"minAmount\" in filter && filter.minAmount !== undefined) {\n\t\t\t\t\t\tconst amount = BigInt(\n\t\t\t\t\t\t\t(data.amount ?? data.locked_amount ?? \"0\") as string,\n\t\t\t\t\t\t);\n\t\t\t\t\t\tif (amount < filter.minAmount) return false;\n\t\t\t\t\t}\n\t\t\t\t\tif (\n\t\t\t\t\t\t\"maxAmount\" in filter &&\n\t\t\t\t\t\t(filter as { maxAmount?: bigint }).maxAmount !== undefined\n\t\t\t\t\t) {\n\t\t\t\t\t\tconst amount = BigInt((data.amount ?? \"0\") as string);\n\t\t\t\t\t\tif (amount > (filter as { maxAmount: bigint }).maxAmount)\n\t\t\t\t\t\t\treturn false;\n\t\t\t\t\t}\n\t\t\t\t\treturn true;\n\t\t\t\t});\n\n\t\t\t\tif (filtered.length > 0) {\n\t\t\t\t\tresults.push({ tx, events: filtered });\n\t\t\t\t}\n\t\t\t}\n\t\t\tbreak;\n\t\t}\n\n\t\t// ── FT events ──\n\t\tcase \"ft_transfer\":\n\t\tcase \"ft_mint\":\n\t\tcase \"ft_burn\": {\n\t\t\tconst eventType = `${filter.type}_event`;\n\t\t\tfor (const tx of transactions) {\n\t\t\t\tconst txEvents = eventsByTx.get(tx.tx_id) ?? [];\n\t\t\t\tconst matched = txEvents.filter((e) => {\n\t\t\t\t\tif (e.type !== eventType) return false;\n\t\t\t\t\tconst data = e.data as Record<string, unknown> | null;\n\t\t\t\t\tif (!data) return false;\n\n\t\t\t\t\t// Asset identifier filter\n\t\t\t\t\tif (filter.assetIdentifier) {\n\t\t\t\t\t\tconst assetId = data.asset_identifier as string | undefined;\n\t\t\t\t\t\tif (!assetId || !matchPattern(assetId, filter.assetIdentifier))\n\t\t\t\t\t\t\treturn false;\n\t\t\t\t\t}\n\t\t\t\t\t// Trait scope — the asset's contract must conform.\n\t\t\t\t\tif (\n\t\t\t\t\t\t!traitAllows(\n\t\t\t\t\t\t\tfilter,\n\t\t\t\t\t\t\tassetContract(data.asset_identifier as string | undefined),\n\t\t\t\t\t\t\ttraitContracts,\n\t\t\t\t\t\t)\n\t\t\t\t\t)\n\t\t\t\t\t\treturn false;\n\t\t\t\t\t// Address filters\n\t\t\t\t\tif (\"sender\" in filter && filter.sender) {\n\t\t\t\t\t\tif (!matchPattern(data.sender as string, filter.sender))\n\t\t\t\t\t\t\treturn false;\n\t\t\t\t\t}\n\t\t\t\t\tif (\"recipient\" in filter && filter.recipient) {\n\t\t\t\t\t\tif (!matchPattern(data.recipient as string, filter.recipient))\n\t\t\t\t\t\t\treturn false;\n\t\t\t\t\t}\n\t\t\t\t\t// Amount filter\n\t\t\t\t\tif (filter.minAmount !== undefined) {\n\t\t\t\t\t\tconst amount = BigInt((data.amount ?? \"0\") as string);\n\t\t\t\t\t\tif (amount < filter.minAmount) return false;\n\t\t\t\t\t}\n\t\t\t\t\treturn true;\n\t\t\t\t});\n\n\t\t\t\tif (matched.length > 0) {\n\t\t\t\t\tresults.push({ tx, events: matched });\n\t\t\t\t}\n\t\t\t}\n\t\t\tbreak;\n\t\t}\n\n\t\t// ── NFT events ──\n\t\tcase \"nft_transfer\":\n\t\tcase \"nft_mint\":\n\t\tcase \"nft_burn\": {\n\t\t\tconst eventType = `${filter.type}_event`;\n\t\t\tfor (const tx of transactions) {\n\t\t\t\tconst txEvents = eventsByTx.get(tx.tx_id) ?? [];\n\t\t\t\tconst matched = txEvents.filter((e) => {\n\t\t\t\t\tif (e.type !== eventType) return false;\n\t\t\t\t\tconst data = e.data as Record<string, unknown> | null;\n\t\t\t\t\tif (!data) return false;\n\n\t\t\t\t\tif (filter.assetIdentifier) {\n\t\t\t\t\t\tconst assetId = data.asset_identifier as string | undefined;\n\t\t\t\t\t\tif (!assetId || !matchPattern(assetId, filter.assetIdentifier))\n\t\t\t\t\t\t\treturn false;\n\t\t\t\t\t}\n\t\t\t\t\tif (\n\t\t\t\t\t\t!traitAllows(\n\t\t\t\t\t\t\tfilter,\n\t\t\t\t\t\t\tassetContract(data.asset_identifier as string | undefined),\n\t\t\t\t\t\t\ttraitContracts,\n\t\t\t\t\t\t)\n\t\t\t\t\t)\n\t\t\t\t\t\treturn false;\n\t\t\t\t\tif (\"sender\" in filter && filter.sender) {\n\t\t\t\t\t\tif (!matchPattern(data.sender as string, filter.sender))\n\t\t\t\t\t\t\treturn false;\n\t\t\t\t\t}\n\t\t\t\t\tif (\"recipient\" in filter && filter.recipient) {\n\t\t\t\t\t\tif (!matchPattern(data.recipient as string, filter.recipient))\n\t\t\t\t\t\t\treturn false;\n\t\t\t\t\t}\n\t\t\t\t\treturn true;\n\t\t\t\t});\n\n\t\t\t\tif (matched.length > 0) {\n\t\t\t\t\tresults.push({ tx, events: matched });\n\t\t\t\t}\n\t\t\t}\n\t\t\tbreak;\n\t\t}\n\n\t\t// ── Contract call ──\n\t\tcase \"contract_call\": {\n\t\t\tfor (const tx of transactions) {\n\t\t\t\tif (tx.type !== \"contract_call\") continue;\n\n\t\t\t\t// Contract filter\n\t\t\t\tif (filter.contractId) {\n\t\t\t\t\tif (\n\t\t\t\t\t\t!tx.contract_id ||\n\t\t\t\t\t\t!matchPattern(tx.contract_id, filter.contractId)\n\t\t\t\t\t)\n\t\t\t\t\t\tcontinue;\n\t\t\t\t}\n\t\t\t\t// Function filter\n\t\t\t\tif (filter.functionName) {\n\t\t\t\t\tif (\n\t\t\t\t\t\t!tx.function_name ||\n\t\t\t\t\t\t!matchPattern(tx.function_name, filter.functionName)\n\t\t\t\t\t)\n\t\t\t\t\t\tcontinue;\n\t\t\t\t}\n\t\t\t\t// Caller filter\n\t\t\t\tif (filter.caller) {\n\t\t\t\t\tif (!matchPattern(tx.sender, filter.caller)) continue;\n\t\t\t\t}\n\t\t\t\t// Trait scope — the called contract must conform.\n\t\t\t\tif (!traitAllows(filter, tx.contract_id, traitContracts)) continue;\n\n\t\t\t\tconst txEvents = eventsByTx.get(tx.tx_id) ?? [];\n\t\t\t\tresults.push({ tx, events: txEvents });\n\t\t\t}\n\t\t\tbreak;\n\t\t}\n\n\t\t// ── Contract deploy ──\n\t\tcase \"contract_deploy\": {\n\t\t\tfor (const tx of transactions) {\n\t\t\t\tif (tx.type !== \"smart_contract\") continue;\n\n\t\t\t\tif (filter.deployer) {\n\t\t\t\t\tif (!matchPattern(tx.sender, filter.deployer)) continue;\n\t\t\t\t}\n\t\t\t\tif (filter.contractName) {\n\t\t\t\t\tconst name = tx.contract_id?.split(\".\")[1] ?? \"\";\n\t\t\t\t\tif (!matchPattern(name, filter.contractName)) continue;\n\t\t\t\t}\n\n\t\t\t\tconst txEvents = eventsByTx.get(tx.tx_id) ?? [];\n\t\t\t\tresults.push({ tx, events: txEvents });\n\t\t\t}\n\t\t\tbreak;\n\t\t}\n\n\t\t// ── Print event ──\n\t\tcase \"print_event\": {\n\t\t\tfor (const tx of transactions) {\n\t\t\t\tconst txEvents = eventsByTx.get(tx.tx_id) ?? [];\n\t\t\t\tconst matched = txEvents.filter((e) => {\n\t\t\t\t\tif (e.type !== \"smart_contract_event\" && e.type !== \"contract_event\")\n\t\t\t\t\t\treturn false;\n\t\t\t\t\tconst data = e.data as Record<string, unknown> | null;\n\t\t\t\t\tif (!data) return false;\n\t\t\t\t\tif (data.topic !== \"print\") return false;\n\n\t\t\t\t\t// Contract filter — events store the contract under either\n\t\t\t\t\t// `contract_identifier` (legacy smart_contract_event payload)\n\t\t\t\t\t// or `contract_id` (current contract_event payload). Mirror\n\t\t\t\t\t// the streams query which checks both shapes.\n\t\t\t\t\tconst printContractId =\n\t\t\t\t\t\t(data.contract_identifier as string | undefined) ??\n\t\t\t\t\t\t(data.contract_id as string | undefined);\n\t\t\t\t\tif (filter.contractId) {\n\t\t\t\t\t\tif (\n\t\t\t\t\t\t\t!printContractId ||\n\t\t\t\t\t\t\t!matchPattern(printContractId, filter.contractId)\n\t\t\t\t\t\t)\n\t\t\t\t\t\t\treturn false;\n\t\t\t\t\t}\n\t\t\t\t\tif (!traitAllows(filter, printContractId, traitContracts))\n\t\t\t\t\t\treturn false;\n\t\t\t\t\t// Topic filter — check the decoded Clarity value's topic field\n\t\t\t\t\t// At this stage data.value is still raw hex; topic filtering happens\n\t\t\t\t\t// after decode in the runner. For now, skip topic filtering here.\n\t\t\t\t\t// The runner will filter by topic after decoding.\n\t\t\t\t\treturn true;\n\t\t\t\t});\n\n\t\t\t\tif (matched.length > 0) {\n\t\t\t\t\tresults.push({ tx, events: matched });\n\t\t\t\t}\n\t\t\t}\n\t\t\tbreak;\n\t\t}\n\t}\n\n\treturn results;\n}\n\n/**\n * Match named filters against a block's transactions and events.\n * Returns matches with sourceName = the object key from sources.\n */\nexport function matchSources(\n\tsources: Record<string, SubgraphFilter>,\n\ttransactions: TxRecord[],\n\tevents: EventRecord[],\n\ttraitContracts: TraitContracts = new Map(),\n): MatchedTx[] {\n\t// Index events by txId\n\tconst eventsByTx = new Map<string, EventRecord[]>();\n\tfor (const event of events) {\n\t\tconst list = eventsByTx.get(event.tx_id) ?? [];\n\t\tlist.push(event);\n\t\teventsByTx.set(event.tx_id, list);\n\t}\n\n\tconst seen = new Set<string>();\n\tconst results: MatchedTx[] = [];\n\n\tfor (const [sourceName, filter] of Object.entries(sources)) {\n\t\tconst matches = matchFilter(\n\t\t\tfilter,\n\t\t\ttransactions,\n\t\t\teventsByTx,\n\t\t\ttraitContracts,\n\t\t);\n\t\tfor (const match of matches) {\n\t\t\tconst dedupeKey = `${match.tx.tx_id}:${sourceName}`;\n\t\t\tif (!seen.has(dedupeKey)) {\n\t\t\t\tseen.add(dedupeKey);\n\t\t\t\tresults.push({ ...match, sourceName });\n\t\t\t}\n\t\t}\n\t}\n\n\treturn results;\n}\n",
|
|
5
|
+
"import type { SubgraphFilter } from \"../types.ts\";\n\nexport interface MatchedTx {\n\ttx: TxRecord;\n\tevents: EventRecord[];\n\t/** Source object key — used for handler dispatch */\n\tsourceName: string;\n}\n\ntype TxRecord = {\n\ttx_id: string;\n\ttype: string;\n\tsender: string;\n\tstatus: string;\n\t/** Position within the block — the runner sorts dispatch into chain order. */\n\ttx_index?: number;\n\tcontract_id?: string | null;\n\tfunction_name?: string | null;\n\tfunction_args?: unknown | null;\n\traw_result?: string | null;\n};\n\ntype EventRecord = {\n\tid: string;\n\ttx_id: string;\n\ttype: string;\n\tevent_index: number;\n\tdata: unknown;\n};\n\n// ── Wildcard matching (shared with v1) ──────────────────────────────\n\nconst patternCache = new Map<string, RegExp>();\n\nfunction matchPattern(value: string, pattern: string): boolean {\n\tif (!pattern.includes(\"*\")) return value === pattern;\n\tlet re = patternCache.get(pattern);\n\tif (!re) {\n\t\tconst regex = pattern\n\t\t\t.replace(/[.+^${}()|[\\]\\\\]/g, \"\\\\$&\")\n\t\t\t.replace(/\\*/g, \".*\");\n\t\tre = new RegExp(`^${regex}$`);\n\t\tpatternCache.set(pattern, re);\n\t}\n\treturn re.test(value);\n}\n\n// Trait → set of conforming contract IDs, resolved per block by the caller\n// (block-processor) from the contract registry. Kept as injected data so this\n// module stays pure/sync/DB-less.\nexport type TraitContracts = Map<string, ReadonlySet<string>>;\nconst EMPTY_SET: ReadonlySet<string> = new Set();\n\n/**\n * True when a filter's optional `trait` admits this contract: no trait → always\n * allowed; trait set → the contract must be in the resolved conforming set.\n */\nfunction traitAllows(\n\tfilter: SubgraphFilter,\n\tcontractId: string | undefined | null,\n\ttraitContracts: TraitContracts,\n): boolean {\n\tconst trait = (filter as { trait?: string }).trait;\n\tif (!trait) return true;\n\tif (!contractId) return false;\n\treturn (traitContracts.get(trait) ?? EMPTY_SET).has(contractId);\n}\n\n/** Extract the contract id from an asset identifier (`<contract>::<token>`). */\nfunction assetContract(assetId: string | undefined): string | undefined {\n\treturn assetId?.split(\"::\")[0];\n}\n\n// ── Per-filter-type matchers ────────────────────────────────────────\n\nfunction matchFilter(\n\tfilter: SubgraphFilter,\n\ttransactions: TxRecord[],\n\teventsByTx: Map<string, EventRecord[]>,\n\ttraitContracts: TraitContracts,\n): { tx: TxRecord; events: EventRecord[] }[] {\n\tconst results: { tx: TxRecord; events: EventRecord[] }[] = [];\n\n\tswitch (filter.type) {\n\t\t// ── STX events ──\n\t\tcase \"stx_transfer\":\n\t\tcase \"stx_mint\":\n\t\tcase \"stx_burn\":\n\t\tcase \"stx_lock\": {\n\t\t\tconst eventType = `${filter.type}_event`;\n\t\t\tfor (const tx of transactions) {\n\t\t\t\tconst txEvents = eventsByTx.get(tx.tx_id) ?? [];\n\t\t\t\tconst matched = txEvents.filter((e) => e.type === eventType);\n\t\t\t\tif (matched.length === 0) continue;\n\n\t\t\t\t// Apply address filters\n\t\t\t\tconst filtered = matched.filter((e) => {\n\t\t\t\t\tconst data = e.data as Record<string, unknown> | null;\n\t\t\t\t\tif (!data) return false;\n\t\t\t\t\tif (\"sender\" in filter && filter.sender) {\n\t\t\t\t\t\tif (!matchPattern(data.sender as string, filter.sender))\n\t\t\t\t\t\t\treturn false;\n\t\t\t\t\t}\n\t\t\t\t\tif (\"recipient\" in filter && filter.recipient) {\n\t\t\t\t\t\tif (!matchPattern(data.recipient as string, filter.recipient))\n\t\t\t\t\t\t\treturn false;\n\t\t\t\t\t}\n\t\t\t\t\tif (\"lockedAddress\" in filter && filter.lockedAddress) {\n\t\t\t\t\t\tif (\n\t\t\t\t\t\t\t!matchPattern(data.locked_address as string, filter.lockedAddress)\n\t\t\t\t\t\t)\n\t\t\t\t\t\t\treturn false;\n\t\t\t\t\t}\n\t\t\t\t\t// Amount filters\n\t\t\t\t\tif (\"minAmount\" in filter && filter.minAmount !== undefined) {\n\t\t\t\t\t\tconst amount = BigInt(\n\t\t\t\t\t\t\t(data.amount ?? data.locked_amount ?? \"0\") as string,\n\t\t\t\t\t\t);\n\t\t\t\t\t\tif (amount < filter.minAmount) return false;\n\t\t\t\t\t}\n\t\t\t\t\tif (\n\t\t\t\t\t\t\"maxAmount\" in filter &&\n\t\t\t\t\t\t(filter as { maxAmount?: bigint }).maxAmount !== undefined\n\t\t\t\t\t) {\n\t\t\t\t\t\tconst amount = BigInt((data.amount ?? \"0\") as string);\n\t\t\t\t\t\tif (amount > (filter as { maxAmount: bigint }).maxAmount)\n\t\t\t\t\t\t\treturn false;\n\t\t\t\t\t}\n\t\t\t\t\treturn true;\n\t\t\t\t});\n\n\t\t\t\tif (filtered.length > 0) {\n\t\t\t\t\tresults.push({ tx, events: filtered });\n\t\t\t\t}\n\t\t\t}\n\t\t\tbreak;\n\t\t}\n\n\t\t// ── FT events ──\n\t\tcase \"ft_transfer\":\n\t\tcase \"ft_mint\":\n\t\tcase \"ft_burn\": {\n\t\t\tconst eventType = `${filter.type}_event`;\n\t\t\tfor (const tx of transactions) {\n\t\t\t\tconst txEvents = eventsByTx.get(tx.tx_id) ?? [];\n\t\t\t\tconst matched = txEvents.filter((e) => {\n\t\t\t\t\tif (e.type !== eventType) return false;\n\t\t\t\t\tconst data = e.data as Record<string, unknown> | null;\n\t\t\t\t\tif (!data) return false;\n\n\t\t\t\t\t// Asset identifier filter\n\t\t\t\t\tif (filter.assetIdentifier) {\n\t\t\t\t\t\tconst assetId = data.asset_identifier as string | undefined;\n\t\t\t\t\t\tif (!assetId || !matchPattern(assetId, filter.assetIdentifier))\n\t\t\t\t\t\t\treturn false;\n\t\t\t\t\t}\n\t\t\t\t\t// Trait scope — the asset's contract must conform.\n\t\t\t\t\tif (\n\t\t\t\t\t\t!traitAllows(\n\t\t\t\t\t\t\tfilter,\n\t\t\t\t\t\t\tassetContract(data.asset_identifier as string | undefined),\n\t\t\t\t\t\t\ttraitContracts,\n\t\t\t\t\t\t)\n\t\t\t\t\t)\n\t\t\t\t\t\treturn false;\n\t\t\t\t\t// Address filters\n\t\t\t\t\tif (\"sender\" in filter && filter.sender) {\n\t\t\t\t\t\tif (!matchPattern(data.sender as string, filter.sender))\n\t\t\t\t\t\t\treturn false;\n\t\t\t\t\t}\n\t\t\t\t\tif (\"recipient\" in filter && filter.recipient) {\n\t\t\t\t\t\tif (!matchPattern(data.recipient as string, filter.recipient))\n\t\t\t\t\t\t\treturn false;\n\t\t\t\t\t}\n\t\t\t\t\t// Amount filter\n\t\t\t\t\tif (filter.minAmount !== undefined) {\n\t\t\t\t\t\tconst amount = BigInt((data.amount ?? \"0\") as string);\n\t\t\t\t\t\tif (amount < filter.minAmount) return false;\n\t\t\t\t\t}\n\t\t\t\t\treturn true;\n\t\t\t\t});\n\n\t\t\t\tif (matched.length > 0) {\n\t\t\t\t\tresults.push({ tx, events: matched });\n\t\t\t\t}\n\t\t\t}\n\t\t\tbreak;\n\t\t}\n\n\t\t// ── NFT events ──\n\t\tcase \"nft_transfer\":\n\t\tcase \"nft_mint\":\n\t\tcase \"nft_burn\": {\n\t\t\tconst eventType = `${filter.type}_event`;\n\t\t\tfor (const tx of transactions) {\n\t\t\t\tconst txEvents = eventsByTx.get(tx.tx_id) ?? [];\n\t\t\t\tconst matched = txEvents.filter((e) => {\n\t\t\t\t\tif (e.type !== eventType) return false;\n\t\t\t\t\tconst data = e.data as Record<string, unknown> | null;\n\t\t\t\t\tif (!data) return false;\n\n\t\t\t\t\tif (filter.assetIdentifier) {\n\t\t\t\t\t\tconst assetId = data.asset_identifier as string | undefined;\n\t\t\t\t\t\tif (!assetId || !matchPattern(assetId, filter.assetIdentifier))\n\t\t\t\t\t\t\treturn false;\n\t\t\t\t\t}\n\t\t\t\t\tif (\n\t\t\t\t\t\t!traitAllows(\n\t\t\t\t\t\t\tfilter,\n\t\t\t\t\t\t\tassetContract(data.asset_identifier as string | undefined),\n\t\t\t\t\t\t\ttraitContracts,\n\t\t\t\t\t\t)\n\t\t\t\t\t)\n\t\t\t\t\t\treturn false;\n\t\t\t\t\tif (\"sender\" in filter && filter.sender) {\n\t\t\t\t\t\tif (!matchPattern(data.sender as string, filter.sender))\n\t\t\t\t\t\t\treturn false;\n\t\t\t\t\t}\n\t\t\t\t\tif (\"recipient\" in filter && filter.recipient) {\n\t\t\t\t\t\tif (!matchPattern(data.recipient as string, filter.recipient))\n\t\t\t\t\t\t\treturn false;\n\t\t\t\t\t}\n\t\t\t\t\treturn true;\n\t\t\t\t});\n\n\t\t\t\tif (matched.length > 0) {\n\t\t\t\t\tresults.push({ tx, events: matched });\n\t\t\t\t}\n\t\t\t}\n\t\t\tbreak;\n\t\t}\n\n\t\t// ── Contract call ──\n\t\tcase \"contract_call\": {\n\t\t\tfor (const tx of transactions) {\n\t\t\t\tif (tx.type !== \"contract_call\") continue;\n\n\t\t\t\t// Contract filter\n\t\t\t\tif (filter.contractId) {\n\t\t\t\t\tif (\n\t\t\t\t\t\t!tx.contract_id ||\n\t\t\t\t\t\t!matchPattern(tx.contract_id, filter.contractId)\n\t\t\t\t\t)\n\t\t\t\t\t\tcontinue;\n\t\t\t\t}\n\t\t\t\t// Function filter\n\t\t\t\tif (filter.functionName) {\n\t\t\t\t\tif (\n\t\t\t\t\t\t!tx.function_name ||\n\t\t\t\t\t\t!matchPattern(tx.function_name, filter.functionName)\n\t\t\t\t\t)\n\t\t\t\t\t\tcontinue;\n\t\t\t\t}\n\t\t\t\t// Caller filter\n\t\t\t\tif (filter.caller) {\n\t\t\t\t\tif (!matchPattern(tx.sender, filter.caller)) continue;\n\t\t\t\t}\n\t\t\t\t// Trait scope — the called contract must conform.\n\t\t\t\tif (!traitAllows(filter, tx.contract_id, traitContracts)) continue;\n\n\t\t\t\tconst txEvents = eventsByTx.get(tx.tx_id) ?? [];\n\t\t\t\tresults.push({ tx, events: txEvents });\n\t\t\t}\n\t\t\tbreak;\n\t\t}\n\n\t\t// ── Contract deploy ──\n\t\tcase \"contract_deploy\": {\n\t\t\tfor (const tx of transactions) {\n\t\t\t\tif (tx.type !== \"smart_contract\") continue;\n\n\t\t\t\tif (filter.deployer) {\n\t\t\t\t\tif (!matchPattern(tx.sender, filter.deployer)) continue;\n\t\t\t\t}\n\t\t\t\tif (filter.contractName) {\n\t\t\t\t\tconst name = tx.contract_id?.split(\".\")[1] ?? \"\";\n\t\t\t\t\tif (!matchPattern(name, filter.contractName)) continue;\n\t\t\t\t}\n\n\t\t\t\tconst txEvents = eventsByTx.get(tx.tx_id) ?? [];\n\t\t\t\tresults.push({ tx, events: txEvents });\n\t\t\t}\n\t\t\tbreak;\n\t\t}\n\n\t\t// ── Print event ──\n\t\tcase \"print_event\": {\n\t\t\tfor (const tx of transactions) {\n\t\t\t\tconst txEvents = eventsByTx.get(tx.tx_id) ?? [];\n\t\t\t\tconst matched = txEvents.filter((e) => {\n\t\t\t\t\tif (e.type !== \"smart_contract_event\" && e.type !== \"contract_event\")\n\t\t\t\t\t\treturn false;\n\t\t\t\t\tconst data = e.data as Record<string, unknown> | null;\n\t\t\t\t\tif (!data) return false;\n\t\t\t\t\tif (data.topic !== \"print\") return false;\n\n\t\t\t\t\t// Contract filter — events store the contract under either\n\t\t\t\t\t// `contract_identifier` (legacy smart_contract_event payload)\n\t\t\t\t\t// or `contract_id` (current contract_event payload). Mirror\n\t\t\t\t\t// the streams query which checks both shapes.\n\t\t\t\t\tconst printContractId =\n\t\t\t\t\t\t(data.contract_identifier as string | undefined) ??\n\t\t\t\t\t\t(data.contract_id as string | undefined);\n\t\t\t\t\tif (filter.contractId) {\n\t\t\t\t\t\tif (\n\t\t\t\t\t\t\t!printContractId ||\n\t\t\t\t\t\t\t!matchPattern(printContractId, filter.contractId)\n\t\t\t\t\t\t)\n\t\t\t\t\t\t\treturn false;\n\t\t\t\t\t}\n\t\t\t\t\tif (!traitAllows(filter, printContractId, traitContracts))\n\t\t\t\t\t\treturn false;\n\t\t\t\t\t// Topic filter — check the decoded Clarity value's topic field\n\t\t\t\t\t// At this stage data.value is still raw hex; topic filtering happens\n\t\t\t\t\t// after decode in the runner. For now, skip topic filtering here.\n\t\t\t\t\t// The runner will filter by topic after decoding.\n\t\t\t\t\treturn true;\n\t\t\t\t});\n\n\t\t\t\tif (matched.length > 0) {\n\t\t\t\t\tresults.push({ tx, events: matched });\n\t\t\t\t}\n\t\t\t}\n\t\t\tbreak;\n\t\t}\n\t}\n\n\treturn results;\n}\n\n/**\n * Match named filters against a block's transactions and events.\n * Returns matches with sourceName = the object key from sources.\n */\nexport function matchSources(\n\tsources: Record<string, SubgraphFilter>,\n\ttransactions: TxRecord[],\n\tevents: EventRecord[],\n\ttraitContracts: TraitContracts = new Map(),\n): MatchedTx[] {\n\t// Index events by txId\n\tconst eventsByTx = new Map<string, EventRecord[]>();\n\tfor (const event of events) {\n\t\tconst list = eventsByTx.get(event.tx_id) ?? [];\n\t\tlist.push(event);\n\t\teventsByTx.set(event.tx_id, list);\n\t}\n\n\tconst seen = new Set<string>();\n\tconst results: MatchedTx[] = [];\n\n\tfor (const [sourceName, filter] of Object.entries(sources)) {\n\t\tconst matches = matchFilter(\n\t\t\tfilter,\n\t\t\ttransactions,\n\t\t\teventsByTx,\n\t\t\ttraitContracts,\n\t\t);\n\t\tfor (const match of matches) {\n\t\t\tconst dedupeKey = `${match.tx.tx_id}:${sourceName}`;\n\t\t\tif (!seen.has(dedupeKey)) {\n\t\t\t\tseen.add(dedupeKey);\n\t\t\t\tresults.push({ ...match, sourceName });\n\t\t\t}\n\t\t}\n\t}\n\n\treturn results;\n}\n",
|
|
6
6
|
"import { createHash } from \"node:crypto\";\nimport { type Database, getTargetDb } from \"@secondlayer/shared/db\";\nimport type { Subscription } from \"@secondlayer/shared/db\";\nimport { getSubscription } from \"@secondlayer/shared/db/queries/subscriptions\";\nimport { logger } from \"@secondlayer/shared/logger\";\nimport { type Kysely, sql } from \"kysely\";\nimport { pgSchemaName as defaultSchemaName } from \"../schema/utils.ts\";\nimport { PublicApiBlockSource, buildHttpClient } from \"./block-source.ts\";\nimport {\n\tbuildSourcesMap,\n\tbuildTraitContracts,\n\temitChainOutbox,\n\tevaluateBlock,\n\treferencedEventTypes,\n} from \"./trigger-evaluator.ts\";\n\n/**\n * Replay historical subgraph rows as new outbox entries for a single\n * subscription. Rows are marked `is_replay=TRUE` so the emitter can\n * prioritize live deliveries (90/10 split) and the delivery log can\n * tag replays distinctly.\n *\n * Idempotency: `replayId` is deterministic over `(subscription_id,\n * fromBlock, toBlock)`, so re-running the same replay range is a no-op\n * thanks to the unique `(subscription_id, dedup_key)` constraint. A\n * user who actually wants to re-deliver the same range passes a\n * distinct `replayIdSuffix` (e.g. a timestamp) to get a fresh key.\n */\n\nconst BATCH_SIZE = 500;\n\nfunction replayDedupKey(\n\tsubgraphName: string,\n\ttableName: string,\n\trow: Record<string, unknown>,\n\treplayId: string,\n): string {\n\tconst canonical = `replay:${replayId}:${subgraphName}:${tableName}:${stableStringify(row)}`;\n\treturn createHash(\"sha256\").update(canonical).digest(\"hex\").slice(0, 32);\n}\n\nfunction stableStringify(obj: Record<string, unknown>): string {\n\tconst keys = Object.keys(obj).sort();\n\treturn JSON.stringify(\n\t\tkeys.reduce<Record<string, unknown>>((acc, k) => {\n\t\t\tacc[k] = obj[k];\n\t\t\treturn acc;\n\t\t}, {}),\n\t);\n}\n\nexport interface ReplayInput {\n\taccountId: string;\n\tsubscriptionId: string;\n\tfromBlock: number;\n\ttoBlock: number;\n\t/** Force re-delivery by appending a unique suffix to the replay id. */\n\treplayIdSuffix?: string;\n}\n\nfunction deterministicReplayId(\n\tsubscriptionId: string,\n\tfromBlock: number,\n\ttoBlock: number,\n\tsuffix?: string,\n): string {\n\tconst canonical = `${subscriptionId}:${fromBlock}:${toBlock}${suffix ? `:${suffix}` : \"\"}`;\n\treturn createHash(\"sha256\").update(canonical).digest(\"hex\").slice(0, 16);\n}\n\nexport interface ReplayResult {\n\treplayId: string;\n\tenqueuedCount: number;\n\tscannedCount: number;\n}\n\nasync function resolveSchemaName(\n\tdb: Kysely<Database>,\n\tsubgraphName: string,\n): Promise<string> {\n\tconst row = await db\n\t\t.selectFrom(\"subgraphs\")\n\t\t.select(\"schema_name\")\n\t\t.where(\"name\", \"=\", subgraphName)\n\t\t.executeTakeFirst();\n\tif (!row) {\n\t\tthrow new Error(\n\t\t\t`Subgraph \"${subgraphName}\" not registered — cannot replay its rows. Deploy the subgraph first.`,\n\t\t);\n\t}\n\treturn row.schema_name ?? defaultSchemaName(subgraphName);\n}\n\nexport async function replaySubscription(\n\tinput: ReplayInput,\n): Promise<ReplayResult> {\n\tif (input.fromBlock > input.toBlock) {\n\t\tthrow new Error(\"fromBlock must be <= toBlock\");\n\t}\n\tif (input.toBlock - input.fromBlock > 100_000) {\n\t\tthrow new Error(\"replay range exceeds 100k blocks\");\n\t}\n\n\tconst db = getTargetDb();\n\tconst sub = await getSubscription(db, input.accountId, input.subscriptionId);\n\tif (!sub) throw new Error(\"Subscription not found\");\n\n\t// Chain subs have no processed table — they react to raw chain events. Replay\n\t// re-runs the pure matcher over the canonical block range instead of scanning\n\t// rows.\n\tif (sub.kind === \"chain\") {\n\t\treturn replayChainSubscription(db, sub, input);\n\t}\n\n\tconst subgraphName = sub.subgraph_name;\n\tconst tableName = sub.table_name;\n\tif (sub.kind !== \"subgraph\" || !subgraphName || !tableName) {\n\t\tthrow new Error(\n\t\t\t\"replay is only supported for subgraph or chain subscriptions\",\n\t\t);\n\t}\n\n\tconst schema = await resolveSchemaName(db, subgraphName);\n\tconst replayId = deterministicReplayId(\n\t\tsub.id,\n\t\tinput.fromBlock,\n\t\tinput.toBlock,\n\t\tinput.replayIdSuffix,\n\t);\n\n\tlet scanned = 0;\n\tlet enqueued = 0;\n\tlet offset = 0;\n\n\twhile (true) {\n\t\tconst { rows } = await sql<\n\t\t\tRecord<string, unknown>\n\t\t>`SELECT * FROM ${sql.raw(`\"${schema}\".\"${tableName}\"`)}\n\t\t\tWHERE _block_height >= ${sql.lit(input.fromBlock)}\n\t\t\t\tAND _block_height <= ${sql.lit(input.toBlock)}\n\t\t\tORDER BY _block_height, _created_at\n\t\t\tLIMIT ${sql.lit(BATCH_SIZE)} OFFSET ${sql.lit(offset)}`.execute(db);\n\n\t\tif (rows.length === 0) break;\n\t\tscanned += rows.length;\n\n\t\tconst inserts = rows.map((row) => ({\n\t\t\tsubscription_id: sub.id,\n\t\t\tsubgraph_name: subgraphName,\n\t\t\ttable_name: tableName,\n\t\t\tblock_height: Number(row._block_height),\n\t\t\ttx_id: (row._tx_id as string | undefined) ?? null,\n\t\t\trow_pk: {\n\t\t\t\tblockHeight: Number(row._block_height),\n\t\t\t\ttxId: row._tx_id ?? \"\",\n\t\t\t\treplayId,\n\t\t\t},\n\t\t\tevent_type: `${subgraphName}.${tableName}.replay`,\n\t\t\tpayload: row,\n\t\t\tdedup_key: replayDedupKey(subgraphName, tableName, row, replayId),\n\t\t\tis_replay: true,\n\t\t}));\n\n\t\tconst result = await db\n\t\t\t.insertInto(\"subscription_outbox\")\n\t\t\t.values(inserts)\n\t\t\t.onConflict((oc) =>\n\t\t\t\toc.columns([\"subscription_id\", \"dedup_key\"]).doNothing(),\n\t\t\t)\n\t\t\t.executeTakeFirst();\n\t\tenqueued += Number(result.numInsertedOrUpdatedRows ?? 0);\n\n\t\tif (rows.length < BATCH_SIZE) break;\n\t\toffset += BATCH_SIZE;\n\t}\n\n\tlogger.info(\"Replay enqueued\", {\n\t\tsubscription: sub.name,\n\t\treplayId,\n\t\tscanned,\n\t\tenqueued,\n\t\tfromBlock: input.fromBlock,\n\t\ttoBlock: input.toBlock,\n\t});\n\n\treturn { replayId, enqueuedCount: enqueued, scannedCount: scanned };\n}\n\nconst CHAIN_REPLAY_BATCH = 200;\n\n/**\n * Replay a chain subscription by re-running the pure matcher over a historical\n * canonical block range and emitting fresh apply rows. Unlike subgraph replay\n * there is no processed table to scan — the matcher is range-driven, so we\n * reload canonical blocks off the public Index/Streams clock and re-match.\n *\n * Rows are emitted with `is_replay=TRUE` and replay-namespaced dedup keys, and —\n * critically — this never advances `trigger_evaluator_state`: replay is\n * historical and must not move the live forward cursor.\n */\nasync function replayChainSubscription(\n\tdb: Kysely<Database>,\n\tsub: Subscription,\n\tinput: ReplayInput,\n): Promise<ReplayResult> {\n\tconst replayId = deterministicReplayId(\n\t\tsub.id,\n\t\tinput.fromBlock,\n\t\tinput.toBlock,\n\t\tinput.replayIdSuffix,\n\t);\n\n\tconst { sources, keyMeta } = buildSourcesMap([sub]);\n\tconst source = new PublicApiBlockSource(\n\t\tbuildHttpClient(),\n\t\treferencedEventTypes([sub]),\n\t);\n\n\tlet scanned = 0;\n\tlet enqueued = 0;\n\tfor (\n\t\tlet from = input.fromBlock;\n\t\tfrom <= input.toBlock;\n\t\tfrom += CHAIN_REPLAY_BATCH\n\t) {\n\t\tconst to = Math.min(from + CHAIN_REPLAY_BATCH - 1, input.toBlock);\n\t\tconst blocks = await source.loadBlockRange(from, to);\n\t\t// Trait membership only grows; resolve once per batch as of its top height.\n\t\tconst traitContracts = await buildTraitContracts(db, [sub], to);\n\t\tfor (let h = from; h <= to; h++) {\n\t\t\tconst bd = blocks.get(h);\n\t\t\tif (!bd) continue;\n\t\t\tscanned++;\n\t\t\tconst matches = evaluateBlock(bd, sources, traitContracts);\n\t\t\tif (matches.length === 0) continue;\n\t\t\tenqueued += await emitChainOutbox(\n\t\t\t\tdb,\n\t\t\t\tmatches,\n\t\t\t\tkeyMeta,\n\t\t\t\th,\n\t\t\t\tbd.block.hash,\n\t\t\t\t{\n\t\t\t\t\treplayId,\n\t\t\t\t},\n\t\t\t);\n\t\t}\n\t}\n\n\tlogger.info(\"Chain replay enqueued\", {\n\t\tsubscription: sub.name,\n\t\treplayId,\n\t\tscanned,\n\t\tenqueued,\n\t\tfromBlock: input.fromBlock,\n\t\ttoBlock: input.toBlock,\n\t});\n\n\treturn { replayId, enqueuedCount: enqueued, scannedCount: scanned };\n}\n",
|
|
7
7
|
"// Re-export canonical pgSchemaName from shared\nexport { pgSchemaName } from \"@secondlayer/shared/db/queries/subgraphs\";\n",
|
|
8
8
|
"import { getSourceDb } from \"@secondlayer/shared/db\";\nimport { IndexHttpClient } from \"@secondlayer/shared/index-http\";\nimport { logger } from \"@secondlayer/shared/logger\";\nimport type { SubgraphDefinition, SubgraphFilter } from \"../types.ts\";\nimport { type BlockData, loadBlockRange } from \"./batch-loader.ts\";\nimport {\n\treconstructBlock,\n\treconstructEvent,\n\treconstructTransaction,\n} from \"./reconstruct.ts\";\n\n/**\n * Where the subgraph runtime reads canonical chain data. Today it taps the\n * indexer Postgres directly (`PostgresBlockSource`); the re-point adds a\n * `PublicApiBlockSource` that consumes the Streams clock + Index data over\n * HTTP. `matchSources` / handlers / flush / outbox are unchanged — only the\n * loader + tip swap behind this seam.\n */\nexport interface BlockSource {\n\t/** Highest canonical block height available to process. */\n\tgetTip(): Promise<number>;\n\t/** Canonical block data for [fromHeight, toHeight], keyed by height. */\n\tloadBlockRange(\n\t\tfromHeight: number,\n\t\ttoHeight: number,\n\t): Promise<Map<number, BlockData>>;\n\t/** Sparse-scan probe: lowest height in (afterHeight, untilHeight] holding\n\t * an event this source's subgraph could match, or null when the rest of\n\t * the range is empty. Optional — only event-scoped sources support it. */\n\tnextDataHeight?(\n\t\tafterHeight: number,\n\t\tuntilHeight: number,\n\t): Promise<number | null>;\n}\n\n/** A (decoded event type, optional contract scope) pair the sparse probe\n * checks. Contract scoping is what makes token-subgraph reindexes leap over\n * everything that isn't their token. */\nexport type SparseProbeTarget = { eventType: string; contractId?: string };\n\n/** Sparse scanning is sound only when EVERY source is an event-type filter —\n * a contract_call/contract_deploy source matches transactions, which the\n * event probe can't see. */\nexport function canSparseScan(subgraph: SubgraphDefinition): boolean {\n\tif (Array.isArray(subgraph.sources)) return false;\n\tconst filters = sourceFilters(subgraph);\n\tif (filters.length === 0) return false;\n\treturn filters.every((f) => Boolean(EVENT_FILTER_TO_INDEX_TYPE[f.type]));\n}\n\n/** Probe targets for a subgraph's filters: decoded type + contract scope when\n * the filter pins one (assetIdentifier \"SP….contract::asset\" or contractId). */\nexport function sparseProbeTargets(\n\tsubgraph: SubgraphDefinition,\n): SparseProbeTarget[] {\n\tconst targets = new Map<string, SparseProbeTarget>();\n\tfor (const f of sourceFilters(subgraph)) {\n\t\tconst eventType = EVENT_FILTER_TO_INDEX_TYPE[f.type];\n\t\tif (!eventType) continue;\n\t\tconst scoped = f as { assetIdentifier?: string; contractId?: string };\n\t\tconst contractId =\n\t\t\tscoped.contractId ?? scoped.assetIdentifier?.split(\"::\")[0];\n\t\tconst key = `${eventType}|${contractId ?? \"\"}`;\n\t\ttargets.set(key, { eventType, ...(contractId ? { contractId } : {}) });\n\t}\n\treturn [...targets.values()];\n}\n\n/** Reads directly from the shared indexer Postgres (the original behavior). */\nexport class PostgresBlockSource implements BlockSource {\n\tasync getTip(): Promise<number> {\n\t\tconst progress = await getSourceDb()\n\t\t\t.selectFrom(\"index_progress\")\n\t\t\t.selectAll()\n\t\t\t.where(\"network\", \"=\", process.env.NETWORK ?? \"mainnet\")\n\t\t\t.executeTakeFirst();\n\t\treturn progress ? Number(progress.highest_seen_block) : 0;\n\t}\n\n\tloadBlockRange(\n\t\tfromHeight: number,\n\t\ttoHeight: number,\n\t): Promise<Map<number, BlockData>> {\n\t\treturn loadBlockRange(getSourceDb(), fromHeight, toHeight);\n\t}\n}\n\n// Subgraph source filter types that map to a decoded Index event_type. The\n// `_event` suffix is the runtime's raw form; print is keyed `print_event`.\nconst EVENT_FILTER_TO_INDEX_TYPE: Record<string, string> = {\n\tstx_transfer: \"stx_transfer\",\n\tstx_mint: \"stx_mint\",\n\tstx_burn: \"stx_burn\",\n\tstx_lock: \"stx_lock\",\n\tft_transfer: \"ft_transfer\",\n\tft_mint: \"ft_mint\",\n\tft_burn: \"ft_burn\",\n\tnft_transfer: \"nft_transfer\",\n\tnft_mint: \"nft_mint\",\n\tnft_burn: \"nft_burn\",\n\tprint_event: \"print\",\n};\n\n// Tx-level source types — matched against /v1/index/transactions, not events.\nconst TX_SOURCE_TYPES = new Set([\"contract_call\", \"contract_deploy\"]);\nconst ALL_INDEX_EVENT_TYPES = [\n\t...new Set(Object.values(EVENT_FILTER_TO_INDEX_TYPE)),\n];\n\nfunction sourceFilters(subgraph: SubgraphDefinition): SubgraphFilter[] {\n\tconst sources = subgraph.sources;\n\treturn Array.isArray(sources)\n\t\t? (sources as SubgraphFilter[])\n\t\t: Object.values(sources as Record<string, SubgraphFilter>);\n}\n\n/**\n * The Index event_types the loader must fetch for a set of source filter types.\n * A contract_call/contract_deploy source matches a tx and hands its FULL event\n * set to the handler, so when one is present we fetch every event type (the\n * matched tx's events must be complete); otherwise just the referenced types.\n * Shared by the subgraph loader and the chain-trigger evaluator.\n */\nexport function indexEventTypesForFilterTypes(filterTypes: string[]): string[] {\n\tif (filterTypes.some((t) => TX_SOURCE_TYPES.has(t))) {\n\t\treturn ALL_INDEX_EVENT_TYPES;\n\t}\n\tconst types = new Set<string>();\n\tfor (const t of filterTypes) {\n\t\tconst indexType = EVENT_FILTER_TO_INDEX_TYPE[t];\n\t\tif (indexType) types.add(indexType);\n\t}\n\treturn [...types];\n}\n\nfunction referencedIndexEventTypes(subgraph: SubgraphDefinition): string[] {\n\treturn indexEventTypesForFilterTypes(\n\t\tsourceFilters(subgraph).map((f) => f.type),\n\t);\n}\n\n/**\n * streams-index eligibility: every source must be a known event-type or\n * contract_call/contract_deploy filter (no array-style sources, which leak the\n * unreconstructable `_eventId`). Trait scope IS allowed — trait resolution\n * reads the contract registry on the platform DB (`targetDb`), which the\n * processor always holds, so it's source-independent. Everything else stays on\n * the DB tap.\n */\nexport function isStreamsIndexEligible(subgraph: SubgraphDefinition): boolean {\n\tif (Array.isArray(subgraph.sources)) return false;\n\tconst filters = sourceFilters(subgraph);\n\tif (filters.length === 0) return false;\n\tfor (const f of filters) {\n\t\tconst known =\n\t\t\tEVENT_FILTER_TO_INDEX_TYPE[f.type] || TX_SOURCE_TYPES.has(f.type);\n\t\tif (!known) return false;\n\t}\n\treturn true;\n}\n\n/** Streams clock + Index data plane, reconstructed into raw BlockData rows. */\nexport class PublicApiBlockSource implements BlockSource {\n\tconstructor(\n\t\tprivate readonly http: IndexHttpClient,\n\t\tprivate readonly eventTypes: string[],\n\t\t/** When set, enables the sparse-scan probe (event-scoped subgraphs). */\n\t\tprivate readonly probeTargets?: SparseProbeTarget[],\n\t) {}\n\n\t/** Lowest height in (after, until] any probe target hits, or null. */\n\tasync nextDataHeight(\n\t\tafterHeight: number,\n\t\tuntilHeight: number,\n\t): Promise<number | null> {\n\t\tif (!this.probeTargets?.length) return afterHeight + 1;\n\t\tconst hits = await Promise.all(\n\t\t\tthis.probeTargets.map((t) =>\n\t\t\t\tthis.http.firstEventHeight(\n\t\t\t\t\tt.eventType,\n\t\t\t\t\tafterHeight + 1,\n\t\t\t\t\tuntilHeight,\n\t\t\t\t\tt.contractId,\n\t\t\t\t),\n\t\t\t),\n\t\t);\n\t\tconst found = hits.filter((h): h is number => h !== null);\n\t\treturn found.length ? Math.min(...found) : null;\n\t}\n\n\tgetTip(): Promise<number> {\n\t\t// Bound advancement to what the Index data plane can serve — never\n\t\t// process past it even if the Streams clock is ahead.\n\t\treturn this.http.getIndexTip();\n\t}\n\n\tasync loadBlockRange(\n\t\tfromHeight: number,\n\t\ttoHeight: number,\n\t): Promise<Map<number, BlockData>> {\n\t\tconst [blocks, txs, eventLists] = await Promise.all([\n\t\t\tthis.http.walkBlocks(fromHeight, toHeight),\n\t\t\tthis.http.walkTransactions(fromHeight, toHeight),\n\t\t\tPromise.all(\n\t\t\t\tthis.eventTypes.map((t) =>\n\t\t\t\t\tthis.http.walkEvents(t, fromHeight, toHeight),\n\t\t\t\t),\n\t\t\t),\n\t\t]);\n\n\t\tconst map = new Map<number, BlockData>();\n\t\t// Seed every canonical height (incl. empty blocks) so catch-up doesn't\n\t\t// file them as gaps.\n\t\tfor (const b of blocks) {\n\t\t\tmap.set(b.block_height, {\n\t\t\t\tblock: reconstructBlock(b),\n\t\t\t\ttxs: [],\n\t\t\t\tevents: [],\n\t\t\t});\n\t\t}\n\t\tfor (const t of txs) {\n\t\t\tmap.get(t.block_height)?.txs.push(reconstructTransaction(t));\n\t\t}\n\t\tfor (const list of eventLists) {\n\t\t\tfor (const e of list) {\n\t\t\t\tmap.get(e.block_height)?.events.push(reconstructEvent(e));\n\t\t\t}\n\t\t}\n\t\t// Canonical ordering — multi-type event walks merge here.\n\t\tfor (const bd of map.values()) {\n\t\t\tbd.txs.sort((a, b) => a.tx_index - b.tx_index);\n\t\t\tbd.events.sort((a, b) => a.event_index - b.event_index);\n\t\t}\n\t\treturn map;\n\t}\n}\n\n/**\n * Wraps a primary source and falls back to a secondary, per call, when the\n * primary throws. Use it to make the HTTP (Streams+Index) plane a SOFT dependency:\n * if api is unavailable, the processor reads the Postgres tap and keeps advancing\n * instead of stalling. Safe to mix mid-stream — both taps read the same canonical\n * chain at the same heights and the cursor is forward-only. Stateless (no breaker)\n * so it's failover-safe across replicas; the primary is retried every call and\n * resumes transparently once healthy.\n */\nexport class FallbackBlockSource implements BlockSource {\n\tconstructor(\n\t\tprivate readonly primary: BlockSource,\n\t\tprivate readonly fallback: BlockSource,\n\t) {}\n\n\tasync getTip(): Promise<number> {\n\t\ttry {\n\t\t\treturn await this.primary.getTip();\n\t\t} catch (err) {\n\t\t\tlogger.warn(\"block source primary getTip failed — using DB tap\", {\n\t\t\t\terror: err instanceof Error ? err.message : String(err),\n\t\t\t});\n\t\t\treturn this.fallback.getTip();\n\t\t}\n\t}\n\n\tasync loadBlockRange(\n\t\tfromHeight: number,\n\t\ttoHeight: number,\n\t): Promise<Map<number, BlockData>> {\n\t\ttry {\n\t\t\treturn await this.primary.loadBlockRange(fromHeight, toHeight);\n\t\t} catch (err) {\n\t\t\tlogger.warn(\"block source primary loadBlockRange failed — using DB tap\", {\n\t\t\t\tfrom: fromHeight,\n\t\t\t\tto: toHeight,\n\t\t\t\terror: err instanceof Error ? err.message : String(err),\n\t\t\t});\n\t\t\treturn this.fallback.loadBlockRange(fromHeight, toHeight);\n\t\t}\n\t}\n\n\t/** Probe via the primary only; a probe failure just means \"no skip\" —\n\t * the caller falls back to plain batch advancement. */\n\tasync nextDataHeight(\n\t\tafterHeight: number,\n\t\tuntilHeight: number,\n\t): Promise<number | null> {\n\t\tif (!this.primary.nextDataHeight) return afterHeight + 1;\n\t\ttry {\n\t\t\treturn await this.primary.nextDataHeight(afterHeight, untilHeight);\n\t\t} catch {\n\t\t\treturn afterHeight + 1;\n\t\t}\n\t}\n}\n\nconst postgresBlockSource = new PostgresBlockSource();\n\n/**\n * HTTP (Streams+Index) chain source for a set of decoded event types, wrapped so\n * it falls back to the Postgres tap when api is down. Used by the chain-trigger\n * evaluator (which isn't subgraph-scoped, so it can't go through resolveBlockSource).\n */\nexport function buildChainBlockSource(eventTypes: string[]): BlockSource {\n\treturn new FallbackBlockSource(\n\t\tnew PublicApiBlockSource(buildHttpClient(), eventTypes),\n\t\tpostgresBlockSource,\n\t);\n}\n\nexport function buildHttpClient(): IndexHttpClient {\n\tconst baseUrl =\n\t\tprocess.env.SUBGRAPH_INDEX_API_URL ??\n\t\tprocess.env.STREAMS_API_URL ??\n\t\t\"http://api:3800\";\n\treturn new IndexHttpClient({\n\t\tindexBaseUrl: baseUrl,\n\t\tstreamsBaseUrl: baseUrl,\n\t\tstreamsApiKey:\n\t\t\tprocess.env.STREAMS_INTERNAL_API_KEY ?? \"sk-sl_streams_l2_internal\",\n\t});\n}\n\n/**\n * Resolve the block source for a subgraph. `SUBGRAPH_SOURCE=streams-index`\n * opts eligible subgraphs onto the public Streams clock + Index data; everything\n * else (and the default) stays on the Postgres tap.\n */\nexport function resolveBlockSource(subgraph?: SubgraphDefinition): BlockSource {\n\tif (\n\t\tprocess.env.SUBGRAPH_SOURCE === \"streams-index\" &&\n\t\tsubgraph &&\n\t\tisStreamsIndexEligible(subgraph)\n\t) {\n\t\t// Soft-depend on api: fall back to the Postgres tap per-call if the HTTP\n\t\t// plane is down, so the processor keeps advancing instead of stalling.\n\t\treturn new FallbackBlockSource(\n\t\t\tnew PublicApiBlockSource(\n\t\t\t\tbuildHttpClient(),\n\t\t\t\treferencedIndexEventTypes(subgraph),\n\t\t\t\tcanSparseScan(subgraph) ? sparseProbeTargets(subgraph) : undefined,\n\t\t\t),\n\t\t\tpostgresBlockSource,\n\t\t);\n\t}\n\tif (process.env.SUBGRAPH_SOURCE === \"streams-index\" && subgraph) {\n\t\tlogger.debug(\"Subgraph not streams-index eligible, using DB tap\", {\n\t\t\tsubgraph: subgraph.name,\n\t\t});\n\t}\n\treturn postgresBlockSource;\n}\n",
|
|
@@ -10,7 +10,7 @@
|
|
|
10
10
|
"import type { Block, Event, Transaction } from \"@secondlayer/shared/db\";\nimport type {\n\tIndexBlockRow,\n\tIndexEventRow,\n\tIndexTransactionRow,\n} from \"@secondlayer/shared/index-http\";\n\nexport type {\n\tIndexBlockRow,\n\tIndexEventRow,\n\tIndexTransactionRow,\n} from \"@secondlayer/shared/index-http\";\n\n/**\n * Reconstruct the raw `blocks`/`events` row shapes the subgraph runtime expects\n * (the shapes `matchSources` + the handler runner read) from the decoded,\n * flattened rows the public Index API serves. This is what lets\n * `PublicApiBlockSource` feed the EXISTING pipeline byte-identically to the\n * Postgres tap.\n *\n * Two shape gaps the Index API can't avoid, handled here:\n * - Index event rows are flat (`event_type: \"ft_transfer\"`, columns\n * `sender`/`amount`/…); the runtime expects the node's nested `data` keyed by\n * a suffixed `type` (`ft_transfer_event`), with print under `contract_event`.\n * - nft/print Clarity values: the runtime decodes from the canonical hex\n * (`raw_value`), so we place the Index hex there. (The node's verbose\n * serde-tagged `value`, e.g. `{UInt:223}`, is not reproducible from hex and\n * is no longer read — see the nft tokenId normalization in runner.ts.)\n */\n\n/** ISO `block_time` (or null) → unix-seconds integer the runtime expects. */\nfunction isoToUnixSeconds(iso: string | null): number {\n\tif (!iso) return 0;\n\treturn Math.floor(new Date(iso).getTime() / 1000);\n}\n\nexport function reconstructBlock(b: IndexBlockRow): Block {\n\treturn {\n\t\theight: b.block_height,\n\t\thash: b.block_hash,\n\t\tparent_hash: b.parent_hash,\n\t\tburn_block_height: b.burn_block_height,\n\t\tburn_block_hash: b.burn_block_hash,\n\t\ttimestamp: isoToUnixSeconds(b.block_time),\n\t\t// Index serves canonical rows only.\n\t\tcanonical: true,\n\t\tcreated_at: new Date(0),\n\t} as Block;\n}\n\nexport function reconstructTransaction(t: IndexTransactionRow): Transaction {\n\treturn {\n\t\ttx_id: t.tx_id,\n\t\tblock_height: t.block_height,\n\t\ttx_index: t.tx_index,\n\t\ttype: t.tx_type,\n\t\tsender: t.sender,\n\t\tstatus: t.status,\n\t\tcontract_id:\n\t\t\tt.contract_call?.contract_id ?? t.smart_contract?.contract_id ?? null,\n\t\tfunction_name: t.contract_call?.function_name ?? null,\n\t\t// Raw hex ClarityValues — the runner decodes them via its own deserializeCV\n\t\t// path, identical to the DB tap.\n\t\tfunction_args: t.contract_call?.function_args_hex ?? [],\n\t\traw_result: t.contract_call?.result_hex ?? null,\n\t\traw_tx: \"\",\n\t\tcreated_at: new Date(0),\n\t} as Transaction;\n}\n\nexport function reconstructEvent(e: IndexEventRow): Event {\n\tconst base = {\n\t\t// Synthetic, deterministic id. The runtime only reads `id` for error logs\n\t\t// and the `*`-wildcard payload (which is streams-index-ineligible).\n\t\tid: `${e.tx_id}#${e.event_index}`,\n\t\ttx_id: e.tx_id,\n\t\tblock_height: e.block_height,\n\t\tevent_index: e.event_index,\n\t\tcreated_at: new Date(0),\n\t};\n\n\tswitch (e.event_type) {\n\t\tcase \"ft_transfer\":\n\t\tcase \"ft_mint\":\n\t\tcase \"ft_burn\":\n\t\t\treturn {\n\t\t\t\t...base,\n\t\t\t\ttype: `${e.event_type}_event`,\n\t\t\t\tdata: {\n\t\t\t\t\tasset_identifier: e.asset_identifier,\n\t\t\t\t\tsender: e.sender,\n\t\t\t\t\trecipient: e.recipient,\n\t\t\t\t\tamount: e.amount,\n\t\t\t\t},\n\t\t\t} as Event;\n\n\t\tcase \"nft_transfer\":\n\t\tcase \"nft_mint\":\n\t\tcase \"nft_burn\":\n\t\t\treturn {\n\t\t\t\t...base,\n\t\t\t\ttype: `${e.event_type}_event`,\n\t\t\t\tdata: {\n\t\t\t\t\tasset_identifier: e.asset_identifier,\n\t\t\t\t\tsender: e.sender,\n\t\t\t\t\trecipient: e.recipient,\n\t\t\t\t\t// Canonical hex → runner decodes tokenId from raw_value.\n\t\t\t\t\traw_value: e.value,\n\t\t\t\t},\n\t\t\t} as Event;\n\n\t\tcase \"stx_transfer\":\n\t\tcase \"stx_mint\":\n\t\tcase \"stx_burn\":\n\t\t\treturn {\n\t\t\t\t...base,\n\t\t\t\ttype: `${e.event_type}_event`,\n\t\t\t\tdata: {\n\t\t\t\t\tsender: e.sender,\n\t\t\t\t\trecipient: e.recipient,\n\t\t\t\t\tamount: e.amount,\n\t\t\t\t\t// Raw stx_transfer always carries memo (\"\" when empty); Index\n\t\t\t\t\t// returns null for empty — default to \"\" to match the DB tap.\n\t\t\t\t\t...(e.event_type === \"stx_transfer\" ? { memo: e.memo ?? \"\" } : {}),\n\t\t\t\t},\n\t\t\t} as Event;\n\n\t\tcase \"stx_lock\":\n\t\t\treturn {\n\t\t\t\t...base,\n\t\t\t\ttype: \"stx_lock_event\",\n\t\t\t\tdata: {\n\t\t\t\t\tlocked_address: e.sender,\n\t\t\t\t\tlocked_amount: e.amount,\n\t\t\t\t\tunlock_height: e.payload.unlock_height,\n\t\t\t\t},\n\t\t\t} as Event;\n\n\t\tcase \"print\":\n\t\t\treturn {\n\t\t\t\t...base,\n\t\t\t\ttype: \"contract_event\",\n\t\t\t\tdata: {\n\t\t\t\t\ttopic: e.payload.topic,\n\t\t\t\t\t// Matcher + runner read `contract_identifier` (the raw node field).\n\t\t\t\t\tcontract_identifier: e.contract_id,\n\t\t\t\t\tvalue: e.payload.value,\n\t\t\t\t\traw_value: e.payload.raw_value,\n\t\t\t\t},\n\t\t\t} as Event;\n\t}\n}\n",
|
|
11
11
|
"import type {\n\tDatabase,\n\tInsertSubscriptionOutbox,\n\tSubscription,\n} from \"@secondlayer/shared/db\";\nimport { resolveTraitContractIds } from \"@secondlayer/shared/db/queries/contracts\";\nimport type { ChainApplyEnvelope } from \"@secondlayer/shared\";\nimport type { ChainTrigger } from \"@secondlayer/shared/schemas/subscriptions\";\nimport type { Kysely } from \"kysely\";\nimport type { SubgraphFilter } from \"../types.ts\";\nimport type { BlockData } from \"./batch-loader.ts\";\nimport { indexEventTypesForFilterTypes } from \"./block-source.ts\";\nimport {\n\ttype MatchedTx,\n\ttype TraitContracts,\n\tmatchSources,\n} from \"./source-matcher.ts\";\n\n/** Trigger types that match a whole transaction (not an individual event). */\nconst TX_LEVEL_TRIGGER_TYPES = new Set([\"contract_call\", \"contract_deploy\"]);\n\n/**\n * Pure matching core for direct chain-level subscriptions. A single evaluator\n * loop serves ALL chain subscriptions: it reads canonical blocks off the public\n * Index/Streams clock (via `PublicApiBlockSource`), runs the same\n * `matchSources` engine the subgraph runtime uses, and routes matches back to\n * the originating subscription. Everything here is pure/sync (DB only for trait\n * resolution) so it's trivially testable.\n *\n * Source keys are `\"{subscriptionId}#{triggerIndex}\"` — `matchSources` echoes\n * the key as `MatchedTx.sourceName`, letting the emitter recover which\n * subscription (and which trigger) matched. `keyMeta` carries the readable\n * trigger type for the outbox `event_type` / payload.\n */\n\nexport interface TriggerKeyMeta {\n\tsubscriptionId: string;\n\ttriggerIndex: number;\n\ttriggerType: ChainTrigger[\"type\"];\n}\n\nexport interface ChainSourcesMap {\n\tsources: Record<string, SubgraphFilter>;\n\tkeyMeta: Map<string, TriggerKeyMeta>;\n}\n\nfunction sourceKey(subscriptionId: string, triggerIndex: number): string {\n\treturn `${subscriptionId}#${triggerIndex}`;\n}\n\nfunction toAmount(v: string | number | undefined): bigint | undefined {\n\treturn v === undefined ? undefined : BigInt(v);\n}\n\n/**\n * Convert a stored `ChainTrigger` (JSON; amounts as string/number) to the\n * runtime `SubgraphFilter` the matcher expects (amounts as bigint). Field names\n * are identical across the two shapes, so this is a copy plus amount coercion.\n */\nexport function chainTriggerToFilter(trigger: ChainTrigger): SubgraphFilter {\n\tconst t = trigger as ChainTrigger & {\n\t\tminAmount?: string | number;\n\t\tmaxAmount?: string | number;\n\t};\n\t// Spread copies all set keys; amounts (string|number) are then overwritten\n\t// with bigint where present. An absent optional amount isn't in the spread,\n\t// so there's nothing to strip.\n\tconst filter = { ...trigger } as Record<string, unknown>;\n\tconst minAmount = toAmount(t.minAmount);\n\tconst maxAmount = toAmount(t.maxAmount);\n\tif (minAmount !== undefined) filter.minAmount = minAmount;\n\tif (maxAmount !== undefined) filter.maxAmount = maxAmount;\n\treturn filter as unknown as SubgraphFilter;\n}\n\nfunction triggersOf(sub: Subscription): ChainTrigger[] {\n\treturn (sub.triggers ?? []) as ChainTrigger[];\n}\n\n/** Build the `matchSources` input from every active chain subscription. */\nexport function buildSourcesMap(chainSubs: Subscription[]): ChainSourcesMap {\n\tconst sources: Record<string, SubgraphFilter> = {};\n\tconst keyMeta = new Map<string, TriggerKeyMeta>();\n\tfor (const sub of chainSubs) {\n\t\ttriggersOf(sub).forEach((trigger, triggerIndex) => {\n\t\t\tconst key = sourceKey(sub.id, triggerIndex);\n\t\t\tsources[key] = chainTriggerToFilter(trigger);\n\t\t\tkeyMeta.set(key, {\n\t\t\t\tsubscriptionId: sub.id,\n\t\t\t\ttriggerIndex,\n\t\t\t\ttriggerType: trigger.type,\n\t\t\t});\n\t\t});\n\t}\n\treturn { sources, keyMeta };\n}\n\n/** The Index event types the loader must fetch to satisfy all chain triggers. */\nexport function referencedEventTypes(chainSubs: Subscription[]): string[] {\n\tconst filterTypes = new Set<string>();\n\tfor (const sub of chainSubs) {\n\t\tfor (const trigger of triggersOf(sub)) filterTypes.add(trigger.type);\n\t}\n\treturn indexEventTypesForFilterTypes([...filterTypes]);\n}\n\n/** Distinct traits referenced across all chain triggers. */\nexport function referencedTraits(chainSubs: Subscription[]): string[] {\n\tconst traits = new Set<string>();\n\tfor (const sub of chainSubs) {\n\t\tfor (const trigger of triggersOf(sub)) {\n\t\t\tconst trait = (trigger as { trait?: string }).trait;\n\t\t\tif (trait) traits.add(trait);\n\t\t}\n\t}\n\treturn [...traits];\n}\n\n/**\n * Resolve each referenced trait to its conforming contract-id set as of\n * `asOfBlock`, from the contract registry (`CONTRACT_REGISTRY_ENABLED` populates\n * it). Empty map when no trigger is trait-scoped → no DB work. Membership only\n * grows, so the evaluator resolves this once per batch, not per block.\n */\nexport async function buildTraitContracts(\n\tdb: Kysely<Database>,\n\tchainSubs: Subscription[],\n\tasOfBlock: number,\n): Promise<TraitContracts> {\n\tconst resolved: TraitContracts = new Map();\n\tfor (const trait of referencedTraits(chainSubs)) {\n\t\tconst ids = await resolveTraitContractIds(db, trait, asOfBlock);\n\t\tresolved.set(trait, new Set(ids));\n\t}\n\treturn resolved;\n}\n\n/** Run the matcher for one block. Thin wrapper for symmetry/testability. */\nexport function evaluateBlock(\n\tblock: BlockData,\n\tsources: Record<string, SubgraphFilter>,\n\ttraitContracts: TraitContracts,\n): MatchedTx[] {\n\treturn matchSources(sources, block.txs, block.events, traitContracts);\n}\n\n// ── Outbox emission ─────────────────────────────────────────────────────────\n\n// Apply-envelope shape is single-sourced as `ChainApplyEnvelope` in\n// `@secondlayer/shared` (shared with the SDK consumer); reorg emits a matching\n// `ChainReorgRollbackEnvelope`, see `handleChainReorg`.\n\n/**\n * Stable dedup identity for a chain delivery — (subscription, tx, event,\n * block_hash). A tx-level match (contract_call/deploy) has no event, so\n * `eventIndex = -1`. `block_hash` is included so a tx that survives a reorg\n * (same tx_id, NEW canonical block) re-delivers an `apply` after its rollback,\n * instead of being suppressed forever; re-processing the SAME canonical block is\n * still idempotent (same hash → same key).\n */\nfunction chainDedupKey(\n\tsubscriptionId: string,\n\ttxId: string,\n\teventIndex: number,\n\tblockHash: string,\n\treplayId?: string,\n): string {\n\tconst base = `chain:${subscriptionId}:${txId}:${eventIndex}:${blockHash}`;\n\t// Replay keys are namespaced so a re-delivery doesn't collide with the\n\t// already-emitted live apply row (whose outbox entry may be long gone), while\n\t// re-running the SAME replay range stays idempotent (same replayId → same key).\n\treturn replayId ? `replay:${replayId}:${base}` : base;\n}\n\nfunction applyRow(\n\tmeta: TriggerKeyMeta,\n\tblockHeight: number,\n\tblockHash: string,\n\ttxId: string,\n\teventIndex: number,\n\tevent: Record<string, unknown>,\n\treplayId?: string,\n): InsertSubscriptionOutbox {\n\tconst payload: ChainApplyEnvelope = {\n\t\taction: \"apply\",\n\t\tblock_hash: blockHash,\n\t\tblock_height: blockHeight,\n\t\ttx_id: txId,\n\t\tcanonical: true,\n\t\ttrigger: meta.triggerType,\n\t\tevent,\n\t};\n\treturn {\n\t\tsubscription_id: meta.subscriptionId,\n\t\tkind: \"chain\",\n\t\tsubgraph_name: null,\n\t\ttable_name: null,\n\t\tblock_height: blockHeight,\n\t\ttx_id: txId,\n\t\trow_pk: { tx_id: txId, event_index: eventIndex },\n\t\tevent_type: `chain.${meta.triggerType}.apply`,\n\t\tpayload,\n\t\tdedup_key: chainDedupKey(\n\t\t\tmeta.subscriptionId,\n\t\t\ttxId,\n\t\t\teventIndex,\n\t\t\tblockHash,\n\t\t\treplayId,\n\t\t),\n\t\t...(replayId ? { is_replay: true } : {}),\n\t};\n}\n\n/**\n * Turn one block's matches into `subscription_outbox` rows (apply envelope). For\n * tx-level triggers (contract_call/deploy) we emit ONE row per matched tx\n * (`event_index = -1`); for event-level triggers, one row per matched event.\n * The `(subscription_id, dedup_key)` unique constraint makes re-processing a\n * block idempotent, so the emitter never double-delivers. Returns rows written.\n */\nexport async function emitChainOutbox(\n\tdb: Kysely<Database>,\n\tmatches: MatchedTx[],\n\tkeyMeta: Map<string, TriggerKeyMeta>,\n\tblockHeight: number,\n\tblockHash: string,\n\topts?: { replayId?: string },\n): Promise<number> {\n\tconst replayId = opts?.replayId;\n\tconst rows: InsertSubscriptionOutbox[] = [];\n\tfor (const match of matches) {\n\t\tconst meta = keyMeta.get(match.sourceName);\n\t\tif (!meta) continue;\n\t\tconst txId = match.tx.tx_id;\n\t\tif (TX_LEVEL_TRIGGER_TYPES.has(meta.triggerType)) {\n\t\t\trows.push(\n\t\t\t\tapplyRow(\n\t\t\t\t\tmeta,\n\t\t\t\t\tblockHeight,\n\t\t\t\t\tblockHash,\n\t\t\t\t\ttxId,\n\t\t\t\t\t-1,\n\t\t\t\t\t{\n\t\t\t\t\t\ttx_id: txId,\n\t\t\t\t\t\ttype: match.tx.type,\n\t\t\t\t\t\tsender: match.tx.sender,\n\t\t\t\t\t\tstatus: match.tx.status,\n\t\t\t\t\t\tcontract_id: match.tx.contract_id ?? null,\n\t\t\t\t\t\tfunction_name: match.tx.function_name ?? null,\n\t\t\t\t\t\tfunction_args: match.tx.function_args ?? null,\n\t\t\t\t\t\tresult_hex: match.tx.raw_result ?? null,\n\t\t\t\t\t},\n\t\t\t\t\treplayId,\n\t\t\t\t),\n\t\t\t);\n\t\t} else {\n\t\t\tfor (const event of match.events) {\n\t\t\t\trows.push(\n\t\t\t\t\tapplyRow(\n\t\t\t\t\t\tmeta,\n\t\t\t\t\t\tblockHeight,\n\t\t\t\t\t\tblockHash,\n\t\t\t\t\t\ttxId,\n\t\t\t\t\t\tevent.event_index,\n\t\t\t\t\t\t{\n\t\t\t\t\t\t\ttx_id: txId,\n\t\t\t\t\t\t\ttype: event.type,\n\t\t\t\t\t\t\tevent_index: event.event_index,\n\t\t\t\t\t\t\tdata: event.data,\n\t\t\t\t\t\t},\n\t\t\t\t\t\treplayId,\n\t\t\t\t\t),\n\t\t\t\t);\n\t\t\t}\n\t\t}\n\t}\n\tif (rows.length === 0) return 0;\n\t// Net-inserted (not built) so callers count genuinely new deliveries — a\n\t// re-processed block or a re-run replay returns 0.\n\tconst result = await db\n\t\t.insertInto(\"subscription_outbox\")\n\t\t.values(rows)\n\t\t.onConflict((oc) =>\n\t\t\toc.columns([\"subscription_id\", \"dedup_key\"]).doNothing(),\n\t\t)\n\t\t.executeTakeFirst();\n\treturn Number(result.numInsertedOrUpdatedRows ?? 0);\n}\n"
|
|
12
12
|
],
|
|
13
|
-
"mappings": ";;;;AA8BA,IAAM,eAAe,IAAI;AAEzB,SAAS,YAAY,CAAC,OAAe,SAA0B;AAAA,EAC9D,IAAI,CAAC,QAAQ,SAAS,GAAG;AAAA,IAAG,OAAO,UAAU;AAAA,EAC7C,IAAI,KAAK,aAAa,IAAI,OAAO;AAAA,EACjC,IAAI,CAAC,IAAI;AAAA,IACR,MAAM,QAAQ,QACZ,QAAQ,qBAAqB,MAAM,EACnC,QAAQ,OAAO,IAAI;AAAA,IACrB,KAAK,IAAI,OAAO,IAAI,QAAQ;AAAA,IAC5B,aAAa,IAAI,SAAS,EAAE;AAAA,EAC7B;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ACA,MAAM,UAAU,cAAc,IAAI,SAAS,cAAc;AAAA,MACzD,IAAI,QAAQ,WAAW;AAAA,QAAG;AAAA,MAC1B,YAAY,MAAM,gBACjB,IACA,SACA,SACA,GACA,GAAG,MAAM,MACT;AAAA,QACC;AAAA,MACD,CACD;AAAA,IACD;AAAA,EACD;AAAA,EAEA,QAAO,KAAK,yBAAyB;AAAA,IACpC,cAAc,IAAI;AAAA,IAClB;AAAA,IACA;AAAA,IACA;AAAA,IACA,WAAW,MAAM;AAAA,IACjB,SAAS,MAAM;AAAA,EAChB,CAAC;AAAA,EAED,OAAO,EAAE,UAAU,eAAe,UAAU,cAAc,QAAQ;AAAA;",
|
|
14
14
|
"debugId": "DBEF44AED32A112E64756E2164756E21",
|
|
15
15
|
"names": []
|
|
16
16
|
}
|
|
@@ -165,6 +165,13 @@ interface SubgraphContext {
|
|
|
165
165
|
update(table: string, where: Record<string, unknown>, set: Record<string, unknown>): void;
|
|
166
166
|
upsert(table: string, key: Record<string, unknown>, row: Record<string, unknown>): void;
|
|
167
167
|
delete(table: string, where: Record<string, unknown>): void;
|
|
168
|
+
/**
|
|
169
|
+
* Atomic counter update — the blessed accumulator primitive. Applies
|
|
170
|
+
* `col = COALESCE(col, 0) + delta` per column (insert-or-add); deltas may
|
|
171
|
+
* be negative. Requires a uniqueKeys constraint matching `key`. Prefer
|
|
172
|
+
* this over patchOrInsert with functional updaters for running totals.
|
|
173
|
+
*/
|
|
174
|
+
increment(table: string, key: Record<string, unknown>, deltas: Record<string, bigint | number>): void;
|
|
168
175
|
/** Partial update — sets only specified fields, preserves others */
|
|
169
176
|
patch(table: string, where: Record<string, unknown>, set: Record<string, unknown>): void;
|
|
170
177
|
/** Find-then-merge-or-insert. Values can be functions: (existing) => newValue */
|
|
@@ -196,6 +203,9 @@ interface SubgraphDefinition {
|
|
|
196
203
|
description?: string;
|
|
197
204
|
/** Block height to start indexing from (default: 1) */
|
|
198
205
|
startBlock?: number;
|
|
206
|
+
/** 'concurrent' = tip-first: live at tip now, history backfills behind.
|
|
207
|
+
* Requires order-tolerant handlers. Default 'blocking'. */
|
|
208
|
+
backfillMode?: "blocking" | "concurrent";
|
|
199
209
|
/** Named source filters — keys become handler keys */
|
|
200
210
|
sources: Record<string, SubgraphFilter>;
|
|
201
211
|
/** Tables in this subgraph */
|
|
@@ -239,7 +249,12 @@ interface TxMeta2 {
|
|
|
239
249
|
/**
|
|
240
250
|
* Runtime context passed to subgraph handlers.
|
|
241
251
|
* Batches writes and flushes them atomically at the end of a block.
|
|
242
|
-
*
|
|
252
|
+
*
|
|
253
|
+
* Row reads (findOne/findMany) are read-your-writes: they overlay the pending
|
|
254
|
+
* ops queue on the DB state, so a handler observes every write queued earlier
|
|
255
|
+
* in the same block. Without this, accumulator patterns (balance = f(existing))
|
|
256
|
+
* silently lose all but the last same-block delta per row (fix-f040 B1).
|
|
257
|
+
* Aggregate reads (count/sum/min/max) remain pre-flush DB state.
|
|
243
258
|
*/
|
|
244
259
|
declare class SubgraphContext2 {
|
|
245
260
|
readonly block: BlockMeta;
|
|
@@ -256,7 +271,14 @@ declare class SubgraphContext2 {
|
|
|
256
271
|
* Non-idempotent `update` handlers are rejected at deploy, not here.
|
|
257
272
|
*/
|
|
258
273
|
private readonly byo;
|
|
259
|
-
|
|
274
|
+
/**
|
|
275
|
+
* Record pre-images of keyed mutations into the schema's `_journal` so a
|
|
276
|
+
* reorg can restore prior row states (fix-f040 B2). Enabled on the live
|
|
277
|
+
* path only — deep reindex/backfill heights are past finality, and the
|
|
278
|
+
* journal would just be churn the pruner deletes.
|
|
279
|
+
*/
|
|
280
|
+
private readonly journal;
|
|
281
|
+
constructor(db: AnyDb, pgSchemaName: string, subgraphSchema: SubgraphSchema, block: BlockMeta, tx: TxMeta2, byo?: boolean, journal?: boolean);
|
|
260
282
|
get tx(): TxMeta2;
|
|
261
283
|
/** Update the current transaction context (used by runner between events) */
|
|
262
284
|
setTx(tx: TxMeta2): void;
|
|
@@ -264,6 +286,24 @@ declare class SubgraphContext2 {
|
|
|
264
286
|
update(table: string, where: Record<string, unknown>, set: Record<string, unknown>): void;
|
|
265
287
|
upsert(table: string, key: Record<string, unknown>, row: Record<string, unknown>): void;
|
|
266
288
|
delete(table: string, where: Record<string, unknown>): void;
|
|
289
|
+
/**
|
|
290
|
+
* Atomic counter update — the blessed accumulator primitive. Compiles to
|
|
291
|
+
* `INSERT ... ON CONFLICT (key) DO UPDATE SET col = COALESCE(t.col,0) + delta`,
|
|
292
|
+
* so deltas commute: same-block, replayed-in-order, and concurrent updates
|
|
293
|
+
* all land correctly without read-modify-write. Missing row inserts the
|
|
294
|
+
* delta as the initial value. Requires a uniqueKeys constraint matching
|
|
295
|
+
* `key`; deltas may be negative.
|
|
296
|
+
*/
|
|
297
|
+
increment(table: string, key: Record<string, unknown>, deltas: Record<string, bigint | number>): void;
|
|
298
|
+
/** Current length of the pending-ops queue. Pair with {@link rollbackTo}. */
|
|
299
|
+
opsCheckpoint(): number;
|
|
300
|
+
/**
|
|
301
|
+
* Discard ops queued after a checkpoint. The runner wraps each handler
|
|
302
|
+
* invocation so a thrown handler contributes nothing — without this, a
|
|
303
|
+
* transfer handler that debited then threw flushes a one-sided debit
|
|
304
|
+
* (fix-f040 B6).
|
|
305
|
+
*/
|
|
306
|
+
rollbackTo(checkpoint: number): void;
|
|
267
307
|
/** Partial update — sets only specified fields, preserves everything else */
|
|
268
308
|
patch(table: string, where: Record<string, unknown>, set: Record<string, unknown>): void;
|
|
269
309
|
/**
|
|
@@ -275,6 +315,17 @@ declare class SubgraphContext2 {
|
|
|
275
315
|
formatUnits(value: bigint, decimals: number): string;
|
|
276
316
|
findOne(table: string, where: Record<string, unknown>): Promise<Record<string, unknown> | null>;
|
|
277
317
|
findMany(table: string, where: Record<string, unknown>): Promise<Record<string, unknown>[]>;
|
|
318
|
+
/**
|
|
319
|
+
* Replay pending ops for `table` over a single DB-read result so reads
|
|
320
|
+
* observe earlier same-block writes. Mirrors flush semantics: upserts
|
|
321
|
+
* merge non-key/non-meta columns, increments add deltas, updates/deletes
|
|
322
|
+
* apply by where-match. Overlaid rows synthesized from pending inserts
|
|
323
|
+
* lack DB-generated columns (_id, _created_at).
|
|
324
|
+
*/
|
|
325
|
+
private overlayOne;
|
|
326
|
+
private overlayMany;
|
|
327
|
+
/** Apply one pending op to a candidate row state (null = row absent). */
|
|
328
|
+
private applyOpToRow;
|
|
278
329
|
count(table: string, where?: Record<string, unknown>): Promise<number>;
|
|
279
330
|
sum(table: string, column: string, where?: Record<string, unknown>): Promise<bigint>;
|
|
280
331
|
min(table: string, column: string, where?: Record<string, unknown>): Promise<bigint | null>;
|
|
@@ -295,6 +346,24 @@ declare class SubgraphContext2 {
|
|
|
295
346
|
flush(): Promise<FlushManifest>;
|
|
296
347
|
/** Prepare a single insert row, returning its data, columns, upsert key for batching. */
|
|
297
348
|
private prepareInsert;
|
|
349
|
+
/**
|
|
350
|
+
* Lazily create `_journal` for schemas deployed before it existed. Cached
|
|
351
|
+
* per process only once CONFIRMED present (to_regclass) — a CREATE issued
|
|
352
|
+
* inside a block tx could roll back with it, so self-created tables are
|
|
353
|
+
* re-verified on the next flush instead of trusted.
|
|
354
|
+
*/
|
|
355
|
+
private ensureJournalTable;
|
|
356
|
+
/** SQL type of a user column (for casting journal key VALUES), if known. */
|
|
357
|
+
private columnSqlType;
|
|
358
|
+
/**
|
|
359
|
+
* Journal pre-images for a keyed batch: one `_journal` row per key with the
|
|
360
|
+
* row's current state (`prev_row`), or NULL when the key doesn't exist yet
|
|
361
|
+
* (the mutation will create it — a revert deletes it). Emitted BEFORE the
|
|
362
|
+
* mutation statement, same transaction.
|
|
363
|
+
*/
|
|
364
|
+
private journalCaptureSQL;
|
|
365
|
+
/** Journal pre-images of rows a where-clause mutation will touch, keyed by `_id`. */
|
|
366
|
+
private journalCaptureByWhereSQL;
|
|
298
367
|
/** Build SQL statements from write ops, batching compatible INSERTs. */
|
|
299
368
|
private buildStatements;
|
|
300
369
|
private validateTable;
|
|
@@ -310,6 +379,8 @@ type TxRecord = {
|
|
|
310
379
|
type: string
|
|
311
380
|
sender: string
|
|
312
381
|
status: string
|
|
382
|
+
/** Position within the block — the runner sorts dispatch into chain order. */
|
|
383
|
+
tx_index?: number
|
|
313
384
|
contract_id?: string | null
|
|
314
385
|
function_name?: string | null
|
|
315
386
|
function_args?: unknown | null
|
|
@@ -291,7 +291,25 @@ async function runHandlers(subgraph, matched, ctx, opts) {
|
|
|
291
291
|
filterLookup.set(name, filter);
|
|
292
292
|
}
|
|
293
293
|
}
|
|
294
|
+
const units = [];
|
|
294
295
|
for (const { tx, events, sourceName } of matched) {
|
|
296
|
+
if (events.length === 0) {
|
|
297
|
+
units.push({ tx, sourceName, event: null });
|
|
298
|
+
} else {
|
|
299
|
+
for (const event of events)
|
|
300
|
+
units.push({ tx, sourceName, event });
|
|
301
|
+
}
|
|
302
|
+
}
|
|
303
|
+
units.sort((a, b) => (a.tx.tx_index ?? 0) - (b.tx.tx_index ?? 0) || (a.event?.event_index ?? -1) - (b.event?.event_index ?? -1));
|
|
304
|
+
for (const { tx, event, sourceName } of units) {
|
|
305
|
+
if (errors >= threshold) {
|
|
306
|
+
logger.error("Subgraph error threshold reached, skipping remaining events", {
|
|
307
|
+
subgraph: subgraph.name,
|
|
308
|
+
errors,
|
|
309
|
+
threshold
|
|
310
|
+
});
|
|
311
|
+
return { processed, errors };
|
|
312
|
+
}
|
|
295
313
|
const handler = subgraph.handlers[sourceName] ?? subgraph.handlers["*"] ?? null;
|
|
296
314
|
if (!handler) {
|
|
297
315
|
logger.warn("No handler found for source", {
|
|
@@ -310,9 +328,29 @@ async function runHandlers(subgraph, matched, ctx, opts) {
|
|
|
310
328
|
functionName: tx.function_name ?? null
|
|
311
329
|
});
|
|
312
330
|
const filter = filterLookup.get(sourceName);
|
|
313
|
-
|
|
314
|
-
|
|
315
|
-
|
|
331
|
+
const checkpoint = ctx.opsCheckpoint();
|
|
332
|
+
try {
|
|
333
|
+
let payload;
|
|
334
|
+
if (event === null) {
|
|
335
|
+
payload = filter ? buildEventPayload(filter, tx, null) : {
|
|
336
|
+
tx: {
|
|
337
|
+
txId: tx.tx_id,
|
|
338
|
+
sender: tx.sender,
|
|
339
|
+
type: tx.type,
|
|
340
|
+
status: tx.status,
|
|
341
|
+
contractId: tx.contract_id,
|
|
342
|
+
functionName: tx.function_name
|
|
343
|
+
}
|
|
344
|
+
};
|
|
345
|
+
} else if (filter) {
|
|
346
|
+
payload = buildEventPayload(filter, tx, event);
|
|
347
|
+
} else {
|
|
348
|
+
const decoded = decodeEventData(event.data);
|
|
349
|
+
payload = {
|
|
350
|
+
...decoded,
|
|
351
|
+
_eventId: event.id,
|
|
352
|
+
_eventType: event.type,
|
|
353
|
+
_eventIndex: event.event_index,
|
|
316
354
|
tx: {
|
|
317
355
|
txId: tx.tx_id,
|
|
318
356
|
sender: tx.sender,
|
|
@@ -322,62 +360,22 @@ async function runHandlers(subgraph, matched, ctx, opts) {
|
|
|
322
360
|
functionName: tx.function_name
|
|
323
361
|
}
|
|
324
362
|
};
|
|
325
|
-
await handler(payload, ctx);
|
|
326
|
-
processed++;
|
|
327
|
-
} catch (err) {
|
|
328
|
-
errors++;
|
|
329
|
-
logger.error("Subgraph handler error", {
|
|
330
|
-
subgraph: subgraph.name,
|
|
331
|
-
sourceName,
|
|
332
|
-
txId: tx.tx_id,
|
|
333
|
-
error: getErrorMessage(err)
|
|
334
|
-
});
|
|
335
|
-
}
|
|
336
|
-
continue;
|
|
337
|
-
}
|
|
338
|
-
for (const event of events) {
|
|
339
|
-
if (errors >= threshold) {
|
|
340
|
-
logger.error("Subgraph error threshold reached, skipping remaining events", {
|
|
341
|
-
subgraph: subgraph.name,
|
|
342
|
-
errors,
|
|
343
|
-
threshold
|
|
344
|
-
});
|
|
345
|
-
return { processed, errors };
|
|
346
363
|
}
|
|
347
|
-
|
|
348
|
-
|
|
349
|
-
const decoded = decodeEventData(event.data);
|
|
350
|
-
return {
|
|
351
|
-
...decoded,
|
|
352
|
-
_eventId: event.id,
|
|
353
|
-
_eventType: event.type,
|
|
354
|
-
_eventIndex: event.event_index,
|
|
355
|
-
tx: {
|
|
356
|
-
txId: tx.tx_id,
|
|
357
|
-
sender: tx.sender,
|
|
358
|
-
type: tx.type,
|
|
359
|
-
status: tx.status,
|
|
360
|
-
contractId: tx.contract_id,
|
|
361
|
-
functionName: tx.function_name
|
|
362
|
-
}
|
|
363
|
-
};
|
|
364
|
-
})();
|
|
365
|
-
if (filter?.type === "print_event" && filter.topic && payload.topic !== filter.topic) {
|
|
366
|
-
continue;
|
|
367
|
-
}
|
|
368
|
-
await handler(payload, ctx);
|
|
369
|
-
processed++;
|
|
370
|
-
} catch (err) {
|
|
371
|
-
errors++;
|
|
372
|
-
logger.error("Subgraph handler error", {
|
|
373
|
-
subgraph: subgraph.name,
|
|
374
|
-
sourceName,
|
|
375
|
-
txId: tx.tx_id,
|
|
376
|
-
eventId: event.id,
|
|
377
|
-
eventType: event.type,
|
|
378
|
-
error: getErrorMessage(err)
|
|
379
|
-
});
|
|
364
|
+
if (event !== null && filter?.type === "print_event" && filter.topic && payload.topic !== filter.topic) {
|
|
365
|
+
continue;
|
|
380
366
|
}
|
|
367
|
+
await handler(payload, ctx);
|
|
368
|
+
processed++;
|
|
369
|
+
} catch (err) {
|
|
370
|
+
ctx.rollbackTo(checkpoint);
|
|
371
|
+
errors++;
|
|
372
|
+
logger.error("Subgraph handler error", {
|
|
373
|
+
subgraph: subgraph.name,
|
|
374
|
+
sourceName,
|
|
375
|
+
txId: tx.tx_id,
|
|
376
|
+
...event !== null ? { eventId: event.id, eventType: event.type } : {},
|
|
377
|
+
error: getErrorMessage(err)
|
|
378
|
+
});
|
|
381
379
|
}
|
|
382
380
|
}
|
|
383
381
|
return { processed, errors };
|
|
@@ -388,5 +386,5 @@ export {
|
|
|
388
386
|
buildContractCallInput
|
|
389
387
|
};
|
|
390
388
|
|
|
391
|
-
//# debugId=
|
|
389
|
+
//# debugId=611CAFE15DEA08D764756E2164756E21
|
|
392
390
|
//# sourceMappingURL=runner.js.map
|