2240 enhancement use const enums or enums for certain values - #810
Draft
correct-horse-battery-bench wants to merge 3 commits into
Draft
2240 enhancement use const enums or enums for certain values#810correct-horse-battery-bench wants to merge 3 commits into
correct-horse-battery-bench wants to merge 3 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().
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