edgespec
Version:
Write Winter-CG compatible routes with filesystem routing and tons of features
1,219 lines (1,216 loc) • 319 kB
JavaScript
#!/usr/bin/env node
import { startDevServer, constructManifest, createRouteMapFromDirectory } from '../chunk-TZHMALR4.js';
import { loadBundle } from '../chunk-PRZQE4JB.js';
import '../chunk-BA3OE4WS.js';
import { loadConfig } from '../chunk-TMYKADNK.js';
import { __commonJS, __toESM } from '../chunk-5WRI5ZAA.js';
import { Command, runExit, Option } from 'clipanion';
import esbuild from 'esbuild';
import fs from 'fs/promises';
import path from 'path';
import { durationFormatter, sizeFormatter } from 'human-readable';
import ora2 from 'ora';
import { Project, ts, TypeFormatFlags } from 'ts-morph';
import { randomUUID } from 'crypto';
import os from 'os';
import { generateSchema } from '@anatine/zod-openapi';
import camelcase from 'camelcase';
// node_modules/typanion/lib/index.js
var require_lib = __commonJS({
"node_modules/typanion/lib/index.js"(exports) {
Object.defineProperty(exports, "__esModule", { value: true });
var simpleKeyRegExp = /^[a-zA-Z_][a-zA-Z0-9_]*$/;
function getPrintable(value) {
if (value === null)
return `null`;
if (value === void 0)
return `undefined`;
if (value === ``)
return `an empty string`;
if (typeof value === "symbol")
return `<${value.toString()}>`;
if (Array.isArray(value))
return `an array`;
return JSON.stringify(value);
}
function getPrintableArray(value, conjunction) {
if (value.length === 0)
return `nothing`;
if (value.length === 1)
return getPrintable(value[0]);
const rest = value.slice(0, -1);
const trailing = value[value.length - 1];
const separator = value.length > 2 ? `, ${conjunction} ` : ` ${conjunction} `;
return `${rest.map((value2) => getPrintable(value2)).join(`, `)}${separator}${getPrintable(trailing)}`;
}
function computeKey(state, key) {
var _a, _b, _c;
if (typeof key === `number`) {
return `${(_a = state === null || state === void 0 ? void 0 : state.p) !== null && _a !== void 0 ? _a : `.`}[${key}]`;
} else if (simpleKeyRegExp.test(key)) {
return `${(_b = state === null || state === void 0 ? void 0 : state.p) !== null && _b !== void 0 ? _b : ``}.${key}`;
} else {
return `${(_c = state === null || state === void 0 ? void 0 : state.p) !== null && _c !== void 0 ? _c : `.`}[${JSON.stringify(key)}]`;
}
}
function plural(n2, singular, plural2) {
return n2 === 1 ? singular : plural2;
}
var colorStringRegExp = /^#[0-9a-f]{6}$/i;
var colorStringAlphaRegExp = /^#[0-9a-f]{6}([0-9a-f]{2})?$/i;
var base64RegExp = /^(?:[A-Za-z0-9+/]{4})*(?:[A-Za-z0-9+/]{2}==|[A-Za-z0-9+/]{3}=)?$/;
var uuid4RegExp = /^[a-f0-9]{8}-[a-f0-9]{4}-4[a-f0-9]{3}-[89aAbB][a-f0-9]{3}-[a-f0-9]{12}$/i;
var iso8601RegExp = /^(?:[1-9]\d{3}(-?)(?:(?:0[1-9]|1[0-2])\1(?:0[1-9]|1\d|2[0-8])|(?:0[13-9]|1[0-2])\1(?:29|30)|(?:0[13578]|1[02])(?:\1)31|00[1-9]|0[1-9]\d|[12]\d{2}|3(?:[0-5]\d|6[0-5]))|(?:[1-9]\d(?:0[48]|[2468][048]|[13579][26])|(?:[2468][048]|[13579][26])00)(?:(-?)02(?:\2)29|-?366))T(?:[01]\d|2[0-3])(:?)[0-5]\d(?:\3[0-5]\d)?(?:Z|[+-][01]\d(?:\3[0-5]\d)?)$/;
function pushError({ errors, p } = {}, message) {
errors === null || errors === void 0 ? void 0 : errors.push(`${p !== null && p !== void 0 ? p : `.`}: ${message}`);
return false;
}
function makeSetter(target, key) {
return (v) => {
target[key] = v;
};
}
function makeCoercionFn(target, key) {
return (v) => {
const previous = target[key];
target[key] = v;
return makeCoercionFn(target, key).bind(null, previous);
};
}
function makeLazyCoercionFn(fn2, orig, generator) {
const commit = () => {
fn2(generator());
return revert;
};
const revert = () => {
fn2(orig);
return commit;
};
return commit;
}
function isUnknown() {
return makeValidator({
test: (value, state) => {
return true;
}
});
}
function isLiteral(expected) {
return makeValidator({
test: (value, state) => {
if (value !== expected)
return pushError(state, `Expected ${getPrintable(expected)} (got ${getPrintable(value)})`);
return true;
}
});
}
function isString() {
return makeValidator({
test: (value, state) => {
if (typeof value !== `string`)
return pushError(state, `Expected a string (got ${getPrintable(value)})`);
return true;
}
});
}
function isEnum2(enumSpec) {
const valuesArray = Array.isArray(enumSpec) ? enumSpec : Object.values(enumSpec);
const isAlphaNum = valuesArray.every((item) => typeof item === "string" || typeof item === "number");
const values = new Set(valuesArray);
if (values.size === 1)
return isLiteral([...values][0]);
return makeValidator({
test: (value, state) => {
if (!values.has(value)) {
if (isAlphaNum) {
return pushError(state, `Expected one of ${getPrintableArray(valuesArray, `or`)} (got ${getPrintable(value)})`);
} else {
return pushError(state, `Expected a valid enumeration value (got ${getPrintable(value)})`);
}
}
return true;
}
});
}
var BOOLEAN_COERCIONS = /* @__PURE__ */ new Map([
[`true`, true],
[`True`, true],
[`1`, true],
[1, true],
[`false`, false],
[`False`, false],
[`0`, false],
[0, false]
]);
function isBoolean() {
return makeValidator({
test: (value, state) => {
var _a;
if (typeof value !== `boolean`) {
if (typeof (state === null || state === void 0 ? void 0 : state.coercions) !== `undefined`) {
if (typeof (state === null || state === void 0 ? void 0 : state.coercion) === `undefined`)
return pushError(state, `Unbound coercion result`);
const coercion = BOOLEAN_COERCIONS.get(value);
if (typeof coercion !== `undefined`) {
state.coercions.push([(_a = state.p) !== null && _a !== void 0 ? _a : `.`, state.coercion.bind(null, coercion)]);
return true;
}
}
return pushError(state, `Expected a boolean (got ${getPrintable(value)})`);
}
return true;
}
});
}
function isNumber() {
return makeValidator({
test: (value, state) => {
var _a;
if (typeof value !== `number`) {
if (typeof (state === null || state === void 0 ? void 0 : state.coercions) !== `undefined`) {
if (typeof (state === null || state === void 0 ? void 0 : state.coercion) === `undefined`)
return pushError(state, `Unbound coercion result`);
let coercion;
if (typeof value === `string`) {
let val;
try {
val = JSON.parse(value);
} catch (_b) {
}
if (typeof val === `number`) {
if (JSON.stringify(val) === value) {
coercion = val;
} else {
return pushError(state, `Received a number that can't be safely represented by the runtime (${value})`);
}
}
}
if (typeof coercion !== `undefined`) {
state.coercions.push([(_a = state.p) !== null && _a !== void 0 ? _a : `.`, state.coercion.bind(null, coercion)]);
return true;
}
}
return pushError(state, `Expected a number (got ${getPrintable(value)})`);
}
return true;
}
});
}
function isPayload(spec) {
return makeValidator({
test: (value, state) => {
var _a;
if (typeof (state === null || state === void 0 ? void 0 : state.coercions) === `undefined`)
return pushError(state, `The isPayload predicate can only be used with coercion enabled`);
if (typeof state.coercion === `undefined`)
return pushError(state, `Unbound coercion result`);
if (typeof value !== `string`)
return pushError(state, `Expected a string (got ${getPrintable(value)})`);
let inner;
try {
inner = JSON.parse(value);
} catch (_b) {
return pushError(state, `Expected a JSON string (got ${getPrintable(value)})`);
}
const wrapper = { value: inner };
if (!spec(inner, Object.assign(Object.assign({}, state), { coercion: makeCoercionFn(wrapper, `value`) })))
return false;
state.coercions.push([(_a = state.p) !== null && _a !== void 0 ? _a : `.`, state.coercion.bind(null, wrapper.value)]);
return true;
}
});
}
function isDate() {
return makeValidator({
test: (value, state) => {
var _a;
if (!(value instanceof Date)) {
if (typeof (state === null || state === void 0 ? void 0 : state.coercions) !== `undefined`) {
if (typeof (state === null || state === void 0 ? void 0 : state.coercion) === `undefined`)
return pushError(state, `Unbound coercion result`);
let coercion;
if (typeof value === `string` && iso8601RegExp.test(value)) {
coercion = new Date(value);
} else {
let timestamp;
if (typeof value === `string`) {
let val;
try {
val = JSON.parse(value);
} catch (_b) {
}
if (typeof val === `number`) {
timestamp = val;
}
} else if (typeof value === `number`) {
timestamp = value;
}
if (typeof timestamp !== `undefined`) {
if (Number.isSafeInteger(timestamp) || !Number.isSafeInteger(timestamp * 1e3)) {
coercion = new Date(timestamp * 1e3);
} else {
return pushError(state, `Received a timestamp that can't be safely represented by the runtime (${value})`);
}
}
}
if (typeof coercion !== `undefined`) {
state.coercions.push([(_a = state.p) !== null && _a !== void 0 ? _a : `.`, state.coercion.bind(null, coercion)]);
return true;
}
}
return pushError(state, `Expected a date (got ${getPrintable(value)})`);
}
return true;
}
});
}
function isArray(spec, { delimiter } = {}) {
return makeValidator({
test: (value, state) => {
var _a;
const originalValue = value;
if (typeof value === `string` && typeof delimiter !== `undefined`) {
if (typeof (state === null || state === void 0 ? void 0 : state.coercions) !== `undefined`) {
if (typeof (state === null || state === void 0 ? void 0 : state.coercion) === `undefined`)
return pushError(state, `Unbound coercion result`);
value = value.split(delimiter);
}
}
if (!Array.isArray(value))
return pushError(state, `Expected an array (got ${getPrintable(value)})`);
let valid = true;
for (let t2 = 0, T = value.length; t2 < T; ++t2) {
valid = spec(value[t2], Object.assign(Object.assign({}, state), { p: computeKey(state, t2), coercion: makeCoercionFn(value, t2) })) && valid;
if (!valid && (state === null || state === void 0 ? void 0 : state.errors) == null) {
break;
}
}
if (value !== originalValue)
state.coercions.push([(_a = state.p) !== null && _a !== void 0 ? _a : `.`, state.coercion.bind(null, value)]);
return valid;
}
});
}
function isSet(spec, { delimiter } = {}) {
const isArrayValidator = isArray(spec, { delimiter });
return makeValidator({
test: (value, state) => {
var _a, _b;
if (Object.getPrototypeOf(value).toString() === `[object Set]`) {
if (typeof (state === null || state === void 0 ? void 0 : state.coercions) !== `undefined`) {
if (typeof (state === null || state === void 0 ? void 0 : state.coercion) === `undefined`)
return pushError(state, `Unbound coercion result`);
const originalValues = [...value];
const coercedValues = [...value];
if (!isArrayValidator(coercedValues, Object.assign(Object.assign({}, state), { coercion: void 0 })))
return false;
const updateValue = () => coercedValues.some((val, t2) => val !== originalValues[t2]) ? new Set(coercedValues) : value;
state.coercions.push([(_a = state.p) !== null && _a !== void 0 ? _a : `.`, makeLazyCoercionFn(state.coercion, value, updateValue)]);
return true;
} else {
let valid = true;
for (const subValue of value) {
valid = spec(subValue, Object.assign({}, state)) && valid;
if (!valid && (state === null || state === void 0 ? void 0 : state.errors) == null) {
break;
}
}
return valid;
}
}
if (typeof (state === null || state === void 0 ? void 0 : state.coercions) !== `undefined`) {
if (typeof (state === null || state === void 0 ? void 0 : state.coercion) === `undefined`)
return pushError(state, `Unbound coercion result`);
const store = { value };
if (!isArrayValidator(value, Object.assign(Object.assign({}, state), { coercion: makeCoercionFn(store, `value`) })))
return false;
state.coercions.push([(_b = state.p) !== null && _b !== void 0 ? _b : `.`, makeLazyCoercionFn(state.coercion, value, () => new Set(store.value))]);
return true;
}
return pushError(state, `Expected a set (got ${getPrintable(value)})`);
}
});
}
function isMap(keySpec, valueSpec) {
const isArrayValidator = isArray(isTuple([keySpec, valueSpec]));
const isRecordValidator = isRecord(valueSpec, { keys: keySpec });
return makeValidator({
test: (value, state) => {
var _a, _b, _c;
if (Object.getPrototypeOf(value).toString() === `[object Map]`) {
if (typeof (state === null || state === void 0 ? void 0 : state.coercions) !== `undefined`) {
if (typeof (state === null || state === void 0 ? void 0 : state.coercion) === `undefined`)
return pushError(state, `Unbound coercion result`);
const originalValues = [...value];
const coercedValues = [...value];
if (!isArrayValidator(coercedValues, Object.assign(Object.assign({}, state), { coercion: void 0 })))
return false;
const updateValue = () => coercedValues.some((val, t2) => val[0] !== originalValues[t2][0] || val[1] !== originalValues[t2][1]) ? new Map(coercedValues) : value;
state.coercions.push([(_a = state.p) !== null && _a !== void 0 ? _a : `.`, makeLazyCoercionFn(state.coercion, value, updateValue)]);
return true;
} else {
let valid = true;
for (const [key, subValue] of value) {
valid = keySpec(key, Object.assign({}, state)) && valid;
if (!valid && (state === null || state === void 0 ? void 0 : state.errors) == null) {
break;
}
valid = valueSpec(subValue, Object.assign(Object.assign({}, state), { p: computeKey(state, key) })) && valid;
if (!valid && (state === null || state === void 0 ? void 0 : state.errors) == null) {
break;
}
}
return valid;
}
}
if (typeof (state === null || state === void 0 ? void 0 : state.coercions) !== `undefined`) {
if (typeof (state === null || state === void 0 ? void 0 : state.coercion) === `undefined`)
return pushError(state, `Unbound coercion result`);
const store = { value };
if (Array.isArray(value)) {
if (!isArrayValidator(value, Object.assign(Object.assign({}, state), { coercion: void 0 })))
return false;
state.coercions.push([(_b = state.p) !== null && _b !== void 0 ? _b : `.`, makeLazyCoercionFn(state.coercion, value, () => new Map(store.value))]);
return true;
} else {
if (!isRecordValidator(value, Object.assign(Object.assign({}, state), { coercion: makeCoercionFn(store, `value`) })))
return false;
state.coercions.push([(_c = state.p) !== null && _c !== void 0 ? _c : `.`, makeLazyCoercionFn(state.coercion, value, () => new Map(Object.entries(store.value)))]);
return true;
}
}
return pushError(state, `Expected a map (got ${getPrintable(value)})`);
}
});
}
function isTuple(spec, { delimiter } = {}) {
const lengthValidator = hasExactLength(spec.length);
return makeValidator({
test: (value, state) => {
var _a;
if (typeof value === `string` && typeof delimiter !== `undefined`) {
if (typeof (state === null || state === void 0 ? void 0 : state.coercions) !== `undefined`) {
if (typeof (state === null || state === void 0 ? void 0 : state.coercion) === `undefined`)
return pushError(state, `Unbound coercion result`);
value = value.split(delimiter);
state.coercions.push([(_a = state.p) !== null && _a !== void 0 ? _a : `.`, state.coercion.bind(null, value)]);
}
}
if (!Array.isArray(value))
return pushError(state, `Expected a tuple (got ${getPrintable(value)})`);
let valid = lengthValidator(value, Object.assign({}, state));
for (let t2 = 0, T = value.length; t2 < T && t2 < spec.length; ++t2) {
valid = spec[t2](value[t2], Object.assign(Object.assign({}, state), { p: computeKey(state, t2), coercion: makeCoercionFn(value, t2) })) && valid;
if (!valid && (state === null || state === void 0 ? void 0 : state.errors) == null) {
break;
}
}
return valid;
}
});
}
function isRecord(spec, { keys: keySpec = null } = {}) {
const isArrayValidator = isArray(isTuple([keySpec !== null && keySpec !== void 0 ? keySpec : isString(), spec]));
return makeValidator({
test: (value, state) => {
var _a;
if (Array.isArray(value)) {
if (typeof (state === null || state === void 0 ? void 0 : state.coercions) !== `undefined`) {
if (typeof (state === null || state === void 0 ? void 0 : state.coercion) === `undefined`)
return pushError(state, `Unbound coercion result`);
if (!isArrayValidator(value, Object.assign(Object.assign({}, state), { coercion: void 0 })))
return false;
value = Object.fromEntries(value);
state.coercions.push([(_a = state.p) !== null && _a !== void 0 ? _a : `.`, state.coercion.bind(null, value)]);
return true;
}
}
if (typeof value !== `object` || value === null)
return pushError(state, `Expected an object (got ${getPrintable(value)})`);
const keys = Object.keys(value);
let valid = true;
for (let t2 = 0, T = keys.length; t2 < T && (valid || (state === null || state === void 0 ? void 0 : state.errors) != null); ++t2) {
const key = keys[t2];
const sub = value[key];
if (key === `__proto__` || key === `constructor`) {
valid = pushError(Object.assign(Object.assign({}, state), { p: computeKey(state, key) }), `Unsafe property name`);
continue;
}
if (keySpec !== null && !keySpec(key, state)) {
valid = false;
continue;
}
if (!spec(sub, Object.assign(Object.assign({}, state), { p: computeKey(state, key), coercion: makeCoercionFn(value, key) }))) {
valid = false;
continue;
}
}
return valid;
}
});
}
function isDict(spec, opts = {}) {
return isRecord(spec, opts);
}
function isObject(props, { extra: extraSpec = null } = {}) {
const specKeys = Object.keys(props);
const validator = makeValidator({
test: (value, state) => {
if (typeof value !== `object` || value === null)
return pushError(state, `Expected an object (got ${getPrintable(value)})`);
const keys = /* @__PURE__ */ new Set([...specKeys, ...Object.keys(value)]);
const extra = {};
let valid = true;
for (const key of keys) {
if (key === `constructor` || key === `__proto__`) {
valid = pushError(Object.assign(Object.assign({}, state), { p: computeKey(state, key) }), `Unsafe property name`);
} else {
const spec = Object.prototype.hasOwnProperty.call(props, key) ? props[key] : void 0;
const sub = Object.prototype.hasOwnProperty.call(value, key) ? value[key] : void 0;
if (typeof spec !== `undefined`) {
valid = spec(sub, Object.assign(Object.assign({}, state), { p: computeKey(state, key), coercion: makeCoercionFn(value, key) })) && valid;
} else if (extraSpec === null) {
valid = pushError(Object.assign(Object.assign({}, state), { p: computeKey(state, key) }), `Extraneous property (got ${getPrintable(sub)})`);
} else {
Object.defineProperty(extra, key, {
enumerable: true,
get: () => sub,
set: makeSetter(value, key)
});
}
}
if (!valid && (state === null || state === void 0 ? void 0 : state.errors) == null) {
break;
}
}
if (extraSpec !== null && (valid || (state === null || state === void 0 ? void 0 : state.errors) != null))
valid = extraSpec(extra, state) && valid;
return valid;
}
});
return Object.assign(validator, {
properties: props
});
}
function isPartial(props) {
return isObject(props, { extra: isRecord(isUnknown()) });
}
var isInstanceOf = (constructor) => makeValidator({
test: (value, state) => {
if (!(value instanceof constructor))
return pushError(state, `Expected an instance of ${constructor.name} (got ${getPrintable(value)})`);
return true;
}
});
var isOneOf = (specs, { exclusive = false } = {}) => makeValidator({
test: (value, state) => {
var _a, _b, _c;
const matches = [];
const errorBuffer = typeof (state === null || state === void 0 ? void 0 : state.errors) !== `undefined` ? [] : void 0;
for (let t2 = 0, T = specs.length; t2 < T; ++t2) {
const subErrors = typeof (state === null || state === void 0 ? void 0 : state.errors) !== `undefined` ? [] : void 0;
const subCoercions = typeof (state === null || state === void 0 ? void 0 : state.coercions) !== `undefined` ? [] : void 0;
if (specs[t2](value, Object.assign(Object.assign({}, state), { errors: subErrors, coercions: subCoercions, p: `${(_a = state === null || state === void 0 ? void 0 : state.p) !== null && _a !== void 0 ? _a : `.`}#${t2 + 1}` }))) {
matches.push([`#${t2 + 1}`, subCoercions]);
if (!exclusive) {
break;
}
} else {
errorBuffer === null || errorBuffer === void 0 ? void 0 : errorBuffer.push(subErrors[0]);
}
}
if (matches.length === 1) {
const [, subCoercions] = matches[0];
if (typeof subCoercions !== `undefined`)
(_b = state === null || state === void 0 ? void 0 : state.coercions) === null || _b === void 0 ? void 0 : _b.push(...subCoercions);
return true;
}
if (matches.length > 1)
pushError(state, `Expected to match exactly a single predicate (matched ${matches.join(`, `)})`);
else
(_c = state === null || state === void 0 ? void 0 : state.errors) === null || _c === void 0 ? void 0 : _c.push(...errorBuffer);
return false;
}
});
function makeTrait(value) {
return () => {
return value;
};
}
function makeValidator({ test }) {
return makeTrait(test)();
}
var TypeAssertionError = class extends Error {
constructor({ errors } = {}) {
let errorMessage = `Type mismatch`;
if (errors && errors.length > 0) {
errorMessage += `
`;
for (const error of errors) {
errorMessage += `
- ${error}`;
}
}
super(errorMessage);
}
};
function assert(val, validator) {
if (!validator(val)) {
throw new TypeAssertionError();
}
}
function assertWithErrors(val, validator) {
const errors = [];
if (!validator(val, { errors })) {
throw new TypeAssertionError({ errors });
}
}
function softAssert(val, validator) {
}
function as(value, validator, { coerce = false, errors: storeErrors, throw: throws } = {}) {
const errors = storeErrors ? [] : void 0;
if (!coerce) {
if (validator(value, { errors })) {
return throws ? value : { value, errors: void 0 };
} else if (!throws) {
return { value: void 0, errors: errors !== null && errors !== void 0 ? errors : true };
} else {
throw new TypeAssertionError({ errors });
}
}
const state = { value };
const coercion = makeCoercionFn(state, `value`);
const coercions = [];
if (!validator(value, { errors, coercion, coercions })) {
if (!throws) {
return { value: void 0, errors: errors !== null && errors !== void 0 ? errors : true };
} else {
throw new TypeAssertionError({ errors });
}
}
for (const [, apply] of coercions)
apply();
if (throws) {
return state.value;
} else {
return { value: state.value, errors: void 0 };
}
}
function fn(validators, fn2) {
const isValidArgList = isTuple(validators);
return (...args) => {
const check = isValidArgList(args);
if (!check)
throw new TypeAssertionError();
return fn2(...args);
};
}
function hasMinLength(length) {
return makeValidator({
test: (value, state) => {
if (!(value.length >= length))
return pushError(state, `Expected to have a length of at least ${length} elements (got ${value.length})`);
return true;
}
});
}
function hasMaxLength(length) {
return makeValidator({
test: (value, state) => {
if (!(value.length <= length))
return pushError(state, `Expected to have a length of at most ${length} elements (got ${value.length})`);
return true;
}
});
}
function hasExactLength(length) {
return makeValidator({
test: (value, state) => {
if (!(value.length === length))
return pushError(state, `Expected to have a length of exactly ${length} elements (got ${value.length})`);
return true;
}
});
}
function hasUniqueItems({ map } = {}) {
return makeValidator({
test: (value, state) => {
const set = /* @__PURE__ */ new Set();
const dup = /* @__PURE__ */ new Set();
for (let t2 = 0, T = value.length; t2 < T; ++t2) {
const sub = value[t2];
const key = typeof map !== `undefined` ? map(sub) : sub;
if (set.has(key)) {
if (dup.has(key))
continue;
pushError(state, `Expected to contain unique elements; got a duplicate with ${getPrintable(value)}`);
dup.add(key);
} else {
set.add(key);
}
}
return dup.size === 0;
}
});
}
function isNegative() {
return makeValidator({
test: (value, state) => {
if (!(value <= 0))
return pushError(state, `Expected to be negative (got ${value})`);
return true;
}
});
}
function isPositive() {
return makeValidator({
test: (value, state) => {
if (!(value >= 0))
return pushError(state, `Expected to be positive (got ${value})`);
return true;
}
});
}
function isAtLeast(n2) {
return makeValidator({
test: (value, state) => {
if (!(value >= n2))
return pushError(state, `Expected to be at least ${n2} (got ${value})`);
return true;
}
});
}
function isAtMost(n2) {
return makeValidator({
test: (value, state) => {
if (!(value <= n2))
return pushError(state, `Expected to be at most ${n2} (got ${value})`);
return true;
}
});
}
function isInInclusiveRange(a2, b) {
return makeValidator({
test: (value, state) => {
if (!(value >= a2 && value <= b))
return pushError(state, `Expected to be in the [${a2}; ${b}] range (got ${value})`);
return true;
}
});
}
function isInExclusiveRange(a2, b) {
return makeValidator({
test: (value, state) => {
if (!(value >= a2 && value < b))
return pushError(state, `Expected to be in the [${a2}; ${b}[ range (got ${value})`);
return true;
}
});
}
function isInteger({ unsafe = false } = {}) {
return makeValidator({
test: (value, state) => {
if (value !== Math.round(value))
return pushError(state, `Expected to be an integer (got ${value})`);
if (!unsafe && !Number.isSafeInteger(value))
return pushError(state, `Expected to be a safe integer (got ${value})`);
return true;
}
});
}
function matchesRegExp(regExp) {
return makeValidator({
test: (value, state) => {
if (!regExp.test(value))
return pushError(state, `Expected to match the pattern ${regExp.toString()} (got ${getPrintable(value)})`);
return true;
}
});
}
function isLowerCase() {
return makeValidator({
test: (value, state) => {
if (value !== value.toLowerCase())
return pushError(state, `Expected to be all-lowercase (got ${value})`);
return true;
}
});
}
function isUpperCase() {
return makeValidator({
test: (value, state) => {
if (value !== value.toUpperCase())
return pushError(state, `Expected to be all-uppercase (got ${value})`);
return true;
}
});
}
function isUUID4() {
return makeValidator({
test: (value, state) => {
if (!uuid4RegExp.test(value))
return pushError(state, `Expected to be a valid UUID v4 (got ${getPrintable(value)})`);
return true;
}
});
}
function isISO8601() {
return makeValidator({
test: (value, state) => {
if (!iso8601RegExp.test(value))
return pushError(state, `Expected to be a valid ISO 8601 date string (got ${getPrintable(value)})`);
return true;
}
});
}
function isHexColor({ alpha = false }) {
return makeValidator({
test: (value, state) => {
const res = alpha ? colorStringRegExp.test(value) : colorStringAlphaRegExp.test(value);
if (!res)
return pushError(state, `Expected to be a valid hexadecimal color string (got ${getPrintable(value)})`);
return true;
}
});
}
function isBase64() {
return makeValidator({
test: (value, state) => {
if (!base64RegExp.test(value))
return pushError(state, `Expected to be a valid base 64 string (got ${getPrintable(value)})`);
return true;
}
});
}
function isJSON(spec = isUnknown()) {
return makeValidator({
test: (value, state) => {
let data;
try {
data = JSON.parse(value);
} catch (_a) {
return pushError(state, `Expected to be a valid JSON string (got ${getPrintable(value)})`);
}
return spec(data, state);
}
});
}
function cascade(spec, ...followups) {
const resolvedFollowups = Array.isArray(followups[0]) ? followups[0] : followups;
return makeValidator({
test: (value, state) => {
var _a, _b;
const context = { value };
const subCoercion = typeof (state === null || state === void 0 ? void 0 : state.coercions) !== `undefined` ? makeCoercionFn(context, `value`) : void 0;
const subCoercions = typeof (state === null || state === void 0 ? void 0 : state.coercions) !== `undefined` ? [] : void 0;
if (!spec(value, Object.assign(Object.assign({}, state), { coercion: subCoercion, coercions: subCoercions })))
return false;
const reverts = [];
if (typeof subCoercions !== `undefined`)
for (const [, coercion] of subCoercions)
reverts.push(coercion());
try {
if (typeof (state === null || state === void 0 ? void 0 : state.coercions) !== `undefined`) {
if (context.value !== value) {
if (typeof (state === null || state === void 0 ? void 0 : state.coercion) === `undefined`)
return pushError(state, `Unbound coercion result`);
state.coercions.push([(_a = state.p) !== null && _a !== void 0 ? _a : `.`, state.coercion.bind(null, context.value)]);
}
(_b = state === null || state === void 0 ? void 0 : state.coercions) === null || _b === void 0 ? void 0 : _b.push(...subCoercions);
}
return resolvedFollowups.every((spec2) => {
return spec2(context.value, state);
});
} finally {
for (const revert of reverts) {
revert();
}
}
}
});
}
function applyCascade(spec, ...followups) {
const resolvedFollowups = Array.isArray(followups[0]) ? followups[0] : followups;
return cascade(spec, resolvedFollowups);
}
function isOptional(spec) {
return makeValidator({
test: (value, state) => {
if (typeof value === `undefined`)
return true;
return spec(value, state);
}
});
}
function isNullable(spec) {
return makeValidator({
test: (value, state) => {
if (value === null)
return true;
return spec(value, state);
}
});
}
var checks = {
missing: (keys, key) => keys.has(key),
undefined: (keys, key, value) => keys.has(key) && typeof value[key] !== `undefined`,
nil: (keys, key, value) => keys.has(key) && value[key] != null,
falsy: (keys, key, value) => keys.has(key) && !!value[key]
};
function hasRequiredKeys(requiredKeys, options) {
var _a;
const requiredSet = new Set(requiredKeys);
const check = checks[(_a = options === null || options === void 0 ? void 0 : options.missingIf) !== null && _a !== void 0 ? _a : "missing"];
return makeValidator({
test: (value, state) => {
const keys = new Set(Object.keys(value));
const problems = [];
for (const key of requiredSet)
if (!check(keys, key, value))
problems.push(key);
if (problems.length > 0)
return pushError(state, `Missing required ${plural(problems.length, `property`, `properties`)} ${getPrintableArray(problems, `and`)}`);
return true;
}
});
}
function hasAtLeastOneKey(requiredKeys, options) {
var _a;
const requiredSet = new Set(requiredKeys);
const check = checks[(_a = options === null || options === void 0 ? void 0 : options.missingIf) !== null && _a !== void 0 ? _a : "missing"];
return makeValidator({
test: (value, state) => {
const keys = Object.keys(value);
const valid = keys.some((key) => check(requiredSet, key, value));
if (!valid)
return pushError(state, `Missing at least one property from ${getPrintableArray(Array.from(requiredSet), `or`)}`);
return true;
}
});
}
function hasForbiddenKeys(forbiddenKeys, options) {
var _a;
const forbiddenSet = new Set(forbiddenKeys);
const check = checks[(_a = options === null || options === void 0 ? void 0 : options.missingIf) !== null && _a !== void 0 ? _a : "missing"];
return makeValidator({
test: (value, state) => {
const keys = new Set(Object.keys(value));
const problems = [];
for (const key of forbiddenSet)
if (check(keys, key, value))
problems.push(key);
if (problems.length > 0)
return pushError(state, `Forbidden ${plural(problems.length, `property`, `properties`)} ${getPrintableArray(problems, `and`)}`);
return true;
}
});
}
function hasMutuallyExclusiveKeys(exclusiveKeys, options) {
var _a;
const exclusiveSet = new Set(exclusiveKeys);
const check = checks[(_a = options === null || options === void 0 ? void 0 : options.missingIf) !== null && _a !== void 0 ? _a : "missing"];
return makeValidator({
test: (value, state) => {
const keys = new Set(Object.keys(value));
const used = [];
for (const key of exclusiveSet)
if (check(keys, key, value))
used.push(key);
if (used.length > 1)
return pushError(state, `Mutually exclusive properties ${getPrintableArray(used, `and`)}`);
return true;
}
});
}
(function(KeyRelationship) {
KeyRelationship["Forbids"] = "Forbids";
KeyRelationship["Requires"] = "Requires";
})(exports.KeyRelationship || (exports.KeyRelationship = {}));
var keyRelationships = {
[exports.KeyRelationship.Forbids]: {
expect: false,
message: `forbids using`
},
[exports.KeyRelationship.Requires]: {
expect: true,
message: `requires using`
}
};
function hasKeyRelationship(subject, relationship, others, options) {
var _a, _b;
const skipped = new Set((_a = options === null || options === void 0 ? void 0 : options.ignore) !== null && _a !== void 0 ? _a : []);
const check = checks[(_b = options === null || options === void 0 ? void 0 : options.missingIf) !== null && _b !== void 0 ? _b : "missing"];
const otherSet = new Set(others);
const spec = keyRelationships[relationship];
const conjunction = relationship === exports.KeyRelationship.Forbids ? `or` : `and`;
return makeValidator({
test: (value, state) => {
const keys = new Set(Object.keys(value));
if (!check(keys, subject, value) || skipped.has(value[subject]))
return true;
const problems = [];
for (const key of otherSet)
if ((check(keys, key, value) && !skipped.has(value[key])) !== spec.expect)
problems.push(key);
if (problems.length >= 1)
return pushError(state, `Property "${subject}" ${spec.message} ${plural(problems.length, `property`, `properties`)} ${getPrintableArray(problems, conjunction)}`);
return true;
}
});
}
exports.TypeAssertionError = TypeAssertionError;
exports.applyCascade = applyCascade;
exports.as = as;
exports.assert = assert;
exports.assertWithErrors = assertWithErrors;
exports.cascade = cascade;
exports.fn = fn;
exports.hasAtLeastOneKey = hasAtLeastOneKey;
exports.hasExactLength = hasExactLength;
exports.hasForbiddenKeys = hasForbiddenKeys;
exports.hasKeyRelationship = hasKeyRelationship;
exports.hasMaxLength = hasMaxLength;
exports.hasMinLength = hasMinLength;
exports.hasMutuallyExclusiveKeys = hasMutuallyExclusiveKeys;
exports.hasRequiredKeys = hasRequiredKeys;
exports.hasUniqueItems = hasUniqueItems;
exports.isArray = isArray;
exports.isAtLeast = isAtLeast;
exports.isAtMost = isAtMost;
exports.isBase64 = isBase64;
exports.isBoolean = isBoolean;
exports.isDate = isDate;
exports.isDict = isDict;
exports.isEnum = isEnum2;
exports.isHexColor = isHexColor;
exports.isISO8601 = isISO8601;
exports.isInExclusiveRange = isInExclusiveRange;
exports.isInInclusiveRange = isInInclusiveRange;
exports.isInstanceOf = isInstanceOf;
exports.isInteger = isInteger;
exports.isJSON = isJSON;
exports.isLiteral = isLiteral;
exports.isLowerCase = isLowerCase;
exports.isMap = isMap;
exports.isNegative = isNegative;
exports.isNullable = isNullable;
exports.isNumber = isNumber;
exports.isObject = isObject;
exports.isOneOf = isOneOf;
exports.isOptional = isOptional;
exports.isPartial = isPartial;
exports.isPayload = isPayload;
exports.isPositive = isPositive;
exports.isRecord = isRecord;
exports.isSet = isSet;
exports.isString = isString;
exports.isTuple = isTuple;
exports.isUUID4 = isUUID4;
exports.isUnknown = isUnknown;
exports.isUpperCase = isUpperCase;
exports.makeTrait = makeTrait;
exports.makeValidator = makeValidator;
exports.matchesRegExp = matchesRegExp;
exports.softAssert = softAssert;
}
});
// node_modules/yaml/dist/nodes/identity.js
var require_identity = __commonJS({
"node_modules/yaml/dist/nodes/identity.js"(exports) {
var ALIAS = Symbol.for("yaml.alias");
var DOC = Symbol.for("yaml.document");
var MAP = Symbol.for("yaml.map");
var PAIR = Symbol.for("yaml.pair");
var SCALAR = Symbol.for("yaml.scalar");
var SEQ = Symbol.for("yaml.seq");
var NODE_TYPE = Symbol.for("yaml.node.type");
var isAlias = (node) => !!node && typeof node === "object" && node[NODE_TYPE] === ALIAS;
var isDocument = (node) => !!node && typeof node === "object" && node[NODE_TYPE] === DOC;
var isMap = (node) => !!node && typeof node === "object" && node[NODE_TYPE] === MAP;
var isPair = (node) => !!node && typeof node === "object" && node[NODE_TYPE] === PAIR;
var isScalar = (node) => !!node && typeof node === "object" && node[NODE_TYPE] === SCALAR;
var isSeq = (node) => !!node && typeof node === "object" && node[NODE_TYPE] === SEQ;
function isCollection(node) {
if (node && typeof node === "object")
switch (node[NODE_TYPE]) {
case MAP:
case SEQ:
return true;
}
return false;
}
function isNode(node) {
if (node && typeof node === "object")
switch (node[NODE_TYPE]) {
case ALIAS:
case MAP:
case SCALAR:
case SEQ:
return true;
}
return false;
}
var hasAnchor = (node) => (isScalar(node) || isCollection(node)) && !!node.anchor;
exports.ALIAS = ALIAS;
exports.DOC = DOC;
exports.MAP = MAP;
exports.NODE_TYPE = NODE_TYPE;
exports.PAIR = PAIR;
exports.SCALAR = SCALAR;
exports.SEQ = SEQ;
exports.hasAnchor = hasAnchor;
exports.isAlias = isAlias;
exports.isCollection = isCollection;
exports.isDocument = isDocument;
exports.isMap = isMap;
exports.isNode = isNode;
exports.isPair = isPair;
exports.isScalar = isScalar;
exports.isSeq = isSeq;
}
});
// node_modules/yaml/dist/visit.js
var require_visit = __commonJS({
"node_modules/yaml/dist/visit.js"(exports) {
var identity = require_identity();
var BREAK = Symbol("break visit");
var SKIP = Symbol("skip children");
var REMOVE = Symbol("remove node");
function visit(node, visitor) {
const visitor_ = initVisitor(visitor);
if (identity.isDocument(node)) {
const cd = visit_(null, node.contents, visitor_, Object.freeze([node]));
if (cd === REMOVE)
node.contents = null;
} else
visit_(null, node, visitor_, Object.freeze([]));
}
visit.BREAK = BREAK;
visit.SKIP = SKIP;
visit.REMOVE = REMOVE;
function visit_(key, node, visitor, path4) {
const ctrl = callVisitor(key, node, visitor, path4);
if (identity.isNode(ctrl) || identity.isPair(ctrl)) {
replaceNode(key, path4, ctrl);
return visit_(key, ctrl, visitor, path4);
}
if (typeof ctrl !== "symbol") {
if (identity.isCollection(node)) {
path4 = Object.freeze(path4.concat(node));
for (let i = 0; i < node.items.length; ++i) {
const ci = visit_(i, node.items[i], visitor, path4);
if (typeof ci === "number")
i = ci - 1;
else if (ci === BREAK)
return BREAK;
else if (ci === REMOVE) {
node.items.splice(i, 1);
i -= 1;
}
}
} else if (identity.isPair(node)) {
path4 = Object.freeze(path4.concat(node));
const ck = visit_("key", node.key, visitor, path4);
if (ck === BREAK)
return BREAK;
else if (ck === REMOVE)
node.key = null;
const cv = visit_("value", node.value, visitor, path4);
if (cv === BREAK)
return BREAK;
else if (cv === REMOVE)
node.value = null;
}
}
return ctrl;
}
async function visitAsync(node, visitor) {
const visitor_ = initVisitor(visitor);
if (identity.isDocument(node)) {
const cd = await visitAsync_(null, node.contents, visitor_, Object.freeze([node]));
if (cd === REMOVE)
node.contents = null;
} else
await visitAsync_(null, node, visitor_, Object.freeze([]));
}
visitAsync.BREAK = BREAK;
visitAsync.SKIP = SKIP;
visitAsync.REMOVE = REMOVE;
async function visitAsync_(key, node, visitor, path4) {
const ctrl = await callVisitor(key, node, visitor, path4);
if (identity.isNode(ctrl) || identity.isPair(ctrl)) {
replaceNode(key, path4, ctrl);
return visitAsync_(key, ctrl, visitor, path4);
}
if (typeof ctrl !== "symbol") {
if (identity.isCollection(node)) {
path4 = Object.freeze(path4.concat(node));
for (let i = 0; i < node.items.length; ++i) {
const ci = await visitAsync_(i, node.items[i], visitor, path4);
if (typeof ci === "number")
i = ci - 1;
else if (ci === BREAK)
return BREAK;
else if (ci === REMOVE) {
node.items.splice(i, 1);
i -= 1;
}
}
} else if (identity.isPair(node)) {
path4 = Object.freeze(path4.concat(node));
const ck = await visitAsync_("key", node.key, visitor, path4);
if (ck === BREAK)
return BREAK;
else if (ck === REMOVE)
node.key = null;
const cv = await visitAsync_("value", node.value, visitor, path4);
if (cv === BREAK)
return BREAK;
else if (cv === REMOVE)
node.value = null;
}
}
return ctrl;
}
function initVisitor(visitor) {
if (typeof visitor === "object" && (visitor.Collection || visitor.Node || visitor.Value)) {
return Object.assign({
Alias: visitor.Node,
Map: visitor.Node,
Scalar: visitor.Node,
Seq: visitor.Node
}, visitor.Value && {
Map: visitor.Value,
Scalar: visitor.Value,
Seq: visitor.Value
}, visitor.Collection && {
Map: visitor.Collection,
Seq: visitor.Collection
}, visitor);
}
return visitor;
}
function callVisitor(key, node, visitor, path4) {
if (typeof visitor === "function")
return visitor(key, node, path4);
if (identity.isMap(node))
return visitor.Map?.(key, node, path4);
if (identity.isSeq(node))
return visitor.Seq?.(key, node, path4);
if (identity.isPair(node))
return visitor.Pair?.(key, node, path4);
if (identity.isScalar(node))
return visitor.Scalar?.(key, node, path4);
if (identity.isAlias(node))
return visitor.Alias?.(key, node, path4);
return void 0;
}
function replaceNode(key, path4, node) {
const parent = path4[path4.length - 1];
if (identity.isCollection(parent)) {
parent.items[key] = node;
} else if (identity.isPair(parent)) {
if (key === "key")
parent.key = node;
else
pa