SDK
SDK Javascript v7.x
2

validateSpecifications #

Checks if a validation specification is well formatted. It does not store nor 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]);

ArgumentsTypeDescription
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

PropertyType
(default)
Description
queuable
boolean

(true)
If true, queues the request during downtime, until connected to Kuzzle again
timeout
number

(-1)
Time (in ms) during which a request will still be waited to be resolved. Set it -1 if you want to wait indefinitely
triggerEvents
boolean

(false)
If set to true, will trigger events even if using Embeded SDK. You should always ensure that your events/pipes does not create an infinite loop.
Available since Kuzzle 2.31.0

Resolves #

Resolves to an object which contain information about the specifications validity.

It contains the following properties:

PropertyTypeDescription
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);
}