Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
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
3 changes: 2 additions & 1 deletion README.md
Original file line number Diff line number Diff line change
Expand Up @@ -158,10 +158,10 @@ The following diagram gives a high-level architecture overview of ZenStack.
### Framework adapters

- [Next.js](https://zenstack.dev/docs/reference/server-adapters/next) (including support for the new "app directory" in Next.js 13)
- [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)
- [ExpressJS](https://zenstack.dev/docs/reference/server-adapters/express)
- Nuxt.js (Future)
- 🙋🏻 [Request for an adapter](https://go.zenstack.dev/chat)

### Prisma schema extensions
Expand All @@ -179,6 +179,7 @@ Check out the [Collaborative Todo App](https://zenstack-todo.vercel.app/) for a
- [Next.js + SWR hooks](https://github.com/zenstackhq/sample-todo-nextjs)
- [Next.js + TanStack Query](https://github.com/zenstackhq/sample-todo-nextjs-tanstack)
- [Next.js + 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)

## Community
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": "1.0.2",
"version": "1.1.0",
"description": "",
"scripts": {
"build": "pnpm -r build",
Expand Down
17 changes: 16 additions & 1 deletion packages/language/package.json
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
{
"name": "@zenstackhq/language",
"version": "1.0.2",
"version": "1.1.0",
"displayName": "ZenStack modeling language compiler",
"description": "ZenStack modeling language compiler",
"homepage": "https://zenstack.dev",
Expand Down Expand Up @@ -28,5 +28,20 @@
},
"dependencies": {
"langium": "1.2.0"
},
"contributes": {
"languages": [
{
"id": "zmodel",
"extensions": [".zmodel"]
}
],
"grammars": [
{
"language": "zmodel",
"scopeName": "source.zmodel",
"path": "./syntaxes/zmodel.tmLanguage.json"
}
]
}
}
6 changes: 3 additions & 3 deletions packages/language/src/generated/ast.ts
Original file line number Diff line number Diff line change
Expand Up @@ -94,10 +94,10 @@ export function isReferenceTarget(item: unknown): item is ReferenceTarget {
return reflection.isInstance(item, ReferenceTarget);
}

export type RegularID = 'abstract' | 'attribute' | 'datasource' | 'enum' | 'in' | 'model' | 'plugin' | 'sort' | string;
export type RegularID = 'abstract' | 'attribute' | 'datasource' | 'enum' | 'import' | 'in' | 'model' | 'plugin' | 'sort' | '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 === 'sort' || (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 === 'sort' || item === 'view' || item === 'import' || (typeof item === 'string' && (/[_a-zA-Z][\w_]*/.test(item)));
}

export type TypeDeclaration = DataModel | Enum;
Expand Down Expand Up @@ -386,7 +386,7 @@ export function isEnumField(item: unknown): item is EnumField {
export interface FieldInitializer extends AstNode {
readonly $container: ObjectExpr;
readonly $type: 'FieldInitializer';
name: RegularID
name: RegularID | string
value: Expression
}

Expand Down
32 changes: 26 additions & 6 deletions packages/language/src/generated/grammar.ts
Original file line number Diff line number Diff line change
Expand Up @@ -1171,11 +1171,23 @@ export const ZModelGrammar = (): Grammar => loadedZModelGrammar ?? (loadedZModel
"feature": "name",
"operator": "=",
"terminal": {
"$type": "RuleCall",
"rule": {
"$ref": "#/rules@47"
},
"arguments": []
"$type": "Alternatives",
"elements": [
{
"$type": "RuleCall",
"rule": {
"$ref": "#/rules@47"
},
"arguments": []
},
{
"$type": "RuleCall",
"rule": {
"$ref": "#/rules@67"
},
"arguments": []
}
]
}
},
{
Expand Down Expand Up @@ -2060,7 +2072,7 @@ export const ZModelGrammar = (): Grammar => loadedZModelGrammar ?? (loadedZModel
}
}
],
"cardinality": "+"
"cardinality": "*"
},
{
"$type": "Keyword",
Expand Down Expand Up @@ -2771,6 +2783,14 @@ export const ZModelGrammar = (): Grammar => loadedZModelGrammar ?? (loadedZModel
{
"$type": "Keyword",
"value": "sort"
},
{
"$type": "Keyword",
"value": "view"
},
{
"$type": "Keyword",
"value": "import"
}
]
},
Expand Down
6 changes: 3 additions & 3 deletions packages/language/src/zmodel.langium
Original file line number Diff line number Diff line change
Expand Up @@ -90,7 +90,7 @@ ObjectExpr:
'}';

FieldInitializer:
name=RegularID ':' value=(Expression);
name=(RegularID | STRING) ':' value=(Expression);

InvocationExpr:
function=[FunctionDecl] '(' ArgumentList? ')';
Expand Down Expand Up @@ -186,7 +186,7 @@ DataModel:
'{' (
fields+=DataModelField
| attributes+=DataModelAttribute
)+
)*
'}';

DataModelField:
Expand Down Expand Up @@ -229,7 +229,7 @@ QualifiedName returns string:
// https://github.com/langium/langium/discussions/1012
RegularID returns string:
// include keywords that we'd like to work as ID in most places
ID | 'model' | 'enum' | 'attribute' | 'datasource' | 'plugin' | 'abstract' | 'in' | 'sort';
ID | 'model' | 'enum' | 'attribute' | 'datasource' | 'plugin' | 'abstract' | 'in' | 'sort' | 'view' | 'import';

// internal attribute
InternalAttributeName returns string:
Expand Down
10 changes: 6 additions & 4 deletions packages/plugins/openapi/package.json
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
{
"name": "@zenstackhq/openapi",
"displayName": "ZenStack Plugin and Runtime for OpenAPI",
"version": "1.0.2",
"version": "1.1.0",
"description": "ZenStack plugin and runtime supporting OpenAPI",
"main": "index.js",
"repository": {
Expand All @@ -20,7 +20,9 @@
"test": "ZENSTACK_TEST=1 jest",
"prepublishOnly": "pnpm build"
},
"keywords": ["openapi"],
"keywords": [
"openapi"
],
"author": "ZenStack Team",
"license": "MIT",
"dependencies": {
Expand All @@ -33,8 +35,8 @@
"tiny-invariant": "^1.3.1",
"upper-case-first": "^2.0.2",
"yaml": "^2.2.1",
"zod": "3.21.1",
"zod-validation-error": "^0.2.1"
"zod": "^3.22.4",
"zod-validation-error": "^1.5.0"
},
"devDependencies": {
"@readme/openapi-parser": "^2.4.0",
Expand Down
36 changes: 26 additions & 10 deletions packages/plugins/openapi/src/rest-generator.ts
Original file line number Diff line number Diff line change
Expand Up @@ -867,20 +867,36 @@ export class RESTfulOpenAPIGenerator extends OpenAPIGeneratorBase {
}
}

const toplevelRequired = ['type', 'attributes'];
// eslint-disable-next-line @typescript-eslint/no-explicit-any
let properties: any = {
type: { type: 'string' },
attributes: {
type: 'object',
required: required.length > 0 ? required : undefined,
properties: attributes,
},
};

if (mode === 'create') {
// 'id' is required if there's no default value
const idField = model.fields.find((f) => isIdField(f));
if (idField && !hasAttribute(idField, '@default')) {
properties = { id: { type: 'string' }, ...properties };
toplevelRequired.unshift('id');
}
} else {
// 'id' always required for read and update
properties = { id: { type: 'string' }, ...properties };
toplevelRequired.unshift('id');
}

// eslint-disable-next-line @typescript-eslint/no-explicit-any
const result: any = {
type: 'object',
description: `The "${model.name}" model`,
required: ['id', 'type', 'attributes'],
properties: {
type: { type: 'string' },
id: { type: 'string' },
attributes: {
type: 'object',
required: required.length > 0 ? required : undefined,
properties: attributes,
},
},
required: toplevelRequired,
properties,
} satisfies OAPI.SchemaObject;

if (Object.keys(relationships).length > 0) {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -590,10 +590,10 @@ components:
- type
- attributes
properties:
type:
type: string
id:
type: string
type:
type: string
attributes:
type: object
properties:
Expand Down Expand Up @@ -628,14 +628,11 @@ components:
type: object
description: The "Foo" model
required:
- id
- type
- attributes
properties:
type:
type: string
id:
type: string
attributes:
type: object
required:
Expand Down Expand Up @@ -685,10 +682,10 @@ components:
- type
- attributes
properties:
type:
type: string
id:
type: string
type:
type: string
attributes:
type: object
properties:
Expand Down
23 changes: 10 additions & 13 deletions packages/plugins/openapi/tests/baseline/rest.baseline.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -1525,10 +1525,10 @@ components:
- type
- attributes
properties:
type:
type: string
id:
type: string
type:
type: string
attributes:
type: object
properties:
Expand Down Expand Up @@ -1557,14 +1557,11 @@ components:
type: object
description: The "User" model
required:
- id
- type
- attributes
properties:
type:
type: string
id:
type: string
attributes:
type: object
required:
Expand Down Expand Up @@ -1602,10 +1599,10 @@ components:
- type
- attributes
properties:
type:
type: string
id:
type: string
type:
type: string
attributes:
type: object
properties:
Expand Down Expand Up @@ -1689,10 +1686,10 @@ components:
- type
- attributes
properties:
type:
type: string
id:
type: string
type:
type: string
attributes:
type: object
properties:
Expand Down Expand Up @@ -1729,10 +1726,10 @@ components:
- type
- attributes
properties:
type:
type: string
id:
type: string
type:
type: string
attributes:
type: object
required:
Expand Down Expand Up @@ -1774,10 +1771,10 @@ components:
- type
- attributes
properties:
type:
type: string
id:
type: string
type:
type: string
attributes:
type: object
properties:
Expand Down
4 changes: 0 additions & 4 deletions packages/plugins/openapi/tests/baseline/rpc.baseline.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -352,7 +352,6 @@ components:
posts:
$ref: '#/components/schemas/Post_ItemCreateNestedManyWithoutAuthorInput'
required:
- id
- email
UserUpdateInput:
type: object
Expand Down Expand Up @@ -397,7 +396,6 @@ components:
role:
$ref: '#/components/schemas/Role'
required:
- id
- email
UserUpdateManyMutationInput:
type: object
Expand Down Expand Up @@ -1709,7 +1707,6 @@ components:
role:
$ref: '#/components/schemas/Role'
required:
- id
- email
UserUncheckedCreateWithoutPostsInput:
type: object
Expand All @@ -1727,7 +1724,6 @@ components:
role:
$ref: '#/components/schemas/Role'
required:
- id
- email
UserCreateOrConnectWithoutPostsInput:
type: object
Expand Down
2 changes: 1 addition & 1 deletion packages/plugins/openapi/tests/openapi-restful.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -23,7 +23,7 @@ enum role {
}

model User {
id String @id
id String @id @default(cuid())
createdAt DateTime @default(now())
updatedAt DateTime @updatedAt
email String @unique
Expand Down
Loading