Skip to content
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

merge dev to main #591

Merged
merged 10 commits into from
Jul 19, 2023
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
10 changes: 9 additions & 1 deletion .github/workflows/build-test.yml
Original file line number Diff line number Diff line change
Expand Up @@ -18,9 +18,17 @@ jobs:
strategy:
matrix:
node-version: [18.x]
prisma-version: [v4, v5]

steps:
- uses: actions/checkout@v3
- name: Checkout
uses: actions/checkout@v3

- name: Set Prisma Version
if: ${{ matrix.prisma-version == 'v5' }}
shell: bash
run: |
bash ./script/test-prisma-v5.sh

- name: Install pnpm
uses: pnpm/action-setup@v2
Expand Down
7 changes: 5 additions & 2 deletions package.json
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
{
"name": "zenstack-monorepo",
"version": "1.0.0-beta.8",
"version": "1.0.0-beta.9",
"description": "",
"scripts": {
"build": "pnpm -r build",
Expand All @@ -14,6 +14,9 @@
"author": "",
"license": "MIT",
"devDependencies": {
"@changesets/cli": "^2.26.0"
"@changesets/cli": "^2.26.0",
"concurrently": "^7.4.0",
"replace-in-file": "^7.0.1",
"tsup": "^7.1.0"
}
}
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": "1.0.0-beta.8",
"version": "1.0.0-beta.9",
"displayName": "ZenStack modeling language compiler",
"description": "ZenStack modeling language compiler",
"homepage": "https://zenstack.dev",
Expand Down
2 changes: 2 additions & 0 deletions packages/language/src/generated/ast.ts
Original file line number Diff line number Diff line change
Expand Up @@ -194,6 +194,7 @@ export interface DataModel extends AstNode {
comments: Array<string>
fields: Array<DataModelField>
isAbstract: boolean
isView: boolean
name: RegularID
superTypes: Array<Reference<DataModel>>
}
Expand Down Expand Up @@ -748,6 +749,7 @@ export class ZModelAstReflection extends AbstractAstReflection {
{ name: 'comments', type: 'array' },
{ name: 'fields', type: 'array' },
{ name: 'isAbstract', type: 'boolean' },
{ name: 'isView', type: 'boolean' },
{ name: 'superTypes', type: 'array' }
]
};
Expand Down
140 changes: 88 additions & 52 deletions packages/language/src/generated/grammar.ts
Original file line number Diff line number Diff line change
Expand Up @@ -1681,74 +1681,110 @@ export const ZModelGrammar = (): Grammar => loadedZModelGrammar ?? (loadedZModel
"cardinality": "*"
},
{
"$type": "Assignment",
"feature": "isAbstract",
"operator": "?=",
"terminal": {
"$type": "Keyword",
"value": "abstract"
},
"cardinality": "?"
},
{
"$type": "Keyword",
"value": "model"
},
{
"$type": "Assignment",
"feature": "name",
"operator": "=",
"terminal": {
"$type": "RuleCall",
"rule": {
"$ref": "#/rules@40"
},
"arguments": []
}
},
{
"$type": "Group",
"$type": "Alternatives",
"elements": [
{
"$type": "Keyword",
"value": "extends"
},
{
"$type": "Assignment",
"feature": "superTypes",
"operator": "+=",
"terminal": {
"$type": "CrossReference",
"type": {
"$ref": "#/rules@30"
"$type": "Group",
"elements": [
{
"$type": "Assignment",
"feature": "isAbstract",
"operator": "?=",
"terminal": {
"$type": "Keyword",
"value": "abstract"
},
"cardinality": "?"
},
"deprecatedSyntax": false
}
{
"$type": "Keyword",
"value": "model"
},
{
"$type": "Assignment",
"feature": "name",
"operator": "=",
"terminal": {
"$type": "RuleCall",
"rule": {
"$ref": "#/rules@40"
},
"arguments": []
}
},
{
"$type": "Group",
"elements": [
{
"$type": "Keyword",
"value": "extends"
},
{
"$type": "Assignment",
"feature": "superTypes",
"operator": "+=",
"terminal": {
"$type": "CrossReference",
"type": {
"$ref": "#/rules@30"
},
"deprecatedSyntax": false
}
},
{
"$type": "Group",
"elements": [
{
"$type": "Keyword",
"value": ","
},
{
"$type": "Assignment",
"feature": "superTypes",
"operator": "+=",
"terminal": {
"$type": "CrossReference",
"type": {
"$ref": "#/rules@30"
},
"deprecatedSyntax": false
}
}
],
"cardinality": "*"
}
],
"cardinality": "?"
}
]
},
{
"$type": "Group",
"elements": [
{
"$type": "Keyword",
"value": ","
"$type": "Assignment",
"feature": "isView",
"operator": "?=",
"terminal": {
"$type": "Keyword",
"value": "view"
}
},
{
"$type": "Assignment",
"feature": "superTypes",
"operator": "+=",
"feature": "name",
"operator": "=",
"terminal": {
"$type": "CrossReference",
"type": {
"$ref": "#/rules@30"
"$type": "RuleCall",
"rule": {
"$ref": "#/rules@40"
},
"deprecatedSyntax": false
"arguments": []
}
}
],
"cardinality": "*"
]
}
],
"cardinality": "?"
]
},
{
"$type": "Keyword",
Expand Down
8 changes: 6 additions & 2 deletions packages/language/src/zmodel.langium
Original file line number Diff line number Diff line change
Expand Up @@ -156,8 +156,12 @@ Argument:
// model
DataModel:
(comments+=TRIPLE_SLASH_COMMENT)*
(isAbstract?='abstract')? 'model' name=RegularID
('extends' superTypes+=[DataModel] (',' superTypes+=[DataModel])*)? '{' (
(
((isAbstract?='abstract')? 'model' name=RegularID
('extends' superTypes+=[DataModel] (',' superTypes+=[DataModel])*)?) |
((isView?='view') name=RegularID)
)
'{' (
fields+=DataModelField
| attributes+=DataModelAttribute
)+
Expand Down
2 changes: 1 addition & 1 deletion packages/language/syntaxes/zmodel.tmLanguage.json
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,7 @@
},
{
"name": "keyword.control.zmodel",
"match": "\\b(Any|Asc|BigInt|Boolean|Bytes|ContextType|DateTime|Decimal|Desc|FieldReference|Float|Int|Json|Null|Object|String|TransitiveFieldReference|Unsupported|abstract|attribute|datasource|enum|extends|false|function|generator|import|in|model|plugin|sort|true)\\b"
"match": "\\b(Any|Asc|BigInt|Boolean|Bytes|ContextType|DateTime|Decimal|Desc|FieldReference|Float|Int|Json|Null|Object|String|TransitiveFieldReference|Unsupported|abstract|attribute|datasource|enum|extends|false|function|generator|import|in|model|plugin|sort|true|view)\\b"
},
{
"name": "string.quoted.double.zmodel",
Expand Down
7 changes: 3 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.0-beta.8",
"version": "1.0.0-beta.9",
"description": "ZenStack plugin and runtime supporting OpenAPI",
"main": "index.js",
"repository": {
Expand All @@ -24,7 +24,7 @@
"author": "ZenStack Team",
"license": "MIT",
"dependencies": {
"@prisma/generator-helper": "4.10.0",
"@prisma/generator-helper": "^5.0.0",
"@zenstackhq/runtime": "workspace:*",
"@zenstackhq/sdk": "workspace:*",
"change-case": "^4.1.2",
Expand All @@ -36,10 +36,9 @@
"zod-validation-error": "^0.2.1"
},
"devDependencies": {
"@prisma/internals": "4.10.0",
"@readme/openapi-parser": "^2.4.0",
"@types/jest": "^29.5.0",
"@types/lower-case-first": "^1.0.1",
"@types/node": "^18.0.0",
"@types/pluralize": "^0.0.29",
"@types/tmp": "^0.2.3",
"@typescript-eslint/eslint-plugin": "^5.54.0",
Expand Down
2 changes: 1 addition & 1 deletion packages/plugins/openapi/src/generator-base.ts
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
import { DMMF } from '@prisma/generator-helper';
import type { DMMF } from '@prisma/generator-helper';
import { PluginError, PluginOptions, getDataModels, hasAttribute } from '@zenstackhq/sdk';
import { Model } from '@zenstackhq/sdk/ast';
import type { OpenAPIV3_1 as OAPI } from 'openapi-types';
Expand Down
2 changes: 1 addition & 1 deletion packages/plugins/openapi/src/index.ts
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
import { DMMF } from '@prisma/generator-helper';
import type { DMMF } from '@prisma/generator-helper';
import { PluginError, PluginOptions } from '@zenstackhq/sdk';
import { Model } from '@zenstackhq/sdk/ast';
import { RESTfulOpenAPIGenerator } from './rest-generator';
Expand Down
23 changes: 16 additions & 7 deletions packages/plugins/openapi/src/rest-generator.ts
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
// Inspired by: https://github.com/omar-dulaimi/prisma-trpc-generator

import { DMMF } from '@prisma/generator-helper';
import type { DMMF } from '@prisma/generator-helper';
import {
AUXILIARY_FIELDS,
analyzePolicies,
Expand Down Expand Up @@ -536,12 +536,16 @@ export class RESTfulOpenAPIGenerator extends OpenAPIGeneratorBase {
required: ['version'],
properties: {
version: { type: 'string' },
meta: this.ref('_meta'),
},
},
_meta: {
type: 'object',
description: 'Meta information about the response',
description: 'Meta information about the request or response',
properties: {
serialization: {
description: 'Superjson serialization metadata',
},
},
additionalProperties: true,
},
_resourceIdentifier: {
Expand Down Expand Up @@ -759,14 +763,15 @@ export class RESTfulOpenAPIGenerator extends OpenAPIGeneratorBase {
required: ['data'],
properties: {
data: this.generateModelEntity(model, 'create'),
meta: this.ref('_meta'),
},
};

result[`${model.name}UpdateRequest`] = {
type: 'object',
description: `Input for updating a "${model.name}"`,
required: ['data'],
properties: { data: this.generateModelEntity(model, 'update') },
properties: { data: this.generateModelEntity(model, 'update'), meta: this.ref('_meta') },
};

const relationships: Record<string, OAPI.ReferenceObject> = {};
Expand All @@ -790,7 +795,7 @@ export class RESTfulOpenAPIGenerator extends OpenAPIGeneratorBase {
type: 'object',
properties: { relationships: { type: 'object', properties: relationships } },
}),

meta: this.ref('_meta'),
included: {
type: 'array',
items: this.ref('_resource'),
Expand All @@ -811,6 +816,7 @@ export class RESTfulOpenAPIGenerator extends OpenAPIGeneratorBase {
properties: { relationships: { type: 'object', properties: relationships } },
})
),
meta: this.ref('_meta'),
included: {
type: 'array',
items: this.ref('_resource'),
Expand Down Expand Up @@ -895,14 +901,17 @@ export class RESTfulOpenAPIGenerator extends OpenAPIGeneratorBase {
case 'BigInt':
return { type: 'integer' };
case 'Float':
case 'Decimal':
return { type: 'number' };
case 'Decimal':
return this.oneOf({ type: 'number' }, { type: 'string' });
case 'Boolean':
return { type: 'boolean' };
case 'DateTime':
return { type: 'string', format: 'date-time' };
case 'Bytes':
return { type: 'string', format: 'byte', description: 'Base64 encoded byte array' };
case 'Json':
return { type: 'object' };
return {};
default: {
const fieldDecl = type.reference?.ref;
invariant(fieldDecl);
Expand Down
Loading