@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,43 +1,201 @@
|
|
|
1
|
-
|
|
2
|
-
|
|
3
|
-
|
|
4
|
-
|
|
5
|
-
|
|
6
|
-
|
|
7
|
-
|
|
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
|
-
|
|
25
|
-
|
|
26
|
-
|
|
27
|
-
|
|
28
|
-
|
|
29
|
-
|
|
30
|
-
|
|
31
|
-
|
|
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
|
-
|
|
4
|
-
|
|
5
|
-
|
|
6
|
-
|
|
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
|
-
|
|
14
|
-
|
|
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
|
-
|
|
18
|
-
|
|
19
|
-
|
|
20
|
-
|
|
21
|
-
|
|
22
|
-
|
|
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
|
-
|
|
25
|
-
|
|
26
|
-
|
|
27
|
-
|
|
28
|
-
if ('anyOf' in schema) {
|
|
29
|
-
typ = 'enum';
|
|
77
|
+
if (!typ) {
|
|
78
|
+
if ('anyOf' in schema) {
|
|
79
|
+
typ = 'enum';
|
|
80
|
+
}
|
|
30
81
|
}
|
|
31
|
-
|
|
32
|
-
|
|
33
|
-
|
|
34
|
-
|
|
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
|
-
|
|
47
|
-
out.push(
|
|
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(
|
|
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
|
-
|
|
65
|
-
|
|
66
|
-
|
|
67
|
-
|
|
68
|
-
|
|
69
|
-
|
|
70
|
-
|
|
71
|
-
|
|
72
|
-
| $
|
|
73
|
-
|
|
74
|
-
|
|
75
|
-
|
|
76
|
-
|
|
77
|
-
|
|
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
|
|
@@ -0,0 +1,20 @@
|
|
|
1
|
+
export function getEstimateProcessTime(param) {
|
|
2
|
+
var total = param.total, processed = param.processed, startTime = param.startTime, _param_elapsed = param.elapsed, elapsed = _param_elapsed === void 0 ? startTime ? (Date.now() - startTime.getTime()) / 1000 : undefined : _param_elapsed;
|
|
3
|
+
if (typeof total !== 'number' || typeof processed !== 'number' || !elapsed || processed === 0 || processed >= total) {
|
|
4
|
+
return undefined;
|
|
5
|
+
}
|
|
6
|
+
var now = new Date();
|
|
7
|
+
var rate = processed / elapsed;
|
|
8
|
+
if (rate === 0) {
|
|
9
|
+
return undefined;
|
|
10
|
+
}
|
|
11
|
+
var remaining = total - processed;
|
|
12
|
+
var eta = Math.round(remaining / rate);
|
|
13
|
+
var endTime = new Date(now.getTime() + eta * 1000);
|
|
14
|
+
return {
|
|
15
|
+
eta: eta,
|
|
16
|
+
elapsed: elapsed,
|
|
17
|
+
endTime: endTime,
|
|
18
|
+
rate: rate
|
|
19
|
+
};
|
|
20
|
+
}
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
export { getEstimateProcessTime } from "./getEstimateProcessTime.js";
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@wener/common",
|
|
3
|
-
"version": "
|
|
3
|
+
"version": "2.0.2",
|
|
4
4
|
"type": "module",
|
|
5
5
|
"description": "",
|
|
6
6
|
"author": "",
|
|
@@ -22,6 +22,14 @@
|
|
|
22
22
|
"types": "./src/data/index.ts",
|
|
23
23
|
"default": "./lib/data/index.js"
|
|
24
24
|
},
|
|
25
|
+
"./dayjs": {
|
|
26
|
+
"types": "./src/dayjs/index.ts",
|
|
27
|
+
"default": "./lib/dayjs/index.js"
|
|
28
|
+
},
|
|
29
|
+
"./decimal": {
|
|
30
|
+
"types": "./src/decimal/index.ts",
|
|
31
|
+
"default": "./lib/decimal/index.js"
|
|
32
|
+
},
|
|
25
33
|
"./jsonschema": {
|
|
26
34
|
"types": "./src/jsonschema/index.ts",
|
|
27
35
|
"default": "./lib/jsonschema/index.js"
|
|
@@ -34,9 +42,17 @@
|
|
|
34
42
|
"types": "./src/password/index.ts",
|
|
35
43
|
"default": "./lib/password/index.js"
|
|
36
44
|
},
|
|
37
|
-
"./
|
|
38
|
-
"types": "./src/
|
|
39
|
-
"default": "./lib/
|
|
45
|
+
"./resource": {
|
|
46
|
+
"types": "./src/resource/index.ts",
|
|
47
|
+
"default": "./lib/resource/index.js"
|
|
48
|
+
},
|
|
49
|
+
"./resource/schema": {
|
|
50
|
+
"types": "./src/resource/schema/index.ts",
|
|
51
|
+
"default": "./lib/resource/schema/index.js"
|
|
52
|
+
},
|
|
53
|
+
"./schema": {
|
|
54
|
+
"types": "./src/schema/index.ts",
|
|
55
|
+
"default": "./lib/schema/index.js"
|
|
40
56
|
},
|
|
41
57
|
"./package.json": "./package.json"
|
|
42
58
|
},
|
|
@@ -47,30 +63,35 @@
|
|
|
47
63
|
"src"
|
|
48
64
|
],
|
|
49
65
|
"keywords": [],
|
|
66
|
+
"peerDependencies": {
|
|
67
|
+
"zod": "*"
|
|
68
|
+
},
|
|
50
69
|
"dependencies": {
|
|
51
|
-
"
|
|
52
|
-
"
|
|
53
|
-
"
|
|
54
|
-
"
|
|
55
|
-
"
|
|
70
|
+
"@standard-schema/spec": "^1.0.0",
|
|
71
|
+
"@wener/utils": "^1.1.51",
|
|
72
|
+
"date-fns": "^4.1.0",
|
|
73
|
+
"es-toolkit": "^1.39.10",
|
|
74
|
+
"std-env": "^3.9.0",
|
|
75
|
+
"ts-pattern": "^5.8.0"
|
|
56
76
|
},
|
|
57
77
|
"devDependencies": {
|
|
58
|
-
"@sinclair/typebox": "^0.34.
|
|
59
|
-
"@sinclair/typebox-codegen": "^0.
|
|
78
|
+
"@sinclair/typebox": "^0.34.41",
|
|
79
|
+
"@sinclair/typebox-codegen": "^0.11.1",
|
|
60
80
|
"@types/argon2-browser": "^1.18.4",
|
|
61
|
-
"@types/bcrypt": "^
|
|
62
|
-
"@types/bcryptjs": "^2.4.6",
|
|
81
|
+
"@types/bcrypt": "^6.0.0",
|
|
63
82
|
"ajv": "^8.17.1",
|
|
64
83
|
"ajv-formats": "^3.0.1",
|
|
65
84
|
"ajv-i18n": "^4.2.0",
|
|
66
85
|
"ajv-keywords": "^5.1.0",
|
|
67
|
-
"argon2": "^0.
|
|
86
|
+
"argon2": "^0.44.0",
|
|
68
87
|
"argon2-browser": "^1.18.0",
|
|
69
|
-
"bcrypt": "^
|
|
88
|
+
"bcrypt": "^6.0.0",
|
|
70
89
|
"bcryptjs": "^3.0.2",
|
|
71
|
-
"chalk": "^5.
|
|
90
|
+
"chalk": "^5.6.2",
|
|
72
91
|
"consola": "^3.4.2",
|
|
73
|
-
"dayjs": "^1.11.
|
|
92
|
+
"dayjs": "^1.11.18",
|
|
93
|
+
"decimal.js": "^10.6.0",
|
|
94
|
+
"zod": "^4.1.8"
|
|
74
95
|
},
|
|
75
96
|
"scripts": {
|
|
76
97
|
"test": "echo \"Error: no test specified\" && exit 1"
|
|
@@ -0,0 +1,18 @@
|
|
|
1
|
+
import { describe, expect, it } from 'vitest';
|
|
2
|
+
import { ChineseResidentIdNo } from './mod';
|
|
3
|
+
|
|
4
|
+
describe('ChineseResidentIdNo', () => {
|
|
5
|
+
it('should parse', () => {
|
|
6
|
+
for (const a of ['11010519491231002X']) {
|
|
7
|
+
let out = ChineseResidentIdNo.parse(a);
|
|
8
|
+
expect(out).toBeTruthy();
|
|
9
|
+
expect(ChineseResidentIdNo.format(out!)).toBe(a);
|
|
10
|
+
expect(out).toMatchSnapshot();
|
|
11
|
+
}
|
|
12
|
+
});
|
|
13
|
+
it('should format with partial', () => {
|
|
14
|
+
expect(ChineseResidentIdNo.format({ addressCode: '110105', birthDate: new Date('1949-12-31'), sequence: 2 })).toBe(
|
|
15
|
+
'11010519491231002X',
|
|
16
|
+
);
|
|
17
|
+
});
|
|
18
|
+
});
|