zenstack 0.5.0 → 0.6.0-pre.1
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.md → LICENSE} +0 -0
- package/bin/cli +1 -1
- package/package.json +18 -13
- package/bin/post-install.js +0 -0
- package/bundle/asset/logo-256-bg.png +0 -0
- package/bundle/asset/logo-dark-256.png +0 -0
- package/bundle/asset/logo-light-256.png +0 -0
- package/bundle/cli/index.js +0 -6952
- package/bundle/extension.js +0 -39
- package/bundle/language-server/main.js +0 -6208
- package/bundle/res/package.template.json +0 -9
- package/bundle/res/prism-zmodel.js +0 -22
- package/bundle/res/stdlib.zmodel +0 -218
- package/bundle/res/tsconfig.template.json +0 -17
- package/src/cli/cli-error.ts +0 -4
- package/src/cli/cli-util.ts +0 -214
- package/src/cli/index.ts +0 -246
- package/src/extension.ts +0 -76
- package/src/generator/ast-utils.ts +0 -18
- package/src/generator/constants.ts +0 -6
- package/src/generator/field-constraint/index.ts +0 -304
- package/src/generator/index.ts +0 -86
- package/src/generator/prisma/expression-writer.ts +0 -360
- package/src/generator/prisma/index.ts +0 -44
- package/src/generator/prisma/prisma-builder.ts +0 -370
- package/src/generator/prisma/query-guard-generator.ts +0 -249
- package/src/generator/prisma/schema-generator.ts +0 -313
- package/src/generator/prisma/typescript-expression-transformer.ts +0 -108
- package/src/generator/react-hooks/index.ts +0 -273
- package/src/generator/service/index.ts +0 -113
- package/src/generator/tsc/index.ts +0 -59
- package/src/generator/types.ts +0 -20
- package/src/global.d.ts +0 -3
- package/src/language-server/constants.ts +0 -29
- package/src/language-server/generated/ast.ts +0 -643
- package/src/language-server/generated/grammar.ts +0 -2492
- package/src/language-server/generated/module.ts +0 -24
- package/src/language-server/langium-ext.d.ts +0 -22
- package/src/language-server/main.ts +0 -13
- package/src/language-server/types.ts +0 -25
- package/src/language-server/utils.ts +0 -21
- package/src/language-server/validator/attribute-validator.ts +0 -11
- package/src/language-server/validator/datamodel-validator.ts +0 -426
- package/src/language-server/validator/datasource-validator.ts +0 -102
- package/src/language-server/validator/enum-validator.ts +0 -14
- package/src/language-server/validator/expression-validator.ts +0 -48
- package/src/language-server/validator/schema-validator.ts +0 -31
- package/src/language-server/validator/utils.ts +0 -158
- package/src/language-server/validator/zmodel-validator.ts +0 -91
- package/src/language-server/zmodel-linker.ts +0 -453
- package/src/language-server/zmodel-module.ts +0 -131
- package/src/language-server/zmodel-scope.ts +0 -45
- package/src/language-server/zmodel-workspace-manager.ts +0 -23
- package/src/language-server/zmodel.langium +0 -207
- package/src/res/package.template.json +0 -9
- package/src/res/prism-zmodel.js +0 -22
- package/src/res/stdlib.zmodel +0 -218
- package/src/res/tsconfig.template.json +0 -17
- package/src/telemetry.ts +0 -119
- package/src/utils/exec-utils.ts +0 -8
- package/src/utils/indent-string.ts +0 -9
- package/src/utils/pkg-utils.ts +0 -63
|
@@ -1,48 +0,0 @@
|
|
|
1
|
-
import {
|
|
2
|
-
Expression,
|
|
3
|
-
isBinaryExpr,
|
|
4
|
-
isInvocationExpr,
|
|
5
|
-
} from '@lang/generated/ast';
|
|
6
|
-
import { AstValidator } from '@lang/types';
|
|
7
|
-
import { isFromStdlib } from '@lang/utils';
|
|
8
|
-
import { ValidationAcceptor } from 'langium';
|
|
9
|
-
|
|
10
|
-
/**
|
|
11
|
-
* Validates expressions.
|
|
12
|
-
*/
|
|
13
|
-
export default class ExpressionValidator implements AstValidator<Expression> {
|
|
14
|
-
validate(expr: Expression, accept: ValidationAcceptor): void {
|
|
15
|
-
if (!expr.$resolvedType) {
|
|
16
|
-
if (this.isAuthInvocation(expr)) {
|
|
17
|
-
// check was done at link time
|
|
18
|
-
accept(
|
|
19
|
-
'error',
|
|
20
|
-
'auth() cannot be resolved because no "User" model is defined',
|
|
21
|
-
{ node: expr }
|
|
22
|
-
);
|
|
23
|
-
} else if (this.isCollectionPredicate(expr)) {
|
|
24
|
-
accept(
|
|
25
|
-
'error',
|
|
26
|
-
'collection predicate can only be used on an array of model type',
|
|
27
|
-
{ node: expr }
|
|
28
|
-
);
|
|
29
|
-
} else {
|
|
30
|
-
accept('error', 'expression cannot be resolved', {
|
|
31
|
-
node: expr,
|
|
32
|
-
});
|
|
33
|
-
}
|
|
34
|
-
}
|
|
35
|
-
}
|
|
36
|
-
|
|
37
|
-
private isCollectionPredicate(expr: Expression) {
|
|
38
|
-
return isBinaryExpr(expr) && ['?', '!', '^'].includes(expr.operator);
|
|
39
|
-
}
|
|
40
|
-
|
|
41
|
-
private isAuthInvocation(expr: Expression) {
|
|
42
|
-
return (
|
|
43
|
-
isInvocationExpr(expr) &&
|
|
44
|
-
expr.function.ref?.name === 'auth' &&
|
|
45
|
-
isFromStdlib(expr.function.ref)
|
|
46
|
-
);
|
|
47
|
-
}
|
|
48
|
-
}
|
|
@@ -1,31 +0,0 @@
|
|
|
1
|
-
import { STD_LIB_MODULE_NAME } from '@lang/constants';
|
|
2
|
-
import { isDataSource, Model } from '@lang/generated/ast';
|
|
3
|
-
import { AstValidator } from '@lang/types';
|
|
4
|
-
import { ValidationAcceptor } from 'langium';
|
|
5
|
-
import { validateDuplicatedDeclarations } from './utils';
|
|
6
|
-
|
|
7
|
-
/**
|
|
8
|
-
* Validates toplevel schema.
|
|
9
|
-
*/
|
|
10
|
-
export default class SchemaValidator implements AstValidator<Model> {
|
|
11
|
-
validate(model: Model, accept: ValidationAcceptor): void {
|
|
12
|
-
validateDuplicatedDeclarations(model.declarations, accept);
|
|
13
|
-
|
|
14
|
-
if (!model.$document?.uri.path.endsWith(STD_LIB_MODULE_NAME)) {
|
|
15
|
-
this.validateDataSources(model, accept);
|
|
16
|
-
}
|
|
17
|
-
}
|
|
18
|
-
|
|
19
|
-
private validateDataSources(model: Model, accept: ValidationAcceptor) {
|
|
20
|
-
const dataSources = model.declarations.filter((d) => isDataSource(d));
|
|
21
|
-
if (dataSources.length === 0) {
|
|
22
|
-
accept('error', 'Model must define a datasource', { node: model });
|
|
23
|
-
} else if (dataSources.length > 1) {
|
|
24
|
-
accept(
|
|
25
|
-
'error',
|
|
26
|
-
'Multiple datasource declarations are not allowed',
|
|
27
|
-
{ node: dataSources[1] }
|
|
28
|
-
);
|
|
29
|
-
}
|
|
30
|
-
}
|
|
31
|
-
}
|
|
@@ -1,158 +0,0 @@
|
|
|
1
|
-
import {
|
|
2
|
-
AttributeArg,
|
|
3
|
-
AttributeParam,
|
|
4
|
-
BuiltinType,
|
|
5
|
-
DataModelAttribute,
|
|
6
|
-
DataModelFieldAttribute,
|
|
7
|
-
ExpressionType,
|
|
8
|
-
isArrayExpr,
|
|
9
|
-
isDataModelField,
|
|
10
|
-
isLiteralExpr,
|
|
11
|
-
isReferenceExpr,
|
|
12
|
-
} from '@lang/generated/ast';
|
|
13
|
-
import { AstNode, ValidationAcceptor } from 'langium';
|
|
14
|
-
|
|
15
|
-
/**
|
|
16
|
-
* Checks if the given declarations have duplicated names
|
|
17
|
-
*/
|
|
18
|
-
export function validateDuplicatedDeclarations(
|
|
19
|
-
decls: Array<AstNode & { name: string }>,
|
|
20
|
-
accept: ValidationAcceptor
|
|
21
|
-
): void {
|
|
22
|
-
const groupByName = decls.reduce<
|
|
23
|
-
Record<string, Array<AstNode & { name: string }>>
|
|
24
|
-
>((group, decl) => {
|
|
25
|
-
group[decl.name] = group[decl.name] ?? [];
|
|
26
|
-
group[decl.name].push(decl);
|
|
27
|
-
return group;
|
|
28
|
-
}, {});
|
|
29
|
-
|
|
30
|
-
for (const [name, decls] of Object.entries<AstNode[]>(groupByName)) {
|
|
31
|
-
if (decls.length > 1) {
|
|
32
|
-
accept('error', `Duplicated declaration name "${name}"`, {
|
|
33
|
-
node: decls[1],
|
|
34
|
-
});
|
|
35
|
-
}
|
|
36
|
-
}
|
|
37
|
-
}
|
|
38
|
-
|
|
39
|
-
/**
|
|
40
|
-
* Try getting string value from a potential string literal expression
|
|
41
|
-
*/
|
|
42
|
-
export function getStringLiteral(node: AstNode): string | undefined {
|
|
43
|
-
if (isLiteralExpr(node) && typeof node.value === 'string') {
|
|
44
|
-
return node.value;
|
|
45
|
-
} else {
|
|
46
|
-
return undefined;
|
|
47
|
-
}
|
|
48
|
-
}
|
|
49
|
-
|
|
50
|
-
/**
|
|
51
|
-
* Determines if the given sourceType is assignable to a destination of destType
|
|
52
|
-
*/
|
|
53
|
-
export function typeAssignable(
|
|
54
|
-
destType: ExpressionType,
|
|
55
|
-
sourceType: ExpressionType
|
|
56
|
-
): boolean {
|
|
57
|
-
switch (destType) {
|
|
58
|
-
case 'Any':
|
|
59
|
-
return true;
|
|
60
|
-
case 'Float':
|
|
61
|
-
return (
|
|
62
|
-
sourceType === 'Any' ||
|
|
63
|
-
sourceType === 'Int' ||
|
|
64
|
-
sourceType === 'Float'
|
|
65
|
-
);
|
|
66
|
-
default:
|
|
67
|
-
return sourceType === 'Any' || sourceType === destType;
|
|
68
|
-
}
|
|
69
|
-
}
|
|
70
|
-
|
|
71
|
-
/**
|
|
72
|
-
* Maps a ZModel builtin type to expression type
|
|
73
|
-
*/
|
|
74
|
-
export function mapBuiltinTypeToExpressionType(
|
|
75
|
-
type: BuiltinType | 'Any' | 'Null'
|
|
76
|
-
): ExpressionType | 'Any' {
|
|
77
|
-
switch (type) {
|
|
78
|
-
case 'Any':
|
|
79
|
-
case 'Boolean':
|
|
80
|
-
case 'String':
|
|
81
|
-
case 'DateTime':
|
|
82
|
-
case 'Int':
|
|
83
|
-
case 'Float':
|
|
84
|
-
case 'Null':
|
|
85
|
-
return type;
|
|
86
|
-
case 'BigInt':
|
|
87
|
-
return 'Int';
|
|
88
|
-
case 'Decimal':
|
|
89
|
-
return 'Float';
|
|
90
|
-
case 'Json':
|
|
91
|
-
case 'Bytes':
|
|
92
|
-
return 'Any';
|
|
93
|
-
}
|
|
94
|
-
}
|
|
95
|
-
|
|
96
|
-
/**
|
|
97
|
-
* Determines if the given attribute argument is assignable to the given attribute parameter
|
|
98
|
-
*/
|
|
99
|
-
export function assignableToAttributeParam(
|
|
100
|
-
arg: AttributeArg,
|
|
101
|
-
param: AttributeParam,
|
|
102
|
-
attr: DataModelAttribute | DataModelFieldAttribute
|
|
103
|
-
): boolean {
|
|
104
|
-
const argResolvedType = arg.$resolvedType;
|
|
105
|
-
if (!argResolvedType) {
|
|
106
|
-
return false;
|
|
107
|
-
}
|
|
108
|
-
|
|
109
|
-
let dstType = param.type.type;
|
|
110
|
-
const dstIsArray = param.type.array;
|
|
111
|
-
const dstRef = param.type.reference;
|
|
112
|
-
|
|
113
|
-
if (dstType) {
|
|
114
|
-
if (typeof argResolvedType?.decl !== 'string') {
|
|
115
|
-
// destination type is not a reference, so argument type must be a plain expression
|
|
116
|
-
return false;
|
|
117
|
-
}
|
|
118
|
-
|
|
119
|
-
if (dstType === 'FieldReference') {
|
|
120
|
-
if (dstIsArray) {
|
|
121
|
-
return (
|
|
122
|
-
isArrayExpr(arg.value) &&
|
|
123
|
-
!arg.value.items.find(
|
|
124
|
-
(item) =>
|
|
125
|
-
!isReferenceExpr(item) ||
|
|
126
|
-
!isDataModelField(item.target.ref)
|
|
127
|
-
)
|
|
128
|
-
);
|
|
129
|
-
} else {
|
|
130
|
-
return (
|
|
131
|
-
isReferenceExpr(arg.value) &&
|
|
132
|
-
isDataModelField(arg.value.target.ref)
|
|
133
|
-
);
|
|
134
|
-
}
|
|
135
|
-
} else if (dstType === 'ContextType') {
|
|
136
|
-
if (isDataModelField(attr.$container)) {
|
|
137
|
-
if (!attr.$container?.type?.type) {
|
|
138
|
-
return false;
|
|
139
|
-
}
|
|
140
|
-
dstType = mapBuiltinTypeToExpressionType(
|
|
141
|
-
attr.$container.type.type
|
|
142
|
-
);
|
|
143
|
-
} else {
|
|
144
|
-
dstType = 'Any';
|
|
145
|
-
}
|
|
146
|
-
}
|
|
147
|
-
|
|
148
|
-
return (
|
|
149
|
-
typeAssignable(dstType, argResolvedType.decl) &&
|
|
150
|
-
dstIsArray === argResolvedType.array
|
|
151
|
-
);
|
|
152
|
-
} else {
|
|
153
|
-
return (
|
|
154
|
-
dstRef?.ref === argResolvedType.decl &&
|
|
155
|
-
dstIsArray === argResolvedType.array
|
|
156
|
-
);
|
|
157
|
-
}
|
|
158
|
-
}
|
|
@@ -1,91 +0,0 @@
|
|
|
1
|
-
import {
|
|
2
|
-
AstNode,
|
|
3
|
-
LangiumDocument,
|
|
4
|
-
ValidationAcceptor,
|
|
5
|
-
ValidationChecks,
|
|
6
|
-
ValidationRegistry,
|
|
7
|
-
} from 'langium';
|
|
8
|
-
import {
|
|
9
|
-
Attribute,
|
|
10
|
-
DataModel,
|
|
11
|
-
DataSource,
|
|
12
|
-
Enum,
|
|
13
|
-
Expression,
|
|
14
|
-
Model,
|
|
15
|
-
ZModelAstType,
|
|
16
|
-
} from '../generated/ast';
|
|
17
|
-
import type { ZModelServices } from '../zmodel-module';
|
|
18
|
-
import SchemaValidator from './schema-validator';
|
|
19
|
-
import DataSourceValidator from './datasource-validator';
|
|
20
|
-
import DataModelValidator from './datamodel-validator';
|
|
21
|
-
import AttributeValidator from './attribute-validator';
|
|
22
|
-
import EnumValidator from './enum-validator';
|
|
23
|
-
import ExpressionValidator from './expression-validator';
|
|
24
|
-
|
|
25
|
-
/**
|
|
26
|
-
* Registry for validation checks.
|
|
27
|
-
*/
|
|
28
|
-
export class ZModelValidationRegistry extends ValidationRegistry {
|
|
29
|
-
constructor(services: ZModelServices) {
|
|
30
|
-
super(services);
|
|
31
|
-
const validator = services.validation.ZModelValidator;
|
|
32
|
-
const checks: ValidationChecks<ZModelAstType> = {
|
|
33
|
-
Model: validator.checkModel,
|
|
34
|
-
DataSource: validator.checkDataSource,
|
|
35
|
-
DataModel: validator.checkDataModel,
|
|
36
|
-
Enum: validator.checkEnum,
|
|
37
|
-
Attribute: validator.checkAttribute,
|
|
38
|
-
Expression: validator.checkExpression,
|
|
39
|
-
};
|
|
40
|
-
this.register(checks, validator);
|
|
41
|
-
}
|
|
42
|
-
}
|
|
43
|
-
|
|
44
|
-
/**
|
|
45
|
-
* Implementation of custom validations.
|
|
46
|
-
*/
|
|
47
|
-
export class ZModelValidator {
|
|
48
|
-
private shouldCheck(node: AstNode) {
|
|
49
|
-
let doc: LangiumDocument | undefined;
|
|
50
|
-
let currNode: AstNode | undefined = node;
|
|
51
|
-
while (currNode) {
|
|
52
|
-
if (currNode.$document) {
|
|
53
|
-
doc = currNode.$document;
|
|
54
|
-
break;
|
|
55
|
-
}
|
|
56
|
-
currNode = currNode.$container;
|
|
57
|
-
}
|
|
58
|
-
|
|
59
|
-
return (
|
|
60
|
-
doc?.parseResult.lexerErrors.length === 0 &&
|
|
61
|
-
doc?.parseResult.parserErrors.length === 0
|
|
62
|
-
);
|
|
63
|
-
}
|
|
64
|
-
|
|
65
|
-
checkModel(node: Model, accept: ValidationAcceptor): void {
|
|
66
|
-
this.shouldCheck(node) && new SchemaValidator().validate(node, accept);
|
|
67
|
-
}
|
|
68
|
-
|
|
69
|
-
checkDataSource(node: DataSource, accept: ValidationAcceptor): void {
|
|
70
|
-
this.shouldCheck(node) &&
|
|
71
|
-
new DataSourceValidator().validate(node, accept);
|
|
72
|
-
}
|
|
73
|
-
|
|
74
|
-
checkDataModel(node: DataModel, accept: ValidationAcceptor): void {
|
|
75
|
-
this.shouldCheck(node) &&
|
|
76
|
-
new DataModelValidator().validate(node, accept);
|
|
77
|
-
}
|
|
78
|
-
|
|
79
|
-
checkEnum(node: Enum, accept: ValidationAcceptor): void {
|
|
80
|
-
this.shouldCheck(node) && new EnumValidator().validate(node, accept);
|
|
81
|
-
}
|
|
82
|
-
|
|
83
|
-
checkAttribute(node: Attribute, accept: ValidationAcceptor): void {
|
|
84
|
-
this.shouldCheck(node) &&
|
|
85
|
-
new AttributeValidator().validate(node, accept);
|
|
86
|
-
}
|
|
87
|
-
|
|
88
|
-
checkExpression(node: Expression, accept: ValidationAcceptor): void {
|
|
89
|
-
new ExpressionValidator().validate(node, accept);
|
|
90
|
-
}
|
|
91
|
-
}
|