本文整理匯總了TypeScript中@tsed/common.PropertyRegistry.getProperties方法的典型用法代碼示例。如果您正苦於以下問題:TypeScript PropertyRegistry.getProperties方法的具體用法?TypeScript PropertyRegistry.getProperties怎麽用?TypeScript PropertyRegistry.getProperties使用的例子?那麽, 這裏精選的方法代碼示例或許可以為您提供幫助。您也可以進一步了解該方法所在類@tsed/common.PropertyRegistry
的用法示例。
在下文中一共展示了PropertyRegistry.getProperties方法的1個代碼示例,這些例子默認根據受歡迎程度排序。您可以為喜歡或者感覺有用的代碼點讚,您的評價將有助於係統推薦出更棒的TypeScript代碼示例。
示例1: buildMongooseSchema
export function buildMongooseSchema(target: any): MongooseSchema {
const properties = PropertyRegistry.getProperties(target);
const schema: MongooseSchema = {schema: {}, virtuals: new Map()};
if (properties) {
const jsonSchema: any = JsonSchemesRegistry.getSchemaDefinition(target) || {properties: {}};
for (const [key, metadata] of properties.entries()) {
if (MONGOOSE_RESERVED_KEYS.includes(key as string)) {
continue;
}
// Keeping the Mongoose Schema separate so it can overwrite everything once schema has been built.
const mongooseSchema = metadata.store.get(MONGOOSE_SCHEMA) || {};
if (mongooseSchema.ref && mongooseSchema.localField && mongooseSchema.foreignField) {
mongooseSchema.justOnce = !metadata.isArray;
schema.virtuals.set(key as string, mongooseSchema);
continue;
}
let definition: any = {
required: metadata.required
? function() {
return metadata.isRequired(this[key]);
}
: false
};
if (!metadata.isClass) {
definition = Object.assign(definition, {type: metadata.type}, mapProps(jsonSchema.properties[key]));
} else if (!mongooseSchema.ref) {
// References are handled by the final merge
definition = Object.assign(definition, {type: Store.from(metadata.type).get(MONGOOSE_SCHEMA)});
}
definition = clean(Object.assign(definition, mongooseSchema));
if (metadata.isCollection) {
if (metadata.isArray) {
definition = [definition];
} else {
// Can be a Map or a Set;
// Mongoose implements only Map;
if (metadata.collectionType !== Map) {
throw new Error(`Invalid collection type. ${metadata.collectionName} is not supported.`);
}
definition = {type: Map, of: definition};
}
}
schema.schema[key as string] = definition;
}
}
return schema;
}