diff --git a/.gitignore b/.gitignore index 462060d9..683c6d51 100644 --- a/.gitignore +++ b/.gitignore @@ -23,6 +23,9 @@ _* TODO.txt **/.env **/id_rsa* +.agent +.claude +CLAUDE.md .task/ attic.txt **/venv/ diff --git a/AGENTS.md b/AGENTS.md new file mode 100644 index 00000000..1ba51323 --- /dev/null +++ b/AGENTS.md @@ -0,0 +1,147 @@ +# Apache OpenServerless Task Agent Guidelines + +This file provides instructions for agentic coding agents working in this repository. + + +## Setup commands + +- Install Dependencies: `bun install` +- Start development server: `` +- Build the configurator utility: `cd util/config/configurator && bun run build` + +## Testing instructions +- Run tests: `bun test` + +- Run a single test: `bun test util/config/configurator/tests/index.test.ts` +- Run tests with verbose output `bun test --reporter=verbose` + +## Running the application +- Run the configurator utility: `cd util/config/configurator && bun run start` +- Run the configurator utility with a specified configuration file: `bun run start -- ` +- Run the configurator utility with a specified configuration file overriding existing values: `bun run start -- [--override]` + + +## Code style + +- TypeScript strict mode + +### Language & Version +- Primary language: TypeScript +- Runtime: Bun (Node.js compatible) +- Target ES version: ES2022+ +- Module system: ES Modules (`"type": "module"` in package.json) + +### File Organization +- TypeScript files: `.ts` extension +- Test files: `*.test.ts` located in `__tests__` or `tests` directories +- Configuration: TOML (`.toml`) or JSON (`.json`) +- Operations definitions: YAML (`.yml`) + +### Imports +1. **Order**: + - Built-in Node.js/Bun modules (e.g., `import { $ } from "bun";`) + - Third-party libraries (e.g., `import { select } from "@clack/prompts";`) + - Local application files (relative paths) + +2. **Syntax**: + - Use ES module syntax: `import { foo } from "bar";` + - Default imports: `import foo from "bar";` + - Avoid `require()` syntax + +3. **Specific Rules**: + - Import types separately when needed: `import type { TypeName } from "./types";` + - Group related imports together + - No unused imports allowed + +### Formatting +- **Indentation**: 2 spaces (not tabs) +- **Line length**: Maximum 100 characters (prefer 80-100) +- **Semicolons**: Required (use semicolons to terminate statements) +- **Quotes**: + - Single quotes (`'`) for strings + - Template literals (`` ` ``) for multi-line or interpolated strings + - Double quotes (`"`) only when required by JSON or external specifications +- **Commas**: Trailing commas in multi-line objects/arrays +- **Braces**: + - Opening brace on the same line as the statement + - Closing brace on its own line + - No braces for single-line conditionals when it improves readability + +### Types +- **Type Annotations**: + - Always annotate function parameters + - Annotate return values for public functions + - Use type inference for local variables when obvious +- **Interfaces vs Types**: + - Use `interface` for object shapes that may be extended + - Use `type` for unions, primitives, complex mapped types +- **Strictness**: Enable strict TypeScript options (null checks, no implicit any, etc.) + +### Naming Conventions +- **Files & Directories**: kebab-case (e.g., `configurator.ts`, `all-config-parameters.toml`) +- **Variables & Functions**: camelCase (e.g., `readPositionalFile`, `isInputConfigValid`) +- **Constants**: UPPER_SNAKE_CASE (e.g., `HelpMsg`, `AdditionalArgsMsg`) +- **Types & Interfaces**: PascalCase (e.g., `OpsConfig`, `PromptData`) +- **Classes**: PascalCase (though minimal class usage in this codebase) +- **Boolean Variables**: Prefix with `is`, `has`, `should`, `can` (e.g., `isValid`, `hasError`) + +### Error Handling +- **Early Returns**: Handle error conditions first with early returns +- **Async Functions**: Use try/catch for async operations that can fail +- **Bun Specific**: + - Use `process.exit(1)` for error exits + - Use `process.exit(0)` for successful exits + - Check `success` property on result objects from utils +- **Messages**: + - Export constant error messages (as seen with `HelpMsg`, `NotValidJsonMsg`, etc.) + - Use descriptive, user-friendly error messages + - Log warnings with `console.warn()`, errors with `console.error()` + +### Specific Patterns from Codebase +- **Configuration Validation**: Separate validation functions (e.g., `isInputConfigValid`) +- **File Operations**: + - Read → Parse → Validate pattern + - Return objects with `{ success: boolean, message?: string, ...data }` shape +- **CLI Argument Parsing**: Use `util.parseArgs` with strict mode and positionals +- **Interactive Prompts**: Use `@clack/prompts` with proper cancellation handling +- **Shell Commands**: Use Bun's `$` helper for shell commands with `.quiet()` to suppress output + +### Testing +- **Framework**: Bun's built-in test framework (`bun:test`) +- **File Naming**: `*.test.ts` +- **Structure**: + - Use `describe()` for test suites + - Use `test()` for individual tests + - Use `expect()` for assertions +- **Mocking**: Minimal mocking; prefer testing actual behavior +- **Async Tests**: Return promises or use `async`/`await` + +### Comments +- Use JSDoc-style comments for public APIs +- Use `//` for inline comments explaining why (not what) +- Keep comments up-to-date; delete outdated comments +- TODO comments should include GitHub issue references when possible +- When adding bash scripts in the documentation, always keep commands separate (one command per ```bash section) + +### Security +- Never log secrets or credentials +- Use `password` prompt type for sensitive inputs +- Validate and sanitize all external inputs +- Follow the principle of least privilege + +## Task Tracking + +For any task that involves more than one non-trivial step (multi-file changes, investigations with uncertain outcomes, features spanning multiple components), maintain a TODO list using the `TaskCreate` / `TaskUpdate` / `TaskList` tools: + +1. **Start**: call `TaskCreate` to create one task entry per step before writing any code. +2. **Progress**: call `TaskUpdate` (status `in_progress`) when starting a step, `completed` when it is done. +3. **Visibility**: after completing a task, call `TaskList` to confirm no steps are left open. + +Keep task titles short and action-oriented ("Add `type` field to ConfigParameter", "Update parseParameter", etc.). +Do **not** create tasks for trivial single-file edits or quick answers. + +## Additional Notes +- This repository uses Bun as its primary runtime/package manager +- Configuration is driven by TOML files and environment variables +- The `opsfile.yml` defines operational tasks but is not part of the main TypeScript codebase +- When modifying the configurator utility, remember to rebuild after changes \ No newline at end of file diff --git a/bun.lock b/bun.lock new file mode 100644 index 00000000..db01606d --- /dev/null +++ b/bun.lock @@ -0,0 +1,46 @@ +{ + "lockfileVersion": 1, + "configVersion": 1, + "workspaces": { + "": { + "dependencies": { + "@clack/prompts": "^1.0.1", + "js-toml": "^1.0.2", + "toml": "^3.0.0", + }, + }, + }, + "packages": { + "@babel/runtime-corejs3": ["@babel/runtime-corejs3@7.29.0", "", { "dependencies": { "core-js-pure": "^3.48.0" } }, "sha512-TgUkdp71C9pIbBcHudc+gXZnihEDOjUAmXO1VO4HHGES7QLZcShR0stfKIxLSNIYx2fqhmJChOjm/wkF8wv4gA=="], + + "@chevrotain/cst-dts-gen": ["@chevrotain/cst-dts-gen@11.1.1", "", { "dependencies": { "@chevrotain/gast": "11.1.1", "@chevrotain/types": "11.1.1", "lodash-es": "4.17.23" } }, "sha512-fRHyv6/f542qQqiRGalrfJl/evD39mAvbJLCekPazhiextEatq1Jx1K/i9gSd5NNO0ds03ek0Cbo/4uVKmOBcw=="], + + "@chevrotain/gast": ["@chevrotain/gast@11.1.1", "", { "dependencies": { "@chevrotain/types": "11.1.1", "lodash-es": "4.17.23" } }, "sha512-Ko/5vPEYy1vn5CbCjjvnSO4U7GgxyGm+dfUZZJIWTlQFkXkyym0jFYrWEU10hyCjrA7rQtiHtBr0EaZqvHFZvg=="], + + "@chevrotain/regexp-to-ast": ["@chevrotain/regexp-to-ast@11.1.1", "", {}, "sha512-ctRw1OKSXkOrR8VTvOxrQ5USEc4sNrfwXHa1NuTcR7wre4YbjPcKw+82C2uylg/TEwFRgwLmbhlln4qkmDyteg=="], + + "@chevrotain/types": ["@chevrotain/types@11.1.1", "", {}, "sha512-wb2ToxG8LkgPYnKe9FH8oGn3TMCBdnwiuNC5l5y+CtlaVRbCytU0kbVsk6CGrqTL4ZN4ksJa0TXOYbxpbthtqw=="], + + "@chevrotain/utils": ["@chevrotain/utils@11.1.1", "", {}, "sha512-71eTYMzYXYSFPrbg/ZwftSaSDld7UYlS8OQa3lNnn9jzNtpFbaReRRyghzqS7rI3CDaorqpPJJcXGHK+FE1TVQ=="], + + "@clack/core": ["@clack/core@1.0.1", "", { "dependencies": { "picocolors": "^1.0.0", "sisteransi": "^1.0.5" } }, "sha512-WKeyK3NOBwDOzagPR5H08rFk9D/WuN705yEbuZvKqlkmoLM2woKtXb10OO2k1NoSU4SFG947i2/SCYh+2u5e4g=="], + + "@clack/prompts": ["@clack/prompts@1.0.1", "", { "dependencies": { "@clack/core": "1.0.1", "picocolors": "^1.0.0", "sisteransi": "^1.0.5" } }, "sha512-/42G73JkuYdyWZ6m8d/CJtBrGl1Hegyc7Fy78m5Ob+jF85TOUmLR5XLce/U3LxYAw0kJ8CT5aI99RIvPHcGp/Q=="], + + "chevrotain": ["chevrotain@11.1.1", "", { "dependencies": { "@chevrotain/cst-dts-gen": "11.1.1", "@chevrotain/gast": "11.1.1", "@chevrotain/regexp-to-ast": "11.1.1", "@chevrotain/types": "11.1.1", "@chevrotain/utils": "11.1.1", "lodash-es": "4.17.23" } }, "sha512-f0yv5CPKaFxfsPTBzX7vGuim4oIC1/gcS7LUGdBSwl2dU6+FON6LVUksdOo1qJjoUvXNn45urgh8C+0a24pACQ=="], + + "core-js-pure": ["core-js-pure@3.48.0", "", {}, "sha512-1slJgk89tWC51HQ1AEqG+s2VuwpTRr8ocu4n20QUcH1v9lAN0RXen0Q0AABa/DK1I7RrNWLucplOHMx8hfTGTw=="], + + "js-toml": ["js-toml@1.0.2", "", { "dependencies": { "chevrotain": "^11.0.3", "xregexp": "^5.1.1" } }, "sha512-/7IQ//bzn2a/5IDazPUNzlW7bsjxS51cxciYZDR+Z+3Le60yzT0YfI8KOWqTtBcZkXXVklhWd2OuGd8ZksB0wQ=="], + + "lodash-es": ["lodash-es@4.17.23", "", {}, "sha512-kVI48u3PZr38HdYz98UmfPnXl2DXrpdctLrFLCd3kOx1xUkOmpFPx7gCWWM5MPkL/fD8zb+Ph0QzjGFs4+hHWg=="], + + "picocolors": ["picocolors@1.1.1", "", {}, "sha512-xceH2snhtb5M9liqDsmEw56le376mTZkEX/jEb/RxNFyegNul7eNslCXP9FDj/Lcu0X8KEyMceP2ntpaHrDEVA=="], + + "sisteransi": ["sisteransi@1.0.5", "", {}, "sha512-bLGGlR1QxBcynn2d5YmDX4MGjlZvy2MRBDRNHLJ8VI6l6+9FUiyTFNJ0IveOSP0bcXgVDPRcfGqA0pjaqUpfVg=="], + + "toml": ["toml@3.0.0", "", {}, "sha512-y/mWCZinnvxjTKYhJ+pYxwD0mRLVvOtdS2Awbgxln6iEnt4rk0yBxeSBHkGJcPucRiG0e55mwWp+g/05rsrd6w=="], + + "xregexp": ["xregexp@5.1.2", "", { "dependencies": { "@babel/runtime-corejs3": "^7.26.9" } }, "sha512-6hGgEMCGhqCTFEJbqmWrNIPqfpdirdGWkqshu7fFZddmTSfgv5Sn9D2SaKloR79s5VUiUlpwzg3CM3G6D3VIlw=="], + } +} diff --git a/package.json b/package.json new file mode 100644 index 00000000..7a76a42b --- /dev/null +++ b/package.json @@ -0,0 +1,7 @@ +{ + "dependencies": { + "@clack/prompts": "^1.0.1", + "js-toml": "^1.0.2", + "toml": "^3.0.0" + } +} \ No newline at end of file diff --git a/pnpm-lock.yaml b/pnpm-lock.yaml new file mode 100644 index 00000000..d4401539 --- /dev/null +++ b/pnpm-lock.yaml @@ -0,0 +1,132 @@ +lockfileVersion: '9.0' + +settings: + autoInstallPeers: true + excludeLinksFromLockfile: false + +importers: + + .: + dependencies: + '@clack/prompts': + specifier: ^1.0.1 + version: 1.0.1 + js-toml: + specifier: ^1.0.2 + version: 1.0.2 + toml: + specifier: ^3.0.0 + version: 3.0.0 + +packages: + + '@babel/runtime-corejs3@7.29.0': + resolution: {integrity: sha512-TgUkdp71C9pIbBcHudc+gXZnihEDOjUAmXO1VO4HHGES7QLZcShR0stfKIxLSNIYx2fqhmJChOjm/wkF8wv4gA==} + engines: {node: '>=6.9.0'} + + '@chevrotain/cst-dts-gen@11.1.1': + resolution: {integrity: sha512-fRHyv6/f542qQqiRGalrfJl/evD39mAvbJLCekPazhiextEatq1Jx1K/i9gSd5NNO0ds03ek0Cbo/4uVKmOBcw==} + + '@chevrotain/gast@11.1.1': + resolution: {integrity: sha512-Ko/5vPEYy1vn5CbCjjvnSO4U7GgxyGm+dfUZZJIWTlQFkXkyym0jFYrWEU10hyCjrA7rQtiHtBr0EaZqvHFZvg==} + + '@chevrotain/regexp-to-ast@11.1.1': + resolution: {integrity: sha512-ctRw1OKSXkOrR8VTvOxrQ5USEc4sNrfwXHa1NuTcR7wre4YbjPcKw+82C2uylg/TEwFRgwLmbhlln4qkmDyteg==} + + '@chevrotain/types@11.1.1': + resolution: {integrity: sha512-wb2ToxG8LkgPYnKe9FH8oGn3TMCBdnwiuNC5l5y+CtlaVRbCytU0kbVsk6CGrqTL4ZN4ksJa0TXOYbxpbthtqw==} + + '@chevrotain/utils@11.1.1': + resolution: {integrity: sha512-71eTYMzYXYSFPrbg/ZwftSaSDld7UYlS8OQa3lNnn9jzNtpFbaReRRyghzqS7rI3CDaorqpPJJcXGHK+FE1TVQ==} + + '@clack/core@1.0.1': + resolution: {integrity: sha512-WKeyK3NOBwDOzagPR5H08rFk9D/WuN705yEbuZvKqlkmoLM2woKtXb10OO2k1NoSU4SFG947i2/SCYh+2u5e4g==} + + '@clack/prompts@1.0.1': + resolution: {integrity: sha512-/42G73JkuYdyWZ6m8d/CJtBrGl1Hegyc7Fy78m5Ob+jF85TOUmLR5XLce/U3LxYAw0kJ8CT5aI99RIvPHcGp/Q==} + + chevrotain@11.1.1: + resolution: {integrity: sha512-f0yv5CPKaFxfsPTBzX7vGuim4oIC1/gcS7LUGdBSwl2dU6+FON6LVUksdOo1qJjoUvXNn45urgh8C+0a24pACQ==} + + core-js-pure@3.48.0: + resolution: {integrity: sha512-1slJgk89tWC51HQ1AEqG+s2VuwpTRr8ocu4n20QUcH1v9lAN0RXen0Q0AABa/DK1I7RrNWLucplOHMx8hfTGTw==} + + js-toml@1.0.2: + resolution: {integrity: sha512-/7IQ//bzn2a/5IDazPUNzlW7bsjxS51cxciYZDR+Z+3Le60yzT0YfI8KOWqTtBcZkXXVklhWd2OuGd8ZksB0wQ==} + + lodash-es@4.17.23: + resolution: {integrity: sha512-kVI48u3PZr38HdYz98UmfPnXl2DXrpdctLrFLCd3kOx1xUkOmpFPx7gCWWM5MPkL/fD8zb+Ph0QzjGFs4+hHWg==} + + picocolors@1.1.1: + resolution: {integrity: sha512-xceH2snhtb5M9liqDsmEw56le376mTZkEX/jEb/RxNFyegNul7eNslCXP9FDj/Lcu0X8KEyMceP2ntpaHrDEVA==} + + sisteransi@1.0.5: + resolution: {integrity: sha512-bLGGlR1QxBcynn2d5YmDX4MGjlZvy2MRBDRNHLJ8VI6l6+9FUiyTFNJ0IveOSP0bcXgVDPRcfGqA0pjaqUpfVg==} + + toml@3.0.0: + resolution: {integrity: sha512-y/mWCZinnvxjTKYhJ+pYxwD0mRLVvOtdS2Awbgxln6iEnt4rk0yBxeSBHkGJcPucRiG0e55mwWp+g/05rsrd6w==} + + xregexp@5.1.2: + resolution: {integrity: sha512-6hGgEMCGhqCTFEJbqmWrNIPqfpdirdGWkqshu7fFZddmTSfgv5Sn9D2SaKloR79s5VUiUlpwzg3CM3G6D3VIlw==} + +snapshots: + + '@babel/runtime-corejs3@7.29.0': + dependencies: + core-js-pure: 3.48.0 + + '@chevrotain/cst-dts-gen@11.1.1': + dependencies: + '@chevrotain/gast': 11.1.1 + '@chevrotain/types': 11.1.1 + lodash-es: 4.17.23 + + '@chevrotain/gast@11.1.1': + dependencies: + '@chevrotain/types': 11.1.1 + lodash-es: 4.17.23 + + '@chevrotain/regexp-to-ast@11.1.1': {} + + '@chevrotain/types@11.1.1': {} + + '@chevrotain/utils@11.1.1': {} + + '@clack/core@1.0.1': + dependencies: + picocolors: 1.1.1 + sisteransi: 1.0.5 + + '@clack/prompts@1.0.1': + dependencies: + '@clack/core': 1.0.1 + picocolors: 1.1.1 + sisteransi: 1.0.5 + + chevrotain@11.1.1: + dependencies: + '@chevrotain/cst-dts-gen': 11.1.1 + '@chevrotain/gast': 11.1.1 + '@chevrotain/regexp-to-ast': 11.1.1 + '@chevrotain/types': 11.1.1 + '@chevrotain/utils': 11.1.1 + lodash-es: 4.17.23 + + core-js-pure@3.48.0: {} + + js-toml@1.0.2: + dependencies: + chevrotain: 11.1.1 + xregexp: 5.1.2 + + lodash-es@4.17.23: {} + + picocolors@1.1.1: {} + + sisteransi@1.0.5: {} + + toml@3.0.0: {} + + xregexp@5.1.2: + dependencies: + '@babel/runtime-corejs3': 7.29.0 diff --git a/util/config/README.md b/util/config/README.md index 27988ddd..a4faff53 100644 --- a/util/config/README.md +++ b/util/config/README.md @@ -8,7 +8,13 @@ The entrypoint is the `configurator/index.ts` file. It simply calls the configur All the logic is inside the `configurator/configurator.ts` file. Of course, you can add more files and change the structure as you see fit. -Inside the `configurator` folder, first install dependencies: +From the root of the project, go to the `util/config/configurator` folder: + +```bash +cd util/config/configurator +``` + +First install the dependencies: ```bash bun install @@ -20,6 +26,161 @@ In the `package.json` file there are a couple of scripts. The `start` script wil bun run start ``` +### How can the ops command be configured? + +Before understanding the configurator, let's see how you can manage the ops configuration. + +From the command line, run the following command: + +```bash +ops -config -d +``` + +it returns the configuration of `ops` command. The output is a text file containing a number of key-value tuples separated by an `=` sign and that looks like this: + +```terminaloutput + +S3_API_URL=http://localhost:9000 + +POSTGRES_PORT=5432 + +OPERATOR_COMPONENT_MILVUS=true +OPERATOR_COMPONENT_KAFKA=false + +S3_PROVIDER=minio + +``` + +You can also set the value of a single parameter by running: + +```bash +ops -config HELLO=123 +``` + +and read the value of a single parameter from the output of the command: + +```bash +ops -config HELLO +``` + +and remove the parameter by running: + +```bash +ops -config -r HELLO +``` + +Finally, you can check if a parameter doesn’t exist anymore by running: + +```bash +ops -config HELLO +``` + +which returns an error because you removed the parameter: + +```terminaloutput +error: invalid key: 'HELLO' - key does not exist +``` + +### How does the configurator work? + +Now that you know how you can manage the `ops` configuration, let's see how the configurator works. + +When you run the configurator with a valid configuration file, + +If you run the configurator without an argument to specify a configuration file, a help message is shown: + +```bash +bun run start +``` + +otherwise, you can specify a configuration file: + +```bash +bun run start your-configuraton-file.json +``` + +If the configuration file is valid, the configurator will run the command + +```bash +ops -config -d +``` + +and will compare the output with the configuration file. + +So, if you store the following content in a json file called `hello-config.json`: + +```json +{ + "HELLO": { + "type": "string" + } +} +``` + +the command + +```bash +ops util config /hello-config.json +``` + +launches an interactive configurator that sequentially reads the configuration file. +For each item found, it prompts the user to assign a value, then proceeds to execute the `ops -config ` command. + +For example, the `HELLO` parameter is of type `string` and the configurator asks for a value that it will assign to it: + +```terminaloutput +Enter value for HELLO (string) + +World +``` +and then the configurator runs the command: + +```terminaloutput +ops -config HELLO=World +``` + +This is how the configurator can interact with the `ops` command. + +## New functionality: show current configuration + +- Show the current configuration: + - show only the parameters needed for the components below: + - redis + - ferretdb + - cron + - prometheus + - slack + - mail + - affinity + - tolerations + - quota + - alert manager + + +To do this, we need to know for each component what are its parameters. + +### redis +$ ops -config -d grep -i REDIS + +To extract the names of the parameters, + +$ ops -config -d | awk -F= '/=/{print $1}' + + + + +### Development with WebStorm: + +Install and configure WebStorm to use the bun as described here: https://www.jetbrains.com/help/webstorm/bun.html + +#### To run the configurator with a valid config file from the command line: + +- change directory to `/util/config/configurator` +- run the following command: + ```bash + `ops util config `./tests/fixtures/valid.json + ``` + ### Tests: There are unit tests inside the `configurator/test` folder. You can run them with the following command: @@ -37,3 +198,17 @@ bun run build ``` It will generate the `configurator.js` file and move it in the parent, where it can be used by the opsfile task. + + + + +**** TODO SISTEMARE DA QUI + +```bash +cd /home/daniele/projects/github/apache/openserverless-task/util/config/configurator +``` + + +```bash +bun run start all-config-parameters.toml +``` diff --git a/util/config/configurator.js b/util/config/configurator.js deleted file mode 100644 index 5ba4c1e2..00000000 --- a/util/config/configurator.js +++ /dev/null @@ -1,906 +0,0 @@ -// @bun -var __create = Object.create; -var __getProtoOf = Object.getPrototypeOf; -var __defProp = Object.defineProperty; -var __getOwnPropNames = Object.getOwnPropertyNames; -var __hasOwnProp = Object.prototype.hasOwnProperty; -var __toESM = (mod, isNodeMode, target) => { - target = mod != null ? __create(__getProtoOf(mod)) : {}; - const to = isNodeMode || !mod || !mod.__esModule ? __defProp(target, "default", { value: mod, enumerable: true }) : target; - for (let key of __getOwnPropNames(mod)) - if (!__hasOwnProp.call(to, key)) - __defProp(to, key, { - get: () => mod[key], - enumerable: true - }); - return to; -}; -var __commonJS = (cb, mod) => () => (mod || cb((mod = { exports: {} }).exports, mod), mod.exports); - -// node_modules/sisteransi/src/index.js -var require_src = __commonJS((exports, module) => { - var ESC = "\x1B"; - var CSI = `${ESC}[`; - var beep = "\x07"; - var cursor = { - to(x, y) { - if (!y) - return `${CSI}${x + 1}G`; - return `${CSI}${y + 1};${x + 1}H`; - }, - move(x, y) { - let ret = ""; - if (x < 0) - ret += `${CSI}${-x}D`; - else if (x > 0) - ret += `${CSI}${x}C`; - if (y < 0) - ret += `${CSI}${-y}A`; - else if (y > 0) - ret += `${CSI}${y}B`; - return ret; - }, - up: (count = 1) => `${CSI}${count}A`, - down: (count = 1) => `${CSI}${count}B`, - forward: (count = 1) => `${CSI}${count}C`, - backward: (count = 1) => `${CSI}${count}D`, - nextLine: (count = 1) => `${CSI}E`.repeat(count), - prevLine: (count = 1) => `${CSI}F`.repeat(count), - left: `${CSI}G`, - hide: `${CSI}?25l`, - show: `${CSI}?25h`, - save: `${ESC}7`, - restore: `${ESC}8` - }; - var scroll = { - up: (count = 1) => `${CSI}S`.repeat(count), - down: (count = 1) => `${CSI}T`.repeat(count) - }; - var erase = { - screen: `${CSI}2J`, - up: (count = 1) => `${CSI}1J`.repeat(count), - down: (count = 1) => `${CSI}J`.repeat(count), - line: `${CSI}2K`, - lineEnd: `${CSI}K`, - lineStart: `${CSI}1K`, - lines(count) { - let clear = ""; - for (let i = 0;i < count; i++) - clear += this.line + (i < count - 1 ? cursor.up() : ""); - if (count) - clear += cursor.left; - return clear; - } - }; - module.exports = { cursor, scroll, erase, beep }; -}); - -// node_modules/picocolors/picocolors.js -var require_picocolors = __commonJS((exports, module) => { - var argv = process.argv || []; - var env = process.env; - var isColorSupported = !(("NO_COLOR" in env) || argv.includes("--no-color")) && (("FORCE_COLOR" in env) || argv.includes("--color") || process.platform === "win32" || import.meta.require != null && import.meta.require("tty").isatty(1) && env.TERM !== "dumb" || ("CI" in env)); - var formatter = (open, close, replace = open) => (input) => { - let string = "" + input; - let index = string.indexOf(close, open.length); - return ~index ? open + replaceClose(string, close, replace, index) + close : open + string + close; - }; - var replaceClose = (string, close, replace, index) => { - let result = ""; - let cursor = 0; - do { - result += string.substring(cursor, index) + replace; - cursor = index + close.length; - index = string.indexOf(close, cursor); - } while (~index); - return result + string.substring(cursor); - }; - var createColors = (enabled = isColorSupported) => { - let init = enabled ? formatter : () => String; - return { - isColorSupported: enabled, - reset: init("\x1B[0m", "\x1B[0m"), - bold: init("\x1B[1m", "\x1B[22m", "\x1B[22m\x1B[1m"), - dim: init("\x1B[2m", "\x1B[22m", "\x1B[22m\x1B[2m"), - italic: init("\x1B[3m", "\x1B[23m"), - underline: init("\x1B[4m", "\x1B[24m"), - inverse: init("\x1B[7m", "\x1B[27m"), - hidden: init("\x1B[8m", "\x1B[28m"), - strikethrough: init("\x1B[9m", "\x1B[29m"), - black: init("\x1B[30m", "\x1B[39m"), - red: init("\x1B[31m", "\x1B[39m"), - green: init("\x1B[32m", "\x1B[39m"), - yellow: init("\x1B[33m", "\x1B[39m"), - blue: init("\x1B[34m", "\x1B[39m"), - magenta: init("\x1B[35m", "\x1B[39m"), - cyan: init("\x1B[36m", "\x1B[39m"), - white: init("\x1B[37m", "\x1B[39m"), - gray: init("\x1B[90m", "\x1B[39m"), - bgBlack: init("\x1B[40m", "\x1B[49m"), - bgRed: init("\x1B[41m", "\x1B[49m"), - bgGreen: init("\x1B[42m", "\x1B[49m"), - bgYellow: init("\x1B[43m", "\x1B[49m"), - bgBlue: init("\x1B[44m", "\x1B[49m"), - bgMagenta: init("\x1B[45m", "\x1B[49m"), - bgCyan: init("\x1B[46m", "\x1B[49m"), - bgWhite: init("\x1B[47m", "\x1B[49m") - }; - }; - module.exports = createColors(); - module.exports.createColors = createColors; -}); - -// configurator.ts -var {$: $2 } = globalThis.Bun; - -// node_modules/@clack/core/dist/index.mjs -var import_sisteransi = __toESM(require_src(), 1); -import {stdin as $, stdout as k} from "process"; -var import_picocolors = __toESM(require_picocolors(), 1); -import _ from "readline"; -import {WriteStream as U} from "tty"; -function q({ onlyFirst: t = false } = {}) { - const u = ["[\\u001B\\u009B][[\\]()#;?]*(?:(?:(?:(?:;[-a-zA-Z\\d\\/#&.:=?%@~_]+)*|[a-zA-Z\\d]+(?:;[-a-zA-Z\\d\\/#&.:=?%@~_]*)*)?\\u0007)", "(?:(?:\\d{1,4}(?:;\\d{0,4})*)?[\\dA-PR-TZcf-ntqry=><~]))"].join("|"); - return new RegExp(u, t ? undefined : "g"); -} -function S(t) { - if (typeof t != "string") - throw new TypeError(`Expected a \`string\`, got \`${typeof t}\``); - return t.replace(q(), ""); -} -function j(t) { - return t && t.__esModule && Object.prototype.hasOwnProperty.call(t, "default") ? t.default : t; -} -function A(t, u = {}) { - if (typeof t != "string" || t.length === 0 || (u = { ambiguousIsNarrow: true, ...u }, t = S(t), t.length === 0)) - return 0; - t = t.replace(DD(), " "); - const F = u.ambiguousIsNarrow ? 1 : 2; - let e = 0; - for (const s of t) { - const C = s.codePointAt(0); - if (C <= 31 || C >= 127 && C <= 159 || C >= 768 && C <= 879) - continue; - switch (Q.eastAsianWidth(s)) { - case "F": - case "W": - e += 2; - break; - case "A": - e += F; - break; - default: - e += 1; - } - } - return e; -} -function tD() { - const t = new Map; - for (const [u, F] of Object.entries(r)) { - for (const [e, s] of Object.entries(F)) - r[e] = { open: `\x1B[${s[0]}m`, close: `\x1B[${s[1]}m` }, F[e] = r[e], t.set(s[0], s[1]); - Object.defineProperty(r, u, { value: F, enumerable: false }); - } - return Object.defineProperty(r, "codes", { value: t, enumerable: false }), r.color.close = "\x1B[39m", r.bgColor.close = "\x1B[49m", r.color.ansi = T(), r.color.ansi256 = P(), r.color.ansi16m = W(), r.bgColor.ansi = T(m), r.bgColor.ansi256 = P(m), r.bgColor.ansi16m = W(m), Object.defineProperties(r, { rgbToAnsi256: { value: (u, F, e) => u === F && F === e ? u < 8 ? 16 : u > 248 ? 231 : Math.round((u - 8) / 247 * 24) + 232 : 16 + 36 * Math.round(u / 255 * 5) + 6 * Math.round(F / 255 * 5) + Math.round(e / 255 * 5), enumerable: false }, hexToRgb: { value: (u) => { - const F = /[a-f\d]{6}|[a-f\d]{3}/i.exec(u.toString(16)); - if (!F) - return [0, 0, 0]; - let [e] = F; - e.length === 3 && (e = [...e].map((C) => C + C).join("")); - const s = Number.parseInt(e, 16); - return [s >> 16 & 255, s >> 8 & 255, s & 255]; - }, enumerable: false }, hexToAnsi256: { value: (u) => r.rgbToAnsi256(...r.hexToRgb(u)), enumerable: false }, ansi256ToAnsi: { value: (u) => { - if (u < 8) - return 30 + u; - if (u < 16) - return 90 + (u - 8); - let F, e, s; - if (u >= 232) - F = ((u - 232) * 10 + 8) / 255, e = F, s = F; - else { - u -= 16; - const i = u % 36; - F = Math.floor(u / 36) / 5, e = Math.floor(i / 6) / 5, s = i % 6 / 5; - } - const C = Math.max(F, e, s) * 2; - if (C === 0) - return 30; - let D = 30 + (Math.round(s) << 2 | Math.round(e) << 1 | Math.round(F)); - return C === 2 && (D += 60), D; - }, enumerable: false }, rgbToAnsi: { value: (u, F, e) => r.ansi256ToAnsi(r.rgbToAnsi256(u, F, e)), enumerable: false }, hexToAnsi: { value: (u) => r.ansi256ToAnsi(r.hexToAnsi256(u)), enumerable: false } }), r; -} -function R(t, u, F) { - return String(t).normalize().replace(/\r\n/g, ` -`).split(` -`).map((e) => ED(e, u, F)).join(` -`); -} -function aD(t, u) { - if (t === u) - return; - const F = t.split(` -`), e = u.split(` -`), s = []; - for (let C = 0;C < Math.max(F.length, e.length); C++) - F[C] !== e[C] && s.push(C); - return s; -} -function hD(t) { - return t === V; -} -function v(t, u) { - t.isTTY && t.setRawMode(u); -} -var M = { exports: {} }; -(function(t) { - var u = {}; - t.exports = u, u.eastAsianWidth = function(e) { - var s = e.charCodeAt(0), C = e.length == 2 ? e.charCodeAt(1) : 0, D = s; - return 55296 <= s && s <= 56319 && 56320 <= C && C <= 57343 && (s &= 1023, C &= 1023, D = s << 10 | C, D += 65536), D == 12288 || 65281 <= D && D <= 65376 || 65504 <= D && D <= 65510 ? "F" : D == 8361 || 65377 <= D && D <= 65470 || 65474 <= D && D <= 65479 || 65482 <= D && D <= 65487 || 65490 <= D && D <= 65495 || 65498 <= D && D <= 65500 || 65512 <= D && D <= 65518 ? "H" : 4352 <= D && D <= 4447 || 4515 <= D && D <= 4519 || 4602 <= D && D <= 4607 || 9001 <= D && D <= 9002 || 11904 <= D && D <= 11929 || 11931 <= D && D <= 12019 || 12032 <= D && D <= 12245 || 12272 <= D && D <= 12283 || 12289 <= D && D <= 12350 || 12353 <= D && D <= 12438 || 12441 <= D && D <= 12543 || 12549 <= D && D <= 12589 || 12593 <= D && D <= 12686 || 12688 <= D && D <= 12730 || 12736 <= D && D <= 12771 || 12784 <= D && D <= 12830 || 12832 <= D && D <= 12871 || 12880 <= D && D <= 13054 || 13056 <= D && D <= 19903 || 19968 <= D && D <= 42124 || 42128 <= D && D <= 42182 || 43360 <= D && D <= 43388 || 44032 <= D && D <= 55203 || 55216 <= D && D <= 55238 || 55243 <= D && D <= 55291 || 63744 <= D && D <= 64255 || 65040 <= D && D <= 65049 || 65072 <= D && D <= 65106 || 65108 <= D && D <= 65126 || 65128 <= D && D <= 65131 || 110592 <= D && D <= 110593 || 127488 <= D && D <= 127490 || 127504 <= D && D <= 127546 || 127552 <= D && D <= 127560 || 127568 <= D && D <= 127569 || 131072 <= D && D <= 194367 || 177984 <= D && D <= 196605 || 196608 <= D && D <= 262141 ? "W" : 32 <= D && D <= 126 || 162 <= D && D <= 163 || 165 <= D && D <= 166 || D == 172 || D == 175 || 10214 <= D && D <= 10221 || 10629 <= D && D <= 10630 ? "Na" : D == 161 || D == 164 || 167 <= D && D <= 168 || D == 170 || 173 <= D && D <= 174 || 176 <= D && D <= 180 || 182 <= D && D <= 186 || 188 <= D && D <= 191 || D == 198 || D == 208 || 215 <= D && D <= 216 || 222 <= D && D <= 225 || D == 230 || 232 <= D && D <= 234 || 236 <= D && D <= 237 || D == 240 || 242 <= D && D <= 243 || 247 <= D && D <= 250 || D == 252 || D == 254 || D == 257 || D == 273 || D == 275 || D == 283 || 294 <= D && D <= 295 || D == 299 || 305 <= D && D <= 307 || D == 312 || 319 <= D && D <= 322 || D == 324 || 328 <= D && D <= 331 || D == 333 || 338 <= D && D <= 339 || 358 <= D && D <= 359 || D == 363 || D == 462 || D == 464 || D == 466 || D == 468 || D == 470 || D == 472 || D == 474 || D == 476 || D == 593 || D == 609 || D == 708 || D == 711 || 713 <= D && D <= 715 || D == 717 || D == 720 || 728 <= D && D <= 731 || D == 733 || D == 735 || 768 <= D && D <= 879 || 913 <= D && D <= 929 || 931 <= D && D <= 937 || 945 <= D && D <= 961 || 963 <= D && D <= 969 || D == 1025 || 1040 <= D && D <= 1103 || D == 1105 || D == 8208 || 8211 <= D && D <= 8214 || 8216 <= D && D <= 8217 || 8220 <= D && D <= 8221 || 8224 <= D && D <= 8226 || 8228 <= D && D <= 8231 || D == 8240 || 8242 <= D && D <= 8243 || D == 8245 || D == 8251 || D == 8254 || D == 8308 || D == 8319 || 8321 <= D && D <= 8324 || D == 8364 || D == 8451 || D == 8453 || D == 8457 || D == 8467 || D == 8470 || 8481 <= D && D <= 8482 || D == 8486 || D == 8491 || 8531 <= D && D <= 8532 || 8539 <= D && D <= 8542 || 8544 <= D && D <= 8555 || 8560 <= D && D <= 8569 || D == 8585 || 8592 <= D && D <= 8601 || 8632 <= D && D <= 8633 || D == 8658 || D == 8660 || D == 8679 || D == 8704 || 8706 <= D && D <= 8707 || 8711 <= D && D <= 8712 || D == 8715 || D == 8719 || D == 8721 || D == 8725 || D == 8730 || 8733 <= D && D <= 8736 || D == 8739 || D == 8741 || 8743 <= D && D <= 8748 || D == 8750 || 8756 <= D && D <= 8759 || 8764 <= D && D <= 8765 || D == 8776 || D == 8780 || D == 8786 || 8800 <= D && D <= 8801 || 8804 <= D && D <= 8807 || 8810 <= D && D <= 8811 || 8814 <= D && D <= 8815 || 8834 <= D && D <= 8835 || 8838 <= D && D <= 8839 || D == 8853 || D == 8857 || D == 8869 || D == 8895 || D == 8978 || 9312 <= D && D <= 9449 || 9451 <= D && D <= 9547 || 9552 <= D && D <= 9587 || 9600 <= D && D <= 9615 || 9618 <= D && D <= 9621 || 9632 <= D && D <= 9633 || 9635 <= D && D <= 9641 || 9650 <= D && D <= 9651 || 9654 <= D && D <= 9655 || 9660 <= D && D <= 9661 || 9664 <= D && D <= 9665 || 9670 <= D && D <= 9672 || D == 9675 || 9678 <= D && D <= 9681 || 9698 <= D && D <= 9701 || D == 9711 || 9733 <= D && D <= 9734 || D == 9737 || 9742 <= D && D <= 9743 || 9748 <= D && D <= 9749 || D == 9756 || D == 9758 || D == 9792 || D == 9794 || 9824 <= D && D <= 9825 || 9827 <= D && D <= 9829 || 9831 <= D && D <= 9834 || 9836 <= D && D <= 9837 || D == 9839 || 9886 <= D && D <= 9887 || 9918 <= D && D <= 9919 || 9924 <= D && D <= 9933 || 9935 <= D && D <= 9953 || D == 9955 || 9960 <= D && D <= 9983 || D == 10045 || D == 10071 || 10102 <= D && D <= 10111 || 11093 <= D && D <= 11097 || 12872 <= D && D <= 12879 || 57344 <= D && D <= 63743 || 65024 <= D && D <= 65039 || D == 65533 || 127232 <= D && D <= 127242 || 127248 <= D && D <= 127277 || 127280 <= D && D <= 127337 || 127344 <= D && D <= 127386 || 917760 <= D && D <= 917999 || 983040 <= D && D <= 1048573 || 1048576 <= D && D <= 1114109 ? "A" : "N"; - }, u.characterLength = function(e) { - var s = this.eastAsianWidth(e); - return s == "F" || s == "W" || s == "A" ? 2 : 1; - }; - function F(e) { - return e.match(/[\uD800-\uDBFF][\uDC00-\uDFFF]|[^\uD800-\uDFFF]/g) || []; - } - u.length = function(e) { - for (var s = F(e), C = 0, D = 0;D < s.length; D++) - C = C + this.characterLength(s[D]); - return C; - }, u.slice = function(e, s, C) { - textLen = u.length(e), s = s || 0, C = C || 1, s < 0 && (s = textLen + s), C < 0 && (C = textLen + C); - for (var D = "", i = 0, n = F(e), E = 0;E < n.length; E++) { - var h = n[E], o = u.length(h); - if (i >= s - (o == 2 ? 1 : 0)) - if (i + o <= C) - D += h; - else - break; - i += o; - } - return D; - }; -})(M); -var J = M.exports; -var Q = j(J); -var X = function() { - return /\uD83C\uDFF4\uDB40\uDC67\uDB40\uDC62(?:\uDB40\uDC77\uDB40\uDC6C\uDB40\uDC73|\uDB40\uDC73\uDB40\uDC63\uDB40\uDC74|\uDB40\uDC65\uDB40\uDC6E\uDB40\uDC67)\uDB40\uDC7F|(?:\uD83E\uDDD1\uD83C\uDFFF\u200D\u2764\uFE0F\u200D(?:\uD83D\uDC8B\u200D)?\uD83E\uDDD1|\uD83D\uDC69\uD83C\uDFFF\u200D\uD83E\uDD1D\u200D(?:\uD83D[\uDC68\uDC69]))(?:\uD83C[\uDFFB-\uDFFE])|(?:\uD83E\uDDD1\uD83C\uDFFE\u200D\u2764\uFE0F\u200D(?:\uD83D\uDC8B\u200D)?\uD83E\uDDD1|\uD83D\uDC69\uD83C\uDFFE\u200D\uD83E\uDD1D\u200D(?:\uD83D[\uDC68\uDC69]))(?:\uD83C[\uDFFB-\uDFFD\uDFFF])|(?:\uD83E\uDDD1\uD83C\uDFFD\u200D\u2764\uFE0F\u200D(?:\uD83D\uDC8B\u200D)?\uD83E\uDDD1|\uD83D\uDC69\uD83C\uDFFD\u200D\uD83E\uDD1D\u200D(?:\uD83D[\uDC68\uDC69]))(?:\uD83C[\uDFFB\uDFFC\uDFFE\uDFFF])|(?:\uD83E\uDDD1\uD83C\uDFFC\u200D\u2764\uFE0F\u200D(?:\uD83D\uDC8B\u200D)?\uD83E\uDDD1|\uD83D\uDC69\uD83C\uDFFC\u200D\uD83E\uDD1D\u200D(?:\uD83D[\uDC68\uDC69]))(?:\uD83C[\uDFFB\uDFFD-\uDFFF])|(?:\uD83E\uDDD1\uD83C\uDFFB\u200D\u2764\uFE0F\u200D(?:\uD83D\uDC8B\u200D)?\uD83E\uDDD1|\uD83D\uDC69\uD83C\uDFFB\u200D\uD83E\uDD1D\u200D(?:\uD83D[\uDC68\uDC69]))(?:\uD83C[\uDFFC-\uDFFF])|\uD83D\uDC68(?:\uD83C\uDFFB(?:\u200D(?:\u2764\uFE0F\u200D(?:\uD83D\uDC8B\u200D\uD83D\uDC68(?:\uD83C[\uDFFB-\uDFFF])|\uD83D\uDC68(?:\uD83C[\uDFFB-\uDFFF]))|\uD83E\uDD1D\u200D\uD83D\uDC68(?:\uD83C[\uDFFC-\uDFFF])|[\u2695\u2696\u2708]\uFE0F|\uD83C[\uDF3E\uDF73\uDF7C\uDF93\uDFA4\uDFA8\uDFEB\uDFED]|\uD83D[\uDCBB\uDCBC\uDD27\uDD2C\uDE80\uDE92]|\uD83E[\uDDAF-\uDDB3\uDDBC\uDDBD]))?|(?:\uD83C[\uDFFC-\uDFFF])\u200D\u2764\uFE0F\u200D(?:\uD83D\uDC8B\u200D\uD83D\uDC68(?:\uD83C[\uDFFB-\uDFFF])|\uD83D\uDC68(?:\uD83C[\uDFFB-\uDFFF]))|\u200D(?:\u2764\uFE0F\u200D(?:\uD83D\uDC8B\u200D)?\uD83D\uDC68|(?:\uD83D[\uDC68\uDC69])\u200D(?:\uD83D\uDC66\u200D\uD83D\uDC66|\uD83D\uDC67\u200D(?:\uD83D[\uDC66\uDC67]))|\uD83D\uDC66\u200D\uD83D\uDC66|\uD83D\uDC67\u200D(?:\uD83D[\uDC66\uDC67])|\uD83C[\uDF3E\uDF73\uDF7C\uDF93\uDFA4\uDFA8\uDFEB\uDFED]|\uD83D[\uDCBB\uDCBC\uDD27\uDD2C\uDE80\uDE92]|\uD83E[\uDDAF-\uDDB3\uDDBC\uDDBD])|\uD83C\uDFFF\u200D(?:\uD83E\uDD1D\u200D\uD83D\uDC68(?:\uD83C[\uDFFB-\uDFFE])|\uD83C[\uDF3E\uDF73\uDF7C\uDF93\uDFA4\uDFA8\uDFEB\uDFED]|\uD83D[\uDCBB\uDCBC\uDD27\uDD2C\uDE80\uDE92]|\uD83E[\uDDAF-\uDDB3\uDDBC\uDDBD])|\uD83C\uDFFE\u200D(?:\uD83E\uDD1D\u200D\uD83D\uDC68(?:\uD83C[\uDFFB-\uDFFD\uDFFF])|\uD83C[\uDF3E\uDF73\uDF7C\uDF93\uDFA4\uDFA8\uDFEB\uDFED]|\uD83D[\uDCBB\uDCBC\uDD27\uDD2C\uDE80\uDE92]|\uD83E[\uDDAF-\uDDB3\uDDBC\uDDBD])|\uD83C\uDFFD\u200D(?:\uD83E\uDD1D\u200D\uD83D\uDC68(?:\uD83C[\uDFFB\uDFFC\uDFFE\uDFFF])|\uD83C[\uDF3E\uDF73\uDF7C\uDF93\uDFA4\uDFA8\uDFEB\uDFED]|\uD83D[\uDCBB\uDCBC\uDD27\uDD2C\uDE80\uDE92]|\uD83E[\uDDAF-\uDDB3\uDDBC\uDDBD])|\uD83C\uDFFC\u200D(?:\uD83E\uDD1D\u200D\uD83D\uDC68(?:\uD83C[\uDFFB\uDFFD-\uDFFF])|\uD83C[\uDF3E\uDF73\uDF7C\uDF93\uDFA4\uDFA8\uDFEB\uDFED]|\uD83D[\uDCBB\uDCBC\uDD27\uDD2C\uDE80\uDE92]|\uD83E[\uDDAF-\uDDB3\uDDBC\uDDBD])|(?:\uD83C\uDFFF\u200D[\u2695\u2696\u2708]|\uD83C\uDFFE\u200D[\u2695\u2696\u2708]|\uD83C\uDFFD\u200D[\u2695\u2696\u2708]|\uD83C\uDFFC\u200D[\u2695\u2696\u2708]|\u200D[\u2695\u2696\u2708])\uFE0F|\u200D(?:(?:\uD83D[\uDC68\uDC69])\u200D(?:\uD83D[\uDC66\uDC67])|\uD83D[\uDC66\uDC67])|\uD83C\uDFFF|\uD83C\uDFFE|\uD83C\uDFFD|\uD83C\uDFFC)?|(?:\uD83D\uDC69(?:\uD83C\uDFFB\u200D\u2764\uFE0F\u200D(?:\uD83D\uDC8B\u200D(?:\uD83D[\uDC68\uDC69])|\uD83D[\uDC68\uDC69])|(?:\uD83C[\uDFFC-\uDFFF])\u200D\u2764\uFE0F\u200D(?:\uD83D\uDC8B\u200D(?:\uD83D[\uDC68\uDC69])|\uD83D[\uDC68\uDC69]))|\uD83E\uDDD1(?:\uD83C[\uDFFB-\uDFFF])\u200D\uD83E\uDD1D\u200D\uD83E\uDDD1)(?:\uD83C[\uDFFB-\uDFFF])|\uD83D\uDC69\u200D\uD83D\uDC69\u200D(?:\uD83D\uDC66\u200D\uD83D\uDC66|\uD83D\uDC67\u200D(?:\uD83D[\uDC66\uDC67]))|\uD83D\uDC69(?:\u200D(?:\u2764\uFE0F\u200D(?:\uD83D\uDC8B\u200D(?:\uD83D[\uDC68\uDC69])|\uD83D[\uDC68\uDC69])|\uD83C[\uDF3E\uDF73\uDF7C\uDF93\uDFA4\uDFA8\uDFEB\uDFED]|\uD83D[\uDCBB\uDCBC\uDD27\uDD2C\uDE80\uDE92]|\uD83E[\uDDAF-\uDDB3\uDDBC\uDDBD])|\uD83C\uDFFF\u200D(?:\uD83C[\uDF3E\uDF73\uDF7C\uDF93\uDFA4\uDFA8\uDFEB\uDFED]|\uD83D[\uDCBB\uDCBC\uDD27\uDD2C\uDE80\uDE92]|\uD83E[\uDDAF-\uDDB3\uDDBC\uDDBD])|\uD83C\uDFFE\u200D(?:\uD83C[\uDF3E\uDF73\uDF7C\uDF93\uDFA4\uDFA8\uDFEB\uDFED]|\uD83D[\uDCBB\uDCBC\uDD27\uDD2C\uDE80\uDE92]|\uD83E[\uDDAF-\uDDB3\uDDBC\uDDBD])|\uD83C\uDFFD\u200D(?:\uD83C[\uDF3E\uDF73\uDF7C\uDF93\uDFA4\uDFA8\uDFEB\uDFED]|\uD83D[\uDCBB\uDCBC\uDD27\uDD2C\uDE80\uDE92]|\uD83E[\uDDAF-\uDDB3\uDDBC\uDDBD])|\uD83C\uDFFC\u200D(?:\uD83C[\uDF3E\uDF73\uDF7C\uDF93\uDFA4\uDFA8\uDFEB\uDFED]|\uD83D[\uDCBB\uDCBC\uDD27\uDD2C\uDE80\uDE92]|\uD83E[\uDDAF-\uDDB3\uDDBC\uDDBD])|\uD83C\uDFFB\u200D(?:\uD83C[\uDF3E\uDF73\uDF7C\uDF93\uDFA4\uDFA8\uDFEB\uDFED]|\uD83D[\uDCBB\uDCBC\uDD27\uDD2C\uDE80\uDE92]|\uD83E[\uDDAF-\uDDB3\uDDBC\uDDBD]))|\uD83E\uDDD1(?:\u200D(?:\uD83E\uDD1D\u200D\uD83E\uDDD1|\uD83C[\uDF3E\uDF73\uDF7C\uDF84\uDF93\uDFA4\uDFA8\uDFEB\uDFED]|\uD83D[\uDCBB\uDCBC\uDD27\uDD2C\uDE80\uDE92]|\uD83E[\uDDAF-\uDDB3\uDDBC\uDDBD])|\uD83C\uDFFF\u200D(?:\uD83C[\uDF3E\uDF73\uDF7C\uDF84\uDF93\uDFA4\uDFA8\uDFEB\uDFED]|\uD83D[\uDCBB\uDCBC\uDD27\uDD2C\uDE80\uDE92]|\uD83E[\uDDAF-\uDDB3\uDDBC\uDDBD])|\uD83C\uDFFE\u200D(?:\uD83C[\uDF3E\uDF73\uDF7C\uDF84\uDF93\uDFA4\uDFA8\uDFEB\uDFED]|\uD83D[\uDCBB\uDCBC\uDD27\uDD2C\uDE80\uDE92]|\uD83E[\uDDAF-\uDDB3\uDDBC\uDDBD])|\uD83C\uDFFD\u200D(?:\uD83C[\uDF3E\uDF73\uDF7C\uDF84\uDF93\uDFA4\uDFA8\uDFEB\uDFED]|\uD83D[\uDCBB\uDCBC\uDD27\uDD2C\uDE80\uDE92]|\uD83E[\uDDAF-\uDDB3\uDDBC\uDDBD])|\uD83C\uDFFC\u200D(?:\uD83C[\uDF3E\uDF73\uDF7C\uDF84\uDF93\uDFA4\uDFA8\uDFEB\uDFED]|\uD83D[\uDCBB\uDCBC\uDD27\uDD2C\uDE80\uDE92]|\uD83E[\uDDAF-\uDDB3\uDDBC\uDDBD])|\uD83C\uDFFB\u200D(?:\uD83C[\uDF3E\uDF73\uDF7C\uDF84\uDF93\uDFA4\uDFA8\uDFEB\uDFED]|\uD83D[\uDCBB\uDCBC\uDD27\uDD2C\uDE80\uDE92]|\uD83E[\uDDAF-\uDDB3\uDDBC\uDDBD]))|\uD83D\uDC69\u200D\uD83D\uDC66\u200D\uD83D\uDC66|\uD83D\uDC69\u200D\uD83D\uDC69\u200D(?:\uD83D[\uDC66\uDC67])|\uD83D\uDC69\u200D\uD83D\uDC67\u200D(?:\uD83D[\uDC66\uDC67])|(?:\uD83D\uDC41\uFE0F\u200D\uD83D\uDDE8|\uD83E\uDDD1(?:\uD83C\uDFFF\u200D[\u2695\u2696\u2708]|\uD83C\uDFFE\u200D[\u2695\u2696\u2708]|\uD83C\uDFFD\u200D[\u2695\u2696\u2708]|\uD83C\uDFFC\u200D[\u2695\u2696\u2708]|\uD83C\uDFFB\u200D[\u2695\u2696\u2708]|\u200D[\u2695\u2696\u2708])|\uD83D\uDC69(?:\uD83C\uDFFF\u200D[\u2695\u2696\u2708]|\uD83C\uDFFE\u200D[\u2695\u2696\u2708]|\uD83C\uDFFD\u200D[\u2695\u2696\u2708]|\uD83C\uDFFC\u200D[\u2695\u2696\u2708]|\uD83C\uDFFB\u200D[\u2695\u2696\u2708]|\u200D[\u2695\u2696\u2708])|\uD83D\uDE36\u200D\uD83C\uDF2B|\uD83C\uDFF3\uFE0F\u200D\u26A7|\uD83D\uDC3B\u200D\u2744|(?:(?:\uD83C[\uDFC3\uDFC4\uDFCA]|\uD83D[\uDC6E\uDC70\uDC71\uDC73\uDC77\uDC81\uDC82\uDC86\uDC87\uDE45-\uDE47\uDE4B\uDE4D\uDE4E\uDEA3\uDEB4-\uDEB6]|\uD83E[\uDD26\uDD35\uDD37-\uDD39\uDD3D\uDD3E\uDDB8\uDDB9\uDDCD-\uDDCF\uDDD4\uDDD6-\uDDDD])(?:\uD83C[\uDFFB-\uDFFF])|\uD83D\uDC6F|\uD83E[\uDD3C\uDDDE\uDDDF])\u200D[\u2640\u2642]|(?:\u26F9|\uD83C[\uDFCB\uDFCC]|\uD83D\uDD75)(?:\uFE0F|\uD83C[\uDFFB-\uDFFF])\u200D[\u2640\u2642]|\uD83C\uDFF4\u200D\u2620|(?:\uD83C[\uDFC3\uDFC4\uDFCA]|\uD83D[\uDC6E\uDC70\uDC71\uDC73\uDC77\uDC81\uDC82\uDC86\uDC87\uDE45-\uDE47\uDE4B\uDE4D\uDE4E\uDEA3\uDEB4-\uDEB6]|\uD83E[\uDD26\uDD35\uDD37-\uDD39\uDD3D\uDD3E\uDDB8\uDDB9\uDDCD-\uDDCF\uDDD4\uDDD6-\uDDDD])\u200D[\u2640\u2642]|[\xA9\xAE\u203C\u2049\u2122\u2139\u2194-\u2199\u21A9\u21AA\u2328\u23CF\u23ED-\u23EF\u23F1\u23F2\u23F8-\u23FA\u24C2\u25AA\u25AB\u25B6\u25C0\u25FB\u25FC\u2600-\u2604\u260E\u2611\u2618\u2620\u2622\u2623\u2626\u262A\u262E\u262F\u2638-\u263A\u2640\u2642\u265F\u2660\u2663\u2665\u2666\u2668\u267B\u267E\u2692\u2694-\u2697\u2699\u269B\u269C\u26A0\u26A7\u26B0\u26B1\u26C8\u26CF\u26D1\u26D3\u26E9\u26F0\u26F1\u26F4\u26F7\u26F8\u2702\u2708\u2709\u270F\u2712\u2714\u2716\u271D\u2721\u2733\u2734\u2744\u2747\u2763\u27A1\u2934\u2935\u2B05-\u2B07\u3030\u303D\u3297\u3299]|\uD83C[\uDD70\uDD71\uDD7E\uDD7F\uDE02\uDE37\uDF21\uDF24-\uDF2C\uDF36\uDF7D\uDF96\uDF97\uDF99-\uDF9B\uDF9E\uDF9F\uDFCD\uDFCE\uDFD4-\uDFDF\uDFF5\uDFF7]|\uD83D[\uDC3F\uDCFD\uDD49\uDD4A\uDD6F\uDD70\uDD73\uDD76-\uDD79\uDD87\uDD8A-\uDD8D\uDDA5\uDDA8\uDDB1\uDDB2\uDDBC\uDDC2-\uDDC4\uDDD1-\uDDD3\uDDDC-\uDDDE\uDDE1\uDDE3\uDDE8\uDDEF\uDDF3\uDDFA\uDECB\uDECD-\uDECF\uDEE0-\uDEE5\uDEE9\uDEF0\uDEF3])\uFE0F|\uD83C\uDFF3\uFE0F\u200D\uD83C\uDF08|\uD83D\uDC69\u200D\uD83D\uDC67|\uD83D\uDC69\u200D\uD83D\uDC66|\uD83D\uDE35\u200D\uD83D\uDCAB|\uD83D\uDE2E\u200D\uD83D\uDCA8|\uD83D\uDC15\u200D\uD83E\uDDBA|\uD83E\uDDD1(?:\uD83C\uDFFF|\uD83C\uDFFE|\uD83C\uDFFD|\uD83C\uDFFC|\uD83C\uDFFB)?|\uD83D\uDC69(?:\uD83C\uDFFF|\uD83C\uDFFE|\uD83C\uDFFD|\uD83C\uDFFC|\uD83C\uDFFB)?|\uD83C\uDDFD\uD83C\uDDF0|\uD83C\uDDF6\uD83C\uDDE6|\uD83C\uDDF4\uD83C\uDDF2|\uD83D\uDC08\u200D\u2B1B|\u2764\uFE0F\u200D(?:\uD83D\uDD25|\uD83E\uDE79)|\uD83D\uDC41\uFE0F|\uD83C\uDFF3\uFE0F|\uD83C\uDDFF(?:\uD83C[\uDDE6\uDDF2\uDDFC])|\uD83C\uDDFE(?:\uD83C[\uDDEA\uDDF9])|\uD83C\uDDFC(?:\uD83C[\uDDEB\uDDF8])|\uD83C\uDDFB(?:\uD83C[\uDDE6\uDDE8\uDDEA\uDDEC\uDDEE\uDDF3\uDDFA])|\uD83C\uDDFA(?:\uD83C[\uDDE6\uDDEC\uDDF2\uDDF3\uDDF8\uDDFE\uDDFF])|\uD83C\uDDF9(?:\uD83C[\uDDE6\uDDE8\uDDE9\uDDEB-\uDDED\uDDEF-\uDDF4\uDDF7\uDDF9\uDDFB\uDDFC\uDDFF])|\uD83C\uDDF8(?:\uD83C[\uDDE6-\uDDEA\uDDEC-\uDDF4\uDDF7-\uDDF9\uDDFB\uDDFD-\uDDFF])|\uD83C\uDDF7(?:\uD83C[\uDDEA\uDDF4\uDDF8\uDDFA\uDDFC])|\uD83C\uDDF5(?:\uD83C[\uDDE6\uDDEA-\uDDED\uDDF0-\uDDF3\uDDF7-\uDDF9\uDDFC\uDDFE])|\uD83C\uDDF3(?:\uD83C[\uDDE6\uDDE8\uDDEA-\uDDEC\uDDEE\uDDF1\uDDF4\uDDF5\uDDF7\uDDFA\uDDFF])|\uD83C\uDDF2(?:\uD83C[\uDDE6\uDDE8-\uDDED\uDDF0-\uDDFF])|\uD83C\uDDF1(?:\uD83C[\uDDE6-\uDDE8\uDDEE\uDDF0\uDDF7-\uDDFB\uDDFE])|\uD83C\uDDF0(?:\uD83C[\uDDEA\uDDEC-\uDDEE\uDDF2\uDDF3\uDDF5\uDDF7\uDDFC\uDDFE\uDDFF])|\uD83C\uDDEF(?:\uD83C[\uDDEA\uDDF2\uDDF4\uDDF5])|\uD83C\uDDEE(?:\uD83C[\uDDE8-\uDDEA\uDDF1-\uDDF4\uDDF6-\uDDF9])|\uD83C\uDDED(?:\uD83C[\uDDF0\uDDF2\uDDF3\uDDF7\uDDF9\uDDFA])|\uD83C\uDDEC(?:\uD83C[\uDDE6\uDDE7\uDDE9-\uDDEE\uDDF1-\uDDF3\uDDF5-\uDDFA\uDDFC\uDDFE])|\uD83C\uDDEB(?:\uD83C[\uDDEE-\uDDF0\uDDF2\uDDF4\uDDF7])|\uD83C\uDDEA(?:\uD83C[\uDDE6\uDDE8\uDDEA\uDDEC\uDDED\uDDF7-\uDDFA])|\uD83C\uDDE9(?:\uD83C[\uDDEA\uDDEC\uDDEF\uDDF0\uDDF2\uDDF4\uDDFF])|\uD83C\uDDE8(?:\uD83C[\uDDE6\uDDE8\uDDE9\uDDEB-\uDDEE\uDDF0-\uDDF5\uDDF7\uDDFA-\uDDFF])|\uD83C\uDDE7(?:\uD83C[\uDDE6\uDDE7\uDDE9-\uDDEF\uDDF1-\uDDF4\uDDF6-\uDDF9\uDDFB\uDDFC\uDDFE\uDDFF])|\uD83C\uDDE6(?:\uD83C[\uDDE8-\uDDEC\uDDEE\uDDF1\uDDF2\uDDF4\uDDF6-\uDDFA\uDDFC\uDDFD\uDDFF])|[#\*0-9]\uFE0F\u20E3|\u2764\uFE0F|(?:\uD83C[\uDFC3\uDFC4\uDFCA]|\uD83D[\uDC6E\uDC70\uDC71\uDC73\uDC77\uDC81\uDC82\uDC86\uDC87\uDE45-\uDE47\uDE4B\uDE4D\uDE4E\uDEA3\uDEB4-\uDEB6]|\uD83E[\uDD26\uDD35\uDD37-\uDD39\uDD3D\uDD3E\uDDB8\uDDB9\uDDCD-\uDDCF\uDDD4\uDDD6-\uDDDD])(?:\uD83C[\uDFFB-\uDFFF])|(?:\u26F9|\uD83C[\uDFCB\uDFCC]|\uD83D\uDD75)(?:\uFE0F|\uD83C[\uDFFB-\uDFFF])|\uD83C\uDFF4|(?:[\u270A\u270B]|\uD83C[\uDF85\uDFC2\uDFC7]|\uD83D[\uDC42\uDC43\uDC46-\uDC50\uDC66\uDC67\uDC6B-\uDC6D\uDC72\uDC74-\uDC76\uDC78\uDC7C\uDC83\uDC85\uDC8F\uDC91\uDCAA\uDD7A\uDD95\uDD96\uDE4C\uDE4F\uDEC0\uDECC]|\uD83E[\uDD0C\uDD0F\uDD18-\uDD1C\uDD1E\uDD1F\uDD30-\uDD34\uDD36\uDD77\uDDB5\uDDB6\uDDBB\uDDD2\uDDD3\uDDD5])(?:\uD83C[\uDFFB-\uDFFF])|(?:[\u261D\u270C\u270D]|\uD83D[\uDD74\uDD90])(?:\uFE0F|\uD83C[\uDFFB-\uDFFF])|[\u270A\u270B]|\uD83C[\uDF85\uDFC2\uDFC7]|\uD83D[\uDC08\uDC15\uDC3B\uDC42\uDC43\uDC46-\uDC50\uDC66\uDC67\uDC6B-\uDC6D\uDC72\uDC74-\uDC76\uDC78\uDC7C\uDC83\uDC85\uDC8F\uDC91\uDCAA\uDD7A\uDD95\uDD96\uDE2E\uDE35\uDE36\uDE4C\uDE4F\uDEC0\uDECC]|\uD83E[\uDD0C\uDD0F\uDD18-\uDD1C\uDD1E\uDD1F\uDD30-\uDD34\uDD36\uDD77\uDDB5\uDDB6\uDDBB\uDDD2\uDDD3\uDDD5]|\uD83C[\uDFC3\uDFC4\uDFCA]|\uD83D[\uDC6E\uDC70\uDC71\uDC73\uDC77\uDC81\uDC82\uDC86\uDC87\uDE45-\uDE47\uDE4B\uDE4D\uDE4E\uDEA3\uDEB4-\uDEB6]|\uD83E[\uDD26\uDD35\uDD37-\uDD39\uDD3D\uDD3E\uDDB8\uDDB9\uDDCD-\uDDCF\uDDD4\uDDD6-\uDDDD]|\uD83D\uDC6F|\uD83E[\uDD3C\uDDDE\uDDDF]|[\u231A\u231B\u23E9-\u23EC\u23F0\u23F3\u25FD\u25FE\u2614\u2615\u2648-\u2653\u267F\u2693\u26A1\u26AA\u26AB\u26BD\u26BE\u26C4\u26C5\u26CE\u26D4\u26EA\u26F2\u26F3\u26F5\u26FA\u26FD\u2705\u2728\u274C\u274E\u2753-\u2755\u2757\u2795-\u2797\u27B0\u27BF\u2B1B\u2B1C\u2B50\u2B55]|\uD83C[\uDC04\uDCCF\uDD8E\uDD91-\uDD9A\uDE01\uDE1A\uDE2F\uDE32-\uDE36\uDE38-\uDE3A\uDE50\uDE51\uDF00-\uDF20\uDF2D-\uDF35\uDF37-\uDF7C\uDF7E-\uDF84\uDF86-\uDF93\uDFA0-\uDFC1\uDFC5\uDFC6\uDFC8\uDFC9\uDFCF-\uDFD3\uDFE0-\uDFF0\uDFF8-\uDFFF]|\uD83D[\uDC00-\uDC07\uDC09-\uDC14\uDC16-\uDC3A\uDC3C-\uDC3E\uDC40\uDC44\uDC45\uDC51-\uDC65\uDC6A\uDC79-\uDC7B\uDC7D-\uDC80\uDC84\uDC88-\uDC8E\uDC90\uDC92-\uDCA9\uDCAB-\uDCFC\uDCFF-\uDD3D\uDD4B-\uDD4E\uDD50-\uDD67\uDDA4\uDDFB-\uDE2D\uDE2F-\uDE34\uDE37-\uDE44\uDE48-\uDE4A\uDE80-\uDEA2\uDEA4-\uDEB3\uDEB7-\uDEBF\uDEC1-\uDEC5\uDED0-\uDED2\uDED5-\uDED7\uDEEB\uDEEC\uDEF4-\uDEFC\uDFE0-\uDFEB]|\uD83E[\uDD0D\uDD0E\uDD10-\uDD17\uDD1D\uDD20-\uDD25\uDD27-\uDD2F\uDD3A\uDD3F-\uDD45\uDD47-\uDD76\uDD78\uDD7A-\uDDB4\uDDB7\uDDBA\uDDBC-\uDDCB\uDDD0\uDDE0-\uDDFF\uDE70-\uDE74\uDE78-\uDE7A\uDE80-\uDE86\uDE90-\uDEA8\uDEB0-\uDEB6\uDEC0-\uDEC2\uDED0-\uDED6]|(?:[\u231A\u231B\u23E9-\u23EC\u23F0\u23F3\u25FD\u25FE\u2614\u2615\u2648-\u2653\u267F\u2693\u26A1\u26AA\u26AB\u26BD\u26BE\u26C4\u26C5\u26CE\u26D4\u26EA\u26F2\u26F3\u26F5\u26FA\u26FD\u2705\u270A\u270B\u2728\u274C\u274E\u2753-\u2755\u2757\u2795-\u2797\u27B0\u27BF\u2B1B\u2B1C\u2B50\u2B55]|\uD83C[\uDC04\uDCCF\uDD8E\uDD91-\uDD9A\uDDE6-\uDDFF\uDE01\uDE1A\uDE2F\uDE32-\uDE36\uDE38-\uDE3A\uDE50\uDE51\uDF00-\uDF20\uDF2D-\uDF35\uDF37-\uDF7C\uDF7E-\uDF93\uDFA0-\uDFCA\uDFCF-\uDFD3\uDFE0-\uDFF0\uDFF4\uDFF8-\uDFFF]|\uD83D[\uDC00-\uDC3E\uDC40\uDC42-\uDCFC\uDCFF-\uDD3D\uDD4B-\uDD4E\uDD50-\uDD67\uDD7A\uDD95\uDD96\uDDA4\uDDFB-\uDE4F\uDE80-\uDEC5\uDECC\uDED0-\uDED2\uDED5-\uDED7\uDEEB\uDEEC\uDEF4-\uDEFC\uDFE0-\uDFEB]|\uD83E[\uDD0C-\uDD3A\uDD3C-\uDD45\uDD47-\uDD78\uDD7A-\uDDCB\uDDCD-\uDDFF\uDE70-\uDE74\uDE78-\uDE7A\uDE80-\uDE86\uDE90-\uDEA8\uDEB0-\uDEB6\uDEC0-\uDEC2\uDED0-\uDED6])|(?:[#\*0-9\xA9\xAE\u203C\u2049\u2122\u2139\u2194-\u2199\u21A9\u21AA\u231A\u231B\u2328\u23CF\u23E9-\u23F3\u23F8-\u23FA\u24C2\u25AA\u25AB\u25B6\u25C0\u25FB-\u25FE\u2600-\u2604\u260E\u2611\u2614\u2615\u2618\u261D\u2620\u2622\u2623\u2626\u262A\u262E\u262F\u2638-\u263A\u2640\u2642\u2648-\u2653\u265F\u2660\u2663\u2665\u2666\u2668\u267B\u267E\u267F\u2692-\u2697\u2699\u269B\u269C\u26A0\u26A1\u26A7\u26AA\u26AB\u26B0\u26B1\u26BD\u26BE\u26C4\u26C5\u26C8\u26CE\u26CF\u26D1\u26D3\u26D4\u26E9\u26EA\u26F0-\u26F5\u26F7-\u26FA\u26FD\u2702\u2705\u2708-\u270D\u270F\u2712\u2714\u2716\u271D\u2721\u2728\u2733\u2734\u2744\u2747\u274C\u274E\u2753-\u2755\u2757\u2763\u2764\u2795-\u2797\u27A1\u27B0\u27BF\u2934\u2935\u2B05-\u2B07\u2B1B\u2B1C\u2B50\u2B55\u3030\u303D\u3297\u3299]|\uD83C[\uDC04\uDCCF\uDD70\uDD71\uDD7E\uDD7F\uDD8E\uDD91-\uDD9A\uDDE6-\uDDFF\uDE01\uDE02\uDE1A\uDE2F\uDE32-\uDE3A\uDE50\uDE51\uDF00-\uDF21\uDF24-\uDF93\uDF96\uDF97\uDF99-\uDF9B\uDF9E-\uDFF0\uDFF3-\uDFF5\uDFF7-\uDFFF]|\uD83D[\uDC00-\uDCFD\uDCFF-\uDD3D\uDD49-\uDD4E\uDD50-\uDD67\uDD6F\uDD70\uDD73-\uDD7A\uDD87\uDD8A-\uDD8D\uDD90\uDD95\uDD96\uDDA4\uDDA5\uDDA8\uDDB1\uDDB2\uDDBC\uDDC2-\uDDC4\uDDD1-\uDDD3\uDDDC-\uDDDE\uDDE1\uDDE3\uDDE8\uDDEF\uDDF3\uDDFA-\uDE4F\uDE80-\uDEC5\uDECB-\uDED2\uDED5-\uDED7\uDEE0-\uDEE5\uDEE9\uDEEB\uDEEC\uDEF0\uDEF3-\uDEFC\uDFE0-\uDFEB]|\uD83E[\uDD0C-\uDD3A\uDD3C-\uDD45\uDD47-\uDD78\uDD7A-\uDDCB\uDDCD-\uDDFF\uDE70-\uDE74\uDE78-\uDE7A\uDE80-\uDE86\uDE90-\uDEA8\uDEB0-\uDEB6\uDEC0-\uDEC2\uDED0-\uDED6])\uFE0F|(?:[\u261D\u26F9\u270A-\u270D]|\uD83C[\uDF85\uDFC2-\uDFC4\uDFC7\uDFCA-\uDFCC]|\uD83D[\uDC42\uDC43\uDC46-\uDC50\uDC66-\uDC78\uDC7C\uDC81-\uDC83\uDC85-\uDC87\uDC8F\uDC91\uDCAA\uDD74\uDD75\uDD7A\uDD90\uDD95\uDD96\uDE45-\uDE47\uDE4B-\uDE4F\uDEA3\uDEB4-\uDEB6\uDEC0\uDECC]|\uD83E[\uDD0C\uDD0F\uDD18-\uDD1F\uDD26\uDD30-\uDD39\uDD3C-\uDD3E\uDD77\uDDB5\uDDB6\uDDB8\uDDB9\uDDBB\uDDCD-\uDDCF\uDDD1-\uDDDD])/g; -}; -var DD = j(X); -var m = 10; -var T = (t = 0) => (u) => `\x1B[${u + t}m`; -var P = (t = 0) => (u) => `\x1B[${38 + t};5;${u}m`; -var W = (t = 0) => (u, F, e) => `\x1B[${38 + t};2;${u};${F};${e}m`; -var r = { modifier: { reset: [0, 0], bold: [1, 22], dim: [2, 22], italic: [3, 23], underline: [4, 24], overline: [53, 55], inverse: [7, 27], hidden: [8, 28], strikethrough: [9, 29] }, color: { black: [30, 39], red: [31, 39], green: [32, 39], yellow: [33, 39], blue: [34, 39], magenta: [35, 39], cyan: [36, 39], white: [37, 39], blackBright: [90, 39], gray: [90, 39], grey: [90, 39], redBright: [91, 39], greenBright: [92, 39], yellowBright: [93, 39], blueBright: [94, 39], magentaBright: [95, 39], cyanBright: [96, 39], whiteBright: [97, 39] }, bgColor: { bgBlack: [40, 49], bgRed: [41, 49], bgGreen: [42, 49], bgYellow: [43, 49], bgBlue: [44, 49], bgMagenta: [45, 49], bgCyan: [46, 49], bgWhite: [47, 49], bgBlackBright: [100, 49], bgGray: [100, 49], bgGrey: [100, 49], bgRedBright: [101, 49], bgGreenBright: [102, 49], bgYellowBright: [103, 49], bgBlueBright: [104, 49], bgMagentaBright: [105, 49], bgCyanBright: [106, 49], bgWhiteBright: [107, 49] } }; -Object.keys(r.modifier); -var uD = Object.keys(r.color); -var FD = Object.keys(r.bgColor); -[...uD]; -var eD = tD(); -var g = new Set(["\x1B", "\x9B"]); -var sD = 39; -var b = "\x07"; -var O = "["; -var CD = "]"; -var I = "m"; -var w = `${CD}8;;`; -var N = (t) => `${g.values().next().value}${O}${t}${I}`; -var L = (t) => `${g.values().next().value}${w}${t}${b}`; -var iD = (t) => t.split(" ").map((u) => A(u)); -var y = (t, u, F) => { - const e = [...u]; - let s = false, C = false, D = A(S(t[t.length - 1])); - for (const [i, n] of e.entries()) { - const E = A(n); - if (D + E <= F ? t[t.length - 1] += n : (t.push(n), D = 0), g.has(n) && (s = true, C = e.slice(i + 1).join("").startsWith(w)), s) { - C ? n === b && (s = false, C = false) : n === I && (s = false); - continue; - } - D += E, D === F && i < e.length - 1 && (t.push(""), D = 0); - } - !D && t[t.length - 1].length > 0 && t.length > 1 && (t[t.length - 2] += t.pop()); -}; -var rD = (t) => { - const u = t.split(" "); - let F = u.length; - for (;F > 0 && !(A(u[F - 1]) > 0); ) - F--; - return F === u.length ? t : u.slice(0, F).join(" ") + u.slice(F).join(""); -}; -var ED = (t, u, F = {}) => { - if (F.trim !== false && t.trim() === "") - return ""; - let e = "", s, C; - const D = iD(t); - let i = [""]; - for (const [E, h] of t.split(" ").entries()) { - F.trim !== false && (i[i.length - 1] = i[i.length - 1].trimStart()); - let o = A(i[i.length - 1]); - if (E !== 0 && (o >= u && (F.wordWrap === false || F.trim === false) && (i.push(""), o = 0), (o > 0 || F.trim === false) && (i[i.length - 1] += " ", o++)), F.hard && D[E] > u) { - const B = u - o, p = 1 + Math.floor((D[E] - B - 1) / u); - Math.floor((D[E] - 1) / u) < p && i.push(""), y(i, h, u); - continue; - } - if (o + D[E] > u && o > 0 && D[E] > 0) { - if (F.wordWrap === false && o < u) { - y(i, h, u); - continue; - } - i.push(""); - } - if (o + D[E] > u && F.wordWrap === false) { - y(i, h, u); - continue; - } - i[i.length - 1] += h; - } - F.trim !== false && (i = i.map((E) => rD(E))); - const n = [...i.join(` -`)]; - for (const [E, h] of n.entries()) { - if (e += h, g.has(h)) { - const { groups: B } = new RegExp(`(?:\\${O}(?\\d+)m|\\${w}(?.*)${b})`).exec(n.slice(E).join("")) || { groups: {} }; - if (B.code !== undefined) { - const p = Number.parseFloat(B.code); - s = p === sD ? undefined : p; - } else - B.uri !== undefined && (C = B.uri.length === 0 ? undefined : B.uri); - } - const o = eD.codes.get(Number(s)); - n[E + 1] === ` -` ? (C && (e += L("")), s && o && (e += N(o))) : h === ` -` && (s && o && (e += N(s)), C && (e += L(C))); - } - return e; -}; -var oD = Object.defineProperty; -var nD = (t, u, F) => (u in t) ? oD(t, u, { enumerable: true, configurable: true, writable: true, value: F }) : t[u] = F; -var a = (t, u, F) => (nD(t, typeof u != "symbol" ? u + "" : u, F), F); -var V = Symbol("clack:cancel"); -var z = new Map([["k", "up"], ["j", "down"], ["h", "left"], ["l", "right"]]); -var lD = new Set(["up", "down", "left", "right", "space", "enter"]); - -class x { - constructor({ render: u, input: F = $, output: e = k, ...s }, C = true) { - a(this, "input"), a(this, "output"), a(this, "rl"), a(this, "opts"), a(this, "_track", false), a(this, "_render"), a(this, "_cursor", 0), a(this, "state", "initial"), a(this, "value"), a(this, "error", ""), a(this, "subscribers", new Map), a(this, "_prevFrame", ""), this.opts = s, this.onKeypress = this.onKeypress.bind(this), this.close = this.close.bind(this), this.render = this.render.bind(this), this._render = u.bind(this), this._track = C, this.input = F, this.output = e; - } - prompt() { - const u = new U(0); - return u._write = (F, e, s) => { - this._track && (this.value = this.rl.line.replace(/\t/g, ""), this._cursor = this.rl.cursor, this.emit("value", this.value)), s(); - }, this.input.pipe(u), this.rl = _.createInterface({ input: this.input, output: u, tabSize: 2, prompt: "", escapeCodeTimeout: 50 }), _.emitKeypressEvents(this.input, this.rl), this.rl.prompt(), this.opts.initialValue !== undefined && this._track && this.rl.write(this.opts.initialValue), this.input.on("keypress", this.onKeypress), v(this.input, true), this.output.on("resize", this.render), this.render(), new Promise((F, e) => { - this.once("submit", () => { - this.output.write(import_sisteransi.cursor.show), this.output.off("resize", this.render), v(this.input, false), F(this.value); - }), this.once("cancel", () => { - this.output.write(import_sisteransi.cursor.show), this.output.off("resize", this.render), v(this.input, false), F(V); - }); - }); - } - on(u, F) { - const e = this.subscribers.get(u) ?? []; - e.push({ cb: F }), this.subscribers.set(u, e); - } - once(u, F) { - const e = this.subscribers.get(u) ?? []; - e.push({ cb: F, once: true }), this.subscribers.set(u, e); - } - emit(u, ...F) { - const e = this.subscribers.get(u) ?? [], s = []; - for (const C of e) - C.cb(...F), C.once && s.push(() => e.splice(e.indexOf(C), 1)); - for (const C of s) - C(); - } - unsubscribe() { - this.subscribers.clear(); - } - onKeypress(u, F) { - if (this.state === "error" && (this.state = "active"), F?.name && !this._track && z.has(F.name) && this.emit("cursor", z.get(F.name)), F?.name && lD.has(F.name) && this.emit("cursor", F.name), u && (u.toLowerCase() === "y" || u.toLowerCase() === "n") && this.emit("confirm", u.toLowerCase() === "y"), u === " " && this.opts.placeholder && (this.value || (this.rl.write(this.opts.placeholder), this.emit("value", this.opts.placeholder))), u && this.emit("key", u.toLowerCase()), F?.name === "return") { - if (this.opts.validate) { - const e = this.opts.validate(this.value); - e && (this.error = e, this.state = "error", this.rl.write(this.value)); - } - this.state !== "error" && (this.state = "submit"); - } - u === "" && (this.state = "cancel"), (this.state === "submit" || this.state === "cancel") && this.emit("finalize"), this.render(), (this.state === "submit" || this.state === "cancel") && this.close(); - } - close() { - this.input.unpipe(), this.input.removeListener("keypress", this.onKeypress), this.output.write(` -`), v(this.input, false), this.rl.close(), this.emit(`${this.state}`, this.value), this.unsubscribe(); - } - restoreCursor() { - const u = R(this._prevFrame, process.stdout.columns, { hard: true }).split(` -`).length - 1; - this.output.write(import_sisteransi.cursor.move(-999, u * -1)); - } - render() { - const u = R(this._render(this) ?? "", process.stdout.columns, { hard: true }); - if (u !== this._prevFrame) { - if (this.state === "initial") - this.output.write(import_sisteransi.cursor.hide); - else { - const F = aD(this._prevFrame, u); - if (this.restoreCursor(), F && F?.length === 1) { - const e = F[0]; - this.output.write(import_sisteransi.cursor.move(0, e)), this.output.write(import_sisteransi.erase.lines(1)); - const s = u.split(` -`); - this.output.write(s[e]), this._prevFrame = u, this.output.write(import_sisteransi.cursor.move(0, s.length - e - 1)); - return; - } else if (F && F?.length > 1) { - const e = F[0]; - this.output.write(import_sisteransi.cursor.move(0, e)), this.output.write(import_sisteransi.erase.down()); - const s = u.split(` -`).slice(e); - this.output.write(s.join(` -`)), this._prevFrame = u; - return; - } - this.output.write(import_sisteransi.erase.down()); - } - this.output.write(u), this.state === "initial" && (this.state = "active"), this._prevFrame = u; - } - } -} -var vD = Object.defineProperty; -var dD = (t, u, F) => (u in t) ? vD(t, u, { enumerable: true, configurable: true, writable: true, value: F }) : t[u] = F; -var Y = (t, u, F) => (dD(t, typeof u != "symbol" ? u + "" : u, F), F); - -class mD extends x { - constructor({ mask: u, ...F }) { - super(F), Y(this, "valueWithCursor", ""), Y(this, "_mask", "\u2022"), this._mask = u ?? "\u2022", this.on("finalize", () => { - this.valueWithCursor = this.masked; - }), this.on("value", () => { - if (this.cursor >= this.value.length) - this.valueWithCursor = `${this.masked}${import_picocolors.default.inverse(import_picocolors.default.hidden("_"))}`; - else { - const e = this.masked.slice(0, this.cursor), s = this.masked.slice(this.cursor); - this.valueWithCursor = `${e}${import_picocolors.default.inverse(s[0])}${s.slice(1)}`; - } - }); - } - get cursor() { - return this._cursor; - } - get masked() { - return this.value.replaceAll(/./g, this._mask); - } -} -var bD = Object.defineProperty; -var wD = (t, u, F) => (u in t) ? bD(t, u, { enumerable: true, configurable: true, writable: true, value: F }) : t[u] = F; -var Z = (t, u, F) => (wD(t, typeof u != "symbol" ? u + "" : u, F), F); -var yD = class extends x { - constructor(u) { - super(u, false), Z(this, "options"), Z(this, "cursor", 0), this.options = u.options, this.cursor = this.options.findIndex(({ value: F }) => F === u.initialValue), this.cursor === -1 && (this.cursor = 0), this.changeValue(), this.on("cursor", (F) => { - switch (F) { - case "left": - case "up": - this.cursor = this.cursor === 0 ? this.options.length - 1 : this.cursor - 1; - break; - case "down": - case "right": - this.cursor = this.cursor === this.options.length - 1 ? 0 : this.cursor + 1; - break; - } - this.changeValue(); - }); - } - get _value() { - return this.options[this.cursor]; - } - changeValue() { - this.value = this._value.value; - } -}; -var SD = Object.defineProperty; -var jD = (t, u, F) => (u in t) ? SD(t, u, { enumerable: true, configurable: true, writable: true, value: F }) : t[u] = F; -var MD = (t, u, F) => (jD(t, typeof u != "symbol" ? u + "" : u, F), F); - -class TD extends x { - constructor(u) { - super(u), MD(this, "valueWithCursor", ""), this.on("finalize", () => { - this.value || (this.value = u.defaultValue), this.valueWithCursor = this.value; - }), this.on("value", () => { - if (this.cursor >= this.value.length) - this.valueWithCursor = `${this.value}${import_picocolors.default.inverse(import_picocolors.default.hidden("_"))}`; - else { - const F = this.value.slice(0, this.cursor), e = this.value.slice(this.cursor); - this.valueWithCursor = `${F}${import_picocolors.default.inverse(e[0])}${e.slice(1)}`; - } - }); - } - get cursor() { - return this._cursor; - } -} -var PD = globalThis.process.platform.startsWith("win"); - -// node_modules/@clack/prompts/dist/index.mjs -var import_picocolors2 = __toESM(require_picocolors(), 1); -var import_sisteransi2 = __toESM(require_src(), 1); -import h from "process"; -function q2() { - return h.platform !== "win32" ? h.env.TERM !== "linux" : Boolean(h.env.CI) || Boolean(h.env.WT_SESSION) || Boolean(h.env.TERMINUS_SUBLIME) || h.env.ConEmuTask === "{cmd::Cmder}" || h.env.TERM_PROGRAM === "Terminus-Sublime" || h.env.TERM_PROGRAM === "vscode" || h.env.TERM === "xterm-256color" || h.env.TERM === "alacritty" || h.env.TERMINAL_EMULATOR === "JetBrains-JediTerm"; -} -var _2 = q2(); -var o = (r2, n) => _2 ? r2 : n; -var H = o("\u25C6", "*"); -var I2 = o("\u25A0", "x"); -var x2 = o("\u25B2", "x"); -var S2 = o("\u25C7", "o"); -var K = o("\u250C", "T"); -var a2 = o("\u2502", "|"); -var d2 = o("\u2514", "\u2014"); -var b2 = o("\u25CF", ">"); -var E = o("\u25CB", " "); -var C = o("\u25FB", "[\u2022]"); -var w2 = o("\u25FC", "[+]"); -var M2 = o("\u25FB", "[ ]"); -var U2 = o("\u25AA", "\u2022"); -var B = o("\u2500", "-"); -var Z2 = o("\u256E", "+"); -var z2 = o("\u251C", "+"); -var X2 = o("\u256F", "+"); -var J2 = o("\u25CF", "\u2022"); -var Y2 = o("\u25C6", "*"); -var Q2 = o("\u25B2", "!"); -var ee = o("\u25A0", "x"); -var y2 = (r2) => { - switch (r2) { - case "initial": - case "active": - return import_picocolors2.default.cyan(H); - case "cancel": - return import_picocolors2.default.red(I2); - case "error": - return import_picocolors2.default.yellow(x2); - case "submit": - return import_picocolors2.default.green(S2); - } -}; -var te = (r2) => new TD({ validate: r2.validate, placeholder: r2.placeholder, defaultValue: r2.defaultValue, initialValue: r2.initialValue, render() { - const n = `${import_picocolors2.default.gray(a2)} -${y2(this.state)} ${r2.message} -`, i = r2.placeholder ? import_picocolors2.default.inverse(r2.placeholder[0]) + import_picocolors2.default.dim(r2.placeholder.slice(1)) : import_picocolors2.default.inverse(import_picocolors2.default.hidden("_")), t = this.value ? this.valueWithCursor : i; - switch (this.state) { - case "error": - return `${n.trim()} -${import_picocolors2.default.yellow(a2)} ${t} -${import_picocolors2.default.yellow(d2)} ${import_picocolors2.default.yellow(this.error)} -`; - case "submit": - return `${n}${import_picocolors2.default.gray(a2)} ${import_picocolors2.default.dim(this.value || r2.placeholder)}`; - case "cancel": - return `${n}${import_picocolors2.default.gray(a2)} ${import_picocolors2.default.strikethrough(import_picocolors2.default.dim(this.value ?? ""))}${this.value?.trim() ? ` -` + import_picocolors2.default.gray(a2) : ""}`; - default: - return `${n}${import_picocolors2.default.cyan(a2)} ${t} -${import_picocolors2.default.cyan(d2)} -`; - } -} }).prompt(); -var re = (r2) => new mD({ validate: r2.validate, mask: r2.mask ?? U2, render() { - const n = `${import_picocolors2.default.gray(a2)} -${y2(this.state)} ${r2.message} -`, i = this.valueWithCursor, t = this.masked; - switch (this.state) { - case "error": - return `${n.trim()} -${import_picocolors2.default.yellow(a2)} ${t} -${import_picocolors2.default.yellow(d2)} ${import_picocolors2.default.yellow(this.error)} -`; - case "submit": - return `${n}${import_picocolors2.default.gray(a2)} ${import_picocolors2.default.dim(t)}`; - case "cancel": - return `${n}${import_picocolors2.default.gray(a2)} ${import_picocolors2.default.strikethrough(import_picocolors2.default.dim(t ?? ""))}${t ? ` -` + import_picocolors2.default.gray(a2) : ""}`; - default: - return `${n}${import_picocolors2.default.cyan(a2)} ${i} -${import_picocolors2.default.cyan(d2)} -`; - } -} }).prompt(); -var ie = (r2) => { - const n = (t, s) => { - const c2 = t.label ?? String(t.value); - return s === "active" ? `${import_picocolors2.default.green(b2)} ${c2} ${t.hint ? import_picocolors2.default.dim(`(${t.hint})`) : ""}` : s === "selected" ? `${import_picocolors2.default.dim(c2)}` : s === "cancelled" ? `${import_picocolors2.default.strikethrough(import_picocolors2.default.dim(c2))}` : `${import_picocolors2.default.dim(E)} ${import_picocolors2.default.dim(c2)}`; - }; - let i = 0; - return new yD({ options: r2.options, initialValue: r2.initialValue, render() { - const t = `${import_picocolors2.default.gray(a2)} -${y2(this.state)} ${r2.message} -`; - switch (this.state) { - case "submit": - return `${t}${import_picocolors2.default.gray(a2)} ${n(this.options[this.cursor], "selected")}`; - case "cancel": - return `${t}${import_picocolors2.default.gray(a2)} ${n(this.options[this.cursor], "cancelled")} -${import_picocolors2.default.gray(a2)}`; - default: { - const s = r2.maxItems === undefined ? 1 / 0 : Math.max(r2.maxItems, 5); - this.cursor >= i + s - 3 ? i = Math.max(Math.min(this.cursor - s + 3, this.options.length - s), 0) : this.cursor < i + 2 && (i = Math.max(this.cursor - 2, 0)); - const c2 = s < this.options.length && i > 0, l2 = s < this.options.length && i + s < this.options.length; - return `${t}${import_picocolors2.default.cyan(a2)} ${this.options.slice(i, i + s).map((u, m2, $2) => m2 === 0 && c2 ? import_picocolors2.default.dim("...") : m2 === $2.length - 1 && l2 ? import_picocolors2.default.dim("...") : n(u, m2 + i === this.cursor ? "active" : "inactive")).join(` -${import_picocolors2.default.cyan(a2)} `)} -${import_picocolors2.default.cyan(d2)} -`; - } - } - } }).prompt(); -}; -var ue = (r2 = "") => { - process.stdout.write(`${import_picocolors2.default.gray(d2)} ${import_picocolors2.default.red(r2)} - -`); -}; -var oe = (r2 = "") => { - process.stdout.write(`${import_picocolors2.default.gray(K)} ${r2} -`); -}; -var $e = (r2 = "") => { - process.stdout.write(`${import_picocolors2.default.gray(a2)} -${import_picocolors2.default.gray(d2)} ${r2} - -`); -}; - -// configurator.ts -var import_picocolors3 = __toESM(require_picocolors(), 1); -import {parseArgs} from "util"; -async function askMissingData(missingData, override = false) { - if (Object.keys(missingData).length === 0) { - $e("Configuration set from ops"); - process.exit(0); - } - console.log(); - if (!override) { - console.log("Configuration partially set from ops. Need a few more:"); - } - for (const key in missingData) { - let inputFromPrompt; - const prompt = missingData[key]; - if (Array.isArray(prompt.type)) { - const defaultValueOK = prompt.default && prompt.type.includes(prompt.default); - if (prompt.default && !defaultValueOK) { - console.log(); - console.warn(`The default value ${prompt.default} is not in the enum values.`); - } - const selected = await ie({ - message: prompt.label || `Pick a value for '${key}'`, - options: prompt.type.map((v2) => ({ label: v2, value: v2 })), - initialValue: defaultValueOK ? prompt.default : undefined - }); - if (!selected || hD(selected)) { - ue("Operation cancelled"); - process.exit(0); - } - inputFromPrompt = selected.toString(); - } else if (prompt.type === "bool") { - const selected = await ie({ - initialValue: prompt.default === "true" || prompt.default === true ? "true" : "false", - message: prompt.label || `Pick a true/false for '${key}'`, - options: [ - { label: "true", value: "true" }, - { label: "false", value: "false" } - ] - }); - if (!selected || hD(selected)) { - ue("Operation cancelled"); - process.exit(0); - } - inputFromPrompt = selected.toString(); - } else if (prompt.type === "password") { - if (prompt.default) { - console.log(); - console.warn("Default password value is not supported. Please enter the password manually."); - } - const input = await re({ - message: prompt.label || `Enter password value for ${key}`, - validate: (value) => { - if (!value) { - return "Password cannot be empty"; - } - } - }); - if (hD(input)) { - ue("Operation cancelled"); - process.exit(0); - } - inputFromPrompt = input; - } else { - const defaultMsgFragment = prompt.default ? `(default: ${prompt.default})` : ""; - const message = `Enter value for ${key} ${defaultMsgFragment} (${prompt.type})`; - let input = await te({ - message: prompt.label || message, - initialValue: prompt.default?.toString(), - validate: (value) => { - switch (prompt.type) { - case "int": - if (!Number.isInteger(Number(value))) { - return `Value for ${key} must be an integer number`; - } - break; - case "float": - if (!Number(value)) { - return `Value for ${key} must be a number`; - } - } - return; - } - }); - if (hD(input)) { - ue("Operation cancelled"); - process.exit(0); - } - inputFromPrompt = input; - } - console.log(`Setting ${key} to ${inputFromPrompt}`); - const { exitCode, stderr } = await $2`${OPS} -config ${key}=${inputFromPrompt}`.nothrow(); - if (exitCode !== 0) { - ue(stderr.toString()); - return process.exit(1); - } - } -} -function findMissingConfig(config, opsCurrentConfig) { - let newConfig = {}; - let opsConfigKeys = opsCurrentConfig.split("\n").map((line) => line.split("=")[0]); - for (const key in config) { - if (opsConfigKeys.includes(key)) { - continue; - } - newConfig[key] = config[key]; - } - return newConfig; -} -function readPositionalFile(positionals) { - if (positionals.length < 2) { - console.error("This should not happen"); - return { success: false, message: "This should not happen" }; - } - if (positionals.length === 2) { - return { success: true, help: HelpMsg }; - } - if (positionals.length > 3) { - return { - success: true, - message: AdditionalArgsMsg, - jsonFilePath: positionals[2] - }; - } - return { success: true, jsonFilePath: positionals[2] }; -} -async function parsePositionalFile(path) { - const file = Bun.file(Bun.pathToFileURL(path)); - if (!await file.exists()) { - return { success: false, message: FileNotFoundJsonMsg + Bun.pathToFileURL(path) }; - } - try { - const contents = await file.json(); - return { success: true, body: contents }; - } catch (error) { - return { success: false, message: NotValidJsonMsg }; - } -} -function isInputConfigValid(body) { - if (Object.keys(body).length === 0) { - return false; - } - for (const key in body) { - const value = body[key]; - if (typeof value !== "object") { - return false; - } - if (!value.type) { - return false; - } - if (!["string", "int", "float", "bool", "password"].includes(value.type) && !Array.isArray(value.type)) { - return false; - } - } - for (const key in body) { - if (!/^[A-Z][A-Z_]|[0-9]*[A-Z]|[0-9]$/.test(key)) { - return false; - } - } - return true; -} -var OPS = process.env.OPS || "ops"; -var AdditionalArgsMsg = "Additional arguments will be ignored."; -var NotValidJsonMsg = "Not a valid JSON file"; -var FileNotFoundJsonMsg = "The JSON file was not found. Pathname: "; -var BadConfigMsg = "Bad configuration file. Check the help message (-h) to see the expected format."; -var HelpMsg = ` -Usage: config [-o | --override] - -Description: -Prompt the user for configuration data defined in the config.json file. -The script will ignore the keys from the input config that are already set in ops -and only prompt the user for the missing data, unless the override flag is set. -Then they will be saved in the ops config. - -The config.json file must be a JSON file with the following structure: - - { - "KEY": { - "type": "string" - }, - "OTHER_KEY": { - "label": "An optional custom message", - "type": "int" - }, - ... - } - -The keys must be uppercase words (separated by underscores). -The value for the "type" key must be either string with the following values: -- string -- int -- float -- bool -- password -- an array of strings with specific values (an enum). -`; -async function main() { - const options = { - showhelp: { - type: "boolean" - }, - override: { - type: "boolean" - } - }; - const { values, positionals } = parseArgs({ - args: Bun.argv, - options, - strict: true, - allowPositionals: true - }); - if (values.showhelp) { - console.log(HelpMsg); - return process.exit(0); - } - const override = values.override || false; - const readPosRes = readPositionalFile(positionals); - if (!readPosRes.success) { - ue(readPosRes.message); - return process.exit(1); - } - if (readPosRes.help) { - console.log(readPosRes.help); - return process.exit(0); - } - if (readPosRes.message) { - console.warn(readPosRes.message); - } - const jsonRes = await parsePositionalFile(readPosRes.jsonFilePath); - if (!jsonRes.success) { - ue(jsonRes.message); - return process.exit(1); - } - const config = jsonRes.body; - if (!isInputConfigValid(config)) { - ue(BadConfigMsg); - return process.exit(1); - } - const { exitCode, stderr, stdout } = await $2`${OPS} -config -d`.quiet(); - if (exitCode !== 0) { - ue(stderr.toString()); - return process.exit(1); - } - const opsCurrentConfig = stdout.toString(); - let missingData = config; - if (!override) { - missingData = findMissingConfig(config, opsCurrentConfig); - } - console.log(); - oe(import_picocolors3.default.inverse(" ops configurator ")); - await askMissingData(missingData, override); - console.log(); - $e("You're all set!"); -} - -// index.ts -main().catch(console.error); diff --git a/util/config/configurator/all-config-parameters.toml b/util/config/configurator/all-config-parameters.toml new file mode 100644 index 00000000..55a49baa --- /dev/null +++ b/util/config/configurator/all-config-parameters.toml @@ -0,0 +1,248 @@ +# Content: for all the components that Openserverless needs in its configuration, +# we create a suitable configuration +# This is a TOML document +# To obtain some of these arguments, use the command +# ops -config -d | awk -F= '/=/{print $1}' + + + +[components.aws] + +# taskfile format: +# VAR={ label="", initialValue="", userInputValue=""} + + +# +# AWS configuration values +# + +# Mandatory values +AWS_ACCESS_KEY_ID= {label="AWS Access Id", initialValue="AAA", userInputValue="BBB"} +AWS_SECRET_ACCESS_KEY= {label="AWS Secret Key", initialValue="", userInputValue="", type="password"} +# Non-mandatory values +AWS_DEFAULT_REGION= {label="AWS Region to use", initialValue="", userInputValue="us-east-1"} + +# Value defined in the aws task +# Mandatory values +# None + +# Non-mandatory values +AWS_VM_IMAGE_ID={ label="AWS Image to use for VMs", initialValue="{{.__image}}", userInputValue="ami-052efd3df9dad4825"} +AWS_VM_IMAGE_USER={ label="AWS Default user for image to use for VMs", initialValue="{{.__vmuser}}", userInputValue="ubuntu"} +AWS_VM_INSTANCE_TYPE={ label="AWS Instance type to use for VMs", hint="The suggested instance type has 8GB and 2vcpus.\nTo get a list of valid values, use:\naws ec2 describe-instance-types --query 'InstanceTypes[].InstanceType' --output table", initialValue="{{.__vm}}", userInputValue="t3a.large"} +AWS_VM_DISK_SIZE={ label="AWS Disk Size to use for VMs", initialValue="{{.__disk}}", userInputValue="100"} + + +# +# EKS configuration values +# + +[components.eks] + +# Mandatory values +# None + +# Non-mandatory values +EKS_NAME={ label="EKS Name for Cluster and Node Group", initialValue="{{.__name}}", userInputValue="openserverless"} +EKS_REGION={ label="EKS location", initialValue="{{.__region}}", userInputValue="us-east-2"} +EKS_COUNT={ label="EKS number of worker nodes", initialValue="{{.__count}}", userInputValue="3"} +EKS_VM={ label="EKS virtual machine type", initialValue="{{.__vm}}", userInputValue="m5.xlarge"} +EKS_DISK={ label="EKS disk size in gigabyte", initialValue="{{.__disk}}", userInputValue="50"} +EKS_KUBERNETES_VERSION={ label="EKS Kubernetes Version", initialValue="{{.__kubever}}", userInputValue="1.25"} + + +# +# GCLOUD configuration values +# + +[components.gcloud] + + +# Mandatory values +GCLOUD_PROJECT={ label="GCloud Project Id", initialValue="{{.__project}}", userInputValue=""} + +# Non-mandatory values +GCLOUD_REGION={ label="GCloud Zone", initialValue="{{.__region}}", userInputValue="us-east1"} +GCLOUD_VM={ label="GCloud virtual machine type", initialValue="{{.__vm}}", userInputValue="n2-standard-4"} +GCLOUD_DISK={ label="GCloud disk size in gigabyte", initialValue="{{.__disk}}", userInputValue="200"} +GCLOUD_SSHKEY={ label="GCloud public SSH key", initialValue="{{.__key}}", userInputValue="~/.ssh/id_rsa.pub"} +GCLOUD_IMAGE={ label="GCloud VM image", initialValue="{{.__image}}", userInputValue="ubuntu-minimal-2204-lts"} + +# +# GKE configuration values +# + +[components.gke] + +# Mandatory values +GKE_PROJECT={ label="GCloud Project Id", initialValue="{{.__project}}", userInputValue=""} + +# Non-mandatory values +GKE_NAME={ label="GCloud Cluster Name", initialValue="{{.__name}}", userInputValue="nuvolaris"} +GKE_REGION={ label="GCloud Cluster Zone", initialValue="{{.__region}}", userInputValue="us-east1"} +GKE_COUNT={ label="GCloud number of worker nodes", initialValue="{{.__count}}", userInputValue="3"} +GKE_VM={ label="GKE virtual machine type", initialValue="{{.__vm}}", userInputValue="e2-standard-2"} +GKE_DISK={ label="GKE disk size in gigabyte", initialValue="{{.__disk}}", userInputValue="50"} + + +# +# AZCLOUD configuration values +# + +[components.azcloud] + +# Mandatory values +AZCLOUD_PROJECT={ label="Azure Resource Group", initialValue="{{.__project}}", userInputValue=""} + +# Non-mandatory values +AZCLOUD_REGION={ label="Azure Zone", initialValue="{{.__region}}", userInputValue="eastus"} +AZCLOUD_VM={ label="Azure virtual machine type", initialValue="{{.__vm}}", userInputValue="Standard_B4s_v2"} +AZCLOUD_DISK={ label="Azure vm disk size in gigabyte", initialValue="{{.__disk}}", userInputValue="100"} +AZCLOUD_SSHKEY={ label="Azure Cloud public SSH key", initialValue="{{.__key}}", userInputValue="~/.ssh/id_rsa.pub"} +AZCLOUD_IMAGE={ label="Azure Cloud VM image", initialValue="{{.__image}}", userInputValue="Ubuntu2204"} + + +# +# AKS configuration values +# + +[components.aks] + +# Mandatory values +AKS_PROJECT={ label="AKS Name for Resource Group", initialValue="{{.__project}}", userInputValue="openserverless"} + +# Non-mandatory values +AKS_NAME={ label="AKS for Cluster", initialValue="{{.__name}}", userInputValue="openserverless"} +AKS_COUNT={ label="AKS number of worker nodes", initialValue="{{.__count}}", userInputValue="3"} +AKS_REGION={ label="AKS location", initialValue="{{.__region}}", userInputValue="eastus"} +AKS_VM={ label="AKS virtual machine type", initialValue="{{.__vm}}", userInputValue="Standard_B4ms"} +AKS_DISK={ label="AKS disk size in gigabyte", initialValue="{{.__disk}}", userInputValue="50"} +AKS_SSHKEY={ label="AKS public SSH key in AWS", initialValue="{{.__key}}", userInputValue="~/.ssh/id_rsa.pub"} + + + +[components.redis] +REDIS_URL= {label="Redis URL", initialValue="", userInputValue=""} +REDIS_SERVICE= {label="Redis Service", initialValue="", userInputValue=""} +REDIS_PREFIX= {label="Redis Prefix", initialValue="", userInputValue=""} +REDIS_PASSWORD= {label="Redis password", initialValue="", userInputValue="", type="password"} +# SECRET_REDIS_DEFAULT +# REDIS_PORT +# OPSTUTORIAL_SECRET_REDIS +# REDIS_PROVIDER +# REDIS_ALT_URL +# SECRET_REDIS_NUVOLARIS +# OPERATOR_COMPONENT_REDIS +# DEVEL_SECRET_REDIS + +[components.postgres] +POSTGRES_DATABASE={label="Database", initialValue="", userInputValue=""} +POSTGRES_PORT={label="Port", initialValue="", userInputValue=""} +POSTGRES_USERNAME={label="Username", initialValue="", userInputValue=""} +POSTGRES_PASSWORD={label="Password", initialValue="", userInputValue="", type="password"} +#SECRET_POSTGRES_REPLICA="" +#OPSTUTORIAL_SECRET_POSTGRES="" + + + +#OPERATOR_CONFIG_ALERTGMAIL +#OPENWHISK_TIME_LIMIT_MAX +#POSTGRES_PORT +#OPERATOR_COMPONENT_CRON +#REDIS_PORT +#S3_BUCKET_STATIC +#S3_PORT +#OPERATOR_COMPONENT_INVOKER +#OPERATOR_COMPONENT_REDIS +#OPERATOR_CONFIG_TLSEMAIL +#OPENWHISK_INVOKER_CONTAINER_POOL_MEMORY +#DEVEL_SECRET_MILVUS +#OPSTUTORIAL_SECRET_MONGODB +#IMAGES_STREAMER +#OPSTUTORIAL_SECRET_MILVUS +#IMAGES_INVOKER +#SECRET_NUVOLARIS_METADATA +#OPERATOR_COMPONENT_ETCD +#SECRET_MILVUS_ROOT +#S3_ACCESS_KEY +#OPSTUTORIAL_SECRET_COUCHDB +#AUTH +#SECRET_MONGODB_ADMIN +#MILVUS_PORT +#MILVUS_TOKEN +#SECRET_REDIS_DEFAULT +#OPERATOR_COMPONENT_KAFKA +#OPERATOR_CONFIG_HOSTPROTOCOL +#DEVEL_SECRET_REDIS +#IMAGES_OPERATOR +#SECRET_OPENWHISK_SYSTEM +#MILVUS_HOST +#S3_API_URL +#OPERATOR_COMPONENT_TLS +#DEVEL_SECRET_OPENWHISK +#OPSDEV_APIHOST +#OPERATOR_CONFIG_TOLERATIONS +#MINIO_CONFIG_INGRESS_S3 +#SECRET_COUCHDB_INVOKER +#OPERATOR_COMPONENT_ZOOKEEPER +#SECRET_MINIO_NUVOLARIS +#OPERATOR_COMPONENT_AM +#CONFIGURED +#DEVEL_SECRET_MINIO +#HELLO +#OPSTUTORIAL_SECRET_MINIO +#STATUS_LAST +#OPERATOR_COMPONENT_MILVUS +#REDIS_PROVIDER +#SECRET_MONGODB_NUVOLARIS +#OPERATOR_COMPONENT_STATIC +#SECRET_ETCD_ROOT +#OPERATOR_CONFIG_APIHOST +#OPS_COREUTILS +#SECRET_COUCHDB_ADMIN +#USER_V1_API_URL +#OPSDEV_USERNAME +#SECRET_POSTGRES_NUVOLARIS +#S3_PROVIDER +#ANOTHER +#OPERATOR_CONFIG_AFFINITY +#OPERATOR_COMPONENT_POSTGRES +#S3_HOST +#SECRET_MILVUS_S3 +#REDIS_URL +#S3_SECRET_KEY +#DEVEL_SECRET_POSTGRES +#SECRET_MILVUS_NUVOLARIS +#OPERATOR_COMPONENT_MINIO +#OPERATOR_CONFIG_SLIM +#POSTGRES_CONFIG_REPLICAS +#REDIS_PREFIX +#ETCD_CONFIG_REPLICAS +#OPERATOR_CONFIG_ALERTSLACK +#OPSTUTORIAL_SECRET_REDIS +#STATIC_CONTENT_URL +#IMAGES_CONTROLLER +#USER_REST_API_URL +#DEVEL_SECRET_MONGODB +#MONGODB_URL +#HELLO3 +#SECRET_POSTGRES_ADMIN +#OPERATOR_COMPONENT_MONGODB +#DEVEL_SECRET_COUCHDB +#POSTGRES_HOST +#OPERATOR_COMPONENT_PROMETHEUS +#REDIS_ALT_URL +#REDIS_PASSWORD +#OPERATOR_COMPONENT_REGISTRY +#OPSTUTORIAL_SECRET_OPENWHISK +#REGISTRY_CONFIG_SECRET_PUSH_PULL +#OPSDEV_HOST +#SECRET_MINIO_ADMIN +#SECRET_OPENWHISK_NUVOLARIS +#SECRET_REDIS_NUVOLARIS +#SECRET_COUCHDB_CONTROLLER +#OPERATOR_COMPONENT_QUOTA +#REDIS_SERVICE +#S3_BUCKET_DATA +#IMAGES_SYSTEMAPI +#MILVUS_DB_NAME diff --git a/util/config/configurator/bun.lockb b/util/config/configurator/bun.lockb old mode 100644 new mode 100755 index 0cae1e1e..8b5b61e8 Binary files a/util/config/configurator/bun.lockb and b/util/config/configurator/bun.lockb differ diff --git a/util/config/configurator/config-accessor.ts b/util/config/configurator/config-accessor.ts new file mode 100644 index 00000000..35c35504 --- /dev/null +++ b/util/config/configurator/config-accessor.ts @@ -0,0 +1,141 @@ +import {ComponentConfig, ConfigParameter} from "./types-core.ts"; +import {OpsConfigFile} from "./types-config-file.ts"; + +/** + * Provides clean API for accessing and modifying configuration data. + * + * Acts as a facade over OpsConfigFile, simplifying access to nested + * configuration data and providing convenience methods for common operations. + */ +export class ConfigAccessor { + private _config: OpsConfigFile; + + /** + * Creates a new ConfigAccessor instance. + * + * @param config - The OpsConfigFile to provide access to + */ + constructor(config: OpsConfigFile) { + this._config = config; + } + + /** + * Returns all component names in the configuration. + * + * @returns Array of component names + */ + getComponentNames(): string[] { + return this._config.getComponentNames(); + } + + /** + * Retrieves a component by name. + * + * @param name - The component name to look up + * @returns The ComponentConfig if found, undefined otherwise + */ + getComponent(name: string): ComponentConfig | undefined { + return this._config.getComponent(name); + } + + /** + * Retrieves a parameter from a specific component. + * + * @param componentName - Name of the component containing the parameter + * @param key - The parameter key to look up + * @returns The ConfigParameter if found, undefined otherwise + */ + getParameter(componentName: string, key: string): ConfigParameter | undefined { + const component = this._config.getComponent(componentName); + if (!component) { + return undefined; + } + return component.getParameter(key); + } + + /** + * Retrieves the effective value of a parameter. + * + * Returns userInputValue if set, otherwise initialValue. + * This is the preferred method for getting parameter values. + * + * @param componentName - Name of the component containing the parameter + * @param key - The parameter key to look up + * @returns The effective value if found, undefined otherwise + */ + getParameterValue(componentName: string, key: string): string | undefined { + const parameter = this.getParameter(componentName, key); + if (!parameter) { + return undefined; + } + return parameter.getValue(); + } + + /** + * Sets the user input value for a parameter. + * + * This modifies the configuration in memory. Changes can be persisted + * by saving the configuration to a file. + * + * @param componentName - Name of the component containing the parameter + * @param key - The parameter key to modify + * @param value - The new user input value + * @returns true if parameter was found and updated, false otherwise + */ + setParameterValue(componentName: string, key: string, value: string): boolean { + const parameter = this.getParameter(componentName, key); + if (!parameter) { + return false; + } + parameter.setUserInputValue(value); + return true; + } + + /** + * Checks if a component exists in the configuration. + * + * @param name - The component name to check + * @returns true if component exists, false otherwise + */ + hasComponent(name: string): boolean { + return this._config.hasComponent(name); + } + + /** + * Checks if a parameter exists in a specific component. + * + * @param componentName - Name of the component to check + * @param key - The parameter key to check + * @returns true if parameter exists, false otherwise + */ + hasParameter(componentName: string, key: string): boolean { + const component = this._config.getComponent(componentName); + if (!component) { + return false; + } + return component.hasParameter(key); + } + + /** + * Returns all components in the configuration. + * + * @returns Array of all ComponentConfig instances + */ + getAllComponents(): ComponentConfig[] { + return this._config.getAllComponents(); + } + + /** + * Returns the number of parameters in a specific component. + * + * @param componentName - Name of the component to count parameters for + * @returns Number of parameters, or 0 if component not found + */ + getParameterCount(componentName: string): number { + const component = this._config.getComponent(componentName); + if (!component) { + return 0; + } + return component.getParameterCount(); + } +} diff --git a/util/config/configurator/config-display.ts b/util/config/configurator/config-display.ts new file mode 100644 index 00000000..5c9be61f --- /dev/null +++ b/util/config/configurator/config-display.ts @@ -0,0 +1,200 @@ +import { note } from '@clack/prompts'; +import { styleText } from 'node:util'; +import {EditableConfigParameter} from "./types-core.ts"; + +export class ConfigDisplay { + static displayParameterTable( + componentName: string, + parameters: EditableConfigParameter[] + ): void { + if (parameters.length === 0) { + note('No parameters configured for this component.', componentName); + return; + } + + const mask = (param: EditableConfigParameter, v: string) => + param.getType() === 'password' ? (v ? '***' : '') : (v || ''); + + const columnWidths = this.calculateColumnWidths(parameters); + + const header = styleText('dim', + 'KEY'.padEnd(columnWidths.key) + ' ' + + 'Label'.padEnd(columnWidths.label) + ' ' + + 'Initial Value'.padEnd(columnWidths.initial) + ' ' + + 'Previous Value'.padEnd(columnWidths.previous) + ' ' + + 'Current Value' + ); + + const separator = styleText('dim', '─'.repeat(this.getTotalWidth(columnWidths))); + + const rows = parameters.map(param => + param.getKey().padEnd(columnWidths.key) + ' ' + + (param.getLabel() || '').padEnd(columnWidths.label) + ' ' + + mask(param, param.getInitialValue()).padEnd(columnWidths.initial) + ' ' + + mask(param, param.getPreviousUserInputValue()).padEnd(columnWidths.previous) + ' ' + + mask(param, param.getValue()) + ); + + note([header, separator, ...rows].join('\n'), componentName); + } + + /** + * Displays a summary of all components and their parameter counts. + * + * @param components - Array of component data + */ + static displayComponentSummary( + components: Array<{ name: string; parameterCount: number; modifiedCount: number }> + ): void { + console.log(`\n${'='.repeat(60)}`); + console.log('Configuration Summary'); + console.log('='.repeat(60)); + + const header = this.formatSimpleRow('Component', 'Parameters', 'Modified'); + console.log(header); + console.log('-'.repeat(60)); + + for (const comp of components) { + const row = this.formatSimpleRow( + comp.name, + comp.parameterCount.toString(), + comp.modifiedCount.toString() + ); + console.log(row); + } + + console.log('='.repeat(60) + '\n'); + } + + /** + * Displays a single parameter's details. + * + * @param parameter - The parameter to display + */ + static displayParameterDetail(parameter: EditableConfigParameter): void { + console.log(`\nParameter: ${parameter.getKey()}`); + console.log('-'.repeat(40)); + console.log(`Label: ${parameter.getLabel() || ''}`); + console.log(`Initial Value: ${parameter.getInitialValue() || ''}`); + console.log(`Previous Value: ${parameter.getPreviousUserInputValue() || ''}`); + console.log(`Current Value: ${parameter.getValue() || ''}`); + console.log(`Has User Input: ${parameter.hasUserInput()}`); + console.log(`Is Mandatory: ${parameter.isMandatory()}`); + console.log('-'.repeat(40) + '\n'); + } + + /** + * Calculates optimal column widths for the parameter table. + * + * @param parameters - Parameters to analyze + * @returns Object with column widths + */ + private static calculateColumnWidths( + parameters: EditableConfigParameter[] + ): { key: number; label: number; initial: number; previous: number; current: number } { + const widths = { + key: 'KEY'.length, + label: 'Label'.length, + initial: 'Initial Value'.length, + previous: 'Previous Value'.length, + current: 'Current Value'.length, + }; + + for (const param of parameters) { + const mask = (v: string) => param.getType() === 'password' ? (v ? '***' : '') : (v || ''); + widths.key = Math.max(widths.key, param.getKey().length); + widths.label = Math.max(widths.label, (param.getLabel() || '').length); + widths.initial = Math.max(widths.initial, mask(param.getInitialValue()).length); + widths.previous = Math.max(widths.previous, mask(param.getPreviousUserInputValue()).length); + widths.current = Math.max(widths.current, mask(param.getValue()).length); + } + + return widths; + } + + /** + * Formats a single row of the parameter table. + * + * @param key - Parameter key + * @param label - Parameter label + * @param initial - Initial value + * @param previous - Previous user input value + * @param current - Current value + * @param widths - Column widths + * @returns Formatted row string + */ + private static formatRow( + key: string, + label: string, + initial: string, + previous: string, + current: string, + widths: { key: number; label: number; initial: number; previous: number; current: number } + ): string { + const padKey = key.padEnd(widths.key).substring(0, widths.key); + const padLabel = label.padEnd(widths.label).substring(0, widths.label); + const padInitial = initial.padEnd(widths.initial).substring(0, widths.initial); + const padPrevious = previous.padEnd(widths.previous).substring(0, widths.previous); + const padCurrent = current.padEnd(widths.current).substring(0, widths.current); + + return `${padKey} | ${padLabel} | ${padInitial} | ${padPrevious} | ${padCurrent}`; + } + + /** + * Formats a simple two-column row. + * + * @param col1 - First column value + * @param col2 - Second column value + * @param col3 - Third column value + * @returns Formatted row string + */ + private static formatSimpleRow(col1: string, col2: string, col3: string): string { + return `${col1.padEnd(20)} | ${col2.padEnd(15)} | ${col3.padEnd(15)}`; + } + + /** + * Calculates total table width from column widths. + * + * @param widths - Column widths + * @returns Total width + */ + private static getTotalWidth( + widths: { key: number; label: number; initial: number; previous: number; current: number } + ): number { + return widths.key + widths.label + widths.initial + widths.previous + widths.current + 8; + } + + /** + * Displays modifications summary. + * + * @param modifications - Array of modified parameters by component + */ + static displayModifications( + modifications: Array<{ component: string; parameters: EditableConfigParameter[] }> + ): void { + if (modifications.length === 0) { + console.log('No modifications detected.\n'); + return; + } + + console.log(`\n${'='.repeat(80)}`); + console.log('Modified Parameters'); + console.log('='.repeat(80)); + + for (const mod of modifications) { + console.log(`\n[${mod.component}]`); + for (const param of mod.parameters) { + console.log(` ${param.getKey()}: ${param.getInitialValue() || ''} → ${param.getValue() || ''}`); + } + } + + console.log('\n' + '='.repeat(80) + '\n'); + } + + /** + * Clears the terminal screen. + */ + static clearScreen(): void { + console.clear(); + } +} diff --git a/util/config/configurator/config-parser.ts b/util/config/configurator/config-parser.ts new file mode 100644 index 00000000..e8456445 --- /dev/null +++ b/util/config/configurator/config-parser.ts @@ -0,0 +1,179 @@ +import type { Result } from './types'; +import {ComponentConfig, ConfigParameter} from "./types-core.ts"; +import {OpsConfigFile} from "./types-config-file.ts"; + +/** + * Parses TOML configuration files and creates OpsConfigFile instances. + * + * Responsible for reading configuration from disk, parsing TOML format, + * and constructing the object-oriented configuration structure. + */ +export class ConfigParser { + private _filePath: string; + + /** + * Creates a new ConfigParser instance. + * + * @param filePath - Path to the TOML configuration file + */ + constructor(filePath: string) { + this._filePath = filePath; + } + + /** + * Loads and parses the TOML configuration file. + * + * Reads the file from disk, parses TOML content, and constructs + * an OpsConfigFile object with all components and parameters. + * + * @returns Result containing OpsConfigFile on success, or error message on failure + */ + async load(): Promise> { + try { + const file = Bun.file(Bun.pathToFileURL(this._filePath)); + + if (!(await file.exists())) { + return { + success: false, + error: `Configuration file not found: ${this._filePath}`, + }; + } + + const content = await file.text(); + const rawData = await this.parseToml(content); + + if (!rawData) { + return { + success: false, + error: `Failed to parse TOML file: ${this._filePath}`, + }; + } + + const config = this.extractComponents(rawData); + + return { + success: true, + data: config, + }; + } catch (error) { + return { + success: false, + error: `Error loading configuration: ${error}`, + }; + } + } + + /** + * Parses TOML content using Bun's import assertion. + * + * @param content - Raw TOML content (unused, file imported directly) + * @returns Parsed TOML data as unknown object, or null on failure + */ + private async parseToml(content: string): Promise { + try { + const data = await import(this._filePath, { + assert: { type: 'toml' }, + }); + return data; + } catch (error) { + return null; + } + } + + /** + * Extracts all components from parsed TOML data. + * + * Iterates through the 'components' section in TOML and creates + * ComponentConfig instances for each section found. + * + * @param rawData - Parsed TOML data + * @returns OpsConfigFile containing all extracted components + */ + extractComponents(rawData: unknown): OpsConfigFile { + const config = new OpsConfigFile(); + + if (typeof rawData !== 'object' || rawData === null) { + return config; + } + + const data = rawData as Record; + + if (!data.components || typeof data.components !== 'object') { + return config; + } + + const components = data.components as Record; + + for (const [componentName, componentData] of Object.entries(components)) { + const component = this.parseComponentSection(componentName, componentData); + if (component.getParameterCount() > 0) { + config.addComponent(component); + } + } + + return config; + } + + /** + * Parses a single component section from TOML. + * + * Processes all key-value pairs in a component section, creating + * ConfigParameter instances for each parameter found. + * Skips keys that start with '#' (commented-out parameters). + * + * @param sectionName - Name of the component section (e.g., 'redis') + * @param sectionData - Key-value pairs in this section + * @returns ComponentConfig with all parsed parameters + */ + parseComponentSection(sectionName: string, sectionData: unknown): ComponentConfig { + const component = new ComponentConfig(sectionName); + + if (typeof sectionData !== 'object' || sectionData === null) { + return component; + } + + const data = sectionData as Record; + + for (const [key, value] of Object.entries(data)) { + if (key.startsWith('#')) { + continue; + } + + const parameter = this.parseParameter(key, value); + component.addParameter(parameter); + } + + return component; + } + + /** + * Parses a single parameter value from TOML. + * + * Handles two formats: + * - Simple string: `KEY=""` - uses value as initialValue + * - Object with metadata: `KEY={label="", initialValue="", userInputValue=""}` + * + * @param key - The parameter key + * @param value - The parameter value (string or object) + * @returns ConfigParameter instance + */ + parseParameter(key: string, value: unknown): ConfigParameter { + if (typeof value === 'string') { + return new ConfigParameter(key, '', value, '', false); + } + + if (typeof value === 'object' && value !== null) { + const data = value as Record; + const label = typeof data.label === 'string' ? data.label : ''; + const initialValue = typeof data.initialValue === 'string' ? data.initialValue : ''; + const userInputValue = typeof data.userInputValue === 'string' ? data.userInputValue : ''; + const isMandatory = typeof data.isMandatory === 'boolean' ? data.isMandatory : false; + const type = data.type === 'password' ? 'password' : 'string'; + const hint = typeof data.hint === 'string' ? data.hint : undefined; + + return new ConfigParameter(key, label, initialValue, userInputValue, isMandatory, type, hint); + } + + return new ConfigParameter(key, '', '', '', false); + } +} diff --git a/util/config/configurator/config-validator.ts b/util/config/configurator/config-validator.ts new file mode 100644 index 00000000..fe7e59eb --- /dev/null +++ b/util/config/configurator/config-validator.ts @@ -0,0 +1,142 @@ +import type { ValidationResult } from './types'; +import {ComponentConfig, ConfigParameter} from "./types-core.ts"; +import {OpsConfigFile} from "./types-config-file.ts"; + +/** + * List of all managed components in OpenServerless. + * Used to validate that configuration only contains known components. + */ +const MANAGED_COMPONENTS = [ + 'redis', + 'postgres', + 'ferretdb', + 'cron', + 'prometheus', + 'slack', + 'mail', + 'affinity', + 'tolerations', + 'quota', + 'alert manager', + 'aws', + 'eks', + 'gcloud', + 'gke', + 'azcloud', + 'alert', + 'aks', +]; + +/** + * Validates configuration against business rules. + * + * Checks that: + * - All component names are from the managed components list + * - All parameter keys follow naming conventions (uppercase, underscores) + */ +export class ConfigValidator { + private _config: OpsConfigFile; + private _managedComponents: string[]; + private _errors: string[]; + + /** + * Creates a new ConfigValidator instance. + * + * @param config - The OpsConfigFile to validate + * @param managedComponents - List of valid component names (default: MANAGED_COMPONENTS) + */ + constructor(config: OpsConfigFile, managedComponents: string[] = MANAGED_COMPONENTS) { + this._config = config; + this._managedComponents = managedComponents; + this._errors = []; + } + + /** + * Runs all validations and returns the result. + * + * Validates: + * 1. Component names against managed components list + * 2. Parameter key naming conventions + * + * @returns ValidationResult with success status and any errors found + */ + validate(): ValidationResult { + this._errors = []; + + this.validateComponentNames(); + this.validateAllParameters(); + + return { + success: this._errors.length === 0, + errors: this._errors, + }; + } + + /** + * Validates that all component names are in the managed components list. + * Adds errors for each unknown component found. + */ + private validateComponentNames(): void { + const componentNames = this._config.getComponentNames(); + + for (const name of componentNames) { + if (!this._managedComponents.includes(name)) { + this._errors.push(`Unknown component: '${name}'. Valid components: ${this._managedComponents.join(', ')}`); + } + } + } + + /** + * Validates parameters for all components. + */ + private validateAllParameters(): void { + const components = this._config.getAllComponents(); + + for (const component of components) { + this.validateComponentParameters(component); + } + } + + /** + * Validates all parameters in a single component. + * + * @param component - The component to validate + */ + private validateComponentParameters(component: ComponentConfig): void { + const parameters = component.getAllParameters(); + + for (const parameter of parameters) { + this.validateParameterKey(component.getName(), parameter); + } + } + + /** + * Validates a parameter key naming convention. + * + * Keys must: + * - Start with uppercase letter + * - Contain only uppercase letters, numbers, and underscores + * + * @param componentName - Name of the component (for error messages) + * @param parameter - The parameter to validate + */ + private validateParameterKey(componentName: string, parameter: ConfigParameter): void { + const key = parameter.getKey(); + + if (!/^[A-Z][A-Z0-9_]*$/.test(key)) { + this._errors.push( + `Invalid parameter key '${key}' in component '${componentName}'. Keys must be uppercase letters, numbers, and underscores only` + ); + } + } + + /** + * Returns all validation errors found. + * Should be called after validate() to get detailed error messages. + * + * @returns Array of error messages + */ + getErrors(): string[] { + return this._errors; + } +} diff --git a/util/config/configurator/configurator-class-diagram.mmd b/util/config/configurator/configurator-class-diagram.mmd new file mode 100644 index 00000000..5967e293 --- /dev/null +++ b/util/config/configurator/configurator-class-diagram.mmd @@ -0,0 +1,146 @@ +classDiagram + %% Core Domain Classes (types.ts) + class ConfigParameter { + -_key: string + -_label: string + -_initialValue: string + -_userInputValue: string + +getKey(): string + +getLabel(): string + +setLabel(label: string): void + +getInitialValue(): string + +getUserInputValue(): string + +setUserInputValue(value: string): void + +getValue(): string + +hasUserInput(): boolean + } + + class ComponentConfig { + -_name: string + -_parameters: Map~string, ConfigParameter~ + +getName(): string + +addParameter(parameter: ConfigParameter): void + +getParameter(key: string): ConfigParameter | undefined + +getAllParameters(): ConfigParameter[] + +getParameterKeys(): string[] + +hasParameter(key: string): boolean + +getParameterCount(): number + } + + class OpsConfigFile { + -_components: Map~string, ComponentConfig~ + +addComponent(component: ComponentConfig): void + +getComponent(name: string): ComponentConfig | undefined + +getAllComponents(): ComponentConfig[] + +getComponentNames(): string[] + +hasComponent(name: string): boolean + +getComponentCount(): number + } + + class EditableConfigParameter { + -_previousUserInputValue: string + +getPreviousUserInputValue(): string + +setPreviousUserInputValue(value: string): void + +updateUserInputValue(value: string): void + +revertToPrevious(): boolean + +fromConfigParameter(param: ConfigParameter)$ EditableConfigParameter + } + + class EditableComponentConfig { + +getAllParameters(): EditableConfigParameter[] + +getParameter(key: string): EditableConfigParameter | undefined + } + + class EditableOpsConfigFile { + +getAllComponents(): EditableComponentConfig[] + +getComponent(name: string): EditableComponentConfig | undefined + } + + %% Inheritance + ConfigParameter <|-- EditableConfigParameter + ComponentConfig <|-- EditableComponentConfig + OpsConfigFile <|-- EditableOpsConfigFile + + %% Composition relationships + OpsConfigFile *-- ComponentConfig : contains + ComponentConfig *-- ConfigParameter : contains + EditableOpsConfigFile *-- EditableComponentConfig : contains + EditableComponentConfig *-- EditableConfigParameter : contains + + %% Parser & Validator + class ConfigParser { + -_filePath: string + +load(): Promise~Result~OpsConfigFile, string~~ + +extractComponents(rawData: unknown): OpsConfigFile + +parseComponentSection(sectionName: string, sectionData: unknown): ComponentConfig + +parseParameter(key: string, value: unknown): ConfigParameter + } + + class ConfigValidator { + -_config: OpsConfigFile + -_managedComponents: string[] + -_errors: string[] + +validate(): ValidationResult + +getErrors(): string[] + } + + ConfigParser ..> OpsConfigFile : creates + ConfigValidator ..> OpsConfigFile : validates + + %% Configuration Management + class PartialConfigManager { + -_configFilePath: string + -_tmpFilePath: string + -_config: EditableOpsConfigFile + +load(): Promise~Result~EditableOpsConfigFile, string~~ + +save(): Promise~Result~void, string~~ + +clear(): Promise~Result~void, string~~ + +getConfig(): EditableOpsConfigFile + +setParameter(componentName: string, key: string, value: string): Promise~Result~void, string~~ + +revertParameter(componentName: string, key: string): Promise~Result~void, string~~ + +hasModifications(): boolean + +getModifiedParameters(): Array + } + + PartialConfigManager *-- EditableOpsConfigFile : manages + + %% Interactive Components + class EditLoop { + -_configManager: PartialConfigManager + -_exitHandler: ExitHandler + -_running: boolean + +start(): Promise~Result~void, string~~ + +stop(): void + +isRunning(): boolean + } + + class ExitHandler { + -_configManager: PartialConfigManager + +handleExit(): Promise~Result~void, string~~ + } + + class ConfigDisplay { + +displayParameterTable(componentName: string, parameters: EditableConfigParameter[])$ void + +displayComponentSummary(components: Array)$ void + +displayParameterDetail(parameter: EditableConfigParameter)$ void + +displayModifications(modifications: Array)$ void + +clearScreen()$ void + } + + EditLoop *-- ExitHandler : uses + EditLoop --> PartialConfigManager : uses + EditLoop --> ConfigDisplay : uses + ExitHandler --> PartialConfigManager : uses + ExitHandler --> ConfigDisplay : uses + + %% Result Types + class Result~T, E~ { + +success: boolean + +data?: T + +error?: E + } + + class ValidationResult { + +success: boolean + +errors: string[] + } diff --git a/util/config/configurator/configurator.ts b/util/config/configurator/configurator.ts index 6ae98c37..416cff87 100644 --- a/util/config/configurator/configurator.ts +++ b/util/config/configurator/configurator.ts @@ -1,17 +1,15 @@ -import { $ } from "bun"; - import { intro, outro, - select, - isCancel, cancel, - text, - password, } from "@clack/prompts"; -import color from "picocolors"; -import { parseArgs } from "util"; +import { styleText } from "node:util"; + +import { ConfigParser } from "./config-parser"; +import { ConfigValidator } from "./config-validator"; +import { EditLoop } from "./edit-loop"; +import { PartialConfigManager } from "./partial-config-manager"; type Prompts = Record; @@ -22,252 +20,77 @@ type PromptData = { value?: string; }; -const OPS = process.env.OPS || "ops"; - export const AdditionalArgsMsg = "Additional arguments will be ignored."; -export const NotValidJsonMsg = "Not a valid JSON file"; -export const FileNotFoundJsonMsg = "The JSON file was not found. Pathname: "; -export const BadConfigMsg = - "Bad configuration file. Check the help message (-h) to see the expected format."; export const HelpMsg = ` -Usage: config [-o | --override] +Usage: config [-h | --help] Description: -Prompt the user for configuration data defined in the config.json file. -The script will ignore the keys from the input config that are already set in ops -and only prompt the user for the missing data, unless the override flag is set. -Then they will be saved in the ops config. You can also define a default value. - -The config.json file must be a JSON file with the following structure: - - { - "KEY": { - "type": "string" - }, - "OTHER_KEY": { - "label": "An optional custom message", - "type": "int", - "default": "42" - }, - ... - } - -The keys must be uppercase words (separated by underscores). -The value for the "type" key must be either string with the following values: -- string -- int -- float -- bool -- password -- an array of strings with specific values (an enum). +Interactive configuration editor for ops configuration. +The tool loads configuration from all-config-parameters.toml and provides +an intuitive interface for editing parameters across all components. + +Features: +- Select components to configure +- Edit individual parameters +- Auto-save to .tmp file +- Resume editing after interruptions `; export default async function main() { - const options: { showhelp: { type: 'boolean' }, override: { type: 'boolean' } } = { - showhelp: { - type: 'boolean', - }, - override: { - type: 'boolean', - }, - }; - const { values, positionals } = parseArgs({ - args: Bun.argv, - options: options, - strict: true, - allowPositionals: true, - - }); - - if (values.showhelp) { + if (Bun.argv.includes('-h') || Bun.argv.includes('--help')) { console.log(HelpMsg); return process.exit(0); } - const override = values.override || false; + // Load and parse the TOML configuration file using OOP ConfigParser + const filePath = './all-config-parameters.toml'; - // 1. Read input config json - const readPosRes = readPositionalFile(positionals); - if (!readPosRes.success) { - cancel(readPosRes.message); - return process.exit(1); - } + // Create parser instance and load configuration from TOML file + const parser = new ConfigParser(filePath); + const loadResult = await parser.load(); - if (readPosRes.help) { - console.log(readPosRes.help); - return process.exit(0); + if (!loadResult.success) { + cancel(loadResult.error || 'Failed to load configuration'); + return process.exit(1); } - if (readPosRes.message) { - console.warn(readPosRes.message); - } + const config = loadResult.data!; - // 2. Parse the json - const jsonRes = await parsePositionalFile(readPosRes.jsonFilePath!); + // Validate configuration using OOP ConfigValidator + // Checks component names and parameter key conventions + const validator = new ConfigValidator(config); + const validationResult = validator.validate(); - if (!jsonRes.success) { - cancel(jsonRes.message); + if (!validationResult.success) { + console.error('Configuration validation errors:'); + validationResult.errors.forEach(err => console.error(` - ${err}`)); + cancel('Invalid configuration file'); return process.exit(1); } - const config = jsonRes.body; - - // 3. Validate the given config json - if (!isInputConfigValid(config)) { - cancel(BadConfigMsg); + // Create PartialConfigManager and EditLoop for interactive editing + const configManager = new PartialConfigManager(filePath); + + const loadPartialResult = await configManager.load(); + if (!loadPartialResult.success) { + cancel(loadPartialResult.error || 'Failed to load partial configuration'); return process.exit(1); } - // 4. Run OPS to get the available config data - const { exitCode, stderr, stdout } = await $`${OPS} -config -d`.quiet(); - if (exitCode !== 0) { - cancel(stderr.toString()); - return process.exit(1); - } + intro(styleText("inverse", " ops configurator ")); - const opsCurrentConfig = stdout.toString(); + const editLoop = new EditLoop(configManager); + const editResult = await editLoop.start(); - // 5. Remove the keys from config that are already in the opsConfig - let missingData = config; - if (!override) { - missingData = findMissingConfig(config, opsCurrentConfig); + if (!editResult.success) { + cancel(editResult.error || 'Configuration editing failed'); + return process.exit(1); } - // 6. Ask the user for the missing data console.log(); - intro(color.inverse(" ops configurator ")); - - await askMissingData(missingData, override); - - // 7. Save the data to the config? - console.log(); - outro("You're all set!"); -} - -async function askMissingData(missingData: Prompts, override: boolean = false) { - if (Object.keys(missingData).length === 0) { - outro("Configuration set from ops"); - process.exit(0); - } - console.log(); - - if (!override) { - console.log("Configuration partially set from ops. Need a few more:"); - } - - for (const key in missingData) { - let inputFromPrompt: string; - const prompt: PromptData = missingData[key]; - // let askedForPassword = false; - - if (Array.isArray(prompt.type)) { - const defaultValueOK = prompt.default && prompt.type.includes(prompt.default); - if (prompt.default && !defaultValueOK) { - console.log(); - console.warn(`The default value ${prompt.default} is not in the enum values.`); - } - - const selected = await select({ - message: prompt.label || `Pick a value for '${key}'`, - options: prompt.type.map((v) => ({ label: v, value: v })), - initialValue: defaultValueOK ? prompt.default : undefined, - }); - - if (!selected || isCancel(selected)) { - cancel("Operation cancelled"); - process.exit(0); - } - - inputFromPrompt = selected.toString(); - - // inputConfigs[key] = { ...prompt, value: selected.toString() }; - } else if (prompt.type === "bool") { - const selected = await select({ - initialValue: prompt.default === "true" || prompt.default as unknown as boolean === true ? "true" : "false", - message: prompt.label || `Pick a true/false for '${key}'`, - options: [ - { label: "true", value: "true" }, - { label: "false", value: "false" }, - ], - }); - - if (!selected || isCancel(selected)) { - cancel("Operation cancelled"); - process.exit(0); - } - - inputFromPrompt = selected.toString(); - // inputConfigs[key] = { ...prompt, value: selected.toString() }; - } else if (prompt.type === "password") { - if (prompt.default) { - console.log(); - console.warn("Default password value is not supported. Please enter the password manually."); - } - const input = await password({ - message: prompt.label || `Enter password value for ${key}`, - validate: (value) => { - if (!value) { - return "Password cannot be empty"; - } - } - }); - - if (isCancel(input)) { - cancel("Operation cancelled"); - process.exit(0); - } - inputFromPrompt = input; - // askedForPassword = true; - } else { - const defaultMsgFragment = prompt.default ? `(default: ${prompt.default})` : ""; - const message = `Enter value for ${key} ${defaultMsgFragment} (${prompt.type})`; - - let input = await text({ - message: prompt.label || message, - // defaultValue: prompt.default?.toString(), - initialValue: prompt.default?.toString(), - validate: (value) => { - switch (prompt.type) { - case "int": - if (!Number.isInteger(Number(value))) { - return `Value for ${key} must be an integer number`; - } - break; - case "float": - if (!Number(value)) { - return `Value for ${key} must be a number`; - } - } - return; - } - }) as string; - - if (isCancel(input)) { - cancel("Operation cancelled"); - process.exit(0); - } - - - inputFromPrompt = input; - // inputConfigs[key] = { ...prompt, value: input }; - } - - // if (!askedForPassword) { - // console.log("Setting", key, "to", inputFromPrompt); - // } else { - // console.log("Setting", key, "to", "*".repeat(inputFromPrompt.length)); - // } - - console.log(`Setting ${key} to ${inputFromPrompt}`); - const { exitCode, stderr } = - await $`${OPS} -config ${key}=${inputFromPrompt}`.nothrow(); - if (exitCode !== 0) { - cancel(stderr.toString()); - return process.exit(1); - } - } + return process.exit(0); } export function findMissingConfig( @@ -305,7 +128,7 @@ export function readPositionalFile(positionals: string[]): { } if (positionals.length > 3) { - return { + return { success: true, message: AdditionalArgsMsg, jsonFilePath: positionals[2], @@ -315,32 +138,11 @@ export function readPositionalFile(positionals: string[]): { return { success: true, jsonFilePath: positionals[2] }; } -export async function parsePositionalFile( - path: string -): Promise<{ success: boolean; message?: string; body?: any }> { - - const file = Bun.file(Bun.pathToFileURL(path)); - - if (!await file.exists()) { - return { success: false, message: FileNotFoundJsonMsg + Bun.pathToFileURL(path) }; - } - - - try { - const contents = await file.json(); - return { success: true, body: contents }; - } catch (error) { - return { success: false, message: NotValidJsonMsg }; - } -} - export function isInputConfigValid(body: Record): boolean { - // 1. If the body is empty, return false if (Object.keys(body).length === 0) { return false; } - // 2. Check that each key in the body has the keys as the Prompt type for (const key in body) { const value = body[key]; if (typeof value !== "object") { @@ -359,7 +161,6 @@ export function isInputConfigValid(body: Record): boolean { } } - // 3. Check that all the keys are uppercase and can only have underscores not at the beginning or end for (const key in body) { if (!/^[A-Z][A-Z_]|[0-9]*[A-Z]|[0-9]$/.test(key)) { return false; diff --git a/util/config/configurator/edit-loop.ts b/util/config/configurator/edit-loop.ts new file mode 100644 index 00000000..102b7249 --- /dev/null +++ b/util/config/configurator/edit-loop.ts @@ -0,0 +1,280 @@ +import { select, isCancel, cancel, text, password, note } from '@clack/prompts'; +import { PartialConfigManager } from './partial-config-manager'; +import { ConfigDisplay } from './config-display'; +import { ExitHandler } from './exit-handler'; +import type { Result } from './types'; +import {EditableComponentConfig, EditableConfigParameter} from "./types-core.ts"; + +/** + * Manages the interactive editing loop for configuration. + * + * Provides the main workflow: + * 1. Display list of components + * 2. User selects component with arrows + ENTER + * 3. Display parameters table + * 4. User selects parameter to edit + * 5. Edit parameter value + * 6. Save changes + * 7. Loop until user exits + */ +export class EditLoop { + private _configManager: PartialConfigManager; + private _exitHandler: ExitHandler; + private _running: boolean; + + /** + * Creates a new EditLoop instance. + * + * @param configManager - The configuration manager instance + */ + constructor(configManager: PartialConfigManager) { + this._configManager = configManager; + this._exitHandler = new ExitHandler(configManager); + this._running = false; + } + + /** + * Starts the interactive editing loop. + * + * Continues until user chooses to exit. + */ + async start(): Promise> { + this._running = true; + + while (this._running) { + const result = await this.selectComponent(); + + if (!result.success) { + if (result.error === 'User cancelled') { + this._running = false; + continue; + } + return { success: false, error: result.error }; + } + + if (!result.data) { + this._running = false; + continue; + } + + await this.editComponent(result.data); + } + + return await this._exitHandler.handleExit(); + } + + /** + * Displays component selection prompt. + * + * User can navigate with ↑/↓ arrows and select with ENTER. Pressing ESC or CTRL+C cancels the selection. + * + * @returns Result with selected component name or error + * + * Result can be: + * - { success: false, error: 'No components found in configuration' } when no components are found in the given configuration. + * - { success: false, error: 'User cancelled' } when user cancels the selection + * - { success: true, data: 'ComponentName' } when a component is selected + * - { success: true, data: null } when user chooses to exit + * - { success: false, error: 'Error message' } on failure or cancellation + */ + private async selectComponent(): Promise> { + const config = this._configManager.getConfig(); + const components = config.getAllComponents(); + + if (components.length === 0) { + return { + success: false, + error: 'No components found in configuration', + }; + } + + const options = components.map((comp) => { + const paramCount = comp.getParameterCount(); + return { + label: `${comp.getName()} (${paramCount} parameters)`, + value: comp.getName(), + }; + }); + + options.push({ label: 'Exit Configuration', value: '__exit__' }); + + const selected = await select({ + message: 'Select a component to configure (use ↑/↓ arrows, ENTER to select):', + options, + }); + + if (isCancel(selected)) { + return { success: false, error: 'User cancelled' }; + } + + if (selected === '__exit__') { + return { success: true, data: null }; + } + + return { success: true, data: selected as string }; + } + + /** + * Handles editing of a specific component. + * + * @param componentName - Name of the component to edit + */ + private async editComponent(componentName: string): Promise { + const component = this._configManager.getConfig().getComponent(componentName); + + if (!component) { + console.error(`Component '${componentName}' not found`); + return; + } + + let editingComponent = true; + + while (editingComponent) { + ConfigDisplay.clearScreen(); + ConfigDisplay.displayParameterTable(componentName, component.getAllParameters()); + + const result = await this.selectParameter(component); + + if (!result.success) { + editingComponent = false; + continue; + } + + if (!result.data) { + editingComponent = false; + continue; + } + + await this.editParameter(component, result.data); + } + } + + /** + * Displays parameter selection prompt for a component. + * + * @param component - The component to select parameters from + * @returns Result with selected parameter key or error + */ + private async selectParameter( + component: EditableComponentConfig + ): Promise> { + const parameters = component.getAllParameters(); + + if (parameters.length === 0) { + return { success: false, error: 'No parameters in this component' }; + } + + const options = parameters.map((param) => { + const raw = param.getValue(); + const currentValue = param.getType() === 'password' + ? (raw ? '***' : '') + : (raw || ''); + return { + label: `${param.getLabel()} = ${currentValue}`, + value: param.getKey(), + }; + }); + + options.push({ label: '← Back to components', value: '__back__' }); + + const selected = await select({ + message: 'Select a parameter to edit (use ↑/↓ arrows, ENTER to select, ESC or CTRL+C to Cancel):', + options, + }); + + if (isCancel(selected)) { + return { success: false, error: 'User cancelled' }; + } + + if (selected === '__back__') { + return { success: true, data: null }; + } + + return { success: true, data: selected as string }; + } + + /** + * Handles editing of a specific parameter. + * + * @param component - The component containing the parameter + * @param paramKey - The parameter key to edit + */ + private async editParameter( + component: EditableComponentConfig, + paramKey: string + ): Promise { + const parameter = component.getParameter(paramKey); + + if (!parameter) { + console.error(`Parameter '${paramKey}' not found`); + return; + } + + // ConfigDisplay.displayParameterDetail(parameter); + + // note("Type new value and press ENTER to confirm\nPress CTRL+C or ESC to cancel. The previous value will be preserved if cancelled\n","Instructions") + + const currentValue = parameter.getUserInputValue() || parameter.getInitialValue(); + const isPassword = parameter.getType() === 'password'; + const hint = parameter.getHint(); + + if (hint) { + note(hint, "What is this parameter for?"); + } + + let value: string | null; + + const promptInput = isPassword + ? await password({ + //message: `Enter new value for ${paramKey}:`, + message: `Enter new value for ${parameter.getLabel()}:`, + validate: (v) => { + if (parameter.isMandatory() && !v) return 'this field is mandatory and cannot be empty'; + return undefined; + }, + }) + : await text({ + message: `Enter new value for ${parameter.getLabel()}:`, + initialValue: currentValue, + placeholder: currentValue || 'Enter value...', + validate: (v) => { + if (parameter.isMandatory() && !v) return 'this field is mandatory and cannot be empty'; + return undefined; + }, + }); + + if (isCancel(promptInput)) { + console.log('\nCancelled - value unchanged.\n'); + return; + } + value = promptInput as string; + + const result = await this._configManager.setParameter( + component.getName(), + paramKey, + value + ); + + if (result.success) { + console.log(`\n✓ Updated ${paramKey} to: ${isPassword ? '***' : value}\n`); + } else { + console.error(`\n✗ Failed to update ${paramKey}: ${result.error}\n`); + } + } + + /** + * Stops the editing loop. + */ + stop(): void { + this._running = false; + } + + /** + * Checks if the editing loop is running. + * + * @returns true if running, false otherwise + */ + isRunning(): boolean { + return this._running; + } +} diff --git a/util/config/configurator/exit-handler.ts b/util/config/configurator/exit-handler.ts new file mode 100644 index 00000000..371405ac --- /dev/null +++ b/util/config/configurator/exit-handler.ts @@ -0,0 +1,245 @@ +import { $ } from 'bun'; +import { select, isCancel, cancel } from '@clack/prompts'; +import { PartialConfigManager } from './partial-config-manager'; +import { ConfigDisplay } from './config-display'; +import type { Result } from './types'; + +const OPS = process.env.OPS || 'ops'; + +/** + * Handles application exit workflow with configuration options. + * + * Provides options to: + * - Apply configuration directly to ops + * - Save configuration to a file + * - Discard all changes + */ +export class ExitHandler { + private _configManager: PartialConfigManager; + + /** + * Creates a new ExitHandler instance. + * + * @param configManager - The configuration manager instance + */ + constructor(configManager: PartialConfigManager) { + this._configManager = configManager; + } + + /** + * Handles the exit workflow by presenting options to the user. + * + * @returns Result indicating success or failure with error message + */ + async handleExit(): Promise> { + const hasModifications = this._configManager.hasModifications(); + + if (!hasModifications) { + console.log('\nNo modifications to apply.\n'); + await this._configManager.clear(); + return { success: true }; + } + + const modifications = this._configManager.getModifiedParameters(); + ConfigDisplay.displayModifications(modifications); + + const action = await select({ + message: 'What would you like to do with your changes?', + options: [ + { label: 'Apply configuration directly', value: 'apply' }, + { label: 'Save configuration to file', value: 'save' }, + { label: 'Discard all changes', value: 'discard' }, + ], + }); + + if (isCancel(action)) { + return { success: true }; + } + + switch (action) { + case 'apply': + return await this.applyConfiguration(); + case 'save': + return await this.saveConfigurationToFile(); + case 'discard': + return await this.discardChanges(); + default: + return { success: true }; + } + } + + /** + * Applies configuration directly to ops by executing ops -config KEY=VALUE commands. + * + * @returns Result indicating success or failure + */ + private async applyConfiguration(): Promise> { + const modifications = this._configManager.getModifiedParameters(); + + if (modifications.length === 0) { + console.log('No modifications to apply.\n'); + return { success: true }; + } + + console.log('\nApplying configuration to ops...\n'); + + let appliedCount = 0; + let errorCount = 0; + + for (const mod of modifications) { + for (const param of mod.parameters) { + const key = param.getKey(); + const value = param.getValue(); + + if (!value || value === '') { + console.log(`Skipping ${key} (empty value)`); + continue; + } + + try { + const { exitCode, stderr } = await $`${OPS} -config ${key}=${value}`.nothrow().quiet(); + + if (exitCode === 0) { + console.log(`✓ Set ${key}=${value}`); + appliedCount++; + } else { + console.error(`✗ Failed to set ${key}: ${stderr.toString()}`); + errorCount++; + } + } catch (error) { + console.error(`✗ Error setting ${key}: ${error}`); + errorCount++; + } + } + } + + console.log(`\nApplied ${appliedCount} configuration(s).`); + if (errorCount > 0) { + console.log(`Failed to apply ${errorCount} configuration(s).\n`); + } else { + console.log(); + } + + if (errorCount === 0) { + await this._configManager.clear(); + return { success: true }; + } else { + return { + success: false, + error: `Failed to apply ${errorCount} configuration(s)`, + }; + } + } + + /** + * Saves configuration to a TOML file that can be used later. + * + * @returns Result indicating success or failure + */ + private async saveConfigurationToFile(): Promise> { + const timestamp = new Date().toISOString().replace(/[:.]/g, '-').substring(0, 19); + const outputFileName = `ops-config-${timestamp}.toml`; + + try { + const config = this._configManager.getConfig(); + const tomlData = this.serializeConfigToToml(config); + + await Bun.write(outputFileName, tomlData); + + console.log(`\n✓ Configuration saved to: ${outputFileName}\n`); + + const shouldClear = await select({ + message: 'Clear partial configuration?', + options: [ + { label: 'Yes', value: 'yes' }, + { label: 'No', value: 'no' }, + ], + }); + + if (!isCancel(shouldClear) && shouldClear === 'yes') { + await this._configManager.clear(); + console.log('Partial configuration cleared.\n'); + } + + return { success: true }; + } catch (error) { + return { + success: false, + error: `Failed to save configuration: ${error}`, + }; + } + } + + /** + * Discards all changes by clearing the partial configuration. + * + * @returns Result indicating success or failure + */ + private async discardChanges(): Promise> { + const clearResult = await this._configManager.clear(); + + if (clearResult.success) { + console.log('\n✓ All changes discarded.\n'); + } + + return clearResult; + } + + /** + * Serializes configuration to TOML format for file output. + * + * @param config - The configuration to serialize + * @returns TOML formatted string + */ + private serializeConfigToToml(config: any): string { + let toml = '# OpenServerless Configuration\n'; + toml += `# Generated: ${new Date().toISOString()}\n\n`; + + const components = config.getAllComponents(); + for (const component of components) { + const parameters = component.getAllParameters(); + const modifiedParams = parameters.filter( + (p: any) => p.getValue() !== '' && p.getValue() !== p.getInitialValue() + ); + + if (modifiedParams.length === 0) { + continue; + } + + toml += `[components.${component.getName()}]\n`; + + for (const param of modifiedParams) { + const key = param.getKey(); + const value = param.getValue(); + const label = param.getLabel(); + const escapedValue = this.escapeTomlValue(value); + + if (label) { + const escapedLabel = this.escapeTomlValue(label); + toml += `${key}={label="${escapedLabel}", userInputValue="${escapedValue}"}\n`; + } else { + toml += `${key}="${escapedValue}"\n`; + } + } + + toml += '\n'; + } + + return toml; + } + + /** + * Escapes a value for TOML format. + * + * @param value - The value to escape + * @returns Escaped string safe for TOML + */ + private escapeTomlValue(value: string): string { + return value + .replace(/\\/g, '\\\\') + .replace(/"/g, '\\"') + .replace(/\n/g, '\\n') + .replace(/\r/g, '\\r') + .replace(/\t/g, '\\t'); + } +} diff --git a/util/config/configurator/package-lock.json b/util/config/configurator/package-lock.json new file mode 100644 index 00000000..da30228d --- /dev/null +++ b/util/config/configurator/package-lock.json @@ -0,0 +1,123 @@ +{ + "name": "prompt", + "lockfileVersion": 3, + "requires": true, + "packages": { + "": { + "name": "prompt", + "dependencies": { + "@clack/prompts": "^1.0.1", + "toml": "^3.0.0" + }, + "devDependencies": { + "@types/bun": "latest" + }, + "peerDependencies": { + "typescript": "^5.0.0" + } + }, + "node_modules/@clack/core": { + "version": "1.3.0", + "resolved": "https://registry.npmjs.org/@clack/core/-/core-1.3.0.tgz", + "integrity": "sha512-xJPHpAmEQUBrXSLx0gF+q5K/IyihXpsHZcha+jB+tyahsKRK3Dxo4D0coZDewHo12NhiuzC3dTtMPbm53GEAAA==", + "dependencies": { + "fast-wrap-ansi": "^0.2.0", + "sisteransi": "^1.0.5" + }, + "engines": { + "node": ">= 20.12.0" + } + }, + "node_modules/@clack/prompts": { + "version": "1.3.0", + "resolved": "https://registry.npmjs.org/@clack/prompts/-/prompts-1.3.0.tgz", + "integrity": "sha512-GgcWwRCs/xPtaqlMy8qRhPnZf9vlWcWZNHAitnVQ3yk7JmSralSiq5q07yaffYE8SogtDm7zFeKccx1QNVARpw==", + "dependencies": { + "@clack/core": "1.3.0", + "fast-string-width": "^3.0.2", + "fast-wrap-ansi": "^0.2.0", + "sisteransi": "^1.0.5" + }, + "engines": { + "node": ">= 20.12.0" + } + }, + "node_modules/@types/bun": { + "version": "1.3.13", + "resolved": "https://registry.npmjs.org/@types/bun/-/bun-1.3.13.tgz", + "integrity": "sha512-9fqXWk5YIHGGnUau9TEi+qdlTYDAnOj+xLCmSTwXfAIqXr2x4tytJb43E9uCvt09zJURKXwAtkoH4nLQfzeTXw==", + "dev": true, + "dependencies": { + "bun-types": "1.3.13" + } + }, + "node_modules/@types/node": { + "version": "25.6.0", + "resolved": "https://registry.npmjs.org/@types/node/-/node-25.6.0.tgz", + "integrity": "sha512-+qIYRKdNYJwY3vRCZMdJbPLJAtGjQBudzZzdzwQYkEPQd+PJGixUL5QfvCLDaULoLv+RhT3LDkwEfKaAkgSmNQ==", + "dev": true, + "dependencies": { + "undici-types": "~7.19.0" + } + }, + "node_modules/bun-types": { + "version": "1.3.13", + "resolved": "https://registry.npmjs.org/bun-types/-/bun-types-1.3.13.tgz", + "integrity": "sha512-QXKeHLlOLqQX9LgYaHJfzdBaV21T63HhFJnvuRCcjZiaUDpbs5ED1MgxbMra71CsryN/1dAoXuJJJwIv/2drVA==", + "dev": true, + "dependencies": { + "@types/node": "*" + } + }, + "node_modules/fast-string-truncated-width": { + "version": "3.0.3", + "resolved": "https://registry.npmjs.org/fast-string-truncated-width/-/fast-string-truncated-width-3.0.3.tgz", + "integrity": "sha512-0jjjIEL6+0jag3l2XWWizO64/aZVtpiGE3t0Zgqxv0DPuxiMjvB3M24fCyhZUO4KomJQPj3LTSUnDP3GpdwC0g==" + }, + "node_modules/fast-string-width": { + "version": "3.0.2", + "resolved": "https://registry.npmjs.org/fast-string-width/-/fast-string-width-3.0.2.tgz", + "integrity": "sha512-gX8LrtNEI5hq8DVUfRQMbr5lpaS4nMIWV+7XEbXk2b8kiQIizgnlr12B4dA3ZEx3308ze0O4Q1R+cHts8kyUJg==", + "dependencies": { + "fast-string-truncated-width": "^3.0.2" + } + }, + "node_modules/fast-wrap-ansi": { + "version": "0.2.0", + "resolved": "https://registry.npmjs.org/fast-wrap-ansi/-/fast-wrap-ansi-0.2.0.tgz", + "integrity": "sha512-rLV8JHxTyhVmFYhBJuMujcrHqOT2cnO5Zxj37qROj23CP39GXubJRBUFF0z8KFK77Uc0SukZUf7JZhsVEQ6n8w==", + "dependencies": { + "fast-string-width": "^3.0.2" + } + }, + "node_modules/sisteransi": { + "version": "1.0.5", + "resolved": "https://registry.npmjs.org/sisteransi/-/sisteransi-1.0.5.tgz", + "integrity": "sha512-bLGGlR1QxBcynn2d5YmDX4MGjlZvy2MRBDRNHLJ8VI6l6+9FUiyTFNJ0IveOSP0bcXgVDPRcfGqA0pjaqUpfVg==" + }, + "node_modules/toml": { + "version": "3.0.0", + "resolved": "https://registry.npmjs.org/toml/-/toml-3.0.0.tgz", + "integrity": "sha512-y/mWCZinnvxjTKYhJ+pYxwD0mRLVvOtdS2Awbgxln6iEnt4rk0yBxeSBHkGJcPucRiG0e55mwWp+g/05rsrd6w==" + }, + "node_modules/typescript": { + "version": "5.9.3", + "resolved": "https://registry.npmjs.org/typescript/-/typescript-5.9.3.tgz", + "integrity": "sha512-jl1vZzPDinLr9eUt3J/t7V6FgNEw9QjvBPdysz9KfQDD41fQrC2Y4vKQdiaUpFT4bXlb1RHhLpp8wtm6M5TgSw==", + "peer": true, + "bin": { + "tsc": "bin/tsc", + "tsserver": "bin/tsserver" + }, + "engines": { + "node": ">=14.17" + } + }, + "node_modules/undici-types": { + "version": "7.19.2", + "resolved": "https://registry.npmjs.org/undici-types/-/undici-types-7.19.2.tgz", + "integrity": "sha512-qYVnV5OEm2AW8cJMCpdV20CDyaN3g0AjDlOGf1OW4iaDEx8MwdtChUp4zu4H0VP3nDRF/8RKWH+IPp9uW0YGZg==", + "dev": true + } + } +} diff --git a/util/config/configurator/package.json b/util/config/configurator/package.json index bbd833cf..606eeba0 100644 --- a/util/config/configurator/package.json +++ b/util/config/configurator/package.json @@ -4,6 +4,7 @@ "type": "module", "scripts": { "start": "bun index.ts", + "startdebug": "bun --inspect-wait index.ts", "test": "bun test tests/index.test.ts", "build": "bun build --target=bun index.ts > configurator.js && mv configurator.js ../configurator.js" }, @@ -14,6 +15,7 @@ "typescript": "^5.0.0" }, "dependencies": { - "@clack/prompts": "^0.7.0" + "@clack/prompts": "^1.0.1", + "toml": "^3.0.0" } } diff --git a/util/config/configurator/partial-config-manager.ts b/util/config/configurator/partial-config-manager.ts new file mode 100644 index 00000000..53536cdc --- /dev/null +++ b/util/config/configurator/partial-config-manager.ts @@ -0,0 +1,424 @@ +import type { Result } from './types'; +import {EditableComponentConfig, EditableConfigParameter} from "./types-core.ts"; +import {EditableOpsConfigFile} from "./types-config-file.ts"; + +/** + * Manages partial configuration state with persistence to .tmp file. + * + * This class provides an abstraction layer for reading and writing + * partial configuration, enabling users to continue where they left off + * after exiting the application. + */ +export class PartialConfigManager { + private _configFilePath: string; + private _tmpFilePath: string; + private _config: EditableOpsConfigFile; + + /** + * Creates a new PartialConfigManager instance. + * + * @param configFilePath - Path to the main configuration file + */ + constructor(configFilePath: string) { + this._configFilePath = configFilePath; + this._tmpFilePath = configFilePath.replace(/\.toml$/, '.tmp'); + this._config = new EditableOpsConfigFile(); + } + + /** + * Returns the path to the temporary file. + * + * @returns The .tmp file path + */ + getTmpFilePath(): string { + return this._tmpFilePath; + } + + /** + * Returns the path to the main configuration file. + * + * @returns The configuration file path + */ + getConfigFilePath(): string { + return this._configFilePath; + } + + /** + * Checks if a partial configuration file exists. + * + * @returns true if .tmp file exists, false otherwise + */ + async hasPartialConfig(): Promise { + const file = Bun.file(this._tmpFilePath); + return await file.exists(); + } + + /** + * Loads configuration from the .tmp file if it exists, + * otherwise loads from the main configuration file. + * + * @returns Result containing the loaded configuration or error message + */ + async load(): Promise> { + try { + const hasPartial = await this.hasPartialConfig(); + const filePathToLoad = hasPartial ? this._tmpFilePath : this._configFilePath; + + const file = Bun.file(filePathToLoad); + if (!(await file.exists())) { + return { + success: false, + error: `Configuration file not found: ${filePathToLoad}`, + }; + } + + const content = await file.text(); + const rawData = await this.parseTomlContent(content); + + if (!rawData) { + return { + success: false, + error: `Failed to parse TOML file: ${filePathToLoad}`, + }; + } + + this._config = this.extractComponents(rawData); + + return { + success: true, + data: this._config, + }; + } catch (error) { + return { + success: false, + error: `Error loading configuration: ${error}`, + }; + } + } + + /** + * Parses TOML content directly without caching. + * + * @param content - Raw TOML content + * @returns Parsed TOML data as unknown object, or null on failure + */ + private async parseTomlContent(content: string): Promise { + try { + const toml = await import('toml'); + return toml.parse(content); + } catch (error) { + return null; + } + } + + /** + * Saves the current configuration state to the .tmp file. + * + * @returns Result indicating success or failure with error message + */ + async save(): Promise> { + try { + const tomlData = this.serializeToToml(); + await Bun.write(this._tmpFilePath, tomlData); + + return { success: true }; + } catch (error) { + return { + success: false, + error: `Error saving configuration: ${error}`, + }; + } + } + + /** + * Clears the partial configuration by deleting the .tmp file. + * + * @returns Result indicating success or failure with error message + */ + async clear(): Promise> { + try { + const file = Bun.file(this._tmpFilePath); + if (await file.exists()) { + const { $ } = await import('bun'); + await $`rm ${this._tmpFilePath}`.quiet(); + } + return { success: true }; + } catch (error) { + return { + success: false, + error: `Error clearing partial configuration: ${error}`, + }; + } + } + + /** + * Returns the current configuration state. + * + * @returns The editable configuration + */ + getConfig(): EditableOpsConfigFile { + return this._config; + } + + /** + * Retrieves a parameter from a specific component. + * + * @param componentName - Name of the component + * @param key - Parameter key + * @returns The parameter if found, undefined otherwise + */ + getParameter(componentName: string, key: string): EditableConfigParameter | undefined { + const component = this._config.getComponent(componentName); + if (!component) { + return undefined; + } + return component.getParameter(key); + } + + /** + * Sets the user input value for a parameter. + * + * Updates the parameter and automatically saves to the .tmp file. + * Tracks the previous value in previousUserInputValue. + * + * @param componentName - Name of the component + * @param key - Parameter key + * @param value - New user input value + * @returns Result indicating success or failure + */ + async setParameter( + componentName: string, + key: string, + value: string + ): Promise> { + const parameter = this.getParameter(componentName, key); + if (!parameter) { + return { + success: false, + error: `Parameter '${key}' not found in component '${componentName}'`, + }; + } + + parameter.updateUserInputValue(value); + + const saveResult = await this.save(); + if (!saveResult.success) { + return saveResult; + } + + return { success: true }; + } + + /** + * Reverts a parameter to its previous user input value. + * + * @param componentName - Name of the component + * @param key - Parameter key + * @returns Result indicating success or failure + */ + async revertParameter( + componentName: string, + key: string + ): Promise> { + const parameter = this.getParameter(componentName, key); + if (!parameter) { + return { + success: false, + error: `Parameter '${key}' not found in component '${componentName}'`, + }; + } + + const reverted = parameter.revertToPrevious(); + if (!reverted) { + return { + success: false, + error: `No previous value to revert for parameter '${key}'`, + }; + } + + const saveResult = await this.save(); + if (!saveResult.success) { + return saveResult; + } + + return { success: true }; + } + + /** + * Extracts all components from parsed TOML data. + * + * @param rawData - Parsed TOML data + * @returns EditableOpsConfigFile containing all extracted components + */ + private extractComponents(rawData: unknown): EditableOpsConfigFile { + const config = new EditableOpsConfigFile(); + + if (typeof rawData !== 'object' || rawData === null) { + return config; + } + + const data = rawData as Record; + + if (!data.components || typeof data.components !== 'object') { + return config; + } + + const components = data.components as Record; + + for (const [componentName, componentData] of Object.entries(components)) { + const component = this.parseComponentSection(componentName, componentData); + if (component.getParameterCount() > 0) { + config.addComponent(component); + } + } + + return config; + } + + /** + * Parses a single component section from TOML. + * + * @param sectionName - Name of the component section + * @param sectionData - Key-value pairs in this section + * @returns EditableComponentConfig with all parsed parameters + */ + private parseComponentSection(sectionName: string, sectionData: unknown): EditableComponentConfig { + const component = new EditableComponentConfig(sectionName); + + if (typeof sectionData !== 'object' || sectionData === null) { + return component; + } + + const data = sectionData as Record; + + for (const [key, value] of Object.entries(data)) { + if (key.startsWith('#')) { + continue; + } + + const parameter = this.parseParameter(key, value); + component.addParameter(parameter); + } + + return component; + } + + /** + * Parses a single parameter value from TOML. + * + * @param key - The parameter key + * @param value - The parameter value + * @returns EditableConfigParameter instance + */ + private parseParameter(key: string, value: unknown): EditableConfigParameter { + if (typeof value === 'string') { + return new EditableConfigParameter(key, '', value, '', '', false); + } + + if (typeof value === 'object' && value !== null) { + const data = value as Record; + const label = typeof data.label === 'string' ? data.label : ''; + const initialValue = typeof data.initialValue === 'string' ? data.initialValue : ''; + const userInputValue = typeof data.userInputValue === 'string' ? data.userInputValue : ''; + const previousUserInputValue = typeof data.previousUserInputValue === 'string' + ? data.previousUserInputValue : ''; + const isMandatory = typeof data.isMandatory === 'boolean' ? data.isMandatory : false; + const type = data.type === 'password' ? 'password' : 'string'; + const hint = typeof data.hint === 'string' ? data.hint : undefined; + + return new EditableConfigParameter(key, label, initialValue, userInputValue, previousUserInputValue, isMandatory, type, hint); + } + + return new EditableConfigParameter(key, '', '', '', '', false); + } + + /** + * Serializes the editable configuration to TOML format. + * + * Format: KEY={label="