Update packages, change to node16

This commit is contained in:
Lucas Costi
2022-04-05 10:05:12 +10:00
parent ab59b778e5
commit a8dd2c1169
542 changed files with 66325 additions and 65198 deletions

View File

@ -1,15 +1,17 @@
import { getUserAgent } from "universal-user-agent";
import { VERSION } from "./version";
const userAgent = `octokit-endpoint.js/${VERSION} ${getUserAgent()}`;
// DEFAULTS has all properties set that EndpointOptions has, except url.
// So we use RequestParameters and add method as additional required property.
export const DEFAULTS = {
method: "GET",
baseUrl: "https://api.github.com",
headers: {
accept: "application/vnd.github.v3+json",
"user-agent": userAgent
"user-agent": userAgent,
},
mediaType: {
format: "",
previews: []
}
previews: [],
},
};

View File

@ -1,20 +1,24 @@
import { lowercaseKeys } from "./util/lowercase-keys";
import { mergeDeep } from "./util/merge-deep";
import { removeUndefinedProperties } from "./util/remove-undefined-properties";
export function merge(defaults, route, options) {
if (typeof route === "string") {
let [method, url] = route.split(" ");
options = Object.assign(url ? { method, url } : { url: method }, options);
}
else {
options = route || {};
options = Object.assign({}, route);
}
// lowercase header names before merging with defaults to avoid duplicates
options.headers = lowercaseKeys(options.headers);
// remove properties with undefined values before merging
removeUndefinedProperties(options);
removeUndefinedProperties(options.headers);
const mergedOptions = mergeDeep(defaults || {}, options);
// mediaType.previews arrays are merged, instead of overwritten
if (defaults && defaults.mediaType.previews.length) {
mergedOptions.mediaType.previews = defaults.mediaType.previews
.filter(preview => !mergedOptions.mediaType.previews.includes(preview))
.filter((preview) => !mergedOptions.mediaType.previews.includes(preview))
.concat(mergedOptions.mediaType.previews);
}
mergedOptions.mediaType.previews = mergedOptions.mediaType.previews.map((preview) => preview.replace(/-preview/, ""));

View File

@ -6,7 +6,7 @@ export function parse(options) {
// https://fetch.spec.whatwg.org/#methods
let method = options.method.toUpperCase();
// replace :varname with {varname} to make it RFC 6570 compatible
let url = options.url.replace(/:([a-z]\w+)/g, "{+$1}");
let url = (options.url || "/").replace(/:([a-z]\w+)/g, "{$1}");
let headers = Object.assign({}, options.headers);
let body;
let parameters = omit(options, [
@ -15,7 +15,7 @@ export function parse(options) {
"url",
"headers",
"request",
"mediaType"
"mediaType",
]);
// extract variable names from URL to calculate remaining variables later
const urlVariableNames = extractUrlVariableNames(url);
@ -24,23 +24,23 @@ export function parse(options) {
url = options.baseUrl + url;
}
const omittedParameters = Object.keys(options)
.filter(option => urlVariableNames.includes(option))
.filter((option) => urlVariableNames.includes(option))
.concat("baseUrl");
const remainingParameters = omit(parameters, omittedParameters);
const isBinaryRequset = /application\/octet-stream/i.test(headers.accept);
if (!isBinaryRequset) {
const isBinaryRequest = /application\/octet-stream/i.test(headers.accept);
if (!isBinaryRequest) {
if (options.mediaType.format) {
// e.g. application/vnd.github.v3+json => application/vnd.github.v3.raw
headers.accept = headers.accept
.split(/,/)
.map(preview => preview.replace(/application\/vnd(\.\w+)(\.v3)?(\.\w+)?(\+json)?$/, `application/vnd$1$2.${options.mediaType.format}`))
.map((preview) => preview.replace(/application\/vnd(\.\w+)(\.v3)?(\.\w+)?(\+json)?$/, `application/vnd$1$2.${options.mediaType.format}`))
.join(",");
}
if (options.mediaType.previews.length) {
const previewsFromAcceptHeader = headers.accept.match(/[\w-]+(?=-preview)/g) || [];
headers.accept = previewsFromAcceptHeader
.concat(options.mediaType.previews)
.map(preview => {
.map((preview) => {
const format = options.mediaType.format
? `.${options.mediaType.format}`
: "+json";

View File

View File

@ -7,13 +7,9 @@ export function addQueryParameters(url, parameters) {
return (url +
separator +
names
.map(name => {
.map((name) => {
if (name === "q") {
return ("q=" +
parameters
.q.split("+")
.map(encodeURIComponent)
.join("+"));
return ("q=" + parameters.q.split("+").map(encodeURIComponent).join("+"));
}
return `${name}=${encodeURIComponent(parameters[name])}`;
})

View File

@ -1,7 +1,7 @@
import isPlainObject from "is-plain-object";
import { isPlainObject } from "is-plain-object";
export function mergeDeep(defaults, options) {
const result = Object.assign({}, defaults);
Object.keys(options).forEach(key => {
Object.keys(options).forEach((key) => {
if (isPlainObject(options[key])) {
if (!(key in defaults))
Object.assign(result, { [key]: options[key] });

View File

@ -1,6 +1,6 @@
export function omit(object, keysToOmit) {
return Object.keys(object)
.filter(option => !keysToOmit.includes(option))
.filter((option) => !keysToOmit.includes(option))
.reduce((obj, key) => {
obj[key] = object[key];
return obj;

View File

@ -0,0 +1,8 @@
export function removeUndefinedProperties(obj) {
for (const key in obj) {
if (obj[key] === undefined) {
delete obj[key];
}
}
return obj;
}

View File

@ -29,9 +29,7 @@ function encodeReserved(str) {
.split(/(%[0-9A-Fa-f]{2})/g)
.map(function (part) {
if (!/%[0-9A-Fa-f]/.test(part)) {
part = encodeURI(part)
.replace(/%5B/g, "[")
.replace(/%5D/g, "]");
part = encodeURI(part).replace(/%5B/g, "[").replace(/%5D/g, "]");
}
return part;
})
@ -39,11 +37,7 @@ function encodeReserved(str) {
}
function encodeUnreserved(str) {
return encodeURIComponent(str).replace(/[!'()*]/g, function (c) {
return ("%" +
c
.charCodeAt(0)
.toString(16)
.toUpperCase());
return "%" + c.charCodeAt(0).toString(16).toUpperCase();
});
}
function encodeValue(operator, value, key) {
@ -132,7 +126,7 @@ function getValues(context, operator, key, modifier) {
}
export function parseUrl(template) {
return {
expand: expand.bind(null, template)
expand: expand.bind(null, template),
};
}
function expand(template, context) {

View File

@ -1 +1 @@
export const VERSION = "0.0.0-development";
export const VERSION = "6.0.12";

View File

@ -8,6 +8,6 @@ export function withDefaults(oldDefaults, newDefaults) {
DEFAULTS,
defaults: withDefaults.bind(null, DEFAULTS),
merge: merge.bind(null, DEFAULTS),
parse
parse,
});
}