(cxt)
| 359 | $data: true, |
| 360 | error, |
| 361 | code(cxt) { |
| 362 | const { gen, data, schemaCode, keyword, it } = cxt; |
| 363 | const { opts, self } = it; |
| 364 | if (!opts.validateFormats) |
| 365 | return; |
| 366 | const fCxt = new ajv_1.KeywordCxt(it, self.RULES.all.format.definition, "format"); |
| 367 | if (fCxt.$data) |
| 368 | validate$DataFormat(); |
| 369 | else |
| 370 | validateFormat(); |
| 371 | function validate$DataFormat() { |
| 372 | const fmts = gen.scopeValue("formats", { |
| 373 | ref: self.formats, |
| 374 | code: opts.code.formats, |
| 375 | }); |
| 376 | const fmt = gen.const("fmt", codegen_1._ `${fmts}[${fCxt.schemaCode}]`); |
| 377 | cxt.fail$data(codegen_1.or(codegen_1._ `typeof ${fmt} != "object"`, codegen_1._ `${fmt} instanceof RegExp`, codegen_1._ `typeof ${fmt}.compare != "function"`, compareCode(fmt))); |
| 378 | } |
| 379 | function validateFormat() { |
| 380 | const format = fCxt.schema; |
| 381 | const fmtDef = self.formats[format]; |
| 382 | if (!fmtDef || fmtDef === true) |
| 383 | return; |
| 384 | if (typeof fmtDef != "object" || |
| 385 | fmtDef instanceof RegExp || |
| 386 | typeof fmtDef.compare != "function") { |
| 387 | throw new Error(`"${keyword}": format "${format}" does not define "compare" function`); |
| 388 | } |
| 389 | const fmt = gen.scopeValue("formats", { |
| 390 | key: format, |
| 391 | ref: fmtDef, |
| 392 | code: opts.code.formats ? codegen_1._ `${opts.code.formats}${codegen_1.getProperty(format)}` : undefined, |
| 393 | }); |
| 394 | cxt.fail$data(compareCode(fmt)); |
| 395 | } |
| 396 | function compareCode(fmt) { |
| 397 | return codegen_1._ `${fmt}.compare(${data}, ${schemaCode}) ${KWDs[keyword].fail} 0`; |
| 398 | } |
| 399 | }, |
| 400 | dependencies: ["format"], |
| 401 | }; |
| 402 | const formatLimitPlugin = (ajv) => { |
nothing calls this directly
no test coverage detected