@wener/common 2.0.5 → 2.0.6

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 (206) hide show
  1. package/lib/ai/qwen3vl/index.js +1 -1
  2. package/lib/ai/qwen3vl/utils.js +15 -15
  3. package/lib/ai/vision/DocLayoutElementTypeSchema.js +22 -22
  4. package/lib/ai/vision/ImageAnnotationSchema.js +63 -47
  5. package/lib/ai/vision/index.js +2 -2
  6. package/lib/ai/vision/resolveImageAnnotation.js +81 -95
  7. package/lib/cn/ChineseResidentIdNo.js +55 -41
  8. package/lib/cn/ChineseResidentIdNo.mod.js +6 -1
  9. package/lib/cn/ChineseResidentIdNo.test.js +22 -21
  10. package/lib/cn/DivisionCode.js +220 -235
  11. package/lib/cn/DivisionCode.mod.js +6 -1
  12. package/lib/cn/DivisionCode.test.js +92 -121
  13. package/lib/cn/Mod11.js +18 -37
  14. package/lib/cn/Mod31.js +23 -41
  15. package/lib/cn/UnifiedSocialCreditCode.js +143 -137
  16. package/lib/cn/UnifiedSocialCreditCode.mod.js +6 -1
  17. package/lib/cn/UnifiedSocialCreditCode.test.js +21 -15
  18. package/lib/cn/formatChineseAmount.js +46 -71
  19. package/lib/cn/index.js +6 -6
  20. package/lib/cn/mod.js +5 -3
  21. package/lib/cn/parseChineseNumber.js +81 -85
  22. package/lib/cn/parseChineseNumber.test.js +183 -261
  23. package/lib/cn/pinyin/cartesianProduct.js +19 -19
  24. package/lib/cn/pinyin/cartesianProduct.test.js +78 -178
  25. package/lib/cn/pinyin/loader.js +13 -11
  26. package/lib/cn/pinyin/preload.js +2 -1
  27. package/lib/cn/pinyin/toPinyin.test.js +149 -161
  28. package/lib/cn/pinyin/toPinyinPure.js +28 -23
  29. package/lib/cn/pinyin/transform.js +11 -11
  30. package/lib/cn/types.d.js +2 -2
  31. package/lib/consola/createStandardConsolaReporter.js +14 -15
  32. package/lib/consola/formatLogObject.js +149 -133
  33. package/lib/consola/formatLogObject.test.js +167 -178
  34. package/lib/consola/index.js +2 -2
  35. package/lib/data/formatSort.js +14 -12
  36. package/lib/data/formatSort.test.js +33 -33
  37. package/lib/data/index.js +3 -3
  38. package/lib/data/maybeNumber.js +23 -23
  39. package/lib/data/parseSort.js +75 -68
  40. package/lib/data/parseSort.test.js +196 -187
  41. package/lib/data/resolvePagination.js +38 -39
  42. package/lib/data/resolvePagination.test.js +228 -218
  43. package/lib/data/types.d.js +2 -2
  44. package/lib/dayjs/dayjs.js +20 -20
  45. package/lib/dayjs/formatDuration.js +56 -56
  46. package/lib/dayjs/formatDuration.test.js +63 -77
  47. package/lib/dayjs/index.js +4 -4
  48. package/lib/dayjs/parseDuration.js +21 -26
  49. package/lib/dayjs/parseRelativeTime.js +65 -66
  50. package/lib/dayjs/parseRelativeTime.test.js +227 -243
  51. package/lib/dayjs/resolveRelativeTime.js +73 -72
  52. package/lib/dayjs/resolveRelativeTime.test.js +296 -307
  53. package/lib/decimal/index.js +1 -1
  54. package/lib/decimal/parseDecimal.js +12 -12
  55. package/lib/drain3/Drain.js +303 -338
  56. package/lib/drain3/LogCluster.js +25 -25
  57. package/lib/drain3/Node.js +24 -24
  58. package/lib/drain3/TemplateMiner.js +197 -196
  59. package/lib/drain3/index.js +5 -5
  60. package/lib/drain3/persistence/FilePersistence.js +19 -19
  61. package/lib/drain3/persistence/MemoryPersistence.js +8 -8
  62. package/lib/drain3/persistence/PersistenceHandler.js +2 -2
  63. package/lib/drain3/types.js +2 -2
  64. package/lib/emittery/emitter.js +7 -7
  65. package/lib/emittery/index.js +1 -1
  66. package/lib/foundation/schema/SexType.js +15 -12
  67. package/lib/foundation/schema/index.js +1 -1
  68. package/lib/foundation/schema/parseSexType.js +15 -16
  69. package/lib/foundation/schema/types.js +8 -6
  70. package/lib/fs/FileSystemError.js +18 -18
  71. package/lib/fs/IFileSystem.d.js +2 -2
  72. package/lib/fs/MemoryFileSystem.test.js +172 -181
  73. package/lib/fs/createBrowserFileSystem.js +222 -235
  74. package/lib/fs/createMemoryFileSystem.js +472 -510
  75. package/lib/fs/createSandboxFileSystem.js +102 -101
  76. package/lib/fs/createWebDavFileSystem.js +162 -149
  77. package/lib/fs/createWebFileSystem.js +197 -220
  78. package/lib/fs/findMimeType.js +14 -14
  79. package/lib/fs/index.js +7 -7
  80. package/lib/fs/minio/createMinioFileSystem.js +959 -956
  81. package/lib/fs/minio/index.js +1 -1
  82. package/lib/fs/orpc/FileSystemContract.js +57 -57
  83. package/lib/fs/orpc/createContractClientFileSystem.js +88 -88
  84. package/lib/fs/orpc/index.js +2 -2
  85. package/lib/fs/orpc/server/createFileSystemContractImpl.js +62 -60
  86. package/lib/fs/orpc/server/index.js +1 -1
  87. package/lib/fs/s3/createS3MiniFileSystem.js +756 -737
  88. package/lib/fs/s3/index.js +1 -1
  89. package/lib/fs/s3/s3mini.test.js +524 -553
  90. package/lib/fs/scandir.js +56 -56
  91. package/lib/fs/server/createDatabaseFileSystem.js +834 -741
  92. package/lib/fs/server/createNodeFileSystem.js +407 -405
  93. package/lib/fs/server/dbfs.test.js +201 -214
  94. package/lib/fs/server/index.js +1 -1
  95. package/lib/fs/server/loadTestDatabase.js +40 -43
  96. package/lib/fs/tests/runFileSystemTest.js +352 -316
  97. package/lib/fs/types.js +17 -20
  98. package/lib/fs/utils/getFileUrl.js +24 -30
  99. package/lib/fs/utils.js +17 -17
  100. package/lib/fs/webdav/index.js +1 -1
  101. package/lib/index.js +2 -2
  102. package/lib/jsonschema/JsonSchema.js +216 -155
  103. package/lib/jsonschema/JsonSchema.test.js +123 -124
  104. package/lib/jsonschema/forEachJsonSchema.js +41 -41
  105. package/lib/jsonschema/index.js +2 -2
  106. package/lib/jsonschema/types.d.js +2 -2
  107. package/lib/meta/defineFileType.js +32 -38
  108. package/lib/meta/defineInit.js +39 -35
  109. package/lib/meta/defineMetadata.js +37 -34
  110. package/lib/meta/defineMetadata.test.js +13 -12
  111. package/lib/meta/index.js +3 -3
  112. package/lib/orpc/createOpenApiContractClient.js +26 -24
  113. package/lib/orpc/createRpcContractClient.js +37 -31
  114. package/lib/orpc/index.js +2 -2
  115. package/lib/orpc/resolveLinkPlugins.js +25 -25
  116. package/lib/password/PHC.js +187 -189
  117. package/lib/password/PHC.test.js +517 -535
  118. package/lib/password/Password.js +85 -80
  119. package/lib/password/Password.test.js +330 -364
  120. package/lib/password/createArgon2PasswordAlgorithm.js +50 -51
  121. package/lib/password/createBase64PasswordAlgorithm.js +11 -11
  122. package/lib/password/createBcryptPasswordAlgorithm.js +20 -18
  123. package/lib/password/createPBKDF2PasswordAlgorithm.js +65 -52
  124. package/lib/password/createScryptPasswordAlgorithm.js +74 -63
  125. package/lib/password/index.js +5 -5
  126. package/lib/password/server/index.js +1 -1
  127. package/lib/resource/Identifiable.js +2 -2
  128. package/lib/resource/ListQuery.js +42 -42
  129. package/lib/resource/getTitleOfResource.js +5 -5
  130. package/lib/resource/index.js +2 -2
  131. package/lib/resource/schema/AnyResourceSchema.js +91 -89
  132. package/lib/resource/schema/BaseResourceSchema.js +26 -26
  133. package/lib/resource/schema/ResourceActionType.js +117 -115
  134. package/lib/resource/schema/ResourceStatus.js +94 -92
  135. package/lib/resource/schema/ResourceType.js +25 -23
  136. package/lib/resource/schema/index.js +5 -5
  137. package/lib/resource/schema/types.js +86 -55
  138. package/lib/resource/schema/types.test.js +16 -13
  139. package/lib/s3/formatS3Url.js +60 -60
  140. package/lib/s3/formatS3Url.test.js +238 -261
  141. package/lib/s3/index.js +2 -2
  142. package/lib/s3/parseS3Url.js +61 -60
  143. package/lib/s3/parseS3Url.test.js +270 -269
  144. package/lib/schema/SchemaRegistry.js +41 -42
  145. package/lib/schema/SchemaRegistry.mod.js +1 -1
  146. package/lib/schema/TypeSchema.d.js +2 -2
  147. package/lib/schema/createSchemaData.js +113 -67
  148. package/lib/schema/findJsonSchemaByPath.js +28 -23
  149. package/lib/schema/formatZodError.js +112 -131
  150. package/lib/schema/formatZodError.test.js +192 -195
  151. package/lib/schema/getSchemaCache.js +7 -7
  152. package/lib/schema/getSchemaOptions.js +17 -16
  153. package/lib/schema/index.js +6 -6
  154. package/lib/schema/toJsonSchema.js +195 -189
  155. package/lib/schema/toJsonSchema.test.js +34 -26
  156. package/lib/schema/validate.js +105 -96
  157. package/lib/tools/generateSchema.js +40 -40
  158. package/lib/tools/renderJsonSchemaToMarkdownDoc.js +74 -74
  159. package/lib/utils/buildBaseUrl.js +8 -8
  160. package/lib/utils/buildRedactorFormSchema.js +54 -53
  161. package/lib/utils/getEstimateProcessTime.js +24 -19
  162. package/lib/utils/index.js +3 -3
  163. package/lib/utils/resolveFeatureOptions.js +9 -9
  164. package/package.json +14 -14
  165. package/src/ai/vision/index.ts +2 -2
  166. package/src/cn/index.ts +1 -2
  167. package/src/consola/index.ts +1 -1
  168. package/src/data/index.ts +3 -4
  169. package/src/data/resolvePagination.ts +2 -2
  170. package/src/dayjs/formatDuration.ts +8 -9
  171. package/src/dayjs/index.ts +1 -1
  172. package/src/dayjs/parseRelativeTime.ts +1 -1
  173. package/src/dayjs/resolveRelativeTime.ts +1 -1
  174. package/src/drain3/Drain.test.ts +2 -2
  175. package/src/drain3/index.ts +2 -4
  176. package/src/fs/createWebDavFileSystem.ts +2 -7
  177. package/src/fs/createWebFileSystem.ts +1 -1
  178. package/src/fs/index.ts +4 -4
  179. package/src/fs/minio/createMinioFileSystem.ts +2 -2
  180. package/src/fs/minio/index.ts +1 -1
  181. package/src/fs/s3/createS3MiniFileSystem.ts +1 -1
  182. package/src/fs/server/createDatabaseFileSystem.ts +84 -120
  183. package/src/fs/server/dbfs.test.ts +14 -10
  184. package/src/fs/server/index.ts +1 -0
  185. package/src/fs/server/loadTestDatabase.ts +8 -119
  186. package/src/jsonschema/index.ts +1 -1
  187. package/src/meta/index.ts +2 -3
  188. package/src/orm/createSqliteDialect.ts +17 -0
  189. package/src/orm/index.ts +1 -0
  190. package/src/orpc/createOpenApiContractClient.ts +1 -1
  191. package/src/orpc/index.ts +1 -1
  192. package/src/password/createArgon2PasswordAlgorithm.ts +1 -1
  193. package/src/password/index.ts +2 -2
  194. package/src/resource/index.ts +3 -3
  195. package/src/resource/schema/index.ts +4 -4
  196. package/src/s3/index.ts +1 -1
  197. package/src/schema/SchemaRegistry.ts +1 -1
  198. package/src/schema/createSchemaData.ts +1 -1
  199. package/src/schema/findJsonSchemaByPath.ts +1 -1
  200. package/src/schema/index.ts +5 -5
  201. package/src/schema/validate.ts +1 -1
  202. package/src/utils/buildRedactorFormSchema.ts +1 -1
  203. package/src/utils/formatNumber.ts +18 -0
  204. package/src/utils/formatPercent.ts +17 -0
  205. package/src/utils/index.ts +3 -3
  206. package/src/utils/resolveFeatureOptions.ts +1 -1
@@ -1,53 +1,52 @@
1
- import { maybeFunction } from "@wener/utils";
2
- export function createArgon2PasswordAlgorithm({ type, provide = async ()=>{
3
- throw new Error('Please provide argon2');
4
- // const { default: wasm } = await import('argon2-browser/dist/argon2.wasm');
5
- // const argon2 = await WebAssembly.instantiateStreaming(fetch(wasm), {
6
- // env: {
7
- // memoryBase: 0,
8
- // tableBase: 0,
9
- // memory: new WebAssembly.Memory({ initial: 256 }),
10
- // table: new WebAssembly.Table({ initial: 0, element: 'anyfunc' }),
11
- // __memory_base: 0,
12
- // __table_base: 0,
13
- // },
14
- // });
15
- // console.log(argon2.instance.exports);
16
- // const { hash } = argon2.instance.exports as any as typeof import('argon2-browser');
17
- } } = {}) {
18
- // 0=Argon2d, 1=Argon2i, 2=Argon2id
19
- const toType = {
20
- argon2d: 0,
21
- argon2i: 1,
22
- argon2id: 2
23
- };
24
- let mod;
25
- const resolve = ()=>{
26
- if (mod) return mod;
27
- return Promise.resolve(maybeFunction(provide)).then((v)=>mod = v);
28
- };
29
- return {
30
- name: 'argon2',
31
- ids: [
32
- 'argon2i',
33
- 'argon2d',
34
- 'argon2id'
35
- ],
36
- async hash (password, opts) {
37
- // const { hash } = await import('argon2');
38
- const { hash } = await resolve();
39
- const id = opts?.id;
40
- return hash(password, {
41
- salt: opts?.salt ? Buffer.from(opts.salt) : undefined,
42
- raw: false,
43
- type: toType[id || ''] ?? toType[type || '']
44
- });
45
- },
46
- async verify (password, hash) {
47
- const { verify } = await resolve();
48
- return verify(hash, password);
49
- }
50
- };
1
+ import { maybeFunction } from '@wener/utils';
2
+ export function createArgon2PasswordAlgorithm({
3
+ type,
4
+ provide = async () => {
5
+ throw new Error('Please provide argon2');
6
+ // const { default: wasm } = await import('argon2-browser/dist/argon2.wasm');
7
+ // const argon2 = await WebAssembly.instantiateStreaming(fetch(wasm), {
8
+ // env: {
9
+ // memoryBase: 0,
10
+ // tableBase: 0,
11
+ // memory: new WebAssembly.Memory({ initial: 256 }),
12
+ // table: new WebAssembly.Table({ initial: 0, element: 'anyfunc' }),
13
+ // __memory_base: 0,
14
+ // __table_base: 0,
15
+ // },
16
+ // });
17
+ // console.log(argon2.instance.exports);
18
+ // const { hash } = argon2.instance.exports as any as typeof import('argon2-browser');
19
+ },
20
+ } = {}) {
21
+ // 0=Argon2d, 1=Argon2i, 2=Argon2id
22
+ const toType = {
23
+ argon2d: 0,
24
+ argon2i: 1,
25
+ argon2id: 2,
26
+ };
27
+ let mod;
28
+ const resolve = () => {
29
+ if (mod) return mod;
30
+ return Promise.resolve(maybeFunction(provide)).then((v) => (mod = v));
31
+ };
32
+ return {
33
+ name: 'argon2',
34
+ ids: ['argon2i', 'argon2d', 'argon2id'],
35
+ async hash(password, opts) {
36
+ // const { hash } = await import('argon2');
37
+ const { hash } = await resolve();
38
+ const id = opts?.id;
39
+ return hash(password, {
40
+ salt: opts?.salt ? Buffer.from(opts.salt) : undefined,
41
+ raw: false,
42
+ type: toType[id || ''] ?? toType[type || ''],
43
+ });
44
+ },
45
+ async verify(password, hash) {
46
+ const { verify } = await resolve();
47
+ return verify(hash, password);
48
+ },
49
+ };
51
50
  }
52
51
 
53
- //# sourceMappingURL=createArgon2PasswordAlgorithm.js.map
52
+ //# sourceMappingURL=createArgon2PasswordAlgorithm.js.map
@@ -1,14 +1,14 @@
1
- import { ArrayBuffers } from "@wener/utils";
1
+ import { ArrayBuffers } from '@wener/utils';
2
2
  export function createBase64PasswordAlgorithm({ id = 'base64' } = {}) {
3
- return {
4
- name: id,
5
- async hash (password) {
6
- return `$${id}$$${ArrayBuffers.toBase64(password).replace(/=/g, '')}`;
7
- },
8
- async verify (password, _hash, opts) {
9
- return Boolean(opts.hash) && ArrayBuffers.toString(opts.hash) === password;
10
- }
11
- };
3
+ return {
4
+ name: id,
5
+ async hash(password) {
6
+ return `$${id}$$${ArrayBuffers.toBase64(password).replace(/=/g, '')}`;
7
+ },
8
+ async verify(password, _hash, opts) {
9
+ return Boolean(opts.hash) && ArrayBuffers.toString(opts.hash) === password;
10
+ },
11
+ };
12
12
  }
13
13
 
14
- //# sourceMappingURL=createBase64PasswordAlgorithm.js.map
14
+ //# sourceMappingURL=createBase64PasswordAlgorithm.js.map
@@ -1,20 +1,22 @@
1
- export function createBcryptPasswordAlgorithm({ // provider = () => import('bcrypt').then((v) => v.default),
2
- provider = ()=>import("bcryptjs").then((v)=>v.default) } = {}) {
3
- // bcrypt or bcryptjs
4
- return {
5
- name: 'bcrypt',
6
- async hash (password, opts) {
7
- const { hash } = await provider();
8
- return hash(password, opts?.rounds ?? 10);
9
- },
10
- async verify (password, hash) {
11
- const { compare } = await provider();
12
- if (hash.startsWith('$2y$')) {
13
- hash = hash.replace(/^\$2y\$/, '$2a$');
14
- }
15
- return compare(password, hash);
16
- }
17
- };
1
+ export function createBcryptPasswordAlgorithm({
2
+ // provider = () => import('bcrypt').then((v) => v.default),
3
+ provider = () => import('bcryptjs').then((v) => v.default),
4
+ } = {}) {
5
+ // bcrypt or bcryptjs
6
+ return {
7
+ name: 'bcrypt',
8
+ async hash(password, opts) {
9
+ const { hash } = await provider();
10
+ return hash(password, opts?.rounds ?? 10);
11
+ },
12
+ async verify(password, hash) {
13
+ const { compare } = await provider();
14
+ if (hash.startsWith('$2y$')) {
15
+ hash = hash.replace(/^\$2y\$/, '$2a$');
16
+ }
17
+ return compare(password, hash);
18
+ },
19
+ };
18
20
  }
19
21
 
20
- //# sourceMappingURL=createBcryptPasswordAlgorithm.js.map
22
+ //# sourceMappingURL=createBcryptPasswordAlgorithm.js.map
@@ -1,54 +1,67 @@
1
- import { Errors } from "@wener/utils";
2
- import { PHC } from "./PHC.js";
3
- export function createPBKDF2PasswordAlgorithm({ id, digest, iterations = 100000, saltlen = 16, keylen = digest === "SHA-256" ? 32 : 64 }) {
4
- return {
5
- name: id,
6
- async hash(password, opts) {
7
- let salt;
8
- if (opts?.salt) {
9
- salt = opts.salt;
10
- }
11
- else {
12
- salt = new Uint8Array(saltlen);
13
- crypto.getRandomValues(salt);
14
- }
15
- const rounds = opts?.rounds ?? iterations;
16
- let key = await crypto.subtle.importKey("raw", new TextEncoder().encode(password), "PBKDF2", false, [
17
- "deriveBits"
18
- ]);
19
- let hash = await crypto.subtle.deriveBits({
20
- name: "PBKDF2",
21
- iterations: rounds,
22
- salt: salt,
23
- hash: digest
24
- }, key, keylen * 8);
25
- return PHC.serialize({
26
- id: opts?.id ?? id,
27
- params: {
28
- rounds
29
- },
30
- salt,
31
- hash: new Uint8Array(hash)
32
- });
33
- },
34
- async verify(password, _, opts) {
35
- const rounds = opts?.params?.rounds ?? iterations;
36
- const salt = opts.salt;
37
- const storedHash = opts.hash;
38
- Errors.BadRequest.check(typeof rounds === "number", "Invalid rounds");
39
- Errors.BadRequest.check(salt instanceof Uint8Array, "Invalid salt");
40
- Errors.BadRequest.check(storedHash instanceof Uint8Array, "Invalid hash");
41
- let key = await crypto.subtle.importKey("raw", new TextEncoder().encode(password), "PBKDF2", false, [
42
- "deriveBits"
43
- ]);
44
- let hash = await crypto.subtle.deriveBits({
45
- name: "PBKDF2",
46
- iterations: rounds,
47
- salt: salt,
48
- hash: digest
49
- }, key, storedHash.length * 8);
50
- return new Uint8Array(hash).every((v, i) => v === storedHash?.[i]);
51
- }
52
- };
1
+ import { Errors } from '@wener/utils';
2
+ import { PHC } from './PHC.js';
3
+ export function createPBKDF2PasswordAlgorithm({
4
+ id,
5
+ digest,
6
+ iterations = 100000,
7
+ saltlen = 16,
8
+ keylen = digest === 'SHA-256' ? 32 : 64,
9
+ }) {
10
+ return {
11
+ name: id,
12
+ async hash(password, opts) {
13
+ let salt;
14
+ if (opts?.salt) {
15
+ salt = opts.salt;
16
+ } else {
17
+ salt = new Uint8Array(saltlen);
18
+ crypto.getRandomValues(salt);
19
+ }
20
+ const rounds = opts?.rounds ?? iterations;
21
+ let key = await crypto.subtle.importKey('raw', new TextEncoder().encode(password), 'PBKDF2', false, [
22
+ 'deriveBits',
23
+ ]);
24
+ let hash = await crypto.subtle.deriveBits(
25
+ {
26
+ name: 'PBKDF2',
27
+ iterations: rounds,
28
+ salt: salt,
29
+ hash: digest,
30
+ },
31
+ key,
32
+ keylen * 8,
33
+ );
34
+ return PHC.serialize({
35
+ id: opts?.id ?? id,
36
+ params: {
37
+ rounds,
38
+ },
39
+ salt,
40
+ hash: new Uint8Array(hash),
41
+ });
42
+ },
43
+ async verify(password, _, opts) {
44
+ const rounds = opts?.params?.rounds ?? iterations;
45
+ const salt = opts.salt;
46
+ const storedHash = opts.hash;
47
+ Errors.BadRequest.check(typeof rounds === 'number', 'Invalid rounds');
48
+ Errors.BadRequest.check(salt instanceof Uint8Array, 'Invalid salt');
49
+ Errors.BadRequest.check(storedHash instanceof Uint8Array, 'Invalid hash');
50
+ let key = await crypto.subtle.importKey('raw', new TextEncoder().encode(password), 'PBKDF2', false, [
51
+ 'deriveBits',
52
+ ]);
53
+ let hash = await crypto.subtle.deriveBits(
54
+ {
55
+ name: 'PBKDF2',
56
+ iterations: rounds,
57
+ salt: salt,
58
+ hash: digest,
59
+ },
60
+ key,
61
+ storedHash.length * 8,
62
+ );
63
+ return new Uint8Array(hash).every((v, i) => v === storedHash?.[i]);
64
+ },
65
+ };
53
66
  }
54
67
  //# sourceMappingURL=createPBKDF2PasswordAlgorithm.js.map
@@ -1,66 +1,77 @@
1
- import { randomBytes, scrypt, timingSafeEqual } from "node:crypto";
2
- import { Errors } from "@wener/utils";
3
- import { PHC } from "./PHC.js";
1
+ import { randomBytes, scrypt, timingSafeEqual } from 'node:crypto';
2
+ import { Errors } from '@wener/utils';
3
+ import { PHC } from './PHC.js';
4
4
  export function createScryptPasswordAlgorithm(options = {}) {
5
- let id = options.id || "scrypt";
6
- options.cost ||= 2 ** 14;
7
- options.blocksize ||= 8;
8
- options.parallelism ||= 1;
9
- options.saltlen ||= 16;
10
- options.keylen ||= 32;
11
- return {
12
- 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
- }));
36
- });
37
- });
38
- },
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
- });
58
- });
59
- }
60
- catch (_error) {
61
- return Promise.resolve(false);
62
- }
63
- }
64
- };
5
+ let id = options.id || 'scrypt';
6
+ options.cost ||= 2 ** 14;
7
+ options.blocksize ||= 8;
8
+ options.parallelism ||= 1;
9
+ options.saltlen ||= 16;
10
+ options.keylen ||= 32;
11
+ return {
12
+ 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(
20
+ password,
21
+ salt,
22
+ options.keylen,
23
+ {
24
+ N,
25
+ r,
26
+ p,
27
+ },
28
+ (err, derivedKey) => {
29
+ if (err) return reject(err);
30
+ resolve(
31
+ PHC.serialize({
32
+ id: opts?.id ?? id,
33
+ params: {
34
+ ln: N,
35
+ r: r,
36
+ p: p,
37
+ },
38
+ salt,
39
+ hash: derivedKey,
40
+ }),
41
+ );
42
+ },
43
+ );
44
+ });
45
+ },
46
+ async verify(password, _hash, opts) {
47
+ try {
48
+ const salt = Errors.BadRequest.require(opts.salt);
49
+ const storedHash = Errors.BadRequest.require(opts.hash);
50
+ const N = parseInt(opts.params?.ln, 10);
51
+ const r = parseInt(opts.params?.r, 10);
52
+ const p = parseInt(opts.params?.p, 10);
53
+ const keylen = storedHash.length;
54
+ return new Promise((resolve, reject) => {
55
+ scrypt(
56
+ password,
57
+ salt,
58
+ keylen,
59
+ {
60
+ N,
61
+ r,
62
+ p,
63
+ },
64
+ (err, derivedKey) => {
65
+ if (err) return reject(err);
66
+ const isMatch = timingSafeEqual(derivedKey, storedHash);
67
+ resolve(isMatch);
68
+ },
69
+ );
70
+ });
71
+ } catch (_error) {
72
+ return Promise.resolve(false);
73
+ }
74
+ },
75
+ };
65
76
  }
66
77
  //# sourceMappingURL=createScryptPasswordAlgorithm.js.map
@@ -1,6 +1,6 @@
1
- export { PHC } from "./PHC.js";
2
- export { Password } from "./Password.js";
3
- export { createArgon2PasswordAlgorithm } from "./createArgon2PasswordAlgorithm.js";
4
- export { createBase64PasswordAlgorithm } from "./createBase64PasswordAlgorithm.js";
5
- export { createBcryptPasswordAlgorithm } from "./createBcryptPasswordAlgorithm.js";
1
+ export { createArgon2PasswordAlgorithm } from './createArgon2PasswordAlgorithm.js';
2
+ export { createBase64PasswordAlgorithm } from './createBase64PasswordAlgorithm.js';
3
+ export { createBcryptPasswordAlgorithm } from './createBcryptPasswordAlgorithm.js';
4
+ export { Password } from './Password.js';
5
+ export { PHC } from './PHC.js';
6
6
  //# sourceMappingURL=index.js.map
@@ -1,2 +1,2 @@
1
- export { createScryptPasswordAlgorithm } from "../createScryptPasswordAlgorithm.js";
1
+ export { createScryptPasswordAlgorithm } from '../createScryptPasswordAlgorithm.js';
2
2
  //# sourceMappingURL=index.js.map
@@ -1,3 +1,3 @@
1
- export { };
1
+ export {};
2
2
 
3
- //# sourceMappingURL=Identifiable.js.map
3
+ //# sourceMappingURL=Identifiable.js.map
@@ -1,47 +1,47 @@
1
- import { z } from "zod/v4";
2
- const IntLikeSchema = z.coerce.number().multipleOf(1).min(0).optional().overwrite((v)=>v || undefined);
1
+ import { z } from 'zod/v4';
2
+
3
+ const IntLikeSchema = z.coerce
4
+ .number()
5
+ .multipleOf(1)
6
+ .min(0)
7
+ .optional()
8
+ .overwrite((v) => v || undefined);
3
9
  export const ListQuerySchema = z.object({
4
- id: z.coerce.string().optional(),
5
- ids: z.array(z.coerce.string()).optional(),
6
- filter: z.string().optional().describe('sql-like filter string'),
7
- filters: z.array(z.any()).optional().describe('sql-like filter string'),
8
- where: z.record(z.string(), z.any()).optional().describe('document query filter'),
9
- search: z.string().optional(),
10
- limit: IntLikeSchema,
11
- offset: IntLikeSchema,
12
- order: z.array(z.string()).optional().describe('order like "a,-b,c desc null last"'),
13
- pageIndex: IntLikeSchema.describe('0-based page index'),
14
- pageNumber: IntLikeSchema.describe('1-based page number'),
15
- pageSize: IntLikeSchema,
16
- cursor: z.string().optional(),
17
- deleted: z.coerce.boolean().optional()
10
+ id: z.coerce.string().optional(),
11
+ ids: z.array(z.coerce.string()).optional(),
12
+ filter: z.string().optional().describe('sql-like filter string'),
13
+ filters: z.array(z.any()).optional().describe('sql-like filter string'),
14
+ where: z.record(z.string(), z.any()).optional().describe('document query filter'),
15
+ search: z.string().optional(),
16
+ limit: IntLikeSchema,
17
+ offset: IntLikeSchema,
18
+ order: z.array(z.string()).optional().describe('order like "a,-b,c desc null last"'),
19
+ pageIndex: IntLikeSchema.describe('0-based page index'),
20
+ pageNumber: IntLikeSchema.describe('1-based page number'),
21
+ pageSize: IntLikeSchema,
22
+ cursor: z.string().optional(),
23
+ deleted: z.coerce.boolean().optional(),
18
24
  });
19
25
  export function resolveListQuery(target, ...args) {
20
- let out = args.reduce((a, source)=>{
21
- if (typeof source === 'function') {
22
- const result = source(a);
23
- // do not use the result as merge source
24
- return result || a;
25
- }
26
- let b = source;
27
- if (!b) return a;
28
- // do not resolve id to ids
29
- let ids = [
30
- ...a.ids || [],
31
- ...b.ids || []
32
- ];
33
- return {
34
- ...a,
35
- ...b,
36
- ids: ids,
37
- filters: [
38
- ...a.filters || [],
39
- ...b.filters || []
40
- ],
41
- search: b.search || a.search
42
- };
43
- }, target || {});
44
- return ListQuerySchema.parse(out);
26
+ let out = args.reduce((a, source) => {
27
+ if (typeof source === 'function') {
28
+ const result = source(a);
29
+ // do not use the result as merge source
30
+ return result || a;
31
+ }
32
+ let b = source;
33
+ if (!b) return a;
34
+ // do not resolve id to ids
35
+ let ids = [...(a.ids || []), ...(b.ids || [])];
36
+ return {
37
+ ...a,
38
+ ...b,
39
+ ids: ids,
40
+ filters: [...(a.filters || []), ...(b.filters || [])],
41
+ search: b.search || a.search,
42
+ };
43
+ }, target || {});
44
+ return ListQuerySchema.parse(out);
45
45
  }
46
46
 
47
- //# sourceMappingURL=ListQuery.js.map
47
+ //# sourceMappingURL=ListQuery.js.map
@@ -1,8 +1,8 @@
1
1
  export function getTitleOfResource(res) {
2
- if (res && typeof res === 'object') {
3
- return res.displayName || res.title || res.fullName || res.loginName || res.topic || res.code;
4
- }
5
- return undefined;
2
+ if (res && typeof res === 'object') {
3
+ return res.displayName || res.title || res.fullName || res.loginName || res.topic || res.code;
4
+ }
5
+ return undefined;
6
6
  }
7
7
 
8
- //# sourceMappingURL=getTitleOfResource.js.map
8
+ //# sourceMappingURL=getTitleOfResource.js.map
@@ -1,3 +1,3 @@
1
- export { getTitleOfResource } from "./getTitleOfResource.js";
2
- export { resolveListQuery, ListQuerySchema } from "./ListQuery.js";
1
+ export { getTitleOfResource } from './getTitleOfResource.js';
2
+ export { ListQuerySchema, resolveListQuery } from './ListQuery.js';
3
3
  //# sourceMappingURL=index.js.map