pubkey / rxdb

A fast, local first, reactive Database for JavaScript Applications https://rxdb.info/
https://rxdb.info/
Apache License 2.0
21.56k stars 1.06k forks source link

Schema Validation Error #708

Closed gpathak18 closed 6 years ago

gpathak18 commented 6 years ago

Case

Bug

Issue

Getting Schema validation error for two cases -

  1. When I try to set 'primary'
  2. When I try to set 'index'

My Schema is defined in separate json file - names.schema.json

Info

Code

/** Index Key Error **/
SchemaCheck: given index is not defined in schema
Given parameters: {
key:"default.Name"}
Error: RxError:
SchemaCheck: given index is not defined in schema
Given parameters: {
key:"default.Name"}
    at new RxError (rx-error.js:48)
    at Object.newRxError (rx-error.js:124)
    at schema-check.js:231`

/** Schema **/
{
  "title": "New schema",
  "type": "object",
  "version": 0,
  "disableKeyCompression": true,
  "properties": {
    "Name": {
      "type": "string",
      "index": true
    }
 }

/** Primary Key Error **/

SchemaCheck: primary can only be defined at top-level
Given parameters: {
path:".default"
primary:true}
    at new RxError (rx-error.js:48)
    at Object.newRxError (rx-error.js:124)
    at checkField (schema-check.js:86)`

/** Schema **/
{
  "title": "New schema",
  "type": "object",
  "version": 0,
  "disableKeyCompression": true,
  "properties": {
    "Name": {
      "type": "string",
      "primary": true
    }
 }
pubkey commented 6 years ago

Hi @gpathak18 It looks like you have imported your seperate file with the schema wrong. Try import MySchema from 'whatever.json';

gpathak18 commented 6 years ago

Hi @pubkey

Currently my import statement is like -

import * as MySchema from '../../whatever.json';

This worked and schema/collection was created. But then it failed as I added "primary" attribute.

Than I changed the import as per your comment to 'import MySchema from '../../whatever.json'; and it worked.

Not sure if there is anything need a fix. This can be closed if not.

Thank you for your response on that.

pubkey commented 6 years ago

No this does not need a fix. There is just a difference between and default and an asterix import. Good that your code works now.