native-document 1.0.50 → 1.0.51

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/index.js CHANGED
@@ -11,7 +11,6 @@ import './src/utils/prototypes.js';
11
11
  export * from './src/utils/property-accumulator';
12
12
  export * from './src/utils/args-types';
13
13
  export * from './src/utils/memoize';
14
- export * from './src/utils/service';
15
14
  export * from './src/data/Observable';
16
15
  export * from './src/data/observable-helpers/array';
17
16
  export * from './src/data/observable-helpers/batch';
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "native-document",
3
- "version": "1.0.50",
3
+ "version": "1.0.51",
4
4
  "main": "index.js",
5
5
  "type": "module",
6
6
  "scripts": {
@@ -0,0 +1,71 @@
1
+ type HttpMethod = 'GET' | 'POST' | 'PUT' | 'DELETE' | 'PATCH';
2
+
3
+ interface FetchConfig {
4
+ method: HttpMethod;
5
+ headers: Record<string, string>;
6
+ body?: string | FormData;
7
+ params?: Record<string, any>;
8
+ }
9
+
10
+ interface FetchOptions {
11
+ headers?: Record<string, string>;
12
+ }
13
+
14
+ type RequestInterceptor = (
15
+ config: FetchConfig,
16
+ endpoint: string
17
+ ) => Promise<FetchConfig | void> | FetchConfig | void;
18
+
19
+ type ResponseInterceptor = (
20
+ response: Response,
21
+ endpoint: string
22
+ ) => Promise<Response | void> | Response | void;
23
+
24
+ interface NativeFetchError extends Error {
25
+ status: number;
26
+ data: any;
27
+ }
28
+
29
+ interface Interceptors {
30
+ request: (callback: RequestInterceptor) => void;
31
+ response: (callback: ResponseInterceptor) => void;
32
+ }
33
+
34
+ declare class NativeFetch {
35
+ constructor(baseUrl: string);
36
+
37
+ interceptors: Interceptors;
38
+
39
+ fetch<T = any>(
40
+ method: HttpMethod,
41
+ endpoint: string,
42
+ params?: Record<string, any> | FormData,
43
+ options?: FetchOptions
44
+ ): Promise<T>;
45
+
46
+ get<T = any>(
47
+ endpoint: string,
48
+ params?: Record<string, any>,
49
+ options?: FetchOptions
50
+ ): Promise<T>;
51
+
52
+ post<T = any>(
53
+ endpoint: string,
54
+ params?: Record<string, any> | FormData,
55
+ options?: FetchOptions
56
+ ): Promise<T>;
57
+
58
+ put<T = any>(
59
+ endpoint: string,
60
+ params?: Record<string, any> | FormData,
61
+ options?: FetchOptions
62
+ ): Promise<T>;
63
+
64
+ delete<T = any>(
65
+ endpoint: string,
66
+ params?: Record<string, any>,
67
+ options?: FetchOptions
68
+ ): Promise<T>;
69
+ }
70
+
71
+ export default NativeFetch;
@@ -0,0 +1,13 @@
1
+ type ServiceFactory<T> = () => T;
2
+ type MemoizedFactory<T, Args extends any[]> = (...args: Args) => T;
3
+
4
+ interface ServiceStatic {
5
+
6
+ once<T>(fn: ServiceFactory<T>): ServiceFactory<T>;
7
+
8
+ memoize<T, Args extends any[]>(
9
+ fn: MemoizedFactory<T, Args>
10
+ ): MemoizedFactory<T, Args>;
11
+ }
12
+
13
+ export const Service: ServiceStatic;
package/utils.d.ts CHANGED
@@ -0,0 +1,3 @@
1
+
2
+ export * from './types/native-fetch';
3
+ export * from './types/service';
package/utils.js CHANGED
@@ -1,6 +1,8 @@
1
1
  import NativeFetch from "./src/utils/fetch/NativeFetch";
2
+ import { Service } from "./src/utils/service";
2
3
 
3
4
 
4
5
  export {
5
- NativeFetch
6
+ NativeFetch,
7
+ Service
6
8
  };