@modern-js/create-request 2.8.1-alpha.0 → 2.9.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.
@@ -0,0 +1,29 @@
1
+ var __defProp = Object.defineProperty;
2
+ var __getOwnPropDesc = Object.getOwnPropertyDescriptor;
3
+ var __getOwnPropNames = Object.getOwnPropertyNames;
4
+ var __hasOwnProp = Object.prototype.hasOwnProperty;
5
+ var __export = (target, all) => {
6
+ for (var name in all)
7
+ __defProp(target, name, { get: all[name], enumerable: true });
8
+ };
9
+ var __copyProps = (to, from, except, desc) => {
10
+ if (from && typeof from === "object" || typeof from === "function") {
11
+ for (let key of __getOwnPropNames(from))
12
+ if (!__hasOwnProp.call(to, key) && key !== except)
13
+ __defProp(to, key, { get: () => from[key], enumerable: !(desc = __getOwnPropDesc(from, key)) || desc.enumerable });
14
+ }
15
+ return to;
16
+ };
17
+ var __toCommonJS = (mod) => __copyProps(__defProp({}, "__esModule", { value: true }), mod);
18
+ var src_exports = {};
19
+ __export(src_exports, {
20
+ default: () => src_default
21
+ });
22
+ module.exports = __toCommonJS(src_exports);
23
+ var import_utils = require("@modern-js/utils");
24
+ var import_browser = require("./browser");
25
+ var import_node = require("./node");
26
+ const createRequest = (...args) => (0, import_utils.isBrowser)() ? (0, import_browser.createRequest)(...args) : (0, import_node.createRequest)(...args);
27
+ var src_default = createRequest;
28
+ // Annotate the CommonJS export names for ESM import in node:
29
+ 0 && (module.exports = {});
@@ -0,0 +1,36 @@
1
+ function _arrayLikeToArray(arr, len) {
2
+ if (len == null || len > arr.length) len = arr.length;
3
+ for(var i = 0, arr2 = new Array(len); i < len; i++)arr2[i] = arr[i];
4
+ return arr2;
5
+ }
6
+ function _arrayWithoutHoles(arr) {
7
+ if (Array.isArray(arr)) return _arrayLikeToArray(arr);
8
+ }
9
+ function _iterableToArray(iter) {
10
+ if (typeof Symbol !== "undefined" && iter[Symbol.iterator] != null || iter["@@iterator"] != null) return Array.from(iter);
11
+ }
12
+ function _nonIterableSpread() {
13
+ throw new TypeError("Invalid attempt to spread non-iterable instance.\\nIn order to be iterable, non-array objects must have a [Symbol.iterator]() method.");
14
+ }
15
+ function _toConsumableArray(arr) {
16
+ return _arrayWithoutHoles(arr) || _iterableToArray(arr) || _unsupportedIterableToArray(arr) || _nonIterableSpread();
17
+ }
18
+ function _unsupportedIterableToArray(o, minLen) {
19
+ if (!o) return;
20
+ if (typeof o === "string") return _arrayLikeToArray(o, minLen);
21
+ var n = Object.prototype.toString.call(o).slice(8, -1);
22
+ if (n === "Object" && o.constructor) n = o.constructor.name;
23
+ if (n === "Map" || n === "Set") return Array.from(n);
24
+ if (n === "Arguments" || /^(?:Ui|I)nt(?:8|16|32)(?:Clamped)?Array$/.test(n)) return _arrayLikeToArray(o, minLen);
25
+ }
26
+ import { isBrowser } from "@modern-js/utils";
27
+ import { createRequest as browser } from "./browser";
28
+ import { createRequest as node } from "./node";
29
+ var createRequest = function() {
30
+ for(var _len = arguments.length, args = new Array(_len), _key = 0; _key < _len; _key++){
31
+ args[_key] = arguments[_key];
32
+ }
33
+ return isBrowser() ? browser.apply(void 0, _toConsumableArray(args)) : node.apply(void 0, _toConsumableArray(args));
34
+ };
35
+ var src_default = createRequest;
36
+ export { src_default as default };
@@ -0,0 +1,8 @@
1
+ import { isBrowser } from "@modern-js/utils";
2
+ import { createRequest as browser } from "./browser";
3
+ import { createRequest as node } from "./node";
4
+ const createRequest = (...args) => isBrowser() ? browser(...args) : node(...args);
5
+ var src_default = createRequest;
6
+ export {
7
+ src_default as default
8
+ };
@@ -0,0 +1,4 @@
1
+ import { RequestCreator, IOptions } from './types';
2
+ declare const createRequest: RequestCreator;
3
+ export declare const configure: (options: IOptions) => void;
4
+ export default createRequest;
@@ -1,4 +1,4 @@
1
1
  import nodeFetch from 'node-fetch';
2
2
  import type { RequestCreator, IOptions } from './types';
3
3
  export declare const configure: (options: IOptions<typeof nodeFetch>) => void;
4
- export declare const createRequest: RequestCreator<typeof nodeFetch>;
4
+ export declare const createRequest: RequestCreator;
@@ -1,3 +1,4 @@
1
+ import type nodeFetch from 'node-fetch';
1
2
  import type { HttpMethodDecider } from '@modern-js/types';
2
3
  export type BFFRequestPayload = {
3
4
  params?: Record<string, any>;
@@ -9,11 +10,12 @@ export type BFFRequestPayload = {
9
10
  headers?: Record<string, any>;
10
11
  cookies?: Record<string, any>;
11
12
  };
12
- export type Sender<F = typeof fetch> = ((...args: any[]) => Promise<any>) & {
13
- fetch?: F;
13
+ export type Fetch = typeof fetch | typeof nodeFetch;
14
+ export type Sender = ((...args: any[]) => Promise<any>) & {
15
+ fetch?: Fetch;
14
16
  };
15
- export type RequestCreator<F = typeof fetch> = (path: string, method: string, port: number, httpMethodDecider: HttpMethodDecider, fetch?: F) => Sender;
16
- export type IOptions<F = typeof fetch> = {
17
+ export type RequestCreator = (path: string, method: string, port: number, httpMethodDecider: HttpMethodDecider, fetch?: Fetch) => Sender;
18
+ export type IOptions<F = Fetch> = {
17
19
  request?: F;
18
20
  interceptor?: (request: F) => F;
19
21
  allowedHeaders?: string[];
package/package.json CHANGED
@@ -11,7 +11,7 @@
11
11
  "modern",
12
12
  "modern.js"
13
13
  ],
14
- "version": "2.8.1-alpha.0",
14
+ "version": "2.9.0",
15
15
  "jsnext:source": "./src/index.ts",
16
16
  "types": "./dist/types/index.d.ts",
17
17
  "main": "./dist/cjs/index.js",
@@ -60,7 +60,7 @@
60
60
  "node-fetch": "^2.6.1",
61
61
  "path-to-regexp": "^6.2.0",
62
62
  "query-string": "^7.1.1",
63
- "@modern-js/utils": "2.8.1-alpha.0"
63
+ "@modern-js/utils": "2.9.0"
64
64
  },
65
65
  "devDependencies": {
66
66
  "@types/jest": "^27",
@@ -70,9 +70,9 @@
70
70
  "jest": "^27",
71
71
  "nock": "^13.2.1",
72
72
  "typescript": "^4",
73
- "@modern-js/types": "2.8.0",
74
- "@scripts/build": "2.8.0",
75
- "@scripts/jest-config": "2.8.0"
73
+ "@modern-js/types": "2.9.0",
74
+ "@scripts/jest-config": "2.9.0",
75
+ "@scripts/build": "2.9.0"
76
76
  },
77
77
  "sideEffects": false,
78
78
  "publishConfig": {