@secondlayer/cli 5.8.0 → 5.10.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/cli.js +524 -97
- package/dist/cli.js.map +7 -4
- package/package.json +4 -3
package/dist/cli.js
CHANGED
|
@@ -2565,6 +2565,9 @@ function cyan(text) {
|
|
|
2565
2565
|
function dim(text) {
|
|
2566
2566
|
return `${colors.dim}${text}${colors.reset}`;
|
|
2567
2567
|
}
|
|
2568
|
+
function bold(text) {
|
|
2569
|
+
return `${colors.bold}${text}${colors.reset}`;
|
|
2570
|
+
}
|
|
2568
2571
|
function success(message) {
|
|
2569
2572
|
console.log(green(`✓ ${message}`));
|
|
2570
2573
|
}
|
|
@@ -5906,8 +5909,8 @@ var require_source = __commonJS((exports, module) => {
|
|
|
5906
5909
|
var deferToConnect = (socket, fn) => {
|
|
5907
5910
|
let listeners;
|
|
5908
5911
|
if (typeof fn === "function") {
|
|
5909
|
-
const
|
|
5910
|
-
listeners = { connect };
|
|
5912
|
+
const connect2 = fn;
|
|
5913
|
+
listeners = { connect: connect2 };
|
|
5911
5914
|
} else {
|
|
5912
5915
|
listeners = fn;
|
|
5913
5916
|
}
|
|
@@ -9808,7 +9811,7 @@ var require_client_request = __commonJS((exports, module) => {
|
|
|
9808
9811
|
// ../../node_modules/resolve-alpn/index.js
|
|
9809
9812
|
var require_resolve_alpn = __commonJS((exports, module) => {
|
|
9810
9813
|
var tls2 = __require("tls");
|
|
9811
|
-
module.exports = (options = {},
|
|
9814
|
+
module.exports = (options = {}, connect2 = tls2.connect) => new Promise((resolve2, reject) => {
|
|
9812
9815
|
let timeout = false;
|
|
9813
9816
|
let socket;
|
|
9814
9817
|
const callback = async () => {
|
|
@@ -9832,7 +9835,7 @@ var require_resolve_alpn = __commonJS((exports, module) => {
|
|
|
9832
9835
|
};
|
|
9833
9836
|
const socketPromise = (async () => {
|
|
9834
9837
|
try {
|
|
9835
|
-
socket = await
|
|
9838
|
+
socket = await connect2(options, callback);
|
|
9836
9839
|
socket.on("error", reject);
|
|
9837
9840
|
socket.once("timeout", onTimeout);
|
|
9838
9841
|
} catch (error2) {
|
|
@@ -9910,7 +9913,7 @@ var require_auto = __commonJS((exports, module) => {
|
|
|
9910
9913
|
socket.on("agentRemove", onRemove);
|
|
9911
9914
|
agent.emit("free", socket, options);
|
|
9912
9915
|
};
|
|
9913
|
-
var createResolveProtocol = (cache2, queue2 = new Map,
|
|
9916
|
+
var createResolveProtocol = (cache2, queue2 = new Map, connect2 = undefined) => {
|
|
9914
9917
|
return async (options) => {
|
|
9915
9918
|
const name = `${options.host}:${options.port}:${options.ALPNProtocols.sort()}`;
|
|
9916
9919
|
if (!cache2.has(name)) {
|
|
@@ -9920,7 +9923,7 @@ var require_auto = __commonJS((exports, module) => {
|
|
|
9920
9923
|
}
|
|
9921
9924
|
const { path: path2 } = options;
|
|
9922
9925
|
options.path = options.socketPath;
|
|
9923
|
-
const resultPromise = resolveALPN(options,
|
|
9926
|
+
const resultPromise = resolveALPN(options, connect2);
|
|
9924
9927
|
queue2.set(name, resultPromise);
|
|
9925
9928
|
try {
|
|
9926
9929
|
const result = await resultPromise;
|
|
@@ -13345,10 +13348,10 @@ var init_manager = __esm(() => {
|
|
|
13345
13348
|
});
|
|
13346
13349
|
|
|
13347
13350
|
// src/services/indexer.ts
|
|
13348
|
-
import { dirname as
|
|
13351
|
+
import { dirname as dirname6, resolve as resolve3 } from "node:path";
|
|
13349
13352
|
async function startIndexer(options2) {
|
|
13350
13353
|
const port = options2.port ?? 3700;
|
|
13351
|
-
const rootDir =
|
|
13354
|
+
const rootDir = dirname6(dirname6(dirname6(dirname6(import.meta.dir))));
|
|
13352
13355
|
const indexerPath = resolve3(rootDir, "packages/indexer/src/index.ts");
|
|
13353
13356
|
await serviceManager.start(SERVICE_NAME, ["bun", "run", "--watch", indexerPath], {
|
|
13354
13357
|
port,
|
|
@@ -13365,9 +13368,9 @@ var init_indexer = __esm(() => {
|
|
|
13365
13368
|
});
|
|
13366
13369
|
|
|
13367
13370
|
// src/services/worker.ts
|
|
13368
|
-
import { dirname as
|
|
13371
|
+
import { dirname as dirname7, resolve as resolve4 } from "node:path";
|
|
13369
13372
|
async function startWorker(options2) {
|
|
13370
|
-
const rootDir =
|
|
13373
|
+
const rootDir = dirname7(dirname7(dirname7(dirname7(import.meta.dir))));
|
|
13371
13374
|
const workerPath = resolve4(rootDir, "packages/worker/src/index.ts");
|
|
13372
13375
|
await serviceManager.start(SERVICE_NAME2, ["bun", "run", "--watch", workerPath], {
|
|
13373
13376
|
onStdout: options2.onLog,
|
|
@@ -13380,10 +13383,10 @@ var init_worker = __esm(() => {
|
|
|
13380
13383
|
});
|
|
13381
13384
|
|
|
13382
13385
|
// src/services/api.ts
|
|
13383
|
-
import { dirname as
|
|
13386
|
+
import { dirname as dirname8, resolve as resolve5 } from "node:path";
|
|
13384
13387
|
async function startApi(options2) {
|
|
13385
13388
|
const port = options2.port ?? 3800;
|
|
13386
|
-
const rootDir =
|
|
13389
|
+
const rootDir = dirname8(dirname8(dirname8(dirname8(import.meta.dir))));
|
|
13387
13390
|
const apiPath = resolve5(rootDir, "packages/api/src/index.ts");
|
|
13388
13391
|
await serviceManager.start(SERVICE_NAME3, ["bun", "run", "--watch", apiPath], {
|
|
13389
13392
|
port,
|
|
@@ -13400,9 +13403,9 @@ var init_api2 = __esm(() => {
|
|
|
13400
13403
|
});
|
|
13401
13404
|
|
|
13402
13405
|
// src/services/subgraph-processor.ts
|
|
13403
|
-
import { dirname as
|
|
13406
|
+
import { dirname as dirname9, resolve as resolve6 } from "node:path";
|
|
13404
13407
|
async function startSubgraphProcessor(options2) {
|
|
13405
|
-
const rootDir =
|
|
13408
|
+
const rootDir = dirname9(dirname9(dirname9(dirname9(import.meta.dir))));
|
|
13406
13409
|
const servicePath = resolve6(rootDir, "packages/subgraphs/src/service.ts");
|
|
13407
13410
|
await serviceManager.start(SERVICE_NAME4, ["bun", "run", "--watch", servicePath], {
|
|
13408
13411
|
env: {
|
|
@@ -13437,8 +13440,8 @@ __export(exports_dev_impl, {
|
|
|
13437
13440
|
restartDev: () => restartDev,
|
|
13438
13441
|
isDevAlreadyRunning: () => isDevAlreadyRunning
|
|
13439
13442
|
});
|
|
13440
|
-
import { mkdirSync as
|
|
13441
|
-
import { dirname as
|
|
13443
|
+
import { mkdirSync as mkdirSync4 } from "node:fs";
|
|
13444
|
+
import { dirname as dirname10, join as join9, resolve as resolve7 } from "node:path";
|
|
13442
13445
|
async function isDevAlreadyRunning() {
|
|
13443
13446
|
if (await isDevRunning()) {
|
|
13444
13447
|
const running = await getRunningServices();
|
|
@@ -13516,7 +13519,7 @@ async function runBackground(options2) {
|
|
|
13516
13519
|
startedAt: new Date().toISOString()
|
|
13517
13520
|
};
|
|
13518
13521
|
try {
|
|
13519
|
-
const packagesDir =
|
|
13522
|
+
const packagesDir = dirname10(dirname10(dirname10(dirname10(import.meta.dir))));
|
|
13520
13523
|
const env = { DATABASE_URL: databaseUrl, DEV_MODE: "true" };
|
|
13521
13524
|
const apiLogFile = getLogFile("api");
|
|
13522
13525
|
const apiProc = Bun.spawn(["bun", "run", resolve7(packagesDir, "packages/api/src/index.ts")], {
|
|
@@ -13866,7 +13869,7 @@ async function restartDev() {
|
|
|
13866
13869
|
await clearDevState();
|
|
13867
13870
|
await clearLogs();
|
|
13868
13871
|
const config = await loadConfig();
|
|
13869
|
-
const packagesDir =
|
|
13872
|
+
const packagesDir = dirname10(dirname10(dirname10(dirname10(import.meta.dir))));
|
|
13870
13873
|
const env = state.env;
|
|
13871
13874
|
const newState = {
|
|
13872
13875
|
services: {},
|
|
@@ -13974,8 +13977,8 @@ function printRunningServices(services) {
|
|
|
13974
13977
|
console.log(blue("Services"));
|
|
13975
13978
|
for (const [name, service] of Object.entries(services)) {
|
|
13976
13979
|
const portInfo = service.port ? dim(`http://localhost:${service.port}`) : dim("background");
|
|
13977
|
-
const
|
|
13978
|
-
console.log(` ${
|
|
13980
|
+
const status2 = isProcessRunning(service.pid) ? green("✓") : red("✗");
|
|
13981
|
+
console.log(` ${status2} ${name.padEnd(10)} ${portInfo} ${dim(`(pid ${service.pid})`)}`);
|
|
13979
13982
|
}
|
|
13980
13983
|
}
|
|
13981
13984
|
async function isContainerRunning(name) {
|
|
@@ -14047,8 +14050,8 @@ async function ensureDevPostgres(dataDir) {
|
|
|
14047
14050
|
if (check.stdout.toString().trim()) {
|
|
14048
14051
|
return false;
|
|
14049
14052
|
}
|
|
14050
|
-
const pgDataDir =
|
|
14051
|
-
|
|
14053
|
+
const pgDataDir = join9(dataDir, "postgres");
|
|
14054
|
+
mkdirSync4(pgDataDir, { recursive: true });
|
|
14052
14055
|
const stopped = await Bun.$`docker ps -aq -f name=secondlayer-dev-postgres`.quiet().nothrow();
|
|
14053
14056
|
if (stopped.stdout.toString().trim()) {
|
|
14054
14057
|
await Bun.$`docker rm secondlayer-dev-postgres`.quiet().nothrow();
|
|
@@ -14063,7 +14066,7 @@ async function ensureDevPostgres(dataDir) {
|
|
|
14063
14066
|
throw new Error("PostgreSQL failed to start");
|
|
14064
14067
|
}
|
|
14065
14068
|
async function runMigrations(databaseUrl) {
|
|
14066
|
-
const packagesDir =
|
|
14069
|
+
const packagesDir = dirname10(dirname10(dirname10(dirname10(import.meta.dir))));
|
|
14067
14070
|
const migrateScript = resolve7(packagesDir, "packages/shared/src/db/migrate.ts");
|
|
14068
14071
|
const result = await Bun.$`DATABASE_URL=${databaseUrl} bun run ${migrateScript}`.quiet().nothrow();
|
|
14069
14072
|
if (result.exitCode !== 0) {
|
|
@@ -21791,11 +21794,11 @@ var init_commands = __esm(() => {
|
|
|
21791
21794
|
});
|
|
21792
21795
|
|
|
21793
21796
|
// ../../node_modules/@antfu/ni/dist/shared/ni.B5qNAuoI.mjs
|
|
21794
|
-
import path3, { join as
|
|
21797
|
+
import path3, { join as join11, dirname as dirname12, resolve as resolve9 } from "node:path";
|
|
21795
21798
|
import process$1 from "node:process";
|
|
21796
21799
|
import require$$0 from "readline";
|
|
21797
21800
|
import require$$2 from "events";
|
|
21798
|
-
import fs5, { promises, existsSync as
|
|
21801
|
+
import fs5, { promises, existsSync as existsSync6 } from "node:fs";
|
|
21799
21802
|
import require$$0$1 from "os";
|
|
21800
21803
|
import require$$1 from "tty";
|
|
21801
21804
|
import os4 from "node:os";
|
|
@@ -24806,7 +24809,7 @@ function requireLib() {
|
|
|
24806
24809
|
return lib;
|
|
24807
24810
|
hasRequiredLib = 1;
|
|
24808
24811
|
const { isexe, sync: isexeSync } = requireCjs();
|
|
24809
|
-
const { join:
|
|
24812
|
+
const { join: join12, delimiter, sep, posix: posix2 } = require$$1$2;
|
|
24810
24813
|
const isWindows = process.platform === "win32";
|
|
24811
24814
|
const rSlash = new RegExp(`[${posix2.sep}${sep === posix2.sep ? "" : sep}]`.replace(/(\\)/g, "\\$1"));
|
|
24812
24815
|
const rRel = new RegExp(`^\\.${rSlash.source}`);
|
|
@@ -24833,7 +24836,7 @@ function requireLib() {
|
|
|
24833
24836
|
const getPathPart = (raw, cmd) => {
|
|
24834
24837
|
const pathPart = /^".*"$/.test(raw) ? raw.slice(1, -1) : raw;
|
|
24835
24838
|
const prefix = !pathPart && rRel.test(cmd) ? cmd.slice(0, 2) : "";
|
|
24836
|
-
return prefix +
|
|
24839
|
+
return prefix + join12(pathPart, cmd);
|
|
24837
24840
|
};
|
|
24838
24841
|
const which = async (cmd, opt = {}) => {
|
|
24839
24842
|
const { pathEnv, pathExt, pathExtExe } = getPathInfo(cmd, opt);
|
|
@@ -24982,7 +24985,7 @@ var init_ni_B5qNAuoI = __esm(() => {
|
|
|
24982
24985
|
options2 = {};
|
|
24983
24986
|
libExports = requireLib();
|
|
24984
24987
|
which = /* @__PURE__ */ getDefaultExportFromCjs(libExports);
|
|
24985
|
-
CLI_TEMP_DIR =
|
|
24988
|
+
CLI_TEMP_DIR = join11(os4.tmpdir(), "antfu-ni");
|
|
24986
24989
|
customRcPath = process$1.env.NI_CONFIG_FILE;
|
|
24987
24990
|
home = process$1.platform === "win32" ? process$1.env.USERPROFILE : process$1.env.HOME;
|
|
24988
24991
|
defaultRcPath = path3.join(home || "~/", ".nirc");
|
|
@@ -25635,11 +25638,11 @@ var hasColors, format = (open, close) => {
|
|
|
25635
25638
|
result += string.slice(lastIndex) + closeCode;
|
|
25636
25639
|
return result;
|
|
25637
25640
|
};
|
|
25638
|
-
}, reset2,
|
|
25641
|
+
}, reset2, bold2, dim2, italic, underline, overline, inverse, hidden, strikethrough, black, red2, green2, yellow2, blue2, magenta2, cyan2, white, gray, bgBlack, bgRed, bgGreen, bgYellow, bgBlue, bgMagenta, bgCyan, bgWhite, bgGray, redBright, greenBright, yellowBright, blueBright, magentaBright, cyanBright, whiteBright, bgRedBright, bgGreenBright, bgYellowBright, bgBlueBright, bgMagentaBright, bgCyanBright, bgWhiteBright;
|
|
25639
25642
|
var init_base = __esm(() => {
|
|
25640
25643
|
hasColors = tty2?.WriteStream?.prototype?.hasColors?.() ?? false;
|
|
25641
25644
|
reset2 = format(0, 0);
|
|
25642
|
-
|
|
25645
|
+
bold2 = format(1, 22);
|
|
25643
25646
|
dim2 = format(2, 22);
|
|
25644
25647
|
italic = format(3, 23);
|
|
25645
25648
|
underline = format(4, 24);
|
|
@@ -25717,7 +25720,7 @@ var init_default = __esm(() => {
|
|
|
25717
25720
|
duration: getFinalIcon
|
|
25718
25721
|
};
|
|
25719
25722
|
COLORS = {
|
|
25720
|
-
command: () =>
|
|
25723
|
+
command: () => bold2,
|
|
25721
25724
|
output: () => identity,
|
|
25722
25725
|
ipc: () => identity,
|
|
25723
25726
|
error: ({ reject }) => reject ? redBright : yellowBright,
|
|
@@ -26263,14 +26266,14 @@ var require_enoent = __commonJS((exports, module) => {
|
|
|
26263
26266
|
return originalEmit.apply(cp, arguments);
|
|
26264
26267
|
};
|
|
26265
26268
|
}
|
|
26266
|
-
function verifyENOENT(
|
|
26267
|
-
if (isWin &&
|
|
26269
|
+
function verifyENOENT(status2, parsed) {
|
|
26270
|
+
if (isWin && status2 === 1 && !parsed.file) {
|
|
26268
26271
|
return notFoundError(parsed.original, "spawn");
|
|
26269
26272
|
}
|
|
26270
26273
|
return null;
|
|
26271
26274
|
}
|
|
26272
|
-
function verifyENOENTSync(
|
|
26273
|
-
if (isWin &&
|
|
26275
|
+
function verifyENOENTSync(status2, parsed) {
|
|
26276
|
+
if (isWin && status2 === 1 && !parsed.file) {
|
|
26274
26277
|
return notFoundError(parsed.original, "spawnSync");
|
|
26275
26278
|
}
|
|
26276
26279
|
return null;
|
|
@@ -26294,7 +26297,7 @@ var require_cross_spawn = __commonJS((exports, module) => {
|
|
|
26294
26297
|
enoent.hookChildProcess(spawned, parsed);
|
|
26295
26298
|
return spawned;
|
|
26296
26299
|
}
|
|
26297
|
-
function
|
|
26300
|
+
function spawnSync2(command, args, options3) {
|
|
26298
26301
|
const parsed = parse2(command, args, options3);
|
|
26299
26302
|
const result = cp.spawnSync(parsed.command, parsed.args, parsed.options);
|
|
26300
26303
|
result.error = result.error || enoent.verifyENOENTSync(result.status, parsed);
|
|
@@ -26302,7 +26305,7 @@ var require_cross_spawn = __commonJS((exports, module) => {
|
|
|
26302
26305
|
}
|
|
26303
26306
|
module.exports = spawn2;
|
|
26304
26307
|
module.exports.spawn = spawn2;
|
|
26305
|
-
module.exports.sync =
|
|
26308
|
+
module.exports.sync = spawnSync2;
|
|
26306
26309
|
module.exports._parse = parse2;
|
|
26307
26310
|
module.exports._enoent = enoent;
|
|
26308
26311
|
});
|
|
@@ -28706,7 +28709,7 @@ var init_stdio_option = __esm(() => {
|
|
|
28706
28709
|
});
|
|
28707
28710
|
|
|
28708
28711
|
// ../../node_modules/execa/lib/stdio/native.js
|
|
28709
|
-
import { readFileSync as
|
|
28712
|
+
import { readFileSync as readFileSync4 } from "node:fs";
|
|
28710
28713
|
import tty3 from "node:tty";
|
|
28711
28714
|
var handleNativeStream = ({ stdioItem, stdioItem: { type }, isStdioArray, fdNumber, direction, isSync }) => {
|
|
28712
28715
|
if (!isStdioArray || type !== "native") {
|
|
@@ -28738,7 +28741,7 @@ var handleNativeStream = ({ stdioItem, stdioItem: { type }, isStdioArray, fdNumb
|
|
|
28738
28741
|
if (tty3.isatty(targetFdNumber)) {
|
|
28739
28742
|
throw new TypeError(`The \`${optionName}: ${serializeOptionValue(value)}\` option is invalid: it cannot be a TTY with synchronous methods.`);
|
|
28740
28743
|
}
|
|
28741
|
-
return { type: "uint8Array", value: bufferToUint8Array(
|
|
28744
|
+
return { type: "uint8Array", value: bufferToUint8Array(readFileSync4(targetFdNumber)), optionName };
|
|
28742
28745
|
}, getTargetFdNumber = (value, fdNumber) => {
|
|
28743
28746
|
if (value === "inherit") {
|
|
28744
28747
|
return fdNumber;
|
|
@@ -29041,7 +29044,7 @@ var init_handle = __esm(() => {
|
|
|
29041
29044
|
});
|
|
29042
29045
|
|
|
29043
29046
|
// ../../node_modules/execa/lib/stdio/handle-sync.js
|
|
29044
|
-
import { readFileSync as
|
|
29047
|
+
import { readFileSync as readFileSync5 } from "node:fs";
|
|
29045
29048
|
var handleStdioSync = (options3, verboseInfo) => handleStdio(addPropertiesSync, options3, verboseInfo, true), forbiddenIfSync = ({ type, optionName }) => {
|
|
29046
29049
|
throwInvalidSyncValue(optionName, TYPE_TO_MESSAGE[type]);
|
|
29047
29050
|
}, forbiddenNativeIfSync = ({ optionName, value }) => {
|
|
@@ -29069,8 +29072,8 @@ var init_handle_sync = __esm(() => {
|
|
|
29069
29072
|
addPropertiesSync = {
|
|
29070
29073
|
input: {
|
|
29071
29074
|
...addProperties,
|
|
29072
|
-
fileUrl: ({ value }) => ({ contents: [bufferToUint8Array(
|
|
29073
|
-
filePath: ({ value: { file } }) => ({ contents: [bufferToUint8Array(
|
|
29075
|
+
fileUrl: ({ value }) => ({ contents: [bufferToUint8Array(readFileSync5(value))] }),
|
|
29076
|
+
filePath: ({ value: { file } }) => ({ contents: [bufferToUint8Array(readFileSync5(file))] }),
|
|
29074
29077
|
fileNumber: forbiddenIfSync,
|
|
29075
29078
|
iterable: ({ value }) => ({ contents: [...value] }),
|
|
29076
29079
|
string: ({ value }) => ({ contents: [value] }),
|
|
@@ -29439,7 +29442,7 @@ var init_output2 = __esm(() => {
|
|
|
29439
29442
|
});
|
|
29440
29443
|
|
|
29441
29444
|
// ../../node_modules/execa/lib/io/output-sync.js
|
|
29442
|
-
import { writeFileSync as
|
|
29445
|
+
import { writeFileSync as writeFileSync5, appendFileSync } from "node:fs";
|
|
29443
29446
|
var transformOutputSync = ({ fileDescriptors, syncResult: { output }, options: options3, isMaxBuffer, verboseInfo }) => {
|
|
29444
29447
|
if (output === null) {
|
|
29445
29448
|
return { output: Array.from({ length: 3 }) };
|
|
@@ -29532,7 +29535,7 @@ var transformOutputSync = ({ fileDescriptors, syncResult: { output }, options: o
|
|
|
29532
29535
|
appendFileSync(path9, serializedResult);
|
|
29533
29536
|
} else {
|
|
29534
29537
|
outputFiles.add(pathString);
|
|
29535
|
-
|
|
29538
|
+
writeFileSync5(path9, serializedResult);
|
|
29536
29539
|
}
|
|
29537
29540
|
}
|
|
29538
29541
|
};
|
|
@@ -29629,7 +29632,7 @@ var init_exit_sync = __esm(() => {
|
|
|
29629
29632
|
});
|
|
29630
29633
|
|
|
29631
29634
|
// ../../node_modules/execa/lib/methods/main-sync.js
|
|
29632
|
-
import { spawnSync } from "node:child_process";
|
|
29635
|
+
import { spawnSync as spawnSync2 } from "node:child_process";
|
|
29633
29636
|
var execaCoreSync = (rawFile, rawArguments, rawOptions) => {
|
|
29634
29637
|
const { file, commandArguments, command, escapedCommand, startTime, verboseInfo, options: options3, fileDescriptors } = handleSyncArguments(rawFile, rawArguments, rawOptions);
|
|
29635
29638
|
const result = spawnSubprocessSync({
|
|
@@ -29714,7 +29717,7 @@ var execaCoreSync = (rawFile, rawArguments, rawOptions) => {
|
|
|
29714
29717
|
try {
|
|
29715
29718
|
addInputOptionsSync(fileDescriptors, options3);
|
|
29716
29719
|
const normalizedOptions = normalizeSpawnSyncOptions(options3);
|
|
29717
|
-
return
|
|
29720
|
+
return spawnSync2(...concatenateShell(file, commandArguments, normalizedOptions));
|
|
29718
29721
|
} catch (error2) {
|
|
29719
29722
|
return makeEarlyError({
|
|
29720
29723
|
error: error2,
|
|
@@ -32321,7 +32324,7 @@ var {
|
|
|
32321
32324
|
// package.json
|
|
32322
32325
|
var package_default = {
|
|
32323
32326
|
name: "@secondlayer/cli",
|
|
32324
|
-
version: "5.
|
|
32327
|
+
version: "5.10.0",
|
|
32325
32328
|
repository: {
|
|
32326
32329
|
type: "git",
|
|
32327
32330
|
url: "git+https://github.com/ryanwaits/secondlayer.git",
|
|
@@ -32370,13 +32373,14 @@ var package_default = {
|
|
|
32370
32373
|
dependencies: {
|
|
32371
32374
|
"@inquirer/prompts": "^8.2.0",
|
|
32372
32375
|
"@secondlayer/bundler": "^0.3.7",
|
|
32373
|
-
"@secondlayer/sdk": "^5.
|
|
32374
|
-
"@secondlayer/shared": "^6.
|
|
32376
|
+
"@secondlayer/sdk": "^5.7.0",
|
|
32377
|
+
"@secondlayer/shared": "^6.10.0",
|
|
32375
32378
|
"@secondlayer/stacks": "^2.3.0",
|
|
32376
32379
|
"@secondlayer/subgraphs": "^3.4.0",
|
|
32377
32380
|
"@biomejs/js-api": "^0.7.0",
|
|
32378
32381
|
"@biomejs/wasm-nodejs": "^1.9.0",
|
|
32379
32382
|
esbuild: "^0.19.0",
|
|
32383
|
+
"smol-toml": "^1.6.1",
|
|
32380
32384
|
zod: "^4.3.6"
|
|
32381
32385
|
},
|
|
32382
32386
|
devDependencies: {
|
|
@@ -34429,16 +34433,438 @@ async function resyncDatabase(skipConfirm, backfill) {
|
|
|
34429
34433
|
process.exit(1);
|
|
34430
34434
|
}
|
|
34431
34435
|
}
|
|
34436
|
+
// src/commands/devnet.ts
|
|
34437
|
+
import { spawnSync } from "node:child_process";
|
|
34438
|
+
import { existsSync as existsSync3, mkdirSync as mkdirSync2, writeFileSync as writeFileSync3 } from "node:fs";
|
|
34439
|
+
import { dirname as dirname4, join as join7 } from "node:path";
|
|
34440
|
+
|
|
34441
|
+
// src/lib/devnet-compose.ts
|
|
34442
|
+
var DEFAULT_IMAGE_OWNER = "ryanwaits";
|
|
34443
|
+
var DEFAULT_IMAGE_TAG = "latest";
|
|
34444
|
+
function buildDevnetCompose(opts = {}) {
|
|
34445
|
+
const owner = opts.owner ?? DEFAULT_IMAGE_OWNER;
|
|
34446
|
+
const tag = opts.imageTag ?? DEFAULT_IMAGE_TAG;
|
|
34447
|
+
const apiPort = opts.apiPort ?? 3800;
|
|
34448
|
+
const indexerPort = opts.indexerPort ?? 3700;
|
|
34449
|
+
const apiImage = `ghcr.io/${owner}/secondlayer-api:${tag}`;
|
|
34450
|
+
const indexerImage = `ghcr.io/${owner}/secondlayer-indexer:${tag}`;
|
|
34451
|
+
const dbUrl = "postgres://secondlayer:secondlayer@postgres:5432/secondlayer";
|
|
34452
|
+
return `# Generated by \`sl devnet connect\` — do not edit by hand.
|
|
34453
|
+
# Secondlayer app services for local clarinet devnet development.
|
|
34454
|
+
name: secondlayer-devnet
|
|
34455
|
+
|
|
34456
|
+
services:
|
|
34457
|
+
postgres:
|
|
34458
|
+
image: postgres:17-alpine
|
|
34459
|
+
environment:
|
|
34460
|
+
POSTGRES_USER: secondlayer
|
|
34461
|
+
POSTGRES_PASSWORD: secondlayer
|
|
34462
|
+
POSTGRES_DB: secondlayer
|
|
34463
|
+
volumes:
|
|
34464
|
+
- postgres_data:/var/lib/postgresql/data
|
|
34465
|
+
healthcheck:
|
|
34466
|
+
test: ["CMD-SHELL", "pg_isready -U secondlayer"]
|
|
34467
|
+
interval: 5s
|
|
34468
|
+
timeout: 5s
|
|
34469
|
+
retries: 10
|
|
34470
|
+
restart: unless-stopped
|
|
34471
|
+
|
|
34472
|
+
migrate:
|
|
34473
|
+
image: ${apiImage}
|
|
34474
|
+
command: ["bun", "run", "packages/shared/src/db/migrate.ts"]
|
|
34475
|
+
environment:
|
|
34476
|
+
DATABASE_URL: ${dbUrl}
|
|
34477
|
+
depends_on:
|
|
34478
|
+
postgres:
|
|
34479
|
+
condition: service_healthy
|
|
34480
|
+
restart: "no"
|
|
34481
|
+
|
|
34482
|
+
api:
|
|
34483
|
+
image: ${apiImage}
|
|
34484
|
+
environment:
|
|
34485
|
+
INSTANCE_MODE: oss
|
|
34486
|
+
DATABASE_URL: ${dbUrl}
|
|
34487
|
+
PORT: 3800
|
|
34488
|
+
NODE_ENV: production
|
|
34489
|
+
DATA_DIR: /data
|
|
34490
|
+
ports:
|
|
34491
|
+
- "${apiPort}:3800"
|
|
34492
|
+
volumes:
|
|
34493
|
+
- subgraphs_data:/data/subgraphs
|
|
34494
|
+
depends_on:
|
|
34495
|
+
migrate:
|
|
34496
|
+
condition: service_completed_successfully
|
|
34497
|
+
postgres:
|
|
34498
|
+
condition: service_healthy
|
|
34499
|
+
healthcheck:
|
|
34500
|
+
test: ["CMD", "curl", "-f", "http://localhost:3800/health"]
|
|
34501
|
+
interval: 10s
|
|
34502
|
+
timeout: 3s
|
|
34503
|
+
start_period: 10s
|
|
34504
|
+
retries: 5
|
|
34505
|
+
restart: unless-stopped
|
|
34506
|
+
|
|
34507
|
+
indexer:
|
|
34508
|
+
image: ${indexerImage}
|
|
34509
|
+
environment:
|
|
34510
|
+
DATABASE_URL: ${dbUrl}
|
|
34511
|
+
PORT: 3700
|
|
34512
|
+
NODE_ENV: production
|
|
34513
|
+
# Keep every network key aligned: the indexer writes index_progress under
|
|
34514
|
+
# STACKS_NETWORK, the subgraph processor reads it under NETWORK. If they
|
|
34515
|
+
# differ, catch-up finds no progress row and subgraphs never advance.
|
|
34516
|
+
NETWORKS: testnet
|
|
34517
|
+
STACKS_NETWORK: testnet
|
|
34518
|
+
NETWORK: testnet
|
|
34519
|
+
# Fed by the devnet node's event observer — never reach out to Hiro mainnet.
|
|
34520
|
+
AUTO_BACKFILL_ENABLED: "false"
|
|
34521
|
+
TIP_FOLLOWER_ENABLED: "false"
|
|
34522
|
+
# Bind on all interfaces so the devnet's stacks-node container can POST to
|
|
34523
|
+
# host.docker.internal:3700.
|
|
34524
|
+
ports:
|
|
34525
|
+
- "${indexerPort}:3700"
|
|
34526
|
+
extra_hosts:
|
|
34527
|
+
- "host.docker.internal:host-gateway"
|
|
34528
|
+
depends_on:
|
|
34529
|
+
migrate:
|
|
34530
|
+
condition: service_completed_successfully
|
|
34531
|
+
postgres:
|
|
34532
|
+
condition: service_healthy
|
|
34533
|
+
healthcheck:
|
|
34534
|
+
test: ["CMD", "curl", "-f", "http://localhost:3700/health"]
|
|
34535
|
+
interval: 10s
|
|
34536
|
+
timeout: 3s
|
|
34537
|
+
start_period: 10s
|
|
34538
|
+
retries: 5
|
|
34539
|
+
restart: unless-stopped
|
|
34540
|
+
|
|
34541
|
+
subgraph-processor:
|
|
34542
|
+
image: ${apiImage}
|
|
34543
|
+
command: ["bun", "run", "packages/subgraphs/src/service.ts"]
|
|
34544
|
+
environment:
|
|
34545
|
+
DATABASE_URL: ${dbUrl}
|
|
34546
|
+
NODE_ENV: production
|
|
34547
|
+
DATA_DIR: /data
|
|
34548
|
+
# Must match the indexer's network key (see indexer note) — catch-up reads
|
|
34549
|
+
# index_progress under NETWORK.
|
|
34550
|
+
NETWORK: testnet
|
|
34551
|
+
STACKS_NETWORK: testnet
|
|
34552
|
+
volumes:
|
|
34553
|
+
- subgraphs_data:/data/subgraphs
|
|
34554
|
+
depends_on:
|
|
34555
|
+
migrate:
|
|
34556
|
+
condition: service_completed_successfully
|
|
34557
|
+
postgres:
|
|
34558
|
+
condition: service_healthy
|
|
34559
|
+
healthcheck:
|
|
34560
|
+
disable: true
|
|
34561
|
+
restart: unless-stopped
|
|
34562
|
+
|
|
34563
|
+
volumes:
|
|
34564
|
+
postgres_data:
|
|
34565
|
+
subgraphs_data:
|
|
34566
|
+
`;
|
|
34567
|
+
}
|
|
34568
|
+
|
|
34569
|
+
// src/lib/devnet-config.ts
|
|
34570
|
+
import { existsSync as existsSync2, readFileSync as readFileSync2, writeFileSync as writeFileSync2 } from "node:fs";
|
|
34571
|
+
import { dirname as dirname3, join as join6, parse as parsePath } from "node:path";
|
|
34572
|
+
import { parse as parseToml } from "smol-toml";
|
|
34573
|
+
var DEFAULT_INDEXER_OBSERVER = "host.docker.internal:3700";
|
|
34574
|
+
function findClarinetProject(startDir) {
|
|
34575
|
+
let dir = startDir;
|
|
34576
|
+
const { root } = parsePath(dir);
|
|
34577
|
+
while (true) {
|
|
34578
|
+
if (existsSync2(join6(dir, "Clarinet.toml")))
|
|
34579
|
+
return dir;
|
|
34580
|
+
if (dir === root)
|
|
34581
|
+
return null;
|
|
34582
|
+
dir = dirname3(dir);
|
|
34583
|
+
}
|
|
34584
|
+
}
|
|
34585
|
+
function ensureEventObserver(devnetTomlPath, endpoint = DEFAULT_INDEXER_OBSERVER) {
|
|
34586
|
+
const exists = existsSync2(devnetTomlPath);
|
|
34587
|
+
const original = exists ? readFileSync2(devnetTomlPath, "utf8") : "";
|
|
34588
|
+
if (original.trim()) {
|
|
34589
|
+
const parsed = parseToml(original);
|
|
34590
|
+
const observers = parsed.devnet?.stacks_node_events_observers;
|
|
34591
|
+
if (Array.isArray(observers) && observers.includes(endpoint)) {
|
|
34592
|
+
return { status: "present" };
|
|
34593
|
+
}
|
|
34594
|
+
}
|
|
34595
|
+
const entry = JSON.stringify(endpoint);
|
|
34596
|
+
const arrayStart = original.match(/^[^#\n]*stacks_node_events_observers\s*=\s*\[/m);
|
|
34597
|
+
if (arrayStart) {
|
|
34598
|
+
const at = (arrayStart.index ?? 0) + arrayStart[0].length;
|
|
34599
|
+
const next = original.slice(at).trimStart().startsWith("]") ? entry : `${entry}, `;
|
|
34600
|
+
const patched = original.slice(0, at) + next + original.slice(at);
|
|
34601
|
+
writeFileSync2(devnetTomlPath, patched);
|
|
34602
|
+
return { status: "added" };
|
|
34603
|
+
}
|
|
34604
|
+
const header = original.match(/^\[devnet\]\s*$/m);
|
|
34605
|
+
if (header) {
|
|
34606
|
+
const at = (header.index ?? 0) + header[0].length;
|
|
34607
|
+
const patched = `${original.slice(0, at)}
|
|
34608
|
+
stacks_node_events_observers = [${entry}]${original.slice(at)}`;
|
|
34609
|
+
writeFileSync2(devnetTomlPath, patched);
|
|
34610
|
+
return { status: "added" };
|
|
34611
|
+
}
|
|
34612
|
+
const prefix = original && !original.endsWith(`
|
|
34613
|
+
`) ? `${original}
|
|
34614
|
+
` : original;
|
|
34615
|
+
const block = `${prefix}${original.trim() ? `
|
|
34616
|
+
` : ""}[devnet]
|
|
34617
|
+
stacks_node_events_observers = [${entry}]
|
|
34618
|
+
`;
|
|
34619
|
+
writeFileSync2(devnetTomlPath, block);
|
|
34620
|
+
return { status: exists ? "added" : "created" };
|
|
34621
|
+
}
|
|
34622
|
+
|
|
34623
|
+
// src/commands/devnet.ts
|
|
34624
|
+
init_output();
|
|
34625
|
+
var COMPOSE_REL = join7(".secondlayer", "docker-compose.yml");
|
|
34626
|
+
function ensureDocker() {
|
|
34627
|
+
const probe = spawnSync("docker", ["info"], { stdio: "ignore" });
|
|
34628
|
+
if (probe.error || probe.status !== 0) {
|
|
34629
|
+
error(`Docker isn't available.
|
|
34630
|
+
|
|
34631
|
+
` + `Start Docker Desktop or OrbStack (macOS), or install Docker:
|
|
34632
|
+
` + ` macOS: brew install --cask docker (or https://orbstack.dev)
|
|
34633
|
+
` + " Linux: curl -fsSL https://get.docker.com | sh");
|
|
34634
|
+
process.exit(1);
|
|
34635
|
+
}
|
|
34636
|
+
}
|
|
34637
|
+
function dockerCompose(composePath, args) {
|
|
34638
|
+
const res = spawnSync("docker", ["compose", "-f", composePath, ...args], {
|
|
34639
|
+
stdio: "inherit"
|
|
34640
|
+
});
|
|
34641
|
+
return res.status ?? 1;
|
|
34642
|
+
}
|
|
34643
|
+
var API_URL = process.env.SL_API_URL ?? "http://localhost:3800";
|
|
34644
|
+
var INDEXER_URL = process.env.INDEXER_URL ?? "http://localhost:3700";
|
|
34645
|
+
var SERVICES = [
|
|
34646
|
+
"indexer",
|
|
34647
|
+
"api",
|
|
34648
|
+
"subgraph-processor",
|
|
34649
|
+
"postgres",
|
|
34650
|
+
"migrate"
|
|
34651
|
+
];
|
|
34652
|
+
function registerDevnetCommand(program2) {
|
|
34653
|
+
const devnet = program2.command("devnet").description("Run Secondlayer services against a local Clarinet devnet");
|
|
34654
|
+
devnet.command("connect").description("Point your clarinet project's devnet at a local Secondlayer stack and start it").option("--project <dir>", "Clarinet project directory (defaults to the nearest Clarinet.toml)").option("--image-tag <tag>", "Published image tag to run", DEFAULT_IMAGE_TAG).option("--owner <owner>", "ghcr image owner (namespace) to pull from").option("--no-up", "Patch config + write compose without starting docker").action(async (options) => {
|
|
34655
|
+
await connect(options);
|
|
34656
|
+
});
|
|
34657
|
+
devnet.command("down").description("Stop the local Secondlayer stack started by `sl devnet connect`").option("--project <dir>", "Clarinet project directory").option("--purge", "Also remove volumes (wipes the local index)").action(async (options) => {
|
|
34658
|
+
await down(options);
|
|
34659
|
+
});
|
|
34660
|
+
devnet.command("status").description("Snapshot of the local stack: ingest, subgraphs, and recent activity").option("-w, --watch", "Refresh every 2s until Ctrl-C").option("-n, --limit <n>", "Recent activity rows to show", "12").action(async (options) => {
|
|
34661
|
+
await status(options);
|
|
34662
|
+
});
|
|
34663
|
+
devnet.command("logs [service]").description("Tail stack logs — all services, or one of: indexer, api, subgraph-processor, postgres").option("--project <dir>", "Clarinet project directory").option("-f, --follow", "Follow log output").option("-n, --tail <n>", "Lines to show from the end of each log", "200").action(async (service, options) => {
|
|
34664
|
+
await logs(service, options);
|
|
34665
|
+
});
|
|
34666
|
+
}
|
|
34667
|
+
function resolveProject(explicit) {
|
|
34668
|
+
if (explicit) {
|
|
34669
|
+
if (!existsSync3(join7(explicit, "Clarinet.toml"))) {
|
|
34670
|
+
error(`No Clarinet.toml in ${explicit}`);
|
|
34671
|
+
process.exit(1);
|
|
34672
|
+
}
|
|
34673
|
+
return explicit;
|
|
34674
|
+
}
|
|
34675
|
+
const found = findClarinetProject(process.cwd());
|
|
34676
|
+
if (!found) {
|
|
34677
|
+
error(`No Clarinet.toml found in this directory or any parent.
|
|
34678
|
+
` + "Run this from inside a clarinet project, or pass --project <dir>.");
|
|
34679
|
+
process.exit(1);
|
|
34680
|
+
}
|
|
34681
|
+
return found;
|
|
34682
|
+
}
|
|
34683
|
+
async function connect(options) {
|
|
34684
|
+
const project = resolveProject(options.project);
|
|
34685
|
+
const devnetToml = join7(project, "settings", "Devnet.toml");
|
|
34686
|
+
mkdirSync2(dirname4(devnetToml), { recursive: true });
|
|
34687
|
+
const result = ensureEventObserver(devnetToml, DEFAULT_INDEXER_OBSERVER);
|
|
34688
|
+
console.log(`${green("✓")} found Clarinet.toml`);
|
|
34689
|
+
if (result.status === "present") {
|
|
34690
|
+
console.log(dim(` settings/Devnet.toml already forwards to ${DEFAULT_INDEXER_OBSERVER}`));
|
|
34691
|
+
} else {
|
|
34692
|
+
console.log(`${green("✓")} ${result.status === "created" ? "created" : "patched"} settings/Devnet.toml`);
|
|
34693
|
+
console.log(dim(` + stacks_node_events_observers = ["${DEFAULT_INDEXER_OBSERVER}"]`));
|
|
34694
|
+
}
|
|
34695
|
+
const composePath = join7(project, COMPOSE_REL);
|
|
34696
|
+
mkdirSync2(dirname4(composePath), { recursive: true });
|
|
34697
|
+
writeFileSync3(composePath, buildDevnetCompose({ owner: options.owner, imageTag: options.imageTag }));
|
|
34698
|
+
console.log(`${green("✓")} wrote ${COMPOSE_REL}`);
|
|
34699
|
+
if (!options.up) {
|
|
34700
|
+
console.log(dim(`
|
|
34701
|
+
Skipped docker. Start it with:
|
|
34702
|
+
docker compose -f ${COMPOSE_REL} up -d`));
|
|
34703
|
+
return;
|
|
34704
|
+
}
|
|
34705
|
+
ensureDocker();
|
|
34706
|
+
console.log(dim(`
|
|
34707
|
+
Starting Secondlayer stack (docker compose up -d)…`));
|
|
34708
|
+
if (dockerCompose(composePath, ["up", "-d"]) !== 0) {
|
|
34709
|
+
error("docker compose up failed — see output above.");
|
|
34710
|
+
process.exit(1);
|
|
34711
|
+
}
|
|
34712
|
+
console.log(`
|
|
34713
|
+
${bold("Secondlayer stack up")}`);
|
|
34714
|
+
console.log(` api → ${cyan("http://localhost:3800")}`);
|
|
34715
|
+
console.log(` indexer → ${cyan("http://localhost:3700")}`);
|
|
34716
|
+
console.log(`
|
|
34717
|
+
${bold("Next:")}`);
|
|
34718
|
+
console.log(` ${yellow("clarinet devnet start")} ${dim("# auto-deploys + streams to the indexer")}`);
|
|
34719
|
+
console.log(` ${yellow("SL_API_URL=http://localhost:3800 SL_SERVICE_KEY=dummy sl subgraphs deploy ./subgraph.ts")}`);
|
|
34720
|
+
console.log(dim(`
|
|
34721
|
+
Stop with: sl devnet down`));
|
|
34722
|
+
}
|
|
34723
|
+
async function down(options) {
|
|
34724
|
+
const project = resolveProject(options.project);
|
|
34725
|
+
const composePath = join7(project, COMPOSE_REL);
|
|
34726
|
+
if (!existsSync3(composePath)) {
|
|
34727
|
+
error(`No ${COMPOSE_REL} in ${project} — nothing to stop. Run \`sl devnet connect\` first.`);
|
|
34728
|
+
process.exit(1);
|
|
34729
|
+
}
|
|
34730
|
+
ensureDocker();
|
|
34731
|
+
const args = options.purge ? ["down", "-v"] : ["down"];
|
|
34732
|
+
if (dockerCompose(composePath, args) !== 0) {
|
|
34733
|
+
error("docker compose down failed — see output above.");
|
|
34734
|
+
process.exit(1);
|
|
34735
|
+
}
|
|
34736
|
+
console.log(`${green("✓")}${options.purge ? " stack stopped, volumes removed" : " stack stopped"}`);
|
|
34737
|
+
}
|
|
34738
|
+
async function logs(service, options) {
|
|
34739
|
+
const project = resolveProject(options.project);
|
|
34740
|
+
const composePath = join7(project, COMPOSE_REL);
|
|
34741
|
+
if (!existsSync3(composePath)) {
|
|
34742
|
+
error(`No ${COMPOSE_REL} in ${project} — run \`sl devnet connect\` first.`);
|
|
34743
|
+
process.exit(1);
|
|
34744
|
+
}
|
|
34745
|
+
if (service && !SERVICES.includes(service)) {
|
|
34746
|
+
error(`Unknown service "${service}". Choose one of: ${SERVICES.join(", ")}`);
|
|
34747
|
+
process.exit(1);
|
|
34748
|
+
}
|
|
34749
|
+
ensureDocker();
|
|
34750
|
+
const args = ["logs", "--tail", options.tail];
|
|
34751
|
+
if (options.follow)
|
|
34752
|
+
args.push("-f");
|
|
34753
|
+
if (service)
|
|
34754
|
+
args.push(service);
|
|
34755
|
+
process.exit(dockerCompose(composePath, args));
|
|
34756
|
+
}
|
|
34757
|
+
async function jget(url) {
|
|
34758
|
+
try {
|
|
34759
|
+
const r = await fetch(url, { signal: AbortSignal.timeout(1500) });
|
|
34760
|
+
return r.ok ? await r.json() : null;
|
|
34761
|
+
} catch {
|
|
34762
|
+
return null;
|
|
34763
|
+
}
|
|
34764
|
+
}
|
|
34765
|
+
var SYS_COLS = new Set([
|
|
34766
|
+
"_id",
|
|
34767
|
+
"_block_height",
|
|
34768
|
+
"_tx_id",
|
|
34769
|
+
"_created_at",
|
|
34770
|
+
"block_height",
|
|
34771
|
+
"tx_id"
|
|
34772
|
+
]);
|
|
34773
|
+
function shortVal(v) {
|
|
34774
|
+
const s = String(v);
|
|
34775
|
+
return s.length > 18 ? `${s.slice(0, 6)}…${s.slice(-4)}` : s;
|
|
34776
|
+
}
|
|
34777
|
+
async function renderStatus(limit) {
|
|
34778
|
+
const [health, integrity, subsRes, apiHealth] = await Promise.all([
|
|
34779
|
+
jget(`${INDEXER_URL}/health`),
|
|
34780
|
+
jget(`${INDEXER_URL}/health/integrity`),
|
|
34781
|
+
jget(`${API_URL}/api/subgraphs`),
|
|
34782
|
+
jget(`${API_URL}/health`)
|
|
34783
|
+
]);
|
|
34784
|
+
const out = [];
|
|
34785
|
+
out.push(bold("STACK"));
|
|
34786
|
+
out.push(` ${health ? green("●") : red("●")} indexer ${health ? "healthy" : "down"} ${dim(":3700")}`);
|
|
34787
|
+
out.push(` ${apiHealth ? green("●") : red("●")} api ${apiHealth ? "healthy" : "down"} ${dim(":3800")}`);
|
|
34788
|
+
if (!health) {
|
|
34789
|
+
out.push("");
|
|
34790
|
+
out.push(dim(" indexer unreachable — is `sl devnet connect` running?"));
|
|
34791
|
+
return out.join(`
|
|
34792
|
+
`);
|
|
34793
|
+
}
|
|
34794
|
+
const tip = Number(health.lastSeenHeight ?? integrity?.lastIndexedBlock ?? 0);
|
|
34795
|
+
const indexed = Number(integrity?.lastIndexedBlock ?? tip);
|
|
34796
|
+
const lag = Math.max(0, tip - indexed);
|
|
34797
|
+
const ago = health.lastBlockReceivedSecondsAgo;
|
|
34798
|
+
out.push("");
|
|
34799
|
+
out.push(bold("INGEST"));
|
|
34800
|
+
out.push(` chain tip ${cyan(String(tip))} indexed ${indexed} lag ${lag === 0 ? green("caught up") : yellow(`${lag} blk`)} ${dim(`last block ${ago != null ? `${ago}s ago` : "?"}`)}`);
|
|
34801
|
+
const subs = subsRes?.data ?? [];
|
|
34802
|
+
out.push("");
|
|
34803
|
+
out.push(bold("SUBGRAPHS"));
|
|
34804
|
+
if (subs.length === 0) {
|
|
34805
|
+
out.push(dim(" none deployed — sl subgraphs deploy ./subgraph.ts"));
|
|
34806
|
+
} else {
|
|
34807
|
+
for (const sg of subs) {
|
|
34808
|
+
const st = sg.status === "active" ? green(sg.status) : yellow(String(sg.status));
|
|
34809
|
+
const tables = (sg.tables ?? []).join(", ");
|
|
34810
|
+
out.push(` ${sg.name} ${st} ${dim(`block ${sg.lastProcessedBlock}`)} ${tables} ${dim(`· ${sg.totalRows ?? 0} rows`)}`);
|
|
34811
|
+
}
|
|
34812
|
+
}
|
|
34813
|
+
out.push("");
|
|
34814
|
+
out.push(bold("ACTIVITY") + dim(" (recent)"));
|
|
34815
|
+
const rows = [];
|
|
34816
|
+
for (const sg of subs) {
|
|
34817
|
+
for (const table of sg.tables ?? []) {
|
|
34818
|
+
const res = await jget(`${API_URL}/api/subgraphs/${sg.name}/${table}?_limit=${limit}&_sort=_block_height&_order=desc`);
|
|
34819
|
+
for (const row of res?.data ?? []) {
|
|
34820
|
+
const summary = Object.entries(row).filter(([k]) => !SYS_COLS.has(k)).map(([, v]) => shortVal(v)).join(" ");
|
|
34821
|
+
rows.push({ block: Number(row._block_height ?? 0), table, summary });
|
|
34822
|
+
}
|
|
34823
|
+
}
|
|
34824
|
+
}
|
|
34825
|
+
rows.sort((a, b2) => b2.block - a.block);
|
|
34826
|
+
if (rows.length === 0) {
|
|
34827
|
+
out.push(dim(" no indexed rows yet — fire a contract call"));
|
|
34828
|
+
} else {
|
|
34829
|
+
for (const r of rows.slice(0, limit)) {
|
|
34830
|
+
out.push(` ${dim(String(r.block).padStart(5))} ${r.table.padEnd(16)} ${r.summary}`);
|
|
34831
|
+
}
|
|
34832
|
+
}
|
|
34833
|
+
return out.join(`
|
|
34834
|
+
`);
|
|
34835
|
+
}
|
|
34836
|
+
async function status(options) {
|
|
34837
|
+
const limit = Math.max(1, Number(options.limit) || 12);
|
|
34838
|
+
if (!options.watch) {
|
|
34839
|
+
console.log(await renderStatus(limit));
|
|
34840
|
+
return;
|
|
34841
|
+
}
|
|
34842
|
+
const tick = async () => {
|
|
34843
|
+
const body = await renderStatus(limit);
|
|
34844
|
+
process.stdout.write("\x1B[2J\x1B[H");
|
|
34845
|
+
console.log(`${dim("sl devnet status")} ${dim("· ctrl-c to stop")}
|
|
34846
|
+
`);
|
|
34847
|
+
console.log(body);
|
|
34848
|
+
};
|
|
34849
|
+
await tick();
|
|
34850
|
+
const id = setInterval(() => void tick(), 2000);
|
|
34851
|
+
process.on("SIGINT", () => {
|
|
34852
|
+
clearInterval(id);
|
|
34853
|
+
process.stdout.write(`
|
|
34854
|
+
`);
|
|
34855
|
+
process.exit(0);
|
|
34856
|
+
});
|
|
34857
|
+
}
|
|
34432
34858
|
// src/commands/subgraphs.ts
|
|
34433
34859
|
import { spawn } from "node:child_process";
|
|
34434
34860
|
import {
|
|
34435
|
-
existsSync as
|
|
34436
|
-
mkdirSync as
|
|
34437
|
-
readFileSync as
|
|
34861
|
+
existsSync as existsSync4,
|
|
34862
|
+
mkdirSync as mkdirSync3,
|
|
34863
|
+
readFileSync as readFileSync3,
|
|
34438
34864
|
watch,
|
|
34439
|
-
writeFileSync as
|
|
34865
|
+
writeFileSync as writeFileSync4
|
|
34440
34866
|
} from "node:fs";
|
|
34441
|
-
import { dirname as
|
|
34867
|
+
import { dirname as dirname5, join as join8, resolve as resolve2 } from "node:path";
|
|
34442
34868
|
import { fileURLToPath as fileURLToPath2 } from "node:url";
|
|
34443
34869
|
import { confirm as confirm4 } from "@inquirer/prompts";
|
|
34444
34870
|
|
|
@@ -35249,8 +35675,8 @@ async function writeOrPrintSubgraphSpec(spec, format, output) {
|
|
|
35249
35675
|
}
|
|
35250
35676
|
const outPath = resolve2(output);
|
|
35251
35677
|
const dir = resolve2(outPath, "..");
|
|
35252
|
-
if (!
|
|
35253
|
-
|
|
35678
|
+
if (!existsSync4(dir))
|
|
35679
|
+
mkdirSync3(dir, { recursive: true });
|
|
35254
35680
|
await writeTextFile(outPath, text);
|
|
35255
35681
|
success(`Created ${outPath}`);
|
|
35256
35682
|
}
|
|
@@ -35312,15 +35738,15 @@ function createLocalSubgraphDetail(input3) {
|
|
|
35312
35738
|
};
|
|
35313
35739
|
}
|
|
35314
35740
|
function readCliSubgraphsDependency() {
|
|
35315
|
-
const here =
|
|
35741
|
+
const here = dirname5(fileURLToPath2(import.meta.url));
|
|
35316
35742
|
const candidates = [
|
|
35317
35743
|
resolve2(here, "..", "..", "package.json"),
|
|
35318
35744
|
resolve2(here, "..", "package.json")
|
|
35319
35745
|
];
|
|
35320
35746
|
for (const candidate of candidates) {
|
|
35321
|
-
if (!
|
|
35747
|
+
if (!existsSync4(candidate))
|
|
35322
35748
|
continue;
|
|
35323
|
-
const pkg = JSON.parse(
|
|
35749
|
+
const pkg = JSON.parse(readFileSync3(candidate, "utf8"));
|
|
35324
35750
|
const dep = pkg.dependencies?.["@secondlayer/subgraphs"];
|
|
35325
35751
|
if (dep)
|
|
35326
35752
|
return dep;
|
|
@@ -35328,10 +35754,10 @@ function readCliSubgraphsDependency() {
|
|
|
35328
35754
|
return "^1.3.2";
|
|
35329
35755
|
}
|
|
35330
35756
|
function ensureScaffoldPackageJson(dir) {
|
|
35331
|
-
const packagePath =
|
|
35757
|
+
const packagePath = join8(dir, "package.json");
|
|
35332
35758
|
const subgraphsDep = readCliSubgraphsDependency();
|
|
35333
|
-
if (!
|
|
35334
|
-
|
|
35759
|
+
if (!existsSync4(packagePath)) {
|
|
35760
|
+
writeFileSync4(packagePath, `${JSON.stringify({
|
|
35335
35761
|
type: "module",
|
|
35336
35762
|
dependencies: {
|
|
35337
35763
|
"@secondlayer/subgraphs": subgraphsDep
|
|
@@ -35340,14 +35766,14 @@ function ensureScaffoldPackageJson(dir) {
|
|
|
35340
35766
|
`, "utf8");
|
|
35341
35767
|
return;
|
|
35342
35768
|
}
|
|
35343
|
-
const pkg = JSON.parse(
|
|
35769
|
+
const pkg = JSON.parse(readFileSync3(packagePath, "utf8"));
|
|
35344
35770
|
if (pkg.dependencies?.["@secondlayer/subgraphs"])
|
|
35345
35771
|
return;
|
|
35346
35772
|
pkg.dependencies = {
|
|
35347
35773
|
...pkg.dependencies ?? {},
|
|
35348
35774
|
"@secondlayer/subgraphs": subgraphsDep
|
|
35349
35775
|
};
|
|
35350
|
-
|
|
35776
|
+
writeFileSync4(packagePath, `${JSON.stringify(pkg, null, 2)}
|
|
35351
35777
|
`, "utf8");
|
|
35352
35778
|
}
|
|
35353
35779
|
async function runBunInstall(dir) {
|
|
@@ -35456,12 +35882,12 @@ ${SUBGRAPH_TEMPLATE_SLUGS.map((s) => ` ${s.padEnd(20)} ${SUBGRAPH_TEMPLATE_DESC
|
|
|
35456
35882
|
}
|
|
35457
35883
|
const dir = resolve2("subgraphs");
|
|
35458
35884
|
const filePath = resolve2(dir, `${name}.ts`);
|
|
35459
|
-
if (
|
|
35885
|
+
if (existsSync4(filePath)) {
|
|
35460
35886
|
error(`File already exists: ${filePath}`);
|
|
35461
35887
|
process.exit(1);
|
|
35462
35888
|
}
|
|
35463
|
-
if (!
|
|
35464
|
-
|
|
35889
|
+
if (!existsSync4(dir)) {
|
|
35890
|
+
mkdirSync3(dir, { recursive: true });
|
|
35465
35891
|
}
|
|
35466
35892
|
const content = generateSubgraphTemplate(name, slug);
|
|
35467
35893
|
await writeTextFile(filePath, content);
|
|
@@ -35474,7 +35900,7 @@ ${SUBGRAPH_TEMPLATE_SLUGS.map((s) => ` ${s.padEnd(20)} ${SUBGRAPH_TEMPLATE_DESC
|
|
|
35474
35900
|
subgraphs.command("dev <file>").description("Watch a subgraph file and auto-redeploy on change").action(async (file) => {
|
|
35475
35901
|
await requireLocalNetwork();
|
|
35476
35902
|
const absPath = resolve2(file);
|
|
35477
|
-
if (!
|
|
35903
|
+
if (!existsSync4(absPath)) {
|
|
35478
35904
|
error(`File not found: ${absPath}`);
|
|
35479
35905
|
process.exit(1);
|
|
35480
35906
|
}
|
|
@@ -35791,7 +36217,7 @@ Synced — exiting watch.`));
|
|
|
35791
36217
|
try {
|
|
35792
36218
|
const format = parseSubgraphSpecFormat(options2.format);
|
|
35793
36219
|
const absPath = resolve2(file);
|
|
35794
|
-
if (!
|
|
36220
|
+
if (!existsSync4(absPath)) {
|
|
35795
36221
|
error(`File not found: ${absPath}`);
|
|
35796
36222
|
process.exit(1);
|
|
35797
36223
|
}
|
|
@@ -35841,7 +36267,7 @@ Synced — exiting watch.`));
|
|
|
35841
36267
|
process.exit(1);
|
|
35842
36268
|
}
|
|
35843
36269
|
const absPath = resolve2(file);
|
|
35844
|
-
if (!
|
|
36270
|
+
if (!existsSync4(absPath)) {
|
|
35845
36271
|
error(`File not found: ${absPath}`);
|
|
35846
36272
|
process.exit(1);
|
|
35847
36273
|
}
|
|
@@ -36057,8 +36483,8 @@ ${rows.length} row(s)`));
|
|
|
36057
36483
|
success(result.message);
|
|
36058
36484
|
} catch (delErr) {
|
|
36059
36485
|
const msg = delErr instanceof Error ? delErr.message : String(delErr);
|
|
36060
|
-
const
|
|
36061
|
-
if (
|
|
36486
|
+
const status2 = delErr?.status;
|
|
36487
|
+
if (status2 === 404 || /not found/i.test(msg)) {
|
|
36062
36488
|
info(`Subgraph "${name}" not found (already deleted?)`);
|
|
36063
36489
|
return;
|
|
36064
36490
|
}
|
|
@@ -36104,8 +36530,8 @@ ${rows.length} row(s)`));
|
|
|
36104
36530
|
});
|
|
36105
36531
|
}
|
|
36106
36532
|
const dir = resolve2(outPath, "..");
|
|
36107
|
-
if (!
|
|
36108
|
-
|
|
36533
|
+
if (!existsSync4(dir))
|
|
36534
|
+
mkdirSync3(dir, { recursive: true });
|
|
36109
36535
|
await writeTextFile(outPath, content);
|
|
36110
36536
|
ensureScaffoldPackageJson(dir);
|
|
36111
36537
|
success(`Created ${outPath}`);
|
|
@@ -36139,8 +36565,8 @@ ${rows.length} row(s)`));
|
|
|
36139
36565
|
info("Generating typed client...");
|
|
36140
36566
|
const content = await generateSubgraphConsumer(subgraphName, subgraphDetail);
|
|
36141
36567
|
const dir = resolve2(outPath, "..");
|
|
36142
|
-
if (!
|
|
36143
|
-
|
|
36568
|
+
if (!existsSync4(dir))
|
|
36569
|
+
mkdirSync3(dir, { recursive: true });
|
|
36144
36570
|
await writeTextFile(outPath, content);
|
|
36145
36571
|
success(`Created ${outPath}`);
|
|
36146
36572
|
} catch (err) {
|
|
@@ -36588,15 +37014,15 @@ async function checkHealth() {
|
|
|
36588
37014
|
try {
|
|
36589
37015
|
const c = JSON.parse(line);
|
|
36590
37016
|
const name = c.Names || c.Name;
|
|
36591
|
-
const
|
|
37017
|
+
const status2 = c.Status || "unknown";
|
|
36592
37018
|
let health = "unknown";
|
|
36593
|
-
if (
|
|
37019
|
+
if (status2.includes("healthy"))
|
|
36594
37020
|
health = "healthy";
|
|
36595
|
-
else if (
|
|
37021
|
+
else if (status2.includes("unhealthy"))
|
|
36596
37022
|
health = "unhealthy";
|
|
36597
|
-
else if (
|
|
37023
|
+
else if (status2.includes("Up"))
|
|
36598
37024
|
health = "running";
|
|
36599
|
-
else if (
|
|
37025
|
+
else if (status2.includes("Exited"))
|
|
36600
37026
|
health = "exited";
|
|
36601
37027
|
let restartCount = 0;
|
|
36602
37028
|
try {
|
|
@@ -36605,7 +37031,7 @@ async function checkHealth() {
|
|
|
36605
37031
|
restartCount = Number.parseInt(inspect2.stdout.toString().trim()) || 0;
|
|
36606
37032
|
}
|
|
36607
37033
|
} catch {}
|
|
36608
|
-
containers.push({ name, status, health, restartCount });
|
|
37034
|
+
containers.push({ name, status: status2, health, restartCount });
|
|
36609
37035
|
if (health === "unhealthy") {
|
|
36610
37036
|
issues.push(`Container ${name} is unhealthy`);
|
|
36611
37037
|
}
|
|
@@ -37019,13 +37445,13 @@ async function showNodeLogs(options2) {
|
|
|
37019
37445
|
console.log(dim("Run 'sl local node start' first"));
|
|
37020
37446
|
process.exit(1);
|
|
37021
37447
|
}
|
|
37022
|
-
const
|
|
37448
|
+
const logs2 = await getNodeLogs({
|
|
37023
37449
|
follow: options2.follow,
|
|
37024
37450
|
lines: Number.parseInt(options2.lines),
|
|
37025
37451
|
quiet: options2.quiet,
|
|
37026
37452
|
format: true
|
|
37027
37453
|
});
|
|
37028
|
-
for await (const line of
|
|
37454
|
+
for await (const line of logs2) {
|
|
37029
37455
|
console.log(line);
|
|
37030
37456
|
}
|
|
37031
37457
|
}
|
|
@@ -37051,8 +37477,8 @@ async function showStaticCombinedLogs(showDev, showNode, lines, quiet) {
|
|
|
37051
37477
|
}
|
|
37052
37478
|
}
|
|
37053
37479
|
if (showNode && await isNodeRunning()) {
|
|
37054
|
-
const
|
|
37055
|
-
for await (const line of
|
|
37480
|
+
const logs2 = await getNodeLogs({ lines, quiet, format: true });
|
|
37481
|
+
for await (const line of logs2) {
|
|
37056
37482
|
const tsMatch = line.match(/\[(\d{4}-\d{2}-\d{2}T[\d:.]+Z)\]/);
|
|
37057
37483
|
const timestamp = tsMatch ? new Date(tsMatch[1]) : new Date(0);
|
|
37058
37484
|
allLines.push({ service: "node", line, timestamp });
|
|
@@ -37152,10 +37578,10 @@ init_config();
|
|
|
37152
37578
|
init_output();
|
|
37153
37579
|
|
|
37154
37580
|
// src/lib/project-file.ts
|
|
37155
|
-
import { existsSync as
|
|
37581
|
+
import { existsSync as existsSync5 } from "node:fs";
|
|
37156
37582
|
import { mkdir as mkdir3, readFile as readFile3, writeFile as writeFile3 } from "node:fs/promises";
|
|
37157
37583
|
import { homedir as homedir5 } from "node:os";
|
|
37158
|
-
import { dirname as
|
|
37584
|
+
import { dirname as dirname11, join as join10, parse as parsePath2, resolve as resolve8 } from "node:path";
|
|
37159
37585
|
import { z as z3 } from "zod/v4";
|
|
37160
37586
|
var ProjectFileSchema = z3.object({
|
|
37161
37587
|
slug: z3.string().min(1)
|
|
@@ -37165,21 +37591,21 @@ var DIRNAME = ".secondlayer";
|
|
|
37165
37591
|
async function readActiveProject(cwd, globalDefault) {
|
|
37166
37592
|
let dir = resolve8(cwd);
|
|
37167
37593
|
const home = resolve8(homedir5());
|
|
37168
|
-
const fsRoot =
|
|
37594
|
+
const fsRoot = parsePath2(dir).root;
|
|
37169
37595
|
while (true) {
|
|
37170
|
-
const candidate =
|
|
37171
|
-
if (
|
|
37596
|
+
const candidate = join10(dir, DIRNAME, FILENAME);
|
|
37597
|
+
if (existsSync5(candidate)) {
|
|
37172
37598
|
try {
|
|
37173
37599
|
const raw = await readFile3(candidate, "utf8");
|
|
37174
37600
|
const parsed = ProjectFileSchema.parse(JSON.parse(raw));
|
|
37175
37601
|
return { slug: parsed.slug, resolvedFrom: candidate };
|
|
37176
37602
|
} catch {}
|
|
37177
37603
|
}
|
|
37178
|
-
if (
|
|
37604
|
+
if (existsSync5(join10(dir, ".git")))
|
|
37179
37605
|
break;
|
|
37180
37606
|
if (dir === home || dir === fsRoot)
|
|
37181
37607
|
break;
|
|
37182
|
-
const parent =
|
|
37608
|
+
const parent = dirname11(dir);
|
|
37183
37609
|
if (parent === dir)
|
|
37184
37610
|
break;
|
|
37185
37611
|
dir = parent;
|
|
@@ -37187,15 +37613,15 @@ async function readActiveProject(cwd, globalDefault) {
|
|
|
37187
37613
|
if (globalDefault) {
|
|
37188
37614
|
return {
|
|
37189
37615
|
slug: globalDefault,
|
|
37190
|
-
resolvedFrom:
|
|
37616
|
+
resolvedFrom: join10(homedir5(), ".secondlayer", "config.json")
|
|
37191
37617
|
};
|
|
37192
37618
|
}
|
|
37193
37619
|
return null;
|
|
37194
37620
|
}
|
|
37195
37621
|
async function writeActiveProject(slug, cwd) {
|
|
37196
|
-
const dir =
|
|
37622
|
+
const dir = join10(resolve8(cwd), DIRNAME);
|
|
37197
37623
|
await mkdir3(dir, { recursive: true });
|
|
37198
|
-
const file =
|
|
37624
|
+
const file = join10(dir, FILENAME);
|
|
37199
37625
|
await writeFile3(file, `${JSON.stringify({ slug }, null, 2)}
|
|
37200
37626
|
`, "utf8");
|
|
37201
37627
|
return file;
|
|
@@ -37400,9 +37826,10 @@ registerDbCommand(program);
|
|
|
37400
37826
|
registerDoctorCommand(program);
|
|
37401
37827
|
registerConfigCommand(program);
|
|
37402
37828
|
registerLocalCommand(program);
|
|
37829
|
+
registerDevnetCommand(program);
|
|
37403
37830
|
registerAccountCommand(program);
|
|
37404
37831
|
registerBillingCommand(program);
|
|
37405
37832
|
program.parse();
|
|
37406
37833
|
|
|
37407
|
-
//# debugId=
|
|
37834
|
+
//# debugId=98906583902E571F64756E2164756E21
|
|
37408
37835
|
//# sourceMappingURL=cli.js.map
|