feat: Define base entity model (closes #3)

This commit is contained in:
2026-07-04 19:12:33 +05:30
parent e712c0dd93
commit fe120442bd
2 changed files with 22 additions and 2 deletions

View File

@@ -44,7 +44,7 @@ export class Attribute {
this.visibility = AttributeVisibility.PRIVATE;
}
grandAccess(objectId: string) {
grantAccess(objectId: string) {
if (this.visibility === AttributeVisibility.PRIVATE) {
this.allowedEntities.add(objectId);
}
@@ -79,11 +79,18 @@ export abstract class AttributableObject implements IAttribute {
addAttribute(
name: string,
value: string,
visibility: AttributeVisibility,
visibility: AttributeVisibility = AttributeVisibility.PRIVATE,
allowedEntities: Set<string> | null = null,
): void {
if (this.attributes.has(name))
throw Error(`Attribute ${name} already exists`);
this.attributes.set(name, new Attribute(name, value, visibility));
if (visibility === AttributeVisibility.PRIVATE && allowedEntities != null) {
for (const entity of allowedEntities) {
this.attributes.get(name)?.grantAccess(entity);
}
}
}
removeAttribute(name: string): void {
@@ -98,3 +105,9 @@ export abstract class AttributableObject implements IAttribute {
);
}
}
export class Entity extends AttributableObject {
constructor(name: string) {
super();
}
}