@project-ajax/sdk 0.0.55 → 0.0.56

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.
Files changed (43) hide show
  1. package/dist/cli/api/client.d.ts +2 -2
  2. package/dist/cli/api/client.d.ts.map +1 -1
  3. package/dist/cli/commands/auth.impl.js +6 -6
  4. package/dist/cli/commands/bundle.impl.js +2 -2
  5. package/dist/cli/commands/capabilities.impl.js +4 -4
  6. package/dist/cli/commands/connect.impl.js +13 -13
  7. package/dist/cli/commands/deploy.impl.d.ts.map +1 -1
  8. package/dist/cli/commands/deploy.impl.js +10 -16
  9. package/dist/cli/commands/env.impl.d.ts.map +1 -1
  10. package/dist/cli/commands/env.impl.js +7 -10
  11. package/dist/cli/commands/exec.impl.d.ts.map +1 -1
  12. package/dist/cli/commands/exec.impl.js +14 -16
  13. package/dist/cli/commands/runs.impl.js +7 -7
  14. package/dist/cli/commands/secrets.impl.js +12 -12
  15. package/dist/cli/commands/utils/testing.d.ts +2 -11
  16. package/dist/cli/commands/utils/testing.d.ts.map +1 -1
  17. package/dist/cli/commands/utils/testing.js +4 -4
  18. package/dist/cli/context.d.ts +2 -2
  19. package/dist/cli/context.d.ts.map +1 -1
  20. package/dist/cli/context.js +3 -3
  21. package/dist/cli/deploy.js +11 -11
  22. package/dist/cli/handler.js +2 -2
  23. package/dist/cli/{writer.d.ts → io.d.ts} +10 -3
  24. package/dist/cli/io.d.ts.map +1 -0
  25. package/dist/cli/{writer.js → io.js} +24 -2
  26. package/package.json +3 -3
  27. package/src/cli/api/client.ts +3 -3
  28. package/src/cli/commands/auth.impl.ts +6 -6
  29. package/src/cli/commands/bundle.impl.ts +2 -2
  30. package/src/cli/commands/capabilities.impl.ts +4 -4
  31. package/src/cli/commands/connect.impl.ts +13 -13
  32. package/src/cli/commands/deploy.impl.test.ts +9 -14
  33. package/src/cli/commands/deploy.impl.ts +11 -16
  34. package/src/cli/commands/env.impl.ts +7 -11
  35. package/src/cli/commands/exec.impl.ts +14 -16
  36. package/src/cli/commands/runs.impl.ts +7 -7
  37. package/src/cli/commands/secrets.impl.ts +12 -12
  38. package/src/cli/commands/utils/testing.ts +5 -4
  39. package/src/cli/context.ts +3 -3
  40. package/src/cli/deploy.ts +11 -11
  41. package/src/cli/handler.ts +2 -2
  42. package/src/cli/{writer.ts → io.ts} +34 -2
  43. package/dist/cli/writer.d.ts.map +0 -1
@@ -4,8 +4,9 @@ import * as os from "node:os";
4
4
  import { tmpdir } from "node:os";
5
5
  import * as path from "node:path";
6
6
  import { Config, type ConfigMap } from "../../config.js";
7
+ import type { LocalContext } from "../../context.js";
7
8
  import type { GlobalFlags } from "../../flags.js";
8
- import { Writer } from "../../writer.js";
9
+ import { IO } from "../../io.js";
9
10
 
10
11
  export const tmpDirectories: string[] = [];
11
12
 
@@ -36,13 +37,13 @@ export async function createAndLoadConfig({
36
37
  return [map, configFilePath];
37
38
  }
38
39
 
39
- export function createBaseContext() {
40
+ export function createBaseContext(): LocalContext {
40
41
  return {
41
- writer: new Writer({ debugEnabled: false }),
42
- process,
43
42
  fs,
43
+ io: new IO({ debugEnabled: false }),
44
44
  os,
45
45
  path,
46
+ process,
46
47
  };
47
48
  }
48
49
 
@@ -3,24 +3,24 @@ import * as os from "node:os";
3
3
  import * as path from "node:path";
4
4
  import type { StricliAutoCompleteContext } from "@stricli/auto-complete";
5
5
  import type { CommandContext } from "@stricli/core";
6
- import { Writer } from "./writer.js";
6
+ import { IO } from "./io.js";
7
7
 
8
8
  export interface LocalContext
9
9
  extends CommandContext,
10
10
  StricliAutoCompleteContext {
11
11
  readonly fs: typeof fs;
12
+ readonly io: IO;
12
13
  readonly os: typeof os;
13
14
  readonly path: typeof path;
14
15
  readonly process: NodeJS.Process;
15
- readonly writer: Writer;
16
16
  }
17
17
 
18
18
  export function buildContext(process: NodeJS.Process): LocalContext {
19
19
  return {
20
20
  fs,
21
+ io: new IO({ debugEnabled: false }),
21
22
  os,
22
23
  path,
23
24
  process,
24
- writer: new Writer({ debugEnabled: false }),
25
25
  };
26
26
  }
package/src/cli/deploy.ts CHANGED
@@ -53,7 +53,7 @@ export async function deployWorker(
53
53
 
54
54
  // Resolve absolute path
55
55
  const absPath = path.resolve(process.cwd(), workerPath);
56
- context.writer.debug(`Deploying worker from: ${absPath}`);
56
+ context.io.debug(`Deploying worker from: ${absPath}`);
57
57
 
58
58
  // Create API client
59
59
  const client = context.apiClient;
@@ -63,7 +63,7 @@ export async function deployWorker(
63
63
  let workerId: string;
64
64
 
65
65
  if ("workerId" in options) {
66
- context.writer.writeErr(`Updating worker...`);
66
+ context.io.writeErr(`Updating worker...`);
67
67
 
68
68
  workerId = options.workerId;
69
69
 
@@ -73,13 +73,13 @@ export async function deployWorker(
73
73
  uploadUrl = res.url;
74
74
  uploadFields = res.fields;
75
75
  } else {
76
- context.writer.writeErr(
76
+ context.io.writeErr(
77
77
  "Failed to generate pre-signed upload URL for worker bundle:",
78
78
  );
79
79
  throw new Error(updateResult.error.message);
80
80
  }
81
81
  } else {
82
- context.writer.writeErr(`Creating worker...`);
82
+ context.io.writeErr(`Creating worker...`);
83
83
 
84
84
  const createResult = await client.createWorker(options.name);
85
85
  if (Result.isSuccess(createResult)) {
@@ -93,20 +93,20 @@ export async function deployWorker(
93
93
  }
94
94
  }
95
95
 
96
- context.writer.debug(`Generated upload URL: ${uploadUrl}`);
96
+ context.io.debug(`Generated upload URL: ${uploadUrl}`);
97
97
 
98
98
  // Build the worker bundle
99
- context.writer.writeErr("Building worker bundle...");
99
+ context.io.writeErr("Building worker bundle...");
100
100
  const archivePath = await buildWorkerBundle(context, absPath);
101
- context.writer.debug(`Created bundle at: ${archivePath}`);
101
+ context.io.debug(`Created bundle at: ${archivePath}`);
102
102
 
103
103
  // Upload the bundle
104
- context.writer.writeErr("Uploading bundle...");
104
+ context.io.writeErr("Uploading bundle...");
105
105
  await uploadBundle(uploadUrl, uploadFields, archivePath);
106
- context.writer.debug("Upload complete");
106
+ context.io.debug("Upload complete");
107
107
 
108
108
  // Fetch and save capabilities
109
- context.writer.writeErr("Fetching and saving worker capabilities...");
109
+ context.io.writeErr("Fetching and saving worker capabilities...");
110
110
  const capabilitiesResult = await client.fetchAndSaveCapabilities(workerId);
111
111
 
112
112
  if (Result.isSuccess(capabilitiesResult)) {
@@ -141,7 +141,7 @@ async function buildWorkerBundle(
141
141
  platform: "node",
142
142
  });
143
143
 
144
- context.writer.debug(`Built bundle to: ${outdir}`);
144
+ context.io.debug(`Built bundle to: ${outdir}`);
145
145
 
146
146
  // Create tar.gz archive
147
147
  const archiveDir = fs.mkdtempSync("/tmp/workers-archive-");
@@ -35,7 +35,7 @@ export function buildHandler<const FLAGS, const ARGS extends BaseArgs = []>(
35
35
  flags,
36
36
  });
37
37
 
38
- this.writer.debugEnabled = flags.debug;
38
+ this.io.debugEnabled = flags.debug;
39
39
 
40
40
  await handler.call({ ...this, config }, flags, ...args);
41
41
  };
@@ -61,7 +61,7 @@ export function buildAuthedHandler<
61
61
  environment,
62
62
  baseUrl: this.config.baseUrl,
63
63
  cellId,
64
- writer: this.writer,
64
+ writer: this.io,
65
65
  });
66
66
  return handler.call({ ...this, apiClient: client }, flags, ...args);
67
67
  });
@@ -1,3 +1,4 @@
1
+ import * as prompts from "@inquirer/prompts";
1
2
  import { createTable, type TableCell, type TableItem } from "@visulima/tabular";
2
3
 
3
4
  export interface WriterOptions {
@@ -10,10 +11,14 @@ export interface TableOptions {
10
11
  plain: boolean;
11
12
  }
12
13
 
14
+ type WithSafety<T> = T & {
15
+ noTTY: string;
16
+ };
17
+
13
18
  /**
14
- * A writer writes messages to standard out and standard error.
19
+ * IO manages safe, consistent, input and output patterns for the CLI.
15
20
  */
16
- export class Writer {
21
+ export class IO {
17
22
  debugEnabled: boolean;
18
23
 
19
24
  constructor(options: WriterOptions) {
@@ -74,6 +79,33 @@ export class Writer {
74
79
  this.writeErr(content);
75
80
  }
76
81
 
82
+ confirm(config: WithSafety<Parameters<typeof prompts.confirm>[0]>) {
83
+ if (!process.stdin.isTTY) {
84
+ this.writeErr(config.noTTY);
85
+ process.exit(1);
86
+ }
87
+
88
+ return prompts.confirm(config).catch(this.#handlePromptExit.bind(this));
89
+ }
90
+
91
+ input(config: WithSafety<Parameters<typeof prompts.input>[0]>) {
92
+ if (!process.stdin.isTTY) {
93
+ this.writeErr(config.noTTY);
94
+ process.exit(1);
95
+ }
96
+
97
+ return prompts.input(config).catch(this.#handlePromptExit.bind(this));
98
+ }
99
+
100
+ #handlePromptExit(err: unknown) {
101
+ if (err instanceof Error && err.name === "ExitPromptError") {
102
+ this.writeErr("👋 Prompt cancelled. Goodbye!");
103
+ process.exit(1);
104
+ }
105
+
106
+ throw err;
107
+ }
108
+
77
109
  #buildTable(tableConfig: TableOptions) {
78
110
  if (tableConfig.plain) {
79
111
  return tableConfig.rows
@@ -1 +0,0 @@
1
- {"version":3,"file":"writer.d.ts","sourceRoot":"","sources":["../../src/cli/writer.ts"],"names":[],"mappings":"AAAA,OAAO,EAAe,KAAK,SAAS,EAAkB,MAAM,mBAAmB,CAAC;AAEhF,MAAM,WAAW,aAAa;IAC7B,YAAY,EAAE,OAAO,CAAC;CACtB;AAED,MAAM,WAAW,YAAY;IAC5B,OAAO,EAAE,SAAS,EAAE,GAAG,SAAS,EAAE,EAAE,CAAC;IACrC,IAAI,EAAE,SAAS,EAAE,EAAE,CAAC;IACpB,KAAK,EAAE,OAAO,CAAC;CACf;AAED;;GAEG;AACH,qBAAa,MAAM;;IAClB,YAAY,EAAE,OAAO,CAAC;gBAEV,OAAO,EAAE,aAAa;IAIlC;;;;OAIG;IACH,KAAK,CAAC,GAAG,IAAI,EAAE,UAAU,CAAC,OAAO,OAAO,CAAC,GAAG,CAAC;IAW7C;;;;OAIG;IACH,QAAQ,CAAC,GAAG,IAAI,EAAE,UAAU,CAAC,OAAO,OAAO,CAAC,MAAM,CAAC,KAAK,CAAC;IAIzD;;;;OAIG;IACH,QAAQ,CAAC,GAAG,IAAI,EAAE,UAAU,CAAC,OAAO,OAAO,CAAC,MAAM,CAAC,KAAK,CAAC;IAIzD;;;;OAIG;IACH,aAAa,CAAC,WAAW,EAAE,YAAY;IAKvC;;;;OAIG;IACH,aAAa,CAAC,WAAW,EAAE,YAAY;CAqBvC"}