在我的项目中,我只使用了aldeed:simple-schema和包check和audit-argument-checks。--使用我的SimpleSchema的检查函数--运行良好的。
但后来我想使用collection2。Collection2需要npm包simpl-schema。当我安装aldeed:collection2和npm包simpl-schema时,我使用SimpleSchema的检查停止工作,现在显示以下错误:
错误:匹配错误:字段标题中的未知键
Check()使用的是aldeed:simple-schema,而不是npm包simpl-schema。
import SimpleSchema from 'simpl-schema';
NoteUpsertSchema = new SimpleSchema({
title: {
type: String,
max: 50
},
description: {
type: String,
max: 500
}
});我的流星法
updateNote(noteId, note){
check(noteId, String);
check(note, NoteUpsertSchema);
// some code
}我的软件包的版本:
// Meteor packages
aldeed:collection2 3.0.0
audit-argument-checks 1.0.7
check 1.3.0*
// Npm package
"simpl-schema": "^1.5.0"
(I tried with simpl-schema: 1.4.3 same result.)如何将四个包( check、audit-argument-checks、simple-schema和collection2 )一起使用?
谢谢你的回答
发布于 2018-05-18 08:37:26
您不能在Meteor中的NoteUpsertSchema实用程序中使用check。
check、audit-argument-checks、simpl-schema和collection2的同步工作非常好,在兼容性方面没有这样的问题。Check只允许使用已定义的参数对有效性进行交叉检查。了解单击此处允许的check类型的详细信息。
考虑到audit-argument-checks,您需要使用下面所示的方法来检查Meteor方法中传递的参数。为了避免在使用SimpleSchema验证Meteor方法参数时不检查所有参数的错误,在创建SimpleSchema实例时必须通过check作为选项。
import SimpleSchema from 'simpl-schema';
import { check } from 'meteor/check';
import { Meteor } from 'meteor/meteor';
SimpleSchema.defineValidationErrorTransform(error => {
const ddpError = new Meteor.Error(error.message);
ddpError.error = 'validation-error';
ddpError.details = error.details;
return ddpError;
});
const myMethodObjArgSchema = new SimpleSchema({ name: String }, { check });
Meteor.methods({
myMethod(obj) {
myMethodObjArgSchema.validate(obj);
// Now do other method stuff knowing that obj satisfies the schema
},
});确保aldeed:simple-schema没有在.meteor/versions文件中列出。
问题还可能是从客户端发送一个完整的对象,并且只验证它在meteor方法中的一些字段。确保发送给方法的参数只具有正在验证的内容,并且没有来自客户端代码的额外字段。
https://stackoverflow.com/questions/50405231
复制相似问题