@zayne-labs/callapi 1.7.0 → 1.7.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.
package/LICENSE ADDED
@@ -0,0 +1,21 @@
1
+ MIT License
2
+
3
+ Copyright (c) 2024 Ikedigwe Ebube
4
+
5
+ Permission is hereby granted, free of charge, to any person obtaining a copy
6
+ of this software and associated documentation files (the "Software"), to deal
7
+ in the Software without restriction, including without limitation the rights
8
+ to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
9
+ copies of the Software, and to permit persons to whom the Software is
10
+ furnished to do so, subject to the following conditions:
11
+
12
+ The above copyright notice and this permission notice shall be included in all
13
+ copies or substantial portions of the Software.
14
+
15
+ THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
16
+ IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
17
+ FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
18
+ AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
19
+ LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
20
+ OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
21
+ SOFTWARE.
package/README.md CHANGED
@@ -1,11 +1,11 @@
1
1
  <h1 align="center">CallApi - Advanced Fetch Client</h1>
2
2
 
3
3
  <p align="center">
4
- <img src="../../apps/docs/public/logo.png" alt="CallApi Logo" width="50%">
4
+ <img src="https://github.com/zayne-labs/call-api/blob/main/packages/callapi/assets/logo.png" alt="CallApi Logo" width="30%">
5
5
  </p>
6
6
 
7
7
  <p align="center">
8
- <a href="https://deno.bundlejs.com/badge?q=@zayne-labs/callapi,@zayne-labs/callapi&treeshake=%5B*%5D,%5B%7B+createFetchClient+%7D%5D&config=%7B%22compression%22:%7B%22type%22:%22brotli%22,%22quality%22:11%7D%7D"><img src="https://deno.bundlejs.com/badge?q=@zayne-labs/callapi,@zayne-labs/callapi&treeshake=%5B*%5D,%5B%7B+createFetchClient+%7D%5D&config=%7B%22compression%22:%7B%22type%22:%22brotli%22,%22quality%22:11%7D%7D" alt="bundle size"></a>
8
+ <!-- <a href="https://deno.bundlejs.com/badge?q=@zayne-labs/callapi,@zayne-labs/callapi&treeshake=%5B*%5D,%5B%7B+createFetchClient+%7D%5D&config=%7B%22compression%22:%7B%22type%22:%22brotli%22,%22quality%22:11%7D%7D"><img src="https://deno.bundlejs.com/badge?q=@zayne-labs/callapi,@zayne-labs/callapi&treeshake=%5B*%5D,%5B%7B+createFetchClient+%7D%5D&config=%7B%22compression%22:%7B%22type%22:%22brotli%22,%22quality%22:11%7D%7D" alt="bundle size"></a> -->
9
9
  <a href="https://www.npmjs.com/package/@zayne-labs/callapi"><img src="https://img.shields.io/npm/v/@zayne-labs/callapi?style=flat&color=EFBA5F" alt="npm version"></a>
10
10
  <a href="https://github.com/zayne-labs/call-api/blob/master/LICENSE"><img src="https://img.shields.io/npm/l/@zayne-labs/callapi?style=flat&color=EFBA5F" alt="license"></a>
11
11
  <a href="https://github.com/zayne-labs/call-api/graphs/commit-activity"><img src="https://img.shields.io/github/commit-activity/m/zayne-labs/call-api?style=flat&color=EFBA5F" alt="commit activity"></a>
@@ -1,41 +1,3 @@
1
- import { StandardSchemaV1 } from '@standard-schema/spec';
2
-
3
- type StreamProgressEvent = {
4
- /**
5
- * Current chunk of data being streamed
6
- */
7
- chunk: Uint8Array;
8
- /**
9
- * Progress in percentage
10
- */
11
- progress: number;
12
- /**
13
- * Total size of data in bytes
14
- */
15
- totalBytes: number;
16
- /**
17
- * Amount of data transferred so far
18
- */
19
- transferredBytes: number;
20
- };
21
- type RequestStreamContext = {
22
- event: StreamProgressEvent;
23
- options: CombinedCallApiExtraOptions;
24
- request: CallApiRequestOptionsForHooks;
25
- requestInstance: Request;
26
- };
27
- type ResponseStreamContext = {
28
- event: StreamProgressEvent;
29
- options: CombinedCallApiExtraOptions;
30
- request: CallApiRequestOptionsForHooks;
31
- response: Response;
32
- };
33
- declare global {
34
- interface ReadableStream<R> {
35
- [Symbol.asyncIterator]: () => AsyncIterableIterator<R>;
36
- }
37
- }
38
-
39
1
  type ValueOrFunctionResult<TValue> = TValue | (() => TValue);
40
2
  /**
41
3
  * Bearer Or Token authentication
@@ -92,6 +54,9 @@ type AnyNumber = number & {
92
54
  z_placeholder?: never;
93
55
  };
94
56
  type AnyFunction<TResult = unknown> = (...args: any) => TResult;
57
+ type Prettify<TObject> = NonNullable<unknown> & {
58
+ [Key in keyof TObject]: TObject[Key];
59
+ };
95
60
  type UnmaskType<TValue> = {
96
61
  _: TValue;
97
62
  }["_"];
@@ -100,6 +65,105 @@ type CommonRequestHeaders = "Access-Control-Allow-Credentials" | "Access-Control
100
65
  type CommonAuthorizationHeaders = `${"Basic" | "Bearer" | "Token"} ${string}`;
101
66
  type CommonContentTypes = "application/epub+zip" | "application/gzip" | "application/json" | "application/ld+json" | "application/octet-stream" | "application/ogg" | "application/pdf" | "application/rtf" | "application/vnd.ms-fontobject" | "application/wasm" | "application/xhtml+xml" | "application/xml" | "application/zip" | "audio/aac" | "audio/mpeg" | "audio/ogg" | "audio/opus" | "audio/webm" | "audio/x-midi" | "font/otf" | "font/ttf" | "font/woff" | "font/woff2" | "image/avif" | "image/bmp" | "image/gif" | "image/jpeg" | "image/png" | "image/svg+xml" | "image/tiff" | "image/webp" | "image/x-icon" | "model/gltf-binary" | "model/gltf+json" | "text/calendar" | "text/css" | "text/csv" | "text/html" | "text/javascript" | "text/plain" | "video/3gpp" | "video/3gpp2" | "video/av1" | "video/mp2t" | "video/mp4" | "video/mpeg" | "video/ogg" | "video/webm" | "video/x-msvideo" | AnyString;
102
67
 
68
+ /**
69
+ * The Standard Schema interface.
70
+ * @see https://github.com/standard-schema/standard-schema
71
+ */
72
+ interface StandardSchemaV1<Input = unknown, Output = Input> {
73
+ /**
74
+ * The Standard Schema properties.
75
+ */
76
+ readonly "~standard": StandardSchemaV1.Props<Input, Output>;
77
+ }
78
+ declare namespace StandardSchemaV1 {
79
+ /**
80
+ * The Standard Schema properties interface.
81
+ */
82
+ interface Props<Input = unknown, Output = Input> {
83
+ /**
84
+ * Inferred types associated with the schema.
85
+ */
86
+ readonly types?: Types<Input, Output> | undefined;
87
+ /**
88
+ * Validates unknown input values.
89
+ */
90
+ readonly validate: (value: unknown) => Promise<Result<Output>> | Result<Output>;
91
+ /**
92
+ * The vendor name of the schema library.
93
+ */
94
+ readonly vendor: string;
95
+ /**
96
+ * The version number of the standard.
97
+ */
98
+ readonly version: 1;
99
+ }
100
+ /**
101
+ * The result interface of the validate function.
102
+ */
103
+ type Result<Output> = FailureResult | SuccessResult<Output>;
104
+ /**
105
+ * The result interface if validation succeeds.
106
+ */
107
+ interface SuccessResult<Output> {
108
+ /**
109
+ * The non-existent issues.
110
+ */
111
+ readonly issues?: undefined;
112
+ /**
113
+ * The typed output value.
114
+ */
115
+ readonly value: Output;
116
+ }
117
+ /**
118
+ * The result interface if validation fails.
119
+ */
120
+ interface FailureResult {
121
+ /**
122
+ * The issues of failed validation.
123
+ */
124
+ readonly issues: readonly Issue[];
125
+ }
126
+ /**
127
+ * The issue interface of the failure output.
128
+ */
129
+ interface Issue {
130
+ /**
131
+ * The error message of the issue.
132
+ */
133
+ readonly message: string;
134
+ /**
135
+ * The path of the issue, if any.
136
+ */
137
+ readonly path?: ReadonlyArray<PathSegment | PropertyKey> | undefined;
138
+ }
139
+ /**
140
+ * The path segment interface of the issue.
141
+ */
142
+ interface PathSegment {
143
+ /**
144
+ * The key representing a path segment.
145
+ */
146
+ readonly key: PropertyKey;
147
+ }
148
+ /**
149
+ * The Standard Schema types interface.
150
+ */
151
+ interface Types<Input = unknown, Output = Input> {
152
+ /** The input type of the schema. */
153
+ readonly input: Input;
154
+ /** The output type of the schema. */
155
+ readonly output: Output;
156
+ }
157
+ /**
158
+ * Infers the input type of a Standard Schema.
159
+ */
160
+ type InferInput<Schema extends StandardSchemaV1> = NonNullable<Schema["~standard"]["types"]>["input"];
161
+ /**
162
+ * Infers the output type of a Standard Schema.
163
+ */
164
+ type InferOutput<Schema extends StandardSchemaV1> = NonNullable<Schema["~standard"]["types"]>["output"];
165
+ }
166
+
103
167
  interface CallApiSchemas {
104
168
  /**
105
169
  * The schema to use for validating the request body.
@@ -233,6 +297,42 @@ type ResponseTypeMap<TResponse> = {
233
297
  };
234
298
  type GetResponseType<TResponse, TResponseType extends ResponseTypeUnion, TComputedMap extends ResponseTypeMap<TResponse> = ResponseTypeMap<TResponse>> = undefined extends TResponseType ? TComputedMap["json"] : TResponseType extends NonNullable<ResponseTypeUnion> ? TComputedMap[TResponseType] : never;
235
299
 
300
+ type StreamProgressEvent = {
301
+ /**
302
+ * Current chunk of data being streamed
303
+ */
304
+ chunk: Uint8Array;
305
+ /**
306
+ * Progress in percentage
307
+ */
308
+ progress: number;
309
+ /**
310
+ * Total size of data in bytes
311
+ */
312
+ totalBytes: number;
313
+ /**
314
+ * Amount of data transferred so far
315
+ */
316
+ transferredBytes: number;
317
+ };
318
+ type RequestStreamContext = {
319
+ event: StreamProgressEvent;
320
+ options: CombinedCallApiExtraOptions;
321
+ request: CallApiRequestOptionsForHooks;
322
+ requestInstance: Request;
323
+ };
324
+ type ResponseStreamContext = {
325
+ event: StreamProgressEvent;
326
+ options: CombinedCallApiExtraOptions;
327
+ request: CallApiRequestOptionsForHooks;
328
+ response: Response;
329
+ };
330
+ declare global {
331
+ interface ReadableStream<R> {
332
+ [Symbol.asyncIterator]: () => AsyncIterableIterator<R>;
333
+ }
334
+ }
335
+
236
336
  type UnionToIntersection<TUnion> = (TUnion extends unknown ? (param: TUnion) => void : never) extends (param: infer TParam) => void ? TParam : never;
237
337
  type InferSchema<TResult> = TResult extends StandardSchemaV1 ? InferSchemaResult<TResult, NonNullable<unknown>> : TResult;
238
338
  type InferPluginOptions<TPluginArray extends CallApiPlugin[]> = UnionToIntersection<InferSchema<ReturnType<NonNullable<TPluginArray[number]["createExtraOptions"]>>>>;
@@ -280,9 +380,9 @@ declare const definePlugin: <TPlugin extends CallApiPlugin | AnyFunction<CallApi
280
380
  type Plugins<TPluginArray extends CallApiPlugin[]> = TPluginArray;
281
381
 
282
382
  type ModifiedRequestInit = RequestInit & {
283
- duplex?: "full" | "half" | "none";
383
+ duplex?: "half";
284
384
  };
285
- declare const fetchSpecificKeys: ("body" | "cache" | "credentials" | "headers" | "integrity" | "keepalive" | "method" | "mode" | "priority" | "redirect" | "referrer" | "referrerPolicy" | "signal" | "window" | "duplex")[];
385
+ declare const fetchSpecificKeys: (keyof RequestInit | "duplex")[];
286
386
  declare const getDefaultOptions: () => {
287
387
  baseURL: string;
288
388
  bodySerializer: {
@@ -374,7 +474,7 @@ type ResultModeOption<TErrorData, TResultMode extends ResultModeUnion> = TErrorD
374
474
  };
375
475
 
376
476
  type FetchSpecificKeysUnion = Exclude<(typeof fetchSpecificKeys)[number], "body" | "headers" | "method">;
377
- type CallApiRequestOptions<TSchemas extends CallApiSchemas = DefaultMoreOptions> = BodyOption<TSchemas> & HeadersOption<TSchemas> & MethodOption<TSchemas> & Pick<ModifiedRequestInit, FetchSpecificKeysUnion>;
477
+ type CallApiRequestOptions<TSchemas extends CallApiSchemas = DefaultMoreOptions> = Prettify<BodyOption<TSchemas> & HeadersOption<TSchemas> & MethodOption<TSchemas> & Pick<ModifiedRequestInit, FetchSpecificKeysUnion>>;
378
478
  type CallApiRequestOptionsForHooks<TSchemas extends CallApiSchemas = DefaultMoreOptions> = Omit<CallApiRequestOptions<TSchemas>, "headers"> & {
379
479
  headers?: Record<string, string | undefined>;
380
480
  };
@@ -486,7 +586,7 @@ type ExtraOptions<TData = DefaultDataType, TErrorData = DefaultDataType, TResult
486
586
  mergedHooksExecutionMode?: "parallel" | "sequential";
487
587
  /**
488
588
  * - Controls what order in which the merged hooks execute
489
- * @default "mainHooksLast"
589
+ * @default "mainHooksAfterPlugins"
490
590
  */
491
591
  mergedHooksExecutionOrder?: "mainHooksAfterPlugins" | "mainHooksBeforePlugins";
492
592
  /**
@@ -535,7 +635,17 @@ type CallApiExtraOptions<TData = DefaultDataType, TErrorData = DefaultDataType,
535
635
  extend?: Pick<ExtraOptions<TData, TErrorData, TResultMode, TThrowOnError, TResponseType, TPluginArray, TSchemas>, (typeof optionsEnumToExtendFromBase)[number]>;
536
636
  };
537
637
  declare const optionsEnumToOmitFromBase: ("dedupeKey" | "extend")[];
538
- type BaseCallApiExtraOptions<TBaseData = DefaultDataType, TBaseErrorData = DefaultDataType, TBaseResultMode extends ResultModeUnion = ResultModeUnion, TBaseThrowOnError extends boolean = DefaultThrowOnError, TBaseResponseType extends ResponseTypeUnion = ResponseTypeUnion, TBasePluginArray extends CallApiPlugin[] = DefaultPluginArray, TBaseSchemas extends CallApiSchemas = DefaultMoreOptions> = Omit<Partial<CallApiExtraOptions<TBaseData, TBaseErrorData, TBaseResultMode, TBaseThrowOnError, TBaseResponseType, TBasePluginArray, TBaseSchemas>>, (typeof optionsEnumToOmitFromBase)[number]>;
638
+ type BaseCallApiExtraOptions<TBaseData = DefaultDataType, TBaseErrorData = DefaultDataType, TBaseResultMode extends ResultModeUnion = ResultModeUnion, TBaseThrowOnError extends boolean = DefaultThrowOnError, TBaseResponseType extends ResponseTypeUnion = ResponseTypeUnion, TBasePluginArray extends CallApiPlugin[] = DefaultPluginArray, TBaseSchemas extends CallApiSchemas = DefaultMoreOptions> = Omit<Partial<CallApiExtraOptions<TBaseData, TBaseErrorData, TBaseResultMode, TBaseThrowOnError, TBaseResponseType, TBasePluginArray, TBaseSchemas>>, (typeof optionsEnumToOmitFromBase)[number]> & {
639
+ /**
640
+ * If true, the base options will not be merged with the main options by default.
641
+ *
642
+ * It's recommended to set this to true when you want to handle the options merge manually from the createFetchClient config function signature.
643
+ *
644
+ * This helps prevent main options from overriding base options by default.
645
+ * @default false
646
+ */
647
+ mergeMainOptionsManuallyFromBase?: boolean;
648
+ };
539
649
  type CombinedCallApiExtraOptions = Interceptors & Omit<BaseCallApiExtraOptions & CallApiExtraOptions, keyof Interceptors>;
540
650
  type BaseCallApiConfig<TBaseData = DefaultDataType, TBaseErrorData = DefaultDataType, TBaseResultMode extends ResultModeUnion = ResultModeUnion, TBaseThrowOnError extends boolean = DefaultThrowOnError, TBaseResponseType extends ResponseTypeUnion = ResponseTypeUnion, TBasePluginArray extends CallApiPlugin[] = DefaultPluginArray, TBaseSchemas extends CallApiSchemas = DefaultMoreOptions> = (CallApiRequestOptions<TBaseSchemas> & BaseCallApiExtraOptions<TBaseData, TBaseErrorData, TBaseResultMode, TBaseThrowOnError, TBaseResponseType, TBasePluginArray, TBaseSchemas>) | ((context: {
541
651
  initURL: string;
@@ -784,7 +784,7 @@ var createFetchClient = (baseConfig = {}) => {
784
784
  const mergedExtraOptions = {
785
785
  ...defaultExtraOptions,
786
786
  ...baseExtraOptions,
787
- ...extraOptions
787
+ ...!baseExtraOptions.mergeMainOptionsManuallyFromBase && extraOptions
788
788
  };
789
789
  const mergedRequestOptions = {
790
790
  ...defaultRequestOptions,