Skip to content

merge dev to main (v2.8.0) #1827

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 21 commits into from
Nov 6, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
Show all changes
21 commits
Select commit Hold shift + click to select a range
fac631b
fix(delegate): discriminator fields should be removed from unchecked …
ymc9 Oct 24, 2024
b8c84a5
🐞 fix (server): support for awaiting next.js 15 params (#1805)
AmruthPillai Oct 24, 2024
efc9da2
chore: bump version (#1807)
ymc9 Oct 25, 2024
c344f77
Improve working with entities related to entities that uses compound …
thomassnielsen Oct 25, 2024
35ea74f
Fix for filtering by compound id (#1806)
thomassnielsen Oct 25, 2024
28b130f
fix(server): change nextjs adapter's context params to be Promise to …
ymc9 Oct 25, 2024
77817f5
chore: bump version (#1814)
ymc9 Oct 29, 2024
d223819
fix(zmodel): prefer to use triple-slash comments as ZModel documentat…
ymc9 Oct 30, 2024
daa3839
fix(delegate): delegate model shouldn't inherit `@@index` from an ind…
ymc9 Oct 30, 2024
be28f2e
fix: support `check()` policy function call in permission checkers (#…
ymc9 Oct 30, 2024
2bb8970
fix(delegate): self relation support (#1821)
ymc9 Oct 31, 2024
00ecb2a
fix(hooks): add null check to data before further deserialization (#1…
ymc9 Oct 31, 2024
d985a73
feat(repl): add CLI option to specify custom zenstack load path (#1823)
ymc9 Nov 1, 2024
f16225c
fix(delegate): orderBy with base field doesn't work when the clause i…
ymc9 Nov 1, 2024
3b18362
Merge remote-tracking branch 'origin/main' into dev
ymc9 Nov 3, 2024
00ccb73
feat(zmodel): "type" construct and strongly-typed Json fields (#1813)
ymc9 Nov 4, 2024
ef6d529
chore: README and JetBrains changelog update (#1828)
ymc9 Nov 4, 2024
e19a377
chore: Prisma 5.22 support (#1829)
ymc9 Nov 5, 2024
5f15fe0
chore: remove commented code (#1830)
ymc9 Nov 6, 2024
9cc01d5
chore: type coverage test (#1831)
ymc9 Nov 6, 2024
13f95d2
fix: missing arg passing to recursion (#1832)
ymc9 Nov 6, 2024
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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
Loading