@naturalcycles/nodejs-lib 15.93.0 → 15.95.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,5 +1,5 @@
1
1
  import type { AnyObject } from '@naturalcycles/js-lib/types';
2
- import type { JsonSchema } from './ajvSchema.js';
2
+ import type { JsonSchema } from './jSchema.js';
3
3
  export declare const JSON_SCHEMA_ORDER: string[];
4
4
  /**
5
5
  * Merges s2 into s1 (mutates s1) and returns s1.
package/package.json CHANGED
@@ -1,7 +1,7 @@
1
1
  {
2
2
  "name": "@naturalcycles/nodejs-lib",
3
3
  "type": "module",
4
- "version": "15.93.0",
4
+ "version": "15.95.0",
5
5
  "dependencies": {
6
6
  "@naturalcycles/js-lib": "^15",
7
7
  "@types/js-yaml": "^4",
@@ -4,7 +4,7 @@ import { _errorDataAppend } from '@naturalcycles/js-lib/error/error.util.js'
4
4
  import type { AnyObject, JWTString } from '@naturalcycles/js-lib/types'
5
5
  import type { Algorithm, JwtHeader, SignOptions, VerifyOptions } from 'jsonwebtoken'
6
6
  import jsonwebtoken from 'jsonwebtoken'
7
- import type { AjvSchema } from '../validation/ajv/ajvSchema.js'
7
+ import type { AjvSchema, JSchema } from '../validation/ajv/jSchema.js'
8
8
  export { jsonwebtoken }
9
9
  export type { Algorithm, JwtHeader, SignOptions, VerifyOptions }
10
10
 
@@ -63,7 +63,11 @@ export interface JWTServiceCfg {
63
63
  export class JWTService {
64
64
  constructor(public cfg: JWTServiceCfg) {}
65
65
 
66
- sign<T extends AnyObject>(payload: T, schema?: AjvSchema<T>, opt: SignOptions = {}): JWTString {
66
+ sign<T extends AnyObject>(
67
+ payload: T,
68
+ schema?: JSchema<T, any> | AjvSchema<T>,
69
+ opt: SignOptions = {},
70
+ ): JWTString {
67
71
  _assert(
68
72
  this.cfg.privateKey,
69
73
  'JWTService: privateKey is required to be able to verify, but not provided',
@@ -81,7 +85,7 @@ export class JWTService {
81
85
 
82
86
  verify<T extends AnyObject>(
83
87
  token: JWTString,
84
- schema?: AjvSchema<T>,
88
+ schema?: JSchema<T, any> | AjvSchema<T>,
85
89
  opt: VerifyOptions = {},
86
90
  publicKey?: string, // allows to override public key
87
91
  ): T {
@@ -112,7 +116,7 @@ export class JWTService {
112
116
 
113
117
  decode<T extends AnyObject>(
114
118
  token: JWTString,
115
- schema?: AjvSchema<T>,
119
+ schema?: JSchema<T, any> | AjvSchema<T>,
116
120
  ): {
117
121
  header: JwtHeader
118
122
  payload: T
@@ -1,7 +1,7 @@
1
1
  import { _uniq } from '@naturalcycles/js-lib/array'
2
- import { _stringMapEntries } from '@naturalcycles/js-lib/types'
3
2
  import type { AnyObject, StringMap } from '@naturalcycles/js-lib/types'
4
- import type { JsonSchema } from '../ajvSchema.js'
3
+ import { _stringMapEntries } from '@naturalcycles/js-lib/types'
4
+ import type { JsonSchema } from '../jSchema.js'
5
5
 
6
6
  type PrimitiveType = 'undefined' | 'null' | 'boolean' | 'string' | 'number'
7
7
  type Type = PrimitiveType | 'array' | 'object'
@@ -3,17 +3,17 @@ import { _assert } from '@naturalcycles/js-lib/error'
3
3
  import { _deepCopy, _mapObject, Set2 } from '@naturalcycles/js-lib/object'
4
4
  import { _substringAfterLast } from '@naturalcycles/js-lib/string'
5
5
  import type { AnyObject } from '@naturalcycles/js-lib/types'
6
- import { Ajv2020 } from 'ajv/dist/2020.js'
7
6
  import type { Options, ValidateFunction } from 'ajv/dist/2020.js'
7
+ import { Ajv2020 } from 'ajv/dist/2020.js'
8
8
  import { validTLDs } from '../tlds.js'
9
9
  import type {
10
10
  CustomConverterFn,
11
11
  CustomValidatorFn,
12
+ JSchema,
12
13
  JsonSchemaIsoDateOptions,
13
14
  JsonSchemaIsoMonthOptions,
14
15
  JsonSchemaStringEmailOptions,
15
- JsonSchemaTerminal,
16
- } from './ajvSchema.js'
16
+ } from './jSchema.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>>,
573
+ schemaDictionary as Record<any, JSchema<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>[], _parentSchema, _it) {
610
+ compile(schemas: JSchema<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 {
@@ -1,8 +1,8 @@
1
1
  import Ajv from 'ajv'
2
2
 
3
- export * from './ajvSchema.js'
4
3
  export * from './ajvValidationError.js'
5
4
  export * from './from-data/generateJsonSchemaFromData.js'
6
5
  export * from './getAjv.js'
6
+ export * from './jSchema.js'
7
7
 
8
8
  export { Ajv }