Skip to content

Commit 3cdadd7

Browse files
authored
chore: misc changes (#186)
* chore: misc changes * update * fix tests * fix lint * update test * update
1 parent 2ad8857 commit 3cdadd7

File tree

12 files changed

+38
-121
lines changed

12 files changed

+38
-121
lines changed

packages/cli/src/actions/validate.ts renamed to packages/cli/src/actions/check.ts

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -6,7 +6,7 @@ type Options = {
66
};
77

88
/**
9-
* CLI action for validating schema without generation
9+
* CLI action for checking a schema's validity.
1010
*/
1111
export async function run(options: Options) {
1212
const schemaFile = getSchemaFile(options.schema);

packages/cli/src/actions/generate.ts

Lines changed: 2 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -12,7 +12,6 @@ import { getPkgJsonConfig, getSchemaFile, loadSchemaDocument } from './action-ut
1212
type Options = {
1313
schema?: string;
1414
output?: string;
15-
silent?: boolean;
1615
};
1716

1817
/**
@@ -28,9 +27,8 @@ export async function run(options: Options) {
2827

2928
await runPlugins(schemaFile, model, outputPath);
3029

31-
if (!options.silent) {
32-
console.log(colors.green(`Generation completed successfully in ${Date.now() - start}ms.\n`));
33-
console.log(`You can now create a ZenStack client with it.
30+
console.log(colors.green(`Generation completed successfully in ${Date.now() - start}ms.\n`));
31+
console.log(`You can now create a ZenStack client with it.
3432
3533
\`\`\`ts
3634
import { ZenStackClient } from '@zenstackhq/runtime';
@@ -40,7 +38,6 @@ const client = new ZenStackClient(schema, {
4038
dialect: { ... }
4139
});
4240
\`\`\``);
43-
}
4441
}
4542

4643
function getOutputPath(options: Options, schemaFile: string) {

packages/cli/src/actions/index.ts

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -3,6 +3,6 @@ import { run as generate } from './generate';
33
import { run as info } from './info';
44
import { run as init } from './init';
55
import { run as migrate } from './migrate';
6-
import { run as validate } from './validate';
6+
import { run as check } from './check';
77

8-
export { db, generate, info, init, migrate, validate };
8+
export { db, generate, info, init, migrate, check };

packages/cli/src/index.ts

Lines changed: 16 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -25,8 +25,8 @@ const initAction = async (projectPath: string): Promise<void> => {
2525
await actions.init(projectPath);
2626
};
2727

28-
const validateAction = async (options: Parameters<typeof actions.validate>[0]): Promise<void> => {
29-
await actions.validate(options);
28+
const checkAction = async (options: Parameters<typeof actions.check>[0]): Promise<void> => {
29+
await actions.check(options);
3030
};
3131

3232
export function createProgram() {
@@ -40,26 +40,25 @@ export function createProgram() {
4040
.description(
4141
`${colors.bold.blue(
4242
'ζ',
43-
)} ZenStack is a database access toolkit for TypeScript apps.\n\nDocumentation: https://zenstack.dev.`,
43+
)} ZenStack is the data layer for modern TypeScript apps.\n\nDocumentation: https://zenstack.dev.`,
4444
)
4545
.showHelpAfterError()
4646
.showSuggestionAfterError();
4747

4848
const schemaOption = new Option(
4949
'--schema <file>',
50-
`schema file (with extension ${schemaExtensions}). Defaults to "schema.zmodel" unless specified in package.json.`,
50+
`schema file (with extension ${schemaExtensions}). Defaults to "zenstack/schema.zmodel" unless specified in package.json.`,
5151
);
5252

5353
program
5454
.command('generate')
55-
.description('Run code generation.')
55+
.description('Run code generation plugins.')
5656
.addOption(schemaOption)
57-
.addOption(new Option('--silent', 'do not print any output'))
58-
.addOption(new Option('-o, --output <path>', 'default output directory for core plugins'))
57+
.addOption(new Option('-o, --output <path>', 'default output directory for code generation'))
5958
.action(generateAction);
6059

61-
const migrateCommand = program.command('migrate').description('Update the database schema with migrations.');
62-
const migrationsOption = new Option('--migrations <path>', 'path for migrations');
60+
const migrateCommand = program.command('migrate').description('Run database schema migration related tasks.');
61+
const migrationsOption = new Option('--migrations <path>', 'path that contains the "migrations" directory');
6362

6463
migrateCommand
6564
.command('dev')
@@ -98,22 +97,22 @@ export function createProgram() {
9897
.addOption(migrationsOption)
9998
.addOption(new Option('--applied <migration>', 'record a specific migration as applied'))
10099
.addOption(new Option('--rolled-back <migration>', 'record a specific migration as rolled back'))
101-
.description('Resolve issues with database migrations in deployment databases')
100+
.description('Resolve issues with database migrations in deployment databases.')
102101
.action((options) => migrateAction('resolve', options));
103102

104103
const dbCommand = program.command('db').description('Manage your database schema during development.');
105104

106105
dbCommand
107106
.command('push')
108-
.description('Push the state from your schema to your database')
107+
.description('Push the state from your schema to your database.')
109108
.addOption(schemaOption)
110109
.addOption(new Option('--accept-data-loss', 'ignore data loss warnings'))
111110
.addOption(new Option('--force-reset', 'force a reset of the database before push'))
112111
.action((options) => dbAction('push', options));
113112

114113
program
115114
.command('info')
116-
.description('Get information of installed ZenStack and related packages.')
115+
.description('Get information of installed ZenStack packages.')
117116
.argument('[path]', 'project path', '.')
118117
.action(infoAction);
119118

@@ -123,7 +122,11 @@ export function createProgram() {
123122
.argument('[path]', 'project path', '.')
124123
.action(initAction);
125124

126-
program.command('validate').description('Validate a ZModel schema.').addOption(schemaOption).action(validateAction);
125+
program
126+
.command('check')
127+
.description('Check a ZModel schema for syntax or semantic errors.')
128+
.addOption(schemaOption)
129+
.action(checkAction);
127130

128131
return program;
129132
}

packages/cli/test/validate.test.ts renamed to packages/cli/test/check.test.ts

Lines changed: 6 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -40,29 +40,29 @@ describe('CLI validate command test', () => {
4040
const workDir = createProject(validModel);
4141

4242
// Should not throw an error
43-
expect(() => runCli('validate', workDir)).not.toThrow();
43+
expect(() => runCli('check', workDir)).not.toThrow();
4444
});
4545

4646
it('should fail validation for invalid schema', () => {
4747
const workDir = createProject(invalidModel);
4848

4949
// Should throw an error due to validation failure
50-
expect(() => runCli('validate', workDir)).toThrow();
50+
expect(() => runCli('check', workDir)).toThrow();
5151
});
5252

5353
it('should respect custom schema location', () => {
5454
const workDir = createProject(validModel);
5555
fs.renameSync(path.join(workDir, 'zenstack/schema.zmodel'), path.join(workDir, 'zenstack/custom.zmodel'));
5656

5757
// Should not throw an error when using custom schema path
58-
expect(() => runCli('validate --schema ./zenstack/custom.zmodel', workDir)).not.toThrow();
58+
expect(() => runCli('check --schema ./zenstack/custom.zmodel', workDir)).not.toThrow();
5959
});
6060

6161
it('should fail when schema file does not exist', () => {
6262
const workDir = createProject(validModel);
6363

6464
// Should throw an error when schema file doesn't exist
65-
expect(() => runCli('validate --schema ./nonexistent.zmodel', workDir)).toThrow();
65+
expect(() => runCli('check --schema ./nonexistent.zmodel', workDir)).toThrow();
6666
});
6767

6868
it('should respect package.json config', () => {
@@ -78,7 +78,7 @@ describe('CLI validate command test', () => {
7878
fs.writeFileSync(path.join(workDir, 'package.json'), JSON.stringify(pkgJson, null, 2));
7979

8080
// Should not throw an error when using package.json config
81-
expect(() => runCli('validate', workDir)).not.toThrow();
81+
expect(() => runCli('check', workDir)).not.toThrow();
8282
});
8383

8484
it('should validate schema with syntax errors', () => {
@@ -96,6 +96,6 @@ model User {
9696
const workDir = createProject(modelWithSyntaxError, false);
9797

9898
// Should throw an error due to syntax error
99-
expect(() => runCli('validate', workDir)).toThrow();
99+
expect(() => runCli('check', workDir)).toThrow();
100100
});
101101
});

packages/language/res/stdlib.zmodel

Lines changed: 6 additions & 75 deletions
Original file line numberDiff line numberDiff line change
@@ -424,73 +424,39 @@ attribute @@fulltext(_ fields: FieldReference[], map: String?) @@@prisma
424424

425425
// String type modifiers
426426

427-
enum MSSQLServerTypes {
428-
Max
429-
}
430-
431-
attribute @db.String(_ x: Int?) @@@targetField([StringField]) @@@prisma
432427
attribute @db.Text() @@@targetField([StringField]) @@@prisma
433-
attribute @db.NText() @@@targetField([StringField]) @@@prisma
434428
attribute @db.Char(_ x: Int?) @@@targetField([StringField]) @@@prisma
435-
attribute @db.NChar(_ x: Int?) @@@targetField([StringField]) @@@prisma
436429
attribute @db.VarChar(_ x: Any?) @@@targetField([StringField]) @@@prisma
437-
attribute @db.NVarChar(_ x: Any?) @@@targetField([StringField]) @@@prisma
438-
attribute @db.CatalogSingleChar() @@@targetField([StringField]) @@@prisma
439-
attribute @db.TinyText() @@@targetField([StringField]) @@@prisma
440-
attribute @db.MediumText() @@@targetField([StringField]) @@@prisma
441-
attribute @db.LongText() @@@targetField([StringField]) @@@prisma
442430
attribute @db.Bit(_ x: Int?) @@@targetField([StringField, BooleanField, BytesField]) @@@prisma
443431
attribute @db.VarBit(_ x: Int?) @@@targetField([StringField]) @@@prisma
444432
attribute @db.Uuid() @@@targetField([StringField]) @@@prisma
445-
attribute @db.UniqueIdentifier() @@@targetField([StringField]) @@@prisma
446433
attribute @db.Xml() @@@targetField([StringField]) @@@prisma
447434
attribute @db.Inet() @@@targetField([StringField]) @@@prisma
448435
attribute @db.Citext() @@@targetField([StringField]) @@@prisma
449436

450437
// Boolean type modifiers
451438

452439
attribute @db.Boolean() @@@targetField([BooleanField]) @@@prisma
453-
attribute @db.TinyInt(_ x: Int?) @@@targetField([BooleanField, IntField]) @@@prisma
454-
attribute @db.Bool() @@@targetField([BooleanField]) @@@prisma
455440

456441
// Int type modifiers
457442

458443
attribute @db.Int() @@@targetField([IntField]) @@@prisma
459444
attribute @db.Integer() @@@targetField([IntField]) @@@prisma
460445
attribute @db.SmallInt() @@@targetField([IntField]) @@@prisma
461446
attribute @db.Oid() @@@targetField([IntField]) @@@prisma
462-
attribute @db.UnsignedInt() @@@targetField([IntField]) @@@prisma
463-
attribute @db.UnsignedSmallInt() @@@targetField([IntField]) @@@prisma
464-
attribute @db.MediumInt() @@@targetField([IntField]) @@@prisma
465-
attribute @db.UnsignedMediumInt() @@@targetField([IntField]) @@@prisma
466-
attribute @db.UnsignedTinyInt() @@@targetField([IntField]) @@@prisma
467-
attribute @db.Year() @@@targetField([IntField]) @@@prisma
468-
attribute @db.Int4() @@@targetField([IntField]) @@@prisma
469-
attribute @db.Int2() @@@targetField([IntField]) @@@prisma
470447

471448
// BigInt type modifiers
472449

473450
attribute @db.BigInt() @@@targetField([BigIntField]) @@@prisma
474-
attribute @db.UnsignedBigInt() @@@targetField([BigIntField]) @@@prisma
475-
attribute @db.Int8() @@@targetField([BigIntField]) @@@prisma
476451

477452
// Float/Decimal type modifiers
478453
attribute @db.DoublePrecision() @@@targetField([FloatField, DecimalField]) @@@prisma
479454
attribute @db.Real() @@@targetField([FloatField, DecimalField]) @@@prisma
480-
attribute @db.Float() @@@targetField([FloatField, DecimalField]) @@@prisma
481455
attribute @db.Decimal(_ p: Int?, _ s: Int?) @@@targetField([FloatField, DecimalField]) @@@prisma
482-
attribute @db.Double() @@@targetField([FloatField, DecimalField]) @@@prisma
483456
attribute @db.Money() @@@targetField([FloatField, DecimalField]) @@@prisma
484-
attribute @db.SmallMoney() @@@targetField([FloatField, DecimalField]) @@@prisma
485-
attribute @db.Float8() @@@targetField([FloatField, DecimalField]) @@@prisma
486-
attribute @db.Float4() @@@targetField([FloatField, DecimalField]) @@@prisma
487457

488458
// DateTime type modifiers
489459

490-
attribute @db.DateTime(_ x: Int?) @@@targetField([DateTimeField]) @@@prisma
491-
attribute @db.DateTime2() @@@targetField([DateTimeField]) @@@prisma
492-
attribute @db.SmallDateTime() @@@targetField([DateTimeField]) @@@prisma
493-
attribute @db.DateTimeOffset() @@@targetField([DateTimeField]) @@@prisma
494460
attribute @db.Timestamp(_ x: Int?) @@@targetField([DateTimeField]) @@@prisma
495461
attribute @db.Timestamptz(_ x: Int?) @@@targetField([DateTimeField]) @@@prisma
496462
attribute @db.Date() @@@targetField([DateTimeField]) @@@prisma
@@ -504,49 +470,14 @@ attribute @db.JsonB() @@@targetField([JsonField]) @@@prisma
504470

505471
// Bytes type modifiers
506472

507-
attribute @db.Bytes() @@@targetField([BytesField]) @@@prisma
508473
attribute @db.ByteA() @@@targetField([BytesField]) @@@prisma
509-
attribute @db.LongBlob() @@@targetField([BytesField]) @@@prisma
510-
attribute @db.Binary() @@@targetField([BytesField]) @@@prisma
511-
attribute @db.VarBinary(_ x: Int?) @@@targetField([BytesField]) @@@prisma
512-
attribute @db.TinyBlob() @@@targetField([BytesField]) @@@prisma
513-
attribute @db.Blob() @@@targetField([BytesField]) @@@prisma
514-
attribute @db.MediumBlob() @@@targetField([BytesField]) @@@prisma
515-
attribute @db.Image() @@@targetField([BytesField]) @@@prisma
516-
517-
/**
518-
* Specifies the schema to use in a multi-schema database. https://www.prisma.io/docs/guides/database/multi-schema.
519-
*
520-
* @param: The name of the database schema.
521-
*/
522-
attribute @@schema(_ name: String) @@@prisma
523474

524-
/**
525-
* Indicates that the field is a password field and needs to be hashed before persistence.
526-
*
527-
* ZenStack uses `bcryptjs` library to hash password. You can use the `saltLength` parameter
528-
* to configure the cost of hashing, or use `salt` parameter to provide an explicit salt.
529-
* By default, salt length of 12 is used.
530-
*
531-
* @see https://www.npmjs.com/package/bcryptjs for details
532-
*
533-
* @param saltLength: length of salt to use (cost factor for the hash function)
534-
* @param salt: salt to use (a pregenerated valid salt)
535-
*/
536-
attribute @password(saltLength: Int?, salt: String?) @@@targetField([StringField])
537-
538-
539-
/**
540-
* Indicates that the field is encrypted when storing in the DB and should be decrypted when read
541-
*
542-
* ZenStack uses the Web Crypto API to encrypt and decrypt the field.
543-
*/
544-
attribute @encrypted() @@@targetField([StringField])
545-
546-
/**
547-
* Indicates that the field should be omitted when read from the generated services.
548-
*/
549-
attribute @omit()
475+
// /**
476+
// * Specifies the schema to use in a multi-schema database. https://www.prisma.io/docs/guides/database/multi-schema.
477+
// *
478+
// * @param: The name of the database schema.
479+
// */
480+
// attribute @@schema(_ name: String) @@@prisma
550481

551482
//////////////////////////////////////////////
552483
// Begin validation attributes and functions

packages/runtime/src/client/client-impl.ts

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -35,7 +35,7 @@ import type { ToKysely } from './query-builder';
3535
import { ResultProcessor } from './result-processor';
3636

3737
/**
38-
* ZenStack client.
38+
* ZenStack ORM client.
3939
*/
4040
export const ZenStackClient = function <Schema extends SchemaDef>(
4141
this: any,

packages/runtime/src/client/crud/operations/base.ts

Lines changed: 1 addition & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -11,7 +11,6 @@ import {
1111
type SelectQueryBuilder,
1212
} from 'kysely';
1313
import { nanoid } from 'nanoid';
14-
import { inspect } from 'node:util';
1514
import { match } from 'ts-pattern';
1615
import { ulid } from 'ulid';
1716
import * as uuid from 'uuid';
@@ -175,10 +174,7 @@ export abstract class BaseOperationHandler<Schema extends SchemaDef> {
175174
const r = await kysely.getExecutor().executeQuery(compiled, queryId);
176175
result = r.rows;
177176
} catch (err) {
178-
let message = `Failed to execute query: ${err}, sql: ${compiled.sql}`;
179-
if (this.options.debug) {
180-
message += `, parameters: \n${compiled.parameters.map((p) => inspect(p)).join('\n')}`;
181-
}
177+
const message = `Failed to execute query: ${err}, sql: ${compiled.sql}`;
182178
throw new QueryError(message, err);
183179
}
184180

packages/runtime/src/client/executor/zenstack-query-executor.ts

Lines changed: 1 addition & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -20,7 +20,6 @@ import {
2020
type TableNode,
2121
} from 'kysely';
2222
import { nanoid } from 'nanoid';
23-
import { inspect } from 'node:util';
2423
import { match } from 'ts-pattern';
2524
import type { GetModels, SchemaDef } from '../../schema';
2625
import { type ClientImpl } from '../client-impl';
@@ -160,10 +159,7 @@ export class ZenStackQueryExecutor<Schema extends SchemaDef> extends DefaultQuer
160159
return { result, connection };
161160
});
162161
} catch (err) {
163-
let message = `Failed to execute query: ${err}, sql: ${compiled.sql}`;
164-
if (this.options.debug) {
165-
message += `, parameters: \n${compiled.parameters.map((p) => inspect(p)).join('\n')}`;
166-
}
162+
const message = `Failed to execute query: ${err}, sql: ${compiled.sql}`;
167163
throw new QueryError(message, err);
168164
}
169165
}

packages/runtime/src/client/options.ts

Lines changed: 0 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -41,11 +41,6 @@ export type ClientOptions<Schema extends SchemaDef> = {
4141
* Logging configuration.
4242
*/
4343
log?: KyselyConfig['log'];
44-
45-
/**
46-
* Debug mode.
47-
*/
48-
debug?: boolean;
4944
} & (HasComputedFields<Schema> extends true
5045
? {
5146
/**

0 commit comments

Comments
 (0)