feat: more resources support importing

This commit is contained in:
Ahmed Bouhuolia
2024-04-05 02:00:12 +02:00
parent 3851d34ba4
commit dd9098bdc1
46 changed files with 1510 additions and 149 deletions

View File

@@ -1,33 +1,54 @@
import { get } from 'lodash';
import { IModelMeta, IModelMetaField, IModelMetaDefaultSort } from '@/interfaces';
import {
IModelMeta,
IModelMetaField,
IModelMetaDefaultSort,
} from '@/interfaces';
const defaultModelMeta = {
fields: {},
fields2: {},
};
export default (Model) =>
class ModelSettings extends Model {
/**
*
* @returns {IModelMeta}
*/
static get meta(): IModelMeta {
throw new Error('');
}
/**
* Parsed meta merged with default emta.
* @returns {IModelMeta}
*/
static get parsedMeta(): IModelMeta {
return {
...defaultModelMeta,
...this.meta,
};
}
/**
* Retrieve specific model field meta of the given field key.
* @param {string} key
* @returns {IModelMetaField}
*/
public static getField(key: string, attribute?:string): IModelMetaField {
public static getField(key: string, attribute?: string): IModelMetaField {
const field = get(this.meta.fields, key);
return attribute ? get(field, attribute) : field;
}
/**
* Retrieve the specific model meta.
* Retrieves the specific model meta.
* @param {string} key
* @returns
*/
public static getMeta(key?: string) {
return key ? get(this.meta, key): this.meta;
return key ? get(this.parsedMeta, key) : this.parsedMeta;
}
/**