@milkio/stargate 1.3.3 → 1.3.5
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/package.json +1 -1
- package/index.d.ts +0 -311
package/package.json
CHANGED
package/index.d.ts
DELETED
|
@@ -1,311 +0,0 @@
|
|
|
1
|
-
export type MilkioStargateOptions = {
|
|
2
|
-
baseUrl: string | (() => string) | (() => Promise<string>);
|
|
3
|
-
timeout?: number;
|
|
4
|
-
fetch?: typeof fetch;
|
|
5
|
-
abort?: typeof AbortController;
|
|
6
|
-
cacheStorage?: CacheStorage;
|
|
7
|
-
cacheEncryption?: boolean;
|
|
8
|
-
};
|
|
9
|
-
export type Mixin<T, U> = U & Omit<T, keyof U>;
|
|
10
|
-
export type CacheStrategy = 'off' | 'fallback' | 'throttle';
|
|
11
|
-
export type RetryStrategy = boolean | number;
|
|
12
|
-
export interface CacheStorage {
|
|
13
|
-
get: (key: string) => Promise<{
|
|
14
|
-
data: any;
|
|
15
|
-
timestamp: number;
|
|
16
|
-
} | null>;
|
|
17
|
-
set: (key: string, data: any) => Promise<void>;
|
|
18
|
-
}
|
|
19
|
-
export type ExecuteOptions<T extends any> = {
|
|
20
|
-
params?: Record<any, any>;
|
|
21
|
-
headers?: Record<string, string>;
|
|
22
|
-
timeout?: number;
|
|
23
|
-
baseUrl?: string | (() => string) | (() => Promise<string>);
|
|
24
|
-
cacheStrategy?: CacheStrategy;
|
|
25
|
-
cacheThrottleMs?: number;
|
|
26
|
-
onCacheHit?: (result: T) => void | Promise<void>;
|
|
27
|
-
retryStrategy?: RetryStrategy;
|
|
28
|
-
};
|
|
29
|
-
export type ExecuteResultsOption = {
|
|
30
|
-
executeId: string;
|
|
31
|
-
};
|
|
32
|
-
export type Ping = [
|
|
33
|
-
{
|
|
34
|
-
connect: false;
|
|
35
|
-
delay: number;
|
|
36
|
-
error: any;
|
|
37
|
-
},
|
|
38
|
-
null
|
|
39
|
-
] | [
|
|
40
|
-
null,
|
|
41
|
-
{
|
|
42
|
-
connect: true;
|
|
43
|
-
delay: number;
|
|
44
|
-
serverTimestamp: number;
|
|
45
|
-
}
|
|
46
|
-
];
|
|
47
|
-
export declare function createStargate<Generated extends {
|
|
48
|
-
routeSchema: any;
|
|
49
|
-
rejectCode: any;
|
|
50
|
-
events: any;
|
|
51
|
-
}>(stargateOptions: MilkioStargateOptions): Promise<{
|
|
52
|
-
options: MilkioStargateOptions;
|
|
53
|
-
execute<Path extends keyof Generated["routeSchema"]>(path: Path, options: Mixin<ExecuteOptions<Generated["routeSchema"][Path]["types"]["result"]>, {
|
|
54
|
-
params?: Generated["routeSchema"][Path]["types"]["params"];
|
|
55
|
-
}>): Promise<Generated["routeSchema"][Path]["types"]["\uD83E\uDD5B"] extends boolean ? // action
|
|
56
|
-
[Partial<Generated["rejectCode"]>, null, ExecuteResultsOption] | [null, Generated["routeSchema"][Path]["types"]["result"], ExecuteResultsOption] : // stream
|
|
57
|
-
[Partial<Generated["rejectCode"]>, null, ExecuteResultsOption] | [null, AsyncGenerator<[Partial<Generated["rejectCode"]>, null] | [null, GeneratorGeneric<Generated["routeSchema"][Path]["types"]["result"]>], undefined>, ExecuteResultsOption]>;
|
|
58
|
-
__cookbook: {
|
|
59
|
-
subscribe: (baseUrl: string) => Promise<any>;
|
|
60
|
-
};
|
|
61
|
-
__astraEmitEvent: (key: any, options?: {
|
|
62
|
-
params?: any;
|
|
63
|
-
headers?: Record<string, string>;
|
|
64
|
-
}) => Promise<any[]>;
|
|
65
|
-
ping(options?: {
|
|
66
|
-
timeout?: number;
|
|
67
|
-
}): Promise<Ping>;
|
|
68
|
-
$types: {
|
|
69
|
-
generated: Generated;
|
|
70
|
-
error: Generated["rejectCode"];
|
|
71
|
-
params: { [Path in keyof Generated["routeSchema"]]: Generated["routeSchema"][Path]["types"]["params"]; };
|
|
72
|
-
results: { [Path in keyof Generated["routeSchema"]]: Generated["routeSchema"][Path]["types"]["\uD83E\uDD5B"] extends boolean ? Generated["routeSchema"][Path]["types"]["result"] : AsyncGenerator<[Partial<Generated["rejectCode"]>, null] | [null, GeneratorGeneric<Generated["routeSchema"][Path]["types"]["result"]>], undefined>; };
|
|
73
|
-
};
|
|
74
|
-
on: <Key extends keyof {
|
|
75
|
-
'milkio:executeBefore': {
|
|
76
|
-
path: string;
|
|
77
|
-
options: Mixin<ExecuteOptions<any>, {
|
|
78
|
-
headers: Record<string, string>;
|
|
79
|
-
baseUrl: string;
|
|
80
|
-
}>;
|
|
81
|
-
};
|
|
82
|
-
'milkio:fetchBefore': {
|
|
83
|
-
path: string;
|
|
84
|
-
options: Mixin<ExecuteOptions<any>, {
|
|
85
|
-
headers: Record<string, string>;
|
|
86
|
-
baseUrl: string;
|
|
87
|
-
}>;
|
|
88
|
-
body: string;
|
|
89
|
-
};
|
|
90
|
-
'milkio:executeError': {
|
|
91
|
-
path: string;
|
|
92
|
-
options: Mixin<ExecuteOptions<any>, {
|
|
93
|
-
headers: Record<string, string>;
|
|
94
|
-
baseUrl: string;
|
|
95
|
-
}>;
|
|
96
|
-
error: Partial<Generated["rejectCode"]>;
|
|
97
|
-
handleError: <K extends keyof Partial<Generated["rejectCode"]>>(error: any, key: K, handler: (error: Partial<Generated["rejectCode"][K]>) => boolean | Promise<boolean>) => Promise<void>;
|
|
98
|
-
};
|
|
99
|
-
}, Handler extends (event: {
|
|
100
|
-
'milkio:executeBefore': {
|
|
101
|
-
path: string;
|
|
102
|
-
options: Mixin<ExecuteOptions<any>, {
|
|
103
|
-
headers: Record<string, string>;
|
|
104
|
-
baseUrl: string;
|
|
105
|
-
}>;
|
|
106
|
-
};
|
|
107
|
-
'milkio:fetchBefore': {
|
|
108
|
-
path: string;
|
|
109
|
-
options: Mixin<ExecuteOptions<any>, {
|
|
110
|
-
headers: Record<string, string>;
|
|
111
|
-
baseUrl: string;
|
|
112
|
-
}>;
|
|
113
|
-
body: string;
|
|
114
|
-
};
|
|
115
|
-
'milkio:executeError': {
|
|
116
|
-
path: string;
|
|
117
|
-
options: Mixin<ExecuteOptions<any>, {
|
|
118
|
-
headers: Record<string, string>;
|
|
119
|
-
baseUrl: string;
|
|
120
|
-
}>;
|
|
121
|
-
error: Partial<Generated["rejectCode"]>;
|
|
122
|
-
handleError: <K extends keyof Partial<Generated["rejectCode"]>>(error: any, key: K, handler: (error: Partial<Generated["rejectCode"][K]>) => boolean | Promise<boolean>) => Promise<void>;
|
|
123
|
-
};
|
|
124
|
-
}[Key]) => void>(key: Key, handler: Handler) => () => void;
|
|
125
|
-
off: <Key extends keyof {
|
|
126
|
-
'milkio:executeBefore': {
|
|
127
|
-
path: string;
|
|
128
|
-
options: Mixin<ExecuteOptions<any>, {
|
|
129
|
-
headers: Record<string, string>;
|
|
130
|
-
baseUrl: string;
|
|
131
|
-
}>;
|
|
132
|
-
};
|
|
133
|
-
'milkio:fetchBefore': {
|
|
134
|
-
path: string;
|
|
135
|
-
options: Mixin<ExecuteOptions<any>, {
|
|
136
|
-
headers: Record<string, string>;
|
|
137
|
-
baseUrl: string;
|
|
138
|
-
}>;
|
|
139
|
-
body: string;
|
|
140
|
-
};
|
|
141
|
-
'milkio:executeError': {
|
|
142
|
-
path: string;
|
|
143
|
-
options: Mixin<ExecuteOptions<any>, {
|
|
144
|
-
headers: Record<string, string>;
|
|
145
|
-
baseUrl: string;
|
|
146
|
-
}>;
|
|
147
|
-
error: Partial<Generated["rejectCode"]>;
|
|
148
|
-
handleError: <K extends keyof Partial<Generated["rejectCode"]>>(error: any, key: K, handler: (error: Partial<Generated["rejectCode"][K]>) => boolean | Promise<boolean>) => Promise<void>;
|
|
149
|
-
};
|
|
150
|
-
}, Handler extends (event: {
|
|
151
|
-
'milkio:executeBefore': {
|
|
152
|
-
path: string;
|
|
153
|
-
options: Mixin<ExecuteOptions<any>, {
|
|
154
|
-
headers: Record<string, string>;
|
|
155
|
-
baseUrl: string;
|
|
156
|
-
}>;
|
|
157
|
-
};
|
|
158
|
-
'milkio:fetchBefore': {
|
|
159
|
-
path: string;
|
|
160
|
-
options: Mixin<ExecuteOptions<any>, {
|
|
161
|
-
headers: Record<string, string>;
|
|
162
|
-
baseUrl: string;
|
|
163
|
-
}>;
|
|
164
|
-
body: string;
|
|
165
|
-
};
|
|
166
|
-
'milkio:executeError': {
|
|
167
|
-
path: string;
|
|
168
|
-
options: Mixin<ExecuteOptions<any>, {
|
|
169
|
-
headers: Record<string, string>;
|
|
170
|
-
baseUrl: string;
|
|
171
|
-
}>;
|
|
172
|
-
error: Partial<Generated["rejectCode"]>;
|
|
173
|
-
handleError: <K extends keyof Partial<Generated["rejectCode"]>>(error: any, key: K, handler: (error: Partial<Generated["rejectCode"][K]>) => boolean | Promise<boolean>) => Promise<void>;
|
|
174
|
-
};
|
|
175
|
-
}[Key]) => void>(key: Key, handler: Handler) => void;
|
|
176
|
-
emit: <Key extends keyof {
|
|
177
|
-
'milkio:executeBefore': {
|
|
178
|
-
path: string;
|
|
179
|
-
options: Mixin<ExecuteOptions<any>, {
|
|
180
|
-
headers: Record<string, string>;
|
|
181
|
-
baseUrl: string;
|
|
182
|
-
}>;
|
|
183
|
-
};
|
|
184
|
-
'milkio:fetchBefore': {
|
|
185
|
-
path: string;
|
|
186
|
-
options: Mixin<ExecuteOptions<any>, {
|
|
187
|
-
headers: Record<string, string>;
|
|
188
|
-
baseUrl: string;
|
|
189
|
-
}>;
|
|
190
|
-
body: string;
|
|
191
|
-
};
|
|
192
|
-
'milkio:executeError': {
|
|
193
|
-
path: string;
|
|
194
|
-
options: Mixin<ExecuteOptions<any>, {
|
|
195
|
-
headers: Record<string, string>;
|
|
196
|
-
baseUrl: string;
|
|
197
|
-
}>;
|
|
198
|
-
error: Partial<Generated["rejectCode"]>;
|
|
199
|
-
handleError: <K extends keyof Partial<Generated["rejectCode"]>>(error: any, key: K, handler: (error: Partial<Generated["rejectCode"][K]>) => boolean | Promise<boolean>) => Promise<void>;
|
|
200
|
-
};
|
|
201
|
-
}, Value extends {
|
|
202
|
-
'milkio:executeBefore': {
|
|
203
|
-
path: string;
|
|
204
|
-
options: Mixin<ExecuteOptions<any>, {
|
|
205
|
-
headers: Record<string, string>;
|
|
206
|
-
baseUrl: string;
|
|
207
|
-
}>;
|
|
208
|
-
};
|
|
209
|
-
'milkio:fetchBefore': {
|
|
210
|
-
path: string;
|
|
211
|
-
options: Mixin<ExecuteOptions<any>, {
|
|
212
|
-
headers: Record<string, string>;
|
|
213
|
-
baseUrl: string;
|
|
214
|
-
}>;
|
|
215
|
-
body: string;
|
|
216
|
-
};
|
|
217
|
-
'milkio:executeError': {
|
|
218
|
-
path: string;
|
|
219
|
-
options: Mixin<ExecuteOptions<any>, {
|
|
220
|
-
headers: Record<string, string>;
|
|
221
|
-
baseUrl: string;
|
|
222
|
-
}>;
|
|
223
|
-
error: Partial<Generated["rejectCode"]>;
|
|
224
|
-
handleError: <K extends keyof Partial<Generated["rejectCode"]>>(error: any, key: K, handler: (error: Partial<Generated["rejectCode"][K]>) => boolean | Promise<boolean>) => Promise<void>;
|
|
225
|
-
};
|
|
226
|
-
}[Key]>(key: Key, value: Value) => Promise<void>;
|
|
227
|
-
}>;
|
|
228
|
-
export declare function reviveJSONParse<T>(json: T): T;
|
|
229
|
-
export interface ExecuteStreamOptions {
|
|
230
|
-
headers?: Record<string, string>;
|
|
231
|
-
timeout?: number;
|
|
232
|
-
}
|
|
233
|
-
export interface ApiSchemaExtend {
|
|
234
|
-
apiValidator: {
|
|
235
|
-
generatedAt: number;
|
|
236
|
-
validate: Record<any, any>;
|
|
237
|
-
};
|
|
238
|
-
apiMethodsSchema: Record<any, any>;
|
|
239
|
-
apiMethodsTypeSchema: Record<any, any>;
|
|
240
|
-
apiTestsSchema: Record<any, any>;
|
|
241
|
-
}
|
|
242
|
-
export type FailCodeExtend = Record<any, (...args: Array<any>) => any>;
|
|
243
|
-
export type BootstrapMiddleware = (data: {
|
|
244
|
-
storage: ClientStorage;
|
|
245
|
-
}) => Promise<void> | void;
|
|
246
|
-
export type BeforeExecuteMiddleware = (data: {
|
|
247
|
-
path: string;
|
|
248
|
-
params: any;
|
|
249
|
-
headers: Record<string, string>;
|
|
250
|
-
storage: ClientStorage;
|
|
251
|
-
}) => Promise<void> | void;
|
|
252
|
-
export type AfterExecuteMiddleware = (data: {
|
|
253
|
-
path: string;
|
|
254
|
-
result: {
|
|
255
|
-
value: any;
|
|
256
|
-
};
|
|
257
|
-
storage: ClientStorage;
|
|
258
|
-
}) => Promise<void> | void;
|
|
259
|
-
export interface MiddlewareOptions {
|
|
260
|
-
bootstrap?: BootstrapMiddleware;
|
|
261
|
-
beforeExecute?: BeforeExecuteMiddleware;
|
|
262
|
-
afterExecute?: AfterExecuteMiddleware;
|
|
263
|
-
}
|
|
264
|
-
export interface ClientStorage {
|
|
265
|
-
getItem: (key: string) => Promise<string | null>;
|
|
266
|
-
setItem: (key: string, value: string) => Promise<void>;
|
|
267
|
-
removeItem: (key: string) => Promise<void>;
|
|
268
|
-
}
|
|
269
|
-
export interface ExecuteResultSuccess<Result> {
|
|
270
|
-
executeId: string;
|
|
271
|
-
success: true;
|
|
272
|
-
data: Result;
|
|
273
|
-
}
|
|
274
|
-
export type GeneratorGeneric<T> = T extends AsyncGenerator<infer I> ? I : never;
|
|
275
|
-
export type FlattenKeys<T, Prefix extends string = ''> = {
|
|
276
|
-
[K in keyof T]: T[K] extends object ? FlattenKeys<T[K], `${Prefix}${Exclude<K, symbol>}.`> : `$input.${Prefix}${Exclude<K, symbol>}`;
|
|
277
|
-
}[keyof T];
|
|
278
|
-
/**
|
|
279
|
-
* Represents a message sent in an event stream
|
|
280
|
-
* https://developer.mozilla.org/en-US/docs/Web/API/Server-sent_events/Using_server-sent_events#Event_stream_format
|
|
281
|
-
*/
|
|
282
|
-
export interface EventSourceMessage {
|
|
283
|
-
data: string;
|
|
284
|
-
}
|
|
285
|
-
/**
|
|
286
|
-
* Converts a ReadableStream into a callback pattern.
|
|
287
|
-
* @param stream The input ReadableStream.
|
|
288
|
-
* @param onChunk A function that will be called on each new byte chunk in the stream.
|
|
289
|
-
* @returns {Promise<void>} A promise that will be resolved when the stream closes.
|
|
290
|
-
*/
|
|
291
|
-
export declare function getBytes(stream: ReadableStream<Uint8Array>, onChunk: (arr: Uint8Array) => void): Promise<void>;
|
|
292
|
-
/**
|
|
293
|
-
* Parses arbitary byte chunks into EventSource line buffers.
|
|
294
|
-
* Each line should be of the format "field: value" and ends with \r, \n, or \r\n.
|
|
295
|
-
* @param onLine A function that will be called on each new EventSource line.
|
|
296
|
-
* @returns A function that should be called for each incoming byte chunk.
|
|
297
|
-
*/
|
|
298
|
-
export declare function getLines(onLine: (line: Uint8Array, fieldLength: number) => void): (arr: Uint8Array) => void;
|
|
299
|
-
/**
|
|
300
|
-
* Parses line buffers into EventSourceMessages.
|
|
301
|
-
* @param onId A function that will be called on each `id` field.
|
|
302
|
-
* @param onRetry A function that will be called on each `retry` field.
|
|
303
|
-
* @param onMessage A function that will be called on each message.
|
|
304
|
-
* @returns A function that should be called for each incoming line buffer.
|
|
305
|
-
*/
|
|
306
|
-
export declare function getMessages(onMessage?: (msg: EventSourceMessage) => void): (line: Uint8Array, fieldLength: number) => void;
|
|
307
|
-
export declare function withResolvers<T = any>(): PromiseWithResolvers<T>;
|
|
308
|
-
export declare function createDefaultCacheStorage(options?: {
|
|
309
|
-
encryption?: boolean;
|
|
310
|
-
encryptionKey?: string;
|
|
311
|
-
}): Promise<CacheStorage>;
|