@wener/common 2.0.3 → 2.0.5
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/ai/qwen3vl/utils.js.map +1 -1
- package/lib/cn/ChineseResidentIdNo.js +1 -1
- package/lib/cn/ChineseResidentIdNo.js.map +1 -1
- package/lib/cn/Mod11.js +1 -1
- package/lib/cn/Mod11.js.map +1 -1
- package/lib/consola/formatLogObject.js +5 -5
- package/lib/consola/formatLogObject.js.map +1 -1
- package/lib/data/maybeNumber.js +1 -1
- package/lib/data/maybeNumber.js.map +1 -1
- package/lib/data/types.d.js.map +1 -1
- package/lib/dayjs/formatDuration.js.map +1 -1
- package/lib/dayjs/resolveRelativeTime.js +9 -80
- package/lib/dayjs/resolveRelativeTime.js.map +1 -1
- package/lib/drain3/Drain.js +356 -0
- package/lib/drain3/Drain.js.map +1 -0
- package/lib/drain3/LogCluster.js +38 -0
- package/lib/drain3/LogCluster.js.map +1 -0
- package/lib/drain3/Node.js +39 -0
- package/lib/drain3/Node.js.map +1 -0
- package/lib/drain3/TemplateMiner.js +204 -0
- package/lib/drain3/TemplateMiner.js.map +1 -0
- package/lib/drain3/index.js +31 -0
- package/lib/drain3/index.js.map +1 -0
- package/lib/drain3/persistence/FilePersistence.js +24 -0
- package/lib/drain3/persistence/FilePersistence.js.map +1 -0
- package/lib/drain3/persistence/MemoryPersistence.js +18 -0
- package/lib/drain3/persistence/MemoryPersistence.js.map +1 -0
- package/lib/drain3/persistence/PersistenceHandler.js +5 -0
- package/lib/drain3/persistence/PersistenceHandler.js.map +1 -0
- package/lib/drain3/types.js +7 -0
- package/lib/drain3/types.js.map +1 -0
- package/lib/fs/IFileSystem.d.js.map +1 -1
- package/lib/fs/createBrowserFileSystem.js +4 -2
- package/lib/fs/createBrowserFileSystem.js.map +1 -1
- package/lib/fs/createMemoryFileSystem.js +7 -6
- package/lib/fs/createMemoryFileSystem.js.map +1 -1
- package/lib/fs/createSandboxFileSystem.js.map +1 -1
- package/lib/fs/createWebDavFileSystem.js +22 -5
- package/lib/fs/createWebDavFileSystem.js.map +1 -1
- package/lib/fs/createWebFileSystem.js +225 -0
- package/lib/fs/createWebFileSystem.js.map +1 -0
- package/lib/fs/findMimeType.js +1 -1
- package/lib/fs/findMimeType.js.map +1 -1
- package/lib/fs/index.js +1 -1
- package/lib/fs/index.js.map +1 -1
- package/lib/fs/minio/createMinioFileSystem.js +974 -0
- package/lib/fs/minio/createMinioFileSystem.js.map +1 -0
- package/lib/fs/minio/index.js +2 -0
- package/lib/fs/minio/index.js.map +1 -0
- package/lib/fs/orpc/createContractClientFileSystem.js +3 -3
- package/lib/fs/orpc/createContractClientFileSystem.js.map +1 -1
- package/lib/fs/orpc/server/createFileSystemContractImpl.js.map +1 -1
- package/lib/fs/s3/createS3MiniFileSystem.js +116 -68
- package/lib/fs/s3/createS3MiniFileSystem.js.map +1 -1
- package/lib/fs/server/createDatabaseFileSystem.js +7 -7
- package/lib/fs/server/createDatabaseFileSystem.js.map +1 -1
- package/lib/fs/server/createNodeFileSystem.js +30 -5
- package/lib/fs/server/createNodeFileSystem.js.map +1 -1
- package/lib/fs/tests/runFileSystemTest.js +27 -26
- package/lib/fs/tests/runFileSystemTest.js.map +1 -1
- package/lib/fs/utils.js.map +1 -1
- package/lib/fs/webdav/index.js +2 -0
- package/lib/fs/webdav/index.js.map +1 -0
- package/lib/jsonschema/JsonSchema.js +5 -5
- package/lib/jsonschema/JsonSchema.js.map +1 -1
- package/lib/jsonschema/forEachJsonSchema.js +1 -1
- package/lib/jsonschema/forEachJsonSchema.js.map +1 -1
- package/lib/jsonschema/types.d.js.map +1 -1
- package/lib/meta/defineMetadata.js.map +1 -1
- package/lib/orpc/createOpenApiContractClient.js.map +1 -1
- package/lib/password/PHC.js +2 -2
- package/lib/password/PHC.js.map +1 -1
- package/lib/password/createArgon2PasswordAlgorithm.js.map +1 -1
- package/lib/password/createBase64PasswordAlgorithm.js +1 -1
- package/lib/password/createBase64PasswordAlgorithm.js.map +1 -1
- package/lib/password/createBcryptPasswordAlgorithm.js.map +1 -1
- package/lib/password/createPBKDF2PasswordAlgorithm.js +1 -1
- package/lib/password/createPBKDF2PasswordAlgorithm.js.map +1 -1
- package/lib/password/createScryptPasswordAlgorithm.js +3 -3
- package/lib/password/createScryptPasswordAlgorithm.js.map +1 -1
- package/lib/resource/ListQuery.js.map +1 -1
- package/lib/resource/index.js.map +1 -1
- package/lib/s3/formatS3Url.js +2 -2
- package/lib/s3/formatS3Url.js.map +1 -1
- package/lib/s3/parseS3Url.js +1 -1
- package/lib/s3/parseS3Url.js.map +1 -1
- package/lib/schema/SchemaRegistry.js.map +1 -1
- package/lib/schema/TypeSchema.d.js.map +1 -1
- package/lib/schema/createSchemaData.js +4 -4
- package/lib/schema/createSchemaData.js.map +1 -1
- package/lib/schema/findJsonSchemaByPath.js.map +1 -1
- package/lib/schema/formatZodError.js +42 -44
- package/lib/schema/formatZodError.js.map +1 -1
- package/lib/schema/toJsonSchema.js +4 -4
- package/lib/schema/toJsonSchema.js.map +1 -1
- package/lib/schema/validate.js +1 -1
- package/lib/schema/validate.js.map +1 -1
- package/lib/utils/buildRedactorFormSchema.js +1 -1
- package/lib/utils/buildRedactorFormSchema.js.map +1 -1
- package/package.json +32 -13
- package/src/ai/qwen3vl/utils.ts +1 -1
- package/src/cn/ChineseResidentIdNo.ts +1 -1
- package/src/cn/Mod11.ts +1 -1
- package/src/cn/__snapshots__/ChineseResidentIdNo.test.ts.snap +1 -1
- package/src/cn/__snapshots__/UnifiedSocialCreditCode.test.ts.snap +0 -23
- package/src/cn/parseChineseNumber.test.ts +4 -4
- package/src/consola/formatLogObject.ts +6 -6
- package/src/data/maybeNumber.ts +1 -1
- package/src/data/parseSort.test.ts +0 -1
- package/src/data/types.d.ts +2 -2
- package/src/dayjs/formatDuration.ts +2 -2
- package/src/dayjs/resolveRelativeTime.ts +11 -14
- package/src/drain3/Drain.test.ts +378 -0
- package/src/drain3/Drain.ts +394 -0
- package/src/drain3/LogCluster.ts +46 -0
- package/src/drain3/Node.ts +53 -0
- package/src/drain3/TemplateMiner.ts +246 -0
- package/src/drain3/index.ts +36 -0
- package/src/drain3/persistence/FilePersistence.ts +24 -0
- package/src/drain3/persistence/MemoryPersistence.ts +23 -0
- package/src/drain3/persistence/PersistenceHandler.ts +19 -0
- package/src/drain3/types.ts +75 -0
- package/src/fs/IFileSystem.d.ts +1 -2
- package/src/fs/createBrowserFileSystem.ts +7 -5
- package/src/fs/createMemoryFileSystem.ts +9 -13
- package/src/fs/createSandboxFileSystem.ts +1 -1
- package/src/fs/createWebDavFileSystem.ts +28 -10
- package/src/fs/createWebFileSystem.ts +242 -0
- package/src/fs/findMimeType.ts +1 -4
- package/src/fs/index.ts +1 -1
- package/src/fs/minio/createMinioFileSystem.ts +1148 -0
- package/src/fs/minio/index.ts +1 -0
- package/src/fs/orpc/createContractClientFileSystem.ts +5 -5
- package/src/fs/orpc/server/createFileSystemContractImpl.ts +1 -1
- package/src/fs/s3/createS3MiniFileSystem.ts +119 -78
- package/src/fs/s3/s3fs.test.ts +441 -0
- package/src/fs/s3/s3mini.test.ts +2 -2
- package/src/fs/server/createDatabaseFileSystem.ts +7 -7
- package/src/fs/server/createNodeFileSystem.ts +32 -13
- package/src/fs/server/dbfs.test.ts +2 -1
- package/src/fs/tests/runFileSystemTest.ts +29 -28
- package/src/fs/utils.ts +1 -1
- package/src/fs/webdav/index.ts +1 -0
- package/src/jsonschema/JsonSchema.ts +5 -5
- package/src/jsonschema/forEachJsonSchema.ts +1 -1
- package/src/jsonschema/types.d.ts +1 -1
- package/src/meta/defineMetadata.ts +1 -1
- package/src/orpc/createOpenApiContractClient.ts +2 -2
- package/src/password/PHC.ts +3 -3
- package/src/password/createArgon2PasswordAlgorithm.ts +1 -1
- package/src/password/createBase64PasswordAlgorithm.ts +2 -2
- package/src/password/createBcryptPasswordAlgorithm.ts +4 -2
- package/src/password/createPBKDF2PasswordAlgorithm.ts +2 -2
- package/src/password/createScryptPasswordAlgorithm.ts +4 -4
- package/src/resource/ListQuery.ts +4 -1
- package/src/resource/index.ts +2 -2
- package/src/s3/formatS3Url.test.ts +1 -1
- package/src/s3/formatS3Url.ts +2 -2
- package/src/s3/parseS3Url.ts +1 -1
- package/src/schema/SchemaRegistry.ts +1 -1
- package/src/schema/TypeSchema.d.ts +6 -6
- package/src/schema/createSchemaData.ts +4 -4
- package/src/schema/findJsonSchemaByPath.ts +4 -4
- package/src/schema/formatZodError.test.ts +2 -1
- package/src/schema/formatZodError.ts +50 -62
- package/src/schema/toJsonSchema.ts +6 -6
- package/src/schema/validate.ts +1 -1
- package/src/utils/buildRedactorFormSchema.ts +3 -3
package/lib/password/PHC.js
CHANGED
|
@@ -71,7 +71,7 @@ import { ArrayBuffers } from "@wener/utils";
|
|
|
71
71
|
}
|
|
72
72
|
// Convert Numbers into Numeric Strings and Buffers into B64 encoded strings.
|
|
73
73
|
pk.forEach((k)=>{
|
|
74
|
-
const value = opts.params[k];
|
|
74
|
+
const value = opts.params?.[k];
|
|
75
75
|
if (typeof value === 'number') {
|
|
76
76
|
opts.params[k] = value.toString();
|
|
77
77
|
} else if (value instanceof Uint8Array) {
|
|
@@ -169,7 +169,7 @@ import { ArrayBuffers } from "@wener/utils";
|
|
|
169
169
|
}
|
|
170
170
|
// Convert Decimal Strings into Numbers
|
|
171
171
|
Object.keys(params).forEach((k)=>{
|
|
172
|
-
const value = params[k];
|
|
172
|
+
const value = params?.[k];
|
|
173
173
|
if (typeof value === 'string' && decimalRegex.test(value)) {
|
|
174
174
|
params[k] = parseInt(value, 10);
|
|
175
175
|
}
|
package/lib/password/PHC.js.map
CHANGED
|
@@ -1 +1 @@
|
|
|
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 as BufferSource).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 as BufferSource).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 as BufferSource).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,UAAU,CAAC,uCAAuC,CAAC;YAC9D;YAEA,MAAMC,MAAMH,IAAII,KAAK;YACrB,IAAID,QAAQE,WAAW;gBACtBf,GAAG,CAACa,IAA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,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
|
+
{"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 as BufferSource).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 as BufferSource).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 as BufferSource).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\texport interface 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,UAA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I,CAACQ,KAAK;oBACzD,MAAM,IAAIrB,UAAU,CAAC,0BAA0B,EAAEvB,UAAU,CAAC,CAAC;gBAC9D;gBAEA,MAAM+C,KAAKnB,OAAOG,MAAM,CAACU;gBACzB,IAAI,CAACM,GAAGJ,KAAK,CAAC,CAACnC,IAAMP,WAAWmC,IAAI,CAACyB,OAAOrD,MAAM;oBACjD,MAAM,IAAIe,UAAU,CAAC,2BAA2B,EAAEtB,YAAY;gBAC/D;gBAEA,uCAAuC;gBACvC2B,OAAOC,IAAI,CAACY,QAAQtB,OAAO,CAAC,CAACL;oBAC5B,MAAMgC,QAAQL,QAAQ,CAAC3B,EAAE;oBACzB,IAAI,OAAOgC,UAAU,YAAY3C,aAAaiC,IAAI,CAACU,QAAQ;wBAC1DL,MAAO,CAAC3B,EAAE,GAAG0C,SAASV,OAAO;oBAC9B;gBACD;YACD;QACD;QAEA,IAAIZ,OAAOZ,MAAM,GAAG,GAAG;YACtB,MAAM,IAAIC,UAAU,CAAC,qCAAqC,EAAEW,QAAQ;QACrE;QAEA,0BAA0B;QAC1B,MAAM4B,SAA4B;YAAE3B;QAAG;QACvC,IAAIG,YAAYZ,WAAWoC,OAAOxB,OAAO,GAAGA;QAC5C,IAAIG,QAAQqB,OAAOrB,MAAM,GAAGA;QAC5B,IAAIQ,MAAMa,OAAOb,IAAI,GAAGA;QACxB,IAAIC,MAAMY,OAAOZ,IAAI,GAAGA;QAExB,OAAOY;IACR;IA5FA;;;;EAIC,OACeV,cAAAA;AAwFjB,GApPiBtD,QAAAA"}
|
|
@@ -1 +1 @@
|
|
|
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
|
+
{"version":3,"sources":["../../src/password/createArgon2PasswordAlgorithm.ts"],"sourcesContent":["import { maybeFunction, type MaybeFunction, type MaybePromise } from '@wener/utils';\nimport type { 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"}
|
|
@@ -5,7 +5,7 @@ export function createBase64PasswordAlgorithm({ id = 'base64' } = {}) {
|
|
|
5
5
|
async hash (password) {
|
|
6
6
|
return `$${id}$$${ArrayBuffers.toBase64(password).replace(/=/g, '')}`;
|
|
7
7
|
},
|
|
8
|
-
async verify (password,
|
|
8
|
+
async verify (password, _hash, opts) {
|
|
9
9
|
return Boolean(opts.hash) && ArrayBuffers.toString(opts.hash) === password;
|
|
10
10
|
}
|
|
11
11
|
};
|
|
@@ -1 +1 @@
|
|
|
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,
|
|
1
|
+
{"version":3,"sources":["../../src/password/createBase64PasswordAlgorithm.ts"],"sourcesContent":["import { ArrayBuffers } from '@wener/utils';\nimport type { 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","_hash","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,EAAEI,KAAa,EAAEC,IAAI;YACjD,OAAOC,QAAQD,KAAKN,IAAI,KAAKJ,aAAaY,QAAQ,CAACF,KAAKN,IAAI,MAAOC;QACpE;IACD;AACD"}
|
|
@@ -1 +1 @@
|
|
|
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}: {
|
|
1
|
+
{"version":3,"sources":["../../src/password/createBcryptPasswordAlgorithm.ts"],"sourcesContent":["import type { MaybePromise } from '@wener/utils';\nimport type { 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}: {\n\tprovider?: ProviderType;\n} = {}): 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,EAG1D,GAAG,CAAC,CAAC;IACL,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"}
|
|
@@ -47,7 +47,7 @@ export function createPBKDF2PasswordAlgorithm({ id, digest, iterations = 100000,
|
|
|
47
47
|
salt: salt,
|
|
48
48
|
hash: digest
|
|
49
49
|
}, key, storedHash.length * 8);
|
|
50
|
-
return new Uint8Array(hash).every((v, i) => v === storedHash[i]);
|
|
50
|
+
return new Uint8Array(hash).every((v, i) => v === storedHash?.[i]);
|
|
51
51
|
}
|
|
52
52
|
};
|
|
53
53
|
}
|
|
@@ -1 +1 @@
|
|
|
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: salt as BufferSource, 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: salt as BufferSource, 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
|
|
1
|
+
{"version":3,"sources":["../../src/password/createPBKDF2PasswordAlgorithm.ts"],"sourcesContent":["import { Errors } from '@wener/utils';\nimport type { 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: salt as BufferSource, 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: salt as BufferSource, 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,OAAO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wener/utils";
|
|
|
3
3
|
import { PHC } from "./PHC.js";
|
|
4
4
|
export function createScryptPasswordAlgorithm(options = {}) {
|
|
5
5
|
let id = options.id || "scrypt";
|
|
6
|
-
options.cost ||=
|
|
6
|
+
options.cost ||= 2 ** 14;
|
|
7
7
|
options.blocksize ||= 8;
|
|
8
8
|
options.parallelism ||= 1;
|
|
9
9
|
options.saltlen ||= 16;
|
|
@@ -36,7 +36,7 @@ export function createScryptPasswordAlgorithm(options = {}) {
|
|
|
36
36
|
});
|
|
37
37
|
});
|
|
38
38
|
},
|
|
39
|
-
async verify(password,
|
|
39
|
+
async verify(password, _hash, opts) {
|
|
40
40
|
try {
|
|
41
41
|
const salt = Errors.BadRequest.require(opts.salt);
|
|
42
42
|
const storedHash = Errors.BadRequest.require(opts.hash);
|
|
@@ -57,7 +57,7 @@ export function createScryptPasswordAlgorithm(options = {}) {
|
|
|
57
57
|
});
|
|
58
58
|
});
|
|
59
59
|
}
|
|
60
|
-
catch (
|
|
60
|
+
catch (_error) {
|
|
61
61
|
return Promise.resolve(false);
|
|
62
62
|
}
|
|
63
63
|
}
|
|
@@ -1 +1 @@
|
|
|
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 ||=
|
|
1
|
+
{"version":3,"sources":["../../src/password/createScryptPasswordAlgorithm.ts"],"sourcesContent":["import { randomBytes, scrypt, timingSafeEqual } from 'node:crypto';\nimport { Errors } from '@wener/utils';\nimport type { 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 ||= 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","blocksize","parallelism","saltlen","keylen","name","hash","password","opts","salt","Promise","resolve","reject","N","r","p","err","derivedKey","serialize","params","ln","verify","_hash","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,KAAK,KAAK;IACtBF,QAAQG,SAAS,KAAK;IACtBH,QAAQI,WAAW,KAAK;IACxBJ,QAAQK,OAAO,KAAK;IACpBL,QAAQM,MAAM,KAAK;IACnB,OAAO;QACNC,MAAMN;QACN,MAAMO,MAAKC,QAAgB,EAAEC,IAAI;YAChC,MAAMC,OAAOD,MAAMC,QAAQjB,YAAYM,QAAQK,OAAO;YACtD,OAAO,IAAIO,QAAQ,CAACC,SAASC;gBAC5B,IAAIC,IAAIf,QAAQE,IAAI;gBACpB,IAAIc,IAAIhB,QAAQG,SAAS;gBACzB,IAAIc,IAAIjB,QAAQI,WAAW;gBAC3BT,OAAOc,UAAUE,MAAMX,QAAQM,MAAM,EAAG;oBAAES;oBAAGC;oBAAGC;gBAAE,GAAG,CAACC,KAAKC;oBAC1D,IAAID,KAAK,OAAOJ,OAAOI;oBAEvBL,QAAQf,IAAIsB,SAAS,CAAC;wBAAEnB,IAAIS,MAAMT,MAAMA;wBAAIoB,QAAQ;4BAAEC,IAAIP;4BAAIC,GAAGA;4BAAIC,GAAGA;wBAAG;wBAAGN;wBAAMH,MAAMW;oBAAW;gBACtG;YACD;QACD;QAEA,MAAMI,QAAOd,QAAgB,EAAEe,KAAa,EAAEd,IAAI;YACjD,IAAI;gBACH,MAAMC,OAAOd,OAAO4B,UAAU,CAACC,OAAO,CAAChB,KAAKC,IAAI;gBAChD,MAAMgB,aAAa9B,OAAO4B,UAAU,CAACC,OAAO,CAAChB,KAAKF,IAAI;gBAEtD,MAAMO,IAAIa,SAASlB,KAAKW,MAAM,EAAEC,IAAc;gBAC9C,MAAMN,IAAIY,SAASlB,KAAKW,MAAM,EAAEL,GAAa;gBAC7C,MAAMC,IAAIW,SAASlB,KAAKW,MAAM,EAAEJ,GAAa;gBAC7C,MAAMX,SAASqB,WAAWE,MAAM;gBAEhC,OAAO,IAAIjB,QAAQ,CAACC,SAASC;oBAC5BnB,OAAOc,UAAUE,MAAML,QAAQ;wBAAES;wBAAGC;wBAAGC;oBAAE,GAAG,CAACC,KAAKC;wBACjD,IAAID,KAAK,OAAOJ,OAAOI;wBAEvB,MAAMY,UAAUlC,gBAAgBuB,YAAYQ;wBAC5Cd,QAAQiB;oBACT;gBACD;YACD,EAAE,OAAOC,QAAQ;gBAChB,OAAOnB,QAAQC,OAAO,CAAC;YACxB;QACD;IACD;AACD"}
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"sources":["../../src/resource/ListQuery.ts"],"sourcesContent":["import { z } from 'zod/v4';\n\nexport type ListQueryInput = z.input<typeof ListQuerySchema>;\nexport type ListQuery = z.infer<typeof ListQuerySchema>;\nconst IntLikeSchema = z.coerce\n\t.number()\n\t.multipleOf(1)\n\t.min(0)\n\t.optional()\n\t.overwrite((v) => v || undefined);\nexport const ListQuerySchema = z.object({\n\tid: z.coerce.string().optional(),\n\tids: z.array(z.coerce.string()).optional(),\n\tfilter: z.string().optional().describe('sql-like filter string'),\n\tfilters: z.array(z.any()).optional().describe('sql-like filter string'),\n\twhere: z.record(z.string(), z.any()).optional().describe('document query filter'),\n\tsearch: z.string().optional(),\n\tlimit: IntLikeSchema,\n\toffset: IntLikeSchema,\n\torder: z.array(z.string()).optional().describe('order like \"a,-b,c desc null last\"'),\n\tpageIndex: IntLikeSchema.describe('0-based page index'),\n\tpageNumber: IntLikeSchema.describe('1-based page number'),\n\tpageSize: IntLikeSchema,\n\tcursor: z.string().optional(),\n\tdeleted: z.coerce.boolean().optional(),\n});\n\ntype ListQueryOverride
|
|
1
|
+
{"version":3,"sources":["../../src/resource/ListQuery.ts"],"sourcesContent":["import { z } from 'zod/v4';\n\nexport type ListQueryInput = z.input<typeof ListQuerySchema>;\nexport type ListQuery = z.infer<typeof ListQuerySchema>;\nconst IntLikeSchema = z.coerce\n\t.number()\n\t.multipleOf(1)\n\t.min(0)\n\t.optional()\n\t.overwrite((v) => v || undefined);\nexport const ListQuerySchema = z.object({\n\tid: z.coerce.string().optional(),\n\tids: z.array(z.coerce.string()).optional(),\n\tfilter: z.string().optional().describe('sql-like filter string'),\n\tfilters: z.array(z.any()).optional().describe('sql-like filter string'),\n\twhere: z.record(z.string(), z.any()).optional().describe('document query filter'),\n\tsearch: z.string().optional(),\n\tlimit: IntLikeSchema,\n\toffset: IntLikeSchema,\n\torder: z.array(z.string()).optional().describe('order like \"a,-b,c desc null last\"'),\n\tpageIndex: IntLikeSchema.describe('0-based page index'),\n\tpageNumber: IntLikeSchema.describe('1-based page number'),\n\tpageSize: IntLikeSchema,\n\tcursor: z.string().optional(),\n\tdeleted: z.coerce.boolean().optional(),\n});\n\ntype ListQueryOverride =\n\t| ListQueryInput\n\t| undefined\n\t| ((input: ListQueryInput) => ListQueryInput | undefined | undefined);\n\nexport function resolveListQuery(target: ListQueryInput | undefined, ...args: ListQueryOverride[]): ListQuery {\n\tlet out = args.reduce((a: ListQueryInput, source) => {\n\t\tif (typeof source === 'function') {\n\t\t\tconst result = source(a);\n\t\t\t// do not use the result as merge source\n\t\t\treturn result || a;\n\t\t}\n\n\t\tlet b: ListQueryInput | undefined = source;\n\t\tif (!b) return a;\n\n\t\t// do not resolve id to ids\n\t\tlet ids = [...(a.ids || []), ...(b.ids || [])];\n\t\treturn {\n\t\t\t...a,\n\t\t\t...b,\n\t\t\tids: ids,\n\t\t\tfilters: [...(a.filters || []), ...(b.filters || [])],\n\t\t\tsearch: b.search || a.search,\n\t\t\t// NOTE maybe should merge where ?\n\t\t};\n\t}, target || {});\n\treturn ListQuerySchema.parse(out);\n}\n"],"names":["z","IntLikeSchema","coerce","number","multipleOf","min","optional","overwrite","v","undefined","ListQuerySchema","object","id","string","ids","array","filter","describe","filters","any","where","record","search","limit","offset","order","pageIndex","pageNumber","pageSize","cursor","deleted","boolean","resolveListQuery","target","args","out","reduce","a","source","result","b","parse"],"mappings":"AAAA,SAASA,CAAC,QAAQ,SAAS;AAI3B,MAAMC,gBAAgBD,EAAEE,MAAM,CAC5BC,MAAM,GACNC,UAAU,CAAC,GACXC,GAAG,CAAC,GACJC,QAAQ,GACRC,SAAS,CAAC,CAACC,IAAMA,KAAKC;AACxB,OAAO,MAAMC,kBAAkBV,EAAEW,MAAM,CAAC;IACvCC,IAAIZ,EAAEE,MAAM,CAACW,MAAM,GAAGP,QAAQ;IAC9BQ,KAAKd,EAAEe,KAAK,CAACf,EAAEE,MAAM,CAACW,MAAM,IAAIP,QAAQ;IACxCU,QAAQhB,EAAEa,MAAM,GAAGP,QAAQ,GAAGW,QAAQ,CAAC;IACvCC,SAASlB,EAAEe,KAAK,CAACf,EAAEmB,GAAG,IAAIb,QAAQ,GAAGW,QAAQ,CAAC;IAC9CG,OAAOpB,EAAEqB,MAAM,CAACrB,EAAEa,MAAM,IAAIb,EAAEmB,GAAG,IAAIb,QAAQ,GAAGW,QAAQ,CAAC;IACzDK,QAAQtB,EAAEa,MAAM,GAAGP,QAAQ;IAC3BiB,OAAOtB;IACPuB,QAAQvB;IACRwB,OAAOzB,EAAEe,KAAK,CAACf,EAAEa,MAAM,IAAIP,QAAQ,GAAGW,QAAQ,CAAC;IAC/CS,WAAWzB,cAAcgB,QAAQ,CAAC;IAClCU,YAAY1B,cAAcgB,QAAQ,CAAC;IACnCW,UAAU3B;IACV4B,QAAQ7B,EAAEa,MAAM,GAAGP,QAAQ;IAC3BwB,SAAS9B,EAAEE,MAAM,CAAC6B,OAAO,GAAGzB,QAAQ;AACrC,GAAG;AAOH,OAAO,SAAS0B,iBAAiBC,MAAkC,EAAE,GAAGC,IAAyB;IAChG,IAAIC,MAAMD,KAAKE,MAAM,CAAC,CAACC,GAAmBC;QACzC,IAAI,OAAOA,WAAW,YAAY;YACjC,MAAMC,SAASD,OAAOD;YACtB,wCAAwC;YACxC,OAAOE,UAAUF;QAClB;QAEA,IAAIG,IAAgCF;QACpC,IAAI,CAACE,GAAG,OAAOH;QAEf,2BAA2B;QAC3B,IAAIvB,MAAM;eAAKuB,EAAEvB,GAAG,IAAI,EAAE;eAAO0B,EAAE1B,GAAG,IAAI,EAAE;SAAE;QAC9C,OAAO;YACN,GAAGuB,CAAC;YACJ,GAAGG,CAAC;YACJ1B,KAAKA;YACLI,SAAS;mBAAKmB,EAAEnB,OAAO,IAAI,EAAE;mBAAOsB,EAAEtB,OAAO,IAAI,EAAE;aAAE;YACrDI,QAAQkB,EAAElB,MAAM,IAAIe,EAAEf,MAAM;QAE7B;IACD,GAAGW,UAAU,CAAC;IACd,OAAOvB,gBAAgB+B,KAAK,CAACN;AAC9B"}
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"sources":["../../src/resource/index.ts"],"sourcesContent":["export {
|
|
1
|
+
{"version":3,"sources":["../../src/resource/index.ts"],"sourcesContent":["export type { AnyResource } from './schema/AnyResourceSchema';\nexport type { Identifiable } from './Identifiable';\nexport { getTitleOfResource } from './getTitleOfResource';\nexport { type ListQueryInput, type ListQuery, resolveListQuery, ListQuerySchema } from './ListQuery';\n"],"names":["getTitleOfResource","resolveListQuery","ListQuerySchema"],"mappings":"AAEA,SAASA,kBAAkB,QAAQ,uBAAuB;AAC1D,SAA8CC,gBAAgB,EAAEC,eAAe,QAAQ,cAAc"}
|
package/lib/s3/formatS3Url.js
CHANGED
|
@@ -17,7 +17,7 @@ export function formatS3Url(o, { credentials, useParams } = {}) {
|
|
|
17
17
|
} else {
|
|
18
18
|
url = new URL(`https://${ep}`);
|
|
19
19
|
}
|
|
20
|
-
} catch (
|
|
20
|
+
} catch (_error) {
|
|
21
21
|
throw new Error(`Invalid endpoint: ${ep}`);
|
|
22
22
|
}
|
|
23
23
|
const { useSsl = true, region, pathStyle, port, accessKeyId, secretAccessKey, bucket } = o;
|
|
@@ -40,7 +40,7 @@ export function formatS3Url(o, { credentials, useParams } = {}) {
|
|
|
40
40
|
}
|
|
41
41
|
if (port) {
|
|
42
42
|
const portNum = Number(port);
|
|
43
|
-
if (isNaN(portNum) || portNum < 1 || portNum > 65535) {
|
|
43
|
+
if (Number.isNaN(portNum) || portNum < 1 || portNum > 65535) {
|
|
44
44
|
throw new Error('Port must be a valid number between 1 and 65535');
|
|
45
45
|
}
|
|
46
46
|
url.port = String(portNum);
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"sources":["../../src/s3/formatS3Url.ts"],"sourcesContent":["import type { ParsedS3Options } from './parseS3Url';\n\nfunction isValidBucketName(bucket: string): boolean {\n\tconst bucketRegex = /^[a-z0-9][a-z0-9.-]{1,61}[a-z0-9]$/;\n\treturn bucketRegex.test(bucket) && !bucket.includes('..') && !bucket.includes('.-') && !bucket.includes('-.');\n}\n\nexport function formatS3Url(\n\to: ParsedS3Options,\n\t{\n\t\tcredentials,\n\t\tuseParams,\n\t}: {\n\t\tcredentials?: boolean;\n\t\tuseParams?: boolean;\n\t} = {},\n): string {\n\tif (!o || typeof o !== 'object') {\n\t\tthrow new Error('S3 options must be an object');\n\t}\n\n\tif (!o.endpoint) {\n\t\tthrow new Error('Endpoint is required');\n\t}\n\n\tlet url: URL;\n\tlet ep = o.endpoint || 's3.amazonaws.com';\n\ttry {\n\t\tif (URL.canParse(ep)) {\n\t\t\turl = new URL(ep);\n\t\t} else {\n\t\t\turl = new URL(`https://${ep}`);\n\t\t}\n\t} catch (
|
|
1
|
+
{"version":3,"sources":["../../src/s3/formatS3Url.ts"],"sourcesContent":["import type { ParsedS3Options } from './parseS3Url';\n\nfunction isValidBucketName(bucket: string): boolean {\n\tconst bucketRegex = /^[a-z0-9][a-z0-9.-]{1,61}[a-z0-9]$/;\n\treturn bucketRegex.test(bucket) && !bucket.includes('..') && !bucket.includes('.-') && !bucket.includes('-.');\n}\n\nexport function formatS3Url(\n\to: ParsedS3Options,\n\t{\n\t\tcredentials,\n\t\tuseParams,\n\t}: {\n\t\tcredentials?: boolean;\n\t\tuseParams?: boolean;\n\t} = {},\n): string {\n\tif (!o || typeof o !== 'object') {\n\t\tthrow new Error('S3 options must be an object');\n\t}\n\n\tif (!o.endpoint) {\n\t\tthrow new Error('Endpoint is required');\n\t}\n\n\tlet url: URL;\n\tlet ep = o.endpoint || 's3.amazonaws.com';\n\ttry {\n\t\tif (URL.canParse(ep)) {\n\t\t\turl = new URL(ep);\n\t\t} else {\n\t\t\turl = new URL(`https://${ep}`);\n\t\t}\n\t} catch (_error) {\n\t\tthrow new Error(`Invalid endpoint: ${ep}`);\n\t}\n\n\tconst { useSsl = true, region, pathStyle, port, accessKeyId, secretAccessKey, bucket } = o;\n\turl.protocol = useSsl ? 'https:' : 'http:';\n\n\tif (credentials) {\n\t\tif (accessKeyId && secretAccessKey) {\n\t\t\turl.username = encodeURIComponent(accessKeyId);\n\t\t\turl.password = encodeURIComponent(secretAccessKey);\n\t\t} else {\n\t\t\tthrow new Error('Access Key ID and Secret Access Key are required for credentials');\n\t\t}\n\t}\n\n\tif (useParams) {\n\t\tif (region) {\n\t\t\turl.searchParams.set('region', region);\n\t\t}\n\t\tif (pathStyle !== undefined) {\n\t\t\turl.searchParams.set('pathStyle', String(pathStyle));\n\t\t}\n\t}\n\n\tif (port) {\n\t\tconst portNum = Number(port);\n\t\tif (Number.isNaN(portNum) || portNum < 1 || portNum > 65535) {\n\t\t\tthrow new Error('Port must be a valid number between 1 and 65535');\n\t\t}\n\t\turl.port = String(portNum);\n\t}\n\n\tif (bucket) {\n\t\tif (!isValidBucketName(bucket)) {\n\t\t\tthrow new Error(`Invalid bucket name: ${bucket}`);\n\t\t}\n\n\t\tif (pathStyle) {\n\t\t\turl.pathname = `/${bucket}${url.pathname}`;\n\t\t} else {\n\t\t\t// Check if bucket is already in hostname (virtual-hosted style)\n\t\t\tconst bucketPattern = new RegExp(`^${bucket.replace(/[.*+?^${}()|[\\]\\\\]/g, '\\\\$&')}\\\\.`);\n\t\t\tif (!bucketPattern.test(url.hostname)) {\n\t\t\t\turl.hostname = `${bucket}.${url.hostname}`;\n\t\t\t}\n\t\t}\n\t}\n\n\treturn url.toString();\n}\n"],"names":["isValidBucketName","bucket","bucketRegex","test","includes","formatS3Url","o","credentials","useParams","Error","endpoint","url","ep","URL","canParse","_error","useSsl","region","pathStyle","port","accessKeyId","secretAccessKey","protocol","username","encodeURIComponent","password","searchParams","set","undefined","String","portNum","Number","isNaN","pathname","bucketPattern","RegExp","replace","hostname","toString"],"mappings":"AAEA,SAASA,kBAAkBC,MAAc;IACxC,MAAMC,cAAc;IACpB,OAAOA,YAAYC,IAAI,CAACF,WAAW,CAACA,OAAOG,QAAQ,CAAC,SAAS,CAACH,OAAOG,QAAQ,CAAC,SAAS,CAACH,OAAOG,QAAQ,CAAC;AACzG;AAEA,OAAO,SAASC,YACfC,CAAkB,EAClB,EACCC,WAAW,EACXC,SAAS,EAIT,GAAG,CAAC,CAAC;IAEN,IAAI,CAACF,KAAK,OAAOA,MAAM,UAAU;QAChC,MAAM,IAAIG,MAAM;IACjB;IAEA,IAAI,CAACH,EAAEI,QAAQ,EAAE;QAChB,MAAM,IAAID,MAAM;IACjB;IAEA,IAAIE;IACJ,IAAIC,KAAKN,EAAEI,QAAQ,IAAI;IACvB,IAAI;QACH,IAAIG,IAAIC,QAAQ,CAACF,KAAK;YACrBD,MAAM,IAAIE,IAAID;QACf,OAAO;YACND,MAAM,IAAIE,IAAI,CAAC,QAAQ,EAAED,IAAI;QAC9B;IACD,EAAE,OAAOG,QAAQ;QAChB,MAAM,IAAIN,MAAM,CAAC,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IACD;IAEA,OAAO1B,IAAI2B,QAAQ;AACpB"}
|
package/lib/s3/parseS3Url.js
CHANGED
|
@@ -10,7 +10,7 @@ export function parseS3Url({ url = process.env.S3_URL, ...rest } = {}) {
|
|
|
10
10
|
let parsed;
|
|
11
11
|
try {
|
|
12
12
|
parsed = new URL(normalizedUrl);
|
|
13
|
-
} catch (
|
|
13
|
+
} catch (_error) {
|
|
14
14
|
throw new Error(`Invalid S3 URL: ${url}`);
|
|
15
15
|
}
|
|
16
16
|
const pathStyleParam = parsed.searchParams.get('pathStyle');
|
package/lib/s3/parseS3Url.js.map
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"sources":["../../src/s3/parseS3Url.ts"],"sourcesContent":["import { parseBoolean } from '@wener/utils';\n\nexport type ParsedS3Options = {\n\taccessKeyId?: string;\n\tsecretAccessKey?: string;\n\tregion?: string;\n\tuseSsl?: boolean;\n\tbucket?: string;\n\tendpoint: string;\n\tport?: number;\n\tpathStyle?: boolean;\n\turl?: string;\n};\n\nexport type ParseS3UrlOptions = Partial<ParsedS3Options>;\n\nfunction isValidIpAddress(hostname: string): boolean {\n\tconst ipv4Regex = /^(?:(?:25[0-5]|2[0-4][0-9]|[01]?[0-9][0-9]?)\\.){3}(?:25[0-5]|2[0-4][0-9]|[01]?[0-9][0-9]?)$/;\n\tconst ipv6Regex = /^\\[([0-9a-fA-F]{1,4}:){7}[0-9a-fA-F]{1,4}]$/;\n\treturn ipv4Regex.test(hostname) || ipv6Regex.test(hostname);\n}\n\nexport function parseS3Url({ url = process.env.S3_URL, ...rest }: ParseS3UrlOptions = {}): ParsedS3Options | undefined {\n\tif (!url) return undefined;\n\n\tconst normalizedUrl = url.startsWith('s3://') ? url.replace(/^s3:\\/\\//, 'https://') : url;\n\tlet parsed: URL;\n\ttry {\n\t\tparsed = new URL(normalizedUrl);\n\t} catch (
|
|
1
|
+
{"version":3,"sources":["../../src/s3/parseS3Url.ts"],"sourcesContent":["import { parseBoolean } from '@wener/utils';\n\nexport type ParsedS3Options = {\n\taccessKeyId?: string;\n\tsecretAccessKey?: string;\n\tregion?: string;\n\tuseSsl?: boolean;\n\tbucket?: string;\n\tendpoint: string;\n\tport?: number;\n\tpathStyle?: boolean;\n\turl?: string;\n};\n\nexport type ParseS3UrlOptions = Partial<ParsedS3Options>;\n\nfunction isValidIpAddress(hostname: string): boolean {\n\tconst ipv4Regex = /^(?:(?:25[0-5]|2[0-4][0-9]|[01]?[0-9][0-9]?)\\.){3}(?:25[0-5]|2[0-4][0-9]|[01]?[0-9][0-9]?)$/;\n\tconst ipv6Regex = /^\\[([0-9a-fA-F]{1,4}:){7}[0-9a-fA-F]{1,4}]$/;\n\treturn ipv4Regex.test(hostname) || ipv6Regex.test(hostname);\n}\n\nexport function parseS3Url({ url = process.env.S3_URL, ...rest }: ParseS3UrlOptions = {}): ParsedS3Options | undefined {\n\tif (!url) return undefined;\n\n\tconst normalizedUrl = url.startsWith('s3://') ? url.replace(/^s3:\\/\\//, 'https://') : url;\n\tlet parsed: URL;\n\ttry {\n\t\tparsed = new URL(normalizedUrl);\n\t} catch (_error) {\n\t\tthrow new Error(`Invalid S3 URL: ${url}`);\n\t}\n\n\tconst pathStyleParam = parsed.searchParams.get('pathStyle');\n\tlet pathStyle: boolean | undefined = rest.pathStyle;\n\tpathStyle ??= parseBoolean(pathStyleParam, true);\n\n\t// Auto-detect path style for IP addresses\n\tif (pathStyle === undefined && isValidIpAddress(parsed.hostname)) {\n\t\tpathStyle = true;\n\t}\n\n\tconst result: ParsedS3Options = {\n\t\taccessKeyId: parsed.username || undefined,\n\t\tsecretAccessKey: parsed.password || undefined,\n\t\tendpoint: parsed.hostname,\n\t\tport: parsed.port ? Number(parsed.port) : undefined,\n\t\tuseSsl: parsed.protocol === 'https:',\n\t\tregion: parsed.searchParams.get('region') || undefined,\n\t\tpathStyle,\n\t};\n\n\tif (!result.port) {\n\t\tif (result.useSsl) {\n\t\t\tresult.port = 443;\n\t\t} else {\n\t\t\tresult.port = 80;\n\t\t}\n\t}\n\n\tconst pathSegments = parsed.pathname.split('/').filter(Boolean);\n\tconst awsVirtualHostMatch = parsed.hostname.match(/^(.*?)\\.s3[.-]([a-z0-9-]+)?\\.?amazonaws\\.com$/);\n\n\tif (result.pathStyle) {\n\t\tresult.bucket = pathSegments[0];\n\t} else if (awsVirtualHostMatch) {\n\t\tresult.bucket = awsVirtualHostMatch[1];\n\t\tresult.endpoint = parsed.hostname;\n\t\tif (!result.region && awsVirtualHostMatch[2]) {\n\t\t\tresult.region = awsVirtualHostMatch[2];\n\t\t}\n\t\tresult.pathStyle = false;\n\t} else {\n\t\tresult.bucket = pathSegments[0];\n\t\tif (result.pathStyle === undefined) {\n\t\t\tresult.pathStyle = true;\n\t\t}\n\t}\n\n\t// Type-safe property assignment\n\tfor (const [key, value] of Object.entries(rest)) {\n\t\tif (value !== undefined && value !== null && key in result) {\n\t\t\t(result as Record<string, unknown>)[key] = value;\n\t\t}\n\t}\n\n\treturn result;\n}\n"],"names":["parseBoolean","isValidIpAddress","hostname","ipv4Regex","ipv6Regex","test","parseS3Url","url","process","env","S3_URL","rest","undefined","normalizedUrl","startsWith","replace","parsed","URL","_error","Error","pathStyleParam","searchParams","get","pathStyle","result","accessKeyId","username","secretAccessKey","password","endpoint","port","Number","useSsl","protocol","region","pathSegments","pathname","split","filter","Boolean","awsVirtualHostMatch","match","bucket","key","value","Object","entries"],"mappings":"AAAA,SAASA,YAAY,QAAQ,eAAe;AAgB5C,SAASC,iBAAiBC,QAAgB;IACzC,MAAMC,YAAY;IAClB,MAAMC,YAAY;IAClB,OAAOD,UAAUE,IAAI,CAACH,aAAaE,UAAUC,IAAI,CAACH;AACnD;AAEA,OAAO,SAASI,WAAW,EAAEC,MAAMC,QAAQC,GAAG,CAACC,MAAM,EAAE,GAAGC,MAAyB,GAAG,CAAC,CAAC;IACvF,IAAI,CAACJ,KAAK,OAAOK;IAEjB,MAAMC,gBAAgBN,IAAIO,UAAU,CAAC,WAAWP,IAA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YAC7ChB,OAAOU,MAAM,GAAGM,mBAAmB,CAAC,EAAE;QACvC;QACAhB,OAAOD,SAAS,GAAG;IACpB,OAAO;QACNC,OAAOkB,MAAM,GAAGP,YAAY,CAAC,EAAE;QAC/B,IAAIX,OAAOD,SAAS,KAAKX,WAAW;YACnCY,OAAOD,SAAS,GAAG;QACpB;IACD;IAEA,gCAAgC;IAChC,KAAK,MAAM,CAACoB,KAAKC,MAAM,IAAIC,OAAOC,OAAO,CAACnC,MAAO;QAChD,IAAIiC,UAAUhC,aAAagC,UAAU,QAAQD,OAAOnB,QAAQ;YAC1DA,MAAkC,CAACmB,IAAI,GAAGC;QAC5C;IACD;IAEA,OAAOpB;AACR"}
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"sources":["../../src/schema/SchemaRegistry.ts"],"sourcesContent":["import { getGlobalStates } from '@wener/utils';\nimport type { JsonSchemaDef } from '../jsonschema';\nimport { toJsonSchema, type SchemaOutput, type TypeSchema } from './index';\n\nexport namespace SchemaRegistry {\n\tconst types = getGlobalStates('@wener/common/resource/schema/SchemaRegistry', () => new Map<string, JsonSchemaDef>());\n\n\texport function get(name: string): JsonSchemaDef;\n\texport function get<S extends TypeSchema>(schema: S): JsonSchemaDef<SchemaOutput<S>>;\n\texport function get(needle: TypeSchema | string) {\n\t\tlet key = getKey(needle);\n\t\tlet found = types.get(key);\n\t\tif (found) {\n\t\t\treturn found;\n\t\t} else {\n\t\t\tif (needle && typeof needle !== 'string') {\n\t\t\t\treturn toJsonSchema(needle);\n\t\t\t}\n\t\t}\n\t\tthrow new Error(`Schema not found: ${key}`);\n\t}\n\n\tfunction getKey(s: TypeSchema | string) {\n\t\tlet key;\n\t\tif (typeof s === 'string') {\n\t\t\tkey = s;\n\t\t} else {\n\t\t\tlet js = toJsonSchema(s);\n\t\t\tkey = js.$id || js.title;\n\t\t}\n\t\tif (!key) {\n\t\t\tthrow new Error(`Schema must have $id or title`);\n\t\t}\n\t\treturn key;\n\t}\n\n\texport function set(key: TypeSchema | string, def: TypeSchema): void;\n\texport function set(key: TypeSchema, def?: TypeSchema): void;\n\texport function set(key: TypeSchema | string, def?: TypeSchema) {\n\t\tif (!def) {\n\t\t\tdef = key as TypeSchema;\n\t\t\tif (!def || typeof def !== 'object') {\n\t\t\t\tthrow new Error(`Invalid schema definition for: ${getKey(key)}`);\n\t\t\t}\n\t\t}\n\t\ttypes.set(getKey(key), toJsonSchema(def));\n\t}\n}\n"],"names":["getGlobalStates","toJsonSchema","SchemaRegistry","types","Map","get","needle","key","getKey","found","Error","s","js","$id","title","set","def"],"mappings":"AAAA,SAASA,eAAe,QAAQ,eAAe;AAE/C,SAASC,YAAY,QAA4C,UAAU;UAE1DC;IAChB,MAAMC,QAAQH,gBAAgB,gDAAgD,IAAM,IAAII;IAIjF,SAASC,IAAIC,MAA2B;QAC9C,IAAIC,MAAMC,OAAOF;QACjB,IAAIG,QAAQN,MAAME,GAAG,CAACE;QACtB,IAAIE,OAAO;YACV,OAAOA;QACR,OAAO;YACN,IAAIH,UAAU,OAAOA,WAAW,UAAU;gBACzC,OAAOL,aAAaK;YACrB;QACD;QACA,MAAM,IAAII,MAAM,CAAC,kBAAkB,EAAEH,KAAK;IAC3C;mBAXgBF,MAAAA;IAahB,SAASG,OAAOG,CAAsB;QACrC,IAAIJ;QACJ,IAAI,OAAOI,MAAM,UAAU;YAC1BJ,MAAMI;QACP,OAAO;YACN,IAAIC,KAAKX,aAAaU;YACtBJ,MAAMK,GAAGC,GAAG,IAAID,GAAGE,KAAK;QACzB;QACA,IAAI,CAACP,KAAK;YACT,MAAM,IAAIG,MAAM,CAAC,6BAA6B,CAAC;QAChD;QACA,OAAOH;IACR;IAIO,SAASQ,IAAIR,GAAwB,EAAES,GAAgB;QAC7D,IAAI,CAACA,KAAK;YACTA,MAAMT;YACN,IAAI,CAACS,OAAO,OAAOA,QAAQ,UAAU;gBACpC,MAAM,IAAIN,MAAM,CAAC,+BAA+B,EAAEF,OAAOD,MAAM;YAChE;QACD;QACAJ,MAAMY,GAAG,CAACP,OAAOD,MAAMN,aAAae;IACrC;mBARgBD,MAAAA;AASjB,GA3CiBb,mBAAAA"}
|
|
1
|
+
{"version":3,"sources":["../../src/schema/SchemaRegistry.ts"],"sourcesContent":["import { getGlobalStates } from '@wener/utils';\nimport type { JsonSchemaDef } from '../jsonschema';\nimport { toJsonSchema, type SchemaOutput, type TypeSchema } from './index';\n\nexport namespace SchemaRegistry {\n\tconst types = getGlobalStates('@wener/common/resource/schema/SchemaRegistry', () => new Map<string, JsonSchemaDef>());\n\n\texport function get(name: string): JsonSchemaDef;\n\texport function get<S extends TypeSchema>(schema: S): JsonSchemaDef<SchemaOutput<S>>;\n\texport function get(needle: TypeSchema | string) {\n\t\tlet key = getKey(needle);\n\t\tlet found = types.get(key);\n\t\tif (found) {\n\t\t\treturn found;\n\t\t} else {\n\t\t\tif (needle && typeof needle !== 'string') {\n\t\t\t\treturn toJsonSchema(needle);\n\t\t\t}\n\t\t}\n\t\tthrow new Error(`Schema not found: ${key}`);\n\t}\n\n\tfunction getKey(s: TypeSchema | string) {\n\t\tlet key: string | undefined;\n\t\tif (typeof s === 'string') {\n\t\t\tkey = s;\n\t\t} else {\n\t\t\tlet js = toJsonSchema(s);\n\t\t\tkey = js.$id || js.title;\n\t\t}\n\t\tif (!key) {\n\t\t\tthrow new Error(`Schema must have $id or title`);\n\t\t}\n\t\treturn key;\n\t}\n\n\texport function set(key: TypeSchema | string, def: TypeSchema): void;\n\texport function set(key: TypeSchema, def?: TypeSchema): void;\n\texport function set(key: TypeSchema | string, def?: TypeSchema) {\n\t\tif (!def) {\n\t\t\tdef = key as TypeSchema;\n\t\t\tif (!def || typeof def !== 'object') {\n\t\t\t\tthrow new Error(`Invalid schema definition for: ${getKey(key)}`);\n\t\t\t}\n\t\t}\n\t\ttypes.set(getKey(key), toJsonSchema(def));\n\t}\n}\n"],"names":["getGlobalStates","toJsonSchema","SchemaRegistry","types","Map","get","needle","key","getKey","found","Error","s","js","$id","title","set","def"],"mappings":"AAAA,SAASA,eAAe,QAAQ,eAAe;AAE/C,SAASC,YAAY,QAA4C,UAAU;UAE1DC;IAChB,MAAMC,QAAQH,gBAAgB,gDAAgD,IAAM,IAAII;IAIjF,SAASC,IAAIC,MAA2B;QAC9C,IAAIC,MAAMC,OAAOF;QACjB,IAAIG,QAAQN,MAAME,GAAG,CAACE;QACtB,IAAIE,OAAO;YACV,OAAOA;QACR,OAAO;YACN,IAAIH,UAAU,OAAOA,WAAW,UAAU;gBACzC,OAAOL,aAAaK;YACrB;QACD;QACA,MAAM,IAAII,MAAM,CAAC,kBAAkB,EAAEH,KAAK;IAC3C;mBAXgBF,MAAAA;IAahB,SAASG,OAAOG,CAAsB;QACrC,IAAIJ;QACJ,IAAI,OAAOI,MAAM,UAAU;YAC1BJ,MAAMI;QACP,OAAO;YACN,IAAIC,KAAKX,aAAaU;YACtBJ,MAAMK,GAAGC,GAAG,IAAID,GAAGE,KAAK;QACzB;QACA,IAAI,CAACP,KAAK;YACT,MAAM,IAAIG,MAAM,CAAC,6BAA6B,CAAC;QAChD;QACA,OAAOH;IACR;IAIO,SAASQ,IAAIR,GAAwB,EAAES,GAAgB;QAC7D,IAAI,CAACA,KAAK;YACTA,MAAMT;YACN,IAAI,CAACS,OAAO,OAAOA,QAAQ,UAAU;gBACpC,MAAM,IAAIN,MAAM,CAAC,+BAA+B,EAAEF,OAAOD,MAAM;YAChE;QACD;QACAJ,MAAMY,GAAG,CAACP,OAAOD,MAAMN,aAAae;IACrC;mBARgBD,MAAAA;AASjB,GA3CiBb,mBAAAA"}
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"sources":["../../src/schema/TypeSchema.d.ts"],"sourcesContent":["import type {\n\tTSchema,\n\tStaticDecode as TypeBoxStaticDecode,\n\tStaticEncode as TypeBoxStaticEncode,\n} from '@sinclair/typebox';\nimport type { StandardSchemaV1 } from '@standard-schema/spec';\nimport type { z } from 'zod/v4';\nimport type { JsonSchemaDef } from '../jsonschema';\n\nexport type TypeSchema<I = unknown, O = I> = TSchema | z.ZodSchema<O, I> | JsonSchemaDef | StandardSchemaV1<I, O>;\n\nexport type SchemaOutput<S extends TypeSchema> =\n\tS extends StandardSchemaV1<infer
|
|
1
|
+
{"version":3,"sources":["../../src/schema/TypeSchema.d.ts"],"sourcesContent":["import type {\n\tTSchema,\n\tStaticDecode as TypeBoxStaticDecode,\n\tStaticEncode as TypeBoxStaticEncode,\n} from '@sinclair/typebox';\nimport type { StandardSchemaV1 } from '@standard-schema/spec';\nimport type { z } from 'zod/v4';\nimport type { JsonSchemaDef } from '../jsonschema';\n\nexport type TypeSchema<I = unknown, O = I> = TSchema | z.ZodSchema<O, I> | JsonSchemaDef | StandardSchemaV1<I, O>;\n\nexport type SchemaOutput<S extends TypeSchema> =\n\tS extends StandardSchemaV1<infer _I, infer O>\n\t\t? O\n\t\t: S extends z.ZodSchema<infer O, infer _I>\n\t\t\t? O\n\t\t\t: S extends TSchema\n\t\t\t\t? TypeBoxStaticEncode<S>\n\t\t\t\t: S extends JsonSchemaDef<infer _I, infer O>\n\t\t\t\t\t? O\n\t\t\t\t\t: never;\n\nexport type SchemaInput<S extends TypeSchema> =\n\tS extends StandardSchemaV1<infer I, infer _O>\n\t\t? I\n\t\t: S extends z.ZodSchema<infer _O, infer I>\n\t\t\t? I\n\t\t\t: S extends TSchema\n\t\t\t\t? TypeBoxStaticDecode<S>\n\t\t\t\t: S extends JsonSchemaDef<infer I, infer _O>\n\t\t\t\t\t? I\n\t\t\t\t\t: never;\n"],"names":[],"mappings":"AAsBA,WASa"}
|
|
@@ -44,9 +44,9 @@ function _create(schema, options, ctx) {
|
|
|
44
44
|
});
|
|
45
45
|
}).with({
|
|
46
46
|
type: "string"
|
|
47
|
-
}, (
|
|
47
|
+
}, (_schema) => "").with({
|
|
48
48
|
type: P.union("number", "integer")
|
|
49
|
-
}, (
|
|
49
|
+
}, (_schema) => 0).with({
|
|
50
50
|
type: "object"
|
|
51
51
|
}, () => {
|
|
52
52
|
const out = {};
|
|
@@ -65,9 +65,9 @@ function _create(schema, options, ctx) {
|
|
|
65
65
|
type: "null"
|
|
66
66
|
}, () => null).with({
|
|
67
67
|
type: "boolean"
|
|
68
|
-
}, (
|
|
68
|
+
}, (_schema) => false).with({
|
|
69
69
|
type: "array"
|
|
70
|
-
}, (
|
|
70
|
+
}, (_schema) => []).otherwise(() => {
|
|
71
71
|
return undefined;
|
|
72
72
|
});
|
|
73
73
|
}
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"sources":["../../src/schema/createSchemaData.ts"],"sourcesContent":["import { match, P } from 'ts-pattern';\nimport type { JsonSchemaDef } from '../jsonschema';\nimport { toJsonSchema } from './toJsonSchema';\nimport type { SchemaOutput, TypeSchema } from './TypeSchema';\n\nexport function createSchemaData<S extends TypeSchema>(\n\tts: S,\n\toptions: CreateSchemaDataOptions = {},\n): Partial<SchemaOutput<S>> {\n\tconst schema = toJsonSchema(ts);\n\treturn createJsonSchemaData(schema, options);\n}\n\ntype CreateSchemaDataOptions = Partial<CreateOptions> & {\n\tall?: boolean;\n};\n\nfunction createJsonSchemaData(schema: JsonSchemaDef, options: CreateSchemaDataOptions): any {\n\tlet skip: CreateOptions['skip'] = (s, ctx) => Boolean(!ctx.required && s.nullable);\n\tif (options.all) {\n\t\tskip = () => false;\n\t}\n\tif (options.skip) {\n\t\tskip = options.skip;\n\t}\n\treturn _create(\n\t\tschema,\n\t\t{\n\t\t\tskip,\n\t\t},\n\t\t{ required: false },\n\t);\n}\n\ntype CreateOptions = {\n\tskip: (schema: JsonSchemaDef, ctx: { required: boolean }) => boolean;\n};\n\nfunction _create(schema: JsonSchemaDef, options: CreateOptions, ctx: { required: boolean }): any {\n\tconst { skip } = options;\n\tif (skip(schema, ctx)) {\n\t\treturn schema.default;\n\t}\n\tif (schema.default !== undefined) {\n\t\treturn schema.default;\n\t}\n\treturn match(schema as JsonSchemaDef)\n\t\t.returnType<any>()\n\t\t.with({ default: P.select() }, (v) => v)\n\t\t.with({ const: P.nonNullable }, (v) => v.const)\n\t\t.with({ anyOf: P.nonNullable }, (schema) => {\n\t\t\treturn _create(schema.anyOf[0], options, { required: false });\n\t\t})\n\t\t.with({ oneOf: P.nonNullable }, (schema) => {\n\t\t\treturn _create(schema.oneOf[0], options, { required: false });\n\t\t})\n\t\t.with({ type: 'string' }, (
|
|
1
|
+
{"version":3,"sources":["../../src/schema/createSchemaData.ts"],"sourcesContent":["import { match, P } from 'ts-pattern';\nimport type { JsonSchemaDef } from '../jsonschema';\nimport { toJsonSchema } from './toJsonSchema';\nimport type { SchemaOutput, TypeSchema } from './TypeSchema';\n\nexport function createSchemaData<S extends TypeSchema>(\n\tts: S,\n\toptions: CreateSchemaDataOptions = {},\n): Partial<SchemaOutput<S>> {\n\tconst schema = toJsonSchema(ts);\n\treturn createJsonSchemaData(schema, options);\n}\n\ntype CreateSchemaDataOptions = Partial<CreateOptions> & {\n\tall?: boolean;\n};\n\nfunction createJsonSchemaData(schema: JsonSchemaDef, options: CreateSchemaDataOptions): any {\n\tlet skip: CreateOptions['skip'] = (s, ctx) => Boolean(!ctx.required && s.nullable);\n\tif (options.all) {\n\t\tskip = () => false;\n\t}\n\tif (options.skip) {\n\t\tskip = options.skip;\n\t}\n\treturn _create(\n\t\tschema,\n\t\t{\n\t\t\tskip,\n\t\t},\n\t\t{ required: false },\n\t);\n}\n\ntype CreateOptions = {\n\tskip: (schema: JsonSchemaDef, ctx: { required: boolean }) => boolean;\n};\n\nfunction _create(schema: JsonSchemaDef, options: CreateOptions, ctx: { required: boolean }): any {\n\tconst { skip } = options;\n\tif (skip(schema, ctx)) {\n\t\treturn schema.default;\n\t}\n\tif (schema.default !== undefined) {\n\t\treturn schema.default;\n\t}\n\treturn match(schema as JsonSchemaDef)\n\t\t.returnType<any>()\n\t\t.with({ default: P.select() }, (v) => v)\n\t\t.with({ const: P.nonNullable }, (v) => v.const)\n\t\t.with({ anyOf: P.nonNullable }, (schema) => {\n\t\t\treturn _create(schema.anyOf[0], options, { required: false });\n\t\t})\n\t\t.with({ oneOf: P.nonNullable }, (schema) => {\n\t\t\treturn _create(schema.oneOf[0], options, { required: false });\n\t\t})\n\t\t.with({ type: 'string' }, (_schema) => '')\n\t\t.with({ type: P.union('number', 'integer') }, (_schema) => 0)\n\t\t.with({ type: 'object' }, () => {\n\t\t\tconst out: Record<string, any> = {};\n\n\t\t\tlet required = Array.isArray(schema.required) ? schema.required : [];\n\t\t\tfor (const [k, v] of Object.entries(schema.properties || {}) as [string, JsonSchemaDef][]) {\n\t\t\t\tconst value = _create(v, options, {\n\t\t\t\t\trequired: required.includes(k),\n\t\t\t\t});\n\t\t\t\tif (value === undefined) {\n\t\t\t\t\tcontinue;\n\t\t\t\t}\n\t\t\t\tout[k] = value;\n\t\t\t}\n\n\t\t\treturn out;\n\t\t})\n\t\t.with({ type: 'null' }, () => null)\n\t\t.with({ type: 'boolean' }, (_schema) => false)\n\t\t.with({ type: 'array' }, (_schema) => [])\n\t\t.otherwise(() => {\n\t\t\treturn undefined;\n\t\t});\n}\n"],"names":["match","P","toJsonSchema","createSchemaData","ts","options","schema","createJsonSchemaData","skip","s","ctx","Boolean","required","nullable","all","_create","default","undefined","returnType","with","select","v","const","nonNullable","anyOf","oneOf","type","_schema","union","out","Array","isArray","k","Object","entries","properties","value","includes","otherwise"],"mappings":"AAAA,SAASA,KAAK,EAAEC,CAAC,QAAQ,aAAa;AAEtC,SAASC,YAAY,QAAQ,iBAAiB;AAG9C,OAAO,SAASC,iBACfC,EAAK,EACLC,UAAmC,CAAC,CAAC;IAErC,MAAMC,SAASJ,aAAaE;IAC5B,OAAOG,qBAAqBD,QAAQD;AACrC;AAMA,SAASE,qBAAqBD,MAAqB,EAAED,OAAgC;IACpF,IAAIG,OAA8B,CAACC,GAAGC,MAAQC,QAAQ,CAACD,IAAIE,QAAQ,IAAIH,EAAEI,QAAQ;IACjF,IAAIR,QAAQS,GAAG,EAAE;QAChBN,OAAO,IAAM;IACd;IACA,I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AAO6B,UAAU,IAAI,CAAC,GAAiC;YAC1F,MAAMC,QAAQrB,QAAQM,GAAGhB,SAAS;gBACjCO,UAAUA,SAASyB,QAAQ,CAACL;YAC7B;YACA,IAAII,UAAUnB,WAAW;gBACxB;YACD;YACAY,GAAG,CAACG,EAAE,GAAGI;QACV;QAEA,OAAOP;IACR,GACCV,IAAI,CAAC;QAAEO,MAAM;IAAO,GAAG,IAAM,MAC7BP,IAAI,CAAC;QAAEO,MAAM;IAAU,GAAG,CAACC,UAAY,OACvCR,IAAI,CAAC;QAAEO,MAAM;IAAQ,GAAG,CAACC,UAAY,EAAE,EACvCW,SAAS,CAAC;QACV,OAAOrB;IACR;AACF"}
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"sources":["../../src/schema/findJsonSchemaByPath.ts"],"sourcesContent":["import { firstOfMaybeArray } from '@wener/utils';\nimport { toJsonSchema } from './toJsonSchema';\nimport type { TypeSchema } from './TypeSchema';\n\nexport function findJsonSchemaByPath(schema: TypeSchema, objectPath: string) {\n\tschema = toJsonSchema(schema);\n\tif (!objectPath || !schema) {\n\t\treturn undefined;\n\t}\n\n\tconst segments = objectPath.split('.');\n\tlet currentSchema = schema;\n\n\tfor (const segment of segments) {\n\t\t// 检查当前 schema 是否是对象类型且有 properties\n\t\tif (\n\t\t\tcurrentSchema
|
|
1
|
+
{"version":3,"sources":["../../src/schema/findJsonSchemaByPath.ts"],"sourcesContent":["import { firstOfMaybeArray } from '@wener/utils';\nimport { toJsonSchema } from './toJsonSchema';\nimport type { TypeSchema } from './TypeSchema';\n\nexport function findJsonSchemaByPath(schema: TypeSchema, objectPath: string) {\n\tschema = toJsonSchema(schema);\n\tif (!objectPath || !schema) {\n\t\treturn undefined;\n\t}\n\n\tconst segments = objectPath.split('.');\n\tlet currentSchema = schema;\n\n\tfor (const segment of segments) {\n\t\t// 检查当前 schema 是否是对象类型且有 properties\n\t\tif (\n\t\t\tcurrentSchema &&\n\t\t\ttypeof currentSchema === 'object' &&\n\t\t\tcurrentSchema.properties &&\n\t\t\tcurrentSchema.properties[segment]\n\t\t) {\n\t\t\tcurrentSchema = currentSchema.properties[segment];\n\t\t\tcontinue;\n\t\t}\n\n\t\tif (/^\\d$/.test(segment) || segment === '[]') {\n\t\t\tif (currentSchema.items) {\n\t\t\t\tcurrentSchema = firstOfMaybeArray(currentSchema.items);\n\t\t\t\tcontinue;\n\t\t\t}\n\t\t}\n\n\t\treturn undefined;\n\t}\n\n\treturn currentSchema;\n}\n"],"names":["firstOfMaybeArray","toJsonSchema","findJsonSchemaByPath","schema","objectPath","undefined","segments","split","currentSchema","segment","properties","test","items"],"mappings":"AAAA,SAASA,iBAAiB,QAAQ,eAAe;AACjD,SAASC,YAAY,QAAQ,iBAAiB;AAG9C,OAAO,SAASC,qBAAqBC,MAAkB,EAAEC,UAAkB;IAC1ED,SAASF,aAAaE;IACtB,IAAI,CAACC,cAAc,CAACD,QAAQ;QAC3B,OAAOE;IACR;IAEA,MAAMC,WAAWF,WAAWG,KAAK,CAAC;IAClC,IAAIC,gBAAgBL;IAEpB,KAAK,MAAMM,WAAWH,SAAU;QAC/B,mCAAmC;QACnC,IACCE,iBACA,OAAOA,kBAAkB,YACzBA,cAAcE,UAAU,IACxBF,cAAcE,UAAU,CAACD,QAAQ,EAChC;YACDD,gBAAgBA,cAAcE,UAAU,CAACD,QAAQ;YACjD;QACD;QAEA,IAAI,OAAOE,IAAI,CAACF,YAAYA,YAAY,MAAM;YAC7C,IAAID,cAAcI,KAAK,EAAE;gBACxBJ,gBAAgBR,kBAAkBQ,cAAcI,KAAK;gBACrD;YACD;QACD;QAEA,OAAOP;IACR;IAEA,OAAOG;AACR"}
|
|
@@ -25,81 +25,91 @@ export function formatZodError(error, schema) {
|
|
|
25
25
|
}
|
|
26
26
|
return messages.join("\uFF1B");
|
|
27
27
|
}
|
|
28
|
-
function formatIssueMessage(issue,
|
|
28
|
+
function formatIssueMessage(issue, _schema) {
|
|
29
29
|
let message = issue.message;
|
|
30
30
|
// 处理常见的错误类型,生成更友好的消息
|
|
31
|
-
|
|
32
|
-
const code = issue.code;
|
|
33
|
-
switch (code) {
|
|
31
|
+
switch (issue.code) {
|
|
34
32
|
case "invalid_type":
|
|
35
33
|
{
|
|
36
|
-
const
|
|
37
|
-
|
|
34
|
+
const i = issue;
|
|
35
|
+
// Zod v4 doesn't have 'received' field directly, extract from message
|
|
36
|
+
const match = issue.message.match(/received (\w+)/);
|
|
37
|
+
const received = match?.[1];
|
|
38
|
+
if (received === "undefined") {
|
|
38
39
|
message = "\u5FC5\u586B";
|
|
39
40
|
}
|
|
40
|
-
else if (
|
|
41
|
+
else if (received === "null") {
|
|
41
42
|
message = "\u4E0D\u80FD\u4E3A\u7A7A";
|
|
42
43
|
}
|
|
43
44
|
else {
|
|
44
|
-
message = issue.message || `期望类型 ${
|
|
45
|
+
message = issue.message || `期望类型 ${i.expected},但收到 ${received}`;
|
|
45
46
|
}
|
|
46
47
|
break;
|
|
47
48
|
}
|
|
48
|
-
case "
|
|
49
|
+
case "invalid_format":
|
|
49
50
|
{
|
|
50
|
-
const
|
|
51
|
-
if (
|
|
51
|
+
const i = issue;
|
|
52
|
+
if (i.format === "email") {
|
|
52
53
|
message = "\u8BF7\u8F93\u5165\u6709\u6548\u7684\u90AE\u7BB1\u5730\u5740";
|
|
53
54
|
}
|
|
54
|
-
else if (
|
|
55
|
+
else if (i.format === "url") {
|
|
55
56
|
message = "\u8BF7\u8F93\u5165\u6709\u6548\u7684 URL";
|
|
56
57
|
}
|
|
57
|
-
else if (
|
|
58
|
+
else if (i.format === "uuid") {
|
|
58
59
|
message = "\u8BF7\u8F93\u5165\u6709\u6548\u7684 UUID";
|
|
59
60
|
}
|
|
60
|
-
else if (
|
|
61
|
+
else if (i.format === "date") {
|
|
61
62
|
message = "\u8BF7\u8F93\u5165\u6709\u6548\u7684\u65E5\u671F";
|
|
62
63
|
}
|
|
63
64
|
break;
|
|
64
65
|
}
|
|
65
66
|
case "too_small":
|
|
66
67
|
{
|
|
67
|
-
const
|
|
68
|
-
if (
|
|
68
|
+
const i = issue;
|
|
69
|
+
if (i.origin === "string" && i.minimum === 1) {
|
|
69
70
|
message = "\u4E0D\u80FD\u4E3A\u7A7A";
|
|
70
71
|
}
|
|
71
|
-
else if (
|
|
72
|
-
message = `至少需要 ${
|
|
72
|
+
else if (i.origin === "string") {
|
|
73
|
+
message = `至少需要 ${i.minimum} 个字符`;
|
|
73
74
|
}
|
|
74
|
-
else if (
|
|
75
|
-
message = `至少需要 ${
|
|
75
|
+
else if (i.origin === "number" || i.origin === "int") {
|
|
76
|
+
message = `至少需要 ${i.minimum}`;
|
|
77
|
+
}
|
|
78
|
+
else if (i.origin === "array") {
|
|
79
|
+
message = `至少需要 ${i.minimum} 项`;
|
|
76
80
|
}
|
|
77
81
|
break;
|
|
78
82
|
}
|
|
79
83
|
case "too_big":
|
|
80
84
|
{
|
|
81
|
-
const
|
|
82
|
-
if (
|
|
83
|
-
message = `最多 ${
|
|
85
|
+
const i = issue;
|
|
86
|
+
if (i.origin === "string") {
|
|
87
|
+
message = `最多 ${i.maximum} 个字符`;
|
|
84
88
|
}
|
|
85
|
-
else if (
|
|
86
|
-
message = `最多 ${
|
|
89
|
+
else if (i.origin === "number" || i.origin === "int") {
|
|
90
|
+
message = `最多 ${i.maximum}`;
|
|
87
91
|
}
|
|
88
|
-
else if (
|
|
89
|
-
message = `最多 ${
|
|
92
|
+
else if (i.origin === "array") {
|
|
93
|
+
message = `最多 ${i.maximum} 项`;
|
|
90
94
|
}
|
|
91
95
|
break;
|
|
92
96
|
}
|
|
93
|
-
case "
|
|
97
|
+
case "invalid_value":
|
|
94
98
|
{
|
|
95
|
-
const
|
|
96
|
-
|
|
99
|
+
const i = issue;
|
|
100
|
+
if (i.values.length === 1) {
|
|
101
|
+
// Single value means it's a literal check
|
|
102
|
+
message = `必须是 ${String(i.values[0])}`;
|
|
103
|
+
}
|
|
104
|
+
else {
|
|
105
|
+
message = `必须是以下值之一: ${i.values.map(String).join(", ")}`;
|
|
106
|
+
}
|
|
97
107
|
break;
|
|
98
108
|
}
|
|
99
109
|
case "unrecognized_keys":
|
|
100
110
|
{
|
|
101
|
-
const
|
|
102
|
-
message = `不支持的字段: ${
|
|
111
|
+
const i = issue;
|
|
112
|
+
message = `不支持的字段: ${i.keys.join(", ")}`;
|
|
103
113
|
break;
|
|
104
114
|
}
|
|
105
115
|
case "invalid_union":
|
|
@@ -107,18 +117,6 @@ function formatIssueMessage(issue, schema) {
|
|
|
107
117
|
message = "\u4E0D\u7B26\u5408\u4EFB\u4F55\u5141\u8BB8\u7684\u7C7B\u578B";
|
|
108
118
|
break;
|
|
109
119
|
}
|
|
110
|
-
case "invalid_union_discriminator":
|
|
111
|
-
{
|
|
112
|
-
const discriminatorIssue = issue;
|
|
113
|
-
message = `必须是以下值之一: ${discriminatorIssue.options?.map(String).join(", ") || "\u672A\u77E5\u9009\u9879"}`;
|
|
114
|
-
break;
|
|
115
|
-
}
|
|
116
|
-
case "invalid_literal":
|
|
117
|
-
{
|
|
118
|
-
const literalIssue = issue;
|
|
119
|
-
message = `必须是 ${String(literalIssue.expected)}`;
|
|
120
|
-
break;
|
|
121
|
-
}
|
|
122
120
|
case "custom":
|
|
123
121
|
{
|
|
124
122
|
// 保留自定义错误消息
|