Validating array items with joi in a Foxx app - arangodb

I am having problems with using joi array-item validation in foxx applications as well as the arango-shell with arangodb-2.5.5.
The joi-documentation suggests to use something like:
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. Pasting the snippet from above into the arango-shell produces the following output:
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 2.5 uses an older version of joi. The method in question was renamed to items in joi 6.0 and was previously called 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
ArangoDB 2.6 will ship with joi 6.4.3, which is the latest version at this time.
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:
require('joi/package.json').version

You don't have to wait for ArangoDB 2.6 to use the latest version of 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. I've been doing that for a while now.

Related

Property 'endBefore' does not exist on type 'Query'

My compiler is giving me the following error on this piece of code
const snap = await admin
.database()
.ref(`schedule/${studentId}`)
.orderByChild('start')
.startAt(startDate)
.endBefore(endDate)
.once('value')
The error is
Property 'endBefore' does not exist on type 'Query'.
However, when looking at the firebase documentation (https://firebase.google.com/docs/reference/js/v8/firebase.database.Query) endBefore is a method on Query! What is going on with this?
The endBefore operation was added in February 2021 to version 8.2.7 of the Firebase SDK for JavaScript/web. It was subsequently also added in May 2021 to version 9.8.0 of the Firebase Admin SDK for Node.js.
That is newer than the version you are using, so if you want to use endBefore you should upgrade to version 9.8 or later.

Nodejs version on Google App Engine standard

Googles docs indicate they support the latest LTS of Nodejs, and that they support the latest version of the specified version.
https://cloud.google.com/appengine/docs/standard/nodejs/runtime
it uses the latest stable release of the version you choose.
Currently, NodeJS is on 14 for LTS, and 12.18.4 for version 12. However, App Engine Standard appears to be stuck on 12.16.3 as it's latest version.
Is there any indication of their release cadence? When can we expect an upgrade?
Motivation: I'm trying to setup a typescript monorepo with published packages & App engine. This relies package.json specifying "exports" field, but 12.16 seems not to support it, even behind the --experimental-exports tag.
I have deployed a quickstart with node12 in AppEngine Standard and had the sames results than yours, the current latest TLS for Node seems to be: v12.16.3.
I printed the version with this code:
app.get('/', (req, res) => {
res.status(200).send('Hello, world!>>'+process.version).end();
});
The result was:
This is happening also in the Flexible environment, I faced a similar issue in which is supposed to pick the latest major version, instead always pick a lower, but it is consistent on picking always the same. This seems to be a expected behavior, but it is well worth to know the reason.
I tried setting the specific version 12.18.4 but with no success.
**ERROR**: (gcloud.app.deploy) INVALID_ARGUMENT: The 'package.json' configuration file must specify a supported nodejs12 version that is compatible with the runtime specified in the deployment. Please pin your application to a compatible major version of the runtime via the 'engines.node' property. Supported 'engines.node' values for the runtime 'nodejs12' are: [12.x.x, 12.X.X, 12.x, 12.X, 12.*.*, 12.*, ~12, ~12.0, ~12.0.0, 12, ^12, ^12.0, ^12.0.0, >=12, >=12.0, >=12.0.0, >12.0, >12.0.0, >=1, >=1.0, >=1.0.0, >1, >1.0, >1.0.0, >=2, >=2.0, >=2.0.0, >2, >2.0, >2.0.0, >=3, >=3.0, >=3.0.0, >3, >3.0, >3.0.0, >=4, >=4.0, >=4.0.0, >4, >4.0, >4.0.0, >=5, >=5.0, >=5.0.0, >5, >5.0, >5.0.0, >=6, >=6.0, >=6.0.0, >6, >6.0, >6.0.0, >=7, >=7.0, >=7.0.0, >7, >7.0, >7.0.0, >=8, >=8.0, >=8.0.0, >8, >8.0, >8.0.0, >=9, >=9.0, >=9.0.0, >9, >9.0, >9.0.0, >=10, >=10.0, >=10.0.0, >10, >10.0, >10.0.0, >=11, >=11.0, >=11.0.0, >11, >11.0, >11.0.0].
I think you can file an issue in the Public Issue Tracker, I found this similar in Flexible. This issue could be related to some internal stuff architecture of App Engine. When filing the issue, provide as much information as possible, always sanitizing to avoid sharing sensitive information, such as project ID, passwords, etc.

Mongoose 4 to 5: connection.db.collection() undefined

I'm attempting to upgrade from Mongoose 4.x to 5.x. So far the biggest issue I'm running in to is after the database has connected I'm unable to fetch collections like I was able to in 4.x.
const someCollection = mongoose.connection.db.collection('someCollection');
This code works fine in 4.x, but apparently the underlying structure of Mongoose has changed between versions.
Is there an equivalent way to do this in Mongoose 5.x? I looked in the documentation and the migration guide but didn't see anything.
For Mongoose 5.x, the .db part isn't needed so it should be:
mongoose.connection.collection('someCollection');

Bluemix node.js doesn't like "=>"

I'm new to Bluemix and node.js. I'm creating a Bluemix app that integrates with Box, but the built in Box service uses out-of-date node.js support, and I'd like to use the most recent node.js Box SDK.
I'm including this line at the top of my code
var BoxSDK = require('box-node-sdk');
But in processing this SDK, the log file throws an error on this line (line 191 of box-node-sdk/lib/api-request.js):
this.stream.on('error', err => this.eventBus.emit('response', err));
The error is:
SyntaxError: Unexpected token =>
What do I need to do to get Bluemix's node.js to recognize this (apparently new) syntax?
After some further digging, I discovered this page in the Bluemix runtime documentation, which says:
A node version should always be specified in the package.json file. If it is not, the latest node version will be used.
I removed the engines{} section from my package.json file to force it to use the latest node version, and I've gotten past this problem. (On to my next error...)
Thanks very much to jfriend00, who gave the crucial information that led me where I needed to go!

Get Object has no method 'executeDbCommand'

I am using mongodb 3.0.2 with mongoose 4.0 in nodejs
While i upgrade mongoose 2.3 to 4.0 it started to throw error for
'executeDbCommand', it looks like this is deprecated in mongoose 4.0,
anyone has an idea for replacement of this command ?
I tried to dig into the mongoose but cant find it, Please help me if anyone knows !!
Mongoose uses a native driver in itself prototype, and api docs says that native drive has a command method. The code will be:
var db = mongoose.createConnection('mongodb://user:pass#localhost:port/database');
db.command('sample command');

Resources