8.2.0 • Published 2 years ago

@socketdb/plugin-validate v8.2.0

Weekly downloads
-
License
MIT
Repository
github
Last release
2 years ago

@socketdb/plugin-validate

Table of Contents

About

Adds schema validation to SocketDB to only allow saving data that matches the schema.

It uses ajv under the hood.

Installing

Using pnpm:

pnpm add @socketdb/plugin-validate

or npm:

npm i @socketdb/plugin-validate

Usage

Create a schema and add plugin to the SocketDB server.

import { SocketDBServer } from 'socketdb';
import validate, { JSONSchemaType } from '@socketdb/plugin-validate';

type Data = {
	[key: string]: {
		player: {
			[id: string]: {
				name: string;
			};
		};
	};
};
const schema: JSONSchemaType<Data> = {
	type: 'object',
	required: [],
	additionalProperties: {
		type: 'object',
		required: ['player'],
		properties: {
			player: {
				type: 'object',
				required: [],
				additionalProperties: {
					type: 'object',
					required: ['name'],
					properties: {
						name: {
							type: 'string',
						},
					},
				},
			},
		},
	},
};

SocketDBServer({
	plugins: [validate(schema)],
});

See: https://ajv.js.org/ for more information on how to create schemas.

8.1.0

2 years ago

8.0.1

2 years ago

8.0.0

2 years ago

8.2.0

2 years ago

8.0.2

2 years ago

7.2.0

2 years ago

6.2.0

2 years ago

7.0.0

2 years ago

6.1.0

2 years ago

6.0.0

2 years ago

5.0.1

2 years ago

5.0.0

2 years ago

4.1.0

3 years ago

4.2.1

3 years ago

4.2.0

3 years ago

4.1.1

3 years ago

1.1.0

4 years ago