zenstack 1.0.0 → 1.0.2
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/LICENSE +1 -1
- package/README.md +194 -1
- package/bin/cli +3 -0
- package/bin/post-install.js +24 -0
- package/cli/actions/generate.d.ts +13 -0
- package/cli/actions/generate.js +71 -0
- package/cli/actions/generate.js.map +1 -0
- package/cli/actions/index.d.ts +3 -0
- package/cli/actions/index.js +20 -0
- package/cli/actions/index.js.map +1 -0
- package/cli/actions/info.d.ts +4 -0
- package/cli/actions/info.js +63 -0
- package/cli/actions/info.js.map +1 -0
- package/cli/actions/init.d.ts +12 -0
- package/cli/actions/init.js +83 -0
- package/cli/actions/init.js.map +1 -0
- package/cli/cli-error.d.ts +5 -0
- package/cli/cli-error.js +10 -0
- package/cli/cli-error.js.map +1 -0
- package/cli/cli-util.d.ts +21 -0
- package/cli/cli-util.js +211 -0
- package/cli/cli-util.js.map +1 -0
- package/cli/config.d.ts +10 -0
- package/cli/config.js +62 -0
- package/cli/config.js.map +1 -0
- package/cli/index.d.ts +7 -0
- package/cli/index.js +128 -0
- package/cli/index.js.map +1 -0
- package/cli/plugin-runner.d.ts +24 -0
- package/cli/plugin-runner.js +229 -0
- package/cli/plugin-runner.js.map +1 -0
- package/constants.d.ts +1 -0
- package/constants.js +6 -0
- package/constants.js.map +1 -0
- package/language-server/constants.d.ts +22 -0
- package/language-server/constants.js +27 -0
- package/language-server/constants.js.map +1 -0
- package/language-server/main.d.ts +1 -0
- package/language-server/main.js +13 -0
- package/language-server/main.js.map +1 -0
- package/language-server/types.d.ts +10 -0
- package/language-server/types.js +3 -0
- package/language-server/types.js.map +1 -0
- package/language-server/utils.d.ts +5 -0
- package/language-server/utils.js +22 -0
- package/language-server/utils.js.map +1 -0
- package/language-server/validator/attribute-application-validator.d.ts +15 -0
- package/language-server/validator/attribute-application-validator.js +246 -0
- package/language-server/validator/attribute-application-validator.js.map +1 -0
- package/language-server/validator/attribute-validator.d.ts +9 -0
- package/language-server/validator/attribute-validator.js +14 -0
- package/language-server/validator/attribute-validator.js.map +1 -0
- package/language-server/validator/datamodel-validator.d.ts +22 -0
- package/language-server/validator/datamodel-validator.js +329 -0
- package/language-server/validator/datamodel-validator.js.map +1 -0
- package/language-server/validator/datasource-validator.d.ts +12 -0
- package/language-server/validator/datasource-validator.js +66 -0
- package/language-server/validator/datasource-validator.js.map +1 -0
- package/language-server/validator/enum-validator.d.ts +11 -0
- package/language-server/validator/enum-validator.js +25 -0
- package/language-server/validator/enum-validator.js.map +1 -0
- package/language-server/validator/expression-validator.d.ts +10 -0
- package/language-server/validator/expression-validator.js +135 -0
- package/language-server/validator/expression-validator.js.map +1 -0
- package/language-server/validator/function-decl-validator.d.ts +9 -0
- package/language-server/validator/function-decl-validator.js +13 -0
- package/language-server/validator/function-decl-validator.js.map +1 -0
- package/language-server/validator/function-invocation-validator.d.ts +11 -0
- package/language-server/validator/function-invocation-validator.js +135 -0
- package/language-server/validator/function-invocation-validator.js.map +1 -0
- package/language-server/validator/schema-validator.d.ts +13 -0
- package/language-server/validator/schema-validator.js +49 -0
- package/language-server/validator/schema-validator.js.map +1 -0
- package/language-server/validator/utils.d.ts +24 -0
- package/language-server/validator/utils.js +154 -0
- package/language-server/validator/utils.js.map +1 -0
- package/language-server/validator/zmodel-validator.d.ts +25 -0
- package/language-server/validator/zmodel-validator.js +83 -0
- package/language-server/validator/zmodel-validator.js.map +1 -0
- package/language-server/zmodel-code-action.d.ts +15 -0
- package/language-server/zmodel-code-action.js +118 -0
- package/language-server/zmodel-code-action.js.map +1 -0
- package/language-server/zmodel-definition.d.ts +7 -0
- package/language-server/zmodel-definition.js +31 -0
- package/language-server/zmodel-definition.js.map +1 -0
- package/language-server/zmodel-formatter.d.ts +9 -0
- package/language-server/zmodel-formatter.js +76 -0
- package/language-server/zmodel-formatter.js.map +1 -0
- package/language-server/zmodel-linker.d.ts +32 -0
- package/language-server/zmodel-linker.js +447 -0
- package/language-server/zmodel-linker.js.map +1 -0
- package/language-server/zmodel-module.d.ts +41 -0
- package/language-server/zmodel-module.js +83 -0
- package/language-server/zmodel-module.js.map +1 -0
- package/language-server/zmodel-scope.d.ts +16 -0
- package/language-server/zmodel-scope.js +100 -0
- package/language-server/zmodel-scope.js.map +1 -0
- package/language-server/zmodel-workspace-manager.d.ts +12 -0
- package/language-server/zmodel-workspace-manager.js +138 -0
- package/language-server/zmodel-workspace-manager.js.map +1 -0
- package/package.json +140 -8
- package/plugins/access-policy/expression-writer.d.ts +46 -0
- package/plugins/access-policy/expression-writer.js +580 -0
- package/plugins/access-policy/expression-writer.js.map +1 -0
- package/plugins/access-policy/index.d.ts +4 -0
- package/plugins/access-policy/index.js +22 -0
- package/plugins/access-policy/index.js.map +1 -0
- package/plugins/access-policy/policy-guard-generator.d.ts +22 -0
- package/plugins/access-policy/policy-guard-generator.js +634 -0
- package/plugins/access-policy/policy-guard-generator.js.map +1 -0
- package/plugins/model-meta/index.d.ts +4 -0
- package/plugins/model-meta/index.js +232 -0
- package/plugins/model-meta/index.js.map +1 -0
- package/plugins/plugin-utils.d.ts +17 -0
- package/plugins/plugin-utils.js +80 -0
- package/plugins/plugin-utils.js.map +1 -0
- package/plugins/prisma/indent-string.d.ts +4 -0
- package/plugins/prisma/indent-string.js +12 -0
- package/plugins/prisma/indent-string.js.map +1 -0
- package/plugins/prisma/index.d.ts +4 -0
- package/plugins/prisma/index.js +22 -0
- package/plugins/prisma/index.js.map +1 -0
- package/plugins/prisma/prisma-builder.d.ts +145 -0
- package/plugins/prisma/prisma-builder.js +358 -0
- package/plugins/prisma/prisma-builder.js.map +1 -0
- package/plugins/prisma/schema-generator.d.ts +29 -0
- package/plugins/prisma/schema-generator.js +336 -0
- package/plugins/prisma/schema-generator.js.map +1 -0
- package/plugins/prisma/zmodel-code-generator.d.ts +30 -0
- package/plugins/prisma/zmodel-code-generator.js +124 -0
- package/plugins/prisma/zmodel-code-generator.js.map +1 -0
- package/plugins/zod/generator.d.ts +4 -0
- package/plugins/zod/generator.js +254 -0
- package/plugins/zod/generator.js.map +1 -0
- package/plugins/zod/index.d.ts +4 -0
- package/plugins/zod/index.js +24 -0
- package/plugins/zod/index.js.map +1 -0
- package/plugins/zod/transformer.d.ts +68 -0
- package/plugins/zod/transformer.js +554 -0
- package/plugins/zod/transformer.js.map +1 -0
- package/plugins/zod/types.d.ts +25 -0
- package/plugins/zod/types.js +3 -0
- package/plugins/zod/types.js.map +1 -0
- package/plugins/zod/utils/removeDir.d.ts +1 -0
- package/plugins/zod/utils/removeDir.js +30 -0
- package/plugins/zod/utils/removeDir.js.map +1 -0
- package/plugins/zod/utils/schema-gen.d.ts +3 -0
- package/plugins/zod/utils/schema-gen.js +188 -0
- package/plugins/zod/utils/schema-gen.js.map +1 -0
- package/res/prism-zmodel.js +20 -0
- package/res/starter.zmodel +51 -0
- package/res/stdlib.zmodel +506 -0
- package/telemetry.d.ts +21 -0
- package/telemetry.js +129 -0
- package/telemetry.js.map +1 -0
- package/utils/ast-utils.d.ts +13 -0
- package/utils/ast-utils.js +136 -0
- package/utils/ast-utils.js.map +1 -0
- package/utils/exec-utils.d.ts +6 -0
- package/utils/exec-utils.js +13 -0
- package/utils/exec-utils.js.map +1 -0
- package/utils/pkg-utils.d.ts +3 -0
- package/utils/pkg-utils.js +64 -0
- package/utils/pkg-utils.js.map +1 -0
- package/utils/typescript-expression-transformer.d.ts +54 -0
- package/utils/typescript-expression-transformer.js +326 -0
- package/utils/typescript-expression-transformer.js.map +1 -0
- package/utils/version-utils.d.ts +1 -0
- package/utils/version-utils.js +20 -0
- package/utils/version-utils.js.map +1 -0
- package/.vscode/extensions.json +0 -7
- package/.vscode/launch.json +0 -49
- package/.vscode/settings.json +0 -4
- package/packages/internal/jest.config.ts +0 -32
- package/packages/internal/package.json +0 -42
- package/packages/internal/src/constants.ts +0 -1
- package/packages/internal/src/handler/data/guard-utils.ts +0 -7
- package/packages/internal/src/handler/data/handler.ts +0 -415
- package/packages/internal/src/handler/data/query-processor.ts +0 -504
- package/packages/internal/src/handler/index.ts +0 -1
- package/packages/internal/src/handler/types.ts +0 -20
- package/packages/internal/src/index.ts +0 -3
- package/packages/internal/src/request-handler.ts +0 -27
- package/packages/internal/src/request.ts +0 -101
- package/packages/internal/src/types.ts +0 -40
- package/packages/internal/tests/query-processor.test.ts +0 -172
- package/packages/internal/tsconfig.json +0 -21
- package/packages/runtime/auth.d.ts +0 -1
- package/packages/runtime/auth.js +0 -3
- package/packages/runtime/hooks.d.ts +0 -10
- package/packages/runtime/hooks.js +0 -3
- package/packages/runtime/index.d.ts +0 -3
- package/packages/runtime/index.js +0 -1
- package/packages/runtime/package-lock.json +0 -512
- package/packages/runtime/package.json +0 -16
- package/packages/runtime/server.d.ts +0 -1
- package/packages/runtime/server.js +0 -3
- package/packages/runtime/types.d.ts +0 -1
- package/packages/runtime/types.js +0 -3
- package/packages/schema/.eslintrc.json +0 -13
- package/packages/schema/.vscodeignore +0 -4
- package/packages/schema/asset/logo-dark.png +0 -0
- package/packages/schema/asset/logo-light.png +0 -0
- package/packages/schema/bin/cli +0 -3
- package/packages/schema/jest.config.ts +0 -32
- package/packages/schema/langium-config.json +0 -14
- package/packages/schema/langium-quickstart.md +0 -41
- package/packages/schema/language-configuration.json +0 -30
- package/packages/schema/package.json +0 -96
- package/packages/schema/src/cli/cli-util.ts +0 -80
- package/packages/schema/src/cli/index.ts +0 -64
- package/packages/schema/src/extension.ts +0 -76
- package/packages/schema/src/generator/constants.ts +0 -5
- package/packages/schema/src/generator/index.ts +0 -92
- package/packages/schema/src/generator/next-auth/index.ts +0 -197
- package/packages/schema/src/generator/package.template.json +0 -9
- package/packages/schema/src/generator/prisma/expression-writer.ts +0 -352
- package/packages/schema/src/generator/prisma/index.ts +0 -32
- package/packages/schema/src/generator/prisma/plain-expression-builder.ts +0 -91
- package/packages/schema/src/generator/prisma/prisma-builder.ts +0 -366
- package/packages/schema/src/generator/prisma/query-gard-generator.ts +0 -208
- package/packages/schema/src/generator/prisma/schema-generator.ts +0 -300
- package/packages/schema/src/generator/react-hooks/index.ts +0 -181
- package/packages/schema/src/generator/service/index.ts +0 -107
- package/packages/schema/src/generator/tsconfig.template.json +0 -17
- package/packages/schema/src/generator/types.ts +0 -17
- package/packages/schema/src/generator/utils.ts +0 -9
- package/packages/schema/src/language-server/generated/ast.ts +0 -603
- package/packages/schema/src/language-server/generated/grammar.ts +0 -2190
- package/packages/schema/src/language-server/generated/module.ts +0 -24
- package/packages/schema/src/language-server/main.ts +0 -12
- package/packages/schema/src/language-server/stdlib.zmodel +0 -22
- package/packages/schema/src/language-server/types.ts +0 -9
- package/packages/schema/src/language-server/zmodel-index.ts +0 -33
- package/packages/schema/src/language-server/zmodel-linker.ts +0 -409
- package/packages/schema/src/language-server/zmodel-module.ts +0 -90
- package/packages/schema/src/language-server/zmodel-scope.ts +0 -21
- package/packages/schema/src/language-server/zmodel-validator.ts +0 -35
- package/packages/schema/src/language-server/zmodel.langium +0 -186
- package/packages/schema/src/utils/exec-utils.ts +0 -5
- package/packages/schema/src/utils/indent-string.ts +0 -6
- package/packages/schema/syntaxes/zmodel.json +0 -57
- package/packages/schema/syntaxes/zmodel.tmLanguage.json +0 -57
- package/packages/schema/tests/generator/expression-writer.test.ts +0 -676
- package/packages/schema/tests/generator/prisma-builder.test.ts +0 -138
- package/packages/schema/tests/schema/parser.test.ts +0 -423
- package/packages/schema/tests/schema/sample-todo.test.ts +0 -14
- package/packages/schema/tests/utils.ts +0 -38
- package/packages/schema/tsconfig.json +0 -23
- package/pnpm-workspace.yaml +0 -3
- package/samples/todo/.env +0 -2
- package/samples/todo/.eslintrc.json +0 -3
- package/samples/todo/.vscode/launch.json +0 -11
- package/samples/todo/README.md +0 -34
- package/samples/todo/components/AuthGuard.tsx +0 -17
- package/samples/todo/components/Avatar.tsx +0 -22
- package/samples/todo/components/BreadCrumb.tsx +0 -44
- package/samples/todo/components/ManageMembers.tsx +0 -134
- package/samples/todo/components/NavBar.tsx +0 -57
- package/samples/todo/components/SpaceMembers.tsx +0 -76
- package/samples/todo/components/Spaces.tsx +0 -28
- package/samples/todo/components/TimeInfo.tsx +0 -17
- package/samples/todo/components/Todo.tsx +0 -72
- package/samples/todo/components/TodoList.tsx +0 -77
- package/samples/todo/lib/context.ts +0 -31
- package/samples/todo/next.config.js +0 -10
- package/samples/todo/package-lock.json +0 -7527
- package/samples/todo/package.json +0 -45
- package/samples/todo/pages/_app.tsx +0 -50
- package/samples/todo/pages/api/auth/[...nextauth].ts +0 -83
- package/samples/todo/pages/api/zenstack/[...path].ts +0 -16
- package/samples/todo/pages/create-space.tsx +0 -114
- package/samples/todo/pages/index.tsx +0 -32
- package/samples/todo/pages/space/[slug]/[listId]/index.tsx +0 -88
- package/samples/todo/pages/space/[slug]/index.tsx +0 -169
- package/samples/todo/postcss.config.js +0 -6
- package/samples/todo/public/avatar.jpg +0 -0
- package/samples/todo/public/favicon.ico +0 -0
- package/samples/todo/public/logo.png +0 -0
- package/samples/todo/public/vercel.svg +0 -4
- package/samples/todo/styles/globals.css +0 -7
- package/samples/todo/tailwind.config.js +0 -11
- package/samples/todo/tsconfig.json +0 -28
- package/samples/todo/types/next-auth.d.ts +0 -14
- package/samples/todo/types/next.d.ts +0 -16
- package/samples/todo/zenstack/migrations/20221014084317_init/migration.sql +0 -153
- package/samples/todo/zenstack/migrations/20221020094651_upate_cli/migration.sql +0 -23
- package/samples/todo/zenstack/migrations/migration_lock.toml +0 -3
- package/samples/todo/zenstack/schema.prisma +0 -126
- package/samples/todo/zenstack/schema.zmodel +0 -161
- package/tests/integration/jest.config.ts +0 -16
- package/tests/integration/package-lock.json +0 -1081
- package/tests/integration/package.json +0 -27
- package/tests/integration/tests/operation-coverate.test.ts +0 -563
- package/tests/integration/tests/operations.zmodel +0 -69
- package/tests/integration/tests/todo-e2e.test.ts +0 -577
- package/tests/integration/tests/todo.zmodel +0 -123
- package/tests/integration/tests/tsconfig.template.json +0 -10
- package/tests/integration/tests/utils.ts +0 -133
- 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
|
-
}
|