@zenstackhq/language 3.2.0 → 3.2.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/dist/index.cjs +95 -16
- package/dist/index.cjs.map +1 -1
- package/dist/index.js +95 -16
- package/dist/index.js.map +1 -1
- package/package.json +5 -5
package/dist/index.js
CHANGED
|
@@ -5772,8 +5772,9 @@ var AttributeApplicationValidator = class {
|
|
|
5772
5772
|
return;
|
|
5773
5773
|
}
|
|
5774
5774
|
}
|
|
5775
|
-
|
|
5776
|
-
|
|
5775
|
+
const argAssignable = assignableToAttributeParam(arg, paramDecl, attr);
|
|
5776
|
+
if (!argAssignable.result) {
|
|
5777
|
+
accept("error", argAssignable.error, {
|
|
5777
5778
|
node: arg
|
|
5778
5779
|
});
|
|
5779
5780
|
return;
|
|
@@ -6072,37 +6073,86 @@ _ts_decorate([
|
|
|
6072
6073
|
_ts_metadata("design:returntype", void 0)
|
|
6073
6074
|
], AttributeApplicationValidator.prototype, "_checkSchema", null);
|
|
6074
6075
|
function assignableToAttributeParam(arg, param, attr) {
|
|
6076
|
+
const genericError = {
|
|
6077
|
+
result: false,
|
|
6078
|
+
error: "invalid argument type"
|
|
6079
|
+
};
|
|
6080
|
+
const success = {
|
|
6081
|
+
result: true
|
|
6082
|
+
};
|
|
6075
6083
|
const argResolvedType = arg.$resolvedType;
|
|
6076
6084
|
if (!argResolvedType) {
|
|
6077
|
-
return
|
|
6085
|
+
return {
|
|
6086
|
+
result: false,
|
|
6087
|
+
error: "unable to resolve argument type"
|
|
6088
|
+
};
|
|
6078
6089
|
}
|
|
6079
6090
|
let dstType = param.type.type;
|
|
6080
6091
|
let dstIsArray = param.type.array;
|
|
6081
6092
|
if (dstType === "ContextType") {
|
|
6082
6093
|
if (isDataField(attr.$container)) {
|
|
6083
|
-
const
|
|
6084
|
-
if (
|
|
6085
|
-
|
|
6094
|
+
const dstIsJson = attr.$container.type.type === "Json" || hasAttribute(attr.$container, "@json");
|
|
6095
|
+
if (dstIsJson && attr.decl.ref?.name === "@default") {
|
|
6096
|
+
if (attr.$container.type.array && attr.$container.type.type === "Json") {
|
|
6097
|
+
if (isArrayExpr(arg.value) && arg.value.items.every((item) => isLiteralJsonString(item))) {
|
|
6098
|
+
return success;
|
|
6099
|
+
} else {
|
|
6100
|
+
return {
|
|
6101
|
+
result: false,
|
|
6102
|
+
error: "expected an array of JSON string literals"
|
|
6103
|
+
};
|
|
6104
|
+
}
|
|
6105
|
+
} else {
|
|
6106
|
+
if (isLiteralJsonString(arg.value)) {
|
|
6107
|
+
return success;
|
|
6108
|
+
} else {
|
|
6109
|
+
return {
|
|
6110
|
+
result: false,
|
|
6111
|
+
error: "expected a JSON string literal"
|
|
6112
|
+
};
|
|
6113
|
+
}
|
|
6114
|
+
}
|
|
6086
6115
|
}
|
|
6087
6116
|
dstIsArray = attr.$container.type.array;
|
|
6088
6117
|
}
|
|
6089
6118
|
}
|
|
6090
6119
|
const dstRef = param.type.reference;
|
|
6091
6120
|
if (dstType === "Any" && !dstIsArray) {
|
|
6092
|
-
return
|
|
6121
|
+
return success;
|
|
6093
6122
|
}
|
|
6094
6123
|
if (argResolvedType.decl === "Any") {
|
|
6095
6124
|
if (!argResolvedType.array) {
|
|
6096
|
-
return
|
|
6125
|
+
return success;
|
|
6097
6126
|
} else {
|
|
6098
|
-
|
|
6127
|
+
if (argResolvedType.array === dstIsArray) {
|
|
6128
|
+
return success;
|
|
6129
|
+
} else {
|
|
6130
|
+
return {
|
|
6131
|
+
result: false,
|
|
6132
|
+
error: `expected ${dstIsArray ? "array" : "non-array"}`
|
|
6133
|
+
};
|
|
6134
|
+
}
|
|
6099
6135
|
}
|
|
6100
6136
|
}
|
|
6101
6137
|
if (dstType === "FieldReference" || dstType === "TransitiveFieldReference") {
|
|
6102
6138
|
if (dstIsArray) {
|
|
6103
|
-
|
|
6139
|
+
if (isArrayExpr(arg.value) && !arg.value.items.some((item) => !isReferenceExpr(item) || !isDataField(item.target.ref))) {
|
|
6140
|
+
return success;
|
|
6141
|
+
} else {
|
|
6142
|
+
return {
|
|
6143
|
+
result: false,
|
|
6144
|
+
error: "expected an array of field references"
|
|
6145
|
+
};
|
|
6146
|
+
}
|
|
6104
6147
|
} else {
|
|
6105
|
-
|
|
6148
|
+
if (isReferenceExpr(arg.value) && isDataField(arg.value.target.ref)) {
|
|
6149
|
+
return success;
|
|
6150
|
+
} else {
|
|
6151
|
+
return {
|
|
6152
|
+
result: false,
|
|
6153
|
+
error: "expected a field reference"
|
|
6154
|
+
};
|
|
6155
|
+
}
|
|
6106
6156
|
}
|
|
6107
6157
|
}
|
|
6108
6158
|
if (isEnum(argResolvedType.decl)) {
|
|
@@ -6111,15 +6161,24 @@ function assignableToAttributeParam(arg, param, attr) {
|
|
|
6111
6161
|
attrArgDeclType = resolved(attr.$container.type.reference);
|
|
6112
6162
|
dstIsArray = attr.$container.type.array;
|
|
6113
6163
|
}
|
|
6114
|
-
|
|
6164
|
+
if (attrArgDeclType !== argResolvedType.decl) {
|
|
6165
|
+
return genericError;
|
|
6166
|
+
}
|
|
6167
|
+
if (dstIsArray !== argResolvedType.array) {
|
|
6168
|
+
return {
|
|
6169
|
+
result: false,
|
|
6170
|
+
error: `expected ${dstIsArray ? "array" : "non-array"}`
|
|
6171
|
+
};
|
|
6172
|
+
}
|
|
6173
|
+
return success;
|
|
6115
6174
|
} else if (dstType) {
|
|
6116
6175
|
if (typeof argResolvedType?.decl !== "string") {
|
|
6117
|
-
return
|
|
6176
|
+
return genericError;
|
|
6118
6177
|
}
|
|
6119
6178
|
if (dstType === "ContextType") {
|
|
6120
6179
|
if (isDataField(attr.$container)) {
|
|
6121
6180
|
if (!attr.$container?.type?.type) {
|
|
6122
|
-
return
|
|
6181
|
+
return genericError;
|
|
6123
6182
|
}
|
|
6124
6183
|
dstType = mapBuiltinTypeToExpressionType(attr.$container.type.type);
|
|
6125
6184
|
dstIsArray = attr.$container.type.array;
|
|
@@ -6127,9 +6186,17 @@ function assignableToAttributeParam(arg, param, attr) {
|
|
|
6127
6186
|
dstType = "Any";
|
|
6128
6187
|
}
|
|
6129
6188
|
}
|
|
6130
|
-
|
|
6189
|
+
if (typeAssignable(dstType, argResolvedType.decl, arg.value) && dstIsArray === argResolvedType.array) {
|
|
6190
|
+
return success;
|
|
6191
|
+
} else {
|
|
6192
|
+
return genericError;
|
|
6193
|
+
}
|
|
6131
6194
|
} else {
|
|
6132
|
-
|
|
6195
|
+
if ((dstRef?.ref === argResolvedType.decl || dstType === "Any") && dstIsArray === argResolvedType.array) {
|
|
6196
|
+
return success;
|
|
6197
|
+
} else {
|
|
6198
|
+
return genericError;
|
|
6199
|
+
}
|
|
6133
6200
|
}
|
|
6134
6201
|
}
|
|
6135
6202
|
__name(assignableToAttributeParam, "assignableToAttributeParam");
|
|
@@ -6192,6 +6259,18 @@ function validateAttributeApplication(attr, accept, contextDataModel) {
|
|
|
6192
6259
|
new AttributeApplicationValidator().validate(attr, accept, contextDataModel);
|
|
6193
6260
|
}
|
|
6194
6261
|
__name(validateAttributeApplication, "validateAttributeApplication");
|
|
6262
|
+
function isLiteralJsonString(value) {
|
|
6263
|
+
if (!isStringLiteral(value)) {
|
|
6264
|
+
return false;
|
|
6265
|
+
}
|
|
6266
|
+
try {
|
|
6267
|
+
JSON.parse(value.value);
|
|
6268
|
+
return true;
|
|
6269
|
+
} catch {
|
|
6270
|
+
return false;
|
|
6271
|
+
}
|
|
6272
|
+
}
|
|
6273
|
+
__name(isLiteralJsonString, "isLiteralJsonString");
|
|
6195
6274
|
|
|
6196
6275
|
// src/validators/attribute-validator.ts
|
|
6197
6276
|
var AttributeValidator = class {
|