A plain JavaScript validator for AT Protocol lexicon schemas
1// Test inputs for params data validation
2
3const paramsLexicon = {
4 lexicon: 1,
5 id: 'test.params.data',
6 defs: {
7 main: {
8 type: 'query',
9 parameters: {
10 type: 'params',
11 properties: {
12 repo: { type: 'string' },
13 limit: { type: 'integer', minimum: 1, maximum: 100 },
14 cursor: { type: 'string' },
15 enabled: { type: 'boolean' },
16 tags: {
17 type: 'array',
18 items: { type: 'string', maxLength: 50 },
19 },
20 },
21 required: ['repo'],
22 },
23 },
24 },
25};
26
27const allTypesLexicon = {
28 lexicon: 1,
29 id: 'test.params.alltypes',
30 defs: {
31 main: {
32 type: 'query',
33 parameters: {
34 type: 'params',
35 properties: {
36 name: { type: 'string', maxLength: 5 },
37 count: { type: 'integer', minimum: 1 },
38 enabled: { type: 'boolean' },
39 metadata: { type: 'unknown' },
40 },
41 },
42 },
43 },
44};
45
46export const paramsDataInputs = [
47 {
48 name: 'params-data-valid-with-required',
49 lexicons: [paramsLexicon],
50 collection: 'test.params.data',
51 record: {
52 repo: 'alice.bsky.social',
53 limit: 50,
54 },
55 },
56 {
57 name: 'params-data-valid-with-optional',
58 lexicons: [paramsLexicon],
59 collection: 'test.params.data',
60 record: {
61 repo: 'alice.bsky.social',
62 },
63 },
64 {
65 name: 'params-data-valid-all-types',
66 lexicons: [allTypesLexicon],
67 collection: 'test.params.alltypes',
68 record: {
69 name: 'test',
70 count: 42,
71 enabled: true,
72 metadata: { key: 'value' },
73 },
74 },
75 {
76 name: 'params-data-valid-with-array',
77 lexicons: [paramsLexicon],
78 collection: 'test.params.data',
79 record: {
80 repo: 'alice.bsky.social',
81 tags: ['foo', 'bar'],
82 },
83 },
84 {
85 name: 'params-data-invalid-missing-required',
86 lexicons: [paramsLexicon],
87 collection: 'test.params.data',
88 record: {
89 limit: 50,
90 },
91 },
92 {
93 name: 'params-data-invalid-wrong-type',
94 lexicons: [
95 {
96 lexicon: 1,
97 id: 'test.params.wrongtype',
98 defs: {
99 main: {
100 type: 'query',
101 parameters: {
102 type: 'params',
103 properties: {
104 limit: { type: 'integer' },
105 },
106 },
107 },
108 },
109 },
110 ],
111 collection: 'test.params.wrongtype',
112 record: {
113 limit: 'not a number',
114 },
115 },
116 {
117 name: 'params-data-invalid-string-too-long',
118 lexicons: [allTypesLexicon],
119 collection: 'test.params.alltypes',
120 record: {
121 name: 'toolongname',
122 },
123 },
124 {
125 name: 'params-data-invalid-integer-below-minimum',
126 lexicons: [allTypesLexicon],
127 collection: 'test.params.alltypes',
128 record: {
129 count: 0,
130 },
131 },
132 {
133 name: 'params-data-invalid-array-wrong-item-type',
134 lexicons: [
135 {
136 lexicon: 1,
137 id: 'test.params.arraytype',
138 defs: {
139 main: {
140 type: 'query',
141 parameters: {
142 type: 'params',
143 properties: {
144 ids: {
145 type: 'array',
146 items: { type: 'integer' },
147 },
148 },
149 },
150 },
151 },
152 },
153 ],
154 collection: 'test.params.arraytype',
155 record: {
156 ids: ['one', 'two'],
157 },
158 },
159 {
160 name: 'params-data-valid-empty-schema',
161 lexicons: [
162 {
163 lexicon: 1,
164 id: 'test.params.empty',
165 defs: {
166 main: {
167 type: 'query',
168 parameters: {
169 type: 'params',
170 },
171 },
172 },
173 },
174 ],
175 collection: 'test.params.empty',
176 record: {},
177 },
178 {
179 name: 'params-data-valid-unknown-parameters-allowed',
180 lexicons: [
181 {
182 lexicon: 1,
183 id: 'test.params.extra',
184 defs: {
185 main: {
186 type: 'query',
187 parameters: {
188 type: 'params',
189 properties: {
190 repo: { type: 'string' },
191 },
192 },
193 },
194 },
195 },
196 ],
197 collection: 'test.params.extra',
198 record: {
199 repo: 'alice.bsky.social',
200 extra: 'allowed',
201 },
202 },
203];