google-sheets-mapper 2.0.0 → 2.1.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.
@@ -1,756 +0,0 @@
1
- function _regeneratorRuntime() {
2
- /*! regenerator-runtime -- Copyright (c) 2014-present, Facebook, Inc. -- license (MIT): https://github.com/facebook/regenerator/blob/main/LICENSE */
3
-
4
- _regeneratorRuntime = function () {
5
- return exports;
6
- };
7
-
8
- var exports = {},
9
- Op = Object.prototype,
10
- hasOwn = Op.hasOwnProperty,
11
- $Symbol = "function" == typeof Symbol ? Symbol : {},
12
- iteratorSymbol = $Symbol.iterator || "@@iterator",
13
- asyncIteratorSymbol = $Symbol.asyncIterator || "@@asyncIterator",
14
- toStringTagSymbol = $Symbol.toStringTag || "@@toStringTag";
15
-
16
- function define(obj, key, value) {
17
- return Object.defineProperty(obj, key, {
18
- value: value,
19
- enumerable: !0,
20
- configurable: !0,
21
- writable: !0
22
- }), obj[key];
23
- }
24
-
25
- try {
26
- define({}, "");
27
- } catch (err) {
28
- define = function (obj, key, value) {
29
- return obj[key] = value;
30
- };
31
- }
32
-
33
- function wrap(innerFn, outerFn, self, tryLocsList) {
34
- var protoGenerator = outerFn && outerFn.prototype instanceof Generator ? outerFn : Generator,
35
- generator = Object.create(protoGenerator.prototype),
36
- context = new Context(tryLocsList || []);
37
- return generator._invoke = function (innerFn, self, context) {
38
- var state = "suspendedStart";
39
- return function (method, arg) {
40
- if ("executing" === state) throw new Error("Generator is already running");
41
-
42
- if ("completed" === state) {
43
- if ("throw" === method) throw arg;
44
- return doneResult();
45
- }
46
-
47
- for (context.method = method, context.arg = arg;;) {
48
- var delegate = context.delegate;
49
-
50
- if (delegate) {
51
- var delegateResult = maybeInvokeDelegate(delegate, context);
52
-
53
- if (delegateResult) {
54
- if (delegateResult === ContinueSentinel) continue;
55
- return delegateResult;
56
- }
57
- }
58
-
59
- if ("next" === context.method) context.sent = context._sent = context.arg;else if ("throw" === context.method) {
60
- if ("suspendedStart" === state) throw state = "completed", context.arg;
61
- context.dispatchException(context.arg);
62
- } else "return" === context.method && context.abrupt("return", context.arg);
63
- state = "executing";
64
- var record = tryCatch(innerFn, self, context);
65
-
66
- if ("normal" === record.type) {
67
- if (state = context.done ? "completed" : "suspendedYield", record.arg === ContinueSentinel) continue;
68
- return {
69
- value: record.arg,
70
- done: context.done
71
- };
72
- }
73
-
74
- "throw" === record.type && (state = "completed", context.method = "throw", context.arg = record.arg);
75
- }
76
- };
77
- }(innerFn, self, context), generator;
78
- }
79
-
80
- function tryCatch(fn, obj, arg) {
81
- try {
82
- return {
83
- type: "normal",
84
- arg: fn.call(obj, arg)
85
- };
86
- } catch (err) {
87
- return {
88
- type: "throw",
89
- arg: err
90
- };
91
- }
92
- }
93
-
94
- exports.wrap = wrap;
95
- var ContinueSentinel = {};
96
-
97
- function Generator() {}
98
-
99
- function GeneratorFunction() {}
100
-
101
- function GeneratorFunctionPrototype() {}
102
-
103
- var IteratorPrototype = {};
104
- define(IteratorPrototype, iteratorSymbol, function () {
105
- return this;
106
- });
107
- var getProto = Object.getPrototypeOf,
108
- NativeIteratorPrototype = getProto && getProto(getProto(values([])));
109
- NativeIteratorPrototype && NativeIteratorPrototype !== Op && hasOwn.call(NativeIteratorPrototype, iteratorSymbol) && (IteratorPrototype = NativeIteratorPrototype);
110
- var Gp = GeneratorFunctionPrototype.prototype = Generator.prototype = Object.create(IteratorPrototype);
111
-
112
- function defineIteratorMethods(prototype) {
113
- ["next", "throw", "return"].forEach(function (method) {
114
- define(prototype, method, function (arg) {
115
- return this._invoke(method, arg);
116
- });
117
- });
118
- }
119
-
120
- function AsyncIterator(generator, PromiseImpl) {
121
- function invoke(method, arg, resolve, reject) {
122
- var record = tryCatch(generator[method], generator, arg);
123
-
124
- if ("throw" !== record.type) {
125
- var result = record.arg,
126
- value = result.value;
127
- return value && "object" == typeof value && hasOwn.call(value, "__await") ? PromiseImpl.resolve(value.__await).then(function (value) {
128
- invoke("next", value, resolve, reject);
129
- }, function (err) {
130
- invoke("throw", err, resolve, reject);
131
- }) : PromiseImpl.resolve(value).then(function (unwrapped) {
132
- result.value = unwrapped, resolve(result);
133
- }, function (error) {
134
- return invoke("throw", error, resolve, reject);
135
- });
136
- }
137
-
138
- reject(record.arg);
139
- }
140
-
141
- var previousPromise;
142
-
143
- this._invoke = function (method, arg) {
144
- function callInvokeWithMethodAndArg() {
145
- return new PromiseImpl(function (resolve, reject) {
146
- invoke(method, arg, resolve, reject);
147
- });
148
- }
149
-
150
- return previousPromise = previousPromise ? previousPromise.then(callInvokeWithMethodAndArg, callInvokeWithMethodAndArg) : callInvokeWithMethodAndArg();
151
- };
152
- }
153
-
154
- function maybeInvokeDelegate(delegate, context) {
155
- var method = delegate.iterator[context.method];
156
-
157
- if (undefined === method) {
158
- if (context.delegate = null, "throw" === context.method) {
159
- if (delegate.iterator.return && (context.method = "return", context.arg = undefined, maybeInvokeDelegate(delegate, context), "throw" === context.method)) return ContinueSentinel;
160
- context.method = "throw", context.arg = new TypeError("The iterator does not provide a 'throw' method");
161
- }
162
-
163
- return ContinueSentinel;
164
- }
165
-
166
- var record = tryCatch(method, delegate.iterator, context.arg);
167
- if ("throw" === record.type) return context.method = "throw", context.arg = record.arg, context.delegate = null, ContinueSentinel;
168
- var info = record.arg;
169
- return info ? info.done ? (context[delegate.resultName] = info.value, context.next = delegate.nextLoc, "return" !== context.method && (context.method = "next", context.arg = undefined), context.delegate = null, ContinueSentinel) : info : (context.method = "throw", context.arg = new TypeError("iterator result is not an object"), context.delegate = null, ContinueSentinel);
170
- }
171
-
172
- function pushTryEntry(locs) {
173
- var entry = {
174
- tryLoc: locs[0]
175
- };
176
- 1 in locs && (entry.catchLoc = locs[1]), 2 in locs && (entry.finallyLoc = locs[2], entry.afterLoc = locs[3]), this.tryEntries.push(entry);
177
- }
178
-
179
- function resetTryEntry(entry) {
180
- var record = entry.completion || {};
181
- record.type = "normal", delete record.arg, entry.completion = record;
182
- }
183
-
184
- function Context(tryLocsList) {
185
- this.tryEntries = [{
186
- tryLoc: "root"
187
- }], tryLocsList.forEach(pushTryEntry, this), this.reset(!0);
188
- }
189
-
190
- function values(iterable) {
191
- if (iterable) {
192
- var iteratorMethod = iterable[iteratorSymbol];
193
- if (iteratorMethod) return iteratorMethod.call(iterable);
194
- if ("function" == typeof iterable.next) return iterable;
195
-
196
- if (!isNaN(iterable.length)) {
197
- var i = -1,
198
- next = function next() {
199
- for (; ++i < iterable.length;) if (hasOwn.call(iterable, i)) return next.value = iterable[i], next.done = !1, next;
200
-
201
- return next.value = undefined, next.done = !0, next;
202
- };
203
-
204
- return next.next = next;
205
- }
206
- }
207
-
208
- return {
209
- next: doneResult
210
- };
211
- }
212
-
213
- function doneResult() {
214
- return {
215
- value: undefined,
216
- done: !0
217
- };
218
- }
219
-
220
- return GeneratorFunction.prototype = GeneratorFunctionPrototype, define(Gp, "constructor", GeneratorFunctionPrototype), define(GeneratorFunctionPrototype, "constructor", GeneratorFunction), GeneratorFunction.displayName = define(GeneratorFunctionPrototype, toStringTagSymbol, "GeneratorFunction"), exports.isGeneratorFunction = function (genFun) {
221
- var ctor = "function" == typeof genFun && genFun.constructor;
222
- return !!ctor && (ctor === GeneratorFunction || "GeneratorFunction" === (ctor.displayName || ctor.name));
223
- }, exports.mark = function (genFun) {
224
- return Object.setPrototypeOf ? Object.setPrototypeOf(genFun, GeneratorFunctionPrototype) : (genFun.__proto__ = GeneratorFunctionPrototype, define(genFun, toStringTagSymbol, "GeneratorFunction")), genFun.prototype = Object.create(Gp), genFun;
225
- }, exports.awrap = function (arg) {
226
- return {
227
- __await: arg
228
- };
229
- }, defineIteratorMethods(AsyncIterator.prototype), define(AsyncIterator.prototype, asyncIteratorSymbol, function () {
230
- return this;
231
- }), exports.AsyncIterator = AsyncIterator, exports.async = function (innerFn, outerFn, self, tryLocsList, PromiseImpl) {
232
- void 0 === PromiseImpl && (PromiseImpl = Promise);
233
- var iter = new AsyncIterator(wrap(innerFn, outerFn, self, tryLocsList), PromiseImpl);
234
- return exports.isGeneratorFunction(outerFn) ? iter : iter.next().then(function (result) {
235
- return result.done ? result.value : iter.next();
236
- });
237
- }, defineIteratorMethods(Gp), define(Gp, toStringTagSymbol, "Generator"), define(Gp, iteratorSymbol, function () {
238
- return this;
239
- }), define(Gp, "toString", function () {
240
- return "[object Generator]";
241
- }), exports.keys = function (object) {
242
- var keys = [];
243
-
244
- for (var key in object) keys.push(key);
245
-
246
- return keys.reverse(), function next() {
247
- for (; keys.length;) {
248
- var key = keys.pop();
249
- if (key in object) return next.value = key, next.done = !1, next;
250
- }
251
-
252
- return next.done = !0, next;
253
- };
254
- }, exports.values = values, Context.prototype = {
255
- constructor: Context,
256
- reset: function (skipTempReset) {
257
- if (this.prev = 0, this.next = 0, this.sent = this._sent = undefined, this.done = !1, this.delegate = null, this.method = "next", this.arg = undefined, this.tryEntries.forEach(resetTryEntry), !skipTempReset) for (var name in this) "t" === name.charAt(0) && hasOwn.call(this, name) && !isNaN(+name.slice(1)) && (this[name] = undefined);
258
- },
259
- stop: function () {
260
- this.done = !0;
261
- var rootRecord = this.tryEntries[0].completion;
262
- if ("throw" === rootRecord.type) throw rootRecord.arg;
263
- return this.rval;
264
- },
265
- dispatchException: function (exception) {
266
- if (this.done) throw exception;
267
- var context = this;
268
-
269
- function handle(loc, caught) {
270
- return record.type = "throw", record.arg = exception, context.next = loc, caught && (context.method = "next", context.arg = undefined), !!caught;
271
- }
272
-
273
- for (var i = this.tryEntries.length - 1; i >= 0; --i) {
274
- var entry = this.tryEntries[i],
275
- record = entry.completion;
276
- if ("root" === entry.tryLoc) return handle("end");
277
-
278
- if (entry.tryLoc <= this.prev) {
279
- var hasCatch = hasOwn.call(entry, "catchLoc"),
280
- hasFinally = hasOwn.call(entry, "finallyLoc");
281
-
282
- if (hasCatch && hasFinally) {
283
- if (this.prev < entry.catchLoc) return handle(entry.catchLoc, !0);
284
- if (this.prev < entry.finallyLoc) return handle(entry.finallyLoc);
285
- } else if (hasCatch) {
286
- if (this.prev < entry.catchLoc) return handle(entry.catchLoc, !0);
287
- } else {
288
- if (!hasFinally) throw new Error("try statement without catch or finally");
289
- if (this.prev < entry.finallyLoc) return handle(entry.finallyLoc);
290
- }
291
- }
292
- }
293
- },
294
- abrupt: function (type, arg) {
295
- for (var i = this.tryEntries.length - 1; i >= 0; --i) {
296
- var entry = this.tryEntries[i];
297
-
298
- if (entry.tryLoc <= this.prev && hasOwn.call(entry, "finallyLoc") && this.prev < entry.finallyLoc) {
299
- var finallyEntry = entry;
300
- break;
301
- }
302
- }
303
-
304
- finallyEntry && ("break" === type || "continue" === type) && finallyEntry.tryLoc <= arg && arg <= finallyEntry.finallyLoc && (finallyEntry = null);
305
- var record = finallyEntry ? finallyEntry.completion : {};
306
- return record.type = type, record.arg = arg, finallyEntry ? (this.method = "next", this.next = finallyEntry.finallyLoc, ContinueSentinel) : this.complete(record);
307
- },
308
- complete: function (record, afterLoc) {
309
- if ("throw" === record.type) throw record.arg;
310
- return "break" === record.type || "continue" === record.type ? this.next = record.arg : "return" === record.type ? (this.rval = this.arg = record.arg, this.method = "return", this.next = "end") : "normal" === record.type && afterLoc && (this.next = afterLoc), ContinueSentinel;
311
- },
312
- finish: function (finallyLoc) {
313
- for (var i = this.tryEntries.length - 1; i >= 0; --i) {
314
- var entry = this.tryEntries[i];
315
- if (entry.finallyLoc === finallyLoc) return this.complete(entry.completion, entry.afterLoc), resetTryEntry(entry), ContinueSentinel;
316
- }
317
- },
318
- catch: function (tryLoc) {
319
- for (var i = this.tryEntries.length - 1; i >= 0; --i) {
320
- var entry = this.tryEntries[i];
321
-
322
- if (entry.tryLoc === tryLoc) {
323
- var record = entry.completion;
324
-
325
- if ("throw" === record.type) {
326
- var thrown = record.arg;
327
- resetTryEntry(entry);
328
- }
329
-
330
- return thrown;
331
- }
332
- }
333
-
334
- throw new Error("illegal catch attempt");
335
- },
336
- delegateYield: function (iterable, resultName, nextLoc) {
337
- return this.delegate = {
338
- iterator: values(iterable),
339
- resultName: resultName,
340
- nextLoc: nextLoc
341
- }, "next" === this.method && (this.arg = undefined), ContinueSentinel;
342
- }
343
- }, exports;
344
- }
345
-
346
- function asyncGeneratorStep(gen, resolve, reject, _next, _throw, key, arg) {
347
- try {
348
- var info = gen[key](arg);
349
- var value = info.value;
350
- } catch (error) {
351
- reject(error);
352
- return;
353
- }
354
-
355
- if (info.done) {
356
- resolve(value);
357
- } else {
358
- Promise.resolve(value).then(_next, _throw);
359
- }
360
- }
361
-
362
- function _asyncToGenerator(fn) {
363
- return function () {
364
- var self = this,
365
- args = arguments;
366
- return new Promise(function (resolve, reject) {
367
- var gen = fn.apply(self, args);
368
-
369
- function _next(value) {
370
- asyncGeneratorStep(gen, resolve, reject, _next, _throw, "next", value);
371
- }
372
-
373
- function _throw(err) {
374
- asyncGeneratorStep(gen, resolve, reject, _next, _throw, "throw", err);
375
- }
376
-
377
- _next(undefined);
378
- });
379
- };
380
- }
381
-
382
- function _inheritsLoose(subClass, superClass) {
383
- subClass.prototype = Object.create(superClass.prototype);
384
- subClass.prototype.constructor = subClass;
385
-
386
- _setPrototypeOf(subClass, superClass);
387
- }
388
-
389
- function _getPrototypeOf(o) {
390
- _getPrototypeOf = Object.setPrototypeOf ? Object.getPrototypeOf.bind() : function _getPrototypeOf(o) {
391
- return o.__proto__ || Object.getPrototypeOf(o);
392
- };
393
- return _getPrototypeOf(o);
394
- }
395
-
396
- function _setPrototypeOf(o, p) {
397
- _setPrototypeOf = Object.setPrototypeOf ? Object.setPrototypeOf.bind() : function _setPrototypeOf(o, p) {
398
- o.__proto__ = p;
399
- return o;
400
- };
401
- return _setPrototypeOf(o, p);
402
- }
403
-
404
- function _isNativeReflectConstruct() {
405
- if (typeof Reflect === "undefined" || !Reflect.construct) return false;
406
- if (Reflect.construct.sham) return false;
407
- if (typeof Proxy === "function") return true;
408
-
409
- try {
410
- Boolean.prototype.valueOf.call(Reflect.construct(Boolean, [], function () {}));
411
- return true;
412
- } catch (e) {
413
- return false;
414
- }
415
- }
416
-
417
- function _construct(Parent, args, Class) {
418
- if (_isNativeReflectConstruct()) {
419
- _construct = Reflect.construct.bind();
420
- } else {
421
- _construct = function _construct(Parent, args, Class) {
422
- var a = [null];
423
- a.push.apply(a, args);
424
- var Constructor = Function.bind.apply(Parent, a);
425
- var instance = new Constructor();
426
- if (Class) _setPrototypeOf(instance, Class.prototype);
427
- return instance;
428
- };
429
- }
430
-
431
- return _construct.apply(null, arguments);
432
- }
433
-
434
- function _isNativeFunction(fn) {
435
- return Function.toString.call(fn).indexOf("[native code]") !== -1;
436
- }
437
-
438
- function _wrapNativeSuper(Class) {
439
- var _cache = typeof Map === "function" ? new Map() : undefined;
440
-
441
- _wrapNativeSuper = function _wrapNativeSuper(Class) {
442
- if (Class === null || !_isNativeFunction(Class)) return Class;
443
-
444
- if (typeof Class !== "function") {
445
- throw new TypeError("Super expression must either be null or a function");
446
- }
447
-
448
- if (typeof _cache !== "undefined") {
449
- if (_cache.has(Class)) return _cache.get(Class);
450
-
451
- _cache.set(Class, Wrapper);
452
- }
453
-
454
- function Wrapper() {
455
- return _construct(Class, arguments, _getPrototypeOf(this).constructor);
456
- }
457
-
458
- Wrapper.prototype = Object.create(Class.prototype, {
459
- constructor: {
460
- value: Wrapper,
461
- enumerable: false,
462
- writable: true,
463
- configurable: true
464
- }
465
- });
466
- return _setPrototypeOf(Wrapper, Class);
467
- };
468
-
469
- return _wrapNativeSuper(Class);
470
- }
471
-
472
- function _assertThisInitialized(self) {
473
- if (self === void 0) {
474
- throw new ReferenceError("this hasn't been initialised - super() hasn't been called");
475
- }
476
-
477
- return self;
478
- }
479
-
480
- var GOOGLE_API_URL = 'https://sheets.googleapis.com/v4/spreadsheets';
481
-
482
- var getRanges = function getRanges(sheetNames) {
483
- if (sheetNames === void 0) {
484
- sheetNames = [];
485
- }
486
-
487
- // ranges=Sheet1&ranges=Sheet2
488
- return sheetNames.map(function (sheetName) {
489
- return "ranges=" + sheetName;
490
- }).join('&');
491
- };
492
-
493
- var getSheetsTitleUrl = function getSheetsTitleUrl(sheetId, apiKey) {
494
- return GOOGLE_API_URL + "/" + sheetId + "?fields=sheets%2Fproperties%2Ftitle&key=" + apiKey;
495
- };
496
-
497
- var getBatchUrl = function getBatchUrl(sheetId, ranges, apiKey) {
498
- var rangesQueryString = getRanges(ranges);
499
- return GOOGLE_API_URL + "/" + sheetId + "/values:batchGet?" + rangesQueryString + "&key=" + apiKey;
500
- };
501
-
502
- var ApiResponseError = /*#__PURE__*/function (_Error) {
503
- _inheritsLoose(ApiResponseError, _Error);
504
-
505
- function ApiResponseError(message, response) {
506
- var _this;
507
-
508
- _this = _Error.call(this, message) || this;
509
- _this.response = response;
510
- Object.setPrototypeOf(_assertThisInitialized(_this), ApiResponseError.prototype);
511
- _this.response = response;
512
- Error.captureStackTrace(_assertThisInitialized(_this), ApiResponseError);
513
- return _this;
514
- }
515
-
516
- return ApiResponseError;
517
- }( /*#__PURE__*/_wrapNativeSuper(Error));
518
-
519
- var makeFetch = /*#__PURE__*/function () {
520
- var _ref = /*#__PURE__*/_asyncToGenerator( /*#__PURE__*/_regeneratorRuntime().mark(function _callee(url, config) {
521
- var response;
522
- return _regeneratorRuntime().wrap(function _callee$(_context) {
523
- while (1) {
524
- switch (_context.prev = _context.next) {
525
- case 0:
526
- if (config === void 0) {
527
- config = {};
528
- }
529
-
530
- _context.prev = 1;
531
- _context.next = 4;
532
- return fetch(url, config);
533
-
534
- case 4:
535
- response = _context.sent;
536
-
537
- if (response.ok) {
538
- _context.next = 7;
539
- break;
540
- }
541
-
542
- throw new ApiResponseError("Request to '" + url + "' failed with " + response.status + (response.statusText ? ": " + response.statusText : ''), {
543
- status: response.status,
544
- statusText: response.statusText,
545
- url: response.url
546
- });
547
-
548
- case 7:
549
- _context.next = 9;
550
- return response.json();
551
-
552
- case 9:
553
- return _context.abrupt("return", _context.sent);
554
-
555
- case 12:
556
- _context.prev = 12;
557
- _context.t0 = _context["catch"](1);
558
- console.error(_context.t0);
559
- throw _context.t0;
560
-
561
- case 16:
562
- case "end":
563
- return _context.stop();
564
- }
565
- }
566
- }, _callee, null, [[1, 12]]);
567
- }));
568
-
569
- return function makeFetch(_x, _x2) {
570
- return _ref.apply(this, arguments);
571
- };
572
- }();
573
-
574
- var mapRecords = function mapRecords(records, headerData) {
575
- return records.filter(function (record) {
576
- return record.length > 0;
577
- }).map(function (record) {
578
- return record.reduce(function (obj, item, index) {
579
- obj[headerData[index]] = item;
580
- return obj;
581
- }, {});
582
- });
583
- };
584
-
585
- var mapData = function mapData(_ref2) {
586
- var sheets = _ref2.sheets,
587
- _ref2$sheetsOptions = _ref2.sheetsOptions,
588
- sheetsOptions = _ref2$sheetsOptions === void 0 ? [] : _ref2$sheetsOptions;
589
- return sheets.map(function (sheet) {
590
- var id = sheet.range.split('!')[0].replace(/'/g, '');
591
- var rows = sheet.values || [];
592
-
593
- if (rows.length > 0) {
594
- var _sheetsOptionsSheet$h;
595
-
596
- var sheetsOptionsSheet = sheetsOptions.find(function (sheet) {
597
- return sheet.id === id;
598
- });
599
- var headerRowIndex = (_sheetsOptionsSheet$h = sheetsOptionsSheet == null ? void 0 : sheetsOptionsSheet.headerRowIndex) != null ? _sheetsOptionsSheet$h : 0;
600
- var header = rows[headerRowIndex];
601
- var records = rows.filter(function (_, index) {
602
- return index > headerRowIndex;
603
- });
604
- var recordsData = mapRecords(records, header);
605
- return {
606
- id: id,
607
- data: recordsData
608
- };
609
- }
610
-
611
- return {
612
- id: id,
613
- data: []
614
- };
615
- });
616
- };
617
- var fetchBatchData = /*#__PURE__*/function () {
618
- var _ref4 = /*#__PURE__*/_asyncToGenerator( /*#__PURE__*/_regeneratorRuntime().mark(function _callee2(_ref3) {
619
- var apiKey, sheetId, _ref3$sheetsOptions, sheetsOptions, sheetsNames, url;
620
-
621
- return _regeneratorRuntime().wrap(function _callee2$(_context2) {
622
- while (1) {
623
- switch (_context2.prev = _context2.next) {
624
- case 0:
625
- apiKey = _ref3.apiKey, sheetId = _ref3.sheetId, _ref3$sheetsOptions = _ref3.sheetsOptions, sheetsOptions = _ref3$sheetsOptions === void 0 ? [] : _ref3$sheetsOptions;
626
- sheetsNames = sheetsOptions.map(function (option) {
627
- return option.id;
628
- });
629
- url = getBatchUrl(sheetId, sheetsNames, apiKey);
630
- _context2.next = 5;
631
- return makeFetch(url);
632
-
633
- case 5:
634
- return _context2.abrupt("return", _context2.sent);
635
-
636
- case 6:
637
- case "end":
638
- return _context2.stop();
639
- }
640
- }
641
- }, _callee2);
642
- }));
643
-
644
- return function fetchBatchData(_x3) {
645
- return _ref4.apply(this, arguments);
646
- };
647
- }();
648
- var fetchAllSheetsData = /*#__PURE__*/function () {
649
- var _ref6 = /*#__PURE__*/_asyncToGenerator( /*#__PURE__*/_regeneratorRuntime().mark(function _callee3(_ref5) {
650
- var apiKey, sheetId, urlTitles, _yield$makeFetch, sheets, sheetsOptions;
651
-
652
- return _regeneratorRuntime().wrap(function _callee3$(_context3) {
653
- while (1) {
654
- switch (_context3.prev = _context3.next) {
655
- case 0:
656
- apiKey = _ref5.apiKey, sheetId = _ref5.sheetId;
657
- urlTitles = getSheetsTitleUrl(sheetId, apiKey);
658
- _context3.next = 4;
659
- return makeFetch(urlTitles);
660
-
661
- case 4:
662
- _yield$makeFetch = _context3.sent;
663
- sheets = _yield$makeFetch.sheets;
664
- sheetsOptions = sheets.map(function (sheet) {
665
- return {
666
- id: sheet.properties.title
667
- };
668
- });
669
- _context3.next = 9;
670
- return fetchBatchData({
671
- apiKey: apiKey,
672
- sheetId: sheetId,
673
- sheetsOptions: sheetsOptions
674
- });
675
-
676
- case 9:
677
- return _context3.abrupt("return", _context3.sent);
678
-
679
- case 10:
680
- case "end":
681
- return _context3.stop();
682
- }
683
- }
684
- }, _callee3);
685
- }));
686
-
687
- return function fetchAllSheetsData(_x4) {
688
- return _ref6.apply(this, arguments);
689
- };
690
- }();
691
-
692
- var GoogleSheetsMapper = {
693
- fetchGoogleSheetsData: function fetchGoogleSheetsData(_ref) {
694
- return _asyncToGenerator( /*#__PURE__*/_regeneratorRuntime().mark(function _callee() {
695
- var apiKey, sheetId, _ref$sheetsOptions, sheetsOptions, response;
696
-
697
- return _regeneratorRuntime().wrap(function _callee$(_context) {
698
- while (1) {
699
- switch (_context.prev = _context.next) {
700
- case 0:
701
- apiKey = _ref.apiKey, sheetId = _ref.sheetId, _ref$sheetsOptions = _ref.sheetsOptions, sheetsOptions = _ref$sheetsOptions === void 0 ? [] : _ref$sheetsOptions;
702
- _context.prev = 1;
703
-
704
- if (!(sheetsOptions.length === 0)) {
705
- _context.next = 8;
706
- break;
707
- }
708
-
709
- _context.next = 5;
710
- return fetchAllSheetsData({
711
- apiKey: apiKey,
712
- sheetId: sheetId
713
- });
714
-
715
- case 5:
716
- _context.t0 = _context.sent;
717
- _context.next = 11;
718
- break;
719
-
720
- case 8:
721
- _context.next = 10;
722
- return fetchBatchData({
723
- apiKey: apiKey,
724
- sheetId: sheetId,
725
- sheetsOptions: sheetsOptions
726
- });
727
-
728
- case 10:
729
- _context.t0 = _context.sent;
730
-
731
- case 11:
732
- response = _context.t0;
733
- return _context.abrupt("return", mapData({
734
- sheets: response.valueRanges,
735
- sheetsOptions: sheetsOptions
736
- }));
737
-
738
- case 15:
739
- _context.prev = 15;
740
- _context.t1 = _context["catch"](1);
741
- throw _context.t1;
742
-
743
- case 18:
744
- case "end":
745
- return _context.stop();
746
- }
747
- }
748
- }, _callee, null, [[1, 15]]);
749
- }))();
750
- }
751
- };
752
- var fetchGoogleSheetsData = GoogleSheetsMapper.fetchGoogleSheetsData;
753
-
754
- export default GoogleSheetsMapper;
755
- export { fetchGoogleSheetsData };
756
- //# sourceMappingURL=google-sheets-mapper.esm.js.map