@wener/common 1.0.2 → 1.0.4
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/DivisionCode.js +311 -0
- package/lib/cn/DivisionCode.js.map +1 -0
- package/lib/cn/Mod11Checksum.js +42 -0
- package/lib/cn/Mod11Checksum.js.map +1 -0
- package/lib/cn/Mod31Checksum.js +48 -0
- package/lib/cn/Mod31Checksum.js.map +1 -0
- package/lib/cn/ResidentIdentityCardNumber.js +50 -0
- package/lib/cn/ResidentIdentityCardNumber.js.map +1 -0
- package/lib/cn/UnifiedSocialCreditCode.js +118 -0
- package/lib/cn/UnifiedSocialCreditCode.js.map +1 -0
- package/lib/cn/formatDate.js +15 -0
- package/lib/cn/formatDate.js.map +1 -0
- package/lib/cn/index.js +4 -0
- package/lib/cn/index.js.map +1 -0
- package/lib/cn/parseSex.js +22 -0
- package/lib/cn/parseSex.js.map +1 -0
- package/lib/cn/types.d.js +8 -0
- package/lib/cn/types.d.js.map +1 -0
- package/lib/data/formatSort.js +15 -0
- package/lib/data/formatSort.js.map +1 -0
- package/lib/data/index.js +4 -0
- package/lib/data/index.js.map +1 -0
- package/lib/data/maybeNumber.js +22 -0
- package/lib/data/maybeNumber.js.map +1 -0
- package/lib/data/parseSort.js +95 -0
- package/lib/data/parseSort.js.map +1 -0
- package/lib/data/resolvePagination.js +36 -0
- package/lib/data/resolvePagination.js.map +1 -0
- package/lib/data/types.d.js +3 -0
- package/lib/data/types.d.js.map +1 -0
- package/lib/index.js +6 -2
- package/lib/index.js.map +1 -1
- package/lib/jsonschema/JsonSchema.js +4 -4
- package/lib/jsonschema/JsonSchema.js.map +1 -1
- package/lib/jsonschema/types.d.js.map +1 -1
- package/lib/meta/defineFileType.js +44 -0
- package/lib/meta/defineFileType.js.map +1 -0
- package/lib/meta/defineInit.js.map +1 -1
- package/lib/meta/defineMetadata.js +14 -3
- package/lib/meta/defineMetadata.js.map +1 -1
- package/lib/meta/index.js +1 -0
- package/lib/meta/index.js.map +1 -1
- package/lib/password/PHC.js +8 -8
- package/lib/password/PHC.js.map +1 -1
- package/lib/password/Password.js.map +1 -1
- package/lib/password/createArgon2PasswordAlgorithm.js.map +1 -1
- package/lib/password/createBase64PasswordAlgorithm.js.map +1 -1
- package/lib/password/createBcryptPasswordAlgorithm.js.map +1 -1
- package/lib/password/createPBKDF2PasswordAlgorithm.js.map +1 -1
- package/lib/password/createScryptPasswordAlgorithm.js.map +1 -1
- package/lib/search/AdvanceSearch.js.map +1 -1
- package/lib/search/formatAdvanceSearch.js +1 -1
- package/lib/search/formatAdvanceSearch.js.map +1 -1
- package/lib/search/optimizeAdvanceSearch.js.map +1 -1
- package/lib/search/parseAdvanceSearch.js.map +1 -1
- package/lib/search/parser.d.js.map +1 -1
- package/lib/search/parser.js +380 -76
- package/lib/search/parser.js.map +1 -1
- package/lib/search/types.d.js.map +1 -1
- package/lib/tools/renderJsonSchemaToMarkdownDoc.js.map +1 -1
- package/package.json +14 -5
- package/src/cn/DivisionCode.test.ts +43 -0
- package/src/cn/DivisionCode.ts +209 -0
- package/src/cn/Mod11Checksum.ts +24 -0
- package/src/cn/Mod31Checksum.ts +36 -0
- package/src/cn/ResidentIdentityCardNumber.test.ts +17 -0
- package/src/cn/ResidentIdentityCardNumber.ts +96 -0
- package/src/cn/UnifiedSocialCreditCode.test.ts +16 -0
- package/src/cn/UnifiedSocialCreditCode.ts +143 -0
- package/src/cn/__snapshots__/ResidentIdentityCardNumber.test.ts.snap +15 -0
- package/src/cn/__snapshots__/UnifiedSocialCreditCode.test.ts.snap +41 -0
- package/src/cn/formatDate.ts +12 -0
- package/src/cn/index.ts +3 -0
- package/src/cn/parseSex.ts +13 -0
- package/src/cn/types.d.ts +51 -0
- package/src/data/formatSort.test.ts +13 -0
- package/src/data/formatSort.ts +18 -0
- package/src/data/index.ts +5 -0
- package/src/data/maybeNumber.ts +23 -0
- package/src/data/parseSort.test.ts +67 -0
- package/src/data/parseSort.ts +108 -0
- package/src/data/resolvePagination.test.ts +58 -0
- package/src/data/resolvePagination.ts +60 -0
- package/src/data/types.d.ts +33 -0
- package/src/index.ts +8 -2
- package/src/jsonschema/JsonSchema.test.ts +13 -22
- package/src/jsonschema/JsonSchema.ts +145 -177
- package/src/jsonschema/types.d.ts +151 -161
- package/src/meta/defineFileType.tsx +68 -0
- package/src/meta/defineInit.ts +32 -53
- package/src/meta/defineMetadata.test.ts +5 -7
- package/src/meta/defineMetadata.ts +35 -40
- package/src/meta/index.ts +2 -0
- package/src/password/PHC.test.ts +186 -277
- package/src/password/PHC.ts +243 -243
- package/src/password/Password.test.ts +38 -50
- package/src/password/Password.ts +73 -95
- package/src/password/createArgon2PasswordAlgorithm.ts +65 -69
- package/src/password/createBase64PasswordAlgorithm.ts +9 -9
- package/src/password/createBcryptPasswordAlgorithm.ts +20 -22
- package/src/password/createPBKDF2PasswordAlgorithm.ts +49 -61
- package/src/password/createScryptPasswordAlgorithm.ts +48 -59
- package/src/search/AdvanceSearch.test.ts +136 -143
- package/src/search/AdvanceSearch.ts +6 -6
- package/src/search/__snapshots__/AdvanceSearch.test.ts.snap +3 -3
- package/src/search/formatAdvanceSearch.ts +44 -53
- package/src/search/optimizeAdvanceSearch.ts +70 -83
- package/src/search/parseAdvanceSearch.ts +16 -19
- package/src/search/parser.d.ts +3 -3
- package/src/search/parser.js +325 -73
- package/src/search/parser.peggy +42 -9
- package/src/search/types.d.ts +28 -54
- package/src/tools/renderJsonSchemaToMarkdownDoc.ts +69 -69
- package/lib/normalizePagination.js +0 -14
- package/lib/normalizePagination.js.map +0 -1
- package/lib/parseSort.js +0 -91
- package/lib/parseSort.js.map +0 -1
- package/src/normalizePagination.ts +0 -25
- package/src/parseSort.test.ts +0 -42
- package/src/parseSort.ts +0 -115
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 // https://github.com/simonepri/phc-format/blob/master/index.js\n\n const idRegex = /^[a-z0-9-]{1,32}$/;\n const nameRegex = /^[a-z0-9-]{1,32}$/;\n const valueRegex = /^[a-zA-Z0-9/+.-]+$/;\n const b64Regex = /^([a-zA-Z0-9/+.-]+|)$/;\n const decimalRegex = /^((-)?[1-9]\\d*|0)$/;\n const versionRegex = /^v=(\\d+)$/;\n\n const fromBase64 = ArrayBuffers.fromBase64;\n const toBase64 = ArrayBuffers.toBase64;\n const isBuffer = (v: any): v is Uint8Array => {\n return v instanceof Uint8Array;\n };\n\n function objToKeyVal(obj: Record<string, any>): string {\n return objectKeys(obj)\n .map((k) => [k, obj[k]].join('='))\n .join(',');\n }\n\n function keyValtoObj(str: string): Record<string, string> {\n const obj: Record<string, string> = {};\n str.split(',').forEach((ps) => {\n const pss = ps.split('=');\n if (pss.length < 2) {\n throw new TypeError(`params must be in the format name=value`);\n }\n\n const key = pss.shift();\n if (key !== undefined) {\n obj[key] = pss.join('=');\n }\n });\n return obj;\n }\n\n function objectKeys<T extends object>(object: T): Array<keyof T> {\n return Object.keys(object) as Array<keyof T>;\n }\n\n function objectValues<T extends object>(object: T): Array<T[keyof T]> {\n if (typeof Object.values === 'function') return Object.values(object);\n return objectKeys(object).map((k) => object[k]);\n }\n\n interface SerializeOptions {\n id: string;\n version?: number;\n params?: Record<string, string | number | Uint8Array>;\n salt?: Uint8Array;\n hash?: Uint8Array;\n }\n\n /**\n * Generates a PHC string using the data provided.\n * @param {SerializeOptions} opts Object that holds the data needed to generate the PHC string.\n * @return {string} The hash string adhering to the PHC format.\n */\n export function serialize(opts: SerializeOptions): string {\n const fields: string[] = [''];\n\n if (typeof opts !== 'object' || opts === null) {\n throw new TypeError('opts must be an object');\n }\n\n // Identifier Validation\n if (typeof opts.id !== 'string') {\n throw new TypeError('id must be a string');\n }\n\n if (!idRegex.test(opts.id)) {\n throw new TypeError(`id must satisfy ${idRegex}`);\n }\n\n fields.push(opts.id);\n\n if (typeof opts.version !== 'undefined') {\n if (typeof opts.version !== 'number' || opts.version < 0 || !Number.isInteger(opts.version)) {\n throw new TypeError('version must be a positive integer number');\n }\n\n fields.push(`v=${opts.version}`);\n }\n\n // Parameters Validation\n if (typeof opts.params !== 'undefined') {\n if (typeof opts.params !== 'object' || opts.params === null) {\n throw new TypeError('params must be an object');\n }\n\n const pk = objectKeys(opts.params);\n if (!pk.every((p) => nameRegex.test(p.toString()))) {\n throw new TypeError(`params names must satisfy ${nameRegex}`);\n }\n\n // Convert Numbers into Numeric Strings and Buffers into B64 encoded strings.\n pk.forEach((k) => {\n const value = opts.params![k];\n if (typeof value === 'number') {\n opts.params![k] = value.toString();\n } else if (value instanceof Uint8Array) {\n opts.params![k] = toBase64(value).split('=')[0];\n }\n });\n const pv = objectValues(opts.params);\n if (!pv.every((v) => typeof v === 'string')) {\n throw new TypeError('params values must be strings');\n }\n\n if (!pv.every((v) => valueRegex.test(v))) {\n throw new TypeError(`params values must satisfy ${valueRegex}`);\n }\n\n const strpar = objToKeyVal(opts.params as Record<string, string>);\n fields.push(strpar);\n }\n\n if (typeof opts.salt !== 'undefined') {\n // Salt Validation\n if (!isBuffer(opts.salt)) {\n throw new TypeError('salt must be a Buffer');\n }\n\n fields.push(toBase64(opts.salt).split('=')[0]);\n\n if (typeof opts.hash !== 'undefined') {\n // Hash Validation\n if (!isBuffer(opts.hash)) {\n throw new TypeError('hash must be a Buffer');\n }\n\n fields.push(toBase64(opts.hash).split('=')[0]);\n }\n }\n\n // Create the PHC formatted string\n const phcstr = fields.join('$');\n\n return phcstr;\n }\n\n interface DeserializeResult {\n id: string;\n version?: number;\n params?: Record<string, string | number>;\n salt?: Uint8Array;\n hash?: Uint8Array;\n }\n\n /**\n * Parses data from a PHC string.\n * @param {string} phcstr A PHC string to parse.\n * @return {DeserializeResult} The object containing the data parsed from the PHC string.\n */\n export function deserialize(phcstr: string): DeserializeResult {\n if (typeof phcstr !== 'string' || phcstr === '') {\n throw new TypeError('pchstr must be a non-empty string');\n }\n\n if (phcstr[0] !== '$') {\n throw new TypeError('pchstr must contain a $ as first char');\n }\n\n const fields = phcstr.split('$');\n // Remove first empty $\n fields.shift();\n\n // Parse Fields\n let maxf = 5;\n if (!versionRegex.test(fields[1])) maxf--;\n if (fields.length > maxf) {\n throw new TypeError(`pchstr contains too many fileds: ${fields.length}/${maxf}`);\n }\n\n // Parse Identifier\n const id = fields.shift();\n if (!id || !idRegex.test(id)) {\n throw new TypeError(`id must satisfy ${idRegex}`);\n }\n\n let version: number | undefined;\n // Parse Version\n if (fields[0] && versionRegex.test(fields[0])) {\n const versionMatch = fields.shift()?.match(versionRegex);\n version = versionMatch ? parseInt(versionMatch[1], 10) : undefined;\n }\n\n let hash: Uint8Array | undefined;\n let salt: Uint8Array | undefined;\n if (fields[fields.length - 1] && b64Regex.test(fields[fields.length - 1])) {\n if (fields.length > 1 && b64Regex.test(fields[fields.length - 2])) {\n // Parse Hash\n const hashStr = fields.pop();\n if (hashStr) hash = fromBase64(hashStr);\n // Parse Salt\n const saltStr = fields.pop();\n if (saltStr !== undefined) salt = fromBase64(saltStr);\n } else {\n // Parse Salt\n const saltStr = fields.pop();\n if (saltStr !== undefined) salt = fromBase64(saltStr);\n }\n }\n\n // Parse Parameters\n let params: Record<string, string | number> | undefined;\n if (fields.length > 0) {\n const parstr = fields.pop();\n if (parstr) {\n params = keyValtoObj(parstr);\n if (!Object.keys(params).every((p) => nameRegex.test(p))) {\n throw new TypeError(`params names must satisfy ${nameRegex}}`);\n }\n\n const pv = Object.values(params);\n if (!pv.every((v) => valueRegex.test(String(v)))) {\n throw new TypeError(`params values must satisfy ${valueRegex}`);\n }\n\n // Convert Decimal Strings into Numbers\n Object.keys(params).forEach((k) => {\n const value = params![k];\n if (typeof value === 'string' && decimalRegex.test(value)) {\n params![k] = parseInt(value, 10);\n }\n });\n }\n }\n\n if (fields.length > 0) {\n throw new TypeError(`pchstr contains unrecognized fileds: ${fields}`);\n }\n\n // Build the output object\n const phcobj: DeserializeResult = { id };\n if (version !== undefined) phcobj.version = version;\n if (params) phcobj.params = params;\n if (salt) phcobj.salt = salt;\n if (hash) phcobj.hash = hash;\n\n return phcobj;\n }\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;IACf,+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;QAChB,OAAOA,aAAaC;IACtB;IAEA,SAASC,YAAYC,GAAwB;QAC3C,OAAOC,WAAWD,KACfE,GAAG,CAAC,CAACC,IAAM;gBAACA;gBAAGH,GAAG,CAACG,EAAE;aAAC,CAACC,IAAI,CAAC,MAC5BA,IAAI,CAAC;IACV;IAEA,SAASC,YAAYC,GAAW;QAC9B,MAAMN,MAA8B,CAAC;QACrCM,IAAIC,KAAK,CAAC,KAAKC,OAAO,CAAC,CAACC;YACtB,MAAMC,MAAMD,GAAGF,KAAK,CAAC;YACrB,IAAIG,IAAIC,MAAM,GAAG,GAAG;gBAClB,MAAM,IAAIC,UAAU,CAAC,uCAAuC,CAAC;YAC/D;YAEA,MAAMC,MAAMH,IAAII,KAAK;YACrB,IAAID,QAAQE,WAAW;gBACrBf,GAAG,CAACa,IAAI,GAAGH,IAA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MAAM,IAAIC,UAAU,CAAC,qCAAqC,EAAEW,QAAQ;QACtE;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;IACT;IA5FA;;;;GAIC,OACeV,cAAAA;AAwFlB,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).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,M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0BAA0B,EAAEvB,UAAU,CAAC,CAAC;gBAC9D;gBAEA,MAAM+C,KAAKnB,OAAOG,MAAM,CAACU;gBACzB,IAAI,CAACM,GAAGJ,KAAK,CAAC,CAACnC,IAAMP,WAAWmC,IAAI,CAACyB,OAAOrD,MAAM;oBACjD,MAAM,IAAIe,UAAU,CAAC,2BAA2B,EAAEtB,YAAY;gBAC/D;gBAEA,uCAAuC;gBACvC2B,OAAOC,IAAI,CAACY,QAAQtB,OAAO,CAAC,CAACL;oBAC5B,MAAMgC,QAAQL,MAAO,CAAC3B,EAAE;oBACxB,IAAI,OAAOgC,UAAU,YAAY3C,aAAaiC,IAAI,CAACU,QAAQ;wBAC1DL,MAAO,CAAC3B,EAAE,GAAG0C,SAASV,OAAO;oBAC9B;gBACD;YACD;QACD;QAEA,IAAIZ,OAAOZ,MAAM,GAAG,GAAG;YACtB,MAAM,IAAIC,UAAU,CAAC,qCAAqC,EAAEW,QAAQ;QACrE;QAEA,0BAA0B;QAC1B,MAAM4B,SAA4B;YAAE3B;QAAG;QACvC,IAAIG,YAAYZ,WAAWoC,OAAOxB,OAAO,GAAGA;QAC5C,IAAIG,QAAQqB,OAAOrB,MAAM,GAAGA;QAC5B,IAAIQ,MAAMa,OAAOb,IAAI,GAAGA;QACxB,IAAIC,MAAMY,OAAOZ,IAAI,GAAGA;QAExB,OAAOY;IACR;IA5FA;;;;EAIC,OACeV,cAAAA;AAwFjB,GApPiBtD,QAAAA"}
|
|
@@ -1 +1 @@
|
|
|
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
|
|
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,OAAO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AAOS,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 +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
|
|
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 +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
|
|
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 +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
|
|
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 +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
|
|
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 +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
|
|
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,I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,UAAUE,MAAML,QAAQ;wBAAES;wBAAGC;wBAAGC;oBAAE,GAAG,CAACC,KAAKC;wBACjD,IAAID,KAAK,OAAOJ,OAAOI;wBAEvB,MAAMW,UAAUnC,gBAAgByB,YAAYO;wBAC5Cb,QAAQgB;oBACT;gBACD;YACD,EAAE,OAAOC,OAAO;gBACf,OAAOlB,QAAQC,OAAO,CAAC;YACxB;QACD;IACD;AACD"}
|
|
@@ -1 +1 @@
|
|
|
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
|
|
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 +1 @@
|
|
|
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
|
|
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,CAAC,CAAC,EAAEM,SAASC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AAIM,MAAML,YAAYG,YAAY,KAAKX,OAAOQ;YAC9C,OAAO,GAAGC,mBAAmB,MAAM,MAAMG,IAAI,CAAC,EAAEC,MAAMH,mBAAmB,MAAM,KAAK;QACrF,GACCnB,IAAI,CAAC;YAAEuB,QAAQ;QAAU,GAAG,CAAC,EAAErB,KAAK,EAAE;YACtC,OAAO,CAAC,CAAC,EAAEA,OAAO;QACnB,GACCsB,SAAS,CAAC,CAACtB;YACX,OAAOS,SAAST,MAAMA,KAAK;QAC5B;IACF;IAEA,OAAOP,OAAOT;AACf"}
|
|
@@ -1 +1 @@
|
|
|
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
|
|
1
|
+
{"version":3,"sources":["../../src/search/optimizeAdvanceSearch.ts"],"sourcesContent":["import { arrayOfMaybeArray, deepEqual, type MaybeArray } from '@wener/utils';\nimport { match } from 'ts-pattern';\nimport { AdvanceSearch } from './AdvanceSearch';\n\nexport function optimizeAdvanceSearch(expr: AdvanceSearch.Exprs): AdvanceSearch.Exprs {\n\tconst NEG = { eq: 'ne', ne: 'eq', gt: 'lte', lt: 'gte', gte: 'lt', lte: 'gt' } as const;\n\tconst _expr = (e: AdvanceSearch.Expr): MaybeArray<AdvanceSearch.Expr> => {\n\t\t// merge Exprs to AND ?\n\t\treturn (\n\t\t\tmatch(e)\n\t\t\t\t// (EXPR) -> EXPR\n\t\t\t\t// TODO (EXPR EXPR) -> EXPR AND EXPR\n\t\t\t\t.with({ type: 'parentheses' }, (expr) => {\n\t\t\t\t\t// unwrap\n\t\t\t\t\tif (expr.value.length < 2) {\n\t\t\t\t\t\treturn expr.value[0];\n\t\t\t\t\t}\n\t\t\t\t\texpr.value = expr.value.flatMap(_expr);\n\t\t\t\t\treturn expr;\n\t\t\t\t})\n\t\t\t\t.with({ type: 'comment' }, (expr) => {\n\t\t\t\t\t// remove empty comment\n\t\t\t\t\tif (!expr.value.length) {\n\t\t\t\t\t\treturn [];\n\t\t\t\t\t}\n\t\t\t\t\treturn expr;\n\t\t\t\t})\n\t\t\t\t// NOT\n\t\t\t\t.with({ type: 'not' }, (expr) => {\n\t\t\t\t\tlet out = arrayOfMaybeArray(_expr(expr.value));\n\t\t\t\t\tif (!out.length) {\n\t\t\t\t\t\treturn [];\n\t\t\t\t\t} else if (out.length === 1) {\n\t\t\t\t\t\texpr.value = out[0];\n\t\t\t\t\t} else {\n\t\t\t\t\t\tthrow new Error('NOT should have only one value');\n\t\t\t\t\t}\n\t\t\t\t\treturn (\n\t\t\t\t\t\tmatch(expr.value)\n\t\t\t\t\t\t\t// NOT NOT EXPR -> EXPR\n\t\t\t\t\t\t\t.with({ type: 'not' }, (expr) => expr.value)\n\t\t\t\t\t\t\t// NOT EXPR -> -EXPR\n\t\t\t\t\t\t\t.with({ type: 'compare' }, (expr) => {\n\t\t\t\t\t\t\t\treturn { ...expr, negative: !expr.negative };\n\t\t\t\t\t\t\t})\n\t\t\t\t\t\t\t.with({ type: 'keyword' }, (expr) => {\n\t\t\t\t\t\t\t\treturn { ...expr, negative: !expr.negative };\n\t\t\t\t\t\t\t})\n\t\t\t\t\t\t\t.otherwise(() => expr)\n\t\t\t\t\t);\n\t\t\t\t})\n\t\t\t\t.with({ type: 'compare' }, (expr) => {\n\t\t\t\t\t// negative by swap operator\n\t\t\t\t\tif (expr.negative) {\n\t\t\t\t\t\tconst ne = NEG[expr.operator as keyof typeof NEG];\n\t\t\t\t\t\tif (ne) {\n\t\t\t\t\t\t\texpr.operator = ne;\n\t\t\t\t\t\t\texpr.negative = false;\n\t\t\t\t\t\t}\n\t\t\t\t\t}\n\t\t\t\t\tif (expr.operator === 'range') {\n\t\t\t\t\t}\n\t\t\t\t\treturn expr;\n\t\t\t\t})\n\t\t\t\t.otherwise((e) => e)\n\t\t);\n\t};\n\n\tlet last = expr;\n\twhile (true) {\n\t\tlet next = structuredClone(last).flatMap(_expr);\n\t\tif (deepEqual(last, next)) {\n\t\t\treturn last;\n\t\t}\n\t\tlast = next;\n\t}\n}\n"],"names":["arrayOfMaybeArray","deepEqual","match","optimizeAdvanceSearch","expr","NEG","eq","ne","gt","lt","gte","lte","_expr","e","with","type","value","length","flatMap","out","Error","negative","otherwise","operator","last","next","structuredClone"],"mappings":"AAAA,SAASA,iBAAiB,EAAEC,SAAS,QAAyB,eAAe;AAC7E,SAASC,KAAK,QAAQ,aAAa;AAGnC,OAAO,SAASC,sBAAsBC,IAAyB;IAC9D,MAAMC,MAAM;QAAEC,IAAI;QAAMC,IAAI;QAAMC,IAAI;QAAOC,IAAI;QAAOC,KAAK;QAAMC,KAAK;IAAK;IAC7E,MAAMC,QAAQ,CAACC;QACd,uBAAuB;QACvB,OACCX,MAAMW,EACL,iBAAiB;QACjB,oCAAoC;SACnCC,IAAI,CAAC;YAAEC,MAAM;QAAc,GAAG,CAACX;YAC/B,SAAS;YACT,IAAIA,KAAKY,KAAK,CAACC,MAAM,GAAG,GAAG;gBAC1B,OAAOb,KAAKY,KAAK,CAAC,EAAE;YACrB;YACAZ,KAAKY,KAAK,GAAGZ,KAAKY,KAAK,CAACE,OAAO,CAACN;YAChC,OAAOR;QACR,GACCU,IAAI,CAAC;YAAEC,MAAM;QAAU,GAAG,CAACX;YAC3B,uBAAuB;YACvB,IAAI,CAACA,KAAKY,KAAK,CAACC,MAAM,EAAE;gBACvB,OAAO,EAAE;YACV;YACA,OAAOb;QACR,EACA,MAAM;SACLU,IAAI,CAAC;YAAEC,MAAM;QAAM,GAAG,CAACX;YACvB,IAAIe,MAAMnB,kBAAkBY,MAAMR,KAAKY,KAAK;YAC5C,IAAI,CAACG,IAAIF,MAAM,EAAE;gBAChB,OAAO,EAAE;YACV,OAAO,IAAIE,IAAIF,MAAM,KAAK,GAAG;gBAC5Bb,KAAKY,KAAK,GAAGG,GAAG,CAAC,EAAE;YACpB,OAAO;gBACN,MAAM,IAAIC,MAAM;YACjB;YACA,OACClB,MAAME,KAAKY,KAAK,CACf,uBAAuB;aACtBF,IAAI,CAAC;gBAAEC,MAAM;YAAM,GAAG,CAACX,OAASA,KAAKY,KAAK,CAC3C,oBAAoB;aACnBF,IAAI,CAAC;gBAAEC,MAAM;YAAU,GAAG,CAACX;gBAC3B,OAAO;oBAAE,GAAGA,IAAI;oBAAEiB,UAAU,CAACjB,KAAKiB,QAAQ;gBAAC;YAC5C,GACCP,IAAI,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 +1 @@
|
|
|
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
|
|
1
|
+
{"version":3,"sources":["../../src/search/parseAdvanceSearch.ts"],"sourcesContent":["import { AdvanceSearch } from './AdvanceSearch';\nimport { parse } from './parser';\n\nexport function parseAdvanceSearch(s: string | undefined | null): AdvanceSearch.Expr[] {\n\ts = s?.trim();\n\tif (!s) {\n\t\treturn [];\n\t}\n\n\t// no Logical, no Compare, no Quote, no Comment\n\tif (!/AND|OR|NOT|[-\"():]|\\/\\*/.test(s)) {\n\t\t// fast path\n\t\treturn s\n\t\t\t.split(/\\s+/)\n\t\t\t.map((v) => v.trim())\n\t\t\t.filter(Boolean)\n\t\t\t.map((v) => {\n\t\t\t\treturn { type: 'keyword', value: v };\n\t\t\t});\n\t}\n\n\treturn parse(s);\n}\n"],"names":["parse","parseAdvanceSearch","s","trim","test","split","map","v","filter","Boolean","type","value"],"mappings":"AACA,SAASA,KAAK,QAAQ,cAAW;AAEjC,OAAO,SAASC,mBAAmBC,CAA4B;IAC9DA,IAAIA,GAAGC;IACP,IAAI,CAACD,GAAG;QACP,OAAO,EAAE;IACV;IAEA,+CAA+C;IAC/C,IAAI,CAAC,0BAA0BE,IAAI,CAACF,IAAI;QACvC,YAAY;QACZ,OAAOA,EACLG,KAAK,CAAC,OACNC,GAAG,CAAC,CAACC,IAAMA,EAAEJ,IAAI,IACjBK,MAAM,CAACC,SACPH,GAAG,CAAC,CAACC;YACL,OAAO;gBAAEG,MAAM;gBAAWC,OAAOJ;YAAE;QACpC;IACF;IAEA,OAAOP,MAAME;AACd"}
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"sources":["../../src/search/parser.d.ts"],"sourcesContent":["export function parse(input: string, options?: ParseOptions): any;\n\nexport interface ParseOptions {\n
|
|
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"}
|