2240 enhancement use const enums or enums for certain values - #810
Draft
correct-horse-battery-bench wants to merge 11 commits into
Draft
2240 enhancement use const enums or enums for certain values#810correct-horse-battery-bench wants to merge 11 commits into
correct-horse-battery-bench wants to merge 11 commits into
Conversation
Model discrete values as `const` object enums with `as const` plus a matching type alias, per the style guide, and give the remaining inline literals names. - New `_constants/http.config.ts` with `HttpStatus` and `HttpHeaderName`, replacing the status codes and the `X-Skip-Error-Dialog` / `X-Cache-Skip` literals spread over the interceptors, datasources and edit pages. - `ASC` and `STATCALCULATION` were static-only classes used in type position, where a class name resolves to its (empty) instance type instead of the union of its values, so `statType: ASC` accepted almost anything. As const objects with a type alias they type as `1 | 2 | 3` and `1 | 2`. Other static-constant classes are left alone; their members were already `static readonly` and never used as types. - TS enums become const object enums: `AgentOS`, `IgnoreErrors`, `FileType`, `TaskType`, `TaskStatus`, `RelationshipType`; `ChunkState` and `HashListFormat` gain `as const` and a type alias. - New const object enums for values that were bare strings or numbers: `HashSource`, `HashcatBrainFeature`, `HashcatAttackMode`, `StaticChunking`, `ServerLogLevel`, `ProxyType`, `Layout`, `BuiltInTheme`, `HashesViewType`, `HashesFilter`, `HashesDisplay`, `HealthCheckType`, `HealthCheckHashType`. - Named the remaining loose literals: `HCCAPX_PMKID_HASH_TYPE_IDS`, `HASHCAT_BRAIN_ENABLE_CONFIG_ID`, `MUTATION_DEBOUNCE_MS`, `DEFAULT_PAGE_SIZE`, `DEFAULT_SESSION_LIFETIME_SECONDS`, `BRIGHTNESS_MIDPOINT`, `THEME_STORAGE_KEY`.
Convert the value sets the first pass left behind and replace the magic numbers and strings that were still spelled out inline, all following the `as const` + `(typeof X)[keyof typeof X]` convention from the style guide. - Remaining TS `enum`s become const object enums: `FilterType`, and the 29 permission groups plus `Perm` in `userpermissions.config.ts`. The only `enum`s left are the per-table `*TableCol` column ids, whose auto-numbered members are used as the ids themselves; the style guide claim is now true. - `HealthCheckStatus` had `as const` on each member and a hand-written `HealthCheckStatusValue` union next to it; it now carries the object-level assertion and a matching alias. - The duplicate `HealthCheckType` enum in `health-check.model.ts` held the hashcat modes (0, 3200), not the attack modes the config const of the same name lists, so `JHealthCheck.checkType` now uses `HealthCheckHashType`, which is what the generated zod schema declares. - `ACTION`/`NOTIF` and `ExportMenuLabel`/`ExportMenuAction` were static-only classes; as const objects the derived arrays type as `ACTION[]`/`NOTIF[]` instead of `Array<string>`. - New const object enums for values that were bare literals: `HttpMethod`, `FileSource`, `NewFileTab`, `StaticArrayKind` and `HashesSelectKind`. - Named the remaining loose literals: `DEFAULT_CRACKER_BINARY_TYPE_NAME`, `API_ENDPOINT_STORAGE_KEY`, and moved `DEFAULT_PAGE_SIZE` next to the 41 table defaults that repeated `25`. `FilesTusService.STORAGE_KEY` was an unused second copy of `AuthService.STORAGE_KEY` and is gone. - Existing consts now cover the call sites that still used raw values: `Layout` in `setBodyClasses`, `FileType` in the files page switch, `HealthCheckStatus` in the status pipe, `HashesFilter` in the hashes datasource, and `HashSource` in the cracked-hashes import. `CheckboxColumnType` keeps its literal union and the `'CMD'`/`'CMD_PREPRO'` call sites: the union already checks them, including in the template. Typing the hashes view's display/filter selector surfaced a bug: `getDescrip` only handles the two selectors, but `buildForm` passed 2 and 3, so restoring `display` from the query params looked the description up in the filter list and always missed. Both call sites now pass `HashesSelectKind`.
Replaces the repeated { [HttpHeaderName.X]: HTTP_HEADER_ENABLED } literals
with HTTP_SKIP_ERROR_HEADER_CONFIG and HTTP_SKIP_CACHE_HEADER_CONFIG, so
call sites just pass the config to new HttpHeaders().
…for-certain-values # Conflicts: # src/app/core/_components/forms/simple-forms/form.component.ts # src/app/core/_components/tables/files-attack-table/files-attack-table.component.ts # src/app/core/_components/tables/hashes-table/hashes-table.component.ts # src/app/core/_constants/tasks.config.ts # src/app/core/_models/config-ui.model.ts # src/app/hashlists/hashes/hashes.component.ts # src/app/hashlists/import-cracked-hashes/import-cracked-hashes.component.ts # src/app/hashlists/new-hashlist/new-hashlist.component.ts # src/app/tasks/edit-supertasks/edit-supertasks.component.ts # src/app/tasks/edit-tasks/edit-tasks.component.ts # src/app/tasks/import-supertasks/wrbulk/wrbulk.component.ts # src/app/tasks/new-preconfigured-tasks/new-preconfigured-tasks.component.ts # src/app/tasks/new-tasks/new-tasks.component.html # src/app/tasks/new-tasks/new-tasks.component.ts # src/app/tasks/new-tasks/new-tasks.form.ts
Contributor
There was a problem hiding this comment.
Pull request overview
This PR standardizes “magic” string/number values across the Angular UI by replacing them with as const objects + union types (and a small set of shared constants), improving type-safety and readability while aligning the repo with the updated style guide guidance.
Changes:
- Introduces/expands shared constant modules (e.g., HTTP status/method/header names, hashlist formats/sources, UI layout/theme) and refactors existing
enum/class-constants intoas constobjects + union types. - Replaces hard-coded literals in components, templates, interceptors, datasources, and utilities with the new constants.
- Updates documentation to reflect the “prefer const objects over enums” convention.
Reviewed changes
Copilot reviewed 99 out of 99 changed files in this pull request and generated 4 comments.
Show a summary per file
| File | Description |
|---|---|
| STYLE_GUIDE.md | Documents preference for as const + union types over TS enums. |
| src/app/users/new-user/new-user.component.ts | Replaces hard-coded session lifetime with a named constant. |
| src/app/tasks/supertasks/applyhashlist.component.ts | Uses HashListFormat and shared default cracker type name constant. |
| src/app/tasks/new-preconfigured-tasks/new-preconfigured-tasks.component.ts | Exposes FileType for template use (and updates imports). |
| src/app/tasks/new-preconfigured-tasks/new-preconfigured-tasks.component.html | Replaces numeric file-type literals with FileType.*. |
| src/app/tasks/import-supertasks/wrbulk/wrbulk.component.ts | Exposes FileType for template use (and updates imports). |
| src/app/tasks/import-supertasks/wrbulk/wrbulk.component.html | Replaces numeric file-type literals with FileType.*. |
| src/app/tasks/edit-tasks/edit-tasks.component.ts | Exposes HashListFormat for template comparisons. |
| src/app/tasks/edit-tasks/edit-tasks.component.spec.ts | Uses centralized HTTP header name constants in assertions. |
| src/app/tasks/edit-tasks/edit-tasks.component.html | Replaces numeric hashlist format comparisons with HashListFormat.*. |
| src/app/tasks/edit-supertasks/edit-supertasks.component.ts | Uses centralized HttpStatus constants for status handling. |
| src/app/tasks/edit-preconfigured-tasks/edit-preconfigured-tasks.component.ts | Uses centralized HttpStatus constants for status handling. |
| src/app/shared/utils/forms.ts | Replaces brightness magic number with a named constant. |
| src/app/shared/utils/estkeyspace_attack.ts | Introduces HashcatAttackMode constants for attack-type comparisons. |
| src/app/shared/graphs/echarts/agent-stat-graph/agent-stat-graph.component.ts | Types statType as ASC and exposes constants for template use. |
| src/app/shared/graphs/echarts/agent-stat-graph/agent-stat-graph.component.html | Uses ASC.* instead of numeric stat type literals. |
| src/app/layout/header/header.component.ts | Uses BuiltInTheme.* instead of literal theme strings. |
| src/app/home/home.component.ts | Uses BuiltInTheme.* defaults when resolving stored theme. |
| src/app/hashlists/new-hashlist/new-hashlist.form.ts | Strongly types form controls with hashlist-related constants. |
| src/app/hashlists/new-hashlist/new-hashlist.component.ts | Centralizes config id, header config, http method, and hashlist constants usage. |
| src/app/hashlists/new-hashlist/new-hashlist.component.spec.ts | Uses centralized HTTP header name constants in assertions. |
| src/app/hashlists/new-hashlist/new-hashlist.component.html | Uses HashSource.* in template conditionals. |
| src/app/hashlists/import-cracked-hashes/import-cracked-hashes.form.ts | Types sourceType using HashSource. |
| src/app/hashlists/import-cracked-hashes/import-cracked-hashes.component.ts | Uses HashSource, HashListFormat, and HTTP constants in control-flow and requests. |
| src/app/hashlists/import-cracked-hashes/import-cracked-hashes.component.spec.ts | Uses centralized HTTP header name constants in assertions; updates typed sourceType usage. |
| src/app/hashlists/import-cracked-hashes/import-cracked-hashes.component.html | Uses HashSource.* / HashListFormat.* for template branching. |
| src/app/hashlists/hashes/hashes.component.ts | Replaces view-kind and select-kind primitives with typed constants. |
| src/app/hashlists/hashes/hashes.component.html | Uses HashesViewType.* instead of literal view strings. |
| src/app/hashlists/edit-hashlist/edit-hashlist.component.ts | Uses HttpStatus and StaticArrayKind constants. |
| src/app/files/new-files/new-files.form.ts | Types file source using FileSource. |
| src/app/files/new-files/new-files.component.ts | Introduces typed tab constants + uses FileSource and HttpMethod constants. |
| src/app/files/new-files/new-files.component.html | Uses typed tab constants and FileSource.* in view switching and clicks. |
| src/app/files/files.component.ts | Uses FileType.* defaults and switches instead of numeric literals. |
| src/app/core/_services/shared/theme.service.ts | Centralizes theme storage key and uses BuiltInTheme.*. |
| src/app/core/_services/shared/theme-catalog.service.ts | Uses BuiltInTheme.DARK for runtime theme metadata. |
| src/app/core/_services/shared/config.service.ts | Centralizes API endpoint storage key usage. |
| src/app/core/_services/main.service.ts | Centralizes mutation debounce constant and uses HttpMethod for helper endpoints. |
| src/app/core/_services/main.config.ts | Replaces RelationshipType enum with as const + union type. |
| src/app/core/_services/files/files_tus.service.ts | Uses shared “skip error dialog” header config. |
| src/app/core/_pipes/static-array.pipe.ts | Introduces StaticArrayKind and types the pipe input. |
| src/app/core/_pipes/healthcheck-status.pipe.ts | Uses HealthCheckStatus constants instead of numeric literals. |
| src/app/core/_models/task.model.ts | Replaces TaskType/TaskStatus enums with as const + union types. |
| src/app/core/_models/request-params.model.ts | Replaces FilterType enum with as const + union type. |
| src/app/core/_models/health-check.model.ts | Aligns checkType / status typing with shared constants. |
| src/app/core/_models/file.model.ts | Replaces FileType enum with as const + union; introduces FileSource. |
| src/app/core/_models/cracker-binary.model.ts | Adds shared default cracker type name constant. |
| src/app/core/_models/config-ui.model.ts | Centralizes defaults (page size, theme/layout re-exports). |
| src/app/core/_interceptors/http-res.interceptor.ts | Uses centralized HTTP status and header-name constants. |
| src/app/core/_interceptors/http-cache.interceptor.ts | Uses centralized HTTP method/header-name constants. |
| src/app/core/_interceptors/http-cache.interceptor.spec.ts | Uses shared skip-cache header config in tests. |
| src/app/core/_datasources/users.datasource.ts | Uses shared skip-error header config. |
| src/app/core/_datasources/tasks-chunks.datasource.ts | Uses shared skip-error header config. |
| src/app/core/_datasources/supertasks.datasource.ts | Uses shared skip-error header config. |
| src/app/core/_datasources/super-hashlists.datasource.ts | Uses shared skip-error header config. |
| src/app/core/_datasources/specs/agents.datasource.spec.ts | Uses centralized HTTP header name constants in assertions. |
| src/app/core/_datasources/preprocessors.datasource.ts | Uses shared skip-error header config. |
| src/app/core/_datasources/preconfigured-tasks.datasource.ts | Uses shared skip-error header config. |
| src/app/core/_datasources/permissions.datasource.ts | Uses shared skip-error header config. |
| src/app/core/_datasources/notifications.datasource.ts | Uses shared skip-error header config. |
| src/app/core/_datasources/logs.datasource.ts | Uses shared skip-error header config. |
| src/app/core/_datasources/health-checks.datasource.ts | Uses shared skip-error header config. |
| src/app/core/_datasources/hashtypes.datasource.ts | Uses shared skip-error header config. |
| src/app/core/_datasources/hashlists.datasource.ts | Uses shared skip-error header config. |
| src/app/core/_datasources/hashlist-supertask-builder.datasource.ts | Uses shared skip-error header config. |
| src/app/core/_datasources/hashlist-pretask-builder.datasource.ts | Uses shared skip-error header config. |
| src/app/core/_datasources/hashes.datasource.ts | Uses typed hashes view/filter constants in filtering logic. |
| src/app/core/_datasources/files.datasource.ts | Uses shared skip-error header config and typed FileType default. |
| src/app/core/_datasources/crackers.datasource.ts | Uses shared skip-error header config. |
| src/app/core/_datasources/chunks.datasource.ts | Uses shared skip-error header config. |
| src/app/core/_datasources/base.datasource.ts | Uses centralized default page size and HttpStatus in filter error mapping. |
| src/app/core/_datasources/agents.datasource.ts | Uses shared skip-error + skip-cache header configs. |
| src/app/core/_datasources/agent-binaries.datasource.ts | Uses shared skip-error header config. |
| src/app/core/_datasources/access-groups.datasource.ts | Uses shared skip-error header config. |
| src/app/core/_constants/userpermissions.config.ts | Replaces nested enums/class wrapper with as const permission groups and unions. |
| src/app/core/_constants/settings.config.ts | Introduces typed Layout, BuiltInTheme, ServerLogLevel, ProxyType. |
| src/app/core/_constants/notifications.config.ts | Replaces classes with typed ACTION/NOTIF constants and arrays. |
| src/app/core/_constants/http.config.ts | Adds centralized HTTP status/method/header-name constants and header configs. |
| src/app/core/_constants/healthchecks.config.ts | Introduces typed healthcheck attack/hash constants and uses them in options arrays. |
| src/app/core/_constants/hashlist.config.ts | Strengthens hashlist-related constants (formats, sources, brain features) and IDs. |
| src/app/core/_constants/hashes.config.ts | Introduces typed hashes view/select/filter/display constants. |
| src/app/core/_constants/files.config.ts | Uses typed FileType constants in file format options. |
| src/app/core/_constants/chunks.config.ts | Adds as const typing for chunk state constants. |
| src/app/core/_constants/agentsc.config.ts | Replaces class/enums with typed ASC, AgentOS, IgnoreErrors constants. |
| src/app/core/_components/tables/users-table/users-table.constants.ts | Adds as const to status constants. |
| src/app/core/_components/tables/hashlist-supertask-builder-table/hashlist-supertask-builder-table.component.ts | Uses shared default cracker type name constant. |
| src/app/core/_components/tables/hashlist-pretask-builder-table/hashlist-pretask-builder-table.component.ts | Uses shared skip-error header config for table-owned error handling. |
| src/app/core/_components/tables/hashes-table/hashes-table.component.ts | Types dataType input using HashesViewType. |
| src/app/core/_components/tables/files-table/files-table.component.ts | Uses typed FileType default for input. |
| src/app/core/_components/tables/agents-status-table/agents-status-table.component.ts | Replaces class constants with typed STATCALCULATION constants. |
| src/app/core/_components/menus/export-menu/export-menu.constants.ts | Replaces classes with as const label/action constants. |
| src/app/core/_components/forms/simple-forms/form.component.ts | Uses centralized HttpStatus constants. |
| src/app/core/_components/forms/custom-forms/superhashlist/new-superhashlist/new-superhashlist.component.ts | Uses HashListFormat constants in filters. |
| src/app/config/health-checks/new-health-check/new-health-checks.component.ts | Uses healthcheck constants for defaults. |
| src/app/config/engine/preprocessors/new_edit-preprocessor/new_edit-preprocessor.component.ts | Uses centralized HttpStatus constants. |
| src/app/auth/forgot-password/forgot-password.component.ts | Uses BuiltInTheme.DARK for dark-mode detection. |
| src/app/app.component.ts | Uses typed layout constants and AuthService.STORAGE_KEY for login state lookup. |
| src/app/agents/edit-agent/edit-agent.component.ts | Uses centralized HttpStatus constants. |
| src/app/account/settings/ui-settings/ui-settings.component.ts | Uses BuiltInTheme.DARK for theme metadata. |
| src/app/account/api-keys/api-key-detail/api-key-detail.component.ts | Uses centralized HttpStatus.NOT_FOUND in error handling. |
💡 Add a code-review agent skill or configure MCP servers for context-aware, tailored reviews. Learn more in the docs.
novasam23
requested review from
cv5ch,
four-random-common-words,
gluafamichl,
gpascal123 and
jessevz
and removed request for
jessevz
September 2, 2026 06:39
…for-certain-values # Conflicts: # src/app/tasks/edit-tasks/edit-tasks.component.html
Contributor
|
Resolved merge conflicts with |
four-random-common-words
previously approved these changes
Sep 2, 2026
novasam23
marked this pull request as draft
September 4, 2026 05:15
…is warnings on the way
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
DRAFT