@maiyunnet/kebab 3.1.3 → 3.1.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.
@@ -1,11 +1,11 @@
1
1
  /**
2
2
  * Project: Kebab, User: JianSuoQiYue
3
3
  * Date: 2020-4-9 20:02:39
4
- * Last: 2020-4-9 20:47:58, 2022-09-10 01:35:34
4
+ * Last: 2020-4-9 20:47:58, 2022-09-10 01:35:34, 2025-9-23 12:41:58
5
5
  */
6
6
  import * as stream from 'stream';
7
- import * as response from './response.js';
8
- import * as types from '#types/index.js';
7
+ import * as lNet from '#lib/net.js';
8
+ import * as lResponse from './response.js';
9
9
  export declare class Request {
10
10
  /** --- get 或 post 的数据 --- */
11
11
  private _data;
@@ -70,7 +70,7 @@ export declare class Request {
70
70
  * --- 批量设置提交的 headers ---
71
71
  * @param headers
72
72
  */
73
- headers(headers: types.THttpHeaders): this;
73
+ headers(headers: lNet.THttpHeaders): this;
74
74
  /**
75
75
  * --- 设置单条 header ---
76
76
  * @param name
@@ -81,5 +81,5 @@ export declare class Request {
81
81
  * --- 发起请求 ---
82
82
  * @param cookie
83
83
  */
84
- request(cookie?: Record<string, types.ICookie>): Promise<response.Response>;
84
+ request(cookie?: Record<string, lNet.ICookie>): Promise<lResponse.Response>;
85
85
  }
@@ -1,4 +1,4 @@
1
- import * as net from '#lib/net.js';
1
+ import * as lNet from '#lib/net.js';
2
2
  export class Request {
3
3
  constructor(url) {
4
4
  /** --- get 或 post 的数据 --- */
@@ -115,6 +115,6 @@ export class Request {
115
115
  */
116
116
  request(cookie) {
117
117
  this._opt.cookie = cookie;
118
- return net.request(this._url, this._data, this._opt);
118
+ return lNet.request(this._url, this._data, this._opt);
119
119
  }
120
120
  }
@@ -4,13 +4,13 @@
4
4
  * Last: 2020-4-12 11:12:03, 2022-09-10 12:43:23, 2022-12-25 15:12:57, 2023-9-26 14:20:41
5
5
  */
6
6
  import * as hc from '@litert/http-client';
7
- import * as nStream from 'stream';
8
- import * as types from '#types/index.js';
7
+ import * as stream from 'stream';
8
+ import * as lNet from '#lib/net.js';
9
9
  export declare class Response {
10
10
  /** --- httpClient 请求对象 --- */
11
11
  private readonly _req;
12
12
  /** --- 返回的 headers --- */
13
- headers: types.THttpHeaders | null;
13
+ headers: lNet.THttpHeaders | null;
14
14
  error: Error | null;
15
15
  /** --- 用户自定义的 content 内容 --- */
16
16
  private _content;
@@ -27,9 +27,9 @@ export declare class Response {
27
27
  /**
28
28
  * --- 获取响应读取流对象 ---
29
29
  */
30
- getStream(): nStream.Readable;
30
+ getStream(): stream.Readable;
31
31
  /**
32
32
  * --- 获取原生响应读取流对象 ---
33
33
  */
34
- getRawStream(): nStream.Readable;
34
+ getRawStream(): stream.Readable;
35
35
  }
package/lib/net.d.ts CHANGED
@@ -7,61 +7,11 @@
7
7
  import * as stream from 'stream';
8
8
  import * as http from 'http';
9
9
  import * as http2 from 'http2';
10
- import * as ctr from '#sys/ctr.js';
11
- import * as types from '#types/index.js';
10
+ import * as kebab from '#index.js';
11
+ import * as sCtr from '#sys/ctr.js';
12
12
  import * as fd from './net/formdata.js';
13
13
  import * as lRequest from './net/request.js';
14
- import * as response from './net/response.js';
15
- /** --- 请求的传入参数选项 --- */
16
- export interface IRequestOptions {
17
- 'method'?: 'GET' | 'POST' | 'PUT' | 'DELETE' | 'OPTIONS';
18
- 'type'?: 'form' | 'json';
19
- /** --- 秒数 --- */
20
- 'timeout'?: number;
21
- 'follow'?: number;
22
- 'hosts'?: Record<string, string>;
23
- 'save'?: string;
24
- 'local'?: string;
25
- 'headers'?: types.THttpHeaders;
26
- /** --- 正向 mproxy 代理,url 如 https://xxx/abc --- */
27
- 'mproxy'?: {
28
- 'url': string;
29
- 'auth': string;
30
- 'data'?: any;
31
- };
32
- /** --- 默认为 default --- */
33
- 'reuse'?: string;
34
- /** --- cookie 托管对象 --- */
35
- 'cookie'?: Record<string, types.ICookie>;
36
- }
37
- /** --- 正向代理请求的传入参数选项 --- */
38
- export interface IMproxyOptions {
39
- /** --- 秒数 --- */
40
- 'timeout'?: number;
41
- 'follow'?: number;
42
- 'hosts'?: Record<string, string>;
43
- 'local'?: string;
44
- 'headers'?: types.THttpHeaders;
45
- /** --- 默认为 default --- */
46
- 'reuse'?: string;
47
- }
48
- /** --- 反向代理请求的传入参数选项 --- */
49
- export interface IRproxyOptions {
50
- /** --- 秒数 --- */
51
- 'timeout'?: number;
52
- 'follow'?: number;
53
- 'hosts'?: Record<string, string>;
54
- 'local'?: string;
55
- 'headers'?: types.THttpHeaders;
56
- /** --- 正向 mproxy 代理,url 如 https://xxx/abc --- */
57
- 'mproxy'?: {
58
- 'url': string;
59
- 'auth': string;
60
- 'data'?: any;
61
- };
62
- /** --- 默认为 default --- */
63
- 'reuse'?: string;
64
- }
14
+ import * as lResponse from './net/response.js';
65
15
  /** --- 获取 CA 证书 --- */
66
16
  export declare function getCa(): Promise<string>;
67
17
  /**
@@ -74,26 +24,26 @@ export declare function open(u: string): lRequest.Request;
74
24
  * @param u 请求的 URL
75
25
  * @param opt 参数
76
26
  */
77
- export declare function get(u: string, opt?: IRequestOptions): Promise<response.Response>;
27
+ export declare function get(u: string, opt?: IRequestOptions): Promise<lResponse.Response>;
78
28
  /**
79
29
  * --- 发起一个 post 请求 ---
80
30
  * @param u 请求的 URL
81
31
  * @param data 要发送的数据
82
32
  * @param opt 参数
83
33
  */
84
- export declare function post(u: string, data: Record<string, types.Json> | Buffer | string | stream.Readable, opt?: IRequestOptions): Promise<response.Response>;
34
+ export declare function post(u: string, data: Record<string, kebab.Json> | Buffer | string | stream.Readable, opt?: IRequestOptions): Promise<lResponse.Response>;
85
35
  /**
86
36
  * --- 发起 JSON 请求 ---
87
37
  * @param u
88
38
  * @param data
89
39
  * @param opt
90
40
  */
91
- export declare function postJson(u: string, data: types.Json[] | Record<string, types.Json>, opt?: IRequestOptions): Promise<response.Response>;
41
+ export declare function postJson(u: string, data: kebab.Json[] | Record<string, kebab.Json>, opt?: IRequestOptions): Promise<lResponse.Response>;
92
42
  /**
93
43
  * --- 发起一个请求 ---
94
44
  * @param opt 配置项
95
45
  */
96
- export declare function request(u: string, data?: Record<string, types.Json> | Buffer | string | stream.Readable, opt?: IRequestOptions): Promise<response.Response>;
46
+ export declare function request(u: string, data?: Record<string, kebab.Json> | Buffer | string | stream.Readable, opt?: IRequestOptions): Promise<lResponse.Response>;
97
47
  /**
98
48
  * --- 对 cookie 对象进行操作 ---
99
49
  * @param cookie 要操作的对象
@@ -102,7 +52,7 @@ export declare function request(u: string, data?: Record<string, types.Json> | B
102
52
  * @param domain 应用网址,如 .xxx.com
103
53
  * @param opt 选项 ttl, path, ssl, httponly
104
54
  */
105
- export declare function setCookie(cookie: Record<string, types.ICookie>, name: string, value: string, domain: string, opt?: {
55
+ export declare function setCookie(cookie: Record<string, ICookie>, name: string, value: string, domain: string, opt?: {
106
56
  'ttl'?: number;
107
57
  'path'?: string;
108
58
  'ssl'?: boolean;
@@ -113,12 +63,12 @@ export declare function setCookie(cookie: Record<string, types.ICookie>, name: s
113
63
  * @param cookie cookie 对象
114
64
  * @param uri 请求的 URI 对象
115
65
  */
116
- export declare function buildCookieQuery(cookie: Record<string, types.ICookie>, uri: types.IUrlParse): string;
66
+ export declare function buildCookieQuery(cookie: Record<string, ICookie>, uri: kebab.IUrlParse): string;
117
67
  /**
118
68
  * --- 模拟重启浏览器后的状态 ---
119
69
  * @param cookie cookie 对象
120
70
  */
121
- export declare function resetCookieSession(cookie: Record<string, types.ICookie>): void;
71
+ export declare function resetCookieSession(cookie: Record<string, ICookie>): void;
122
72
  /**
123
73
  * --- 创建 FormData 对象, Mutton: false, Kebab: true ---
124
74
  */
@@ -128,7 +78,7 @@ export declare function getFormData(): fd.FormData;
128
78
  * @param headers 剔除前的 header
129
79
  * @param res 直接设置头部而不返回,可置空
130
80
  */
131
- export declare function filterProxyHeaders(headers: http.IncomingHttpHeaders | http2.IncomingHttpHeaders | types.THttpHeaders, res?: http2.Http2ServerResponse | http.ServerResponse): Record<string, string | string[]>;
81
+ export declare function filterProxyHeaders(headers: http.IncomingHttpHeaders | http2.IncomingHttpHeaders | THttpHeaders, res?: http2.Http2ServerResponse | http.ServerResponse): Record<string, string | string[]>;
132
82
  /**
133
83
  * --- 正向 mproxy 代理,读取 get 的 url 为实际请求地址 ---
134
84
  * --- get: url, auth ---
@@ -136,16 +86,83 @@ export declare function filterProxyHeaders(headers: http.IncomingHttpHeaders | h
136
86
  * @param auth 校验字符串,读取 get 的 auth 和本参数做比对
137
87
  * @param opt 参数
138
88
  */
139
- export declare function mproxy(ctr: ctr.Ctr, auth: string, opt?: IMproxyOptions): Promise<number>;
89
+ export declare function mproxy(ctr: sCtr.Ctr, auth: string, opt?: IMproxyOptions): Promise<number>;
140
90
  /**
141
91
  * --- 获取 mproxy 的附加数据 ---
142
92
  * @param ctr 当前控制器
143
93
  */
144
- export declare function mproxyData(ctr: ctr.Ctr): any;
94
+ export declare function mproxyData(ctr: sCtr.Ctr): any;
145
95
  /**
146
96
  * --- 反向代理,将本服务器的某个路由反代到其他网址 ---
147
97
  * @param ctr 当前控制器
148
98
  * @param route 要反代的路由
149
99
  * @param opt 参数
150
100
  */
151
- export declare function rproxy(ctr: ctr.Ctr, route: Record<string, string>, opt?: IRproxyOptions): Promise<boolean>;
101
+ export declare function rproxy(ctr: sCtr.Ctr, route: Record<string, string>, opt?: IRproxyOptions): Promise<boolean>;
102
+ /** --- 请求的传入参数选项 --- */
103
+ export interface IRequestOptions {
104
+ 'method'?: 'GET' | 'POST' | 'PUT' | 'DELETE' | 'OPTIONS';
105
+ 'type'?: 'form' | 'json';
106
+ /** --- 秒数 --- */
107
+ 'timeout'?: number;
108
+ 'follow'?: number;
109
+ 'hosts'?: Record<string, string>;
110
+ 'save'?: string;
111
+ 'local'?: string;
112
+ 'headers'?: THttpHeaders;
113
+ /** --- 正向 mproxy 代理,url 如 https://xxx/abc --- */
114
+ 'mproxy'?: {
115
+ 'url': string;
116
+ 'auth': string;
117
+ 'data'?: any;
118
+ };
119
+ /** --- 默认为 default --- */
120
+ 'reuse'?: string;
121
+ /** --- cookie 托管对象 --- */
122
+ 'cookie'?: Record<string, ICookie>;
123
+ }
124
+ /** --- 正向代理请求的传入参数选项 --- */
125
+ export interface IMproxyOptions {
126
+ /** --- 秒数 --- */
127
+ 'timeout'?: number;
128
+ 'follow'?: number;
129
+ 'hosts'?: Record<string, string>;
130
+ 'local'?: string;
131
+ 'headers'?: THttpHeaders;
132
+ /** --- 默认为 default --- */
133
+ 'reuse'?: string;
134
+ }
135
+ /** --- 反向代理请求的传入参数选项 --- */
136
+ export interface IRproxyOptions {
137
+ /** --- 秒数 --- */
138
+ 'timeout'?: number;
139
+ 'follow'?: number;
140
+ 'hosts'?: Record<string, string>;
141
+ 'local'?: string;
142
+ 'headers'?: THttpHeaders;
143
+ /** --- 正向 mproxy 代理,url 如 https://xxx/abc --- */
144
+ 'mproxy'?: {
145
+ 'url': string;
146
+ 'auth': string;
147
+ 'data'?: any;
148
+ };
149
+ /** --- 默认为 default --- */
150
+ 'reuse'?: string;
151
+ }
152
+ /** --- http headers --- */
153
+ export type THttpHeaders = http.IncomingHttpHeaders & {
154
+ 'http-version'?: '1.1' | '2.0';
155
+ 'http-code'?: number;
156
+ 'http-url'?: string;
157
+ };
158
+ /** --- Net Cookie 对象 --- */
159
+ export interface ICookie {
160
+ 'name': string;
161
+ 'value': string;
162
+ /** --- 有效期秒级时间戳 --- */
163
+ 'exp': number;
164
+ 'path': string;
165
+ 'domain': string;
166
+ 'secure': boolean;
167
+ 'httponly': boolean;
168
+ }
package/lib/net.js CHANGED
@@ -8,14 +8,14 @@ import * as stream from 'stream';
8
8
  // --- 第三方 ---
9
9
  import * as hc from '@litert/http-client';
10
10
  // --- 库和定义 ---
11
- import * as fs from '#lib/fs.js';
12
- import * as text from '#lib/text.js';
13
- import * as time from '#lib/time.js';
14
11
  import * as kebab from '#index.js';
12
+ import * as lFs from '#lib/fs.js';
13
+ import * as lText from '#lib/text.js';
14
+ import * as lTime from '#lib/time.js';
15
15
  // --- 自己 ---
16
16
  import * as fd from './net/formdata.js';
17
17
  import * as lRequest from './net/request.js';
18
- import * as response from './net/response.js';
18
+ import * as lResponse from './net/response.js';
19
19
  /** --- ca 根证书内容 --- */
20
20
  let ca = '';
21
21
  /** --- 获取 CA 证书 --- */
@@ -23,12 +23,12 @@ export async function getCa() {
23
23
  if (ca) {
24
24
  return ca;
25
25
  }
26
- ca = (await fs.getContent(kebab.LIB_PATH + 'net/cacert.pem', 'utf8')) ?? '';
26
+ ca = (await lFs.getContent(kebab.LIB_PATH + 'net/cacert.pem', 'utf8')) ?? '';
27
27
  return ca;
28
28
  }
29
29
  /** --- 复用的 hc 对象列表 --- */
30
30
  const reuses = {
31
- 'default': hc.createHttpClient()
31
+ 'default': hc.createHttpClient(),
32
32
  };
33
33
  /**
34
34
  * --- 创建一个请求对象 ---
@@ -71,9 +71,9 @@ export async function postJson(u, data, opt = {}) {
71
71
  * @param opt 配置项
72
72
  */
73
73
  export async function request(u, data, opt = {}) {
74
- const uri = text.parseUrl(u);
74
+ const uri = lText.parseUrl(u);
75
75
  /** --- 正向代理的地址 --- */
76
- const puri = opt.mproxy ? text.parseUrl(opt.mproxy.url) : null;
76
+ const puri = opt.mproxy ? lText.parseUrl(opt.mproxy.url) : null;
77
77
  const method = opt.method ?? 'GET';
78
78
  const type = opt.type ?? 'form';
79
79
  const timeout = opt.timeout ?? 10;
@@ -93,7 +93,7 @@ export async function request(u, data, opt = {}) {
93
93
  if (method === 'GET') {
94
94
  if (data && !(data instanceof stream.Readable) && !Buffer.isBuffer(data)) {
95
95
  u += (u.includes('?') ? '&' : '?') +
96
- (typeof data === 'string' ? data : text.queryStringify(data));
96
+ (typeof data === 'string' ? data : lText.queryStringify(data));
97
97
  data = undefined;
98
98
  }
99
99
  }
@@ -101,11 +101,11 @@ export async function request(u, data, opt = {}) {
101
101
  // --- POST ---
102
102
  if (data && !(data instanceof stream.Readable) && !Buffer.isBuffer(data) && typeof data !== 'string') {
103
103
  if (type === 'form') {
104
- data = text.queryStringify(data);
104
+ data = lText.queryStringify(data);
105
105
  headers['content-type'] = 'application/x-www-form-urlencoded';
106
106
  }
107
107
  else {
108
- data = text.stringifyJson(data);
108
+ data = lText.stringifyJson(data);
109
109
  headers['content-type'] = 'application/json; charset=utf-8';
110
110
  }
111
111
  }
@@ -129,7 +129,7 @@ export async function request(u, data, opt = {}) {
129
129
  // --- 重定义 IP ---
130
130
  const host = (puri ? puri.hostname : uri.hostname) ?? '';
131
131
  if (!host) {
132
- const res = new response.Response(null);
132
+ const res = new lResponse.Response(null);
133
133
  res.error = {
134
134
  'name': 'Possible mProxy error',
135
135
  'message': 'host not found'
@@ -137,7 +137,7 @@ export async function request(u, data, opt = {}) {
137
137
  return res;
138
138
  }
139
139
  if (hosts[host] !== undefined && !hosts[host]) {
140
- const res = new response.Response(null);
140
+ const res = new lResponse.Response(null);
141
141
  res.error = {
142
142
  'name': 'hosts error',
143
143
  'message': 'hosts param error'
@@ -148,10 +148,10 @@ export async function request(u, data, opt = {}) {
148
148
  reuses[reuse] = hc.createHttpClient();
149
149
  }
150
150
  req = await reuses[reuse].request({
151
- 'url': opt.mproxy ? opt.mproxy.url + (opt.mproxy.url.includes('?') ? '&' : '?') + text.queryStringify({
151
+ 'url': opt.mproxy ? opt.mproxy.url + (opt.mproxy.url.includes('?') ? '&' : '?') + lText.queryStringify({
152
152
  'url': u,
153
153
  'auth': opt.mproxy.auth,
154
- 'data': opt.mproxy.data ? text.stringifyJson(opt.mproxy.data) : '{}'
154
+ 'data': opt.mproxy.data ? lText.stringifyJson(opt.mproxy.data) : '{}'
155
155
  }) : u,
156
156
  'method': method,
157
157
  'data': data,
@@ -165,7 +165,7 @@ export async function request(u, data, opt = {}) {
165
165
  });
166
166
  }
167
167
  catch (err) {
168
- const res = new response.Response(null);
168
+ const res = new lResponse.Response(null);
169
169
  res.error = err;
170
170
  return res;
171
171
  }
@@ -181,7 +181,7 @@ export async function request(u, data, opt = {}) {
181
181
  if (save && (!req.headers['location'] || follow === 0)) {
182
182
  await new Promise(function (resolve) {
183
183
  req.getStream().on('end', () => {
184
- fs.stats(save).then((stat) => {
184
+ lFs.stats(save).then((stat) => {
185
185
  total = stat?.size ?? 0;
186
186
  resolve();
187
187
  }).catch(() => {
@@ -189,11 +189,11 @@ export async function request(u, data, opt = {}) {
189
189
  });
190
190
  }).on('error', function () {
191
191
  resolve();
192
- }).pipe(fs.createWriteStream(save));
192
+ }).pipe(lFs.createWriteStream(save));
193
193
  });
194
194
  }
195
195
  // --- 创建 Response 对象 ---
196
- const res = new response.Response(req);
196
+ const res = new lResponse.Response(req);
197
197
  if (total) {
198
198
  res.setContent(total.toString());
199
199
  }
@@ -219,7 +219,7 @@ export async function request(u, data, opt = {}) {
219
219
  }
220
220
  // --- 哦,要追踪 ---
221
221
  headers['referer'] = u;
222
- return request(text.urlResolve(u, req.headers['location']), data, {
222
+ return request(lText.urlResolve(u, req.headers['location']), data, {
223
223
  'method': method,
224
224
  'type': type,
225
225
  'timeout': timeout,
@@ -241,7 +241,7 @@ export async function request(u, data, opt = {}) {
241
241
  * @param opt 选项 ttl, path, ssl, httponly
242
242
  */
243
243
  export function setCookie(cookie, name, value, domain, opt = {}) {
244
- const tim = time.stamp();
244
+ const tim = lTime.stamp();
245
245
  const ttl = opt.ttl ?? 0;
246
246
  domain = domain.split(':')[0];
247
247
  const domainN = domain.startsWith('.') ? domain.slice(1) : domain;
@@ -266,7 +266,7 @@ export function setCookie(cookie, name, value, domain, opt = {}) {
266
266
  * @param uri 请求的 URI 对象
267
267
  */
268
268
  async function buildCookieObject(cookie, setCookies, uri) {
269
- const tim = time.stamp();
269
+ const tim = lTime.stamp();
270
270
  uri.path ??= '/';
271
271
  for (const setCookie of setCookies) {
272
272
  const cookieTmp = {};
@@ -312,10 +312,10 @@ async function buildCookieObject(cookie, setCookies, uri) {
312
312
  // --- ok.xxx.com vs .zz.ok.xxx.com: false ---
313
313
  if (uri.hostname !== domainN) {
314
314
  // --- 设置的域名和当前 host 不相等,如果是 IP、无 . 域名,则直接失败 ---
315
- if (!text.isDomain(uri.hostname ?? '')) {
315
+ if (!lText.isDomain(uri.hostname ?? '')) {
316
316
  continue;
317
317
  }
318
- const parseDomain = await text.parseDomain(domainN);
318
+ const parseDomain = await lText.parseDomain(domainN);
319
319
  if (parseDomain.tld === domainN.toLowerCase()) {
320
320
  // --- 不能给 tld 设置 cookie ---
321
321
  continue;
@@ -366,7 +366,7 @@ async function buildCookieObject(cookie, setCookies, uri) {
366
366
  * @param uri 请求的 URI 对象
367
367
  */
368
368
  export function buildCookieQuery(cookie, uri) {
369
- const tim = time.stamp();
369
+ const tim = lTime.stamp();
370
370
  let cookieStr = '';
371
371
  for (const key in cookie) {
372
372
  const item = cookie[key];
@@ -503,7 +503,7 @@ export function mproxyData(ctr) {
503
503
  if (!get['data']) {
504
504
  return {};
505
505
  }
506
- const data = text.parseJson(get['data']);
506
+ const data = lText.parseJson(get['data']);
507
507
  if (!data) {
508
508
  return {};
509
509
  }
package/lib/sql.d.ts CHANGED
@@ -3,8 +3,8 @@
3
3
  * Date: 2019-5-27 20:18:50
4
4
  * Last: 2020-3-29 19:37:25, 2022-07-24 22:38:11, 2023-5-24 18:49:18, 2023-6-13 22:20:21, 2023-12-11 13:58:54, 2023-12-14 13:14:40, 2023-12-21 00:04:40, 2024-4-11 19:29:29, 2024-9-2 17:15:28, 2025-8-3 21:28:18
5
5
  */
6
+ import * as kebab from '#index.js';
6
7
  import * as ctr from '#sys/ctr.js';
7
- import * as types from '#types/index.js';
8
8
  export declare class Sql {
9
9
  /** --- 前置 --- */
10
10
  private readonly _pre;
@@ -13,7 +13,7 @@ export declare class Sql {
13
13
  /** --- 所有 data 数据 --- */
14
14
  private _data;
15
15
  constructor(pre?: string, opt?: {
16
- 'data'?: types.DbValue[];
16
+ 'data'?: kebab.DbValue[];
17
17
  'sql'?: string[];
18
18
  });
19
19
  /**
@@ -31,19 +31,19 @@ export declare class Sql {
31
31
  * @param cs [] 数据列或字段列
32
32
  * @param vs [] | [][] 数据
33
33
  */
34
- values(cs: string[] | Record<string, types.DbValue>, vs?: types.DbValue[] | types.DbValue[][]): this;
34
+ values(cs: string[] | Record<string, kebab.DbValue>, vs?: kebab.DbValue[] | kebab.DbValue[][]): this;
35
35
  /**
36
36
  * --- 不存在则插入,衔接在 insert 之后 ---
37
37
  * @param table 表名
38
38
  * @param insert {'xx': 'xx', 'xx': 'xx'}
39
39
  * @param where [{'xx': 'xx', 'xx': 'xx'}], {'xx': 'xx'}
40
40
  */
41
- notExists(table: string, insert: Record<string, types.DbValue>, where: string | types.Json): this;
41
+ notExists(table: string, insert: Record<string, kebab.DbValue>, where: string | kebab.Json): this;
42
42
  /**
43
43
  * --- 当不能 insert 时,update(仅能配合 insert 方法用) ---
44
44
  * @param s 更新数据
45
45
  */
46
- duplicate(s: types.Json): this;
46
+ duplicate(s: kebab.Json): this;
47
47
  /**
48
48
  * --- '*', 'xx' ---
49
49
  * @param c 字段字符串或字段数组
@@ -55,7 +55,7 @@ export declare class Sql {
55
55
  * @param f 表名
56
56
  * @param s 设定 update 的值
57
57
  */
58
- update(f: string, s: types.Json): this;
58
+ update(f: string, s: kebab.Json): this;
59
59
  private _updateSub;
60
60
  /**
61
61
  * --- 'xx' ---
@@ -81,7 +81,7 @@ export declare class Sql {
81
81
  * @param suf 表后缀
82
82
  * @param pre 表前缀,仅在 join 非默认表前缀时填写
83
83
  */
84
- join(f: string, s?: types.Json, type?: string, suf?: string, pre?: string): this;
84
+ join(f: string, s?: kebab.Json, type?: string, suf?: string, pre?: string): this;
85
85
  /**
86
86
  * --- left join 方法 ---
87
87
  * @param f 表名
@@ -89,7 +89,7 @@ export declare class Sql {
89
89
  * @param suf 表后缀
90
90
  * @param pre 表前缀,仅在 join 非默认表前缀时填写
91
91
  */
92
- leftJoin(f: string, s?: types.Json, suf?: string, pre?: string): this;
92
+ leftJoin(f: string, s?: kebab.Json, suf?: string, pre?: string): this;
93
93
  /**
94
94
  * --- right join 方法 ---
95
95
  * @param f 表名
@@ -97,7 +97,7 @@ export declare class Sql {
97
97
  * @param suf 表后缀
98
98
  * @param pre 表前缀,仅在 join 非默认表前缀时填写
99
99
  */
100
- rightJoin(f: string, s?: types.Json, suf?: string, pre?: string): this;
100
+ rightJoin(f: string, s?: kebab.Json, suf?: string, pre?: string): this;
101
101
  /**
102
102
  * --- inner join 方法 ---
103
103
  * @param f 表名
@@ -105,7 +105,7 @@ export declare class Sql {
105
105
  * @param suf 表后缀
106
106
  * @param pre 表前缀,仅在 join 非默认表前缀时填写
107
107
  */
108
- innerJoin(f: string, s?: types.Json, suf?: string, pre?: string): this;
108
+ innerJoin(f: string, s?: kebab.Json, suf?: string, pre?: string): this;
109
109
  /**
110
110
  * --- full join 方法 ---
111
111
  * @param f 表名
@@ -113,7 +113,7 @@ export declare class Sql {
113
113
  * @param suf 表后缀
114
114
  * @param pre 表前缀,仅在 join 非默认表前缀时填写
115
115
  */
116
- fullJoin(f: string, s?: types.Json, suf?: string, pre?: string): this;
116
+ fullJoin(f: string, s?: kebab.Json, suf?: string, pre?: string): this;
117
117
  /**
118
118
  * --- cross join 方法 ---
119
119
  * @param f 表名
@@ -121,11 +121,11 @@ export declare class Sql {
121
121
  * @param suf 表后缀
122
122
  * @param pre 表前缀,仅在 join 非默认表前缀时填写
123
123
  */
124
- crossJoin(f: string, s?: types.Json, suf?: string, pre?: string): this;
124
+ crossJoin(f: string, s?: kebab.Json, suf?: string, pre?: string): this;
125
125
  /**
126
126
  * --- having 后置筛选器,用法类似 where ---
127
127
  */
128
- having(s?: string | types.Json): this;
128
+ having(s?: string | kebab.Json): this;
129
129
  /** --- where 的 data 的开始处和结束处 --- */
130
130
  private _whereDataPosition;
131
131
  /**
@@ -139,7 +139,7 @@ export declare class Sql {
139
139
  * --- 7. ['JSON_CONTAINS(`uid`, ?)', ['hello']] ---
140
140
  * @param s 筛选数据
141
141
  */
142
- where(s: string | types.Json): this;
142
+ where(s: string | kebab.Json): this;
143
143
  private _whereSub;
144
144
  /**
145
145
  * --- ORDER BY ---
@@ -167,7 +167,7 @@ export declare class Sql {
167
167
  * @param f 可为空,可设置新对象的 table 名变化
168
168
  */
169
169
  copy(f?: string | string[], opt?: {
170
- 'where'?: string | types.Json;
170
+ 'where'?: string | kebab.Json;
171
171
  }): Sql;
172
172
  /**
173
173
  * --- 获取 sql 语句 ---
@@ -176,7 +176,7 @@ export declare class Sql {
176
176
  /**
177
177
  * --- 获取全部 data ---
178
178
  */
179
- getData(): types.DbValue[];
179
+ getData(): kebab.DbValue[];
180
180
  /**
181
181
  * --- 获取定义的 pre ---
182
182
  */
@@ -186,7 +186,7 @@ export declare class Sql {
186
186
  * @param sql
187
187
  * @param data
188
188
  */
189
- format(sql?: string, data?: types.DbValue[]): string;
189
+ format(sql?: string, data?: kebab.DbValue[]): string;
190
190
  /**
191
191
  * --- 在 sql 最后追加字符串 ---
192
192
  * @param sql
@@ -211,7 +211,7 @@ export declare class Sql {
211
211
  * @param opt 参数
212
212
  */
213
213
  export declare function get(ctrPre?: ctr.Ctr | string, opt?: {
214
- 'data'?: types.DbValue[];
214
+ 'data'?: kebab.DbValue[];
215
215
  'sql'?: string[];
216
216
  }): Sql;
217
217
  /**
@@ -219,12 +219,12 @@ export declare function get(ctrPre?: ctr.Ctr | string, opt?: {
219
219
  * @param sql SQL 字符串
220
220
  * @param data DATA 数据
221
221
  */
222
- export declare function format(sql: string, data: types.DbValue[]): string;
222
+ export declare function format(sql: string, data: kebab.DbValue[]): string;
223
223
  /**
224
224
  * --- 将数组兑换为组合的对象(Array/Object mix) ---
225
225
  * @param arr 要转换的数组
226
226
  */
227
- export declare function aoMix(arr: types.Json): Record<string, string | number | types.Json>;
227
+ export declare function aoMix(arr: kebab.Json): Record<string, string | number | kebab.Json>;
228
228
  /** --- 创建字段对象 --- */
229
229
  export declare function column(field: string): {
230
230
  'type': 'column';
package/lib/sql.js CHANGED
@@ -1,8 +1,3 @@
1
- /**
2
- * Project: Kebab, User: JianSuoQiYue
3
- * Date: 2019-5-27 20:18:50
4
- * Last: 2020-3-29 19:37:25, 2022-07-24 22:38:11, 2023-5-24 18:49:18, 2023-6-13 22:20:21, 2023-12-11 13:58:54, 2023-12-14 13:14:40, 2023-12-21 00:04:40, 2024-4-11 19:29:29, 2024-9-2 17:15:28, 2025-8-3 21:28:18
5
- */
6
1
  import * as lText from '#lib/text.js';
7
2
  import * as lCore from '#lib/core.js';
8
3
  // --- 第三方 ---