Skip to content
This repository has been archived by the owner on Nov 23, 2021. It is now read-only.

Commit

Permalink
Merge pull request #48 from bookmoons/update-deps
Browse files Browse the repository at this point in the history
Update dependencies
  • Loading branch information
simskij authored Mar 24, 2020
2 parents 9e3d508 + a99c8a2 commit 84d0d92
Show file tree
Hide file tree
Showing 31 changed files with 261 additions and 247 deletions.
2 changes: 1 addition & 1 deletion bin/postman-to-k6.js
Original file line number Diff line number Diff line change
Expand Up @@ -48,7 +48,7 @@ async function run (...args) {
// Convert
let main, requests
try {
[ main, requests ] = await convertFile(input, translateOptions(options))
[main, requests] = await convertFile(input, translateOptions(options))
} catch (e) {
console.error(e.message)
console.log(e)
Expand Down
4 changes: 2 additions & 2 deletions bin/requests.js
Original file line number Diff line number Diff line change
Expand Up @@ -2,15 +2,15 @@ const fs = require('fs-extra')
const path = require('path')

function outputRequests (dir, requests) {
const address = [ dir, 'requests' ]
const address = [dir, 'requests']
location(requests, address)
}

function location (node, address) {
const target = path.join(...address)
fs.ensureDirSync(target)
for (const name of Object.keys(node)) {
const downstreamAddress = [ ...address ]
const downstreamAddress = [...address]
downstreamAddress.push(name)
entry(node[name], downstreamAddress)
}
Expand Down
4 changes: 3 additions & 1 deletion lib/aid.js
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,7 @@ const auth = require('./auth')
const { VariableType } = require('./enum')

const tabSize = 2
const schemeStart = /^[a-zA-Z][a-zA-Z0-9+.-]*:/
const variable = /{{(.*)}}/
const variableStart = /^{{(.*)}}/
const variables = /{{(.*?)}}/g
Expand Down Expand Up @@ -51,7 +52,7 @@ function makeGroup ({
declares: new Set(),
pre: null,
post: null,
auths: [ ...auths ],
auths: [...auths],
main: []
}
}
Expand Down Expand Up @@ -146,6 +147,7 @@ Object.assign(exports, {
indent,
makeGroup,
makeResult,
schemeStart,
spread,
SuffixGenerator,
validAuth,
Expand Down
13 changes: 7 additions & 6 deletions lib/auth/awsv4.js
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,7 @@ class Aws4Auth {
const lines = []

// Address
lines.push(`const address = new URI(config.address);`)
lines.push('const address = new URI(config.address);')

// Options
const options = []
Expand All @@ -21,6 +21,7 @@ class Aws4Auth {
options.push(`port: address.port()`)
options.push(`path: address.path() + address.search()`)
options.push('body: config.data')

if (params.has('region')) {
const region = aid.evalString(params.get('region'))
options.push(`region: ${region}`)
Expand All @@ -30,7 +31,7 @@ class Aws4Auth {
options.push(`service: ${service}`)
}
lines.push(`const options = {
${aid.indent(options.join(`,\n`))}
${aid.indent(options.join(',\n'))}
};`)

// Credential
Expand All @@ -48,11 +49,11 @@ ${aid.indent(options.join(`,\n`))}
credential.push(`sessionToken: ${sessionToken}`)
}
lines.push(`const credential = {
${aid.indent(credential.join(`,\n`))}
${aid.indent(credential.join(',\n'))}
};`)

// Sign
lines.push(`const signed = aws4.sign(options, credential);`)
lines.push('const signed = aws4.sign(options, credential);')

// Request
lines.push(`const [path, query = ""] = signed.path.split("?");
Expand All @@ -62,8 +63,8 @@ config.address = new URI()
.path(path)
.query(query)
.toString();`)
lines.push(`Object.assign(config.headers, signed.headers);`)
this.logic = lines.join(`\n`)
lines.push('Object.assign(config.headers, signed.headers);')
this.logic = lines.join('\n')
}
}

Expand Down
30 changes: 15 additions & 15 deletions lib/auth/oauth1.js
Original file line number Diff line number Diff line change
Expand Up @@ -36,7 +36,7 @@ class Oauth1Auth {
// Options
const options = []
options.push(`consumer: {
${aid.indent(consumer.join(`,\n`))}
${aid.indent(consumer.join(',\n'))}
}`)
options.push(`signature_method: ${JSON.stringify(signatureMethod)}`)
renderHashFunction(signatureMethod, options)
Expand All @@ -47,13 +47,13 @@ ${aid.indent(consumer.join(`,\n`))}
options.push(`realm: ${realm}`)
}
lines.push(`const options = {
${aid.indent(options.join(`,\n`))}
${aid.indent(options.join(',\n'))}
};`)

// Request Data
const request = []
request.push(`method: config.method`)
request.push(`url: config.address`)
request.push('method: config.method')
request.push('url: config.address')
const data = []
if (timestamp) {
data.push(`oauth_timestamp: ${timestamp}`)
Expand All @@ -63,11 +63,11 @@ ${aid.indent(options.join(`,\n`))}
}
if (data.length) {
request.push(`data: {
${aid.indent(data.join(`,\n`))}
${aid.indent(data.join(',\n'))}
}`)
}
lines.push(`const request = {
${aid.indent(request.join(`,\n`))}
${aid.indent(request.join(',\n'))}
};`)

// Token
Expand All @@ -80,36 +80,36 @@ ${aid.indent(request.join(`,\n`))}
}
if (token.length) {
lines.push(`const token = {
${aid.indent(token.join(`,\n`))}
${aid.indent(token.join(',\n'))}
};`)
}

// Sign
lines.push(`const oauth = OAuth(options);`)
lines.push('const oauth = OAuth(options);')
const args = []
args.push(`request`)
args.push('request')
if (token.length) {
args.push(`token`)
args.push('token')
}
switch (location) {
case Location.Header:
lines.push(
`const auth = oauth.toHeader(oauth.authorize(${args.join(`, `)}));`
`const auth = oauth.toHeader(oauth.authorize(${args.join(', ')}));`
)
break
case Location.Body:
case Location.Address:
lines.push(`const auth = oauth.authorize(${args.join(`, `)});`)
lines.push(`const auth = oauth.authorize(${args.join(', ')});`)
break
}

// Request
switch (location) {
case Location.Header:
lines.push(`Object.assign(config.headers, auth);`)
lines.push('Object.assign(config.headers, auth);')
break
case Location.Body:
lines.push(`Object.assign(config.data, auth);`)
lines.push('Object.assign(config.data, auth);')
break
case Location.Address:
this.imports.set('URI', './libs/urijs.js')
Expand All @@ -120,7 +120,7 @@ for (const key of Object.keys(auth)) {
config.address = address.toString();`)
break
}
this.logic = lines.join(`\n`)
this.logic = lines.join('\n')
}
}

Expand Down
4 changes: 2 additions & 2 deletions lib/common/post.js
Original file line number Diff line number Diff line change
Expand Up @@ -13,14 +13,14 @@ function readPost (node, block, result = block) {
if (exec.disabled) {
continue
}
const logic = exec.join(`\n`).trim()
const logic = exec.join('\n').trim()
if (!logic) {
continue
}
sections.push(logic)
}
if (sections.length) {
block.post = sections.join(`\n\n`)
block.post = sections.join('\n\n')
detectFeature(block.post, result)
}
}
Expand Down
4 changes: 2 additions & 2 deletions lib/common/pre.js
Original file line number Diff line number Diff line change
Expand Up @@ -13,14 +13,14 @@ function readPre (node, block, result = block) {
if (exec.disabled) {
continue
}
const logic = exec.join(`\n`).trim()
const logic = exec.join('\n').trim()
if (!logic) {
continue
}
sections.push(logic)
}
if (sections.length) {
block.pre = sections.join(`\n\n`)
block.pre = sections.join('\n\n')
detectFeature(block.pre, result)
}
}
Expand Down
4 changes: 2 additions & 2 deletions lib/convert/object.js
Original file line number Diff line number Diff line change
Expand Up @@ -24,9 +24,9 @@ async function convertObject (collection, options = {}) {
result.iterations = options.iterations
}
if (options.csv) {
result.data.path = `./data.csv`
result.data.path = './data.csv'
} else if (options.json) {
result.data.path = `./data.json`
result.data.path = './data.json'
}
result.data.type = (options.csv ? 'csv' : options.json ? 'json' : null)
if (result.data.type === 'csv') {
Expand Down
2 changes: 1 addition & 1 deletion lib/generate/Item/inline.js
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,7 @@ function inline (item, result, block) {
for (const declare of spec.declares) {
block.declares.add(declare)
}
const chunk = [ ...spec.main ]
const chunk = [...spec.main]
block.main.push(chunk)
}

Expand Down
2 changes: 1 addition & 1 deletion lib/generate/Item/separate.js
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,7 @@ function separate (item, result, block) {
for (const declare of spec.declares) {
block.declares.add(declare)
}
const chunk = [ ...spec.main ]
const chunk = [...spec.main]
block.main.push(chunk)
}

Expand Down
22 changes: 13 additions & 9 deletions lib/generate/Request/analyze.js
Original file line number Diff line number Diff line change
Expand Up @@ -34,12 +34,16 @@ function analyze (request, result, block) {

function address (address, feature, result) {
const string = address.toString()
feature.address = new URI(string)
if (aid.variableStart.test(string)) {
// Runtime protocol defaulting necessary
// Runtime scheme processing necessary
feature.address = new URI(string)
result.effectImports.add('./libs/shim/urijs.js')
} else if (!feature.address.protocol()) {
feature.address.protocol('http')
} else if (aid.schemeStart.test(string)) {
// Scheme specified
feature.address = new URI(string)
} else {
// Scheme missing
feature.address = new URI(`http://${string}`)
}
}

Expand Down Expand Up @@ -105,7 +109,7 @@ function header (key, value, feature, result) {
}

function authentication (direct, feature, result, block) {
const auths = [ ...block.auths ]
const auths = [...block.auths]
readAuth(direct, auths)
const settings = selectAuth(auths)
if (!settings) {
Expand All @@ -119,7 +123,7 @@ function authentication (direct, feature, result, block) {
applyAuth(auth, feature, result, block)
}
function selectAuth (auths) {
for (const auth of [ ...auths ].reverse()) {
for (const auth of [...auths].reverse()) {
if (auth !== InheritAuth) {
return auth
}
Expand Down Expand Up @@ -164,7 +168,7 @@ function authPolyfills (auth, result) {
}
}
function authImports (auth, result) {
for (const [ name, spec ] of auth.imports) {
for (const [name, spec] of auth.imports) {
result.imports.set(name, spec)
}
}
Expand All @@ -174,7 +178,7 @@ function authDeclares (auth, block) {
}
}
function authHeaders (auth, feature) {
for (const [ name, value ] of auth.headers) {
for (const [name, value] of auth.headers) {
feature.headers.set(name, value)
}
}
Expand All @@ -189,7 +193,7 @@ function authDataSpread (auth, feature) {
}
}
function authOptions (auth, feature) {
for (const [ name, value ] of auth.options) {
for (const [name, value] of auth.options) {
feature.options.set(name, value)
}
}
Expand Down
Loading

0 comments on commit 84d0d92

Please sign in to comment.