@masculinecache/wrangler-axi 0.1.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.
Files changed (42) hide show
  1. package/LICENSE +21 -0
  2. package/README.md +193 -0
  3. package/dist/bin/wrangler-axi.d.ts +2 -0
  4. package/dist/bin/wrangler-axi.js +17 -0
  5. package/dist/src/args.d.ts +19 -0
  6. package/dist/src/args.js +105 -0
  7. package/dist/src/cli.d.ts +27 -0
  8. package/dist/src/cli.js +101 -0
  9. package/dist/src/commands/d1.d.ts +2 -0
  10. package/dist/src/commands/d1.js +149 -0
  11. package/dist/src/commands/kv.d.ts +2 -0
  12. package/dist/src/commands/kv.js +423 -0
  13. package/dist/src/commands/pages.d.ts +2 -0
  14. package/dist/src/commands/pages.js +337 -0
  15. package/dist/src/commands/r2.d.ts +2 -0
  16. package/dist/src/commands/r2.js +289 -0
  17. package/dist/src/commands/secrets.d.ts +2 -0
  18. package/dist/src/commands/secrets.js +195 -0
  19. package/dist/src/commands/whoami.d.ts +2 -0
  20. package/dist/src/commands/whoami.js +60 -0
  21. package/dist/src/commands/workers.d.ts +2 -0
  22. package/dist/src/commands/workers.js +431 -0
  23. package/dist/src/errors.d.ts +6 -0
  24. package/dist/src/errors.js +77 -0
  25. package/dist/src/fields.d.ts +15 -0
  26. package/dist/src/fields.js +36 -0
  27. package/dist/src/format.d.ts +13 -0
  28. package/dist/src/format.js +21 -0
  29. package/dist/src/list.d.ts +18 -0
  30. package/dist/src/list.js +23 -0
  31. package/dist/src/stdin.d.ts +2 -0
  32. package/dist/src/stdin.js +14 -0
  33. package/dist/src/toon.d.ts +30 -0
  34. package/dist/src/toon.js +159 -0
  35. package/dist/src/util.d.ts +8 -0
  36. package/dist/src/util.js +26 -0
  37. package/dist/src/version.d.ts +1 -0
  38. package/dist/src/version.js +23 -0
  39. package/dist/src/wrangler.d.ts +64 -0
  40. package/dist/src/wrangler.js +175 -0
  41. package/package.json +48 -0
  42. package/skills/wrangler-axi/SKILL.md +82 -0
@@ -0,0 +1,423 @@
1
+ import { AxiError } from "../errors.js";
2
+ import { callWrangler, parseJson } from "../wrangler.js";
3
+ import { takeAllFlags, takeFlag, takeNumber } from "../args.js";
4
+ import { validateFlags, wantsHelp } from "../util.js";
5
+ import { addExtraDefs, parseFields, } from "../fields.js";
6
+ import { custom, field, renderDetail, renderHelp } from "../toon.js";
7
+ import { renderListBlock } from "../list.js";
8
+ const keyAvailable = {
9
+ expiration: { def: field("expiration") },
10
+ };
11
+ const nsAvailable = {
12
+ title: { def: field("title") },
13
+ };
14
+ const NS_FLAGS = ["--title", "--json", "--namespace-id"];
15
+ export const kvCommand = {
16
+ name: "kv",
17
+ description: "manage KV namespaces and keys",
18
+ help: [
19
+ "Usage: wrangler-axi kv <namespace|key> <sub> [args]",
20
+ " namespace <list|create|delete|rename>",
21
+ " key <list|get|put>",
22
+ "Example: wrangler-axi kv namespace list",
23
+ "Example: wrangler-axi kv key list --namespace-id <id>",
24
+ ],
25
+ async run(ctx, args) {
26
+ const sub = args[0];
27
+ if (sub === undefined || wantsHelp(args)) {
28
+ return { stdout: renderHelp(kvCommand.help), exitCode: 0 };
29
+ }
30
+ const rest = args.slice(1);
31
+ switch (sub) {
32
+ case "namespace":
33
+ return namespace(ctx, rest);
34
+ case "key":
35
+ return key(ctx, rest);
36
+ default:
37
+ throw new AxiError(`Unknown kv subcommand "${sub}"`, "VALIDATION_ERROR", [
38
+ "Run `wrangler-axi kv --help` for valid subcommands",
39
+ ]);
40
+ }
41
+ },
42
+ };
43
+ async function namespace(ctx, args) {
44
+ if (wantsHelp(args)) {
45
+ return {
46
+ stdout: renderHelp([
47
+ "Usage: wrangler-axi kv namespace <list|create|delete|rename> [args]",
48
+ " list — list KV namespaces",
49
+ " create <title> — create a namespace",
50
+ " delete <namespace-id> — delete a namespace",
51
+ " rename <old-name> — rename a namespace",
52
+ ]),
53
+ exitCode: 0,
54
+ };
55
+ }
56
+ const sub = args[0];
57
+ if (sub === undefined || sub.startsWith("-")) {
58
+ throw new AxiError("kv namespace requires a subcommand", "VALIDATION_ERROR", [
59
+ "Run `wrangler-axi kv namespace --help` for valid subcommands",
60
+ ]);
61
+ }
62
+ const rest = args.slice(1);
63
+ switch (sub) {
64
+ case "list":
65
+ return nsList(ctx, rest);
66
+ case "create":
67
+ return nsCreate(ctx, rest);
68
+ case "delete":
69
+ return nsDelete(ctx, rest);
70
+ case "rename":
71
+ return nsRename(ctx, rest);
72
+ default:
73
+ throw new AxiError(`Unknown kv namespace subcommand "${sub}"`, "VALIDATION_ERROR", [
74
+ "Run `wrangler-axi kv namespace --help` for valid subcommands",
75
+ ]);
76
+ }
77
+ }
78
+ async function nsList(ctx, args) {
79
+ if (wantsHelp(args)) {
80
+ return {
81
+ stdout: renderHelp([
82
+ "Usage: wrangler-axi kv namespace list [--fields] [--limit] [--full] [--json]",
83
+ ]),
84
+ exitCode: 0,
85
+ };
86
+ }
87
+ const json = takeAllFlags(args, ["--json"]).length > 0;
88
+ const full = takeAllFlags(args, ["--full"]).length > 0;
89
+ validateFlags(args, ["--fields", "--limit", "--full", "--json"], "kv namespace list");
90
+ // wrangler's `kv namespace list` rejects --json but already prints JSON.
91
+ const wArgs = ["kv", "namespace", "list"];
92
+ if (ctx.account) {
93
+ wArgs.push("--account", ctx.account);
94
+ }
95
+ const limit = full ? undefined : takeNumber(args, "--limit");
96
+ const fieldsArg = takeFlag(args, "--fields");
97
+ const { stdout } = await callWrangler(ctx.runner, wArgs);
98
+ if (json) {
99
+ return { stdout, exitCode: 0 };
100
+ }
101
+ const items = parseJson(stdout, "kv namespaces");
102
+ const { extraDefs } = parseFields(fieldsArg, nsAvailable);
103
+ const schema = addExtraDefs({
104
+ id: field("id"),
105
+ title: field("title"),
106
+ }, extraDefs);
107
+ return {
108
+ stdout: renderListBlock({
109
+ noun: "namespaces",
110
+ items,
111
+ schema,
112
+ limit,
113
+ empty: "namespaces: no KV namespaces found",
114
+ truncatedHint: "Run `wrangler-axi kv namespace list --json` for the full set",
115
+ }),
116
+ exitCode: 0,
117
+ };
118
+ }
119
+ async function nsCreate(ctx, args) {
120
+ if (wantsHelp(args)) {
121
+ return {
122
+ stdout: renderHelp([
123
+ "Usage: wrangler-axi kv namespace create <title> [--json]",
124
+ ]),
125
+ exitCode: 0,
126
+ };
127
+ }
128
+ validateFlags(args, ["--json"], "kv namespace create");
129
+ // wrangler's `kv namespace create` rejects --json and prints human output
130
+ // only, so --json is a wrapper-side escape hatch here.
131
+ const json = takeAllFlags(args, ["--json"]).length > 0;
132
+ const title = args.filter((a) => !a.startsWith("-"))[0];
133
+ if (!title) {
134
+ throw new AxiError("kv namespace create requires a title", "VALIDATION_ERROR", [
135
+ "Usage: wrangler-axi kv namespace create <title>",
136
+ ]);
137
+ }
138
+ const wArgs = ["kv", "namespace", "create", title];
139
+ if (ctx.account) {
140
+ wArgs.push("--account", ctx.account);
141
+ }
142
+ await callWrangler(ctx.runner, wArgs);
143
+ if (json) {
144
+ return { stdout: JSON.stringify({ title, status: "created" }, null, 2), exitCode: 0 };
145
+ }
146
+ return {
147
+ stdout: renderDetail("namespace", { title, status: "created" }, {
148
+ title: custom((d) => d.title),
149
+ status: custom((d) => d.status),
150
+ }),
151
+ exitCode: 0,
152
+ };
153
+ }
154
+ async function nsDelete(ctx, args) {
155
+ if (wantsHelp(args)) {
156
+ return {
157
+ stdout: renderHelp([
158
+ "Usage: wrangler-axi kv namespace delete <namespace-id> [--force]",
159
+ ]),
160
+ exitCode: 0,
161
+ };
162
+ }
163
+ validateFlags(args, ["--force"], "kv namespace delete");
164
+ const id = args.filter((a) => !a.startsWith("-"))[0];
165
+ if (!id) {
166
+ throw new AxiError("kv namespace delete requires a namespace id", "VALIDATION_ERROR", [
167
+ "Usage: wrangler-axi kv namespace delete <namespace-id>",
168
+ ]);
169
+ }
170
+ const wArgs = ["kv", "namespace", "delete", id];
171
+ if (ctx.account) {
172
+ wArgs.push("--account", ctx.account);
173
+ }
174
+ if (takeAllFlags(args, ["--force"]).length > 0) {
175
+ wArgs.push("-f");
176
+ }
177
+ await callWrangler(ctx.runner, wArgs);
178
+ return {
179
+ stdout: renderDetail("namespace", { id, status: "deleted" }, {
180
+ id: custom((d) => d.id),
181
+ status: custom((d) => d.status),
182
+ }),
183
+ exitCode: 0,
184
+ };
185
+ }
186
+ async function nsRename(ctx, args) {
187
+ if (wantsHelp(args)) {
188
+ return {
189
+ stdout: renderHelp([
190
+ "Usage: wrangler-axi kv namespace rename <old-name> [--title <new>]",
191
+ ]),
192
+ exitCode: 0,
193
+ };
194
+ }
195
+ validateFlags(args, ["--title"], "kv namespace rename");
196
+ // Take value-consuming flags before extracting the positional old name.
197
+ const title = takeFlag(args, "--title");
198
+ const oldName = args.filter((a) => !a.startsWith("-"))[0];
199
+ if (!oldName) {
200
+ throw new AxiError("kv namespace rename requires the current name", "VALIDATION_ERROR", [
201
+ "Usage: wrangler-axi kv namespace rename <old-name>",
202
+ ]);
203
+ }
204
+ const wArgs = ["kv", "namespace", "rename", oldName];
205
+ if (ctx.account) {
206
+ wArgs.push("--account", ctx.account);
207
+ }
208
+ if (title) {
209
+ wArgs.push("--title", title);
210
+ }
211
+ await callWrangler(ctx.runner, wArgs);
212
+ return {
213
+ stdout: renderDetail("namespace", { name: title ?? oldName, status: "renamed" }, {
214
+ name: custom((d) => d.name),
215
+ status: custom((d) => d.status),
216
+ }),
217
+ exitCode: 0,
218
+ };
219
+ }
220
+ async function key(ctx, args) {
221
+ if (wantsHelp(args)) {
222
+ return {
223
+ stdout: renderHelp([
224
+ "Usage: wrangler-axi kv key <list|get|put> [args]",
225
+ " list — list keys in a namespace",
226
+ " get <key> — get a key's value",
227
+ " put <key> <value> — write a key (or use --path)",
228
+ "Flag to select namespace: --namespace-id <id> (or --binding <name>)",
229
+ ]),
230
+ exitCode: 0,
231
+ };
232
+ }
233
+ const sub = args[0];
234
+ if (sub === undefined || sub.startsWith("-")) {
235
+ throw new AxiError("kv key requires a subcommand", "VALIDATION_ERROR", [
236
+ "Run `wrangler-axi kv key --help` for valid subcommands",
237
+ ]);
238
+ }
239
+ const rest = args.slice(1);
240
+ switch (sub) {
241
+ case "list":
242
+ return keyList(ctx, rest);
243
+ case "get":
244
+ return keyGet(ctx, rest);
245
+ case "put":
246
+ return keyPut(ctx, rest);
247
+ default:
248
+ throw new AxiError(`Unknown kv key subcommand "${sub}"`, "VALIDATION_ERROR", [
249
+ "Run `wrangler-axi kv key --help` for valid subcommands",
250
+ ]);
251
+ }
252
+ }
253
+ async function keyList(ctx, args) {
254
+ if (wantsHelp(args)) {
255
+ return {
256
+ stdout: renderHelp([
257
+ "Usage: wrangler-axi kv key list --namespace-id <id> [--prefix] [--fields] [--limit] [--full] [--json]",
258
+ ]),
259
+ exitCode: 0,
260
+ };
261
+ }
262
+ const json = takeAllFlags(args, ["--json"]).length > 0;
263
+ const full = takeAllFlags(args, ["--full"]).length > 0;
264
+ validateFlags(args, ["--namespace-id", "--binding", "--prefix", "--fields", "--limit", "--full", "--json"], "kv key list");
265
+ const wArgs = ["kv", "key", "list"];
266
+ if (ctx.account) {
267
+ wArgs.push("--account", ctx.account);
268
+ }
269
+ const nsId = takeFlag(args, "--namespace-id");
270
+ const binding = takeFlag(args, "--binding");
271
+ if (nsId) {
272
+ wArgs.push("--namespace-id", nsId);
273
+ }
274
+ else if (binding) {
275
+ wArgs.push("--binding", binding);
276
+ }
277
+ else {
278
+ throw new AxiError("kv key list requires --namespace-id or --binding", "VALIDATION_ERROR", [
279
+ "Run `wrangler-axi kv key list --help` for usage",
280
+ ]);
281
+ }
282
+ const prefix = takeFlag(args, "--prefix");
283
+ if (prefix !== undefined) {
284
+ wArgs.push("--prefix", prefix);
285
+ }
286
+ const limit = full ? undefined : takeNumber(args, "--limit");
287
+ const fieldsArg = takeFlag(args, "--fields");
288
+ const { stdout } = await callWrangler(ctx.runner, wArgs);
289
+ if (json) {
290
+ return { stdout, exitCode: 0 };
291
+ }
292
+ const items = parseJson(stdout, "kv keys");
293
+ const { extraDefs } = parseFields(fieldsArg, keyAvailable);
294
+ const schema = addExtraDefs({
295
+ name: field("name"),
296
+ }, extraDefs);
297
+ return {
298
+ stdout: renderListBlock({
299
+ noun: "keys",
300
+ items,
301
+ schema,
302
+ limit,
303
+ empty: "keys: no keys found in this namespace",
304
+ truncatedHint: "Run `wrangler-axi kv key list --namespace-id <id> --json` for the full set",
305
+ }),
306
+ exitCode: 0,
307
+ };
308
+ }
309
+ async function keyGet(ctx, args) {
310
+ if (wantsHelp(args)) {
311
+ return {
312
+ stdout: renderHelp([
313
+ "Usage: wrangler-axi kv key get <key> --namespace-id <id> [--text]",
314
+ ]),
315
+ exitCode: 0,
316
+ };
317
+ }
318
+ validateFlags(args, ["--namespace-id", "--binding", "--text"], "kv key get");
319
+ // Take value-consuming flags before extracting the positional key name.
320
+ const nsId = takeFlag(args, "--namespace-id");
321
+ const binding = takeFlag(args, "--binding");
322
+ const name = args.filter((a) => !a.startsWith("-"))[0];
323
+ if (!name) {
324
+ throw new AxiError("kv key get requires a key name", "VALIDATION_ERROR", [
325
+ "Usage: wrangler-axi kv key get <key> --namespace-id <id>|--binding <b>",
326
+ ]);
327
+ }
328
+ const wArgs = ["kv", "key", "get", name, "--text"];
329
+ if (ctx.account) {
330
+ wArgs.push("--account", ctx.account);
331
+ }
332
+ if (nsId) {
333
+ wArgs.push("--namespace-id", nsId);
334
+ }
335
+ else if (binding) {
336
+ wArgs.push("--binding", binding);
337
+ }
338
+ else {
339
+ throw new AxiError("kv key get requires --namespace-id or --binding", "VALIDATION_ERROR", [
340
+ "Run `wrangler-axi kv key get --help` for usage",
341
+ ]);
342
+ }
343
+ const { stdout } = await callWrangler(ctx.runner, wArgs);
344
+ return {
345
+ stdout: renderDetail("key", { name, value: stdout.replace(/\n$/, "") }, {
346
+ name: custom((d) => d.name),
347
+ value: custom((d) => d.value || "(empty)"),
348
+ }),
349
+ exitCode: 0,
350
+ };
351
+ }
352
+ async function keyPut(ctx, args) {
353
+ if (wantsHelp(args)) {
354
+ return {
355
+ stdout: renderHelp([
356
+ "Usage: wrangler-axi kv key put <key> <value> --namespace-id <id>",
357
+ " wrangler-axi kv key put <key> --path <file> --namespace-id <id>",
358
+ ]),
359
+ exitCode: 0,
360
+ };
361
+ }
362
+ validateFlags(args, ["--namespace-id", "--binding", "--path", "--ttl", "--expiration", "--metadata"], "kv key put");
363
+ // Take every value-consuming flag BEFORE capturing positionals, so a
364
+ // space-form flag value (e.g. `--namespace-id ns1`) is not misread as the
365
+ // key value and silently written to KV. Only the key and value remain.
366
+ const nsId = takeFlag(args, "--namespace-id");
367
+ const binding = takeFlag(args, "--binding");
368
+ const path = takeFlag(args, "--path");
369
+ const ttl = takeFlag(args, "--ttl");
370
+ const expiration = takeFlag(args, "--expiration");
371
+ const metadata = takeFlag(args, "--metadata");
372
+ const positional = args.filter((a) => !a.startsWith("-"));
373
+ const name = positional[0];
374
+ if (!name) {
375
+ throw new AxiError("kv key put requires a key name", "VALIDATION_ERROR", [
376
+ "Usage: wrangler-axi kv key put <key> <value|--path <p>> --namespace-id <id>|--binding <b>",
377
+ ]);
378
+ }
379
+ const wArgs = ["kv", "key", "put", name];
380
+ if (ctx.account) {
381
+ wArgs.push("--account", ctx.account);
382
+ }
383
+ if (nsId) {
384
+ wArgs.push("--namespace-id", nsId);
385
+ }
386
+ else if (binding) {
387
+ wArgs.push("--binding", binding);
388
+ }
389
+ else {
390
+ throw new AxiError("kv key put requires --namespace-id or --binding", "VALIDATION_ERROR", [
391
+ "Run `wrangler-axi kv key put --help` for usage",
392
+ ]);
393
+ }
394
+ if (path) {
395
+ wArgs.push("--path", path);
396
+ }
397
+ else {
398
+ const value = positional[1];
399
+ if (value === undefined) {
400
+ throw new AxiError("kv key put requires a value or --path", "VALIDATION_ERROR", [
401
+ "Usage: wrangler-axi kv key put <key> <value> or --path <file>",
402
+ ]);
403
+ }
404
+ wArgs.push(value);
405
+ }
406
+ if (ttl !== undefined) {
407
+ wArgs.push("--ttl", ttl);
408
+ }
409
+ if (expiration !== undefined) {
410
+ wArgs.push("--expiration", expiration);
411
+ }
412
+ if (metadata !== undefined) {
413
+ wArgs.push("--metadata", metadata);
414
+ }
415
+ await callWrangler(ctx.runner, wArgs);
416
+ return {
417
+ stdout: renderDetail("key", { name, status: "written" }, {
418
+ name: custom((d) => d.name),
419
+ status: custom((d) => d.status),
420
+ }),
421
+ exitCode: 0,
422
+ };
423
+ }
@@ -0,0 +1,2 @@
1
+ import type { CommandArea } from "../cli.js";
2
+ export declare const pagesCommand: CommandArea;