@poppinss/utils 6.5.0 → 6.5.1
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/build/{chunk-XHQBV7AF.js → chunk-IOBSMUFC.js} +1 -0
- package/build/chunk-IOBSMUFC.js.map +1 -0
- package/build/{chunk-OKRMWJO4.js → chunk-K76IL3UP.js} +2 -1
- package/build/chunk-K76IL3UP.js.map +1 -0
- package/build/{chunk-PWRXO3NF.js → chunk-NKGAOHNN.js} +1 -0
- package/build/chunk-NKGAOHNN.js.map +1 -0
- package/build/index.d.ts +19 -278
- package/build/index.js +3 -2
- package/build/index.js.map +1 -0
- package/build/src/assert.d.ts +3 -5
- package/build/src/assert.js +1 -0
- package/build/src/assert.js.map +1 -0
- package/build/src/base64.d.ts +33 -0
- package/build/src/compose.d.ts +19 -0
- package/build/src/define_static_property.d.ts +10 -0
- package/build/src/exception.d.ts +52 -0
- package/build/src/exceptions/invalid_arguments_exception.d.ts +5 -0
- package/build/src/exceptions/runtime_exception.d.ts +5 -0
- package/build/src/flatten.d.ts +4 -0
- package/build/src/fs_import_all.d.ts +20 -0
- package/build/src/fs_read_all.d.ts +20 -0
- package/build/src/import_default.d.ts +6 -0
- package/build/src/is_script_file.d.ts +5 -0
- package/build/src/json/main.d.ts +3 -15
- package/build/src/json/main.js +2 -1
- package/build/src/json/main.js.map +1 -0
- package/build/src/json/safe_parse.d.ts +5 -0
- package/build/src/json/safe_stringify.d.ts +6 -0
- package/build/src/message_builder.d.ts +17 -0
- package/build/src/natural_sort.d.ts +4 -0
- package/build/src/object_builder.d.ts +58 -0
- package/build/src/safe_equal.d.ts +11 -0
- package/build/src/slash.d.ts +1 -0
- package/build/src/string/bytes.d.ts +11 -0
- package/build/src/string/change_case.d.ts +42 -0
- package/build/src/string/excerpt.d.ts +11 -0
- package/build/src/string/interpolate.d.ts +8 -0
- package/build/src/string/main.d.ts +15 -118
- package/build/src/string/main.js +3 -2
- package/build/src/string/main.js.map +1 -0
- package/build/src/string/milliseconds.d.ts +9 -0
- package/build/src/string/ordinal.d.ts +4 -0
- package/build/src/string/pluralize.d.ts +16 -0
- package/build/src/string/random.d.ts +4 -0
- package/build/src/string/seconds.d.ts +9 -0
- package/build/src/string/sentence.d.ts +8 -0
- package/build/src/string/slugify.d.ts +6 -0
- package/build/src/string/truncate.d.ts +10 -0
- package/build/src/string_builder.d.ts +1 -3
- package/build/src/string_builder.js +3 -2
- package/build/src/string_builder.js.map +1 -0
- package/build/src/types.d.ts +9 -10
- package/build/src/types.js +1 -0
- package/build/src/types.js.map +1 -0
- package/package.json +17 -12
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"sources":["../src/json/safe_parse.ts","../src/json/safe_stringify.ts","../src/json/main.ts"],"sourcesContent":["/*\n * @poppinss/utils\n *\n * (c) Poppinss\n *\n * For the full copyright and license information, please view the LICENSE\n * file that was distributed with this source code.\n */\n\nimport { parse } from 'secure-json-parse'\nimport { JSONReviver } from '../types.js'\n\n/**\n * A drop-in replacement for JSON.parse with prototype poisoning protection.\n */\nexport function safeParse(jsonString: string, reviver?: JSONReviver): any {\n return parse(jsonString, reviver, {\n protoAction: 'remove',\n constructorAction: 'remove',\n })\n}\n","/*\n * @poppinss/utils\n *\n * (c) Poppinss\n *\n * For the full copyright and license information, please view the LICENSE\n * file that was distributed with this source code.\n */\n\nimport { configure } from 'safe-stable-stringify'\nimport { JSONReplacer } from '../types.js'\n\nconst stringify = configure({\n bigint: false,\n circularValue: undefined,\n deterministic: false,\n})\n\n/**\n * Replacer to handle custom data types.\n *\n * - Bigints are converted to string\n */\nfunction jsonStringifyReplacer(replacer?: JSONReplacer): JSONReplacer {\n return function (key, value) {\n const val = replacer ? replacer.call(this, key, value) : value\n\n if (typeof val === 'bigint') {\n return val.toString()\n }\n\n return val\n }\n}\n\n/**\n * String Javascript values to a JSON string. Handles circular\n * references and bigints\n */\nexport function safeStringify(\n value: any,\n replacer?: JSONReplacer,\n space?: string | number\n): string | undefined {\n return stringify(value, jsonStringifyReplacer(replacer), space)\n}\n","/*\n * @poppinss/utils\n *\n * (c) Poppinss\n *\n * For the full copyright and license information, please view the LICENSE\n * file that was distributed with this source code.\n */\n\nimport { safeParse } from './safe_parse.js'\nimport { safeStringify } from './safe_stringify.js'\n\nconst json = {\n safeParse,\n safeStringify,\n}\n\nexport default json\n"],"mappings":";AASA,SAAS,aAAa;AAMf,SAAS,UAAU,YAAoB,SAA4B;AACxE,SAAO,MAAM,YAAY,SAAS;AAAA,IAChC,aAAa;AAAA,IACb,mBAAmB;AAAA,EACrB,CAAC;AACH;;;ACXA,SAAS,iBAAiB;AAG1B,IAAM,YAAY,UAAU;AAAA,EAC1B,QAAQ;AAAA,EACR,eAAe;AAAA,EACf,eAAe;AACjB,CAAC;AAOD,SAAS,sBAAsB,UAAuC;AACpE,SAAO,SAAU,KAAK,OAAO;AAC3B,UAAM,MAAM,WAAW,SAAS,KAAK,MAAM,KAAK,KAAK,IAAI;AAEzD,QAAI,OAAO,QAAQ,UAAU;AAC3B,aAAO,IAAI,SAAS;AAAA,IACtB;AAEA,WAAO;AAAA,EACT;AACF;AAMO,SAAS,cACd,OACA,UACA,OACoB;AACpB,SAAO,UAAU,OAAO,sBAAsB,QAAQ,GAAG,KAAK;AAChE;;;ACjCA,IAAM,OAAO;AAAA,EACX;AAAA,EACA;AACF;AAEA,IAAO,eAAQ;","names":[]}
|
|
@@ -1,7 +1,7 @@
|
|
|
1
1
|
import {
|
|
2
2
|
base64,
|
|
3
3
|
milliseconds_default
|
|
4
|
-
} from "./chunk-
|
|
4
|
+
} from "./chunk-NKGAOHNN.js";
|
|
5
5
|
|
|
6
6
|
// src/string/bytes.ts
|
|
7
7
|
import bytes from "bytes";
|
|
@@ -267,3 +267,4 @@ var main_default = string;
|
|
|
267
267
|
export {
|
|
268
268
|
main_default
|
|
269
269
|
};
|
|
270
|
+
//# sourceMappingURL=chunk-K76IL3UP.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"sources":["../src/string/bytes.ts","../src/string/seconds.ts","../src/string/slugify.ts","../src/string/random.ts","../src/string/excerpt.ts","../src/string/ordinal.ts","../src/string/truncate.ts","../src/string/sentence.ts","../src/string/interpolate.ts","../src/string/pluralize.ts","../src/string/change_case.ts","../src/string/main.ts"],"sourcesContent":["/*\n * @poppinss/utils\n *\n * (c) Poppinss\n *\n * For the full copyright and license information, please view the LICENSE\n * file that was distributed with this source code.\n */\n\nimport bytes, { BytesOptions } from 'bytes'\n\nexport default {\n format(valueInBytes: number, options?: BytesOptions): string {\n return bytes.format(valueInBytes, options)\n },\n\n /**\n * Parse the unit expression to bytes. If the unit value\n * is a number, then it will be returned as it is considering\n * it is already in bytes.\n */\n parse(unit: string | number): number {\n if (typeof unit === 'number') {\n return unit\n }\n\n return bytes.parse(unit)\n },\n}\n","/*\n * @poppinss/utils\n *\n * (c) Poppinss\n *\n * For the full copyright and license information, please view the LICENSE\n * file that was distributed with this source code.\n */\n\nimport { parse, format } from '@lukeed/ms'\n\nexport default {\n format(seconds: number, long?: boolean): string {\n return format(seconds * 1000, long)\n },\n\n /**\n * Parse time expression string to seconds. The number value\n * is returned as it is, considering it is already in seconds\n */\n parse(duration: string | number): number {\n if (typeof duration === 'number') {\n return duration\n }\n\n const milliseconds = parse(duration)\n if (milliseconds === undefined) {\n throw new Error(`Invalid duration expression \"${duration}\"`)\n }\n\n return Math.floor(milliseconds / 1000)\n },\n}\n","/*\n * @poppinss/utils\n *\n * (c) Poppinss\n *\n * For the full copyright and license information, please view the LICENSE\n * file that was distributed with this source code.\n */\n\nimport { default as slugifyPkg } from 'slugify'\n\n/**\n * Typings of the slugify package are a bit off and therefore we have\n * to do this manual dance of re-assigning types\n */\nexport const slug = slugifyPkg as unknown as (typeof slugifyPkg)['default']\n","/*\n * @poppinss/utils\n *\n * (c) Poppinss\n *\n * For the full copyright and license information, please view the LICENSE\n * file that was distributed with this source code.\n */\n\nimport { randomBytes } from 'node:crypto'\nimport { base64 } from '../base64.js'\n\n/**\n * Generates a random string of a given size\n */\nexport function random(size: number): string {\n const bits = (size + 1) * 6\n const buffer = randomBytes(Math.ceil(bits / 8))\n return base64.urlEncode(buffer).slice(0, size)\n}\n","/*\n * @poppinss/utils\n *\n * (c) Poppinss\n *\n * For the full copyright and license information, please view the LICENSE\n * file that was distributed with this source code.\n */\n\n// @ts-expect-error (Package has no types)\nimport truncatise from 'truncatise'\n\n/**\n * Truncate a sentence to be under a certain characters limit and strip\n * out HTML tags from it.\n *\n * Optionally, you can force the truncate logic to complete words, which\n * may exceed the defined characters limit.\n */\nexport function excerpt(\n sentence: string,\n charactersLimit: number,\n options?: {\n completeWords?: boolean\n suffix?: string\n }\n): string {\n return truncatise(sentence, {\n TruncateLength: charactersLimit,\n /**\n * Do not complete words when \"completeWords\" is not explicitly set\n * to true\n */\n Strict: options && options.completeWords === true ? false : true,\n StripHTML: true,\n TruncateBy: 'characters',\n Suffix: options && options.suffix,\n })\n}\n","/*\n * @poppinss/utils\n *\n * (c) Poppinss\n *\n * For the full copyright and license information, please view the LICENSE\n * file that was distributed with this source code.\n */\n\n/**\n * Ordinalize a give number or string\n */\nexport function ordinal(value: string | number): string {\n const transformedValue = Math.abs(typeof value === 'string' ? Number.parseInt(value) : value)\n if (!Number.isFinite(transformedValue) || Number.isNaN(transformedValue)) {\n throw new Error('Cannot ordinalize invalid or infinite numbers')\n }\n\n const percent = transformedValue % 100\n if (percent >= 10 && percent <= 20) {\n return `${value}th`\n }\n\n const decimal = transformedValue % 10\n switch (decimal) {\n case 1:\n return `${value}st`\n case 2:\n return `${value}nd`\n case 3:\n return `${value}rd`\n default:\n return `${value}th`\n }\n}\n","/*\n * @poppinss/utils\n *\n * (c) Poppinss\n *\n * For the full copyright and license information, please view the LICENSE\n * file that was distributed with this source code.\n */\n\n// @ts-expect-error (Package has no types)\nimport truncatise from 'truncatise'\n\n/**\n * Truncate a sentence to be under a certain characters limit.\n *\n * Optionally, you can force the truncate logic to complete words, which\n * may exceed the defined characters limit.\n */\nexport function truncate(\n sentence: string,\n charactersLimit: number,\n options?: {\n completeWords?: boolean\n suffix?: string\n }\n): string {\n return truncatise(sentence, {\n TruncateLength: charactersLimit,\n /**\n * Do not complete words when \"completeWords\" is not explicitly set\n * to true\n */\n Strict: options && options.completeWords === true ? false : true,\n StripHTML: false,\n TruncateBy: 'characters',\n Suffix: options && options.suffix,\n })\n}\n","/*\n * @poppinss/utils\n *\n * (c) Poppinss\n *\n * For the full copyright and license information, please view the LICENSE\n * file that was distributed with this source code.\n */\n\n/**\n * Convert an array of values to a sentence.\n */\nexport function sentence(\n values: any[],\n options?: {\n separator?: string\n pairSeparator?: string\n lastSeparator?: string\n }\n): string {\n /**\n * Empty array\n */\n if (values.length === 0) {\n return ''\n }\n\n /**\n * Just one item\n */\n if (values.length === 1) {\n return values[0]\n }\n\n /**\n * Giving some love to two items, so that one can ditch comma with two items\n */\n if (values.length === 2) {\n return `${values[0]}${options?.pairSeparator || ' and '}${values[1]}`\n }\n\n const normalized = Object.assign({ separator: ', ', lastSeparator: ', and ' }, options)\n\n /**\n * Make sentence\n */\n return `${values.slice(0, -1).join(normalized.separator)}${normalized.lastSeparator}${\n values[values.length - 1]\n }`\n}\n","/*\n * @poppinss/utils\n *\n * (c) Poppinss\n *\n * For the full copyright and license information, please view the LICENSE\n * file that was distributed with this source code.\n */\n\n/**\n * Parses prop\n */\nfunction parseProp(data: any, key: string) {\n const tokens = key.split('.')\n while (tokens.length) {\n if (data === null || typeof data !== 'object') {\n return\n }\n const token = tokens.shift()!\n data = Object.hasOwn(data, token) ? data[token] : undefined\n }\n return data\n}\n\n/**\n * A simple function interpolate values inside curly braces.\n *\n * ```\n * interpolate('hello {{ username }}', { username: 'virk' })\n * ```\n */\nexport function interpolate(input: string, data: any) {\n return input.replace(/(\\\\)?{{(.*?)}}/g, (_, escapeChar, key) => {\n if (escapeChar) {\n return `{{${key}}}`\n }\n\n return parseProp(data, key.trim())\n })\n}\n","/*\n * @poppinss/utils\n *\n * (c) Poppinss\n *\n * For the full copyright and license information, please view the LICENSE\n * file that was distributed with this source code.\n */\n\nimport { default as pluralizePkg } from 'pluralize'\n\n/**\n * Pluralize a word based upon the count. The method returns the\n * singular form when count is 1.\n */\nexport function pluralize(word: string, count?: number, inclusive?: boolean): string {\n return pluralizePkg(word, count, inclusive)\n}\npluralize.addPluralRule = pluralizePkg.addPluralRule\npluralize.addSingularRule = pluralizePkg.addSingularRule\npluralize.addIrregularRule = pluralizePkg.addIrregularRule\npluralize.addUncountableRule = pluralizePkg.addUncountableRule\n\nexport const plural = pluralizePkg.plural\nexport const singular = pluralizePkg.singular\nexport const isPlural = pluralizePkg.isPlural\nexport const isSingular = pluralizePkg.isSingular\n","/*\n * @poppinss/utils\n *\n * (c) Poppinss\n *\n * For the full copyright and license information, please view the LICENSE\n * file that was distributed with this source code.\n */\n\nimport * as changeCase from 'case-anything'\n\n// Support camel case (\"camelCase\" -> \"camel Case\" and \"CAMELCase\" -> \"CAMEL Case\").\nconst NO_CASE_SPLIT_REGEXP = [/([a-z0-9])([A-Z])/g, /([A-Z])([A-Z][a-z])/g]\n\n// Remove all non-word characters.\nconst NO_CASE_STRIP_REGEXP = /[^A-Z0-9]+/gi\n\nconst SMALL_WORDS =\n /\\b(?:an?d?|a[st]|because|but|by|en|for|i[fn]|neither|nor|o[fnr]|only|over|per|so|some|tha[tn]|the|to|up|upon|vs?\\.?|versus|via|when|with|without|yet)\\b/i\nconst TOKENS = /[^\\s:–—-]+|./g\nconst WHITESPACE = /\\s/\nconst IS_MANUAL_CASE = /.(?=[A-Z]|\\..)/\nconst ALPHANUMERIC_PATTERN = /[A-Za-z0-9\\u00C0-\\u00FF]/\n\n/**\n * The method is a copy/paste from the \"title-case\" package. They have\n * a dependency on \"tslib\", which I don't want.\n */\nexport function titleCase(input: string) {\n let output = ''\n let result: RegExpExecArray | null\n\n while ((result = TOKENS.exec(input)) !== null) {\n const { 0: token, index } = result\n\n if (\n !IS_MANUAL_CASE.test(token) &&\n (!SMALL_WORDS.test(token) || index === 0 || index + token.length === input.length) &&\n (input.charAt(index + token.length) !== ':' ||\n WHITESPACE.test(input.charAt(index + token.length + 1)))\n ) {\n output += token.replace(ALPHANUMERIC_PATTERN, (char) => char.toUpperCase())\n continue\n }\n\n output += token\n }\n\n return output\n}\n\n/**\n * Convert string to camelcase\n */\nexport function camelCase(value: string): string {\n return changeCase.camelCase(value)\n}\n\n/**\n * Convert string to snakecase\n */\nexport function snakeCase(value: string): string {\n return changeCase.snakeCase(value)\n}\n\n/**\n * Convert string to dashcase\n */\nexport function dashCase(value: string, options?: { capitalize?: boolean }): string {\n if (options && options.capitalize) {\n return changeCase.trainCase(value)\n }\n\n return changeCase.kebabCase(value)\n}\n\n/**\n * Convert string to pascal case\n */\nexport function pascalCase(value: string): string {\n return changeCase.pascalCase(value)\n}\n\n/**\n * Convert string to capital case\n */\nexport function capitalCase(value: string): string {\n return changeCase.capitalCase(value)\n}\n\n/**\n * Convert string to sentence case\n */\nexport function sentenceCase(value: string): string {\n return noCase(value, (input, index) => {\n const result = input.toLowerCase()\n if (index === 0) {\n return input.charAt(0).toUpperCase() + input.substring(1)\n }\n return result\n })\n}\n\n/**\n * Convert string to dot case\n */\nexport function dotCase(value: string, options?: { lowerCase?: boolean }): string {\n const transformedValue = changeCase.dotNotation(value)\n if (options && options.lowerCase) {\n return transformedValue.toLowerCase()\n }\n\n return transformedValue\n}\n\n/**\n * Remove all sort of casing from the string. Copy-pasted from\n * \"no-case\" package with slight modifications.\n */\nexport function noCase(\n value: string,\n transform?: (part: string, index: number, parts: string[]) => string\n): string {\n let result = NO_CASE_SPLIT_REGEXP.reduce((input, regex) => input.replace(regex, '$1\\0$2'), value)\n result = result.replace(NO_CASE_STRIP_REGEXP, '\\0')\n\n let start = 0\n let end = result.length\n\n // Trim the delimiter from around the output string.\n while (result.charAt(start) === '\\0') {\n start++\n }\n while (result.charAt(end - 1) === '\\0') {\n end--\n }\n\n return result\n .slice(start, end)\n .split('\\0')\n .map(transform || ((input) => input.toLowerCase()))\n .join(' ')\n}\n","/*\n * @poppinss/utils\n *\n * (c) Poppinss\n *\n * For the full copyright and license information, please view the LICENSE\n * file that was distributed with this source code.\n */\n\nimport bytes from './bytes.js'\nimport seconds from './seconds.js'\nimport { slug } from './slugify.js'\nimport { random } from './random.js'\nimport { excerpt } from './excerpt.js'\nimport { ordinal } from './ordinal.js'\nimport { truncate } from './truncate.js'\nimport milliseconds from './milliseconds.js'\nimport { sentence } from './sentence.js'\nimport { interpolate } from './interpolate.js'\nimport { plural, pluralize, singular, isPlural, isSingular } from './pluralize.js'\nimport {\n noCase,\n dotCase,\n dashCase,\n camelCase,\n snakeCase,\n titleCase,\n pascalCase,\n capitalCase,\n sentenceCase,\n} from './change_case.js'\n\n/**\n * Condense multiple whitespaces from a string\n */\nfunction condenseWhitespace(value: string): string {\n return value.trim().replace(/\\s{2,}/g, ' ')\n}\n\nconst string = {\n excerpt,\n truncate,\n slug,\n interpolate,\n plural,\n pluralize,\n singular,\n isPlural,\n isSingular,\n camelCase,\n capitalCase,\n dashCase,\n dotCase,\n noCase,\n pascalCase,\n sentenceCase,\n snakeCase,\n titleCase,\n random,\n sentence,\n condenseWhitespace,\n seconds,\n milliseconds,\n bytes,\n ordinal,\n}\n\nexport default string\n"],"mappings":";;;;;;AASA,OAAO,WAA6B;AAEpC,IAAO,gBAAQ;AAAA,EACb,OAAO,cAAsB,SAAgC;AAC3D,WAAO,MAAM,OAAO,cAAc,OAAO;AAAA,EAC3C;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA,EAOA,MAAM,MAA+B;AACnC,QAAI,OAAO,SAAS,UAAU;AAC5B,aAAO;AAAA,IACT;AAEA,WAAO,MAAM,MAAM,IAAI;AAAA,EACzB;AACF;;;ACnBA,SAAS,OAAO,cAAc;AAE9B,IAAO,kBAAQ;AAAA,EACb,OAAO,SAAiB,MAAwB;AAC9C,WAAO,OAAO,UAAU,KAAM,IAAI;AAAA,EACpC;AAAA;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,EACA;AAAA,EACA;AAAA,EACA;AAAA,EACA;AAAA,EACA;AAAA,EACA;AAAA,EACA,WAAAC;AAAA,EACA,aAAAC;AAAA,EACA;AAAA,EACA;AAAA,EACA;AAAA,EACA,YAAAC;AAAA,EACA;AAAA,EACA,WAAAC;AAAA,EACA;AAAA,EACA;AAAA,EACA;AAAA,EACA;AAAA,EACA;AAAA,EACA;AAAA,EACA;AAAA,EACA;AACF;AAEA,IAAO,eAAQ;","names":["sentence","truncatise","sentence","camelCase","snakeCase","pascalCase","capitalCase","camelCase","capitalCase","pascalCase","snakeCase"]}
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"sources":["../src/base64.ts","../src/string/milliseconds.ts"],"sourcesContent":["/*\n * @poppinss/utils\n *\n * (c) Poppinss\n *\n * For the full copyright and license information, please view the LICENSE\n * file that was distributed with this source code.\n */\n\n/**\n * Helper class to base64 encode/decode values with option\n * for url encoding and decoding\n */\nclass Base64 {\n /**\n * Base64 encode Buffer or string\n */\n encode(arrayBuffer: ArrayBuffer | SharedArrayBuffer): string\n encode(data: string, encoding?: BufferEncoding): string\n encode(data: ArrayBuffer | SharedArrayBuffer | string, encoding?: BufferEncoding): string {\n if (typeof data === 'string') {\n return Buffer.from(data, encoding).toString('base64')\n }\n return Buffer.from(data).toString('base64')\n }\n\n /**\n * Base64 decode a previously encoded string or Buffer.\n */\n decode(encode: string, encoding: BufferEncoding, strict: true): string\n decode(encode: string, encoding: undefined, strict: true): string\n decode(encode: string, encoding?: BufferEncoding, strict?: false): string | null\n decode(encode: Buffer, encoding?: BufferEncoding): string\n decode(\n encoded: string | Buffer,\n encoding: BufferEncoding = 'utf-8',\n strict: boolean = false\n ): string | null {\n if (Buffer.isBuffer(encoded)) {\n return encoded.toString(encoding)\n }\n\n const decoded = Buffer.from(encoded, 'base64').toString(encoding)\n const isInvalid = this.encode(decoded, encoding) !== encoded\n\n if (strict && isInvalid) {\n throw new Error('Cannot decode malformed value')\n }\n\n return isInvalid ? null : decoded\n }\n\n /**\n * Base64 encode Buffer or string to be URL safe. (RFC 4648)\n */\n urlEncode(arrayBuffer: ArrayBuffer | SharedArrayBuffer): string\n urlEncode(data: string, encoding?: BufferEncoding): string\n urlEncode(data: ArrayBuffer | SharedArrayBuffer | string, encoding?: BufferEncoding): string {\n const encoded = typeof data === 'string' ? this.encode(data, encoding) : this.encode(data)\n return encoded.replace(/\\+/g, '-').replace(/\\//g, '_').replace(/\\=/g, '')\n }\n\n /**\n * Base64 URL decode a previously encoded string or Buffer. (RFC 4648)\n */\n urlDecode(encode: string, encoding: BufferEncoding, strict: true): string\n urlDecode(encode: string, encoding: undefined, strict: true): string\n urlDecode(encode: string, encoding?: BufferEncoding, strict?: false): string | null\n urlDecode(encode: Buffer, encoding?: BufferEncoding): string\n urlDecode(\n encoded: string | Buffer,\n encoding: BufferEncoding = 'utf-8',\n strict: boolean = false\n ): string | null {\n if (Buffer.isBuffer(encoded)) {\n return encoded.toString(encoding)\n }\n\n const decoded = Buffer.from(encoded, 'base64').toString(encoding)\n const isInvalid = this.urlEncode(decoded, encoding) !== encoded\n\n if (strict && isInvalid) {\n throw new Error('Cannot urlDecode malformed value')\n }\n\n return isInvalid ? null : decoded\n }\n}\n\nexport const base64 = new Base64()\n","/*\n * @poppinss/utils\n *\n * (c) Poppinss\n *\n * For the full copyright and license information, please view the LICENSE\n * file that was distributed with this source code.\n */\n\nimport { parse, format } from '@lukeed/ms'\n\nexport default {\n format(milliseconds: number, long?: boolean): string {\n return format(milliseconds, long)\n },\n\n /**\n * Parse time expression string to milliseconds. The number value\n * is returned as it is, considering it is already in milliseconds\n */\n parse(duration: string | number): number {\n if (typeof duration === 'number') {\n return duration\n }\n\n const milliseconds = parse(duration)\n if (milliseconds === undefined) {\n throw new Error(`Invalid duration expression \"${duration}\"`)\n }\n\n return milliseconds\n },\n}\n"],"mappings":";AAaA,IAAM,SAAN,MAAa;AAAA,EAMX,OAAO,MAAgD,UAAmC;AACxF,QAAI,OAAO,SAA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;AAAA,EAMA,MAAM,UAAmC;AACvC,QAAI,OAAO,aAAa,UAAU;AAChC,aAAO;AAAA,IACT;AAEA,UAAM,eAAe,MAAM,QAAQ;AACnC,QAAI,iBAAiB,QAAW;AAC9B,YAAM,IAAI,MAAM,gCAAgC,QAAQ,GAAG;AAAA,IAC7D;AAEA,WAAO;AAAA,EACT;AACF;","names":[]}
|
package/build/index.d.ts
CHANGED
|
@@ -1,284 +1,25 @@
|
|
|
1
|
-
|
|
2
|
-
export {
|
|
3
|
-
|
|
4
|
-
|
|
5
|
-
|
|
6
|
-
|
|
7
|
-
|
|
8
|
-
|
|
9
|
-
|
|
10
|
-
|
|
11
|
-
|
|
12
|
-
|
|
13
|
-
|
|
14
|
-
|
|
15
|
-
|
|
16
|
-
|
|
17
|
-
|
|
18
|
-
decode(encode: string, encoding: undefined, strict: true): string;
|
|
19
|
-
decode(encode: string, encoding?: BufferEncoding, strict?: false): string | null;
|
|
20
|
-
decode(encode: Buffer, encoding?: BufferEncoding): string;
|
|
21
|
-
/**
|
|
22
|
-
* Base64 encode Buffer or string to be URL safe. (RFC 4648)
|
|
23
|
-
*/
|
|
24
|
-
urlEncode(arrayBuffer: ArrayBuffer | SharedArrayBuffer): string;
|
|
25
|
-
urlEncode(data: string, encoding?: BufferEncoding): string;
|
|
26
|
-
/**
|
|
27
|
-
* Base64 URL decode a previously encoded string or Buffer. (RFC 4648)
|
|
28
|
-
*/
|
|
29
|
-
urlDecode(encode: string, encoding: BufferEncoding, strict: true): string;
|
|
30
|
-
urlDecode(encode: string, encoding: undefined, strict: true): string;
|
|
31
|
-
urlDecode(encode: string, encoding?: BufferEncoding, strict?: false): string | null;
|
|
32
|
-
urlDecode(encode: Buffer, encoding?: BufferEncoding): string;
|
|
33
|
-
}
|
|
34
|
-
declare const base64: Base64;
|
|
35
|
-
|
|
36
|
-
interface UnaryFunction<T, R> {
|
|
37
|
-
(source: T): R;
|
|
38
|
-
}
|
|
39
|
-
/**
|
|
40
|
-
* Compose a class by applying mixins to it.
|
|
41
|
-
* The code is inspired by https://justinfagnani.com/2015/12/21/real-mixins-with-javascript-classes/, its
|
|
42
|
-
* just that I have added the support for static types too.
|
|
43
|
-
*/
|
|
44
|
-
declare function compose<T extends Constructor$1, A>(superclass: T, mixin: UnaryFunction<T, A>): A;
|
|
45
|
-
declare function compose<T extends Constructor$1, A, B>(superclass: T, mixin: UnaryFunction<T, A>, mixinB: UnaryFunction<A, B>): B;
|
|
46
|
-
declare function compose<T extends Constructor$1, A, B, C>(superclass: T, mixin: UnaryFunction<T, A>, mixinB: UnaryFunction<A, B>, mixinC: UnaryFunction<B, C>): C;
|
|
47
|
-
declare function compose<T extends Constructor$1, A, B, C, D>(superclass: T, mixin: UnaryFunction<T, A>, mixinB: UnaryFunction<A, B>, mixinC: UnaryFunction<B, C>, mixinD: UnaryFunction<C, D>): D;
|
|
48
|
-
declare function compose<T extends Constructor$1, A, B, C, D, E>(superclass: T, mixin: UnaryFunction<T, A>, mixinB: UnaryFunction<A, B>, mixinC: UnaryFunction<B, C>, mixinD: UnaryFunction<C, D>, mixinE: UnaryFunction<D, E>): E;
|
|
49
|
-
declare function compose<T extends Constructor$1, A, B, C, D, E, F>(superclass: T, mixin: UnaryFunction<T, A>, mixinB: UnaryFunction<A, B>, mixinC: UnaryFunction<B, C>, mixinD: UnaryFunction<C, D>, mixinF: UnaryFunction<E, F>): F;
|
|
50
|
-
declare function compose<T extends Constructor$1, A, B, C, D, E, F, G>(superclass: T, mixin: UnaryFunction<T, A>, mixinB: UnaryFunction<A, B>, mixinC: UnaryFunction<B, C>, mixinD: UnaryFunction<C, D>, mixinF: UnaryFunction<E, F>, mixinG: UnaryFunction<F, G>): G;
|
|
51
|
-
declare function compose<T extends Constructor$1, A, B, C, D, E, F, G, H>(superclass: T, mixin: UnaryFunction<T, A>, mixinB: UnaryFunction<A, B>, mixinC: UnaryFunction<B, C>, mixinD: UnaryFunction<C, D>, mixinF: UnaryFunction<E, F>, mixinG: UnaryFunction<F, G>, mixinH: UnaryFunction<G, H>): H;
|
|
52
|
-
declare function compose<T extends Constructor$1, A, B, C, D, E, F, G, H, I>(superclass: T, mixin: UnaryFunction<T, A>, mixinB: UnaryFunction<A, B>, mixinC: UnaryFunction<B, C>, mixinD: UnaryFunction<C, D>, mixinF: UnaryFunction<E, F>, mixinG: UnaryFunction<F, G>, mixinH: UnaryFunction<G, H>, mixinI: UnaryFunction<H, I>): I;
|
|
53
|
-
|
|
54
|
-
/**
|
|
55
|
-
* Dynamically import a module and ensure it has a default export
|
|
56
|
-
*/
|
|
57
|
-
declare function importDefault<T extends object>(importFn: () => Promise<T>, filePath?: string): Promise<T extends {
|
|
58
|
-
default: infer A;
|
|
59
|
-
} ? A : never>;
|
|
60
|
-
|
|
61
|
-
type Constructor = new (...args: any[]) => any;
|
|
62
|
-
type AbstractConstructor = abstract new (...args: any[]) => any;
|
|
63
|
-
/**
|
|
64
|
-
* Define static properties on a class with inheritance in play.
|
|
65
|
-
*/
|
|
66
|
-
declare function defineStaticProperty<T extends Constructor | AbstractConstructor, Prop extends keyof T>(self: T, propertyName: Prop, { initialValue, strategy, }: {
|
|
67
|
-
initialValue: T[Prop];
|
|
68
|
-
strategy: 'inherit' | 'define' | ((value: T[Prop]) => T[Prop]);
|
|
69
|
-
}): void;
|
|
70
|
-
|
|
71
|
-
/**
|
|
72
|
-
* Extended Error object with the option to set error `status` and `code`.
|
|
73
|
-
* At AdonisJs, we prefer exceptions with proper error codes to handle
|
|
74
|
-
* them without relying on message pattern matching.
|
|
75
|
-
*
|
|
76
|
-
* ```js
|
|
77
|
-
* new Exception('message', 500, 'E_RUNTIME_EXCEPTION')
|
|
78
|
-
* ```
|
|
79
|
-
*/
|
|
80
|
-
declare class Exception extends Error {
|
|
81
|
-
/**
|
|
82
|
-
* Static properties to defined on the exception once
|
|
83
|
-
* and then re-use them
|
|
84
|
-
*/
|
|
85
|
-
static help?: string;
|
|
86
|
-
static code?: string;
|
|
87
|
-
static status?: number;
|
|
88
|
-
static message?: string;
|
|
89
|
-
/**
|
|
90
|
-
* Name of the class that raised the exception.
|
|
91
|
-
*/
|
|
92
|
-
name: string;
|
|
93
|
-
/**
|
|
94
|
-
* Optional help description for the error. You can use it to define additional
|
|
95
|
-
* human readable information for the error.
|
|
96
|
-
*/
|
|
97
|
-
help?: string;
|
|
98
|
-
/**
|
|
99
|
-
* A machine readable error code. This will allow the error handling logic
|
|
100
|
-
* to narrow down exceptions based upon the error code.
|
|
101
|
-
*/
|
|
102
|
-
code?: string;
|
|
103
|
-
/**
|
|
104
|
-
* A status code for the error. Usually helpful when converting errors
|
|
105
|
-
* to HTTP responses.
|
|
106
|
-
*/
|
|
107
|
-
status: number;
|
|
108
|
-
constructor(message?: string, options?: ErrorOptions & {
|
|
109
|
-
code?: string;
|
|
110
|
-
status?: number;
|
|
111
|
-
});
|
|
112
|
-
get [Symbol.toStringTag](): string;
|
|
113
|
-
toString(): string;
|
|
114
|
-
}
|
|
115
|
-
/**
|
|
116
|
-
* Helper to create anonymous error classes
|
|
117
|
-
*/
|
|
118
|
-
declare function createError<T extends any[] = never>(message: string, code: string, status?: number): typeof Exception & T extends never ? {
|
|
119
|
-
new (args?: any, options?: ErrorOptions): Exception;
|
|
120
|
-
} : {
|
|
121
|
-
new (args: T, options?: ErrorOptions): Exception;
|
|
122
|
-
};
|
|
123
|
-
|
|
124
|
-
/**
|
|
125
|
-
* Recursively flatten an object/array.
|
|
126
|
-
*/
|
|
127
|
-
declare function flatten<X = Record<string, any>, Y = unknown>(input: Y, glue?: string, keepNullish?: boolean): X;
|
|
128
|
-
|
|
129
|
-
/**
|
|
130
|
-
* Returns an array of file paths from the given location. You can
|
|
131
|
-
* optionally filter and sort files by passing relevant options
|
|
132
|
-
*
|
|
133
|
-
* ```ts
|
|
134
|
-
* await fsReadAll(new URL('./', import.meta.url))
|
|
135
|
-
*
|
|
136
|
-
* await fsReadAll(new URL('./', import.meta.url), {
|
|
137
|
-
* filter: (filePath) => filePath.endsWith('.js')
|
|
138
|
-
* })
|
|
139
|
-
|
|
140
|
-
* await fsReadAll(new URL('./', import.meta.url), {
|
|
141
|
-
* absolute: true,
|
|
142
|
-
* unixPaths: true
|
|
143
|
-
* })
|
|
144
|
-
* ```
|
|
145
|
-
*/
|
|
146
|
-
declare function fsImportAll(location: string | URL, options?: ImportAllFilesOptions): Promise<any>;
|
|
147
|
-
|
|
148
|
-
/**
|
|
149
|
-
* Returns an array of file paths from the given location. You can
|
|
150
|
-
* optionally filter and sort files by passing relevant options
|
|
151
|
-
*
|
|
152
|
-
* ```ts
|
|
153
|
-
* await fsReadAll(new URL('./', import.meta.url))
|
|
154
|
-
*
|
|
155
|
-
* await fsReadAll(new URL('./', import.meta.url), {
|
|
156
|
-
* filter: (filePath) => filePath.endsWith('.js')
|
|
157
|
-
* })
|
|
158
|
-
|
|
159
|
-
* await fsReadAll(new URL('./', import.meta.url), {
|
|
160
|
-
* absolute: true,
|
|
161
|
-
* unixPaths: true
|
|
162
|
-
* })
|
|
163
|
-
* ```
|
|
164
|
-
*/
|
|
165
|
-
declare function fsReadAll(location: string | URL, options?: ReadAllFilesOptions): Promise<string[]>;
|
|
166
|
-
|
|
167
|
-
/**
|
|
168
|
-
* Returns `true` when file ends with `.js`, `.json` or
|
|
169
|
-
* `.ts` but not `.d.ts`.
|
|
170
|
-
*/
|
|
171
|
-
declare function isScriptFile(filePath: string): boolean;
|
|
172
|
-
|
|
173
|
-
/**
|
|
174
|
-
* Message builder exposes an API to "JSON.stringify" values by
|
|
175
|
-
* encoding purpose and expiry date inside them.
|
|
176
|
-
*
|
|
177
|
-
* The return value must be further encrypted to prevent tempering.
|
|
178
|
-
*/
|
|
179
|
-
declare class MessageBuilder {
|
|
180
|
-
#private;
|
|
181
|
-
/**
|
|
182
|
-
* Builds a message by encoding expiry date and purpose inside it.
|
|
183
|
-
*/
|
|
184
|
-
build(message: any, expiresIn?: string | number, purpose?: string): string;
|
|
185
|
-
/**
|
|
186
|
-
* Verifies the message for expiry and purpose.
|
|
187
|
-
*/
|
|
188
|
-
verify<T extends any>(message: any, purpose?: string): null | T;
|
|
189
|
-
}
|
|
190
|
-
|
|
191
|
-
/**
|
|
192
|
-
* Perform natural sorting with "Array.sort()" method
|
|
193
|
-
*/
|
|
194
|
-
declare function naturalSort(current: string, next: string): number;
|
|
195
|
-
|
|
196
|
-
/**
|
|
197
|
-
* A simple class to build an object incrementally. It is helpful when you
|
|
198
|
-
* want to add properties to the object conditionally.
|
|
199
|
-
*
|
|
200
|
-
* Instead of writing
|
|
201
|
-
* ```
|
|
202
|
-
* const obj = {
|
|
203
|
-
* ...(user.id ? { id: user.id } : {}),
|
|
204
|
-
* ...(user.firstName && user.lastName ? { name: `${user.firstName} ${user.lastName}` } : {}),
|
|
205
|
-
* }
|
|
206
|
-
* ```
|
|
207
|
-
*
|
|
208
|
-
* You can write
|
|
209
|
-
*
|
|
210
|
-
* const obj = new ObjectBuilder()
|
|
211
|
-
* .add('id', user.id)
|
|
212
|
-
* .add(
|
|
213
|
-
* 'fullName',
|
|
214
|
-
* user.firstName && user.lastName ? `${user.firstName} ${user.lastName}` : undefined
|
|
215
|
-
* )
|
|
216
|
-
* .toObject()
|
|
217
|
-
*/
|
|
218
|
-
declare class ObjectBuilder<ReturnType extends Record<string, any>, IgnoreNull extends boolean = false> {
|
|
219
|
-
#private;
|
|
220
|
-
values: ReturnType;
|
|
221
|
-
constructor(initialValue: ReturnType, ignoreNull?: IgnoreNull);
|
|
222
|
-
/**
|
|
223
|
-
* Add a key-value pair to the object
|
|
224
|
-
*
|
|
225
|
-
* - Undefined values are ignored
|
|
226
|
-
* - Null values are ignored, when `ignoreNull` is set to true
|
|
227
|
-
*/
|
|
228
|
-
add<Prop extends string>(key: Prop, value: undefined): this;
|
|
229
|
-
add<Prop extends string, Value>(key: Prop, value: Value): ObjectBuilder<ReturnType & {
|
|
230
|
-
[P in Prop]: Value;
|
|
231
|
-
}, IgnoreNull>;
|
|
232
|
-
/**
|
|
233
|
-
* Remove key from the object
|
|
234
|
-
*/
|
|
235
|
-
remove<K extends keyof ReturnType>(key: K): this;
|
|
236
|
-
/**
|
|
237
|
-
* Find if a value exists
|
|
238
|
-
*/
|
|
239
|
-
has<K extends keyof ReturnType>(key: K): boolean;
|
|
240
|
-
/**
|
|
241
|
-
* Get the existing value for a given key
|
|
242
|
-
*/
|
|
243
|
-
get<K extends keyof ReturnType>(key: K): ReturnType[K];
|
|
244
|
-
/**
|
|
245
|
-
* Get the underlying constructed object
|
|
246
|
-
*/
|
|
247
|
-
toObject(): IgnoreNull extends true ? {
|
|
248
|
-
[K in keyof OmitProperties<ReturnType, null>]: ReturnType[K];
|
|
249
|
-
} : {
|
|
250
|
-
[K in keyof ReturnType]: ReturnType[K];
|
|
251
|
-
};
|
|
252
|
-
}
|
|
253
|
-
|
|
254
|
-
type BufferSafeValue = ArrayBuffer | SharedArrayBuffer | number[] | string | {
|
|
255
|
-
valueOf(): string | object;
|
|
256
|
-
} | {
|
|
257
|
-
[Symbol.toPrimitive](hint: 'string'): string;
|
|
258
|
-
};
|
|
259
|
-
/**
|
|
260
|
-
* Compare two values to see if they are equal. The comparison is done in
|
|
261
|
-
* a way to avoid timing-attacks.
|
|
262
|
-
*/
|
|
263
|
-
declare function safeEqual<T extends BufferSafeValue, U extends BufferSafeValue>(trustedValue: T, userInput: U): boolean;
|
|
264
|
-
|
|
265
|
-
declare class RuntimeException extends Exception {
|
|
266
|
-
static code: string;
|
|
267
|
-
static status: number;
|
|
268
|
-
}
|
|
269
|
-
|
|
270
|
-
declare class InvalidArgumentsException extends Exception {
|
|
271
|
-
static code: string;
|
|
272
|
-
static status: number;
|
|
273
|
-
}
|
|
274
|
-
|
|
1
|
+
/// <reference types="node" resolution-mode="require"/>
|
|
2
|
+
export { base64 } from './src/base64.js';
|
|
3
|
+
export { compose } from './src/compose.js';
|
|
4
|
+
export { importDefault } from './src/import_default.js';
|
|
5
|
+
export { defineStaticProperty } from './src/define_static_property.js';
|
|
6
|
+
export { Exception, createError } from './src/exception.js';
|
|
7
|
+
export { flatten } from './src/flatten.js';
|
|
8
|
+
export { fsImportAll } from './src/fs_import_all.js';
|
|
9
|
+
export { fsReadAll } from './src/fs_read_all.js';
|
|
10
|
+
export { isScriptFile } from './src/is_script_file.js';
|
|
11
|
+
export { MessageBuilder } from './src/message_builder.js';
|
|
12
|
+
export { naturalSort } from './src/natural_sort.js';
|
|
13
|
+
export { ObjectBuilder } from './src/object_builder.js';
|
|
14
|
+
export { safeEqual } from './src/safe_equal.js';
|
|
15
|
+
export { slash } from './src/slash.js';
|
|
16
|
+
export { RuntimeException } from './src/exceptions/runtime_exception.js';
|
|
17
|
+
export { InvalidArgumentsException } from './src/exceptions/invalid_arguments_exception.js';
|
|
275
18
|
/**
|
|
276
19
|
* Get dirname for a given file path URL
|
|
277
20
|
*/
|
|
278
|
-
declare function getDirname(url: string | URL): string;
|
|
21
|
+
export declare function getDirname(url: string | URL): string;
|
|
279
22
|
/**
|
|
280
23
|
* Get filename for a given file path URL
|
|
281
24
|
*/
|
|
282
|
-
declare function getFilename(url: string | URL): string;
|
|
283
|
-
|
|
284
|
-
export { Exception, InvalidArgumentsException, MessageBuilder, ObjectBuilder, RuntimeException, base64, compose, createError, defineStaticProperty, flatten, fsImportAll, fsReadAll, getDirname, getFilename, importDefault, isScriptFile, naturalSort, safeEqual };
|
|
25
|
+
export declare function getFilename(url: string | URL): string;
|
package/build/index.js
CHANGED
|
@@ -1,10 +1,10 @@
|
|
|
1
1
|
import {
|
|
2
2
|
base64,
|
|
3
3
|
milliseconds_default
|
|
4
|
-
} from "./chunk-
|
|
4
|
+
} from "./chunk-NKGAOHNN.js";
|
|
5
5
|
import {
|
|
6
6
|
main_default
|
|
7
|
-
} from "./chunk-
|
|
7
|
+
} from "./chunk-IOBSMUFC.js";
|
|
8
8
|
|
|
9
9
|
// index.ts
|
|
10
10
|
import { fileURLToPath as fileURLToPath3 } from "node:url";
|
|
@@ -371,3 +371,4 @@ export {
|
|
|
371
371
|
safeEqual,
|
|
372
372
|
default2 as slash
|
|
373
373
|
};
|
|
374
|
+
//# sourceMappingURL=index.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"sources":["../index.ts","../src/compose.ts","../src/exception.ts","../src/exceptions/runtime_exception.ts","../src/import_default.ts","../src/define_static_property.ts","../src/flatten.ts","../src/fs_import_all.ts","../src/fs_read_all.ts","../src/slash.ts","../src/natural_sort.ts","../src/is_script_file.ts","../src/message_builder.ts","../src/object_builder.ts","../src/safe_equal.ts","../src/exceptions/invalid_arguments_exception.ts"],"sourcesContent":["/*\n * @poppinss/utils\n *\n * (c) Poppinss\n *\n * For the full copyright and license information, please view the LICENSE\n * file that was distributed with this source code.\n */\n\nimport { fileURLToPath } from 'node:url'\nimport { dirname as pathDirname } from 'node:path'\n\nexport { base64 } from './src/base64.js'\nexport { compose } from './src/compose.js'\nexport { importDefault } from './src/import_default.js'\nexport { defineStaticProperty } from './src/define_static_property.js'\nexport { Exception, createError } from './src/exception.js'\nexport { flatten } from './src/flatten.js'\nexport { fsImportAll } from './src/fs_import_all.js'\nexport { fsReadAll } from './src/fs_read_all.js'\nexport { isScriptFile } from './src/is_script_file.js'\nexport { MessageBuilder } from './src/message_builder.js'\nexport { naturalSort } from './src/natural_sort.js'\nexport { ObjectBuilder } from './src/object_builder.js'\nexport { safeEqual } from './src/safe_equal.js'\nexport { slash } from './src/slash.js'\nexport { RuntimeException } from './src/exceptions/runtime_exception.js'\nexport { InvalidArgumentsException } from './src/exceptions/invalid_arguments_exception.js'\n\n/**\n * Get dirname for a given file path URL\n */\nexport function getDirname(url: string | URL) {\n return pathDirname(getFilename(url))\n}\n\n/**\n * Get filename for a given file path URL\n */\nexport function getFilename(url: string | URL) {\n return fileURLToPath(url)\n}\n","/*\n * @poppinss/utils\n *\n * (c) Poppinss\n *\n * For the full copyright and license information, please view the LICENSE\n * file that was distributed with this source code.\n */\n\nimport type { Constructor } from './types.js'\n\ninterface UnaryFunction<T, R> {\n (source: T): R\n}\n\n/**\n * Compose a class by applying mixins to it.\n * The code is inspired by https://justinfagnani.com/2015/12/21/real-mixins-with-javascript-classes/, its\n * just that I have added the support for static types too.\n */\nexport function compose<T extends Constructor, A>(superclass: T, mixin: UnaryFunction<T, A>): A\nexport function compose<T extends Constructor, A, B>(\n superclass: T,\n mixin: UnaryFunction<T, A>,\n mixinB: UnaryFunction<A, B>\n): B\nexport function compose<T extends Constructor, A, B, C>(\n superclass: T,\n mixin: UnaryFunction<T, A>,\n mixinB: UnaryFunction<A, B>,\n mixinC: UnaryFunction<B, C>\n): C\nexport function compose<T extends Constructor, A, B, C, D>(\n superclass: T,\n mixin: UnaryFunction<T, A>,\n mixinB: UnaryFunction<A, B>,\n mixinC: UnaryFunction<B, C>,\n mixinD: UnaryFunction<C, D>\n): D\nexport function compose<T extends Constructor, A, B, C, D, E>(\n superclass: T,\n mixin: UnaryFunction<T, A>,\n mixinB: UnaryFunction<A, B>,\n mixinC: UnaryFunction<B, C>,\n mixinD: UnaryFunction<C, D>,\n mixinE: UnaryFunction<D, E>\n): E\nexport function compose<T extends Constructor, A, B, C, D, E, F>(\n superclass: T,\n mixin: UnaryFunction<T, A>,\n mixinB: UnaryFunction<A, B>,\n mixinC: UnaryFunction<B, C>,\n mixinD: UnaryFunction<C, D>,\n mixinF: UnaryFunction<E, F>\n): F\nexport function compose<T extends Constructor, A, B, C, D, E, F, G>(\n superclass: T,\n mixin: UnaryFunction<T, A>,\n mixinB: UnaryFunction<A, B>,\n mixinC: UnaryFunction<B, C>,\n mixinD: UnaryFunction<C, D>,\n mixinF: UnaryFunction<E, F>,\n mixinG: UnaryFunction<F, G>\n): G\nexport function compose<T extends Constructor, A, B, C, D, E, F, G, H>(\n superclass: T,\n mixin: UnaryFunction<T, A>,\n mixinB: UnaryFunction<A, B>,\n mixinC: UnaryFunction<B, C>,\n mixinD: UnaryFunction<C, D>,\n mixinF: UnaryFunction<E, F>,\n mixinG: UnaryFunction<F, G>,\n mixinH: UnaryFunction<G, H>\n): H\nexport function compose<T extends Constructor, A, B, C, D, E, F, G, H, I>(\n superclass: T,\n mixin: UnaryFunction<T, A>,\n mixinB: UnaryFunction<A, B>,\n mixinC: UnaryFunction<B, C>,\n mixinD: UnaryFunction<C, D>,\n mixinF: UnaryFunction<E, F>,\n mixinG: UnaryFunction<F, G>,\n mixinH: UnaryFunction<G, H>,\n mixinI: UnaryFunction<H, I>\n): I\nexport function compose<T extends Constructor, Mixins extends UnaryFunction<T, T>>(\n superclass: T,\n ...mixins: Mixins[]\n) {\n return mixins.reduce((c, mixin) => mixin(c), superclass)\n}\n","/*\n * @poppinss/utils\n *\n * (c) Poppinss\n *\n * For the full copyright and license information, please view the LICENSE\n * file that was distributed with this source code.\n */\n\nimport { format } from 'node:util'\n\n/**\n * Extended Error object with the option to set error `status` and `code`.\n * At AdonisJs, we prefer exceptions with proper error codes to handle\n * them without relying on message pattern matching.\n *\n * ```js\n * new Exception('message', 500, 'E_RUNTIME_EXCEPTION')\n * ```\n */\nexport class Exception extends Error {\n /**\n * Static properties to defined on the exception once\n * and then re-use them\n */\n declare static help?: string\n declare static code?: string\n declare static status?: number\n declare static message?: string\n\n /**\n * Name of the class that raised the exception.\n */\n name: string\n\n /**\n * Optional help description for the error. You can use it to define additional\n * human readable information for the error.\n */\n declare help?: string\n\n /**\n * A machine readable error code. This will allow the error handling logic\n * to narrow down exceptions based upon the error code.\n */\n declare code?: string\n\n /**\n * A status code for the error. Usually helpful when converting errors\n * to HTTP responses.\n */\n status: number\n\n constructor(message?: string, options?: ErrorOptions & { code?: string; status?: number }) {\n super(message, options)\n\n const ErrorConstructor = this.constructor as typeof Exception\n\n this.name = ErrorConstructor.name\n this.message = message || ErrorConstructor.message || ''\n this.status = options?.status || ErrorConstructor.status || 500\n\n const code = options?.code || ErrorConstructor.code\n if (code !== undefined) {\n this.code = code\n }\n\n const help = ErrorConstructor.help\n if (help !== undefined) {\n this.help = help\n }\n\n Error.captureStackTrace(this, ErrorConstructor)\n }\n\n get [Symbol.toStringTag]() {\n return this.constructor.name\n }\n\n toString() {\n if (this.code) {\n return `${this.name} [${this.code}]: ${this.message}`\n }\n return `${this.name}: ${this.message}`\n }\n}\n\n/**\n * Helper to create anonymous error classes\n */\nexport function createError<T extends any[] = never>(\n message: string,\n code: string,\n status?: number\n): typeof Exception & T extends never\n ? { new (args?: any, options?: ErrorOptions): Exception }\n : { new (args: T, options?: ErrorOptions): Exception } {\n return class extends Exception {\n static message = message\n static code = code\n static status = status\n\n constructor(args: T, options?: ErrorOptions) {\n super(format(message, ...(args || [])), options)\n }\n }\n}\n","/*\n * @poppinss/utils\n *\n * (c) Poppinss\n *\n * For the full copyright and license information, please view the LICENSE\n * file that was distributed with this source code.\n */\n\nimport { Exception } from '../exception.js'\n\nexport class RuntimeException extends Exception {\n static code = 'E_RUNTIME_EXCEPTION'\n static status = 500\n}\n","/*\n * @poppinss/utils\n *\n * (c) Poppinss\n *\n * For the full copyright and license information, please view the LICENSE\n * file that was distributed with this source code.\n */\n\nimport { RuntimeException } from './exceptions/runtime_exception.js'\n\n/**\n * Dynamically import a module and ensure it has a default export\n */\nexport async function importDefault<T extends object>(\n importFn: () => Promise<T>,\n filePath?: string\n): Promise<T extends { default: infer A } ? A : never> {\n const moduleExports = await importFn()\n\n /**\n * Make sure a default export exists\n */\n if (!('default' in moduleExports)) {\n const errorMessage = filePath\n ? `Missing \"export default\" in module \"${filePath}\"`\n : `Missing \"export default\" from lazy import \"${importFn}\"`\n\n throw new RuntimeException(errorMessage, {\n cause: {\n source: importFn,\n },\n })\n }\n\n return moduleExports.default as Promise<T extends { default: infer A } ? A : never>\n}\n","/*\n * @poppinss/utils\n *\n * (c) Poppinss\n *\n * For the full copyright and license information, please view the LICENSE\n * file that was distributed with this source code.\n */\n\nimport lodash from '@poppinss/utils/lodash'\n\ntype Constructor = new (...args: any[]) => any\ntype AbstractConstructor = abstract new (...args: any[]) => any\n\n/**\n * Define static properties on a class with inheritance in play.\n */\nexport function defineStaticProperty<\n T extends Constructor | AbstractConstructor,\n Prop extends keyof T,\n>(\n self: T,\n propertyName: Prop,\n {\n initialValue,\n strategy,\n }: {\n initialValue: T[Prop]\n strategy: 'inherit' | 'define' | ((value: T[Prop]) => T[Prop])\n }\n) {\n if (!self.hasOwnProperty(propertyName)) {\n const value = self[propertyName]\n\n /**\n * Define the property as it is when the strategy is set\n * to \"define\". Or the value on the prototype chain\n * is set to undefined.\n */\n if (strategy === 'define' || value === undefined) {\n Object.defineProperty(self, propertyName, {\n value: initialValue,\n configurable: true,\n enumerable: true,\n writable: true,\n })\n return\n }\n\n Object.defineProperty(self, propertyName, {\n value: typeof strategy === 'function' ? strategy(value) : lodash.cloneDeep(value),\n configurable: true,\n enumerable: true,\n writable: true,\n })\n }\n}\n","/*\n * @poppinss/utils\n *\n * (c) Poppinss\n *\n * For the full copyright and license information, please view the LICENSE\n * file that was distributed with this source code.\n */\n\n// @ts-expect-error (Package has no types)\nimport { flattie } from 'flattie'\n\n/**\n * Recursively flatten an object/array.\n */\nexport function flatten<X = Record<string, any>, Y = unknown>(\n input: Y,\n glue?: string,\n keepNullish?: boolean\n): X {\n return flattie(input, glue, keepNullish)\n}\n","/*\n * @poppinss/utils\n *\n * (c) Poppinss\n *\n * For the full copyright and license information, please view the LICENSE\n * file that was distributed with this source code.\n */\n\nimport { fileURLToPath } from 'node:url'\nimport lodash from '@poppinss/utils/lodash'\nimport { extname, relative, sep } from 'node:path'\n\nimport { fsReadAll } from './fs_read_all.js'\nimport { ImportAllFilesOptions } from './types.js'\nimport { isScriptFile } from './is_script_file.js'\n\n/**\n * Import the file and update the values collection with the default\n * export.\n */\nasync function importFile(\n basePath: string,\n fileURL: string,\n values: any,\n options: ImportAllFilesOptions\n) {\n /**\n * Converting URL to file path\n */\n const filePath = fileURLToPath(fileURL)\n\n /**\n * Grab file extension\n */\n const fileExtension = extname(filePath)\n\n const collectionKey = relative(basePath, filePath) // Get file relative path\n .replace(new RegExp(`${fileExtension}$`), '') // Get rid of the file extension\n .split(sep) // Convert nested paths to an array of keys\n\n /**\n * Import module\n */\n const exportedValue =\n fileExtension === '.json'\n ? await import(fileURL, { assert: { type: 'json' } })\n : await import(fileURL)\n\n lodash.set(\n values,\n options.transformKeys ? options.transformKeys(collectionKey) : collectionKey,\n exportedValue.default ? exportedValue.default : { ...exportedValue }\n )\n}\n\n/**\n * Returns an array of file paths from the given location. You can\n * optionally filter and sort files by passing relevant options\n *\n * ```ts\n * await fsReadAll(new URL('./', import.meta.url))\n *\n * await fsReadAll(new URL('./', import.meta.url), {\n * filter: (filePath) => filePath.endsWith('.js')\n * })\n\n * await fsReadAll(new URL('./', import.meta.url), {\n * absolute: true,\n * unixPaths: true\n * })\n* ```\n */\nexport async function fsImportAll(\n location: string | URL,\n options?: ImportAllFilesOptions\n): Promise<any> {\n options = options || {}\n const collection: any = {}\n const normalizedLocation = typeof location === 'string' ? location : fileURLToPath(location)\n const files = await fsReadAll(normalizedLocation, {\n filter: isScriptFile,\n ...options,\n pathType: 'url',\n })\n\n /**\n * Parallelly import all the files and mutate the values collection\n */\n await Promise.all(files.map((file) => importFile(normalizedLocation, file, collection, options!)))\n\n return collection\n}\n","/*\n * @poppinss/utils\n *\n * (c) Poppinss\n *\n * For the full copyright and license information, please view the LICENSE\n * file that was distributed with this source code.\n */\n\nimport { join } from 'node:path'\nimport { readdir, stat } from 'node:fs/promises'\nimport { fileURLToPath, pathToFileURL } from 'node:url'\n\nimport { slash } from './slash.js'\nimport { naturalSort } from './natural_sort.js'\nimport { ReadAllFilesOptions } from './types.js'\n\n/**\n * Filter to remove dot files\n */\nfunction filterDotFiles(fileName: string) {\n return fileName[0] !== '.'\n}\n\n/**\n * Read all files from the directory recursively\n */\nasync function readFiles(\n root: string,\n files: string[],\n options: ReadAllFilesOptions,\n relativePath: string\n): Promise<void> {\n const location = join(root, relativePath)\n const stats = await stat(location)\n\n if (stats.isDirectory()) {\n let locationFiles = await readdir(location)\n\n await Promise.all(\n locationFiles.filter(filterDotFiles).map((file) => {\n return readFiles(root, files, options, join(relativePath, file))\n })\n )\n\n return\n }\n\n const pathType = options.pathType || 'relative'\n switch (pathType) {\n case 'relative':\n files.push(relativePath)\n break\n case 'absolute':\n files.push(location)\n break\n case 'unixRelative':\n files.push(slash(relativePath))\n break\n case 'unixAbsolute':\n files.push(slash(location))\n break\n case 'url':\n files.push(pathToFileURL(location).href)\n }\n}\n\n/**\n * Returns an array of file paths from the given location. You can\n * optionally filter and sort files by passing relevant options\n *\n * ```ts\n * await fsReadAll(new URL('./', import.meta.url))\n *\n * await fsReadAll(new URL('./', import.meta.url), {\n * filter: (filePath) => filePath.endsWith('.js')\n * })\n\n * await fsReadAll(new URL('./', import.meta.url), {\n * absolute: true,\n * unixPaths: true\n * })\n* ```\n */\nexport async function fsReadAll(\n location: string | URL,\n options?: ReadAllFilesOptions\n): Promise<string[]> {\n const normalizedLocation = typeof location === 'string' ? location : fileURLToPath(location)\n const normalizedOptions = Object.assign({ absolute: false, sort: naturalSort }, options)\n const files: string[] = []\n\n /**\n * Check to see if the root directory exists and ignore\n * error when \"ignoreMissingRoot\" is set to true\n */\n try {\n await stat(normalizedLocation)\n } catch (error) {\n if (normalizedOptions.ignoreMissingRoot) {\n return []\n }\n\n throw error\n }\n\n await readFiles(normalizedLocation, files, normalizedOptions, '')\n\n if (normalizedOptions.filter) {\n return files.filter(normalizedOptions.filter).sort(normalizedOptions.sort)\n }\n\n return files.sort(normalizedOptions.sort)\n}\n","/*\n * @poppinss/utils\n *\n * (c) Poppinss\n *\n * For the full copyright and license information, please view the LICENSE\n * file that was distributed with this source code.\n */\n\nexport { default as slash } from 'slash'\n","/*\n * @poppinss/utils\n *\n * (c) Poppinss\n *\n * For the full copyright and license information, please view the LICENSE\n * file that was distributed with this source code.\n */\n\n/**\n * Perform natural sorting with \"Array.sort()\" method\n */\nexport function naturalSort(current: string, next: string) {\n return current.localeCompare(next, undefined, { numeric: true, sensitivity: 'base' })\n}\n","/*\n * @poppinss/utils\n *\n * (c) Poppinss\n *\n * For the full copyright and license information, please view the LICENSE\n * file that was distributed with this source code.\n */\n\nimport { extname } from 'node:path'\nconst JS_MODULES = ['.js', '.json', '.cjs', '.mjs']\n\n/**\n * Returns `true` when file ends with `.js`, `.json` or\n * `.ts` but not `.d.ts`.\n */\nexport function isScriptFile(filePath: string) {\n const ext = extname(filePath)\n\n if (JS_MODULES.includes(ext)) {\n return true\n }\n\n if (ext === '.ts' && !filePath.endsWith('.d.ts')) {\n return true\n }\n\n return false\n}\n","/*\n * @poppinss/utils\n *\n * (c) Poppinss\n *\n * For the full copyright and license information, please view the LICENSE\n * file that was distributed with this source code.\n */\n\nimport json from './json/main.js'\nimport milliseconds from './string/milliseconds.js'\n\n/**\n * Message builder exposes an API to \"JSON.stringify\" values by\n * encoding purpose and expiry date inside them.\n *\n * The return value must be further encrypted to prevent tempering.\n */\nexport class MessageBuilder {\n #getExpiryDate(expiresIn?: string | number): undefined | Date {\n if (!expiresIn) {\n return undefined\n }\n\n const expiryMs = milliseconds.parse(expiresIn)\n return new Date(Date.now() + expiryMs)\n }\n\n /**\n * Returns a boolean telling, if message has been expired or not\n */\n #isExpired(message: any) {\n if (!message.expiryDate) {\n return false\n }\n\n const expiryDate = new Date(message.expiryDate)\n return Number.isNaN(expiryDate.getTime()) || expiryDate < new Date()\n }\n\n /**\n * Builds a message by encoding expiry date and purpose inside it.\n */\n build(message: any, expiresIn?: string | number, purpose?: string): string {\n const expiryDate = this.#getExpiryDate(expiresIn)\n return json.safeStringify({ message, purpose, expiryDate })!\n }\n\n /**\n * Verifies the message for expiry and purpose.\n */\n verify<T extends any>(message: any, purpose?: string): null | T {\n const parsed = json.safeParse(message)\n\n /**\n * After JSON.parse we do not receive a valid object\n */\n if (typeof parsed !== 'object' || !parsed) {\n return null\n }\n\n /**\n * Missing \".message\" property\n */\n if (!parsed.message) {\n return null\n }\n\n /**\n * Ensure purposes are same.\n */\n if (parsed.purpose !== purpose) {\n return null\n }\n\n /**\n * Ensure isn't expired\n */\n if (this.#isExpired(parsed)) {\n return null\n }\n\n return parsed.message\n }\n}\n","/*\n * @poppinss/utils\n *\n * (c) Poppinss\n *\n * For the full copyright and license information, please view the LICENSE\n * file that was distributed with this source code.\n */\n\nimport { OmitProperties } from './types.js'\n\n/**\n * A simple class to build an object incrementally. It is helpful when you\n * want to add properties to the object conditionally.\n *\n * Instead of writing\n * ```\n * const obj = {\n * ...(user.id ? { id: user.id } : {}),\n * ...(user.firstName && user.lastName ? { name: `${user.firstName} ${user.lastName}` } : {}),\n * }\n * ```\n *\n * You can write\n *\n * const obj = new ObjectBuilder()\n * .add('id', user.id)\n * .add(\n * 'fullName',\n * user.firstName && user.lastName ? `${user.firstName} ${user.lastName}` : undefined\n * )\n * .toObject()\n */\nexport class ObjectBuilder<\n ReturnType extends Record<string, any>,\n IgnoreNull extends boolean = false,\n> {\n #ignoreNull: boolean\n values: ReturnType\n\n constructor(initialValue: ReturnType, ignoreNull?: IgnoreNull) {\n this.values = initialValue\n this.#ignoreNull = ignoreNull === true ? true : false\n }\n\n /**\n * Add a key-value pair to the object\n *\n * - Undefined values are ignored\n * - Null values are ignored, when `ignoreNull` is set to true\n */\n add<Prop extends string>(key: Prop, value: undefined): this\n add<Prop extends string, Value>(\n key: Prop,\n value: Value\n ): ObjectBuilder<ReturnType & { [P in Prop]: Value }, IgnoreNull>\n add<Prop extends string, Value>(key: Prop, value: Value): this {\n if (value === undefined) {\n return this\n }\n\n if (this.#ignoreNull === true && value === null) {\n return this\n }\n\n ;(this.values as any)[key] = value\n return this\n }\n\n /**\n * Remove key from the object\n */\n remove<K extends keyof ReturnType>(key: K): this {\n delete this.values[key]\n return this\n }\n\n /**\n * Find if a value exists\n */\n has<K extends keyof ReturnType>(key: K): boolean {\n return this.get(key) !== undefined\n }\n\n /**\n * Get the existing value for a given key\n */\n get<K extends keyof ReturnType>(key: K): ReturnType[K] {\n return this.values[key]\n }\n\n /**\n * Get the underlying constructed object\n */\n toObject(): IgnoreNull extends true\n ? { [K in keyof OmitProperties<ReturnType, null>]: ReturnType[K] }\n : { [K in keyof ReturnType]: ReturnType[K] } {\n return this.values\n }\n}\n","/*\n * @poppinss/utils\n *\n * (c) Poppinss\n *\n * For the full copyright and license information, please view the LICENSE\n * file that was distributed with this source code.\n */\n\nimport { Buffer } from 'node:buffer'\nimport { timingSafeEqual } from 'node:crypto'\n\ntype BufferSafeValue =\n | ArrayBuffer\n | SharedArrayBuffer\n | number[]\n | string\n | { valueOf(): string | object }\n | { [Symbol.toPrimitive](hint: 'string'): string }\n\n/**\n * Compare two values to see if they are equal. The comparison is done in\n * a way to avoid timing-attacks.\n */\nexport function safeEqual<T extends BufferSafeValue, U extends BufferSafeValue>(\n trustedValue: T,\n userInput: U\n): boolean {\n if (typeof trustedValue === 'string' && typeof userInput === 'string') {\n /**\n * The length of the comparison value.\n */\n const trustedLength = Buffer.byteLength(trustedValue)\n\n /**\n * Expected value\n */\n const trustedValueBuffer = Buffer.alloc(trustedLength, 0, 'utf-8')\n trustedValueBuffer.write(trustedValue)\n\n /**\n * Actual value (taken from user input)\n */\n const userValueBuffer = Buffer.alloc(trustedLength, 0, 'utf-8')\n userValueBuffer.write(userInput)\n\n /**\n * Ensure values are same and also have same length\n */\n return (\n timingSafeEqual(trustedValueBuffer, userValueBuffer) &&\n trustedLength === Buffer.byteLength(userInput)\n )\n }\n\n return timingSafeEqual(\n Buffer.from(trustedValue as ArrayBuffer | SharedArrayBuffer),\n Buffer.from(userInput as ArrayBuffer | SharedArrayBuffer)\n )\n}\n","/*\n * @poppinss/utils\n *\n * (c) Poppinss\n *\n * For the full copyright and license information, please view the LICENSE\n * file that was distributed with this source code.\n */\n\nimport { Exception } from '../exception.js'\n\nexport class InvalidArgumentsException extends Exception {\n static code = 'E_INVALID_ARGUMENTS_EXCEPTION'\n static status = 500\n}\n"],"mappings":";;;;;;;;;AASA,SAAS,iBAAAA,sBAAqB;AAC9B,SAAS,WAAW,mBAAmB;;;AC2EhC,SAAS,QACd,eACG,QACH;AACA,SA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T;AAAA;AAAA;AAAA;AAAA,EAKA,OAAmC,KAAc;AAC/C,WAAO,KAAK,OAAO,GAAG;AACtB,WAAO;AAAA,EACT;AAAA;AAAA;AAAA;AAAA,EAKA,IAAgC,KAAiB;AAC/C,WAAO,KAAK,IAAI,GAAG,MAAM;AAAA,EAC3B;AAAA;AAAA;AAAA;AAAA,EAKA,IAAgC,KAAuB;AACrD,WAAO,KAAK,OAAO,GAAG;AAAA,EACxB;AAAA;AAAA;AAAA;AAAA,EAKA,WAE+C;AAC7C,WAAO,KAAK;AAAA,EACd;AACF;;;AC1FA,SAAS,cAAc;AACvB,SAAS,uBAAuB;AAczB,SAAS,UACd,cACA,WACS;AACT,MAAI,OAAO,iBAAiB,YAAY,OAAO,cAAc,UAAU;AAIrE,UAAM,gBAAgB,OAAO,WAAW,YAAY;AAKpD,UAAM,qBAAqB,OAAO,MAAM,eAAe,GAAG,OAAO;AACjE,uBAAmB,MAAM,YAAY;AAKrC,UAAM,kBAAkB,OAAO,MAAM,eAAe,GAAG,OAAO;AAC9D,oBAAgB,MAAM,SAAS;AAK/B,WACE,gBAAgB,oBAAoB,eAAe,KACnD,kBAAkB,OAAO,WAAW,SAAS;AAAA,EAEjD;AAEA,SAAO;AAAA,IACL,OAAO,KAAK,YAA+C;AAAA,IAC3D,OAAO,KAAK,SAA4C;AAAA,EAC1D;AACF;;;AChDO,IAAM,4BAAN,cAAwC,UAAU;AAAA,EACvD,OAAO,OAAO;AAAA,EACd,OAAO,SAAS;AAClB;;;AfkBO,SAAS,WAAW,KAAmB;AAC5C,SAAO,YAAY,YAAY,GAAG,CAAC;AACrC;AAKO,SAAS,YAAY,KAAmB;AAC7C,SAAOG,eAAc,GAAG;AAC1B;","names":["fileURLToPath","fileURLToPath","lodash","extname","default","default","fileURLToPath","extname","lodash","fileURLToPath"]}
|
package/build/src/assert.d.ts
CHANGED
|
@@ -1,5 +1,3 @@
|
|
|
1
|
-
declare function assert(value: unknown, message?: string): asserts value;
|
|
2
|
-
declare function assertUnreachable(x?: never): never;
|
|
3
|
-
declare function assertNotNull<T>(value: T | null): asserts value is Exclude<T, null>;
|
|
4
|
-
|
|
5
|
-
export { assert, assertNotNull, assertUnreachable };
|
|
1
|
+
export declare function assert(value: unknown, message?: string): asserts value;
|
|
2
|
+
export declare function assertUnreachable(x?: never): never;
|
|
3
|
+
export declare function assertNotNull<T>(value: T | null): asserts value is Exclude<T, null>;
|
package/build/src/assert.js
CHANGED
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"sources":["../../src/assert.ts"],"sourcesContent":["/*\n * @poppinss/utils\n *\n * (c) Poppinss\n *\n * For the full copyright and license information, please view the LICENSE\n * file that was distributed with this source code.\n */\n\nexport function assert(value: unknown, message?: string): asserts value {\n if (!value) {\n throw new Error(message ?? 'value is falsy')\n }\n}\n\nexport function assertUnreachable(x?: never): never {\n throw new Error(`unreachable code executed: ${String(x)}`)\n}\n\nexport function assertNotNull<T>(value: T | null): asserts value is Exclude<T, null> {\n if (value === null) {\n throw new Error('unexpected null value')\n }\n}\n"],"mappings":";AASO,SAAS,OAAO,OAAgB,SAAiC;AACtE,MAAI,CAAC,OAAO;AACV,UAAM,IAAI,MAAM,WAAW,gBAAgB;AAAA,EAC7C;AACF;AAEO,SAAS,kBAAkB,GAAkB;AAClD,QAAM,IAAI,MAAM,8BAA8B,OAAO,CAAC,CAAC,EAAE;AAC3D;AAEO,SAAS,cAAiB,OAAoD;AACnF,MAAI,UAAU,MAAM;AAClB,UAAM,IAAI,MAAM,uBAAuB;AAAA,EACzC;AACF;","names":[]}
|
|
@@ -0,0 +1,33 @@
|
|
|
1
|
+
/// <reference types="node" resolution-mode="require"/>
|
|
2
|
+
/**
|
|
3
|
+
* Helper class to base64 encode/decode values with option
|
|
4
|
+
* for url encoding and decoding
|
|
5
|
+
*/
|
|
6
|
+
declare class Base64 {
|
|
7
|
+
/**
|
|
8
|
+
* Base64 encode Buffer or string
|
|
9
|
+
*/
|
|
10
|
+
encode(arrayBuffer: ArrayBuffer | SharedArrayBuffer): string;
|
|
11
|
+
encode(data: string, encoding?: BufferEncoding): string;
|
|
12
|
+
/**
|
|
13
|
+
* Base64 decode a previously encoded string or Buffer.
|
|
14
|
+
*/
|
|
15
|
+
decode(encode: string, encoding: BufferEncoding, strict: true): string;
|
|
16
|
+
decode(encode: string, encoding: undefined, strict: true): string;
|
|
17
|
+
decode(encode: string, encoding?: BufferEncoding, strict?: false): string | null;
|
|
18
|
+
decode(encode: Buffer, encoding?: BufferEncoding): string;
|
|
19
|
+
/**
|
|
20
|
+
* Base64 encode Buffer or string to be URL safe. (RFC 4648)
|
|
21
|
+
*/
|
|
22
|
+
urlEncode(arrayBuffer: ArrayBuffer | SharedArrayBuffer): string;
|
|
23
|
+
urlEncode(data: string, encoding?: BufferEncoding): string;
|
|
24
|
+
/**
|
|
25
|
+
* Base64 URL decode a previously encoded string or Buffer. (RFC 4648)
|
|
26
|
+
*/
|
|
27
|
+
urlDecode(encode: string, encoding: BufferEncoding, strict: true): string;
|
|
28
|
+
urlDecode(encode: string, encoding: undefined, strict: true): string;
|
|
29
|
+
urlDecode(encode: string, encoding?: BufferEncoding, strict?: false): string | null;
|
|
30
|
+
urlDecode(encode: Buffer, encoding?: BufferEncoding): string;
|
|
31
|
+
}
|
|
32
|
+
export declare const base64: Base64;
|
|
33
|
+
export {};
|
|
@@ -0,0 +1,19 @@
|
|
|
1
|
+
import type { Constructor } from './types.js';
|
|
2
|
+
interface UnaryFunction<T, R> {
|
|
3
|
+
(source: T): R;
|
|
4
|
+
}
|
|
5
|
+
/**
|
|
6
|
+
* Compose a class by applying mixins to it.
|
|
7
|
+
* The code is inspired by https://justinfagnani.com/2015/12/21/real-mixins-with-javascript-classes/, its
|
|
8
|
+
* just that I have added the support for static types too.
|
|
9
|
+
*/
|
|
10
|
+
export declare function compose<T extends Constructor, A>(superclass: T, mixin: UnaryFunction<T, A>): A;
|
|
11
|
+
export declare function compose<T extends Constructor, A, B>(superclass: T, mixin: UnaryFunction<T, A>, mixinB: UnaryFunction<A, B>): B;
|
|
12
|
+
export declare function compose<T extends Constructor, A, B, C>(superclass: T, mixin: UnaryFunction<T, A>, mixinB: UnaryFunction<A, B>, mixinC: UnaryFunction<B, C>): C;
|
|
13
|
+
export declare function compose<T extends Constructor, A, B, C, D>(superclass: T, mixin: UnaryFunction<T, A>, mixinB: UnaryFunction<A, B>, mixinC: UnaryFunction<B, C>, mixinD: UnaryFunction<C, D>): D;
|
|
14
|
+
export declare function compose<T extends Constructor, A, B, C, D, E>(superclass: T, mixin: UnaryFunction<T, A>, mixinB: UnaryFunction<A, B>, mixinC: UnaryFunction<B, C>, mixinD: UnaryFunction<C, D>, mixinE: UnaryFunction<D, E>): E;
|
|
15
|
+
export declare function compose<T extends Constructor, A, B, C, D, E, F>(superclass: T, mixin: UnaryFunction<T, A>, mixinB: UnaryFunction<A, B>, mixinC: UnaryFunction<B, C>, mixinD: UnaryFunction<C, D>, mixinF: UnaryFunction<E, F>): F;
|
|
16
|
+
export declare function compose<T extends Constructor, A, B, C, D, E, F, G>(superclass: T, mixin: UnaryFunction<T, A>, mixinB: UnaryFunction<A, B>, mixinC: UnaryFunction<B, C>, mixinD: UnaryFunction<C, D>, mixinF: UnaryFunction<E, F>, mixinG: UnaryFunction<F, G>): G;
|
|
17
|
+
export declare function compose<T extends Constructor, A, B, C, D, E, F, G, H>(superclass: T, mixin: UnaryFunction<T, A>, mixinB: UnaryFunction<A, B>, mixinC: UnaryFunction<B, C>, mixinD: UnaryFunction<C, D>, mixinF: UnaryFunction<E, F>, mixinG: UnaryFunction<F, G>, mixinH: UnaryFunction<G, H>): H;
|
|
18
|
+
export declare function compose<T extends Constructor, A, B, C, D, E, F, G, H, I>(superclass: T, mixin: UnaryFunction<T, A>, mixinB: UnaryFunction<A, B>, mixinC: UnaryFunction<B, C>, mixinD: UnaryFunction<C, D>, mixinF: UnaryFunction<E, F>, mixinG: UnaryFunction<F, G>, mixinH: UnaryFunction<G, H>, mixinI: UnaryFunction<H, I>): I;
|
|
19
|
+
export {};
|
|
@@ -0,0 +1,10 @@
|
|
|
1
|
+
type Constructor = new (...args: any[]) => any;
|
|
2
|
+
type AbstractConstructor = abstract new (...args: any[]) => any;
|
|
3
|
+
/**
|
|
4
|
+
* Define static properties on a class with inheritance in play.
|
|
5
|
+
*/
|
|
6
|
+
export declare function defineStaticProperty<T extends Constructor | AbstractConstructor, Prop extends keyof T>(self: T, propertyName: Prop, { initialValue, strategy, }: {
|
|
7
|
+
initialValue: T[Prop];
|
|
8
|
+
strategy: 'inherit' | 'define' | ((value: T[Prop]) => T[Prop]);
|
|
9
|
+
}): void;
|
|
10
|
+
export {};
|
|
@@ -0,0 +1,52 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Extended Error object with the option to set error `status` and `code`.
|
|
3
|
+
* At AdonisJs, we prefer exceptions with proper error codes to handle
|
|
4
|
+
* them without relying on message pattern matching.
|
|
5
|
+
*
|
|
6
|
+
* ```js
|
|
7
|
+
* new Exception('message', 500, 'E_RUNTIME_EXCEPTION')
|
|
8
|
+
* ```
|
|
9
|
+
*/
|
|
10
|
+
export declare class Exception extends Error {
|
|
11
|
+
/**
|
|
12
|
+
* Static properties to defined on the exception once
|
|
13
|
+
* and then re-use them
|
|
14
|
+
*/
|
|
15
|
+
static help?: string;
|
|
16
|
+
static code?: string;
|
|
17
|
+
static status?: number;
|
|
18
|
+
static message?: string;
|
|
19
|
+
/**
|
|
20
|
+
* Name of the class that raised the exception.
|
|
21
|
+
*/
|
|
22
|
+
name: string;
|
|
23
|
+
/**
|
|
24
|
+
* Optional help description for the error. You can use it to define additional
|
|
25
|
+
* human readable information for the error.
|
|
26
|
+
*/
|
|
27
|
+
help?: string;
|
|
28
|
+
/**
|
|
29
|
+
* A machine readable error code. This will allow the error handling logic
|
|
30
|
+
* to narrow down exceptions based upon the error code.
|
|
31
|
+
*/
|
|
32
|
+
code?: string;
|
|
33
|
+
/**
|
|
34
|
+
* A status code for the error. Usually helpful when converting errors
|
|
35
|
+
* to HTTP responses.
|
|
36
|
+
*/
|
|
37
|
+
status: number;
|
|
38
|
+
constructor(message?: string, options?: ErrorOptions & {
|
|
39
|
+
code?: string;
|
|
40
|
+
status?: number;
|
|
41
|
+
});
|
|
42
|
+
get [Symbol.toStringTag](): string;
|
|
43
|
+
toString(): string;
|
|
44
|
+
}
|
|
45
|
+
/**
|
|
46
|
+
* Helper to create anonymous error classes
|
|
47
|
+
*/
|
|
48
|
+
export declare function createError<T extends any[] = never>(message: string, code: string, status?: number): typeof Exception & T extends never ? {
|
|
49
|
+
new (args?: any, options?: ErrorOptions): Exception;
|
|
50
|
+
} : {
|
|
51
|
+
new (args: T, options?: ErrorOptions): Exception;
|
|
52
|
+
};
|