ata-validator 1.33.3 → 1.34.0

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
package/compat.d.ts CHANGED
@@ -36,14 +36,25 @@ declare class Ata {
36
36
  }
37
37
 
38
38
  declare namespace Ata {
39
- interface ErrorObject {
39
+ /** The same class under the name ajv 8 exports it by: `import { Ajv } from 'ata-validator/compat'`. */
40
+ const Ajv: typeof Ata;
41
+ type Ajv = Ata;
42
+ // Generic the way the reference's ErrorObject is, so code that names
43
+ // `ErrorObject<string, Record<string, any>, unknown>` compiles against this
44
+ // entry unchanged, and an error from here passes where one from the
45
+ // reference is expected.
46
+ interface ErrorObject<K extends string = string, P = Record<string, any>, S = unknown> {
40
47
  instancePath: string;
41
48
  schemaPath: string;
42
- keyword: string;
43
- params: Record<string, unknown>;
49
+ keyword: K;
50
+ params: P;
44
51
  message: string;
45
52
  /** Present when `verbose: true`. */
46
- parentSchema?: unknown;
53
+ schema?: S;
54
+ /** Present when `verbose: true`. */
55
+ parentSchema?: Record<string, any>;
56
+ /** Present when `verbose: true`. */
57
+ data?: unknown;
47
58
  /** Present on errors produced under `propertyNames`. */
48
59
  propertyName?: string;
49
60
  [extra: string]: unknown;
package/compat.js CHANGED
@@ -432,3 +432,4 @@ Ata.attachDataFrames = function attachDataFrames(errors, text) {
432
432
  module.exports = Ata;
433
433
  module.exports.default = Ata;
434
434
  module.exports.Ata = Ata;
435
+ module.exports.Ajv = Ata;
package/compat.mjs CHANGED
@@ -1,3 +1,5 @@
1
1
  import Ata from './compat.js';
2
- export { Ata };
2
+ // `Ajv` as well, so the named import ajv 8 documents,
3
+ // `import { Ajv } from 'ajv'`, changes only in the module name.
4
+ export { Ata, Ata as Ajv };
3
5
  export default Ata;
@@ -369,8 +369,25 @@ function createShaper({ Validator, rootId, rootDoc, schemas, options, allErrors,
369
369
  return group.length;
370
370
  }
371
371
 
372
+ // A `type` error the way the reference words it. ata folds `nullable: true`
373
+ // into the type union before compiling, so its own error names the union:
374
+ // `must be integer, null`. The reference names the type as written, adding
375
+ // `null` only when the written type is already a list, and joins a list
376
+ // with a bare comma: `must be integer`, `must be string,number,null`. The
377
+ // node is read from the schema as the caller passed it.
378
+ function asReferenceType(e) {
379
+ if (e.keyword !== 'type' || typeof e.message !== 'string' || !e.message.startsWith('must be ')) return e;
380
+ const ptr = pointerOf(e.schemaPath || '');
381
+ if (!ptr.endsWith('/type')) return e;
382
+ const node = walkPointer(rootDoc, ptr.slice(0, -'/type'.length));
383
+ let t = node && typeof node === 'object' && node.type !== undefined ? node.type : e.params && e.params.type;
384
+ if (t === undefined) return e;
385
+ if (node && node.nullable === true && Array.isArray(t) && !t.includes('null')) t = [...t, 'null'];
386
+ return { ...e, params: { ...e.params, type: t }, message: 'must be ' + (Array.isArray(t) ? t.join(',') : t) };
387
+ }
388
+
372
389
  return function shapeErrors(errors, data) {
373
- const shaped = shape(errors, data, '').map(asReferenceKeyword);
390
+ const shaped = shape(errors, data, '').map(asReferenceKeyword).map(asReferenceType);
374
391
  if (allErrors) return shaped;
375
392
  const n = groupEnd(shaped);
376
393
  return shaped.slice(0, n);
package/lib/version.js CHANGED
@@ -7,4 +7,4 @@
7
7
  //
8
8
  // Kept in lockstep with package.json by `tests/test_version_sync.js`.
9
9
 
10
- module.exports = '1.33.3';
10
+ module.exports = '1.34.0';
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "ata-validator",
3
- "version": "1.33.3",
3
+ "version": "1.34.0",
4
4
  "description": "JSON Schema validation that compiles for speed and still runs where code generation is blocked. Compiled and interpreted engines answer identically at 100% of the official suite. TypeScript inference, Standard Schema V1, and a build step that emits dependency-free modules.",
5
5
  "main": "index.js",
6
6
  "module": "index.mjs",
@@ -121,13 +121,13 @@
121
121
  "LICENSE"
122
122
  ],
123
123
  "optionalDependencies": {
124
- "@ata-validator/native-darwin-arm64": "1.33.3",
125
- "@ata-validator/native-darwin-x64": "1.33.3",
126
- "@ata-validator/native-linux-arm64-gnu": "1.33.3",
127
- "@ata-validator/native-linux-arm64-musl": "1.33.3",
128
- "@ata-validator/native-linux-x64-gnu": "1.33.3",
129
- "@ata-validator/native-linux-x64-musl": "1.33.3",
130
- "@ata-validator/native-win32-x64": "1.33.3"
124
+ "@ata-validator/native-darwin-arm64": "1.34.0",
125
+ "@ata-validator/native-darwin-x64": "1.34.0",
126
+ "@ata-validator/native-linux-arm64-gnu": "1.34.0",
127
+ "@ata-validator/native-linux-arm64-musl": "1.34.0",
128
+ "@ata-validator/native-linux-x64-gnu": "1.34.0",
129
+ "@ata-validator/native-linux-x64-musl": "1.34.0",
130
+ "@ata-validator/native-win32-x64": "1.34.0"
131
131
  },
132
132
  "peerDependencies": {
133
133
  "yaml": "^2.0.0"