@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.
- package/dist/jwt/jwt.service.d.ts +4 -4
- package/dist/validation/ajv/from-data/generateJsonSchemaFromData.d.ts +1 -1
- package/dist/validation/ajv/getAjv.d.ts +1 -1
- package/dist/validation/ajv/index.d.ts +1 -1
- package/dist/validation/ajv/index.js +1 -1
- package/dist/validation/ajv/{ajvSchema.d.ts → jSchema.d.ts} +232 -271
- package/dist/validation/ajv/{ajvSchema.js → jSchema.js} +453 -460
- package/dist/validation/ajv/jsonSchemaBuilder.util.d.ts +1 -1
- package/dist/zip/zip.util.d.ts +3 -0
- package/dist/zip/zip.util.js +10 -0
- package/package.json +2 -2
- package/src/jwt/jwt.service.ts +8 -4
- package/src/validation/ajv/from-data/generateJsonSchemaFromData.ts +2 -2
- package/src/validation/ajv/getAjv.ts +5 -5
- package/src/validation/ajv/index.ts +1 -1
- package/src/validation/ajv/{ajvSchema.ts → jSchema.ts} +1447 -1471
- package/src/validation/ajv/jsonSchemaBuilder.util.ts +1 -1
- package/src/zip/zip.util.ts +16 -0
|
@@ -1,5 +1,5 @@
|
|
|
1
1
|
import type { AnyObject } from '@naturalcycles/js-lib/types';
|
|
2
|
-
import type { JsonSchema } from './
|
|
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/dist/zip/zip.util.d.ts
CHANGED
|
@@ -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;
|
package/dist/zip/zip.util.js
CHANGED
|
@@ -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.
|
|
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": "
|
|
22
|
+
"@naturalcycles/dev-lib": "20.36.0"
|
|
23
23
|
},
|
|
24
24
|
"exports": {
|
|
25
25
|
".": "./dist/index.js",
|
package/src/jwt/jwt.service.ts
CHANGED
|
@@ -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/
|
|
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>(
|
|
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
|
|
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
|
-
|
|
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,
|
|
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:
|
|
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 {
|