@contextual-io/cli 0.4.0 → 0.6.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 CHANGED
@@ -20,7 +20,7 @@ $ npm install -g @contextual-io/cli
20
20
  $ ctxl COMMAND
21
21
  running command...
22
22
  $ ctxl (--version)
23
- @contextual-io/cli/0.4.0 linux-x64 node-v25.2.1
23
+ @contextual-io/cli/0.6.0 linux-x64 node-v25.2.1
24
24
  $ ctxl --help [COMMAND]
25
25
  USAGE
26
26
  $ ctxl COMMAND
@@ -46,8 +46,13 @@ USAGE
46
46
  * [`ctxl records get [URI]`](#ctxl-records-get-uri)
47
47
  * [`ctxl records import [URI]`](#ctxl-records-import-uri)
48
48
  * [`ctxl records list [URI]`](#ctxl-records-list-uri)
49
+ * [`ctxl records patch [URI]`](#ctxl-records-patch-uri)
49
50
  * [`ctxl records query [URI]`](#ctxl-records-query-uri)
51
+ * [`ctxl records remove [URI]`](#ctxl-records-remove-uri)
50
52
  * [`ctxl records replace [URI]`](#ctxl-records-replace-uri)
53
+ * [`ctxl records rm [URI]`](#ctxl-records-rm-uri)
54
+ * [`ctxl records search [URI]`](#ctxl-records-search-uri)
55
+ * [`ctxl records stats [URI]`](#ctxl-records-stats-uri)
51
56
  * [`ctxl types <COMMAND>`](#ctxl-types-command)
52
57
  * [`ctxl types add`](#ctxl-types-add)
53
58
  * [`ctxl types create`](#ctxl-types-create)
@@ -55,7 +60,10 @@ USAGE
55
60
  * [`ctxl types get [URI]`](#ctxl-types-get-uri)
56
61
  * [`ctxl types import`](#ctxl-types-import)
57
62
  * [`ctxl types list`](#ctxl-types-list)
63
+ * [`ctxl types remove [URI]`](#ctxl-types-remove-uri)
58
64
  * [`ctxl types replace [URI]`](#ctxl-types-replace-uri)
65
+ * [`ctxl types rm [URI]`](#ctxl-types-rm-uri)
66
+ * [`ctxl types search`](#ctxl-types-search)
59
67
 
60
68
  ## `ctxl autocomplete [SHELL]`
61
69
 
@@ -106,14 +114,12 @@ Add a new config.
106
114
 
107
115
  ```
108
116
  USAGE
109
- $ ctxl config add CONFIG-ID [-s prod|qa|dev] [-t <value>]
117
+ $ ctxl config add CONFIG-ID [-t <value>]
110
118
 
111
119
  ARGUMENTS
112
120
  CONFIG-ID id of config
113
121
 
114
122
  FLAGS
115
- -s, --silo=<option> [default: prod] silo
116
- <options: prod|qa|dev>
117
123
  -t, --tenant-id=<value> tenant id (if different from config id)
118
124
 
119
125
  DESCRIPTION
@@ -333,14 +339,14 @@ Delete record(s).
333
339
 
334
340
  ```
335
341
  USAGE
336
- $ ctxl records delete [URI] [-C <value>] [-i <value>...] [-T <value>]
342
+ $ ctxl records delete [URI] [-C <value>] [-I <value>...] [-T <value>]
337
343
 
338
344
  ARGUMENTS
339
345
  [URI] uri of record
340
346
 
341
347
  FLAGS
348
+ -I, --id=<value>... id(s)
342
349
  -T, --type=<value> type
343
- -i, --id=<value>... id(s)
344
350
 
345
351
  GLOBAL FLAGS
346
352
  -C, --config-id=<value> Specify config id to use for call.
@@ -348,6 +354,10 @@ GLOBAL FLAGS
348
354
  DESCRIPTION
349
355
  Delete record(s).
350
356
 
357
+ ALIASES
358
+ $ ctxl records rm
359
+ $ ctxl records remove
360
+
351
361
  EXAMPLES
352
362
  $ ctxl records delete native-object:my-type/instance-1
353
363
 
@@ -366,14 +376,14 @@ Get a record.
366
376
 
367
377
  ```
368
378
  USAGE
369
- $ ctxl records get [URI] [-C <value>] [-i <value>...] [-T <value>]
379
+ $ ctxl records get [URI] [-C <value>] [-I <value>...] [-T <value>]
370
380
 
371
381
  ARGUMENTS
372
382
  [URI] uri of record
373
383
 
374
384
  FLAGS
385
+ -I, --id=<value>... id(s)
375
386
  -T, --type=<value> type
376
- -i, --id=<value>... id(s)
377
387
 
378
388
  GLOBAL FLAGS
379
389
  -C, --config-id=<value> Specify config id to use for call.
@@ -455,6 +465,9 @@ GLOBAL FLAGS
455
465
  DESCRIPTION
456
466
  List records.
457
467
 
468
+ ALIASES
469
+ $ ctxl records search
470
+
458
471
  EXAMPLES
459
472
  $ ctxl records list native-object:my-type
460
473
 
@@ -465,6 +478,41 @@ EXAMPLES
465
478
  $ ctxl records list --type my-type -s field1=value1 -s field2=value2 --include-total
466
479
  ```
467
480
 
481
+ ## `ctxl records patch [URI]`
482
+
483
+ Patch a record.
484
+
485
+ ```
486
+ USAGE
487
+ $ ctxl records patch [URI] [-C <value>] [-a <value>...] [-I <value>] [-i <value>...] [-d <value>...] [-r
488
+ <value>...] [-s <value>...] [-T <value>]
489
+
490
+ ARGUMENTS
491
+ [URI] uri of record
492
+
493
+ FLAGS
494
+ -I, --id=<value> id
495
+ -T, --type=<value> type
496
+ -a, --add=<value>... add field
497
+ -d, --remove=<value>... remove field
498
+ -i, --increment=<value>... increment field
499
+ -r, --replace=<value>... replace field
500
+ -s, --set=<value>... set field
501
+
502
+ GLOBAL FLAGS
503
+ -C, --config-id=<value> Specify config id to use for call.
504
+
505
+ DESCRIPTION
506
+ Patch a record.
507
+
508
+ EXAMPLES
509
+ $ ctxl records patch native-object:my-type/instance-1 --set field1=value1
510
+
511
+ $ ctxl records patch native-object:my-type --id instance-1 --remove field2
512
+
513
+ $ ctxl records patch --type my-type --id instance-1 --increment field3=2
514
+ ```
515
+
468
516
  ## `ctxl records query [URI]`
469
517
 
470
518
  Query records.
@@ -503,20 +551,57 @@ EXAMPLES
503
551
  $ ctxl records query --type my-type --include-total --query-file query.json
504
552
  ```
505
553
 
554
+ ## `ctxl records remove [URI]`
555
+
556
+ Delete record(s).
557
+
558
+ ```
559
+ USAGE
560
+ $ ctxl records remove [URI] [-C <value>] [-I <value>...] [-T <value>]
561
+
562
+ ARGUMENTS
563
+ [URI] uri of record
564
+
565
+ FLAGS
566
+ -I, --id=<value>... id(s)
567
+ -T, --type=<value> type
568
+
569
+ GLOBAL FLAGS
570
+ -C, --config-id=<value> Specify config id to use for call.
571
+
572
+ DESCRIPTION
573
+ Delete record(s).
574
+
575
+ ALIASES
576
+ $ ctxl records rm
577
+ $ ctxl records remove
578
+
579
+ EXAMPLES
580
+ $ ctxl records remove native-object:my-type/instance-1
581
+
582
+ $ ctxl records remove native-object:my-type --id instance-1
583
+
584
+ $ ctxl records remove native-object:my-type --id instance-1 --id instance-2
585
+
586
+ $ ctxl records remove --type my-type --id instance-1
587
+
588
+ $ ctxl records remove --type my-type --id instance-1 --id instance-2
589
+ ```
590
+
506
591
  ## `ctxl records replace [URI]`
507
592
 
508
593
  Replace a record.
509
594
 
510
595
  ```
511
596
  USAGE
512
- $ ctxl records replace [URI] [-C <value>] [-i <value>] [-i <value>] [-T <value>]
597
+ $ ctxl records replace [URI] [-C <value>] [-I <value>] [-i <value>] [-T <value>]
513
598
 
514
599
  ARGUMENTS
515
600
  [URI] uri of record
516
601
 
517
602
  FLAGS
603
+ -I, --id=<value> id
518
604
  -T, --type=<value> type
519
- -i, --id=<value> id
520
605
  -i, --input-file=<value> [default: -] file to read. can read stdin if value is '-'
521
606
 
522
607
  GLOBAL FLAGS
@@ -533,6 +618,116 @@ EXAMPLES
533
618
  $ ctxl records replace --type my-type --id instance-1 --input-file record.json
534
619
  ```
535
620
 
621
+ ## `ctxl records rm [URI]`
622
+
623
+ Delete record(s).
624
+
625
+ ```
626
+ USAGE
627
+ $ ctxl records rm [URI] [-C <value>] [-I <value>...] [-T <value>]
628
+
629
+ ARGUMENTS
630
+ [URI] uri of record
631
+
632
+ FLAGS
633
+ -I, --id=<value>... id(s)
634
+ -T, --type=<value> type
635
+
636
+ GLOBAL FLAGS
637
+ -C, --config-id=<value> Specify config id to use for call.
638
+
639
+ DESCRIPTION
640
+ Delete record(s).
641
+
642
+ ALIASES
643
+ $ ctxl records rm
644
+ $ ctxl records remove
645
+
646
+ EXAMPLES
647
+ $ ctxl records rm native-object:my-type/instance-1
648
+
649
+ $ ctxl records rm native-object:my-type --id instance-1
650
+
651
+ $ ctxl records rm native-object:my-type --id instance-1 --id instance-2
652
+
653
+ $ ctxl records rm --type my-type --id instance-1
654
+
655
+ $ ctxl records rm --type my-type --id instance-1 --id instance-2
656
+ ```
657
+
658
+ ## `ctxl records search [URI]`
659
+
660
+ List records.
661
+
662
+ ```
663
+ USAGE
664
+ $ ctxl records search [URI] [-C <value>] [-S <value>...] [-e] [-f <value>...] [--include-total] [-o <value>...]
665
+ [--page-size <value>] [--page-token <value>] [-p] [-s <value>...] [-t <value>...] [-T <value>]
666
+
667
+ ARGUMENTS
668
+ [URI] uri of type
669
+
670
+ FLAGS
671
+ -S, --exact-search=<value>... search fields exactly
672
+ -T, --type=<value> type
673
+ -e, --export export data as JSONL
674
+ -f, --from=<value>... search from
675
+ -o, --order-by=<value>... order fields
676
+ -p, --progress show progress during export
677
+ -s, --search=<value>... search fields
678
+ -t, --to=<value>... search to
679
+ --include-total include total count
680
+ --page-size=<value> number of records per page
681
+ --page-token=<value> page token to fetch
682
+
683
+ GLOBAL FLAGS
684
+ -C, --config-id=<value> Specify config id to use for call.
685
+
686
+ DESCRIPTION
687
+ List records.
688
+
689
+ ALIASES
690
+ $ ctxl records search
691
+
692
+ EXAMPLES
693
+ $ ctxl records search native-object:my-type
694
+
695
+ $ ctxl records search --type my-type
696
+
697
+ $ ctxl records search --type my-type --order-by field1:desc
698
+
699
+ $ ctxl records search --type my-type -s field1=value1 -s field2=value2 --include-total
700
+ ```
701
+
702
+ ## `ctxl records stats [URI]`
703
+
704
+ Get the stats of a record.
705
+
706
+ ```
707
+ USAGE
708
+ $ ctxl records stats [URI] [-C <value>] [-I <value>] [-T <value>]
709
+
710
+ ARGUMENTS
711
+ [URI] uri of record
712
+
713
+ FLAGS
714
+ -I, --id=<value> id
715
+ -T, --type=<value> type
716
+
717
+ GLOBAL FLAGS
718
+ -C, --config-id=<value> Specify config id to use for call.
719
+
720
+ DESCRIPTION
721
+ Get the stats of a record.
722
+
723
+ EXAMPLES
724
+ $ ctxl records stats native-object:my-type/instance-1
725
+
726
+ $ ctxl records stats native-object:my-type --id instance-1
727
+
728
+ $ ctxl records stats --type my-type --id instance-1
729
+ ```
730
+
536
731
  ## `ctxl types <COMMAND>`
537
732
 
538
733
  Manage types.
@@ -619,6 +814,10 @@ GLOBAL FLAGS
619
814
  DESCRIPTION
620
815
  Delete a type.
621
816
 
817
+ ALIASES
818
+ $ ctxl types rm
819
+ $ ctxl types remove
820
+
622
821
  EXAMPLES
623
822
  $ ctxl types delete native-object:my-type
624
823
 
@@ -705,6 +904,9 @@ GLOBAL FLAGS
705
904
  DESCRIPTION
706
905
  List types.
707
906
 
907
+ ALIASES
908
+ $ ctxl types search
909
+
708
910
  EXAMPLES
709
911
  $ ctxl types list
710
912
 
@@ -713,6 +915,36 @@ EXAMPLES
713
915
  $ ctxl types list -s field1=value1 -s field2=value2 --include-total
714
916
  ```
715
917
 
918
+ ## `ctxl types remove [URI]`
919
+
920
+ Delete a type.
921
+
922
+ ```
923
+ USAGE
924
+ $ ctxl types remove [URI] [-C <value>] [-T <value>]
925
+
926
+ ARGUMENTS
927
+ [URI] uri of type
928
+
929
+ FLAGS
930
+ -T, --type=<value> type
931
+
932
+ GLOBAL FLAGS
933
+ -C, --config-id=<value> Specify config id to use for call.
934
+
935
+ DESCRIPTION
936
+ Delete a type.
937
+
938
+ ALIASES
939
+ $ ctxl types rm
940
+ $ ctxl types remove
941
+
942
+ EXAMPLES
943
+ $ ctxl types remove native-object:my-type
944
+
945
+ $ ctxl types remove --type my-type
946
+ ```
947
+
716
948
  ## `ctxl types replace [URI]`
717
949
 
718
950
  Replace a type.
@@ -739,4 +971,72 @@ EXAMPLES
739
971
 
740
972
  $ ctxl types replace --type my-type --input-file record.json
741
973
  ```
974
+
975
+ ## `ctxl types rm [URI]`
976
+
977
+ Delete a type.
978
+
979
+ ```
980
+ USAGE
981
+ $ ctxl types rm [URI] [-C <value>] [-T <value>]
982
+
983
+ ARGUMENTS
984
+ [URI] uri of type
985
+
986
+ FLAGS
987
+ -T, --type=<value> type
988
+
989
+ GLOBAL FLAGS
990
+ -C, --config-id=<value> Specify config id to use for call.
991
+
992
+ DESCRIPTION
993
+ Delete a type.
994
+
995
+ ALIASES
996
+ $ ctxl types rm
997
+ $ ctxl types remove
998
+
999
+ EXAMPLES
1000
+ $ ctxl types rm native-object:my-type
1001
+
1002
+ $ ctxl types rm --type my-type
1003
+ ```
1004
+
1005
+ ## `ctxl types search`
1006
+
1007
+ List types.
1008
+
1009
+ ```
1010
+ USAGE
1011
+ $ ctxl types search [-C <value>] [-S <value>...] [-e] [-f <value>...] [--include-total] [-o <value>...]
1012
+ [--page-size <value>] [--page-token <value>] [-p] [-s <value>...] [-t <value>...]
1013
+
1014
+ FLAGS
1015
+ -S, --exact-search=<value>... search fields exactly
1016
+ -e, --export export data as JSONL
1017
+ -f, --from=<value>... search from
1018
+ -o, --order-by=<value>... order fields
1019
+ -p, --progress show progress during export
1020
+ -s, --search=<value>... search fields
1021
+ -t, --to=<value>... search to
1022
+ --include-total include total count
1023
+ --page-size=<value> number of types per page
1024
+ --page-token=<value> page token to fetch
1025
+
1026
+ GLOBAL FLAGS
1027
+ -C, --config-id=<value> Specify config id to use for call.
1028
+
1029
+ DESCRIPTION
1030
+ List types.
1031
+
1032
+ ALIASES
1033
+ $ ctxl types search
1034
+
1035
+ EXAMPLES
1036
+ $ ctxl types search
1037
+
1038
+ $ ctxl types search --order-by field1:desc
1039
+
1040
+ $ ctxl types search -s field1=value1 -s field2=value2 --include-total
1041
+ ```
742
1042
  <!-- commandsstop -->
package/dist/base.d.ts CHANGED
@@ -7,7 +7,11 @@ export type Args<T extends typeof Command> = Interfaces.InferredArgs<T["args"]>;
7
7
  declare class CommandConfig {
8
8
  private readonly configDir;
9
9
  constructor(configDir: string);
10
- clean(configId: UrlSafeId, { silo, tenantId }: Config): CleanConfig;
10
+ cleanJson(configId: UrlSafeId, { silo, tenantId }: Config): CleanConfig;
11
+ cleanTable(configId: UrlSafeId, config: Config): {
12
+ tenantId: string;
13
+ configId: string;
14
+ };
11
15
  get(configId?: UrlSafeId): Promise<{
12
16
  config: Config;
13
17
  lookup: string;
package/dist/base.js CHANGED
@@ -13,12 +13,25 @@ class CommandConfig {
13
13
  constructor(configDir) {
14
14
  this.configDir = configDir;
15
15
  }
16
- clean(configId, { silo, tenantId }) {
17
- return {
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,11 +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
- if (!(err instanceof HttpError)) {
118
- await this.showHelp();
119
- }
120
133
  }
121
134
  this.exit(exitCode);
122
135
  }
@@ -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)" }),
@@ -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.clean(lookup, config);
13
+ return this.userConfig.cleanJson(lookup, config);
14
14
  }
15
15
  }
@@ -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: [rv],
20
+ data: [this.userConfig.cleanTable(lookup, config)],
22
21
  }));
23
- return rv;
22
+ return this.userConfig.cleanJson(lookup, config);
24
23
  }
25
24
  }
@@ -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: configs.map(c => colorize(c)),
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
  }
@@ -1,5 +1,6 @@
1
1
  import { BaseCommand } from "../../base.js";
2
2
  export default class RecordsDelete extends BaseCommand<typeof RecordsDelete> {
3
+ static aliases: string[];
3
4
  static args: {
4
5
  uri: import("@oclif/core/interfaces").Arg<string | undefined, Record<string, unknown>>;
5
6
  };
@@ -3,6 +3,7 @@ import { BaseCommand } from "../../base.js";
3
3
  import { parseUri } from "../../models/uri.js";
4
4
  import { getNativeObjectApiEndpoint } from "../../utils/endpoints.js";
5
5
  export default class RecordsDelete extends BaseCommand {
6
+ static aliases = ["records rm", "records remove"];
6
7
  static args = {
7
8
  "uri": Args.string({ description: "uri of record" }),
8
9
  };
@@ -16,7 +17,7 @@ export default class RecordsDelete extends BaseCommand {
16
17
  ];
17
18
  static flags = {
18
19
  id: Flags.string({
19
- char: "i",
20
+ char: "I",
20
21
  description: "id(s)",
21
22
  multiple: true,
22
23
  }),
@@ -16,7 +16,7 @@ export default class RecordsGet extends BaseCommand {
16
16
  ];
17
17
  static flags = {
18
18
  id: Flags.string({
19
- char: "i",
19
+ char: "I",
20
20
  description: "id(s)",
21
21
  multiple: true,
22
22
  }),
@@ -1,5 +1,6 @@
1
1
  import { BaseCommand } from "../../base.js";
2
2
  export default class RecordsList extends BaseCommand<typeof RecordsList> {
3
+ static aliases: string[];
3
4
  static args: {
4
5
  uri: import("@oclif/core/interfaces").Arg<string | undefined, Record<string, unknown>>;
5
6
  };
@@ -9,6 +9,7 @@ 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
  };
@@ -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
+ }
@@ -17,7 +17,7 @@ export default class RecordsReplace extends BaseCommand {
17
17
  ];
18
18
  static flags = {
19
19
  id: Flags.string({
20
- char: "i",
20
+ char: "I",
21
21
  description: "id",
22
22
  }),
23
23
  "input-file": Flags.file({
@@ -0,0 +1,13 @@
1
+ import { BaseCommand } from "../../base.js";
2
+ export default class RecordsStats extends BaseCommand<typeof RecordsStats> {
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
+ id: import("@oclif/core/interfaces").OptionFlag<string | undefined, import("@oclif/core/interfaces").CustomOptions>;
10
+ type: import("@oclif/core/interfaces").OptionFlag<string | undefined, import("@oclif/core/interfaces").CustomOptions>;
11
+ };
12
+ run(): Promise<void>;
13
+ }
@@ -0,0 +1,73 @@
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 bytesToString = (bytes) => {
6
+ if (bytes < 1000)
7
+ return `${bytes} B`;
8
+ bytes /= 1000;
9
+ if (bytes < 1000)
10
+ return `${bytes.toFixed(2)} kB`;
11
+ bytes /= 1000;
12
+ if (bytes < 1000)
13
+ return `${bytes.toFixed(2)} MB`;
14
+ bytes /= 1000;
15
+ return `${bytes.toFixed(2)} GB`;
16
+ };
17
+ export default class RecordsStats extends BaseCommand {
18
+ static args = {
19
+ "uri": Args.string({ description: "uri of record" }),
20
+ };
21
+ static description = "Get the stats of a record.";
22
+ static examples = [
23
+ "<%= config.bin %> <%= command.id %> native-object:my-type/instance-1",
24
+ "<%= config.bin %> <%= command.id %> native-object:my-type --id instance-1",
25
+ "<%= config.bin %> <%= command.id %> --type my-type --id instance-1",
26
+ ];
27
+ static flags = {
28
+ id: Flags.string({
29
+ char: "I",
30
+ description: "id",
31
+ }),
32
+ type: Flags.string({
33
+ char: "T",
34
+ description: "type",
35
+ }),
36
+ };
37
+ async run() {
38
+ const { uri } = this.args;
39
+ const { id: flagId, type: flagType } = this.flags;
40
+ let type = flagType;
41
+ let lookup = flagId;
42
+ if (uri) {
43
+ const { id, type: uriType } = parseUri(uri);
44
+ type = uriType;
45
+ if (id) {
46
+ lookup = id;
47
+ }
48
+ }
49
+ if (!type) {
50
+ throw new Error("Type not provided");
51
+ }
52
+ if (!lookup) {
53
+ throw new Error("Id not provided");
54
+ }
55
+ const record = await this.fetch(({ silo, tenantId }) => getNativeObjectApiEndpoint(tenantId, silo) + `/api/v1/${type}/${lookup}`);
56
+ const totalBytes = Buffer.byteLength(JSON.stringify(record));
57
+ const { _metaData, ...data } = record;
58
+ const bytesWithoutMetaData = Buffer.byteLength(JSON.stringify(data));
59
+ const rv = { total: bytesToString(totalBytes), withoutMetaData: bytesToString(bytesWithoutMetaData) };
60
+ if (type === "flow") {
61
+ const nodes = data.node_red_data.flows;
62
+ const largestFiveNodes = nodes
63
+ .map(n => [n, Buffer.byteLength(JSON.stringify(n))])
64
+ .sort(([, sizeA], [, sizeB]) => sizeA - sizeB)
65
+ .slice(-5)
66
+ .map(([{ id, name }, size]) => ({ id, name, size: bytesToString(size) }));
67
+ this.logJson({ ...rv, largestFiveNodes });
68
+ }
69
+ else {
70
+ this.logJson(rv);
71
+ }
72
+ }
73
+ }
@@ -1,5 +1,6 @@
1
1
  import { BaseCommand } from "../../base.js";
2
2
  export default class TypesDelete extends BaseCommand<typeof TypesDelete> {
3
+ static aliases: string[];
3
4
  static args: {
4
5
  uri: import("@oclif/core/interfaces").Arg<string | undefined, Record<string, unknown>>;
5
6
  };
@@ -3,6 +3,7 @@ import { BaseCommand } from "../../base.js";
3
3
  import { parseUri } from "../../models/uri.js";
4
4
  import { getRegistryApiEndpoint } from "../../utils/endpoints.js";
5
5
  export default class TypesDelete extends BaseCommand {
6
+ static aliases = ["types rm", "types remove"];
6
7
  static args = {
7
8
  "uri": Args.string({ description: "uri of type" }),
8
9
  };
@@ -1,5 +1,6 @@
1
1
  import { BaseCommand } from "../../base.js";
2
2
  export default class TypesList extends BaseCommand<typeof TypesList> {
3
+ static aliases: string[];
3
4
  static args: {};
4
5
  static description: string;
5
6
  static examples: string[];
@@ -8,6 +8,7 @@ const flagArrayToParam = (cmd, values) => values
8
8
  .map(([k, v]) => ({ [`${cmd}.${k}`]: v }))
9
9
  .reduce((a, b) => ({ ...a, ...b }), {});
10
10
  export default class TypesList extends BaseCommand {
11
+ static aliases = ["types search"];
11
12
  static args = {};
12
13
  static description = "List types.";
13
14
  static examples = [
@@ -23,11 +23,11 @@ export declare const Config: z.ZodObject<{
23
23
  }, z.core.$strip>;
24
24
  export type Config = z.infer<typeof Config>;
25
25
  export declare const CleanConfig: z.ZodObject<{
26
- silo: z.ZodEnum<{
26
+ silo: z.ZodOptional<z.ZodEnum<{
27
27
  prod: "prod";
28
28
  qa: "qa";
29
29
  dev: "dev";
30
- }>;
30
+ }>>;
31
31
  tenantId: z.ZodString;
32
32
  configId: z.ZodString;
33
33
  }, z.core.$strip>;
@@ -15,6 +15,8 @@ export const Config = z.object({
15
15
  export const CleanConfig = Config.pick({
16
16
  silo: true,
17
17
  tenantId: true,
18
+ }).partial({
19
+ silo: true,
18
20
  }).extend({
19
21
  configId: z.string(),
20
22
  });
@@ -17,6 +17,7 @@
17
17
  "silo": {
18
18
  "char": "s",
19
19
  "description": "silo",
20
+ "hidden": true,
20
21
  "name": "silo",
21
22
  "default": "prod",
22
23
  "hasDynamicHelp": false,
@@ -325,7 +326,10 @@
325
326
  ]
326
327
  },
327
328
  "records:delete": {
328
- "aliases": [],
329
+ "aliases": [
330
+ "records:rm",
331
+ "records:remove"
332
+ ],
329
333
  "args": {
330
334
  "uri": {
331
335
  "description": "uri of record",
@@ -351,7 +355,7 @@
351
355
  "type": "option"
352
356
  },
353
357
  "id": {
354
- "char": "i",
358
+ "char": "I",
355
359
  "description": "id(s)",
356
360
  "name": "id",
357
361
  "hasDynamicHelp": false,
@@ -410,7 +414,7 @@
410
414
  "type": "option"
411
415
  },
412
416
  "id": {
413
- "char": "i",
417
+ "char": "I",
414
418
  "description": "id(s)",
415
419
  "name": "id",
416
420
  "hasDynamicHelp": false,
@@ -468,7 +472,9 @@
468
472
  ]
469
473
  },
470
474
  "records:list": {
471
- "aliases": [],
475
+ "aliases": [
476
+ "records:search"
477
+ ],
472
478
  "args": {
473
479
  "uri": {
474
480
  "description": "uri of type",
@@ -591,6 +597,103 @@
591
597
  "list.js"
592
598
  ]
593
599
  },
600
+ "records:patch": {
601
+ "aliases": [],
602
+ "args": {
603
+ "uri": {
604
+ "description": "uri of record",
605
+ "name": "uri"
606
+ }
607
+ },
608
+ "description": "Patch a record.",
609
+ "examples": [
610
+ "<%= config.bin %> <%= command.id %> native-object:my-type/instance-1 --set field1=value1",
611
+ "<%= config.bin %> <%= command.id %> native-object:my-type --id instance-1 --remove field2",
612
+ "<%= config.bin %> <%= command.id %> --type my-type --id instance-1 --increment field3=2"
613
+ ],
614
+ "flags": {
615
+ "config-id": {
616
+ "char": "C",
617
+ "helpGroup": "GLOBAL",
618
+ "name": "config-id",
619
+ "summary": "Specify config id to use for call.",
620
+ "hasDynamicHelp": false,
621
+ "multiple": false,
622
+ "type": "option"
623
+ },
624
+ "add": {
625
+ "char": "a",
626
+ "description": "add field",
627
+ "name": "add",
628
+ "hasDynamicHelp": false,
629
+ "multiple": true,
630
+ "type": "option"
631
+ },
632
+ "id": {
633
+ "char": "I",
634
+ "description": "id",
635
+ "name": "id",
636
+ "hasDynamicHelp": false,
637
+ "multiple": false,
638
+ "type": "option"
639
+ },
640
+ "increment": {
641
+ "char": "i",
642
+ "description": "increment field",
643
+ "name": "increment",
644
+ "hasDynamicHelp": false,
645
+ "multiple": true,
646
+ "type": "option"
647
+ },
648
+ "remove": {
649
+ "char": "d",
650
+ "description": "remove field",
651
+ "name": "remove",
652
+ "hasDynamicHelp": false,
653
+ "multiple": true,
654
+ "type": "option"
655
+ },
656
+ "replace": {
657
+ "char": "r",
658
+ "description": "replace field",
659
+ "name": "replace",
660
+ "hasDynamicHelp": false,
661
+ "multiple": true,
662
+ "type": "option"
663
+ },
664
+ "set": {
665
+ "char": "s",
666
+ "description": "set field",
667
+ "name": "set",
668
+ "hasDynamicHelp": false,
669
+ "multiple": true,
670
+ "type": "option"
671
+ },
672
+ "type": {
673
+ "char": "T",
674
+ "description": "type",
675
+ "name": "type",
676
+ "hasDynamicHelp": false,
677
+ "multiple": false,
678
+ "type": "option"
679
+ }
680
+ },
681
+ "hasDynamicHelp": false,
682
+ "hiddenAliases": [],
683
+ "id": "records:patch",
684
+ "pluginAlias": "@contextual-io/cli",
685
+ "pluginName": "@contextual-io/cli",
686
+ "pluginType": "core",
687
+ "strict": true,
688
+ "enableJsonFlag": false,
689
+ "isESM": true,
690
+ "relativePath": [
691
+ "dist",
692
+ "commands",
693
+ "records",
694
+ "patch.js"
695
+ ]
696
+ },
594
697
  "records:query": {
595
698
  "aliases": [],
596
699
  "args": {
@@ -717,7 +820,7 @@
717
820
  "type": "option"
718
821
  },
719
822
  "id": {
720
- "char": "i",
823
+ "char": "I",
721
824
  "description": "id",
722
825
  "name": "id",
723
826
  "hasDynamicHelp": false,
@@ -758,6 +861,63 @@
758
861
  "replace.js"
759
862
  ]
760
863
  },
864
+ "records:stats": {
865
+ "aliases": [],
866
+ "args": {
867
+ "uri": {
868
+ "description": "uri of record",
869
+ "name": "uri"
870
+ }
871
+ },
872
+ "description": "Get the stats of a record.",
873
+ "examples": [
874
+ "<%= config.bin %> <%= command.id %> native-object:my-type/instance-1",
875
+ "<%= config.bin %> <%= command.id %> native-object:my-type --id instance-1",
876
+ "<%= config.bin %> <%= command.id %> --type my-type --id instance-1"
877
+ ],
878
+ "flags": {
879
+ "config-id": {
880
+ "char": "C",
881
+ "helpGroup": "GLOBAL",
882
+ "name": "config-id",
883
+ "summary": "Specify config id to use for call.",
884
+ "hasDynamicHelp": false,
885
+ "multiple": false,
886
+ "type": "option"
887
+ },
888
+ "id": {
889
+ "char": "I",
890
+ "description": "id",
891
+ "name": "id",
892
+ "hasDynamicHelp": false,
893
+ "multiple": false,
894
+ "type": "option"
895
+ },
896
+ "type": {
897
+ "char": "T",
898
+ "description": "type",
899
+ "name": "type",
900
+ "hasDynamicHelp": false,
901
+ "multiple": false,
902
+ "type": "option"
903
+ }
904
+ },
905
+ "hasDynamicHelp": false,
906
+ "hiddenAliases": [],
907
+ "id": "records:stats",
908
+ "pluginAlias": "@contextual-io/cli",
909
+ "pluginName": "@contextual-io/cli",
910
+ "pluginType": "core",
911
+ "strict": true,
912
+ "enableJsonFlag": false,
913
+ "isESM": true,
914
+ "relativePath": [
915
+ "dist",
916
+ "commands",
917
+ "records",
918
+ "stats.js"
919
+ ]
920
+ },
761
921
  "types:add": {
762
922
  "aliases": [
763
923
  "types:create",
@@ -806,7 +966,10 @@
806
966
  ]
807
967
  },
808
968
  "types:delete": {
809
- "aliases": [],
969
+ "aliases": [
970
+ "types:rm",
971
+ "types:remove"
972
+ ],
810
973
  "args": {
811
974
  "uri": {
812
975
  "description": "uri of type",
@@ -927,7 +1090,9 @@
927
1090
  ]
928
1091
  },
929
1092
  "types:list": {
930
- "aliases": [],
1093
+ "aliases": [
1094
+ "types:search"
1095
+ ],
931
1096
  "args": {},
932
1097
  "description": "List types.",
933
1098
  "examples": [
@@ -1094,5 +1259,5 @@
1094
1259
  ]
1095
1260
  }
1096
1261
  },
1097
- "version": "0.4.0"
1262
+ "version": "0.6.0"
1098
1263
  }
package/package.json CHANGED
@@ -1,7 +1,7 @@
1
1
  {
2
2
  "name": "@contextual-io/cli",
3
3
  "description": "Contextual CLI",
4
- "version": "0.4.0",
4
+ "version": "0.6.0",
5
5
  "author": "Nasser Oloumi",
6
6
  "bin": {
7
7
  "ctxl": "./bin/run.js"