@wener/common 1.0.5 → 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.
Files changed (152) hide show
  1. package/lib/cn/DivisionCode.js +55 -32
  2. package/lib/cn/DivisionCode.test.js +140 -0
  3. package/lib/cn/Mod11Checksum.js +80 -37
  4. package/lib/cn/Mod31Checksum.js +89 -40
  5. package/lib/cn/ResidentIdentityCardNumber.js +16 -16
  6. package/lib/cn/ResidentIdentityCardNumber.test.js +21 -0
  7. package/lib/cn/UnifiedSocialCreditCode.js +32 -26
  8. package/lib/cn/UnifiedSocialCreditCode.test.js +16 -0
  9. package/lib/cn/formatDate.js +5 -7
  10. package/lib/cn/index.js +0 -1
  11. package/lib/cn/parseSex.js +0 -2
  12. package/lib/cn/types.d.js +0 -2
  13. package/lib/consola/createStandardConsolaReporter.js +6 -6
  14. package/lib/consola/formatLogObject.js +133 -32
  15. package/lib/consola/index.js +0 -1
  16. package/lib/data/formatSort.js +5 -6
  17. package/lib/data/formatSort.test.js +34 -0
  18. package/lib/data/index.js +0 -1
  19. package/lib/data/maybeNumber.js +11 -5
  20. package/lib/data/parseSort.js +28 -22
  21. package/lib/data/parseSort.test.js +188 -0
  22. package/lib/data/resolvePagination.js +27 -16
  23. package/lib/data/resolvePagination.test.js +232 -0
  24. package/lib/data/types.d.js +0 -2
  25. package/lib/index.js +0 -1
  26. package/lib/jsonschema/JsonSchema.js +78 -52
  27. package/lib/jsonschema/JsonSchema.test.js +137 -0
  28. package/lib/jsonschema/index.js +0 -1
  29. package/lib/jsonschema/types.d.js +5 -3
  30. package/lib/meta/defineFileType.js +103 -20
  31. package/lib/meta/defineInit.js +250 -31
  32. package/lib/meta/defineMetadata.js +140 -24
  33. package/lib/meta/defineMetadata.test.js +13 -0
  34. package/lib/meta/index.js +0 -1
  35. package/lib/password/PHC.js +87 -63
  36. package/lib/password/PHC.test.js +539 -0
  37. package/lib/password/Password.js +291 -29
  38. package/lib/password/Password.test.js +362 -0
  39. package/lib/password/createArgon2PasswordAlgorithm.js +191 -35
  40. package/lib/password/createBase64PasswordAlgorithm.js +141 -8
  41. package/lib/password/createBcryptPasswordAlgorithm.js +168 -13
  42. package/lib/password/createPBKDF2PasswordAlgorithm.js +228 -46
  43. package/lib/password/createScryptPasswordAlgorithm.js +211 -55
  44. package/lib/password/index.js +0 -1
  45. package/lib/password/server/index.js +0 -1
  46. package/lib/resource/Identifiable.js +1 -0
  47. package/lib/resource/getTitleOfResource.js +10 -0
  48. package/lib/resource/index.js +1 -0
  49. package/lib/resource/schema/AnyResourceSchema.js +89 -0
  50. package/lib/resource/schema/BaseResourceSchema.js +29 -0
  51. package/lib/resource/schema/ResourceActionType.js +118 -0
  52. package/lib/resource/schema/ResourceStatus.js +93 -0
  53. package/lib/resource/schema/ResourceType.js +24 -0
  54. package/lib/resource/schema/SchemaRegistry.js +38 -0
  55. package/lib/resource/schema/SexType.js +10 -0
  56. package/lib/resource/schema/types.js +89 -0
  57. package/lib/resource/schema/types.test.js +14 -0
  58. package/lib/schema/TypeSchema.d.js +1 -0
  59. package/lib/schema/createSchemaData.js +173 -0
  60. package/lib/schema/findJsonSchemaByPath.js +49 -0
  61. package/lib/schema/getSchemaCache.js +11 -0
  62. package/lib/schema/getSchemaOptions.js +24 -0
  63. package/lib/schema/index.js +5 -0
  64. package/lib/schema/toJsonSchema.js +441 -0
  65. package/lib/schema/toJsonSchema.test.js +27 -0
  66. package/lib/schema/validate.js +124 -0
  67. package/lib/search/AdvanceSearch.js +0 -1
  68. package/lib/search/AdvanceSearch.test.js +435 -0
  69. package/lib/search/formatAdvanceSearch.js +41 -27
  70. package/lib/search/index.js +0 -1
  71. package/lib/search/optimizeAdvanceSearch.js +79 -25
  72. package/lib/search/parseAdvanceSearch.js +5 -5
  73. package/lib/search/parser.d.js +0 -2
  74. package/lib/search/parser.js +97 -74
  75. package/lib/search/types.d.js +0 -2
  76. package/lib/tools/generateSchema.js +197 -39
  77. package/lib/tools/renderJsonSchemaToMarkdownDoc.js +143 -55
  78. package/package.json +23 -11
  79. package/src/data/maybeNumber.ts +5 -1
  80. package/src/data/resolvePagination.test.ts +1 -1
  81. package/src/data/resolvePagination.ts +18 -7
  82. package/src/data/types.d.ts +12 -0
  83. package/src/jsonschema/JsonSchema.test.ts +17 -0
  84. package/src/jsonschema/JsonSchema.ts +2 -2
  85. package/src/jsonschema/types.d.ts +63 -12
  86. package/src/resource/Identifiable.ts +3 -0
  87. package/src/resource/getTitleOfResource.tsx +6 -0
  88. package/src/resource/index.ts +3 -0
  89. package/src/resource/schema/AnyResourceSchema.ts +113 -0
  90. package/src/resource/schema/BaseResourceSchema.ts +32 -0
  91. package/src/resource/schema/ResourceActionType.ts +123 -0
  92. package/src/resource/schema/ResourceStatus.ts +94 -0
  93. package/src/resource/schema/ResourceType.ts +25 -0
  94. package/src/resource/schema/SchemaRegistry.ts +42 -0
  95. package/src/resource/schema/SexType.ts +13 -0
  96. package/src/resource/schema/types.test.ts +18 -0
  97. package/src/resource/schema/types.ts +105 -0
  98. package/src/schema/TypeSchema.d.ts +32 -0
  99. package/src/schema/createSchemaData.ts +81 -0
  100. package/src/schema/findJsonSchemaByPath.ts +37 -0
  101. package/src/schema/getSchemaCache.ts +21 -0
  102. package/src/schema/getSchemaOptions.ts +24 -0
  103. package/src/schema/index.ts +6 -0
  104. package/src/schema/toJsonSchema.test.ts +37 -0
  105. package/src/schema/toJsonSchema.ts +200 -0
  106. package/src/schema/validate.ts +135 -0
  107. package/src/tools/generateSchema.ts +28 -28
  108. package/lib/cn/DivisionCode.js.map +0 -1
  109. package/lib/cn/Mod11Checksum.js.map +0 -1
  110. package/lib/cn/Mod31Checksum.js.map +0 -1
  111. package/lib/cn/ResidentIdentityCardNumber.js.map +0 -1
  112. package/lib/cn/UnifiedSocialCreditCode.js.map +0 -1
  113. package/lib/cn/formatDate.js.map +0 -1
  114. package/lib/cn/index.js.map +0 -1
  115. package/lib/cn/parseSex.js.map +0 -1
  116. package/lib/cn/types.d.js.map +0 -1
  117. package/lib/consola/createStandardConsolaReporter.js.map +0 -1
  118. package/lib/consola/formatLogObject.js.map +0 -1
  119. package/lib/consola/index.js.map +0 -1
  120. package/lib/data/formatSort.js.map +0 -1
  121. package/lib/data/index.js.map +0 -1
  122. package/lib/data/maybeNumber.js.map +0 -1
  123. package/lib/data/parseSort.js.map +0 -1
  124. package/lib/data/resolvePagination.js.map +0 -1
  125. package/lib/data/types.d.js.map +0 -1
  126. package/lib/index.js.map +0 -1
  127. package/lib/jsonschema/JsonSchema.js.map +0 -1
  128. package/lib/jsonschema/index.js.map +0 -1
  129. package/lib/jsonschema/types.d.js.map +0 -1
  130. package/lib/meta/defineFileType.js.map +0 -1
  131. package/lib/meta/defineInit.js.map +0 -1
  132. package/lib/meta/defineMetadata.js.map +0 -1
  133. package/lib/meta/index.js.map +0 -1
  134. package/lib/password/PHC.js.map +0 -1
  135. package/lib/password/Password.js.map +0 -1
  136. package/lib/password/createArgon2PasswordAlgorithm.js.map +0 -1
  137. package/lib/password/createBase64PasswordAlgorithm.js.map +0 -1
  138. package/lib/password/createBcryptPasswordAlgorithm.js.map +0 -1
  139. package/lib/password/createPBKDF2PasswordAlgorithm.js.map +0 -1
  140. package/lib/password/createScryptPasswordAlgorithm.js.map +0 -1
  141. package/lib/password/index.js.map +0 -1
  142. package/lib/password/server/index.js.map +0 -1
  143. package/lib/search/AdvanceSearch.js.map +0 -1
  144. package/lib/search/formatAdvanceSearch.js.map +0 -1
  145. package/lib/search/index.js.map +0 -1
  146. package/lib/search/optimizeAdvanceSearch.js.map +0 -1
  147. package/lib/search/parseAdvanceSearch.js.map +0 -1
  148. package/lib/search/parser.d.js.map +0 -1
  149. package/lib/search/parser.js.map +0 -1
  150. package/lib/search/types.d.js.map +0 -1
  151. package/lib/tools/generateSchema.js.map +0 -1
  152. package/lib/tools/renderJsonSchemaToMarkdownDoc.js.map +0 -1
@@ -1,8 +1,200 @@
1
+ function asyncGeneratorStep(gen, resolve, reject, _next, _throw, key, arg) {
2
+ try {
3
+ var info = gen[key](arg);
4
+ var value = info.value;
5
+ }
6
+ catch (error) {
7
+ reject(error);
8
+ return;
9
+ }
10
+ if (info.done) {
11
+ resolve(value);
12
+ }
13
+ else {
14
+ Promise.resolve(value).then(_next, _throw);
15
+ }
16
+ }
17
+ function _async_to_generator(fn) {
18
+ return function () {
19
+ var self = this, args = arguments;
20
+ return new Promise(function (resolve, reject) {
21
+ var gen = fn.apply(self, args);
22
+ function _next(value) {
23
+ asyncGeneratorStep(gen, resolve, reject, _next, _throw, "next", value);
24
+ }
25
+ function _throw(err) {
26
+ asyncGeneratorStep(gen, resolve, reject, _next, _throw, "throw", err);
27
+ }
28
+ _next(undefined);
29
+ });
30
+ };
31
+ }
32
+ function _define_property(obj, key, value) {
33
+ if (key in obj) {
34
+ Object.defineProperty(obj, key, {
35
+ value: value,
36
+ enumerable: true,
37
+ configurable: true,
38
+ writable: true
39
+ });
40
+ }
41
+ else {
42
+ obj[key] = value;
43
+ }
44
+ return obj;
45
+ }
46
+ function _object_spread(target) {
47
+ for (var i = 1; i < arguments.length; i++) {
48
+ var source = arguments[i] != null ? arguments[i] : {};
49
+ var ownKeys = Object.keys(source);
50
+ if (typeof Object.getOwnPropertySymbols === "function") {
51
+ ownKeys = ownKeys.concat(Object.getOwnPropertySymbols(source).filter(function (sym) {
52
+ return Object.getOwnPropertyDescriptor(source, sym).enumerable;
53
+ }));
54
+ }
55
+ ownKeys.forEach(function (key) {
56
+ _define_property(target, key, source[key]);
57
+ });
58
+ }
59
+ return target;
60
+ }
61
+ function _object_without_properties(source, excluded) {
62
+ if (source == null)
63
+ return {};
64
+ var target = _object_without_properties_loose(source, excluded);
65
+ var key, i;
66
+ if (Object.getOwnPropertySymbols) {
67
+ var sourceSymbolKeys = Object.getOwnPropertySymbols(source);
68
+ for (i = 0; i < sourceSymbolKeys.length; i++) {
69
+ key = sourceSymbolKeys[i];
70
+ if (excluded.indexOf(key) >= 0)
71
+ continue;
72
+ if (!Object.prototype.propertyIsEnumerable.call(source, key))
73
+ continue;
74
+ target[key] = source[key];
75
+ }
76
+ }
77
+ return target;
78
+ }
79
+ function _object_without_properties_loose(source, excluded) {
80
+ if (source == null)
81
+ return {};
82
+ var target = {};
83
+ var sourceKeys = Object.keys(source);
84
+ var key, i;
85
+ for (i = 0; i < sourceKeys.length; i++) {
86
+ key = sourceKeys[i];
87
+ if (excluded.indexOf(key) >= 0)
88
+ continue;
89
+ target[key] = source[key];
90
+ }
91
+ return target;
92
+ }
93
+ function _ts_generator(thisArg, body) {
94
+ var f, y, t, _ = {
95
+ label: 0,
96
+ sent: function () {
97
+ if (t[0] & 1)
98
+ throw t[1];
99
+ return t[1];
100
+ },
101
+ trys: [],
102
+ ops: []
103
+ }, g = Object.create((typeof Iterator === "function" ? Iterator : Object).prototype);
104
+ return g.next = verb(0), g["throw"] = verb(1), g["return"] = verb(2), typeof Symbol === "function" && (g[Symbol.iterator] = function () {
105
+ return this;
106
+ }), g;
107
+ function verb(n) {
108
+ return function (v) {
109
+ return step([
110
+ n,
111
+ v
112
+ ]);
113
+ };
114
+ }
115
+ function step(op) {
116
+ if (f)
117
+ throw new TypeError("Generator is already executing.");
118
+ while (g && (g = 0, op[0] && (_ = 0)), _)
119
+ try {
120
+ if (f = 1, y && (t = op[0] & 2 ? y["return"] : op[0] ? y["throw"] || ((t = y["return"]) && t.call(y), 0) : y.next) && !(t = t.call(y, op[1])).done)
121
+ return t;
122
+ if (y = 0, t)
123
+ op = [
124
+ op[0] & 2,
125
+ t.value
126
+ ];
127
+ switch (op[0]) {
128
+ case 0:
129
+ case 1:
130
+ t = op;
131
+ break;
132
+ case 4:
133
+ _.label++;
134
+ return {
135
+ value: op[1],
136
+ done: false
137
+ };
138
+ case 5:
139
+ _.label++;
140
+ y = op[1];
141
+ op = [
142
+ 0
143
+ ];
144
+ continue;
145
+ case 7:
146
+ op = _.ops.pop();
147
+ _.trys.pop();
148
+ continue;
149
+ default:
150
+ if (!(t = _.trys, t = t.length > 0 && t[t.length - 1]) && (op[0] === 6 || op[0] === 2)) {
151
+ _ = 0;
152
+ continue;
153
+ }
154
+ if (op[0] === 3 && (!t || op[1] > t[0] && op[1] < t[3])) {
155
+ _.label = op[1];
156
+ break;
157
+ }
158
+ if (op[0] === 6 && _.label < t[1]) {
159
+ _.label = t[1];
160
+ t = op;
161
+ break;
162
+ }
163
+ if (t && _.label < t[2]) {
164
+ _.label = t[2];
165
+ _.ops.push(op);
166
+ break;
167
+ }
168
+ if (t[2])
169
+ _.ops.pop();
170
+ _.trys.pop();
171
+ continue;
172
+ }
173
+ op = body.call(thisArg, _);
174
+ }
175
+ catch (e) {
176
+ op = [
177
+ 6,
178
+ e
179
+ ];
180
+ y = 0;
181
+ }
182
+ finally {
183
+ f = t = 0;
184
+ }
185
+ if (op[0] & 5)
186
+ throw op[1];
187
+ return {
188
+ value: op[0] ? op[1] : void 0,
189
+ done: true
190
+ };
191
+ }
192
+ }
1
193
  import { Errors } from "@wener/utils";
2
194
  import { createPBKDF2PasswordAlgorithm } from "./createPBKDF2PasswordAlgorithm.js";
3
195
  import { PHC } from "./PHC.js";
4
196
  (function (Password) {
5
- const Algorithms = {
197
+ var Algorithms = {
6
198
  1: "md5",
7
199
  "2a": "bcrypt",
8
200
  "2b": "bcrypt",
@@ -12,9 +204,9 @@ import { PHC } from "./PHC.js";
12
204
  6: "sha512",
13
205
  7: "scrypt"
14
206
  };
15
- let DefaultAlgorithm = "6";
207
+ var DefaultAlgorithm = "6";
16
208
  function setDefaultAlgorithm(algorithm) {
17
- Errors.BadRequest.check(Algorithms[algorithm], `Unknown algorithm ${algorithm}`);
209
+ Errors.BadRequest.check(Algorithms[algorithm], "Unknown algorithm ".concat(algorithm));
18
210
  DefaultAlgorithm = algorithm;
19
211
  }
20
212
  Password.setDefaultAlgorithm = setDefaultAlgorithm;
@@ -25,8 +217,28 @@ import { PHC } from "./PHC.js";
25
217
  function addAlgorithm(algorithm) {
26
218
  Algorithms[algorithm.name] = algorithm;
27
219
  if (algorithm.ids) {
28
- for (const id of algorithm.ids) {
29
- Algorithms[id] = algorithm;
220
+ var _iteratorNormalCompletion = true, _didIteratorError = false, _iteratorError = undefined;
221
+ try {
222
+ for (var _iterator = algorithm.ids[Symbol.iterator](), _step; !(_iteratorNormalCompletion = (_step = _iterator.next()).done); _iteratorNormalCompletion = true) {
223
+ var id = _step.value;
224
+ Algorithms[id] = algorithm;
225
+ }
226
+ }
227
+ catch (err) {
228
+ _didIteratorError = true;
229
+ _iteratorError = err;
230
+ }
231
+ finally {
232
+ try {
233
+ if (!_iteratorNormalCompletion && _iterator.return != null) {
234
+ _iterator.return();
235
+ }
236
+ }
237
+ finally {
238
+ if (_didIteratorError) {
239
+ throw _iteratorError;
240
+ }
241
+ }
30
242
  }
31
243
  }
32
244
  }
@@ -39,45 +251,95 @@ import { PHC } from "./PHC.js";
39
251
  id: "sha512",
40
252
  digest: "SHA-512"
41
253
  }));
42
- async function parse(hash) {
43
- return PHC.deserialize(hash);
254
+ function parse(hash) {
255
+ return _async_to_generator(function () {
256
+ return _ts_generator(this, function (_state) {
257
+ return [
258
+ 2,
259
+ PHC.deserialize(hash)
260
+ ];
261
+ });
262
+ })();
44
263
  }
45
264
  Password.parse = parse;
46
265
  function resolveAlgorithm(id) {
47
- let f = id;
266
+ var f = id;
48
267
  while (typeof f === "string") {
49
268
  f = Algorithms[f];
50
269
  }
51
270
  if (!f) {
52
- throw new Error(`Unknown algorithm ${id}`);
271
+ throw new Error("Unknown algorithm ".concat(id));
53
272
  }
54
273
  return f;
55
274
  }
56
- async function check(password, hash) {
57
- let res = await parse(hash);
58
- let f = resolveAlgorithm(res.id);
59
- return {
60
- result: f.verify(password, hash, res),
61
- parsed: res
62
- };
275
+ function check(password, hash) {
276
+ return _async_to_generator(function () {
277
+ var res, f;
278
+ return _ts_generator(this, function (_state) {
279
+ switch (_state.label) {
280
+ case 0:
281
+ return [
282
+ 4,
283
+ parse(hash)
284
+ ];
285
+ case 1:
286
+ res = _state.sent();
287
+ f = resolveAlgorithm(res.id);
288
+ return [
289
+ 2,
290
+ {
291
+ result: f.verify(password, hash, res),
292
+ parsed: res
293
+ }
294
+ ];
295
+ }
296
+ });
297
+ })();
63
298
  }
64
299
  Password.check = check;
65
- async function verify(password, hash) {
66
- let res = await parse(hash);
67
- let f = resolveAlgorithm(res.id);
68
- return f.verify(password, hash, res);
300
+ function verify(password, hash) {
301
+ return _async_to_generator(function () {
302
+ var res, f;
303
+ return _ts_generator(this, function (_state) {
304
+ switch (_state.label) {
305
+ case 0:
306
+ return [
307
+ 4,
308
+ parse(hash)
309
+ ];
310
+ case 1:
311
+ res = _state.sent();
312
+ f = resolveAlgorithm(res.id);
313
+ return [
314
+ 2,
315
+ f.verify(password, hash, res)
316
+ ];
317
+ }
318
+ });
319
+ })();
69
320
  }
70
321
  Password.verify = verify;
71
- async function hash(password, { algorithm, ...opts } = {}) {
72
- let f = resolveAlgorithm(algorithm ?? DefaultAlgorithm);
73
- let id = algorithm ?? DefaultAlgorithm;
74
- typeof id !== "string" && (id = f.name);
75
- return f.hash(password, {
76
- id,
77
- ...opts
78
- });
322
+ function hash(_0) {
323
+ return _async_to_generator(function (password) {
324
+ var _param, algorithm, opts, f, id;
325
+ var _arguments = arguments;
326
+ return _ts_generator(this, function (_state) {
327
+ _param = _arguments.length > 1 && _arguments[1] !== void 0 ? _arguments[1] : {};
328
+ algorithm = _param.algorithm, opts = _object_without_properties(_param, [
329
+ "algorithm"
330
+ ]);
331
+ f = resolveAlgorithm(algorithm !== null && algorithm !== void 0 ? algorithm : DefaultAlgorithm);
332
+ id = algorithm !== null && algorithm !== void 0 ? algorithm : DefaultAlgorithm;
333
+ typeof id !== "string" && (id = f.name);
334
+ return [
335
+ 2,
336
+ f.hash(password, _object_spread({
337
+ id: id
338
+ }, opts))
339
+ ];
340
+ });
341
+ }).apply(this, arguments);
79
342
  }
80
343
  Password.hash = hash;
81
344
  })(Password || (Password = {}));
82
345
  export var Password;
83
- //# sourceMappingURL=Password.js.map