@wener/common 1.0.5 → 2.0.1

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
Files changed (152) hide show
  1. package/lib/cn/DivisionCode.js +55 -32
  2. package/lib/cn/DivisionCode.test.js +140 -0
  3. package/lib/cn/Mod11Checksum.js +80 -37
  4. package/lib/cn/Mod31Checksum.js +89 -40
  5. package/lib/cn/ResidentIdentityCardNumber.js +16 -16
  6. package/lib/cn/ResidentIdentityCardNumber.test.js +21 -0
  7. package/lib/cn/UnifiedSocialCreditCode.js +32 -26
  8. package/lib/cn/UnifiedSocialCreditCode.test.js +16 -0
  9. package/lib/cn/formatDate.js +5 -7
  10. package/lib/cn/index.js +0 -1
  11. package/lib/cn/parseSex.js +0 -2
  12. package/lib/cn/types.d.js +0 -2
  13. package/lib/consola/createStandardConsolaReporter.js +6 -6
  14. package/lib/consola/formatLogObject.js +133 -32
  15. package/lib/consola/index.js +0 -1
  16. package/lib/data/formatSort.js +5 -6
  17. package/lib/data/formatSort.test.js +34 -0
  18. package/lib/data/index.js +0 -1
  19. package/lib/data/maybeNumber.js +11 -5
  20. package/lib/data/parseSort.js +28 -22
  21. package/lib/data/parseSort.test.js +188 -0
  22. package/lib/data/resolvePagination.js +27 -16
  23. package/lib/data/resolvePagination.test.js +232 -0
  24. package/lib/data/types.d.js +0 -2
  25. package/lib/index.js +0 -1
  26. package/lib/jsonschema/JsonSchema.js +78 -52
  27. package/lib/jsonschema/JsonSchema.test.js +137 -0
  28. package/lib/jsonschema/index.js +0 -1
  29. package/lib/jsonschema/types.d.js +5 -3
  30. package/lib/meta/defineFileType.js +103 -20
  31. package/lib/meta/defineInit.js +250 -31
  32. package/lib/meta/defineMetadata.js +140 -24
  33. package/lib/meta/defineMetadata.test.js +13 -0
  34. package/lib/meta/index.js +0 -1
  35. package/lib/password/PHC.js +87 -63
  36. package/lib/password/PHC.test.js +539 -0
  37. package/lib/password/Password.js +291 -29
  38. package/lib/password/Password.test.js +362 -0
  39. package/lib/password/createArgon2PasswordAlgorithm.js +191 -35
  40. package/lib/password/createBase64PasswordAlgorithm.js +141 -8
  41. package/lib/password/createBcryptPasswordAlgorithm.js +168 -13
  42. package/lib/password/createPBKDF2PasswordAlgorithm.js +228 -46
  43. package/lib/password/createScryptPasswordAlgorithm.js +211 -55
  44. package/lib/password/index.js +0 -1
  45. package/lib/password/server/index.js +0 -1
  46. package/lib/resource/Identifiable.js +1 -0
  47. package/lib/resource/getTitleOfResource.js +10 -0
  48. package/lib/resource/index.js +1 -0
  49. package/lib/resource/schema/AnyResourceSchema.js +89 -0
  50. package/lib/resource/schema/BaseResourceSchema.js +29 -0
  51. package/lib/resource/schema/ResourceActionType.js +118 -0
  52. package/lib/resource/schema/ResourceStatus.js +93 -0
  53. package/lib/resource/schema/ResourceType.js +24 -0
  54. package/lib/resource/schema/SchemaRegistry.js +38 -0
  55. package/lib/resource/schema/SexType.js +10 -0
  56. package/lib/resource/schema/types.js +89 -0
  57. package/lib/resource/schema/types.test.js +14 -0
  58. package/lib/schema/TypeSchema.d.js +1 -0
  59. package/lib/schema/createSchemaData.js +173 -0
  60. package/lib/schema/findJsonSchemaByPath.js +49 -0
  61. package/lib/schema/getSchemaCache.js +11 -0
  62. package/lib/schema/getSchemaOptions.js +24 -0
  63. package/lib/schema/index.js +5 -0
  64. package/lib/schema/toJsonSchema.js +441 -0
  65. package/lib/schema/toJsonSchema.test.js +27 -0
  66. package/lib/schema/validate.js +124 -0
  67. package/lib/search/AdvanceSearch.js +0 -1
  68. package/lib/search/AdvanceSearch.test.js +435 -0
  69. package/lib/search/formatAdvanceSearch.js +41 -27
  70. package/lib/search/index.js +0 -1
  71. package/lib/search/optimizeAdvanceSearch.js +79 -25
  72. package/lib/search/parseAdvanceSearch.js +5 -5
  73. package/lib/search/parser.d.js +0 -2
  74. package/lib/search/parser.js +97 -74
  75. package/lib/search/types.d.js +0 -2
  76. package/lib/tools/generateSchema.js +197 -39
  77. package/lib/tools/renderJsonSchemaToMarkdownDoc.js +143 -55
  78. package/package.json +23 -11
  79. package/src/data/maybeNumber.ts +5 -1
  80. package/src/data/resolvePagination.test.ts +1 -1
  81. package/src/data/resolvePagination.ts +18 -7
  82. package/src/data/types.d.ts +12 -0
  83. package/src/jsonschema/JsonSchema.test.ts +17 -0
  84. package/src/jsonschema/JsonSchema.ts +2 -2
  85. package/src/jsonschema/types.d.ts +63 -12
  86. package/src/resource/Identifiable.ts +3 -0
  87. package/src/resource/getTitleOfResource.tsx +6 -0
  88. package/src/resource/index.ts +3 -0
  89. package/src/resource/schema/AnyResourceSchema.ts +113 -0
  90. package/src/resource/schema/BaseResourceSchema.ts +32 -0
  91. package/src/resource/schema/ResourceActionType.ts +123 -0
  92. package/src/resource/schema/ResourceStatus.ts +94 -0
  93. package/src/resource/schema/ResourceType.ts +25 -0
  94. package/src/resource/schema/SchemaRegistry.ts +42 -0
  95. package/src/resource/schema/SexType.ts +13 -0
  96. package/src/resource/schema/types.test.ts +18 -0
  97. package/src/resource/schema/types.ts +105 -0
  98. package/src/schema/TypeSchema.d.ts +32 -0
  99. package/src/schema/createSchemaData.ts +81 -0
  100. package/src/schema/findJsonSchemaByPath.ts +37 -0
  101. package/src/schema/getSchemaCache.ts +21 -0
  102. package/src/schema/getSchemaOptions.ts +24 -0
  103. package/src/schema/index.ts +6 -0
  104. package/src/schema/toJsonSchema.test.ts +37 -0
  105. package/src/schema/toJsonSchema.ts +200 -0
  106. package/src/schema/validate.ts +135 -0
  107. package/src/tools/generateSchema.ts +28 -28
  108. package/lib/cn/DivisionCode.js.map +0 -1
  109. package/lib/cn/Mod11Checksum.js.map +0 -1
  110. package/lib/cn/Mod31Checksum.js.map +0 -1
  111. package/lib/cn/ResidentIdentityCardNumber.js.map +0 -1
  112. package/lib/cn/UnifiedSocialCreditCode.js.map +0 -1
  113. package/lib/cn/formatDate.js.map +0 -1
  114. package/lib/cn/index.js.map +0 -1
  115. package/lib/cn/parseSex.js.map +0 -1
  116. package/lib/cn/types.d.js.map +0 -1
  117. package/lib/consola/createStandardConsolaReporter.js.map +0 -1
  118. package/lib/consola/formatLogObject.js.map +0 -1
  119. package/lib/consola/index.js.map +0 -1
  120. package/lib/data/formatSort.js.map +0 -1
  121. package/lib/data/index.js.map +0 -1
  122. package/lib/data/maybeNumber.js.map +0 -1
  123. package/lib/data/parseSort.js.map +0 -1
  124. package/lib/data/resolvePagination.js.map +0 -1
  125. package/lib/data/types.d.js.map +0 -1
  126. package/lib/index.js.map +0 -1
  127. package/lib/jsonschema/JsonSchema.js.map +0 -1
  128. package/lib/jsonschema/index.js.map +0 -1
  129. package/lib/jsonschema/types.d.js.map +0 -1
  130. package/lib/meta/defineFileType.js.map +0 -1
  131. package/lib/meta/defineInit.js.map +0 -1
  132. package/lib/meta/defineMetadata.js.map +0 -1
  133. package/lib/meta/index.js.map +0 -1
  134. package/lib/password/PHC.js.map +0 -1
  135. package/lib/password/Password.js.map +0 -1
  136. package/lib/password/createArgon2PasswordAlgorithm.js.map +0 -1
  137. package/lib/password/createBase64PasswordAlgorithm.js.map +0 -1
  138. package/lib/password/createBcryptPasswordAlgorithm.js.map +0 -1
  139. package/lib/password/createPBKDF2PasswordAlgorithm.js.map +0 -1
  140. package/lib/password/createScryptPasswordAlgorithm.js.map +0 -1
  141. package/lib/password/index.js.map +0 -1
  142. package/lib/password/server/index.js.map +0 -1
  143. package/lib/search/AdvanceSearch.js.map +0 -1
  144. package/lib/search/formatAdvanceSearch.js.map +0 -1
  145. package/lib/search/index.js.map +0 -1
  146. package/lib/search/optimizeAdvanceSearch.js.map +0 -1
  147. package/lib/search/parseAdvanceSearch.js.map +0 -1
  148. package/lib/search/parser.d.js.map +0 -1
  149. package/lib/search/parser.js.map +0 -1
  150. package/lib/search/types.d.js.map +0 -1
  151. package/lib/tools/generateSchema.js.map +0 -1
  152. package/lib/tools/renderJsonSchemaToMarkdownDoc.js.map +0 -1
@@ -4,36 +4,36 @@ import path from 'node:path';
4
4
  import * as Codegen from '@sinclair/typebox-codegen';
5
5
 
6
6
  export async function generateSchema({ file, dir = path.dirname(file) }: { file: string; dir?: string }) {
7
- const fn = path.basename(file).replace(/\.d\.ts$/, '.ts');
8
- const types = await fs.readFile(file, 'utf-8');
7
+ const fn = path.basename(file).replace(/\.d\.ts$/, '.ts');
8
+ const types = await fs.readFile(file, 'utf-8');
9
9
 
10
- const typeboxDir = path.join(dir, 'typebox');
11
- const zodDir = path.join(dir, 'zod');
10
+ const typeboxDir = path.join(dir, 'typebox');
11
+ const zodDir = path.join(dir, 'zod');
12
12
 
13
- await fs.mkdir(typeboxDir, { recursive: true });
14
- await fs.mkdir(zodDir, { recursive: true });
13
+ await fs.mkdir(typeboxDir, { recursive: true });
14
+ await fs.mkdir(zodDir, { recursive: true });
15
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);
23
- }
24
- const model = Codegen.TypeScriptToModel.Generate(types);
25
- await fs.writeFile(zodFile, Codegen.ModelToZod.Generate(model));
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);
23
+ }
24
+ const model = Codegen.TypeScriptToModel.Generate(types);
25
+ await fs.writeFile(zodFile, Codegen.ModelToZod.Generate(model));
26
26
 
27
- await new Promise((resolve, reject) => {
28
- exec(`pnpm prettier --write "${dir}/{typebox,zod}/*.ts"`, (error, stdout, stderr) => {
29
- if (error) {
30
- console.error(`exec error: ${error}`);
31
- reject(error);
32
- return;
33
- }
34
- resolve({ stderr, stdout });
35
- stdout && console.log(`prettier:stdout: ${stdout}`);
36
- stderr && console.error(`prettier:stderr: ${stderr}`);
37
- });
38
- });
27
+ await new Promise((resolve, reject) => {
28
+ exec(`pnpm prettier --write "${dir}/{typebox,zod}/*.ts"`, (error, stdout, stderr) => {
29
+ if (error) {
30
+ console.error(`exec error: ${error}`);
31
+ reject(error);
32
+ return;
33
+ }
34
+ resolve({ stderr, stdout });
35
+ stdout && console.log(`prettier:stdout: ${stdout}`);
36
+ stderr && console.error(`prettier:stderr: ${stderr}`);
37
+ });
38
+ });
39
39
  }
@@ -1 +0,0 @@
1
- {"version":3,"sources":["../../src/cn/DivisionCode.ts"],"sourcesContent":["const DivisionCodeLevels: Array<{ level: number; code: string; length: number; size: number; label: string }> = [\n\t{ level: 1, code: 'Province', length: 2, size: 2, label: '省' },\n\t{ level: 2, code: 'City', length: 4, size: 2, label: '市' },\n\t{ level: 3, code: 'County', length: 6, size: 2, label: '区县' },\n\t{ level: 4, code: 'Town', length: 9, size: 3, label: '乡镇' },\n\t{ level: 5, code: 'Village', length: 12, size: 3, label: '村' },\n] as const;\n\n// String(Number.MAX_SAFE_INTEGER).length=16\n// 12 is safe int\n\n/**\n * Codes for the administrative divisions of the People's Republic of China\n *\n * @see https://zh.wikipedia.org/wiki/GB/T_2260 中华人民共和国行政区划代码\n */\nexport namespace DivisionCode {\n\tenum DivisionCodeLevel {\n\t\tProvince = 1,\n\t\tCity = 2,\n\t\tCounty = 3,\n\t\tTown = 4,\n\t\tVillage = 5,\n\t}\n\n\texport const levels = DivisionCodeLevels;\n\n\texport const regex = /^(?<province>\\d{2})(?<city>\\d{2})?(?<county>\\d{2})?(?<town>\\d{3})?(?<village>\\d{3})?$/;\n\n\tconst root: CodeValue[] = [\n\t\t{ value: '11', label: '北京市' },\n\t\t{ value: '12', label: '天津市' },\n\t\t{ value: '13', label: '河北省' },\n\t\t{ value: '14', label: '山西省' },\n\t\t{ value: '15', label: '内蒙古自治区' },\n\t\t{ value: '21', label: '辽宁省' },\n\t\t{ value: '22', label: '吉林省' },\n\t\t{ value: '23', label: '黑龙江省' },\n\t\t{ value: '31', label: '上海市' },\n\t\t{ value: '32', label: '江苏省' },\n\t\t{ value: '33', label: '浙江省' },\n\t\t{ value: '34', label: '安徽省' },\n\t\t{ value: '35', label: '福建省' },\n\t\t{ value: '36', label: '江西省' },\n\t\t{ value: '37', label: '山东省' },\n\t\t{ value: '41', label: '河南省' },\n\t\t{ value: '42', label: '湖北省' },\n\t\t{ value: '43', label: '湖南省' },\n\t\t{ value: '44', label: '广东省' },\n\t\t{ value: '45', label: '广西壮族自治区' },\n\t\t{ value: '46', label: '海南省' },\n\t\t{ value: '50', label: '重庆市' },\n\t\t{ value: '51', label: '四川省' },\n\t\t{ value: '52', label: '贵州省' },\n\t\t{ value: '53', label: '云南省' },\n\t\t{ value: '54', label: '西藏自治区' },\n\t\t{ value: '61', label: '陕西省' },\n\t\t{ value: '62', label: '甘肃省' },\n\t\t{ value: '63', label: '青海省' },\n\t\t{ value: '64', label: '宁夏回族自治区' },\n\t\t{ value: '65', label: '新疆维吾尔自治区' },\n\t\t{ value: '71', label: '台湾省' },\n\t\t{ value: '81', label: '香港特别行政区' },\n\t\t{ value: '82', label: '澳门特别行政区' },\n\t\t// 9 国外\n\t];\n\n\texport type ParsedCode = {\n\t\tprovince: string;\n\t\tcity?: string;\n\t\tcounty?: string;\n\t\ttown?: string;\n\t\tvillage?: string;\n\t\tcodes: string[];\n\t\tlevel: DivisionCodeLevel;\n\t\tlabels: string[];\n\t};\n\n\texport function parse(code: string | undefined | null | number): ParsedCode | undefined {\n\t\tif (!code) return;\n\t\tcode = String(code);\n\t\tconst match = regex.exec(code);\n\t\tif (!match) return;\n\t\tconst { province, city, county, town, village } = match.groups ?? {};\n\t\tif (!province) return;\n\n\t\tlet codes = [province, city, county, town, village].filter(Boolean);\n\t\treturn { province, city, county, town, village, codes: codes, level: codes.length as DivisionCodeLevel };\n\t}\n\n\texport function format({\n\t\tprovince,\n\t\tcity,\n\t\tcounty,\n\t\ttown,\n\t\tvillage,\n\t}: {\n\t\tprovince: string | number;\n\t\tcity?: string | number;\n\t\tcounty?: string | number;\n\t\ttown?: string | number;\n\t\tvillage?: string | number;\n\t}): string {\n\t\tconst codes: string[] = [];\n\t\tfor (let i = 0; i < [province, city, county, town, village].length; i++) {\n\t\t\tlet x = [province, city, county, town, village][i];\n\t\t\tif (x === undefined || x === null || x === '') {\n\t\t\t\tbreak;\n\t\t\t}\n\t\t\tlet len = levels[i].size;\n\t\t\tcodes.push(String(x).padStart(len, '0').slice(0, len));\n\t\t}\n\t\treturn codes.join('');\n\t}\n\n\t// export function random(level: DivisionCodeLevel = 'County'): string {\n\t// const l = DivisionCodeLevels.find((v) => v.code === level) || DivisionCodeLevels[2];\n\t// const l1 = randomPick(provinces);\n\t// if (l.level === 1) {\n\t// return String(l1[0]);\n\t// }\n\t// return l1 + String(Math.floor(Math.random() * parseFloat(`1e${l.length - 2}`) - 1));\n\t// }\n}\n\ninterface DivisionTreeNode {\n\tsub: string; // sub code\n\tchildren?: Record<string, DivisionTreeNode>;\n\n\tcode: string; // full code\n\tname?: string; // name of division\n}\n\n// export type DivisionCodeLevel = 'Village' | 'Town' | 'County' | 'City' | 'Province';\n\n// export interface ParsedDivisionCode {\n// level: DivisionCodeLevel;\n// code: string;\n// name?: string;\n// fullName?: string;\n// names: string[];\n// // 村级(村委会、居委会)\n// // 12 位\n// village?: CodeName;\n// // 乡级(乡镇、街道)\n// // 9 位\n// town?: CodeName;\n// // 县级(区县)\n// // 6 位 - 常用 - 2985 个\n// county?: CodeName;\n// // 地级(城市)\n// // 4 位 - 343 个\n// city?: CodeName;\n// // 省级(省份、直辖市、自治区)\n// // 2 位 - 32 个\n// province: CodeName;\n//\n// children?: Array<{ code: string; name?: string }>;\n// }\n\n// export interface CodeName {\n// code: string;\n// name: string;\n// }\n\n// export function getSimpleProvinceLabel(value: string) {\n// if (!value) {\n// return;\n// }\n// let label = value;\n// if (/[0-9]/.test(label)) {\n// label = label.slice(0, 2);\n// label = options.find((v) => v.value === label)?.label || label;\n// }\n// return label.replace(/省|市|(回族|维吾尔|壮族)?自治区|特别行政区$/, '');\n// }\n\nexport function randomPick<T>(s: T[]) {\n\treturn s[Math.floor(Math.random() * s.length)];\n}\n\nfunction lookup(opts: { values: string[]; root: CodeValue[] }): { found: CodeValue[] } {\n\tconst { values, root } = opts;\n\tconst found: CodeValue[] = [];\n\tlet currentLevel = root;\n\n\tfor (const v of values) {\n\t\tconst node = currentLevel.find((n) => n.value === v);\n\t\tif (!node) {\n\t\t\tbreak;\n\t\t}\n\n\t\tfound.push(node);\n\n\t\tif (node.children) {\n\t\t\tcurrentLevel = node.children;\n\t\t} else {\n\t\t\tbreak;\n\t\t}\n\t}\n\n\treturn { found };\n}\n\ninterface CodeValue {\n\tvalue: string;\n\tlabel: string;\n\tchildren?: Array<CodeValue>;\n}\n"],"names":["DivisionCodeLevels","level","code","length","size","label","DivisionCode","DivisionCodeLevel","levels","regex","root","value","parse","String","match","exec","province","city","county","town","village","groups","codes","filter","Boolean","format","i","x","undefined","len","push","padStart","slice","join","randomPick","s","Math","floor","random","lookup","opts","values","found","currentLevel","v","node","find","n","children"],"mappings":"AAAA,MAAMA,qBAA0G;IAC/G;QAAEC,OAAO;QAAGC,MAAM;QAAYC,QAAQ;QAAGC,MAAM;QAAGC,OAAO;IAAI;IAC7D;QAAEJ,OAAO;QAAGC,MAAM;QAAQC,QAAQ;QAAGC,MAAM;QAAGC,OAAO;IAAI;IACzD;QAAEJ,OAAO;QAAGC,MAAM;QAAUC,QAAQ;QAAGC,MAAM;QAAGC,OAAO;IAAK;IAC5D;QAAEJ,OAAO;QAAGC,MAAM;QAAQC,QAAQ;QAAGC,MAAM;QAAGC,OAAO;IAAK;IAC1D;QAAEJ,OAAO;QAAGC,MAAM;QAAWC,QAAQ;QAAIC,MAAM;QAAGC,OAAO;IAAI;CAC7D;UAUgBC;IAChB,IAAA,AAAKC,2CAAAA;;;;;;eAAAA;;iBAQQC,SAASR;iBAET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-1 +0,0 @@
1
- {"version":3,"sources":["../../src/cn/Mod11Checksum.ts"],"sourcesContent":["/**\n * ISO 7064:1983, MOD 11-2.\n */\nexport class Mod11Checksum {\n\tweights = [7, 9, 10, 5, 8, 4, 2, 1, 6, 3, 7, 9, 10, 5, 8, 4, 2, 1];\n\n\tvalidate(s: string) {\n\t\treturn s.at(-1) === this.compute(s.slice(0, s.length - 1));\n\t}\n\n\tcompute(s: string) {\n\t\tconst { weights } = this;\n\t\tlet sum = 0;\n\t\tfor (let i = 0; i < s.length; i++) {\n\t\t\tsum += parseInt(s[i]) * weights[i];\n\t\t}\n\t\tconst num = (12 - (sum % 11)) % 11;\n\t\tif (num < 10) {\n\t\t\treturn num.toString();\n\t\t} else {\n\t\t\treturn 'X';\n\t\t}\n\t}\n}\n"],"names":["Mod11Checksum","weights","validate","s","at","compute","slice","length","sum","i","parseInt","num","toString"],"mappings":"AAAA;;CAEC,GACD,OAAO,MAAMA;IACZC,UAAU;QAAC;QAAG;QAAG;QAAI;QAAG;QAAG;QAAG;QAAG;QAAG;QAAG;QAAG;QAAG;QAAG;QAAI;QAAG;QAAG;QAAG;QAAG;KAAE,CAAC;IAEnEC,SAASC,CAAS,EAAE;QACnB,OAAOA,EAAEC,EAAE,CAAC,CAAC,OAAO,IAAI,CAACC,OAAO,CAACF,EAAEG,KAAK,CAAC,GAAGH,EAAEI,MAAM,GAAG;IACxD;IAEAF,QAAQF,CAAS,EAAE;QAClB,MAAM,EAAEF,OAAO,EAAE,GAAG,IAAI;QACxB,IAAIO,MAAM;QACV,IAAK,IAAIC,IAAI,GAAGA,IAAIN,EAAEI,MAAM,EAAEE,IAAK;YAClCD,OAAOE,SAASP,CAAC,CAACM,EAAE,IAAIR,OAAO,CAACQ,EAAE;QACnC;QACA,MAAME,MAAM,AAAC,CAAA,KAAMH,MAAM,EAAE,IAAK;QAChC,IAAIG,MAAM,IAAI;YACb,OAAOA,IAAIC,QAAQ;QACpB,OAAO;YACN,OAAO;QACR;IACD;AACD"}
@@ -1 +0,0 @@
1
- {"version":3,"sources":["../../src/cn/Mod31Checksum.ts"],"sourcesContent":["/**\n * GB/T 17710(采ISO 7064)的模31校验码\n *\n * Mod31-3\n */\nexport class Mod31Checksum {\n\tweights = [1, 3, 9, 27, 19, 26, 16, 17, 20, 29, 25, 13, 8, 24, 10, 30, 28];\n\tchars = '0123456789ABCDEFGHJKLMNPQRTUWXY';\n\tnumbers: Record<string, number> = this.chars.split('').reduce(\n\t\t(acc, cur, i) => {\n\t\t\tacc[cur] = i;\n\t\t\treturn acc;\n\t\t},\n\t\t{} as Record<string, number>,\n\t);\n\n\ttoChar(n: number) {\n\t\treturn this.chars[n];\n\t}\n\n\ttoNumber(c: string) {\n\t\treturn this.numbers[c];\n\t}\n\n\tvalidate(s: string) {\n\t\treturn s.at(-1) === this.compute(s.slice(0, s.length - 1));\n\t}\n\n\tcompute(s: string) {\n\t\tlet sum = 0;\n\t\tfor (let i = 0; i < s.length; i++) {\n\t\t\tsum += this.numbers[s[i]] * this.weights[i];\n\t\t}\n\t\treturn this.toChar(31 - (sum % 31));\n\t}\n}\n"],"names":["Mod31Checksum","weights","chars","numbers","split","reduce","acc","cur","i","toChar","n","toNumber","c","validate","s","at","compute","slice","length","sum"],"mappings":"AAAA;;;;CAIC,GACD,OAAO,MAAMA;IACZC,UAAU;QAAC;QAAG;QAAG;QAAG;QAAI;QAAI;QAAI;QAAI;QAAI;QAAI;QAAI;QAAI;QAAI;QAAG;QAAI;QAAI;QAAI;KAAG,CAAC;IAC3EC,QAAQ,kCAAkC;IAC1CC,UAAkC,IAAI,CAACD,KAAK,CAACE,KAAK,CAAC,IAAIC,MAAM,CAC5D,CAACC,KAAKC,KAAKC;QACVF,GAAG,CAACC,IAAI,GAAGC;QACX,OAAOF;IACR,GACA,CAAC,GACA;IAEFG,OAAOC,CAAS,EAAE;QACjB,OAAO,IAAI,CAACR,KAAK,CAACQ,EAAE;IACrB;IAEAC,SAASC,CAAS,EAAE;QACnB,OAAO,IAAI,CAACT,OAAO,CAACS,EAAE;IACvB;IAEAC,SAASC,CAAS,EAAE;QACnB,OAAOA,EAAEC,EAAE,CAAC,CAAC,OAAO,IAAI,CAACC,OAAO,CAACF,EAAEG,KAAK,CAAC,GAAGH,EAAEI,MAAM,GAAG;IACxD;IAEAF,QAAQF,CAAS,EAAE;QAClB,IAAIK,MAAM;QACV,IAAK,IAAIX,IAAI,GAAGA,IAAIM,EAAEI,MAAM,EAAEV,IAAK;YAClCW,OAAO,IAAI,CAAChB,OAAO,CAACW,CAAC,CAACN,EAAE,CAAC,GAAG,IAAI,CAACP,OAAO,CAACO,EAAE;QAC5C;QACA,OAAO,IAAI,CAACC,MAAM,CAAC,KAAMU,MAAM;IAChC;AACD"}
@@ -1 +0,0 @@
1
- {"version":3,"sources":["../../src/cn/ResidentIdentityCardNumber.ts"],"sourcesContent":["import { formatDate } from './formatDate';\nimport { Mod11Checksum } from './Mod11Checksum';\n\nexport namespace ResidentIdentityCardNumber {\n\texport const Checksum = new Mod11Checksum();\n\n\t/*\n export const length = 18;\n export const pattern = /^\\d{6}(18|19|20)\\d{2}(0[1-9]|1[0-2])(0[1-9]|[12]\\d|3[01])\\d{3}[0-9Xx]$/;\n */\n\n\texport function parse(s: string): ParsedResidentIdentityCardNumber {\n\t\tconst division = s.slice(0, 6);\n\t\tconst birthDate = s.slice(6, 14);\n\t\tconst sequence = parseInt(s.slice(14, 17), 10);\n\t\tconst checksum = s.slice(17, 18);\n\t\tconst valid = Checksum.validate(s);\n\t\tconst sex = sequence % 2 === 1 ? 'Male' : 'Female';\n\t\treturn {\n\t\t\tdivision,\n\t\t\tbirthDate,\n\t\t\tsequence,\n\t\t\tchecksum,\n\t\t\tvalid,\n\t\t\tsex,\n\t\t\tmale: sex === 'Male',\n\t\t\tfemale: sex === 'Female',\n\t\t\tage: new Date().getFullYear() - parseInt(birthDate.slice(0, 4), 10),\n\t\t};\n\t}\n\n\texport function format({\n\t\tdivision,\n\t\tbirthDate,\n\t\tsequence,\n\t\tchecksum,\n\t}: {\n\t\tdivision: string;\n\t\tbirthDate: string | Date;\n\t\tsequence: number | string;\n\t\tchecksum?: string;\n\t}) {\n\t\tif (typeof birthDate !== 'string') {\n\t\t\tbirthDate = formatDate(birthDate, 'yyyyMMDD');\n\t\t}\n\t\tif (birthDate.includes('-')) {\n\t\t\tbirthDate = birthDate.replace(/-/g, '');\n\t\t}\n\t\ttypeof sequence === 'number' && (sequence = sequence.toString());\n\t\tsequence = sequence.padStart(3, '0');\n\t\tconst base = [division, birthDate, sequence].join('');\n\t\tif (base.length !== 17) throw new Error('Invalid params');\n\t\tchecksum ||= Checksum.compute(base);\n\t\treturn base + checksum;\n\t}\n}\nexport interface ParsedResidentIdentityCardNumber {\n\t/**\n\t * @title 行政区划代码\n\t */\n\tdivision: string;\n\t/**\n\t * @title 出生日期\n\t * 格式 yyyyMMDD\n\t */\n\tbirthDate: string;\n\t/**\n\t * @title 顺序码\n\t */\n\tsequence: number;\n\t/**\n\t * @title 校验位\n\t */\n\tchecksum: string;\n\n\t/**\n\t * @title 是否有效\n\t */\n\tvalid: boolean;\n\t/**\n\t * @title 是否男性\n\t */\n\tmale: boolean;\n\t/**\n\t * @title 是否女性\n\t */\n\tfemale: boolean;\n\t/**\n\t * @title 性别\n\t */\n\tsex: 'Male' | 'Female';\n\t/**\n\t * @title 年龄\n\t */\n\tage: number;\n}\n"],"names":["formatDate","Mod11Checksum","ResidentIdentityCardNumber","Checksum","parse","s","division","slice","birthDate","sequence","parseInt","checksum","valid","validate","sex","male","female","age","Date","getFullYear","format","includes","replace","toString","padStart","base","join","length","Error","compute"],"mappings":"AAAA,SAASA,UAAU,QAAQ,eAAe;AAC1C,SAASC,aAAa,QAAQ,kBAAkB;UAE/BC;+BACHC,WAAW,IAAIF;IAOrB,SAASG,MAAMC,CAAS;QAC9B,MAAMC,WAAWD,EAAEE,KAAK,CAAC,GAAG;QAC5B,MAAMC,YAAYH,EAAEE,KAAK,CAAC,GAAG;QAC7B,MAAME,WAAWC,SAASL,EAAEE,KAAK,CAAC,IAAI,KAAK;QAC3C,MAAMI,WAAWN,EAAEE,KAAK,CAAC,IAAI;QAC7B,MAAMK,QAAQT,2BAAAA,SAASU,QAAQ,CAACR;QAChC,MAAMS,MAAML,WAAW,MAAM,IAAI,SAAS;QAC1C,OAAO;YACNH;YACAE;YACAC;YACAE;YACAC;YACAE;YACAC,MAAMD,QAAQ;YACdE,QAAQF,QAAQ;YAChBG,KAAK,IAAIC,OAAOC,WAAW,KAAKT,SAASF,UAAUD,KAAK,CAAC,GAAG,IAAI;QACjE;IACD;IAvBA;;;GAGE,8BAEcH,QAAAA;IAoBT,SAASgB,OAAO,EACtBd,QAAQ,EACRE,SAAS,EACTC,QAAQ,EACRE,QAAQ,EAMR;QACA,IAAI,OAAOH,cAAc,UAAU;YAClCA,YAAYR,WAAWQ,WAAW;QACnC;QACA,IAAIA,UAAUa,QAAQ,CAAC,MAAM;YAC5Bb,YAAYA,UAAUc,OAAO,CAAC,MAAM;QACrC;QACA,OAAOb,aAAa,YAAaA,CAAAA,WAAWA,SAASc,QAAQ,EAAC;QAC9Dd,WAAWA,SAASe,QAAQ,CAAC,GAAG;QAChC,MAAMC,OAAO;YAACnB;YAAUE;YAAWC;SAAS,CAACiB,IAAI,CAAC;QAClD,IAAID,KAAKE,MAAM,KAAK,IAAI,MAAM,IAAIC,MAAM;QACxCjB,aAAaR,2BAAAA,SAAS0B,OAAO,CAACJ;QAC9B,OAAOA,OAAOd;IACf;+BAvBgBS,SAAAA;AAwBjB,GApDiBlB,+BAAAA"}
@@ -1 +0,0 @@
1
- {"version":3,"sources":["../../src/cn/UnifiedSocialCreditCode.ts"],"sourcesContent":["import { Mod31Checksum } from './Mod31Checksum';\n\n/**\n * 统一社会信用代码\n *\n * - GB 11714-1997 全国组织机构代码编制规则\n */\nexport namespace UnifiedSocialCreditCode {\n\tinterface CodeValue {\n\t\tlabel: string;\n\t\tchildren?: Record<string, CodeValue>;\n\t}\n\n\tconst CodeLabels: Record<string, CodeValue> = {\n\t\t1: {\n\t\t\tlabel: '机构编制',\n\t\t\tchildren: {\n\t\t\t\t1: { label: '机关' },\n\t\t\t\t2: { label: '事业单位' },\n\t\t\t\t3: { label: '中央编办直接管理机构编制的群众团体' },\n\t\t\t\t9: { label: '其他' },\n\t\t\t},\n\t\t},\n\t\t5: {\n\t\t\tlabel: '民政',\n\t\t\tchildren: {\n\t\t\t\t1: { label: '社会团体' },\n\t\t\t\t2: { label: '民办非企业单位' },\n\t\t\t\t3: { label: '基金会' },\n\t\t\t\t9: { label: '其他' },\n\t\t\t},\n\t\t},\n\t\t9: {\n\t\t\tlabel: '工商',\n\t\t\tchildren: {\n\t\t\t\t1: { label: '企业' },\n\t\t\t\t2: { label: '个体工商户' },\n\t\t\t\t3: { label: '农民专业合作社' },\n\t\t\t\t9: { label: '其他' },\n\t\t\t},\n\t\t},\n\t\tY: { label: '其他', children: { 1: { label: '其他' } } },\n\t};\n\n\texport const pattern = /^([159][1239]|Y1)[0-9]{6}[0-9A-HJ-NP-RTUWXY]{10}$/; // 无 I O Z S V\n\n\texport const Checksum = new Mod31Checksum();\n\n\texport function parse(s: string): ParsedUnifiedSocialCreditCode {\n\t\tlet bureau = s[0];\n\t\tlet subjectType = s[1];\n\t\tlet division = s.slice(2, 8); // 第3~8位,共6位,正确\n\t\tlet subject = s.slice(8, 17); // 第9~17位,共9位\n\t\tlet checksum = s.slice(17, 18); // 第18位,校验码\n\n\t\tconst labels: string[] = [];\n\t\tlet l1 = CodeLabels[bureau];\n\t\tl1 && labels.push(l1?.label);\n\t\tlet l2 = l1?.children?.[subjectType];\n\t\tl2 && labels.push(l2?.label);\n\n\t\treturn {\n\t\t\tbureau,\n\t\t\tsubjectType,\n\t\t\tdivision,\n\t\t\tsubject,\n\t\t\tchecksum,\n\t\t\tcodes: [bureau, subjectType, division, subject],\n\t\t\tlabels,\n\t\t};\n\t}\n\n\texport function format({\n\t\tbureau,\n\t\tsubjectType,\n\t\tdivision,\n\t\tsubject,\n\t\tchecksum,\n\t}: {\n\t\tbureau: string;\n\t\tsubjectType: string;\n\t\tdivision: string;\n\t\tsubject: string;\n\t\tchecksum?: string;\n\t}): string {\n\t\tconst base = `${bureau}${subjectType}${division}${subject}`;\n\t\tchecksum ||= Checksum.compute(base);\n\t\treturn `${base}${checksum}`;\n\t}\n\n\texport function next(s: string, delta: number = 1) {\n\t\tconst sp = s.split('').map((v) => Checksum.numbers[v]);\n\t\tfor (let i = sp.length - 1; i >= 0; i--) {\n\t\t\tif ((delta > 0 && sp[i] < 30) || (delta < 0 && sp[i] > 0)) {\n\t\t\t\tsp[i] += delta;\n\t\t\t\tbreak;\n\t\t\t} else if (delta > 0 && sp[i] === 30) {\n\t\t\t\tsp[i] = 0;\n\t\t\t} else if (delta < 0 && sp[i] === 0) {\n\t\t\t\tsp[i] = 30;\n\t\t\t}\n\t\t}\n\t\treturn sp.map((v) => Checksum.chars[v]).join('');\n\t}\n}\n\n/**\n * 解析后的统一社会信用代码信息\n */\ninterface ParsedUnifiedSocialCreditCode {\n\t/**\n\t * @title 登记管理部门代码\n\t * 对应统一社会信用代码的第1位字符,用于标识发证机构类别(登记管理部门)。\n\t */\n\tbureau: string;\n\n\t/**\n\t * @title 机构类别代码\n\t * 对应统一社会信用代码的第2位字符,用于标识被赋码主体的类型(如企业、事业单位、社会组织等)。\n\t */\n\tsubjectType: string;\n\n\t/**\n\t * @title 登记管理机关行政区划代码\n\t * 对应统一社会信用代码的第3至第8位字符,用于标识该主体登记机关所在的行政区划。\n\t */\n\tdivision: string;\n\n\t/**\n\t * @title 主体标识码\n\t * 对应统一社会信用代码的第9至第17位字符,用于标识特定的市场主体或法人单位。\n\t */\n\tsubject: string;\n\n\t/**\n\t * @title 校验码\n\t * 对应统一社会信用代码的最后一位字符,用特定算法计算,用于校验代码有效性。\n\t */\n\tchecksum: string;\n\n\tcodes: string[];\n\tlabels: string[];\n}\n"],"names":["Mod31Checksum","UnifiedSocialCreditCode","CodeLabels","label","children","Y","pattern","Checksum","parse","s","bureau","subjectType","division","slice","subject","checksum","labels","l1","push","l2","codes","format","base","compute","next","delta","sp","split","map","v","numbers","i","length","chars","join"],"mappings":"AAAA,SAASA,aAAa,QAAQ,kBAAkB;UAO/BC;IAMhB,MAAMC,aAAwC;QAC7C,GAAG;YACFC,OAAO;YACPC,UAAU;gBACT,GAAG;oBAAED,OAAO;gBAAK;gBACjB,GAAG;oBAAEA,OAAO;gBAAO;gBACnB,GAAG;oBAAEA,OAAO;gBAAoB;gBAChC,GAAG;oBAAEA,OAAO;gBAAK;YAClB;QACD;QACA,GAAG;YACFA,OAAO;YACPC,UAAU;gBACT,GAAG;oBAAED,OAAO;gBAAO;gBACnB,GAAG;oBAAEA,OAAO;gBAAU;gBACtB,GAAG;oBAAEA,OAAO;gBAAM;gBAClB,GAAG;oBAAEA,OAAO;gBAAK;YAClB;QACD;QACA,GAAG;YACFA,OAAO;YACPC,UAAU;gBACT,GAAG;oBAAED,OAAO;gBAAK;gBACjB,GAAG;oBAAEA,OAAO;gBAAQ;gBACpB,GAAG;oBAAEA,OAAO;gBAAU;gBACtB,GAAG;oBAAEA,OAAO;gBAAK;YAClB;QACD;QACAE,GAAG;YAAEF,OAAO;YAAMC,UAAU;gBAAE,GAAG;oBAAED,OAAO;gBAAK;YAAE;QAAE;IACpD;4BAEaG,UAAU,qDAAqD,cAAc;4BAE7EC,WAAW,IAAIP;IAErB,SAASQ,MAAMC,CAAS;QAC9B,IAAIC,SAASD,CAAC,CAAC,EAAE;QACjB,IAAIE,cAAcF,CAAC,CAAC,EAAE;QACtB,IAAIG,WAAWH,EAAEI,KAAK,CAAC,GAAG,IAAI,eAAe;QAC7C,IAAIC,UAAUL,EAAEI,KAAK,CAAC,GAAG,KAAK,aAAa;QAC3C,IAAIE,WAAWN,EAAEI,KAAK,CAAC,IAAI,KAAK,WAAW;QAE3C,MAAMG,SAAmB,EAAE;QAC3B,IAAIC,KAAKf,UAAU,CAACQ,OAAO;QAC3BO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@@ -1 +0,0 @@
1
- {"version":3,"sources":["../../src/cn/formatDate.ts"],"sourcesContent":["export function formatDate(date: Date, format: 'yyyyMMDD') {\n\tswitch (format) {\n\t\tcase 'yyyyMMDD': {\n\t\t\tconst year = date.getFullYear();\n\t\t\tconst month = (date.getMonth() + 1).toString().padStart(2, '0');\n\t\t\tconst day = date.getDate().toString().padStart(2, '0');\n\t\t\treturn `${year}${month}${day}`;\n\t\t}\n\t\tdefault:\n\t\t\tthrow new Error(`Invalid format`);\n\t}\n}\n"],"names":["formatDate","date","format","year","getFullYear","month","getMonth","toString","padStart","day","getDate","Error"],"mappings":"AAAA,OAAO,SAASA,WAAWC,IAAU,EAAEC,MAAkB;IACxD,OAAQA;QACP,KAAK;YAAY;gBAChB,MAAMC,OAAOF,KAAKG,WAAW;gBAC7B,MAAMC,QAAQ,AAACJ,CAAAA,KAAKK,QAAQ,KAAK,CAAA,EAAGC,QAAQ,GAAGC,QAAQ,CAAC,GAAG;gBAC3D,MAAMC,MAAMR,KAAKS,OAAO,GAAGH,QAAQ,GAAGC,QAAQ,CAAC,GAAG;gBAClD,OAAO,GAAGL,OAAOE,QAAQI,KAAK;YAC/B;QACA;YACC,MAAM,IAAIE,MAAM,CAAC,cAAc,CAAC;IAClC;AACD"}
@@ -1 +0,0 @@
1
- {"version":3,"sources":["../../src/cn/index.ts"],"sourcesContent":["export { ResidentIdentityCardNumber } from './ResidentIdentityCardNumber';\nexport { DivisionCode } from './DivisionCode';\nexport { UnifiedSocialCreditCode } from './UnifiedSocialCreditCode';\n"],"names":["ResidentIdentityCardNumber","DivisionCode","UnifiedSocialCreditCode"],"mappings":"AAAA,SAASA,0BAA0B,QAAQ,+BAA+B;AAC1E,SAASC,YAAY,QAAQ,iBAAiB;AAC9C,SAASC,uBAAuB,QAAQ,4BAA4B"}
@@ -1 +0,0 @@
1
- {"version":3,"sources":["../../src/cn/parseSex.ts"],"sourcesContent":["export function parseSex(s: string): undefined | { sex: 'Male' | 'Female'; male: boolean; female: boolean } {\n\tif (!s) return undefined;\n\n\tswitch (s.toLowerCase()) {\n\t\tcase '男':\n\t\tcase 'male':\n\t\t\treturn { sex: 'Male', male: true, female: false };\n\t\tcase '女':\n\t\tcase 'female':\n\t\t\treturn { sex: 'Female', male: false, female: true };\n\t}\n\treturn undefined;\n}\n"],"names":["parseSex","s","undefined","toLowerCase","sex","male","female"],"mappings":"AAAA,OAAO,SAASA,SAASC,CAAS;IACjC,IAAI,CAACA,GAAG,OAAOC;IAEf,OAAQD,EAAEE,WAAW;QACpB,KAAK;QACL,KAAK;YACJ,OAAO;gBAAEC,KAAK;gBAAQC,MAAM;gBAAMC,QAAQ;YAAM;QACjD,KAAK;QACL,KAAK;YACJ,OAAO;gBAAEF,KAAK;gBAAUC,MAAM;gBAAOC,QAAQ;YAAK;IACpD;IACA,OAAOJ;AACR"}
@@ -1 +0,0 @@
1
- {"version":3,"sources":["../../src/cn/types.d.ts"],"sourcesContent":["/**\n * 居民身份证\n *\n * @see https://en.wikipedia.org/wiki/Resident_Identity_Card\n * @see https://en.wikipedia.org/wiki/Foreign_Permanent_Resident_ID_Card\n */\nexport interface ResidentIdentityCardInfo {\n\t/**\n\t * @title 姓名\n\t */\n\tname: string;\n\t/**\n\t * @title 性别\n\t */\n\tsex: 'Male' | 'Female';\n\t/**\n\t * @title 民族\n\t * 例如 '汉'/'满'/'回'\n\t */\n\tethnicity: string;\n\t/**\n\t * @title 出生日期\n\t * @format date\n\t */\n\tbirthDate: string;\n\t/**\n\t * @title 地址\n\t *\n\t * - 通常为 domicile/户籍地\n\t */\n\taddress: string;\n\t/**\n\t * @title 身份证号\n\t */\n\tidentityCardNumber: string;\n\t/**\n\t * @title 签发机关\n\t */\n\tissuer: string;\n\t/**\n\t * @title 有效期开始日期\n\t * @format date\n\t */\n\tvalidStartDate: string;\n\t/**\n\t * @title 有效期结束日期\n\t * @format date\n\t * @description 如长期有效则为 空\n\t */\n\tvalidEndDate?: string;\n}\n"],"names":[],"mappings":"AAAA;;;;;CAKC,GACD,WA4CC"}
@@ -1 +0,0 @@
1
- {"version":3,"sources":["../../src/consola/createStandardConsolaReporter.ts"],"sourcesContent":["import type { ConsolaOptions, ConsolaReporter, LogObject } from 'consola/core';\nimport { formatLogObject } from './formatLogObject';\n\ntype Formatter = (\n\to: LogObject,\n\tctx: {\n\t\toptions: ConsolaOptions;\n\t},\n) => string;\n\nexport function createStandardConsolaReporter({\n\tformat = formatLogObject,\n}: {\n\tformat?: Formatter;\n} = {}): ConsolaReporter {\n\treturn {\n\t\tlog: (o, ctx) => {\n\t\t\tlet out = format(o, ctx);\n\t\t\tlet fn = console.log;\n\n\t\t\tconst { level } = o;\n\t\t\tif (level < 1) {\n\t\t\t\tfn = console.error;\n\t\t\t} else if (level === 1) {\n\t\t\t\tfn = console.warn;\n\t\t\t}\n\n\t\t\tfn(out);\n\t\t},\n\t};\n}\n"],"names":["formatLogObject","createStandardConsolaReporter","format","log","o","ctx","out","fn","console","level","error","warn"],"mappings":"AACA,SAASA,eAAe,QAAQ,oBAAoB;AASpD,OAAO,SAASC,8BAA8B,EAC7CC,SAASF,eAAe,EAGxB,GAAG,CAAC,CAAC;IACL,OAAO;QACNG,KAAK,CAACC,GAAGC;YACR,IAAIC,MAAMJ,OAAOE,GAAGC;YACpB,IAAIE,KAAKC,QAAQL,GAAG;YAEpB,MAAM,EAAEM,KAAK,EAAE,GAAGL;YAClB,IAAIK,QAAQ,GAAG;gBACdF,KAAKC,QAAQE,KAAK;YACnB,OAAO,IAAID,UAAU,GAAG;gBACvBF,KAAKC,QAAQG,IAAI;YAClB;YAEAJ,GAAGD;QACJ;IACD;AACD"}
@@ -1 +0,0 @@
1
- {"version":3,"sources":["../../src/consola/formatLogObject.ts"],"sourcesContent":["import colors from 'chalk';\nimport type { ConsolaOptions, FormatOptions, LogObject, LogType } from 'consola/core';\nimport dayjs from 'dayjs';\nimport { isDevelopment } from 'std-env';\n\nconst levelColors: Record<LogType, (str: string) => string> = {\n\ttrace: colors.gray,\n\tdebug: colors.cyan,\n\tinfo: colors.blueBright,\n\twarn: colors.yellow,\n\terror: colors.red,\n\tfatal: colors.bgRed.white,\n\tsilent: colors.white,\n\tlog: colors.white,\n\tsuccess: colors.green,\n\tfail: colors.red,\n\tready: colors.green,\n\tstart: colors.cyan,\n\tbox: colors.white,\n\tverbose: colors.green,\n};\n\nconst levelShort: Record<LogType, string> = {\n\ttrace: 'TRAC',\n\tdebug: 'DEBG',\n\tinfo: 'INFO',\n\twarn: 'WARN',\n\terror: 'ERRO',\n\tfatal: 'FATL',\n\tsilent: 'SLNT',\n\tlog: 'LOG ', // Added space to make it 4 characters\n\tsuccess: 'SUCC',\n\tfail: 'FAIL',\n\tready: 'READ',\n\tstart: 'STRT',\n\tbox: 'BOX ', // Added space to make it 4 characters\n\tverbose: 'VERB',\n};\nconst start = Date.now();\n\nexport function formatLogObject(\n\to: LogObject,\n\tctx: {\n\t\toptions: ConsolaOptions;\n\t},\n) {\n\tlet { date, type, tag } = o;\n\ttype = type === 'log' ? 'info' : type;\n\n\tconst color = levelColors[type] || colors.white;\n\tconst levelText = levelShort[type] || type.toUpperCase().slice(0, 4); // Get first 4 chars, consistent uppercase\n\n\tlet line = '';\n\tlet out: string[] = [];\n\n\t// Timestamp\n\tif (isDevelopment) {\n\t\t// process.hrtime.bigint()\n\t\tlet diff = (date.getTime() - start) / 1000;\n\n\t\tout.push(colors.gray(diff.toFixed(3).padStart(7, ' ')));\n\t} else {\n\t\tout.push(colors.gray(dayjs(date).format('YYYY-MM-DD HH:mm:ss.SSS')));\n\t}\n\n\t// Log Level (colored)\n\t// Pad to 4 characters\n\tout.push(color(levelText.padEnd(4, ' ')));\n\n\tif (tag) {\n\t\tout.push(colors.yellow(`[${tag}]`)); // Added color for tag\n\t}\n\n\t{\n\t\tconst [message, ...additional] = formatArgs(o.args, ctx).split('\\n');\n\n\t\tout.push(characterFormat(message));\n\n\t\tline = out.join(' ');\n\t\tif (additional.length > 0) {\n\t\t\tline += characterFormat(additional.join('\\n'));\n\t\t}\n\n\t\tif (type === 'trace') {\n\t\t\tconst _err = new Error('Trace: ' + o.message);\n\t\t\tline += formatStack(_err.stack || '', _err.message);\n\t\t}\n\t}\n\n\t// if (!message && typeof args[0] === 'string') {\n\t// message = args.shift();\n\t// }\n\t// if (message) {\n\t// out.push(message);\n\t// }\n\t// if (args.length) {\n\t// out.push(...args.map((a) => (typeof a === 'string' ? a : JSON.stringify(a)))); // Handle non-string args\n\t// }\n\n\t// todo format error\n\t// https://github.com/unjs/consola/blob/main/src/reporters/fancy.ts\n\n\t// return out.join(' '); // Increased spacing for better readability\n\treturn line;\n}\n\nfunction characterFormat(str: string) {\n\treturn (\n\t\tstr\n\t\t\t// highlight backticks\n\t\t\t.replace(/`([^`]+)`/gm, (_, m) => colors.cyan(m))\n\t\t\t// underline underscores\n\t\t\t.replace(/\\s+_([^_]+)_\\s+/gm, (_, m) => ` ${colors.underline(m)} `)\n\t);\n}\n\nfunction parseStack(stack: string, message: string) {\n\t// const cwd = process.cwd() + sep;\n\n\tconst lines = stack\n\t\t.split('\\n')\n\t\t.splice(message.split('\\n').length)\n\t\t.map(\n\t\t\t(l) => l.trim().replace('file://', ''),\n\t\t\t// .replace(cwd, '')\n\t\t);\n\n\treturn lines;\n}\n\nfunction formatStack(stack: string, message: string, opts?: FormatOptions) {\n\tconst indent = ' '.repeat((opts?.errorLevel || 0) + 1);\n\treturn (\n\t\t`\\n${indent}`\n\t\t+ parseStack(stack, message)\n\t\t\t.map(\n\t\t\t\t(line) =>\n\t\t\t\t\t' ' + line.replace(/^at +/, (m) => colors.gray(m)).replace(/\\((.+)\\)/, (_, m) => `(${colors.cyan(m)})`),\n\t\t\t)\n\t\t\t.join(`\\n${indent}`)\n\t);\n}\n\nfunction formatArgs(args: any[], opts: FormatOptions) {\n\tconst _args = args.map((arg) => {\n\t\tif (arg && typeof arg.stack === 'string') {\n\t\t\treturn formatError(arg, opts);\n\t\t}\n\t\treturn arg;\n\t});\n\n\t// Only supported with Node >= 10\n\t// https://nodejs.org/api/util.html#util_util_inspect_object_options\n\treturn formatWithOptions(opts, ..._args);\n}\n\nfunction formatWithOptions(o: any, ...params: any[]) {\n\t// import { formatWithOptions } from 'node:util';\n\treturn params.join(' ');\n}\n\nfunction formatError(err: any, opts: FormatOptions): string {\n\tconst message = err.message ?? formatWithOptions(opts, err);\n\tconst stack = err.stack ? formatStack(err.stack, message, opts) : '';\n\n\tconst level = opts?.errorLevel || 0;\n\tconst causedPrefix = level > 0 ? `${' '.repeat(level)}[cause]: ` : '';\n\tconst causedError = err.cause ? '\\n\\n' + formatError(err.cause, { ...opts, errorLevel: level + 1 }) : '';\n\n\treturn causedPrefix + message + '\\n' + stack + causedError;\n}\n"],"names":["colors","dayjs","isDevelopment","levelColors","trace","gray","debug","cyan","info","blueBright","warn","yellow","error","red","fatal","bgRed","white","silent","log","success","green","fail","ready","start","box","verbose","levelShort","Date","now","formatLogObject","o","ctx","date","type","tag","color","levelText","toUpperCase","slice","line","out","diff","getTime","push","toFixed","padStart","format","padEnd","message","additional","formatArgs","args","split","characterFormat","join","length","_err","Error","formatStack","stack","str","replace","_","m","underline","parseStack","lines","splice","map","l","trim","opts","indent","repeat","errorLevel","_args","arg","formatError","formatWithOptions","params","err","level","causedPrefix","causedError","cause"],"mappings":"AAAA,OAAOA,YAAY,QAAQ;AAE3B,OAAOC,WAAW,QAAQ;AAC1B,SAASC,aAAa,QAAQ,UAAU;AAExC,MAAMC,cAAwD;IAC7DC,OAAOJ,OAAOK,IAAI;IAClBC,OAAON,OAAOO,IAAI;IAClBC,MAAMR,OAAOS,UAAU;IACvBC,MAAMV,OAAOW,MAAM;IACnBC,OAAOZ,OAAOa,GAAG;IACjBC,OAAOd,OAAOe,KAAK,CAACC,KAAK;IACzBC,QAAQjB,OAAOgB,KAAK;IACpBE,KAAKlB,OAAOgB,KAAK;IACjBG,SAASnB,OAAOoB,KAAK;IACrBC,MAAMrB,OAAOa,GAAG;IAChBS,OAAOtB,OAAOoB,K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,QAAQ,GACXP,WAAWN,OAAOX,SAClBoB,GAAG,CACH,CAAC7B,OACA,OAAOA,KAAKsB,OAAO,CAAC,SAAS,CAACE,IAAM/D,OAAOK,IAAI,CAAC0D,IAAIF,OAAO,CAAC,YAAY,CAACC,GAAGC,IAAM,CAAC,CAAC,EAAE/D,OAAOO,IAAI,CAACwD,GAAG,CAAC,CAAC,GAExGT,IAAI,CAAC,CAAC,EAAE,EAAEkB,QAAQ;AAEtB;AAEA,SAAStB,WAAWC,IAAW,EAAEoB,IAAmB;IACnD,MAAMI,QAAQxB,KAAKiB,GAAG,CAAC,CAACQ;QACvB,IAAIA,OAAO,OAAOA,IAAIjB,KAAK,KAAK,UAAU;YACzC,OAAOkB,YAAYD,KAAKL;QACzB;QACA,OAAOK;IACR;IAEA,iCAAiC;IACjC,oEAAoE;IACpE,OAAOE,kBAAkBP,SAASI;AACnC;AAEA,SAASG,kBAAkBhD,CAAM,EAAE,GAAGiD,MAAa;IAClD,iDAAiD;IACjD,OAAOA,OAAOzB,IAAI,CAAC;AACpB;AAEA,SAASuB,YAAYG,GAAQ,EAAET,IAAmB;IACjD,MAAMvB,UAAUgC,IAAIhC,OAAO,IAAI8B,kBAAkBP,MAAMS;IACvD,MAAMrB,QAAQqB,IAAIrB,KAAK,GAAGD,YAAYsB,IAAIrB,KAAK,EAAEX,SAASuB,QAAQ;IAElE,MAAMU,QAAQV,MAAMG,cAAc;IAClC,MAAMQ,eAAeD,QAAQ,IAAI,GAAG,KAAKR,MAAM,CAACQ,OAAO,SAAS,CAAC,GAAG;IACpE,MAAME,cAAcH,IAAII,KAAK,GAAG,SAASP,YAAYG,IAAII,KAAK,EAAE;QAAE,GAAGb,IAAI;QAAEG,YAAYO,QAAQ;IAAE,KAAK;IAEtG,OAAOC,eAAelC,UAAU,OAAOW,QAAQwB;AAChD"}
@@ -1 +0,0 @@
1
- {"version":3,"sources":["../../src/consola/index.ts"],"sourcesContent":["export { formatLogObject } from './formatLogObject';\nexport { createStandardConsolaReporter } from './createStandardConsolaReporter';\n"],"names":["formatLogObject","createStandardConsolaReporter"],"mappings":"AAAA,SAASA,eAAe,QAAQ,oBAAoB;AACpD,SAASC,6BAA6B,QAAQ,kCAAkC"}
@@ -1 +0,0 @@
1
- {"version":3,"sources":["../../src/data/formatSort.ts"],"sourcesContent":["import type { SortRule } from './parseSort';\n\nexport function formatSort(s: SortRule[]): string[] {\n\treturn s\n\t\t.map(({ field, order, nulls }) => {\n\t\t\tif (!field) return '';\n\n\t\t\tlet r = field;\n\t\t\tif (order) {\n\t\t\t\tr += ` ${order}`;\n\t\t\t}\n\t\t\tif (nulls) {\n\t\t\t\tr += ` nulls ${nulls}`;\n\t\t\t}\n\t\t\treturn r;\n\t\t})\n\t\t.filter(Boolean);\n}\n"],"names":["formatSort","s","map","field","order","nulls","r","filter","Boolean"],"mappings":"AAEA,OAAO,SAASA,WAAWC,CAAa;IACvC,OAAOA,EACLC,GAAG,CAAC,CAAC,EAAEC,KAAK,EAAEC,KAAK,EAAEC,KAAK,EAAE;QAC5B,IAAI,CAACF,OAAO,OAAO;QAEnB,IAAIG,IAAIH;QACR,IAAIC,OAAO;YACVE,KAAK,CAAC,CAAC,EAAEF,OAAO;QACjB;QACA,IAAIC,OAAO;YACVC,KAAK,CAAC,OAAO,EAAED,OAAO;QACvB;QACA,OAAOC;IACR,GACCC,MAAM,CAACC;AACV"}
@@ -1 +0,0 @@
1
- {"version":3,"sources":["../../src/data/index.ts"],"sourcesContent":["export type * from './types';\n\nexport { resolvePagination, type PaginationInput, type ResolvedPagination } from './resolvePagination';\nexport { parseSort, type SortRule } from './parseSort';\nexport { formatSort } from './formatSort';\n"],"names":["resolvePagination","parseSort","formatSort"],"mappings":"AAEA,SAASA,iBAAiB,QAAuD,sBAAsB;AACvG,SAASC,SAAS,QAAuB,cAAc;AACvD,SAASC,UAAU,QAAQ,eAAe"}
@@ -1 +0,0 @@
1
- {"version":3,"sources":["../../src/data/maybeNumber.ts"],"sourcesContent":["export type MaybeNumber = number | null | string | undefined | bigint;\n\nexport function maybeNumber(v: MaybeNumber) {\n\tif (v === null || v === undefined) {\n\t\treturn undefined;\n\t}\n\n\tswitch (typeof v) {\n\t\tcase 'number':\n\t\t\treturn v;\n\t\tcase 'bigint':\n\t\t\treturn Number(v);\n\t\tcase 'string':\n\t\t\tif (v === '') {\n\t\t\t\treturn undefined;\n\t\t\t}\n\t}\n\tconst n = Number(v);\n\tif (isNaN(n)) {\n\t\treturn undefined;\n\t}\n\treturn n;\n}\n"],"names":["maybeNumber","v","undefined","Number","n","isNaN"],"mappings":"AAEA,OAAO,SAASA,YAAYC,CAAc;IACzC,IAAIA,MAAM,QAAQA,MAAMC,WAAW;QAClC,OAAOA;IACR;IAEA,OAAQ,OAAOD;QACd,KAAK;YACJ,OAAOA;QACR,KAAK;YACJ,OAAOE,OAAOF;QACf,KAAK;YACJ,IAAIA,MAAM,IAAI;gBACb,OAAOC;YACR;IACF;IACA,MAAME,IAAID,OAAOF;IACjB,IAAII,MAAMD,IAAI;QACb,OAAOF;IACR;IACA,OAAOE;AACR"}
@@ -1 +0,0 @@
1
- {"version":3,"sources":["../../src/data/parseSort.ts"],"sourcesContent":["import { arrayOfMaybeArray, type MaybeArray } from '@wener/utils';\n\nexport type SortRule = { field: string; order: 'asc' | 'desc'; nulls?: 'last' | 'first' };\n\n/**\n * Parses various format of sort specifications into standardized SortRule objects\n *\n * Supported formats:\n * - \"field asc|desc\"\n * - \"field asc|desc nulls first|last\"\n * - \"+field\" for ascending, \"-field\" for descending\n * - Object notation: { field: string, order?: string, nulls?: string }\n *\n * @example\n * parseSort('name desc') // [{ field: 'name', order: 'desc' }]\n * parseSort('+name,-age') // [{ field: 'name', order: 'asc' }, { field: 'age', order: 'desc' }]\n * parseSort('name asc nulls last') // [{ field: 'name', order: 'asc', nulls: 'last' }]\n * parseSort([{ field: 'name' }]) // [{ field: 'name', order: 'asc' }]\n */\nexport function parseSort(\n\torder: MaybeArray<{ field?: string; order?: string; nulls?: string } | string> | undefined | null,\n): SortRule[] {\n\tif (!order) {\n\t\treturn [];\n\t}\n\n\treturn arrayOfMaybeArray(order).flatMap((v): MaybeArray<SortRule> => {\n\t\tif (!v) return [];\n\t\tif (typeof v === 'object') {\n\t\t\tif (!v.field) {\n\t\t\t\treturn [];\n\t\t\t}\n\t\t\tconst rule: SortRule = {\n\t\t\t\tfield: v.field,\n\t\t\t\torder: normalizeOrder(v.order),\n\t\t\t};\n\n\t\t\tif (v.nulls) {\n\t\t\t\trule.nulls = normalizeNulls(v.nulls);\n\t\t\t}\n\t\t\treturn rule;\n\t\t}\n\t\treturn v\n\t\t\t.split(',')\n\t\t\t.map((v) => v.trim())\n\t\t\t.filter(Boolean)\n\t\t\t.map(_parse);\n\t});\n}\n\n/**\n * Normalizes order values to 'asc' or 'desc'\n */\nfunction normalizeOrder(order?: string): SortRule['order'] {\n\treturn order?.toLowerCase() === 'asc' ? 'asc' : 'desc';\n}\n\n/**\n * Normalizes nulls values to 'last' or 'first'\n */\nfunction normalizeNulls(nulls?: string): SortRule['nulls'] {\n\treturn nulls?.toLowerCase() === 'last' ? 'last' : 'first';\n}\n\nfunction _parse(v: string): SortRule {\n\tconst sp = v.split(/\\s+/);\n\tlet field = '';\n\tlet order: SortRule['order'];\n\tlet nulls: SortRule['nulls'];\n\n\t// Handle first token which should be the field name (possibly with +/- prefix)\n\tconst f = sp.shift();\n\tif (!f) return { field: '', order: 'asc' }; // Defensive programming\n\n\tif (f.startsWith('-') || f.startsWith('+')) {\n\t\tfield = f.slice(1).trim();\n\t\torder = f.startsWith('-') ? 'desc' : 'asc';\n\t} else {\n\t\tfield = f.trim();\n\t}\n\n\t// Process remaining tokens\n\twhile (sp.length > 0) {\n\t\tconst token = sp.shift()?.trim()?.toLowerCase();\n\t\tif (!token) continue;\n\n\t\tswitch (token) {\n\t\t\tcase 'asc':\n\t\t\tcase 'desc':\n\t\t\t\torder = token;\n\t\t\t\tbreak;\n\n\t\t\tcase 'nulls':\n\t\t\t\tnulls = sp.shift()?.trim()?.toLowerCase() === 'last' ? 'last' : 'first';\n\t\t\t\tbreak;\n\n\t\t\tcase 'last':\n\t\t\tcase 'first':\n\t\t\t\tnulls = token;\n\t\t\t\tbreak;\n\t\t}\n\t}\n\n\torder ||= 'asc';\n\n\t// Only include nulls if specified\n\treturn nulls ? { field, order, nulls } : { field, order };\n}\n"],"names":["arrayOfMaybeArray","parseSort","order","flatMap","v","field","rule","normalizeOrder","nulls","normalizeNulls","split","map","trim","filter","Boolean","_parse","toLowerCase","sp","f","shift","startsWith","slice","length","token"],"mappings":"AAAA,SAASA,iBAAiB,QAAyB,eAAe;AAIlE;;;;;;;;;;;;;;CAcC,GACD,OAAO,SAASC,UACfC,KAAiG;IAEjG,IAAI,CAACA,OAAO;QACX,OAAO,EAAE;IACV;IAEA,OAAOF,kBAAkBE,OAAOC,OAAO,CAAC,CAACC;QACxC,IAAI,CAACA,GAAG,OAAO,EAAE;QACjB,IAAI,OAAOA,MAAM,UAAU;YAC1B,IAAI,CAACA,EAAEC,KAAK,EAAE;gBACb,OAAO,EAAE;YACV;YACA,MAAMC,OAAiB;gBACtBD,OAAOD,EAAEC,KAAK;gBACdH,OAAOK,eAAeH,EAAEF,KAAK;YAC9B;YAEA,IAAIE,EAAEI,KAAK,EAAE;gBACZF,KAAKE,KAAK,GAAGC,eAAeL,EAAEI,KAAK;YACpC;YACA,OAAOF;QACR;QACA,OAAOF,EACLM,KAAK,CAAC,KACNC,GAAG,CAAC,CAACP,IAAMA,EAAEQ,IAAI,IACjBC,MAAM,CAACC,SACPH,GAAG,CAACI;IACP;AACD;AAEA;;CAEC,GACD,SAASR,eAAeL,KAAc;IACrC,OAAOA,OAAOc,kBAAkB,QAAQ,QAAQ;AACjD;AAEA;;CAEC,GACD,SAASP,eAAeD,KAAc;IACrC,OAAOA,OAAOQ,kBAAkB,SAAS,SAAS;AACnD;AAEA,SAASD,OAAOX,CAAS;IACxB,MAAMa,KAAKb,EAAEM,KAAK,CAAC;IACnB,IAAIL,QAAQ;IACZ,IAAIH;IACJ,IAAIM;IAEJ,+EAA+E;IAC/E,MAAMU,IAAID,GAAGE,KAAK;IAClB,IAAI,CAACD,GAAG,OAAO;QAAEb,OAAO;QAAIH,OAAO;IAAM,GAAG,wBAAwB;IAEpE,IAAIgB,EAAEE,UAAU,CAAC,QAAQF,EAAEE,UAAU,CAAC,MAAM;QAC3Cf,QAAQa,EAAEG,KAAK,CAAC,GAAGT,IAAI;QACvBV,QAAQgB,EAAEE,UAAU,CAAC,OAAO,SAAS;IACtC,OAAO;QACNf,QAAQa,EAAEN,IAAI;IACf;IAEA,2BAA2B;IAC3B,MAAOK,GAAGK,MAAM,GAAG,EAAG;QACrB,MAAMC,QAAQN,GAAGE,KAAK,IAAIP,QAAQI;QAClC,IAAI,CAACO,OAAO;QAEZ,OAAQA;YACP,KAAK;YACL,KAAK;gBACJrB,QAAQqB;gBACR;YAED,KAAK;gBACJf,QAAQS,GAAGE,KAAK,IAAIP,QAAQI,kBAAkB,SAAS,SAAS;gBAChE;YAED,KAAK;YACL,KAAK;gBACJR,QAAQe;gBACR;QACF;IACD;IAEArB,UAAU;IAEV,kCAAkC;IAClC,OAAOM,QAAQ;QAAEH;QAAOH;QAAOM;IAAM,IAAI;QAAEH;QAAOH;IAAM;AACzD"}
@@ -1 +0,0 @@
1
- {"version":3,"sources":["../../src/data/resolvePagination.ts"],"sourcesContent":["import { maybeFunction, type MaybeFunction } from '@wener/utils';\nimport { clamp, mapValues, omitBy, pick } from 'es-toolkit';\nimport { maybeNumber, type MaybeNumber } from './maybeNumber';\n\nexport type PaginationInput = {\n\tlimit?: MaybeNumber;\n\toffset?: MaybeNumber;\n\tpageSize?: MaybeNumber;\n\tpageNumber?: MaybeNumber;\n\tpageIndex?: MaybeNumber;\n};\n\nexport type ResolvedPagination = {\n\tlimit: number;\n\toffset: number;\n\tpageSize: number;\n\tpageNumber: number;\n\tpageIndex: number;\n};\n\nexport function resolvePagination(\n\tpage: PaginationInput,\n\toptions: {\n\t\tpageSize?: MaybeFunction<number, [number | undefined]>;\n\t\tmaxPageSize?: number;\n\t} = {},\n): ResolvedPagination {\n\tlet out = omitBy(\n\t\tmapValues(\n\t\t\t//\n\t\t\tpick(page, ['limit', 'offset', 'pageSize', 'pageNumber', 'pageIndex']),\n\t\t\t// to Number\n\t\t\t(v) => maybeNumber(v),\n\t\t),\n\t\t(v) => v === undefined || v === null,\n\t);\n\tlet { pageSize } = out;\n\tif (options.pageSize) {\n\t\tpageSize = maybeFunction(options.pageSize, pageSize);\n\t}\n\tpageSize ??= 20;\n\tpageSize = clamp(pageSize, 1, options.maxPageSize ?? 1000);\n\n\tlet { pageNumber = 1, pageIndex, limit, offset } = out;\n\t// page index over page number\n\tpageNumber = Math.max(pageNumber, 1);\n\tpageIndex = Math.max(pageIndex ?? pageNumber - 1, 0);\n\tlimit = Math.max(1, limit ?? pageSize);\n\toffset = Math.max(0, offset ?? pageSize * pageIndex);\n\n\tpageSize = limit;\n\tpageIndex = Math.floor(offset / pageSize);\n\treturn {\n\t\tlimit,\n\t\toffset,\n\t\tpageSize,\n\t\tpageNumber: pageIndex + 1,\n\t\tpageIndex,\n\t};\n}\n"],"names":["maybeFunction","clamp","mapValues","omitBy","pick","maybeNumber","resolvePagination","page","options","out","v","undefined","pageSize","maxPageSize","pageNumber","pageIndex","limit","offset","Math","max","floor"],"mappings":"AAAA,SAASA,aAAa,QAA4B,eAAe;AACjE,SAASC,KAAK,EAAEC,SAAS,EAAEC,MAAM,EAAEC,IAAI,QAAQ,aAAa;AAC5D,SAASC,WAAW,QAA0B,gBAAgB;AAkB9D,OAAO,SAASC,kBACfC,IAAqB,EACrBC,UAGI,CAAC,CAAC;IAEN,IAAIC,MAAMN,OACTD,UACC,EAAE;IACFE,KAAKG,MAAM;QAAC;QAAS;QAAU;QAAY;QAAc;KAAY,GACrE,YAAY;IACZ,CAACG,IAAML,YAAYK,KAEpB,CAACA,IAAMA,MAAMC,aAAaD,MAAM;IAEjC,IAAI,EAAEE,QAAQ,EAAE,GAAGH;IACnB,IAAID,QAAQI,QAAQ,EAAE;QACrBA,WAAWZ,cAAcQ,QAAQI,QAAQ,EAAEA;IAC5C;IACAA,aAAa;IACbA,WAAWX,MAAMW,UAAU,GAAGJ,QAAQK,WAAW,IAAI;IAErD,IAAI,EAAEC,aAAa,CAAC,EAAEC,SAAS,EAAEC,KAAK,EAAEC,MAAM,EAAE,GAAGR;IACnD,8BAA8B;IAC9BK,aAAaI,KAAKC,GAAG,CAACL,YAAY;IAClCC,YAAYG,KAAKC,GAAG,CAACJ,aAAaD,aAAa,GAAG;IAClDE,QAAQE,KAAKC,GAAG,CAAC,GAAGH,SAASJ;IAC7BK,SAASC,KAAKC,GAAG,CAAC,GAAGF,UAAUL,WAAWG;IAE1CH,WAAWI;IACXD,YAAYG,KAAKE,KAAK,CAACH,SAASL;IAChC,OAAO;QACNI;QACAC;QACAL;QACAE,YAAYC,YAAY;QACxBA;IACD;AACD"}
@@ -1 +0,0 @@
1
- {"version":3,"sources":["../../src/data/types.d.ts"],"sourcesContent":["export type ListQueryInput = {\n\t/** Filter string */\n\tfilter?: string;\n\t/** Filter array */\n\tfilters?: string[];\n\t/** Filter by IDs */\n\tids?: string[];\n\t/** Search query */\n\tsearch?: string;\n\t/** Items per page */\n\tlimit?: number;\n\t/** Offset for pagination */\n\toffset?: number;\n\t/** Ordering criteria */\n\torder?: string[];\n\t/** Page index (0-based) */\n\tpageIndex?: number;\n\t/** Page number (1-based) */\n\tpageNumber?: number;\n\t/** Items per page */\n\tpageSize?: number;\n\t/** Cursor for pagination */\n\tcursor?: string;\n\t/** Whether to include deleted items */\n\tdeleted?: boolean;\n};\n\ntype ListResult<T = any> = {\n\t/** List of items */\n\tdata: T[];\n\t/** Total number of items */\n\ttotal: number;\n};\n"],"names":[],"mappings":"AAAA,WAyBE"}
package/lib/index.js.map DELETED
@@ -1 +0,0 @@
1
- {"version":3,"sources":["../src/index.ts"],"sourcesContent":["/**\n * @deprecated\n */\nexport { parseSort, type SortRule } from './data/parseSort';\n/**\n * @deprecated\n */\nexport { resolvePagination as normalizePagination } from './data/resolvePagination';\n"],"names":["parseSort","resolvePagination","normalizePagination"],"mappings":"AAAA;;CAEC,GACD,SAASA,SAAS,QAAuB,mBAAmB;AAC5D;;CAEC,GACD,SAASC,qBAAqBC,mBAAmB,QAAQ,2BAA2B"}
@@ -1 +0,0 @@
1
- {"version":3,"sources":["../../src/jsonschema/JsonSchema.ts"],"sourcesContent":["import type { Static, TSchema } from '@sinclair/typebox';\nimport Ajv, { type ErrorObject, type Options } from 'ajv';\nimport addFormats from 'ajv-formats';\n// import localize from 'ajv-i18n/localize/zh';\nimport addKeywords from 'ajv-keywords';\nimport { isNil } from 'es-toolkit';\nimport { match, P } from 'ts-pattern';\nimport type { JsonSchemaDef } from './types';\n\nfunction _createAjv(opt: Options) {\n\tconst ajv = new Ajv(opt);\n\taddKeywords(ajv);\n\taddFormats(ajv);\n\treturn ajv;\n}\n\ntype ValidateOptions = { mutate?: boolean; clone?: boolean; ajv?: Ajv };\n\ntype ValidateResult<T> =\n\t| { data: T; success: true; message: undefined }\n\t| { data: undefined; success: false; message: string; errors: ErrorObject[] };\n\nfunction validate({ schema, data, mutate, clone, ajv }: ValidateOptions & { schema: any; data: any }) {\n\tlet opts: Options = {\n\t\t// strict: 'log',\n\t\tstrict: true,\n\t\tstrictSchema: 'log', // skip unknown keywords in schema\n\t};\n\n\tif (mutate) {\n\t\tObject.assign(opts, { removeAdditional: true, useDefaults: true, coerceTypes: true, allErrors: true });\n\t}\n\n\tif (clone) {\n\t\tdata = structuredClone(data);\n\t}\n\n\tif (!ajv) {\n\t\tajv = JsonSchema.createAjv(opts);\n\t}\n\n\tconst validate = ajv.compile(schema);\n\n\t// consider reusing validate instance\n\n\tconst valid = validate(data);\n\tconst errors = validate.errors;\n\t// localize(errors);\n\n\treturn { data, success: valid, message: ajv.errorsText(errors), errors: errors };\n}\n\ntype TypeOfSchema<S> = S extends TSchema ? Static<S> : any;\n\nexport namespace JsonSchema {\n\texport let schemas: JsonSchemaDef[] = [];\n\n\texport const createAjv = _createAjv;\n\n\texport function addSchema(\n\t\tschema: JsonSchemaDef,\n\t\t{\n\t\t\tonConflict = 'throw',\n\t\t}: {\n\t\t\tonConflict?: 'throw' | 'ignore' | 'replace' | ((old: JsonSchemaDef, neo: JsonSchemaDef) => JsonSchemaDef);\n\t\t} = {},\n\t) {\n\t\tif (!schema.$id) throw new Error('Schema must have $id');\n\t\tswitch (onConflict) {\n\t\t\tcase 'ignore':\n\t\t\t\tonConflict = (old) => old;\n\t\t\t\tbreak;\n\t\t\tcase 'replace':\n\t\t\t\tonConflict = (_, neo) => neo;\n\t\t\t\tbreak;\n\t\t\tcase 'throw':\n\t\t\t\tonConflict = (old, neo) => {\n\t\t\t\t\tthrow new Error(`Schema ${neo.$id} already exists`);\n\t\t\t\t};\n\t\t\t\tbreak;\n\t\t}\n\t\tlet idx = schemas.findIndex((s) => s.$id === schema.$id);\n\t\tif (idx >= 0) {\n\t\t\tschemas[idx] = onConflict(schemas[idx], schema);\n\t\t} else {\n\t\t\tschemas.push(schema);\n\t\t}\n\t}\n\n\t/**\n\t * Check data is valid, will not use default\n\t */\n\texport function check<S>(schema: S, data: any): ValidateResult<TypeOfSchema<S>> {\n\t\treturn validate({ schema, data, mutate: false, clone: true }) as any;\n\t}\n\n\t/**\n\t * Parse data with default value and coerceTypes\n\t */\n\texport function safeParse<S>(schema: S, data: any): ValidateResult<TypeOfSchema<S>> {\n\t\treturn validate({ schema, data, mutate: true, clone: true }) as any;\n\t}\n\n\texport function parse<S>(schema: S, data: any): TypeOfSchema<S> {\n\t\tconst { data: out, message, errors } = validate({ schema, data, mutate: true, clone: true });\n\t\tif (errors) {\n\t\t\tthrow new Error(message);\n\t\t}\n\t\treturn out;\n\t}\n\n\texport function create<S>(schema: S, data?: any): TypeOfSchema<S> {\n\t\t// will not ensure value match the rule\n\t\treturn match(schema as JsonSchemaDef)\n\t\t\t.returnType<any>()\n\t\t\t.with({ const: P.select() }, (v) => v)\n\t\t\t.with({ default: P.select() }, (v) => v)\n\t\t\t.with({ anyOf: P.nonNullable }, (schema) => {\n\t\t\t\treturn create(schema.anyOf[0]);\n\t\t\t})\n\t\t\t.with({ oneOf: P.nonNullable }, (schema) => {\n\t\t\t\treturn create(schema.oneOf[0]);\n\t\t\t})\n\t\t\t.with({ type: 'string' }, (schema) => '')\n\t\t\t.with({ type: P.union('number', 'integer') }, (schema) => 0)\n\t\t\t.with({ type: 'object' }, (schema) => {\n\t\t\t\tlet out = validate({ schema, data: data ?? {}, mutate: true });\n\t\t\t\tif (!out.success) {\n\t\t\t\t\t// fallback\n\t\t\t\t\tlet obj = data || {};\n\t\t\t\t\tschema.required?.forEach((key) => {\n\t\t\t\t\t\tif (!(key in obj)) {\n\t\t\t\t\t\t\tlet last = obj[key];\n\t\t\t\t\t\t\tlet prop = schema.properties?.[key];\n\t\t\t\t\t\t\tif (prop && isNil(last)) obj[key] = JsonSchema.create(prop, last);\n\t\t\t\t\t\t}\n\t\t\t\t\t});\n\t\t\t\t\tout = validate({ schema, data: obj, mutate: true });\n\t\t\t\t\tif (!out.success) {\n\t\t\t\t\t\tconsole.warn(`Failed to create object with schema: ${out.message}`);\n\t\t\t\t\t}\n\t\t\t\t}\n\t\t\t\treturn out.data;\n\t\t\t})\n\t\t\t.with({ type: 'null' }, () => null)\n\t\t\t.with({ type: 'boolean' }, (schema) => false)\n\t\t\t.with({ type: 'array' }, (schema) => [])\n\t\t\t.otherwise(() => {\n\t\t\t\treturn undefined;\n\t\t\t});\n\t}\n\n\texport function isPrimitiveType(schema: any): boolean {\n\t\treturn match(schema as JsonSchemaDef)\n\t\t\t.returnType<boolean>()\n\t\t\t.with({ type: P.union('number', 'integer', 'string', 'boolean') }, () => true)\n\t\t\t.with({ anyOf: P.nonNullable }, (schema) => {\n\t\t\t\treturn isPrimitiveType(schema.anyOf[0]);\n\t\t\t})\n\t\t\t.with({ oneOf: P.nonNullable }, (schema) => {\n\t\t\t\treturn isPrimitiveType(schema.oneOf[0]);\n\t\t\t})\n\t\t\t.otherwise(() => false);\n\t}\n}\n"],"names":["Ajv","addFormats","addKeywords","isNil","match","P","_createAjv","opt","ajv","validate","schema","data","mutate","clone","opts","strict","strictSchema","Object","assign","removeAdditional","useDefaults","coerceTypes","allErrors","structuredClone","JsonSchema","createAjv","compile","valid","errors","success","message","errorsText","schemas","addSchema","onConflict","$id","Error","old","_","neo","idx","findIndex","s","push","check","safeParse","parse","out","create","returnType","with","const","select","v","default","anyOf","nonNullable","oneOf","type","union","obj","required","forEach","key","last","prop","properties","console","warn","otherwise","undefined","isPrimitiveType"],"mappings":"AACA,OAAOA,SAA6C,MAAM;AAC1D,OAAOC,gBAAgB,cAAc;AACrC,+CAA+C;AAC/C,OAAOC,iBAAiB,eAAe;AACvC,SAASC,KAAK,QAAQ,aAAa;AACnC,SAASC,KAAK,EAAEC,CAAC,QAAQ,aAAa;AAGtC,SAASC,WAAWC,GAAY;IAC/B,MAAMC,MAAM,IAAIR,IAAIO;IACpBL,YAAYM;IACZP,WAAWO;IACX,OAAOA;AACR;AAQA,SAASC,SAAS,EAAEC,MAAM,EAAEC,IAAI,EAAEC,MAAM,EAAEC,KAAK,EAAEL,GAAG,EAAgD;IACnG,IAAIM,OAAgB;QACnB,iBAAiB;QACjBC,QAAQ;QACRC,cAAc;IACf;IAEA,IAAIJ,QAAQ;QACXK,OAAOC,MAAM,CAACJ,MAAM;YAAEK,kBAAkB;YAAMC,aAAa;YAAMC,aAAa;YAAMC,WAAW;QAAK;IACrG;IAEA,IAAIT,OAAO;QACVF,OAAOY,gBAAgBZ;IACxB;IAEA,IAAI,CAACH,KAAK;QACTA,MAAMgB,WAAWC,SAAS,CAACX;IAC5B;IAEA,MAAML,WAAWD,IAAIkB,OAAO,CAAChB;IAE7B,qCAAqC;IAErC,MAAMiB,QAAQlB,SAASE;IACvB,MAAMiB,SAASnB,SAASmB,MAAM;IAC9B,oBAAoB;IAEpB,O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,CAACiB,MAAMD;oBAC7D;gBACD;gBACAjB,MAAMtC,SAAS;oBAAEC;oBAAQC,MAAMiD;oBAAKhD,QAAQ;gBAAK;gBACjD,IAAI,CAACmC,IAAIlB,OAAO,EAAE;oBACjBsC,QAAQC,IAAI,CAAC,CAAC,qCAAqC,EAAErB,IAAIjB,OAAO,EAAE;gBACnE;YACD;YACA,OAAOiB,IAAIpC,IAAI;QAChB,GACCuC,IAAI,CAAC;YAAEQ,MAAM;QAAO,GAAG,IAAM,MAC7BR,IAAI,CAAC;YAAEQ,MAAM;QAAU,GAAG,CAAChD,SAAW,OACtCwC,IAAI,CAAC;YAAEQ,MAAM;QAAQ,GAAG,CAAChD,SAAW,EAAE,EACtC2D,SAAS,CAAC;YACV,OAAOC;QACR;IACF;eAvCgBtB,SAAAA;IAyCT,SAASuB,gBAAgB7D,MAAW;QAC1C,OAAON,MAAMM,QACXuC,UAAU,GACVC,IAAI,CAAC;YAAEQ,MAAMrD,EAAEsD,KAAK,CAAC,UAAU,WAAW,UAAU;QAAW,GAAG,IAAM,MACxET,IAAI,CAAC;YAAEK,OAAOlD,EAAEmD,WAAW;QAAC,GAAG,CAAC9C;YAChC,OAAO6D,gBAAgB7D,OAAO6C,KAAK,CAAC,EAAE;QACvC,GACCL,IAAI,CAAC;YAAEO,OAAOpD,EAAEmD,WAAW;QAAC,GAAG,CAAC9C;YAChC,OAAO6D,gBAAgB7D,OAAO+C,KAAK,CAAC,EAAE;QACvC,GACCY,SAAS,CAAC,IAAM;IACnB;eAXgBE,kBAAAA;AAYjB,GA9GiB/C,eAAAA"}
@@ -1 +0,0 @@
1
- {"version":3,"sources":["../../src/jsonschema/index.ts"],"sourcesContent":["export { JsonSchema } from './JsonSchema';\nexport type { JsonSchemaDef } from './types';\n"],"names":["JsonSchema"],"mappings":"AAAA,SAASA,UAAU,QAAQ,eAAe"}
@@ -1 +0,0 @@
1
- {"version":3,"sources":["../../src/jsonschema/types.d.ts"],"sourcesContent":["type JsonSchemaTypeName =\n\t| 'string' //\n\t| 'number'\n\t| 'integer'\n\t| 'boolean'\n\t| 'object'\n\t| 'array'\n\t| 'null';\n\ntype JsonValue =\n\t| string //\n\t| number\n\t| boolean\n\t| { [key: string]: JsonValue }\n\t| JsonValue[]\n\t| null;\n\ntype JsonSchemaVersion =\n\t| 'http://json-schema.org/schema' // latest\n\t| 'https://json-schema.org/draft/2020-12/schema'\n\t// draft-07\n\t| 'http://json-schema.org/draft-07/schema#' //\n\t| 'http://json-schema.org/draft-07/hyper-schema#';\n\ntype JsonSchemaFormatName =\n\t//\n\t| 'date-time'\n\t| 'date'\n\t| 'time'\n\t| 'duration'\n\t//\n\t| 'email'\n\t| 'idn-email'\n\t//\n\t| 'hostname'\n\t| 'idn-hostname'\n\t| 'ipv4'\n\t| 'ipv6'\n\t//\n\t| 'uri'\n\t| 'uri-reference'\n\t| 'iri'\n\t| 'iri-reference'\n\t| 'uuid'\n\t| 'uri-template'\n\t| 'regex'\n\t| 'json-pointer'\n\t| 'relative-json-pointer';\n\nexport type JsonSchemaDef = {\n\t$id?: string;\n\t$ref?: string;\n\t/**\n\t * Meta schema\n\t *\n\t * Recommended values:\n\t * - 'http://json-schema.org/schema#'\n\t * - 'http://json-schema.org/hyper-schema#'\n\t * - 'http://json-schema.org/draft-07/schema#'\n\t * - 'http://json-schema.org/draft-07/hyper-schema#'\n\t *\n\t * @see https://tools.ietf.org/html/draft-handrews-json-schema-validation-01#section-5\n\t */\n\t$schema?: JsonSchemaVersion | string;\n\t$comment?: string;\n\n\t$defs?: { [key: string]: JsonSchemaDef };\n\n\ttype?: JsonSchemaTypeName | JsonSchemaTypeName[];\n\tenum?: JsonValue[];\n\tconst?: JsonValue;\n\n\t//region Numeric Validation\n\n\tmultipleOf?: number;\n\tmaximum?: number;\n\texclusiveMaximum?: number;\n\tminimum?: number;\n\texclusiveMinimum?: number;\n\n\t//endregion\n\n\t//region String Validation\n\n\tmaxLength?: number;\n\tminLength?: number;\n\tpattern?: string;\n\n\t//endregion\n\n\t//region Array Validation\n\n\titems?: JsonSchemaDef | JsonSchemaDef[];\n\tadditionalItems?: JsonSchemaDef;\n\tmaxItems?: number;\n\tminItems?: number;\n\tuniqueItems?: boolean;\n\tcontains?: JsonSchemaDef;\n\t//endregion\n\n\t//region Object Validation\n\n\tmaxProperties?: number;\n\tminProperties?: number;\n\trequired?: string[];\n\tproperties?: { [key: string]: JsonSchemaDef };\n\tpatternProperties?: { [key: string]: JsonSchemaDef };\n\tadditionalProperties?: JsonSchemaDef;\n\tdependencies?: { [key: string]: JsonSchemaDef | string[] };\n\tpropertyNames?: JsonSchemaDef;\n\t//endregion\n\n\t//region Conditional\n\n\tif?: JsonSchemaDef;\n\tthen?: JsonSchemaDef;\n\telse?: JsonSchemaDef;\n\n\t//endregion\n\n\t//region Boolean Logic\n\n\tallOf?: JsonSchemaDef[];\n\tanyOf?: JsonSchemaDef[];\n\toneOf?: JsonSchemaDef[];\n\tnot?: JsonSchemaDef;\n\t//endregion\n\n\t//region Semantic\n\n\tformat?: JsonSchemaFormatName | string;\n\n\t//endregion\n\n\t//region String-Encoding Non-JSON Data\n\n\tcontentMediaType?: string;\n\tcontentEncoding?: string;\n\tcontentSchema?: JsonSchemaDef;\n\t//endregion\n\n\t/**\n\t * use {@link $defs} instead\n\t */\n\tdefinitions?: Record<string, JsonSchemaDef>;\n\n\t//region Meta-Data Annotations\n\t/**\n\t * @see https://tools.ietf.org/html/draft-handrews-json-schema-validation-01#section-10\n\t */\n\n\ttitle?: string;\n\tdescription?: string;\n\tdefault?: JsonValue;\n\treadOnly?: boolean;\n\twriteOnly?: boolean;\n\texamples?: JsonValue;\n\tdeprecated?: boolean;\n\n\t//endregion\n\n\tnullable?: boolean;\n};\n"],"names":[],"mappings":"AAiDA,WAiHE"}
@@ -1 +0,0 @@
1
- {"version":3,"sources":["../../src/meta/defineFileType.tsx"],"sourcesContent":["type DefineFileTypeOptions = {\n\tname: string;\n\ttitle?: string;\n\tdescription?: string;\n\ttype?: string;\n\ttypes?: string[];\n\textension?: string;\n\textensions?: string[];\n\ttags?: string[];\n\tmetadata?: Record<string, any>;\n};\nexport type FileTypeDef = {\n\tname: string;\n\ttitle: string;\n\tdescription?: string;\n\ttype: string; // primary type\n\textension: string; // primary extension\n\ttypes: string[];\n\textensions: string[];\n\ttags: string[];\n\tmetadata: Record<string, any>;\n};\n\nlet _all: FileTypeDef[] = [];\n\nexport function defineFileType({\n\ttype = '',\n\ttypes = [],\n\textension = '',\n\textensions = [],\n\t...opts\n}: DefineFileTypeOptions): FileTypeDef {\n\tif (!type) {\n\t\ttype = types[0] || '';\n\t}\n\tif (!extension) {\n\t\textension = extensions[0] || '';\n\t}\n\tif (!types.includes(type)) {\n\t\ttypes = [type, ...types];\n\t}\n\tif (!extensions.includes(extension)) {\n\t\textensions = [extension, ...extensions];\n\t}\n\n\tconst def: FileTypeDef = {\n\t\ttitle: opts.title || opts.name,\n\t\ttype,\n\t\textension,\n\t\ttypes,\n\t\textensions,\n\t\ttags: [],\n\t\tmetadata: {},\n\t\t...opts,\n\t};\n\tlet idx = _all.findIndex((v) => v.name === def.name);\n\tif (idx >= 0) {\n\t\t_all[idx] = def;\n\t\tconsole.warn(`File type ${def.name} is redefined`);\n\t} else {\n\t\t_all.push(def);\n\t}\n\treturn def;\n}\n\nexport function getFileType(): FileTypeDef[] {\n\treturn _all;\n}\n"],"names":["_all","defineFileType","type","types","extension","extensions","opts","includes","def","title","name","tags","metadata","idx","findIndex","v","console","warn","push","getFileType"],"mappings":"AAuBA,IAAIA,OAAsB,EAAE;AAE5B,OAAO,SAASC,eAAe,EAC9BC,OAAO,EAAE,EACTC,QAAQ,EAAE,EACVC,YAAY,EAAE,EACdC,aAAa,EAAE,EACf,GAAGC,MACoB;IACvB,IAAI,CAACJ,MAAM;QACVA,OAAOC,KAAK,CAAC,EAAE,IAAI;IACpB;IACA,IAAI,CAACC,WAAW;QACfA,YAAYC,UAAU,CAAC,EAAE,IAAI;IAC9B;IACA,IAAI,CAACF,MAAMI,QAAQ,CAACL,OAAO;QAC1BC,QAAQ;YAACD;eAASC;SAAM;IACzB;IACA,IAAI,CAACE,WAAWE,QAAQ,CAACH,YAAY;QACpCC,aAAa;YAACD;eAAcC;SAAW;IACxC;IAEA,MAAMG,MAAmB;QACxBC,OAAOH,KAAKG,KAAK,IAAIH,KAAKI,IAAI;QAC9BR;QACAE;QACAD;QACAE;QACAM,MAAM,EAAE;QACRC,UAAU,CAAC;QACX,GAAGN,IAAI;IACR;IACA,IAAIO,MAAMb,KAAKc,SAAS,CAAC,CAACC,IAAMA,EAAEL,IAAI,KAAKF,IAAIE,IAAI;IACnD,IAAIG,OAAO,GAAG;QACbb,IAAI,CAACa,IAAI,GAAGL;QACZQ,QAAQC,IAAI,CAAC,CAAC,UAAU,EAAET,IAAIE,IAAI,CAAC,aAAa,CAAC;IAClD,OAAO;QACNV,KAAKkB,IAAI,CAACV;IACX;IACA,OAAOA;AACR;AAEA,OAAO,SAASW;IACf,OAAOnB;AACR"}
@@ -1 +0,0 @@
1
- {"version":3,"sources":["../../src/meta/defineInit.ts"],"sourcesContent":["import type { MaybePromise } from '@wener/utils';\nimport { startCase } from 'es-toolkit';\n\ntype DefineInitOptions = { name: string; title?: string; onInit?: () => any; metadata?: Record<string, any> };\nexport type InitDef = { name: string; title: string; onInit?: () => any; metadata: Record<string, any> };\nlet _all: InitDef[] = [];\n\nexport function defineInit(o: DefineInitOptions) {\n\tconst def = { title: startCase(o.name), metadata: {}, ...o };\n\tlet idx = _all.findIndex((v) => v.name === def.name);\n\tif (idx >= 0) {\n\t\tconsole.warn(`skip redefined init: ${def.name}`);\n\t} else {\n\t\t_all.push(def);\n\t}\n\n\treturn def;\n}\n\nlet result = new Map<any, MaybePromise<InitResult>>();\n\ntype InitResult = { name: string; success: boolean; error?: any };\n\nexport async function runInit(inits = _all) {\n\tfor (let init of inits) {\n\t\tif (result.get(init)) {\n\t\t\treturn;\n\t\t}\n\t\tresult.set(\n\t\t\tinit,\n\t\t\tPromise.resolve().then(async () => {\n\t\t\t\tlet out: InitResult = { name: init.name, success: true };\n\t\t\t\ttry {\n\t\t\t\t\tawait init.onInit?.();\n\t\t\t\t} catch (e) {\n\t\t\t\t\tconsole.error(`Failed to init ${init.name}`, e);\n\t\t\t\t\tout.success = false;\n\t\t\t\t\tout.error = e;\n\t\t\t\t}\n\t\t\t\tresult.set(init, out);\n\t\t\t\treturn out;\n\t\t\t}),\n\t\t);\n\t}\n\n\treturn Promise.all(result.values());\n}\n"],"names":["startCase","_all","defineInit","o","def","title","name","metadata","idx","findIndex","v","console","warn","push","result","Map","runInit","inits","init","get","set","Promise","resolve","then","out","success","onInit","e","error","all","values"],"mappings":"AACA,SAASA,SAAS,QAAQ,aAAa;AAIvC,IAAIC,OAAkB,EAAE;AAExB,OAAO,SAASC,WAAWC,CAAoB;IAC9C,MAAMC,MAAM;QAAEC,OAAOL,UAAUG,EAAEG,IAAI;QAAGC,UAAU,CAAC;QAAG,GAAGJ,CAAC;IAAC;IAC3D,IAAIK,MAAMP,KAAKQ,SAAS,CAAC,CAACC,IAAMA,EAAEJ,IAAI,KAAKF,IAAIE,IAAI;IACnD,IAAIE,OAAO,GAAG;QACbG,QAAQC,IAAI,CAAC,CAAC,qBAAqB,EAAER,IAAIE,IAAI,EAAE;IAChD,OAAO;QACNL,KAAKY,IAAI,CAACT;IACX;IAEA,OAAOA;AACR;AAEA,IAAIU,SAAS,IAAIC;AAIjB,OAAO,eAAeC,QAAQC,QAAQhB,IAAI;IACzC,KAAK,IAAIiB,QAAQD,MAAO;QACvB,IAAIH,OAAOK,GAAG,CAACD,OAAO;YACrB;QACD;QACAJ,OAAOM,GAAG,CACTF,MACAG,QAAQC,OAAO,GAAGC,IAAI,CAAC;YACtB,IAAIC,MAAkB;gBAAElB,MAAMY,KAAKZ,IAAI;gBAAEmB,SAAS;YAAK;YACvD,IAAI;gBACH,MAAMP,KAAKQ,MAAM;YAClB,EAAE,OAAOC,GAAG;gBACXhB,QAAQiB,KAAK,CAAC,CAAC,eAAe,EAAEV,KAAKZ,IAAI,EAAE,EAAEqB;gBAC7CH,IAAIC,OAAO,GAAG;gBACdD,IAAII,KAAK,GAAGD;YACb;YACAb,OAAOM,GAAG,CAACF,MAAMM;YACjB,OAAOA;QACR;IAEF;IAEA,OAAOH,QAAQQ,GAAG,CAACf,OAAOgB,MAAM;AACjC"}
@@ -1 +0,0 @@
1
- {"version":3,"sources":["../../src/meta/defineMetadata.ts"],"sourcesContent":["import { startCase } from 'es-toolkit';\nimport { get, set } from 'es-toolkit/compat';\n\ntype HasMetadata = { metadata?: Record<string, any> };\n\ntype MetadataKey<T> = { key: string; type: T; title: string; description?: string };\n\ninterface CreateMetadataKeyOptions {\n\tkey: string;\n\ttitle?: string;\n\tdescription?: string;\n}\n\nexport function createMetadataKey<T = never>(key: string, opts?: Omit<CreateMetadataKeyOptions, 'key'>): MetadataKey<T>;\nexport function createMetadataKey<T = never>(opts: CreateMetadataKeyOptions): MetadataKey<T>;\nexport function createMetadataKey<T = never>(a: any, b?: any): MetadataKey<T> {\n\tconst opts: CreateMetadataKeyOptions = typeof a === 'string' ? { key: a, ...b } : a;\n\n\tconst { key } = opts;\n\topts.title ||= startCase(key);\n\n\tconst k: MetadataKey<T> = { ...opts, type: null as any } as MetadataKey<T>;\n\n\tif ('toStringTag' in Symbol && typeof Symbol.toStringTag === 'symbol') {\n\t\tObject.defineProperty(k, Symbol.toStringTag, { value: key });\n\t}\n\n\treturn k;\n}\n\nexport function defineMetadata<T>(res: HasMetadata, key: MetadataKey<T>, opts: T): void;\nexport function defineMetadata<T>(key: MetadataKey<T>, items: Array<[HasMetadata, T]>): void;\nexport function defineMetadata<T>(a: any, b: any, c?: any) {\n\tif (Array.isArray(b)) {\n\t\tconst key = a;\n\t\tconst items = b;\n\t\tfor (const [res, opts] of items) {\n\t\t\tdefineMetadata(res, key, opts);\n\t\t}\n\t} else {\n\t\tconst res = a;\n\t\tconst key = b;\n\t\tconst opts = c;\n\t\tres.metadata = res.metadata || {};\n\t\tset(res.metadata, key.key, opts);\n\t}\n}\n\nexport function getMetadata<T>(res: HasMetadata | undefined | null, key: MetadataKey<T>): T | undefined {\n\tif (!res?.metadata) return undefined;\n\treturn get(res.metadata, key.key);\n}\n"],"names":["startCase","get","set","createMetadataKey","a","b","opts","key","title","k","type","Symbol","toStringTag","Object","defineProperty","value","defineMetadata","c","Array","isArray","items","res","metadata","getMetadata","undefined"],"mappings":"AAAA,SAASA,SAAS,QAAQ,aAAa;AACvC,SAASC,GAAG,EAAEC,GAAG,QAAQ,oBAAoB;AAc7C,OAAO,SAASC,kBAA6BC,CAAM,EAAEC,CAAO;IAC3D,MAAMC,OAAiC,OAAOF,MAAM,WAAW;QAAEG,KAAKH;QAAG,GAAGC,CAAC;IAAC,IAAID;IAElF,MAAM,EAAEG,GAAG,EAAE,GAAGD;IAChBA,KAAKE,KAAK,KAAKR,UAAUO;IAEzB,MAAME,IAAoB;QAAE,GAAGH,IAAI;QAAEI,MAAM;IAAY;IAEvD,IAAI,iBAAiBC,UAAU,OAAOA,OAAOC,WAAW,KAAK,UAAU;QACtEC,OAAOC,cAAc,CAACL,GAAGE,OAAOC,WAAW,EAAE;YAAEG,OAAOR;QAAI;IAC3D;IAEA,OAAOE;AACR;AAIA,OAAO,SAASO,eAAkBZ,CAAM,EAAEC,CAAM,EAAEY,CAAO;IACxD,IAAIC,MAAMC,OAAO,CAACd,IAAI;QACrB,MAAME,MAAMH;QACZ,MAAMgB,QAAQf;QACd,KAAK,MAAM,CAACgB,KAAKf,KAAK,IAAIc,MAAO;YAChCJ,eAAeK,KAAKd,KAAKD;QAC1B;IACD,OAAO;QACN,MAAMe,MAAMjB;QACZ,MAAMG,MAAMF;QACZ,MAAMC,OAAOW;QACbI,IAAIC,QAAQ,GAAGD,IAAIC,QAAQ,IAAI,CAAC;QAChCpB,IAAImB,IAAIC,QAAQ,EAAEf,IAAIA,GAAG,EAAED;IAC5B;AACD;AAEA,OAAO,SAASiB,YAAeF,GAAmC,EAAEd,GAAmB;IACtF,IAAI,CAACc,KAAKC,UAAU,OAAOE;IAC3B,OAAOvB,IAAIoB,IAAIC,QAAQ,EAAEf,IAAIA,GAAG;AACjC"}
@@ -1 +0,0 @@
1
- {"version":3,"sources":["../../src/meta/index.ts"],"sourcesContent":["export { createMetadataKey, defineMetadata, getMetadata } from './defineMetadata';\n\nexport { defineInit, type InitDef, runInit } from './defineInit';\n\nexport { defineFileType, getFileType, type FileTypeDef } from './defineFileType';\n"],"names":["createMetadataKey","defineMetadata","getMetadata","defineInit","runInit","defineFileType","getFileType"],"mappings":"AAAA,SAASA,iBAAiB,EAAEC,cAAc,EAAEC,WAAW,QAAQ,mBAAmB;AAElF,SAASC,UAAU,EAAgBC,OAAO,QAAQ,eAAe;AAEjE,SAASC,cAAc,EAAEC,WAAW,QAA0B,mBAAmB"}
@@ -1 +0,0 @@
1
- {"version":3,"sources":["../../src/password/PHC.ts"],"sourcesContent":["import { ArrayBuffers } from '@wener/utils';\n\nexport namespace PHC {\n\t// https://github.com/simonepri/phc-format/blob/master/index.js\n\n\tconst idRegex = /^[a-z0-9-]{1,32}$/;\n\tconst nameRegex = /^[a-z0-9-]{1,32}$/;\n\tconst valueRegex = /^[a-zA-Z0-9/+.-]+$/;\n\tconst b64Regex = /^([a-zA-Z0-9/+.-]+|)$/;\n\tconst decimalRegex = /^((-)?[1-9]\\d*|0)$/;\n\tconst versionRegex = /^v=(\\d+)$/;\n\n\tconst fromBase64 = ArrayBuffers.fromBase64;\n\tconst toBase64 = ArrayBuffers.toBase64;\n\tconst isBuffer = (v: any): v is Uint8Array => {\n\t\treturn v instanceof Uint8Array;\n\t};\n\n\tfunction objToKeyVal(obj: Record<string, any>): string {\n\t\treturn objectKeys(obj)\n\t\t\t.map((k) => [k, obj[k]].join('='))\n\t\t\t.join(',');\n\t}\n\n\tfunction keyValtoObj(str: string): Record<string, string> {\n\t\tconst obj: Record<string, string> = {};\n\t\tstr.split(',').forEach((ps) => {\n\t\t\tconst pss = ps.split('=');\n\t\t\tif (pss.length < 2) {\n\t\t\t\tthrow new TypeError(`params must be in the format name=value`);\n\t\t\t}\n\n\t\t\tconst key = pss.shift();\n\t\t\tif (key !== undefined) {\n\t\t\t\tobj[key] = pss.join('=');\n\t\t\t}\n\t\t});\n\t\treturn obj;\n\t}\n\n\tfunction objectKeys<T extends object>(object: T): Array<keyof T> {\n\t\treturn Object.keys(object) as Array<keyof T>;\n\t}\n\n\tfunction objectValues<T extends object>(object: T): Array<T[keyof T]> {\n\t\tif (typeof Object.values === 'function') return Object.values(object);\n\t\treturn objectKeys(object).map((k) => object[k]);\n\t}\n\n\tinterface SerializeOptions {\n\t\tid: string;\n\t\tversion?: number;\n\t\tparams?: Record<string, string | number | Uint8Array>;\n\t\tsalt?: Uint8Array;\n\t\thash?: Uint8Array;\n\t}\n\n\t/**\n\t * Generates a PHC string using the data provided.\n\t * @param {SerializeOptions} opts Object that holds the data needed to generate the PHC string.\n\t * @return {string} The hash string adhering to the PHC format.\n\t */\n\texport function serialize(opts: SerializeOptions): string {\n\t\tconst fields: string[] = [''];\n\n\t\tif (typeof opts !== 'object' || opts === null) {\n\t\t\tthrow new TypeError('opts must be an object');\n\t\t}\n\n\t\t// Identifier Validation\n\t\tif (typeof opts.id !== 'string') {\n\t\t\tthrow new TypeError('id must be a string');\n\t\t}\n\n\t\tif (!idRegex.test(opts.id)) {\n\t\t\tthrow new TypeError(`id must satisfy ${idRegex}`);\n\t\t}\n\n\t\tfields.push(opts.id);\n\n\t\tif (typeof opts.version !== 'undefined') {\n\t\t\tif (typeof opts.version !== 'number' || opts.version < 0 || !Number.isInteger(opts.version)) {\n\t\t\t\tthrow new TypeError('version must be a positive integer number');\n\t\t\t}\n\n\t\t\tfields.push(`v=${opts.version}`);\n\t\t}\n\n\t\t// Parameters Validation\n\t\tif (typeof opts.params !== 'undefined') {\n\t\t\tif (typeof opts.params !== 'object' || opts.params === null) {\n\t\t\t\tthrow new TypeError('params must be an object');\n\t\t\t}\n\n\t\t\tconst pk = objectKeys(opts.params);\n\t\t\tif (!pk.every((p) => nameRegex.test(p.toString()))) {\n\t\t\t\tthrow new TypeError(`params names must satisfy ${nameRegex}`);\n\t\t\t}\n\n\t\t\t// Convert Numbers into Numeric Strings and Buffers into B64 encoded strings.\n\t\t\tpk.forEach((k) => {\n\t\t\t\tconst value = opts.params![k];\n\t\t\t\tif (typeof value === 'number') {\n\t\t\t\t\topts.params![k] = value.toString();\n\t\t\t\t} else if (value instanceof Uint8Array) {\n\t\t\t\t\topts.params![k] = toBase64(value).split('=')[0];\n\t\t\t\t}\n\t\t\t});\n\t\t\tconst pv = objectValues(opts.params);\n\t\t\tif (!pv.every((v) => typeof v === 'string')) {\n\t\t\t\tthrow new TypeError('params values must be strings');\n\t\t\t}\n\n\t\t\tif (!pv.every((v) => valueRegex.test(v))) {\n\t\t\t\tthrow new TypeError(`params values must satisfy ${valueRegex}`);\n\t\t\t}\n\n\t\t\tconst strpar = objToKeyVal(opts.params as Record<string, string>);\n\t\t\tfields.push(strpar);\n\t\t}\n\n\t\tif (typeof opts.salt !== 'undefined') {\n\t\t\t// Salt Validation\n\t\t\tif (!isBuffer(opts.salt)) {\n\t\t\t\tthrow new TypeError('salt must be a Buffer');\n\t\t\t}\n\n\t\t\tfields.push(toBase64(opts.salt).split('=')[0]);\n\n\t\t\tif (typeof opts.hash !== 'undefined') {\n\t\t\t\t// Hash Validation\n\t\t\t\tif (!isBuffer(opts.hash)) {\n\t\t\t\t\tthrow new TypeError('hash must be a Buffer');\n\t\t\t\t}\n\n\t\t\t\tfields.push(toBase64(opts.hash).split('=')[0]);\n\t\t\t}\n\t\t}\n\n\t\t// Create the PHC formatted string\n\t\tconst phcstr = fields.join('$');\n\n\t\treturn phcstr;\n\t}\n\n\tinterface DeserializeResult {\n\t\tid: string;\n\t\tversion?: number;\n\t\tparams?: Record<string, string | number>;\n\t\tsalt?: Uint8Array;\n\t\thash?: Uint8Array;\n\t}\n\n\t/**\n\t * Parses data from a PHC string.\n\t * @param {string} phcstr A PHC string to parse.\n\t * @return {DeserializeResult} The object containing the data parsed from the PHC string.\n\t */\n\texport function deserialize(phcstr: string): DeserializeResult {\n\t\tif (typeof phcstr !== 'string' || phcstr === '') {\n\t\t\tthrow new TypeError('pchstr must be a non-empty string');\n\t\t}\n\n\t\tif (phcstr[0] !== '$') {\n\t\t\tthrow new TypeError('pchstr must contain a $ as first char');\n\t\t}\n\n\t\tconst fields = phcstr.split('$');\n\t\t// Remove first empty $\n\t\tfields.shift();\n\n\t\t// Parse Fields\n\t\tlet maxf = 5;\n\t\tif (!versionRegex.test(fields[1])) maxf--;\n\t\tif (fields.length > maxf) {\n\t\t\tthrow new TypeError(`pchstr contains too many fileds: ${fields.length}/${maxf}`);\n\t\t}\n\n\t\t// Parse Identifier\n\t\tconst id = fields.shift();\n\t\tif (!id || !idRegex.test(id)) {\n\t\t\tthrow new TypeError(`id must satisfy ${idRegex}`);\n\t\t}\n\n\t\tlet version: number | undefined;\n\t\t// Parse Version\n\t\tif (fields[0] && versionRegex.test(fields[0])) {\n\t\t\tconst versionMatch = fields.shift()?.match(versionRegex);\n\t\t\tversion = versionMatch ? parseInt(versionMatch[1], 10) : undefined;\n\t\t}\n\n\t\tlet hash: Uint8Array | undefined;\n\t\tlet salt: Uint8Array | undefined;\n\t\tif (fields[fields.length - 1] && b64Regex.test(fields[fields.length - 1])) {\n\t\t\tif (fields.length > 1 && b64Regex.test(fields[fields.length - 2])) {\n\t\t\t\t// Parse Hash\n\t\t\t\tconst hashStr = fields.pop();\n\t\t\t\tif (hashStr) hash = fromBase64(hashStr);\n\t\t\t\t// Parse Salt\n\t\t\t\tconst saltStr = fields.pop();\n\t\t\t\tif (saltStr !== undefined) salt = fromBase64(saltStr);\n\t\t\t} else {\n\t\t\t\t// Parse Salt\n\t\t\t\tconst saltStr = fields.pop();\n\t\t\t\tif (saltStr !== undefined) salt = fromBase64(saltStr);\n\t\t\t}\n\t\t}\n\n\t\t// Parse Parameters\n\t\tlet params: Record<string, string | number> | undefined;\n\t\tif (fields.length > 0) {\n\t\t\tconst parstr = fields.pop();\n\t\t\tif (parstr) {\n\t\t\t\tparams = keyValtoObj(parstr);\n\t\t\t\tif (!Object.keys(params).every((p) => nameRegex.test(p))) {\n\t\t\t\t\tthrow new TypeError(`params names must satisfy ${nameRegex}}`);\n\t\t\t\t}\n\n\t\t\t\tconst pv = Object.values(params);\n\t\t\t\tif (!pv.every((v) => valueRegex.test(String(v)))) {\n\t\t\t\t\tthrow new TypeError(`params values must satisfy ${valueRegex}`);\n\t\t\t\t}\n\n\t\t\t\t// Convert Decimal Strings into Numbers\n\t\t\t\tObject.keys(params).forEach((k) => {\n\t\t\t\t\tconst value = params![k];\n\t\t\t\t\tif (typeof value === 'string' && decimalRegex.test(value)) {\n\t\t\t\t\t\tparams![k] = parseInt(value, 10);\n\t\t\t\t\t}\n\t\t\t\t});\n\t\t\t}\n\t\t}\n\n\t\tif (fields.length > 0) {\n\t\t\tthrow new TypeError(`pchstr contains unrecognized fileds: ${fields}`);\n\t\t}\n\n\t\t// Build the output object\n\t\tconst phcobj: DeserializeResult = { id };\n\t\tif (version !== undefined) phcobj.version = version;\n\t\tif (params) phcobj.params = params;\n\t\tif (salt) phcobj.salt = salt;\n\t\tif (hash) phcobj.hash = hash;\n\n\t\treturn phcobj;\n\t}\n}\n"],"names":["ArrayBuffers","PHC","idRegex","nameRegex","valueRegex","b64Regex","decimalRegex","versionRegex","fromBase64","toBase64","isBuffer","v","Uint8Array","objToKeyVal","obj","objectKeys","map","k","join","keyValtoObj","str","split","forEach","ps","pss","length","TypeError","key","shift","undefined","object","Object","keys","objectValues","values","serialize","opts","fields","id","test","push","version","Number","isInteger","params","pk","every","p","toString","value","pv","strpar","salt","hash","phcstr","deserialize","maxf","versionMatch","match","parseInt","hashStr","pop","saltStr","parstr","String","phcobj"],"mappings":"AAAA,SAASA,YAAY,QAAQ,eAAe;UAE3BC;IAChB,+DAA+D;IAE/D,MAAMC,UAAU;IAChB,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E,QAAQ;gBACXnB,SAASzB,YAAY4C;gBACrB,IAAI,CAAChC,OAAOC,IAAI,CAACY,QAAQE,KAAK,CAAC,CAACC,IAAM5C,UAAUoC,IAAI,CAACQ,KAAK;oBACzD,MAAM,IAAIrB,UAAU,CAAC,0BAA0B,EAAEvB,UAAU,CAAC,CAAC;gBAC9D;gBAEA,MAAM+C,KAAKnB,OAAOG,MAAM,CAACU;gBACzB,IAAI,CAACM,GAAGJ,KAAK,CAAC,CAACnC,IAAMP,WAAWmC,IAAI,CAACyB,OAAOrD,MAAM;oBACjD,MAAM,IAAIe,UAAU,CAAC,2BAA2B,EAAEtB,YAAY;gBAC/D;gBAEA,uCAAuC;gBACvC2B,OAAOC,IAAI,CAACY,QAAQtB,OAAO,CAAC,CAACL;oBAC5B,MAAMgC,QAAQL,MAAO,CAAC3B,EAAE;oBACxB,IAAI,OAAOgC,UAAU,YAAY3C,aAAaiC,IAAI,CAACU,QAAQ;wBAC1DL,MAAO,CAAC3B,EAAE,GAAG0C,SAASV,OAAO;oBAC9B;gBACD;YACD;QACD;QAEA,IAAIZ,OAAOZ,MAAM,GAAG,GAAG;YACtB,MAAM,IAAIC,UAAU,CAAC,qCAAqC,EAAEW,QAAQ;QACrE;QAEA,0BAA0B;QAC1B,MAAM4B,SAA4B;YAAE3B;QAAG;QACvC,IAAIG,YAAYZ,WAAWoC,OAAOxB,OAAO,GAAGA;QAC5C,IAAIG,QAAQqB,OAAOrB,MAAM,GAAGA;QAC5B,IAAIQ,MAAMa,OAAOb,IAAI,GAAGA;QACxB,IAAIC,MAAMY,OAAOZ,IAAI,GAAGA;QAExB,OAAOY;IACR;IA5FA;;;;EAIC,OACeV,cAAAA;AAwFjB,GApPiBtD,QAAAA"}
@@ -1 +0,0 @@
1
- {"version":3,"sources":["../../src/password/Password.ts"],"sourcesContent":["import { Errors } from '@wener/utils';\nimport { createPBKDF2PasswordAlgorithm } from './createPBKDF2PasswordAlgorithm';\nimport { PHC } from './PHC';\n\nexport namespace Password {\n\texport interface ParsedPassword {\n\t\tid: string;\n\t\tversion?: number;\n\t\tparams?: Record<string, string | number>;\n\t\tsalt?: Uint8Array;\n\t\thash?: Uint8Array;\n\t}\n\n\ttype PasswordAlgorithmHashOptions = { rounds?: number; salt?: Uint8Array; id?: string };\n\ttype PasswordAlgorithmVerifyOptions = ParsedPassword;\n\texport type PasswordAlgorithm = {\n\t\treadonly name: string;\n\t\treadonly ids?: string[];\n\t\thash(password: string, opts?: PasswordAlgorithmHashOptions): Promise<string>;\n\t\tverify(password: string, hash: string, opts: PasswordAlgorithmVerifyOptions): Promise<boolean>;\n\t};\n\n\tconst Algorithms: Record<string, string | PasswordAlgorithm> = {\n\t\t1: 'md5',\n\t\t'2a': 'bcrypt', // original\n\t\t'2b': 'bcrypt', // February 2014\n\t\t'2x': 'bcrypt', // June 2011\n\t\t'2y': 'bcrypt', // June 2011\n\t\t5: 'sha256',\n\t\t6: 'sha512',\n\t\t7: 'scrypt',\n\t};\n\tlet DefaultAlgorithm: string = '6';\n\n\texport function setDefaultAlgorithm(algorithm: string) {\n\t\tErrors.BadRequest.check(Algorithms[algorithm], `Unknown algorithm ${algorithm}`);\n\t\tDefaultAlgorithm = algorithm;\n\t}\n\n\texport function getDefaultAlgorithm() {\n\t\treturn DefaultAlgorithm;\n\t}\n\n\texport function addAlgorithm(algorithm: PasswordAlgorithm) {\n\t\tAlgorithms[algorithm.name] = algorithm;\n\t\tif (algorithm.ids) {\n\t\t\tfor (const id of algorithm.ids) {\n\t\t\t\tAlgorithms[id] = algorithm;\n\t\t\t}\n\t\t}\n\t}\n\n\taddAlgorithm(createPBKDF2PasswordAlgorithm({ id: 'sha256', digest: 'SHA-256' }));\n\taddAlgorithm(createPBKDF2PasswordAlgorithm({ id: 'sha512', digest: 'SHA-512' }));\n\n\texport async function parse(hash: string) {\n\t\treturn PHC.deserialize(hash);\n\t}\n\n\tfunction resolveAlgorithm(id: string | PasswordAlgorithm): PasswordAlgorithm {\n\t\tlet f = id;\n\t\twhile (typeof f === 'string') {\n\t\t\tf = Algorithms[f];\n\t\t}\n\t\tif (!f) {\n\t\t\tthrow new Error(`Unknown algorithm ${id}`);\n\t\t}\n\t\treturn f;\n\t}\n\n\texport async function check(password: string, hash: string) {\n\t\tlet res = await parse(hash);\n\t\tlet f = resolveAlgorithm(res.id);\n\t\treturn { result: f.verify(password, hash, res), parsed: res };\n\t}\n\n\texport async function verify(password: string, hash: string) {\n\t\tlet res = await parse(hash);\n\t\tlet f = resolveAlgorithm(res.id);\n\t\treturn f.verify(password, hash, res);\n\t}\n\n\texport type PasswordHashOptions = PasswordAlgorithmHashOptions & { algorithm?: string | PasswordAlgorithm };\n\n\texport async function hash(password: string, { algorithm, ...opts }: PasswordHashOptions = {}) {\n\t\tlet f = resolveAlgorithm(algorithm ?? DefaultAlgorithm);\n\t\tlet id = algorithm ?? DefaultAlgorithm;\n\t\ttypeof id !== 'string' && (id = f.name);\n\t\treturn f.hash(password, { id, ...opts });\n\t}\n}\n"],"names":["Errors","createPBKDF2PasswordAlgorithm","PHC","Password","Algorithms","DefaultAlgorithm","setDefaultAlgorithm","algorithm","BadRequest","check","getDefaultAlgorithm","addAlgorithm","name","ids","id","digest","parse","hash","deserialize","resolveAlgorithm","f","Error","password","res","result","verify","parsed","opts"],"mappings":"AAAA,SAASA,MAAM,QAAQ,eAAe;AACtC,SAASC,6BAA6B,QAAQ,kCAAkC;AAChF,SAASC,GAAG,QAAQ,QAAQ;UAEXC;IAkBhB,MAAMC,aAAyD;QAC9D,GAAG;QACH,MAAM;QACN,MAAM;QACN,MAAM;QACN,MAAM;QACN,GAAG;QACH,GAAG;QACH,GAAG;IACJ;IACA,IAAIC,mBAA2B;IAExB,SAASC,oBAAoBC,SAAiB;QACpDP,OAAOQ,UAAU,CAACC,KAAK,CAACL,UAAU,CAACG,UAAU,EAAE,CAAC,kBAAkB,EAAEA,WAAW;QAC/EF,mBAAmBE;IACpB;aAHgBD,sBAAAA;IAKT,SAASI;QACf,OAAOL;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OS,OAAO,YAAaA,CAAAA,KAAKM,EAAER,IAAI,AAAD;QACrC,OAAOQ,EAAEH,IAAI,CAACK,UAAU;YAAER;YAAI,GAAGa,IAAI;QAAC;IACvC;aALsBV,OAAAA;AAMvB,GAtFiBd,aAAAA"}
@@ -1 +0,0 @@
1
- {"version":3,"sources":["../../src/password/createArgon2PasswordAlgorithm.ts"],"sourcesContent":["import { maybeFunction, type MaybeFunction, type MaybePromise } from '@wener/utils';\nimport { Password } from './Password';\n\ntype Provide = {\n\thash: (password: string, options: { salt?: Buffer; raw?: boolean; type?: 0 | 1 | 2 }) => Promise<string>;\n\tverify: (hash: string, password: string) => Promise<boolean>;\n};\n\nexport function createArgon2PasswordAlgorithm({\n\ttype,\n\tprovide = async () => {\n\t\tthrow new Error('Please provide argon2');\n\t\t// const { default: wasm } = await import('argon2-browser/dist/argon2.wasm');\n\t\t// const argon2 = await WebAssembly.instantiateStreaming(fetch(wasm), {\n\t\t// env: {\n\t\t// memoryBase: 0,\n\t\t// tableBase: 0,\n\t\t// memory: new WebAssembly.Memory({ initial: 256 }),\n\t\t// table: new WebAssembly.Table({ initial: 0, element: 'anyfunc' }),\n\t\t// __memory_base: 0,\n\t\t// __table_base: 0,\n\t\t// },\n\t\t// });\n\t\t// console.log(argon2.instance.exports);\n\t\t// const { hash } = argon2.instance.exports as any as typeof import('argon2-browser');\n\t},\n\t// argon2-browser/dist/argon2-bundled.min.js\n\t// import('argon2-browser').then(({ default: { hash, verify } }) => {\n\t// return {\n\t// hash(password, options) {\n\t// return hash({\n\t// pass: password,\n\t// });\n\t// },\n\t// verify(hash, password) {\n\t// return verify({\n\t// pass: password,\n\t// hash: hash,\n\t// })\n\t// .then(() => true)\n\t// .catch(() => false);\n\t// },\n\t// };\n\t// }),\n\t// provide = () => import('argon2'),\n}: {\n\ttype?: 'argon2d' | 'argon2i' | 'argon2id';\n\tprovide?: MaybeFunction<MaybePromise<Provide>>;\n} = {}): Password.PasswordAlgorithm {\n\t// 0=Argon2d, 1=Argon2i, 2=Argon2id\n\tconst toType: Record<string, 0 | 1 | 2 | undefined> = { argon2d: 0, argon2i: 1, argon2id: 2 } as const;\n\n\tlet mod: Provide;\n\tconst resolve = () => {\n\t\tif (mod) return mod;\n\t\treturn Promise.resolve(maybeFunction(provide)).then((v) => (mod = v));\n\t};\n\treturn {\n\t\tname: 'argon2',\n\t\tids: ['argon2i', 'argon2d', 'argon2id'],\n\t\tasync hash(password: string, opts) {\n\t\t\t// const { hash } = await import('argon2');\n\t\t\tconst { hash } = await resolve();\n\t\t\tconst id = opts?.id;\n\t\t\treturn hash(password, {\n\t\t\t\tsalt: opts?.salt ? Buffer.from(opts.salt) : undefined,\n\t\t\t\traw: false,\n\t\t\t\ttype: toType[id || ''] ?? toType[type || ''],\n\t\t\t});\n\t\t},\n\t\tasync verify(password: string, hash: string) {\n\t\t\tconst { verify } = await resolve();\n\t\t\treturn verify(hash, password);\n\t\t},\n\t};\n}\n"],"names":["maybeFunction","createArgon2PasswordAlgorithm","type","provide","Error","toType","argon2d","argon2i","argon2id","mod","resolve","Promise","then","v","name","ids","hash","password","opts","id","salt","Buffer","from","undefined","raw","verify"],"mappings":"AAAA,SAASA,aAAa,QAA+C,eAAe;AAQpF,OAAO,SAASC,8BAA8B,EAC7CC,IAAI,EACJC,UAAU;IACT,MAAM,IAAIC,MAAM;AAChB,6EAA6E;AAC7E,uEAAuE;AACvE,WAAW;AACX,qBAAqB;AACrB,oBAAoB;AACpB,wDAAwD;AACxD,wEAAwE;AACxE,wBAAwB;AACxB,uBAAuB;AACvB,OAAO;AACP,MAAM;AACN,wCAAwC;AACxC,sFAAsF;AACvF,CAAC,EAuBD,GAAG,CAAC,CAAC;IACL,mCAAmC;IACnC,MAAMC,SAAgD;QAAEC,SAAS;QAAGC,SAAS;QAAGC,UAAU;IAAE;IAE5F,IAAIC;IACJ,MAAMC,UAAU;QACf,IAAID,KAAK,OAAOA;QAChB,OAAOE,QAAQD,OAAO,CAACV,cAAcG,UAAUS,IAAI,CAAC,CAACC,IAAOJ,MAAMI;IACnE;IACA,OAAO;QACNC,MAAM;QACNC,KAAK;YAAC;YAAW;YAAW;SAAW;QACvC,MAAMC,MAAKC,QAAgB,EAAEC,IAAI;YAChC,2CAA2C;YAC3C,MAAM,EAAEF,IAAI,EAAE,GAAG,MAAMN;YACvB,MAAMS,KAAKD,MAAMC;YACjB,OAAOH,KAAKC,UAAU;gBACrBG,MAAMF,MAAME,OAAOC,OAAOC,IAAI,CAACJ,KAAKE,IAAI,IAAIG;gBAC5CC,KAAK;gBACLtB,MAAMG,MAAM,CAACc,MAAM,GAAG,IAAId,MAAM,CAACH,QAAQ,GAAG;YAC7C;QACD;QACA,MAAMuB,QAAOR,QAAgB,EAAED,IAAY;YAC1C,MAAM,EAAES,MAAM,EAAE,GAAG,MAAMf;YACzB,OAAOe,OAAOT,MAAMC;QACrB;IACD;AACD"}
@@ -1 +0,0 @@
1
- {"version":3,"sources":["../../src/password/createBase64PasswordAlgorithm.ts"],"sourcesContent":["import { ArrayBuffers } from '@wener/utils';\nimport { Password } from './Password';\n\nexport function createBase64PasswordAlgorithm({ id = 'base64' }: { id?: string } = {}): Password.PasswordAlgorithm {\n\treturn {\n\t\tname: id,\n\t\tasync hash(password: string) {\n\t\t\treturn `$${id}$$${ArrayBuffers.toBase64(password).replace(/=/g, '')}`;\n\t\t},\n\t\tasync verify(password: string, hash: string, opts) {\n\t\t\treturn Boolean(opts.hash) && ArrayBuffers.toString(opts.hash!) === password;\n\t\t},\n\t};\n}\n"],"names":["ArrayBuffers","createBase64PasswordAlgorithm","id","name","hash","password","toBase64","replace","verify","opts","Boolean","toString"],"mappings":"AAAA,SAASA,YAAY,QAAQ,eAAe;AAG5C,OAAO,SAASC,8BAA8B,EAAEC,KAAK,QAAQ,EAAmB,GAAG,CAAC,CAAC;IACpF,OAAO;QACNC,MAAMD;QACN,MAAME,MAAKC,QAAgB;YAC1B,OAAO,CAAC,CAAC,EAAEH,GAAG,EAAE,EAAEF,aAAaM,QAAQ,CAACD,UAAUE,OAAO,CAAC,MAAM,KAAK;QACtE;QACA,MAAMC,QAAOH,QAAgB,EAAED,IAAY,EAAEK,IAAI;YAChD,OAAOC,QAAQD,KAAKL,IAAI,KAAKJ,aAAaW,QAAQ,CAACF,KAAKL,IAAI,MAAOC;QACpE;IACD;AACD"}
@@ -1 +0,0 @@
1
- {"version":3,"sources":["../../src/password/createBcryptPasswordAlgorithm.ts"],"sourcesContent":["import type { MaybePromise } from '@wener/utils';\nimport { Password } from './Password';\n\ntype ProviderType = () => MaybePromise<{\n\thash: (password: string, rounds: number | string) => Promise<string>;\n\tcompare: (password: string, hash: string) => Promise<boolean>;\n}>;\n\nexport function createBcryptPasswordAlgorithm({\n\t// provider = () => import('bcrypt').then((v) => v.default),\n\tprovider = () => import('bcryptjs').then((v) => v.default),\n}: { provider?: ProviderType } = {}): Password.PasswordAlgorithm {\n\t// bcrypt or bcryptjs\n\treturn {\n\t\tname: 'bcrypt',\n\t\tasync hash(password: string, opts) {\n\t\t\tconst { hash } = await provider();\n\t\t\treturn hash(password, opts?.rounds ?? 10);\n\t\t},\n\t\tasync verify(password: string, hash: string) {\n\t\t\tconst { compare } = await provider();\n\t\t\tif (hash.startsWith('$2y$')) {\n\t\t\t\thash = hash.replace(/^\\$2y\\$/, '$2a$');\n\t\t\t}\n\t\t\treturn compare(password, hash);\n\t\t},\n\t};\n}\n"],"names":["createBcryptPasswordAlgorithm","provider","then","v","default","name","hash","password","opts","rounds","verify","compare","startsWith","replace"],"mappings":"AAQA,OAAO,SAASA,8BAA8B,EAC7C,4DAA4D;AAC5DC,WAAW,IAAM,MAAM,CAAC,YAAYC,IAAI,CAAC,CAACC,IAAMA,EAAEC,OAAO,CAAC,EAC7B,GAAG,CAAC,CAAC;IAClC,qBAAqB;IACrB,OAAO;QACNC,MAAM;QACN,MAAMC,MAAKC,QAAgB,EAAEC,IAAI;YAChC,MAAM,EAAEF,IAAI,EAAE,GAAG,MAAML;YACvB,OAAOK,KAAKC,UAAUC,MAAMC,UAAU;QACvC;QACA,MAAMC,QAAOH,QAAgB,EAAED,IAAY;YAC1C,MAAM,EAAEK,OAAO,EAAE,GAAG,MAAMV;YAC1B,IAAIK,KAAKM,UAAU,CAAC,SAAS;gBAC5BN,OAAOA,KAAKO,OAAO,CAAC,WAAW;YAChC;YACA,OAAOF,QAAQJ,UAAUD;QAC1B;IACD;AACD"}
@@ -1 +0,0 @@
1
- {"version":3,"sources":["../../src/password/createPBKDF2PasswordAlgorithm.ts"],"sourcesContent":["import { Errors } from '@wener/utils';\nimport { Password } from './Password';\nimport { PHC } from './PHC';\n\nexport function createPBKDF2PasswordAlgorithm({\n\tid,\n\tdigest,\n\titerations = 100000,\n\tsaltlen = 16,\n\tkeylen = digest === 'SHA-256' ? 32 : 64,\n}: {\n\tid: string;\n\tdigest: 'SHA-256' | 'SHA-512';\n\titerations?: number;\n\tkeylen?: number;\n\tsaltlen?: number;\n}): Password.PasswordAlgorithm {\n\treturn {\n\t\tname: id,\n\t\tasync hash(password: string, opts) {\n\t\t\tlet salt: Uint8Array;\n\n\t\t\tif (opts?.salt) {\n\t\t\t\tsalt = opts.salt;\n\t\t\t} else {\n\t\t\t\tsalt = new Uint8Array(saltlen);\n\t\t\t\tcrypto.getRandomValues(salt);\n\t\t\t}\n\n\t\t\tconst rounds = opts?.rounds ?? iterations;\n\n\t\t\tlet key = await crypto.subtle.importKey('raw', new TextEncoder().encode(password), 'PBKDF2', false, [\n\t\t\t\t'deriveBits',\n\t\t\t]);\n\t\t\tlet hash = await crypto.subtle.deriveBits(\n\t\t\t\t{ name: 'PBKDF2', iterations: rounds, salt, hash: digest },\n\t\t\t\tkey,\n\t\t\t\tkeylen * 8,\n\t\t\t);\n\t\t\treturn PHC.serialize({ id: opts?.id ?? id, params: { rounds }, salt, hash: new Uint8Array(hash) });\n\t\t},\n\t\tasync verify(password: string, _: string, opts) {\n\t\t\tconst rounds = opts?.params?.rounds ?? iterations;\n\t\t\tconst salt = opts.salt;\n\t\t\tconst storedHash = opts.hash;\n\t\t\tErrors.BadRequest.check(typeof rounds === 'number', 'Invalid rounds');\n\t\t\tErrors.BadRequest.check(salt instanceof Uint8Array, 'Invalid salt');\n\t\t\tErrors.BadRequest.check(storedHash instanceof Uint8Array, 'Invalid hash');\n\n\t\t\tlet key = await crypto.subtle.importKey('raw', new TextEncoder().encode(password), 'PBKDF2', false, [\n\t\t\t\t'deriveBits',\n\t\t\t]);\n\t\t\tlet hash = await crypto.subtle.deriveBits(\n\t\t\t\t{ name: 'PBKDF2', iterations: rounds, salt, hash: digest },\n\t\t\t\tkey,\n\t\t\t\tstoredHash.length * 8,\n\t\t\t);\n\t\t\treturn new Uint8Array(hash).every((v, i) => v === storedHash![i]);\n\t\t},\n\t};\n}\n"],"names":["Errors","PHC","createPBKDF2PasswordAlgorithm","id","digest","iterations","saltlen","keylen","name","hash","password","opts","salt","Uint8Array","crypto","getRandomValues","rounds","key","subtle","importKey","TextEncoder","encode","deriveBits","serialize","params","verify","_","storedHash","BadRequest","check","length","every","v","i"],"mappings":"AAAA,SAASA,MAAM,QAAQ,eAAe;AAEtC,SAASC,GAAG,QAAQ,QAAQ;AAE5B,OAAO,SAASC,8BAA8B,EAC7CC,EAAE,EACFC,MAAM,EACNC,aAAa,MAAM,EACnBC,UAAU,EAAE,EACZC,SAASH,WAAW,YAAY,KAAK,EAAE,EAOvC;IACA,OAAO;QACNI,MAAML;QACN,MAAMM,MAAKC,QAAgB,EAAEC,IAAI;YAChC,IAAIC;YAEJ,IAAID,MAAMC,MAAM;gBACfA,OAAOD,KAAKC,IAAI;YACjB,OAAO;gBACNA,OAAO,IAAIC,WAAWP;gBACtBQ,OAAOC,eAAe,CAACH;YACxB;YAEA,MAAMI,SAASL,MAAMK,UAAUX;YAE/B,IAAIY,MAAM,MAAMH,OAAOI,MAAM,CAACC,SAAS,CAAC,OAAO,IAAIC,cAAcC,MAAM,CAACX,WAAW,UAAU,OAAO;gBACnG;aACA;YACD,IAAID,OAAO,MAAMK,OAAOI,MAAM,CAACI,UAAU,CACxC;gBAAEd,MAAM;gBAAUH,YAAYW;gBAAQJ;gBAAMH,MAAML;YAAO,GACzDa,KACAV,SAAS;YAEV,OAAON,IAAIsB,SAAS,CAAC;gBAAEpB,IAAIQ,MAAMR,MAAMA;gBAAIqB,QAAQ;oBAAER;gBAAO;gBAAGJ;gBAAMH,MAAM,IAAII,WAAWJ;YAAM;QACjG;QACA,MAAMgB,QAAOf,QAAgB,EAAEgB,CAAS,EAAEf,IAAI;YAC7C,MAAMK,SAASL,MAAMa,QAAQR,UAAUX;YACvC,MAAMO,OAAOD,KAAKC,IAAI;YACtB,MAAMe,aAAahB,KAAKF,IAAI;YAC5BT,OAAO4B,UAAU,CAACC,KAAK,CAAC,OAAOb,WAAW,UAAU;YACpDhB,OAAO4B,UAAU,CAACC,KAAK,CAACjB,gBAAgBC,YAAY;YACpDb,OAAO4B,UAAU,CAACC,KAAK,CAACF,sBAAsBd,YAAY;YAE1D,IAAII,MAAM,MAAMH,OAAOI,MAAM,CAACC,SAAS,CAAC,OAAO,IAAIC,cAAcC,MAAM,CAACX,WAAW,UAAU,OAAO;gBACnG;aACA;YACD,IAAID,OAAO,MAAMK,OAAOI,MAAM,CAACI,UAAU,CACxC;gBAAEd,MAAM;gBAAUH,YAAYW;gBAAQJ;gBAAMH,MAAML;YAAO,GACzDa,KACAU,WAAWG,MAAM,GAAG;YAErB,OAAO,IAAIjB,WAAWJ,MAAMsB,KAAK,CAAC,CAACC,GAAGC,IAAMD,MAAML,UAAW,CAACM,EAAE;QACjE;IACD;AACD"}
@@ -1 +0,0 @@
1
- {"version":3,"sources":["../../src/password/createScryptPasswordAlgorithm.ts"],"sourcesContent":["import { randomBytes, scrypt, timingSafeEqual } from 'node:crypto';\nimport { Errors } from '@wener/utils';\nimport { Password } from './Password';\nimport { PHC } from './PHC';\n\nexport function createScryptPasswordAlgorithm(\n\toptions: {\n\t\tid?: string;\n\t\tcost?: number;\n\t\tblocksize?: number;\n\t\tparallelism?: number;\n\t\tsaltlen?: number;\n\t\tkeylen?: number;\n\t} = {},\n): Password.PasswordAlgorithm {\n\tlet id = options.id || 'scrypt';\n\toptions.cost ||= Math.pow(2, 14);\n\toptions.blocksize ||= 8;\n\toptions.parallelism ||= 1;\n\toptions.saltlen ||= 16;\n\toptions.keylen ||= 32;\n\treturn {\n\t\tname: id,\n\t\tasync hash(password: string, opts): Promise<string> {\n\t\t\tconst salt = opts?.salt || randomBytes(options.saltlen!);\n\t\t\treturn new Promise((resolve, reject) => {\n\t\t\t\tlet N = options.cost!;\n\t\t\t\tlet r = options.blocksize!;\n\t\t\t\tlet p = options.parallelism!;\n\t\t\t\tscrypt(password, salt, options.keylen!, { N, r, p }, (err, derivedKey) => {\n\t\t\t\t\tif (err) return reject(err);\n\n\t\t\t\t\tresolve(PHC.serialize({ id: opts?.id ?? id, params: { ln: N!, r: r!, p: p! }, salt, hash: derivedKey }));\n\t\t\t\t});\n\t\t\t});\n\t\t},\n\n\t\tasync verify(password: string, hash: string, opts): Promise<boolean> {\n\t\t\ttry {\n\t\t\t\tconst salt = Errors.BadRequest.require(opts.salt);\n\t\t\t\tconst storedHash = Errors.BadRequest.require(opts.hash);\n\n\t\t\t\tconst N = parseInt(opts.params?.ln as string, 10);\n\t\t\t\tconst r = parseInt(opts.params?.r as string, 10);\n\t\t\t\tconst p = parseInt(opts.params?.p as string, 10);\n\t\t\t\tconst keylen = storedHash.length;\n\n\t\t\t\treturn new Promise((resolve, reject) => {\n\t\t\t\t\tscrypt(password, salt, keylen, { N, r, p }, (err, derivedKey) => {\n\t\t\t\t\t\tif (err) return reject(err);\n\n\t\t\t\t\t\tconst isMatch = timingSafeEqual(derivedKey, storedHash);\n\t\t\t\t\t\tresolve(isMatch);\n\t\t\t\t\t});\n\t\t\t\t});\n\t\t\t} catch (error) {\n\t\t\t\treturn Promise.resolve(false);\n\t\t\t}\n\t\t},\n\t};\n}\n"],"names":["randomBytes","scrypt","timingSafeEqual","Errors","PHC","createScryptPasswordAlgorithm","options","id","cost","Math","pow","blocksize","parallelism","saltlen","keylen","name","hash","password","opts","salt","Promise","resolve","reject","N","r","p","err","derivedKey","serialize","params","ln","verify","BadRequest","require","storedHash","parseInt","length","isMatch","error"],"mappings":"AAAA,SAASA,WAAW,EAAEC,MAAM,EAAEC,eAAe,QAAQ,cAAc;AACnE,SAASC,MAAM,QAAQ,eAAe;AAEtC,SAASC,GAAG,QAAQ,QAAQ;AAE5B,OAAO,SAASC,8BACfC,UAOI,CAAC,CAAC;IAEN,IAAIC,KAAKD,QAAQC,EAAE,IAAI;IACvBD,QAAQE,IAAI,KAAKC,KAAKC,GAAG,CAAC,GAAG;IAC7BJ,QAAQK,SAAS,KAAK;IACtBL,QAAQM,WAAW,KAAK;IACxBN,QAAQO,OAAO,KAAK;IACpBP,QAAQQ,MAAM,KAAK;IACnB,OAAO;QACNC,MAAMR;QACN,MAAMS,MAAKC,QAAgB,EAAEC,IAAI;YAChC,MAAMC,OAAOD,MAAMC,QAAQnB,YAAYM,QAAQO,OAAO;YACtD,OAAO,IAAIO,QAAQ,CAACC,SAASC;gBAC5B,IAAIC,IAAIjB,QAAQE,IAAI;gBACpB,IAAIgB,IAAIlB,QAAQK,SAAS;gBACzB,IAAIc,IAAInB,QAAQM,WAAW;gBAC3BX,OAAOgB,UAAUE,MAAMb,QAAQQ,MAAM,EAAG;oBAAES;oBAAGC;oBAAGC;gBAAE,GAAG,CAACC,KAAKC;oBAC1D,IAAID,KAAK,OAAOJ,OAAOI;oBAEvBL,QAAQjB,IAAIwB,SAAS,CAAC;wBAAErB,IAAIW,MAAMX,MAAMA;wBAAIsB,QAAQ;4BAAEC,IAAIP;4BAAIC,GAAGA;4BAAIC,GAAGA;wBAAG;wBAAGN;wBAAMH,MAAMW;oBAAW;gBACtG;YACD;QACD;QAEA,MAAMI,QAAOd,QAAgB,EAAED,IAAY,EAAEE,IAAI;YAChD,IAAI;gBACH,MAAMC,OAAOhB,OAAO6B,UAAU,CAACC,OAAO,CAACf,KAAKC,IAAI;gBAChD,MAAMe,aAAa/B,OAAO6B,UAAU,CAACC,OAAO,CAACf,KAAKF,IAAI;gBAEtD,MAAMO,IAAIY,SAASjB,KAAKW,MAAM,EAAEC,IAAc;gBAC9C,MAAMN,IAAIW,SAASjB,KAAKW,MAAM,EAAEL,GAAa;gBAC7C,MAAMC,IAAIU,SAASjB,KAAKW,MAAM,EAAEJ,GAAa;gBAC7C,MAAMX,SAASoB,WAAWE,MAAM;gBAEhC,OAAO,IAAIhB,QAAQ,CAACC,SAASC;oBAC5BrB,OAAOgB,UAAUE,MAAML,QAAQ;wBAAES;wBAAGC;wBAAGC;oBAAE,GAAG,CAACC,KAAKC;wBACjD,IAAID,KAAK,OAAOJ,OAAOI;wBAEvB,MAAMW,UAAUnC,gBAAgByB,YAAYO;wBAC5Cb,QAAQgB;oBACT;gBACD;YACD,EAAE,OAAOC,OAAO;gBACf,OAAOlB,QAAQC,OAAO,CAAC;YACxB;QACD;IACD;AACD"}
@@ -1 +0,0 @@
1
- {"version":3,"sources":["../../src/password/index.ts"],"sourcesContent":["export { PHC } from './PHC';\nexport { Password } from './Password';\nexport { createArgon2PasswordAlgorithm } from './createArgon2PasswordAlgorithm';\nexport { createBase64PasswordAlgorithm } from './createBase64PasswordAlgorithm';\nexport { createBcryptPasswordAlgorithm } from './createBcryptPasswordAlgorithm';\n"],"names":["PHC","Password","createArgon2PasswordAlgorithm","createBase64PasswordAlgorithm","createBcryptPasswordAlgorithm"],"mappings":"AAAA,SAASA,GAAG,QAAQ,QAAQ;AAC5B,SAASC,QAAQ,QAAQ,aAAa;AACtC,SAASC,6BAA6B,QAAQ,kCAAkC;AAChF,SAASC,6BAA6B,QAAQ,kCAAkC;AAChF,SAASC,6BAA6B,QAAQ,kCAAkC"}
@@ -1 +0,0 @@
1
- {"version":3,"sources":["../../../src/password/server/index.ts"],"sourcesContent":["export { createScryptPasswordAlgorithm } from '../createScryptPasswordAlgorithm';\n"],"names":["createScryptPasswordAlgorithm"],"mappings":"AAAA,SAASA,6BAA6B,QAAQ,mCAAmC"}
@@ -1 +0,0 @@
1
- {"version":3,"sources":["../../src/search/AdvanceSearch.ts"],"sourcesContent":["import { formatAdvanceSearch } from './formatAdvanceSearch';\nimport { optimizeAdvanceSearch } from './optimizeAdvanceSearch';\nimport { parseAdvanceSearch } from './parseAdvanceSearch';\nimport type * as types from './types';\n\nexport namespace AdvanceSearch {\n\texport type Exprs = types.Exprs;\n\texport type Expr = types.Expr;\n\texport type Value = types.Value;\n\n\texport const parse = parseAdvanceSearch;\n\texport const format = formatAdvanceSearch;\n\texport const optimize = optimizeAdvanceSearch;\n}\n"],"names":["formatAdvanceSearch","optimizeAdvanceSearch","parseAdvanceSearch","AdvanceSearch","parse","format","optimize"],"mappings":"AAAA,SAASA,mBAAmB,QAAQ,wBAAwB;AAC5D,SAASC,qBAAqB,QAAQ,0BAA0B;AAChE,SAASC,kBAAkB,QAAQ,uBAAuB;UAGzCC;kBAKHC,QAAQF;kBACRG,SAASL;kBACTM,WAAWL;AACzB,GARiBE,kBAAAA"}
@@ -1 +0,0 @@
1
- {"version":3,"sources":["../../src/search/formatAdvanceSearch.ts"],"sourcesContent":["import { match } from 'ts-pattern';\nimport { AdvanceSearch } from './AdvanceSearch';\n\nexport function formatAdvanceSearch(input: AdvanceSearch.Expr[]) {\n\tconst OP = { match: ':', eq: ':=', ne: ':!=', gt: ':>', lt: ':<', gte: ':>=', lte: ':<=', range: ':' } as const;\n\n\tconst _exprs = (s: AdvanceSearch.Expr[]): string => {\n\t\treturn s.map(_expr).join(' ');\n\t};\n\tconst _expr = (s: AdvanceSearch.Expr): string => {\n\t\treturn match(s)\n\t\t\t.with({ type: 'keyword' }, ({ value, exact, negative }) => {\n\t\t\t\treturn `${negative ? '-' : ''}${exact ? `\"${value}\"` : value}`;\n\t\t\t})\n\t\t\t.with({ type: 'logical' }, ({ operator, value }) => value.map(_expr).join(` ${operator.toLocaleUpperCase()} `))\n\t\t\t.with({ type: 'not' }, ({ value }) => `NOT ${_expr(value)}`)\n\t\t\t.with({ type: 'compare' }, ({ field, operator, value, negative, mention }) => {\n\t\t\t\treturn `${negative ? '-' : ''}${mention ? '@' : ''}${field}${OP[operator]}${_value(value)}`;\n\t\t\t})\n\t\t\t.with({ type: 'comment' }, ({ value }) => `/* ${value} */`)\n\t\t\t.with({ type: 'parentheses' }, ({ value }) => `(${_exprs(value)})`)\n\t\t\t.exhaustive();\n\t};\n\n\tconst _literal = (s: string | null | number) => {\n\t\tif (typeof s === 'string') {\n\t\t\treturn s.includes(' ') ? `\"${s}\"` : s;\n\t\t}\n\t\treturn JSON.stringify(s);\n\t};\n\tconst _value = (v: AdvanceSearch.Value): string => {\n\t\treturn match(v)\n\t\t\t.with({ type: 'range' }, ({ minimum, maximum, minimumExclusive, maximumExclusive }) => {\n\t\t\t\tif (minimumExclusive === undefined && maximumExclusive === undefined) {\n\t\t\t\t\tlet min = minimum === undefined ? '*' : _value(minimum);\n\t\t\t\t\tlet max = maximum === undefined ? '*' : _value(maximum);\n\t\t\t\t\treturn `${min}..${max}`;\n\t\t\t\t}\n\t\t\t\tlet min = minimum === undefined ? '' : _value(minimum);\n\t\t\t\tlet max = maximum === undefined ? '' : _value(maximum);\n\t\t\t\treturn `${minimumExclusive ? '(' : '['}${min},${max}${maximumExclusive ? ')' : ']'}`;\n\t\t\t})\n\t\t\t.with({ format: 'mention' }, ({ value }) => {\n\t\t\t\treturn `@${value}`;\n\t\t\t})\n\t\t\t.otherwise((value) => {\n\t\t\t\treturn _literal(value.value);\n\t\t\t});\n\t};\n\n\treturn _exprs(input);\n}\n"],"names":["match","formatAdvanceSearch","input","OP","eq","ne","gt","lt","gte","lte","range","_exprs","s","map","_expr","join","with","type","value","exact","negative","operator","toLocaleUpperCase","field","mention","_value","exhaustive","_literal","includes","JSON","stringify","v","minimum","maximum","minimumExclusive","maximumExclusive","undefined","min","max","format","otherwise"],"mappings":"AAAA,SAASA,KAAK,QAAQ,aAAa;AA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,OAAOO,OAAO,CAAC,CAAC,EACjEQ,UAAU;IACb;IAEA,MAAMC,WAAW,CAACf;QACjB,IAAI,OAAOA,MAAM,UAAU;YAC1B,OAAOA,EAAEgB,QAAQ,CAAC,OAAO,CAAC,CAAC,EAAEhB,EAAE,CAAC,CAAC,GAAGA;QACrC;QACA,OAAOiB,KAAKC,SAAS,CAAClB;IACvB;IACA,MAAMa,SAAS,CAACM;QACf,OAAO/B,MAAM+B,GACXf,IAAI,CAAC;YAAEC,MAAM;QAAQ,GAAG,CAAC,EAAEe,OAAO,EAAEC,OAAO,EAAEC,gBAAgB,EAAEC,gBAAgB,EAAE;YACjF,IAAID,qBAAqBE,aAAaD,qBAAqBC,WAAW;gBACrE,IAAIC,MAAML,YAAYI,YAAY,MAAMX,OAAOO;gBAC/C,IAAIM,MAAML,YAAYG,YAAY,MAAMX,OAAOQ;gBAC/C,OAAO,GAAGI,IAAI,EAAE,EAAEC,KAAK;YACxB;YACA,IAAID,MAAML,YAAYI,YAAY,KAAKX,OAAOO;YAC9C,IAAIM,MAAML,YAAYG,YAAY,KAAKX,OAAOQ;YAC9C,OAAO,GAAGC,mBAAmB,MAAM,MAAMG,IAAI,CAAC,EAAEC,MAAMH,mBAAmB,MAAM,KAAK;QACrF,GACCnB,IAAI,CAAC;YAAEuB,QAAQ;QAAU,GAAG,CAAC,EAAErB,KAAK,EAAE;YACtC,OAAO,CAAC,CAAC,EAAEA,OAAO;QACnB,GACCsB,SAAS,CAAC,CAACtB;YACX,OAAOS,SAAST,MAAMA,KAAK;QAC5B;IACF;IAEA,OAAOP,OAAOT;AACf"}
@@ -1 +0,0 @@
1
- {"version":3,"sources":["../../src/search/index.ts"],"sourcesContent":["export { AdvanceSearch } from './AdvanceSearch';\n"],"names":["AdvanceSearch"],"mappings":"AAAA,SAASA,aAAa,QAAQ,kBAAkB"}
@@ -1 +0,0 @@
1
- {"version":3,"sources":["../../src/search/optimizeAdvanceSearch.ts"],"sourcesContent":["import { arrayOfMaybeArray, deepEqual, type MaybeArray } from '@wener/utils';\nimport { match } from 'ts-pattern';\nimport { AdvanceSearch } from './AdvanceSearch';\n\nexport function optimizeAdvanceSearch(expr: AdvanceSearch.Exprs): AdvanceSearch.Exprs {\n\tconst NEG = { eq: 'ne', ne: 'eq', gt: 'lte', lt: 'gte', gte: 'lt', lte: 'gt' } as const;\n\tconst _expr = (e: AdvanceSearch.Expr): MaybeArray<AdvanceSearch.Expr> => {\n\t\t// merge Exprs to AND ?\n\t\treturn (\n\t\t\tmatch(e)\n\t\t\t\t// (EXPR) -> EXPR\n\t\t\t\t// TODO (EXPR EXPR) -> EXPR AND EXPR\n\t\t\t\t.with({ type: 'parentheses' }, (expr) => {\n\t\t\t\t\t// unwrap\n\t\t\t\t\tif (expr.value.length < 2) {\n\t\t\t\t\t\treturn expr.value[0];\n\t\t\t\t\t}\n\t\t\t\t\texpr.value = expr.value.flatMap(_expr);\n\t\t\t\t\treturn expr;\n\t\t\t\t})\n\t\t\t\t.with({ type: 'comment' }, (expr) => {\n\t\t\t\t\t// remove empty comment\n\t\t\t\t\tif (!expr.value.length) {\n\t\t\t\t\t\treturn [];\n\t\t\t\t\t}\n\t\t\t\t\treturn expr;\n\t\t\t\t})\n\t\t\t\t// NOT\n\t\t\t\t.with({ type: 'not' }, (expr) => {\n\t\t\t\t\tlet out = arrayOfMaybeArray(_expr(expr.value));\n\t\t\t\t\tif (!out.length) {\n\t\t\t\t\t\treturn [];\n\t\t\t\t\t} else if (out.length === 1) {\n\t\t\t\t\t\texpr.value = out[0];\n\t\t\t\t\t} else {\n\t\t\t\t\t\tthrow new Error('NOT should have only one value');\n\t\t\t\t\t}\n\t\t\t\t\treturn (\n\t\t\t\t\t\tmatch(expr.value)\n\t\t\t\t\t\t\t// NOT NOT EXPR -> EXPR\n\t\t\t\t\t\t\t.with({ type: 'not' }, (expr) => expr.value)\n\t\t\t\t\t\t\t// NOT EXPR -> -EXPR\n\t\t\t\t\t\t\t.with({ type: 'compare' }, (expr) => {\n\t\t\t\t\t\t\t\treturn { ...expr, negative: !expr.negative };\n\t\t\t\t\t\t\t})\n\t\t\t\t\t\t\t.with({ type: 'keyword' }, (expr) => {\n\t\t\t\t\t\t\t\treturn { ...expr, negative: !expr.negative };\n\t\t\t\t\t\t\t})\n\t\t\t\t\t\t\t.otherwise(() => expr)\n\t\t\t\t\t);\n\t\t\t\t})\n\t\t\t\t.with({ type: 'compare' }, (expr) => {\n\t\t\t\t\t// negative by swap operator\n\t\t\t\t\tif (expr.negative) {\n\t\t\t\t\t\tconst ne = NEG[expr.operator as keyof typeof NEG];\n\t\t\t\t\t\tif (ne) {\n\t\t\t\t\t\t\texpr.operator = ne;\n\t\t\t\t\t\t\texpr.negative = false;\n\t\t\t\t\t\t}\n\t\t\t\t\t}\n\t\t\t\t\tif (expr.operator === 'range') {\n\t\t\t\t\t}\n\t\t\t\t\treturn expr;\n\t\t\t\t})\n\t\t\t\t.otherwise((e) => e)\n\t\t);\n\t};\n\n\tlet last = expr;\n\twhile (true) {\n\t\tlet next = structuredClone(last).flatMap(_expr);\n\t\tif (deepEqual(last, next)) {\n\t\t\treturn last;\n\t\t}\n\t\tlast = next;\n\t}\n}\n"],"names":["arrayOfMaybeArray","deepEqual","match","optimizeAdvanceSearch","expr","NEG","eq","ne","gt","lt","gte","lte","_expr","e","with","type","value","length","flatMap","out","Error","negative","otherwise","operator","last","next","structuredClone"],"mappings":"AAAA,SAASA,iBAAiB,EAAEC,SAAS,QAAyB,eAAe;AAC7E,SAASC,KAAK,QAAQ,aAAa;AAGnC,OAAO,SAASC,sBAAsBC,IAAyB;IAC9D,MAAMC,MAAM;QAAEC,IAAI;QAAMC,IAAI;QAAMC,IAAI;QAAOC,IAAI;QAAOC,KAAK;QAAMC,KAAK;IAAK;IAC7E,MAAMC,QAAQ,CAACC;QACd,uBAAuB;QACvB,OACCX,MAAMW,EACL,iBAAiB;QACjB,oCAAoC;SACnCC,IAAI,CAAC;YAAEC,MAAM;QAAc,GAAG,CAACX;YA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AAQ,CAAqB;gBACjD,IAAIhB,IAAI;oBACPH,KAAKmB,QAAQ,GAAGhB;oBAChBH,KAAKiB,QAAQ,GAAG;gBACjB;YACD;YACA,IAAIjB,KAAKmB,QAAQ,KAAK,SAAS,CAC/B;YACA,OAAOnB;QACR,GACCkB,SAAS,CAAC,CAACT,IAAMA;IAErB;IAEA,IAAIW,OAAOpB;IACX,MAAO,KAAM;QACZ,IAAIqB,OAAOC,gBAAgBF,MAAMN,OAAO,CAACN;QACzC,IAAIX,UAAUuB,MAAMC,OAAO;YAC1B,OAAOD;QACR;QACAA,OAAOC;IACR;AACD"}
@@ -1 +0,0 @@
1
- {"version":3,"sources":["../../src/search/parseAdvanceSearch.ts"],"sourcesContent":["import { AdvanceSearch } from './AdvanceSearch';\nimport { parse } from './parser';\n\nexport function parseAdvanceSearch(s: string | undefined | null): AdvanceSearch.Expr[] {\n\ts = s?.trim();\n\tif (!s) {\n\t\treturn [];\n\t}\n\n\t// no Logical, no Compare, no Quote, no Comment\n\tif (!/AND|OR|NOT|[-\"():]|\\/\\*/.test(s)) {\n\t\t// fast path\n\t\treturn s\n\t\t\t.split(/\\s+/)\n\t\t\t.map((v) => v.trim())\n\t\t\t.filter(Boolean)\n\t\t\t.map((v) => {\n\t\t\t\treturn { type: 'keyword', value: v };\n\t\t\t});\n\t}\n\n\treturn parse(s);\n}\n"],"names":["parse","parseAdvanceSearch","s","trim","test","split","map","v","filter","Boolean","type","value"],"mappings":"AACA,SAASA,KAAK,QAAQ,cAAW;AAEjC,OAAO,SAASC,mBAAmBC,CAA4B;IAC9DA,IAAIA,GAAGC;IACP,IAAI,CAACD,GAAG;QACP,OAAO,EAAE;IACV;IAEA,+CAA+C;IAC/C,IAAI,CAAC,0BAA0BE,IAAI,CAACF,IAAI;QACvC,YAAY;QACZ,OAAOA,EACLG,KAAK,CAAC,OACNC,GAAG,CAAC,CAACC,IAAMA,EAAEJ,IAAI,IACjBK,MAAM,CAACC,SACPH,GAAG,CAAC,CAACC;YACL,OAAO;gBAAEG,MAAM;gBAAWC,OAAOJ;YAAE;QACpC;IACF;IAEA,OAAOP,MAAME;AACd"}
@@ -1 +0,0 @@
1
- {"version":3,"sources":["../../src/search/parser.d.ts"],"sourcesContent":["export function parse(input: string, options?: ParseOptions): any;\n\nexport interface ParseOptions {\n\tgrammarSource?: string;\n\tstartRule?: string;\n\n\t[k: string]: any;\n}\n"],"names":[],"mappings":"AAEA,WAKC"}