k99 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.
package/index.mjs CHANGED
@@ -1,14 +1,15 @@
1
1
  /*!
2
- * k99 v0.7.1
3
- * (c) 2019-2025 猛火Fierflame
2
+ * k99 v0.8.0
3
+ * (c) 2019-2026 猛火Fierflame
4
4
  * @license MIT
5
5
  */
6
6
  /**
7
7
  *
8
8
  * @param {string} str
9
- * @returns {Uint8Array}
9
+ * @returns {Uint8Array<ArrayBuffer>}
10
10
  */
11
11
  function str2utf8bin(str) {
12
+ // @ts-ignore
12
13
  return new TextEncoder().encode(str);
13
14
  }
14
15
  /**
@@ -47,26 +48,15 @@ async function write(writer, chunk) {
47
48
  }
48
49
  }
49
50
 
50
- /**
51
- *
52
- * @param {any} k
53
- * @param {any} v
54
- * @returns {any}
55
- */
56
- function replacer(k, v) {
57
- if (typeof v === 'bigint') {
58
- return String(v);
59
- }
60
- return v;
61
- }
62
51
 
63
52
  /**
64
53
  *
65
54
  * @param {any} result
55
+ * @param {(this: any, key: string, value: any) => any} replacer
66
56
  * @param {Promise<never>} [aborted]
67
57
  * @returns {[BodyInit, number, string] | null}
68
58
  */
69
- function toBodyData(result, aborted) {
59
+ function toBodyData(result, replacer, aborted) {
70
60
  if (result instanceof ReadableStream) {
71
61
  return [result, 0, ''];
72
62
  }
@@ -80,11 +70,16 @@ function toBodyData(result, aborted) {
80
70
  return [result, 0, ''];
81
71
  }
82
72
  if (ArrayBuffer.isView(result) || result instanceof ArrayBuffer) {
73
+ // @ts-ignore
83
74
  return [result, result.byteLength, ''];
84
75
  }
85
76
  if (typeof result === 'string') {
86
77
  const body = str2utf8bin(result);
87
- return [body, body.byteLength, ''];
78
+ return [body, body.byteLength, 'text/plain'];
79
+ }
80
+ if (['bigint', 'boolean', 'number'].includes(typeof result)) {
81
+ const body = str2utf8bin(JSON.stringify(result, replacer));
82
+ return [body, body.byteLength, 'application/json'];
88
83
  }
89
84
  if (typeof result !== 'object') {
90
85
  return null;
@@ -111,11 +106,12 @@ function toBodyData(result, aborted) {
111
106
  *
112
107
  * @param {any} result
113
108
  * @param {Headers} headers
109
+ * @param {(this: any, key: string, value: any) => any} replacer
114
110
  * @param {Promise<never>} [aborted]
115
111
  * @returns
116
112
  */
117
- function toBody(result, headers, aborted) {
118
- const bodyData = toBodyData(result, aborted);
113
+ function toBody(result, headers, replacer, aborted) {
114
+ const bodyData = toBodyData(result, replacer, aborted);
119
115
  if (!bodyData) { return null; }
120
116
  const [body, size, type] = bodyData;
121
117
  if (type && !headers.get('Content-Type')) {
@@ -209,7 +205,7 @@ function clearCookie(
209
205
  }
210
206
  }
211
207
 
212
- /** @import { Context, Cookie, CookieOption, FindHandler, Method, Options, Params, Service } from './types' */
208
+ /** @import { Context, Cookie, CookieOption, FindHandler, HandlerResult, Method, Options, Params, Service } from './types' */
213
209
 
214
210
 
215
211
  const noBodyMethods = new Set(['GET', 'OPTIONS']);
@@ -262,6 +258,18 @@ function getMethod(request, toMethod) {
262
258
  }
263
259
  return /** @type {Method} */(methodStr.toUpperCase());
264
260
  }
261
+ /**
262
+ *
263
+ * @param {any} k
264
+ * @param {any} v
265
+ * @returns {any}
266
+ */
267
+ function defaultReplacer(k, v) {
268
+ if (typeof v === 'bigint') {
269
+ return String(v);
270
+ }
271
+ return v;
272
+ }
265
273
  /**
266
274
  *
267
275
  * @param {Request} request
@@ -269,10 +277,15 @@ function getMethod(request, toMethod) {
269
277
  * @param {Options} [options]
270
278
  * @returns {Promise<Response | null>}
271
279
  */
272
- function main(
273
- request, getHandler,
274
- { runner, error: echoError, catch: catchError, method: toMethod, environment } = {},
275
- ) {
280
+ function main(request, getHandler, {
281
+ runner,
282
+ error: echoError,
283
+ catch: catchError,
284
+ method: toMethod,
285
+ environment,
286
+ replacer: JSONReplacer,
287
+ } = {}) {
288
+ const replacer = typeof JSONReplacer === 'function' ? JSONReplacer : defaultReplacer;
276
289
  /**
277
290
  *
278
291
  * @param {Request} request
@@ -296,12 +309,12 @@ function main(
296
309
  /** @type {any} */
297
310
  let error = null;
298
311
 
299
- let resolve = () => {};
312
+ let resolve = () => { };
300
313
  /** @type {(error: unknown) => void} */
301
- let reject = () => {};
314
+ let reject = () => { };
302
315
  /** @type {Promise<void>} */
303
316
  const donePromise = new Promise((a, b) => { resolve = a; reject = b; });
304
- donePromise.catch(() => {});
317
+ donePromise.catch(() => { });
305
318
 
306
319
  /** @type {Params} */
307
320
  let params = {};
@@ -319,7 +332,7 @@ function main(
319
332
  if (!data || noBodyMethods.has(method.toUpperCase())) {
320
333
  return exec(new Request(fetchUrl, { method, headers, signal }), context);
321
334
  }
322
- const body = toBody(data, headers);
335
+ const body = toBody(data, headers, replacer);
323
336
  return exec(new Request(fetchUrl, { method, headers, signal, body }), context);
324
337
  },
325
338
  done(onfulfilled, onrejected) {
@@ -364,7 +377,7 @@ function main(
364
377
  set responseType(type) { setHeader(responseHeaders, 'content-type', type); },
365
378
  getCookie(name) { return getCookie(sentCookies, name); },
366
379
  setCookie(name, value, { expire, domain, path, secure, httpOnly } = {}) {
367
- sentCookies.push({name, value, expire, domain, path, secure, httpOnly});
380
+ sentCookies.push({ name, value, expire, domain, path, secure, httpOnly });
368
381
  setCookiesHeader(responseHeaders, sentCookies);
369
382
  },
370
383
  /**
@@ -382,16 +395,22 @@ function main(
382
395
  return Promise.race([
383
396
  aborted,
384
397
  Promise.resolve().then(() => getHandler(context, v => { params = v; })),
385
- ]).then(handler => handler ? Promise.race([aborted, handler(context)]).then(result => {
386
- if (result instanceof Response) {
387
- return result;
398
+ ]).then(async handlers => {
399
+ const allHandlers = [handlers].flat().filter(h => typeof h === 'function');
400
+ if (!allHandlers.length) { return null; }
401
+ /** @type {HandlerResult?} */
402
+ let result;
403
+ for (const handle of allHandlers) {
404
+ result = await Promise.race([aborted, handle(context)]);
405
+ if (result !== undefined) { break; }
388
406
  }
407
+ if (result instanceof Response) { return result; }
389
408
  const headers = new Headers(context.responseHeaders);
390
409
  const { status } = context;
391
410
  if (!result) { return new Response(null, { status, headers }); }
392
- const body = toBody(result, headers, aborted);
411
+ const body = toBody(result, headers, replacer, aborted);
393
412
  return new Response(body, { status, headers });
394
- }) : null).then(response => {
413
+ }).then(response => {
395
414
  destroyed = true;
396
415
  resolve();
397
416
  return response;
@@ -419,12 +438,12 @@ function make(getHandler, options) {
419
438
  return r => main(r, getHandler, options);
420
439
  }
421
440
 
422
- /** @import { Context, Handler } from './main/types' */
441
+ /** @import { Context, Handler, HandlerResult } from './main/types' */
423
442
  /**
424
443
  *
425
444
  * @param {Context} context
426
445
  * @param {Handler[]} handlers
427
- * @returns {Promise<string | boolean | object | undefined>}
446
+ * @returns {Promise<HandlerResult>}
428
447
  */
429
448
  async function runHandles(context, handlers) {
430
449
  for (const handle of handlers) {
@@ -626,9 +645,11 @@ function storeService(destroy, exec, options) {
626
645
  /** @import { Onionskin } from './onionskin.mjs' */
627
646
  /**
628
647
  * @callback Packer
629
- * @param {Handler} handler
630
- * @returns {Handler}
648
+ * @param {Handler | Handler[]} handler
649
+ * @returns {Handler | Handler[]}
631
650
  */
651
+
652
+
632
653
  /** @type {Packer} */
633
654
  const noop$1 = h => h;
634
655
  /**
@@ -640,7 +661,7 @@ const noop$1 = h => h;
640
661
  function packer(onionskin, packer = noop$1) {
641
662
  return h => {
642
663
  const handler = packer(h);
643
- return async (ctx) => onionskin(ctx, async () => handler(ctx));
664
+ return async (ctx) => onionskin(ctx, async () => runHandles(ctx, [handler].flat()));
644
665
  };
645
666
  }
646
667
 
@@ -653,7 +674,7 @@ function packer(onionskin, packer = noop$1) {
653
674
  * @returns {PromiseLike<boolean | Handler | void> | boolean | Handler | void}
654
675
  */
655
676
  /**
656
- * @typedef {[Handler | Router, Record<string | symbol, any>, string[]]} FindItem
677
+ * @typedef {[Handler | Handler[] | Router, Record<string | symbol, any>, string[]]} FindItem
657
678
  */
658
679
  /**
659
680
  * @callback Finder
@@ -664,55 +685,6 @@ function packer(onionskin, packer = noop$1) {
664
685
  * @returns {AsyncIterable<FindItem> | Iterable<FindItem>}
665
686
  */
666
687
 
667
- /**
668
- *
669
- * @param {Set<Guard>} guards
670
- * @param {Context} ctx
671
- * @param {(v: any) => void} setParams
672
- * @param {object} params
673
- * @returns {Promise<boolean | Handler>}
674
- */
675
- async function execGuard(guards, ctx, setParams, params) {
676
- if (!guards.size) { return true; }
677
- setParams(params);
678
- for (const guard of guards) {
679
- if (ctx.destroyed) { return false; }
680
- const ret = await guard(Object.create(ctx, {
681
- params: { value: { ...params } },
682
- }));
683
- if (ret === false) { return false; }
684
- // @ts-ignore
685
- if (typeof ret === 'function') { return ret; }
686
- }
687
- return true;
688
- }
689
-
690
- /**
691
- *
692
- * @param {Router | Handler} route
693
- * @param {string[]} path
694
- * @param {Context} ctx
695
- * @param {(v: Params) => void} setParams
696
- * @param {Params} params
697
- * @returns {Promise<Handler | null>}
698
- */
699
- async function find(route, path, ctx, setParams, params) {
700
- if (!(route instanceof Router)) {
701
- setParams(params);
702
- return route;
703
- }
704
- if (route.disabled) { return null; }
705
- const guardResult = await execGuard(route.guards, ctx, setParams, params);
706
- if (!guardResult) { return null; }
707
- if (typeof guardResult === 'function') { return guardResult; }
708
- if (ctx.destroyed) { return null; }
709
- for await (const [r, result, p] of route.find(ctx.method, path, ctx)) {
710
- if (ctx.destroyed) { return null; }
711
- const res = await find(r, p, ctx, setParams, { ...params, ...result });
712
- if (res) { return route.__onionskin(res); }
713
- }
714
- return null;
715
- }
716
688
 
717
689
  /**
718
690
  *
@@ -731,6 +703,29 @@ function uriDecode(t) {
731
703
  */
732
704
  class Router {
733
705
  disabled = false;
706
+ /**
707
+ *
708
+ * @param {Router | Handler[] | Handler} route
709
+ * @param {string[]} path
710
+ * @param {Context} ctx
711
+ * @param {(v: Params) => void} setParams
712
+ * @param {Params} params
713
+ * @returns {Promise<Handler[] | null>}
714
+ */
715
+ static async #find(route, path, ctx, setParams, params) {
716
+ if (!(route instanceof Router)) {
717
+ setParams(params);
718
+ return [route].flat();
719
+ }
720
+ if (route.disabled) { return null; }
721
+ if (ctx.destroyed) { return null; }
722
+ for await (const [r, result, p] of route.find(ctx.method, path, ctx)) {
723
+ if (ctx.destroyed) { return null; }
724
+ const res = await Router.#find(r, p, ctx, setParams, { ...params, ...result });
725
+ if (res) { return [route.#guards, route.#onionskin(res)].flat(); }
726
+ }
727
+ return null;
728
+ }
734
729
  /**
735
730
  * @abstract
736
731
  * @param {Method} method
@@ -749,13 +744,28 @@ class Router {
749
744
  const list = routers.flat();
750
745
  const path = ctx.url.pathname.split('/').filter(Boolean).map(uriDecode);
751
746
  for (const route of list) {
752
- const res = await find(route, path, ctx, setParams, {});
747
+ const res = await Router.#find(route, path, ctx, setParams, {});
753
748
  if (res) { return res; }
754
749
  }
755
750
  return null;
756
751
  };
757
752
  }
758
753
 
754
+
755
+ /** @type {Handler[]} */
756
+ #guards = [];
757
+ /**
758
+ *
759
+ * @param {...Handler | Handler[]} guards
760
+ */
761
+ guard(...guards) {
762
+ const list =this.#guards;
763
+ for (const guard of guards.flat()) {
764
+ if (typeof guard !== 'function') { continue; }
765
+ list.push(guard);
766
+ }
767
+ }
768
+
759
769
  /**
760
770
  *
761
771
  * @param {Finder} find
@@ -766,16 +776,14 @@ class Router {
766
776
  'find': { configurable: true, value: find, writable: true },
767
777
  });
768
778
  }
769
- /** @readonly @type {Set<Guard>} */
770
- guards = new Set();
771
779
  /**
772
780
  *
773
- * @param {Handler} h
774
- * @returns {Handler}
781
+ * @param {Handler | Handler[]} h
782
+ * @returns {Handler | Handler[]}
775
783
  */
776
- __onionskin = (h) => h;
784
+ #onionskin = (h) => h;
777
785
  /** @param {Onionskin} os */
778
- onionskin(os) { this.__onionskin = packer(os, this.__onionskin); }
786
+ onionskin(os) { this.#onionskin = packer(os, this.#onionskin); }
779
787
  }
780
788
 
781
789
  /** @import { Match } from './index.mjs' */
@@ -973,7 +981,7 @@ function toMatch(path, end) {
973
981
  */
974
982
  function bind(routes, methods, match, handlers) {
975
983
  /** @type {Route} */
976
- const route = { match, methods, handler: ctx => runHandles(ctx, handlers) };
984
+ const route = { match, methods, handlers: handlers };
977
985
  routes.push(route);
978
986
  let removed = false;
979
987
  return () => {
@@ -1055,8 +1063,7 @@ function getMethods(methods) {
1055
1063
  * @typedef {object} Route
1056
1064
  * @property {Match} [match] 路径匹配
1057
1065
  * @property {null} [router]
1058
- * @property {string} [plugin] 所属插件
1059
- * @property {Handler} handler 处理函数
1066
+ * @property {Handler[]} handlers 处理函数
1060
1067
  * @property {Set<Method>} methods 方法列表
1061
1068
  */
1062
1069
 
@@ -1143,14 +1150,14 @@ class ApiRouter extends Router {
1143
1150
  const {match} = route;
1144
1151
  if (!match) {
1145
1152
  if (route.router || !path.length) {
1146
- yield [route.router || route.handler, {}, path];
1153
+ yield [route.router || route.handlers, {}, path];
1147
1154
  }
1148
1155
  continue;
1149
1156
  }
1150
1157
  if (!path.length) { continue; }
1151
1158
  const result = match(path);
1152
1159
  if (!result) { continue; }
1153
- yield [route.router || route.handler, ...result];
1160
+ yield [route.router || route.handlers, ...result];
1154
1161
  }
1155
1162
  }
1156
1163
  /**
@@ -1178,25 +1185,25 @@ class ApiRouter extends Router {
1178
1185
  /**
1179
1186
  * @param {Method | Iterable<Method> | ArrayLike<Method>} methods
1180
1187
  * @param {string| Handler} [path]
1181
- * @param {Handler} [handler]
1188
+ * @param {...Handler} handler
1182
1189
  * @returns {Binder | (() => void)}
1183
1190
  */
1184
- verb(methods, path, handler) {
1191
+ verb(methods, path, ...handler) {
1185
1192
  const allMethods = getMethods(methods);
1186
1193
  if (!allMethods.length) { return () => {}; }
1187
- return verb(this.#routes, allMethods, [path, handler]);
1194
+ return verb(this.#routes, allMethods, [path, ...handler]);
1188
1195
  }
1189
1196
  /**
1190
1197
  * 注册 HTTP GET/POST/PUT/DELETE 处理函数
1191
1198
  * @overload
1192
- * @param {Handler} handler 要注册的处理函数
1199
+ * @param {...Handler} handlers 要注册的处理函数
1193
1200
  * @returns {() => void}
1194
1201
  */
1195
1202
  /**
1196
1203
  * 注册处理函数
1197
1204
  * @overload
1198
1205
  * @param {string} path 要注册的路径
1199
- * @param {Handler} handler 要注册的处理函数
1206
+ * @param {...Handler} handlers 要注册的处理函数
1200
1207
  * @returns {() => void}
1201
1208
  */
1202
1209
  /**
@@ -1222,14 +1229,14 @@ class ApiRouter extends Router {
1222
1229
  /**
1223
1230
  * 注册 HTTP GET 处理函数
1224
1231
  * @overload
1225
- * @param {Handler} handler 要注册的处理函数
1232
+ * @param {...Handler} handlers 要注册的处理函数
1226
1233
  * @returns {() => void}
1227
1234
  */
1228
1235
  /**
1229
1236
  * 注册 HTTP GET 处理函数
1230
1237
  * @overload
1231
1238
  * @param {string} path 要注册的路径
1232
- * @param {Handler} handler 要注册的处理函数
1239
+ * @param {...Handler} handlers 要注册的处理函数
1233
1240
  * @returns {() => void}
1234
1241
  */
1235
1242
  /**
@@ -1253,14 +1260,14 @@ class ApiRouter extends Router {
1253
1260
  /**
1254
1261
  * 注册 HTTP POST 处理函数
1255
1262
  * @overload
1256
- * @param {Handler} handler 要注册的处理函数
1263
+ * @param {...Handler} handlers 要注册的处理函数
1257
1264
  * @returns {() => void}
1258
1265
  */
1259
1266
  /**
1260
1267
  * 注册 HTTP POST 处理函数
1261
1268
  * @overload
1262
1269
  * @param {string} path 要注册的路径
1263
- * @param {Handler} handler 要注册的处理函数
1270
+ * @param {...Handler} handlers 要注册的处理函数
1264
1271
  * @returns {() => void}
1265
1272
  */
1266
1273
  /**
@@ -1284,14 +1291,14 @@ class ApiRouter extends Router {
1284
1291
  /**
1285
1292
  * 注册 HTTP PUT 处理函数
1286
1293
  * @overload
1287
- * @param {Handler} handler 要注册的处理函数
1294
+ * @param {...Handler} handlers 要注册的处理函数
1288
1295
  * @returns {() => void}
1289
1296
  */
1290
1297
  /**
1291
1298
  * 注册 HTTP PUT 处理函数
1292
1299
  * @overload
1293
1300
  * @param {string} path 要注册的路径
1294
- * @param {Handler} handler 要注册的处理函数
1301
+ * @param {...Handler} handlers 要注册的处理函数
1295
1302
  * @returns {() => void}
1296
1303
  */
1297
1304
  /**
@@ -1315,14 +1322,14 @@ class ApiRouter extends Router {
1315
1322
  /**
1316
1323
  * 注册 HTTP DELETE 处理函数
1317
1324
  * @overload
1318
- * @param {Handler} handler 要注册的处理函数
1325
+ * @param {...Handler} handlers 要注册的处理函数
1319
1326
  * @returns {() => void}
1320
1327
  */
1321
1328
  /**
1322
1329
  * 注册 HTTP DELETE 处理函数
1323
1330
  * @overload
1324
1331
  * @param {string} path 要注册的路径
1325
- * @param {Handler} handler 要注册的处理函数
1332
+ * @param {...Handler} handlers 要注册的处理函数
1326
1333
  * @returns {() => void}
1327
1334
  */
1328
1335
  /**
@@ -1346,14 +1353,14 @@ class ApiRouter extends Router {
1346
1353
  /**
1347
1354
  * 注册 HTTP HEAD 处理函数
1348
1355
  * @overload
1349
- * @param {Handler} handler 要注册的处理函数
1356
+ * @param {...Handler} handlers 要注册的处理函数
1350
1357
  * @returns {() => void}
1351
1358
  */
1352
1359
  /**
1353
1360
  * 注册 HTTP HEAD 处理函数
1354
1361
  * @overload
1355
1362
  * @param {string} path 要注册的路径
1356
- * @param {Handler} handler 要注册的处理函数
1363
+ * @param {...Handler} handlers 要注册的处理函数
1357
1364
  * @returns {() => void}
1358
1365
  */
1359
1366
  /**
@@ -1377,14 +1384,14 @@ class ApiRouter extends Router {
1377
1384
  /**
1378
1385
  * 注册 HTTP OPTIONS 处理函数
1379
1386
  * @overload
1380
- * @param {Handler} handler 要注册的处理函数
1387
+ * @param {...Handler} handlers 要注册的处理函数
1381
1388
  * @returns {() => void}
1382
1389
  */
1383
1390
  /**
1384
1391
  * 注册 HTTP OPTIONS 处理函数
1385
1392
  * @overload
1386
1393
  * @param {string} path 要注册的路径
1387
- * @param {Handler} handler 要注册的处理函数
1394
+ * @param {...Handler} handlers 要注册的处理函数
1388
1395
  * @returns {() => void}
1389
1396
  */
1390
1397
  /**
package/package.json CHANGED
@@ -1,7 +1,7 @@
1
1
  {
2
2
  "name": "k99",
3
3
  "description": "前后端均可用的 web 服务器",
4
- "version": "0.7.1",
4
+ "version": "0.8.0",
5
5
  "dependencies": {},
6
6
  "keywords": [
7
7
  "k99",
package/services.cjs CHANGED
@@ -1,6 +1,6 @@
1
1
  /*!
2
- * k99 v0.7.1
3
- * (c) 2019-2025 猛火Fierflame
2
+ * k99 v0.8.0
3
+ * (c) 2019-2026 猛火Fierflame
4
4
  * @license MIT
5
5
  */
6
6
  'use strict';
package/services.d.ts CHANGED
@@ -1,6 +1,6 @@
1
1
  /*!
2
- * k99 v0.7.1
3
- * (c) 2019-2025 猛火Fierflame
2
+ * k99 v0.8.0
3
+ * (c) 2019-2026 猛火Fierflame
4
4
  * @license MIT
5
5
  */
6
6
  import { Service } from 'k99';
package/services.js CHANGED
@@ -1,6 +1,6 @@
1
1
  /*!
2
- * k99 v0.7.1
3
- * (c) 2019-2025 猛火Fierflame
2
+ * k99 v0.8.0
3
+ * (c) 2019-2026 猛火Fierflame
4
4
  * @license MIT
5
5
  */
6
6
  (function (global, factory) {
package/services.min.js CHANGED
@@ -1,6 +1,6 @@
1
1
  /*!
2
- * k99 v0.7.1
3
- * (c) 2019-2025 猛火Fierflame
2
+ * k99 v0.8.0
3
+ * (c) 2019-2026 猛火Fierflame
4
4
  * @license MIT
5
5
  */
6
6
  !function(e,n){"object"==typeof exports&&"undefined"!=typeof module?n(exports):"function"==typeof define&&define.amd?define(["exports"],n):n((e="undefined"!=typeof globalThis?globalThis:e||self).k99Services={})}(this,(function(e){"use strict";function n(e){const n=e.indexOf("=");return n<0?[decodeURIComponent(e),""]:[decodeURIComponent(e.substring(0,n)),decodeURIComponent(e.substring(n+1))]}async function t(e){try{const t=await e.text();return t.length?function(e){const t={};for(const o of e.split("&").filter(Boolean)){const[e,r]=n(o);t[e]=e in t?[t[e],r].flat():[r]}return t}(t):null}catch{}return null}e.formBodyService=function(e){const[n,o]=e.requestType.replace(/\s/g,"").split(";");if("application/x-www-form-urlencoded"!==n)return()=>null;if(o&&"charset=UTF-8"!==o)return()=>null;const{request:r}=e;if(r.bodyUsed)return()=>null;const s=t(r);return()=>s},e.jsonBodyService=function(e){const[n,t]=e.requestType.replace(/\s/g,"").split(";");if("application/json"!==n&&"text/json"!==n)return()=>null;if(t&&"charset=UTF-8"!==t)return()=>null;const{request:o}=e;if(o.bodyUsed)return()=>null;const r=o.json();return()=>r}}));
package/services.min.mjs CHANGED
@@ -1,6 +1,6 @@
1
1
  /*!
2
- * k99 v0.7.1
3
- * (c) 2019-2025 猛火Fierflame
2
+ * k99 v0.8.0
3
+ * (c) 2019-2026 猛火Fierflame
4
4
  * @license MIT
5
5
  */
6
6
  function n(n){const t=n.indexOf("=");return t<0?[decodeURIComponent(n),""]:[decodeURIComponent(n.substring(0,t)),decodeURIComponent(n.substring(t+1))]}async function t(t){try{const e=await t.text();return e.length?function(t){const e={};for(const o of t.split("&").filter(Boolean)){const[t,r]=n(o);e[t]=t in e?[e[t],r].flat():[r]}return e}(e):null}catch{}return null}const e=function(n){const[e,o]=n.requestType.replace(/\s/g,"").split(";");if("application/x-www-form-urlencoded"!==e)return()=>null;if(o&&"charset=UTF-8"!==o)return()=>null;const{request:r}=n;if(r.bodyUsed)return()=>null;const s=t(r);return()=>s},o=function(n){const[t,e]=n.requestType.replace(/\s/g,"").split(";");if("application/json"!==t&&"text/json"!==t)return()=>null;if(e&&"charset=UTF-8"!==e)return()=>null;const{request:o}=n;if(o.bodyUsed)return()=>null;const r=o.json();return()=>r};export{e as formBodyService,o as jsonBodyService};
package/services.mjs CHANGED
@@ -1,6 +1,6 @@
1
1
  /*!
2
- * k99 v0.7.1
3
- * (c) 2019-2025 猛火Fierflame
2
+ * k99 v0.8.0
3
+ * (c) 2019-2026 猛火Fierflame
4
4
  * @license MIT
5
5
  */
6
6
  /** @import { Service } from 'k99' */