@poppinss/utils 6.5.1 → 6.7.0

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/README.md CHANGED
@@ -644,6 +644,53 @@ import lodash from '@poppinss/utils/lodash'
644
644
  lodash.pick(collection, keys)
645
645
  ```
646
646
 
647
+ ### Assertion helpers
648
+ The following assertion methods offers type-safe approach for writing conditionals and throwing error when the variable has unexpected values.
649
+
650
+ #### assertExists(message?: string)
651
+ Throws [AssertionError](https://nodejs.org/api/assert.html#new-assertassertionerroroptions) when the value is `false`, `null`, or `undefined`.
652
+
653
+ ```ts
654
+ import { assertExists } from '@poppinss/utils/assert'
655
+
656
+ const value = false as string | false
657
+ assertExists(value)
658
+
659
+ // value is string
660
+ ```
661
+
662
+ #### assertNotNull(value: unknown, message?: string)
663
+ Throws [AssertionError](https://nodejs.org/api/assert.html#new-assertassertionerroroptions) when the value is `null`.
664
+
665
+ ```ts
666
+ import { assertNotNull } from '@poppinss/utils/assert'
667
+
668
+ const value = null as string | null
669
+ assertNotNull(value)
670
+
671
+ // value is string
672
+ ```
673
+
674
+ #### assertIsDefined(value: unknown, message?: string)
675
+ Throws [AssertionError](https://nodejs.org/api/assert.html#new-assertassertionerroroptions) when the value is `undefined`.
676
+
677
+ ```ts
678
+ import { assertIsDefined } from '@poppinss/utils/assert'
679
+
680
+ const value = undefined as string | undefined
681
+ assertIsDefined(value)
682
+
683
+ // value is string
684
+ ```
685
+
686
+ #### assertUnreachable(value: unknown)
687
+ Throws [AssertionError](https://nodejs.org/api/assert.html#new-assertassertionerroroptions) when the method is invoked. In other words, this method always throws an exception.
688
+
689
+ ```ts
690
+ import { assertUnreachable } from '@poppinss/utils/assert'
691
+ assertUnreachable()
692
+ ```
693
+
647
694
  ### All other helpers
648
695
 
649
696
  The following helpers are exported from the package main module.
@@ -940,7 +987,7 @@ const files = await fsReadAll(dir, options)
940
987
  await Promise.all(
941
988
  files.map((file) => {
942
989
  if (file.endsWith('.json')) {
943
- return import(file, { assert: { type: 'json' } })
990
+ return import(file, { with: { type: 'json' } })
944
991
  }
945
992
 
946
993
  return import(file)
@@ -1097,6 +1144,79 @@ builder.add(key)
1097
1144
  builder.toObject() // get plain object
1098
1145
  ```
1099
1146
 
1147
+ #### Secret
1148
+
1149
+ Creates a secret value that prevents itself from getting logged inside `console.log` statements, during JSON serialization, and string concatenation.
1150
+
1151
+ To understand why you need a special `Secret` object, you need to understand the root of the problem. Let's start with an example.
1152
+
1153
+ Given that you have a `Token` class that generates an opaque token for a user and persists its hash inside the database. The plain token (aka raw value) is shared with the user and it should only be visible once (for security reasons). Here is a dummy implementation of the same.
1154
+
1155
+ ```ts
1156
+ class Token {
1157
+ generate() {
1158
+ return {
1159
+ value: 'opaque_raw_token',
1160
+ hash: 'hash_of_raw_token_inside_db',
1161
+ }
1162
+ }
1163
+ }
1164
+
1165
+ const token = new Token().generate()
1166
+ return response.send(token)
1167
+ ```
1168
+
1169
+ At the same time, you want to drop a log statement inside your application that you can later use to debug the flow of the application, and this is how you log the token.
1170
+
1171
+ ```ts
1172
+ const token = new Token().generate()
1173
+
1174
+ logger.log('token generated %O', token)
1175
+ // token generated {"value":"opaque_raw_token","hash":"hash_of_raw_token_inside_db"}
1176
+
1177
+ return response.send(token)
1178
+ ```
1179
+
1180
+ BOOM! You have weakened the security of your app. Now, anyone monitoring the logs can grab raw token values from the log and use them to perform the actions on behalf of the user.
1181
+
1182
+ Now, to prevent this from happening, you **should work with a branded data type**. Our [old friend PHP has it](https://www.php.net/manual/en/class.sensitiveparametervalue.php), so we need it as well.
1183
+
1184
+ This is what exactly the `Secret` utility class does for you. Create values that prevent themselves from leaking inside logs or during JSON serialization.
1185
+
1186
+ ```ts
1187
+ import { Secret } from '@poppinss/utils'
1188
+
1189
+ class Token {
1190
+ generate() {
1191
+ return {
1192
+ // THIS LINE 👇
1193
+ value: new Secret('opaque_raw_token'),
1194
+ hash: 'hash_of_raw_token_inside_db',
1195
+ }
1196
+ }
1197
+ }
1198
+
1199
+ const token = new Token().generate()
1200
+
1201
+ logger.log('token generated %O', token)
1202
+ // AND THIS LOG 👇
1203
+ // token generated {"value":"[redacted]","hash":"hash_of_raw_token_inside_db"}
1204
+
1205
+ return response.send(token)
1206
+ ```
1207
+
1208
+ **Need the original value back?**
1209
+ You can call the `release` method to get the secret value back. Again, the idea is not to prevent your code from accessing the raw value. It's to stop the logging and serialization layer from reading it.
1210
+
1211
+ ```ts
1212
+ const secret = new Secret('opaque_raw_token')
1213
+ const rawValue = secret.release()
1214
+
1215
+ rawValue === opaque_raw_token // true
1216
+ ```
1217
+
1218
+ > Shoutout to [https://transcend.io/blog/keep-sensitive-values-out-of-your-logs-with-types](transcend.io's article) to helping me design the API. In fact, I have ripped their implementation for my personal use.
1219
+
1100
1220
  #### dirname/filename
1101
1221
 
1102
1222
  ES modules does not have magic variables `__filename` and `__dirname`. You can use these helpers to get the current directory and filenames as follows.
@@ -1108,6 +1228,21 @@ const dirname = getDirname(import.meta.url)
1108
1228
  const filename = getFilename(import.meta.url)
1109
1229
  ```
1110
1230
 
1231
+ #### joinToURL
1232
+ Similar to the Node.js `path.join`, but instead expects the first parameter to be a URL instance or a string with the `file:///` protocol.
1233
+
1234
+ The return value is an absolute file system path without the `file:///` protocol.
1235
+
1236
+ ```ts
1237
+ import { joinToURL } from '@poppinss/utils'
1238
+
1239
+ // With URL as a string
1240
+ const APP_PATH = joinToURL(import.meta.url, 'app')
1241
+
1242
+ // With URL instance
1243
+ const APP_PATH = joinToURL(new URL('./', import.meta.url), 'app')
1244
+ ```
1245
+
1111
1246
  [gh-workflow-image]: https://img.shields.io/github/actions/workflow/status/poppinss/utils/checks.yml?style=for-the-badge
1112
1247
  [gh-workflow-url]: https://github.com/poppinss/utils/actions/workflows/checks.yml 'Github action'
1113
1248
  [typescript-image]: https://img.shields.io/badge/Typescript-294E80.svg?style=for-the-badge&logo=typescript
package/build/index.d.ts CHANGED
@@ -1,4 +1,5 @@
1
1
  /// <reference types="node" resolution-mode="require"/>
2
+ export { Secret } from './src/secret.js';
2
3
  export { base64 } from './src/base64.js';
3
4
  export { compose } from './src/compose.js';
4
5
  export { importDefault } from './src/import_default.js';
@@ -23,3 +24,8 @@ export declare function getDirname(url: string | URL): string;
23
24
  * Get filename for a given file path URL
24
25
  */
25
26
  export declare function getFilename(url: string | URL): string;
27
+ /**
28
+ * Join paths to a URL instance or a URL string. The return
29
+ * value will be a file path without the `file:///` protocol.
30
+ */
31
+ export declare function joinToURL(url: string | URL, ...str: string[]): string;
package/build/index.js CHANGED
@@ -8,7 +8,47 @@ import {
8
8
 
9
9
  // index.ts
10
10
  import { fileURLToPath as fileURLToPath3 } from "node:url";
11
- import { dirname as pathDirname } from "node:path";
11
+ import { join as pathJoin, dirname as pathDirname } from "node:path";
12
+
13
+ // src/secret.ts
14
+ var REDACTED = "[redacted]";
15
+ var Secret = class _Secret {
16
+ /** The secret value */
17
+ #value;
18
+ #keyword;
19
+ constructor(value, redactedKeyword) {
20
+ this.#value = value;
21
+ this.#keyword = redactedKeyword || REDACTED;
22
+ }
23
+ toJSON() {
24
+ return this.#keyword;
25
+ }
26
+ valueOf() {
27
+ return this.#keyword;
28
+ }
29
+ [Symbol.for("nodejs.util.inspect.custom")]() {
30
+ return this.#keyword;
31
+ }
32
+ toLocaleString() {
33
+ return this.#keyword;
34
+ }
35
+ toString() {
36
+ return this.#keyword;
37
+ }
38
+ /**
39
+ * Returns the original value
40
+ */
41
+ release() {
42
+ return this.#value;
43
+ }
44
+ /**
45
+ * Transform the original value and create a new
46
+ * secret from it.
47
+ */
48
+ map(transformFunc) {
49
+ return new _Secret(transformFunc(this.#value));
50
+ }
51
+ };
12
52
 
13
53
  // src/compose.ts
14
54
  function compose(superclass, ...mixins) {
@@ -350,12 +390,16 @@ function getDirname(url) {
350
390
  function getFilename(url) {
351
391
  return fileURLToPath3(url);
352
392
  }
393
+ function joinToURL(url, ...str) {
394
+ return pathJoin(getDirname(url), ...str);
395
+ }
353
396
  export {
354
397
  Exception,
355
398
  InvalidArgumentsException,
356
399
  MessageBuilder,
357
400
  ObjectBuilder,
358
401
  RuntimeException,
402
+ Secret,
359
403
  base64,
360
404
  compose,
361
405
  createError,
@@ -367,6 +411,7 @@ export {
367
411
  getFilename,
368
412
  importDefault,
369
413
  isScriptFile,
414
+ joinToURL,
370
415
  naturalSort,
371
416
  safeEqual,
372
417
  default2 as slash
@@ -1 +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 {\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URLToPath","fileURLToPath","lodash","extname","default","default","fileURLToPath","extname","lodash","fileURLToPath"]}
1
+ {"version":3,"sources":["../index.ts","../src/secret.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 { join as pathJoin, dirname as pathDirname } from 'node:path'\n\nexport { Secret } from './src/secret.js'\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/**\n * Join paths to a URL instance or a URL string. The return\n * value will be a file path without the `file:///` protocol.\n */\nexport function joinToURL(url: string | URL, ...str: string[]) {\n return pathJoin(getDirname(url), ...str)\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\nconst REDACTED = '[redacted]'\n\n/**\n * Define a Secret value that hides itself from the logs or the console\n * statements.\n *\n * The idea is to prevent accedential leaking of sensitive information.\n * Idea borrowed from.\n * https://transcend.io/blog/keep-sensitive-values-out-of-your-logs-with-types\n */\nexport class Secret<T> {\n /** The secret value */\n #value: T\n #keyword: string\n\n constructor(value: T, redactedKeyword?: string) {\n this.#value = value\n this.#keyword = redactedKeyword || REDACTED\n }\n\n toJSON(): string {\n return this.#keyword\n }\n valueOf(): string {\n return this.#keyword\n }\n [Symbol.for('nodejs.util.inspect.custom')](): string {\n return this.#keyword\n }\n toLocaleString(): string {\n return this.#keyword\n }\n toString(): string {\n return this.#keyword\n }\n\n /**\n * Returns the original value\n */\n release(): T {\n return this.#value\n }\n\n /**\n * Transform the original value and create a new\n * secret from it.\n */\n map<R>(transformFunc: (value: T) => R): Secret<R> {\n return new Secret(transformFunc(this.#value))\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 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,QAAQ,UAAU,WAAW,mBAAmB;;;ACDzD,IAAM,WAAW;AAUV,IAAM,SAAN,MAAM,QAAU;AAAA;AAAA,EAErB;AAAA,EACA;AAAA,EAEA,YAAY,OAAU,iBAA0B;AAC9C,SAAK,SAAS;AACd,SAAK,WAAW,mBAAmB;AAAA,EACrC;AAAA,EAEA,SAAiB;AACf,WAAO,KAAK;AAAA,EACd;AAAA,EACA,UAAkB;AAChB,WAAO,KAAK;AAAA,EACd;AAAA,EACA,CAAC,OAAO,IAAI,4BAA4B,CAAC,IAAY;AACnD,WAAO,KAAK;AAAA,EACd;AAAA,EACA,iBAAyB;AACvB,WAAO,KAAK;AAAA,EACd;AAAA,EACA,WAAmB;AACjB,WAAO,KAAK;AAAA,EACd;AAAA;AAAA;AAAA;AAAA,EAKA,UAAa;AACX,WAA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B;AAMO,SAAS,UAAU,QAAsB,KAAe;AAC7D,SAAO,SAAS,WAAW,GAAG,GAAG,GAAG,GAAG;AACzC;","names":["fileURLToPath","fileURLToPath","lodash","extname","default","default","fileURLToPath","extname","lodash","fileURLToPath"]}
@@ -1,3 +1,22 @@
1
+ /**
2
+ * @alias "assertExists"
3
+ */
1
4
  export declare function assert(value: unknown, message?: string): asserts value;
5
+ /**
6
+ * Assert the value is turthy or raise an exception.
7
+ *
8
+ * Truthy value excludes, undefined, null, and false values.
9
+ */
10
+ export declare function assertExists(value: unknown, message?: string): asserts value;
11
+ /**
12
+ * Throws error when method is called
13
+ */
2
14
  export declare function assertUnreachable(x?: never): never;
3
- export declare function assertNotNull<T>(value: T | null): asserts value is Exclude<T, null>;
15
+ /**
16
+ * Assert the value is not null.
17
+ */
18
+ export declare function assertNotNull<T>(value: T | null, message?: string): asserts value is Exclude<T, null>;
19
+ /**
20
+ * Assert the value is not undefined.
21
+ */
22
+ export declare function assertIsDefined<T>(value: T | undefined, message?: string): asserts value is Exclude<T, undefined>;
@@ -1,19 +1,31 @@
1
1
  // src/assert.ts
2
+ import { inspect } from "node:util";
3
+ import { AssertionError } from "node:assert";
2
4
  function assert(value, message) {
5
+ return assertExists(value, message);
6
+ }
7
+ function assertExists(value, message) {
3
8
  if (!value) {
4
- throw new Error(message ?? "value is falsy");
9
+ throw new AssertionError({ message: message ?? "value is falsy" });
5
10
  }
6
11
  }
7
12
  function assertUnreachable(x) {
8
- throw new Error(`unreachable code executed: ${String(x)}`);
13
+ throw new AssertionError({ message: `unreachable code executed: ${inspect(x)}` });
9
14
  }
10
- function assertNotNull(value) {
15
+ function assertNotNull(value, message) {
11
16
  if (value === null) {
12
- throw new Error("unexpected null value");
17
+ throw new AssertionError({ message: message ?? "unexpected null value" });
18
+ }
19
+ }
20
+ function assertIsDefined(value, message) {
21
+ if (value === void 0) {
22
+ throw new AssertionError({ message: message ?? "unexpected undefined value" });
13
23
  }
14
24
  }
15
25
  export {
16
26
  assert,
27
+ assertExists,
28
+ assertIsDefined,
17
29
  assertNotNull,
18
30
  assertUnreachable
19
31
  };
@@ -1 +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":[]}
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\nimport { inspect } from 'node:util'\nimport { AssertionError } from 'node:assert'\n\n/**\n * @alias \"assertExists\"\n */\nexport function assert(value: unknown, message?: string): asserts value {\n return assertExists(value, message)\n}\n\n/**\n * Assert the value is turthy or raise an exception.\n *\n * Truthy value excludes, undefined, null, and false values.\n */\nexport function assertExists(value: unknown, message?: string): asserts value {\n if (!value) {\n throw new AssertionError({ message: message ?? 'value is falsy' })\n }\n}\n\n/**\n * Throws error when method is called\n */\nexport function assertUnreachable(x?: never): never {\n throw new AssertionError({ message: `unreachable code executed: ${inspect(x)}` })\n}\n\n/**\n * Assert the value is not null.\n */\nexport function assertNotNull<T>(\n value: T | null,\n message?: string\n): asserts value is Exclude<T, null> {\n if (value === null) {\n throw new AssertionError({ message: message ?? 'unexpected null value' })\n }\n}\n\n/**\n * Assert the value is not undefined.\n */\nexport function assertIsDefined<T>(\n value: T | undefined,\n message?: string\n): asserts value is Exclude<T, undefined> {\n if (value === undefined) {\n throw new AssertionError({ message: message ?? 'unexpected undefined value' })\n }\n}\n"],"mappings":";AASA,SAAS,eAAe;AACxB,SAAS,sBAAsB;AAKxB,SAAS,OAAO,OAAgB,SAAiC;AACtE,SAAO,aAAa,OAAO,OAAO;AACpC;AAOO,SAAS,aAAa,OAAgB,SAAiC;AAC5E,MAAI,CAAC,OAAO;AACV,UAAM,IAAI,eAAe,EAAE,SAAS,WAAW,iBAAiB,CAAC;AAAA,EACnE;AACF;AAKO,SAAS,kBAAkB,GAAkB;AAClD,QAAM,IAAI,eAAe,EAAE,SAAS,8BAA8B,QAAQ,CAAC,CAAC,GAAG,CAAC;AAClF;AAKO,SAAS,cACd,OACA,SACmC;AACnC,MAAI,UAAU,MAAM;AAClB,UAAM,IAAI,eAAe,EAAE,SAAS,WAAW,wBAAwB,CAAC;AAAA,EAC1E;AACF;AAKO,SAAS,gBACd,OACA,SACwC;AACxC,MAAI,UAAU,QAAW;AACvB,UAAM,IAAI,eAAe,EAAE,SAAS,WAAW,6BAA6B,CAAC;AAAA,EAC/E;AACF;","names":[]}
@@ -0,0 +1,25 @@
1
+ /**
2
+ * Define a Secret value that hides itself from the logs or the console
3
+ * statements.
4
+ *
5
+ * The idea is to prevent accedential leaking of sensitive information.
6
+ * Idea borrowed from.
7
+ * https://transcend.io/blog/keep-sensitive-values-out-of-your-logs-with-types
8
+ */
9
+ export declare class Secret<T> {
10
+ #private;
11
+ constructor(value: T, redactedKeyword?: string);
12
+ toJSON(): string;
13
+ valueOf(): string;
14
+ toLocaleString(): string;
15
+ toString(): string;
16
+ /**
17
+ * Returns the original value
18
+ */
19
+ release(): T;
20
+ /**
21
+ * Transform the original value and create a new
22
+ * secret from it.
23
+ */
24
+ map<R>(transformFunc: (value: T) => R): Secret<R>;
25
+ }
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@poppinss/utils",
3
- "version": "6.5.1",
3
+ "version": "6.7.0",
4
4
  "description": "Handy utilities for repetitive work",
5
5
  "main": "build/index.js",
6
6
  "type": "module",
@@ -50,36 +50,37 @@
50
50
  "author": "virk,poppinss",
51
51
  "license": "MIT",
52
52
  "devDependencies": {
53
- "@adonisjs/eslint-config": "^1.1.6",
54
- "@adonisjs/prettier-config": "^1.1.6",
55
- "@adonisjs/tsconfig": "^1.1.6",
56
- "@commitlint/cli": "^18.2.0",
57
- "@commitlint/config-conventional": "^18.1.0",
58
- "@japa/assert": "^2.0.0",
53
+ "@adonisjs/eslint-config": "^1.2.0",
54
+ "@adonisjs/logger": "^5.4.2-7",
55
+ "@adonisjs/prettier-config": "^1.2.0",
56
+ "@adonisjs/tsconfig": "^1.2.0",
57
+ "@commitlint/cli": "^18.4.3",
58
+ "@commitlint/config-conventional": "^18.4.3",
59
+ "@japa/assert": "^2.0.1",
59
60
  "@japa/expect-type": "^2.0.0",
60
- "@japa/runner": "^3.0.4",
61
- "@swc/core": "^1.3.96",
62
- "@types/fs-extra": "^11.0.3",
63
- "@types/node": "^20.8.10",
64
- "c8": "^8.0.0",
61
+ "@japa/runner": "^3.1.0",
62
+ "@swc/core": "^1.3.100",
63
+ "@types/fs-extra": "^11.0.4",
64
+ "@types/node": "^20.10.4",
65
+ "c8": "^8.0.1",
65
66
  "del-cli": "^5.1.0",
66
- "eslint": "^8.53.0",
67
- "fs-extra": "^11.1.1",
67
+ "eslint": "^8.55.0",
68
+ "fs-extra": "^11.2.0",
68
69
  "github-label-sync": "^2.3.1",
69
70
  "husky": "^8.0.3",
70
71
  "lodash": "^4.17.21",
71
72
  "lodash-cli": "^4.17.5",
72
73
  "move-file-cli": "^3.0.0",
73
- "np": "^8.0.4",
74
- "prettier": "^3.0.3",
75
- "ts-node": "^10.9.1",
76
- "tsup": "^7.1.0",
77
- "typescript": "^5.2.2"
74
+ "np": "^9.2.0",
75
+ "prettier": "^3.1.1",
76
+ "ts-node": "^10.9.2",
77
+ "tsup": "^8.0.1",
78
+ "typescript": "^5.3.3"
78
79
  },
79
80
  "dependencies": {
80
- "@lukeed/ms": "^2.0.1",
81
- "@types/bytes": "^3.1.3",
82
- "@types/pluralize": "^0.0.32",
81
+ "@lukeed/ms": "^2.0.2",
82
+ "@types/bytes": "^3.1.4",
83
+ "@types/pluralize": "^0.0.33",
83
84
  "bytes": "^3.1.2",
84
85
  "case-anything": "^2.1.13",
85
86
  "flattie": "^1.1.0",