io-ts-from-json-schema
Advanced tools
Comparing version 0.0.10 to 0.0.11
@@ -30,2 +30,13 @@ #!/usr/bin/env node | ||
}; | ||
var __rest = (this && this.__rest) || function (s, e) { | ||
var t = {}; | ||
for (var p in s) if (Object.prototype.hasOwnProperty.call(s, p) && e.indexOf(p) < 0) | ||
t[p] = s[p]; | ||
if (s != null && typeof Object.getOwnPropertySymbols === "function") | ||
for (var i = 0, p = Object.getOwnPropertySymbols(s); i < p.length; i++) { | ||
if (e.indexOf(p[i]) < 0 && Object.prototype.propertyIsEnumerable.call(s, p[i])) | ||
t[p[i]] = s[p[i]]; | ||
} | ||
return t; | ||
}; | ||
var __read = (this && this.__read) || function (o, n) { | ||
@@ -88,4 +99,4 @@ var m = typeof Symbol === "function" && o[Symbol.iterator]; | ||
} | ||
// eslint-disable-next-line | ||
throw new Error("unknown regexp format"); | ||
// eslint-disable-next-line fp/no-throw | ||
throw new Error('unknown regexp format'); | ||
} | ||
@@ -125,3 +136,3 @@ // END: Ajv Schema Helpers | ||
} | ||
// eslint-disable-next-line | ||
// eslint-disable-next-line fp/no-mutation | ||
returnCode = level; | ||
@@ -131,3 +142,2 @@ } | ||
var lines = [level + ": " + message, " in " + args.inputFile]; | ||
// eslint-disable-next-line | ||
stderr.write(lines.join('\n').concat('\n')); | ||
@@ -168,20 +178,19 @@ } | ||
if (parts.length > 2) { | ||
// eslint-disable-next-line | ||
throw new Error("unknown ref format"); | ||
// eslint-disable-next-line fp/no-throw | ||
throw new Error('unknown ref format'); | ||
} | ||
var _b = __read(parts, 2), filePath = _b[0], jsonPath = _b[1]; | ||
// eslint-disable-next-line | ||
var jsonPathParts = jsonPath.split("/"); | ||
var jsonPathParts = jsonPath.split('/'); | ||
if (jsonPathParts.length !== 3) { | ||
// eslint-disable-next-line | ||
throw new Error("unknown ref format"); | ||
// eslint-disable-next-line fp/no-throw | ||
throw new Error('unknown ref format'); | ||
} | ||
var _c = __read(jsonPathParts, 3), empty = _c[0], definitions = _c[1], name = _c[2]; | ||
if (empty !== '') { | ||
// eslint-disable-next-line | ||
throw new Error("unknown ref format"); | ||
// eslint-disable-next-line fp/no-throw | ||
throw new Error('unknown ref format'); | ||
} | ||
if (definitions !== 'definitions') { | ||
// eslint-disable-next-line | ||
throw new Error("unknown ref format"); | ||
// eslint-disable-next-line fp/no-throw | ||
throw new Error('unknown ref format'); | ||
} | ||
@@ -271,3 +280,3 @@ var variableName = typenameFromKebab(name); | ||
} | ||
// eslint-disable-next-line | ||
// eslint-disable-next-line fp/no-throw | ||
throw new Error('tuples with ...rest are not supported, set additionalItems false'); | ||
@@ -336,3 +345,3 @@ } | ||
try { | ||
// eslint-disable-next-line | ||
// eslint-disable-next-line fp/no-loops | ||
for (var imports_1 = __values(imports), imports_1_1 = imports_1.next(); !imports_1_1.done; imports_1_1 = imports_1.next()) { | ||
@@ -355,4 +364,3 @@ var _c = __read(imports_1_1.value, 2), uri = _c[0], location_1 = _c[1]; | ||
function importBaseName(filePath) { | ||
// eslint-disable-next-line | ||
var _a = __read(filePath.split("/").reverse(), 1), withoutPath = _a[0]; | ||
var _a = __read(filePath.split('/').reverse(), 1), withoutPath = _a[0]; | ||
var _b = __read(withoutPath.split('.json'), 1), basefile = _b[0]; | ||
@@ -379,7 +387,21 @@ var typeName = typenameFromKebab(basefile); | ||
} | ||
function fromRef(refString, name) { | ||
// eslint-disable-next-line | ||
function isRefObject(schema) { | ||
if (schema.hasOwnProperty('$ref') === false) { | ||
return false; | ||
} | ||
if (typeof schema['$ref'] === 'string') { | ||
return true; | ||
} | ||
// eslint-disable-next-line fp/no-throw | ||
throw new Error('broken input'); | ||
} | ||
function fromRef(refObject, name) { | ||
var refString = refObject.$ref, _comment = refObject.$comment, extra = __rest(refObject, ["$ref", "$comment"]); | ||
if (Object.keys(extra).length) { | ||
warning("unexpected key in a $ref object"); | ||
} | ||
// eslint-disable-next-line fp/no-let | ||
var ref; | ||
try { | ||
// eslint-disable-next-line | ||
// eslint-disable-next-line fp/no-mutation | ||
ref = parseRef(refString); | ||
@@ -414,3 +436,2 @@ } | ||
var combinators = schema.type.map(function (t) { | ||
// eslint-disable-next-line | ||
switch (t) { | ||
@@ -427,3 +448,3 @@ case 'string': | ||
} | ||
// eslint-disable-next-line | ||
// eslint-disable-next-line fp/no-throw | ||
throw new Error(t + "s are not supported as part of type MULTIPLES"); | ||
@@ -488,3 +509,3 @@ }); | ||
} | ||
// eslint-disable-next-line | ||
// eslint-disable-next-line fp/no-throw | ||
throw new Error(typeof s + "s are not supported as part of ENUM"); | ||
@@ -508,3 +529,3 @@ }); | ||
} | ||
// eslint-disable-next-line | ||
// eslint-disable-next-line fp/no-throw | ||
throw new Error(typeof schema.const + "s are not supported as part of CONST"); | ||
@@ -565,3 +586,3 @@ } | ||
} | ||
// eslint-disable-next-line | ||
// eslint-disable-next-line fp/no-loops | ||
for (var key in schema) { | ||
@@ -575,8 +596,4 @@ if (isSupported(key, isRoot) !== true) { | ||
} | ||
if ('$ref' in schema) { | ||
if (typeof schema['$ref'] === 'undefined') { | ||
// eslint-disable-next-line | ||
throw new Error("broken input"); | ||
} | ||
return fromRef(schema['$ref']); | ||
if (isRefObject(schema)) { | ||
return fromRef(schema); | ||
} | ||
@@ -596,3 +613,3 @@ imps.add("import * as t from 'io-ts';"); | ||
} | ||
// eslint-disable-next-line | ||
// eslint-disable-next-line fp/no-throw | ||
throw new Error("unknown schema: " + JSON.stringify(schema)); | ||
@@ -616,4 +633,4 @@ } | ||
} | ||
// eslint-disable-next-line | ||
throw new Error("Unexpected format of examples"); | ||
// eslint-disable-next-line fp/no-throw | ||
throw new Error('Unexpected format of examples'); | ||
} | ||
@@ -654,10 +671,6 @@ function extractDefaultValue(schema) { | ||
} | ||
if ('$ref' in scem) { | ||
if (isRefObject(scem)) { | ||
// ref's do not have meta data | ||
var title = undefined; | ||
var description = undefined; | ||
if (typeof scem['$ref'] === 'undefined') { | ||
// eslint-disable-next-line | ||
throw new Error("broken input"); | ||
} | ||
return [ | ||
@@ -671,3 +684,3 @@ { | ||
}, | ||
dec: gen.typeDeclaration(name, fromRef(scem['$ref'], name), true), | ||
dec: gen.typeDeclaration(name, fromRef(scem, name), true), | ||
}, | ||
@@ -713,7 +726,3 @@ ]; | ||
var defaultValue = extractDefaultValue(root); | ||
if ('$ref' in root) { | ||
if (typeof root['$ref'] === 'undefined') { | ||
// eslint-disable-next-line | ||
throw new Error("broken input"); | ||
} | ||
if (isRefObject(root)) { | ||
exps.add("export default " + defaultExport + ";"); | ||
@@ -728,3 +737,3 @@ return [ | ||
}, | ||
dec: gen.typeDeclaration(defaultExport, fromRef(root['$ref'], defaultExport), true), | ||
dec: gen.typeDeclaration(defaultExport, fromRef(root, defaultExport), true), | ||
}, | ||
@@ -746,3 +755,3 @@ ]; | ||
}).includes(defaultExport)) { | ||
warning('Naming clash, ignoring default export'); | ||
warning('naming clash, ignoring default export'); | ||
return namedDefs; | ||
@@ -756,3 +765,3 @@ } | ||
defInputs.forEach(function (defInput) { | ||
// eslint-disable-next-line | ||
// eslint-disable-next-line fp/no-mutation | ||
metas[defInput.dec.name] = defInput.meta; | ||
@@ -764,3 +773,2 @@ }); | ||
}); | ||
// eslint-disable-next-line | ||
return gen.sort(decs).map(function (dec) { | ||
@@ -842,5 +850,3 @@ var _a, _b; | ||
documentBase = (function () { | ||
// eslint-disable-next-line | ||
var _a = __read(args.documentURI.split('/').reverse()), reversePath = _a.slice(1); | ||
// eslint-disable-next-line | ||
return reversePath.reverse().join('/'); | ||
@@ -861,7 +867,7 @@ })(); | ||
if (returnCode === ErrorCode.ERROR) { | ||
// eslint-disable-next-line | ||
// eslint-disable-next-line fp/no-throw | ||
throw new Error('Balining because of errors'); | ||
} | ||
if (returnCode === ErrorCode.WARNING && args.strict) { | ||
// eslint-disable-next-line | ||
// eslint-disable-next-line fp/no-throw | ||
throw new Error('Balining because of warnings'); | ||
@@ -868,0 +874,0 @@ } |
{ | ||
"name": "io-ts-from-json-schema", | ||
"version": "0.0.10", | ||
"version": "0.0.11", | ||
"description": "Iotsfjs is a static code generation utility used for converting json schema files into static TypeScript types and io-ts runtime validators.", | ||
@@ -5,0 +5,0 @@ "main": "lib/cli.js", |
Major refactor
Supply chain riskPackage has recently undergone a major refactor. It may be unstable or indicate significant internal changes. Use caution when updating to versions that include significant changes.
Found 1 instance in 1 package
60826
1375
0