@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.cjs
CHANGED
|
@@ -5808,8 +5808,9 @@ var AttributeApplicationValidator = class {
|
|
|
5808
5808
|
return;
|
|
5809
5809
|
}
|
|
5810
5810
|
}
|
|
5811
|
-
|
|
5812
|
-
|
|
5811
|
+
const argAssignable = assignableToAttributeParam(arg, paramDecl, attr);
|
|
5812
|
+
if (!argAssignable.result) {
|
|
5813
|
+
accept("error", argAssignable.error, {
|
|
5813
5814
|
node: arg
|
|
5814
5815
|
});
|
|
5815
5816
|
return;
|
|
@@ -6108,37 +6109,86 @@ _ts_decorate([
|
|
|
6108
6109
|
_ts_metadata("design:returntype", void 0)
|
|
6109
6110
|
], AttributeApplicationValidator.prototype, "_checkSchema", null);
|
|
6110
6111
|
function assignableToAttributeParam(arg, param, attr) {
|
|
6112
|
+
const genericError = {
|
|
6113
|
+
result: false,
|
|
6114
|
+
error: "invalid argument type"
|
|
6115
|
+
};
|
|
6116
|
+
const success = {
|
|
6117
|
+
result: true
|
|
6118
|
+
};
|
|
6111
6119
|
const argResolvedType = arg.$resolvedType;
|
|
6112
6120
|
if (!argResolvedType) {
|
|
6113
|
-
return
|
|
6121
|
+
return {
|
|
6122
|
+
result: false,
|
|
6123
|
+
error: "unable to resolve argument type"
|
|
6124
|
+
};
|
|
6114
6125
|
}
|
|
6115
6126
|
let dstType = param.type.type;
|
|
6116
6127
|
let dstIsArray = param.type.array;
|
|
6117
6128
|
if (dstType === "ContextType") {
|
|
6118
6129
|
if (isDataField(attr.$container)) {
|
|
6119
|
-
const
|
|
6120
|
-
if (
|
|
6121
|
-
|
|
6130
|
+
const dstIsJson = attr.$container.type.type === "Json" || hasAttribute(attr.$container, "@json");
|
|
6131
|
+
if (dstIsJson && attr.decl.ref?.name === "@default") {
|
|
6132
|
+
if (attr.$container.type.array && attr.$container.type.type === "Json") {
|
|
6133
|
+
if (isArrayExpr(arg.value) && arg.value.items.every((item) => isLiteralJsonString(item))) {
|
|
6134
|
+
return success;
|
|
6135
|
+
} else {
|
|
6136
|
+
return {
|
|
6137
|
+
result: false,
|
|
6138
|
+
error: "expected an array of JSON string literals"
|
|
6139
|
+
};
|
|
6140
|
+
}
|
|
6141
|
+
} else {
|
|
6142
|
+
if (isLiteralJsonString(arg.value)) {
|
|
6143
|
+
return success;
|
|
6144
|
+
} else {
|
|
6145
|
+
return {
|
|
6146
|
+
result: false,
|
|
6147
|
+
error: "expected a JSON string literal"
|
|
6148
|
+
};
|
|
6149
|
+
}
|
|
6150
|
+
}
|
|
6122
6151
|
}
|
|
6123
6152
|
dstIsArray = attr.$container.type.array;
|
|
6124
6153
|
}
|
|
6125
6154
|
}
|
|
6126
6155
|
const dstRef = param.type.reference;
|
|
6127
6156
|
if (dstType === "Any" && !dstIsArray) {
|
|
6128
|
-
return
|
|
6157
|
+
return success;
|
|
6129
6158
|
}
|
|
6130
6159
|
if (argResolvedType.decl === "Any") {
|
|
6131
6160
|
if (!argResolvedType.array) {
|
|
6132
|
-
return
|
|
6161
|
+
return success;
|
|
6133
6162
|
} else {
|
|
6134
|
-
|
|
6163
|
+
if (argResolvedType.array === dstIsArray) {
|
|
6164
|
+
return success;
|
|
6165
|
+
} else {
|
|
6166
|
+
return {
|
|
6167
|
+
result: false,
|
|
6168
|
+
error: `expected ${dstIsArray ? "array" : "non-array"}`
|
|
6169
|
+
};
|
|
6170
|
+
}
|
|
6135
6171
|
}
|
|
6136
6172
|
}
|
|
6137
6173
|
if (dstType === "FieldReference" || dstType === "TransitiveFieldReference") {
|
|
6138
6174
|
if (dstIsArray) {
|
|
6139
|
-
|
|
6175
|
+
if (isArrayExpr(arg.value) && !arg.value.items.some((item) => !isReferenceExpr(item) || !isDataField(item.target.ref))) {
|
|
6176
|
+
return success;
|
|
6177
|
+
} else {
|
|
6178
|
+
return {
|
|
6179
|
+
result: false,
|
|
6180
|
+
error: "expected an array of field references"
|
|
6181
|
+
};
|
|
6182
|
+
}
|
|
6140
6183
|
} else {
|
|
6141
|
-
|
|
6184
|
+
if (isReferenceExpr(arg.value) && isDataField(arg.value.target.ref)) {
|
|
6185
|
+
return success;
|
|
6186
|
+
} else {
|
|
6187
|
+
return {
|
|
6188
|
+
result: false,
|
|
6189
|
+
error: "expected a field reference"
|
|
6190
|
+
};
|
|
6191
|
+
}
|
|
6142
6192
|
}
|
|
6143
6193
|
}
|
|
6144
6194
|
if (isEnum(argResolvedType.decl)) {
|
|
@@ -6147,15 +6197,24 @@ function assignableToAttributeParam(arg, param, attr) {
|
|
|
6147
6197
|
attrArgDeclType = resolved(attr.$container.type.reference);
|
|
6148
6198
|
dstIsArray = attr.$container.type.array;
|
|
6149
6199
|
}
|
|
6150
|
-
|
|
6200
|
+
if (attrArgDeclType !== argResolvedType.decl) {
|
|
6201
|
+
return genericError;
|
|
6202
|
+
}
|
|
6203
|
+
if (dstIsArray !== argResolvedType.array) {
|
|
6204
|
+
return {
|
|
6205
|
+
result: false,
|
|
6206
|
+
error: `expected ${dstIsArray ? "array" : "non-array"}`
|
|
6207
|
+
};
|
|
6208
|
+
}
|
|
6209
|
+
return success;
|
|
6151
6210
|
} else if (dstType) {
|
|
6152
6211
|
if (typeof argResolvedType?.decl !== "string") {
|
|
6153
|
-
return
|
|
6212
|
+
return genericError;
|
|
6154
6213
|
}
|
|
6155
6214
|
if (dstType === "ContextType") {
|
|
6156
6215
|
if (isDataField(attr.$container)) {
|
|
6157
6216
|
if (!attr.$container?.type?.type) {
|
|
6158
|
-
return
|
|
6217
|
+
return genericError;
|
|
6159
6218
|
}
|
|
6160
6219
|
dstType = mapBuiltinTypeToExpressionType(attr.$container.type.type);
|
|
6161
6220
|
dstIsArray = attr.$container.type.array;
|
|
@@ -6163,9 +6222,17 @@ function assignableToAttributeParam(arg, param, attr) {
|
|
|
6163
6222
|
dstType = "Any";
|
|
6164
6223
|
}
|
|
6165
6224
|
}
|
|
6166
|
-
|
|
6225
|
+
if (typeAssignable(dstType, argResolvedType.decl, arg.value) && dstIsArray === argResolvedType.array) {
|
|
6226
|
+
return success;
|
|
6227
|
+
} else {
|
|
6228
|
+
return genericError;
|
|
6229
|
+
}
|
|
6167
6230
|
} else {
|
|
6168
|
-
|
|
6231
|
+
if ((dstRef?.ref === argResolvedType.decl || dstType === "Any") && dstIsArray === argResolvedType.array) {
|
|
6232
|
+
return success;
|
|
6233
|
+
} else {
|
|
6234
|
+
return genericError;
|
|
6235
|
+
}
|
|
6169
6236
|
}
|
|
6170
6237
|
}
|
|
6171
6238
|
__name(assignableToAttributeParam, "assignableToAttributeParam");
|
|
@@ -6228,6 +6295,18 @@ function validateAttributeApplication(attr, accept, contextDataModel) {
|
|
|
6228
6295
|
new AttributeApplicationValidator().validate(attr, accept, contextDataModel);
|
|
6229
6296
|
}
|
|
6230
6297
|
__name(validateAttributeApplication, "validateAttributeApplication");
|
|
6298
|
+
function isLiteralJsonString(value) {
|
|
6299
|
+
if (!isStringLiteral(value)) {
|
|
6300
|
+
return false;
|
|
6301
|
+
}
|
|
6302
|
+
try {
|
|
6303
|
+
JSON.parse(value.value);
|
|
6304
|
+
return true;
|
|
6305
|
+
} catch {
|
|
6306
|
+
return false;
|
|
6307
|
+
}
|
|
6308
|
+
}
|
|
6309
|
+
__name(isLiteralJsonString, "isLiteralJsonString");
|
|
6231
6310
|
|
|
6232
6311
|
// src/validators/attribute-validator.ts
|
|
6233
6312
|
var AttributeValidator = class {
|