@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.
Files changed (222) hide show
  1. package/lib/cn/ChineseResidentIdNo.js +41 -0
  2. package/lib/cn/ChineseResidentIdNo.mod.js +1 -0
  3. package/lib/cn/ChineseResidentIdNo.test.js +22 -0
  4. package/lib/cn/DivisionCode.js +214 -280
  5. package/lib/cn/DivisionCode.mod.js +1 -0
  6. package/lib/cn/DivisionCode.test.js +134 -0
  7. package/lib/cn/Mod11.js +86 -0
  8. package/lib/cn/Mod31.js +98 -0
  9. package/lib/cn/UnifiedSocialCreditCode.js +130 -109
  10. package/lib/cn/UnifiedSocialCreditCode.mod.js +1 -0
  11. package/lib/cn/UnifiedSocialCreditCode.test.js +16 -0
  12. package/lib/cn/index.js +1 -4
  13. package/lib/cn/mod.js +6 -0
  14. package/lib/cn/types.d.js +0 -2
  15. package/lib/consola/createStandardConsolaReporter.js +6 -6
  16. package/lib/consola/formatLogObject.js +147 -34
  17. package/lib/consola/index.js +0 -1
  18. package/lib/data/formatSort.js +5 -6
  19. package/lib/data/formatSort.test.js +34 -0
  20. package/lib/data/index.js +0 -1
  21. package/lib/data/maybeNumber.js +11 -5
  22. package/lib/data/parseSort.js +28 -22
  23. package/lib/data/parseSort.test.js +188 -0
  24. package/lib/data/resolvePagination.js +27 -16
  25. package/lib/data/resolvePagination.test.js +232 -0
  26. package/lib/data/types.d.js +0 -2
  27. package/lib/dayjs/dayjs.js +38 -0
  28. package/lib/dayjs/formatDuration.js +58 -0
  29. package/lib/dayjs/formatDuration.test.js +90 -0
  30. package/lib/dayjs/index.js +3 -0
  31. package/lib/dayjs/parseDuration.js +32 -0
  32. package/lib/decimal/index.js +1 -0
  33. package/lib/decimal/parseDecimal.js +13 -0
  34. package/lib/foundation/schema/SexType.js +14 -0
  35. package/lib/foundation/schema/index.js +1 -0
  36. package/lib/foundation/schema/parseSexType.js +18 -0
  37. package/lib/foundation/schema/types.js +5 -0
  38. package/lib/index.js +0 -1
  39. package/lib/jsonschema/JsonSchema.js +78 -52
  40. package/lib/jsonschema/JsonSchema.test.js +137 -0
  41. package/lib/jsonschema/index.js +0 -1
  42. package/lib/jsonschema/types.d.js +5 -3
  43. package/lib/meta/defineFileType.js +103 -20
  44. package/lib/meta/defineInit.js +250 -31
  45. package/lib/meta/defineMetadata.js +140 -24
  46. package/lib/meta/defineMetadata.test.js +13 -0
  47. package/lib/meta/index.js +0 -1
  48. package/lib/password/PHC.js +87 -63
  49. package/lib/password/PHC.test.js +539 -0
  50. package/lib/password/Password.js +295 -30
  51. package/lib/password/Password.test.js +362 -0
  52. package/lib/password/createArgon2PasswordAlgorithm.js +191 -35
  53. package/lib/password/createBase64PasswordAlgorithm.js +141 -8
  54. package/lib/password/createBcryptPasswordAlgorithm.js +168 -13
  55. package/lib/password/createPBKDF2PasswordAlgorithm.js +228 -46
  56. package/lib/password/createScryptPasswordAlgorithm.js +211 -55
  57. package/lib/password/index.js +0 -1
  58. package/lib/password/server/index.js +0 -1
  59. package/lib/resource/Identifiable.js +1 -0
  60. package/lib/resource/ListQuery.js +119 -0
  61. package/lib/resource/getTitleOfResource.js +10 -0
  62. package/lib/resource/index.js +2 -0
  63. package/lib/resource/schema/AnyResourceSchema.js +89 -0
  64. package/lib/resource/schema/BaseResourceSchema.js +29 -0
  65. package/lib/resource/schema/ResourceActionType.js +118 -0
  66. package/lib/resource/schema/ResourceStatus.js +93 -0
  67. package/lib/resource/schema/ResourceType.js +24 -0
  68. package/lib/resource/schema/index.js +5 -0
  69. package/lib/resource/schema/types.js +89 -0
  70. package/lib/resource/schema/types.test.js +14 -0
  71. package/lib/schema/SchemaRegistry.js +45 -0
  72. package/lib/schema/SchemaRegistry.mod.js +2 -0
  73. package/lib/schema/TypeSchema.d.js +1 -0
  74. package/lib/schema/createSchemaData.js +173 -0
  75. package/lib/schema/findJsonSchemaByPath.js +49 -0
  76. package/lib/schema/getSchemaCache.js +11 -0
  77. package/lib/schema/getSchemaOptions.js +24 -0
  78. package/lib/schema/index.js +6 -0
  79. package/lib/schema/toJsonSchema.js +441 -0
  80. package/lib/schema/toJsonSchema.test.js +27 -0
  81. package/lib/schema/validate.js +124 -0
  82. package/lib/tools/generateSchema.js +197 -39
  83. package/lib/tools/renderJsonSchemaToMarkdownDoc.js +143 -55
  84. package/lib/utils/getEstimateProcessTime.js +20 -0
  85. package/lib/utils/index.js +1 -0
  86. package/package.json +38 -17
  87. package/src/cn/ChineseResidentIdNo.mod.ts +7 -0
  88. package/src/cn/ChineseResidentIdNo.test.ts +18 -0
  89. package/src/cn/ChineseResidentIdNo.ts +66 -0
  90. package/src/cn/DivisionCode.mod.ts +7 -0
  91. package/src/cn/DivisionCode.test.ts +3 -13
  92. package/src/cn/DivisionCode.ts +132 -195
  93. package/src/cn/{Mod11Checksum.ts → Mod11.ts} +3 -1
  94. package/src/cn/{Mod31Checksum.ts → Mod31.ts} +2 -0
  95. package/src/cn/UnifiedSocialCreditCode.mod.ts +7 -0
  96. package/src/cn/UnifiedSocialCreditCode.test.ts +2 -2
  97. package/src/cn/UnifiedSocialCreditCode.ts +105 -125
  98. package/src/cn/__snapshots__/ChineseResidentIdNo.test.ts.snap +14 -0
  99. package/src/cn/__snapshots__/UnifiedSocialCreditCode.test.ts.snap +18 -12
  100. package/src/cn/index.ts +1 -3
  101. package/src/cn/mod.ts +3 -0
  102. package/src/consola/formatLogObject.ts +12 -4
  103. package/src/data/maybeNumber.ts +5 -1
  104. package/src/data/resolvePagination.test.ts +1 -1
  105. package/src/data/resolvePagination.ts +18 -7
  106. package/src/data/types.d.ts +12 -0
  107. package/src/dayjs/dayjs.ts +40 -0
  108. package/src/dayjs/formatDuration.test.ts +14 -0
  109. package/src/dayjs/formatDuration.ts +86 -0
  110. package/src/dayjs/index.ts +3 -0
  111. package/src/dayjs/parseDuration.ts +40 -0
  112. package/src/decimal/index.ts +1 -0
  113. package/src/decimal/parseDecimal.ts +16 -0
  114. package/src/foundation/schema/SexType.ts +21 -0
  115. package/src/foundation/schema/index.ts +1 -0
  116. package/src/foundation/schema/parseSexType.ts +19 -0
  117. package/src/foundation/schema/types.ts +8 -0
  118. package/src/jsonschema/JsonSchema.test.ts +17 -0
  119. package/src/jsonschema/JsonSchema.ts +2 -2
  120. package/src/jsonschema/types.d.ts +63 -12
  121. package/src/password/Password.ts +2 -2
  122. package/src/resource/Identifiable.ts +3 -0
  123. package/src/resource/ListQuery.ts +53 -0
  124. package/src/resource/getTitleOfResource.tsx +6 -0
  125. package/src/resource/index.ts +4 -0
  126. package/src/resource/schema/AnyResourceSchema.ts +113 -0
  127. package/src/resource/schema/BaseResourceSchema.ts +32 -0
  128. package/src/resource/schema/ResourceActionType.ts +123 -0
  129. package/src/resource/schema/ResourceStatus.ts +94 -0
  130. package/src/resource/schema/ResourceType.ts +25 -0
  131. package/src/resource/schema/index.ts +5 -0
  132. package/src/resource/schema/types.test.ts +18 -0
  133. package/src/resource/schema/types.ts +105 -0
  134. package/src/schema/SchemaRegistry.mod.ts +1 -0
  135. package/src/schema/SchemaRegistry.ts +46 -0
  136. package/src/schema/TypeSchema.d.ts +32 -0
  137. package/src/schema/createSchemaData.ts +81 -0
  138. package/src/schema/findJsonSchemaByPath.ts +37 -0
  139. package/src/schema/getSchemaCache.ts +21 -0
  140. package/src/schema/getSchemaOptions.ts +24 -0
  141. package/src/schema/index.ts +7 -0
  142. package/src/schema/toJsonSchema.test.ts +37 -0
  143. package/src/schema/toJsonSchema.ts +200 -0
  144. package/src/schema/validate.ts +135 -0
  145. package/src/tools/generateSchema.ts +28 -28
  146. package/src/utils/getEstimateProcessTime.ts +36 -0
  147. package/src/utils/index.ts +1 -0
  148. package/lib/cn/DivisionCode.js.map +0 -1
  149. package/lib/cn/Mod11Checksum.js +0 -42
  150. package/lib/cn/Mod11Checksum.js.map +0 -1
  151. package/lib/cn/Mod31Checksum.js +0 -48
  152. package/lib/cn/Mod31Checksum.js.map +0 -1
  153. package/lib/cn/ResidentIdentityCardNumber.js +0 -50
  154. package/lib/cn/ResidentIdentityCardNumber.js.map +0 -1
  155. package/lib/cn/UnifiedSocialCreditCode.js.map +0 -1
  156. package/lib/cn/formatDate.js +0 -15
  157. package/lib/cn/formatDate.js.map +0 -1
  158. package/lib/cn/index.js.map +0 -1
  159. package/lib/cn/parseSex.js +0 -22
  160. package/lib/cn/parseSex.js.map +0 -1
  161. package/lib/cn/types.d.js.map +0 -1
  162. package/lib/consola/createStandardConsolaReporter.js.map +0 -1
  163. package/lib/consola/formatLogObject.js.map +0 -1
  164. package/lib/consola/index.js.map +0 -1
  165. package/lib/data/formatSort.js.map +0 -1
  166. package/lib/data/index.js.map +0 -1
  167. package/lib/data/maybeNumber.js.map +0 -1
  168. package/lib/data/parseSort.js.map +0 -1
  169. package/lib/data/resolvePagination.js.map +0 -1
  170. package/lib/data/types.d.js.map +0 -1
  171. package/lib/index.js.map +0 -1
  172. package/lib/jsonschema/JsonSchema.js.map +0 -1
  173. package/lib/jsonschema/index.js.map +0 -1
  174. package/lib/jsonschema/types.d.js.map +0 -1
  175. package/lib/meta/defineFileType.js.map +0 -1
  176. package/lib/meta/defineInit.js.map +0 -1
  177. package/lib/meta/defineMetadata.js.map +0 -1
  178. package/lib/meta/index.js.map +0 -1
  179. package/lib/password/PHC.js.map +0 -1
  180. package/lib/password/Password.js.map +0 -1
  181. package/lib/password/createArgon2PasswordAlgorithm.js.map +0 -1
  182. package/lib/password/createBase64PasswordAlgorithm.js.map +0 -1
  183. package/lib/password/createBcryptPasswordAlgorithm.js.map +0 -1
  184. package/lib/password/createPBKDF2PasswordAlgorithm.js.map +0 -1
  185. package/lib/password/createScryptPasswordAlgorithm.js.map +0 -1
  186. package/lib/password/index.js.map +0 -1
  187. package/lib/password/server/index.js.map +0 -1
  188. package/lib/search/AdvanceSearch.js +0 -10
  189. package/lib/search/AdvanceSearch.js.map +0 -1
  190. package/lib/search/formatAdvanceSearch.js +0 -64
  191. package/lib/search/formatAdvanceSearch.js.map +0 -1
  192. package/lib/search/index.js +0 -2
  193. package/lib/search/index.js.map +0 -1
  194. package/lib/search/optimizeAdvanceSearch.js +0 -89
  195. package/lib/search/optimizeAdvanceSearch.js.map +0 -1
  196. package/lib/search/parseAdvanceSearch.js +0 -20
  197. package/lib/search/parseAdvanceSearch.js.map +0 -1
  198. package/lib/search/parser.d.js +0 -3
  199. package/lib/search/parser.d.js.map +0 -1
  200. package/lib/search/parser.js +0 -3065
  201. package/lib/search/parser.js.map +0 -1
  202. package/lib/search/types.d.js +0 -3
  203. package/lib/search/types.d.js.map +0 -1
  204. package/lib/tools/generateSchema.js.map +0 -1
  205. package/lib/tools/renderJsonSchemaToMarkdownDoc.js.map +0 -1
  206. package/src/cn/ResidentIdentityCardNumber.test.ts +0 -17
  207. package/src/cn/ResidentIdentityCardNumber.ts +0 -96
  208. package/src/cn/__snapshots__/ResidentIdentityCardNumber.test.ts.snap +0 -15
  209. package/src/cn/formatDate.ts +0 -12
  210. package/src/cn/parseSex.ts +0 -13
  211. package/src/search/AdvanceSearch.test.ts +0 -149
  212. package/src/search/AdvanceSearch.ts +0 -14
  213. package/src/search/Makefile +0 -2
  214. package/src/search/__snapshots__/AdvanceSearch.test.ts.snap +0 -675
  215. package/src/search/formatAdvanceSearch.ts +0 -52
  216. package/src/search/index.ts +0 -1
  217. package/src/search/optimizeAdvanceSearch.ts +0 -77
  218. package/src/search/parseAdvanceSearch.ts +0 -23
  219. package/src/search/parser.d.ts +0 -8
  220. package/src/search/parser.js +0 -2794
  221. package/src/search/parser.peggy +0 -237
  222. package/src/search/types.d.ts +0 -45
@@ -1,66 +1,222 @@
1
+ function asyncGeneratorStep(gen, resolve, reject, _next, _throw, key, arg) {
2
+ try {
3
+ var info = gen[key](arg);
4
+ var value = info.value;
5
+ }
6
+ catch (error) {
7
+ reject(error);
8
+ return;
9
+ }
10
+ if (info.done) {
11
+ resolve(value);
12
+ }
13
+ else {
14
+ Promise.resolve(value).then(_next, _throw);
15
+ }
16
+ }
17
+ function _async_to_generator(fn) {
18
+ return function () {
19
+ var self = this, args = arguments;
20
+ return new Promise(function (resolve, reject) {
21
+ var gen = fn.apply(self, args);
22
+ function _next(value) {
23
+ asyncGeneratorStep(gen, resolve, reject, _next, _throw, "next", value);
24
+ }
25
+ function _throw(err) {
26
+ asyncGeneratorStep(gen, resolve, reject, _next, _throw, "throw", err);
27
+ }
28
+ _next(undefined);
29
+ });
30
+ };
31
+ }
32
+ function _ts_generator(thisArg, body) {
33
+ var f, y, t, _ = {
34
+ label: 0,
35
+ sent: function () {
36
+ if (t[0] & 1)
37
+ throw t[1];
38
+ return t[1];
39
+ },
40
+ trys: [],
41
+ ops: []
42
+ }, g = Object.create((typeof Iterator === "function" ? Iterator : Object).prototype);
43
+ return g.next = verb(0), g["throw"] = verb(1), g["return"] = verb(2), typeof Symbol === "function" && (g[Symbol.iterator] = function () {
44
+ return this;
45
+ }), g;
46
+ function verb(n) {
47
+ return function (v) {
48
+ return step([
49
+ n,
50
+ v
51
+ ]);
52
+ };
53
+ }
54
+ function step(op) {
55
+ if (f)
56
+ throw new TypeError("Generator is already executing.");
57
+ while (g && (g = 0, op[0] && (_ = 0)), _)
58
+ try {
59
+ 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)
60
+ return t;
61
+ if (y = 0, t)
62
+ op = [
63
+ op[0] & 2,
64
+ t.value
65
+ ];
66
+ switch (op[0]) {
67
+ case 0:
68
+ case 1:
69
+ t = op;
70
+ break;
71
+ case 4:
72
+ _.label++;
73
+ return {
74
+ value: op[1],
75
+ done: false
76
+ };
77
+ case 5:
78
+ _.label++;
79
+ y = op[1];
80
+ op = [
81
+ 0
82
+ ];
83
+ continue;
84
+ case 7:
85
+ op = _.ops.pop();
86
+ _.trys.pop();
87
+ continue;
88
+ default:
89
+ if (!(t = _.trys, t = t.length > 0 && t[t.length - 1]) && (op[0] === 6 || op[0] === 2)) {
90
+ _ = 0;
91
+ continue;
92
+ }
93
+ if (op[0] === 3 && (!t || op[1] > t[0] && op[1] < t[3])) {
94
+ _.label = op[1];
95
+ break;
96
+ }
97
+ if (op[0] === 6 && _.label < t[1]) {
98
+ _.label = t[1];
99
+ t = op;
100
+ break;
101
+ }
102
+ if (t && _.label < t[2]) {
103
+ _.label = t[2];
104
+ _.ops.push(op);
105
+ break;
106
+ }
107
+ if (t[2])
108
+ _.ops.pop();
109
+ _.trys.pop();
110
+ continue;
111
+ }
112
+ op = body.call(thisArg, _);
113
+ }
114
+ catch (e) {
115
+ op = [
116
+ 6,
117
+ e
118
+ ];
119
+ y = 0;
120
+ }
121
+ finally {
122
+ f = t = 0;
123
+ }
124
+ if (op[0] & 5)
125
+ throw op[1];
126
+ return {
127
+ value: op[0] ? op[1] : void 0,
128
+ done: true
129
+ };
130
+ }
131
+ }
1
132
  import { randomBytes, scrypt, timingSafeEqual } from "node:crypto";
2
133
  import { Errors } from "@wener/utils";
3
134
  import { PHC } from "./PHC.js";
4
- export function createScryptPasswordAlgorithm(options = {}) {
5
- let id = options.id || "scrypt";
6
- options.cost ||= Math.pow(2, 14);
7
- options.blocksize ||= 8;
8
- options.parallelism ||= 1;
9
- options.saltlen ||= 16;
10
- options.keylen ||= 32;
135
+ export function createScryptPasswordAlgorithm() {
136
+ var options = arguments.length > 0 && arguments[0] !== void 0 ? arguments[0] : {};
137
+ var _options, _options1, _options2, _options3, _options4;
138
+ var id = options.id || "scrypt";
139
+ (_options = options).cost || (_options.cost = Math.pow(2, 14));
140
+ (_options1 = options).blocksize || (_options1.blocksize = 8);
141
+ (_options2 = options).parallelism || (_options2.parallelism = 1);
142
+ (_options3 = options).saltlen || (_options3.saltlen = 16);
143
+ (_options4 = options).keylen || (_options4.keylen = 32);
11
144
  return {
12
145
  name: id,
13
- async hash(password, opts) {
14
- const salt = opts?.salt || randomBytes(options.saltlen);
15
- return new Promise((resolve, reject) => {
16
- let N = options.cost;
17
- let r = options.blocksize;
18
- let p = options.parallelism;
19
- scrypt(password, salt, options.keylen, {
20
- N,
21
- r,
22
- p
23
- }, (err, derivedKey) => {
24
- if (err)
25
- return reject(err);
26
- resolve(PHC.serialize({
27
- id: opts?.id ?? id,
28
- params: {
29
- ln: N,
30
- r: r,
31
- p: p
32
- },
33
- salt,
34
- hash: derivedKey
35
- }));
146
+ hash: function hash(password, opts) {
147
+ return _async_to_generator(function () {
148
+ var salt;
149
+ return _ts_generator(this, function (_state) {
150
+ salt = (opts === null || opts === void 0 ? void 0 : opts.salt) || randomBytes(options.saltlen);
151
+ return [
152
+ 2,
153
+ new Promise(function (resolve, reject) {
154
+ var N = options.cost;
155
+ var r = options.blocksize;
156
+ var p = options.parallelism;
157
+ scrypt(password, salt, options.keylen, {
158
+ N: N,
159
+ r: r,
160
+ p: p
161
+ }, function (err, derivedKey) {
162
+ if (err)
163
+ return reject(err);
164
+ var _opts_id;
165
+ resolve(PHC.serialize({
166
+ id: (_opts_id = opts === null || opts === void 0 ? void 0 : opts.id) !== null && _opts_id !== void 0 ? _opts_id : id,
167
+ params: {
168
+ ln: N,
169
+ r: r,
170
+ p: p
171
+ },
172
+ salt: salt,
173
+ hash: derivedKey
174
+ }));
175
+ });
176
+ })
177
+ ];
36
178
  });
37
- });
179
+ })();
38
180
  },
39
- async verify(password, hash, opts) {
40
- try {
41
- const salt = Errors.BadRequest.require(opts.salt);
42
- const storedHash = Errors.BadRequest.require(opts.hash);
43
- const N = parseInt(opts.params?.ln, 10);
44
- const r = parseInt(opts.params?.r, 10);
45
- const p = parseInt(opts.params?.p, 10);
46
- const keylen = storedHash.length;
47
- return new Promise((resolve, reject) => {
48
- scrypt(password, salt, keylen, {
49
- N,
50
- r,
51
- p
52
- }, (err, derivedKey) => {
53
- if (err)
54
- return reject(err);
55
- const isMatch = timingSafeEqual(derivedKey, storedHash);
56
- resolve(isMatch);
57
- });
181
+ verify: function verify(password, hash, opts) {
182
+ return _async_to_generator(function () {
183
+ var _opts_params, _opts_params1, _opts_params2, salt, storedHash, N, r, p, keylen;
184
+ return _ts_generator(this, function (_state) {
185
+ try {
186
+ ;
187
+ salt = Errors.BadRequest.require(opts.salt);
188
+ storedHash = Errors.BadRequest.require(opts.hash);
189
+ N = parseInt((_opts_params = opts.params) === null || _opts_params === void 0 ? void 0 : _opts_params.ln, 10);
190
+ r = parseInt((_opts_params1 = opts.params) === null || _opts_params1 === void 0 ? void 0 : _opts_params1.r, 10);
191
+ p = parseInt((_opts_params2 = opts.params) === null || _opts_params2 === void 0 ? void 0 : _opts_params2.p, 10);
192
+ keylen = storedHash.length;
193
+ return [
194
+ 2,
195
+ new Promise(function (resolve, reject) {
196
+ scrypt(password, salt, keylen, {
197
+ N: N,
198
+ r: r,
199
+ p: p
200
+ }, function (err, derivedKey) {
201
+ if (err)
202
+ return reject(err);
203
+ var isMatch = timingSafeEqual(derivedKey, storedHash);
204
+ resolve(isMatch);
205
+ });
206
+ })
207
+ ];
208
+ }
209
+ catch (error) {
210
+ return [
211
+ 2,
212
+ Promise.resolve(false)
213
+ ];
214
+ }
215
+ return [
216
+ 2
217
+ ];
58
218
  });
59
- }
60
- catch (error) {
61
- return Promise.resolve(false);
62
- }
219
+ })();
63
220
  }
64
221
  };
65
222
  }
66
- //# sourceMappingURL=createScryptPasswordAlgorithm.js.map
@@ -3,4 +3,3 @@ export { Password } from "./Password.js";
3
3
  export { createArgon2PasswordAlgorithm } from "./createArgon2PasswordAlgorithm.js";
4
4
  export { createBase64PasswordAlgorithm } from "./createBase64PasswordAlgorithm.js";
5
5
  export { createBcryptPasswordAlgorithm } from "./createBcryptPasswordAlgorithm.js";
6
- //# sourceMappingURL=index.js.map
@@ -1,2 +1 @@
1
1
  export { createScryptPasswordAlgorithm } from "../createScryptPasswordAlgorithm.js";
2
- //# sourceMappingURL=index.js.map
@@ -0,0 +1 @@
1
+ export { };
@@ -0,0 +1,119 @@
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_without_holes(arr) {
7
+ if (Array.isArray(arr)) return _array_like_to_array(arr);
8
+ }
9
+ function _define_property(obj, key, value) {
10
+ if (key in obj) {
11
+ Object.defineProperty(obj, key, {
12
+ value: value,
13
+ enumerable: true,
14
+ configurable: true,
15
+ writable: true
16
+ });
17
+ } else {
18
+ obj[key] = value;
19
+ }
20
+ return obj;
21
+ }
22
+ function _iterable_to_array(iter) {
23
+ if (typeof Symbol !== "undefined" && iter[Symbol.iterator] != null || iter["@@iterator"] != null) return Array.from(iter);
24
+ }
25
+ function _non_iterable_spread() {
26
+ throw new TypeError("Invalid attempt to spread non-iterable instance.\\nIn order to be iterable, non-array objects must have a [Symbol.iterator]() method.");
27
+ }
28
+ function _object_spread(target) {
29
+ for(var i = 1; i < arguments.length; i++){
30
+ var source = arguments[i] != null ? arguments[i] : {};
31
+ var ownKeys = Object.keys(source);
32
+ if (typeof Object.getOwnPropertySymbols === "function") {
33
+ ownKeys = ownKeys.concat(Object.getOwnPropertySymbols(source).filter(function(sym) {
34
+ return Object.getOwnPropertyDescriptor(source, sym).enumerable;
35
+ }));
36
+ }
37
+ ownKeys.forEach(function(key) {
38
+ _define_property(target, key, source[key]);
39
+ });
40
+ }
41
+ return target;
42
+ }
43
+ function ownKeys(object, enumerableOnly) {
44
+ var keys = Object.keys(object);
45
+ if (Object.getOwnPropertySymbols) {
46
+ var symbols = Object.getOwnPropertySymbols(object);
47
+ if (enumerableOnly) {
48
+ symbols = symbols.filter(function(sym) {
49
+ return Object.getOwnPropertyDescriptor(object, sym).enumerable;
50
+ });
51
+ }
52
+ keys.push.apply(keys, symbols);
53
+ }
54
+ return keys;
55
+ }
56
+ function _object_spread_props(target, source) {
57
+ source = source != null ? source : {};
58
+ if (Object.getOwnPropertyDescriptors) {
59
+ Object.defineProperties(target, Object.getOwnPropertyDescriptors(source));
60
+ } else {
61
+ ownKeys(Object(source)).forEach(function(key) {
62
+ Object.defineProperty(target, key, Object.getOwnPropertyDescriptor(source, key));
63
+ });
64
+ }
65
+ return target;
66
+ }
67
+ function _to_consumable_array(arr) {
68
+ return _array_without_holes(arr) || _iterable_to_array(arr) || _unsupported_iterable_to_array(arr) || _non_iterable_spread();
69
+ }
70
+ function _unsupported_iterable_to_array(o, minLen) {
71
+ if (!o) return;
72
+ if (typeof o === "string") return _array_like_to_array(o, minLen);
73
+ var n = Object.prototype.toString.call(o).slice(8, -1);
74
+ if (n === "Object" && o.constructor) n = o.constructor.name;
75
+ if (n === "Map" || n === "Set") return Array.from(n);
76
+ if (n === "Arguments" || /^(?:Ui|I)nt(?:8|16|32)(?:Clamped)?Array$/.test(n)) return _array_like_to_array(o, minLen);
77
+ }
78
+ import { z } from 'zod/v4';
79
+ var IntLikeSchema = z.coerce.number().multipleOf(1).min(0).optional().overwrite(function(v) {
80
+ return v || undefined;
81
+ });
82
+ export var ListQuerySchema = z.object({
83
+ id: z.coerce.string().optional(),
84
+ ids: z.array(z.coerce.string()).optional(),
85
+ filter: z.string().optional().describe('sql-like filter string'),
86
+ filters: z.array(z.any()).optional().describe('sql-like filter string'),
87
+ where: z.record(z.string(), z.any()).optional().describe('document query filter'),
88
+ search: z.string().optional(),
89
+ limit: IntLikeSchema,
90
+ offset: IntLikeSchema,
91
+ order: z.array(z.string()).optional().describe('order like "a,-b,c desc null last"'),
92
+ pageIndex: IntLikeSchema.describe('0-based page index'),
93
+ pageNumber: IntLikeSchema.describe('1-based page number'),
94
+ pageSize: IntLikeSchema,
95
+ cursor: z.string().optional(),
96
+ deleted: z.coerce.boolean().optional()
97
+ });
98
+ export function resolveListQuery(target) {
99
+ for(var _len = arguments.length, args = new Array(_len > 1 ? _len - 1 : 0), _key = 1; _key < _len; _key++){
100
+ args[_key - 1] = arguments[_key];
101
+ }
102
+ var out = args.reduce(function(a, source) {
103
+ if (typeof source === 'function') {
104
+ var result = source(a);
105
+ // do not use the result as merge source
106
+ return result || a;
107
+ }
108
+ var b = source;
109
+ if (!b) return a;
110
+ // do not resolve id to ids
111
+ var ids = _to_consumable_array(a.ids || []).concat(_to_consumable_array(b.ids || []));
112
+ return _object_spread_props(_object_spread({}, a, b), {
113
+ ids: ids,
114
+ filters: _to_consumable_array(a.filters || []).concat(_to_consumable_array(b.filters || [])),
115
+ search: b.search || a.search
116
+ });
117
+ }, target || {});
118
+ return ListQuerySchema.parse(out);
119
+ }
@@ -0,0 +1,10 @@
1
+ function _type_of(obj) {
2
+ "@swc/helpers - typeof";
3
+ return obj && typeof Symbol !== "undefined" && obj.constructor === Symbol ? "symbol" : typeof obj;
4
+ }
5
+ export function getTitleOfResource(res) {
6
+ if (res && (typeof res === "undefined" ? "undefined" : _type_of(res)) === 'object') {
7
+ return res.displayName || res.title || res.fullName || res.loginName || res.topic || res.code;
8
+ }
9
+ return undefined;
10
+ }
@@ -0,0 +1,2 @@
1
+ export { getTitleOfResource } from "./getTitleOfResource.js";
2
+ export { resolveListQuery, ListQuerySchema } from "./ListQuery.js";
@@ -0,0 +1,89 @@
1
+ import { z } from "zod/v4";
2
+ import { SexTypeSchema } from "../../foundation/schema/SexType.js";
3
+ import { rz } from "./types.js";
4
+ export var AnyResourceSchema = z.object({
5
+ id: rz.resourceId.readonly().describe("ID"),
6
+ uid: z.guid().nullish().readonly().describe("\u552F\u4E00ID"),
7
+ tid: rz.resourceId.nullish().readonly().describe("\u79DF\u6237ID"),
8
+ sid: z.coerce.number().nullish().readonly().describe("\u5E8F\u53F7"),
9
+ eid: z.string().nullish().readonly().describe("\u5916\u90E8ID"),
10
+ cid: z.string().nullish().readonly().describe("\u670D\u52A1\u5546ID"),
11
+ rid: z.string().nullish().readonly().describe("\u670D\u52A1\u5546\u8D44\u6E90ID"),
12
+ code: z.string().nullish().describe("\u7F16\u53F7"),
13
+ fullName: rz.friendlyName.optional().describe("\u540D\u79F0"),
14
+ displayName: rz.friendlyName.nullish().describe("\u663E\u793A\u540D"),
15
+ loginName: rz.loginName.nullish().describe("\u767B\u5F55\u540D"),
16
+ email: z.string().nullish().describe("\u90AE\u7BB1"),
17
+ emailVerifiedAt: rz.date.nullish().describe("\u90AE\u7BB1\u9A8C\u8BC1\u65F6\u95F4"),
18
+ phoneNumber: rz.phoneNumber.nullish().describe("\u7535\u8BDD\u53F7\u7801"),
19
+ phoneNumberVerifiedAt: rz.date.nullish().describe("\u7535\u8BDD\u53F7\u7801\u9A8C\u8BC1\u65F6\u95F4"),
20
+ jobNumber: z.string().nullish().describe("\u5DE5\u53F7"),
21
+ jobTitle: z.string().nullish().describe("\u804C\u4F4D"),
22
+ birthDate: rz.date.nullish().describe("\u51FA\u751F\u65E5\u671F"),
23
+ password: rz.password.nullish().describe("\u5BC6\u7801"),
24
+ sex: SexTypeSchema.nullish().describe("\u6027\u522B"),
25
+ contactName: rz.friendlyName.nullish().describe("\u8054\u7CFB\u4EBA"),
26
+ contactPhone: rz.phoneNumber.nullish().describe("\u8054\u7CFB\u7535\u8BDD"),
27
+ contactEmail: z.string().nullish().describe("\u8054\u7CFB\u90AE\u7BB1"),
28
+ contactAddress: z.string().nullish().describe("\u8054\u7CFB\u5730\u5740"),
29
+ alternativeName: rz.friendlyName.nullish().describe("\u5907\u7528\u8054\u7CFB\u4EBA"),
30
+ alternativeEmail: z.string().nullish().describe("\u5907\u7528\u8054\u7CFB\u90AE\u7BB1"),
31
+ alternativePhone: rz.phoneNumber.nullish().describe("\u5907\u7528\u8054\u7CFB\u7535\u8BDD"),
32
+ alternativeAddress: z.string().nullish().describe("\u5907\u7528\u8054\u7CFB\u5730\u5740"),
33
+ title: z.string().trim().nullish().describe("\u6807\u9898"),
34
+ description: z.string().trim().nullish().describe("\u63CF\u8FF0"),
35
+ topic: z.string().nullish().describe("\u4E3B\u9898"),
36
+ summary: z.string().nullish().describe("\u6458\u8981"),
37
+ avatarUrl: z.string().nullish().describe("\u5934\u50CF"),
38
+ photoUrl: z.string().nullish().describe("\u7167\u7247"),
39
+ imageUrl: z.string().nullish().describe("\u56FE\u7247"),
40
+ bannerUrl: z.string().nullish().describe("\u6A2A\u5E45\u56FE\u7247"),
41
+ type: z.string().nullish().describe("\u7C7B\u578B"),
42
+ data: z.record(z.string(), z.any()).nullish().describe("\u6570\u636E"),
43
+ licenseNumber: z.string().nullish().describe("\u8BC1\u4EF6\u53F7\u7801"),
44
+ licenseStartDate: rz.date.nullish().describe("\u8BC1\u4EF6\u6709\u6548\u671F\u5F00\u59CB\u65E5\u671F"),
45
+ licenseEndDate: rz.date.nullish().describe("\u8BC1\u4EF6\u6709\u6548\u671F\u7ED3\u675F\u65E5\u671F"),
46
+ licenseAddress: z.string().nullish().describe("\u8BC1\u4EF6\u5730\u5740"),
47
+ licenseFrontUrl: z.string().nullish().describe("\u8BC1\u4EF6\u6B63\u9762\u7167\u7247"),
48
+ licenseBackUrl: z.string().nullish().describe("\u8BC1\u4EF6\u80CC\u9762\u7167\u7247"),
49
+ address: z.string().nullish().describe("\u5730\u5740"),
50
+ divisionCode: z.string().nullish().describe("\u884C\u653F\u533A\u5212\u4EE3\u7801"),
51
+ province: z.string().nullish().describe("\u7701"),
52
+ city: z.string().nullish().describe("\u5E02"),
53
+ startDate: rz.date.nullish().describe("\u5F00\u59CB\u65E5\u671F"),
54
+ endDate: rz.date.nullish().describe("\u7ED3\u675F\u65E5\u671F"),
55
+ startTime: rz.dateTime.nullish().describe("\u5F00\u59CB\u65F6\u95F4"),
56
+ endTime: rz.dateTime.nullish().describe("\u7ED3\u675F\u65F6\u95F4"),
57
+ userId: rz.resourceIdOf("User").nullish(),
58
+ entityId: rz.resourceId.nullish().describe("\u5173\u8054\u7684\u5B9E\u4F53"),
59
+ entityType: z.string().nullish().describe("\u5173\u8054\u7684\u5B9E\u4F53\u7C7B\u578B"),
60
+ customerId: rz.resourceId.nullish().describe("\u5BA2\u6237"),
61
+ customerType: z.string().nullish().describe("\u5BA2\u6237\u7C7B\u578B"),
62
+ contactId: rz.resourceId.nullish().describe("\u8054\u7CFB\u4EBA"),
63
+ accountId: rz.resourceId.nullish().describe("\u8D26\u6237"),
64
+ ownerId: rz.resourceId.nullish(),
65
+ ownerType: z.string().nullish().describe("\u8D1F\u8D23\u4EBA\u7C7B\u578B"),
66
+ owningUserId: rz.resourceId.nullish().describe("\u8D1F\u8D23\u4EBA"),
67
+ parentId: rz.resourceId.nullish().describe("\u7236\u7EA7"),
68
+ metadata: z.record(z.string(), z.any()).nullish().describe("\u5143\u6570\u636E"),
69
+ tags: z.array(z.string()).nullish().describe("\u6807\u8BB0"),
70
+ notes: z.string().nullish().describe("\u5907\u6CE8"),
71
+ state: z.string().nullish().describe("\u7CFB\u7EDF\u72B6\u6001"),
72
+ status: z.string().nullish().describe("\u72B6\u6001"),
73
+ statusReason: z.string().nullish().describe("\u72B6\u6001\u539F\u56E0"),
74
+ statusUpdatedAt: rz.dateTime.nullish().describe("\u72B6\u6001\u66F4\u65B0\u65F6\u95F4"),
75
+ statusUpdatedById: rz.resourceId.nullish().describe("\u72B6\u6001\u66F4\u65B0\u4EBA"),
76
+ createdAt: rz.dateTime.nullish().readonly().describe("\u521B\u5EFA\u65F6\u95F4"),
77
+ updatedAt: rz.dateTime.nullish().readonly().describe("\u66F4\u65B0\u65F6\u95F4"),
78
+ deletedAt: rz.dateTime.nullish().readonly().describe("\u5220\u9664\u65F6\u95F4"),
79
+ createdById: z.string().nullish().readonly().describe("\u521B\u5EFA\u4EBA"),
80
+ updatedById: z.string().nullish().readonly().describe("\u66F4\u65B0\u4EBA"),
81
+ deletedById: z.string().nullish().readonly().describe("\u5220\u9664\u4EBA"),
82
+ attributes: z.record(z.string(), z.any()).nullish().describe("\u81EA\u5B9A\u4E49\u5C5E\u6027"),
83
+ properties: z.record(z.string(), z.any()).nullish().describe("\u5C5E\u6027"),
84
+ extensions: z.record(z.string(), z.any()).nullish().describe("\u6269\u5C55\u5C5E\u6027"),
85
+ __typename: z.coerce.string().nullish().describe("\u7C7B\u578B")
86
+ }).meta({
87
+ title: "AnyResource",
88
+ description: "\u4EFB\u610F\u8D44\u6E90"
89
+ });
@@ -0,0 +1,29 @@
1
+ import { AnyResourceSchema } from "./AnyResourceSchema.js";
2
+ export var BaseResourceSchema = AnyResourceSchema.pick({
3
+ id: true,
4
+ uid: true,
5
+ tid: true,
6
+ eid: true,
7
+ state: true,
8
+ status: true,
9
+ statusReason: true,
10
+ statusUpdatedAt: true,
11
+ statusUpdatedById: true,
12
+ createdAt: true,
13
+ updatedAt: true,
14
+ deletedAt: true,
15
+ createdById: true,
16
+ updatedById: true,
17
+ deletedById: true,
18
+ attributes: true,
19
+ properties: true
20
+ }).required({
21
+ uid: true,
22
+ tid: true,
23
+ state: true,
24
+ status: true,
25
+ createdAt: true,
26
+ updatedAt: true,
27
+ attributes: true,
28
+ properties: true
29
+ });
@@ -0,0 +1,118 @@
1
+ import { z } from 'zod/v4';
2
+ export var ResourceActionType = Object.freeze({
3
+ __proto__: null,
4
+ Approve: 'Approve',
5
+ AssignOwner: 'AssignOwner',
6
+ Bind: 'Bind',
7
+ BindCustomer: 'BindCustomer',
8
+ BindEntity: 'BindEntity',
9
+ BindUser: 'BindUser',
10
+ Cancel: 'Cancel',
11
+ ChangePassword: 'ChangePassword',
12
+ ClaimOwner: 'ClaimOwner',
13
+ Close: 'Close',
14
+ Communicate: 'Communicate',
15
+ Complete: 'Complete',
16
+ Create: 'Create',
17
+ Delete: 'Delete',
18
+ Deny: 'Deny',
19
+ Disable: 'Disable',
20
+ Download: 'Download',
21
+ Edit: 'Edit',
22
+ Enable: 'Enable',
23
+ List: 'List',
24
+ Login: 'Login',
25
+ Logout: 'Logout',
26
+ Manage: 'Manage',
27
+ Publish: 'Publish',
28
+ Purge: 'Purge',
29
+ Read: 'Read',
30
+ Reject: 'Reject',
31
+ ReleaseOwner: 'ReleaseOwner',
32
+ ResetPassword: 'ResetPassword',
33
+ ReturnForRevision: 'ReturnForRevision',
34
+ Revise: 'Revise',
35
+ SaveDraft: 'SaveDraft',
36
+ Signup: 'Signup',
37
+ Submit: 'Submit',
38
+ SubmitAgency: 'SubmitAgency',
39
+ SubmitVendor: 'SubmitVendor',
40
+ Suspend: 'Suspend',
41
+ Terminate: 'Terminate',
42
+ Timeout: 'Timeout',
43
+ Unbind: 'Unbind',
44
+ UnbindCustomer: 'UnbindCustomer',
45
+ UnbindEntity: 'UnbindEntity',
46
+ UnbindUser: 'UnbindUser',
47
+ Undelete: 'Undelete',
48
+ Unpublish: 'Unpublish',
49
+ Update: 'Update',
50
+ UpdateNotes: 'UpdateNotes',
51
+ UpdateTags: 'UpdateTags',
52
+ Upload: 'Upload',
53
+ Validate: 'Validate',
54
+ View: 'View',
55
+ Write: 'Write'
56
+ });
57
+ export var ResourceActionTypeSchema = z.union([
58
+ z.literal(ResourceActionType.Approve).describe('批准'),
59
+ z.literal(ResourceActionType.AssignOwner).describe('分配负责人'),
60
+ z.literal(ResourceActionType.Bind).describe('绑定'),
61
+ z.literal(ResourceActionType.BindCustomer).describe('绑定客户'),
62
+ z.literal(ResourceActionType.BindEntity).describe('绑定实体'),
63
+ z.literal(ResourceActionType.BindUser).describe('绑定用户'),
64
+ z.literal(ResourceActionType.Cancel).describe('取消'),
65
+ z.literal(ResourceActionType.ChangePassword).describe('修改密码'),
66
+ z.literal(ResourceActionType.ClaimOwner).describe('认领负责人'),
67
+ z.literal(ResourceActionType.Close).describe('关闭'),
68
+ z.literal(ResourceActionType.Communicate).describe('沟通'),
69
+ z.literal(ResourceActionType.Complete).describe('完成'),
70
+ z.literal(ResourceActionType.Create).describe('创建'),
71
+ z.literal(ResourceActionType.Delete).describe('删除'),
72
+ z.literal(ResourceActionType.Deny).describe('拒绝'),
73
+ z.literal(ResourceActionType.Disable).describe('禁用'),
74
+ z.literal(ResourceActionType.Download).describe('下载'),
75
+ z.literal(ResourceActionType.Edit).describe('编辑'),
76
+ z.literal(ResourceActionType.Enable).describe('启用'),
77
+ z.literal(ResourceActionType.List).describe('列表'),
78
+ z.literal(ResourceActionType.Login).describe('登录'),
79
+ z.literal(ResourceActionType.Logout).describe('登出'),
80
+ z.literal(ResourceActionType.Manage).describe('管理'),
81
+ z.literal(ResourceActionType.Publish).describe('发布'),
82
+ z.literal(ResourceActionType.Purge).describe('彻底删除'),
83
+ z.literal(ResourceActionType.Read).describe('读取'),
84
+ z.literal(ResourceActionType.Reject).describe('驳回'),
85
+ z.literal(ResourceActionType.ReleaseOwner).describe('释放负责人'),
86
+ z.literal(ResourceActionType.ResetPassword).describe('重置密码'),
87
+ z.literal(ResourceActionType.ReturnForRevision).describe('退回修订'),
88
+ z.literal(ResourceActionType.Revise).describe('修订'),
89
+ z.literal(ResourceActionType.SaveDraft).describe('保存草稿'),
90
+ z.literal(ResourceActionType.Signup).describe('注册'),
91
+ z.literal(ResourceActionType.Submit).describe('提交'),
92
+ z.literal(ResourceActionType.SubmitAgency).describe('提交机构'),
93
+ z.literal(ResourceActionType.SubmitVendor).describe('提交供应商'),
94
+ z.literal(ResourceActionType.Suspend).describe('暂停'),
95
+ z.literal(ResourceActionType.Terminate).describe('终止'),
96
+ z.literal(ResourceActionType.Timeout).describe('超时'),
97
+ z.literal(ResourceActionType.Unbind).describe('解绑'),
98
+ z.literal(ResourceActionType.UnbindCustomer).describe('解绑客户'),
99
+ z.literal(ResourceActionType.UnbindEntity).describe('解绑实体'),
100
+ z.literal(ResourceActionType.UnbindUser).describe('解绑用户'),
101
+ z.literal(ResourceActionType.Undelete).describe('恢复删除'),
102
+ z.literal(ResourceActionType.Unpublish).describe('取消发布'),
103
+ z.literal(ResourceActionType.Update).describe('更新'),
104
+ z.literal(ResourceActionType.UpdateNotes).describe('修改备注'),
105
+ z.literal(ResourceActionType.UpdateNotes).describe('更新备注'),
106
+ z.literal(ResourceActionType.UpdateTags).describe('更新标签'),
107
+ z.literal(ResourceActionType.Upload).describe('上传'),
108
+ z.literal(ResourceActionType.Validate).describe('校验'),
109
+ z.literal(ResourceActionType.View).describe('查看'),
110
+ z.literal(ResourceActionType.Write).describe('写入')
111
+ ]).meta({
112
+ title: 'ResourceAction',
113
+ description: '资源操作',
114
+ type: 'string'
115
+ });
116
+ export var ResourceActionDataSchema = z.object({
117
+ reason: z.string().optional().describe('操作原因')
118
+ });