bdy 1.26.3-stage → 1.26.5-beta

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 (35) hide show
  1. package/distTs/package.json +4 -3
  2. package/distTs/src/api/client.js +40 -0
  3. package/distTs/src/cliIndex.js +2 -0
  4. package/distTs/src/command/login.js +1 -0
  5. package/distTs/src/command/ruleset/create.js +32 -0
  6. package/distTs/src/command/ruleset/delete.js +33 -0
  7. package/distTs/src/command/ruleset/get.js +67 -0
  8. package/distTs/src/command/ruleset/list.js +46 -0
  9. package/distTs/src/command/ruleset/ruleset.js +58 -0
  10. package/distTs/src/command/ruleset/update.js +35 -0
  11. package/distTs/src/command/ruleset.js +20 -0
  12. package/distTs/src/command/yaml/actions/info.js +8 -3
  13. package/distTs/src/command/yaml/actions/list.js +10 -11
  14. package/distTs/src/command/yaml/actions/schema.js +1 -0
  15. package/distTs/src/command/yaml/agent.js +13 -0
  16. package/distTs/src/command/yaml/customAction.js +13 -0
  17. package/distTs/src/command/yaml/distro.js +13 -0
  18. package/distTs/src/command/yaml/documentType.js +64 -0
  19. package/distTs/src/command/yaml/domain.js +13 -0
  20. package/distTs/src/command/yaml/environment.js +14 -0
  21. package/distTs/src/command/yaml/pipeline.js +49 -2
  22. package/distTs/src/command/yaml/render.js +30 -11
  23. package/distTs/src/command/yaml/rooted.js +48 -0
  24. package/distTs/src/command/yaml/sandbox.js +13 -0
  25. package/distTs/src/command/yaml/schemaUtils.js +45 -100
  26. package/distTs/src/command/yaml/targets/info.js +84 -0
  27. package/distTs/src/command/yaml/targets/list.js +60 -0
  28. package/distTs/src/command/yaml/targets/schema.js +29 -0
  29. package/distTs/src/command/yaml/targets.js +15 -0
  30. package/distTs/src/command/yaml/validate.js +238 -287
  31. package/distTs/src/command/yaml.js +22 -0
  32. package/distTs/src/output.js +43 -0
  33. package/distTs/src/texts.js +293 -49
  34. package/distTs/src/utils.js +2 -0
  35. package/package.json +4 -3
@@ -8,27 +8,74 @@ const output_1 = __importDefault(require("../../output"));
8
8
  const texts_1 = require("../../texts");
9
9
  const schemaUtils_1 = require("./schemaUtils");
10
10
  const render_1 = require("./render");
11
+ const ACTION_UNION = 'Action';
11
12
  const commandYamlPipeline = (0, utils_1.newCommand)('pipeline', texts_1.DESC_COMMAND_YAML_PIPELINE, {
12
13
  requiredScopes: [],
13
14
  examples: texts_1.EXAMPLE_YAML_PIPELINE,
14
15
  });
15
16
  commandYamlPipeline.option('--format <text|json>', texts_1.OPTION_FORMAT);
17
+ commandYamlPipeline.option('--event <type>', texts_1.OPTION_YAML_PIPELINE_EVENT);
18
+ async function eventTypes() {
19
+ const properties = await (0, schemaUtils_1.pipelinesScope)().properties('PipelineEventYaml');
20
+ const type = properties.find((property) => property.name === 'type');
21
+ return (type?.enum ?? []).map(String);
22
+ }
23
+ async function outputEvent(type, format) {
24
+ const known = await eventTypes();
25
+ if (!known.includes(type)) {
26
+ output_1.default.exitError((0, texts_1.ERR_YAML_PIPELINE_EVENT_UNKNOWN)(type, known.join(', ')));
27
+ }
28
+ const variables = await (0, schemaUtils_1.pipelinesScope)().eventVariables(type);
29
+ if (format === 'json') {
30
+ output_1.default.json({ event: type, variables });
31
+ }
32
+ else if (variables.length === 0) {
33
+ output_1.default.normal((0, texts_1.TXT_YAML_PIPELINE_EVENT_NONE)(type));
34
+ }
35
+ else {
36
+ output_1.default.blue((0, texts_1.TXT_YAML_EVENT_VARIABLES_OF)(type));
37
+ (0, render_1.outputVariables)(variables);
38
+ }
39
+ output_1.default.exitNormal();
40
+ }
16
41
  commandYamlPipeline.action(async (options) => {
17
42
  await (0, schemaUtils_1.ensureYamlSchema)();
43
+ if (options.event !== undefined) {
44
+ await outputEvent(options.event.toUpperCase(), options.format);
45
+ return;
46
+ }
18
47
  const scope = (0, schemaUtils_1.pipelinesScope)();
19
48
  const properties = await scope.properties('PipelineYaml');
20
- const examples = ((await scope.root())?.examples ?? []);
49
+ const root = await scope.root();
50
+ const examples = (root?.examples ?? []);
51
+ const types = Object.fromEntries(Object.entries(root?.types ?? {}).filter(([name]) => name !== ACTION_UNION));
52
+ const eventVariables = await scope.eventVariables();
21
53
  if (options.format === 'json') {
22
54
  output_1.default.json({
23
55
  properties: (0, render_1.propertiesJson)(properties),
24
56
  required: properties.filter((p) => p.required).map((p) => p.name),
57
+ types: (0, render_1.typesJson)(types),
58
+ eventVariables,
25
59
  examples,
26
60
  });
27
61
  }
28
62
  else {
29
- output_1.default.blue('Pipeline properties');
63
+ output_1.default.blue(texts_1.TXT_YAML_PIPELINE_PROPERTIES);
30
64
  output_1.default.normal('');
31
65
  (0, render_1.outputProperties)(properties);
66
+ if (Object.keys(types).length > 0) {
67
+ output_1.default.normal('');
68
+ output_1.default.blue(texts_1.TXT_YAML_TYPES);
69
+ output_1.default.muted(texts_1.TXT_YAML_PIPELINE_ACTION_FIELDS);
70
+ (0, render_1.outputTypes)(types);
71
+ }
72
+ const events = Object.keys(eventVariables);
73
+ if (events.length > 0) {
74
+ output_1.default.normal('');
75
+ output_1.default.blue(texts_1.TXT_YAML_EVENT_VARIABLES);
76
+ output_1.default.normal((0, texts_1.TXT_YAML_PIPELINE_EVENTS_WITH_VARIABLES)(events.join(', ')));
77
+ output_1.default.muted(texts_1.TXT_YAML_PIPELINE_EVENT_HINT);
78
+ }
32
79
  if (examples.length > 0) {
33
80
  output_1.default.normal('');
34
81
  (0, render_1.outputExamples)(examples);
@@ -7,14 +7,18 @@ exports.propertiesJson = propertiesJson;
7
7
  exports.outputProperties = outputProperties;
8
8
  exports.typesJson = typesJson;
9
9
  exports.outputTypes = outputTypes;
10
+ exports.outputVariables = outputVariables;
11
+ exports.outputOutputs = outputOutputs;
10
12
  exports.outputExamples = outputExamples;
11
13
  const output_1 = __importDefault(require("../../output"));
14
+ const texts_1 = require("../../texts");
12
15
  const shownProperty = (prop) => prop;
13
16
  const shownField = (field) => ({
14
17
  ...field,
15
18
  minimum: field.constraints?.minimum,
16
19
  maximum: field.constraints?.maximum,
17
20
  });
21
+ const nameOf = (one) => (one.mapKey ? `<${one.name}>` : one.name);
18
22
  const typeOf = (one) => (one.const !== undefined ? `"${one.const}"` : one.type);
19
23
  function describe(one) {
20
24
  const parts = [];
@@ -42,20 +46,16 @@ function row(one) {
42
46
  out.minimum = one.minimum;
43
47
  if (one.maximum !== undefined)
44
48
  out.maximum = one.maximum;
49
+ if (one.mapKey)
50
+ out.mapKey = true;
45
51
  return out;
46
52
  }
47
53
  function table(rows) {
48
54
  const data = [['FIELD', 'TYPE', 'REQUIRED', 'DESCRIPTION']];
49
55
  for (const one of rows) {
50
- const desc = describe(one);
51
- data.push([
52
- one.name,
53
- typeOf(one),
54
- one.required ? 'yes' : '',
55
- desc.length > 100 ? `${desc.substring(0, 97)}...` : desc,
56
- ]);
56
+ data.push([nameOf(one), typeOf(one), one.required ? 'yes' : '', describe(one)]);
57
57
  }
58
- output_1.default.table(data);
58
+ output_1.default.wrappedTable(data, { wrapColumn: 3, fixedWidths: { 1: 30 } });
59
59
  }
60
60
  function sorted(properties) {
61
61
  return properties.map(shownProperty).toSorted((a, b) => {
@@ -100,6 +100,25 @@ function outputTypes(types) {
100
100
  table(namedFields(type));
101
101
  }
102
102
  }
103
+ const EXAMPLE_WIDTH = 30;
104
+ function outputVariables(variables) {
105
+ output_1.default.wrappedTable([
106
+ ['VARIABLE', 'DESCRIPTION', 'EXAMPLE'],
107
+ ...variables.map((one) => [one.name, one.description, one.example ?? '']),
108
+ ], { wrapColumn: 1, fixedWidths: { 2: EXAMPLE_WIDTH } });
109
+ }
110
+ function outputOutputs(outputs) {
111
+ if (outputs.variables.length > 0) {
112
+ output_1.default.blue(texts_1.TXT_YAML_EXPORTED_VARIABLES);
113
+ outputVariables(outputs.variables);
114
+ }
115
+ if (outputs.files.length > 0) {
116
+ if (outputs.variables.length > 0)
117
+ output_1.default.normal('');
118
+ output_1.default.blue(texts_1.TXT_YAML_OUTPUT_FILES);
119
+ output_1.default.wrappedTable([['PATH', 'DESCRIPTION'], ...outputs.files.map((one) => [one.path, one.description])]);
120
+ }
121
+ }
103
122
  function formatExampleYaml(value) {
104
123
  try {
105
124
  const YAML = require('yaml');
@@ -114,10 +133,10 @@ function formatExampleYaml(value) {
114
133
  return value.trimEnd();
115
134
  }
116
135
  function outputExamples(examples) {
117
- output_1.default.blue('Examples');
136
+ output_1.default.blue(texts_1.TXT_YAML_EXAMPLES);
118
137
  for (const ex of examples) {
119
138
  output_1.default.normal('');
120
- output_1.default.yellow(`# ${ex.title ?? 'Example'}`);
121
- output_1.default.gray(formatExampleYaml(ex.value));
139
+ output_1.default.yellow(output_1.default.escapeTermKit((0, texts_1.TXT_YAML_EXAMPLE_TITLE)(ex.title)));
140
+ output_1.default.gray(output_1.default.escapeTermKit(formatExampleYaml(ex.value)));
122
141
  }
123
142
  }
@@ -0,0 +1,48 @@
1
+ "use strict";
2
+ var __importDefault = (this && this.__importDefault) || function (mod) {
3
+ return (mod && mod.__esModule) ? mod : { "default": mod };
4
+ };
5
+ Object.defineProperty(exports, "__esModule", { value: true });
6
+ exports.rootedYamlCommand = rootedYamlCommand;
7
+ const utils_1 = require("../../utils");
8
+ const output_1 = __importDefault(require("../../output"));
9
+ const texts_1 = require("../../texts");
10
+ const schemaUtils_1 = require("./schemaUtils");
11
+ const render_1 = require("./render");
12
+ function rootedYamlCommand({ name, description, examples, document, scope, title, typesHint, }) {
13
+ const command = (0, utils_1.newCommand)(name, description, { requiredScopes: [], examples });
14
+ command.option('--format <text|json>', texts_1.OPTION_FORMAT);
15
+ command.action(async (options) => {
16
+ await (0, schemaUtils_1.ensureYamlSchema)(document);
17
+ const root = await scope().root();
18
+ const properties = root ? await scope().properties(root.name) : [];
19
+ const types = root?.types ?? {};
20
+ const rootExamples = (root?.examples ?? []);
21
+ if (options.format === 'json') {
22
+ output_1.default.json({
23
+ properties: (0, render_1.propertiesJson)(properties),
24
+ required: properties.filter((p) => p.required).map((p) => p.name),
25
+ types: (0, render_1.typesJson)(types),
26
+ examples: rootExamples,
27
+ });
28
+ output_1.default.exitNormal();
29
+ return;
30
+ }
31
+ output_1.default.blue(title);
32
+ output_1.default.normal('');
33
+ (0, render_1.outputProperties)(properties);
34
+ if (Object.keys(types).length > 0) {
35
+ output_1.default.normal('');
36
+ output_1.default.blue(texts_1.TXT_YAML_TYPES);
37
+ if (typesHint)
38
+ output_1.default.muted(typesHint);
39
+ (0, render_1.outputTypes)(types);
40
+ }
41
+ if (rootExamples.length > 0) {
42
+ output_1.default.normal('');
43
+ (0, render_1.outputExamples)(rootExamples);
44
+ }
45
+ output_1.default.exitNormal();
46
+ });
47
+ return command;
48
+ }
@@ -0,0 +1,13 @@
1
+ "use strict";
2
+ Object.defineProperty(exports, "__esModule", { value: true });
3
+ const texts_1 = require("../../texts");
4
+ const schemaUtils_1 = require("./schemaUtils");
5
+ const rooted_1 = require("./rooted");
6
+ exports.default = (0, rooted_1.rootedYamlCommand)({
7
+ name: 'sandbox',
8
+ description: texts_1.DESC_COMMAND_YAML_SANDBOX,
9
+ examples: texts_1.EXAMPLE_YAML_SANDBOX,
10
+ document: 'sandboxes',
11
+ scope: schemaUtils_1.sandboxesScope,
12
+ title: texts_1.TXT_YAML_SANDBOX_PROPERTIES,
13
+ });
@@ -3,124 +3,69 @@ var __importDefault = (this && this.__importDefault) || function (mod) {
3
3
  return (mod && mod.__esModule) ? mod : { "default": mod };
4
4
  };
5
5
  Object.defineProperty(exports, "__esModule", { value: true });
6
- exports.pipelinesScope = exports.actionsScope = void 0;
6
+ exports.customActionsScope = exports.agentsScope = exports.distributionsScope = exports.environmentsScope = exports.domainsScope = exports.targetsScope = exports.sandboxesScope = exports.pipelinesScope = exports.actionsScope = void 0;
7
7
  exports.ensureYamlSchema = ensureYamlSchema;
8
- exports.loadRawSchema = loadRawSchema;
9
- exports.getDefValidator = getDefValidator;
10
- exports.validateAgainstDef = validateAgainstDef;
11
- exports.validateAgainstSchema = validateAgainstSchema;
12
- exports.getAllDefs = getAllDefs;
8
+ exports.schemaClient = schemaClient;
13
9
  const docs_schema_1 = require("@buddy-works/docs-schema");
14
10
  const utils_1 = require("../../utils");
15
11
  const input_1 = __importDefault(require("../../input"));
16
12
  const diskCache_1 = require("../../diskCache");
17
13
  const texts_1 = require("../../texts");
18
- function schemaUrl() {
14
+ const FILES = {
15
+ pipelines: 'yaml-schema.json',
16
+ sandboxes: 'sandboxes-schema.json',
17
+ targets: 'targets-schema.json',
18
+ domains: 'domains-schema.json',
19
+ environments: 'environments-schema.json',
20
+ distributions: 'distributions-schema.json',
21
+ agents: 'agents-schema.json',
22
+ customActions: 'custom-actions-schema.json',
23
+ };
24
+ function schemaUrl(document) {
19
25
  const env = (0, utils_1.getApiEnv)(input_1.default.restApiTokenClient(true).baseUrl);
20
- return `https://es.buddy.works/yaml-schema/${env}/yaml-schema.json`;
26
+ return `https://es.buddy.works/yaml-schema/${env}/${FILES[document]}`;
21
27
  }
22
- async function ensureYamlSchema() {
23
- const url = schemaUrl();
28
+ const ensured = new Set();
29
+ let client = null;
30
+ async function ensureYamlSchema(document = 'pipelines') {
31
+ const url = schemaUrl(document);
24
32
  const paths = (0, diskCache_1.cachePaths)('yaml-schema', url);
25
- if ((0, diskCache_1.isHardFresh)((0, diskCache_1.readMeta)(paths.meta)))
26
- return;
27
- if ((await (0, diskCache_1.refresh)(url, paths)) === 'none') {
33
+ if (!(0, diskCache_1.isHardFresh)((0, diskCache_1.readMeta)(paths.meta)) && (await (0, diskCache_1.refresh)(url, paths)) === 'none') {
28
34
  throw new Error((0, texts_1.ERR_YAML_SCHEMA_FETCH_FAILED)(url));
29
35
  }
36
+ if (!ensured.has(document)) {
37
+ ensured.add(document);
38
+ client = null;
39
+ }
30
40
  }
31
- function readCachedSchema() {
32
- const path = (0, diskCache_1.cachePaths)('yaml-schema', schemaUrl()).raw;
41
+ function readCachedSchema(document) {
42
+ const path = (0, diskCache_1.cachePaths)('yaml-schema', schemaUrl(document)).raw;
33
43
  const raw = (0, diskCache_1.readCached)(path);
34
44
  if (!raw)
35
45
  throw new Error((0, texts_1.ERR_YAML_SCHEMA_READ_FAILED)(path));
36
46
  return JSON.parse(raw);
37
47
  }
38
- let client = null;
39
- function schemas() {
40
- if (!client)
41
- client = docs_schema_1.BuddySchema.from({ pipelines: loadRawSchema() });
48
+ function schemaClient() {
49
+ if (!client) {
50
+ client = docs_schema_1.BuddySchema.from(Object.fromEntries([...ensured].map((document) => [document, readCachedSchema(document)])));
51
+ }
42
52
  return client;
43
53
  }
44
- const actionsScope = () => schemas().actions;
54
+ const actionsScope = () => schemaClient().actions;
45
55
  exports.actionsScope = actionsScope;
46
- const pipelinesScope = () => schemas().pipelines;
56
+ const pipelinesScope = () => schemaClient().pipelines;
47
57
  exports.pipelinesScope = pipelinesScope;
48
- let cachedRaw = null;
49
- let ajvInstance = null;
50
- const validatorCache = new Map();
51
- function loadRawSchema() {
52
- if (cachedRaw)
53
- return cachedRaw;
54
- cachedRaw = readCachedSchema();
55
- return cachedRaw;
56
- }
57
- // Read off the schema, not listed: AJV strict mode rejects any x- keyword it was
58
- // not told about, and the backend keeps adding them.
59
- function vendorKeywords(schema) {
60
- const found = new Set();
61
- const walk = (node) => {
62
- if (!node || typeof node !== 'object')
63
- return;
64
- if (Array.isArray(node)) {
65
- node.forEach(walk);
66
- return;
67
- }
68
- for (const [key, value] of Object.entries(node)) {
69
- if (key.startsWith('x-'))
70
- found.add(key);
71
- walk(value);
72
- }
73
- };
74
- walk(schema);
75
- return [...found];
76
- }
77
- function getAjv() {
78
- if (ajvInstance)
79
- return ajvInstance;
80
- const Ajv = require('ajv/dist/2020').default;
81
- const addFormats = require('ajv-formats').default;
82
- const schema = loadRawSchema();
83
- const ajv = new Ajv({ allErrors: true, coerceTypes: true });
84
- addFormats(ajv);
85
- for (const kw of vendorKeywords(schema))
86
- ajv.addKeyword(kw);
87
- ajv.addKeyword('discriminator');
88
- ajv.addSchema(schema);
89
- ajvInstance = ajv;
90
- return ajv;
91
- }
92
- function getDefValidator(defName) {
93
- if (validatorCache.has(defName))
94
- return validatorCache.get(defName);
95
- const ajv = getAjv();
96
- const raw = loadRawSchema();
97
- const validate = ajv.compile({ $ref: `${raw.$id}#/$defs/${defName}` });
98
- validatorCache.set(defName, validate);
99
- return validate;
100
- }
101
- function formatErrors(errors) {
102
- if (!errors)
103
- return [];
104
- return errors.map((err) => {
105
- let errPath = err.instancePath.replace(/^\//, '').replace(/\//g, '.');
106
- if (err.keyword === 'required' && err.params?.missingProperty) {
107
- errPath = errPath ? `${errPath}.${err.params.missingProperty}` : err.params.missingProperty;
108
- }
109
- return { path: errPath, message: err.message || 'unknown error' };
110
- });
111
- }
112
- function validateAgainstDef(defName, data) {
113
- const validate = getDefValidator(defName);
114
- const valid = validate(data);
115
- return { valid: !!valid, errors: formatErrors(validate.errors) };
116
- }
117
- function validateAgainstSchema(schema, data) {
118
- const ajv = getAjv();
119
- const validate = ajv.compile(schema);
120
- const valid = validate(data);
121
- return { valid: !!valid, errors: formatErrors(validate.errors) };
122
- }
123
- function getAllDefs() {
124
- const raw = loadRawSchema();
125
- return raw.$defs || {};
126
- }
58
+ const sandboxesScope = () => schemaClient().sandboxes;
59
+ exports.sandboxesScope = sandboxesScope;
60
+ const targetsScope = () => schemaClient().targets;
61
+ exports.targetsScope = targetsScope;
62
+ const domainsScope = () => schemaClient().domains;
63
+ exports.domainsScope = domainsScope;
64
+ const environmentsScope = () => schemaClient().environments;
65
+ exports.environmentsScope = environmentsScope;
66
+ const distributionsScope = () => schemaClient().distributions;
67
+ exports.distributionsScope = distributionsScope;
68
+ const agentsScope = () => schemaClient().agents;
69
+ exports.agentsScope = agentsScope;
70
+ const customActionsScope = () => schemaClient().customActions;
71
+ exports.customActionsScope = customActionsScope;
@@ -0,0 +1,84 @@
1
+ "use strict";
2
+ var __importDefault = (this && this.__importDefault) || function (mod) {
3
+ return (mod && mod.__esModule) ? mod : { "default": mod };
4
+ };
5
+ Object.defineProperty(exports, "__esModule", { value: true });
6
+ const utils_1 = require("../../../utils");
7
+ const output_1 = __importDefault(require("../../../output"));
8
+ const texts_1 = require("../../../texts");
9
+ const schemaUtils_1 = require("../schemaUtils");
10
+ const render_1 = require("../render");
11
+ const schema_1 = require("./schema");
12
+ const commandYamlTargetsInfo = (0, utils_1.newCommand)('info', texts_1.DESC_COMMAND_YAML_TARGETS_INFO, {
13
+ requiredScopes: [],
14
+ examples: texts_1.EXAMPLE_YAML_TARGETS_INFO,
15
+ });
16
+ commandYamlTargetsInfo.argument('<type>', texts_1.OPTION_YAML_TARGET_TYPE);
17
+ commandYamlTargetsInfo.option('--format <text|json>', texts_1.OPTION_FORMAT);
18
+ commandYamlTargetsInfo.action(async (type, options) => {
19
+ await (0, schemaUtils_1.ensureYamlSchema)('targets');
20
+ const target = await (0, schema_1.findTarget)(type);
21
+ if (!target) {
22
+ if (options.format === 'json') {
23
+ output_1.default.json(null);
24
+ output_1.default.exitNormal();
25
+ return;
26
+ }
27
+ output_1.default.error((0, texts_1.ERR_YAML_TARGET_NOT_FOUND)(type));
28
+ const similar = await (0, schema_1.searchTargets)(type, 5);
29
+ if (similar.length > 0) {
30
+ output_1.default.muted((0, texts_1.TXT_ACTION_DID_YOU_MEAN)(similar.map((one) => `${one.value} (${one.name})`).join(', ')));
31
+ }
32
+ output_1.default.muted(texts_1.TXT_YAML_TARGET_USE_LIST);
33
+ output_1.default.exitNormal();
34
+ return;
35
+ }
36
+ const commonFields = new Set(await (0, schemaUtils_1.targetsScope)().commonFields());
37
+ const common = [];
38
+ const specific = [];
39
+ for (const property of target.properties) {
40
+ (commonFields.has(property.name) ? common : specific).push(property);
41
+ }
42
+ const types = target.document?.types ?? {};
43
+ if (options.format === 'json') {
44
+ output_1.default.json({
45
+ type: target.value,
46
+ slug: target.slug,
47
+ name: target.name,
48
+ description: target.description,
49
+ required: target.required,
50
+ fields: {
51
+ specific: (0, render_1.propertiesJson)(specific),
52
+ common: (0, render_1.propertiesJson)(common),
53
+ },
54
+ types: (0, render_1.typesJson)(types),
55
+ examples: target.examples,
56
+ });
57
+ output_1.default.exitNormal();
58
+ return;
59
+ }
60
+ output_1.default.blue(target.name, false);
61
+ output_1.default.gray(` · ${target.value}`);
62
+ output_1.default.gray(target.description);
63
+ output_1.default.normal('');
64
+ if (specific.length > 0) {
65
+ output_1.default.blue(texts_1.TXT_YAML_TYPE_SPECIFIC_FIELDS);
66
+ (0, render_1.outputProperties)(specific);
67
+ output_1.default.normal('');
68
+ }
69
+ if (common.length > 0) {
70
+ output_1.default.blue(texts_1.TXT_YAML_COMMON_FIELDS);
71
+ (0, render_1.outputProperties)(common);
72
+ }
73
+ if (Object.keys(types).length > 0) {
74
+ output_1.default.normal('');
75
+ output_1.default.blue(texts_1.TXT_YAML_TYPES);
76
+ (0, render_1.outputTypes)(types);
77
+ }
78
+ if (target.examples.length > 0) {
79
+ output_1.default.normal('');
80
+ (0, render_1.outputExamples)(target.examples);
81
+ }
82
+ output_1.default.exitNormal();
83
+ });
84
+ exports.default = commandYamlTargetsInfo;
@@ -0,0 +1,60 @@
1
+ "use strict";
2
+ var __importDefault = (this && this.__importDefault) || function (mod) {
3
+ return (mod && mod.__esModule) ? mod : { "default": mod };
4
+ };
5
+ Object.defineProperty(exports, "__esModule", { value: true });
6
+ const utils_1 = require("../../../utils");
7
+ const output_1 = __importDefault(require("../../../output"));
8
+ const texts_1 = require("../../../texts");
9
+ const schemaUtils_1 = require("../schemaUtils");
10
+ const schema_1 = require("./schema");
11
+ function targetTable(targets) {
12
+ output_1.default.wrappedTable([
13
+ ['TYPE', 'NAME', 'DESCRIPTION'],
14
+ ...targets.map((target) => [target.value, target.name, target.description]),
15
+ ]);
16
+ }
17
+ const targetJson = (targets) => targets.map((target) => ({
18
+ type: target.value,
19
+ slug: target.slug,
20
+ name: target.name,
21
+ description: target.description,
22
+ }));
23
+ const commandYamlTargetsList = (0, utils_1.newCommand)('list', texts_1.DESC_COMMAND_YAML_TARGETS_LIST, {
24
+ requiredScopes: [],
25
+ examples: texts_1.EXAMPLE_YAML_TARGETS_LIST,
26
+ });
27
+ commandYamlTargetsList.alias('ls');
28
+ commandYamlTargetsList.option('-s, --search <query>', texts_1.OPTION_ACTION_SEARCH);
29
+ commandYamlTargetsList.option('--format <text|json>', texts_1.OPTION_FORMAT);
30
+ commandYamlTargetsList.action(async (options) => {
31
+ await (0, schemaUtils_1.ensureYamlSchema)('targets');
32
+ const json = options.format === 'json';
33
+ if (options.search) {
34
+ const results = await (0, schema_1.searchTargets)(options.search);
35
+ if (json) {
36
+ output_1.default.json(targetJson(results));
37
+ }
38
+ else if (results.length === 0) {
39
+ output_1.default.error((0, texts_1.ERR_YAML_TARGET_SEARCH_NO_RESULTS)(options.search));
40
+ output_1.default.muted(texts_1.TXT_YAML_TARGET_USE_LIST);
41
+ }
42
+ else {
43
+ targetTable(results);
44
+ }
45
+ output_1.default.exitNormal();
46
+ return;
47
+ }
48
+ const targets = await (0, schema_1.loadTargets)();
49
+ if (json) {
50
+ output_1.default.json(targetJson(targets));
51
+ output_1.default.exitNormal();
52
+ return;
53
+ }
54
+ output_1.default.blue((0, texts_1.TXT_YAML_TARGETS_ALL)(targets.length));
55
+ targetTable(targets);
56
+ output_1.default.normal('');
57
+ output_1.default.muted(texts_1.TXT_YAML_TARGET_HINT);
58
+ output_1.default.exitNormal();
59
+ });
60
+ exports.default = commandYamlTargetsList;
@@ -0,0 +1,29 @@
1
+ "use strict";
2
+ Object.defineProperty(exports, "__esModule", { value: true });
3
+ exports.UNSUPPORTED_TARGET_TYPES = void 0;
4
+ exports.loadTargets = loadTargets;
5
+ exports.findTarget = findTarget;
6
+ exports.searchTargets = searchTargets;
7
+ const schemaUtils_1 = require("../schemaUtils");
8
+ exports.UNSUPPORTED_TARGET_TYPES = new Set(['MATCH', 'PROJECT_REPOSITORY']);
9
+ async function loadTargets() {
10
+ const scope = (0, schemaUtils_1.targetsScope)();
11
+ const types = (await scope.list()).filter((type) => !exports.UNSUPPORTED_TARGET_TYPES.has(type));
12
+ const all = await Promise.all(types.map((type) => scope.get(type)));
13
+ return all
14
+ .filter((member) => member !== undefined)
15
+ .toSorted((a, b) => a.value.localeCompare(b.value));
16
+ }
17
+ async function findTarget(query) {
18
+ const all = await loadTargets();
19
+ return (all.find((member) => member.value === query.toUpperCase()) ??
20
+ all.find((member) => member.slug === query.toLowerCase()));
21
+ }
22
+ async function searchTargets(query, limit = Infinity) {
23
+ const bySearch = await (0, schemaUtils_1.targetsScope)().search(query, { fuzzy: 0.3, limit: Infinity });
24
+ const byType = new Map((await loadTargets()).map((member) => [member.value, member]));
25
+ return bySearch
26
+ .filter((hit) => hit.kind === 'member')
27
+ .flatMap((hit) => byType.get(hit.key) ?? [])
28
+ .slice(0, limit);
29
+ }
@@ -0,0 +1,15 @@
1
+ "use strict";
2
+ var __importDefault = (this && this.__importDefault) || function (mod) {
3
+ return (mod && mod.__esModule) ? mod : { "default": mod };
4
+ };
5
+ Object.defineProperty(exports, "__esModule", { value: true });
6
+ const utils_1 = require("../../utils");
7
+ const texts_1 = require("../../texts");
8
+ const list_1 = __importDefault(require("./targets/list"));
9
+ const info_1 = __importDefault(require("./targets/info"));
10
+ const commandYamlTargets = (0, utils_1.newCommand)('targets', texts_1.DESC_COMMAND_YAML_TARGETS, {
11
+ examples: [...texts_1.EXAMPLE_YAML_TARGETS_LIST, ...texts_1.EXAMPLE_YAML_TARGETS_INFO],
12
+ });
13
+ commandYamlTargets.addCommand(list_1.default);
14
+ commandYamlTargets.addCommand(info_1.default);
15
+ exports.default = commandYamlTargets;