@naturalcycles/nodejs-lib 15.15.0 → 15.17.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.
|
@@ -7,6 +7,13 @@ import { Ajv } from 'ajv';
|
|
|
7
7
|
* to benefit from cached Ajv instance.
|
|
8
8
|
*/
|
|
9
9
|
export declare const getAjv: any;
|
|
10
|
+
/**
|
|
11
|
+
* Returns cached instance of Ajv, which is non-mutating.
|
|
12
|
+
*
|
|
13
|
+
* To be used in places where we only need to know if an item is valid or not,
|
|
14
|
+
* and are not interested in transforming the data.
|
|
15
|
+
*/
|
|
16
|
+
export declare const getNonMutatingAjv: any;
|
|
10
17
|
/**
|
|
11
18
|
* Create Ajv with modified defaults.
|
|
12
19
|
*
|
|
@@ -11,6 +11,11 @@ const AJV_OPTIONS = {
|
|
|
11
11
|
// https://ajv.js.org/options.html#coercetypes
|
|
12
12
|
coerceTypes: false, // while `false` - it won't mutate your input
|
|
13
13
|
};
|
|
14
|
+
const AJV_NON_MUTATING_OPTIONS = {
|
|
15
|
+
...AJV_OPTIONS,
|
|
16
|
+
removeAdditional: false,
|
|
17
|
+
useDefaults: false,
|
|
18
|
+
};
|
|
14
19
|
/**
|
|
15
20
|
* Return cached instance of Ajv with default (recommended) options.
|
|
16
21
|
*
|
|
@@ -18,6 +23,13 @@ const AJV_OPTIONS = {
|
|
|
18
23
|
* to benefit from cached Ajv instance.
|
|
19
24
|
*/
|
|
20
25
|
export const getAjv = _lazyValue(createAjv);
|
|
26
|
+
/**
|
|
27
|
+
* Returns cached instance of Ajv, which is non-mutating.
|
|
28
|
+
*
|
|
29
|
+
* To be used in places where we only need to know if an item is valid or not,
|
|
30
|
+
* and are not interested in transforming the data.
|
|
31
|
+
*/
|
|
32
|
+
export const getNonMutatingAjv = _lazyValue(() => createAjv(AJV_NON_MUTATING_OPTIONS));
|
|
21
33
|
/**
|
|
22
34
|
* Create Ajv with modified defaults.
|
|
23
35
|
*
|
|
@@ -32,6 +44,7 @@ export function createAjv(opt) {
|
|
|
32
44
|
});
|
|
33
45
|
// Add custom formats
|
|
34
46
|
addCustomAjvFormats(ajv);
|
|
47
|
+
// todo: review and possibly cherry-pick/vendor the formats
|
|
35
48
|
// Adds ajv "formats"
|
|
36
49
|
// https://ajv.js.org/guide/formats.html
|
|
37
50
|
// @ts-expect-error types are wrong
|
|
@@ -50,7 +63,9 @@ export function createAjv(opt) {
|
|
|
50
63
|
return ajv;
|
|
51
64
|
}
|
|
52
65
|
const TS_2500 = 16725225600; // 2500-01-01
|
|
66
|
+
const TS_2500_MILLIS = TS_2500 * 1000;
|
|
53
67
|
const TS_2000 = 946684800; // 2000-01-01
|
|
68
|
+
const TS_2000_MILLIS = TS_2000 * 1000;
|
|
54
69
|
function addCustomAjvFormats(ajv) {
|
|
55
70
|
return (ajv
|
|
56
71
|
.addFormat('id', /^[a-z0-9_]{6,64}$/)
|
|
@@ -75,13 +90,13 @@ function addCustomAjvFormats(ajv) {
|
|
|
75
90
|
.addFormat('unixTimestampMillis', {
|
|
76
91
|
type: 'number',
|
|
77
92
|
validate: (n) => {
|
|
78
|
-
return n >= 0 && n <
|
|
93
|
+
return n >= 0 && n < TS_2500_MILLIS;
|
|
79
94
|
},
|
|
80
95
|
})
|
|
81
96
|
.addFormat('unixTimestampMillis2000', {
|
|
82
97
|
type: 'number',
|
|
83
98
|
validate: (n) => {
|
|
84
|
-
return n >=
|
|
99
|
+
return n >= TS_2000_MILLIS && n < TS_2500_MILLIS;
|
|
85
100
|
},
|
|
86
101
|
})
|
|
87
102
|
.addFormat('utcOffset', {
|
package/dist/zip/zip.util.d.ts
CHANGED
|
@@ -3,23 +3,23 @@ import type { ZlibOptions } from 'node:zlib';
|
|
|
3
3
|
* deflateBuffer uses `deflate`.
|
|
4
4
|
* It's 9 bytes shorter than `gzip`.
|
|
5
5
|
*/
|
|
6
|
-
export declare function deflateBuffer(buf: Buffer, options?: ZlibOptions): Promise<Buffer
|
|
7
|
-
export declare function inflateBuffer(buf: Buffer, options?: ZlibOptions): Promise<Buffer
|
|
6
|
+
export declare function deflateBuffer(buf: Buffer, options?: ZlibOptions): Promise<Buffer<ArrayBuffer>>;
|
|
7
|
+
export declare function inflateBuffer(buf: Buffer, options?: ZlibOptions): Promise<Buffer<ArrayBuffer>>;
|
|
8
8
|
/**
|
|
9
9
|
* deflateString uses `deflate`.
|
|
10
10
|
* It's 9 bytes shorter than `gzip`.
|
|
11
11
|
*/
|
|
12
|
-
export declare function deflateString(s: string, options?: ZlibOptions): Promise<Buffer
|
|
12
|
+
export declare function deflateString(s: string, options?: ZlibOptions): Promise<Buffer<ArrayBuffer>>;
|
|
13
13
|
export declare function inflateToString(buf: Buffer, options?: ZlibOptions): Promise<string>;
|
|
14
14
|
/**
|
|
15
15
|
* gzipBuffer uses `gzip`
|
|
16
16
|
* It's 9 bytes longer than `deflate`.
|
|
17
17
|
*/
|
|
18
|
-
export declare function gzipBuffer(buf: Buffer, options?: ZlibOptions): Promise<Buffer
|
|
19
|
-
export declare function gunzipBuffer(buf: Buffer, options?: ZlibOptions): Promise<Buffer
|
|
18
|
+
export declare function gzipBuffer(buf: Buffer, options?: ZlibOptions): Promise<Buffer<ArrayBuffer>>;
|
|
19
|
+
export declare function gunzipBuffer(buf: Buffer, options?: ZlibOptions): Promise<Buffer<ArrayBuffer>>;
|
|
20
20
|
/**
|
|
21
21
|
* gzipString uses `gzip`.
|
|
22
22
|
* It's 9 bytes longer than `deflate`.
|
|
23
23
|
*/
|
|
24
|
-
export declare function gzipString(s: string, options?: ZlibOptions): Promise<Buffer
|
|
24
|
+
export declare function gzipString(s: string, options?: ZlibOptions): Promise<Buffer<ArrayBuffer>>;
|
|
25
25
|
export declare function gunzipToString(buf: Buffer, options?: ZlibOptions): Promise<string>;
|
package/dist/zip/zip.util.js
CHANGED
|
@@ -9,10 +9,10 @@ const gunzip = promisify(zlib.gunzip.bind(zlib));
|
|
|
9
9
|
* It's 9 bytes shorter than `gzip`.
|
|
10
10
|
*/
|
|
11
11
|
export async function deflateBuffer(buf, options = {}) {
|
|
12
|
-
return await deflate(buf, options);
|
|
12
|
+
return (await deflate(buf, options));
|
|
13
13
|
}
|
|
14
14
|
export async function inflateBuffer(buf, options = {}) {
|
|
15
|
-
return await inflate(buf, options);
|
|
15
|
+
return (await inflate(buf, options));
|
|
16
16
|
}
|
|
17
17
|
/**
|
|
18
18
|
* deflateString uses `deflate`.
|
|
@@ -29,10 +29,10 @@ export async function inflateToString(buf, options) {
|
|
|
29
29
|
* It's 9 bytes longer than `deflate`.
|
|
30
30
|
*/
|
|
31
31
|
export async function gzipBuffer(buf, options = {}) {
|
|
32
|
-
return await gzip(buf, options);
|
|
32
|
+
return (await gzip(buf, options));
|
|
33
33
|
}
|
|
34
34
|
export async function gunzipBuffer(buf, options = {}) {
|
|
35
|
-
return await gunzip(buf, options);
|
|
35
|
+
return (await gunzip(buf, options));
|
|
36
36
|
}
|
|
37
37
|
/**
|
|
38
38
|
* gzipString uses `gzip`.
|
package/package.json
CHANGED
|
@@ -14,6 +14,12 @@ const AJV_OPTIONS: Options = {
|
|
|
14
14
|
coerceTypes: false, // while `false` - it won't mutate your input
|
|
15
15
|
}
|
|
16
16
|
|
|
17
|
+
const AJV_NON_MUTATING_OPTIONS: Options = {
|
|
18
|
+
...AJV_OPTIONS,
|
|
19
|
+
removeAdditional: false,
|
|
20
|
+
useDefaults: false,
|
|
21
|
+
}
|
|
22
|
+
|
|
17
23
|
/**
|
|
18
24
|
* Return cached instance of Ajv with default (recommended) options.
|
|
19
25
|
*
|
|
@@ -22,6 +28,14 @@ const AJV_OPTIONS: Options = {
|
|
|
22
28
|
*/
|
|
23
29
|
export const getAjv = _lazyValue(createAjv)
|
|
24
30
|
|
|
31
|
+
/**
|
|
32
|
+
* Returns cached instance of Ajv, which is non-mutating.
|
|
33
|
+
*
|
|
34
|
+
* To be used in places where we only need to know if an item is valid or not,
|
|
35
|
+
* and are not interested in transforming the data.
|
|
36
|
+
*/
|
|
37
|
+
export const getNonMutatingAjv = _lazyValue(() => createAjv(AJV_NON_MUTATING_OPTIONS))
|
|
38
|
+
|
|
25
39
|
/**
|
|
26
40
|
* Create Ajv with modified defaults.
|
|
27
41
|
*
|
|
@@ -38,6 +52,7 @@ export function createAjv(opt?: Options): Ajv {
|
|
|
38
52
|
// Add custom formats
|
|
39
53
|
addCustomAjvFormats(ajv)
|
|
40
54
|
|
|
55
|
+
// todo: review and possibly cherry-pick/vendor the formats
|
|
41
56
|
// Adds ajv "formats"
|
|
42
57
|
// https://ajv.js.org/guide/formats.html
|
|
43
58
|
// @ts-expect-error types are wrong
|
|
@@ -60,7 +75,9 @@ export function createAjv(opt?: Options): Ajv {
|
|
|
60
75
|
}
|
|
61
76
|
|
|
62
77
|
const TS_2500 = 16725225600 // 2500-01-01
|
|
78
|
+
const TS_2500_MILLIS = TS_2500 * 1000
|
|
63
79
|
const TS_2000 = 946684800 // 2000-01-01
|
|
80
|
+
const TS_2000_MILLIS = TS_2000 * 1000
|
|
64
81
|
|
|
65
82
|
function addCustomAjvFormats(ajv: Ajv): Ajv {
|
|
66
83
|
return (
|
|
@@ -87,13 +104,13 @@ function addCustomAjvFormats(ajv: Ajv): Ajv {
|
|
|
87
104
|
.addFormat('unixTimestampMillis', {
|
|
88
105
|
type: 'number',
|
|
89
106
|
validate: (n: number) => {
|
|
90
|
-
return n >= 0 && n <
|
|
107
|
+
return n >= 0 && n < TS_2500_MILLIS
|
|
91
108
|
},
|
|
92
109
|
})
|
|
93
110
|
.addFormat('unixTimestampMillis2000', {
|
|
94
111
|
type: 'number',
|
|
95
112
|
validate: (n: number) => {
|
|
96
|
-
return n >=
|
|
113
|
+
return n >= TS_2000_MILLIS && n < TS_2500_MILLIS
|
|
97
114
|
},
|
|
98
115
|
})
|
|
99
116
|
.addFormat('utcOffset', {
|
package/src/zip/zip.util.ts
CHANGED
|
@@ -11,19 +11,28 @@ const gunzip = promisify(zlib.gunzip.bind(zlib))
|
|
|
11
11
|
* deflateBuffer uses `deflate`.
|
|
12
12
|
* It's 9 bytes shorter than `gzip`.
|
|
13
13
|
*/
|
|
14
|
-
export async function deflateBuffer(
|
|
15
|
-
|
|
14
|
+
export async function deflateBuffer(
|
|
15
|
+
buf: Buffer,
|
|
16
|
+
options: ZlibOptions = {},
|
|
17
|
+
): Promise<Buffer<ArrayBuffer>> {
|
|
18
|
+
return (await deflate(buf, options)) as Buffer<ArrayBuffer>
|
|
16
19
|
}
|
|
17
20
|
|
|
18
|
-
export async function inflateBuffer(
|
|
19
|
-
|
|
21
|
+
export async function inflateBuffer(
|
|
22
|
+
buf: Buffer,
|
|
23
|
+
options: ZlibOptions = {},
|
|
24
|
+
): Promise<Buffer<ArrayBuffer>> {
|
|
25
|
+
return (await inflate(buf, options)) as Buffer<ArrayBuffer>
|
|
20
26
|
}
|
|
21
27
|
|
|
22
28
|
/**
|
|
23
29
|
* deflateString uses `deflate`.
|
|
24
30
|
* It's 9 bytes shorter than `gzip`.
|
|
25
31
|
*/
|
|
26
|
-
export async function deflateString(
|
|
32
|
+
export async function deflateString(
|
|
33
|
+
s: string,
|
|
34
|
+
options?: ZlibOptions,
|
|
35
|
+
): Promise<Buffer<ArrayBuffer>> {
|
|
27
36
|
return await deflateBuffer(Buffer.from(s), options)
|
|
28
37
|
}
|
|
29
38
|
|
|
@@ -35,19 +44,25 @@ export async function inflateToString(buf: Buffer, options?: ZlibOptions): Promi
|
|
|
35
44
|
* gzipBuffer uses `gzip`
|
|
36
45
|
* It's 9 bytes longer than `deflate`.
|
|
37
46
|
*/
|
|
38
|
-
export async function gzipBuffer(
|
|
39
|
-
|
|
47
|
+
export async function gzipBuffer(
|
|
48
|
+
buf: Buffer,
|
|
49
|
+
options: ZlibOptions = {},
|
|
50
|
+
): Promise<Buffer<ArrayBuffer>> {
|
|
51
|
+
return (await gzip(buf, options)) as Buffer<ArrayBuffer>
|
|
40
52
|
}
|
|
41
53
|
|
|
42
|
-
export async function gunzipBuffer(
|
|
43
|
-
|
|
54
|
+
export async function gunzipBuffer(
|
|
55
|
+
buf: Buffer,
|
|
56
|
+
options: ZlibOptions = {},
|
|
57
|
+
): Promise<Buffer<ArrayBuffer>> {
|
|
58
|
+
return (await gunzip(buf, options)) as Buffer<ArrayBuffer>
|
|
44
59
|
}
|
|
45
60
|
|
|
46
61
|
/**
|
|
47
62
|
* gzipString uses `gzip`.
|
|
48
63
|
* It's 9 bytes longer than `deflate`.
|
|
49
64
|
*/
|
|
50
|
-
export async function gzipString(s: string, options?: ZlibOptions): Promise<Buffer
|
|
65
|
+
export async function gzipString(s: string, options?: ZlibOptions): Promise<Buffer<ArrayBuffer>> {
|
|
51
66
|
return await gzipBuffer(Buffer.from(s), options)
|
|
52
67
|
}
|
|
53
68
|
|