Skip to content

Commit f2d6fee

Browse files
authored
merge dev to main (v1.1 release) (#766)
2 parents 4d6a436 + 916d3c1 commit f2d6fee

Some content is hidden

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

55 files changed

+4618
-365
lines changed

README.md

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -158,10 +158,10 @@ The following diagram gives a high-level architecture overview of ZenStack.
158158
### Framework adapters
159159

160160
- [Next.js](https://zenstack.dev/docs/reference/server-adapters/next) (including support for the new "app directory" in Next.js 13)
161+
- [Nuxt](https://zenstack.dev/docs/reference/server-adapters/nuxt)
161162
- [SvelteKit](https://zenstack.dev/docs/reference/server-adapters/sveltekit)
162163
- [Fastify](https://zenstack.dev/docs/reference/server-adapters/fastify)
163164
- [ExpressJS](https://zenstack.dev/docs/reference/server-adapters/express)
164-
- Nuxt.js (Future)
165165
- 🙋🏻 [Request for an adapter](https://go.zenstack.dev/chat)
166166

167167
### Prisma schema extensions
@@ -179,6 +179,7 @@ Check out the [Collaborative Todo App](https://zenstack-todo.vercel.app/) for a
179179
- [Next.js + SWR hooks](https://github.com/zenstackhq/sample-todo-nextjs)
180180
- [Next.js + TanStack Query](https://github.com/zenstackhq/sample-todo-nextjs-tanstack)
181181
- [Next.js + tRPC](https://github.com/zenstackhq/sample-todo-trpc)
182+
- [Nuxt + TanStack Query](https://github.com/zenstackhq/sample-todo-nuxt)
182183
- [SvelteKit + TanStack Query](https://github.com/zenstackhq/sample-todo-sveltekit)
183184

184185
## Community

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": "1.0.2",
3+
"version": "1.1.0",
44
"description": "",
55
"scripts": {
66
"build": "pnpm -r build",

packages/language/package.json

Lines changed: 16 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
{
22
"name": "@zenstackhq/language",
3-
"version": "1.0.2",
3+
"version": "1.1.0",
44
"displayName": "ZenStack modeling language compiler",
55
"description": "ZenStack modeling language compiler",
66
"homepage": "https://zenstack.dev",
@@ -28,5 +28,20 @@
2828
},
2929
"dependencies": {
3030
"langium": "1.2.0"
31+
},
32+
"contributes": {
33+
"languages": [
34+
{
35+
"id": "zmodel",
36+
"extensions": [".zmodel"]
37+
}
38+
],
39+
"grammars": [
40+
{
41+
"language": "zmodel",
42+
"scopeName": "source.zmodel",
43+
"path": "./syntaxes/zmodel.tmLanguage.json"
44+
}
45+
]
3146
}
3247
}

packages/language/src/generated/ast.ts

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -94,10 +94,10 @@ export function isReferenceTarget(item: unknown): item is ReferenceTarget {
9494
return reflection.isInstance(item, ReferenceTarget);
9595
}
9696

97-
export type RegularID = 'abstract' | 'attribute' | 'datasource' | 'enum' | 'in' | 'model' | 'plugin' | 'sort' | string;
97+
export type RegularID = 'abstract' | 'attribute' | 'datasource' | 'enum' | 'import' | 'in' | 'model' | 'plugin' | 'sort' | 'view' | string;
9898

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

103103
export type TypeDeclaration = DataModel | Enum;
@@ -386,7 +386,7 @@ export function isEnumField(item: unknown): item is EnumField {
386386
export interface FieldInitializer extends AstNode {
387387
readonly $container: ObjectExpr;
388388
readonly $type: 'FieldInitializer';
389-
name: RegularID
389+
name: RegularID | string
390390
value: Expression
391391
}
392392

packages/language/src/generated/grammar.ts

Lines changed: 26 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -1171,11 +1171,23 @@ export const ZModelGrammar = (): Grammar => loadedZModelGrammar ?? (loadedZModel
11711171
"feature": "name",
11721172
"operator": "=",
11731173
"terminal": {
1174-
"$type": "RuleCall",
1175-
"rule": {
1176-
"$ref": "#/rules@47"
1177-
},
1178-
"arguments": []
1174+
"$type": "Alternatives",
1175+
"elements": [
1176+
{
1177+
"$type": "RuleCall",
1178+
"rule": {
1179+
"$ref": "#/rules@47"
1180+
},
1181+
"arguments": []
1182+
},
1183+
{
1184+
"$type": "RuleCall",
1185+
"rule": {
1186+
"$ref": "#/rules@67"
1187+
},
1188+
"arguments": []
1189+
}
1190+
]
11791191
}
11801192
},
11811193
{
@@ -2060,7 +2072,7 @@ export const ZModelGrammar = (): Grammar => loadedZModelGrammar ?? (loadedZModel
20602072
}
20612073
}
20622074
],
2063-
"cardinality": "+"
2075+
"cardinality": "*"
20642076
},
20652077
{
20662078
"$type": "Keyword",
@@ -2771,6 +2783,14 @@ export const ZModelGrammar = (): Grammar => loadedZModelGrammar ?? (loadedZModel
27712783
{
27722784
"$type": "Keyword",
27732785
"value": "sort"
2786+
},
2787+
{
2788+
"$type": "Keyword",
2789+
"value": "view"
2790+
},
2791+
{
2792+
"$type": "Keyword",
2793+
"value": "import"
27742794
}
27752795
]
27762796
},

packages/language/src/zmodel.langium

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -90,7 +90,7 @@ ObjectExpr:
9090
'}';
9191

9292
FieldInitializer:
93-
name=RegularID ':' value=(Expression);
93+
name=(RegularID | STRING) ':' value=(Expression);
9494

9595
InvocationExpr:
9696
function=[FunctionDecl] '(' ArgumentList? ')';
@@ -186,7 +186,7 @@ DataModel:
186186
'{' (
187187
fields+=DataModelField
188188
| attributes+=DataModelAttribute
189-
)+
189+
)*
190190
'}';
191191

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

234234
// internal attribute
235235
InternalAttributeName returns string:

packages/plugins/openapi/package.json

Lines changed: 6 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,7 @@
11
{
22
"name": "@zenstackhq/openapi",
33
"displayName": "ZenStack Plugin and Runtime for OpenAPI",
4-
"version": "1.0.2",
4+
"version": "1.1.0",
55
"description": "ZenStack plugin and runtime supporting OpenAPI",
66
"main": "index.js",
77
"repository": {
@@ -20,7 +20,9 @@
2020
"test": "ZENSTACK_TEST=1 jest",
2121
"prepublishOnly": "pnpm build"
2222
},
23-
"keywords": ["openapi"],
23+
"keywords": [
24+
"openapi"
25+
],
2426
"author": "ZenStack Team",
2527
"license": "MIT",
2628
"dependencies": {
@@ -33,8 +35,8 @@
3335
"tiny-invariant": "^1.3.1",
3436
"upper-case-first": "^2.0.2",
3537
"yaml": "^2.2.1",
36-
"zod": "3.21.1",
37-
"zod-validation-error": "^0.2.1"
38+
"zod": "^3.22.4",
39+
"zod-validation-error": "^1.5.0"
3840
},
3941
"devDependencies": {
4042
"@readme/openapi-parser": "^2.4.0",

packages/plugins/openapi/src/rest-generator.ts

Lines changed: 26 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -867,20 +867,36 @@ export class RESTfulOpenAPIGenerator extends OpenAPIGeneratorBase {
867867
}
868868
}
869869

870+
const toplevelRequired = ['type', 'attributes'];
871+
// eslint-disable-next-line @typescript-eslint/no-explicit-any
872+
let properties: any = {
873+
type: { type: 'string' },
874+
attributes: {
875+
type: 'object',
876+
required: required.length > 0 ? required : undefined,
877+
properties: attributes,
878+
},
879+
};
880+
881+
if (mode === 'create') {
882+
// 'id' is required if there's no default value
883+
const idField = model.fields.find((f) => isIdField(f));
884+
if (idField && !hasAttribute(idField, '@default')) {
885+
properties = { id: { type: 'string' }, ...properties };
886+
toplevelRequired.unshift('id');
887+
}
888+
} else {
889+
// 'id' always required for read and update
890+
properties = { id: { type: 'string' }, ...properties };
891+
toplevelRequired.unshift('id');
892+
}
893+
870894
// eslint-disable-next-line @typescript-eslint/no-explicit-any
871895
const result: any = {
872896
type: 'object',
873897
description: `The "${model.name}" model`,
874-
required: ['id', 'type', 'attributes'],
875-
properties: {
876-
type: { type: 'string' },
877-
id: { type: 'string' },
878-
attributes: {
879-
type: 'object',
880-
required: required.length > 0 ? required : undefined,
881-
properties: attributes,
882-
},
883-
},
898+
required: toplevelRequired,
899+
properties,
884900
} satisfies OAPI.SchemaObject;
885901

886902
if (Object.keys(relationships).length > 0) {

packages/plugins/openapi/tests/baseline/rest-type-coverage.baseline.yaml

Lines changed: 4 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -590,10 +590,10 @@ components:
590590
- type
591591
- attributes
592592
properties:
593-
type:
594-
type: string
595593
id:
596594
type: string
595+
type:
596+
type: string
597597
attributes:
598598
type: object
599599
properties:
@@ -628,14 +628,11 @@ components:
628628
type: object
629629
description: The "Foo" model
630630
required:
631-
- id
632631
- type
633632
- attributes
634633
properties:
635634
type:
636635
type: string
637-
id:
638-
type: string
639636
attributes:
640637
type: object
641638
required:
@@ -685,10 +682,10 @@ components:
685682
- type
686683
- attributes
687684
properties:
688-
type:
689-
type: string
690685
id:
691686
type: string
687+
type:
688+
type: string
692689
attributes:
693690
type: object
694691
properties:

packages/plugins/openapi/tests/baseline/rest.baseline.yaml

Lines changed: 10 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -1525,10 +1525,10 @@ components:
15251525
- type
15261526
- attributes
15271527
properties:
1528-
type:
1529-
type: string
15301528
id:
15311529
type: string
1530+
type:
1531+
type: string
15321532
attributes:
15331533
type: object
15341534
properties:
@@ -1557,14 +1557,11 @@ components:
15571557
type: object
15581558
description: The "User" model
15591559
required:
1560-
- id
15611560
- type
15621561
- attributes
15631562
properties:
15641563
type:
15651564
type: string
1566-
id:
1567-
type: string
15681565
attributes:
15691566
type: object
15701567
required:
@@ -1602,10 +1599,10 @@ components:
16021599
- type
16031600
- attributes
16041601
properties:
1605-
type:
1606-
type: string
16071602
id:
16081603
type: string
1604+
type:
1605+
type: string
16091606
attributes:
16101607
type: object
16111608
properties:
@@ -1689,10 +1686,10 @@ components:
16891686
- type
16901687
- attributes
16911688
properties:
1692-
type:
1693-
type: string
16941689
id:
16951690
type: string
1691+
type:
1692+
type: string
16961693
attributes:
16971694
type: object
16981695
properties:
@@ -1729,10 +1726,10 @@ components:
17291726
- type
17301727
- attributes
17311728
properties:
1732-
type:
1733-
type: string
17341729
id:
17351730
type: string
1731+
type:
1732+
type: string
17361733
attributes:
17371734
type: object
17381735
required:
@@ -1774,10 +1771,10 @@ components:
17741771
- type
17751772
- attributes
17761773
properties:
1777-
type:
1778-
type: string
17791774
id:
17801775
type: string
1776+
type:
1777+
type: string
17811778
attributes:
17821779
type: object
17831780
properties:

0 commit comments

Comments
 (0)