Skip to content

Conversation

@bcpmihail
Copy link
Contributor

Description

Checklist

  • I have added relevant error handling and logging messages to help troubleshooting
  • I have added tests that prove my fix is effective or that my feature works
  • I have added necessary documentation, relevant usage information (if applicable)
  • I have updated the PR title with affected component, related issue number and a short summary of the changes introduced
  • I have added labels for implementation kind (kind/) and version type (version/)
  • I have tested against live environment, if applicable
  • I have synced any structure and/or content vRA-NG improvements with vra-ng and ts-vra-ng archetypes (if applicable)
  • I have my changes rebased and squashed to the minimal number of relevant commits. Notice: don't squash all commits
  • I have added a descriptive commit message with a short title, including a Fixed #XXX - or Closed #XXX - prefix to auto-close the issue

Testing

Release Notes

Related issues and PRs

@github-actions github-actions bot added kind/feature New Feature to the project kind/refactor Refactoring of existing features labels Sep 17, 2025
@bcpmihail
Copy link
Contributor Author

bcpmihail commented Sep 17, 2025

Pseudo-enum regexes (copy vro-types/o11n-plugin-vc/index.d.ts in Notepad++ and use Find/Replace with Regular Expression, Wrap around, no ". matches newline")
Total matches for "fromString": 413
Regex to identify pseudo-enum:
declare class (.+)\s*\{[^\{]+fromString[^\}]+\}
Total matches: 413
Regex to replace fromString:
;(\r\n\t/\*\*\r\n\t \* @param value \r\n\t \*/\r\n\t)(static )?fromString[^\}]+
with
;\r\n\t//placeholder fromString\r\n
>> when restored will include declarations for name/id/value/private c-tor
Regex to remove private c-tor, id, value, name (only 366 matches?!):
({[^\{\}]+)\r\n\tprivate constructor\(\);([^\{\}]+//placeholder fromString\r\n\})
({[^\{\}]+)\r\n\t(?:private )?(?:readonly )?(?:static )?(?:readonly )?(?:private )?id: string;([^\{\}]+//placeholder fromString\r\n\})
({[^\{\}]+)\r\n\t(?:private )?(?:readonly )?(?:static )?(?:readonly )?(?:private )?value: string;([^\{\}]+//placeholder fromString\r\n\})
({[^\{\}]+)\r\n\t(?:private )?(?:readonly )?(?:static )?(?:readonly )?(?:private )?name: string;([^\{\}]+//placeholder fromString\r\n\})
replace with:
$1$2
Verifying structure (413 matches):
declare class (.+) {(\r\n\t.+: .+;)*\r\n\t//placeholder fromString\r\n\}
Prepare class row - replace:
(declare class (?:.+) ){((\r\n\t.+: .+;)*\r\n\t//placeholder fromString\r\n\})
with 
$1implements IPseudoEnum {//fix next$2
Replace each enum value row:
(?<=//fix next)\r\n\t.+ (.+):\s?(.+);
with:
\r\n\tstatic readonly$1: $2 & EnumVal<'$1'>;//fix next
Replace fromString placeholder and restore instance fields & c-tor, add toString():
(declare class (.+) implements IPseudoEnum \{[^\}]+)//placeholder fromString
with
$1static fromString\(value: string\): $2 & EnumVal<TcleanKeys<typeof $2>>;\r\n\r\n\treadonly id: string;\r\n\treadonly name: string;\r\n\treadonly value: string;\r\n\tprivate constructor\(\);\r\n\ttoString: \(\) => string;
Remove (replace w/ empty string): //fix next
Add helper types to the start of the file:
interface IPseudoEnum {
	id: string,
	name: string,
	value: string,
	toString: () => string
}
type EnumVal<K extends string> = IPseudoEnum | K; // for comparing
type TcleanKeys<T> = Exclude<keyof T, "prototype" | "fromString">;

Optional: add jsDoc to fromString() - replace:
(static fromString)
with:
/\*\* @param \{string\} value \*/\r\n\t$1

@bcpmihail
Copy link
Contributor Author

bcpmihail commented Sep 17, 2025

Untested (build currently blocked). Example tests:

const s: string = "bla";
// WITH DECL:
// no compiler error:
let c: SomeEnum = SomeEnum.fromString('someval');
let bool = s == SomeEnum.fromString("secondVal");
let d: SomeEnum = SomeEnum.fromString('bla'); // param not limited to key
// expected compiler error:
let e: SomeEnum = 'someval'; // string not assignable to someEnum
console.log("bla" == SomeEnum.fromString("secondVal")); // types "bla" and SomeEnum & ... have no overlap
// works, but shouldn't:
let f= {"id":"bla", "name": "bla", toString:()=>"bla"};

// WITH IMPL (delete "declare", uncomment impl.)
// no compiler error:
console.log(c == SomeEnum.someval); // true
console.log("secondVal" == SomeEnum.fromString("secondVal")); // true
console.log(SomeEnum.someval == SomeEnum.fromString("someval")); // true
console.log(SomeEnum.secondVal == SomeEnum.fromString("someval")); // false

@bcpmihail bcpmihail force-pushed the feature/vro-types-vc-pseudoenums branch from a9b2866 to e85468d Compare September 18, 2025 09:11
@bcpmihail
Copy link
Contributor Author

Fixed the remaining 47 'name' fields that weren't caught by the regular expression.

@bcpmihail bcpmihail force-pushed the feature/vro-types-vc-pseudoenums branch from e0b9d88 to 259c74b Compare September 18, 2025 15:11
@github-actions
Copy link

This PR is stale because it has been open 30 days with no activity. Remove stale label or comment or this will be closed in 7 days.

@github-actions github-actions bot added the Stale label Oct 19, 2025
@VenelinBakalov VenelinBakalov added triage/blocked This issue is blocked by another, specified in the description and removed Stale labels Oct 20, 2025
@VenelinBakalov
Copy link
Collaborator

Refactor relates to: #604

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

kind/feature New Feature to the project kind/refactor Refactoring of existing features triage/blocked This issue is blocked by another, specified in the description

Projects

None yet

Development

Successfully merging this pull request may close these issues.

3 participants