@bytescale/sdk 1.5.0 → 3.0.0-alpha.10
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/README.md +377 -38
- package/dist/browser/cjs/main.js +458 -380
- package/dist/node/cjs/main.js +446 -99
- package/dist/node/esm/main.mjs +448 -101
- package/dist/types/private/AuthSessionState.d.ts +25 -8
- package/dist/types/public/browser/AuthManagerBrowser.d.ts +1 -0
- package/dist/types/public/shared/UrlBuilder.d.ts +1 -0
- package/dist/types/public/shared/UrlBuilderTypes.d.ts +65 -65
- package/dist/types/public/shared/generated/apis/FileApi.d.ts +104 -3
- package/dist/types/public/shared/generated/apis/FolderApi.d.ts +0 -3
- package/dist/types/public/shared/generated/apis/JobApi.d.ts +0 -3
- package/dist/types/public/shared/generated/apis/UploadApi.d.ts +6 -3
- package/dist/types/public/shared/generated/models/index.d.ts +5 -7
- package/dist/types/public/shared/generated/runtime.d.ts +8 -6
- package/package.json +2 -6
- package/tests/UrlBuilder.test.ts +31 -36
package/dist/node/cjs/main.js
CHANGED
|
@@ -64,7 +64,7 @@ __lib_require__.d(__lib_exports__, {
|
|
|
64
64
|
"AuthManager": function() { return /* reexport */ AuthManager; },
|
|
65
65
|
"BaseAPI": function() { return /* reexport */ BaseAPI; },
|
|
66
66
|
"BinaryResult": function() { return /* reexport */ BinaryResult; },
|
|
67
|
-
"
|
|
67
|
+
"BytescaleApiClientConfigUtils": function() { return /* reexport */ BytescaleApiClientConfigUtils; },
|
|
68
68
|
"BytescaleApiError": function() { return /* reexport */ BytescaleApiError; },
|
|
69
69
|
"CancelledError": function() { return /* reexport */ CancelledError; },
|
|
70
70
|
"CommonTypesNoOp": function() { return /* reexport */ CommonTypesNoOp; },
|
|
@@ -80,16 +80,332 @@ __lib_require__.d(__lib_exports__, {
|
|
|
80
80
|
"querystring": function() { return /* reexport */ querystring; }
|
|
81
81
|
});
|
|
82
82
|
|
|
83
|
-
;// CONCATENATED MODULE: ./src/private/
|
|
83
|
+
;// CONCATENATED MODULE: ./src/private/Mutex.ts
|
|
84
84
|
function _typeof(obj) { "@babel/helpers - typeof"; return _typeof = "function" == typeof Symbol && "symbol" == typeof Symbol.iterator ? function (obj) { return typeof obj; } : function (obj) { return obj && "function" == typeof Symbol && obj.constructor === Symbol && obj !== Symbol.prototype ? "symbol" : typeof obj; }, _typeof(obj); }
|
|
85
|
+
function _call(body, then, direct) {
|
|
86
|
+
if (direct) {
|
|
87
|
+
return then ? then(body()) : body();
|
|
88
|
+
}
|
|
89
|
+
try {
|
|
90
|
+
var result = Promise.resolve(body());
|
|
91
|
+
return then ? result.then(then) : result;
|
|
92
|
+
} catch (e) {
|
|
93
|
+
return Promise.reject(e);
|
|
94
|
+
}
|
|
95
|
+
}
|
|
96
|
+
function _rethrow(thrown, value) {
|
|
97
|
+
if (thrown) throw value;
|
|
98
|
+
return value;
|
|
99
|
+
}
|
|
100
|
+
function _finallyRethrows(body, finalizer) {
|
|
101
|
+
try {
|
|
102
|
+
var result = body();
|
|
103
|
+
} catch (e) {
|
|
104
|
+
return finalizer(true, e);
|
|
105
|
+
}
|
|
106
|
+
if (result && result.then) {
|
|
107
|
+
return result.then(finalizer.bind(null, false), finalizer.bind(null, true));
|
|
108
|
+
}
|
|
109
|
+
return finalizer(false, result);
|
|
110
|
+
}
|
|
111
|
+
function _await(value, then, direct) {
|
|
112
|
+
if (direct) {
|
|
113
|
+
return then ? then(value) : value;
|
|
114
|
+
}
|
|
115
|
+
if (!value || !value.then) {
|
|
116
|
+
value = Promise.resolve(value);
|
|
117
|
+
}
|
|
118
|
+
return then ? value.then(then) : value;
|
|
119
|
+
}
|
|
120
|
+
function _empty() {}
|
|
121
|
+
function _awaitIgnored(value, direct) {
|
|
122
|
+
if (!direct) {
|
|
123
|
+
return value && value.then ? value.then(_empty) : Promise.resolve();
|
|
124
|
+
}
|
|
125
|
+
}
|
|
126
|
+
function _settle(pact, state, value) {
|
|
127
|
+
if (!pact.s) {
|
|
128
|
+
if (value instanceof _Pact) {
|
|
129
|
+
if (value.s) {
|
|
130
|
+
if (state & 1) {
|
|
131
|
+
state = value.s;
|
|
132
|
+
}
|
|
133
|
+
value = value.v;
|
|
134
|
+
} else {
|
|
135
|
+
value.o = _settle.bind(null, pact, state);
|
|
136
|
+
return;
|
|
137
|
+
}
|
|
138
|
+
}
|
|
139
|
+
if (value && value.then) {
|
|
140
|
+
value.then(_settle.bind(null, pact, state), _settle.bind(null, pact, 2));
|
|
141
|
+
return;
|
|
142
|
+
}
|
|
143
|
+
pact.s = state;
|
|
144
|
+
pact.v = value;
|
|
145
|
+
var observer = pact.o;
|
|
146
|
+
if (observer) {
|
|
147
|
+
observer(pact);
|
|
148
|
+
}
|
|
149
|
+
}
|
|
150
|
+
}
|
|
151
|
+
var _Pact = /*#__PURE__*/function () {
|
|
152
|
+
function _Pact() {}
|
|
153
|
+
_Pact.prototype.then = function (onFulfilled, onRejected) {
|
|
154
|
+
var result = new _Pact();
|
|
155
|
+
var state = this.s;
|
|
156
|
+
if (state) {
|
|
157
|
+
var callback = state & 1 ? onFulfilled : onRejected;
|
|
158
|
+
if (callback) {
|
|
159
|
+
try {
|
|
160
|
+
_settle(result, 1, callback(this.v));
|
|
161
|
+
} catch (e) {
|
|
162
|
+
_settle(result, 2, e);
|
|
163
|
+
}
|
|
164
|
+
return result;
|
|
165
|
+
} else {
|
|
166
|
+
return this;
|
|
167
|
+
}
|
|
168
|
+
}
|
|
169
|
+
this.o = function (_this) {
|
|
170
|
+
try {
|
|
171
|
+
var value = _this.v;
|
|
172
|
+
if (_this.s & 1) {
|
|
173
|
+
_settle(result, 1, onFulfilled ? onFulfilled(value) : value);
|
|
174
|
+
} else if (onRejected) {
|
|
175
|
+
_settle(result, 1, onRejected(value));
|
|
176
|
+
} else {
|
|
177
|
+
_settle(result, 2, value);
|
|
178
|
+
}
|
|
179
|
+
} catch (e) {
|
|
180
|
+
_settle(result, 2, e);
|
|
181
|
+
}
|
|
182
|
+
};
|
|
183
|
+
return result;
|
|
184
|
+
};
|
|
185
|
+
return _Pact;
|
|
186
|
+
}();
|
|
187
|
+
function _isSettledPact(thenable) {
|
|
188
|
+
return thenable instanceof _Pact && thenable.s & 1;
|
|
189
|
+
}
|
|
190
|
+
function _for(test, update, body) {
|
|
191
|
+
var stage;
|
|
192
|
+
for (;;) {
|
|
193
|
+
var shouldContinue = test();
|
|
194
|
+
if (_isSettledPact(shouldContinue)) {
|
|
195
|
+
shouldContinue = shouldContinue.v;
|
|
196
|
+
}
|
|
197
|
+
if (!shouldContinue) {
|
|
198
|
+
return result;
|
|
199
|
+
}
|
|
200
|
+
if (shouldContinue.then) {
|
|
201
|
+
stage = 0;
|
|
202
|
+
break;
|
|
203
|
+
}
|
|
204
|
+
var result = body();
|
|
205
|
+
if (result && result.then) {
|
|
206
|
+
if (_isSettledPact(result)) {
|
|
207
|
+
result = result.s;
|
|
208
|
+
} else {
|
|
209
|
+
stage = 1;
|
|
210
|
+
break;
|
|
211
|
+
}
|
|
212
|
+
}
|
|
213
|
+
if (update) {
|
|
214
|
+
var updateValue = update();
|
|
215
|
+
if (updateValue && updateValue.then && !_isSettledPact(updateValue)) {
|
|
216
|
+
stage = 2;
|
|
217
|
+
break;
|
|
218
|
+
}
|
|
219
|
+
}
|
|
220
|
+
}
|
|
221
|
+
var pact = new _Pact();
|
|
222
|
+
var reject = _settle.bind(null, pact, 2);
|
|
223
|
+
(stage === 0 ? shouldContinue.then(_resumeAfterTest) : stage === 1 ? result.then(_resumeAfterBody) : updateValue.then(_resumeAfterUpdate)).then(void 0, reject);
|
|
224
|
+
return pact;
|
|
225
|
+
function _resumeAfterBody(value) {
|
|
226
|
+
result = value;
|
|
227
|
+
do {
|
|
228
|
+
if (update) {
|
|
229
|
+
updateValue = update();
|
|
230
|
+
if (updateValue && updateValue.then && !_isSettledPact(updateValue)) {
|
|
231
|
+
updateValue.then(_resumeAfterUpdate).then(void 0, reject);
|
|
232
|
+
return;
|
|
233
|
+
}
|
|
234
|
+
}
|
|
235
|
+
shouldContinue = test();
|
|
236
|
+
if (!shouldContinue || _isSettledPact(shouldContinue) && !shouldContinue.v) {
|
|
237
|
+
_settle(pact, 1, result);
|
|
238
|
+
return;
|
|
239
|
+
}
|
|
240
|
+
if (shouldContinue.then) {
|
|
241
|
+
shouldContinue.then(_resumeAfterTest).then(void 0, reject);
|
|
242
|
+
return;
|
|
243
|
+
}
|
|
244
|
+
result = body();
|
|
245
|
+
if (_isSettledPact(result)) {
|
|
246
|
+
result = result.v;
|
|
247
|
+
}
|
|
248
|
+
} while (!result || !result.then);
|
|
249
|
+
result.then(_resumeAfterBody).then(void 0, reject);
|
|
250
|
+
}
|
|
251
|
+
function _resumeAfterTest(shouldContinue) {
|
|
252
|
+
if (shouldContinue) {
|
|
253
|
+
result = body();
|
|
254
|
+
if (result && result.then) {
|
|
255
|
+
result.then(_resumeAfterBody).then(void 0, reject);
|
|
256
|
+
} else {
|
|
257
|
+
_resumeAfterBody(result);
|
|
258
|
+
}
|
|
259
|
+
} else {
|
|
260
|
+
_settle(pact, 1, result);
|
|
261
|
+
}
|
|
262
|
+
}
|
|
263
|
+
function _resumeAfterUpdate() {
|
|
264
|
+
if (shouldContinue = test()) {
|
|
265
|
+
if (shouldContinue.then) {
|
|
266
|
+
shouldContinue.then(_resumeAfterTest).then(void 0, reject);
|
|
267
|
+
} else {
|
|
268
|
+
_resumeAfterTest(shouldContinue);
|
|
269
|
+
}
|
|
270
|
+
} else {
|
|
271
|
+
_settle(pact, 1, result);
|
|
272
|
+
}
|
|
273
|
+
}
|
|
274
|
+
}
|
|
275
|
+
function _continue(value, then) {
|
|
276
|
+
return value && value.then ? value.then(then) : then(value);
|
|
277
|
+
}
|
|
278
|
+
function _classCallCheck(instance, Constructor) { if (!(instance instanceof Constructor)) { throw new TypeError("Cannot call a class as a function"); } }
|
|
85
279
|
function _defineProperties(target, props) { for (var i = 0; i < props.length; i++) { var descriptor = props[i]; descriptor.enumerable = descriptor.enumerable || false; descriptor.configurable = true; if ("value" in descriptor) descriptor.writable = true; Object.defineProperty(target, _toPropertyKey(descriptor.key), descriptor); } }
|
|
86
280
|
function _createClass(Constructor, protoProps, staticProps) { if (protoProps) _defineProperties(Constructor.prototype, protoProps); if (staticProps) _defineProperties(Constructor, staticProps); Object.defineProperty(Constructor, "prototype", { writable: false }); return Constructor; }
|
|
87
281
|
function _toPropertyKey(arg) { var key = _toPrimitive(arg, "string"); return _typeof(key) === "symbol" ? key : String(key); }
|
|
88
282
|
function _toPrimitive(input, hint) { if (_typeof(input) !== "object" || input === null) return input; var prim = input[Symbol.toPrimitive]; if (prim !== undefined) { var res = prim.call(input, hint || "default"); if (_typeof(res) !== "object") return res; throw new TypeError("@@toPrimitive must return a primitive value."); } return (hint === "string" ? String : Number)(input); }
|
|
89
|
-
|
|
90
|
-
|
|
91
|
-
|
|
92
|
-
|
|
283
|
+
/**
|
|
284
|
+
* A lightweight mutex. (Other libraries contain too many features and we want to keep the size upload-js down).
|
|
285
|
+
*
|
|
286
|
+
* Characteristics:
|
|
287
|
+
* - Non-reentrant.
|
|
288
|
+
* - Unfair. (Multiple callers awaiting 'acquire' will be granted the mutex in no order.)
|
|
289
|
+
* - When calling `safe` consecutively with no 'awaits' in-between, the current context will synchronously acquire
|
|
290
|
+
* the mutex every time.
|
|
291
|
+
*/
|
|
292
|
+
var Mutex = /*#__PURE__*/function () {
|
|
293
|
+
function Mutex() {
|
|
294
|
+
_classCallCheck(this, Mutex);
|
|
295
|
+
this.mutex = undefined;
|
|
296
|
+
this.resolver = undefined;
|
|
297
|
+
}
|
|
298
|
+
_createClass(Mutex, [{
|
|
299
|
+
key: "safe",
|
|
300
|
+
value: function safe(callback) {
|
|
301
|
+
try {
|
|
302
|
+
var _this2 = this;
|
|
303
|
+
return _await(_this2.acquire(), function () {
|
|
304
|
+
return _finallyRethrows(callback, function (_wasThrown, _result) {
|
|
305
|
+
_this2.release();
|
|
306
|
+
return _rethrow(_wasThrown, _result);
|
|
307
|
+
});
|
|
308
|
+
});
|
|
309
|
+
} catch (e) {
|
|
310
|
+
return Promise.reject(e);
|
|
311
|
+
}
|
|
312
|
+
}
|
|
313
|
+
}, {
|
|
314
|
+
key: "acquire",
|
|
315
|
+
value: function acquire() {
|
|
316
|
+
try {
|
|
317
|
+
var _this4 = this;
|
|
318
|
+
// Loop necessary for when multiple calls are made to 'acquire' before a 'release' is called, else the call to
|
|
319
|
+
// 'release' will resume every caller currently waiting on 'acquire'.
|
|
320
|
+
return _continue(_for(function () {
|
|
321
|
+
return _this4.mutex !== undefined;
|
|
322
|
+
}, void 0, function () {
|
|
323
|
+
return _awaitIgnored(_this4.mutex);
|
|
324
|
+
}), function () {
|
|
325
|
+
_this4.mutex = new Promise(function (resolve) {
|
|
326
|
+
_this4.resolver = resolve;
|
|
327
|
+
});
|
|
328
|
+
});
|
|
329
|
+
} catch (e) {
|
|
330
|
+
return Promise.reject(e);
|
|
331
|
+
}
|
|
332
|
+
}
|
|
333
|
+
}, {
|
|
334
|
+
key: "release",
|
|
335
|
+
value: function release() {
|
|
336
|
+
if (this.resolver === undefined) {
|
|
337
|
+
throw new Error("Unable to release mutex: already released.");
|
|
338
|
+
}
|
|
339
|
+
this.resolver();
|
|
340
|
+
this.resolver = undefined;
|
|
341
|
+
this.mutex = undefined;
|
|
342
|
+
}
|
|
343
|
+
}]);
|
|
344
|
+
return Mutex;
|
|
345
|
+
}();
|
|
346
|
+
;// CONCATENATED MODULE: ./src/private/AuthSessionState.ts
|
|
347
|
+
function AuthSessionState_typeof(obj) { "@babel/helpers - typeof"; return AuthSessionState_typeof = "function" == typeof Symbol && "symbol" == typeof Symbol.iterator ? function (obj) { return typeof obj; } : function (obj) { return obj && "function" == typeof Symbol && obj.constructor === Symbol && obj !== Symbol.prototype ? "symbol" : typeof obj; }, AuthSessionState_typeof(obj); }
|
|
348
|
+
function AuthSessionState_classCallCheck(instance, Constructor) { if (!(instance instanceof Constructor)) { throw new TypeError("Cannot call a class as a function"); } }
|
|
349
|
+
function AuthSessionState_defineProperties(target, props) { for (var i = 0; i < props.length; i++) { var descriptor = props[i]; descriptor.enumerable = descriptor.enumerable || false; descriptor.configurable = true; if ("value" in descriptor) descriptor.writable = true; Object.defineProperty(target, AuthSessionState_toPropertyKey(descriptor.key), descriptor); } }
|
|
350
|
+
function AuthSessionState_createClass(Constructor, protoProps, staticProps) { if (protoProps) AuthSessionState_defineProperties(Constructor.prototype, protoProps); if (staticProps) AuthSessionState_defineProperties(Constructor, staticProps); Object.defineProperty(Constructor, "prototype", { writable: false }); return Constructor; }
|
|
351
|
+
function AuthSessionState_toPropertyKey(arg) { var key = AuthSessionState_toPrimitive(arg, "string"); return AuthSessionState_typeof(key) === "symbol" ? key : String(key); }
|
|
352
|
+
function AuthSessionState_toPrimitive(input, hint) { if (AuthSessionState_typeof(input) !== "object" || input === null) return input; var prim = input[Symbol.toPrimitive]; if (prim !== undefined) { var res = prim.call(input, hint || "default"); if (AuthSessionState_typeof(res) !== "object") return res; throw new TypeError("@@toPrimitive must return a primitive value."); } return (hint === "string" ? String : Number)(input); }
|
|
353
|
+
|
|
354
|
+
/**
|
|
355
|
+
* Maintains a global session state, even across package versions.
|
|
356
|
+
*
|
|
357
|
+
* This is to allow users to start auth sessions via the Bytescale JavaScript SDK, where due to versioning or other
|
|
358
|
+
* bundling issues, the Bytescale Upload Widget has been bundled with a different Bytescale JavaScript SDK. In this
|
|
359
|
+
* scenario, the user wouldn't be able to start an auth session with the Bytescale Upload Widget. Therefore, we use
|
|
360
|
+
* global state (i.e. on the window) to ensure the session state can be shared between the user's instance of the
|
|
361
|
+
* Bytescale JavaScript SDK and the Upload Widget's version of the Bytescale JavaScript SDK.
|
|
362
|
+
*
|
|
363
|
+
* Users also frequently have problems caused by them not keeping track of *Api and *Manager instances correctly, so
|
|
364
|
+
* making this global prevents a lot of common mistakes.
|
|
365
|
+
*/
|
|
366
|
+
var AuthSessionState = /*#__PURE__*/function () {
|
|
367
|
+
function AuthSessionState() {
|
|
368
|
+
AuthSessionState_classCallCheck(this, AuthSessionState);
|
|
369
|
+
}
|
|
370
|
+
AuthSessionState_createClass(AuthSessionState, null, [{
|
|
371
|
+
key: "getMutex",
|
|
372
|
+
value:
|
|
373
|
+
/**
|
|
374
|
+
* Called in the browser only.
|
|
375
|
+
*/
|
|
376
|
+
function getMutex() {
|
|
377
|
+
var key = AuthSessionState.mutexKey;
|
|
378
|
+
var mutex = window[key];
|
|
379
|
+
if (mutex === undefined) {
|
|
380
|
+
mutex = new Mutex();
|
|
381
|
+
window[key] = mutex;
|
|
382
|
+
}
|
|
383
|
+
return mutex;
|
|
384
|
+
}
|
|
385
|
+
/**
|
|
386
|
+
* Called in the browser only.
|
|
387
|
+
*/
|
|
388
|
+
}, {
|
|
389
|
+
key: "setSession",
|
|
390
|
+
value: function setSession(session) {
|
|
391
|
+
window[AuthSessionState.stateKey] = session;
|
|
392
|
+
}
|
|
393
|
+
/**
|
|
394
|
+
* Called in the browser and in Node.js (so we check the env before calling env-specific code).
|
|
395
|
+
*/
|
|
396
|
+
}, {
|
|
397
|
+
key: "getSession",
|
|
398
|
+
value: function getSession() {
|
|
399
|
+
if (typeof window === "undefined") {
|
|
400
|
+
return undefined;
|
|
401
|
+
}
|
|
402
|
+
return window[AuthSessionState.stateKey];
|
|
403
|
+
}
|
|
404
|
+
}]);
|
|
405
|
+
return AuthSessionState;
|
|
406
|
+
}();
|
|
407
|
+
AuthSessionState.stateKey = "BytescaleSessionState";
|
|
408
|
+
AuthSessionState.mutexKey = "BytescaleSessionStateMutex";
|
|
93
409
|
;// CONCATENATED MODULE: ./src/public/shared/generated/runtime.ts
|
|
94
410
|
function runtime_typeof(obj) { "@babel/helpers - typeof"; return runtime_typeof = "function" == typeof Symbol && "symbol" == typeof Symbol.iterator ? function (obj) { return typeof obj; } : function (obj) { return obj && "function" == typeof Symbol && obj.constructor === Symbol && obj !== Symbol.prototype ? "symbol" : typeof obj; }, runtime_typeof(obj); }
|
|
95
411
|
function _inherits(subClass, superClass) { if (typeof superClass !== "function" && superClass !== null) { throw new TypeError("Super expression must either be null or a function"); } subClass.prototype = Object.create(superClass && superClass.prototype, { constructor: { value: subClass, writable: true, configurable: true } }); Object.defineProperty(subClass, "prototype", { writable: false }); if (superClass) _setPrototypeOf(subClass, superClass); }
|
|
@@ -113,8 +429,8 @@ function _catch(body, recover) {
|
|
|
113
429
|
}
|
|
114
430
|
return result;
|
|
115
431
|
}
|
|
116
|
-
function
|
|
117
|
-
function
|
|
432
|
+
function runtime_empty() {}
|
|
433
|
+
function runtime_continue(value, then) {
|
|
118
434
|
return value && value.then ? value.then(then) : then(value);
|
|
119
435
|
}
|
|
120
436
|
function _invoke(body, then) {
|
|
@@ -125,7 +441,7 @@ function _invoke(body, then) {
|
|
|
125
441
|
return then(result);
|
|
126
442
|
}
|
|
127
443
|
function _defineProperty(obj, key, value) { key = runtime_toPropertyKey(key); if (key in obj) { Object.defineProperty(obj, key, { value: value, enumerable: true, configurable: true, writable: true }); } else { obj[key] = value; } return obj; }
|
|
128
|
-
function
|
|
444
|
+
function runtime_await(value, then, direct) {
|
|
129
445
|
if (direct) {
|
|
130
446
|
return then ? then(value) : value;
|
|
131
447
|
}
|
|
@@ -140,21 +456,21 @@ function runtime_createClass(Constructor, protoProps, staticProps) { if (protoPr
|
|
|
140
456
|
function runtime_toPropertyKey(arg) { var key = runtime_toPrimitive(arg, "string"); return runtime_typeof(key) === "symbol" ? key : String(key); }
|
|
141
457
|
function runtime_toPrimitive(input, hint) { if (runtime_typeof(input) !== "object" || input === null) return input; var prim = input[Symbol.toPrimitive]; if (prim !== undefined) { var res = prim.call(input, hint || "default"); if (runtime_typeof(res) !== "object") return res; throw new TypeError("@@toPrimitive must return a primitive value."); } return (hint === "string" ? String : Number)(input); }
|
|
142
458
|
|
|
143
|
-
var
|
|
144
|
-
function
|
|
145
|
-
runtime_classCallCheck(this,
|
|
459
|
+
var BytescaleApiClientConfigUtils = /*#__PURE__*/function () {
|
|
460
|
+
function BytescaleApiClientConfigUtils() {
|
|
461
|
+
runtime_classCallCheck(this, BytescaleApiClientConfigUtils);
|
|
146
462
|
}
|
|
147
|
-
runtime_createClass(
|
|
463
|
+
runtime_createClass(BytescaleApiClientConfigUtils, null, [{
|
|
148
464
|
key: "getApiUrl",
|
|
149
465
|
value: function getApiUrl(config) {
|
|
150
466
|
var _a;
|
|
151
|
-
return (_a = config.apiUrl) !== null && _a !== void 0 ? _a :
|
|
467
|
+
return (_a = config.apiUrl) !== null && _a !== void 0 ? _a : BytescaleApiClientConfigUtils.defaultApiUrl;
|
|
152
468
|
}
|
|
153
469
|
}, {
|
|
154
470
|
key: "getCdnUrl",
|
|
155
471
|
value: function getCdnUrl(config) {
|
|
156
472
|
var _a;
|
|
157
|
-
return (_a = config.cdnUrl) !== null && _a !== void 0 ? _a :
|
|
473
|
+
return (_a = config.cdnUrl) !== null && _a !== void 0 ? _a : BytescaleApiClientConfigUtils.defaultCdnUrl;
|
|
158
474
|
}
|
|
159
475
|
}, {
|
|
160
476
|
key: "getFetchApi",
|
|
@@ -162,11 +478,48 @@ var BytescaleApiClientConfigResolver = /*#__PURE__*/function () {
|
|
|
162
478
|
var _a;
|
|
163
479
|
return (_a = config.fetchApi) !== null && _a !== void 0 ? _a : fetch;
|
|
164
480
|
}
|
|
481
|
+
}, {
|
|
482
|
+
key: "getAccountId",
|
|
483
|
+
value: function getAccountId(config) {
|
|
484
|
+
var _a, _b;
|
|
485
|
+
var accountId;
|
|
486
|
+
if (BytescaleApiClientConfigUtils.specialApiKeys.includes(config.apiKey)) {
|
|
487
|
+
accountId = BytescaleApiClientConfigUtils.specialApiKeyAccountId;
|
|
488
|
+
} else {
|
|
489
|
+
accountId = (_b = (_a = config.apiKey.split("_")[1]) === null || _a === void 0 ? void 0 : _a.substr(0, BytescaleApiClientConfigUtils.accountIdLength)) !== null && _b !== void 0 ? _b : "";
|
|
490
|
+
if (accountId.length !== BytescaleApiClientConfigUtils.accountIdLength) {
|
|
491
|
+
throw new Error("Invalid Bytescale API key.");
|
|
492
|
+
}
|
|
493
|
+
}
|
|
494
|
+
return accountId;
|
|
495
|
+
}
|
|
496
|
+
}, {
|
|
497
|
+
key: "validate",
|
|
498
|
+
value: function validate(config) {
|
|
499
|
+
var _a;
|
|
500
|
+
// Defensive programming, for users not using TypeScript. Mainly because this is used by UploadWidget users.
|
|
501
|
+
if ((config !== null && config !== void 0 ? config : undefined) === undefined) {
|
|
502
|
+
throw new Error("Config parameter required.");
|
|
503
|
+
}
|
|
504
|
+
if (((_a = config.apiKey) !== null && _a !== void 0 ? _a : undefined) === undefined) {
|
|
505
|
+
throw new Error("Please provide an API key via the 'apiKey' config parameter.");
|
|
506
|
+
}
|
|
507
|
+
if (config.apiKey.trim() !== config.apiKey) {
|
|
508
|
+
// We do not support API keys with whitespace (by trimming ourselves) because otherwise we'd need to support this
|
|
509
|
+
// everywhere in perpetuity (since removing the trimming would be a breaking change).
|
|
510
|
+
throw new Error("API key needs trimming (whitespace detected).");
|
|
511
|
+
}
|
|
512
|
+
// This performs futher validation on the API key...
|
|
513
|
+
BytescaleApiClientConfigUtils.getAccountId(config);
|
|
514
|
+
}
|
|
165
515
|
}]);
|
|
166
|
-
return
|
|
516
|
+
return BytescaleApiClientConfigUtils;
|
|
167
517
|
}();
|
|
168
|
-
|
|
169
|
-
|
|
518
|
+
BytescaleApiClientConfigUtils.defaultApiUrl = "https://api.bytescale.com";
|
|
519
|
+
BytescaleApiClientConfigUtils.defaultCdnUrl = "https://upcdn.io";
|
|
520
|
+
BytescaleApiClientConfigUtils.specialApiKeys = ["free", "demo"];
|
|
521
|
+
BytescaleApiClientConfigUtils.specialApiKeyAccountId = "W142hJk";
|
|
522
|
+
BytescaleApiClientConfigUtils.accountIdLength = 7; // Sync with: upload/shared/**/AccountIdUtils
|
|
170
523
|
/**
|
|
171
524
|
* This is the base class for all generated API classes.
|
|
172
525
|
*/
|
|
@@ -174,22 +527,24 @@ var BaseAPI = /*#__PURE__*/function () {
|
|
|
174
527
|
function BaseAPI(config) {
|
|
175
528
|
runtime_classCallCheck(this, BaseAPI);
|
|
176
529
|
this.config = config;
|
|
530
|
+
BytescaleApiClientConfigUtils.validate(config);
|
|
177
531
|
}
|
|
178
532
|
runtime_createClass(BaseAPI, [{
|
|
179
533
|
key: "request",
|
|
180
534
|
value: function request(context, initOverrides, baseUrlOverride) {
|
|
181
535
|
try {
|
|
182
536
|
var _this2 = this;
|
|
183
|
-
var _a
|
|
537
|
+
var _a;
|
|
184
538
|
var apiKey = _this2.config.apiKey;
|
|
185
539
|
context.headers["Authorization"] = "Bearer ".concat(apiKey); // authorization-header authentication
|
|
186
|
-
|
|
187
|
-
|
|
540
|
+
var session = AuthSessionState.getSession();
|
|
541
|
+
if ((session === null || session === void 0 ? void 0 : session.accessToken) !== undefined) {
|
|
542
|
+
context.headers["Authorization-Token"] = session.accessToken;
|
|
188
543
|
}
|
|
189
544
|
// Key: any possible value for 'baseUrlOverride'
|
|
190
545
|
// Value: user-overridden value for that base URL from the config.
|
|
191
|
-
var nonDefaultBasePaths = _defineProperty({},
|
|
192
|
-
return
|
|
546
|
+
var nonDefaultBasePaths = _defineProperty({}, BytescaleApiClientConfigUtils.defaultCdnUrl, BytescaleApiClientConfigUtils.getCdnUrl(_this2.config));
|
|
547
|
+
return runtime_await(_this2.createFetchParams(context, initOverrides, baseUrlOverride === undefined ? undefined : (_a = nonDefaultBasePaths[baseUrlOverride]) !== null && _a !== void 0 ? _a : baseUrlOverride), function (_ref) {
|
|
193
548
|
var url = _ref.url,
|
|
194
549
|
init = _ref.init;
|
|
195
550
|
return _this2.doFetch(url, init, true);
|
|
@@ -209,8 +564,8 @@ var BaseAPI = /*#__PURE__*/function () {
|
|
|
209
564
|
var _this4 = this;
|
|
210
565
|
var _a, _b;
|
|
211
566
|
var response;
|
|
212
|
-
return
|
|
213
|
-
return
|
|
567
|
+
return runtime_continue(_catch(function () {
|
|
568
|
+
return runtime_await(BytescaleApiClientConfigUtils.getFetchApi(_this4.config)(url, init), function (_BytescaleApiClientCo) {
|
|
214
569
|
response = _BytescaleApiClientCo;
|
|
215
570
|
});
|
|
216
571
|
}, function (e) {
|
|
@@ -223,11 +578,11 @@ var BaseAPI = /*#__PURE__*/function () {
|
|
|
223
578
|
return response.status >= 200 && response.status < 300 ? response : _invoke(function () {
|
|
224
579
|
if (isBytescaleApi) {
|
|
225
580
|
var jsonError = undefined;
|
|
226
|
-
return
|
|
227
|
-
return
|
|
581
|
+
return runtime_continue(_catch(function () {
|
|
582
|
+
return runtime_await(response.json(), function (_response$json) {
|
|
228
583
|
jsonError = _response$json;
|
|
229
584
|
});
|
|
230
|
-
},
|
|
585
|
+
}, runtime_empty), function () {
|
|
231
586
|
if (typeof ((_a = jsonError === null || jsonError === void 0 ? void 0 : jsonError.error) === null || _a === void 0 ? void 0 : _a.code) === "string") {
|
|
232
587
|
throw new BytescaleApiError(jsonError);
|
|
233
588
|
}
|
|
@@ -264,7 +619,7 @@ var BaseAPI = /*#__PURE__*/function () {
|
|
|
264
619
|
value: function createFetchParams(context, initOverrides, baseUrlOverride) {
|
|
265
620
|
try {
|
|
266
621
|
var _this6 = this;
|
|
267
|
-
var url = (baseUrlOverride !== null && baseUrlOverride !== void 0 ? baseUrlOverride :
|
|
622
|
+
var url = (baseUrlOverride !== null && baseUrlOverride !== void 0 ? baseUrlOverride : BytescaleApiClientConfigUtils.getApiUrl(_this6.config)) + context.path;
|
|
268
623
|
if (context.query !== undefined && Object.keys(context.query).length !== 0) {
|
|
269
624
|
// only add the querystring to the URL if there are query parameters.
|
|
270
625
|
// this is done to avoid urls ending with a "?" character which buggy webservers
|
|
@@ -273,13 +628,13 @@ var BaseAPI = /*#__PURE__*/function () {
|
|
|
273
628
|
}
|
|
274
629
|
var configHeaders = _this6.config.headers;
|
|
275
630
|
var _Object$assign3 = Object.assign({}, context.headers);
|
|
276
|
-
return
|
|
631
|
+
return runtime_await(configHeaders === undefined ? {} : configHeaders(), function (_configHeaders) {
|
|
277
632
|
var headers = Object.assign(_Object$assign3, _configHeaders);
|
|
278
633
|
Object.keys(headers).forEach(function (key) {
|
|
279
634
|
return headers[key] === undefined ? delete headers[key] : {};
|
|
280
635
|
});
|
|
281
636
|
var initOverrideFn = typeof initOverrides === "function" ? initOverrides : function () {
|
|
282
|
-
return
|
|
637
|
+
return runtime_await(initOverrides);
|
|
283
638
|
};
|
|
284
639
|
var initParams = {
|
|
285
640
|
method: context.method,
|
|
@@ -287,7 +642,7 @@ var BaseAPI = /*#__PURE__*/function () {
|
|
|
287
642
|
body: context.body
|
|
288
643
|
};
|
|
289
644
|
var _Object$assign2 = Object.assign({}, initParams);
|
|
290
|
-
return
|
|
645
|
+
return runtime_await(initOverrideFn({
|
|
291
646
|
init: initParams,
|
|
292
647
|
context: context
|
|
293
648
|
}), function (_initOverrideFn) {
|
|
@@ -308,9 +663,6 @@ var BaseAPI = /*#__PURE__*/function () {
|
|
|
308
663
|
}]);
|
|
309
664
|
return BaseAPI;
|
|
310
665
|
}();
|
|
311
|
-
BaseAPI.specialApiKeys = ["free", "demo"];
|
|
312
|
-
BaseAPI.specialApiKeyAccountId = "W142hJk";
|
|
313
|
-
BaseAPI.accountIdLength = 7; // Sync with: upload/shared/**/AccountIdUtils
|
|
314
666
|
var CancelledError = /*#__PURE__*/function (_Error) {
|
|
315
667
|
_inherits(CancelledError, _Error);
|
|
316
668
|
var _super = _createSuper(CancelledError);
|
|
@@ -360,7 +712,7 @@ var JSONApiResponse = /*#__PURE__*/function () {
|
|
|
360
712
|
value: function value() {
|
|
361
713
|
try {
|
|
362
714
|
var _this10 = this;
|
|
363
|
-
return
|
|
715
|
+
return runtime_await(_this10.raw.json());
|
|
364
716
|
} catch (e) {
|
|
365
717
|
return Promise.reject(e);
|
|
366
718
|
}
|
|
@@ -376,7 +728,7 @@ var VoidApiResponse = /*#__PURE__*/function () {
|
|
|
376
728
|
runtime_createClass(VoidApiResponse, [{
|
|
377
729
|
key: "value",
|
|
378
730
|
value: function value() {
|
|
379
|
-
return
|
|
731
|
+
return runtime_await(undefined);
|
|
380
732
|
}
|
|
381
733
|
}]);
|
|
382
734
|
return VoidApiResponse;
|
|
@@ -402,7 +754,7 @@ var BinaryResult = /*#__PURE__*/function () {
|
|
|
402
754
|
value: function text() {
|
|
403
755
|
try {
|
|
404
756
|
var _this12 = this;
|
|
405
|
-
return
|
|
757
|
+
return runtime_await(_this12.raw.text());
|
|
406
758
|
} catch (e) {
|
|
407
759
|
return Promise.reject(e);
|
|
408
760
|
}
|
|
@@ -412,7 +764,7 @@ var BinaryResult = /*#__PURE__*/function () {
|
|
|
412
764
|
value: function blob() {
|
|
413
765
|
try {
|
|
414
766
|
var _this14 = this;
|
|
415
|
-
return
|
|
767
|
+
return runtime_await(_this14.raw.blob());
|
|
416
768
|
} catch (e) {
|
|
417
769
|
return Promise.reject(e);
|
|
418
770
|
}
|
|
@@ -422,7 +774,7 @@ var BinaryResult = /*#__PURE__*/function () {
|
|
|
422
774
|
value: function json() {
|
|
423
775
|
try {
|
|
424
776
|
var _this16 = this;
|
|
425
|
-
return
|
|
777
|
+
return runtime_await(_this16.raw.json());
|
|
426
778
|
} catch (e) {
|
|
427
779
|
return Promise.reject(e);
|
|
428
780
|
}
|
|
@@ -468,9 +820,6 @@ function FileApi_getPrototypeOf(o) { FileApi_getPrototypeOf = Object.setPrototyp
|
|
|
468
820
|
*/
|
|
469
821
|
// @ts-ignore
|
|
470
822
|
|
|
471
|
-
/**
|
|
472
|
-
*
|
|
473
|
-
*/
|
|
474
823
|
var FileApi = /*#__PURE__*/function (_runtime$BaseAPI) {
|
|
475
824
|
FileApi_inherits(FileApi, _runtime$BaseAPI);
|
|
476
825
|
var _super = FileApi_createSuper(FileApi);
|
|
@@ -769,9 +1118,6 @@ function FolderApi_getPrototypeOf(o) { FolderApi_getPrototypeOf = Object.setProt
|
|
|
769
1118
|
*/
|
|
770
1119
|
// @ts-ignore
|
|
771
1120
|
|
|
772
|
-
/**
|
|
773
|
-
*
|
|
774
|
-
*/
|
|
775
1121
|
var FolderApi = /*#__PURE__*/function (_runtime$BaseAPI) {
|
|
776
1122
|
FolderApi_inherits(FolderApi, _runtime$BaseAPI);
|
|
777
1123
|
var _super = FolderApi_createSuper(FolderApi);
|
|
@@ -1029,9 +1375,6 @@ function JobApi_getPrototypeOf(o) { JobApi_getPrototypeOf = Object.setPrototypeO
|
|
|
1029
1375
|
*/
|
|
1030
1376
|
// @ts-ignore
|
|
1031
1377
|
|
|
1032
|
-
/**
|
|
1033
|
-
*
|
|
1034
|
-
*/
|
|
1035
1378
|
var JobApi = /*#__PURE__*/function (_runtime$BaseAPI) {
|
|
1036
1379
|
JobApi_inherits(JobApi, _runtime$BaseAPI);
|
|
1037
1380
|
var _super = JobApi_createSuper(JobApi);
|
|
@@ -1164,9 +1507,6 @@ function UploadApi_getPrototypeOf(o) { UploadApi_getPrototypeOf = Object.setProt
|
|
|
1164
1507
|
*/
|
|
1165
1508
|
// @ts-ignore
|
|
1166
1509
|
|
|
1167
|
-
/**
|
|
1168
|
-
*
|
|
1169
|
-
*/
|
|
1170
1510
|
var UploadApi = /*#__PURE__*/function (_runtime$BaseAPI) {
|
|
1171
1511
|
UploadApi_inherits(UploadApi, _runtime$BaseAPI);
|
|
1172
1512
|
var _super = UploadApi_createSuper(UploadApi);
|
|
@@ -1362,7 +1702,7 @@ var UrlBuilder = /*#__PURE__*/function () {
|
|
|
1362
1702
|
function UrlBuilder(config) {
|
|
1363
1703
|
UrlBuilder_classCallCheck(this, UrlBuilder);
|
|
1364
1704
|
var _a;
|
|
1365
|
-
this.cdnUrl = (_a = config === null || config === void 0 ? void 0 : config.cdnUrl) !== null && _a !== void 0 ? _a :
|
|
1705
|
+
this.cdnUrl = (_a = config === null || config === void 0 ? void 0 : config.cdnUrl) !== null && _a !== void 0 ? _a : BytescaleApiClientConfigUtils.defaultCdnUrl;
|
|
1366
1706
|
}
|
|
1367
1707
|
/**
|
|
1368
1708
|
* Builds a URL to either a raw file or a transformed file.
|
|
@@ -1387,7 +1727,7 @@ var UrlBuilder = /*#__PURE__*/function () {
|
|
|
1387
1727
|
key: "url",
|
|
1388
1728
|
value: function url(params) {
|
|
1389
1729
|
var _a;
|
|
1390
|
-
return ((_a = params.options) === null || _a === void 0 ? void 0 : _a.transformation) === undefined ? this.raw(params) : this.transformation(params, params.options
|
|
1730
|
+
return ((_a = params.options) === null || _a === void 0 ? void 0 : _a.transformation) === undefined ? this.raw(params) : this.transformation(params, params.options);
|
|
1391
1731
|
}
|
|
1392
1732
|
}, {
|
|
1393
1733
|
key: "raw",
|
|
@@ -1401,18 +1741,25 @@ var UrlBuilder = /*#__PURE__*/function () {
|
|
|
1401
1741
|
key: "transformation",
|
|
1402
1742
|
value: function transformation(params, trans) {
|
|
1403
1743
|
var _a;
|
|
1404
|
-
var baseUrl = this.getBaseUrl(params, trans.
|
|
1405
|
-
var transParams = this.getTransformationParams(trans
|
|
1406
|
-
cachePermanently: "cache_perm"
|
|
1407
|
-
});
|
|
1744
|
+
var baseUrl = this.getBaseUrl(params, trans.transformation === "preset" ? trans.transformationPreset : trans.transformation);
|
|
1745
|
+
var transParams = trans.transformation === "preset" ? [] : this.getTransformationParams(trans);
|
|
1408
1746
|
var commonParams = this.getCommonQueryParams((_a = params.options) !== null && _a !== void 0 ? _a : {});
|
|
1409
|
-
|
|
1747
|
+
var transCommonParams = this.getCommonTransformationQueryParams(trans);
|
|
1748
|
+
// This format puts "artifact" at the end, which isn't required, but is convention.
|
|
1749
|
+
return this.addQueryParams(baseUrl, [].concat(_toConsumableArray(transParams), _toConsumableArray(commonParams), _toConsumableArray(transCommonParams)));
|
|
1410
1750
|
}
|
|
1411
1751
|
}, {
|
|
1412
1752
|
key: "getBaseUrl",
|
|
1413
1753
|
value: function getBaseUrl(params, prefix) {
|
|
1414
1754
|
return "".concat(this.cdnUrl, "/").concat(params.accountId, "/").concat(prefix).concat(params.filePath);
|
|
1415
1755
|
}
|
|
1756
|
+
}, {
|
|
1757
|
+
key: "getCommonTransformationQueryParams",
|
|
1758
|
+
value: function getCommonTransformationQueryParams(trans) {
|
|
1759
|
+
return this.makeQueryParams(["cachePermanently", "large", "artifact"], {
|
|
1760
|
+
cachePermanently: "cache_perm"
|
|
1761
|
+
})(trans);
|
|
1762
|
+
}
|
|
1416
1763
|
}, {
|
|
1417
1764
|
key: "getCommonQueryParams",
|
|
1418
1765
|
value: function getCommonQueryParams(params) {
|
|
@@ -1438,8 +1785,9 @@ var UrlBuilder = /*#__PURE__*/function () {
|
|
|
1438
1785
|
}
|
|
1439
1786
|
}, {
|
|
1440
1787
|
key: "getTransformationParams",
|
|
1441
|
-
value: function getTransformationParams(trans
|
|
1442
|
-
|
|
1788
|
+
value: function getTransformationParams(trans) {
|
|
1789
|
+
var params = trans.transformationParams;
|
|
1790
|
+
if (params === undefined) {
|
|
1443
1791
|
return [];
|
|
1444
1792
|
}
|
|
1445
1793
|
var serializeObj = function serializeObj(obj) {
|
|
@@ -1447,11 +1795,10 @@ var UrlBuilder = /*#__PURE__*/function () {
|
|
|
1447
1795
|
var _ref2 = _slicedToArray(_ref, 2),
|
|
1448
1796
|
key = _ref2[0],
|
|
1449
1797
|
value = _ref2[1];
|
|
1450
|
-
|
|
1451
|
-
return [(_a = keyRewrites[key]) !== null && _a !== void 0 ? _a : key, value.toString()];
|
|
1798
|
+
return [key, value.toString()];
|
|
1452
1799
|
});
|
|
1453
1800
|
};
|
|
1454
|
-
return Array.isArray(
|
|
1801
|
+
return Array.isArray(params) ? params.flatMap(serializeObj) : serializeObj(params);
|
|
1455
1802
|
}
|
|
1456
1803
|
}, {
|
|
1457
1804
|
key: "addQueryParams",
|
|
@@ -1499,21 +1846,21 @@ function _invokeIgnored(body) {
|
|
|
1499
1846
|
return result.then(UploadManagerBase_empty);
|
|
1500
1847
|
}
|
|
1501
1848
|
}
|
|
1502
|
-
function
|
|
1849
|
+
function UploadManagerBase_settle(pact, state, value) {
|
|
1503
1850
|
if (!pact.s) {
|
|
1504
|
-
if (value instanceof
|
|
1851
|
+
if (value instanceof UploadManagerBase_Pact) {
|
|
1505
1852
|
if (value.s) {
|
|
1506
1853
|
if (state & 1) {
|
|
1507
1854
|
state = value.s;
|
|
1508
1855
|
}
|
|
1509
1856
|
value = value.v;
|
|
1510
1857
|
} else {
|
|
1511
|
-
value.o =
|
|
1858
|
+
value.o = UploadManagerBase_settle.bind(null, pact, state);
|
|
1512
1859
|
return;
|
|
1513
1860
|
}
|
|
1514
1861
|
}
|
|
1515
1862
|
if (value && value.then) {
|
|
1516
|
-
value.then(
|
|
1863
|
+
value.then(UploadManagerBase_settle.bind(null, pact, state), UploadManagerBase_settle.bind(null, pact, 2));
|
|
1517
1864
|
return;
|
|
1518
1865
|
}
|
|
1519
1866
|
pact.s = state;
|
|
@@ -1524,7 +1871,7 @@ function _settle(pact, state, value) {
|
|
|
1524
1871
|
}
|
|
1525
1872
|
}
|
|
1526
1873
|
}
|
|
1527
|
-
var
|
|
1874
|
+
var UploadManagerBase_Pact = /*#__PURE__*/function () {
|
|
1528
1875
|
function _Pact() {}
|
|
1529
1876
|
_Pact.prototype.then = function (onFulfilled, onRejected) {
|
|
1530
1877
|
var result = new _Pact();
|
|
@@ -1533,9 +1880,9 @@ var _Pact = /*#__PURE__*/function () {
|
|
|
1533
1880
|
var callback = state & 1 ? onFulfilled : onRejected;
|
|
1534
1881
|
if (callback) {
|
|
1535
1882
|
try {
|
|
1536
|
-
|
|
1883
|
+
UploadManagerBase_settle(result, 1, callback(this.v));
|
|
1537
1884
|
} catch (e) {
|
|
1538
|
-
|
|
1885
|
+
UploadManagerBase_settle(result, 2, e);
|
|
1539
1886
|
}
|
|
1540
1887
|
return result;
|
|
1541
1888
|
} else {
|
|
@@ -1546,28 +1893,28 @@ var _Pact = /*#__PURE__*/function () {
|
|
|
1546
1893
|
try {
|
|
1547
1894
|
var value = _this.v;
|
|
1548
1895
|
if (_this.s & 1) {
|
|
1549
|
-
|
|
1896
|
+
UploadManagerBase_settle(result, 1, onFulfilled ? onFulfilled(value) : value);
|
|
1550
1897
|
} else if (onRejected) {
|
|
1551
|
-
|
|
1898
|
+
UploadManagerBase_settle(result, 1, onRejected(value));
|
|
1552
1899
|
} else {
|
|
1553
|
-
|
|
1900
|
+
UploadManagerBase_settle(result, 2, value);
|
|
1554
1901
|
}
|
|
1555
1902
|
} catch (e) {
|
|
1556
|
-
|
|
1903
|
+
UploadManagerBase_settle(result, 2, e);
|
|
1557
1904
|
}
|
|
1558
1905
|
};
|
|
1559
1906
|
return result;
|
|
1560
1907
|
};
|
|
1561
1908
|
return _Pact;
|
|
1562
1909
|
}();
|
|
1563
|
-
function
|
|
1564
|
-
return thenable instanceof
|
|
1910
|
+
function UploadManagerBase_isSettledPact(thenable) {
|
|
1911
|
+
return thenable instanceof UploadManagerBase_Pact && thenable.s & 1;
|
|
1565
1912
|
}
|
|
1566
|
-
function
|
|
1913
|
+
function UploadManagerBase_for(test, update, body) {
|
|
1567
1914
|
var stage;
|
|
1568
1915
|
for (;;) {
|
|
1569
1916
|
var shouldContinue = test();
|
|
1570
|
-
if (
|
|
1917
|
+
if (UploadManagerBase_isSettledPact(shouldContinue)) {
|
|
1571
1918
|
shouldContinue = shouldContinue.v;
|
|
1572
1919
|
}
|
|
1573
1920
|
if (!shouldContinue) {
|
|
@@ -1579,7 +1926,7 @@ function _for(test, update, body) {
|
|
|
1579
1926
|
}
|
|
1580
1927
|
var result = body();
|
|
1581
1928
|
if (result && result.then) {
|
|
1582
|
-
if (
|
|
1929
|
+
if (UploadManagerBase_isSettledPact(result)) {
|
|
1583
1930
|
result = result.s;
|
|
1584
1931
|
} else {
|
|
1585
1932
|
stage = 1;
|
|
@@ -1588,14 +1935,14 @@ function _for(test, update, body) {
|
|
|
1588
1935
|
}
|
|
1589
1936
|
if (update) {
|
|
1590
1937
|
var updateValue = update();
|
|
1591
|
-
if (updateValue && updateValue.then && !
|
|
1938
|
+
if (updateValue && updateValue.then && !UploadManagerBase_isSettledPact(updateValue)) {
|
|
1592
1939
|
stage = 2;
|
|
1593
1940
|
break;
|
|
1594
1941
|
}
|
|
1595
1942
|
}
|
|
1596
1943
|
}
|
|
1597
|
-
var pact = new
|
|
1598
|
-
var reject =
|
|
1944
|
+
var pact = new UploadManagerBase_Pact();
|
|
1945
|
+
var reject = UploadManagerBase_settle.bind(null, pact, 2);
|
|
1599
1946
|
(stage === 0 ? shouldContinue.then(_resumeAfterTest) : stage === 1 ? result.then(_resumeAfterBody) : updateValue.then(_resumeAfterUpdate)).then(void 0, reject);
|
|
1600
1947
|
return pact;
|
|
1601
1948
|
function _resumeAfterBody(value) {
|
|
@@ -1603,14 +1950,14 @@ function _for(test, update, body) {
|
|
|
1603
1950
|
do {
|
|
1604
1951
|
if (update) {
|
|
1605
1952
|
updateValue = update();
|
|
1606
|
-
if (updateValue && updateValue.then && !
|
|
1953
|
+
if (updateValue && updateValue.then && !UploadManagerBase_isSettledPact(updateValue)) {
|
|
1607
1954
|
updateValue.then(_resumeAfterUpdate).then(void 0, reject);
|
|
1608
1955
|
return;
|
|
1609
1956
|
}
|
|
1610
1957
|
}
|
|
1611
1958
|
shouldContinue = test();
|
|
1612
|
-
if (!shouldContinue ||
|
|
1613
|
-
|
|
1959
|
+
if (!shouldContinue || UploadManagerBase_isSettledPact(shouldContinue) && !shouldContinue.v) {
|
|
1960
|
+
UploadManagerBase_settle(pact, 1, result);
|
|
1614
1961
|
return;
|
|
1615
1962
|
}
|
|
1616
1963
|
if (shouldContinue.then) {
|
|
@@ -1618,7 +1965,7 @@ function _for(test, update, body) {
|
|
|
1618
1965
|
return;
|
|
1619
1966
|
}
|
|
1620
1967
|
result = body();
|
|
1621
|
-
if (
|
|
1968
|
+
if (UploadManagerBase_isSettledPact(result)) {
|
|
1622
1969
|
result = result.v;
|
|
1623
1970
|
}
|
|
1624
1971
|
} while (!result || !result.then);
|
|
@@ -1633,7 +1980,7 @@ function _for(test, update, body) {
|
|
|
1633
1980
|
_resumeAfterBody(result);
|
|
1634
1981
|
}
|
|
1635
1982
|
} else {
|
|
1636
|
-
|
|
1983
|
+
UploadManagerBase_settle(pact, 1, result);
|
|
1637
1984
|
}
|
|
1638
1985
|
}
|
|
1639
1986
|
function _resumeAfterUpdate() {
|
|
@@ -1644,7 +1991,7 @@ function _for(test, update, body) {
|
|
|
1644
1991
|
_resumeAfterTest(shouldContinue);
|
|
1645
1992
|
}
|
|
1646
1993
|
} else {
|
|
1647
|
-
|
|
1994
|
+
UploadManagerBase_settle(pact, 1, result);
|
|
1648
1995
|
}
|
|
1649
1996
|
}
|
|
1650
1997
|
}
|
|
@@ -1660,7 +2007,7 @@ function UploadManagerBase_iterableToArray(iter) { if (typeof Symbol !== "undefi
|
|
|
1660
2007
|
function UploadManagerBase_arrayWithoutHoles(arr) { if (Array.isArray(arr)) return UploadManagerBase_arrayLikeToArray(arr); }
|
|
1661
2008
|
function UploadManagerBase_arrayLikeToArray(arr, len) { if (len == null || len > arr.length) len = arr.length; for (var i = 0, arr2 = new Array(len); i < len; i++) { arr2[i] = arr[i]; } return arr2; }
|
|
1662
2009
|
function UploadManagerBase_empty() {}
|
|
1663
|
-
function
|
|
2010
|
+
function UploadManagerBase_awaitIgnored(value, direct) {
|
|
1664
2011
|
if (!direct) {
|
|
1665
2012
|
return value && value.then ? value.then(UploadManagerBase_empty) : Promise.resolve();
|
|
1666
2013
|
}
|
|
@@ -1674,11 +2021,11 @@ function UploadManagerBase_await(value, then, direct) {
|
|
|
1674
2021
|
}
|
|
1675
2022
|
return then ? value.then(then) : value;
|
|
1676
2023
|
}
|
|
1677
|
-
function
|
|
2024
|
+
function UploadManagerBase_rethrow(thrown, value) {
|
|
1678
2025
|
if (thrown) throw value;
|
|
1679
2026
|
return value;
|
|
1680
2027
|
}
|
|
1681
|
-
function
|
|
2028
|
+
function UploadManagerBase_finallyRethrows(body, finalizer) {
|
|
1682
2029
|
try {
|
|
1683
2030
|
var result = body();
|
|
1684
2031
|
} catch (e) {
|
|
@@ -1729,15 +2076,15 @@ var UploadManagerBase = /*#__PURE__*/function () {
|
|
|
1729
2076
|
cancel = _this2$makeCancellati.cancel,
|
|
1730
2077
|
addCancellationHandler = _this2$makeCancellati.addCancellationHandler;
|
|
1731
2078
|
var intervalHandle = setInterval(_this2.onIntervalTick(request, cancel), _this2.intervalMs);
|
|
1732
|
-
return UploadManagerBase_continue(
|
|
2079
|
+
return UploadManagerBase_continue(UploadManagerBase_finallyRethrows(function () {
|
|
1733
2080
|
return UploadManagerBase_await(_this2.mapAsync(parts, preUploadInfo.maxConcurrentUploadParts, _async(function (part) {
|
|
1734
2081
|
return _this2.uploadPart(request, source, part, uploadInfo, onProgress, addCancellationHandler);
|
|
1735
2082
|
})), function () {
|
|
1736
|
-
return
|
|
2083
|
+
return UploadManagerBase_awaitIgnored(_this2.postUpload(init));
|
|
1737
2084
|
});
|
|
1738
2085
|
}, function (_wasThrown, _result) {
|
|
1739
2086
|
clearInterval(intervalHandle);
|
|
1740
|
-
return
|
|
2087
|
+
return UploadManagerBase_rethrow(_wasThrown, _result);
|
|
1741
2088
|
}), function () {
|
|
1742
2089
|
return uploadInfo.file;
|
|
1743
2090
|
});
|
|
@@ -1851,7 +2198,7 @@ var UploadManagerBase = /*#__PURE__*/function () {
|
|
|
1851
2198
|
_this7.assertNotCancelled(request);
|
|
1852
2199
|
return UploadManagerBase_await(_this7.putUploadPart(part, source, onProgress, addCancellationHandler), function (etag) {
|
|
1853
2200
|
_this7.assertNotCancelled(request);
|
|
1854
|
-
return
|
|
2201
|
+
return UploadManagerBase_awaitIgnored(_this7.uploadApi.completeUploadPart({
|
|
1855
2202
|
accountId: request.accountId,
|
|
1856
2203
|
uploadId: uploadInfo.uploadId,
|
|
1857
2204
|
uploadPartIndex: partIndex,
|
|
@@ -1923,14 +2270,14 @@ var UploadManagerBase = /*#__PURE__*/function () {
|
|
|
1923
2270
|
value: function mapAsync(items, concurrency, callback) {
|
|
1924
2271
|
try {
|
|
1925
2272
|
var workQueue = UploadManagerBase_toConsumableArray(items);
|
|
1926
|
-
return
|
|
1927
|
-
return _continueIgnored(
|
|
2273
|
+
return UploadManagerBase_awaitIgnored(Promise.all(UploadManagerBase_toConsumableArray(Array(concurrency).keys()).map(_async(function () {
|
|
2274
|
+
return _continueIgnored(UploadManagerBase_for(function () {
|
|
1928
2275
|
return workQueue.length > 0;
|
|
1929
2276
|
}, void 0, function () {
|
|
1930
2277
|
var work = workQueue.shift(); // IMPORTANT: use 'shift' instead of 'pop' to ensure 'items' are processed in order when 'concurrency = 1'.
|
|
1931
2278
|
return _invokeIgnored(function () {
|
|
1932
2279
|
if (work !== undefined) {
|
|
1933
|
-
return
|
|
2280
|
+
return UploadManagerBase_awaitIgnored(callback(work));
|
|
1934
2281
|
}
|
|
1935
2282
|
});
|
|
1936
2283
|
}));
|