@magda/utils 2.3.2 → 3.0.0-alpha.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.
@@ -1,200 +1,17 @@
1
- /// <reference types="node" />
2
- import { Arguments } from 'yargs';
3
-
4
- /**
5
- * Checks to see whether the passed argv has a jwtSecret object. If not,
6
- * tries to add one by looking at the JWT_SECRET env var and failing that,
7
- * the jwtSecret value in package.json config.
8
- *
9
- * If it can't find one and required is true (or unprovided), this will
10
- * throw an Error.
11
- */
12
- export declare function addJwtSecretFromEnvVar<T>(argv: {
13
- [key in keyof Arguments<T>]: Arguments<T>[key];
14
- }, required?: boolean): {
15
- [key in keyof Arguments<T>]: Arguments<T>[key];
16
- };
17
-
18
- declare class ApiError {
19
- 'message': string;
20
- }
21
-
22
- export declare function arrayToMaybe<T>(rows: T[]): Maybe<T>;
23
-
24
- export declare class AsyncPage<T> {
25
- readonly requestNextPage: CreateAsyncPage<T>;
26
- readonly data: T;
27
- readonly hasData: boolean;
28
- static create<T>(next: (data: T) => Promise<T>): AsyncPage<T>;
29
- static single<T>(value: T): AsyncPage<T>;
30
- static singlePromise<T>(valuePromise: Promise<T>): AsyncPage<T>;
31
- static none<T>(): AsyncPage<T>;
32
- constructor(data: T, hasData: boolean, requestNextPage: CreateAsyncPage<T>);
33
- map<TResult>(selector: (data: T) => TResult): AsyncPage<TResult>;
34
- forEach(callback: (data: T) => void): Promise<void>;
35
- take(n: number): AsyncPage<T>;
36
- }
37
-
38
- export declare function asyncPageToArray<T>(page: AsyncPage<T[]>): Promise<T[]>;
39
-
40
- export declare class BadRequestError extends ServiceError {
41
- constructor(statusCode: number, errorResponse: ApiError, e: any);
42
- }
43
-
44
- export declare function buildJwt(jwtSecret: string, userId: string, session?: any): any;
45
-
46
- export declare const coerceJson: (param: string) => (json?: string | object | any[]) => any;
47
-
48
- declare interface CreateAsyncPage<T> {
49
- (): Promise<AsyncPage<T>>;
50
- }
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
-
68
- /**
69
- * Creates a {@link ServiceError} from the result of a failed call to an API generated
70
- * by swagger-codegen. The result typically includes `response` (with a status code) and
71
- * a `body` (the JSON the server returned with the error), but may be other things if,
72
- * e.g., an exception occurred while attempting to invoke the service.
73
- *
74
- * @export
75
- * @param {*} e The result of the failed call.
76
- * @returns {Error} An Error created from the failed result.
77
- */
78
- export declare function createServiceError(e: any): Error;
79
-
80
- export declare function encodeURIComponentWithApost(string: string): string;
81
-
82
- declare interface Eq<T> {
83
- equals(t: T): boolean;
84
- }
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
-
90
- export declare function forEachAsync<T>(page: AsyncPage<T[]>, maxConcurrency: number, callbackFn: (data: T) => Promise<void>): Promise<void>;
91
-
92
- export declare function formatServiceError(baseMessage: string, e: any, retriesLeft: number): string;
93
-
94
- declare interface Functor<T> {
95
- fmap<U>(f: (t: T) => U): Functor<U>;
96
- lift<U>(f: (t: T) => U): Functor<U>;
97
- map<U>(f: (t: T) => U): Functor<U>;
98
- }
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
-
106
- export declare const isUuid: (id: any) => boolean;
107
-
108
- declare class Maybe<T> implements Monad<T>, Functor<T>, Eq<Maybe<T>> {
109
- private type;
110
- private value;
111
- constructor(type: MaybeType, value?: T);
112
- static sequence<T>(t: {
113
- [k: string]: Maybe<T>;
114
- }): Maybe<{
115
- [k: string]: T;
116
- }>;
117
- static all: (t: {
118
- [k: string]: Maybe<any>;
119
- }) => Maybe<{
120
- [k: string]: any;
121
- }>;
122
- static maybe<T>(t: T): Maybe<T>;
123
- static just<T>(t: T): Maybe<T>;
124
- static nothing<T>(): Maybe<T>;
125
- unit<U>(u: U): Maybe<U>;
126
- bind<U>(f: (t: T) => Maybe<U>): Maybe<U>;
127
- of: <U>(u: U) => Maybe<U>;
128
- chain: <U>(f: (t: T) => Maybe<U>) => Maybe<U>;
129
- fmap<U>(f: (t: T) => U): Maybe<U>;
130
- lift: <U>(f: (t: T) => U) => Maybe<U>;
131
- map: <U>(f: (t: T) => U) => Maybe<U>;
132
- caseOf<U>(patterns: MaybePatterns<T, U>): U;
133
- defaulting(defaultValue: T): Maybe<T>;
134
- equals(other: Maybe<T>): any;
135
- valueOr<U extends T>(defaultValue: U): T | U;
136
- valueOrCompute<U extends T>(defaultValueFunction: () => U): T | U;
137
- valueOrThrow(error?: Error): T;
138
- do(patterns?: OptionalMaybePatterns<T, void>): Maybe<T>;
139
- }
140
-
141
- declare interface MaybePatterns<T, U> {
142
- just: (t: T) => U;
143
- nothing: () => U;
144
- }
145
-
146
- declare enum MaybeType {
147
- Nothing = 0,
148
- Just = 1,
149
- }
150
-
151
- declare interface Monad<T> {
152
- unit<U>(t: U): Monad<U>;
153
- bind<U>(f: (t: T) => Monad<U>): Monad<U>;
154
- of<U>(t: U): Monad<U>;
155
- chain<U>(f: (t: T) => Monad<U>): Monad<U>;
156
- }
157
-
158
- declare interface OptionalMaybePatterns<T, U> {
159
- just?: (t: T) => U;
160
- nothing?: () => U;
161
- }
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
-
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>;
176
-
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>;
178
-
179
- export declare function runLater<TResult>(milliseconds: number, functionToRunLater: () => Promise<TResult> | TResult): Promise<TResult>;
180
-
181
- declare class ServerError extends Error {
182
- statusCode: number;
183
- constructor(message?: string, statusCode?: number);
184
- toData(): {
185
- isError: boolean;
186
- errorCode: number;
187
- errorMessage: string;
188
- };
189
- }
190
-
191
- export declare class ServiceError extends Error {
192
- e: any;
193
- constructor(message: string, e: any);
194
- }
195
-
196
- export declare function setDefaultRequestInitOptions(options: RequestInit): void;
197
-
198
- export declare function unionToThrowable<T>(input: T | Error | ServerError): T;
199
-
200
- export { }
1
+ export { default as arrayToMaybe } from "@magda/typescript-common/dist/util/arrayToMaybe.js";
2
+ export { default as isUuid } from "@magda/typescript-common/dist/util/isUuid.js";
3
+ export { default as unionToThrowable } from "@magda/typescript-common/dist/util/unionToThrowable.js";
4
+ export { default as AsyncPage, forEachAsync, asyncPageToArray } from "@magda/typescript-common/dist/AsyncPage.js";
5
+ export { default as coerceJson } from "@magda/typescript-common/dist/coerceJson.js";
6
+ export { default as retry } from "@magda/typescript-common/dist/retry.js";
7
+ export { default as retryBackoff } from "@magda/typescript-common/dist/retryBackoff.js";
8
+ export { default as runLater } from "@magda/typescript-common/dist/runLater.js";
9
+ export { default as addJwtSecretFromEnvVar } from "@magda/typescript-common/dist/session/addJwtSecretFromEnvVar.js";
10
+ export { encodeURIComponentWithApost } from "@magda/typescript-common/dist/test/util.js";
11
+ export { default as formatServiceError } from "@magda/typescript-common/dist/formatServiceError.js";
12
+ export { default as createServiceError, ServiceError, BadRequestError } from "@magda/typescript-common/dist/createServiceError.js";
13
+ export { default as fetchRequest } from "@magda/typescript-common/dist/fetchRequest.js";
14
+ export { getDefaultRequestInitOptions, setDefaultRequestInitOptions } from "@magda/typescript-common/dist/fetchRequest.js";
15
+ export { default as getRequest } from "@magda/typescript-common/dist/getRequest.js";
16
+ export { default as getRequestNoCache } from "@magda/typescript-common/dist/getRequestNoCache.js";
17
+ export { default as createNoCacheFetchOptions } from "@magda/typescript-common/dist/createNoCacheFetchOptions.js";