@agentuity/cli 0.0.47 → 0.0.49
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/bin/cli.ts +26 -5
- package/dist/banner.d.ts +1 -1
- package/dist/banner.d.ts.map +1 -1
- package/dist/cli-logger.d.ts +27 -0
- package/dist/cli-logger.d.ts.map +1 -0
- package/dist/cli.d.ts.map +1 -1
- package/dist/cmd/auth/index.d.ts.map +1 -1
- package/dist/cmd/auth/login.d.ts.map +1 -1
- package/dist/cmd/auth/logout.d.ts.map +1 -1
- package/dist/cmd/auth/signup.d.ts.map +1 -1
- package/dist/cmd/auth/ssh/add.d.ts.map +1 -1
- package/dist/cmd/auth/ssh/delete.d.ts.map +1 -1
- package/dist/cmd/auth/ssh/index.d.ts +1 -2
- package/dist/cmd/auth/ssh/index.d.ts.map +1 -1
- package/dist/cmd/auth/ssh/list.d.ts.map +1 -1
- package/dist/cmd/auth/whoami.d.ts.map +1 -1
- package/dist/cmd/bundle/ast.d.ts.map +1 -1
- package/dist/cmd/bundle/index.d.ts.map +1 -1
- package/dist/cmd/bundle/plugin.d.ts.map +1 -1
- package/dist/cmd/capabilities/index.d.ts +4 -0
- package/dist/cmd/capabilities/index.d.ts.map +1 -0
- package/dist/cmd/capabilities/show.d.ts +20 -0
- package/dist/cmd/capabilities/show.d.ts.map +1 -0
- package/dist/cmd/cloud/deploy.d.ts.map +1 -1
- package/dist/cmd/cloud/deployment/index.d.ts +2 -0
- package/dist/cmd/cloud/deployment/index.d.ts.map +1 -0
- package/dist/cmd/cloud/deployment/list.d.ts +2 -0
- package/dist/cmd/cloud/deployment/list.d.ts.map +1 -0
- package/dist/cmd/cloud/deployment/remove.d.ts +2 -0
- package/dist/cmd/cloud/deployment/remove.d.ts.map +1 -0
- package/dist/cmd/cloud/deployment/rollback.d.ts +2 -0
- package/dist/cmd/cloud/deployment/rollback.d.ts.map +1 -0
- package/dist/cmd/cloud/deployment/show.d.ts +2 -0
- package/dist/cmd/cloud/deployment/show.d.ts.map +1 -0
- package/dist/cmd/cloud/deployment/undeploy.d.ts +2 -0
- package/dist/cmd/cloud/deployment/undeploy.d.ts.map +1 -0
- package/dist/cmd/cloud/deployment/utils.d.ts +7 -0
- package/dist/cmd/cloud/deployment/utils.d.ts.map +1 -0
- package/dist/cmd/cloud/domain.d.ts.map +1 -1
- package/dist/cmd/cloud/index.d.ts.map +1 -1
- package/dist/cmd/cloud/resource/add.d.ts.map +1 -1
- package/dist/cmd/cloud/resource/delete.d.ts.map +1 -1
- package/dist/cmd/cloud/resource/index.d.ts +1 -2
- package/dist/cmd/cloud/resource/index.d.ts.map +1 -1
- package/dist/cmd/cloud/resource/list.d.ts.map +1 -1
- package/dist/cmd/cloud/scp/download.d.ts.map +1 -1
- package/dist/cmd/cloud/scp/index.d.ts +1 -2
- package/dist/cmd/cloud/scp/index.d.ts.map +1 -1
- package/dist/cmd/cloud/scp/upload.d.ts.map +1 -1
- package/dist/cmd/cloud/ssh.d.ts.map +1 -1
- package/dist/cmd/dev/index.d.ts.map +1 -1
- package/dist/cmd/env/delete.d.ts.map +1 -1
- package/dist/cmd/env/get.d.ts.map +1 -1
- package/dist/cmd/env/import.d.ts.map +1 -1
- package/dist/cmd/env/index.d.ts.map +1 -1
- package/dist/cmd/env/list.d.ts.map +1 -1
- package/dist/cmd/env/pull.d.ts.map +1 -1
- package/dist/cmd/env/push.d.ts.map +1 -1
- package/dist/cmd/env/set.d.ts.map +1 -1
- package/dist/cmd/index.d.ts.map +1 -1
- package/dist/cmd/kv/create-namespace.d.ts +3 -0
- package/dist/cmd/kv/create-namespace.d.ts.map +1 -0
- package/dist/cmd/kv/delete-namespace.d.ts +3 -0
- package/dist/cmd/kv/delete-namespace.d.ts.map +1 -0
- package/dist/cmd/kv/delete.d.ts +3 -0
- package/dist/cmd/kv/delete.d.ts.map +1 -0
- package/dist/cmd/kv/get.d.ts +3 -0
- package/dist/cmd/kv/get.d.ts.map +1 -0
- package/dist/cmd/kv/index.d.ts +2 -0
- package/dist/cmd/kv/index.d.ts.map +1 -0
- package/dist/cmd/kv/keys.d.ts +3 -0
- package/dist/cmd/kv/keys.d.ts.map +1 -0
- package/dist/cmd/kv/list-namespaces.d.ts +3 -0
- package/dist/cmd/kv/list-namespaces.d.ts.map +1 -0
- package/dist/cmd/kv/repl.d.ts +3 -0
- package/dist/cmd/kv/repl.d.ts.map +1 -0
- package/dist/cmd/kv/search.d.ts +3 -0
- package/dist/cmd/kv/search.d.ts.map +1 -0
- package/dist/cmd/kv/set.d.ts +3 -0
- package/dist/cmd/kv/set.d.ts.map +1 -0
- package/dist/cmd/kv/stats.d.ts +3 -0
- package/dist/cmd/kv/stats.d.ts.map +1 -0
- package/dist/cmd/kv/util.d.ts +8 -0
- package/dist/cmd/kv/util.d.ts.map +1 -0
- package/dist/cmd/objectstore/delete-bucket.d.ts +3 -0
- package/dist/cmd/objectstore/delete-bucket.d.ts.map +1 -0
- package/dist/cmd/objectstore/delete.d.ts +3 -0
- package/dist/cmd/objectstore/delete.d.ts.map +1 -0
- package/dist/cmd/objectstore/get.d.ts +3 -0
- package/dist/cmd/objectstore/get.d.ts.map +1 -0
- package/dist/cmd/objectstore/index.d.ts +2 -0
- package/dist/cmd/objectstore/index.d.ts.map +1 -0
- package/dist/cmd/objectstore/list-buckets.d.ts +3 -0
- package/dist/cmd/objectstore/list-buckets.d.ts.map +1 -0
- package/dist/cmd/objectstore/list-keys.d.ts +3 -0
- package/dist/cmd/objectstore/list-keys.d.ts.map +1 -0
- package/dist/cmd/objectstore/put.d.ts +3 -0
- package/dist/cmd/objectstore/put.d.ts.map +1 -0
- package/dist/cmd/objectstore/repl.d.ts +3 -0
- package/dist/cmd/objectstore/repl.d.ts.map +1 -0
- package/dist/cmd/objectstore/url.d.ts +3 -0
- package/dist/cmd/objectstore/url.d.ts.map +1 -0
- package/dist/cmd/objectstore/util.d.ts +8 -0
- package/dist/cmd/objectstore/util.d.ts.map +1 -0
- package/dist/cmd/profile/create.d.ts.map +1 -1
- package/dist/cmd/profile/delete.d.ts.map +1 -1
- package/dist/cmd/profile/index.d.ts.map +1 -1
- package/dist/cmd/profile/list.d.ts +1 -2
- package/dist/cmd/profile/list.d.ts.map +1 -1
- package/dist/cmd/profile/show.d.ts.map +1 -1
- package/dist/cmd/profile/use.d.ts.map +1 -1
- package/dist/cmd/project/create.d.ts.map +1 -1
- package/dist/cmd/project/delete.d.ts.map +1 -1
- package/dist/cmd/project/index.d.ts.map +1 -1
- package/dist/cmd/project/list.d.ts.map +1 -1
- package/dist/cmd/project/show.d.ts.map +1 -1
- package/dist/cmd/project/template-flow.d.ts +1 -1
- package/dist/cmd/project/template-flow.d.ts.map +1 -1
- package/dist/cmd/prompt/index.d.ts +4 -0
- package/dist/cmd/prompt/index.d.ts.map +1 -0
- package/dist/cmd/prompt/llm.d.ts +3 -0
- package/dist/cmd/prompt/llm.d.ts.map +1 -0
- package/dist/cmd/repl/index.d.ts +3 -0
- package/dist/cmd/repl/index.d.ts.map +1 -0
- package/dist/cmd/schema/index.d.ts +4 -0
- package/dist/cmd/schema/index.d.ts.map +1 -0
- package/dist/cmd/schema/show.d.ts +3 -0
- package/dist/cmd/schema/show.d.ts.map +1 -0
- package/dist/cmd/secret/delete.d.ts.map +1 -1
- package/dist/cmd/secret/get.d.ts.map +1 -1
- package/dist/cmd/secret/import.d.ts.map +1 -1
- package/dist/cmd/secret/index.d.ts.map +1 -1
- package/dist/cmd/secret/list.d.ts.map +1 -1
- package/dist/cmd/secret/pull.d.ts.map +1 -1
- package/dist/cmd/secret/push.d.ts.map +1 -1
- package/dist/cmd/secret/set.d.ts.map +1 -1
- package/dist/cmd/version/index.d.ts.map +1 -1
- package/dist/config.d.ts +1 -1
- package/dist/config.d.ts.map +1 -1
- package/dist/errors.d.ts +83 -0
- package/dist/errors.d.ts.map +1 -0
- package/dist/explain.d.ts +47 -0
- package/dist/explain.d.ts.map +1 -0
- package/dist/index.d.ts +6 -0
- package/dist/index.d.ts.map +1 -1
- package/dist/json.d.ts +3 -0
- package/dist/json.d.ts.map +1 -0
- package/dist/output.d.ts +136 -0
- package/dist/output.d.ts.map +1 -0
- package/dist/repl.d.ts +124 -0
- package/dist/repl.d.ts.map +1 -0
- package/dist/schema-generator.d.ts +67 -0
- package/dist/schema-generator.d.ts.map +1 -0
- package/dist/tui.d.ts +20 -1
- package/dist/tui.d.ts.map +1 -1
- package/dist/types.d.ts +65 -6
- package/dist/types.d.ts.map +1 -1
- package/package.json +10 -4
- package/src/banner.ts +7 -7
- package/src/cli-logger.ts +80 -0
- package/src/cli.ts +186 -54
- package/src/cmd/auth/index.ts +1 -0
- package/src/cmd/auth/login.ts +7 -2
- package/src/cmd/auth/logout.ts +4 -0
- package/src/cmd/auth/signup.ts +7 -2
- package/src/cmd/auth/ssh/add.ts +20 -3
- package/src/cmd/auth/ssh/delete.ts +57 -4
- package/src/cmd/auth/ssh/index.ts +4 -3
- package/src/cmd/auth/ssh/list.ts +44 -32
- package/src/cmd/auth/whoami.ts +32 -21
- package/src/cmd/bundle/ast.ts +27 -5
- package/src/cmd/bundle/index.ts +20 -0
- package/src/cmd/bundle/plugin.ts +36 -12
- package/src/cmd/capabilities/index.ts +12 -0
- package/src/cmd/capabilities/show.ts +256 -0
- package/src/cmd/cloud/deploy.ts +60 -0
- package/src/cmd/cloud/deployment/index.ts +20 -0
- package/src/cmd/cloud/deployment/list.ts +105 -0
- package/src/cmd/cloud/deployment/remove.ts +65 -0
- package/src/cmd/cloud/deployment/rollback.ts +87 -0
- package/src/cmd/cloud/deployment/show.ts +107 -0
- package/src/cmd/cloud/deployment/undeploy.ts +48 -0
- package/src/cmd/cloud/deployment/utils.ts +14 -0
- package/src/cmd/cloud/domain.ts +3 -2
- package/src/cmd/cloud/index.ts +9 -1
- package/src/cmd/cloud/resource/add.ts +19 -0
- package/src/cmd/cloud/resource/delete.ts +24 -3
- package/src/cmd/cloud/resource/index.ts +4 -3
- package/src/cmd/cloud/resource/list.ts +36 -10
- package/src/cmd/cloud/scp/download.ts +27 -1
- package/src/cmd/cloud/scp/index.ts +4 -3
- package/src/cmd/cloud/scp/upload.ts +27 -1
- package/src/cmd/cloud/ssh.ts +12 -0
- package/src/cmd/dev/index.ts +11 -7
- package/src/cmd/dev/templates.ts +1 -1
- package/src/cmd/env/delete.ts +17 -0
- package/src/cmd/env/get.ts +17 -1
- package/src/cmd/env/import.ts +47 -3
- package/src/cmd/env/index.ts +1 -0
- package/src/cmd/env/list.ts +13 -1
- package/src/cmd/env/pull.ts +20 -0
- package/src/cmd/env/push.ts +33 -1
- package/src/cmd/env/set.ts +25 -1
- package/src/cmd/index.ts +9 -2
- package/src/cmd/kv/create-namespace.ts +45 -0
- package/src/cmd/kv/delete-namespace.ts +73 -0
- package/src/cmd/kv/delete.ts +51 -0
- package/src/cmd/kv/get.ts +65 -0
- package/src/cmd/kv/index.ts +31 -0
- package/src/cmd/kv/keys.ts +57 -0
- package/src/cmd/kv/list-namespaces.ts +43 -0
- package/src/cmd/kv/repl.ts +284 -0
- package/src/cmd/kv/search.ts +80 -0
- package/src/cmd/kv/set.ts +63 -0
- package/src/cmd/kv/stats.ts +96 -0
- package/src/cmd/kv/util.ts +32 -0
- package/src/cmd/objectstore/delete-bucket.ts +72 -0
- package/src/cmd/objectstore/delete.ts +59 -0
- package/src/cmd/objectstore/get.ts +64 -0
- package/src/cmd/objectstore/index.ts +27 -0
- package/src/cmd/objectstore/list-buckets.ts +45 -0
- package/src/cmd/objectstore/list-keys.ts +60 -0
- package/src/cmd/objectstore/put.ts +62 -0
- package/src/cmd/objectstore/repl.ts +235 -0
- package/src/cmd/objectstore/url.ts +59 -0
- package/src/cmd/objectstore/util.ts +28 -0
- package/src/cmd/profile/create.ts +61 -6
- package/src/cmd/profile/delete.ts +25 -5
- package/src/cmd/profile/index.ts +1 -0
- package/src/cmd/profile/list.ts +7 -3
- package/src/cmd/profile/show.ts +33 -19
- package/src/cmd/profile/use.ts +17 -4
- package/src/cmd/project/create.ts +31 -0
- package/src/cmd/project/delete.ts +24 -2
- package/src/cmd/project/index.ts +1 -0
- package/src/cmd/project/list.ts +23 -9
- package/src/cmd/project/show.ts +27 -8
- package/src/cmd/project/template-flow.ts +10 -6
- package/src/cmd/prompt/index.ts +12 -0
- package/src/cmd/prompt/llm.ts +368 -0
- package/src/cmd/repl/index.ts +477 -0
- package/src/cmd/schema/index.ts +12 -0
- package/src/cmd/schema/show.ts +27 -0
- package/src/cmd/secret/delete.ts +17 -0
- package/src/cmd/secret/get.ts +20 -1
- package/src/cmd/secret/import.ts +45 -2
- package/src/cmd/secret/index.ts +1 -0
- package/src/cmd/secret/list.ts +10 -1
- package/src/cmd/secret/pull.ts +20 -0
- package/src/cmd/secret/push.ts +33 -1
- package/src/cmd/secret/set.ts +20 -0
- package/src/cmd/version/index.ts +15 -2
- package/src/config.ts +18 -5
- package/src/errors.ts +222 -0
- package/src/explain.ts +126 -0
- package/src/index.ts +51 -0
- package/src/json.ts +28 -0
- package/src/output.ts +307 -0
- package/src/repl.ts +1517 -0
- package/src/schema-generator.ts +389 -0
- package/src/tui.ts +136 -13
- package/src/types.ts +62 -12
package/src/cmd/env/set.ts
CHANGED
|
@@ -11,15 +11,29 @@ import {
|
|
|
11
11
|
} from '../../env-util';
|
|
12
12
|
import { getCommand } from '../../command-prefix';
|
|
13
13
|
|
|
14
|
+
const EnvSetResponseSchema = z.object({
|
|
15
|
+
success: z.boolean().describe('Whether the operation succeeded'),
|
|
16
|
+
key: z.string().describe('Environment variable key'),
|
|
17
|
+
path: z.string().describe('Local file path where env var was saved'),
|
|
18
|
+
});
|
|
19
|
+
|
|
14
20
|
export const setSubcommand = createSubcommand({
|
|
15
21
|
name: 'set',
|
|
16
22
|
description: 'Set an environment variable',
|
|
23
|
+
tags: ['mutating', 'updates-resource', 'slow', 'requires-auth', 'requires-project'],
|
|
24
|
+
idempotent: true,
|
|
17
25
|
requires: { auth: true, project: true, apiClient: true },
|
|
26
|
+
examples: [
|
|
27
|
+
getCommand('env set NODE_ENV production'),
|
|
28
|
+
getCommand('env set PORT 3000'),
|
|
29
|
+
getCommand('env set LOG_LEVEL debug'),
|
|
30
|
+
],
|
|
18
31
|
schema: {
|
|
19
32
|
args: z.object({
|
|
20
33
|
key: z.string().describe('the environment variable key'),
|
|
21
34
|
value: z.string().describe('the environment variable value'),
|
|
22
35
|
}),
|
|
36
|
+
response: EnvSetResponseSchema,
|
|
23
37
|
},
|
|
24
38
|
|
|
25
39
|
async handler(ctx) {
|
|
@@ -45,7 +59,11 @@ export const setSubcommand = createSubcommand({
|
|
|
45
59
|
tui.info(
|
|
46
60
|
`Cancelled. Use "${getCommand('secret set')}" to store this as a secret instead.`
|
|
47
61
|
);
|
|
48
|
-
return
|
|
62
|
+
return {
|
|
63
|
+
success: false,
|
|
64
|
+
key: args.key,
|
|
65
|
+
path: '',
|
|
66
|
+
};
|
|
49
67
|
}
|
|
50
68
|
}
|
|
51
69
|
|
|
@@ -67,5 +85,11 @@ export const setSubcommand = createSubcommand({
|
|
|
67
85
|
await writeEnvFile(envFilePath, filteredEnv);
|
|
68
86
|
|
|
69
87
|
tui.success(`Environment variable '${args.key}' set successfully (cloud + ${envFilePath})`);
|
|
88
|
+
|
|
89
|
+
return {
|
|
90
|
+
success: true,
|
|
91
|
+
key: args.key,
|
|
92
|
+
path: envFilePath,
|
|
93
|
+
};
|
|
70
94
|
},
|
|
71
95
|
});
|
package/src/cmd/index.ts
CHANGED
|
@@ -22,7 +22,8 @@ export async function discoverCommands(): Promise<CommandDefinition[]> {
|
|
|
22
22
|
if (cmd.subcommands) {
|
|
23
23
|
for (const subcommand of cmd.subcommands) {
|
|
24
24
|
if (subcommand.toplevel) {
|
|
25
|
-
|
|
25
|
+
// eslint-disable-next-line @typescript-eslint/no-explicit-any
|
|
26
|
+
const alias: any = {
|
|
26
27
|
name: subcommand.name,
|
|
27
28
|
description: subcommand.description,
|
|
28
29
|
aliases: subcommand.aliases,
|
|
@@ -31,8 +32,14 @@ export async function discoverCommands(): Promise<CommandDefinition[]> {
|
|
|
31
32
|
optional: subcommand.optional,
|
|
32
33
|
schema: subcommand.schema,
|
|
33
34
|
handler: subcommand.handler,
|
|
35
|
+
// eslint-disable-next-line @typescript-eslint/no-explicit-any
|
|
36
|
+
idempotent: (subcommand as any).idempotent,
|
|
37
|
+
// eslint-disable-next-line @typescript-eslint/no-explicit-any
|
|
38
|
+
prerequisites: (subcommand as any).prerequisites,
|
|
39
|
+
// eslint-disable-next-line @typescript-eslint/no-explicit-any
|
|
40
|
+
tags: (subcommand as any).tags,
|
|
34
41
|
};
|
|
35
|
-
commands.push(alias);
|
|
42
|
+
commands.push(alias as CommandDefinition);
|
|
36
43
|
}
|
|
37
44
|
}
|
|
38
45
|
}
|
|
@@ -0,0 +1,45 @@
|
|
|
1
|
+
import { z } from 'zod';
|
|
2
|
+
import { createCommand } from '../../types';
|
|
3
|
+
import * as tui from '../../tui';
|
|
4
|
+
import { createStorageAdapter } from './util';
|
|
5
|
+
import { getCommand } from '../../command-prefix';
|
|
6
|
+
|
|
7
|
+
export const createNamespaceSubcommand = createCommand({
|
|
8
|
+
name: 'create-namespace',
|
|
9
|
+
aliases: ['create'],
|
|
10
|
+
description: 'Create a new keyvalue namespace',
|
|
11
|
+
tags: ['mutating', 'creates-resource', 'slow', 'requires-auth'],
|
|
12
|
+
idempotent: false,
|
|
13
|
+
requires: { auth: true, project: true },
|
|
14
|
+
examples: [
|
|
15
|
+
`${getCommand('kv create-namespace production')} - Create production namespace`,
|
|
16
|
+
`${getCommand('kv create staging')} - Create staging namespace (using alias)`,
|
|
17
|
+
`${getCommand('kv create cache')} - Create cache namespace`,
|
|
18
|
+
],
|
|
19
|
+
schema: {
|
|
20
|
+
args: z.object({
|
|
21
|
+
name: z.string().min(1).max(64).describe('the namespace name'),
|
|
22
|
+
}),
|
|
23
|
+
response: z.object({
|
|
24
|
+
success: z.boolean().describe('Whether the operation succeeded'),
|
|
25
|
+
namespace: z.string().describe('Namespace name'),
|
|
26
|
+
message: z.string().optional().describe('Success message'),
|
|
27
|
+
}),
|
|
28
|
+
},
|
|
29
|
+
|
|
30
|
+
async handler(ctx) {
|
|
31
|
+
const { args } = ctx;
|
|
32
|
+
const kv = await createStorageAdapter(ctx);
|
|
33
|
+
|
|
34
|
+
await kv.createNamespace(args.name);
|
|
35
|
+
tui.success(`Namespace ${tui.bold(args.name)} created`);
|
|
36
|
+
|
|
37
|
+
return {
|
|
38
|
+
success: true,
|
|
39
|
+
namespace: args.name,
|
|
40
|
+
message: `Namespace ${args.name} created`,
|
|
41
|
+
};
|
|
42
|
+
},
|
|
43
|
+
});
|
|
44
|
+
|
|
45
|
+
export default createNamespaceSubcommand;
|
|
@@ -0,0 +1,73 @@
|
|
|
1
|
+
import { z } from 'zod';
|
|
2
|
+
import { createCommand } from '../../types';
|
|
3
|
+
import { ErrorCode } from '../../errors';
|
|
4
|
+
import * as tui from '../../tui';
|
|
5
|
+
import { createStorageAdapter } from './util';
|
|
6
|
+
import { getCommand } from '../../command-prefix';
|
|
7
|
+
|
|
8
|
+
export const deleteNamespaceSubcommand = createCommand({
|
|
9
|
+
name: 'delete-namespace',
|
|
10
|
+
aliases: ['rm-namespace'],
|
|
11
|
+
description: 'Delete a keyvalue namespace and all its keys',
|
|
12
|
+
tags: ['destructive', 'deletes-resource', 'slow', 'requires-auth', 'requires-project'],
|
|
13
|
+
idempotent: true,
|
|
14
|
+
requires: { auth: true, project: true },
|
|
15
|
+
examples: [
|
|
16
|
+
`${getCommand('kv delete-namespace staging')} - Delete staging namespace (interactive)`,
|
|
17
|
+
`${getCommand('kv rm-namespace cache --confirm')} - Delete cache without confirmation`,
|
|
18
|
+
`${getCommand('kv delete-namespace production --confirm')} - Force delete production`,
|
|
19
|
+
],
|
|
20
|
+
schema: {
|
|
21
|
+
args: z.object({
|
|
22
|
+
name: z.string().min(1).max(64).describe('the namespace name'),
|
|
23
|
+
confirm: z
|
|
24
|
+
.boolean()
|
|
25
|
+
.optional()
|
|
26
|
+
.default(false)
|
|
27
|
+
.describe('if true will not prompt for confirmation'),
|
|
28
|
+
}),
|
|
29
|
+
response: z.object({
|
|
30
|
+
success: z.boolean().describe('Whether the deletion succeeded'),
|
|
31
|
+
namespace: z.string().describe('Deleted namespace name'),
|
|
32
|
+
message: z.string().optional().describe('Confirmation message'),
|
|
33
|
+
}),
|
|
34
|
+
},
|
|
35
|
+
|
|
36
|
+
async handler(ctx) {
|
|
37
|
+
const { args } = ctx;
|
|
38
|
+
const kv = await createStorageAdapter(ctx);
|
|
39
|
+
|
|
40
|
+
if (!args.confirm) {
|
|
41
|
+
if (!process.stdin.isTTY) {
|
|
42
|
+
tui.fatal(
|
|
43
|
+
'No TTY and --confirm is not set. Refusing to delete',
|
|
44
|
+
ErrorCode.VALIDATION_FAILED
|
|
45
|
+
);
|
|
46
|
+
}
|
|
47
|
+
tui.warning(`This will delete namespace ${tui.bold(args.name)} and ALL its keys.`);
|
|
48
|
+
const confirm = await new Promise<boolean>((resolve) => {
|
|
49
|
+
process.stdout.write('Are you sure? (yes/no): ');
|
|
50
|
+
process.stdin.once('data', (data) => {
|
|
51
|
+
const answer = data.toString().trim().toLowerCase();
|
|
52
|
+
resolve(answer === 'yes' || answer === 'y');
|
|
53
|
+
});
|
|
54
|
+
});
|
|
55
|
+
|
|
56
|
+
if (!confirm) {
|
|
57
|
+
tui.info('Cancelled');
|
|
58
|
+
return { success: false, namespace: args.name, message: 'Cancelled' };
|
|
59
|
+
}
|
|
60
|
+
}
|
|
61
|
+
|
|
62
|
+
await kv.deleteNamespace(args.name);
|
|
63
|
+
tui.success(`Namespace ${tui.bold(args.name)} deleted`);
|
|
64
|
+
|
|
65
|
+
return {
|
|
66
|
+
success: true,
|
|
67
|
+
namespace: args.name,
|
|
68
|
+
message: `Namespace ${args.name} deleted`,
|
|
69
|
+
};
|
|
70
|
+
},
|
|
71
|
+
});
|
|
72
|
+
|
|
73
|
+
export default deleteNamespaceSubcommand;
|
|
@@ -0,0 +1,51 @@
|
|
|
1
|
+
import { z } from 'zod';
|
|
2
|
+
import { createCommand } from '../../types';
|
|
3
|
+
import * as tui from '../../tui';
|
|
4
|
+
import { createStorageAdapter } from './util';
|
|
5
|
+
import { getCommand } from '../../command-prefix';
|
|
6
|
+
|
|
7
|
+
const KVDeleteResponseSchema = z.object({
|
|
8
|
+
success: z.boolean().describe('Whether the operation succeeded'),
|
|
9
|
+
namespace: z.string().describe('Namespace name'),
|
|
10
|
+
key: z.string().describe('Key name'),
|
|
11
|
+
durationMs: z.number().describe('Operation duration in milliseconds'),
|
|
12
|
+
});
|
|
13
|
+
|
|
14
|
+
export const deleteSubcommand = createCommand({
|
|
15
|
+
name: 'delete',
|
|
16
|
+
aliases: ['del', 'rm', 'remove'],
|
|
17
|
+
description: 'Delete a key from the keyvalue storage',
|
|
18
|
+
tags: ['destructive', 'deletes-resource', 'slow', 'requires-auth'],
|
|
19
|
+
idempotent: true,
|
|
20
|
+
requires: { auth: true, project: true },
|
|
21
|
+
examples: [
|
|
22
|
+
`${getCommand('kv delete production user:123')} - Delete user data`,
|
|
23
|
+
`${getCommand('kv delete cache session:abc')} - Delete cached session`,
|
|
24
|
+
`${getCommand('kv rm staging cache:homepage')} - Delete homepage cache (using alias)`,
|
|
25
|
+
],
|
|
26
|
+
schema: {
|
|
27
|
+
args: z.object({
|
|
28
|
+
namespace: z.string().min(1).describe('the namespace name'),
|
|
29
|
+
key: z.string().min(1).describe('the key name'),
|
|
30
|
+
}),
|
|
31
|
+
response: KVDeleteResponseSchema,
|
|
32
|
+
},
|
|
33
|
+
|
|
34
|
+
async handler(ctx) {
|
|
35
|
+
const { args } = ctx;
|
|
36
|
+
const started = Date.now();
|
|
37
|
+
const storage = await createStorageAdapter(ctx);
|
|
38
|
+
await storage.delete(args.namespace, args.key);
|
|
39
|
+
const durationMs = Date.now() - started;
|
|
40
|
+
tui.success(`deleted in ${durationMs.toFixed(1)}ms`);
|
|
41
|
+
|
|
42
|
+
return {
|
|
43
|
+
success: true,
|
|
44
|
+
namespace: args.namespace,
|
|
45
|
+
key: args.key,
|
|
46
|
+
durationMs,
|
|
47
|
+
};
|
|
48
|
+
},
|
|
49
|
+
});
|
|
50
|
+
|
|
51
|
+
export default deleteSubcommand;
|
|
@@ -0,0 +1,65 @@
|
|
|
1
|
+
import { z } from 'zod';
|
|
2
|
+
import { createCommand } from '../../types';
|
|
3
|
+
import * as tui from '../../tui';
|
|
4
|
+
import { tryParseJSON } from '../../json';
|
|
5
|
+
import { createStorageAdapter } from './util';
|
|
6
|
+
import { getCommand } from '../../command-prefix';
|
|
7
|
+
|
|
8
|
+
const KVGetResponseSchema = z.object({
|
|
9
|
+
exists: z.boolean().describe('Whether the key exists'),
|
|
10
|
+
data: z.union([z.string(), z.any()]).optional().describe('Value data (string or binary)'),
|
|
11
|
+
contentType: z.string().optional().describe('Content type'),
|
|
12
|
+
});
|
|
13
|
+
|
|
14
|
+
export const getSubcommand = createCommand({
|
|
15
|
+
name: 'get',
|
|
16
|
+
description: 'Get a value from the keyvalue storage',
|
|
17
|
+
tags: ['read-only', 'fast', 'requires-auth'],
|
|
18
|
+
requires: { auth: true, project: true },
|
|
19
|
+
examples: [
|
|
20
|
+
`${getCommand('kv get production user:123')} - Get user data`,
|
|
21
|
+
`${getCommand('kv get cache session:abc')} - Get cached session`,
|
|
22
|
+
`${getCommand('kv get staging cache:homepage')} - Get homepage cache`,
|
|
23
|
+
],
|
|
24
|
+
schema: {
|
|
25
|
+
args: z.object({
|
|
26
|
+
namespace: z.string().min(1).describe('the namespace name'),
|
|
27
|
+
key: z.string().min(1).describe('the key name'),
|
|
28
|
+
}),
|
|
29
|
+
response: KVGetResponseSchema,
|
|
30
|
+
},
|
|
31
|
+
idempotent: true,
|
|
32
|
+
|
|
33
|
+
async handler(ctx) {
|
|
34
|
+
const { args } = ctx;
|
|
35
|
+
const storage = await createStorageAdapter(ctx);
|
|
36
|
+
const started = Date.now();
|
|
37
|
+
const res = await storage.get(args.namespace, args.key);
|
|
38
|
+
if (res.exists) {
|
|
39
|
+
if (res.data) {
|
|
40
|
+
if (res.contentType?.includes('json')) {
|
|
41
|
+
const val = tryParseJSON(res.data as unknown as string);
|
|
42
|
+
tui.json(val);
|
|
43
|
+
} else if (res.contentType?.includes('text')) {
|
|
44
|
+
console.log(String(res.data));
|
|
45
|
+
} else {
|
|
46
|
+
const b = res.data as ArrayBuffer;
|
|
47
|
+
tui.info(`Read ${b.byteLength} bytes (${res.contentType})`);
|
|
48
|
+
}
|
|
49
|
+
tui.success(`retrieved in ${(Date.now() - started).toFixed(1)}ms (${res.contentType})`);
|
|
50
|
+
} else {
|
|
51
|
+
tui.warning(`${args.key} returned empty data for ${args.namespace}`);
|
|
52
|
+
}
|
|
53
|
+
} else {
|
|
54
|
+
tui.warning(`${args.key} does not exist in ${args.namespace}`);
|
|
55
|
+
}
|
|
56
|
+
|
|
57
|
+
return {
|
|
58
|
+
exists: res.exists,
|
|
59
|
+
data: res.data,
|
|
60
|
+
contentType: res.exists ? res.contentType : undefined,
|
|
61
|
+
};
|
|
62
|
+
},
|
|
63
|
+
});
|
|
64
|
+
|
|
65
|
+
export default getSubcommand;
|
|
@@ -0,0 +1,31 @@
|
|
|
1
|
+
import { createCommand } from '../../types';
|
|
2
|
+
import { createNamespaceSubcommand } from './create-namespace';
|
|
3
|
+
import { deleteSubcommand } from './delete';
|
|
4
|
+
import { deleteNamespaceSubcommand } from './delete-namespace';
|
|
5
|
+
import { getSubcommand } from './get';
|
|
6
|
+
import { keysSubcommand } from './keys';
|
|
7
|
+
import { listNamespacesSubcommand } from './list-namespaces';
|
|
8
|
+
import { replSubcommand } from './repl';
|
|
9
|
+
import { searchSubcommand } from './search';
|
|
10
|
+
import { setSubcommand } from './set';
|
|
11
|
+
import { statsSubcommand } from './stats';
|
|
12
|
+
|
|
13
|
+
export const command = createCommand({
|
|
14
|
+
name: 'keyvalue',
|
|
15
|
+
aliases: ['kv'],
|
|
16
|
+
description: 'Manage keyvalue storage for your projects',
|
|
17
|
+
tags: ['read-only', 'fast', 'requires-auth'],
|
|
18
|
+
subcommands: [
|
|
19
|
+
replSubcommand,
|
|
20
|
+
getSubcommand,
|
|
21
|
+
setSubcommand,
|
|
22
|
+
deleteSubcommand,
|
|
23
|
+
statsSubcommand,
|
|
24
|
+
searchSubcommand,
|
|
25
|
+
keysSubcommand,
|
|
26
|
+
listNamespacesSubcommand,
|
|
27
|
+
createNamespaceSubcommand,
|
|
28
|
+
deleteNamespaceSubcommand,
|
|
29
|
+
],
|
|
30
|
+
requires: { auth: true, project: true },
|
|
31
|
+
});
|
|
@@ -0,0 +1,57 @@
|
|
|
1
|
+
import { z } from 'zod';
|
|
2
|
+
import { createCommand } from '../../types';
|
|
3
|
+
import * as tui from '../../tui';
|
|
4
|
+
import { createStorageAdapter } from './util';
|
|
5
|
+
import { getCommand } from '../../command-prefix';
|
|
6
|
+
|
|
7
|
+
const KVKeysResponseSchema = z.object({
|
|
8
|
+
namespace: z.string().describe('Namespace name'),
|
|
9
|
+
keys: z.array(z.string()).describe('List of keys in the namespace'),
|
|
10
|
+
});
|
|
11
|
+
|
|
12
|
+
export const keysSubcommand = createCommand({
|
|
13
|
+
name: 'keys',
|
|
14
|
+
aliases: ['ls', 'list'],
|
|
15
|
+
description: 'List all keys in a keyvalue namespace',
|
|
16
|
+
tags: ['read-only', 'slow', 'requires-auth'],
|
|
17
|
+
requires: { auth: true, project: true },
|
|
18
|
+
idempotent: true,
|
|
19
|
+
examples: [
|
|
20
|
+
`${getCommand('kv keys production')} - List all keys in production`,
|
|
21
|
+
`${getCommand('kv ls cache')} - List all cached keys (using alias)`,
|
|
22
|
+
`${getCommand('kv list staging')} - List all staging keys`,
|
|
23
|
+
],
|
|
24
|
+
schema: {
|
|
25
|
+
args: z.object({
|
|
26
|
+
name: z.string().min(1).describe('the namespace name'),
|
|
27
|
+
}),
|
|
28
|
+
response: KVKeysResponseSchema,
|
|
29
|
+
},
|
|
30
|
+
|
|
31
|
+
async handler(ctx) {
|
|
32
|
+
const { args } = ctx;
|
|
33
|
+
const kv = await createStorageAdapter(ctx);
|
|
34
|
+
|
|
35
|
+
const keys = await kv.getKeys(args.name);
|
|
36
|
+
|
|
37
|
+
if (keys.length === 0) {
|
|
38
|
+
tui.info(`No keys found in namespace ${tui.bold(args.name)}`);
|
|
39
|
+
return {
|
|
40
|
+
namespace: args.name,
|
|
41
|
+
keys: [],
|
|
42
|
+
};
|
|
43
|
+
}
|
|
44
|
+
|
|
45
|
+
tui.info(`Found ${keys.length} key(s) in ${tui.bold(args.name)}:`);
|
|
46
|
+
for (const key of keys) {
|
|
47
|
+
tui.info(` ${key}`);
|
|
48
|
+
}
|
|
49
|
+
|
|
50
|
+
return {
|
|
51
|
+
namespace: args.name,
|
|
52
|
+
keys,
|
|
53
|
+
};
|
|
54
|
+
},
|
|
55
|
+
});
|
|
56
|
+
|
|
57
|
+
export default keysSubcommand;
|
|
@@ -0,0 +1,43 @@
|
|
|
1
|
+
import { z } from 'zod';
|
|
2
|
+
import { createCommand } from '../../types';
|
|
3
|
+
import * as tui from '../../tui';
|
|
4
|
+
import { createStorageAdapter } from './util';
|
|
5
|
+
import { getCommand } from '../../command-prefix';
|
|
6
|
+
|
|
7
|
+
const NamespaceListResponseSchema = z.array(z.string().describe('Namespace name'));
|
|
8
|
+
|
|
9
|
+
export const listNamespacesSubcommand = createCommand({
|
|
10
|
+
name: 'list-namespaces',
|
|
11
|
+
aliases: ['namespaces', 'ns'],
|
|
12
|
+
description: 'List all keyvalue namespaces',
|
|
13
|
+
tags: ['read-only', 'fast', 'requires-auth'],
|
|
14
|
+
requires: { auth: true, project: true },
|
|
15
|
+
examples: [
|
|
16
|
+
`${getCommand('kv list-namespaces')} - List all namespaces`,
|
|
17
|
+
`${getCommand('kv namespaces')} - List namespaces (using alias)`,
|
|
18
|
+
`${getCommand('kv ns')} - List namespaces (short alias)`,
|
|
19
|
+
],
|
|
20
|
+
schema: {
|
|
21
|
+
response: NamespaceListResponseSchema,
|
|
22
|
+
},
|
|
23
|
+
idempotent: true,
|
|
24
|
+
|
|
25
|
+
async handler(ctx) {
|
|
26
|
+
const storage = await createStorageAdapter(ctx);
|
|
27
|
+
const namespaces = await storage.getNamespaces();
|
|
28
|
+
|
|
29
|
+
if (namespaces.length === 0) {
|
|
30
|
+
tui.info('No namespaces found');
|
|
31
|
+
return [];
|
|
32
|
+
}
|
|
33
|
+
|
|
34
|
+
tui.info(`Found ${namespaces.length} namespace(s):`);
|
|
35
|
+
for (const name of namespaces) {
|
|
36
|
+
tui.arrow(name);
|
|
37
|
+
}
|
|
38
|
+
|
|
39
|
+
return namespaces;
|
|
40
|
+
},
|
|
41
|
+
});
|
|
42
|
+
|
|
43
|
+
export default listNamespacesSubcommand;
|