zenstack 0.2.3 → 0.2.9
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/README.md +3 -1
- package/bundle/cli/index.js +129 -132
- package/package.json +4 -4
- package/src/generator/next-auth/index.ts +2 -1
- package/src/generator/prisma/schema-generator.ts +1 -1
- package/src/generator/service/index.ts +20 -79
- package/bundle/asset/logo-dark.png +0 -0
- package/bundle/asset/logo-light.png +0 -0
- package/bundle/cli/index.js.map +0 -7
- package/bundle/extension.js.map +0 -7
- package/bundle/language-server/main.js.map +0 -7
package/package.json
CHANGED
|
@@ -3,7 +3,7 @@
|
|
|
3
3
|
"publisher": "zenstack",
|
|
4
4
|
"displayName": "ZenStack Language Tools",
|
|
5
5
|
"description": "ZenStack is a toolkit that simplifies full-stack development",
|
|
6
|
-
"version": "0.2.
|
|
6
|
+
"version": "0.2.9",
|
|
7
7
|
"author": {
|
|
8
8
|
"name": "ZenStack Team"
|
|
9
9
|
},
|
|
@@ -64,7 +64,7 @@
|
|
|
64
64
|
},
|
|
65
65
|
"main": "./bundle/extension.js",
|
|
66
66
|
"dependencies": {
|
|
67
|
-
"@zenstackhq/internal": "0.2.
|
|
67
|
+
"@zenstackhq/internal": "0.2.9",
|
|
68
68
|
"change-case": "^4.1.2",
|
|
69
69
|
"chevrotain": "^9.1.0",
|
|
70
70
|
"colors": "^1.4.0",
|
|
@@ -106,9 +106,9 @@
|
|
|
106
106
|
},
|
|
107
107
|
"scripts": {
|
|
108
108
|
"vscode:publish": "vsce publish --no-dependencies",
|
|
109
|
-
"vscode:prepublish": "cp ../../README.md ./ && pnpm lint && pnpm build
|
|
109
|
+
"vscode:prepublish": "cp ../../README.md ./ && pnpm lint && pnpm build",
|
|
110
110
|
"vscode:package": "vsce package --no-dependencies",
|
|
111
|
-
"build": "cp -r src/res/* bundle/res/
|
|
111
|
+
"build": "pnpm langium:generate && tsc --noEmit && pnpm bundle && cp -r src/res/* bundle/res/",
|
|
112
112
|
"bundle": "node build/bundle.js --minify",
|
|
113
113
|
"bundle-watch": "node build/bundle.js --watch",
|
|
114
114
|
"ts:watch": "tsc --watch --noEmit",
|
|
@@ -3,6 +3,7 @@ import { Project } from 'ts-morph';
|
|
|
3
3
|
import * as path from 'path';
|
|
4
4
|
import colors from 'colors';
|
|
5
5
|
import { DataModel, isDataModel, Model } from '@lang/generated/ast';
|
|
6
|
+
import { execSync } from 'child_process';
|
|
6
7
|
|
|
7
8
|
/**
|
|
8
9
|
* Generates NextAuth adaptor code
|
|
@@ -20,7 +21,7 @@ export default class NextAuthGenerator implements Generator {
|
|
|
20
21
|
|
|
21
22
|
async generate(context: Context): Promise<void> {
|
|
22
23
|
try {
|
|
23
|
-
|
|
24
|
+
execSync('npm ls next-auth');
|
|
24
25
|
} catch (err) {
|
|
25
26
|
console.warn(
|
|
26
27
|
colors.yellow(
|
|
@@ -1,5 +1,5 @@
|
|
|
1
1
|
import { Context, Generator } from '../types';
|
|
2
|
-
import { Project
|
|
2
|
+
import { Project } from 'ts-morph';
|
|
3
3
|
import * as path from 'path';
|
|
4
4
|
import colors from 'colors';
|
|
5
5
|
import { INTERNAL_PACKAGE } from '../constants';
|
|
@@ -16,90 +16,31 @@ export default class ServiceGenerator implements Generator {
|
|
|
16
16
|
{ overwrite: true }
|
|
17
17
|
);
|
|
18
18
|
|
|
19
|
-
sf.
|
|
20
|
-
|
|
21
|
-
|
|
22
|
-
|
|
23
|
-
|
|
24
|
-
sf.addImportDeclaration({
|
|
25
|
-
namedImports: ['Service', 'PolicyOperationKind', 'QueryContext'],
|
|
26
|
-
moduleSpecifier: INTERNAL_PACKAGE,
|
|
27
|
-
isTypeOnly: true,
|
|
28
|
-
});
|
|
29
|
-
|
|
30
|
-
sf.addVariableStatement({
|
|
31
|
-
declarationKind: VariableDeclarationKind.Let,
|
|
32
|
-
declarations: [
|
|
33
|
-
{
|
|
34
|
-
name: 'guardModule',
|
|
35
|
-
type: 'any',
|
|
36
|
-
},
|
|
37
|
-
],
|
|
38
|
-
});
|
|
19
|
+
sf.addStatements([
|
|
20
|
+
`import { PrismaClient } from "../.prisma";`,
|
|
21
|
+
`import { DefaultService } from "${INTERNAL_PACKAGE}";`,
|
|
22
|
+
]);
|
|
39
23
|
|
|
40
24
|
const cls = sf.addClass({
|
|
41
25
|
name: 'ZenStackService',
|
|
42
26
|
isExported: true,
|
|
43
|
-
|
|
44
|
-
});
|
|
45
|
-
cls.addMember({
|
|
46
|
-
kind: StructureKind.Property,
|
|
47
|
-
name: 'private readonly _prisma',
|
|
48
|
-
initializer: 'new PrismaClient()',
|
|
27
|
+
extends: 'DefaultService<PrismaClient>',
|
|
49
28
|
});
|
|
50
29
|
|
|
51
|
-
cls.
|
|
52
|
-
name: '
|
|
53
|
-
})
|
|
54
|
-
.
|
|
55
|
-
|
|
56
|
-
|
|
57
|
-
|
|
58
|
-
|
|
59
|
-
|
|
60
|
-
|
|
61
|
-
|
|
62
|
-
|
|
63
|
-
|
|
64
|
-
|
|
65
|
-
},
|
|
66
|
-
{
|
|
67
|
-
name: 'field',
|
|
68
|
-
type: 'string',
|
|
69
|
-
},
|
|
70
|
-
],
|
|
71
|
-
})
|
|
72
|
-
.addBody().setBodyText(`
|
|
73
|
-
if (!guardModule) {
|
|
74
|
-
guardModule = await import('./query/guard');
|
|
75
|
-
}
|
|
76
|
-
return guardModule._fieldMapping?.[model]?.[field];
|
|
77
|
-
`);
|
|
78
|
-
|
|
79
|
-
cls
|
|
80
|
-
.addMethod({
|
|
81
|
-
name: 'buildQueryGuard',
|
|
82
|
-
isAsync: true,
|
|
83
|
-
parameters: [
|
|
84
|
-
{
|
|
85
|
-
name: 'model',
|
|
86
|
-
type: 'string',
|
|
87
|
-
},
|
|
88
|
-
{
|
|
89
|
-
name: 'operation',
|
|
90
|
-
type: 'PolicyOperationKind',
|
|
91
|
-
},
|
|
92
|
-
{
|
|
93
|
-
name: 'context',
|
|
94
|
-
type: 'QueryContext',
|
|
95
|
-
},
|
|
96
|
-
],
|
|
97
|
-
})
|
|
98
|
-
.addBody().setBodyText(`
|
|
99
|
-
const module: any = await import('./query/guard');
|
|
100
|
-
const provider: (context: QueryContext) => any = module[model+ '_' + operation];
|
|
101
|
-
return provider(context);
|
|
102
|
-
`);
|
|
30
|
+
cls.addMethod({
|
|
31
|
+
name: 'initializePrisma',
|
|
32
|
+
}).setBodyText(`
|
|
33
|
+
const logConfig = (this.config.log || [])
|
|
34
|
+
.filter(item => typeof item === 'string' ? ['info', 'warn', 'error', 'query'].includes(item): ['info', 'warn', 'error', 'query'].includes(item.level));
|
|
35
|
+
return new PrismaClient({log: logConfig as any });
|
|
36
|
+
`);
|
|
37
|
+
|
|
38
|
+
cls.addMethod({
|
|
39
|
+
name: 'loadGuardModule',
|
|
40
|
+
isAsync: true,
|
|
41
|
+
}).setBodyText(`
|
|
42
|
+
return import('./query/guard');
|
|
43
|
+
`);
|
|
103
44
|
|
|
104
45
|
// Recommended by Prisma for Next.js
|
|
105
46
|
// https://www.prisma.io/docs/guides/database/troubleshooting-orm/help-articles/nextjs-prisma-client-dev-practices#problem
|
|
Binary file
|
|
Binary file
|