@wener/common 1.0.4 → 2.0.1
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/lib/cn/DivisionCode.js +55 -32
- package/lib/cn/DivisionCode.test.js +140 -0
- package/lib/cn/Mod11Checksum.js +80 -37
- package/lib/cn/Mod31Checksum.js +89 -40
- package/lib/cn/ResidentIdentityCardNumber.js +16 -16
- package/lib/cn/ResidentIdentityCardNumber.test.js +21 -0
- package/lib/cn/UnifiedSocialCreditCode.js +32 -26
- package/lib/cn/UnifiedSocialCreditCode.test.js +16 -0
- package/lib/cn/formatDate.js +5 -7
- package/lib/cn/index.js +0 -1
- package/lib/cn/parseSex.js +0 -2
- package/lib/cn/types.d.js +0 -2
- package/lib/consola/createStandardConsolaReporter.js +18 -0
- package/lib/consola/formatLogObject.js +226 -0
- package/lib/consola/index.js +2 -0
- package/lib/data/formatSort.js +5 -6
- package/lib/data/formatSort.test.js +34 -0
- package/lib/data/index.js +0 -1
- package/lib/data/maybeNumber.js +11 -5
- package/lib/data/parseSort.js +28 -22
- package/lib/data/parseSort.test.js +188 -0
- package/lib/data/resolvePagination.js +27 -16
- package/lib/data/resolvePagination.test.js +232 -0
- package/lib/data/types.d.js +0 -2
- package/lib/index.js +0 -1
- package/lib/jsonschema/JsonSchema.js +80 -54
- package/lib/jsonschema/JsonSchema.test.js +137 -0
- package/lib/jsonschema/index.js +0 -1
- package/lib/jsonschema/types.d.js +5 -3
- package/lib/meta/defineFileType.js +103 -20
- package/lib/meta/defineInit.js +250 -31
- package/lib/meta/defineMetadata.js +140 -24
- package/lib/meta/defineMetadata.test.js +13 -0
- package/lib/meta/index.js +0 -1
- package/lib/password/PHC.js +87 -63
- package/lib/password/PHC.test.js +539 -0
- package/lib/password/Password.js +291 -29
- package/lib/password/Password.test.js +362 -0
- package/lib/password/createArgon2PasswordAlgorithm.js +191 -35
- package/lib/password/createBase64PasswordAlgorithm.js +141 -8
- package/lib/password/createBcryptPasswordAlgorithm.js +168 -13
- package/lib/password/createPBKDF2PasswordAlgorithm.js +228 -46
- package/lib/password/createScryptPasswordAlgorithm.js +211 -55
- package/lib/password/index.js +0 -1
- package/lib/password/server/index.js +0 -1
- package/lib/resource/Identifiable.js +1 -0
- package/lib/resource/getTitleOfResource.js +10 -0
- package/lib/resource/index.js +1 -0
- package/lib/resource/schema/AnyResourceSchema.js +89 -0
- package/lib/resource/schema/BaseResourceSchema.js +29 -0
- package/lib/resource/schema/ResourceActionType.js +118 -0
- package/lib/resource/schema/ResourceStatus.js +93 -0
- package/lib/resource/schema/ResourceType.js +24 -0
- package/lib/resource/schema/SchemaRegistry.js +38 -0
- package/lib/resource/schema/SexType.js +10 -0
- package/lib/resource/schema/types.js +89 -0
- package/lib/resource/schema/types.test.js +14 -0
- package/lib/schema/TypeSchema.d.js +1 -0
- package/lib/schema/createSchemaData.js +173 -0
- package/lib/schema/findJsonSchemaByPath.js +49 -0
- package/lib/schema/getSchemaCache.js +11 -0
- package/lib/schema/getSchemaOptions.js +24 -0
- package/lib/schema/index.js +5 -0
- package/lib/schema/toJsonSchema.js +441 -0
- package/lib/schema/toJsonSchema.test.js +27 -0
- package/lib/schema/validate.js +124 -0
- package/lib/search/AdvanceSearch.js +0 -1
- package/lib/search/AdvanceSearch.test.js +435 -0
- package/lib/search/formatAdvanceSearch.js +41 -27
- package/lib/search/index.js +0 -1
- package/lib/search/optimizeAdvanceSearch.js +79 -25
- package/lib/search/parseAdvanceSearch.js +5 -5
- package/lib/search/parser.d.js +0 -2
- package/lib/search/parser.js +97 -74
- package/lib/search/types.d.js +0 -2
- package/lib/tools/generateSchema.js +201 -0
- package/lib/tools/renderJsonSchemaToMarkdownDoc.js +143 -55
- package/package.json +30 -9
- package/src/consola/createStandardConsolaReporter.ts +31 -0
- package/src/consola/formatLogObject.ts +171 -0
- package/src/consola/index.ts +2 -0
- package/src/data/maybeNumber.ts +5 -1
- package/src/data/resolvePagination.test.ts +1 -1
- package/src/data/resolvePagination.ts +18 -7
- package/src/data/types.d.ts +12 -0
- package/src/jsonschema/JsonSchema.test.ts +17 -0
- package/src/jsonschema/JsonSchema.ts +4 -4
- package/src/jsonschema/types.d.ts +63 -12
- package/src/resource/Identifiable.ts +3 -0
- package/src/resource/getTitleOfResource.tsx +6 -0
- package/src/resource/index.ts +3 -0
- package/src/resource/schema/AnyResourceSchema.ts +113 -0
- package/src/resource/schema/BaseResourceSchema.ts +32 -0
- package/src/resource/schema/ResourceActionType.ts +123 -0
- package/src/resource/schema/ResourceStatus.ts +94 -0
- package/src/resource/schema/ResourceType.ts +25 -0
- package/src/resource/schema/SchemaRegistry.ts +42 -0
- package/src/resource/schema/SexType.ts +13 -0
- package/src/resource/schema/types.test.ts +18 -0
- package/src/resource/schema/types.ts +105 -0
- package/src/schema/TypeSchema.d.ts +32 -0
- package/src/schema/createSchemaData.ts +81 -0
- package/src/schema/findJsonSchemaByPath.ts +37 -0
- package/src/schema/getSchemaCache.ts +21 -0
- package/src/schema/getSchemaOptions.ts +24 -0
- package/src/schema/index.ts +6 -0
- package/src/schema/toJsonSchema.test.ts +37 -0
- package/src/schema/toJsonSchema.ts +200 -0
- package/src/schema/validate.ts +135 -0
- package/src/tools/generateSchema.ts +39 -0
- package/lib/cn/DivisionCode.js.map +0 -1
- package/lib/cn/Mod11Checksum.js.map +0 -1
- package/lib/cn/Mod31Checksum.js.map +0 -1
- package/lib/cn/ResidentIdentityCardNumber.js.map +0 -1
- package/lib/cn/UnifiedSocialCreditCode.js.map +0 -1
- package/lib/cn/formatDate.js.map +0 -1
- package/lib/cn/index.js.map +0 -1
- package/lib/cn/parseSex.js.map +0 -1
- package/lib/cn/types.d.js.map +0 -1
- package/lib/data/formatSort.js.map +0 -1
- package/lib/data/index.js.map +0 -1
- package/lib/data/maybeNumber.js.map +0 -1
- package/lib/data/parseSort.js.map +0 -1
- package/lib/data/resolvePagination.js.map +0 -1
- package/lib/data/types.d.js.map +0 -1
- package/lib/index.js.map +0 -1
- package/lib/jsonschema/JsonSchema.js.map +0 -1
- package/lib/jsonschema/index.js.map +0 -1
- package/lib/jsonschema/types.d.js.map +0 -1
- package/lib/meta/defineFileType.js.map +0 -1
- package/lib/meta/defineInit.js.map +0 -1
- package/lib/meta/defineMetadata.js.map +0 -1
- package/lib/meta/index.js.map +0 -1
- package/lib/password/PHC.js.map +0 -1
- package/lib/password/Password.js.map +0 -1
- package/lib/password/createArgon2PasswordAlgorithm.js.map +0 -1
- package/lib/password/createBase64PasswordAlgorithm.js.map +0 -1
- package/lib/password/createBcryptPasswordAlgorithm.js.map +0 -1
- package/lib/password/createPBKDF2PasswordAlgorithm.js.map +0 -1
- package/lib/password/createScryptPasswordAlgorithm.js.map +0 -1
- package/lib/password/index.js.map +0 -1
- package/lib/password/server/index.js.map +0 -1
- package/lib/search/AdvanceSearch.js.map +0 -1
- package/lib/search/formatAdvanceSearch.js.map +0 -1
- package/lib/search/index.js.map +0 -1
- package/lib/search/optimizeAdvanceSearch.js.map +0 -1
- package/lib/search/parseAdvanceSearch.js.map +0 -1
- package/lib/search/parser.d.js.map +0 -1
- package/lib/search/parser.js.map +0 -1
- package/lib/search/types.d.js.map +0 -1
- package/lib/tools/renderJsonSchemaToMarkdownDoc.js.map +0 -1
package/lib/password/PHC.js
CHANGED
|
@@ -1,31 +1,44 @@
|
|
|
1
|
-
|
|
1
|
+
function _instanceof(left, right) {
|
|
2
|
+
if (right != null && typeof Symbol !== "undefined" && right[Symbol.hasInstance]) {
|
|
3
|
+
return !!right[Symbol.hasInstance](left);
|
|
4
|
+
} else {
|
|
5
|
+
return left instanceof right;
|
|
6
|
+
}
|
|
7
|
+
}
|
|
8
|
+
function _type_of(obj) {
|
|
9
|
+
"@swc/helpers - typeof";
|
|
10
|
+
return obj && typeof Symbol !== "undefined" && obj.constructor === Symbol ? "symbol" : typeof obj;
|
|
11
|
+
}
|
|
12
|
+
import { ArrayBuffers } from '@wener/utils';
|
|
2
13
|
(function(PHC) {
|
|
3
14
|
// https://github.com/simonepri/phc-format/blob/master/index.js
|
|
4
|
-
|
|
5
|
-
|
|
6
|
-
|
|
7
|
-
|
|
8
|
-
|
|
9
|
-
|
|
10
|
-
|
|
11
|
-
|
|
12
|
-
|
|
13
|
-
return v
|
|
15
|
+
var idRegex = /^[a-z0-9-]{1,32}$/;
|
|
16
|
+
var nameRegex = /^[a-z0-9-]{1,32}$/;
|
|
17
|
+
var valueRegex = /^[a-zA-Z0-9/+.-]+$/;
|
|
18
|
+
var b64Regex = /^([a-zA-Z0-9/+.-]+|)$/;
|
|
19
|
+
var decimalRegex = /^((-)?[1-9]\d*|0)$/;
|
|
20
|
+
var versionRegex = /^v=(\d+)$/;
|
|
21
|
+
var fromBase64 = ArrayBuffers.fromBase64;
|
|
22
|
+
var toBase64 = ArrayBuffers.toBase64;
|
|
23
|
+
var isBuffer = function(v) {
|
|
24
|
+
return _instanceof(v, Uint8Array);
|
|
14
25
|
};
|
|
15
26
|
function objToKeyVal(obj) {
|
|
16
|
-
return objectKeys(obj).map((k)
|
|
27
|
+
return objectKeys(obj).map(function(k) {
|
|
28
|
+
return [
|
|
17
29
|
k,
|
|
18
30
|
obj[k]
|
|
19
|
-
].join('=')
|
|
31
|
+
].join('=');
|
|
32
|
+
}).join(',');
|
|
20
33
|
}
|
|
21
34
|
function keyValtoObj(str) {
|
|
22
|
-
|
|
23
|
-
str.split(',').forEach((ps)
|
|
24
|
-
|
|
35
|
+
var obj = {};
|
|
36
|
+
str.split(',').forEach(function(ps) {
|
|
37
|
+
var pss = ps.split('=');
|
|
25
38
|
if (pss.length < 2) {
|
|
26
|
-
throw new TypeError(
|
|
39
|
+
throw new TypeError("params must be in the format name=value");
|
|
27
40
|
}
|
|
28
|
-
|
|
41
|
+
var key = pss.shift();
|
|
29
42
|
if (key !== undefined) {
|
|
30
43
|
obj[key] = pss.join('=');
|
|
31
44
|
}
|
|
@@ -37,13 +50,15 @@ import { ArrayBuffers } from "@wener/utils";
|
|
|
37
50
|
}
|
|
38
51
|
function objectValues(object) {
|
|
39
52
|
if (typeof Object.values === 'function') return Object.values(object);
|
|
40
|
-
return objectKeys(object).map((k)
|
|
53
|
+
return objectKeys(object).map(function(k) {
|
|
54
|
+
return object[k];
|
|
55
|
+
});
|
|
41
56
|
}
|
|
42
57
|
function serialize(opts) {
|
|
43
|
-
|
|
58
|
+
var fields = [
|
|
44
59
|
''
|
|
45
60
|
];
|
|
46
|
-
if (typeof opts !== 'object' || opts === null) {
|
|
61
|
+
if ((typeof opts === "undefined" ? "undefined" : _type_of(opts)) !== 'object' || opts === null) {
|
|
47
62
|
throw new TypeError('opts must be an object');
|
|
48
63
|
}
|
|
49
64
|
// Identifier Validation
|
|
@@ -51,41 +66,47 @@ import { ArrayBuffers } from "@wener/utils";
|
|
|
51
66
|
throw new TypeError('id must be a string');
|
|
52
67
|
}
|
|
53
68
|
if (!idRegex.test(opts.id)) {
|
|
54
|
-
throw new TypeError(
|
|
69
|
+
throw new TypeError("id must satisfy ".concat(idRegex));
|
|
55
70
|
}
|
|
56
71
|
fields.push(opts.id);
|
|
57
72
|
if (typeof opts.version !== 'undefined') {
|
|
58
73
|
if (typeof opts.version !== 'number' || opts.version < 0 || !Number.isInteger(opts.version)) {
|
|
59
74
|
throw new TypeError('version must be a positive integer number');
|
|
60
75
|
}
|
|
61
|
-
fields.push(
|
|
76
|
+
fields.push("v=".concat(opts.version));
|
|
62
77
|
}
|
|
63
78
|
// Parameters Validation
|
|
64
79
|
if (typeof opts.params !== 'undefined') {
|
|
65
|
-
if (
|
|
80
|
+
if (_type_of(opts.params) !== 'object' || opts.params === null) {
|
|
66
81
|
throw new TypeError('params must be an object');
|
|
67
82
|
}
|
|
68
|
-
|
|
69
|
-
if (!pk.every((p)
|
|
70
|
-
|
|
83
|
+
var pk = objectKeys(opts.params);
|
|
84
|
+
if (!pk.every(function(p) {
|
|
85
|
+
return nameRegex.test(p.toString());
|
|
86
|
+
})) {
|
|
87
|
+
throw new TypeError("params names must satisfy ".concat(nameRegex));
|
|
71
88
|
}
|
|
72
89
|
// Convert Numbers into Numeric Strings and Buffers into B64 encoded strings.
|
|
73
|
-
pk.forEach((k)
|
|
74
|
-
|
|
90
|
+
pk.forEach(function(k) {
|
|
91
|
+
var value = opts.params[k];
|
|
75
92
|
if (typeof value === 'number') {
|
|
76
93
|
opts.params[k] = value.toString();
|
|
77
|
-
} else if (value
|
|
94
|
+
} else if (_instanceof(value, Uint8Array)) {
|
|
78
95
|
opts.params[k] = toBase64(value).split('=')[0];
|
|
79
96
|
}
|
|
80
97
|
});
|
|
81
|
-
|
|
82
|
-
if (!pv.every((v)
|
|
98
|
+
var pv = objectValues(opts.params);
|
|
99
|
+
if (!pv.every(function(v) {
|
|
100
|
+
return typeof v === 'string';
|
|
101
|
+
})) {
|
|
83
102
|
throw new TypeError('params values must be strings');
|
|
84
103
|
}
|
|
85
|
-
if (!pv.every((v)
|
|
86
|
-
|
|
104
|
+
if (!pv.every(function(v) {
|
|
105
|
+
return valueRegex.test(v);
|
|
106
|
+
})) {
|
|
107
|
+
throw new TypeError("params values must satisfy ".concat(valueRegex));
|
|
87
108
|
}
|
|
88
|
-
|
|
109
|
+
var strpar = objToKeyVal(opts.params);
|
|
89
110
|
fields.push(strpar);
|
|
90
111
|
}
|
|
91
112
|
if (typeof opts.salt !== 'undefined') {
|
|
@@ -103,7 +124,7 @@ import { ArrayBuffers } from "@wener/utils";
|
|
|
103
124
|
}
|
|
104
125
|
}
|
|
105
126
|
// Create the PHC formatted string
|
|
106
|
-
|
|
127
|
+
var phcstr = fields.join('$');
|
|
107
128
|
return phcstr;
|
|
108
129
|
}
|
|
109
130
|
/**
|
|
@@ -118,58 +139,63 @@ import { ArrayBuffers } from "@wener/utils";
|
|
|
118
139
|
if (phcstr[0] !== '$') {
|
|
119
140
|
throw new TypeError('pchstr must contain a $ as first char');
|
|
120
141
|
}
|
|
121
|
-
|
|
142
|
+
var fields = phcstr.split('$');
|
|
122
143
|
// Remove first empty $
|
|
123
144
|
fields.shift();
|
|
124
145
|
// Parse Fields
|
|
125
|
-
|
|
146
|
+
var maxf = 5;
|
|
126
147
|
if (!versionRegex.test(fields[1])) maxf--;
|
|
127
148
|
if (fields.length > maxf) {
|
|
128
|
-
throw new TypeError(
|
|
149
|
+
throw new TypeError("pchstr contains too many fileds: ".concat(fields.length, "/").concat(maxf));
|
|
129
150
|
}
|
|
130
151
|
// Parse Identifier
|
|
131
|
-
|
|
152
|
+
var id = fields.shift();
|
|
132
153
|
if (!id || !idRegex.test(id)) {
|
|
133
|
-
throw new TypeError(
|
|
154
|
+
throw new TypeError("id must satisfy ".concat(idRegex));
|
|
134
155
|
}
|
|
135
|
-
|
|
156
|
+
var version;
|
|
136
157
|
// Parse Version
|
|
137
158
|
if (fields[0] && versionRegex.test(fields[0])) {
|
|
138
|
-
|
|
159
|
+
var _fields_shift;
|
|
160
|
+
var versionMatch = (_fields_shift = fields.shift()) === null || _fields_shift === void 0 ? void 0 : _fields_shift.match(versionRegex);
|
|
139
161
|
version = versionMatch ? parseInt(versionMatch[1], 10) : undefined;
|
|
140
162
|
}
|
|
141
|
-
|
|
142
|
-
|
|
163
|
+
var hash;
|
|
164
|
+
var salt;
|
|
143
165
|
if (fields[fields.length - 1] && b64Regex.test(fields[fields.length - 1])) {
|
|
144
166
|
if (fields.length > 1 && b64Regex.test(fields[fields.length - 2])) {
|
|
145
167
|
// Parse Hash
|
|
146
|
-
|
|
168
|
+
var hashStr = fields.pop();
|
|
147
169
|
if (hashStr) hash = fromBase64(hashStr);
|
|
148
170
|
// Parse Salt
|
|
149
|
-
|
|
171
|
+
var saltStr = fields.pop();
|
|
150
172
|
if (saltStr !== undefined) salt = fromBase64(saltStr);
|
|
151
173
|
} else {
|
|
152
174
|
// Parse Salt
|
|
153
|
-
|
|
154
|
-
if (
|
|
175
|
+
var saltStr1 = fields.pop();
|
|
176
|
+
if (saltStr1 !== undefined) salt = fromBase64(saltStr1);
|
|
155
177
|
}
|
|
156
178
|
}
|
|
157
179
|
// Parse Parameters
|
|
158
|
-
|
|
180
|
+
var params;
|
|
159
181
|
if (fields.length > 0) {
|
|
160
|
-
|
|
182
|
+
var parstr = fields.pop();
|
|
161
183
|
if (parstr) {
|
|
162
184
|
params = keyValtoObj(parstr);
|
|
163
|
-
if (!Object.keys(params).every((p)
|
|
164
|
-
|
|
185
|
+
if (!Object.keys(params).every(function(p) {
|
|
186
|
+
return nameRegex.test(p);
|
|
187
|
+
})) {
|
|
188
|
+
throw new TypeError("params names must satisfy ".concat(nameRegex, "}"));
|
|
165
189
|
}
|
|
166
|
-
|
|
167
|
-
if (!pv.every((v)
|
|
168
|
-
|
|
190
|
+
var pv = Object.values(params);
|
|
191
|
+
if (!pv.every(function(v) {
|
|
192
|
+
return valueRegex.test(String(v));
|
|
193
|
+
})) {
|
|
194
|
+
throw new TypeError("params values must satisfy ".concat(valueRegex));
|
|
169
195
|
}
|
|
170
196
|
// Convert Decimal Strings into Numbers
|
|
171
|
-
Object.keys(params).forEach((k)
|
|
172
|
-
|
|
197
|
+
Object.keys(params).forEach(function(k) {
|
|
198
|
+
var value = params[k];
|
|
173
199
|
if (typeof value === 'string' && decimalRegex.test(value)) {
|
|
174
200
|
params[k] = parseInt(value, 10);
|
|
175
201
|
}
|
|
@@ -177,11 +203,11 @@ import { ArrayBuffers } from "@wener/utils";
|
|
|
177
203
|
}
|
|
178
204
|
}
|
|
179
205
|
if (fields.length > 0) {
|
|
180
|
-
throw new TypeError(
|
|
206
|
+
throw new TypeError("pchstr contains unrecognized fileds: ".concat(fields));
|
|
181
207
|
}
|
|
182
208
|
// Build the output object
|
|
183
|
-
|
|
184
|
-
id
|
|
209
|
+
var phcobj = {
|
|
210
|
+
id: id
|
|
185
211
|
};
|
|
186
212
|
if (version !== undefined) phcobj.version = version;
|
|
187
213
|
if (params) phcobj.params = params;
|
|
@@ -196,5 +222,3 @@ import { ArrayBuffers } from "@wener/utils";
|
|
|
196
222
|
*/ PHC.deserialize = deserialize;
|
|
197
223
|
})(PHC || (PHC = {}));
|
|
198
224
|
export var PHC;
|
|
199
|
-
|
|
200
|
-
//# sourceMappingURL=PHC.js.map
|