File tree Expand file tree Collapse file tree 3 files changed +99
-0
lines changed
tests/integration/tests/enhancements/json Expand file tree Collapse file tree 3 files changed +99
-0
lines changed Original file line number Diff line number Diff line change @@ -15,6 +15,7 @@ export function createProject(options?: CompilerOptions) {
15
15
strict : true ,
16
16
skipLibCheck : true ,
17
17
noEmitOnError : true ,
18
+ noImplicitAny : false ,
18
19
...options ,
19
20
} ,
20
21
} ) ;
Original file line number Diff line number Diff line change @@ -344,4 +344,49 @@ describe('Json field CRUD', () => {
344
344
expect ( u2 . profile . ownerId ) . toBe ( 2 ) ;
345
345
expect ( u2 . profile . nested . userId ) . toBe ( 3 ) ;
346
346
} ) ;
347
+
348
+ it ( 'works with recursive types' , async ( ) => {
349
+ const params = await loadSchema (
350
+ `
351
+ type Content {
352
+ type String
353
+ content Content[]?
354
+ text String?
355
+ }
356
+
357
+ model Post {
358
+ id Int @id @default(autoincrement())
359
+ content Content @json
360
+ @@allow('all', true)
361
+ }
362
+ ` ,
363
+ {
364
+ provider : 'postgresql' ,
365
+ dbUrl,
366
+ }
367
+ ) ;
368
+
369
+ prisma = params . prisma ;
370
+ const db = params . enhance ( ) ;
371
+ const post = await db . post . create ( {
372
+ data : {
373
+ content : {
374
+ type : 'text' ,
375
+ content : [
376
+ {
377
+ type : 'text' ,
378
+ content : [
379
+ {
380
+ type : 'text' ,
381
+ text : 'hello' ,
382
+ } ,
383
+ ] ,
384
+ } ,
385
+ ] ,
386
+ } ,
387
+ } ,
388
+ } ) ;
389
+
390
+ await expect ( post . content . content [ 0 ] . content [ 0 ] . text ) . toBe ( 'hello' ) ;
391
+ } ) ;
347
392
} ) ;
Original file line number Diff line number Diff line change @@ -325,6 +325,59 @@ async function main() {
325
325
dateTime: new Date(),
326
326
json: { a: 1 },
327
327
}
328
+ }
329
+ ` ,
330
+ } ,
331
+ ] ,
332
+ }
333
+ ) ;
334
+ } ) ;
335
+
336
+ it ( 'supports recursive definition' , async ( ) => {
337
+ await loadSchema (
338
+ `
339
+ type Content {
340
+ type String
341
+ content Content[]?
342
+ text String?
343
+ }
344
+
345
+ model Post {
346
+ id Int @id @default(autoincrement())
347
+ content Content @json
348
+ }
349
+ ` ,
350
+ {
351
+ provider : 'postgresql' ,
352
+ pushDb : false ,
353
+ compile : true ,
354
+ extraSourceFiles : [
355
+ {
356
+ name : 'main.ts' ,
357
+ content : `
358
+ import type { Content } from '.zenstack/models';
359
+ import { enhance } from '.zenstack/enhance';
360
+ import { PrismaClient } from '@prisma/client';
361
+
362
+ async function main() {
363
+ const content: Content = {
364
+ type: 'text',
365
+ content: [
366
+ {
367
+ type: 'text',
368
+ content: [
369
+ {
370
+ type: 'text',
371
+ text: 'hello',
372
+ },
373
+ ],
374
+ },
375
+ ],
376
+ }
377
+
378
+ const db = enhance(new PrismaClient());
379
+ const post = await db.post.create({ data: { content } });
380
+ console.log(post.content.content?.[0].content?.[0].text);
328
381
}
329
382
` ,
330
383
} ,
You can’t perform that action at this time.
0 commit comments