Merge pull request #25 from bknd-io/feat/node-media-local

Feat: Node media local
This commit is contained in:
dswbx
2024-12-23 11:44:40 +01:00
committed by GitHub
13 changed files with 206 additions and 124 deletions

View File

@@ -69,7 +69,8 @@ export class SchemaObject<Schema extends TObject> {
forceParse: true,
skipMark: this.isForceParse()
});
const updatedConfig = noEmit ? valid : await this.onBeforeUpdate(this._config, valid);
// regardless of "noEmit" this should always be triggered
const updatedConfig = await this.onBeforeUpdate(this._config, valid);
this._value = updatedConfig;
this._config = Object.freeze(updatedConfig);

View File

@@ -1,29 +1,50 @@
export type Constructor<T> = new (...args: any[]) => T;
export class Registry<Item, Items extends Record<string, object> = Record<string, object>> {
export type RegisterFn<Item> = (unknown: any) => Item;
export class Registry<
Item,
Items extends Record<string, Item> = Record<string, Item>,
Fn extends RegisterFn<Item> = RegisterFn<Item>
> {
private is_set: boolean = false;
private items: Items = {} as Items;
set<Actual extends Record<string, object>>(items: Actual) {
constructor(private registerFn?: Fn) {}
set<Actual extends Record<string, Item>>(items: Actual) {
if (this.is_set) {
throw new Error("Registry is already set");
}
// @ts-ignore
this.items = items;
this.items = items as unknown as Items;
this.is_set = true;
return this as unknown as Registry<Item, Actual>;
return this as unknown as Registry<Item, Actual, Fn>;
}
add(name: string, item: Item) {
// @ts-ignore
this.items[name] = item;
this.items[name as keyof Items] = item as Items[keyof Items];
return this;
}
register(name: string, specific: Parameters<Fn>[0]) {
if (this.registerFn) {
const item = this.registerFn(specific);
this.items[name as keyof Items] = item as Items[keyof Items];
return this;
}
return this.add(name, specific);
}
get<Name extends keyof Items>(name: Name): Items[Name] {
return this.items[name];
}
has(name: keyof Items): boolean {
return name in this.items;
}
all() {
return this.items;
}