UNPKG

adr-cli

Version:

Architecture Decision Records (ADR) command cli

294 lines 10.7 kB
//https://app.quicktype.io/ // To parse this data: // // import { Convert, ILocale } from "./file"; // // const iLocale = Convert.toILocale(json); // // These functions will throw an error if the JSON doesn't // match the expected interface, even if the JSON is valid. // Converts JSON strings to/from your types // and asserts the results of JSON.parse at runtime export class Convert { static toILocale(json) { return cast(JSON.parse(json), r("ILocale")); } static iLocaleToJson(value) { return JSON.stringify(uncast(value, r("ILocale")), null, 2); } } function invalidValue(typ, val, key, parent = '') { const prettyTyp = prettyTypeName(typ); const parentText = parent ? ` on ${parent}` : ''; const keyText = key ? ` for key "${key}"` : ''; throw Error(`Invalid value${keyText}${parentText}. Expected ${prettyTyp} but got ${JSON.stringify(val)}`); } function prettyTypeName(typ) { if (Array.isArray(typ)) { if (typ.length === 2 && typ[0] === undefined) { return `an optional ${prettyTypeName(typ[1])}`; } else { return `one of [${typ.map(a => { return prettyTypeName(a); }).join(", ")}]`; } } else if (typeof typ === "object" && typ.literal !== undefined) { return typ.literal; } else { return typeof typ; } } function jsonToJSProps(typ) { if (typ.jsonToJS === undefined) { const map = {}; typ.props.forEach((p) => map[p.json] = { key: p.js, typ: p.typ }); typ.jsonToJS = map; } return typ.jsonToJS; } function jsToJSONProps(typ) { if (typ.jsToJSON === undefined) { const map = {}; typ.props.forEach((p) => map[p.js] = { key: p.json, typ: p.typ }); typ.jsToJSON = map; } return typ.jsToJSON; } function transform(val, typ, getProps, key = '', parent = '') { function transformPrimitive(typ, val) { if (typeof typ === typeof val) return val; return invalidValue(typ, val, key, parent); } function transformUnion(typs, val) { // val must validate against one typ in typs const l = typs.length; for (let i = 0; i < l; i++) { const typ = typs[i]; try { return transform(val, typ, getProps); } catch (_) { } } return invalidValue(typs, val, key, parent); } function transformEnum(cases, val) { if (cases.indexOf(val) !== -1) return val; return invalidValue(cases.map(a => { return l(a); }), val, key, parent); } function transformArray(typ, val) { // val must be an array with no invalid elements if (!Array.isArray(val)) return invalidValue(l("array"), val, key, parent); return val.map(el => transform(el, typ, getProps)); } function transformDate(val) { if (val === null) { return null; } const d = new Date(val); if (isNaN(d.valueOf())) { return invalidValue(l("Date"), val, key, parent); } return d; } function transformObject(props, additional, val) { if (val === null || typeof val !== "object" || Array.isArray(val)) { return invalidValue(l(ref || "object"), val, key, parent); } const result = {}; Object.getOwnPropertyNames(props).forEach(key => { const prop = props[key]; const v = Object.prototype.hasOwnProperty.call(val, key) ? val[key] : undefined; result[prop.key] = transform(v, prop.typ, getProps, key, ref); }); Object.getOwnPropertyNames(val).forEach(key => { if (!Object.prototype.hasOwnProperty.call(props, key)) { result[key] = transform(val[key], additional, getProps, key, ref); } }); return result; } if (typ === "any") return val; if (typ === null) { if (val === null) return val; return invalidValue(typ, val, key, parent); } if (typ === false) return invalidValue(typ, val, key, parent); let ref = undefined; while (typeof typ === "object" && typ.ref !== undefined) { ref = typ.ref; typ = typeMap[typ.ref]; } if (Array.isArray(typ)) return transformEnum(typ, val); if (typeof typ === "object") { return typ.hasOwnProperty("unionMembers") ? transformUnion(typ.unionMembers, val) : typ.hasOwnProperty("arrayItems") ? transformArray(typ.arrayItems, val) : typ.hasOwnProperty("props") ? transformObject(getProps(typ), typ.additional, val) : invalidValue(typ, val, key, parent); } // Numbers can be parsed by Date but shouldn't be. if (typ === Date && typeof val !== "number") return transformDate(val); return transformPrimitive(typ, val); } function cast(val, typ) { return transform(val, typ, jsonToJSProps); } function uncast(val, typ) { return transform(val, typ, jsToJSONProps); } function l(typ) { return { literal: typ }; } function a(typ) { return { arrayItems: typ }; } function u(...typs) { return { unionMembers: typs }; } function o(props, additional) { return { props, additional }; } function m(additional) { return { props: [], additional }; } function r(name) { return { ref: name }; } const typeMap = { "ILocale": o([ { json: "command", js: "command", typ: r("Command") }, { json: "class", js: "class", typ: r("Class") }, ], false), "Class": o([ { json: "adr", js: "adr", typ: r("Adr") }, ], false), "Adr": o([ { json: "Add", js: "Add", typ: r("Add") }, { json: "Adr", js: "Adr", typ: r("AdrClass") }, ], false), "Add": o([ { json: "checkContextValid", js: "checkContextValid", typ: "" }, ], false), "AdrClass": o([ { json: "validateOrCreateIndex", js: "validateOrCreateIndex", typ: r("ValidateOrCreateIndex") }, { json: "suppressedAdr", js: "suppressedAdr", typ: r("SuppressedAdr") }, ], false), "SuppressedAdr": o([ { json: "okRanameAdrFile", js: "okRanameAdrFile", typ: "" }, ], false), "ValidateOrCreateIndex": o([ { json: "reading", js: "reading", typ: "" }, { json: "generated", js: "generated", typ: "" }, ], false), "Command": o([ { json: "config", js: "config", typ: r("Config") }, { json: "new", js: "new", typ: r("New") }, { json: "index", js: "index", typ: r("Index") }, { json: "show", js: "show", typ: r("Index") }, { json: "status", js: "status", typ: r("Status") }, { json: "init", js: "init", typ: r("Init") }, { json: "rel", js: "rel", typ: r("Rel") }, { json: "suppressed", js: "suppressed", typ: r("Rel") }, ], false), "Config": o([ { json: "program", js: "program", typ: r("ConfigProgram") }, { json: "show", js: "show", typ: r("Show") }, { json: "get", js: "get", typ: r("Get") }, { json: "set", js: "set", typ: r("Set") }, { json: "reset", js: "reset", typ: r("Path") }, { json: "path", js: "path", typ: r("Path") }, ], false), "Get": o([ { json: "argument", js: "argument", typ: "" }, { json: "description", js: "description", typ: "" }, { json: "messages", js: "messages", typ: r("GetMessages") }, ], false), "GetMessages": o([ { json: "propertyNotFound", js: "propertyNotFound", typ: "" }, { json: "propertyNotValid", js: "propertyNotValid", typ: "" }, { json: "propertyName", js: "propertyName", typ: "" }, ], false), "Path": o([ { json: "description", js: "description", typ: "" }, ], false), "ConfigProgram": o([ { json: "descriptions", js: "descriptions", typ: "" }, ], false), "Set": o([ { json: "argument", js: "argument", typ: "" }, { json: "description", js: "description", typ: "" }, { json: "messages", js: "messages", typ: r("SetMessages") }, ], false), "SetMessages": o([ { json: "propertyEntered", js: "propertyEntered", typ: "" }, { json: "propertyChanged", js: "propertyChanged", typ: "" }, { json: "propertyNotFound", js: "propertyNotFound", typ: "" }, ], false), "Show": o([ { json: "description", js: "description", typ: "" }, { json: "table", js: "table", typ: r("Table") }, ], false), "Table": o([ { json: "columnName", js: "columnName", typ: a("") }, { json: "rows", js: "rows", typ: r("Rows") }, ], false), "Rows": o([ { json: "adrPath", js: "adrPath", typ: "" }, { json: "locale", js: "locale", typ: "" }, { json: "markdownEngine", js: "markdownEngine", typ: "" }, ], false), "Index": o([ { json: "program", js: "program", typ: r("ConfigProgram") }, ], false), "Init": o([ { json: "program", js: "program", typ: r("InitProgram") }, ], false), "InitProgram": o([ { json: "description", js: "description", typ: "" }, { json: "messages", js: "messages", typ: r("ProgramMessages") }, ], false), "ProgramMessages": o([ { json: "successfully", js: "successfully", typ: "" }, { json: "wrong", js: "wrong", typ: "" }, ], false), "New": o([ { json: "withAnswers", js: "withAnswers", typ: r("WithAnswers") }, { json: "WithOutAnswers", js: "WithOutAnswers", typ: r("WithOutAnswers") }, { json: "program", js: "program", typ: r("NewProgram") }, ], false), "WithOutAnswers": o([], false), "NewProgram": o([ { json: "descriptions", js: "descriptions", typ: "" }, { json: "arguments", js: "arguments", typ: "" }, ], false), "WithAnswers": o([ { json: "shortTitle", js: "shortTitle", typ: "" }, { json: "contextDescription", js: "contextDescription", typ: "" }, ], false), "Rel": o([ { json: "program", js: "program", typ: r("RelProgram") }, ], false), "RelProgram": o([ { json: "description", js: "description", typ: "" }, { json: "argument", js: "argument", typ: "" }, { json: "option", js: "option", typ: "" }, { json: "argumentError", js: "argumentError", typ: "" }, ], false), "Status": o([ { json: "program", js: "program", typ: r("StatusProgram") }, ], false), "StatusProgram": o([ { json: "descriptions", js: "descriptions", typ: "" }, { json: "argument", js: "argument", typ: "" }, { json: "option", js: "option", typ: "" }, ], false), }; //# sourceMappingURL=ilocale.js.map