zenstack 1.0.0 → 1.0.16

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.
Files changed (264) hide show
  1. package/LICENSE +1 -1
  2. package/README.md +126 -1
  3. package/bin/cli +3 -0
  4. package/bin/post-install.js +24 -0
  5. package/cli/cli-error.d.ts +5 -0
  6. package/cli/cli-error.js +10 -0
  7. package/cli/cli-error.js.map +1 -0
  8. package/cli/cli-util.d.ts +18 -0
  9. package/cli/cli-util.js +143 -0
  10. package/cli/cli-util.js.map +1 -0
  11. package/cli/index.d.ts +15 -0
  12. package/cli/index.js +121 -0
  13. package/cli/index.js.map +1 -0
  14. package/cli/plugin-runner.d.ts +14 -0
  15. package/cli/plugin-runner.js +145 -0
  16. package/cli/plugin-runner.js.map +1 -0
  17. package/constants.d.ts +1 -0
  18. package/constants.js +6 -0
  19. package/constants.js.map +1 -0
  20. package/language-server/constants.d.ts +15 -0
  21. package/language-server/constants.js +20 -0
  22. package/language-server/constants.js.map +1 -0
  23. package/language-server/main.d.ts +1 -0
  24. package/language-server/main.js +13 -0
  25. package/language-server/main.js.map +1 -0
  26. package/language-server/types.d.ts +10 -0
  27. package/language-server/types.js +3 -0
  28. package/language-server/types.js.map +1 -0
  29. package/language-server/utils.d.ts +18 -0
  30. package/language-server/utils.js +58 -0
  31. package/language-server/utils.js.map +1 -0
  32. package/language-server/validator/attribute-validator.d.ts +9 -0
  33. package/language-server/validator/attribute-validator.js +11 -0
  34. package/language-server/validator/attribute-validator.js.map +1 -0
  35. package/language-server/validator/datamodel-validator.d.ts +15 -0
  36. package/language-server/validator/datamodel-validator.js +278 -0
  37. package/language-server/validator/datamodel-validator.js.map +1 -0
  38. package/language-server/validator/datasource-validator.d.ts +12 -0
  39. package/language-server/validator/datasource-validator.js +66 -0
  40. package/language-server/validator/datasource-validator.js.map +1 -0
  41. package/language-server/validator/enum-validator.d.ts +11 -0
  42. package/language-server/validator/enum-validator.js +28 -0
  43. package/language-server/validator/enum-validator.js.map +1 -0
  44. package/language-server/validator/expression-validator.d.ts +10 -0
  45. package/language-server/validator/expression-validator.js +30 -0
  46. package/language-server/validator/expression-validator.js.map +1 -0
  47. package/language-server/validator/schema-validator.d.ts +10 -0
  48. package/language-server/validator/schema-validator.js +28 -0
  49. package/language-server/validator/schema-validator.js.map +1 -0
  50. package/language-server/validator/utils.d.ts +25 -0
  51. package/language-server/validator/utils.js +257 -0
  52. package/language-server/validator/utils.js.map +1 -0
  53. package/language-server/validator/zmodel-validator.d.ts +21 -0
  54. package/language-server/validator/zmodel-validator.js +69 -0
  55. package/language-server/validator/zmodel-validator.js.map +1 -0
  56. package/language-server/zmodel-code-action.d.ts +14 -0
  57. package/language-server/zmodel-code-action.js +93 -0
  58. package/language-server/zmodel-code-action.js.map +1 -0
  59. package/language-server/zmodel-formatter.d.ts +9 -0
  60. package/language-server/zmodel-formatter.js +76 -0
  61. package/language-server/zmodel-formatter.js.map +1 -0
  62. package/language-server/zmodel-linker.d.ts +29 -0
  63. package/language-server/zmodel-linker.js +366 -0
  64. package/language-server/zmodel-linker.js.map +1 -0
  65. package/language-server/zmodel-module.d.ts +41 -0
  66. package/language-server/zmodel-module.js +80 -0
  67. package/language-server/zmodel-module.js.map +1 -0
  68. package/language-server/zmodel-scope.d.ts +10 -0
  69. package/language-server/zmodel-scope.js +44 -0
  70. package/language-server/zmodel-scope.js.map +1 -0
  71. package/language-server/zmodel-workspace-manager.d.ts +8 -0
  72. package/language-server/zmodel-workspace-manager.js +37 -0
  73. package/language-server/zmodel-workspace-manager.js.map +1 -0
  74. package/package.json +133 -8
  75. package/plugins/access-policy/expression-writer.d.ts +39 -0
  76. package/plugins/access-policy/expression-writer.js +361 -0
  77. package/plugins/access-policy/expression-writer.js.map +1 -0
  78. package/plugins/access-policy/index.d.ts +4 -0
  79. package/plugins/access-policy/index.js +24 -0
  80. package/plugins/access-policy/index.js.map +1 -0
  81. package/plugins/access-policy/policy-guard-generator.d.ts +15 -0
  82. package/plugins/access-policy/policy-guard-generator.js +349 -0
  83. package/plugins/access-policy/policy-guard-generator.js.map +1 -0
  84. package/plugins/access-policy/typescript-expression-transformer.d.ts +26 -0
  85. package/plugins/access-policy/typescript-expression-transformer.js +111 -0
  86. package/plugins/access-policy/typescript-expression-transformer.js.map +1 -0
  87. package/plugins/access-policy/utils.d.ts +5 -0
  88. package/plugins/access-policy/utils.js +14 -0
  89. package/plugins/access-policy/utils.js.map +1 -0
  90. package/plugins/access-policy/zod-schema-generator.d.ts +12 -0
  91. package/plugins/access-policy/zod-schema-generator.js +158 -0
  92. package/plugins/access-policy/zod-schema-generator.js.map +1 -0
  93. package/plugins/model-meta/index.d.ts +4 -0
  94. package/plugins/model-meta/index.js +168 -0
  95. package/plugins/model-meta/index.js.map +1 -0
  96. package/plugins/plugin-utils.d.ts +16 -0
  97. package/plugins/plugin-utils.js +54 -0
  98. package/plugins/plugin-utils.js.map +1 -0
  99. package/plugins/prisma/indent-string.d.ts +4 -0
  100. package/plugins/prisma/indent-string.js +12 -0
  101. package/plugins/prisma/indent-string.js.map +1 -0
  102. package/plugins/prisma/index.d.ts +4 -0
  103. package/plugins/prisma/index.js +24 -0
  104. package/plugins/prisma/index.js.map +1 -0
  105. package/plugins/prisma/prisma-builder.d.ts +152 -0
  106. package/plugins/prisma/prisma-builder.js +363 -0
  107. package/plugins/prisma/prisma-builder.js.map +1 -0
  108. package/plugins/prisma/schema-generator.d.ts +25 -0
  109. package/plugins/prisma/schema-generator.js +292 -0
  110. package/plugins/prisma/schema-generator.js.map +1 -0
  111. package/plugins/prisma/zmodel-code-generator.d.ts +28 -0
  112. package/plugins/prisma/zmodel-code-generator.js +114 -0
  113. package/plugins/prisma/zmodel-code-generator.js.map +1 -0
  114. package/res/prism-zmodel.js +20 -0
  115. package/res/starter.zmodel +51 -0
  116. package/res/stdlib.zmodel +346 -0
  117. package/telemetry.d.ts +20 -0
  118. package/telemetry.js +119 -0
  119. package/telemetry.js.map +1 -0
  120. package/types.d.ts +12 -0
  121. package/types.js +3 -0
  122. package/types.js.map +1 -0
  123. package/utils/ast-utils.d.ts +16 -0
  124. package/utils/ast-utils.js +85 -0
  125. package/utils/ast-utils.js.map +1 -0
  126. package/utils/exec-utils.d.ts +6 -0
  127. package/utils/exec-utils.js +13 -0
  128. package/utils/exec-utils.js.map +1 -0
  129. package/utils/pkg-utils.d.ts +3 -0
  130. package/utils/pkg-utils.js +46 -0
  131. package/utils/pkg-utils.js.map +1 -0
  132. package/utils/version-utils.d.ts +1 -0
  133. package/utils/version-utils.js +14 -0
  134. package/utils/version-utils.js.map +1 -0
  135. package/.vscode/extensions.json +0 -7
  136. package/.vscode/launch.json +0 -49
  137. package/.vscode/settings.json +0 -4
  138. package/packages/internal/jest.config.ts +0 -32
  139. package/packages/internal/package.json +0 -42
  140. package/packages/internal/src/constants.ts +0 -1
  141. package/packages/internal/src/handler/data/guard-utils.ts +0 -7
  142. package/packages/internal/src/handler/data/handler.ts +0 -415
  143. package/packages/internal/src/handler/data/query-processor.ts +0 -504
  144. package/packages/internal/src/handler/index.ts +0 -1
  145. package/packages/internal/src/handler/types.ts +0 -20
  146. package/packages/internal/src/index.ts +0 -3
  147. package/packages/internal/src/request-handler.ts +0 -27
  148. package/packages/internal/src/request.ts +0 -101
  149. package/packages/internal/src/types.ts +0 -40
  150. package/packages/internal/tests/query-processor.test.ts +0 -172
  151. package/packages/internal/tsconfig.json +0 -21
  152. package/packages/runtime/auth.d.ts +0 -1
  153. package/packages/runtime/auth.js +0 -3
  154. package/packages/runtime/hooks.d.ts +0 -10
  155. package/packages/runtime/hooks.js +0 -3
  156. package/packages/runtime/index.d.ts +0 -3
  157. package/packages/runtime/index.js +0 -1
  158. package/packages/runtime/package-lock.json +0 -512
  159. package/packages/runtime/package.json +0 -16
  160. package/packages/runtime/server.d.ts +0 -1
  161. package/packages/runtime/server.js +0 -3
  162. package/packages/runtime/types.d.ts +0 -1
  163. package/packages/runtime/types.js +0 -3
  164. package/packages/schema/.eslintrc.json +0 -13
  165. package/packages/schema/.vscodeignore +0 -4
  166. package/packages/schema/asset/logo-dark.png +0 -0
  167. package/packages/schema/asset/logo-light.png +0 -0
  168. package/packages/schema/bin/cli +0 -3
  169. package/packages/schema/jest.config.ts +0 -32
  170. package/packages/schema/langium-config.json +0 -14
  171. package/packages/schema/langium-quickstart.md +0 -41
  172. package/packages/schema/language-configuration.json +0 -30
  173. package/packages/schema/package.json +0 -96
  174. package/packages/schema/src/cli/cli-util.ts +0 -80
  175. package/packages/schema/src/cli/index.ts +0 -64
  176. package/packages/schema/src/extension.ts +0 -76
  177. package/packages/schema/src/generator/constants.ts +0 -5
  178. package/packages/schema/src/generator/index.ts +0 -92
  179. package/packages/schema/src/generator/next-auth/index.ts +0 -197
  180. package/packages/schema/src/generator/package.template.json +0 -9
  181. package/packages/schema/src/generator/prisma/expression-writer.ts +0 -352
  182. package/packages/schema/src/generator/prisma/index.ts +0 -32
  183. package/packages/schema/src/generator/prisma/plain-expression-builder.ts +0 -91
  184. package/packages/schema/src/generator/prisma/prisma-builder.ts +0 -366
  185. package/packages/schema/src/generator/prisma/query-gard-generator.ts +0 -208
  186. package/packages/schema/src/generator/prisma/schema-generator.ts +0 -300
  187. package/packages/schema/src/generator/react-hooks/index.ts +0 -181
  188. package/packages/schema/src/generator/service/index.ts +0 -107
  189. package/packages/schema/src/generator/tsconfig.template.json +0 -17
  190. package/packages/schema/src/generator/types.ts +0 -17
  191. package/packages/schema/src/generator/utils.ts +0 -9
  192. package/packages/schema/src/language-server/generated/ast.ts +0 -603
  193. package/packages/schema/src/language-server/generated/grammar.ts +0 -2190
  194. package/packages/schema/src/language-server/generated/module.ts +0 -24
  195. package/packages/schema/src/language-server/main.ts +0 -12
  196. package/packages/schema/src/language-server/stdlib.zmodel +0 -22
  197. package/packages/schema/src/language-server/types.ts +0 -9
  198. package/packages/schema/src/language-server/zmodel-index.ts +0 -33
  199. package/packages/schema/src/language-server/zmodel-linker.ts +0 -409
  200. package/packages/schema/src/language-server/zmodel-module.ts +0 -90
  201. package/packages/schema/src/language-server/zmodel-scope.ts +0 -21
  202. package/packages/schema/src/language-server/zmodel-validator.ts +0 -35
  203. package/packages/schema/src/language-server/zmodel.langium +0 -186
  204. package/packages/schema/src/utils/exec-utils.ts +0 -5
  205. package/packages/schema/src/utils/indent-string.ts +0 -6
  206. package/packages/schema/syntaxes/zmodel.json +0 -57
  207. package/packages/schema/syntaxes/zmodel.tmLanguage.json +0 -57
  208. package/packages/schema/tests/generator/expression-writer.test.ts +0 -676
  209. package/packages/schema/tests/generator/prisma-builder.test.ts +0 -138
  210. package/packages/schema/tests/schema/parser.test.ts +0 -423
  211. package/packages/schema/tests/schema/sample-todo.test.ts +0 -14
  212. package/packages/schema/tests/utils.ts +0 -38
  213. package/packages/schema/tsconfig.json +0 -23
  214. package/pnpm-workspace.yaml +0 -3
  215. package/samples/todo/.env +0 -2
  216. package/samples/todo/.eslintrc.json +0 -3
  217. package/samples/todo/.vscode/launch.json +0 -11
  218. package/samples/todo/README.md +0 -34
  219. package/samples/todo/components/AuthGuard.tsx +0 -17
  220. package/samples/todo/components/Avatar.tsx +0 -22
  221. package/samples/todo/components/BreadCrumb.tsx +0 -44
  222. package/samples/todo/components/ManageMembers.tsx +0 -134
  223. package/samples/todo/components/NavBar.tsx +0 -57
  224. package/samples/todo/components/SpaceMembers.tsx +0 -76
  225. package/samples/todo/components/Spaces.tsx +0 -28
  226. package/samples/todo/components/TimeInfo.tsx +0 -17
  227. package/samples/todo/components/Todo.tsx +0 -72
  228. package/samples/todo/components/TodoList.tsx +0 -77
  229. package/samples/todo/lib/context.ts +0 -31
  230. package/samples/todo/next.config.js +0 -10
  231. package/samples/todo/package-lock.json +0 -7527
  232. package/samples/todo/package.json +0 -45
  233. package/samples/todo/pages/_app.tsx +0 -50
  234. package/samples/todo/pages/api/auth/[...nextauth].ts +0 -83
  235. package/samples/todo/pages/api/zenstack/[...path].ts +0 -16
  236. package/samples/todo/pages/create-space.tsx +0 -114
  237. package/samples/todo/pages/index.tsx +0 -32
  238. package/samples/todo/pages/space/[slug]/[listId]/index.tsx +0 -88
  239. package/samples/todo/pages/space/[slug]/index.tsx +0 -169
  240. package/samples/todo/postcss.config.js +0 -6
  241. package/samples/todo/public/avatar.jpg +0 -0
  242. package/samples/todo/public/favicon.ico +0 -0
  243. package/samples/todo/public/logo.png +0 -0
  244. package/samples/todo/public/vercel.svg +0 -4
  245. package/samples/todo/styles/globals.css +0 -7
  246. package/samples/todo/tailwind.config.js +0 -11
  247. package/samples/todo/tsconfig.json +0 -28
  248. package/samples/todo/types/next-auth.d.ts +0 -14
  249. package/samples/todo/types/next.d.ts +0 -16
  250. package/samples/todo/zenstack/migrations/20221014084317_init/migration.sql +0 -153
  251. package/samples/todo/zenstack/migrations/20221020094651_upate_cli/migration.sql +0 -23
  252. package/samples/todo/zenstack/migrations/migration_lock.toml +0 -3
  253. package/samples/todo/zenstack/schema.prisma +0 -126
  254. package/samples/todo/zenstack/schema.zmodel +0 -161
  255. package/tests/integration/jest.config.ts +0 -16
  256. package/tests/integration/package-lock.json +0 -1081
  257. package/tests/integration/package.json +0 -27
  258. package/tests/integration/tests/operation-coverate.test.ts +0 -563
  259. package/tests/integration/tests/operations.zmodel +0 -69
  260. package/tests/integration/tests/todo-e2e.test.ts +0 -577
  261. package/tests/integration/tests/todo.zmodel +0 -123
  262. package/tests/integration/tests/tsconfig.template.json +0 -10
  263. package/tests/integration/tests/utils.ts +0 -133
  264. package/tests/integration/tsconfig.json +0 -10
@@ -1,27 +0,0 @@
1
- {
2
- "name": "integration",
3
- "version": "1.0.0",
4
- "description": "",
5
- "main": "index.js",
6
- "scripts": {
7
- "test": "jest --runInBand"
8
- },
9
- "keywords": [],
10
- "author": "",
11
- "license": "ISC",
12
- "devDependencies": {
13
- "@types/jest": "^29.0.3",
14
- "@types/supertest": "^2.0.12",
15
- "@types/tmp": "^0.2.3",
16
- "jest": "^29.0.3",
17
- "next": "^12.3.1",
18
- "supertest": "^6.3.0",
19
- "tmp": "^0.2.1",
20
- "ts-jest": "^29.0.1",
21
- "ts-node": "^10.9.1",
22
- "typescript": "^4.6.2"
23
- },
24
- "dependencies": {
25
- "@types/node": "^14.18.29"
26
- }
27
- }
@@ -1,563 +0,0 @@
1
- import path from 'path';
2
- import { makeClient, run, setup } from './utils';
3
-
4
- describe('Operation Coverage Tests', () => {
5
- let workDir: string;
6
- let origDir: string;
7
-
8
- beforeAll(async () => {
9
- origDir = path.resolve('.');
10
- workDir = await setup('./tests/operations.zmodel');
11
- });
12
-
13
- beforeEach(() => {
14
- run('npx prisma migrate reset --schema ./zenstack/schema.prisma -f');
15
- });
16
-
17
- afterAll(() => {
18
- process.chdir(origDir);
19
- });
20
-
21
- //#region Empty Policy
22
-
23
- it('empty policy', async () => {
24
- const client = makeClient('/api/data/EmptyPolicy');
25
- await client.post('/').send({ data: {} }).expect(403);
26
- await client
27
- .get('/')
28
- .expect((resp) => expect(resp.body).toHaveLength(0));
29
- });
30
-
31
- it('nested write empty policy to-many', async () => {
32
- const client = makeClient('/api/data/M1');
33
- await client
34
- .post('/')
35
- .send({
36
- data: {
37
- m2: {
38
- create: [{}],
39
- },
40
- },
41
- })
42
- .expect(403);
43
- });
44
-
45
- it('nested write empty policy to-one', async () => {
46
- const client = makeClient('/api/data/M1');
47
- await client
48
- .post('/')
49
- .send({
50
- data: {
51
- m3: {
52
- create: {},
53
- },
54
- },
55
- })
56
- .expect(403);
57
- });
58
-
59
- //#endregion
60
-
61
- //#region Toplevel operations
62
-
63
- it('toplevel find and get', async () => {
64
- await makeClient('/api/data/M4')
65
- .post('/')
66
- .send({
67
- data: {
68
- id: '1',
69
- value: 1,
70
- },
71
- })
72
- .expect(201);
73
-
74
- await makeClient('/api/data/M4')
75
- .get('/')
76
- .expect((resp) => expect(resp.body).toHaveLength(0));
77
-
78
- await makeClient('/api/data/M4/1').get('/').expect(404);
79
-
80
- await makeClient('/api/data/M4')
81
- .post('/')
82
- .send({
83
- data: {
84
- id: '2',
85
- value: 2,
86
- },
87
- })
88
- .expect(201);
89
-
90
- await makeClient('/api/data/M4')
91
- .get('/')
92
- .expect((resp) => expect(resp.body).toHaveLength(1));
93
-
94
- await makeClient('/api/data/M4/2').get('/').expect(200);
95
- });
96
-
97
- it('toplevel create, update and delete', async () => {
98
- await makeClient('/api/data/M4')
99
- .post('/')
100
- .send({
101
- data: {
102
- value: 0,
103
- },
104
- })
105
- .expect(403);
106
-
107
- await makeClient('/api/data/M4')
108
- .post('/')
109
- .send({
110
- data: {
111
- id: '1',
112
- value: 1,
113
- },
114
- })
115
- .expect(201);
116
-
117
- await makeClient('/api/data/M4/1')
118
- .put('/')
119
- .send({
120
- data: {
121
- value: 1,
122
- },
123
- })
124
- .expect(403);
125
-
126
- await makeClient('/api/data/M4')
127
- .post('/')
128
- .send({
129
- data: {
130
- id: '2',
131
- value: 2,
132
- },
133
- })
134
- .expect(201);
135
-
136
- await makeClient('/api/data/M4/2')
137
- .put('/')
138
- .send({
139
- data: {
140
- value: 3,
141
- },
142
- })
143
- .expect(200);
144
-
145
- await makeClient('/api/data/M4/1').delete('/').expect(403);
146
- await makeClient('/api/data/M4/2').delete('/').expect(200);
147
- });
148
-
149
- //#endregion
150
-
151
- //#region Nested To-one
152
-
153
- it('nested to-one writes', async () => {
154
- await makeClient('/api/data/M5')
155
- .post('/')
156
- .send({
157
- data: {
158
- m6: {
159
- create: {
160
- value: 0,
161
- },
162
- },
163
- },
164
- })
165
- .expect(403);
166
-
167
- await makeClient('/api/data/M5')
168
- .post('/')
169
- .send({
170
- data: {
171
- id: '1',
172
- m6: {
173
- create: {
174
- id: '1',
175
- value: 1,
176
- },
177
- },
178
- },
179
- })
180
- .expect(201);
181
-
182
- await makeClient('/api/data/M5/1')
183
- .put('/')
184
- .send({
185
- data: {
186
- m6: {
187
- update: {
188
- value: 2,
189
- },
190
- },
191
- },
192
- })
193
- .expect(403);
194
-
195
- await makeClient('/api/data/M5')
196
- .post('/')
197
- .send({
198
- data: {
199
- id: '2',
200
- m6: {
201
- create: {
202
- id: '2',
203
- value: 2,
204
- },
205
- },
206
- },
207
- })
208
- .expect(201);
209
-
210
- await makeClient('/api/data/M5/2')
211
- .put('/')
212
- .send({
213
- data: {
214
- id: '2',
215
- m6: {
216
- delete: true,
217
- },
218
- },
219
- })
220
- .expect(403);
221
-
222
- await makeClient('/api/data/M5/2')
223
- .put('/')
224
- .send({
225
- data: {
226
- m6: {
227
- update: {
228
- value: 3,
229
- },
230
- },
231
- },
232
- })
233
- .expect(200);
234
-
235
- await makeClient('/api/data/M6/2').get('/').expect(200);
236
-
237
- await makeClient('/api/data/M5/2')
238
- .put('/')
239
- .send({
240
- data: {
241
- id: '2',
242
- m6: {
243
- delete: true,
244
- },
245
- },
246
- })
247
- .expect(200);
248
-
249
- await makeClient('/api/data/M6/2').get('/').expect(404);
250
- });
251
-
252
- //#endregion
253
-
254
- //#region Nested To-many
255
-
256
- it('nested to-many create denied', async () => {
257
- const client = makeClient('/api/data/M5');
258
-
259
- // single-create
260
- await client
261
- .post('/')
262
- .send({
263
- data: {
264
- m7: {
265
- create: {
266
- value: 0,
267
- },
268
- },
269
- },
270
- })
271
- .expect(403);
272
-
273
- // multi-create
274
- await client
275
- .post('/')
276
- .send({
277
- data: {
278
- m7: {
279
- create: [
280
- {
281
- value: 0,
282
- },
283
- {
284
- value: 1,
285
- },
286
- ],
287
- },
288
- },
289
- })
290
- .expect(403);
291
- });
292
-
293
- it('nested to-many create allowed', async () => {
294
- const client = makeClient('/api/data/M5');
295
-
296
- // single-create
297
- await client
298
- .post('/')
299
- .send({
300
- data: {
301
- m7: {
302
- create: {
303
- value: 1,
304
- },
305
- },
306
- },
307
- })
308
- .expect(201);
309
-
310
- // multi-create
311
- await client
312
- .post('/')
313
- .send({
314
- data: {
315
- m7: {
316
- create: [
317
- {
318
- value: 1,
319
- },
320
- {
321
- value: 2,
322
- },
323
- ],
324
- },
325
- },
326
- })
327
- .expect(201);
328
- });
329
-
330
- it('nested to-many update', async () => {
331
- // nested entities don't satisify policy before update, so should be excluded
332
- await makeClient('/api/data/M5')
333
- .post('/')
334
- .send({
335
- data: {
336
- id: '1',
337
- m7: {
338
- create: [
339
- {
340
- id: '1',
341
- value: 1,
342
- },
343
- ],
344
- },
345
- },
346
- })
347
- .expect(201);
348
-
349
- await makeClient('/api/data/M5/1')
350
- .put('/')
351
- .send({
352
- include: { m7: true },
353
- data: {
354
- m7: {
355
- update: {
356
- where: { id: '1' },
357
- data: { value: 2 },
358
- },
359
- },
360
- },
361
- })
362
- .expect(200)
363
- .expect((resp) => {
364
- expect(resp.body.m7).toEqual(
365
- expect.arrayContaining([
366
- expect.objectContaining({ id: '1', value: 1 }),
367
- ])
368
- );
369
- });
370
-
371
- // nested entities satisify policy before update, so should be included for update
372
- await makeClient('/api/data/M5')
373
- .post('/')
374
- .send({
375
- data: {
376
- id: '2',
377
- m7: {
378
- create: {
379
- id: '2',
380
- value: 2,
381
- },
382
- },
383
- },
384
- })
385
- .expect(201);
386
-
387
- await makeClient('/api/data/M5/2')
388
- .put('/')
389
- .send({
390
- include: { m7: true },
391
- data: {
392
- m7: {
393
- update: {
394
- where: { id: '2' },
395
- data: { value: 3 },
396
- },
397
- },
398
- },
399
- })
400
- .expect(200)
401
- .expect((resp) => {
402
- expect(resp.body.m7).toEqual(
403
- expect.arrayContaining([
404
- expect.objectContaining({ id: '2', value: 3 }),
405
- ])
406
- );
407
- });
408
- });
409
-
410
- it('nested to-many update with create', async () => {
411
- await makeClient('/api/data/M5')
412
- .post('/')
413
- .send({
414
- data: {
415
- id: '1',
416
- m7: {
417
- create: {
418
- value: 1,
419
- },
420
- },
421
- },
422
- })
423
- .expect(201);
424
-
425
- await makeClient('/api/data/M5/1')
426
- .put('/')
427
- .send({
428
- data: {
429
- m7: {
430
- create: {
431
- id: '2',
432
- value: 0,
433
- },
434
- },
435
- },
436
- })
437
- .expect(403);
438
-
439
- await makeClient('/api/data/M5/1')
440
- .put('/')
441
- .send({
442
- data: {
443
- m7: {
444
- create: [
445
- {
446
- value: 0,
447
- },
448
- {
449
- value: 1,
450
- },
451
- ],
452
- },
453
- },
454
- })
455
- .expect(403);
456
-
457
- await makeClient('/api/data/M5/1')
458
- .put('/')
459
- .send({
460
- include: { m7: true },
461
- data: {
462
- m7: {
463
- create: [
464
- {
465
- value: 1,
466
- },
467
- {
468
- value: 2,
469
- },
470
- ],
471
- },
472
- },
473
- })
474
- .expect(200)
475
- .expect((resp) => {
476
- expect(resp.body.m7).toHaveLength(3);
477
- });
478
- });
479
-
480
- it('nested to-many update with delete', async () => {
481
- await makeClient('/api/data/M5')
482
- .post('/')
483
- .send({
484
- data: {
485
- id: '1',
486
- m7: {
487
- create: [
488
- {
489
- id: '1',
490
- value: 1,
491
- },
492
- {
493
- id: '2',
494
- value: 2,
495
- },
496
- {
497
- id: '3',
498
- value: 3,
499
- },
500
- {
501
- id: '4',
502
- value: 4,
503
- },
504
- {
505
- id: '5',
506
- value: 5,
507
- },
508
- ],
509
- },
510
- },
511
- })
512
- .expect(201);
513
-
514
- await makeClient('/api/data/M5/1')
515
- .put('/')
516
- .send({
517
- data: {
518
- m7: {
519
- delete: { id: '1' },
520
- },
521
- },
522
- })
523
- .expect(403);
524
-
525
- await makeClient('/api/data/M5/1')
526
- .put('/')
527
- .send({
528
- data: {
529
- m7: {
530
- deleteMany: { OR: [{ id: '2' }, { id: '3' }] },
531
- },
532
- },
533
- })
534
- .expect(403);
535
-
536
- await makeClient('/api/data/M5/1')
537
- .put('/')
538
- .send({
539
- data: {
540
- m7: {
541
- delete: { id: '3' },
542
- },
543
- },
544
- })
545
- .expect(200);
546
- await makeClient('/api/data/M7/3').get('/').expect(404);
547
-
548
- await makeClient('/api/data/M5/1')
549
- .put('/')
550
- .send({
551
- data: {
552
- m7: {
553
- deleteMany: { value: { gte: 4 } },
554
- },
555
- },
556
- })
557
- .expect(200);
558
- await makeClient('/api/data/M7/4').get('/').expect(404);
559
- await makeClient('/api/data/M7/5').get('/').expect(404);
560
- });
561
-
562
- //#endregion
563
- });
@@ -1,69 +0,0 @@
1
- datasource db {
2
- provider = 'sqlite'
3
- url = 'file:./operations.db'
4
- }
5
-
6
- model EmptyPolicy {
7
- id String @id @default(uuid())
8
- }
9
-
10
- model M1 {
11
- id String @id @default(uuid())
12
- m2 M2[]
13
- m3 M3?
14
-
15
- @@allow('all', true)
16
- }
17
-
18
- model M2 {
19
- id String @id @default(uuid())
20
- m1 M1 @relation(fields: [m1Id], references:[id])
21
- m1Id String
22
- }
23
-
24
- model M3 {
25
- id String @id @default(uuid())
26
- m1 M1 @relation(fields: [m1Id], references:[id])
27
- m1Id String @unique
28
- }
29
-
30
- model M4 {
31
- id String @id @default(uuid())
32
- value Int
33
-
34
- @@allow('read', value > 1)
35
- @@allow('create', value > 0)
36
- @@allow('update', value > 1)
37
- @@allow('delete', value > 2)
38
- }
39
-
40
- model M5 {
41
- id String @id @default(uuid())
42
- m6 M6?
43
- m7 M7[]
44
-
45
- @@allow('all', true)
46
- }
47
-
48
- model M6 {
49
- id String @id @default(uuid())
50
- value Int
51
- m5 M5 @relation(fields: [m5Id], references:[id])
52
- m5Id String @unique
53
-
54
- @@allow('read', true)
55
- @@allow('create', value > 0)
56
- @@allow('update', value > 1)
57
- @@allow('delete', value > 2)
58
- }
59
-
60
- model M7 {
61
- id String @id @default(uuid())
62
- value Int
63
- m5 M5 @relation(fields: [m5Id], references:[id])
64
- m5Id String
65
-
66
- @@allow('create', value > 0)
67
- @@allow('update', value > 1)
68
- @@allow('delete', value > 2)
69
- }