@naturalcycles/nodejs-lib 15.90.2 → 15.92.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.
@@ -1,7 +1,7 @@
1
1
  import { _uniq } from '@naturalcycles/js-lib/array'
2
2
  import { _stringMapEntries } from '@naturalcycles/js-lib/types'
3
3
  import type { AnyObject, StringMap } from '@naturalcycles/js-lib/types'
4
- import type { JsonSchema } from '../jsonSchemaBuilder.js'
4
+ import type { JsonSchema } from '../ajvSchema.js'
5
5
 
6
6
  type PrimitiveType = 'undefined' | 'null' | 'boolean' | 'string' | 'number'
7
7
  type Type = PrimitiveType | 'array' | 'object'
@@ -13,7 +13,7 @@ import type {
13
13
  JsonSchemaIsoMonthOptions,
14
14
  JsonSchemaStringEmailOptions,
15
15
  JsonSchemaTerminal,
16
- } from './jsonSchemaBuilder.js'
16
+ } from './ajvSchema.js'
17
17
 
18
18
  /* eslint-disable @typescript-eslint/prefer-string-starts-ends-with */
19
19
  // oxlint-disable unicorn/prefer-code-point
@@ -570,7 +570,7 @@ export function createAjv(opt?: Options): Ajv2020 {
570
570
  const { propertyName, schemaDictionary } = config
571
571
 
572
572
  const isValidFnByKey: Record<any, ValidateFunction> = _mapObject(
573
- schemaDictionary as Record<any, JsonSchemaTerminal<any, any, any>>,
573
+ schemaDictionary as Record<any, JsonSchemaTerminal<any, any>>,
574
574
  (key, value) => {
575
575
  return [key, ajv.compile(value)]
576
576
  },
@@ -607,7 +607,7 @@ export function createAjv(opt?: Options): Ajv2020 {
607
607
  modifying: true,
608
608
  errors: true,
609
609
  schemaType: 'array',
610
- compile(schemas: JsonSchemaTerminal<any, any, any>[], _parentSchema, _it) {
610
+ compile(schemas: JsonSchemaTerminal<any, any>[], _parentSchema, _it) {
611
611
  const validators = schemas.map(schema => ajv.compile(schema))
612
612
 
613
613
  function validate(data: AnyObject, ctx: any): boolean {
@@ -725,6 +725,13 @@ export function createAjv(opt?: Options): Ajv2020 {
725
725
  },
726
726
  })
727
727
 
728
+ // postValidation is handled in AjvSchema.getValidationResult, not by Ajv itself.
729
+ // We register it here so Ajv's strict mode doesn't reject the keyword.
730
+ ajv.addKeyword({
731
+ keyword: 'postValidation',
732
+ valid: true,
733
+ })
734
+
728
735
  return ajv
729
736
  }
730
737
 
@@ -4,6 +4,5 @@ export * from './ajvSchema.js'
4
4
  export * from './ajvValidationError.js'
5
5
  export * from './from-data/generateJsonSchemaFromData.js'
6
6
  export * from './getAjv.js'
7
- export * from './jsonSchemaBuilder.js'
8
7
 
9
8
  export { Ajv }
@@ -1,7 +1,7 @@
1
1
  import { _uniq } from '@naturalcycles/js-lib/array'
2
2
  import { _filterNullishValues } from '@naturalcycles/js-lib/object'
3
3
  import type { AnyObject } from '@naturalcycles/js-lib/types'
4
- import type { JsonSchema } from './jsonSchemaBuilder.js'
4
+ import type { JsonSchema } from './ajvSchema.js'
5
5
 
6
6
  export const JSON_SCHEMA_ORDER = [
7
7
  '$schema',