k99 0.6.0 → 0.6.1

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.cjs CHANGED
@@ -1,6 +1,6 @@
1
1
  /*!
2
- * k99 v0.6.0
3
- * (c) 2019-2024 猛火Fierflame
2
+ * k99 v0.6.1
3
+ * (c) 2019-2025 猛火Fierflame
4
4
  * @license MIT
5
5
  */
6
6
  'use strict';
@@ -13,20 +13,6 @@
13
13
  function str2utf8bin(str) {
14
14
  return new TextEncoder().encode(str);
15
15
  }
16
- /**
17
- *
18
- * @param {unknown} chunk
19
- * @returns {chunk is ArrayBuffer | SharedArrayBuffer}
20
- */
21
- function isBufferSource(chunk) {
22
- if (chunk instanceof ArrayBuffer) { return true; }
23
- try {
24
- if (chunk instanceof SharedArrayBuffer) { return true; }
25
- } catch {
26
-
27
- }
28
- return false;
29
- }
30
16
  /**
31
17
  *
32
18
  * @template T
@@ -51,7 +37,7 @@ async function write(writer, chunk) {
51
37
  if (ArrayBuffer.isView(chunk)) {
52
38
  return writer.write(new Uint8Array(chunk.buffer, chunk.byteOffset, chunk.byteLength));
53
39
  }
54
- if (isBufferSource(chunk)) {
40
+ if (chunk instanceof ArrayBuffer) {
55
41
  return writer.write(new Uint8Array(chunk));
56
42
  }
57
43
  if (!isIterable(chunk)) {
@@ -95,7 +81,7 @@ function toBodyData(result, aborted) {
95
81
  if (result instanceof FormData) {
96
82
  return [result, 0, ''];
97
83
  }
98
- if (ArrayBuffer.isView(result) || isBufferSource(result)) {
84
+ if (ArrayBuffer.isView(result) || result instanceof ArrayBuffer) {
99
85
  return [result, result.byteLength, ''];
100
86
  }
101
87
  if (typeof result === 'string') {
package/index.d.ts CHANGED
@@ -1,6 +1,6 @@
1
1
  /*!
2
- * k99 v0.6.0
3
- * (c) 2019-2024 猛火Fierflame
2
+ * k99 v0.6.1
3
+ * (c) 2019-2025 猛火Fierflame
4
4
  * @license MIT
5
5
  */
6
6
  type Method = 'GET' | 'POST' | 'PUT' | 'DELETE' | 'HEAD' | 'OPTIONS';
@@ -476,7 +476,7 @@ type RouteBinder<T extends Router | Finder = ApiRouter> = (router?: T | undefine
476
476
  * @param {Packer} [packer]
477
477
  * @returns {Packer}
478
478
  */
479
- declare function packer(onionskin: Onionskin, packer?: Packer | undefined): Packer;
479
+ declare function packer(onionskin: Onionskin, packer?: Packer): Packer;
480
480
  type Packer = (handler: Handler) => Handler;
481
481
 
482
482
  /**
@@ -486,7 +486,7 @@ type Packer = (handler: Handler) => Handler;
486
486
  * @param {import('./types').Options} [options]
487
487
  * @returns {Promise<Response | null>}
488
488
  */
489
- declare function main(request: Request, getHandler: FindHandler, { runner, error: echoError, catch: catchError, method: toMethod, environment }?: Options | undefined): Promise<Response | null>;
489
+ declare function main(request: Request, getHandler: FindHandler, { runner, error: echoError, catch: catchError, method: toMethod, environment }?: Options): Promise<Response | null>;
490
490
 
491
491
  /**
492
492
  *
@@ -590,6 +590,7 @@ declare function storeService<T>(destroy?: ((state: T | undefined, ctx: Context,
590
590
  * @param {((request: Request) => Response | Promise<Response>)?} [notFound]
591
591
  * @returns {(input: RequestInfo, init?: RequestInit) => Promise<Response>}
592
592
  */
593
- declare function createFetch(run: (request: Request) => Promise<Response | null>, notFound?: ((request: Request) => Response | Promise<Response>) | null | undefined): (input: RequestInfo, init?: RequestInit) => Promise<Response>;
593
+ declare function createFetch(run: (request: Request) => Promise<Response | null>, notFound?: ((request: Request) => Response | Promise<Response>) | null): (input: RequestInfo, init?: RequestInit) => Promise<Response>;
594
594
 
595
- export { ApiRouter, type Binder, type Context, type Cookie, type CookieOption, type FindHandler, type FindItem, type Finder, type Guard, type Handler, type HandlerResult, type Match, type Method, type Onionskin, type Options, type Packer, type Route, type RouteBinder, Router, type RouterRoute, type Runner, Service, type StateService, type StoreService, createFetch, main, make, merge, onionskin, packer, service, stateService, storeService };
595
+ export { ApiRouter, Router, Service, createFetch, main, make, merge, onionskin, packer, service, stateService, storeService };
596
+ export type { Binder, Context, Cookie, CookieOption, FindHandler, FindItem, Finder, Guard, Handler, HandlerResult, Match, Method, Onionskin, Options, Packer, Route, RouteBinder, RouterRoute, Runner, StateService, StoreService };
package/index.js CHANGED
@@ -1,6 +1,6 @@
1
1
  /*!
2
- * k99 v0.6.0
3
- * (c) 2019-2024 猛火Fierflame
2
+ * k99 v0.6.1
3
+ * (c) 2019-2025 猛火Fierflame
4
4
  * @license MIT
5
5
  */
6
6
  (function (global, factory) {
@@ -17,20 +17,6 @@
17
17
  function str2utf8bin(str) {
18
18
  return new TextEncoder().encode(str);
19
19
  }
20
- /**
21
- *
22
- * @param {unknown} chunk
23
- * @returns {chunk is ArrayBuffer | SharedArrayBuffer}
24
- */
25
- function isBufferSource(chunk) {
26
- if (chunk instanceof ArrayBuffer) { return true; }
27
- try {
28
- if (chunk instanceof SharedArrayBuffer) { return true; }
29
- } catch {
30
-
31
- }
32
- return false;
33
- }
34
20
  /**
35
21
  *
36
22
  * @template T
@@ -55,7 +41,7 @@
55
41
  if (ArrayBuffer.isView(chunk)) {
56
42
  return writer.write(new Uint8Array(chunk.buffer, chunk.byteOffset, chunk.byteLength));
57
43
  }
58
- if (isBufferSource(chunk)) {
44
+ if (chunk instanceof ArrayBuffer) {
59
45
  return writer.write(new Uint8Array(chunk));
60
46
  }
61
47
  if (!isIterable(chunk)) {
@@ -99,7 +85,7 @@
99
85
  if (result instanceof FormData) {
100
86
  return [result, 0, ''];
101
87
  }
102
- if (ArrayBuffer.isView(result) || isBufferSource(result)) {
88
+ if (ArrayBuffer.isView(result) || result instanceof ArrayBuffer) {
103
89
  return [result, result.byteLength, ''];
104
90
  }
105
91
  if (typeof result === 'string') {
package/index.min.js CHANGED
@@ -1,6 +1,6 @@
1
1
  /*!
2
- * k99 v0.6.0
3
- * (c) 2019-2024 猛火Fierflame
2
+ * k99 v0.6.1
3
+ * (c) 2019-2025 猛火Fierflame
4
4
  * @license MIT
5
5
  */
6
- !function(e,t){"object"==typeof exports&&"undefined"!=typeof module?t(exports):"function"==typeof define&&define.amd?define(["exports"],t):t((e="undefined"!=typeof globalThis?globalThis:e||self).k99={})}(this,(function(e){"use strict";function t(e){return(new TextEncoder).encode(e)}function n(e){if(e instanceof ArrayBuffer)return!0;try{if(e instanceof SharedArrayBuffer)return!0}catch{}return!1}function r(e){return Symbol.asyncIterator in e||Symbol.iterator in e}async function o(e,i){if("string"==typeof i)return e.write(t(i));if("object"==typeof i){if(ArrayBuffer.isView(i))return e.write(new Uint8Array(i.buffer,i.byteOffset,i.byteLength));if(n(i))return e.write(new Uint8Array(i));if(r(i))for await(const t of i)t&&await o(e,t)}}function i(e,t){return"bigint"==typeof t?String(t):t}function s(e,s,u){const c=function(e,s){if(e instanceof ReadableStream)return[e,0,""];if(e instanceof URLSearchParams)return[e,0,""];if(e instanceof Blob)return[e,e.size,e.type];if(e instanceof FormData)return[e,0,""];if(ArrayBuffer.isView(e)||n(e))return[e,e.byteLength,""];if("string"==typeof e){const n=t(e);return[n,n.byteLength,""]}if("object"!=typeof e)return null;if(Array.isArray(e)||!r(e)){const n=t(JSON.stringify(e,i));return[n,n.byteLength,"application/json"]}const{writable:u,readable:c}=new TransformStream,f=u.getWriter();return s?.catch((e=>{u.abort(e||new DOMException("The user aborted a request.")).catch((()=>{}))})),(async()=>{for await(const t of e)t&&await o(f,t);await u.close()})().catch((()=>{})),[c,0,""]}(e,u);if(!c)return null;const[f,a,l]=c;return l&&!s.get("Content-Type")&&s.set("Content-Type",l),a>0&&!s.get("Content-Length")&&s.set("Content-Length",String(a)),f}function u(e,t){e.delete("set-cookie");for(const{name:n,value:r,expire:o,domain:i,path:s,secure:u,httpOnly:c}of t)n&&e.append("set-cookie",[`${encodeURI(n)}=${encodeURI(r||"")}`,o&&`Expires=${o}`,i&&`Domain=${encodeURI(i)}`,s&&`Path=${encodeURI(s)}`,u&&"Secure",c&&"HttpOnly"].filter(Boolean).join("; "))}const c=new Set(["GET","OPTIONS"]);function f(e,t,n){n?e.set(t,n):e.delete(t)}function a(e,t,{runner:n,error:r,catch:o,method:i,environment:a}={}){return function e(l,p){const h=function(e,t){let n="";return"string"==typeof t?n=t:"function"==typeof t&&(n=t(e)),n&&"string"==typeof n||(n=e.method||"GET"),n.toUpperCase()}(l,i),y=new URL(l.url),{signal:d,headers:g}=l,m=function(e){return new Promise(((t,n)=>{if(e.aborted)return n(e.reason);e.addEventListener("abort",(()=>n(e.reason)),{once:!0})}))}(d),w=new Map,b=function(e){let t={};for(const n of e.replace(/\s/g,"").split(";")){const e=n.split("=");t[decodeURIComponent(e.shift())]=decodeURIComponent(e.join("="))}return t}(g.get("cookie")||""),O=[],T=new Headers,E=p?.root;let S=200,j=!1,R=null,P=()=>{},U=()=>{};const k=new Promise(((e,t)=>{P=e,U=t}));k.catch((()=>{}));let v={};const A={environment:a,parent:p,get error(){return R},get root(){return E||this},signal:d,url:y,fetch(t,{method:n="get",signal:r,body:o,headers:i}={}){const u=new URL(t,y),f=new Headers(i||{});if(!o||c.has(n.toUpperCase()))return e(new Request(u,{method:n,headers:f,signal:r}),A);const a=s(o,f);return e(new Request(u,{method:n,headers:f,signal:r,body:a}),A)},done(e,t){if(j)return null;const n=k.then(e,t);return n.catch(r),n},service(e,...t){if(e.rootOnly&&E)return E.service(e,...t);let n=w.get(e);if(!n){if(n=e(A),"function"!=typeof n)return;w.set(e,n)}return n(...t)},method:h,get params(){return v},requestHeaders:g,requestType:g.get("content-type")||"",referer:g.get("referer")||"",userAgent:g.get("user-agent")||"",accept:(g.get("accept")||"").split(/,\s*/).filter(Boolean),acceptLanguage:(g.get("accept-language")||"").split(/,\s*/).filter(Boolean),cookies:b,request:l,get destroyed(){return j},get status(){return S},set status(e){S=e},responseHeaders:T,get location(){return T.get("location")||""},set location(e){f(T,"location",e)},get responseType(){return T.get("content-type")||""},set responseType(e){f(T,"content-type",e)},getCookie:e=>function*(e,t){const n=e;for(const e of n)t&&e.name!==t||(yield{...e})}(O,e),setCookie(e,t,{expire:n,domain:r,path:o,secure:i,httpOnly:s}={}){O.push({name:e,value:t,expire:n,domain:r,path:o,secure:i,httpOnly:s}),u(T,O)},clearCookie(e,t){!function(e,t,n,r){let o="Fri, 31 Dec 1999 16:00:00 GMT";if("string"==typeof n){if(!n)return;const{domain:t,path:i,secure:s,httpOnly:u}=!0!==r&&r||{};e.push({name:n,value:"delete",expire:o,domain:t,path:i,secure:s,httpOnly:u})}else{const{domain:i,path:s,secure:u,httpOnly:c}=n||{};if(e.length=0,r)for(let n in t)e.push({name:n,value:"delete",expire:o,domain:i,path:s,secure:u,httpOnly:c})}}(O,b,e,t),u(T,O)}};function x(){return Promise.race([m,Promise.resolve().then((()=>t(A,(e=>{v=e}))))]).then((e=>e?Promise.race([m,e(A)]).then((e=>{if(e instanceof Response)return e;const t=new Headers(A.responseHeaders),{status:n}=A;if(!e)return new Response(null,{status:n,headers:t});const r=s(e,t,m);return new Response(r,{status:n,headers:t})})):null)).then((e=>(j=!0,P(),e)),(e=>(j=!0,R=e||!0,U(R),Promise.reject(e)))).catch(o)}return n?n(A,x):x()}(e)}const l=e=>e;function p(e,t=l){return n=>{const r=t(n);return async t=>e(t,(async()=>r(t)))}}async function h(e,t,n,r,o){if(!(e instanceof d))return r(o),e;if(e.disabled)return null;const i=await async function(e,t,n,r){if(!e.size)return!0;n(r);for(const n of e){if(t.destroyed)return!1;const e=await n(Object.create(t,{params:{value:{...r}}}));if(!1===e)return!1;if("function"==typeof e)return e}return!0}(e.guards,n,r,o);if(!i)return null;if("function"==typeof i)return i;if(n.destroyed)return null;for await(const[i,s,u]of e.find(n.method,t,n)){if(n.destroyed)return null;const t=await h(i,u,n,r,{...o,...s});if(t)return e.__onionskin(t)}return null}function y(e){try{return decodeURIComponent(e)}catch{return e}}class d{disabled=!1;find(e,t,n){return[]}static make(e){return async(t,n)=>{const r=e.flat(),o=t.url.pathname.split("/").filter(Boolean).map(y);for(const e of r){const r=await h(e,o,t,n,{});if(r)return r}return null}}static create(e){return Object.defineProperties(new d,{find:{configurable:!0,value:e,writable:!0}})}guards=new Set;__onionskin=e=>e;onionskin(e){this.__onionskin=p(e,this.__onionskin)}}const g=/^:([a-zA-Z][a-zA-Z0-9]*)(?:\((.+)\))?([ius]+)?([?+*]?)$/;function m(e){const t=g.exec(e);if(!t)return e;const[,n,r=".*",o,i]=t;if(!r)return{name:n,pattern:new RegExp("^.*$",o),optional:"?"===i||"*"===i,many:"+"===i||"*"===i};let s=0,u=0;const c=["^(?:"];for(;s<r.length;){const t=r[s++];if(c.push(t),"\\"!==t)if(")"!==t)if("["!==t){if("("===t&&(u++,"?"===r[s]&&(s+=2,":"!==r[s-1])))return e}else for(;s<r.length;){const e=r[s++];if(c.push(e),"]"===e)break;"\\"===e&&c.push(r[s++])}else{if(0===u)return e;u--}else c.push(r[s++])}return u?e:(c.push(")$"),{name:n,pattern:new RegExp(c.join(""),o),optional:"?"===i||"*"===i,many:"+"===i||"*"===i})}function w(e,t){const n=[];for(const t of e.split("/"))t&&!/^\.+$/.test(t)&&n.push(m(t));if(n.length)return e=>function(e,t,n){const r={};for(let n=0;n<e.length;n++){const o=e[n],i=t[n];if(o!==i){if("string"==typeof o)return;if(!i)return o.optional?[r,[]]:void 0;if(!o.pattern.test(i))return;r[o.name]=i}}if(!n)return[r,t.slice(e.length)];if(t.length<=e.length)return[r,[]];const o=e[e.length-1];if("string"!=typeof o&&(o.many||!(t.length>e.length))){for(let n=e.length;n<t.length;n++)if(!o.pattern.test(t[n]))return;return r[o.name]=t.slice(e.length-1),[r,[]]}}(n,e,t)}function b(e,t,n,r){const o={match:w(n||"",!0),methods:new Set(t),handler:r};e.push(o);let i=!1;return()=>{if(i)return;i=!0;const t=e.indexOf(o);t<0||e.splice(t,1)}}const O=e=>"function"==typeof e;function T(e,t,n){if(!n.length)return n=>b(e,t,"",n);const[r,o]=n;if(r&&"object"==typeof r){const o=String.raw(r,...n.slice(1));return n=>b(e,t,o,n)}const i="string"==typeof r?r:"",s=[r,o].find(O);return s?b(e,t,i,s):n=>b(e,t,i,n)}const E=new Set(["GET","POST","PUT","DELETE","HEAD","OPTIONS"]);function S(e){return E.has(e)}function j(e,t,n){const r=n instanceof d?n:"function"==typeof n?d.create(n):new R;return e.push({match:w(t,!1),router:r}),r}class R extends d{#e=[];route(...e){const[t]=e;if(t&&"object"==typeof t&&!(t instanceof d)){const n=String.raw(t,...e.slice(1));return e=>j(this.#e,n,e)}const n="string"==typeof t?t:"",r="string"==typeof t?e[1]:t;return j(this.#e,n,r)}*find(e,t,n){for(const n of Array.from(this.#e)){if(!n.router&&!n.methods.has(e))continue;const{match:r}=n;if(!r){!n.router&&t.length||(yield[n.router||n.handler,{},t]);continue}if(!t.length)continue;const o=r(t);o&&(yield[n.router||n.handler,...o])}}verb(e,t,n){const r=function(e){return e?"string"==typeof e?[e.toUpperCase()].filter(S):Array.from(e).map((e=>"string"==typeof e&&e.toUpperCase())).filter(S):["GET","POST","PUT","DELETE"]}(e);return r.length?T(this.#e,r,[t,n]):()=>{}}match(...e){return T(this.#e,["GET","POST","PUT","DELETE"],e)}get(...e){return T(this.#e,["GET"],e)}post(...e){return T(this.#e,["POST"],e)}put(...e){return T(this.#e,["PUT"],e)}delete(...e){return T(this.#e,["DELETE"],e)}head(...e){return T(this.#e,["HEAD"],e)}options(...e){return T(this.#e,["OPTIONS"],e)}}const P=()=>{};e.ApiRouter=R,e.Router=d,e.createFetch=function(e,t){return async function(n,r){const o=new Request(n,r),{signal:i}=o;i.throwIfAborted();const s=await e(o);return s||("function"==typeof t?t(o):new Response(null,{status:404}))}},e.main=a,e.make=function(e,t){return n=>a(n,e,t)},e.merge=function(...e){return t=>async function(e,t){for(const n of t){const t=await n(e);if("boolean"==typeof t)return t;if(t)return t}}(t,e.flat())},e.onionskin=function(...e){let t=P;for(const n of e.flat()){const e=t;t=async t=>n(t,(async()=>e(t)))}return t},e.packer=p,e.service=function(e,t,n){const r=function(n){return"function"==typeof t&&n.done((()=>t(n)),(e=>t(n,e))),(...t)=>e(n,...t)},{rootOnly:o}="object"==typeof t&&t||"object"==typeof n&&n||{};return Object.assign(r,{rootOnly:Boolean(o)}),r},e.stateService=function(e,t,n,r){const o=function(r){const o=e(r)||{};return"function"==typeof t&&r.done((()=>t(o,r)),(e=>t(o,r,e))),"function"!=typeof n?()=>o:()=>(n(o,r),o)},{rootOnly:i}="object"==typeof t&&t||"object"==typeof n&&n||"object"==typeof r&&r||{};return Object.assign(o,{rootOnly:Boolean(i)}),o},e.storeService=function(e,t,n){const r=function(n){let r;return"function"==typeof e&&n.done((()=>e(r,n)),(t=>e(r,n,t))),"function"!=typeof t?(...e)=>(e.length&&([r]=e),r):(...e)=>(e.length&&([r]=e,t(r,n)),r)},{rootOnly:o}="object"==typeof e&&e||"object"==typeof t&&t||"object"==typeof n&&n||{};return Object.assign(r,{rootOnly:Boolean(o)}),r}}));
6
+ !function(e,t){"object"==typeof exports&&"undefined"!=typeof module?t(exports):"function"==typeof define&&define.amd?define(["exports"],t):t((e="undefined"!=typeof globalThis?globalThis:e||self).k99={})}(this,(function(e){"use strict";function t(e){return(new TextEncoder).encode(e)}function n(e){return Symbol.asyncIterator in e||Symbol.iterator in e}async function r(e,o){if("string"==typeof o)return e.write(t(o));if("object"==typeof o){if(ArrayBuffer.isView(o))return e.write(new Uint8Array(o.buffer,o.byteOffset,o.byteLength));if(o instanceof ArrayBuffer)return e.write(new Uint8Array(o));if(n(o))for await(const t of o)t&&await r(e,t)}}function o(e,t){return"bigint"==typeof t?String(t):t}function s(e,s,i){const u=function(e,s){if(e instanceof ReadableStream)return[e,0,""];if(e instanceof URLSearchParams)return[e,0,""];if(e instanceof Blob)return[e,e.size,e.type];if(e instanceof FormData)return[e,0,""];if(ArrayBuffer.isView(e)||e instanceof ArrayBuffer)return[e,e.byteLength,""];if("string"==typeof e){const n=t(e);return[n,n.byteLength,""]}if("object"!=typeof e)return null;if(Array.isArray(e)||!n(e)){const n=t(JSON.stringify(e,o));return[n,n.byteLength,"application/json"]}const{writable:i,readable:u}=new TransformStream,c=i.getWriter();return s?.catch((e=>{i.abort(e||new DOMException("The user aborted a request.")).catch((()=>{}))})),(async()=>{for await(const t of e)t&&await r(c,t);await i.close()})().catch((()=>{})),[u,0,""]}(e,i);if(!u)return null;const[c,f,a]=u;return a&&!s.get("Content-Type")&&s.set("Content-Type",a),f>0&&!s.get("Content-Length")&&s.set("Content-Length",String(f)),c}function i(e,t){e.delete("set-cookie");for(const{name:n,value:r,expire:o,domain:s,path:i,secure:u,httpOnly:c}of t)n&&e.append("set-cookie",[`${encodeURI(n)}=${encodeURI(r||"")}`,o&&`Expires=${o}`,s&&`Domain=${encodeURI(s)}`,i&&`Path=${encodeURI(i)}`,u&&"Secure",c&&"HttpOnly"].filter(Boolean).join("; "))}const u=new Set(["GET","OPTIONS"]);function c(e,t,n){n?e.set(t,n):e.delete(t)}function f(e,t,{runner:n,error:r,catch:o,method:f,environment:a}={}){return function e(l,p){const h=function(e,t){let n="";return"string"==typeof t?n=t:"function"==typeof t&&(n=t(e)),n&&"string"==typeof n||(n=e.method||"GET"),n.toUpperCase()}(l,f),y=new URL(l.url),{signal:d,headers:g}=l,m=function(e){return new Promise(((t,n)=>{if(e.aborted)return n(e.reason);e.addEventListener("abort",(()=>n(e.reason)),{once:!0})}))}(d),w=new Map,b=function(e){let t={};for(const n of e.replace(/\s/g,"").split(";")){const e=n.split("=");t[decodeURIComponent(e.shift())]=decodeURIComponent(e.join("="))}return t}(g.get("cookie")||""),O=[],T=new Headers,E=p?.root;let S=200,j=!1,R=null,P=()=>{},U=()=>{};const k=new Promise(((e,t)=>{P=e,U=t}));k.catch((()=>{}));let v={};const A={environment:a,parent:p,get error(){return R},get root(){return E||this},signal:d,url:y,fetch(t,{method:n="get",signal:r,body:o,headers:i}={}){const c=new URL(t,y),f=new Headers(i||{});if(!o||u.has(n.toUpperCase()))return e(new Request(c,{method:n,headers:f,signal:r}),A);const a=s(o,f);return e(new Request(c,{method:n,headers:f,signal:r,body:a}),A)},done(e,t){if(j)return null;const n=k.then(e,t);return n.catch(r),n},service(e,...t){if(e.rootOnly&&E)return E.service(e,...t);let n=w.get(e);if(!n){if(n=e(A),"function"!=typeof n)return;w.set(e,n)}return n(...t)},method:h,get params(){return v},requestHeaders:g,requestType:g.get("content-type")||"",referer:g.get("referer")||"",userAgent:g.get("user-agent")||"",accept:(g.get("accept")||"").split(/,\s*/).filter(Boolean),acceptLanguage:(g.get("accept-language")||"").split(/,\s*/).filter(Boolean),cookies:b,request:l,get destroyed(){return j},get status(){return S},set status(e){S=e},responseHeaders:T,get location(){return T.get("location")||""},set location(e){c(T,"location",e)},get responseType(){return T.get("content-type")||""},set responseType(e){c(T,"content-type",e)},getCookie:e=>function*(e,t){const n=e;for(const e of n)t&&e.name!==t||(yield{...e})}(O,e),setCookie(e,t,{expire:n,domain:r,path:o,secure:s,httpOnly:u}={}){O.push({name:e,value:t,expire:n,domain:r,path:o,secure:s,httpOnly:u}),i(T,O)},clearCookie(e,t){!function(e,t,n,r){let o="Fri, 31 Dec 1999 16:00:00 GMT";if("string"==typeof n){if(!n)return;const{domain:t,path:s,secure:i,httpOnly:u}=!0!==r&&r||{};e.push({name:n,value:"delete",expire:o,domain:t,path:s,secure:i,httpOnly:u})}else{const{domain:s,path:i,secure:u,httpOnly:c}=n||{};if(e.length=0,r)for(let n in t)e.push({name:n,value:"delete",expire:o,domain:s,path:i,secure:u,httpOnly:c})}}(O,b,e,t),i(T,O)}};function x(){return Promise.race([m,Promise.resolve().then((()=>t(A,(e=>{v=e}))))]).then((e=>e?Promise.race([m,e(A)]).then((e=>{if(e instanceof Response)return e;const t=new Headers(A.responseHeaders),{status:n}=A;if(!e)return new Response(null,{status:n,headers:t});const r=s(e,t,m);return new Response(r,{status:n,headers:t})})):null)).then((e=>(j=!0,P(),e)),(e=>(j=!0,R=e||!0,U(R),Promise.reject(e)))).catch(o)}return n?n(A,x):x()}(e)}const a=e=>e;function l(e,t=a){return n=>{const r=t(n);return async t=>e(t,(async()=>r(t)))}}async function p(e,t,n,r,o){if(!(e instanceof y))return r(o),e;if(e.disabled)return null;const s=await async function(e,t,n,r){if(!e.size)return!0;n(r);for(const n of e){if(t.destroyed)return!1;const e=await n(Object.create(t,{params:{value:{...r}}}));if(!1===e)return!1;if("function"==typeof e)return e}return!0}(e.guards,n,r,o);if(!s)return null;if("function"==typeof s)return s;if(n.destroyed)return null;for await(const[s,i,u]of e.find(n.method,t,n)){if(n.destroyed)return null;const t=await p(s,u,n,r,{...o,...i});if(t)return e.__onionskin(t)}return null}function h(e){try{return decodeURIComponent(e)}catch{return e}}class y{disabled=!1;find(e,t,n){return[]}static make(e){return async(t,n)=>{const r=e.flat(),o=t.url.pathname.split("/").filter(Boolean).map(h);for(const e of r){const r=await p(e,o,t,n,{});if(r)return r}return null}}static create(e){return Object.defineProperties(new y,{find:{configurable:!0,value:e,writable:!0}})}guards=new Set;__onionskin=e=>e;onionskin(e){this.__onionskin=l(e,this.__onionskin)}}const d=/^:([a-zA-Z][a-zA-Z0-9]*)(?:\((.+)\))?([ius]+)?([?+*]?)$/;function g(e){const t=d.exec(e);if(!t)return e;const[,n,r=".*",o,s]=t;if(!r)return{name:n,pattern:new RegExp("^.*$",o),optional:"?"===s||"*"===s,many:"+"===s||"*"===s};let i=0,u=0;const c=["^(?:"];for(;i<r.length;){const t=r[i++];if(c.push(t),"\\"!==t)if(")"!==t)if("["!==t){if("("===t&&(u++,"?"===r[i]&&(i+=2,":"!==r[i-1])))return e}else for(;i<r.length;){const e=r[i++];if(c.push(e),"]"===e)break;"\\"===e&&c.push(r[i++])}else{if(0===u)return e;u--}else c.push(r[i++])}return u?e:(c.push(")$"),{name:n,pattern:new RegExp(c.join(""),o),optional:"?"===s||"*"===s,many:"+"===s||"*"===s})}function m(e,t){const n=[];for(const t of e.split("/"))t&&!/^\.+$/.test(t)&&n.push(g(t));if(n.length)return e=>function(e,t,n){const r={};for(let n=0;n<e.length;n++){const o=e[n],s=t[n];if(o!==s){if("string"==typeof o)return;if(!s)return o.optional?[r,[]]:void 0;if(!o.pattern.test(s))return;r[o.name]=s}}if(!n)return[r,t.slice(e.length)];if(t.length<=e.length)return[r,[]];const o=e[e.length-1];if("string"!=typeof o&&(o.many||!(t.length>e.length))){for(let n=e.length;n<t.length;n++)if(!o.pattern.test(t[n]))return;return r[o.name]=t.slice(e.length-1),[r,[]]}}(n,e,t)}function w(e,t,n,r){const o={match:m(n||"",!0),methods:new Set(t),handler:r};e.push(o);let s=!1;return()=>{if(s)return;s=!0;const t=e.indexOf(o);t<0||e.splice(t,1)}}const b=e=>"function"==typeof e;function O(e,t,n){if(!n.length)return n=>w(e,t,"",n);const[r,o]=n;if(r&&"object"==typeof r){const o=String.raw(r,...n.slice(1));return n=>w(e,t,o,n)}const s="string"==typeof r?r:"",i=[r,o].find(b);return i?w(e,t,s,i):n=>w(e,t,s,n)}const T=new Set(["GET","POST","PUT","DELETE","HEAD","OPTIONS"]);function E(e){return T.has(e)}function S(e,t,n){const r=n instanceof y?n:"function"==typeof n?y.create(n):new j;return e.push({match:m(t,!1),router:r}),r}class j extends y{#e=[];route(...e){const[t]=e;if(t&&"object"==typeof t&&!(t instanceof y)){const n=String.raw(t,...e.slice(1));return e=>S(this.#e,n,e)}const n="string"==typeof t?t:"",r="string"==typeof t?e[1]:t;return S(this.#e,n,r)}*find(e,t,n){for(const n of Array.from(this.#e)){if(!n.router&&!n.methods.has(e))continue;const{match:r}=n;if(!r){!n.router&&t.length||(yield[n.router||n.handler,{},t]);continue}if(!t.length)continue;const o=r(t);o&&(yield[n.router||n.handler,...o])}}verb(e,t,n){const r=function(e){return e?"string"==typeof e?[e.toUpperCase()].filter(E):Array.from(e).map((e=>"string"==typeof e&&e.toUpperCase())).filter(E):["GET","POST","PUT","DELETE"]}(e);return r.length?O(this.#e,r,[t,n]):()=>{}}match(...e){return O(this.#e,["GET","POST","PUT","DELETE"],e)}get(...e){return O(this.#e,["GET"],e)}post(...e){return O(this.#e,["POST"],e)}put(...e){return O(this.#e,["PUT"],e)}delete(...e){return O(this.#e,["DELETE"],e)}head(...e){return O(this.#e,["HEAD"],e)}options(...e){return O(this.#e,["OPTIONS"],e)}}const R=()=>{};e.ApiRouter=j,e.Router=y,e.createFetch=function(e,t){return async function(n,r){const o=new Request(n,r),{signal:s}=o;s.throwIfAborted();const i=await e(o);return i||("function"==typeof t?t(o):new Response(null,{status:404}))}},e.main=f,e.make=function(e,t){return n=>f(n,e,t)},e.merge=function(...e){return t=>async function(e,t){for(const n of t){const t=await n(e);if("boolean"==typeof t)return t;if(t)return t}}(t,e.flat())},e.onionskin=function(...e){let t=R;for(const n of e.flat()){const e=t;t=async t=>n(t,(async()=>e(t)))}return t},e.packer=l,e.service=function(e,t,n){const r=function(n){return"function"==typeof t&&n.done((()=>t(n)),(e=>t(n,e))),(...t)=>e(n,...t)},{rootOnly:o}="object"==typeof t&&t||"object"==typeof n&&n||{};return Object.assign(r,{rootOnly:Boolean(o)}),r},e.stateService=function(e,t,n,r){const o=function(r){const o=e(r)||{};return"function"==typeof t&&r.done((()=>t(o,r)),(e=>t(o,r,e))),"function"!=typeof n?()=>o:()=>(n(o,r),o)},{rootOnly:s}="object"==typeof t&&t||"object"==typeof n&&n||"object"==typeof r&&r||{};return Object.assign(o,{rootOnly:Boolean(s)}),o},e.storeService=function(e,t,n){const r=function(n){let r;return"function"==typeof e&&n.done((()=>e(r,n)),(t=>e(r,n,t))),"function"!=typeof t?(...e)=>(e.length&&([r]=e),r):(...e)=>(e.length&&([r]=e,t(r,n)),r)},{rootOnly:o}="object"==typeof e&&e||"object"==typeof t&&t||"object"==typeof n&&n||{};return Object.assign(r,{rootOnly:Boolean(o)}),r}}));
package/index.min.mjs CHANGED
@@ -1,6 +1,6 @@
1
1
  /*!
2
- * k99 v0.6.0
3
- * (c) 2019-2024 猛火Fierflame
2
+ * k99 v0.6.1
3
+ * (c) 2019-2025 猛火Fierflame
4
4
  * @license MIT
5
5
  */
6
- function t(t){return(new TextEncoder).encode(t)}function e(t){if(t instanceof ArrayBuffer)return!0;try{if(t instanceof SharedArrayBuffer)return!0}catch{}return!1}function n(t){return Symbol.asyncIterator in t||Symbol.iterator in t}async function r(o,s){if("string"==typeof s)return o.write(t(s));if("object"==typeof s){if(ArrayBuffer.isView(s))return o.write(new Uint8Array(s.buffer,s.byteOffset,s.byteLength));if(e(s))return o.write(new Uint8Array(s));if(n(s))for await(const t of s)t&&await r(o,t)}}function o(t,e){return"bigint"==typeof e?String(e):e}function s(s,i,u){const c=function(s,i){if(s instanceof ReadableStream)return[s,0,""];if(s instanceof URLSearchParams)return[s,0,""];if(s instanceof Blob)return[s,s.size,s.type];if(s instanceof FormData)return[s,0,""];if(ArrayBuffer.isView(s)||e(s))return[s,s.byteLength,""];if("string"==typeof s){const e=t(s);return[e,e.byteLength,""]}if("object"!=typeof s)return null;if(Array.isArray(s)||!n(s)){const e=t(JSON.stringify(s,o));return[e,e.byteLength,"application/json"]}const{writable:u,readable:c}=new TransformStream,f=u.getWriter();return i?.catch((t=>{u.abort(t||new DOMException("The user aborted a request.")).catch((()=>{}))})),(async()=>{for await(const t of s)t&&await r(f,t);await u.close()})().catch((()=>{})),[c,0,""]}(s,u);if(!c)return null;const[f,a,l]=c;return l&&!i.get("Content-Type")&&i.set("Content-Type",l),a>0&&!i.get("Content-Length")&&i.set("Content-Length",String(a)),f}function i(t,e){t.delete("set-cookie");for(const{name:n,value:r,expire:o,domain:s,path:i,secure:u,httpOnly:c}of e)n&&t.append("set-cookie",[`${encodeURI(n)}=${encodeURI(r||"")}`,o&&`Expires=${o}`,s&&`Domain=${encodeURI(s)}`,i&&`Path=${encodeURI(i)}`,u&&"Secure",c&&"HttpOnly"].filter(Boolean).join("; "))}const u=new Set(["GET","OPTIONS"]);function c(t,e,n){n?t.set(e,n):t.delete(e)}function f(t,e,{runner:n,error:r,catch:o,method:f,environment:a}={}){return function t(l,p){const h=function(t,e){let n="";return"string"==typeof e?n=e:"function"==typeof e&&(n=e(t)),n&&"string"==typeof n||(n=t.method||"GET"),n.toUpperCase()}(l,f),y=new URL(l.url),{signal:d,headers:g}=l,m=function(t){return new Promise(((e,n)=>{if(t.aborted)return n(t.reason);t.addEventListener("abort",(()=>n(t.reason)),{once:!0})}))}(d),w=new Map,b=function(t){let e={};for(const n of t.replace(/\s/g,"").split(";")){const t=n.split("=");e[decodeURIComponent(t.shift())]=decodeURIComponent(t.join("="))}return e}(g.get("cookie")||""),O=[],T=new Headers,E=p?.root;let S=200,j=!1,P=null,R=()=>{},U=()=>{};const A=new Promise(((t,e)=>{R=t,U=e}));A.catch((()=>{}));let L={};const k={environment:a,parent:p,get error(){return P},get root(){return E||this},signal:d,url:y,fetch(e,{method:n="get",signal:r,body:o,headers:i}={}){const c=new URL(e,y),f=new Headers(i||{});if(!o||u.has(n.toUpperCase()))return t(new Request(c,{method:n,headers:f,signal:r}),k);const a=s(o,f);return t(new Request(c,{method:n,headers:f,signal:r,body:a}),k)},done(t,e){if(j)return null;const n=A.then(t,e);return n.catch(r),n},service(t,...e){if(t.rootOnly&&E)return E.service(t,...e);let n=w.get(t);if(!n){if(n=t(k),"function"!=typeof n)return;w.set(t,n)}return n(...e)},method:h,get params(){return L},requestHeaders:g,requestType:g.get("content-type")||"",referer:g.get("referer")||"",userAgent:g.get("user-agent")||"",accept:(g.get("accept")||"").split(/,\s*/).filter(Boolean),acceptLanguage:(g.get("accept-language")||"").split(/,\s*/).filter(Boolean),cookies:b,request:l,get destroyed(){return j},get status(){return S},set status(t){S=t},responseHeaders:T,get location(){return T.get("location")||""},set location(t){c(T,"location",t)},get responseType(){return T.get("content-type")||""},set responseType(t){c(T,"content-type",t)},getCookie:t=>function*(t,e){const n=t;for(const t of n)e&&t.name!==e||(yield{...t})}(O,t),setCookie(t,e,{expire:n,domain:r,path:o,secure:s,httpOnly:u}={}){O.push({name:t,value:e,expire:n,domain:r,path:o,secure:s,httpOnly:u}),i(T,O)},clearCookie(t,e){!function(t,e,n,r){let o="Fri, 31 Dec 1999 16:00:00 GMT";if("string"==typeof n){if(!n)return;const{domain:e,path:s,secure:i,httpOnly:u}=!0!==r&&r||{};t.push({name:n,value:"delete",expire:o,domain:e,path:s,secure:i,httpOnly:u})}else{const{domain:s,path:i,secure:u,httpOnly:c}=n||{};if(t.length=0,r)for(let n in e)t.push({name:n,value:"delete",expire:o,domain:s,path:i,secure:u,httpOnly:c})}}(O,b,t,e),i(T,O)}};function v(){return Promise.race([m,Promise.resolve().then((()=>e(k,(t=>{L=t}))))]).then((t=>t?Promise.race([m,t(k)]).then((t=>{if(t instanceof Response)return t;const e=new Headers(k.responseHeaders),{status:n}=k;if(!t)return new Response(null,{status:n,headers:e});const r=s(t,e,m);return new Response(r,{status:n,headers:e})})):null)).then((t=>(j=!0,R(),t)),(t=>(j=!0,P=t||!0,U(P),Promise.reject(t)))).catch(o)}return n?n(k,v):v()}(t)}function a(t,e){return n=>f(n,t,e)}function l(...t){return e=>async function(t,e){for(const n of e){const e=await n(t);if("boolean"==typeof e)return e;if(e)return e}}(e,t.flat())}function p(t,e,n){const r=function(n){return"function"==typeof e&&n.done((()=>e(n)),(t=>e(n,t))),(...e)=>t(n,...e)},{rootOnly:o}="object"==typeof e&&e||"object"==typeof n&&n||{};return Object.assign(r,{rootOnly:Boolean(o)}),r}function h(t,e,n,r){const o=function(r){const o=t(r)||{};return"function"==typeof e&&r.done((()=>e(o,r)),(t=>e(o,r,t))),"function"!=typeof n?()=>o:()=>(n(o,r),o)},{rootOnly:s}="object"==typeof e&&e||"object"==typeof n&&n||"object"==typeof r&&r||{};return Object.assign(o,{rootOnly:Boolean(s)}),o}function y(t,e,n){const r=function(n){let r;return"function"==typeof t&&n.done((()=>t(r,n)),(e=>t(r,n,e))),"function"!=typeof e?(...t)=>(t.length&&([r]=t),r):(...t)=>(t.length&&([r]=t,e(r,n)),r)},{rootOnly:o}="object"==typeof t&&t||"object"==typeof e&&e||"object"==typeof n&&n||{};return Object.assign(r,{rootOnly:Boolean(o)}),r}const d=t=>t;function g(t,e=d){return n=>{const r=e(n);return async e=>t(e,(async()=>r(e)))}}async function m(t,e,n,r,o){if(!(t instanceof b))return r(o),t;if(t.disabled)return null;const s=await async function(t,e,n,r){if(!t.size)return!0;n(r);for(const n of t){if(e.destroyed)return!1;const t=await n(Object.create(e,{params:{value:{...r}}}));if(!1===t)return!1;if("function"==typeof t)return t}return!0}(t.guards,n,r,o);if(!s)return null;if("function"==typeof s)return s;if(n.destroyed)return null;for await(const[s,i,u]of t.find(n.method,e,n)){if(n.destroyed)return null;const e=await m(s,u,n,r,{...o,...i});if(e)return t.__onionskin(e)}return null}function w(t){try{return decodeURIComponent(t)}catch{return t}}class b{disabled=!1;find(t,e,n){return[]}static make(t){return async(e,n)=>{const r=t.flat(),o=e.url.pathname.split("/").filter(Boolean).map(w);for(const t of r){const r=await m(t,o,e,n,{});if(r)return r}return null}}static create(t){return Object.defineProperties(new b,{find:{configurable:!0,value:t,writable:!0}})}guards=new Set;__onionskin=t=>t;onionskin(t){this.__onionskin=g(t,this.__onionskin)}}const O=/^:([a-zA-Z][a-zA-Z0-9]*)(?:\((.+)\))?([ius]+)?([?+*]?)$/;function T(t){const e=O.exec(t);if(!e)return t;const[,n,r=".*",o,s]=e;if(!r)return{name:n,pattern:new RegExp("^.*$",o),optional:"?"===s||"*"===s,many:"+"===s||"*"===s};let i=0,u=0;const c=["^(?:"];for(;i<r.length;){const e=r[i++];if(c.push(e),"\\"!==e)if(")"!==e)if("["!==e){if("("===e&&(u++,"?"===r[i]&&(i+=2,":"!==r[i-1])))return t}else for(;i<r.length;){const t=r[i++];if(c.push(t),"]"===t)break;"\\"===t&&c.push(r[i++])}else{if(0===u)return t;u--}else c.push(r[i++])}return u?t:(c.push(")$"),{name:n,pattern:new RegExp(c.join(""),o),optional:"?"===s||"*"===s,many:"+"===s||"*"===s})}function E(t,e){const n=[];for(const e of t.split("/"))e&&!/^\.+$/.test(e)&&n.push(T(e));if(n.length)return t=>function(t,e,n){const r={};for(let n=0;n<t.length;n++){const o=t[n],s=e[n];if(o!==s){if("string"==typeof o)return;if(!s)return o.optional?[r,[]]:void 0;if(!o.pattern.test(s))return;r[o.name]=s}}if(!n)return[r,e.slice(t.length)];if(e.length<=t.length)return[r,[]];const o=t[t.length-1];if("string"!=typeof o&&(o.many||!(e.length>t.length))){for(let n=t.length;n<e.length;n++)if(!o.pattern.test(e[n]))return;return r[o.name]=e.slice(t.length-1),[r,[]]}}(n,t,e)}function S(t,e,n,r){const o={match:E(n||"",!0),methods:new Set(e),handler:r};t.push(o);let s=!1;return()=>{if(s)return;s=!0;const e=t.indexOf(o);e<0||t.splice(e,1)}}const j=t=>"function"==typeof t;function P(t,e,n){if(!n.length)return n=>S(t,e,"",n);const[r,o]=n;if(r&&"object"==typeof r){const o=String.raw(r,...n.slice(1));return n=>S(t,e,o,n)}const s="string"==typeof r?r:"",i=[r,o].find(j);return i?S(t,e,s,i):n=>S(t,e,s,n)}const R=new Set(["GET","POST","PUT","DELETE","HEAD","OPTIONS"]);function U(t){return R.has(t)}function A(t,e,n){const r=n instanceof b?n:"function"==typeof n?b.create(n):new L;return t.push({match:E(e,!1),router:r}),r}class L extends b{#t=[];route(...t){const[e]=t;if(e&&"object"==typeof e&&!(e instanceof b)){const n=String.raw(e,...t.slice(1));return t=>A(this.#t,n,t)}const n="string"==typeof e?e:"",r="string"==typeof e?t[1]:e;return A(this.#t,n,r)}*find(t,e,n){for(const n of Array.from(this.#t)){if(!n.router&&!n.methods.has(t))continue;const{match:r}=n;if(!r){!n.router&&e.length||(yield[n.router||n.handler,{},e]);continue}if(!e.length)continue;const o=r(e);o&&(yield[n.router||n.handler,...o])}}verb(t,e,n){const r=function(t){return t?"string"==typeof t?[t.toUpperCase()].filter(U):Array.from(t).map((t=>"string"==typeof t&&t.toUpperCase())).filter(U):["GET","POST","PUT","DELETE"]}(t);return r.length?P(this.#t,r,[e,n]):()=>{}}match(...t){return P(this.#t,["GET","POST","PUT","DELETE"],t)}get(...t){return P(this.#t,["GET"],t)}post(...t){return P(this.#t,["POST"],t)}put(...t){return P(this.#t,["PUT"],t)}delete(...t){return P(this.#t,["DELETE"],t)}head(...t){return P(this.#t,["HEAD"],t)}options(...t){return P(this.#t,["OPTIONS"],t)}}function k(t,e){return async function(n,r){const o=new Request(n,r),{signal:s}=o;s.throwIfAborted();const i=await t(o);return i||("function"==typeof e?e(o):new Response(null,{status:404}))}}const v=()=>{};function x(...t){let e=v;for(const n of t.flat()){const t=e;e=async e=>n(e,(async()=>t(e)))}return e}export{L as ApiRouter,b as Router,k as createFetch,f as main,a as make,l as merge,x as onionskin,g as packer,p as service,h as stateService,y as storeService};
6
+ function t(t){return(new TextEncoder).encode(t)}function e(t){return Symbol.asyncIterator in t||Symbol.iterator in t}async function n(r,o){if("string"==typeof o)return r.write(t(o));if("object"==typeof o){if(ArrayBuffer.isView(o))return r.write(new Uint8Array(o.buffer,o.byteOffset,o.byteLength));if(o instanceof ArrayBuffer)return r.write(new Uint8Array(o));if(e(o))for await(const t of o)t&&await n(r,t)}}function r(t,e){return"bigint"==typeof e?String(e):e}function o(o,s,i){const u=function(o,s){if(o instanceof ReadableStream)return[o,0,""];if(o instanceof URLSearchParams)return[o,0,""];if(o instanceof Blob)return[o,o.size,o.type];if(o instanceof FormData)return[o,0,""];if(ArrayBuffer.isView(o)||o instanceof ArrayBuffer)return[o,o.byteLength,""];if("string"==typeof o){const e=t(o);return[e,e.byteLength,""]}if("object"!=typeof o)return null;if(Array.isArray(o)||!e(o)){const e=t(JSON.stringify(o,r));return[e,e.byteLength,"application/json"]}const{writable:i,readable:u}=new TransformStream,c=i.getWriter();return s?.catch((t=>{i.abort(t||new DOMException("The user aborted a request.")).catch((()=>{}))})),(async()=>{for await(const t of o)t&&await n(c,t);await i.close()})().catch((()=>{})),[u,0,""]}(o,i);if(!u)return null;const[c,a,f]=u;return f&&!s.get("Content-Type")&&s.set("Content-Type",f),a>0&&!s.get("Content-Length")&&s.set("Content-Length",String(a)),c}function s(t,e){t.delete("set-cookie");for(const{name:n,value:r,expire:o,domain:s,path:i,secure:u,httpOnly:c}of e)n&&t.append("set-cookie",[`${encodeURI(n)}=${encodeURI(r||"")}`,o&&`Expires=${o}`,s&&`Domain=${encodeURI(s)}`,i&&`Path=${encodeURI(i)}`,u&&"Secure",c&&"HttpOnly"].filter(Boolean).join("; "))}const i=new Set(["GET","OPTIONS"]);function u(t,e,n){n?t.set(e,n):t.delete(e)}function c(t,e,{runner:n,error:r,catch:c,method:a,environment:f}={}){return function t(l,p){const h=function(t,e){let n="";return"string"==typeof e?n=e:"function"==typeof e&&(n=e(t)),n&&"string"==typeof n||(n=t.method||"GET"),n.toUpperCase()}(l,a),y=new URL(l.url),{signal:d,headers:g}=l,m=function(t){return new Promise(((e,n)=>{if(t.aborted)return n(t.reason);t.addEventListener("abort",(()=>n(t.reason)),{once:!0})}))}(d),w=new Map,b=function(t){let e={};for(const n of t.replace(/\s/g,"").split(";")){const t=n.split("=");e[decodeURIComponent(t.shift())]=decodeURIComponent(t.join("="))}return e}(g.get("cookie")||""),O=[],T=new Headers,E=p?.root;let j=200,S=!1,P=null,R=()=>{},U=()=>{};const A=new Promise(((t,e)=>{R=t,U=e}));A.catch((()=>{}));let L={};const k={environment:f,parent:p,get error(){return P},get root(){return E||this},signal:d,url:y,fetch(e,{method:n="get",signal:r,body:s,headers:u}={}){const c=new URL(e,y),a=new Headers(u||{});if(!s||i.has(n.toUpperCase()))return t(new Request(c,{method:n,headers:a,signal:r}),k);const f=o(s,a);return t(new Request(c,{method:n,headers:a,signal:r,body:f}),k)},done(t,e){if(S)return null;const n=A.then(t,e);return n.catch(r),n},service(t,...e){if(t.rootOnly&&E)return E.service(t,...e);let n=w.get(t);if(!n){if(n=t(k),"function"!=typeof n)return;w.set(t,n)}return n(...e)},method:h,get params(){return L},requestHeaders:g,requestType:g.get("content-type")||"",referer:g.get("referer")||"",userAgent:g.get("user-agent")||"",accept:(g.get("accept")||"").split(/,\s*/).filter(Boolean),acceptLanguage:(g.get("accept-language")||"").split(/,\s*/).filter(Boolean),cookies:b,request:l,get destroyed(){return S},get status(){return j},set status(t){j=t},responseHeaders:T,get location(){return T.get("location")||""},set location(t){u(T,"location",t)},get responseType(){return T.get("content-type")||""},set responseType(t){u(T,"content-type",t)},getCookie:t=>function*(t,e){const n=t;for(const t of n)e&&t.name!==e||(yield{...t})}(O,t),setCookie(t,e,{expire:n,domain:r,path:o,secure:i,httpOnly:u}={}){O.push({name:t,value:e,expire:n,domain:r,path:o,secure:i,httpOnly:u}),s(T,O)},clearCookie(t,e){!function(t,e,n,r){let o="Fri, 31 Dec 1999 16:00:00 GMT";if("string"==typeof n){if(!n)return;const{domain:e,path:s,secure:i,httpOnly:u}=!0!==r&&r||{};t.push({name:n,value:"delete",expire:o,domain:e,path:s,secure:i,httpOnly:u})}else{const{domain:s,path:i,secure:u,httpOnly:c}=n||{};if(t.length=0,r)for(let n in e)t.push({name:n,value:"delete",expire:o,domain:s,path:i,secure:u,httpOnly:c})}}(O,b,t,e),s(T,O)}};function v(){return Promise.race([m,Promise.resolve().then((()=>e(k,(t=>{L=t}))))]).then((t=>t?Promise.race([m,t(k)]).then((t=>{if(t instanceof Response)return t;const e=new Headers(k.responseHeaders),{status:n}=k;if(!t)return new Response(null,{status:n,headers:e});const r=o(t,e,m);return new Response(r,{status:n,headers:e})})):null)).then((t=>(S=!0,R(),t)),(t=>(S=!0,P=t||!0,U(P),Promise.reject(t)))).catch(c)}return n?n(k,v):v()}(t)}function a(t,e){return n=>c(n,t,e)}function f(...t){return e=>async function(t,e){for(const n of e){const e=await n(t);if("boolean"==typeof e)return e;if(e)return e}}(e,t.flat())}function l(t,e,n){const r=function(n){return"function"==typeof e&&n.done((()=>e(n)),(t=>e(n,t))),(...e)=>t(n,...e)},{rootOnly:o}="object"==typeof e&&e||"object"==typeof n&&n||{};return Object.assign(r,{rootOnly:Boolean(o)}),r}function p(t,e,n,r){const o=function(r){const o=t(r)||{};return"function"==typeof e&&r.done((()=>e(o,r)),(t=>e(o,r,t))),"function"!=typeof n?()=>o:()=>(n(o,r),o)},{rootOnly:s}="object"==typeof e&&e||"object"==typeof n&&n||"object"==typeof r&&r||{};return Object.assign(o,{rootOnly:Boolean(s)}),o}function h(t,e,n){const r=function(n){let r;return"function"==typeof t&&n.done((()=>t(r,n)),(e=>t(r,n,e))),"function"!=typeof e?(...t)=>(t.length&&([r]=t),r):(...t)=>(t.length&&([r]=t,e(r,n)),r)},{rootOnly:o}="object"==typeof t&&t||"object"==typeof e&&e||"object"==typeof n&&n||{};return Object.assign(r,{rootOnly:Boolean(o)}),r}const y=t=>t;function d(t,e=y){return n=>{const r=e(n);return async e=>t(e,(async()=>r(e)))}}async function g(t,e,n,r,o){if(!(t instanceof w))return r(o),t;if(t.disabled)return null;const s=await async function(t,e,n,r){if(!t.size)return!0;n(r);for(const n of t){if(e.destroyed)return!1;const t=await n(Object.create(e,{params:{value:{...r}}}));if(!1===t)return!1;if("function"==typeof t)return t}return!0}(t.guards,n,r,o);if(!s)return null;if("function"==typeof s)return s;if(n.destroyed)return null;for await(const[s,i,u]of t.find(n.method,e,n)){if(n.destroyed)return null;const e=await g(s,u,n,r,{...o,...i});if(e)return t.__onionskin(e)}return null}function m(t){try{return decodeURIComponent(t)}catch{return t}}class w{disabled=!1;find(t,e,n){return[]}static make(t){return async(e,n)=>{const r=t.flat(),o=e.url.pathname.split("/").filter(Boolean).map(m);for(const t of r){const r=await g(t,o,e,n,{});if(r)return r}return null}}static create(t){return Object.defineProperties(new w,{find:{configurable:!0,value:t,writable:!0}})}guards=new Set;__onionskin=t=>t;onionskin(t){this.__onionskin=d(t,this.__onionskin)}}const b=/^:([a-zA-Z][a-zA-Z0-9]*)(?:\((.+)\))?([ius]+)?([?+*]?)$/;function O(t){const e=b.exec(t);if(!e)return t;const[,n,r=".*",o,s]=e;if(!r)return{name:n,pattern:new RegExp("^.*$",o),optional:"?"===s||"*"===s,many:"+"===s||"*"===s};let i=0,u=0;const c=["^(?:"];for(;i<r.length;){const e=r[i++];if(c.push(e),"\\"!==e)if(")"!==e)if("["!==e){if("("===e&&(u++,"?"===r[i]&&(i+=2,":"!==r[i-1])))return t}else for(;i<r.length;){const t=r[i++];if(c.push(t),"]"===t)break;"\\"===t&&c.push(r[i++])}else{if(0===u)return t;u--}else c.push(r[i++])}return u?t:(c.push(")$"),{name:n,pattern:new RegExp(c.join(""),o),optional:"?"===s||"*"===s,many:"+"===s||"*"===s})}function T(t,e){const n=[];for(const e of t.split("/"))e&&!/^\.+$/.test(e)&&n.push(O(e));if(n.length)return t=>function(t,e,n){const r={};for(let n=0;n<t.length;n++){const o=t[n],s=e[n];if(o!==s){if("string"==typeof o)return;if(!s)return o.optional?[r,[]]:void 0;if(!o.pattern.test(s))return;r[o.name]=s}}if(!n)return[r,e.slice(t.length)];if(e.length<=t.length)return[r,[]];const o=t[t.length-1];if("string"!=typeof o&&(o.many||!(e.length>t.length))){for(let n=t.length;n<e.length;n++)if(!o.pattern.test(e[n]))return;return r[o.name]=e.slice(t.length-1),[r,[]]}}(n,t,e)}function E(t,e,n,r){const o={match:T(n||"",!0),methods:new Set(e),handler:r};t.push(o);let s=!1;return()=>{if(s)return;s=!0;const e=t.indexOf(o);e<0||t.splice(e,1)}}const j=t=>"function"==typeof t;function S(t,e,n){if(!n.length)return n=>E(t,e,"",n);const[r,o]=n;if(r&&"object"==typeof r){const o=String.raw(r,...n.slice(1));return n=>E(t,e,o,n)}const s="string"==typeof r?r:"",i=[r,o].find(j);return i?E(t,e,s,i):n=>E(t,e,s,n)}const P=new Set(["GET","POST","PUT","DELETE","HEAD","OPTIONS"]);function R(t){return P.has(t)}function U(t,e,n){const r=n instanceof w?n:"function"==typeof n?w.create(n):new A;return t.push({match:T(e,!1),router:r}),r}class A extends w{#t=[];route(...t){const[e]=t;if(e&&"object"==typeof e&&!(e instanceof w)){const n=String.raw(e,...t.slice(1));return t=>U(this.#t,n,t)}const n="string"==typeof e?e:"",r="string"==typeof e?t[1]:e;return U(this.#t,n,r)}*find(t,e,n){for(const n of Array.from(this.#t)){if(!n.router&&!n.methods.has(t))continue;const{match:r}=n;if(!r){!n.router&&e.length||(yield[n.router||n.handler,{},e]);continue}if(!e.length)continue;const o=r(e);o&&(yield[n.router||n.handler,...o])}}verb(t,e,n){const r=function(t){return t?"string"==typeof t?[t.toUpperCase()].filter(R):Array.from(t).map((t=>"string"==typeof t&&t.toUpperCase())).filter(R):["GET","POST","PUT","DELETE"]}(t);return r.length?S(this.#t,r,[e,n]):()=>{}}match(...t){return S(this.#t,["GET","POST","PUT","DELETE"],t)}get(...t){return S(this.#t,["GET"],t)}post(...t){return S(this.#t,["POST"],t)}put(...t){return S(this.#t,["PUT"],t)}delete(...t){return S(this.#t,["DELETE"],t)}head(...t){return S(this.#t,["HEAD"],t)}options(...t){return S(this.#t,["OPTIONS"],t)}}function L(t,e){return async function(n,r){const o=new Request(n,r),{signal:s}=o;s.throwIfAborted();const i=await t(o);return i||("function"==typeof e?e(o):new Response(null,{status:404}))}}const k=()=>{};function v(...t){let e=k;for(const n of t.flat()){const t=e;e=async e=>n(e,(async()=>t(e)))}return e}export{A as ApiRouter,w as Router,L as createFetch,c as main,a as make,f as merge,v as onionskin,d as packer,l as service,p as stateService,h as storeService};
package/index.mjs CHANGED
@@ -1,6 +1,6 @@
1
1
  /*!
2
- * k99 v0.6.0
3
- * (c) 2019-2024 猛火Fierflame
2
+ * k99 v0.6.1
3
+ * (c) 2019-2025 猛火Fierflame
4
4
  * @license MIT
5
5
  */
6
6
  /**
@@ -11,20 +11,6 @@
11
11
  function str2utf8bin(str) {
12
12
  return new TextEncoder().encode(str);
13
13
  }
14
- /**
15
- *
16
- * @param {unknown} chunk
17
- * @returns {chunk is ArrayBuffer | SharedArrayBuffer}
18
- */
19
- function isBufferSource(chunk) {
20
- if (chunk instanceof ArrayBuffer) { return true; }
21
- try {
22
- if (chunk instanceof SharedArrayBuffer) { return true; }
23
- } catch {
24
-
25
- }
26
- return false;
27
- }
28
14
  /**
29
15
  *
30
16
  * @template T
@@ -49,7 +35,7 @@ async function write(writer, chunk) {
49
35
  if (ArrayBuffer.isView(chunk)) {
50
36
  return writer.write(new Uint8Array(chunk.buffer, chunk.byteOffset, chunk.byteLength));
51
37
  }
52
- if (isBufferSource(chunk)) {
38
+ if (chunk instanceof ArrayBuffer) {
53
39
  return writer.write(new Uint8Array(chunk));
54
40
  }
55
41
  if (!isIterable(chunk)) {
@@ -93,7 +79,7 @@ function toBodyData(result, aborted) {
93
79
  if (result instanceof FormData) {
94
80
  return [result, 0, ''];
95
81
  }
96
- if (ArrayBuffer.isView(result) || isBufferSource(result)) {
82
+ if (ArrayBuffer.isView(result) || result instanceof ArrayBuffer) {
97
83
  return [result, result.byteLength, ''];
98
84
  }
99
85
  if (typeof result === 'string') {
package/node/index.cjs CHANGED
@@ -1,6 +1,6 @@
1
1
  /*!
2
- * k99 v0.6.0
3
- * (c) 2019-2024 猛火Fierflame
2
+ * k99 v0.6.1
3
+ * (c) 2019-2025 猛火Fierflame
4
4
  * @license MIT
5
5
  */
6
6
  'use strict';
@@ -8,12 +8,15 @@
8
8
  var node_stream = require('node:stream');
9
9
  var node_http2 = require('node:http2');
10
10
 
11
+ /** @import { IncomingMessage, ServerResponse } from 'node:http' */
12
+ /** @import { Http2ServerRequest, Http2ServerResponse } from 'node:http2' */
11
13
  /**
12
14
  *
13
- * @param {import('node:http').IncomingMessage | import('node:http2').Http2ServerRequest} req
15
+ * @param {IncomingMessage | Http2ServerRequest} req
16
+ * @param {ServerResponse | Http2ServerResponse} [res]
14
17
  * @returns {AbortSignal}
15
18
  */
16
- function createAbortSignal(req) {
19
+ function createAbortSignal(req, res) {
17
20
  const ac = new AbortController();
18
21
  /**
19
22
  *
@@ -21,12 +24,11 @@ function createAbortSignal(req) {
21
24
  * @returns
22
25
  */
23
26
  const end = (err) => {
24
- req.off('end', end);
27
+ res?.off('close', end);
25
28
  req.off('error', end);
26
- if (!err) { return; }
27
29
  ac.abort(err);
28
30
  };
29
- req.on('end', end);
31
+ res?.on('close', end);
30
32
  req.on('error', end);
31
33
 
32
34
  return ac.signal;
@@ -34,11 +36,14 @@ function createAbortSignal(req) {
34
36
 
35
37
  /**
36
38
  *
37
- * @param {import('node:http').IncomingMessage | import('node:http2').Http2ServerRequest} req
39
+ * @param {IncomingMessage | Http2ServerRequest} req
40
+ * @param {AbortSignal | ServerResponse | Http2ServerResponse} [signalOrRes]
38
41
  * @returns {Request}
39
42
  */
40
- function toWebRequest(req) {
41
- const signal = createAbortSignal(req);
43
+ function toWebRequest(req, signalOrRes) {
44
+ const signal = signalOrRes instanceof AbortSignal
45
+ ? signalOrRes
46
+ : createAbortSignal(req, signalOrRes);
42
47
  const host = req.headers['host'] || '127.0.0.1';
43
48
  const url = new URL(req.url || '/', `http://${ host }`);
44
49
  const method = (req.method || 'GET').toUpperCase();
@@ -53,9 +58,11 @@ function toWebRequest(req) {
53
58
  return new Request(url, { method, headers, signal, body, duplex: 'half'});
54
59
  }
55
60
 
61
+ /** @import { ServerResponse } from 'node:http' */
62
+
56
63
  /**
57
64
  *
58
- * @param {import('node:http').ServerResponse | Http2ServerResponse} res
65
+ * @param {ServerResponse | Http2ServerResponse} res
59
66
  * @param {Response} response
60
67
  * @param {(e: any) => void} onError
61
68
  * @returns
@@ -80,6 +87,8 @@ async function linkResponse(res, response, onError) {
80
87
  readable.pipe(res instanceof node_http2.Http2ServerResponse ? res.stream : res);
81
88
  }
82
89
 
90
+ /** @import { IncomingMessage, ServerResponse } from 'node:http' */
91
+
83
92
  /**
84
93
  *
85
94
  * @param {any} e
@@ -88,8 +97,8 @@ function echoError(e) {
88
97
  console.error(e);
89
98
  }
90
99
  /**
91
- * @template {import('node:http').IncomingMessage | import('node:http2').Http2ServerRequest} TReq
92
- * @template {import('node:http').ServerResponse | import('node:http2').Http2ServerResponse} TRes
100
+ * @template {IncomingMessage | Http2ServerRequest} TReq
101
+ * @template {ServerResponse | Http2ServerResponse} TRes
93
102
  * @typedef {object} HttpCallbackOptions
94
103
  * @property {(req: TReq, res: TRes, next?: () => void) => any} [notFound]
95
104
  * @property {(e: any) => void} [onError]
@@ -97,8 +106,8 @@ function echoError(e) {
97
106
  */
98
107
  /**
99
108
  *
100
- * @template {import('node:http').IncomingMessage | import('node:http2').Http2ServerRequest} TReq
101
- * @template {import('node:http').ServerResponse | import('node:http2').Http2ServerResponse} TRes
109
+ * @template {IncomingMessage | Http2ServerRequest} TReq
110
+ * @template {ServerResponse | Http2ServerResponse} TRes
102
111
  * @param {(request: Request) => Promise<Response | null>} run
103
112
  * @param {HttpCallbackOptions<TReq, TRes>} [options]
104
113
  * @returns {(req: TReq, res: TRes, next?: () => void) => any}
@@ -109,7 +118,7 @@ function createHttpCallback(run, {
109
118
  errorInResponse,
110
119
  } = {}) {
111
120
  return function httpCallback(req, res, next) {
112
- return run(toWebRequest(req)).then(r => {
121
+ return run(toWebRequest(req, res)).then(r => {
113
122
  if (r) { return linkResponse(res, r, onError); }
114
123
  if (notFound) { return notFound(req, res, next); }
115
124
  if (next) { return next(); }
package/node/index.d.cts CHANGED
@@ -1,34 +1,31 @@
1
- /// <reference types="node" />
2
1
  /*!
3
- * k99 v0.6.0
4
- * (c) 2019-2024 猛火Fierflame
2
+ * k99 v0.6.1
3
+ * (c) 2019-2025 猛火Fierflame
5
4
  * @license MIT
6
5
  */
7
- import * as node_http2 from 'node:http2';
8
- import { Http2ServerResponse } from 'node:http2';
9
- import * as node_http from 'node:http';
10
- import * as http2 from 'http2';
11
- import * as http from 'http';
6
+ import { IncomingMessage, ServerResponse } from 'node:http';
7
+ import { Http2ServerRequest, Http2ServerResponse } from 'node:http2';
12
8
 
13
9
  /**
14
10
  *
15
- * @param {import('node:http').IncomingMessage | import('node:http2').Http2ServerRequest} req
11
+ * @param {IncomingMessage | Http2ServerRequest} req
12
+ * @param {AbortSignal | ServerResponse | Http2ServerResponse} [signalOrRes]
16
13
  * @returns {Request}
17
14
  */
18
- declare function toWebRequest(req: node_http.IncomingMessage | node_http2.Http2ServerRequest): Request;
15
+ declare function toWebRequest(req: IncomingMessage | Http2ServerRequest, signalOrRes?: AbortSignal | ServerResponse | Http2ServerResponse): Request;
19
16
 
20
17
  /**
21
18
  *
22
- * @param {import('node:http').ServerResponse | Http2ServerResponse} res
19
+ * @param {ServerResponse | Http2ServerResponse} res
23
20
  * @param {Response} response
24
21
  * @param {(e: any) => void} onError
25
22
  * @returns
26
23
  */
27
- declare function linkResponse(res: node_http.ServerResponse | Http2ServerResponse, response: Response, onError: (e: any) => void): Promise<void>;
24
+ declare function linkResponse(res: ServerResponse | Http2ServerResponse, response: Response, onError: (e: any) => void): Promise<void>;
28
25
 
29
26
  /**
30
- * @template {import('node:http').IncomingMessage | import('node:http2').Http2ServerRequest} TReq
31
- * @template {import('node:http').ServerResponse | import('node:http2').Http2ServerResponse} TRes
27
+ * @template {IncomingMessage | Http2ServerRequest} TReq
28
+ * @template {ServerResponse | Http2ServerResponse} TRes
32
29
  * @typedef {object} HttpCallbackOptions
33
30
  * @property {(req: TReq, res: TRes, next?: () => void) => any} [notFound]
34
31
  * @property {(e: any) => void} [onError]
@@ -36,14 +33,14 @@ declare function linkResponse(res: node_http.ServerResponse | Http2ServerRespons
36
33
  */
37
34
  /**
38
35
  *
39
- * @template {import('node:http').IncomingMessage | import('node:http2').Http2ServerRequest} TReq
40
- * @template {import('node:http').ServerResponse | import('node:http2').Http2ServerResponse} TRes
36
+ * @template {IncomingMessage | Http2ServerRequest} TReq
37
+ * @template {ServerResponse | Http2ServerResponse} TRes
41
38
  * @param {(request: Request) => Promise<Response | null>} run
42
39
  * @param {HttpCallbackOptions<TReq, TRes>} [options]
43
40
  * @returns {(req: TReq, res: TRes, next?: () => void) => any}
44
41
  */
45
- declare function createHttpCallback<TReq extends http.IncomingMessage | http2.Http2ServerRequest, TRes extends http.ServerResponse<http.IncomingMessage> | Http2ServerResponse>(run: (request: Request) => Promise<Response | null>, { notFound, onError, errorInResponse, }?: HttpCallbackOptions<TReq, TRes> | undefined): (req: TReq, res: TRes, next?: () => void) => any;
46
- type HttpCallbackOptions<TReq extends http.IncomingMessage | http2.Http2ServerRequest, TRes extends http.ServerResponse<http.IncomingMessage> | Http2ServerResponse> = {
42
+ declare function createHttpCallback<TReq extends IncomingMessage | Http2ServerRequest, TRes extends ServerResponse | Http2ServerResponse>(run: (request: Request) => Promise<Response | null>, { notFound, onError, errorInResponse, }?: HttpCallbackOptions<TReq, TRes>): (req: TReq, res: TRes, next?: () => void) => any;
43
+ type HttpCallbackOptions<TReq extends IncomingMessage | Http2ServerRequest, TRes extends ServerResponse | Http2ServerResponse> = {
47
44
  notFound?: ((req: TReq, res: TRes, next?: () => void) => any) | undefined;
48
45
  onError?: ((e: any) => void) | undefined;
49
46
  errorInResponse?: boolean | undefined;
package/package.json CHANGED
@@ -1,7 +1,7 @@
1
1
  {
2
2
  "name": "k99",
3
3
  "description": "前后端均可用的 web 服务器",
4
- "version": "0.6.0",
4
+ "version": "0.6.1",
5
5
  "dependencies": {},
6
6
  "keywords": [
7
7
  "k99",
package/services.cjs CHANGED
@@ -1,6 +1,6 @@
1
1
  /*!
2
- * k99 v0.6.0
3
- * (c) 2019-2024 猛火Fierflame
2
+ * k99 v0.6.1
3
+ * (c) 2019-2025 猛火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.6.0
3
- * (c) 2019-2024 猛火Fierflame
2
+ * k99 v0.6.1
3
+ * (c) 2019-2025 猛火Fierflame
4
4
  * @license MIT
5
5
  */
6
6
  import * as k99 from 'k99';
package/services.js CHANGED
@@ -1,6 +1,6 @@
1
1
  /*!
2
- * k99 v0.6.0
3
- * (c) 2019-2024 猛火Fierflame
2
+ * k99 v0.6.1
3
+ * (c) 2019-2025 猛火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.6.0
3
- * (c) 2019-2024 猛火Fierflame
2
+ * k99 v0.6.1
3
+ * (c) 2019-2025 猛火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.6.0
3
- * (c) 2019-2024 猛火Fierflame
2
+ * k99 v0.6.1
3
+ * (c) 2019-2025 猛火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.6.0
3
- * (c) 2019-2024 猛火Fierflame
2
+ * k99 v0.6.1
3
+ * (c) 2019-2025 猛火Fierflame
4
4
  * @license MIT
5
5
  */
6
6
  /**