diff --git a/README.md b/README.md index 321321d..980e501 100644 --- a/README.md +++ b/README.md @@ -70,7 +70,10 @@ npm install @adobe/aio-lib-files */ // list all files - await files.list('/') // ['mydir/myfile.txt', 'public/index.html'] + await files.list('mydir/') // with a trailing slash lists a directory, recursively. Returns [] if no files are recursively stored under mydir/. + await files.list('myfile') // without a trailing slash list returns [fileProps] or [] if it doesn't exist. + + await files.list('/') /* list = [ { name: 'mydir/myfile.txt', creationTime: 2020-12-09T19:49:57.000Z, diff --git a/doc/api.md b/doc/api.md index ab0a65e..389752e 100644 --- a/doc/api.md +++ b/doc/api.md @@ -75,16 +75,23 @@ Cloud Files Abstraction ### *files.list([filePath]) ⇒ Promise.<Array.<RemoteFileProperties>>* -Lists files in a remote folder. If called on a file returns the file info if the file exists. -If the file or folder does not exist returns an empty array. +Lists files. Depending on the input the behavior is different: +- If a path has a trailing '/' it is considered as a directory and + list returns files recursively contained below that path. If the + directory is empty, an empty array is returned. +- If a path has no trailing '/' it will ALWAYS be considered a file and we + will return the file (and its properties) in an array. If that file + doesn't exist we return an empty array EVEN if listing a directory with the + same name would return some files (directories are subpaths, not entities per se). **Kind**: instance method of [Files](#Files) -**Returns**: Promise.<Array.<RemoteFileProperties>> - resolves to array of [RemoteFileProperties](#RemoteFileProperties) +**Returns**: Promise.<Array.<RemoteFileProperties>> - resolves to array of +[RemoteFileProperties](#RemoteFileProperties) **Access**: public | Param | Type | Description | | --- | --- | --- | -| [filePath] | [RemotePathString](#RemotePathString) | [RemotePathString](#RemotePathString) if not specified list all files | +| [filePath] | [RemotePathString](#RemotePathString) | [RemotePathString](#RemotePathString) Use a trailing '/' otherwise this is considered as a file. If not specified list all files. | diff --git a/lib/Files.js b/lib/Files.js index ee136c0..15ce677 100644 --- a/lib/Files.js +++ b/lib/Files.js @@ -405,12 +405,20 @@ class Files { /* **************************** PUBLIC API METHODS ***************************** */ /** * - * Lists files in a remote folder. If called on a file returns the file info if the file exists. - * If the file or folder does not exist returns an empty array. - * - * @param {RemotePathString} [filePath] {@link RemotePathString} if not - * specified list all files - * @returns {Promise>} resolves to array of {@link RemoteFileProperties} + * Lists files. Depending on the input the behavior is different: + * - If a path has a trailing '/' it is considered as a directory and + * list returns files recursively contained below that path. If the + * directory is empty, an empty array is returned. + * - If a path has no trailing '/' it will ALWAYS be considered a file and we + * will return the file (and its properties) in an array. If that file + * doesn't exist we return an empty array EVEN if listing a directory with the + * same name would return some files (directories are subpaths, not entities per se). + * + * @param {RemotePathString} [filePath] {@link RemotePathString} Use a + * trailing '/' otherwise this is considered as a file. If not specified + * list all files. + * @returns {Promise>} resolves to array of + * {@link RemoteFileProperties} * @memberof Files * @public */ diff --git a/package.json b/package.json index e0988e7..b427f2e 100644 --- a/package.json +++ b/package.json @@ -1,6 +1,6 @@ { "name": "@adobe/aio-lib-files", - "version": "4.1.1", + "version": "4.1.2", "description": "An abstraction on top of blob cloud storage exposing a file like API", "main": "lib/init.js", "directories": { diff --git a/types.d.ts b/types.d.ts index ced4be7..2822c9a 100644 --- a/types.d.ts +++ b/types.d.ts @@ -124,11 +124,19 @@ export class Files { */ protected _statusFromProviderError(e: Error): number; /** - * Lists files in a remote folder. If called on a file returns the file info if the file exists. - * If the file or folder does not exist returns an empty array. - * @param [filePath] - {@link RemotePathString} if not - * specified list all files - * @returns resolves to array of {@link RemoteFileProperties} + * Lists files. Depending on the input the behavior is different: + * - If a path has a trailing '/' it is considered as a directory and + * list returns files recursively contained below that path. If the + * directory is empty, an empty array is returned. + * - If a path has no trailing '/' it will ALWAYS be considered a file and we + * will return the file (and its properties) in an array. If that file + * doesn't exist we return an empty array EVEN if listing a directory with the + * same name would return some files (directories are subpaths, not entities per se). + * @param [filePath] - {@link RemotePathString} Use a + * trailing '/' otherwise this is considered as a file. If not specified + * list all files. + * @returns resolves to array of + * {@link RemoteFileProperties} */ public list(filePath?: RemotePathString): Promise; /** @@ -248,9 +256,7 @@ export class Files { localDest?: boolean; noOverwrite?: boolean; progressCallback?: (...params: any[]) => any; - }): Promise<{ - [key: string]: string; - }>; + }): Promise<{ key: string; }>; /** * Generate pre-sign URLs for a private file * @param filePath - {@link RemotePathString}