@wener/common 1.0.5 → 2.0.2
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/ChineseResidentIdNo.js +41 -0
- package/lib/cn/ChineseResidentIdNo.mod.js +1 -0
- package/lib/cn/ChineseResidentIdNo.test.js +22 -0
- package/lib/cn/DivisionCode.js +214 -280
- package/lib/cn/DivisionCode.mod.js +1 -0
- package/lib/cn/DivisionCode.test.js +134 -0
- package/lib/cn/Mod11.js +86 -0
- package/lib/cn/Mod31.js +98 -0
- package/lib/cn/UnifiedSocialCreditCode.js +130 -109
- package/lib/cn/UnifiedSocialCreditCode.mod.js +1 -0
- package/lib/cn/UnifiedSocialCreditCode.test.js +16 -0
- package/lib/cn/index.js +1 -4
- package/lib/cn/mod.js +6 -0
- package/lib/cn/types.d.js +0 -2
- package/lib/consola/createStandardConsolaReporter.js +6 -6
- package/lib/consola/formatLogObject.js +147 -34
- package/lib/consola/index.js +0 -1
- 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/dayjs/dayjs.js +38 -0
- package/lib/dayjs/formatDuration.js +58 -0
- package/lib/dayjs/formatDuration.test.js +90 -0
- package/lib/dayjs/index.js +3 -0
- package/lib/dayjs/parseDuration.js +32 -0
- package/lib/decimal/index.js +1 -0
- package/lib/decimal/parseDecimal.js +13 -0
- package/lib/foundation/schema/SexType.js +14 -0
- package/lib/foundation/schema/index.js +1 -0
- package/lib/foundation/schema/parseSexType.js +18 -0
- package/lib/foundation/schema/types.js +5 -0
- package/lib/index.js +0 -1
- package/lib/jsonschema/JsonSchema.js +78 -52
- 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 +295 -30
- 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/ListQuery.js +119 -0
- package/lib/resource/getTitleOfResource.js +10 -0
- package/lib/resource/index.js +2 -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/index.js +5 -0
- package/lib/resource/schema/types.js +89 -0
- package/lib/resource/schema/types.test.js +14 -0
- package/lib/schema/SchemaRegistry.js +45 -0
- package/lib/schema/SchemaRegistry.mod.js +2 -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 +6 -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/tools/generateSchema.js +197 -39
- package/lib/tools/renderJsonSchemaToMarkdownDoc.js +143 -55
- package/lib/utils/getEstimateProcessTime.js +20 -0
- package/lib/utils/index.js +1 -0
- package/package.json +38 -17
- package/src/cn/ChineseResidentIdNo.mod.ts +7 -0
- package/src/cn/ChineseResidentIdNo.test.ts +18 -0
- package/src/cn/ChineseResidentIdNo.ts +66 -0
- package/src/cn/DivisionCode.mod.ts +7 -0
- package/src/cn/DivisionCode.test.ts +3 -13
- package/src/cn/DivisionCode.ts +132 -195
- package/src/cn/{Mod11Checksum.ts → Mod11.ts} +3 -1
- package/src/cn/{Mod31Checksum.ts → Mod31.ts} +2 -0
- package/src/cn/UnifiedSocialCreditCode.mod.ts +7 -0
- package/src/cn/UnifiedSocialCreditCode.test.ts +2 -2
- package/src/cn/UnifiedSocialCreditCode.ts +105 -125
- package/src/cn/__snapshots__/ChineseResidentIdNo.test.ts.snap +14 -0
- package/src/cn/__snapshots__/UnifiedSocialCreditCode.test.ts.snap +18 -12
- package/src/cn/index.ts +1 -3
- package/src/cn/mod.ts +3 -0
- package/src/consola/formatLogObject.ts +12 -4
- 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/dayjs/dayjs.ts +40 -0
- package/src/dayjs/formatDuration.test.ts +14 -0
- package/src/dayjs/formatDuration.ts +86 -0
- package/src/dayjs/index.ts +3 -0
- package/src/dayjs/parseDuration.ts +40 -0
- package/src/decimal/index.ts +1 -0
- package/src/decimal/parseDecimal.ts +16 -0
- package/src/foundation/schema/SexType.ts +21 -0
- package/src/foundation/schema/index.ts +1 -0
- package/src/foundation/schema/parseSexType.ts +19 -0
- package/src/foundation/schema/types.ts +8 -0
- package/src/jsonschema/JsonSchema.test.ts +17 -0
- package/src/jsonschema/JsonSchema.ts +2 -2
- package/src/jsonschema/types.d.ts +63 -12
- package/src/password/Password.ts +2 -2
- package/src/resource/Identifiable.ts +3 -0
- package/src/resource/ListQuery.ts +53 -0
- package/src/resource/getTitleOfResource.tsx +6 -0
- package/src/resource/index.ts +4 -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/index.ts +5 -0
- package/src/resource/schema/types.test.ts +18 -0
- package/src/resource/schema/types.ts +105 -0
- package/src/schema/SchemaRegistry.mod.ts +1 -0
- package/src/schema/SchemaRegistry.ts +46 -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 +7 -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 +28 -28
- package/src/utils/getEstimateProcessTime.ts +36 -0
- package/src/utils/index.ts +1 -0
- package/lib/cn/DivisionCode.js.map +0 -1
- package/lib/cn/Mod11Checksum.js +0 -42
- package/lib/cn/Mod11Checksum.js.map +0 -1
- package/lib/cn/Mod31Checksum.js +0 -48
- package/lib/cn/Mod31Checksum.js.map +0 -1
- package/lib/cn/ResidentIdentityCardNumber.js +0 -50
- package/lib/cn/ResidentIdentityCardNumber.js.map +0 -1
- package/lib/cn/UnifiedSocialCreditCode.js.map +0 -1
- package/lib/cn/formatDate.js +0 -15
- package/lib/cn/formatDate.js.map +0 -1
- package/lib/cn/index.js.map +0 -1
- package/lib/cn/parseSex.js +0 -22
- package/lib/cn/parseSex.js.map +0 -1
- package/lib/cn/types.d.js.map +0 -1
- package/lib/consola/createStandardConsolaReporter.js.map +0 -1
- package/lib/consola/formatLogObject.js.map +0 -1
- package/lib/consola/index.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 +0 -10
- package/lib/search/AdvanceSearch.js.map +0 -1
- package/lib/search/formatAdvanceSearch.js +0 -64
- package/lib/search/formatAdvanceSearch.js.map +0 -1
- package/lib/search/index.js +0 -2
- package/lib/search/index.js.map +0 -1
- package/lib/search/optimizeAdvanceSearch.js +0 -89
- package/lib/search/optimizeAdvanceSearch.js.map +0 -1
- package/lib/search/parseAdvanceSearch.js +0 -20
- package/lib/search/parseAdvanceSearch.js.map +0 -1
- package/lib/search/parser.d.js +0 -3
- package/lib/search/parser.d.js.map +0 -1
- package/lib/search/parser.js +0 -3065
- package/lib/search/parser.js.map +0 -1
- package/lib/search/types.d.js +0 -3
- package/lib/search/types.d.js.map +0 -1
- package/lib/tools/generateSchema.js.map +0 -1
- package/lib/tools/renderJsonSchemaToMarkdownDoc.js.map +0 -1
- package/src/cn/ResidentIdentityCardNumber.test.ts +0 -17
- package/src/cn/ResidentIdentityCardNumber.ts +0 -96
- package/src/cn/__snapshots__/ResidentIdentityCardNumber.test.ts.snap +0 -15
- package/src/cn/formatDate.ts +0 -12
- package/src/cn/parseSex.ts +0 -13
- package/src/search/AdvanceSearch.test.ts +0 -149
- package/src/search/AdvanceSearch.ts +0 -14
- package/src/search/Makefile +0 -2
- package/src/search/__snapshots__/AdvanceSearch.test.ts.snap +0 -675
- package/src/search/formatAdvanceSearch.ts +0 -52
- package/src/search/index.ts +0 -1
- package/src/search/optimizeAdvanceSearch.ts +0 -77
- package/src/search/parseAdvanceSearch.ts +0 -23
- package/src/search/parser.d.ts +0 -8
- package/src/search/parser.js +0 -2794
- package/src/search/parser.peggy +0 -237
- package/src/search/types.d.ts +0 -45
|
@@ -1,7 +1,93 @@
|
|
|
1
|
-
|
|
2
|
-
|
|
3
|
-
|
|
4
|
-
|
|
1
|
+
function _array_like_to_array(arr, len) {
|
|
2
|
+
if (len == null || len > arr.length) len = arr.length;
|
|
3
|
+
for(var i = 0, arr2 = new Array(len); i < len; i++)arr2[i] = arr[i];
|
|
4
|
+
return arr2;
|
|
5
|
+
}
|
|
6
|
+
function _array_with_holes(arr) {
|
|
7
|
+
if (Array.isArray(arr)) return arr;
|
|
8
|
+
}
|
|
9
|
+
function _array_without_holes(arr) {
|
|
10
|
+
if (Array.isArray(arr)) return _array_like_to_array(arr);
|
|
11
|
+
}
|
|
12
|
+
function _define_property(obj, key, value) {
|
|
13
|
+
if (key in obj) {
|
|
14
|
+
Object.defineProperty(obj, key, {
|
|
15
|
+
value: value,
|
|
16
|
+
enumerable: true,
|
|
17
|
+
configurable: true,
|
|
18
|
+
writable: true
|
|
19
|
+
});
|
|
20
|
+
} else {
|
|
21
|
+
obj[key] = value;
|
|
22
|
+
}
|
|
23
|
+
return obj;
|
|
24
|
+
}
|
|
25
|
+
function _iterable_to_array(iter) {
|
|
26
|
+
if (typeof Symbol !== "undefined" && iter[Symbol.iterator] != null || iter["@@iterator"] != null) return Array.from(iter);
|
|
27
|
+
}
|
|
28
|
+
function _non_iterable_rest() {
|
|
29
|
+
throw new TypeError("Invalid attempt to destructure non-iterable instance.\\nIn order to be iterable, non-array objects must have a [Symbol.iterator]() method.");
|
|
30
|
+
}
|
|
31
|
+
function _non_iterable_spread() {
|
|
32
|
+
throw new TypeError("Invalid attempt to spread non-iterable instance.\\nIn order to be iterable, non-array objects must have a [Symbol.iterator]() method.");
|
|
33
|
+
}
|
|
34
|
+
function _object_spread(target) {
|
|
35
|
+
for(var i = 1; i < arguments.length; i++){
|
|
36
|
+
var source = arguments[i] != null ? arguments[i] : {};
|
|
37
|
+
var ownKeys = Object.keys(source);
|
|
38
|
+
if (typeof Object.getOwnPropertySymbols === "function") {
|
|
39
|
+
ownKeys = ownKeys.concat(Object.getOwnPropertySymbols(source).filter(function(sym) {
|
|
40
|
+
return Object.getOwnPropertyDescriptor(source, sym).enumerable;
|
|
41
|
+
}));
|
|
42
|
+
}
|
|
43
|
+
ownKeys.forEach(function(key) {
|
|
44
|
+
_define_property(target, key, source[key]);
|
|
45
|
+
});
|
|
46
|
+
}
|
|
47
|
+
return target;
|
|
48
|
+
}
|
|
49
|
+
function ownKeys(object, enumerableOnly) {
|
|
50
|
+
var keys = Object.keys(object);
|
|
51
|
+
if (Object.getOwnPropertySymbols) {
|
|
52
|
+
var symbols = Object.getOwnPropertySymbols(object);
|
|
53
|
+
if (enumerableOnly) {
|
|
54
|
+
symbols = symbols.filter(function(sym) {
|
|
55
|
+
return Object.getOwnPropertyDescriptor(object, sym).enumerable;
|
|
56
|
+
});
|
|
57
|
+
}
|
|
58
|
+
keys.push.apply(keys, symbols);
|
|
59
|
+
}
|
|
60
|
+
return keys;
|
|
61
|
+
}
|
|
62
|
+
function _object_spread_props(target, source) {
|
|
63
|
+
source = source != null ? source : {};
|
|
64
|
+
if (Object.getOwnPropertyDescriptors) {
|
|
65
|
+
Object.defineProperties(target, Object.getOwnPropertyDescriptors(source));
|
|
66
|
+
} else {
|
|
67
|
+
ownKeys(Object(source)).forEach(function(key) {
|
|
68
|
+
Object.defineProperty(target, key, Object.getOwnPropertyDescriptor(source, key));
|
|
69
|
+
});
|
|
70
|
+
}
|
|
71
|
+
return target;
|
|
72
|
+
}
|
|
73
|
+
function _to_array(arr) {
|
|
74
|
+
return _array_with_holes(arr) || _iterable_to_array(arr) || _unsupported_iterable_to_array(arr) || _non_iterable_rest();
|
|
75
|
+
}
|
|
76
|
+
function _to_consumable_array(arr) {
|
|
77
|
+
return _array_without_holes(arr) || _iterable_to_array(arr) || _unsupported_iterable_to_array(arr) || _non_iterable_spread();
|
|
78
|
+
}
|
|
79
|
+
function _unsupported_iterable_to_array(o, minLen) {
|
|
80
|
+
if (!o) return;
|
|
81
|
+
if (typeof o === "string") return _array_like_to_array(o, minLen);
|
|
82
|
+
var n = Object.prototype.toString.call(o).slice(8, -1);
|
|
83
|
+
if (n === "Object" && o.constructor) n = o.constructor.name;
|
|
84
|
+
if (n === "Map" || n === "Set") return Array.from(n);
|
|
85
|
+
if (n === "Arguments" || /^(?:Ui|I)nt(?:8|16|32)(?:Clamped)?Array$/.test(n)) return _array_like_to_array(o, minLen);
|
|
86
|
+
}
|
|
87
|
+
import colors, { Chalk } from 'chalk';
|
|
88
|
+
import dayjs from 'dayjs';
|
|
89
|
+
import { isDevelopment } from 'std-env';
|
|
90
|
+
var LevelColors = {
|
|
5
91
|
trace: colors.gray,
|
|
6
92
|
debug: colors.cyan,
|
|
7
93
|
info: colors.blueBright,
|
|
@@ -17,7 +103,7 @@ const levelColors = {
|
|
|
17
103
|
box: colors.white,
|
|
18
104
|
verbose: colors.green
|
|
19
105
|
};
|
|
20
|
-
|
|
106
|
+
var levelShort = {
|
|
21
107
|
trace: 'TRAC',
|
|
22
108
|
debug: 'DEBG',
|
|
23
109
|
info: 'INFO',
|
|
@@ -33,37 +119,49 @@ const levelShort = {
|
|
|
33
119
|
box: 'BOX ',
|
|
34
120
|
verbose: 'VERB'
|
|
35
121
|
};
|
|
36
|
-
|
|
122
|
+
var start = Date.now();
|
|
123
|
+
var Colors = colors;
|
|
124
|
+
var NoColors = new Chalk({
|
|
125
|
+
level: 0
|
|
126
|
+
});
|
|
37
127
|
export function formatLogObject(o, ctx) {
|
|
38
|
-
|
|
128
|
+
var _ctx_options_formatOptions, _ctx_options;
|
|
129
|
+
var shouldColor = Boolean((_ctx_options = ctx.options) === null || _ctx_options === void 0 ? void 0 : (_ctx_options_formatOptions = _ctx_options.formatOptions) === null || _ctx_options_formatOptions === void 0 ? void 0 : _ctx_options_formatOptions.colors);
|
|
130
|
+
var date = o.date, type = o.type, tag = o.tag;
|
|
39
131
|
type = type === 'log' ? 'info' : type;
|
|
40
|
-
|
|
41
|
-
|
|
42
|
-
|
|
43
|
-
|
|
132
|
+
var _$colors = shouldColor ? Colors : NoColors;
|
|
133
|
+
var color = LevelColors[type] || _$colors.white;
|
|
134
|
+
if (!shouldColor) {
|
|
135
|
+
color = function(v) {
|
|
136
|
+
return v;
|
|
137
|
+
};
|
|
138
|
+
}
|
|
139
|
+
var levelText = levelShort[type] || type.toUpperCase().slice(0, 4); // Get first 4 chars, consistent uppercase
|
|
140
|
+
var line = '';
|
|
141
|
+
var out = [];
|
|
44
142
|
// Timestamp
|
|
45
143
|
if (isDevelopment) {
|
|
46
144
|
// process.hrtime.bigint()
|
|
47
|
-
|
|
48
|
-
out.push(colors.gray(diff.toFixed(3).padStart(7, ' ')));
|
|
145
|
+
var diff = (date.getTime() - start) / 1000;
|
|
146
|
+
out.push(_$colors.gray(diff.toFixed(3).padStart(7, ' ')));
|
|
49
147
|
} else {
|
|
50
|
-
out.push(colors.gray(dayjs(date).format('YYYY-MM-DD HH:mm:ss.SSS')));
|
|
148
|
+
out.push(_$colors.gray(dayjs(date).format('YYYY-MM-DD HH:mm:ss.SSS')));
|
|
51
149
|
}
|
|
52
150
|
// Log Level (colored)
|
|
53
151
|
// Pad to 4 characters
|
|
54
152
|
out.push(color(levelText.padEnd(4, ' ')));
|
|
55
153
|
if (tag) {
|
|
56
|
-
out.push(colors.yellow(
|
|
154
|
+
out.push(_$colors.yellow("[".concat(tag, "]"))); // Added color for tag
|
|
57
155
|
}
|
|
58
156
|
{
|
|
59
|
-
|
|
157
|
+
var _formatArgs_split = _to_array(formatArgs(o.args, ctx).split('\n')), message = _formatArgs_split[0], additional = _formatArgs_split.slice(1);
|
|
60
158
|
out.push(characterFormat(message));
|
|
61
159
|
line = out.join(' ');
|
|
62
160
|
if (additional.length > 0) {
|
|
63
161
|
line += characterFormat(additional.join('\n'));
|
|
64
162
|
}
|
|
65
163
|
if (type === 'trace') {
|
|
66
|
-
|
|
164
|
+
var _err = new Error('Trace: ' + o.message);
|
|
67
165
|
line += formatStack(_err.stack || '', _err.message);
|
|
68
166
|
}
|
|
69
167
|
}
|
|
@@ -83,20 +181,32 @@ export function formatLogObject(o, ctx) {
|
|
|
83
181
|
}
|
|
84
182
|
function characterFormat(str) {
|
|
85
183
|
return str// highlight backticks
|
|
86
|
-
.replace(/`([^`]+)`/gm, (_, m)
|
|
87
|
-
|
|
184
|
+
.replace(/`([^`]+)`/gm, function(_, m) {
|
|
185
|
+
return colors.cyan(m);
|
|
186
|
+
})// underline underscores
|
|
187
|
+
.replace(/\s+_([^_]+)_\s+/gm, function(_, m) {
|
|
188
|
+
return " ".concat(colors.underline(m), " ");
|
|
189
|
+
});
|
|
88
190
|
}
|
|
89
191
|
function parseStack(stack, message) {
|
|
90
192
|
// const cwd = process.cwd() + sep;
|
|
91
|
-
|
|
193
|
+
var lines = stack.split('\n').splice(message.split('\n').length).map(function(l) {
|
|
194
|
+
return l.trim().replace('file://', '');
|
|
195
|
+
});
|
|
92
196
|
return lines;
|
|
93
197
|
}
|
|
94
198
|
function formatStack(stack, message, opts) {
|
|
95
|
-
|
|
96
|
-
return
|
|
199
|
+
var indent = ' '.repeat(((opts === null || opts === void 0 ? void 0 : opts.errorLevel) || 0) + 1);
|
|
200
|
+
return "\n".concat(indent) + parseStack(stack, message).map(function(line) {
|
|
201
|
+
return ' ' + line.replace(/^at +/, function(m) {
|
|
202
|
+
return colors.gray(m);
|
|
203
|
+
}).replace(/\((.+)\)/, function(_, m) {
|
|
204
|
+
return "(".concat(colors.cyan(m), ")");
|
|
205
|
+
});
|
|
206
|
+
}).join("\n".concat(indent));
|
|
97
207
|
}
|
|
98
208
|
function formatArgs(args, opts) {
|
|
99
|
-
|
|
209
|
+
var _args = args.map(function(arg) {
|
|
100
210
|
if (arg && typeof arg.stack === 'string') {
|
|
101
211
|
return formatError(arg, opts);
|
|
102
212
|
}
|
|
@@ -104,22 +214,25 @@ function formatArgs(args, opts) {
|
|
|
104
214
|
});
|
|
105
215
|
// Only supported with Node >= 10
|
|
106
216
|
// https://nodejs.org/api/util.html#util_util_inspect_object_options
|
|
107
|
-
return formatWithOptions(
|
|
217
|
+
return formatWithOptions.apply(void 0, [
|
|
218
|
+
opts
|
|
219
|
+
].concat(_to_consumable_array(_args)));
|
|
108
220
|
}
|
|
109
|
-
function formatWithOptions(o
|
|
221
|
+
function formatWithOptions(o) {
|
|
222
|
+
for(var _len = arguments.length, params = new Array(_len > 1 ? _len - 1 : 0), _key = 1; _key < _len; _key++){
|
|
223
|
+
params[_key - 1] = arguments[_key];
|
|
224
|
+
}
|
|
110
225
|
// import { formatWithOptions } from 'node:util';
|
|
111
226
|
return params.join(' ');
|
|
112
227
|
}
|
|
113
228
|
function formatError(err, opts) {
|
|
114
|
-
|
|
115
|
-
|
|
116
|
-
|
|
117
|
-
|
|
118
|
-
|
|
119
|
-
|
|
229
|
+
var _err_message;
|
|
230
|
+
var message = (_err_message = err.message) !== null && _err_message !== void 0 ? _err_message : formatWithOptions(opts, err);
|
|
231
|
+
var stack = err.stack ? formatStack(err.stack, message, opts) : '';
|
|
232
|
+
var level = (opts === null || opts === void 0 ? void 0 : opts.errorLevel) || 0;
|
|
233
|
+
var causedPrefix = level > 0 ? "".concat(' '.repeat(level), "[cause]: ") : '';
|
|
234
|
+
var causedError = err.cause ? '\n\n' + formatError(err.cause, _object_spread_props(_object_spread({}, opts), {
|
|
120
235
|
errorLevel: level + 1
|
|
121
|
-
}) : '';
|
|
236
|
+
})) : '';
|
|
122
237
|
return causedPrefix + message + '\n' + stack + causedError;
|
|
123
238
|
}
|
|
124
|
-
|
|
125
|
-
//# sourceMappingURL=formatLogObject.js.map
|
package/lib/consola/index.js
CHANGED
package/lib/data/formatSort.js
CHANGED
|
@@ -1,15 +1,14 @@
|
|
|
1
1
|
export function formatSort(s) {
|
|
2
|
-
return s.map((
|
|
2
|
+
return s.map(function(param) {
|
|
3
|
+
var field = param.field, order = param.order, nulls = param.nulls;
|
|
3
4
|
if (!field) return '';
|
|
4
|
-
|
|
5
|
+
var r = field;
|
|
5
6
|
if (order) {
|
|
6
|
-
r +=
|
|
7
|
+
r += " ".concat(order);
|
|
7
8
|
}
|
|
8
9
|
if (nulls) {
|
|
9
|
-
r +=
|
|
10
|
+
r += " nulls ".concat(nulls);
|
|
10
11
|
}
|
|
11
12
|
return r;
|
|
12
13
|
}).filter(Boolean);
|
|
13
14
|
}
|
|
14
|
-
|
|
15
|
-
//# sourceMappingURL=formatSort.js.map
|
|
@@ -0,0 +1,34 @@
|
|
|
1
|
+
import { expect, test } from "vitest";
|
|
2
|
+
import { formatSort } from "./formatSort.js";
|
|
3
|
+
test("formatSort", function () {
|
|
4
|
+
expect(formatSort([
|
|
5
|
+
{
|
|
6
|
+
field: "name",
|
|
7
|
+
order: "asc"
|
|
8
|
+
}
|
|
9
|
+
])).toEqual([
|
|
10
|
+
"name asc"
|
|
11
|
+
]);
|
|
12
|
+
expect(formatSort([
|
|
13
|
+
{
|
|
14
|
+
field: "age",
|
|
15
|
+
order: "desc",
|
|
16
|
+
nulls: "last"
|
|
17
|
+
}
|
|
18
|
+
])).toEqual([
|
|
19
|
+
"age desc nulls last"
|
|
20
|
+
]);
|
|
21
|
+
expect(formatSort([
|
|
22
|
+
{
|
|
23
|
+
field: "name",
|
|
24
|
+
order: "asc"
|
|
25
|
+
},
|
|
26
|
+
{
|
|
27
|
+
field: "age",
|
|
28
|
+
order: "desc"
|
|
29
|
+
}
|
|
30
|
+
])).toEqual([
|
|
31
|
+
"name asc",
|
|
32
|
+
"age desc"
|
|
33
|
+
]);
|
|
34
|
+
});
|
package/lib/data/index.js
CHANGED
package/lib/data/maybeNumber.js
CHANGED
|
@@ -1,22 +1,28 @@
|
|
|
1
|
+
function _type_of(obj) {
|
|
2
|
+
"@swc/helpers - typeof";
|
|
3
|
+
return obj && typeof Symbol !== "undefined" && obj.constructor === Symbol ? "symbol" : typeof obj;
|
|
4
|
+
}
|
|
1
5
|
export function maybeNumber(v) {
|
|
2
6
|
if (v === null || v === undefined) {
|
|
3
7
|
return undefined;
|
|
4
8
|
}
|
|
5
|
-
switch(typeof v){
|
|
9
|
+
switch(typeof v === "undefined" ? "undefined" : _type_of(v)){
|
|
6
10
|
case 'number':
|
|
7
11
|
return v;
|
|
8
12
|
case 'bigint':
|
|
13
|
+
if (v > BigInt(Number.MAX_SAFE_INTEGER) || v < BigInt(Number.MIN_SAFE_INTEGER)) {
|
|
14
|
+
throw new Error("bigint out of range");
|
|
15
|
+
}
|
|
9
16
|
return Number(v);
|
|
10
17
|
case 'string':
|
|
11
|
-
|
|
18
|
+
v = v.trim();
|
|
19
|
+
if (!v) {
|
|
12
20
|
return undefined;
|
|
13
21
|
}
|
|
14
22
|
}
|
|
15
|
-
|
|
23
|
+
var n = Number(v);
|
|
16
24
|
if (isNaN(n)) {
|
|
17
25
|
return undefined;
|
|
18
26
|
}
|
|
19
27
|
return n;
|
|
20
28
|
}
|
|
21
|
-
|
|
22
|
-
//# sourceMappingURL=maybeNumber.js.map
|
package/lib/data/parseSort.js
CHANGED
|
@@ -1,4 +1,8 @@
|
|
|
1
|
-
|
|
1
|
+
function _type_of(obj) {
|
|
2
|
+
"@swc/helpers - typeof";
|
|
3
|
+
return obj && typeof Symbol !== "undefined" && obj.constructor === Symbol ? "symbol" : typeof obj;
|
|
4
|
+
}
|
|
5
|
+
import { arrayOfMaybeArray } from '@wener/utils';
|
|
2
6
|
/**
|
|
3
7
|
* Parses various format of sort specifications into standardized SortRule objects
|
|
4
8
|
*
|
|
@@ -17,13 +21,13 @@ import { arrayOfMaybeArray } from "@wener/utils";
|
|
|
17
21
|
if (!order) {
|
|
18
22
|
return [];
|
|
19
23
|
}
|
|
20
|
-
return arrayOfMaybeArray(order).flatMap((v)
|
|
24
|
+
return arrayOfMaybeArray(order).flatMap(function(v) {
|
|
21
25
|
if (!v) return [];
|
|
22
|
-
if (typeof v === 'object') {
|
|
26
|
+
if ((typeof v === "undefined" ? "undefined" : _type_of(v)) === 'object') {
|
|
23
27
|
if (!v.field) {
|
|
24
28
|
return [];
|
|
25
29
|
}
|
|
26
|
-
|
|
30
|
+
var rule = {
|
|
27
31
|
field: v.field,
|
|
28
32
|
order: normalizeOrder(v.order)
|
|
29
33
|
};
|
|
@@ -32,26 +36,28 @@ import { arrayOfMaybeArray } from "@wener/utils";
|
|
|
32
36
|
}
|
|
33
37
|
return rule;
|
|
34
38
|
}
|
|
35
|
-
return v.split(',').map((v)
|
|
39
|
+
return v.split(',').map(function(v) {
|
|
40
|
+
return v.trim();
|
|
41
|
+
}).filter(Boolean).map(_parse);
|
|
36
42
|
});
|
|
37
43
|
}
|
|
38
44
|
/**
|
|
39
45
|
* Normalizes order values to 'asc' or 'desc'
|
|
40
46
|
*/ function normalizeOrder(order) {
|
|
41
|
-
return order
|
|
47
|
+
return (order === null || order === void 0 ? void 0 : order.toLowerCase()) === 'asc' ? 'asc' : 'desc';
|
|
42
48
|
}
|
|
43
49
|
/**
|
|
44
50
|
* Normalizes nulls values to 'last' or 'first'
|
|
45
51
|
*/ function normalizeNulls(nulls) {
|
|
46
|
-
return nulls
|
|
52
|
+
return (nulls === null || nulls === void 0 ? void 0 : nulls.toLowerCase()) === 'last' ? 'last' : 'first';
|
|
47
53
|
}
|
|
48
54
|
function _parse(v) {
|
|
49
|
-
|
|
50
|
-
|
|
51
|
-
|
|
52
|
-
|
|
55
|
+
var sp = v.split(/\s+/);
|
|
56
|
+
var field = '';
|
|
57
|
+
var order;
|
|
58
|
+
var nulls;
|
|
53
59
|
// Handle first token which should be the field name (possibly with +/- prefix)
|
|
54
|
-
|
|
60
|
+
var f = sp.shift();
|
|
55
61
|
if (!f) return {
|
|
56
62
|
field: '',
|
|
57
63
|
order: 'asc'
|
|
@@ -64,7 +70,8 @@ function _parse(v) {
|
|
|
64
70
|
}
|
|
65
71
|
// Process remaining tokens
|
|
66
72
|
while(sp.length > 0){
|
|
67
|
-
|
|
73
|
+
var _sp_shift_trim, _sp_shift;
|
|
74
|
+
var token = (_sp_shift = sp.shift()) === null || _sp_shift === void 0 ? void 0 : (_sp_shift_trim = _sp_shift.trim()) === null || _sp_shift_trim === void 0 ? void 0 : _sp_shift_trim.toLowerCase();
|
|
68
75
|
if (!token) continue;
|
|
69
76
|
switch(token){
|
|
70
77
|
case 'asc':
|
|
@@ -72,7 +79,8 @@ function _parse(v) {
|
|
|
72
79
|
order = token;
|
|
73
80
|
break;
|
|
74
81
|
case 'nulls':
|
|
75
|
-
|
|
82
|
+
var _sp_shift_trim1, _sp_shift1;
|
|
83
|
+
nulls = ((_sp_shift1 = sp.shift()) === null || _sp_shift1 === void 0 ? void 0 : (_sp_shift_trim1 = _sp_shift1.trim()) === null || _sp_shift_trim1 === void 0 ? void 0 : _sp_shift_trim1.toLowerCase()) === 'last' ? 'last' : 'first';
|
|
76
84
|
break;
|
|
77
85
|
case 'last':
|
|
78
86
|
case 'first':
|
|
@@ -80,16 +88,14 @@ function _parse(v) {
|
|
|
80
88
|
break;
|
|
81
89
|
}
|
|
82
90
|
}
|
|
83
|
-
order
|
|
91
|
+
order || (order = 'asc');
|
|
84
92
|
// Only include nulls if specified
|
|
85
93
|
return nulls ? {
|
|
86
|
-
field,
|
|
87
|
-
order,
|
|
88
|
-
nulls
|
|
94
|
+
field: field,
|
|
95
|
+
order: order,
|
|
96
|
+
nulls: nulls
|
|
89
97
|
} : {
|
|
90
|
-
field,
|
|
91
|
-
order
|
|
98
|
+
field: field,
|
|
99
|
+
order: order
|
|
92
100
|
};
|
|
93
101
|
}
|
|
94
|
-
|
|
95
|
-
//# sourceMappingURL=parseSort.js.map
|
|
@@ -0,0 +1,188 @@
|
|
|
1
|
+
import { describe, expect, test } from "vitest";
|
|
2
|
+
import { parseSort } from "./parseSort.js";
|
|
3
|
+
describe("parseSort", function () {
|
|
4
|
+
describe("basic parsing", function () {
|
|
5
|
+
test("handles empty inputs", function () {
|
|
6
|
+
expect(parseSort("")).toEqual([]);
|
|
7
|
+
expect(parseSort([])).toEqual([]);
|
|
8
|
+
expect(parseSort(null)).toEqual([]);
|
|
9
|
+
expect(parseSort(undefined)).toEqual([]);
|
|
10
|
+
});
|
|
11
|
+
test("handles simple field names", function () {
|
|
12
|
+
expect(parseSort("a")).toEqual([
|
|
13
|
+
{
|
|
14
|
+
field: "a",
|
|
15
|
+
order: "asc"
|
|
16
|
+
}
|
|
17
|
+
]);
|
|
18
|
+
expect(parseSort([
|
|
19
|
+
"a"
|
|
20
|
+
])).toEqual([
|
|
21
|
+
{
|
|
22
|
+
field: "a",
|
|
23
|
+
order: "asc"
|
|
24
|
+
}
|
|
25
|
+
]);
|
|
26
|
+
expect(parseSort("a.b")).toEqual([
|
|
27
|
+
{
|
|
28
|
+
field: "a.b",
|
|
29
|
+
order: "asc"
|
|
30
|
+
}
|
|
31
|
+
]);
|
|
32
|
+
});
|
|
33
|
+
test("handles prefix notation", function () {
|
|
34
|
+
expect(parseSort("-a")).toEqual([
|
|
35
|
+
{
|
|
36
|
+
field: "a",
|
|
37
|
+
order: "desc"
|
|
38
|
+
}
|
|
39
|
+
]);
|
|
40
|
+
expect(parseSort("+b")).toEqual([
|
|
41
|
+
{
|
|
42
|
+
field: "b",
|
|
43
|
+
order: "asc"
|
|
44
|
+
}
|
|
45
|
+
]);
|
|
46
|
+
expect(parseSort("-a,+b")).toEqual([
|
|
47
|
+
{
|
|
48
|
+
field: "a",
|
|
49
|
+
order: "desc"
|
|
50
|
+
},
|
|
51
|
+
{
|
|
52
|
+
field: "b",
|
|
53
|
+
order: "asc"
|
|
54
|
+
}
|
|
55
|
+
]);
|
|
56
|
+
});
|
|
57
|
+
});
|
|
58
|
+
describe("explicit ordering", function () {
|
|
59
|
+
test("handles explicit order keywords", function () {
|
|
60
|
+
expect(parseSort("a asc")).toEqual([
|
|
61
|
+
{
|
|
62
|
+
field: "a",
|
|
63
|
+
order: "asc"
|
|
64
|
+
}
|
|
65
|
+
]);
|
|
66
|
+
expect(parseSort("a desc")).toEqual([
|
|
67
|
+
{
|
|
68
|
+
field: "a",
|
|
69
|
+
order: "desc"
|
|
70
|
+
}
|
|
71
|
+
]);
|
|
72
|
+
expect(parseSort("-a asc")).toEqual([
|
|
73
|
+
{
|
|
74
|
+
field: "a",
|
|
75
|
+
order: "asc"
|
|
76
|
+
}
|
|
77
|
+
]); // explicit order overrides prefix
|
|
78
|
+
});
|
|
79
|
+
});
|
|
80
|
+
describe("nulls handling", function () {
|
|
81
|
+
test("handles nulls specification", function () {
|
|
82
|
+
expect(parseSort("a asc nulls last")).toEqual([
|
|
83
|
+
{
|
|
84
|
+
field: "a",
|
|
85
|
+
order: "asc",
|
|
86
|
+
nulls: "last"
|
|
87
|
+
}
|
|
88
|
+
]);
|
|
89
|
+
expect(parseSort("a asc nulls first")).toEqual([
|
|
90
|
+
{
|
|
91
|
+
field: "a",
|
|
92
|
+
order: "asc",
|
|
93
|
+
nulls: "first"
|
|
94
|
+
}
|
|
95
|
+
]);
|
|
96
|
+
expect(parseSort("a desc nulls last")).toEqual([
|
|
97
|
+
{
|
|
98
|
+
field: "a",
|
|
99
|
+
order: "desc",
|
|
100
|
+
nulls: "last"
|
|
101
|
+
}
|
|
102
|
+
]);
|
|
103
|
+
expect(parseSort("a nulls first")).toEqual([
|
|
104
|
+
{
|
|
105
|
+
field: "a",
|
|
106
|
+
order: "asc",
|
|
107
|
+
nulls: "first"
|
|
108
|
+
}
|
|
109
|
+
]);
|
|
110
|
+
expect(parseSort("-a nulls first")).toEqual([
|
|
111
|
+
{
|
|
112
|
+
field: "a",
|
|
113
|
+
order: "desc",
|
|
114
|
+
nulls: "first"
|
|
115
|
+
}
|
|
116
|
+
]);
|
|
117
|
+
// Alternative syntax
|
|
118
|
+
expect(parseSort("a asc last")).toEqual([
|
|
119
|
+
{
|
|
120
|
+
field: "a",
|
|
121
|
+
order: "asc",
|
|
122
|
+
nulls: "last"
|
|
123
|
+
}
|
|
124
|
+
]);
|
|
125
|
+
});
|
|
126
|
+
});
|
|
127
|
+
describe("object notation", function () {
|
|
128
|
+
test("handles object input", function () {
|
|
129
|
+
expect(parseSort([
|
|
130
|
+
{
|
|
131
|
+
field: "a",
|
|
132
|
+
order: "asc"
|
|
133
|
+
}
|
|
134
|
+
])).toEqual([
|
|
135
|
+
{
|
|
136
|
+
field: "a",
|
|
137
|
+
order: "asc"
|
|
138
|
+
}
|
|
139
|
+
]);
|
|
140
|
+
expect(parseSort([
|
|
141
|
+
{
|
|
142
|
+
field: "a",
|
|
143
|
+
order: "asc",
|
|
144
|
+
nulls: "last"
|
|
145
|
+
}
|
|
146
|
+
])).toEqual([
|
|
147
|
+
{
|
|
148
|
+
field: "a",
|
|
149
|
+
order: "asc",
|
|
150
|
+
nulls: "last"
|
|
151
|
+
}
|
|
152
|
+
]);
|
|
153
|
+
});
|
|
154
|
+
});
|
|
155
|
+
describe("invalid inputs", function () {
|
|
156
|
+
test("handles invalid inputs gracefully", function () {
|
|
157
|
+
expect(parseSort([
|
|
158
|
+
{
|
|
159
|
+
order: "asc"
|
|
160
|
+
}
|
|
161
|
+
])).toEqual([]);
|
|
162
|
+
expect(parseSort([
|
|
163
|
+
"a,,",
|
|
164
|
+
{
|
|
165
|
+
field: "",
|
|
166
|
+
order: "asc"
|
|
167
|
+
}
|
|
168
|
+
])).toEqual([
|
|
169
|
+
{
|
|
170
|
+
field: "a",
|
|
171
|
+
order: "asc"
|
|
172
|
+
}
|
|
173
|
+
]);
|
|
174
|
+
expect(parseSort([
|
|
175
|
+
",,",
|
|
176
|
+
{
|
|
177
|
+
field: "a",
|
|
178
|
+
order: "asc"
|
|
179
|
+
}
|
|
180
|
+
])).toEqual([
|
|
181
|
+
{
|
|
182
|
+
field: "a",
|
|
183
|
+
order: "asc"
|
|
184
|
+
}
|
|
185
|
+
]);
|
|
186
|
+
});
|
|
187
|
+
});
|
|
188
|
+
});
|