validateSpecifications #
The validateSpecifications method checks if a validation specification is well formatted. It does not store or modify the existing specification.
When the validation specification is not formatted correctly, a detailed error message is returned to help you to debug.
validateSpecifications(index, collection, specifications, [options]);
Arguments | Type | Description |
---|---|---|
index | string | Index name |
collection | string | Collection name |
specifications | object | Specifications to validate |
options | object | Query options |
specifications #
An object representing the specifications.
This object must follow the Specification Structure:
{
strict: <boolean>,
fields: {
// ... specification for each field
}
}
options #
Additional query options
Property | Type (default) | Description |
---|---|---|
queuable | boolean ( true ) | If true, queues the request during downtime, until connected to Kuzzle again |
Resolves #
Resolves to an object which contain information about the specifications validity.
It contains the following properties:
Property | Type | Description |
---|---|---|
valid | boolean | Specifications validity |
details | string[] | Specifications errors |
description | string | Global description of errors |
Usage #
try {
const specifications = {
strict: false,
fields: {
license: {
mandatory: true,
type: 'symbol' // symbol is not a recognized type
}
}
};
const result = await kuzzle.collection.validateSpecifications('nyc-open-data', 'yellow-taxi', specifications);
console.log(result);
/*
{
valid: false,
details: [
'In nyc-open-data.yellow-taxi.license: symbol is not a recognized type.'
],
description: 'Some errors with provided specifications.'
}
*/
if (result.valid === false) {
console.log(result.description);
}
} catch (error) {
console.error(error.message);
}
Edit this page on Github(opens new window)