@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,31 +1,44 @@
1
- import { ArrayBuffers } from "@wener/utils";
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
- const idRegex = /^[a-z0-9-]{1,32}$/;
5
- const nameRegex = /^[a-z0-9-]{1,32}$/;
6
- const valueRegex = /^[a-zA-Z0-9/+.-]+$/;
7
- const b64Regex = /^([a-zA-Z0-9/+.-]+|)$/;
8
- const decimalRegex = /^((-)?[1-9]\d*|0)$/;
9
- const versionRegex = /^v=(\d+)$/;
10
- const fromBase64 = ArrayBuffers.fromBase64;
11
- const toBase64 = ArrayBuffers.toBase64;
12
- const isBuffer = (v)=>{
13
- return v instanceof Uint8Array;
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('=')).join(',');
31
+ ].join('=');
32
+ }).join(',');
20
33
  }
21
34
  function keyValtoObj(str) {
22
- const obj = {};
23
- str.split(',').forEach((ps)=>{
24
- const pss = ps.split('=');
35
+ var obj = {};
36
+ str.split(',').forEach(function(ps) {
37
+ var pss = ps.split('=');
25
38
  if (pss.length < 2) {
26
- throw new TypeError(`params must be in the format name=value`);
39
+ throw new TypeError("params must be in the format name=value");
27
40
  }
28
- const key = pss.shift();
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)=>object[k]);
53
+ return objectKeys(object).map(function(k) {
54
+ return object[k];
55
+ });
41
56
  }
42
57
  function serialize(opts) {
43
- const fields = [
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(`id must satisfy ${idRegex}`);
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(`v=${opts.version}`);
76
+ fields.push("v=".concat(opts.version));
62
77
  }
63
78
  // Parameters Validation
64
79
  if (typeof opts.params !== 'undefined') {
65
- if (typeof opts.params !== 'object' || opts.params === null) {
80
+ if (_type_of(opts.params) !== 'object' || opts.params === null) {
66
81
  throw new TypeError('params must be an object');
67
82
  }
68
- const pk = objectKeys(opts.params);
69
- if (!pk.every((p)=>nameRegex.test(p.toString()))) {
70
- throw new TypeError(`params names must satisfy ${nameRegex}`);
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
- const value = opts.params[k];
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 instanceof Uint8Array) {
94
+ } else if (_instanceof(value, Uint8Array)) {
78
95
  opts.params[k] = toBase64(value).split('=')[0];
79
96
  }
80
97
  });
81
- const pv = objectValues(opts.params);
82
- if (!pv.every((v)=>typeof v === 'string')) {
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)=>valueRegex.test(v))) {
86
- throw new TypeError(`params values must satisfy ${valueRegex}`);
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
- const strpar = objToKeyVal(opts.params);
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
- const phcstr = fields.join('$');
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
- const fields = phcstr.split('$');
142
+ var fields = phcstr.split('$');
122
143
  // Remove first empty $
123
144
  fields.shift();
124
145
  // Parse Fields
125
- let maxf = 5;
146
+ var maxf = 5;
126
147
  if (!versionRegex.test(fields[1])) maxf--;
127
148
  if (fields.length > maxf) {
128
- throw new TypeError(`pchstr contains too many fileds: ${fields.length}/${maxf}`);
149
+ throw new TypeError("pchstr contains too many fileds: ".concat(fields.length, "/").concat(maxf));
129
150
  }
130
151
  // Parse Identifier
131
- const id = fields.shift();
152
+ var id = fields.shift();
132
153
  if (!id || !idRegex.test(id)) {
133
- throw new TypeError(`id must satisfy ${idRegex}`);
154
+ throw new TypeError("id must satisfy ".concat(idRegex));
134
155
  }
135
- let version;
156
+ var version;
136
157
  // Parse Version
137
158
  if (fields[0] && versionRegex.test(fields[0])) {
138
- const versionMatch = fields.shift()?.match(versionRegex);
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
- let hash;
142
- let salt;
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
- const hashStr = fields.pop();
168
+ var hashStr = fields.pop();
147
169
  if (hashStr) hash = fromBase64(hashStr);
148
170
  // Parse Salt
149
- const saltStr = fields.pop();
171
+ var saltStr = fields.pop();
150
172
  if (saltStr !== undefined) salt = fromBase64(saltStr);
151
173
  } else {
152
174
  // Parse Salt
153
- const saltStr = fields.pop();
154
- if (saltStr !== undefined) salt = fromBase64(saltStr);
175
+ var saltStr1 = fields.pop();
176
+ if (saltStr1 !== undefined) salt = fromBase64(saltStr1);
155
177
  }
156
178
  }
157
179
  // Parse Parameters
158
- let params;
180
+ var params;
159
181
  if (fields.length > 0) {
160
- const parstr = fields.pop();
182
+ var parstr = fields.pop();
161
183
  if (parstr) {
162
184
  params = keyValtoObj(parstr);
163
- if (!Object.keys(params).every((p)=>nameRegex.test(p))) {
164
- throw new TypeError(`params names must satisfy ${nameRegex}}`);
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
- const pv = Object.values(params);
167
- if (!pv.every((v)=>valueRegex.test(String(v)))) {
168
- throw new TypeError(`params values must satisfy ${valueRegex}`);
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
- const value = params[k];
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(`pchstr contains unrecognized fileds: ${fields}`);
206
+ throw new TypeError("pchstr contains unrecognized fileds: ".concat(fields));
181
207
  }
182
208
  // Build the output object
183
- const phcobj = {
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