@microlink/mql 0.11.0-8 → 0.11.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/LICENSE.md +0 -0
- package/lightweight/index.js +1 -1
- package/package.json +25 -24
- package/src/index.d.ts +0 -29
package/LICENSE.md
CHANGED
|
File without changes
|
package/lightweight/index.js
CHANGED
|
@@ -1,2 +1,2 @@
|
|
|
1
1
|
"undefined"!=typeof globalThis?globalThis:"undefined"!=typeof window?window:"undefined"!=typeof global?global:"undefined"!=typeof self&&self;function t(t){return t&&t.__esModule&&Object.prototype.hasOwnProperty.call(t,"default")?t.default:t}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;var i=({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:l=t}=s,h=null!=(o=a)&&null!=o.constructor&&"function"==typeof o.constructor.isBuffer&&o.constructor.isBuffer(o),c=n(a)&&!h?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}}})(h?a.toString():a,r,l);throw new e({...c,message:c.message,url:l,statusCode:i,headers:u})}var o},l=(t,{data:e,apiKey:r,endpoint:s,retry:n,cache:u,...l}={},{responseType:h="json",headers:c,...p}={})=>{const f=!!r;return[`${s||o[f?"PRO":"FREE"]}?${new URLSearchParams({url:t,...a(e),...i(l)}).toString()}`,{...p,responseType:h,cache:u,retry:n,headers:f?{...c,"x-api-key":r}:{...c}}]},h=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]=l(s,o,{...t,...n});return u(i,a)},c=h();return c.MicrolinkError=e,c.getApiUrl=l,c.fetchFromApi=u,c.mapRules=a,c.version=t,c.stream=s.stream,c.buffer=h({responseType:"buffer"}),c},a={exports:{}};!function(t){class e 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 r 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 s=t=>null!==t&&"object"==typeof t,o=(...t)=>{for(const e of t)if((!s(e)||Array.isArray(e))&&void 0!==e)throw new TypeError("The `options` argument must be an object");return i({},...t)},n=(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},i=(...t)=>{let e={},r={};for(const o of t)if(Array.isArray(o))Array.isArray(e)||(e=[]),e=[...e,...o];else if(s(o)){for(let[t,r]of Object.entries(o))s(r)&&t in e&&(r=i(e[t],r)),e={...e,[t]:r};s(o.headers)&&(r=n(r,o.headers),e.headers=r)}return e},a=(()=>{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})(),u="function"==typeof globalThis.AbortController,l="function"==typeof globalThis.ReadableStream,h="function"==typeof globalThis.FormData,c=["get","post","put","patch","head","delete"],p={json:"application/json",text:"text/*",formData:"multipart/form-data",arrayBuffer:"*/*",blob:"*/*"},f=2147483647,d=Symbol("stop"),y=t=>c.includes(t)?t.toUpperCase():t,b=[413,429,503],m={limit:2,methods:["get","put","head","delete","options","trace"],statusCodes:[408,413,429,500,502,503,504],afterStatusCodes:b,maxRetryAfter:Number.POSITIVE_INFINITY,backoffLimit:Number.POSITIVE_INFINITY},w=(t={})=>{if("number"==typeof t)return{...m,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{...m,...t,afterStatusCodes:b}};async function _(t,e,s){return new Promise(((o,n)=>{const i=setTimeout((()=>{e&&e.abort(),n(new r(t))}),s.timeout);s.fetch(t).then(o).catch(n).then((()=>{clearTimeout(i)}))}))}async function g(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)}))}class T{static create(t,r){const s=new T(t,r),o=async()=>{if("number"==typeof s._options.timeout&&s._options.timeout>f)throw new RangeError(`The \`timeout\` option cannot be greater than ${f}`);await Promise.resolve();let t=await s._fetch();for(const e of s._options.hooks.afterResponse){const r=await e(s.request,s._options,s._decorateResponse(t.clone()));r instanceof globalThis.Response&&(t=r)}if(s._decorateResponse(t),!t.ok&&s._options.throwHttpErrors){let r=new e(t,s.request,s._options);for(const t of s._options.hooks.beforeError)r=await t(r);throw r}if(s._options.onDownloadProgress){if("function"!=typeof s._options.onDownloadProgress)throw new TypeError("The `onDownloadProgress` option must be a function");if(!l)throw new Error("Streams are not supported in your environment. `ReadableStream` is missing.");return s._stream(t.clone(),s._options.onDownloadProgress)}return t},n=s._options.retry.methods.includes(s.request.method.toLowerCase())?s._retry(o):o();for(const[t,e]of Object.entries(p))n[t]=async()=>{s.request.headers.set("accept",s.request.headers.get("accept")||e);const o=(await n).clone();if("json"===t){if(204===o.status)return"";if(0===(await o.clone().arrayBuffer()).byteLength)return"";if(r.parseJson)return r.parseJson(await o.text())}return o[t]()};return n}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:n(this._input.headers,e.headers),hooks:i({beforeRequest:[],beforeRetry:[],beforeError:[],afterResponse:[]},e.hooks),method:y(e.method??this._input.method),prefixUrl:String(e.prefixUrl||""),retry:w(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(u){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(a&&(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);!(h&&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 r)){if(t instanceof e){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 r=.3;return Math.min(this._options.retry.backoffLimit,r*2**(this._retryCount-1)*1e3)}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),f);if(0!==r&&this._retryCount>0){await g(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})===d)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}return!1===this._options.timeout?this._options.fetch(this.request.clone()):_(this.request.clone(),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();async function i(){const{done:t,value:a}=await n.read();t?o.close():(e&&(s+=a.byteLength,e({percent:0===r?0:s/r,transferredBytes:s,totalBytes:r},a)),o.enqueue(a),await i())}e&&e({percent:0,transferredBytes:0,totalBytes:r},new Uint8Array),await i()}}),{status:t.status,statusText:t.statusText,headers:t.headers})}}
|
|
2
|
-
/*! MIT License © Sindre Sorhus */const R=t=>{const e=(e,r)=>T.create(e,o(t,r));for(const r of c)e[r]=(e,s)=>T.create(e,o(t,s,{method:r}));return e.create=t=>R(o(t)),e.extend=e=>R(o(t,e)),e.stop=d,e},v=R();t.HTTPError=e,t.TimeoutError=r,t.default=v,Object.defineProperty(t,"__esModule",{value:!0})}(a.exports);var u=a.exports;const l=t=>{try{const{href:r}=new URL(t);return e.test(r)&&r}catch(t){return!1}},{flattie:h}=r,c=i,{default:p}=u;class f 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}}var d=t(c({MicrolinkError:f,urlHttp:l,got:async(t,e)=>{try{e.retry>0&&(e.retry=e.retry+1),void 0===e.timeout&&(e.timeout=!1);const r=await p(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:h,VERSION:"0.11.0
|
|
2
|
+
/*! MIT License © Sindre Sorhus */const R=t=>{const e=(e,r)=>T.create(e,o(t,r));for(const r of c)e[r]=(e,s)=>T.create(e,o(t,s,{method:r}));return e.create=t=>R(o(t)),e.extend=e=>R(o(t,e)),e.stop=d,e},v=R();t.HTTPError=e,t.TimeoutError=r,t.default=v,Object.defineProperty(t,"__esModule",{value:!0})}(a.exports);var u=a.exports;const l=t=>{try{const{href:r}=new URL(t);return e.test(r)&&r}catch(t){return!1}},{flattie:h}=r,c=i,{default:p}=u;class f 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}}var d=t(c({MicrolinkError:f,urlHttp:l,got:async(t,e)=>{try{e.retry>0&&(e.retry=e.retry+1),void 0===e.timeout&&(e.timeout=!1);const r=await p(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:h,VERSION:"0.11.0"}));export{d as default};
|
package/package.json
CHANGED
|
@@ -2,8 +2,8 @@
|
|
|
2
2
|
"name": "@microlink/mql",
|
|
3
3
|
"description": "Microlink Query Language. The official HTTP client to interact with Microlink API for Node.js, browsers & Deno.",
|
|
4
4
|
"homepage": "https://microlink.io/mql",
|
|
5
|
-
"version": "0.11.0
|
|
6
|
-
"types": "
|
|
5
|
+
"version": "0.11.0",
|
|
6
|
+
"types": "lightweight/index.d.ts",
|
|
7
7
|
"browser": "src/lightweight.js",
|
|
8
8
|
"umd:main": "dist/mql.js",
|
|
9
9
|
"unpkg": "dist/mql.js",
|
|
@@ -92,12 +92,31 @@
|
|
|
92
92
|
"node": ">= 12"
|
|
93
93
|
},
|
|
94
94
|
"files": [
|
|
95
|
+
"lightweight",
|
|
95
96
|
"src/factory.js",
|
|
96
97
|
"src/index.d.ts",
|
|
97
98
|
"src/ky.js",
|
|
98
|
-
"src/node.js"
|
|
99
|
-
"lightweight"
|
|
99
|
+
"src/node.js"
|
|
100
100
|
],
|
|
101
|
+
"scripts": {
|
|
102
|
+
"build": "rollup -c rollup.config.js --bundleConfigAsCjs",
|
|
103
|
+
"build:kys": "[ -f src/ky.js ] || rollup node_modules/ky/distribution/index.js --format=umd --name=ky --exports=named --file=src/ky.js",
|
|
104
|
+
"clean": "rm -rf node_modules",
|
|
105
|
+
"clean:build": "rm -rf dist lightweight/index.js",
|
|
106
|
+
"contributors": "(npx git-authors-cli && npx finepack --sort-ignore-object-at ava && git add package.json && git commit -m 'build: contributors' --no-verify) || true",
|
|
107
|
+
"dev": "npm run build -- -w",
|
|
108
|
+
"lint": "standard && tsd",
|
|
109
|
+
"postrelease": "npm run release:tags && npm run release:github && (ci-publish || npm publish --access=public)",
|
|
110
|
+
"prebuild": "npm run clean:build && npm run build:kys",
|
|
111
|
+
"prerelease": "npm run update:check",
|
|
112
|
+
"pretest": "npm run lint && npm run build",
|
|
113
|
+
"release": "standard-version -a",
|
|
114
|
+
"release:github": "conventional-github-releaser -p angular",
|
|
115
|
+
"release:tags": "git push --follow-tags origin HEAD:master",
|
|
116
|
+
"test": "c8 ava --verbose",
|
|
117
|
+
"update": "ncu -u",
|
|
118
|
+
"update:check": "ncu -- --error-level 2"
|
|
119
|
+
},
|
|
101
120
|
"license": "MIT",
|
|
102
121
|
"ava": {
|
|
103
122
|
"files": [
|
|
@@ -130,6 +149,7 @@
|
|
|
130
149
|
"standard": {
|
|
131
150
|
"ignore": [
|
|
132
151
|
"dist",
|
|
152
|
+
"lightweight/index.js",
|
|
133
153
|
"src/ky.js"
|
|
134
154
|
]
|
|
135
155
|
},
|
|
@@ -140,24 +160,5 @@
|
|
|
140
160
|
},
|
|
141
161
|
"tsd": {
|
|
142
162
|
"directory": "test"
|
|
143
|
-
},
|
|
144
|
-
"scripts": {
|
|
145
|
-
"build": "rollup -c rollup.config.js --bundleConfigAsCjs",
|
|
146
|
-
"build:kys": "[ -f src/ky.js ] || rollup node_modules/ky/distribution/index.js --format=umd --name=ky --exports=named --file=src/ky.js",
|
|
147
|
-
"clean": "rm -rf node_modules",
|
|
148
|
-
"clean:build": "rm -rf dist",
|
|
149
|
-
"contributors": "(npx git-authors-cli && npx finepack --sort-ignore-object-at ava && git add package.json && git commit -m 'build: contributors' --no-verify) || true",
|
|
150
|
-
"dev": "npm run build -- -w",
|
|
151
|
-
"lint": "standard && tsd",
|
|
152
|
-
"postrelease": "npm run release:tags && npm run release:github && (ci-publish || npm publish --access=public)",
|
|
153
|
-
"prebuild": "npm run clean:build && npm run build:kys",
|
|
154
|
-
"prerelease": "npm run update:check",
|
|
155
|
-
"pretest": "npm run lint && npm run build",
|
|
156
|
-
"release": "standard-version -a",
|
|
157
|
-
"release:github": "conventional-github-releaser -p angular",
|
|
158
|
-
"release:tags": "git push --follow-tags origin HEAD:master",
|
|
159
|
-
"test": "c8 ava --verbose",
|
|
160
|
-
"update": "ncu -u",
|
|
161
|
-
"update:check": "ncu -- --error-level 2"
|
|
162
163
|
}
|
|
163
|
-
}
|
|
164
|
+
}
|
package/src/index.d.ts
DELETED
|
@@ -1,29 +0,0 @@
|
|
|
1
|
-
import { MqlPayload, MqlOptions, MicrolinkApiOptions } from '../lightweight'
|
|
2
|
-
|
|
3
|
-
export { MqlPayload } from '../lightweight'
|
|
4
|
-
|
|
5
|
-
export type MqlResponse = MqlPayload & {
|
|
6
|
-
response: {
|
|
7
|
-
url: string;
|
|
8
|
-
isFromCache?: boolean;
|
|
9
|
-
statusCode: number;
|
|
10
|
-
headers: { [key: string]: string };
|
|
11
|
-
body: MqlPayload
|
|
12
|
-
};
|
|
13
|
-
}
|
|
14
|
-
|
|
15
|
-
declare function mql(
|
|
16
|
-
url: string,
|
|
17
|
-
opts?: MqlOptions & MicrolinkApiOptions,
|
|
18
|
-
gotOpts?: object
|
|
19
|
-
): Promise<MqlResponse>;
|
|
20
|
-
|
|
21
|
-
declare namespace mql {
|
|
22
|
-
function stream(
|
|
23
|
-
url: string,
|
|
24
|
-
opts?: MqlOptions & MicrolinkApiOptions,
|
|
25
|
-
gotOpts?: object
|
|
26
|
-
): NodeJS.ReadableStream;
|
|
27
|
-
}
|
|
28
|
-
|
|
29
|
-
export default mql;
|