@naturalcycles/nodejs-lib 15.92.1 → 15.94.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.
@@ -31,8 +31,11 @@ export declare function gunzipBuffer(buf: Buffer, options?: ZlibOptions): Promis
31
31
  export declare function gzipString(s: string, options?: ZlibOptions): Promise<Buffer<ArrayBuffer>>;
32
32
  export declare function gunzipToString(buf: Buffer, options?: ZlibOptions): Promise<string>;
33
33
  export declare function zstdCompress(input: Buffer | string, level?: Integer, options?: ZstdOptions): Promise<Buffer<ArrayBuffer>>;
34
+ export declare function zstdCompressSync(input: Buffer | string, level?: Integer, options?: ZstdOptions): Buffer<ArrayBuffer>;
34
35
  export declare function zstdLevelToOptions(level: Integer | undefined, opt?: ZstdOptions): ZstdOptions;
35
36
  export declare function zstdDecompressToString(input: Buffer, options?: ZstdOptions): Promise<string>;
36
37
  export declare function zstdDecompress(input: Buffer, options?: ZstdOptions): Promise<Buffer<ArrayBuffer>>;
38
+ export declare function zstdDecompressToStringSync(input: Buffer, options?: ZstdOptions): string;
39
+ export declare function zstdDecompressSync(input: Buffer, options?: ZstdOptions): Buffer<ArrayBuffer>;
37
40
  export declare function isZstdBuffer(input: Buffer): boolean;
38
41
  export declare function isGzipBuffer(input: Buffer): boolean;
@@ -63,6 +63,10 @@ export async function zstdCompress(input, level, // defaults to 3
63
63
  options = {}) {
64
64
  return await zstdCompressAsync(input, zstdLevelToOptions(level, options));
65
65
  }
66
+ export function zstdCompressSync(input, level, // defaults to 3
67
+ options = {}) {
68
+ return zlib.zstdCompressSync(input, zstdLevelToOptions(level, options));
69
+ }
66
70
  export function zstdLevelToOptions(level, opt = {}) {
67
71
  if (!level)
68
72
  return opt;
@@ -80,6 +84,12 @@ export async function zstdDecompressToString(input, options = {}) {
80
84
  export async function zstdDecompress(input, options = {}) {
81
85
  return await zstdDecompressAsync(input, options);
82
86
  }
87
+ export function zstdDecompressToStringSync(input, options = {}) {
88
+ return zlib.zstdDecompressSync(input, options).toString();
89
+ }
90
+ export function zstdDecompressSync(input, options = {}) {
91
+ return zlib.zstdDecompressSync(input, options);
92
+ }
83
93
  const ZSTD_MAGIC_NUMBER = 0xfd2fb528;
84
94
  export function isZstdBuffer(input) {
85
95
  return input.readUInt32LE(0) === ZSTD_MAGIC_NUMBER;
package/package.json CHANGED
@@ -1,7 +1,7 @@
1
1
  {
2
2
  "name": "@naturalcycles/nodejs-lib",
3
3
  "type": "module",
4
- "version": "15.92.1",
4
+ "version": "15.94.0",
5
5
  "dependencies": {
6
6
  "@naturalcycles/js-lib": "^15",
7
7
  "@types/js-yaml": "^4",
@@ -19,7 +19,7 @@
19
19
  },
20
20
  "devDependencies": {
21
21
  "@typescript/native-preview": "7.0.0-dev.20260201.1",
22
- "@naturalcycles/dev-lib": "18.4.2"
22
+ "@naturalcycles/dev-lib": "20.36.0"
23
23
  },
24
24
  "exports": {
25
25
  ".": "./dist/index.js",
@@ -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 }