11import { query , prerender , command , form } from '$app/server' ;
22import { StandardSchemaV1 } from '@standard-schema/spec' ;
3- import { RemotePrerenderFunction , RemoteQueryFunction } from '@sveltejs/kit' ;
3+ import { RemotePrerenderFunction , RemoteQueryFunction , invalid } from '@sveltejs/kit' ;
44
55const schema : StandardSchemaV1 < string > = null as any ;
66const schema2 : StandardSchemaV1 < string , number > = null as any ;
@@ -159,14 +159,16 @@ command_tests();
159159
160160function form_tests ( ) {
161161 const q = query ( ( ) => '' ) ;
162- const f = form ( 'unchecked' , ( data : { input : string } , invalid ) => {
162+ const f = form ( 'unchecked' , ( data : { input : string } , issue ) => {
163163 data . input ;
164- invalid (
165- 'foo' ,
166- invalid . input ( 'bar' ) ,
167- // @ts -expect-error
168- invalid . nonexistent . prop ( 'baz' )
169- ) ;
164+ if ( Math . random ( ) > 0.5 ) {
165+ invalid (
166+ 'foo' ,
167+ issue . input ( 'bar' ) ,
168+ // @ts -expect-error
169+ issue . nonexistent . prop ( 'baz' )
170+ ) ;
171+ }
170172 return { success : true } ;
171173 } ) ;
172174
@@ -184,7 +186,7 @@ function form_tests() {
184186
185187 const f2 = form (
186188 null as any as StandardSchemaV1 < { a : string ; nested : { prop : string } } > ,
187- ( data , invalid ) => {
189+ ( data , issue ) => {
188190 data . a === '' ;
189191 data . nested . prop === '' ;
190192 // @ts -expect-error
@@ -193,17 +195,19 @@ function form_tests() {
193195 data . nonexistent ;
194196 // @ts -expect-error
195197 data . a === 123 ;
196- invalid (
197- 'foo' ,
198- invalid . nested . prop ( 'bar' ) ,
199- // @ts -expect-error
200- invalid . nonexistent . prop ( 'baz' )
201- ) ;
198+ if ( Math . random ( ) > 0.5 ) {
199+ invalid (
200+ 'foo' ,
201+ issue . nested . prop ( 'bar' ) ,
202+ // @ts -expect-error
203+ issue . nonexistent . prop ( 'baz' )
204+ ) ;
205+ }
202206 return { success : true } ;
203207 }
204208 ) ;
205209 // @ts -expect-error
206- f2 . fields . name ( ) ;
210+ f2 . fields . as ( 'text' ) ;
207211 f2 . fields . a . issues ( ) ;
208212 f2 . fields . nested . prop . issues ( ) ;
209213 // @ts -expect-error
@@ -213,12 +217,12 @@ function form_tests() {
213217 // @ts -expect-error
214218 f2 . fields . nonexistent . value ( ) ;
215219 // @ts -expect-error
216- f2 . fields . array [ 0 ] . array . name ( ) ;
220+ f2 . fields . array [ 0 ] . array . as ( 'text' ) ;
217221
218222 // all schema properties optional
219223 const f3 = form (
220224 null as any as StandardSchemaV1 < { a ?: string ; nested ?: { prop ?: string } } > ,
221- ( data , invalid ) => {
225+ ( data , issue ) => {
222226 data . a === '' ;
223227 data . nested ?. prop === '' ;
224228 // @ts -expect-error
@@ -229,23 +233,25 @@ function form_tests() {
229233 data . nonexistent ;
230234 // @ts -expect-error
231235 data . a === 123 ;
232- invalid (
233- 'foo' ,
234- invalid . nested . prop ( 'bar' ) ,
235- // @ts -expect-error
236- invalid . nonexistent . prop ( 'baz' )
237- ) ;
236+ if ( Math . random ( ) > 0.5 ) {
237+ invalid (
238+ 'foo' ,
239+ issue . nested . prop ( 'bar' ) ,
240+ // @ts -expect-error
241+ issue . nonexistent . prop ( 'baz' )
242+ ) ;
243+ }
238244 return { success : true } ;
239245 }
240246 ) ;
241247 // @ts -expect-error
242- f3 . fields . name ( ) ;
248+ f3 . fields . as ( 'text' ) ;
243249 f3 . fields . a . issues ( ) ;
244250 f3 . fields . a . value ( ) ;
245251 f3 . fields . nested . prop . issues ( ) ;
246252 f3 . fields . nested . prop . value ( ) ;
247253 // @ts -expect-error
248- f3 . fields . nonexistent . name ( ) ;
254+ f3 . fields . nonexistent . as ( 'text' ) ;
249255
250256 // index signature schema
251257 const f4 = form ( null as any as StandardSchemaV1 < Record < string , any > > , ( data ) => {
@@ -254,7 +260,7 @@ function form_tests() {
254260 return { success : true } ;
255261 } ) ;
256262 // @ts -expect-error
257- f4 . fields . name ( ) ;
263+ f4 . fields . as ( 'text' ) ;
258264 f4 . fields . a . issues ( ) ;
259265 f4 . fields . a . value ( ) ;
260266 f4 . fields . nested . prop . issues ( ) ;
@@ -263,50 +269,54 @@ function form_tests() {
263269 // schema with union types
264270 const f5 = form (
265271 null as any as StandardSchemaV1 < { foo : 'a' | 'b' ; bar : 'c' | 'd' } > ,
266- ( data , invalid ) => {
272+ ( data , issue ) => {
267273 data . foo === 'a' ;
268274 data . bar === 'c' ;
269275 // @ts -expect-error
270276 data . foo === 'e' ;
271- invalid (
272- 'foo' ,
273- invalid . bar ( 'bar' ) ,
274- // @ts -expect-error
275- invalid . nonexistent . prop ( 'baz' )
276- ) ;
277+ if ( Math . random ( ) > 0.5 ) {
278+ invalid (
279+ 'foo' ,
280+ issue . bar ( 'bar' ) ,
281+ // @ts -expect-error
282+ issue . nonexistent . prop ( 'baz' )
283+ ) ;
284+ }
277285 return { success : true } ;
278286 }
279287 ) ;
280288 // @ts -expect-error
281- f5 . fields . name ( ) ;
289+ f5 . fields . as ( 'text' ) ;
282290 f5 . fields . foo . issues ( ) ;
283291 f5 . fields . bar . issues ( ) ;
284292 f5 . fields . foo . value ( ) ;
285293 f5 . fields . bar . value ( ) === 'c' ;
286294 // @ts -expect-error
287295 f5 . fields . foo . value ( ) === 'e' ;
288296 // @ts -expect-error
289- f5 . fields . nonexistent . name ( ) ;
297+ f5 . fields . nonexistent . as ( 'text' ) ;
290298
291299 // schema with arrays
292300 const f6 = form (
293301 null as any as StandardSchemaV1 < { array : Array < { array : string [ ] ; prop : string } > } > ,
294- ( data , invalid ) => {
302+ ( data , issue ) => {
295303 data . array [ 0 ] . prop === 'a' ;
296304 data . array [ 0 ] . array [ 0 ] === 'a' ;
297305 // @ts -expect-error
298306 data . array [ 0 ] . array [ 0 ] === 1 ;
299- invalid (
300- 'foo' ,
301- invalid . array [ 0 ] . prop ( 'bar' ) ,
302- // @ts -expect-error
303- invalid . nonexistent . prop ( 'baz' )
304- ) ;
307+ if ( Math . random ( ) > 0.5 ) {
308+ invalid (
309+ 'foo' ,
310+ issue . array [ 0 ] . prop ( 'bar' ) ,
311+ // @ts -expect-error
312+ issue . nonexistent . prop ( 'baz' )
313+ ) ;
314+ }
305315 return { success : true } ;
306316 }
307317 ) ;
308318 // @ts -expect-error
309- f6 . fields . name ( ) ;
319+ f6 . fields . as ( 'text' ) ;
310320 // @ts -expect-error
311321 f6 . field ( 'array[0].array' ) ;
312322 f6 . fields . array . issues ( ) ;
@@ -317,29 +327,27 @@ function form_tests() {
317327 f6 . fields . array [ 0 ] . prop . value ( ) ;
318328 f6 . fields . array [ 0 ] . array . value ( ) ;
319329 // @ts -expect-error
320- f6 . fields . array [ 0 ] . array . name ( ) ;
330+ f6 . fields . array [ 0 ] . array . as ( 'text' ) ;
321331
322332 // any
323- const f7 = form ( null as any , ( data , invalid ) => {
333+ const f7 = form ( null as any , ( data , issue ) => {
324334 data . a === '' ;
325335 data . nested ?. prop === '' ;
326- invalid ( 'foo' , invalid . nested . prop ( 'bar' ) ) ;
336+ if ( Math . random ( ) > 0.5 ) {
337+ invalid ( 'foo' , issue . nested . prop ( 'bar' ) ) ;
338+ }
327339 return { success : true } ;
328340 } ) ;
329341 // @ts -expect-error
330- f7 . fields . name ( ) ;
342+ f7 . fields . as ( 'text' ) ;
331343 f7 . fields . a . issues ( ) ;
332344 f7 . fields . a . value ( ) ;
333345 f7 . fields . nested . prop . issues ( ) ;
334346 f7 . fields . nested . prop . value ( ) ;
335347
336348 // no schema
337- const f8 = form ( ( invalid ) => {
338- invalid (
339- 'foo' ,
340- // @ts -expect-error
341- invalid . x ( 'bar' )
342- ) ;
349+ const f8 = form ( ( ) => {
350+ invalid ( 'foo' ) ;
343351 } ) ;
344352 // @ts -expect-error
345353 f8 . fields . x ;
0 commit comments