Browse Source

update index.ts

pull/1/head
ojizero 3 years ago
parent
commit
85ee4bc67b
No known key found for this signature in database
GPG Key ID: FEBB7097845B0C7E
  1. 39
      src/index.ts

39
src/index.ts

@ -3,33 +3,34 @@ import PortalClient, { Client, ClientFn, Config as ClientConfig } from './client @@ -3,33 +3,34 @@ import PortalClient, { Client, ClientFn, Config as ClientConfig } from './client
import methodGenerator, { MethodFactory } from './method'
import resrouceGenerator, { ResourceFactory } from './resource'
let got: ClientFn
// let got: ClientFn
try {
got = require('got')
} catch (_) {}
// try {
// got = require('got')
// } catch (_) {}
import got from 'got'
function forNode (clientType: ClientType | undefined): clientType is NodeClient {
return typeof clientType === 'undefined' || (clientType.type === 'node' || clientType.type === 'got')
}
// function forNode (clientType: ClientType | undefined): clientType is NodeClient {
// return typeof clientType === 'undefined' || (clientType.type === 'node' || clientType.type === 'got')
// }
function getClient (config: PortalConfig): ClientFn {
if (forNode(config.client)) return got
// function getClient (config: PortalConfig): ClientFn {
// if (forNode(config.client)) return got
throw new Error(`Unspported client config ${config.client}`)
}
// throw new Error(`Unspported client config ${config.client}`)
// }
export interface ClientType {
type: 'node' | 'got', // | 'browser' | 'ky' | 'custom',
}
// export interface ClientType {
// type: 'node' | 'got', // | 'browser' | 'ky' | 'custom',
// }
export interface NodeClient extends ClientType {
type: 'node' | 'got',
}
// export interface NodeClient extends ClientType {
// type: 'node' | 'got',
// }
export interface PortalConfig {
client?: NodeClient,
// client?: NodeClient,
}
export type Config = ClientConfig & PortalConfig
@ -43,7 +44,7 @@ export interface Portal { @@ -43,7 +44,7 @@ export interface Portal {
}
export function createPortalClient (config: Config): Portal {
const clientFn = getClient(config)
const clientFn = got // getClient(config)
const client = new PortalClient(clientFn, config)
const portal: Portal = {

Loading…
Cancel
Save