mirror of
https://github.com/shishantbiswas/bknd.git
synced 2026-03-16 12:37:20 +00:00
public commit
This commit is contained in:
32
app/src/data/fields/VirtualField.ts
Normal file
32
app/src/data/fields/VirtualField.ts
Normal file
@@ -0,0 +1,32 @@
|
||||
import { type Static, Type } from "core/utils";
|
||||
import { Field, baseFieldConfigSchema } from "./Field";
|
||||
|
||||
export const virtualFieldConfigSchema = Type.Composite([baseFieldConfigSchema, Type.Object({})]);
|
||||
|
||||
export type VirtualFieldConfig = Static<typeof virtualFieldConfigSchema>;
|
||||
|
||||
export class VirtualField extends Field<VirtualFieldConfig> {
|
||||
override readonly type = "virtual";
|
||||
|
||||
constructor(name: string, config?: Partial<VirtualFieldConfig>) {
|
||||
// field must be virtual, as it doesn't store a reference to the entity
|
||||
super(name, { ...config, fillable: false, virtual: true });
|
||||
}
|
||||
|
||||
protected getSchema() {
|
||||
return virtualFieldConfigSchema;
|
||||
}
|
||||
|
||||
schema() {
|
||||
return undefined;
|
||||
}
|
||||
|
||||
override toJsonSchema() {
|
||||
return this.toSchemaWrapIfRequired(
|
||||
Type.Any({
|
||||
default: this.getDefault(),
|
||||
readOnly: true
|
||||
})
|
||||
);
|
||||
}
|
||||
}
|
||||
Reference in New Issue
Block a user