Help with mdg:validated-method - expected function in field validate

Hey there, fellow meteorians,

I’m trying to keep up with the guide on methods and want to implement mdg’s validated-method package.
However, I’m running into the following server error:

Error: Match error: Expected Function in field validate

I’m running on release 1.3.rc-3.
My method file looks like this (it’s literally copied from the guide):

import { Meteor } from 'meteor/meteor';
import { ValidatedMethod } from 'meteor/mdg:validated-method';
import { SimpleSchema } from 'meteor/aldeed:simple-schema';
import { Documents } from '../../../collections/documents.js';

export const insert = new ValidatedMethod({
	name: 'documents.insert',
	validate: new SimpleSchema({
		title: { type: String }
	}).validator(),
	run() {
		return Documents.insert({})
	},
});

Filestructure is
-imports
–server
----methods
-------documents
-----------methods.js

ValidateMethod will work if I replace the simple-schema validation with check validation.
... validate(args){ check( args,{title, String})}, ...

Maybe anybody could have an idea what I’m doing wrong?
Thank you very much in advance!

1 Like

You need to pass the data you want to add into the run function. Take a look at the Calling a Method from a form ValidatedMethod example. Note how it’s defined as run(newInvoice), with Invoices.insert(newInvoice) in the function body.

I’m also having this issue

Hi there! That doesn’t solve the problem as the error seems to be that
new SimpleSchema({ title: { type: String } }).validator()

isn’t recognized as a function. My problem is not the ‘run’ part but the validation. As I mentioned, everything works fine with audit-arguments-check, so it must be somehow not recognizing 'validator() as a function call.

1 Like

Which version of Simple Schema are you using? (what does it show in your .meteor/versions file?) Maybe try removing Simple Schema, followed by a meteor add aldeed:simple-schema@1.5.3 to see if that helps.

2 Likes

Hey, that did the trick!
I was running on simple-schema@1.3.3.
I thought this would have been no issue due to dependency management.

Thank you very much @hwillson!

It works, thank you. But why simple-schema is added as 1.3.3 by default?

Meteor’s constraint-solver tries its best to line all dependencies up in a way that makes the most sense, but it’s extremely difficult to get everything aligned properly (especially in applications with large package/dependency graphs). It decided version 1.3.3 made the most sense to include (based on the requirements of other packages in your app).