@microlink/mql 0.10.1 → 0.10.5
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/mql.js +1 -1
- package/dist/mql.min.js +1 -1
- package/index.d.ts +91 -23
- package/package.json +5 -1
package/dist/mql.js
CHANGED
package/dist/mql.min.js
CHANGED
|
@@ -1,4 +1,4 @@
|
|
|
1
1
|
!function(t,e){"object"==typeof exports&&"undefined"!=typeof module?module.exports=e(require("url")):"function"==typeof define&&define.amd?define(["url"],e):(t="undefined"!=typeof globalThis?globalThis:t||self).mql=e(t.require$$0$1)}(this,(function(t){"use strict";function e(t){return t&&"object"==typeof t&&"default"in t?t:{default:t}}var r=e(t),o="undefined"!=typeof globalThis?globalThis:"undefined"!=typeof window?window:"undefined"!=typeof global?global:"undefined"!=typeof self?self:{};function s(t){if(t.__esModule)return t;var e=Object.defineProperty({},"__esModule",{value:!0});return Object.keys(t).forEach((function(r){var o=Object.getOwnPropertyDescriptor(t,r);Object.defineProperty(e,r,o.get?o:{enumerable:!0,get:function(){return t[r]}})})),e}const n=o.window?window.URL:r.default.URL,i=/^https?:\/\//i;var a={};function u(t,e,r,o,s){var n,i=s?s+r:s;if(null==o)e&&(t[s]=o);else if("object"!=typeof o)t[s]=o;else if(Array.isArray(o))for(n=0;n<o.length;n++)u(t,e,r,o[n],i+n);else for(n in o)u(t,e,r,o[n],i+n)}function c(t){if(!t)return"";var e=decodeURIComponent(t);return"false"!==e&&("true"===e||(0*+e==0?+e:e))}a.flattie=function(t,e,r){var o={};return"object"==typeof t&&u(o,!!r,e||".",t,""),o};var p=s(Object.freeze({__proto__:null,encode:function(t,e){var r,o,s,n="";for(r in t)if(void 0!==(s=t[r]))if(Array.isArray(s))for(o=0;o<s.length;o++)n&&(n+="&"),n+=encodeURIComponent(r)+"="+encodeURIComponent(s[o]);else n&&(n+="&"),n+=encodeURIComponent(r)+"="+encodeURIComponent(s);return(e||"")+n},decode:function(t){for(var e,r,o={},s=t.split("&");e=s.shift();)void 0!==o[r=(e=e.split("=")).shift()]?o[r]=[].concat(o[r],c(e.shift())):o[r]=c(e.shift());return o}})),h={exports:{}},f=s(Object.freeze({__proto__:null,default:t=>t}));const l=(t,e,r,o)=>{if("length"===r||"prototype"===r)return;const s=Object.getOwnPropertyDescriptor(t,r),n=Object.getOwnPropertyDescriptor(e,r);!d(s,n)&&o||Object.defineProperty(t,r,n)},d=function(t,e){return void 0===t||t.configurable||t.writable===e.writable&&t.enumerable===e.enumerable&&t.configurable===e.configurable&&(t.writable||t.value===e.value)},y=(t,e)=>`/* Wrapped ${t}*/\n${e}`,b=Object.getOwnPropertyDescriptor(Function.prototype,"toString"),m=Object.getOwnPropertyDescriptor(Function.prototype.toString,"name");var g=(t,e,{ignoreNonConfigurable:r=!1}={})=>{const{name:o}=t;for(const o of Reflect.ownKeys(e))l(t,e,o,r);return((t,e)=>{const r=Object.getPrototypeOf(e);r!==Object.getPrototypeOf(t)&&Object.setPrototypeOf(t,r)})(t,e),((t,e,r)=>{const o=""===r?"":`with ${r.trim()}() `,s=y.bind(null,o,e.toString());Object.defineProperty(s,"name",m),Object.defineProperty(t,"toString",{...b,value:s})})(t,e,o),t},w={isFunction:t=>"function"==typeof t,isString:t=>"string"==typeof t,composeErrorMessage:(t,e)=>`${t}, ${e}`,inherits:(t,e)=>{t.super_=e,t.prototype=Object.create(e.prototype,{constructor:{value:t,enumerable:!1,writable:!0,configurable:!0}})}};const{isFunction:_,composeErrorMessage:E}=w;const R=f,T=g,j=function(t,...e){Object.assign(t,...e),t.description=_(t.message)?t.message(t):t.message,t.message=t.code?E(t.code,t.description):t.description},{isString:x}=w;var v=function(t,e){function r(r){const o=new t,s=x(r)?{message:r}:r;return j(o,e,s),o.stack=R(o.stack),o}return r.prototype=t.prototype,T(r,t),r};const{inherits:C}=w,O=g,q=/[^0-9a-zA-Z_$]/;const P=v,A=function(t){if("string"!=typeof t)throw new TypeError("Expected className to be a string");if(q.test(t))throw new Error("className contains invalid characters");function e(){Object.defineProperty(this,"name",{configurable:!0,value:t,writable:!0}),Error.captureStackTrace(this,this.constructor)}return C(e,Error),O(e,Error),e},S=t=>(e,r)=>{const o=A(e||t.name);return P(o,r)};h.exports=S(Error),h.exports.type=S(TypeError),h.exports.range=S(RangeError),h.exports.eval=S(EvalError),h.exports.syntax=S(SyntaxError),h.exports.reference=S(ReferenceError),h.exports.uri=S(URIError);const U={FREE:"https://api.microlink.io",PRO:"https://pro.microlink.io"},k=t=>null!==t&&"object"==typeof t;var D=({VERSION:t,MicrolinkError:e,isUrlHttp:r,stringify:o,got:s,flatten:n})=>{const i=t=>{if(!k(t))return;const e=n(t);return Object.keys(e).reduce(((t,r)=>({...t,[`data.${r}`]:e[r].toString()})),{})},a=async(t,r={},o=0)=>{try{const e=await s(t,r);return"buffer"===r.responseType?{body:e.body,response:e}:{...e.body,response:e}}catch(s){const{response:n={}}=s,{statusCode:i,body:u,headers:c,url:p=t}=n,h=k(u)&&!Buffer.isBuffer(u)?u:((t,e,r)=>{try{return JSON.parse(t)}catch(o){const s=t||e.message;return{status:"error",data:{url:s},more:"https://microlink.io/efatalclient",code:"EFATALCLIENT",message:s,url:r}}})(u,s,p);if("EFATALCLIENT"===h.code&&o++<2)return a(t,r,o);throw e({...h,message:h.message,url:p,statusCode:i,headers:c})}},u=(t,{data:e,apiKey:r,endpoint:s,retry:a,cache:u,...c}={},{responseType:p="json",headers:h,...f}={})=>{const l=!!r;return[`${s||U[l?"PRO":"FREE"]}?${o({url:t,...i(e),...n(c)})}`,{...f,responseType:p,cache:u,retry:a,headers:l?{...h,"x-api-key":r}:{...h}}]},c=t=>async(o,s,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})}})(o);const[i,c]=u(o,s,{...t,...n});return a(i,c)},p=c();return p.MicrolinkError=e,p.getApiUrl=u,p.fetchFromApi=a,p.mapRules=i,p.version=t,p.stream=s.stream,p.buffer=c({responseType:"buffer"}),p},L={exports:{}};!function(t,e){t.exports=function(){
|
|
2
2
|
/*! MIT License © Sindre Sorhus */
|
|
3
|
-
const t=t=>null!==t&&"object"==typeof t,e="function"==typeof globalThis.AbortController,r="function"==typeof globalThis.ReadableStream,o="function"==typeof globalThis.FormData,s=(t,e)=>{const r=new globalThis.Headers(t||{}),o=e instanceof globalThis.Headers,s=new globalThis.Headers(e||{});for(const[t,e]of s)o&&"undefined"===e||void 0===e?r.delete(t):r.set(t,e);return r},n=(...e)=>{let r={},o={};for(const i of e){if(Array.isArray(i))Array.isArray(r)||(r=[]),r=[...r,...i];else if(t(i)){for(let[e,o]of Object.entries(i))t(o)&&e in r&&(o=n(r[e],o)),r={...r,[e]:o};t(i.headers)&&(o=s(o,i.headers))}r.headers=o}return r},i=["get","post","put","patch","head","delete"],a={json:"application/json",text:"text/*",formData:"multipart/form-data",arrayBuffer:"*/*",blob:"*/*"},u=["get","put","head","delete","options","trace"],c=[408,413,429,500,502,503,504],p=[413,429,503],h=Symbol("stop");class f extends Error{constructor(t,e,r){super(t.statusText||String(0===t.status||t.status?t.status:"Unknown response error")),this.name="HTTPError",this.response=t,this.request=e,this.options=r}}class l extends Error{constructor(t){super("Request timed out"),this.name="TimeoutError",this.request=t}}const d=t=>new Promise((e=>setTimeout(e,t))),y=(t,e,r)=>new Promise(((o,s)=>{const n=setTimeout((()=>{e&&e.abort(),s(new l(t))}),r.timeout);r.fetch(t).then(o).catch(s).then((()=>{clearTimeout(n)}))})),b=t=>i.includes(t)?t.toUpperCase():t,m={limit:2,methods:u,statusCodes:c,afterStatusCodes:p},g=(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:p}},w=2147483647;class _{constructor(t,i={}){if(this._retryCount=0,this._input=t,this._options={credentials:this._input.credentials||"same-origin",...i,headers:s(this._input.headers,i.headers),hooks:n({beforeRequest:[],beforeRetry:[],afterResponse:[]},i.hooks),method:b(i.method||this._input.method),prefixUrl:String(i.prefixUrl||""),retry:g(i.retry),throwHttpErrors:!1!==i.throwHttpErrors,timeout:void 0===i.timeout?1e4:i.timeout,fetch:i.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(e&&(this.abortController=new globalThis.AbortController,this._options.signal&&this._options.signal.addEventListener("abort",(()=>{this.abortController.abort()})),this._options.signal=this.abortController.signal),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);!(o&&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","application/json"),this.request=new globalThis.Request(this.request,{body:this._options.body}));const u=async()=>{if(this._options.timeout>w)throw new RangeError(`The \`timeout\` option cannot be greater than ${w}`);await d(1);let t=await this._fetch();for(const e of this._options.hooks.afterResponse){const r=await e(this.request,this._options,this._decorateResponse(t.clone()));r instanceof globalThis.Response&&(t=r)}if(this._decorateResponse(t),!t.ok&&this._options.throwHttpErrors)throw new f(t,this.request,this._options);if(this._options.onDownloadProgress){if("function"!=typeof this._options.onDownloadProgress)throw new TypeError("The `onDownloadProgress` option must be a function");if(!r)throw new Error("Streams are not supported in your environment. `ReadableStream` is missing.");return this._stream(t.clone(),this._options.onDownloadProgress)}return t},c=this._options.retry.methods.includes(this.request.method.toLowerCase())?this._retry(u):u();for(const[t,e]of Object.entries(a))c[t]=async()=>{this.request.headers.set("accept",this.request.headers.get("accept")||e);const r=(await c).clone();if("json"===t){if(204===r.status)return"";if(i.parseJson)return i.parseJson(await r.text())}return r[t]()};return c}_calculateRetryDelay(t){if(this._retryCount++,this._retryCount<this._options.retry.limit&&!(t instanceof l)){if(t instanceof f){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}return.3*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),w);if(0!==r&&this._retryCount>0){await d(r);for(const t of this._options.hooks.beforeRetry)if(await t({request:this.request,options:this._options,error:e,retryCount:this._retryCount})===h)return;return this._retry(t)}if(this._options.throwHttpErrors)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()):y(this.request.clone(),this.abortController,this._options)}_stream(t,e){const r=Number(t.headers.get("content-length"))||0;let o=0;return new globalThis.Response(new globalThis.ReadableStream({async start(s){const n=t.body.getReader();async function i(){const{done:t,value:a}=await n.read();t?s.close():(e&&(o+=a.byteLength,e({percent:0===r?0:o/r,transferredBytes:o,totalBytes:r},a)),s.enqueue(a),await i())}e&&e({percent:0,transferredBytes:0,totalBytes:r},new Uint8Array),await i()}}))}}const E=(...e)=>{for(const r of e)if((!t(r)||Array.isArray(r))&&void 0!==r)throw new TypeError("The `options` argument must be an object");return n({},...e)},R=t=>{const e=(e,r)=>new _(e,E(t,r));for(const r of i)e[r]=(e,o)=>new _(e,E(t,o,{method:r}));return e.HTTPError=f,e.TimeoutError=l,e.create=t=>R(E(t)),e.extend=e=>R(E(t,e)),e.stop=h,e};return R()}()}(L);const N=t=>{try{return i.test(new n(t).href)}catch(t){return!1}},{flattie:$}=a,{encode:I}=p,F=h.exports,H=L.exports;return D({MicrolinkError:F("MicrolinkError"),isUrlHttp:N,stringify:I,got:async(t,e)=>{try{void 0===e.timeout&&(e.timeout=!1);const r=await H(t,e),o=await r.json(),{headers:s,status:n,statusText:i}=r;return{url:r.url,body:o,headers:s,statusCode:n,statusMessage:i}}catch(t){if(t.response){const{response:e}=t;t.response={...e,headers:[...e.headers.entries()].reduce(((t,[e,r])=>({...t,[e]:r})),{}),statusCode:e.status,body:await e.text()}}throw t}},flatten:$,VERSION:"0.10.
|
|
3
|
+
const t=t=>null!==t&&"object"==typeof t,e="function"==typeof globalThis.AbortController,r="function"==typeof globalThis.ReadableStream,o="function"==typeof globalThis.FormData,s=(t,e)=>{const r=new globalThis.Headers(t||{}),o=e instanceof globalThis.Headers,s=new globalThis.Headers(e||{});for(const[t,e]of s)o&&"undefined"===e||void 0===e?r.delete(t):r.set(t,e);return r},n=(...e)=>{let r={},o={};for(const i of e){if(Array.isArray(i))Array.isArray(r)||(r=[]),r=[...r,...i];else if(t(i)){for(let[e,o]of Object.entries(i))t(o)&&e in r&&(o=n(r[e],o)),r={...r,[e]:o};t(i.headers)&&(o=s(o,i.headers))}r.headers=o}return r},i=["get","post","put","patch","head","delete"],a={json:"application/json",text:"text/*",formData:"multipart/form-data",arrayBuffer:"*/*",blob:"*/*"},u=["get","put","head","delete","options","trace"],c=[408,413,429,500,502,503,504],p=[413,429,503],h=Symbol("stop");class f extends Error{constructor(t,e,r){super(t.statusText||String(0===t.status||t.status?t.status:"Unknown response error")),this.name="HTTPError",this.response=t,this.request=e,this.options=r}}class l extends Error{constructor(t){super("Request timed out"),this.name="TimeoutError",this.request=t}}const d=t=>new Promise((e=>setTimeout(e,t))),y=(t,e,r)=>new Promise(((o,s)=>{const n=setTimeout((()=>{e&&e.abort(),s(new l(t))}),r.timeout);r.fetch(t).then(o).catch(s).then((()=>{clearTimeout(n)}))})),b=t=>i.includes(t)?t.toUpperCase():t,m={limit:2,methods:u,statusCodes:c,afterStatusCodes:p},g=(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:p}},w=2147483647;class _{constructor(t,i={}){if(this._retryCount=0,this._input=t,this._options={credentials:this._input.credentials||"same-origin",...i,headers:s(this._input.headers,i.headers),hooks:n({beforeRequest:[],beforeRetry:[],afterResponse:[]},i.hooks),method:b(i.method||this._input.method),prefixUrl:String(i.prefixUrl||""),retry:g(i.retry),throwHttpErrors:!1!==i.throwHttpErrors,timeout:void 0===i.timeout?1e4:i.timeout,fetch:i.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(e&&(this.abortController=new globalThis.AbortController,this._options.signal&&this._options.signal.addEventListener("abort",(()=>{this.abortController.abort()})),this._options.signal=this.abortController.signal),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);!(o&&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","application/json"),this.request=new globalThis.Request(this.request,{body:this._options.body}));const u=async()=>{if(this._options.timeout>w)throw new RangeError(`The \`timeout\` option cannot be greater than ${w}`);await d(1);let t=await this._fetch();for(const e of this._options.hooks.afterResponse){const r=await e(this.request,this._options,this._decorateResponse(t.clone()));r instanceof globalThis.Response&&(t=r)}if(this._decorateResponse(t),!t.ok&&this._options.throwHttpErrors)throw new f(t,this.request,this._options);if(this._options.onDownloadProgress){if("function"!=typeof this._options.onDownloadProgress)throw new TypeError("The `onDownloadProgress` option must be a function");if(!r)throw new Error("Streams are not supported in your environment. `ReadableStream` is missing.");return this._stream(t.clone(),this._options.onDownloadProgress)}return t},c=this._options.retry.methods.includes(this.request.method.toLowerCase())?this._retry(u):u();for(const[t,e]of Object.entries(a))c[t]=async()=>{this.request.headers.set("accept",this.request.headers.get("accept")||e);const r=(await c).clone();if("json"===t){if(204===r.status)return"";if(i.parseJson)return i.parseJson(await r.text())}return r[t]()};return c}_calculateRetryDelay(t){if(this._retryCount++,this._retryCount<this._options.retry.limit&&!(t instanceof l)){if(t instanceof f){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}return.3*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),w);if(0!==r&&this._retryCount>0){await d(r);for(const t of this._options.hooks.beforeRetry)if(await t({request:this.request,options:this._options,error:e,retryCount:this._retryCount})===h)return;return this._retry(t)}if(this._options.throwHttpErrors)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()):y(this.request.clone(),this.abortController,this._options)}_stream(t,e){const r=Number(t.headers.get("content-length"))||0;let o=0;return new globalThis.Response(new globalThis.ReadableStream({async start(s){const n=t.body.getReader();async function i(){const{done:t,value:a}=await n.read();t?s.close():(e&&(o+=a.byteLength,e({percent:0===r?0:o/r,transferredBytes:o,totalBytes:r},a)),s.enqueue(a),await i())}e&&e({percent:0,transferredBytes:0,totalBytes:r},new Uint8Array),await i()}}))}}const E=(...e)=>{for(const r of e)if((!t(r)||Array.isArray(r))&&void 0!==r)throw new TypeError("The `options` argument must be an object");return n({},...e)},R=t=>{const e=(e,r)=>new _(e,E(t,r));for(const r of i)e[r]=(e,o)=>new _(e,E(t,o,{method:r}));return e.HTTPError=f,e.TimeoutError=l,e.create=t=>R(E(t)),e.extend=e=>R(E(t,e)),e.stop=h,e};return R()}()}(L);const N=t=>{try{return i.test(new n(t).href)}catch(t){return!1}},{flattie:$}=a,{encode:I}=p,F=h.exports,H=L.exports;return D({MicrolinkError:F("MicrolinkError"),isUrlHttp:N,stringify:I,got:async(t,e)=>{try{void 0===e.timeout&&(e.timeout=!1);const r=await H(t,e),o=await r.json(),{headers:s,status:n,statusText:i}=r;return{url:r.url,body:o,headers:s,statusCode:n,statusMessage:i}}catch(t){if(t.response){const{response:e}=t;t.response={...e,headers:[...e.headers.entries()].reduce(((t,[e,r])=>({...t,[e]:r})),{}),statusCode:e.status,body:await e.text()}}throw t}},flatten:$,VERSION:"0.10.5"})}));
|
|
4
4
|
//# sourceMappingURL=mql.min.js.map
|
package/index.d.ts
CHANGED
|
@@ -1,11 +1,7 @@
|
|
|
1
1
|
/// <reference types="node" />
|
|
2
2
|
|
|
3
3
|
declare module "@microlink/mql" {
|
|
4
|
-
export type WaitUntilEvent =
|
|
5
|
-
| "load"
|
|
6
|
-
| "domcontentloaded"
|
|
7
|
-
| "networkidle0"
|
|
8
|
-
| "networkidle2";
|
|
4
|
+
export type WaitUntilEvent = "load" | "domcontentloaded" | "networkidle0" | "networkidle2";
|
|
9
5
|
|
|
10
6
|
export type ScreenshotOptions = Partial<{
|
|
11
7
|
background: string;
|
|
@@ -38,10 +34,12 @@ declare module "@microlink/mql" {
|
|
|
38
34
|
| "image"
|
|
39
35
|
| "ip"
|
|
40
36
|
| "lang"
|
|
37
|
+
| "lang"
|
|
41
38
|
| "logo"
|
|
42
39
|
| "number"
|
|
43
40
|
| "object"
|
|
44
41
|
| "publisher"
|
|
42
|
+
| "publisher"
|
|
45
43
|
| "regexp"
|
|
46
44
|
| "string"
|
|
47
45
|
| "title"
|
|
@@ -51,35 +49,36 @@ declare module "@microlink/mql" {
|
|
|
51
49
|
export type MqlQueryOptions = Partial<{
|
|
52
50
|
attr: string | string[];
|
|
53
51
|
selector: string | string[];
|
|
52
|
+
evaluate: string | function;
|
|
54
53
|
selectorAll: string | string[];
|
|
55
54
|
type: MqlQueryResponseType;
|
|
56
55
|
}>;
|
|
57
56
|
|
|
58
57
|
export interface MqlQuery {
|
|
59
|
-
[field: string]: MqlQueryOptions
|
|
58
|
+
[field: string]: MqlQueryOptions;
|
|
60
59
|
}
|
|
61
60
|
|
|
62
61
|
export type MicrolinkApiOptions = Partial<{
|
|
63
62
|
animations: boolean;
|
|
64
63
|
audio: boolean;
|
|
65
64
|
click: string | string[];
|
|
66
|
-
colorScheme: "dark" | "light";
|
|
67
65
|
codeScheme: string;
|
|
66
|
+
colorScheme: "dark" | "light";
|
|
68
67
|
data: MqlQuery;
|
|
69
68
|
device: string;
|
|
70
69
|
embed: string;
|
|
71
70
|
filter: string;
|
|
72
71
|
force: boolean;
|
|
73
|
-
|
|
74
|
-
|
|
75
|
-
iframe: boolean |
|
|
72
|
+
function: string;
|
|
73
|
+
headers: Record<string, unknown>;
|
|
74
|
+
iframe: boolean | Record<"maxwidth" | "maxheight", number>;
|
|
76
75
|
insights: boolean | object;
|
|
77
76
|
javascript: boolean;
|
|
78
77
|
mediatype: string;
|
|
79
78
|
meta: boolean;
|
|
80
79
|
modules: string | string[];
|
|
81
80
|
palette: boolean;
|
|
82
|
-
ping: boolean |
|
|
81
|
+
ping: boolean | Partial<{ audio: boolean }>;
|
|
83
82
|
prerender: boolean | "auto";
|
|
84
83
|
proxy: string;
|
|
85
84
|
remove: string | string[];
|
|
@@ -99,39 +98,90 @@ declare module "@microlink/mql" {
|
|
|
99
98
|
}>;
|
|
100
99
|
|
|
101
100
|
export type MqlOptions = Partial<{
|
|
101
|
+
endpoint: string;
|
|
102
102
|
apiKey: string;
|
|
103
103
|
retry: number;
|
|
104
104
|
cache: Map<string, any>;
|
|
105
105
|
timeout: number;
|
|
106
106
|
}>;
|
|
107
107
|
|
|
108
|
-
export interface
|
|
109
|
-
width: number;
|
|
110
|
-
height: number;
|
|
111
|
-
type: string;
|
|
108
|
+
export interface BaseMediaInfo {
|
|
112
109
|
url: string;
|
|
110
|
+
// file type extension.
|
|
111
|
+
type: string;
|
|
112
|
+
// file size in bytes.
|
|
113
113
|
size: number;
|
|
114
|
+
// file size in a human readable format.
|
|
114
115
|
size_pretty: string;
|
|
115
116
|
}
|
|
116
117
|
|
|
117
|
-
export interface PlayableMediaInfo
|
|
118
|
+
export interface PlayableMediaInfo {
|
|
119
|
+
// source duration in seconds.
|
|
118
120
|
duration: number;
|
|
121
|
+
// source duration in a human readable format.
|
|
119
122
|
duration_pretty: string;
|
|
120
123
|
}
|
|
121
124
|
|
|
125
|
+
export interface VisualMediaInfo {
|
|
126
|
+
// file width in pixels.
|
|
127
|
+
width: number;
|
|
128
|
+
// file height in pixels.
|
|
129
|
+
height: number;
|
|
130
|
+
}
|
|
131
|
+
|
|
132
|
+
export interface AudioInfo extends BaseMediaInfo, PlayableMediaInfo {
|
|
133
|
+
// TODO make this a complete type
|
|
134
|
+
type: "mp3" | string;
|
|
135
|
+
}
|
|
136
|
+
|
|
137
|
+
export interface ImageInfo extends BaseMediaInfo, VisualMediaInfo {
|
|
138
|
+
// TODO make this a complete type
|
|
139
|
+
type: "png" | "jpg" | string;
|
|
140
|
+
palette: string[];
|
|
141
|
+
background_color: string;
|
|
142
|
+
color: string;
|
|
143
|
+
alternative_color: string;
|
|
144
|
+
}
|
|
145
|
+
|
|
146
|
+
export interface VideoInfo extends BaseMediaInfo, PlayableMediaInfo, VisualMediaInfo {
|
|
147
|
+
// TODO make this a complete type
|
|
148
|
+
type: "mp4" | string;
|
|
149
|
+
}
|
|
150
|
+
|
|
151
|
+
export interface IframeInfo {
|
|
152
|
+
html: string;
|
|
153
|
+
scripts: Record<string, unknown>;
|
|
154
|
+
}
|
|
155
|
+
|
|
156
|
+
export type MqlFunctionResult = {
|
|
157
|
+
isFulfilled: boolean;
|
|
158
|
+
isRejected: boolean;
|
|
159
|
+
value: any;
|
|
160
|
+
};
|
|
161
|
+
|
|
122
162
|
export type MqlResponseData = Partial<{
|
|
163
|
+
// A human-readable representation of the author's name.
|
|
123
164
|
author: string;
|
|
165
|
+
// An ISO 8601 representation of the date the article was published.
|
|
124
166
|
date: string;
|
|
167
|
+
// The publisher's chosen description of the article.
|
|
125
168
|
description: string;
|
|
169
|
+
// An ISO 639-1 representation of the url content language.
|
|
126
170
|
lang: string;
|
|
171
|
+
// An image URL that best represents the publisher brand.
|
|
172
|
+
logo: ImageInfo;
|
|
173
|
+
// A human-readable representation of the publisher's name.
|
|
127
174
|
publisher: string;
|
|
175
|
+
// The publisher's chosen title of the article.
|
|
128
176
|
title: string;
|
|
177
|
+
// The URL of the article.
|
|
178
|
+
|
|
129
179
|
url: string;
|
|
130
|
-
image: ImageInfo;
|
|
131
|
-
|
|
132
|
-
|
|
133
|
-
|
|
134
|
-
|
|
180
|
+
image: ImageInfo | null;
|
|
181
|
+
video: VideoInfo | null;
|
|
182
|
+
audio: AudioInfo | null;
|
|
183
|
+
iframe: IframeInfo | null;
|
|
184
|
+
function: MqlFunctionResult;
|
|
135
185
|
}>;
|
|
136
186
|
|
|
137
187
|
export type MqlStatus = "success" | "fail";
|
|
@@ -139,12 +189,30 @@ declare module "@microlink/mql" {
|
|
|
139
189
|
export interface MqlResponse {
|
|
140
190
|
status: MqlStatus;
|
|
141
191
|
data: MqlResponseData;
|
|
142
|
-
|
|
192
|
+
// TODO: The response object depends on the context
|
|
193
|
+
// - Under Node.js context
|
|
194
|
+
// import { ServerResponse} from 'http';
|
|
195
|
+
// - Under browser, It will be global `Response`
|
|
196
|
+
response: {
|
|
197
|
+
headers: { [key: string]: string };
|
|
198
|
+
body?: {
|
|
199
|
+
statusCode?: number;
|
|
200
|
+
};
|
|
201
|
+
};
|
|
143
202
|
}
|
|
144
203
|
|
|
145
204
|
declare function mql(
|
|
146
205
|
url: string,
|
|
147
|
-
opts?: MqlOptions & MicrolinkApiOptions
|
|
206
|
+
opts?: MqlOptions & MicrolinkApiOptions,
|
|
207
|
+
// TODO: gotOpts could be different depends the environment where the library is being used
|
|
208
|
+
// - Under Node.js context, types are from `got`
|
|
209
|
+
// https://github.com/microlinkhq/mql/blob/fbb55f4758495fa42d35822867763f95ac5ae960/src/node.js#L5
|
|
210
|
+
// https://github.com/DefinitelyTyped/DefinitelyTyped/blob/90a4ec8f0a9c76f33fdeeef0118f26c5d3df5cfa/types/got/index.d.ts#L212
|
|
211
|
+
//
|
|
212
|
+
// - Under brower context, types are from `ky`
|
|
213
|
+
// https://github.com/microlinkhq/mql/blob/fbb55f4758495fa42d35822867763f95ac5ae960/src/browser.js#L9
|
|
214
|
+
// https://github.com/sindresorhus/ky/blob/main/source/types/options.ts#L30
|
|
215
|
+
gotOpts?: object
|
|
148
216
|
): Promise<MqlResponse>;
|
|
149
217
|
|
|
150
218
|
declare namespace mql {
|
package/package.json
CHANGED
|
@@ -2,7 +2,7 @@
|
|
|
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://nicedoc.io/microlinkhq/mql",
|
|
5
|
-
"version": "0.10.
|
|
5
|
+
"version": "0.10.5",
|
|
6
6
|
"browser": "src/browser.js",
|
|
7
7
|
"main": "src/node.js",
|
|
8
8
|
"author": {
|
|
@@ -18,6 +18,10 @@
|
|
|
18
18
|
{
|
|
19
19
|
"name": "ndom91",
|
|
20
20
|
"email": "yo@ndo.dev"
|
|
21
|
+
},
|
|
22
|
+
{
|
|
23
|
+
"name": "Gabe O'Leary",
|
|
24
|
+
"email": "oleary.gabe@gmail.com"
|
|
21
25
|
}
|
|
22
26
|
],
|
|
23
27
|
"repository": {
|