Skip to content

Commit

Permalink
merge dev to main (release 1.6.1) (#929)
Browse files Browse the repository at this point in the history
  • Loading branch information
ymc9 authored Jan 3, 2024
2 parents bdb95ff + 91fe8e7 commit 890aeeb
Show file tree
Hide file tree
Showing 29 changed files with 278 additions and 100 deletions.
2 changes: 1 addition & 1 deletion .github/workflows/build-test.yml
Original file line number Diff line number Diff line change
Expand Up @@ -82,7 +82,7 @@ jobs:
java-version: 17

- name: Setup Gradle
uses: gradle/gradle-build-action@v2
uses: gradle/gradle-build-action@v2.4.2
with:
gradle-home-cache-cleanup: true

Expand Down
1 change: 1 addition & 0 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -189,6 +189,7 @@ Check out the [Multi-tenant Todo App](https://zenstack-todo.vercel.app/) for a r
- [Next.js 13 + NextAuth + tRPC](https://github.com/zenstackhq/sample-todo-trpc)
- [Nuxt V3 + 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

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.6.0",
"version": "1.6.1",
"description": "",
"scripts": {
"build": "pnpm -r build",
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 @@ -5,7 +5,7 @@ plugins {
}

group = "dev.zenstack"
version = "1.6.0"
version = "1.6.1"

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": "1.6.0",
"version": "1.6.1",
"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": "1.6.0",
"version": "1.6.1",
"displayName": "ZenStack modeling language compiler",
"description": "ZenStack modeling language compiler",
"homepage": "https://zenstack.dev",
Expand Down
4 changes: 2 additions & 2 deletions packages/misc/redwood/package.json
Original file line number Diff line number Diff line change
@@ -1,15 +1,15 @@
{
"name": "@zenstackhq/redwood",
"displayName": "ZenStack RedwoodJS Integration",
"version": "1.6.0",
"version": "1.6.1",
"description": "CLI and runtime for integrating ZenStack with RedwoodJS projects.",
"repository": {
"type": "git",
"url": "https://github.com/zenstackhq/zenstack"
},
"scripts": {
"clean": "rimraf dist",
"build": "pnpm lint --max-warnings=0 && pnpm clean && tsc",
"build": "pnpm lint --max-warnings=0 && pnpm clean && tsc && pnpm pack dist --pack-destination '../../../.build'",
"watch": "tsc --watch",
"lint": "eslint src --ext ts",
"prepublishOnly": "pnpm build"
Expand Down
6 changes: 3 additions & 3 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.6.0",
"version": "1.6.1",
"description": "ZenStack plugin and runtime supporting OpenAPI",
"main": "index.js",
"repository": {
Expand Down Expand Up @@ -32,11 +32,11 @@
"change-case": "^4.1.2",
"lower-case-first": "^2.0.2",
"openapi-types": "^12.1.0",
"semver": "^7.3.8",
"semver": "^7.5.2",
"tiny-invariant": "^1.3.1",
"ts-pattern": "^4.3.0",
"upper-case-first": "^2.0.2",
"yaml": "^2.2.1",
"yaml": "^2.2.2",
"zod": "^3.22.4",
"zod-validation-error": "^1.5.0"
},
Expand Down
4 changes: 2 additions & 2 deletions packages/plugins/swr/package.json
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
{
"name": "@zenstackhq/swr",
"displayName": "ZenStack plugin for generating SWR hooks",
"version": "1.6.0",
"version": "1.6.1",
"description": "ZenStack plugin for generating SWR hooks",
"main": "index.js",
"repository": {
Expand Down Expand Up @@ -45,7 +45,7 @@
"cross-fetch": "^4.0.0",
"decimal.js": "^10.4.2",
"lower-case-first": "^2.0.2",
"semver": "^7.3.8",
"semver": "^7.5.2",
"ts-morph": "^16.0.0",
"upper-case-first": "^2.0.2"
},
Expand Down
4 changes: 2 additions & 2 deletions packages/plugins/tanstack-query/package.json
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
{
"name": "@zenstackhq/tanstack-query",
"displayName": "ZenStack plugin for generating tanstack-query hooks",
"version": "1.6.0",
"version": "1.6.1",
"description": "ZenStack plugin for generating tanstack-query hooks",
"main": "index.js",
"exports": {
Expand Down Expand Up @@ -87,7 +87,7 @@
"cross-fetch": "^4.0.0",
"decimal.js": "^10.4.2",
"lower-case-first": "^2.0.2",
"semver": "^7.3.8",
"semver": "^7.5.2",
"superjson": "^1.11.0",
"ts-morph": "^16.0.0",
"upper-case-first": "^2.0.2"
Expand Down
2 changes: 1 addition & 1 deletion packages/plugins/trpc/package.json
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
{
"name": "@zenstackhq/trpc",
"displayName": "ZenStack plugin for tRPC",
"version": "1.6.0",
"version": "1.6.1",
"description": "ZenStack plugin for tRPC",
"main": "index.js",
"repository": {
Expand Down
4 changes: 2 additions & 2 deletions packages/runtime/package.json
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
{
"name": "@zenstackhq/runtime",
"displayName": "ZenStack Runtime Library",
"version": "1.6.0",
"version": "1.6.1",
"description": "Runtime of ZenStack for both client-side and server-side environments.",
"repository": {
"type": "git",
Expand Down Expand Up @@ -62,7 +62,7 @@
"deepcopy": "^2.1.0",
"lower-case-first": "^2.0.2",
"pluralize": "^8.0.0",
"semver": "^7.3.8",
"semver": "^7.5.2",
"superjson": "^1.11.0",
"tiny-invariant": "^1.3.1",
"tslib": "^2.4.1",
Expand Down
4 changes: 2 additions & 2 deletions packages/schema/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@
"publisher": "zenstack",
"displayName": "ZenStack Language Tools",
"description": "Build scalable web apps with minimum code by defining authorization and validation rules inside the data schema that closer to the database",
"version": "1.6.0",
"version": "1.6.1",
"author": {
"name": "ZenStack Team"
},
Expand Down Expand Up @@ -95,7 +95,7 @@
"pluralize": "^8.0.0",
"pretty-repl": "^4.0.0",
"promisify": "^0.0.3",
"semver": "^7.3.8",
"semver": "^7.5.2",
"sleep-promise": "^9.1.0",
"strip-color": "^0.1.0",
"tiny-invariant": "^1.3.1",
Expand Down
92 changes: 74 additions & 18 deletions packages/schema/src/language-server/zmodel-linker.ts
Original file line number Diff line number Diff line change
Expand Up @@ -52,7 +52,12 @@ import {
} from 'langium';
import { match } from 'ts-pattern';
import { CancellationToken } from 'vscode-jsonrpc';
import { getAllDeclarationsFromImports, isAuthInvocation, getContainingDataModel } from '../utils/ast-utils';
import {
getAllDeclarationsFromImports,
getContainingDataModel,
isAuthInvocation,
isCollectionPredicate,
} from '../utils/ast-utils';
import { mapBuiltinTypeToExpressionType } from './validator/utils';

interface DefaultReference extends Reference {
Expand Down Expand Up @@ -94,9 +99,21 @@ export class ZModelLinker extends DefaultLinker {
extraScopes: ScopeProvider[],
onlyFromExtraScopes = false
) {
if (!this.resolveFromScopeProviders(container, property, document, extraScopes) && !onlyFromExtraScopes) {
// eslint-disable-next-line @typescript-eslint/no-explicit-any
const reference: Reference<AstNode> = (container as any)[property];
if (this.resolveFromScopeProviders(container, property, document, extraScopes)) {
return;
}

// eslint-disable-next-line @typescript-eslint/no-explicit-any
const reference: DefaultReference = (container as any)[property];

if (onlyFromExtraScopes) {
// if reference is not resolved from explicit scope providers and automatic linking is not allowed,
// we should explicitly create a linking error
reference._ref = this.createLinkingError({ reference, container, property });

// Add the reference to the document's array of references
document.references.push(reference);
} else {
this.doLink({ reference, container, property }, document);
}
}
Expand All @@ -118,6 +135,10 @@ export class ZModelLinker extends DefaultLinker {
if (target) {
reference._ref = target;
reference._nodeDescription = this.descriptions.createDescription(target, target.name, document);

// Add the reference to the document's array of references
document.references.push(reference);

return target;
}
}
Expand Down Expand Up @@ -244,6 +265,22 @@ export class ZModelLinker extends DefaultLinker {
node.args.forEach((arg) => this.resolve(arg, document, extraScopes));

if (node.target.ref) {
// if the reference is inside the RHS of a collection predicate, it cannot be resolve to a field
// not belonging to the collection's model type

const collectionPredicateContext = this.getCollectionPredicateContextDataModel(node);
if (
// inside a collection predicate RHS
collectionPredicateContext &&
// current ref expr is resolved to a field
isDataModelField(node.target.ref) &&
// the resolved field doesn't belong to the collection predicate's operand's type
node.target.ref.$container !== collectionPredicateContext
) {
this.unresolvableRefExpr(node);
return;
}

// resolve type
if (node.target.ref.$type === EnumField) {
this.resolveToBuiltinTypeOrDecl(node, node.target.ref.$container);
Expand All @@ -253,6 +290,26 @@ export class ZModelLinker extends DefaultLinker {
}
}

private getCollectionPredicateContextDataModel(node: ReferenceExpr) {
let curr: AstNode | undefined = node;
while (curr) {
if (
curr.$container &&
// parent is a collection predicate
isCollectionPredicate(curr.$container) &&
// the collection predicate's LHS is resolved to a DataModel
isDataModel(curr.$container.left.$resolvedType?.decl) &&
// current node is the RHS
curr.$containerProperty === 'right'
) {
// return the resolved type of LHS
return curr.$container.left.$resolvedType?.decl;
}
curr = curr.$container;
}
return undefined;
}

private resolveArray(node: ArrayExpr, document: LangiumDocument<AstNode>, extraScopes: ScopeProvider[]) {
node.items.forEach((item) => this.resolve(item, document, extraScopes));

Expand Down Expand Up @@ -414,13 +471,8 @@ export class ZModelLinker extends DefaultLinker {
if (resolved) {
this.resolveToDeclaredType(item, (resolved as DataModelField).type);
} else {
// need to clear linked reference, because it's resolved in default scope by default
const ref = item.target as DefaultReference;
ref._ref = this.createLinkingError({
reference: ref,
container: item,
property: 'target',
});
// mark unresolvable
this.unresolvableRefExpr(item);
}
}
});
Expand All @@ -432,13 +484,8 @@ export class ZModelLinker extends DefaultLinker {
if (resolved) {
this.resolveToDeclaredType(node.value, (resolved as DataModelField).type);
} else {
// need to clear linked reference, because it's resolved in default scope by default
const ref = node.value.target as DefaultReference;
ref._ref = this.createLinkingError({
reference: ref,
container: node.value,
property: 'target',
});
// mark unresolvable
this.unresolvableRefExpr(node.value);
}
}
}
Expand All @@ -448,6 +495,15 @@ export class ZModelLinker extends DefaultLinker {
node.$resolvedType = node.value.$resolvedType;
}

private unresolvableRefExpr(item: ReferenceExpr) {
const ref = item.target as DefaultReference;
ref._ref = this.createLinkingError({
reference: ref,
container: item,
property: 'target',
});
}

private findAttrParamForArg(arg: AttributeArg): AttributeParam | undefined {
const attr = arg.$container.decl.ref;
if (!attr) {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -461,8 +461,9 @@ export class ExpressionWriter {
this.writer.write(`db.${lowerCaseFirst(containingModel.name)}.fields.${expr.target.ref.name}`);
}

private isAuthOrAuthMemberAccess(expr: Expression) {
return isAuthInvocation(expr) || (isMemberAccessExpr(expr) && isAuthInvocation(expr.operand));
private isAuthOrAuthMemberAccess(expr: Expression): boolean {
// recursive check for auth().x.y.z
return isAuthInvocation(expr) || (isMemberAccessExpr(expr) && this.isAuthOrAuthMemberAccess(expr.operand));
}

private writeOperator(operator: ComparisonOperator, fieldAccess: Expression, writeOperand: () => void) {
Expand Down
11 changes: 2 additions & 9 deletions packages/schema/src/plugins/prisma/prisma-builder.ts
Original file line number Diff line number Diff line change
Expand Up @@ -304,17 +304,10 @@ export class FunctionCall {
}

export class FunctionCallArg {
// eslint-disable-next-line @typescript-eslint/explicit-module-boundary-types, @typescript-eslint/no-explicit-any
constructor(public name: string | undefined, public value: any) {}
constructor(public name: string | undefined, public value: string) {}

toString(): string {
const val =
this.value === null || this.value === undefined
? 'null'
: typeof this.value === 'string'
? `"${this.value}"`
: this.value.toString();
return this.name ? `${this.name}: ${val}` : val;
return this.name ? `${this.name}: ${this.value}` : this.value;
}
}

Expand Down
Loading

0 comments on commit 890aeeb

Please sign in to comment.