mtxuilib 0.0.379 → 0.0.381
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/dist/esm/lib/http/backup/http/cors.d.ts +15 -0
- package/dist/esm/lib/http/backup/http/cors.js +1 -0
- package/dist/esm/lib/http/backup/http/fetchMiddleWithCache.d.ts +2 -0
- package/dist/esm/lib/http/backup/http/fetchMiddleWithCache.js +1 -0
- package/dist/esm/lib/http/backup/http/fetchMiddleWithUrlProxy.d.ts +2 -0
- package/dist/esm/lib/http/backup/http/fetchMiddleWithUrlProxy.js +1 -0
- package/dist/esm/lib/http/backup/http/mthttp.d.ts +5 -0
- package/dist/esm/lib/http/backup/http/mthttp.js +1 -0
- package/dist/esm/lib/http/backup/http/response-cache.test.js +1 -0
- package/dist/tsconfig.type.tsbuildinfo +1 -1
- package/package.json +1 -1
|
@@ -0,0 +1,15 @@
|
|
|
1
|
+
type StaticOrigin = boolean | string | RegExp | (boolean | string | RegExp)[];
|
|
2
|
+
type OriginFn = (origin: string | undefined, req: Request) => StaticOrigin | Promise<StaticOrigin>;
|
|
3
|
+
interface CorsOptions {
|
|
4
|
+
origin?: StaticOrigin | OriginFn;
|
|
5
|
+
methods?: string | string[];
|
|
6
|
+
allowedHeaders?: string | string[];
|
|
7
|
+
exposedHeaders?: string | string[];
|
|
8
|
+
credentials?: boolean;
|
|
9
|
+
maxAge?: number;
|
|
10
|
+
preflightContinue?: boolean;
|
|
11
|
+
optionsSuccessStatus?: number;
|
|
12
|
+
}
|
|
13
|
+
export default function cors(req: Request, res: Response, options?: CorsOptions): Promise<Response>;
|
|
14
|
+
export declare function initCors(options?: CorsOptions): (req: Request, res: Response) => Promise<Response>;
|
|
15
|
+
export {};
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
var O=Object.defineProperty;var p=Object.getOwnPropertySymbols;var h=Object.prototype.hasOwnProperty,y=Object.prototype.propertyIsEnumerable;var l=(t,e,s)=>e in t?O(t,e,{enumerable:!0,configurable:!0,writable:!0,value:s}):t[e]=s,u=(t,e)=>{for(var s in e||(e={}))h.call(e,s)&&l(t,s,e[s]);if(p)for(var s of p(e))y.call(e,s)&&l(t,s,e[s]);return t};var f=(t,e,s)=>new Promise((n,r)=>{var c=i=>{try{a(s.next(i))}catch(o){r(o)}},g=i=>{try{a(s.throw(i))}catch(o){r(o)}},a=i=>i.done?n(i.value):Promise.resolve(i.value).then(c,g);a((s=s.apply(t,e)).next())});const H={origin:"*",methods:"GET,HEAD,PUT,PATCH,POST,DELETE",preflightContinue:!1,optionsSuccessStatus:204};function A(t,e){return Array.isArray(e)?e.some(s=>A(t,s)):typeof e=="string"?t===e:e instanceof RegExp?e.test(t):!!e}function m(t,e){const s=new Headers;return e==="*"?s.set("Access-Control-Allow-Origin","*"):typeof e=="string"?(s.set("Access-Control-Allow-Origin",e),s.append("Vary","Origin")):(A(t!=null?t:"",e)&&t&&s.set("Access-Control-Allow-Origin",t),s.append("Vary","Origin")),s}function S(t,e){return f(this,null,function*(){const s=t.headers.get("Origin")||void 0,n=typeof e=="function"?yield e(s,t):e;if(n)return m(s,n)})}function x(t,e){const s=new Headers;return e?Array.isArray(e)&&(e=e.join(",")):(e=t.headers.get("Access-Control-Request-Headers"),s.append("Vary","Access-Control-Request-Headers")),e&&s.set("Access-Control-Allow-Headers",e),s}function C(t,e,s){return f(this,null,function*(){var i;const n=u(u({},H),s),{headers:r}=e,c=yield S(t,(i=n.origin)!=null?i:!1),g=(o,d)=>{d==="Vary"?r.append(d,o):r.set(d,o)};if(!c)return e;c.forEach(g),n.credentials&&r.set("Access-Control-Allow-Credentials","true");const a=Array.isArray(n.exposedHeaders)?n.exposedHeaders.join(","):n.exposedHeaders;if(a&&r.set("Access-Control-Expose-Headers",a),t.method==="OPTIONS"){if(n.methods){const o=Array.isArray(n.methods)?n.methods.join(","):n.methods;r.set("Access-Control-Allow-Methods",o)}return x(t,n.allowedHeaders).forEach(g),typeof n.maxAge=="number"&&r.set("Access-Control-Max-Age",String(n.maxAge)),n.preflightContinue?e:(r.set("Content-Length","0"),new Response(null,{status:n.optionsSuccessStatus,headers:r}))}return e})}function E(t){return(e,s)=>C(e,s,t)}export{C as default,E as initCors};
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
var y=(r,e,t)=>new Promise((n,a)=>{var s=i=>{try{o(t.next(i))}catch(l){a(l)}},c=i=>{try{o(t.throw(i))}catch(l){a(l)}},o=i=>i.done?n(i.value):Promise.resolve(i.value).then(s,c);o((t=t.apply(r,e)).next())});import{LRUCache as u}from"lru-cache";import{sha256WithAlphabets as f}from"mtxuilib/lib/utils";const d={max:500,maxSize:5e3,sizeCalculation:(r,e)=>1,ttl:1e3*30,allowStale:!1,updateAgeOnGet:!1,updateAgeOnHas:!1},h=new u(d),g=(r,e)=>{const n=new Request(r,e).headers.get("authorization");let a="";return e!=null&&e.body&&(a=e.body.toString()),f(r+n+a)};function w(r){return(e,t)=>y(this,null,function*(){const n=yield g(e,t),a=h.get(n);if(a)return new Response(new Uint8Array(a));{const s=yield r(e,t);if(s.status==200&&s.body){const[c,o]=s.body.tee();return p(n,o),new Response(c,s)}return s.clone()}})}function p(r,e){return y(this,null,function*(){const t=[];let n=!1;const a=yield e.getReader();for(;!n;){const{value:c,done:o}=yield a.read();n=o,c&&t.push(c)}const s=new Uint8Array(t.reduce((c,o)=>[...c,...Array.from(o)],[]));s.buffer.byteLength>0&&h.set(r,s.buffer)})}export{w as fetchMiddleWithCache};
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
var l=(r,o,e)=>new Promise((n,i)=>{var p=t=>{try{c(e.next(t))}catch(h){i(h)}},s=t=>{try{c(e.throw(t))}catch(h){i(h)}},c=t=>t.done?n(t.value):Promise.resolve(t.value).then(p,s);c((e=e.apply(r,o)).next())});const y="http://localhost:3338/api.v3/fetc";function a(r){return(o,e)=>l(this,null,function*(){return r(o,e)})}export{a as fetchMiddleWithUrlProxy};
|
|
@@ -0,0 +1,5 @@
|
|
|
1
|
+
export type FetchType = typeof fetch;
|
|
2
|
+
export declare const responseJson: (data: any) => Response;
|
|
3
|
+
export declare function jsonResponse(data: any): Promise<Response>;
|
|
4
|
+
export declare function jsonSuccessResponse(data?: any): Promise<Response>;
|
|
5
|
+
export declare function getContentType(req: Request): string | null;
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
var p=(e,t,s)=>new Promise((c,a)=>{var y=n=>{try{o(s.next(n))}catch(r){a(r)}},u=n=>{try{o(s.throw(n))}catch(r){a(r)}},o=n=>n.done?c(n.value):Promise.resolve(n.value).then(y,u);o((s=s.apply(e,t)).next())});const g=e=>new Response(JSON.stringify(e),{status:200,headers:{"Content-type":"application/json"}});function i(e){return p(this,null,function*(){try{return new Response(JSON.stringify(e),{status:200,headers:{"Content-Type":"application/json"}})}catch(t){return console.log(t),new Response(JSON.stringify({error:t.message}))}})}function h(e){return p(this,null,function*(){return i({success:!0,data:e})})}function R(e){return e.headers.get("Content-Type")}export{R as getContentType,i as jsonResponse,h as jsonSuccessResponse,g as responseJson};
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
var h=(t,n,e)=>new Promise((c,s)=>{var a=o=>{try{i(e.next(o))}catch(r){s(r)}},l=o=>{try{i(e.throw(o))}catch(r){s(r)}},i=o=>o.done?c(o.value):Promise.resolve(o.value).then(a,l);i((e=e.apply(t,n)).next())});import{fetchMiddleWithCache as f}from"./fetchMiddleWithCache";test("fetch \u7F13\u5B58\u6B63\u5E38\u60C5\u51B5",()=>h(void 0,null,function*(){const t=jest.fn(fetch),n=f(t),e=10;for(let c=0;c<e;c++){t.mockReturnValueOnce(Promise.resolve(new Response("abc",{})));const a=yield(yield n("https://www.bing.com",{headers:{authorization:"token2"}})).text();expect(a).toContain("abc")}expect(t.mock.calls.length).toBe(1)})),test("fetch \u975E200\u54CD\u5E94\u4E0D\u505A\u7F13\u5B58",()=>h(void 0,null,function*(){const t=jest.fn(fetch),n=f(t),e=10;for(let c=0;c<e;c++){t.mockReturnValueOnce(Promise.resolve(new Response("some content",{status:500})));const a=yield(yield n("https://www.bing.com",{headers:{authorization:"token1"}})).text();expect(a).toContain("some conten")}expect(t.mock.calls.length).toBe(e)})),test("fetch \u7F13\u5B58\u4E0D\u540C\u7684url",()=>h(void 0,null,function*(){const t=jest.fn(fetch),n=10,e=f(t);for(let c=0;c<n;c++){t.mockReturnValueOnce(Promise.resolve(new Response("abc",{})));const s=yield e(`https://www.bing.com/${c}`,{headers:{authorization:"token2"}});expect(yield s.text()).toContain("abc")}expect(t.mock.calls.length).toBe(10)}));
|