@secondlayer/shared 0.5.1 → 0.6.1
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 +23 -22
- package/dist/src/crypto/hmac.js +2 -1
- package/dist/src/crypto/hmac.js.map +2 -2
- package/dist/src/db/index.d.ts +1 -1
- package/dist/src/db/index.js +2 -1
- package/dist/src/db/index.js.map +2 -2
- package/dist/src/db/jsonb.js +2 -1
- package/dist/src/db/jsonb.js.map +2 -2
- package/dist/src/db/queries/accounts.d.ts +1 -1
- package/dist/src/db/queries/accounts.js +2 -1
- package/dist/src/db/queries/accounts.js.map +2 -2
- package/dist/src/db/queries/integrity.d.ts +1 -1
- package/dist/src/db/queries/integrity.js +2 -1
- package/dist/src/db/queries/integrity.js.map +2 -2
- package/dist/src/db/queries/metrics.d.ts +1 -1
- package/dist/src/db/queries/metrics.js +2 -1
- package/dist/src/db/queries/metrics.js.map +2 -2
- package/dist/src/db/queries/subgraphs.d.ts +1 -1
- package/dist/src/db/queries/subgraphs.js +2 -1
- package/dist/src/db/queries/subgraphs.js.map +2 -2
- package/dist/src/db/queries/usage.d.ts +1 -1
- package/dist/src/db/queries/usage.js +2 -1
- package/dist/src/db/queries/usage.js.map +2 -2
- package/dist/src/db/schema.d.ts +1 -1
- package/dist/src/env.js +2 -1
- package/dist/src/env.js.map +2 -2
- package/dist/src/errors.js +2 -1
- package/dist/src/errors.js.map +2 -2
- package/dist/src/index.d.ts +1 -1
- package/dist/src/index.js +3 -2
- package/dist/src/index.js.map +3 -3
- package/dist/src/lib/plans.js +2 -1
- package/dist/src/lib/plans.js.map +2 -2
- package/dist/src/logger.js +2 -1
- package/dist/src/logger.js.map +2 -2
- package/dist/src/node/archive-client.d.ts +25 -0
- package/dist/src/node/archive-client.js +288 -0
- package/dist/src/node/archive-client.js.map +12 -0
- package/dist/src/node/client.js +2 -1
- package/dist/src/node/client.js.map +2 -2
- package/dist/src/node/hiro-client.js +3 -2
- package/dist/src/node/hiro-client.js.map +3 -3
- package/dist/src/node/hiro-pg-client.d.ts +21 -0
- package/dist/src/node/hiro-pg-client.js +439 -0
- package/dist/src/node/hiro-pg-client.js.map +10 -0
- package/dist/src/node/local-client.d.ts +1 -1
- package/dist/src/node/local-client.js +2 -1
- package/dist/src/node/local-client.js.map +2 -2
- package/dist/src/queue/index.js +2 -1
- package/dist/src/queue/index.js.map +2 -2
- package/dist/src/queue/listener.js +2 -1
- package/dist/src/queue/listener.js.map +2 -2
- package/dist/src/queue/recovery.js +2 -1
- package/dist/src/queue/recovery.js.map +2 -2
- package/dist/src/schemas/filters.js +2 -1
- package/dist/src/schemas/filters.js.map +2 -2
- package/dist/src/schemas/index.js +3 -2
- package/dist/src/schemas/index.js.map +3 -3
- package/dist/src/schemas/subgraphs.js +2 -1
- package/dist/src/schemas/subgraphs.js.map +2 -2
- package/package.json +14 -6
|
@@ -0,0 +1,10 @@
|
|
|
1
|
+
{
|
|
2
|
+
"version": 3,
|
|
3
|
+
"sources": ["../src/node/hiro-pg-client.ts"],
|
|
4
|
+
"sourcesContent": [
|
|
5
|
+
"/**\n * Direct Postgres client for reading from a local Hiro API database.\n *\n * Bypasses the Hiro HTTP API entirely — queries the stacks_blockchain_api\n * schema directly. Orders of magnitude faster for bulk backfill since we\n * avoid per-tx HTTP round-trips and the API's slow UNION event queries.\n *\n * Expects HIRO_PG_URL env var pointing to the Hiro API database, e.g.:\n * postgres://secondlayer:pass@localhost:5432/stacks_blockchain_api\n */\n\nimport postgres from \"postgres\";\n\nconst SCHEMA = \"stacks_blockchain_api\";\n\n// Hiro DB stores bytea; we need 0x-prefixed hex strings\nfunction toHex(buf: Buffer | Uint8Array | null): string {\n if (!buf) return \"0x\";\n return \"0x\" + Buffer.from(buf).toString(\"hex\");\n}\n\n// asset_event_type_id mapping: 1=transfer, 2=mint, 3=burn\nfunction stxEventType(assetTypeId: number): string {\n switch (assetTypeId) {\n case 1: return \"stx_transfer_event\";\n case 2: return \"stx_mint_event\";\n case 3: return \"stx_burn_event\";\n default: return \"stx_transfer_event\";\n }\n}\n\nfunction ftEventType(assetTypeId: number): string {\n switch (assetTypeId) {\n case 1: return \"ft_transfer_event\";\n case 2: return \"ft_mint_event\";\n case 3: return \"ft_burn_event\";\n default: return \"ft_transfer_event\";\n }\n}\n\nfunction nftEventType(assetTypeId: number): string {\n switch (assetTypeId) {\n case 1: return \"nft_transfer_event\";\n case 2: return \"nft_mint_event\";\n case 3: return \"nft_burn_event\";\n default: return \"nft_transfer_event\";\n }\n}\n\n// Hiro tx type_id mapping\nfunction mapTxTypeId(typeId: number): string {\n switch (typeId) {\n case 0: return \"token_transfer\";\n case 1: return \"smart_contract\";\n case 2: return \"contract_call\";\n case 3: return \"poison_microblock\";\n case 4: return \"coinbase\";\n case 5: return \"coinbase\"; // coinbase-pay-to-alt\n case 6: return \"smart_contract\"; // versioned\n case 7: return \"tenure_change\";\n case 8: return \"coinbase\"; // nakamoto coinbase\n default: return \"token_transfer\";\n }\n}\n\n// Hiro tx status mapping\nfunction mapTxStatus(status: number): string {\n switch (status) {\n case 1: return \"success\";\n case 0: return \"abort_by_response\";\n default: return \"abort_by_post_condition\";\n }\n}\n\ninterface BlockRow {\n block_hash: Buffer;\n block_height: number;\n index_block_hash: Buffer;\n parent_block_hash: Buffer;\n parent_index_block_hash: Buffer;\n burn_block_hash: Buffer;\n burn_block_height: number;\n burn_block_time: number;\n block_time: number;\n miner_txid: Buffer;\n}\n\ninterface TxRow {\n tx_id: Buffer;\n tx_index: number;\n type_id: number;\n status: number;\n sender_address: string;\n raw_tx: Buffer;\n event_count: number;\n contract_call_contract_id: string | null;\n contract_call_function_name: string | null;\n smart_contract_contract_id: string | null;\n}\n\nexport class HiroPgClient {\n private sql: ReturnType<typeof postgres>;\n\n constructor(connectionUrl?: string) {\n const url = connectionUrl || process.env.HIRO_PG_URL;\n if (!url) throw new Error(\"HIRO_PG_URL is required for HiroPgClient\");\n this.sql = postgres(url, {\n max: 10,\n idle_timeout: 30,\n });\n }\n\n async getChainTip(): Promise<number> {\n const rows = await this.sql`\n SELECT MAX(block_height) as tip FROM ${this.sql(SCHEMA)}.blocks WHERE canonical = true\n `;\n return Number(rows[0]?.tip ?? 0);\n }\n\n /**\n * Fetch a complete block by height directly from PG.\n * Returns data in the same NewBlockPayload shape the backfill expects.\n */\n async getBlockForIndexer(height: number, options?: { includeRawTx?: boolean }): Promise<any | null> {\n // 1. Block metadata\n const blocks = await this.sql<BlockRow[]>`\n SELECT block_hash, block_height, index_block_hash, parent_block_hash,\n parent_index_block_hash, burn_block_hash, burn_block_height,\n burn_block_time, block_time, miner_txid\n FROM ${this.sql(SCHEMA)}.blocks\n WHERE block_height = ${height} AND canonical = true\n LIMIT 1\n `;\n if (blocks.length === 0) return null;\n const block = blocks[0];\n\n // 2. Transactions\n const txs = await this.sql<TxRow[]>`\n SELECT tx_id, tx_index, type_id, status, sender_address, raw_tx, event_count,\n contract_call_contract_id, contract_call_function_name, smart_contract_contract_id\n FROM ${this.sql(SCHEMA)}.txs\n WHERE block_height = ${height} AND canonical = true AND microblock_canonical = true\n ORDER BY tx_index\n `;\n\n const transactions = txs.map((tx) => {\n const txType = mapTxTypeId(tx.type_id);\n const entry: any = {\n txid: toHex(tx.tx_id),\n raw_tx: options?.includeRawTx ? toHex(tx.raw_tx) : \"0x00\",\n status: mapTxStatus(tx.status),\n tx_index: tx.tx_index,\n tx_type: txType,\n sender_address: tx.sender_address,\n };\n if (txType === \"contract_call\" && tx.contract_call_contract_id) {\n entry.contract_call = {\n contract_id: tx.contract_call_contract_id,\n function_name: tx.contract_call_function_name || \"\",\n };\n } else if (txType === \"smart_contract\" && tx.smart_contract_contract_id) {\n entry.smart_contract = {\n contract_id: tx.smart_contract_contract_id,\n };\n }\n return entry;\n });\n\n // 3. Events — query all event tables by block_height (fast, indexed)\n const events: any[] = [];\n\n // STX events\n const stxEvents = await this.sql`\n SELECT tx_id, event_index, asset_event_type_id, amount, sender, recipient, memo\n FROM ${this.sql(SCHEMA)}.stx_events\n WHERE block_height = ${height} AND canonical = true AND microblock_canonical = true\n ORDER BY event_index\n `;\n for (const e of stxEvents) {\n const type = stxEventType(e.asset_event_type_id);\n const evt: any = { txid: toHex(e.tx_id), event_index: e.event_index, committed: true, type };\n if (type === \"stx_transfer_event\") {\n evt.stx_transfer_event = {\n sender: e.sender || \"\",\n recipient: e.recipient || \"\",\n amount: String(e.amount),\n ...(e.memo ? { memo: toHex(e.memo) } : {}),\n };\n } else if (type === \"stx_mint_event\") {\n evt.stx_mint_event = { recipient: e.recipient || \"\", amount: String(e.amount) };\n } else if (type === \"stx_burn_event\") {\n evt.stx_burn_event = { sender: e.sender || \"\", amount: String(e.amount) };\n }\n events.push(evt);\n }\n\n // STX lock events\n const lockEvents = await this.sql`\n SELECT tx_id, event_index, locked_amount, unlock_height, locked_address\n FROM ${this.sql(SCHEMA)}.stx_lock_events\n WHERE block_height = ${height} AND canonical = true AND microblock_canonical = true\n ORDER BY event_index\n `;\n for (const e of lockEvents) {\n events.push({\n txid: toHex(e.tx_id),\n event_index: e.event_index,\n committed: true,\n type: \"stx_lock_event\",\n stx_lock_event: {\n locked_amount: String(e.locked_amount),\n unlock_height: String(e.unlock_height),\n locked_address: e.locked_address,\n },\n });\n }\n\n // FT events\n const ftEvents = await this.sql`\n SELECT tx_id, event_index, asset_event_type_id, asset_identifier, amount, sender, recipient\n FROM ${this.sql(SCHEMA)}.ft_events\n WHERE block_height = ${height} AND canonical = true AND microblock_canonical = true\n ORDER BY event_index\n `;\n for (const e of ftEvents) {\n const type = ftEventType(e.asset_event_type_id);\n const evt: any = { txid: toHex(e.tx_id), event_index: e.event_index, committed: true, type };\n if (type === \"ft_transfer_event\") {\n evt.ft_transfer_event = {\n asset_identifier: e.asset_identifier,\n sender: e.sender || \"\",\n recipient: e.recipient || \"\",\n amount: String(e.amount),\n };\n } else if (type === \"ft_mint_event\") {\n evt.ft_mint_event = { asset_identifier: e.asset_identifier, recipient: e.recipient || \"\", amount: String(e.amount) };\n } else if (type === \"ft_burn_event\") {\n evt.ft_burn_event = { asset_identifier: e.asset_identifier, sender: e.sender || \"\", amount: String(e.amount) };\n }\n events.push(evt);\n }\n\n // NFT events\n const nftEvents = await this.sql`\n SELECT tx_id, event_index, asset_event_type_id, asset_identifier, value, sender, recipient\n FROM ${this.sql(SCHEMA)}.nft_events\n WHERE block_height = ${height} AND canonical = true AND microblock_canonical = true\n ORDER BY event_index\n `;\n for (const e of nftEvents) {\n const type = nftEventType(e.asset_event_type_id);\n const evt: any = { txid: toHex(e.tx_id), event_index: e.event_index, committed: true, type };\n const val = toHex(e.value);\n if (type === \"nft_transfer_event\") {\n evt.nft_transfer_event = { asset_identifier: e.asset_identifier, sender: e.sender || \"\", recipient: e.recipient || \"\", value: val };\n } else if (type === \"nft_mint_event\") {\n evt.nft_mint_event = { asset_identifier: e.asset_identifier, recipient: e.recipient || \"\", value: val };\n } else if (type === \"nft_burn_event\") {\n evt.nft_burn_event = { asset_identifier: e.asset_identifier, sender: e.sender || \"\", value: val };\n }\n events.push(evt);\n }\n\n // Contract log events\n const logEvents = await this.sql`\n SELECT tx_id, event_index, contract_identifier, topic, value\n FROM ${this.sql(SCHEMA)}.contract_logs\n WHERE block_height = ${height} AND canonical = true AND microblock_canonical = true\n ORDER BY event_index\n `;\n for (const e of logEvents) {\n events.push({\n txid: toHex(e.tx_id),\n event_index: e.event_index,\n committed: true,\n type: \"smart_contract_event\",\n smart_contract_event: {\n contract_identifier: e.contract_identifier,\n topic: e.topic,\n value: toHex(e.value),\n },\n });\n }\n\n return {\n block_hash: toHex(block.block_hash),\n block_height: block.block_height,\n index_block_hash: toHex(block.index_block_hash),\n parent_block_hash: toHex(block.parent_block_hash),\n parent_index_block_hash: toHex(block.parent_index_block_hash),\n burn_block_hash: toHex(block.burn_block_hash),\n burn_block_height: block.burn_block_height,\n burn_block_timestamp: block.burn_block_time,\n miner_txid: toHex(block.miner_txid),\n timestamp: block.block_time,\n transactions,\n events,\n };\n }\n\n /**\n * Fetch multiple blocks in bulk — 6 queries total instead of 6 per block.\n * Returns array of NewBlockPayload in height order.\n */\n async getBlockBatch(heights: number[], options?: { includeRawTx?: boolean }): Promise<any[]> {\n if (heights.length === 0) return [];\n\n // 1. All blocks in range\n const blocks = await this.sql`\n SELECT block_hash, block_height, index_block_hash, parent_block_hash,\n parent_index_block_hash, burn_block_hash, burn_block_height,\n burn_block_time, block_time, miner_txid\n FROM ${this.sql(SCHEMA)}.blocks\n WHERE block_height = ANY(${heights}) AND canonical = true\n `;\n\n if (blocks.length === 0) return [];\n const blockMap = new Map<number, any>();\n for (const b of blocks) {\n blockMap.set(b.block_height, { ...b, transactions: [], events: [] });\n }\n\n // 2. All transactions\n const txs = await this.sql`\n SELECT tx_id, tx_index, type_id, status, sender_address, raw_tx, event_count, block_height,\n contract_call_contract_id, contract_call_function_name, smart_contract_contract_id\n FROM ${this.sql(SCHEMA)}.txs\n WHERE block_height = ANY(${heights}) AND canonical = true AND microblock_canonical = true\n ORDER BY block_height, tx_index\n `;\n for (const tx of txs) {\n const block = blockMap.get(tx.block_height);\n if (!block) continue;\n const txType = mapTxTypeId(tx.type_id);\n const entry: any = {\n txid: toHex(tx.tx_id),\n raw_tx: options?.includeRawTx ? toHex(tx.raw_tx) : \"0x00\",\n status: mapTxStatus(tx.status),\n tx_index: tx.tx_index,\n tx_type: txType,\n sender_address: tx.sender_address,\n };\n if (txType === \"contract_call\" && tx.contract_call_contract_id) {\n entry.contract_call = { contract_id: tx.contract_call_contract_id, function_name: tx.contract_call_function_name || \"\" };\n } else if (txType === \"smart_contract\" && tx.smart_contract_contract_id) {\n entry.smart_contract = { contract_id: tx.smart_contract_contract_id };\n }\n block.transactions.push(entry);\n }\n\n // 3. STX events\n const stxEvents = await this.sql`\n SELECT tx_id, event_index, asset_event_type_id, amount, sender, recipient, memo, block_height\n FROM ${this.sql(SCHEMA)}.stx_events\n WHERE block_height = ANY(${heights}) AND canonical = true AND microblock_canonical = true\n `;\n for (const e of stxEvents) {\n const block = blockMap.get(e.block_height);\n if (!block) continue;\n const type = stxEventType(e.asset_event_type_id);\n const evt: any = { txid: toHex(e.tx_id), event_index: e.event_index, committed: true, type };\n if (type === \"stx_transfer_event\") {\n evt.stx_transfer_event = { sender: e.sender || \"\", recipient: e.recipient || \"\", amount: String(e.amount), ...(e.memo ? { memo: toHex(e.memo) } : {}) };\n } else if (type === \"stx_mint_event\") {\n evt.stx_mint_event = { recipient: e.recipient || \"\", amount: String(e.amount) };\n } else if (type === \"stx_burn_event\") {\n evt.stx_burn_event = { sender: e.sender || \"\", amount: String(e.amount) };\n }\n block.events.push(evt);\n }\n\n // 4. STX lock events\n const lockEvents = await this.sql`\n SELECT tx_id, event_index, locked_amount, unlock_height, locked_address, block_height\n FROM ${this.sql(SCHEMA)}.stx_lock_events\n WHERE block_height = ANY(${heights}) AND canonical = true AND microblock_canonical = true\n `;\n for (const e of lockEvents) {\n const block = blockMap.get(e.block_height);\n if (!block) continue;\n block.events.push({\n txid: toHex(e.tx_id), event_index: e.event_index, committed: true, type: \"stx_lock_event\",\n stx_lock_event: { locked_amount: String(e.locked_amount), unlock_height: String(e.unlock_height), locked_address: e.locked_address },\n });\n }\n\n // 5. FT events\n const ftEvents = await this.sql`\n SELECT tx_id, event_index, asset_event_type_id, asset_identifier, amount, sender, recipient, block_height\n FROM ${this.sql(SCHEMA)}.ft_events\n WHERE block_height = ANY(${heights}) AND canonical = true AND microblock_canonical = true\n `;\n for (const e of ftEvents) {\n const block = blockMap.get(e.block_height);\n if (!block) continue;\n const type = ftEventType(e.asset_event_type_id);\n const evt: any = { txid: toHex(e.tx_id), event_index: e.event_index, committed: true, type };\n if (type === \"ft_transfer_event\") {\n evt.ft_transfer_event = { asset_identifier: e.asset_identifier, sender: e.sender || \"\", recipient: e.recipient || \"\", amount: String(e.amount) };\n } else if (type === \"ft_mint_event\") {\n evt.ft_mint_event = { asset_identifier: e.asset_identifier, recipient: e.recipient || \"\", amount: String(e.amount) };\n } else if (type === \"ft_burn_event\") {\n evt.ft_burn_event = { asset_identifier: e.asset_identifier, sender: e.sender || \"\", amount: String(e.amount) };\n }\n block.events.push(evt);\n }\n\n // 6. NFT events\n const nftEvents = await this.sql`\n SELECT tx_id, event_index, asset_event_type_id, asset_identifier, value, sender, recipient, block_height\n FROM ${this.sql(SCHEMA)}.nft_events\n WHERE block_height = ANY(${heights}) AND canonical = true AND microblock_canonical = true\n `;\n for (const e of nftEvents) {\n const block = blockMap.get(e.block_height);\n if (!block) continue;\n const type = nftEventType(e.asset_event_type_id);\n const evt: any = { txid: toHex(e.tx_id), event_index: e.event_index, committed: true, type };\n const val = toHex(e.value);\n if (type === \"nft_transfer_event\") {\n evt.nft_transfer_event = { asset_identifier: e.asset_identifier, sender: e.sender || \"\", recipient: e.recipient || \"\", value: val };\n } else if (type === \"nft_mint_event\") {\n evt.nft_mint_event = { asset_identifier: e.asset_identifier, recipient: e.recipient || \"\", value: val };\n } else if (type === \"nft_burn_event\") {\n evt.nft_burn_event = { asset_identifier: e.asset_identifier, sender: e.sender || \"\", value: val };\n }\n block.events.push(evt);\n }\n\n // 7. Contract log events\n const logEvents = await this.sql`\n SELECT tx_id, event_index, contract_identifier, topic, value, block_height\n FROM ${this.sql(SCHEMA)}.contract_logs\n WHERE block_height = ANY(${heights}) AND canonical = true AND microblock_canonical = true\n `;\n for (const e of logEvents) {\n const block = blockMap.get(e.block_height);\n if (!block) continue;\n block.events.push({\n txid: toHex(e.tx_id), event_index: e.event_index, committed: true, type: \"smart_contract_event\",\n smart_contract_event: { contract_identifier: e.contract_identifier, topic: e.topic, value: toHex(e.value) },\n });\n }\n\n // Build results in height order\n return heights\n .filter((h) => blockMap.has(h))\n .map((h) => {\n const b = blockMap.get(h)!;\n return {\n block_hash: toHex(b.block_hash),\n block_height: b.block_height,\n index_block_hash: toHex(b.index_block_hash),\n parent_block_hash: toHex(b.parent_block_hash),\n parent_index_block_hash: toHex(b.parent_index_block_hash),\n burn_block_hash: toHex(b.burn_block_hash),\n burn_block_height: b.burn_block_height,\n burn_block_timestamp: b.burn_block_time,\n miner_txid: toHex(b.miner_txid),\n timestamp: b.block_time,\n transactions: b.transactions,\n events: b.events,\n };\n });\n }\n\n async close(): Promise<void> {\n await this.sql.end();\n }\n}\n"
|
|
6
|
+
],
|
|
7
|
+
"mappings": ";;;;;;;;;;;;;;;;;;AAWA;AAEA,IAAM,SAAS;AAGf,SAAS,KAAK,CAAC,KAAyC;AAAA,EACtD,IAAI,CAAC;AAAA,IAAK,OAAO;AAAA,EACjB,OAAO,OAAO,OAAO,KAAK,GAAG,EAAE,SAAS,KAAK;AAAA;AAI/C,SAAS,YAAY,CAAC,aAA6B;AAAA,EACjD,QAAQ;AAAA,SACD;AAAA,MAAG,OAAO;AAAA,SACV;AAAA,MAAG,OAAO;AAAA,SACV;AAAA,MAAG,OAAO;AAAA;AAAA,MACN,OAAO;AAAA;AAAA;AAIpB,SAAS,WAAW,CAAC,aAA6B;AAAA,EAChD,QAAQ;AAAA,SACD;AAAA,MAAG,OAAO;AAAA,SACV;AAAA,MAAG,OAAO;AAAA,SACV;AAAA,MAAG,OAAO;AAAA;AAAA,MACN,OAAO;AAAA;AAAA;AAIpB,SAAS,YAAY,CAAC,aAA6B;AAAA,EACjD,QAAQ;AAAA,SACD;AAAA,MAAG,OAAO;AAAA,SACV;AAAA,MAAG,OAAO;AAAA,SACV;AAAA,MAAG,OAAO;AAAA;AAAA,MACN,OAAO;AAAA;AAAA;AAKpB,SAAS,WAAW,CAAC,QAAwB;AAAA,EAC3C,QAAQ;AAAA,SACD;AAAA,MAAG,OAAO;AAAA,SACV;AAAA,MAAG,OAAO;AAAA,SACV;AAAA,MAAG,OAAO;AAAA,SACV;AAAA,MAAG,OAAO;AAAA,SACV;AAAA,MAAG,OAAO;AAAA,SACV;AAAA,MAAG,OAAO;AAAA,SACV;AAAA,MAAG,OAAO;AAAA,SACV;AAAA,MAAG,OAAO;AAAA,SACV;AAAA,MAAG,OAAO;AAAA;AAAA,MACN,OAA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BAAqB,OAAO,EAAE,OAAO,OAAO,MAAM,EAAE,KAAK,EAAE;AAAA,MAC5G,CAAC;AAAA,IACH;AAAA,IAGA,OAAO,QACJ,OAAO,CAAC,MAAM,SAAS,IAAI,CAAC,CAAC,EAC7B,IAAI,CAAC,MAAM;AAAA,MACV,MAAM,IAAI,SAAS,IAAI,CAAC;AAAA,MACxB,OAAO;AAAA,QACL,YAAY,MAAM,EAAE,UAAU;AAAA,QAC9B,cAAc,EAAE;AAAA,QAChB,kBAAkB,MAAM,EAAE,gBAAgB;AAAA,QAC1C,mBAAmB,MAAM,EAAE,iBAAiB;AAAA,QAC5C,yBAAyB,MAAM,EAAE,uBAAuB;AAAA,QACxD,iBAAiB,MAAM,EAAE,eAAe;AAAA,QACxC,mBAAmB,EAAE;AAAA,QACrB,sBAAsB,EAAE;AAAA,QACxB,YAAY,MAAM,EAAE,UAAU;AAAA,QAC9B,WAAW,EAAE;AAAA,QACb,cAAc,EAAE;AAAA,QAChB,QAAQ,EAAE;AAAA,MACZ;AAAA,KACD;AAAA;AAAA,OAGC,MAAK,GAAkB;AAAA,IAC3B,MAAM,KAAK,IAAI,IAAI;AAAA;AAEvB;",
|
|
8
|
+
"debugId": "60C656DFEAB92D4E64756E2164756E21",
|
|
9
|
+
"names": []
|
|
10
|
+
}
|
|
@@ -13,6 +13,7 @@ var __export = (target, all) => {
|
|
|
13
13
|
set: __exportSetter.bind(all, name)
|
|
14
14
|
});
|
|
15
15
|
};
|
|
16
|
+
var __require = /* @__PURE__ */ createRequire(import.meta.url);
|
|
16
17
|
|
|
17
18
|
// src/node/local-client.ts
|
|
18
19
|
class LocalClient {
|
|
@@ -70,5 +71,5 @@ export {
|
|
|
70
71
|
LocalClient
|
|
71
72
|
};
|
|
72
73
|
|
|
73
|
-
//# debugId=
|
|
74
|
+
//# debugId=147ABF16EE47670D64756E2164756E21
|
|
74
75
|
//# sourceMappingURL=local-client.js.map
|
|
@@ -4,7 +4,7 @@
|
|
|
4
4
|
"sourcesContent": [
|
|
5
5
|
"/**\n * Local replay client — reconstructs NewBlockPayload from our own Postgres.\n *\n * Used for re-orgs, reprocessing, and self-serve replay after genesis sync.\n * Eliminates need for self-hosted Hiro API for blocks already in our DB.\n */\n\nimport type { Kysely } from \"kysely\";\nimport type { Database } from \"../db/types.ts\";\n\n/** Matches the NewBlockPayload shape expected by the indexer's /new_block endpoint */\nexport interface ReplayBlockPayload {\n block_hash: string;\n block_height: number;\n index_block_hash: string;\n parent_block_hash: string;\n parent_index_block_hash: string;\n burn_block_hash: string;\n burn_block_height: number;\n burn_block_timestamp: number;\n miner_txid: string;\n timestamp: number;\n transactions: ReplayTransactionPayload[];\n events: ReplayEventPayload[];\n}\n\ninterface ReplayTransactionPayload {\n txid: string;\n raw_tx: string;\n status: string;\n tx_index: number;\n tx_type?: string;\n sender_address?: string;\n}\n\ninterface ReplayEventPayload {\n txid: string;\n event_index: number;\n committed: boolean;\n type: string;\n [key: string]: unknown;\n}\n\nexport class LocalClient {\n /**\n * Reconstruct a NewBlockPayload from local DB for replay.\n * Returns null if block not found.\n */\n async getBlockForReplay(db: Kysely<Database>, height: number): Promise<ReplayBlockPayload | null> {\n const block = await db\n .selectFrom(\"blocks\")\n .selectAll()\n .where(\"height\", \"=\", height)\n .where(\"canonical\", \"=\", true)\n .executeTakeFirst();\n\n if (!block) return null;\n\n const transactions = await db\n .selectFrom(\"transactions\")\n .selectAll()\n .where(\"block_height\", \"=\", height)\n .orderBy(\"tx_index\", \"asc\")\n .execute();\n\n const events = await db\n .selectFrom(\"events\")\n .selectAll()\n .where(\"block_height\", \"=\", height)\n .orderBy(\"event_index\", \"asc\")\n .execute();\n\n return {\n block_hash: block.hash,\n block_height: block.height,\n // Not stored in our DB — not needed by parser/deliveries\n index_block_hash: \"\",\n parent_block_hash: block.parent_hash,\n parent_index_block_hash: \"\",\n burn_block_hash: \"\",\n burn_block_height: block.burn_block_height,\n burn_block_timestamp: block.timestamp,\n miner_txid: \"\",\n timestamp: block.timestamp,\n transactions: transactions.map((tx) => ({\n txid: tx.tx_id,\n raw_tx: tx.raw_tx,\n status: tx.status,\n tx_index: tx.tx_index,\n tx_type: tx.type,\n sender_address: tx.sender,\n })),\n events: events.map((evt) => {\n const data = (evt.data ?? {}) as Record<string, unknown>;\n const eventType = evt.type;\n\n // Reconstruct the flat event structure the indexer expects:\n // { txid, event_index, committed, type, [type_key]: data }\n const payload: ReplayEventPayload = {\n txid: evt.tx_id,\n event_index: evt.event_index,\n committed: true,\n type: eventType,\n };\n\n // Attach event-specific data under the correct key\n if (eventType && data) {\n payload[eventType] = data;\n }\n\n return payload;\n }),\n };\n }\n\n /** Get highest block height in local DB */\n async getChainTip(db: Kysely<Database>): Promise<number> {\n const row = await db\n .selectFrom(\"blocks\")\n .select((eb) => eb.fn.max(\"height\").as(\"max_height\"))\n .where(\"canonical\", \"=\", true)\n .executeTakeFirst();\n return Number(row?.max_height ?? 0);\n }\n\n /** Check if a specific block height exists in local DB */\n async hasBlock(db: Kysely<Database>, height: number): Promise<boolean> {\n const row = await db\n .selectFrom(\"blocks\")\n .select(\"height\")\n .where(\"height\", \"=\", height)\n .where(\"canonical\", \"=\", true)\n .executeTakeFirst();\n return !!row;\n }\n}\n"
|
|
6
6
|
],
|
|
7
|
-
"mappings": "
|
|
8
|
-
"debugId": "
|
|
7
|
+
"mappings": ";;;;;;;;;;;;;;;;;;AA2CO,MAAM,YAAY;AAAA,OAKjB,kBAAiB,CAAC,IAAsB,QAAoD;AAAA,IAChG,MAAM,QAAQ,MAAM,GACjB,WAAW,QAAQ,EACnB,UAAU,EACV,MAAM,UAAU,KAAK,MAAM,EAC3B,MAAM,aAAa,KAAK,IAAI,EAC5B,iBAAiB;AAAA,IAEpB,IAAI,CAAC;AAAA,MAAO,OAAO;AAAA,IAEnB,MAAM,eAAe,MAAM,GACxB,WAAW,cAAc,EACzB,UAAU,EACV,MAAM,gBAAgB,KAAK,MAAM,EACjC,QAAQ,YAAY,KAAK,EACzB,QAAQ;AAAA,I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AAM,MAAM,MAAM,GACf,WAAW,QAAQ,EACnB,OAAO,QAAQ,EACf,MAAM,UAAU,KAAK,MAAM,EAC3B,MAAM,aAAa,KAAK,IAAI,EAC5B,iBAAiB;AAAA,IACpB,OAAO,CAAC,CAAC;AAAA;AAEb;",
|
|
8
|
+
"debugId": "147ABF16EE47670D64756E2164756E21",
|
|
9
9
|
"names": []
|
|
10
10
|
}
|
package/dist/src/queue/index.js
CHANGED
|
@@ -13,6 +13,7 @@ var __export = (target, all) => {
|
|
|
13
13
|
set: __exportSetter.bind(all, name)
|
|
14
14
|
});
|
|
15
15
|
};
|
|
16
|
+
var __require = /* @__PURE__ */ createRequire(import.meta.url);
|
|
16
17
|
|
|
17
18
|
// src/db/jsonb.ts
|
|
18
19
|
import { sql } from "kysely";
|
|
@@ -176,5 +177,5 @@ export {
|
|
|
176
177
|
WORKER_ID
|
|
177
178
|
};
|
|
178
179
|
|
|
179
|
-
//# debugId=
|
|
180
|
+
//# debugId=81AE2ABDE8B335F564756E2164756E21
|
|
180
181
|
//# sourceMappingURL=index.js.map
|
|
@@ -6,7 +6,7 @@
|
|
|
6
6
|
"import { Kysely } from \"kysely\";\nimport { PostgresJSDialect } from \"kysely-postgres-js\";\nimport postgres from \"postgres\";\nimport type { Database } from \"./types.ts\";\n\nlet db: Kysely<Database> | null = null;\nlet rawClient: ReturnType<typeof postgres> | null = null;\n\nexport function getDb(connectionString?: string): Kysely<Database> {\n if (!db) {\n const url = connectionString || process.env.DATABASE_URL || \"postgres://postgres:postgres@localhost:5432/streams_dev\";\n\n // Always use SSL for remote databases, just disable cert verification if needed\n const isLocal = url.includes(\"localhost\") || url.includes(\"127.0.0.1\") || url.includes(\"@postgres:\");\n rawClient = postgres(url, {\n ssl: isLocal ? undefined : { rejectUnauthorized: process.env.NODE_TLS_REJECT_UNAUTHORIZED !== \"0\" },\n });\n db = new Kysely<Database>({\n dialect: new PostgresJSDialect({ postgres: rawClient }),\n });\n }\n return db;\n}\n\n/** Raw postgres.js client for dynamic schema DDL (CREATE SCHEMA, DROP, etc.) */\nexport function getRawClient(): ReturnType<typeof postgres> {\n if (!rawClient) getDb();\n return rawClient!;\n}\n\n/** Close the DB connection pool. Call in CLI commands to allow process exit. */\nexport async function closeDb(): Promise<void> {\n if (db) {\n await db.destroy();\n db = null;\n }\n if (rawClient) {\n await rawClient.end();\n rawClient = null;\n }\n}\n\nimport { sql } from \"kysely\";\nexport { sql };\nexport * from \"./types.ts\";\nexport { jsonb, parseJsonb } from \"./jsonb.ts\";\n",
|
|
7
7
|
"import { sql } from \"kysely\";\nimport { getDb } from \"../db/index.ts\";\nimport type { Job } from \"../db/types.ts\";\nimport { randomUUID } from \"crypto\";\n\nexport interface QueueStats {\n pending: number;\n processing: number;\n completed: number;\n failed: number;\n total: number;\n}\n\n// Worker identifier for this process\nconst WORKER_ID: string = `worker-${randomUUID().slice(0, 8)}`;\n\n/**\n * Enqueue a new job for stream evaluation\n */\nexport async function enqueue(\n streamId: string,\n blockHeight: number,\n backfill = false\n): Promise<string> {\n const db = getDb();\n\n const row = await db\n .insertInto(\"jobs\")\n .values({\n stream_id: streamId,\n block_height: blockHeight,\n backfill,\n status: \"pending\",\n attempts: 0,\n })\n .returning([\"id\"])\n .executeTakeFirstOrThrow();\n\n return row.id;\n}\n\n/**\n * Claim a pending job using SKIP LOCKED to prevent concurrent access\n * Returns null if no jobs available\n */\nexport async function claim(): Promise<Job | null> {\n const db = getDb();\n\n const { rows } = await sql<Job>`\n UPDATE jobs\n SET\n status = 'processing',\n locked_at = NOW(),\n locked_by = ${WORKER_ID},\n attempts = attempts + 1\n WHERE id = (\n SELECT id FROM jobs\n WHERE status = 'pending'\n ORDER BY\n backfill ASC,\n block_height ASC,\n created_at ASC\n FOR UPDATE SKIP LOCKED\n LIMIT 1\n )\n RETURNING *\n `.execute(db);\n\n return rows[0] ?? null;\n}\n\n/**\n * Mark a job as completed\n */\nexport async function complete(jobId: string): Promise<void> {\n const db = getDb();\n\n await db\n .updateTable(\"jobs\")\n .set({\n status: \"completed\",\n completed_at: new Date(),\n locked_at: null,\n locked_by: null,\n })\n .where(\"id\", \"=\", jobId)\n .execute();\n}\n\n/**\n * Mark a job as failed\n * Re-queues if under max attempts, otherwise marks as permanently failed\n */\nexport async function fail(\n jobId: string,\n error: string,\n maxAttempts = 3\n): Promise<void> {\n const db = getDb();\n\n const job = await db\n .selectFrom(\"jobs\")\n .select(\"attempts\")\n .where(\"id\", \"=\", jobId)\n .executeTakeFirst();\n\n if (!job) return;\n\n if (job.attempts < maxAttempts) {\n await db\n .updateTable(\"jobs\")\n .set({\n status: \"pending\",\n error,\n locked_at: null,\n locked_by: null,\n })\n .where(\"id\", \"=\", jobId)\n .execute();\n } else {\n await db\n .updateTable(\"jobs\")\n .set({\n status: \"failed\",\n error,\n completed_at: new Date(),\n locked_at: null,\n locked_by: null,\n })\n .where(\"id\", \"=\", jobId)\n .execute();\n }\n}\n\n/**\n * Get queue statistics\n */\nexport async function stats(): Promise<QueueStats> {\n const { rows } = await sql<{ status: string; count: string }>`\n SELECT status, COUNT(*) as count\n FROM jobs\n GROUP BY status\n `.execute(getDb());\n\n const counts: Record<string, number> = {};\n for (const row of rows) {\n counts[row.status] = parseInt(row.count, 10);\n }\n\n return {\n pending: counts[\"pending\"] || 0,\n processing: counts[\"processing\"] || 0,\n completed: counts[\"completed\"] || 0,\n failed: counts[\"failed\"] || 0,\n total: Object.values(counts).reduce((a, b) => a + b, 0),\n };\n}\n\n/**\n * Get worker ID for this process\n */\nexport function getWorkerId(): string {\n return WORKER_ID;\n}\n\nexport { WORKER_ID };\n"
|
|
8
8
|
],
|
|
9
|
-
"mappings": "
|
|
10
|
-
"debugId": "
|
|
9
|
+
"mappings": ";;;;;;;;;;;;;;;;;;AAAA;AAOO,SAAS,KAAK,CAAC,OAAqC;AAAA,EACzD,MAAM,UAAU,KAAK,UAAU,KAAK,EAAE,QAAQ,MAAM,IAAI;AAAA,EACxD,OAAO,MAAM,IAAI,IAAI,IAAI,iB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AA,MACH,QAAQ;AAAA,MACR;AAAA,MACA,cAAc,IAAI;AAAA,MAClB,WAAW;AAAA,MACX,WAAW;AAAA,IACb,CAAC,EACA,MAAM,MAAM,KAAK,KAAK,EACtB,QAAQ;AAAA;AAAA;AAOf,eAAsB,KAAK,GAAwB;AAAA,EACjD,QAAQ,SAAS,MAAM;AAAA;AAAA;AAAA;AAAA,IAIrB,QAAQ,MAAM,CAAC;AAAA,EAEjB,MAAM,SAAiC,CAAC;AAAA,EACxC,WAAW,OAAO,MAAM;AAAA,IACtB,OAAO,IAAI,UAAU,SAAS,IAAI,OAAO,EAAE;AAAA,EAC7C;AAAA,EAEA,OAAO;AAAA,IACL,SAAS,OAAO,cAAc;AAAA,IAC9B,YAAY,OAAO,iBAAiB;AAAA,IACpC,WAAW,OAAO,gBAAgB;AAAA,IAClC,QAAQ,OAAO,aAAa;AAAA,IAC5B,OAAO,OAAO,OAAO,MAAM,EAAE,OAAO,CAAC,GAAG,MAAM,IAAI,GAAG,CAAC;AAAA,EACxD;AAAA;AAMK,SAAS,WAAW,GAAW;AAAA,EACpC,OAAO;AAAA;",
|
|
10
|
+
"debugId": "81AE2ABDE8B335F564756E2164756E21",
|
|
11
11
|
"names": []
|
|
12
12
|
}
|
|
@@ -13,6 +13,7 @@ var __export = (target, all) => {
|
|
|
13
13
|
set: __exportSetter.bind(all, name)
|
|
14
14
|
});
|
|
15
15
|
};
|
|
16
|
+
var __require = /* @__PURE__ */ createRequire(import.meta.url);
|
|
16
17
|
|
|
17
18
|
// src/queue/listener.ts
|
|
18
19
|
import postgres from "postgres";
|
|
@@ -63,5 +64,5 @@ export {
|
|
|
63
64
|
CHANNEL_NEW_JOB
|
|
64
65
|
};
|
|
65
66
|
|
|
66
|
-
//# debugId=
|
|
67
|
+
//# debugId=46551B1075461F0164756E2164756E21
|
|
67
68
|
//# sourceMappingURL=listener.js.map
|
|
@@ -4,7 +4,7 @@
|
|
|
4
4
|
"sourcesContent": [
|
|
5
5
|
"import postgres from \"postgres\";\n\nconst CHANNEL_NEW_JOB = \"streams:new_job\";\n\n/**\n * Listen for notifications on a channel\n * Uses a dedicated connection for LISTEN\n */\nexport async function listen(\n channel: string,\n callback: (payload?: string) => void\n): Promise<() => Promise<void>> {\n const connectionString = process.env.DATABASE_URL;\n if (!connectionString) {\n throw new Error(\"DATABASE_URL is required\");\n }\n\n // Each listener gets its own connection\n const client = postgres(connectionString, {\n max: 1,\n onnotice: () => {}, // Ignore notices\n });\n\n await client.listen(channel, (payload) => {\n callback(payload);\n });\n\n // Return cleanup function\n return async () => {\n await client.end();\n };\n}\n\n/**\n * Send a notification on a channel\n */\nexport async function notify(\n channel: string,\n payload?: string\n): Promise<void> {\n const connectionString = process.env.DATABASE_URL;\n if (!connectionString) {\n throw new Error(\"DATABASE_URL is required\");\n }\n\n const client = postgres(connectionString, { max: 1 });\n\n try {\n if (payload) {\n await client`SELECT pg_notify(${channel}, ${payload})`;\n } else {\n await client`SELECT pg_notify(${channel}, '')`;\n }\n } finally {\n await client.end();\n }\n}\n\n/**\n * Listen for new job notifications\n * Convenience wrapper for the common use case\n */\nexport async function listenForJobs(\n callback: (payload?: string) => void\n): Promise<() => Promise<void>> {\n return listen(CHANNEL_NEW_JOB, callback);\n}\n\n/**\n * Notify workers about new jobs\n */\nexport async function notifyNewJob(streamId?: string): Promise<void> {\n return notify(CHANNEL_NEW_JOB, streamId);\n}\n\nexport { CHANNEL_NEW_JOB };\n"
|
|
6
6
|
],
|
|
7
|
-
"mappings": "
|
|
8
|
-
"debugId": "
|
|
7
|
+
"mappings": ";;;;;;;;;;;;;;;;;;AAAA;AAEA,IAAM,kBAAkB;AAMxB,eAAsB,MAAM,CAC1B,SACA,UAC8B;AAAA,EAC9B,MAAM,mBAAmB,QAAQ,IAAI;AAAA,EACrC,IAAI,CAAC,kBAAkB;AAAA,IACrB,MAAM,IAAI,MAAM,0BAA0B;AAAA,EAC5C;AAAA,EAGA,MAAM,SAAS,SAAS,kBAAkB;AAAA,IACxC,KAAK;AAAA,IACL,UAAU,MAAM;AAAA,EAClB,CAAC;AAAA,EAED,MAAM,OAAO,OAAO,SAAS,CAAC,YAAY;AAAA,IACxC,SAAS,OAAO;AAAA,GACjB;AAAA,EAGD,OAAO,YAAY;AAAA,IACjB,MAAM,OAAO,IAAI;AAAA;AAAA;AAOrB,eAAsB,MAAM,CAC1B,SACA,SACe;AAAA,EACf,MAAM,mBAAmB,QAAQ,IAAI;AAAA,EACrC,IAAI,CAAC,kBAAkB;AAAA,IACrB,MAAM,IAAI,MAAM,0BAA0B;AAAA,EAC5C;AAAA,EAEA,MAAM,SAAS,SAAS,kBAAkB,EAAE,KAAK,EAAE,CAAC;AAAA,EAEpD,IAAI;AAAA,IACF,IAAI,SAAS;AAAA,MACX,MAAM,0BAA0B,YAAY;AAAA,IAC9C,EAAO;AAAA,MACL,MAAM,0BAA0B;AAAA;AAAA,YAElC;AAAA,IACA,MAAM,OAAO,IAAI;AAAA;AAAA;AAQrB,eAAsB,aAAa,CACjC,UAC8B;AAAA,EAC9B,OAAO,OAAO,iBAAiB,QAAQ;AAAA;AAMzC,eAAsB,YAAY,CAAC,UAAkC;AAAA,EACnE,OAAO,OAAO,iBAAiB,QAAQ;AAAA;",
|
|
8
|
+
"debugId": "46551B1075461F0164756E2164756E21",
|
|
9
9
|
"names": []
|
|
10
10
|
}
|
|
@@ -13,6 +13,7 @@ var __export = (target, all) => {
|
|
|
13
13
|
set: __exportSetter.bind(all, name)
|
|
14
14
|
});
|
|
15
15
|
};
|
|
16
|
+
var __require = /* @__PURE__ */ createRequire(import.meta.url);
|
|
16
17
|
|
|
17
18
|
// src/db/jsonb.ts
|
|
18
19
|
import { sql } from "kysely";
|
|
@@ -100,5 +101,5 @@ export {
|
|
|
100
101
|
recoverStaleJobs
|
|
101
102
|
};
|
|
102
103
|
|
|
103
|
-
//# debugId=
|
|
104
|
+
//# debugId=FC85FE33032D8FFF64756E2164756E21
|
|
104
105
|
//# sourceMappingURL=recovery.js.map
|
|
@@ -6,7 +6,7 @@
|
|
|
6
6
|
"import { Kysely } from \"kysely\";\nimport { PostgresJSDialect } from \"kysely-postgres-js\";\nimport postgres from \"postgres\";\nimport type { Database } from \"./types.ts\";\n\nlet db: Kysely<Database> | null = null;\nlet rawClient: ReturnType<typeof postgres> | null = null;\n\nexport function getDb(connectionString?: string): Kysely<Database> {\n if (!db) {\n const url = connectionString || process.env.DATABASE_URL || \"postgres://postgres:postgres@localhost:5432/streams_dev\";\n\n // Always use SSL for remote databases, just disable cert verification if needed\n const isLocal = url.includes(\"localhost\") || url.includes(\"127.0.0.1\") || url.includes(\"@postgres:\");\n rawClient = postgres(url, {\n ssl: isLocal ? undefined : { rejectUnauthorized: process.env.NODE_TLS_REJECT_UNAUTHORIZED !== \"0\" },\n });\n db = new Kysely<Database>({\n dialect: new PostgresJSDialect({ postgres: rawClient }),\n });\n }\n return db;\n}\n\n/** Raw postgres.js client for dynamic schema DDL (CREATE SCHEMA, DROP, etc.) */\nexport function getRawClient(): ReturnType<typeof postgres> {\n if (!rawClient) getDb();\n return rawClient!;\n}\n\n/** Close the DB connection pool. Call in CLI commands to allow process exit. */\nexport async function closeDb(): Promise<void> {\n if (db) {\n await db.destroy();\n db = null;\n }\n if (rawClient) {\n await rawClient.end();\n rawClient = null;\n }\n}\n\nimport { sql } from \"kysely\";\nexport { sql };\nexport * from \"./types.ts\";\nexport { jsonb, parseJsonb } from \"./jsonb.ts\";\n",
|
|
7
7
|
"import { sql } from \"kysely\";\nimport { getDb } from \"../db/index.ts\";\n\n/**\n * Recover jobs that have been locked for longer than the threshold\n * These are likely from crashed workers\n *\n * @param staleThresholdMinutes - Minutes after which a locked job is considered stale\n * @returns Number of recovered jobs\n */\nexport async function recoverStaleJobs(\n staleThresholdMinutes = 5\n): Promise<number> {\n const { rows } = await sql`\n UPDATE jobs\n SET\n status = 'pending',\n locked_at = NULL,\n locked_by = NULL\n WHERE\n status = 'processing'\n AND locked_at < NOW() - INTERVAL '${sql.raw(staleThresholdMinutes.toString())} minutes'\n RETURNING id\n `.execute(getDb());\n\n return rows.length;\n}\n\n/**\n * Run periodic stale job recovery\n * Returns a cleanup function to stop the interval\n */\nexport function startRecoveryLoop(\n intervalMs = 60000, // 1 minute\n staleThresholdMinutes = 5\n): () => void {\n const intervalId = setInterval(async () => {\n try {\n const recovered = await recoverStaleJobs(staleThresholdMinutes);\n if (recovered > 0) {\n console.log(`Recovered ${recovered} stale jobs`);\n }\n } catch (error) {\n console.error(\"Error recovering stale jobs:\", error);\n }\n }, intervalMs);\n\n return () => clearInterval(intervalId);\n}\n"
|
|
8
8
|
],
|
|
9
|
-
"mappings": "
|
|
10
|
-
"debugId": "
|
|
9
|
+
"mappings": ";;;;;;;;;;;;;;;;;;AAAA;AAOO,SAAS,KAAK,CAAC,OAAqC;AAAA,EACzD,MAAM,UAAU,KAAK,UAAU,KAAK,EAAE,QAAQ,MAAM,IAAI;AAAA,EACxD,OAAO,MAAM,IAAI,IAAI,IAAI,iBAAiB;AAAA;AAQrC,SAAS,UAAuB,CAAC,OAAmB;AAAA,EACzD,IAAI,OAAO,UAAU,UAAU;AAAA,IAC7B,IAAI;AAAA,MACF,OAAO,KAAK,MAAM,KAAK;AAAA,MACvB,MAAM;AAAA,MACN,OAAO;AAAA;AAAA,EAEX;AAAA,EACA,OAAQ,SAAS,CAAC;AAAA;;;ACzBpB;AACA;AACA;AAwCA,gBAAS;AArCT,IAAI,KAA8B;AAClC,IAAI,YAAgD;AAE7C,SAAS,KAAK,CAAC,kBAA6C;AAAA,EACjE,IAAI,CAAC,IAAI;AAAA,IACP,MAAM,MAAM,oBAAoB,QAAQ,IAAI,gBAAgB;AAAA,IAG5D,MAAM,UAAU,IAAI,SAAS,WAAW,KAAK,IAAI,SAAS,WAAW,KAAK,IAAI,SAAS,YAAY;AAAA,IACnG,YAAY,SAAS,KAAK;AAAA,MACxB,KAAK,UAAU,YAAY,EAAE,oBAAoB,QAAQ,IAAI,iCAAiC,IAAI;AAAA,IACpG,CAAC;AAAA,IACD,KAAK,IAAI,OAAiB;AAAA,MACxB,SAAS,IAAI,kBAAkB,EAAE,UAAU,UAAU,CAAC;AAAA,IACxD,CAAC;AAAA,EACH;AAAA,EACA,OAAO;AAAA;AAIF,SAAS,YAAY,GAAgC;AAAA,EAC1D,IAAI,CAAC;AAAA,IAAW,MAAM;AAAA,EACtB,OAAO;AAAA;AAIT,eAAsB,OAAO,GAAkB;AAAA,EAC7C,IAAI,IAAI;AAAA,IACN,MAAM,GAAG,QAAQ;AAAA,IACjB,KAAK;AAAA,EACP;AAAA,EACA,IAAI,WAAW;AAAA,IACb,MAAM,UAAU,IAAI;AAAA,IACpB,YAAY;AAAA,EACd;AAAA;;ACvCF,gBAAS;AAUT,eAAsB,gBAAgB,CACpC,wBAAwB,GACP;AAAA,EACjB,QAAQ,SAAS,MAAM;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA,0CAQiB,KAAI,IAAI,sBAAsB,SAAS,CAAC;AAAA;AAAA,IAE9E,QAAQ,MAAM,CAAC;AAAA,EAEjB,OAAO,KAAK;AAAA;AAOP,SAAS,iBAAiB,CAC/B,aAAa,OACb,wBAAwB,GACZ;AAAA,EACZ,MAAM,aAAa,YAAY,YAAY;AAAA,IACzC,IAAI;AAAA,MACF,MAAM,YAAY,MAAM,iBAAiB,qBAAqB;AAAA,MAC9D,IAAI,YAAY,GAAG;AAAA,QACjB,QAAQ,IAAI,aAAa,sBAAsB;AAAA,MACjD;AAAA,MACA,OAAO,OAAO;AAAA,MACd,QAAQ,MAAM,gCAAgC,KAAK;AAAA;AAAA,KAEpD,UAAU;AAAA,EAEb,OAAO,MAAM,cAAc,UAAU;AAAA;",
|
|
10
|
+
"debugId": "FC85FE33032D8FFF64756E2164756E21",
|
|
11
11
|
"names": []
|
|
12
12
|
}
|
|
@@ -13,6 +13,7 @@ var __export = (target, all) => {
|
|
|
13
13
|
set: __exportSetter.bind(all, name)
|
|
14
14
|
});
|
|
15
15
|
};
|
|
16
|
+
var __require = /* @__PURE__ */ createRequire(import.meta.url);
|
|
16
17
|
|
|
17
18
|
// src/schemas/filters.ts
|
|
18
19
|
import { z } from "zod/v4";
|
|
@@ -134,5 +135,5 @@ export {
|
|
|
134
135
|
ContractCallFilterSchema
|
|
135
136
|
};
|
|
136
137
|
|
|
137
|
-
//# debugId=
|
|
138
|
+
//# debugId=22C7E59A5FADC58C64756E2164756E21
|
|
138
139
|
//# sourceMappingURL=filters.js.map
|
|
@@ -4,7 +4,7 @@
|
|
|
4
4
|
"sourcesContent": [
|
|
5
5
|
"import { z } from \"zod/v4\";\nimport { isValidAddress as _isValidAddress } from \"@secondlayer/stacks\";\n\nconst isValidAddress = _isValidAddress as (addr: string) => boolean;\n\n/** Validate a Stacks principal (standard or contract, e.g. SP2J...ABC or SP2J...ABC.contract-name) */\nconst stacksPrincipal = z.string().refine((val) => {\n const parts = val.split(\".\");\n if (parts.length > 2) return false;\n return isValidAddress(parts[0]!);\n}, \"Invalid Stacks principal address\");\n\n// Base filter with common fields\nconst baseFilter = {\n // Optional: filter by sender\n sender: stacksPrincipal.optional(),\n // Optional: filter by recipient\n recipient: stacksPrincipal.optional(),\n};\n\n// Type exports — defined first so they can annotate schemas\nexport interface StxTransferFilter {\n type: \"stx_transfer\";\n sender?: string;\n recipient?: string;\n minAmount?: number;\n maxAmount?: number;\n}\n\nexport interface StxMintFilter {\n type: \"stx_mint\";\n recipient?: string;\n minAmount?: number;\n}\n\nexport interface StxBurnFilter {\n type: \"stx_burn\";\n sender?: string;\n minAmount?: number;\n}\n\nexport interface StxLockFilter {\n type: \"stx_lock\";\n lockedAddress?: string;\n minAmount?: number;\n}\n\nexport interface FtTransferFilter {\n type: \"ft_transfer\";\n sender?: string;\n recipient?: string;\n assetIdentifier?: string;\n minAmount?: number;\n}\n\nexport interface FtMintFilter {\n type: \"ft_mint\";\n recipient?: string;\n assetIdentifier?: string;\n minAmount?: number;\n}\n\nexport interface FtBurnFilter {\n type: \"ft_burn\";\n sender?: string;\n assetIdentifier?: string;\n minAmount?: number;\n}\n\nexport interface NftTransferFilter {\n type: \"nft_transfer\";\n sender?: string;\n recipient?: string;\n assetIdentifier?: string;\n tokenId?: string;\n}\n\nexport interface NftMintFilter {\n type: \"nft_mint\";\n recipient?: string;\n assetIdentifier?: string;\n tokenId?: string;\n}\n\nexport interface NftBurnFilter {\n type: \"nft_burn\";\n sender?: string;\n assetIdentifier?: string;\n tokenId?: string;\n}\n\nexport interface ContractCallFilter {\n type: \"contract_call\";\n contractId?: string;\n functionName?: string;\n caller?: string;\n}\n\nexport interface ContractDeployFilter {\n type: \"contract_deploy\";\n deployer?: string;\n contractName?: string;\n}\n\nexport interface PrintEventFilter {\n type: \"print_event\";\n contractId?: string;\n topic?: string;\n contains?: string;\n}\n\nexport type StreamFilter =\n | StxTransferFilter\n | StxMintFilter\n | StxBurnFilter\n | StxLockFilter\n | FtTransferFilter\n | FtMintFilter\n | FtBurnFilter\n | NftTransferFilter\n | NftMintFilter\n | NftBurnFilter\n | ContractCallFilter\n | ContractDeployFilter\n | PrintEventFilter;\n\n// STX Transfer Filter\nexport const StxTransferFilterSchema: z.ZodType<StxTransferFilter> = z.object({\n type: z.literal(\"stx_transfer\"),\n ...baseFilter,\n // Optional: minimum amount in microSTX\n minAmount: z.coerce.number().int().positive().optional(),\n // Optional: maximum amount in microSTX\n maxAmount: z.coerce.number().int().positive().optional(),\n});\n\n// STX Mint Filter\nexport const StxMintFilterSchema: z.ZodType<StxMintFilter> = z.object({\n type: z.literal(\"stx_mint\"),\n recipient: stacksPrincipal.optional(),\n minAmount: z.coerce.number().int().positive().optional(),\n});\n\n// STX Burn Filter\nexport const StxBurnFilterSchema: z.ZodType<StxBurnFilter> = z.object({\n type: z.literal(\"stx_burn\"),\n sender: stacksPrincipal.optional(),\n minAmount: z.coerce.number().int().positive().optional(),\n});\n\n// STX Lock Filter\nexport const StxLockFilterSchema: z.ZodType<StxLockFilter> = z.object({\n type: z.literal(\"stx_lock\"),\n lockedAddress: stacksPrincipal.optional(),\n minAmount: z.coerce.number().int().positive().optional(),\n});\n\n// FT Transfer Filter\nexport const FtTransferFilterSchema: z.ZodType<FtTransferFilter> = z.object({\n type: z.literal(\"ft_transfer\"),\n ...baseFilter,\n // Contract that defines the token (e.g., SP3K8BC0PPEVCV7NZ6QSRWPQ2JE9E5B6N3PA0KBR9.token-wstx)\n assetIdentifier: z.string().optional(),\n minAmount: z.coerce.number().int().positive().optional(),\n});\n\n// FT Mint Filter\nexport const FtMintFilterSchema: z.ZodType<FtMintFilter> = z.object({\n type: z.literal(\"ft_mint\"),\n recipient: stacksPrincipal.optional(),\n assetIdentifier: z.string().optional(),\n minAmount: z.coerce.number().int().positive().optional(),\n});\n\n// FT Burn Filter\nexport const FtBurnFilterSchema: z.ZodType<FtBurnFilter> = z.object({\n type: z.literal(\"ft_burn\"),\n sender: stacksPrincipal.optional(),\n assetIdentifier: z.string().optional(),\n minAmount: z.coerce.number().int().positive().optional(),\n});\n\n// NFT Transfer Filter\nexport const NftTransferFilterSchema: z.ZodType<NftTransferFilter> = z.object({\n type: z.literal(\"nft_transfer\"),\n ...baseFilter,\n assetIdentifier: z.string().optional(),\n // Optional: filter by specific token ID (Clarity value as hex)\n tokenId: z.string().optional(),\n});\n\n// NFT Mint Filter\nexport const NftMintFilterSchema: z.ZodType<NftMintFilter> = z.object({\n type: z.literal(\"nft_mint\"),\n recipient: stacksPrincipal.optional(),\n assetIdentifier: z.string().optional(),\n tokenId: z.string().optional(),\n});\n\n// NFT Burn Filter\nexport const NftBurnFilterSchema: z.ZodType<NftBurnFilter> = z.object({\n type: z.literal(\"nft_burn\"),\n sender: stacksPrincipal.optional(),\n assetIdentifier: z.string().optional(),\n tokenId: z.string().optional(),\n});\n\n// Contract Call Filter\nexport const ContractCallFilterSchema: z.ZodType<ContractCallFilter> = z.object({\n type: z.literal(\"contract_call\"),\n // Contract being called\n contractId: stacksPrincipal.optional(),\n // Function name (supports wildcards with *)\n functionName: z.string().optional(),\n // Caller address\n caller: stacksPrincipal.optional(),\n});\n\n// Contract Deploy Filter\nexport const ContractDeployFilterSchema: z.ZodType<ContractDeployFilter> = z.object({\n type: z.literal(\"contract_deploy\"),\n // Deployer address\n deployer: stacksPrincipal.optional(),\n // Contract name pattern (supports wildcards)\n contractName: z.string().optional(),\n});\n\n// Print Event Filter (smart contract events)\nexport const PrintEventFilterSchema: z.ZodType<PrintEventFilter> = z.object({\n type: z.literal(\"print_event\"),\n // Contract emitting the event\n contractId: stacksPrincipal.optional(),\n // Topic/name of the event\n topic: z.string().optional(),\n // Search for substring in event data\n contains: z.string().optional(),\n});\n\n// Union of all filter types\nexport const StreamFilterSchema: z.ZodType<StreamFilter> = z.discriminatedUnion(\"type\", [\n StxTransferFilterSchema as any,\n StxMintFilterSchema as any,\n StxBurnFilterSchema as any,\n StxLockFilterSchema as any,\n FtTransferFilterSchema as any,\n FtMintFilterSchema as any,\n FtBurnFilterSchema as any,\n NftTransferFilterSchema as any,\n NftMintFilterSchema as any,\n NftBurnFilterSchema as any,\n ContractCallFilterSchema as any,\n ContractDeployFilterSchema as any,\n PrintEventFilterSchema as any,\n]);\n"
|
|
6
6
|
],
|
|
7
|
-
"mappings": "
|
|
8
|
-
"debugId": "
|
|
7
|
+
"mappings": ";;;;;;;;;;;;;;;;;;AAAA;AACA,2BAAS;AAET,IAAM,iBAAiB;AAGvB,IAAM,kBAAkB,EAAE,OAAO,EAAE,OAAO,CAAC,QAAQ;AAAA,EACjD,MAAM,QAAQ,IAAI,MAAM,GAAG;AAAA,EAC3B,IAAI,MAAM,SAAS;AAAA,IAAG,OAAO;AAAA,EAC7B,OAAO,eAAe,MAAM,EAAG;AAAA,GAC9B,kCAAkC;AAGrC,IAAM,aAAa;AAAA,EAEjB,QAAQ,gBAAgB,SAAS;AAAA,EAEjC,WAAW,gBAAgB,SAAS;AACtC;AA6GO,IAAM,0BAAwD,EAAE,OAAO;AAAA,EAC5E,MAAM,EAAE,QAAQ,cAAc;AAAA,KAC3B;AAAA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E,OAAO,EAAE,SAAS;AAAA,EAE3B,UAAU,EAAE,OAAO,EAAE,SAAS;AAChC,CAAC;AAGM,IAAM,qBAA8C,EAAE,mBAAmB,QAAQ;AAAA,EACtF;AAAA,EACA;AAAA,EACA;AAAA,EACA;AAAA,EACA;AAAA,EACA;AAAA,EACA;AAAA,EACA;AAAA,EACA;AAAA,EACA;AAAA,EACA;AAAA,EACA;AAAA,EACA;AACF,CAAC;",
|
|
8
|
+
"debugId": "22C7E59A5FADC58C64756E2164756E21",
|
|
9
9
|
"names": []
|
|
10
10
|
}
|
|
@@ -13,6 +13,7 @@ var __export = (target, all) => {
|
|
|
13
13
|
set: __exportSetter.bind(all, name)
|
|
14
14
|
});
|
|
15
15
|
};
|
|
16
|
+
var __require = /* @__PURE__ */ createRequire(import.meta.url);
|
|
16
17
|
|
|
17
18
|
// src/schemas/filters.ts
|
|
18
19
|
import { z } from "zod/v4";
|
|
@@ -144,7 +145,7 @@ var CreateStreamSchema = z3.object({
|
|
|
144
145
|
name: z3.string().min(1).max(255),
|
|
145
146
|
endpointUrl: z3.string().url(),
|
|
146
147
|
filters: z3.array(StreamFilterSchema).min(1),
|
|
147
|
-
options: streamOptionsShape.optional()
|
|
148
|
+
options: streamOptionsShape.optional(),
|
|
148
149
|
startBlock: z3.number().int().positive().optional(),
|
|
149
150
|
endBlock: z3.number().int().positive().optional()
|
|
150
151
|
});
|
|
@@ -230,5 +231,5 @@ export {
|
|
|
230
231
|
ContractCallFilterSchema
|
|
231
232
|
};
|
|
232
233
|
|
|
233
|
-
//# debugId=
|
|
234
|
+
//# debugId=61A0895CD0D2BA5464756E2164756E21
|
|
234
235
|
//# sourceMappingURL=index.js.map
|
|
@@ -4,9 +4,9 @@
|
|
|
4
4
|
"sourcesContent": [
|
|
5
5
|
"import { z } from \"zod/v4\";\nimport { isValidAddress as _isValidAddress } from \"@secondlayer/stacks\";\n\nconst isValidAddress = _isValidAddress as (addr: string) => boolean;\n\n/** Validate a Stacks principal (standard or contract, e.g. SP2J...ABC or SP2J...ABC.contract-name) */\nconst stacksPrincipal = z.string().refine((val) => {\n const parts = val.split(\".\");\n if (parts.length > 2) return false;\n return isValidAddress(parts[0]!);\n}, \"Invalid Stacks principal address\");\n\n// Base filter with common fields\nconst baseFilter = {\n // Optional: filter by sender\n sender: stacksPrincipal.optional(),\n // Optional: filter by recipient\n recipient: stacksPrincipal.optional(),\n};\n\n// Type exports — defined first so they can annotate schemas\nexport interface StxTransferFilter {\n type: \"stx_transfer\";\n sender?: string;\n recipient?: string;\n minAmount?: number;\n maxAmount?: number;\n}\n\nexport interface StxMintFilter {\n type: \"stx_mint\";\n recipient?: string;\n minAmount?: number;\n}\n\nexport interface StxBurnFilter {\n type: \"stx_burn\";\n sender?: string;\n minAmount?: number;\n}\n\nexport interface StxLockFilter {\n type: \"stx_lock\";\n lockedAddress?: string;\n minAmount?: number;\n}\n\nexport interface FtTransferFilter {\n type: \"ft_transfer\";\n sender?: string;\n recipient?: string;\n assetIdentifier?: string;\n minAmount?: number;\n}\n\nexport interface FtMintFilter {\n type: \"ft_mint\";\n recipient?: string;\n assetIdentifier?: string;\n minAmount?: number;\n}\n\nexport interface FtBurnFilter {\n type: \"ft_burn\";\n sender?: string;\n assetIdentifier?: string;\n minAmount?: number;\n}\n\nexport interface NftTransferFilter {\n type: \"nft_transfer\";\n sender?: string;\n recipient?: string;\n assetIdentifier?: string;\n tokenId?: string;\n}\n\nexport interface NftMintFilter {\n type: \"nft_mint\";\n recipient?: string;\n assetIdentifier?: string;\n tokenId?: string;\n}\n\nexport interface NftBurnFilter {\n type: \"nft_burn\";\n sender?: string;\n assetIdentifier?: string;\n tokenId?: string;\n}\n\nexport interface ContractCallFilter {\n type: \"contract_call\";\n contractId?: string;\n functionName?: string;\n caller?: string;\n}\n\nexport interface ContractDeployFilter {\n type: \"contract_deploy\";\n deployer?: string;\n contractName?: string;\n}\n\nexport interface PrintEventFilter {\n type: \"print_event\";\n contractId?: string;\n topic?: string;\n contains?: string;\n}\n\nexport type StreamFilter =\n | StxTransferFilter\n | StxMintFilter\n | StxBurnFilter\n | StxLockFilter\n | FtTransferFilter\n | FtMintFilter\n | FtBurnFilter\n | NftTransferFilter\n | NftMintFilter\n | NftBurnFilter\n | ContractCallFilter\n | ContractDeployFilter\n | PrintEventFilter;\n\n// STX Transfer Filter\nexport const StxTransferFilterSchema: z.ZodType<StxTransferFilter> = z.object({\n type: z.literal(\"stx_transfer\"),\n ...baseFilter,\n // Optional: minimum amount in microSTX\n minAmount: z.coerce.number().int().positive().optional(),\n // Optional: maximum amount in microSTX\n maxAmount: z.coerce.number().int().positive().optional(),\n});\n\n// STX Mint Filter\nexport const StxMintFilterSchema: z.ZodType<StxMintFilter> = z.object({\n type: z.literal(\"stx_mint\"),\n recipient: stacksPrincipal.optional(),\n minAmount: z.coerce.number().int().positive().optional(),\n});\n\n// STX Burn Filter\nexport const StxBurnFilterSchema: z.ZodType<StxBurnFilter> = z.object({\n type: z.literal(\"stx_burn\"),\n sender: stacksPrincipal.optional(),\n minAmount: z.coerce.number().int().positive().optional(),\n});\n\n// STX Lock Filter\nexport const StxLockFilterSchema: z.ZodType<StxLockFilter> = z.object({\n type: z.literal(\"stx_lock\"),\n lockedAddress: stacksPrincipal.optional(),\n minAmount: z.coerce.number().int().positive().optional(),\n});\n\n// FT Transfer Filter\nexport const FtTransferFilterSchema: z.ZodType<FtTransferFilter> = z.object({\n type: z.literal(\"ft_transfer\"),\n ...baseFilter,\n // Contract that defines the token (e.g., SP3K8BC0PPEVCV7NZ6QSRWPQ2JE9E5B6N3PA0KBR9.token-wstx)\n assetIdentifier: z.string().optional(),\n minAmount: z.coerce.number().int().positive().optional(),\n});\n\n// FT Mint Filter\nexport const FtMintFilterSchema: z.ZodType<FtMintFilter> = z.object({\n type: z.literal(\"ft_mint\"),\n recipient: stacksPrincipal.optional(),\n assetIdentifier: z.string().optional(),\n minAmount: z.coerce.number().int().positive().optional(),\n});\n\n// FT Burn Filter\nexport const FtBurnFilterSchema: z.ZodType<FtBurnFilter> = z.object({\n type: z.literal(\"ft_burn\"),\n sender: stacksPrincipal.optional(),\n assetIdentifier: z.string().optional(),\n minAmount: z.coerce.number().int().positive().optional(),\n});\n\n// NFT Transfer Filter\nexport const NftTransferFilterSchema: z.ZodType<NftTransferFilter> = z.object({\n type: z.literal(\"nft_transfer\"),\n ...baseFilter,\n assetIdentifier: z.string().optional(),\n // Optional: filter by specific token ID (Clarity value as hex)\n tokenId: z.string().optional(),\n});\n\n// NFT Mint Filter\nexport const NftMintFilterSchema: z.ZodType<NftMintFilter> = z.object({\n type: z.literal(\"nft_mint\"),\n recipient: stacksPrincipal.optional(),\n assetIdentifier: z.string().optional(),\n tokenId: z.string().optional(),\n});\n\n// NFT Burn Filter\nexport const NftBurnFilterSchema: z.ZodType<NftBurnFilter> = z.object({\n type: z.literal(\"nft_burn\"),\n sender: stacksPrincipal.optional(),\n assetIdentifier: z.string().optional(),\n tokenId: z.string().optional(),\n});\n\n// Contract Call Filter\nexport const ContractCallFilterSchema: z.ZodType<ContractCallFilter> = z.object({\n type: z.literal(\"contract_call\"),\n // Contract being called\n contractId: stacksPrincipal.optional(),\n // Function name (supports wildcards with *)\n functionName: z.string().optional(),\n // Caller address\n caller: stacksPrincipal.optional(),\n});\n\n// Contract Deploy Filter\nexport const ContractDeployFilterSchema: z.ZodType<ContractDeployFilter> = z.object({\n type: z.literal(\"contract_deploy\"),\n // Deployer address\n deployer: stacksPrincipal.optional(),\n // Contract name pattern (supports wildcards)\n contractName: z.string().optional(),\n});\n\n// Print Event Filter (smart contract events)\nexport const PrintEventFilterSchema: z.ZodType<PrintEventFilter> = z.object({\n type: z.literal(\"print_event\"),\n // Contract emitting the event\n contractId: stacksPrincipal.optional(),\n // Topic/name of the event\n topic: z.string().optional(),\n // Search for substring in event data\n contains: z.string().optional(),\n});\n\n// Union of all filter types\nexport const StreamFilterSchema: z.ZodType<StreamFilter> = z.discriminatedUnion(\"type\", [\n StxTransferFilterSchema as any,\n StxMintFilterSchema as any,\n StxBurnFilterSchema as any,\n StxLockFilterSchema as any,\n FtTransferFilterSchema as any,\n FtMintFilterSchema as any,\n FtBurnFilterSchema as any,\n NftTransferFilterSchema as any,\n NftMintFilterSchema as any,\n NftBurnFilterSchema as any,\n ContractCallFilterSchema as any,\n ContractDeployFilterSchema as any,\n PrintEventFilterSchema as any,\n]);\n",
|
|
6
6
|
"import { z } from \"zod/v4\";\n\n// ── Deploy Subgraph Request ─────────────────────────────────────────────────\n\nexport interface DeploySubgraphRequest {\n name: string;\n version?: string;\n description?: string;\n sources: string[];\n schema: Record<string, unknown>;\n handlerCode: string;\n reindex?: boolean;\n}\n\nexport const DeploySubgraphRequestSchema: z.ZodType<DeploySubgraphRequest> = z.object({\n name: z.string().regex(/^[a-z0-9-]+$/, \"lowercase alphanumeric + hyphens only\").max(63),\n version: z.string().optional(),\n description: z.string().optional(),\n sources: z.array(z.string()).min(1),\n schema: z.record(z.string(), z.unknown()),\n handlerCode: z.string().max(1_048_576, \"handler code exceeds 1MB limit\"),\n reindex: z.boolean().optional(),\n});\n\nexport interface DeploySubgraphResponse {\n action: \"created\" | \"unchanged\" | \"updated\" | \"reindexed\";\n subgraphId: string;\n message: string;\n}\n\n// Subgraph API response types\n\nexport interface SubgraphSummary {\n name: string;\n version: string;\n status: string;\n lastProcessedBlock: number;\n tables: string[];\n createdAt: string;\n}\n\nexport interface SubgraphDetail {\n name: string;\n version: string;\n status: string;\n lastProcessedBlock: number;\n health: {\n totalProcessed: number;\n totalErrors: number;\n errorRate: number;\n lastError: string | null;\n lastErrorAt: string | null;\n };\n tables: Record<string, {\n endpoint: string;\n columns: Record<string, { type: string; nullable?: boolean }>;\n rowCount: number;\n example: string;\n }>;\n createdAt: string;\n updatedAt: string;\n}\n\nexport interface ReindexResponse {\n message: string;\n fromBlock: number;\n toBlock: number | string;\n}\n\nexport interface SubgraphQueryParams {\n sort?: string;\n order?: string;\n limit?: number;\n offset?: number;\n fields?: string;\n filters?: Record<string, string>;\n}\n",
|
|
7
|
-
"import { z } from \"zod/v4\";\nimport { StreamFilterSchema, type StreamFilter } from \"./filters.ts\";\n\n// ── Type interfaces ──────────────────────────────────────────────────\n\nexport interface StreamOptions {\n decodeClarityValues: boolean;\n includeRawTx: boolean;\n includeBlockMetadata: boolean;\n rateLimit: number;\n timeoutMs: number;\n maxRetries: number;\n}\n\nexport interface CreateStream {\n name: string;\n endpointUrl: string;\n filters: StreamFilter[];\n options?: StreamOptions;\n startBlock?: number;\n endBlock?: number;\n}\n\nexport interface UpdateStream {\n name?: string;\n endpointUrl?: string;\n filters?: StreamFilter[];\n options?: Partial<StreamOptions>;\n}\n\nexport interface DeliveryPayload {\n streamId: string;\n streamName: string;\n block: {\n height: number;\n hash: string;\n parentHash: string;\n burnBlockHeight: number;\n timestamp: number;\n };\n matches: {\n transactions: Array<{\n txId: string;\n type: string;\n sender: string;\n status: string;\n contractId: string | null;\n functionName: string | null;\n rawTx?: string;\n }>;\n events: Array<{\n txId: string;\n eventIndex: number;\n type: string;\n data?: any;\n }>;\n };\n isBackfill: boolean;\n deliveredAt: string;\n}\n\nexport interface StreamMetricsResponse {\n totalDeliveries: number;\n failedDeliveries: number;\n lastTriggeredAt: string | null;\n lastTriggeredBlock: number | null;\n errorMessage: string | null;\n}\n\nexport interface StreamResponse {\n id: string;\n name: string;\n status: \"inactive\" | \"active\" | \"paused\" | \"failed\";\n endpointUrl: string;\n filters: StreamFilter[];\n options: StreamOptions;\n totalDeliveries: number;\n failedDeliveries: number;\n lastTriggeredAt?: string | null;\n lastTriggeredBlock?: number | null;\n errorMessage?: string | null;\n createdAt: string;\n updatedAt: string;\n}\n\n// ── Zod schemas ──────────────────────────────────────────────────────\n\n// Stream options schema (internal, keeps ZodObject methods like .partial())\nconst streamOptionsShape = z.object({\n decodeClarityValues: z.boolean().default(true),\n includeRawTx: z.boolean().default(false),\n includeBlockMetadata: z.boolean().default(true),\n rateLimit: z.number().int().positive().max(100).default(10),\n timeoutMs: z.number().int().positive().max(30000).default(10000),\n maxRetries: z.number().int().min(0).max(10).default(3),\n});\n\n// Cast: .default() makes _input fields optional, but output type matches StreamOptions\nexport const StreamOptionsSchema: z.ZodType<StreamOptions> =\n streamOptionsShape as unknown as z.ZodType<StreamOptions>;\n\nexport const CreateStreamSchema: z.ZodType<CreateStream> = z.object({\n name: z.string().min(1).max(255),\n endpointUrl: z.string().url(),\n filters: z.array(StreamFilterSchema).min(1),\n options: streamOptionsShape.optional()
|
|
7
|
+
"import { z } from \"zod/v4\";\nimport { StreamFilterSchema, type StreamFilter } from \"./filters.ts\";\n\n// ── Type interfaces ──────────────────────────────────────────────────\n\nexport interface StreamOptions {\n decodeClarityValues: boolean;\n includeRawTx: boolean;\n includeBlockMetadata: boolean;\n rateLimit: number;\n timeoutMs: number;\n maxRetries: number;\n}\n\nexport interface CreateStream {\n name: string;\n endpointUrl: string;\n filters: StreamFilter[];\n options?: StreamOptions;\n startBlock?: number;\n endBlock?: number;\n}\n\nexport interface UpdateStream {\n name?: string;\n endpointUrl?: string;\n filters?: StreamFilter[];\n options?: Partial<StreamOptions>;\n}\n\nexport interface DeliveryPayload {\n streamId: string;\n streamName: string;\n block: {\n height: number;\n hash: string;\n parentHash: string;\n burnBlockHeight: number;\n timestamp: number;\n };\n matches: {\n transactions: Array<{\n txId: string;\n type: string;\n sender: string;\n status: string;\n contractId: string | null;\n functionName: string | null;\n rawTx?: string;\n }>;\n events: Array<{\n txId: string;\n eventIndex: number;\n type: string;\n data?: any;\n }>;\n };\n isBackfill: boolean;\n deliveredAt: string;\n}\n\nexport interface StreamMetricsResponse {\n totalDeliveries: number;\n failedDeliveries: number;\n lastTriggeredAt: string | null;\n lastTriggeredBlock: number | null;\n errorMessage: string | null;\n}\n\nexport interface StreamResponse {\n id: string;\n name: string;\n status: \"inactive\" | \"active\" | \"paused\" | \"failed\";\n endpointUrl: string;\n filters: StreamFilter[];\n options: StreamOptions;\n totalDeliveries: number;\n failedDeliveries: number;\n lastTriggeredAt?: string | null;\n lastTriggeredBlock?: number | null;\n errorMessage?: string | null;\n createdAt: string;\n updatedAt: string;\n}\n\n// ── Zod schemas ──────────────────────────────────────────────────────\n\n// Stream options schema (internal, keeps ZodObject methods like .partial())\nconst streamOptionsShape = z.object({\n decodeClarityValues: z.boolean().default(true),\n includeRawTx: z.boolean().default(false),\n includeBlockMetadata: z.boolean().default(true),\n rateLimit: z.number().int().positive().max(100).default(10),\n timeoutMs: z.number().int().positive().max(30000).default(10000),\n maxRetries: z.number().int().min(0).max(10).default(3),\n});\n\n// Cast: .default() makes _input fields optional, but output type matches StreamOptions\nexport const StreamOptionsSchema: z.ZodType<StreamOptions> =\n streamOptionsShape as unknown as z.ZodType<StreamOptions>;\n\nexport const CreateStreamSchema: z.ZodType<CreateStream> = z.object({\n name: z.string().min(1).max(255),\n endpointUrl: z.string().url(),\n filters: z.array(StreamFilterSchema).min(1),\n options: streamOptionsShape.optional(),\n startBlock: z.number().int().positive().optional(),\n endBlock: z.number().int().positive().optional(),\n}) as unknown as z.ZodType<CreateStream>;\n\nexport const UpdateStreamSchema: z.ZodType<UpdateStream> = z.object({\n name: z.string().min(1).max(255).optional(),\n endpointUrl: z.string().url().optional(),\n filters: z.array(StreamFilterSchema).min(1).optional(),\n options: streamOptionsShape.partial().optional(),\n}).refine(\n (data) => Object.keys(data).length > 0,\n { message: \"At least one field must be provided for update\" }\n) as unknown as z.ZodType<UpdateStream>;\n\nexport const DeliveryPayloadSchema: z.ZodType<DeliveryPayload> = z.object({\n streamId: z.string().uuid(),\n streamName: z.string(),\n block: z.object({\n height: z.number(),\n hash: z.string(),\n parentHash: z.string(),\n burnBlockHeight: z.number(),\n timestamp: z.number(),\n }),\n matches: z.object({\n transactions: z.array(z.object({\n txId: z.string(),\n type: z.string(),\n sender: z.string(),\n status: z.string(),\n contractId: z.string().nullable(),\n functionName: z.string().nullable(),\n rawTx: z.string().optional(),\n })),\n events: z.array(z.object({\n txId: z.string(),\n eventIndex: z.number(),\n type: z.string(),\n data: z.any(),\n })),\n }),\n isBackfill: z.boolean(),\n deliveredAt: z.string().datetime(),\n}) as unknown as z.ZodType<DeliveryPayload>;\n\nexport const StreamMetricsSchema: z.ZodType<StreamMetricsResponse> = z.object({\n totalDeliveries: z.number(),\n failedDeliveries: z.number(),\n lastTriggeredAt: z.string().datetime().nullable(),\n lastTriggeredBlock: z.number().nullable(),\n errorMessage: z.string().nullable(),\n});\n\nexport const StreamResponseSchema: z.ZodType<StreamResponse> = z.object({\n id: z.string().uuid(),\n name: z.string(),\n status: z.enum([\"inactive\", \"active\", \"paused\", \"failed\"]),\n endpointUrl: z.string().url(),\n filters: z.array(StreamFilterSchema),\n options: streamOptionsShape,\n totalDeliveries: z.number().int().default(0),\n failedDeliveries: z.number().int().default(0),\n lastTriggeredAt: z.string().datetime().nullable().optional(),\n lastTriggeredBlock: z.number().int().nullable().optional(),\n errorMessage: z.string().nullable().optional(),\n createdAt: z.string().datetime(),\n updatedAt: z.string().datetime(),\n}) as unknown as z.ZodType<StreamResponse>;\n\n// API response types\nexport interface CreateStreamResponse {\n stream: StreamResponse;\n signingSecret: string;\n}\n\nexport interface ListStreamsResponse {\n streams: StreamResponse[];\n total: number;\n}\n\nexport interface BulkPauseResponse {\n paused: number;\n streams: StreamResponse[];\n}\n\nexport interface BulkResumeResponse {\n resumed: number;\n streams: StreamResponse[];\n}\n"
|
|
8
8
|
],
|
|
9
|
-
"mappings": "
|
|
10
|
-
"debugId": "
|
|
9
|
+
"mappings": ";;;;;;;;;;;;;;;;;;AAAA;AACA,2BAAS;AAET,IAAM,iBAAiB;AAGvB,IAAM,kBAAkB,EAAE,OAAO,EAAE,OAAO,CAAC,QAAQ;AAAA,EACjD,MAAM,QAAQ,IAAI,MAAM,GAAG;AAAA,EAC3B,IAAI,MAAM,SAAS;AAAA,IAAG,OAAO;AAAA,EAC7B,OAAO,eAAe,MAAM,EAAG;AAAA,GAC9B,kCAAkC;AAGrC,IAAM,aAAa;AAAA,EAEjB,QAAQ,gBAAgB,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AAO,EAAE,IAAI,EAAE,QAAQ,CAAC;AAAA,EAC5C,iBAAiB,GAAE,OAAO,EAAE,SAAS,EAAE,SAAS,EAAE,SAAS;AAAA,EAC3D,oBAAoB,GAAE,OAAO,EAAE,IAAI,EAAE,SAAS,EAAE,SAAS;AAAA,EACzD,cAAc,GAAE,OAAO,EAAE,SAAS,EAAE,SAAS;AAAA,EAC7C,WAAW,GAAE,OAAO,EAAE,SAAS;AAAA,EAC/B,WAAW,GAAE,OAAO,EAAE,SAAS;AACjC,CAAC;",
|
|
10
|
+
"debugId": "61A0895CD0D2BA5464756E2164756E21",
|
|
11
11
|
"names": []
|
|
12
12
|
}
|
|
@@ -13,6 +13,7 @@ var __export = (target, all) => {
|
|
|
13
13
|
set: __exportSetter.bind(all, name)
|
|
14
14
|
});
|
|
15
15
|
};
|
|
16
|
+
var __require = /* @__PURE__ */ createRequire(import.meta.url);
|
|
16
17
|
|
|
17
18
|
// src/schemas/subgraphs.ts
|
|
18
19
|
import { z } from "zod/v4";
|
|
@@ -29,5 +30,5 @@ export {
|
|
|
29
30
|
DeploySubgraphRequestSchema
|
|
30
31
|
};
|
|
31
32
|
|
|
32
|
-
//# debugId=
|
|
33
|
+
//# debugId=F307F1DD406DAE7364756E2164756E21
|
|
33
34
|
//# sourceMappingURL=subgraphs.js.map
|
|
@@ -4,7 +4,7 @@
|
|
|
4
4
|
"sourcesContent": [
|
|
5
5
|
"import { z } from \"zod/v4\";\n\n// ── Deploy Subgraph Request ─────────────────────────────────────────────────\n\nexport interface DeploySubgraphRequest {\n name: string;\n version?: string;\n description?: string;\n sources: string[];\n schema: Record<string, unknown>;\n handlerCode: string;\n reindex?: boolean;\n}\n\nexport const DeploySubgraphRequestSchema: z.ZodType<DeploySubgraphRequest> = z.object({\n name: z.string().regex(/^[a-z0-9-]+$/, \"lowercase alphanumeric + hyphens only\").max(63),\n version: z.string().optional(),\n description: z.string().optional(),\n sources: z.array(z.string()).min(1),\n schema: z.record(z.string(), z.unknown()),\n handlerCode: z.string().max(1_048_576, \"handler code exceeds 1MB limit\"),\n reindex: z.boolean().optional(),\n});\n\nexport interface DeploySubgraphResponse {\n action: \"created\" | \"unchanged\" | \"updated\" | \"reindexed\";\n subgraphId: string;\n message: string;\n}\n\n// Subgraph API response types\n\nexport interface SubgraphSummary {\n name: string;\n version: string;\n status: string;\n lastProcessedBlock: number;\n tables: string[];\n createdAt: string;\n}\n\nexport interface SubgraphDetail {\n name: string;\n version: string;\n status: string;\n lastProcessedBlock: number;\n health: {\n totalProcessed: number;\n totalErrors: number;\n errorRate: number;\n lastError: string | null;\n lastErrorAt: string | null;\n };\n tables: Record<string, {\n endpoint: string;\n columns: Record<string, { type: string; nullable?: boolean }>;\n rowCount: number;\n example: string;\n }>;\n createdAt: string;\n updatedAt: string;\n}\n\nexport interface ReindexResponse {\n message: string;\n fromBlock: number;\n toBlock: number | string;\n}\n\nexport interface SubgraphQueryParams {\n sort?: string;\n order?: string;\n limit?: number;\n offset?: number;\n fields?: string;\n filters?: Record<string, string>;\n}\n"
|
|
6
6
|
],
|
|
7
|
-
"mappings": "
|
|
8
|
-
"debugId": "
|
|
7
|
+
"mappings": ";;;;;;;;;;;;;;;;;;AAAA;AAcO,IAAM,8BAAgE,EAAE,OAAO;AAAA,EACpF,MAAM,EAAE,OAAO,EAAE,MAAM,gBAAgB,uCAAuC,EAAE,IAAI,EAAE;AAAA,EACtF,SAAS,EAAE,OAAO,EAAE,SAAS;AAAA,EAC7B,aAAa,EAAE,OAAO,EAAE,SAAS;AAAA,EACjC,SAAS,EAAE,MAAM,EAAE,OAAO,CAAC,EAAE,IAAI,CAAC;AAAA,EAClC,QAAQ,EAAE,OAAO,EAAE,OAAO,GAAG,EAAE,QAAQ,CAAC;AAAA,EACxC,aAAa,EAAE,OAAO,EAAE,IAAI,SAAW,gCAAgC;AAAA,EACvE,SAAS,EAAE,QAAQ,EAAE,SAAS;AAChC,CAAC;",
|
|
8
|
+
"debugId": "F307F1DD406DAE7364756E2164756E21",
|
|
9
9
|
"names": []
|
|
10
10
|
}
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@secondlayer/shared",
|
|
3
|
-
"version": "0.
|
|
3
|
+
"version": "0.6.1",
|
|
4
4
|
"type": "module",
|
|
5
5
|
"main": "./dist/src/index.js",
|
|
6
6
|
"types": "./dist/src/index.d.ts",
|
|
@@ -33,10 +33,6 @@
|
|
|
33
33
|
"types": "./dist/src/db/queries/subgraphs.d.ts",
|
|
34
34
|
"import": "./dist/src/db/queries/subgraphs.js"
|
|
35
35
|
},
|
|
36
|
-
"./db/queries/contracts": {
|
|
37
|
-
"types": "./dist/src/db/queries/contracts.d.ts",
|
|
38
|
-
"import": "./dist/src/db/queries/contracts.js"
|
|
39
|
-
},
|
|
40
36
|
"./db/jsonb": {
|
|
41
37
|
"types": "./dist/src/db/jsonb.d.ts",
|
|
42
38
|
"import": "./dist/src/db/jsonb.js"
|
|
@@ -108,6 +104,18 @@
|
|
|
108
104
|
"./node/local-client": {
|
|
109
105
|
"types": "./dist/src/node/local-client.d.ts",
|
|
110
106
|
"import": "./dist/src/node/local-client.js"
|
|
107
|
+
},
|
|
108
|
+
"./node/hiro-pg-client": {
|
|
109
|
+
"types": "./dist/src/node/hiro-pg-client.d.ts",
|
|
110
|
+
"import": "./dist/src/node/hiro-pg-client.js"
|
|
111
|
+
},
|
|
112
|
+
"./node/client": {
|
|
113
|
+
"types": "./dist/src/node/client.d.ts",
|
|
114
|
+
"import": "./dist/src/node/client.js"
|
|
115
|
+
},
|
|
116
|
+
"./node/archive-client": {
|
|
117
|
+
"types": "./dist/src/node/archive-client.d.ts",
|
|
118
|
+
"import": "./dist/src/node/archive-client.js"
|
|
111
119
|
}
|
|
112
120
|
},
|
|
113
121
|
"files": [
|
|
@@ -124,7 +132,7 @@
|
|
|
124
132
|
"prepublishOnly": "bun run build"
|
|
125
133
|
},
|
|
126
134
|
"dependencies": {
|
|
127
|
-
"@secondlayer/stacks": "^0.2.
|
|
135
|
+
"@secondlayer/stacks": "^0.2.2",
|
|
128
136
|
"kysely": "0.28.10",
|
|
129
137
|
"kysely-postgres-js": "3.0.0",
|
|
130
138
|
"postgres": "^3.4.6",
|