@magda/utils 2.0.0-alpha.1 → 2.0.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.
- package/README.md +75 -40
- package/dist/index-web.d.ts +40 -0
- package/dist/index-web.js +4386 -658
- package/dist/index.d.ts +40 -0
- package/dist/index.js +8504 -1427
- package/package.json +2 -2
package/README.md
CHANGED
|
@@ -4,40 +4,40 @@ This package includes the following common utilities that may help magda miniors
|
|
|
4
4
|
|
|
5
5
|
```typescript
|
|
6
6
|
export declare function addJwtSecretFromEnvVar<T>(
|
|
7
|
-
|
|
8
|
-
[key in keyof Arguments<T>]: Arguments<T>[key];
|
|
9
|
-
},
|
|
10
|
-
required?: boolean
|
|
11
|
-
): {
|
|
7
|
+
argv: {
|
|
12
8
|
[key in keyof Arguments<T>]: Arguments<T>[key];
|
|
9
|
+
},
|
|
10
|
+
required?: boolean
|
|
11
|
+
): {
|
|
12
|
+
[key in keyof Arguments<T>]: Arguments<T>[key];
|
|
13
13
|
};
|
|
14
14
|
|
|
15
15
|
export declare function arrayToMaybe<T>(rows: T[]): Maybe<T>;
|
|
16
16
|
|
|
17
17
|
export declare class AsyncPage<T> {
|
|
18
|
-
|
|
19
|
-
|
|
20
|
-
|
|
21
|
-
|
|
22
|
-
|
|
23
|
-
|
|
24
|
-
|
|
25
|
-
|
|
26
|
-
|
|
27
|
-
|
|
28
|
-
|
|
18
|
+
readonly requestNextPage: CreateAsyncPage<T>;
|
|
19
|
+
readonly data: T;
|
|
20
|
+
readonly hasData: boolean;
|
|
21
|
+
static create<T>(next: (data: T) => Promise<T>): AsyncPage<T>;
|
|
22
|
+
static single<T>(value: T): AsyncPage<T>;
|
|
23
|
+
static singlePromise<T>(valuePromise: Promise<T>): AsyncPage<T>;
|
|
24
|
+
static none<T>(): AsyncPage<T>;
|
|
25
|
+
constructor(data: T, hasData: boolean, requestNextPage: CreateAsyncPage<T>);
|
|
26
|
+
map<TResult>(selector: (data: T) => TResult): AsyncPage<TResult>;
|
|
27
|
+
forEach(callback: (data: T) => void): Promise<void>;
|
|
28
|
+
take(n: number): AsyncPage<T>;
|
|
29
29
|
}
|
|
30
30
|
|
|
31
31
|
export declare function asyncPageToArray<T>(page: AsyncPage<T[]>): Promise<T[]>;
|
|
32
32
|
|
|
33
33
|
export declare class BadRequestError extends ServiceError {
|
|
34
|
-
|
|
34
|
+
constructor(statusCode: number, errorResponse: ApiError, e: any);
|
|
35
35
|
}
|
|
36
36
|
|
|
37
37
|
export declare function buildJwt(
|
|
38
|
-
|
|
39
|
-
|
|
40
|
-
|
|
38
|
+
jwtSecret: string,
|
|
39
|
+
userId: string,
|
|
40
|
+
session?: any
|
|
41
41
|
): any;
|
|
42
42
|
|
|
43
43
|
export declare const coerceJson: (param: string) => (json?: string) => any;
|
|
@@ -47,47 +47,82 @@ export declare function createServiceError(e: any): Error;
|
|
|
47
47
|
export declare function encodeURIComponentWithApost(string: string): string;
|
|
48
48
|
|
|
49
49
|
export declare function forEachAsync<T>(
|
|
50
|
-
|
|
51
|
-
|
|
52
|
-
|
|
50
|
+
page: AsyncPage<T[]>,
|
|
51
|
+
maxConcurrency: number,
|
|
52
|
+
callbackFn: (data: T) => Promise<void>
|
|
53
53
|
): Promise<void>;
|
|
54
54
|
|
|
55
55
|
export declare function formatServiceError(
|
|
56
|
-
|
|
57
|
-
|
|
58
|
-
|
|
56
|
+
baseMessage: string,
|
|
57
|
+
e: any,
|
|
58
|
+
retriesLeft: number
|
|
59
59
|
): string;
|
|
60
60
|
|
|
61
61
|
export declare function getMinikubeIP(): string;
|
|
62
62
|
|
|
63
63
|
export declare const isUuid: (id: any) => boolean;
|
|
64
64
|
|
|
65
|
+
// deprecated. Please use fetchRequest instead
|
|
65
66
|
export declare const request: any;
|
|
66
67
|
|
|
68
|
+
export declare function fetchRequest<T = any, CT = string>(
|
|
69
|
+
method: string,
|
|
70
|
+
url: string,
|
|
71
|
+
body?: any,
|
|
72
|
+
contentType?: CT | RequestContentType | undefined,
|
|
73
|
+
returnHeaders?: false,
|
|
74
|
+
extraRequestOptions?: RequestInit
|
|
75
|
+
): Promise<T>;
|
|
76
|
+
|
|
77
|
+
export declare function fetchRequest<T = any, CT = string>(
|
|
78
|
+
method: string,
|
|
79
|
+
url: string,
|
|
80
|
+
body?: any,
|
|
81
|
+
contentType?: CT | RequestContentType | undefined,
|
|
82
|
+
returnHeaders?: true,
|
|
83
|
+
extraRequestOptions?: RequestInit
|
|
84
|
+
): Promise<[T, Headers]>;
|
|
85
|
+
|
|
86
|
+
export declare function getDefaultRequestInitOptions(): RequestInit;
|
|
87
|
+
export declare function setDefaultRequestInitOptions(
|
|
88
|
+
options: RequestInit
|
|
89
|
+
): void;
|
|
90
|
+
|
|
91
|
+
export declare function getRequest<T = any, CT = string>(
|
|
92
|
+
url: string,
|
|
93
|
+
noCache?: boolean,
|
|
94
|
+
extraFetchOptions?: RequestInit
|
|
95
|
+
): Promise<T>;
|
|
96
|
+
|
|
97
|
+
export declare function getRequestNoCache<T = any, CT = string>(
|
|
98
|
+
url: string,
|
|
99
|
+
extraFetchOptions?: RequestInit
|
|
100
|
+
): Promise<T>;
|
|
101
|
+
|
|
67
102
|
export declare function retry<T>(
|
|
68
|
-
|
|
69
|
-
|
|
70
|
-
|
|
71
|
-
|
|
72
|
-
|
|
103
|
+
op: () => Promise<T>,
|
|
104
|
+
delaySeconds: number,
|
|
105
|
+
retries: number,
|
|
106
|
+
onRetry: (e: any, retries: number) => any,
|
|
107
|
+
shouldRetry?: (e: any) => boolean
|
|
73
108
|
): Promise<T>;
|
|
74
109
|
|
|
75
110
|
export declare function retryBackoff<T>(
|
|
76
|
-
|
|
77
|
-
|
|
78
|
-
|
|
79
|
-
|
|
80
|
-
|
|
111
|
+
op: () => Promise<T>,
|
|
112
|
+
delaySeconds: number,
|
|
113
|
+
retries: number,
|
|
114
|
+
onRetry: (e: any, retries: number) => any,
|
|
115
|
+
easing?: (delaySeconds: number) => number
|
|
81
116
|
): Promise<T>;
|
|
82
117
|
|
|
83
118
|
export declare function runLater<TResult>(
|
|
84
|
-
|
|
85
|
-
|
|
119
|
+
milliseconds: number,
|
|
120
|
+
functionToRunLater: () => Promise<TResult> | TResult
|
|
86
121
|
): Promise<TResult>;
|
|
87
122
|
|
|
88
123
|
export declare class ServiceError extends Error {
|
|
89
|
-
|
|
90
|
-
|
|
124
|
+
e: any;
|
|
125
|
+
constructor(message: string, e: any);
|
|
91
126
|
}
|
|
92
127
|
|
|
93
128
|
export declare function unionToThrowable<T>(input: T | Error): T;
|
package/dist/index-web.d.ts
CHANGED
|
@@ -49,6 +49,22 @@ declare interface CreateAsyncPage<T> {
|
|
|
49
49
|
(): Promise<AsyncPage<T>>;
|
|
50
50
|
}
|
|
51
51
|
|
|
52
|
+
export declare function createNoCacheFetchOptions(fetchOptions?: RequestInit): {
|
|
53
|
+
body?: BodyInit;
|
|
54
|
+
cache?: RequestCache;
|
|
55
|
+
credentials?: RequestCredentials;
|
|
56
|
+
headers?: HeadersInit;
|
|
57
|
+
integrity?: string;
|
|
58
|
+
keepalive?: boolean;
|
|
59
|
+
method?: string;
|
|
60
|
+
mode?: RequestMode;
|
|
61
|
+
redirect?: RequestRedirect;
|
|
62
|
+
referrer?: string;
|
|
63
|
+
referrerPolicy?: ReferrerPolicy;
|
|
64
|
+
signal?: AbortSignal;
|
|
65
|
+
window?: any;
|
|
66
|
+
};
|
|
67
|
+
|
|
52
68
|
/**
|
|
53
69
|
* Creates a {@link ServiceError} from the result of a failed call to an API generated
|
|
54
70
|
* by swagger-codegen. The result typically includes `response` (with a status code) and
|
|
@@ -67,6 +83,10 @@ declare interface Eq<T> {
|
|
|
67
83
|
equals(t: T): boolean;
|
|
68
84
|
}
|
|
69
85
|
|
|
86
|
+
export declare function fetchRequest<T = any, CT = string>(method: string, url: string, body?: any, contentType?: CT | RequestContentType | undefined | null, returnHeaders?: false, extraRequestOptions?: RequestInit): Promise<T>;
|
|
87
|
+
|
|
88
|
+
export declare function fetchRequest<T = any, CT = string>(method: string, url: string, body?: any, contentType?: CT | RequestContentType | undefined | null, returnHeaders?: true, extraRequestOptions?: RequestInit): Promise<[T, Headers]>;
|
|
89
|
+
|
|
70
90
|
export declare function forEachAsync<T>(page: AsyncPage<T[]>, maxConcurrency: number, callbackFn: (data: T) => Promise<void>): Promise<void>;
|
|
71
91
|
|
|
72
92
|
export declare function formatServiceError(baseMessage: string, e: any, retriesLeft: number): string;
|
|
@@ -77,6 +97,12 @@ declare interface Functor<T> {
|
|
|
77
97
|
map<U>(f: (t: T) => U): Functor<U>;
|
|
78
98
|
}
|
|
79
99
|
|
|
100
|
+
export declare function getDefaultRequestInitOptions(): RequestInit;
|
|
101
|
+
|
|
102
|
+
export declare function getRequest<T = any, CT = string>(url: string, noCache?: boolean, extraFetchOptions?: RequestInit): Promise<T>;
|
|
103
|
+
|
|
104
|
+
export declare function getRequestNoCache<T = any, CT = string>(url: string, extraFetchOptions?: RequestInit): Promise<T>;
|
|
105
|
+
|
|
80
106
|
export declare const isUuid: (id: any) => boolean;
|
|
81
107
|
|
|
82
108
|
declare class Maybe<T> implements Monad<T>, Functor<T>, Eq<Maybe<T>> {
|
|
@@ -134,6 +160,18 @@ declare interface OptionalMaybePatterns<T, U> {
|
|
|
134
160
|
nothing?: () => U;
|
|
135
161
|
}
|
|
136
162
|
|
|
163
|
+
declare type RequestContentType = RequestContentTypeJson | RequestContentTypePlainText | RequestContentTypeForm | RequestContentTypeBinary | RequestContentTypeMultipartForm;
|
|
164
|
+
|
|
165
|
+
declare type RequestContentTypeBinary = "application/octet-stream";
|
|
166
|
+
|
|
167
|
+
declare type RequestContentTypeForm = "application/x-www-form-urlencoded";
|
|
168
|
+
|
|
169
|
+
declare type RequestContentTypeJson = "application/json";
|
|
170
|
+
|
|
171
|
+
declare type RequestContentTypeMultipartForm = "multipart/form-data";
|
|
172
|
+
|
|
173
|
+
declare type RequestContentTypePlainText = "text/plain";
|
|
174
|
+
|
|
137
175
|
export declare function retry<T>(op: () => Promise<T>, delaySeconds: number, retries: number, onRetry: (e: any, retries: number) => any, shouldRetry?: (e: any) => boolean): Promise<T>;
|
|
138
176
|
|
|
139
177
|
export declare function retryBackoff<T>(op: () => Promise<T>, delaySeconds: number, retries: number, onRetry: (e: any, retries: number) => any, easing?: (delaySeconds: number) => number): Promise<T>;
|
|
@@ -145,6 +183,8 @@ export declare class ServiceError extends Error {
|
|
|
145
183
|
constructor(message: string, e: any);
|
|
146
184
|
}
|
|
147
185
|
|
|
186
|
+
export declare function setDefaultRequestInitOptions(options: RequestInit): void;
|
|
187
|
+
|
|
148
188
|
export declare function unionToThrowable<T>(input: T | Error): T;
|
|
149
189
|
|
|
150
190
|
export { }
|