@adobe/helix-google-support 1.3.0 → 1.3.3

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/CHANGELOG.md CHANGED
@@ -1,3 +1,24 @@
1
+ ## [1.3.3](https://github.com/adobe/helix-google-support/compare/v1.3.2...v1.3.3) (2022-05-03)
2
+
3
+
4
+ ### Bug Fixes
5
+
6
+ * more fixes ([#17](https://github.com/adobe/helix-google-support/issues/17)) ([87b3ea8](https://github.com/adobe/helix-google-support/commit/87b3ea8a4621a8773d072d20be33e2b5d4ce2e54))
7
+
8
+ ## [1.3.2](https://github.com/adobe/helix-google-support/compare/v1.3.1...v1.3.2) (2022-04-30)
9
+
10
+
11
+ ### Bug Fixes
12
+
13
+ * **deps:** update dependency lru-cache to v7.9.0 ([de4e8e3](https://github.com/adobe/helix-google-support/commit/de4e8e3918a04dbb646c33946791168f434b872d))
14
+
15
+ ## [1.3.1](https://github.com/adobe/helix-google-support/compare/v1.3.0...v1.3.1) (2022-04-28)
16
+
17
+
18
+ ### Bug Fixes
19
+
20
+ * more fixes ([#14](https://github.com/adobe/helix-google-support/issues/14)) ([f52b01d](https://github.com/adobe/helix-google-support/commit/f52b01d575fb17602ea57b35f0e4c93dbbd41dd1))
21
+
1
22
  # [1.3.0](https://github.com/adobe/helix-google-support/compare/v1.2.2...v1.3.0) (2022-04-28)
2
23
 
3
24
 
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@adobe/helix-google-support",
3
- "version": "1.3.0",
3
+ "version": "1.3.3",
4
4
  "description": "Helix Google Support",
5
5
  "main": "src/index.js",
6
6
  "type": "module",
@@ -33,7 +33,7 @@
33
33
  "dependencies": {
34
34
  "@adobe/helix-onedrive-support": "https://github.com/adobe/helix-onedrive-support.git#d279dda0abdc05df14628d45a7c716042d94ec45",
35
35
  "googleapis": "100.0.0",
36
- "lru-cache": "7.8.1"
36
+ "lru-cache": "7.9.0"
37
37
  },
38
38
  "devDependencies": {
39
39
  "@adobe/eslint-config-helix": "1.3.2",
@@ -47,8 +47,8 @@
47
47
  "eslint-plugin-import": "2.26.0",
48
48
  "husky": "7.0.4",
49
49
  "junit-report-builder": "3.0.0",
50
- "lint-staged": "12.4.0",
51
- "mocha": "9.2.2",
50
+ "lint-staged": "12.4.1",
51
+ "mocha": "10.0.0",
52
52
  "mocha-multi-reporters": "1.5.1",
53
53
  "nock": "13.2.4",
54
54
  "semantic-release": "19.0.2"
@@ -25,19 +25,25 @@ let lru = new LRU({ max: 1000, ttl: 60000 });
25
25
  * @property {string} name
26
26
  * @property {string} url
27
27
  * @property {string} path
28
+ * @property {string} mimeType
29
+ * @property {number} lastModified
28
30
  */
29
31
 
30
32
  /**
31
- * Adds the last modified property if defined in item
33
+ * Adds the last modified property and mimeType if defined in item
32
34
  * @param {DriveItemInfo} itemInfo
33
35
  * @param item
34
36
  * @returns {DriveItemInfo}
35
37
  */
36
- function addLastModified(itemInfo, item) {
38
+ function addFields(itemInfo, item) {
37
39
  if (item.modifiedTime) {
38
40
  // eslint-disable-next-line no-param-reassign
39
41
  itemInfo.lastModified = Date.parse(item.modifiedTime);
40
42
  }
43
+ if (item.mimeType) {
44
+ // eslint-disable-next-line no-param-reassign
45
+ itemInfo.mimeType = item.mimeType;
46
+ }
41
47
  return itemInfo;
42
48
  }
43
49
 
@@ -232,11 +238,10 @@ export class GoogleClient {
232
238
  if (!children) {
233
239
  return null;
234
240
  }
235
- const pathItem = addLastModified({
241
+ const pathItem = addFields({
236
242
  name,
237
243
  path: itemPath,
238
244
  id: item.id,
239
- mimeType: item.mimeType,
240
245
  }, item);
241
246
 
242
247
  if (children.length) {
@@ -320,7 +325,7 @@ export class GoogleClient {
320
325
  const root = roots[fileId];
321
326
  if (root) {
322
327
  // stop at mount root
323
- return [addLastModified({
328
+ return [addFields({
324
329
  id: fileId,
325
330
  name: '',
326
331
  path: root,
@@ -330,7 +335,7 @@ export class GoogleClient {
330
335
  const parentId = data.parents ? data.parents[0] : '';
331
336
  if (!parentId) {
332
337
  // outside mountpoint
333
- return [addLastModified({
338
+ return [addFields({
334
339
  id: fileId,
335
340
  name: data.name,
336
341
  path: `/root:/${data.name}`,
@@ -339,7 +344,7 @@ export class GoogleClient {
339
344
 
340
345
  const ancestors = await this.getItems(data.parents[0], roots);
341
346
  const parentPath = ancestors[0].path.replace(/\/+$/, '');
342
- ancestors.unshift(addLastModified({
347
+ ancestors.unshift(addFields({
343
348
  id: fileId,
344
349
  name: data.name,
345
350
  path: `${parentPath}/${data.name}`,
@@ -370,27 +375,38 @@ export class GoogleClient {
370
375
  * Returns the (cached) item for the given path or {@code null} if the item cannot be found.
371
376
  * The item will contains a `invalidate()` method which can be used to remove it from the cache.
372
377
  *
373
- * @param {string} parentId
374
- * @param {string} path
378
+ * @param {string} parentId the parent id or the id of the item itself, if the path is missing
379
+ * @param {string} [path]
375
380
  * @returns {Promise<DriveItemInfo>}
376
381
  */
377
382
  async getItemFromPath(parentId, path) {
378
383
  if (!path) {
379
384
  try {
380
- const { data } = (await this.drive.files.get({
381
- fileId: parentId,
382
- fields: [
383
- 'name',
384
- 'parents',
385
- 'mimeType',
386
- 'modifiedTime',
387
- ].join(','),
388
- }));
389
-
390
- return addLastModified({
391
- id: parentId,
392
- path: `/${data.name}`,
393
- }, data);
385
+ let item = lru.get(parentId);
386
+ if (!item) {
387
+ const { data } = (await this.drive.files.get({
388
+ fileId: parentId,
389
+ fields: [
390
+ 'name',
391
+ 'parents',
392
+ 'mimeType',
393
+ 'modifiedTime',
394
+ ].join(','),
395
+ }));
396
+ item = addFields({
397
+ id: parentId,
398
+ path: `/${data.name}`,
399
+ }, data);
400
+ // todo: extend caching to all items ?
401
+ Object.defineProperty(item, 'invalidate', {
402
+ enumerable: false,
403
+ value() {
404
+ lru.delete(parentId);
405
+ },
406
+ });
407
+ lru.set(parentId, item);
408
+ }
409
+ return item;
394
410
  } catch (e) {
395
411
  if (e.response && e.response.status === 404) {
396
412
  return null;