@contextual-io/cli 0.3.1 → 0.5.0
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/README.md +383 -44
- package/dist/base.d.ts +5 -1
- package/dist/base.js +19 -4
- package/dist/commands/config/add.js +2 -1
- package/dist/commands/config/current.js +2 -2
- package/dist/commands/config/delete.js +1 -1
- package/dist/commands/config/get.js +3 -4
- package/dist/commands/config/index.js +1 -1
- package/dist/commands/config/list.js +6 -6
- package/dist/commands/config/login.js +1 -1
- package/dist/commands/config/use.js +1 -1
- package/dist/commands/records/add.js +1 -1
- package/dist/commands/records/delete.js +2 -2
- package/dist/commands/records/get.js +2 -2
- package/dist/commands/records/index.js +1 -1
- package/dist/commands/records/list.d.ts +1 -0
- package/dist/commands/records/list.js +2 -1
- package/dist/commands/records/patch.d.ts +25 -0
- package/dist/commands/records/patch.js +106 -0
- package/dist/commands/records/query.js +1 -1
- package/dist/commands/records/replace.js +2 -2
- package/dist/commands/types/add.d.ts +11 -0
- package/dist/commands/types/add.js +57 -0
- package/dist/commands/types/delete.d.ts +12 -0
- package/dist/commands/types/delete.js +35 -0
- package/dist/commands/types/get.d.ts +12 -0
- package/dist/commands/types/get.js +33 -0
- package/dist/commands/types/index.d.ts +9 -0
- package/dist/commands/types/index.js +13 -0
- package/dist/commands/types/list.d.ts +20 -0
- package/dist/commands/types/list.js +129 -0
- package/dist/commands/types/replace.d.ts +13 -0
- package/dist/commands/types/replace.js +57 -0
- package/dist/models/uri.js +5 -0
- package/dist/models/user-config.d.ts +2 -2
- package/dist/models/user-config.js +2 -0
- package/dist/utils/endpoints.d.ts +1 -0
- package/dist/utils/endpoints.js +1 -0
- package/oclif.manifest.json +457 -20
- package/package.json +1 -1
package/dist/base.js
CHANGED
|
@@ -13,12 +13,25 @@ class CommandConfig {
|
|
|
13
13
|
constructor(configDir) {
|
|
14
14
|
this.configDir = configDir;
|
|
15
15
|
}
|
|
16
|
-
|
|
17
|
-
|
|
16
|
+
cleanJson(configId, { silo, tenantId }) {
|
|
17
|
+
const rv = {
|
|
18
18
|
configId,
|
|
19
|
-
silo,
|
|
20
19
|
tenantId,
|
|
21
20
|
};
|
|
21
|
+
if (silo === "prod") {
|
|
22
|
+
return rv;
|
|
23
|
+
}
|
|
24
|
+
return {
|
|
25
|
+
...rv,
|
|
26
|
+
silo,
|
|
27
|
+
};
|
|
28
|
+
}
|
|
29
|
+
cleanTable(configId, config) {
|
|
30
|
+
const { silo, ...rv } = this.cleanJson(configId, config);
|
|
31
|
+
if (silo) {
|
|
32
|
+
rv.tenantId = `[${silo}] ${rv.tenantId}`;
|
|
33
|
+
}
|
|
34
|
+
return rv;
|
|
22
35
|
}
|
|
23
36
|
async get(configId) {
|
|
24
37
|
const userConfig = this.read();
|
|
@@ -112,9 +125,11 @@ export class BaseConfigCommand extends Command {
|
|
|
112
125
|
const flattened = z.flattenError(err);
|
|
113
126
|
message = flattened.formErrors.join("\n");
|
|
114
127
|
}
|
|
128
|
+
if (!/See more help with/.test(message)) {
|
|
129
|
+
message += "\nSee more help with --help";
|
|
130
|
+
}
|
|
115
131
|
this.logToStderr(chalkStderr.red(chalkStderr.bold(" Error: ") + message));
|
|
116
132
|
this.logToStderr();
|
|
117
|
-
await this.showHelp();
|
|
118
133
|
}
|
|
119
134
|
this.exit(exitCode);
|
|
120
135
|
}
|
|
@@ -7,7 +7,7 @@ export default class ConfigAdd extends BaseConfigCommand {
|
|
|
7
7
|
static args = {
|
|
8
8
|
"config-id": Args.string({ description: "id of config", required: true }),
|
|
9
9
|
};
|
|
10
|
-
static description = "
|
|
10
|
+
static description = "Add a new config.";
|
|
11
11
|
static examples = [
|
|
12
12
|
"<%= config.bin %> <%= command.id %> some-config-id --tenant-id my-tenant",
|
|
13
13
|
];
|
|
@@ -16,6 +16,7 @@ export default class ConfigAdd extends BaseConfigCommand {
|
|
|
16
16
|
char: "s",
|
|
17
17
|
default: "prod",
|
|
18
18
|
description: "silo",
|
|
19
|
+
hidden: true,
|
|
19
20
|
options: [...Silo.options.values()],
|
|
20
21
|
}),
|
|
21
22
|
"tenant-id": Flags.string({ char: "t", description: "tenant id (if different from config id)" }),
|
|
@@ -1,7 +1,7 @@
|
|
|
1
1
|
import { BaseConfigCommand } from "../../base.js";
|
|
2
2
|
export default class ConfigCurrent extends BaseConfigCommand {
|
|
3
3
|
static args = {};
|
|
4
|
-
static description = "
|
|
4
|
+
static description = "Get the current config.";
|
|
5
5
|
static enableJsonFlag = true;
|
|
6
6
|
static examples = [
|
|
7
7
|
"<%= config.bin %> <%= command.id %>",
|
|
@@ -10,6 +10,6 @@ export default class ConfigCurrent extends BaseConfigCommand {
|
|
|
10
10
|
async run() {
|
|
11
11
|
const { config, lookup } = await this.userConfig.get();
|
|
12
12
|
this.log(lookup);
|
|
13
|
-
return this.userConfig.
|
|
13
|
+
return this.userConfig.cleanJson(lookup, config);
|
|
14
14
|
}
|
|
15
15
|
}
|
|
@@ -5,7 +5,7 @@ export default class ConfigDelete extends BaseConfigCommand {
|
|
|
5
5
|
static args = {
|
|
6
6
|
"config-id": Args.string({ description: "id of config", required: true }),
|
|
7
7
|
};
|
|
8
|
-
static description = "
|
|
8
|
+
static description = "Delete a config.";
|
|
9
9
|
static examples = [
|
|
10
10
|
"<%= config.bin %> <%= command.id %> some-config-id",
|
|
11
11
|
];
|
|
@@ -6,7 +6,7 @@ export default class ConfigGet extends BaseConfigCommand {
|
|
|
6
6
|
static args = {
|
|
7
7
|
"config-id": Args.string({ description: "id of config" }),
|
|
8
8
|
};
|
|
9
|
-
static description = "
|
|
9
|
+
static description = "Get a specific config.";
|
|
10
10
|
static enableJsonFlag = true;
|
|
11
11
|
static examples = [
|
|
12
12
|
"<%= config.bin %> <%= command.id %>",
|
|
@@ -16,10 +16,9 @@ export default class ConfigGet extends BaseConfigCommand {
|
|
|
16
16
|
async run() {
|
|
17
17
|
const configId = UrlSafeId.optional().parse(this.args["config-id"]);
|
|
18
18
|
const { config, lookup } = await this.userConfig.get(configId);
|
|
19
|
-
const rv = this.userConfig.clean(lookup, config);
|
|
20
19
|
this.log(makeTable({
|
|
21
|
-
data: [
|
|
20
|
+
data: [this.userConfig.cleanTable(lookup, config)],
|
|
22
21
|
}));
|
|
23
|
-
return
|
|
22
|
+
return this.userConfig.cleanJson(lookup, config);
|
|
24
23
|
}
|
|
25
24
|
}
|
|
@@ -1,7 +1,7 @@
|
|
|
1
1
|
import { BaseConfigCommand } from "../../base.js";
|
|
2
2
|
export default class Config extends BaseConfigCommand {
|
|
3
3
|
static args = {};
|
|
4
|
-
static description = "
|
|
4
|
+
static description = "Manage configs.";
|
|
5
5
|
static examples = [];
|
|
6
6
|
static flags = {};
|
|
7
7
|
static usage = [
|
|
@@ -3,7 +3,7 @@ import chalk from "chalk";
|
|
|
3
3
|
import { BaseConfigCommand } from "../../base.js";
|
|
4
4
|
export default class ConfigList extends BaseConfigCommand {
|
|
5
5
|
static args = {};
|
|
6
|
-
static description = "
|
|
6
|
+
static description = "List all available configs.";
|
|
7
7
|
static enableJsonFlag = true;
|
|
8
8
|
static examples = [
|
|
9
9
|
"<%= config.bin %> <%= command.id %>",
|
|
@@ -16,17 +16,17 @@ export default class ConfigList extends BaseConfigCommand {
|
|
|
16
16
|
return config;
|
|
17
17
|
return {
|
|
18
18
|
configId: chalk.bold(chalk.yellow(config.configId)),
|
|
19
|
-
silo: chalk.bold(chalk.yellow(config.silo)),
|
|
20
19
|
tenantId: chalk.bold(chalk.yellow(config.tenantId)),
|
|
21
20
|
};
|
|
22
21
|
};
|
|
23
|
-
const configs = Object.entries(userConfig.configs)
|
|
24
|
-
.map(([configId, config]) => this.userConfig.clean(configId, config));
|
|
25
22
|
this.log(makeTable({
|
|
26
|
-
data:
|
|
23
|
+
data: Object.entries(userConfig.configs)
|
|
24
|
+
.map(([configId, config]) => this.userConfig.cleanTable(configId, config))
|
|
25
|
+
.map(c => colorize(c)),
|
|
27
26
|
}));
|
|
28
27
|
return {
|
|
29
|
-
configs
|
|
28
|
+
configs: Object.entries(userConfig.configs)
|
|
29
|
+
.map(([configId, config]) => this.userConfig.cleanJson(configId, config)),
|
|
30
30
|
current: userConfig.current,
|
|
31
31
|
};
|
|
32
32
|
}
|
|
@@ -2,7 +2,7 @@ import { BaseConfigCommand } from "../../base.js";
|
|
|
2
2
|
import { codeExchange, getUserProfile } from "../../utils/auth.js";
|
|
3
3
|
export default class ConfigLogin extends BaseConfigCommand {
|
|
4
4
|
static args = {};
|
|
5
|
-
static description = "
|
|
5
|
+
static description = "Login using the current config.";
|
|
6
6
|
static examples = [
|
|
7
7
|
"<%= config.bin %> <%= command.id %>",
|
|
8
8
|
];
|
|
@@ -5,7 +5,7 @@ export default class ConfigUse extends BaseConfigCommand {
|
|
|
5
5
|
static args = {
|
|
6
6
|
"config-id": Args.string({ description: "id of config", required: true }),
|
|
7
7
|
};
|
|
8
|
-
static description = "
|
|
8
|
+
static description = "Use a config.";
|
|
9
9
|
static examples = [
|
|
10
10
|
"<%= config.bin %> <%= command.id %> some-config-id",
|
|
11
11
|
];
|
|
@@ -11,7 +11,7 @@ export default class RecordsAdd extends BaseCommand {
|
|
|
11
11
|
static args = {
|
|
12
12
|
"uri": Args.string({ description: "uri of type" }),
|
|
13
13
|
};
|
|
14
|
-
static description = "
|
|
14
|
+
static description = "Create record(s).";
|
|
15
15
|
static examples = [
|
|
16
16
|
"<%= config.bin %> <%= command.id %> native-object:my-type",
|
|
17
17
|
"<%= config.bin %> <%= command.id %> --type my-type --input-file records.json",
|
|
@@ -6,7 +6,7 @@ export default class RecordsDelete extends BaseCommand {
|
|
|
6
6
|
static args = {
|
|
7
7
|
"uri": Args.string({ description: "uri of record" }),
|
|
8
8
|
};
|
|
9
|
-
static description = "
|
|
9
|
+
static description = "Delete record(s).";
|
|
10
10
|
static examples = [
|
|
11
11
|
"<%= config.bin %> <%= command.id %> native-object:my-type/instance-1",
|
|
12
12
|
"<%= config.bin %> <%= command.id %> native-object:my-type --id instance-1",
|
|
@@ -16,7 +16,7 @@ export default class RecordsDelete extends BaseCommand {
|
|
|
16
16
|
];
|
|
17
17
|
static flags = {
|
|
18
18
|
id: Flags.string({
|
|
19
|
-
char: "
|
|
19
|
+
char: "I",
|
|
20
20
|
description: "id(s)",
|
|
21
21
|
multiple: true,
|
|
22
22
|
}),
|
|
@@ -6,7 +6,7 @@ export default class RecordsGet extends BaseCommand {
|
|
|
6
6
|
static args = {
|
|
7
7
|
"uri": Args.string({ description: "uri of record" }),
|
|
8
8
|
};
|
|
9
|
-
static description = "
|
|
9
|
+
static description = "Get a record.";
|
|
10
10
|
static examples = [
|
|
11
11
|
"<%= config.bin %> <%= command.id %> native-object:my-type/instance-1",
|
|
12
12
|
"<%= config.bin %> <%= command.id %> native-object:my-type --id instance-1",
|
|
@@ -16,7 +16,7 @@ export default class RecordsGet extends BaseCommand {
|
|
|
16
16
|
];
|
|
17
17
|
static flags = {
|
|
18
18
|
id: Flags.string({
|
|
19
|
-
char: "
|
|
19
|
+
char: "I",
|
|
20
20
|
description: "id(s)",
|
|
21
21
|
multiple: true,
|
|
22
22
|
}),
|
|
@@ -1,7 +1,7 @@
|
|
|
1
1
|
import { BaseConfigCommand } from "../../base.js";
|
|
2
2
|
export default class Records extends BaseConfigCommand {
|
|
3
3
|
static args = {};
|
|
4
|
-
static description = "
|
|
4
|
+
static description = "Manage records.";
|
|
5
5
|
static examples = [];
|
|
6
6
|
static flags = {};
|
|
7
7
|
static usage = [
|
|
@@ -9,10 +9,11 @@ const flagArrayToParam = (cmd, values) => values
|
|
|
9
9
|
.map(([k, v]) => ({ [`${cmd}.${k}`]: v }))
|
|
10
10
|
.reduce((a, b) => ({ ...a, ...b }), {});
|
|
11
11
|
export default class RecordsList extends BaseCommand {
|
|
12
|
+
static aliases = ["records search"];
|
|
12
13
|
static args = {
|
|
13
14
|
"uri": Args.string({ description: "uri of type" }),
|
|
14
15
|
};
|
|
15
|
-
static description = "
|
|
16
|
+
static description = "List records.";
|
|
16
17
|
static examples = [
|
|
17
18
|
"<%= config.bin %> <%= command.id %> native-object:my-type",
|
|
18
19
|
"<%= config.bin %> <%= command.id %> --type my-type",
|
|
@@ -0,0 +1,25 @@
|
|
|
1
|
+
import { BaseCommand } from "../../base.js";
|
|
2
|
+
type Patch = {
|
|
3
|
+
path: string;
|
|
4
|
+
};
|
|
5
|
+
type PatchWithValue = Patch & {
|
|
6
|
+
value: unknown;
|
|
7
|
+
};
|
|
8
|
+
export default class RecordsPatch extends BaseCommand<typeof RecordsPatch> {
|
|
9
|
+
static args: {
|
|
10
|
+
uri: import("@oclif/core/interfaces").Arg<string | undefined, Record<string, unknown>>;
|
|
11
|
+
};
|
|
12
|
+
static description: string;
|
|
13
|
+
static examples: string[];
|
|
14
|
+
static flags: {
|
|
15
|
+
add: import("@oclif/core/interfaces").OptionFlag<PatchWithValue[] | undefined, import("@oclif/core/interfaces").CustomOptions>;
|
|
16
|
+
id: import("@oclif/core/interfaces").OptionFlag<string | undefined, import("@oclif/core/interfaces").CustomOptions>;
|
|
17
|
+
increment: import("@oclif/core/interfaces").OptionFlag<PatchWithValue[] | undefined, import("@oclif/core/interfaces").CustomOptions>;
|
|
18
|
+
remove: import("@oclif/core/interfaces").OptionFlag<Patch[] | undefined, import("@oclif/core/interfaces").CustomOptions>;
|
|
19
|
+
replace: import("@oclif/core/interfaces").OptionFlag<PatchWithValue[] | undefined, import("@oclif/core/interfaces").CustomOptions>;
|
|
20
|
+
set: import("@oclif/core/interfaces").OptionFlag<PatchWithValue[] | undefined, import("@oclif/core/interfaces").CustomOptions>;
|
|
21
|
+
type: import("@oclif/core/interfaces").OptionFlag<string | undefined, import("@oclif/core/interfaces").CustomOptions>;
|
|
22
|
+
};
|
|
23
|
+
run(): Promise<void>;
|
|
24
|
+
}
|
|
25
|
+
export {};
|
|
@@ -0,0 +1,106 @@
|
|
|
1
|
+
import { Args, Flags } from "@oclif/core";
|
|
2
|
+
import { BaseCommand } from "../../base.js";
|
|
3
|
+
import { parseUri } from "../../models/uri.js";
|
|
4
|
+
import { getNativeObjectApiEndpoint } from "../../utils/endpoints.js";
|
|
5
|
+
const toPath = (input) => "/" + input.replaceAll(".", "/");
|
|
6
|
+
const patchFlag = Flags.custom({
|
|
7
|
+
async parse(input) {
|
|
8
|
+
return {
|
|
9
|
+
path: toPath(input),
|
|
10
|
+
};
|
|
11
|
+
},
|
|
12
|
+
});
|
|
13
|
+
const patchWithValueFlag = Flags.custom({
|
|
14
|
+
async parse(input) {
|
|
15
|
+
if (!/=/.test(input)) {
|
|
16
|
+
throw new Error("No value provided for patch");
|
|
17
|
+
}
|
|
18
|
+
const [key, value] = input.split("=");
|
|
19
|
+
return {
|
|
20
|
+
path: toPath(key),
|
|
21
|
+
value,
|
|
22
|
+
};
|
|
23
|
+
},
|
|
24
|
+
});
|
|
25
|
+
export default class RecordsPatch extends BaseCommand {
|
|
26
|
+
static args = {
|
|
27
|
+
"uri": Args.string({ description: "uri of record" }),
|
|
28
|
+
};
|
|
29
|
+
static description = "Patch a record.";
|
|
30
|
+
static examples = [
|
|
31
|
+
"<%= config.bin %> <%= command.id %> native-object:my-type/instance-1 --set field1=value1",
|
|
32
|
+
"<%= config.bin %> <%= command.id %> native-object:my-type --id instance-1 --remove field2",
|
|
33
|
+
"<%= config.bin %> <%= command.id %> --type my-type --id instance-1 --increment field3=2",
|
|
34
|
+
];
|
|
35
|
+
static flags = {
|
|
36
|
+
add: patchWithValueFlag({
|
|
37
|
+
char: "a",
|
|
38
|
+
description: "add field",
|
|
39
|
+
multiple: true,
|
|
40
|
+
}),
|
|
41
|
+
id: Flags.string({
|
|
42
|
+
char: "I",
|
|
43
|
+
description: "id",
|
|
44
|
+
}),
|
|
45
|
+
increment: patchWithValueFlag({
|
|
46
|
+
char: "i",
|
|
47
|
+
description: "increment field",
|
|
48
|
+
multiple: true,
|
|
49
|
+
}),
|
|
50
|
+
remove: patchFlag({
|
|
51
|
+
char: "d",
|
|
52
|
+
description: "remove field",
|
|
53
|
+
multiple: true,
|
|
54
|
+
}),
|
|
55
|
+
replace: patchWithValueFlag({
|
|
56
|
+
char: "r",
|
|
57
|
+
description: "replace field",
|
|
58
|
+
multiple: true,
|
|
59
|
+
}),
|
|
60
|
+
set: patchWithValueFlag({
|
|
61
|
+
char: "s",
|
|
62
|
+
description: "set field",
|
|
63
|
+
multiple: true,
|
|
64
|
+
}),
|
|
65
|
+
type: Flags.string({
|
|
66
|
+
char: "T",
|
|
67
|
+
description: "type",
|
|
68
|
+
}),
|
|
69
|
+
};
|
|
70
|
+
async run() {
|
|
71
|
+
const { uri } = this.args;
|
|
72
|
+
const { id: flagId, type: flagType } = this.flags;
|
|
73
|
+
let type = flagType;
|
|
74
|
+
let lookup = flagId;
|
|
75
|
+
if (uri) {
|
|
76
|
+
const { id, type: uriType } = parseUri(uri);
|
|
77
|
+
type = uriType;
|
|
78
|
+
if (id) {
|
|
79
|
+
lookup = id;
|
|
80
|
+
}
|
|
81
|
+
}
|
|
82
|
+
if (!type) {
|
|
83
|
+
throw new Error("Type not provided");
|
|
84
|
+
}
|
|
85
|
+
if (!lookup) {
|
|
86
|
+
throw new Error("Id not provided");
|
|
87
|
+
}
|
|
88
|
+
const patches = [
|
|
89
|
+
...(this.flags.add ?? []).map(x => ({ op: "add", ...x })),
|
|
90
|
+
...(this.flags.set ?? []).map(x => ({ op: "set", ...x })),
|
|
91
|
+
...(this.flags.replace ?? []).map(x => ({ op: "replace", ...x })),
|
|
92
|
+
...(this.flags.remove ?? []).map(x => ({ op: "remove", ...x })),
|
|
93
|
+
...(this.flags.increment ?? []).map(({ value, ...x }) => ({ op: "increment", ...x, value: Number(`${value}`) })),
|
|
94
|
+
];
|
|
95
|
+
if (patches.length === 0) {
|
|
96
|
+
throw new Error("No patches provided");
|
|
97
|
+
}
|
|
98
|
+
this.logJson(await this.fetch(({ silo, tenantId }) => getNativeObjectApiEndpoint(tenantId, silo) + `/api/v1/${type}/${lookup}`, {
|
|
99
|
+
body: JSON.stringify(patches),
|
|
100
|
+
headers: {
|
|
101
|
+
"content-type": "application/json",
|
|
102
|
+
},
|
|
103
|
+
method: "PATCH",
|
|
104
|
+
}));
|
|
105
|
+
}
|
|
106
|
+
}
|
|
@@ -10,7 +10,7 @@ export default class RecordsQuery extends BaseCommand {
|
|
|
10
10
|
static args = {
|
|
11
11
|
"uri": Args.string({ description: "uri of type" }),
|
|
12
12
|
};
|
|
13
|
-
static description = "
|
|
13
|
+
static description = "Query records.";
|
|
14
14
|
static examples = [
|
|
15
15
|
"<%= config.bin %> <%= command.id %> native-object:my-type",
|
|
16
16
|
"<%= config.bin %> <%= command.id %> --type my-type --query-file query.json",
|
|
@@ -9,7 +9,7 @@ export default class RecordsReplace extends BaseCommand {
|
|
|
9
9
|
static args = {
|
|
10
10
|
"uri": Args.string({ description: "uri of record" }),
|
|
11
11
|
};
|
|
12
|
-
static description = "
|
|
12
|
+
static description = "Replace a record.";
|
|
13
13
|
static examples = [
|
|
14
14
|
"<%= config.bin %> <%= command.id %> native-object:my-type/instance-1 --input-file record.json",
|
|
15
15
|
"<%= config.bin %> <%= command.id %> native-object:my-type --id instance-1 --input-file record.json",
|
|
@@ -17,7 +17,7 @@ export default class RecordsReplace extends BaseCommand {
|
|
|
17
17
|
];
|
|
18
18
|
static flags = {
|
|
19
19
|
id: Flags.string({
|
|
20
|
-
char: "
|
|
20
|
+
char: "I",
|
|
21
21
|
description: "id",
|
|
22
22
|
}),
|
|
23
23
|
"input-file": Flags.file({
|
|
@@ -0,0 +1,11 @@
|
|
|
1
|
+
import { BaseCommand } from "../../base.js";
|
|
2
|
+
export default class TypesAdd extends BaseCommand<typeof TypesAdd> {
|
|
3
|
+
static aliases: string[];
|
|
4
|
+
static args: {};
|
|
5
|
+
static description: string;
|
|
6
|
+
static examples: string[];
|
|
7
|
+
static flags: {
|
|
8
|
+
"input-file": import("@oclif/core/interfaces").OptionFlag<string, import("@oclif/core/interfaces").CustomOptions>;
|
|
9
|
+
};
|
|
10
|
+
run(): Promise<void>;
|
|
11
|
+
}
|
|
@@ -0,0 +1,57 @@
|
|
|
1
|
+
import { Flags } from "@oclif/core";
|
|
2
|
+
import fs, { createReadStream } from "node:fs";
|
|
3
|
+
import path from "node:path";
|
|
4
|
+
import jsonl from "stream-json/jsonl/Parser.js";
|
|
5
|
+
import { BaseCommand } from "../../base.js";
|
|
6
|
+
import { getRegistryApiEndpoint } from "../../utils/endpoints.js";
|
|
7
|
+
import { mapStream, readStreamToEnd } from "../../utils/stream.js";
|
|
8
|
+
export default class TypesAdd extends BaseCommand {
|
|
9
|
+
static aliases = ["types create", "types import"];
|
|
10
|
+
static args = {};
|
|
11
|
+
static description = "Create type(s).";
|
|
12
|
+
static examples = [
|
|
13
|
+
"<%= config.bin %> <%= command.id %>",
|
|
14
|
+
"<%= config.bin %> <%= command.id %> --input-file types.json",
|
|
15
|
+
];
|
|
16
|
+
static flags = {
|
|
17
|
+
"input-file": Flags.file({
|
|
18
|
+
char: "i",
|
|
19
|
+
default: "-",
|
|
20
|
+
description: "file to read. can read stdin if value is '-'",
|
|
21
|
+
}),
|
|
22
|
+
};
|
|
23
|
+
async run() {
|
|
24
|
+
const inputFile = this.flags["input-file"] === "-"
|
|
25
|
+
? "-"
|
|
26
|
+
: path.resolve(this.flags["input-file"]);
|
|
27
|
+
if (inputFile && inputFile !== "-" && !fs.existsSync(inputFile)) {
|
|
28
|
+
throw new Error("File does not exist");
|
|
29
|
+
}
|
|
30
|
+
const stream = inputFile && inputFile !== "-"
|
|
31
|
+
? createReadStream(inputFile)
|
|
32
|
+
: process.stdin;
|
|
33
|
+
const types = await readStreamToEnd(stream
|
|
34
|
+
.pipe(jsonl.parser())
|
|
35
|
+
// eslint-disable-next-line @typescript-eslint/no-explicit-any
|
|
36
|
+
.pipe(mapStream(async (x) => x.value))
|
|
37
|
+
.pipe(mapStream(async (x) => JSON.stringify(x))));
|
|
38
|
+
// eslint-disable-next-line unicorn/consistent-function-scoping
|
|
39
|
+
const create = (body) => this.fetch(({ silo, tenantId }) => getRegistryApiEndpoint(tenantId, silo) + "/api/v1/types", {
|
|
40
|
+
body,
|
|
41
|
+
headers: {
|
|
42
|
+
"content-type": "application/json",
|
|
43
|
+
},
|
|
44
|
+
method: "POST",
|
|
45
|
+
});
|
|
46
|
+
for (const type of types) {
|
|
47
|
+
// eslint-disable-next-line no-await-in-loop
|
|
48
|
+
const rv = await create(type);
|
|
49
|
+
if (types.length > 1) {
|
|
50
|
+
this.log(JSON.stringify(rv));
|
|
51
|
+
}
|
|
52
|
+
else {
|
|
53
|
+
this.logJson(rv);
|
|
54
|
+
}
|
|
55
|
+
}
|
|
56
|
+
}
|
|
57
|
+
}
|
|
@@ -0,0 +1,12 @@
|
|
|
1
|
+
import { BaseCommand } from "../../base.js";
|
|
2
|
+
export default class TypesDelete extends BaseCommand<typeof TypesDelete> {
|
|
3
|
+
static args: {
|
|
4
|
+
uri: import("@oclif/core/interfaces").Arg<string | undefined, Record<string, unknown>>;
|
|
5
|
+
};
|
|
6
|
+
static description: string;
|
|
7
|
+
static examples: string[];
|
|
8
|
+
static flags: {
|
|
9
|
+
type: import("@oclif/core/interfaces").OptionFlag<string | undefined, import("@oclif/core/interfaces").CustomOptions>;
|
|
10
|
+
};
|
|
11
|
+
run(): Promise<void>;
|
|
12
|
+
}
|
|
@@ -0,0 +1,35 @@
|
|
|
1
|
+
import { Args, Flags } from "@oclif/core";
|
|
2
|
+
import { BaseCommand } from "../../base.js";
|
|
3
|
+
import { parseUri } from "../../models/uri.js";
|
|
4
|
+
import { getRegistryApiEndpoint } from "../../utils/endpoints.js";
|
|
5
|
+
export default class TypesDelete extends BaseCommand {
|
|
6
|
+
static args = {
|
|
7
|
+
"uri": Args.string({ description: "uri of type" }),
|
|
8
|
+
};
|
|
9
|
+
static description = "Delete a type.";
|
|
10
|
+
static examples = [
|
|
11
|
+
"<%= config.bin %> <%= command.id %> native-object:my-type",
|
|
12
|
+
"<%= config.bin %> <%= command.id %> --type my-type",
|
|
13
|
+
];
|
|
14
|
+
static flags = {
|
|
15
|
+
type: Flags.string({
|
|
16
|
+
char: "T",
|
|
17
|
+
description: "type",
|
|
18
|
+
}),
|
|
19
|
+
};
|
|
20
|
+
async run() {
|
|
21
|
+
const { uri } = this.args;
|
|
22
|
+
const { type: flagType } = this.flags;
|
|
23
|
+
let type = flagType;
|
|
24
|
+
if (uri) {
|
|
25
|
+
const { type: uriType } = parseUri(uri);
|
|
26
|
+
type = uriType;
|
|
27
|
+
}
|
|
28
|
+
if (!type) {
|
|
29
|
+
throw new Error("Type not provided");
|
|
30
|
+
}
|
|
31
|
+
await this.fetch(({ silo, tenantId }) => getRegistryApiEndpoint(tenantId, silo) + `/api/v1/types/${type}`, {
|
|
32
|
+
method: "DELETE",
|
|
33
|
+
});
|
|
34
|
+
}
|
|
35
|
+
}
|
|
@@ -0,0 +1,12 @@
|
|
|
1
|
+
import { BaseCommand } from "../../base.js";
|
|
2
|
+
export default class TypesGet extends BaseCommand<typeof TypesGet> {
|
|
3
|
+
static args: {
|
|
4
|
+
uri: import("@oclif/core/interfaces").Arg<string | undefined, Record<string, unknown>>;
|
|
5
|
+
};
|
|
6
|
+
static description: string;
|
|
7
|
+
static examples: string[];
|
|
8
|
+
static flags: {
|
|
9
|
+
type: import("@oclif/core/interfaces").OptionFlag<string | undefined, import("@oclif/core/interfaces").CustomOptions>;
|
|
10
|
+
};
|
|
11
|
+
run(): Promise<void>;
|
|
12
|
+
}
|
|
@@ -0,0 +1,33 @@
|
|
|
1
|
+
import { Args, Flags } from "@oclif/core";
|
|
2
|
+
import { BaseCommand } from "../../base.js";
|
|
3
|
+
import { parseUri } from "../../models/uri.js";
|
|
4
|
+
import { getRegistryApiEndpoint } from "../../utils/endpoints.js";
|
|
5
|
+
export default class TypesGet extends BaseCommand {
|
|
6
|
+
static args = {
|
|
7
|
+
"uri": Args.string({ description: "uri of type" }),
|
|
8
|
+
};
|
|
9
|
+
static description = "Get a type.";
|
|
10
|
+
static examples = [
|
|
11
|
+
"<%= config.bin %> <%= command.id %> native-object:my-type",
|
|
12
|
+
"<%= config.bin %> <%= command.id %> --type my-type",
|
|
13
|
+
];
|
|
14
|
+
static flags = {
|
|
15
|
+
type: Flags.string({
|
|
16
|
+
char: "T",
|
|
17
|
+
description: "type",
|
|
18
|
+
}),
|
|
19
|
+
};
|
|
20
|
+
async run() {
|
|
21
|
+
const { uri } = this.args;
|
|
22
|
+
const { type: flagType } = this.flags;
|
|
23
|
+
let type = flagType;
|
|
24
|
+
if (uri) {
|
|
25
|
+
const { type: uriType } = parseUri(uri);
|
|
26
|
+
type = uriType;
|
|
27
|
+
}
|
|
28
|
+
if (!type) {
|
|
29
|
+
throw new Error("Type not provided");
|
|
30
|
+
}
|
|
31
|
+
this.logJson(await this.fetch(({ silo, tenantId }) => getRegistryApiEndpoint(tenantId, silo) + `/api/v1/types/${type}`));
|
|
32
|
+
}
|
|
33
|
+
}
|
|
@@ -0,0 +1,9 @@
|
|
|
1
|
+
import { BaseConfigCommand } from "../../base.js";
|
|
2
|
+
export default class Types extends BaseConfigCommand<typeof Types> {
|
|
3
|
+
static args: {};
|
|
4
|
+
static description: string;
|
|
5
|
+
static examples: never[];
|
|
6
|
+
static flags: {};
|
|
7
|
+
static usage: string[];
|
|
8
|
+
run(): Promise<void>;
|
|
9
|
+
}
|
|
@@ -0,0 +1,13 @@
|
|
|
1
|
+
import { BaseConfigCommand } from "../../base.js";
|
|
2
|
+
export default class Types extends BaseConfigCommand {
|
|
3
|
+
static args = {};
|
|
4
|
+
static description = "Manage types.";
|
|
5
|
+
static examples = [];
|
|
6
|
+
static flags = {};
|
|
7
|
+
static usage = [
|
|
8
|
+
"<%= command.id %> <COMMAND>",
|
|
9
|
+
];
|
|
10
|
+
async run() {
|
|
11
|
+
await this.showHelp();
|
|
12
|
+
}
|
|
13
|
+
}
|
|
@@ -0,0 +1,20 @@
|
|
|
1
|
+
import { BaseCommand } from "../../base.js";
|
|
2
|
+
export default class TypesList extends BaseCommand<typeof TypesList> {
|
|
3
|
+
static aliases: string[];
|
|
4
|
+
static args: {};
|
|
5
|
+
static description: string;
|
|
6
|
+
static examples: string[];
|
|
7
|
+
static flags: {
|
|
8
|
+
"exact-search": import("@oclif/core/interfaces").OptionFlag<string[] | undefined, import("@oclif/core/interfaces").CustomOptions>;
|
|
9
|
+
export: import("@oclif/core/interfaces").BooleanFlag<boolean>;
|
|
10
|
+
from: import("@oclif/core/interfaces").OptionFlag<string[] | undefined, import("@oclif/core/interfaces").CustomOptions>;
|
|
11
|
+
"include-total": import("@oclif/core/interfaces").BooleanFlag<boolean>;
|
|
12
|
+
"order-by": import("@oclif/core/interfaces").OptionFlag<string[] | undefined, import("@oclif/core/interfaces").CustomOptions>;
|
|
13
|
+
"page-size": import("@oclif/core/interfaces").OptionFlag<number | undefined, import("@oclif/core/interfaces").CustomOptions>;
|
|
14
|
+
"page-token": import("@oclif/core/interfaces").OptionFlag<string | undefined, import("@oclif/core/interfaces").CustomOptions>;
|
|
15
|
+
progress: import("@oclif/core/interfaces").BooleanFlag<boolean>;
|
|
16
|
+
search: import("@oclif/core/interfaces").OptionFlag<string[] | undefined, import("@oclif/core/interfaces").CustomOptions>;
|
|
17
|
+
to: import("@oclif/core/interfaces").OptionFlag<string[] | undefined, import("@oclif/core/interfaces").CustomOptions>;
|
|
18
|
+
};
|
|
19
|
+
run(): Promise<void>;
|
|
20
|
+
}
|