@snail-js/api 0.1.15 → 0.1.17

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
package/README.md CHANGED
@@ -4,7 +4,7 @@
4
4
  <img src="https://img.shields.io/npm/v/reflect-metadata?label=reflect-metadata&labelColor=1e80ff&color=67C23A"></img>
5
5
  </p>
6
6
 
7
- 中文文档|<a href='./README_EN.md'>English Document</a>
7
+ 中文文档|<a href='https://github.com/limingchang/snail/blob/master/packages/api/README_EN.md'>English Document</a>
8
8
 
9
9
  ## 项目介绍
10
10
 
@@ -1,12 +1,12 @@
1
1
  import { AxiosResponse, AxiosRequestConfig } from "axios";
2
- import { EventHandler, Strategy, ResponseData, SendRequest, StandardResponseData, ResponseJsonData, SnailMethodEventType } from "../typings";
2
+ import { EventHandler, Strategy, ResponseData, SendRequest, StandardResponseData, SnailMethodEventType } from "../typings";
3
3
  import { SnailApi } from "./snailApi";
4
4
  /**
5
5
  * SnailMethod
6
6
  * 泛型参数: RT => response.data类型,默认标准json返回
7
7
  * DK => response.data.data 类型
8
8
  */
9
- export declare class SnailMethod<RT extends ResponseData = StandardResponseData<ResponseJsonData>> {
9
+ export declare class SnailMethod<RT extends ResponseData = StandardResponseData> {
10
10
  private Name;
11
11
  private apiInstance;
12
12
  private target;
@@ -1,6 +1,6 @@
1
1
  import "reflect-metadata";
2
2
  import { AxiosInstance } from "axios";
3
- import { Strategy, ApiInstanceOptions, VersioningOption, CacheStorage, ApiProxy, ResponseData, StandardResponseData, ResponseJsonData, CacheForType } from "../typings";
3
+ import { Strategy, ApiInstanceOptions, VersioningOption, CacheStorage, ApiProxy, ResponseData, StandardResponseData, CacheForType } from "../typings";
4
4
  import { SnailApi } from "./snailApi";
5
5
  import { SnailSse } from "./snailSse";
6
6
  export declare const CacheStorageMap: Map<string, CacheStorage>;
@@ -10,7 +10,7 @@ export declare const ExpireSourceMap: Map<string, Set<string>>;
10
10
  export declare const AxiosInstanceMap: Map<string, AxiosInstance>;
11
11
  export declare const StrategyMap: Map<string, (new () => Strategy)[]>;
12
12
  export declare const VersioningMap: Map<string, VersioningOption>;
13
- export declare class SnailServer<RT extends ResponseData = StandardResponseData<ResponseJsonData>, DK extends string = "data"> {
13
+ export declare class SnailServer<RT extends ResponseData = StandardResponseData, DK extends string = "data"> {
14
14
  private Name;
15
15
  private BaseURL;
16
16
  private Version;
package/dist/snail-api.js CHANGED
@@ -1339,21 +1339,6 @@ 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
- };
1357
1342
  function isSpecCompliantForm(thing) {
1358
1343
  return !!(thing && isFunction(thing.append) && thing[Symbol.toStringTag] === "FormData" && thing[Symbol.iterator]);
1359
1344
  }
@@ -1452,8 +1437,6 @@ const utils$1 = {
1452
1437
  findKey,
1453
1438
  global: _global,
1454
1439
  isContextDefined,
1455
- ALPHABET,
1456
- generateString,
1457
1440
  isSpecCompliantForm,
1458
1441
  toJSONObject,
1459
1442
  isAsyncFn,
@@ -2409,8 +2392,9 @@ function isAbsoluteURL(url) {
2409
2392
  function combineURLs(baseURL, relativeURL) {
2410
2393
  return relativeURL ? baseURL.replace(/\/?\/$/, "") + "/" + relativeURL.replace(/^\/+/, "") : baseURL;
2411
2394
  }
2412
- function buildFullPath(baseURL, requestedURL) {
2413
- if (baseURL && !isAbsoluteURL(requestedURL)) {
2395
+ function buildFullPath(baseURL, requestedURL, allowAbsoluteUrls) {
2396
+ let isRelativeUrl = !isAbsoluteURL(requestedURL);
2397
+ if (baseURL && isRelativeUrl || allowAbsoluteUrls == false) {
2414
2398
  return combineURLs(baseURL, requestedURL);
2415
2399
  }
2416
2400
  return requestedURL;
@@ -2497,7 +2481,7 @@ const resolveConfig = (config) => {
2497
2481
  const newConfig = mergeConfig({}, config);
2498
2482
  let { data, withXSRFToken, xsrfHeaderName, xsrfCookieName, headers, auth } = newConfig;
2499
2483
  newConfig.headers = headers = AxiosHeaders.from(headers);
2500
- newConfig.url = buildURL(buildFullPath(newConfig.baseURL, newConfig.url), config.params, config.paramsSerializer);
2484
+ newConfig.url = buildURL(buildFullPath(newConfig.baseURL, newConfig.url, newConfig.allowAbsoluteUrls), config.params, config.paramsSerializer);
2501
2485
  if (auth) {
2502
2486
  headers.set(
2503
2487
  "Authorization",
@@ -3014,7 +2998,7 @@ function dispatchRequest(config) {
3014
2998
  return Promise.reject(reason);
3015
2999
  });
3016
3000
  }
3017
- const VERSION = "1.7.9";
3001
+ const VERSION = "1.8.3";
3018
3002
  const validators$1 = {};
3019
3003
  ["object", "boolean", "number", "function", "string", "symbol"].forEach((type, i) => {
3020
3004
  validators$1[type] = function validator2(thing) {
@@ -3142,6 +3126,12 @@ class Axios {
3142
3126
  }, true);
3143
3127
  }
3144
3128
  }
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
+ }
3145
3135
  validator.assertOptions(config, {
3146
3136
  baseUrl: validators.spelling("baseURL"),
3147
3137
  withXsrfToken: validators.spelling("withXSRFToken")
@@ -3212,7 +3202,7 @@ class Axios {
3212
3202
  }
3213
3203
  getUri(config) {
3214
3204
  config = mergeConfig(this.defaults, config);
3215
- const fullPath = buildFullPath(config.baseURL, config.url);
3205
+ const fullPath = buildFullPath(config.baseURL, config.url, config.allowAbsoluteUrls);
3216
3206
  return buildURL(fullPath, config.params, config.paramsSerializer);
3217
3207
  }
3218
3208
  }
@@ -1343,21 +1343,6 @@ 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
- };
1361
1346
  function isSpecCompliantForm(thing) {
1362
1347
  return !!(thing && isFunction(thing.append) && thing[Symbol.toStringTag] === "FormData" && thing[Symbol.iterator]);
1363
1348
  }
@@ -1456,8 +1441,6 @@ var __publicField = (obj, key, value) => __defNormalProp(obj, typeof key !== "sy
1456
1441
  findKey,
1457
1442
  global: _global,
1458
1443
  isContextDefined,
1459
- ALPHABET,
1460
- generateString,
1461
1444
  isSpecCompliantForm,
1462
1445
  toJSONObject,
1463
1446
  isAsyncFn,
@@ -2413,8 +2396,9 @@ var __publicField = (obj, key, value) => __defNormalProp(obj, typeof key !== "sy
2413
2396
  function combineURLs(baseURL, relativeURL) {
2414
2397
  return relativeURL ? baseURL.replace(/\/?\/$/, "") + "/" + relativeURL.replace(/^\/+/, "") : baseURL;
2415
2398
  }
2416
- function buildFullPath(baseURL, requestedURL) {
2417
- if (baseURL && !isAbsoluteURL(requestedURL)) {
2399
+ function buildFullPath(baseURL, requestedURL, allowAbsoluteUrls) {
2400
+ let isRelativeUrl = !isAbsoluteURL(requestedURL);
2401
+ if (baseURL && isRelativeUrl || allowAbsoluteUrls == false) {
2418
2402
  return combineURLs(baseURL, requestedURL);
2419
2403
  }
2420
2404
  return requestedURL;
@@ -2501,7 +2485,7 @@ var __publicField = (obj, key, value) => __defNormalProp(obj, typeof key !== "sy
2501
2485
  const newConfig = mergeConfig({}, config);
2502
2486
  let { data, withXSRFToken, xsrfHeaderName, xsrfCookieName, headers, auth } = newConfig;
2503
2487
  newConfig.headers = headers = AxiosHeaders.from(headers);
2504
- newConfig.url = buildURL(buildFullPath(newConfig.baseURL, newConfig.url), config.params, config.paramsSerializer);
2488
+ newConfig.url = buildURL(buildFullPath(newConfig.baseURL, newConfig.url, newConfig.allowAbsoluteUrls), config.params, config.paramsSerializer);
2505
2489
  if (auth) {
2506
2490
  headers.set(
2507
2491
  "Authorization",
@@ -3018,7 +3002,7 @@ var __publicField = (obj, key, value) => __defNormalProp(obj, typeof key !== "sy
3018
3002
  return Promise.reject(reason);
3019
3003
  });
3020
3004
  }
3021
- const VERSION = "1.7.9";
3005
+ const VERSION = "1.8.3";
3022
3006
  const validators$1 = {};
3023
3007
  ["object", "boolean", "number", "function", "string", "symbol"].forEach((type, i) => {
3024
3008
  validators$1[type] = function validator2(thing) {
@@ -3146,6 +3130,12 @@ var __publicField = (obj, key, value) => __defNormalProp(obj, typeof key !== "sy
3146
3130
  }, true);
3147
3131
  }
3148
3132
  }
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
+ }
3149
3139
  validator.assertOptions(config, {
3150
3140
  baseUrl: validators.spelling("baseURL"),
3151
3141
  withXsrfToken: validators.spelling("withXSRFToken")
@@ -3216,7 +3206,7 @@ var __publicField = (obj, key, value) => __defNormalProp(obj, typeof key !== "sy
3216
3206
  }
3217
3207
  getUri(config) {
3218
3208
  config = mergeConfig(this.defaults, config);
3219
- const fullPath = buildFullPath(config.baseURL, config.url);
3209
+ const fullPath = buildFullPath(config.baseURL, config.url, config.allowAbsoluteUrls);
3220
3210
  return buildURL(fullPath, config.params, config.paramsSerializer);
3221
3211
  }
3222
3212
  }
@@ -1,11 +1,11 @@
1
- import { ResponseData, ResponseJsonData, SpecialResponseData, StandardResponseData } from "./response.data";
1
+ import { ResponseData, SpecialResponseData, StandardResponseData } from "./response.data";
2
2
  import { SnailMethod } from "../core/snailMethod";
3
3
  export type ApiResponse<T> = Promise<{
4
4
  data: T | null;
5
5
  error: Error | null;
6
6
  hitCache?: boolean;
7
7
  }>;
8
- export type ApiProxy<T extends object, RT extends ResponseData = StandardResponseData<ResponseJsonData>, DK extends string = "data"> = {
8
+ export type ApiProxy<T extends object, RT extends ResponseData = StandardResponseData, DK extends string = "data"> = {
9
9
  [K in keyof T]: T[K] extends (...args: infer A) => any ? RT extends SpecialResponseData ? <RD>(...args: A) => SnailMethod<RD extends SpecialResponseData ? RD : never> : <RD>(...args: A) => RD extends SpecialResponseData ? SnailMethod<RD> : SnailMethod<RT & {
10
10
  [KK in DK]: RD;
11
11
  }> : T[K];
@@ -6,7 +6,7 @@ export interface PaginationData<T> {
6
6
  }
7
7
  export type ResponseJsonData = Record<string, any> | object;
8
8
  export type SpecialResponseData = string | ArrayBuffer | Blob | FormData;
9
- export type StandardResponseData<T extends ResponseJsonData = Record<string, any>> = {
9
+ export type StandardResponseData<T = any> = {
10
10
  code: number;
11
11
  message: string;
12
12
  data: T;
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@snail-js/api",
3
- "version": "0.1.15",
3
+ "version": "0.1.17",
4
4
  "description": "Http Request with Decorators Api, build on axios",
5
5
  "type": "module",
6
6
  "main": "./src/index.ts",
@@ -26,7 +26,7 @@
26
26
  "author": "",
27
27
  "license": "MIT",
28
28
  "peerDependencies": {
29
- "axios": "^1.7.9"
29
+ "axios": "^1.8.3"
30
30
  },
31
31
  "files": [
32
32
  "README.md",