@project-ajax/sdk 0.0.30 → 0.0.32

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.
@@ -1 +1 @@
1
- {"version":3,"file":"tool.d.ts","sourceRoot":"","sources":["../../src/capabilities/tool.ts"],"names":[],"mappings":"AAAA,OAAO,EAAO,KAAK,cAAc,EAAE,MAAM,KAAK,CAAC;AAE/C,KAAK,SAAS,GACX,MAAM,GACN,MAAM,GACN,OAAO,GACP,IAAI,GACJ,SAAS,EAAE,GACX;IAAE,CAAC,GAAG,EAAE,MAAM,GAAG,SAAS,CAAA;CAAE,CAAC;AAEhC,MAAM,WAAW,iBAAiB,CACjC,CAAC,SAAS,SAAS,EACnB,CAAC,SAAS,SAAS,GAAG,SAAS;IAE/B,WAAW,EAAE,MAAM,CAAC;IACpB,MAAM,EAAE,cAAc,CAAC,CAAC,CAAC,CAAC;IAC1B,YAAY,CAAC,EAAE,cAAc,CAAC,CAAC,CAAC,CAAC;IACjC,OAAO,EAAE,CAAC,KAAK,EAAE,CAAC,KAAK,CAAC,GAAG,OAAO,CAAC,CAAC,CAAC,CAAC;CACtC;AAED;;GAEG;AACH,qBAAa,qBAAsB,SAAQ,KAAK;gBACnC,OAAO,EAAE,MAAM;CAI3B;AAED;;GAEG;AACH,qBAAa,sBAAuB,SAAQ,KAAK;gBACpC,OAAO,EAAE,MAAM;CAI3B;AAED;;GAEG;AACH,qBAAa,kBAAmB,SAAQ,KAAK;gBAChC,OAAO,EAAE,MAAM;CAI3B;AAED;;;;;;;;;;;;;;;;;;;;;;;GAuBG;AACH,wBAAgB,IAAI,CAAC,CAAC,SAAS,SAAS,EAAE,CAAC,SAAS,SAAS,GAAG,SAAS,EACxE,MAAM,EAAE,iBAAiB,CAAC,CAAC,EAAE,CAAC,CAAC;;;;;;;mBAeT,SAAS,GAAG,OAAO,CACrC;QACA,IAAI,EAAE,SAAS,CAAC;QAChB,KAAK,EAAE,CAAC,CAAC;KACR,G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EAAE,OAAO,CAAC;QACd,KAAK,EACF,qBAAqB,GACrB,sBAAsB,GACtB,kBAAkB,CAAC;KACrB,CACH;EA4CF"}
@@ -52,6 +52,9 @@ function tool(config) {
52
52
  )
53
53
  };
54
54
  }
55
+ process.stdout.write(`
56
+ <output>${JSON.stringify(result)}</output>
57
+ `);
55
58
  return {
56
59
  _tag: "success",
57
60
  value: result
@@ -1 +1 @@
1
- {"version":3,"file":"deploy.d.ts","sourceRoot":"","sources":["../../../src/cli/commands/deploy.ts"],"names":[],"mappings":";AAGA,wBAYG"}
1
+ {"version":3,"file":"deploy.d.ts","sourceRoot":"","sources":["../../../src/cli/commands/deploy.ts"],"names":[],"mappings":";AAGA,wBAkBG"}
@@ -1,2 +1,6 @@
1
- export declare const deploy: (this: import("../context.js").LocalContext, flags: import("../flags.js").GlobalFlags) => Promise<void>;
1
+ interface DeployFlags {
2
+ name?: string;
3
+ }
4
+ export declare const deploy: (this: import("../context.js").LocalContext, flags: import("../flags.js").GlobalFlags & DeployFlags) => Promise<void>;
5
+ export {};
2
6
  //# sourceMappingURL=deploy.impl.d.ts.map
@@ -1 +1 @@
1
- {"version":3,"file":"deploy.impl.d.ts","sourceRoot":"","sources":["../../../src/cli/commands/deploy.impl.ts"],"names":[],"mappings":"AAIA,eAAO,MAAM,MAAM,yGA6BjB,CAAC"}
1
+ {"version":3,"file":"deploy.impl.d.ts","sourceRoot":"","sources":["../../../src/cli/commands/deploy.impl.ts"],"names":[],"mappings":"AAMA,UAAU,WAAW;IACpB,IAAI,CAAC,EAAE,MAAM,CAAC;CACd;AAED,eAAO,MAAM,MAAM,uHAmEjB,CAAC"}
@@ -1,7 +1,8 @@
1
+ import prompts from "prompts";
1
2
  import { Result } from "../api/result.js";
2
3
  import { deployWorker } from "../deploy.js";
3
4
  import { buildAuthedHandler } from "../handler.js";
4
- const deploy = buildAuthedHandler(async function() {
5
+ const deploy = buildAuthedHandler(async function(flags) {
5
6
  const { token } = this.config.tokenInfo;
6
7
  const workerId = this.config.workerId;
7
8
  const environment = this.config.environment;
@@ -10,12 +11,46 @@ const deploy = buildAuthedHandler(async function() {
10
11
  }
11
12
  const workerPath = this.process.cwd();
12
13
  this.writer.writeErr("Deploying worker...");
13
- const result = await deployWorker(this, {
14
- workerPath,
15
- workerId,
16
- token,
17
- environment
18
- });
14
+ const name = flags.name;
15
+ if (workerId && name) {
16
+ throw new Error("Cannot specify a name when updating an existing worker");
17
+ }
18
+ let result;
19
+ if (workerId) {
20
+ result = await deployWorker(this, {
21
+ workerPath,
22
+ workerId,
23
+ token,
24
+ environment
25
+ });
26
+ } else {
27
+ let validatedName;
28
+ if (name) {
29
+ validatedName = name;
30
+ } else {
31
+ const { name: nameInput } = await prompts({
32
+ type: "text",
33
+ name: "name",
34
+ message: "Enter a name for the worker",
35
+ validate: (value) => {
36
+ if (value.length < 1) {
37
+ return "Name is required";
38
+ }
39
+ return true;
40
+ }
41
+ });
42
+ if (!nameInput?.trim()) {
43
+ throw new Error("Name is required");
44
+ }
45
+ validatedName = nameInput.trim();
46
+ }
47
+ result = await deployWorker(this, {
48
+ name: validatedName,
49
+ workerPath,
50
+ token,
51
+ environment
52
+ });
53
+ }
19
54
  if (Result.isSuccess(result)) {
20
55
  const { workerId: workerId2 } = Result.unwrap(result);
21
56
  await this.config.setWorkerId(workerId2);
@@ -6,7 +6,13 @@ var deploy_default = buildCommand({
6
6
  },
7
7
  parameters: {
8
8
  flags: {
9
- ...globalFlags
9
+ ...globalFlags,
10
+ name: {
11
+ kind: "parsed",
12
+ parse: String,
13
+ brief: "The name of the worker (if it has not yet been created)",
14
+ optional: true
15
+ }
10
16
  }
11
17
  },
12
18
  loader: () => import("./deploy.impl.js").then((m) => m.deploy)
@@ -1,7 +1,7 @@
1
1
  import type { ApiError, Environment } from "./api/client.js";
2
2
  import { Result } from "./api/result.js";
3
3
  import type { AuthedContext } from "./handler.js";
4
- export interface DeployOptions {
4
+ export interface BaseDeployOptions {
5
5
  /**
6
6
  * Path to the worker directory to deploy
7
7
  */
@@ -14,8 +14,20 @@ export interface DeployOptions {
14
14
  * Environment to deploy to
15
15
  */
16
16
  environment: Environment;
17
- workerId?: string | null;
18
17
  }
18
+ export interface CreateDeployOptions extends BaseDeployOptions {
19
+ /**
20
+ * Name of the worker (if it has not yet been created)
21
+ */
22
+ name: string;
23
+ }
24
+ export interface UpdateDeployOptions extends BaseDeployOptions {
25
+ /**
26
+ * ID of the worker to update
27
+ */
28
+ workerId: string;
29
+ }
30
+ export type DeployOptions = CreateDeployOptions | UpdateDeployOptions;
19
31
  /**
20
32
  * Deploy a worker to the specified environment
21
33
  */
@@ -1 +1 @@
1
- {"version":3,"file":"deploy.d.ts","sourceRoot":"","sources":["../../src/cli/deploy.ts"],"names":[],"mappings":"AAMA,OAAO,KAAK,EAAE,QAAQ,EAAE,WAAW,EAAE,MAAM,iBAAiB,CAAC;AAC7D,OAAO,EAAE,MAAM,EAAE,MAAM,iBAAiB,CAAC;AAEzC,OAAO,KAAK,EAAE,aAAa,EAAE,MAAM,cAAc,CAAC;AAElD,MAAM,WAAW,aAAa;IAC7B;;OAEG;IACH,UAAU,EAAE,MAAM,CAAC;IAEnB;;OAEG;IACH,KAAK,EAAE,MAAM,CAAC;IAEd;;OAEG;IACH,WAAW,EAAE,WAAW,CAAC;IAEzB,QAAQ,CAAC,EAAE,MAAM,GAAG,IAAI,CAAC;CACzB;AAED;;GAEG;AACH,wBAAsB,YAAY,CACjC,OAAO,EAAE,aAAa,EACtB,OAAO,EAAE,aAAa,GACpB,OAAO,CAAC,MAAM,CAAC;IAAE,QAAQ,EAAE,MAAM,CAAA;CAAE,EAAE,QAAQ,CAAC,CAAC,CAiEjD"}
1
+ {"version":3,"file":"deploy.d.ts","sourceRoot":"","sources":["../../src/cli/deploy.ts"],"names":[],"mappings":"AAMA,OAAO,KAAK,EAAE,QAAQ,EAAE,WAAW,EAAE,MAAM,iBAAiB,CAAC;AAC7D,OAAO,EAAE,MAAM,EAAE,MAAM,iBAAiB,CAAC;AAEzC,OAAO,KAAK,EAAE,aAAa,EAAE,MAAM,cAAc,CAAC;AAElD,MAAM,WAAW,iBAAiB;IACjC;;OAEG;IACH,UAAU,EAAE,MAAM,CAAC;IAEnB;;OAEG;IACH,KAAK,EAAE,MAAM,CAAC;IAEd;;OAEG;IACH,WAAW,EAAE,WAAW,CAAC;CACzB;AAED,MAAM,WAAW,mBAAoB,SAAQ,iBAAiB;IAC7D;;OAEG;IACH,IAAI,EAAE,MAAM,CAAC;CACb;AAED,MAAM,WAAW,mBAAoB,SAAQ,iBAAiB;IAC7D;;OAEG;IACH,QAAQ,EAAE,MAAM,CAAC;CACjB;AAED,MAAM,MAAM,aAAa,GAAG,mBAAmB,GAAG,mBAAmB,CAAC;AAEtE;;GAEG;AACH,wBAAsB,YAAY,CACjC,OAAO,EAAE,aAAa,EACtB,OAAO,EAAE,aAAa,GACpB,OAAO,CAAC,MAAM,CAAC;IAAE,QAAQ,EAAE,MAAM,CAAA;CAAE,EAAE,QAAQ,CAAC,CAAC,CAkEjD"}
@@ -4,19 +4,17 @@ import * as path from "node:path";
4
4
  import * as esbuild from "esbuild";
5
5
  import { Result } from "./api/result.js";
6
6
  async function deployWorker(context, options) {
7
- const { workerPath, workerId: workerIdForUpdate } = options;
7
+ const { workerPath } = options;
8
8
  const absPath = path.resolve(process.cwd(), workerPath);
9
9
  context.writer.debug(`Deploying worker from: ${absPath}`);
10
10
  const client = context.apiClient;
11
11
  let uploadUrl;
12
12
  let uploadFields;
13
13
  let workerId;
14
- context.writer.writeErr(
15
- workerIdForUpdate ? `Updating worker...` : `Creating worker...`
16
- );
17
- if (workerIdForUpdate) {
18
- workerId = workerIdForUpdate;
19
- const updateResult = await client.updateWorkerBundle(workerIdForUpdate);
14
+ if ("workerId" in options) {
15
+ context.writer.writeErr(`Updating worker...`);
16
+ workerId = options.workerId;
17
+ const updateResult = await client.updateWorkerBundle(workerId);
20
18
  if (Result.isSuccess(updateResult)) {
21
19
  const res = Result.unwrap(updateResult);
22
20
  uploadUrl = res.url;
@@ -28,7 +26,8 @@ async function deployWorker(context, options) {
28
26
  throw new Error(updateResult.error.message);
29
27
  }
30
28
  } else {
31
- const createResult = await client.createWorker("tmp-give-me-a-good-name");
29
+ context.writer.writeErr(`Creating worker...`);
30
+ const createResult = await client.createWorker(options.name);
32
31
  if (Result.isSuccess(createResult)) {
33
32
  const res = Result.unwrap(createResult);
34
33
  uploadUrl = res.url;
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@project-ajax/sdk",
3
- "version": "0.0.30",
3
+ "version": "0.0.32",
4
4
  "description": "An SDK for building workers for the Project Ajax platform",
5
5
  "license": "UNLICENSED",
6
6
  "type": "module",
@@ -74,6 +74,7 @@
74
74
  "@stricli/core": "^1.2.4",
75
75
  "@visulima/tabular": "^3.1.1",
76
76
  "ajv": "^8.17.1",
77
- "esbuild": "^0.25.12"
77
+ "esbuild": "^0.25.12",
78
+ "prompts": "^2.4.2"
78
79
  }
79
80
  }
@@ -128,6 +128,8 @@ export function tool<I extends JSONValue, O extends JSONValue = JSONValue>(
128
128
  };
129
129
  }
130
130
 
131
+ process.stdout.write(`\n<output>${JSON.stringify(result)}</output>\n`);
132
+
131
133
  return {
132
134
  _tag: "success" as const,
133
135
  value: result,
@@ -1,8 +1,14 @@
1
+ import prompts from "prompts";
2
+ import type { ApiError } from "../api/client.js";
1
3
  import { Result } from "../api/result.js";
2
4
  import { deployWorker } from "../deploy.js";
3
5
  import { buildAuthedHandler } from "../handler.js";
4
6
 
5
- export const deploy = buildAuthedHandler(async function () {
7
+ interface DeployFlags {
8
+ name?: string;
9
+ }
10
+
11
+ export const deploy = buildAuthedHandler(async function (flags: DeployFlags) {
6
12
  const { token } = this.config.tokenInfo;
7
13
  const workerId = this.config.workerId;
8
14
 
@@ -15,12 +21,50 @@ export const deploy = buildAuthedHandler(async function () {
15
21
 
16
22
  this.writer.writeErr("Deploying worker...");
17
23
 
18
- const result = await deployWorker(this, {
19
- workerPath,
20
- workerId,
21
- token,
22
- environment,
23
- });
24
+ const name = flags.name;
25
+ if (workerId && name) {
26
+ throw new Error("Cannot specify a name when updating an existing worker");
27
+ }
28
+
29
+ let result: Result<{ workerId: string }, ApiError>;
30
+ if (workerId) {
31
+ result = await deployWorker(this, {
32
+ workerPath,
33
+ workerId,
34
+ token,
35
+ environment,
36
+ });
37
+ } else {
38
+ let validatedName: string;
39
+ if (name) {
40
+ validatedName = name;
41
+ } else {
42
+ const { name: nameInput } = await prompts({
43
+ type: "text",
44
+ name: "name",
45
+ message: "Enter a name for the worker",
46
+ validate: (value) => {
47
+ if (value.length < 1) {
48
+ return "Name is required";
49
+ }
50
+ return true;
51
+ },
52
+ });
53
+
54
+ if (!nameInput?.trim()) {
55
+ throw new Error("Name is required");
56
+ }
57
+
58
+ validatedName = nameInput.trim();
59
+ }
60
+
61
+ result = await deployWorker(this, {
62
+ name: validatedName,
63
+ workerPath,
64
+ token,
65
+ environment,
66
+ });
67
+ }
24
68
 
25
69
  if (Result.isSuccess(result)) {
26
70
  const { workerId } = Result.unwrap(result);
@@ -9,6 +9,12 @@ export default buildCommand({
9
9
  parameters: {
10
10
  flags: {
11
11
  ...globalFlags,
12
+ name: {
13
+ kind: "parsed",
14
+ parse: String,
15
+ brief: "The name of the worker (if it has not yet been created)",
16
+ optional: true,
17
+ },
12
18
  },
13
19
  },
14
20
 
package/src/cli/deploy.ts CHANGED
@@ -9,7 +9,7 @@ import { Result } from "./api/result.js";
9
9
  import type { LocalContext } from "./context.js";
10
10
  import type { AuthedContext } from "./handler.js";
11
11
 
12
- export interface DeployOptions {
12
+ export interface BaseDeployOptions {
13
13
  /**
14
14
  * Path to the worker directory to deploy
15
15
  */
@@ -24,10 +24,24 @@ export interface DeployOptions {
24
24
  * Environment to deploy to
25
25
  */
26
26
  environment: Environment;
27
+ }
27
28
 
28
- workerId?: string | null;
29
+ export interface CreateDeployOptions extends BaseDeployOptions {
30
+ /**
31
+ * Name of the worker (if it has not yet been created)
32
+ */
33
+ name: string;
29
34
  }
30
35
 
36
+ export interface UpdateDeployOptions extends BaseDeployOptions {
37
+ /**
38
+ * ID of the worker to update
39
+ */
40
+ workerId: string;
41
+ }
42
+
43
+ export type DeployOptions = CreateDeployOptions | UpdateDeployOptions;
44
+
31
45
  /**
32
46
  * Deploy a worker to the specified environment
33
47
  */
@@ -35,7 +49,7 @@ export async function deployWorker(
35
49
  context: AuthedContext,
36
50
  options: DeployOptions,
37
51
  ): Promise<Result<{ workerId: string }, ApiError>> {
38
- const { workerPath, workerId: workerIdForUpdate } = options;
52
+ const { workerPath } = options;
39
53
 
40
54
  // Resolve absolute path
41
55
  const absPath = path.resolve(process.cwd(), workerPath);
@@ -48,13 +62,12 @@ export async function deployWorker(
48
62
  let uploadFields: Record<string, string>;
49
63
  let workerId: string;
50
64
 
51
- context.writer.writeErr(
52
- workerIdForUpdate ? `Updating worker...` : `Creating worker...`,
53
- );
65
+ if ("workerId" in options) {
66
+ context.writer.writeErr(`Updating worker...`);
54
67
 
55
- if (workerIdForUpdate) {
56
- workerId = workerIdForUpdate;
57
- const updateResult = await client.updateWorkerBundle(workerIdForUpdate);
68
+ workerId = options.workerId;
69
+
70
+ const updateResult = await client.updateWorkerBundle(workerId);
58
71
  if (Result.isSuccess(updateResult)) {
59
72
  const res = Result.unwrap(updateResult);
60
73
  uploadUrl = res.url;
@@ -66,7 +79,9 @@ export async function deployWorker(
66
79
  throw new Error(updateResult.error.message);
67
80
  }
68
81
  } else {
69
- const createResult = await client.createWorker("tmp-give-me-a-good-name");
82
+ context.writer.writeErr(`Creating worker...`);
83
+
84
+ const createResult = await client.createWorker(options.name);
70
85
  if (Result.isSuccess(createResult)) {
71
86
  const res = Result.unwrap(createResult);
72
87
  uploadUrl = res.url;