@zenstackhq/plugin-policy 3.0.0-beta.9 → 3.1.0

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
package/package.json CHANGED
@@ -1,13 +1,14 @@
1
1
  {
2
2
  "name": "@zenstackhq/plugin-policy",
3
- "version": "3.0.0-beta.9",
3
+ "version": "3.1.0",
4
4
  "description": "ZenStack Policy Plugin",
5
5
  "type": "module",
6
6
  "keywords": [],
7
7
  "author": "ZenStack Team",
8
8
  "license": "MIT",
9
9
  "files": [
10
- "dist"
10
+ "dist",
11
+ "plugin.zmodel"
11
12
  ],
12
13
  "exports": {
13
14
  ".": {
@@ -20,6 +21,10 @@
20
21
  "default": "./dist/index.cjs"
21
22
  }
22
23
  },
24
+ "./plugin.zmodel": {
25
+ "import": "./plugin.zmodel",
26
+ "require": "./plugin.zmodel"
27
+ },
23
28
  "./package.json": {
24
29
  "import": "./package.json",
25
30
  "require": "./package.json"
@@ -27,19 +32,18 @@
27
32
  },
28
33
  "dependencies": {
29
34
  "ts-pattern": "^5.7.1",
30
- "@zenstackhq/common-helpers": "3.0.0-beta.9",
31
- "@zenstackhq/sdk": "3.0.0-beta.9",
32
- "@zenstackhq/runtime": "3.0.0-beta.9"
35
+ "@zenstackhq/common-helpers": "3.1.0",
36
+ "@zenstackhq/orm": "3.1.0"
33
37
  },
34
38
  "peerDependencies": {
35
- "kysely": "^0.27.6"
39
+ "kysely": "~0.28.8"
36
40
  },
37
41
  "devDependencies": {
38
42
  "@types/better-sqlite3": "^7.6.13",
39
43
  "@types/pg": "^8.0.0",
40
- "@zenstackhq/typescript-config": "3.0.0-beta.9",
41
- "@zenstackhq/eslint-config": "3.0.0-beta.9",
42
- "@zenstackhq/vitest-config": "3.0.0-beta.9"
44
+ "@zenstackhq/eslint-config": "3.1.0",
45
+ "@zenstackhq/typescript-config": "3.1.0",
46
+ "@zenstackhq/vitest-config": "3.1.0"
43
47
  },
44
48
  "scripts": {
45
49
  "build": "tsc --noEmit && tsup-node",
package/plugin.zmodel ADDED
@@ -0,0 +1,72 @@
1
+ /**
2
+ * Defines an access policy that allows a set of operations when the given condition is true.
3
+ *
4
+ * @param operation: comma-separated list of "create", "read", "update", "post-update", "delete". Use "all" to denote all operations.
5
+ * @param condition: a boolean expression that controls if the operation should be allowed.
6
+ */
7
+ attribute @@allow(_ operation: String @@@completionHint(["'create'", "'read'", "'update'", "'post-update'","'delete'", "'all'"]), _ condition: Boolean)
8
+
9
+ /**
10
+ * Defines an access policy that allows the annotated field to be read or updated.
11
+ * You can pass a third argument as `true` to make it override the model-level policies.
12
+ *
13
+ * @param operation: comma-separated list of "create", "read", "update", "post-update", "delete". Use "all" to denote all operations.
14
+ * @param condition: a boolean expression that controls if the operation should be allowed.
15
+ * @param override: a boolean value that controls if the field-level policy should override the model-level policy.
16
+ */
17
+ // attribute @allow(_ operation: String @@@completionHint(["'create'", "'read'", "'update'", "'post-update'", "'delete'", "'all'"]), _ condition: Boolean, _ override: Boolean?)
18
+
19
+ /**
20
+ * Defines an access policy that denies a set of operations when the given condition is true.
21
+ *
22
+ * @param operation: comma-separated list of "create", "read", "update", "post-update", "delete". Use "all" to denote all operations.
23
+ * @param condition: a boolean expression that controls if the operation should be denied.
24
+ */
25
+ attribute @@deny(_ operation: String @@@completionHint(["'create'", "'read'", "'update'", "'post-update'","'delete'", "'all'"]), _ condition: Boolean)
26
+
27
+ /**
28
+ * Defines an access policy that denies the annotated field to be read or updated.
29
+ *
30
+ * @param operation: comma-separated list of "create", "read", "update", "post-update", "delete". Use "all" to denote all operations.
31
+ * @param condition: a boolean expression that controls if the operation should be denied.
32
+ */
33
+ // attribute @deny(_ operation: String @@@completionHint(["'create'", "'read'", "'update'", "'delete'", "'all'"]), _ condition: Boolean)
34
+
35
+ /**
36
+ * Delegates the access control decision to a relation. Only to-one relations are supported.
37
+ *
38
+ * @param field: The relation field to delegate to.
39
+ * @param operation: The operation to check access for. Can be "read", "create", "update", "post-update", or "delete". If the operation is not provided,
40
+ * it defaults the operation of the containing policy rule.
41
+ */
42
+ function check(field: Any, operation: String?): Boolean {
43
+ } @@@expressionContext([AccessPolicy])
44
+
45
+ /**
46
+ * Gets entity's value before an update. Only valid when used in a "post-update" policy rule.
47
+ */
48
+ function before(): Any {
49
+ } @@@expressionContext([AccessPolicy])
50
+
51
+ /**
52
+ * The name of the model for which the policy rule is defined. If the rule is
53
+ * inherited to a sub model, this function returns the name of the sub model.
54
+ *
55
+ * @param optional parameter to control the casing of the returned value. Valid
56
+ * values are "original", "upper", "lower", "capitalize", "uncapitalize". Defaults
57
+ * to "original".
58
+ */
59
+ function currentModel(casing: String?): String {
60
+ } @@@expressionContext([AccessPolicy])
61
+
62
+ /**
63
+ * The operation for which the policy rule is defined for. Note that a rule with
64
+ * "all" operation is expanded to "create", "read", "update", and "delete" rules,
65
+ * and the function returns corresponding value for each expanded version.
66
+ *
67
+ * @param optional parameter to control the casing of the returned value. Valid
68
+ * values are "original", "upper", "lower", "capitalize", "uncapitalize". Defaults
69
+ * to "original".
70
+ */
71
+ function currentOperation(casing: String?): String {
72
+ } @@@expressionContext([AccessPolicy])