@cqse/commons 1.0.0-beta.7 → 1.0.5

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
package/lib/index.cjs ADDED
@@ -0,0 +1,7 @@
1
+ var e=Object.create,t=Object.defineProperty,n=Object.getOwnPropertyDescriptor,r=Object.getOwnPropertyNames,i=Object.getPrototypeOf,a=Object.prototype.hasOwnProperty,o=(e,i,o,s)=>{if(i&&typeof i==`object`||typeof i==`function`)for(var c=r(i),l=0,u=c.length,d;l<u;l++)d=c[l],!a.call(e,d)&&d!==o&&t(e,d,{get:(e=>i[e]).bind(null,d),enumerable:!(s=n(i,d))||s.enumerable});return e},s=(n,r,a)=>(a=n==null?{}:e(i(n)),o(r||!n||!n.__esModule?t(a,`default`,{value:n,enumerable:!0}):a,n));let c=require(`node:process`);c=s(c);let l=require(`node:crypto`);var u=class extends Error{constructor(e){super(`Implement me!`),this._implementMeFor=e}get message(){return this._implementMeFor?`Implement me for: ${this._implementMeFor}`:`Implement me!`}},d=class extends Error{},f=class extends Error{},p=class extends Error{},m=class{static require(e,t){if(!e)throw new f(t)}static requireDefined(e,t){if(e||typeof e==`number`||typeof e==`boolean`||typeof e==`string`||e instanceof String)return e;throw t?new f(t):new f(`Reference must be defined.`)}static requireNonEmpty(e,t){if(this.requireDefined(e),e.length===0)throw new f(t);return e}static requireStringPattern(e,t,n){if(this.requireDefined(e),this.requireDefined(t),!e.match(t))throw new f(n);return e}};function h(e,t){return t.startsWith(e)?t.substring(e.length):t}const g={order:999,title:`Application`};function _(e){if(e.type===`int`||e.type===`string`)return 1;if(e.type===`bool`)return 0;if(e.type===`string[]`)return 1/0;throw new p(`Unsupported parameter type "${e.type}" for parameter "${e.longParameter}".`)}function v(e){return e.replace(/^-+/,``).replace(/-([a-z])/g,(e,t)=>t.toUpperCase())}function y(e){return e.replace(/^--/,``).toUpperCase().replace(/-/g,`_`)}var b=class e{constructor(){this.parameters=new Map,this.shortToLongParameterMap=new Map,this.sequentialParameters=[],this.argumentChecks=[]}addParameter(e,t,n,r={}){let i=v(t),a=y(t);this.describeParameter(i,{parameterId:i,longParameter:t,type:n,shortParameter:e,help:r.help??``,default:r.default,internal:r.internal??!1,group:r.group,environmentVariableName:a})}addArgumentCheck(e){this.argumentChecks.push(e)}addRequiredArgumentFor(e){let t=this.lookupParameter(e);if(t===void 0)throw new p(`Unknown parameter "${e}".`);if(t.default!==void 0)throw new p(`Parameter "${e}" is required, but has a default value.`);this.argumentChecks.push(n=>{if(n[e]===void 0)return`Missing required argument for parameter "${t.longParameter}"\n\tParameter description: ${t.help}`})}describeParameter(e,t){if(this.parameters.set(e,t),t.shortParameter){let n=t.shortParameter.replace(/^-/,``).trim().toLowerCase();if(n.length<1||n.length>3)throw new p(`Short parameter "${n}" is invalid.`);let r=this.shortToLongParameterMap.get(n);if(r!==void 0&&r!==e)throw new p(`Short parameter "${n}" is already mapped to parameter "${r}".`);this.shortToLongParameterMap.set(n,t.parameterId)}t.longParameter.startsWith(`--`)||this.sequentialParameters.push(e)}lookupParameter(e){let t=this.parameters.get(e);if(t===void 0){let n=this.shortToLongParameterMap.get(e);n!==void 0&&(t=this.parameters.get(n))}return t}getParameters(){return Array.from(this.parameters.values())}getArgumentChecks(){return this.argumentChecks}getSequentialParameters(){return this.sequentialParameters}clone(){let t=new e;for(let e of this.parameters.values())t.describeParameter(e.parameterId,e);for(let e of this.argumentChecks)t.addArgumentCheck(e);return t}addAllOf(e){for(let t of e.getParameters())this.describeParameter(t.parameterId,t);for(let t of e.getArgumentChecks())this.addArgumentCheck(t)}};function x(e,t){let n={},r,i=[],a=0;function o(){if(r){if(a<1/0&&a>0)throw new p(`Missing value for parameter "${r.longParameter}".`);if(r.type===`bool`)n[r.parameterId]=!0,r=void 0;else if(r.type===`string[]`){let e=n[r.parameterId],t=C(i.join(`,`));T(e)?n[r.parameterId]=e.concat(t):n[r.parameterId]=t}else{if(i.length!==1)throw new p(`Invalid value for parameter "${r.longParameter}": Expected a single value, got ${i.length}.`);n[r.parameterId]=w(i[0],r)}r=void 0,i=[]}}for(let n of e){if(n.startsWith(`-`)){o();let e=v(n);if(r=t.lookupParameter(e),!r)throw new p(`Unknown configuration parameter: ${n}`);a=_(r)}else{if(!r)throw new p(`Unexpected or unnamed argument, or unknown parameter '${n}' supplied. Please specify a parameter name (for example, --input) for each argument.`);i.push(n),a--}a===0&&o()}o();for(let e of t.getParameters())if(n[e.parameterId]===void 0){n[e.parameterId]=e.default;let t=c.default.env[e.environmentVariableName];t&&!e.disableEnvironmentVariableOverride&&(n[e.parameterId]=w(t,e))}return n}function S(e){return e=e.trim(),e.startsWith(`"`)&&e.endsWith(`"`)||e.startsWith(`'`)&&e.endsWith(`'`)||e.startsWith("`")&&e.endsWith("`")?e.substring(1,e.length-1):e}function C(e){return e?e.split(`,`).map(e=>S(e)):[]}function w(e,t){if(t.type===`int`){let n=parseInt(e,10);if(isNaN(n))throw new p(`Invalid value for parameter "${t.longParameter}": Expected an integer, got "${e}".`);return n}else if(t.type===`bool`){let n=e.toLowerCase();if(n===`true`||n===`1`)return!0;if(n===`false`||n===`0`)return!1;throw new p(`Invalid value for parameter "${t.longParameter}": Expected a boolean, got "${e}".`)}else if(t.type===`string`)return S(e);else if(t.type===`string[]`)return C(e);else throw new p(`Unsupported parameter type "${t.type}" for parameter "${t.longParameter}".`)}function T(e){return Array.isArray(e)&&e.every(e=>typeof e==`string`)}function E(e,t){let n={},r=[];for(let i of e.split(`
2
+ `)){let e=i.trim();if(e.startsWith(`#`)||e.length===0)continue;if(!e.includes(`=`)&&t.getSequentialParameters().length>0){r.push(e);continue}let[a,o]=e.split(`=`),s=v(a),c=t.lookupParameter(s);if(c)if(T(n[s])&&c.type===`string[]`){let e=w(o,c);if(T(e))n[s]=n[s].concat(e);else throw new p(`Invalid value for parameter "${c.longParameter}": Expected a list of strings, got "${o}".`)}else n[s]=w(o,c);else throw new p(`Unknown configuration parameter: ${a}`)}return{options:n,unnamedArguments:r}}function D(e,t,n=!1){let r=[];t&&(r.push(t),r.push(``)),n||r.push(`Usage:`);let i=A(e);for(let e of i){e.groupTitle&&(r.push(``),r.push(`# ${e.groupTitle}`),r.push(``)),e.groupHint&&(r.push(O(e.groupHint,80)),r.push(``));for(let t of e.parameters){if(t.internal)continue;function e(){let e=t.environmentVariableName;return t.type===`bool`?``:t.type===`string[]`?` ${e}, .., ${e}`:` ${e}`}let i=[];n?i.push(`Parameter "${t.parameterId}" (${t.type})`):(t.shortParameter&&i.push(`${t.shortParameter}${e()}`),i.push(`${t.longParameter}${e()}`));let a=k(O(t.help,80)),o=t.default?`Default: ${t.default}`:void 0;r.push(` ${i.join(`, `)}`),a&&r.push(`\t${a}`),o&&r.push(`\t${o}`)}}r.push(``),console.log(r.join(`
3
+ `))}function O(e,t){e=e.replace(/\n/g,` `);let n=e.split(` `),r=[],i=``;for(let e of n)i.length+e.length+1>t&&(r.push(i),i=``),i.length>0&&(i+=` `),i+=e;return i.length>0&&r.push(i),r.join(`
4
+ `)}function k(e){if(e)return e.replace(/\n/g,`
5
+ `)}function A(e){let t=new Map,n=new Map,r=new Map;for(let i of e.getParameters()){let e=i.group?.title;i.group&&n.set(e,i.group.order),i.group?.hints&&r.set(e,i.group?.hints);let a=t.get(e)||[];a.push(i),t.set(e,a)}return Array.from(t.entries()).sort(([e],[t])=>(n.get(e)??Number.MAX_VALUE)-(n.get(t)??Number.MAX_VALUE)).map(([e,t])=>({groupTitle:e,groupHint:r.get(e),parameters:t.sort((e,t)=>e.longParameter.localeCompare(t.longParameter))}))}function j(e,t,n){let r=!0;n||=e=>{console.error(e)};for(let i of e.getArgumentChecks()){let e=i(t);e&&(n(`Invalid configuration: `+e),r=!1)}return r}function M(e,t,n,r){n??=c.default.argv.slice(2);let i=e.clone();i.addParameter(`-h`,`--help`,`bool`,{help:`Show this help message and exit.`,group:g,disableEnvironmentVariableOverride:!0}),i.addParameter(`-v`,`--version`,`bool`,{help:`Show the version number and exit.`,group:g,disableEnvironmentVariableOverride:!0});let a=x(n,i);return a.version&&(console.log(`${t.name} v${t.version}`),c.default.exit(0)),a.help&&(D(i,t.about),c.default.exit(0)),r&&r(a),j(i,a)||(console.error(`
6
+ Arguments were missing or invalid. Please check the --help for more information. Exiting with error code 1.`),c.default.exit(1)),a}function N(e,t){let n=e.clone();return n.addAllOf(t),n}var P=class e{constructor(e,t,n,r){this.baseConfiguration=m.requireDefined(n),this.redefinableParameters=m.requireDefined(t),this.allParameters=m.requireDefined(e),this.overwrites=r??{},this.hash=void 0}get(e){return this.assertParameterExists(e),this.overwrites[e]??this.baseConfiguration[e]}set(e,t){if(this.redefinableParameters.lookupParameter(e)===void 0)throw Error(`Unknown configuration parameter: ${e}`);this.overwriteConfig(e,t),this.hash=void 0}overwriteConfig(e,t){let n=v(e);if(this.assertParameterExists(n),t===void 0){delete this.overwrites[n];return}this.overwrites[n]=this.castConfigArgument(n,t),this.hash=void 0}castConfigArgument(e,t){let n=this.getParameter(e).type;if(n===`int`){if(typeof t==`number`)return Math.floor(t);if(typeof t==`string`)return parseInt(t,10);if(typeof t==`boolean`)return t?1:0}else if(n===`bool`){if(typeof t==`boolean`)return t;if(typeof t==`string`)return t.toLowerCase()===`true`;if(typeof t==`number`)return t!==0}else if(n===`string[]`){if(t===void 0||t==null)return[];if(Array.isArray(t))return t.map(String);if(typeof t==`string`)return t.split(`,`).map(e=>e.trim())}else return String(t);throw Error(`Cannot cast value of type ${typeof t} to ${n}`)}assertParameterExists(e){if(this.allParameters.lookupParameter(e)===void 0)throw Error(`Unknown configuration parameter: ${e}`)}getParameter(e){let t=this.redefinableParameters.lookupParameter(e);if(t===void 0)throw Error(`Unknown configuration parameter: ${e}`);return t}getHash(){if(this.hash===void 0){let e=(0,l.createHash)(`sha256`);for(let[t,n]of Object.entries(this.baseConfiguration))e.update(t),e.update(String(n));for(let[t,n]of Object.entries(this.overwrites))e.update(t),e.update(String(n));this.hash=e.digest(`hex`)}return this.hash}copy(){let t=JSON.parse(JSON.stringify(this.overwrites));return new e(this.allParameters,this.redefinableParameters,this.baseConfiguration,t)}};function F(e){return new Proxy(e,{get(t,n){return e.get(n.toString())},set(t,n,r){return e.set(n.toString(),r),!0}})}const I={order:1,title:`Collector Connectivity`},L={order:1,title:`Teamscale Server`},R={order:2,title:`Upload to Teamscale`,hints:"NOTE: We generally recommend to set these parameters per app during the instrumentation process, that is, on the instrumenter side, for example, by setting `--config-id` or specifying single options via `--collector-option`. The following parameters are supposed to take effect if the application is instrumented with the `--coverage-target-from-collector` flag."},z={order:3,title:`Coverage Dumping`},B={order:4,title:`Upload to Artifactory`},V={order:5,title:`Logging Behavior`};function H(){let e=new b;function t(t,n,r,i){e.addParameter(t,n,r,i)}return t(`-k`,`--keep-coverage-files`,`bool`,{help:`Whether to keep the coverage files on disk after a successful upload to Teamscale.`,default:!1,group:z}),t(`-t`,`--dump-after-mins`,`int`,{help:`Dump the coverage information every N minutes.`,default:120,group:z}),t(void 0,`--artifactory-server-url`,`string`,{help:`Upload the coverage to the given Artifactory server URL. The URL may include a subpath on the artifactory server, e.g. https://artifactory.acme.com/my-repo/my/subpath`,group:B}),t(void 0,`--artifactory-user`,`string`,{help:`The user for uploading coverage to Artifactory. Only needed when not using the --artifactory-access-token option`,group:B}),t(void 0,`--artifactory-password`,`string`,{help:`The password for uploading coverage to Artifactory. Only needed when not using the --artifactory-access-token option`,group:B}),t(void 0,`--artifactory-access-token`,`string`,{help:`The access_token for uploading coverage to Artifactory.`,group:B}),t(void 0,`--artifactory-path-suffix`,`string`,{help:`(optional): The path within the storage location between the default path and the uploaded artifact.`,group:B}),t(void 0,`--teamscale-project`,`string`,{help:`The project ID to upload coverage to.`,group:R}),t(void 0,`--teamscale-partition`,`string`,{help:`The partition to upload coverage to.`,group:R}),t(void 0,`--teamscale-repository`,`string`,{help:`The repository to upload coverage for. Optional: Only needed when uploading via revision to a project that has more than one connector.`,group:R}),t(void 0,`--teamscale-message`,`string`,{help:`The commit message shown within Teamscale for the coverage upload.`,default:`JavaScript coverage upload`,group:R}),e}function U(){let e=H();function t(t,n,r,i){e.addParameter(t,n,r,i)}return t(`-p`,`--port`,`int`,{help:`The port to receive coverage information on.`,default:54678,group:I,disableEnvironmentVariableOverride:!0}),t(`-l`,`--log-to-file`,`string`,{help:`Log file`,default:`logs/collector-combined.log`,group:V,disableEnvironmentVariableOverride:!0}),t(`-e`,`--log-level`,`string`,{help:`Log level`,default:`info`,group:V,disableEnvironmentVariableOverride:!0}),t(`-j`,`--json-log`,`bool`,{help:`Additional JSON-like log file format.`,group:V,disableEnvironmentVariableOverride:!0}),t(`-c`,`--enable-control-port`,`int`,{help:`Enables the remote control API on the specified port (<=0 means "disabled").`,default:0,group:I}),t(`-s`,`--teamscale-server-url`,`string`,{help:`Upload the coverage to the given Teamscale server URL, for example, https://teamscale.dev.example.com:8080/production.`,group:L}),t(`-u`,`--teamscale-user`,`string`,{help:`The user for uploading coverage to Teamscale.`,group:L}),t(`-a`,`--teamscale-access-token`,`string`,{help:`The API key to use for uploading to Teamscale.`,group:L}),t(void 0,`--http-proxy`,`string`,{help:`(optional): The HTTP/HTTPS proxy address that should be used in the format: http://host:port/ or http://username:password@host:port/.`,group:I}),t(`-f`,`--dump-folder`,`string`,{help:`Target folder for coverage files.`,default:`./coverage`,group:z}),e.addArgumentCheck(e=>{if(e.teamscaleServerUrl&&(!e.teamscaleUser||!e.teamscaleAccessToken))return`The Teamscale user name and access token must be given if the Teamscale server URL is given.`}),e}function W(){let e=H();function t(t,n,r,i){e.addParameter(t,n,r,i)}function n(e,n,r){t(void 0,e,n,r)}return n(`--dump-to-folder`,`string`,{help:`Coverage should be dumped to a folder on the server that the collector is running on.
7
+ Specifies the name of the subfolder within the collector's dump folder (--dump-folder of the collector) where coverage files should be placed.`,group:z}),e}function G(e){if(typeof e==`string`){if(/^[a-zA-Z0-9_-]+:([0-9]+|HEAD|head)$/.test(e))return!0;if(/^[0-9]+$/.test(e))return!1;if(/^[a-zA-Z0-9]{7,40}$/.test(e))return!0}return!1}exports.CONFIG_GROUP_APP=g,exports.ConfigurationParameters=b,exports.ConfigurationWithOverwrites=P,exports.Contract=m,exports.IllegalArgumentException=f,exports.IllegalStateException=d,exports.ImplementMeException=u,exports.InvalidConfigurationException=p,exports.buildPredefinableParameters=H,exports.buildReconfigurableCollectorParameters=W,exports.buildStaticCollectorParameters=U,exports.checkArguments=j,exports.isValidCommitInfo=G,exports.longParameterToEnvironmentVariableName=y,exports.makeConfigProxy=F,exports.parameterNameToParameterId=v,exports.parameterUnion=N,exports.parseArguments=x,exports.parseConfigFile=E,exports.printHelp=D,exports.processCommandLine=M,exports.removePrefix=h;
package/lib/index.mjs ADDED
@@ -0,0 +1,8 @@
1
+ import e from"node:process";import{createHash as t}from"node:crypto";var n=class extends Error{constructor(e){super(`Implement me!`),this._implementMeFor=e}get message(){return this._implementMeFor?`Implement me for: ${this._implementMeFor}`:`Implement me!`}},r=class extends Error{},i=class extends Error{},a=class extends Error{},o=class{static require(e,t){if(!e)throw new i(t)}static requireDefined(e,t){if(e||typeof e==`number`||typeof e==`boolean`||typeof e==`string`||e instanceof String)return e;throw t?new i(t):new i(`Reference must be defined.`)}static requireNonEmpty(e,t){if(this.requireDefined(e),e.length===0)throw new i(t);return e}static requireStringPattern(e,t,n){if(this.requireDefined(e),this.requireDefined(t),!e.match(t))throw new i(n);return e}};function s(e,t){return t.startsWith(e)?t.substring(e.length):t}const c={order:999,title:`Application`};function l(e){if(e.type===`int`||e.type===`string`)return 1;if(e.type===`bool`)return 0;if(e.type===`string[]`)return 1/0;throw new a(`Unsupported parameter type "${e.type}" for parameter "${e.longParameter}".`)}function u(e){return e.replace(/^-+/,``).replace(/-([a-z])/g,(e,t)=>t.toUpperCase())}function d(e){return e.replace(/^--/,``).toUpperCase().replace(/-/g,`_`)}var f=class e{constructor(){this.parameters=new Map,this.shortToLongParameterMap=new Map,this.sequentialParameters=[],this.argumentChecks=[]}addParameter(e,t,n,r={}){let i=u(t),a=d(t);this.describeParameter(i,{parameterId:i,longParameter:t,type:n,shortParameter:e,help:r.help??``,default:r.default,internal:r.internal??!1,group:r.group,environmentVariableName:a})}addArgumentCheck(e){this.argumentChecks.push(e)}addRequiredArgumentFor(e){let t=this.lookupParameter(e);if(t===void 0)throw new a(`Unknown parameter "${e}".`);if(t.default!==void 0)throw new a(`Parameter "${e}" is required, but has a default value.`);this.argumentChecks.push(n=>{if(n[e]===void 0)return`Missing required argument for parameter "${t.longParameter}"\n\tParameter description: ${t.help}`})}describeParameter(e,t){if(this.parameters.set(e,t),t.shortParameter){let n=t.shortParameter.replace(/^-/,``).trim().toLowerCase();if(n.length<1||n.length>3)throw new a(`Short parameter "${n}" is invalid.`);let r=this.shortToLongParameterMap.get(n);if(r!==void 0&&r!==e)throw new a(`Short parameter "${n}" is already mapped to parameter "${r}".`);this.shortToLongParameterMap.set(n,t.parameterId)}t.longParameter.startsWith(`--`)||this.sequentialParameters.push(e)}lookupParameter(e){let t=this.parameters.get(e);if(t===void 0){let n=this.shortToLongParameterMap.get(e);n!==void 0&&(t=this.parameters.get(n))}return t}getParameters(){return Array.from(this.parameters.values())}getArgumentChecks(){return this.argumentChecks}getSequentialParameters(){return this.sequentialParameters}clone(){let t=new e;for(let e of this.parameters.values())t.describeParameter(e.parameterId,e);for(let e of this.argumentChecks)t.addArgumentCheck(e);return t}addAllOf(e){for(let t of e.getParameters())this.describeParameter(t.parameterId,t);for(let t of e.getArgumentChecks())this.addArgumentCheck(t)}};function p(t,n){let r={},i,o=[],s=0;function c(){if(i){if(s<1/0&&s>0)throw new a(`Missing value for parameter "${i.longParameter}".`);if(i.type===`bool`)r[i.parameterId]=!0,i=void 0;else if(i.type===`string[]`){let e=r[i.parameterId],t=h(o.join(`,`));_(e)?r[i.parameterId]=e.concat(t):r[i.parameterId]=t}else{if(o.length!==1)throw new a(`Invalid value for parameter "${i.longParameter}": Expected a single value, got ${o.length}.`);r[i.parameterId]=g(o[0],i)}i=void 0,o=[]}}for(let e of t){if(e.startsWith(`-`)){c();let t=u(e);if(i=n.lookupParameter(t),!i)throw new a(`Unknown configuration parameter: ${e}`);s=l(i)}else{if(!i)throw new a(`Unexpected or unnamed argument, or unknown parameter '${e}' supplied. Please specify a parameter name (for example, --input) for each argument.`);o.push(e),s--}s===0&&c()}c();for(let t of n.getParameters())if(r[t.parameterId]===void 0){r[t.parameterId]=t.default;let n=e.env[t.environmentVariableName];n&&!t.disableEnvironmentVariableOverride&&(r[t.parameterId]=g(n,t))}return r}function m(e){return e=e.trim(),e.startsWith(`"`)&&e.endsWith(`"`)||e.startsWith(`'`)&&e.endsWith(`'`)||e.startsWith("`")&&e.endsWith("`")?e.substring(1,e.length-1):e}function h(e){return e?e.split(`,`).map(e=>m(e)):[]}function g(e,t){if(t.type===`int`){let n=parseInt(e,10);if(isNaN(n))throw new a(`Invalid value for parameter "${t.longParameter}": Expected an integer, got "${e}".`);return n}else if(t.type===`bool`){let n=e.toLowerCase();if(n===`true`||n===`1`)return!0;if(n===`false`||n===`0`)return!1;throw new a(`Invalid value for parameter "${t.longParameter}": Expected a boolean, got "${e}".`)}else if(t.type===`string`)return m(e);else if(t.type===`string[]`)return h(e);else throw new a(`Unsupported parameter type "${t.type}" for parameter "${t.longParameter}".`)}function _(e){return Array.isArray(e)&&e.every(e=>typeof e==`string`)}function v(e,t){let n={},r=[];for(let i of e.split(`
2
+ `)){let e=i.trim();if(e.startsWith(`#`)||e.length===0)continue;if(!e.includes(`=`)&&t.getSequentialParameters().length>0){r.push(e);continue}let[o,s]=e.split(`=`),c=u(o),l=t.lookupParameter(c);if(l)if(_(n[c])&&l.type===`string[]`){let e=g(s,l);if(_(e))n[c]=n[c].concat(e);else throw new a(`Invalid value for parameter "${l.longParameter}": Expected a list of strings, got "${s}".`)}else n[c]=g(s,l);else throw new a(`Unknown configuration parameter: ${o}`)}return{options:n,unnamedArguments:r}}function y(e,t,n=!1){let r=[];t&&(r.push(t),r.push(``)),n||r.push(`Usage:`);let i=S(e);for(let e of i){e.groupTitle&&(r.push(``),r.push(`# ${e.groupTitle}`),r.push(``)),e.groupHint&&(r.push(b(e.groupHint,80)),r.push(``));for(let t of e.parameters){if(t.internal)continue;function e(){let e=t.environmentVariableName;return t.type===`bool`?``:t.type===`string[]`?` ${e}, .., ${e}`:` ${e}`}let i=[];n?i.push(`Parameter "${t.parameterId}" (${t.type})`):(t.shortParameter&&i.push(`${t.shortParameter}${e()}`),i.push(`${t.longParameter}${e()}`));let a=x(b(t.help,80)),o=t.default?`Default: ${t.default}`:void 0;r.push(` ${i.join(`, `)}`),a&&r.push(`\t${a}`),o&&r.push(`\t${o}`)}}r.push(``),console.log(r.join(`
3
+ `))}function b(e,t){e=e.replace(/\n/g,` `);let n=e.split(` `),r=[],i=``;for(let e of n)i.length+e.length+1>t&&(r.push(i),i=``),i.length>0&&(i+=` `),i+=e;return i.length>0&&r.push(i),r.join(`
4
+ `)}function x(e){if(e)return e.replace(/\n/g,`
5
+ `)}function S(e){let t=new Map,n=new Map,r=new Map;for(let i of e.getParameters()){let e=i.group?.title;i.group&&n.set(e,i.group.order),i.group?.hints&&r.set(e,i.group?.hints);let a=t.get(e)||[];a.push(i),t.set(e,a)}return Array.from(t.entries()).sort(([e],[t])=>(n.get(e)??Number.MAX_VALUE)-(n.get(t)??Number.MAX_VALUE)).map(([e,t])=>({groupTitle:e,groupHint:r.get(e),parameters:t.sort((e,t)=>e.longParameter.localeCompare(t.longParameter))}))}function C(e,t,n){let r=!0;n||=e=>{console.error(e)};for(let i of e.getArgumentChecks()){let e=i(t);e&&(n(`Invalid configuration: `+e),r=!1)}return r}function w(t,n,r,i){r??=e.argv.slice(2);let a=t.clone();a.addParameter(`-h`,`--help`,`bool`,{help:`Show this help message and exit.`,group:c,disableEnvironmentVariableOverride:!0}),a.addParameter(`-v`,`--version`,`bool`,{help:`Show the version number and exit.`,group:c,disableEnvironmentVariableOverride:!0});let o=p(r,a);return o.version&&(console.log(`${n.name} v${n.version}`),e.exit(0)),o.help&&(y(a,n.about),e.exit(0)),i&&i(o),C(a,o)||(console.error(`
6
+ Arguments were missing or invalid. Please check the --help for more information. Exiting with error code 1.`),e.exit(1)),o}function T(e,t){let n=e.clone();return n.addAllOf(t),n}var E=class e{constructor(e,t,n,r){this.baseConfiguration=o.requireDefined(n),this.redefinableParameters=o.requireDefined(t),this.allParameters=o.requireDefined(e),this.overwrites=r??{},this.hash=void 0}get(e){return this.assertParameterExists(e),this.overwrites[e]??this.baseConfiguration[e]}set(e,t){if(this.redefinableParameters.lookupParameter(e)===void 0)throw Error(`Unknown configuration parameter: ${e}`);this.overwriteConfig(e,t),this.hash=void 0}overwriteConfig(e,t){let n=u(e);if(this.assertParameterExists(n),t===void 0){delete this.overwrites[n];return}this.overwrites[n]=this.castConfigArgument(n,t),this.hash=void 0}castConfigArgument(e,t){let n=this.getParameter(e).type;if(n===`int`){if(typeof t==`number`)return Math.floor(t);if(typeof t==`string`)return parseInt(t,10);if(typeof t==`boolean`)return t?1:0}else if(n===`bool`){if(typeof t==`boolean`)return t;if(typeof t==`string`)return t.toLowerCase()===`true`;if(typeof t==`number`)return t!==0}else if(n===`string[]`){if(t===void 0||t==null)return[];if(Array.isArray(t))return t.map(String);if(typeof t==`string`)return t.split(`,`).map(e=>e.trim())}else return String(t);throw Error(`Cannot cast value of type ${typeof t} to ${n}`)}assertParameterExists(e){if(this.allParameters.lookupParameter(e)===void 0)throw Error(`Unknown configuration parameter: ${e}`)}getParameter(e){let t=this.redefinableParameters.lookupParameter(e);if(t===void 0)throw Error(`Unknown configuration parameter: ${e}`);return t}getHash(){if(this.hash===void 0){let e=t(`sha256`);for(let[t,n]of Object.entries(this.baseConfiguration))e.update(t),e.update(String(n));for(let[t,n]of Object.entries(this.overwrites))e.update(t),e.update(String(n));this.hash=e.digest(`hex`)}return this.hash}copy(){let t=JSON.parse(JSON.stringify(this.overwrites));return new e(this.allParameters,this.redefinableParameters,this.baseConfiguration,t)}};function D(e){return new Proxy(e,{get(t,n){return e.get(n.toString())},set(t,n,r){return e.set(n.toString(),r),!0}})}const O={order:1,title:`Collector Connectivity`},k={order:1,title:`Teamscale Server`},A={order:2,title:`Upload to Teamscale`,hints:"NOTE: We generally recommend to set these parameters per app during the instrumentation process, that is, on the instrumenter side, for example, by setting `--config-id` or specifying single options via `--collector-option`. The following parameters are supposed to take effect if the application is instrumented with the `--coverage-target-from-collector` flag."},j={order:3,title:`Coverage Dumping`},M={order:4,title:`Upload to Artifactory`},N={order:5,title:`Logging Behavior`};function P(){let e=new f;function t(t,n,r,i){e.addParameter(t,n,r,i)}return t(`-k`,`--keep-coverage-files`,`bool`,{help:`Whether to keep the coverage files on disk after a successful upload to Teamscale.`,default:!1,group:j}),t(`-t`,`--dump-after-mins`,`int`,{help:`Dump the coverage information every N minutes.`,default:120,group:j}),t(void 0,`--artifactory-server-url`,`string`,{help:`Upload the coverage to the given Artifactory server URL. The URL may include a subpath on the artifactory server, e.g. https://artifactory.acme.com/my-repo/my/subpath`,group:M}),t(void 0,`--artifactory-user`,`string`,{help:`The user for uploading coverage to Artifactory. Only needed when not using the --artifactory-access-token option`,group:M}),t(void 0,`--artifactory-password`,`string`,{help:`The password for uploading coverage to Artifactory. Only needed when not using the --artifactory-access-token option`,group:M}),t(void 0,`--artifactory-access-token`,`string`,{help:`The access_token for uploading coverage to Artifactory.`,group:M}),t(void 0,`--artifactory-path-suffix`,`string`,{help:`(optional): The path within the storage location between the default path and the uploaded artifact.`,group:M}),t(void 0,`--teamscale-project`,`string`,{help:`The project ID to upload coverage to.`,group:A}),t(void 0,`--teamscale-partition`,`string`,{help:`The partition to upload coverage to.`,group:A}),t(void 0,`--teamscale-repository`,`string`,{help:`The repository to upload coverage for. Optional: Only needed when uploading via revision to a project that has more than one connector.`,group:A}),t(void 0,`--teamscale-message`,`string`,{help:`The commit message shown within Teamscale for the coverage upload.`,default:`JavaScript coverage upload`,group:A}),e}function F(){let e=P();function t(t,n,r,i){e.addParameter(t,n,r,i)}return t(`-p`,`--port`,`int`,{help:`The port to receive coverage information on.`,default:54678,group:O,disableEnvironmentVariableOverride:!0}),t(`-l`,`--log-to-file`,`string`,{help:`Log file`,default:`logs/collector-combined.log`,group:N,disableEnvironmentVariableOverride:!0}),t(`-e`,`--log-level`,`string`,{help:`Log level`,default:`info`,group:N,disableEnvironmentVariableOverride:!0}),t(`-j`,`--json-log`,`bool`,{help:`Additional JSON-like log file format.`,group:N,disableEnvironmentVariableOverride:!0}),t(`-c`,`--enable-control-port`,`int`,{help:`Enables the remote control API on the specified port (<=0 means "disabled").`,default:0,group:O}),t(`-s`,`--teamscale-server-url`,`string`,{help:`Upload the coverage to the given Teamscale server URL, for example, https://teamscale.dev.example.com:8080/production.`,group:k}),t(`-u`,`--teamscale-user`,`string`,{help:`The user for uploading coverage to Teamscale.`,group:k}),t(`-a`,`--teamscale-access-token`,`string`,{help:`The API key to use for uploading to Teamscale.`,group:k}),t(void 0,`--http-proxy`,`string`,{help:`(optional): The HTTP/HTTPS proxy address that should be used in the format: http://host:port/ or http://username:password@host:port/.`,group:O}),t(`-f`,`--dump-folder`,`string`,{help:`Target folder for coverage files.`,default:`./coverage`,group:j}),e.addArgumentCheck(e=>{if(e.teamscaleServerUrl&&(!e.teamscaleUser||!e.teamscaleAccessToken))return`The Teamscale user name and access token must be given if the Teamscale server URL is given.`}),e}function I(){let e=P();function t(t,n,r,i){e.addParameter(t,n,r,i)}function n(e,n,r){t(void 0,e,n,r)}return n(`--dump-to-folder`,`string`,{help:`Coverage should be dumped to a folder on the server that the collector is running on.
7
+ Specifies the name of the subfolder within the collector's dump folder (--dump-folder of the collector) where coverage files should be placed.`,group:j}),e}function L(e){if(typeof e==`string`){if(/^[a-zA-Z0-9_-]+:([0-9]+|HEAD|head)$/.test(e))return!0;if(/^[0-9]+$/.test(e))return!1;if(/^[a-zA-Z0-9]{7,40}$/.test(e))return!0}return!1}export{c as CONFIG_GROUP_APP,f as ConfigurationParameters,E as ConfigurationWithOverwrites,o as Contract,i as IllegalArgumentException,r as IllegalStateException,n as ImplementMeException,a as InvalidConfigurationException,P as buildPredefinableParameters,I as buildReconfigurableCollectorParameters,F as buildStaticCollectorParameters,C as checkArguments,L as isValidCommitInfo,d as longParameterToEnvironmentVariableName,D as makeConfigProxy,u as parameterNameToParameterId,T as parameterUnion,p as parseArguments,v as parseConfigFile,y as printHelp,w as processCommandLine,s as removePrefix};
8
+ //# sourceMappingURL=index.mjs.map
package/package.json CHANGED
@@ -1,21 +1,35 @@
1
1
  {
2
2
  "name": "@cqse/commons",
3
- "version": "1.0.0-beta.7",
3
+ "version": "1.0.5",
4
4
  "description": "A collection of generic functionality for TypeScript projects.",
5
5
  "author": "CQSE GmbH",
6
- "main": "lib/index.js",
6
+ "main": "lib/index.cjs",
7
+ "module": "lib/index.mjs",
8
+ "types": "lib/index.d.cts",
9
+ "exports": {
10
+ ".": {
11
+ "require": {
12
+ "types": "./lib/index.d.cts",
13
+ "default": "./lib/index.cjs"
14
+ },
15
+ "import": {
16
+ "types": "./lib/index.d.mts",
17
+ "default": "./lib/index.mjs"
18
+ }
19
+ }
20
+ },
7
21
  "license": "Apache-2.0",
8
22
  "homepage": "https://docs.teamscale.com/howto/setting-up-profiler-tga/javascript/",
9
23
  "files": [
10
- "dist/**/*",
11
- "lib/**/*"
24
+ "lib/*.mjs",
25
+ "lib/*.cjs"
12
26
  ],
13
27
  "publishConfig": {
14
28
  "access": "public"
15
29
  },
16
30
  "scripts": {
17
- "build": "tsc",
18
- "clean": "rimraf lib tsconfig.tsbuildinfo",
31
+ "build": "pnpm tsc --noEmit && pnpm tsdown",
32
+ "clean": "rimraf lib",
19
33
  "test": "node --import tsx --test test/**/*.test.ts"
20
34
  }
21
35
  }
@@ -1,34 +0,0 @@
1
- import { ConfigurationParameters } from './ConfigParser';
2
- export type PredefinableOptions = {
3
- keepCoverageFiles: boolean;
4
- dumpAfterMins: number;
5
- artifactoryServerUrl?: string;
6
- artifactoryUser?: string;
7
- artifactoryPassword?: string;
8
- artifactoryAccessToken?: string;
9
- artifactoryPathSuffix?: string;
10
- };
11
- export type StaticCollectorOptions = PredefinableOptions & {
12
- port: number;
13
- dumpFolder: string;
14
- httpProxy?: string;
15
- logLevel: string;
16
- logToFile: string;
17
- jsonLog: boolean;
18
- enableControlPort?: number;
19
- teamscaleServerUrl?: string;
20
- teamscaleUser?: string;
21
- teamscaleAccessToken?: string;
22
- };
23
- export type ReconfigurableCollectorOptions = PredefinableOptions & {
24
- teamscaleProject?: string;
25
- teamscalePartition?: string;
26
- teamscaleRepository?: string;
27
- teamscaleMessage?: string;
28
- dumpToFolder?: string;
29
- };
30
- export type CollectorOptions = StaticCollectorOptions & ReconfigurableCollectorOptions;
31
- export declare function buildPredefinableParameters(): ConfigurationParameters;
32
- export declare function buildStaticCollectorParameters(): ConfigurationParameters;
33
- export declare function buildReconfigurableCollectorParameters(): ConfigurationParameters;
34
- //# sourceMappingURL=CollectorConfig.d.ts.map
@@ -1 +0,0 @@
1
- {"version":3,"file":"CollectorConfig.d.ts","sourceRoot":"","sources":["../src/CollectorConfig.ts"],"names":[],"mappings":"AAAA,OAAO,EAEN,uBAAuB,EACvB,MAAM,gBAAgB,CAAC;AAExB,MAAM,MAAM,mBAAmB,GAAG;IACjC,iBAAiB,EAAE,OAAO,CAAC;IAC3B,aAAa,EAAE,MAAM,CAAC;IACtB,oBAAoB,CAAC,EAAE,MAAM,CAAC;IAC9B,eAAe,CAAC,EAAE,MAAM,CAAC;IACzB,mBAAmB,CAAC,EAAE,MAAM,CAAC;IAC7B,sBAAsB,CAAC,EAAE,MAAM,CAAC;IAChC,qBAAqB,CAAC,EAAE,MAAM,CAAC;CAC/B,CAAA;AAMD,MAAM,MAAM,sBAAsB,GAAG,mBAAmB,GAAG;IAC1D,IAAI,EAAE,MAAM,CAAC;IACb,UAAU,EAAE,MAAM,CAAC;IACnB,SAAS,CAAC,EAAE,MAAM,CAAC;IACnB,QAAQ,EAAE,MAAM,CAAC;IACjB,SAAS,EAAE,MAAM,CAAC;IAClB,OAAO,EAAE,OAAO,CAAC;IACjB,iBAAiB,CAAC,EAAE,MAAM,CAAC;IAC3B,kBAAkB,CAAC,EAAE,MAAM,CAAC;IAC5B,aAAa,CAAC,EAAE,MAAM,CAAC;IACvB,oBAAoB,CAAC,EAAE,MAAM,CAAC;CAC9B,CAAC;AASF,MAAM,MAAM,8BAA8B,GAAG,mBAAmB,GAAG;IAClE,gBAAgB,CAAC,EAAE,MAAM,CAAC;IAC1B,kBAAkB,CAAC,EAAE,MAAM,CAAC;IAC5B,mBAAmB,CAAC,EAAE,MAAM,CAAC;IAC7B,gBAAgB,CAAC,EAAE,MAAM,CAAC;IAC1B,YAAY,CAAC,EAAE,MAAM,CAAC;CACtB,CAAC;AAMF,MAAM,MAAM,gBAAgB,GAAG,sBAAsB,GAAG,8BAA8B,CAAC;AA8CvF,wBAAgB,2BAA2B,IAAI,uBAAuB,CA6DrE;AAQD,wBAAgB,8BAA8B,IAAI,uBAAuB,CAkDxE;AAKD,wBAAgB,sCAAsC,IAAI,uBAAuB,CAoBhF"}
@@ -1,152 +0,0 @@
1
- "use strict";
2
- Object.defineProperty(exports, "__esModule", { value: true });
3
- exports.buildPredefinableParameters = buildPredefinableParameters;
4
- exports.buildStaticCollectorParameters = buildStaticCollectorParameters;
5
- exports.buildReconfigurableCollectorParameters = buildReconfigurableCollectorParameters;
6
- const ConfigParser_1 = require("./ConfigParser");
7
- const CONFIG_GROUP_COLLECTOR_CONNECTIVITY = {
8
- order: 1,
9
- title: 'Collector Connectivity'
10
- };
11
- const CONFIG_GROUP_TEAMSCALE_SERVER = {
12
- order: 1,
13
- title: 'Teamscale Server'
14
- };
15
- const CONFIG_GROUP_TEAMSCALE_UPLOAD = {
16
- order: 2,
17
- title: 'Upload to Teamscale',
18
- hints: 'NOTE: We generally recommend to set these parameters per app during ' +
19
- 'the instrumentation process, that is, on the instrumenter side, for example, ' +
20
- 'by setting `--config-id` or specifying single options via `--collector-option`. ' +
21
- 'The following parameters are supposed to take effect if the application ' +
22
- 'is instrumented with the `--coverage-target-from-collector` flag.'
23
- };
24
- const CONFIG_GROUP_COVERAGE_DUMP = {
25
- order: 3,
26
- title: 'Coverage Dumping'
27
- };
28
- const CONFIG_GROUP_ARTIFACTORY_UPLOAD = {
29
- order: 4,
30
- title: 'Upload to Artifactory'
31
- };
32
- const CONFIG_GROUP_LOGGING = {
33
- order: 5,
34
- title: 'Logging Behavior'
35
- };
36
- function buildPredefinableParameters() {
37
- const parameters = new ConfigParser_1.ConfigurationParameters();
38
- function add(shortParameter, longParameter, type, options) {
39
- parameters.addParameter(shortParameter, longParameter, type, options);
40
- }
41
- add('-k', '--keep-coverage-files', 'bool', {
42
- help: 'Whether to keep the coverage files on disk after a successful upload to Teamscale.',
43
- default: false,
44
- group: CONFIG_GROUP_COVERAGE_DUMP
45
- });
46
- add('-t', '--dump-after-mins', 'int', {
47
- help: 'Dump the coverage information every N minutes.',
48
- default: 120,
49
- group: CONFIG_GROUP_COVERAGE_DUMP
50
- });
51
- add(undefined, '--artifactory-server-url', 'string', {
52
- help: 'Upload the coverage to the given Artifactory server URL. The URL may include a subpath on the artifactory server, e.g. https://artifactory.acme.com/my-repo/my/subpath',
53
- group: CONFIG_GROUP_ARTIFACTORY_UPLOAD
54
- });
55
- add(undefined, '--artifactory-user', 'string', {
56
- help: 'The user for uploading coverage to Artifactory. Only needed when not using the --artifactory-access-token option',
57
- group: CONFIG_GROUP_ARTIFACTORY_UPLOAD
58
- });
59
- add(undefined, '--artifactory-password', 'string', {
60
- help: 'The password for uploading coverage to Artifactory. Only needed when not using the --artifactory-access-token option',
61
- group: CONFIG_GROUP_ARTIFACTORY_UPLOAD
62
- });
63
- add(undefined, '--artifactory-access-token', 'string', {
64
- help: 'The access_token for uploading coverage to Artifactory.',
65
- group: CONFIG_GROUP_ARTIFACTORY_UPLOAD
66
- });
67
- add(undefined, '--artifactory-path-suffix', 'string', {
68
- help: '(optional): The path within the storage location between the default path and the uploaded artifact.',
69
- group: CONFIG_GROUP_ARTIFACTORY_UPLOAD
70
- });
71
- add(undefined, '--teamscale-project', 'string', {
72
- help: 'The project ID to upload coverage to.',
73
- group: CONFIG_GROUP_TEAMSCALE_UPLOAD
74
- });
75
- add(undefined, '--teamscale-partition', 'string', {
76
- help: 'The partition to upload coverage to.',
77
- group: CONFIG_GROUP_TEAMSCALE_UPLOAD
78
- });
79
- add(undefined, '--teamscale-repository', 'string', {
80
- help: 'The repository to upload coverage for. Optional: Only needed when uploading via revision to a project that has more than one connector.',
81
- group: CONFIG_GROUP_TEAMSCALE_UPLOAD
82
- });
83
- add(undefined, '--teamscale-message', 'string', {
84
- help: 'The commit message shown within Teamscale for the coverage upload.',
85
- default: 'JavaScript coverage upload',
86
- group: CONFIG_GROUP_TEAMSCALE_UPLOAD
87
- });
88
- return parameters;
89
- }
90
- function buildStaticCollectorParameters() {
91
- const parameters = buildPredefinableParameters();
92
- function add(shortParameter, longParameter, type, options) {
93
- parameters.addParameter(shortParameter, longParameter, type, options);
94
- }
95
- add('-p', '--port', 'int', { help: 'The port to receive coverage information on.',
96
- default: 54678, group: CONFIG_GROUP_COLLECTOR_CONNECTIVITY, disableEnvironmentVariableOverride: true });
97
- add('-l', '--log-to-file', 'string', { help: 'Log file', default: 'logs/collector-combined.log', group: CONFIG_GROUP_LOGGING,
98
- disableEnvironmentVariableOverride: true });
99
- add('-e', '--log-level', 'string', { help: 'Log level',
100
- default: 'info', group: CONFIG_GROUP_LOGGING, disableEnvironmentVariableOverride: true });
101
- add('-j', '--json-log', 'bool', { help: 'Additional JSON-like log file format.',
102
- group: CONFIG_GROUP_LOGGING, disableEnvironmentVariableOverride: true });
103
- add('-c', '--enable-control-port', 'int', {
104
- help: 'Enables the remote control API on the specified port (<=0 means "disabled").',
105
- default: 0, group: CONFIG_GROUP_COLLECTOR_CONNECTIVITY
106
- });
107
- add('-s', '--teamscale-server-url', 'string', {
108
- help: 'Upload the coverage to the given Teamscale server URL, for example, https://teamscale.dev.example.com:8080/production.',
109
- group: CONFIG_GROUP_TEAMSCALE_SERVER
110
- });
111
- add('-u', '--teamscale-user', 'string', {
112
- help: 'The user for uploading coverage to Teamscale.',
113
- group: CONFIG_GROUP_TEAMSCALE_SERVER
114
- });
115
- add('-a', '--teamscale-access-token', 'string', {
116
- help: 'The API key to use for uploading to Teamscale.',
117
- group: CONFIG_GROUP_TEAMSCALE_SERVER
118
- });
119
- add(undefined, '--http-proxy', 'string', {
120
- help: '(optional): The HTTP/HTTPS proxy address that should be used in the format: http://host:port/ or http://username:password@host:port/.',
121
- group: CONFIG_GROUP_COLLECTOR_CONNECTIVITY,
122
- });
123
- add('-f', '--dump-folder', 'string', {
124
- help: 'Target folder for coverage files.',
125
- default: './coverage',
126
- group: CONFIG_GROUP_COVERAGE_DUMP
127
- });
128
- parameters.addArgumentCheck((options) => {
129
- if (options.teamscaleServerUrl) {
130
- if (!options.teamscaleUser || !options.teamscaleAccessToken) {
131
- return 'The Teamscale user name and access token must be given if the Teamscale server URL is given.';
132
- }
133
- }
134
- });
135
- return parameters;
136
- }
137
- function buildReconfigurableCollectorParameters() {
138
- const parameters = buildPredefinableParameters();
139
- function addShort(shortParameter, longParameter, type, options) {
140
- parameters.addParameter(shortParameter, longParameter, type, options);
141
- }
142
- function add(longArgument, type, options) {
143
- addShort(undefined, longArgument, type, options);
144
- }
145
- add('--dump-to-folder', 'string', {
146
- help: 'Coverage should be dumped to a folder on the server that the collector is running on.\n' +
147
- 'Specifies the name of the subfolder within the collector\'s dump folder (--dump-folder of the collector) where coverage files should be placed.',
148
- group: CONFIG_GROUP_COVERAGE_DUMP
149
- });
150
- return parameters;
151
- }
152
- //# sourceMappingURL=CollectorConfig.js.map
@@ -1 +0,0 @@
1
- {"version":3,"file":"CollectorConfig.js","sourceRoot":"","sources":["../src/CollectorConfig.ts"],"names":[],"mappings":";;AAiGA,kEA6DC;AAQD,wEAkDC;AAKD,wFAoBC;AAjPD,iDAGwB;AAwDxB,MAAM,mCAAmC,GAAmB;IAC3D,KAAK,EAAE,CAAC;IACR,KAAK,EAAE,wBAAwB;CAC/B,CA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ameterType = 'string' | 'int' | 'bool' | 'string[]';
2
- export type ConfigValueType = string | number | boolean | string[];
3
- export type Options = Record<string, ConfigValueType>;
4
- export type VersionAndHelpOptions = {
5
- version: boolean;
6
- help: boolean;
7
- };
8
- export type ConfigParsingResult = {
9
- options: Options;
10
- unnamedArguments: string[];
11
- };
12
- export type AppInfos = {
13
- name: string;
14
- version: string;
15
- about: string;
16
- };
17
- export type ParameterGroup = {
18
- order: number;
19
- title: string;
20
- hints?: string;
21
- };
22
- export declare const CONFIG_GROUP_APP: ParameterGroup;
23
- export type ParameterDescriptor = {
24
- parameterId: string;
25
- shortParameter?: string;
26
- longParameter: string;
27
- environmentVariableName: string;
28
- disableEnvironmentVariableOverride?: boolean;
29
- type: ConfigParameterType;
30
- default?: ConfigValueType;
31
- help: string;
32
- internal: boolean;
33
- group?: ParameterGroup;
34
- };
35
- export type ParameterDefinitionOptions = Partial<ParameterDescriptor>;
36
- export declare function parameterNameToParameterId(parameterName: string): string;
37
- export declare function longParameterToEnvironmentVariableName(longParameter: string): string;
38
- export declare class ConfigurationParameters {
39
- private readonly parameters;
40
- private readonly shortToLongParameterMap;
41
- private readonly sequentialParameters;
42
- private readonly argumentChecks;
43
- constructor();
44
- addParameter(shortParameter: string | undefined, longParameter: string, type: ConfigParameterType, options?: ParameterDefinitionOptions): void;
45
- addArgumentCheck(check: (options: Record<string, unknown>) => string | undefined): void;
46
- addRequiredArgumentFor(parameterId: string): void;
47
- describeParameter(parameterId: string, descriptor: ParameterDescriptor): void;
48
- lookupParameter(parameterId: string): ParameterDescriptor | undefined;
49
- getParameters(): ParameterDescriptor[];
50
- getArgumentChecks(): Array<(options: Record<string, unknown>) => string | undefined>;
51
- getSequentialParameters(): string[];
52
- clone(): ConfigurationParameters;
53
- addAllOf(toAdd: ConfigurationParameters): void;
54
- }
55
- export declare function parseArguments<OptionsType extends Record<string, unknown>>(args: string[], parameters: ConfigurationParameters): Partial<OptionsType>;
56
- export declare function parseConfigFile(fileContent: string, parameters: ConfigurationParameters): ConfigParsingResult;
57
- export declare function printHelp(parameters: ConfigurationParameters, aboutText?: string, printParamterId?: boolean): void;
58
- export declare function checkArguments(configParameters: ConfigurationParameters, options: Options, errorReceiver?: (error: string) => void): boolean;
59
- export declare function processCommandLine<O>(parameters: ConfigurationParameters, appInfos: AppInfos, args?: string[], beforeCheckCallback?: (options: O) => void): O;
60
- export declare function parameterUnion(parameters1: ConfigurationParameters, parameters2: ConfigurationParameters): ConfigurationParameters;
61
- //# sourceMappingURL=ConfigParser.d.ts.map
@@ -1 +0,0 @@
1
- {"version":3,"file":"ConfigParser.d.ts","sourceRoot":"","sources":["../src/ConfigParser.ts"],"names":[],"mappings":"AAWA,MAAM,MAAM,mBAAmB,GAAG,QAAQ,GAAG,KAAK,GAAG,MAAM,GAAG,UAAU,CAAC;AAGzE,MAAM,MAAM,eAAe,GAAG,MAAM,GAAG,MAAM,GAAG,OAAO,GAAG,MAAM,EAAE,CAAC;AAGnE,MAAM,MAAM,OAAO,GAAG,MAAM,CAAC,MAAM,EAAE,eAAe,CAAC,CAAC;AAGtD,MAAM,MAAM,qBAAqB,GAAG;IAAE,OAAO,EAAE,OAAO,CAAC;IAAC,IAAI,EAAE,OAAO,CAAA;CAAE,CAAC;AAGxE,MAAM,MAAM,mBAAmB,GAAG;IACjC,OAAO,EAAE,OAAO,CAAC;IACjB,gBAAgB,EAAE,MAAM,EAAE,CAAC;CAC3B,CAAC;AAGF,MAAM,MAAM,QAAQ,GAAG;IACtB,IAAI,EAAE,MAAM,CAAC;IACb,OAAO,EAAE,MAAM,CAAC;IAChB,KAAK,EAAE,MAAM,CAAC;CACd,CAAA;AAGD,MAAM,MAAM,cAAc,GAAG;IAE5B,KAAK,EAAE,MAAM,CAAC;IAGd,KAAK,EAAE,MAAM,CAAC;IAGd,KAAK,CAAC,EAAE,MAAM,CAAC;CACf,CAAA;AAGD,eAAO,MAAM,gBAAgB,EAAE,cAG9B,CAAC;AAGF,MAAM,MAAM,mBAAmB,GAA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