@aws-amplify/ui-react-storage 0.0.0-storage-browser-alpha-0a15ea5-20241102003708 → 0.0.0-storage-browser-alpha-48c4ba4-20241104223722

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/dist/browser.js CHANGED
@@ -2,7 +2,7 @@
2
2
 
3
3
  Object.defineProperty(exports, '__esModule', { value: true });
4
4
 
5
- var createStorageBrowser = require('./createStorageBrowser-BhuwN2iU.js');
5
+ var createStorageBrowser = require('./createStorageBrowser-wUnhh_C_.js');
6
6
  var internals = require('@aws-amplify/storage/internals');
7
7
  require('aws-amplify');
8
8
  require('aws-amplify/utils');
@@ -624,7 +624,7 @@ const createFolderAction = async (_, input) => {
624
624
  return { result };
625
625
  };
626
626
 
627
- const parseItems = (items, excludedPath) => items
627
+ const parseItems$1 = (items, excludedPath) => items
628
628
  .filter(({ path }) => path !== excludedPath)
629
629
  .map(({ path: key, lastModified, size }) => {
630
630
  const id = crypto.randomUUID();
@@ -640,10 +640,10 @@ const parseItems = (items, excludedPath) => items
640
640
  type: 'FILE',
641
641
  };
642
642
  });
643
- const parseExcludedPaths = (paths) => paths?.map((key) => ({ key, id: crypto.randomUUID(), type: 'FOLDER' })) ?? [];
644
- const parseResult = (output, path) => [
645
- ...parseExcludedPaths(output.excludedSubpaths),
646
- ...parseItems(output.items, path),
643
+ const parseExcludedPaths$1 = (paths) => paths?.map((key) => ({ key, id: crypto.randomUUID(), type: 'FOLDER' })) ?? [];
644
+ const parseResult$1 = (output, path) => [
645
+ ...parseExcludedPaths$1(output.excludedSubpaths),
646
+ ...parseItems$1(output.items, path),
647
647
  ];
648
648
  async function listLocationItemsAction(prevState, input) {
649
649
  const { config, options, prefix: path } = input ?? {};
@@ -679,7 +679,7 @@ async function listLocationItemsAction(prevState, input) {
679
679
  const output = await internals.list(listInput);
680
680
  const result = [
681
681
  ...(refresh ? [] : prevState.result),
682
- ...parseResult(output, path),
682
+ ...parseResult$1(output, path),
683
683
  ];
684
684
  return { result, nextToken: output.nextToken };
685
685
  }
@@ -1218,7 +1218,68 @@ const deleteHandler = ({ config, key, options, }) => {
1218
1218
  };
1219
1219
  };
1220
1220
 
1221
- const listLocationItemsHandler = null;
1221
+ const DEFAULT_PAGE_SIZE$2 = 1000;
1222
+ const parseItems = (items, excludedPath) => items
1223
+ // remove root `key` from results
1224
+ .filter(({ path }) => path !== excludedPath)
1225
+ .map(({ path: key, lastModified, size }) => {
1226
+ const id = crypto.randomUUID();
1227
+ // Mark zero byte files as Folders
1228
+ if (size === 0 && key.endsWith('/')) {
1229
+ return { key, id, type: 'FOLDER' };
1230
+ }
1231
+ return {
1232
+ key,
1233
+ id,
1234
+ lastModified: lastModified,
1235
+ size: size,
1236
+ type: 'FILE',
1237
+ };
1238
+ });
1239
+ const parseExcludedPaths = (paths) => paths?.map((key) => ({ key, id: crypto.randomUUID(), type: 'FOLDER' })) ?? [];
1240
+ const parseResult = ({ excludedSubpaths, items }, prefix) => [
1241
+ ...parseExcludedPaths(excludedSubpaths),
1242
+ ...parseItems(items, prefix),
1243
+ ];
1244
+ const listLocationItemsHandler = async (input) => {
1245
+ const { config, prefix, options } = input;
1246
+ const { bucket: _bucket, credentials, region } = config;
1247
+ const { delimiter, nextToken, pageSize: _pageSize = DEFAULT_PAGE_SIZE$2, ..._options } = options ?? {};
1248
+ const excludedType = 'FILE';
1249
+ const bucket = { bucketName: _bucket, region };
1250
+ const subpathStrategy = {
1251
+ delimiter,
1252
+ strategy: delimiter ? 'exclude' : 'include',
1253
+ };
1254
+ // `ListObjectsV2` returns the root `key` on initial request, which is from
1255
+ // filtered from `results` by `parseResult`, creatimg a scenario where the
1256
+ // return count of `results` to be one item less than provided the `pageSize`.
1257
+ // To mitigate, if a `pageSize` is provided and there are no previous `results`
1258
+ // or `refresh` is `true` increment the provided `pageSize` by `1`
1259
+ const hasOffset = !nextToken;
1260
+ const pageSize = hasOffset ? _pageSize + 1 : _pageSize;
1261
+ const result = [];
1262
+ let nextNextToken = nextToken;
1263
+ do {
1264
+ const listInput = {
1265
+ path: prefix,
1266
+ options: {
1267
+ nextToken: nextNextToken,
1268
+ ..._options,
1269
+ bucket,
1270
+ locationCredentialsProvider: credentials,
1271
+ pageSize,
1272
+ subpathStrategy,
1273
+ },
1274
+ };
1275
+ const output = await internals.list(listInput);
1276
+ nextNextToken = output.nextToken;
1277
+ const items = parseResult(output, prefix);
1278
+ result.push(...(items.filter((item) => item.type !== excludedType)
1279
+ ));
1280
+ } while (nextNextToken && result.length < pageSize);
1281
+ return { items: result, nextToken: nextNextToken };
1282
+ };
1222
1283
 
1223
1284
  const listLocationsHandler = null;
1224
1285
 
@@ -1,3 +1,66 @@
1
- const listLocationItemsHandler = null;
1
+ import { list } from '@aws-amplify/storage/internals';
2
2
 
3
- export { listLocationItemsHandler };
3
+ const DEFAULT_PAGE_SIZE = 1000;
4
+ const parseItems = (items, excludedPath) => items
5
+ // remove root `key` from results
6
+ .filter(({ path }) => path !== excludedPath)
7
+ .map(({ path: key, lastModified, size }) => {
8
+ const id = crypto.randomUUID();
9
+ // Mark zero byte files as Folders
10
+ if (size === 0 && key.endsWith('/')) {
11
+ return { key, id, type: 'FOLDER' };
12
+ }
13
+ return {
14
+ key,
15
+ id,
16
+ lastModified: lastModified,
17
+ size: size,
18
+ type: 'FILE',
19
+ };
20
+ });
21
+ const parseExcludedPaths = (paths) => paths?.map((key) => ({ key, id: crypto.randomUUID(), type: 'FOLDER' })) ?? [];
22
+ const parseResult = ({ excludedSubpaths, items }, prefix) => [
23
+ ...parseExcludedPaths(excludedSubpaths),
24
+ ...parseItems(items, prefix),
25
+ ];
26
+ const listLocationItemsHandler = async (input) => {
27
+ const { config, prefix, options } = input;
28
+ const { bucket: _bucket, credentials, region } = config;
29
+ const { delimiter, nextToken, pageSize: _pageSize = DEFAULT_PAGE_SIZE, ..._options } = options ?? {};
30
+ const excludedType = 'FILE';
31
+ const bucket = { bucketName: _bucket, region };
32
+ const subpathStrategy = {
33
+ delimiter,
34
+ strategy: delimiter ? 'exclude' : 'include',
35
+ };
36
+ // `ListObjectsV2` returns the root `key` on initial request, which is from
37
+ // filtered from `results` by `parseResult`, creatimg a scenario where the
38
+ // return count of `results` to be one item less than provided the `pageSize`.
39
+ // To mitigate, if a `pageSize` is provided and there are no previous `results`
40
+ // or `refresh` is `true` increment the provided `pageSize` by `1`
41
+ const hasOffset = !nextToken;
42
+ const pageSize = hasOffset ? _pageSize + 1 : _pageSize;
43
+ const result = [];
44
+ let nextNextToken = nextToken;
45
+ do {
46
+ const listInput = {
47
+ path: prefix,
48
+ options: {
49
+ nextToken: nextNextToken,
50
+ ..._options,
51
+ bucket,
52
+ locationCredentialsProvider: credentials,
53
+ pageSize,
54
+ subpathStrategy,
55
+ },
56
+ };
57
+ const output = await list(listInput);
58
+ nextNextToken = output.nextToken;
59
+ const items = parseResult(output, prefix);
60
+ result.push(...(items.filter((item) => item.type !== excludedType)
61
+ ));
62
+ } while (nextNextToken && result.length < pageSize);
63
+ return { items: result, nextToken: nextNextToken };
64
+ };
65
+
66
+ export { listLocationItemsHandler, parseResult };
package/dist/index.js CHANGED
@@ -9,7 +9,7 @@ var uiReactCore = require('@aws-amplify/ui-react-core');
9
9
  var auth = require('aws-amplify/auth');
10
10
  var storage = require('aws-amplify/storage');
11
11
  var internal = require('@aws-amplify/ui-react/internal');
12
- var createStorageBrowser = require('./createStorageBrowser-BhuwN2iU.js');
12
+ var createStorageBrowser = require('./createStorageBrowser-wUnhh_C_.js');
13
13
  require('aws-amplify');
14
14
  require('aws-amplify/utils');
15
15
  require('@aws-amplify/ui-react-core/elements');
@@ -1,3 +1,4 @@
1
+ import { ListOutput } from '../../storage-internal';
1
2
  import { ListHandler, ListHandlerInput, ListHandlerOptions, ListHandlerOutput } from '../types';
2
3
  export interface FolderData {
3
4
  key: string;
@@ -23,4 +24,5 @@ export interface ListLocationItemsHandlerOutput extends ListHandlerOutput<Locati
23
24
  }
24
25
  export interface ListLocationItemsHandler extends ListHandler<ListLocationItemsHandlerInput, ListLocationItemsHandlerOutput> {
25
26
  }
27
+ export declare const parseResult: ({ excludedSubpaths, items }: ListOutput, prefix: string) => LocationItemData[];
26
28
  export declare const listLocationItemsHandler: ListLocationItemsHandler;
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@aws-amplify/ui-react-storage",
3
- "version": "0.0.0-storage-browser-alpha-0a15ea5-20241102003708",
3
+ "version": "0.0.0-storage-browser-alpha-48c4ba4-20241104223722",
4
4
  "main": "dist/index.js",
5
5
  "module": "dist/esm/index.mjs",
6
6
  "exports": {
@@ -47,9 +47,9 @@
47
47
  "typecheck": "tsc --noEmit"
48
48
  },
49
49
  "dependencies": {
50
- "@aws-amplify/ui": "0.0.0-storage-browser-alpha-0a15ea5-20241102003708",
51
- "@aws-amplify/ui-react": "0.0.0-storage-browser-alpha-0a15ea5-20241102003708",
52
- "@aws-amplify/ui-react-core": "0.0.0-storage-browser-alpha-0a15ea5-20241102003708",
50
+ "@aws-amplify/ui": "0.0.0-storage-browser-alpha-48c4ba4-20241104223722",
51
+ "@aws-amplify/ui-react": "0.0.0-storage-browser-alpha-48c4ba4-20241104223722",
52
+ "@aws-amplify/ui-react-core": "0.0.0-storage-browser-alpha-48c4ba4-20241104223722",
53
53
  "lodash": "4.17.21",
54
54
  "tslib": "^2.5.2"
55
55
  },
@@ -71,7 +71,7 @@
71
71
  "name": "createStorageBrowser",
72
72
  "path": "dist/esm/browser.mjs",
73
73
  "import": "{ createStorageBrowser }",
74
- "limit": "18.03 kB",
74
+ "limit": "18.30 kB",
75
75
  "ignore": [
76
76
  "@aws-amplify/storage"
77
77
  ]