@wener/common 1.0.5 → 2.0.2
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/lib/cn/ChineseResidentIdNo.js +41 -0
- package/lib/cn/ChineseResidentIdNo.mod.js +1 -0
- package/lib/cn/ChineseResidentIdNo.test.js +22 -0
- package/lib/cn/DivisionCode.js +214 -280
- package/lib/cn/DivisionCode.mod.js +1 -0
- package/lib/cn/DivisionCode.test.js +134 -0
- package/lib/cn/Mod11.js +86 -0
- package/lib/cn/Mod31.js +98 -0
- package/lib/cn/UnifiedSocialCreditCode.js +130 -109
- package/lib/cn/UnifiedSocialCreditCode.mod.js +1 -0
- package/lib/cn/UnifiedSocialCreditCode.test.js +16 -0
- package/lib/cn/index.js +1 -4
- package/lib/cn/mod.js +6 -0
- package/lib/cn/types.d.js +0 -2
- package/lib/consola/createStandardConsolaReporter.js +6 -6
- package/lib/consola/formatLogObject.js +147 -34
- package/lib/consola/index.js +0 -1
- package/lib/data/formatSort.js +5 -6
- package/lib/data/formatSort.test.js +34 -0
- package/lib/data/index.js +0 -1
- package/lib/data/maybeNumber.js +11 -5
- package/lib/data/parseSort.js +28 -22
- package/lib/data/parseSort.test.js +188 -0
- package/lib/data/resolvePagination.js +27 -16
- package/lib/data/resolvePagination.test.js +232 -0
- package/lib/data/types.d.js +0 -2
- package/lib/dayjs/dayjs.js +38 -0
- package/lib/dayjs/formatDuration.js +58 -0
- package/lib/dayjs/formatDuration.test.js +90 -0
- package/lib/dayjs/index.js +3 -0
- package/lib/dayjs/parseDuration.js +32 -0
- package/lib/decimal/index.js +1 -0
- package/lib/decimal/parseDecimal.js +13 -0
- package/lib/foundation/schema/SexType.js +14 -0
- package/lib/foundation/schema/index.js +1 -0
- package/lib/foundation/schema/parseSexType.js +18 -0
- package/lib/foundation/schema/types.js +5 -0
- package/lib/index.js +0 -1
- package/lib/jsonschema/JsonSchema.js +78 -52
- package/lib/jsonschema/JsonSchema.test.js +137 -0
- package/lib/jsonschema/index.js +0 -1
- package/lib/jsonschema/types.d.js +5 -3
- package/lib/meta/defineFileType.js +103 -20
- package/lib/meta/defineInit.js +250 -31
- package/lib/meta/defineMetadata.js +140 -24
- package/lib/meta/defineMetadata.test.js +13 -0
- package/lib/meta/index.js +0 -1
- package/lib/password/PHC.js +87 -63
- package/lib/password/PHC.test.js +539 -0
- package/lib/password/Password.js +295 -30
- package/lib/password/Password.test.js +362 -0
- package/lib/password/createArgon2PasswordAlgorithm.js +191 -35
- package/lib/password/createBase64PasswordAlgorithm.js +141 -8
- package/lib/password/createBcryptPasswordAlgorithm.js +168 -13
- package/lib/password/createPBKDF2PasswordAlgorithm.js +228 -46
- package/lib/password/createScryptPasswordAlgorithm.js +211 -55
- package/lib/password/index.js +0 -1
- package/lib/password/server/index.js +0 -1
- package/lib/resource/Identifiable.js +1 -0
- package/lib/resource/ListQuery.js +119 -0
- package/lib/resource/getTitleOfResource.js +10 -0
- package/lib/resource/index.js +2 -0
- package/lib/resource/schema/AnyResourceSchema.js +89 -0
- package/lib/resource/schema/BaseResourceSchema.js +29 -0
- package/lib/resource/schema/ResourceActionType.js +118 -0
- package/lib/resource/schema/ResourceStatus.js +93 -0
- package/lib/resource/schema/ResourceType.js +24 -0
- package/lib/resource/schema/index.js +5 -0
- package/lib/resource/schema/types.js +89 -0
- package/lib/resource/schema/types.test.js +14 -0
- package/lib/schema/SchemaRegistry.js +45 -0
- package/lib/schema/SchemaRegistry.mod.js +2 -0
- package/lib/schema/TypeSchema.d.js +1 -0
- package/lib/schema/createSchemaData.js +173 -0
- package/lib/schema/findJsonSchemaByPath.js +49 -0
- package/lib/schema/getSchemaCache.js +11 -0
- package/lib/schema/getSchemaOptions.js +24 -0
- package/lib/schema/index.js +6 -0
- package/lib/schema/toJsonSchema.js +441 -0
- package/lib/schema/toJsonSchema.test.js +27 -0
- package/lib/schema/validate.js +124 -0
- package/lib/tools/generateSchema.js +197 -39
- package/lib/tools/renderJsonSchemaToMarkdownDoc.js +143 -55
- package/lib/utils/getEstimateProcessTime.js +20 -0
- package/lib/utils/index.js +1 -0
- package/package.json +38 -17
- package/src/cn/ChineseResidentIdNo.mod.ts +7 -0
- package/src/cn/ChineseResidentIdNo.test.ts +18 -0
- package/src/cn/ChineseResidentIdNo.ts +66 -0
- package/src/cn/DivisionCode.mod.ts +7 -0
- package/src/cn/DivisionCode.test.ts +3 -13
- package/src/cn/DivisionCode.ts +132 -195
- package/src/cn/{Mod11Checksum.ts → Mod11.ts} +3 -1
- package/src/cn/{Mod31Checksum.ts → Mod31.ts} +2 -0
- package/src/cn/UnifiedSocialCreditCode.mod.ts +7 -0
- package/src/cn/UnifiedSocialCreditCode.test.ts +2 -2
- package/src/cn/UnifiedSocialCreditCode.ts +105 -125
- package/src/cn/__snapshots__/ChineseResidentIdNo.test.ts.snap +14 -0
- package/src/cn/__snapshots__/UnifiedSocialCreditCode.test.ts.snap +18 -12
- package/src/cn/index.ts +1 -3
- package/src/cn/mod.ts +3 -0
- package/src/consola/formatLogObject.ts +12 -4
- package/src/data/maybeNumber.ts +5 -1
- package/src/data/resolvePagination.test.ts +1 -1
- package/src/data/resolvePagination.ts +18 -7
- package/src/data/types.d.ts +12 -0
- package/src/dayjs/dayjs.ts +40 -0
- package/src/dayjs/formatDuration.test.ts +14 -0
- package/src/dayjs/formatDuration.ts +86 -0
- package/src/dayjs/index.ts +3 -0
- package/src/dayjs/parseDuration.ts +40 -0
- package/src/decimal/index.ts +1 -0
- package/src/decimal/parseDecimal.ts +16 -0
- package/src/foundation/schema/SexType.ts +21 -0
- package/src/foundation/schema/index.ts +1 -0
- package/src/foundation/schema/parseSexType.ts +19 -0
- package/src/foundation/schema/types.ts +8 -0
- package/src/jsonschema/JsonSchema.test.ts +17 -0
- package/src/jsonschema/JsonSchema.ts +2 -2
- package/src/jsonschema/types.d.ts +63 -12
- package/src/password/Password.ts +2 -2
- package/src/resource/Identifiable.ts +3 -0
- package/src/resource/ListQuery.ts +53 -0
- package/src/resource/getTitleOfResource.tsx +6 -0
- package/src/resource/index.ts +4 -0
- package/src/resource/schema/AnyResourceSchema.ts +113 -0
- package/src/resource/schema/BaseResourceSchema.ts +32 -0
- package/src/resource/schema/ResourceActionType.ts +123 -0
- package/src/resource/schema/ResourceStatus.ts +94 -0
- package/src/resource/schema/ResourceType.ts +25 -0
- package/src/resource/schema/index.ts +5 -0
- package/src/resource/schema/types.test.ts +18 -0
- package/src/resource/schema/types.ts +105 -0
- package/src/schema/SchemaRegistry.mod.ts +1 -0
- package/src/schema/SchemaRegistry.ts +46 -0
- package/src/schema/TypeSchema.d.ts +32 -0
- package/src/schema/createSchemaData.ts +81 -0
- package/src/schema/findJsonSchemaByPath.ts +37 -0
- package/src/schema/getSchemaCache.ts +21 -0
- package/src/schema/getSchemaOptions.ts +24 -0
- package/src/schema/index.ts +7 -0
- package/src/schema/toJsonSchema.test.ts +37 -0
- package/src/schema/toJsonSchema.ts +200 -0
- package/src/schema/validate.ts +135 -0
- package/src/tools/generateSchema.ts +28 -28
- package/src/utils/getEstimateProcessTime.ts +36 -0
- package/src/utils/index.ts +1 -0
- package/lib/cn/DivisionCode.js.map +0 -1
- package/lib/cn/Mod11Checksum.js +0 -42
- package/lib/cn/Mod11Checksum.js.map +0 -1
- package/lib/cn/Mod31Checksum.js +0 -48
- package/lib/cn/Mod31Checksum.js.map +0 -1
- package/lib/cn/ResidentIdentityCardNumber.js +0 -50
- package/lib/cn/ResidentIdentityCardNumber.js.map +0 -1
- package/lib/cn/UnifiedSocialCreditCode.js.map +0 -1
- package/lib/cn/formatDate.js +0 -15
- package/lib/cn/formatDate.js.map +0 -1
- package/lib/cn/index.js.map +0 -1
- package/lib/cn/parseSex.js +0 -22
- package/lib/cn/parseSex.js.map +0 -1
- package/lib/cn/types.d.js.map +0 -1
- package/lib/consola/createStandardConsolaReporter.js.map +0 -1
- package/lib/consola/formatLogObject.js.map +0 -1
- package/lib/consola/index.js.map +0 -1
- package/lib/data/formatSort.js.map +0 -1
- package/lib/data/index.js.map +0 -1
- package/lib/data/maybeNumber.js.map +0 -1
- package/lib/data/parseSort.js.map +0 -1
- package/lib/data/resolvePagination.js.map +0 -1
- package/lib/data/types.d.js.map +0 -1
- package/lib/index.js.map +0 -1
- package/lib/jsonschema/JsonSchema.js.map +0 -1
- package/lib/jsonschema/index.js.map +0 -1
- package/lib/jsonschema/types.d.js.map +0 -1
- package/lib/meta/defineFileType.js.map +0 -1
- package/lib/meta/defineInit.js.map +0 -1
- package/lib/meta/defineMetadata.js.map +0 -1
- package/lib/meta/index.js.map +0 -1
- package/lib/password/PHC.js.map +0 -1
- package/lib/password/Password.js.map +0 -1
- package/lib/password/createArgon2PasswordAlgorithm.js.map +0 -1
- package/lib/password/createBase64PasswordAlgorithm.js.map +0 -1
- package/lib/password/createBcryptPasswordAlgorithm.js.map +0 -1
- package/lib/password/createPBKDF2PasswordAlgorithm.js.map +0 -1
- package/lib/password/createScryptPasswordAlgorithm.js.map +0 -1
- package/lib/password/index.js.map +0 -1
- package/lib/password/server/index.js.map +0 -1
- package/lib/search/AdvanceSearch.js +0 -10
- package/lib/search/AdvanceSearch.js.map +0 -1
- package/lib/search/formatAdvanceSearch.js +0 -64
- package/lib/search/formatAdvanceSearch.js.map +0 -1
- package/lib/search/index.js +0 -2
- package/lib/search/index.js.map +0 -1
- package/lib/search/optimizeAdvanceSearch.js +0 -89
- package/lib/search/optimizeAdvanceSearch.js.map +0 -1
- package/lib/search/parseAdvanceSearch.js +0 -20
- package/lib/search/parseAdvanceSearch.js.map +0 -1
- package/lib/search/parser.d.js +0 -3
- package/lib/search/parser.d.js.map +0 -1
- package/lib/search/parser.js +0 -3065
- package/lib/search/parser.js.map +0 -1
- package/lib/search/types.d.js +0 -3
- package/lib/search/types.d.js.map +0 -1
- package/lib/tools/generateSchema.js.map +0 -1
- package/lib/tools/renderJsonSchemaToMarkdownDoc.js.map +0 -1
- package/src/cn/ResidentIdentityCardNumber.test.ts +0 -17
- package/src/cn/ResidentIdentityCardNumber.ts +0 -96
- package/src/cn/__snapshots__/ResidentIdentityCardNumber.test.ts.snap +0 -15
- package/src/cn/formatDate.ts +0 -12
- package/src/cn/parseSex.ts +0 -13
- package/src/search/AdvanceSearch.test.ts +0 -149
- package/src/search/AdvanceSearch.ts +0 -14
- package/src/search/Makefile +0 -2
- package/src/search/__snapshots__/AdvanceSearch.test.ts.snap +0 -675
- package/src/search/formatAdvanceSearch.ts +0 -52
- package/src/search/index.ts +0 -1
- package/src/search/optimizeAdvanceSearch.ts +0 -77
- package/src/search/parseAdvanceSearch.ts +0 -23
- package/src/search/parser.d.ts +0 -8
- package/src/search/parser.js +0 -2794
- package/src/search/parser.peggy +0 -237
- package/src/search/types.d.ts +0 -45
package/lib/cn/index.js.map
DELETED
|
@@ -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"}
|
package/lib/cn/parseSex.js
DELETED
|
@@ -1,22 +0,0 @@
|
|
|
1
|
-
export function parseSex(s) {
|
|
2
|
-
if (!s) return undefined;
|
|
3
|
-
switch(s.toLowerCase()){
|
|
4
|
-
case '男':
|
|
5
|
-
case 'male':
|
|
6
|
-
return {
|
|
7
|
-
sex: 'Male',
|
|
8
|
-
male: true,
|
|
9
|
-
female: false
|
|
10
|
-
};
|
|
11
|
-
case '女':
|
|
12
|
-
case 'female':
|
|
13
|
-
return {
|
|
14
|
-
sex: 'Female',
|
|
15
|
-
male: false,
|
|
16
|
-
female: true
|
|
17
|
-
};
|
|
18
|
-
}
|
|
19
|
-
return undefined;
|
|
20
|
-
}
|
|
21
|
-
|
|
22
|
-
//# sourceMappingURL=parseSex.js.map
|
package/lib/cn/parseSex.js.map
DELETED
|
@@ -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"}
|
package/lib/cn/types.d.js.map
DELETED
|
@@ -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,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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"}
|
package/lib/consola/index.js.map
DELETED
|
@@ -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"}
|
package/lib/data/index.js.map
DELETED
|
@@ -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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@
|
|
|
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"}
|
package/lib/data/types.d.js.map
DELETED
|
@@ -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,IA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6D,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"}
|
package/lib/meta/index.js.map
DELETED
|
@@ -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"}
|
package/lib/password/PHC.js.map
DELETED
|
@@ -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,MAAMC,YAAY;IAClB,MAAMC,aAAa;IACnB,MAAMC,WAAW;IACjB,MAAMC,eAAe;IACrB,MAAMC,eAAe;IAErB,MAAMC,aAAaR,aAAaQ,UAAU;IAC1C,MAAMC,WAAWT,aAAaS,QAAQ;IACtC,MAAMC,WAAW,CAACC;QACjB,OAAOA,aAAaC;IACrB;IAEA,SAASC,YAAYC,GAAwB;QAC5C,OAAOC,WAAWD,KAChBE,GAAG,CAAC,CAACC,IAAM;gBAACA;gBAAGH,GAAG,CAACG,EAAE;aAAC,CAACC,IAAI,CAAC,MAC5BA,IAAI,CAAC;IACR;IAEA,SAASC,YAAYC,GAAW;QAC/B,MAAMN,MAA8B,CAAC;QACrCM,IAAIC,KAAK,CAAC,KAAKC,OAAO,CAAC,CAACC;YACvB,MAAMC,MAAMD,GAAGF,KAAK,CAAC;YACrB,IAAIG,IAAIC,MAAM,GAAG,GAAG;gBACnB,MAAM,IAAIC,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U,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;IACR;aAFgBK,sBAAAA;IAIT,SAASC,aAAaJ,SAA4B;QACxDH,UAAU,CAACG,UAAUK,IAAI,CAAC,GAAGL;QAC7B,IAAIA,UAAUM,GAAG,EAAE;YAClB,KAAK,MAAMC,MAAMP,UAAUM,GAAG,CAAE;gBAC/BT,UAAU,CAACU,GAAG,GAAGP;YAClB;QACD;IACD;aAPgBI,eAAAA;IAShBA,aAAaV,8BAA8B;QAAEa,IAAI;QAAUC,QAAQ;IAAU;IAC7EJ,aAAaV,8BAA8B;QAAEa,IAAI;QAAUC,QAAQ;IAAU;IAEtE,eAAeC,MAAMC,IAAY;QACvC,OAAOf,IAAIgB,WAAW,CAACD;IACxB;aAFsBD,QAAAA;IAItB,SAASG,iBAAiBL,EAA8B;QACvD,IAAIM,IAAIN;QACR,MAAO,OAAOM,MAAM,SAAU;YAC7BA,IAAIhB,UAAU,CAACgB,EAAE;QAClB;QACA,IAAI,CAACA,GAAG;YACP,MAAM,IAAIC,MAAM,CAAC,kBAAkB,EAAEP,IAAI;QAC1C;QACA,OAAOM;IACR;IAEO,eAAeX,MAAMa,QAAgB,EAAEL,IAAY;QACzD,IAAIM,MAAM,MAAMP,MAAMC;QACtB,IAAIG,IAAID,iBAAiBI,IAAIT,EAAE;QAC/B,OAAO;YAAEU,QAAQJ,EAAEK,MAAM,CAACH,UAAUL,MAAMM;YAAMG,QAAQH;QAAI;IAC7D;aAJsBd,QAAAA;IAMf,eAAegB,OAAOH,QAAgB,EAAEL,IAAY;QAC1D,IAAIM,MAAM,MAAMP,MAAMC;QACtB,IAAIG,IAAID,iBAAiBI,IAAIT,EAAE;QAC/B,OAAOM,EAAEK,MAAM,CAACH,UAAUL,MAAMM;IACjC;aAJsBE,SAAAA;IAQf,eAAeR,KAAKK,QAAgB,EAAE,EAAEf,SAAS,EAAE,GAAGoB,MAA2B,GAAG,CAAC,CAAC;QAC5F,IAAIP,IAAID,iBAAiBZ,aAAaF;QACtC,IAAIS,KAAKP,aAAaF;QACtB,OAAOS,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,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W,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,10 +0,0 @@
|
|
|
1
|
-
import { formatAdvanceSearch } from "./formatAdvanceSearch.js";
|
|
2
|
-
import { optimizeAdvanceSearch } from "./optimizeAdvanceSearch.js";
|
|
3
|
-
import { parseAdvanceSearch } from "./parseAdvanceSearch.js";
|
|
4
|
-
(function (AdvanceSearch) {
|
|
5
|
-
AdvanceSearch.parse = parseAdvanceSearch;
|
|
6
|
-
AdvanceSearch.format = formatAdvanceSearch;
|
|
7
|
-
AdvanceSearch.optimize = optimizeAdvanceSearch;
|
|
8
|
-
})(AdvanceSearch || (AdvanceSearch = {}));
|
|
9
|
-
export var AdvanceSearch;
|
|
10
|
-
//# sourceMappingURL=AdvanceSearch.js.map
|
|
@@ -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,64 +0,0 @@
|
|
|
1
|
-
import { match } from "ts-pattern";
|
|
2
|
-
export function formatAdvanceSearch(input) {
|
|
3
|
-
const OP = {
|
|
4
|
-
match: ':',
|
|
5
|
-
eq: ':=',
|
|
6
|
-
ne: ':!=',
|
|
7
|
-
gt: ':>',
|
|
8
|
-
lt: ':<',
|
|
9
|
-
gte: ':>=',
|
|
10
|
-
lte: ':<=',
|
|
11
|
-
range: ':'
|
|
12
|
-
};
|
|
13
|
-
const _exprs = (s)=>{
|
|
14
|
-
return s.map(_expr).join(' ');
|
|
15
|
-
};
|
|
16
|
-
const _expr = (s)=>{
|
|
17
|
-
return match(s).with({
|
|
18
|
-
type: 'keyword'
|
|
19
|
-
}, ({ value, exact, negative })=>{
|
|
20
|
-
return `${negative ? '-' : ''}${exact ? `"${value}"` : value}`;
|
|
21
|
-
}).with({
|
|
22
|
-
type: 'logical'
|
|
23
|
-
}, ({ operator, value })=>value.map(_expr).join(` ${operator.toLocaleUpperCase()} `)).with({
|
|
24
|
-
type: 'not'
|
|
25
|
-
}, ({ value })=>`NOT ${_expr(value)}`).with({
|
|
26
|
-
type: 'compare'
|
|
27
|
-
}, ({ field, operator, value, negative, mention })=>{
|
|
28
|
-
return `${negative ? '-' : ''}${mention ? '@' : ''}${field}${OP[operator]}${_value(value)}`;
|
|
29
|
-
}).with({
|
|
30
|
-
type: 'comment'
|
|
31
|
-
}, ({ value })=>`/* ${value} */`).with({
|
|
32
|
-
type: 'parentheses'
|
|
33
|
-
}, ({ value })=>`(${_exprs(value)})`).exhaustive();
|
|
34
|
-
};
|
|
35
|
-
const _literal = (s)=>{
|
|
36
|
-
if (typeof s === 'string') {
|
|
37
|
-
return s.includes(' ') ? `"${s}"` : s;
|
|
38
|
-
}
|
|
39
|
-
return JSON.stringify(s);
|
|
40
|
-
};
|
|
41
|
-
const _value = (v)=>{
|
|
42
|
-
return match(v).with({
|
|
43
|
-
type: 'range'
|
|
44
|
-
}, ({ minimum, maximum, minimumExclusive, maximumExclusive })=>{
|
|
45
|
-
if (minimumExclusive === undefined && maximumExclusive === undefined) {
|
|
46
|
-
let min = minimum === undefined ? '*' : _value(minimum);
|
|
47
|
-
let max = maximum === undefined ? '*' : _value(maximum);
|
|
48
|
-
return `${min}..${max}`;
|
|
49
|
-
}
|
|
50
|
-
let min = minimum === undefined ? '' : _value(minimum);
|
|
51
|
-
let max = maximum === undefined ? '' : _value(maximum);
|
|
52
|
-
return `${minimumExclusive ? '(' : '['}${min},${max}${maximumExclusive ? ')' : ']'}`;
|
|
53
|
-
}).with({
|
|
54
|
-
format: 'mention'
|
|
55
|
-
}, ({ value })=>{
|
|
56
|
-
return `@${value}`;
|
|
57
|
-
}).otherwise((value)=>{
|
|
58
|
-
return _literal(value.value);
|
|
59
|
-
});
|
|
60
|
-
};
|
|
61
|
-
return _exprs(input);
|
|
62
|
-
}
|
|
63
|
-
|
|
64
|
-
//# sourceMappingURL=formatAdvanceSearch.js.map
|
|
@@ -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;AAGnC,OAAO,SAASC,oBAAoBC,KAA2B;IAC9D,MAAMC,KAAK;QAAEH,OAAO;QAAKI,IAAI;QAAMC,IAAI;QAAOC,IAAI;QAAMC,IAAI;QAAMC,KAAK;QAAOC,KAAK;QAAOC,OAAO;IAAI;IAErG,MAAMC,SAAS,CAACC;QACf,OAAOA,EAAEC,GAAG,CAACC,OAAOC,IAAI,CAAC;IAC1B;IACA,MAAMD,QAAQ,CAACF;QACd,OAAOZ,MAAMY,GACXI,IAAI,CAAC;YAAEC,MAAM;QAAU,GAAG,CAAC,EAAEC,KAAK,EAAEC,KAAK,EAAEC,QAAQ,EAAE;YACrD,OAAO,GAAGA,WAAW,MAAM,KAAKD,QAAQ,CAAC,CAAC,EAAED,MAAM,CAAC,CAAC,GAAGA,OAAO;QAC/D,GACCF,IAAI,CAAC;YAAEC,MAAM;QAAU,GAAG,CAAC,EAAEI,QAAQ,EAAEH,KAAK,EAAE,GAAKA,MAAML,GAAG,CAACC,OAAOC,IAAI,CAAC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Y,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"}
|
package/lib/search/index.js
DELETED
package/lib/search/index.js.map
DELETED
|
@@ -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,89 +0,0 @@
|
|
|
1
|
-
import { arrayOfMaybeArray, deepEqual } from "@wener/utils";
|
|
2
|
-
import { match } from "ts-pattern";
|
|
3
|
-
export function optimizeAdvanceSearch(expr) {
|
|
4
|
-
const NEG = {
|
|
5
|
-
eq: 'ne',
|
|
6
|
-
ne: 'eq',
|
|
7
|
-
gt: 'lte',
|
|
8
|
-
lt: 'gte',
|
|
9
|
-
gte: 'lt',
|
|
10
|
-
lte: 'gt'
|
|
11
|
-
};
|
|
12
|
-
const _expr = (e)=>{
|
|
13
|
-
// merge Exprs to AND ?
|
|
14
|
-
return match(e)// (EXPR) -> EXPR
|
|
15
|
-
// TODO (EXPR EXPR) -> EXPR AND EXPR
|
|
16
|
-
.with({
|
|
17
|
-
type: 'parentheses'
|
|
18
|
-
}, (expr)=>{
|
|
19
|
-
// unwrap
|
|
20
|
-
if (expr.value.length < 2) {
|
|
21
|
-
return expr.value[0];
|
|
22
|
-
}
|
|
23
|
-
expr.value = expr.value.flatMap(_expr);
|
|
24
|
-
return expr;
|
|
25
|
-
}).with({
|
|
26
|
-
type: 'comment'
|
|
27
|
-
}, (expr)=>{
|
|
28
|
-
// remove empty comment
|
|
29
|
-
if (!expr.value.length) {
|
|
30
|
-
return [];
|
|
31
|
-
}
|
|
32
|
-
return expr;
|
|
33
|
-
})// NOT
|
|
34
|
-
.with({
|
|
35
|
-
type: 'not'
|
|
36
|
-
}, (expr)=>{
|
|
37
|
-
let out = arrayOfMaybeArray(_expr(expr.value));
|
|
38
|
-
if (!out.length) {
|
|
39
|
-
return [];
|
|
40
|
-
} else if (out.length === 1) {
|
|
41
|
-
expr.value = out[0];
|
|
42
|
-
} else {
|
|
43
|
-
throw new Error('NOT should have only one value');
|
|
44
|
-
}
|
|
45
|
-
return match(expr.value)// NOT NOT EXPR -> EXPR
|
|
46
|
-
.with({
|
|
47
|
-
type: 'not'
|
|
48
|
-
}, (expr)=>expr.value)// NOT EXPR -> -EXPR
|
|
49
|
-
.with({
|
|
50
|
-
type: 'compare'
|
|
51
|
-
}, (expr)=>{
|
|
52
|
-
return {
|
|
53
|
-
...expr,
|
|
54
|
-
negative: !expr.negative
|
|
55
|
-
};
|
|
56
|
-
}).with({
|
|
57
|
-
type: 'keyword'
|
|
58
|
-
}, (expr)=>{
|
|
59
|
-
return {
|
|
60
|
-
...expr,
|
|
61
|
-
negative: !expr.negative
|
|
62
|
-
};
|
|
63
|
-
}).otherwise(()=>expr);
|
|
64
|
-
}).with({
|
|
65
|
-
type: 'compare'
|
|
66
|
-
}, (expr)=>{
|
|
67
|
-
// negative by swap operator
|
|
68
|
-
if (expr.negative) {
|
|
69
|
-
const ne = NEG[expr.operator];
|
|
70
|
-
if (ne) {
|
|
71
|
-
expr.operator = ne;
|
|
72
|
-
expr.negative = false;
|
|
73
|
-
}
|
|
74
|
-
}
|
|
75
|
-
if (expr.operator === 'range') {}
|
|
76
|
-
return expr;
|
|
77
|
-
}).otherwise((e)=>e);
|
|
78
|
-
};
|
|
79
|
-
let last = expr;
|
|
80
|
-
while(true){
|
|
81
|
-
let next = structuredClone(last).flatMap(_expr);
|
|
82
|
-
if (deepEqual(last, next)) {
|
|
83
|
-
return last;
|
|
84
|
-
}
|
|
85
|
-
last = next;
|
|
86
|
-
}
|
|
87
|
-
}
|
|
88
|
-
|
|
89
|
-
//# sourceMappingURL=optimizeAdvanceSearch.js.map
|
|
@@ -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,S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I,CAAC;gBAAEC,MAAM;YAAU,GAAG,CAACX;gBAC3B,OAAO;oBAAE,GAAGA,IAAI;oBAAEiB,UAAU,CAACjB,KAAKiB,QAAQ;gBAAC;YAC5C,GACCC,SAAS,CAAC,IAAMlB;QAEpB,GACCU,IAAI,CAAC;YAAEC,MAAM;QAAU,GAAG,CAACX;YAC3B,4BAA4B;YAC5B,IAAIA,KAAKiB,QAAQ,EAAE;gBAClB,MAAMd,KAAKF,GAAG,CAACD,KAAKmB,QAAQ,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,20 +0,0 @@
|
|
|
1
|
-
import { parse } from "./parser.js";
|
|
2
|
-
export function parseAdvanceSearch(s) {
|
|
3
|
-
s = s?.trim();
|
|
4
|
-
if (!s) {
|
|
5
|
-
return [];
|
|
6
|
-
}
|
|
7
|
-
// no Logical, no Compare, no Quote, no Comment
|
|
8
|
-
if (!/AND|OR|NOT|[-"():]|\/\*/.test(s)) {
|
|
9
|
-
// fast path
|
|
10
|
-
return s.split(/\s+/).map((v)=>v.trim()).filter(Boolean).map((v)=>{
|
|
11
|
-
return {
|
|
12
|
-
type: 'keyword',
|
|
13
|
-
value: v
|
|
14
|
-
};
|
|
15
|
-
});
|
|
16
|
-
}
|
|
17
|
-
return parse(s);
|
|
18
|
-
}
|
|
19
|
-
|
|
20
|
-
//# sourceMappingURL=parseAdvanceSearch.js.map
|
|
@@ -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"}
|
package/lib/search/parser.d.js
DELETED
|
@@ -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"}
|