@zenstackhq/cli 3.0.0-beta.3 → 3.0.0-beta.30

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
@@ -57,4 +57,25 @@ model User {
57
57
  runCli('generate', workDir);
58
58
  expect(fs.existsSync(path.join(workDir, 'prisma/schema.prisma'))).toBe(true);
59
59
  });
60
+
61
+ it('can generate a Prisma schema with custom output relative to zenstack.output', () => {
62
+ const workDir = createProject(`
63
+ plugin prisma {
64
+ provider = '@core/prisma'
65
+ output = './schema.prisma'
66
+ }
67
+
68
+ model User {
69
+ id String @id @default(cuid())
70
+ }
71
+ `);
72
+
73
+ const pkgJson = JSON.parse(fs.readFileSync(path.join(workDir, 'package.json'), 'utf8'));
74
+ pkgJson.zenstack = {
75
+ output: './relative',
76
+ };
77
+ fs.writeFileSync(path.join(workDir, 'package.json'), JSON.stringify(pkgJson, null, 2));
78
+ runCli('generate', workDir);
79
+ expect(fs.existsSync(path.join(workDir, 'relative/schema.prisma'))).toBe(true);
80
+ });
60
81
  });
@@ -1,4 +1,4 @@
1
- import { ExpressionUtils } from '@zenstackhq/runtime/schema';
1
+ import { ExpressionUtils } from '@zenstackhq/orm/schema';
2
2
  import { createTestProject, generateTsSchema, generateTsSchemaInPlace } from '@zenstackhq/testtools';
3
3
  import fs from 'node:fs';
4
4
  import path from 'node:path';
@@ -360,4 +360,86 @@ model User extends Base {
360
360
  expect(schema.enums).toMatchObject({ Role: expect.any(Object) });
361
361
  expect(schema.models).toMatchObject({ User: expect.any(Object) });
362
362
  });
363
+
364
+ it('generates correct default literal function arguments', async () => {
365
+ const { schema } = await generateTsSchema(`
366
+ model User {
367
+ id String @id @default(uuid(7))
368
+ }
369
+ `);
370
+
371
+ expect(schema.models).toMatchObject({
372
+ User: {
373
+ name: 'User',
374
+ fields: {
375
+ id: {
376
+ name: 'id',
377
+ type: 'String',
378
+ id: true,
379
+ attributes: [
380
+ {
381
+ name: '@id',
382
+ },
383
+ {
384
+ name: '@default',
385
+ args: [
386
+ {
387
+ name: 'value',
388
+ value: {
389
+ kind: 'call',
390
+ function: 'uuid',
391
+ args: [
392
+ {
393
+ kind: 'literal',
394
+ value: 7,
395
+ },
396
+ ],
397
+ },
398
+ },
399
+ ],
400
+ },
401
+ ],
402
+ default: {
403
+ kind: 'call',
404
+ function: 'uuid',
405
+ args: [
406
+ {
407
+ kind: 'literal',
408
+ value: 7,
409
+ },
410
+ ],
411
+ },
412
+ },
413
+ },
414
+ idFields: ['id'],
415
+ uniqueFields: {
416
+ id: {
417
+ type: 'String',
418
+ },
419
+ },
420
+ },
421
+ });
422
+ });
423
+
424
+ it('supports lite schema generation', async () => {
425
+ const { schemaLite } = await generateTsSchema(
426
+ `
427
+ model User {
428
+ id String @id @default(uuid())
429
+ name String
430
+ email String @unique
431
+
432
+ @@map('users')
433
+ }
434
+ `,
435
+ undefined,
436
+ undefined,
437
+ undefined,
438
+ true,
439
+ );
440
+
441
+ expect(schemaLite!.models.User.attributes).toBeUndefined();
442
+ expect(schemaLite!.models.User.fields.id.attributes).toBeUndefined();
443
+ expect(schemaLite!.models.User.fields.email.attributes).toBeUndefined();
444
+ });
363
445
  });