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.
package/dist/one.d.ts ADDED
@@ -0,0 +1,17 @@
1
+ /**
2
+ *
3
+ * 代码有很多需要优化的地方,时间紧迫,先实现功能,后面再进行优化
4
+ * 1. [ ] 需要支持通用的片段提取
5
+ * 1. [ ] 提取 identifier 的方法可以统一成一个
6
+ * 1. [ ] 静态分析所有依赖变量,如果有非 JSON 标准的类型,则报错
7
+ * 1. [ ] 静态分析对象调用,避免因需要对象某个字段而发送整个对象的情况
8
+ * 1. [ ] ~~静态依赖的语句,还需要分析所有可能,比如在 if for while function 中时被修改,需要连同这些块一起分析提取~~ 不允许修改path在调用的作用域链外
9
+ * 1. [ ] 构建服务端代码时,作用域全使用函数包裹,需要根据实际情况进行函数作用域和块级作用域区分包裹
10
+ * 1. [ ] 编写 vscode 插件,把所有静态依赖的代码全部进行高亮标注
11
+ */
12
+ export declare function getCode({ filename, code, alias, moduleName }: {
13
+ filename: any;
14
+ code: any;
15
+ alias?: string;
16
+ moduleName?: string;
17
+ }): void;
@@ -0,0 +1,5 @@
1
+ export declare function usePazuIdGen({ workerId, isFixedLength, prefix }?: {
2
+ workerId?: number;
3
+ isFixedLength?: boolean;
4
+ prefix?: string;
5
+ }): () => string;
@@ -0,0 +1,88 @@
1
+ import { Config, defineApi, defineConfig, Meta, Platform, PazuApp, UserContext } from '.';
2
+ import { IncomingHttpHeaders, OutgoingHttpHeaders } from 'http';
3
+
4
+ type Method = 'get' | 'head' | 'post' | 'put' | 'delete' | 'connect' | 'options' | 'trace' | 'patch' | 'all';
5
+ export type APIOptionsBase = {
6
+ /**
7
+ * 访问路径,/开头是绝对路径,非绝对路径则仅是替换访问名称而不改变路径层级,可为''
8
+ */
9
+ path?: string;
10
+ /**
11
+ * 访问方法,默认 POST 可在配置中修改
12
+ */
13
+ method?: Method;
14
+ /**
15
+ * 是否停用此 api ,默认为 false
16
+ */
17
+ disabled?: boolean;
18
+ /**
19
+ * api名称
20
+ */
21
+ name?: string;
22
+ /**
23
+ * api说明
24
+ */
25
+ desc?: string;
26
+ /**
27
+ * api标签
28
+ */
29
+ tags?: string[];
30
+ /**
31
+ * api扩展信息
32
+ */
33
+ meta?: Meta;
34
+ };
35
+ export type APIOptions = ReturnType<typeof defineApi>;
36
+ export type Request = {
37
+ headers: IncomingHttpHeaders;
38
+ method: Method;
39
+ body: any;
40
+ queryString: string;
41
+ query: Record<string, string>;
42
+ params: Record<string, string>;
43
+ path: string;
44
+ baseUrl: string;
45
+ url: string;
46
+ reqId: string;
47
+ requestId: string;
48
+ ip: string;
49
+ };
50
+ export type Response<Body = any> = {
51
+ headers: OutgoingHttpHeaders;
52
+ status: number;
53
+ body: Body;
54
+ custom?: any;
55
+ };
56
+ export type Context<APIBodySchema = {}> = {
57
+ req: Request;
58
+ res: Response;
59
+ request: Request;
60
+ response: Response;
61
+ reqId: string;
62
+ requestId: string;
63
+ platform?: Platform;
64
+ currentAPI: APIOptionsBase & APIBodySchema;
65
+ app: PazuApp;
66
+ config: Config;
67
+ meta: Meta;
68
+ } & UserContext;
69
+ export type PazuFetchOptions = {
70
+ headers?: IncomingHttpHeaders;
71
+ method?: Exclude<Method, 'all'>;
72
+ body?: unknown;
73
+ url?: string;
74
+ query?: Record<string, string>;
75
+ ip?: string;
76
+ platform?: Context['platform'];
77
+ };
78
+ export type Middleware = (context: Context, next: () => any) => Promise<void> | void;
79
+ export type PazuAppOptions = {
80
+ baseUrl?: string;
81
+ defaultMethod?: Method;
82
+ onInit?: (app: PazuApp) => void | Promise<void>;
83
+ middlewares?: Middleware[];
84
+ apis?: APIOptions[];
85
+ workId?: number;
86
+ config?: ReturnType<typeof defineConfig>;
87
+ };
88
+ export {};
@@ -0,0 +1,6 @@
1
+ /**
2
+ * 中间件组合处理
3
+ *
4
+ * from koa-compose
5
+ */
6
+ export declare function compose(middleware: any): (context: any, next: any) => Promise<any>;
@@ -0,0 +1,3 @@
1
+ import { Plugin } from 'vite';
2
+
3
+ export declare function vitePluginPazuClient(options?: {}): Plugin;
@@ -0,0 +1,11 @@
1
+ import { Plugin } from 'vite';
2
+
3
+ export declare function vitePluginPazuServer(options?: {
4
+ removeEntry?: boolean;
5
+ entryPath?: string;
6
+ disableApis?: boolean;
7
+ apisDir?: string;
8
+ servicesDir?: string;
9
+ importDirResolve?: (dir: string) => string;
10
+ baseUrl?: string;
11
+ }): Plugin;
package/package.json ADDED
@@ -0,0 +1,44 @@
1
+ {
2
+ "name": "soonjs",
3
+ "version": "0.0.5",
4
+ "description": "",
5
+ "main": "./dist/index.js",
6
+ "types": "./dist/index.d.ts",
7
+ "type": "module",
8
+ "main1": "./src/index.ts",
9
+ "scripts": {
10
+ "dev": "vite-node examples/index.ts",
11
+ "build": "vite build --ssr ./src/index.ts",
12
+ "dev-one": "vite-node --watch src/one.ts",
13
+ "publish": "npm run build && npm publish --registry=https://registry.npmjs.com",
14
+ "npm:adduser": "npm adduser --registry=https://registry.npmjs.com"
15
+ },
16
+ "publishConfig": {
17
+ "access": "public",
18
+ "registry": "https://registry.npmjs.com"
19
+ },
20
+ "keywords": [],
21
+ "author": "lanbomo",
22
+ "license": "ISC",
23
+ "devDependencies": {
24
+ "@babel/generator": "^7.25.0",
25
+ "@babel/parser": "^7.25.3",
26
+ "@babel/traverse": "^7.25.3",
27
+ "@babel/types": "^7.25.2",
28
+ "@types/node": "^20.14.12",
29
+ "@types/zen-observable": "^0.8.7",
30
+ "fast-glob": "^3.3.2",
31
+ "path-to-regexp": "^7.1.0",
32
+ "prettier": "^3.3.3",
33
+ "qs": "^6.13.0",
34
+ "typescript": "^5.5.4",
35
+ "vite": "^5.3.5",
36
+ "vite-node": "^2.0.4",
37
+ "vite-plugin-dts": "4.0.0-beta.2",
38
+ "zen-observable": "^0.10.0",
39
+ "zod": "^3.23.8"
40
+ },
41
+ "files": [
42
+ "dist"
43
+ ]
44
+ }