pinejs-client-fetch 1.0.1 → 1.0.2
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/build/index.d.ts +2 -1
- package/build/index.js +2 -2
- package/build/index.js.map +1 -1
- package/build/index.umd.js +117 -65
- package/package.json +20 -19
- package/CHANGELOG.md +0 -43
package/build/index.d.ts
CHANGED
|
@@ -1,4 +1,5 @@
|
|
|
1
|
-
import {
|
|
1
|
+
import type { Params, AnyObject } from 'pinejs-client-core';
|
|
2
|
+
import { PinejsClientCore } from 'pinejs-client-core';
|
|
2
3
|
export type { PinejsClientCore } from 'pinejs-client-core';
|
|
3
4
|
interface BackendParams {
|
|
4
5
|
fetch?: typeof fetch;
|
package/build/index.js
CHANGED
|
@@ -42,9 +42,9 @@ class PineFetch extends pinejs_client_core_1.PinejsClientCore {
|
|
|
42
42
|
}
|
|
43
43
|
}
|
|
44
44
|
_request(_a) {
|
|
45
|
-
var _b, _c;
|
|
46
|
-
var { url, body } = _a, options = __rest(_a, ["url", "body"]);
|
|
47
45
|
return __awaiter(this, void 0, void 0, function* () {
|
|
46
|
+
var _b, _c;
|
|
47
|
+
var { url, body } = _a, options = __rest(_a, ["url", "body"]);
|
|
48
48
|
const normalizedBody = body == null
|
|
49
49
|
? null
|
|
50
50
|
: typeof body === 'object'
|
package/build/index.js.map
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"index.js","sourceRoot":"","sources":["../src/index.ts"],"names":[],"mappings":";;;;;;;;;;;;;;;;;;;;;;;
|
|
1
|
+
{"version":3,"file":"index.js","sourceRoot":"","sources":["../src/index.ts"],"names":[],"mappings":";;;;;;;;;;;;;;;;;;;;;;;AACA,2DAAsD;AAQtD,MAAa,YAAa,SAAQ,KAAK;IAGtC,YACQ,IAAY,EACZ,MAAc,EACd,eAAuB;QAE9B,KAAK,CAAC,kBAAkB,IAAI,EAAE,CAAC,CAAC;QAJzB,SAAI,GAAJ,IAAI,CAAQ;QACZ,WAAM,GAAN,MAAM,CAAQ;QACd,oBAAe,GAAf,eAAe,CAAQ;QALxB,SAAI,GAAG,6BAA6B,CAAC;IAQ5C,CAAC;CACD;AAVD,oCAUC;AAED,MAAqB,SAAU,SAAQ,qCAA2B;IACjE,YACC,MAAc,EACP,aAA4B;QAEnC,KAAK,CAAC,MAAM,CAAC,CAAC;QAFP,kBAAa,GAAb,aAAa,CAAe;QAGnC,IACC,OAAO,CAAA,aAAa,aAAb,aAAa,uBAAb,aAAa,CAAE,KAAK,CAAA,KAAK,UAAU;YAC1C,OAAO,KAAK,KAAK,UAAU,EAC1B,CAAC;YACF,MAAM,IAAI,KAAK,CACd,+DAA+D,CAC/D,CAAC;QACH,CAAC;IACF,CAAC;IAEK,QAAQ,CAAC,EAOF;;;gBAPE,EACd,GAAG,EACH,IAAI,OAKQ,EAJT,OAAO,cAHI,eAId,CADU;YAKV,MAAM,cAAc,GACnB,IAAI,IAAI,IAAI;gBACX,CAAC,CAAC,IAAI;gBACN,CAAC,CAAC,OAAO,IAAI,KAAK,QAAQ;oBACzB,CAAC,CAAC,IAAI,CAAC,SAAS,CAAC,IAAI,CAAC;oBACtB,CAAC,CAAC,IAAI,CAAC;YAGV,MAAM,mBAAmB,GAAG,MAAA,MAAA,IAAI,CAAC,aAAa,0CAAE,KAAK,mCAAI,KAAK,CAAC;YAE/D,MAAM,QAAQ,GAAG,MAAM,mBAAmB,CAAC,GAAG,kCAC1C,OAAO,KACV,IAAI,EAAE,cAAc,IACnB,CAAC;YAEH,IAAI,QAAQ,CAAC,MAAM,IAAI,GAAG,EAAE,CAAC;gBAC5B,IAAI,YAAY,GAAG,eAAe,CAAC;gBACnC,IAAI,CAAC;oBACJ,YAAY,GAAG,MAAM,QAAQ,CAAC,IAAI,EAAE,CAAC;gBACtC,CAAC;gBAAC,WAAM,CAAC;gBAET,CAAC;gBACD,MAAM,IAAI,YAAY,CAAC,YAAY,EAAE,QAAQ,CAAC,MAAM,EAAE,QAAQ,CAAC,OAAO,CAAC,CAAC;YACzE,CAAC;YACD,OAAO,QAAQ,CAAC,IAAI,EAAE,CAAC;QACxB,CAAC;KAAA;CACD;AAlDD,4BAkDC"}
|
package/build/index.umd.js
CHANGED
|
@@ -37,6 +37,9 @@
|
|
|
37
37
|
};
|
|
38
38
|
Object.defineProperty(exports, "__esModule", { value: true });
|
|
39
39
|
exports.PinejsClientCore = void 0;
|
|
40
|
+
function isArray(value) {
|
|
41
|
+
return Array.isArray(value);
|
|
42
|
+
}
|
|
40
43
|
const noop = () => {
|
|
41
44
|
};
|
|
42
45
|
const deprecated = (() => {
|
|
@@ -62,7 +65,7 @@
|
|
|
62
65
|
const isString = (v) => typeof v === 'string';
|
|
63
66
|
const isBoolean = (v) => v === true || v === false;
|
|
64
67
|
const isDate = (v) => Object.prototype.toString.call(v) === '[object Date]';
|
|
65
|
-
const isObject = (v) =>
|
|
68
|
+
const isObject = (v) => v != null && typeof v === 'object';
|
|
66
69
|
const isValidOption = (key) => {
|
|
67
70
|
return (key === '$select' ||
|
|
68
71
|
key === '$filter' ||
|
|
@@ -80,6 +83,11 @@
|
|
|
80
83
|
$expand: '$expand: a: $count: ...',
|
|
81
84
|
$orderby: "$orderby: { a: { $count: ... }, $dir: 'asc' }",
|
|
82
85
|
};
|
|
86
|
+
const durationTimepartFlagEntries = [
|
|
87
|
+
['hours', 'H'],
|
|
88
|
+
['minutes', 'M'],
|
|
89
|
+
['seconds', 'S'],
|
|
90
|
+
];
|
|
83
91
|
class Poll {
|
|
84
92
|
constructor(requestFn, intervalTime = 10000) {
|
|
85
93
|
this.intervalTime = intervalTime;
|
|
@@ -140,7 +148,7 @@
|
|
|
140
148
|
}
|
|
141
149
|
start() {
|
|
142
150
|
this.stopped = false;
|
|
143
|
-
this.runRequest();
|
|
151
|
+
void this.runRequest();
|
|
144
152
|
}
|
|
145
153
|
stop() {
|
|
146
154
|
if (this.pollInterval) {
|
|
@@ -175,7 +183,7 @@
|
|
|
175
183
|
if (isString(resource)) {
|
|
176
184
|
resource = encodeURIComponent(resource);
|
|
177
185
|
}
|
|
178
|
-
else if (
|
|
186
|
+
else if (isArray(resource)) {
|
|
179
187
|
resource = resource.map(encodeURIComponent).join('/');
|
|
180
188
|
}
|
|
181
189
|
else {
|
|
@@ -208,7 +216,7 @@
|
|
|
208
216
|
if (isString(strOrArray)) {
|
|
209
217
|
return strOrArray;
|
|
210
218
|
}
|
|
211
|
-
else if (
|
|
219
|
+
else if (isArray(strOrArray)) {
|
|
212
220
|
return strOrArray.join(separator);
|
|
213
221
|
}
|
|
214
222
|
else {
|
|
@@ -237,7 +245,7 @@
|
|
|
237
245
|
};
|
|
238
246
|
const addParentKey = (filter, parentKey, operator = ' eq ') => {
|
|
239
247
|
if (parentKey != null) {
|
|
240
|
-
if (
|
|
248
|
+
if (isArray(filter)) {
|
|
241
249
|
if (filter.length === 1) {
|
|
242
250
|
filter = filter[0];
|
|
243
251
|
}
|
|
@@ -250,7 +258,7 @@
|
|
|
250
258
|
}
|
|
251
259
|
return [escapeResource(parentKey), operator, filter];
|
|
252
260
|
}
|
|
253
|
-
if (
|
|
261
|
+
if (isArray(filter)) {
|
|
254
262
|
return filter;
|
|
255
263
|
}
|
|
256
264
|
return [`${filter}`];
|
|
@@ -271,7 +279,7 @@
|
|
|
271
279
|
const filterStr = escapeValue(filter);
|
|
272
280
|
return addParentKey(filterStr, parentKey, op);
|
|
273
281
|
}
|
|
274
|
-
else if (
|
|
282
|
+
else if (isArray(filter)) {
|
|
275
283
|
const filterArr = handleFilterArray(filter);
|
|
276
284
|
const filterStr = bracketJoin(filterArr, op);
|
|
277
285
|
return addParentKey(filterStr, parentKey);
|
|
@@ -303,7 +311,7 @@
|
|
|
303
311
|
operands.push(escapeValue(filter));
|
|
304
312
|
return [`${fnName}(${operands.join()})`];
|
|
305
313
|
}
|
|
306
|
-
else if (
|
|
314
|
+
else if (isArray(filter)) {
|
|
307
315
|
const filterArr = handleFilterArray(filter);
|
|
308
316
|
let filterStr = filterArr.map((subArr) => subArr.join('')).join(',');
|
|
309
317
|
filterStr = `${fnName}(${filterStr})`;
|
|
@@ -363,15 +371,40 @@
|
|
|
363
371
|
case '$isof':
|
|
364
372
|
case '$cast':
|
|
365
373
|
return filterFunction(filter, operator, parentKey);
|
|
374
|
+
case '$duration': {
|
|
375
|
+
const durationValue = filter;
|
|
376
|
+
if (!isObject(durationValue)) {
|
|
377
|
+
throw new Error(`Expected type for ${operator}, got: ${typeof filter}`);
|
|
378
|
+
}
|
|
379
|
+
let durationString = 'P';
|
|
380
|
+
if (durationValue.days) {
|
|
381
|
+
durationString += `${durationValue.days}D`;
|
|
382
|
+
}
|
|
383
|
+
let timePart = '';
|
|
384
|
+
for (const [partKey, partFlag] of durationTimepartFlagEntries) {
|
|
385
|
+
if (durationValue[partKey]) {
|
|
386
|
+
timePart += `${durationValue[partKey]}${partFlag}`;
|
|
387
|
+
}
|
|
388
|
+
}
|
|
389
|
+
if (timePart.length > 0) {
|
|
390
|
+
durationString += `T${timePart}`;
|
|
391
|
+
}
|
|
392
|
+
if (durationString.length <= 1) {
|
|
393
|
+
throw new Error(`Expected ${operator} to include duration properties, got: ${typeof filter}`);
|
|
394
|
+
}
|
|
395
|
+
if (durationValue.negative) {
|
|
396
|
+
durationString = `-${durationString}`;
|
|
397
|
+
}
|
|
398
|
+
return addParentKey(`duration'${durationString}'`, parentKey);
|
|
399
|
+
}
|
|
366
400
|
case '$raw': {
|
|
367
|
-
|
|
368
|
-
if (isString(
|
|
369
|
-
|
|
370
|
-
return addParentKey(filter, parentKey);
|
|
401
|
+
const filterx = filter;
|
|
402
|
+
if (isString(filterx)) {
|
|
403
|
+
return addParentKey(`(${filterx})`, parentKey);
|
|
371
404
|
}
|
|
372
|
-
else if (!isPrimitive(
|
|
373
|
-
if (Array.isArray(
|
|
374
|
-
const [rawFilter, ...params] =
|
|
405
|
+
else if (!isPrimitive(filterx)) {
|
|
406
|
+
if (Array.isArray(filterx)) {
|
|
407
|
+
const [rawFilter, ...params] = filterx;
|
|
375
408
|
if (!isString(rawFilter)) {
|
|
376
409
|
throw new Error(`First element of array for ${operator} must be a string, got: ${typeof rawFilter}`);
|
|
377
410
|
}
|
|
@@ -381,24 +414,24 @@
|
|
|
381
414
|
}
|
|
382
415
|
return applyBinds(rawFilter, mappedParams, parentKey);
|
|
383
416
|
}
|
|
384
|
-
else if (isObject(
|
|
385
|
-
const filterStr =
|
|
417
|
+
else if (isObject(filterx)) {
|
|
418
|
+
const filterStr = filterx.$string;
|
|
386
419
|
if (!isString(filterStr)) {
|
|
387
420
|
throw new Error(`$string element of object for ${operator} must be a string, got: ${typeof filterStr}`);
|
|
388
421
|
}
|
|
389
422
|
const mappedParams = {};
|
|
390
|
-
for (const index in
|
|
423
|
+
for (const index in filterx) {
|
|
391
424
|
if (index !== '$string') {
|
|
392
425
|
if (!/^[a-zA-Z0-9]+$/.test(index)) {
|
|
393
426
|
throw new Error(`${operator} param names must contain only [a-zA-Z0-9], got: ${index}`);
|
|
394
427
|
}
|
|
395
|
-
mappedParams[index] =
|
|
428
|
+
mappedParams[index] = filterx[index];
|
|
396
429
|
}
|
|
397
430
|
}
|
|
398
431
|
return applyBinds(filterStr, mappedParams, parentKey);
|
|
399
432
|
}
|
|
400
433
|
}
|
|
401
|
-
throw new Error(`Expected string/array/object for ${operator}, got: ${typeof
|
|
434
|
+
throw new Error(`Expected string/array/object for ${operator}, got: ${typeof filterx}`);
|
|
402
435
|
}
|
|
403
436
|
case '$': {
|
|
404
437
|
const resource = escapeResource(filter);
|
|
@@ -408,7 +441,8 @@
|
|
|
408
441
|
let keys = ['$count'];
|
|
409
442
|
if (parentKey != null &&
|
|
410
443
|
isObject(filter) &&
|
|
411
|
-
(Object.keys(filter).length === 0 ||
|
|
444
|
+
(Object.keys(filter).length === 0 ||
|
|
445
|
+
Object.prototype.hasOwnProperty.call(filter, '$filter'))) {
|
|
412
446
|
keys = parentKey.slice(0, parentKey.length - 1);
|
|
413
447
|
keys.push(handleOptions('$filter', { $count: filter }, parentKey[parentKey.length - 1]));
|
|
414
448
|
return [keys.join('/')];
|
|
@@ -430,7 +464,7 @@
|
|
|
430
464
|
const filterStr = escapeValue(filter);
|
|
431
465
|
return addParentKey(filterStr, parentKey, ' eq ');
|
|
432
466
|
}
|
|
433
|
-
else if (
|
|
467
|
+
else if (isArray(filter)) {
|
|
434
468
|
if (filter.every(isPrimitive)) {
|
|
435
469
|
const filterStr = handleFilterArray(filter, undefined, 1);
|
|
436
470
|
const inStr = bracketJoin(filterStr, ', ').join('');
|
|
@@ -519,7 +553,7 @@
|
|
|
519
553
|
const filterStr = escapeValue(filter);
|
|
520
554
|
return addParentKey(filterStr, parentKey);
|
|
521
555
|
}
|
|
522
|
-
else if (
|
|
556
|
+
else if (isArray(filter)) {
|
|
523
557
|
const filterArr = handleFilterArray(filter);
|
|
524
558
|
const filterStr = bracketJoin(filterArr, joinStr !== null && joinStr !== void 0 ? joinStr : ' or ');
|
|
525
559
|
return addParentKey(filterStr, parentKey);
|
|
@@ -539,12 +573,12 @@
|
|
|
539
573
|
}
|
|
540
574
|
return orderby;
|
|
541
575
|
}
|
|
542
|
-
else if (
|
|
576
|
+
else if (isArray(orderby)) {
|
|
543
577
|
if (orderby.length === 0) {
|
|
544
578
|
throw new Error(`'$orderby' arrays have to have at least 1 element`);
|
|
545
579
|
}
|
|
546
580
|
const result = orderby.map((value) => {
|
|
547
|
-
if (
|
|
581
|
+
if (isArray(value)) {
|
|
548
582
|
throw new Error(`'$orderby' cannot have nested arrays`);
|
|
549
583
|
}
|
|
550
584
|
return buildOrderBy(value);
|
|
@@ -552,8 +586,7 @@
|
|
|
552
586
|
return join(result);
|
|
553
587
|
}
|
|
554
588
|
else if (isObject(orderby)) {
|
|
555
|
-
const { $dir } =
|
|
556
|
-
const $orderby = restOrderby;
|
|
589
|
+
const _a = orderby, { $dir } = _a, $orderby = __rest(_a, ["$dir"]);
|
|
557
590
|
const result = mapObj($orderby, (dirOrOptions, key) => {
|
|
558
591
|
let propertyPath = key;
|
|
559
592
|
let dir = $dir;
|
|
@@ -562,7 +595,8 @@
|
|
|
562
595
|
}
|
|
563
596
|
else {
|
|
564
597
|
const keys = Object.keys(dirOrOptions);
|
|
565
|
-
if (!
|
|
598
|
+
if (!Object.prototype.hasOwnProperty.call(dirOrOptions, '$count') ||
|
|
599
|
+
keys.length > 1) {
|
|
566
600
|
throw new Error(`When using '${ODataOptionCodeExampleMap['$orderby']}' you can only specify $count, got: '${JSON.stringify(keys)}'`);
|
|
567
601
|
}
|
|
568
602
|
propertyPath = handleOptions('$orderby', dirOrOptions, propertyPath);
|
|
@@ -597,19 +631,20 @@
|
|
|
597
631
|
compiledValue = buildOrderBy(value);
|
|
598
632
|
break;
|
|
599
633
|
case '$top':
|
|
600
|
-
case '$skip':
|
|
634
|
+
case '$skip': {
|
|
601
635
|
const num = value;
|
|
602
636
|
if (!NumberIsFinite(num)) {
|
|
603
637
|
throw new Error(`'${option}' option has to be a number`);
|
|
604
638
|
}
|
|
605
639
|
compiledValue = '' + num;
|
|
606
640
|
break;
|
|
607
|
-
|
|
641
|
+
}
|
|
642
|
+
case '$select': {
|
|
608
643
|
const select = value;
|
|
609
644
|
if (isString(select)) {
|
|
610
645
|
compiledValue = join(select);
|
|
611
646
|
}
|
|
612
|
-
else if (
|
|
647
|
+
else if (isArray(select)) {
|
|
613
648
|
if (select.length === 0) {
|
|
614
649
|
throw new Error(`'${option}' arrays have to have at least 1 element`);
|
|
615
650
|
}
|
|
@@ -619,6 +654,7 @@
|
|
|
619
654
|
throw new Error(`'${option}' option has to be either a string or array`);
|
|
620
655
|
}
|
|
621
656
|
break;
|
|
657
|
+
}
|
|
622
658
|
default:
|
|
623
659
|
if (option[0] === '@') {
|
|
624
660
|
if (!isPrimitive(value)) {
|
|
@@ -626,7 +662,7 @@
|
|
|
626
662
|
}
|
|
627
663
|
compiledValue = '' + escapeValue(value);
|
|
628
664
|
}
|
|
629
|
-
else if (
|
|
665
|
+
else if (isArray(value)) {
|
|
630
666
|
compiledValue = join(value);
|
|
631
667
|
}
|
|
632
668
|
else if (isString(value)) {
|
|
@@ -642,14 +678,15 @@
|
|
|
642
678
|
return `${option}=${compiledValue}`;
|
|
643
679
|
};
|
|
644
680
|
const handleOptions = (optionOperation, options, parentKey) => {
|
|
645
|
-
if (
|
|
681
|
+
if (Object.prototype.hasOwnProperty.call(options, '$count')) {
|
|
646
682
|
const keys = Object.keys(options);
|
|
647
683
|
if (keys.length > 1) {
|
|
648
684
|
throw new Error(`When using '${ODataOptionCodeExampleMap[optionOperation]}' you can only specify $count, got: '${JSON.stringify(keys)}'`);
|
|
649
685
|
}
|
|
650
686
|
options = options.$count;
|
|
651
687
|
parentKey += '/$count';
|
|
652
|
-
if (Object.keys(options).length >
|
|
688
|
+
if (Object.keys(options).length >
|
|
689
|
+
(Object.prototype.hasOwnProperty.call(options, '$filter') ? 1 : 0)) {
|
|
653
690
|
if (optionOperation === '$expand') {
|
|
654
691
|
deprecated.non$filterOptionIn$expand$count();
|
|
655
692
|
}
|
|
@@ -686,7 +723,7 @@
|
|
|
686
723
|
const jsonValue = JSON.stringify(value);
|
|
687
724
|
throw new Error(`'$expand: ${key}: ${jsonValue}' is invalid, use '$expand: ${key}: $expand: ${jsonValue}' instead.`);
|
|
688
725
|
}
|
|
689
|
-
if (
|
|
726
|
+
if (isArray(value)) {
|
|
690
727
|
throw new Error(`'$expand: ${key}: [...]' is invalid, use '$expand: ${key}: {...}' instead.`);
|
|
691
728
|
}
|
|
692
729
|
if (key.endsWith('/$count')) {
|
|
@@ -708,7 +745,7 @@
|
|
|
708
745
|
if (isPrimitive(expand)) {
|
|
709
746
|
return escapeResource(expand);
|
|
710
747
|
}
|
|
711
|
-
else if (
|
|
748
|
+
else if (isArray(expand)) {
|
|
712
749
|
const expandStr = handleExpandArray(expand);
|
|
713
750
|
return join(expandStr);
|
|
714
751
|
}
|
|
@@ -720,6 +757,17 @@
|
|
|
720
757
|
throw new Error(`Unknown type for expand '${typeof expand}'`);
|
|
721
758
|
}
|
|
722
759
|
};
|
|
760
|
+
const getRetryAfterHeaderDelayMs = (getRetryAfterHeader, err) => {
|
|
761
|
+
const retryAfterRaw = getRetryAfterHeader === null || getRetryAfterHeader === void 0 ? void 0 : getRetryAfterHeader(err);
|
|
762
|
+
if (typeof retryAfterRaw !== 'string') {
|
|
763
|
+
return;
|
|
764
|
+
}
|
|
765
|
+
const retryAfterSeconds = parseInt(retryAfterRaw, 10);
|
|
766
|
+
if (!Number.isInteger(retryAfterSeconds) || retryAfterSeconds < 0) {
|
|
767
|
+
return;
|
|
768
|
+
}
|
|
769
|
+
return retryAfterSeconds * 1000;
|
|
770
|
+
};
|
|
723
771
|
const validParams = [
|
|
724
772
|
'apiPrefix',
|
|
725
773
|
'passthrough',
|
|
@@ -749,8 +797,8 @@
|
|
|
749
797
|
return code == null || code === 429 || (code >= 500 && code < 600);
|
|
750
798
|
}
|
|
751
799
|
callWithRetry(fnCall, retry) {
|
|
752
|
-
var _a, _b, _c, _d, _e, _f;
|
|
753
800
|
return __awaiter(this, void 0, void 0, function* () {
|
|
801
|
+
var _a, _b, _c, _d, _e, _f, _g;
|
|
754
802
|
if (retry === false || (retry == null && this.retry === false)) {
|
|
755
803
|
return yield fnCall();
|
|
756
804
|
}
|
|
@@ -772,8 +820,9 @@
|
|
|
772
820
|
throw new Error('pinejs-client maxDelayMs must be greater than or equal to minDelayMs');
|
|
773
821
|
}
|
|
774
822
|
const onRetryHandler = (_d = retryParameters.onRetry) !== null && _d !== void 0 ? _d : retryDefaultParameters.onRetry;
|
|
823
|
+
const getRetryAfterHeader = (_e = retryParameters.getRetryAfterHeader) !== null && _e !== void 0 ? _e : retryDefaultParameters.getRetryAfterHeader;
|
|
775
824
|
let attempt = 1;
|
|
776
|
-
const canRetryHandler = (
|
|
825
|
+
const canRetryHandler = (_g = (_f = retryParameters.canRetry) !== null && _f !== void 0 ? _f : retryDefaultParameters.canRetry) !== null && _g !== void 0 ? _g : this.canRetryDefaultHandler;
|
|
777
826
|
while (true) {
|
|
778
827
|
try {
|
|
779
828
|
return yield fnCall();
|
|
@@ -782,8 +831,12 @@
|
|
|
782
831
|
if (attempt >= maxAttempts || !canRetryHandler(err)) {
|
|
783
832
|
throw err;
|
|
784
833
|
}
|
|
785
|
-
|
|
834
|
+
let delayMs = Math.min(Math.pow(2, (attempt - 1)) * minDelayMs, maxDelayMs);
|
|
786
835
|
attempt++;
|
|
836
|
+
const retryAfterDelayMs = getRetryAfterHeaderDelayMs(getRetryAfterHeader, err);
|
|
837
|
+
if (retryAfterDelayMs != null && retryAfterDelayMs > delayMs) {
|
|
838
|
+
delayMs = retryAfterDelayMs;
|
|
839
|
+
}
|
|
787
840
|
onRetryHandler === null || onRetryHandler === void 0 ? void 0 : onRetryHandler(err, delayMs, attempt, maxAttempts);
|
|
788
841
|
yield new Promise((resolve) => {
|
|
789
842
|
setTimeout(resolve, delayMs);
|
|
@@ -822,26 +875,26 @@
|
|
|
822
875
|
throw new Error('`get(url)` is no longer supported, please use `get({ url })` instead.');
|
|
823
876
|
}
|
|
824
877
|
const result = yield this.request(Object.assign(Object.assign({}, params), { method: 'GET' }));
|
|
825
|
-
return this.
|
|
878
|
+
return this._transformGetResult(params, result);
|
|
826
879
|
});
|
|
827
880
|
}
|
|
828
|
-
|
|
829
|
-
|
|
830
|
-
|
|
831
|
-
|
|
832
|
-
|
|
833
|
-
|
|
834
|
-
|
|
835
|
-
|
|
836
|
-
|
|
837
|
-
|
|
838
|
-
if (data.d.length > 1) {
|
|
839
|
-
throw new Error('Returned multiple results when only one was expected.');
|
|
840
|
-
}
|
|
841
|
-
return data.d[0];
|
|
881
|
+
_transformGetResult(params, data) {
|
|
882
|
+
if (!isObject(data)) {
|
|
883
|
+
throw new Error(`Response was not a JSON object: '${typeof data}'`);
|
|
884
|
+
}
|
|
885
|
+
if (data.d == null) {
|
|
886
|
+
throw new Error("Invalid response received, the 'd' property is missing.");
|
|
887
|
+
}
|
|
888
|
+
if (params.id != null) {
|
|
889
|
+
if (data.d.length > 1) {
|
|
890
|
+
throw new Error('Returned multiple results when only one was expected.');
|
|
842
891
|
}
|
|
843
|
-
return data.d;
|
|
844
|
-
}
|
|
892
|
+
return data.d[0];
|
|
893
|
+
}
|
|
894
|
+
return data.d;
|
|
895
|
+
}
|
|
896
|
+
transformGetResult(params) {
|
|
897
|
+
return (data) => this._transformGetResult(params, data);
|
|
845
898
|
}
|
|
846
899
|
subscribe(params) {
|
|
847
900
|
if (isString(params)) {
|
|
@@ -936,9 +989,7 @@
|
|
|
936
989
|
else {
|
|
937
990
|
params.method = params.method.toUpperCase();
|
|
938
991
|
}
|
|
939
|
-
const { body: defaultBody } = params;
|
|
940
|
-
const { passthrough: defaultPassthrough } = params;
|
|
941
|
-
const transformFn = params.method === 'GET' ? this.transformGetResult(params) : undefined;
|
|
992
|
+
const { body: defaultBody, passthrough: defaultPassthrough } = params;
|
|
942
993
|
return (parameterAliases, body, passthrough) => __awaiter(this, void 0, void 0, function* () {
|
|
943
994
|
if (body != null) {
|
|
944
995
|
params.body = Object.assign(Object.assign({}, defaultBody), body);
|
|
@@ -967,8 +1018,8 @@
|
|
|
967
1018
|
params.url = compiledUrl;
|
|
968
1019
|
}
|
|
969
1020
|
const result = yield this.request(params);
|
|
970
|
-
if (
|
|
971
|
-
return
|
|
1021
|
+
if (params.method === 'GET') {
|
|
1022
|
+
return this._transformGetResult(params, result);
|
|
972
1023
|
}
|
|
973
1024
|
return result;
|
|
974
1025
|
});
|
|
@@ -989,7 +1040,8 @@
|
|
|
989
1040
|
}
|
|
990
1041
|
let url = escapeResource(params.resource);
|
|
991
1042
|
let { options } = params;
|
|
992
|
-
if (options
|
|
1043
|
+
if (options != null &&
|
|
1044
|
+
Object.prototype.hasOwnProperty.call(options, '$count')) {
|
|
993
1045
|
const keys = Object.keys(options);
|
|
994
1046
|
if (keys.length > 1) {
|
|
995
1047
|
throw new Error(`When using '$expand: a: $count: ...' you can only specify $count, got: '${JSON.stringify(keys)}'`);
|
|
@@ -997,7 +1049,7 @@
|
|
|
997
1049
|
url += '/$count';
|
|
998
1050
|
options = options.$count;
|
|
999
1051
|
}
|
|
1000
|
-
if (
|
|
1052
|
+
if (Object.prototype.hasOwnProperty.call(params, 'id')) {
|
|
1001
1053
|
const { id } = params;
|
|
1002
1054
|
if (id == null) {
|
|
1003
1055
|
throw new Error('If the id property is set it must be non-null');
|
|
@@ -1110,9 +1162,9 @@
|
|
|
1110
1162
|
}
|
|
1111
1163
|
}
|
|
1112
1164
|
_request(_a) {
|
|
1113
|
-
var _b, _c;
|
|
1114
|
-
var { url, body } = _a, options = __rest(_a, ["url", "body"]);
|
|
1115
1165
|
return __awaiter(this, void 0, void 0, function* () {
|
|
1166
|
+
var _b, _c;
|
|
1167
|
+
var { url, body } = _a, options = __rest(_a, ["url", "body"]);
|
|
1116
1168
|
const normalizedBody = body == null
|
|
1117
1169
|
? null
|
|
1118
1170
|
: typeof body === 'object'
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "pinejs-client-fetch",
|
|
3
|
-
"version": "1.0.
|
|
3
|
+
"version": "1.0.2",
|
|
4
4
|
"description": "This module provides the nodejs interface for the pinejs API using request.",
|
|
5
5
|
"main": "build/index.js",
|
|
6
6
|
"browser": "build/index.umd.js",
|
|
@@ -29,36 +29,37 @@
|
|
|
29
29
|
},
|
|
30
30
|
"scripts": {
|
|
31
31
|
"build": "tsc && rollup -c",
|
|
32
|
-
"lint": "balena-lint
|
|
33
|
-
"lint-fix": "balena-lint
|
|
32
|
+
"lint": "balena-lint -t tsconfig.dev.json src tests",
|
|
33
|
+
"lint-fix": "balena-lint -t tsconfig.dev.json --fix src tests",
|
|
34
34
|
"test:node": "mocha -r ts-node/register --reporter spec tests/**/*.spec.ts",
|
|
35
35
|
"test:browser": "karma start",
|
|
36
36
|
"test": "npm run build && npm run test:node && npm run test:browser && npm run lint",
|
|
37
|
-
"prepack": "npm run build"
|
|
37
|
+
"prepack": "npm run build",
|
|
38
|
+
"prepare": "node -e \"try { (await import('husky')).default() } catch (e) { if (e.code !== 'ERR_MODULE_NOT_FOUND') throw e }\" --input-type module"
|
|
38
39
|
},
|
|
39
40
|
"devDependencies": {
|
|
40
|
-
"@balena/lint": "^
|
|
41
|
+
"@balena/lint": "^8.0.2",
|
|
41
42
|
"@rollup/plugin-commonjs": "^11.1.0",
|
|
42
43
|
"@rollup/plugin-node-resolve": "^7.1.3",
|
|
43
|
-
"@types/chai": "^4.3.
|
|
44
|
-
"@types/chai-as-promised": "^7.1.
|
|
44
|
+
"@types/chai": "^4.3.16",
|
|
45
|
+
"@types/chai-as-promised": "^7.1.8",
|
|
45
46
|
"@types/mocha": "^9.1.1",
|
|
46
|
-
"balena-config-karma": "^4.0.
|
|
47
|
-
"chai": "^4.
|
|
48
|
-
"chai-as-promised": "^7.1.
|
|
47
|
+
"balena-config-karma": "^4.0.2",
|
|
48
|
+
"chai": "^4.4.1",
|
|
49
|
+
"chai-as-promised": "^7.1.2",
|
|
49
50
|
"fetch-ponyfill": "^7.1.0",
|
|
50
|
-
"husky": "^
|
|
51
|
-
"karma": "^5.
|
|
52
|
-
"lint-staged": "^
|
|
53
|
-
"mocha": "^10.
|
|
54
|
-
"rollup": "^2.
|
|
55
|
-
"ts-node": "^10.9.
|
|
56
|
-
"typescript": "^4.
|
|
51
|
+
"husky": "^9.0.11",
|
|
52
|
+
"karma": "^5.2.3",
|
|
53
|
+
"lint-staged": "^15.2.5",
|
|
54
|
+
"mocha": "^10.4.0",
|
|
55
|
+
"rollup": "^2.79.1",
|
|
56
|
+
"ts-node": "^10.9.2",
|
|
57
|
+
"typescript": "^5.4.5"
|
|
57
58
|
},
|
|
58
59
|
"dependencies": {
|
|
59
|
-
"pinejs-client-core": "^6.
|
|
60
|
+
"pinejs-client-core": "^6.14.7"
|
|
60
61
|
},
|
|
61
62
|
"versionist": {
|
|
62
|
-
"publishedAt": "
|
|
63
|
+
"publishedAt": "2024-06-06T15:44:29.125Z"
|
|
63
64
|
}
|
|
64
65
|
}
|
package/CHANGELOG.md
DELETED
|
@@ -1,43 +0,0 @@
|
|
|
1
|
-
# Change Log
|
|
2
|
-
|
|
3
|
-
All notable changes to this project will be documented in this file
|
|
4
|
-
automatically by Versionist. DO NOT EDIT THIS FILE MANUALLY!
|
|
5
|
-
This project adheres to [Semantic Versioning](http://semver.org/).
|
|
6
|
-
|
|
7
|
-
## 1.0.1 - 2023-01-19
|
|
8
|
-
|
|
9
|
-
* Flowzone: use inherited secrets [Page-]
|
|
10
|
-
|
|
11
|
-
## 1.0.0 - 2023-01-19
|
|
12
|
-
|
|
13
|
-
* Update to pinejs-client-core 6.x [Pagan Gazzard]
|
|
14
|
-
|
|
15
|
-
## 0.3.1 - 2022-09-26
|
|
16
|
-
|
|
17
|
-
* Delete redundant .resinci.yml [Thodoris Greasidis]
|
|
18
|
-
|
|
19
|
-
## 0.3.0 - 2022-09-22
|
|
20
|
-
|
|
21
|
-
* Replace balenaCI with flowzone [Thodoris Greasidis]
|
|
22
|
-
* Specify node 12 as the minimum supported node engine in the package.json [Thodoris Greasidis]
|
|
23
|
-
|
|
24
|
-
# v0.2.2
|
|
25
|
-
## (2021-06-30)
|
|
26
|
-
|
|
27
|
-
* Delete CODEOWNERS [Thodoris Greasidis]
|
|
28
|
-
|
|
29
|
-
# v0.2.1
|
|
30
|
-
## (2020-06-02)
|
|
31
|
-
|
|
32
|
-
* Test on browser using the umd build [Thodoris Greasidis]
|
|
33
|
-
* Fix the umd build for the latest pinejs client [Thodoris Greasidis]
|
|
34
|
-
|
|
35
|
-
# v0.2.0
|
|
36
|
-
## (2020-06-02)
|
|
37
|
-
|
|
38
|
-
* Add test cases [Thodoris Greasidis]
|
|
39
|
-
* Initial code commit [Thodoris Greasidis]
|
|
40
|
-
|
|
41
|
-
## v0.1.0 - 2020-05-14
|
|
42
|
-
|
|
43
|
-
* Initialize repository
|