wok-server 0.7.1 → 0.8.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.
Files changed (42) hide show
  1. package/README.md +101 -14
  2. package/dist/http-client/index.js +5 -4
  3. package/dist/lock/index.js +5 -2
  4. package/dist/mvc/config.js +4 -2
  5. package/dist/mvc/exchange.js +32 -7
  6. package/dist/mvc/index.js +1 -1
  7. package/dist/mvc/server.js +12 -4
  8. package/dist/mysql/manager/base.js +5 -8
  9. package/dist/mysql/manager/ops/delete.js +2 -1
  10. package/dist/mysql/manager/ops/find.js +8 -4
  11. package/dist/mysql/manager/ops/insert.js +15 -40
  12. package/dist/mysql/manager/ops/update.js +2 -1
  13. package/dist/mysql/manager/ops/upsert.js +11 -31
  14. package/dist/mysql/migration.js +10 -3
  15. package/documentation/en/mysql.md +26 -33
  16. package/documentation/zh-cn/mysql.md +27 -34
  17. package/documentation/zh-cn/philosophy.md +433 -0
  18. package/package.json +1 -1
  19. package/skills/wok-server-api-rules/SKILL.md +113 -0
  20. package/skills/wok-server-code-navigation/SKILL.md +169 -95
  21. package/skills/wok-server-mysql/SKILL.md +16 -10
  22. package/skills/wok-server-mysql/references/version-control.md +7 -5
  23. package/src/http-client/index.ts +8 -7
  24. package/src/lock/index.ts +5 -2
  25. package/src/mvc/config.ts +9 -2
  26. package/src/mvc/exchange.ts +31 -6
  27. package/src/mvc/index.ts +1 -1
  28. package/src/mvc/server.ts +11 -5
  29. package/src/mysql/manager/base.ts +17 -17
  30. package/src/mysql/manager/ops/delete.ts +2 -1
  31. package/src/mysql/manager/ops/find.ts +8 -4
  32. package/src/mysql/manager/ops/insert.ts +23 -61
  33. package/src/mysql/manager/ops/update.ts +2 -1
  34. package/src/mysql/manager/ops/upsert.ts +31 -51
  35. package/src/mysql/migration.ts +14 -3
  36. package/types/http-client/index.d.ts +4 -4
  37. package/types/lock/index.d.ts +3 -0
  38. package/types/mvc/config.d.ts +5 -0
  39. package/types/mvc/exchange.d.ts +13 -3
  40. package/types/mysql/manager/base.d.ts +12 -12
  41. package/types/mysql/manager/ops/insert.d.ts +2 -16
  42. package/types/mysql/manager/ops/upsert.d.ts +3 -4
@@ -38,5 +38,10 @@ export interface WebConfig {
38
38
  * pem 格式证书私钥文件路径
39
39
  */
40
40
  tlsKey: string;
41
+ /**
42
+ * 请求体最大大小(字节),超出返回 413 Payload Too Large。
43
+ * 默认 10MB,设置为 0 表示不限制。
44
+ */
45
+ maxBodySize: number;
41
46
  }
42
47
  export declare function getConfig(): WebConfig;
@@ -3,6 +3,12 @@
3
3
  import { IncomingMessage, ServerResponse } from 'http';
4
4
  import { QueryString } from './query';
5
5
  import { HtmlStuct } from './render';
6
+ /**
7
+ * 请求体超出大小限制时抛出的错误
8
+ */
9
+ export declare class PayloadTooLargeError extends Error {
10
+ constructor(message: string);
11
+ }
6
12
  /**
7
13
  * 服务的数据交换对象.
8
14
  */
@@ -11,9 +17,13 @@ export declare class ServerExchange {
11
17
  readonly request: IncomingMessage;
12
18
  readonly response: ServerResponse;
13
19
  constructor(request: IncomingMessage, response: ServerResponse);
14
- bodyBuffer(): Promise<Buffer>;
15
- bodyText(): Promise<string>;
16
- bodyJson<T>(): Promise<T>;
20
+ /**
21
+ * 读取请求体为 Buffer
22
+ * @param maxSize 最大字节数,不传则使用全局配置 SERVER_MAX_BODY_SIZE,设为 0 不限制
23
+ */
24
+ bodyBuffer(maxSize?: number): Promise<Buffer>;
25
+ bodyText(maxSize?: number): Promise<string>;
26
+ bodyJson<T>(maxSize?: number): Promise<T>;
17
27
  /**
18
28
  * 响应纯文本
19
29
  * @param text 文本内容
@@ -1,7 +1,7 @@
1
1
  import { Pool, PoolConnection } from 'mysql2';
2
2
  import { MysqlConfig } from '../config';
3
3
  import { Table } from '../table-info';
4
- import { DeleteManyOpts, FindOpts, MixCriteria, MysqlPage, MysqlPaginateOpts, MysqlPaginateSelectOpts, OrderBy, UpdateOpts, Updater, InsertValue, FindSelectOpts } from './ops';
4
+ import { DeleteManyOpts, FindOpts, MixCriteria, MysqlPage, MysqlPaginateOpts, MysqlPaginateSelectOpts, OrderBy, UpdateOpts, Updater, FindSelectOpts } from './ops';
5
5
  /**
6
6
  * mysql 管理器基类,提供基础的操作方法.
7
7
  */
@@ -69,7 +69,7 @@ export declare abstract class BaseMysqlManager {
69
69
  * @param criteria
70
70
  * @returns
71
71
  */
72
- deleteOne<T>(table: Table<T>, criteria: Partial<T>): Promise<boolean>;
72
+ deleteOne<T>(table: Table<T>, criteria: MixCriteria<T>): Promise<boolean>;
73
73
  /**
74
74
  * 查询表中所有数据.
75
75
  * @param table 表信息
@@ -87,41 +87,41 @@ export declare abstract class BaseMysqlManager {
87
87
  /**
88
88
  * 插入数据. 不支持自增加长id,id必须提前生成,请使用 uuid.
89
89
  * @param table 表信息
90
- * @param data 数据,数据必须是 T 的实例, T 必须是已配置的实体类类型,否则无法完成操作
90
+ * @param data 完整实体数据,必填字段必须存在
91
91
  * @returns 插入后的数据
92
92
  */
93
- insert<T>(table: Table<T>, data: InsertValue<T>): Promise<T>;
93
+ insert<T>(table: Table<T>, data: T): Promise<T>;
94
94
  /**
95
95
  * 批量插入
96
96
  * @param table 表
97
- * @param list 要插入的数据列表
97
+ * @param list 要插入的完整实体数据列表
98
98
  */
99
- insertMany<T>(table: Table<T>, list: InsertValue<T>[]): Promise<void>;
99
+ insertMany<T>(table: Table<T>, list: T[]): Promise<void>;
100
100
  /**
101
101
  * Upsert 单条数据
102
102
  * 如果主键冲突则更新,否则插入
103
103
  * @param table 表信息
104
- * @param data 数据
104
+ * @param data 完整实体数据
105
105
  * @returns
106
106
  */
107
- upsert<T>(table: Table<T>, data: InsertValue<T>): Promise<T>;
107
+ upsert<T>(table: Table<T>, data: T): Promise<T>;
108
108
  /**
109
109
  * Upsert 多条数据
110
110
  * 如果主键冲突则更新,否则插入
111
111
  * @param table 表
112
- * @param list 要插入的数据列表
112
+ * @param list 要插入的完整实体数据列表
113
113
  * @returns 影响的行数
114
114
  */
115
- upsertMany<T>(table: Table<T>, list: InsertValue<T>[]): Promise<number>;
115
+ upsertMany<T>(table: Table<T>, list: T[]): Promise<number>;
116
116
  /**
117
117
  * Upsert 单条数据(支持自定义更新器)
118
118
  * 如果主键冲突则按自定义逻辑更新,否则插入
119
119
  * @param table 表信息
120
- * @param data 插入的数据
120
+ * @param data 完整实体数据
121
121
  * @param updater 冲突时的更新器
122
122
  * @returns
123
123
  */
124
- upsertWithUpdater<T>(table: Table<T>, data: InsertValue<T>, updater: Updater<T>): Promise<T>;
124
+ upsertWithUpdater<T>(table: Table<T>, data: T, updater: Updater<T>): Promise<T>;
125
125
  /**
126
126
  * 更新
127
127
  * @param table 表信息
@@ -1,20 +1,6 @@
1
1
  import { PoolConnection } from 'mysql2';
2
2
  import { Table } from '../../table-info';
3
3
  import { MysqlConfig } from '../../config';
4
- /**
5
- * 插入值类型,支持在 INSERT VALUES 中使用表达式
6
- */
7
- export type InsertValue<T> = {
8
- [K in keyof T]?: T[K] | ['now'] | ['set', T[K]] | ['expr', string] | ['expr', string, any[]];
9
- };
10
- /**
11
- * 处理 insert value,支持表达式
12
- * @returns { frag: SQL 片段, values: 参数值数组 }
13
- */
14
- export declare function processInsertValue(value: any): {
15
- frag: string;
16
- values: any[];
17
- };
18
4
  /**
19
5
  * 为表插入数据
20
6
  * @param connection
@@ -22,11 +8,11 @@ export declare function processInsertValue(value: any): {
22
8
  * @param data
23
9
  * @returns
24
10
  */
25
- export declare function insert<T>(config: MysqlConfig, connection: PoolConnection, table: Table<T>, data: InsertValue<T>): Promise<T>;
11
+ export declare function insert<T>(config: MysqlConfig, connection: PoolConnection, table: Table<T>, data: T): Promise<T>;
26
12
  /**
27
13
  * 一次插入多条记录
28
14
  * @param connection 连接
29
15
  * @param table 表
30
16
  * @param list 要插入的记录列表
31
17
  */
32
- export declare function insertMany<T>(config: MysqlConfig, connection: PoolConnection, table: Table<T>, list: InsertValue<T>[]): Promise<void>;
18
+ export declare function insertMany<T>(config: MysqlConfig, connection: PoolConnection, table: Table<T>, list: T[]): Promise<void>;
@@ -1,7 +1,6 @@
1
1
  import { PoolConnection } from 'mysql2';
2
2
  import { MysqlConfig } from '../../config';
3
3
  import { Table } from '../../table-info';
4
- import { InsertValue } from './insert';
5
4
  import { Updater } from './update';
6
5
  /**
7
6
  * Upsert 单条数据
@@ -12,7 +11,7 @@ import { Updater } from './update';
12
11
  * @param data
13
12
  * @returns
14
13
  */
15
- export declare function upsert<T>(config: MysqlConfig, connection: PoolConnection, table: Table<T>, data: InsertValue<T>): Promise<T>;
14
+ export declare function upsert<T>(config: MysqlConfig, connection: PoolConnection, table: Table<T>, data: T): Promise<T>;
16
15
  /**
17
16
  * Upsert 多条数据
18
17
  * 如果主键冲突则更新,否则插入
@@ -22,7 +21,7 @@ export declare function upsert<T>(config: MysqlConfig, connection: PoolConnectio
22
21
  * @param list
23
22
  * @returns 影响的行数
24
23
  */
25
- export declare function upsertMany<T>(config: MysqlConfig, connection: PoolConnection, table: Table<T>, list: InsertValue<T>[]): Promise<number>;
24
+ export declare function upsertMany<T>(config: MysqlConfig, connection: PoolConnection, table: Table<T>, list: T[]): Promise<number>;
26
25
  /**
27
26
  * Upsert 单条数据(支持自定义更新器)
28
27
  * 如果主键冲突则按自定义逻辑更新,否则插入
@@ -33,4 +32,4 @@ export declare function upsertMany<T>(config: MysqlConfig, connection: PoolConne
33
32
  * @param updater 冲突时的更新器
34
33
  * @returns
35
34
  */
36
- export declare function upsertWithUpdater<T>(config: MysqlConfig, connection: PoolConnection, table: Table<T>, data: InsertValue<T>, updater: Updater<T>): Promise<T>;
35
+ export declare function upsertWithUpdater<T>(config: MysqlConfig, connection: PoolConnection, table: Table<T>, data: T, updater: Updater<T>): Promise<T>;