@secondlayer/cli 3.5.3 → 3.5.4

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 CHANGED
@@ -13466,10 +13466,10 @@ var init_manager = __esm(() => {
13466
13466
  });
13467
13467
 
13468
13468
  // src/services/indexer.ts
13469
- import { dirname as dirname4, resolve as resolve4 } from "node:path";
13469
+ import { dirname as dirname5, resolve as resolve4 } from "node:path";
13470
13470
  async function startIndexer(options2) {
13471
13471
  const port = options2.port ?? 3700;
13472
- const rootDir = dirname4(dirname4(dirname4(dirname4(import.meta.dir))));
13472
+ const rootDir = dirname5(dirname5(dirname5(dirname5(import.meta.dir))));
13473
13473
  const indexerPath = resolve4(rootDir, "packages/indexer/src/index.ts");
13474
13474
  await serviceManager.start(SERVICE_NAME, ["bun", "run", "--watch", indexerPath], {
13475
13475
  port,
@@ -13486,9 +13486,9 @@ var init_indexer = __esm(() => {
13486
13486
  });
13487
13487
 
13488
13488
  // src/services/worker.ts
13489
- import { dirname as dirname5, resolve as resolve5 } from "node:path";
13489
+ import { dirname as dirname6, resolve as resolve5 } from "node:path";
13490
13490
  async function startWorker(options2) {
13491
- const rootDir = dirname5(dirname5(dirname5(dirname5(import.meta.dir))));
13491
+ const rootDir = dirname6(dirname6(dirname6(dirname6(import.meta.dir))));
13492
13492
  const workerPath = resolve5(rootDir, "packages/worker/src/index.ts");
13493
13493
  await serviceManager.start(SERVICE_NAME2, ["bun", "run", "--watch", workerPath], {
13494
13494
  onStdout: options2.onLog,
@@ -13501,10 +13501,10 @@ var init_worker = __esm(() => {
13501
13501
  });
13502
13502
 
13503
13503
  // src/services/api.ts
13504
- import { dirname as dirname6, resolve as resolve6 } from "node:path";
13504
+ import { dirname as dirname7, resolve as resolve6 } from "node:path";
13505
13505
  async function startApi(options2) {
13506
13506
  const port = options2.port ?? 3800;
13507
- const rootDir = dirname6(dirname6(dirname6(dirname6(import.meta.dir))));
13507
+ const rootDir = dirname7(dirname7(dirname7(dirname7(import.meta.dir))));
13508
13508
  const apiPath = resolve6(rootDir, "packages/api/src/index.ts");
13509
13509
  await serviceManager.start(SERVICE_NAME3, ["bun", "run", "--watch", apiPath], {
13510
13510
  port,
@@ -13521,9 +13521,9 @@ var init_api2 = __esm(() => {
13521
13521
  });
13522
13522
 
13523
13523
  // src/services/subgraph-processor.ts
13524
- import { dirname as dirname7, resolve as resolve7 } from "node:path";
13524
+ import { dirname as dirname8, resolve as resolve7 } from "node:path";
13525
13525
  async function startSubgraphProcessor(options2) {
13526
- const rootDir = dirname7(dirname7(dirname7(dirname7(import.meta.dir))));
13526
+ const rootDir = dirname8(dirname8(dirname8(dirname8(import.meta.dir))));
13527
13527
  const servicePath = resolve7(rootDir, "packages/subgraphs/src/service.ts");
13528
13528
  await serviceManager.start(SERVICE_NAME4, ["bun", "run", "--watch", servicePath], {
13529
13529
  env: {
@@ -13559,7 +13559,7 @@ __export(exports_dev_impl, {
13559
13559
  isDevAlreadyRunning: () => isDevAlreadyRunning
13560
13560
  });
13561
13561
  import { mkdirSync as mkdirSync3 } from "node:fs";
13562
- import { dirname as dirname8, join as join7, resolve as resolve8 } from "node:path";
13562
+ import { dirname as dirname9, join as join8, resolve as resolve8 } from "node:path";
13563
13563
  async function isDevAlreadyRunning() {
13564
13564
  if (await isDevRunning()) {
13565
13565
  const running = await getRunningServices();
@@ -13637,7 +13637,7 @@ async function runBackground(options2) {
13637
13637
  startedAt: new Date().toISOString()
13638
13638
  };
13639
13639
  try {
13640
- const packagesDir = dirname8(dirname8(dirname8(dirname8(import.meta.dir))));
13640
+ const packagesDir = dirname9(dirname9(dirname9(dirname9(import.meta.dir))));
13641
13641
  const env = { DATABASE_URL: databaseUrl, DEV_MODE: "true" };
13642
13642
  const apiLogFile = getLogFile("api");
13643
13643
  const apiProc = Bun.spawn(["bun", "run", resolve8(packagesDir, "packages/api/src/index.ts")], {
@@ -13984,7 +13984,7 @@ async function restartDev() {
13984
13984
  await clearDevState();
13985
13985
  await clearLogs();
13986
13986
  const config = await loadConfig();
13987
- const packagesDir = dirname8(dirname8(dirname8(dirname8(import.meta.dir))));
13987
+ const packagesDir = dirname9(dirname9(dirname9(dirname9(import.meta.dir))));
13988
13988
  const env = state.env;
13989
13989
  const newState = {
13990
13990
  services: {},
@@ -14165,7 +14165,7 @@ async function ensureDevPostgres(dataDir) {
14165
14165
  if (check.stdout.toString().trim()) {
14166
14166
  return false;
14167
14167
  }
14168
- const pgDataDir = join7(dataDir, "postgres");
14168
+ const pgDataDir = join8(dataDir, "postgres");
14169
14169
  mkdirSync3(pgDataDir, { recursive: true });
14170
14170
  const stopped = await Bun.$`docker ps -aq -f name=secondlayer-dev-postgres`.quiet().nothrow();
14171
14171
  if (stopped.stdout.toString().trim()) {
@@ -14181,7 +14181,7 @@ async function ensureDevPostgres(dataDir) {
14181
14181
  throw new Error("PostgreSQL failed to start");
14182
14182
  }
14183
14183
  async function runMigrations(databaseUrl) {
14184
- const packagesDir = dirname8(dirname8(dirname8(dirname8(import.meta.dir))));
14184
+ const packagesDir = dirname9(dirname9(dirname9(dirname9(import.meta.dir))));
14185
14185
  const migrateScript = resolve8(packagesDir, "packages/shared/src/db/migrate.ts");
14186
14186
  const result = await Bun.$`DATABASE_URL=${databaseUrl} bun run ${migrateScript}`.quiet().nothrow();
14187
14187
  if (result.exitCode !== 0) {
@@ -21909,7 +21909,7 @@ var init_commands = __esm(() => {
21909
21909
  });
21910
21910
 
21911
21911
  // ../../node_modules/@antfu/ni/dist/shared/ni.B5qNAuoI.mjs
21912
- import path3, { join as join8, dirname as dirname9, resolve as resolve9 } from "node:path";
21912
+ import path3, { join as join9, dirname as dirname10, resolve as resolve9 } from "node:path";
21913
21913
  import process$1 from "node:process";
21914
21914
  import require$$0 from "readline";
21915
21915
  import require$$2 from "events";
@@ -24924,7 +24924,7 @@ function requireLib() {
24924
24924
  return lib;
24925
24925
  hasRequiredLib = 1;
24926
24926
  const { isexe, sync: isexeSync } = requireCjs();
24927
- const { join: join9, delimiter, sep, posix: posix2 } = require$$1$2;
24927
+ const { join: join10, delimiter, sep, posix: posix2 } = require$$1$2;
24928
24928
  const isWindows = process.platform === "win32";
24929
24929
  const rSlash = new RegExp(`[${posix2.sep}${sep === posix2.sep ? "" : sep}]`.replace(/(\\)/g, "\\$1"));
24930
24930
  const rRel = new RegExp(`^\\.${rSlash.source}`);
@@ -24951,7 +24951,7 @@ function requireLib() {
24951
24951
  const getPathPart = (raw, cmd) => {
24952
24952
  const pathPart = /^".*"$/.test(raw) ? raw.slice(1, -1) : raw;
24953
24953
  const prefix = !pathPart && rRel.test(cmd) ? cmd.slice(0, 2) : "";
24954
- return prefix + join9(pathPart, cmd);
24954
+ return prefix + join10(pathPart, cmd);
24955
24955
  };
24956
24956
  const which = async (cmd, opt = {}) => {
24957
24957
  const { pathEnv, pathExt, pathExtExe } = getPathInfo(cmd, opt);
@@ -25100,7 +25100,7 @@ var init_ni_B5qNAuoI = __esm(() => {
25100
25100
  options2 = {};
25101
25101
  libExports = requireLib();
25102
25102
  which = /* @__PURE__ */ getDefaultExportFromCjs(libExports);
25103
- CLI_TEMP_DIR = join8(os4.tmpdir(), "antfu-ni");
25103
+ CLI_TEMP_DIR = join9(os4.tmpdir(), "antfu-ni");
25104
25104
  customRcPath = process$1.env.NI_CONFIG_FILE;
25105
25105
  home = process$1.platform === "win32" ? process$1.env.USERPROFILE : process$1.env.HOME;
25106
25106
  defaultRcPath = path3.join(home || "~/", ".nirc");
@@ -25137,14 +25137,14 @@ function isPlainObject2(value) {
25137
25137
  }
25138
25138
 
25139
25139
  // ../../node_modules/execa/lib/arguments/file-url.js
25140
- import { fileURLToPath as fileURLToPath2 } from "node:url";
25140
+ import { fileURLToPath as fileURLToPath3 } from "node:url";
25141
25141
  var safeNormalizeFileUrl = (file, name) => {
25142
25142
  const fileString = normalizeFileUrl(normalizeDenoExecPath(file));
25143
25143
  if (typeof fileString !== "string") {
25144
25144
  throw new TypeError(`${name} must be a string or a file URL: ${fileString}.`);
25145
25145
  }
25146
25146
  return fileString;
25147
- }, normalizeDenoExecPath = (file) => isDenoExecPath(file) ? file.toString() : file, isDenoExecPath = (file) => typeof file !== "string" && file && Object.getPrototypeOf(file) === String.prototype, normalizeFileUrl = (file) => file instanceof URL ? fileURLToPath2(file) : file;
25147
+ }, normalizeDenoExecPath = (file) => isDenoExecPath(file) ? file.toString() : file, isDenoExecPath = (file) => typeof file !== "string" && file && Object.getPrototypeOf(file) === String.prototype, normalizeFileUrl = (file) => file instanceof URL ? fileURLToPath3(file) : file;
25148
25148
  var init_file_url = () => {};
25149
25149
 
25150
25150
  // ../../node_modules/execa/lib/methods/parameters.js
@@ -26440,9 +26440,9 @@ function pathKey(options3 = {}) {
26440
26440
  import { promisify as promisify4 } from "node:util";
26441
26441
  import { execFile as execFileCallback, execFileSync as execFileSyncOriginal } from "node:child_process";
26442
26442
  import path4 from "node:path";
26443
- import { fileURLToPath as fileURLToPath3 } from "node:url";
26443
+ import { fileURLToPath as fileURLToPath4 } from "node:url";
26444
26444
  function toPath(urlOrPath) {
26445
- return urlOrPath instanceof URL ? fileURLToPath3(urlOrPath) : urlOrPath;
26445
+ return urlOrPath instanceof URL ? fileURLToPath4(urlOrPath) : urlOrPath;
26446
26446
  }
26447
26447
  function traversePathUp(startPath) {
26448
26448
  return {
@@ -28824,7 +28824,7 @@ var init_stdio_option = __esm(() => {
28824
28824
  });
28825
28825
 
28826
28826
  // ../../node_modules/execa/lib/stdio/native.js
28827
- import { readFileSync as readFileSync2 } from "node:fs";
28827
+ import { readFileSync as readFileSync3 } from "node:fs";
28828
28828
  import tty3 from "node:tty";
28829
28829
  var handleNativeStream = ({ stdioItem, stdioItem: { type }, isStdioArray, fdNumber, direction, isSync }) => {
28830
28830
  if (!isStdioArray || type !== "native") {
@@ -28856,7 +28856,7 @@ var handleNativeStream = ({ stdioItem, stdioItem: { type }, isStdioArray, fdNumb
28856
28856
  if (tty3.isatty(targetFdNumber)) {
28857
28857
  throw new TypeError(`The \`${optionName}: ${serializeOptionValue(value)}\` option is invalid: it cannot be a TTY with synchronous methods.`);
28858
28858
  }
28859
- return { type: "uint8Array", value: bufferToUint8Array(readFileSync2(targetFdNumber)), optionName };
28859
+ return { type: "uint8Array", value: bufferToUint8Array(readFileSync3(targetFdNumber)), optionName };
28860
28860
  }, getTargetFdNumber = (value, fdNumber) => {
28861
28861
  if (value === "inherit") {
28862
28862
  return fdNumber;
@@ -29159,7 +29159,7 @@ var init_handle = __esm(() => {
29159
29159
  });
29160
29160
 
29161
29161
  // ../../node_modules/execa/lib/stdio/handle-sync.js
29162
- import { readFileSync as readFileSync3 } from "node:fs";
29162
+ import { readFileSync as readFileSync4 } from "node:fs";
29163
29163
  var handleStdioSync = (options3, verboseInfo) => handleStdio(addPropertiesSync, options3, verboseInfo, true), forbiddenIfSync = ({ type, optionName }) => {
29164
29164
  throwInvalidSyncValue(optionName, TYPE_TO_MESSAGE[type]);
29165
29165
  }, forbiddenNativeIfSync = ({ optionName, value }) => {
@@ -29187,8 +29187,8 @@ var init_handle_sync = __esm(() => {
29187
29187
  addPropertiesSync = {
29188
29188
  input: {
29189
29189
  ...addProperties,
29190
- fileUrl: ({ value }) => ({ contents: [bufferToUint8Array(readFileSync3(value))] }),
29191
- filePath: ({ value: { file } }) => ({ contents: [bufferToUint8Array(readFileSync3(file))] }),
29190
+ fileUrl: ({ value }) => ({ contents: [bufferToUint8Array(readFileSync4(value))] }),
29191
+ filePath: ({ value: { file } }) => ({ contents: [bufferToUint8Array(readFileSync4(file))] }),
29192
29192
  fileNumber: forbiddenIfSync,
29193
29193
  iterable: ({ value }) => ({ contents: [...value] }),
29194
29194
  string: ({ value }) => ({ contents: [value] }),
@@ -29557,7 +29557,7 @@ var init_output2 = __esm(() => {
29557
29557
  });
29558
29558
 
29559
29559
  // ../../node_modules/execa/lib/io/output-sync.js
29560
- import { writeFileSync as writeFileSync2, appendFileSync } from "node:fs";
29560
+ import { writeFileSync as writeFileSync3, appendFileSync } from "node:fs";
29561
29561
  var transformOutputSync = ({ fileDescriptors, syncResult: { output }, options: options3, isMaxBuffer, verboseInfo }) => {
29562
29562
  if (output === null) {
29563
29563
  return { output: Array.from({ length: 3 }) };
@@ -29650,7 +29650,7 @@ var transformOutputSync = ({ fileDescriptors, syncResult: { output }, options: o
29650
29650
  appendFileSync(path9, serializedResult);
29651
29651
  } else {
29652
29652
  outputFiles.add(pathString);
29653
- writeFileSync2(path9, serializedResult);
29653
+ writeFileSync3(path9, serializedResult);
29654
29654
  }
29655
29655
  }
29656
29656
  };
@@ -32439,7 +32439,7 @@ var {
32439
32439
  // package.json
32440
32440
  var package_default = {
32441
32441
  name: "@secondlayer/cli",
32442
- version: "3.5.3",
32442
+ version: "3.5.4",
32443
32443
  description: "CLI for subgraphs and blockchain indexing on Stacks",
32444
32444
  type: "module",
32445
32445
  bin: {
@@ -32483,7 +32483,7 @@ var package_default = {
32483
32483
  "@inquirer/prompts": "^8.2.0",
32484
32484
  "@secondlayer/bundler": "^0.3.2",
32485
32485
  "@secondlayer/sdk": "^3.2.2",
32486
- "@secondlayer/shared": "^4.3.3",
32486
+ "@secondlayer/shared": "^4.3.4",
32487
32487
  "@secondlayer/stacks": "^2.0.0",
32488
32488
  "@secondlayer/subgraphs": "^1.3.2",
32489
32489
  "@biomejs/js-api": "^0.7.0",
@@ -33196,6 +33196,7 @@ async function createSubscription(name, opts) {
33196
33196
  TASK_ID: `${subgraph}-${table}`
33197
33197
  });
33198
33198
  let signingSecret = null;
33199
+ let provisioningFailed = false;
33199
33200
  if (!opts.skipApi) {
33200
33201
  try {
33201
33202
  if (!sl)
@@ -33213,8 +33214,9 @@ async function createSubscription(name, opts) {
33213
33214
  signingSecret = res.signingSecret;
33214
33215
  success(`Subscription provisioned: ${blue(res.subscription.id)}`);
33215
33216
  } catch (err) {
33217
+ provisioningFailed = true;
33216
33218
  warn(`Subscription provisioning failed: ${err instanceof Error ? err.message : String(err)}`);
33217
- info("Template copied fix auth + run again, or provision via dashboard.");
33219
+ info("Template copied, but the subscription was not created. Provision it in the dashboard, or remove the template directory and rerun this command after fixing the API error.");
33218
33220
  }
33219
33221
  }
33220
33222
  if (signingSecret) {
@@ -33236,6 +33238,10 @@ ${dim(" ")}${signingSecret}`);
33236
33238
  }
33237
33239
  }
33238
33240
  console.log();
33241
+ if (provisioningFailed) {
33242
+ error("Subscription was not created.");
33243
+ process.exit(1);
33244
+ }
33239
33245
  success(`Done. Next:
33240
33246
  cd ${name}
33241
33247
  bun install
@@ -34309,8 +34315,15 @@ async function resyncDatabase(skipConfirm, backfill) {
34309
34315
  }
34310
34316
  }
34311
34317
  // src/commands/subgraphs.ts
34312
- import { existsSync as existsSync3, mkdirSync as mkdirSync2, watch } from "node:fs";
34313
- import { resolve as resolve3 } from "node:path";
34318
+ import {
34319
+ existsSync as existsSync3,
34320
+ mkdirSync as mkdirSync2,
34321
+ readFileSync as readFileSync2,
34322
+ watch,
34323
+ writeFileSync as writeFileSync2
34324
+ } from "node:fs";
34325
+ import { dirname as dirname4, join as join7, resolve as resolve3 } from "node:path";
34326
+ import { fileURLToPath as fileURLToPath2 } from "node:url";
34314
34327
  import { confirm as confirm3 } from "@inquirer/prompts";
34315
34328
 
34316
34329
  // src/generators/subgraph-scaffold.ts
@@ -34585,6 +34598,45 @@ function parseStartBlockOption(value) {
34585
34598
  }
34586
34599
  return parsed;
34587
34600
  }
34601
+ function readCliSubgraphsDependency() {
34602
+ const here = dirname4(fileURLToPath2(import.meta.url));
34603
+ const candidates = [
34604
+ resolve3(here, "..", "..", "package.json"),
34605
+ resolve3(here, "..", "package.json")
34606
+ ];
34607
+ for (const candidate of candidates) {
34608
+ if (!existsSync3(candidate))
34609
+ continue;
34610
+ const pkg = JSON.parse(readFileSync2(candidate, "utf8"));
34611
+ const dep = pkg.dependencies?.["@secondlayer/subgraphs"];
34612
+ if (dep)
34613
+ return dep;
34614
+ }
34615
+ return "^1.3.2";
34616
+ }
34617
+ function ensureScaffoldPackageJson(dir) {
34618
+ const packagePath = join7(dir, "package.json");
34619
+ const subgraphsDep = readCliSubgraphsDependency();
34620
+ if (!existsSync3(packagePath)) {
34621
+ writeFileSync2(packagePath, `${JSON.stringify({
34622
+ type: "module",
34623
+ dependencies: {
34624
+ "@secondlayer/subgraphs": subgraphsDep
34625
+ }
34626
+ }, null, 2)}
34627
+ `, "utf8");
34628
+ return;
34629
+ }
34630
+ const pkg = JSON.parse(readFileSync2(packagePath, "utf8"));
34631
+ if (pkg.dependencies?.["@secondlayer/subgraphs"])
34632
+ return;
34633
+ pkg.dependencies = {
34634
+ ...pkg.dependencies ?? {},
34635
+ "@secondlayer/subgraphs": subgraphsDep
34636
+ };
34637
+ writeFileSync2(packagePath, `${JSON.stringify(pkg, null, 2)}
34638
+ `, "utf8");
34639
+ }
34588
34640
  function createSubgraphDeployPreview(def, options2 = {}) {
34589
34641
  const tableColumns = Object.entries(def.schema).map(([table, schema]) => `${table}: ${Object.keys(schema.columns).join(", ") || "(no columns)"}`);
34590
34642
  return {
@@ -34773,6 +34825,7 @@ Stopped watching.`);
34773
34825
  sources: effectiveDef.sources,
34774
34826
  schema: effectiveDef.schema,
34775
34827
  handlerCode,
34828
+ sourceCode: source,
34776
34829
  ...startBlock !== undefined ? { startBlock } : {}
34777
34830
  });
34778
34831
  if (result.action === "unchanged") {
@@ -35086,6 +35139,7 @@ ${rows.length} row(s)`));
35086
35139
  if (!existsSync3(dir))
35087
35140
  mkdirSync2(dir, { recursive: true });
35088
35141
  await writeTextFile(outPath, content);
35142
+ ensureScaffoldPackageJson(dir);
35089
35143
  success(`Created ${outPath}`);
35090
35144
  info(`Next: sl subgraphs deploy ${options2.output}`);
35091
35145
  } catch (err) {
@@ -36528,5 +36582,5 @@ registerLocalCommand(program);
36528
36582
  registerAccountCommand(program);
36529
36583
  program.parse();
36530
36584
 
36531
- //# debugId=BE2AD99915C01F0964756E2164756E21
36585
+ //# debugId=96B7A917235EEA4164756E2164756E21
36532
36586
  //# sourceMappingURL=cli.js.map