@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.
Files changed (151) 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 +18 -0
  14. package/lib/consola/formatLogObject.js +226 -0
  15. package/lib/consola/index.js +2 -0
  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 +80 -54
  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 +201 -0
  77. package/lib/tools/renderJsonSchemaToMarkdownDoc.js +143 -55
  78. package/package.json +30 -9
  79. package/src/consola/createStandardConsolaReporter.ts +31 -0
  80. package/src/consola/formatLogObject.ts +171 -0
  81. package/src/consola/index.ts +2 -0
  82. package/src/data/maybeNumber.ts +5 -1
  83. package/src/data/resolvePagination.test.ts +1 -1
  84. package/src/data/resolvePagination.ts +18 -7
  85. package/src/data/types.d.ts +12 -0
  86. package/src/jsonschema/JsonSchema.test.ts +17 -0
  87. package/src/jsonschema/JsonSchema.ts +4 -4
  88. package/src/jsonschema/types.d.ts +63 -12
  89. package/src/resource/Identifiable.ts +3 -0
  90. package/src/resource/getTitleOfResource.tsx +6 -0
  91. package/src/resource/index.ts +3 -0
  92. package/src/resource/schema/AnyResourceSchema.ts +113 -0
  93. package/src/resource/schema/BaseResourceSchema.ts +32 -0
  94. package/src/resource/schema/ResourceActionType.ts +123 -0
  95. package/src/resource/schema/ResourceStatus.ts +94 -0
  96. package/src/resource/schema/ResourceType.ts +25 -0
  97. package/src/resource/schema/SchemaRegistry.ts +42 -0
  98. package/src/resource/schema/SexType.ts +13 -0
  99. package/src/resource/schema/types.test.ts +18 -0
  100. package/src/resource/schema/types.ts +105 -0
  101. package/src/schema/TypeSchema.d.ts +32 -0
  102. package/src/schema/createSchemaData.ts +81 -0
  103. package/src/schema/findJsonSchemaByPath.ts +37 -0
  104. package/src/schema/getSchemaCache.ts +21 -0
  105. package/src/schema/getSchemaOptions.ts +24 -0
  106. package/src/schema/index.ts +6 -0
  107. package/src/schema/toJsonSchema.test.ts +37 -0
  108. package/src/schema/toJsonSchema.ts +200 -0
  109. package/src/schema/validate.ts +135 -0
  110. package/src/tools/generateSchema.ts +39 -0
  111. package/lib/cn/DivisionCode.js.map +0 -1
  112. package/lib/cn/Mod11Checksum.js.map +0 -1
  113. package/lib/cn/Mod31Checksum.js.map +0 -1
  114. package/lib/cn/ResidentIdentityCardNumber.js.map +0 -1
  115. package/lib/cn/UnifiedSocialCreditCode.js.map +0 -1
  116. package/lib/cn/formatDate.js.map +0 -1
  117. package/lib/cn/index.js.map +0 -1
  118. package/lib/cn/parseSex.js.map +0 -1
  119. package/lib/cn/types.d.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/renderJsonSchemaToMarkdownDoc.js.map +0 -1
@@ -1,6 +1,6 @@
1
1
  import { Mod31Checksum } from "./Mod31Checksum.js";
2
2
  (function (UnifiedSocialCreditCode) {
3
- const CodeLabels = {
3
+ var CodeLabels = {
4
4
  1: {
5
5
  label: "\u673A\u6784\u7F16\u5236",
6
6
  children: {
@@ -64,41 +64,46 @@ import { Mod31Checksum } from "./Mod31Checksum.js";
64
64
  UnifiedSocialCreditCode.pattern = /^([159][1239]|Y1)[0-9]{6}[0-9A-HJ-NP-RTUWXY]{10}$/; // 无 I O Z S V
65
65
  UnifiedSocialCreditCode.Checksum = new Mod31Checksum();
66
66
  function parse(s) {
67
- let bureau = s[0];
68
- let subjectType = s[1];
69
- let division = s.slice(2, 8); // 第3~8位,共6位,正确
70
- let subject = s.slice(8, 17); // 第9~17位,共9位
71
- let checksum = s.slice(17, 18); // 第18位,校验码
72
- const labels = [];
73
- let l1 = CodeLabels[bureau];
74
- l1 && labels.push(l1?.label);
75
- let l2 = l1?.children?.[subjectType];
76
- l2 && labels.push(l2?.label);
67
+ var _l1_children;
68
+ var bureau = s[0];
69
+ var subjectType = s[1];
70
+ var division = s.slice(2, 8); // 第3~8位,共6位,正确
71
+ var subject = s.slice(8, 17); // 第9~17位,共9位
72
+ var checksum = s.slice(17, 18); // 第18位,校验码
73
+ var labels = [];
74
+ var l1 = CodeLabels[bureau];
75
+ l1 && labels.push(l1 === null || l1 === void 0 ? void 0 : l1.label);
76
+ var l2 = l1 === null || l1 === void 0 ? void 0 : (_l1_children = l1.children) === null || _l1_children === void 0 ? void 0 : _l1_children[subjectType];
77
+ l2 && labels.push(l2 === null || l2 === void 0 ? void 0 : l2.label);
77
78
  return {
78
- bureau,
79
- subjectType,
80
- division,
81
- subject,
82
- checksum,
79
+ bureau: bureau,
80
+ subjectType: subjectType,
81
+ division: division,
82
+ subject: subject,
83
+ checksum: checksum,
83
84
  codes: [
84
85
  bureau,
85
86
  subjectType,
86
87
  division,
87
88
  subject
88
89
  ],
89
- labels
90
+ labels: labels
90
91
  };
91
92
  }
92
93
  UnifiedSocialCreditCode.parse = parse;
93
- function format({ bureau, subjectType, division, subject, checksum }) {
94
- const base = `${bureau}${subjectType}${division}${subject}`;
95
- checksum ||= UnifiedSocialCreditCode.Checksum.compute(base);
96
- return `${base}${checksum}`;
94
+ function format(param) {
95
+ var bureau = param.bureau, subjectType = param.subjectType, division = param.division, subject = param.subject, checksum = param.checksum;
96
+ var base = "".concat(bureau).concat(subjectType).concat(division).concat(subject);
97
+ checksum || (checksum = UnifiedSocialCreditCode.Checksum.compute(base));
98
+ return "".concat(base).concat(checksum);
97
99
  }
98
100
  UnifiedSocialCreditCode.format = format;
99
- function next(s, delta = 1) {
100
- const sp = s.split("").map((v) => UnifiedSocialCreditCode.Checksum.numbers[v]);
101
- for (let i = sp.length - 1; i >= 0; i--) {
101
+ function next(s) {
102
+ var delta = arguments.length > 1 && arguments[1] !== void 0 ? arguments[1] : 1;
103
+ var sp = s.split("").map(function (v) {
104
+ return UnifiedSocialCreditCode.Checksum.numbers[v];
105
+ });
106
+ for (var i = sp.length - 1; i >= 0; i--) {
102
107
  if (delta > 0 && sp[i] < 30 || delta < 0 && sp[i] > 0) {
103
108
  sp[i] += delta;
104
109
  break;
@@ -110,9 +115,10 @@ import { Mod31Checksum } from "./Mod31Checksum.js";
110
115
  sp[i] = 30;
111
116
  }
112
117
  }
113
- return sp.map((v) => UnifiedSocialCreditCode.Checksum.chars[v]).join("");
118
+ return sp.map(function (v) {
119
+ return UnifiedSocialCreditCode.Checksum.chars[v];
120
+ }).join("");
114
121
  }
115
122
  UnifiedSocialCreditCode.next = next;
116
123
  })(UnifiedSocialCreditCode || (UnifiedSocialCreditCode = {}));
117
124
  export var UnifiedSocialCreditCode;
118
- //# sourceMappingURL=UnifiedSocialCreditCode.js.map
@@ -0,0 +1,16 @@
1
+ import { describe, expect, it } from "vitest";
2
+ import { UnifiedSocialCreditCode } from "./UnifiedSocialCreditCode.js";
3
+ describe("UnifiedSocialCreditCode", function () {
4
+ it("should parse", function () {
5
+ for (var _i = 0, _iter = [
6
+ //
7
+ "91330106673959654P",
8
+ "91330106MA2CFLDG4R"
9
+ ]; _i < _iter.length; _i++) {
10
+ var a = _iter[_i];
11
+ var out = UnifiedSocialCreditCode.parse(a);
12
+ expect(UnifiedSocialCreditCode.format(out)).toBe(a);
13
+ expect(out).toMatchSnapshot();
14
+ }
15
+ });
16
+ });
@@ -2,14 +2,12 @@ export function formatDate(date, format) {
2
2
  switch(format){
3
3
  case 'yyyyMMDD':
4
4
  {
5
- const year = date.getFullYear();
6
- const month = (date.getMonth() + 1).toString().padStart(2, '0');
7
- const day = date.getDate().toString().padStart(2, '0');
8
- return `${year}${month}${day}`;
5
+ var year = date.getFullYear();
6
+ var month = (date.getMonth() + 1).toString().padStart(2, '0');
7
+ var day = date.getDate().toString().padStart(2, '0');
8
+ return "".concat(year).concat(month).concat(day);
9
9
  }
10
10
  default:
11
- throw new Error(`Invalid format`);
11
+ throw new Error("Invalid format");
12
12
  }
13
13
  }
14
-
15
- //# sourceMappingURL=formatDate.js.map
package/lib/cn/index.js CHANGED
@@ -1,4 +1,3 @@
1
1
  export { ResidentIdentityCardNumber } from "./ResidentIdentityCardNumber.js";
2
2
  export { DivisionCode } from "./DivisionCode.js";
3
3
  export { UnifiedSocialCreditCode } from "./UnifiedSocialCreditCode.js";
4
- //# sourceMappingURL=index.js.map
@@ -18,5 +18,3 @@ export function parseSex(s) {
18
18
  }
19
19
  return undefined;
20
20
  }
21
-
22
- //# sourceMappingURL=parseSex.js.map
package/lib/cn/types.d.js CHANGED
@@ -4,5 +4,3 @@
4
4
  * @see https://en.wikipedia.org/wiki/Resident_Identity_Card
5
5
  * @see https://en.wikipedia.org/wiki/Foreign_Permanent_Resident_ID_Card
6
6
  */ export { };
7
-
8
- //# sourceMappingURL=types.d.js.map
@@ -0,0 +1,18 @@
1
+ import { formatLogObject } from "./formatLogObject.js";
2
+ export function createStandardConsolaReporter() {
3
+ var _ref = arguments.length > 0 && arguments[0] !== void 0 ? arguments[0] : {}, _ref_format = _ref.format, format = _ref_format === void 0 ? formatLogObject : _ref_format;
4
+ return {
5
+ log: function (o, ctx) {
6
+ var out = format(o, ctx);
7
+ var fn = console.log;
8
+ var level = o.level;
9
+ if (level < 1) {
10
+ fn = console.error;
11
+ }
12
+ else if (level === 1) {
13
+ fn = console.warn;
14
+ }
15
+ fn(out);
16
+ }
17
+ };
18
+ }
@@ -0,0 +1,226 @@
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 from 'chalk';
88
+ import dayjs from 'dayjs';
89
+ import { isDevelopment } from 'std-env';
90
+ var levelColors = {
91
+ trace: colors.gray,
92
+ debug: colors.cyan,
93
+ info: colors.blueBright,
94
+ warn: colors.yellow,
95
+ error: colors.red,
96
+ fatal: colors.bgRed.white,
97
+ silent: colors.white,
98
+ log: colors.white,
99
+ success: colors.green,
100
+ fail: colors.red,
101
+ ready: colors.green,
102
+ start: colors.cyan,
103
+ box: colors.white,
104
+ verbose: colors.green
105
+ };
106
+ var levelShort = {
107
+ trace: 'TRAC',
108
+ debug: 'DEBG',
109
+ info: 'INFO',
110
+ warn: 'WARN',
111
+ error: 'ERRO',
112
+ fatal: 'FATL',
113
+ silent: 'SLNT',
114
+ log: 'LOG ',
115
+ success: 'SUCC',
116
+ fail: 'FAIL',
117
+ ready: 'READ',
118
+ start: 'STRT',
119
+ box: 'BOX ',
120
+ verbose: 'VERB'
121
+ };
122
+ var start = Date.now();
123
+ export function formatLogObject(o, ctx) {
124
+ var date = o.date, type = o.type, tag = o.tag;
125
+ type = type === 'log' ? 'info' : type;
126
+ var color = levelColors[type] || colors.white;
127
+ var levelText = levelShort[type] || type.toUpperCase().slice(0, 4); // Get first 4 chars, consistent uppercase
128
+ var line = '';
129
+ var out = [];
130
+ // Timestamp
131
+ if (isDevelopment) {
132
+ // process.hrtime.bigint()
133
+ var diff = (date.getTime() - start) / 1000;
134
+ out.push(colors.gray(diff.toFixed(3).padStart(7, ' ')));
135
+ } else {
136
+ out.push(colors.gray(dayjs(date).format('YYYY-MM-DD HH:mm:ss.SSS')));
137
+ }
138
+ // Log Level (colored)
139
+ // Pad to 4 characters
140
+ out.push(color(levelText.padEnd(4, ' ')));
141
+ if (tag) {
142
+ out.push(colors.yellow("[".concat(tag, "]"))); // Added color for tag
143
+ }
144
+ {
145
+ var _formatArgs_split = _to_array(formatArgs(o.args, ctx).split('\n')), message = _formatArgs_split[0], additional = _formatArgs_split.slice(1);
146
+ out.push(characterFormat(message));
147
+ line = out.join(' ');
148
+ if (additional.length > 0) {
149
+ line += characterFormat(additional.join('\n'));
150
+ }
151
+ if (type === 'trace') {
152
+ var _err = new Error('Trace: ' + o.message);
153
+ line += formatStack(_err.stack || '', _err.message);
154
+ }
155
+ }
156
+ // if (!message && typeof args[0] === 'string') {
157
+ // message = args.shift();
158
+ // }
159
+ // if (message) {
160
+ // out.push(message);
161
+ // }
162
+ // if (args.length) {
163
+ // out.push(...args.map((a) => (typeof a === 'string' ? a : JSON.stringify(a)))); // Handle non-string args
164
+ // }
165
+ // todo format error
166
+ // https://github.com/unjs/consola/blob/main/src/reporters/fancy.ts
167
+ // return out.join(' '); // Increased spacing for better readability
168
+ return line;
169
+ }
170
+ function characterFormat(str) {
171
+ return str// highlight backticks
172
+ .replace(/`([^`]+)`/gm, function(_, m) {
173
+ return colors.cyan(m);
174
+ })// underline underscores
175
+ .replace(/\s+_([^_]+)_\s+/gm, function(_, m) {
176
+ return " ".concat(colors.underline(m), " ");
177
+ });
178
+ }
179
+ function parseStack(stack, message) {
180
+ // const cwd = process.cwd() + sep;
181
+ var lines = stack.split('\n').splice(message.split('\n').length).map(function(l) {
182
+ return l.trim().replace('file://', '');
183
+ });
184
+ return lines;
185
+ }
186
+ function formatStack(stack, message, opts) {
187
+ var indent = ' '.repeat(((opts === null || opts === void 0 ? void 0 : opts.errorLevel) || 0) + 1);
188
+ return "\n".concat(indent) + parseStack(stack, message).map(function(line) {
189
+ return ' ' + line.replace(/^at +/, function(m) {
190
+ return colors.gray(m);
191
+ }).replace(/\((.+)\)/, function(_, m) {
192
+ return "(".concat(colors.cyan(m), ")");
193
+ });
194
+ }).join("\n".concat(indent));
195
+ }
196
+ function formatArgs(args, opts) {
197
+ var _args = args.map(function(arg) {
198
+ if (arg && typeof arg.stack === 'string') {
199
+ return formatError(arg, opts);
200
+ }
201
+ return arg;
202
+ });
203
+ // Only supported with Node >= 10
204
+ // https://nodejs.org/api/util.html#util_util_inspect_object_options
205
+ return formatWithOptions.apply(void 0, [
206
+ opts
207
+ ].concat(_to_consumable_array(_args)));
208
+ }
209
+ function formatWithOptions(o) {
210
+ for(var _len = arguments.length, params = new Array(_len > 1 ? _len - 1 : 0), _key = 1; _key < _len; _key++){
211
+ params[_key - 1] = arguments[_key];
212
+ }
213
+ // import { formatWithOptions } from 'node:util';
214
+ return params.join(' ');
215
+ }
216
+ function formatError(err, opts) {
217
+ var _err_message;
218
+ var message = (_err_message = err.message) !== null && _err_message !== void 0 ? _err_message : formatWithOptions(opts, err);
219
+ var stack = err.stack ? formatStack(err.stack, message, opts) : '';
220
+ var level = (opts === null || opts === void 0 ? void 0 : opts.errorLevel) || 0;
221
+ var causedPrefix = level > 0 ? "".concat(' '.repeat(level), "[cause]: ") : '';
222
+ var causedError = err.cause ? '\n\n' + formatError(err.cause, _object_spread_props(_object_spread({}, opts), {
223
+ errorLevel: level + 1
224
+ })) : '';
225
+ return causedPrefix + message + '\n' + stack + causedError;
226
+ }
@@ -0,0 +1,2 @@
1
+ export { formatLogObject } from "./formatLogObject.js";
2
+ export { createStandardConsolaReporter } from "./createStandardConsolaReporter.js";
@@ -1,15 +1,14 @@
1
1
  export function formatSort(s) {
2
- return s.map(({ field, order, nulls })=>{
2
+ return s.map(function(param) {
3
+ var field = param.field, order = param.order, nulls = param.nulls;
3
4
  if (!field) return '';
4
- let r = field;
5
+ var r = field;
5
6
  if (order) {
6
- r += ` ${order}`;
7
+ r += " ".concat(order);
7
8
  }
8
9
  if (nulls) {
9
- r += ` nulls ${nulls}`;
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
@@ -1,4 +1,3 @@
1
1
  export { resolvePagination } from "./resolvePagination.js";
2
2
  export { parseSort } from "./parseSort.js";
3
3
  export { formatSort } from "./formatSort.js";
4
- //# sourceMappingURL=index.js.map
@@ -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
- if (v === '') {
18
+ v = v.trim();
19
+ if (!v) {
12
20
  return undefined;
13
21
  }
14
22
  }
15
- const n = Number(v);
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
@@ -1,4 +1,8 @@
1
- import { arrayOfMaybeArray } from "@wener/utils";
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
- const rule = {
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)=>v.trim()).filter(Boolean).map(_parse);
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?.toLowerCase() === 'asc' ? 'asc' : 'desc';
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?.toLowerCase() === 'last' ? 'last' : 'first';
52
+ return (nulls === null || nulls === void 0 ? void 0 : nulls.toLowerCase()) === 'last' ? 'last' : 'first';
47
53
  }
48
54
  function _parse(v) {
49
- const sp = v.split(/\s+/);
50
- let field = '';
51
- let order;
52
- let nulls;
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
- const f = sp.shift();
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
- const token = sp.shift()?.trim()?.toLowerCase();
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
- nulls = sp.shift()?.trim()?.toLowerCase() === 'last' ? 'last' : 'first';
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 ||= 'asc';
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