feat: add @actions/cache

This commit is contained in:
xHyroM 2022-07-12 09:00:22 +02:00
parent b15fb7d098
commit 16e8c96a41
1932 changed files with 261172 additions and 10 deletions

View file

@ -0,0 +1,35 @@
// Copyright (c) Microsoft Corporation. All rights reserved.
// Licensed under the MIT License. See License.txt in the project root for license information.
/**
* Encodes a string in base64 format.
* @param value the string to encode
*/
export function encodeString(value: string): string {
return btoa(value);
}
/**
* Encodes a byte array in base64 format.
* @param value the Uint8Aray to encode
*/
export function encodeByteArray(value: Uint8Array): string {
let str = "";
for (let i = 0; i < value.length; i++) {
str += String.fromCharCode(value[i]);
}
return btoa(str);
}
/**
* Decodes a base64 string into a byte array.
* @param value the base64 string to decode
*/
export function decodeString(value: string): Uint8Array {
const byteString = atob(value);
const arr = new Uint8Array(byteString.length);
for (let i = 0; i < byteString.length; i++) {
arr[i] = byteString.charCodeAt(i);
}
return arr;
}

29
node_modules/@azure/ms-rest-js/lib/util/base64.ts generated vendored Normal file
View file

@ -0,0 +1,29 @@
// Copyright (c) Microsoft Corporation. All rights reserved.
// Licensed under the MIT License. See License.txt in the project root for license information.
/**
* Encodes a string in base64 format.
* @param value the string to encode
*/
export function encodeString(value: string): string {
return Buffer.from(value).toString("base64");
}
/**
* Encodes a byte array in base64 format.
* @param value the Uint8Aray to encode
*/
export function encodeByteArray(value: Uint8Array): string {
// Buffer.from accepts <ArrayBuffer> | <SharedArrayBuffer>-- the TypeScript definition is off here
// https://nodejs.org/api/buffer.html#buffer_class_method_buffer_from_arraybuffer_byteoffset_length
const bufferValue = value instanceof Buffer ? value : Buffer.from(value.buffer as ArrayBuffer);
return bufferValue.toString("base64");
}
/**
* Decodes a base64 string into a byte array.
* @param value the base64 string to decode
*/
export function decodeString(value: string): Uint8Array {
return Buffer.from(value, "base64");
}

108
node_modules/@azure/ms-rest-js/lib/util/constants.ts generated vendored Normal file
View file

@ -0,0 +1,108 @@
// Copyright (c) Microsoft Corporation. All rights reserved.
// Licensed under the MIT License. See License.txt in the project root for license information.
export const Constants = {
/**
* The ms-rest version
* @const
* @type {string}
*/
msRestVersion: "2.6.1",
/**
* Specifies HTTP.
*
* @const
* @type {string}
*/
HTTP: "http:",
/**
* Specifies HTTPS.
*
* @const
* @type {string}
*/
HTTPS: "https:",
/**
* Specifies HTTP Proxy.
*
* @const
* @type {string}
*/
HTTP_PROXY: "HTTP_PROXY",
/**
* Specifies HTTPS Proxy.
*
* @const
* @type {string}
*/
HTTPS_PROXY: "HTTPS_PROXY",
/**
* Specifies NO Proxy.
*/
NO_PROXY: "NO_PROXY",
/**
* Specifies ALL Proxy.
*/
ALL_PROXY: "ALL_PROXY",
HttpConstants: {
/**
* Http Verbs
*
* @const
* @enum {string}
*/
HttpVerbs: {
PUT: "PUT",
GET: "GET",
DELETE: "DELETE",
POST: "POST",
MERGE: "MERGE",
HEAD: "HEAD",
PATCH: "PATCH",
},
StatusCodes: {
TooManyRequests: 429,
},
},
/**
* Defines constants for use with HTTP headers.
*/
HeaderConstants: {
/**
* The Authorization header.
*
* @const
* @type {string}
*/
AUTHORIZATION: "authorization",
AUTHORIZATION_SCHEME: "Bearer",
/**
* The Retry-After response-header field can be used with a 503 (Service
* Unavailable) or 349 (Too Many Requests) responses to indicate how long
* the service is expected to be unavailable to the requesting client.
*
* @const
* @type {string}
*/
RETRY_AFTER: "Retry-After",
/**
* The UserAgent header.
*
* @const
* @type {string}
*/
USER_AGENT: "User-Agent",
},
};

288
node_modules/@azure/ms-rest-js/lib/util/utils.ts generated vendored Normal file
View file

@ -0,0 +1,288 @@
// Copyright (c) Microsoft Corporation. All rights reserved.
// Licensed under the MIT License. See License.txt in the project root for license information.
import { v4 as uuidv4 } from "uuid";
import { HttpOperationResponse } from "../httpOperationResponse";
import { RestError } from "../restError";
import { WebResourceLike } from "../webResource";
import { Constants } from "./constants";
/**
* A constant that indicates whether the environment is node.js or browser based.
*/
export const isNode =
typeof process !== "undefined" &&
!!process.version &&
!!process.versions &&
!!process.versions.node;
/**
* Checks if a parsed URL is HTTPS
*
* @param {object} urlToCheck The url to check
* @return {boolean} True if the URL is HTTPS; false otherwise.
*/
export function urlIsHTTPS(urlToCheck: { protocol: string }): boolean {
return urlToCheck.protocol.toLowerCase() === Constants.HTTPS;
}
/**
* Encodes an URI.
*
* @param {string} uri The URI to be encoded.
* @return {string} The encoded URI.
*/
export function encodeUri(uri: string): string {
return encodeURIComponent(uri)
.replace(/!/g, "%21")
.replace(/"/g, "%27")
.replace(/\(/g, "%28")
.replace(/\)/g, "%29")
.replace(/\*/g, "%2A");
}
/**
* Returns a stripped version of the Http Response which only contains body,
* headers and the status.
*
* @param {HttpOperationResponse} response The Http Response
*
* @return {object} The stripped version of Http Response.
*/
export function stripResponse(response: HttpOperationResponse): any {
const strippedResponse: any = {};
strippedResponse.body = response.bodyAsText;
strippedResponse.headers = response.headers;
strippedResponse.status = response.status;
return strippedResponse;
}
/**
* Returns a stripped version of the Http Request that does not contain the
* Authorization header.
*
* @param {WebResource} request The Http Request object
*
* @return {WebResource} The stripped version of Http Request.
*/
export function stripRequest(request: WebResourceLike): WebResourceLike {
const strippedRequest = request.clone();
if (strippedRequest.headers) {
strippedRequest.headers.remove("authorization");
}
return strippedRequest;
}
/**
* Validates the given uuid as a string
*
* @param {string} uuid The uuid as a string that needs to be validated
*
* @return {boolean} True if the uuid is valid; false otherwise.
*/
export function isValidUuid(uuid: string): boolean {
const validUuidRegex = new RegExp(
"^[0-9a-fA-F]{8}-[0-9a-fA-F]{4}-[0-9a-fA-F]{4}-[0-9a-fA-F]{4}-[0-9a-fA-F]{12}$",
"ig"
);
return validUuidRegex.test(uuid);
}
/**
* Provides an array of values of an object. For example
* for a given object { "a": "foo", "b": "bar" }, the method returns ["foo", "bar"].
*
* @param {object} obj An object whose properties need to be enumerated so that it"s values can be provided as an array
*
* @return {any[]} An array of values of the given object.
*/
export function objectValues(obj: { [key: string]: any }): any[] {
const result: any[] = [];
if (obj && obj instanceof Object) {
for (const key in obj) {
if (obj.hasOwnProperty(key)) {
result.push((<any>obj)[key]);
}
}
} else {
throw new Error(
`The provided object ${JSON.stringify(
obj,
undefined,
2
)} is not a valid object that can be ` + `enumerated to provide its values as an array.`
);
}
return result;
}
/**
* Generated UUID
*
* @return {string} RFC4122 v4 UUID.
*/
export function generateUuid(): string {
return uuidv4();
}
/**
* Executes an array of promises sequentially. Inspiration of this method is here:
* https://pouchdb.com/2015/05/18/we-have-a-problem-with-promises.html. An awesome blog on promises!
*
* @param {Array} promiseFactories An array of promise factories(A function that return a promise)
*
* @param {any} [kickstart] Input to the first promise that is used to kickstart the promise chain.
* If not provided then the promise chain starts with undefined.
*
* @return A chain of resolved or rejected promises
*/
export function executePromisesSequentially(promiseFactories: Array<any>, kickstart: any) {
let result = Promise.resolve(kickstart);
promiseFactories.forEach((promiseFactory) => {
result = result.then(promiseFactory);
});
return result;
}
/**
* Merges source object into the target object
* @param {object} source The object that needs to be merged
*
* @param {object} target The object to be merged into
*
* @returns {object} Returns the merged target object.
*/
export function mergeObjects(source: { [key: string]: any }, target: { [key: string]: any }) {
Object.keys(source).forEach((key) => {
target[key] = source[key];
});
return target;
}
/**
* A wrapper for setTimeout that resolves a promise after t milliseconds.
* @param {number} t The number of milliseconds to be delayed.
* @param {T} value The value to be resolved with after a timeout of t milliseconds.
* @returns {Promise<T>} Resolved promise
*/
export function delay<T>(t: number, value?: T): Promise<T> {
return new Promise((resolve) => setTimeout(() => resolve(value), t));
}
/**
* Service callback that is returned for REST requests initiated by the service client.
*/
export interface ServiceCallback<TResult> {
/**
* A method that will be invoked as a callback to a service function.
* @param {Error | RestError | null} err The error occurred if any, while executing the request; otherwise null.
* @param {TResult} [result] The deserialized response body if an error did not occur.
* @param {WebResourceLike} [request] The raw/actual request sent to the server if an error did not occur.
* @param {HttpOperationResponse} [response] The raw/actual response from the server if an error did not occur.
*/
(
err: Error | RestError | null,
result?: TResult,
request?: WebResourceLike,
response?: HttpOperationResponse
): void;
}
/**
* Converts a Promise to a callback.
* @param {Promise<any>} promise The Promise to be converted to a callback
* @returns {Function} A function that takes the callback (cb: Function): void
* @deprecated generated code should instead depend on responseToBody
*/
export function promiseToCallback(promise: Promise<any>): Function {
if (typeof promise.then !== "function") {
throw new Error("The provided input is not a Promise.");
}
return (cb: Function): void => {
promise.then(
(data: any) => {
cb(undefined, data);
},
(err: Error) => {
cb(err);
}
);
};
}
/**
* Converts a Promise to a service callback.
* @param {Promise<HttpOperationResponse>} promise - The Promise of HttpOperationResponse to be converted to a service callback
* @returns {Function} A function that takes the service callback (cb: ServiceCallback<T>): void
*/
export function promiseToServiceCallback<T>(promise: Promise<HttpOperationResponse>): Function {
if (typeof promise.then !== "function") {
throw new Error("The provided input is not a Promise.");
}
return (cb: ServiceCallback<T>): void => {
promise.then(
(data: HttpOperationResponse) => {
process.nextTick(cb, undefined, data.parsedBody as T, data.request, data);
},
(err: Error) => {
process.nextTick(cb, err);
}
);
};
}
export function prepareXMLRootList(obj: any, elementName: string) {
if (!Array.isArray(obj)) {
obj = [obj];
}
return { [elementName]: obj };
}
/**
* Applies the properties on the prototype of sourceCtors to the prototype of targetCtor
* @param {object} targetCtor The target object on which the properties need to be applied.
* @param {Array<object>} sourceCtors An array of source objects from which the properties need to be taken.
*/
export function applyMixins(targetCtor: any, sourceCtors: any[]): void {
sourceCtors.forEach((sourceCtors) => {
Object.getOwnPropertyNames(sourceCtors.prototype).forEach((name) => {
targetCtor.prototype[name] = sourceCtors.prototype[name];
});
});
}
const validateISODuration = /^(-|\+)?P(?:([-+]?[0-9,.]*)Y)?(?:([-+]?[0-9,.]*)M)?(?:([-+]?[0-9,.]*)W)?(?:([-+]?[0-9,.]*)D)?(?:T(?:([-+]?[0-9,.]*)H)?(?:([-+]?[0-9,.]*)M)?(?:([-+]?[0-9,.]*)S)?)?$/;
/**
* Indicates whether the given string is in ISO 8601 format.
* @param {string} value The value to be validated for ISO 8601 duration format.
* @return {boolean} `true` if valid, `false` otherwise.
*/
export function isDuration(value: string): boolean {
return validateISODuration.test(value);
}
/**
* Replace all of the instances of searchValue in value with the provided replaceValue.
* @param {string | undefined} value The value to search and replace in.
* @param {string} searchValue The value to search for in the value argument.
* @param {string} replaceValue The value to replace searchValue with in the value argument.
* @returns {string | undefined} The value where each instance of searchValue was replaced with replacedValue.
*/
export function replaceAll(
value: string | undefined,
searchValue: string,
replaceValue: string
): string | undefined {
return !value || !searchValue ? value : value.split(searchValue).join(replaceValue || "");
}
/**
* Determines whether the given enity is a basic/primitive type
* (string, number, boolean, null, undefined).
* @param value Any entity
* @return boolean - true is it is primitive type, false otherwise.
*/
export function isPrimitiveType(value: any): boolean {
return (typeof value !== "object" && typeof value !== "function") || value === null;
}

149
node_modules/@azure/ms-rest-js/lib/util/xml.browser.ts generated vendored Normal file
View file

@ -0,0 +1,149 @@
// Copyright (c) Microsoft Corporation. All rights reserved.
// Licensed under the MIT License. See License.txt in the project root for license information.
const parser = new DOMParser();
export function parseXML(str: string): Promise<any> {
try {
const dom = parser.parseFromString(str, "application/xml");
throwIfError(dom);
const obj = domToObject(dom.childNodes[0]);
return Promise.resolve(obj);
} catch (err) {
return Promise.reject(err);
}
}
let errorNS = "";
try {
errorNS = parser.parseFromString("INVALID", "text/xml").getElementsByTagName("parsererror")[0]
.namespaceURI!;
} catch (ignored) {
// Most browsers will return a document containing <parsererror>, but IE will throw.
}
function throwIfError(dom: Document) {
if (errorNS) {
const parserErrors = dom.getElementsByTagNameNS(errorNS, "parsererror");
if (parserErrors.length) {
throw new Error(parserErrors.item(0)!.innerHTML);
}
}
}
function isElement(node: Node): node is Element {
return !!(node as Element).attributes;
}
/**
* Get the Element-typed version of the provided Node if the provided node is an element with
* attributes. If it isn't, then undefined is returned.
*/
function asElementWithAttributes(node: Node): Element | undefined {
return isElement(node) && node.hasAttributes() ? node : undefined;
}
function domToObject(node: Node): any {
let result: any = {};
const childNodeCount: number = node.childNodes.length;
const firstChildNode: Node = node.childNodes[0];
const onlyChildTextValue: string | undefined =
(firstChildNode &&
childNodeCount === 1 &&
firstChildNode.nodeType === Node.TEXT_NODE &&
firstChildNode.nodeValue) ||
undefined;
const elementWithAttributes: Element | undefined = asElementWithAttributes(node);
if (elementWithAttributes) {
result["$"] = {};
for (let i = 0; i < elementWithAttributes.attributes.length; i++) {
const attr = elementWithAttributes.attributes[i];
result["$"][attr.nodeName] = attr.nodeValue;
}
if (onlyChildTextValue) {
result["_"] = onlyChildTextValue;
}
} else if (childNodeCount === 0) {
result = "";
} else if (onlyChildTextValue) {
result = onlyChildTextValue;
}
if (!onlyChildTextValue) {
for (let i = 0; i < childNodeCount; i++) {
const child = node.childNodes[i];
// Ignore leading/trailing whitespace nodes
if (child.nodeType !== Node.TEXT_NODE) {
const childObject: any = domToObject(child);
if (!result[child.nodeName]) {
result[child.nodeName] = childObject;
} else if (Array.isArray(result[child.nodeName])) {
result[child.nodeName].push(childObject);
} else {
result[child.nodeName] = [result[child.nodeName], childObject];
}
}
}
}
return result;
}
// tslint:disable-next-line:no-null-keyword
const doc = document.implementation.createDocument(null, null, null);
const serializer = new XMLSerializer();
export function stringifyXML(obj: any, opts?: { rootName?: string }) {
const rootName = (opts && opts.rootName) || "root";
const dom = buildNode(obj, rootName)[0];
return (
'<?xml version="1.0" encoding="UTF-8" standalone="yes"?>' + serializer.serializeToString(dom)
);
}
function buildAttributes(attrs: { [key: string]: { toString(): string } }): Attr[] {
const result = [];
for (const key of Object.keys(attrs)) {
const attr = doc.createAttribute(key);
attr.value = attrs[key].toString();
result.push(attr);
}
return result;
}
function buildNode(obj: any, elementName: string): Node[] {
if (typeof obj === "string" || typeof obj === "number" || typeof obj === "boolean") {
const elem = doc.createElement(elementName);
elem.textContent = obj.toString();
return [elem];
} else if (Array.isArray(obj)) {
const result = [];
for (const arrayElem of obj) {
for (const child of buildNode(arrayElem, elementName)) {
result.push(child);
}
}
return result;
} else if (typeof obj === "object") {
const elem = doc.createElement(elementName);
for (const key of Object.keys(obj)) {
if (key === "$") {
for (const attr of buildAttributes(obj[key])) {
elem.attributes.setNamedItem(attr);
}
} else {
for (const child of buildNode(obj[key], key)) {
elem.appendChild(child);
}
}
}
return [elem];
} else {
throw new Error(`Illegal value passed to buildObject: ${obj}`);
}
}

35
node_modules/@azure/ms-rest-js/lib/util/xml.ts generated vendored Normal file
View file

@ -0,0 +1,35 @@
// Copyright (c) Microsoft Corporation. All rights reserved.
// Licensed under the MIT License. See License.txt in the project root for license information.
import * as xml2js from "xml2js";
export function stringifyXML(obj: any, opts?: { rootName?: string }) {
const builder = new xml2js.Builder({
rootName: (opts || {}).rootName,
renderOpts: {
pretty: false,
},
});
return builder.buildObject(obj);
}
export function parseXML(str: string): Promise<any> {
const xmlParser = new xml2js.Parser({
explicitArray: false,
explicitCharkey: false,
explicitRoot: false,
});
return new Promise((resolve, reject) => {
if (!str) {
reject(new Error("Document is empty"));
} else {
xmlParser.parseString(str, (err?: Error, res?: any) => {
if (err) {
reject(err);
} else {
resolve(res);
}
});
}
});
}