Skip to content

Commit

Permalink
feat: Add category attribute to exposes (#6837)
Browse files Browse the repository at this point in the history
* add 'category' property to class Base

* Restrict categories to 'config' and 'diagnostic' and validate expose access

* Use single category 'system' instead of 'config' and 'diagnostic'

* Revert "Use single category 'system' instead of 'config' and 'diagnostic'"

This reverts commit f093e37.
  • Loading branch information
slugzero committed Jan 7, 2024
1 parent 4b972d6 commit 3a1b7a9
Showing 1 changed file with 20 additions and 0 deletions.
20 changes: 20 additions & 0 deletions src/lib/exposes.ts
Original file line number Diff line number Diff line change
Expand Up @@ -16,6 +16,7 @@ export class Base {
property?: string;
description?: string;
features?: Feature[];
category?: 'config' | 'diagnostic';

withEndpoint(endpointName: string) {
this.endpoint = endpointName;
Expand All @@ -39,6 +40,7 @@ export class Base {
withAccess(a: number) {
assert(this.access !== undefined, 'Cannot add access if not defined yet');
this.access = a;
this.validateCategory();
return this;
}

Expand All @@ -57,6 +59,23 @@ export class Base {
return this;
}

withCategory(category: 'config' | 'diagnostic') {
this.category = category;
this.validateCategory();
return this;
}

validateCategory() {
switch (this.category) {
case 'config':
assert(this.access & a.SET, 'Config expose must be settable');
break;
case 'diagnostic':
assert(!(this.access & a.SET), 'Diagnostic expose must not be settable');
break;
}
}

removeFeature(feature: string) {
assert(this.features, 'Does not have any features');
const f = this.features.find((f) => f.name === feature);
Expand All @@ -70,6 +89,7 @@ export class Base {
const f = this.features.find((f) => f.name === feature);
assert(f.access !== a, `Access mode not changed for '${f.name}'`);
f.access = a;
f.validateCategory();
return this;
}
}
Expand Down

0 comments on commit 3a1b7a9

Please sign in to comment.