@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,43 +1,201 @@
1
- import { exec } from "node:child_process";
2
- import fs from "node:fs/promises";
3
- import path from "node:path";
4
- import * as Codegen from "@sinclair/typebox-codegen";
5
- export async function generateSchema({ file, dir = path.dirname(file) }) {
6
- const fn = path.basename(file).replace(/\.d\.ts$/, '.ts');
7
- const types = await fs.readFile(file, 'utf-8');
8
- const typeboxDir = path.join(dir, 'typebox');
9
- const zodDir = path.join(dir, 'zod');
10
- await fs.mkdir(typeboxDir, {
11
- recursive: true
12
- });
13
- await fs.mkdir(zodDir, {
14
- recursive: true
15
- });
16
- const typeBoxFile = path.join(typeboxDir, fn);
17
- const zodFile = path.join(zodDir, fn);
18
- {
19
- // avoid import type error
20
- let out = Codegen.TypeScriptToTypeBox.Generate(types);
21
- out = out.replace(/^import \{ Type, Static\b/, `import { Type, type Static`);
22
- await fs.writeFile(typeBoxFile, out);
1
+ function asyncGeneratorStep(gen, resolve, reject, _next, _throw, key, arg) {
2
+ try {
3
+ var info = gen[key](arg);
4
+ var value = info.value;
5
+ } catch (error) {
6
+ reject(error);
7
+ return;
23
8
  }
24
- const model = Codegen.TypeScriptToModel.Generate(types);
25
- await fs.writeFile(zodFile, Codegen.ModelToZod.Generate(model));
26
- await new Promise((resolve, reject)=>{
27
- exec(`pnpm prettier --write "${dir}/{typebox,zod}/*.ts"`, (error, stdout, stderr)=>{
28
- if (error) {
29
- console.error(`exec error: ${error}`);
30
- reject(error);
31
- return;
9
+ if (info.done) {
10
+ resolve(value);
11
+ } else {
12
+ Promise.resolve(value).then(_next, _throw);
13
+ }
14
+ }
15
+ function _async_to_generator(fn) {
16
+ return function() {
17
+ var self = this, args = arguments;
18
+ return new Promise(function(resolve, reject) {
19
+ var gen = fn.apply(self, args);
20
+ function _next(value) {
21
+ asyncGeneratorStep(gen, resolve, reject, _next, _throw, "next", value);
22
+ }
23
+ function _throw(err) {
24
+ asyncGeneratorStep(gen, resolve, reject, _next, _throw, "throw", err);
25
+ }
26
+ _next(undefined);
27
+ });
28
+ };
29
+ }
30
+ function _ts_generator(thisArg, body) {
31
+ var f, y, t, _ = {
32
+ label: 0,
33
+ sent: function() {
34
+ if (t[0] & 1) throw t[1];
35
+ return t[1];
36
+ },
37
+ trys: [],
38
+ ops: []
39
+ }, g = Object.create((typeof Iterator === "function" ? Iterator : Object).prototype);
40
+ return g.next = verb(0), g["throw"] = verb(1), g["return"] = verb(2), typeof Symbol === "function" && (g[Symbol.iterator] = function() {
41
+ return this;
42
+ }), g;
43
+ function verb(n) {
44
+ return function(v) {
45
+ return step([
46
+ n,
47
+ v
48
+ ]);
49
+ };
50
+ }
51
+ function step(op) {
52
+ if (f) throw new TypeError("Generator is already executing.");
53
+ while(g && (g = 0, op[0] && (_ = 0)), _)try {
54
+ 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) return t;
55
+ if (y = 0, t) op = [
56
+ op[0] & 2,
57
+ t.value
58
+ ];
59
+ switch(op[0]){
60
+ case 0:
61
+ case 1:
62
+ t = op;
63
+ break;
64
+ case 4:
65
+ _.label++;
66
+ return {
67
+ value: op[1],
68
+ done: false
69
+ };
70
+ case 5:
71
+ _.label++;
72
+ y = op[1];
73
+ op = [
74
+ 0
75
+ ];
76
+ continue;
77
+ case 7:
78
+ op = _.ops.pop();
79
+ _.trys.pop();
80
+ continue;
81
+ default:
82
+ if (!(t = _.trys, t = t.length > 0 && t[t.length - 1]) && (op[0] === 6 || op[0] === 2)) {
83
+ _ = 0;
84
+ continue;
85
+ }
86
+ if (op[0] === 3 && (!t || op[1] > t[0] && op[1] < t[3])) {
87
+ _.label = op[1];
88
+ break;
89
+ }
90
+ if (op[0] === 6 && _.label < t[1]) {
91
+ _.label = t[1];
92
+ t = op;
93
+ break;
94
+ }
95
+ if (t && _.label < t[2]) {
96
+ _.label = t[2];
97
+ _.ops.push(op);
98
+ break;
99
+ }
100
+ if (t[2]) _.ops.pop();
101
+ _.trys.pop();
102
+ continue;
103
+ }
104
+ op = body.call(thisArg, _);
105
+ } catch (e) {
106
+ op = [
107
+ 6,
108
+ e
109
+ ];
110
+ y = 0;
111
+ } finally{
112
+ f = t = 0;
113
+ }
114
+ if (op[0] & 5) throw op[1];
115
+ return {
116
+ value: op[0] ? op[1] : void 0,
117
+ done: true
118
+ };
119
+ }
120
+ }
121
+ import { exec } from 'node:child_process';
122
+ import fs from 'node:fs/promises';
123
+ import path from 'node:path';
124
+ import * as Codegen from '@sinclair/typebox-codegen';
125
+ export function generateSchema(_0) {
126
+ return _async_to_generator(function(param) {
127
+ var file, _param_dir, dir, fn, types, typeboxDir, zodDir, typeBoxFile, zodFile, out, model;
128
+ return _ts_generator(this, function(_state) {
129
+ switch(_state.label){
130
+ case 0:
131
+ file = param.file, _param_dir = param.dir, dir = _param_dir === void 0 ? path.dirname(file) : _param_dir;
132
+ fn = path.basename(file).replace(/\.d\.ts$/, '.ts');
133
+ return [
134
+ 4,
135
+ fs.readFile(file, 'utf-8')
136
+ ];
137
+ case 1:
138
+ types = _state.sent();
139
+ typeboxDir = path.join(dir, 'typebox');
140
+ zodDir = path.join(dir, 'zod');
141
+ return [
142
+ 4,
143
+ fs.mkdir(typeboxDir, {
144
+ recursive: true
145
+ })
146
+ ];
147
+ case 2:
148
+ _state.sent();
149
+ return [
150
+ 4,
151
+ fs.mkdir(zodDir, {
152
+ recursive: true
153
+ })
154
+ ];
155
+ case 3:
156
+ _state.sent();
157
+ typeBoxFile = path.join(typeboxDir, fn);
158
+ zodFile = path.join(zodDir, fn);
159
+ // avoid import type error
160
+ out = Codegen.TypeScriptToTypeBox.Generate(types);
161
+ out = out.replace(/^import \{ Type, Static\b/, "import { Type, type Static");
162
+ return [
163
+ 4,
164
+ fs.writeFile(typeBoxFile, out)
165
+ ];
166
+ case 4:
167
+ _state.sent();
168
+ model = Codegen.TypeScriptToModel.Generate(types);
169
+ return [
170
+ 4,
171
+ fs.writeFile(zodFile, Codegen.ModelToZod.Generate(model))
172
+ ];
173
+ case 5:
174
+ _state.sent();
175
+ return [
176
+ 4,
177
+ new Promise(function(resolve, reject) {
178
+ exec('pnpm prettier --write "'.concat(dir, '/{typebox,zod}/*.ts"'), function(error, stdout, stderr) {
179
+ if (error) {
180
+ console.error("exec error: ".concat(error));
181
+ reject(error);
182
+ return;
183
+ }
184
+ resolve({
185
+ stderr: stderr,
186
+ stdout: stdout
187
+ });
188
+ stdout && console.log("prettier:stdout: ".concat(stdout));
189
+ stderr && console.error("prettier:stderr: ".concat(stderr));
190
+ });
191
+ })
192
+ ];
193
+ case 6:
194
+ _state.sent();
195
+ return [
196
+ 2
197
+ ];
32
198
  }
33
- resolve({
34
- stderr,
35
- stdout
36
- });
37
- stdout && console.log(`prettier:stdout: ${stdout}`);
38
- stderr && console.error(`prettier:stderr: ${stderr}`);
39
199
  });
40
- });
200
+ }).apply(this, arguments);
41
201
  }
42
-
43
- //# sourceMappingURL=generateSchema.js.map
@@ -1,85 +1,173 @@
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 _iterable_to_array_limit(arr, i) {
10
+ var _i = arr == null ? null : typeof Symbol !== "undefined" && arr[Symbol.iterator] || arr["@@iterator"];
11
+ if (_i == null) return;
12
+ var _arr = [];
13
+ var _n = true;
14
+ var _d = false;
15
+ var _s, _e;
16
+ try {
17
+ for(_i = _i.call(arr); !(_n = (_s = _i.next()).done); _n = true){
18
+ _arr.push(_s.value);
19
+ if (i && _arr.length === i) break;
20
+ }
21
+ } catch (err) {
22
+ _d = true;
23
+ _e = err;
24
+ } finally{
25
+ try {
26
+ if (!_n && _i["return"] != null) _i["return"]();
27
+ } finally{
28
+ if (_d) throw _e;
29
+ }
30
+ }
31
+ return _arr;
32
+ }
33
+ function _non_iterable_rest() {
34
+ throw new TypeError("Invalid attempt to destructure non-iterable instance.\\nIn order to be iterable, non-array objects must have a [Symbol.iterator]() method.");
35
+ }
36
+ function _sliced_to_array(arr, i) {
37
+ return _array_with_holes(arr) || _iterable_to_array_limit(arr, i) || _unsupported_iterable_to_array(arr, i) || _non_iterable_rest();
38
+ }
39
+ function _unsupported_iterable_to_array(o, minLen) {
40
+ if (!o) return;
41
+ if (typeof o === "string") return _array_like_to_array(o, minLen);
42
+ var n = Object.prototype.toString.call(o).slice(8, -1);
43
+ if (n === "Object" && o.constructor) n = o.constructor.name;
44
+ if (n === "Map" || n === "Set") return Array.from(n);
45
+ if (n === "Arguments" || /^(?:Ui|I)nt(?:8|16|32)(?:Clamped)?Array$/.test(n)) return _array_like_to_array(o, minLen);
46
+ }
1
47
  export function renderJsonSchemaToMarkdownDoc(rootSchema) {
2
48
  // markdown
3
- const out = [];
4
- const all = new Set();
5
- const pending = [];
6
- const addObject = (o)=>{
49
+ var out = [];
50
+ var all = new Set();
51
+ var pending = [];
52
+ var addObject = function(o) {
7
53
  if (all.has(o.$id)) {
8
54
  return;
9
55
  }
10
56
  all.add(o.$id);
11
57
  pending.push(o);
12
58
  };
13
- const writeObjectProps = (T, { prefix = '' } = {})=>{
14
- if (!T?.properties) {
59
+ var writeObjectProps = function(T) {
60
+ var _ref = arguments.length > 1 && arguments[1] !== void 0 ? arguments[1] : {}, _ref_prefix = _ref.prefix, prefix = _ref_prefix === void 0 ? '' : _ref_prefix;
61
+ if (!(T === null || T === void 0 ? void 0 : T.properties)) {
15
62
  return;
16
63
  }
17
- for (const [name, schema] of Object.entries(T.properties)){
18
- let typ = schema.$id || schema.type;
19
- if (typ === 'array') {
20
- typ = `${schema.items.$id || schema.items.type}[]`;
21
- if (schema.items.$id) {
22
- addObject(schema.items);
64
+ var _iteratorNormalCompletion = true, _didIteratorError = false, _iteratorError = undefined;
65
+ try {
66
+ for(var _iterator = Object.entries(T.properties)[Symbol.iterator](), _step; !(_iteratorNormalCompletion = (_step = _iterator.next()).done); _iteratorNormalCompletion = true){
67
+ var _step_value = _sliced_to_array(_step.value, 2), name = _step_value[0], schema = _step_value[1];
68
+ var typ = schema.$id || schema.type;
69
+ if (typ === 'array') {
70
+ typ = "".concat(schema.items.$id || schema.items.type, "[]");
71
+ if (schema.items.$id) {
72
+ addObject(schema.items);
73
+ }
74
+ } else if (schema.$id) {
75
+ addObject(schema);
23
76
  }
24
- } else if (schema.$id) {
25
- addObject(schema);
26
- }
27
- if (!typ) {
28
- if ('anyOf' in schema) {
29
- typ = 'enum';
77
+ if (!typ) {
78
+ if ('anyOf' in schema) {
79
+ typ = 'enum';
80
+ }
30
81
  }
31
- }
32
- out.push(`| ${prefix}${name} | ${typ} | ${schema.title || schema.description || ''} |`);
33
- if (typ === 'object') {
34
- writeObjectProps(schema, {
35
- prefix: `${prefix}${name}.`
36
- });
37
- } else if (schema.type === 'array') {
38
- if (schema.items.type === 'object' && !schema.items.$id) {
39
- writeObjectProps(schema.items, {
40
- prefix: `${prefix}${name}[].`
82
+ out.push("| ".concat(prefix).concat(name, " | ").concat(typ, " | ").concat(schema.title || schema.description || '', " |"));
83
+ if (typ === 'object') {
84
+ writeObjectProps(schema, {
85
+ prefix: "".concat(prefix).concat(name, ".")
41
86
  });
87
+ } else if (schema.type === 'array') {
88
+ if (schema.items.type === 'object' && !schema.items.$id) {
89
+ writeObjectProps(schema.items, {
90
+ prefix: "".concat(prefix).concat(name, "[].")
91
+ });
92
+ }
93
+ }
94
+ }
95
+ } catch (err) {
96
+ _didIteratorError = true;
97
+ _iteratorError = err;
98
+ } finally{
99
+ try {
100
+ if (!_iteratorNormalCompletion && _iterator.return != null) {
101
+ _iterator.return();
102
+ }
103
+ } finally{
104
+ if (_didIteratorError) {
105
+ throw _iteratorError;
42
106
  }
43
107
  }
44
108
  }
45
109
  };
46
- const writeObject = (T)=>{
47
- out.push(`### ${T.title || T.$id}`);
48
- out.push(`
49
- | $id | 名字 |
50
- | --- | --- |
51
- | ${T.$id || ''} | ${T.title || ''} |
52
- `);
110
+ var writeObject = function(T) {
111
+ out.push("### ".concat(T.title || T.$id));
112
+ out.push("\n| $id | 名字 |\n| --- | --- |\n| ".concat(T.$id || '', " | ").concat(T.title || '', " | \n "));
53
113
  if (T.description) {
54
114
  out.push('');
55
- out.push(`> ${T.description}`);
115
+ out.push("> ".concat(T.description));
56
116
  out.push('');
57
117
  }
58
- out.push(`| 名字 | 类型 | 说明 |`);
59
- out.push(`| --- | --- | --- |`);
118
+ out.push("| 名字 | 类型 | 说明 |");
119
+ out.push("| --- | --- | --- |");
60
120
  writeObjectProps(T);
61
121
  out.push('');
62
122
  };
63
123
  writeObject(rootSchema);
64
- for (const schema of pending){
65
- if (schema.type === 'object') {
66
- writeObject(schema);
67
- } else if ('anyOf' in schema) {
68
- out.push(`### ${schema.$id || schema.title}`);
69
- out.push(`
70
- | $id | 名字 |
71
- | --- | --- |
72
- | ${schema.$id || ''} | ${schema.title || ''} |
73
- `);
74
- out.push(`| | 说明 |`);
75
- out.push(`| --- | --- |`);
76
- for (const item of schema.anyOf){
77
- out.push(`| ${item.const} | ${item.title || item.description || ''} |`);
124
+ var _iteratorNormalCompletion = true, _didIteratorError = false, _iteratorError = undefined;
125
+ try {
126
+ for(var _iterator = pending[Symbol.iterator](), _step; !(_iteratorNormalCompletion = (_step = _iterator.next()).done); _iteratorNormalCompletion = true){
127
+ var schema = _step.value;
128
+ if (schema.type === 'object') {
129
+ writeObject(schema);
130
+ } else if ('anyOf' in schema) {
131
+ out.push("### ".concat(schema.$id || schema.title));
132
+ out.push("\n| $id | 名字 |\n| --- | --- |\n| ".concat(schema.$id || '', " | ").concat(schema.title || '', " | \n "));
133
+ out.push("| 值 | 说明 |");
134
+ out.push("| --- | --- |");
135
+ var _iteratorNormalCompletion1 = true, _didIteratorError1 = false, _iteratorError1 = undefined;
136
+ try {
137
+ for(var _iterator1 = schema.anyOf[Symbol.iterator](), _step1; !(_iteratorNormalCompletion1 = (_step1 = _iterator1.next()).done); _iteratorNormalCompletion1 = true){
138
+ var item = _step1.value;
139
+ out.push("| ".concat(item.const, " | ").concat(item.title || item.description || '', " |"));
140
+ }
141
+ } catch (err) {
142
+ _didIteratorError1 = true;
143
+ _iteratorError1 = err;
144
+ } finally{
145
+ try {
146
+ if (!_iteratorNormalCompletion1 && _iterator1.return != null) {
147
+ _iterator1.return();
148
+ }
149
+ } finally{
150
+ if (_didIteratorError1) {
151
+ throw _iteratorError1;
152
+ }
153
+ }
154
+ }
155
+ out.push('');
156
+ }
157
+ }
158
+ } catch (err) {
159
+ _didIteratorError = true;
160
+ _iteratorError = err;
161
+ } finally{
162
+ try {
163
+ if (!_iteratorNormalCompletion && _iterator.return != null) {
164
+ _iterator.return();
165
+ }
166
+ } finally{
167
+ if (_didIteratorError) {
168
+ throw _iteratorError;
78
169
  }
79
- out.push('');
80
170
  }
81
171
  }
82
172
  return out.join('\n');
83
173
  }
84
-
85
- //# sourceMappingURL=renderJsonSchemaToMarkdownDoc.js.map
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@wener/common",
3
- "version": "1.0.5",
3
+ "version": "2.0.1",
4
4
  "type": "module",
5
5
  "description": "",
6
6
  "author": "",
@@ -34,6 +34,14 @@
34
34
  "types": "./src/password/index.ts",
35
35
  "default": "./lib/password/index.js"
36
36
  },
37
+ "./resource": {
38
+ "types": "./src/resource/index.ts",
39
+ "default": "./lib/resource/index.js"
40
+ },
41
+ "./schema": {
42
+ "types": "./src/schema/index.ts",
43
+ "default": "./lib/schema/index.js"
44
+ },
37
45
  "./search": {
38
46
  "types": "./src/search/index.ts",
39
47
  "default": "./lib/search/index.js"
@@ -47,30 +55,34 @@
47
55
  "src"
48
56
  ],
49
57
  "keywords": [],
58
+ "peerDependencies": {
59
+ "zod": "*"
60
+ },
50
61
  "dependencies": {
51
- "es-toolkit": "^1.32.0",
52
- "std-env": "^3.8.1",
53
- "ts-pattern": "^5.6.2",
54
- "zod": "^3.24.2",
55
- "@wener/utils": "1.1.51"
62
+ "@standard-schema/spec": "^1.0.0",
63
+ "@wener/utils": "^1.1.51",
64
+ "date-fns": "^4.1.0",
65
+ "es-toolkit": "^1.37.2",
66
+ "std-env": "^3.9.0",
67
+ "ts-pattern": "^5.7.0"
56
68
  },
57
69
  "devDependencies": {
58
- "@sinclair/typebox": "^0.34.28",
59
- "@sinclair/typebox-codegen": "^0.10.5",
70
+ "@sinclair/typebox": "^0.34.33",
71
+ "@sinclair/typebox-codegen": "^0.11.1",
60
72
  "@types/argon2-browser": "^1.18.4",
61
73
  "@types/bcrypt": "^5.0.2",
62
- "@types/bcryptjs": "^2.4.6",
63
74
  "ajv": "^8.17.1",
64
75
  "ajv-formats": "^3.0.1",
65
76
  "ajv-i18n": "^4.2.0",
66
77
  "ajv-keywords": "^5.1.0",
67
- "argon2": "^0.41.1",
78
+ "argon2": "^0.43.0",
68
79
  "argon2-browser": "^1.18.0",
69
80
  "bcrypt": "^5.1.1",
70
81
  "bcryptjs": "^3.0.2",
71
82
  "chalk": "^5.4.1",
72
83
  "consola": "^3.4.2",
73
- "dayjs": "^1.11.13"
84
+ "dayjs": "^1.11.13",
85
+ "zod": "^3.25.63"
74
86
  },
75
87
  "scripts": {
76
88
  "test": "echo \"Error: no test specified\" && exit 1"
@@ -9,9 +9,13 @@ export function maybeNumber(v: MaybeNumber) {
9
9
  case 'number':
10
10
  return v;
11
11
  case 'bigint':
12
+ if (v > BigInt(Number.MAX_SAFE_INTEGER) || v < BigInt(Number.MIN_SAFE_INTEGER)) {
13
+ throw new Error(`bigint out of range`);
14
+ }
12
15
  return Number(v);
13
16
  case 'string':
14
- if (v === '') {
17
+ v = v.trim();
18
+ if (!v) {
15
19
  return undefined;
16
20
  }
17
21
  }
@@ -53,6 +53,6 @@ test(resolvePagination.name, () => {
53
53
  });
54
54
 
55
55
  test(`${resolvePagination.name} with options`, () => {
56
- expect(resolvePagination({ pageSize: '200' }, { maxPageSize: 50 })).toMatchObject({ pageSize: 50, limit: 50 });
56
+ expect(resolvePagination({ pageSize: '200' }, { maxLimit: 50 })).toMatchObject({ pageSize: 50, limit: 50 });
57
57
  expect(resolvePagination({}, { pageSize: 30 })).toMatchObject({ pageSize: 30, limit: 30 });
58
58
  });
@@ -1,5 +1,5 @@
1
1
  import { maybeFunction, type MaybeFunction } from '@wener/utils';
2
- import { clamp, mapValues, omitBy, pick } from 'es-toolkit';
2
+ import { mapValues, omitBy, pick } from 'es-toolkit';
3
3
  import { maybeNumber, type MaybeNumber } from './maybeNumber';
4
4
 
5
5
  export type PaginationInput = {
@@ -22,7 +22,8 @@ export function resolvePagination(
22
22
  page: PaginationInput,
23
23
  options: {
24
24
  pageSize?: MaybeFunction<number, [number | undefined]>;
25
- maxPageSize?: number;
25
+ maxLimit?: number;
26
+ maxOffset?: number;
26
27
  } = {},
27
28
  ): ResolvedPagination {
28
29
  let out = omitBy(
@@ -38,15 +39,23 @@ export function resolvePagination(
38
39
  if (options.pageSize) {
39
40
  pageSize = maybeFunction(options.pageSize, pageSize);
40
41
  }
41
- pageSize ??= 20;
42
- pageSize = clamp(pageSize, 1, options.maxPageSize ?? 1000);
42
+ pageSize ??= resolvePagination.pageSize;
43
43
 
44
- let { pageNumber = 1, pageIndex, limit, offset } = out;
44
+ let { pageNumber = 1, pageIndex } = out;
45
45
  // page index over page number
46
46
  pageNumber = Math.max(pageNumber, 1);
47
47
  pageIndex = Math.max(pageIndex ?? pageNumber - 1, 0);
48
- limit = Math.max(1, limit ?? pageSize);
49
- offset = Math.max(0, offset ?? pageSize * pageIndex);
48
+
49
+ let { limit = pageSize, offset = pageSize * pageIndex } = out;
50
+ limit = Math.max(1, limit);
51
+ offset = Math.max(0, offset);
52
+
53
+ if (options.maxLimit) {
54
+ limit = Math.min(limit, options.maxLimit);
55
+ }
56
+ if (options.maxOffset) {
57
+ offset = Math.min(offset, options.maxOffset);
58
+ }
50
59
 
51
60
  pageSize = limit;
52
61
  pageIndex = Math.floor(offset / pageSize);
@@ -58,3 +67,5 @@ export function resolvePagination(
58
67
  pageIndex,
59
68
  };
60
69
  }
70
+
71
+ resolvePagination.pageSize = 20;
@@ -31,3 +31,15 @@ type ListResult<T = any> = {
31
31
  /** Total number of items */
32
32
  total: number;
33
33
  };
34
+
35
+ type PageInfo = {
36
+ /** Whether there are more items */
37
+ hasNextPage: boolean;
38
+ /** Whether there are previous items */
39
+ hasPreviousPage: boolean;
40
+
41
+ // /** Start cursor */
42
+ // startCursor?: string;
43
+ // /** End cursor */
44
+ // endCursor?: string;
45
+ };
@@ -1,5 +1,8 @@
1
+ import type { TObject } from '@sinclair/typebox';
2
+ import type { AnySchemaObject, JSONSchemaType } from 'ajv';
1
3
  import { describe, expect, it } from 'vitest';
2
4
  import { JsonSchema } from './JsonSchema';
5
+ import type { JsonSchemaDef } from './types';
3
6
 
4
7
  describe('jsonschema', () => {
5
8
  it('should create from schema', () => {
@@ -15,4 +18,18 @@ describe('jsonschema', () => {
15
18
  expect(JsonSchema.create(a)).toEqual(b);
16
19
  }
17
20
  });
21
+
22
+ it('should match typebox types', () => {
23
+ let a: JsonSchemaDef | undefined;
24
+ let b: TObject<{}> | undefined;
25
+ a = b;
26
+ });
27
+
28
+ it('should match ajv types', () => {
29
+ let a: JsonSchemaDef | undefined;
30
+ let b: AnySchemaObject | undefined;
31
+ let c: JSONSchemaType<{}> | undefined;
32
+ a = b;
33
+ // a = c;
34
+ });
18
35
  });