dashevo / js-dpp

DEPRECATED The JavaScript implementation of the Dash Platform Protocol
MIT License
8 stars 8 forks source link

support building indices on arrays #275

Closed dashameter closed 3 years ago

dashameter commented 4 years ago

Expected Behavior

Support building an index over a "type": "array" field in data contracts so it can be queried by $in, $elementMatch, $all.

Current Behavior

{
    "tweet": {
        "indices": [
            {
                "properties": [
                    {
                        "mentions": "asc"
                    }
                ]
            }
        ],
        "properties": {
            "mentions": {
                "type": "array",
                "items": [
                    {
                        "type": "string"
                    }
                ],
                "minItems": 0,
                "maxItems": 5,
                "additionalItems": false
            }
        },
        "additionalProperties": false
    }
}

Throws error: type array cannot be used as index

shuplenkov commented 3 years ago

Change "items": [ { "type": "string" } ], to "items": { "type": "string" } ,. It will help.

dashameter commented 3 years ago

on v.21-devnet this issue is solved, this registers successfully:

{
    tweet: {
      type: 'object',
      indices: [
        { properties: [{ mentions: 'asc' }] },
      ],
      properties: {
        mentions: {
          type: 'array',
          items: { type: 'string' },
          minItems: 0,
          maxItems: 5,
        },
      },
      additionalProperties: false,
    },
  }

Note: now using additionalItems now throws:

{
  keyword: 'unevaluatedProperties',
  instancePath: '/documents/note/properties/message',
  schemaPath: '#/patternProperties/%5E%5Ba-zA-Z%5D%5Ba-zA-Z0-9-_%5D%7B1%2C62%7D%5Ba-zA-Z0-9%5D%24/unevaluatedProperties',
  params: { unevaluatedProperty: 'additionalItems' },
  propertyName: undefined,
  [Symbol(constructorArguments)]: [
    'must NOT have unevaluated properties',
    'unevaluatedProperties',
    '/documents/note/properties/message',
    '#/patternProperties/%5E%5Ba-zA-Z%5D%5Ba-zA-Z0-9-_%5D%7B1%2C62%7D%5Ba-zA-Z0-9%5D%24/unevaluatedProperties',
    { unevaluatedProperty: 'additionalItems' },
    undefined
  ]
}