diff --git a/lib/analyze-action-post.js b/lib/analyze-action-post.js index 6adbd9db4..fd07f7f08 100644 --- a/lib/analyze-action-post.js +++ b/lib/analyze-action-post.js @@ -49518,6 +49518,7 @@ var require_minimatch = __commonJS({ re += c; continue; } + if (c === "*" && stateChar === "*") continue; self2.debug("call clearStateChar %j", stateChar); clearStateChar(); stateChar = c; @@ -103582,6 +103583,7 @@ var require_minimatch2 = __commonJS({ re += c; continue; } + if (c === "*" && stateChar === "*") continue; this.debug("call clearStateChar %j", stateChar); clearStateChar(); stateChar = c; @@ -116408,9 +116410,9 @@ var require_isPlainObject = __commonJS({ } }); -// node_modules/@isaacs/balanced-match/dist/commonjs/index.js +// node_modules/glob/node_modules/balanced-match/dist/commonjs/index.js var require_commonjs18 = __commonJS({ - "node_modules/@isaacs/balanced-match/dist/commonjs/index.js"(exports2) { + "node_modules/glob/node_modules/balanced-match/dist/commonjs/index.js"(exports2) { "use strict"; Object.defineProperty(exports2, "__esModule", { value: true }); exports2.range = exports2.balanced = void 0; @@ -116470,9 +116472,9 @@ var require_commonjs18 = __commonJS({ } }); -// node_modules/@isaacs/brace-expansion/dist/commonjs/index.js +// node_modules/glob/node_modules/brace-expansion/dist/commonjs/index.js var require_commonjs19 = __commonJS({ - "node_modules/@isaacs/brace-expansion/dist/commonjs/index.js"(exports2) { + "node_modules/glob/node_modules/brace-expansion/dist/commonjs/index.js"(exports2) { "use strict"; Object.defineProperty(exports2, "__esModule", { value: true }); exports2.EXPANSION_MAX = void 0; @@ -117233,6 +117235,7 @@ var require_ast = __commonJS({ let escaping = false; let re = ""; let uflag = false; + let inStar = false; for (let i = 0; i < glob2.length; i++) { const c = glob2.charAt(i); if (escaping) { @@ -117240,6 +117243,16 @@ var require_ast = __commonJS({ re += (reSpecials.has(c) ? "\\" : "") + c; continue; } + if (c === "*") { + if (inStar) + continue; + inStar = true; + re += noEmpty && /^[*]+$/.test(glob2) ? starNoEmpty : star; + hasMagic = true; + continue; + } else { + inStar = false; + } if (c === "\\") { if (i === glob2.length - 1) { re += "\\\\"; @@ -117258,11 +117271,6 @@ var require_ast = __commonJS({ continue; } } - if (c === "*") { - re += noEmpty && glob2 === "*" ? starNoEmpty : star; - hasMagic = true; - continue; - } if (c === "?") { re += qmark; hasMagic = true; @@ -117422,7 +117430,7 @@ var require_commonjs20 = __commonJS({ if (options.nobrace || !/\{(?:(?!\{).)*\}/.test(pattern)) { return [pattern]; } - return (0, brace_expansion_1.expand)(pattern); + return (0, brace_expansion_1.expand)(pattern, { max: options.braceExpandMax }); }; exports2.braceExpand = braceExpand; exports2.minimatch.braceExpand = exports2.braceExpand; @@ -117466,7 +117474,8 @@ var require_commonjs20 = __commonJS({ this.pattern = pattern; this.platform = options.platform || defaultPlatform; this.isWindows = this.platform === "win32"; - this.windowsPathsNoEscape = !!options.windowsPathsNoEscape || options.allowWindowsEscape === false; + const awe = "allowWindowsEscape"; + this.windowsPathsNoEscape = !!options.windowsPathsNoEscape || options[awe] === false; if (this.windowsPathsNoEscape) { this.pattern = this.pattern.replace(/\\/g, "/"); } @@ -117523,7 +117532,10 @@ var require_commonjs20 = __commonJS({ const isUNC = s[0] === "" && s[1] === "" && (s[2] === "?" || !globMagic.test(s[2])) && !globMagic.test(s[3]); const isDrive = /^[a-z]:/i.test(s[0]); if (isUNC) { - return [...s.slice(0, 4), ...s.slice(4).map((ss) => this.parse(ss))]; + return [ + ...s.slice(0, 4), + ...s.slice(4).map((ss) => this.parse(ss)) + ]; } else if (isDrive) { return [s[0], ...s.slice(1).map((ss) => this.parse(ss))]; } @@ -117804,7 +117816,10 @@ var require_commonjs20 = __commonJS({ const fdi = fileUNC ? 3 : fileDrive ? 0 : void 0; const pdi = patternUNC ? 3 : patternDrive ? 0 : void 0; if (typeof fdi === "number" && typeof pdi === "number") { - const [fd, pd] = [file[fdi], pattern[pdi]]; + const [fd, pd] = [ + file[fdi], + pattern[pdi] + ]; if (fd.toLowerCase() === pd.toLowerCase()) { pattern[pdi] = fd; if (pdi > fdi) { @@ -161601,11 +161616,6 @@ var featureConfig = { envVar: "CODEQL_ACTION_IGNORE_GENERATED_FILES", minimumVersion: void 0 }, - ["improved_proxy_certificates" /* ImprovedProxyCertificates */]: { - defaultValue: false, - envVar: "CODEQL_ACTION_IMPROVED_PROXY_CERTIFICATES", - minimumVersion: void 0 - }, ["java_network_debugging" /* JavaNetworkDebugging */]: { defaultValue: false, envVar: "CODEQL_ACTION_JAVA_NETWORK_DEBUGGING", diff --git a/lib/analyze-action.js b/lib/analyze-action.js index d20a7e6ff..71f11dc2e 100644 --- a/lib/analyze-action.js +++ b/lib/analyze-action.js @@ -49518,6 +49518,7 @@ var require_minimatch = __commonJS({ re += c; continue; } + if (c === "*" && stateChar === "*") continue; self2.debug("call clearStateChar %j", stateChar); clearStateChar(); stateChar = c; @@ -107713,11 +107714,6 @@ var featureConfig = { envVar: "CODEQL_ACTION_IGNORE_GENERATED_FILES", minimumVersion: void 0 }, - ["improved_proxy_certificates" /* ImprovedProxyCertificates */]: { - defaultValue: false, - envVar: "CODEQL_ACTION_IMPROVED_PROXY_CERTIFICATES", - minimumVersion: void 0 - }, ["java_network_debugging" /* JavaNetworkDebugging */]: { defaultValue: false, envVar: "CODEQL_ACTION_JAVA_NETWORK_DEBUGGING", diff --git a/lib/autobuild-action.js b/lib/autobuild-action.js index 6a2dfbad6..73883fc7e 100644 --- a/lib/autobuild-action.js +++ b/lib/autobuild-action.js @@ -49518,6 +49518,7 @@ var require_minimatch = __commonJS({ re += c; continue; } + if (c === "*" && stateChar === "*") continue; self2.debug("call clearStateChar %j", stateChar); clearStateChar(); stateChar = c; @@ -104002,11 +104003,6 @@ var featureConfig = { envVar: "CODEQL_ACTION_IGNORE_GENERATED_FILES", minimumVersion: void 0 }, - ["improved_proxy_certificates" /* ImprovedProxyCertificates */]: { - defaultValue: false, - envVar: "CODEQL_ACTION_IMPROVED_PROXY_CERTIFICATES", - minimumVersion: void 0 - }, ["java_network_debugging" /* JavaNetworkDebugging */]: { defaultValue: false, envVar: "CODEQL_ACTION_JAVA_NETWORK_DEBUGGING", diff --git a/lib/init-action-post.js b/lib/init-action-post.js index cb91c0bf3..cc0f7f8e2 100644 --- a/lib/init-action-post.js +++ b/lib/init-action-post.js @@ -49518,6 +49518,7 @@ var require_minimatch = __commonJS({ re += c; continue; } + if (c === "*" && stateChar === "*") continue; self2.debug("call clearStateChar %j", stateChar); clearStateChar(); stateChar = c; @@ -103582,6 +103583,7 @@ var require_minimatch2 = __commonJS({ re += c; continue; } + if (c === "*" && stateChar === "*") continue; this.debug("call clearStateChar %j", stateChar); clearStateChar(); stateChar = c; @@ -116408,9 +116410,9 @@ var require_isPlainObject = __commonJS({ } }); -// node_modules/@isaacs/balanced-match/dist/commonjs/index.js +// node_modules/glob/node_modules/balanced-match/dist/commonjs/index.js var require_commonjs18 = __commonJS({ - "node_modules/@isaacs/balanced-match/dist/commonjs/index.js"(exports2) { + "node_modules/glob/node_modules/balanced-match/dist/commonjs/index.js"(exports2) { "use strict"; Object.defineProperty(exports2, "__esModule", { value: true }); exports2.range = exports2.balanced = void 0; @@ -116470,9 +116472,9 @@ var require_commonjs18 = __commonJS({ } }); -// node_modules/@isaacs/brace-expansion/dist/commonjs/index.js +// node_modules/glob/node_modules/brace-expansion/dist/commonjs/index.js var require_commonjs19 = __commonJS({ - "node_modules/@isaacs/brace-expansion/dist/commonjs/index.js"(exports2) { + "node_modules/glob/node_modules/brace-expansion/dist/commonjs/index.js"(exports2) { "use strict"; Object.defineProperty(exports2, "__esModule", { value: true }); exports2.EXPANSION_MAX = void 0; @@ -117233,6 +117235,7 @@ var require_ast = __commonJS({ let escaping = false; let re = ""; let uflag = false; + let inStar = false; for (let i = 0; i < glob2.length; i++) { const c = glob2.charAt(i); if (escaping) { @@ -117240,6 +117243,16 @@ var require_ast = __commonJS({ re += (reSpecials.has(c) ? "\\" : "") + c; continue; } + if (c === "*") { + if (inStar) + continue; + inStar = true; + re += noEmpty && /^[*]+$/.test(glob2) ? starNoEmpty : star; + hasMagic = true; + continue; + } else { + inStar = false; + } if (c === "\\") { if (i === glob2.length - 1) { re += "\\\\"; @@ -117258,11 +117271,6 @@ var require_ast = __commonJS({ continue; } } - if (c === "*") { - re += noEmpty && glob2 === "*" ? starNoEmpty : star; - hasMagic = true; - continue; - } if (c === "?") { re += qmark; hasMagic = true; @@ -117422,7 +117430,7 @@ var require_commonjs20 = __commonJS({ if (options.nobrace || !/\{(?:(?!\{).)*\}/.test(pattern)) { return [pattern]; } - return (0, brace_expansion_1.expand)(pattern); + return (0, brace_expansion_1.expand)(pattern, { max: options.braceExpandMax }); }; exports2.braceExpand = braceExpand; exports2.minimatch.braceExpand = exports2.braceExpand; @@ -117466,7 +117474,8 @@ var require_commonjs20 = __commonJS({ this.pattern = pattern; this.platform = options.platform || defaultPlatform; this.isWindows = this.platform === "win32"; - this.windowsPathsNoEscape = !!options.windowsPathsNoEscape || options.allowWindowsEscape === false; + const awe = "allowWindowsEscape"; + this.windowsPathsNoEscape = !!options.windowsPathsNoEscape || options[awe] === false; if (this.windowsPathsNoEscape) { this.pattern = this.pattern.replace(/\\/g, "/"); } @@ -117523,7 +117532,10 @@ var require_commonjs20 = __commonJS({ const isUNC = s[0] === "" && s[1] === "" && (s[2] === "?" || !globMagic.test(s[2])) && !globMagic.test(s[3]); const isDrive = /^[a-z]:/i.test(s[0]); if (isUNC) { - return [...s.slice(0, 4), ...s.slice(4).map((ss) => this.parse(ss))]; + return [ + ...s.slice(0, 4), + ...s.slice(4).map((ss) => this.parse(ss)) + ]; } else if (isDrive) { return [s[0], ...s.slice(1).map((ss) => this.parse(ss))]; } @@ -117804,7 +117816,10 @@ var require_commonjs20 = __commonJS({ const fdi = fileUNC ? 3 : fileDrive ? 0 : void 0; const pdi = patternUNC ? 3 : patternDrive ? 0 : void 0; if (typeof fdi === "number" && typeof pdi === "number") { - const [fd, pd] = [file[fdi], pattern[pdi]]; + const [fd, pd] = [ + file[fdi], + pattern[pdi] + ]; if (fd.toLowerCase() === pd.toLowerCase()) { pattern[pdi] = fd; if (pdi > fdi) { @@ -165098,11 +165113,6 @@ var featureConfig = { envVar: "CODEQL_ACTION_IGNORE_GENERATED_FILES", minimumVersion: void 0 }, - ["improved_proxy_certificates" /* ImprovedProxyCertificates */]: { - defaultValue: false, - envVar: "CODEQL_ACTION_IMPROVED_PROXY_CERTIFICATES", - minimumVersion: void 0 - }, ["java_network_debugging" /* JavaNetworkDebugging */]: { defaultValue: false, envVar: "CODEQL_ACTION_JAVA_NETWORK_DEBUGGING", diff --git a/lib/init-action.js b/lib/init-action.js index ba5c1e742..ac85956f0 100644 --- a/lib/init-action.js +++ b/lib/init-action.js @@ -49669,6 +49669,7 @@ var require_minimatch = __commonJS({ re += c; continue; } + if (c === "*" && stateChar === "*") continue; self2.debug("call clearStateChar %j", stateChar); clearStateChar(); stateChar = c; @@ -103609,30 +103610,32 @@ function joinAtMost(array, separator, limit) { } return array.join(separator); } -var Result = class _Result { - constructor(_ok, value) { - this._ok = _ok; +var Success = class { + constructor(value) { this.value = value; } - /** Creates a success result. */ - static success(value) { - return new _Result(true, value); - } - /** Creates a failure result. */ - static failure(value) { - return new _Result(false, value); - } - /** Whether this result represents a success. */ isSuccess() { - return this._ok; + return true; } - /** Whether this result represents a failure. */ isFailure() { - return !this._ok; + return false; + } + orElse(_defaultValue) { + return this.value; + } +}; +var Failure = class { + constructor(value) { + this.value = value; + } + isSuccess() { + return false; + } + isFailure() { + return true; } - /** Get the value if this is a success, or return the default value if this is a failure. */ orElse(defaultValue) { - return this.isSuccess() ? this.value : defaultValue; + return defaultValue; } }; @@ -105246,11 +105249,6 @@ var featureConfig = { envVar: "CODEQL_ACTION_IGNORE_GENERATED_FILES", minimumVersion: void 0 }, - ["improved_proxy_certificates" /* ImprovedProxyCertificates */]: { - defaultValue: false, - envVar: "CODEQL_ACTION_IMPROVED_PROXY_CERTIFICATES", - minimumVersion: void 0 - }, ["java_network_debugging" /* JavaNetworkDebugging */]: { defaultValue: false, envVar: "CODEQL_ACTION_JAVA_NETWORK_DEBUGGING", @@ -109864,23 +109862,23 @@ async function loadRepositoryProperties(repositoryNwo, gitHubVersion, features, logger.debug( "Skipping loading repository properties because the repository is owned by a user and therefore cannot have repository properties." ); - return Result.success({}); + return new Success({}); } if (!await features.getValue("use_repository_properties_v2" /* UseRepositoryProperties */)) { logger.debug( "Skipping loading repository properties because the UseRepositoryProperties feature flag is disabled." ); - return Result.success({}); + return new Success({}); } try { - return Result.success( + return new Success( await loadPropertiesFromApi(gitHubVersion, logger, repositoryNwo) ); } catch (error3) { logger.warning( `Failed to load repository properties: ${getErrorMessage(error3)}` ); - return Result.failure(error3); + return new Failure(error3); } } function getTrapCachingEnabled() { diff --git a/lib/resolve-environment-action.js b/lib/resolve-environment-action.js index ad7b6c8ec..4dbf739db 100644 --- a/lib/resolve-environment-action.js +++ b/lib/resolve-environment-action.js @@ -49518,6 +49518,7 @@ var require_minimatch = __commonJS({ re += c; continue; } + if (c === "*" && stateChar === "*") continue; self2.debug("call clearStateChar %j", stateChar); clearStateChar(); stateChar = c; @@ -103993,11 +103994,6 @@ var featureConfig = { envVar: "CODEQL_ACTION_IGNORE_GENERATED_FILES", minimumVersion: void 0 }, - ["improved_proxy_certificates" /* ImprovedProxyCertificates */]: { - defaultValue: false, - envVar: "CODEQL_ACTION_IMPROVED_PROXY_CERTIFICATES", - minimumVersion: void 0 - }, ["java_network_debugging" /* JavaNetworkDebugging */]: { defaultValue: false, envVar: "CODEQL_ACTION_JAVA_NETWORK_DEBUGGING", diff --git a/lib/setup-codeql-action.js b/lib/setup-codeql-action.js index 099e162ae..97e858030 100644 --- a/lib/setup-codeql-action.js +++ b/lib/setup-codeql-action.js @@ -48221,6 +48221,7 @@ var require_minimatch = __commonJS({ re += c; continue; } + if (c === "*" && stateChar === "*") continue; self2.debug("call clearStateChar %j", stateChar); clearStateChar(); stateChar = c; @@ -103890,11 +103891,6 @@ var featureConfig = { envVar: "CODEQL_ACTION_IGNORE_GENERATED_FILES", minimumVersion: void 0 }, - ["improved_proxy_certificates" /* ImprovedProxyCertificates */]: { - defaultValue: false, - envVar: "CODEQL_ACTION_IMPROVED_PROXY_CERTIFICATES", - minimumVersion: void 0 - }, ["java_network_debugging" /* JavaNetworkDebugging */]: { defaultValue: false, envVar: "CODEQL_ACTION_JAVA_NETWORK_DEBUGGING", diff --git a/lib/start-proxy-action-post.js b/lib/start-proxy-action-post.js index 78a4ed2a8..0aa8fbd35 100644 --- a/lib/start-proxy-action-post.js +++ b/lib/start-proxy-action-post.js @@ -49518,6 +49518,7 @@ var require_minimatch = __commonJS({ re += c; continue; } + if (c === "*" && stateChar === "*") continue; self2.debug("call clearStateChar %j", stateChar); clearStateChar(); stateChar = c; @@ -102209,6 +102210,7 @@ var require_minimatch2 = __commonJS({ re += c; continue; } + if (c === "*" && stateChar === "*") continue; this.debug("call clearStateChar %j", stateChar); clearStateChar(); stateChar = c; @@ -115035,9 +115037,9 @@ var require_isPlainObject = __commonJS({ } }); -// node_modules/@isaacs/balanced-match/dist/commonjs/index.js +// node_modules/glob/node_modules/balanced-match/dist/commonjs/index.js var require_commonjs18 = __commonJS({ - "node_modules/@isaacs/balanced-match/dist/commonjs/index.js"(exports2) { + "node_modules/glob/node_modules/balanced-match/dist/commonjs/index.js"(exports2) { "use strict"; Object.defineProperty(exports2, "__esModule", { value: true }); exports2.range = exports2.balanced = void 0; @@ -115097,9 +115099,9 @@ var require_commonjs18 = __commonJS({ } }); -// node_modules/@isaacs/brace-expansion/dist/commonjs/index.js +// node_modules/glob/node_modules/brace-expansion/dist/commonjs/index.js var require_commonjs19 = __commonJS({ - "node_modules/@isaacs/brace-expansion/dist/commonjs/index.js"(exports2) { + "node_modules/glob/node_modules/brace-expansion/dist/commonjs/index.js"(exports2) { "use strict"; Object.defineProperty(exports2, "__esModule", { value: true }); exports2.EXPANSION_MAX = void 0; @@ -115860,6 +115862,7 @@ var require_ast = __commonJS({ let escaping = false; let re = ""; let uflag = false; + let inStar = false; for (let i = 0; i < glob2.length; i++) { const c = glob2.charAt(i); if (escaping) { @@ -115867,6 +115870,16 @@ var require_ast = __commonJS({ re += (reSpecials.has(c) ? "\\" : "") + c; continue; } + if (c === "*") { + if (inStar) + continue; + inStar = true; + re += noEmpty && /^[*]+$/.test(glob2) ? starNoEmpty : star; + hasMagic = true; + continue; + } else { + inStar = false; + } if (c === "\\") { if (i === glob2.length - 1) { re += "\\\\"; @@ -115885,11 +115898,6 @@ var require_ast = __commonJS({ continue; } } - if (c === "*") { - re += noEmpty && glob2 === "*" ? starNoEmpty : star; - hasMagic = true; - continue; - } if (c === "?") { re += qmark; hasMagic = true; @@ -116049,7 +116057,7 @@ var require_commonjs20 = __commonJS({ if (options.nobrace || !/\{(?:(?!\{).)*\}/.test(pattern)) { return [pattern]; } - return (0, brace_expansion_1.expand)(pattern); + return (0, brace_expansion_1.expand)(pattern, { max: options.braceExpandMax }); }; exports2.braceExpand = braceExpand; exports2.minimatch.braceExpand = exports2.braceExpand; @@ -116093,7 +116101,8 @@ var require_commonjs20 = __commonJS({ this.pattern = pattern; this.platform = options.platform || defaultPlatform; this.isWindows = this.platform === "win32"; - this.windowsPathsNoEscape = !!options.windowsPathsNoEscape || options.allowWindowsEscape === false; + const awe = "allowWindowsEscape"; + this.windowsPathsNoEscape = !!options.windowsPathsNoEscape || options[awe] === false; if (this.windowsPathsNoEscape) { this.pattern = this.pattern.replace(/\\/g, "/"); } @@ -116150,7 +116159,10 @@ var require_commonjs20 = __commonJS({ const isUNC = s[0] === "" && s[1] === "" && (s[2] === "?" || !globMagic.test(s[2])) && !globMagic.test(s[3]); const isDrive = /^[a-z]:/i.test(s[0]); if (isUNC) { - return [...s.slice(0, 4), ...s.slice(4).map((ss) => this.parse(ss))]; + return [ + ...s.slice(0, 4), + ...s.slice(4).map((ss) => this.parse(ss)) + ]; } else if (isDrive) { return [s[0], ...s.slice(1).map((ss) => this.parse(ss))]; } @@ -116431,7 +116443,10 @@ var require_commonjs20 = __commonJS({ const fdi = fileUNC ? 3 : fileDrive ? 0 : void 0; const pdi = patternUNC ? 3 : patternDrive ? 0 : void 0; if (typeof fdi === "number" && typeof pdi === "number") { - const [fd, pd] = [file[fdi], pattern[pdi]]; + const [fd, pd] = [ + file[fdi], + pattern[pdi] + ]; if (fd.toLowerCase() === pd.toLowerCase()) { pattern[pdi] = fd; if (pdi > fdi) { @@ -161007,11 +161022,6 @@ var featureConfig = { envVar: "CODEQL_ACTION_IGNORE_GENERATED_FILES", minimumVersion: void 0 }, - ["improved_proxy_certificates" /* ImprovedProxyCertificates */]: { - defaultValue: false, - envVar: "CODEQL_ACTION_IMPROVED_PROXY_CERTIFICATES", - minimumVersion: void 0 - }, ["java_network_debugging" /* JavaNetworkDebugging */]: { defaultValue: false, envVar: "CODEQL_ACTION_JAVA_NETWORK_DEBUGGING", diff --git a/lib/start-proxy-action.js b/lib/start-proxy-action.js index daed18596..4d729a4a8 100644 --- a/lib/start-proxy-action.js +++ b/lib/start-proxy-action.js @@ -48221,6 +48221,7 @@ var require_minimatch = __commonJS({ re += c; continue; } + if (c === "*" && stateChar === "*") continue; self2.debug("call clearStateChar %j", stateChar); clearStateChar(); stateChar = c; @@ -120682,11 +120683,6 @@ var featureConfig = { envVar: "CODEQL_ACTION_IGNORE_GENERATED_FILES", minimumVersion: void 0 }, - ["improved_proxy_certificates" /* ImprovedProxyCertificates */]: { - defaultValue: false, - envVar: "CODEQL_ACTION_IMPROVED_PROXY_CERTIFICATES", - minimumVersion: void 0 - }, ["java_network_debugging" /* JavaNetworkDebugging */]: { defaultValue: false, envVar: "CODEQL_ACTION_JAVA_NETWORK_DEBUGGING", @@ -121850,7 +121846,8 @@ var CERT_SUBJECT = [ value: "San Francisco" } ]; -var extraExtensions = [ +var allExtensions = [ + { name: "basicConstraints", cA: true }, { name: "keyUsage", critical: true, @@ -121861,7 +121858,7 @@ var extraExtensions = [ { name: "subjectKeyIdentifier" }, { name: "authorityKeyIdentifier", keyIdentifier: true } ]; -function generateCertificateAuthority(newCertGenFF) { +function generateCertificateAuthority() { const keys = import_node_forge.pki.rsa.generateKeyPair(KEY_SIZE); const cert = import_node_forge.pki.createCertificate(); cert.publicKey = keys.publicKey; @@ -121873,16 +121870,8 @@ function generateCertificateAuthority(newCertGenFF) { ); cert.setSubject(CERT_SUBJECT); cert.setIssuer(CERT_SUBJECT); - const extensions = [{ name: "basicConstraints", cA: true }]; - if (newCertGenFF) { - extensions.push(...extraExtensions); - } - cert.setExtensions(extensions); - if (newCertGenFF) { - cert.sign(keys.privateKey, import_node_forge.md.sha256.create()); - } else { - cert.sign(keys.privateKey); - } + cert.setExtensions(allExtensions); + cert.sign(keys.privateKey, import_node_forge.md.sha256.create()); const pem = import_node_forge.pki.certificateToPem(cert); const key = import_node_forge.pki.privateKeyToPem(keys.privateKey); return { cert: pem, key }; @@ -122159,9 +122148,7 @@ async function run(startedAt) { ); } } - const ca = generateCertificateAuthority( - await features.getValue("improved_proxy_certificates" /* ImprovedProxyCertificates */) - ); + const ca = generateCertificateAuthority(); const proxyConfig = { all_credentials: credentials, ca diff --git a/lib/upload-lib.js b/lib/upload-lib.js index f66b8ce9b..83be5e0fc 100644 --- a/lib/upload-lib.js +++ b/lib/upload-lib.js @@ -49518,6 +49518,7 @@ var require_minimatch = __commonJS({ re += c; continue; } + if (c === "*" && stateChar === "*") continue; self2.debug("call clearStateChar %j", stateChar); clearStateChar(); stateChar = c; @@ -107161,11 +107162,6 @@ var featureConfig = { envVar: "CODEQL_ACTION_IGNORE_GENERATED_FILES", minimumVersion: void 0 }, - ["improved_proxy_certificates" /* ImprovedProxyCertificates */]: { - defaultValue: false, - envVar: "CODEQL_ACTION_IMPROVED_PROXY_CERTIFICATES", - minimumVersion: void 0 - }, ["java_network_debugging" /* JavaNetworkDebugging */]: { defaultValue: false, envVar: "CODEQL_ACTION_JAVA_NETWORK_DEBUGGING", diff --git a/lib/upload-sarif-action-post.js b/lib/upload-sarif-action-post.js index 4e0869c70..7368fb23c 100644 --- a/lib/upload-sarif-action-post.js +++ b/lib/upload-sarif-action-post.js @@ -94492,6 +94492,7 @@ var require_minimatch = __commonJS({ re += c; continue; } + if (c === "*" && stateChar === "*") continue; this.debug("call clearStateChar %j", stateChar); clearStateChar(); stateChar = c; @@ -107318,9 +107319,9 @@ var require_isPlainObject = __commonJS({ } }); -// node_modules/@isaacs/balanced-match/dist/commonjs/index.js +// node_modules/glob/node_modules/balanced-match/dist/commonjs/index.js var require_commonjs18 = __commonJS({ - "node_modules/@isaacs/balanced-match/dist/commonjs/index.js"(exports2) { + "node_modules/glob/node_modules/balanced-match/dist/commonjs/index.js"(exports2) { "use strict"; Object.defineProperty(exports2, "__esModule", { value: true }); exports2.range = exports2.balanced = void 0; @@ -107380,9 +107381,9 @@ var require_commonjs18 = __commonJS({ } }); -// node_modules/@isaacs/brace-expansion/dist/commonjs/index.js +// node_modules/glob/node_modules/brace-expansion/dist/commonjs/index.js var require_commonjs19 = __commonJS({ - "node_modules/@isaacs/brace-expansion/dist/commonjs/index.js"(exports2) { + "node_modules/glob/node_modules/brace-expansion/dist/commonjs/index.js"(exports2) { "use strict"; Object.defineProperty(exports2, "__esModule", { value: true }); exports2.EXPANSION_MAX = void 0; @@ -108143,6 +108144,7 @@ var require_ast = __commonJS({ let escaping = false; let re = ""; let uflag = false; + let inStar = false; for (let i = 0; i < glob2.length; i++) { const c = glob2.charAt(i); if (escaping) { @@ -108150,6 +108152,16 @@ var require_ast = __commonJS({ re += (reSpecials.has(c) ? "\\" : "") + c; continue; } + if (c === "*") { + if (inStar) + continue; + inStar = true; + re += noEmpty && /^[*]+$/.test(glob2) ? starNoEmpty : star; + hasMagic = true; + continue; + } else { + inStar = false; + } if (c === "\\") { if (i === glob2.length - 1) { re += "\\\\"; @@ -108168,11 +108180,6 @@ var require_ast = __commonJS({ continue; } } - if (c === "*") { - re += noEmpty && glob2 === "*" ? starNoEmpty : star; - hasMagic = true; - continue; - } if (c === "?") { re += qmark; hasMagic = true; @@ -108332,7 +108339,7 @@ var require_commonjs20 = __commonJS({ if (options.nobrace || !/\{(?:(?!\{).)*\}/.test(pattern)) { return [pattern]; } - return (0, brace_expansion_1.expand)(pattern); + return (0, brace_expansion_1.expand)(pattern, { max: options.braceExpandMax }); }; exports2.braceExpand = braceExpand; exports2.minimatch.braceExpand = exports2.braceExpand; @@ -108376,7 +108383,8 @@ var require_commonjs20 = __commonJS({ this.pattern = pattern; this.platform = options.platform || defaultPlatform; this.isWindows = this.platform === "win32"; - this.windowsPathsNoEscape = !!options.windowsPathsNoEscape || options.allowWindowsEscape === false; + const awe = "allowWindowsEscape"; + this.windowsPathsNoEscape = !!options.windowsPathsNoEscape || options[awe] === false; if (this.windowsPathsNoEscape) { this.pattern = this.pattern.replace(/\\/g, "/"); } @@ -108433,7 +108441,10 @@ var require_commonjs20 = __commonJS({ const isUNC = s[0] === "" && s[1] === "" && (s[2] === "?" || !globMagic.test(s[2])) && !globMagic.test(s[3]); const isDrive = /^[a-z]:/i.test(s[0]); if (isUNC) { - return [...s.slice(0, 4), ...s.slice(4).map((ss) => this.parse(ss))]; + return [ + ...s.slice(0, 4), + ...s.slice(4).map((ss) => this.parse(ss)) + ]; } else if (isDrive) { return [s[0], ...s.slice(1).map((ss) => this.parse(ss))]; } @@ -108714,7 +108725,10 @@ var require_commonjs20 = __commonJS({ const fdi = fileUNC ? 3 : fileDrive ? 0 : void 0; const pdi = patternUNC ? 3 : patternDrive ? 0 : void 0; if (typeof fdi === "number" && typeof pdi === "number") { - const [fd, pd] = [file[fdi], pattern[pdi]]; + const [fd, pd] = [ + file[fdi], + pattern[pdi] + ]; if (fd.toLowerCase() === pd.toLowerCase()) { pattern[pdi] = fd; if (pdi > fdi) { @@ -150931,6 +150945,7 @@ var require_minimatch2 = __commonJS({ re += c; continue; } + if (c === "*" && stateChar === "*") continue; self2.debug("call clearStateChar %j", stateChar); clearStateChar(); stateChar = c; @@ -161169,11 +161184,6 @@ var featureConfig = { envVar: "CODEQL_ACTION_IGNORE_GENERATED_FILES", minimumVersion: void 0 }, - ["improved_proxy_certificates" /* ImprovedProxyCertificates */]: { - defaultValue: false, - envVar: "CODEQL_ACTION_IMPROVED_PROXY_CERTIFICATES", - minimumVersion: void 0 - }, ["java_network_debugging" /* JavaNetworkDebugging */]: { defaultValue: false, envVar: "CODEQL_ACTION_JAVA_NETWORK_DEBUGGING", diff --git a/lib/upload-sarif-action.js b/lib/upload-sarif-action.js index 64189de33..4cacc4ae9 100644 --- a/lib/upload-sarif-action.js +++ b/lib/upload-sarif-action.js @@ -48221,6 +48221,7 @@ var require_minimatch = __commonJS({ re += c; continue; } + if (c === "*" && stateChar === "*") continue; self2.debug("call clearStateChar %j", stateChar); clearStateChar(); stateChar = c; @@ -106874,11 +106875,6 @@ var featureConfig = { envVar: "CODEQL_ACTION_IGNORE_GENERATED_FILES", minimumVersion: void 0 }, - ["improved_proxy_certificates" /* ImprovedProxyCertificates */]: { - defaultValue: false, - envVar: "CODEQL_ACTION_IMPROVED_PROXY_CERTIFICATES", - minimumVersion: void 0 - }, ["java_network_debugging" /* JavaNetworkDebugging */]: { defaultValue: false, envVar: "CODEQL_ACTION_JAVA_NETWORK_DEBUGGING", diff --git a/package-lock.json b/package-lock.json index 89e11fc2d..203901544 100644 --- a/package-lock.json +++ b/package-lock.json @@ -1607,27 +1607,6 @@ "url": "https://github.com/sponsors/nzakas" } }, - "node_modules/@isaacs/balanced-match": { - "version": "4.0.1", - "resolved": "https://registry.npmjs.org/@isaacs/balanced-match/-/balanced-match-4.0.1.tgz", - "integrity": "sha512-yzMTt9lEb8Gv7zRioUilSglI0c0smZ9k5D65677DLWLtWJaXIS3CqcGyUFByYKlnUj6TkjLVs54fBl6+TiGQDQ==", - "license": "MIT", - "engines": { - "node": "20 || >=22" - } - }, - "node_modules/@isaacs/brace-expansion": { - "version": "5.0.1", - "resolved": "https://registry.npmjs.org/@isaacs/brace-expansion/-/brace-expansion-5.0.1.tgz", - "integrity": "sha512-WMz71T1JS624nWj2n2fnYAuPovhv7EUhk69R6i9dsVyzxt5eM3bjwvgk9L+APE1TRscGysAVMANkB0jh0LQZrQ==", - "license": "MIT", - "dependencies": { - "@isaacs/balanced-match": "^4.0.1" - }, - "engines": { - "node": "20 || >=22" - } - }, "node_modules/@isaacs/cliui": { "version": "8.0.2", "resolved": "https://registry.npmjs.org/@isaacs/cliui/-/cliui-8.0.2.tgz", @@ -2807,14 +2786,27 @@ "typescript": ">=4.8.4 <6.0.0" } }, + "node_modules/@typescript-eslint/typescript-estree/node_modules/balanced-match": { + "version": "4.0.4", + "resolved": "https://registry.npmjs.org/balanced-match/-/balanced-match-4.0.4.tgz", + "integrity": "sha512-BLrgEcRTwX2o6gGxGOCNyMvGSp35YofuYzw9h1IMTRmKqttAZZVU67bdb9Pr2vUHA8+j3i2tJfjO6C6+4myGTA==", + "dev": true, + "license": "MIT", + "engines": { + "node": "18 || 20 || >=22" + } + }, "node_modules/@typescript-eslint/typescript-estree/node_modules/brace-expansion": { - "version": "2.0.2", - "resolved": "https://registry.npmjs.org/brace-expansion/-/brace-expansion-2.0.2.tgz", - "integrity": "sha512-Jt0vHyM+jmUBqojB7E1NIYadt0vI0Qxjxd2TErW94wDz+E2LAm5vKMXXwg6ZZBTHPuUlDgQHKXvjGBdfcF1ZDQ==", + "version": "5.0.3", + "resolved": "https://registry.npmjs.org/brace-expansion/-/brace-expansion-5.0.3.tgz", + "integrity": "sha512-fy6KJm2RawA5RcHkLa1z/ScpBeA762UF9KmZQxwIbDtRJrgLzM10depAiEQ+CXYcoiqW1/m96OAAoke2nE9EeA==", "dev": true, "license": "MIT", "dependencies": { - "balanced-match": "^1.0.0" + "balanced-match": "^4.0.2" + }, + "engines": { + "node": "18 || 20 || >=22" } }, "node_modules/@typescript-eslint/typescript-estree/node_modules/debug": { @@ -2836,13 +2828,13 @@ } }, "node_modules/@typescript-eslint/typescript-estree/node_modules/minimatch": { - "version": "9.0.5", - "resolved": "https://registry.npmjs.org/minimatch/-/minimatch-9.0.5.tgz", - "integrity": "sha512-G6T0ZX48xgozx7587koeX9Ys2NYy6Gmv//P89sEte9V9whIapMNF4idKxnW2QtCcLiTWlb/wfCabAtAFWhhBow==", + "version": "9.0.6", + "resolved": "https://registry.npmjs.org/minimatch/-/minimatch-9.0.6.tgz", + "integrity": "sha512-kQAVowdR33euIqeA0+VZTDqU+qo1IeVY+hrKYtZMio3Pg0P0vuh/kwRylLUddJhB6pf3q/botcOvRtx4IN1wqQ==", "dev": true, "license": "ISC", "dependencies": { - "brace-expansion": "^2.0.1" + "brace-expansion": "^5.0.2" }, "engines": { "node": ">=16 || 14 >=14.17" @@ -6010,16 +6002,37 @@ "node": ">= 6" } }, - "node_modules/glob/node_modules/minimatch": { - "version": "10.1.1", - "resolved": "https://registry.npmjs.org/minimatch/-/minimatch-10.1.1.tgz", - "integrity": "sha512-enIvLvRAFZYXJzkCYG5RKmPfrFArdLv+R+lbQ53BmIMLIry74bjKzX6iHAm8WYamJkhSSEabrWN5D97XnKObjQ==", - "license": "BlueOak-1.0.0", + "node_modules/glob/node_modules/balanced-match": { + "version": "4.0.4", + "resolved": "https://registry.npmjs.org/balanced-match/-/balanced-match-4.0.4.tgz", + "integrity": "sha512-BLrgEcRTwX2o6gGxGOCNyMvGSp35YofuYzw9h1IMTRmKqttAZZVU67bdb9Pr2vUHA8+j3i2tJfjO6C6+4myGTA==", + "license": "MIT", + "engines": { + "node": "18 || 20 || >=22" + } + }, + "node_modules/glob/node_modules/brace-expansion": { + "version": "5.0.3", + "resolved": "https://registry.npmjs.org/brace-expansion/-/brace-expansion-5.0.3.tgz", + "integrity": "sha512-fy6KJm2RawA5RcHkLa1z/ScpBeA762UF9KmZQxwIbDtRJrgLzM10depAiEQ+CXYcoiqW1/m96OAAoke2nE9EeA==", + "license": "MIT", "dependencies": { - "@isaacs/brace-expansion": "^5.0.0" + "balanced-match": "^4.0.2" }, "engines": { - "node": "20 || >=22" + "node": "18 || 20 || >=22" + } + }, + "node_modules/glob/node_modules/minimatch": { + "version": "10.2.2", + "resolved": "https://registry.npmjs.org/minimatch/-/minimatch-10.2.2.tgz", + "integrity": "sha512-+G4CpNBxa5MprY+04MbgOw1v7So6n5JY166pFi9KfYwT78fxScCeSNQSNzp6dpPSW2rONOps6Ocam1wFhCgoVw==", + "license": "BlueOak-1.0.0", + "dependencies": { + "brace-expansion": "^5.0.2" + }, + "engines": { + "node": "18 || 20 || >=22" }, "funding": { "url": "https://github.com/sponsors/isaacs" @@ -7227,7 +7240,9 @@ } }, "node_modules/minimatch": { - "version": "3.1.2", + "version": "3.1.3", + "resolved": "https://registry.npmjs.org/minimatch/-/minimatch-3.1.3.tgz", + "integrity": "sha512-M2GCs7Vk83NxkUyQV1bkABc4yxgz9kILhHImZiBPAZ9ybuvCb0/H7lEl5XvIg3g+9d4eNotkZA5IWwYl0tibaA==", "license": "ISC", "dependencies": { "brace-expansion": "^1.1.7" @@ -7913,9 +7928,9 @@ } }, "node_modules/readdir-glob/node_modules/minimatch": { - "version": "5.1.6", - "resolved": "https://registry.npmjs.org/minimatch/-/minimatch-5.1.6.tgz", - "integrity": "sha512-lKwV/1brpG6mBUFHtb7NUmtABCb2WZZmm2wNiOA5hAb8VdCS4B3dtMWyvcoViccwAW/COERjXLt0zP1zXUN26g==", + "version": "5.1.7", + "resolved": "https://registry.npmjs.org/minimatch/-/minimatch-5.1.7.tgz", + "integrity": "sha512-FjiwU9HaHW6YB3H4a1sFudnv93lvydNjz2lmyUXR6IwKhGI+bgL3SOZrBGn6kvvX2pJvhEkGSGjyTHN47O4rqA==", "license": "ISC", "dependencies": { "brace-expansion": "^2.0.1" diff --git a/src/feature-flags.ts b/src/feature-flags.ts index f0b08734a..6155950a4 100644 --- a/src/feature-flags.ts +++ b/src/feature-flags.ts @@ -47,7 +47,6 @@ export enum Feature { ExportDiagnosticsEnabled = "export_diagnostics_enabled", ForceNightly = "force_nightly", IgnoreGeneratedFiles = "ignore_generated_files", - ImprovedProxyCertificates = "improved_proxy_certificates", JavaNetworkDebugging = "java_network_debugging", OverlayAnalysis = "overlay_analysis", OverlayAnalysisActions = "overlay_analysis_actions", @@ -177,11 +176,6 @@ export const featureConfig = { envVar: "CODEQL_ACTION_IGNORE_GENERATED_FILES", minimumVersion: undefined, }, - [Feature.ImprovedProxyCertificates]: { - defaultValue: false, - envVar: "CODEQL_ACTION_IMPROVED_PROXY_CERTIFICATES", - minimumVersion: undefined, - }, [Feature.JavaNetworkDebugging]: { defaultValue: false, envVar: "CODEQL_ACTION_JAVA_NETWORK_DEBUGGING", diff --git a/src/init-action.ts b/src/init-action.ts index 8234ecd38..7bd749e82 100644 --- a/src/init-action.ts +++ b/src/init-action.ts @@ -96,6 +96,8 @@ import { GitHubVersion, Result, getOptionalEnvVar, + Success, + Failure, } from "./util"; import { checkWorkflow } from "./workflow"; @@ -834,25 +836,25 @@ async function loadRepositoryProperties( "Skipping loading repository properties because the repository is owned by a user and " + "therefore cannot have repository properties.", ); - return Result.success({}); + return new Success({}); } if (!(await features.getValue(Feature.UseRepositoryProperties))) { logger.debug( "Skipping loading repository properties because the UseRepositoryProperties feature flag is disabled.", ); - return Result.success({}); + return new Success({}); } try { - return Result.success( + return new Success( await loadPropertiesFromApi(gitHubVersion, logger, repositoryNwo), ); } catch (error) { logger.warning( `Failed to load repository properties: ${getErrorMessage(error)}`, ); - return Result.failure(error); + return new Failure(error); } } diff --git a/src/start-proxy-action.ts b/src/start-proxy-action.ts index 9ff0f8529..f95a16999 100644 --- a/src/start-proxy-action.ts +++ b/src/start-proxy-action.ts @@ -90,9 +90,7 @@ async function run(startedAt: Date) { } } - const ca = generateCertificateAuthority( - await features.getValue(Feature.ImprovedProxyCertificates), - ); + const ca = generateCertificateAuthority(); const proxyConfig: ProxyConfig = { all_credentials: credentials, diff --git a/src/start-proxy/ca.test.ts b/src/start-proxy/ca.test.ts index ae4e22e9a..7b88fc54b 100644 --- a/src/start-proxy/ca.test.ts +++ b/src/start-proxy/ca.test.ts @@ -32,33 +32,7 @@ function checkCertAttributes( } test("generateCertificateAuthority - generates certificates", (t) => { - const result = ca.generateCertificateAuthority(false); - const cert = pki.certificateFromPem(result.cert); - const key = pki.privateKeyFromPem(result.key); - - t.truthy(cert); - t.truthy(key); - - checkCertAttributes(t, cert); - - // Check the validity. - t.true( - cert.validity.notBefore <= new Date(), - "notBefore date is in the future", - ); - t.true(cert.validity.notAfter > new Date(), "notAfter date is in the past"); - - // Check that the extensions are set as we'd expect. - const exts = cert.extensions as ca.Extension[]; - t.is(exts.length, 1); - t.is(exts[0].name, "basicConstraints"); - t.is(exts[0].cA, true); - - t.truthy(cert.siginfo); -}); - -test("generateCertificateAuthority - generates certificates with FF", (t) => { - const result = ca.generateCertificateAuthority(true); + const result = ca.generateCertificateAuthority(); const cert = pki.certificateFromPem(result.cert); const key = pki.privateKeyFromPem(result.key); diff --git a/src/start-proxy/ca.ts b/src/start-proxy/ca.ts index 80d976f7b..8f9b8de13 100644 --- a/src/start-proxy/ca.ts +++ b/src/start-proxy/ca.ts @@ -37,7 +37,8 @@ export type Extension = { [key: string]: unknown; }; -const extraExtensions: Extension[] = [ +const allExtensions: Extension[] = [ + { name: "basicConstraints", cA: true }, { name: "keyUsage", critical: true, @@ -52,12 +53,9 @@ const extraExtensions: Extension[] = [ /** * Generates a CA certificate for the proxy. * - * @param newCertGenFF Whether to use the updated certificate generation. * @returns The private and public keys. */ -export function generateCertificateAuthority( - newCertGenFF: boolean, -): CertificateAuthority { +export function generateCertificateAuthority(): CertificateAuthority { const keys = pki.rsa.generateKeyPair(KEY_SIZE); const cert = pki.createCertificate(); cert.publicKey = keys.publicKey; @@ -71,21 +69,11 @@ export function generateCertificateAuthority( cert.setSubject(CERT_SUBJECT); cert.setIssuer(CERT_SUBJECT); - const extensions: Extension[] = [{ name: "basicConstraints", cA: true }]; + // Set the CA extensions for the certificate. + cert.setExtensions(allExtensions); - // Add the extra CA extensions if the FF is enabled. - if (newCertGenFF) { - extensions.push(...extraExtensions); - } - - cert.setExtensions(extensions); - - // Specifically use SHA256 when the FF is enabled. - if (newCertGenFF) { - cert.sign(keys.privateKey, md.sha256.create()); - } else { - cert.sign(keys.privateKey); - } + // Specifically use SHA256 to ensure consistency and compatibility. + cert.sign(keys.privateKey, md.sha256.create()); const pem = pki.certificateToPem(cert); const key = pki.privateKeyToPem(keys.privateKey); diff --git a/src/util.test.ts b/src/util.test.ts index 4d3121cf1..7b6850018 100644 --- a/src/util.test.ts +++ b/src/util.test.ts @@ -564,27 +564,27 @@ test("joinAtMost - truncates list if array is > than limit", (t) => { t.false(result.includes("test6")); }); -test("Result.success creates a success result", (t) => { - const result = util.Result.success("test value"); +test("Success creates a success result", (t) => { + const result = new util.Success("test value"); t.true(result.isSuccess()); t.false(result.isFailure()); t.is(result.value, "test value"); }); -test("Result.failure creates a failure result", (t) => { +test("Failure creates a failure result", (t) => { const error = new Error("test error"); - const result = util.Result.failure(error); + const result = new util.Failure(error); t.false(result.isSuccess()); t.true(result.isFailure()); t.is(result.value, error); }); -test("Result.orElse returns the value for a success result", (t) => { - const result = util.Result.success("success value"); +test("Success.orElse returns the value for a success result", (t) => { + const result = new util.Success("success value"); t.is(result.orElse("default value"), "success value"); }); -test("Result.orElse returns the default value for a failure result", (t) => { - const result = util.Result.failure(new Error("test error")); +test("Failure.orElse returns the default value for a failure result", (t) => { + const result = new util.Failure(new Error("test error")); t.is(result.orElse("default value"), "default value"); }); diff --git a/src/util.ts b/src/util.ts index bc5f02f00..823291a0a 100644 --- a/src/util.ts +++ b/src/util.ts @@ -1292,42 +1292,51 @@ export function joinAtMost( return array.join(separator); } -/** A success result. */ -type Success = Result; -/** A failure result. */ -type Failure = Result; - -/** - * A simple result type representing either a success or a failure. - */ -export class Result { - private constructor( - private readonly _ok: boolean, - public readonly value: T | E, - ) {} - - /** Creates a success result. */ - static success(value: T): Success { - return new Result(true, value) as Success; - } - - /** Creates a failure result. */ - static failure(value: E): Failure { - return new Result(false, value) as Failure; - } - +/** An interface representing something that is either a success or a failure. */ +interface ResultLike { + /** The value of the result, which can be either a success value or a failure value. */ + value: T | E; /** Whether this result represents a success. */ - isSuccess(): this is Success { - return this._ok; - } - + isSuccess(): this is Success; /** Whether this result represents a failure. */ - isFailure(): this is Failure { - return !this._ok; + isFailure(): this is Failure; + /** Get the value if this is a success, or return the default value if this is a failure. */ + orElse(defaultValue: U): T | U; +} + +/** A simple result type representing either a success or a failure. */ +export type Result = Success | Failure; + +/** A result representing a success. */ +export class Success implements ResultLike { + constructor(public readonly value: T) {} + + isSuccess(): this is Success { + return true; } - /** Get the value if this is a success, or return the default value if this is a failure. */ - orElse(defaultValue: U): T | U { - return this.isSuccess() ? this.value : defaultValue; + isFailure(): this is Failure { + return false; + } + + orElse(_defaultValue: U): T { + return this.value; + } +} + +/** A result representing a failure. */ +export class Failure implements ResultLike { + constructor(public readonly value: E) {} + + isSuccess(): this is Success { + return false; + } + + isFailure(): this is Failure { + return true; + } + + orElse(defaultValue: U): U { + return defaultValue; } }