fsd-oss 0.13.2 → 0.14.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/lib/index.js CHANGED
@@ -117,7 +117,7 @@ class OSSAdapter {
117
117
  try {
118
118
  position = await this.size(path);
119
119
  }
120
- catch (e) { }
120
+ catch (_e) { }
121
121
  await this._oss.append(p, data, { position });
122
122
  }
123
123
  async createReadStream(path, options) {
@@ -143,7 +143,7 @@ class OSSAdapter {
143
143
  }
144
144
  async createWriteStream(path, options) {
145
145
  debug('createWriteStream %s', path);
146
- if (options === null || options === void 0 ? void 0 : options.start)
146
+ if (options?.start)
147
147
  throw new Error('fsd-oss read stream does not support start options');
148
148
  const { root } = this._options;
149
149
  let p = slash(Path.join(root, path)).substring(1);
@@ -152,7 +152,6 @@ class OSSAdapter {
152
152
  return stream;
153
153
  }
154
154
  async unlink(path) {
155
- var _a;
156
155
  debug('unlink %s', path);
157
156
  const { root } = this._options;
158
157
  let p = slash(Path.join(root, path)).substring(1);
@@ -165,7 +164,7 @@ class OSSAdapter {
165
164
  maxKeys: 1000
166
165
  });
167
166
  continuationToken = list.NextContinuationToken;
168
- if ((_a = list.Contents) === null || _a === void 0 ? void 0 : _a.length) {
167
+ if (list.Contents?.length) {
169
168
  let objects = list.Contents.map((o) => o.Key);
170
169
  await this._oss.deleteMulti(objects, {
171
170
  quiet: true
@@ -204,8 +203,10 @@ class OSSAdapter {
204
203
  }
205
204
  const { root } = this._options;
206
205
  let p = slash(Path.join(root, path)).substring(1);
207
- let results = [];
206
+ let results = Object.create(null);
208
207
  let continuationToken = '';
208
+ let hasContents = false;
209
+ let hasCommonPrefixes = false;
209
210
  do {
210
211
  let list = await this._oss.list({
211
212
  prefix: p,
@@ -216,6 +217,7 @@ class OSSAdapter {
216
217
  debug('list: %O', list);
217
218
  continuationToken = list.NextContinuationToken;
218
219
  if (list.Contents) {
220
+ hasContents = true;
219
221
  list.Contents.forEach((object) => {
220
222
  let relative = slash(Path.relative(p, object.Key));
221
223
  if (!relative)
@@ -224,17 +226,34 @@ class OSSAdapter {
224
226
  relative += '/';
225
227
  if (pattern && pattern !== '**/*' && !minimatch(relative, pattern))
226
228
  return;
227
- results.push({
229
+ results[relative] = {
228
230
  name: relative,
229
231
  metadata: {
230
232
  size: object.Size,
231
233
  lastModified: new Date(object.LastModified)
232
234
  }
233
- });
235
+ };
236
+ });
237
+ }
238
+ if (list.CommonPrefixes) {
239
+ hasCommonPrefixes = true;
240
+ list.CommonPrefixes.forEach((prefix) => {
241
+ let relative = slash(Path.relative(p, prefix.Prefix));
242
+ if (!relative)
243
+ return;
244
+ relative += '/';
245
+ results[relative] = {
246
+ name: relative
247
+ };
234
248
  });
235
249
  }
236
250
  } while (continuationToken);
237
- return results;
251
+ if (hasContents && hasCommonPrefixes) {
252
+ return Object.keys(results)
253
+ .sort()
254
+ .map((key) => results[key]);
255
+ }
256
+ return Object.values(results);
238
257
  }
239
258
  async createUrl(path, options) {
240
259
  debug('createUrl %s', path);
@@ -265,7 +284,6 @@ class OSSAdapter {
265
284
  return url;
266
285
  }
267
286
  async copy(path, dest) {
268
- var _a;
269
287
  debug('copy %s to %s', path, dest);
270
288
  if (!(await this.exists(path)))
271
289
  throw new Error('The source path is not exists!');
@@ -283,7 +301,7 @@ class OSSAdapter {
283
301
  });
284
302
  debug('list result: %O', list);
285
303
  continuationToken = list.NextContinuationToken;
286
- if ((_a = list.Contents) === null || _a === void 0 ? void 0 : _a.length) {
304
+ if (list.Contents?.length) {
287
305
  await eachLimit(list.Contents, 10, async (object) => {
288
306
  debug(' -> copy %s', object.Key);
289
307
  let relative = slash(Path.relative(from, object.Key));
@@ -322,7 +340,7 @@ class OSSAdapter {
322
340
  await this._oss.head(p);
323
341
  return true;
324
342
  }
325
- catch (e) {
343
+ catch (_e) {
326
344
  return false;
327
345
  }
328
346
  }
@@ -334,7 +352,7 @@ class OSSAdapter {
334
352
  await this._oss.head(p);
335
353
  return true;
336
354
  }
337
- catch (e) {
355
+ catch (_e) {
338
356
  return false;
339
357
  }
340
358
  }
@@ -345,7 +363,7 @@ class OSSAdapter {
345
363
  await this._oss.head(p);
346
364
  return true;
347
365
  }
348
- catch (e) {
366
+ catch (_e) {
349
367
  return false;
350
368
  }
351
369
  }
@@ -86,6 +86,10 @@ class SimpleOSSClient {
86
86
  content.Size = parseInt(content.Size);
87
87
  });
88
88
  }
89
+ if (res.CommonPrefixes) {
90
+ if (!Array.isArray(res.CommonPrefixes))
91
+ res.CommonPrefixes = [res.CommonPrefixes];
92
+ }
89
93
  return res;
90
94
  }
91
95
  del(name, options) {
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "fsd-oss",
3
- "version": "0.13.2",
3
+ "version": "0.14.0",
4
4
  "description": "Aliyun OSS adapter for fsd",
5
5
  "main": "lib/index.js",
6
6
  "types": "index.d.ts",
@@ -12,15 +12,15 @@
12
12
  "author": "Liang <liang@miaomo.cc> (https://github.com/liangxingchen)",
13
13
  "license": "MIT",
14
14
  "dependencies": {
15
- "@alicloud/pop-core": "^1.7.13",
16
- "akita": "^1.0.4",
15
+ "@alicloud/pop-core": "^1.8.0",
16
+ "akita": "^1.1.0",
17
17
  "async": "*",
18
- "crypto-js": "^4.1.1",
19
- "debug": "^4.3.4",
18
+ "crypto-js": "^4.2.0",
19
+ "debug": "^4.4.0",
20
20
  "mime-types": "^2.1.35",
21
21
  "minimatch": "^3.1.2",
22
22
  "slash": "^3.0.0",
23
23
  "xml2js": "^0.6.2"
24
24
  },
25
- "gitHead": "f5aaaca713f514d3a8fb65bc2eecd1e8df8fd5c8"
25
+ "gitHead": "74e32bf47242909f040eb6012dda56e5c5a668a0"
26
26
  }
@@ -105,6 +105,7 @@ export interface ListResult extends Result {
105
105
  KeyCount: number;
106
106
  NextContinuationToken?: string;
107
107
  Contents: ListResultContent[];
108
+ CommonPrefixes: ListResultCommonPrefixes[];
108
109
  }
109
110
 
110
111
  export interface ListResultContent {
@@ -119,6 +120,10 @@ export interface ListResultContent {
119
120
  };
120
121
  }
121
122
 
123
+ export interface ListResultCommonPrefixes {
124
+ Prefix: string;
125
+ }
126
+
122
127
  export interface DeleteMultiOptions extends RequestOptions {
123
128
  quiet?: boolean;
124
129
  }