Skip to content

Commit 1770b12

Browse files
authored
Merge pull request #267 from zenstackhq/dev
merge dev to main (v3.0.0-beta.6)
2 parents 495a512 + 9bf6d7f commit 1770b12

File tree

25 files changed

+78
-92
lines changed

25 files changed

+78
-92
lines changed

package.json

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
{
22
"name": "zenstack-v3",
3-
"version": "3.0.0-beta.5",
3+
"version": "3.0.0-beta.6",
44
"description": "ZenStack",
55
"packageManager": "[email protected]",
66
"scripts": {

packages/cli/package.json

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -3,7 +3,7 @@
33
"publisher": "zenstack",
44
"displayName": "ZenStack CLI",
55
"description": "FullStack database toolkit with built-in access control and automatic API generation.",
6-
"version": "3.0.0-beta.5",
6+
"version": "3.0.0-beta.6",
77
"type": "module",
88
"author": {
99
"name": "ZenStack Team"

packages/common-helpers/package.json

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
{
22
"name": "@zenstackhq/common-helpers",
3-
"version": "3.0.0-beta.5",
3+
"version": "3.0.0-beta.6",
44
"description": "ZenStack Common Helpers",
55
"type": "module",
66
"scripts": {

packages/create-zenstack/package.json

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
{
22
"name": "create-zenstack",
3-
"version": "3.0.0-beta.5",
3+
"version": "3.0.0-beta.6",
44
"description": "Create a new ZenStack project",
55
"type": "module",
66
"scripts": {

packages/dialects/sql.js/package.json

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
{
22
"name": "@zenstackhq/kysely-sql-js",
3-
"version": "3.0.0-beta.5",
3+
"version": "3.0.0-beta.6",
44
"description": "Kysely dialect for sql.js",
55
"type": "module",
66
"scripts": {

packages/eslint-config/package.json

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
{
22
"name": "@zenstackhq/eslint-config",
3-
"version": "3.0.0-beta.5",
3+
"version": "3.0.0-beta.6",
44
"type": "module",
55
"private": true,
66
"license": "MIT"

packages/language/package.json

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,7 @@
11
{
22
"name": "@zenstackhq/language",
33
"description": "ZenStack ZModel language specification",
4-
"version": "3.0.0-beta.5",
4+
"version": "3.0.0-beta.6",
55
"license": "MIT",
66
"author": "ZenStack Team",
77
"files": [

packages/language/res/stdlib.zmodel

Lines changed: 53 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -116,12 +116,6 @@ function autoincrement(): Int {
116116
function dbgenerated(expr: String?): Any {
117117
} @@@expressionContext([DefaultValue])
118118

119-
/**
120-
* Gets entities value before an update. Only valid when used in a "update" policy rule.
121-
*/
122-
function future(): Any {
123-
} @@@expressionContext([AccessPolicy])
124-
125119
/**
126120
* Checks if the field value contains the search string. By default, the search is case-sensitive, and
127121
* "LIKE" operator is used to match. If `caseInSensitive` is true, "ILIKE" operator is used if
@@ -663,3 +657,56 @@ attribute @meta(_ name: String, _ value: Any)
663657
* Marks an attribute as deprecated.
664658
*/
665659
attribute @@@deprecated(_ message: String)
660+
661+
/* --- Policy Plugin --- */
662+
663+
/**
664+
* Defines an access policy that allows a set of operations when the given condition is true.
665+
*
666+
* @param operation: comma-separated list of "create", "read", "update", "delete". Use "all" to denote all operations.
667+
* @param condition: a boolean expression that controls if the operation should be allowed.
668+
*/
669+
attribute @@allow(_ operation: String @@@completionHint(["'create'", "'read'", "'update'", "'delete'", "'all'"]), _ condition: Boolean)
670+
671+
/**
672+
* Defines an access policy that allows the annotated field to be read or updated.
673+
* You can pass a third argument as `true` to make it override the model-level policies.
674+
*
675+
* @param operation: comma-separated list of "create", "read", "update", "delete". Use "all" to denote all operations.
676+
* @param condition: a boolean expression that controls if the operation should be allowed.
677+
* @param override: a boolean value that controls if the field-level policy should override the model-level policy.
678+
*/
679+
attribute @allow(_ operation: String @@@completionHint(["'create'", "'read'", "'update'", "'delete'", "'all'"]), _ condition: Boolean, _ override: Boolean?)
680+
681+
/**
682+
* Defines an access policy that denies a set of operations when the given condition is true.
683+
*
684+
* @param operation: comma-separated list of "create", "read", "update", "delete". Use "all" to denote all operations.
685+
* @param condition: a boolean expression that controls if the operation should be denied.
686+
*/
687+
attribute @@deny(_ operation: String @@@completionHint(["'create'", "'read'", "'update'", "'delete'", "'all'"]), _ condition: Boolean)
688+
689+
/**
690+
* Defines an access policy that denies the annotated field to be read or updated.
691+
*
692+
* @param operation: comma-separated list of "create", "read", "update", "delete". Use "all" to denote all operations.
693+
* @param condition: a boolean expression that controls if the operation should be denied.
694+
*/
695+
attribute @deny(_ operation: String @@@completionHint(["'create'", "'read'", "'update'", "'delete'", "'all'"]), _ condition: Boolean)
696+
697+
/**
698+
* Checks if the current user can perform the given operation on the given field.
699+
*
700+
* @param field: The field to check access for
701+
* @param operation: The operation to check access for. Can be "read", "create", "update", or "delete". If the operation is not provided,
702+
* it defaults the operation of the containing policy rule.
703+
*/
704+
function check(field: Any, operation: String?): Boolean {
705+
} @@@expressionContext([AccessPolicy])
706+
707+
/**
708+
* Gets entities value before an update. Only valid when used in a "update" policy rule.
709+
*/
710+
function future(): Any {
711+
} @@@expressionContext([AccessPolicy])
712+

packages/language/test/utils.ts

Lines changed: 2 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,4 @@
11
import { invariant } from '@zenstackhq/common-helpers';
2-
import { glob } from 'glob';
32
import fs from 'node:fs';
43
import os from 'node:os';
54
import path from 'node:path';
@@ -10,7 +9,7 @@ export async function loadSchema(schema: string) {
109
// create a temp file
1110
const tempFile = path.join(os.tmpdir(), `zenstack-schema-${crypto.randomUUID()}.zmodel`);
1211
fs.writeFileSync(tempFile, schema);
13-
const r = await loadDocument(tempFile, getPluginModels());
12+
const r = await loadDocument(tempFile);
1413
expect(r).toSatisfy(
1514
(r) => r.success,
1615
`Failed to load schema: ${(r as any).errors?.map((e) => e.toString()).join(', ')}`,
@@ -23,7 +22,7 @@ export async function loadSchemaWithError(schema: string, error: string | RegExp
2322
// create a temp file
2423
const tempFile = path.join(os.tmpdir(), `zenstack-schema-${crypto.randomUUID()}.zmodel`);
2524
fs.writeFileSync(tempFile, schema);
26-
const r = await loadDocument(tempFile, getPluginModels());
25+
const r = await loadDocument(tempFile);
2726
expect(r.success).toBe(false);
2827
invariant(!r.success);
2928
if (typeof error === 'string') {
@@ -38,6 +37,3 @@ export async function loadSchemaWithError(schema: string, error: string | RegExp
3837
);
3938
}
4039
}
41-
function getPluginModels() {
42-
return glob.sync(path.resolve(__dirname, '../../runtime/src/plugins/**/plugin.zmodel'));
43-
}

packages/runtime/package.json

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
{
22
"name": "@zenstackhq/runtime",
3-
"version": "3.0.0-beta.5",
3+
"version": "3.0.0-beta.6",
44
"description": "ZenStack Runtime",
55
"type": "module",
66
"scripts": {

0 commit comments

Comments
 (0)