@dcc-bs/communication.bs.js 0.0.1 → 0.0.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.
@@ -0,0 +1,44 @@
1
+ import { default as default_2 } from 'zod';
2
+ import { z } from 'zod';
3
+ import { ZodType } from 'zod';
4
+
5
+ export declare class ApiError extends Error {
6
+ $type: "ApiError";
7
+ errorId: ErrorId;
8
+ debugMessage?: string;
9
+ status: number;
10
+ constructor(errorId: ErrorId, status: number, debugMessage?: string);
11
+ }
12
+
13
+ export declare const ApiErrorResponse: default_2.ZodObject<{
14
+ errorId: default_2.ZodDefault<default_2.ZodOptional<default_2.ZodString>>;
15
+ debugMessage: default_2.ZodOptional<default_2.ZodString>;
16
+ }, default_2.core.$strip>;
17
+
18
+ export declare type ApiErrorResponse = default_2.infer<typeof ApiErrorResponse>;
19
+
20
+ export declare function apiFetch<T extends ZodType>(url: string, options: ApiFetchOptionsWithSchema<T>): Promise<ApiResponse<z.infer<T>>>;
21
+
22
+ export declare function apiFetch<T extends object>(url: string, options?: ApiFetchOptions): Promise<ApiResponse<T>>;
23
+
24
+ export declare function apiFetchMany<T extends ZodType>(url: string, options: ApiFetchOptionsWithSchema<T>): AsyncGenerator<z.infer<T>, void, void>;
25
+
26
+ export declare type ApiFetchOptions = Omit<RequestInit, "body"> & {
27
+ body?: object | FormData;
28
+ };
29
+
30
+ export declare type ApiFetchOptionsWithSchema<T extends ZodType> = ApiFetchOptions & {
31
+ schema: T;
32
+ };
33
+
34
+ export declare function apiFetchTextMany(url: string, options?: ApiFetchOptions): AsyncGenerator<string, void, void>;
35
+
36
+ declare type ApiResponse<T> = T | ApiError;
37
+
38
+ export declare function apiStreamFetch(url: string, options?: ApiFetchOptions): Promise<ApiResponse<ReadableStream<Uint8Array>>>;
39
+
40
+ declare type ErrorId = "unexpected_error" | "fetch_failed" | string;
41
+
42
+ export declare function isApiError(response: unknown): response is ApiError;
43
+
44
+ export { }