Object.defineProperty(exports, "__esModule", { value: true });
const codegen_1 = require("../../compile/codegen");
const error = {
- message: ({ schemaCode }) => codegen_1.str `must match format "${schemaCode}"`,
- params: ({ schemaCode }) => codegen_1._ `{format: ${schemaCode}}`,
+ message: ({ schemaCode }) => (0, codegen_1.str) `must match format "${schemaCode}"`,
+ params: ({ schemaCode }) => (0, codegen_1._) `{format: ${schemaCode}}`,
};
const def = {
keyword: "format",
ref: self.formats,
code: opts.code.formats,
});
- const fDef = gen.const("fDef", codegen_1._ `${fmts}[${schemaCode}]`);
+ const fDef = gen.const("fDef", (0, codegen_1._) `${fmts}[${schemaCode}]`);
const fType = gen.let("fType");
const format = gen.let("format");
// TODO simplify
- gen.if(codegen_1._ `typeof ${fDef} == "object" && !(${fDef} instanceof RegExp)`, () => gen.assign(fType, codegen_1._ `${fDef}.type || "string"`).assign(format, codegen_1._ `${fDef}.validate`), () => gen.assign(fType, codegen_1._ `"string"`).assign(format, fDef));
- cxt.fail$data(codegen_1.or(unknownFmt(), invalidFmt()));
+ gen.if((0, codegen_1._) `typeof ${fDef} == "object" && !(${fDef} instanceof RegExp)`, () => gen.assign(fType, (0, codegen_1._) `${fDef}.type || "string"`).assign(format, (0, codegen_1._) `${fDef}.validate`), () => gen.assign(fType, (0, codegen_1._) `"string"`).assign(format, fDef));
+ cxt.fail$data((0, codegen_1.or)(unknownFmt(), invalidFmt()));
function unknownFmt() {
if (opts.strictSchema === false)
return codegen_1.nil;
- return codegen_1._ `${schemaCode} && !${format}`;
+ return (0, codegen_1._) `${schemaCode} && !${format}`;
}
function invalidFmt() {
const callFormat = schemaEnv.$async
- ? codegen_1._ `(${fDef}.async ? await ${format}(${data}) : ${format}(${data}))`
- : codegen_1._ `${format}(${data})`;
- const validData = codegen_1._ `(typeof ${format} == "function" ? ${callFormat} : ${format}.test(${data}))`;
- return codegen_1._ `${format} && ${format} !== true && ${fType} === ${ruleType} && !${validData}`;
+ ? (0, codegen_1._) `(${fDef}.async ? await ${format}(${data}) : ${format}(${data}))`
+ : (0, codegen_1._) `${format}(${data})`;
+ const validData = (0, codegen_1._) `(typeof ${format} == "function" ? ${callFormat} : ${format}.test(${data}))`;
+ return (0, codegen_1._) `${format} && ${format} !== true && ${fType} === ${ruleType} && !${validData}`;
}
}
function validateFormat() {
}
}
function getFormat(fmtDef) {
- const fmt = gen.scopeValue("formats", {
- key: schema,
- ref: fmtDef,
- code: opts.code.formats ? codegen_1._ `${opts.code.formats}${codegen_1.getProperty(schema)}` : undefined,
- });
+ const code = fmtDef instanceof RegExp
+ ? (0, codegen_1.regexpCode)(fmtDef)
+ : opts.code.formats
+ ? (0, codegen_1._) `${opts.code.formats}${(0, codegen_1.getProperty)(schema)}`
+ : undefined;
+ const fmt = gen.scopeValue("formats", { key: schema, ref: fmtDef, code });
if (typeof fmtDef == "object" && !(fmtDef instanceof RegExp)) {
- return [fmtDef.type || "string", fmtDef.validate, codegen_1._ `${fmt}.validate`];
+ return [fmtDef.type || "string", fmtDef.validate, (0, codegen_1._) `${fmt}.validate`];
}
return ["string", fmtDef, fmt];
}
if (typeof formatDef == "object" && !(formatDef instanceof RegExp) && formatDef.async) {
if (!schemaEnv.$async)
throw new Error("async format in sync schema");
- return codegen_1._ `await ${fmtRef}(${data})`;
+ return (0, codegen_1._) `await ${fmtRef}(${data})`;
}
- return typeof format == "function" ? codegen_1._ `${fmtRef}(${data})` : codegen_1._ `${fmtRef}.test(${data})`;
+ return typeof format == "function" ? (0, codegen_1._) `${fmtRef}(${data})` : (0, codegen_1._) `${fmtRef}.test(${data})`;
}
}
},