diff --git a/.gitignore b/.gitignore index bdeb873..b743a60 100755 --- a/.gitignore +++ b/.gitignore @@ -38,3 +38,4 @@ stats.html examples src/node.mjs lightweight/index.js +lightweight/index.umd.js diff --git a/lightweight/index.d.ts b/lightweight/index.d.ts index 95eab99..237c3c4 100644 --- a/lightweight/index.d.ts +++ b/lightweight/index.d.ts @@ -173,12 +173,18 @@ export type MqlError = { export type MqlOptions = MqlClientOptions & MicrolinkApiOptions; +export const MicrolinkError: new (props: object) => MqlError; + +export const version: string; + interface mql { (url: string, opts?: MqlOptions & { stream: string }, gotOpts?: object): Promise; (url: string, opts?: MqlOptions, gotOpts?: object): Promise; arrayBuffer: (url: string, opts?: MqlOptions, gotOpts?: object) => Promise; extend: (gotOpts?: object) => mql; stream: (input: RequestInfo, init?: RequestInit) => ReadableStream; + MicrolinkError, + version } declare const mql: mql; diff --git a/rollup.config.js b/rollup.config.js index 45719fc..32adce5 100644 --- a/rollup.config.js +++ b/rollup.config.js @@ -44,7 +44,7 @@ const builds = [ plugins: [commonjs(), rewriteFlattie()] }), build({ - compress: true, + compress: false, input: 'src/lightweight.js', output: { file: 'lightweight/index.js', format: 'es' }, plugins: [ @@ -55,7 +55,7 @@ const builds = [ ] }), build({ - compress: true, + compress: false, input: 'src/lightweight.js', output: { name: 'mql', file: 'lightweight/index.umd.js', format: 'umd' }, plugins: [ diff --git a/test/lightweight.test-d.ts b/test/lightweight.test-d.ts index b23dc29..2fffd7d 100644 --- a/test/lightweight.test-d.ts +++ b/test/lightweight.test-d.ts @@ -1,9 +1,29 @@ -import mql from '../lightweight' +import mql, { MicrolinkError } from '../lightweight' import type { MqlError } from '../lightweight' +/** error */ + +;(async () => { + const error = new MicrolinkError({ + status: 'fail', + data: { url: 'something goes wrong' }, + more: 'https://microlink.io/docs/api/api-parameters/url', + code: 'EINVALURLCLIENT', + message: 'something goes wrong', + url: 'https://example.com' + }) + + console.log(error.status) + console.log(error.data) + console.log(error.more) + console.log(error.code) + console.log(error.url) + console.log(error.description) +})() + /** mql */ -;async () => { +;(async () => { const result = await mql('https://example.com', { endpoint: 'https://pro.microlink.io', apiKey: '123', @@ -16,7 +36,7 @@ import type { MqlError } from '../lightweight' console.log(result.statusCode) console.log(result.headers) console.log(result.response) -} +})() ;(async () => { const response = await mql('https://example.com', { @@ -106,6 +126,9 @@ mql('https://example.com', { video: true }) +console.log(MicrolinkError) +console.log(mql.version) + /** response */ const result = await mql('https://example.com', { meta: true })