Skip to content

Commit

Permalink
Add type alias
Browse files Browse the repository at this point in the history
  • Loading branch information
hugoalh committed Mar 22, 2024
1 parent c9c27d7 commit 1647ca4
Show file tree
Hide file tree
Showing 7 changed files with 33 additions and 23 deletions.
7 changes: 4 additions & 3 deletions command/file.ts
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,7 @@ import { EOL } from "node:os";
import { isAbsolute as isPathAbsolute } from "node:path";
import { getEnv } from "https://raw.githubusercontent.com/hugoalh-studio/cross-env-ts/v1.0.1/mod.ts";
import { isStringSingleLine } from "https://raw.githubusercontent.com/hugoalh-studio/is-string-singleline-ts/v1.0.0/mod.ts";
import { type KeyValueLike } from "../common.ts";
const commandsFile: Set<string> = new Set<string>([
"GITHUB_ENV",
"GITHUB_OUTPUT",
Expand Down Expand Up @@ -152,11 +153,11 @@ export class GitHubActionsFileMapCommand extends GitHubActionsFileCommandBase {
append(key: string, value: string): this;
/**
* Append pairs to the file map command.
* @param {{ [key: string]: string; } | Map<string, string> | Record<string, string>} pairs Pairs of the file map command.
* @param {KeyValueLike} pairs Pairs of the file map command.
* @returns {this}
*/
append(pairs: { [key: string]: string; } | Map<string, string> | Record<string, string>): this;
append(param0: string | { [key: string]: string; } | Map<string, string> | Record<string, string>, param1?: string): this {
append(pairs: KeyValueLike): this;
append(param0: string | KeyValueLike, param1?: string): this {
const pairs: Map<string, string> = new Map<string, string>();
if (typeof param0 === "string") {
if (!isStringSingleLine(param0)) {
Expand Down
11 changes: 6 additions & 5 deletions command/stdout.ts
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
import { isStringSingleLine } from "https://raw.githubusercontent.com/hugoalh-studio/is-string-singleline-ts/v1.0.0/mod.ts";
import { type KeyValueLike } from "../common.ts";
const commandsStdOutCurrent: Set<string> = new Set<string>([
"add-mask",
"add-matcher",
Expand Down Expand Up @@ -53,11 +54,11 @@ export class GitHubActionsStdOutCommand {
/**
* **\[🅰️ ADVANCED\]** Create new instance to communicate with the GitHub Actions runner via stdout command.
* @param {string} command StdOut command.
* @param {{ [key: string]: string; } | Map<string, string> | Record<string, string>} properties Properties of the stdout command.
* @param {KeyValueLike} properties Properties of the stdout command.
* @param {string} [message] Message of the stdout command.
*/
constructor(command: string, properties: { [key: string]: string; } | Map<string, string> | Record<string, string>, message?: string);
constructor(command: string, param1?: string | { [key: string]: string; } | Map<string, string> | Record<string, string>, param2?: string) {
constructor(command: string, properties: KeyValueLike, message?: string);
constructor(command: string, param1?: string | KeyValueLike, param2?: string) {
if (!(
commandsStdOutCurrent.has(command) ||
regexpCommandStdout.test(command)
Expand Down Expand Up @@ -103,10 +104,10 @@ export class GitHubActionsStdOutCommand {
}
/**
* Set properties of the stdout command.
* @param {{ [key: string]: string; } | Map<string, string> | Record<string, string>} properties Properties of the stdout command.
* @param {KeyValueLike} properties Properties of the stdout command.
* @returns {this}
*/
setProperties(properties: { [key: string]: string; } | Map<string, string> | Record<string, string>): this {
setProperties(properties: KeyValueLike): this {
for (const [key, value] of ((properties instanceof Map) ? properties.entries() : Object.entries(properties))) {
this.setProperty(key, value);
}
Expand Down
4 changes: 4 additions & 0 deletions common.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,4 @@
/**
* Type of key-value like.
*/
export type KeyValueLike<V extends string = string> = { [key: string]: V; } | Map<string, V> | Record<string, V>;
11 changes: 6 additions & 5 deletions environment_variable.ts
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,7 @@ import { delimiter as pathDelimiter } from "node:path";
import { getEnv, setEnv } from "https://raw.githubusercontent.com/hugoalh-studio/cross-env-ts/v1.0.1/mod.ts";
import { isStringSingleLine } from "https://raw.githubusercontent.com/hugoalh-studio/is-string-singleline-ts/v1.0.0/mod.ts";
import { GitHubActionsFileLineCommand, GitHubActionsFileMapCommand, type GitHubActionsFileCommandOptions } from "./command/file.ts";
import { type KeyValueLike } from "./common.ts";
const regexpEnvironmentVariableKeyForbidden = /^(?:CI|PATH)$|^(?:ACTIONS|GITHUB|RUNNER)_/i;
/**
* Validate the item is a valid GitHub Actions environment variable key.
Expand Down Expand Up @@ -85,11 +86,11 @@ export class GitHubActionsEnvironmentVariableExportation {
set(key: string, value: string): this;
/**
* Set the environment variables.
* @param {{ [key: string]: string; } | Map<string, string> | Record<string, string>} pairs Pairs of the environment variable.
* @param {KeyValueLike} pairs Pairs of the environment variable.
* @returns {this}
*/
set(pairs: { [key: string]: string; } | Map<string, string> | Record<string, string>): this;
set(param0: string | { [key: string]: string; } | Map<string, string> | Record<string, string>, param1?: string): this {
set(pairs: KeyValueLike): this;
set(param0: string | KeyValueLike, param1?: string): this {
const pairs: Map<string, string> = new Map<string, string>();
if (typeof param0 === "string") {
validateEnvironmentVariableKey(param0);
Expand Down Expand Up @@ -141,11 +142,11 @@ export function setEnvironmentVariable(key: string, value: string, options: GitH
* > - Environment Variable (`allow-env`)
* > - File System - Read (`allow-read`)
* > - File System - Write (`allow-write`)
* @param {{ [key: string]: string; } | Map<string, string> | Record<string, string>} pairs Pairs of the environment variable.
* @param {KeyValueLike} pairs Pairs of the environment variable.
* @param {GitHubActionsEnvironmentVariableOptions & GitHubActionsFileCommandOptions} [options={}] Options.
* @returns {void}
*/
export function setEnvironmentVariables(pairs: { [key: string]: string; } | Map<string, string> | Record<string, string>, options: GitHubActionsEnvironmentVariableOptions & GitHubActionsFileCommandOptions = {}): void {
export function setEnvironmentVariables(pairs: KeyValueLike, options: GitHubActionsEnvironmentVariableOptions & GitHubActionsFileCommandOptions = {}): void {
const instance: GitHubActionsEnvironmentVariableExportation = new GitHubActionsEnvironmentVariableExportation(options);
instance.set(pairs);
if (options.optimize) {
Expand Down
1 change: 1 addition & 0 deletions mod.ts
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
export { GitHubActionsFileLineCommand, GitHubActionsFileMapCommand, type GitHubActionsFileCommandOptions } from "./command/file.ts";
export { disableEchoStdOutCommand, disableProcessStdOutCommand, enableEchoStdOutCommand, enableProcessStdOutCommand, GitHubActionsStdOutCommand } from "./command/stdout.ts";
export { type KeyValueLike } from "./common.ts";
export { addPATH, GitHubActionsEnvironmentVariableExportation, GitHubActionsPATHExportation, setEnvironmentVariable, setEnvironmentVariables, type GitHubActionsEnvironmentVariableOptions } from "./environment_variable.ts";
export { addMask, addSecret, addSecretMask, endLogGroup, enterLogGroup, exitLogGroup, GitHubActionsAnnotationType, startLogGroup, writeAnnotation, writeDebug, writeError, writeNote, writeNotice, writeWarn, writeWarning, type GitHubActionsAnnotationProperties } from "./log.ts";
export { getInput, getInputBigInt, getInputBoolean, getInputNumber, getInputRaw, getInputRegExp, GitHubActionsOutput, setOutput, setOutputs, type GitHubActionsInputOptions } from "./parameter.ts";
Expand Down
11 changes: 6 additions & 5 deletions parameter.ts
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
import { getEnv } from "https://raw.githubusercontent.com/hugoalh-studio/cross-env-ts/v1.0.1/mod.ts";
import { isStringSingleLine } from "https://raw.githubusercontent.com/hugoalh-studio/is-string-singleline-ts/v1.0.0/mod.ts";
import { GitHubActionsFileMapCommand, type GitHubActionsFileCommandOptions } from "./command/file.ts";
import { type KeyValueLike } from "./common.ts";
export interface GitHubActionsInputOptions {
/**
* Whether the input is require.
Expand Down Expand Up @@ -169,11 +170,11 @@ export class GitHubActionsOutput {
set(key: string, value: string): this;
/**
* Set the outputs.
* @param {{ [key: string]: string; } | Map<string, string> | Record<string, string>} pairs Pairs of the output.
* @param {KeyValueLike} pairs Pairs of the output.
* @returns {this}
*/
set(pairs: { [key: string]: string; } | Map<string, string> | Record<string, string>): this;
set(param0: string | { [key: string]: string; } | Map<string, string> | Record<string, string>, param1?: string): this {
set(pairs: KeyValueLike): this;
set(param0: string | KeyValueLike, param1?: string): this {
const pairs: Map<string, string> = new Map<string, string>();
if (typeof param0 === "string") {
if (!isStringSingleLine(param0)) {
Expand Down Expand Up @@ -222,11 +223,11 @@ export function setOutput(key: string, value: string, options: GitHubActionsFile
* > - Environment Variable (`allow-env`)
* > - File System - Read (`allow-read`)
* > - File System - Write (`allow-write`)
* @param {{ [key: string]: string; } | Map<string, string> | Record<string, string>} pairs Pairs of the output.
* @param {KeyValueLike} pairs Pairs of the output.
* @param {GitHubActionsFileCommandOptions} [options={}] Options.
* @returns {void}
*/
export function setOutputs(pairs: { [key: string]: string; } | Map<string, string> | Record<string, string>, options: GitHubActionsFileCommandOptions={}): void{
export function setOutputs(pairs: KeyValueLike, options: GitHubActionsFileCommandOptions={}): void{
const instance: GitHubActionsOutput = new GitHubActionsOutput();
instance.set(pairs);
if (options.optimize) {
Expand Down
11 changes: 6 additions & 5 deletions state.ts
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
import { getEnv } from "https://raw.githubusercontent.com/hugoalh-studio/cross-env-ts/v1.0.1/mod.ts";
import { isStringSingleLine } from "https://raw.githubusercontent.com/hugoalh-studio/is-string-singleline-ts/v1.0.0/mod.ts";
import { GitHubActionsFileMapCommand, type GitHubActionsFileCommandOptions } from "./command/file.ts";
import { type KeyValueLike } from "./common.ts";
/**
* Get the raw value of a state.
*
Expand Down Expand Up @@ -64,11 +65,11 @@ export class GitHubActionsStateExportation {
set(key: string, value: string): this;
/**
* Set the states.
* @param {{ [key: string]: string; } | Map<string, string> | Record<string, string>} pairs Pairs of the state.
* @param {KeyValueLike} pairs Pairs of the state.
* @returns {this}
*/
set(pairs: { [key: string]: string; } | Map<string, string> | Record<string, string>): this;
set(param0: string | { [key: string]: string; } | Map<string, string> | Record<string, string>, param1?: string): this {
set(pairs: KeyValueLike): this;
set(param0: string | KeyValueLike, param1?: string): this {
const pairs: Map<string, string> = new Map<string, string>();
if (typeof param0 === "string") {
if (!isStringSingleLine(param0)) {
Expand Down Expand Up @@ -117,11 +118,11 @@ export function setState(key: string, value: string, options: GitHubActionsFileC
* > - Environment Variable (`allow-env`)
* > - File System - Read (`allow-read`)
* > - File System - Write (`allow-write`)
* @param {{ [key: string]: string; } | Map<string, string> | Record<string, string>} pairs Pairs of the state.
* @param {KeyValueLike} pairs Pairs of the state.
* @param {GitHubActionsFileCommandOptions} [options={}] Options.
* @returns {void}
*/
export function setStates(pairs: { [key: string]: string; } | Map<string, string> | Record<string, string>, options: GitHubActionsFileCommandOptions = {}): void {
export function setStates(pairs: KeyValueLike, options: GitHubActionsFileCommandOptions = {}): void {
const instance: GitHubActionsStateExportation = new GitHubActionsStateExportation();
instance.set(pairs);
if (options.optimize) {
Expand Down

0 comments on commit 1647ca4

Please sign in to comment.