@maiyunnet/kebab 9.29.5 → 10.0.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 (64) hide show
  1. package/abox/proxy.js +24 -2
  2. package/abox/response.js +36 -17
  3. package/abox/session-login.js +1 -13
  4. package/abox/text.d.ts +2 -0
  5. package/abox/text.js +51 -0
  6. package/doc/kebab-rag.md +2700 -1270
  7. package/index.d.ts +12 -1
  8. package/index.js +1 -1
  9. package/lib/ai.d.ts +4 -0
  10. package/lib/ai.js +32 -16
  11. package/lib/cookie.d.ts +2 -0
  12. package/lib/cookie.js +47 -45
  13. package/lib/core.d.ts +26 -0
  14. package/lib/core.js +36 -13
  15. package/lib/cron.js +1 -8
  16. package/lib/crypto.js +20 -6
  17. package/lib/db/conn.d.ts +10 -1
  18. package/lib/db/conn.js +1 -5
  19. package/lib/db/pool.d.ts +10 -2
  20. package/lib/db/pool.js +0 -6
  21. package/lib/db/tran.d.ts +10 -1
  22. package/lib/db/tran.js +0 -5
  23. package/lib/db.d.ts +3 -3
  24. package/lib/fs.js +78 -31
  25. package/lib/kv.d.ts +216 -88
  26. package/lib/kv.js +520 -230
  27. package/lib/s3.d.ts +2 -0
  28. package/lib/s3.js +14 -27
  29. package/lib/session.d.ts +7 -0
  30. package/lib/session.js +23 -2
  31. package/lib/socket.d.ts +4 -1
  32. package/lib/socket.js +1 -0
  33. package/lib/sql.d.ts +0 -5
  34. package/lib/sql.js +48 -12
  35. package/lib/text.d.ts +32 -8
  36. package/lib/text.js +30 -17
  37. package/lib/turnstile.d.ts +6 -0
  38. package/lib/turnstile.js +16 -9
  39. package/lib/undici/response.d.ts +13 -3
  40. package/lib/undici/response.js +0 -1
  41. package/lib/undici.d.ts +33 -1
  42. package/lib/undici.js +72 -56
  43. package/lib/vector.d.ts +33 -19
  44. package/lib/vector.js +0 -1
  45. package/lib/ws.d.ts +1 -1
  46. package/lib/ws.js +85 -128
  47. package/lib/zip.js +46 -45
  48. package/package.json +2 -2
  49. package/sys/child.js +178 -146
  50. package/sys/cmd.js +196 -197
  51. package/sys/ctr.d.ts +14 -14
  52. package/sys/ctr.js +145 -59
  53. package/sys/master.js +111 -80
  54. package/sys/mod.d.ts +112 -51
  55. package/sys/mod.js +23 -51
  56. package/sys/monitor/files.d.ts +2 -1
  57. package/sys/monitor/files.js +77 -21
  58. package/sys/monitor/watchdog.d.ts +7 -0
  59. package/sys/monitor/watchdog.js +311 -203
  60. package/sys/monitor.d.ts +59 -54
  61. package/sys/monitor.js +742 -681
  62. package/sys/route.d.ts +4 -4
  63. package/sys/route.js +93 -52
  64. package/www/example/ctr/test.js +8 -8
package/abox/proxy.js CHANGED
@@ -1,6 +1,7 @@
1
1
  const excludedHeaders = new Set([
2
2
  'host', 'connection', 'keep-alive', 'http-code', 'http-url',
3
3
  'transfer-encoding', 'upgrade', 'proxy-connection',
4
+ 'te', 'trailer', 'proxy-authenticate', 'proxy-authorization',
4
5
  ]);
5
6
  const privateHeaders = new Set([
6
7
  'forwarded', 'via', 'x-real-ip', 'true-client-ip', 'client-ip', 'x-client-ip',
@@ -10,8 +11,22 @@ const privateHeaders = new Set([
10
11
  export function filterProxyHeaders(headers, res, filter) {
11
12
  const result = {};
12
13
  const sent = res?.headersSent ?? false;
14
+ const dynamicHopByHop = new Set();
13
15
  for (const name in headers) {
14
- if (excludedHeaders.has(name) || name.includes(':') || name.includes('(')) {
16
+ if (name.toLowerCase() === 'connection') {
17
+ const raw = headers[name];
18
+ const text = Array.isArray(raw) ? raw.join(',') : String(raw ?? '');
19
+ for (const part of text.split(',')) {
20
+ const token = part.trim().toLowerCase();
21
+ if (token) {
22
+ dynamicHopByHop.add(token);
23
+ }
24
+ }
25
+ }
26
+ }
27
+ for (const name in headers) {
28
+ const lower = name.toLowerCase();
29
+ if (excludedHeaders.has(lower) || dynamicHopByHop.has(lower) || name.includes(':') || name.includes('(')) {
15
30
  continue;
16
31
  }
17
32
  const value = headers[name];
@@ -32,7 +47,14 @@ export function filterProxyHeaders(headers, res, filter) {
32
47
  export function buildProxyHeaders(req, opt = {}) {
33
48
  const headers = filterProxyHeaders(req.headers, undefined, opt.filter);
34
49
  if (opt.proxyMode === undefined || opt.proxyMode === 'passthrough') {
35
- return Object.assign(headers, opt.headers);
50
+ const merged = {};
51
+ for (const name in headers) {
52
+ merged[name.toLowerCase()] = headers[name];
53
+ }
54
+ for (const name in opt.headers) {
55
+ merged[name.toLowerCase()] = opt.headers[name];
56
+ }
57
+ return merged;
36
58
  }
37
59
  const result = {};
38
60
  for (const name in headers) {
package/abox/response.js CHANGED
@@ -4,6 +4,31 @@ export function pipeResponse(parts, response, compress, onInputDone) {
4
4
  const sources = parts.filter((part) => part instanceof stream.Readable);
5
5
  let failure;
6
6
  let inputDone = false;
7
+ const h2Stream = response.stream;
8
+ const isClosed = () => {
9
+ if (response.destroyed || response.writableEnded || response.closed) {
10
+ return true;
11
+ }
12
+ return !!(h2Stream && (h2Stream.destroyed || h2Stream.writableEnded || h2Stream.closed));
13
+ };
14
+ const stopSources = () => {
15
+ for (const source of sources) {
16
+ if (!source.destroyed) {
17
+ source.destroy();
18
+ }
19
+ }
20
+ };
21
+ const finishInput = () => {
22
+ if (!inputDone) {
23
+ inputDone = true;
24
+ onInputDone?.();
25
+ }
26
+ };
27
+ if (isClosed()) {
28
+ stopSources();
29
+ finishInput();
30
+ return;
31
+ }
7
32
  const combined = stream.Readable.from((async function* () {
8
33
  for (const part of parts) {
9
34
  if (failure) {
@@ -19,13 +44,6 @@ export function pipeResponse(parts, response, compress, onInputDone) {
19
44
  }
20
45
  }
21
46
  })());
22
- const stopSources = () => {
23
- for (const source of sources) {
24
- if (!source.destroyed) {
25
- source.destroy();
26
- }
27
- }
28
- };
29
47
  const onError = (error) => {
30
48
  failure ??= error;
31
49
  if (!inputDone) {
@@ -38,22 +56,23 @@ export function pipeResponse(parts, response, compress, onInputDone) {
38
56
  source.once('close', () => source.off('error', onError));
39
57
  }
40
58
  response.once('close', stopSources);
41
- const finishInput = () => {
42
- if (!inputDone) {
43
- inputDone = true;
44
- onInputDone?.();
45
- }
46
- };
59
+ h2Stream?.once('close', stopSources);
47
60
  combined.once('end', finishInput);
48
61
  const done = () => {
49
62
  stopSources();
50
63
  response.off('close', stopSources);
64
+ h2Stream?.off('close', stopSources);
51
65
  finishInput();
52
66
  };
53
- if (compress) {
54
- stream.pipeline(combined, compress, response, done);
67
+ try {
68
+ if (compress) {
69
+ stream.pipeline(combined, compress, response, done);
70
+ }
71
+ else {
72
+ stream.pipeline(combined, response, done);
73
+ }
55
74
  }
56
- else {
57
- stream.pipeline(combined, response, done);
75
+ catch {
76
+ done();
58
77
  }
59
78
  }
@@ -150,19 +150,7 @@ export class Store {
150
150
  async _run(args) {
151
151
  if (!this._valid)
152
152
  return false;
153
- try {
154
- const pipeline = await this._kv.pipeline();
155
- if (pipeline === false)
156
- return false;
157
- pipeline.eval(script, [this._pre], args);
158
- const result = await pipeline.exec();
159
- if (result.length !== 1 || result[0] instanceof Error)
160
- return false;
161
- return result[0];
162
- }
163
- catch {
164
- return false;
165
- }
153
+ return this._kv.eval(script, [this._pre], args);
166
154
  }
167
155
  async create(token, identity, options) {
168
156
  if (!this._valid || !tokenValid(token))
package/abox/text.d.ts CHANGED
@@ -1,3 +1,5 @@
1
+ import type { IJsonObject } from '#kebab/lib/text.js';
1
2
  export declare function redact(value: string, secrets: readonly string[], replacement: string, encoded: boolean): string;
2
3
  export declare function parseJson<T>(str: string): T | false;
3
4
  export declare function stringifyJson(obj: unknown, space?: string | number): string;
5
+ export declare function normalizeJsonObject(value: unknown): IJsonObject | false;
package/abox/text.js CHANGED
@@ -55,3 +55,54 @@ export function stringifyJson(obj, space) {
55
55
  return typeof value === 'bigint' ? nativeJson.rawJSON(value.toString()) : value;
56
56
  }, space);
57
57
  }
58
+ function copyJson(value, ancestors) {
59
+ if (value === null || typeof value === 'string' || typeof value === 'boolean' ||
60
+ (typeof value === 'number' && Number.isFinite(value)))
61
+ return value;
62
+ if (typeof value !== 'object' || ancestors.has(value))
63
+ throw new TypeError();
64
+ const array = Array.isArray(value);
65
+ if (!array) {
66
+ const proto = Object.getPrototypeOf(value);
67
+ if (proto !== null && proto !== Object.prototype)
68
+ throw new TypeError();
69
+ }
70
+ ancestors.add(value);
71
+ const keys = Reflect.ownKeys(value);
72
+ let result;
73
+ if (array) {
74
+ if (keys.length !== value.length + 1)
75
+ throw new TypeError();
76
+ const items = [];
77
+ for (let i = 0; i < value.length; ++i)
78
+ items.push(copyProperty(value, i, ancestors));
79
+ result = items;
80
+ }
81
+ else {
82
+ const object = Object.create(null);
83
+ for (const key of keys.sort()) {
84
+ if (typeof key !== 'string')
85
+ throw new TypeError();
86
+ object[key] = copyProperty(value, key, ancestors);
87
+ }
88
+ result = object;
89
+ }
90
+ ancestors.delete(value);
91
+ return result;
92
+ }
93
+ function copyProperty(object, key, ancestors) {
94
+ const prop = Object.getOwnPropertyDescriptor(object, key);
95
+ if (!prop?.enumerable || !Object.hasOwn(prop, 'value'))
96
+ throw new TypeError();
97
+ return copyJson(prop.value, ancestors);
98
+ }
99
+ export function normalizeJsonObject(value) {
100
+ try {
101
+ if (value === null || typeof value !== 'object' || Array.isArray(value))
102
+ return false;
103
+ return copyJson(value, new Set());
104
+ }
105
+ catch {
106
+ return false;
107
+ }
108
+ }