@octokit/endpoint
Advanced tools
Comparing version 2.1.0 to 3.0.0
module.exports = endpointWithDefaults | ||
const defaultOptions = require('./default-options') | ||
const toRequestOptions = require('./to-request-options') | ||
const merge = require('./merge') | ||
const parse = require('./parse') | ||
function endpointWithDefaults (defaults, route, options) { | ||
const endpointOptions = defaultOptions(defaults, route, options) | ||
return toRequestOptions(endpointOptions) | ||
return parse(merge(defaults, route, options)) | ||
} |
{ | ||
"name": "@octokit/endpoint", | ||
"version": "2.1.0", | ||
"version": "3.0.0", | ||
"publishConfig": { | ||
@@ -5,0 +5,0 @@ "access": "public", |
@@ -261,3 +261,3 @@ # endpoint.js | ||
## endpoint.options() | ||
## endpoint.merge() | ||
@@ -274,6 +274,7 @@ Get the defaulted endpoint options, but without parsing them into request options | ||
}) | ||
myProjectEndpoint.options('GET /orgs/:org/repos', { | ||
myProjectEndpoint.merge('GET /orgs/:org/repos', { | ||
headers: { | ||
authorization: `token 0000000000000000000000000000000000000001` | ||
}, | ||
org: 'my-secret-project', | ||
type: 'private' | ||
@@ -290,3 +291,3 @@ }) | ||
// }, | ||
// org: 'my-project', | ||
// org: 'my-secret-project', | ||
// type: 'private' | ||
@@ -299,3 +300,3 @@ // } | ||
Stateless method to turn endpoint options into request options. Calling | ||
`endpoint(options)` is the same as calling `endpoint.parse(endpoint.options(options))` | ||
`endpoint(options)` is the same as calling `endpoint.parse(endpoint.merge(options))` | ||
@@ -302,0 +303,0 @@ ## Special cases |
@@ -72,2 +72,17 @@ const chai = require('chai') | ||
}) | ||
it('.defaults() merges options but does not yet parse ', () => { | ||
const myEndpoint = endpoint.defaults({ | ||
url: '/orgs/:org', | ||
org: 'test1' | ||
}) | ||
expect(myEndpoint.DEFAULTS.url).to.equal('/orgs/:org') | ||
expect(myEndpoint.DEFAULTS.org).to.equal('test1') | ||
const myEndpoint2 = myEndpoint.defaults({ | ||
url: '/orgs/:org', | ||
org: 'test2' | ||
}) | ||
expect(myEndpoint2.DEFAULTS.url).to.equal('/orgs/:org') | ||
expect(myEndpoint2.DEFAULTS.org).to.equal('test2') | ||
}) | ||
}) |
@@ -21,7 +21,5 @@ const chai = require('chai') | ||
} | ||
const options1 = endpoint(input) | ||
const options2 = endpoint.parse(endpoint.options(input)) | ||
expect(options1).to.deep.equal(options2) | ||
expect(endpoint(input)).to.deep.equal(endpoint.parse(endpoint.merge(input))) | ||
}) | ||
}) |
module.exports = withDefaults | ||
const merge = require('deepmerge') | ||
const isPlainObject = require('is-plain-object') | ||
const endpointWithDefaults = require('./lib/endpoint-with-defaults') | ||
const lowercaseKeys = require('./lib/lowercase-keys') | ||
const optionsWithDefaults = require('./lib/default-options') | ||
const toRequestOptions = require('./lib/to-request-options') | ||
const merge = require('./lib/merge') | ||
const parse = require('./lib/parse') | ||
function withDefaults (oldDefaults, newDefaults) { | ||
newDefaults.headers = lowercaseKeys(newDefaults.headers) | ||
const DEFAULTS = merge.all([oldDefaults, newDefaults].filter(Boolean), { isMergeableObject: isPlainObject }) | ||
const endpoint = endpointWithDefaults.bind(null, DEFAULTS) | ||
endpoint.DEFAULTS = DEFAULTS | ||
endpoint.defaults = withDefaults.bind(null, DEFAULTS) | ||
endpoint.options = optionsWithDefaults.bind(null, DEFAULTS) | ||
endpoint.parse = toRequestOptions | ||
return endpoint | ||
const DEFAULTS = merge(oldDefaults, newDefaults) | ||
return Object.assign(endpointWithDefaults.bind(null, DEFAULTS), { | ||
DEFAULTS, | ||
defaults: withDefaults.bind(null, DEFAULTS), | ||
merge: merge.bind(null, DEFAULTS), | ||
parse | ||
}) | ||
} |
License Policy Violation
LicenseThis package is not allowed per your license policy. Review the package's license to ensure compliance.
Found 1 instance in 1 package
License Policy Violation
LicenseThis package is not allowed per your license policy. Review the package's license to ensure compliance.
Found 1 instance in 1 package
561
350
35962