@player-tools/json-language-service 0.13.0-next.3 → 0.13.0-next.5
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/cjs/index.cjs +440 -35
- package/dist/cjs/index.cjs.map +1 -1
- package/dist/index.legacy-esm.js +430 -26
- package/dist/index.mjs +430 -26
- package/dist/index.mjs.map +1 -1
- package/package.json +4 -4
- package/src/__tests__/__snapshots__/service.test.ts.snap +5 -15
- package/src/__tests__/service.test.ts +1 -28
- package/src/constants.ts +2 -0
- package/src/plugins/__tests__/asset-wrapper-array-plugin.test.ts +2 -2
- package/src/plugins/__tests__/missing-asset-wrapper-plugin.test.ts +2 -2
- package/src/plugins/__tests__/schema-validation-plugin.test.ts +1923 -0
- package/src/plugins/schema-validation-plugin.ts +508 -0
- package/src/plugins/xlr-plugin.ts +2 -21
- package/src/utils.ts +20 -0
- package/src/xlr/registry.ts +6 -1
- package/types/plugins/schema-validation-plugin.d.ts +12 -0
- package/types/plugins/xlr-plugin.d.ts +7 -0
- package/types/utils.d.ts +3 -0
package/dist/index.legacy-esm.js
CHANGED
|
@@ -686,6 +686,19 @@ function mapFlowStateToType(flowType) {
|
|
|
686
686
|
}
|
|
687
687
|
return flowXLR;
|
|
688
688
|
}
|
|
689
|
+
var findErrorNode = (rootNode, nodeToFind) => {
|
|
690
|
+
const children = [rootNode];
|
|
691
|
+
while (children.length > 0) {
|
|
692
|
+
const child = children.pop();
|
|
693
|
+
if (child.jsonNode === nodeToFind) {
|
|
694
|
+
return child;
|
|
695
|
+
}
|
|
696
|
+
if (child.children) {
|
|
697
|
+
children.push(...child.children);
|
|
698
|
+
}
|
|
699
|
+
}
|
|
700
|
+
return rootNode;
|
|
701
|
+
};
|
|
689
702
|
|
|
690
703
|
// ../../../../../../../../../../execroot/_main/bazel-out/k8-fastbuild/bin/language/json-language-service/src/plugins/asset-wrapper-array-plugin.ts
|
|
691
704
|
var isInView = (node) => {
|
|
@@ -937,19 +950,6 @@ import {
|
|
|
937
950
|
function isError(issue) {
|
|
938
951
|
return issue.severity === DiagnosticSeverity3.Error;
|
|
939
952
|
}
|
|
940
|
-
var findErrorNode = (rootNode, nodeToFind) => {
|
|
941
|
-
const children = [rootNode];
|
|
942
|
-
while (children.length > 0) {
|
|
943
|
-
const child = children.pop();
|
|
944
|
-
if (child.jsonNode === nodeToFind) {
|
|
945
|
-
return child;
|
|
946
|
-
}
|
|
947
|
-
if (child.children) {
|
|
948
|
-
children.push(...child.children);
|
|
949
|
-
}
|
|
950
|
-
}
|
|
951
|
-
return rootNode;
|
|
952
|
-
};
|
|
953
953
|
var translateSeverity = (severity) => {
|
|
954
954
|
return severity;
|
|
955
955
|
};
|
|
@@ -1201,8 +1201,409 @@ var XLRPlugin = class {
|
|
|
1201
1201
|
}
|
|
1202
1202
|
};
|
|
1203
1203
|
|
|
1204
|
-
// ../../../../../../../../../../execroot/_main/bazel-out/k8-fastbuild/bin/language/json-language-service/src/plugins/
|
|
1204
|
+
// ../../../../../../../../../../execroot/_main/bazel-out/k8-fastbuild/bin/language/json-language-service/src/plugins/schema-validation-plugin.ts
|
|
1205
1205
|
import { DiagnosticSeverity as DiagnosticSeverity4 } from "vscode-languageserver-types";
|
|
1206
|
+
import { isObjectType, isPrimitiveTypeNode } from "@player-tools/xlr-utils";
|
|
1207
|
+
function formatErrorMessage(message) {
|
|
1208
|
+
return `Schema Validation Error: ${message}`;
|
|
1209
|
+
}
|
|
1210
|
+
function makeValidationRefObject(baseObject, validationFunction) {
|
|
1211
|
+
return {
|
|
1212
|
+
...baseObject,
|
|
1213
|
+
properties: {
|
|
1214
|
+
...baseObject.properties,
|
|
1215
|
+
...validationFunction.properties
|
|
1216
|
+
},
|
|
1217
|
+
additionalProperties: false
|
|
1218
|
+
};
|
|
1219
|
+
}
|
|
1220
|
+
function validateSchemaValidations(validationNode, sdk, validationContext) {
|
|
1221
|
+
const claimedValidator = getProperty(validationNode, "type");
|
|
1222
|
+
if (!claimedValidator) {
|
|
1223
|
+
validationContext.addViolation({
|
|
1224
|
+
node: validationNode,
|
|
1225
|
+
message: formatErrorMessage('Validation object missing "type" property'),
|
|
1226
|
+
severity: DiagnosticSeverity4.Error
|
|
1227
|
+
});
|
|
1228
|
+
} else if (claimedValidator.valueNode?.type !== "string") {
|
|
1229
|
+
validationContext.addViolation({
|
|
1230
|
+
node: claimedValidator.valueNode ?? validationNode,
|
|
1231
|
+
message: formatErrorMessage("Validation type must be a string"),
|
|
1232
|
+
severity: DiagnosticSeverity4.Error
|
|
1233
|
+
});
|
|
1234
|
+
} else {
|
|
1235
|
+
const validationXLR = sdk.getType(claimedValidator.valueNode.value, {
|
|
1236
|
+
getRawType: true
|
|
1237
|
+
});
|
|
1238
|
+
if (!validationXLR) {
|
|
1239
|
+
validationContext.addViolation({
|
|
1240
|
+
node: validationNode,
|
|
1241
|
+
message: formatErrorMessage(
|
|
1242
|
+
`Validation Function ${claimedValidator} is not a registered validator`
|
|
1243
|
+
),
|
|
1244
|
+
severity: DiagnosticSeverity4.Error
|
|
1245
|
+
});
|
|
1246
|
+
} else {
|
|
1247
|
+
const valRef = sdk.getType("Validation.Reference", {
|
|
1248
|
+
getRawType: true
|
|
1249
|
+
});
|
|
1250
|
+
if (valRef) {
|
|
1251
|
+
let validationIssues;
|
|
1252
|
+
const validatorFunctionProps = validationXLR.genericArguments?.[0];
|
|
1253
|
+
if (!validatorFunctionProps || isObjectType(validatorFunctionProps)) {
|
|
1254
|
+
validationIssues = sdk.validateByType(
|
|
1255
|
+
makeValidationRefObject(
|
|
1256
|
+
valRef,
|
|
1257
|
+
validatorFunctionProps ?? {}
|
|
1258
|
+
),
|
|
1259
|
+
validationNode.jsonNode
|
|
1260
|
+
);
|
|
1261
|
+
validationIssues.forEach((issue) => {
|
|
1262
|
+
validationContext.addViolation({
|
|
1263
|
+
node: validationNode,
|
|
1264
|
+
message: formatErrorMessage(issue.message),
|
|
1265
|
+
severity: translateSeverity(issue.severity)
|
|
1266
|
+
});
|
|
1267
|
+
});
|
|
1268
|
+
} else {
|
|
1269
|
+
const validationResults = validatorFunctionProps.or.map((node) => {
|
|
1270
|
+
if (isObjectType(node)) {
|
|
1271
|
+
return sdk.validateByType(
|
|
1272
|
+
makeValidationRefObject(valRef, node),
|
|
1273
|
+
validationNode.jsonNode
|
|
1274
|
+
);
|
|
1275
|
+
} else {
|
|
1276
|
+
validationIssues.forEach((issue) => {
|
|
1277
|
+
validationContext.addViolation({
|
|
1278
|
+
node: validationNode,
|
|
1279
|
+
message: formatErrorMessage(
|
|
1280
|
+
`Internal Error - Validation function ${validationXLR.name} type argument is not an object`
|
|
1281
|
+
),
|
|
1282
|
+
severity: DiagnosticSeverity4.Error
|
|
1283
|
+
});
|
|
1284
|
+
});
|
|
1285
|
+
return null;
|
|
1286
|
+
}
|
|
1287
|
+
}).filter((o) => o !== null && Array.isArray(o) && o.length === 0);
|
|
1288
|
+
if (validationResults.length !== 1) {
|
|
1289
|
+
validationContext.addViolation({
|
|
1290
|
+
node: validationNode,
|
|
1291
|
+
message: formatErrorMessage(
|
|
1292
|
+
`Validation function invalid function parameters for type ${validationXLR.name}`
|
|
1293
|
+
),
|
|
1294
|
+
severity: DiagnosticSeverity4.Error
|
|
1295
|
+
});
|
|
1296
|
+
}
|
|
1297
|
+
}
|
|
1298
|
+
} else {
|
|
1299
|
+
validationContext.addViolation({
|
|
1300
|
+
node: validationNode,
|
|
1301
|
+
message: formatErrorMessage(
|
|
1302
|
+
"Validation.Reference from @player-ui/types is not loaded into SDK"
|
|
1303
|
+
),
|
|
1304
|
+
severity: DiagnosticSeverity4.Error
|
|
1305
|
+
});
|
|
1306
|
+
}
|
|
1307
|
+
}
|
|
1308
|
+
}
|
|
1309
|
+
}
|
|
1310
|
+
function validateSchemaFormat(formatNode, sdk, validationContext) {
|
|
1311
|
+
const claimedFormatter = getProperty(formatNode, "type");
|
|
1312
|
+
if (!claimedFormatter) {
|
|
1313
|
+
validationContext.addViolation({
|
|
1314
|
+
node: formatNode,
|
|
1315
|
+
message: formatErrorMessage('Format object missing "type" property'),
|
|
1316
|
+
severity: DiagnosticSeverity4.Error
|
|
1317
|
+
});
|
|
1318
|
+
} else if (claimedFormatter.valueNode?.type !== "string") {
|
|
1319
|
+
validationContext.addViolation({
|
|
1320
|
+
node: claimedFormatter.valueNode ?? claimedFormatter,
|
|
1321
|
+
message: formatErrorMessage("Format type must be a string"),
|
|
1322
|
+
severity: DiagnosticSeverity4.Error
|
|
1323
|
+
});
|
|
1324
|
+
} else {
|
|
1325
|
+
const formatterXLR = sdk.getType(claimedFormatter.valueNode.value, {
|
|
1326
|
+
getRawType: true
|
|
1327
|
+
});
|
|
1328
|
+
if (!formatterXLR) {
|
|
1329
|
+
validationContext.addViolation({
|
|
1330
|
+
node: formatNode,
|
|
1331
|
+
message: formatErrorMessage(
|
|
1332
|
+
`Formatter ${claimedFormatter} is not a registered formatter`
|
|
1333
|
+
),
|
|
1334
|
+
severity: DiagnosticSeverity4.Error
|
|
1335
|
+
});
|
|
1336
|
+
} else if (formatterXLR.genericArguments && formatterXLR.genericArguments.length === 3) {
|
|
1337
|
+
const otherArgsXLR = formatterXLR.genericArguments[2];
|
|
1338
|
+
const validationIssues = sdk.validateByType(
|
|
1339
|
+
{
|
|
1340
|
+
...otherArgsXLR,
|
|
1341
|
+
properties: {
|
|
1342
|
+
...otherArgsXLR.properties,
|
|
1343
|
+
type: {
|
|
1344
|
+
required: true,
|
|
1345
|
+
node: {
|
|
1346
|
+
type: "string",
|
|
1347
|
+
const: claimedFormatter.valueNode.value
|
|
1348
|
+
}
|
|
1349
|
+
}
|
|
1350
|
+
}
|
|
1351
|
+
},
|
|
1352
|
+
formatNode.jsonNode
|
|
1353
|
+
);
|
|
1354
|
+
validationIssues.forEach((issue) => {
|
|
1355
|
+
validationContext.addViolation({
|
|
1356
|
+
node: formatNode,
|
|
1357
|
+
message: formatErrorMessage(issue.message),
|
|
1358
|
+
severity: translateSeverity(issue.severity)
|
|
1359
|
+
});
|
|
1360
|
+
});
|
|
1361
|
+
}
|
|
1362
|
+
}
|
|
1363
|
+
}
|
|
1364
|
+
function getSchemaTypeNames(schemaObj) {
|
|
1365
|
+
const names = /* @__PURE__ */ new Set();
|
|
1366
|
+
for (const prop of schemaObj.properties) {
|
|
1367
|
+
const key = prop.keyNode?.value;
|
|
1368
|
+
if (typeof key === "string") {
|
|
1369
|
+
names.add(key);
|
|
1370
|
+
}
|
|
1371
|
+
}
|
|
1372
|
+
return names;
|
|
1373
|
+
}
|
|
1374
|
+
function validateDataTypeStructure(dataTypeNode, claimedDataType, sdk, validationContext) {
|
|
1375
|
+
const validationProp = getProperty(dataTypeNode, "validation");
|
|
1376
|
+
if (validationProp?.valueNode && validationProp.valueNode.type !== "array") {
|
|
1377
|
+
validationContext.addViolation({
|
|
1378
|
+
node: validationProp.valueNode,
|
|
1379
|
+
message: formatErrorMessage(
|
|
1380
|
+
'Schema.DataType "validation" must be an array.'
|
|
1381
|
+
),
|
|
1382
|
+
severity: DiagnosticSeverity4.Error
|
|
1383
|
+
});
|
|
1384
|
+
} else if (validationProp?.valueNode) {
|
|
1385
|
+
validationProp.valueNode.children?.forEach((valRef) => {
|
|
1386
|
+
if (valRef && valRef.type === "object") {
|
|
1387
|
+
validateSchemaValidations(valRef, sdk, validationContext);
|
|
1388
|
+
} else {
|
|
1389
|
+
validationContext.addViolation({
|
|
1390
|
+
node: validationProp.valueNode ?? dataTypeNode,
|
|
1391
|
+
message: formatErrorMessage(
|
|
1392
|
+
'Schema.DataType "validation" must be an object.'
|
|
1393
|
+
),
|
|
1394
|
+
severity: DiagnosticSeverity4.Error
|
|
1395
|
+
});
|
|
1396
|
+
}
|
|
1397
|
+
});
|
|
1398
|
+
}
|
|
1399
|
+
const formatProp = getProperty(dataTypeNode, "format");
|
|
1400
|
+
if (formatProp?.valueNode?.type === "object") {
|
|
1401
|
+
validateSchemaFormat(formatProp.valueNode, sdk, validationContext);
|
|
1402
|
+
} else {
|
|
1403
|
+
if (formatProp) {
|
|
1404
|
+
validationContext.addViolation({
|
|
1405
|
+
node: formatProp?.valueNode ?? dataTypeNode,
|
|
1406
|
+
message: formatErrorMessage(
|
|
1407
|
+
'Schema.DataType "format" must be an object.'
|
|
1408
|
+
),
|
|
1409
|
+
severity: DiagnosticSeverity4.Error
|
|
1410
|
+
});
|
|
1411
|
+
}
|
|
1412
|
+
}
|
|
1413
|
+
const defaultNode = claimedDataType.properties?.["default"]?.node;
|
|
1414
|
+
const defaultProp = getProperty(dataTypeNode, "default");
|
|
1415
|
+
if (defaultNode && defaultProp?.valueNode) {
|
|
1416
|
+
if (isPrimitiveTypeNode(defaultNode)) {
|
|
1417
|
+
if (defaultProp.valueNode.type !== defaultNode.type) {
|
|
1418
|
+
validationContext.addViolation({
|
|
1419
|
+
node: defaultProp.valueNode,
|
|
1420
|
+
message: formatErrorMessage(
|
|
1421
|
+
`Default value doesn't match the expected type of ${defaultNode.type} for type ${claimedDataType.name}`
|
|
1422
|
+
),
|
|
1423
|
+
severity: DiagnosticSeverity4.Error
|
|
1424
|
+
});
|
|
1425
|
+
}
|
|
1426
|
+
} else if (defaultNode.type === "or") {
|
|
1427
|
+
if (!defaultNode.or.some((n) => n.type === defaultProp.valueNode?.type)) {
|
|
1428
|
+
validationContext.addViolation({
|
|
1429
|
+
node: defaultProp.valueNode,
|
|
1430
|
+
message: formatErrorMessage(
|
|
1431
|
+
`Default value doesn't match any of the expected types ${defaultNode.or.map((t) => t.type).join(", ")} for type ${claimedDataType.name}`
|
|
1432
|
+
),
|
|
1433
|
+
severity: DiagnosticSeverity4.Error
|
|
1434
|
+
});
|
|
1435
|
+
}
|
|
1436
|
+
} else {
|
|
1437
|
+
validationContext.addViolation({
|
|
1438
|
+
node: defaultProp.valueNode,
|
|
1439
|
+
message: formatErrorMessage(
|
|
1440
|
+
`Unknown default node type ${defaultNode.type}`
|
|
1441
|
+
),
|
|
1442
|
+
severity: DiagnosticSeverity4.Error
|
|
1443
|
+
});
|
|
1444
|
+
}
|
|
1445
|
+
}
|
|
1446
|
+
const isArrayProp = getProperty(dataTypeNode, "isArray");
|
|
1447
|
+
const isRecordProp = getProperty(dataTypeNode, "isRecord");
|
|
1448
|
+
if (isArrayProp?.valueNode && isArrayProp.valueNode.type !== "boolean") {
|
|
1449
|
+
validationContext.addViolation({
|
|
1450
|
+
node: isArrayProp.valueNode,
|
|
1451
|
+
message: formatErrorMessage(
|
|
1452
|
+
'Schema.DataType "isArray" must be a boolean.'
|
|
1453
|
+
),
|
|
1454
|
+
severity: DiagnosticSeverity4.Error
|
|
1455
|
+
});
|
|
1456
|
+
}
|
|
1457
|
+
if (isRecordProp?.valueNode && isRecordProp.valueNode.type !== "boolean") {
|
|
1458
|
+
validationContext.addViolation({
|
|
1459
|
+
node: isRecordProp.valueNode,
|
|
1460
|
+
message: formatErrorMessage(
|
|
1461
|
+
'Schema.DataType "isRecord" must be a boolean.'
|
|
1462
|
+
),
|
|
1463
|
+
severity: DiagnosticSeverity4.Error
|
|
1464
|
+
});
|
|
1465
|
+
}
|
|
1466
|
+
if (isArrayProp?.valueNode && isRecordProp?.valueNode && isArrayProp.valueNode.value === true && isRecordProp.valueNode.value === true) {
|
|
1467
|
+
validationContext.addViolation({
|
|
1468
|
+
node: dataTypeNode,
|
|
1469
|
+
message: formatErrorMessage(
|
|
1470
|
+
'Schema.DataType cannot have both "isArray" and "isRecord" true.'
|
|
1471
|
+
),
|
|
1472
|
+
severity: DiagnosticSeverity4.Error
|
|
1473
|
+
});
|
|
1474
|
+
}
|
|
1475
|
+
}
|
|
1476
|
+
function validateSchemaNode(node, schemaTypeNames, sdk, validationContext) {
|
|
1477
|
+
for (const prop of node.properties) {
|
|
1478
|
+
const valueNode = prop.valueNode;
|
|
1479
|
+
if (!(valueNode && valueNode.type === "object")) {
|
|
1480
|
+
if (valueNode) {
|
|
1481
|
+
validationContext.addViolation({
|
|
1482
|
+
node: valueNode,
|
|
1483
|
+
message: formatErrorMessage(
|
|
1484
|
+
`Schema property "${prop.keyNode.value}" must be an object (Schema.DataType) with a "type" field.`
|
|
1485
|
+
),
|
|
1486
|
+
severity: DiagnosticSeverity4.Error
|
|
1487
|
+
});
|
|
1488
|
+
}
|
|
1489
|
+
continue;
|
|
1490
|
+
}
|
|
1491
|
+
const dataTypeNode = valueNode;
|
|
1492
|
+
const typeProp = getProperty(dataTypeNode, "type");
|
|
1493
|
+
if (!typeProp) {
|
|
1494
|
+
validationContext.addViolation({
|
|
1495
|
+
node: valueNode,
|
|
1496
|
+
message: formatErrorMessage(
|
|
1497
|
+
'Schema.DataType must have a "type" property (reference to schema or XLR type).'
|
|
1498
|
+
),
|
|
1499
|
+
severity: DiagnosticSeverity4.Error
|
|
1500
|
+
});
|
|
1501
|
+
continue;
|
|
1502
|
+
}
|
|
1503
|
+
const typeValueNode = typeProp.valueNode;
|
|
1504
|
+
if (!typeValueNode || typeValueNode.type !== "string") {
|
|
1505
|
+
validationContext.addViolation({
|
|
1506
|
+
node: typeValueNode ?? typeProp,
|
|
1507
|
+
message: formatErrorMessage(
|
|
1508
|
+
'Schema "type" must be a string (schema type name or XLR type name).'
|
|
1509
|
+
),
|
|
1510
|
+
severity: DiagnosticSeverity4.Error
|
|
1511
|
+
});
|
|
1512
|
+
continue;
|
|
1513
|
+
}
|
|
1514
|
+
const typeName = typeValueNode.value;
|
|
1515
|
+
const isSchemaType = schemaTypeNames.has(typeName);
|
|
1516
|
+
const XLRType = sdk.getType(typeName, { getRawType: true });
|
|
1517
|
+
if (!isSchemaType && !XLRType) {
|
|
1518
|
+
validationContext.addViolation({
|
|
1519
|
+
node: typeValueNode,
|
|
1520
|
+
message: formatErrorMessage(
|
|
1521
|
+
`Unknown schema type "${typeName}". Type must be a schema type (key in this schema) or an XLR type loaded in the SDK.`
|
|
1522
|
+
),
|
|
1523
|
+
severity: DiagnosticSeverity4.Error
|
|
1524
|
+
});
|
|
1525
|
+
} else if (XLRType) {
|
|
1526
|
+
validateDataTypeStructure(
|
|
1527
|
+
dataTypeNode,
|
|
1528
|
+
XLRType,
|
|
1529
|
+
sdk,
|
|
1530
|
+
validationContext
|
|
1531
|
+
);
|
|
1532
|
+
}
|
|
1533
|
+
}
|
|
1534
|
+
}
|
|
1535
|
+
function validateFlowSchema(contentNode, sdk, validationContext) {
|
|
1536
|
+
const schemaProp = getProperty(contentNode, "schema");
|
|
1537
|
+
if (!schemaProp?.valueNode) {
|
|
1538
|
+
return;
|
|
1539
|
+
}
|
|
1540
|
+
const schemaValue = schemaProp.valueNode;
|
|
1541
|
+
if (schemaValue.type !== "object") {
|
|
1542
|
+
validationContext.addViolation({
|
|
1543
|
+
node: schemaValue,
|
|
1544
|
+
message: formatErrorMessage(
|
|
1545
|
+
'Flow "schema" must be an object with at least a "ROOT" key.'
|
|
1546
|
+
),
|
|
1547
|
+
severity: DiagnosticSeverity4.Error
|
|
1548
|
+
});
|
|
1549
|
+
return;
|
|
1550
|
+
}
|
|
1551
|
+
const schemaObj = schemaValue;
|
|
1552
|
+
const hasRoot = schemaObj.properties.some((p) => p.keyNode.value === "ROOT");
|
|
1553
|
+
if (!hasRoot) {
|
|
1554
|
+
validationContext.addViolation({
|
|
1555
|
+
node: schemaValue,
|
|
1556
|
+
message: formatErrorMessage('Schema must have a "ROOT" key.'),
|
|
1557
|
+
severity: DiagnosticSeverity4.Error
|
|
1558
|
+
});
|
|
1559
|
+
}
|
|
1560
|
+
const schemaTypeNames = getSchemaTypeNames(schemaObj);
|
|
1561
|
+
for (const prop of schemaObj.properties) {
|
|
1562
|
+
const nodeValue = prop.valueNode;
|
|
1563
|
+
if (!nodeValue || nodeValue.type !== "object") {
|
|
1564
|
+
if (nodeValue) {
|
|
1565
|
+
validationContext.addViolation({
|
|
1566
|
+
node: nodeValue,
|
|
1567
|
+
message: formatErrorMessage(
|
|
1568
|
+
`Schema node "${prop.keyNode.value}" must be an object.`
|
|
1569
|
+
),
|
|
1570
|
+
severity: DiagnosticSeverity4.Error
|
|
1571
|
+
});
|
|
1572
|
+
}
|
|
1573
|
+
continue;
|
|
1574
|
+
}
|
|
1575
|
+
validateSchemaNode(
|
|
1576
|
+
nodeValue,
|
|
1577
|
+
schemaTypeNames,
|
|
1578
|
+
sdk,
|
|
1579
|
+
validationContext
|
|
1580
|
+
);
|
|
1581
|
+
}
|
|
1582
|
+
}
|
|
1583
|
+
var SchemaValidationPlugin = class {
|
|
1584
|
+
name = "schema-validation";
|
|
1585
|
+
/** Resolved when CommonTypes have been loaded into the XLR SDK (once per plugin apply) */
|
|
1586
|
+
commonTypesLoaded = null;
|
|
1587
|
+
apply(service) {
|
|
1588
|
+
service.hooks.validate.tap(this.name, async (_ctx, validationContext) => {
|
|
1589
|
+
await this.commonTypesLoaded;
|
|
1590
|
+
validationContext.useASTVisitor(
|
|
1591
|
+
this.createValidationVisitor(service, validationContext)
|
|
1592
|
+
);
|
|
1593
|
+
});
|
|
1594
|
+
}
|
|
1595
|
+
createValidationVisitor(service, validationContext) {
|
|
1596
|
+
const sdk = service.XLRService.XLRSDK;
|
|
1597
|
+
return {
|
|
1598
|
+
ContentNode: (contentNode) => {
|
|
1599
|
+
validateFlowSchema(contentNode, sdk, validationContext);
|
|
1600
|
+
}
|
|
1601
|
+
};
|
|
1602
|
+
}
|
|
1603
|
+
};
|
|
1604
|
+
|
|
1605
|
+
// ../../../../../../../../../../execroot/_main/bazel-out/k8-fastbuild/bin/language/json-language-service/src/plugins/duplicate-id-plugin.ts
|
|
1606
|
+
import { DiagnosticSeverity as DiagnosticSeverity5 } from "vscode-languageserver-types";
|
|
1206
1607
|
var checkParentTemplate = (node, depth = 0) => {
|
|
1207
1608
|
if (node.parent) {
|
|
1208
1609
|
if (isPropertyNode(node.parent) && node.parent.keyNode.value === "template") {
|
|
@@ -1233,7 +1634,7 @@ var createViolation = (node) => {
|
|
|
1233
1634
|
}
|
|
1234
1635
|
return {
|
|
1235
1636
|
node: valueNode,
|
|
1236
|
-
severity:
|
|
1637
|
+
severity: DiagnosticSeverity5.Error,
|
|
1237
1638
|
message: `The id "${node.id?.valueNode?.value}" is already in use in this view.`,
|
|
1238
1639
|
fix: () => {
|
|
1239
1640
|
return {
|
|
@@ -1275,7 +1676,7 @@ var createValidationVisitor2 = (ctx) => {
|
|
|
1275
1676
|
if (missingIndexSegments.length !== 0) {
|
|
1276
1677
|
ctx.addViolation({
|
|
1277
1678
|
node: assetNode,
|
|
1278
|
-
severity:
|
|
1679
|
+
severity: DiagnosticSeverity5.Error,
|
|
1279
1680
|
message: `The id for this templated elements is missing the following index segments: ${missingIndexSegments.join(
|
|
1280
1681
|
", "
|
|
1281
1682
|
)}`
|
|
@@ -1310,7 +1711,7 @@ var DuplicateIDPlugin = class {
|
|
|
1310
1711
|
};
|
|
1311
1712
|
|
|
1312
1713
|
// ../../../../../../../../../../execroot/_main/bazel-out/k8-fastbuild/bin/language/json-language-service/src/plugins/missing-asset-wrapper-plugin.ts
|
|
1313
|
-
import { DiagnosticSeverity as
|
|
1714
|
+
import { DiagnosticSeverity as DiagnosticSeverity6 } from "vscode-languageserver-types";
|
|
1314
1715
|
var getObjectTarget = (node) => {
|
|
1315
1716
|
if (isObjectNode(node)) {
|
|
1316
1717
|
return node;
|
|
@@ -1346,7 +1747,7 @@ var MissingAssetWrapperPlugin = class {
|
|
|
1346
1747
|
addFixableViolation(d, {
|
|
1347
1748
|
node: originalNode,
|
|
1348
1749
|
message: d.message,
|
|
1349
|
-
severity: d.severity ??
|
|
1750
|
+
severity: d.severity ?? DiagnosticSeverity6.Error,
|
|
1350
1751
|
fix: () => ({
|
|
1351
1752
|
name: `Wrap in "asset"`,
|
|
1352
1753
|
edit: {
|
|
@@ -1372,7 +1773,7 @@ var MissingAssetWrapperPlugin = class {
|
|
|
1372
1773
|
// ../../../../../../../../../../execroot/_main/bazel-out/k8-fastbuild/bin/language/json-language-service/src/plugins/nav-state-plugin.ts
|
|
1373
1774
|
import {
|
|
1374
1775
|
CompletionItemKind as CompletionItemKind3,
|
|
1375
|
-
DiagnosticSeverity as
|
|
1776
|
+
DiagnosticSeverity as DiagnosticSeverity7
|
|
1376
1777
|
} from "vscode-languageserver-types";
|
|
1377
1778
|
var createValidationVisitor3 = (ctx) => {
|
|
1378
1779
|
const validTransitions = /* @__PURE__ */ new Map();
|
|
@@ -1400,7 +1801,7 @@ var createValidationVisitor3 = (ctx) => {
|
|
|
1400
1801
|
if (!validTransitions.get(flowNodeId)?.has(transitionObjects.valueNode.value)) {
|
|
1401
1802
|
ctx.addViolation({
|
|
1402
1803
|
node: transitionObjects.valueNode,
|
|
1403
|
-
severity:
|
|
1804
|
+
severity: DiagnosticSeverity7.Error,
|
|
1404
1805
|
message: `Node "${transitionObjects.valueNode.value}" not found`
|
|
1405
1806
|
});
|
|
1406
1807
|
}
|
|
@@ -1461,7 +1862,7 @@ var NavStatePlugin = class {
|
|
|
1461
1862
|
// ../../../../../../../../../../execroot/_main/bazel-out/k8-fastbuild/bin/language/json-language-service/src/plugins/view-node-plugin.ts
|
|
1462
1863
|
import {
|
|
1463
1864
|
CompletionItemKind as CompletionItemKind4,
|
|
1464
|
-
DiagnosticSeverity as
|
|
1865
|
+
DiagnosticSeverity as DiagnosticSeverity8
|
|
1465
1866
|
} from "vscode-languageserver-types";
|
|
1466
1867
|
var createValidationVisitor4 = (ctx, viewInfo) => {
|
|
1467
1868
|
return {
|
|
@@ -1478,7 +1879,7 @@ var createValidationVisitor4 = (ctx, viewInfo) => {
|
|
|
1478
1879
|
ctx.addViolation({
|
|
1479
1880
|
node: refNode.valueNode,
|
|
1480
1881
|
message: `View with id: ${refID} does not exist.`,
|
|
1481
|
-
severity:
|
|
1882
|
+
severity: DiagnosticSeverity8.Error
|
|
1482
1883
|
});
|
|
1483
1884
|
}
|
|
1484
1885
|
},
|
|
@@ -1488,7 +1889,7 @@ var createValidationVisitor4 = (ctx, viewInfo) => {
|
|
|
1488
1889
|
ctx.addViolation({
|
|
1489
1890
|
node: viewNode.id.valueNode,
|
|
1490
1891
|
message: `View is not reachable`,
|
|
1491
|
-
severity:
|
|
1892
|
+
severity: DiagnosticSeverity8.Warning
|
|
1492
1893
|
});
|
|
1493
1894
|
}
|
|
1494
1895
|
}
|
|
@@ -1588,7 +1989,7 @@ var ViewNodePlugin = class {
|
|
|
1588
1989
|
|
|
1589
1990
|
// ../../../../../../../../../../execroot/_main/bazel-out/k8-fastbuild/bin/language/json-language-service/src/xlr/transforms.ts
|
|
1590
1991
|
import { simpleTransformGenerator } from "@player-tools/xlr-sdk";
|
|
1591
|
-
import { isPrimitiveTypeNode } from "@player-tools/xlr-utils";
|
|
1992
|
+
import { isPrimitiveTypeNode as isPrimitiveTypeNode2 } from "@player-tools/xlr-utils";
|
|
1592
1993
|
var applyCommonProps = (node, capability) => {
|
|
1593
1994
|
return simpleTransformGenerator("object", ["Assets", "Views"], (xlrNode) => {
|
|
1594
1995
|
if (!xlrNode.properties.applicability) {
|
|
@@ -1653,7 +2054,7 @@ var applyValueRefs = (node, capability) => {
|
|
|
1653
2054
|
type: "ref",
|
|
1654
2055
|
ref: "BindingRef"
|
|
1655
2056
|
});
|
|
1656
|
-
} else if (
|
|
2057
|
+
} else if (isPrimitiveTypeNode2(value.node)) {
|
|
1657
2058
|
const newUnionType = {
|
|
1658
2059
|
type: "or",
|
|
1659
2060
|
description: value.node.description,
|
|
@@ -1721,6 +2122,7 @@ var PLUGINS = [
|
|
|
1721
2122
|
new DuplicateIDPlugin(),
|
|
1722
2123
|
new ViewNodePlugin(),
|
|
1723
2124
|
new SchemaInfoPlugin(),
|
|
2125
|
+
new SchemaValidationPlugin(),
|
|
1724
2126
|
new AssetWrapperArrayPlugin(),
|
|
1725
2127
|
new NavStatePlugin(),
|
|
1726
2128
|
new MissingAssetWrapperPlugin(),
|
|
@@ -1738,6 +2140,7 @@ var TRANSFORM_FUNCTIONS = [
|
|
|
1738
2140
|
|
|
1739
2141
|
// ../../../../../../../../../../execroot/_main/bazel-out/k8-fastbuild/bin/language/json-language-service/src/xlr/registry.ts
|
|
1740
2142
|
import { BasicXLRRegistry } from "@player-tools/xlr-sdk";
|
|
2143
|
+
var SINGLE_INSTANCE_CAPABILITIES = ["DataTypes", "Formatters", "Validators"];
|
|
1741
2144
|
var PlayerXLRRegistry = class extends BasicXLRRegistry {
|
|
1742
2145
|
/** Keeps the mapping of how a type is referenced by Player to the underlying XLR */
|
|
1743
2146
|
registrationMap;
|
|
@@ -1768,7 +2171,7 @@ var PlayerXLRRegistry = class extends BasicXLRRegistry {
|
|
|
1768
2171
|
this.registrationMap.set(registeredName, type.name);
|
|
1769
2172
|
registeredName = type.extends.genericArguments[0].const;
|
|
1770
2173
|
}
|
|
1771
|
-
if (this.registrationMap.has(registeredName)) {
|
|
2174
|
+
if (this.registrationMap.has(registeredName) && !SINGLE_INSTANCE_CAPABILITIES.includes(capability)) {
|
|
1772
2175
|
const current = this.registrationMap.get(registeredName);
|
|
1773
2176
|
if (Array.isArray(current)) {
|
|
1774
2177
|
current.push(registeredName);
|
|
@@ -2218,6 +2621,7 @@ export {
|
|
|
2218
2621
|
applyTemplateProperty,
|
|
2219
2622
|
applyValueRefs,
|
|
2220
2623
|
containsRange,
|
|
2624
|
+
findErrorNode,
|
|
2221
2625
|
formatLikeNode,
|
|
2222
2626
|
getContentNode,
|
|
2223
2627
|
getLSLocationOfNode,
|