wrangler 0.0.0-e7cf0caa → 0.0.0-e87ad068
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/miniflare-dist/index.mjs +167 -93
- package/package.json +6 -6
- package/src/__tests__/configuration.test.ts +218 -0
- package/src/__tests__/constellation.test.ts +371 -0
- package/src/__tests__/d1/migrate.test.ts +100 -0
- package/src/__tests__/index.test.ts +4 -2
- package/src/__tests__/init.test.ts +109 -3
- package/src/__tests__/mtls-certificates.test.ts +2 -1
- package/src/__tests__/pages/functions-build.test.ts +77 -0
- package/src/__tests__/pages-deployment-tail.test.ts +2 -0
- package/src/__tests__/publish.test.ts +646 -187
- package/src/__tests__/tail.test.ts +49 -7
- package/src/__tests__/tsconfig.tsbuildinfo +1 -1
- package/src/__tests__/unstableDev.test.ts +61 -0
- package/src/__tests__/user.test.ts +1 -1
- package/src/api/dev.ts +12 -0
- package/src/api/pages/create-worker-bundle-contents.ts +4 -0
- package/src/api/pages/publish.tsx +28 -12
- package/src/bundle.ts +58 -14
- package/src/cfetch/internal.ts +19 -14
- package/src/config/environment.ts +41 -0
- package/src/config/index.ts +21 -0
- package/src/config/validation.ts +182 -0
- package/src/constellation/createProject.tsx +51 -0
- package/src/constellation/deleteProject.ts +51 -0
- package/src/constellation/deleteProjectModel.ts +76 -0
- package/src/constellation/index.ts +75 -0
- package/src/constellation/listCatalog.tsx +35 -0
- package/src/constellation/listModel.tsx +49 -0
- package/src/constellation/listProject.tsx +28 -0
- package/src/constellation/listRuntime.tsx +28 -0
- package/src/constellation/options.ts +17 -0
- package/src/constellation/types.ts +17 -0
- package/src/constellation/uploadModel.tsx +84 -0
- package/src/constellation/utils.ts +90 -0
- package/src/create-worker-upload-form.ts +25 -0
- package/src/d1/backups.tsx +4 -4
- package/src/d1/constants.ts +3 -0
- package/src/d1/create.tsx +77 -43
- package/src/d1/delete.ts +1 -1
- package/src/d1/execute.tsx +27 -13
- package/src/d1/list.tsx +13 -11
- package/src/d1/migrations/apply.tsx +29 -6
- package/src/d1/migrations/helpers.ts +8 -9
- package/src/d1/types.ts +7 -0
- package/src/dev/dev.tsx +9 -2
- package/src/dev/local.tsx +52 -20
- package/src/dev/remote.tsx +4 -0
- package/src/dev/start-server.ts +64 -40
- package/src/dev/use-esbuild.ts +70 -43
- package/src/dev-registry.ts +11 -0
- package/src/dev.tsx +23 -6
- package/src/docs/helpers.ts +50 -0
- package/src/docs/index.ts +25 -68
- package/src/entry.ts +8 -1
- package/src/environment-variables/factory.ts +2 -1
- package/src/generate/index.ts +5 -0
- package/src/index.ts +12 -1
- package/src/init.ts +52 -10
- package/src/inspect.ts +107 -6
- package/src/kv/helpers.ts +7 -4
- package/src/logger.ts +5 -1
- package/src/miniflare-cli/index.ts +2 -2
- package/src/miniflare-cli/tsconfig.tsbuildinfo +1 -1
- package/src/module-collection.ts +1 -1
- package/src/pages/build.ts +30 -17
- package/src/pages/dev.ts +51 -8
- package/src/pages/functions/buildPlugin.ts +1 -0
- package/src/pages/functions/buildWorker.ts +92 -2
- package/src/pages/functions/tsconfig.tsbuildinfo +1 -1
- package/src/publish/publish.ts +9 -1
- package/src/secret/index.ts +4 -0
- package/src/sites.ts +164 -52
- package/src/tail/createTail.ts +9 -0
- package/src/tail/printing.ts +12 -0
- package/src/traverse-module-graph.ts +2 -1
- package/src/type-generation.ts +6 -0
- package/src/user/user.ts +1 -0
- package/src/utils/render.ts +1 -1
- package/src/worker.ts +26 -0
- package/templates/__tests__/tsconfig.tsbuildinfo +1 -1
- package/templates/pages-dev-util.ts +4 -1
- package/templates/tsconfig.tsbuildinfo +1 -1
- package/wrangler-dist/cli.d.ts +78 -2
- package/wrangler-dist/cli.js +65057 -63883
package/src/config/validation.ts
CHANGED
|
@@ -1,5 +1,6 @@
|
|
|
1
1
|
import path from "node:path";
|
|
2
2
|
import TOML from "@iarna/toml";
|
|
3
|
+
import { getConstellationWarningFromEnv } from "../constellation/utils";
|
|
3
4
|
import { Diagnostics } from "./diagnostics";
|
|
4
5
|
import {
|
|
5
6
|
deprecated,
|
|
@@ -32,6 +33,7 @@ import type {
|
|
|
32
33
|
DeprecatedUpload,
|
|
33
34
|
Environment,
|
|
34
35
|
Rule,
|
|
36
|
+
TailConsumer,
|
|
35
37
|
} from "./environment";
|
|
36
38
|
import type { ValidatorFn } from "./validation-helpers";
|
|
37
39
|
|
|
@@ -873,6 +875,88 @@ function validateRoutes(
|
|
|
873
875
|
);
|
|
874
876
|
}
|
|
875
877
|
|
|
878
|
+
function normalizeAndValidatePlacement(
|
|
879
|
+
diagnostics: Diagnostics,
|
|
880
|
+
topLevelEnv: Environment | undefined,
|
|
881
|
+
rawEnv: RawEnvironment
|
|
882
|
+
): Config["placement"] {
|
|
883
|
+
if (rawEnv.placement) {
|
|
884
|
+
validateRequiredProperty(
|
|
885
|
+
diagnostics,
|
|
886
|
+
"placement",
|
|
887
|
+
"mode",
|
|
888
|
+
rawEnv.placement.mode,
|
|
889
|
+
"string",
|
|
890
|
+
["off", "smart"]
|
|
891
|
+
);
|
|
892
|
+
}
|
|
893
|
+
|
|
894
|
+
return inheritable(
|
|
895
|
+
diagnostics,
|
|
896
|
+
topLevelEnv,
|
|
897
|
+
rawEnv,
|
|
898
|
+
"placement",
|
|
899
|
+
() => true,
|
|
900
|
+
undefined
|
|
901
|
+
);
|
|
902
|
+
}
|
|
903
|
+
|
|
904
|
+
function validateTailConsumer(
|
|
905
|
+
diagnostics: Diagnostics,
|
|
906
|
+
field: string,
|
|
907
|
+
value: TailConsumer
|
|
908
|
+
) {
|
|
909
|
+
if (typeof value !== "object" || value === null) {
|
|
910
|
+
diagnostics.errors.push(
|
|
911
|
+
`"${field}" should be an object but got ${JSON.stringify(value)}.`
|
|
912
|
+
);
|
|
913
|
+
return false;
|
|
914
|
+
}
|
|
915
|
+
|
|
916
|
+
let isValid = true;
|
|
917
|
+
|
|
918
|
+
isValid =
|
|
919
|
+
isValid &&
|
|
920
|
+
validateRequiredProperty(
|
|
921
|
+
diagnostics,
|
|
922
|
+
field,
|
|
923
|
+
"service",
|
|
924
|
+
value.service,
|
|
925
|
+
"string"
|
|
926
|
+
);
|
|
927
|
+
isValid =
|
|
928
|
+
isValid &&
|
|
929
|
+
validateOptionalProperty(
|
|
930
|
+
diagnostics,
|
|
931
|
+
field,
|
|
932
|
+
"environment",
|
|
933
|
+
value.environment,
|
|
934
|
+
"string"
|
|
935
|
+
);
|
|
936
|
+
|
|
937
|
+
return isValid;
|
|
938
|
+
}
|
|
939
|
+
|
|
940
|
+
const validateTailConsumers: ValidatorFn = (diagnostics, field, value) => {
|
|
941
|
+
if (!value) {
|
|
942
|
+
return true;
|
|
943
|
+
}
|
|
944
|
+
if (!Array.isArray(value)) {
|
|
945
|
+
diagnostics.errors.push(
|
|
946
|
+
`Expected "${field}" to be an array but got ${JSON.stringify(value)}.`
|
|
947
|
+
);
|
|
948
|
+
return false;
|
|
949
|
+
}
|
|
950
|
+
|
|
951
|
+
let isValid = true;
|
|
952
|
+
for (let i = 0; i < value.length; i++) {
|
|
953
|
+
isValid =
|
|
954
|
+
validateTailConsumer(diagnostics, `${field}[${i}]`, value[i]) && isValid;
|
|
955
|
+
}
|
|
956
|
+
|
|
957
|
+
return isValid;
|
|
958
|
+
};
|
|
959
|
+
|
|
876
960
|
/**
|
|
877
961
|
* Validate top-level environment configuration and return the normalized values.
|
|
878
962
|
*/
|
|
@@ -1060,6 +1144,7 @@ function normalizeAndValidateEnvironment(
|
|
|
1060
1144
|
isOneOf("bundled", "unbound"),
|
|
1061
1145
|
undefined
|
|
1062
1146
|
),
|
|
1147
|
+
placement: normalizeAndValidatePlacement(diagnostics, topLevelEnv, rawEnv),
|
|
1063
1148
|
build,
|
|
1064
1149
|
workers_dev,
|
|
1065
1150
|
// Not inherited fields
|
|
@@ -1145,6 +1230,16 @@ function normalizeAndValidateEnvironment(
|
|
|
1145
1230
|
validateBindingArray(envName, validateD1Binding),
|
|
1146
1231
|
[]
|
|
1147
1232
|
),
|
|
1233
|
+
constellation: notInheritable(
|
|
1234
|
+
diagnostics,
|
|
1235
|
+
topLevelEnv,
|
|
1236
|
+
rawConfig,
|
|
1237
|
+
rawEnv,
|
|
1238
|
+
envName,
|
|
1239
|
+
"constellation",
|
|
1240
|
+
validateBindingArray(envName, validateConstellationBinding),
|
|
1241
|
+
[]
|
|
1242
|
+
),
|
|
1148
1243
|
services: notInheritable(
|
|
1149
1244
|
diagnostics,
|
|
1150
1245
|
topLevelEnv,
|
|
@@ -1185,6 +1280,16 @@ function normalizeAndValidateEnvironment(
|
|
|
1185
1280
|
validateBindingArray(envName, validateMTlsCertificateBinding),
|
|
1186
1281
|
[]
|
|
1187
1282
|
),
|
|
1283
|
+
tail_consumers: notInheritable(
|
|
1284
|
+
diagnostics,
|
|
1285
|
+
topLevelEnv,
|
|
1286
|
+
rawConfig,
|
|
1287
|
+
rawEnv,
|
|
1288
|
+
envName,
|
|
1289
|
+
"tail_consumers",
|
|
1290
|
+
validateTailConsumers,
|
|
1291
|
+
undefined
|
|
1292
|
+
),
|
|
1188
1293
|
logfwdr: inheritable(
|
|
1189
1294
|
diagnostics,
|
|
1190
1295
|
topLevelEnv,
|
|
@@ -1206,6 +1311,16 @@ function normalizeAndValidateEnvironment(
|
|
|
1206
1311
|
validateUnsafeSettings(envName),
|
|
1207
1312
|
{}
|
|
1208
1313
|
),
|
|
1314
|
+
browser: notInheritable(
|
|
1315
|
+
diagnostics,
|
|
1316
|
+
topLevelEnv,
|
|
1317
|
+
rawConfig,
|
|
1318
|
+
rawEnv,
|
|
1319
|
+
envName,
|
|
1320
|
+
"browser",
|
|
1321
|
+
validateBrowserBinding(envName),
|
|
1322
|
+
undefined
|
|
1323
|
+
),
|
|
1209
1324
|
zone_id: rawEnv.zone_id,
|
|
1210
1325
|
no_bundle: inheritable(
|
|
1211
1326
|
diagnostics,
|
|
@@ -1663,6 +1778,30 @@ const validateCflogfwdrBinding: ValidatorFn = (diagnostics, field, value) => {
|
|
|
1663
1778
|
return isValid;
|
|
1664
1779
|
};
|
|
1665
1780
|
|
|
1781
|
+
const validateBrowserBinding =
|
|
1782
|
+
(envName: string): ValidatorFn =>
|
|
1783
|
+
(diagnostics, field, value, config) => {
|
|
1784
|
+
const fieldPath =
|
|
1785
|
+
config === undefined ? `${field}` : `env.${envName}.${field}`;
|
|
1786
|
+
|
|
1787
|
+
if (typeof value !== "object" || value === null || Array.isArray(value)) {
|
|
1788
|
+
diagnostics.errors.push(
|
|
1789
|
+
`The field "${fieldPath}" should be an object but got ${JSON.stringify(
|
|
1790
|
+
value
|
|
1791
|
+
)}.`
|
|
1792
|
+
);
|
|
1793
|
+
return false;
|
|
1794
|
+
}
|
|
1795
|
+
|
|
1796
|
+
let isValid = true;
|
|
1797
|
+
if (!isRequiredProperty(value, "binding", "string")) {
|
|
1798
|
+
diagnostics.errors.push(`binding should have a string "binding" field.`);
|
|
1799
|
+
isValid = false;
|
|
1800
|
+
}
|
|
1801
|
+
|
|
1802
|
+
return isValid;
|
|
1803
|
+
};
|
|
1804
|
+
|
|
1666
1805
|
/**
|
|
1667
1806
|
* Check that the given field is a valid "unsafe" binding object.
|
|
1668
1807
|
*
|
|
@@ -1689,9 +1828,11 @@ const validateUnsafeBinding: ValidatorFn = (diagnostics, field, value) => {
|
|
|
1689
1828
|
"wasm_module",
|
|
1690
1829
|
"data_blob",
|
|
1691
1830
|
"text_blob",
|
|
1831
|
+
"browser",
|
|
1692
1832
|
"kv_namespace",
|
|
1693
1833
|
"durable_object_namespace",
|
|
1694
1834
|
"d1_database",
|
|
1835
|
+
"constellation",
|
|
1695
1836
|
"r2_bucket",
|
|
1696
1837
|
"service",
|
|
1697
1838
|
"logfwdr",
|
|
@@ -1982,6 +2123,45 @@ const validateD1Binding: ValidatorFn = (diagnostics, field, value) => {
|
|
|
1982
2123
|
return isValid;
|
|
1983
2124
|
};
|
|
1984
2125
|
|
|
2126
|
+
const validateConstellationBinding: ValidatorFn = (
|
|
2127
|
+
diagnostics,
|
|
2128
|
+
field,
|
|
2129
|
+
value
|
|
2130
|
+
) => {
|
|
2131
|
+
if (typeof value !== "object" || value === null) {
|
|
2132
|
+
diagnostics.errors.push(
|
|
2133
|
+
`"constellation" bindings should be objects, but got ${JSON.stringify(
|
|
2134
|
+
value
|
|
2135
|
+
)}`
|
|
2136
|
+
);
|
|
2137
|
+
return false;
|
|
2138
|
+
}
|
|
2139
|
+
let isValid = true;
|
|
2140
|
+
// Constellation bindings must have a binding and a project.
|
|
2141
|
+
if (!isRequiredProperty(value, "binding", "string")) {
|
|
2142
|
+
diagnostics.errors.push(
|
|
2143
|
+
`"${field}" bindings should have a string "binding" field but got ${JSON.stringify(
|
|
2144
|
+
value
|
|
2145
|
+
)}.`
|
|
2146
|
+
);
|
|
2147
|
+
isValid = false;
|
|
2148
|
+
}
|
|
2149
|
+
if (!isRequiredProperty(value, "project_id", "string")) {
|
|
2150
|
+
diagnostics.errors.push(
|
|
2151
|
+
`"${field}" bindings must have a "project_id" field but got ${JSON.stringify(
|
|
2152
|
+
value
|
|
2153
|
+
)}.`
|
|
2154
|
+
);
|
|
2155
|
+
isValid = false;
|
|
2156
|
+
}
|
|
2157
|
+
if (isValid && getConstellationWarningFromEnv() === undefined) {
|
|
2158
|
+
diagnostics.warnings.push(
|
|
2159
|
+
"Constellation Bindings are currently in beta to allow the API to evolve before general availability.\nPlease report any issues to https://github.com/cloudflare/workers-sdk/issues/new/choose\nNote: Run this command with the environment variable NO_CONSTELLATION_WARNING=true to hide this message\n\nFor example: `export NO_CONSTELLATION_WARNING=true && wrangler <YOUR COMMAND HERE>`"
|
|
2160
|
+
);
|
|
2161
|
+
}
|
|
2162
|
+
return isValid;
|
|
2163
|
+
};
|
|
2164
|
+
|
|
1985
2165
|
/**
|
|
1986
2166
|
* Check that bindings whose names might conflict, don't.
|
|
1987
2167
|
*
|
|
@@ -1998,6 +2178,7 @@ const validateBindingsHaveUniqueNames = (
|
|
|
1998
2178
|
r2_buckets,
|
|
1999
2179
|
analytics_engine_datasets,
|
|
2000
2180
|
text_blobs,
|
|
2181
|
+
browser,
|
|
2001
2182
|
unsafe,
|
|
2002
2183
|
vars,
|
|
2003
2184
|
define,
|
|
@@ -2013,6 +2194,7 @@ const validateBindingsHaveUniqueNames = (
|
|
|
2013
2194
|
"R2 Bucket": getBindingNames(r2_buckets),
|
|
2014
2195
|
"Analytics Engine Dataset": getBindingNames(analytics_engine_datasets),
|
|
2015
2196
|
"Text Blob": getBindingNames(text_blobs),
|
|
2197
|
+
Browser: getBindingNames(browser),
|
|
2016
2198
|
Unsafe: getBindingNames(unsafe),
|
|
2017
2199
|
"Environment Variable": getBindingNames(vars),
|
|
2018
2200
|
Definition: getBindingNames(define),
|
|
@@ -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,76 @@
|
|
|
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 {
|
|
7
|
+
constellationBetaWarning,
|
|
8
|
+
getProjectByName,
|
|
9
|
+
getProjectModelByName,
|
|
10
|
+
} from "./utils";
|
|
11
|
+
import type {
|
|
12
|
+
CommonYargsArgv,
|
|
13
|
+
StrictYargsOptionsToInterface,
|
|
14
|
+
} from "../yargs-types";
|
|
15
|
+
import type { Project, Model } from "./types";
|
|
16
|
+
|
|
17
|
+
export function options(yargs: CommonYargsArgv) {
|
|
18
|
+
return yargs
|
|
19
|
+
.positional("projectName", {
|
|
20
|
+
describe: "The name of the project",
|
|
21
|
+
type: "string",
|
|
22
|
+
demandOption: true,
|
|
23
|
+
})
|
|
24
|
+
.positional("modelName", {
|
|
25
|
+
describe: "The name of the uploaded model",
|
|
26
|
+
type: "string",
|
|
27
|
+
demandOption: true,
|
|
28
|
+
})
|
|
29
|
+
.option("force", {
|
|
30
|
+
describe: "Skip confirmation",
|
|
31
|
+
type: "boolean",
|
|
32
|
+
alias: "f",
|
|
33
|
+
default: false,
|
|
34
|
+
})
|
|
35
|
+
.epilogue(constellationBetaWarning);
|
|
36
|
+
}
|
|
37
|
+
type HandlerOptions = StrictYargsOptionsToInterface<typeof options>;
|
|
38
|
+
export const handler = withConfig<HandlerOptions>(
|
|
39
|
+
async ({ projectName, modelName, force, config }): Promise<void> => {
|
|
40
|
+
const accountId = await requireAuth(config);
|
|
41
|
+
logger.log(constellationBetaWarning);
|
|
42
|
+
|
|
43
|
+
const proj: Project = await getProjectByName(
|
|
44
|
+
config,
|
|
45
|
+
accountId,
|
|
46
|
+
projectName
|
|
47
|
+
);
|
|
48
|
+
|
|
49
|
+
const model: Model = await getProjectModelByName(
|
|
50
|
+
config,
|
|
51
|
+
accountId,
|
|
52
|
+
proj,
|
|
53
|
+
modelName
|
|
54
|
+
);
|
|
55
|
+
|
|
56
|
+
logger.log(`About to delete Model '${modelName}' (${model.id}).`);
|
|
57
|
+
if (!force) {
|
|
58
|
+
const response = await confirm(`Ok to proceed?`);
|
|
59
|
+
if (!response) {
|
|
60
|
+
logger.log(`Not deleting.`);
|
|
61
|
+
return;
|
|
62
|
+
}
|
|
63
|
+
|
|
64
|
+
logger.log("Deleting...");
|
|
65
|
+
}
|
|
66
|
+
|
|
67
|
+
await fetchResult(
|
|
68
|
+
`/accounts/${accountId}/constellation/project/${proj.id}/model/${model.id}`,
|
|
69
|
+
{
|
|
70
|
+
method: "DELETE",
|
|
71
|
+
}
|
|
72
|
+
);
|
|
73
|
+
|
|
74
|
+
logger.log(`Deleted '${modelName}' successfully.`);
|
|
75
|
+
}
|
|
76
|
+
);
|
|
@@ -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 <projectName> <modelName> <modelFile>",
|
|
38
|
+
"Upload a model for an existing project",
|
|
39
|
+
UploadModel.options,
|
|
40
|
+
UploadModel.handler
|
|
41
|
+
)
|
|
42
|
+
.command(
|
|
43
|
+
"list <projectName>",
|
|
44
|
+
"List models of a project",
|
|
45
|
+
ListModel.options,
|
|
46
|
+
ListModel.handler
|
|
47
|
+
)
|
|
48
|
+
.command(
|
|
49
|
+
"delete <projectName> <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,49 @@
|
|
|
1
|
+
import { withConfig } from "../config";
|
|
2
|
+
import { logger } from "../logger";
|
|
3
|
+
import { requireAuth } from "../user";
|
|
4
|
+
import {
|
|
5
|
+
constellationBetaWarning,
|
|
6
|
+
getProjectByName,
|
|
7
|
+
listModels,
|
|
8
|
+
} from "./utils";
|
|
9
|
+
import type {
|
|
10
|
+
CommonYargsArgv,
|
|
11
|
+
StrictYargsOptionsToInterface,
|
|
12
|
+
} from "../yargs-types";
|
|
13
|
+
import type { Project } from "./types";
|
|
14
|
+
|
|
15
|
+
export function options(yargs: CommonYargsArgv) {
|
|
16
|
+
return yargs
|
|
17
|
+
.positional("projectName", {
|
|
18
|
+
describe: "The name of the project",
|
|
19
|
+
type: "string",
|
|
20
|
+
demandOption: true,
|
|
21
|
+
})
|
|
22
|
+
.option("json", {
|
|
23
|
+
describe: "return output as clean JSON",
|
|
24
|
+
type: "boolean",
|
|
25
|
+
default: false,
|
|
26
|
+
})
|
|
27
|
+
.epilogue(constellationBetaWarning);
|
|
28
|
+
}
|
|
29
|
+
|
|
30
|
+
type HandlerOptions = StrictYargsOptionsToInterface<typeof options>;
|
|
31
|
+
export const handler = withConfig<HandlerOptions>(
|
|
32
|
+
async ({ projectName, json, config }): Promise<void> => {
|
|
33
|
+
const accountId = await requireAuth(config);
|
|
34
|
+
const proj: Project = await getProjectByName(
|
|
35
|
+
config,
|
|
36
|
+
accountId,
|
|
37
|
+
projectName
|
|
38
|
+
);
|
|
39
|
+
|
|
40
|
+
const models = await listModels(accountId, proj);
|
|
41
|
+
|
|
42
|
+
if (json) {
|
|
43
|
+
logger.log(JSON.stringify(models, null, 2));
|
|
44
|
+
} else {
|
|
45
|
+
logger.log(constellationBetaWarning);
|
|
46
|
+
logger.table(models);
|
|
47
|
+
}
|
|
48
|
+
}
|
|
49
|
+
);
|
|
@@ -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
|
+
}
|
|
@@ -0,0 +1,17 @@
|
|
|
1
|
+
export type Project = {
|
|
2
|
+
id: string;
|
|
3
|
+
name: string;
|
|
4
|
+
runtime: string;
|
|
5
|
+
};
|
|
6
|
+
|
|
7
|
+
export type Model = {
|
|
8
|
+
id: string;
|
|
9
|
+
project_id: string;
|
|
10
|
+
name: string;
|
|
11
|
+
description: string;
|
|
12
|
+
};
|
|
13
|
+
|
|
14
|
+
export type CatalogEntry = {
|
|
15
|
+
project: Project;
|
|
16
|
+
models: Model[];
|
|
17
|
+
};
|