Skip to content

Commit

Permalink
fix(types): expose some methods
Browse files Browse the repository at this point in the history
  • Loading branch information
Kikobeats committed Mar 17, 2024
1 parent 2100c49 commit ed52262
Show file tree
Hide file tree
Showing 4 changed files with 35 additions and 5 deletions.
1 change: 1 addition & 0 deletions .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -38,3 +38,4 @@ stats.html
examples
src/node.mjs
lightweight/index.js
lightweight/index.umd.js
6 changes: 6 additions & 0 deletions lightweight/index.d.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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<Response>;
(url: string, opts?: MqlOptions, gotOpts?: object): Promise<MqlResponse>;
arrayBuffer: (url: string, opts?: MqlOptions, gotOpts?: object) => Promise<HTTPResponseRaw>;
extend: (gotOpts?: object) => mql;
stream: (input: RequestInfo, init?: RequestInit) => ReadableStream;
MicrolinkError,
version
}

declare const mql: mql;
Expand Down
4 changes: 2 additions & 2 deletions rollup.config.js
Original file line number Diff line number Diff line change
Expand Up @@ -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: [
Expand All @@ -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: [
Expand Down
29 changes: 26 additions & 3 deletions test/lightweight.test-d.ts
Original file line number Diff line number Diff line change
@@ -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',
Expand All @@ -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', {
Expand Down Expand Up @@ -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 })
Expand Down

0 comments on commit ed52262

Please sign in to comment.