wrangler 0.0.0-e33294b0 → 0.0.0-e351afcf

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 (127) hide show
  1. package/bin/wrangler.js +1 -1
  2. package/miniflare-dist/index.mjs +183 -92
  3. package/package.json +15 -10
  4. package/src/__tests__/api-devregistry.test.ts +121 -0
  5. package/src/__tests__/api.test.ts +27 -5
  6. package/src/__tests__/configuration.test.ts +294 -18
  7. package/src/__tests__/constellation.test.ts +371 -0
  8. package/src/__tests__/d1/execute.test.ts +3 -1
  9. package/src/__tests__/d1/migrate.test.ts +102 -0
  10. package/src/__tests__/delete.test.ts +6 -0
  11. package/src/__tests__/deployments.test.ts +335 -95
  12. package/src/__tests__/dev.test.tsx +87 -57
  13. package/src/__tests__/generate.test.ts +3 -4
  14. package/src/__tests__/guess-worker-format.test.ts +35 -0
  15. package/src/__tests__/helpers/mock-console.ts +6 -0
  16. package/src/__tests__/helpers/msw/handlers/deployments.ts +70 -3
  17. package/src/__tests__/helpers/msw/index.ts +4 -2
  18. package/src/__tests__/helpers/worker-scripts/parent-worker.js +4 -1
  19. package/src/__tests__/index.test.ts +14 -6
  20. package/src/__tests__/init.test.ts +136 -104
  21. package/src/__tests__/jest.setup.ts +4 -0
  22. package/src/__tests__/kv.test.ts +9 -9
  23. package/src/__tests__/logger.test.ts +68 -2
  24. package/src/__tests__/middleware.scheduled.test.ts +2 -2
  25. package/src/__tests__/middleware.test.ts +4 -3
  26. package/src/__tests__/mtls-certificates.test.ts +7 -3
  27. package/src/__tests__/pages/deployment-list.test.ts +2 -0
  28. package/src/__tests__/pages/functions-build.test.ts +159 -39
  29. package/src/__tests__/pages/project-list.test.ts +2 -0
  30. package/src/__tests__/pages/project-upload.test.ts +43 -24
  31. package/src/__tests__/pages/publish.test.ts +267 -148
  32. package/src/__tests__/publish.test.ts +1040 -339
  33. package/src/__tests__/pubsub.test.ts +3 -0
  34. package/src/__tests__/queues.test.ts +5 -2
  35. package/src/__tests__/test-old-node-version.js +3 -3
  36. package/src/__tests__/traverse-module-graph.test.ts +220 -0
  37. package/src/__tests__/tsconfig.tsbuildinfo +1 -1
  38. package/src/__tests__/type-generation.test.ts +1 -0
  39. package/src/__tests__/user.test.ts +2 -2
  40. package/src/__tests__/worker-namespace.test.ts +1 -0
  41. package/src/api/dev.ts +15 -22
  42. package/src/api/pages/create-worker-bundle-contents.ts +1 -0
  43. package/src/api/pages/publish.tsx +64 -61
  44. package/src/bundle.ts +51 -16
  45. package/src/config/environment.ts +36 -4
  46. package/src/config/index.ts +30 -2
  47. package/src/config/validation-helpers.ts +1 -1
  48. package/src/config/validation.ts +149 -5
  49. package/src/constellation/createProject.tsx +51 -0
  50. package/src/constellation/deleteProject.ts +51 -0
  51. package/src/constellation/deleteProjectModel.ts +68 -0
  52. package/src/constellation/index.ts +75 -0
  53. package/src/constellation/listCatalog.tsx +35 -0
  54. package/src/constellation/listModel.tsx +41 -0
  55. package/src/constellation/listProject.tsx +28 -0
  56. package/src/constellation/listRuntime.tsx +28 -0
  57. package/src/constellation/options.ts +17 -0
  58. package/src/constellation/types.ts +17 -0
  59. package/src/constellation/uploadModel.tsx +64 -0
  60. package/src/constellation/utils.ts +90 -0
  61. package/src/create-worker-preview.ts +19 -8
  62. package/src/create-worker-upload-form.ts +28 -3
  63. package/src/d1/backups.tsx +19 -15
  64. package/src/d1/create.tsx +45 -39
  65. package/src/d1/delete.ts +1 -1
  66. package/src/d1/execute.tsx +23 -20
  67. package/src/d1/list.tsx +14 -12
  68. package/src/d1/migrations/apply.tsx +36 -30
  69. package/src/d1/migrations/create.tsx +15 -12
  70. package/src/d1/migrations/helpers.ts +5 -8
  71. package/src/d1/migrations/list.tsx +10 -7
  72. package/src/deployments.ts +260 -8
  73. package/src/dev/dev.tsx +6 -4
  74. package/src/dev/local.tsx +65 -40
  75. package/src/dev/start-server.ts +57 -52
  76. package/src/dev/use-esbuild.ts +59 -52
  77. package/src/dev/validate-dev-props.ts +9 -0
  78. package/src/dev-registry.ts +2 -1
  79. package/src/dev.tsx +38 -18
  80. package/src/docs/helpers.ts +50 -0
  81. package/src/docs/index.ts +25 -68
  82. package/src/entry.ts +19 -9
  83. package/src/environment-variables/factory.ts +2 -1
  84. package/src/generate/index.ts +2 -2
  85. package/src/index.ts +87 -24
  86. package/src/init.ts +144 -134
  87. package/src/inspect.ts +16 -1
  88. package/src/kv/helpers.ts +7 -4
  89. package/src/logger.ts +23 -4
  90. package/src/metrics/send-event.ts +2 -1
  91. package/src/miniflare-cli/assets.ts +8 -7
  92. package/src/miniflare-cli/index.ts +3 -3
  93. package/src/miniflare-cli/tsconfig.tsbuildinfo +1 -1
  94. package/src/module-collection.ts +92 -26
  95. package/src/pages/build.ts +290 -100
  96. package/src/pages/buildFunctions.ts +20 -10
  97. package/src/pages/deployments.tsx +3 -5
  98. package/src/pages/dev.ts +44 -26
  99. package/src/pages/errors.ts +1 -0
  100. package/src/pages/functions/buildPlugin.ts +57 -34
  101. package/src/pages/functions/buildWorker.ts +91 -31
  102. package/src/pages/functions/tsconfig.tsbuildinfo +1 -1
  103. package/src/pages/projects.tsx +2 -5
  104. package/src/pages/publish.tsx +1 -10
  105. package/src/pages/upload.tsx +29 -9
  106. package/src/paths.ts +1 -1
  107. package/src/publish/index.ts +1 -1
  108. package/src/publish/publish.ts +29 -34
  109. package/src/queues/cli/commands/consumer/add.ts +6 -0
  110. package/src/queues/client.ts +1 -0
  111. package/src/r2/helpers.ts +1 -0
  112. package/src/secret/index.ts +2 -1
  113. package/src/sites.ts +164 -52
  114. package/src/traverse-module-graph.ts +53 -0
  115. package/src/type-generation.ts +1 -1
  116. package/src/user/user.ts +2 -1
  117. package/src/utils/render.ts +93 -0
  118. package/src/worker.ts +18 -1
  119. package/templates/d1-beta-facade.js +5 -2
  120. package/templates/gitignore +1 -0
  121. package/templates/middleware/middleware-miniflare3-json-error.ts +17 -5
  122. package/templates/pages-template-plugin.ts +7 -3
  123. package/templates/tsconfig.init.json +1 -2
  124. package/templates/tsconfig.tsbuildinfo +1 -1
  125. package/wrangler-dist/cli.d.ts +552 -16
  126. package/wrangler-dist/cli.js +32141 -24052
  127. package/src/__tests__/api-devregistry.test.js +0 -64
@@ -97,6 +97,7 @@ export function printBindings(bindings: CfWorkerInit["bindings"]) {
97
97
  data_blobs,
98
98
  durable_objects,
99
99
  kv_namespaces,
100
+ send_email,
100
101
  queues,
101
102
  d1_databases,
102
103
  r2_buckets,
@@ -155,6 +156,23 @@ export function printBindings(bindings: CfWorkerInit["bindings"]) {
155
156
  });
156
157
  }
157
158
 
159
+ if (send_email !== undefined && send_email.length > 0) {
160
+ output.push({
161
+ type: "Send Email",
162
+ entries: send_email.map(
163
+ ({ name, destination_address, allowed_destination_addresses }) => {
164
+ return {
165
+ key: name,
166
+ value:
167
+ destination_address ||
168
+ allowed_destination_addresses?.join(", ") ||
169
+ "unrestricted",
170
+ };
171
+ }
172
+ ),
173
+ });
174
+ }
175
+
158
176
  if (queues !== undefined && queues.length > 0) {
159
177
  output.push({
160
178
  type: "Queues",
@@ -255,10 +273,10 @@ export function printBindings(bindings: CfWorkerInit["bindings"]) {
255
273
  });
256
274
  }
257
275
 
258
- if (unsafe !== undefined && unsafe.length > 0) {
276
+ if (unsafe?.bindings !== undefined && unsafe.bindings.length > 0) {
259
277
  output.push({
260
278
  type: "Unsafe",
261
- entries: unsafe.map(({ name, type }) => ({
279
+ entries: unsafe.bindings.map(({ name, type }) => ({
262
280
  key: type,
263
281
  value: name,
264
282
  })),
@@ -319,6 +337,16 @@ export function printBindings(bindings: CfWorkerInit["bindings"]) {
319
337
  });
320
338
  }
321
339
 
340
+ if (unsafe?.metadata !== undefined) {
341
+ output.push({
342
+ type: "Unsafe Metadata",
343
+ entries: Object.entries(unsafe.metadata).map(([key, value]) => ({
344
+ key,
345
+ value: `${value}`,
346
+ })),
347
+ });
348
+ }
349
+
322
350
  if (output.length === 0) {
323
351
  return;
324
352
  }
@@ -550,7 +550,7 @@ export const getBindingNames = (value: unknown): string[] => {
550
550
  } else if (isNamespaceList(value)) {
551
551
  return value.map(({ binding }) => binding);
552
552
  } else if (isRecord(value)) {
553
- return Object.keys(value);
553
+ return Object.keys(value).filter((k) => value[k] !== undefined);
554
554
  } else {
555
555
  return [];
556
556
  }
@@ -358,6 +358,26 @@ function normalizeAndValidateMainField(
358
358
  }
359
359
  }
360
360
 
361
+ /**
362
+ * Validate the `base_dir` field and return the normalized values.
363
+ */
364
+ function normalizeAndValidateBaseDirField(
365
+ configPath: string | undefined,
366
+ rawDir: string | undefined
367
+ ): string | undefined {
368
+ const configDir = path.dirname(configPath ?? "wrangler.toml");
369
+ if (rawDir !== undefined) {
370
+ if (typeof rawDir === "string") {
371
+ const directory = path.resolve(configDir);
372
+ return path.resolve(directory, rawDir);
373
+ } else {
374
+ return rawDir;
375
+ }
376
+ } else {
377
+ return;
378
+ }
379
+ }
380
+
361
381
  /**
362
382
  * Validate the `dev` configuration and return the normalized values.
363
383
  */
@@ -1011,6 +1031,17 @@ function normalizeAndValidateEnvironment(
1011
1031
  ),
1012
1032
  deprecatedUpload
1013
1033
  ),
1034
+ base_dir: normalizeAndValidateBaseDirField(
1035
+ configPath,
1036
+ inheritable(
1037
+ diagnostics,
1038
+ topLevelEnv,
1039
+ rawEnv,
1040
+ "base_dir",
1041
+ isString,
1042
+ undefined
1043
+ )
1044
+ ),
1014
1045
  route,
1015
1046
  routes,
1016
1047
  triggers: inheritable(
@@ -1074,6 +1105,16 @@ function normalizeAndValidateEnvironment(
1074
1105
  validateBindingArray(envName, validateKVBinding),
1075
1106
  []
1076
1107
  ),
1108
+ send_email: notInheritable(
1109
+ diagnostics,
1110
+ topLevelEnv,
1111
+ rawConfig,
1112
+ rawEnv,
1113
+ envName,
1114
+ "send_email",
1115
+ validateBindingArray(envName, validateSendEmailBinding),
1116
+ []
1117
+ ),
1077
1118
  queues: notInheritable(
1078
1119
  diagnostics,
1079
1120
  topLevelEnv,
@@ -1162,10 +1203,8 @@ function normalizeAndValidateEnvironment(
1162
1203
  rawEnv,
1163
1204
  envName,
1164
1205
  "unsafe",
1165
- validateBindingsProperty(envName, validateUnsafeBinding),
1166
- {
1167
- bindings: [],
1168
- }
1206
+ validateUnsafeSettings(envName),
1207
+ {}
1169
1208
  ),
1170
1209
  zone_id: rawEnv.zone_id,
1171
1210
  no_bundle: inheritable(
@@ -1495,6 +1534,62 @@ const validateBindingsProperty =
1495
1534
  return isValid;
1496
1535
  };
1497
1536
 
1537
+ const validateUnsafeSettings =
1538
+ (envName: string): ValidatorFn =>
1539
+ (diagnostics, field, value, config) => {
1540
+ const fieldPath =
1541
+ config === undefined ? `${field}` : `env.${envName}.${field}`;
1542
+
1543
+ if (typeof value !== "object" || value === null || Array.isArray(value)) {
1544
+ diagnostics.errors.push(
1545
+ `The field "${fieldPath}" should be an object but got ${JSON.stringify(
1546
+ value
1547
+ )}.`
1548
+ );
1549
+ return false;
1550
+ }
1551
+
1552
+ // At least one of bindings and metadata must exist
1553
+ if (!hasProperty(value, "bindings") && !hasProperty(value, "metadata")) {
1554
+ diagnostics.errors.push(
1555
+ `The field "${fieldPath}" should contain at least one of "bindings" or "metadata" properties but got ${JSON.stringify(
1556
+ value
1557
+ )}.`
1558
+ );
1559
+ return false;
1560
+ }
1561
+
1562
+ // unsafe.bindings
1563
+ if (hasProperty(value, "bindings") && value.bindings !== undefined) {
1564
+ const validateBindingsFn = validateBindingsProperty(
1565
+ envName,
1566
+ validateUnsafeBinding
1567
+ );
1568
+ const valid = validateBindingsFn(diagnostics, field, value, config);
1569
+ if (!valid) {
1570
+ return false;
1571
+ }
1572
+ }
1573
+
1574
+ // unsafe.metadata
1575
+ if (
1576
+ hasProperty(value, "metadata") &&
1577
+ value.metadata !== undefined &&
1578
+ (typeof value.metadata !== "object" ||
1579
+ value.metadata === null ||
1580
+ Array.isArray(value.metadata))
1581
+ ) {
1582
+ diagnostics.errors.push(
1583
+ `The field "${fieldPath}.metadata" should be an object but got ${JSON.stringify(
1584
+ value.metadata
1585
+ )}.`
1586
+ );
1587
+ return false;
1588
+ }
1589
+
1590
+ return true;
1591
+ };
1592
+
1498
1593
  /**
1499
1594
  * Check that the given field is a valid "durable_object" binding object.
1500
1595
  */
@@ -1711,6 +1806,53 @@ const validateKVBinding: ValidatorFn = (diagnostics, field, value) => {
1711
1806
  return isValid;
1712
1807
  };
1713
1808
 
1809
+ const validateSendEmailBinding: ValidatorFn = (diagnostics, field, value) => {
1810
+ if (typeof value !== "object" || value === null) {
1811
+ diagnostics.errors.push(
1812
+ `"send_email" bindings should be objects, but got ${JSON.stringify(
1813
+ value
1814
+ )}`
1815
+ );
1816
+ return false;
1817
+ }
1818
+ let isValid = true;
1819
+ // send email bindings must have a name.
1820
+ if (!isRequiredProperty(value, "name", "string")) {
1821
+ diagnostics.errors.push(
1822
+ `"${field}" bindings should have a string "name" field but got ${JSON.stringify(
1823
+ value
1824
+ )}.`
1825
+ );
1826
+ isValid = false;
1827
+ }
1828
+ if (!isOptionalProperty(value, "destination_address", "string")) {
1829
+ diagnostics.errors.push(
1830
+ `"${field}" bindings should, optionally, have a string "destination_address" field but got ${JSON.stringify(
1831
+ value
1832
+ )}.`
1833
+ );
1834
+ isValid = false;
1835
+ }
1836
+ if (!isOptionalProperty(value, "allowed_destination_addresses", "object")) {
1837
+ diagnostics.errors.push(
1838
+ `"${field}" bindings should, optionally, have a []string "allowed_destination_addresses" field but got ${JSON.stringify(
1839
+ value
1840
+ )}.`
1841
+ );
1842
+ isValid = false;
1843
+ }
1844
+ if (
1845
+ "destination_address" in value &&
1846
+ "allowed_destination_addresses" in value
1847
+ ) {
1848
+ diagnostics.errors.push(
1849
+ `"${field}" bindings should have either a "destination_address" or "allowed_destination_addresses" field, but not both.`
1850
+ );
1851
+ isValid = false;
1852
+ }
1853
+ return isValid;
1854
+ };
1855
+
1714
1856
  const validateQueueBinding: ValidatorFn = (diagnostics, field, value) => {
1715
1857
  if (typeof value !== "object" || value === null) {
1716
1858
  diagnostics.errors.push(
@@ -2161,6 +2303,7 @@ const validateConsumer: ValidatorFn = (diagnostics, field, value, _config) => {
2161
2303
  "max_batch_timeout",
2162
2304
  "max_retries",
2163
2305
  "dead_letter_queue",
2306
+ "max_concurrency",
2164
2307
  ])
2165
2308
  ) {
2166
2309
  isValid = false;
@@ -2176,12 +2319,13 @@ const validateConsumer: ValidatorFn = (diagnostics, field, value, _config) => {
2176
2319
 
2177
2320
  const options: {
2178
2321
  key: string;
2179
- type: "number" | "string";
2322
+ type: "number" | "string" | "boolean";
2180
2323
  }[] = [
2181
2324
  { key: "max_batch_size", type: "number" },
2182
2325
  { key: "max_batch_timeout", type: "number" },
2183
2326
  { key: "max_retries", type: "number" },
2184
2327
  { key: "dead_letter_queue", type: "string" },
2328
+ { key: "max_concurrency", type: "number" },
2185
2329
  ];
2186
2330
  for (const optionalOpt of options) {
2187
2331
  if (!isOptionalProperty(value, optionalOpt.key, optionalOpt.type)) {
@@ -0,0 +1,51 @@
1
+ import { fetchResult } from "../cfetch";
2
+ import { withConfig } from "../config";
3
+ import { logger } from "../logger";
4
+ import { requireAuth } from "../user";
5
+ import { takeName } from "./options";
6
+ import { constellationBetaWarning } from "./utils";
7
+ import type {
8
+ CommonYargsArgv,
9
+ StrictYargsOptionsToInterface,
10
+ } from "../yargs-types";
11
+ import type { Project } from "./types";
12
+
13
+ export function options(yargs: CommonYargsArgv) {
14
+ return takeName(yargs)
15
+ .positional("runtime", {
16
+ describe: "The name of the runtime to use",
17
+ type: "string",
18
+ demandOption: true,
19
+ })
20
+ .epilogue(constellationBetaWarning);
21
+ }
22
+
23
+ type HandlerOptions = StrictYargsOptionsToInterface<typeof options>;
24
+ export const handler = withConfig<HandlerOptions>(
25
+ async ({ name, runtime, config }): Promise<void> => {
26
+ const accountId = await requireAuth(config);
27
+
28
+ logger.log(constellationBetaWarning);
29
+
30
+ let proj: Project;
31
+ try {
32
+ proj = await fetchResult(`/accounts/${accountId}/constellation/project`, {
33
+ method: "POST",
34
+ headers: {
35
+ "Content-Type": "application/json",
36
+ },
37
+ body: JSON.stringify({
38
+ name,
39
+ runtime,
40
+ }),
41
+ });
42
+ } catch (e) {
43
+ if ((e as { code: number }).code === 7409) {
44
+ throw new Error("A project with that name already exists");
45
+ }
46
+ throw e;
47
+ }
48
+
49
+ logger.log(`✅ Successfully created Project "${proj.name}"!`);
50
+ }
51
+ );
@@ -0,0 +1,51 @@
1
+ import { fetchResult } from "../cfetch";
2
+ import { withConfig } from "../config";
3
+ import { confirm } from "../dialogs";
4
+ import { logger } from "../logger";
5
+ import { requireAuth } from "../user";
6
+ import { takeName } from "./options";
7
+ import { constellationBetaWarning, getProjectByName } from "./utils";
8
+ import type {
9
+ CommonYargsArgv,
10
+ StrictYargsOptionsToInterface,
11
+ } from "../yargs-types";
12
+
13
+ export function options(yargs: CommonYargsArgv) {
14
+ return takeName(yargs)
15
+ .option("force", {
16
+ describe: "Skip confirmation",
17
+ type: "boolean",
18
+ alias: "f",
19
+ default: false,
20
+ })
21
+ .epilogue(constellationBetaWarning);
22
+ }
23
+ type HandlerOptions = StrictYargsOptionsToInterface<typeof options>;
24
+ export const handler = withConfig<HandlerOptions>(
25
+ async ({ name, force, config }): Promise<void> => {
26
+ const accountId = await requireAuth(config);
27
+ logger.log(constellationBetaWarning);
28
+
29
+ const proj = await getProjectByName(config, accountId, name);
30
+
31
+ logger.log(`About to delete Project '${name}' (${proj.id}).`);
32
+ if (!force) {
33
+ const response = await confirm(`Ok to proceed?`);
34
+ if (!response) {
35
+ logger.log(`Not deleting.`);
36
+ return;
37
+ }
38
+
39
+ logger.log("Deleting...");
40
+ }
41
+
42
+ await fetchResult(
43
+ `/accounts/${accountId}/constellation/project/${proj.id}`,
44
+ {
45
+ method: "DELETE",
46
+ }
47
+ );
48
+
49
+ logger.log(`Deleted '${name}' successfully.`);
50
+ }
51
+ );
@@ -0,0 +1,68 @@
1
+ import { fetchResult } from "../cfetch";
2
+ import { withConfig } from "../config";
3
+ import { confirm } from "../dialogs";
4
+ import { logger } from "../logger";
5
+ import { requireAuth } from "../user";
6
+ import { takeName } from "./options";
7
+ import {
8
+ constellationBetaWarning,
9
+ getProjectByName,
10
+ getProjectModelByName,
11
+ } from "./utils";
12
+ import type {
13
+ CommonYargsArgv,
14
+ StrictYargsOptionsToInterface,
15
+ } from "../yargs-types";
16
+ import type { Project, Model } from "./types";
17
+
18
+ export function options(yargs: CommonYargsArgv) {
19
+ return takeName(yargs)
20
+ .positional("modelName", {
21
+ describe: "The name of the uploaded model",
22
+ type: "string",
23
+ demandOption: true,
24
+ })
25
+ .option("force", {
26
+ describe: "Skip confirmation",
27
+ type: "boolean",
28
+ alias: "f",
29
+ default: false,
30
+ })
31
+ .epilogue(constellationBetaWarning);
32
+ }
33
+ type HandlerOptions = StrictYargsOptionsToInterface<typeof options>;
34
+ export const handler = withConfig<HandlerOptions>(
35
+ async ({ name, modelName, force, config }): Promise<void> => {
36
+ const accountId = await requireAuth(config);
37
+ logger.log(constellationBetaWarning);
38
+
39
+ const proj: Project = await getProjectByName(config, accountId, name);
40
+
41
+ const model: Model = await getProjectModelByName(
42
+ config,
43
+ accountId,
44
+ proj,
45
+ modelName
46
+ );
47
+
48
+ logger.log(`About to delete Model '${modelName}' (${model.id}).`);
49
+ if (!force) {
50
+ const response = await confirm(`Ok to proceed?`);
51
+ if (!response) {
52
+ logger.log(`Not deleting.`);
53
+ return;
54
+ }
55
+
56
+ logger.log("Deleting...");
57
+ }
58
+
59
+ await fetchResult(
60
+ `/accounts/${accountId}/constellation/project/${proj.id}/model/${model.id}`,
61
+ {
62
+ method: "DELETE",
63
+ }
64
+ );
65
+
66
+ logger.log(`Deleted '${modelName}' successfully.`);
67
+ }
68
+ );
@@ -0,0 +1,75 @@
1
+ import * as CreateProject from "./createProject";
2
+ import * as DeleteProject from "./deleteProject";
3
+ import * as DeleteProjectModel from "./deleteProjectModel";
4
+ import * as ListCatalog from "./listCatalog";
5
+ import * as ListModel from "./listModel";
6
+ import * as ListProject from "./listProject";
7
+ import * as ListRuntime from "./listRuntime";
8
+ import * as UploadModel from "./uploadModel";
9
+ import type { CommonYargsArgv } from "../yargs-types";
10
+
11
+ export function constellation(yargs: CommonYargsArgv) {
12
+ return yargs
13
+ .command("project", "Manage your projects", (constProjYargs) => {
14
+ return constProjYargs
15
+ .command(
16
+ "list",
17
+ "List your projects",
18
+ ListProject.options,
19
+ ListProject.handler
20
+ )
21
+ .command(
22
+ "create <name> <runtime>",
23
+ "Create project",
24
+ CreateProject.options,
25
+ CreateProject.handler
26
+ )
27
+ .command(
28
+ "delete <name>",
29
+ "Delete project",
30
+ DeleteProject.options,
31
+ DeleteProject.handler
32
+ );
33
+ })
34
+ .command("model", "Manage your models", (constModelYargs) => {
35
+ return constModelYargs
36
+ .command(
37
+ "upload <name> <modelName> <modelFile>",
38
+ "Upload a model for an existing project",
39
+ UploadModel.options,
40
+ UploadModel.handler
41
+ )
42
+ .command(
43
+ "list <name>",
44
+ "List models of a project",
45
+ ListModel.options,
46
+ ListModel.handler
47
+ )
48
+ .command(
49
+ "delete <name> <modelName>",
50
+ "Delete a model of a project",
51
+ DeleteProjectModel.options,
52
+ DeleteProjectModel.handler
53
+ );
54
+ })
55
+ .command(
56
+ "catalog",
57
+ "Check the curated model catalog",
58
+ (constCatalogYargs) => {
59
+ return constCatalogYargs.command(
60
+ "list",
61
+ "List catalog models",
62
+ ListCatalog.options,
63
+ ListCatalog.handler
64
+ );
65
+ }
66
+ )
67
+ .command("runtime", "Check the suported runtimes", (constRuntimeYargs) => {
68
+ return constRuntimeYargs.command(
69
+ "list",
70
+ "List suported runtimes",
71
+ ListRuntime.options,
72
+ ListRuntime.handler
73
+ );
74
+ });
75
+ }
@@ -0,0 +1,35 @@
1
+ import { withConfig } from "../config";
2
+ import { logger } from "../logger";
3
+ import { requireAuth } from "../user";
4
+ import { asJson } from "./options";
5
+ import { constellationBetaWarning, listCatalogEntries } from "./utils";
6
+ import type {
7
+ CommonYargsArgv,
8
+ StrictYargsOptionsToInterface,
9
+ } from "../yargs-types";
10
+
11
+ export function options(yargs: CommonYargsArgv) {
12
+ return asJson(yargs).epilogue(constellationBetaWarning);
13
+ }
14
+
15
+ type HandlerOptions = StrictYargsOptionsToInterface<typeof options>;
16
+ export const handler = withConfig<HandlerOptions>(
17
+ async ({ json, config }): Promise<void> => {
18
+ const accountId = await requireAuth(config);
19
+ const entries = await listCatalogEntries(accountId);
20
+
21
+ if (json) {
22
+ logger.log(JSON.stringify(entries, null, 2));
23
+ } else {
24
+ logger.log(constellationBetaWarning);
25
+ logger.table(
26
+ entries.map((entry) => ({
27
+ project_id: entry.project.id,
28
+ project_name: entry.project.name,
29
+ project_runtime: entry.project.runtime,
30
+ models: entry.models.map((model) => model.name).join(","),
31
+ }))
32
+ );
33
+ }
34
+ }
35
+ );
@@ -0,0 +1,41 @@
1
+ import { withConfig } from "../config";
2
+ import { logger } from "../logger";
3
+ import { requireAuth } from "../user";
4
+ import { takeName } from "./options";
5
+ import {
6
+ constellationBetaWarning,
7
+ getProjectByName,
8
+ listModels,
9
+ } from "./utils";
10
+ import type {
11
+ CommonYargsArgv,
12
+ StrictYargsOptionsToInterface,
13
+ } from "../yargs-types";
14
+ import type { Project } from "./types";
15
+
16
+ export function options(yargs: CommonYargsArgv) {
17
+ return takeName(yargs)
18
+ .option("json", {
19
+ describe: "return output as clean JSON",
20
+ type: "boolean",
21
+ default: false,
22
+ })
23
+ .epilogue(constellationBetaWarning);
24
+ }
25
+
26
+ type HandlerOptions = StrictYargsOptionsToInterface<typeof options>;
27
+ export const handler = withConfig<HandlerOptions>(
28
+ async ({ name, json, config }): Promise<void> => {
29
+ const accountId = await requireAuth(config);
30
+ const proj: Project = await getProjectByName(config, accountId, name);
31
+
32
+ const models = await listModels(accountId, proj);
33
+
34
+ if (json) {
35
+ logger.log(JSON.stringify(models, null, 2));
36
+ } else {
37
+ logger.log(constellationBetaWarning);
38
+ logger.table(models);
39
+ }
40
+ }
41
+ );
@@ -0,0 +1,28 @@
1
+ import { withConfig } from "../config";
2
+ import { logger } from "../logger";
3
+ import { requireAuth } from "../user";
4
+ import { asJson } from "./options";
5
+ import { constellationBetaWarning, listProjects } from "./utils";
6
+ import type {
7
+ CommonYargsArgv,
8
+ StrictYargsOptionsToInterface,
9
+ } from "../yargs-types";
10
+
11
+ export function options(yargs: CommonYargsArgv) {
12
+ return asJson(yargs).epilogue(constellationBetaWarning);
13
+ }
14
+
15
+ type HandlerOptions = StrictYargsOptionsToInterface<typeof options>;
16
+ export const handler = withConfig<HandlerOptions>(
17
+ async ({ json, config }): Promise<void> => {
18
+ const accountId = await requireAuth(config);
19
+ const projs = await listProjects(accountId);
20
+
21
+ if (json) {
22
+ logger.log(JSON.stringify(projs, null, 2));
23
+ } else {
24
+ logger.log(constellationBetaWarning);
25
+ logger.table(projs);
26
+ }
27
+ }
28
+ );
@@ -0,0 +1,28 @@
1
+ import { withConfig } from "../config";
2
+ import { logger } from "../logger";
3
+ import { requireAuth } from "../user";
4
+ import { asJson } from "./options";
5
+ import { constellationBetaWarning, listRuntimes } from "./utils";
6
+ import type {
7
+ CommonYargsArgv,
8
+ StrictYargsOptionsToInterface,
9
+ } from "../yargs-types";
10
+
11
+ export function options(yargs: CommonYargsArgv) {
12
+ return asJson(yargs).epilogue(constellationBetaWarning);
13
+ }
14
+
15
+ type HandlerOptions = StrictYargsOptionsToInterface<typeof options>;
16
+ export const handler = withConfig<HandlerOptions>(
17
+ async ({ json, config }): Promise<void> => {
18
+ const accountId = await requireAuth(config);
19
+ const runtimes = await listRuntimes(accountId);
20
+
21
+ if (json) {
22
+ logger.log(JSON.stringify(runtimes, null, 2));
23
+ } else {
24
+ logger.log(constellationBetaWarning);
25
+ logger.table(runtimes.map((runtime) => ({ name: runtime })));
26
+ }
27
+ }
28
+ );
@@ -0,0 +1,17 @@
1
+ import type { CommonYargsArgv } from "../yargs-types";
2
+
3
+ export function takeName(yargs: CommonYargsArgv) {
4
+ return yargs.positional("name", {
5
+ describe: "The name of the project",
6
+ type: "string",
7
+ demandOption: true,
8
+ });
9
+ }
10
+
11
+ export function asJson(yargs: CommonYargsArgv) {
12
+ return yargs.option("json", {
13
+ describe: "return output as clean JSON",
14
+ type: "boolean",
15
+ default: false,
16
+ });
17
+ }