UNPKG

@lbu/code-gen

Version:

Generate various boring parts of your server

2,003 lines (2,001 loc) 116 kB
// Generated by @lbu/code-gen /* eslint-disable no-unused-vars */ /** * @param {*} value * @returns {boolean} */ export function isNil(value) { return value === undefined || value === null; } /** * @name {ValidationErrorFn} * This function should not throw as the corresponding validator will do that * @typedef {function(string,any): Error} */ /** @type {ValidationErrorFn} */ let errorFn = (key, info) => { const err = new Error(`ValidationError: ${key}`); err.key = key; err.info = info; return err; }; /** * @param {string} type * @param {string} key * @param {*} info */ export function buildError(type, key, info) { return errorFn(`validator.${type}.${key}`, info); } /** * Set a different error function, for example AppError.validationError * @param {ValidationErrorFn} fn */ export function validatorSetError(fn) { errorFn = fn; } /** * @param {*} value * @param {string} propertyPath * @param {*[]} errors * @param {string} parentType * @returns {"anyOf"|undefined} */ export function anonymousValidator1( value, propertyPath, errors = [], parentType = "string", ) { if (isNil(value)) { errors.push(buildError(parentType, "undefined", { propertyPath })); return undefined; } if (typeof value !== "string") { errors.push(buildError(parentType, "type", { propertyPath })); return undefined; } if (value.length < 1) { const min = 1; errors.push(buildError(parentType, "min", { propertyPath, min })); return undefined; } if (value !== "anyOf") { const oneOf = ["anyOf"]; errors.push(buildError(parentType, "oneOf", { propertyPath, oneOf })); return undefined; } return value; } /** * @param {*} value * @param {string} propertyPath * @param {*[]} errors * @param {string} parentType * @returns {string|undefined} */ export function anonymousValidator2( value, propertyPath, errors = [], parentType = "string", ) { if (isNil(value)) { return ""; } if (typeof value !== "string") { errors.push(buildError(parentType, "type", { propertyPath })); return undefined; } if (value.length === 0) { return ""; } if (value.length < 1) { const min = 1; errors.push(buildError(parentType, "min", { propertyPath, min })); return undefined; } return value; } /** * @param {*} value * @param {string} propertyPath * @param {*[]} errors * @param {string} parentType * @returns {boolean|undefined} */ export function anonymousValidator3( value, propertyPath, errors = [], parentType = "boolean", ) { if (isNil(value)) { return false; } if (typeof value !== "boolean") { errors.push(buildError(parentType, "type", { propertyPath })); return undefined; } return value; } /** * @param {*} value * @param {string} propertyPath * @param {*[]} errors * @param {string} parentType * @returns {string|undefined} */ export function anonymousValidator5( value, propertyPath, errors = [], parentType = "string", ) { if (isNil(value)) { errors.push(buildError(parentType, "undefined", { propertyPath })); return undefined; } if (typeof value !== "string") { errors.push(buildError(parentType, "type", { propertyPath })); return undefined; } if (value.length < 0) { const min = 0; errors.push(buildError(parentType, "min", { propertyPath, min })); return undefined; } return value; } /** * @param {*} value * @param {string} propertyPath * @param {*[]} errors * @param {string} parentType * @returns {boolean|undefined} */ export function anonymousValidator6( value, propertyPath, errors = [], parentType = "boolean", ) { if (isNil(value)) { errors.push(buildError(parentType, "undefined", { propertyPath })); return undefined; } if (typeof value !== "boolean") { errors.push(buildError(parentType, "type", { propertyPath })); return undefined; } return value; } /** * @param {*} value * @param {string} propertyPath * @param {*[]} errors * @param {string} parentType * @returns {number|undefined} */ export function anonymousValidator7( value, propertyPath, errors = [], parentType = "number", ) { if (isNil(value)) { errors.push(buildError(parentType, "undefined", { propertyPath })); return undefined; } if (typeof value !== "number" || isNaN(value) || !isFinite(value)) { errors.push(buildError(parentType, "type", { propertyPath })); return undefined; } if (!Number.isInteger(value)) { errors.push(buildError(parentType, "integer", { propertyPath })); return undefined; } return value; } /** * @param {*} value * @param {string} propertyPath * @param {*[]} errors * @param {string} parentType * @returns {undefined|string|boolean|number|undefined} */ export function anonymousValidator4( value, propertyPath, errors = [], parentType = "anyOf", ) { if (isNil(value)) { return value; } let errorCount = 0; const subErrors = []; let result = undefined; result = anonymousValidator5(value, propertyPath, subErrors); if (subErrors.length === errorCount) { return result; } subErrors.splice(errorCount + 1, subErrors.length - errorCount); errorCount = subErrors.length; result = anonymousValidator6(value, propertyPath, subErrors); if (subErrors.length === errorCount) { return result; } subErrors.splice(errorCount + 1, subErrors.length - errorCount); errorCount = subErrors.length; result = anonymousValidator7(value, propertyPath, subErrors); if (subErrors.length === errorCount) { return result; } subErrors.splice(errorCount + 1, subErrors.length - errorCount); errorCount = subErrors.length; errors.push( buildError(parentType, "type", { propertyPath, errors: subErrors }), ); return undefined; } /** * @param {*} value * @param {string} propertyPath * @param {*[]} errors * @param {string} parentType * @returns {undefined|string|undefined} */ export function anonymousValidator8( value, propertyPath, errors = [], parentType = "string", ) { if (isNil(value)) { return value; } if (typeof value !== "string") { errors.push(buildError(parentType, "type", { propertyPath })); return undefined; } if (value.length === 0) { return undefined; } if (value.length < 1) { const min = 1; errors.push(buildError(parentType, "min", { propertyPath, min })); return undefined; } return value; } /** * @param {*} value * @param {string} propertyPath * @param {*[]} errors * @param {string} parentType * @returns {undefined|{"primary": boolean, "searchable": boolean, }|undefined} */ export function anonymousValidator9( value, propertyPath, errors = [], parentType = "object", ) { if (isNil(value)) { return value; } if (typeof value !== "object") { errors.push(buildError(parentType, "type", { propertyPath })); return undefined; } const result = Object.create(null); result["primary"] = anonymousValidator3( value["primary"], `${propertyPath}.primary`, errors, ); result["searchable"] = anonymousValidator3( value["searchable"], `${propertyPath}.searchable`, errors, ); return result; } /** * @param {*} value * @param {string} propertyPath * @param {*[]} errors * @param {string} parentType * @returns {{}|undefined} */ export function anonymousValidator10( value, propertyPath, errors = [], parentType = "object", ) { if (isNil(value)) { return {}; } if (typeof value !== "object") { errors.push(buildError(parentType, "type", { propertyPath })); return undefined; } const result = Object.create(null); return result; } /** * @param {*} value * @param {string} propertyPath * @param {*[]} errors * @param {string} parentType * @returns {"any"|undefined} */ export function anonymousValidator16( value, propertyPath, errors = [], parentType = "string", ) { if (isNil(value)) { errors.push(buildError(parentType, "undefined", { propertyPath })); return undefined; } if (typeof value !== "string") { errors.push(buildError(parentType, "type", { propertyPath })); return undefined; } if (value.length < 1) { const min = 1; errors.push(buildError(parentType, "min", { propertyPath, min })); return undefined; } if (value !== "any") { const oneOf = ["any"]; errors.push(buildError(parentType, "oneOf", { propertyPath, oneOf })); return undefined; } return value; } /** * @param {*} value * @param {string} propertyPath * @param {*[]} errors * @param {string} parentType * @returns {{"allowNull": boolean, }|undefined} */ export function anonymousValidator17( value, propertyPath, errors = [], parentType = "object", ) { if (isNil(value)) { return { allowNull: false }; } if (typeof value !== "object") { errors.push(buildError(parentType, "type", { propertyPath })); return undefined; } const result = Object.create(null); result["allowNull"] = anonymousValidator3( value["allowNull"], `${propertyPath}.allowNull`, errors, ); return result; } /** * @param {*} value * @param {string} propertyPath * @param {*[]} errors * @param {string} parentType * @returns {{"javaScript"?: string, "typeScript"?: string, }|undefined} */ export function anonymousValidator18( value, propertyPath, errors = [], parentType = "object", ) { if (isNil(value)) { return {}; } if (typeof value !== "object") { errors.push(buildError(parentType, "type", { propertyPath })); return undefined; } const result = Object.create(null); result["javaScript"] = anonymousValidator8( value["javaScript"], `${propertyPath}.javaScript`, errors, ); result["typeScript"] = anonymousValidator8( value["typeScript"], `${propertyPath}.typeScript`, errors, ); return result; } /** * @param {*} value * @param {string} propertyPath * @param {*[]} errors * @param {string} parentType * @returns {{"type": "any", "docString": string, "isOptional": boolean, "defaultValue"?: string|boolean|number, "uniqueName"?: string, "group"?: string, "name"?: string, "sql"?: {"primary": boolean, "searchable": boolean, }, "validator": {"allowNull": boolean, }, "rawValue"?: string, "importRaw": {"javaScript"?: string, "typeScript"?: string, }, }|undefined} */ export function anonymousValidator15( value, propertyPath, errors = [], parentType = "object", ) { if (isNil(value)) { errors.push(buildError(parentType, "undefined", { propertyPath })); return undefined; } if (typeof value !== "object") { errors.push(buildError(parentType, "type", { propertyPath })); return undefined; } const result = Object.create(null); result["type"] = anonymousValidator16( value["type"], `${propertyPath}.type`, errors, ); result["docString"] = anonymousValidator2( value["docString"], `${propertyPath}.docString`, errors, ); result["isOptional"] = anonymousValidator3( value["isOptional"], `${propertyPath}.isOptional`, errors, ); result["defaultValue"] = anonymousValidator4( value["defaultValue"], `${propertyPath}.defaultValue`, errors, ); result["uniqueName"] = anonymousValidator8( value["uniqueName"], `${propertyPath}.uniqueName`, errors, ); result["group"] = anonymousValidator8( value["group"], `${propertyPath}.group`, errors, ); result["name"] = anonymousValidator8( value["name"], `${propertyPath}.name`, errors, ); result["sql"] = anonymousValidator9( value["sql"], `${propertyPath}.sql`, errors, ); result["validator"] = anonymousValidator17( value["validator"], `${propertyPath}.validator`, errors, ); result["rawValue"] = anonymousValidator8( value["rawValue"], `${propertyPath}.rawValue`, errors, ); result["importRaw"] = anonymousValidator18( value["importRaw"], `${propertyPath}.importRaw`, errors, ); return result; } /** * @param {*} value * @param {string} propertyPath * @param {*[]} errors * @param {string} parentType * @returns {CodeGenAnyType|undefined} */ export function anonymousValidator14( value, propertyPath, errors = [], parentType = "reference", ) { if (isNil(value)) { errors.push(buildError(parentType, "undefined", { propertyPath })); return undefined; } return anonymousValidator15(value, propertyPath, errors); } /** * @param {*} value * @param {string} propertyPath * @param {*[]} errors * @param {string} parentType * @returns {CodeGenAnyOfType|undefined} */ export function anonymousValidator19( value, propertyPath, errors = [], parentType = "reference", ) { if (isNil(value)) { errors.push(buildError(parentType, "undefined", { propertyPath })); return undefined; } return anonymousValidator0(value, propertyPath, errors); } /** * @param {*} value * @param {string} propertyPath * @param {*[]} errors * @param {string} parentType * @returns {"array"|undefined} */ export function anonymousValidator22( value, propertyPath, errors = [], parentType = "string", ) { if (isNil(value)) { errors.push(buildError(parentType, "undefined", { propertyPath })); return undefined; } if (typeof value !== "string") { errors.push(buildError(parentType, "type", { propertyPath })); return undefined; } if (value.length < 1) { const min = 1; errors.push(buildError(parentType, "min", { propertyPath, min })); return undefined; } if (value !== "array") { const oneOf = ["array"]; errors.push(buildError(parentType, "oneOf", { propertyPath, oneOf })); return undefined; } return value; } /** * @param {*} value * @param {string} propertyPath * @param {*[]} errors * @param {string} parentType * @returns {undefined|number|undefined} */ export function anonymousValidator24( value, propertyPath, errors = [], parentType = "number", ) { if (isNil(value)) { return value; } if (typeof value !== "number" || isNaN(value) || !isFinite(value)) { errors.push(buildError(parentType, "type", { propertyPath })); return undefined; } if (!Number.isInteger(value)) { errors.push(buildError(parentType, "integer", { propertyPath })); return undefined; } return value; } /** * @param {*} value * @param {string} propertyPath * @param {*[]} errors * @param {string} parentType * @returns {{"convert": boolean, "min"?: number, "max"?: number, }|undefined} */ export function anonymousValidator23( value, propertyPath, errors = [], parentType = "object", ) { if (isNil(value)) { errors.push(buildError(parentType, "undefined", { propertyPath })); return undefined; } if (typeof value !== "object") { errors.push(buildError(parentType, "type", { propertyPath })); return undefined; } const result = Object.create(null); result["convert"] = anonymousValidator3( value["convert"], `${propertyPath}.convert`, errors, ); result["min"] = anonymousValidator24( value["min"], `${propertyPath}.min`, errors, ); result["max"] = anonymousValidator24( value["max"], `${propertyPath}.max`, errors, ); return result; } /** * @param {*} value * @param {string} propertyPath * @param {*[]} errors * @param {string} parentType * @returns {CodeGenType|undefined} */ export function anonymousValidator25( value, propertyPath, errors = [], parentType = "reference", ) { if (isNil(value)) { errors.push(buildError(parentType, "undefined", { propertyPath })); return undefined; } return anonymousValidator13(value, propertyPath, errors); } /** * @param {*} value * @param {string} propertyPath * @param {*[]} errors * @param {string} parentType * @returns {{"type": "array", "docString": string, "isOptional": boolean, "defaultValue"?: string|boolean|number, "uniqueName"?: string, "group"?: string, "name"?: string, "sql"?: {"primary": boolean, "searchable": boolean, }, "validator": {"convert": boolean, "min"?: number, "max"?: number, }, "values": CodeGenType, }|undefined} */ export function anonymousValidator21( value, propertyPath, errors = [], parentType = "object", ) { if (isNil(value)) { errors.push(buildError(parentType, "undefined", { propertyPath })); return undefined; } if (typeof value !== "object") { errors.push(buildError(parentType, "type", { propertyPath })); return undefined; } const result = Object.create(null); result["type"] = anonymousValidator22( value["type"], `${propertyPath}.type`, errors, ); result["docString"] = anonymousValidator2( value["docString"], `${propertyPath}.docString`, errors, ); result["isOptional"] = anonymousValidator3( value["isOptional"], `${propertyPath}.isOptional`, errors, ); result["defaultValue"] = anonymousValidator4( value["defaultValue"], `${propertyPath}.defaultValue`, errors, ); result["uniqueName"] = anonymousValidator8( value["uniqueName"], `${propertyPath}.uniqueName`, errors, ); result["group"] = anonymousValidator8( value["group"], `${propertyPath}.group`, errors, ); result["name"] = anonymousValidator8( value["name"], `${propertyPath}.name`, errors, ); result["sql"] = anonymousValidator9( value["sql"], `${propertyPath}.sql`, errors, ); result["validator"] = anonymousValidator23( value["validator"], `${propertyPath}.validator`, errors, ); result["values"] = anonymousValidator25( value["values"], `${propertyPath}.values`, errors, ); return result; } /** * @param {*} value * @param {string} propertyPath * @param {*[]} errors * @param {string} parentType * @returns {CodeGenArrayType|undefined} */ export function anonymousValidator20( value, propertyPath, errors = [], parentType = "reference", ) { if (isNil(value)) { errors.push(buildError(parentType, "undefined", { propertyPath })); return undefined; } return anonymousValidator21(value, propertyPath, errors); } /** * @param {*} value * @param {string} propertyPath * @param {*[]} errors * @param {string} parentType * @returns {"boolean"|undefined} */ export function anonymousValidator28( value, propertyPath, errors = [], parentType = "string", ) { if (isNil(value)) { errors.push(buildError(parentType, "undefined", { propertyPath })); return undefined; } if (typeof value !== "string") { errors.push(buildError(parentType, "type", { propertyPath })); return undefined; } if (value.length < 1) { const min = 1; errors.push(buildError(parentType, "min", { propertyPath, min })); return undefined; } if (value !== "boolean") { const oneOf = ["boolean"]; errors.push(buildError(parentType, "oneOf", { propertyPath, oneOf })); return undefined; } return value; } /** * @param {*} value * @param {string} propertyPath * @param {*[]} errors * @param {string} parentType * @returns {{"convert": boolean, "allowNull": boolean, }|undefined} */ export function anonymousValidator29( value, propertyPath, errors = [], parentType = "object", ) { if (isNil(value)) { errors.push(buildError(parentType, "undefined", { propertyPath })); return undefined; } if (typeof value !== "object") { errors.push(buildError(parentType, "type", { propertyPath })); return undefined; } const result = Object.create(null); result["convert"] = anonymousValidator3( value["convert"], `${propertyPath}.convert`, errors, ); result["allowNull"] = anonymousValidator3( value["allowNull"], `${propertyPath}.allowNull`, errors, ); return result; } /** * @param {*} value * @param {string} propertyPath * @param {*[]} errors * @param {string} parentType * @returns {undefined|boolean|undefined} */ export function anonymousValidator30( value, propertyPath, errors = [], parentType = "boolean", ) { if (isNil(value)) { return value; } if (typeof value !== "boolean") { errors.push(buildError(parentType, "type", { propertyPath })); return undefined; } return value; } /** * @param {*} value * @param {string} propertyPath * @param {*[]} errors * @param {string} parentType * @returns {{"type": "boolean", "docString": string, "isOptional": boolean, "defaultValue"?: string|boolean|number, "uniqueName"?: string, "group"?: string, "name"?: string, "sql"?: {"primary": boolean, "searchable": boolean, }, "validator": {"convert": boolean, "allowNull": boolean, }, "oneOf"?: boolean, }|undefined} */ export function anonymousValidator27( value, propertyPath, errors = [], parentType = "object", ) { if (isNil(value)) { errors.push(buildError(parentType, "undefined", { propertyPath })); return undefined; } if (typeof value !== "object") { errors.push(buildError(parentType, "type", { propertyPath })); return undefined; } const result = Object.create(null); result["type"] = anonymousValidator28( value["type"], `${propertyPath}.type`, errors, ); result["docString"] = anonymousValidator2( value["docString"], `${propertyPath}.docString`, errors, ); result["isOptional"] = anonymousValidator3( value["isOptional"], `${propertyPath}.isOptional`, errors, ); result["defaultValue"] = anonymousValidator4( value["defaultValue"], `${propertyPath}.defaultValue`, errors, ); result["uniqueName"] = anonymousValidator8( value["uniqueName"], `${propertyPath}.uniqueName`, errors, ); result["group"] = anonymousValidator8( value["group"], `${propertyPath}.group`, errors, ); result["name"] = anonymousValidator8( value["name"], `${propertyPath}.name`, errors, ); result["sql"] = anonymousValidator9( value["sql"], `${propertyPath}.sql`, errors, ); result["validator"] = anonymousValidator29( value["validator"], `${propertyPath}.validator`, errors, ); result["oneOf"] = anonymousValidator30( value["oneOf"], `${propertyPath}.oneOf`, errors, ); return result; } /** * @param {*} value * @param {string} propertyPath * @param {*[]} errors * @param {string} parentType * @returns {CodeGenBooleanType|undefined} */ export function anonymousValidator26( value, propertyPath, errors = [], parentType = "reference", ) { if (isNil(value)) { errors.push(buildError(parentType, "undefined", { propertyPath })); return undefined; } return anonymousValidator27(value, propertyPath, errors); } /** * @param {*} value * @param {string} propertyPath * @param {*[]} errors * @param {string} parentType * @returns {"date"|undefined} */ export function anonymousValidator33( value, propertyPath, errors = [], parentType = "string", ) { if (isNil(value)) { errors.push(buildError(parentType, "undefined", { propertyPath })); return undefined; } if (typeof value !== "string") { errors.push(buildError(parentType, "type", { propertyPath })); return undefined; } if (value.length < 1) { const min = 1; errors.push(buildError(parentType, "min", { propertyPath, min })); return undefined; } if (value !== "date") { const oneOf = ["date"]; errors.push(buildError(parentType, "oneOf", { propertyPath, oneOf })); return undefined; } return value; } /** * @param {*} value * @param {string} propertyPath * @param {*[]} errors * @param {string} parentType * @returns {{"type": "date", "docString": string, "isOptional": boolean, "defaultValue"?: string|boolean|number, "uniqueName"?: string, "group"?: string, "name"?: string, "sql"?: {"primary": boolean, "searchable": boolean, }, "validator": {"allowNull": boolean, }, }|undefined} */ export function anonymousValidator32( value, propertyPath, errors = [], parentType = "object", ) { if (isNil(value)) { errors.push(buildError(parentType, "undefined", { propertyPath })); return undefined; } if (typeof value !== "object") { errors.push(buildError(parentType, "type", { propertyPath })); return undefined; } const result = Object.create(null); result["type"] = anonymousValidator33( value["type"], `${propertyPath}.type`, errors, ); result["docString"] = anonymousValidator2( value["docString"], `${propertyPath}.docString`, errors, ); result["isOptional"] = anonymousValidator3( value["isOptional"], `${propertyPath}.isOptional`, errors, ); result["defaultValue"] = anonymousValidator4( value["defaultValue"], `${propertyPath}.defaultValue`, errors, ); result["uniqueName"] = anonymousValidator8( value["uniqueName"], `${propertyPath}.uniqueName`, errors, ); result["group"] = anonymousValidator8( value["group"], `${propertyPath}.group`, errors, ); result["name"] = anonymousValidator8( value["name"], `${propertyPath}.name`, errors, ); result["sql"] = anonymousValidator9( value["sql"], `${propertyPath}.sql`, errors, ); result["validator"] = anonymousValidator17( value["validator"], `${propertyPath}.validator`, errors, ); return result; } /** * @param {*} value * @param {string} propertyPath * @param {*[]} errors * @param {string} parentType * @returns {CodeGenDateType|undefined} */ export function anonymousValidator31( value, propertyPath, errors = [], parentType = "reference", ) { if (isNil(value)) { errors.push(buildError(parentType, "undefined", { propertyPath })); return undefined; } return anonymousValidator32(value, propertyPath, errors); } /** * @param {*} value * @param {string} propertyPath * @param {*[]} errors * @param {string} parentType * @returns {"file"|undefined} */ export function anonymousValidator36( value, propertyPath, errors = [], parentType = "string", ) { if (isNil(value)) { errors.push(buildError(parentType, "undefined", { propertyPath })); return undefined; } if (typeof value !== "string") { errors.push(buildError(parentType, "type", { propertyPath })); return undefined; } if (value.length < 1) { const min = 1; errors.push(buildError(parentType, "min", { propertyPath, min })); return undefined; } if (value !== "file") { const oneOf = ["file"]; errors.push(buildError(parentType, "oneOf", { propertyPath, oneOf })); return undefined; } return value; } /** * @param {*} value * @param {string} propertyPath * @param {*[]} errors * @param {string} parentType * @returns {{"type": "file", "docString": string, "isOptional": boolean, "defaultValue"?: string|boolean|number, "uniqueName"?: string, "group"?: string, "name"?: string, "sql"?: {"primary": boolean, "searchable": boolean, }, "validator": {}, }|undefined} */ export function anonymousValidator35( value, propertyPath, errors = [], parentType = "object", ) { if (isNil(value)) { errors.push(buildError(parentType, "undefined", { propertyPath })); return undefined; } if (typeof value !== "object") { errors.push(buildError(parentType, "type", { propertyPath })); return undefined; } const result = Object.create(null); result["type"] = anonymousValidator36( value["type"], `${propertyPath}.type`, errors, ); result["docString"] = anonymousValidator2( value["docString"], `${propertyPath}.docString`, errors, ); result["isOptional"] = anonymousValidator3( value["isOptional"], `${propertyPath}.isOptional`, errors, ); result["defaultValue"] = anonymousValidator4( value["defaultValue"], `${propertyPath}.defaultValue`, errors, ); result["uniqueName"] = anonymousValidator8( value["uniqueName"], `${propertyPath}.uniqueName`, errors, ); result["group"] = anonymousValidator8( value["group"], `${propertyPath}.group`, errors, ); result["name"] = anonymousValidator8( value["name"], `${propertyPath}.name`, errors, ); result["sql"] = anonymousValidator9( value["sql"], `${propertyPath}.sql`, errors, ); result["validator"] = anonymousValidator10( value["validator"], `${propertyPath}.validator`, errors, ); return result; } /** * @param {*} value * @param {string} propertyPath * @param {*[]} errors * @param {string} parentType * @returns {CodeGenFileType|undefined} */ export function anonymousValidator34( value, propertyPath, errors = [], parentType = "reference", ) { if (isNil(value)) { errors.push(buildError(parentType, "undefined", { propertyPath })); return undefined; } return anonymousValidator35(value, propertyPath, errors); } /** * @param {*} value * @param {string} propertyPath * @param {*[]} errors * @param {string} parentType * @returns {"generic"|undefined} */ export function anonymousValidator39( value, propertyPath, errors = [], parentType = "string", ) { if (isNil(value)) { errors.push(buildError(parentType, "undefined", { propertyPath })); return undefined; } if (typeof value !== "string") { errors.push(buildError(parentType, "type", { propertyPath })); return undefined; } if (value.length < 1) { const min = 1; errors.push(buildError(parentType, "min", { propertyPath, min })); return undefined; } if (value !== "generic") { const oneOf = ["generic"]; errors.push(buildError(parentType, "oneOf", { propertyPath, oneOf })); return undefined; } return value; } /** * @param {*} value * @param {string} propertyPath * @param {*[]} errors * @param {string} parentType * @returns {CodeGenType|undefined} */ export function anonymousValidator40( value, propertyPath, errors = [], parentType = "reference", ) { if (isNil(value)) { errors.push(buildError(parentType, "undefined", { propertyPath })); return undefined; } return anonymousValidator13(value, propertyPath, errors); } /** * @param {*} value * @param {string} propertyPath * @param {*[]} errors * @param {string} parentType * @returns {CodeGenType|undefined} */ export function anonymousValidator41( value, propertyPath, errors = [], parentType = "reference", ) { if (isNil(value)) { errors.push(buildError(parentType, "undefined", { propertyPath })); return undefined; } return anonymousValidator13(value, propertyPath, errors); } /** * @param {*} value * @param {string} propertyPath * @param {*[]} errors * @param {string} parentType * @returns {{"type": "generic", "docString": string, "isOptional": boolean, "defaultValue"?: string|boolean|number, "uniqueName"?: string, "group"?: string, "name"?: string, "sql"?: {"primary": boolean, "searchable": boolean, }, "validator": {}, "keys": CodeGenType, "values": CodeGenType, }|undefined} */ export function anonymousValidator38( value, propertyPath, errors = [], parentType = "object", ) { if (isNil(value)) { errors.push(buildError(parentType, "undefined", { propertyPath })); return undefined; } if (typeof value !== "object") { errors.push(buildError(parentType, "type", { propertyPath })); return undefined; } const result = Object.create(null); result["type"] = anonymousValidator39( value["type"], `${propertyPath}.type`, errors, ); result["docString"] = anonymousValidator2( value["docString"], `${propertyPath}.docString`, errors, ); result["isOptional"] = anonymousValidator3( value["isOptional"], `${propertyPath}.isOptional`, errors, ); result["defaultValue"] = anonymousValidator4( value["defaultValue"], `${propertyPath}.defaultValue`, errors, ); result["uniqueName"] = anonymousValidator8( value["uniqueName"], `${propertyPath}.uniqueName`, errors, ); result["group"] = anonymousValidator8( value["group"], `${propertyPath}.group`, errors, ); result["name"] = anonymousValidator8( value["name"], `${propertyPath}.name`, errors, ); result["sql"] = anonymousValidator9( value["sql"], `${propertyPath}.sql`, errors, ); result["validator"] = anonymousValidator10( value["validator"], `${propertyPath}.validator`, errors, ); result["keys"] = anonymousValidator40( value["keys"], `${propertyPath}.keys`, errors, ); result["values"] = anonymousValidator41( value["values"], `${propertyPath}.values`, errors, ); return result; } /** * @param {*} value * @param {string} propertyPath * @param {*[]} errors * @param {string} parentType * @returns {CodeGenGenericType|undefined} */ export function anonymousValidator37( value, propertyPath, errors = [], parentType = "reference", ) { if (isNil(value)) { errors.push(buildError(parentType, "undefined", { propertyPath })); return undefined; } return anonymousValidator38(value, propertyPath, errors); } /** * @param {*} value * @param {string} propertyPath * @param {*[]} errors * @param {string} parentType * @returns {"number"|undefined} */ export function anonymousValidator44( value, propertyPath, errors = [], parentType = "string", ) { if (isNil(value)) { errors.push(buildError(parentType, "undefined", { propertyPath })); return undefined; } if (typeof value !== "string") { errors.push(buildError(parentType, "type", { propertyPath })); return undefined; } if (value.length < 1) { const min = 1; errors.push(buildError(parentType, "min", { propertyPath, min })); return undefined; } if (value !== "number") { const oneOf = ["number"]; errors.push(buildError(parentType, "oneOf", { propertyPath, oneOf })); return undefined; } return value; } /** * @param {*} value * @param {string} propertyPath * @param {*[]} errors * @param {string} parentType * @returns {{"convert": boolean, "floatingPoint": boolean, "min"?: number, "max"?: number, "allowNull": boolean, }|undefined} */ export function anonymousValidator45( value, propertyPath, errors = [], parentType = "object", ) { if (isNil(value)) { errors.push(buildError(parentType, "undefined", { propertyPath })); return undefined; } if (typeof value !== "object") { errors.push(buildError(parentType, "type", { propertyPath })); return undefined; } const result = Object.create(null); result["convert"] = anonymousValidator3( value["convert"], `${propertyPath}.convert`, errors, ); result["floatingPoint"] = anonymousValidator3( value["floatingPoint"], `${propertyPath}.floatingPoint`, errors, ); result["min"] = anonymousValidator24( value["min"], `${propertyPath}.min`, errors, ); result["max"] = anonymousValidator24( value["max"], `${propertyPath}.max`, errors, ); result["allowNull"] = anonymousValidator3( value["allowNull"], `${propertyPath}.allowNull`, errors, ); return result; } /** * @param {*} value * @param {string} propertyPath * @param {*[]} errors * @param {string} parentType * @returns {undefined|(number)[]|undefined} */ export function anonymousValidator46( value, propertyPath, errors = [], parentType = "array", ) { if (isNil(value)) { return value; } if (!Array.isArray(value)) { errors.push(buildError(parentType, "type", { propertyPath })); return undefined; } const result = Array.from({ length: value.length }); for (let i = 0; i < value.length; ++i) { result[i] = anonymousValidator7(value[i], `${propertyPath}[${i}]`, errors); } return result; } /** * @param {*} value * @param {string} propertyPath * @param {*[]} errors * @param {string} parentType * @returns {{"type": "number", "docString": string, "isOptional": boolean, "defaultValue"?: string|boolean|number, "uniqueName"?: string, "group"?: string, "name"?: string, "sql"?: {"primary": boolean, "searchable": boolean, }, "validator": {"convert": boolean, "floatingPoint": boolean, "min"?: number, "max"?: number, "allowNull": boolean, }, "oneOf"?: (number)[], }|undefined} */ export function anonymousValidator43( value, propertyPath, errors = [], parentType = "object", ) { if (isNil(value)) { errors.push(buildError(parentType, "undefined", { propertyPath })); return undefined; } if (typeof value !== "object") { errors.push(buildError(parentType, "type", { propertyPath })); return undefined; } const result = Object.create(null); result["type"] = anonymousValidator44( value["type"], `${propertyPath}.type`, errors, ); result["docString"] = anonymousValidator2( value["docString"], `${propertyPath}.docString`, errors, ); result["isOptional"] = anonymousValidator3( value["isOptional"], `${propertyPath}.isOptional`, errors, ); result["defaultValue"] = anonymousValidator4( value["defaultValue"], `${propertyPath}.defaultValue`, errors, ); result["uniqueName"] = anonymousValidator8( value["uniqueName"], `${propertyPath}.uniqueName`, errors, ); result["group"] = anonymousValidator8( value["group"], `${propertyPath}.group`, errors, ); result["name"] = anonymousValidator8( value["name"], `${propertyPath}.name`, errors, ); result["sql"] = anonymousValidator9( value["sql"], `${propertyPath}.sql`, errors, ); result["validator"] = anonymousValidator45( value["validator"], `${propertyPath}.validator`, errors, ); result["oneOf"] = anonymousValidator46( value["oneOf"], `${propertyPath}.oneOf`, errors, ); return result; } /** * @param {*} value * @param {string} propertyPath * @param {*[]} errors * @param {string} parentType * @returns {CodeGenNumberType|undefined} */ export function anonymousValidator42( value, propertyPath, errors = [], parentType = "reference", ) { if (isNil(value)) { errors.push(buildError(parentType, "undefined", { propertyPath })); return undefined; } return anonymousValidator43(value, propertyPath, errors); } /** * @param {*} value * @param {string} propertyPath * @param {*[]} errors * @param {string} parentType * @returns {"object"|undefined} */ export function anonymousValidator49( value, propertyPath, errors = [], parentType = "string", ) { if (isNil(value)) { errors.push(buildError(parentType, "undefined", { propertyPath })); return undefined; } if (typeof value !== "string") { errors.push(buildError(parentType, "type", { propertyPath })); return undefined; } if (value.length < 1) { const min = 1; errors.push(buildError(parentType, "min", { propertyPath, min })); return undefined; } if (value !== "object") { const oneOf = ["object"]; errors.push(buildError(parentType, "oneOf", { propertyPath, oneOf })); return undefined; } return value; } /** * @param {*} value * @param {string} propertyPath * @param {*[]} errors * @param {string} parentType * @returns {boolean|undefined} */ export function anonymousValidator51( value, propertyPath, errors = [], parentType = "boolean", ) { if (isNil(value)) { return true; } if (typeof value !== "boolean") { errors.push(buildError(parentType, "type", { propertyPath })); return undefined; } return value; } /** * @param {*} value * @param {string} propertyPath * @param {*[]} errors * @param {string} parentType * @returns {{"strict": boolean, }|undefined} */ export function anonymousValidator50( value, propertyPath, errors = [], parentType = "object", ) { if (isNil(value)) { errors.push(buildError(parentType, "undefined", { propertyPath })); return undefined; } if (typeof value !== "object") { errors.push(buildError(parentType, "type", { propertyPath })); return undefined; } const result = Object.create(null); result["strict"] = anonymousValidator51( value["strict"], `${propertyPath}.strict`, errors, ); return result; } /** * @param {*} value * @param {string} propertyPath * @param {*[]} errors * @param {string} parentType * @returns {string|undefined} */ export function anonymousValidator53( value, propertyPath, errors = [], parentType = "string", ) { if (isNil(value)) { errors.push(buildError(parentType, "undefined", { propertyPath })); return undefined; } if (typeof value !== "string") { errors.push(buildError(parentType, "type", { propertyPath })); return undefined; } if (value.length < 1) { const min = 1; errors.push(buildError(parentType, "min", { propertyPath, min })); return undefined; } return value; } /** * @param {*} value * @param {string} propertyPath * @param {*[]} errors * @param {string} parentType * @returns {CodeGenType|undefined} */ export function anonymousValidator54( value, propertyPath, errors = [], parentType = "reference", ) { if (isNil(value)) { errors.push(buildError(parentType, "undefined", { propertyPath })); return undefined; } return anonymousValidator13(value, propertyPath, errors); } /** * @param {*} value * @param {string} propertyPath * @param {*[]} errors * @param {string} parentType * @returns {Object<string, CodeGenType>|undefined} */ export function anonymousValidator52( value, propertyPath, errors = [], parentType = "generic", ) { if (isNil(value)) { errors.push(buildError(parentType, "undefined", { propertyPath })); return undefined; } if (typeof value !== "object") { errors.push(buildError(parentType, "type", { propertyPath })); return undefined; } const result = Object.create(null); for (const key of Object.keys(value)) { const genericKey = anonymousValidator53( key, `${propertyPath}.$key[${key}]`, errors, ); if (genericKey !== undefined) { result[genericKey] = anonymousValidator54( value[key], `${propertyPath}.$value[${key}]`, errors, ); } } return result; } /** * @param {*} value * @param {string} propertyPath * @param {*[]} errors * @param {string} parentType * @returns {undefined|{"withSoftDeletes": boolean, "withDates": boolean, "withPrimaryKey": boolean, "isView": boolean, }|undefined} */ export function anonymousValidator55( value, propertyPath, errors = [], parentType = "object", ) { if (isNil(value)) { return value; } if (typeof value !== "object") { errors.push(buildError(parentType, "type", { propertyPath })); return undefined; } const result = Object.create(null); result["withSoftDeletes"] = anonymousValidator3( value["withSoftDeletes"], `${propertyPath}.withSoftDeletes`, errors, ); result["withDates"] = anonymousValidator3( value["withDates"], `${propertyPath}.withDates`, errors, ); result["withPrimaryKey"] = anonymousValidator51( value["withPrimaryKey"], `${propertyPath}.withPrimaryKey`, errors, ); result["isView"] = anonymousValidator3( value["isView"], `${propertyPath}.isView`, errors, ); return result; } /** * @param {*} value * @param {string} propertyPath * @param {*[]} errors * @param {string} parentType * @returns {"relation"|undefined} */ export function anonymousValidator59( value, propertyPath, errors = [], parentType = "string", ) { if (isNil(value)) { errors.push(buildError(parentType, "undefined", { propertyPath })); return undefined; } if (typeof value !== "string") { errors.push(buildError(parentType, "type", { propertyPath })); return undefined; } if (value.length < 1) { const min = 1; errors.push(buildError(parentType, "min", { propertyPath, min })); return undefined; } if (value !== "relation") { const oneOf = ["relation"]; errors.push(buildError(parentType, "oneOf", { propertyPath, oneOf })); return undefined; } return value; } /** * @param {*} value * @param {string} propertyPath * @param {*[]} errors * @param {string} parentType * @returns {"manyToOne"|"oneToMany"|"oneToOne"|"oneToOneReverse"|undefined} */ export function anonymousValidator60( value, propertyPath, errors = [], parentType = "string", ) { if (isNil(value)) { errors.push(buildError(parentType, "undefined", { propertyPath })); return undefined; } if (typeof value !== "string") { errors.push(buildError(parentType, "type", { propertyPath })); return undefined; } if (value.length < 1) { const min = 1; errors.push(buildError(parentType, "min", { propertyPath, min })); return undefined; } if ( value !== "manyToOne" && value !== "oneToMany" && value !== "oneToOne" && value !== "oneToOneReverse" ) { const oneOf = ["manyToOne", "oneToMany", "oneToOne", "oneToOneReverse"]; errors.push(buildError(parentType, "oneOf", { propertyPath, oneOf })); return undefined; } return value; } /** * @param {*} value * @param {string} propertyPath * @param {*[]} errors * @param {string} parentType * @returns {"reference"|undefined} */ export function anonymousValidator63( value, propertyPath, errors = [], parentType = "string", ) { if (isNil(value)) { errors.push(buildError(parentType, "undefined", { propertyPath })); return undefined; } if (typeof value !== "string") { errors.push(buildError(parentType, "type", { propertyPath })); return undefined; } if (value.length < 1) { const min = 1; errors.push(buildError(parentType, "min", { propertyPath, min })); return undefined; } if (value !== "reference") { const oneOf = ["reference"]; errors.push(buildError(parentType, "oneOf", { propertyPath, oneOf })); return undefined; } return value; } /** * @param {*} value * @param {string} propertyPath * @param {*[]} errors * @param {string} parentType * @returns {CodeGenType|undefined} */ export function anonymousValidator65( value, propertyPath, errors = [], parentType = "reference", ) { if (isNil(value)) { errors.push(buildError(parentType, "undefined", { propertyPath })); return undefined; } return anonymousValidator13(value, propertyPath, errors); } /** * @param {*} value * @param {string} propertyPath * @param {*[]} errors * @param {string} parentType * @returns {{"uniqueName"?: string, "group"?: string, "name"?: string, }|undefined} */ export function anonymousValidator66( value, propertyPath, errors = [], parentType = "object", ) { if (isNil(value)) { errors.push(buildError(parentType, "undefined", { propertyPath })); return undefined; } if (typeof value !== "object") { errors.push(buildError(parentType, "type", { propertyPath })); return undefined; } const result = Object.create(null); const keySet = new Set(Object.keys(value)); result["uniqueName"] = anonymousValidator8( value["uniqueName"], `${propertyPath}.uniqueName`, errors, ); keySet.delete("uniqueName"); result["group"] = anonymousValidator8( value["group"], `${propertyPath}.group`, errors, ); keySet.delete("group"); result["name"] = anonymousValidator8( value["name"], `${propertyPath}.name`, errors, ); keySet.delete("name"); if (keySet.size !== 0) { const extraKeys = [...keySet]; errors.push(buildError(parentType, "strict", { propertyPath, extraKeys })); return undefined; } return result; } /** * @param {*} value * @param {string} propertyPath * @param {*[]} errors * @param {string} parentType * @returns {CodeGenType|{"uniqueName"?: string, "group"?: string, "name"?: string, }|undefined} */ export function anonymousValidator64( value, propertyPath, errors = [], parentType = "anyOf", ) { if (isNil(value)) { errors.push(buildError(parentType, "undefined", { propertyPath })); return undefined; } let errorCount = 0; const subErrors = []; let result = undefined; result = anonymousValidator65(value, propertyPath, subErrors); if (subErrors.length === errorCount) { return result; } subErrors.splice(errorCount + 1, subErrors.length - errorCount); errorCount = subErrors.length; result = anonymousValidator66(value, propertyPath, subErrors); if (subErrors.length === errorCount) { return result; } subErrors.splice(errorCount + 1, subErrors.length - errorCount); errorCount = subErrors.length; errors.push( buildError(parentType, "type", { propertyPath, errors: subErrors }), ); return undefined; } /** * @param {*} value * @param {string} propertyPath * @param {*[]} errors * @param {string} parentType * @returns {{"type": "reference", "docString": string, "isOptional": boolean, "defaultValue"?: string|boolean|number, "uniqueName"?: string, "group"?: string, "name"?: string, "sql"?: {"primary": boolean, "searchable": boolean, }, "validator": {}, "reference": CodeGenType|{"uniqueName"?: string, "group"?: string, "name"?: string, }, }|undefined} */ export function anonymousValidator62( value, propertyPath, errors = [], parentType = "object", ) { if (isNil(value)) { errors.push(buildError(parentType, "undefined", { propertyPath })); return undefined; } if (typeof value !== "object") { errors.push(buildError(parentType, "type", { propertyPath })); return undefined; } const result = Object.create(null); result["type"] = anonymousValidator63( value["type"], `${propertyPath}.type`, errors, ); result["docString"] = anonymousValidator2( value["docString"], `${propertyPath}.docString`, errors, ); result["isOptional"] = anonymousValidator3( value["isOptional"], `${propertyPath}.isOptional`, errors, ); result["defaultValue"] = anonymousValidator4( value["defaultValue"],