mirror of https://github.com/Seich/Beau.git
parent
0b3e16b120
commit
93b8778972
|
|
@ -1555,6 +1555,12 @@
|
|||
"@types/responselike": "*"
|
||||
}
|
||||
},
|
||||
"@types/caseless": {
|
||||
"version": "0.12.2",
|
||||
"resolved": "https://registry.npmjs.org/@types/caseless/-/caseless-0.12.2.tgz",
|
||||
"integrity": "sha512-6ckxMjBBD8URvjB6J3NcnuAn5Pkl7t3TizAg+xdlzzQGSPSmBcXf8KoIH0ua/i+tio+ZRUHEXp0HEmvaR4kt0w==",
|
||||
"dev": true
|
||||
},
|
||||
"@types/deepmerge": {
|
||||
"version": "2.2.0",
|
||||
"resolved": "https://registry.npmjs.org/@types/deepmerge/-/deepmerge-2.2.0.tgz",
|
||||
|
|
@ -1658,6 +1664,40 @@
|
|||
"integrity": "sha512-UEyp8LwZ4Dg30kVU2Q3amHHyTn1jEdhCIE59ANed76GaT1Vp76DD3ZWSAxgCrw6wJ0TqeoBpqmfUHiUDPs//HQ==",
|
||||
"dev": true
|
||||
},
|
||||
"@types/request": {
|
||||
"version": "2.48.5",
|
||||
"resolved": "https://registry.npmjs.org/@types/request/-/request-2.48.5.tgz",
|
||||
"integrity": "sha512-/LO7xRVnL3DxJ1WkPGDQrp4VTV1reX9RkC85mJ+Qzykj2Bdw+mG15aAfDahc76HtknjzE16SX/Yddn6MxVbmGQ==",
|
||||
"dev": true,
|
||||
"requires": {
|
||||
"@types/caseless": "*",
|
||||
"@types/node": "*",
|
||||
"@types/tough-cookie": "*",
|
||||
"form-data": "^2.5.0"
|
||||
},
|
||||
"dependencies": {
|
||||
"form-data": {
|
||||
"version": "2.5.1",
|
||||
"resolved": "https://registry.npmjs.org/form-data/-/form-data-2.5.1.tgz",
|
||||
"integrity": "sha512-m21N3WOmEEURgk6B9GLOE4RuWOFf28Lhh9qGYeNlGq4VDXUlJy2th2slBNU8Gp8EzloYZOibZJ7t5ecIrFSjVA==",
|
||||
"dev": true,
|
||||
"requires": {
|
||||
"asynckit": "^0.4.0",
|
||||
"combined-stream": "^1.0.6",
|
||||
"mime-types": "^2.1.12"
|
||||
}
|
||||
}
|
||||
}
|
||||
},
|
||||
"@types/request-promise-native": {
|
||||
"version": "1.0.17",
|
||||
"resolved": "https://registry.npmjs.org/@types/request-promise-native/-/request-promise-native-1.0.17.tgz",
|
||||
"integrity": "sha512-05/d0WbmuwjtGMYEdHIBZ0tqMJJQ2AD9LG2F6rKNBGX1SSFR27XveajH//2N/XYtual8T9Axwl+4v7oBtPUZqg==",
|
||||
"dev": true,
|
||||
"requires": {
|
||||
"@types/request": "*"
|
||||
}
|
||||
},
|
||||
"@types/responselike": {
|
||||
"version": "1.0.0",
|
||||
"resolved": "https://registry.npmjs.org/@types/responselike/-/responselike-1.0.0.tgz",
|
||||
|
|
@ -1673,6 +1713,12 @@
|
|||
"integrity": "sha512-RJJrrySY7A8havqpGObOB4W92QXKJo63/jFLLgpvOtsGUqbQZ9Sbgl35KMm1DjC6j7AvmmU2bIno+3IyEaemaw==",
|
||||
"dev": true
|
||||
},
|
||||
"@types/tough-cookie": {
|
||||
"version": "4.0.0",
|
||||
"resolved": "https://registry.npmjs.org/@types/tough-cookie/-/tough-cookie-4.0.0.tgz",
|
||||
"integrity": "sha512-I99sngh224D0M7XgW1s120zxCt3VYQ3IQsuw3P3jbq5GG4yc79+ZjyKznyOGIQrflfylLgcfekeZW/vk0yng6A==",
|
||||
"dev": true
|
||||
},
|
||||
"@types/yargs": {
|
||||
"version": "15.0.10",
|
||||
"resolved": "https://registry.npmjs.org/@types/yargs/-/yargs-15.0.10.tgz",
|
||||
|
|
|
|||
|
|
@ -40,6 +40,7 @@
|
|||
"@types/deepmerge": "2.2.0",
|
||||
"@types/jest": "26.0.15",
|
||||
"@types/js-yaml": "3.12.5",
|
||||
"@types/request-promise-native": "1.0.17",
|
||||
"jest": "26.6.3",
|
||||
"jest-watch-typeahead": "0.6.1",
|
||||
"np": "7.0.0",
|
||||
|
|
|
|||
|
|
@ -4,11 +4,11 @@ import RequestCache from '../requestCache'
|
|||
const requireg = require('requireg')
|
||||
|
||||
describe(`Beau's plugin system`, () => {
|
||||
let request
|
||||
let plugins
|
||||
let request: Request
|
||||
let plugins: Plugins
|
||||
|
||||
beforeEach(() => {
|
||||
plugins = new Plugins([{ Modifiers: [Object] }, 'DynamicValues'], [])
|
||||
plugins = new Plugins([{ Modifiers: [{}] }, 'DynamicValues'], [])
|
||||
})
|
||||
|
||||
it('should load all plugins', () => {
|
||||
|
|
|
|||
|
|
@ -1,15 +1,14 @@
|
|||
import { moduleVersion } from './shared'
|
||||
import RequestList from './requestList'
|
||||
import Config, { BeauConfig } from './config'
|
||||
|
||||
const deepmerge = require('deepmerge')
|
||||
import * as deepmerge from 'deepmerge'
|
||||
|
||||
export default class Beau {
|
||||
config: Config
|
||||
requests: RequestList
|
||||
|
||||
constructor(doc: BeauConfig, env = {}) {
|
||||
doc.environment = deepmerge(doc.environment, env)
|
||||
doc.environment = deepmerge(doc.environment ?? {}, env)
|
||||
this.config = new Config(doc)
|
||||
this.requests = new RequestList(this.config)
|
||||
|
||||
|
|
@ -22,4 +21,3 @@ export default class Beau {
|
|||
}
|
||||
}
|
||||
}
|
||||
|
||||
|
|
|
|||
|
|
@ -1,6 +1,6 @@
|
|||
import vm = require('vm')
|
||||
import requireg = require('requireg')
|
||||
import deepmerge = require('deepmerge')
|
||||
import * as requireg from 'requireg'
|
||||
import * as deepmerge from 'deepmerge'
|
||||
import { toKebabCase, dynamicValueRegex, replaceInObject } from './shared'
|
||||
import { isPlainObject } from 'is-plain-object'
|
||||
import { RequestObject, UObjectString } from './config'
|
||||
|
|
@ -19,7 +19,10 @@ export default class Plugins {
|
|||
context: vm.Context
|
||||
autoload: string[] = []
|
||||
|
||||
constructor(plugins: UObjectString[] = [], autoload = ['std']) {
|
||||
constructor(
|
||||
plugins: Array<string | { [key: string]: any }> = [],
|
||||
autoload = ['std']
|
||||
) {
|
||||
this.registry = {
|
||||
preRequestModifiers: [],
|
||||
postRequestModifiers: [],
|
||||
|
|
|
|||
|
|
@ -1,4 +1,4 @@
|
|||
import request = require('request-promise-native')
|
||||
import * as request from 'request-promise-native'
|
||||
import RequestCache from './requestCache'
|
||||
import Plugins from './plugins'
|
||||
|
||||
|
|
|
|||
|
|
@ -8,7 +8,7 @@ export default class RequestCache {
|
|||
return typeof this.$cache[key] !== 'undefined'
|
||||
}
|
||||
|
||||
add(key: string, value: { [key: string]: any }) {
|
||||
add(key: string, value: any) {
|
||||
this.$cache[key] = value
|
||||
}
|
||||
|
||||
|
|
|
|||
|
|
@ -22,8 +22,8 @@ export const isEmptyObject = (obj: object) =>
|
|||
export const removeOptionalKeys = function (
|
||||
obj: object,
|
||||
optionalValues: string[]
|
||||
): typeof obj {
|
||||
let result = {}
|
||||
): Partial<typeof obj> {
|
||||
let result: { [key: string]: any } = {}
|
||||
|
||||
Object.entries(obj).forEach(([key, value]) => {
|
||||
if (optionalValues.includes(key) && isEmptyObject(value)) {
|
||||
|
|
@ -43,10 +43,10 @@ export const toKebabCase = function (str: string) {
|
|||
.toLowerCase()
|
||||
}
|
||||
|
||||
export const replaceInObject = function<T> (
|
||||
obj: T,
|
||||
export const replaceInObject = function (
|
||||
obj: { [key: string]: any },
|
||||
fn: (arg0: string) => string
|
||||
): T | null | {} | string {
|
||||
): typeof obj | null | {} | string {
|
||||
if (obj === null) {
|
||||
return null
|
||||
}
|
||||
|
|
|
|||
Loading…
Reference in New Issue