soonjs 0.0.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.
@@ -0,0 +1,135 @@
1
+ import { PassThrough } from 'stream';
2
+ import { z, ZodType } from 'zod';
3
+ import { default as Observable } from 'zen-observable';
4
+ import { APIOptionsBase, Context, Middleware, PazuAppOptions, PazuFetchOptions, Response, APIOptions } from './types';
5
+ import { vitePluginPazuServer } from './vite-plugin-pazu-server';
6
+ import { vitePluginPazuClient } from './vite-plugin-pazu-client';
7
+
8
+ export interface Meta {
9
+ }
10
+ export interface UserContext {
11
+ }
12
+ export interface Platform {
13
+ }
14
+ export interface Config {
15
+ }
16
+ export { Context, PazuFetchOptions };
17
+ export type ReturnRealType<T extends (...args: any) => any | Promise<(...args: any) => any>, R = ReturnType<T>> = R extends Promise<infer U> ? U : R;
18
+ export type ReturnConfig<ConfigDefine extends () => any, T = ReturnType<ConfigDefine>> = T extends Promise<infer U> ? U : T;
19
+ export declare class PazuApp {
20
+ private options;
21
+ private apis;
22
+ private middlewares;
23
+ private defaultMiddlewares;
24
+ private api404;
25
+ private fnMiddleware;
26
+ private getId;
27
+ config: Config;
28
+ apiList: APIOptions[];
29
+ constructor(options?: PazuAppOptions, callback?: (error: any, app: PazuApp) => void);
30
+ private init;
31
+ /**
32
+ * 调用 API
33
+ */
34
+ fetchRaw(url: string, body?: any, pazuFetchOptions?: PazuFetchOptions): Promise<Response<any>>;
35
+ fetch(url: string, body?: any, pazuFetchOptions?: PazuFetchOptions): Promise<any>;
36
+ }
37
+ export declare const pazuApiSymbol: unique symbol;
38
+ /**
39
+ * 定义 API
40
+ */
41
+ export declare function defineApi<BodySchema extends ZodType<any, any, any>, CustomBody, Data>(options: APIOptionsBase & {
42
+ /**
43
+ * api body 验证模式
44
+ */
45
+ bodySchema?: BodySchema;
46
+ /**
47
+ * api执行方法
48
+ */
49
+ action: (body: BodySchema extends null ? CustomBody : z.infer<BodySchema>, context: Context<{
50
+ bodySchema?: BodySchema;
51
+ }>) => Promise<Data> | Data;
52
+ }): {
53
+ path?: string;
54
+ method?: "get" | "head" | "post" | "put" | "delete" | "connect" | "options" | "trace" | "patch" | "all";
55
+ disabled?: boolean;
56
+ name?: string;
57
+ desc?: string;
58
+ tags?: string[];
59
+ meta?: Meta;
60
+ /**
61
+ * api body 验证模式
62
+ */
63
+ bodySchema?: BodySchema;
64
+ /**
65
+ * api执行方法
66
+ */
67
+ action: (body: BodySchema extends null ? CustomBody : z.infer<BodySchema>, context: Context<{
68
+ bodySchema?: BodySchema;
69
+ }>) => Promise<Data> | Data;
70
+ };
71
+ export declare const pazuServiceSymbol: unique symbol;
72
+ /**
73
+ * 定义服务,使用时会以单例形式被调用
74
+ */
75
+ export declare function defineService<T>(args: {
76
+ /** 服务名称,必须声明才能自动注入且在 client 中使用 */
77
+ serviceName?: string;
78
+ /** 是否自动注入到 contenxt 中,默认为 false */
79
+ autoInject?: boolean;
80
+ /** 是否在 client 中启用,默认为 false */
81
+ enableClient?: boolean;
82
+ /** 服务函数 */
83
+ service: (app: PazuApp) => T | Promise<T>;
84
+ }): () => Promise<T>;
85
+ /**
86
+ * 定义中间件
87
+ */
88
+ export declare function defineMiddleware<T extends Middleware>(middlewareFn: T): T;
89
+ /**
90
+ * 定义配置信息
91
+ */
92
+ export declare function defineConfig<T>(configFn: () => T | Promise<T>): () => T | Promise<T>;
93
+ /**
94
+ * 创建 PazuApp 实例,只允许存在一个
95
+ */
96
+ export declare function createPazuApp(options?: PazuAppOptions): Promise<PazuApp>;
97
+ /**
98
+ * 错误
99
+ */
100
+ export declare function CodeError(message?: string, code?: number): Error;
101
+ /**
102
+ * 使用 SSE,在 API action 中返回该 SSE
103
+ */
104
+ export declare function useSSE<T>({ pingTime, action, }: {
105
+ pingTime?: number;
106
+ action: (subscriber: {
107
+ closed: boolean;
108
+ send(value: {
109
+ event?: string;
110
+ data: T;
111
+ }): void;
112
+ error(message: string): void;
113
+ close(): void;
114
+ }) => any | Promise<any>;
115
+ }): Observable<{
116
+ event: string;
117
+ data?: T;
118
+ message: string;
119
+ }>;
120
+ /**
121
+ * 判断是否为 SSE Body
122
+ */
123
+ export declare function isSSEBody(body: any): boolean;
124
+ /**
125
+ * 处理 SSE Body
126
+ */
127
+ export declare function resolveSSEBody(body: any): PassThrough;
128
+ /**
129
+ * zen-observable
130
+ */
131
+ export { Observable };
132
+ /**
133
+ * Vite Plugin
134
+ */
135
+ export { vitePluginPazuServer, vitePluginPazuClient };