@secondlayer/shared 18.0.2 → 19.0.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.
@@ -39,65 +39,6 @@ type Supervisor = {
39
39
  };
40
40
  declare function createSupervisor(modules: readonly RuntimeModule[]): Supervisor;
41
41
  /**
42
- * Handler isolation — untrusted subgraph handlers run behind a timeout,
43
- * optional network deny, and cannot take down the host process.
44
- */
45
- declare const ISOLATION_FAULTS: readonly ["timeout", "throw", "oom", "kill", "network"];
46
- type IsolationFault = (typeof ISOLATION_FAULTS)[number];
47
- type IsolationLimits = {
48
- timeoutMs: number
49
- memoryMb?: number
50
- allowNetwork?: boolean
51
- };
52
- type IsolationResult = {
53
- ok: true
54
- hostAlive: true
55
- } | {
56
- ok: false
57
- fault: IsolationFault
58
- hostAlive: true
59
- detail: string
60
- };
61
- declare class IsolationNetworkError extends Error {
62
- readonly name = "IsolationNetworkError";
63
- }
64
- declare class IsolationKillError extends Error {
65
- readonly name = "IsolationKillError";
66
- }
67
- declare class IsolationOomError extends Error {
68
- readonly name = "IsolationOomError";
69
- }
70
- declare function isolateHandler(run: (ctx: {
71
- signal: AbortSignal
72
- fetch: (url: string) => Promise<unknown>
73
- }) => Promise<void>, limits: IsolationLimits): Promise<IsolationResult>;
74
- /**
75
- * Embedded migration — advisory-locked before listeners/workers start.
76
- * Concurrent boots serialize. A failed pass releases the lock and refuses
77
- * to start the rest of the runtime.
78
- */
79
- declare const MIGRATION_LOCK_KEY = 1397509447;
80
- type EmbeddedMigration = {
81
- applied: string[]
82
- ok: boolean
83
- error: string | null
84
- };
85
- type MigrationRunner = {
86
- acquire: (key: number) => Promise<boolean>
87
- release: (key: number) => Promise<void>
88
- apply: () => Promise<string[]>
89
- };
90
- declare function migrateEmbedded(runner: MigrationRunner): Promise<EmbeddedMigration>;
91
- /** In-memory lock used by concurrent-startup tests. */
92
- declare function createMemoryMigrationRunner(opts?: {
93
- fail?: boolean
94
- delayMs?: number
95
- sleep?: (ms: number) => Promise<void>
96
- }): MigrationRunner & {
97
- holders: number
98
- appliedCount: number
99
- };
100
- /**
101
42
  * Minimal runtime config — six or fewer required non-secret values.
102
43
  * Unknown or contradictory values fail before ingest starts.
103
44
  */
@@ -129,28 +70,6 @@ type ConfigResult = {
129
70
  errors: string[]
130
71
  };
131
72
  declare function parseRuntimeConfig(env: Record<string, string | undefined>): ConfigResult;
132
- declare const COVERAGE_STATES: readonly ["complete", "syncing", "lagging", "gap", "stale", "failed", "unverified_import", "unanchored", "source_unavailable", "out_of_scope", "disabled"];
133
- type CoverageState = (typeof COVERAGE_STATES)[number];
134
- declare const STATUS_PLANES: readonly ["node", "raw", "decoder", "subgraph", "queue", "archive", "disk", "coverage"];
135
- type StatusPlane = (typeof STATUS_PLANES)[number];
136
- type PlaneStatus = {
137
- plane: StatusPlane
138
- state: string
139
- action: string
140
- };
141
- type RuntimeStatusReport = {
142
- status: SupervisorHealth["status"]
143
- modules: ModuleHealth[]
144
- planes: PlaneStatus[]
145
- };
146
- declare function reportRuntimeStatus(input: {
147
- supervisor: SupervisorHealth
148
- node?: string
149
- archive?: string
150
- disk?: string
151
- coverage?: CoverageState | string
152
- }): RuntimeStatusReport;
153
- declare function actionFor(plane: StatusPlane, state: string): string;
154
73
  declare const BACKUP_MANIFEST_VERSION = 1;
155
74
  declare const BACKUP_PARTS: readonly ["db", "config", "keys", "handlers", "scope"];
156
75
  type BackupPart = (typeof BACKUP_PARTS)[number];
@@ -237,44 +156,6 @@ declare function precheckRestore(input: {
237
156
  secretsKeyHex?: string
238
157
  }): RestorePrecheck;
239
158
  /**
240
- * Upgrade contract — pin image, preflight schema/disk, backup first,
241
- * migrate, health/verify, document rollback limits.
242
- *
243
- * PLANNER ONLY — `applyUpgrade` returns `{applied:true}` without pulling an
244
- * image, running a preflight, or migrating anything. Nothing in the product
245
- * calls it. The upgrade operators actually perform is `docker compose pull &&
246
- * up -d`, with migrations applied at boot by the runtime entrypoint.
247
- *
248
- * Same caution as the sibling backup planner: this step list was published as
249
- * an operator procedure in the self-host docs until 2026-08-15. Make it do the
250
- * work before presenting it as one.
251
- */
252
- declare const UPGRADE_STEPS: readonly ["pin", "preflight", "backup", "migrate", "health", "verify"];
253
- type UpgradeStep = (typeof UPGRADE_STEPS)[number];
254
- type UpgradePlan = {
255
- from: string
256
- to: string
257
- steps: UpgradeStep[]
258
- ok: boolean
259
- reason: string
260
- rollback: string
261
- };
262
- declare function planUpgrade(input: {
263
- from: string
264
- to: string
265
- diskOk: boolean
266
- schemaOk: boolean
267
- backupDone: boolean
268
- supported?: readonly string[]
269
- }): UpgradePlan;
270
- declare function applyUpgrade(plan: UpgradePlan, opts?: {
271
- apply?: boolean
272
- }): {
273
- ok: boolean
274
- applied: boolean
275
- reason: string
276
- };
277
- /**
278
159
  * Resource guardrails — preflight RAM/disk/Postgres and estimate growth.
279
160
  * Constrained fixtures fail early.
280
161
  *
@@ -368,4 +249,4 @@ declare function runPreflight(input: {
368
249
  }): Promise<PreflightDecision>;
369
250
  declare const MODULE_COMMANDS: Record<ModuleId, readonly string[]>;
370
251
  declare function commandFor(id: ModuleId): readonly string[];
371
- export { BACKUP_MANIFEST_VERSION, BACKUP_PARTS, BackupManifest, BackupPart, BackupPlan, ConfigResult, DEFAULT_PROFILE, DiskEstimates, EmbeddedMigration, FLOORS, GuardrailNetwork, GuardrailResult, ISOLATION_FAULTS, IsolationFault, IsolationKillError, IsolationLimits, IsolationNetworkError, IsolationOomError, IsolationResult, MIGRATION_LOCK_KEY, MODULE_COMMANDS, MODULE_IDS, MODULE_STATES, MeasuredResources, MigrationRunner, ModuleHealth, ModuleId, ModuleState, NETWORKS, NODE_MODES, NodeMode, OPTIONAL_KEYS, PUBLISHER_PROFILE, PlaneStatus, PreflightDecision, REQUIRED_KEYS, RequiredConfigKey, ResourceSnapshot, RestorePrecheck, RuntimeConfig, RuntimeModule, RuntimeNetwork, RuntimeStatusReport, SECRET_KEYS, STATUS_PLANES, StatusPlane, Supervisor, SupervisorHealth, UNDERSIZED_OVERRIDE, UPGRADE_STEPS, UpgradePlan, UpgradeStep, actionFor, applyUpgrade, commandFor, createMemoryMigrationRunner, createMemoryModule, createSupervisor, decidePreflight, decryptBundle, diskFloorGb, emptyHealth, encryptBundle, isModuleId, isolateHandler, keyMatchesCanary, measureResources, migrateEmbedded, parseRuntimeConfig, planBackup, planUpgrade, precheckRestore, preflightResources, reportRuntimeStatus, runPreflight, sealKeyCanary };
252
+ export { BACKUP_MANIFEST_VERSION, BACKUP_PARTS, BackupManifest, BackupPart, BackupPlan, ConfigResult, DEFAULT_PROFILE, DiskEstimates, FLOORS, GuardrailNetwork, GuardrailResult, MODULE_COMMANDS, MODULE_IDS, MODULE_STATES, MeasuredResources, ModuleHealth, ModuleId, ModuleState, NETWORKS, NODE_MODES, NodeMode, OPTIONAL_KEYS, PUBLISHER_PROFILE, PreflightDecision, REQUIRED_KEYS, RequiredConfigKey, ResourceSnapshot, RestorePrecheck, RuntimeConfig, RuntimeModule, RuntimeNetwork, SECRET_KEYS, Supervisor, SupervisorHealth, UNDERSIZED_OVERRIDE, commandFor, createMemoryModule, createSupervisor, decidePreflight, decryptBundle, diskFloorGb, emptyHealth, encryptBundle, isModuleId, keyMatchesCanary, measureResources, parseRuntimeConfig, planBackup, precheckRestore, preflightResources, runPreflight, sealKeyCanary };
@@ -182,150 +182,6 @@ function createSupervisor(modules) {
182
182
  }
183
183
  };
184
184
  }
185
- // src/runtime/isolate.ts
186
- var ISOLATION_FAULTS = [
187
- "timeout",
188
- "throw",
189
- "oom",
190
- "kill",
191
- "network"
192
- ];
193
-
194
- class IsolationNetworkError extends Error {
195
- name = "IsolationNetworkError";
196
- }
197
-
198
- class IsolationKillError extends Error {
199
- name = "IsolationKillError";
200
- }
201
-
202
- class IsolationOomError extends Error {
203
- name = "IsolationOomError";
204
- }
205
- async function isolateHandler(run, limits) {
206
- const controller = new AbortController;
207
- const timer = setTimeout(() => controller.abort(), limits.timeoutMs);
208
- const blockedFetch = async (_url) => {
209
- throw new IsolationNetworkError("network is disabled in this handler");
210
- };
211
- try {
212
- await run({
213
- signal: controller.signal,
214
- fetch: limits.allowNetwork ? (url) => fetch(url) : blockedFetch
215
- });
216
- if (controller.signal.aborted) {
217
- return {
218
- ok: false,
219
- fault: "timeout",
220
- hostAlive: true,
221
- detail: `exceeded ${limits.timeoutMs}ms`
222
- };
223
- }
224
- return { ok: true, hostAlive: true };
225
- } catch (error) {
226
- if (controller.signal.aborted || isAbort(error)) {
227
- return {
228
- ok: false,
229
- fault: "timeout",
230
- hostAlive: true,
231
- detail: `exceeded ${limits.timeoutMs}ms`
232
- };
233
- }
234
- if (error instanceof IsolationNetworkError) {
235
- return {
236
- ok: false,
237
- fault: "network",
238
- hostAlive: true,
239
- detail: error.message
240
- };
241
- }
242
- if (error instanceof IsolationKillError) {
243
- return {
244
- ok: false,
245
- fault: "kill",
246
- hostAlive: true,
247
- detail: error.message
248
- };
249
- }
250
- if (error instanceof IsolationOomError) {
251
- return {
252
- ok: false,
253
- fault: "oom",
254
- hostAlive: true,
255
- detail: error.message
256
- };
257
- }
258
- return {
259
- ok: false,
260
- fault: "throw",
261
- hostAlive: true,
262
- detail: error instanceof Error ? error.message : String(error)
263
- };
264
- } finally {
265
- clearTimeout(timer);
266
- }
267
- }
268
- function isAbort(error) {
269
- return error instanceof Error && error.name === "AbortError";
270
- }
271
- // src/runtime/migrate-embed.ts
272
- var MIGRATION_LOCK_KEY = 1397509447;
273
- async function migrateEmbedded(runner) {
274
- const got = await runner.acquire(MIGRATION_LOCK_KEY);
275
- if (!got) {
276
- return {
277
- applied: [],
278
- ok: false,
279
- error: "migration lock held by another process"
280
- };
281
- }
282
- try {
283
- const applied = await runner.apply();
284
- return { applied, ok: true, error: null };
285
- } catch (error) {
286
- return {
287
- applied: [],
288
- ok: false,
289
- error: error instanceof Error ? error.message : String(error)
290
- };
291
- } finally {
292
- await runner.release(MIGRATION_LOCK_KEY);
293
- }
294
- }
295
- function createMemoryMigrationRunner(opts) {
296
- let held = false;
297
- const state = { holders: 0, appliedCount: 0 };
298
- return {
299
- get holders() {
300
- return state.holders;
301
- },
302
- get appliedCount() {
303
- return state.appliedCount;
304
- },
305
- async acquire() {
306
- if (held)
307
- return false;
308
- held = true;
309
- state.holders += 1;
310
- return true;
311
- },
312
- async release() {
313
- held = false;
314
- state.holders = Math.max(0, state.holders - 1);
315
- },
316
- async apply() {
317
- if (opts?.delayMs)
318
- await (opts.sleep ?? delay)(opts.delayMs);
319
- if (opts?.fail)
320
- throw new Error("migration failed");
321
- state.appliedCount += 1;
322
- return ["0116_coverage_schema"];
323
- }
324
- };
325
- }
326
- function delay(ms) {
327
- return new Promise((resolve) => setTimeout(resolve, ms));
328
- }
329
185
  // src/runtime/config.ts
330
186
  var NODE_MODES = ["external", "stacks", "full"];
331
187
  var NETWORKS = ["mainnet", "testnet", "devnet"];
@@ -453,80 +309,6 @@ function parsePort(raw, name, errors) {
453
309
  }
454
310
  return n;
455
311
  }
456
- // src/runtime/status.ts
457
- var STATUS_PLANES = [
458
- "node",
459
- "raw",
460
- "decoder",
461
- "subgraph",
462
- "queue",
463
- "archive",
464
- "disk",
465
- "coverage"
466
- ];
467
- var MODULE_TO_PLANE = {
468
- ingest: "raw",
469
- decoder: "decoder",
470
- subgraph: "subgraph",
471
- notification: "queue"
472
- };
473
- function reportRuntimeStatus(input) {
474
- const planes = [];
475
- planes.push({
476
- plane: "node",
477
- state: input.node ?? "unknown",
478
- action: actionFor("node", input.node ?? "unknown")
479
- });
480
- for (const mod of input.supervisor.modules) {
481
- const plane = MODULE_TO_PLANE[mod.id];
482
- if (!plane)
483
- continue;
484
- planes.push({
485
- plane,
486
- state: mod.state,
487
- action: actionFor(plane, mod.state)
488
- });
489
- }
490
- planes.push({
491
- plane: "archive",
492
- state: input.archive ?? "idle",
493
- action: actionFor("archive", input.archive ?? "idle")
494
- });
495
- planes.push({
496
- plane: "disk",
497
- state: input.disk ?? "ok",
498
- action: actionFor("disk", input.disk ?? "ok")
499
- });
500
- planes.push({
501
- plane: "coverage",
502
- state: input.coverage ?? "unknown",
503
- action: actionFor("coverage", String(input.coverage ?? "unknown"))
504
- });
505
- return {
506
- status: input.supervisor.status,
507
- modules: input.supervisor.modules,
508
- planes
509
- };
510
- }
511
- function actionFor(plane, state) {
512
- if (state === "running" || state === "ok" || state === "complete") {
513
- return "none";
514
- }
515
- if (state === "failed" || state === "gap") {
516
- return plane === "raw" || plane === "coverage" ? "sl verify all --against <manifest>" : `restart ${plane}`;
517
- }
518
- if (state === "lagging" || state === "syncing")
519
- return "wait for catch-up";
520
- if (state === "stale")
521
- return "refresh source tip";
522
- if (plane === "archive" && state === "idle")
523
- return "sl bootstrap --against <manifest>";
524
- if (plane === "disk" && state !== "ok")
525
- return "free disk and retry";
526
- if (plane === "node" && state === "unknown")
527
- return "sl observer";
528
- return "inspect logs";
529
- }
530
312
  // src/runtime/backup.ts
531
313
  import {
532
314
  createCipheriv,
@@ -687,83 +469,6 @@ function precheckRestore(input) {
687
469
  }
688
470
  return { ok: true };
689
471
  }
690
- // src/runtime/upgrade.ts
691
- var UPGRADE_STEPS = [
692
- "pin",
693
- "preflight",
694
- "backup",
695
- "migrate",
696
- "health",
697
- "verify"
698
- ];
699
- function planUpgrade(input) {
700
- const rollback = "roll back to the pinned previous image; schema migrations are forward-only";
701
- if (input.from === input.to) {
702
- return {
703
- from: input.from,
704
- to: input.to,
705
- steps: [],
706
- ok: false,
707
- reason: "from and to are the same image",
708
- rollback
709
- };
710
- }
711
- if (input.supported && !input.supported.includes(input.to)) {
712
- return {
713
- from: input.from,
714
- to: input.to,
715
- steps: [],
716
- ok: false,
717
- reason: `image ${input.to} is not in the supported matrix`,
718
- rollback
719
- };
720
- }
721
- if (!input.diskOk) {
722
- return {
723
- from: input.from,
724
- to: input.to,
725
- steps: ["pin", "preflight"],
726
- ok: false,
727
- reason: "disk preflight failed",
728
- rollback
729
- };
730
- }
731
- if (!input.schemaOk) {
732
- return {
733
- from: input.from,
734
- to: input.to,
735
- steps: ["pin", "preflight"],
736
- ok: false,
737
- reason: "schema preflight failed",
738
- rollback
739
- };
740
- }
741
- if (!input.backupDone) {
742
- return {
743
- from: input.from,
744
- to: input.to,
745
- steps: ["pin", "preflight", "backup"],
746
- ok: false,
747
- reason: "backup required before migrate",
748
- rollback
749
- };
750
- }
751
- return {
752
- from: input.from,
753
- to: input.to,
754
- steps: [...UPGRADE_STEPS],
755
- ok: true,
756
- reason: "dry-run upgrade",
757
- rollback
758
- };
759
- }
760
- function applyUpgrade(plan, opts) {
761
- if (!plan.ok)
762
- return { ok: false, applied: false, reason: plan.reason };
763
- if (!opts?.apply)
764
- return { ok: true, applied: false, reason: plan.reason };
765
- return { ok: true, applied: true, reason: "upgrade applied" };
766
- }
767
472
  // src/runtime/guardrails.ts
768
473
  var MEASURED_DISK = {
769
474
  diskGbPer100kBlocks: 3,
@@ -910,11 +615,6 @@ export {
910
615
  BACKUP_PARTS,
911
616
  DEFAULT_PROFILE,
912
617
  FLOORS,
913
- ISOLATION_FAULTS,
914
- IsolationKillError,
915
- IsolationNetworkError,
916
- IsolationOomError,
917
- MIGRATION_LOCK_KEY,
918
618
  MODULE_COMMANDS,
919
619
  MODULE_IDS,
920
620
  MODULE_STATES,
@@ -924,13 +624,8 @@ export {
924
624
  PUBLISHER_PROFILE,
925
625
  REQUIRED_KEYS,
926
626
  SECRET_KEYS,
927
- STATUS_PLANES,
928
627
  UNDERSIZED_OVERRIDE,
929
- UPGRADE_STEPS,
930
- actionFor,
931
- applyUpgrade,
932
628
  commandFor,
933
- createMemoryMigrationRunner,
934
629
  createMemoryModule,
935
630
  createSupervisor,
936
631
  decidePreflight,
@@ -939,19 +634,15 @@ export {
939
634
  emptyHealth,
940
635
  encryptBundle,
941
636
  isModuleId,
942
- isolateHandler,
943
637
  keyMatchesCanary,
944
638
  measureResources,
945
- migrateEmbedded,
946
639
  parseRuntimeConfig,
947
640
  planBackup,
948
- planUpgrade,
949
641
  precheckRestore,
950
642
  preflightResources,
951
- reportRuntimeStatus,
952
643
  runPreflight,
953
644
  sealKeyCanary
954
645
  };
955
646
 
956
- //# debugId=D116744B4730D96D64756E2164756E21
647
+ //# debugId=BEFFE5FEA5ECCBC464756E2164756E21
957
648
  //# sourceMappingURL=index.js.map