当前位置: 首页>>代码示例>>TypeScript>>正文


TypeScript Schema.eachPath方法代码示例

本文整理汇总了TypeScript中mongoose.Schema.eachPath方法的典型用法代码示例。如果您正苦于以下问题:TypeScript Schema.eachPath方法的具体用法?TypeScript Schema.eachPath怎么用?TypeScript Schema.eachPath使用的例子?那么, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在mongoose.Schema的用法示例。


在下文中一共展示了Schema.eachPath方法的3个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的TypeScript代码示例。

示例1: traversePaths

export function traversePaths(schema: Schema, prefix: string = '', paths: any = {}): { [key: string]: any } {
	schema.eachPath((path, type) => {
		const schemaType = type as any;
		const isPathArray = schemaType.options && isArray(schemaType.options.type);
		const fullPath = prefix + (prefix ? '.' : '') + path + (isPathArray ? '.0' : '');
		paths[fullPath] = schemaType;
		if (schemaType.schema) {
			exports.traversePaths(schemaType.schema, fullPath, paths);
		}
	});
	return paths;
}
开发者ID:freezy,项目名称:node-vpdb,代码行数:12,代码来源:util.ts

示例2: idReferenceValidatorPlugin

export function idReferenceValidatorPlugin(schema: Schema, options: IdReferenceValidatorOpts = {}) {

	options = options || {};
	const fields = options.fields || [];
	const message = options.message || '{PATH} references a non existing ID';

	schema.eachPath((path, schemaType: any) => {
		let validateFunction: (doc: Document, path: string, refModelName: string, values: any[], conditions: {[key: string]: any}) => Promise<boolean> = null;
		let refModelName: string = null;
		let conditions = {};

		if (fields.length > 0 && !fields.includes(path)) {
			return;
		}

		if (schemaType.options && schemaType.options.ref) {
			validateFunction = validateId;
			refModelName = schemaType.options.ref;
			if (schemaType.options.refConditions) {
				conditions = schemaType.options.refConditions;
			}
		} else if (schemaType.caster && schemaType.caster.instance && schemaType.caster.options && schemaType.caster.options.ref) {
			validateFunction = validateIdArray;
			refModelName = schemaType.caster.options.ref;
			if (schemaType.caster.options.refConditions) {
				conditions = schemaType.caster.options.refConditions;
			}
		}

		if (validateFunction) {
			schema.path(path).validate(async function(value: any) {
				return validateFunction(this, path, refModelName, value, conditions);
			}, message);
		}
	});
}
开发者ID:freezy,项目名称:node-vpdb,代码行数:36,代码来源:id.reference.validator.plugin.ts

示例3:

  ofBuffer:   [Buffer],
  ofBoolean:  [Boolean],
  ofMixed:    [mongoose.Schema.Types.Mixed],
  ofObjectId: [mongoose.Schema.Types.ObjectId],
  nested: {
    stuff: { type: String, lowercase: true, trim: true }
  }
});
schema.add({
  mixedArray: {
    type: [mongoose.Schema.Types.Mixed],
    required: true
  }
}, 'prefix');
schema.eachPath(function (path, type) {
  path.toLowerCase();
  type.sparse(true);
}).eachPath(cb);
schema.get('path');
schema.index({
  name: 1,
  binary: -1
}).index({}, {});
schema.indexes().slice();
schema.method('name', cb).method({
  m1: cb,
  m2: cb
});
schema.path('a', mongoose.Schema.Types.Buffer).path('a');
schema.pathType('m1').toLowerCase();
schema.plugin(function (schema, opts) {
  schema.get('path');
开发者ID:RaySingerNZ,项目名称:DefinitelyTyped,代码行数:32,代码来源:mongoose-tests.ts


注:本文中的mongoose.Schema.eachPath方法示例由纯净天空整理自Github/MSDocs等开源代码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。