Skip to content

Commit

Permalink
feat(2683): nodejs upgrade (#507)
Browse files Browse the repository at this point in the history
BREAKING CHANGE: Node 16 upgrade && eslint upgrade
  • Loading branch information
klu909 authored Nov 4, 2022
1 parent 654f2c6 commit ee91314
Show file tree
Hide file tree
Showing 40 changed files with 235 additions and 831 deletions.
16 changes: 4 additions & 12 deletions api/commandValidator.js
Original file line number Diff line number Diff line change
Expand Up @@ -5,16 +5,12 @@ const Joi = require('joi');
// essentially a Joi.ValidationError.details object
const COMMAND_ERROR = Joi.object().keys({
context: Joi.object().label('Functional context regarding the error'),
message: Joi.string()
.label('Description of a particular validation error')
.required(),
message: Joi.string().label('Description of a particular validation error').required(),
path: Joi.array()
.items(Joi.string())
.label('Dot-notation path to the field that caused the validation error')
.required(),
type: Joi.string()
.label('The the Joi-type that categorizes the error')
.required()
type: Joi.string().label('The the Joi-type that categorizes the error').required()
});

const SCHEMA_OUTPUT = Joi.object()
Expand All @@ -24,16 +20,12 @@ const SCHEMA_OUTPUT = Joi.object()
.label('Array of errors encountered while validating the given command')
.required(),
// since a command could be parseable but invalid, the contents are unpredicatble
command: Joi.object()
.label('The end-result of parsing the given command')
.required()
command: Joi.object().label('The end-result of parsing the given command').required()
})
.label('Command validation output');

const SCHEMA_INPUT = Joi.object({
yaml: Joi.string()
.required()
.label('sd-command.yaml contents')
yaml: Joi.string().required().label('sd-command.yaml contents')
}).label('Certify input to command validator');

/**
Expand Down
30 changes: 6 additions & 24 deletions api/loglines.js
Original file line number Diff line number Diff line change
Expand Up @@ -12,16 +12,8 @@ const SCHEMA_PARAMS = Joi.object()

const SCHEMA_QUERY = Joi.object()
.keys({
from: Joi.number()
.integer()
.min(0)
.default(0)
.description('Starting line Number'),
pages: Joi.number()
.integer()
.min(1)
.default(10)
.description('Max pages sent per request'),
from: Joi.number().integer().min(0).default(0).description('Starting line Number'),
pages: Joi.number().integer().min(1).default(10).description('Max pages sent per request'),
sort: Joi.string()
.lowercase()
.valid('ascending', 'descending')
Expand All @@ -36,20 +28,10 @@ const SCHEMA_QUERY = Joi.object()

const SCHEMA_LOGLINE = Joi.object()
.keys({
n: Joi.number()
.integer()
.description('Numbered line number since the start of the step')
.example(15),
t: Joi.number()
.positive()
.description('Unix timestamp of the log line')
.example(1472084645.33),
m: Joi.string()
.allow('')
.description('Line Message'),
s: Joi.string()
.min(1)
.description('Step Name')
n: Joi.number().integer().description('Numbered line number since the start of the step').example(15),
t: Joi.number().positive().description('Unix timestamp of the log line').example(1472084645.33),
m: Joi.string().allow('').description('Line Message'),
s: Joi.string().min(1).description('Step Name')
})
.label('Log Line');

Expand Down
33 changes: 9 additions & 24 deletions api/pagination.js
Original file line number Diff line number Diff line change
Expand Up @@ -3,30 +3,15 @@
const Joi = require('joi');

const MODEL = {
page: Joi.number()
.integer()
.min(1)
.description('Page to paginate'),

count: Joi.number()
.integer()
.min(1)
.max(50)
.description('Count to paginate'),

search: Joi.string()
.max(200)
.description('Keyword to search by'),

sort: Joi.string()
.lowercase()
.valid('ascending', 'descending')
.default('descending')
.description('Sorting option'),

sortBy: Joi.string()
.max(100)
.description('Field to sort by'),
page: Joi.number().integer().min(1).description('Page to paginate'),

count: Joi.number().integer().min(1).max(50).description('Count to paginate'),

search: Joi.string().max(200).description('Keyword to search by'),

sort: Joi.string().lowercase().valid('ascending', 'descending').default('descending').description('Sorting option'),

sortBy: Joi.string().max(100).description('Field to sort by'),

getCount: Joi.boolean().description('Return total count')
};
Expand Down
29 changes: 6 additions & 23 deletions api/stats.js
Original file line number Diff line number Diff line change
Expand Up @@ -4,29 +4,12 @@ const Joi = require('joi');

const SCHEMA_REQUESTS = Joi.object()
.keys({
total: Joi.number()
.integer()
.description('Total number of requests')
.example(100),
timeouts: Joi.number()
.integer()
.description('Number of timeouts')
.example(0),
success: Joi.number()
.integer()
.description('Number of successes')
.example(95),
failure: Joi.number()
.integer()
.description('Number of failures')
.example('5'),
concurrent: Joi.number()
.integer()
.description('Number of concurrent requests')
.example(0),
averageTime: Joi.number()
.label('Average time per request')
.example(5.3134)
total: Joi.number().integer().description('Total number of requests').example(100),
timeouts: Joi.number().integer().description('Number of timeouts').example(0),
success: Joi.number().integer().description('Number of successes').example(95),
failure: Joi.number().integer().description('Number of failures').example('5'),
concurrent: Joi.number().integer().description('Number of concurrent requests').example(0),
averageTime: Joi.number().label('Average time per request').example(5.3134)
})
.label('Requests Object');

Expand Down
16 changes: 4 additions & 12 deletions api/templateValidator.js
Original file line number Diff line number Diff line change
Expand Up @@ -5,16 +5,12 @@ const Joi = require('joi');
// essentially a Joi.ValidationError.details object
const TEMPLATE_ERROR = Joi.object().keys({
context: Joi.object().label('Functional context regarding the error'),
message: Joi.string()
.label('Description of a particular validation error')
.required(),
message: Joi.string().label('Description of a particular validation error').required(),
path: Joi.array()
.items(Joi.string(), Joi.number().integer())
.label('Array of path to the field that caused the validation error')
.required(),
type: Joi.string()
.label('The the Joi-type that categorizes the error')
.required()
type: Joi.string().label('The the Joi-type that categorizes the error').required()
});

const SCHEMA_OUTPUT = Joi.object()
Expand All @@ -24,17 +20,13 @@ const SCHEMA_OUTPUT = Joi.object()
.label('Array of errors encountered while validating the given template')
.required(),
// since a template could be parseable but invalid, the contents are unpredictable
template: Joi.object()
.label('The end-result of parsing the given template')
.required(),
template: Joi.object().label('The end-result of parsing the given template').required(),
warnMessages: Joi.array().optional()
})
.label('Template validation output');

const SCHEMA_INPUT = Joi.object({
yaml: Joi.string()
.required()
.label('sd-template.yaml contents')
yaml: Joi.string().required().label('sd-template.yaml contents')
}).label('Certify input to template validator');

/**
Expand Down
13 changes: 3 additions & 10 deletions api/validator.js
Original file line number Diff line number Diff line change
Expand Up @@ -17,10 +17,7 @@ const SCHEMA_JOB_COMMAND = Joi.object()
.unknown(false)
.label('Named command to execute');

const SCHEMA_JOB_COMMANDS = Joi.array()
.items(SCHEMA_JOB_COMMAND)
.min(1)
.label('List of named commands to execute');
const SCHEMA_JOB_COMMANDS = Joi.array().items(SCHEMA_JOB_COMMAND).min(1).label('List of named commands to execute');

const SCHEMA_JOB_PERMUTATION = Joi.object()
.keys({
Expand All @@ -45,9 +42,7 @@ const SCHEMA_JOB_PERMUTATION = Joi.object()
})
.label('Job permutation');

const SCHEMA_JOB_PERMUTATIONS = Joi.array()
.items(SCHEMA_JOB_PERMUTATION)
.label('List of job permutations');
const SCHEMA_JOB_PERMUTATIONS = Joi.array().items(SCHEMA_JOB_PERMUTATION).label('List of job permutations');

const SCHEMA_JOBS = Joi.object()
// Jobs can only be named with A-Z,a-z,0-9,-,_
Expand All @@ -59,9 +54,7 @@ const SCHEMA_JOBS = Joi.object()
const SCHEMA_OUTPUT = Joi.object()
.keys({
annotations: Annotations.annotations,
errors: Joi.array()
.items(Joi.string())
.optional(),
errors: Joi.array().items(Joi.string()).optional(),
jobs: SCHEMA_JOBS,
childPipelines: Base.childPipelines,
workflowGraph: WorkflowGraph.workflowGraph,
Expand Down
17 changes: 4 additions & 13 deletions config/base.js
Original file line number Diff line number Diff line change
Expand Up @@ -10,9 +10,7 @@ const SCHEMA_CACHE_VALUE = Joi.string().uri({
relativeOnly: true
});
const SCHEMA_CACHE_LIST = Joi.array().items(SCHEMA_CACHE_VALUE);
const SCHEMA_CACHE_JOBS = Joi.object()
.pattern(Job.jobName, SCHEMA_CACHE_LIST)
.unknown(false);
const SCHEMA_CACHE_JOBS = Joi.object().pattern(Job.jobName, SCHEMA_CACHE_LIST).unknown(false);
const SCHEMA_CACHE = Joi.object({
event: SCHEMA_CACHE_LIST,
pipeline: SCHEMA_CACHE_LIST,
Expand All @@ -32,9 +30,7 @@ const SCHEMA_JOBS = Joi.object()
.unknown(false);
const SCHEMA_SHARED = Job.job;
const SCHEMA_SCM_URL = Joi.string().regex(Regex.CHECKOUT_URL);
const SCHEMA_SCM_URLS = Joi.array()
.items(SCHEMA_SCM_URL)
.min(1);
const SCHEMA_SCM_URLS = Joi.array().items(SCHEMA_SCM_URL).min(1);
const SCHEMA_CHILD_PIPELINES = Joi.object()
.keys({
scmUrls: SCHEMA_SCM_URLS.required(),
Expand All @@ -45,9 +41,7 @@ const SCHEMA_CHILD_PIPELINES = Joi.object()
const SCHEMA_STAGE = Joi.object()
.keys({
description: Joi.string(),
jobs: Joi.array()
.items(Job.jobName)
.min(0)
jobs: Joi.array().items(Job.jobName).min(0)
})
.unknown(false);

Expand All @@ -68,10 +62,7 @@ const SCHEMA_SUBSCRIBE = Joi.object().keys({

const SCHEMA_CONFIG = Joi.object()
.keys({
version: Joi.number()
.integer()
.min(1)
.max(50),
version: Joi.number().integer().min(1).max(50),
annotations: Annotations.annotations,
jobs: SCHEMA_JOBS.required(),
shared: SCHEMA_SHARED,
Expand Down
18 changes: 3 additions & 15 deletions config/command.js
Original file line number Diff line number Diff line change
Expand Up @@ -10,23 +10,15 @@ const COMMAND_NAMESPACE = Joi.string()
.description('Namespace of the Command')
.example('chefdk');

const COMMAND_NAME = Joi.string()
.regex(Regex.COMMAND_NAME)
.max(64)
.description('Name of the Command')
.example('knife');
const COMMAND_NAME = Joi.string().regex(Regex.COMMAND_NAME).max(64).description('Name of the Command').example('knife');

const COMMAND_TAG_NAME = Joi.string()
.regex(Regex.COMMAND_TAG_NAME)
.max(30)
.description('Name of the Command Tag')
.example('latest');

const COMMAND_VERSION = Joi.string()
.regex(Regex.VERSION)
.max(16)
.description('Version of the Command')
.example('1.2');
const COMMAND_VERSION = Joi.string().regex(Regex.VERSION).max(16).description('Version of the Command').example('1.2');

const COMMAND_EXACT_VERSION = Joi.string()
.regex(Regex.EXACT_VERSION)
Expand All @@ -45,11 +37,7 @@ const COMMAND_USAGE = Joi.string()
.description('Usage and arguments of the command')
.example('sd_cmd exec foo/bar@1 -h <host> -d <domain>');

const COMMAND_MAINTAINER = Joi.string()
.email()
.max(64)
.description('Maintainer of the Command')
.example('[email protected]');
const COMMAND_MAINTAINER = Joi.string().email().max(64).description('Maintainer of the Command').example('[email protected]');

const COMMAND_FORMAT = Joi.string()
.valid('habitat', 'docker', 'binary')
Expand Down
30 changes: 7 additions & 23 deletions config/commandFormat.js
Original file line number Diff line number Diff line change
Expand Up @@ -2,22 +2,13 @@

const Joi = require('joi');

const HABITAT_MODE = Joi.string()
.valid('remote', 'local')
.description('Mode of the Habitat command')
.example('remote');
const HABITAT_MODE = Joi.string().valid('remote', 'local').description('Mode of the Habitat command').example('remote');

const HABITAT_FILE = Joi.string()
.description('File path of the Habitat artifact')
.example('./foobar.hart');
const HABITAT_FILE = Joi.string().description('File path of the Habitat artifact').example('./foobar.hart');

const HABITAT_PACKAGE = Joi.string()
.description('Package of the Habitat command')
.example('core/git/2.14.1');
const HABITAT_PACKAGE = Joi.string().description('Package of the Habitat command').example('core/git/2.14.1');

const HABITAT_COMMAND = Joi.string()
.description('Executable of the Habitat command')
.example('git');
const HABITAT_COMMAND = Joi.string().description('Executable of the Habitat command').example('git');

const SCHEMA_HABITAT = Joi.object().keys({
mode: HABITAT_MODE.required(),
Expand All @@ -26,23 +17,16 @@ const SCHEMA_HABITAT = Joi.object().keys({
command: HABITAT_COMMAND.required()
});

const DOCKER_IMAGE = Joi.string()
.description('Image of the Docker command')
.example('chefdk:1.2.3');
const DOCKER_IMAGE = Joi.string().description('Image of the Docker command').example('chefdk:1.2.3');

const DOCKER_COMMAND = Joi.string()
.description('Executable of the Docker command')
.default('')
.example('knife');
const DOCKER_COMMAND = Joi.string().description('Executable of the Docker command').default('').example('knife');

const SCHEMA_DOCKER = Joi.object().keys({
image: DOCKER_IMAGE.required(),
command: DOCKER_COMMAND
});

const BINARY_FILE = Joi.string()
.description('File of the Binary command')
.example('./foobar.sh');
const BINARY_FILE = Joi.string().description('File of the Binary command').example('./foobar.sh');

const SCHEMA_BINARY = Joi.object().keys({
file: BINARY_FILE.required()
Expand Down
Loading

0 comments on commit ee91314

Please sign in to comment.