0
# Slate Schema Violations
1
2
Slate Schema Violations provides a comprehensive set of named string constants for schema validation violations in the Slate rich text editor framework. These constants represent different types of validation errors that can occur when validating document structure against a Slate schema.
3
4
## Package Information
5
6
- **Package Name**: slate-schema-violations
7
- **Package Type**: npm
8
- **Language**: JavaScript
9
- **Installation**: `npm install slate-schema-violations`
10
11
## Core Imports
12
13
```javascript
14
import {
15
CHILD_REQUIRED,
16
NODE_TYPE_INVALID,
17
PARENT_OBJECT_INVALID
18
} from "slate-schema-violations";
19
```
20
21
For importing all constants:
22
23
```javascript
24
import * as violations from "slate-schema-violations";
25
```
26
27
CommonJS:
28
29
```javascript
30
const {
31
CHILD_REQUIRED,
32
NODE_TYPE_INVALID,
33
PARENT_OBJECT_INVALID
34
} = require("slate-schema-violations");
35
```
36
37
## Basic Usage
38
39
```javascript
40
import { CHILD_REQUIRED, NODE_TYPE_INVALID } from "slate-schema-violations";
41
42
// Use in schema validation logic
43
function validateNode(node, schema) {
44
if (!node.type) {
45
throw new Error(NODE_TYPE_INVALID);
46
}
47
48
if (schema.children && !node.children) {
49
throw new Error(CHILD_REQUIRED);
50
}
51
52
// Additional validation logic...
53
}
54
55
// Use in error handling
56
function handleValidationError(error) {
57
switch (error.code) {
58
case CHILD_REQUIRED:
59
return "Required child node is missing";
60
case NODE_TYPE_INVALID:
61
return "Node type is invalid";
62
default:
63
return "Unknown validation error";
64
}
65
}
66
```
67
68
## Capabilities
69
70
### Child Node Validation Constants
71
72
Constants for validating child node relationships and structure.
73
74
```javascript { .api }
75
const CHILD_OBJECT_INVALID = 'child_object_invalid';
76
const CHILD_REQUIRED = 'child_required';
77
const CHILD_TYPE_INVALID = 'child_type_invalid';
78
const CHILD_UNKNOWN = 'child_unknown';
79
```
80
81
- **CHILD_OBJECT_INVALID**: Child object structure is invalid
82
- **CHILD_REQUIRED**: Required child node is missing
83
- **CHILD_TYPE_INVALID**: Child node type is invalid
84
- **CHILD_UNKNOWN**: Unknown/unexpected child node
85
86
### First/Last Child Validation Constants
87
88
Constants for validating specific positional child nodes.
89
90
```javascript { .api }
91
const FIRST_CHILD_OBJECT_INVALID = 'first_child_object_invalid';
92
const FIRST_CHILD_TYPE_INVALID = 'first_child_type_invalid';
93
const LAST_CHILD_OBJECT_INVALID = 'last_child_object_invalid';
94
const LAST_CHILD_TYPE_INVALID = 'last_child_type_invalid';
95
```
96
97
- **FIRST_CHILD_OBJECT_INVALID**: First child object structure is invalid
98
- **FIRST_CHILD_TYPE_INVALID**: First child node type is invalid
99
- **LAST_CHILD_OBJECT_INVALID**: Last child object structure is invalid
100
- **LAST_CHILD_TYPE_INVALID**: Last child node type is invalid
101
102
### Sibling Node Validation Constants
103
104
Constants for validating sibling node relationships.
105
106
```javascript { .api }
107
const NEXT_SIBLING_OBJECT_INVALID = 'next_sibling_object_invalid';
108
const NEXT_SIBLING_TYPE_INVALID = 'next_sibling_type_invalid';
109
const PREVIOUS_SIBLING_OBJECT_INVALID = 'previous_sibling_object_invalid';
110
const PREVIOUS_SIBLING_TYPE_INVALID = 'previous_sibling_type_invalid';
111
```
112
113
- **NEXT_SIBLING_OBJECT_INVALID**: Next sibling object structure is invalid
114
- **NEXT_SIBLING_TYPE_INVALID**: Next sibling node type is invalid
115
- **PREVIOUS_SIBLING_OBJECT_INVALID**: Previous sibling object structure is invalid
116
- **PREVIOUS_SIBLING_TYPE_INVALID**: Previous sibling node type is invalid
117
118
### Node Property Validation Constants
119
120
Constants for validating individual node properties and structure.
121
122
```javascript { .api }
123
const NODE_DATA_INVALID = 'node_data_invalid';
124
const NODE_IS_VOID_INVALID = 'node_is_void_invalid';
125
const NODE_MARK_INVALID = 'node_mark_invalid';
126
const NODE_OBJECT_INVALID = 'node_object_invalid';
127
const NODE_TEXT_INVALID = 'node_text_invalid';
128
const NODE_TYPE_INVALID = 'node_type_invalid';
129
```
130
131
- **NODE_DATA_INVALID**: Node data property is invalid
132
- **NODE_IS_VOID_INVALID**: Node void property is invalid
133
- **NODE_MARK_INVALID**: Node mark property is invalid
134
- **NODE_OBJECT_INVALID**: Node object structure is invalid
135
- **NODE_TEXT_INVALID**: Node text property is invalid
136
- **NODE_TYPE_INVALID**: Node type property is invalid
137
138
### Parent Node Validation Constants
139
140
Constants for validating parent-child relationships.
141
142
```javascript { .api }
143
const PARENT_OBJECT_INVALID = 'parent_object_invalid';
144
const PARENT_TYPE_INVALID = 'parent_type_invalid';
145
```
146
147
- **PARENT_OBJECT_INVALID**: Parent object structure is invalid
148
- **PARENT_TYPE_INVALID**: Parent node type is invalid
149
150
## All Available Constants
151
152
Complete list of all exported constants:
153
154
```javascript { .api }
155
// Child validation
156
export const CHILD_OBJECT_INVALID = 'child_object_invalid';
157
export const CHILD_REQUIRED = 'child_required';
158
export const CHILD_TYPE_INVALID = 'child_type_invalid';
159
export const CHILD_UNKNOWN = 'child_unknown';
160
161
// First/Last child validation
162
export const FIRST_CHILD_OBJECT_INVALID = 'first_child_object_invalid';
163
export const FIRST_CHILD_TYPE_INVALID = 'first_child_type_invalid';
164
export const LAST_CHILD_OBJECT_INVALID = 'last_child_object_invalid';
165
export const LAST_CHILD_TYPE_INVALID = 'last_child_type_invalid';
166
167
// Sibling validation
168
export const NEXT_SIBLING_OBJECT_INVALID = 'next_sibling_object_invalid';
169
export const NEXT_SIBLING_TYPE_INVALID = 'next_sibling_type_invalid';
170
export const PREVIOUS_SIBLING_OBJECT_INVALID = 'previous_sibling_object_invalid';
171
export const PREVIOUS_SIBLING_TYPE_INVALID = 'previous_sibling_type_invalid';
172
173
// Node property validation
174
export const NODE_DATA_INVALID = 'node_data_invalid';
175
export const NODE_IS_VOID_INVALID = 'node_is_void_invalid';
176
export const NODE_MARK_INVALID = 'node_mark_invalid';
177
export const NODE_OBJECT_INVALID = 'node_object_invalid';
178
export const NODE_TEXT_INVALID = 'node_text_invalid';
179
export const NODE_TYPE_INVALID = 'node_type_invalid';
180
181
// Parent validation
182
export const PARENT_OBJECT_INVALID = 'parent_object_invalid';
183
export const PARENT_TYPE_INVALID = 'parent_type_invalid';
184
```