Skip to content

Commit

Permalink
merge dev to main (v2.8.0) (#1827)
Browse files Browse the repository at this point in the history
  • Loading branch information
ymc9 authored Nov 6, 2024
2 parents 9eb241f + 13f95d2 commit 59fe945
Show file tree
Hide file tree
Showing 75 changed files with 2,650 additions and 549 deletions.
26 changes: 13 additions & 13 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -158,15 +158,15 @@ The following diagram gives a high-level architecture overview of ZenStack.
### Plugins

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

### Framework adapters

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

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

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

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

### Blog App

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

## Contributing

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.
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).

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.

Expand All @@ -241,14 +241,14 @@ Thank you for your generous support!
<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>
<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>
<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>
<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>
</tr>
</table>

### Previous Sponsors

<table>
<tr>
<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>
<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>
<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>
</tr>
Expand Down
2 changes: 1 addition & 1 deletion package.json
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
{
"name": "zenstack-monorepo",
"version": "2.7.5",
"version": "2.8.0",
"description": "",
"scripts": {
"build": "pnpm -r build",
Expand Down
6 changes: 6 additions & 0 deletions packages/ide/jetbrains/CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,12 @@

## [Unreleased]

### Added

- Type declaration support.

## 2.7.0

### Fixed

- ZModel validation issues importing zmodel files from npm packages.
Expand Down
2 changes: 1 addition & 1 deletion packages/ide/jetbrains/build.gradle.kts
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,7 @@ plugins {
}

group = "dev.zenstack"
version = "2.7.5"
version = "2.8.0"

repositories {
mavenCentral()
Expand Down
2 changes: 1 addition & 1 deletion packages/ide/jetbrains/package.json
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
{
"name": "jetbrains",
"version": "2.7.5",
"version": "2.8.0",
"displayName": "ZenStack JetBrains IDE Plugin",
"description": "ZenStack JetBrains IDE plugin",
"homepage": "https://zenstack.dev",
Expand Down
2 changes: 1 addition & 1 deletion packages/language/package.json
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
{
"name": "@zenstackhq/language",
"version": "2.7.5",
"version": "2.8.0",
"displayName": "ZenStack modeling language compiler",
"description": "ZenStack modeling language compiler",
"homepage": "https://zenstack.dev",
Expand Down
92 changes: 85 additions & 7 deletions packages/language/src/generated/ast.ts
Original file line number Diff line number Diff line change
Expand Up @@ -20,7 +20,7 @@ export const ZModelTerminals = {
SL_COMMENT: /\/\/[^\n\r]*/,
};

export type AbstractDeclaration = Attribute | DataModel | DataSource | Enum | FunctionDecl | GeneratorDecl | Plugin;
export type AbstractDeclaration = Attribute | DataModel | DataSource | Enum | FunctionDecl | GeneratorDecl | Plugin | TypeDef;

export const AbstractDeclaration = 'AbstractDeclaration';

Expand Down Expand Up @@ -78,10 +78,10 @@ export function isReferenceTarget(item: unknown): item is ReferenceTarget {
return reflection.isInstance(item, ReferenceTarget);
}

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

export function isRegularID(item: unknown): item is RegularID {
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)));
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)));
}

export type RegularIDWithTypeNames = 'Any' | 'BigInt' | 'Boolean' | 'Bytes' | 'DateTime' | 'Decimal' | 'Float' | 'Int' | 'Json' | 'Null' | 'Object' | 'String' | 'Unsupported' | RegularID;
Expand All @@ -90,7 +90,7 @@ export function isRegularIDWithTypeNames(item: unknown): item is RegularIDWithTy
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';
}

export type TypeDeclaration = DataModel | Enum;
export type TypeDeclaration = DataModel | Enum | TypeDef;

export const TypeDeclaration = 'TypeDeclaration';

Expand Down Expand Up @@ -305,7 +305,7 @@ export function isDataModelField(item: unknown): item is DataModelField {
}

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

export interface TypeDef extends AstNode {
readonly $container: Model;
readonly $type: 'TypeDef';
comments: Array<string>
fields: Array<TypeDefField>
name: RegularID
}

export const TypeDef = 'TypeDef';

export function isTypeDef(item: unknown): item is TypeDef {
return reflection.isInstance(item, TypeDef);
}

export interface TypeDefField extends AstNode {
readonly $container: TypeDef;
readonly $type: 'TypeDefField';
attributes: Array<DataModelFieldAttribute>
comments: Array<string>
name: RegularIDWithTypeNames
type: TypeDefFieldType
}

export const TypeDefField = 'TypeDefField';

export function isTypeDefField(item: unknown): item is TypeDefField {
return reflection.isInstance(item, TypeDefField);
}

export interface TypeDefFieldType extends AstNode {
readonly $container: TypeDefField;
readonly $type: 'TypeDefFieldType';
array: boolean
optional: boolean
reference?: Reference<TypeDef>
type?: BuiltinType
}

export const TypeDefFieldType = 'TypeDefFieldType';

export function isTypeDefFieldType(item: unknown): item is TypeDefFieldType {
return reflection.isInstance(item, TypeDefFieldType);
}

export interface UnaryExpr extends AstNode {
readonly $container: Argument | ArrayExpr | AttributeArg | BinaryExpr | ConfigArrayExpr | ConfigField | ConfigInvocationArg | FieldInitializer | FunctionDecl | MemberAccessExpr | PluginField | ReferenceArg | UnaryExpr | UnsupportedFieldType;
readonly $type: 'UnaryExpr';
Expand Down Expand Up @@ -691,14 +735,17 @@ export type ZModelAstType = {
StringLiteral: StringLiteral
ThisExpr: ThisExpr
TypeDeclaration: TypeDeclaration
TypeDef: TypeDef
TypeDefField: TypeDefField
TypeDefFieldType: TypeDefFieldType
UnaryExpr: UnaryExpr
UnsupportedFieldType: UnsupportedFieldType
}

export class ZModelAstReflection extends AbstractAstReflection {

getAllTypes(): string[] {
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'];
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'];
}

protected override computeIsSubtype(subtype: string, supertype: string): boolean {
Expand Down Expand Up @@ -729,7 +776,8 @@ export class ZModelAstReflection extends AbstractAstReflection {
return this.isSubtype(ConfigExpr, supertype);
}
case DataModel:
case Enum: {
case Enum:
case TypeDef: {
return this.isSubtype(AbstractDeclaration, supertype) || this.isSubtype(TypeDeclaration, supertype);
}
case DataModelField:
Expand Down Expand Up @@ -772,6 +820,9 @@ export class ZModelAstReflection extends AbstractAstReflection {
case 'ReferenceExpr:target': {
return ReferenceTarget;
}
case 'TypeDefFieldType:reference': {
return TypeDef;
}
default: {
throw new Error(`${referenceId} is not a valid reference id.`);
}
Expand Down Expand Up @@ -989,6 +1040,33 @@ export class ZModelAstReflection extends AbstractAstReflection {
]
};
}
case 'TypeDef': {
return {
name: 'TypeDef',
mandatory: [
{ name: 'comments', type: 'array' },
{ name: 'fields', type: 'array' }
]
};
}
case 'TypeDefField': {
return {
name: 'TypeDefField',
mandatory: [
{ name: 'attributes', type: 'array' },
{ name: 'comments', type: 'array' }
]
};
}
case 'TypeDefFieldType': {
return {
name: 'TypeDefFieldType',
mandatory: [
{ name: 'array', type: 'boolean' },
{ name: 'optional', type: 'boolean' }
]
};
}
default: {
return {
name: type,
Expand Down
Loading

0 comments on commit 59fe945

Please sign in to comment.