简体   繁体   English

在Foxx应用中使用joi验证数组项

[英]Validating array items with joi in a Foxx app

I am having problems with using joi array-item validation in foxx applications as well as the arango-shell with arangodb-2.5.5. 我在foxx应用程序以及带有arangodb-2.5.5的arango-shell中使用joi数组项验证时遇到问题。 The joi-documentation suggests to use something like: joi文档建议使用类似以下的内容:

var Joi = require('joi');
Joi.array().items({'name': Joi.string().required()});

for validating a dataset similar to: 用于验证类似于以下内容的数据集:

[{'name': 'Peter'}, {'name': 'Edeltraut'}, ...]

However, using it in a Foxx application results in the application to stop working. 但是,在Foxx应用程序中使用它会导致该应用程序停止工作。 Pasting the snippet from above into the arango-shell produces the following output: 从上方将代码段粘贴到arango-shell中,将产生以下输出:

JavaScript exception: TypeError: undefined is not a function
!Joi.array().items({'name': Joi.string().required()});
!            ^
stacktrace: TypeError: undefined is not a function
    at <shell command>:1:13

Is there something I am missing, or is arangodb using a modified / smaller version of joi that has this feature stripped out? 我是否缺少某些东西,或者arangodb使用的joi的修改后版本/较小版本已删除了此功能?

ArangoDB 2.5 uses an older version of joi. ArangoDB 2.5使用较旧的joi版本。 The method in question was renamed to items in joi 6.0 and was previously called includes . 有问题的方法在joi 6.0中重命名为items ,以前称为includes

You can find the documentation for joi 4.9.0 (the version shipped with ArangoDB 2.5) at https://github.com/hapijs/joi/tree/v4.9.0 您可以在https://github.com/hapijs/joi/tree/v4.9.0中找到joi 4.9.0(ArangoDB 2.5附带的版本)的文档。

ArangoDB 2.6 will ship with joi 6.4.3, which is the latest version at this time. ArangoDB 2.6将随joi 6.4.3一起提供,这是当前的最新版本。

If you want to know the version of an NPM dependency shipped with ArangoDB, you can also find out the version number by importing its package.json file like this: 如果您想知道ArangoDB随附的NPM依赖项的版本,还可以通过导入其package.json文件来查找版本号,如下所示:

require('joi/package.json').version

You don't have to wait for ArangoDB 2.6 to use the latest version of joi. 您不必等待ArangoDB 2.6使用最新版本的joi。 If you npm install joi --save inside of your Foxx app's APP folder, it'll be used instead of the one bundled with ArangoDB. 如果您在Foxx应用程序的APP文件夹中npm install joi --save ,它将被使用,而不是与ArangoDB捆绑在一起的文件夹。 I've been doing that for a while now. 我已经做了一段时间了。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM