@microlink/function 0.1.6 → 0.2.2
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/README.md +205 -0
- package/lightweight/index-bundled.d.ts +24234 -0
- package/lightweight/index.d.ts +33 -0
- package/lightweight/index.js +1 -0
- package/lightweight/package.json +5 -0
- package/package.json +85 -24
- package/src/node.js +24 -5
- package/dist/microlink-function.js +0 -958
- package/dist/microlink-function.js.map +0 -1
- package/dist/microlink-function.min.js +0 -3
- package/dist/microlink-function.min.js.map +0 -1
- package/src/browser.js +0 -7
- package/src/factory.js +0 -29
|
@@ -0,0 +1,33 @@
|
|
|
1
|
+
import { MqlOptions } from '@microlink/mql'
|
|
2
|
+
import { Page, HTTPResponse } from 'puppeteer-core'
|
|
3
|
+
|
|
4
|
+
export type FunctionResponse = {
|
|
5
|
+
isFulfilled: true,
|
|
6
|
+
isRejected: false,
|
|
7
|
+
value: any
|
|
8
|
+
}
|
|
9
|
+
|
|
10
|
+
export type FunctionArgs = {
|
|
11
|
+
page: object;
|
|
12
|
+
response: object;
|
|
13
|
+
url: string;
|
|
14
|
+
}
|
|
15
|
+
|
|
16
|
+
export type FunctionInput = (args: {
|
|
17
|
+
page: Page;
|
|
18
|
+
response: HTTPResponse;
|
|
19
|
+
[key: string]: any;
|
|
20
|
+
}) => any;
|
|
21
|
+
|
|
22
|
+
|
|
23
|
+
declare function microlinkFunction(
|
|
24
|
+
fn: FunctionInput,
|
|
25
|
+
mqlOpts?: MqlOptions,
|
|
26
|
+
gotOpts?: object
|
|
27
|
+
): (
|
|
28
|
+
url: string,
|
|
29
|
+
mqlOpts?: MqlOptions,
|
|
30
|
+
gotOpts?: object
|
|
31
|
+
) => Promise<FunctionResponse>;
|
|
32
|
+
|
|
33
|
+
export default microlinkFunction;
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
var t={exports:{}};const e=/^https?:\/\//i;var r={};function s(t,e,r,o,n){var i,a=n?n+r:n;if(null==o)e&&(t[n]=o);else if("object"!=typeof o)t[n]=o;else if(Array.isArray(o))for(i=0;i<o.length;i++)s(t,e,r,o[i],a+i);else for(i in o)s(t,e,r,o[i],a+i)}r.flattie=function(t,e,r){var o={};return"object"==typeof t&&s(o,!!r,e||".",t,""),o};const o={FREE:"https://api.microlink.io/",PRO:"https://pro.microlink.io/"},n=t=>null!==t&&"object"==typeof t;class i extends Error{constructor(t,e,r){const s=`${t.status||0===t.status?t.status:""} ${t.statusText||""}`.trim();super("Request failed with "+(s?`status code ${s}`:"an unknown error")),Object.defineProperty(this,"response",{enumerable:!0,configurable:!0,writable:!0,value:void 0}),Object.defineProperty(this,"request",{enumerable:!0,configurable:!0,writable:!0,value:void 0}),Object.defineProperty(this,"options",{enumerable:!0,configurable:!0,writable:!0,value:void 0}),this.name="HTTPError",this.response=t,this.request=e,this.options=r}}class a extends Error{constructor(t){super("Request timed out"),Object.defineProperty(this,"request",{enumerable:!0,configurable:!0,writable:!0,value:void 0}),this.name="TimeoutError",this.request=t}}const u=t=>null!==t&&"object"==typeof t,c=(...t)=>{for(const e of t)if((!u(e)||Array.isArray(e))&&void 0!==e)throw new TypeError("The `options` argument must be an object");return h({},...t)},l=(t={},e={})=>{const r=new globalThis.Headers(t),s=e instanceof globalThis.Headers,o=new globalThis.Headers(e);for(const[t,e]of o.entries())s&&"undefined"===e||void 0===e?r.delete(t):r.set(t,e);return r},h=(...t)=>{let e={},r={};for(const s of t)if(Array.isArray(s))Array.isArray(e)||(e=[]),e=[...e,...s];else if(u(s)){for(let[t,r]of Object.entries(s))u(r)&&t in e&&(r=h(e[t],r)),e={...e,[t]:r};u(s.headers)&&(r=l(r,s.headers),e.headers=r)}return e},p=(()=>{let t=!1,e=!1;const r="function"==typeof globalThis.ReadableStream,s="function"==typeof globalThis.Request;return r&&s&&(e=new globalThis.Request("https://empty.invalid",{body:new globalThis.ReadableStream,method:"POST",get duplex(){return t=!0,"half"}}).headers.has("Content-Type")),t&&!e})(),f="function"==typeof globalThis.AbortController,d="function"==typeof globalThis.ReadableStream,y="function"==typeof globalThis.FormData,b=["get","post","put","patch","head","delete"],m={json:"application/json",text:"text/*",formData:"multipart/form-data",arrayBuffer:"*/*",blob:"*/*"},_=2147483647,w=Symbol("stop"),g={json:!0,parseJson:!0,searchParams:!0,prefixUrl:!0,retry:!0,timeout:!0,hooks:!0,throwHttpErrors:!0,onDownloadProgress:!0,fetch:!0},T={method:!0,headers:!0,body:!0,mode:!0,credentials:!0,cache:!0,redirect:!0,referrer:!0,referrerPolicy:!0,integrity:!0,keepalive:!0,signal:!0,window:!0,dispatcher:!0,duplex:!0},R=t=>b.includes(t)?t.toUpperCase():t,v=[413,429,503],E={limit:2,methods:["get","put","head","delete","options","trace"],statusCodes:[408,413,429,500,502,503,504],afterStatusCodes:v,maxRetryAfter:Number.POSITIVE_INFINITY,backoffLimit:Number.POSITIVE_INFINITY,delay:t=>.3*2**(t-1)*1e3},q=(t={})=>{if("number"==typeof t)return{...E,limit:t};if(t.methods&&!Array.isArray(t.methods))throw new Error("retry.methods must be an array");if(t.statusCodes&&!Array.isArray(t.statusCodes))throw new Error("retry.statusCodes must be an array");return{...E,...t,afterStatusCodes:v}};class x{static create(t,e){const r=new x(t,e),s=async()=>{if("number"==typeof r._options.timeout&&r._options.timeout>_)throw new RangeError("The `timeout` option cannot be greater than 2147483647");await Promise.resolve();let t=await r._fetch();for(const e of r._options.hooks.afterResponse){const s=await e(r.request,r._options,r._decorateResponse(t.clone()));s instanceof globalThis.Response&&(t=s)}if(r._decorateResponse(t),!t.ok&&r._options.throwHttpErrors){let e=new i(t,r.request,r._options);for(const t of r._options.hooks.beforeError)e=await t(e);throw e}if(r._options.onDownloadProgress){if("function"!=typeof r._options.onDownloadProgress)throw new TypeError("The `onDownloadProgress` option must be a function");if(!d)throw new Error("Streams are not supported in your environment. `ReadableStream` is missing.");return r._stream(t.clone(),r._options.onDownloadProgress)}return t},o=r._options.retry.methods.includes(r.request.method.toLowerCase())?r._retry(s):s();for(const[t,s]of Object.entries(m))o[t]=async()=>{r.request.headers.set("accept",r.request.headers.get("accept")||s);const n=(await o).clone();if("json"===t){if(204===n.status)return"";if(0===(await n.clone().arrayBuffer()).byteLength)return"";if(e.parseJson)return e.parseJson(await n.text())}return n[t]()};return o}constructor(t,e={}){if(Object.defineProperty(this,"request",{enumerable:!0,configurable:!0,writable:!0,value:void 0}),Object.defineProperty(this,"abortController",{enumerable:!0,configurable:!0,writable:!0,value:void 0}),Object.defineProperty(this,"_retryCount",{enumerable:!0,configurable:!0,writable:!0,value:0}),Object.defineProperty(this,"_input",{enumerable:!0,configurable:!0,writable:!0,value:void 0}),Object.defineProperty(this,"_options",{enumerable:!0,configurable:!0,writable:!0,value:void 0}),this._input=t,this._options={credentials:this._input.credentials||"same-origin",...e,headers:l(this._input.headers,e.headers),hooks:h({beforeRequest:[],beforeRetry:[],beforeError:[],afterResponse:[]},e.hooks),method:R(e.method??this._input.method),prefixUrl:String(e.prefixUrl||""),retry:q(e.retry),throwHttpErrors:!1!==e.throwHttpErrors,timeout:e.timeout??1e4,fetch:e.fetch??globalThis.fetch.bind(globalThis)},"string"!=typeof this._input&&!(this._input instanceof URL||this._input instanceof globalThis.Request))throw new TypeError("`input` must be a string, URL, or Request");if(this._options.prefixUrl&&"string"==typeof this._input){if(this._input.startsWith("/"))throw new Error("`input` must not begin with a slash when using `prefixUrl`");this._options.prefixUrl.endsWith("/")||(this._options.prefixUrl+="/"),this._input=this._options.prefixUrl+this._input}if(f){if(this.abortController=new globalThis.AbortController,this._options.signal){const t=this._options.signal;this._options.signal.addEventListener("abort",(()=>{this.abortController.abort(t.reason)}))}this._options.signal=this.abortController.signal}if(p&&(this._options.duplex="half"),this.request=new globalThis.Request(this._input,this._options),this._options.searchParams){const t="?"+("string"==typeof this._options.searchParams?this._options.searchParams.replace(/^\?/,""):new URLSearchParams(this._options.searchParams).toString()),e=this.request.url.replace(/(?:\?.*?)?(?=#|$)/,t);!(y&&this._options.body instanceof globalThis.FormData||this._options.body instanceof URLSearchParams)||this._options.headers&&this._options.headers["content-type"]||this.request.headers.delete("content-type"),this.request=new globalThis.Request(new globalThis.Request(e,{...this.request}),this._options)}void 0!==this._options.json&&(this._options.body=JSON.stringify(this._options.json),this.request.headers.set("content-type",this._options.headers.get("content-type")??"application/json"),this.request=new globalThis.Request(this.request,{body:this._options.body}))}_calculateRetryDelay(t){if(this._retryCount++,this._retryCount<this._options.retry.limit&&!(t instanceof a)){if(t instanceof i){if(!this._options.retry.statusCodes.includes(t.response.status))return 0;const e=t.response.headers.get("Retry-After");if(e&&this._options.retry.afterStatusCodes.includes(t.response.status)){let t=Number(e);return Number.isNaN(t)?t=Date.parse(e)-Date.now():t*=1e3,void 0!==this._options.retry.maxRetryAfter&&t>this._options.retry.maxRetryAfter?0:t}if(413===t.response.status)return 0}const e=this._options.retry.delay(this._retryCount);return Math.min(this._options.retry.backoffLimit,e)}return 0}_decorateResponse(t){return this._options.parseJson&&(t.json=async()=>this._options.parseJson(await t.text())),t}async _retry(t){try{return await t()}catch(e){const r=Math.min(this._calculateRetryDelay(e),_);if(0!==r&&this._retryCount>0){await async function(t,{signal:e}){return new Promise(((r,s)=>{function o(){clearTimeout(n),s(e.reason)}e&&(e.throwIfAborted(),e.addEventListener("abort",o,{once:!0}));const n=setTimeout((()=>{e?.removeEventListener("abort",o),r()}),t)}))}(r,{signal:this._options.signal});for(const t of this._options.hooks.beforeRetry)if(await t({request:this.request,options:this._options,error:e,retryCount:this._retryCount})===w)return;return this._retry(t)}throw e}}async _fetch(){for(const t of this._options.hooks.beforeRequest){const e=await t(this.request,this._options);if(e instanceof Request){this.request=e;break}if(e instanceof Response)return e}const t=((t,e)=>{const r={};for(const s in e)s in T||s in g||s in t||(r[s]=e[s]);return r})(this.request,this._options);return!1===this._options.timeout?this._options.fetch(this.request.clone(),t):async function(t,e,r,s){return new Promise(((o,n)=>{const i=setTimeout((()=>{r&&r.abort(),n(new a(t))}),s.timeout);s.fetch(t,e).then(o).catch(n).then((()=>{clearTimeout(i)}))}))}(this.request.clone(),t,this.abortController,this._options)}_stream(t,e){const r=Number(t.headers.get("content-length"))||0;let s=0;return 204===t.status?(e&&e({percent:1,totalBytes:r,transferredBytes:s},new Uint8Array),new globalThis.Response(null,{status:t.status,statusText:t.statusText,headers:t.headers})):new globalThis.Response(new globalThis.ReadableStream({async start(o){const n=t.body.getReader();e&&e({percent:0,transferredBytes:0,totalBytes:r},new Uint8Array),await async function t(){const{done:i,value:a}=await n.read();i?o.close():(e&&(s+=a.byteLength,e({percent:0===r?0:s/r,transferredBytes:s,totalBytes:r},a)),o.enqueue(a),await t())}()}}),{status:t.status,statusText:t.statusText,headers:t.headers})}}const P=t=>{const e=(e,r)=>x.create(e,c(t,r));for(const r of b)e[r]=(e,s)=>x.create(e,c(t,s,{method:r}));return e.create=t=>P(c(t)),e.extend=e=>P(c(t,e)),e.stop=w,e},j=P();var C=function(t){if(t.__esModule)return t;var e=t.default;if("function"==typeof e){var r=function t(){return this instanceof t?Reflect.construct(e,arguments,this.constructor):e.apply(this,arguments)};r.prototype=e.prototype}else r={};return Object.defineProperty(r,"__esModule",{value:!0}),Object.keys(t).forEach((function(e){var s=Object.getOwnPropertyDescriptor(t,e);Object.defineProperty(r,e,s.get?s:{enumerable:!0,get:function(){return t[e]}})})),r}(Object.freeze({__proto__:null,HTTPError:i,TimeoutError:a,default:j}));const{flattie:O}=r,A=({VERSION:t,MicrolinkError:e,urlHttp:r,got:s,flatten:i})=>{const a=t=>{if(!n(t))return;const e=i(t);return Object.keys(e).reduce(((t,r)=>(t[`data.${r}`]=e[r].toString(),t)),{})},u=async(t,r={})=>{try{const e=await s(t,r);return"buffer"===r.responseType?{body:e.body,response:e}:{...e.body,response:e}}catch(r){const{response:s={}}=r,{statusCode:i,body:a,headers:u={},url:c=t}=s,l=null!=(o=a)&&null!=o.constructor&&"function"==typeof o.constructor.isBuffer&&o.constructor.isBuffer(o),h=n(a)&&!l?a:((t,e,r)=>{try{return JSON.parse(t)}catch(s){const o=t||e.message;return{status:"error",data:{url:o},more:"https://microlink.io/efatalclient",code:"EFATALCLIENT",message:o,url:r}}})(l?a.toString():a,r,c);throw new e({...h,message:h.message,url:c,statusCode:i,headers:u})}var o},c=(t,{data:e,apiKey:r,endpoint:s,retry:n,cache:u,...c}={},{responseType:l="json",headers:h,...p}={})=>{const f=!!r;return[`${s||o[f?"PRO":"FREE"]}?${new URLSearchParams({url:t,...a(e),...i(c)}).toString()}`,{...p,responseType:l,cache:u,retry:n,headers:f?{...h,"x-api-key":r}:{...h}}]},l=t=>async(s,o,n)=>{((t="")=>{if(!r(t)){const r=`The \`url\` as \`${t}\` is not valid. Ensure it has protocol (http or https) and hostname.`;throw new e({status:"fail",data:{url:r},more:"https://microlink.io/docs/api/api-parameters/url",code:"EINVALURLCLIENT",message:r,url:t})}})(s);const[i,a]=c(s,o,{...t,...n});return u(i,a)},h=l();return h.MicrolinkError=e,h.getApiUrl=c,h.fetchFromApi=u,h.mapRules=a,h.version=t,h.stream=s.stream,h.buffer=l({responseType:"buffer"}),h},{default:k}=C;class S extends Error{constructor(t){super(),this.name="MicrolinkError",Object.assign(this,t),this.description=this.message,this.message=this.code?`${this.code}, ${this.description}`:this.description}}const U=A({MicrolinkError:S,urlHttp:t=>{try{const{href:r}=new URL(t);return e.test(r)&&r}catch(t){return!1}},got:async(t,e)=>{try{e.retry>0&&(e.retry=e.retry+1),void 0===e.timeout&&(e.timeout=!1);const r=await k(t,e),s=await r.json(),{headers:o,status:n}=r;return{url:r.url,body:s,headers:o,statusCode:n}}catch(t){if(t.response){const{response:e}=t;t.response={...e,headers:Array.from(e.headers.entries()).reduce(((t,[e,r])=>(t[e]=r,t)),{}),statusCode:e.status,body:await e.text()}}throw t}},flatten:O,VERSION:"0.11.7"});t.exports=U,t.exports.MicrolinkError=U.MicrolinkError,t.exports.getApiUrl=U.getApiUrl,t.exports.mapRules=U.mapRules,t.exports.version=U.version;var L=function(t){return t&&t.__esModule&&Object.prototype.hasOwnProperty.call(t,"default")?t.default:t}(t.exports);const N=(t,e,r)=>async(s,o)=>{const{data:n}=await L(s,{function:t.toString(),meta:!1,...e,...o},r);return n.function};N.mql=L,N.render=L.render,N.version="0.2.2";export{N as default};
|
package/package.json
CHANGED
|
@@ -1,13 +1,17 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@microlink/function",
|
|
3
|
-
"
|
|
4
|
-
"
|
|
5
|
-
"
|
|
6
|
-
"
|
|
3
|
+
"description": "Browser functions as Service. Interacting with browser pages, remotely.",
|
|
4
|
+
"homepage": "https://function.microlink.io",
|
|
5
|
+
"version": "0.2.2",
|
|
6
|
+
"types": "lightweight/index.d.ts",
|
|
7
|
+
"exports": {
|
|
8
|
+
"require": "./src/node.js",
|
|
9
|
+
"default": "./lightweight/index.js"
|
|
10
|
+
},
|
|
7
11
|
"author": {
|
|
8
|
-
"name": "Kiko Beats",
|
|
9
12
|
"email": "josefrancisco.verdu@gmail.com",
|
|
10
|
-
"
|
|
13
|
+
"name": "Kiko Beats",
|
|
14
|
+
"url": "https://github.com/Kikobeats"
|
|
11
15
|
},
|
|
12
16
|
"repository": {
|
|
13
17
|
"type": "git",
|
|
@@ -27,48 +31,105 @@
|
|
|
27
31
|
"serverless"
|
|
28
32
|
],
|
|
29
33
|
"dependencies": {
|
|
30
|
-
"@microlink/mql": "~0.
|
|
34
|
+
"@microlink/mql": "~0.11.8",
|
|
31
35
|
"base64-url": "~2.3.3"
|
|
32
36
|
},
|
|
33
37
|
"devDependencies": {
|
|
38
|
+
"@commitlint/cli": "latest",
|
|
39
|
+
"@commitlint/config-conventional": "latest",
|
|
40
|
+
"@ksmithut/prettier-standard": "latest",
|
|
34
41
|
"@rollup/plugin-commonjs": "latest",
|
|
35
42
|
"@rollup/plugin-node-resolve": "latest",
|
|
36
43
|
"@rollup/plugin-replace": "latest",
|
|
37
|
-
"
|
|
44
|
+
"@rollup/plugin-terser": "latest",
|
|
45
|
+
"async-listen": "latest",
|
|
38
46
|
"ava": "latest",
|
|
47
|
+
"c8": "latest",
|
|
48
|
+
"ci-publish": "latest",
|
|
39
49
|
"conventional-github-releaser": "latest",
|
|
40
|
-
"
|
|
50
|
+
"execa": "latest",
|
|
51
|
+
"git-authors-cli": "latest",
|
|
52
|
+
"nano-staged": "latest",
|
|
41
53
|
"npm-check-updates": "latest",
|
|
42
|
-
"
|
|
54
|
+
"prettier-standard": "latest",
|
|
55
|
+
"puppeteer-core": "latest",
|
|
43
56
|
"rollup": "latest",
|
|
44
57
|
"rollup-plugin-filesize": "latest",
|
|
45
|
-
"rollup-plugin-
|
|
46
|
-
"rollup-plugin-
|
|
47
|
-
"
|
|
58
|
+
"rollup-plugin-rewrite": "latest",
|
|
59
|
+
"rollup-plugin-visualizer": "latest",
|
|
60
|
+
"simple-git-hooks": "latest",
|
|
61
|
+
"standard": "latest",
|
|
62
|
+
"standard-markdown": "latest",
|
|
63
|
+
"standard-version": "latest",
|
|
64
|
+
"stream-to-promise": "latest",
|
|
65
|
+
"tsd": "latest",
|
|
66
|
+
"tsup": "latest"
|
|
48
67
|
},
|
|
49
68
|
"engines": {
|
|
50
|
-
"node": ">=
|
|
69
|
+
"node": ">= 18"
|
|
51
70
|
},
|
|
52
71
|
"files": [
|
|
53
|
-
"
|
|
54
|
-
"src"
|
|
72
|
+
"lightweight",
|
|
73
|
+
"src/factory.js",
|
|
74
|
+
"src/node.js"
|
|
55
75
|
],
|
|
56
76
|
"scripts": {
|
|
57
|
-
"build": "rollup
|
|
58
|
-
"
|
|
77
|
+
"build": "npm run build:rollup && npm run build:tsup",
|
|
78
|
+
"build:rollup": "rollup -c rollup.config.js --bundleConfigAsCjs",
|
|
79
|
+
"build:tsup": "npx tsup --entry.index-bundled lightweight/index.d.ts --dts-only --dts-resolve --out-dir lightweight/",
|
|
80
|
+
"clean": "rm -rf node_modules",
|
|
81
|
+
"clean:build": "rm -rf lightweight/index.js",
|
|
82
|
+
"contributors": "(npx git-authors-cli && npx finepack && git add package.json && git commit -m 'build: contributors' --no-verify) || true",
|
|
59
83
|
"dev": "npm run build -- -w",
|
|
60
|
-
"
|
|
84
|
+
"lint": "standard && tsd",
|
|
85
|
+
"postrelease": "npm run release:tags && npm run release:github && (ci-publish || npm publish --access=public)",
|
|
86
|
+
"prebuild": "npm run clean:build",
|
|
87
|
+
"prepublishOnly": "npm run build",
|
|
88
|
+
"prerelease": "npm run update:check",
|
|
89
|
+
"pretest": "npm run lint && npm run build",
|
|
90
|
+
"release": "standard-version -a",
|
|
91
|
+
"release:github": "conventional-github-releaser -p angular",
|
|
92
|
+
"release:tags": "git push --follow-tags origin HEAD:master",
|
|
93
|
+
"test": "c8 ava --verbose",
|
|
94
|
+
"update": "ncu -u",
|
|
95
|
+
"update:check": "ncu -- --error-level 2"
|
|
61
96
|
},
|
|
62
97
|
"license": "MIT",
|
|
63
98
|
"ava": {
|
|
64
99
|
"files": [
|
|
65
100
|
"test/**/*",
|
|
66
|
-
"!test/
|
|
67
|
-
"!test/clients.js"
|
|
101
|
+
"!test/clients.mjs"
|
|
68
102
|
],
|
|
69
103
|
"timeout": "1m"
|
|
70
104
|
},
|
|
71
|
-
"
|
|
72
|
-
|
|
73
|
-
|
|
105
|
+
"commitlint": {
|
|
106
|
+
"extends": [
|
|
107
|
+
"@commitlint/config-conventional"
|
|
108
|
+
]
|
|
109
|
+
},
|
|
110
|
+
"nano-staged": {
|
|
111
|
+
"*.js": [
|
|
112
|
+
"prettier-standard",
|
|
113
|
+
"standard --fix"
|
|
114
|
+
],
|
|
115
|
+
"*.md": [
|
|
116
|
+
"standard-markdown"
|
|
117
|
+
],
|
|
118
|
+
"package.json": [
|
|
119
|
+
"finepack"
|
|
120
|
+
]
|
|
121
|
+
},
|
|
122
|
+
"simple-git-hooks": {
|
|
123
|
+
"commit-msg": "npx commitlint --edit",
|
|
124
|
+
"pre-commit": "npx nano-staged"
|
|
125
|
+
},
|
|
126
|
+
"standard": {
|
|
127
|
+
"ignore": [
|
|
128
|
+
"lightweight/index.js",
|
|
129
|
+
"src/node.mjs"
|
|
130
|
+
]
|
|
131
|
+
},
|
|
132
|
+
"tsd": {
|
|
133
|
+
"directory": "test"
|
|
134
|
+
}
|
|
74
135
|
}
|
package/src/node.js
CHANGED
|
@@ -12,8 +12,27 @@ const toCompress = code =>
|
|
|
12
12
|
data => `br#${escape(data.toString('base64'))}`
|
|
13
13
|
)
|
|
14
14
|
|
|
15
|
-
|
|
16
|
-
|
|
17
|
-
|
|
18
|
-
|
|
19
|
-
}
|
|
15
|
+
const fn = (code, mqlOpts, gotOpts) => {
|
|
16
|
+
const compress = toCompress(code)
|
|
17
|
+
|
|
18
|
+
return async (url, opts) => {
|
|
19
|
+
const { data } = await mql(
|
|
20
|
+
url,
|
|
21
|
+
{
|
|
22
|
+
function: await compress,
|
|
23
|
+
meta: false,
|
|
24
|
+
...mqlOpts,
|
|
25
|
+
...opts
|
|
26
|
+
},
|
|
27
|
+
gotOpts
|
|
28
|
+
)
|
|
29
|
+
|
|
30
|
+
return data.function
|
|
31
|
+
}
|
|
32
|
+
}
|
|
33
|
+
|
|
34
|
+
fn.mql = mql
|
|
35
|
+
fn.render = mql.render
|
|
36
|
+
fn.version = require('../package.json').version
|
|
37
|
+
|
|
38
|
+
module.exports = fn
|