core-types-suretype
Advanced tools
Comparing version
@@ -7,5 +7,5 @@ export interface CaughtErrorSuccess<T> { | ||
result: undefined; | ||
error: Error; | ||
error: any; | ||
} | ||
export declare type CaughtError<T> = CaughtErrorSuccess<T> | CaughtErrorFailed; | ||
export declare function catchError<R>(fn: () => PromiseLike<R>): Promise<CaughtError<R>>; |
@@ -7,5 +7,5 @@ "use strict"; | ||
function convertCoreTypesToSureType(doc, options) { | ||
const resJsonSchema = core_types_json_schema_1.convertCoreTypesToJsonSchema(doc, options); | ||
const resJsonSchema = (0, core_types_json_schema_1.convertCoreTypesToJsonSchema)(doc, options); | ||
const { data: jsonSchema } = resJsonSchema; | ||
const resSureType = json_schema_to_suretype_1.convertJsonSchemaToSureType(jsonSchema, options); | ||
const resSureType = (0, json_schema_to_suretype_1.convertJsonSchemaToSureType)(jsonSchema, options); | ||
return { | ||
@@ -12,0 +12,0 @@ convertedTypes: resSureType.convertedTypes, |
@@ -29,8 +29,8 @@ "use strict"; | ||
const { title, comment, default: _default, description: _description, } = annotations; | ||
const see = core_types_1.ensureArray(annotations.see); | ||
const examples = core_types_1.ensureArray(annotations.examples); | ||
const see = (0, core_types_1.ensureArray)(annotations.see); | ||
const examples = (0, core_types_1.ensureArray)(annotations.examples); | ||
const descriptions = [ | ||
...(_description ? [_description] : []), | ||
...(see.length ? [core_types_1.formatSee(see)] : []), | ||
...(_default ? [core_types_1.formatDefault(_default)] : []), | ||
...(see.length ? [(0, core_types_1.formatSee)(see)] : []), | ||
...(_default ? [(0, core_types_1.formatDefault)(_default)] : []), | ||
]; | ||
@@ -37,0 +37,0 @@ const description = descriptions.length |
@@ -7,3 +7,3 @@ "use strict"; | ||
function analyzeSchema(schema) { | ||
const { graph, cyclic, dependencies, dependents } = json_schema_cycles_1.analyzeTypesFast(schema); | ||
const { graph, cyclic, dependencies, dependents } = (0, json_schema_cycles_1.analyzeTypesFast)(schema); | ||
const cycledSchemas = new Set([...cyclic, ...dependencies, ...dependents]); | ||
@@ -10,0 +10,0 @@ const nonCyclic = graph |
@@ -20,4 +20,4 @@ "use strict"; | ||
const parsed = typeof jsonSchema === 'string' | ||
? jsonpos_1.getAstByString(jsonSchema) | ||
: jsonpos_1.getAstByObject(jsonSchema); | ||
? (0, jsonpos_1.getAstByString)(jsonSchema) | ||
: (0, jsonpos_1.getAstByObject)(jsonSchema); | ||
const { json, jsonString } = parsed; | ||
@@ -27,3 +27,3 @@ const { definitions } = json; | ||
throw new core_types_1.UnsupportedError("JSON Schema must contain definitions"); | ||
const { cyclic, nonCyclic } = json_schema_analysis_1.analyzeSchema(json); | ||
const { cyclic, nonCyclic } = (0, json_schema_analysis_1.analyzeSchema)(json); | ||
const { warn = defaultWarn, sourceFilename, useUnknown = true, forwardSchema = false, inlineTypes: _inlineTypes = true, exportType = true, exportSchema = true, exportValidator = true, exportEnsurer = true, exportTypeGuard = true, unsupported = 'warn', missingReference = 'warn', } = opts; | ||
@@ -68,4 +68,4 @@ const inlineTypes = forwardSchema || _inlineTypes; | ||
}); | ||
const jsonSchemaAsCoreTypes = core_types_json_schema_1.convertJsonSchemaToCoreTypes(json); | ||
const coreTypes = core_types_1.simplify(jsonSchemaAsCoreTypes.data); | ||
const jsonSchemaAsCoreTypes = (0, core_types_json_schema_1.convertJsonSchemaToCoreTypes)(json); | ||
const coreTypes = (0, core_types_1.simplify)(jsonSchemaAsCoreTypes.data); | ||
Object.keys(definitions) | ||
@@ -84,3 +84,3 @@ .filter(key => { | ||
const jsonSchemaChunk = (!isAnyCyclic && !forwardSchema) ? [] : [ | ||
core_types_ts_1.helpers.wrapAnnotations(helpers_1.createVariable(schemaObjectVariableName, helpers_1.translateValue({ | ||
core_types_ts_1.helpers.wrapAnnotations((0, helpers_1.createVariable)(schemaObjectVariableName, (0, helpers_1.translateValue)({ | ||
definitions: Object.fromEntries(rawSchemas.map(key => [ | ||
@@ -115,3 +115,3 @@ key, | ||
const exports = []; | ||
const { validatorSchemaName, regularValidatorName, ensureValidatorName, typeGuardValidatorName, } = utils_1.getNames(name); | ||
const { validatorSchemaName, regularValidatorName, ensureValidatorName, typeGuardValidatorName, } = (0, utils_1.getNames)(name); | ||
const typeName = name; | ||
@@ -175,7 +175,7 @@ exports.push((forwardSchema || isCyclic) | ||
throw new core_types_1.MissingReferenceError(name, ctx.meta()); | ||
return core_types_ts_1.convertSingleCoreTypeToTypeScriptAst(coreType, { declaration: false, useUnknown }); | ||
return (0, core_types_ts_1.convertSingleCoreTypeToTypeScriptAst)(coreType, { declaration: false, useUnknown }); | ||
} | ||
function createTypeNameFromSchema(export_, typeName, schemaName) { | ||
return helpers_1.factory.createTypeAliasDeclaration(undefined, // decorators | ||
export_ ? helpers_1.createExportModifier() : undefined, // modifiers | ||
export_ ? (0, helpers_1.createExportModifier)() : undefined, // modifiers | ||
helpers_1.t.ident(typeName), undefined, // type parameters | ||
@@ -188,3 +188,3 @@ helpers_1.factory.createTypeReferenceNode("TypeOf", // type name | ||
function createRegularValidator(typeName, validatorSchemaName, exportedName) { | ||
const exportNode = helpers_1.createVariable(exportedName, helpers_1.factory.createCallExpression(helpers_1.t.ident("compile"), undefined, // type arguments | ||
const exportNode = (0, helpers_1.createVariable)(exportedName, helpers_1.factory.createCallExpression(helpers_1.t.ident("compile"), undefined, // type arguments | ||
[helpers_1.t.ident(validatorSchemaName)]), { export: true }); | ||
@@ -197,3 +197,3 @@ return core_types_ts_1.helpers.wrapAnnotations(exportNode, { | ||
function createEnsureValidator(typeName, validatorSchemaName, exportedName) { | ||
const exportNode = helpers_1.factory.createVariableStatement(helpers_1.createExportModifier(), // modifiers | ||
const exportNode = helpers_1.factory.createVariableStatement((0, helpers_1.createExportModifier)(), // modifiers | ||
helpers_1.factory.createVariableDeclarationList([ | ||
@@ -224,3 +224,3 @@ helpers_1.factory.createVariableDeclaration(exportedName, undefined, // exclamation token | ||
function createTypeGuardValidator(typeName, validatorSchemaName, exportedName) { | ||
const exportNode = helpers_1.factory.createVariableStatement(helpers_1.createExportModifier(), // modifiers | ||
const exportNode = helpers_1.factory.createVariableStatement((0, helpers_1.createExportModifier)(), // modifiers | ||
helpers_1.factory.createVariableDeclarationList([ | ||
@@ -243,6 +243,6 @@ helpers_1.factory.createVariableDeclaration(exportedName, undefined, // exclamation token | ||
function createRawValidatorSchema(_ctx, exportSchema, typeName, validatorSchemaName) { | ||
const exportNode = helpers_1.factory.createVariableStatement(exportSchema ? helpers_1.createExportModifier() : undefined, helpers_1.factory.createVariableDeclarationList([ | ||
const exportNode = helpers_1.factory.createVariableStatement(exportSchema ? (0, helpers_1.createExportModifier)() : undefined, helpers_1.factory.createVariableDeclarationList([ | ||
helpers_1.factory.createVariableDeclaration(validatorSchemaName, undefined, // exclamation token | ||
undefined, // type node | ||
helpers_1.createCall('raw', [ | ||
(0, helpers_1.createCall)('raw', [ | ||
helpers_1.t.ident(schemaObjectVariableName), | ||
@@ -259,3 +259,3 @@ helpers_1.t.string(typeName) | ||
function createValidatorSchema(ctx, exportSchema, typeName, validatorSchemaName, schemaObject) { | ||
const exportNode = helpers_1.factory.createVariableStatement(exportSchema ? helpers_1.createExportModifier() : undefined, helpers_1.factory.createVariableDeclarationList([ | ||
const exportNode = helpers_1.factory.createVariableStatement(exportSchema ? (0, helpers_1.createExportModifier)() : undefined, helpers_1.factory.createVariableDeclarationList([ | ||
helpers_1.factory.createVariableDeclaration(validatorSchemaName, undefined, // exclamation token | ||
@@ -277,7 +277,7 @@ undefined, // type node | ||
const annotations = extractAnnotations(def); | ||
const suretypeAnnotations = helpers_1.annotationsToSuretype(annotations, topLevelName); | ||
const suretypeAnnotations = (0, helpers_1.annotationsToSuretype)(annotations, topLevelName); | ||
const annotationsArgs = suretypeAnnotations ? [suretypeAnnotations] : []; | ||
const callAnnotate = (expr) => { | ||
ctx.set('use-annotate'); | ||
return helpers_1.createCall('annotate', [...annotationsArgs, expr]); | ||
return (0, helpers_1.createCall)('annotate', [...annotationsArgs, expr]); | ||
}; | ||
@@ -289,7 +289,7 @@ const wrapDecorations = (expr) => !includeAnnotations | ||
: topLevelName | ||
? helpers_1.createCall('suretype', [...annotationsArgs, expr]) | ||
? (0, helpers_1.createCall)('suretype', [...annotationsArgs, expr]) | ||
: callAnnotate(expr); | ||
const wrapAnnotations = (expr) => wrapDecorations(expr); | ||
const wrapRequired = (expr) => required | ||
? helpers_1.createChainedCall(expr, 'required') | ||
? (0, helpers_1.createChainedCall)(expr, 'required') | ||
: expr; | ||
@@ -305,15 +305,15 @@ const wrap = (expr) => wrapAnnotations(wrapRequired(expr)); | ||
// Convert into 'anyOf' | ||
return wrap(helpers_1.createCall("v.anyOf", [ | ||
return wrap((0, helpers_1.createCall)("v.anyOf", [ | ||
helpers_1.factory.createArrayLiteralExpression(def.type.map(type => createValidator(ctx, { ...def, type }, { includeAnnotations: false }))) | ||
])); | ||
if (def.type === 'null') | ||
return wrap(wrapValidatorGenerics(traversal, helpers_1.createCall("v.null"))); | ||
return wrap(wrapValidatorGenerics(traversal, (0, helpers_1.createCall)("v.null"))); | ||
else if (def.type === 'boolean') | ||
return wrap(wrapBoolean(traversal, helpers_1.createCall("v.boolean"))); | ||
return wrap(wrapBoolean(traversal, (0, helpers_1.createCall)("v.boolean"))); | ||
else if (def.type === 'integer') | ||
return wrap(wrapNumber(traversal, helpers_1.createChainedCall(helpers_1.createCall("v.number"), 'integer'))); | ||
return wrap(wrapNumber(traversal, (0, helpers_1.createChainedCall)((0, helpers_1.createCall)("v.number"), 'integer'))); | ||
else if (def.type === 'number') | ||
return wrap(wrapNumber(traversal, helpers_1.createCall("v.number"))); | ||
return wrap(wrapNumber(traversal, (0, helpers_1.createCall)("v.number"))); | ||
else if (def.type === 'string') | ||
return wrap(wrapString(traversal, helpers_1.createCall("v.string"))); | ||
return wrap(wrapString(traversal, (0, helpers_1.createCall)("v.string"))); | ||
else if (def.type === 'array') | ||
@@ -324,7 +324,7 @@ return wrap(wrapArray(traversal)); | ||
if (Array.isArray(def.anyOf)) | ||
return wrap(wrapValidatorGenerics(traversal, helpers_1.createCall("v.anyOf", [ | ||
return wrap(wrapValidatorGenerics(traversal, (0, helpers_1.createCall)("v.anyOf", [ | ||
helpers_1.factory.createArrayLiteralExpression(def.anyOf.map(type => createValidator(ctx, type))) | ||
]), { noAnyOf: true })); | ||
if (Array.isArray(def.allOf)) | ||
return wrap(wrapValidatorGenerics(traversal, helpers_1.createCall("v.allOf", [ | ||
return wrap(wrapValidatorGenerics(traversal, (0, helpers_1.createCall)("v.allOf", [ | ||
helpers_1.factory.createArrayLiteralExpression(def.allOf.map(type => createValidator(ctx, type))) | ||
@@ -335,3 +335,3 @@ ]), { noAllOf: true })); | ||
function createAnyCall(ctx) { | ||
return helpers_1.createCall(ctx.useUnknown ? 'v.unknown' : 'v.any'); | ||
return (0, helpers_1.createCall)(ctx.useUnknown ? 'v.unknown' : 'v.any'); | ||
} | ||
@@ -355,12 +355,12 @@ function createValidators(ctx, defs, parentType) { | ||
if (required) | ||
expr = helpers_1.createChainedCall(expr, 'required'); | ||
expr = (0, helpers_1.createChainedCall)(expr, 'required'); | ||
if (def.const !== undefined) | ||
expr = helpers_1.createChainedCall(expr, 'const', [helpers_1.translateValue(def.const)]); | ||
expr = (0, helpers_1.createChainedCall)(expr, 'const', [(0, helpers_1.translateValue)(def.const)]); | ||
if (Array.isArray(def.enum)) | ||
expr = helpers_1.createChainedCall(expr, 'enum', helpers_1.translateValues(def.enum)); | ||
expr = (0, helpers_1.createChainedCall)(expr, 'enum', (0, helpers_1.translateValues)(def.enum)); | ||
if (def.default !== undefined) | ||
expr = helpers_1.createChainedCall(expr, 'default', [helpers_1.translateValue(def.default)]); | ||
expr = (0, helpers_1.createChainedCall)(expr, 'default', [(0, helpers_1.translateValue)(def.default)]); | ||
if (!noAnyOf && Array.isArray(def.anyOf)) { | ||
const subCtx = ctx.walk('anyOf'); | ||
expr = helpers_1.createChainedCall(expr, 'anyOf', [ | ||
expr = (0, helpers_1.createChainedCall)(expr, 'anyOf', [ | ||
helpers_1.factory.createArrayLiteralExpression(createValidators(subCtx, def.anyOf, def.type)) | ||
@@ -371,3 +371,3 @@ ]); | ||
const subCtx = ctx.walk('allOf'); | ||
expr = helpers_1.createChainedCall(expr, 'allOf', [ | ||
expr = (0, helpers_1.createChainedCall)(expr, 'allOf', [ | ||
helpers_1.factory.createArrayLiteralExpression(createValidators(subCtx, def.allOf, def.type)) | ||
@@ -379,5 +379,5 @@ ]); | ||
function wrapRef(ctx, name) { | ||
const decoded = openapi_json_schema_1.decodeRefNameJsonSchema(name); | ||
const decoded = (0, openapi_json_schema_1.decodeRefNameJsonSchema)(name); | ||
if (decoded === ctx.topLevelType) | ||
return helpers_1.createCall('v.recursive'); | ||
return (0, helpers_1.createCall)('v.recursive'); | ||
if (decoded.match(/[#/ ]/)) { | ||
@@ -387,3 +387,3 @@ ctx.handleUnsupported(`Unsupported reference type: ${name}`); | ||
} | ||
return helpers_1.t.ident(utils_1.getNames(decoded).validatorSchemaName); | ||
return helpers_1.t.ident((0, utils_1.getNames)(decoded).validatorSchemaName); | ||
} | ||
@@ -396,15 +396,15 @@ function wrapBoolean(traversal, expr) { | ||
const wrapMultipleOf = (expr) => typeof def.multipleOf === 'number' | ||
? helpers_1.createChainedCall(expr, 'multipleOf', [helpers_1.translateValue(def.multipleOf)]) | ||
? (0, helpers_1.createChainedCall)(expr, 'multipleOf', [(0, helpers_1.translateValue)(def.multipleOf)]) | ||
: expr; | ||
const wrapMinimum = (expr) => typeof def.minimum === 'number' | ||
? helpers_1.createChainedCall(expr, 'gte', [helpers_1.translateValue(def.minimum)]) | ||
? (0, helpers_1.createChainedCall)(expr, 'gte', [(0, helpers_1.translateValue)(def.minimum)]) | ||
: expr; | ||
const wrapExclusiveMinimum = (expr) => typeof def.exclusiveMinimum === 'number' | ||
? helpers_1.createChainedCall(expr, 'gt', [helpers_1.translateValue(def.exclusiveMinimum)]) | ||
? (0, helpers_1.createChainedCall)(expr, 'gt', [(0, helpers_1.translateValue)(def.exclusiveMinimum)]) | ||
: expr; | ||
const wrapMaximum = (expr) => typeof def.maximum === 'number' | ||
? helpers_1.createChainedCall(expr, 'lt', [helpers_1.translateValue(def.maximum)]) | ||
? (0, helpers_1.createChainedCall)(expr, 'lt', [(0, helpers_1.translateValue)(def.maximum)]) | ||
: expr; | ||
const wrapExclusiveMaximum = (expr) => typeof def.exclusiveMaximum === 'number' | ||
? helpers_1.createChainedCall(expr, 'lte', [helpers_1.translateValue(def.exclusiveMaximum)]) | ||
? (0, helpers_1.createChainedCall)(expr, 'lte', [(0, helpers_1.translateValue)(def.exclusiveMaximum)]) | ||
: expr; | ||
@@ -416,12 +416,12 @@ return wrapValidatorGenerics(traversal, wrapMaximum(wrapExclusiveMaximum(wrapMinimum(wrapExclusiveMinimum(wrapMultipleOf(expr)))))); | ||
const wrapMinLength = (expr) => typeof def.minLength === 'number' | ||
? helpers_1.createChainedCall(expr, 'minLength', [helpers_1.translateValue(def.minLength)]) | ||
? (0, helpers_1.createChainedCall)(expr, 'minLength', [(0, helpers_1.translateValue)(def.minLength)]) | ||
: expr; | ||
const wrapMaxLength = (expr) => typeof def.maxLength === 'number' | ||
? helpers_1.createChainedCall(expr, 'maxLength', [helpers_1.translateValue(def.maxLength)]) | ||
? (0, helpers_1.createChainedCall)(expr, 'maxLength', [(0, helpers_1.translateValue)(def.maxLength)]) | ||
: expr; | ||
const wrapPattern = (expr) => typeof def.pattern === 'string' | ||
? helpers_1.createChainedCall(expr, 'pattern', [helpers_1.translateValue(def.pattern)]) | ||
? (0, helpers_1.createChainedCall)(expr, 'pattern', [(0, helpers_1.translateValue)(def.pattern)]) | ||
: expr; | ||
const wrapFormat = (expr) => typeof def.format === 'string' | ||
? helpers_1.createChainedCall(expr, 'format', [helpers_1.translateValue(def.format)]) | ||
? (0, helpers_1.createChainedCall)(expr, 'format', [(0, helpers_1.translateValue)(def.format)]) | ||
: expr; | ||
@@ -451,6 +451,6 @@ return wrapValidatorGenerics(traversal, wrapFormat(wrapPattern(wrapMaxLength(wrapMinLength(expr))))); | ||
? expr | ||
: helpers_1.createChainedCall(expr, 'minItems', [helpers_1.translateValue(def.minItems)]); | ||
: (0, helpers_1.createChainedCall)(expr, 'minItems', [(0, helpers_1.translateValue)(def.minItems)]); | ||
const wrapMaxItems = (expr) => def.maxItems === undefined | ||
? expr | ||
: helpers_1.createChainedCall(expr, 'maxItems', [helpers_1.translateValue(def.maxItems)]); | ||
: (0, helpers_1.createChainedCall)(expr, 'maxItems', [(0, helpers_1.translateValue)(def.maxItems)]); | ||
const wrapAdditionalItems = (expr) => !isTuple | ||
@@ -461,5 +461,5 @@ ? expr // Ignored for arrays, only applicable for tuples | ||
: additionalItems === false | ||
? helpers_1.createChainedCall(expr, 'additional', [helpers_1.t.false()]) | ||
: helpers_1.createChainedCall(expr, 'additional', [createValidator(ctx, additionalItems)]); | ||
return wrapValidatorGenerics(traversal, wrapAdditionalItems(wrapMaxItems(wrapMinItems(helpers_1.createCall("v.array", itemsArgs))))); | ||
? (0, helpers_1.createChainedCall)(expr, 'additional', [helpers_1.t.false()]) | ||
: (0, helpers_1.createChainedCall)(expr, 'additional', [createValidator(ctx, additionalItems)]); | ||
return wrapValidatorGenerics(traversal, wrapAdditionalItems(wrapMaxItems(wrapMinItems((0, helpers_1.createCall)("v.array", itemsArgs))))); | ||
} | ||
@@ -472,3 +472,3 @@ function wrapObject(traversal) { | ||
.map(prop => helpers_1.factory.createPropertyAssignment(prop, createValidator(traversal.ctx.walk('properties', prop), def.properties[prop], { required: required.includes(prop) }))), true) | ||
: helpers_1.translateValue({}); | ||
: (0, helpers_1.translateValue)({}); | ||
const additionalProperties = def.additionalProperties === undefined | ||
@@ -482,6 +482,6 @@ ? true | ||
const wrapAdditionalProperties = (expr) => additionalProperties === true | ||
? helpers_1.createChainedCall(expr, 'additional', [helpers_1.t.true()]) | ||
? (0, helpers_1.createChainedCall)(expr, 'additional', [helpers_1.t.true()]) | ||
: additionalProperties === false | ||
? expr | ||
: helpers_1.createChainedCall(expr, 'additional', [ | ||
: (0, helpers_1.createChainedCall)(expr, 'additional', [ | ||
createValidator(ctx.walk('additionalProperties'), additionalProperties) | ||
@@ -499,3 +499,3 @@ ]); | ||
ctx.handleUnsupported("Property 'dependencies' not supported"); | ||
return wrapValidatorGenerics(traversal, wrapAdditionalProperties(helpers_1.createCall("v.object", [properties]))); | ||
return wrapValidatorGenerics(traversal, wrapAdditionalProperties((0, helpers_1.createCall)("v.object", [properties]))); | ||
} |
@@ -6,3 +6,3 @@ "use strict"; | ||
const { file, refMethod, onTopLevelNameConflict } = worker_threads_1.workerData; | ||
const response = read_exports_file_1.readExportedSchemas(file, refMethod, onTopLevelNameConflict); | ||
const response = (0, read_exports_file_1.readExportedSchemas)(file, refMethod, onTopLevelNameConflict); | ||
worker_threads_1.parentPort.postMessage(response); |
@@ -15,3 +15,3 @@ "use strict"; | ||
ok: false, | ||
error: types_1.serializeError(err), | ||
error: (0, types_1.serializeError)(err), | ||
}; | ||
@@ -41,8 +41,8 @@ } | ||
const schemas = ret | ||
.map(({ value, name }) => ({ name, schema: suretype_1.getValidatorSchema(value) })) | ||
.map(({ value, name }) => ({ name, schema: (0, suretype_1.getValidatorSchema)(value) })) | ||
.map(({ name, schema }) => name && schema | ||
? suretype_1.ensureNamed(name, schema) | ||
? (0, suretype_1.ensureNamed)(name, schema) | ||
: schema) | ||
.filter((value) => !!value); | ||
const { schema: jsonSchema } = suretype_1.extractJsonSchema(schemas, { | ||
const { schema: jsonSchema } = (0, suretype_1.extractJsonSchema)(schemas, { | ||
onNonSuretypeValidator: 'ignore', | ||
@@ -49,0 +49,0 @@ onTopLevelNameConflict, |
@@ -20,3 +20,3 @@ "use strict"; | ||
ok: false, | ||
error: types_1.serializeError(err), | ||
error: (0, types_1.serializeError)(err), | ||
}); | ||
@@ -23,0 +23,0 @@ }); |
@@ -7,5 +7,5 @@ "use strict"; | ||
async function convertSureTypeToCoreTypes(filename, options = {}) { | ||
const resSchema = await suretype_to_json_schema_1.convertSuretypeToJsonSchema(filename, options); | ||
const resSchema = await (0, suretype_to_json_schema_1.convertSuretypeToJsonSchema)(filename, options); | ||
const { data: jsonSchema } = resSchema; | ||
const resCoreTypes = core_types_json_schema_1.convertJsonSchemaToCoreTypes(jsonSchema); | ||
const resCoreTypes = (0, core_types_json_schema_1.convertJsonSchemaToCoreTypes)(jsonSchema); | ||
return { | ||
@@ -12,0 +12,0 @@ convertedTypes: resCoreTypes.convertedTypes, |
@@ -9,6 +9,7 @@ "use strict"; | ||
async function convertSuretypeToJsonSchema(filename, options = {}) { | ||
var _a; | ||
const { warn = console.warn.bind(console), refMethod = 'provided', nameConflict = 'error', } = options !== null && options !== void 0 ? options : {}; | ||
const { result, error } = await async_error_1.catchError(() => read_exports_1.extractJsonSchema(filename, refMethod, nameConflict === 'rename' ? 'rename' : 'error')); | ||
const { result, error } = await (0, async_error_1.catchError)(() => (0, read_exports_1.extractJsonSchema)(filename, refMethod, nameConflict === 'rename' ? 'rename' : 'error')); | ||
if (error) { | ||
if (error.name.startsWith('Duplicate') && nameConflict === 'warn') | ||
if (((_a = error.name) === null || _a === void 0 ? void 0 : _a.startsWith('Duplicate')) && nameConflict === 'warn') | ||
warn(error.message, error); | ||
@@ -20,3 +21,3 @@ else | ||
return { data: {}, convertedTypes: [], notConvertedTypes: [] }; | ||
core_types_json_schema_1.decorateSchema(result.jsonSchema, { sourceFilename: path.basename(filename), ...options }, 'core-types-suretype', 'https://github.com/grantila/core-types-suretype'); | ||
(0, core_types_json_schema_1.decorateSchema)(result.jsonSchema, { sourceFilename: path.basename(filename), ...options }, 'core-types-suretype', 'https://github.com/grantila/core-types-suretype'); | ||
return { | ||
@@ -23,0 +24,0 @@ data: result.jsonSchema, |
{ | ||
"name": "core-types-suretype", | ||
"version": "1.1.2", | ||
"version": "1.2.0", | ||
"description": "core-types ⬌ SureType validator conversion", | ||
@@ -41,21 +41,21 @@ "author": "Gustaf Räntilä", | ||
"dependencies": { | ||
"@types/json-schema": "^7.0.7", | ||
"core-types": "^1.8.1", | ||
"@types/json-schema": "^7.0.9", | ||
"core-types": "^1.8.2", | ||
"core-types-json-schema": "^1.5.0", | ||
"core-types-ts": "^1.2.2", | ||
"core-types-ts": "^1.3.0", | ||
"json-schema-cycles": "^1.1.0", | ||
"jsonpos": "^1.1.0", | ||
"openapi-json-schema": "^1.1.1", | ||
"suretype": "^2.3.0", | ||
"openapi-json-schema": "^1.1.2", | ||
"suretype": "^2.4.1", | ||
"toposort": "^2.0.2", | ||
"typescript": "^4.2.3" | ||
"typescript": "^4.4.3" | ||
}, | ||
"devDependencies": { | ||
"@types/jest": "^26.0.22", | ||
"@types/jest": "^27.0.1", | ||
"@types/toposort": "^2.0.3", | ||
"cz-conventional-changelog": "^3.3.0", | ||
"jest": "^26.4.2", | ||
"jest": "^27.1.1", | ||
"rimraf": "^3.0.2", | ||
"ts-jest": "^26.5.5", | ||
"ts-node": "^9.1.1" | ||
"ts-jest": "^27.0.5", | ||
"ts-node": "^10.2.1" | ||
}, | ||
@@ -62,0 +62,0 @@ "config": { |
59783
0.85%1070
0.09%Updated
Updated
Updated
Updated
Updated
Updated