api-def 0.11.0-alpha.1 → 0.11.0-alpha.2

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.
@@ -1,2 +1,2 @@
1
- import { type BaseRequestConfig, type Body, type ComputedRequestConfig, type Query, type RequestConfig, type State } from "./ApiTypes";
2
- export declare const computeRequestConfig: <TParams extends string | undefined, TQuery extends Query, TBody extends Body | undefined, TState extends State>(configs: (RequestConfig<TParams, TQuery, TBody, TState> | BaseRequestConfig | undefined)[]) => ComputedRequestConfig<TParams, TQuery, TBody, TState>;
1
+ import { type BaseRequestConfig, type Body, type ComputedRequestConfig, type Params, type Query, type RequestConfig, type State } from "./ApiTypes";
2
+ export declare const computeRequestConfig: <TParams extends Params | undefined, TQuery extends Query | undefined, TBody extends Body | undefined, TState extends State>(configs: (RequestConfig<TParams, TQuery, TBody, TState> | BaseRequestConfig | undefined)[]) => ComputedRequestConfig<TParams, TQuery, TBody, TState>;
@@ -1,3 +1,3 @@
1
- import type { ApiResponse, Body, Query, RequestConfig, RequestHost, State } from "./ApiTypes";
1
+ import type { ApiResponse, Body, Params, Query, RequestConfig, RequestHost, State } from "./ApiTypes";
2
2
  import type { EndpointMockingConfig } from "./MockingTypes";
3
- export declare const submit: <TResponse, TParams extends string | undefined, TQuery extends Query, TBody extends Body | undefined, TState extends State>(host: RequestHost, config: RequestConfig<TParams, TQuery, TBody, TState>, mocking: EndpointMockingConfig<TResponse, TParams, TQuery, TBody, TState> | null | undefined) => Promise<ApiResponse<TResponse>>;
3
+ export declare const submit: <TResponse, TParams extends Params | undefined, TQuery extends Query | undefined, TBody extends Body | undefined, TState extends State>(host: RequestHost, config: RequestConfig<TParams, TQuery, TBody, TState>, mocking: EndpointMockingConfig<TResponse, TParams, TQuery, TBody, TState> | null | undefined) => Promise<ApiResponse<TResponse>>;
package/cjs/Utils.d.ts CHANGED
@@ -13,3 +13,4 @@ export declare const noop: () => void;
13
13
  */
14
14
  export declare const delayThenReturn: <T>(value: T, delayMs: number) => Promise<T>;
15
15
  export declare const randInt: (min: number, max: number) => number;
16
+ export declare const isFormData: (value: any) => value is FormData;
package/cjs/Utils.js CHANGED
@@ -1,6 +1,6 @@
1
1
  "use strict";
2
2
  Object.defineProperty(exports, "__esModule", { value: true });
3
- exports.randInt = exports.delayThenReturn = exports.noop = exports.getGlobalFetch = exports.getGlobal = exports.padNumber = exports.assign = void 0;
3
+ exports.isFormData = exports.randInt = exports.delayThenReturn = exports.noop = exports.getGlobalFetch = exports.getGlobal = exports.padNumber = exports.assign = void 0;
4
4
  // polyfill from https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/Object/assign
5
5
  exports.assign = Object.assign ||
6
6
  (function (target) {
@@ -75,3 +75,7 @@ var randInt = function (min, max) {
75
75
  return Math.floor(Math.random() * (maxI - minI + 1)) + minI;
76
76
  };
77
77
  exports.randInt = randInt;
78
+ var isFormData = function (value) {
79
+ return value instanceof FormData;
80
+ };
81
+ exports.isFormData = isFormData;
@@ -3,7 +3,7 @@ import type { ApiResponse } from "../ApiTypes";
3
3
  import type RequestContext from "../RequestContext";
4
4
  import type RequestBackend from "./RequestBackend";
5
5
  import type { ConvertedApiResponse, RequestBackendErrorInfo, RequestOperation } from "./RequestBackend";
6
- export declare const isAxiosError: (error: Error) => error is AxiosError<unknown, any>;
6
+ export declare const isAxiosError: (error: Error) => error is AxiosError;
7
7
  export default class AxiosRequestBackend implements RequestBackend<AxiosResponse> {
8
8
  readonly id = "axios";
9
9
  constructor(axiosLibrary: any);
@@ -4,7 +4,7 @@ import { type Fetch } from "../Utils";
4
4
  import type RequestBackend from "./RequestBackend";
5
5
  import type { ConvertedApiResponse, RequestBackendErrorInfo, RequestOperation } from "./RequestBackend";
6
6
  export default class FetchRequestBackend implements RequestBackend<Response> {
7
- fetch: (((input: URL | RequestInfo, init?: RequestInit | undefined) => Promise<Response>) & typeof fetch) | undefined;
7
+ fetch: (((input: RequestInfo | URL, init?: RequestInit) => Promise<Response>) & typeof fetch) | undefined;
8
8
  readonly id = "fetch";
9
9
  constructor(fetchLibrary?: Fetch);
10
10
  extractResponseFromError(error: Error): Promise<Response | null | undefined>;
@@ -144,18 +144,18 @@ var FetchRequestBackend = /** @class */ (function () {
144
144
  if (!this.fetch) {
145
145
  throw new Error("[api-def] No fetch impl was provided to FetchRequestBackend");
146
146
  }
147
- var computedConfig = context.computedConfig;
147
+ var requestConfig = context.requestConfig;
148
148
  // abort controller is a newer feature than fetch
149
149
  var abortController = AbortController && new AbortController();
150
150
  var abortSignal = abortController ? abortController.signal : undefined;
151
151
  var softAbort = false;
152
152
  var responded = false;
153
153
  var body = context.getParsedBody();
154
- var bodyJsonify = body !== null && typeof body === "object";
154
+ var bodyJsonify = body !== null && typeof body === "object" && !Utils.isFormData(body);
155
155
  var headers = Utils.assign({
156
156
  // logic from axios
157
157
  "Content-Type": bodyJsonify ? "application/json;charset=utf-8" : "application/x-www-form-urlencoded",
158
- }, computedConfig.headers);
158
+ }, requestConfig.headers);
159
159
  var parsedHeaders = Object.keys(headers).reduce(function (parsedHeaders, key) {
160
160
  var value = headers[key];
161
161
  if (value !== undefined) {
@@ -1,2 +1,2 @@
1
- import { type BaseRequestConfig, type Body, type ComputedRequestConfig, type Query, type RequestConfig, type State } from "./ApiTypes";
2
- export declare const computeRequestConfig: <TParams extends string | undefined, TQuery extends Query, TBody extends Body | undefined, TState extends State>(configs: (RequestConfig<TParams, TQuery, TBody, TState> | BaseRequestConfig | undefined)[]) => ComputedRequestConfig<TParams, TQuery, TBody, TState>;
1
+ import { type BaseRequestConfig, type Body, type ComputedRequestConfig, type Params, type Query, type RequestConfig, type State } from "./ApiTypes";
2
+ export declare const computeRequestConfig: <TParams extends Params | undefined, TQuery extends Query | undefined, TBody extends Body | undefined, TState extends State>(configs: (RequestConfig<TParams, TQuery, TBody, TState> | BaseRequestConfig | undefined)[]) => ComputedRequestConfig<TParams, TQuery, TBody, TState>;
@@ -1,3 +1,3 @@
1
- import type { ApiResponse, Body, Query, RequestConfig, RequestHost, State } from "./ApiTypes";
1
+ import type { ApiResponse, Body, Params, Query, RequestConfig, RequestHost, State } from "./ApiTypes";
2
2
  import type { EndpointMockingConfig } from "./MockingTypes";
3
- export declare const submit: <TResponse, TParams extends string | undefined, TQuery extends Query, TBody extends Body | undefined, TState extends State>(host: RequestHost, config: RequestConfig<TParams, TQuery, TBody, TState>, mocking: EndpointMockingConfig<TResponse, TParams, TQuery, TBody, TState> | null | undefined) => Promise<ApiResponse<TResponse>>;
3
+ export declare const submit: <TResponse, TParams extends Params | undefined, TQuery extends Query | undefined, TBody extends Body | undefined, TState extends State>(host: RequestHost, config: RequestConfig<TParams, TQuery, TBody, TState>, mocking: EndpointMockingConfig<TResponse, TParams, TQuery, TBody, TState> | null | undefined) => Promise<ApiResponse<TResponse>>;
package/esm/Requester.js CHANGED
@@ -175,7 +175,7 @@ const makeRequest = (context) => __awaiter(void 0, void 0, void 0, function* ()
175
175
  return response;
176
176
  });
177
177
  const parseResponse = (context, response, error) => __awaiter(void 0, void 0, void 0, function* () {
178
- var _d;
178
+ var _a;
179
179
  if (response) {
180
180
  const parsedResponse = yield context.backend.convertResponse(context, response);
181
181
  const contentType = parsedResponse.headers.get("content-type");
@@ -194,7 +194,7 @@ const parseResponse = (context, response, error) => __awaiter(void 0, void 0, vo
194
194
  if (inferredResponseType === "arraybuffer" && context.responseType === "json") {
195
195
  if (parsedResponse.data && typeof parsedResponse.data === "object") {
196
196
  const data = response.data;
197
- if (((_d = data.constructor) === null || _d === void 0 ? void 0 : _d.name) === "ArrayBuffer") {
197
+ if (((_a = data.constructor) === null || _a === void 0 ? void 0 : _a.name) === "ArrayBuffer") {
198
198
  try {
199
199
  const decodedData = (response.data = textDecode(data));
200
200
  response.data = JSON.parse(decodedData);
@@ -216,7 +216,7 @@ const parseResponse = (context, response, error) => __awaiter(void 0, void 0, vo
216
216
  return response;
217
217
  });
218
218
  const parseError = (context, rawError) => __awaiter(void 0, void 0, void 0, function* () {
219
- var _e;
219
+ var _a;
220
220
  let error;
221
221
  if (isRequestError(rawError)) {
222
222
  error = rawError;
@@ -236,7 +236,7 @@ const parseError = (context, rawError) => __awaiter(void 0, void 0, void 0, func
236
236
  }
237
237
  }
238
238
  else {
239
- if (rawError.code === "ENOTFOUND" || ((_e = rawError.cause) === null || _e === void 0 ? void 0 : _e.code) === "ENOTFOUND") {
239
+ if (rawError.code === "ENOTFOUND" || ((_a = rawError.cause) === null || _a === void 0 ? void 0 : _a.code) === "ENOTFOUND") {
240
240
  code = RequestErrorCode.REQUEST_HOST_NAME_NOT_FOUND;
241
241
  }
242
242
  }
package/esm/Utils.d.ts CHANGED
@@ -13,3 +13,4 @@ export declare const noop: () => void;
13
13
  */
14
14
  export declare const delayThenReturn: <T>(value: T, delayMs: number) => Promise<T>;
15
15
  export declare const randInt: (min: number, max: number) => number;
16
+ export declare const isFormData: (value: any) => value is FormData;
package/esm/Utils.js CHANGED
@@ -62,3 +62,6 @@ export const randInt = (min, max) => {
62
62
  const maxI = Math.floor(max);
63
63
  return Math.floor(Math.random() * (maxI - minI + 1)) + minI;
64
64
  };
65
+ export const isFormData = (value) => {
66
+ return value instanceof FormData;
67
+ };
@@ -3,7 +3,7 @@ import type { ApiResponse } from "../ApiTypes";
3
3
  import type RequestContext from "../RequestContext";
4
4
  import type RequestBackend from "./RequestBackend";
5
5
  import type { ConvertedApiResponse, RequestBackendErrorInfo, RequestOperation } from "./RequestBackend";
6
- export declare const isAxiosError: (error: Error) => error is AxiosError<unknown, any>;
6
+ export declare const isAxiosError: (error: Error) => error is AxiosError;
7
7
  export default class AxiosRequestBackend implements RequestBackend<AxiosResponse> {
8
8
  readonly id = "axios";
9
9
  constructor(axiosLibrary: any);
@@ -4,7 +4,7 @@ import { type Fetch } from "../Utils";
4
4
  import type RequestBackend from "./RequestBackend";
5
5
  import type { ConvertedApiResponse, RequestBackendErrorInfo, RequestOperation } from "./RequestBackend";
6
6
  export default class FetchRequestBackend implements RequestBackend<Response> {
7
- fetch: (((input: URL | RequestInfo, init?: RequestInit | undefined) => Promise<Response>) & typeof fetch) | undefined;
7
+ fetch: (((input: RequestInfo | URL, init?: RequestInit) => Promise<Response>) & typeof fetch) | undefined;
8
8
  readonly id = "fetch";
9
9
  constructor(fetchLibrary?: Fetch);
10
10
  extractResponseFromError(error: Error): Promise<Response | null | undefined>;
@@ -79,18 +79,18 @@ export default class FetchRequestBackend {
79
79
  if (!this.fetch) {
80
80
  throw new Error("[api-def] No fetch impl was provided to FetchRequestBackend");
81
81
  }
82
- const { computedConfig } = context;
82
+ const { requestConfig } = context;
83
83
  // abort controller is a newer feature than fetch
84
84
  const abortController = AbortController && new AbortController();
85
85
  const abortSignal = abortController ? abortController.signal : undefined;
86
86
  let softAbort = false;
87
87
  let responded = false;
88
88
  const body = context.getParsedBody();
89
- const bodyJsonify = body !== null && typeof body === "object";
89
+ const bodyJsonify = body !== null && typeof body === "object" && !Utils.isFormData(body);
90
90
  const headers = Utils.assign({
91
91
  // logic from axios
92
92
  "Content-Type": bodyJsonify ? "application/json;charset=utf-8" : "application/x-www-form-urlencoded",
93
- }, computedConfig.headers);
93
+ }, requestConfig.headers);
94
94
  const parsedHeaders = Object.keys(headers).reduce((parsedHeaders, key) => {
95
95
  const value = headers[key];
96
96
  if (value !== undefined) {
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "api-def",
3
- "version": "0.11.0-alpha.1",
3
+ "version": "0.11.0-alpha.2",
4
4
  "description": "Typed API definitions with middleware support",
5
5
  "main": "cjs/index.js",
6
6
  "types": "esm/index.d.ts",
@@ -10,8 +10,8 @@
10
10
  "prepublishOnly": "npm run check:fix && npm run test && npm run build",
11
11
  "test": "jest",
12
12
  "example:start": "cd example && npm run start",
13
- "check:fix": "tsc --noEmit --project tsconfig.json && npx @biomejs/biome check --apply .",
14
- "check": "tsc --noEmit --project tsconfig.json && npx @biomejs/biome check .",
13
+ "check:fix": "tsc --noEmit --project tsconfig.json && npx @biomejs/biome check --write",
14
+ "check": "tsc --noEmit --project tsconfig.json && npx @biomejs/biome check",
15
15
  "cleanup": "rimraf esm && rimraf cjs",
16
16
  "build": "npm run cleanup && npm run build:esm && npm run build:cjs",
17
17
  "build:esm": "tsc --module es2015 --target es2016 --outDir esm --preserveWatchOutput",
@@ -30,20 +30,20 @@
30
30
  },
31
31
  "repository": "https://github.com/Censkh/api-def",
32
32
  "devDependencies": {
33
- "@biomejs/biome": "1.8.1",
33
+ "@biomejs/biome": "1.8.3",
34
34
  "@swc/core": "latest",
35
35
  "@swc/jest": "latest",
36
36
  "@types/axios": "0.14.0",
37
37
  "@types/jest": "^29.5.12",
38
- "@types/node": "20.14.2",
38
+ "@types/node": "22.4.0",
39
39
  "@types/qs": "6.9.15",
40
- "axios": "1.7.2",
40
+ "axios": "1.7.4",
41
41
  "cross-env": "7.0.3",
42
42
  "jest": "latest",
43
43
  "npm-run-all": "4.1.5",
44
- "qs": "6.12.1",
45
- "rimraf": "5.0.7",
46
- "typescript": "5.4.5",
44
+ "qs": "6.13.0",
45
+ "rimraf": "6.0.1",
46
+ "typescript": "5.5.4",
47
47
  "zod": "3.23.8"
48
48
  }
49
49
  }