@naturalcycles/nodejs-lib 12.79.0 → 12.80.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.
@@ -16,6 +16,14 @@ export declare function objectSchema<IN, OUT = IN>(schema?: {
16
16
  export declare function oneOfSchema<T = any>(...schemas: AnySchemaTyped<any>[]): AlternativesSchemaTyped<T>;
17
17
  export declare const anySchema: import("joi").AnySchema;
18
18
  export declare const anyObjectSchema: import("joi").ObjectSchema<any>;
19
+ export declare const BASE62_REGEX: RegExp;
20
+ export declare const BASE64_REGEX: RegExp;
21
+ export declare const BASE64URL_REGEX: RegExp;
22
+ export declare const base62Schema: import("./string.extensions").ExtendedStringSchema;
23
+ export declare const base64Schema: import("./string.extensions").ExtendedStringSchema;
24
+ export declare const base64UrlSchema: import("./string.extensions").ExtendedStringSchema;
25
+ export declare const JWT_REGEX: RegExp;
26
+ export declare const jwtSchema: import("./string.extensions").ExtendedStringSchema;
19
27
  /**
20
28
  * [a-zA-Z0-9_]*
21
29
  * 6-64 length
@@ -24,13 +32,10 @@ export declare const idSchema: import("./string.extensions").ExtendedStringSchem
24
32
  export declare const idBase62Schema: import("./string.extensions").ExtendedStringSchema;
25
33
  export declare const idBase64Schema: import("./string.extensions").ExtendedStringSchema;
26
34
  export declare const idBase64UrlSchema: import("./string.extensions").ExtendedStringSchema;
27
- export declare const base62Schema: import("./string.extensions").ExtendedStringSchema;
28
- export declare const base64Schema: import("./string.extensions").ExtendedStringSchema;
29
- export declare const base64UrlSchema: import("./string.extensions").ExtendedStringSchema;
30
35
  /**
31
36
  * `_` should NOT be allowed to be able to use slug-ids as part of natural ids with `_` separator.
32
37
  */
33
- export declare const SLUG_PATTERN: RegExp;
38
+ export declare const SLUG_REGEX: RegExp;
34
39
  /**
35
40
  * "Slug" - a valid URL, filename, etc.
36
41
  */
@@ -59,7 +64,7 @@ export declare const emailSchema: import("./string.extensions").ExtendedStringSc
59
64
  /**
60
65
  * Pattern is simplified for our use, it's not a canonical SemVer.
61
66
  */
62
- export declare const SEM_VER_PATTERN: RegExp;
67
+ export declare const SEM_VER_REGEX: RegExp;
63
68
  export declare const semVerSchema: import("./string.extensions").ExtendedStringSchema;
64
69
  export declare const userAgentSchema: import("./string.extensions").ExtendedStringSchema;
65
70
  export declare const utcOffsetSchema: import("./number.extensions").ExtendedNumberSchema;
@@ -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.unixTimestampMillis2000Schema = exports.unixTimestampMillisSchema = exports.unixTimestamp2000Schema = exports.unixTimestampSchema = exports.slugSchema = exports.SLUG_PATTERN = exports.base64UrlSchema = exports.base64Schema = exports.base62Schema = exports.idBase64UrlSchema = exports.idBase64Schema = exports.idBase62Schema = 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_REGEX = exports.emailSchema = exports.verSchema = exports.unixTimestampMillis2000Schema = exports.unixTimestampMillisSchema = exports.unixTimestamp2000Schema = exports.unixTimestampSchema = exports.slugSchema = exports.SLUG_REGEX = exports.idBase64UrlSchema = exports.idBase64Schema = exports.idBase62Schema = exports.idSchema = exports.jwtSchema = exports.JWT_REGEX = exports.base64UrlSchema = exports.base64Schema = exports.base62Schema = exports.BASE64URL_REGEX = exports.BASE64_REGEX = exports.BASE62_REGEX = 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);
@@ -26,26 +26,31 @@ function oneOfSchema(...schemas) {
26
26
  exports.oneOfSchema = oneOfSchema;
27
27
  exports.anySchema = joi_extensions_1.Joi.any();
28
28
  exports.anyObjectSchema = joi_extensions_1.Joi.object().options({ stripUnknown: false });
29
+ exports.BASE62_REGEX = /^[a-zA-Z0-9]+$/;
30
+ exports.BASE64_REGEX = /^[A-Za-z0-9+/]+={0,2}$/;
31
+ exports.BASE64URL_REGEX = /^[\w-/]+$/;
32
+ exports.base62Schema = exports.stringSchema.regex(exports.BASE62_REGEX);
33
+ exports.base64Schema = exports.stringSchema.regex(exports.BASE64_REGEX);
34
+ exports.base64UrlSchema = exports.stringSchema.regex(exports.BASE64URL_REGEX);
35
+ exports.JWT_REGEX = /^[\w-]+\.[\w-]+\.[\w-]+$/;
36
+ exports.jwtSchema = exports.stringSchema.regex(exports.JWT_REGEX);
29
37
  // 1g498efj5sder3324zer
30
38
  /**
31
39
  * [a-zA-Z0-9_]*
32
40
  * 6-64 length
33
41
  */
34
42
  exports.idSchema = exports.stringSchema.regex(/^[a-zA-Z0-9_]{6,64}$/);
35
- exports.idBase62Schema = exports.stringSchema.regex(/^[a-zA-Z0-9]{8,64}$/);
36
- exports.idBase64Schema = exports.stringSchema.regex(/^[a-zA-Z0-9+/]{8,64}$/);
37
- exports.idBase64UrlSchema = exports.stringSchema.regex(/^[a-zA-Z0-9-_]{8,64}$/);
38
- exports.base62Schema = exports.stringSchema.regex(/^[a-zA-Z0-9]+$/);
39
- exports.base64Schema = exports.stringSchema.regex(/^[a-zA-Z0-9+/]+$/);
40
- exports.base64UrlSchema = exports.stringSchema.regex(/^[a-zA-Z0-9-_]+$/);
43
+ exports.idBase62Schema = exports.base62Schema.min(8).max(64);
44
+ exports.idBase64Schema = exports.base64Schema.min(8).max(64);
45
+ exports.idBase64UrlSchema = exports.base64UrlSchema.min(8).max(64);
41
46
  /**
42
47
  * `_` should NOT be allowed to be able to use slug-ids as part of natural ids with `_` separator.
43
48
  */
44
- exports.SLUG_PATTERN = /^[a-z0-9-]*$/;
49
+ exports.SLUG_REGEX = /^[a-z0-9-]*$/;
45
50
  /**
46
51
  * "Slug" - a valid URL, filename, etc.
47
52
  */
48
- exports.slugSchema = exports.stringSchema.regex(/^[a-z0-9-_]{1,255}$/);
53
+ exports.slugSchema = exports.stringSchema.regex(exports.SLUG_REGEX).min(1).max(255);
49
54
  const TS_2500 = 16725225600; // 2500-01-01
50
55
  const TS_2000 = 946684800; // 2000-01-01
51
56
  /**
@@ -79,8 +84,8 @@ exports.emailSchema = exports.stringSchema.email().lowercase();
79
84
  /**
80
85
  * Pattern is simplified for our use, it's not a canonical SemVer.
81
86
  */
82
- exports.SEM_VER_PATTERN = /^[0-9]+\.[0-9]+\.[0-9]+$/;
83
- exports.semVerSchema = exports.stringSchema.regex(exports.SEM_VER_PATTERN);
87
+ exports.SEM_VER_REGEX = /^[0-9]+\.[0-9]+\.[0-9]+$/;
88
+ exports.semVerSchema = exports.stringSchema.regex(exports.SEM_VER_REGEX);
84
89
  // todo: .error(() => 'should be SemVer')
85
90
  exports.userAgentSchema = exports.stringSchema
86
91
  .min(5) // I've seen UA of `Android` (7 characters)
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@naturalcycles/nodejs-lib",
3
- "version": "12.79.0",
3
+ "version": "12.80.0",
4
4
  "scripts": {
5
5
  "prepare": "husky install",
6
6
  "docs-serve": "vuepress dev docs",
@@ -40,6 +40,16 @@ export function oneOfSchema<T = any>(
40
40
  export const anySchema = Joi.any()
41
41
  export const anyObjectSchema = Joi.object().options({ stripUnknown: false })
42
42
 
43
+ export const BASE62_REGEX = /^[a-zA-Z0-9]+$/
44
+ export const BASE64_REGEX = /^[A-Za-z0-9+/]+={0,2}$/
45
+ export const BASE64URL_REGEX = /^[\w-/]+$/
46
+ export const base62Schema = stringSchema.regex(BASE62_REGEX)
47
+ export const base64Schema = stringSchema.regex(BASE64_REGEX)
48
+ export const base64UrlSchema = stringSchema.regex(BASE64URL_REGEX)
49
+
50
+ export const JWT_REGEX = /^[\w-]+\.[\w-]+\.[\w-]+$/
51
+ export const jwtSchema = stringSchema.regex(JWT_REGEX)
52
+
43
53
  // 1g498efj5sder3324zer
44
54
  /**
45
55
  * [a-zA-Z0-9_]*
@@ -47,23 +57,19 @@ export const anyObjectSchema = Joi.object().options({ stripUnknown: false })
47
57
  */
48
58
  export const idSchema = stringSchema.regex(/^[a-zA-Z0-9_]{6,64}$/)
49
59
 
50
- export const idBase62Schema = stringSchema.regex(/^[a-zA-Z0-9]{8,64}$/)
51
- export const idBase64Schema = stringSchema.regex(/^[a-zA-Z0-9+/]{8,64}$/)
52
- export const idBase64UrlSchema = stringSchema.regex(/^[a-zA-Z0-9-_]{8,64}$/)
53
-
54
- export const base62Schema = stringSchema.regex(/^[a-zA-Z0-9]+$/)
55
- export const base64Schema = stringSchema.regex(/^[a-zA-Z0-9+/]+$/)
56
- export const base64UrlSchema = stringSchema.regex(/^[a-zA-Z0-9-_]+$/)
60
+ export const idBase62Schema = base62Schema.min(8).max(64)
61
+ export const idBase64Schema = base64Schema.min(8).max(64)
62
+ export const idBase64UrlSchema = base64UrlSchema.min(8).max(64)
57
63
 
58
64
  /**
59
65
  * `_` should NOT be allowed to be able to use slug-ids as part of natural ids with `_` separator.
60
66
  */
61
- export const SLUG_PATTERN = /^[a-z0-9-]*$/
67
+ export const SLUG_REGEX = /^[a-z0-9-]*$/
62
68
 
63
69
  /**
64
70
  * "Slug" - a valid URL, filename, etc.
65
71
  */
66
- export const slugSchema = stringSchema.regex(/^[a-z0-9-_]{1,255}$/)
72
+ export const slugSchema = stringSchema.regex(SLUG_REGEX).min(1).max(255)
67
73
 
68
74
  const TS_2500 = 16725225600 // 2500-01-01
69
75
  const TS_2000 = 946684800 // 2000-01-01
@@ -102,8 +108,8 @@ export const emailSchema = stringSchema.email().lowercase()
102
108
  /**
103
109
  * Pattern is simplified for our use, it's not a canonical SemVer.
104
110
  */
105
- export const SEM_VER_PATTERN = /^[0-9]+\.[0-9]+\.[0-9]+$/
106
- export const semVerSchema = stringSchema.regex(SEM_VER_PATTERN)
111
+ export const SEM_VER_REGEX = /^[0-9]+\.[0-9]+\.[0-9]+$/
112
+ export const semVerSchema = stringSchema.regex(SEM_VER_REGEX)
107
113
  // todo: .error(() => 'should be SemVer')
108
114
 
109
115
  export const userAgentSchema = stringSchema