@snail-js/api 0.1.17 → 0.1.18
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/dist/core/snailApi.d.ts +1 -1
- package/dist/core/snailMethod.d.ts +9 -9
- package/dist/core/snailServer.d.ts +1 -1
- package/dist/snail-api.js +92 -79
- package/dist/snail-api.umd.cjs +92 -79
- package/package.json +1 -1
package/dist/core/snailApi.d.ts
CHANGED
|
@@ -9,7 +9,7 @@ export declare class SnailApi {
|
|
|
9
9
|
constructor(options: ApiInstanceOptions);
|
|
10
10
|
private init;
|
|
11
11
|
private initStrategy;
|
|
12
|
-
registerStrategies(...strategys: Array<new () => Strategy>)
|
|
12
|
+
registerStrategies: (...strategys: Array<new () => Strategy>) => void;
|
|
13
13
|
private initName;
|
|
14
14
|
private getApiConfig;
|
|
15
15
|
private isNoCache;
|
|
@@ -29,14 +29,14 @@ export declare class SnailMethod<RT extends ResponseData = StandardResponseData>
|
|
|
29
29
|
private initVersion;
|
|
30
30
|
private getExpireSources;
|
|
31
31
|
private createRequest;
|
|
32
|
-
onSuccess(handler: EventHandler<RT>)
|
|
33
|
-
onError(handler: EventHandler<RT>)
|
|
34
|
-
onHitCache(handler: EventHandler<RT>)
|
|
35
|
-
onFinish(handler: EventHandler<RT>)
|
|
36
|
-
on(eventName: SnailMethodEventType, handler: EventHandler<RT>)
|
|
37
|
-
once(eventName: SnailMethodEventType, handler: EventHandler<RT>)
|
|
38
|
-
emit(eventName: SnailMethodEventType, ...args: any)
|
|
39
|
-
off(eventName: SnailMethodEventType, handler: EventHandler<RT>)
|
|
32
|
+
onSuccess: (handler: EventHandler<RT>) => void;
|
|
33
|
+
onError: (handler: EventHandler<RT>) => void;
|
|
34
|
+
onHitCache: (handler: EventHandler<RT>) => void;
|
|
35
|
+
onFinish: (handler: EventHandler<RT>) => void;
|
|
36
|
+
on: (eventName: SnailMethodEventType, handler: EventHandler<RT>) => void;
|
|
37
|
+
once: (eventName: SnailMethodEventType, handler: EventHandler<RT>) => void;
|
|
38
|
+
emit: (eventName: SnailMethodEventType, ...args: any) => boolean;
|
|
39
|
+
off: (eventName: SnailMethodEventType, handler: EventHandler<RT>) => void;
|
|
40
40
|
private getCacheData;
|
|
41
41
|
private setCacheData;
|
|
42
42
|
get response(): AxiosResponse<RT, any>;
|
|
@@ -44,7 +44,7 @@ export declare class SnailMethod<RT extends ResponseData = StandardResponseData>
|
|
|
44
44
|
get version(): string | undefined;
|
|
45
45
|
get name(): string;
|
|
46
46
|
get error(): any;
|
|
47
|
-
registerStrategies(...strategys: Array<new () => Strategy>)
|
|
47
|
+
registerStrategies: (...strategys: Array<new () => Strategy>) => void;
|
|
48
48
|
private getStrategies;
|
|
49
49
|
private getMethodOptions;
|
|
50
50
|
private isNoCache;
|
|
@@ -20,7 +20,7 @@ export declare class SnailServer<RT extends ResponseData = StandardResponseData,
|
|
|
20
20
|
private initLog;
|
|
21
21
|
private initStrategy;
|
|
22
22
|
private initVersioning;
|
|
23
|
-
registerStrategies(...strategys: Array<new () => Strategy>)
|
|
23
|
+
registerStrategies: (...strategys: Array<new () => Strategy>) => void;
|
|
24
24
|
createApi<T extends SnailApi>(constructor: new (options: ApiInstanceOptions) => T): ApiProxy<T, RT, DK>;
|
|
25
25
|
private initCacheManage;
|
|
26
26
|
private initExpireSource;
|
package/dist/snail-api.js
CHANGED
|
@@ -1339,6 +1339,21 @@ const noop = () => {
|
|
|
1339
1339
|
const toFiniteNumber = (value, defaultValue) => {
|
|
1340
1340
|
return value != null && Number.isFinite(value = +value) ? value : defaultValue;
|
|
1341
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
|
+
};
|
|
1342
1357
|
function isSpecCompliantForm(thing) {
|
|
1343
1358
|
return !!(thing && isFunction(thing.append) && thing[Symbol.toStringTag] === "FormData" && thing[Symbol.iterator]);
|
|
1344
1359
|
}
|
|
@@ -1437,6 +1452,8 @@ const utils$1 = {
|
|
|
1437
1452
|
findKey,
|
|
1438
1453
|
global: _global,
|
|
1439
1454
|
isContextDefined,
|
|
1455
|
+
ALPHABET,
|
|
1456
|
+
generateString,
|
|
1440
1457
|
isSpecCompliantForm,
|
|
1441
1458
|
toJSONObject,
|
|
1442
1459
|
isAsyncFn,
|
|
@@ -2392,9 +2409,8 @@ function isAbsoluteURL(url) {
|
|
|
2392
2409
|
function combineURLs(baseURL, relativeURL) {
|
|
2393
2410
|
return relativeURL ? baseURL.replace(/\/?\/$/, "") + "/" + relativeURL.replace(/^\/+/, "") : baseURL;
|
|
2394
2411
|
}
|
|
2395
|
-
function buildFullPath(baseURL, requestedURL
|
|
2396
|
-
|
|
2397
|
-
if (baseURL && isRelativeUrl || allowAbsoluteUrls == false) {
|
|
2412
|
+
function buildFullPath(baseURL, requestedURL) {
|
|
2413
|
+
if (baseURL && !isAbsoluteURL(requestedURL)) {
|
|
2398
2414
|
return combineURLs(baseURL, requestedURL);
|
|
2399
2415
|
}
|
|
2400
2416
|
return requestedURL;
|
|
@@ -2481,7 +2497,7 @@ const resolveConfig = (config) => {
|
|
|
2481
2497
|
const newConfig = mergeConfig({}, config);
|
|
2482
2498
|
let { data, withXSRFToken, xsrfHeaderName, xsrfCookieName, headers, auth } = newConfig;
|
|
2483
2499
|
newConfig.headers = headers = AxiosHeaders.from(headers);
|
|
2484
|
-
newConfig.url = buildURL(buildFullPath(newConfig.baseURL, newConfig.url
|
|
2500
|
+
newConfig.url = buildURL(buildFullPath(newConfig.baseURL, newConfig.url), config.params, config.paramsSerializer);
|
|
2485
2501
|
if (auth) {
|
|
2486
2502
|
headers.set(
|
|
2487
2503
|
"Authorization",
|
|
@@ -2998,7 +3014,7 @@ function dispatchRequest(config) {
|
|
|
2998
3014
|
return Promise.reject(reason);
|
|
2999
3015
|
});
|
|
3000
3016
|
}
|
|
3001
|
-
const VERSION = "1.
|
|
3017
|
+
const VERSION = "1.7.9";
|
|
3002
3018
|
const validators$1 = {};
|
|
3003
3019
|
["object", "boolean", "number", "function", "string", "symbol"].forEach((type, i) => {
|
|
3004
3020
|
validators$1[type] = function validator2(thing) {
|
|
@@ -3126,12 +3142,6 @@ class Axios {
|
|
|
3126
3142
|
}, true);
|
|
3127
3143
|
}
|
|
3128
3144
|
}
|
|
3129
|
-
if (config.allowAbsoluteUrls !== void 0) ;
|
|
3130
|
-
else if (this.defaults.allowAbsoluteUrls !== void 0) {
|
|
3131
|
-
config.allowAbsoluteUrls = this.defaults.allowAbsoluteUrls;
|
|
3132
|
-
} else {
|
|
3133
|
-
config.allowAbsoluteUrls = true;
|
|
3134
|
-
}
|
|
3135
3145
|
validator.assertOptions(config, {
|
|
3136
3146
|
baseUrl: validators.spelling("baseURL"),
|
|
3137
3147
|
withXsrfToken: validators.spelling("withXSRFToken")
|
|
@@ -3202,7 +3212,7 @@ class Axios {
|
|
|
3202
3212
|
}
|
|
3203
3213
|
getUri(config) {
|
|
3204
3214
|
config = mergeConfig(this.defaults, config);
|
|
3205
|
-
const fullPath = buildFullPath(config.baseURL, config.url
|
|
3215
|
+
const fullPath = buildFullPath(config.baseURL, config.url);
|
|
3206
3216
|
return buildURL(fullPath, config.params, config.paramsSerializer);
|
|
3207
3217
|
}
|
|
3208
3218
|
}
|
|
@@ -3870,8 +3880,9 @@ const buildRequestArgs = (target, propertyKey, args) => {
|
|
|
3870
3880
|
return requestArgs;
|
|
3871
3881
|
};
|
|
3872
3882
|
function isSpecialResponse(response) {
|
|
3873
|
-
const contentType = response.headers["
|
|
3874
|
-
|
|
3883
|
+
const contentType = response.headers["Content-Type"];
|
|
3884
|
+
if (!contentType) return false;
|
|
3885
|
+
return !contentType.includes("application/json");
|
|
3875
3886
|
}
|
|
3876
3887
|
const METHOD_KEY = Symbol("SNAIL_METHOD_KEY");
|
|
3877
3888
|
const API_CONFIG_KEY = Symbol("SNAIL_API_CONFIG_KEY");
|
|
@@ -4074,7 +4085,9 @@ class SnailMethod {
|
|
|
4074
4085
|
this.applyHitSource(serverName);
|
|
4075
4086
|
this.emit("success", response.data);
|
|
4076
4087
|
this.emit("finish", response.data);
|
|
4088
|
+
isSpecial && console.log("isSpecial:", isSpecial);
|
|
4077
4089
|
if (isSpecial) return response;
|
|
4090
|
+
!isSpecial && console.log("isSpecial:", isSpecial);
|
|
4078
4091
|
return response.data;
|
|
4079
4092
|
} catch (error) {
|
|
4080
4093
|
this.emit("error", error);
|
|
@@ -4084,6 +4097,61 @@ class SnailMethod {
|
|
|
4084
4097
|
return error;
|
|
4085
4098
|
}
|
|
4086
4099
|
});
|
|
4100
|
+
__publicField(this, "onSuccess", (handler) => {
|
|
4101
|
+
this.on("success", handler);
|
|
4102
|
+
});
|
|
4103
|
+
__publicField(this, "onError", (handler) => {
|
|
4104
|
+
this.on("error", handler);
|
|
4105
|
+
});
|
|
4106
|
+
__publicField(this, "onHitCache", (handler) => {
|
|
4107
|
+
this.on("hitCache", handler);
|
|
4108
|
+
});
|
|
4109
|
+
__publicField(this, "onFinish", (handler) => {
|
|
4110
|
+
this.on("finish", handler);
|
|
4111
|
+
});
|
|
4112
|
+
__publicField(this, "on", (eventName, handler) => {
|
|
4113
|
+
if (typeof handler !== "function") {
|
|
4114
|
+
throw new TypeError("Handler must be a function");
|
|
4115
|
+
}
|
|
4116
|
+
const handlers = this.eventMap.get(eventName) || /* @__PURE__ */ new Set();
|
|
4117
|
+
handlers.add(handler);
|
|
4118
|
+
this.eventMap.set(eventName, handlers);
|
|
4119
|
+
});
|
|
4120
|
+
__publicField(this, "once", (eventName, handler) => {
|
|
4121
|
+
const onceHandler = (data) => {
|
|
4122
|
+
try {
|
|
4123
|
+
handler.apply(this, [data]);
|
|
4124
|
+
} finally {
|
|
4125
|
+
this.off(eventName, onceHandler);
|
|
4126
|
+
this.onceWrapperMap.delete(handler);
|
|
4127
|
+
}
|
|
4128
|
+
};
|
|
4129
|
+
this.onceWrapperMap.set(handler, onceHandler);
|
|
4130
|
+
this.on(eventName, onceHandler);
|
|
4131
|
+
});
|
|
4132
|
+
__publicField(this, "emit", (eventName, ...args) => {
|
|
4133
|
+
const handlers = this.eventMap.get(eventName);
|
|
4134
|
+
if (!handlers || handlers.size === 0) return false;
|
|
4135
|
+
handlers.forEach((handler) => {
|
|
4136
|
+
Promise.resolve().then(() => {
|
|
4137
|
+
handler.apply(this, args);
|
|
4138
|
+
});
|
|
4139
|
+
});
|
|
4140
|
+
return true;
|
|
4141
|
+
});
|
|
4142
|
+
__publicField(this, "off", (eventName, handler) => {
|
|
4143
|
+
const handlers = this.eventMap.get(eventName);
|
|
4144
|
+
if (!handlers) return;
|
|
4145
|
+
if (handlers.has(handler)) {
|
|
4146
|
+
handlers.delete(handler);
|
|
4147
|
+
}
|
|
4148
|
+
if (handlers.size === 0) {
|
|
4149
|
+
this.eventMap.delete(eventName);
|
|
4150
|
+
}
|
|
4151
|
+
});
|
|
4152
|
+
__publicField(this, "registerStrategies", (...strategys) => {
|
|
4153
|
+
this.strategies.push(...strategys);
|
|
4154
|
+
});
|
|
4087
4155
|
this.apiInstance = apiInstance;
|
|
4088
4156
|
this.target = target;
|
|
4089
4157
|
this.propertyKey = propertyKey.toString();
|
|
@@ -4170,58 +4238,6 @@ class SnailMethod {
|
|
|
4170
4238
|
this.Request = request;
|
|
4171
4239
|
return request;
|
|
4172
4240
|
}
|
|
4173
|
-
onSuccess(handler) {
|
|
4174
|
-
this.on("success", handler);
|
|
4175
|
-
}
|
|
4176
|
-
onError(handler) {
|
|
4177
|
-
this.on("error", handler);
|
|
4178
|
-
}
|
|
4179
|
-
onHitCache(handler) {
|
|
4180
|
-
this.on("hitCache", handler);
|
|
4181
|
-
}
|
|
4182
|
-
onFinish(handler) {
|
|
4183
|
-
this.on("finish", handler);
|
|
4184
|
-
}
|
|
4185
|
-
on(eventName, handler) {
|
|
4186
|
-
if (typeof handler !== "function") {
|
|
4187
|
-
throw new TypeError("Handler must be a function");
|
|
4188
|
-
}
|
|
4189
|
-
const handlers = this.eventMap.get(eventName) || /* @__PURE__ */ new Set();
|
|
4190
|
-
handlers.add(handler);
|
|
4191
|
-
this.eventMap.set(eventName, handlers);
|
|
4192
|
-
}
|
|
4193
|
-
once(eventName, handler) {
|
|
4194
|
-
const onceHandler = (data) => {
|
|
4195
|
-
try {
|
|
4196
|
-
handler.apply(this, [data]);
|
|
4197
|
-
} finally {
|
|
4198
|
-
this.off(eventName, onceHandler);
|
|
4199
|
-
this.onceWrapperMap.delete(handler);
|
|
4200
|
-
}
|
|
4201
|
-
};
|
|
4202
|
-
this.onceWrapperMap.set(handler, onceHandler);
|
|
4203
|
-
this.on(eventName, onceHandler);
|
|
4204
|
-
}
|
|
4205
|
-
emit(eventName, ...args) {
|
|
4206
|
-
const handlers = this.eventMap.get(eventName);
|
|
4207
|
-
if (!handlers || handlers.size === 0) return false;
|
|
4208
|
-
handlers.forEach((handler) => {
|
|
4209
|
-
Promise.resolve().then(() => {
|
|
4210
|
-
handler.apply(this, args);
|
|
4211
|
-
});
|
|
4212
|
-
});
|
|
4213
|
-
return true;
|
|
4214
|
-
}
|
|
4215
|
-
off(eventName, handler) {
|
|
4216
|
-
const handlers = this.eventMap.get(eventName);
|
|
4217
|
-
if (!handlers) return;
|
|
4218
|
-
if (handlers.has(handler)) {
|
|
4219
|
-
handlers.delete(handler);
|
|
4220
|
-
}
|
|
4221
|
-
if (handlers.size === 0) {
|
|
4222
|
-
this.eventMap.delete(eventName);
|
|
4223
|
-
}
|
|
4224
|
-
}
|
|
4225
4241
|
async getCacheData(serverName) {
|
|
4226
4242
|
const methodKey = await generateCacheKey(
|
|
4227
4243
|
this.name,
|
|
@@ -4271,9 +4287,6 @@ class SnailMethod {
|
|
|
4271
4287
|
if (this.Error) return this.Error;
|
|
4272
4288
|
return null;
|
|
4273
4289
|
}
|
|
4274
|
-
registerStrategies(...strategys) {
|
|
4275
|
-
this.strategies.push(...strategys);
|
|
4276
|
-
}
|
|
4277
4290
|
getStrategies() {
|
|
4278
4291
|
const [serverName, apiName] = this.apiInstance.name.split(".");
|
|
4279
4292
|
const serverStrategies = StrategyMap.get(serverName) ?? [];
|
|
@@ -4376,6 +4389,11 @@ class SnailServer {
|
|
|
4376
4389
|
__publicField(this, "BaseURL");
|
|
4377
4390
|
__publicField(this, "Version");
|
|
4378
4391
|
__publicField(this, "EnableLog", false);
|
|
4392
|
+
__publicField(this, "registerStrategies", (...strategys) => {
|
|
4393
|
+
const serverStrategies = StrategyMap.get(this.Name) ?? [];
|
|
4394
|
+
serverStrategies.push(...strategys);
|
|
4395
|
+
StrategyMap.set(this.Name, serverStrategies);
|
|
4396
|
+
});
|
|
4379
4397
|
const options = this.getServerOptions();
|
|
4380
4398
|
this.Name = options.name ?? this.constructor.name;
|
|
4381
4399
|
this.init();
|
|
@@ -4418,11 +4436,6 @@ class SnailServer {
|
|
|
4418
4436
|
VersioningMap.set(this.Name, versioning);
|
|
4419
4437
|
}
|
|
4420
4438
|
}
|
|
4421
|
-
registerStrategies(...strategys) {
|
|
4422
|
-
const serverStrategies = StrategyMap.get(this.Name) ?? [];
|
|
4423
|
-
serverStrategies.push(...strategys);
|
|
4424
|
-
StrategyMap.set(this.Name, serverStrategies);
|
|
4425
|
-
}
|
|
4426
4439
|
createApi(constructor) {
|
|
4427
4440
|
const serverVersioning = Reflect.getMetadata(
|
|
4428
4441
|
VERSIONING_KEY,
|
|
@@ -4552,6 +4565,11 @@ class SnailApi {
|
|
|
4552
4565
|
__publicField(this, "Url");
|
|
4553
4566
|
__publicField(this, "Timeout");
|
|
4554
4567
|
__publicField(this, "EnableLog");
|
|
4568
|
+
__publicField(this, "registerStrategies", (...strategys) => {
|
|
4569
|
+
const serverStrategies = StrategyMap.get(this.Name) ?? [];
|
|
4570
|
+
serverStrategies.push(...strategys);
|
|
4571
|
+
StrategyMap.set(this.Name, serverStrategies);
|
|
4572
|
+
});
|
|
4555
4573
|
const apiConfig = this.getApiConfig();
|
|
4556
4574
|
if (!apiConfig) {
|
|
4557
4575
|
throw new Error("Create SnailApi must be used for @Api() decoration");
|
|
@@ -4573,11 +4591,6 @@ class SnailApi {
|
|
|
4573
4591
|
const serverStrategies = Reflect.getMetadata(STRATEGY_KEY, this.constructor) || [];
|
|
4574
4592
|
StrategyMap.set(this.Name, serverStrategies);
|
|
4575
4593
|
}
|
|
4576
|
-
registerStrategies(...strategys) {
|
|
4577
|
-
const serverStrategies = StrategyMap.get(this.Name) ?? [];
|
|
4578
|
-
serverStrategies.push(...strategys);
|
|
4579
|
-
StrategyMap.set(this.Name, serverStrategies);
|
|
4580
|
-
}
|
|
4581
4594
|
initName() {
|
|
4582
4595
|
const { name } = this.getApiConfig();
|
|
4583
4596
|
const apiName = name ?? this.constructor.name;
|
package/dist/snail-api.umd.cjs
CHANGED
|
@@ -1343,6 +1343,21 @@ var __publicField = (obj, key, value) => __defNormalProp(obj, typeof key !== "sy
|
|
|
1343
1343
|
const toFiniteNumber = (value, defaultValue) => {
|
|
1344
1344
|
return value != null && Number.isFinite(value = +value) ? value : defaultValue;
|
|
1345
1345
|
};
|
|
1346
|
+
const ALPHA = "abcdefghijklmnopqrstuvwxyz";
|
|
1347
|
+
const DIGIT = "0123456789";
|
|
1348
|
+
const ALPHABET = {
|
|
1349
|
+
DIGIT,
|
|
1350
|
+
ALPHA,
|
|
1351
|
+
ALPHA_DIGIT: ALPHA + ALPHA.toUpperCase() + DIGIT
|
|
1352
|
+
};
|
|
1353
|
+
const generateString = (size = 16, alphabet = ALPHABET.ALPHA_DIGIT) => {
|
|
1354
|
+
let str = "";
|
|
1355
|
+
const { length } = alphabet;
|
|
1356
|
+
while (size--) {
|
|
1357
|
+
str += alphabet[Math.random() * length | 0];
|
|
1358
|
+
}
|
|
1359
|
+
return str;
|
|
1360
|
+
};
|
|
1346
1361
|
function isSpecCompliantForm(thing) {
|
|
1347
1362
|
return !!(thing && isFunction(thing.append) && thing[Symbol.toStringTag] === "FormData" && thing[Symbol.iterator]);
|
|
1348
1363
|
}
|
|
@@ -1441,6 +1456,8 @@ var __publicField = (obj, key, value) => __defNormalProp(obj, typeof key !== "sy
|
|
|
1441
1456
|
findKey,
|
|
1442
1457
|
global: _global,
|
|
1443
1458
|
isContextDefined,
|
|
1459
|
+
ALPHABET,
|
|
1460
|
+
generateString,
|
|
1444
1461
|
isSpecCompliantForm,
|
|
1445
1462
|
toJSONObject,
|
|
1446
1463
|
isAsyncFn,
|
|
@@ -2396,9 +2413,8 @@ var __publicField = (obj, key, value) => __defNormalProp(obj, typeof key !== "sy
|
|
|
2396
2413
|
function combineURLs(baseURL, relativeURL) {
|
|
2397
2414
|
return relativeURL ? baseURL.replace(/\/?\/$/, "") + "/" + relativeURL.replace(/^\/+/, "") : baseURL;
|
|
2398
2415
|
}
|
|
2399
|
-
function buildFullPath(baseURL, requestedURL
|
|
2400
|
-
|
|
2401
|
-
if (baseURL && isRelativeUrl || allowAbsoluteUrls == false) {
|
|
2416
|
+
function buildFullPath(baseURL, requestedURL) {
|
|
2417
|
+
if (baseURL && !isAbsoluteURL(requestedURL)) {
|
|
2402
2418
|
return combineURLs(baseURL, requestedURL);
|
|
2403
2419
|
}
|
|
2404
2420
|
return requestedURL;
|
|
@@ -2485,7 +2501,7 @@ var __publicField = (obj, key, value) => __defNormalProp(obj, typeof key !== "sy
|
|
|
2485
2501
|
const newConfig = mergeConfig({}, config);
|
|
2486
2502
|
let { data, withXSRFToken, xsrfHeaderName, xsrfCookieName, headers, auth } = newConfig;
|
|
2487
2503
|
newConfig.headers = headers = AxiosHeaders.from(headers);
|
|
2488
|
-
newConfig.url = buildURL(buildFullPath(newConfig.baseURL, newConfig.url
|
|
2504
|
+
newConfig.url = buildURL(buildFullPath(newConfig.baseURL, newConfig.url), config.params, config.paramsSerializer);
|
|
2489
2505
|
if (auth) {
|
|
2490
2506
|
headers.set(
|
|
2491
2507
|
"Authorization",
|
|
@@ -3002,7 +3018,7 @@ var __publicField = (obj, key, value) => __defNormalProp(obj, typeof key !== "sy
|
|
|
3002
3018
|
return Promise.reject(reason);
|
|
3003
3019
|
});
|
|
3004
3020
|
}
|
|
3005
|
-
const VERSION = "1.
|
|
3021
|
+
const VERSION = "1.7.9";
|
|
3006
3022
|
const validators$1 = {};
|
|
3007
3023
|
["object", "boolean", "number", "function", "string", "symbol"].forEach((type, i) => {
|
|
3008
3024
|
validators$1[type] = function validator2(thing) {
|
|
@@ -3130,12 +3146,6 @@ var __publicField = (obj, key, value) => __defNormalProp(obj, typeof key !== "sy
|
|
|
3130
3146
|
}, true);
|
|
3131
3147
|
}
|
|
3132
3148
|
}
|
|
3133
|
-
if (config.allowAbsoluteUrls !== void 0) ;
|
|
3134
|
-
else if (this.defaults.allowAbsoluteUrls !== void 0) {
|
|
3135
|
-
config.allowAbsoluteUrls = this.defaults.allowAbsoluteUrls;
|
|
3136
|
-
} else {
|
|
3137
|
-
config.allowAbsoluteUrls = true;
|
|
3138
|
-
}
|
|
3139
3149
|
validator.assertOptions(config, {
|
|
3140
3150
|
baseUrl: validators.spelling("baseURL"),
|
|
3141
3151
|
withXsrfToken: validators.spelling("withXSRFToken")
|
|
@@ -3206,7 +3216,7 @@ var __publicField = (obj, key, value) => __defNormalProp(obj, typeof key !== "sy
|
|
|
3206
3216
|
}
|
|
3207
3217
|
getUri(config) {
|
|
3208
3218
|
config = mergeConfig(this.defaults, config);
|
|
3209
|
-
const fullPath = buildFullPath(config.baseURL, config.url
|
|
3219
|
+
const fullPath = buildFullPath(config.baseURL, config.url);
|
|
3210
3220
|
return buildURL(fullPath, config.params, config.paramsSerializer);
|
|
3211
3221
|
}
|
|
3212
3222
|
}
|
|
@@ -3874,8 +3884,9 @@ var __publicField = (obj, key, value) => __defNormalProp(obj, typeof key !== "sy
|
|
|
3874
3884
|
return requestArgs;
|
|
3875
3885
|
};
|
|
3876
3886
|
function isSpecialResponse(response) {
|
|
3877
|
-
const contentType = response.headers["
|
|
3878
|
-
|
|
3887
|
+
const contentType = response.headers["Content-Type"];
|
|
3888
|
+
if (!contentType) return false;
|
|
3889
|
+
return !contentType.includes("application/json");
|
|
3879
3890
|
}
|
|
3880
3891
|
const METHOD_KEY = Symbol("SNAIL_METHOD_KEY");
|
|
3881
3892
|
const API_CONFIG_KEY = Symbol("SNAIL_API_CONFIG_KEY");
|
|
@@ -4078,7 +4089,9 @@ var __publicField = (obj, key, value) => __defNormalProp(obj, typeof key !== "sy
|
|
|
4078
4089
|
this.applyHitSource(serverName);
|
|
4079
4090
|
this.emit("success", response.data);
|
|
4080
4091
|
this.emit("finish", response.data);
|
|
4092
|
+
isSpecial && console.log("isSpecial:", isSpecial);
|
|
4081
4093
|
if (isSpecial) return response;
|
|
4094
|
+
!isSpecial && console.log("isSpecial:", isSpecial);
|
|
4082
4095
|
return response.data;
|
|
4083
4096
|
} catch (error) {
|
|
4084
4097
|
this.emit("error", error);
|
|
@@ -4088,6 +4101,61 @@ var __publicField = (obj, key, value) => __defNormalProp(obj, typeof key !== "sy
|
|
|
4088
4101
|
return error;
|
|
4089
4102
|
}
|
|
4090
4103
|
});
|
|
4104
|
+
__publicField(this, "onSuccess", (handler) => {
|
|
4105
|
+
this.on("success", handler);
|
|
4106
|
+
});
|
|
4107
|
+
__publicField(this, "onError", (handler) => {
|
|
4108
|
+
this.on("error", handler);
|
|
4109
|
+
});
|
|
4110
|
+
__publicField(this, "onHitCache", (handler) => {
|
|
4111
|
+
this.on("hitCache", handler);
|
|
4112
|
+
});
|
|
4113
|
+
__publicField(this, "onFinish", (handler) => {
|
|
4114
|
+
this.on("finish", handler);
|
|
4115
|
+
});
|
|
4116
|
+
__publicField(this, "on", (eventName, handler) => {
|
|
4117
|
+
if (typeof handler !== "function") {
|
|
4118
|
+
throw new TypeError("Handler must be a function");
|
|
4119
|
+
}
|
|
4120
|
+
const handlers = this.eventMap.get(eventName) || /* @__PURE__ */ new Set();
|
|
4121
|
+
handlers.add(handler);
|
|
4122
|
+
this.eventMap.set(eventName, handlers);
|
|
4123
|
+
});
|
|
4124
|
+
__publicField(this, "once", (eventName, handler) => {
|
|
4125
|
+
const onceHandler = (data) => {
|
|
4126
|
+
try {
|
|
4127
|
+
handler.apply(this, [data]);
|
|
4128
|
+
} finally {
|
|
4129
|
+
this.off(eventName, onceHandler);
|
|
4130
|
+
this.onceWrapperMap.delete(handler);
|
|
4131
|
+
}
|
|
4132
|
+
};
|
|
4133
|
+
this.onceWrapperMap.set(handler, onceHandler);
|
|
4134
|
+
this.on(eventName, onceHandler);
|
|
4135
|
+
});
|
|
4136
|
+
__publicField(this, "emit", (eventName, ...args) => {
|
|
4137
|
+
const handlers = this.eventMap.get(eventName);
|
|
4138
|
+
if (!handlers || handlers.size === 0) return false;
|
|
4139
|
+
handlers.forEach((handler) => {
|
|
4140
|
+
Promise.resolve().then(() => {
|
|
4141
|
+
handler.apply(this, args);
|
|
4142
|
+
});
|
|
4143
|
+
});
|
|
4144
|
+
return true;
|
|
4145
|
+
});
|
|
4146
|
+
__publicField(this, "off", (eventName, handler) => {
|
|
4147
|
+
const handlers = this.eventMap.get(eventName);
|
|
4148
|
+
if (!handlers) return;
|
|
4149
|
+
if (handlers.has(handler)) {
|
|
4150
|
+
handlers.delete(handler);
|
|
4151
|
+
}
|
|
4152
|
+
if (handlers.size === 0) {
|
|
4153
|
+
this.eventMap.delete(eventName);
|
|
4154
|
+
}
|
|
4155
|
+
});
|
|
4156
|
+
__publicField(this, "registerStrategies", (...strategys) => {
|
|
4157
|
+
this.strategies.push(...strategys);
|
|
4158
|
+
});
|
|
4091
4159
|
this.apiInstance = apiInstance;
|
|
4092
4160
|
this.target = target;
|
|
4093
4161
|
this.propertyKey = propertyKey.toString();
|
|
@@ -4174,58 +4242,6 @@ var __publicField = (obj, key, value) => __defNormalProp(obj, typeof key !== "sy
|
|
|
4174
4242
|
this.Request = request;
|
|
4175
4243
|
return request;
|
|
4176
4244
|
}
|
|
4177
|
-
onSuccess(handler) {
|
|
4178
|
-
this.on("success", handler);
|
|
4179
|
-
}
|
|
4180
|
-
onError(handler) {
|
|
4181
|
-
this.on("error", handler);
|
|
4182
|
-
}
|
|
4183
|
-
onHitCache(handler) {
|
|
4184
|
-
this.on("hitCache", handler);
|
|
4185
|
-
}
|
|
4186
|
-
onFinish(handler) {
|
|
4187
|
-
this.on("finish", handler);
|
|
4188
|
-
}
|
|
4189
|
-
on(eventName, handler) {
|
|
4190
|
-
if (typeof handler !== "function") {
|
|
4191
|
-
throw new TypeError("Handler must be a function");
|
|
4192
|
-
}
|
|
4193
|
-
const handlers = this.eventMap.get(eventName) || /* @__PURE__ */ new Set();
|
|
4194
|
-
handlers.add(handler);
|
|
4195
|
-
this.eventMap.set(eventName, handlers);
|
|
4196
|
-
}
|
|
4197
|
-
once(eventName, handler) {
|
|
4198
|
-
const onceHandler = (data) => {
|
|
4199
|
-
try {
|
|
4200
|
-
handler.apply(this, [data]);
|
|
4201
|
-
} finally {
|
|
4202
|
-
this.off(eventName, onceHandler);
|
|
4203
|
-
this.onceWrapperMap.delete(handler);
|
|
4204
|
-
}
|
|
4205
|
-
};
|
|
4206
|
-
this.onceWrapperMap.set(handler, onceHandler);
|
|
4207
|
-
this.on(eventName, onceHandler);
|
|
4208
|
-
}
|
|
4209
|
-
emit(eventName, ...args) {
|
|
4210
|
-
const handlers = this.eventMap.get(eventName);
|
|
4211
|
-
if (!handlers || handlers.size === 0) return false;
|
|
4212
|
-
handlers.forEach((handler) => {
|
|
4213
|
-
Promise.resolve().then(() => {
|
|
4214
|
-
handler.apply(this, args);
|
|
4215
|
-
});
|
|
4216
|
-
});
|
|
4217
|
-
return true;
|
|
4218
|
-
}
|
|
4219
|
-
off(eventName, handler) {
|
|
4220
|
-
const handlers = this.eventMap.get(eventName);
|
|
4221
|
-
if (!handlers) return;
|
|
4222
|
-
if (handlers.has(handler)) {
|
|
4223
|
-
handlers.delete(handler);
|
|
4224
|
-
}
|
|
4225
|
-
if (handlers.size === 0) {
|
|
4226
|
-
this.eventMap.delete(eventName);
|
|
4227
|
-
}
|
|
4228
|
-
}
|
|
4229
4245
|
async getCacheData(serverName) {
|
|
4230
4246
|
const methodKey = await generateCacheKey(
|
|
4231
4247
|
this.name,
|
|
@@ -4275,9 +4291,6 @@ var __publicField = (obj, key, value) => __defNormalProp(obj, typeof key !== "sy
|
|
|
4275
4291
|
if (this.Error) return this.Error;
|
|
4276
4292
|
return null;
|
|
4277
4293
|
}
|
|
4278
|
-
registerStrategies(...strategys) {
|
|
4279
|
-
this.strategies.push(...strategys);
|
|
4280
|
-
}
|
|
4281
4294
|
getStrategies() {
|
|
4282
4295
|
const [serverName, apiName] = this.apiInstance.name.split(".");
|
|
4283
4296
|
const serverStrategies = StrategyMap.get(serverName) ?? [];
|
|
@@ -4380,6 +4393,11 @@ var __publicField = (obj, key, value) => __defNormalProp(obj, typeof key !== "sy
|
|
|
4380
4393
|
__publicField(this, "BaseURL");
|
|
4381
4394
|
__publicField(this, "Version");
|
|
4382
4395
|
__publicField(this, "EnableLog", false);
|
|
4396
|
+
__publicField(this, "registerStrategies", (...strategys) => {
|
|
4397
|
+
const serverStrategies = StrategyMap.get(this.Name) ?? [];
|
|
4398
|
+
serverStrategies.push(...strategys);
|
|
4399
|
+
StrategyMap.set(this.Name, serverStrategies);
|
|
4400
|
+
});
|
|
4383
4401
|
const options = this.getServerOptions();
|
|
4384
4402
|
this.Name = options.name ?? this.constructor.name;
|
|
4385
4403
|
this.init();
|
|
@@ -4422,11 +4440,6 @@ var __publicField = (obj, key, value) => __defNormalProp(obj, typeof key !== "sy
|
|
|
4422
4440
|
VersioningMap.set(this.Name, versioning);
|
|
4423
4441
|
}
|
|
4424
4442
|
}
|
|
4425
|
-
registerStrategies(...strategys) {
|
|
4426
|
-
const serverStrategies = StrategyMap.get(this.Name) ?? [];
|
|
4427
|
-
serverStrategies.push(...strategys);
|
|
4428
|
-
StrategyMap.set(this.Name, serverStrategies);
|
|
4429
|
-
}
|
|
4430
4443
|
createApi(constructor) {
|
|
4431
4444
|
const serverVersioning = Reflect.getMetadata(
|
|
4432
4445
|
VERSIONING_KEY,
|
|
@@ -4556,6 +4569,11 @@ var __publicField = (obj, key, value) => __defNormalProp(obj, typeof key !== "sy
|
|
|
4556
4569
|
__publicField(this, "Url");
|
|
4557
4570
|
__publicField(this, "Timeout");
|
|
4558
4571
|
__publicField(this, "EnableLog");
|
|
4572
|
+
__publicField(this, "registerStrategies", (...strategys) => {
|
|
4573
|
+
const serverStrategies = StrategyMap.get(this.Name) ?? [];
|
|
4574
|
+
serverStrategies.push(...strategys);
|
|
4575
|
+
StrategyMap.set(this.Name, serverStrategies);
|
|
4576
|
+
});
|
|
4559
4577
|
const apiConfig = this.getApiConfig();
|
|
4560
4578
|
if (!apiConfig) {
|
|
4561
4579
|
throw new Error("Create SnailApi must be used for @Api() decoration");
|
|
@@ -4577,11 +4595,6 @@ var __publicField = (obj, key, value) => __defNormalProp(obj, typeof key !== "sy
|
|
|
4577
4595
|
const serverStrategies = Reflect.getMetadata(STRATEGY_KEY, this.constructor) || [];
|
|
4578
4596
|
StrategyMap.set(this.Name, serverStrategies);
|
|
4579
4597
|
}
|
|
4580
|
-
registerStrategies(...strategys) {
|
|
4581
|
-
const serverStrategies = StrategyMap.get(this.Name) ?? [];
|
|
4582
|
-
serverStrategies.push(...strategys);
|
|
4583
|
-
StrategyMap.set(this.Name, serverStrategies);
|
|
4584
|
-
}
|
|
4585
4598
|
initName() {
|
|
4586
4599
|
const { name } = this.getApiConfig();
|
|
4587
4600
|
const apiName = name ?? this.constructor.name;
|