change-string-case/node_modules/@octokit/graphql/dist-node/index.js

155 lines
4.6 KiB
JavaScript
Raw Normal View History

2023-10-26 04:27:07 +08:00
"use strict";
var __defProp = Object.defineProperty;
var __getOwnPropDesc = Object.getOwnPropertyDescriptor;
var __getOwnPropNames = Object.getOwnPropertyNames;
var __hasOwnProp = Object.prototype.hasOwnProperty;
var __export = (target, all) => {
for (var name in all)
__defProp(target, name, { get: all[name], enumerable: true });
};
var __copyProps = (to, from, except, desc) => {
if (from && typeof from === "object" || typeof from === "function") {
for (let key of __getOwnPropNames(from))
if (!__hasOwnProp.call(to, key) && key !== except)
__defProp(to, key, { get: () => from[key], enumerable: !(desc = __getOwnPropDesc(from, key)) || desc.enumerable });
}
return to;
};
var __toCommonJS = (mod) => __copyProps(__defProp({}, "__esModule", { value: true }), mod);
// pkg/dist-src/index.js
var dist_src_exports = {};
__export(dist_src_exports, {
GraphqlResponseError: () => GraphqlResponseError,
graphql: () => graphql2,
withCustomRequest: () => withCustomRequest
});
module.exports = __toCommonJS(dist_src_exports);
var import_request3 = require("@octokit/request");
var import_universal_user_agent = require("universal-user-agent");
2022-11-04 00:55:07 +08:00
2023-10-26 04:27:07 +08:00
// pkg/dist-src/version.js
var VERSION = "7.0.2";
2022-11-04 00:55:07 +08:00
2023-10-26 04:27:07 +08:00
// pkg/dist-src/with-defaults.js
var import_request2 = require("@octokit/request");
2022-11-04 00:55:07 +08:00
2023-10-26 04:27:07 +08:00
// pkg/dist-src/graphql.js
var import_request = require("@octokit/request");
2022-11-04 00:55:07 +08:00
2023-10-26 04:27:07 +08:00
// pkg/dist-src/error.js
function _buildMessageForResponseErrors(data) {
return `Request failed due to following response errors:
` + data.errors.map((e) => ` - ${e.message}`).join("\n");
}
var GraphqlResponseError = class extends Error {
constructor(request2, headers, response) {
super(_buildMessageForResponseErrors(response));
this.request = request2;
this.headers = headers;
this.response = response;
this.name = "GraphqlResponseError";
this.errors = response.errors;
this.data = response.data;
2022-11-04 00:55:07 +08:00
if (Error.captureStackTrace) {
Error.captureStackTrace(this, this.constructor);
}
}
2023-10-26 04:27:07 +08:00
};
// pkg/dist-src/graphql.js
var NON_VARIABLE_OPTIONS = [
"method",
"baseUrl",
"url",
"headers",
"request",
"query",
"mediaType"
];
var FORBIDDEN_VARIABLE_OPTIONS = ["query", "method", "url"];
var GHES_V3_SUFFIX_REGEX = /\/api\/v3\/?$/;
function graphql(request2, query, options) {
if (options) {
if (typeof query === "string" && "query" in options) {
return Promise.reject(
new Error(`[@octokit/graphql] "query" cannot be used as variable name`)
);
}
for (const key in options) {
if (!FORBIDDEN_VARIABLE_OPTIONS.includes(key))
continue;
return Promise.reject(
new Error(
`[@octokit/graphql] "${key}" cannot be used as variable name`
)
);
}
}
const parsedOptions = typeof query === "string" ? Object.assign({ query }, options) : query;
const requestOptions = Object.keys(
parsedOptions
).reduce((result, key) => {
2022-11-04 00:55:07 +08:00
if (NON_VARIABLE_OPTIONS.includes(key)) {
2023-10-26 04:27:07 +08:00
result[key] = parsedOptions[key];
2022-11-04 00:55:07 +08:00
return result;
}
if (!result.variables) {
result.variables = {};
}
2023-10-26 04:27:07 +08:00
result.variables[key] = parsedOptions[key];
2022-11-04 00:55:07 +08:00
return result;
}, {});
2023-10-26 04:27:07 +08:00
const baseUrl = parsedOptions.baseUrl || request2.endpoint.DEFAULTS.baseUrl;
if (GHES_V3_SUFFIX_REGEX.test(baseUrl)) {
requestOptions.url = baseUrl.replace(GHES_V3_SUFFIX_REGEX, "/api/graphql");
}
return request2(requestOptions).then((response) => {
2022-11-04 00:55:07 +08:00
if (response.data.errors) {
const headers = {};
for (const key of Object.keys(response.headers)) {
headers[key] = response.headers[key];
}
2023-10-26 04:27:07 +08:00
throw new GraphqlResponseError(
requestOptions,
2022-11-04 00:55:07 +08:00
headers,
2023-10-26 04:27:07 +08:00
response.data
);
2022-11-04 00:55:07 +08:00
}
return response.data.data;
});
}
2023-10-26 04:27:07 +08:00
// pkg/dist-src/with-defaults.js
function withDefaults(request2, newDefaults) {
const newRequest = request2.defaults(newDefaults);
2022-11-04 00:55:07 +08:00
const newApi = (query, options) => {
return graphql(newRequest, query, options);
};
return Object.assign(newApi, {
defaults: withDefaults.bind(null, newRequest),
2023-10-26 04:27:07 +08:00
endpoint: newRequest.endpoint
2022-11-04 00:55:07 +08:00
});
}
2023-10-26 04:27:07 +08:00
// pkg/dist-src/index.js
var graphql2 = withDefaults(import_request3.request, {
2022-11-04 00:55:07 +08:00
headers: {
2023-10-26 04:27:07 +08:00
"user-agent": `octokit-graphql.js/${VERSION} ${(0, import_universal_user_agent.getUserAgent)()}`
2022-11-04 00:55:07 +08:00
},
method: "POST",
url: "/graphql"
});
function withCustomRequest(customRequest) {
return withDefaults(customRequest, {
method: "POST",
url: "/graphql"
});
}
2023-10-26 04:27:07 +08:00
// Annotate the CommonJS export names for ESM import in node:
0 && (module.exports = {
GraphqlResponseError,
graphql,
withCustomRequest
});