@@ -150,4 +150,106 @@ describe('THS schema validation + lint', function () {
150150 const issues = lintThs ( res . data ) ;
151151 expect ( issues . some ( ( i ) => i . code === 'lint.app.ui.custom_home_without_extensions' ) ) . to . equal ( true ) ;
152152 } ) ;
153+
154+ it ( 'validateThsStructural accepts tokenized query index primitives' , function ( ) {
155+ const input = minimalSchema ( {
156+ collections : [
157+ {
158+ name : 'Post' ,
159+ fields : [ { name : 'body' , type : 'string' , required : true } ] ,
160+ createRules : { required : [ 'body' ] , access : 'public' } ,
161+ visibilityRules : { gets : [ 'body' ] , access : 'public' } ,
162+ updateRules : { mutable : [ 'body' ] , access : 'owner' } ,
163+ deleteRules : { softDelete : true , access : 'owner' } ,
164+ indexes : {
165+ unique : [ ] ,
166+ index : [ { field : 'body' , mode : 'tokenized' , tokenizer : 'hashtag' } ]
167+ }
168+ }
169+ ]
170+ } ) ;
171+
172+ const res = validateThsStructural ( input ) ;
173+ expect ( res . ok ) . to . equal ( true ) ;
174+ } ) ;
175+
176+ it ( 'lintThs rejects tokenized query indexes on unsupported field types' , function ( ) {
177+ const input = minimalSchema ( {
178+ collections : [
179+ {
180+ name : 'Post' ,
181+ fields : [ { name : 'imageRef' , type : 'image' , required : true } ] ,
182+ createRules : { required : [ 'imageRef' ] , access : 'public' } ,
183+ visibilityRules : { gets : [ 'imageRef' ] , access : 'public' } ,
184+ updateRules : { mutable : [ 'imageRef' ] , access : 'owner' } ,
185+ deleteRules : { softDelete : true , access : 'owner' } ,
186+ indexes : {
187+ unique : [ ] ,
188+ index : [ { field : 'imageRef' , mode : 'tokenized' , tokenizer : 'hashtag' } ]
189+ }
190+ }
191+ ]
192+ } ) ;
193+
194+ const res = validateThsStructural ( input ) ;
195+ expect ( res . ok ) . to . equal ( true ) ;
196+ const issues = lintThs ( res . data ) ;
197+ expect ( issues . some ( ( i ) => i . code === 'lint.indexes.index_tokenized_unsupported_type' ) ) . to . equal ( true ) ;
198+ } ) ;
199+
200+ it ( 'lintThs rejects duplicate query indexes on the same field' , function ( ) {
201+ const input = minimalSchema ( {
202+ collections : [
203+ {
204+ name : 'Post' ,
205+ fields : [ { name : 'body' , type : 'string' , required : true } ] ,
206+ createRules : { required : [ 'body' ] , access : 'public' } ,
207+ visibilityRules : { gets : [ 'body' ] , access : 'public' } ,
208+ updateRules : { mutable : [ 'body' ] , access : 'owner' } ,
209+ deleteRules : { softDelete : true , access : 'owner' } ,
210+ indexes : {
211+ unique : [ ] ,
212+ index : [
213+ { field : 'body' } ,
214+ { field : 'body' , mode : 'tokenized' , tokenizer : 'hashtag' }
215+ ]
216+ }
217+ }
218+ ]
219+ } ) ;
220+
221+ const res = validateThsStructural ( input ) ;
222+ expect ( res . ok ) . to . equal ( true ) ;
223+ const issues = lintThs ( res . data ) ;
224+ expect ( issues . some ( ( i ) => i . code === 'lint.indexes.index_duplicate_field' ) ) . to . equal ( true ) ;
225+ } ) ;
226+
227+ it ( 'lintThs warns when query indexes are declared but on-chain indexing is disabled' , function ( ) {
228+ const input = minimalSchema ( {
229+ app : {
230+ name : 'Test App' ,
231+ slug : 'test-app' ,
232+ features : { uploads : false , onChainIndexing : false }
233+ } ,
234+ collections : [
235+ {
236+ name : 'Post' ,
237+ fields : [ { name : 'body' , type : 'string' , required : true } ] ,
238+ createRules : { required : [ 'body' ] , access : 'public' } ,
239+ visibilityRules : { gets : [ 'body' ] , access : 'public' } ,
240+ updateRules : { mutable : [ 'body' ] , access : 'owner' } ,
241+ deleteRules : { softDelete : true , access : 'owner' } ,
242+ indexes : {
243+ unique : [ ] ,
244+ index : [ { field : 'body' , mode : 'tokenized' , tokenizer : 'hashtag' } ]
245+ }
246+ }
247+ ]
248+ } ) ;
249+
250+ const res = validateThsStructural ( input ) ;
251+ expect ( res . ok ) . to . equal ( true ) ;
252+ const issues = lintThs ( res . data ) ;
253+ expect ( issues . some ( ( i ) => i . code === 'lint.indexes.index_ignored_when_onchain_disabled' ) ) . to . equal ( true ) ;
254+ } ) ;
153255} ) ;
0 commit comments