@tsed/schema
Version:
JsonSchema module for Ts.ED Framework
40 lines (39 loc) • 1.25 kB
JavaScript
import { alterIgnore } from "../hooks/alterIgnore.js";
import { getInheritedStores } from "./getInheritedStores.js";
import { getJsonEntityStore } from "./getJsonEntityStore.js";
/**
* Return the list of properties including properties from inherited classes
* @param target
* @ignore
*/
export function getPropertiesStores(target) {
const store = target.isStore ? target : getJsonEntityStore(target);
if (!store.$properties) {
const stores = getInheritedStores(store);
store.$properties = new Map();
stores.forEach((currentStore) => {
currentStore.children.forEach((propStore) => {
if (!store.$properties.has(propStore.propertyKey)) {
store.$properties.set(propStore.propertyKey, propStore);
}
});
});
}
return store.$properties;
}
/**
* @ignore
*/
export function getProperties(target, options = {}) {
const stores = getPropertiesStores(target);
const map = new Map();
stores.forEach((store, key) => {
if (!options.withIgnoredProps) {
if (alterIgnore(store.itemSchema, options)) {
return;
}
}
map.set(key, store);
});
return map;
}