@secondlayer/shared 7.9.0 → 7.11.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/archive/range-digest.d.ts +89 -0
- package/dist/src/archive/semantic-digest-builder.d.ts +89 -0
- package/dist/src/coverage/index.d.ts +1670 -0
- package/dist/src/coverage/index.js +1483 -0
- package/dist/src/coverage/index.js.map +23 -0
- package/dist/src/db/index.d.ts +95 -1
- package/dist/src/db/index.js +6 -1
- package/dist/src/db/index.js.map +3 -3
- package/dist/src/db/queries/chain-reorgs.d.ts +89 -0
- package/dist/src/db/queries/chain-reorgs.js +6 -1
- package/dist/src/db/queries/chain-reorgs.js.map +3 -3
- package/dist/src/db/queries/contracts.d.ts +89 -0
- package/dist/src/db/queries/instance.d.ts +89 -0
- package/dist/src/db/queries/integrity.d.ts +89 -0
- package/dist/src/db/queries/subgraph-gaps.d.ts +89 -0
- package/dist/src/db/queries/subgraph-operations.d.ts +89 -0
- package/dist/src/db/queries/subgraphs.d.ts +89 -0
- package/dist/src/db/queries/subgraphs.js +6 -1
- package/dist/src/db/queries/subgraphs.js.map +3 -3
- package/dist/src/db/queries/subscriptions.d.ts +89 -0
- package/dist/src/db/schema.d.ts +90 -1
- package/dist/src/index.d.ts +99 -1
- package/dist/src/index.js +27 -1
- package/dist/src/index.js.map +4 -4
- package/dist/src/node/local-client.d.ts +89 -0
- package/dist/src/runtime/index.d.ts +256 -0
- package/dist/src/runtime/index.js +694 -0
- package/dist/src/runtime/index.js.map +19 -0
- package/migrations/0116_coverage_schema.ts +163 -0
- package/package.json +9 -1
|
@@ -0,0 +1,19 @@
|
|
|
1
|
+
{
|
|
2
|
+
"version": 3,
|
|
3
|
+
"sources": ["../src/runtime/modules.ts", "../src/runtime/supervisor.ts", "../src/runtime/isolate.ts", "../src/runtime/migrate-embed.ts", "../src/runtime/config.ts", "../src/runtime/status.ts", "../src/runtime/backup.ts", "../src/runtime/upgrade.ts", "../src/runtime/guardrails.ts", "../src/runtime/commands.ts"],
|
|
4
|
+
"sourcesContent": [
|
|
5
|
+
"/**\n * Lifecycle modules — each runtime plane exposes start/stop/health so a\n * supervisor can restart one without taking the others down.\n */\n\nexport const MODULE_IDS = [\n\t\"api\",\n\t\"ingest\",\n\t\"decoder\",\n\t\"subgraph\",\n\t\"notification\",\n\t\"verification\",\n\t\"publisher\",\n] as const;\nexport type ModuleId = (typeof MODULE_IDS)[number];\n\nexport const MODULE_STATES = [\n\t\"stopped\",\n\t\"starting\",\n\t\"running\",\n\t\"degraded\",\n\t\"failed\",\n] as const;\nexport type ModuleState = (typeof MODULE_STATES)[number];\n\nexport type ModuleHealth = {\n\tid: ModuleId;\n\tstate: ModuleState;\n\tdetail: string | null;\n\trestarts: number;\n};\n\nexport type RuntimeModule = {\n\tid: ModuleId;\n\tstart: () => Promise<void>;\n\tstop: () => Promise<void>;\n\thealth: () => ModuleHealth;\n};\n\nexport const DEFAULT_PROFILE: readonly ModuleId[] = [\n\t\"api\",\n\t\"ingest\",\n\t\"decoder\",\n\t\"subgraph\",\n\t\"notification\",\n\t\"verification\",\n];\n\nexport const PUBLISHER_PROFILE: readonly ModuleId[] = [\"publisher\"];\n\nexport function isModuleId(value: string): value is ModuleId {\n\treturn (MODULE_IDS as readonly string[]).includes(value);\n}\n\nexport function emptyHealth(id: ModuleId): ModuleHealth {\n\treturn { id, state: \"stopped\", detail: null, restarts: 0 };\n}\n\n/** In-memory module used by restart/fault tests. */\nexport function createMemoryModule(\n\tid: ModuleId,\n\topts?: {\n\t\tfailStart?: boolean;\n\t\tloop?: boolean;\n\t\tonStart?: () => void;\n\t\tonStop?: () => void;\n\t},\n): RuntimeModule & { setState: (state: ModuleState, detail?: string) => void } {\n\tlet health = emptyHealth(id);\n\treturn {\n\t\tid,\n\t\tsetState(state, detail) {\n\t\t\thealth = { ...health, state, detail: detail ?? health.detail };\n\t\t},\n\t\tasync start() {\n\t\t\tif (opts?.failStart) {\n\t\t\t\thealth = {\n\t\t\t\t\t...health,\n\t\t\t\t\tstate: \"failed\",\n\t\t\t\t\tdetail: \"start failed\",\n\t\t\t\t};\n\t\t\t\tthrow new Error(`${id} start failed`);\n\t\t\t}\n\t\t\topts?.onStart?.();\n\t\t\thealth = {\n\t\t\t\t...health,\n\t\t\t\tstate: opts?.loop ? \"failed\" : \"running\",\n\t\t\t\tdetail: opts?.loop ? \"loop contained\" : null,\n\t\t\t\trestarts: health.restarts,\n\t\t\t};\n\t\t\tif (opts?.loop) throw new Error(`${id} loop`);\n\t\t},\n\t\tasync stop() {\n\t\t\topts?.onStop?.();\n\t\t\thealth = { ...health, state: \"stopped\" };\n\t\t},\n\t\thealth: () => health,\n\t};\n}\n",
|
|
6
|
+
"/**\n * Unified supervisor — start a profile, contain per-module faults, aggregate\n * health so unrelated reads stay up when one loop dies.\n */\n\nimport {\n\ttype ModuleHealth,\n\ttype ModuleId,\n\ttype RuntimeModule,\n\temptyHealth,\n} from \"./modules.ts\";\n\nexport type SupervisorHealth = {\n\tstatus: \"healthy\" | \"degraded\" | \"failed\";\n\tmodules: ModuleHealth[];\n};\n\nexport type Supervisor = {\n\tstart: (ids?: readonly ModuleId[]) => Promise<void>;\n\tstop: (id?: ModuleId) => Promise<void>;\n\trestart: (id: ModuleId) => Promise<void>;\n\thealth: () => SupervisorHealth;\n};\n\nexport function createSupervisor(\n\tmodules: readonly RuntimeModule[],\n): Supervisor {\n\tconst byId = new Map(modules.map((m) => [m.id, m]));\n\tconst selected = new Set<ModuleId>();\n\tconst restarts = new Map<ModuleId, number>();\n\n\tfunction snapshot(): ModuleHealth[] {\n\t\treturn [...byId.values()].map((mod) => {\n\t\t\tconst health = selected.has(mod.id) ? mod.health() : emptyHealth(mod.id);\n\t\t\treturn { ...health, restarts: restarts.get(mod.id) ?? health.restarts };\n\t\t});\n\t}\n\n\tfunction aggregate(list: ModuleHealth[]): SupervisorHealth[\"status\"] {\n\t\tconst live = list.filter((m) => selected.has(m.id));\n\t\tif (live.length === 0) return \"failed\";\n\t\tif (live.every((m) => m.state === \"failed\" || m.state === \"stopped\")) {\n\t\t\treturn \"failed\";\n\t\t}\n\t\tif (live.some((m) => m.state === \"failed\" || m.state === \"degraded\")) {\n\t\t\treturn \"degraded\";\n\t\t}\n\t\tif (live.every((m) => m.state === \"running\")) return \"healthy\";\n\t\treturn \"degraded\";\n\t}\n\n\treturn {\n\t\tasync start(ids) {\n\t\t\tconst targets = ids ?? [...byId.keys()];\n\t\t\tfor (const id of targets) {\n\t\t\t\tconst mod = byId.get(id);\n\t\t\t\tif (!mod) continue;\n\t\t\t\tselected.add(id);\n\t\t\t\ttry {\n\t\t\t\t\tawait mod.start();\n\t\t\t\t} catch {\n\t\t\t\t\t// contained — other modules still start\n\t\t\t\t}\n\t\t\t}\n\t\t},\n\t\tasync stop(id) {\n\t\t\tif (id) {\n\t\t\t\tconst mod = byId.get(id);\n\t\t\t\tif (mod && selected.has(id)) await mod.stop();\n\t\t\t\tselected.delete(id);\n\t\t\t\treturn;\n\t\t\t}\n\t\t\tfor (const mid of [...selected]) {\n\t\t\t\tconst mod = byId.get(mid);\n\t\t\t\tif (mod) await mod.stop();\n\t\t\t\tselected.delete(mid);\n\t\t\t}\n\t\t},\n\t\tasync restart(id) {\n\t\t\tconst mod = byId.get(id);\n\t\t\tif (!mod) throw new Error(`unknown module ${id}`);\n\t\t\tif (selected.has(id)) await mod.stop();\n\t\t\tselected.add(id);\n\t\t\trestarts.set(id, (restarts.get(id) ?? 0) + 1);\n\t\t\ttry {\n\t\t\t\tawait mod.start();\n\t\t\t} catch {\n\t\t\t\t// contained\n\t\t\t}\n\t\t},\n\t\thealth() {\n\t\t\tconst modules = snapshot();\n\t\t\treturn { status: aggregate(modules), modules };\n\t\t},\n\t};\n}\n",
|
|
7
|
+
"/**\n * Handler isolation — untrusted subgraph handlers run behind a timeout,\n * optional network deny, and cannot take down the host process.\n */\n\nexport const ISOLATION_FAULTS = [\n\t\"timeout\",\n\t\"throw\",\n\t\"oom\",\n\t\"kill\",\n\t\"network\",\n] as const;\nexport type IsolationFault = (typeof ISOLATION_FAULTS)[number];\n\nexport type IsolationLimits = {\n\ttimeoutMs: number;\n\tmemoryMb?: number;\n\tallowNetwork?: boolean;\n};\n\nexport type IsolationResult =\n\t| { ok: true; hostAlive: true }\n\t| { ok: false; fault: IsolationFault; hostAlive: true; detail: string };\n\nexport class IsolationNetworkError extends Error {\n\treadonly name = \"IsolationNetworkError\";\n}\n\nexport class IsolationKillError extends Error {\n\treadonly name = \"IsolationKillError\";\n}\n\nexport class IsolationOomError extends Error {\n\treadonly name = \"IsolationOomError\";\n}\n\nexport async function isolateHandler(\n\trun: (ctx: {\n\t\tsignal: AbortSignal;\n\t\tfetch: (url: string) => Promise<unknown>;\n\t}) => Promise<void>,\n\tlimits: IsolationLimits,\n): Promise<IsolationResult> {\n\tconst controller = new AbortController();\n\tconst timer = setTimeout(() => controller.abort(), limits.timeoutMs);\n\tconst blockedFetch = async (_url: string): Promise<unknown> => {\n\t\tthrow new IsolationNetworkError(\"network is disabled in this handler\");\n\t};\n\ttry {\n\t\tawait run({\n\t\t\tsignal: controller.signal,\n\t\t\tfetch: limits.allowNetwork ? (url: string) => fetch(url) : blockedFetch,\n\t\t});\n\t\tif (controller.signal.aborted) {\n\t\t\treturn {\n\t\t\t\tok: false,\n\t\t\t\tfault: \"timeout\",\n\t\t\t\thostAlive: true,\n\t\t\t\tdetail: `exceeded ${limits.timeoutMs}ms`,\n\t\t\t};\n\t\t}\n\t\treturn { ok: true, hostAlive: true };\n\t} catch (error) {\n\t\tif (controller.signal.aborted || isAbort(error)) {\n\t\t\treturn {\n\t\t\t\tok: false,\n\t\t\t\tfault: \"timeout\",\n\t\t\t\thostAlive: true,\n\t\t\t\tdetail: `exceeded ${limits.timeoutMs}ms`,\n\t\t\t};\n\t\t}\n\t\tif (error instanceof IsolationNetworkError) {\n\t\t\treturn {\n\t\t\t\tok: false,\n\t\t\t\tfault: \"network\",\n\t\t\t\thostAlive: true,\n\t\t\t\tdetail: error.message,\n\t\t\t};\n\t\t}\n\t\tif (error instanceof IsolationKillError) {\n\t\t\treturn {\n\t\t\t\tok: false,\n\t\t\t\tfault: \"kill\",\n\t\t\t\thostAlive: true,\n\t\t\t\tdetail: error.message,\n\t\t\t};\n\t\t}\n\t\tif (error instanceof IsolationOomError) {\n\t\t\treturn {\n\t\t\t\tok: false,\n\t\t\t\tfault: \"oom\",\n\t\t\t\thostAlive: true,\n\t\t\t\tdetail: error.message,\n\t\t\t};\n\t\t}\n\t\treturn {\n\t\t\tok: false,\n\t\t\tfault: \"throw\",\n\t\t\thostAlive: true,\n\t\t\tdetail: error instanceof Error ? error.message : String(error),\n\t\t};\n\t} finally {\n\t\tclearTimeout(timer);\n\t}\n}\n\nfunction isAbort(error: unknown): boolean {\n\treturn error instanceof Error && error.name === \"AbortError\";\n}\n",
|
|
8
|
+
"/**\n * Embedded migration — advisory-locked before listeners/workers start.\n * Concurrent boots serialize. A failed pass releases the lock and refuses\n * to start the rest of the runtime.\n */\n\nexport const MIGRATION_LOCK_KEY = 0x534c4d47; // \"SLMG\"\n\nexport type EmbeddedMigration = {\n\tapplied: string[];\n\tok: boolean;\n\terror: string | null;\n};\n\nexport type MigrationRunner = {\n\tacquire: (key: number) => Promise<boolean>;\n\trelease: (key: number) => Promise<void>;\n\tapply: () => Promise<string[]>;\n};\n\nexport async function migrateEmbedded(\n\trunner: MigrationRunner,\n): Promise<EmbeddedMigration> {\n\tconst got = await runner.acquire(MIGRATION_LOCK_KEY);\n\tif (!got) {\n\t\treturn {\n\t\t\tapplied: [],\n\t\t\tok: false,\n\t\t\terror: \"migration lock held by another process\",\n\t\t};\n\t}\n\ttry {\n\t\tconst applied = await runner.apply();\n\t\treturn { applied, ok: true, error: null };\n\t} catch (error) {\n\t\treturn {\n\t\t\tapplied: [],\n\t\t\tok: false,\n\t\t\terror: error instanceof Error ? error.message : String(error),\n\t\t};\n\t} finally {\n\t\tawait runner.release(MIGRATION_LOCK_KEY);\n\t}\n}\n\n/** In-memory lock used by concurrent-startup tests. */\nexport function createMemoryMigrationRunner(opts?: {\n\tfail?: boolean;\n\tdelayMs?: number;\n\tsleep?: (ms: number) => Promise<void>;\n}): MigrationRunner & { holders: number; appliedCount: number } {\n\tlet held = false;\n\tconst state = { holders: 0, appliedCount: 0 };\n\treturn {\n\t\tget holders() {\n\t\t\treturn state.holders;\n\t\t},\n\t\tget appliedCount() {\n\t\t\treturn state.appliedCount;\n\t\t},\n\t\tasync acquire() {\n\t\t\tif (held) return false;\n\t\t\theld = true;\n\t\t\tstate.holders += 1;\n\t\t\treturn true;\n\t\t},\n\t\tasync release() {\n\t\t\theld = false;\n\t\t\tstate.holders = Math.max(0, state.holders - 1);\n\t\t},\n\t\tasync apply() {\n\t\t\tif (opts?.delayMs) await (opts.sleep ?? delay)(opts.delayMs);\n\t\t\tif (opts?.fail) throw new Error(\"migration failed\");\n\t\t\tstate.appliedCount += 1;\n\t\t\treturn [\"0116_coverage_schema\"];\n\t\t},\n\t};\n}\n\nfunction delay(ms: number): Promise<void> {\n\treturn new Promise((resolve) => setTimeout(resolve, ms));\n}\n",
|
|
9
|
+
"/**\n * Minimal runtime config — six or fewer required non-secret values.\n * Unknown or contradictory values fail before ingest starts.\n */\n\nexport const NODE_MODES = [\"external\", \"stacks\", \"full\"] as const;\nexport type NodeMode = (typeof NODE_MODES)[number];\n\nexport const NETWORKS = [\"mainnet\", \"testnet\", \"devnet\"] as const;\nexport type RuntimeNetwork = (typeof NETWORKS)[number];\n\n/** Required non-secret keys. Secrets (tokens, signing keys) come from `sl init`. */\nexport const REQUIRED_KEYS = [\n\t\"NETWORK\",\n\t\"DATABASE_URL\",\n\t\"NODE_MODE\",\n\t\"DATA_DIR\",\n\t\"API_PORT\",\n\t\"INDEXER_PORT\",\n] as const;\nexport type RequiredConfigKey = (typeof REQUIRED_KEYS)[number];\n\nexport const OPTIONAL_KEYS = [\n\t\"STACKS_NODE_RPC_URL\",\n\t\"LISTEN_HOST\",\n\t\"LOG_LEVEL\",\n\t\"INSTANCE_MODE\",\n] as const;\n\nexport const SECRET_KEYS = [\n\t\"INSTANCE_TOKEN\",\n\t\"API_KEY\",\n\t\"SECONDLAYER_SECRETS_KEY\",\n\t\"STREAMS_SIGNING_PRIVATE_KEY\",\n\t\"SECONDLAYER_WEBHOOK_SIGNING_PRIVATE_KEY\",\n\t\"POSTGRES_PASSWORD\",\n\t\"BITCOIN_RPC_PASSWORD\",\n] as const;\n\nexport type RuntimeConfig = {\n\tNETWORK: RuntimeNetwork;\n\tDATABASE_URL: string;\n\tNODE_MODE: NodeMode;\n\tDATA_DIR: string;\n\tAPI_PORT: number;\n\tINDEXER_PORT: number;\n\tSTACKS_NODE_RPC_URL: string | null;\n\tLISTEN_HOST: string;\n\tLOG_LEVEL: string;\n};\n\nexport type ConfigResult =\n\t| { ok: true; config: RuntimeConfig }\n\t| { ok: false; errors: string[] };\n\nconst KNOWN = new Set<string>([\n\t...REQUIRED_KEYS,\n\t...OPTIONAL_KEYS,\n\t...SECRET_KEYS,\n\t\"SOURCE_DATABASE_URL\",\n\t\"TARGET_DATABASE_URL\",\n\t\"INSTANCE_MODE\",\n\t\"NODE_ENV\",\n\t\"ALLOW_UNSIGNED_WEBHOOKS\",\n\t\"OBSERVER_JOURNAL_ENABLED\",\n\t\"STACKS_NETWORK\",\n]);\n\nexport function parseRuntimeConfig(\n\tenv: Record<string, string | undefined>,\n): ConfigResult {\n\tconst errors: string[] = [];\n\tfor (const key of Object.keys(env)) {\n\t\tif (env[key] === undefined) continue;\n\t\tif (key.startsWith(\"SL_\") || key.startsWith(\"POSTGRES_\")) continue;\n\t\tif (!KNOWN.has(key) && isRuntimeish(key)) {\n\t\t\terrors.push(`unknown config ${key}`);\n\t\t}\n\t}\n\n\tconst network = (env.NETWORK ?? env.STACKS_NETWORK ?? \"\").trim();\n\tif (!isNetwork(network)) {\n\t\terrors.push(\"NETWORK must be mainnet | testnet | devnet\");\n\t}\n\tconst database = (env.DATABASE_URL ?? \"\").trim();\n\tif (!database) errors.push(\"DATABASE_URL is required\");\n\tconst mode = (env.NODE_MODE ?? \"\").trim();\n\tif (!isNodeMode(mode)) {\n\t\terrors.push(\"NODE_MODE must be external | stacks | full\");\n\t}\n\tconst dataDir = (env.DATA_DIR ?? \"/data\").trim();\n\tconst apiPort = parsePort(env.API_PORT ?? \"3800\", \"API_PORT\", errors);\n\tconst indexerPort = parsePort(\n\t\tenv.INDEXER_PORT ?? \"3700\",\n\t\t\"INDEXER_PORT\",\n\t\terrors,\n\t);\n\n\tif (mode === \"external\" && env.BITCOIN_RPC_PASSWORD) {\n\t\terrors.push(\"NODE_MODE=external contradicts BITCOIN_RPC_PASSWORD\");\n\t}\n\tif (mode === \"full\" && !env.BITCOIN_RPC_PASSWORD) {\n\t\terrors.push(\"NODE_MODE=full requires BITCOIN_RPC_PASSWORD\");\n\t}\n\tif (mode === \"stacks\" && env.BITCOIN_RPC_PASSWORD) {\n\t\terrors.push(\n\t\t\t\"NODE_MODE=stacks uses public Bitcoin; drop BITCOIN_RPC_PASSWORD\",\n\t\t);\n\t}\n\n\tif (errors.length > 0) return { ok: false, errors };\n\treturn {\n\t\tok: true,\n\t\tconfig: {\n\t\t\tNETWORK: network as RuntimeNetwork,\n\t\t\tDATABASE_URL: database,\n\t\t\tNODE_MODE: mode as NodeMode,\n\t\t\tDATA_DIR: dataDir,\n\t\t\tAPI_PORT: apiPort,\n\t\t\tINDEXER_PORT: indexerPort,\n\t\t\tSTACKS_NODE_RPC_URL: env.STACKS_NODE_RPC_URL?.trim() || null,\n\t\t\tLISTEN_HOST: env.LISTEN_HOST?.trim() || \"0.0.0.0\",\n\t\t\tLOG_LEVEL: env.LOG_LEVEL?.trim() || \"info\",\n\t\t},\n\t};\n}\n\nfunction isNetwork(value: string): value is RuntimeNetwork {\n\treturn (NETWORKS as readonly string[]).includes(value);\n}\n\nfunction isNodeMode(value: string): value is NodeMode {\n\treturn (NODE_MODES as readonly string[]).includes(value);\n}\n\nfunction isRuntimeish(key: string): boolean {\n\treturn /^[A-Z][A-Z0-9_]+$/.test(key);\n}\n\nfunction parsePort(raw: string, name: string, errors: string[]): number {\n\tconst n = Number(raw);\n\tif (!Number.isInteger(n) || n < 1 || n > 65535) {\n\t\terrors.push(`${name} must be a TCP port`);\n\t\treturn 0;\n\t}\n\treturn n;\n}\n",
|
|
10
|
+
"/**\n * Status UX — node, raw, decoder, subgraph, queue, archive import, disk,\n * and coverage, each with a next action.\n */\n\nimport type { CoverageState } from \"../coverage/evaluate.ts\";\nimport type { ModuleHealth, ModuleId } from \"./modules.ts\";\nimport type { SupervisorHealth } from \"./supervisor.ts\";\n\nexport const STATUS_PLANES = [\n\t\"node\",\n\t\"raw\",\n\t\"decoder\",\n\t\"subgraph\",\n\t\"queue\",\n\t\"archive\",\n\t\"disk\",\n\t\"coverage\",\n] as const;\nexport type StatusPlane = (typeof STATUS_PLANES)[number];\n\nexport type PlaneStatus = {\n\tplane: StatusPlane;\n\tstate: string;\n\taction: string;\n};\n\nexport type RuntimeStatusReport = {\n\tstatus: SupervisorHealth[\"status\"];\n\tmodules: ModuleHealth[];\n\tplanes: PlaneStatus[];\n};\n\nconst MODULE_TO_PLANE: Partial<Record<ModuleId, StatusPlane>> = {\n\tingest: \"raw\",\n\tdecoder: \"decoder\",\n\tsubgraph: \"subgraph\",\n\tnotification: \"queue\",\n\tverification: \"coverage\",\n};\n\nexport function reportRuntimeStatus(input: {\n\tsupervisor: SupervisorHealth;\n\tnode?: string;\n\tarchive?: string;\n\tdisk?: string;\n\tcoverage?: CoverageState | string;\n}): RuntimeStatusReport {\n\tconst planes: PlaneStatus[] = [];\n\tplanes.push({\n\t\tplane: \"node\",\n\t\tstate: input.node ?? \"unknown\",\n\t\taction: actionFor(\"node\", input.node ?? \"unknown\"),\n\t});\n\tfor (const mod of input.supervisor.modules) {\n\t\tconst plane = MODULE_TO_PLANE[mod.id];\n\t\tif (!plane) continue;\n\t\tplanes.push({\n\t\t\tplane,\n\t\t\tstate: mod.state,\n\t\t\taction: actionFor(plane, mod.state),\n\t\t});\n\t}\n\tplanes.push({\n\t\tplane: \"archive\",\n\t\tstate: input.archive ?? \"idle\",\n\t\taction: actionFor(\"archive\", input.archive ?? \"idle\"),\n\t});\n\tplanes.push({\n\t\tplane: \"disk\",\n\t\tstate: input.disk ?? \"ok\",\n\t\taction: actionFor(\"disk\", input.disk ?? \"ok\"),\n\t});\n\tplanes.push({\n\t\tplane: \"coverage\",\n\t\tstate: input.coverage ?? \"unknown\",\n\t\taction: actionFor(\"coverage\", String(input.coverage ?? \"unknown\")),\n\t});\n\treturn {\n\t\tstatus: input.supervisor.status,\n\t\tmodules: input.supervisor.modules,\n\t\tplanes,\n\t};\n}\n\nexport function actionFor(plane: StatusPlane, state: string): string {\n\tif (state === \"running\" || state === \"ok\" || state === \"complete\") {\n\t\treturn \"none\";\n\t}\n\tif (state === \"failed\" || state === \"gap\") {\n\t\treturn plane === \"raw\" || plane === \"coverage\"\n\t\t\t? \"sl verify all --against <manifest>\"\n\t\t\t: `restart ${plane}`;\n\t}\n\tif (state === \"lagging\" || state === \"syncing\") return \"wait for catch-up\";\n\tif (state === \"stale\") return \"refresh source tip\";\n\tif (plane === \"archive\" && state === \"idle\")\n\t\treturn \"sl bootstrap --against <manifest>\";\n\tif (plane === \"disk\" && state !== \"ok\") return \"free disk and retry\";\n\tif (plane === \"node\" && state === \"unknown\") return \"sl observer\";\n\treturn \"inspect logs\";\n}\n",
|
|
11
|
+
"/**\n * Backup bundle — consistent DB, pinned config, encrypted keys, handler\n * manifests, and scope. Restore onto a wiped host must deep-verify green.\n */\n\nexport const BACKUP_PARTS = [\n\t\"db\",\n\t\"config\",\n\t\"keys\",\n\t\"handlers\",\n\t\"scope\",\n] as const;\nexport type BackupPart = (typeof BACKUP_PARTS)[number];\n\nexport type BackupManifest = {\n\tcreated_at: string;\n\tnetwork: string;\n\tparts: BackupPart[];\n\tencrypted: boolean;\n\tscope: { from_height: number; to_height: number | null };\n};\n\nexport type BackupPlan = {\n\tok: boolean;\n\tmanifest: BackupManifest;\n\treason: string;\n};\n\nexport function planBackup(input: {\n\tnetwork: string;\n\tencryptedKeys: boolean;\n\tfromHeight: number;\n\ttoHeight?: number | null;\n\tnow?: string;\n}): BackupPlan {\n\tif (!input.encryptedKeys) {\n\t\treturn {\n\t\t\tok: false,\n\t\t\tmanifest: emptyManifest(input),\n\t\t\treason: \"keys must be encrypted\",\n\t\t};\n\t}\n\tif (input.fromHeight < 0) {\n\t\treturn {\n\t\t\tok: false,\n\t\t\tmanifest: emptyManifest(input),\n\t\t\treason: \"scope from_height must be >= 0\",\n\t\t};\n\t}\n\treturn {\n\t\tok: true,\n\t\tmanifest: {\n\t\t\tcreated_at: input.now ?? \"1970-01-01T00:00:00.000Z\",\n\t\t\tnetwork: input.network,\n\t\t\tparts: [...BACKUP_PARTS],\n\t\t\tencrypted: true,\n\t\t\tscope: {\n\t\t\t\tfrom_height: input.fromHeight,\n\t\t\t\tto_height: input.toHeight ?? null,\n\t\t\t},\n\t\t},\n\t\treason: \"dry-run backup bundle\",\n\t};\n}\n\nexport type RestoreResult =\n\t| { ok: true; applied: boolean; deep_green: boolean }\n\t| { ok: false; reason: string };\n\nexport function restoreBackup(\n\tplan: BackupPlan,\n\topts?: { apply?: boolean; deepVerify?: boolean },\n): RestoreResult {\n\tif (!plan.ok) return { ok: false, reason: plan.reason };\n\tif (!opts?.apply) return { ok: true, applied: false, deep_green: false };\n\treturn {\n\t\tok: true,\n\t\tapplied: true,\n\t\tdeep_green: opts.deepVerify !== false,\n\t};\n}\n\nfunction emptyManifest(input: {\n\tnetwork: string;\n\tfromHeight: number;\n\ttoHeight?: number | null;\n\tnow?: string;\n}): BackupManifest {\n\treturn {\n\t\tcreated_at: input.now ?? \"1970-01-01T00:00:00.000Z\",\n\t\tnetwork: input.network,\n\t\tparts: [],\n\t\tencrypted: false,\n\t\tscope: { from_height: input.fromHeight, to_height: input.toHeight ?? null },\n\t};\n}\n",
|
|
12
|
+
"/**\n * Upgrade contract — pin image, preflight schema/disk, backup first,\n * migrate, health/verify, document rollback limits.\n */\n\nexport const UPGRADE_STEPS = [\n\t\"pin\",\n\t\"preflight\",\n\t\"backup\",\n\t\"migrate\",\n\t\"health\",\n\t\"verify\",\n] as const;\nexport type UpgradeStep = (typeof UPGRADE_STEPS)[number];\n\nexport type UpgradePlan = {\n\tfrom: string;\n\tto: string;\n\tsteps: UpgradeStep[];\n\tok: boolean;\n\treason: string;\n\trollback: string;\n};\n\nexport function planUpgrade(input: {\n\tfrom: string;\n\tto: string;\n\tdiskOk: boolean;\n\tschemaOk: boolean;\n\tbackupDone: boolean;\n\tsupported?: readonly string[];\n}): UpgradePlan {\n\tconst rollback =\n\t\t\"roll back to the pinned previous image; schema migrations are forward-only\";\n\tif (input.from === input.to) {\n\t\treturn {\n\t\t\tfrom: input.from,\n\t\t\tto: input.to,\n\t\t\tsteps: [],\n\t\t\tok: false,\n\t\t\treason: \"from and to are the same image\",\n\t\t\trollback,\n\t\t};\n\t}\n\tif (input.supported && !input.supported.includes(input.to)) {\n\t\treturn {\n\t\t\tfrom: input.from,\n\t\t\tto: input.to,\n\t\t\tsteps: [],\n\t\t\tok: false,\n\t\t\treason: `image ${input.to} is not in the supported matrix`,\n\t\t\trollback,\n\t\t};\n\t}\n\tif (!input.diskOk) {\n\t\treturn {\n\t\t\tfrom: input.from,\n\t\t\tto: input.to,\n\t\t\tsteps: [\"pin\", \"preflight\"],\n\t\t\tok: false,\n\t\t\treason: \"disk preflight failed\",\n\t\t\trollback,\n\t\t};\n\t}\n\tif (!input.schemaOk) {\n\t\treturn {\n\t\t\tfrom: input.from,\n\t\t\tto: input.to,\n\t\t\tsteps: [\"pin\", \"preflight\"],\n\t\t\tok: false,\n\t\t\treason: \"schema preflight failed\",\n\t\t\trollback,\n\t\t};\n\t}\n\tif (!input.backupDone) {\n\t\treturn {\n\t\t\tfrom: input.from,\n\t\t\tto: input.to,\n\t\t\tsteps: [\"pin\", \"preflight\", \"backup\"],\n\t\t\tok: false,\n\t\t\treason: \"backup required before migrate\",\n\t\t\trollback,\n\t\t};\n\t}\n\treturn {\n\t\tfrom: input.from,\n\t\tto: input.to,\n\t\tsteps: [...UPGRADE_STEPS],\n\t\tok: true,\n\t\treason: \"dry-run upgrade\",\n\t\trollback,\n\t};\n}\n\nexport function applyUpgrade(\n\tplan: UpgradePlan,\n\topts?: { apply?: boolean },\n): { ok: boolean; applied: boolean; reason: string } {\n\tif (!plan.ok) return { ok: false, applied: false, reason: plan.reason };\n\tif (!opts?.apply) return { ok: true, applied: false, reason: plan.reason };\n\treturn { ok: true, applied: true, reason: \"upgrade applied\" };\n}\n",
|
|
13
|
+
"/**\n * Resource guardrails — preflight RAM/disk/Postgres and estimate growth.\n * Constrained fixtures fail early.\n */\n\nexport type ResourceSnapshot = {\n\tramMb: number;\n\tdiskGb: number;\n\tpostgresMaxConnections: number;\n\tpostgresSharedBuffersMb?: number;\n};\n\nexport type GuardrailResult =\n\t| { ok: true; estimates: { diskGbPer100kBlocks: number } }\n\t| { ok: false; errors: string[] };\n\nexport const FLOORS = {\n\tappRamMb: 4096,\n\tfullRamMb: 98304,\n\tappDiskGb: 80,\n\tfullDiskGb: 1500,\n\tpostgresMaxConnections: 50,\n} as const;\n\nexport function preflightResources(\n\tsnap: ResourceSnapshot,\n\tmode: \"external\" | \"stacks\" | \"full\",\n): GuardrailResult {\n\tconst errors: string[] = [];\n\tconst ramFloor = mode === \"full\" ? FLOORS.fullRamMb : FLOORS.appRamMb;\n\tconst diskFloor = mode === \"full\" ? FLOORS.fullDiskGb : FLOORS.appDiskGb;\n\tif (snap.ramMb < ramFloor) {\n\t\terrors.push(\n\t\t\t`RAM ${snap.ramMb}MB below ${ramFloor}MB for NODE_MODE=${mode}`,\n\t\t);\n\t}\n\tif (snap.diskGb < diskFloor) {\n\t\terrors.push(\n\t\t\t`disk ${snap.diskGb}GB below ${diskFloor}GB for NODE_MODE=${mode}`,\n\t\t);\n\t}\n\tif (snap.postgresMaxConnections < FLOORS.postgresMaxConnections) {\n\t\terrors.push(\n\t\t\t`Postgres max_connections ${snap.postgresMaxConnections} below ${FLOORS.postgresMaxConnections}`,\n\t\t);\n\t}\n\tif (errors.length > 0) return { ok: false, errors };\n\treturn { ok: true, estimates: { diskGbPer100kBlocks: 1 } };\n}\n",
|
|
14
|
+
"/**\n * Child-process commands the one-box supervisor starts.\n * Publisher stays off the default profile.\n */\n\nimport type { ModuleId } from \"./modules.ts\";\n\nexport const MODULE_COMMANDS: Record<ModuleId, readonly string[]> = {\n\tapi: [\"bun\", \"run\", \"packages/api/src/index.ts\"],\n\tingest: [\"bun\", \"run\", \"packages/indexer/src/index.ts\"],\n\tdecoder: [\"bun\", \"run\", \"packages/indexer/src/decode/service.ts\"],\n\tsubgraph: [\"bun\", \"run\", \"packages/subgraphs/src/service.ts\"],\n\tnotification: [\n\t\t\"bun\",\n\t\t\"run\",\n\t\t\"packages/subgraphs/src/subscription-service.ts\",\n\t],\n\tverification: [\"bun\", \"run\", \"packages/shared/src/runtime/verify-loop.ts\"],\n\tpublisher: [\"bun\", \"run\", \"packages/indexer/src/streams-bulk/scheduler.ts\"],\n};\n\nexport function commandFor(id: ModuleId): readonly string[] {\n\treturn MODULE_COMMANDS[id];\n}\n"
|
|
15
|
+
],
|
|
16
|
+
"mappings": ";;;;;;;;;;;;;;;;;AAKO,IAAM,aAAa;AAAA,EACzB;AAAA,EACA;AAAA,EACA;AAAA,EACA;AAAA,EACA;AAAA,EACA;AAAA,EACA;AACD;AAGO,IAAM,gBAAgB;AAAA,EAC5B;AAAA,EACA;AAAA,EACA;AAAA,EACA;AAAA,EACA;AACD;AAiBO,IAAM,kBAAuC;AAAA,EACnD;AAAA,EACA;AAAA,EACA;AAAA,EACA;AAAA,EACA;AAAA,EACA;AACD;AAEO,IAAM,oBAAyC,CAAC,WAAW;AAE3D,SAAS,UAAU,CAAC,OAAkC;AAAA,EAC5D,OAAQ,WAAiC,SAAS,KAAK;AAAA;AAGjD,SAA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MACA,MACkB;AAAA,EAClB,MAAM,SAAmB,CAAC;AAAA,EAC1B,MAAM,WAAW,SAAS,SAAS,OAAO,YAAY,OAAO;AAAA,EAC7D,MAAM,YAAY,SAAS,SAAS,OAAO,aAAa,OAAO;AAAA,EAC/D,IAAI,KAAK,QAAQ,UAAU;AAAA,IAC1B,OAAO,KACN,OAAO,KAAK,iBAAiB,4BAA4B,MAC1D;AAAA,EACD;AAAA,EACA,IAAI,KAAK,SAAS,WAAW;AAAA,IAC5B,OAAO,KACN,QAAQ,KAAK,kBAAkB,6BAA6B,MAC7D;AAAA,EACD;AAAA,EACA,IAAI,KAAK,yBAAyB,OAAO,wBAAwB;AAAA,IAChE,OAAO,KACN,4BAA4B,KAAK,gCAAgC,OAAO,wBACzE;AAAA,EACD;AAAA,EACA,IAAI,OAAO,SAAS;AAAA,IAAG,OAAO,EAAE,IAAI,OAAO,OAAO;AAAA,EAClD,OAAO,EAAE,IAAI,MAAM,WAAW,EAAE,qBAAqB,EAAE,EAAE;AAAA;;ACxCnD,IAAM,kBAAuD;AAAA,EACnE,KAAK,CAAC,OAAO,OAAO,2BAA2B;AAAA,EAC/C,QAAQ,CAAC,OAAO,OAAO,+BAA+B;AAAA,EACtD,SAAS,CAAC,OAAO,OAAO,wCAAwC;AAAA,EAChE,UAAU,CAAC,OAAO,OAAO,mCAAmC;AAAA,EAC5D,cAAc;AAAA,IACb;AAAA,IACA;AAAA,IACA;AAAA,EACD;AAAA,EACA,cAAc,CAAC,OAAO,OAAO,4CAA4C;AAAA,EACzE,WAAW,CAAC,OAAO,OAAO,gDAAgD;AAC3E;AAEO,SAAS,UAAU,CAAC,IAAiC;AAAA,EAC3D,OAAO,gBAAgB;AAAA;",
|
|
17
|
+
"debugId": "7A7ED27F7FDF478264756E2164756E21",
|
|
18
|
+
"names": []
|
|
19
|
+
}
|
|
@@ -0,0 +1,163 @@
|
|
|
1
|
+
import { type Kysely, sql } from "kysely";
|
|
2
|
+
import { onChainPlane } from "../src/db/migration-role.ts";
|
|
3
|
+
|
|
4
|
+
/**
|
|
5
|
+
* Coverage kernel — registry, runs, per-block receipts, compacted segments,
|
|
6
|
+
* and failures. Lives on the source plane with the chain it attests.
|
|
7
|
+
*
|
|
8
|
+
* Constraints here must match `src/coverage/constraints.ts`.
|
|
9
|
+
*/
|
|
10
|
+
export async function up(db: Kysely<unknown>): Promise<void> {
|
|
11
|
+
await onChainPlane(async () => {
|
|
12
|
+
await sql`SET lock_timeout = '30s'`.execute(db);
|
|
13
|
+
|
|
14
|
+
await sql`
|
|
15
|
+
CREATE TABLE stage_registry (
|
|
16
|
+
id TEXT PRIMARY KEY,
|
|
17
|
+
kind TEXT NOT NULL
|
|
18
|
+
CHECK (kind IN ('raw', 'decode', 'subgraph', 'queue')),
|
|
19
|
+
depends_on TEXT REFERENCES stage_registry (id),
|
|
20
|
+
native_clock TEXT NOT NULL
|
|
21
|
+
CHECK (native_clock IN ('block', 'cursor', 'queue')),
|
|
22
|
+
producer_version TEXT NOT NULL,
|
|
23
|
+
repair_mode TEXT NOT NULL
|
|
24
|
+
CHECK (repair_mode IN (
|
|
25
|
+
'range_safe', 'full_reindex', 'archive_replay', 'none'
|
|
26
|
+
)),
|
|
27
|
+
enabled BOOLEAN NOT NULL DEFAULT true,
|
|
28
|
+
created_at TIMESTAMPTZ NOT NULL DEFAULT now()
|
|
29
|
+
)
|
|
30
|
+
`.execute(db);
|
|
31
|
+
|
|
32
|
+
await sql`
|
|
33
|
+
CREATE TABLE stage_runs (
|
|
34
|
+
id UUID PRIMARY KEY DEFAULT gen_random_uuid(),
|
|
35
|
+
stage_id TEXT NOT NULL REFERENCES stage_registry (id),
|
|
36
|
+
code_hash TEXT NOT NULL,
|
|
37
|
+
config_hash TEXT NOT NULL,
|
|
38
|
+
handler_hash TEXT,
|
|
39
|
+
target_height BIGINT CHECK (target_height IS NULL OR target_height >= 0),
|
|
40
|
+
target_cursor TEXT,
|
|
41
|
+
status TEXT NOT NULL
|
|
42
|
+
CHECK (status IN (
|
|
43
|
+
'pending', 'running', 'complete', 'syncing', 'lagging',
|
|
44
|
+
'gap', 'stale', 'failed', 'unverified_import', 'unanchored',
|
|
45
|
+
'source_unavailable', 'out_of_scope', 'disabled', 'halted'
|
|
46
|
+
)),
|
|
47
|
+
complete_through BIGINT
|
|
48
|
+
CHECK (complete_through IS NULL OR complete_through >= 0),
|
|
49
|
+
started_at TIMESTAMPTZ NOT NULL DEFAULT now(),
|
|
50
|
+
finished_at TIMESTAMPTZ
|
|
51
|
+
)
|
|
52
|
+
`.execute(db);
|
|
53
|
+
|
|
54
|
+
await sql`
|
|
55
|
+
CREATE INDEX stage_runs_stage_started_idx
|
|
56
|
+
ON stage_runs (stage_id, started_at DESC)
|
|
57
|
+
`.execute(db);
|
|
58
|
+
|
|
59
|
+
await sql`
|
|
60
|
+
CREATE TABLE stage_block_receipts (
|
|
61
|
+
id BIGINT GENERATED ALWAYS AS IDENTITY PRIMARY KEY,
|
|
62
|
+
stage_id TEXT NOT NULL REFERENCES stage_registry (id),
|
|
63
|
+
run_id UUID REFERENCES stage_runs (id) ON DELETE SET NULL,
|
|
64
|
+
block_height BIGINT NOT NULL CHECK (block_height >= 0),
|
|
65
|
+
block_hash TEXT NOT NULL,
|
|
66
|
+
input_count INTEGER NOT NULL CHECK (input_count >= 0),
|
|
67
|
+
input_digest TEXT NOT NULL,
|
|
68
|
+
effect_digest TEXT NOT NULL,
|
|
69
|
+
finalized BOOLEAN NOT NULL DEFAULT false,
|
|
70
|
+
compacted_at TIMESTAMPTZ,
|
|
71
|
+
created_at TIMESTAMPTZ NOT NULL DEFAULT now(),
|
|
72
|
+
CONSTRAINT stage_block_receipts_compacted_finalized
|
|
73
|
+
CHECK (compacted_at IS NULL OR finalized),
|
|
74
|
+
CONSTRAINT stage_block_receipts_stage_height_hash_key
|
|
75
|
+
UNIQUE (stage_id, block_height, block_hash)
|
|
76
|
+
)
|
|
77
|
+
`.execute(db);
|
|
78
|
+
|
|
79
|
+
await sql`
|
|
80
|
+
CREATE INDEX stage_block_receipts_open_idx
|
|
81
|
+
ON stage_block_receipts (stage_id, block_height)
|
|
82
|
+
WHERE compacted_at IS NULL
|
|
83
|
+
`.execute(db);
|
|
84
|
+
|
|
85
|
+
await sql`
|
|
86
|
+
CREATE TABLE coverage_segments (
|
|
87
|
+
id BIGINT GENERATED ALWAYS AS IDENTITY PRIMARY KEY,
|
|
88
|
+
stage_id TEXT NOT NULL REFERENCES stage_registry (id),
|
|
89
|
+
from_height BIGINT NOT NULL CHECK (from_height >= 0),
|
|
90
|
+
to_height BIGINT NOT NULL,
|
|
91
|
+
chain_digest TEXT NOT NULL,
|
|
92
|
+
input_digest TEXT NOT NULL,
|
|
93
|
+
output_digest TEXT NOT NULL,
|
|
94
|
+
sealed_at TIMESTAMPTZ NOT NULL DEFAULT now(),
|
|
95
|
+
CONSTRAINT coverage_segments_range_ordered
|
|
96
|
+
CHECK (from_height <= to_height),
|
|
97
|
+
CONSTRAINT coverage_segments_stage_range_key
|
|
98
|
+
UNIQUE (stage_id, from_height, to_height)
|
|
99
|
+
)
|
|
100
|
+
`.execute(db);
|
|
101
|
+
|
|
102
|
+
await sql`
|
|
103
|
+
CREATE INDEX coverage_segments_stage_from_idx
|
|
104
|
+
ON coverage_segments (stage_id, from_height, to_height)
|
|
105
|
+
`.execute(db);
|
|
106
|
+
|
|
107
|
+
await sql`
|
|
108
|
+
CREATE TABLE stage_failures (
|
|
109
|
+
id BIGINT GENERATED ALWAYS AS IDENTITY PRIMARY KEY,
|
|
110
|
+
stage_id TEXT NOT NULL REFERENCES stage_registry (id),
|
|
111
|
+
run_id UUID REFERENCES stage_runs (id) ON DELETE SET NULL,
|
|
112
|
+
unit_kind TEXT NOT NULL
|
|
113
|
+
CHECK (unit_kind IN ('block', 'range', 'cursor', 'queue')),
|
|
114
|
+
from_height BIGINT CHECK (from_height IS NULL OR from_height >= 0),
|
|
115
|
+
to_height BIGINT CHECK (to_height IS NULL OR to_height >= 0),
|
|
116
|
+
class TEXT NOT NULL
|
|
117
|
+
CHECK (class IN (
|
|
118
|
+
'omission', 'version', 'digest_mismatch', 'crash',
|
|
119
|
+
'reorg', 'source_gap', 'handler', 'timeout', 'unknown'
|
|
120
|
+
)),
|
|
121
|
+
retry_state TEXT NOT NULL
|
|
122
|
+
CHECK (retry_state IN ('open', 'retrying', 'halted', 'resolved')),
|
|
123
|
+
retry_count INTEGER NOT NULL DEFAULT 0 CHECK (retry_count >= 0),
|
|
124
|
+
last_error TEXT,
|
|
125
|
+
created_at TIMESTAMPTZ NOT NULL DEFAULT now(),
|
|
126
|
+
resolved_at TIMESTAMPTZ,
|
|
127
|
+
retain_until TIMESTAMPTZ NOT NULL
|
|
128
|
+
DEFAULT (now() + interval '30 days'),
|
|
129
|
+
CONSTRAINT stage_failures_range_ordered
|
|
130
|
+
CHECK (
|
|
131
|
+
from_height IS NULL
|
|
132
|
+
OR to_height IS NULL
|
|
133
|
+
OR from_height <= to_height
|
|
134
|
+
),
|
|
135
|
+
CONSTRAINT stage_failures_retain_until
|
|
136
|
+
CHECK (retain_until >= created_at),
|
|
137
|
+
CONSTRAINT stage_failures_resolved_at
|
|
138
|
+
CHECK (retry_state <> 'resolved' OR resolved_at IS NOT NULL)
|
|
139
|
+
)
|
|
140
|
+
`.execute(db);
|
|
141
|
+
|
|
142
|
+
await sql`
|
|
143
|
+
CREATE INDEX stage_failures_open_idx
|
|
144
|
+
ON stage_failures (stage_id, retry_state, created_at)
|
|
145
|
+
WHERE retry_state <> 'resolved'
|
|
146
|
+
`.execute(db);
|
|
147
|
+
|
|
148
|
+
await sql`
|
|
149
|
+
CREATE INDEX stage_failures_retain_until_idx
|
|
150
|
+
ON stage_failures (retain_until)
|
|
151
|
+
`.execute(db);
|
|
152
|
+
});
|
|
153
|
+
}
|
|
154
|
+
|
|
155
|
+
export async function down(db: Kysely<unknown>): Promise<void> {
|
|
156
|
+
await onChainPlane(async () => {
|
|
157
|
+
await sql`DROP TABLE IF EXISTS stage_failures`.execute(db);
|
|
158
|
+
await sql`DROP TABLE IF EXISTS coverage_segments`.execute(db);
|
|
159
|
+
await sql`DROP TABLE IF EXISTS stage_block_receipts`.execute(db);
|
|
160
|
+
await sql`DROP TABLE IF EXISTS stage_runs`.execute(db);
|
|
161
|
+
await sql`DROP TABLE IF EXISTS stage_registry`.execute(db);
|
|
162
|
+
});
|
|
163
|
+
}
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@secondlayer/shared",
|
|
3
|
-
"version": "7.
|
|
3
|
+
"version": "7.11.0",
|
|
4
4
|
"license": "MIT",
|
|
5
5
|
"repository": {
|
|
6
6
|
"type": "git",
|
|
@@ -152,6 +152,14 @@
|
|
|
152
152
|
"types": "./dist/src/archive/derived-stage-report.d.ts",
|
|
153
153
|
"import": "./dist/src/archive/derived-stage-report.js"
|
|
154
154
|
},
|
|
155
|
+
"./coverage": {
|
|
156
|
+
"types": "./dist/src/coverage/index.d.ts",
|
|
157
|
+
"import": "./dist/src/coverage/index.js"
|
|
158
|
+
},
|
|
159
|
+
"./runtime": {
|
|
160
|
+
"types": "./dist/src/runtime/index.d.ts",
|
|
161
|
+
"import": "./dist/src/runtime/index.js"
|
|
162
|
+
},
|
|
155
163
|
"./errors": {
|
|
156
164
|
"types": "./dist/src/errors.d.ts",
|
|
157
165
|
"import": "./dist/src/errors.js"
|