Skip to content

Commit

Permalink
Browse files Browse the repository at this point in the history
  • Loading branch information
pubkey committed Jul 22, 2022
1 parent b59e025 commit d79fc49
Showing 1 changed file with 15 additions and 13 deletions.
28 changes: 15 additions & 13 deletions docs-src/schema-validation.md
Original file line number Diff line number Diff line change
Expand Up @@ -14,16 +14,16 @@ When no validation is used, any document data can be safed but there might be **

RxDB has different implementations to validate data, each of them is based on a different [JSON Schema library](https://json-schema.org/implementations.html). In this exmaples we use the [Dexie.js RxStorage](./rx-storage-dexie.md), but you can wrap the validation around **any other** [RxStorage](./rx-storage.md).

### validate-is-my-json-valid
### validate-ajv

The `validate-is-my-json-valid` plugin uses [is-my-json-valid](https://www.npmjs.com/package/is-my-json-valid) for schema validation.
Another validation-module that does the schema-validation. This one is using [ajv](https://github.com/epoberezkin/ajv) as validator which is a bit faster. Better compliant to the jsonschema-standart but also has a bigger build-size.

```javascript
import { wrappedValidateIsMyJsonValidStorage } from 'rxdb/plugins/validate-is-my-json-valid';
import { wrappedValidateAjvStorage } from 'rxdb/plugins/validate-ajv';
import { getRxStorageDexie } from 'rxdb/plugins/dexie';

// wrap the validation around the main RxStorage
const storage = wrappedValidateIsMyJsonValidStorage({
const storage = wrappedValidateAjvStorage({
storage: getRxStorageDexie()
});

Expand All @@ -33,17 +33,16 @@ const db = await createRxDatabase({
});
```

### validate-z-schema

### validate-ajv

Another validation-module that does the schema-validation. This one is using [ajv](https://github.com/epoberezkin/ajv) as validator which is a bit faster. Better compliant to the jsonschema-standart but also has a bigger build-size.
Both `is-my-json-valid` and `validate-ajv` use `eval()` to perform validation which might not be wanted when `'unsafe-eval'` is not allowed in Content Security Policies. This one is using [z-schema](https://github.com/zaggino/z-schema) as validator which doesn't use `eval`.

```javascript
import { wrappedValidateAjvStorage } from 'rxdb/plugins/validate-ajv';
import { wrappedValidateZSchemaStorage } from 'rxdb/plugins/validate-z-schema';
import { getRxStorageDexie } from 'rxdb/plugins/dexie';

// wrap the validation around the main RxStorage
const storage = wrappedValidateAjvStorage({
const storage = wrappedValidateZSchemaStorage({
storage: getRxStorageDexie()
});

Expand All @@ -53,16 +52,19 @@ const db = await createRxDatabase({
});
```

### validate-z-schema

Both `is-my-json-valid` and `validate-ajv` use `eval()` to perform validation which might not be wanted when `'unsafe-eval'` is not allowed in Content Security Policies. This one is using [z-schema](https://github.com/zaggino/z-schema) as validator which doesn't use `eval`.
### validate-is-my-json-valid

**WARNING**: The `is-my-json-valid` validation is no longer supported until [this bug](https://github.com/mafintosh/is-my-json-valid/pull/192) is fixed.

The `validate-is-my-json-valid` plugin uses [is-my-json-valid](https://www.npmjs.com/package/is-my-json-valid) for schema validation.

```javascript
import { wrappedValidateZSchemaStorage } from 'rxdb/plugins/validate-z-schema';
import { wrappedValidateIsMyJsonValidStorage } from 'rxdb/plugins/validate-is-my-json-valid';
import { getRxStorageDexie } from 'rxdb/plugins/dexie';

// wrap the validation around the main RxStorage
const storage = wrappedValidateZSchemaStorage({
const storage = wrappedValidateIsMyJsonValidStorage({
storage: getRxStorageDexie()
});

Expand Down

0 comments on commit d79fc49

Please sign in to comment.