datasette-ts 0.0.4 → 0.0.6

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
@@ -23975,20 +23975,30 @@ function normalizeLibsqlRows(result) {
23975
23975
  // src/cli/deploy-cloudflare.ts
23976
23976
  var DEFAULT_IMPORTS_DIR = ".datasette-ts/imports";
23977
23977
  async function runCloudflareDeploy(args) {
23978
+ const startedAt = Date.now();
23979
+ logStep("Starting Cloudflare deploy");
23978
23980
  const options = parseDeployArgs(args);
23981
+ logStep(`Database: ${options.dbFile}`);
23982
+ logStep(`Worker: ${options.workerName}`);
23983
+ logStep(`D1: ${options.d1Name}`);
23979
23984
  await assertFileExists(options.dbFile, "SQLite database");
23980
23985
  const packageRoot = await resolvePackageRoot();
23986
+ logStep(`Package root: ${packageRoot}`);
23981
23987
  const workerEntrypoint = await resolveWorkerEntrypoint(packageRoot);
23988
+ logStep(`Worker entrypoint: ${workerEntrypoint}`);
23982
23989
  const assetsPath = join(packageRoot, "public");
23983
23990
  await assertFileExists(assetsPath, "assets directory");
23991
+ logStep("Initializing Alchemy app");
23984
23992
  const app = await alchemy(options.workerName);
23985
23993
  let importFile;
23986
23994
  try {
23995
+ logStep("Exporting SQLite for D1 import");
23987
23996
  importFile = await dumpSqliteForD1({
23988
23997
  dbFile: options.dbFile,
23989
23998
  outputDir: options.importsDir,
23990
23999
  outputName: options.d1Name
23991
24000
  });
24001
+ logStep(`D1 import file: ${importFile}`);
23992
24002
  } catch (error) {
23993
24003
  if (isSqliteCliMissing(error)) {
23994
24004
  throw new Error(
@@ -23997,14 +24007,21 @@ async function runCloudflareDeploy(args) {
23997
24007
  }
23998
24008
  throw error;
23999
24009
  }
24010
+ logStep("Loading schema");
24000
24011
  const schema = await loadSchemaFromFile(options.dbFile);
24001
- const inspectData = options.precomputeInspect ? await loadInspectDataFromFile(options.dbFile, options.dbName) : null;
24012
+ let inspectData = null;
24013
+ if (options.precomputeInspect) {
24014
+ logStep("Precomputing inspect data");
24015
+ inspectData = await loadInspectDataFromFile(options.dbFile, options.dbName);
24016
+ }
24017
+ logStep("Creating D1 database");
24002
24018
  const db = await D1Database(`d1-${options.d1Name}`, {
24003
24019
  name: options.d1Name,
24004
24020
  importFiles: [importFile],
24005
24021
  profile: options.profile,
24006
24022
  adopt: true
24007
24023
  });
24024
+ logStep("Configuring static assets");
24008
24025
  const staticAssets = await Assets({
24009
24026
  path: assetsPath
24010
24027
  });
@@ -24017,6 +24034,7 @@ async function runCloudflareDeploy(args) {
24017
24034
  if (inspectData) {
24018
24035
  bindings.DATASETTE_INSPECT_DATA = JSON.stringify(inspectData);
24019
24036
  }
24037
+ logStep("Deploying worker");
24020
24038
  const worker = await Worker(`worker-${options.workerName}`, {
24021
24039
  entrypoint: workerEntrypoint,
24022
24040
  compatibilityFlags: ["nodejs_compat"],
@@ -24028,7 +24046,9 @@ async function runCloudflareDeploy(args) {
24028
24046
  adopt: true
24029
24047
  });
24030
24048
  console.log(`Worker deployed at: ${worker.url}`);
24049
+ logStep("Finalizing Alchemy app");
24031
24050
  await app.finalize();
24051
+ logStep(`Done in ${formatDuration(Date.now() - startedAt)}`);
24032
24052
  }
24033
24053
  function parseDeployArgs(args) {
24034
24054
  const positional = [];
@@ -24206,6 +24226,16 @@ function isSqliteCliMissing(error) {
24206
24226
  }
24207
24227
  return "code" in error && error.code === "ENOENT";
24208
24228
  }
24229
+ function logStep(message) {
24230
+ console.log(`[datasette-ts] ${message}`);
24231
+ }
24232
+ function formatDuration(ms) {
24233
+ if (ms < 1e3) {
24234
+ return `${ms}ms`;
24235
+ }
24236
+ const seconds = (ms / 1e3).toFixed(1);
24237
+ return `${seconds}s`;
24238
+ }
24209
24239
 
24210
24240
  // src/cli/serve.ts
24211
24241
  init_registry();
@@ -24507,12 +24537,16 @@ function parseNamedArg2(arg, nextValue) {
24507
24537
  }
24508
24538
 
24509
24539
  // src/cli.ts
24510
- try {
24511
- await main();
24512
- } catch (error) {
24540
+ var keepAlive = setInterval(() => {
24541
+ }, 1e3);
24542
+ var mainPromise = main();
24543
+ mainPromise.catch((error) => {
24513
24544
  console.error(error);
24514
24545
  process.exitCode = 1;
24515
- }
24546
+ });
24547
+ mainPromise.finally(() => {
24548
+ clearInterval(keepAlive);
24549
+ });
24516
24550
  async function main() {
24517
24551
  const args = process.argv.slice(2);
24518
24552
  const [command, subcommand] = args;