@snail-js/api 0.1.28 → 1.0.0
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/LICENSE +21 -0
- package/README.md +125 -605
- package/dist/adapter/plain.d.ts +12 -0
- package/dist/adapter/plain.d.ts.map +1 -0
- package/dist/adapter/react.d.ts +14 -0
- package/dist/adapter/react.d.ts.map +1 -0
- package/dist/adapter/registry.d.ts +16 -0
- package/dist/adapter/registry.d.ts.map +1 -0
- package/dist/adapter/vue.d.ts +15 -0
- package/dist/adapter/vue.d.ts.map +1 -0
- package/dist/chunks/custom-UchOSg_s.js +466 -0
- package/dist/chunks/custom-UchOSg_s.js.map +1 -0
- package/dist/chunks/download-lBC7oOTT.js +160 -0
- package/dist/chunks/download-lBC7oOTT.js.map +1 -0
- package/dist/chunks/object-Ct0w-h4i.js +74 -0
- package/dist/chunks/object-Ct0w-h4i.js.map +1 -0
- package/dist/chunks/plugin-D3RDffDG.js +742 -0
- package/dist/chunks/plugin-D3RDffDG.js.map +1 -0
- package/dist/chunks/react-C1em-gxy.js +62 -0
- package/dist/chunks/react-C1em-gxy.js.map +1 -0
- package/dist/chunks/request-qeRhihEF.js +40 -0
- package/dist/chunks/request-qeRhihEF.js.map +1 -0
- package/dist/chunks/response-D-ubkAFl.js +127 -0
- package/dist/chunks/response-D-ubkAFl.js.map +1 -0
- package/dist/chunks/use-download-FAjtdJ58.js +1816 -0
- package/dist/chunks/use-download-FAjtdJ58.js.map +1 -0
- package/dist/chunks/vue-Dd9EhkQ3.js +34 -0
- package/dist/chunks/vue-Dd9EhkQ3.js.map +1 -0
- package/dist/core/args.d.ts +54 -0
- package/dist/core/args.d.ts.map +1 -0
- package/dist/core/connection.d.ts +15 -0
- package/dist/core/connection.d.ts.map +1 -0
- package/dist/core/context.d.ts +124 -0
- package/dist/core/context.d.ts.map +1 -0
- package/dist/core/http-stream.d.ts +28 -0
- package/dist/core/http-stream.d.ts.map +1 -0
- package/dist/core/logger.d.ts +22 -0
- package/dist/core/logger.d.ts.map +1 -0
- package/dist/core/metadata.d.ts +92 -0
- package/dist/core/metadata.d.ts.map +1 -0
- package/dist/core/metadata.keys.d.ts +41 -0
- package/dist/core/metadata.keys.d.ts.map +1 -0
- package/dist/core/method.d.ts +177 -0
- package/dist/core/method.d.ts.map +1 -0
- package/dist/core/plugin-manager.d.ts +106 -0
- package/dist/core/plugin-manager.d.ts.map +1 -0
- package/dist/core/plugin.d.ts +113 -0
- package/dist/core/plugin.d.ts.map +1 -0
- package/dist/core/reconnect.d.ts +22 -0
- package/dist/core/reconnect.d.ts.map +1 -0
- package/dist/core/resolve-stream.d.ts +45 -0
- package/dist/core/resolve-stream.d.ts.map +1 -0
- package/dist/core/resolve.d.ts +50 -0
- package/dist/core/resolve.d.ts.map +1 -0
- package/dist/core/response.d.ts +60 -0
- package/dist/core/response.d.ts.map +1 -0
- package/dist/core/server.d.ts +132 -0
- package/dist/core/server.d.ts.map +1 -0
- package/dist/core/sse.d.ts +27 -0
- package/dist/core/sse.d.ts.map +1 -0
- package/dist/core/state-bag.d.ts +36 -0
- package/dist/core/state-bag.d.ts.map +1 -0
- package/dist/core/websocket.d.ts +29 -0
- package/dist/core/websocket.d.ts.map +1 -0
- package/dist/decorators/api.d.ts +24 -4
- package/dist/decorators/api.d.ts.map +1 -0
- package/dist/decorators/args.d.ts +77 -14
- package/dist/decorators/args.d.ts.map +1 -0
- package/dist/decorators/custom.d.ts +81 -0
- package/dist/decorators/custom.d.ts.map +1 -0
- package/dist/decorators/header.d.ts +22 -0
- package/dist/decorators/header.d.ts.map +1 -0
- package/dist/decorators/index.d.ts +17 -0
- package/dist/decorators/index.d.ts.map +1 -0
- package/dist/decorators/methods.d.ts +33 -0
- package/dist/decorators/methods.d.ts.map +1 -0
- package/dist/decorators/progress.d.ts +24 -6
- package/dist/decorators/progress.d.ts.map +1 -0
- package/dist/decorators/server.d.ts +28 -7
- package/dist/decorators/server.d.ts.map +1 -0
- package/dist/decorators/stream.d.ts +113 -0
- package/dist/decorators/stream.d.ts.map +1 -0
- package/dist/default/options.d.ts +19 -0
- package/dist/default/options.d.ts.map +1 -0
- package/dist/error/base.d.ts +20 -0
- package/dist/error/base.d.ts.map +1 -0
- package/dist/error/decorator.d.ts +14 -0
- package/dist/error/decorator.d.ts.map +1 -0
- package/dist/error/hook.d.ts +14 -0
- package/dist/error/hook.d.ts.map +1 -0
- package/dist/error/index.d.ts +8 -0
- package/dist/error/index.d.ts.map +1 -0
- package/dist/error/options.d.ts +12 -0
- package/dist/error/options.d.ts.map +1 -0
- package/dist/error/plugin.d.ts +11 -0
- package/dist/error/plugin.d.ts.map +1 -0
- package/dist/error/request.d.ts +29 -0
- package/dist/error/request.d.ts.map +1 -0
- package/dist/error/response.d.ts +36 -0
- package/dist/error/response.d.ts.map +1 -0
- package/dist/index.d.ts +56 -11
- package/dist/index.d.ts.map +1 -0
- package/dist/index.js +2034 -0
- package/dist/index.js.map +1 -0
- package/dist/locale/en.d.ts +5 -0
- package/dist/locale/en.d.ts.map +1 -0
- package/dist/locale/index.d.ts +57 -0
- package/dist/locale/index.d.ts.map +1 -0
- package/dist/locale/types.d.ts +11 -0
- package/dist/locale/types.d.ts.map +1 -0
- package/dist/locale/zh.d.ts +5 -0
- package/dist/locale/zh.d.ts.map +1 -0
- package/dist/plugins/cache/adapters/indexeddb.d.ts +52 -0
- package/dist/plugins/cache/adapters/indexeddb.d.ts.map +1 -0
- package/dist/plugins/cache/adapters/memory.d.ts +60 -0
- package/dist/plugins/cache/adapters/memory.d.ts.map +1 -0
- package/dist/plugins/cache/adapters/web-storage.d.ts +43 -0
- package/dist/plugins/cache/adapters/web-storage.d.ts.map +1 -0
- package/dist/plugins/cache/decorators.d.ts +62 -0
- package/dist/plugins/cache/decorators.d.ts.map +1 -0
- package/dist/plugins/cache/index.d.ts +41 -0
- package/dist/plugins/cache/index.d.ts.map +1 -0
- package/dist/plugins/cache/key.d.ts +48 -0
- package/dist/plugins/cache/key.d.ts.map +1 -0
- package/dist/plugins/cache/manager.d.ts +124 -0
- package/dist/plugins/cache/manager.d.ts.map +1 -0
- package/dist/plugins/cache/plugin.d.ts +64 -0
- package/dist/plugins/cache/plugin.d.ts.map +1 -0
- package/dist/plugins/cache/type.d.ts +116 -0
- package/dist/plugins/cache/type.d.ts.map +1 -0
- package/dist/plugins/index.d.ts +75 -0
- package/dist/plugins/index.d.ts.map +1 -0
- package/dist/plugins/index.js +2265 -0
- package/dist/plugins/index.js.map +1 -0
- package/dist/plugins/interceptor/decorators.d.ts +44 -0
- package/dist/plugins/interceptor/decorators.d.ts.map +1 -0
- package/dist/plugins/interceptor/index.d.ts +31 -0
- package/dist/plugins/interceptor/index.d.ts.map +1 -0
- package/dist/plugins/interceptor/manager.d.ts +27 -0
- package/dist/plugins/interceptor/manager.d.ts.map +1 -0
- package/dist/plugins/interceptor/plugin.d.ts +65 -0
- package/dist/plugins/interceptor/plugin.d.ts.map +1 -0
- package/dist/plugins/interceptor/type.d.ts +45 -0
- package/dist/plugins/interceptor/type.d.ts.map +1 -0
- package/dist/plugins/pool/index.d.ts +26 -0
- package/dist/plugins/pool/index.d.ts.map +1 -0
- package/dist/plugins/pool/plugin.d.ts +83 -0
- package/dist/plugins/pool/plugin.d.ts.map +1 -0
- package/dist/plugins/pool/scheduler.d.ts +153 -0
- package/dist/plugins/pool/scheduler.d.ts.map +1 -0
- package/dist/plugins/pool/type.d.ts +38 -0
- package/dist/plugins/pool/type.d.ts.map +1 -0
- package/dist/plugins/react/index.d.ts +20 -0
- package/dist/plugins/react/index.d.ts.map +1 -0
- package/dist/plugins/react/index.js +145 -0
- package/dist/plugins/react/index.js.map +1 -0
- package/dist/plugins/react/plugin.d.ts +33 -0
- package/dist/plugins/react/plugin.d.ts.map +1 -0
- package/dist/plugins/react/type.d.ts +32 -0
- package/dist/plugins/react/type.d.ts.map +1 -0
- package/dist/plugins/transform/decorators.d.ts +54 -0
- package/dist/plugins/transform/decorators.d.ts.map +1 -0
- package/dist/plugins/transform/hydrate.d.ts +47 -0
- package/dist/plugins/transform/hydrate.d.ts.map +1 -0
- package/dist/plugins/transform/index.d.ts +41 -0
- package/dist/plugins/transform/index.d.ts.map +1 -0
- package/dist/plugins/transform/plugin.d.ts +20 -0
- package/dist/plugins/transform/plugin.d.ts.map +1 -0
- package/dist/plugins/transform/type.d.ts +67 -0
- package/dist/plugins/transform/type.d.ts.map +1 -0
- package/dist/plugins/validate/decorators.d.ts +24 -0
- package/dist/plugins/validate/decorators.d.ts.map +1 -0
- package/dist/plugins/validate/index.d.ts +40 -0
- package/dist/plugins/validate/index.d.ts.map +1 -0
- package/dist/plugins/validate/plugin.d.ts +13 -0
- package/dist/plugins/validate/plugin.d.ts.map +1 -0
- package/dist/plugins/validate/type.d.ts +54 -0
- package/dist/plugins/validate/type.d.ts.map +1 -0
- package/dist/plugins/version/decorators.d.ts +22 -0
- package/dist/plugins/version/decorators.d.ts.map +1 -0
- package/dist/plugins/version/index.d.ts +23 -0
- package/dist/plugins/version/index.d.ts.map +1 -0
- package/dist/plugins/version/plugin.d.ts +13 -0
- package/dist/plugins/version/plugin.d.ts.map +1 -0
- package/dist/plugins/version/type.d.ts +47 -0
- package/dist/plugins/version/type.d.ts.map +1 -0
- package/dist/plugins/vue/index.d.ts +21 -0
- package/dist/plugins/vue/index.d.ts.map +1 -0
- package/dist/plugins/vue/index.js +114 -0
- package/dist/plugins/vue/index.js.map +1 -0
- package/dist/plugins/vue/plugin.d.ts +15 -0
- package/dist/plugins/vue/plugin.d.ts.map +1 -0
- package/dist/plugins/vue/type.d.ts +34 -0
- package/dist/plugins/vue/type.d.ts.map +1 -0
- package/dist/strategies/index.d.ts +2 -0
- package/dist/strategies/index.d.ts.map +1 -0
- package/dist/strategies/index.js +29 -0
- package/dist/strategies/index.js.map +1 -0
- package/dist/strategies/plain.d.ts +2 -0
- package/dist/strategies/plain.d.ts.map +1 -0
- package/dist/strategies/plain.js +23 -0
- package/dist/strategies/plain.js.map +1 -0
- package/dist/strategies/react.d.ts +2 -0
- package/dist/strategies/react.d.ts.map +1 -0
- package/dist/strategies/react.js +30 -0
- package/dist/strategies/react.js.map +1 -0
- package/dist/strategies/shared/adapter.d.ts +23 -0
- package/dist/strategies/shared/adapter.d.ts.map +1 -0
- package/dist/strategies/shared/dom.d.ts +53 -0
- package/dist/strategies/shared/dom.d.ts.map +1 -0
- package/dist/strategies/shared/error.d.ts +30 -0
- package/dist/strategies/shared/error.d.ts.map +1 -0
- package/dist/strategies/shared/method.d.ts +51 -0
- package/dist/strategies/shared/method.d.ts.map +1 -0
- package/dist/strategies/shared/public.d.ts +33 -0
- package/dist/strategies/shared/public.d.ts.map +1 -0
- package/dist/strategies/shared/queue.d.ts +30 -0
- package/dist/strategies/shared/queue.d.ts.map +1 -0
- package/dist/strategies/shared/retry.d.ts +51 -0
- package/dist/strategies/shared/retry.d.ts.map +1 -0
- package/dist/strategies/shared/state.d.ts +117 -0
- package/dist/strategies/shared/state.d.ts.map +1 -0
- package/dist/strategies/shared/timing.d.ts +53 -0
- package/dist/strategies/shared/timing.d.ts.map +1 -0
- package/dist/strategies/shared/watcher.d.ts +37 -0
- package/dist/strategies/shared/watcher.d.ts.map +1 -0
- package/dist/strategies/use-auto-request.d.ts +77 -0
- package/dist/strategies/use-auto-request.d.ts.map +1 -0
- package/dist/strategies/use-download.d.ts +103 -0
- package/dist/strategies/use-download.d.ts.map +1 -0
- package/dist/strategies/use-fetcher.d.ts +52 -0
- package/dist/strategies/use-fetcher.d.ts.map +1 -0
- package/dist/strategies/use-pagination.d.ts +101 -0
- package/dist/strategies/use-pagination.d.ts.map +1 -0
- package/dist/strategies/use-request.d.ts +50 -0
- package/dist/strategies/use-request.d.ts.map +1 -0
- package/dist/strategies/use-retriable-request.d.ts +46 -0
- package/dist/strategies/use-retriable-request.d.ts.map +1 -0
- package/dist/strategies/use-sse.d.ts +103 -0
- package/dist/strategies/use-sse.d.ts.map +1 -0
- package/dist/strategies/use-token-auth.d.ts +88 -0
- package/dist/strategies/use-token-auth.d.ts.map +1 -0
- package/dist/strategies/use-uploader.d.ts +88 -0
- package/dist/strategies/use-uploader.d.ts.map +1 -0
- package/dist/strategies/use-watcher.d.ts +69 -0
- package/dist/strategies/use-watcher.d.ts.map +1 -0
- package/dist/typings/adapter.d.ts +61 -0
- package/dist/typings/adapter.d.ts.map +1 -0
- package/dist/typings/api.d.ts +122 -0
- package/dist/typings/api.d.ts.map +1 -0
- package/dist/typings/args.d.ts +51 -0
- package/dist/typings/args.d.ts.map +1 -0
- package/dist/typings/index.d.ts +8 -12
- package/dist/typings/index.d.ts.map +1 -0
- package/dist/typings/meta.d.ts +44 -0
- package/dist/typings/meta.d.ts.map +1 -0
- package/dist/typings/plugin.d.ts +114 -0
- package/dist/typings/plugin.d.ts.map +1 -0
- package/dist/typings/response.d.ts +118 -0
- package/dist/typings/response.d.ts.map +1 -0
- package/dist/typings/server.d.ts +83 -0
- package/dist/typings/server.d.ts.map +1 -0
- package/dist/typings/stream.d.ts +150 -0
- package/dist/typings/stream.d.ts.map +1 -0
- package/dist/utils/download.d.ts +97 -0
- package/dist/utils/download.d.ts.map +1 -0
- package/dist/utils/emitter.d.ts +36 -0
- package/dist/utils/emitter.d.ts.map +1 -0
- package/dist/utils/index.d.ts +6 -1
- package/dist/utils/index.d.ts.map +1 -0
- package/dist/utils/is.d.ts +22 -0
- package/dist/utils/is.d.ts.map +1 -0
- package/dist/utils/object.d.ts +44 -0
- package/dist/utils/object.d.ts.map +1 -0
- package/dist/utils/url.d.ts +44 -0
- package/dist/utils/url.d.ts.map +1 -0
- package/package.json +90 -27
- package/README_EN.md +0 -607
- package/dist/cache/index.d.ts +0 -9
- package/dist/cache/indexDBCache.d.ts +0 -13
- package/dist/cache/localstorageCache.d.ts +0 -10
- package/dist/cache/memoryCache.d.ts +0 -11
- package/dist/core/index.d.ts +0 -4
- package/dist/core/snailApi.d.ts +0 -22
- package/dist/core/snailMethod.d.ts +0 -49
- package/dist/core/snailServer.d.ts +0 -35
- package/dist/core/snailSse.d.ts +0 -20
- package/dist/decorators/cache.d.ts +0 -15
- package/dist/decorators/method.d.ts +0 -38
- package/dist/decorators/sse.d.ts +0 -30
- package/dist/decorators/strategy.d.ts +0 -10
- package/dist/decorators/versioning.d.ts +0 -16
- package/dist/eventEmmit/index.d.ts +0 -1
- package/dist/eventEmmit/snail.event.d.ts +0 -10
- package/dist/snail-api.js +0 -4871
- package/dist/snail-api.umd.cjs +0 -4875
- package/dist/strategies/jwtStrategy.d.ts +0 -4
- package/dist/typings/api.option.d.ts +0 -10
- package/dist/typings/apiProxy.d.ts +0 -8
- package/dist/typings/cache.management.option.d.ts +0 -25
- package/dist/typings/cache.type.d.ts +0 -23
- package/dist/typings/content.type.d.ts +0 -5
- package/dist/typings/request.body.d.ts +0 -3
- package/dist/typings/response.data.d.ts +0 -13
- package/dist/typings/snail.event.d.ts +0 -6
- package/dist/typings/snail.method.d.ts +0 -14
- package/dist/typings/snail.option.d.ts +0 -16
- package/dist/typings/sse.d.ts +0 -15
- package/dist/typings/strategy.d.ts +0 -5
- package/dist/typings/versioning.option.d.ts +0 -30
- package/dist/utils/function.d.ts +0 -31
- package/dist/versioning/index.d.ts +0 -1
- package/dist/versioning/versioning.d.ts +0 -12
package/dist/snail-api.js
DELETED
|
@@ -1,4871 +0,0 @@
|
|
|
1
|
-
var __defProp = Object.defineProperty;
|
|
2
|
-
var __defNormalProp = (obj, key, value) => key in obj ? __defProp(obj, key, { enumerable: true, configurable: true, writable: true, value }) : obj[key] = value;
|
|
3
|
-
var __publicField = (obj, key, value) => __defNormalProp(obj, typeof key !== "symbol" ? key + "" : key, value);
|
|
4
|
-
var commonjsGlobal = typeof globalThis !== "undefined" ? globalThis : typeof window !== "undefined" ? window : typeof global !== "undefined" ? global : typeof self !== "undefined" ? self : {};
|
|
5
|
-
/*! *****************************************************************************
|
|
6
|
-
Copyright (C) Microsoft. All rights reserved.
|
|
7
|
-
Licensed under the Apache License, Version 2.0 (the "License"); you may not use
|
|
8
|
-
this file except in compliance with the License. You may obtain a copy of the
|
|
9
|
-
License at http://www.apache.org/licenses/LICENSE-2.0
|
|
10
|
-
|
|
11
|
-
THIS CODE IS PROVIDED ON AN *AS IS* BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
|
|
12
|
-
KIND, EITHER EXPRESS OR IMPLIED, INCLUDING WITHOUT LIMITATION ANY IMPLIED
|
|
13
|
-
WARRANTIES OR CONDITIONS OF TITLE, FITNESS FOR A PARTICULAR PURPOSE,
|
|
14
|
-
MERCHANTABLITY OR NON-INFRINGEMENT.
|
|
15
|
-
|
|
16
|
-
See the Apache Version 2.0 License for specific language governing permissions
|
|
17
|
-
and limitations under the License.
|
|
18
|
-
***************************************************************************** */
|
|
19
|
-
var Reflect$1;
|
|
20
|
-
(function(Reflect2) {
|
|
21
|
-
(function(factory) {
|
|
22
|
-
var root = typeof globalThis === "object" ? globalThis : typeof commonjsGlobal === "object" ? commonjsGlobal : typeof self === "object" ? self : typeof this === "object" ? this : sloppyModeThis();
|
|
23
|
-
var exporter = makeExporter(Reflect2);
|
|
24
|
-
if (typeof root.Reflect !== "undefined") {
|
|
25
|
-
exporter = makeExporter(root.Reflect, exporter);
|
|
26
|
-
}
|
|
27
|
-
factory(exporter, root);
|
|
28
|
-
if (typeof root.Reflect === "undefined") {
|
|
29
|
-
root.Reflect = Reflect2;
|
|
30
|
-
}
|
|
31
|
-
function makeExporter(target, previous) {
|
|
32
|
-
return function(key, value) {
|
|
33
|
-
Object.defineProperty(target, key, { configurable: true, writable: true, value });
|
|
34
|
-
if (previous)
|
|
35
|
-
previous(key, value);
|
|
36
|
-
};
|
|
37
|
-
}
|
|
38
|
-
function functionThis() {
|
|
39
|
-
try {
|
|
40
|
-
return Function("return this;")();
|
|
41
|
-
} catch (_) {
|
|
42
|
-
}
|
|
43
|
-
}
|
|
44
|
-
function indirectEvalThis() {
|
|
45
|
-
try {
|
|
46
|
-
return (void 0, eval)("(function() { return this; })()");
|
|
47
|
-
} catch (_) {
|
|
48
|
-
}
|
|
49
|
-
}
|
|
50
|
-
function sloppyModeThis() {
|
|
51
|
-
return functionThis() || indirectEvalThis();
|
|
52
|
-
}
|
|
53
|
-
})(function(exporter, root) {
|
|
54
|
-
var hasOwn = Object.prototype.hasOwnProperty;
|
|
55
|
-
var supportsSymbol = typeof Symbol === "function";
|
|
56
|
-
var toPrimitiveSymbol = supportsSymbol && typeof Symbol.toPrimitive !== "undefined" ? Symbol.toPrimitive : "@@toPrimitive";
|
|
57
|
-
var iteratorSymbol = supportsSymbol && typeof Symbol.iterator !== "undefined" ? Symbol.iterator : "@@iterator";
|
|
58
|
-
var supportsCreate = typeof Object.create === "function";
|
|
59
|
-
var supportsProto = { __proto__: [] } instanceof Array;
|
|
60
|
-
var downLevel = !supportsCreate && !supportsProto;
|
|
61
|
-
var HashMap = {
|
|
62
|
-
// create an object in dictionary mode (a.k.a. "slow" mode in v8)
|
|
63
|
-
create: supportsCreate ? function() {
|
|
64
|
-
return MakeDictionary(/* @__PURE__ */ Object.create(null));
|
|
65
|
-
} : supportsProto ? function() {
|
|
66
|
-
return MakeDictionary({ __proto__: null });
|
|
67
|
-
} : function() {
|
|
68
|
-
return MakeDictionary({});
|
|
69
|
-
},
|
|
70
|
-
has: downLevel ? function(map, key) {
|
|
71
|
-
return hasOwn.call(map, key);
|
|
72
|
-
} : function(map, key) {
|
|
73
|
-
return key in map;
|
|
74
|
-
},
|
|
75
|
-
get: downLevel ? function(map, key) {
|
|
76
|
-
return hasOwn.call(map, key) ? map[key] : void 0;
|
|
77
|
-
} : function(map, key) {
|
|
78
|
-
return map[key];
|
|
79
|
-
}
|
|
80
|
-
};
|
|
81
|
-
var functionPrototype = Object.getPrototypeOf(Function);
|
|
82
|
-
var _Map = typeof Map === "function" && typeof Map.prototype.entries === "function" ? Map : CreateMapPolyfill();
|
|
83
|
-
var _Set = typeof Set === "function" && typeof Set.prototype.entries === "function" ? Set : CreateSetPolyfill();
|
|
84
|
-
var _WeakMap = typeof WeakMap === "function" ? WeakMap : CreateWeakMapPolyfill();
|
|
85
|
-
var registrySymbol = supportsSymbol ? Symbol.for("@reflect-metadata:registry") : void 0;
|
|
86
|
-
var metadataRegistry = GetOrCreateMetadataRegistry();
|
|
87
|
-
var metadataProvider = CreateMetadataProvider(metadataRegistry);
|
|
88
|
-
function decorate(decorators, target, propertyKey, attributes) {
|
|
89
|
-
if (!IsUndefined(propertyKey)) {
|
|
90
|
-
if (!IsArray(decorators))
|
|
91
|
-
throw new TypeError();
|
|
92
|
-
if (!IsObject(target))
|
|
93
|
-
throw new TypeError();
|
|
94
|
-
if (!IsObject(attributes) && !IsUndefined(attributes) && !IsNull(attributes))
|
|
95
|
-
throw new TypeError();
|
|
96
|
-
if (IsNull(attributes))
|
|
97
|
-
attributes = void 0;
|
|
98
|
-
propertyKey = ToPropertyKey(propertyKey);
|
|
99
|
-
return DecorateProperty(decorators, target, propertyKey, attributes);
|
|
100
|
-
} else {
|
|
101
|
-
if (!IsArray(decorators))
|
|
102
|
-
throw new TypeError();
|
|
103
|
-
if (!IsConstructor(target))
|
|
104
|
-
throw new TypeError();
|
|
105
|
-
return DecorateConstructor(decorators, target);
|
|
106
|
-
}
|
|
107
|
-
}
|
|
108
|
-
exporter("decorate", decorate);
|
|
109
|
-
function metadata(metadataKey, metadataValue) {
|
|
110
|
-
function decorator(target, propertyKey) {
|
|
111
|
-
if (!IsObject(target))
|
|
112
|
-
throw new TypeError();
|
|
113
|
-
if (!IsUndefined(propertyKey) && !IsPropertyKey(propertyKey))
|
|
114
|
-
throw new TypeError();
|
|
115
|
-
OrdinaryDefineOwnMetadata(metadataKey, metadataValue, target, propertyKey);
|
|
116
|
-
}
|
|
117
|
-
return decorator;
|
|
118
|
-
}
|
|
119
|
-
exporter("metadata", metadata);
|
|
120
|
-
function defineMetadata(metadataKey, metadataValue, target, propertyKey) {
|
|
121
|
-
if (!IsObject(target))
|
|
122
|
-
throw new TypeError();
|
|
123
|
-
if (!IsUndefined(propertyKey))
|
|
124
|
-
propertyKey = ToPropertyKey(propertyKey);
|
|
125
|
-
return OrdinaryDefineOwnMetadata(metadataKey, metadataValue, target, propertyKey);
|
|
126
|
-
}
|
|
127
|
-
exporter("defineMetadata", defineMetadata);
|
|
128
|
-
function hasMetadata(metadataKey, target, propertyKey) {
|
|
129
|
-
if (!IsObject(target))
|
|
130
|
-
throw new TypeError();
|
|
131
|
-
if (!IsUndefined(propertyKey))
|
|
132
|
-
propertyKey = ToPropertyKey(propertyKey);
|
|
133
|
-
return OrdinaryHasMetadata(metadataKey, target, propertyKey);
|
|
134
|
-
}
|
|
135
|
-
exporter("hasMetadata", hasMetadata);
|
|
136
|
-
function hasOwnMetadata(metadataKey, target, propertyKey) {
|
|
137
|
-
if (!IsObject(target))
|
|
138
|
-
throw new TypeError();
|
|
139
|
-
if (!IsUndefined(propertyKey))
|
|
140
|
-
propertyKey = ToPropertyKey(propertyKey);
|
|
141
|
-
return OrdinaryHasOwnMetadata(metadataKey, target, propertyKey);
|
|
142
|
-
}
|
|
143
|
-
exporter("hasOwnMetadata", hasOwnMetadata);
|
|
144
|
-
function getMetadata(metadataKey, target, propertyKey) {
|
|
145
|
-
if (!IsObject(target))
|
|
146
|
-
throw new TypeError();
|
|
147
|
-
if (!IsUndefined(propertyKey))
|
|
148
|
-
propertyKey = ToPropertyKey(propertyKey);
|
|
149
|
-
return OrdinaryGetMetadata(metadataKey, target, propertyKey);
|
|
150
|
-
}
|
|
151
|
-
exporter("getMetadata", getMetadata);
|
|
152
|
-
function getOwnMetadata(metadataKey, target, propertyKey) {
|
|
153
|
-
if (!IsObject(target))
|
|
154
|
-
throw new TypeError();
|
|
155
|
-
if (!IsUndefined(propertyKey))
|
|
156
|
-
propertyKey = ToPropertyKey(propertyKey);
|
|
157
|
-
return OrdinaryGetOwnMetadata(metadataKey, target, propertyKey);
|
|
158
|
-
}
|
|
159
|
-
exporter("getOwnMetadata", getOwnMetadata);
|
|
160
|
-
function getMetadataKeys(target, propertyKey) {
|
|
161
|
-
if (!IsObject(target))
|
|
162
|
-
throw new TypeError();
|
|
163
|
-
if (!IsUndefined(propertyKey))
|
|
164
|
-
propertyKey = ToPropertyKey(propertyKey);
|
|
165
|
-
return OrdinaryMetadataKeys(target, propertyKey);
|
|
166
|
-
}
|
|
167
|
-
exporter("getMetadataKeys", getMetadataKeys);
|
|
168
|
-
function getOwnMetadataKeys(target, propertyKey) {
|
|
169
|
-
if (!IsObject(target))
|
|
170
|
-
throw new TypeError();
|
|
171
|
-
if (!IsUndefined(propertyKey))
|
|
172
|
-
propertyKey = ToPropertyKey(propertyKey);
|
|
173
|
-
return OrdinaryOwnMetadataKeys(target, propertyKey);
|
|
174
|
-
}
|
|
175
|
-
exporter("getOwnMetadataKeys", getOwnMetadataKeys);
|
|
176
|
-
function deleteMetadata(metadataKey, target, propertyKey) {
|
|
177
|
-
if (!IsObject(target))
|
|
178
|
-
throw new TypeError();
|
|
179
|
-
if (!IsUndefined(propertyKey))
|
|
180
|
-
propertyKey = ToPropertyKey(propertyKey);
|
|
181
|
-
if (!IsObject(target))
|
|
182
|
-
throw new TypeError();
|
|
183
|
-
if (!IsUndefined(propertyKey))
|
|
184
|
-
propertyKey = ToPropertyKey(propertyKey);
|
|
185
|
-
var provider = GetMetadataProvider(
|
|
186
|
-
target,
|
|
187
|
-
propertyKey,
|
|
188
|
-
/*Create*/
|
|
189
|
-
false
|
|
190
|
-
);
|
|
191
|
-
if (IsUndefined(provider))
|
|
192
|
-
return false;
|
|
193
|
-
return provider.OrdinaryDeleteMetadata(metadataKey, target, propertyKey);
|
|
194
|
-
}
|
|
195
|
-
exporter("deleteMetadata", deleteMetadata);
|
|
196
|
-
function DecorateConstructor(decorators, target) {
|
|
197
|
-
for (var i = decorators.length - 1; i >= 0; --i) {
|
|
198
|
-
var decorator = decorators[i];
|
|
199
|
-
var decorated = decorator(target);
|
|
200
|
-
if (!IsUndefined(decorated) && !IsNull(decorated)) {
|
|
201
|
-
if (!IsConstructor(decorated))
|
|
202
|
-
throw new TypeError();
|
|
203
|
-
target = decorated;
|
|
204
|
-
}
|
|
205
|
-
}
|
|
206
|
-
return target;
|
|
207
|
-
}
|
|
208
|
-
function DecorateProperty(decorators, target, propertyKey, descriptor) {
|
|
209
|
-
for (var i = decorators.length - 1; i >= 0; --i) {
|
|
210
|
-
var decorator = decorators[i];
|
|
211
|
-
var decorated = decorator(target, propertyKey, descriptor);
|
|
212
|
-
if (!IsUndefined(decorated) && !IsNull(decorated)) {
|
|
213
|
-
if (!IsObject(decorated))
|
|
214
|
-
throw new TypeError();
|
|
215
|
-
descriptor = decorated;
|
|
216
|
-
}
|
|
217
|
-
}
|
|
218
|
-
return descriptor;
|
|
219
|
-
}
|
|
220
|
-
function OrdinaryHasMetadata(MetadataKey, O, P) {
|
|
221
|
-
var hasOwn2 = OrdinaryHasOwnMetadata(MetadataKey, O, P);
|
|
222
|
-
if (hasOwn2)
|
|
223
|
-
return true;
|
|
224
|
-
var parent = OrdinaryGetPrototypeOf(O);
|
|
225
|
-
if (!IsNull(parent))
|
|
226
|
-
return OrdinaryHasMetadata(MetadataKey, parent, P);
|
|
227
|
-
return false;
|
|
228
|
-
}
|
|
229
|
-
function OrdinaryHasOwnMetadata(MetadataKey, O, P) {
|
|
230
|
-
var provider = GetMetadataProvider(
|
|
231
|
-
O,
|
|
232
|
-
P,
|
|
233
|
-
/*Create*/
|
|
234
|
-
false
|
|
235
|
-
);
|
|
236
|
-
if (IsUndefined(provider))
|
|
237
|
-
return false;
|
|
238
|
-
return ToBoolean(provider.OrdinaryHasOwnMetadata(MetadataKey, O, P));
|
|
239
|
-
}
|
|
240
|
-
function OrdinaryGetMetadata(MetadataKey, O, P) {
|
|
241
|
-
var hasOwn2 = OrdinaryHasOwnMetadata(MetadataKey, O, P);
|
|
242
|
-
if (hasOwn2)
|
|
243
|
-
return OrdinaryGetOwnMetadata(MetadataKey, O, P);
|
|
244
|
-
var parent = OrdinaryGetPrototypeOf(O);
|
|
245
|
-
if (!IsNull(parent))
|
|
246
|
-
return OrdinaryGetMetadata(MetadataKey, parent, P);
|
|
247
|
-
return void 0;
|
|
248
|
-
}
|
|
249
|
-
function OrdinaryGetOwnMetadata(MetadataKey, O, P) {
|
|
250
|
-
var provider = GetMetadataProvider(
|
|
251
|
-
O,
|
|
252
|
-
P,
|
|
253
|
-
/*Create*/
|
|
254
|
-
false
|
|
255
|
-
);
|
|
256
|
-
if (IsUndefined(provider))
|
|
257
|
-
return;
|
|
258
|
-
return provider.OrdinaryGetOwnMetadata(MetadataKey, O, P);
|
|
259
|
-
}
|
|
260
|
-
function OrdinaryDefineOwnMetadata(MetadataKey, MetadataValue, O, P) {
|
|
261
|
-
var provider = GetMetadataProvider(
|
|
262
|
-
O,
|
|
263
|
-
P,
|
|
264
|
-
/*Create*/
|
|
265
|
-
true
|
|
266
|
-
);
|
|
267
|
-
provider.OrdinaryDefineOwnMetadata(MetadataKey, MetadataValue, O, P);
|
|
268
|
-
}
|
|
269
|
-
function OrdinaryMetadataKeys(O, P) {
|
|
270
|
-
var ownKeys = OrdinaryOwnMetadataKeys(O, P);
|
|
271
|
-
var parent = OrdinaryGetPrototypeOf(O);
|
|
272
|
-
if (parent === null)
|
|
273
|
-
return ownKeys;
|
|
274
|
-
var parentKeys = OrdinaryMetadataKeys(parent, P);
|
|
275
|
-
if (parentKeys.length <= 0)
|
|
276
|
-
return ownKeys;
|
|
277
|
-
if (ownKeys.length <= 0)
|
|
278
|
-
return parentKeys;
|
|
279
|
-
var set = new _Set();
|
|
280
|
-
var keys = [];
|
|
281
|
-
for (var _i = 0, ownKeys_1 = ownKeys; _i < ownKeys_1.length; _i++) {
|
|
282
|
-
var key = ownKeys_1[_i];
|
|
283
|
-
var hasKey = set.has(key);
|
|
284
|
-
if (!hasKey) {
|
|
285
|
-
set.add(key);
|
|
286
|
-
keys.push(key);
|
|
287
|
-
}
|
|
288
|
-
}
|
|
289
|
-
for (var _a = 0, parentKeys_1 = parentKeys; _a < parentKeys_1.length; _a++) {
|
|
290
|
-
var key = parentKeys_1[_a];
|
|
291
|
-
var hasKey = set.has(key);
|
|
292
|
-
if (!hasKey) {
|
|
293
|
-
set.add(key);
|
|
294
|
-
keys.push(key);
|
|
295
|
-
}
|
|
296
|
-
}
|
|
297
|
-
return keys;
|
|
298
|
-
}
|
|
299
|
-
function OrdinaryOwnMetadataKeys(O, P) {
|
|
300
|
-
var provider = GetMetadataProvider(
|
|
301
|
-
O,
|
|
302
|
-
P,
|
|
303
|
-
/*create*/
|
|
304
|
-
false
|
|
305
|
-
);
|
|
306
|
-
if (!provider) {
|
|
307
|
-
return [];
|
|
308
|
-
}
|
|
309
|
-
return provider.OrdinaryOwnMetadataKeys(O, P);
|
|
310
|
-
}
|
|
311
|
-
function Type(x) {
|
|
312
|
-
if (x === null)
|
|
313
|
-
return 1;
|
|
314
|
-
switch (typeof x) {
|
|
315
|
-
case "undefined":
|
|
316
|
-
return 0;
|
|
317
|
-
case "boolean":
|
|
318
|
-
return 2;
|
|
319
|
-
case "string":
|
|
320
|
-
return 3;
|
|
321
|
-
case "symbol":
|
|
322
|
-
return 4;
|
|
323
|
-
case "number":
|
|
324
|
-
return 5;
|
|
325
|
-
case "object":
|
|
326
|
-
return x === null ? 1 : 6;
|
|
327
|
-
default:
|
|
328
|
-
return 6;
|
|
329
|
-
}
|
|
330
|
-
}
|
|
331
|
-
function IsUndefined(x) {
|
|
332
|
-
return x === void 0;
|
|
333
|
-
}
|
|
334
|
-
function IsNull(x) {
|
|
335
|
-
return x === null;
|
|
336
|
-
}
|
|
337
|
-
function IsSymbol(x) {
|
|
338
|
-
return typeof x === "symbol";
|
|
339
|
-
}
|
|
340
|
-
function IsObject(x) {
|
|
341
|
-
return typeof x === "object" ? x !== null : typeof x === "function";
|
|
342
|
-
}
|
|
343
|
-
function ToPrimitive(input, PreferredType) {
|
|
344
|
-
switch (Type(input)) {
|
|
345
|
-
case 0:
|
|
346
|
-
return input;
|
|
347
|
-
case 1:
|
|
348
|
-
return input;
|
|
349
|
-
case 2:
|
|
350
|
-
return input;
|
|
351
|
-
case 3:
|
|
352
|
-
return input;
|
|
353
|
-
case 4:
|
|
354
|
-
return input;
|
|
355
|
-
case 5:
|
|
356
|
-
return input;
|
|
357
|
-
}
|
|
358
|
-
var hint = "string";
|
|
359
|
-
var exoticToPrim = GetMethod(input, toPrimitiveSymbol);
|
|
360
|
-
if (exoticToPrim !== void 0) {
|
|
361
|
-
var result = exoticToPrim.call(input, hint);
|
|
362
|
-
if (IsObject(result))
|
|
363
|
-
throw new TypeError();
|
|
364
|
-
return result;
|
|
365
|
-
}
|
|
366
|
-
return OrdinaryToPrimitive(input);
|
|
367
|
-
}
|
|
368
|
-
function OrdinaryToPrimitive(O, hint) {
|
|
369
|
-
var valueOf, result;
|
|
370
|
-
{
|
|
371
|
-
var toString_1 = O.toString;
|
|
372
|
-
if (IsCallable(toString_1)) {
|
|
373
|
-
var result = toString_1.call(O);
|
|
374
|
-
if (!IsObject(result))
|
|
375
|
-
return result;
|
|
376
|
-
}
|
|
377
|
-
var valueOf = O.valueOf;
|
|
378
|
-
if (IsCallable(valueOf)) {
|
|
379
|
-
var result = valueOf.call(O);
|
|
380
|
-
if (!IsObject(result))
|
|
381
|
-
return result;
|
|
382
|
-
}
|
|
383
|
-
}
|
|
384
|
-
throw new TypeError();
|
|
385
|
-
}
|
|
386
|
-
function ToBoolean(argument) {
|
|
387
|
-
return !!argument;
|
|
388
|
-
}
|
|
389
|
-
function ToString(argument) {
|
|
390
|
-
return "" + argument;
|
|
391
|
-
}
|
|
392
|
-
function ToPropertyKey(argument) {
|
|
393
|
-
var key = ToPrimitive(argument);
|
|
394
|
-
if (IsSymbol(key))
|
|
395
|
-
return key;
|
|
396
|
-
return ToString(key);
|
|
397
|
-
}
|
|
398
|
-
function IsArray(argument) {
|
|
399
|
-
return Array.isArray ? Array.isArray(argument) : argument instanceof Object ? argument instanceof Array : Object.prototype.toString.call(argument) === "[object Array]";
|
|
400
|
-
}
|
|
401
|
-
function IsCallable(argument) {
|
|
402
|
-
return typeof argument === "function";
|
|
403
|
-
}
|
|
404
|
-
function IsConstructor(argument) {
|
|
405
|
-
return typeof argument === "function";
|
|
406
|
-
}
|
|
407
|
-
function IsPropertyKey(argument) {
|
|
408
|
-
switch (Type(argument)) {
|
|
409
|
-
case 3:
|
|
410
|
-
return true;
|
|
411
|
-
case 4:
|
|
412
|
-
return true;
|
|
413
|
-
default:
|
|
414
|
-
return false;
|
|
415
|
-
}
|
|
416
|
-
}
|
|
417
|
-
function SameValueZero(x, y) {
|
|
418
|
-
return x === y || x !== x && y !== y;
|
|
419
|
-
}
|
|
420
|
-
function GetMethod(V, P) {
|
|
421
|
-
var func = V[P];
|
|
422
|
-
if (func === void 0 || func === null)
|
|
423
|
-
return void 0;
|
|
424
|
-
if (!IsCallable(func))
|
|
425
|
-
throw new TypeError();
|
|
426
|
-
return func;
|
|
427
|
-
}
|
|
428
|
-
function GetIterator(obj) {
|
|
429
|
-
var method = GetMethod(obj, iteratorSymbol);
|
|
430
|
-
if (!IsCallable(method))
|
|
431
|
-
throw new TypeError();
|
|
432
|
-
var iterator = method.call(obj);
|
|
433
|
-
if (!IsObject(iterator))
|
|
434
|
-
throw new TypeError();
|
|
435
|
-
return iterator;
|
|
436
|
-
}
|
|
437
|
-
function IteratorValue(iterResult) {
|
|
438
|
-
return iterResult.value;
|
|
439
|
-
}
|
|
440
|
-
function IteratorStep(iterator) {
|
|
441
|
-
var result = iterator.next();
|
|
442
|
-
return result.done ? false : result;
|
|
443
|
-
}
|
|
444
|
-
function IteratorClose(iterator) {
|
|
445
|
-
var f = iterator["return"];
|
|
446
|
-
if (f)
|
|
447
|
-
f.call(iterator);
|
|
448
|
-
}
|
|
449
|
-
function OrdinaryGetPrototypeOf(O) {
|
|
450
|
-
var proto = Object.getPrototypeOf(O);
|
|
451
|
-
if (typeof O !== "function" || O === functionPrototype)
|
|
452
|
-
return proto;
|
|
453
|
-
if (proto !== functionPrototype)
|
|
454
|
-
return proto;
|
|
455
|
-
var prototype2 = O.prototype;
|
|
456
|
-
var prototypeProto = prototype2 && Object.getPrototypeOf(prototype2);
|
|
457
|
-
if (prototypeProto == null || prototypeProto === Object.prototype)
|
|
458
|
-
return proto;
|
|
459
|
-
var constructor = prototypeProto.constructor;
|
|
460
|
-
if (typeof constructor !== "function")
|
|
461
|
-
return proto;
|
|
462
|
-
if (constructor === O)
|
|
463
|
-
return proto;
|
|
464
|
-
return constructor;
|
|
465
|
-
}
|
|
466
|
-
function CreateMetadataRegistry() {
|
|
467
|
-
var fallback;
|
|
468
|
-
if (!IsUndefined(registrySymbol) && typeof root.Reflect !== "undefined" && !(registrySymbol in root.Reflect) && typeof root.Reflect.defineMetadata === "function") {
|
|
469
|
-
fallback = CreateFallbackProvider(root.Reflect);
|
|
470
|
-
}
|
|
471
|
-
var first;
|
|
472
|
-
var second;
|
|
473
|
-
var rest;
|
|
474
|
-
var targetProviderMap = new _WeakMap();
|
|
475
|
-
var registry = {
|
|
476
|
-
registerProvider,
|
|
477
|
-
getProvider,
|
|
478
|
-
setProvider
|
|
479
|
-
};
|
|
480
|
-
return registry;
|
|
481
|
-
function registerProvider(provider) {
|
|
482
|
-
if (!Object.isExtensible(registry)) {
|
|
483
|
-
throw new Error("Cannot add provider to a frozen registry.");
|
|
484
|
-
}
|
|
485
|
-
switch (true) {
|
|
486
|
-
case fallback === provider:
|
|
487
|
-
break;
|
|
488
|
-
case IsUndefined(first):
|
|
489
|
-
first = provider;
|
|
490
|
-
break;
|
|
491
|
-
case first === provider:
|
|
492
|
-
break;
|
|
493
|
-
case IsUndefined(second):
|
|
494
|
-
second = provider;
|
|
495
|
-
break;
|
|
496
|
-
case second === provider:
|
|
497
|
-
break;
|
|
498
|
-
default:
|
|
499
|
-
if (rest === void 0)
|
|
500
|
-
rest = new _Set();
|
|
501
|
-
rest.add(provider);
|
|
502
|
-
break;
|
|
503
|
-
}
|
|
504
|
-
}
|
|
505
|
-
function getProviderNoCache(O, P) {
|
|
506
|
-
if (!IsUndefined(first)) {
|
|
507
|
-
if (first.isProviderFor(O, P))
|
|
508
|
-
return first;
|
|
509
|
-
if (!IsUndefined(second)) {
|
|
510
|
-
if (second.isProviderFor(O, P))
|
|
511
|
-
return first;
|
|
512
|
-
if (!IsUndefined(rest)) {
|
|
513
|
-
var iterator = GetIterator(rest);
|
|
514
|
-
while (true) {
|
|
515
|
-
var next = IteratorStep(iterator);
|
|
516
|
-
if (!next) {
|
|
517
|
-
return void 0;
|
|
518
|
-
}
|
|
519
|
-
var provider = IteratorValue(next);
|
|
520
|
-
if (provider.isProviderFor(O, P)) {
|
|
521
|
-
IteratorClose(iterator);
|
|
522
|
-
return provider;
|
|
523
|
-
}
|
|
524
|
-
}
|
|
525
|
-
}
|
|
526
|
-
}
|
|
527
|
-
}
|
|
528
|
-
if (!IsUndefined(fallback) && fallback.isProviderFor(O, P)) {
|
|
529
|
-
return fallback;
|
|
530
|
-
}
|
|
531
|
-
return void 0;
|
|
532
|
-
}
|
|
533
|
-
function getProvider(O, P) {
|
|
534
|
-
var providerMap = targetProviderMap.get(O);
|
|
535
|
-
var provider;
|
|
536
|
-
if (!IsUndefined(providerMap)) {
|
|
537
|
-
provider = providerMap.get(P);
|
|
538
|
-
}
|
|
539
|
-
if (!IsUndefined(provider)) {
|
|
540
|
-
return provider;
|
|
541
|
-
}
|
|
542
|
-
provider = getProviderNoCache(O, P);
|
|
543
|
-
if (!IsUndefined(provider)) {
|
|
544
|
-
if (IsUndefined(providerMap)) {
|
|
545
|
-
providerMap = new _Map();
|
|
546
|
-
targetProviderMap.set(O, providerMap);
|
|
547
|
-
}
|
|
548
|
-
providerMap.set(P, provider);
|
|
549
|
-
}
|
|
550
|
-
return provider;
|
|
551
|
-
}
|
|
552
|
-
function hasProvider(provider) {
|
|
553
|
-
if (IsUndefined(provider))
|
|
554
|
-
throw new TypeError();
|
|
555
|
-
return first === provider || second === provider || !IsUndefined(rest) && rest.has(provider);
|
|
556
|
-
}
|
|
557
|
-
function setProvider(O, P, provider) {
|
|
558
|
-
if (!hasProvider(provider)) {
|
|
559
|
-
throw new Error("Metadata provider not registered.");
|
|
560
|
-
}
|
|
561
|
-
var existingProvider = getProvider(O, P);
|
|
562
|
-
if (existingProvider !== provider) {
|
|
563
|
-
if (!IsUndefined(existingProvider)) {
|
|
564
|
-
return false;
|
|
565
|
-
}
|
|
566
|
-
var providerMap = targetProviderMap.get(O);
|
|
567
|
-
if (IsUndefined(providerMap)) {
|
|
568
|
-
providerMap = new _Map();
|
|
569
|
-
targetProviderMap.set(O, providerMap);
|
|
570
|
-
}
|
|
571
|
-
providerMap.set(P, provider);
|
|
572
|
-
}
|
|
573
|
-
return true;
|
|
574
|
-
}
|
|
575
|
-
}
|
|
576
|
-
function GetOrCreateMetadataRegistry() {
|
|
577
|
-
var metadataRegistry2;
|
|
578
|
-
if (!IsUndefined(registrySymbol) && IsObject(root.Reflect) && Object.isExtensible(root.Reflect)) {
|
|
579
|
-
metadataRegistry2 = root.Reflect[registrySymbol];
|
|
580
|
-
}
|
|
581
|
-
if (IsUndefined(metadataRegistry2)) {
|
|
582
|
-
metadataRegistry2 = CreateMetadataRegistry();
|
|
583
|
-
}
|
|
584
|
-
if (!IsUndefined(registrySymbol) && IsObject(root.Reflect) && Object.isExtensible(root.Reflect)) {
|
|
585
|
-
Object.defineProperty(root.Reflect, registrySymbol, {
|
|
586
|
-
enumerable: false,
|
|
587
|
-
configurable: false,
|
|
588
|
-
writable: false,
|
|
589
|
-
value: metadataRegistry2
|
|
590
|
-
});
|
|
591
|
-
}
|
|
592
|
-
return metadataRegistry2;
|
|
593
|
-
}
|
|
594
|
-
function CreateMetadataProvider(registry) {
|
|
595
|
-
var metadata2 = new _WeakMap();
|
|
596
|
-
var provider = {
|
|
597
|
-
isProviderFor: function(O, P) {
|
|
598
|
-
var targetMetadata = metadata2.get(O);
|
|
599
|
-
if (IsUndefined(targetMetadata))
|
|
600
|
-
return false;
|
|
601
|
-
return targetMetadata.has(P);
|
|
602
|
-
},
|
|
603
|
-
OrdinaryDefineOwnMetadata: OrdinaryDefineOwnMetadata2,
|
|
604
|
-
OrdinaryHasOwnMetadata: OrdinaryHasOwnMetadata2,
|
|
605
|
-
OrdinaryGetOwnMetadata: OrdinaryGetOwnMetadata2,
|
|
606
|
-
OrdinaryOwnMetadataKeys: OrdinaryOwnMetadataKeys2,
|
|
607
|
-
OrdinaryDeleteMetadata
|
|
608
|
-
};
|
|
609
|
-
metadataRegistry.registerProvider(provider);
|
|
610
|
-
return provider;
|
|
611
|
-
function GetOrCreateMetadataMap(O, P, Create) {
|
|
612
|
-
var targetMetadata = metadata2.get(O);
|
|
613
|
-
var createdTargetMetadata = false;
|
|
614
|
-
if (IsUndefined(targetMetadata)) {
|
|
615
|
-
if (!Create)
|
|
616
|
-
return void 0;
|
|
617
|
-
targetMetadata = new _Map();
|
|
618
|
-
metadata2.set(O, targetMetadata);
|
|
619
|
-
createdTargetMetadata = true;
|
|
620
|
-
}
|
|
621
|
-
var metadataMap = targetMetadata.get(P);
|
|
622
|
-
if (IsUndefined(metadataMap)) {
|
|
623
|
-
if (!Create)
|
|
624
|
-
return void 0;
|
|
625
|
-
metadataMap = new _Map();
|
|
626
|
-
targetMetadata.set(P, metadataMap);
|
|
627
|
-
if (!registry.setProvider(O, P, provider)) {
|
|
628
|
-
targetMetadata.delete(P);
|
|
629
|
-
if (createdTargetMetadata) {
|
|
630
|
-
metadata2.delete(O);
|
|
631
|
-
}
|
|
632
|
-
throw new Error("Wrong provider for target.");
|
|
633
|
-
}
|
|
634
|
-
}
|
|
635
|
-
return metadataMap;
|
|
636
|
-
}
|
|
637
|
-
function OrdinaryHasOwnMetadata2(MetadataKey, O, P) {
|
|
638
|
-
var metadataMap = GetOrCreateMetadataMap(
|
|
639
|
-
O,
|
|
640
|
-
P,
|
|
641
|
-
/*Create*/
|
|
642
|
-
false
|
|
643
|
-
);
|
|
644
|
-
if (IsUndefined(metadataMap))
|
|
645
|
-
return false;
|
|
646
|
-
return ToBoolean(metadataMap.has(MetadataKey));
|
|
647
|
-
}
|
|
648
|
-
function OrdinaryGetOwnMetadata2(MetadataKey, O, P) {
|
|
649
|
-
var metadataMap = GetOrCreateMetadataMap(
|
|
650
|
-
O,
|
|
651
|
-
P,
|
|
652
|
-
/*Create*/
|
|
653
|
-
false
|
|
654
|
-
);
|
|
655
|
-
if (IsUndefined(metadataMap))
|
|
656
|
-
return void 0;
|
|
657
|
-
return metadataMap.get(MetadataKey);
|
|
658
|
-
}
|
|
659
|
-
function OrdinaryDefineOwnMetadata2(MetadataKey, MetadataValue, O, P) {
|
|
660
|
-
var metadataMap = GetOrCreateMetadataMap(
|
|
661
|
-
O,
|
|
662
|
-
P,
|
|
663
|
-
/*Create*/
|
|
664
|
-
true
|
|
665
|
-
);
|
|
666
|
-
metadataMap.set(MetadataKey, MetadataValue);
|
|
667
|
-
}
|
|
668
|
-
function OrdinaryOwnMetadataKeys2(O, P) {
|
|
669
|
-
var keys = [];
|
|
670
|
-
var metadataMap = GetOrCreateMetadataMap(
|
|
671
|
-
O,
|
|
672
|
-
P,
|
|
673
|
-
/*Create*/
|
|
674
|
-
false
|
|
675
|
-
);
|
|
676
|
-
if (IsUndefined(metadataMap))
|
|
677
|
-
return keys;
|
|
678
|
-
var keysObj = metadataMap.keys();
|
|
679
|
-
var iterator = GetIterator(keysObj);
|
|
680
|
-
var k = 0;
|
|
681
|
-
while (true) {
|
|
682
|
-
var next = IteratorStep(iterator);
|
|
683
|
-
if (!next) {
|
|
684
|
-
keys.length = k;
|
|
685
|
-
return keys;
|
|
686
|
-
}
|
|
687
|
-
var nextValue = IteratorValue(next);
|
|
688
|
-
try {
|
|
689
|
-
keys[k] = nextValue;
|
|
690
|
-
} catch (e) {
|
|
691
|
-
try {
|
|
692
|
-
IteratorClose(iterator);
|
|
693
|
-
} finally {
|
|
694
|
-
throw e;
|
|
695
|
-
}
|
|
696
|
-
}
|
|
697
|
-
k++;
|
|
698
|
-
}
|
|
699
|
-
}
|
|
700
|
-
function OrdinaryDeleteMetadata(MetadataKey, O, P) {
|
|
701
|
-
var metadataMap = GetOrCreateMetadataMap(
|
|
702
|
-
O,
|
|
703
|
-
P,
|
|
704
|
-
/*Create*/
|
|
705
|
-
false
|
|
706
|
-
);
|
|
707
|
-
if (IsUndefined(metadataMap))
|
|
708
|
-
return false;
|
|
709
|
-
if (!metadataMap.delete(MetadataKey))
|
|
710
|
-
return false;
|
|
711
|
-
if (metadataMap.size === 0) {
|
|
712
|
-
var targetMetadata = metadata2.get(O);
|
|
713
|
-
if (!IsUndefined(targetMetadata)) {
|
|
714
|
-
targetMetadata.delete(P);
|
|
715
|
-
if (targetMetadata.size === 0) {
|
|
716
|
-
metadata2.delete(targetMetadata);
|
|
717
|
-
}
|
|
718
|
-
}
|
|
719
|
-
}
|
|
720
|
-
return true;
|
|
721
|
-
}
|
|
722
|
-
}
|
|
723
|
-
function CreateFallbackProvider(reflect) {
|
|
724
|
-
var defineMetadata2 = reflect.defineMetadata, hasOwnMetadata2 = reflect.hasOwnMetadata, getOwnMetadata2 = reflect.getOwnMetadata, getOwnMetadataKeys2 = reflect.getOwnMetadataKeys, deleteMetadata2 = reflect.deleteMetadata;
|
|
725
|
-
var metadataOwner = new _WeakMap();
|
|
726
|
-
var provider = {
|
|
727
|
-
isProviderFor: function(O, P) {
|
|
728
|
-
var metadataPropertySet = metadataOwner.get(O);
|
|
729
|
-
if (!IsUndefined(metadataPropertySet) && metadataPropertySet.has(P)) {
|
|
730
|
-
return true;
|
|
731
|
-
}
|
|
732
|
-
if (getOwnMetadataKeys2(O, P).length) {
|
|
733
|
-
if (IsUndefined(metadataPropertySet)) {
|
|
734
|
-
metadataPropertySet = new _Set();
|
|
735
|
-
metadataOwner.set(O, metadataPropertySet);
|
|
736
|
-
}
|
|
737
|
-
metadataPropertySet.add(P);
|
|
738
|
-
return true;
|
|
739
|
-
}
|
|
740
|
-
return false;
|
|
741
|
-
},
|
|
742
|
-
OrdinaryDefineOwnMetadata: defineMetadata2,
|
|
743
|
-
OrdinaryHasOwnMetadata: hasOwnMetadata2,
|
|
744
|
-
OrdinaryGetOwnMetadata: getOwnMetadata2,
|
|
745
|
-
OrdinaryOwnMetadataKeys: getOwnMetadataKeys2,
|
|
746
|
-
OrdinaryDeleteMetadata: deleteMetadata2
|
|
747
|
-
};
|
|
748
|
-
return provider;
|
|
749
|
-
}
|
|
750
|
-
function GetMetadataProvider(O, P, Create) {
|
|
751
|
-
var registeredProvider = metadataRegistry.getProvider(O, P);
|
|
752
|
-
if (!IsUndefined(registeredProvider)) {
|
|
753
|
-
return registeredProvider;
|
|
754
|
-
}
|
|
755
|
-
if (Create) {
|
|
756
|
-
if (metadataRegistry.setProvider(O, P, metadataProvider)) {
|
|
757
|
-
return metadataProvider;
|
|
758
|
-
}
|
|
759
|
-
throw new Error("Illegal state.");
|
|
760
|
-
}
|
|
761
|
-
return void 0;
|
|
762
|
-
}
|
|
763
|
-
function CreateMapPolyfill() {
|
|
764
|
-
var cacheSentinel = {};
|
|
765
|
-
var arraySentinel = [];
|
|
766
|
-
var MapIterator = (
|
|
767
|
-
/** @class */
|
|
768
|
-
function() {
|
|
769
|
-
function MapIterator2(keys, values, selector) {
|
|
770
|
-
this._index = 0;
|
|
771
|
-
this._keys = keys;
|
|
772
|
-
this._values = values;
|
|
773
|
-
this._selector = selector;
|
|
774
|
-
}
|
|
775
|
-
MapIterator2.prototype["@@iterator"] = function() {
|
|
776
|
-
return this;
|
|
777
|
-
};
|
|
778
|
-
MapIterator2.prototype[iteratorSymbol] = function() {
|
|
779
|
-
return this;
|
|
780
|
-
};
|
|
781
|
-
MapIterator2.prototype.next = function() {
|
|
782
|
-
var index = this._index;
|
|
783
|
-
if (index >= 0 && index < this._keys.length) {
|
|
784
|
-
var result = this._selector(this._keys[index], this._values[index]);
|
|
785
|
-
if (index + 1 >= this._keys.length) {
|
|
786
|
-
this._index = -1;
|
|
787
|
-
this._keys = arraySentinel;
|
|
788
|
-
this._values = arraySentinel;
|
|
789
|
-
} else {
|
|
790
|
-
this._index++;
|
|
791
|
-
}
|
|
792
|
-
return { value: result, done: false };
|
|
793
|
-
}
|
|
794
|
-
return { value: void 0, done: true };
|
|
795
|
-
};
|
|
796
|
-
MapIterator2.prototype.throw = function(error) {
|
|
797
|
-
if (this._index >= 0) {
|
|
798
|
-
this._index = -1;
|
|
799
|
-
this._keys = arraySentinel;
|
|
800
|
-
this._values = arraySentinel;
|
|
801
|
-
}
|
|
802
|
-
throw error;
|
|
803
|
-
};
|
|
804
|
-
MapIterator2.prototype.return = function(value) {
|
|
805
|
-
if (this._index >= 0) {
|
|
806
|
-
this._index = -1;
|
|
807
|
-
this._keys = arraySentinel;
|
|
808
|
-
this._values = arraySentinel;
|
|
809
|
-
}
|
|
810
|
-
return { value, done: true };
|
|
811
|
-
};
|
|
812
|
-
return MapIterator2;
|
|
813
|
-
}()
|
|
814
|
-
);
|
|
815
|
-
var Map2 = (
|
|
816
|
-
/** @class */
|
|
817
|
-
function() {
|
|
818
|
-
function Map3() {
|
|
819
|
-
this._keys = [];
|
|
820
|
-
this._values = [];
|
|
821
|
-
this._cacheKey = cacheSentinel;
|
|
822
|
-
this._cacheIndex = -2;
|
|
823
|
-
}
|
|
824
|
-
Object.defineProperty(Map3.prototype, "size", {
|
|
825
|
-
get: function() {
|
|
826
|
-
return this._keys.length;
|
|
827
|
-
},
|
|
828
|
-
enumerable: true,
|
|
829
|
-
configurable: true
|
|
830
|
-
});
|
|
831
|
-
Map3.prototype.has = function(key) {
|
|
832
|
-
return this._find(
|
|
833
|
-
key,
|
|
834
|
-
/*insert*/
|
|
835
|
-
false
|
|
836
|
-
) >= 0;
|
|
837
|
-
};
|
|
838
|
-
Map3.prototype.get = function(key) {
|
|
839
|
-
var index = this._find(
|
|
840
|
-
key,
|
|
841
|
-
/*insert*/
|
|
842
|
-
false
|
|
843
|
-
);
|
|
844
|
-
return index >= 0 ? this._values[index] : void 0;
|
|
845
|
-
};
|
|
846
|
-
Map3.prototype.set = function(key, value) {
|
|
847
|
-
var index = this._find(
|
|
848
|
-
key,
|
|
849
|
-
/*insert*/
|
|
850
|
-
true
|
|
851
|
-
);
|
|
852
|
-
this._values[index] = value;
|
|
853
|
-
return this;
|
|
854
|
-
};
|
|
855
|
-
Map3.prototype.delete = function(key) {
|
|
856
|
-
var index = this._find(
|
|
857
|
-
key,
|
|
858
|
-
/*insert*/
|
|
859
|
-
false
|
|
860
|
-
);
|
|
861
|
-
if (index >= 0) {
|
|
862
|
-
var size = this._keys.length;
|
|
863
|
-
for (var i = index + 1; i < size; i++) {
|
|
864
|
-
this._keys[i - 1] = this._keys[i];
|
|
865
|
-
this._values[i - 1] = this._values[i];
|
|
866
|
-
}
|
|
867
|
-
this._keys.length--;
|
|
868
|
-
this._values.length--;
|
|
869
|
-
if (SameValueZero(key, this._cacheKey)) {
|
|
870
|
-
this._cacheKey = cacheSentinel;
|
|
871
|
-
this._cacheIndex = -2;
|
|
872
|
-
}
|
|
873
|
-
return true;
|
|
874
|
-
}
|
|
875
|
-
return false;
|
|
876
|
-
};
|
|
877
|
-
Map3.prototype.clear = function() {
|
|
878
|
-
this._keys.length = 0;
|
|
879
|
-
this._values.length = 0;
|
|
880
|
-
this._cacheKey = cacheSentinel;
|
|
881
|
-
this._cacheIndex = -2;
|
|
882
|
-
};
|
|
883
|
-
Map3.prototype.keys = function() {
|
|
884
|
-
return new MapIterator(this._keys, this._values, getKey);
|
|
885
|
-
};
|
|
886
|
-
Map3.prototype.values = function() {
|
|
887
|
-
return new MapIterator(this._keys, this._values, getValue);
|
|
888
|
-
};
|
|
889
|
-
Map3.prototype.entries = function() {
|
|
890
|
-
return new MapIterator(this._keys, this._values, getEntry);
|
|
891
|
-
};
|
|
892
|
-
Map3.prototype["@@iterator"] = function() {
|
|
893
|
-
return this.entries();
|
|
894
|
-
};
|
|
895
|
-
Map3.prototype[iteratorSymbol] = function() {
|
|
896
|
-
return this.entries();
|
|
897
|
-
};
|
|
898
|
-
Map3.prototype._find = function(key, insert) {
|
|
899
|
-
if (!SameValueZero(this._cacheKey, key)) {
|
|
900
|
-
this._cacheIndex = -1;
|
|
901
|
-
for (var i = 0; i < this._keys.length; i++) {
|
|
902
|
-
if (SameValueZero(this._keys[i], key)) {
|
|
903
|
-
this._cacheIndex = i;
|
|
904
|
-
break;
|
|
905
|
-
}
|
|
906
|
-
}
|
|
907
|
-
}
|
|
908
|
-
if (this._cacheIndex < 0 && insert) {
|
|
909
|
-
this._cacheIndex = this._keys.length;
|
|
910
|
-
this._keys.push(key);
|
|
911
|
-
this._values.push(void 0);
|
|
912
|
-
}
|
|
913
|
-
return this._cacheIndex;
|
|
914
|
-
};
|
|
915
|
-
return Map3;
|
|
916
|
-
}()
|
|
917
|
-
);
|
|
918
|
-
return Map2;
|
|
919
|
-
function getKey(key, _) {
|
|
920
|
-
return key;
|
|
921
|
-
}
|
|
922
|
-
function getValue(_, value) {
|
|
923
|
-
return value;
|
|
924
|
-
}
|
|
925
|
-
function getEntry(key, value) {
|
|
926
|
-
return [key, value];
|
|
927
|
-
}
|
|
928
|
-
}
|
|
929
|
-
function CreateSetPolyfill() {
|
|
930
|
-
var Set2 = (
|
|
931
|
-
/** @class */
|
|
932
|
-
function() {
|
|
933
|
-
function Set3() {
|
|
934
|
-
this._map = new _Map();
|
|
935
|
-
}
|
|
936
|
-
Object.defineProperty(Set3.prototype, "size", {
|
|
937
|
-
get: function() {
|
|
938
|
-
return this._map.size;
|
|
939
|
-
},
|
|
940
|
-
enumerable: true,
|
|
941
|
-
configurable: true
|
|
942
|
-
});
|
|
943
|
-
Set3.prototype.has = function(value) {
|
|
944
|
-
return this._map.has(value);
|
|
945
|
-
};
|
|
946
|
-
Set3.prototype.add = function(value) {
|
|
947
|
-
return this._map.set(value, value), this;
|
|
948
|
-
};
|
|
949
|
-
Set3.prototype.delete = function(value) {
|
|
950
|
-
return this._map.delete(value);
|
|
951
|
-
};
|
|
952
|
-
Set3.prototype.clear = function() {
|
|
953
|
-
this._map.clear();
|
|
954
|
-
};
|
|
955
|
-
Set3.prototype.keys = function() {
|
|
956
|
-
return this._map.keys();
|
|
957
|
-
};
|
|
958
|
-
Set3.prototype.values = function() {
|
|
959
|
-
return this._map.keys();
|
|
960
|
-
};
|
|
961
|
-
Set3.prototype.entries = function() {
|
|
962
|
-
return this._map.entries();
|
|
963
|
-
};
|
|
964
|
-
Set3.prototype["@@iterator"] = function() {
|
|
965
|
-
return this.keys();
|
|
966
|
-
};
|
|
967
|
-
Set3.prototype[iteratorSymbol] = function() {
|
|
968
|
-
return this.keys();
|
|
969
|
-
};
|
|
970
|
-
return Set3;
|
|
971
|
-
}()
|
|
972
|
-
);
|
|
973
|
-
return Set2;
|
|
974
|
-
}
|
|
975
|
-
function CreateWeakMapPolyfill() {
|
|
976
|
-
var UUID_SIZE = 16;
|
|
977
|
-
var keys = HashMap.create();
|
|
978
|
-
var rootKey = CreateUniqueKey();
|
|
979
|
-
return (
|
|
980
|
-
/** @class */
|
|
981
|
-
function() {
|
|
982
|
-
function WeakMap2() {
|
|
983
|
-
this._key = CreateUniqueKey();
|
|
984
|
-
}
|
|
985
|
-
WeakMap2.prototype.has = function(target) {
|
|
986
|
-
var table = GetOrCreateWeakMapTable(
|
|
987
|
-
target,
|
|
988
|
-
/*create*/
|
|
989
|
-
false
|
|
990
|
-
);
|
|
991
|
-
return table !== void 0 ? HashMap.has(table, this._key) : false;
|
|
992
|
-
};
|
|
993
|
-
WeakMap2.prototype.get = function(target) {
|
|
994
|
-
var table = GetOrCreateWeakMapTable(
|
|
995
|
-
target,
|
|
996
|
-
/*create*/
|
|
997
|
-
false
|
|
998
|
-
);
|
|
999
|
-
return table !== void 0 ? HashMap.get(table, this._key) : void 0;
|
|
1000
|
-
};
|
|
1001
|
-
WeakMap2.prototype.set = function(target, value) {
|
|
1002
|
-
var table = GetOrCreateWeakMapTable(
|
|
1003
|
-
target,
|
|
1004
|
-
/*create*/
|
|
1005
|
-
true
|
|
1006
|
-
);
|
|
1007
|
-
table[this._key] = value;
|
|
1008
|
-
return this;
|
|
1009
|
-
};
|
|
1010
|
-
WeakMap2.prototype.delete = function(target) {
|
|
1011
|
-
var table = GetOrCreateWeakMapTable(
|
|
1012
|
-
target,
|
|
1013
|
-
/*create*/
|
|
1014
|
-
false
|
|
1015
|
-
);
|
|
1016
|
-
return table !== void 0 ? delete table[this._key] : false;
|
|
1017
|
-
};
|
|
1018
|
-
WeakMap2.prototype.clear = function() {
|
|
1019
|
-
this._key = CreateUniqueKey();
|
|
1020
|
-
};
|
|
1021
|
-
return WeakMap2;
|
|
1022
|
-
}()
|
|
1023
|
-
);
|
|
1024
|
-
function CreateUniqueKey() {
|
|
1025
|
-
var key;
|
|
1026
|
-
do
|
|
1027
|
-
key = "@@WeakMap@@" + CreateUUID();
|
|
1028
|
-
while (HashMap.has(keys, key));
|
|
1029
|
-
keys[key] = true;
|
|
1030
|
-
return key;
|
|
1031
|
-
}
|
|
1032
|
-
function GetOrCreateWeakMapTable(target, create) {
|
|
1033
|
-
if (!hasOwn.call(target, rootKey)) {
|
|
1034
|
-
if (!create)
|
|
1035
|
-
return void 0;
|
|
1036
|
-
Object.defineProperty(target, rootKey, { value: HashMap.create() });
|
|
1037
|
-
}
|
|
1038
|
-
return target[rootKey];
|
|
1039
|
-
}
|
|
1040
|
-
function FillRandomBytes(buffer, size) {
|
|
1041
|
-
for (var i = 0; i < size; ++i)
|
|
1042
|
-
buffer[i] = Math.random() * 255 | 0;
|
|
1043
|
-
return buffer;
|
|
1044
|
-
}
|
|
1045
|
-
function GenRandomBytes(size) {
|
|
1046
|
-
if (typeof Uint8Array === "function") {
|
|
1047
|
-
var array = new Uint8Array(size);
|
|
1048
|
-
if (typeof crypto !== "undefined") {
|
|
1049
|
-
crypto.getRandomValues(array);
|
|
1050
|
-
} else if (typeof msCrypto !== "undefined") {
|
|
1051
|
-
msCrypto.getRandomValues(array);
|
|
1052
|
-
} else {
|
|
1053
|
-
FillRandomBytes(array, size);
|
|
1054
|
-
}
|
|
1055
|
-
return array;
|
|
1056
|
-
}
|
|
1057
|
-
return FillRandomBytes(new Array(size), size);
|
|
1058
|
-
}
|
|
1059
|
-
function CreateUUID() {
|
|
1060
|
-
var data = GenRandomBytes(UUID_SIZE);
|
|
1061
|
-
data[6] = data[6] & 79 | 64;
|
|
1062
|
-
data[8] = data[8] & 191 | 128;
|
|
1063
|
-
var result = "";
|
|
1064
|
-
for (var offset = 0; offset < UUID_SIZE; ++offset) {
|
|
1065
|
-
var byte = data[offset];
|
|
1066
|
-
if (offset === 4 || offset === 6 || offset === 8)
|
|
1067
|
-
result += "-";
|
|
1068
|
-
if (byte < 16)
|
|
1069
|
-
result += "0";
|
|
1070
|
-
result += byte.toString(16).toLowerCase();
|
|
1071
|
-
}
|
|
1072
|
-
return result;
|
|
1073
|
-
}
|
|
1074
|
-
}
|
|
1075
|
-
function MakeDictionary(obj) {
|
|
1076
|
-
obj.__ = void 0;
|
|
1077
|
-
delete obj.__;
|
|
1078
|
-
return obj;
|
|
1079
|
-
}
|
|
1080
|
-
});
|
|
1081
|
-
})(Reflect$1 || (Reflect$1 = {}));
|
|
1082
|
-
function bind(fn, thisArg) {
|
|
1083
|
-
return function wrap() {
|
|
1084
|
-
return fn.apply(thisArg, arguments);
|
|
1085
|
-
};
|
|
1086
|
-
}
|
|
1087
|
-
const { toString } = Object.prototype;
|
|
1088
|
-
const { getPrototypeOf } = Object;
|
|
1089
|
-
const kindOf = /* @__PURE__ */ ((cache) => (thing) => {
|
|
1090
|
-
const str = toString.call(thing);
|
|
1091
|
-
return cache[str] || (cache[str] = str.slice(8, -1).toLowerCase());
|
|
1092
|
-
})(/* @__PURE__ */ Object.create(null));
|
|
1093
|
-
const kindOfTest = (type) => {
|
|
1094
|
-
type = type.toLowerCase();
|
|
1095
|
-
return (thing) => kindOf(thing) === type;
|
|
1096
|
-
};
|
|
1097
|
-
const typeOfTest = (type) => (thing) => typeof thing === type;
|
|
1098
|
-
const { isArray } = Array;
|
|
1099
|
-
const isUndefined = typeOfTest("undefined");
|
|
1100
|
-
function isBuffer(val) {
|
|
1101
|
-
return val !== null && !isUndefined(val) && val.constructor !== null && !isUndefined(val.constructor) && isFunction(val.constructor.isBuffer) && val.constructor.isBuffer(val);
|
|
1102
|
-
}
|
|
1103
|
-
const isArrayBuffer = kindOfTest("ArrayBuffer");
|
|
1104
|
-
function isArrayBufferView(val) {
|
|
1105
|
-
let result;
|
|
1106
|
-
if (typeof ArrayBuffer !== "undefined" && ArrayBuffer.isView) {
|
|
1107
|
-
result = ArrayBuffer.isView(val);
|
|
1108
|
-
} else {
|
|
1109
|
-
result = val && val.buffer && isArrayBuffer(val.buffer);
|
|
1110
|
-
}
|
|
1111
|
-
return result;
|
|
1112
|
-
}
|
|
1113
|
-
const isString = typeOfTest("string");
|
|
1114
|
-
const isFunction = typeOfTest("function");
|
|
1115
|
-
const isNumber = typeOfTest("number");
|
|
1116
|
-
const isObject = (thing) => thing !== null && typeof thing === "object";
|
|
1117
|
-
const isBoolean = (thing) => thing === true || thing === false;
|
|
1118
|
-
const isPlainObject = (val) => {
|
|
1119
|
-
if (kindOf(val) !== "object") {
|
|
1120
|
-
return false;
|
|
1121
|
-
}
|
|
1122
|
-
const prototype2 = getPrototypeOf(val);
|
|
1123
|
-
return (prototype2 === null || prototype2 === Object.prototype || Object.getPrototypeOf(prototype2) === null) && !(Symbol.toStringTag in val) && !(Symbol.iterator in val);
|
|
1124
|
-
};
|
|
1125
|
-
const isDate = kindOfTest("Date");
|
|
1126
|
-
const isFile = kindOfTest("File");
|
|
1127
|
-
const isBlob = kindOfTest("Blob");
|
|
1128
|
-
const isFileList = kindOfTest("FileList");
|
|
1129
|
-
const isStream = (val) => isObject(val) && isFunction(val.pipe);
|
|
1130
|
-
const isFormData = (thing) => {
|
|
1131
|
-
let kind;
|
|
1132
|
-
return thing && (typeof FormData === "function" && thing instanceof FormData || isFunction(thing.append) && ((kind = kindOf(thing)) === "formdata" || // detect form-data instance
|
|
1133
|
-
kind === "object" && isFunction(thing.toString) && thing.toString() === "[object FormData]"));
|
|
1134
|
-
};
|
|
1135
|
-
const isURLSearchParams = kindOfTest("URLSearchParams");
|
|
1136
|
-
const [isReadableStream, isRequest, isResponse, isHeaders] = ["ReadableStream", "Request", "Response", "Headers"].map(kindOfTest);
|
|
1137
|
-
const trim = (str) => str.trim ? str.trim() : str.replace(/^[\s\uFEFF\xA0]+|[\s\uFEFF\xA0]+$/g, "");
|
|
1138
|
-
function forEach(obj, fn, { allOwnKeys = false } = {}) {
|
|
1139
|
-
if (obj === null || typeof obj === "undefined") {
|
|
1140
|
-
return;
|
|
1141
|
-
}
|
|
1142
|
-
let i;
|
|
1143
|
-
let l;
|
|
1144
|
-
if (typeof obj !== "object") {
|
|
1145
|
-
obj = [obj];
|
|
1146
|
-
}
|
|
1147
|
-
if (isArray(obj)) {
|
|
1148
|
-
for (i = 0, l = obj.length; i < l; i++) {
|
|
1149
|
-
fn.call(null, obj[i], i, obj);
|
|
1150
|
-
}
|
|
1151
|
-
} else {
|
|
1152
|
-
const keys = allOwnKeys ? Object.getOwnPropertyNames(obj) : Object.keys(obj);
|
|
1153
|
-
const len = keys.length;
|
|
1154
|
-
let key;
|
|
1155
|
-
for (i = 0; i < len; i++) {
|
|
1156
|
-
key = keys[i];
|
|
1157
|
-
fn.call(null, obj[key], key, obj);
|
|
1158
|
-
}
|
|
1159
|
-
}
|
|
1160
|
-
}
|
|
1161
|
-
function findKey(obj, key) {
|
|
1162
|
-
key = key.toLowerCase();
|
|
1163
|
-
const keys = Object.keys(obj);
|
|
1164
|
-
let i = keys.length;
|
|
1165
|
-
let _key;
|
|
1166
|
-
while (i-- > 0) {
|
|
1167
|
-
_key = keys[i];
|
|
1168
|
-
if (key === _key.toLowerCase()) {
|
|
1169
|
-
return _key;
|
|
1170
|
-
}
|
|
1171
|
-
}
|
|
1172
|
-
return null;
|
|
1173
|
-
}
|
|
1174
|
-
const _global = (() => {
|
|
1175
|
-
if (typeof globalThis !== "undefined") return globalThis;
|
|
1176
|
-
return typeof self !== "undefined" ? self : typeof window !== "undefined" ? window : global;
|
|
1177
|
-
})();
|
|
1178
|
-
const isContextDefined = (context) => !isUndefined(context) && context !== _global;
|
|
1179
|
-
function merge() {
|
|
1180
|
-
const { caseless } = isContextDefined(this) && this || {};
|
|
1181
|
-
const result = {};
|
|
1182
|
-
const assignValue = (val, key) => {
|
|
1183
|
-
const targetKey = caseless && findKey(result, key) || key;
|
|
1184
|
-
if (isPlainObject(result[targetKey]) && isPlainObject(val)) {
|
|
1185
|
-
result[targetKey] = merge(result[targetKey], val);
|
|
1186
|
-
} else if (isPlainObject(val)) {
|
|
1187
|
-
result[targetKey] = merge({}, val);
|
|
1188
|
-
} else if (isArray(val)) {
|
|
1189
|
-
result[targetKey] = val.slice();
|
|
1190
|
-
} else {
|
|
1191
|
-
result[targetKey] = val;
|
|
1192
|
-
}
|
|
1193
|
-
};
|
|
1194
|
-
for (let i = 0, l = arguments.length; i < l; i++) {
|
|
1195
|
-
arguments[i] && forEach(arguments[i], assignValue);
|
|
1196
|
-
}
|
|
1197
|
-
return result;
|
|
1198
|
-
}
|
|
1199
|
-
const extend = (a, b, thisArg, { allOwnKeys } = {}) => {
|
|
1200
|
-
forEach(b, (val, key) => {
|
|
1201
|
-
if (thisArg && isFunction(val)) {
|
|
1202
|
-
a[key] = bind(val, thisArg);
|
|
1203
|
-
} else {
|
|
1204
|
-
a[key] = val;
|
|
1205
|
-
}
|
|
1206
|
-
}, { allOwnKeys });
|
|
1207
|
-
return a;
|
|
1208
|
-
};
|
|
1209
|
-
const stripBOM = (content) => {
|
|
1210
|
-
if (content.charCodeAt(0) === 65279) {
|
|
1211
|
-
content = content.slice(1);
|
|
1212
|
-
}
|
|
1213
|
-
return content;
|
|
1214
|
-
};
|
|
1215
|
-
const inherits = (constructor, superConstructor, props, descriptors2) => {
|
|
1216
|
-
constructor.prototype = Object.create(superConstructor.prototype, descriptors2);
|
|
1217
|
-
constructor.prototype.constructor = constructor;
|
|
1218
|
-
Object.defineProperty(constructor, "super", {
|
|
1219
|
-
value: superConstructor.prototype
|
|
1220
|
-
});
|
|
1221
|
-
props && Object.assign(constructor.prototype, props);
|
|
1222
|
-
};
|
|
1223
|
-
const toFlatObject = (sourceObj, destObj, filter2, propFilter) => {
|
|
1224
|
-
let props;
|
|
1225
|
-
let i;
|
|
1226
|
-
let prop;
|
|
1227
|
-
const merged = {};
|
|
1228
|
-
destObj = destObj || {};
|
|
1229
|
-
if (sourceObj == null) return destObj;
|
|
1230
|
-
do {
|
|
1231
|
-
props = Object.getOwnPropertyNames(sourceObj);
|
|
1232
|
-
i = props.length;
|
|
1233
|
-
while (i-- > 0) {
|
|
1234
|
-
prop = props[i];
|
|
1235
|
-
if ((!propFilter || propFilter(prop, sourceObj, destObj)) && !merged[prop]) {
|
|
1236
|
-
destObj[prop] = sourceObj[prop];
|
|
1237
|
-
merged[prop] = true;
|
|
1238
|
-
}
|
|
1239
|
-
}
|
|
1240
|
-
sourceObj = filter2 !== false && getPrototypeOf(sourceObj);
|
|
1241
|
-
} while (sourceObj && (!filter2 || filter2(sourceObj, destObj)) && sourceObj !== Object.prototype);
|
|
1242
|
-
return destObj;
|
|
1243
|
-
};
|
|
1244
|
-
const endsWith = (str, searchString, position) => {
|
|
1245
|
-
str = String(str);
|
|
1246
|
-
if (position === void 0 || position > str.length) {
|
|
1247
|
-
position = str.length;
|
|
1248
|
-
}
|
|
1249
|
-
position -= searchString.length;
|
|
1250
|
-
const lastIndex = str.indexOf(searchString, position);
|
|
1251
|
-
return lastIndex !== -1 && lastIndex === position;
|
|
1252
|
-
};
|
|
1253
|
-
const toArray = (thing) => {
|
|
1254
|
-
if (!thing) return null;
|
|
1255
|
-
if (isArray(thing)) return thing;
|
|
1256
|
-
let i = thing.length;
|
|
1257
|
-
if (!isNumber(i)) return null;
|
|
1258
|
-
const arr = new Array(i);
|
|
1259
|
-
while (i-- > 0) {
|
|
1260
|
-
arr[i] = thing[i];
|
|
1261
|
-
}
|
|
1262
|
-
return arr;
|
|
1263
|
-
};
|
|
1264
|
-
const isTypedArray = /* @__PURE__ */ ((TypedArray) => {
|
|
1265
|
-
return (thing) => {
|
|
1266
|
-
return TypedArray && thing instanceof TypedArray;
|
|
1267
|
-
};
|
|
1268
|
-
})(typeof Uint8Array !== "undefined" && getPrototypeOf(Uint8Array));
|
|
1269
|
-
const forEachEntry = (obj, fn) => {
|
|
1270
|
-
const generator = obj && obj[Symbol.iterator];
|
|
1271
|
-
const iterator = generator.call(obj);
|
|
1272
|
-
let result;
|
|
1273
|
-
while ((result = iterator.next()) && !result.done) {
|
|
1274
|
-
const pair = result.value;
|
|
1275
|
-
fn.call(obj, pair[0], pair[1]);
|
|
1276
|
-
}
|
|
1277
|
-
};
|
|
1278
|
-
const matchAll = (regExp, str) => {
|
|
1279
|
-
let matches;
|
|
1280
|
-
const arr = [];
|
|
1281
|
-
while ((matches = regExp.exec(str)) !== null) {
|
|
1282
|
-
arr.push(matches);
|
|
1283
|
-
}
|
|
1284
|
-
return arr;
|
|
1285
|
-
};
|
|
1286
|
-
const isHTMLForm = kindOfTest("HTMLFormElement");
|
|
1287
|
-
const toCamelCase = (str) => {
|
|
1288
|
-
return str.toLowerCase().replace(
|
|
1289
|
-
/[-_\s]([a-z\d])(\w*)/g,
|
|
1290
|
-
function replacer(m, p1, p2) {
|
|
1291
|
-
return p1.toUpperCase() + p2;
|
|
1292
|
-
}
|
|
1293
|
-
);
|
|
1294
|
-
};
|
|
1295
|
-
const hasOwnProperty = (({ hasOwnProperty: hasOwnProperty2 }) => (obj, prop) => hasOwnProperty2.call(obj, prop))(Object.prototype);
|
|
1296
|
-
const isRegExp = kindOfTest("RegExp");
|
|
1297
|
-
const reduceDescriptors = (obj, reducer) => {
|
|
1298
|
-
const descriptors2 = Object.getOwnPropertyDescriptors(obj);
|
|
1299
|
-
const reducedDescriptors = {};
|
|
1300
|
-
forEach(descriptors2, (descriptor, name) => {
|
|
1301
|
-
let ret;
|
|
1302
|
-
if ((ret = reducer(descriptor, name, obj)) !== false) {
|
|
1303
|
-
reducedDescriptors[name] = ret || descriptor;
|
|
1304
|
-
}
|
|
1305
|
-
});
|
|
1306
|
-
Object.defineProperties(obj, reducedDescriptors);
|
|
1307
|
-
};
|
|
1308
|
-
const freezeMethods = (obj) => {
|
|
1309
|
-
reduceDescriptors(obj, (descriptor, name) => {
|
|
1310
|
-
if (isFunction(obj) && ["arguments", "caller", "callee"].indexOf(name) !== -1) {
|
|
1311
|
-
return false;
|
|
1312
|
-
}
|
|
1313
|
-
const value = obj[name];
|
|
1314
|
-
if (!isFunction(value)) return;
|
|
1315
|
-
descriptor.enumerable = false;
|
|
1316
|
-
if ("writable" in descriptor) {
|
|
1317
|
-
descriptor.writable = false;
|
|
1318
|
-
return;
|
|
1319
|
-
}
|
|
1320
|
-
if (!descriptor.set) {
|
|
1321
|
-
descriptor.set = () => {
|
|
1322
|
-
throw Error("Can not rewrite read-only method '" + name + "'");
|
|
1323
|
-
};
|
|
1324
|
-
}
|
|
1325
|
-
});
|
|
1326
|
-
};
|
|
1327
|
-
const toObjectSet = (arrayOrString, delimiter) => {
|
|
1328
|
-
const obj = {};
|
|
1329
|
-
const define = (arr) => {
|
|
1330
|
-
arr.forEach((value) => {
|
|
1331
|
-
obj[value] = true;
|
|
1332
|
-
});
|
|
1333
|
-
};
|
|
1334
|
-
isArray(arrayOrString) ? define(arrayOrString) : define(String(arrayOrString).split(delimiter));
|
|
1335
|
-
return obj;
|
|
1336
|
-
};
|
|
1337
|
-
const noop = () => {
|
|
1338
|
-
};
|
|
1339
|
-
const toFiniteNumber = (value, defaultValue) => {
|
|
1340
|
-
return value != null && Number.isFinite(value = +value) ? value : defaultValue;
|
|
1341
|
-
};
|
|
1342
|
-
const ALPHA = "abcdefghijklmnopqrstuvwxyz";
|
|
1343
|
-
const DIGIT = "0123456789";
|
|
1344
|
-
const ALPHABET = {
|
|
1345
|
-
DIGIT,
|
|
1346
|
-
ALPHA,
|
|
1347
|
-
ALPHA_DIGIT: ALPHA + ALPHA.toUpperCase() + DIGIT
|
|
1348
|
-
};
|
|
1349
|
-
const generateString = (size = 16, alphabet = ALPHABET.ALPHA_DIGIT) => {
|
|
1350
|
-
let str = "";
|
|
1351
|
-
const { length } = alphabet;
|
|
1352
|
-
while (size--) {
|
|
1353
|
-
str += alphabet[Math.random() * length | 0];
|
|
1354
|
-
}
|
|
1355
|
-
return str;
|
|
1356
|
-
};
|
|
1357
|
-
function isSpecCompliantForm(thing) {
|
|
1358
|
-
return !!(thing && isFunction(thing.append) && thing[Symbol.toStringTag] === "FormData" && thing[Symbol.iterator]);
|
|
1359
|
-
}
|
|
1360
|
-
const toJSONObject = (obj) => {
|
|
1361
|
-
const stack = new Array(10);
|
|
1362
|
-
const visit = (source, i) => {
|
|
1363
|
-
if (isObject(source)) {
|
|
1364
|
-
if (stack.indexOf(source) >= 0) {
|
|
1365
|
-
return;
|
|
1366
|
-
}
|
|
1367
|
-
if (!("toJSON" in source)) {
|
|
1368
|
-
stack[i] = source;
|
|
1369
|
-
const target = isArray(source) ? [] : {};
|
|
1370
|
-
forEach(source, (value, key) => {
|
|
1371
|
-
const reducedValue = visit(value, i + 1);
|
|
1372
|
-
!isUndefined(reducedValue) && (target[key] = reducedValue);
|
|
1373
|
-
});
|
|
1374
|
-
stack[i] = void 0;
|
|
1375
|
-
return target;
|
|
1376
|
-
}
|
|
1377
|
-
}
|
|
1378
|
-
return source;
|
|
1379
|
-
};
|
|
1380
|
-
return visit(obj, 0);
|
|
1381
|
-
};
|
|
1382
|
-
const isAsyncFn = kindOfTest("AsyncFunction");
|
|
1383
|
-
const isThenable = (thing) => thing && (isObject(thing) || isFunction(thing)) && isFunction(thing.then) && isFunction(thing.catch);
|
|
1384
|
-
const _setImmediate = ((setImmediateSupported, postMessageSupported) => {
|
|
1385
|
-
if (setImmediateSupported) {
|
|
1386
|
-
return setImmediate;
|
|
1387
|
-
}
|
|
1388
|
-
return postMessageSupported ? ((token, callbacks) => {
|
|
1389
|
-
_global.addEventListener("message", ({ source, data }) => {
|
|
1390
|
-
if (source === _global && data === token) {
|
|
1391
|
-
callbacks.length && callbacks.shift()();
|
|
1392
|
-
}
|
|
1393
|
-
}, false);
|
|
1394
|
-
return (cb) => {
|
|
1395
|
-
callbacks.push(cb);
|
|
1396
|
-
_global.postMessage(token, "*");
|
|
1397
|
-
};
|
|
1398
|
-
})(`axios@${Math.random()}`, []) : (cb) => setTimeout(cb);
|
|
1399
|
-
})(
|
|
1400
|
-
typeof setImmediate === "function",
|
|
1401
|
-
isFunction(_global.postMessage)
|
|
1402
|
-
);
|
|
1403
|
-
const asap = typeof queueMicrotask !== "undefined" ? queueMicrotask.bind(_global) : typeof process !== "undefined" && process.nextTick || _setImmediate;
|
|
1404
|
-
const utils$1 = {
|
|
1405
|
-
isArray,
|
|
1406
|
-
isArrayBuffer,
|
|
1407
|
-
isBuffer,
|
|
1408
|
-
isFormData,
|
|
1409
|
-
isArrayBufferView,
|
|
1410
|
-
isString,
|
|
1411
|
-
isNumber,
|
|
1412
|
-
isBoolean,
|
|
1413
|
-
isObject,
|
|
1414
|
-
isPlainObject,
|
|
1415
|
-
isReadableStream,
|
|
1416
|
-
isRequest,
|
|
1417
|
-
isResponse,
|
|
1418
|
-
isHeaders,
|
|
1419
|
-
isUndefined,
|
|
1420
|
-
isDate,
|
|
1421
|
-
isFile,
|
|
1422
|
-
isBlob,
|
|
1423
|
-
isRegExp,
|
|
1424
|
-
isFunction,
|
|
1425
|
-
isStream,
|
|
1426
|
-
isURLSearchParams,
|
|
1427
|
-
isTypedArray,
|
|
1428
|
-
isFileList,
|
|
1429
|
-
forEach,
|
|
1430
|
-
merge,
|
|
1431
|
-
extend,
|
|
1432
|
-
trim,
|
|
1433
|
-
stripBOM,
|
|
1434
|
-
inherits,
|
|
1435
|
-
toFlatObject,
|
|
1436
|
-
kindOf,
|
|
1437
|
-
kindOfTest,
|
|
1438
|
-
endsWith,
|
|
1439
|
-
toArray,
|
|
1440
|
-
forEachEntry,
|
|
1441
|
-
matchAll,
|
|
1442
|
-
isHTMLForm,
|
|
1443
|
-
hasOwnProperty,
|
|
1444
|
-
hasOwnProp: hasOwnProperty,
|
|
1445
|
-
// an alias to avoid ESLint no-prototype-builtins detection
|
|
1446
|
-
reduceDescriptors,
|
|
1447
|
-
freezeMethods,
|
|
1448
|
-
toObjectSet,
|
|
1449
|
-
toCamelCase,
|
|
1450
|
-
noop,
|
|
1451
|
-
toFiniteNumber,
|
|
1452
|
-
findKey,
|
|
1453
|
-
global: _global,
|
|
1454
|
-
isContextDefined,
|
|
1455
|
-
ALPHABET,
|
|
1456
|
-
generateString,
|
|
1457
|
-
isSpecCompliantForm,
|
|
1458
|
-
toJSONObject,
|
|
1459
|
-
isAsyncFn,
|
|
1460
|
-
isThenable,
|
|
1461
|
-
setImmediate: _setImmediate,
|
|
1462
|
-
asap
|
|
1463
|
-
};
|
|
1464
|
-
function AxiosError(message, code, config, request, response) {
|
|
1465
|
-
Error.call(this);
|
|
1466
|
-
if (Error.captureStackTrace) {
|
|
1467
|
-
Error.captureStackTrace(this, this.constructor);
|
|
1468
|
-
} else {
|
|
1469
|
-
this.stack = new Error().stack;
|
|
1470
|
-
}
|
|
1471
|
-
this.message = message;
|
|
1472
|
-
this.name = "AxiosError";
|
|
1473
|
-
code && (this.code = code);
|
|
1474
|
-
config && (this.config = config);
|
|
1475
|
-
request && (this.request = request);
|
|
1476
|
-
if (response) {
|
|
1477
|
-
this.response = response;
|
|
1478
|
-
this.status = response.status ? response.status : null;
|
|
1479
|
-
}
|
|
1480
|
-
}
|
|
1481
|
-
utils$1.inherits(AxiosError, Error, {
|
|
1482
|
-
toJSON: function toJSON() {
|
|
1483
|
-
return {
|
|
1484
|
-
// Standard
|
|
1485
|
-
message: this.message,
|
|
1486
|
-
name: this.name,
|
|
1487
|
-
// Microsoft
|
|
1488
|
-
description: this.description,
|
|
1489
|
-
number: this.number,
|
|
1490
|
-
// Mozilla
|
|
1491
|
-
fileName: this.fileName,
|
|
1492
|
-
lineNumber: this.lineNumber,
|
|
1493
|
-
columnNumber: this.columnNumber,
|
|
1494
|
-
stack: this.stack,
|
|
1495
|
-
// Axios
|
|
1496
|
-
config: utils$1.toJSONObject(this.config),
|
|
1497
|
-
code: this.code,
|
|
1498
|
-
status: this.status
|
|
1499
|
-
};
|
|
1500
|
-
}
|
|
1501
|
-
});
|
|
1502
|
-
const prototype$1 = AxiosError.prototype;
|
|
1503
|
-
const descriptors = {};
|
|
1504
|
-
[
|
|
1505
|
-
"ERR_BAD_OPTION_VALUE",
|
|
1506
|
-
"ERR_BAD_OPTION",
|
|
1507
|
-
"ECONNABORTED",
|
|
1508
|
-
"ETIMEDOUT",
|
|
1509
|
-
"ERR_NETWORK",
|
|
1510
|
-
"ERR_FR_TOO_MANY_REDIRECTS",
|
|
1511
|
-
"ERR_DEPRECATED",
|
|
1512
|
-
"ERR_BAD_RESPONSE",
|
|
1513
|
-
"ERR_BAD_REQUEST",
|
|
1514
|
-
"ERR_CANCELED",
|
|
1515
|
-
"ERR_NOT_SUPPORT",
|
|
1516
|
-
"ERR_INVALID_URL"
|
|
1517
|
-
// eslint-disable-next-line func-names
|
|
1518
|
-
].forEach((code) => {
|
|
1519
|
-
descriptors[code] = { value: code };
|
|
1520
|
-
});
|
|
1521
|
-
Object.defineProperties(AxiosError, descriptors);
|
|
1522
|
-
Object.defineProperty(prototype$1, "isAxiosError", { value: true });
|
|
1523
|
-
AxiosError.from = (error, code, config, request, response, customProps) => {
|
|
1524
|
-
const axiosError = Object.create(prototype$1);
|
|
1525
|
-
utils$1.toFlatObject(error, axiosError, function filter2(obj) {
|
|
1526
|
-
return obj !== Error.prototype;
|
|
1527
|
-
}, (prop) => {
|
|
1528
|
-
return prop !== "isAxiosError";
|
|
1529
|
-
});
|
|
1530
|
-
AxiosError.call(axiosError, error.message, code, config, request, response);
|
|
1531
|
-
axiosError.cause = error;
|
|
1532
|
-
axiosError.name = error.name;
|
|
1533
|
-
customProps && Object.assign(axiosError, customProps);
|
|
1534
|
-
return axiosError;
|
|
1535
|
-
};
|
|
1536
|
-
const httpAdapter = null;
|
|
1537
|
-
function isVisitable(thing) {
|
|
1538
|
-
return utils$1.isPlainObject(thing) || utils$1.isArray(thing);
|
|
1539
|
-
}
|
|
1540
|
-
function removeBrackets(key) {
|
|
1541
|
-
return utils$1.endsWith(key, "[]") ? key.slice(0, -2) : key;
|
|
1542
|
-
}
|
|
1543
|
-
function renderKey(path, key, dots) {
|
|
1544
|
-
if (!path) return key;
|
|
1545
|
-
return path.concat(key).map(function each(token, i) {
|
|
1546
|
-
token = removeBrackets(token);
|
|
1547
|
-
return !dots && i ? "[" + token + "]" : token;
|
|
1548
|
-
}).join(dots ? "." : "");
|
|
1549
|
-
}
|
|
1550
|
-
function isFlatArray(arr) {
|
|
1551
|
-
return utils$1.isArray(arr) && !arr.some(isVisitable);
|
|
1552
|
-
}
|
|
1553
|
-
const predicates = utils$1.toFlatObject(utils$1, {}, null, function filter(prop) {
|
|
1554
|
-
return /^is[A-Z]/.test(prop);
|
|
1555
|
-
});
|
|
1556
|
-
function toFormData(obj, formData, options) {
|
|
1557
|
-
if (!utils$1.isObject(obj)) {
|
|
1558
|
-
throw new TypeError("target must be an object");
|
|
1559
|
-
}
|
|
1560
|
-
formData = formData || new FormData();
|
|
1561
|
-
options = utils$1.toFlatObject(options, {
|
|
1562
|
-
metaTokens: true,
|
|
1563
|
-
dots: false,
|
|
1564
|
-
indexes: false
|
|
1565
|
-
}, false, function defined(option, source) {
|
|
1566
|
-
return !utils$1.isUndefined(source[option]);
|
|
1567
|
-
});
|
|
1568
|
-
const metaTokens = options.metaTokens;
|
|
1569
|
-
const visitor = options.visitor || defaultVisitor;
|
|
1570
|
-
const dots = options.dots;
|
|
1571
|
-
const indexes = options.indexes;
|
|
1572
|
-
const _Blob = options.Blob || typeof Blob !== "undefined" && Blob;
|
|
1573
|
-
const useBlob = _Blob && utils$1.isSpecCompliantForm(formData);
|
|
1574
|
-
if (!utils$1.isFunction(visitor)) {
|
|
1575
|
-
throw new TypeError("visitor must be a function");
|
|
1576
|
-
}
|
|
1577
|
-
function convertValue(value) {
|
|
1578
|
-
if (value === null) return "";
|
|
1579
|
-
if (utils$1.isDate(value)) {
|
|
1580
|
-
return value.toISOString();
|
|
1581
|
-
}
|
|
1582
|
-
if (!useBlob && utils$1.isBlob(value)) {
|
|
1583
|
-
throw new AxiosError("Blob is not supported. Use a Buffer instead.");
|
|
1584
|
-
}
|
|
1585
|
-
if (utils$1.isArrayBuffer(value) || utils$1.isTypedArray(value)) {
|
|
1586
|
-
return useBlob && typeof Blob === "function" ? new Blob([value]) : Buffer.from(value);
|
|
1587
|
-
}
|
|
1588
|
-
return value;
|
|
1589
|
-
}
|
|
1590
|
-
function defaultVisitor(value, key, path) {
|
|
1591
|
-
let arr = value;
|
|
1592
|
-
if (value && !path && typeof value === "object") {
|
|
1593
|
-
if (utils$1.endsWith(key, "{}")) {
|
|
1594
|
-
key = metaTokens ? key : key.slice(0, -2);
|
|
1595
|
-
value = JSON.stringify(value);
|
|
1596
|
-
} else if (utils$1.isArray(value) && isFlatArray(value) || (utils$1.isFileList(value) || utils$1.endsWith(key, "[]")) && (arr = utils$1.toArray(value))) {
|
|
1597
|
-
key = removeBrackets(key);
|
|
1598
|
-
arr.forEach(function each(el, index) {
|
|
1599
|
-
!(utils$1.isUndefined(el) || el === null) && formData.append(
|
|
1600
|
-
// eslint-disable-next-line no-nested-ternary
|
|
1601
|
-
indexes === true ? renderKey([key], index, dots) : indexes === null ? key : key + "[]",
|
|
1602
|
-
convertValue(el)
|
|
1603
|
-
);
|
|
1604
|
-
});
|
|
1605
|
-
return false;
|
|
1606
|
-
}
|
|
1607
|
-
}
|
|
1608
|
-
if (isVisitable(value)) {
|
|
1609
|
-
return true;
|
|
1610
|
-
}
|
|
1611
|
-
formData.append(renderKey(path, key, dots), convertValue(value));
|
|
1612
|
-
return false;
|
|
1613
|
-
}
|
|
1614
|
-
const stack = [];
|
|
1615
|
-
const exposedHelpers = Object.assign(predicates, {
|
|
1616
|
-
defaultVisitor,
|
|
1617
|
-
convertValue,
|
|
1618
|
-
isVisitable
|
|
1619
|
-
});
|
|
1620
|
-
function build(value, path) {
|
|
1621
|
-
if (utils$1.isUndefined(value)) return;
|
|
1622
|
-
if (stack.indexOf(value) !== -1) {
|
|
1623
|
-
throw Error("Circular reference detected in " + path.join("."));
|
|
1624
|
-
}
|
|
1625
|
-
stack.push(value);
|
|
1626
|
-
utils$1.forEach(value, function each(el, key) {
|
|
1627
|
-
const result = !(utils$1.isUndefined(el) || el === null) && visitor.call(
|
|
1628
|
-
formData,
|
|
1629
|
-
el,
|
|
1630
|
-
utils$1.isString(key) ? key.trim() : key,
|
|
1631
|
-
path,
|
|
1632
|
-
exposedHelpers
|
|
1633
|
-
);
|
|
1634
|
-
if (result === true) {
|
|
1635
|
-
build(el, path ? path.concat(key) : [key]);
|
|
1636
|
-
}
|
|
1637
|
-
});
|
|
1638
|
-
stack.pop();
|
|
1639
|
-
}
|
|
1640
|
-
if (!utils$1.isObject(obj)) {
|
|
1641
|
-
throw new TypeError("data must be an object");
|
|
1642
|
-
}
|
|
1643
|
-
build(obj);
|
|
1644
|
-
return formData;
|
|
1645
|
-
}
|
|
1646
|
-
function encode$1(str) {
|
|
1647
|
-
const charMap = {
|
|
1648
|
-
"!": "%21",
|
|
1649
|
-
"'": "%27",
|
|
1650
|
-
"(": "%28",
|
|
1651
|
-
")": "%29",
|
|
1652
|
-
"~": "%7E",
|
|
1653
|
-
"%20": "+",
|
|
1654
|
-
"%00": "\0"
|
|
1655
|
-
};
|
|
1656
|
-
return encodeURIComponent(str).replace(/[!'()~]|%20|%00/g, function replacer(match) {
|
|
1657
|
-
return charMap[match];
|
|
1658
|
-
});
|
|
1659
|
-
}
|
|
1660
|
-
function AxiosURLSearchParams(params, options) {
|
|
1661
|
-
this._pairs = [];
|
|
1662
|
-
params && toFormData(params, this, options);
|
|
1663
|
-
}
|
|
1664
|
-
const prototype = AxiosURLSearchParams.prototype;
|
|
1665
|
-
prototype.append = function append(name, value) {
|
|
1666
|
-
this._pairs.push([name, value]);
|
|
1667
|
-
};
|
|
1668
|
-
prototype.toString = function toString2(encoder) {
|
|
1669
|
-
const _encode = encoder ? function(value) {
|
|
1670
|
-
return encoder.call(this, value, encode$1);
|
|
1671
|
-
} : encode$1;
|
|
1672
|
-
return this._pairs.map(function each(pair) {
|
|
1673
|
-
return _encode(pair[0]) + "=" + _encode(pair[1]);
|
|
1674
|
-
}, "").join("&");
|
|
1675
|
-
};
|
|
1676
|
-
function encode(val) {
|
|
1677
|
-
return encodeURIComponent(val).replace(/%3A/gi, ":").replace(/%24/g, "$").replace(/%2C/gi, ",").replace(/%20/g, "+").replace(/%5B/gi, "[").replace(/%5D/gi, "]");
|
|
1678
|
-
}
|
|
1679
|
-
function buildURL(url, params, options) {
|
|
1680
|
-
if (!params) {
|
|
1681
|
-
return url;
|
|
1682
|
-
}
|
|
1683
|
-
const _encode = options && options.encode || encode;
|
|
1684
|
-
if (utils$1.isFunction(options)) {
|
|
1685
|
-
options = {
|
|
1686
|
-
serialize: options
|
|
1687
|
-
};
|
|
1688
|
-
}
|
|
1689
|
-
const serializeFn = options && options.serialize;
|
|
1690
|
-
let serializedParams;
|
|
1691
|
-
if (serializeFn) {
|
|
1692
|
-
serializedParams = serializeFn(params, options);
|
|
1693
|
-
} else {
|
|
1694
|
-
serializedParams = utils$1.isURLSearchParams(params) ? params.toString() : new AxiosURLSearchParams(params, options).toString(_encode);
|
|
1695
|
-
}
|
|
1696
|
-
if (serializedParams) {
|
|
1697
|
-
const hashmarkIndex = url.indexOf("#");
|
|
1698
|
-
if (hashmarkIndex !== -1) {
|
|
1699
|
-
url = url.slice(0, hashmarkIndex);
|
|
1700
|
-
}
|
|
1701
|
-
url += (url.indexOf("?") === -1 ? "?" : "&") + serializedParams;
|
|
1702
|
-
}
|
|
1703
|
-
return url;
|
|
1704
|
-
}
|
|
1705
|
-
class InterceptorManager {
|
|
1706
|
-
constructor() {
|
|
1707
|
-
this.handlers = [];
|
|
1708
|
-
}
|
|
1709
|
-
/**
|
|
1710
|
-
* Add a new interceptor to the stack
|
|
1711
|
-
*
|
|
1712
|
-
* @param {Function} fulfilled The function to handle `then` for a `Promise`
|
|
1713
|
-
* @param {Function} rejected The function to handle `reject` for a `Promise`
|
|
1714
|
-
*
|
|
1715
|
-
* @return {Number} An ID used to remove interceptor later
|
|
1716
|
-
*/
|
|
1717
|
-
use(fulfilled, rejected, options) {
|
|
1718
|
-
this.handlers.push({
|
|
1719
|
-
fulfilled,
|
|
1720
|
-
rejected,
|
|
1721
|
-
synchronous: options ? options.synchronous : false,
|
|
1722
|
-
runWhen: options ? options.runWhen : null
|
|
1723
|
-
});
|
|
1724
|
-
return this.handlers.length - 1;
|
|
1725
|
-
}
|
|
1726
|
-
/**
|
|
1727
|
-
* Remove an interceptor from the stack
|
|
1728
|
-
*
|
|
1729
|
-
* @param {Number} id The ID that was returned by `use`
|
|
1730
|
-
*
|
|
1731
|
-
* @returns {Boolean} `true` if the interceptor was removed, `false` otherwise
|
|
1732
|
-
*/
|
|
1733
|
-
eject(id) {
|
|
1734
|
-
if (this.handlers[id]) {
|
|
1735
|
-
this.handlers[id] = null;
|
|
1736
|
-
}
|
|
1737
|
-
}
|
|
1738
|
-
/**
|
|
1739
|
-
* Clear all interceptors from the stack
|
|
1740
|
-
*
|
|
1741
|
-
* @returns {void}
|
|
1742
|
-
*/
|
|
1743
|
-
clear() {
|
|
1744
|
-
if (this.handlers) {
|
|
1745
|
-
this.handlers = [];
|
|
1746
|
-
}
|
|
1747
|
-
}
|
|
1748
|
-
/**
|
|
1749
|
-
* Iterate over all the registered interceptors
|
|
1750
|
-
*
|
|
1751
|
-
* This method is particularly useful for skipping over any
|
|
1752
|
-
* interceptors that may have become `null` calling `eject`.
|
|
1753
|
-
*
|
|
1754
|
-
* @param {Function} fn The function to call for each interceptor
|
|
1755
|
-
*
|
|
1756
|
-
* @returns {void}
|
|
1757
|
-
*/
|
|
1758
|
-
forEach(fn) {
|
|
1759
|
-
utils$1.forEach(this.handlers, function forEachHandler(h) {
|
|
1760
|
-
if (h !== null) {
|
|
1761
|
-
fn(h);
|
|
1762
|
-
}
|
|
1763
|
-
});
|
|
1764
|
-
}
|
|
1765
|
-
}
|
|
1766
|
-
const transitionalDefaults = {
|
|
1767
|
-
silentJSONParsing: true,
|
|
1768
|
-
forcedJSONParsing: true,
|
|
1769
|
-
clarifyTimeoutError: false
|
|
1770
|
-
};
|
|
1771
|
-
const URLSearchParams$1 = typeof URLSearchParams !== "undefined" ? URLSearchParams : AxiosURLSearchParams;
|
|
1772
|
-
const FormData$1 = typeof FormData !== "undefined" ? FormData : null;
|
|
1773
|
-
const Blob$1 = typeof Blob !== "undefined" ? Blob : null;
|
|
1774
|
-
const platform$1 = {
|
|
1775
|
-
isBrowser: true,
|
|
1776
|
-
classes: {
|
|
1777
|
-
URLSearchParams: URLSearchParams$1,
|
|
1778
|
-
FormData: FormData$1,
|
|
1779
|
-
Blob: Blob$1
|
|
1780
|
-
},
|
|
1781
|
-
protocols: ["http", "https", "file", "blob", "url", "data"]
|
|
1782
|
-
};
|
|
1783
|
-
const hasBrowserEnv = typeof window !== "undefined" && typeof document !== "undefined";
|
|
1784
|
-
const _navigator = typeof navigator === "object" && navigator || void 0;
|
|
1785
|
-
const hasStandardBrowserEnv = hasBrowserEnv && (!_navigator || ["ReactNative", "NativeScript", "NS"].indexOf(_navigator.product) < 0);
|
|
1786
|
-
const hasStandardBrowserWebWorkerEnv = (() => {
|
|
1787
|
-
return typeof WorkerGlobalScope !== "undefined" && // eslint-disable-next-line no-undef
|
|
1788
|
-
self instanceof WorkerGlobalScope && typeof self.importScripts === "function";
|
|
1789
|
-
})();
|
|
1790
|
-
const origin = hasBrowserEnv && window.location.href || "http://localhost";
|
|
1791
|
-
const utils = /* @__PURE__ */ Object.freeze(/* @__PURE__ */ Object.defineProperty({
|
|
1792
|
-
__proto__: null,
|
|
1793
|
-
hasBrowserEnv,
|
|
1794
|
-
hasStandardBrowserEnv,
|
|
1795
|
-
hasStandardBrowserWebWorkerEnv,
|
|
1796
|
-
navigator: _navigator,
|
|
1797
|
-
origin
|
|
1798
|
-
}, Symbol.toStringTag, { value: "Module" }));
|
|
1799
|
-
const platform = {
|
|
1800
|
-
...utils,
|
|
1801
|
-
...platform$1
|
|
1802
|
-
};
|
|
1803
|
-
function toURLEncodedForm(data, options) {
|
|
1804
|
-
return toFormData(data, new platform.classes.URLSearchParams(), Object.assign({
|
|
1805
|
-
visitor: function(value, key, path, helpers) {
|
|
1806
|
-
if (platform.isNode && utils$1.isBuffer(value)) {
|
|
1807
|
-
this.append(key, value.toString("base64"));
|
|
1808
|
-
return false;
|
|
1809
|
-
}
|
|
1810
|
-
return helpers.defaultVisitor.apply(this, arguments);
|
|
1811
|
-
}
|
|
1812
|
-
}, options));
|
|
1813
|
-
}
|
|
1814
|
-
function parsePropPath(name) {
|
|
1815
|
-
return utils$1.matchAll(/\w+|\[(\w*)]/g, name).map((match) => {
|
|
1816
|
-
return match[0] === "[]" ? "" : match[1] || match[0];
|
|
1817
|
-
});
|
|
1818
|
-
}
|
|
1819
|
-
function arrayToObject(arr) {
|
|
1820
|
-
const obj = {};
|
|
1821
|
-
const keys = Object.keys(arr);
|
|
1822
|
-
let i;
|
|
1823
|
-
const len = keys.length;
|
|
1824
|
-
let key;
|
|
1825
|
-
for (i = 0; i < len; i++) {
|
|
1826
|
-
key = keys[i];
|
|
1827
|
-
obj[key] = arr[key];
|
|
1828
|
-
}
|
|
1829
|
-
return obj;
|
|
1830
|
-
}
|
|
1831
|
-
function formDataToJSON(formData) {
|
|
1832
|
-
function buildPath(path, value, target, index) {
|
|
1833
|
-
let name = path[index++];
|
|
1834
|
-
if (name === "__proto__") return true;
|
|
1835
|
-
const isNumericKey = Number.isFinite(+name);
|
|
1836
|
-
const isLast = index >= path.length;
|
|
1837
|
-
name = !name && utils$1.isArray(target) ? target.length : name;
|
|
1838
|
-
if (isLast) {
|
|
1839
|
-
if (utils$1.hasOwnProp(target, name)) {
|
|
1840
|
-
target[name] = [target[name], value];
|
|
1841
|
-
} else {
|
|
1842
|
-
target[name] = value;
|
|
1843
|
-
}
|
|
1844
|
-
return !isNumericKey;
|
|
1845
|
-
}
|
|
1846
|
-
if (!target[name] || !utils$1.isObject(target[name])) {
|
|
1847
|
-
target[name] = [];
|
|
1848
|
-
}
|
|
1849
|
-
const result = buildPath(path, value, target[name], index);
|
|
1850
|
-
if (result && utils$1.isArray(target[name])) {
|
|
1851
|
-
target[name] = arrayToObject(target[name]);
|
|
1852
|
-
}
|
|
1853
|
-
return !isNumericKey;
|
|
1854
|
-
}
|
|
1855
|
-
if (utils$1.isFormData(formData) && utils$1.isFunction(formData.entries)) {
|
|
1856
|
-
const obj = {};
|
|
1857
|
-
utils$1.forEachEntry(formData, (name, value) => {
|
|
1858
|
-
buildPath(parsePropPath(name), value, obj, 0);
|
|
1859
|
-
});
|
|
1860
|
-
return obj;
|
|
1861
|
-
}
|
|
1862
|
-
return null;
|
|
1863
|
-
}
|
|
1864
|
-
function stringifySafely(rawValue, parser, encoder) {
|
|
1865
|
-
if (utils$1.isString(rawValue)) {
|
|
1866
|
-
try {
|
|
1867
|
-
(parser || JSON.parse)(rawValue);
|
|
1868
|
-
return utils$1.trim(rawValue);
|
|
1869
|
-
} catch (e) {
|
|
1870
|
-
if (e.name !== "SyntaxError") {
|
|
1871
|
-
throw e;
|
|
1872
|
-
}
|
|
1873
|
-
}
|
|
1874
|
-
}
|
|
1875
|
-
return (0, JSON.stringify)(rawValue);
|
|
1876
|
-
}
|
|
1877
|
-
const defaults = {
|
|
1878
|
-
transitional: transitionalDefaults,
|
|
1879
|
-
adapter: ["xhr", "http", "fetch"],
|
|
1880
|
-
transformRequest: [function transformRequest(data, headers) {
|
|
1881
|
-
const contentType = headers.getContentType() || "";
|
|
1882
|
-
const hasJSONContentType = contentType.indexOf("application/json") > -1;
|
|
1883
|
-
const isObjectPayload = utils$1.isObject(data);
|
|
1884
|
-
if (isObjectPayload && utils$1.isHTMLForm(data)) {
|
|
1885
|
-
data = new FormData(data);
|
|
1886
|
-
}
|
|
1887
|
-
const isFormData2 = utils$1.isFormData(data);
|
|
1888
|
-
if (isFormData2) {
|
|
1889
|
-
return hasJSONContentType ? JSON.stringify(formDataToJSON(data)) : data;
|
|
1890
|
-
}
|
|
1891
|
-
if (utils$1.isArrayBuffer(data) || utils$1.isBuffer(data) || utils$1.isStream(data) || utils$1.isFile(data) || utils$1.isBlob(data) || utils$1.isReadableStream(data)) {
|
|
1892
|
-
return data;
|
|
1893
|
-
}
|
|
1894
|
-
if (utils$1.isArrayBufferView(data)) {
|
|
1895
|
-
return data.buffer;
|
|
1896
|
-
}
|
|
1897
|
-
if (utils$1.isURLSearchParams(data)) {
|
|
1898
|
-
headers.setContentType("application/x-www-form-urlencoded;charset=utf-8", false);
|
|
1899
|
-
return data.toString();
|
|
1900
|
-
}
|
|
1901
|
-
let isFileList2;
|
|
1902
|
-
if (isObjectPayload) {
|
|
1903
|
-
if (contentType.indexOf("application/x-www-form-urlencoded") > -1) {
|
|
1904
|
-
return toURLEncodedForm(data, this.formSerializer).toString();
|
|
1905
|
-
}
|
|
1906
|
-
if ((isFileList2 = utils$1.isFileList(data)) || contentType.indexOf("multipart/form-data") > -1) {
|
|
1907
|
-
const _FormData = this.env && this.env.FormData;
|
|
1908
|
-
return toFormData(
|
|
1909
|
-
isFileList2 ? { "files[]": data } : data,
|
|
1910
|
-
_FormData && new _FormData(),
|
|
1911
|
-
this.formSerializer
|
|
1912
|
-
);
|
|
1913
|
-
}
|
|
1914
|
-
}
|
|
1915
|
-
if (isObjectPayload || hasJSONContentType) {
|
|
1916
|
-
headers.setContentType("application/json", false);
|
|
1917
|
-
return stringifySafely(data);
|
|
1918
|
-
}
|
|
1919
|
-
return data;
|
|
1920
|
-
}],
|
|
1921
|
-
transformResponse: [function transformResponse(data) {
|
|
1922
|
-
const transitional2 = this.transitional || defaults.transitional;
|
|
1923
|
-
const forcedJSONParsing = transitional2 && transitional2.forcedJSONParsing;
|
|
1924
|
-
const JSONRequested = this.responseType === "json";
|
|
1925
|
-
if (utils$1.isResponse(data) || utils$1.isReadableStream(data)) {
|
|
1926
|
-
return data;
|
|
1927
|
-
}
|
|
1928
|
-
if (data && utils$1.isString(data) && (forcedJSONParsing && !this.responseType || JSONRequested)) {
|
|
1929
|
-
const silentJSONParsing = transitional2 && transitional2.silentJSONParsing;
|
|
1930
|
-
const strictJSONParsing = !silentJSONParsing && JSONRequested;
|
|
1931
|
-
try {
|
|
1932
|
-
return JSON.parse(data);
|
|
1933
|
-
} catch (e) {
|
|
1934
|
-
if (strictJSONParsing) {
|
|
1935
|
-
if (e.name === "SyntaxError") {
|
|
1936
|
-
throw AxiosError.from(e, AxiosError.ERR_BAD_RESPONSE, this, null, this.response);
|
|
1937
|
-
}
|
|
1938
|
-
throw e;
|
|
1939
|
-
}
|
|
1940
|
-
}
|
|
1941
|
-
}
|
|
1942
|
-
return data;
|
|
1943
|
-
}],
|
|
1944
|
-
/**
|
|
1945
|
-
* A timeout in milliseconds to abort a request. If set to 0 (default) a
|
|
1946
|
-
* timeout is not created.
|
|
1947
|
-
*/
|
|
1948
|
-
timeout: 0,
|
|
1949
|
-
xsrfCookieName: "XSRF-TOKEN",
|
|
1950
|
-
xsrfHeaderName: "X-XSRF-TOKEN",
|
|
1951
|
-
maxContentLength: -1,
|
|
1952
|
-
maxBodyLength: -1,
|
|
1953
|
-
env: {
|
|
1954
|
-
FormData: platform.classes.FormData,
|
|
1955
|
-
Blob: platform.classes.Blob
|
|
1956
|
-
},
|
|
1957
|
-
validateStatus: function validateStatus(status) {
|
|
1958
|
-
return status >= 200 && status < 300;
|
|
1959
|
-
},
|
|
1960
|
-
headers: {
|
|
1961
|
-
common: {
|
|
1962
|
-
"Accept": "application/json, text/plain, */*",
|
|
1963
|
-
"Content-Type": void 0
|
|
1964
|
-
}
|
|
1965
|
-
}
|
|
1966
|
-
};
|
|
1967
|
-
utils$1.forEach(["delete", "get", "head", "post", "put", "patch"], (method) => {
|
|
1968
|
-
defaults.headers[method] = {};
|
|
1969
|
-
});
|
|
1970
|
-
const ignoreDuplicateOf = utils$1.toObjectSet([
|
|
1971
|
-
"age",
|
|
1972
|
-
"authorization",
|
|
1973
|
-
"content-length",
|
|
1974
|
-
"content-type",
|
|
1975
|
-
"etag",
|
|
1976
|
-
"expires",
|
|
1977
|
-
"from",
|
|
1978
|
-
"host",
|
|
1979
|
-
"if-modified-since",
|
|
1980
|
-
"if-unmodified-since",
|
|
1981
|
-
"last-modified",
|
|
1982
|
-
"location",
|
|
1983
|
-
"max-forwards",
|
|
1984
|
-
"proxy-authorization",
|
|
1985
|
-
"referer",
|
|
1986
|
-
"retry-after",
|
|
1987
|
-
"user-agent"
|
|
1988
|
-
]);
|
|
1989
|
-
const parseHeaders = (rawHeaders) => {
|
|
1990
|
-
const parsed = {};
|
|
1991
|
-
let key;
|
|
1992
|
-
let val;
|
|
1993
|
-
let i;
|
|
1994
|
-
rawHeaders && rawHeaders.split("\n").forEach(function parser(line) {
|
|
1995
|
-
i = line.indexOf(":");
|
|
1996
|
-
key = line.substring(0, i).trim().toLowerCase();
|
|
1997
|
-
val = line.substring(i + 1).trim();
|
|
1998
|
-
if (!key || parsed[key] && ignoreDuplicateOf[key]) {
|
|
1999
|
-
return;
|
|
2000
|
-
}
|
|
2001
|
-
if (key === "set-cookie") {
|
|
2002
|
-
if (parsed[key]) {
|
|
2003
|
-
parsed[key].push(val);
|
|
2004
|
-
} else {
|
|
2005
|
-
parsed[key] = [val];
|
|
2006
|
-
}
|
|
2007
|
-
} else {
|
|
2008
|
-
parsed[key] = parsed[key] ? parsed[key] + ", " + val : val;
|
|
2009
|
-
}
|
|
2010
|
-
});
|
|
2011
|
-
return parsed;
|
|
2012
|
-
};
|
|
2013
|
-
const $internals = Symbol("internals");
|
|
2014
|
-
function normalizeHeader(header) {
|
|
2015
|
-
return header && String(header).trim().toLowerCase();
|
|
2016
|
-
}
|
|
2017
|
-
function normalizeValue(value) {
|
|
2018
|
-
if (value === false || value == null) {
|
|
2019
|
-
return value;
|
|
2020
|
-
}
|
|
2021
|
-
return utils$1.isArray(value) ? value.map(normalizeValue) : String(value);
|
|
2022
|
-
}
|
|
2023
|
-
function parseTokens(str) {
|
|
2024
|
-
const tokens = /* @__PURE__ */ Object.create(null);
|
|
2025
|
-
const tokensRE = /([^\s,;=]+)\s*(?:=\s*([^,;]+))?/g;
|
|
2026
|
-
let match;
|
|
2027
|
-
while (match = tokensRE.exec(str)) {
|
|
2028
|
-
tokens[match[1]] = match[2];
|
|
2029
|
-
}
|
|
2030
|
-
return tokens;
|
|
2031
|
-
}
|
|
2032
|
-
const isValidHeaderName = (str) => /^[-_a-zA-Z0-9^`|~,!#$%&'*+.]+$/.test(str.trim());
|
|
2033
|
-
function matchHeaderValue(context, value, header, filter2, isHeaderNameFilter) {
|
|
2034
|
-
if (utils$1.isFunction(filter2)) {
|
|
2035
|
-
return filter2.call(this, value, header);
|
|
2036
|
-
}
|
|
2037
|
-
if (isHeaderNameFilter) {
|
|
2038
|
-
value = header;
|
|
2039
|
-
}
|
|
2040
|
-
if (!utils$1.isString(value)) return;
|
|
2041
|
-
if (utils$1.isString(filter2)) {
|
|
2042
|
-
return value.indexOf(filter2) !== -1;
|
|
2043
|
-
}
|
|
2044
|
-
if (utils$1.isRegExp(filter2)) {
|
|
2045
|
-
return filter2.test(value);
|
|
2046
|
-
}
|
|
2047
|
-
}
|
|
2048
|
-
function formatHeader(header) {
|
|
2049
|
-
return header.trim().toLowerCase().replace(/([a-z\d])(\w*)/g, (w, char, str) => {
|
|
2050
|
-
return char.toUpperCase() + str;
|
|
2051
|
-
});
|
|
2052
|
-
}
|
|
2053
|
-
function buildAccessors(obj, header) {
|
|
2054
|
-
const accessorName = utils$1.toCamelCase(" " + header);
|
|
2055
|
-
["get", "set", "has"].forEach((methodName) => {
|
|
2056
|
-
Object.defineProperty(obj, methodName + accessorName, {
|
|
2057
|
-
value: function(arg1, arg2, arg3) {
|
|
2058
|
-
return this[methodName].call(this, header, arg1, arg2, arg3);
|
|
2059
|
-
},
|
|
2060
|
-
configurable: true
|
|
2061
|
-
});
|
|
2062
|
-
});
|
|
2063
|
-
}
|
|
2064
|
-
class AxiosHeaders {
|
|
2065
|
-
constructor(headers) {
|
|
2066
|
-
headers && this.set(headers);
|
|
2067
|
-
}
|
|
2068
|
-
set(header, valueOrRewrite, rewrite) {
|
|
2069
|
-
const self2 = this;
|
|
2070
|
-
function setHeader(_value, _header, _rewrite) {
|
|
2071
|
-
const lHeader = normalizeHeader(_header);
|
|
2072
|
-
if (!lHeader) {
|
|
2073
|
-
throw new Error("header name must be a non-empty string");
|
|
2074
|
-
}
|
|
2075
|
-
const key = utils$1.findKey(self2, lHeader);
|
|
2076
|
-
if (!key || self2[key] === void 0 || _rewrite === true || _rewrite === void 0 && self2[key] !== false) {
|
|
2077
|
-
self2[key || _header] = normalizeValue(_value);
|
|
2078
|
-
}
|
|
2079
|
-
}
|
|
2080
|
-
const setHeaders = (headers, _rewrite) => utils$1.forEach(headers, (_value, _header) => setHeader(_value, _header, _rewrite));
|
|
2081
|
-
if (utils$1.isPlainObject(header) || header instanceof this.constructor) {
|
|
2082
|
-
setHeaders(header, valueOrRewrite);
|
|
2083
|
-
} else if (utils$1.isString(header) && (header = header.trim()) && !isValidHeaderName(header)) {
|
|
2084
|
-
setHeaders(parseHeaders(header), valueOrRewrite);
|
|
2085
|
-
} else if (utils$1.isHeaders(header)) {
|
|
2086
|
-
for (const [key, value] of header.entries()) {
|
|
2087
|
-
setHeader(value, key, rewrite);
|
|
2088
|
-
}
|
|
2089
|
-
} else {
|
|
2090
|
-
header != null && setHeader(valueOrRewrite, header, rewrite);
|
|
2091
|
-
}
|
|
2092
|
-
return this;
|
|
2093
|
-
}
|
|
2094
|
-
get(header, parser) {
|
|
2095
|
-
header = normalizeHeader(header);
|
|
2096
|
-
if (header) {
|
|
2097
|
-
const key = utils$1.findKey(this, header);
|
|
2098
|
-
if (key) {
|
|
2099
|
-
const value = this[key];
|
|
2100
|
-
if (!parser) {
|
|
2101
|
-
return value;
|
|
2102
|
-
}
|
|
2103
|
-
if (parser === true) {
|
|
2104
|
-
return parseTokens(value);
|
|
2105
|
-
}
|
|
2106
|
-
if (utils$1.isFunction(parser)) {
|
|
2107
|
-
return parser.call(this, value, key);
|
|
2108
|
-
}
|
|
2109
|
-
if (utils$1.isRegExp(parser)) {
|
|
2110
|
-
return parser.exec(value);
|
|
2111
|
-
}
|
|
2112
|
-
throw new TypeError("parser must be boolean|regexp|function");
|
|
2113
|
-
}
|
|
2114
|
-
}
|
|
2115
|
-
}
|
|
2116
|
-
has(header, matcher) {
|
|
2117
|
-
header = normalizeHeader(header);
|
|
2118
|
-
if (header) {
|
|
2119
|
-
const key = utils$1.findKey(this, header);
|
|
2120
|
-
return !!(key && this[key] !== void 0 && (!matcher || matchHeaderValue(this, this[key], key, matcher)));
|
|
2121
|
-
}
|
|
2122
|
-
return false;
|
|
2123
|
-
}
|
|
2124
|
-
delete(header, matcher) {
|
|
2125
|
-
const self2 = this;
|
|
2126
|
-
let deleted = false;
|
|
2127
|
-
function deleteHeader(_header) {
|
|
2128
|
-
_header = normalizeHeader(_header);
|
|
2129
|
-
if (_header) {
|
|
2130
|
-
const key = utils$1.findKey(self2, _header);
|
|
2131
|
-
if (key && (!matcher || matchHeaderValue(self2, self2[key], key, matcher))) {
|
|
2132
|
-
delete self2[key];
|
|
2133
|
-
deleted = true;
|
|
2134
|
-
}
|
|
2135
|
-
}
|
|
2136
|
-
}
|
|
2137
|
-
if (utils$1.isArray(header)) {
|
|
2138
|
-
header.forEach(deleteHeader);
|
|
2139
|
-
} else {
|
|
2140
|
-
deleteHeader(header);
|
|
2141
|
-
}
|
|
2142
|
-
return deleted;
|
|
2143
|
-
}
|
|
2144
|
-
clear(matcher) {
|
|
2145
|
-
const keys = Object.keys(this);
|
|
2146
|
-
let i = keys.length;
|
|
2147
|
-
let deleted = false;
|
|
2148
|
-
while (i--) {
|
|
2149
|
-
const key = keys[i];
|
|
2150
|
-
if (!matcher || matchHeaderValue(this, this[key], key, matcher, true)) {
|
|
2151
|
-
delete this[key];
|
|
2152
|
-
deleted = true;
|
|
2153
|
-
}
|
|
2154
|
-
}
|
|
2155
|
-
return deleted;
|
|
2156
|
-
}
|
|
2157
|
-
normalize(format) {
|
|
2158
|
-
const self2 = this;
|
|
2159
|
-
const headers = {};
|
|
2160
|
-
utils$1.forEach(this, (value, header) => {
|
|
2161
|
-
const key = utils$1.findKey(headers, header);
|
|
2162
|
-
if (key) {
|
|
2163
|
-
self2[key] = normalizeValue(value);
|
|
2164
|
-
delete self2[header];
|
|
2165
|
-
return;
|
|
2166
|
-
}
|
|
2167
|
-
const normalized = format ? formatHeader(header) : String(header).trim();
|
|
2168
|
-
if (normalized !== header) {
|
|
2169
|
-
delete self2[header];
|
|
2170
|
-
}
|
|
2171
|
-
self2[normalized] = normalizeValue(value);
|
|
2172
|
-
headers[normalized] = true;
|
|
2173
|
-
});
|
|
2174
|
-
return this;
|
|
2175
|
-
}
|
|
2176
|
-
concat(...targets) {
|
|
2177
|
-
return this.constructor.concat(this, ...targets);
|
|
2178
|
-
}
|
|
2179
|
-
toJSON(asStrings) {
|
|
2180
|
-
const obj = /* @__PURE__ */ Object.create(null);
|
|
2181
|
-
utils$1.forEach(this, (value, header) => {
|
|
2182
|
-
value != null && value !== false && (obj[header] = asStrings && utils$1.isArray(value) ? value.join(", ") : value);
|
|
2183
|
-
});
|
|
2184
|
-
return obj;
|
|
2185
|
-
}
|
|
2186
|
-
[Symbol.iterator]() {
|
|
2187
|
-
return Object.entries(this.toJSON())[Symbol.iterator]();
|
|
2188
|
-
}
|
|
2189
|
-
toString() {
|
|
2190
|
-
return Object.entries(this.toJSON()).map(([header, value]) => header + ": " + value).join("\n");
|
|
2191
|
-
}
|
|
2192
|
-
get [Symbol.toStringTag]() {
|
|
2193
|
-
return "AxiosHeaders";
|
|
2194
|
-
}
|
|
2195
|
-
static from(thing) {
|
|
2196
|
-
return thing instanceof this ? thing : new this(thing);
|
|
2197
|
-
}
|
|
2198
|
-
static concat(first, ...targets) {
|
|
2199
|
-
const computed = new this(first);
|
|
2200
|
-
targets.forEach((target) => computed.set(target));
|
|
2201
|
-
return computed;
|
|
2202
|
-
}
|
|
2203
|
-
static accessor(header) {
|
|
2204
|
-
const internals = this[$internals] = this[$internals] = {
|
|
2205
|
-
accessors: {}
|
|
2206
|
-
};
|
|
2207
|
-
const accessors = internals.accessors;
|
|
2208
|
-
const prototype2 = this.prototype;
|
|
2209
|
-
function defineAccessor(_header) {
|
|
2210
|
-
const lHeader = normalizeHeader(_header);
|
|
2211
|
-
if (!accessors[lHeader]) {
|
|
2212
|
-
buildAccessors(prototype2, _header);
|
|
2213
|
-
accessors[lHeader] = true;
|
|
2214
|
-
}
|
|
2215
|
-
}
|
|
2216
|
-
utils$1.isArray(header) ? header.forEach(defineAccessor) : defineAccessor(header);
|
|
2217
|
-
return this;
|
|
2218
|
-
}
|
|
2219
|
-
}
|
|
2220
|
-
AxiosHeaders.accessor(["Content-Type", "Content-Length", "Accept", "Accept-Encoding", "User-Agent", "Authorization"]);
|
|
2221
|
-
utils$1.reduceDescriptors(AxiosHeaders.prototype, ({ value }, key) => {
|
|
2222
|
-
let mapped = key[0].toUpperCase() + key.slice(1);
|
|
2223
|
-
return {
|
|
2224
|
-
get: () => value,
|
|
2225
|
-
set(headerValue) {
|
|
2226
|
-
this[mapped] = headerValue;
|
|
2227
|
-
}
|
|
2228
|
-
};
|
|
2229
|
-
});
|
|
2230
|
-
utils$1.freezeMethods(AxiosHeaders);
|
|
2231
|
-
function transformData(fns, response) {
|
|
2232
|
-
const config = this || defaults;
|
|
2233
|
-
const context = response || config;
|
|
2234
|
-
const headers = AxiosHeaders.from(context.headers);
|
|
2235
|
-
let data = context.data;
|
|
2236
|
-
utils$1.forEach(fns, function transform(fn) {
|
|
2237
|
-
data = fn.call(config, data, headers.normalize(), response ? response.status : void 0);
|
|
2238
|
-
});
|
|
2239
|
-
headers.normalize();
|
|
2240
|
-
return data;
|
|
2241
|
-
}
|
|
2242
|
-
function isCancel(value) {
|
|
2243
|
-
return !!(value && value.__CANCEL__);
|
|
2244
|
-
}
|
|
2245
|
-
function CanceledError(message, config, request) {
|
|
2246
|
-
AxiosError.call(this, message == null ? "canceled" : message, AxiosError.ERR_CANCELED, config, request);
|
|
2247
|
-
this.name = "CanceledError";
|
|
2248
|
-
}
|
|
2249
|
-
utils$1.inherits(CanceledError, AxiosError, {
|
|
2250
|
-
__CANCEL__: true
|
|
2251
|
-
});
|
|
2252
|
-
function settle(resolve, reject, response) {
|
|
2253
|
-
const validateStatus2 = response.config.validateStatus;
|
|
2254
|
-
if (!response.status || !validateStatus2 || validateStatus2(response.status)) {
|
|
2255
|
-
resolve(response);
|
|
2256
|
-
} else {
|
|
2257
|
-
reject(new AxiosError(
|
|
2258
|
-
"Request failed with status code " + response.status,
|
|
2259
|
-
[AxiosError.ERR_BAD_REQUEST, AxiosError.ERR_BAD_RESPONSE][Math.floor(response.status / 100) - 4],
|
|
2260
|
-
response.config,
|
|
2261
|
-
response.request,
|
|
2262
|
-
response
|
|
2263
|
-
));
|
|
2264
|
-
}
|
|
2265
|
-
}
|
|
2266
|
-
function parseProtocol(url) {
|
|
2267
|
-
const match = /^([-+\w]{1,25})(:?\/\/|:)/.exec(url);
|
|
2268
|
-
return match && match[1] || "";
|
|
2269
|
-
}
|
|
2270
|
-
function speedometer(samplesCount, min) {
|
|
2271
|
-
samplesCount = samplesCount || 10;
|
|
2272
|
-
const bytes = new Array(samplesCount);
|
|
2273
|
-
const timestamps = new Array(samplesCount);
|
|
2274
|
-
let head = 0;
|
|
2275
|
-
let tail = 0;
|
|
2276
|
-
let firstSampleTS;
|
|
2277
|
-
min = min !== void 0 ? min : 1e3;
|
|
2278
|
-
return function push(chunkLength) {
|
|
2279
|
-
const now = Date.now();
|
|
2280
|
-
const startedAt = timestamps[tail];
|
|
2281
|
-
if (!firstSampleTS) {
|
|
2282
|
-
firstSampleTS = now;
|
|
2283
|
-
}
|
|
2284
|
-
bytes[head] = chunkLength;
|
|
2285
|
-
timestamps[head] = now;
|
|
2286
|
-
let i = tail;
|
|
2287
|
-
let bytesCount = 0;
|
|
2288
|
-
while (i !== head) {
|
|
2289
|
-
bytesCount += bytes[i++];
|
|
2290
|
-
i = i % samplesCount;
|
|
2291
|
-
}
|
|
2292
|
-
head = (head + 1) % samplesCount;
|
|
2293
|
-
if (head === tail) {
|
|
2294
|
-
tail = (tail + 1) % samplesCount;
|
|
2295
|
-
}
|
|
2296
|
-
if (now - firstSampleTS < min) {
|
|
2297
|
-
return;
|
|
2298
|
-
}
|
|
2299
|
-
const passed = startedAt && now - startedAt;
|
|
2300
|
-
return passed ? Math.round(bytesCount * 1e3 / passed) : void 0;
|
|
2301
|
-
};
|
|
2302
|
-
}
|
|
2303
|
-
function throttle(fn, freq) {
|
|
2304
|
-
let timestamp = 0;
|
|
2305
|
-
let threshold = 1e3 / freq;
|
|
2306
|
-
let lastArgs;
|
|
2307
|
-
let timer;
|
|
2308
|
-
const invoke = (args, now = Date.now()) => {
|
|
2309
|
-
timestamp = now;
|
|
2310
|
-
lastArgs = null;
|
|
2311
|
-
if (timer) {
|
|
2312
|
-
clearTimeout(timer);
|
|
2313
|
-
timer = null;
|
|
2314
|
-
}
|
|
2315
|
-
fn.apply(null, args);
|
|
2316
|
-
};
|
|
2317
|
-
const throttled = (...args) => {
|
|
2318
|
-
const now = Date.now();
|
|
2319
|
-
const passed = now - timestamp;
|
|
2320
|
-
if (passed >= threshold) {
|
|
2321
|
-
invoke(args, now);
|
|
2322
|
-
} else {
|
|
2323
|
-
lastArgs = args;
|
|
2324
|
-
if (!timer) {
|
|
2325
|
-
timer = setTimeout(() => {
|
|
2326
|
-
timer = null;
|
|
2327
|
-
invoke(lastArgs);
|
|
2328
|
-
}, threshold - passed);
|
|
2329
|
-
}
|
|
2330
|
-
}
|
|
2331
|
-
};
|
|
2332
|
-
const flush = () => lastArgs && invoke(lastArgs);
|
|
2333
|
-
return [throttled, flush];
|
|
2334
|
-
}
|
|
2335
|
-
const progressEventReducer = (listener, isDownloadStream, freq = 3) => {
|
|
2336
|
-
let bytesNotified = 0;
|
|
2337
|
-
const _speedometer = speedometer(50, 250);
|
|
2338
|
-
return throttle((e) => {
|
|
2339
|
-
const loaded = e.loaded;
|
|
2340
|
-
const total = e.lengthComputable ? e.total : void 0;
|
|
2341
|
-
const progressBytes = loaded - bytesNotified;
|
|
2342
|
-
const rate = _speedometer(progressBytes);
|
|
2343
|
-
const inRange = loaded <= total;
|
|
2344
|
-
bytesNotified = loaded;
|
|
2345
|
-
const data = {
|
|
2346
|
-
loaded,
|
|
2347
|
-
total,
|
|
2348
|
-
progress: total ? loaded / total : void 0,
|
|
2349
|
-
bytes: progressBytes,
|
|
2350
|
-
rate: rate ? rate : void 0,
|
|
2351
|
-
estimated: rate && total && inRange ? (total - loaded) / rate : void 0,
|
|
2352
|
-
event: e,
|
|
2353
|
-
lengthComputable: total != null,
|
|
2354
|
-
[isDownloadStream ? "download" : "upload"]: true
|
|
2355
|
-
};
|
|
2356
|
-
listener(data);
|
|
2357
|
-
}, freq);
|
|
2358
|
-
};
|
|
2359
|
-
const progressEventDecorator = (total, throttled) => {
|
|
2360
|
-
const lengthComputable = total != null;
|
|
2361
|
-
return [(loaded) => throttled[0]({
|
|
2362
|
-
lengthComputable,
|
|
2363
|
-
total,
|
|
2364
|
-
loaded
|
|
2365
|
-
}), throttled[1]];
|
|
2366
|
-
};
|
|
2367
|
-
const asyncDecorator = (fn) => (...args) => utils$1.asap(() => fn(...args));
|
|
2368
|
-
const isURLSameOrigin = platform.hasStandardBrowserEnv ? /* @__PURE__ */ ((origin2, isMSIE) => (url) => {
|
|
2369
|
-
url = new URL(url, platform.origin);
|
|
2370
|
-
return origin2.protocol === url.protocol && origin2.host === url.host && (isMSIE || origin2.port === url.port);
|
|
2371
|
-
})(
|
|
2372
|
-
new URL(platform.origin),
|
|
2373
|
-
platform.navigator && /(msie|trident)/i.test(platform.navigator.userAgent)
|
|
2374
|
-
) : () => true;
|
|
2375
|
-
const cookies = platform.hasStandardBrowserEnv ? (
|
|
2376
|
-
// Standard browser envs support document.cookie
|
|
2377
|
-
{
|
|
2378
|
-
write(name, value, expires, path, domain, secure) {
|
|
2379
|
-
const cookie = [name + "=" + encodeURIComponent(value)];
|
|
2380
|
-
utils$1.isNumber(expires) && cookie.push("expires=" + new Date(expires).toGMTString());
|
|
2381
|
-
utils$1.isString(path) && cookie.push("path=" + path);
|
|
2382
|
-
utils$1.isString(domain) && cookie.push("domain=" + domain);
|
|
2383
|
-
secure === true && cookie.push("secure");
|
|
2384
|
-
document.cookie = cookie.join("; ");
|
|
2385
|
-
},
|
|
2386
|
-
read(name) {
|
|
2387
|
-
const match = document.cookie.match(new RegExp("(^|;\\s*)(" + name + ")=([^;]*)"));
|
|
2388
|
-
return match ? decodeURIComponent(match[3]) : null;
|
|
2389
|
-
},
|
|
2390
|
-
remove(name) {
|
|
2391
|
-
this.write(name, "", Date.now() - 864e5);
|
|
2392
|
-
}
|
|
2393
|
-
}
|
|
2394
|
-
) : (
|
|
2395
|
-
// Non-standard browser env (web workers, react-native) lack needed support.
|
|
2396
|
-
{
|
|
2397
|
-
write() {
|
|
2398
|
-
},
|
|
2399
|
-
read() {
|
|
2400
|
-
return null;
|
|
2401
|
-
},
|
|
2402
|
-
remove() {
|
|
2403
|
-
}
|
|
2404
|
-
}
|
|
2405
|
-
);
|
|
2406
|
-
function isAbsoluteURL(url) {
|
|
2407
|
-
return /^([a-z][a-z\d+\-.]*:)?\/\//i.test(url);
|
|
2408
|
-
}
|
|
2409
|
-
function combineURLs(baseURL, relativeURL) {
|
|
2410
|
-
return relativeURL ? baseURL.replace(/\/?\/$/, "") + "/" + relativeURL.replace(/^\/+/, "") : baseURL;
|
|
2411
|
-
}
|
|
2412
|
-
function buildFullPath(baseURL, requestedURL) {
|
|
2413
|
-
if (baseURL && !isAbsoluteURL(requestedURL)) {
|
|
2414
|
-
return combineURLs(baseURL, requestedURL);
|
|
2415
|
-
}
|
|
2416
|
-
return requestedURL;
|
|
2417
|
-
}
|
|
2418
|
-
const headersToObject = (thing) => thing instanceof AxiosHeaders ? { ...thing } : thing;
|
|
2419
|
-
function mergeConfig(config1, config2) {
|
|
2420
|
-
config2 = config2 || {};
|
|
2421
|
-
const config = {};
|
|
2422
|
-
function getMergedValue(target, source, prop, caseless) {
|
|
2423
|
-
if (utils$1.isPlainObject(target) && utils$1.isPlainObject(source)) {
|
|
2424
|
-
return utils$1.merge.call({ caseless }, target, source);
|
|
2425
|
-
} else if (utils$1.isPlainObject(source)) {
|
|
2426
|
-
return utils$1.merge({}, source);
|
|
2427
|
-
} else if (utils$1.isArray(source)) {
|
|
2428
|
-
return source.slice();
|
|
2429
|
-
}
|
|
2430
|
-
return source;
|
|
2431
|
-
}
|
|
2432
|
-
function mergeDeepProperties(a, b, prop, caseless) {
|
|
2433
|
-
if (!utils$1.isUndefined(b)) {
|
|
2434
|
-
return getMergedValue(a, b, prop, caseless);
|
|
2435
|
-
} else if (!utils$1.isUndefined(a)) {
|
|
2436
|
-
return getMergedValue(void 0, a, prop, caseless);
|
|
2437
|
-
}
|
|
2438
|
-
}
|
|
2439
|
-
function valueFromConfig2(a, b) {
|
|
2440
|
-
if (!utils$1.isUndefined(b)) {
|
|
2441
|
-
return getMergedValue(void 0, b);
|
|
2442
|
-
}
|
|
2443
|
-
}
|
|
2444
|
-
function defaultToConfig2(a, b) {
|
|
2445
|
-
if (!utils$1.isUndefined(b)) {
|
|
2446
|
-
return getMergedValue(void 0, b);
|
|
2447
|
-
} else if (!utils$1.isUndefined(a)) {
|
|
2448
|
-
return getMergedValue(void 0, a);
|
|
2449
|
-
}
|
|
2450
|
-
}
|
|
2451
|
-
function mergeDirectKeys(a, b, prop) {
|
|
2452
|
-
if (prop in config2) {
|
|
2453
|
-
return getMergedValue(a, b);
|
|
2454
|
-
} else if (prop in config1) {
|
|
2455
|
-
return getMergedValue(void 0, a);
|
|
2456
|
-
}
|
|
2457
|
-
}
|
|
2458
|
-
const mergeMap = {
|
|
2459
|
-
url: valueFromConfig2,
|
|
2460
|
-
method: valueFromConfig2,
|
|
2461
|
-
data: valueFromConfig2,
|
|
2462
|
-
baseURL: defaultToConfig2,
|
|
2463
|
-
transformRequest: defaultToConfig2,
|
|
2464
|
-
transformResponse: defaultToConfig2,
|
|
2465
|
-
paramsSerializer: defaultToConfig2,
|
|
2466
|
-
timeout: defaultToConfig2,
|
|
2467
|
-
timeoutMessage: defaultToConfig2,
|
|
2468
|
-
withCredentials: defaultToConfig2,
|
|
2469
|
-
withXSRFToken: defaultToConfig2,
|
|
2470
|
-
adapter: defaultToConfig2,
|
|
2471
|
-
responseType: defaultToConfig2,
|
|
2472
|
-
xsrfCookieName: defaultToConfig2,
|
|
2473
|
-
xsrfHeaderName: defaultToConfig2,
|
|
2474
|
-
onUploadProgress: defaultToConfig2,
|
|
2475
|
-
onDownloadProgress: defaultToConfig2,
|
|
2476
|
-
decompress: defaultToConfig2,
|
|
2477
|
-
maxContentLength: defaultToConfig2,
|
|
2478
|
-
maxBodyLength: defaultToConfig2,
|
|
2479
|
-
beforeRedirect: defaultToConfig2,
|
|
2480
|
-
transport: defaultToConfig2,
|
|
2481
|
-
httpAgent: defaultToConfig2,
|
|
2482
|
-
httpsAgent: defaultToConfig2,
|
|
2483
|
-
cancelToken: defaultToConfig2,
|
|
2484
|
-
socketPath: defaultToConfig2,
|
|
2485
|
-
responseEncoding: defaultToConfig2,
|
|
2486
|
-
validateStatus: mergeDirectKeys,
|
|
2487
|
-
headers: (a, b, prop) => mergeDeepProperties(headersToObject(a), headersToObject(b), prop, true)
|
|
2488
|
-
};
|
|
2489
|
-
utils$1.forEach(Object.keys(Object.assign({}, config1, config2)), function computeConfigValue(prop) {
|
|
2490
|
-
const merge2 = mergeMap[prop] || mergeDeepProperties;
|
|
2491
|
-
const configValue = merge2(config1[prop], config2[prop], prop);
|
|
2492
|
-
utils$1.isUndefined(configValue) && merge2 !== mergeDirectKeys || (config[prop] = configValue);
|
|
2493
|
-
});
|
|
2494
|
-
return config;
|
|
2495
|
-
}
|
|
2496
|
-
const resolveConfig = (config) => {
|
|
2497
|
-
const newConfig = mergeConfig({}, config);
|
|
2498
|
-
let { data, withXSRFToken, xsrfHeaderName, xsrfCookieName, headers, auth } = newConfig;
|
|
2499
|
-
newConfig.headers = headers = AxiosHeaders.from(headers);
|
|
2500
|
-
newConfig.url = buildURL(buildFullPath(newConfig.baseURL, newConfig.url), config.params, config.paramsSerializer);
|
|
2501
|
-
if (auth) {
|
|
2502
|
-
headers.set(
|
|
2503
|
-
"Authorization",
|
|
2504
|
-
"Basic " + btoa((auth.username || "") + ":" + (auth.password ? unescape(encodeURIComponent(auth.password)) : ""))
|
|
2505
|
-
);
|
|
2506
|
-
}
|
|
2507
|
-
let contentType;
|
|
2508
|
-
if (utils$1.isFormData(data)) {
|
|
2509
|
-
if (platform.hasStandardBrowserEnv || platform.hasStandardBrowserWebWorkerEnv) {
|
|
2510
|
-
headers.setContentType(void 0);
|
|
2511
|
-
} else if ((contentType = headers.getContentType()) !== false) {
|
|
2512
|
-
const [type, ...tokens] = contentType ? contentType.split(";").map((token) => token.trim()).filter(Boolean) : [];
|
|
2513
|
-
headers.setContentType([type || "multipart/form-data", ...tokens].join("; "));
|
|
2514
|
-
}
|
|
2515
|
-
}
|
|
2516
|
-
if (platform.hasStandardBrowserEnv) {
|
|
2517
|
-
withXSRFToken && utils$1.isFunction(withXSRFToken) && (withXSRFToken = withXSRFToken(newConfig));
|
|
2518
|
-
if (withXSRFToken || withXSRFToken !== false && isURLSameOrigin(newConfig.url)) {
|
|
2519
|
-
const xsrfValue = xsrfHeaderName && xsrfCookieName && cookies.read(xsrfCookieName);
|
|
2520
|
-
if (xsrfValue) {
|
|
2521
|
-
headers.set(xsrfHeaderName, xsrfValue);
|
|
2522
|
-
}
|
|
2523
|
-
}
|
|
2524
|
-
}
|
|
2525
|
-
return newConfig;
|
|
2526
|
-
};
|
|
2527
|
-
const isXHRAdapterSupported = typeof XMLHttpRequest !== "undefined";
|
|
2528
|
-
const xhrAdapter = isXHRAdapterSupported && function(config) {
|
|
2529
|
-
return new Promise(function dispatchXhrRequest(resolve, reject) {
|
|
2530
|
-
const _config = resolveConfig(config);
|
|
2531
|
-
let requestData = _config.data;
|
|
2532
|
-
const requestHeaders = AxiosHeaders.from(_config.headers).normalize();
|
|
2533
|
-
let { responseType, onUploadProgress, onDownloadProgress } = _config;
|
|
2534
|
-
let onCanceled;
|
|
2535
|
-
let uploadThrottled, downloadThrottled;
|
|
2536
|
-
let flushUpload, flushDownload;
|
|
2537
|
-
function done() {
|
|
2538
|
-
flushUpload && flushUpload();
|
|
2539
|
-
flushDownload && flushDownload();
|
|
2540
|
-
_config.cancelToken && _config.cancelToken.unsubscribe(onCanceled);
|
|
2541
|
-
_config.signal && _config.signal.removeEventListener("abort", onCanceled);
|
|
2542
|
-
}
|
|
2543
|
-
let request = new XMLHttpRequest();
|
|
2544
|
-
request.open(_config.method.toUpperCase(), _config.url, true);
|
|
2545
|
-
request.timeout = _config.timeout;
|
|
2546
|
-
function onloadend() {
|
|
2547
|
-
if (!request) {
|
|
2548
|
-
return;
|
|
2549
|
-
}
|
|
2550
|
-
const responseHeaders = AxiosHeaders.from(
|
|
2551
|
-
"getAllResponseHeaders" in request && request.getAllResponseHeaders()
|
|
2552
|
-
);
|
|
2553
|
-
const responseData = !responseType || responseType === "text" || responseType === "json" ? request.responseText : request.response;
|
|
2554
|
-
const response = {
|
|
2555
|
-
data: responseData,
|
|
2556
|
-
status: request.status,
|
|
2557
|
-
statusText: request.statusText,
|
|
2558
|
-
headers: responseHeaders,
|
|
2559
|
-
config,
|
|
2560
|
-
request
|
|
2561
|
-
};
|
|
2562
|
-
settle(function _resolve(value) {
|
|
2563
|
-
resolve(value);
|
|
2564
|
-
done();
|
|
2565
|
-
}, function _reject(err) {
|
|
2566
|
-
reject(err);
|
|
2567
|
-
done();
|
|
2568
|
-
}, response);
|
|
2569
|
-
request = null;
|
|
2570
|
-
}
|
|
2571
|
-
if ("onloadend" in request) {
|
|
2572
|
-
request.onloadend = onloadend;
|
|
2573
|
-
} else {
|
|
2574
|
-
request.onreadystatechange = function handleLoad() {
|
|
2575
|
-
if (!request || request.readyState !== 4) {
|
|
2576
|
-
return;
|
|
2577
|
-
}
|
|
2578
|
-
if (request.status === 0 && !(request.responseURL && request.responseURL.indexOf("file:") === 0)) {
|
|
2579
|
-
return;
|
|
2580
|
-
}
|
|
2581
|
-
setTimeout(onloadend);
|
|
2582
|
-
};
|
|
2583
|
-
}
|
|
2584
|
-
request.onabort = function handleAbort() {
|
|
2585
|
-
if (!request) {
|
|
2586
|
-
return;
|
|
2587
|
-
}
|
|
2588
|
-
reject(new AxiosError("Request aborted", AxiosError.ECONNABORTED, config, request));
|
|
2589
|
-
request = null;
|
|
2590
|
-
};
|
|
2591
|
-
request.onerror = function handleError() {
|
|
2592
|
-
reject(new AxiosError("Network Error", AxiosError.ERR_NETWORK, config, request));
|
|
2593
|
-
request = null;
|
|
2594
|
-
};
|
|
2595
|
-
request.ontimeout = function handleTimeout() {
|
|
2596
|
-
let timeoutErrorMessage = _config.timeout ? "timeout of " + _config.timeout + "ms exceeded" : "timeout exceeded";
|
|
2597
|
-
const transitional2 = _config.transitional || transitionalDefaults;
|
|
2598
|
-
if (_config.timeoutErrorMessage) {
|
|
2599
|
-
timeoutErrorMessage = _config.timeoutErrorMessage;
|
|
2600
|
-
}
|
|
2601
|
-
reject(new AxiosError(
|
|
2602
|
-
timeoutErrorMessage,
|
|
2603
|
-
transitional2.clarifyTimeoutError ? AxiosError.ETIMEDOUT : AxiosError.ECONNABORTED,
|
|
2604
|
-
config,
|
|
2605
|
-
request
|
|
2606
|
-
));
|
|
2607
|
-
request = null;
|
|
2608
|
-
};
|
|
2609
|
-
requestData === void 0 && requestHeaders.setContentType(null);
|
|
2610
|
-
if ("setRequestHeader" in request) {
|
|
2611
|
-
utils$1.forEach(requestHeaders.toJSON(), function setRequestHeader(val, key) {
|
|
2612
|
-
request.setRequestHeader(key, val);
|
|
2613
|
-
});
|
|
2614
|
-
}
|
|
2615
|
-
if (!utils$1.isUndefined(_config.withCredentials)) {
|
|
2616
|
-
request.withCredentials = !!_config.withCredentials;
|
|
2617
|
-
}
|
|
2618
|
-
if (responseType && responseType !== "json") {
|
|
2619
|
-
request.responseType = _config.responseType;
|
|
2620
|
-
}
|
|
2621
|
-
if (onDownloadProgress) {
|
|
2622
|
-
[downloadThrottled, flushDownload] = progressEventReducer(onDownloadProgress, true);
|
|
2623
|
-
request.addEventListener("progress", downloadThrottled);
|
|
2624
|
-
}
|
|
2625
|
-
if (onUploadProgress && request.upload) {
|
|
2626
|
-
[uploadThrottled, flushUpload] = progressEventReducer(onUploadProgress);
|
|
2627
|
-
request.upload.addEventListener("progress", uploadThrottled);
|
|
2628
|
-
request.upload.addEventListener("loadend", flushUpload);
|
|
2629
|
-
}
|
|
2630
|
-
if (_config.cancelToken || _config.signal) {
|
|
2631
|
-
onCanceled = (cancel) => {
|
|
2632
|
-
if (!request) {
|
|
2633
|
-
return;
|
|
2634
|
-
}
|
|
2635
|
-
reject(!cancel || cancel.type ? new CanceledError(null, config, request) : cancel);
|
|
2636
|
-
request.abort();
|
|
2637
|
-
request = null;
|
|
2638
|
-
};
|
|
2639
|
-
_config.cancelToken && _config.cancelToken.subscribe(onCanceled);
|
|
2640
|
-
if (_config.signal) {
|
|
2641
|
-
_config.signal.aborted ? onCanceled() : _config.signal.addEventListener("abort", onCanceled);
|
|
2642
|
-
}
|
|
2643
|
-
}
|
|
2644
|
-
const protocol = parseProtocol(_config.url);
|
|
2645
|
-
if (protocol && platform.protocols.indexOf(protocol) === -1) {
|
|
2646
|
-
reject(new AxiosError("Unsupported protocol " + protocol + ":", AxiosError.ERR_BAD_REQUEST, config));
|
|
2647
|
-
return;
|
|
2648
|
-
}
|
|
2649
|
-
request.send(requestData || null);
|
|
2650
|
-
});
|
|
2651
|
-
};
|
|
2652
|
-
const composeSignals = (signals, timeout) => {
|
|
2653
|
-
const { length } = signals = signals ? signals.filter(Boolean) : [];
|
|
2654
|
-
if (timeout || length) {
|
|
2655
|
-
let controller = new AbortController();
|
|
2656
|
-
let aborted;
|
|
2657
|
-
const onabort = function(reason) {
|
|
2658
|
-
if (!aborted) {
|
|
2659
|
-
aborted = true;
|
|
2660
|
-
unsubscribe();
|
|
2661
|
-
const err = reason instanceof Error ? reason : this.reason;
|
|
2662
|
-
controller.abort(err instanceof AxiosError ? err : new CanceledError(err instanceof Error ? err.message : err));
|
|
2663
|
-
}
|
|
2664
|
-
};
|
|
2665
|
-
let timer = timeout && setTimeout(() => {
|
|
2666
|
-
timer = null;
|
|
2667
|
-
onabort(new AxiosError(`timeout ${timeout} of ms exceeded`, AxiosError.ETIMEDOUT));
|
|
2668
|
-
}, timeout);
|
|
2669
|
-
const unsubscribe = () => {
|
|
2670
|
-
if (signals) {
|
|
2671
|
-
timer && clearTimeout(timer);
|
|
2672
|
-
timer = null;
|
|
2673
|
-
signals.forEach((signal2) => {
|
|
2674
|
-
signal2.unsubscribe ? signal2.unsubscribe(onabort) : signal2.removeEventListener("abort", onabort);
|
|
2675
|
-
});
|
|
2676
|
-
signals = null;
|
|
2677
|
-
}
|
|
2678
|
-
};
|
|
2679
|
-
signals.forEach((signal2) => signal2.addEventListener("abort", onabort));
|
|
2680
|
-
const { signal } = controller;
|
|
2681
|
-
signal.unsubscribe = () => utils$1.asap(unsubscribe);
|
|
2682
|
-
return signal;
|
|
2683
|
-
}
|
|
2684
|
-
};
|
|
2685
|
-
const streamChunk = function* (chunk, chunkSize) {
|
|
2686
|
-
let len = chunk.byteLength;
|
|
2687
|
-
if (len < chunkSize) {
|
|
2688
|
-
yield chunk;
|
|
2689
|
-
return;
|
|
2690
|
-
}
|
|
2691
|
-
let pos = 0;
|
|
2692
|
-
let end;
|
|
2693
|
-
while (pos < len) {
|
|
2694
|
-
end = pos + chunkSize;
|
|
2695
|
-
yield chunk.slice(pos, end);
|
|
2696
|
-
pos = end;
|
|
2697
|
-
}
|
|
2698
|
-
};
|
|
2699
|
-
const readBytes = async function* (iterable, chunkSize) {
|
|
2700
|
-
for await (const chunk of readStream(iterable)) {
|
|
2701
|
-
yield* streamChunk(chunk, chunkSize);
|
|
2702
|
-
}
|
|
2703
|
-
};
|
|
2704
|
-
const readStream = async function* (stream) {
|
|
2705
|
-
if (stream[Symbol.asyncIterator]) {
|
|
2706
|
-
yield* stream;
|
|
2707
|
-
return;
|
|
2708
|
-
}
|
|
2709
|
-
const reader = stream.getReader();
|
|
2710
|
-
try {
|
|
2711
|
-
for (; ; ) {
|
|
2712
|
-
const { done, value } = await reader.read();
|
|
2713
|
-
if (done) {
|
|
2714
|
-
break;
|
|
2715
|
-
}
|
|
2716
|
-
yield value;
|
|
2717
|
-
}
|
|
2718
|
-
} finally {
|
|
2719
|
-
await reader.cancel();
|
|
2720
|
-
}
|
|
2721
|
-
};
|
|
2722
|
-
const trackStream = (stream, chunkSize, onProgress, onFinish) => {
|
|
2723
|
-
const iterator = readBytes(stream, chunkSize);
|
|
2724
|
-
let bytes = 0;
|
|
2725
|
-
let done;
|
|
2726
|
-
let _onFinish = (e) => {
|
|
2727
|
-
if (!done) {
|
|
2728
|
-
done = true;
|
|
2729
|
-
onFinish && onFinish(e);
|
|
2730
|
-
}
|
|
2731
|
-
};
|
|
2732
|
-
return new ReadableStream({
|
|
2733
|
-
async pull(controller) {
|
|
2734
|
-
try {
|
|
2735
|
-
const { done: done2, value } = await iterator.next();
|
|
2736
|
-
if (done2) {
|
|
2737
|
-
_onFinish();
|
|
2738
|
-
controller.close();
|
|
2739
|
-
return;
|
|
2740
|
-
}
|
|
2741
|
-
let len = value.byteLength;
|
|
2742
|
-
if (onProgress) {
|
|
2743
|
-
let loadedBytes = bytes += len;
|
|
2744
|
-
onProgress(loadedBytes);
|
|
2745
|
-
}
|
|
2746
|
-
controller.enqueue(new Uint8Array(value));
|
|
2747
|
-
} catch (err) {
|
|
2748
|
-
_onFinish(err);
|
|
2749
|
-
throw err;
|
|
2750
|
-
}
|
|
2751
|
-
},
|
|
2752
|
-
cancel(reason) {
|
|
2753
|
-
_onFinish(reason);
|
|
2754
|
-
return iterator.return();
|
|
2755
|
-
}
|
|
2756
|
-
}, {
|
|
2757
|
-
highWaterMark: 2
|
|
2758
|
-
});
|
|
2759
|
-
};
|
|
2760
|
-
const isFetchSupported = typeof fetch === "function" && typeof Request === "function" && typeof Response === "function";
|
|
2761
|
-
const isReadableStreamSupported = isFetchSupported && typeof ReadableStream === "function";
|
|
2762
|
-
const encodeText = isFetchSupported && (typeof TextEncoder === "function" ? /* @__PURE__ */ ((encoder) => (str) => encoder.encode(str))(new TextEncoder()) : async (str) => new Uint8Array(await new Response(str).arrayBuffer()));
|
|
2763
|
-
const test = (fn, ...args) => {
|
|
2764
|
-
try {
|
|
2765
|
-
return !!fn(...args);
|
|
2766
|
-
} catch (e) {
|
|
2767
|
-
return false;
|
|
2768
|
-
}
|
|
2769
|
-
};
|
|
2770
|
-
const supportsRequestStream = isReadableStreamSupported && test(() => {
|
|
2771
|
-
let duplexAccessed = false;
|
|
2772
|
-
const hasContentType = new Request(platform.origin, {
|
|
2773
|
-
body: new ReadableStream(),
|
|
2774
|
-
method: "POST",
|
|
2775
|
-
get duplex() {
|
|
2776
|
-
duplexAccessed = true;
|
|
2777
|
-
return "half";
|
|
2778
|
-
}
|
|
2779
|
-
}).headers.has("Content-Type");
|
|
2780
|
-
return duplexAccessed && !hasContentType;
|
|
2781
|
-
});
|
|
2782
|
-
const DEFAULT_CHUNK_SIZE = 64 * 1024;
|
|
2783
|
-
const supportsResponseStream = isReadableStreamSupported && test(() => utils$1.isReadableStream(new Response("").body));
|
|
2784
|
-
const resolvers = {
|
|
2785
|
-
stream: supportsResponseStream && ((res) => res.body)
|
|
2786
|
-
};
|
|
2787
|
-
isFetchSupported && ((res) => {
|
|
2788
|
-
["text", "arrayBuffer", "blob", "formData", "stream"].forEach((type) => {
|
|
2789
|
-
!resolvers[type] && (resolvers[type] = utils$1.isFunction(res[type]) ? (res2) => res2[type]() : (_, config) => {
|
|
2790
|
-
throw new AxiosError(`Response type '${type}' is not supported`, AxiosError.ERR_NOT_SUPPORT, config);
|
|
2791
|
-
});
|
|
2792
|
-
});
|
|
2793
|
-
})(new Response());
|
|
2794
|
-
const getBodyLength = async (body) => {
|
|
2795
|
-
if (body == null) {
|
|
2796
|
-
return 0;
|
|
2797
|
-
}
|
|
2798
|
-
if (utils$1.isBlob(body)) {
|
|
2799
|
-
return body.size;
|
|
2800
|
-
}
|
|
2801
|
-
if (utils$1.isSpecCompliantForm(body)) {
|
|
2802
|
-
const _request = new Request(platform.origin, {
|
|
2803
|
-
method: "POST",
|
|
2804
|
-
body
|
|
2805
|
-
});
|
|
2806
|
-
return (await _request.arrayBuffer()).byteLength;
|
|
2807
|
-
}
|
|
2808
|
-
if (utils$1.isArrayBufferView(body) || utils$1.isArrayBuffer(body)) {
|
|
2809
|
-
return body.byteLength;
|
|
2810
|
-
}
|
|
2811
|
-
if (utils$1.isURLSearchParams(body)) {
|
|
2812
|
-
body = body + "";
|
|
2813
|
-
}
|
|
2814
|
-
if (utils$1.isString(body)) {
|
|
2815
|
-
return (await encodeText(body)).byteLength;
|
|
2816
|
-
}
|
|
2817
|
-
};
|
|
2818
|
-
const resolveBodyLength = async (headers, body) => {
|
|
2819
|
-
const length = utils$1.toFiniteNumber(headers.getContentLength());
|
|
2820
|
-
return length == null ? getBodyLength(body) : length;
|
|
2821
|
-
};
|
|
2822
|
-
const fetchAdapter = isFetchSupported && (async (config) => {
|
|
2823
|
-
let {
|
|
2824
|
-
url,
|
|
2825
|
-
method,
|
|
2826
|
-
data,
|
|
2827
|
-
signal,
|
|
2828
|
-
cancelToken,
|
|
2829
|
-
timeout,
|
|
2830
|
-
onDownloadProgress,
|
|
2831
|
-
onUploadProgress,
|
|
2832
|
-
responseType,
|
|
2833
|
-
headers,
|
|
2834
|
-
withCredentials = "same-origin",
|
|
2835
|
-
fetchOptions
|
|
2836
|
-
} = resolveConfig(config);
|
|
2837
|
-
responseType = responseType ? (responseType + "").toLowerCase() : "text";
|
|
2838
|
-
let composedSignal = composeSignals([signal, cancelToken && cancelToken.toAbortSignal()], timeout);
|
|
2839
|
-
let request;
|
|
2840
|
-
const unsubscribe = composedSignal && composedSignal.unsubscribe && (() => {
|
|
2841
|
-
composedSignal.unsubscribe();
|
|
2842
|
-
});
|
|
2843
|
-
let requestContentLength;
|
|
2844
|
-
try {
|
|
2845
|
-
if (onUploadProgress && supportsRequestStream && method !== "get" && method !== "head" && (requestContentLength = await resolveBodyLength(headers, data)) !== 0) {
|
|
2846
|
-
let _request = new Request(url, {
|
|
2847
|
-
method: "POST",
|
|
2848
|
-
body: data,
|
|
2849
|
-
duplex: "half"
|
|
2850
|
-
});
|
|
2851
|
-
let contentTypeHeader;
|
|
2852
|
-
if (utils$1.isFormData(data) && (contentTypeHeader = _request.headers.get("content-type"))) {
|
|
2853
|
-
headers.setContentType(contentTypeHeader);
|
|
2854
|
-
}
|
|
2855
|
-
if (_request.body) {
|
|
2856
|
-
const [onProgress, flush] = progressEventDecorator(
|
|
2857
|
-
requestContentLength,
|
|
2858
|
-
progressEventReducer(asyncDecorator(onUploadProgress))
|
|
2859
|
-
);
|
|
2860
|
-
data = trackStream(_request.body, DEFAULT_CHUNK_SIZE, onProgress, flush);
|
|
2861
|
-
}
|
|
2862
|
-
}
|
|
2863
|
-
if (!utils$1.isString(withCredentials)) {
|
|
2864
|
-
withCredentials = withCredentials ? "include" : "omit";
|
|
2865
|
-
}
|
|
2866
|
-
const isCredentialsSupported = "credentials" in Request.prototype;
|
|
2867
|
-
request = new Request(url, {
|
|
2868
|
-
...fetchOptions,
|
|
2869
|
-
signal: composedSignal,
|
|
2870
|
-
method: method.toUpperCase(),
|
|
2871
|
-
headers: headers.normalize().toJSON(),
|
|
2872
|
-
body: data,
|
|
2873
|
-
duplex: "half",
|
|
2874
|
-
credentials: isCredentialsSupported ? withCredentials : void 0
|
|
2875
|
-
});
|
|
2876
|
-
let response = await fetch(request);
|
|
2877
|
-
const isStreamResponse = supportsResponseStream && (responseType === "stream" || responseType === "response");
|
|
2878
|
-
if (supportsResponseStream && (onDownloadProgress || isStreamResponse && unsubscribe)) {
|
|
2879
|
-
const options = {};
|
|
2880
|
-
["status", "statusText", "headers"].forEach((prop) => {
|
|
2881
|
-
options[prop] = response[prop];
|
|
2882
|
-
});
|
|
2883
|
-
const responseContentLength = utils$1.toFiniteNumber(response.headers.get("content-length"));
|
|
2884
|
-
const [onProgress, flush] = onDownloadProgress && progressEventDecorator(
|
|
2885
|
-
responseContentLength,
|
|
2886
|
-
progressEventReducer(asyncDecorator(onDownloadProgress), true)
|
|
2887
|
-
) || [];
|
|
2888
|
-
response = new Response(
|
|
2889
|
-
trackStream(response.body, DEFAULT_CHUNK_SIZE, onProgress, () => {
|
|
2890
|
-
flush && flush();
|
|
2891
|
-
unsubscribe && unsubscribe();
|
|
2892
|
-
}),
|
|
2893
|
-
options
|
|
2894
|
-
);
|
|
2895
|
-
}
|
|
2896
|
-
responseType = responseType || "text";
|
|
2897
|
-
let responseData = await resolvers[utils$1.findKey(resolvers, responseType) || "text"](response, config);
|
|
2898
|
-
!isStreamResponse && unsubscribe && unsubscribe();
|
|
2899
|
-
return await new Promise((resolve, reject) => {
|
|
2900
|
-
settle(resolve, reject, {
|
|
2901
|
-
data: responseData,
|
|
2902
|
-
headers: AxiosHeaders.from(response.headers),
|
|
2903
|
-
status: response.status,
|
|
2904
|
-
statusText: response.statusText,
|
|
2905
|
-
config,
|
|
2906
|
-
request
|
|
2907
|
-
});
|
|
2908
|
-
});
|
|
2909
|
-
} catch (err) {
|
|
2910
|
-
unsubscribe && unsubscribe();
|
|
2911
|
-
if (err && err.name === "TypeError" && /fetch/i.test(err.message)) {
|
|
2912
|
-
throw Object.assign(
|
|
2913
|
-
new AxiosError("Network Error", AxiosError.ERR_NETWORK, config, request),
|
|
2914
|
-
{
|
|
2915
|
-
cause: err.cause || err
|
|
2916
|
-
}
|
|
2917
|
-
);
|
|
2918
|
-
}
|
|
2919
|
-
throw AxiosError.from(err, err && err.code, config, request);
|
|
2920
|
-
}
|
|
2921
|
-
});
|
|
2922
|
-
const knownAdapters = {
|
|
2923
|
-
http: httpAdapter,
|
|
2924
|
-
xhr: xhrAdapter,
|
|
2925
|
-
fetch: fetchAdapter
|
|
2926
|
-
};
|
|
2927
|
-
utils$1.forEach(knownAdapters, (fn, value) => {
|
|
2928
|
-
if (fn) {
|
|
2929
|
-
try {
|
|
2930
|
-
Object.defineProperty(fn, "name", { value });
|
|
2931
|
-
} catch (e) {
|
|
2932
|
-
}
|
|
2933
|
-
Object.defineProperty(fn, "adapterName", { value });
|
|
2934
|
-
}
|
|
2935
|
-
});
|
|
2936
|
-
const renderReason = (reason) => `- ${reason}`;
|
|
2937
|
-
const isResolvedHandle = (adapter) => utils$1.isFunction(adapter) || adapter === null || adapter === false;
|
|
2938
|
-
const adapters = {
|
|
2939
|
-
getAdapter: (adapters2) => {
|
|
2940
|
-
adapters2 = utils$1.isArray(adapters2) ? adapters2 : [adapters2];
|
|
2941
|
-
const { length } = adapters2;
|
|
2942
|
-
let nameOrAdapter;
|
|
2943
|
-
let adapter;
|
|
2944
|
-
const rejectedReasons = {};
|
|
2945
|
-
for (let i = 0; i < length; i++) {
|
|
2946
|
-
nameOrAdapter = adapters2[i];
|
|
2947
|
-
let id;
|
|
2948
|
-
adapter = nameOrAdapter;
|
|
2949
|
-
if (!isResolvedHandle(nameOrAdapter)) {
|
|
2950
|
-
adapter = knownAdapters[(id = String(nameOrAdapter)).toLowerCase()];
|
|
2951
|
-
if (adapter === void 0) {
|
|
2952
|
-
throw new AxiosError(`Unknown adapter '${id}'`);
|
|
2953
|
-
}
|
|
2954
|
-
}
|
|
2955
|
-
if (adapter) {
|
|
2956
|
-
break;
|
|
2957
|
-
}
|
|
2958
|
-
rejectedReasons[id || "#" + i] = adapter;
|
|
2959
|
-
}
|
|
2960
|
-
if (!adapter) {
|
|
2961
|
-
const reasons = Object.entries(rejectedReasons).map(
|
|
2962
|
-
([id, state]) => `adapter ${id} ` + (state === false ? "is not supported by the environment" : "is not available in the build")
|
|
2963
|
-
);
|
|
2964
|
-
let s = length ? reasons.length > 1 ? "since :\n" + reasons.map(renderReason).join("\n") : " " + renderReason(reasons[0]) : "as no adapter specified";
|
|
2965
|
-
throw new AxiosError(
|
|
2966
|
-
`There is no suitable adapter to dispatch the request ` + s,
|
|
2967
|
-
"ERR_NOT_SUPPORT"
|
|
2968
|
-
);
|
|
2969
|
-
}
|
|
2970
|
-
return adapter;
|
|
2971
|
-
},
|
|
2972
|
-
adapters: knownAdapters
|
|
2973
|
-
};
|
|
2974
|
-
function throwIfCancellationRequested(config) {
|
|
2975
|
-
if (config.cancelToken) {
|
|
2976
|
-
config.cancelToken.throwIfRequested();
|
|
2977
|
-
}
|
|
2978
|
-
if (config.signal && config.signal.aborted) {
|
|
2979
|
-
throw new CanceledError(null, config);
|
|
2980
|
-
}
|
|
2981
|
-
}
|
|
2982
|
-
function dispatchRequest(config) {
|
|
2983
|
-
throwIfCancellationRequested(config);
|
|
2984
|
-
config.headers = AxiosHeaders.from(config.headers);
|
|
2985
|
-
config.data = transformData.call(
|
|
2986
|
-
config,
|
|
2987
|
-
config.transformRequest
|
|
2988
|
-
);
|
|
2989
|
-
if (["post", "put", "patch"].indexOf(config.method) !== -1) {
|
|
2990
|
-
config.headers.setContentType("application/x-www-form-urlencoded", false);
|
|
2991
|
-
}
|
|
2992
|
-
const adapter = adapters.getAdapter(config.adapter || defaults.adapter);
|
|
2993
|
-
return adapter(config).then(function onAdapterResolution(response) {
|
|
2994
|
-
throwIfCancellationRequested(config);
|
|
2995
|
-
response.data = transformData.call(
|
|
2996
|
-
config,
|
|
2997
|
-
config.transformResponse,
|
|
2998
|
-
response
|
|
2999
|
-
);
|
|
3000
|
-
response.headers = AxiosHeaders.from(response.headers);
|
|
3001
|
-
return response;
|
|
3002
|
-
}, function onAdapterRejection(reason) {
|
|
3003
|
-
if (!isCancel(reason)) {
|
|
3004
|
-
throwIfCancellationRequested(config);
|
|
3005
|
-
if (reason && reason.response) {
|
|
3006
|
-
reason.response.data = transformData.call(
|
|
3007
|
-
config,
|
|
3008
|
-
config.transformResponse,
|
|
3009
|
-
reason.response
|
|
3010
|
-
);
|
|
3011
|
-
reason.response.headers = AxiosHeaders.from(reason.response.headers);
|
|
3012
|
-
}
|
|
3013
|
-
}
|
|
3014
|
-
return Promise.reject(reason);
|
|
3015
|
-
});
|
|
3016
|
-
}
|
|
3017
|
-
const VERSION = "1.7.9";
|
|
3018
|
-
const validators$1 = {};
|
|
3019
|
-
["object", "boolean", "number", "function", "string", "symbol"].forEach((type, i) => {
|
|
3020
|
-
validators$1[type] = function validator2(thing) {
|
|
3021
|
-
return typeof thing === type || "a" + (i < 1 ? "n " : " ") + type;
|
|
3022
|
-
};
|
|
3023
|
-
});
|
|
3024
|
-
const deprecatedWarnings = {};
|
|
3025
|
-
validators$1.transitional = function transitional(validator2, version, message) {
|
|
3026
|
-
function formatMessage(opt, desc) {
|
|
3027
|
-
return "[Axios v" + VERSION + "] Transitional option '" + opt + "'" + desc + (message ? ". " + message : "");
|
|
3028
|
-
}
|
|
3029
|
-
return (value, opt, opts) => {
|
|
3030
|
-
if (validator2 === false) {
|
|
3031
|
-
throw new AxiosError(
|
|
3032
|
-
formatMessage(opt, " has been removed" + (version ? " in " + version : "")),
|
|
3033
|
-
AxiosError.ERR_DEPRECATED
|
|
3034
|
-
);
|
|
3035
|
-
}
|
|
3036
|
-
if (version && !deprecatedWarnings[opt]) {
|
|
3037
|
-
deprecatedWarnings[opt] = true;
|
|
3038
|
-
console.warn(
|
|
3039
|
-
formatMessage(
|
|
3040
|
-
opt,
|
|
3041
|
-
" has been deprecated since v" + version + " and will be removed in the near future"
|
|
3042
|
-
)
|
|
3043
|
-
);
|
|
3044
|
-
}
|
|
3045
|
-
return validator2 ? validator2(value, opt, opts) : true;
|
|
3046
|
-
};
|
|
3047
|
-
};
|
|
3048
|
-
validators$1.spelling = function spelling(correctSpelling) {
|
|
3049
|
-
return (value, opt) => {
|
|
3050
|
-
console.warn(`${opt} is likely a misspelling of ${correctSpelling}`);
|
|
3051
|
-
return true;
|
|
3052
|
-
};
|
|
3053
|
-
};
|
|
3054
|
-
function assertOptions(options, schema, allowUnknown) {
|
|
3055
|
-
if (typeof options !== "object") {
|
|
3056
|
-
throw new AxiosError("options must be an object", AxiosError.ERR_BAD_OPTION_VALUE);
|
|
3057
|
-
}
|
|
3058
|
-
const keys = Object.keys(options);
|
|
3059
|
-
let i = keys.length;
|
|
3060
|
-
while (i-- > 0) {
|
|
3061
|
-
const opt = keys[i];
|
|
3062
|
-
const validator2 = schema[opt];
|
|
3063
|
-
if (validator2) {
|
|
3064
|
-
const value = options[opt];
|
|
3065
|
-
const result = value === void 0 || validator2(value, opt, options);
|
|
3066
|
-
if (result !== true) {
|
|
3067
|
-
throw new AxiosError("option " + opt + " must be " + result, AxiosError.ERR_BAD_OPTION_VALUE);
|
|
3068
|
-
}
|
|
3069
|
-
continue;
|
|
3070
|
-
}
|
|
3071
|
-
if (allowUnknown !== true) {
|
|
3072
|
-
throw new AxiosError("Unknown option " + opt, AxiosError.ERR_BAD_OPTION);
|
|
3073
|
-
}
|
|
3074
|
-
}
|
|
3075
|
-
}
|
|
3076
|
-
const validator = {
|
|
3077
|
-
assertOptions,
|
|
3078
|
-
validators: validators$1
|
|
3079
|
-
};
|
|
3080
|
-
const validators = validator.validators;
|
|
3081
|
-
class Axios {
|
|
3082
|
-
constructor(instanceConfig) {
|
|
3083
|
-
this.defaults = instanceConfig;
|
|
3084
|
-
this.interceptors = {
|
|
3085
|
-
request: new InterceptorManager(),
|
|
3086
|
-
response: new InterceptorManager()
|
|
3087
|
-
};
|
|
3088
|
-
}
|
|
3089
|
-
/**
|
|
3090
|
-
* Dispatch a request
|
|
3091
|
-
*
|
|
3092
|
-
* @param {String|Object} configOrUrl The config specific for this request (merged with this.defaults)
|
|
3093
|
-
* @param {?Object} config
|
|
3094
|
-
*
|
|
3095
|
-
* @returns {Promise} The Promise to be fulfilled
|
|
3096
|
-
*/
|
|
3097
|
-
async request(configOrUrl, config) {
|
|
3098
|
-
try {
|
|
3099
|
-
return await this._request(configOrUrl, config);
|
|
3100
|
-
} catch (err) {
|
|
3101
|
-
if (err instanceof Error) {
|
|
3102
|
-
let dummy = {};
|
|
3103
|
-
Error.captureStackTrace ? Error.captureStackTrace(dummy) : dummy = new Error();
|
|
3104
|
-
const stack = dummy.stack ? dummy.stack.replace(/^.+\n/, "") : "";
|
|
3105
|
-
try {
|
|
3106
|
-
if (!err.stack) {
|
|
3107
|
-
err.stack = stack;
|
|
3108
|
-
} else if (stack && !String(err.stack).endsWith(stack.replace(/^.+\n.+\n/, ""))) {
|
|
3109
|
-
err.stack += "\n" + stack;
|
|
3110
|
-
}
|
|
3111
|
-
} catch (e) {
|
|
3112
|
-
}
|
|
3113
|
-
}
|
|
3114
|
-
throw err;
|
|
3115
|
-
}
|
|
3116
|
-
}
|
|
3117
|
-
_request(configOrUrl, config) {
|
|
3118
|
-
if (typeof configOrUrl === "string") {
|
|
3119
|
-
config = config || {};
|
|
3120
|
-
config.url = configOrUrl;
|
|
3121
|
-
} else {
|
|
3122
|
-
config = configOrUrl || {};
|
|
3123
|
-
}
|
|
3124
|
-
config = mergeConfig(this.defaults, config);
|
|
3125
|
-
const { transitional: transitional2, paramsSerializer, headers } = config;
|
|
3126
|
-
if (transitional2 !== void 0) {
|
|
3127
|
-
validator.assertOptions(transitional2, {
|
|
3128
|
-
silentJSONParsing: validators.transitional(validators.boolean),
|
|
3129
|
-
forcedJSONParsing: validators.transitional(validators.boolean),
|
|
3130
|
-
clarifyTimeoutError: validators.transitional(validators.boolean)
|
|
3131
|
-
}, false);
|
|
3132
|
-
}
|
|
3133
|
-
if (paramsSerializer != null) {
|
|
3134
|
-
if (utils$1.isFunction(paramsSerializer)) {
|
|
3135
|
-
config.paramsSerializer = {
|
|
3136
|
-
serialize: paramsSerializer
|
|
3137
|
-
};
|
|
3138
|
-
} else {
|
|
3139
|
-
validator.assertOptions(paramsSerializer, {
|
|
3140
|
-
encode: validators.function,
|
|
3141
|
-
serialize: validators.function
|
|
3142
|
-
}, true);
|
|
3143
|
-
}
|
|
3144
|
-
}
|
|
3145
|
-
validator.assertOptions(config, {
|
|
3146
|
-
baseUrl: validators.spelling("baseURL"),
|
|
3147
|
-
withXsrfToken: validators.spelling("withXSRFToken")
|
|
3148
|
-
}, true);
|
|
3149
|
-
config.method = (config.method || this.defaults.method || "get").toLowerCase();
|
|
3150
|
-
let contextHeaders = headers && utils$1.merge(
|
|
3151
|
-
headers.common,
|
|
3152
|
-
headers[config.method]
|
|
3153
|
-
);
|
|
3154
|
-
headers && utils$1.forEach(
|
|
3155
|
-
["delete", "get", "head", "post", "put", "patch", "common"],
|
|
3156
|
-
(method) => {
|
|
3157
|
-
delete headers[method];
|
|
3158
|
-
}
|
|
3159
|
-
);
|
|
3160
|
-
config.headers = AxiosHeaders.concat(contextHeaders, headers);
|
|
3161
|
-
const requestInterceptorChain = [];
|
|
3162
|
-
let synchronousRequestInterceptors = true;
|
|
3163
|
-
this.interceptors.request.forEach(function unshiftRequestInterceptors(interceptor) {
|
|
3164
|
-
if (typeof interceptor.runWhen === "function" && interceptor.runWhen(config) === false) {
|
|
3165
|
-
return;
|
|
3166
|
-
}
|
|
3167
|
-
synchronousRequestInterceptors = synchronousRequestInterceptors && interceptor.synchronous;
|
|
3168
|
-
requestInterceptorChain.unshift(interceptor.fulfilled, interceptor.rejected);
|
|
3169
|
-
});
|
|
3170
|
-
const responseInterceptorChain = [];
|
|
3171
|
-
this.interceptors.response.forEach(function pushResponseInterceptors(interceptor) {
|
|
3172
|
-
responseInterceptorChain.push(interceptor.fulfilled, interceptor.rejected);
|
|
3173
|
-
});
|
|
3174
|
-
let promise;
|
|
3175
|
-
let i = 0;
|
|
3176
|
-
let len;
|
|
3177
|
-
if (!synchronousRequestInterceptors) {
|
|
3178
|
-
const chain = [dispatchRequest.bind(this), void 0];
|
|
3179
|
-
chain.unshift.apply(chain, requestInterceptorChain);
|
|
3180
|
-
chain.push.apply(chain, responseInterceptorChain);
|
|
3181
|
-
len = chain.length;
|
|
3182
|
-
promise = Promise.resolve(config);
|
|
3183
|
-
while (i < len) {
|
|
3184
|
-
promise = promise.then(chain[i++], chain[i++]);
|
|
3185
|
-
}
|
|
3186
|
-
return promise;
|
|
3187
|
-
}
|
|
3188
|
-
len = requestInterceptorChain.length;
|
|
3189
|
-
let newConfig = config;
|
|
3190
|
-
i = 0;
|
|
3191
|
-
while (i < len) {
|
|
3192
|
-
const onFulfilled = requestInterceptorChain[i++];
|
|
3193
|
-
const onRejected = requestInterceptorChain[i++];
|
|
3194
|
-
try {
|
|
3195
|
-
newConfig = onFulfilled(newConfig);
|
|
3196
|
-
} catch (error) {
|
|
3197
|
-
onRejected.call(this, error);
|
|
3198
|
-
break;
|
|
3199
|
-
}
|
|
3200
|
-
}
|
|
3201
|
-
try {
|
|
3202
|
-
promise = dispatchRequest.call(this, newConfig);
|
|
3203
|
-
} catch (error) {
|
|
3204
|
-
return Promise.reject(error);
|
|
3205
|
-
}
|
|
3206
|
-
i = 0;
|
|
3207
|
-
len = responseInterceptorChain.length;
|
|
3208
|
-
while (i < len) {
|
|
3209
|
-
promise = promise.then(responseInterceptorChain[i++], responseInterceptorChain[i++]);
|
|
3210
|
-
}
|
|
3211
|
-
return promise;
|
|
3212
|
-
}
|
|
3213
|
-
getUri(config) {
|
|
3214
|
-
config = mergeConfig(this.defaults, config);
|
|
3215
|
-
const fullPath = buildFullPath(config.baseURL, config.url);
|
|
3216
|
-
return buildURL(fullPath, config.params, config.paramsSerializer);
|
|
3217
|
-
}
|
|
3218
|
-
}
|
|
3219
|
-
utils$1.forEach(["delete", "get", "head", "options"], function forEachMethodNoData(method) {
|
|
3220
|
-
Axios.prototype[method] = function(url, config) {
|
|
3221
|
-
return this.request(mergeConfig(config || {}, {
|
|
3222
|
-
method,
|
|
3223
|
-
url,
|
|
3224
|
-
data: (config || {}).data
|
|
3225
|
-
}));
|
|
3226
|
-
};
|
|
3227
|
-
});
|
|
3228
|
-
utils$1.forEach(["post", "put", "patch"], function forEachMethodWithData(method) {
|
|
3229
|
-
function generateHTTPMethod(isForm) {
|
|
3230
|
-
return function httpMethod(url, data, config) {
|
|
3231
|
-
return this.request(mergeConfig(config || {}, {
|
|
3232
|
-
method,
|
|
3233
|
-
headers: isForm ? {
|
|
3234
|
-
"Content-Type": "multipart/form-data"
|
|
3235
|
-
} : {},
|
|
3236
|
-
url,
|
|
3237
|
-
data
|
|
3238
|
-
}));
|
|
3239
|
-
};
|
|
3240
|
-
}
|
|
3241
|
-
Axios.prototype[method] = generateHTTPMethod();
|
|
3242
|
-
Axios.prototype[method + "Form"] = generateHTTPMethod(true);
|
|
3243
|
-
});
|
|
3244
|
-
class CancelToken {
|
|
3245
|
-
constructor(executor) {
|
|
3246
|
-
if (typeof executor !== "function") {
|
|
3247
|
-
throw new TypeError("executor must be a function.");
|
|
3248
|
-
}
|
|
3249
|
-
let resolvePromise;
|
|
3250
|
-
this.promise = new Promise(function promiseExecutor(resolve) {
|
|
3251
|
-
resolvePromise = resolve;
|
|
3252
|
-
});
|
|
3253
|
-
const token = this;
|
|
3254
|
-
this.promise.then((cancel) => {
|
|
3255
|
-
if (!token._listeners) return;
|
|
3256
|
-
let i = token._listeners.length;
|
|
3257
|
-
while (i-- > 0) {
|
|
3258
|
-
token._listeners[i](cancel);
|
|
3259
|
-
}
|
|
3260
|
-
token._listeners = null;
|
|
3261
|
-
});
|
|
3262
|
-
this.promise.then = (onfulfilled) => {
|
|
3263
|
-
let _resolve;
|
|
3264
|
-
const promise = new Promise((resolve) => {
|
|
3265
|
-
token.subscribe(resolve);
|
|
3266
|
-
_resolve = resolve;
|
|
3267
|
-
}).then(onfulfilled);
|
|
3268
|
-
promise.cancel = function reject() {
|
|
3269
|
-
token.unsubscribe(_resolve);
|
|
3270
|
-
};
|
|
3271
|
-
return promise;
|
|
3272
|
-
};
|
|
3273
|
-
executor(function cancel(message, config, request) {
|
|
3274
|
-
if (token.reason) {
|
|
3275
|
-
return;
|
|
3276
|
-
}
|
|
3277
|
-
token.reason = new CanceledError(message, config, request);
|
|
3278
|
-
resolvePromise(token.reason);
|
|
3279
|
-
});
|
|
3280
|
-
}
|
|
3281
|
-
/**
|
|
3282
|
-
* Throws a `CanceledError` if cancellation has been requested.
|
|
3283
|
-
*/
|
|
3284
|
-
throwIfRequested() {
|
|
3285
|
-
if (this.reason) {
|
|
3286
|
-
throw this.reason;
|
|
3287
|
-
}
|
|
3288
|
-
}
|
|
3289
|
-
/**
|
|
3290
|
-
* Subscribe to the cancel signal
|
|
3291
|
-
*/
|
|
3292
|
-
subscribe(listener) {
|
|
3293
|
-
if (this.reason) {
|
|
3294
|
-
listener(this.reason);
|
|
3295
|
-
return;
|
|
3296
|
-
}
|
|
3297
|
-
if (this._listeners) {
|
|
3298
|
-
this._listeners.push(listener);
|
|
3299
|
-
} else {
|
|
3300
|
-
this._listeners = [listener];
|
|
3301
|
-
}
|
|
3302
|
-
}
|
|
3303
|
-
/**
|
|
3304
|
-
* Unsubscribe from the cancel signal
|
|
3305
|
-
*/
|
|
3306
|
-
unsubscribe(listener) {
|
|
3307
|
-
if (!this._listeners) {
|
|
3308
|
-
return;
|
|
3309
|
-
}
|
|
3310
|
-
const index = this._listeners.indexOf(listener);
|
|
3311
|
-
if (index !== -1) {
|
|
3312
|
-
this._listeners.splice(index, 1);
|
|
3313
|
-
}
|
|
3314
|
-
}
|
|
3315
|
-
toAbortSignal() {
|
|
3316
|
-
const controller = new AbortController();
|
|
3317
|
-
const abort = (err) => {
|
|
3318
|
-
controller.abort(err);
|
|
3319
|
-
};
|
|
3320
|
-
this.subscribe(abort);
|
|
3321
|
-
controller.signal.unsubscribe = () => this.unsubscribe(abort);
|
|
3322
|
-
return controller.signal;
|
|
3323
|
-
}
|
|
3324
|
-
/**
|
|
3325
|
-
* Returns an object that contains a new `CancelToken` and a function that, when called,
|
|
3326
|
-
* cancels the `CancelToken`.
|
|
3327
|
-
*/
|
|
3328
|
-
static source() {
|
|
3329
|
-
let cancel;
|
|
3330
|
-
const token = new CancelToken(function executor(c) {
|
|
3331
|
-
cancel = c;
|
|
3332
|
-
});
|
|
3333
|
-
return {
|
|
3334
|
-
token,
|
|
3335
|
-
cancel
|
|
3336
|
-
};
|
|
3337
|
-
}
|
|
3338
|
-
}
|
|
3339
|
-
function spread(callback) {
|
|
3340
|
-
return function wrap(arr) {
|
|
3341
|
-
return callback.apply(null, arr);
|
|
3342
|
-
};
|
|
3343
|
-
}
|
|
3344
|
-
function isAxiosError(payload) {
|
|
3345
|
-
return utils$1.isObject(payload) && payload.isAxiosError === true;
|
|
3346
|
-
}
|
|
3347
|
-
const HttpStatusCode = {
|
|
3348
|
-
Continue: 100,
|
|
3349
|
-
SwitchingProtocols: 101,
|
|
3350
|
-
Processing: 102,
|
|
3351
|
-
EarlyHints: 103,
|
|
3352
|
-
Ok: 200,
|
|
3353
|
-
Created: 201,
|
|
3354
|
-
Accepted: 202,
|
|
3355
|
-
NonAuthoritativeInformation: 203,
|
|
3356
|
-
NoContent: 204,
|
|
3357
|
-
ResetContent: 205,
|
|
3358
|
-
PartialContent: 206,
|
|
3359
|
-
MultiStatus: 207,
|
|
3360
|
-
AlreadyReported: 208,
|
|
3361
|
-
ImUsed: 226,
|
|
3362
|
-
MultipleChoices: 300,
|
|
3363
|
-
MovedPermanently: 301,
|
|
3364
|
-
Found: 302,
|
|
3365
|
-
SeeOther: 303,
|
|
3366
|
-
NotModified: 304,
|
|
3367
|
-
UseProxy: 305,
|
|
3368
|
-
Unused: 306,
|
|
3369
|
-
TemporaryRedirect: 307,
|
|
3370
|
-
PermanentRedirect: 308,
|
|
3371
|
-
BadRequest: 400,
|
|
3372
|
-
Unauthorized: 401,
|
|
3373
|
-
PaymentRequired: 402,
|
|
3374
|
-
Forbidden: 403,
|
|
3375
|
-
NotFound: 404,
|
|
3376
|
-
MethodNotAllowed: 405,
|
|
3377
|
-
NotAcceptable: 406,
|
|
3378
|
-
ProxyAuthenticationRequired: 407,
|
|
3379
|
-
RequestTimeout: 408,
|
|
3380
|
-
Conflict: 409,
|
|
3381
|
-
Gone: 410,
|
|
3382
|
-
LengthRequired: 411,
|
|
3383
|
-
PreconditionFailed: 412,
|
|
3384
|
-
PayloadTooLarge: 413,
|
|
3385
|
-
UriTooLong: 414,
|
|
3386
|
-
UnsupportedMediaType: 415,
|
|
3387
|
-
RangeNotSatisfiable: 416,
|
|
3388
|
-
ExpectationFailed: 417,
|
|
3389
|
-
ImATeapot: 418,
|
|
3390
|
-
MisdirectedRequest: 421,
|
|
3391
|
-
UnprocessableEntity: 422,
|
|
3392
|
-
Locked: 423,
|
|
3393
|
-
FailedDependency: 424,
|
|
3394
|
-
TooEarly: 425,
|
|
3395
|
-
UpgradeRequired: 426,
|
|
3396
|
-
PreconditionRequired: 428,
|
|
3397
|
-
TooManyRequests: 429,
|
|
3398
|
-
RequestHeaderFieldsTooLarge: 431,
|
|
3399
|
-
UnavailableForLegalReasons: 451,
|
|
3400
|
-
InternalServerError: 500,
|
|
3401
|
-
NotImplemented: 501,
|
|
3402
|
-
BadGateway: 502,
|
|
3403
|
-
ServiceUnavailable: 503,
|
|
3404
|
-
GatewayTimeout: 504,
|
|
3405
|
-
HttpVersionNotSupported: 505,
|
|
3406
|
-
VariantAlsoNegotiates: 506,
|
|
3407
|
-
InsufficientStorage: 507,
|
|
3408
|
-
LoopDetected: 508,
|
|
3409
|
-
NotExtended: 510,
|
|
3410
|
-
NetworkAuthenticationRequired: 511
|
|
3411
|
-
};
|
|
3412
|
-
Object.entries(HttpStatusCode).forEach(([key, value]) => {
|
|
3413
|
-
HttpStatusCode[value] = key;
|
|
3414
|
-
});
|
|
3415
|
-
function createInstance(defaultConfig) {
|
|
3416
|
-
const context = new Axios(defaultConfig);
|
|
3417
|
-
const instance = bind(Axios.prototype.request, context);
|
|
3418
|
-
utils$1.extend(instance, Axios.prototype, context, { allOwnKeys: true });
|
|
3419
|
-
utils$1.extend(instance, context, null, { allOwnKeys: true });
|
|
3420
|
-
instance.create = function create(instanceConfig) {
|
|
3421
|
-
return createInstance(mergeConfig(defaultConfig, instanceConfig));
|
|
3422
|
-
};
|
|
3423
|
-
return instance;
|
|
3424
|
-
}
|
|
3425
|
-
const axios = createInstance(defaults);
|
|
3426
|
-
axios.Axios = Axios;
|
|
3427
|
-
axios.CanceledError = CanceledError;
|
|
3428
|
-
axios.CancelToken = CancelToken;
|
|
3429
|
-
axios.isCancel = isCancel;
|
|
3430
|
-
axios.VERSION = VERSION;
|
|
3431
|
-
axios.toFormData = toFormData;
|
|
3432
|
-
axios.AxiosError = AxiosError;
|
|
3433
|
-
axios.Cancel = axios.CanceledError;
|
|
3434
|
-
axios.all = function all(promises) {
|
|
3435
|
-
return Promise.all(promises);
|
|
3436
|
-
};
|
|
3437
|
-
axios.spread = spread;
|
|
3438
|
-
axios.isAxiosError = isAxiosError;
|
|
3439
|
-
axios.mergeConfig = mergeConfig;
|
|
3440
|
-
axios.AxiosHeaders = AxiosHeaders;
|
|
3441
|
-
axios.formToJSON = (thing) => formDataToJSON(utils$1.isHTMLForm(thing) ? new FormData(thing) : thing);
|
|
3442
|
-
axios.getAdapter = adapters.getAdapter;
|
|
3443
|
-
axios.HttpStatusCode = HttpStatusCode;
|
|
3444
|
-
axios.default = axios;
|
|
3445
|
-
class MemoryCache {
|
|
3446
|
-
constructor(ttl) {
|
|
3447
|
-
// private cache: Record<string, CacheSetData> = {};
|
|
3448
|
-
__publicField(this, "CacheMap", /* @__PURE__ */ new Map());
|
|
3449
|
-
__publicField(this, "ttl");
|
|
3450
|
-
this.ttl = ttl;
|
|
3451
|
-
}
|
|
3452
|
-
async get(key) {
|
|
3453
|
-
return new Promise((resolve, reject) => {
|
|
3454
|
-
try {
|
|
3455
|
-
const cacheItem = this.CacheMap.get(key);
|
|
3456
|
-
if (!cacheItem) {
|
|
3457
|
-
return resolve({
|
|
3458
|
-
error: new Error("[MemoryCache]未找到缓存,将执行请求"),
|
|
3459
|
-
data: null
|
|
3460
|
-
});
|
|
3461
|
-
}
|
|
3462
|
-
const { data, exp } = cacheItem;
|
|
3463
|
-
if (exp < Math.ceil((/* @__PURE__ */ new Date()).getTime() / 1e3)) {
|
|
3464
|
-
this.delete(key);
|
|
3465
|
-
return resolve({
|
|
3466
|
-
error: new Error("[MemoryCache]缓存已过期,将执行请求"),
|
|
3467
|
-
data: null
|
|
3468
|
-
});
|
|
3469
|
-
}
|
|
3470
|
-
resolve({ error: null, data });
|
|
3471
|
-
} catch (error) {
|
|
3472
|
-
console.error("[MemoryCache]获取缓存错误:", error);
|
|
3473
|
-
reject(error);
|
|
3474
|
-
}
|
|
3475
|
-
});
|
|
3476
|
-
}
|
|
3477
|
-
async set(key, value) {
|
|
3478
|
-
return new Promise((resolve, reject) => {
|
|
3479
|
-
try {
|
|
3480
|
-
this.CacheMap.set(key, {
|
|
3481
|
-
data: value,
|
|
3482
|
-
exp: Math.ceil((/* @__PURE__ */ new Date()).getTime() / 1e3) + this.ttl
|
|
3483
|
-
});
|
|
3484
|
-
resolve(true);
|
|
3485
|
-
} catch (error) {
|
|
3486
|
-
console.error("[MemoryCache]设置缓存错误:", error);
|
|
3487
|
-
reject(error);
|
|
3488
|
-
}
|
|
3489
|
-
});
|
|
3490
|
-
}
|
|
3491
|
-
async delete(key) {
|
|
3492
|
-
return new Promise((resolve, reject) => {
|
|
3493
|
-
try {
|
|
3494
|
-
this.CacheMap.delete(key);
|
|
3495
|
-
resolve(true);
|
|
3496
|
-
} catch (error) {
|
|
3497
|
-
console.error("[MemoryCache]删除缓存错误:", error);
|
|
3498
|
-
reject(error);
|
|
3499
|
-
}
|
|
3500
|
-
});
|
|
3501
|
-
}
|
|
3502
|
-
async clear() {
|
|
3503
|
-
return new Promise((resolve, reject) => {
|
|
3504
|
-
try {
|
|
3505
|
-
this.CacheMap.clear();
|
|
3506
|
-
resolve(true);
|
|
3507
|
-
} catch (error) {
|
|
3508
|
-
console.error("[MemoryCache]清空缓存错误:", error);
|
|
3509
|
-
reject(error);
|
|
3510
|
-
}
|
|
3511
|
-
});
|
|
3512
|
-
}
|
|
3513
|
-
async keys() {
|
|
3514
|
-
return new Promise((resolve, reject) => {
|
|
3515
|
-
try {
|
|
3516
|
-
const keys = Array.from(this.CacheMap.keys());
|
|
3517
|
-
resolve(keys);
|
|
3518
|
-
} catch (error) {
|
|
3519
|
-
console.error("[MemoryCache]获取缓存键错误:", error);
|
|
3520
|
-
reject(error);
|
|
3521
|
-
}
|
|
3522
|
-
});
|
|
3523
|
-
}
|
|
3524
|
-
}
|
|
3525
|
-
class LocalStorageCache {
|
|
3526
|
-
constructor(ttl) {
|
|
3527
|
-
__publicField(this, "ttl");
|
|
3528
|
-
this.ttl = ttl;
|
|
3529
|
-
}
|
|
3530
|
-
async get(key) {
|
|
3531
|
-
return new Promise((resolve, reject) => {
|
|
3532
|
-
try {
|
|
3533
|
-
const cacheItem = localStorage.getItem(key);
|
|
3534
|
-
if (!cacheItem) {
|
|
3535
|
-
return resolve({
|
|
3536
|
-
error: new Error(`未找到${key}的缓存`),
|
|
3537
|
-
data: null
|
|
3538
|
-
});
|
|
3539
|
-
}
|
|
3540
|
-
const { data, exp } = JSON.parse(cacheItem);
|
|
3541
|
-
if (exp < Math.ceil((/* @__PURE__ */ new Date()).getTime() / 1e3)) {
|
|
3542
|
-
this.delete(key);
|
|
3543
|
-
return resolve({
|
|
3544
|
-
error: new Error(`${key}的缓存已过期`),
|
|
3545
|
-
data: null
|
|
3546
|
-
});
|
|
3547
|
-
}
|
|
3548
|
-
resolve({ error: null, data });
|
|
3549
|
-
} catch (error) {
|
|
3550
|
-
reject({ error, data: null });
|
|
3551
|
-
}
|
|
3552
|
-
});
|
|
3553
|
-
}
|
|
3554
|
-
async set(key, value) {
|
|
3555
|
-
return new Promise((resolve, reject) => {
|
|
3556
|
-
try {
|
|
3557
|
-
localStorage.setItem(
|
|
3558
|
-
key,
|
|
3559
|
-
JSON.stringify({
|
|
3560
|
-
data: value,
|
|
3561
|
-
exp: Math.ceil((/* @__PURE__ */ new Date()).getTime() / 1e3) + this.ttl
|
|
3562
|
-
})
|
|
3563
|
-
);
|
|
3564
|
-
resolve(true);
|
|
3565
|
-
} catch (error) {
|
|
3566
|
-
console.error("[LocalStorage]插入数据错误:", error);
|
|
3567
|
-
reject({ error, data: null });
|
|
3568
|
-
}
|
|
3569
|
-
});
|
|
3570
|
-
}
|
|
3571
|
-
async delete(key) {
|
|
3572
|
-
return new Promise((resolve, reject) => {
|
|
3573
|
-
try {
|
|
3574
|
-
localStorage.removeItem(key);
|
|
3575
|
-
resolve(true);
|
|
3576
|
-
} catch (error) {
|
|
3577
|
-
console.error("[LocalStorage]删除数据错误:", error);
|
|
3578
|
-
reject(error);
|
|
3579
|
-
}
|
|
3580
|
-
});
|
|
3581
|
-
}
|
|
3582
|
-
async clear() {
|
|
3583
|
-
return new Promise((resolve, reject) => {
|
|
3584
|
-
try {
|
|
3585
|
-
localStorage.clear();
|
|
3586
|
-
resolve(true);
|
|
3587
|
-
} catch (error) {
|
|
3588
|
-
console.error("[LocalStorage]清空数据错误:", error);
|
|
3589
|
-
reject(false);
|
|
3590
|
-
}
|
|
3591
|
-
});
|
|
3592
|
-
}
|
|
3593
|
-
async keys() {
|
|
3594
|
-
return new Promise((resolve) => {
|
|
3595
|
-
const keys = [];
|
|
3596
|
-
for (let i = 0; i < localStorage.length; i++) {
|
|
3597
|
-
const key = localStorage.key(i);
|
|
3598
|
-
if (key) keys.push(key);
|
|
3599
|
-
}
|
|
3600
|
-
resolve(keys);
|
|
3601
|
-
});
|
|
3602
|
-
}
|
|
3603
|
-
}
|
|
3604
|
-
const INDEXDB_DATABASE_NAME = "SNAIL_CACHE";
|
|
3605
|
-
const INDEXDB_VERSION = 3;
|
|
3606
|
-
const INDEXDB_OBJECT_STORE_NAME = "SNAIL_CACHE_OBJECT";
|
|
3607
|
-
const INDEXDB_INDEX_NAME = "SNAIL_CACHE_INDEX";
|
|
3608
|
-
class IndexDBCache {
|
|
3609
|
-
constructor(ttl) {
|
|
3610
|
-
__publicField(this, "ttl");
|
|
3611
|
-
__publicField(this, "db");
|
|
3612
|
-
this.ttl = ttl;
|
|
3613
|
-
}
|
|
3614
|
-
async init() {
|
|
3615
|
-
this.db = await this.openDB();
|
|
3616
|
-
}
|
|
3617
|
-
async openDB() {
|
|
3618
|
-
return new Promise((resolve, reject) => {
|
|
3619
|
-
const request = indexedDB.open(INDEXDB_DATABASE_NAME, INDEXDB_VERSION);
|
|
3620
|
-
request.onupgradeneeded = function(event) {
|
|
3621
|
-
const db = event.target.result;
|
|
3622
|
-
const objectStore = db.createObjectStore(INDEXDB_OBJECT_STORE_NAME, {
|
|
3623
|
-
keyPath: "key"
|
|
3624
|
-
});
|
|
3625
|
-
objectStore.createIndex(INDEXDB_INDEX_NAME, "key", {
|
|
3626
|
-
unique: false
|
|
3627
|
-
});
|
|
3628
|
-
};
|
|
3629
|
-
request.onsuccess = function(event) {
|
|
3630
|
-
const db = event.target.result;
|
|
3631
|
-
resolve(db);
|
|
3632
|
-
};
|
|
3633
|
-
request.onerror = (event) => {
|
|
3634
|
-
console.error(`[indexDB]连接数据库错误:${event.target}`);
|
|
3635
|
-
reject(null);
|
|
3636
|
-
};
|
|
3637
|
-
});
|
|
3638
|
-
}
|
|
3639
|
-
async get(key) {
|
|
3640
|
-
return new Promise(async (resolve, reject) => {
|
|
3641
|
-
if (this.db === null || this.db === void 0) {
|
|
3642
|
-
await this.init();
|
|
3643
|
-
}
|
|
3644
|
-
const select = this.db.transaction(INDEXDB_OBJECT_STORE_NAME, "readonly").objectStore(INDEXDB_OBJECT_STORE_NAME).get(key);
|
|
3645
|
-
select.onsuccess = () => {
|
|
3646
|
-
const result = select.result;
|
|
3647
|
-
if (!result || result.exp < Math.ceil((/* @__PURE__ */ new Date()).getTime() / 1e3)) {
|
|
3648
|
-
this.delete(key);
|
|
3649
|
-
return resolve({ error: new Error("缓存已过期"), data: null });
|
|
3650
|
-
}
|
|
3651
|
-
resolve({ error: null, data: result.data });
|
|
3652
|
-
};
|
|
3653
|
-
select.onerror = (event) => {
|
|
3654
|
-
reject({
|
|
3655
|
-
error: new Error(`查询数据错误:${event.target}`),
|
|
3656
|
-
data: null
|
|
3657
|
-
});
|
|
3658
|
-
};
|
|
3659
|
-
});
|
|
3660
|
-
}
|
|
3661
|
-
async set(key, value) {
|
|
3662
|
-
return new Promise(async (resolve, reject) => {
|
|
3663
|
-
if (this.db === null || this.db === void 0) {
|
|
3664
|
-
await this.init();
|
|
3665
|
-
}
|
|
3666
|
-
const select = this.db.transaction(INDEXDB_OBJECT_STORE_NAME, "readwrite").objectStore(INDEXDB_OBJECT_STORE_NAME).put({
|
|
3667
|
-
data: value,
|
|
3668
|
-
exp: Math.ceil((/* @__PURE__ */ new Date()).getTime() / 1e3) + this.ttl,
|
|
3669
|
-
key
|
|
3670
|
-
});
|
|
3671
|
-
select.onsuccess = () => {
|
|
3672
|
-
resolve(true);
|
|
3673
|
-
};
|
|
3674
|
-
select.onerror = (event) => {
|
|
3675
|
-
console.error(`[indexDB]插入数据错误:${event.target}`);
|
|
3676
|
-
reject(event);
|
|
3677
|
-
};
|
|
3678
|
-
});
|
|
3679
|
-
}
|
|
3680
|
-
async delete(key) {
|
|
3681
|
-
return new Promise(async (resolve, reject) => {
|
|
3682
|
-
if (this.db === null || this.db === void 0) {
|
|
3683
|
-
await this.init();
|
|
3684
|
-
}
|
|
3685
|
-
const select = this.db.transaction(INDEXDB_OBJECT_STORE_NAME, "readwrite").objectStore(INDEXDB_OBJECT_STORE_NAME).delete(key);
|
|
3686
|
-
select.onsuccess = () => {
|
|
3687
|
-
resolve(true);
|
|
3688
|
-
};
|
|
3689
|
-
select.onerror = (event) => {
|
|
3690
|
-
console.error(`[indexDB]删除数据错误:${event.target}`);
|
|
3691
|
-
reject(event);
|
|
3692
|
-
};
|
|
3693
|
-
});
|
|
3694
|
-
}
|
|
3695
|
-
async clear() {
|
|
3696
|
-
return new Promise(async (resolve, reject) => {
|
|
3697
|
-
if (!this.db) await this.init();
|
|
3698
|
-
const transaction = this.db.transaction(
|
|
3699
|
-
INDEXDB_OBJECT_STORE_NAME,
|
|
3700
|
-
"readwrite"
|
|
3701
|
-
);
|
|
3702
|
-
const request = transaction.objectStore(INDEXDB_OBJECT_STORE_NAME).clear();
|
|
3703
|
-
request.onsuccess = () => resolve(true);
|
|
3704
|
-
request.onerror = (event) => {
|
|
3705
|
-
console.error(`[indexDB]清空数据错误:${event.target}`);
|
|
3706
|
-
reject(false);
|
|
3707
|
-
};
|
|
3708
|
-
});
|
|
3709
|
-
}
|
|
3710
|
-
async keys() {
|
|
3711
|
-
return new Promise(async (resolve, reject) => {
|
|
3712
|
-
if (!this.db) await this.init();
|
|
3713
|
-
const transaction = this.db.transaction(
|
|
3714
|
-
INDEXDB_OBJECT_STORE_NAME,
|
|
3715
|
-
"readonly"
|
|
3716
|
-
);
|
|
3717
|
-
const request = transaction.objectStore(INDEXDB_OBJECT_STORE_NAME).getAllKeys();
|
|
3718
|
-
request.onsuccess = () => resolve(request.result.map((key) => key.toString()));
|
|
3719
|
-
request.onerror = (event) => {
|
|
3720
|
-
console.error(`[indexDB]获取键名错误:${event.target}`);
|
|
3721
|
-
reject([]);
|
|
3722
|
-
};
|
|
3723
|
-
});
|
|
3724
|
-
}
|
|
3725
|
-
}
|
|
3726
|
-
class SnailServerStatusCodeRuleOptions {
|
|
3727
|
-
constructor() {
|
|
3728
|
-
__publicField(this, "key");
|
|
3729
|
-
__publicField(this, "rule");
|
|
3730
|
-
}
|
|
3731
|
-
}
|
|
3732
|
-
var VersioningType = /* @__PURE__ */ ((VersioningType2) => {
|
|
3733
|
-
VersioningType2[VersioningType2["Uri"] = 0] = "Uri";
|
|
3734
|
-
VersioningType2[VersioningType2["Header"] = 1] = "Header";
|
|
3735
|
-
VersioningType2[VersioningType2["Query"] = 2] = "Query";
|
|
3736
|
-
VersioningType2[VersioningType2["Custom"] = 3] = "Custom";
|
|
3737
|
-
return VersioningType2;
|
|
3738
|
-
})(VersioningType || {});
|
|
3739
|
-
var CacheType = /* @__PURE__ */ ((CacheType2) => {
|
|
3740
|
-
CacheType2[CacheType2["Memory"] = 0] = "Memory";
|
|
3741
|
-
CacheType2[CacheType2["IndexDB"] = 1] = "IndexDB";
|
|
3742
|
-
CacheType2[CacheType2["LocalStorage"] = 2] = "LocalStorage";
|
|
3743
|
-
CacheType2[CacheType2["Custom"] = 3] = "Custom";
|
|
3744
|
-
return CacheType2;
|
|
3745
|
-
})(CacheType || {});
|
|
3746
|
-
class CacheStorageAdapter {
|
|
3747
|
-
}
|
|
3748
|
-
class Strategy {
|
|
3749
|
-
}
|
|
3750
|
-
class SseEventListener {
|
|
3751
|
-
constructor() {
|
|
3752
|
-
__publicField(this, "eventName");
|
|
3753
|
-
__publicField(this, "emit");
|
|
3754
|
-
__publicField(this, "options");
|
|
3755
|
-
}
|
|
3756
|
-
}
|
|
3757
|
-
class SseOptions {
|
|
3758
|
-
constructor() {
|
|
3759
|
-
__publicField(this, "withCredentials");
|
|
3760
|
-
__publicField(this, "version");
|
|
3761
|
-
}
|
|
3762
|
-
}
|
|
3763
|
-
function createCache(optios) {
|
|
3764
|
-
const { type } = optios;
|
|
3765
|
-
if (type === CacheType.Custom) {
|
|
3766
|
-
const adapter = optios.adapter;
|
|
3767
|
-
return new adapter(optios.options);
|
|
3768
|
-
}
|
|
3769
|
-
if (type === CacheType.LocalStorage) {
|
|
3770
|
-
const { ttl: ttl2 } = optios;
|
|
3771
|
-
return new LocalStorageCache(ttl2);
|
|
3772
|
-
}
|
|
3773
|
-
if (type === CacheType.IndexDB) {
|
|
3774
|
-
const { ttl: ttl2 } = optios;
|
|
3775
|
-
const db = new IndexDBCache(ttl2);
|
|
3776
|
-
db.init();
|
|
3777
|
-
return db;
|
|
3778
|
-
}
|
|
3779
|
-
const { ttl } = optios;
|
|
3780
|
-
return new MemoryCache(ttl);
|
|
3781
|
-
}
|
|
3782
|
-
const REQUEST_ARGS_KEY = Symbol("SNAIL_REQUEST_ARGS_KEY");
|
|
3783
|
-
const Params = (key) => createArgsDecorator("params", key);
|
|
3784
|
-
const Query = (key) => createArgsDecorator("querys", key);
|
|
3785
|
-
const Data = (key) => createArgsDecorator("data", key);
|
|
3786
|
-
const createArgsDecorator = (type, key) => {
|
|
3787
|
-
return (target, propertyKey, parameterIndex) => {
|
|
3788
|
-
const args = Reflect.getMetadata(REQUEST_ARGS_KEY, target, propertyKey) || [];
|
|
3789
|
-
args.push({ index: parameterIndex, type, key });
|
|
3790
|
-
Reflect.defineMetadata(REQUEST_ARGS_KEY, args, target, propertyKey);
|
|
3791
|
-
};
|
|
3792
|
-
};
|
|
3793
|
-
async function generateCacheKey(methodName, version, request) {
|
|
3794
|
-
const { method, url, params, headers } = request;
|
|
3795
|
-
const hash = await generateShortUniqueHash(
|
|
3796
|
-
`${params ? `-${recordToString(params)}` : ""}${headers ? `-${recordToString(headers)}` : ""}`
|
|
3797
|
-
);
|
|
3798
|
-
return `${methodName}${version ? `[v${version}]` : ""}[${method}]${url}-${hash}`;
|
|
3799
|
-
}
|
|
3800
|
-
async function generateShortUniqueHash(str) {
|
|
3801
|
-
const encoder = new TextEncoder();
|
|
3802
|
-
const data = encoder.encode(str);
|
|
3803
|
-
const hashBuffer = await window.crypto.subtle.digest("SHA-256", data);
|
|
3804
|
-
const hashArray = Array.from(new Uint8Array(hashBuffer));
|
|
3805
|
-
let hashBase64 = btoa(String.fromCharCode.apply(null, hashArray));
|
|
3806
|
-
hashBase64 = hashBase64.replace(/\+/g, "0").replace(/\//g, "1").replace(/=/g, "");
|
|
3807
|
-
return hashBase64.substring(0, 16);
|
|
3808
|
-
}
|
|
3809
|
-
function recordToString(record) {
|
|
3810
|
-
return Object.keys(record).map((key) => {
|
|
3811
|
-
return `${key}=${record[key]}`;
|
|
3812
|
-
}).sort((a, b) => a.localeCompare(b)).join("&");
|
|
3813
|
-
}
|
|
3814
|
-
function replacePlaceholders(route, values) {
|
|
3815
|
-
const placeholderRegex = /:([a-zA-Z0-9_]+)/g;
|
|
3816
|
-
const newRoute = route.replace(placeholderRegex, (match, key) => {
|
|
3817
|
-
if (values.hasOwnProperty(key)) {
|
|
3818
|
-
return values[key];
|
|
3819
|
-
} else {
|
|
3820
|
-
console.error(`路由[${route}]中的占位符${match},没有对应的值`);
|
|
3821
|
-
console.error(`请在该路由对应的方法中添加@Params('${key}')装饰器`);
|
|
3822
|
-
throw new TypeError(`route params error in ${route}`);
|
|
3823
|
-
}
|
|
3824
|
-
});
|
|
3825
|
-
return newRoute;
|
|
3826
|
-
}
|
|
3827
|
-
const resolveUrl = (url) => {
|
|
3828
|
-
if (!url) return "";
|
|
3829
|
-
if (url.startsWith("/")) return url;
|
|
3830
|
-
return `/${url}`;
|
|
3831
|
-
};
|
|
3832
|
-
async function applyStrategies(data, strategies, type = "request") {
|
|
3833
|
-
return await strategies.reduce(
|
|
3834
|
-
async (result, strategy) => {
|
|
3835
|
-
let handler;
|
|
3836
|
-
const instance = new strategy();
|
|
3837
|
-
if (type == "response") {
|
|
3838
|
-
handler = instance.applyResponse;
|
|
3839
|
-
}
|
|
3840
|
-
handler = instance.applyRequest;
|
|
3841
|
-
const currentResult = handler(await result);
|
|
3842
|
-
if (!currentResult) return result;
|
|
3843
|
-
return currentResult;
|
|
3844
|
-
},
|
|
3845
|
-
Promise.resolve(data)
|
|
3846
|
-
);
|
|
3847
|
-
}
|
|
3848
|
-
const SnailPass = (...args) => {
|
|
3849
|
-
};
|
|
3850
|
-
const buildRequestArgs = (target, propertyKey, args) => {
|
|
3851
|
-
const requestArgs = { params: {}, data: {}, querys: {} };
|
|
3852
|
-
const argsConfigs = Reflect.getMetadata(REQUEST_ARGS_KEY, target, propertyKey) || [];
|
|
3853
|
-
console.log("argsConfigs:", argsConfigs);
|
|
3854
|
-
argsConfigs.forEach(({ index, type, key }) => {
|
|
3855
|
-
const value = args[index];
|
|
3856
|
-
if (type === "params" && !key && typeof value === "object") {
|
|
3857
|
-
requestArgs.params = { ...requestArgs.params, ...value };
|
|
3858
|
-
}
|
|
3859
|
-
if (type === "params" && key) {
|
|
3860
|
-
requestArgs.params[key] = value;
|
|
3861
|
-
}
|
|
3862
|
-
if (type === "querys" && !key && typeof value === "object") {
|
|
3863
|
-
requestArgs.querys = { ...requestArgs.params, ...value };
|
|
3864
|
-
}
|
|
3865
|
-
if (type === "querys" && key) {
|
|
3866
|
-
requestArgs.querys[key] = value;
|
|
3867
|
-
}
|
|
3868
|
-
if (type === "data" && !key && typeof value === "object") {
|
|
3869
|
-
requestArgs.data = { ...requestArgs.data, ...value };
|
|
3870
|
-
}
|
|
3871
|
-
if (type === "data" && key) {
|
|
3872
|
-
requestArgs.data[key] = value;
|
|
3873
|
-
}
|
|
3874
|
-
});
|
|
3875
|
-
return requestArgs;
|
|
3876
|
-
};
|
|
3877
|
-
function isSpecialResponse(response) {
|
|
3878
|
-
const contentType = response.headers["Content-Type"];
|
|
3879
|
-
if (!contentType) return false;
|
|
3880
|
-
return !contentType.includes("application/json");
|
|
3881
|
-
}
|
|
3882
|
-
const METHOD_KEY = Symbol("SNAIL_METHOD_KEY");
|
|
3883
|
-
const createMethodDecorator = (method) => {
|
|
3884
|
-
return (path = "", options) => {
|
|
3885
|
-
return (target, propertyKey) => {
|
|
3886
|
-
const methodOptions = Reflect.getMetadata(
|
|
3887
|
-
METHOD_KEY,
|
|
3888
|
-
target,
|
|
3889
|
-
propertyKey
|
|
3890
|
-
);
|
|
3891
|
-
if (methodOptions) {
|
|
3892
|
-
console.error("only one method decorator for a request function!");
|
|
3893
|
-
console.error(
|
|
3894
|
-
`you must chose only one method decorator[@${method} or @${methodOptions.method}]`
|
|
3895
|
-
);
|
|
3896
|
-
throw new TypeError(
|
|
3897
|
-
`Multiple decorators are used for the same request function`
|
|
3898
|
-
);
|
|
3899
|
-
}
|
|
3900
|
-
Reflect.defineMetadata(
|
|
3901
|
-
METHOD_KEY,
|
|
3902
|
-
{ method, path, ...options },
|
|
3903
|
-
target,
|
|
3904
|
-
propertyKey
|
|
3905
|
-
);
|
|
3906
|
-
};
|
|
3907
|
-
};
|
|
3908
|
-
};
|
|
3909
|
-
const Get = createMethodDecorator("GET");
|
|
3910
|
-
const Post = createMethodDecorator("POST");
|
|
3911
|
-
const Put = createMethodDecorator("PUT");
|
|
3912
|
-
const Delete = createMethodDecorator("DELETE");
|
|
3913
|
-
const Patch = createMethodDecorator("PATCH");
|
|
3914
|
-
const Options = createMethodDecorator("OPTIONS");
|
|
3915
|
-
const Head = createMethodDecorator("HEAD");
|
|
3916
|
-
const SERVER_CONFIG_KEY = Symbol("SANIL_SERVER_CONFIG_KEY");
|
|
3917
|
-
const Server = (config) => {
|
|
3918
|
-
return (target) => {
|
|
3919
|
-
Reflect.defineMetadata(SERVER_CONFIG_KEY, config, target);
|
|
3920
|
-
};
|
|
3921
|
-
};
|
|
3922
|
-
const STRATEGY_KEY = Symbol("SNAIL_STRATEGY_KEY");
|
|
3923
|
-
const UseStrategy = (...strategies) => {
|
|
3924
|
-
return (target, propertyKey) => {
|
|
3925
|
-
const key = propertyKey ? `${STRATEGY_KEY.toString()}_${propertyKey}` : STRATEGY_KEY;
|
|
3926
|
-
Reflect.defineMetadata(key, strategies, target);
|
|
3927
|
-
};
|
|
3928
|
-
};
|
|
3929
|
-
const VERSIONING_KEY = Symbol("SNAIL_VERSIONING_KEY");
|
|
3930
|
-
const VERSION_KEY = Symbol("SNAIL_VERSION_KEY");
|
|
3931
|
-
const Versioning = (options) => {
|
|
3932
|
-
return (target) => {
|
|
3933
|
-
Reflect.defineMetadata(VERSIONING_KEY, options, target);
|
|
3934
|
-
};
|
|
3935
|
-
};
|
|
3936
|
-
const Version = (version) => {
|
|
3937
|
-
return (target, propertyKey) => {
|
|
3938
|
-
Reflect.defineMetadata(VERSION_KEY, version, target, propertyKey);
|
|
3939
|
-
};
|
|
3940
|
-
};
|
|
3941
|
-
const NO_CACHE_KEY = Symbol("SNALI_NO_CACHE_KEY");
|
|
3942
|
-
const CACHE_EXPIRE_SOURCE_KEY = Symbol("SNALI_CACHE_EXPIRE_SOURCE_KEY");
|
|
3943
|
-
const NoCache = () => {
|
|
3944
|
-
return (target, propertyKey) => {
|
|
3945
|
-
if (propertyKey) {
|
|
3946
|
-
Reflect.defineMetadata(NO_CACHE_KEY, true, target, propertyKey);
|
|
3947
|
-
return;
|
|
3948
|
-
}
|
|
3949
|
-
Reflect.defineMetadata(NO_CACHE_KEY, true, target);
|
|
3950
|
-
};
|
|
3951
|
-
};
|
|
3952
|
-
const HitSource = (...sources) => {
|
|
3953
|
-
return (target, propertyKey) => {
|
|
3954
|
-
if (propertyKey) {
|
|
3955
|
-
Reflect.defineMetadata(
|
|
3956
|
-
CACHE_EXPIRE_SOURCE_KEY,
|
|
3957
|
-
sources,
|
|
3958
|
-
target,
|
|
3959
|
-
propertyKey
|
|
3960
|
-
);
|
|
3961
|
-
return;
|
|
3962
|
-
}
|
|
3963
|
-
Reflect.defineMetadata(CACHE_EXPIRE_SOURCE_KEY, sources, target);
|
|
3964
|
-
};
|
|
3965
|
-
};
|
|
3966
|
-
class SnailEvent {
|
|
3967
|
-
constructor() {
|
|
3968
|
-
__publicField(this, "eventMap");
|
|
3969
|
-
__publicField(this, "onceWrapperMap");
|
|
3970
|
-
__publicField(this, "on", (eventName, listener) => {
|
|
3971
|
-
if (typeof listener !== "function") {
|
|
3972
|
-
throw new TypeError("Handler must be a function");
|
|
3973
|
-
}
|
|
3974
|
-
const listeners = this.eventMap.get(eventName) || /* @__PURE__ */ new Set();
|
|
3975
|
-
listeners.add(listener);
|
|
3976
|
-
this.eventMap.set(eventName, listeners);
|
|
3977
|
-
});
|
|
3978
|
-
__publicField(this, "off", (eventName, listener) => {
|
|
3979
|
-
const listeners = this.eventMap.get(eventName);
|
|
3980
|
-
if (!listeners) return;
|
|
3981
|
-
if (this.onceWrapperMap.has(listener)) {
|
|
3982
|
-
this.onceWrapperMap.delete(listener);
|
|
3983
|
-
}
|
|
3984
|
-
if (listeners.size === 0) {
|
|
3985
|
-
this.eventMap.delete(eventName);
|
|
3986
|
-
}
|
|
3987
|
-
});
|
|
3988
|
-
__publicField(this, "once", (eventName, listener) => {
|
|
3989
|
-
const onceHandler = (data) => {
|
|
3990
|
-
try {
|
|
3991
|
-
listener.apply(this, [data]);
|
|
3992
|
-
} finally {
|
|
3993
|
-
this.off(eventName, onceHandler);
|
|
3994
|
-
this.onceWrapperMap.delete(listener);
|
|
3995
|
-
}
|
|
3996
|
-
};
|
|
3997
|
-
this.onceWrapperMap.set(listener, onceHandler);
|
|
3998
|
-
this.on(eventName, onceHandler);
|
|
3999
|
-
});
|
|
4000
|
-
__publicField(this, "emit", (eventName, ...args) => {
|
|
4001
|
-
const listeners = this.eventMap.get(eventName);
|
|
4002
|
-
if (!listeners || listeners.size === 0) return false;
|
|
4003
|
-
listeners.forEach((listener) => {
|
|
4004
|
-
Promise.resolve().then(() => {
|
|
4005
|
-
listener.apply(this, args);
|
|
4006
|
-
});
|
|
4007
|
-
});
|
|
4008
|
-
return true;
|
|
4009
|
-
});
|
|
4010
|
-
this.eventMap = /* @__PURE__ */ new Map();
|
|
4011
|
-
this.onceWrapperMap = /* @__PURE__ */ new Map();
|
|
4012
|
-
}
|
|
4013
|
-
}
|
|
4014
|
-
const versionHandlers = {
|
|
4015
|
-
[VersioningType.Uri]: (version, versioning) => {
|
|
4016
|
-
const prefix = versioning.prefix || "v";
|
|
4017
|
-
return {
|
|
4018
|
-
type: VersioningType.Uri,
|
|
4019
|
-
result: `${prefix}${version}`
|
|
4020
|
-
};
|
|
4021
|
-
},
|
|
4022
|
-
[VersioningType.Header]: (version, versioning) => {
|
|
4023
|
-
const headers = {
|
|
4024
|
-
[versioning.header || "version"]: version
|
|
4025
|
-
};
|
|
4026
|
-
return {
|
|
4027
|
-
type: VersioningType.Header,
|
|
4028
|
-
result: headers
|
|
4029
|
-
};
|
|
4030
|
-
},
|
|
4031
|
-
[VersioningType.Query]: (version, versioning) => {
|
|
4032
|
-
const key = versioning.key || "v";
|
|
4033
|
-
return {
|
|
4034
|
-
type: VersioningType.Query,
|
|
4035
|
-
result: {
|
|
4036
|
-
[key]: version
|
|
4037
|
-
}
|
|
4038
|
-
};
|
|
4039
|
-
},
|
|
4040
|
-
[VersioningType.Custom]: (version, versioning) => {
|
|
4041
|
-
return versioning.extractor({
|
|
4042
|
-
version
|
|
4043
|
-
});
|
|
4044
|
-
}
|
|
4045
|
-
};
|
|
4046
|
-
function applyVersioning(version, versioning) {
|
|
4047
|
-
if (!versioning) return void 0;
|
|
4048
|
-
const handler = versionHandlers[versioning.type];
|
|
4049
|
-
return handler(
|
|
4050
|
-
version,
|
|
4051
|
-
versioning
|
|
4052
|
-
);
|
|
4053
|
-
}
|
|
4054
|
-
const UPLOAD_PROGRESS_KEY = Symbol("SNAIL_UPLOAD_PROGRESS_KEY");
|
|
4055
|
-
const DOWNLOAD_PROGRESS_KEY = Symbol("SNAIL_DOWNLOAD_PROGRESS_KEY");
|
|
4056
|
-
class SnailMethod {
|
|
4057
|
-
// private Args: any[] = [];
|
|
4058
|
-
constructor(apiInstance, target, propertyKey) {
|
|
4059
|
-
// 私有属性
|
|
4060
|
-
// private serverInstance: SnailServer;
|
|
4061
|
-
__publicField(this, "Name");
|
|
4062
|
-
__publicField(this, "apiInstance");
|
|
4063
|
-
__publicField(this, "target");
|
|
4064
|
-
__publicField(this, "strategies", []);
|
|
4065
|
-
__publicField(this, "Request");
|
|
4066
|
-
__publicField(this, "Response");
|
|
4067
|
-
__publicField(this, "Error");
|
|
4068
|
-
__publicField(this, "EventEmit");
|
|
4069
|
-
// private eventMap: Map<string, Set<EventHandler>>;
|
|
4070
|
-
// private onceWrapperMap: Map<EventHandler, EventHandler>;
|
|
4071
|
-
__publicField(this, "propertyKey");
|
|
4072
|
-
__publicField(this, "Url", "");
|
|
4073
|
-
__publicField(this, "Path", "");
|
|
4074
|
-
__publicField(this, "Method", "GET");
|
|
4075
|
-
__publicField(this, "Adapter");
|
|
4076
|
-
__publicField(this, "Version");
|
|
4077
|
-
__publicField(this, "send", (...args) => {
|
|
4078
|
-
this.enableLog() && console.log("send:", this.name);
|
|
4079
|
-
const [serverName] = this.apiInstance.name.split(".");
|
|
4080
|
-
const axios2 = AxiosInstanceMap.get(serverName);
|
|
4081
|
-
if (!axios2) throw new Error("AxiosInstance not created");
|
|
4082
|
-
return new Promise(async (resolve, reject) => {
|
|
4083
|
-
const serverStatusCodeRule = ServerStatusCodeRuleMap.get(serverName);
|
|
4084
|
-
const strategies = this.getStrategies();
|
|
4085
|
-
this.Request = await applyStrategies(this.Request, strategies, "request");
|
|
4086
|
-
this.Request = this.applyProgress(this.Request);
|
|
4087
|
-
const { data, querys, params } = buildRequestArgs(
|
|
4088
|
-
this.target,
|
|
4089
|
-
this.propertyKey,
|
|
4090
|
-
// this.Args
|
|
4091
|
-
args
|
|
4092
|
-
);
|
|
4093
|
-
this.enableLog() && console.log("methodUrl:", this.Request.baseURL, this.Request.url);
|
|
4094
|
-
const newUrl = replacePlaceholders(this.Url, params);
|
|
4095
|
-
this.Request = {
|
|
4096
|
-
...this.Request,
|
|
4097
|
-
url: newUrl,
|
|
4098
|
-
params: {
|
|
4099
|
-
...this.Request.params,
|
|
4100
|
-
...querys
|
|
4101
|
-
},
|
|
4102
|
-
data
|
|
4103
|
-
};
|
|
4104
|
-
this.enableLog() && console.log("request:", this.Request);
|
|
4105
|
-
const isNoCache = this.isNoCache();
|
|
4106
|
-
this.enableLog() && console.log("method is noCache:", isNoCache);
|
|
4107
|
-
if (!isNoCache) {
|
|
4108
|
-
const { data: data2 } = await this.getCacheData(serverName);
|
|
4109
|
-
this.enableLog() && console.log("getCacheData:", data2);
|
|
4110
|
-
if (data2) {
|
|
4111
|
-
this.EventEmit.emit("hitCache", data2);
|
|
4112
|
-
this.EventEmit.emit("success", data2);
|
|
4113
|
-
this.EventEmit.emit("finish", data2);
|
|
4114
|
-
resolve(data2);
|
|
4115
|
-
return;
|
|
4116
|
-
}
|
|
4117
|
-
}
|
|
4118
|
-
const requester = AxiosInstanceMap.get(serverName);
|
|
4119
|
-
if (!requester) throw new Error("AxiosInstance not created");
|
|
4120
|
-
try {
|
|
4121
|
-
const rawResponse = await requester.request(this.Request);
|
|
4122
|
-
const isSpecial = isSpecialResponse(rawResponse);
|
|
4123
|
-
const response = await applyStrategies(
|
|
4124
|
-
rawResponse,
|
|
4125
|
-
strategies,
|
|
4126
|
-
"response"
|
|
4127
|
-
);
|
|
4128
|
-
if (!isNoCache) {
|
|
4129
|
-
!isSpecial && await this.setCacheData(serverName, response.data);
|
|
4130
|
-
}
|
|
4131
|
-
this.Response = response;
|
|
4132
|
-
this.applyHitSource(serverName);
|
|
4133
|
-
isSpecial && console.log("isSpecial:", isSpecial);
|
|
4134
|
-
if (isSpecial) {
|
|
4135
|
-
this.EventEmit.emit("success", response.data);
|
|
4136
|
-
this.EventEmit.emit("finish", response.data);
|
|
4137
|
-
resolve(response);
|
|
4138
|
-
return;
|
|
4139
|
-
}
|
|
4140
|
-
!isSpecial && console.log("isSpecial:", isSpecial);
|
|
4141
|
-
if (serverStatusCodeRule) {
|
|
4142
|
-
const { key, rule } = serverStatusCodeRule;
|
|
4143
|
-
const statuCodeKey = key ?? "code";
|
|
4144
|
-
const data2 = response.data;
|
|
4145
|
-
if (rule(data2[statuCodeKey])) {
|
|
4146
|
-
this.EventEmit.emit("success", response.data);
|
|
4147
|
-
} else {
|
|
4148
|
-
this.EventEmit.emit("error", response.data);
|
|
4149
|
-
}
|
|
4150
|
-
}
|
|
4151
|
-
resolve(response.data);
|
|
4152
|
-
} catch (error) {
|
|
4153
|
-
this.EventEmit.emit("error", error);
|
|
4154
|
-
this.EventEmit.emit("finish", error);
|
|
4155
|
-
console.error(error);
|
|
4156
|
-
this.Error = error;
|
|
4157
|
-
reject(error);
|
|
4158
|
-
return;
|
|
4159
|
-
}
|
|
4160
|
-
});
|
|
4161
|
-
});
|
|
4162
|
-
__publicField(this, "onSuccess", (listener) => {
|
|
4163
|
-
this.EventEmit.on("success", listener);
|
|
4164
|
-
});
|
|
4165
|
-
__publicField(this, "onError", (listener) => {
|
|
4166
|
-
this.EventEmit.on("error", listener);
|
|
4167
|
-
});
|
|
4168
|
-
__publicField(this, "onHitCache", (listener) => {
|
|
4169
|
-
this.EventEmit.on("hitCache", listener);
|
|
4170
|
-
});
|
|
4171
|
-
__publicField(this, "onFinish", (listener) => {
|
|
4172
|
-
this.EventEmit.on("finish", listener);
|
|
4173
|
-
});
|
|
4174
|
-
__publicField(this, "registerStrategies", (...strategys) => {
|
|
4175
|
-
this.strategies.push(...strategys);
|
|
4176
|
-
});
|
|
4177
|
-
this.apiInstance = apiInstance;
|
|
4178
|
-
this.target = target;
|
|
4179
|
-
this.propertyKey = propertyKey.toString();
|
|
4180
|
-
this.init();
|
|
4181
|
-
this.enableLog() && console.log("url:", this.Url);
|
|
4182
|
-
this.EventEmit = new SnailEvent();
|
|
4183
|
-
}
|
|
4184
|
-
init() {
|
|
4185
|
-
const methodOptions = this.getMethodOptions();
|
|
4186
|
-
if (!methodOptions) {
|
|
4187
|
-
throw new Error("Create SnailMethod must be used for decoration");
|
|
4188
|
-
}
|
|
4189
|
-
const { path, method, name, adapter } = methodOptions;
|
|
4190
|
-
this.Name = name ?? this.propertyKey;
|
|
4191
|
-
this.Path = path;
|
|
4192
|
-
this.Method = method;
|
|
4193
|
-
this.Adapter = adapter;
|
|
4194
|
-
this.createRequest();
|
|
4195
|
-
this.initUrl();
|
|
4196
|
-
this.initVersion();
|
|
4197
|
-
}
|
|
4198
|
-
initUrl() {
|
|
4199
|
-
if (this.Path === "") {
|
|
4200
|
-
this.Url = this.apiInstance.url || "";
|
|
4201
|
-
return;
|
|
4202
|
-
}
|
|
4203
|
-
this.Url = `${this.apiInstance.url || ""}${resolveUrl(this.Path)}`;
|
|
4204
|
-
}
|
|
4205
|
-
initVersion() {
|
|
4206
|
-
const version = Reflect.getMetadata(
|
|
4207
|
-
VERSION_KEY,
|
|
4208
|
-
this.target,
|
|
4209
|
-
this.propertyKey
|
|
4210
|
-
);
|
|
4211
|
-
this.Version = version ?? this.apiInstance.version;
|
|
4212
|
-
if (!this.Version) return;
|
|
4213
|
-
const [serverName] = this.apiInstance.name.split(".");
|
|
4214
|
-
const versioningOptions = VersioningMap.get(serverName);
|
|
4215
|
-
if (!versioningOptions) {
|
|
4216
|
-
console.warn("Version Manager not configured");
|
|
4217
|
-
console.log(
|
|
4218
|
-
"Please use @Versioning() to configure the version manager on the ` SnailServer ` class"
|
|
4219
|
-
);
|
|
4220
|
-
return;
|
|
4221
|
-
}
|
|
4222
|
-
const versioningResult = applyVersioning(this.Version, versioningOptions);
|
|
4223
|
-
if (!versioningResult) {
|
|
4224
|
-
console.warn("Apply Versioning error");
|
|
4225
|
-
return;
|
|
4226
|
-
}
|
|
4227
|
-
const { type, result } = versioningResult;
|
|
4228
|
-
if (type === VersioningType.Uri) {
|
|
4229
|
-
this.Url = `${resolveUrl(result)}${resolveUrl(this.Url)}`;
|
|
4230
|
-
}
|
|
4231
|
-
if (type === VersioningType.Header) {
|
|
4232
|
-
this.Request.headers = {
|
|
4233
|
-
...this.Request.headers,
|
|
4234
|
-
...result
|
|
4235
|
-
};
|
|
4236
|
-
}
|
|
4237
|
-
if (type === VersioningType.Query) {
|
|
4238
|
-
this.Request.params = {
|
|
4239
|
-
...this.Request.params,
|
|
4240
|
-
...result
|
|
4241
|
-
};
|
|
4242
|
-
}
|
|
4243
|
-
}
|
|
4244
|
-
getExpireSources() {
|
|
4245
|
-
const invalidSources = ExpireSourceMap.get(this.name) ?? /* @__PURE__ */ new Set();
|
|
4246
|
-
if (invalidSources.size === 0) return [];
|
|
4247
|
-
return Array.from(invalidSources);
|
|
4248
|
-
}
|
|
4249
|
-
createRequest() {
|
|
4250
|
-
const request = {
|
|
4251
|
-
url: this.Url,
|
|
4252
|
-
method: this.Method,
|
|
4253
|
-
adapter: this.Adapter,
|
|
4254
|
-
timeout: this.apiInstance.timeout,
|
|
4255
|
-
data: {},
|
|
4256
|
-
params: {},
|
|
4257
|
-
headers: {}
|
|
4258
|
-
};
|
|
4259
|
-
this.Request = request;
|
|
4260
|
-
return request;
|
|
4261
|
-
}
|
|
4262
|
-
async getCacheData(serverName) {
|
|
4263
|
-
const methodKey = await generateCacheKey(
|
|
4264
|
-
this.name,
|
|
4265
|
-
this.version,
|
|
4266
|
-
this.Request
|
|
4267
|
-
);
|
|
4268
|
-
const cacheStorage = CacheStorageMap.get(serverName);
|
|
4269
|
-
if (!cacheStorage) {
|
|
4270
|
-
throw new Error("CacheStorage not created");
|
|
4271
|
-
}
|
|
4272
|
-
const cacheData = await cacheStorage.get(methodKey);
|
|
4273
|
-
const { error } = cacheData;
|
|
4274
|
-
if (!error) {
|
|
4275
|
-
this.enableLog() && console.warn(`[${this.Name}]`, "Cache hit");
|
|
4276
|
-
}
|
|
4277
|
-
return cacheData;
|
|
4278
|
-
}
|
|
4279
|
-
async setCacheData(serverName, responseData) {
|
|
4280
|
-
const methodKey = await generateCacheKey(
|
|
4281
|
-
this.name,
|
|
4282
|
-
this.version,
|
|
4283
|
-
this.Request
|
|
4284
|
-
);
|
|
4285
|
-
this.enableLog() && console.log("setCacheData:", methodKey);
|
|
4286
|
-
const cacheStorage = CacheStorageMap.get(serverName);
|
|
4287
|
-
if (!cacheStorage) throw new Error("CacheStorage not created");
|
|
4288
|
-
cacheStorage.set(methodKey, responseData);
|
|
4289
|
-
}
|
|
4290
|
-
get response() {
|
|
4291
|
-
return this.Response;
|
|
4292
|
-
}
|
|
4293
|
-
get request() {
|
|
4294
|
-
return this.Request;
|
|
4295
|
-
}
|
|
4296
|
-
get version() {
|
|
4297
|
-
return this.Version;
|
|
4298
|
-
}
|
|
4299
|
-
get name() {
|
|
4300
|
-
return `${this.apiInstance.name}.${this.Name}`;
|
|
4301
|
-
}
|
|
4302
|
-
get error() {
|
|
4303
|
-
if (this.Error) return this.Error;
|
|
4304
|
-
return null;
|
|
4305
|
-
}
|
|
4306
|
-
getStrategies() {
|
|
4307
|
-
const [serverName, apiName] = this.apiInstance.name.split(".");
|
|
4308
|
-
const serverStrategies = StrategyMap.get(serverName) ?? [];
|
|
4309
|
-
const apiStrategies = StrategyMap.get(apiName) ?? [];
|
|
4310
|
-
const methodStrategies = Reflect.getMetadata(
|
|
4311
|
-
`${STRATEGY_KEY.toString()}_${this.propertyKey}`,
|
|
4312
|
-
this.target
|
|
4313
|
-
) || [];
|
|
4314
|
-
const allStrategies = [
|
|
4315
|
-
...serverStrategies,
|
|
4316
|
-
...apiStrategies,
|
|
4317
|
-
...methodStrategies
|
|
4318
|
-
];
|
|
4319
|
-
return allStrategies;
|
|
4320
|
-
}
|
|
4321
|
-
getMethodOptions() {
|
|
4322
|
-
const methodConfig = Reflect.getMetadata(
|
|
4323
|
-
METHOD_KEY,
|
|
4324
|
-
this.target,
|
|
4325
|
-
this.propertyKey
|
|
4326
|
-
);
|
|
4327
|
-
return methodConfig;
|
|
4328
|
-
}
|
|
4329
|
-
isNoCache() {
|
|
4330
|
-
const [serverName] = this.apiInstance.name.split(".");
|
|
4331
|
-
const cacheForMap = CacheForMap.get(serverName);
|
|
4332
|
-
let flag = false;
|
|
4333
|
-
if (cacheForMap) {
|
|
4334
|
-
flag = cacheForMap.includes(this.Method.toLowerCase());
|
|
4335
|
-
}
|
|
4336
|
-
this.enableLog() && console.log("cacheForMap:", cacheForMap);
|
|
4337
|
-
this.enableLog() && console.log("cacheMethodFlag:", flag);
|
|
4338
|
-
const isMethodNoCache = Reflect.getMetadata(
|
|
4339
|
-
NO_CACHE_KEY,
|
|
4340
|
-
this.target,
|
|
4341
|
-
this.propertyKey
|
|
4342
|
-
);
|
|
4343
|
-
const isApiNoCache = this.apiInstance.noCache;
|
|
4344
|
-
this.enableLog() && console.log("isApiNoCache:", isApiNoCache);
|
|
4345
|
-
this.enableLog() && console.log("isMethodNoCache:", isMethodNoCache);
|
|
4346
|
-
const noCacheFlag = isMethodNoCache ? true : isApiNoCache ? true : false;
|
|
4347
|
-
this.enableLog() && console.log("noCacheFlag:", noCacheFlag);
|
|
4348
|
-
return flag ? noCacheFlag : true;
|
|
4349
|
-
}
|
|
4350
|
-
enableLog() {
|
|
4351
|
-
return this.apiInstance.enableLog;
|
|
4352
|
-
}
|
|
4353
|
-
async applyHitSource(serverName) {
|
|
4354
|
-
const sources = this.getExpireSources();
|
|
4355
|
-
const cacheStorage = CacheStorageMap.get(serverName);
|
|
4356
|
-
if (cacheStorage) {
|
|
4357
|
-
const cacheKeys = await cacheStorage.keys();
|
|
4358
|
-
sources.map((source) => {
|
|
4359
|
-
cacheKeys.map((key) => {
|
|
4360
|
-
if (key.startsWith(source)) {
|
|
4361
|
-
this.enableLog() && console.warn(`[${this.name}]请求成功,触发清除缓存:${source}`);
|
|
4362
|
-
cacheStorage.delete(key);
|
|
4363
|
-
}
|
|
4364
|
-
});
|
|
4365
|
-
});
|
|
4366
|
-
}
|
|
4367
|
-
}
|
|
4368
|
-
applyProgress(request) {
|
|
4369
|
-
const onUploadProgress = Reflect.getMetadata(
|
|
4370
|
-
UPLOAD_PROGRESS_KEY,
|
|
4371
|
-
this.target,
|
|
4372
|
-
this.propertyKey
|
|
4373
|
-
);
|
|
4374
|
-
const onDownloadProgress = Reflect.getMetadata(
|
|
4375
|
-
DOWNLOAD_PROGRESS_KEY,
|
|
4376
|
-
this.target,
|
|
4377
|
-
this.propertyKey
|
|
4378
|
-
);
|
|
4379
|
-
return {
|
|
4380
|
-
...request,
|
|
4381
|
-
onUploadProgress,
|
|
4382
|
-
onDownloadProgress
|
|
4383
|
-
};
|
|
4384
|
-
}
|
|
4385
|
-
}
|
|
4386
|
-
const CacheStorageMap = /* @__PURE__ */ new Map();
|
|
4387
|
-
const CacheForMap = /* @__PURE__ */ new Map();
|
|
4388
|
-
const ExpireSourceMap = /* @__PURE__ */ new Map();
|
|
4389
|
-
const AxiosInstanceMap = /* @__PURE__ */ new Map();
|
|
4390
|
-
const StrategyMap = /* @__PURE__ */ new Map();
|
|
4391
|
-
const VersioningMap = /* @__PURE__ */ new Map();
|
|
4392
|
-
const ServerStatusCodeRuleMap = /* @__PURE__ */ new Map();
|
|
4393
|
-
const defaultCacheManageOptions = {
|
|
4394
|
-
type: CacheType.Memory,
|
|
4395
|
-
ttl: 500
|
|
4396
|
-
};
|
|
4397
|
-
const defaultServerOptions = {
|
|
4398
|
-
baseURL: "",
|
|
4399
|
-
timeout: 5e3,
|
|
4400
|
-
cacheManage: defaultCacheManageOptions,
|
|
4401
|
-
cacheFor: "get",
|
|
4402
|
-
enableLog: false
|
|
4403
|
-
};
|
|
4404
|
-
class SnailServer {
|
|
4405
|
-
constructor() {
|
|
4406
|
-
__publicField(this, "Name");
|
|
4407
|
-
__publicField(this, "BaseURL");
|
|
4408
|
-
__publicField(this, "Version");
|
|
4409
|
-
__publicField(this, "EnableLog", false);
|
|
4410
|
-
__publicField(this, "registerStrategies", (...strategys) => {
|
|
4411
|
-
const serverStrategies = StrategyMap.get(this.Name) ?? [];
|
|
4412
|
-
serverStrategies.push(...strategys);
|
|
4413
|
-
StrategyMap.set(this.Name, serverStrategies);
|
|
4414
|
-
});
|
|
4415
|
-
const options = this.getServerOptions();
|
|
4416
|
-
this.Name = options.name ?? this.constructor.name;
|
|
4417
|
-
this.init();
|
|
4418
|
-
}
|
|
4419
|
-
init() {
|
|
4420
|
-
const options = this.getServerOptions();
|
|
4421
|
-
const {
|
|
4422
|
-
baseURL,
|
|
4423
|
-
timeout,
|
|
4424
|
-
cacheManage,
|
|
4425
|
-
enableLog,
|
|
4426
|
-
cacheFor,
|
|
4427
|
-
serverStatusCodeRule
|
|
4428
|
-
} = options;
|
|
4429
|
-
this.BaseURL = baseURL ?? resolveUrl("");
|
|
4430
|
-
this.initAxios({ baseURL, timeout });
|
|
4431
|
-
if (serverStatusCodeRule) {
|
|
4432
|
-
this.initServerStatusCodeRule(serverStatusCodeRule);
|
|
4433
|
-
}
|
|
4434
|
-
this.initStrategy();
|
|
4435
|
-
this.initCacheManage(cacheManage, cacheFor);
|
|
4436
|
-
this.initVersioning();
|
|
4437
|
-
this.initExpireSource(this);
|
|
4438
|
-
this.EnableLog = enableLog ?? false;
|
|
4439
|
-
this.initLog(enableLog);
|
|
4440
|
-
}
|
|
4441
|
-
initServerStatusCodeRule(ruleOptions) {
|
|
4442
|
-
ServerStatusCodeRuleMap.set(this.name, ruleOptions);
|
|
4443
|
-
}
|
|
4444
|
-
initLog(enableLog) {
|
|
4445
|
-
if (enableLog) {
|
|
4446
|
-
const axiosInstance = AxiosInstanceMap.get(this.Name);
|
|
4447
|
-
axiosInstance.interceptors.request.use((config) => {
|
|
4448
|
-
console.log("Request:", config);
|
|
4449
|
-
return config;
|
|
4450
|
-
});
|
|
4451
|
-
axiosInstance.interceptors.response.use((response) => {
|
|
4452
|
-
console.log("Response:", response);
|
|
4453
|
-
return response;
|
|
4454
|
-
});
|
|
4455
|
-
}
|
|
4456
|
-
}
|
|
4457
|
-
initStrategy() {
|
|
4458
|
-
const serverStrategies = Reflect.getMetadata(STRATEGY_KEY, this.constructor) || [];
|
|
4459
|
-
StrategyMap.set(this.Name, serverStrategies);
|
|
4460
|
-
}
|
|
4461
|
-
initVersioning() {
|
|
4462
|
-
const versioning = Reflect.getMetadata(
|
|
4463
|
-
VERSIONING_KEY,
|
|
4464
|
-
this.constructor
|
|
4465
|
-
);
|
|
4466
|
-
if (versioning) {
|
|
4467
|
-
VersioningMap.set(this.Name, versioning);
|
|
4468
|
-
}
|
|
4469
|
-
}
|
|
4470
|
-
createApi(constructor) {
|
|
4471
|
-
const serverVersioning = Reflect.getMetadata(
|
|
4472
|
-
VERSIONING_KEY,
|
|
4473
|
-
this.constructor
|
|
4474
|
-
);
|
|
4475
|
-
if (serverVersioning) {
|
|
4476
|
-
this.Version = serverVersioning.defaultVersion || "";
|
|
4477
|
-
}
|
|
4478
|
-
const apiInstanceOptions = {
|
|
4479
|
-
serverInstance: this,
|
|
4480
|
-
enableLog: this.EnableLog
|
|
4481
|
-
};
|
|
4482
|
-
const apiInstance = new constructor(apiInstanceOptions);
|
|
4483
|
-
this.initExpireSource(apiInstance);
|
|
4484
|
-
return new Proxy(apiInstance, {
|
|
4485
|
-
get: (target, propertyKey) => {
|
|
4486
|
-
if (typeof propertyKey !== "string")
|
|
4487
|
-
return target[propertyKey];
|
|
4488
|
-
const methodConfig = Reflect.getMetadata(
|
|
4489
|
-
METHOD_KEY,
|
|
4490
|
-
target,
|
|
4491
|
-
propertyKey
|
|
4492
|
-
);
|
|
4493
|
-
if (!methodConfig) return target[propertyKey];
|
|
4494
|
-
return () => {
|
|
4495
|
-
const method = new SnailMethod(apiInstance, target, propertyKey);
|
|
4496
|
-
this.initExpireSource(method, propertyKey);
|
|
4497
|
-
return method;
|
|
4498
|
-
};
|
|
4499
|
-
}
|
|
4500
|
-
});
|
|
4501
|
-
}
|
|
4502
|
-
initCacheManage(options, cacheFor) {
|
|
4503
|
-
const noCache = Reflect.getMetadata(
|
|
4504
|
-
NO_CACHE_KEY,
|
|
4505
|
-
this.constructor
|
|
4506
|
-
);
|
|
4507
|
-
if (noCache && options !== defaultCacheManageOptions) {
|
|
4508
|
-
console.warn("you configured cache manage, but you set noCache");
|
|
4509
|
-
return;
|
|
4510
|
-
}
|
|
4511
|
-
const cacheStorage = CacheStorageMap.get(this.Name);
|
|
4512
|
-
if (!cacheStorage && options !== void 0) {
|
|
4513
|
-
const storage = createCache(options);
|
|
4514
|
-
CacheStorageMap.set(this.Name, storage);
|
|
4515
|
-
}
|
|
4516
|
-
if (cacheFor) {
|
|
4517
|
-
if (Array.isArray(cacheFor)) {
|
|
4518
|
-
CacheForMap.set(
|
|
4519
|
-
this.Name,
|
|
4520
|
-
cacheFor.map((method) => method.toLowerCase())
|
|
4521
|
-
);
|
|
4522
|
-
return;
|
|
4523
|
-
}
|
|
4524
|
-
CacheForMap.set(this.Name, [cacheFor.toLowerCase()]);
|
|
4525
|
-
}
|
|
4526
|
-
}
|
|
4527
|
-
initExpireSource(target, propertyKey) {
|
|
4528
|
-
if (propertyKey) {
|
|
4529
|
-
const expireSource = Reflect.getMetadata(
|
|
4530
|
-
CACHE_EXPIRE_SOURCE_KEY,
|
|
4531
|
-
target.target,
|
|
4532
|
-
propertyKey
|
|
4533
|
-
);
|
|
4534
|
-
if (expireSource && expireSource.length > 0) {
|
|
4535
|
-
expireSource.map((source) => {
|
|
4536
|
-
const invalidSources = ExpireSourceMap.get(source) ?? /* @__PURE__ */ new Set();
|
|
4537
|
-
invalidSources.add(target.name);
|
|
4538
|
-
ExpireSourceMap.set(source, invalidSources);
|
|
4539
|
-
});
|
|
4540
|
-
}
|
|
4541
|
-
return;
|
|
4542
|
-
}
|
|
4543
|
-
const expireSources = Reflect.getMetadata(
|
|
4544
|
-
CACHE_EXPIRE_SOURCE_KEY,
|
|
4545
|
-
target.constructor
|
|
4546
|
-
) ?? [];
|
|
4547
|
-
if (expireSources.length > 0) {
|
|
4548
|
-
expireSources.map((source) => {
|
|
4549
|
-
const invalidSources = ExpireSourceMap.get(source) ?? /* @__PURE__ */ new Set();
|
|
4550
|
-
invalidSources.add(target.name);
|
|
4551
|
-
ExpireSourceMap.set(source, invalidSources);
|
|
4552
|
-
});
|
|
4553
|
-
}
|
|
4554
|
-
}
|
|
4555
|
-
initAxios(config) {
|
|
4556
|
-
const axiosInstance = AxiosInstanceMap.get(this.Name);
|
|
4557
|
-
if (!axiosInstance) {
|
|
4558
|
-
const axiosInstance2 = axios.create({
|
|
4559
|
-
baseURL: resolveUrl(config.baseURL),
|
|
4560
|
-
timeout: config.timeout
|
|
4561
|
-
});
|
|
4562
|
-
AxiosInstanceMap.set(this.Name, axiosInstance2);
|
|
4563
|
-
}
|
|
4564
|
-
}
|
|
4565
|
-
getServerOptions() {
|
|
4566
|
-
const serverOptions = Reflect.getMetadata(
|
|
4567
|
-
SERVER_CONFIG_KEY,
|
|
4568
|
-
this.constructor
|
|
4569
|
-
);
|
|
4570
|
-
if (!serverOptions) {
|
|
4571
|
-
throw new Error(
|
|
4572
|
-
"Create SnailServer must be used for @Server() decoration"
|
|
4573
|
-
);
|
|
4574
|
-
}
|
|
4575
|
-
const options = Object.assign({}, defaultServerOptions, serverOptions);
|
|
4576
|
-
return options;
|
|
4577
|
-
}
|
|
4578
|
-
createSse(constructor) {
|
|
4579
|
-
const serverVersioning = Reflect.getMetadata(
|
|
4580
|
-
VERSIONING_KEY,
|
|
4581
|
-
this.constructor
|
|
4582
|
-
);
|
|
4583
|
-
if (serverVersioning) {
|
|
4584
|
-
this.Version = serverVersioning.defaultVersion || "";
|
|
4585
|
-
}
|
|
4586
|
-
const sseInstance = new constructor(this);
|
|
4587
|
-
return sseInstance;
|
|
4588
|
-
}
|
|
4589
|
-
get version() {
|
|
4590
|
-
return this.Version;
|
|
4591
|
-
}
|
|
4592
|
-
get name() {
|
|
4593
|
-
return this.Name;
|
|
4594
|
-
}
|
|
4595
|
-
get enableLog() {
|
|
4596
|
-
return this.EnableLog;
|
|
4597
|
-
}
|
|
4598
|
-
get baseUrl() {
|
|
4599
|
-
return this.BaseURL;
|
|
4600
|
-
}
|
|
4601
|
-
}
|
|
4602
|
-
const API_CONFIG_KEY = Symbol("SNAIL_API_CONFIG_KEY");
|
|
4603
|
-
const Api = (url = "", config) => {
|
|
4604
|
-
return (target) => {
|
|
4605
|
-
Reflect.defineMetadata(API_CONFIG_KEY, { url, ...config }, target);
|
|
4606
|
-
};
|
|
4607
|
-
};
|
|
4608
|
-
class SnailApi {
|
|
4609
|
-
constructor(options) {
|
|
4610
|
-
__publicField(this, "Name");
|
|
4611
|
-
__publicField(this, "serverInstance");
|
|
4612
|
-
__publicField(this, "Version");
|
|
4613
|
-
__publicField(this, "Url");
|
|
4614
|
-
__publicField(this, "Timeout");
|
|
4615
|
-
__publicField(this, "EnableLog");
|
|
4616
|
-
__publicField(this, "registerStrategies", (...strategys) => {
|
|
4617
|
-
const serverStrategies = StrategyMap.get(this.Name) ?? [];
|
|
4618
|
-
serverStrategies.push(...strategys);
|
|
4619
|
-
StrategyMap.set(this.Name, serverStrategies);
|
|
4620
|
-
});
|
|
4621
|
-
const apiConfig = this.getApiConfig();
|
|
4622
|
-
if (!apiConfig) {
|
|
4623
|
-
throw new Error("Create SnailApi must be used for @Api() decoration");
|
|
4624
|
-
}
|
|
4625
|
-
const { serverInstance, enableLog } = options;
|
|
4626
|
-
this.serverInstance = serverInstance;
|
|
4627
|
-
this.EnableLog = enableLog ? true : false;
|
|
4628
|
-
this.init();
|
|
4629
|
-
}
|
|
4630
|
-
init() {
|
|
4631
|
-
const apiConfig = this.getApiConfig();
|
|
4632
|
-
this.initName();
|
|
4633
|
-
this.initStrategy();
|
|
4634
|
-
this.Version = apiConfig.version ?? this.serverInstance.version;
|
|
4635
|
-
this.Url = apiConfig.url;
|
|
4636
|
-
this.Timeout = apiConfig.timeout;
|
|
4637
|
-
}
|
|
4638
|
-
initStrategy() {
|
|
4639
|
-
const serverStrategies = Reflect.getMetadata(STRATEGY_KEY, this.constructor) || [];
|
|
4640
|
-
StrategyMap.set(this.Name, serverStrategies);
|
|
4641
|
-
}
|
|
4642
|
-
initName() {
|
|
4643
|
-
const { name } = this.getApiConfig();
|
|
4644
|
-
const apiName = name ?? this.constructor.name;
|
|
4645
|
-
this.Name = `${this.serverInstance.name}.${apiName}`;
|
|
4646
|
-
}
|
|
4647
|
-
getApiConfig() {
|
|
4648
|
-
return Reflect.getMetadata(
|
|
4649
|
-
API_CONFIG_KEY,
|
|
4650
|
-
this.constructor
|
|
4651
|
-
);
|
|
4652
|
-
}
|
|
4653
|
-
isNoCache() {
|
|
4654
|
-
const isServerNoCache = Reflect.getMetadata(
|
|
4655
|
-
NO_CACHE_KEY,
|
|
4656
|
-
this.serverInstance.constructor
|
|
4657
|
-
);
|
|
4658
|
-
const isApiNoCache = Reflect.getMetadata(
|
|
4659
|
-
NO_CACHE_KEY,
|
|
4660
|
-
this.constructor
|
|
4661
|
-
);
|
|
4662
|
-
return isServerNoCache || isApiNoCache;
|
|
4663
|
-
}
|
|
4664
|
-
get version() {
|
|
4665
|
-
return this.Version;
|
|
4666
|
-
}
|
|
4667
|
-
get url() {
|
|
4668
|
-
return this.Url;
|
|
4669
|
-
}
|
|
4670
|
-
get name() {
|
|
4671
|
-
return this.Name;
|
|
4672
|
-
}
|
|
4673
|
-
get noCache() {
|
|
4674
|
-
return this.isNoCache();
|
|
4675
|
-
}
|
|
4676
|
-
get enableLog() {
|
|
4677
|
-
return this.EnableLog;
|
|
4678
|
-
}
|
|
4679
|
-
get timeout() {
|
|
4680
|
-
return this.Timeout;
|
|
4681
|
-
}
|
|
4682
|
-
}
|
|
4683
|
-
const EVENT_SOURCE_OPTION_KEY = Symbol("SNAIL_EVENT_SOURCE_OPTION_KEY");
|
|
4684
|
-
const Sse = (path, options) => {
|
|
4685
|
-
return (target) => {
|
|
4686
|
-
Reflect.defineMetadata(
|
|
4687
|
-
EVENT_SOURCE_OPTION_KEY,
|
|
4688
|
-
{
|
|
4689
|
-
path,
|
|
4690
|
-
...options
|
|
4691
|
-
},
|
|
4692
|
-
target
|
|
4693
|
-
);
|
|
4694
|
-
};
|
|
4695
|
-
};
|
|
4696
|
-
const EVENT_SOURCE_EVENTS_KEY = Symbol("EVENT_SOURCE_EVENTS_KEY");
|
|
4697
|
-
const SseEvent = (eventName, options) => {
|
|
4698
|
-
return (target, propertyKey) => {
|
|
4699
|
-
console.log("SseEvent:", target.constructor);
|
|
4700
|
-
const events = Reflect.getMetadata(EVENT_SOURCE_EVENTS_KEY, target) || [];
|
|
4701
|
-
events.push({
|
|
4702
|
-
eventName: eventName ? eventName : "message",
|
|
4703
|
-
emit: target[propertyKey],
|
|
4704
|
-
options
|
|
4705
|
-
});
|
|
4706
|
-
Reflect.defineMetadata(EVENT_SOURCE_EVENTS_KEY, events, target.constructor);
|
|
4707
|
-
};
|
|
4708
|
-
};
|
|
4709
|
-
const EVENT_SOURCE_OPEN_KEY = Symbol("EVENT_SOURCE_OPEN_KEY");
|
|
4710
|
-
const OnSseOpen = () => {
|
|
4711
|
-
return (target, propertyKey) => {
|
|
4712
|
-
Reflect.defineMetadata(EVENT_SOURCE_OPEN_KEY, target[propertyKey], target);
|
|
4713
|
-
};
|
|
4714
|
-
};
|
|
4715
|
-
const EVENT_SOURCE_ERROR_KEY = Symbol("EVENT_SOURCE_ERROR_KEY");
|
|
4716
|
-
const OnSseError = () => {
|
|
4717
|
-
return (target, propertyKey) => {
|
|
4718
|
-
Reflect.defineMetadata(EVENT_SOURCE_ERROR_KEY, target[propertyKey], target);
|
|
4719
|
-
};
|
|
4720
|
-
};
|
|
4721
|
-
const defaultSseOptions = {
|
|
4722
|
-
path: "",
|
|
4723
|
-
withCredentials: false
|
|
4724
|
-
};
|
|
4725
|
-
class SnailSse {
|
|
4726
|
-
constructor(server) {
|
|
4727
|
-
__publicField(this, "_serverInstance");
|
|
4728
|
-
__publicField(this, "_baseUrl");
|
|
4729
|
-
__publicField(this, "_url");
|
|
4730
|
-
__publicField(this, "_version");
|
|
4731
|
-
__publicField(this, "_withCredentials");
|
|
4732
|
-
__publicField(this, "_eventSource");
|
|
4733
|
-
__publicField(this, "open", () => {
|
|
4734
|
-
const url = `${this._baseUrl}${this._url}`;
|
|
4735
|
-
const eventSource = new EventSource(url, {
|
|
4736
|
-
withCredentials: this._withCredentials
|
|
4737
|
-
});
|
|
4738
|
-
this._eventSource = eventSource;
|
|
4739
|
-
this.setEvent();
|
|
4740
|
-
this.registerSseEvent();
|
|
4741
|
-
return this._eventSource;
|
|
4742
|
-
});
|
|
4743
|
-
__publicField(this, "close", () => {
|
|
4744
|
-
const eventSource = this.eventSource;
|
|
4745
|
-
if (!eventSource) return;
|
|
4746
|
-
eventSource.close();
|
|
4747
|
-
});
|
|
4748
|
-
__publicField(this, "on", (eventName, callback, options) => {
|
|
4749
|
-
this._eventSource && this._eventSource.addEventListener(eventName, callback, options);
|
|
4750
|
-
});
|
|
4751
|
-
__publicField(this, "off", (eventName, callback, options) => {
|
|
4752
|
-
this._eventSource && this._eventSource.removeEventListener(eventName, callback, options);
|
|
4753
|
-
});
|
|
4754
|
-
this._serverInstance = server;
|
|
4755
|
-
this._baseUrl = server.baseUrl;
|
|
4756
|
-
const options = this.getSseOptions();
|
|
4757
|
-
const { path, withCredentials, version } = options;
|
|
4758
|
-
this._url = resolveUrl(path);
|
|
4759
|
-
this._version = version ?? server.version;
|
|
4760
|
-
this._withCredentials = withCredentials ? withCredentials : false;
|
|
4761
|
-
this.initVersion();
|
|
4762
|
-
}
|
|
4763
|
-
getSseOptions() {
|
|
4764
|
-
const sseOptions = Reflect.getMetadata(
|
|
4765
|
-
EVENT_SOURCE_OPTION_KEY,
|
|
4766
|
-
this.constructor
|
|
4767
|
-
);
|
|
4768
|
-
if (!sseOptions) {
|
|
4769
|
-
throw new Error(
|
|
4770
|
-
"you need to use @Sse() decorator to decorate your class"
|
|
4771
|
-
);
|
|
4772
|
-
}
|
|
4773
|
-
const options = Object.assign({}, defaultSseOptions, sseOptions);
|
|
4774
|
-
return options;
|
|
4775
|
-
}
|
|
4776
|
-
initVersion() {
|
|
4777
|
-
const versioningOptions = VersioningMap.get(this._serverInstance.name);
|
|
4778
|
-
if (!versioningOptions || !this._version) return;
|
|
4779
|
-
const versioningResult = applyVersioning(this._version, versioningOptions);
|
|
4780
|
-
if (!versioningResult) return;
|
|
4781
|
-
const { type, result } = versioningResult;
|
|
4782
|
-
if (type === VersioningType.Uri) {
|
|
4783
|
-
const url = `${resolveUrl(result)}${this._url}`;
|
|
4784
|
-
this._url = url;
|
|
4785
|
-
return;
|
|
4786
|
-
}
|
|
4787
|
-
if (type === VersioningType.Query) {
|
|
4788
|
-
const k = Object.keys(result)[0];
|
|
4789
|
-
const v = result[k];
|
|
4790
|
-
this._url = `resolveUrl(${this._url}?${k}=${v})`;
|
|
4791
|
-
return;
|
|
4792
|
-
}
|
|
4793
|
-
}
|
|
4794
|
-
registerSseEvent() {
|
|
4795
|
-
const eventSource = this._eventSource;
|
|
4796
|
-
if (!eventSource) return;
|
|
4797
|
-
const events = Reflect.getMetadata(
|
|
4798
|
-
EVENT_SOURCE_EVENTS_KEY,
|
|
4799
|
-
this.constructor
|
|
4800
|
-
);
|
|
4801
|
-
if (!events) return;
|
|
4802
|
-
events.map((event) => {
|
|
4803
|
-
eventSource.addEventListener(event.eventName, event.emit, event.options);
|
|
4804
|
-
});
|
|
4805
|
-
}
|
|
4806
|
-
setEvent() {
|
|
4807
|
-
const onOpenFunc = Reflect.getMetadata(
|
|
4808
|
-
EVENT_SOURCE_OPEN_KEY,
|
|
4809
|
-
this.constructor
|
|
4810
|
-
);
|
|
4811
|
-
if (typeof onOpenFunc == "function") {
|
|
4812
|
-
this._eventSource && (this._eventSource.onopen = onOpenFunc);
|
|
4813
|
-
}
|
|
4814
|
-
const onErrorFunc = Reflect.getMetadata(
|
|
4815
|
-
EVENT_SOURCE_ERROR_KEY,
|
|
4816
|
-
this.constructor
|
|
4817
|
-
);
|
|
4818
|
-
if (typeof onErrorFunc == "function") {
|
|
4819
|
-
this._eventSource && (this._eventSource.onerror = onErrorFunc);
|
|
4820
|
-
}
|
|
4821
|
-
}
|
|
4822
|
-
get url() {
|
|
4823
|
-
return `${this._baseUrl}${this._url}`;
|
|
4824
|
-
}
|
|
4825
|
-
get eventSource() {
|
|
4826
|
-
return this._eventSource;
|
|
4827
|
-
}
|
|
4828
|
-
}
|
|
4829
|
-
export {
|
|
4830
|
-
Api,
|
|
4831
|
-
CacheStorageAdapter,
|
|
4832
|
-
CacheType,
|
|
4833
|
-
Data,
|
|
4834
|
-
Delete,
|
|
4835
|
-
Get,
|
|
4836
|
-
Head,
|
|
4837
|
-
HitSource,
|
|
4838
|
-
NoCache,
|
|
4839
|
-
OnSseError,
|
|
4840
|
-
OnSseOpen,
|
|
4841
|
-
Options,
|
|
4842
|
-
Params,
|
|
4843
|
-
Patch,
|
|
4844
|
-
Post,
|
|
4845
|
-
Put,
|
|
4846
|
-
Query,
|
|
4847
|
-
Server,
|
|
4848
|
-
SnailApi,
|
|
4849
|
-
SnailMethod,
|
|
4850
|
-
SnailPass,
|
|
4851
|
-
SnailServer,
|
|
4852
|
-
SnailServerStatusCodeRuleOptions,
|
|
4853
|
-
SnailSse,
|
|
4854
|
-
Sse,
|
|
4855
|
-
SseEvent,
|
|
4856
|
-
SseEventListener,
|
|
4857
|
-
SseOptions,
|
|
4858
|
-
Strategy,
|
|
4859
|
-
UseStrategy,
|
|
4860
|
-
Version,
|
|
4861
|
-
Versioning,
|
|
4862
|
-
VersioningType,
|
|
4863
|
-
applyStrategies,
|
|
4864
|
-
buildRequestArgs,
|
|
4865
|
-
generateCacheKey,
|
|
4866
|
-
generateShortUniqueHash,
|
|
4867
|
-
isSpecialResponse,
|
|
4868
|
-
recordToString,
|
|
4869
|
-
replacePlaceholders,
|
|
4870
|
-
resolveUrl
|
|
4871
|
-
};
|