Skip to content

Commit 59fe945

Browse files
authored
merge dev to main (v2.8.0) (#1827)
2 parents 9eb241f + 13f95d2 commit 59fe945

File tree

75 files changed

+2650
-549
lines changed

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

75 files changed

+2650
-549
lines changed

README.md

Lines changed: 13 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -158,15 +158,15 @@ The following diagram gives a high-level architecture overview of ZenStack.
158158
### Plugins
159159

160160
- Prisma schema generator
161-
- Zod schema generator
161+
- [Zod](https://zod.dev/) schema generator
162162
- [SWR](https://github.com/vercel/swr) and [TanStack Query](https://github.com/TanStack/query) hooks generator
163163
- OpenAPI specification generator
164164
- [tRPC](https://trpc.io) router generator
165165
- 🙋🏻 [Request for a plugin](https://discord.gg/Ykhr738dUe)
166166

167167
### Framework adapters
168168

169-
- [Next.js](https://zenstack.dev/docs/reference/server-adapters/next) (including support for the new "app directory" in Next.js 13)
169+
- [Next.js](https://zenstack.dev/docs/reference/server-adapters/next)
170170
- [Nuxt](https://zenstack.dev/docs/reference/server-adapters/nuxt)
171171
- [SvelteKit](https://zenstack.dev/docs/reference/server-adapters/sveltekit)
172172
- [Fastify](https://zenstack.dev/docs/reference/server-adapters/fastify)
@@ -180,7 +180,7 @@ The following diagram gives a high-level architecture overview of ZenStack.
180180
- [Custom attributes and functions](https://zenstack.dev/docs/reference/zmodel-language#custom-attributes-and-functions)
181181
- [Multi-file schema and model inheritance](https://zenstack.dev/docs/guides/multiple-schema)
182182
- [Polymorphic Relations](https://zenstack.dev/docs/guides/polymorphism)
183-
- Strong-typed JSON field (coming soon)
183+
- [Strongly typed JSON field](https://zenstack.dev/docs/guides/typing-json)
184184
- 🙋🏻 [Request for an extension](https://discord.gg/Ykhr738dUe)
185185

186186
## Examples
@@ -200,19 +200,19 @@ You can use [this blog post](https://zenstack.dev/blog/model-authz) as an introd
200200

201201
Check out the [Multi-tenant Todo App](https://zenstack-todo.vercel.app/) for a running example. You can find different implementations below:
202202

203-
- [Next.js 13 + NextAuth + SWR](https://github.com/zenstackhq/sample-todo-nextjs)
204-
- [Next.js 13 + NextAuth + TanStack Query](https://github.com/zenstackhq/sample-todo-nextjs-tanstack)
205-
- [Next.js 13 + NextAuth + tRPC](https://github.com/zenstackhq/sample-todo-trpc)
206-
- [Nuxt V3 + TanStack Query](https://github.com/zenstackhq/sample-todo-nuxt)
203+
- [Next.js + NextAuth + TanStack Query](https://github.com/zenstackhq/sample-todo-nextjs-tanstack)
204+
- [Next.js + NextAuth + SWR](https://github.com/zenstackhq/sample-todo-nextjs)
205+
- [Next.js + NextAuth + tRPC](https://github.com/zenstackhq/sample-todo-trpc)
206+
- [Nuxt + TanStack Query](https://github.com/zenstackhq/sample-todo-nuxt)
207207
- [SvelteKit + TanStack Query](https://github.com/zenstackhq/sample-todo-sveltekit)
208208
- [RedwoodJS](https://github.com/zenstackhq/sample-todo-redwood)
209209

210210
### Blog App
211211

212-
- [Next.js 13 + Pages Route + SWR](https://github.com/zenstackhq/docs-tutorial-nextjs)
213-
- [Next.js 13 + App Route + ReactQuery](https://github.com/zenstackhq/docs-tutorial-nextjs-app-dir)
214-
- [Next.js 13 + App Route + tRPC](https://github.com/zenstackhq/sample-blog-nextjs-app-trpc)
215-
- [Nuxt V3 + TanStack Query](https://github.com/zenstackhq/docs-tutorial-nuxt)
212+
- [Next.js + App Route + TanStack Query](https://github.com/zenstackhq/docs-tutorial-nextjs-app-dir)
213+
- [Next.js + Pages Route + SWR](https://github.com/zenstackhq/docs-tutorial-nextjs)
214+
- [Next.js + App Route + tRPC](https://github.com/zenstackhq/sample-blog-nextjs-app-trpc)
215+
- [Nuxt + TanStack Query](https://github.com/zenstackhq/docs-tutorial-nuxt)
216216
- [SvelteKit](https://github.com/zenstackhq/docs-tutorial-sveltekit)
217217
- [Remix](https://github.com/zenstackhq/docs-tutorial-remix)
218218
- [NestJS Backend API](https://github.com/zenstackhq/docs-tutorial-nestjs)
@@ -225,7 +225,7 @@ Join our [discord server](https://discord.gg/Ykhr738dUe) for chat and updates!
225225

226226
## Contributing
227227

228-
If you like ZenStack, join us to make it a better tool! Please use the [Contributing Guide](CONTRIBUTING.md) for details on how to get started, and don't hesitate to join [Discord](https://discord.gg/Ykhr738dUe) to share your thoughts.
228+
If you like ZenStack, join us to make it a better tool! Please use the [Contributing Guide](CONTRIBUTING.md) for details on how to get started, and don't hesitate to join [Discord](https://discord.gg/Ykhr738dUe) to share your thoughts. Documentations reside in a separate repo: [zenstack-docs](https://github.com/zenstackhq/zenstack-docs).
229229

230230
Please also consider [sponsoring our work](https://github.com/sponsors/zenstackhq) to speed up the development. Your contribution will be 100% used as a bounty reward to encourage community members to help fix bugs, add features, and improve documentation.
231231

@@ -241,14 +241,14 @@ Thank you for your generous support!
241241
<td align="center"><a href="https://www.mermaidchart.com/"><img src="https://avatars.githubusercontent.com/u/117662492?s=200&v=4" width="100" style="border-radius:50%" alt="Mermaid Chart"/><br />Mermaid Chart</a></td>
242242
<td align="center"><a href="https://coderabbit.ai/"><img src="https://avatars.githubusercontent.com/u/132028505?v=4" width="100" style="border-radius:50%" alt="CodeRabbit"/><br />CodeRabbit</a></td>
243243
<td align="center"><a href="https://github.com/j0hannr"><img src="https://avatars.githubusercontent.com/u/52762073?v=4" width="100" style="border-radius:50%" alt="Johann Rohn"/><br />Johann Rohn</a></td>
244-
<td align="center"><a href="https://github.com/baenie"><img src="https://avatars.githubusercontent.com/u/58309104?v=4" width="100" style="border-radius:50%" alt="Benjamin Zecirovic"/><br />Benjamin Zecirovic</a></td>
245244
</tr>
246245
</table>
247246

248247
### Previous Sponsors
249248

250249
<table>
251250
<tr>
251+
<td align="center"><a href="https://github.com/baenie"><img src="https://avatars.githubusercontent.com/u/58309104?v=4" width="100" style="border-radius:50%" alt="Benjamin Zecirovic"/><br />Benjamin Zecirovic</a></td>
252252
<td align="center"><a href="https://github.com/umussetu"><img src="https://avatars.githubusercontent.com/u/152648499?v=4" width="100" style="border-radius:50%" alt="Ulric"/><br />Ulric</a></td>
253253
<td align="center"><a href="https://github.com/iamfj"><img src="https://avatars.githubusercontent.com/u/24557998?v=4" width="100" style="border-radius:50%" alt="Fabian Jocks"/><br />Fabian Jocks</a></td>
254254
</tr>

package.json

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
{
22
"name": "zenstack-monorepo",
3-
"version": "2.7.5",
3+
"version": "2.8.0",
44
"description": "",
55
"scripts": {
66
"build": "pnpm -r build",

packages/ide/jetbrains/CHANGELOG.md

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -2,6 +2,12 @@
22

33
## [Unreleased]
44

5+
### Added
6+
7+
- Type declaration support.
8+
9+
## 2.7.0
10+
511
### Fixed
612

713
- ZModel validation issues importing zmodel files from npm packages.

packages/ide/jetbrains/build.gradle.kts

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -9,7 +9,7 @@ plugins {
99
}
1010

1111
group = "dev.zenstack"
12-
version = "2.7.5"
12+
version = "2.8.0"
1313

1414
repositories {
1515
mavenCentral()

packages/ide/jetbrains/package.json

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
{
22
"name": "jetbrains",
3-
"version": "2.7.5",
3+
"version": "2.8.0",
44
"displayName": "ZenStack JetBrains IDE Plugin",
55
"description": "ZenStack JetBrains IDE plugin",
66
"homepage": "https://zenstack.dev",

packages/language/package.json

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
{
22
"name": "@zenstackhq/language",
3-
"version": "2.7.5",
3+
"version": "2.8.0",
44
"displayName": "ZenStack modeling language compiler",
55
"description": "ZenStack modeling language compiler",
66
"homepage": "https://zenstack.dev",

packages/language/src/generated/ast.ts

Lines changed: 85 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -20,7 +20,7 @@ export const ZModelTerminals = {
2020
SL_COMMENT: /\/\/[^\n\r]*/,
2121
};
2222

23-
export type AbstractDeclaration = Attribute | DataModel | DataSource | Enum | FunctionDecl | GeneratorDecl | Plugin;
23+
export type AbstractDeclaration = Attribute | DataModel | DataSource | Enum | FunctionDecl | GeneratorDecl | Plugin | TypeDef;
2424

2525
export const AbstractDeclaration = 'AbstractDeclaration';
2626

@@ -78,10 +78,10 @@ export function isReferenceTarget(item: unknown): item is ReferenceTarget {
7878
return reflection.isInstance(item, ReferenceTarget);
7979
}
8080

81-
export type RegularID = 'abstract' | 'attribute' | 'datasource' | 'enum' | 'import' | 'in' | 'model' | 'plugin' | 'view' | string;
81+
export type RegularID = 'abstract' | 'attribute' | 'datasource' | 'enum' | 'import' | 'in' | 'model' | 'plugin' | 'type' | 'view' | string;
8282

8383
export function isRegularID(item: unknown): item is RegularID {
84-
return item === 'model' || item === 'enum' || item === 'attribute' || item === 'datasource' || item === 'plugin' || item === 'abstract' || item === 'in' || item === 'view' || item === 'import' || (typeof item === 'string' && (/[_a-zA-Z][\w_]*/.test(item)));
84+
return item === 'model' || item === 'enum' || item === 'attribute' || item === 'datasource' || item === 'plugin' || item === 'abstract' || item === 'in' || item === 'view' || item === 'import' || item === 'type' || (typeof item === 'string' && (/[_a-zA-Z][\w_]*/.test(item)));
8585
}
8686

8787
export type RegularIDWithTypeNames = 'Any' | 'BigInt' | 'Boolean' | 'Bytes' | 'DateTime' | 'Decimal' | 'Float' | 'Int' | 'Json' | 'Null' | 'Object' | 'String' | 'Unsupported' | RegularID;
@@ -90,7 +90,7 @@ export function isRegularIDWithTypeNames(item: unknown): item is RegularIDWithTy
9090
return isRegularID(item) || item === 'String' || item === 'Boolean' || item === 'Int' || item === 'BigInt' || item === 'Float' || item === 'Decimal' || item === 'DateTime' || item === 'Json' || item === 'Bytes' || item === 'Null' || item === 'Object' || item === 'Any' || item === 'Unsupported';
9191
}
9292

93-
export type TypeDeclaration = DataModel | Enum;
93+
export type TypeDeclaration = DataModel | Enum | TypeDef;
9494

9595
export const TypeDeclaration = 'TypeDeclaration';
9696

@@ -305,7 +305,7 @@ export function isDataModelField(item: unknown): item is DataModelField {
305305
}
306306

307307
export interface DataModelFieldAttribute extends AstNode {
308-
readonly $container: DataModelField | EnumField;
308+
readonly $container: DataModelField | EnumField | TypeDefField;
309309
readonly $type: 'DataModelFieldAttribute';
310310
args: Array<AttributeArg>
311311
decl: Reference<Attribute>
@@ -620,6 +620,50 @@ export function isThisExpr(item: unknown): item is ThisExpr {
620620
return reflection.isInstance(item, ThisExpr);
621621
}
622622

623+
export interface TypeDef extends AstNode {
624+
readonly $container: Model;
625+
readonly $type: 'TypeDef';
626+
comments: Array<string>
627+
fields: Array<TypeDefField>
628+
name: RegularID
629+
}
630+
631+
export const TypeDef = 'TypeDef';
632+
633+
export function isTypeDef(item: unknown): item is TypeDef {
634+
return reflection.isInstance(item, TypeDef);
635+
}
636+
637+
export interface TypeDefField extends AstNode {
638+
readonly $container: TypeDef;
639+
readonly $type: 'TypeDefField';
640+
attributes: Array<DataModelFieldAttribute>
641+
comments: Array<string>
642+
name: RegularIDWithTypeNames
643+
type: TypeDefFieldType
644+
}
645+
646+
export const TypeDefField = 'TypeDefField';
647+
648+
export function isTypeDefField(item: unknown): item is TypeDefField {
649+
return reflection.isInstance(item, TypeDefField);
650+
}
651+
652+
export interface TypeDefFieldType extends AstNode {
653+
readonly $container: TypeDefField;
654+
readonly $type: 'TypeDefFieldType';
655+
array: boolean
656+
optional: boolean
657+
reference?: Reference<TypeDef>
658+
type?: BuiltinType
659+
}
660+
661+
export const TypeDefFieldType = 'TypeDefFieldType';
662+
663+
export function isTypeDefFieldType(item: unknown): item is TypeDefFieldType {
664+
return reflection.isInstance(item, TypeDefFieldType);
665+
}
666+
623667
export interface UnaryExpr extends AstNode {
624668
readonly $container: Argument | ArrayExpr | AttributeArg | BinaryExpr | ConfigArrayExpr | ConfigField | ConfigInvocationArg | FieldInitializer | FunctionDecl | MemberAccessExpr | PluginField | ReferenceArg | UnaryExpr | UnsupportedFieldType;
625669
readonly $type: 'UnaryExpr';
@@ -691,14 +735,17 @@ export type ZModelAstType = {
691735
StringLiteral: StringLiteral
692736
ThisExpr: ThisExpr
693737
TypeDeclaration: TypeDeclaration
738+
TypeDef: TypeDef
739+
TypeDefField: TypeDefField
740+
TypeDefFieldType: TypeDefFieldType
694741
UnaryExpr: UnaryExpr
695742
UnsupportedFieldType: UnsupportedFieldType
696743
}
697744

698745
export class ZModelAstReflection extends AbstractAstReflection {
699746

700747
getAllTypes(): string[] {
701-
return ['AbstractDeclaration', 'Argument', 'ArrayExpr', 'Attribute', 'AttributeArg', 'AttributeParam', 'AttributeParamType', 'BinaryExpr', 'BooleanLiteral', 'ConfigArrayExpr', 'ConfigExpr', 'ConfigField', 'ConfigInvocationArg', 'ConfigInvocationExpr', 'DataModel', 'DataModelAttribute', 'DataModelField', 'DataModelFieldAttribute', 'DataModelFieldType', 'DataSource', 'Enum', 'EnumField', 'Expression', 'FieldInitializer', 'FunctionDecl', 'FunctionParam', 'FunctionParamType', 'GeneratorDecl', 'InternalAttribute', 'InvocationExpr', 'LiteralExpr', 'MemberAccessExpr', 'Model', 'ModelImport', 'NullExpr', 'NumberLiteral', 'ObjectExpr', 'Plugin', 'PluginField', 'ReferenceArg', 'ReferenceExpr', 'ReferenceTarget', 'StringLiteral', 'ThisExpr', 'TypeDeclaration', 'UnaryExpr', 'UnsupportedFieldType'];
748+
return ['AbstractDeclaration', 'Argument', 'ArrayExpr', 'Attribute', 'AttributeArg', 'AttributeParam', 'AttributeParamType', 'BinaryExpr', 'BooleanLiteral', 'ConfigArrayExpr', 'ConfigExpr', 'ConfigField', 'ConfigInvocationArg', 'ConfigInvocationExpr', 'DataModel', 'DataModelAttribute', 'DataModelField', 'DataModelFieldAttribute', 'DataModelFieldType', 'DataSource', 'Enum', 'EnumField', 'Expression', 'FieldInitializer', 'FunctionDecl', 'FunctionParam', 'FunctionParamType', 'GeneratorDecl', 'InternalAttribute', 'InvocationExpr', 'LiteralExpr', 'MemberAccessExpr', 'Model', 'ModelImport', 'NullExpr', 'NumberLiteral', 'ObjectExpr', 'Plugin', 'PluginField', 'ReferenceArg', 'ReferenceExpr', 'ReferenceTarget', 'StringLiteral', 'ThisExpr', 'TypeDeclaration', 'TypeDef', 'TypeDefField', 'TypeDefFieldType', 'UnaryExpr', 'UnsupportedFieldType'];
702749
}
703750

704751
protected override computeIsSubtype(subtype: string, supertype: string): boolean {
@@ -729,7 +776,8 @@ export class ZModelAstReflection extends AbstractAstReflection {
729776
return this.isSubtype(ConfigExpr, supertype);
730777
}
731778
case DataModel:
732-
case Enum: {
779+
case Enum:
780+
case TypeDef: {
733781
return this.isSubtype(AbstractDeclaration, supertype) || this.isSubtype(TypeDeclaration, supertype);
734782
}
735783
case DataModelField:
@@ -772,6 +820,9 @@ export class ZModelAstReflection extends AbstractAstReflection {
772820
case 'ReferenceExpr:target': {
773821
return ReferenceTarget;
774822
}
823+
case 'TypeDefFieldType:reference': {
824+
return TypeDef;
825+
}
775826
default: {
776827
throw new Error(`${referenceId} is not a valid reference id.`);
777828
}
@@ -989,6 +1040,33 @@ export class ZModelAstReflection extends AbstractAstReflection {
9891040
]
9901041
};
9911042
}
1043+
case 'TypeDef': {
1044+
return {
1045+
name: 'TypeDef',
1046+
mandatory: [
1047+
{ name: 'comments', type: 'array' },
1048+
{ name: 'fields', type: 'array' }
1049+
]
1050+
};
1051+
}
1052+
case 'TypeDefField': {
1053+
return {
1054+
name: 'TypeDefField',
1055+
mandatory: [
1056+
{ name: 'attributes', type: 'array' },
1057+
{ name: 'comments', type: 'array' }
1058+
]
1059+
};
1060+
}
1061+
case 'TypeDefFieldType': {
1062+
return {
1063+
name: 'TypeDefFieldType',
1064+
mandatory: [
1065+
{ name: 'array', type: 'boolean' },
1066+
{ name: 'optional', type: 'boolean' }
1067+
]
1068+
};
1069+
}
9921070
default: {
9931071
return {
9941072
name: type,

0 commit comments

Comments
 (0)