@anmiles/google-api-wrapper 3.0.3 → 4.0.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/CHANGELOG.md CHANGED
@@ -5,6 +5,10 @@ All notable changes to this project will be documented in this file.
5
5
  The format is based on [Keep a Changelog](https://keepachangelog.com/en/1.0.0/),
6
6
  and this project adheres to [Semantic Versioning](https://semver.org/spec/v2.0.0.html).
7
7
 
8
+ ## [4.0.0](../../tags/v4.0.0) - 2023-03-12
9
+ ### Changed
10
+ - Silent mode for getting items
11
+
8
12
  ## [3.0.3](../../tags/v3.0.3) - 2023-03-12
9
13
  ### Changed
10
14
  - Fixed path to scopes file
@@ -1,4 +1,5 @@
1
1
  import type GoogleApis from 'googleapis';
2
+ import type { GetItemsOptions } from '../../types';
2
3
  export { getAPI, getEvents, getCalendars, setEvent };
3
4
  declare const _default: {
4
5
  getAPI: typeof getAPI;
@@ -8,6 +9,6 @@ declare const _default: {
8
9
  };
9
10
  export default _default;
10
11
  declare function getAPI(profile: string): Promise<GoogleApis.calendar_v3.Calendar>;
11
- declare function getCalendars(profile: string, args: GoogleApis.calendar_v3.Params$Resource$Calendarlist$List): Promise<GoogleApis.calendar_v3.Schema$CalendarListEntry[]>;
12
- declare function getEvents(profile: string, args: GoogleApis.calendar_v3.Params$Resource$Events$List): Promise<GoogleApis.calendar_v3.Schema$Event[]>;
12
+ declare function getCalendars(profile: string, args: GoogleApis.calendar_v3.Params$Resource$Calendarlist$List, options?: GetItemsOptions): Promise<GoogleApis.calendar_v3.Schema$CalendarListEntry[]>;
13
+ declare function getEvents(profile: string, args: GoogleApis.calendar_v3.Params$Resource$Events$List, options?: GetItemsOptions): Promise<GoogleApis.calendar_v3.Schema$Event[]>;
13
14
  declare function setEvent(profile: string, eventId: string | undefined, args: GoogleApis.calendar_v3.Params$Resource$Events$Update): Promise<void>;
@@ -17,14 +17,14 @@ async function getAPI(profile) {
17
17
  });
18
18
  }
19
19
  exports.getAPI = getAPI;
20
- async function getCalendars(profile, args) {
20
+ async function getCalendars(profile, args, options) {
21
21
  const api = await calendar_1.default.getAPI(profile);
22
- return (0, shared_1.getItems)(api.calendarList, args);
22
+ return (0, shared_1.getItems)(api.calendarList, args, options);
23
23
  }
24
24
  exports.getCalendars = getCalendars;
25
- async function getEvents(profile, args) {
25
+ async function getEvents(profile, args, options) {
26
26
  const api = await calendar_1.default.getAPI(profile);
27
- return (0, shared_1.getItems)(api.events, args);
27
+ return (0, shared_1.getItems)(api.events, args, options);
28
28
  }
29
29
  exports.getEvents = getEvents;
30
30
  async function setEvent(profile, eventId, args) {
@@ -1 +1 @@
1
- {"version":3,"file":"calendar.js","sourceRoot":"","sources":["../../../src/lib/api/calendar.ts"],"names":[],"mappings":";;;;;;AAAA,2CAAoC;AAEpC,kCAAkC;AAClC,qCAAoC;AACpC,0DAAkC;AAGlC,kBAAe,EAAE,MAAM,EAAE,SAAS,EAAE,YAAY,EAAE,QAAQ,EAAE,CAAC;AAE7D,KAAK,UAAU,MAAM,CAAC,OAAe;IACpC,MAAM,UAAU,GAAG,MAAM,IAAA,cAAO,EAAC,OAAO,CAAC,CAAC;IAE1C,OAAO,mBAAM,CAAC,QAAQ,CAAC;QACtB,OAAO,EAAG,IAAI;QACd,IAAI,EAAM,UAAU;KACpB,CAAC,CAAC;AACJ,CAAC;AAVQ,wBAAM;AAYf,KAAK,UAAU,YAAY,CAAC,OAAe,EAAE,IAA8D;IAC1G,MAAM,GAAG,GAAG,MAAM,kBAAQ,CAAC,MAAM,CAAC,OAAO,CAAC,CAAC;IAC3C,OAAO,IAAA,iBAAQ,EAAC,GAAG,CAAC,YAAY,EAAE,IAAI,CAAC,CAAC;AACzC,CAAC;AAf2B,oCAAY;AAiBxC,KAAK,UAAU,SAAS,CAAC,OAAe,EAAE,IAAwD;IACjG,MAAM,GAAG,GAAG,MAAM,kBAAQ,CAAC,MAAM,CAAC,OAAO,CAAC,CAAC;IAC3C,OAAO,IAAA,iBAAQ,EAAC,GAAG,CAAC,MAAM,EAAE,IAAI,CAAC,CAAC;AACnC,CAAC;AApBgB,8BAAS;AAsB1B,KAAK,UAAU,QAAQ,CAAC,OAAe,EAAE,OAA2B,EAAE,IAA0D;IAC/H,MAAM,GAAG,GAAG,MAAM,kBAAQ,CAAC,MAAM,CAAC,OAAO,CAAC,CAAC;IAC3C,GAAG,CAAC,MAAM,CAAC,MAAM,CAAC,EAAE,OAAO,EAAE,GAAG,IAAI,EAAE,CAAC,CAAC;AACzC,CAAC;AAzByC,4BAAQ"}
1
+ {"version":3,"file":"calendar.js","sourceRoot":"","sources":["../../../src/lib/api/calendar.ts"],"names":[],"mappings":";;;;;;AAAA,2CAAoC;AAGpC,kCAAkC;AAClC,qCAAoC;AACpC,0DAAkC;AAGlC,kBAAe,EAAE,MAAM,EAAE,SAAS,EAAE,YAAY,EAAE,QAAQ,EAAE,CAAC;AAE7D,KAAK,UAAU,MAAM,CAAC,OAAe;IACpC,MAAM,UAAU,GAAG,MAAM,IAAA,cAAO,EAAC,OAAO,CAAC,CAAC;IAE1C,OAAO,mBAAM,CAAC,QAAQ,CAAC;QACtB,OAAO,EAAG,IAAI;QACd,IAAI,EAAM,UAAU;KACpB,CAAC,CAAC;AACJ,CAAC;AAVQ,wBAAM;AAYf,KAAK,UAAU,YAAY,CAAC,OAAe,EAAE,IAA8D,EAAE,OAAyB;IACrI,MAAM,GAAG,GAAG,MAAM,kBAAQ,CAAC,MAAM,CAAC,OAAO,CAAC,CAAC;IAC3C,OAAO,IAAA,iBAAQ,EAAC,GAAG,CAAC,YAAY,EAAE,IAAI,EAAE,OAAO,CAAC,CAAC;AAClD,CAAC;AAf2B,oCAAY;AAiBxC,KAAK,UAAU,SAAS,CAAC,OAAe,EAAE,IAAwD,EAAE,OAAyB;IAC5H,MAAM,GAAG,GAAG,MAAM,kBAAQ,CAAC,MAAM,CAAC,OAAO,CAAC,CAAC;IAC3C,OAAO,IAAA,iBAAQ,EAAC,GAAG,CAAC,MAAM,EAAE,IAAI,EAAE,OAAO,CAAC,CAAC;AAC5C,CAAC;AApBgB,8BAAS;AAsB1B,KAAK,UAAU,QAAQ,CAAC,OAAe,EAAE,OAA2B,EAAE,IAA0D;IAC/H,MAAM,GAAG,GAAG,MAAM,kBAAQ,CAAC,MAAM,CAAC,OAAO,CAAC,CAAC;IAC3C,GAAG,CAAC,MAAM,CAAC,MAAM,CAAC,EAAE,OAAO,EAAE,GAAG,IAAI,EAAE,CAAC,CAAC;AACzC,CAAC;AAzByC,4BAAQ"}
@@ -1,4 +1,5 @@
1
1
  import type GoogleApis from 'googleapis';
2
+ import type { GetItemsOptions } from '../../types';
2
3
  export { getItems };
3
4
  declare const _default: {
4
5
  getItems: typeof getItems;
@@ -16,4 +17,4 @@ type CommonResponse<TItem> = {
16
17
  };
17
18
  nextPageToken?: string | null | undefined;
18
19
  };
19
- declare function getItems<TApi extends CommonApi<TArgs, TResponse>, TItem, TArgs, TResponse extends CommonResponse<TItem>>(api: TApi, args: TArgs): Promise<TItem[]>;
20
+ declare function getItems<TApi extends CommonApi<TArgs, TResponse>, TItem, TArgs, TResponse extends CommonResponse<TItem>>(api: TApi, args: TArgs, options?: GetItemsOptions): Promise<TItem[]>;
@@ -5,14 +5,16 @@ const logger_1 = require("../logger");
5
5
  const sleep_1 = require("../sleep");
6
6
  exports.default = { getItems };
7
7
  const requestInterval = 300;
8
- async function getItems(api, args) {
8
+ async function getItems(api, args, options) {
9
9
  var _a, _b;
10
10
  const items = [];
11
11
  let pageToken = undefined;
12
12
  do {
13
13
  const response = await api.list({ ...args, pageToken });
14
14
  (_a = response.data.items) === null || _a === void 0 ? void 0 : _a.forEach((item) => items.push(item));
15
- (0, logger_1.log)(`Getting items (${items.length} of ${((_b = response.data.pageInfo) === null || _b === void 0 ? void 0 : _b.totalResults) || 'many'})...`);
15
+ if (options === null || options === void 0 ? void 0 : options.showProgress) {
16
+ (0, logger_1.log)(`Getting items (${items.length} of ${((_b = response.data.pageInfo) === null || _b === void 0 ? void 0 : _b.totalResults) || 'many'})...`);
17
+ }
16
18
  pageToken = response.data.nextPageToken;
17
19
  await (0, sleep_1.sleep)(requestInterval);
18
20
  } while (pageToken);
@@ -1 +1 @@
1
- {"version":3,"file":"shared.js","sourceRoot":"","sources":["../../../src/lib/api/shared.ts"],"names":[],"mappings":";;;AACA,sCAAgC;AAChC,oCAAiC;AAGjC,kBAAe,EAAE,QAAQ,EAAE,CAAC;AAiB5B,MAAM,eAAe,GAAG,GAAG,CAAC;AAE5B,KAAK,UAAU,QAAQ,CAKrB,GAAS,EAAE,IAAW;;IACvB,MAAM,KAAK,GAAY,EAAE,CAAC;IAE1B,IAAI,SAAS,GAA8B,SAAS,CAAC;IAErD,GAAG;QACF,MAAM,QAAQ,GAAgD,MAAM,GAAG,CAAC,IAAI,CAAC,EAAE,GAAG,IAAI,EAAE,SAAS,EAAE,CAAC,CAAC;QACrG,MAAA,QAAQ,CAAC,IAAI,CAAC,KAAK,0CAAE,OAAO,CAAC,CAAC,IAAI,EAAE,EAAE,CAAC,KAAK,CAAC,IAAI,CAAC,IAAI,CAAC,CAAC,CAAC;QACzD,IAAA,YAAG,EAAC,kBAAkB,KAAK,CAAC,MAAM,OAAO,CAAA,MAAA,QAAQ,CAAC,IAAI,CAAC,QAAQ,0CAAE,YAAY,KAAI,MAAM,MAAM,CAAC,CAAC;QAC/F,SAAS,GAAG,QAAQ,CAAC,IAAI,CAAC,aAAa,CAAC;QACxC,MAAM,IAAA,aAAK,EAAC,eAAe,CAAC,CAAC;KAC7B,QAAQ,SAAS,EAAE;IAEpB,OAAO,KAAK,CAAC;AACd,CAAC;AAvCQ,4BAAQ"}
1
+ {"version":3,"file":"shared.js","sourceRoot":"","sources":["../../../src/lib/api/shared.ts"],"names":[],"mappings":";;;AAEA,sCAAgC;AAChC,oCAAiC;AAGjC,kBAAe,EAAE,QAAQ,EAAE,CAAC;AAiB5B,MAAM,eAAe,GAAG,GAAG,CAAC;AAE5B,KAAK,UAAU,QAAQ,CAKrB,GAAS,EAAE,IAAW,EAAE,OAAyB;;IAClD,MAAM,KAAK,GAAY,EAAE,CAAC;IAE1B,IAAI,SAAS,GAA8B,SAAS,CAAC;IAErD,GAAG;QACF,MAAM,QAAQ,GAAgD,MAAM,GAAG,CAAC,IAAI,CAAC,EAAE,GAAG,IAAI,EAAE,SAAS,EAAE,CAAC,CAAC;QACrG,MAAA,QAAQ,CAAC,IAAI,CAAC,KAAK,0CAAE,OAAO,CAAC,CAAC,IAAI,EAAE,EAAE,CAAC,KAAK,CAAC,IAAI,CAAC,IAAI,CAAC,CAAC,CAAC;QAEzD,IAAI,OAAO,aAAP,OAAO,uBAAP,OAAO,CAAE,YAAY,EAAE;YAC1B,IAAA,YAAG,EAAC,kBAAkB,KAAK,CAAC,MAAM,OAAO,CAAA,MAAA,QAAQ,CAAC,IAAI,CAAC,QAAQ,0CAAE,YAAY,KAAI,MAAM,MAAM,CAAC,CAAC;SAC/F;QAED,SAAS,GAAG,QAAQ,CAAC,IAAI,CAAC,aAAa,CAAC;QACxC,MAAM,IAAA,aAAK,EAAC,eAAe,CAAC,CAAC;KAC7B,QAAQ,SAAS,EAAE;IAEpB,OAAO,KAAK,CAAC;AACd,CAAC;AA3CQ,4BAAQ"}
@@ -1,4 +1,5 @@
1
1
  import type GoogleApis from 'googleapis';
2
+ import type { GetItemsOptions } from '../../types';
2
3
  export { getAPI, getPlaylistItems };
3
4
  declare const _default: {
4
5
  getAPI: typeof getAPI;
@@ -6,4 +7,4 @@ declare const _default: {
6
7
  };
7
8
  export default _default;
8
9
  declare function getAPI(profile: string): Promise<GoogleApis.youtube_v3.Youtube>;
9
- declare function getPlaylistItems(profile: string, args: GoogleApis.youtube_v3.Params$Resource$Playlistitems$List): Promise<GoogleApis.youtube_v3.Schema$PlaylistItem[]>;
10
+ declare function getPlaylistItems(profile: string, args: GoogleApis.youtube_v3.Params$Resource$Playlistitems$List, options?: GetItemsOptions): Promise<GoogleApis.youtube_v3.Schema$PlaylistItem[]>;
@@ -17,9 +17,9 @@ async function getAPI(profile) {
17
17
  });
18
18
  }
19
19
  exports.getAPI = getAPI;
20
- async function getPlaylistItems(profile, args) {
20
+ async function getPlaylistItems(profile, args, options) {
21
21
  const api = await youtube_1.default.getAPI(profile);
22
- return (0, shared_1.getItems)(api.playlistItems, args);
22
+ return (0, shared_1.getItems)(api.playlistItems, args, options);
23
23
  }
24
24
  exports.getPlaylistItems = getPlaylistItems;
25
25
  //# sourceMappingURL=youtube.js.map
@@ -1 +1 @@
1
- {"version":3,"file":"youtube.js","sourceRoot":"","sources":["../../../src/lib/api/youtube.ts"],"names":[],"mappings":";;;;;;AAAA,2CAAoC;AAEpC,kCAAkC;AAClC,qCAAoC;AACpC,wDAAgC;AAGhC,kBAAe,EAAE,MAAM,EAAE,gBAAgB,EAAE,CAAC;AAE5C,KAAK,UAAU,MAAM,CAAC,OAAe;IACpC,MAAM,UAAU,GAAG,MAAM,IAAA,cAAO,EAAC,OAAO,CAAC,CAAC;IAE1C,OAAO,mBAAM,CAAC,OAAO,CAAC;QACrB,OAAO,EAAG,IAAI;QACd,IAAI,EAAM,UAAU;KACpB,CAAC,CAAC;AACJ,CAAC;AAVQ,wBAAM;AAYf,KAAK,UAAU,gBAAgB,CAAC,OAAe,EAAE,IAA8D;IAC9G,MAAM,GAAG,GAAG,MAAM,iBAAO,CAAC,MAAM,CAAC,OAAO,CAAC,CAAC;IAC1C,OAAO,IAAA,iBAAQ,EAAC,GAAG,CAAC,aAAa,EAAE,IAAI,CAAC,CAAC;AAC1C,CAAC;AAfgB,4CAAgB"}
1
+ {"version":3,"file":"youtube.js","sourceRoot":"","sources":["../../../src/lib/api/youtube.ts"],"names":[],"mappings":";;;;;;AAAA,2CAAoC;AAGpC,kCAAkC;AAClC,qCAAoC;AACpC,wDAAgC;AAGhC,kBAAe,EAAE,MAAM,EAAE,gBAAgB,EAAE,CAAC;AAE5C,KAAK,UAAU,MAAM,CAAC,OAAe;IACpC,MAAM,UAAU,GAAG,MAAM,IAAA,cAAO,EAAC,OAAO,CAAC,CAAC;IAE1C,OAAO,mBAAM,CAAC,OAAO,CAAC;QACrB,OAAO,EAAG,IAAI;QACd,IAAI,EAAM,UAAU;KACpB,CAAC,CAAC;AACJ,CAAC;AAVQ,wBAAM;AAYf,KAAK,UAAU,gBAAgB,CAAC,OAAe,EAAE,IAA8D,EAAE,OAAyB;IACzI,MAAM,GAAG,GAAG,MAAM,iBAAO,CAAC,MAAM,CAAC,OAAO,CAAC,CAAC;IAC1C,OAAO,IAAA,iBAAQ,EAAC,GAAG,CAAC,aAAa,EAAE,IAAI,EAAE,OAAO,CAAC,CAAC;AACnD,CAAC;AAfgB,4CAAgB"}
@@ -0,0 +1,3 @@
1
+ export interface GetItemsOptions {
2
+ showProgress?: boolean;
3
+ }
@@ -0,0 +1,3 @@
1
+ "use strict";
2
+ Object.defineProperty(exports, "__esModule", { value: true });
3
+ //# sourceMappingURL=api.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"api.js","sourceRoot":"","sources":["../../src/types/api.ts"],"names":[],"mappings":""}
@@ -1 +1,2 @@
1
+ export * from './api';
1
2
  export * from './secrets';
@@ -14,5 +14,6 @@ var __exportStar = (this && this.__exportStar) || function(m, exports) {
14
14
  for (var p in m) if (p !== "default" && !Object.prototype.hasOwnProperty.call(exports, p)) __createBinding(exports, m, p);
15
15
  };
16
16
  Object.defineProperty(exports, "__esModule", { value: true });
17
+ __exportStar(require("./api"), exports);
17
18
  __exportStar(require("./secrets"), exports);
18
19
  //# sourceMappingURL=index.js.map
@@ -1 +1 @@
1
- {"version":3,"file":"index.js","sourceRoot":"","sources":["../../src/types/index.ts"],"names":[],"mappings":";;;;;;;;;;;;;;;;AAAA,4CAA0B"}
1
+ {"version":3,"file":"index.js","sourceRoot":"","sources":["../../src/types/index.ts"],"names":[],"mappings":";;;;;;;;;;;;;;;;AAAA,wCAAsB;AACtB,4CAA0B"}
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@anmiles/google-api-wrapper",
3
- "version": "3.0.3",
3
+ "version": "4.0.0",
4
4
  "description": "Provides quick interface for getting google API data",
5
5
  "keywords": [
6
6
  "google",
@@ -30,7 +30,8 @@ jest.mock<Partial<typeof auth>>('../../auth', () => ({
30
30
 
31
31
  const getItemsSpy = jest.spyOn(shared, 'getItems');
32
32
 
33
- const profile = 'username';
33
+ const profile = 'username';
34
+ const getItemsOptions = { showProgress : true };
34
35
 
35
36
  const googleAuth = {
36
37
  setCredentials : jest.fn(),
@@ -100,19 +101,19 @@ describe('src/lib/api/calendar', () => {
100
101
  });
101
102
 
102
103
  it('should get api', async () => {
103
- await original.getCalendars(profile, args);
104
+ await original.getCalendars(profile, args, getItemsOptions);
104
105
 
105
106
  expect(calendar.getAPI).toBeCalledWith(profile);
106
107
  });
107
108
 
108
109
  it('should get items', async () => {
109
- await original.getCalendars(profile, args);
110
+ await original.getCalendars(profile, args, getItemsOptions);
110
111
 
111
- expect(getItemsSpy).toBeCalledWith(calendarsAPI, args);
112
+ expect(getItemsSpy).toBeCalledWith(calendarsAPI, args, getItemsOptions);
112
113
  });
113
114
 
114
115
  it('should return calendars', async () => {
115
- const result = await original.getCalendars(profile, args);
116
+ const result = await original.getCalendars(profile, args, getItemsOptions);
116
117
 
117
118
  expect(result).toEqual(calendars);
118
119
  });
@@ -126,19 +127,19 @@ describe('src/lib/api/calendar', () => {
126
127
  });
127
128
 
128
129
  it('should get api', async () => {
129
- await original.getEvents(profile, args);
130
+ await original.getEvents(profile, args, getItemsOptions);
130
131
 
131
132
  expect(calendar.getAPI).toBeCalledWith(profile);
132
133
  });
133
134
 
134
135
  it('should get items', async () => {
135
- await original.getEvents(profile, args);
136
+ await original.getEvents(profile, args, getItemsOptions);
136
137
 
137
- expect(getItemsSpy).toBeCalledWith(eventsAPI, args);
138
+ expect(getItemsSpy).toBeCalledWith(eventsAPI, args, getItemsOptions);
138
139
  });
139
140
 
140
141
  it('should return events', async () => {
141
- const result = await original.getEvents(profile, args);
142
+ const result = await original.getEvents(profile, args, getItemsOptions);
142
143
 
143
144
  expect(result).toEqual(events);
144
145
  });
@@ -48,8 +48,8 @@ describe('src/lib/api/shared', () => {
48
48
  });
49
49
  });
50
50
 
51
- it('should output progress', async () => {
52
- await original.getItems(api, args);
51
+ it('should output progress if requested', async () => {
52
+ await original.getItems(api, args, { showProgress : true });
53
53
 
54
54
  expect(logger.log).toBeCalledTimes(response.length);
55
55
  expect(logger.log).toBeCalledWith('Getting items (2 of 4)...');
@@ -57,6 +57,12 @@ describe('src/lib/api/shared', () => {
57
57
  expect(logger.log).toBeCalledWith('Getting items (4 of 4)...');
58
58
  });
59
59
 
60
+ it('should not output progress by default', async () => {
61
+ await original.getItems(api, args);
62
+
63
+ expect(logger.log).not.toBeCalled();
64
+ });
65
+
60
66
  it('should sleep after reach request', async () => {
61
67
  await original.getItems(api, args);
62
68
 
@@ -30,7 +30,8 @@ jest.mock<Partial<typeof auth>>('../../auth', () => ({
30
30
 
31
31
  const getItemsSpy = jest.spyOn(shared, 'getItems');
32
32
 
33
- const profile = 'username';
33
+ const profile = 'username';
34
+ const getItemsOptions = { showProgress : true };
34
35
 
35
36
  const googleAuth = {
36
37
  setCredentials : jest.fn(),
@@ -86,19 +87,19 @@ describe('src/lib/api/youtube', () => {
86
87
  });
87
88
 
88
89
  it('should get api', async () => {
89
- await original.getPlaylistItems(profile, args);
90
+ await original.getPlaylistItems(profile, args, getItemsOptions);
90
91
 
91
92
  expect(youtube.getAPI).toBeCalledWith(profile);
92
93
  });
93
94
 
94
95
  it('should call getItems', async () => {
95
- await original.getPlaylistItems(profile, args);
96
+ await original.getPlaylistItems(profile, args, getItemsOptions);
96
97
 
97
- expect(getItemsSpy).toBeCalledWith(playlistItemsAPI, args);
98
+ expect(getItemsSpy).toBeCalledWith(playlistItemsAPI, args, getItemsOptions);
98
99
  });
99
100
 
100
101
  it('should return videos', async () => {
101
- const result = await original.getPlaylistItems(profile, args);
102
+ const result = await original.getPlaylistItems(profile, args, getItemsOptions);
102
103
 
103
104
  expect(result).toEqual(playlistItems);
104
105
  });
@@ -1,5 +1,6 @@
1
1
  import { google } from 'googleapis';
2
2
  import type GoogleApis from 'googleapis';
3
+ import type { GetItemsOptions } from '../../types';
3
4
  import { getAuth } from '../auth';
4
5
  import { getItems } from './shared';
5
6
  import calendar from './calendar';
@@ -16,14 +17,14 @@ async function getAPI(profile: string): Promise<GoogleApis.calendar_v3.Calendar>
16
17
  });
17
18
  }
18
19
 
19
- async function getCalendars(profile: string, args: GoogleApis.calendar_v3.Params$Resource$Calendarlist$List): Promise<GoogleApis.calendar_v3.Schema$CalendarListEntry[]> {
20
+ async function getCalendars(profile: string, args: GoogleApis.calendar_v3.Params$Resource$Calendarlist$List, options?: GetItemsOptions): Promise<GoogleApis.calendar_v3.Schema$CalendarListEntry[]> {
20
21
  const api = await calendar.getAPI(profile);
21
- return getItems(api.calendarList, args);
22
+ return getItems(api.calendarList, args, options);
22
23
  }
23
24
 
24
- async function getEvents(profile: string, args: GoogleApis.calendar_v3.Params$Resource$Events$List): Promise<GoogleApis.calendar_v3.Schema$Event[]> {
25
+ async function getEvents(profile: string, args: GoogleApis.calendar_v3.Params$Resource$Events$List, options?: GetItemsOptions): Promise<GoogleApis.calendar_v3.Schema$Event[]> {
25
26
  const api = await calendar.getAPI(profile);
26
- return getItems(api.events, args);
27
+ return getItems(api.events, args, options);
27
28
  }
28
29
 
29
30
  async function setEvent(profile: string, eventId: string | undefined, args: GoogleApis.calendar_v3.Params$Resource$Events$Update) {
@@ -1,4 +1,5 @@
1
1
  import type GoogleApis from 'googleapis';
2
+ import type { GetItemsOptions } from '../../types';
2
3
  import { log } from '../logger';
3
4
  import { sleep } from '../sleep';
4
5
 
@@ -27,7 +28,7 @@ async function getItems<
27
28
  TItem,
28
29
  TArgs,
29
30
  TResponse extends CommonResponse<TItem>
30
- >(api: TApi, args: TArgs): Promise<TItem[]> {
31
+ >(api: TApi, args: TArgs, options?: GetItemsOptions): Promise<TItem[]> {
31
32
  const items: TItem[] = [];
32
33
 
33
34
  let pageToken: string | null | undefined = undefined;
@@ -35,7 +36,11 @@ async function getItems<
35
36
  do {
36
37
  const response: GoogleApis.Common.GaxiosResponse<TResponse> = await api.list({ ...args, pageToken });
37
38
  response.data.items?.forEach((item) => items.push(item));
38
- log(`Getting items (${items.length} of ${response.data.pageInfo?.totalResults || 'many'})...`);
39
+
40
+ if (options?.showProgress) {
41
+ log(`Getting items (${items.length} of ${response.data.pageInfo?.totalResults || 'many'})...`);
42
+ }
43
+
39
44
  pageToken = response.data.nextPageToken;
40
45
  await sleep(requestInterval);
41
46
  } while (pageToken);
@@ -1,5 +1,6 @@
1
1
  import { google } from 'googleapis';
2
2
  import type GoogleApis from 'googleapis';
3
+ import type { GetItemsOptions } from '../../types';
3
4
  import { getAuth } from '../auth';
4
5
  import { getItems } from './shared';
5
6
  import youtube from './youtube';
@@ -16,7 +17,7 @@ async function getAPI(profile: string): Promise<GoogleApis.youtube_v3.Youtube> {
16
17
  });
17
18
  }
18
19
 
19
- async function getPlaylistItems(profile: string, args: GoogleApis.youtube_v3.Params$Resource$Playlistitems$List): Promise<GoogleApis.youtube_v3.Schema$PlaylistItem[]> {
20
+ async function getPlaylistItems(profile: string, args: GoogleApis.youtube_v3.Params$Resource$Playlistitems$List, options?: GetItemsOptions): Promise<GoogleApis.youtube_v3.Schema$PlaylistItem[]> {
20
21
  const api = await youtube.getAPI(profile);
21
- return getItems(api.playlistItems, args);
22
+ return getItems(api.playlistItems, args, options);
22
23
  }
@@ -0,0 +1,3 @@
1
+ export interface GetItemsOptions {
2
+ showProgress?: boolean
3
+ }
@@ -1 +1,2 @@
1
+ export * from './api';
1
2
  export * from './secrets';