@naturalcycles/nodejs-lib 12.70.1 → 12.73.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/bin/json2env.js +7 -1
- package/dist/fs/json2env.d.ts +16 -0
- package/dist/fs/json2env.js +38 -3
- package/dist/got/getGot.js +8 -1
- package/dist/stream/ndjson/pipelineFromNDJsonFile.d.ts +1 -0
- package/dist/stream/ndjson/pipelineToNDJsonFile.d.ts +1 -0
- package/dist/stream/pipeline/pipeline.d.ts +1 -0
- package/dist/util/zip.util.d.ts +1 -0
- package/dist/validation/joi/joi.shared.schemas.d.ts +15 -0
- package/dist/validation/joi/joi.shared.schemas.js +29 -7
- package/package.json +1 -1
- package/src/bin/json2env.ts +7 -1
- package/src/fs/json2env.ts +46 -2
- package/src/got/getGot.ts +8 -3
- package/src/validation/joi/joi.shared.schemas.ts +29 -6
package/dist/bin/json2env.js
CHANGED
|
@@ -19,6 +19,11 @@ const script_1 = require("../script");
|
|
|
19
19
|
desc: 'Populate $BASH_ENV file if BASH_ENV env variable exists',
|
|
20
20
|
default: true,
|
|
21
21
|
},
|
|
22
|
+
githubEnv: {
|
|
23
|
+
type: 'boolean',
|
|
24
|
+
desc: 'Populate $GITHUB_ENV file if GITHUB_ENV env variable exists',
|
|
25
|
+
default: true,
|
|
26
|
+
},
|
|
22
27
|
fail: {
|
|
23
28
|
type: 'boolean',
|
|
24
29
|
desc: 'Fail (exit status 1) on non-existing input file',
|
|
@@ -31,7 +36,7 @@ const script_1 = require("../script");
|
|
|
31
36
|
type: 'boolean',
|
|
32
37
|
},
|
|
33
38
|
});
|
|
34
|
-
const { _: args, prefix, saveEnvFile, bashEnv, fail, debug, silent } = argv;
|
|
39
|
+
const { _: args, prefix, saveEnvFile, bashEnv, githubEnv, fail, debug, silent } = argv;
|
|
35
40
|
if (debug)
|
|
36
41
|
console.log({ argv });
|
|
37
42
|
const jsonPath = args[0];
|
|
@@ -40,6 +45,7 @@ const script_1 = require("../script");
|
|
|
40
45
|
prefix,
|
|
41
46
|
saveEnvFile,
|
|
42
47
|
bashEnv,
|
|
48
|
+
githubEnv,
|
|
43
49
|
fail,
|
|
44
50
|
debug,
|
|
45
51
|
silent,
|
package/dist/fs/json2env.d.ts
CHANGED
|
@@ -9,6 +9,10 @@ export interface Json2EnvOptions {
|
|
|
9
9
|
* @default true
|
|
10
10
|
*/
|
|
11
11
|
bashEnv?: boolean;
|
|
12
|
+
/**
|
|
13
|
+
* @default true
|
|
14
|
+
*/
|
|
15
|
+
githubEnv?: boolean;
|
|
12
16
|
/**
|
|
13
17
|
* @default true
|
|
14
18
|
*/
|
|
@@ -29,3 +33,15 @@ export declare function json2env(opt: Json2EnvOptions): void;
|
|
|
29
33
|
* export b="c"
|
|
30
34
|
*/
|
|
31
35
|
export declare function objectToShellExport(o: any, prefix?: string): string;
|
|
36
|
+
/**
|
|
37
|
+
* Turns Object with keys/values into a file of key-value pairs
|
|
38
|
+
*
|
|
39
|
+
* @example
|
|
40
|
+
* { a: 'b', b: 'c'}
|
|
41
|
+
*
|
|
42
|
+
* will turn into:
|
|
43
|
+
*
|
|
44
|
+
* a=b
|
|
45
|
+
* b=c
|
|
46
|
+
*/
|
|
47
|
+
export declare function objectToGithubActionsEnv(o: any, prefix?: string): string;
|
package/dist/fs/json2env.js
CHANGED
|
@@ -1,15 +1,16 @@
|
|
|
1
1
|
"use strict";
|
|
2
2
|
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
-
exports.objectToShellExport = exports.json2env = void 0;
|
|
3
|
+
exports.objectToGithubActionsEnv = exports.objectToShellExport = exports.json2env = void 0;
|
|
4
4
|
const fs = require("fs-extra");
|
|
5
5
|
const colors_1 = require("../colors");
|
|
6
6
|
const JSON2ENV_OPT_DEF = {
|
|
7
7
|
saveEnvFile: true,
|
|
8
8
|
bashEnv: true,
|
|
9
|
+
githubEnv: true,
|
|
9
10
|
fail: true,
|
|
10
11
|
};
|
|
11
12
|
function json2env(opt) {
|
|
12
|
-
const { jsonPath, prefix, saveEnvFile, bashEnv, fail, debug, silent } = {
|
|
13
|
+
const { jsonPath, prefix, saveEnvFile, bashEnv, githubEnv, fail, debug, silent } = {
|
|
13
14
|
...JSON2ENV_OPT_DEF,
|
|
14
15
|
...opt,
|
|
15
16
|
};
|
|
@@ -28,8 +29,9 @@ function json2env(opt) {
|
|
|
28
29
|
// read file
|
|
29
30
|
const json = fs.readJsonSync(jsonPath);
|
|
30
31
|
const exportStr = objectToShellExport(json, prefix);
|
|
32
|
+
const githubStr = objectToGithubActionsEnv(json, prefix);
|
|
31
33
|
if (debug) {
|
|
32
|
-
console.log(json, exportStr);
|
|
34
|
+
console.log(json, exportStr, githubStr);
|
|
33
35
|
}
|
|
34
36
|
if (saveEnvFile) {
|
|
35
37
|
const shPath = `${jsonPath}.sh`;
|
|
@@ -42,6 +44,9 @@ function json2env(opt) {
|
|
|
42
44
|
if (bashEnv) {
|
|
43
45
|
appendBashEnv(exportStr);
|
|
44
46
|
}
|
|
47
|
+
if (githubEnv) {
|
|
48
|
+
appendGithubEnv(githubStr);
|
|
49
|
+
}
|
|
45
50
|
}
|
|
46
51
|
exports.json2env = json2env;
|
|
47
52
|
function appendBashEnv(exportStr) {
|
|
@@ -51,6 +56,13 @@ function appendBashEnv(exportStr) {
|
|
|
51
56
|
console.log(`BASH_ENV file appended (${(0, colors_1.dimGrey)(BASH_ENV)})`);
|
|
52
57
|
}
|
|
53
58
|
}
|
|
59
|
+
function appendGithubEnv(exportStr) {
|
|
60
|
+
const { GITHUB_ENV } = process.env;
|
|
61
|
+
if (GITHUB_ENV) {
|
|
62
|
+
fs.appendFileSync(GITHUB_ENV, exportStr + '\n');
|
|
63
|
+
console.log(`GITHUB_ENV file appended (${(0, colors_1.dimGrey)(GITHUB_ENV)})`);
|
|
64
|
+
}
|
|
65
|
+
}
|
|
54
66
|
/**
|
|
55
67
|
* Turns Object with keys/values into a *.sh script that exports all keys as values.
|
|
56
68
|
*
|
|
@@ -74,3 +86,26 @@ function objectToShellExport(o, prefix = '') {
|
|
|
74
86
|
.join('\n');
|
|
75
87
|
}
|
|
76
88
|
exports.objectToShellExport = objectToShellExport;
|
|
89
|
+
/**
|
|
90
|
+
* Turns Object with keys/values into a file of key-value pairs
|
|
91
|
+
*
|
|
92
|
+
* @example
|
|
93
|
+
* { a: 'b', b: 'c'}
|
|
94
|
+
*
|
|
95
|
+
* will turn into:
|
|
96
|
+
*
|
|
97
|
+
* a=b
|
|
98
|
+
* b=c
|
|
99
|
+
*/
|
|
100
|
+
function objectToGithubActionsEnv(o, prefix = '') {
|
|
101
|
+
return Object.keys(o)
|
|
102
|
+
.map(k => {
|
|
103
|
+
const v = o[k];
|
|
104
|
+
if (v) {
|
|
105
|
+
return `${prefix}${k}=${v}`;
|
|
106
|
+
}
|
|
107
|
+
})
|
|
108
|
+
.filter(Boolean)
|
|
109
|
+
.join('\n');
|
|
110
|
+
}
|
|
111
|
+
exports.objectToGithubActionsEnv = objectToGithubActionsEnv;
|
package/dist/got/getGot.js
CHANGED
|
@@ -1,6 +1,7 @@
|
|
|
1
1
|
"use strict";
|
|
2
2
|
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
3
|
exports.getGot = void 0;
|
|
4
|
+
const url_1 = require("url");
|
|
4
5
|
const js_lib_1 = require("@naturalcycles/js-lib");
|
|
5
6
|
const got_1 = require("got");
|
|
6
7
|
const __1 = require("..");
|
|
@@ -180,7 +181,9 @@ function gotBeforeRetryHook(opt) {
|
|
|
180
181
|
const statusCode = err?.response?.statusCode || 0;
|
|
181
182
|
if (statusCode && statusCode < 300) {
|
|
182
183
|
// todo: possibly remove the log message completely in the future
|
|
183
|
-
opt.logger
|
|
184
|
+
// opt.logger!.log(
|
|
185
|
+
// `skipping got.beforeRetry hook as statusCode is ${statusCode}, err.msg is ${err?.message}`,
|
|
186
|
+
// )
|
|
184
187
|
return;
|
|
185
188
|
}
|
|
186
189
|
const { method, url, prefixUrl } = options;
|
|
@@ -242,6 +245,10 @@ function gotAfterResponseHook(opt = {}) {
|
|
|
242
245
|
};
|
|
243
246
|
}
|
|
244
247
|
function getShortUrl(opt, url, prefixUrl) {
|
|
248
|
+
if (url.password) {
|
|
249
|
+
url = new url_1.URL(url.toString()); // prevent original url mutation
|
|
250
|
+
url.password = '[redacted]';
|
|
251
|
+
}
|
|
245
252
|
let shortUrl = url.toString();
|
|
246
253
|
if (opt.logWithSearchParams === false) {
|
|
247
254
|
shortUrl = shortUrl.split('?')[0];
|
package/dist/util/zip.util.d.ts
CHANGED
|
@@ -29,7 +29,22 @@ export declare const SLUG_PATTERN: RegExp;
|
|
|
29
29
|
* "Slug" - a valid URL, filename, etc.
|
|
30
30
|
*/
|
|
31
31
|
export declare const slugSchema: import("./string.extensions").ExtendedStringSchema;
|
|
32
|
+
/**
|
|
33
|
+
* Between years 1970 and 2050
|
|
34
|
+
*/
|
|
32
35
|
export declare const unixTimestampSchema: import("./number.extensions").ExtendedNumberSchema;
|
|
36
|
+
/**
|
|
37
|
+
* Between years 2000 and 2050
|
|
38
|
+
*/
|
|
39
|
+
export declare const unixTimestamp2000Schema: import("./number.extensions").ExtendedNumberSchema;
|
|
40
|
+
/**
|
|
41
|
+
* Between years 1970 and 2050
|
|
42
|
+
*/
|
|
43
|
+
export declare const unixTimestampMillisSchema: import("./number.extensions").ExtendedNumberSchema;
|
|
44
|
+
/**
|
|
45
|
+
* Between years 2000 and 2050
|
|
46
|
+
*/
|
|
47
|
+
export declare const unixTimestampMillis2000Schema: import("./number.extensions").ExtendedNumberSchema;
|
|
33
48
|
export declare const verSchema: import("./number.extensions").ExtendedNumberSchema;
|
|
34
49
|
/**
|
|
35
50
|
* Be careful, by default emailSchema does TLD validation. To disable it - use `stringSchema.email({tld: false}).lowercase()`
|
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
"use strict";
|
|
2
2
|
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
-
exports.savedDBEntitySchema = exports.baseDBEntitySchema = exports.ipAddressSchema = exports.utcOffsetSchema = exports.userAgentSchema = exports.semVerSchema = exports.SEM_VER_PATTERN = exports.emailSchema = exports.verSchema = exports.unixTimestampSchema = exports.slugSchema = exports.SLUG_PATTERN = exports.idSchema = exports.anyObjectSchema = exports.anySchema = exports.oneOfSchema = exports.objectSchema = exports.arraySchema = exports.urlSchema = exports.binarySchema = exports.dateStringSchema = exports.percentageSchema = exports.integerSchema = exports.numberSchema = exports.stringSchema = exports.booleanDefaultToFalseSchema = exports.booleanSchema = void 0;
|
|
3
|
+
exports.savedDBEntitySchema = exports.baseDBEntitySchema = exports.ipAddressSchema = exports.utcOffsetSchema = exports.userAgentSchema = exports.semVerSchema = exports.SEM_VER_PATTERN = exports.emailSchema = exports.verSchema = exports.unixTimestampMillis2000Schema = exports.unixTimestampMillisSchema = exports.unixTimestamp2000Schema = exports.unixTimestampSchema = exports.slugSchema = exports.SLUG_PATTERN = exports.idSchema = exports.anyObjectSchema = exports.anySchema = exports.oneOfSchema = exports.objectSchema = exports.arraySchema = exports.urlSchema = exports.binarySchema = exports.dateStringSchema = exports.percentageSchema = exports.integerSchema = exports.numberSchema = exports.stringSchema = exports.booleanDefaultToFalseSchema = exports.booleanSchema = void 0;
|
|
4
4
|
const joi_extensions_1 = require("./joi.extensions");
|
|
5
5
|
exports.booleanSchema = joi_extensions_1.Joi.boolean();
|
|
6
6
|
exports.booleanDefaultToFalseSchema = joi_extensions_1.Joi.boolean().default(false);
|
|
@@ -40,8 +40,30 @@ exports.SLUG_PATTERN = /^[a-z0-9-]*$/;
|
|
|
40
40
|
* "Slug" - a valid URL, filename, etc.
|
|
41
41
|
*/
|
|
42
42
|
exports.slugSchema = exports.stringSchema.regex(/^[a-z0-9-]{1,255}$/);
|
|
43
|
-
|
|
44
|
-
|
|
43
|
+
const TS_2500 = 16725225600; // 2500-01-01
|
|
44
|
+
const TS_2000 = 946684800; // 2000-01-01
|
|
45
|
+
/**
|
|
46
|
+
* Between years 1970 and 2050
|
|
47
|
+
*/
|
|
48
|
+
exports.unixTimestampSchema = exports.numberSchema.integer().min(0).max(TS_2500);
|
|
49
|
+
/**
|
|
50
|
+
* Between years 2000 and 2050
|
|
51
|
+
*/
|
|
52
|
+
exports.unixTimestamp2000Schema = exports.numberSchema.integer().min(0).min(TS_2000).max(TS_2500);
|
|
53
|
+
/**
|
|
54
|
+
* Between years 1970 and 2050
|
|
55
|
+
*/
|
|
56
|
+
exports.unixTimestampMillisSchema = exports.numberSchema
|
|
57
|
+
.integer()
|
|
58
|
+
.min(0)
|
|
59
|
+
.max(TS_2500 * 1000);
|
|
60
|
+
/**
|
|
61
|
+
* Between years 2000 and 2050
|
|
62
|
+
*/
|
|
63
|
+
exports.unixTimestampMillis2000Schema = exports.numberSchema
|
|
64
|
+
.integer()
|
|
65
|
+
.min(TS_2000 * 1000)
|
|
66
|
+
.max(TS_2500 * 1000);
|
|
45
67
|
// 2
|
|
46
68
|
exports.verSchema = exports.numberSchema.optional().integer().min(1).max(100);
|
|
47
69
|
/**
|
|
@@ -64,11 +86,11 @@ exports.utcOffsetSchema = exports.numberSchema
|
|
|
64
86
|
exports.ipAddressSchema = exports.stringSchema.ip();
|
|
65
87
|
exports.baseDBEntitySchema = objectSchema({
|
|
66
88
|
id: exports.stringSchema.optional(),
|
|
67
|
-
created: exports.
|
|
68
|
-
updated: exports.
|
|
89
|
+
created: exports.unixTimestamp2000Schema.optional(),
|
|
90
|
+
updated: exports.unixTimestamp2000Schema.optional(),
|
|
69
91
|
});
|
|
70
92
|
exports.savedDBEntitySchema = objectSchema({
|
|
71
93
|
id: exports.stringSchema,
|
|
72
|
-
created: exports.
|
|
73
|
-
updated: exports.
|
|
94
|
+
created: exports.unixTimestamp2000Schema,
|
|
95
|
+
updated: exports.unixTimestamp2000Schema,
|
|
74
96
|
});
|
package/package.json
CHANGED
package/src/bin/json2env.ts
CHANGED
|
@@ -19,6 +19,11 @@ runScript(() => {
|
|
|
19
19
|
desc: 'Populate $BASH_ENV file if BASH_ENV env variable exists',
|
|
20
20
|
default: true,
|
|
21
21
|
},
|
|
22
|
+
githubEnv: {
|
|
23
|
+
type: 'boolean',
|
|
24
|
+
desc: 'Populate $GITHUB_ENV file if GITHUB_ENV env variable exists',
|
|
25
|
+
default: true,
|
|
26
|
+
},
|
|
22
27
|
fail: {
|
|
23
28
|
type: 'boolean',
|
|
24
29
|
desc: 'Fail (exit status 1) on non-existing input file',
|
|
@@ -32,7 +37,7 @@ runScript(() => {
|
|
|
32
37
|
},
|
|
33
38
|
})
|
|
34
39
|
|
|
35
|
-
const { _: args, prefix, saveEnvFile, bashEnv, fail, debug, silent } = argv
|
|
40
|
+
const { _: args, prefix, saveEnvFile, bashEnv, githubEnv, fail, debug, silent } = argv
|
|
36
41
|
if (debug) console.log({ argv })
|
|
37
42
|
|
|
38
43
|
const jsonPath = args[0] as string
|
|
@@ -42,6 +47,7 @@ runScript(() => {
|
|
|
42
47
|
prefix,
|
|
43
48
|
saveEnvFile,
|
|
44
49
|
bashEnv,
|
|
50
|
+
githubEnv,
|
|
45
51
|
fail,
|
|
46
52
|
debug,
|
|
47
53
|
silent,
|
package/src/fs/json2env.ts
CHANGED
|
@@ -15,6 +15,11 @@ export interface Json2EnvOptions {
|
|
|
15
15
|
*/
|
|
16
16
|
bashEnv?: boolean
|
|
17
17
|
|
|
18
|
+
/**
|
|
19
|
+
* @default true
|
|
20
|
+
*/
|
|
21
|
+
githubEnv?: boolean
|
|
22
|
+
|
|
18
23
|
/**
|
|
19
24
|
* @default true
|
|
20
25
|
*/
|
|
@@ -27,11 +32,12 @@ export interface Json2EnvOptions {
|
|
|
27
32
|
const JSON2ENV_OPT_DEF: Partial<Json2EnvOptions> = {
|
|
28
33
|
saveEnvFile: true,
|
|
29
34
|
bashEnv: true,
|
|
35
|
+
githubEnv: true,
|
|
30
36
|
fail: true,
|
|
31
37
|
}
|
|
32
38
|
|
|
33
39
|
export function json2env(opt: Json2EnvOptions): void {
|
|
34
|
-
const { jsonPath, prefix, saveEnvFile, bashEnv, fail, debug, silent } = {
|
|
40
|
+
const { jsonPath, prefix, saveEnvFile, bashEnv, githubEnv, fail, debug, silent } = {
|
|
35
41
|
...JSON2ENV_OPT_DEF,
|
|
36
42
|
...opt,
|
|
37
43
|
}
|
|
@@ -56,8 +62,10 @@ export function json2env(opt: Json2EnvOptions): void {
|
|
|
56
62
|
const json = fs.readJsonSync(jsonPath)
|
|
57
63
|
|
|
58
64
|
const exportStr = objectToShellExport(json, prefix)
|
|
65
|
+
const githubStr = objectToGithubActionsEnv(json, prefix)
|
|
66
|
+
|
|
59
67
|
if (debug) {
|
|
60
|
-
console.log(json, exportStr)
|
|
68
|
+
console.log(json, exportStr, githubStr)
|
|
61
69
|
}
|
|
62
70
|
|
|
63
71
|
if (saveEnvFile) {
|
|
@@ -73,6 +81,10 @@ export function json2env(opt: Json2EnvOptions): void {
|
|
|
73
81
|
if (bashEnv) {
|
|
74
82
|
appendBashEnv(exportStr)
|
|
75
83
|
}
|
|
84
|
+
|
|
85
|
+
if (githubEnv) {
|
|
86
|
+
appendGithubEnv(githubStr)
|
|
87
|
+
}
|
|
76
88
|
}
|
|
77
89
|
|
|
78
90
|
function appendBashEnv(exportStr: string): void {
|
|
@@ -84,6 +96,15 @@ function appendBashEnv(exportStr: string): void {
|
|
|
84
96
|
}
|
|
85
97
|
}
|
|
86
98
|
|
|
99
|
+
function appendGithubEnv(exportStr: string): void {
|
|
100
|
+
const { GITHUB_ENV } = process.env
|
|
101
|
+
if (GITHUB_ENV) {
|
|
102
|
+
fs.appendFileSync(GITHUB_ENV, exportStr + '\n')
|
|
103
|
+
|
|
104
|
+
console.log(`GITHUB_ENV file appended (${dimGrey(GITHUB_ENV)})`)
|
|
105
|
+
}
|
|
106
|
+
}
|
|
107
|
+
|
|
87
108
|
/**
|
|
88
109
|
* Turns Object with keys/values into a *.sh script that exports all keys as values.
|
|
89
110
|
*
|
|
@@ -106,3 +127,26 @@ export function objectToShellExport(o: any, prefix = ''): string {
|
|
|
106
127
|
.filter(Boolean)
|
|
107
128
|
.join('\n')
|
|
108
129
|
}
|
|
130
|
+
|
|
131
|
+
/**
|
|
132
|
+
* Turns Object with keys/values into a file of key-value pairs
|
|
133
|
+
*
|
|
134
|
+
* @example
|
|
135
|
+
* { a: 'b', b: 'c'}
|
|
136
|
+
*
|
|
137
|
+
* will turn into:
|
|
138
|
+
*
|
|
139
|
+
* a=b
|
|
140
|
+
* b=c
|
|
141
|
+
*/
|
|
142
|
+
export function objectToGithubActionsEnv(o: any, prefix = ''): string {
|
|
143
|
+
return Object.keys(o)
|
|
144
|
+
.map(k => {
|
|
145
|
+
const v = o[k]
|
|
146
|
+
if (v) {
|
|
147
|
+
return `${prefix}${k}=${v}`
|
|
148
|
+
}
|
|
149
|
+
})
|
|
150
|
+
.filter(Boolean)
|
|
151
|
+
.join('\n')
|
|
152
|
+
}
|
package/src/got/getGot.ts
CHANGED
|
@@ -207,9 +207,9 @@ function gotBeforeRetryHook(opt: GetGotOptions): BeforeRetryHook {
|
|
|
207
207
|
|
|
208
208
|
if (statusCode && statusCode < 300) {
|
|
209
209
|
// todo: possibly remove the log message completely in the future
|
|
210
|
-
opt.logger!.log(
|
|
211
|
-
|
|
212
|
-
)
|
|
210
|
+
// opt.logger!.log(
|
|
211
|
+
// `skipping got.beforeRetry hook as statusCode is ${statusCode}, err.msg is ${err?.message}`,
|
|
212
|
+
// )
|
|
213
213
|
return
|
|
214
214
|
}
|
|
215
215
|
|
|
@@ -284,6 +284,11 @@ function gotAfterResponseHook(opt: GetGotOptions = {}): AfterResponseHook {
|
|
|
284
284
|
}
|
|
285
285
|
|
|
286
286
|
function getShortUrl(opt: GetGotOptions, url: URL, prefixUrl?: string): string {
|
|
287
|
+
if (url.password) {
|
|
288
|
+
url = new URL(url.toString()) // prevent original url mutation
|
|
289
|
+
url.password = '[redacted]'
|
|
290
|
+
}
|
|
291
|
+
|
|
287
292
|
let shortUrl = url.toString()
|
|
288
293
|
|
|
289
294
|
if (opt.logWithSearchParams === false) {
|
|
@@ -57,8 +57,31 @@ export const SLUG_PATTERN = /^[a-z0-9-]*$/
|
|
|
57
57
|
*/
|
|
58
58
|
export const slugSchema = stringSchema.regex(/^[a-z0-9-]{1,255}$/)
|
|
59
59
|
|
|
60
|
-
|
|
61
|
-
|
|
60
|
+
const TS_2500 = 16725225600 // 2500-01-01
|
|
61
|
+
const TS_2000 = 946684800 // 2000-01-01
|
|
62
|
+
|
|
63
|
+
/**
|
|
64
|
+
* Between years 1970 and 2050
|
|
65
|
+
*/
|
|
66
|
+
export const unixTimestampSchema = numberSchema.integer().min(0).max(TS_2500)
|
|
67
|
+
/**
|
|
68
|
+
* Between years 2000 and 2050
|
|
69
|
+
*/
|
|
70
|
+
export const unixTimestamp2000Schema = numberSchema.integer().min(0).min(TS_2000).max(TS_2500)
|
|
71
|
+
/**
|
|
72
|
+
* Between years 1970 and 2050
|
|
73
|
+
*/
|
|
74
|
+
export const unixTimestampMillisSchema = numberSchema
|
|
75
|
+
.integer()
|
|
76
|
+
.min(0)
|
|
77
|
+
.max(TS_2500 * 1000)
|
|
78
|
+
/**
|
|
79
|
+
* Between years 2000 and 2050
|
|
80
|
+
*/
|
|
81
|
+
export const unixTimestampMillis2000Schema = numberSchema
|
|
82
|
+
.integer()
|
|
83
|
+
.min(TS_2000 * 1000)
|
|
84
|
+
.max(TS_2500 * 1000)
|
|
62
85
|
|
|
63
86
|
// 2
|
|
64
87
|
export const verSchema = numberSchema.optional().integer().min(1).max(100)
|
|
@@ -88,12 +111,12 @@ export const ipAddressSchema = stringSchema.ip()
|
|
|
88
111
|
|
|
89
112
|
export const baseDBEntitySchema = objectSchema<BaseDBEntity>({
|
|
90
113
|
id: stringSchema.optional(),
|
|
91
|
-
created:
|
|
92
|
-
updated:
|
|
114
|
+
created: unixTimestamp2000Schema.optional(),
|
|
115
|
+
updated: unixTimestamp2000Schema.optional(),
|
|
93
116
|
})
|
|
94
117
|
|
|
95
118
|
export const savedDBEntitySchema = objectSchema<SavedDBEntity>({
|
|
96
119
|
id: stringSchema,
|
|
97
|
-
created:
|
|
98
|
-
updated:
|
|
120
|
+
created: unixTimestamp2000Schema,
|
|
121
|
+
updated: unixTimestamp2000Schema,
|
|
99
122
|
})
|