@player-tools/xlr-sdk 0.9.0 → 0.9.1--canary.196.4186
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 +116 -18
- package/dist/cjs/index.cjs.map +1 -1
- package/dist/index.legacy-esm.js +115 -18
- package/dist/index.mjs +115 -18
- package/dist/index.mjs.map +1 -1
- package/package.json +4 -4
- package/src/__tests__/__snapshots__/sdk.test.ts.snap +12 -0
- package/src/__tests__/sdk.test.ts +150 -1
- package/src/types.ts +38 -5
- package/src/validator.ts +168 -18
- package/types/sdk.d.ts +2 -2
- package/types/types.d.ts +25 -5
- package/types/validator.d.ts +9 -3
package/dist/index.legacy-esm.js
CHANGED
|
@@ -73,10 +73,24 @@ import {
|
|
|
73
73
|
resolveReferenceNode,
|
|
74
74
|
computeEffectiveObject
|
|
75
75
|
} from "@player-tools/xlr-utils";
|
|
76
|
+
|
|
77
|
+
// ../../../../../../../../../../execroot/_main/bazel-out/k8-fastbuild/bin/xlr/sdk/src/types.ts
|
|
78
|
+
var ValidationSeverity = /* @__PURE__ */ ((ValidationSeverity2) => {
|
|
79
|
+
ValidationSeverity2[ValidationSeverity2["Error"] = 1] = "Error";
|
|
80
|
+
ValidationSeverity2[ValidationSeverity2["Warning"] = 2] = "Warning";
|
|
81
|
+
ValidationSeverity2[ValidationSeverity2["Info"] = 3] = "Info";
|
|
82
|
+
ValidationSeverity2[ValidationSeverity2["Trace"] = 4] = "Trace";
|
|
83
|
+
return ValidationSeverity2;
|
|
84
|
+
})(ValidationSeverity || {});
|
|
85
|
+
|
|
86
|
+
// ../../../../../../../../../../execroot/_main/bazel-out/k8-fastbuild/bin/xlr/sdk/src/validator.ts
|
|
87
|
+
var MAX_VALID_SHOWN = 20;
|
|
76
88
|
var XLRValidator = class {
|
|
89
|
+
config;
|
|
77
90
|
resolveType;
|
|
78
91
|
regexCache;
|
|
79
|
-
constructor(resolveType) {
|
|
92
|
+
constructor(resolveType, config) {
|
|
93
|
+
this.config = config || {};
|
|
80
94
|
this.resolveType = resolveType;
|
|
81
95
|
this.regexCache = /* @__PURE__ */ new Map();
|
|
82
96
|
}
|
|
@@ -90,7 +104,8 @@ var XLRValidator = class {
|
|
|
90
104
|
validationIssues.push({
|
|
91
105
|
type: "type",
|
|
92
106
|
node: rootNode,
|
|
93
|
-
message: `Expected an object but got an "${rootNode.type}"
|
|
107
|
+
message: `Expected an object but got an "${rootNode.type}"`,
|
|
108
|
+
severity: 1 /* Error */
|
|
94
109
|
});
|
|
95
110
|
}
|
|
96
111
|
} else if (xlrNode.type === "array") {
|
|
@@ -100,7 +115,8 @@ var XLRValidator = class {
|
|
|
100
115
|
validationIssues.push({
|
|
101
116
|
type: "type",
|
|
102
117
|
node: rootNode,
|
|
103
|
-
message: `Expected an array but got an "${rootNode.type}"
|
|
118
|
+
message: `Expected an array but got an "${rootNode.type}"`,
|
|
119
|
+
severity: 1 /* Error */
|
|
104
120
|
});
|
|
105
121
|
}
|
|
106
122
|
} else if (xlrNode.type === "template") {
|
|
@@ -109,25 +125,45 @@ var XLRValidator = class {
|
|
|
109
125
|
validationIssues.push(error);
|
|
110
126
|
}
|
|
111
127
|
} else if (xlrNode.type === "or") {
|
|
128
|
+
const potentialTypeErrors = [];
|
|
112
129
|
for (const potentialType of xlrNode.or) {
|
|
113
130
|
const potentialErrors = this.validateType(rootNode, potentialType);
|
|
114
131
|
if (potentialErrors.length === 0) {
|
|
115
132
|
return validationIssues;
|
|
116
133
|
}
|
|
134
|
+
potentialTypeErrors.push({
|
|
135
|
+
type: potentialType,
|
|
136
|
+
errors: potentialErrors
|
|
137
|
+
});
|
|
117
138
|
}
|
|
118
139
|
let message;
|
|
140
|
+
const expectedTypes = xlrNode.or.map((node) => node.name ?? node.title ?? node.type ?? "<unnamed type>").join(" | ");
|
|
119
141
|
if (xlrNode.name) {
|
|
120
142
|
message = `Does not match any of the expected types for type: '${xlrNode.name}'`;
|
|
121
143
|
} else if (xlrNode.title) {
|
|
122
144
|
message = `Does not match any of the expected types for property: '${xlrNode.title}'`;
|
|
123
145
|
} else {
|
|
124
|
-
message = `Does not match any of the types ${
|
|
146
|
+
message = `Does not match any of the types: ${expectedTypes}`;
|
|
125
147
|
}
|
|
148
|
+
const { infoMessage } = this.generateNestedTypesInfo(
|
|
149
|
+
potentialTypeErrors,
|
|
150
|
+
xlrNode,
|
|
151
|
+
rootNode
|
|
152
|
+
);
|
|
126
153
|
validationIssues.push({
|
|
127
154
|
type: "value",
|
|
128
155
|
node: rootNode,
|
|
129
|
-
message
|
|
156
|
+
message: message.trim(),
|
|
157
|
+
severity: 1 /* Error */
|
|
130
158
|
});
|
|
159
|
+
if (infoMessage) {
|
|
160
|
+
validationIssues.push({
|
|
161
|
+
type: "value",
|
|
162
|
+
node: rootNode,
|
|
163
|
+
message: infoMessage,
|
|
164
|
+
severity: 3 /* Info */
|
|
165
|
+
});
|
|
166
|
+
}
|
|
131
167
|
} else if (xlrNode.type === "and") {
|
|
132
168
|
const effectiveType = {
|
|
133
169
|
...this.computeIntersectionType(xlrNode.and),
|
|
@@ -149,7 +185,8 @@ var XLRValidator = class {
|
|
|
149
185
|
validationIssues.push({
|
|
150
186
|
type: "unknown",
|
|
151
187
|
node: rootNode,
|
|
152
|
-
message: `Type "${xlrNode.ref}" is not defined in provided bundles
|
|
188
|
+
message: `Type "${xlrNode.ref}" is not defined in provided bundles`,
|
|
189
|
+
severity: 1 /* Error */
|
|
153
190
|
});
|
|
154
191
|
} else {
|
|
155
192
|
validationIssues.push(
|
|
@@ -162,13 +199,17 @@ var XLRValidator = class {
|
|
|
162
199
|
validationIssues.push({
|
|
163
200
|
type: "type",
|
|
164
201
|
node: rootNode.parent,
|
|
165
|
-
message: `Expected "${xlrNode.const}" but got "${rootNode.value}"
|
|
202
|
+
message: `Expected "${xlrNode.const}" but got "${rootNode.value}"`,
|
|
203
|
+
expected: xlrNode.const,
|
|
204
|
+
severity: 1 /* Error */
|
|
166
205
|
});
|
|
167
206
|
} else {
|
|
168
207
|
validationIssues.push({
|
|
169
208
|
type: "type",
|
|
170
209
|
node: rootNode.parent,
|
|
171
|
-
message: `Expected type "${xlrNode.type}" but got "${rootNode.type}"
|
|
210
|
+
message: `Expected type "${xlrNode.type}" but got "${rootNode.type}"`,
|
|
211
|
+
expected: xlrNode.type,
|
|
212
|
+
severity: 1 /* Error */
|
|
172
213
|
});
|
|
173
214
|
}
|
|
174
215
|
}
|
|
@@ -201,12 +242,45 @@ var XLRValidator = class {
|
|
|
201
242
|
}
|
|
202
243
|
return validationIssues;
|
|
203
244
|
}
|
|
245
|
+
generateNestedTypesInfo(potentialTypeErrors, xlrNode, rootNode) {
|
|
246
|
+
const nestedTypes = /* @__PURE__ */ new Set();
|
|
247
|
+
potentialTypeErrors.forEach((typeError) => {
|
|
248
|
+
if (typeError.type.type !== "template") {
|
|
249
|
+
typeError.errors.forEach((error) => {
|
|
250
|
+
if (error.type === "type" && error.expected) {
|
|
251
|
+
String(error.expected).split(" | ").forEach((val) => nestedTypes.add(val.trim()));
|
|
252
|
+
}
|
|
253
|
+
});
|
|
254
|
+
}
|
|
255
|
+
});
|
|
256
|
+
if (nestedTypes.size === 0) {
|
|
257
|
+
xlrNode.or.forEach((type) => {
|
|
258
|
+
const typeName = type.name ?? type.title ?? type.type ?? "<unnamed type>";
|
|
259
|
+
nestedTypes.add(typeName);
|
|
260
|
+
});
|
|
261
|
+
}
|
|
262
|
+
const nestedTypesArray = [...nestedTypes];
|
|
263
|
+
let nestedTypesList = nestedTypesArray.slice(0, MAX_VALID_SHOWN).join(" | ") + (nestedTypesArray.length > MAX_VALID_SHOWN ? ` | +${nestedTypesArray.length - MAX_VALID_SHOWN} ... ${nestedTypesArray.pop()}` : "");
|
|
264
|
+
const docsURL = this.config.urlMapping;
|
|
265
|
+
if (docsURL && xlrNode.name && docsURL[xlrNode.name]) {
|
|
266
|
+
nestedTypesList = docsURL[xlrNode.name];
|
|
267
|
+
}
|
|
268
|
+
let infoMessage;
|
|
269
|
+
if (rootNode.value !== void 0) {
|
|
270
|
+
infoMessage = `Got: ${rootNode.value} and expected: ${nestedTypesList}`;
|
|
271
|
+
} else if (nestedTypesList) {
|
|
272
|
+
infoMessage = `Expected: ${nestedTypesList}`;
|
|
273
|
+
}
|
|
274
|
+
return { nestedTypesList, infoMessage };
|
|
275
|
+
}
|
|
204
276
|
validateTemplate(node, xlrNode) {
|
|
205
277
|
if (node.type !== "string") {
|
|
206
278
|
return {
|
|
207
279
|
type: "type",
|
|
208
280
|
node: node.parent,
|
|
209
|
-
message: `Expected type "${xlrNode.type}" but got "${typeof node}"
|
|
281
|
+
message: `Expected type "${xlrNode.type}" but got "${typeof node}"`,
|
|
282
|
+
expected: xlrNode.type,
|
|
283
|
+
severity: 1 /* Error */
|
|
210
284
|
};
|
|
211
285
|
}
|
|
212
286
|
const regex = this.getRegex(xlrNode.format);
|
|
@@ -215,7 +289,9 @@ var XLRValidator = class {
|
|
|
215
289
|
return {
|
|
216
290
|
type: "value",
|
|
217
291
|
node: node.parent,
|
|
218
|
-
message: `Does not match expected format: ${xlrNode.format}
|
|
292
|
+
message: `Does not match expected format: ${xlrNode.format}`,
|
|
293
|
+
expected: xlrNode.format,
|
|
294
|
+
severity: 1 /* Error */
|
|
219
295
|
};
|
|
220
296
|
}
|
|
221
297
|
}
|
|
@@ -236,7 +312,8 @@ var XLRValidator = class {
|
|
|
236
312
|
issues.push({
|
|
237
313
|
type: "missing",
|
|
238
314
|
node,
|
|
239
|
-
message: `Property "${prop}" missing from type "${xlrNode.name}"
|
|
315
|
+
message: `Property "${prop}" missing from type "${xlrNode.name}"`,
|
|
316
|
+
severity: 1 /* Error */
|
|
240
317
|
});
|
|
241
318
|
}
|
|
242
319
|
if (valueNode) {
|
|
@@ -254,7 +331,8 @@ var XLRValidator = class {
|
|
|
254
331
|
node,
|
|
255
332
|
message: `Unexpected properties on "${xlrNode.name}": ${extraKeys.join(
|
|
256
333
|
", "
|
|
257
|
-
)}
|
|
334
|
+
)}`,
|
|
335
|
+
severity: 1 /* Error */
|
|
258
336
|
});
|
|
259
337
|
} else {
|
|
260
338
|
issues.push(
|
|
@@ -321,6 +399,7 @@ var XLRValidator = class {
|
|
|
321
399
|
computeIntersectionType(types) {
|
|
322
400
|
let firstElement = types[0];
|
|
323
401
|
let effectiveType;
|
|
402
|
+
const topLevelTypeName = types[0].name;
|
|
324
403
|
if (firstElement.type === "ref") {
|
|
325
404
|
firstElement = this.getRefType(firstElement);
|
|
326
405
|
}
|
|
@@ -360,18 +439,32 @@ var XLRValidator = class {
|
|
|
360
439
|
} else {
|
|
361
440
|
effectiveType = {
|
|
362
441
|
...effectiveType,
|
|
363
|
-
or: effectiveType.or.map(
|
|
364
|
-
|
|
365
|
-
|
|
442
|
+
or: effectiveType.or.map((y) => {
|
|
443
|
+
const intersectedType = this.computeIntersectionType([
|
|
444
|
+
y,
|
|
445
|
+
typeToApply
|
|
446
|
+
]);
|
|
447
|
+
if (!intersectedType.name && topLevelTypeName) {
|
|
448
|
+
intersectedType.name = topLevelTypeName;
|
|
449
|
+
}
|
|
450
|
+
return intersectedType;
|
|
451
|
+
})
|
|
366
452
|
};
|
|
367
453
|
}
|
|
368
454
|
} else if (typeToApply.type === "or") {
|
|
369
455
|
if (effectiveType.type === "object") {
|
|
370
456
|
effectiveType = {
|
|
371
457
|
...typeToApply,
|
|
372
|
-
or: typeToApply.or.map(
|
|
373
|
-
|
|
374
|
-
|
|
458
|
+
or: typeToApply.or.map((y) => {
|
|
459
|
+
const intersectedType = this.computeIntersectionType([
|
|
460
|
+
y,
|
|
461
|
+
effectiveType
|
|
462
|
+
]);
|
|
463
|
+
if (!intersectedType.name && topLevelTypeName) {
|
|
464
|
+
intersectedType.name = topLevelTypeName;
|
|
465
|
+
}
|
|
466
|
+
return intersectedType;
|
|
467
|
+
})
|
|
375
468
|
};
|
|
376
469
|
} else {
|
|
377
470
|
throw new Error("unimplemented operation or x or projection");
|
|
@@ -382,6 +475,9 @@ var XLRValidator = class {
|
|
|
382
475
|
);
|
|
383
476
|
}
|
|
384
477
|
});
|
|
478
|
+
if (effectiveType.type === "or" && !effectiveType.name && topLevelTypeName) {
|
|
479
|
+
effectiveType.name = topLevelTypeName;
|
|
480
|
+
}
|
|
385
481
|
return effectiveType;
|
|
386
482
|
}
|
|
387
483
|
};
|
|
@@ -855,6 +951,7 @@ ${nodeText}`;
|
|
|
855
951
|
};
|
|
856
952
|
export {
|
|
857
953
|
BasicXLRRegistry,
|
|
954
|
+
ValidationSeverity,
|
|
858
955
|
XLRSDK,
|
|
859
956
|
simpleTransformGenerator,
|
|
860
957
|
xlrTransformWalker
|
package/dist/index.mjs
CHANGED
|
@@ -73,10 +73,24 @@ import {
|
|
|
73
73
|
resolveReferenceNode,
|
|
74
74
|
computeEffectiveObject
|
|
75
75
|
} from "@player-tools/xlr-utils";
|
|
76
|
+
|
|
77
|
+
// ../../../../../../../../../../execroot/_main/bazel-out/k8-fastbuild/bin/xlr/sdk/src/types.ts
|
|
78
|
+
var ValidationSeverity = /* @__PURE__ */ ((ValidationSeverity2) => {
|
|
79
|
+
ValidationSeverity2[ValidationSeverity2["Error"] = 1] = "Error";
|
|
80
|
+
ValidationSeverity2[ValidationSeverity2["Warning"] = 2] = "Warning";
|
|
81
|
+
ValidationSeverity2[ValidationSeverity2["Info"] = 3] = "Info";
|
|
82
|
+
ValidationSeverity2[ValidationSeverity2["Trace"] = 4] = "Trace";
|
|
83
|
+
return ValidationSeverity2;
|
|
84
|
+
})(ValidationSeverity || {});
|
|
85
|
+
|
|
86
|
+
// ../../../../../../../../../../execroot/_main/bazel-out/k8-fastbuild/bin/xlr/sdk/src/validator.ts
|
|
87
|
+
var MAX_VALID_SHOWN = 20;
|
|
76
88
|
var XLRValidator = class {
|
|
89
|
+
config;
|
|
77
90
|
resolveType;
|
|
78
91
|
regexCache;
|
|
79
|
-
constructor(resolveType) {
|
|
92
|
+
constructor(resolveType, config) {
|
|
93
|
+
this.config = config || {};
|
|
80
94
|
this.resolveType = resolveType;
|
|
81
95
|
this.regexCache = /* @__PURE__ */ new Map();
|
|
82
96
|
}
|
|
@@ -90,7 +104,8 @@ var XLRValidator = class {
|
|
|
90
104
|
validationIssues.push({
|
|
91
105
|
type: "type",
|
|
92
106
|
node: rootNode,
|
|
93
|
-
message: `Expected an object but got an "${rootNode.type}"
|
|
107
|
+
message: `Expected an object but got an "${rootNode.type}"`,
|
|
108
|
+
severity: 1 /* Error */
|
|
94
109
|
});
|
|
95
110
|
}
|
|
96
111
|
} else if (xlrNode.type === "array") {
|
|
@@ -100,7 +115,8 @@ var XLRValidator = class {
|
|
|
100
115
|
validationIssues.push({
|
|
101
116
|
type: "type",
|
|
102
117
|
node: rootNode,
|
|
103
|
-
message: `Expected an array but got an "${rootNode.type}"
|
|
118
|
+
message: `Expected an array but got an "${rootNode.type}"`,
|
|
119
|
+
severity: 1 /* Error */
|
|
104
120
|
});
|
|
105
121
|
}
|
|
106
122
|
} else if (xlrNode.type === "template") {
|
|
@@ -109,25 +125,45 @@ var XLRValidator = class {
|
|
|
109
125
|
validationIssues.push(error);
|
|
110
126
|
}
|
|
111
127
|
} else if (xlrNode.type === "or") {
|
|
128
|
+
const potentialTypeErrors = [];
|
|
112
129
|
for (const potentialType of xlrNode.or) {
|
|
113
130
|
const potentialErrors = this.validateType(rootNode, potentialType);
|
|
114
131
|
if (potentialErrors.length === 0) {
|
|
115
132
|
return validationIssues;
|
|
116
133
|
}
|
|
134
|
+
potentialTypeErrors.push({
|
|
135
|
+
type: potentialType,
|
|
136
|
+
errors: potentialErrors
|
|
137
|
+
});
|
|
117
138
|
}
|
|
118
139
|
let message;
|
|
140
|
+
const expectedTypes = xlrNode.or.map((node) => node.name ?? node.title ?? node.type ?? "<unnamed type>").join(" | ");
|
|
119
141
|
if (xlrNode.name) {
|
|
120
142
|
message = `Does not match any of the expected types for type: '${xlrNode.name}'`;
|
|
121
143
|
} else if (xlrNode.title) {
|
|
122
144
|
message = `Does not match any of the expected types for property: '${xlrNode.title}'`;
|
|
123
145
|
} else {
|
|
124
|
-
message = `Does not match any of the types ${
|
|
146
|
+
message = `Does not match any of the types: ${expectedTypes}`;
|
|
125
147
|
}
|
|
148
|
+
const { infoMessage } = this.generateNestedTypesInfo(
|
|
149
|
+
potentialTypeErrors,
|
|
150
|
+
xlrNode,
|
|
151
|
+
rootNode
|
|
152
|
+
);
|
|
126
153
|
validationIssues.push({
|
|
127
154
|
type: "value",
|
|
128
155
|
node: rootNode,
|
|
129
|
-
message
|
|
156
|
+
message: message.trim(),
|
|
157
|
+
severity: 1 /* Error */
|
|
130
158
|
});
|
|
159
|
+
if (infoMessage) {
|
|
160
|
+
validationIssues.push({
|
|
161
|
+
type: "value",
|
|
162
|
+
node: rootNode,
|
|
163
|
+
message: infoMessage,
|
|
164
|
+
severity: 3 /* Info */
|
|
165
|
+
});
|
|
166
|
+
}
|
|
131
167
|
} else if (xlrNode.type === "and") {
|
|
132
168
|
const effectiveType = {
|
|
133
169
|
...this.computeIntersectionType(xlrNode.and),
|
|
@@ -149,7 +185,8 @@ var XLRValidator = class {
|
|
|
149
185
|
validationIssues.push({
|
|
150
186
|
type: "unknown",
|
|
151
187
|
node: rootNode,
|
|
152
|
-
message: `Type "${xlrNode.ref}" is not defined in provided bundles
|
|
188
|
+
message: `Type "${xlrNode.ref}" is not defined in provided bundles`,
|
|
189
|
+
severity: 1 /* Error */
|
|
153
190
|
});
|
|
154
191
|
} else {
|
|
155
192
|
validationIssues.push(
|
|
@@ -162,13 +199,17 @@ var XLRValidator = class {
|
|
|
162
199
|
validationIssues.push({
|
|
163
200
|
type: "type",
|
|
164
201
|
node: rootNode.parent,
|
|
165
|
-
message: `Expected "${xlrNode.const}" but got "${rootNode.value}"
|
|
202
|
+
message: `Expected "${xlrNode.const}" but got "${rootNode.value}"`,
|
|
203
|
+
expected: xlrNode.const,
|
|
204
|
+
severity: 1 /* Error */
|
|
166
205
|
});
|
|
167
206
|
} else {
|
|
168
207
|
validationIssues.push({
|
|
169
208
|
type: "type",
|
|
170
209
|
node: rootNode.parent,
|
|
171
|
-
message: `Expected type "${xlrNode.type}" but got "${rootNode.type}"
|
|
210
|
+
message: `Expected type "${xlrNode.type}" but got "${rootNode.type}"`,
|
|
211
|
+
expected: xlrNode.type,
|
|
212
|
+
severity: 1 /* Error */
|
|
172
213
|
});
|
|
173
214
|
}
|
|
174
215
|
}
|
|
@@ -201,12 +242,45 @@ var XLRValidator = class {
|
|
|
201
242
|
}
|
|
202
243
|
return validationIssues;
|
|
203
244
|
}
|
|
245
|
+
generateNestedTypesInfo(potentialTypeErrors, xlrNode, rootNode) {
|
|
246
|
+
const nestedTypes = /* @__PURE__ */ new Set();
|
|
247
|
+
potentialTypeErrors.forEach((typeError) => {
|
|
248
|
+
if (typeError.type.type !== "template") {
|
|
249
|
+
typeError.errors.forEach((error) => {
|
|
250
|
+
if (error.type === "type" && error.expected) {
|
|
251
|
+
String(error.expected).split(" | ").forEach((val) => nestedTypes.add(val.trim()));
|
|
252
|
+
}
|
|
253
|
+
});
|
|
254
|
+
}
|
|
255
|
+
});
|
|
256
|
+
if (nestedTypes.size === 0) {
|
|
257
|
+
xlrNode.or.forEach((type) => {
|
|
258
|
+
const typeName = type.name ?? type.title ?? type.type ?? "<unnamed type>";
|
|
259
|
+
nestedTypes.add(typeName);
|
|
260
|
+
});
|
|
261
|
+
}
|
|
262
|
+
const nestedTypesArray = [...nestedTypes];
|
|
263
|
+
let nestedTypesList = nestedTypesArray.slice(0, MAX_VALID_SHOWN).join(" | ") + (nestedTypesArray.length > MAX_VALID_SHOWN ? ` | +${nestedTypesArray.length - MAX_VALID_SHOWN} ... ${nestedTypesArray.pop()}` : "");
|
|
264
|
+
const docsURL = this.config.urlMapping;
|
|
265
|
+
if (docsURL && xlrNode.name && docsURL[xlrNode.name]) {
|
|
266
|
+
nestedTypesList = docsURL[xlrNode.name];
|
|
267
|
+
}
|
|
268
|
+
let infoMessage;
|
|
269
|
+
if (rootNode.value !== void 0) {
|
|
270
|
+
infoMessage = `Got: ${rootNode.value} and expected: ${nestedTypesList}`;
|
|
271
|
+
} else if (nestedTypesList) {
|
|
272
|
+
infoMessage = `Expected: ${nestedTypesList}`;
|
|
273
|
+
}
|
|
274
|
+
return { nestedTypesList, infoMessage };
|
|
275
|
+
}
|
|
204
276
|
validateTemplate(node, xlrNode) {
|
|
205
277
|
if (node.type !== "string") {
|
|
206
278
|
return {
|
|
207
279
|
type: "type",
|
|
208
280
|
node: node.parent,
|
|
209
|
-
message: `Expected type "${xlrNode.type}" but got "${typeof node}"
|
|
281
|
+
message: `Expected type "${xlrNode.type}" but got "${typeof node}"`,
|
|
282
|
+
expected: xlrNode.type,
|
|
283
|
+
severity: 1 /* Error */
|
|
210
284
|
};
|
|
211
285
|
}
|
|
212
286
|
const regex = this.getRegex(xlrNode.format);
|
|
@@ -215,7 +289,9 @@ var XLRValidator = class {
|
|
|
215
289
|
return {
|
|
216
290
|
type: "value",
|
|
217
291
|
node: node.parent,
|
|
218
|
-
message: `Does not match expected format: ${xlrNode.format}
|
|
292
|
+
message: `Does not match expected format: ${xlrNode.format}`,
|
|
293
|
+
expected: xlrNode.format,
|
|
294
|
+
severity: 1 /* Error */
|
|
219
295
|
};
|
|
220
296
|
}
|
|
221
297
|
}
|
|
@@ -236,7 +312,8 @@ var XLRValidator = class {
|
|
|
236
312
|
issues.push({
|
|
237
313
|
type: "missing",
|
|
238
314
|
node,
|
|
239
|
-
message: `Property "${prop}" missing from type "${xlrNode.name}"
|
|
315
|
+
message: `Property "${prop}" missing from type "${xlrNode.name}"`,
|
|
316
|
+
severity: 1 /* Error */
|
|
240
317
|
});
|
|
241
318
|
}
|
|
242
319
|
if (valueNode) {
|
|
@@ -254,7 +331,8 @@ var XLRValidator = class {
|
|
|
254
331
|
node,
|
|
255
332
|
message: `Unexpected properties on "${xlrNode.name}": ${extraKeys.join(
|
|
256
333
|
", "
|
|
257
|
-
)}
|
|
334
|
+
)}`,
|
|
335
|
+
severity: 1 /* Error */
|
|
258
336
|
});
|
|
259
337
|
} else {
|
|
260
338
|
issues.push(
|
|
@@ -321,6 +399,7 @@ var XLRValidator = class {
|
|
|
321
399
|
computeIntersectionType(types) {
|
|
322
400
|
let firstElement = types[0];
|
|
323
401
|
let effectiveType;
|
|
402
|
+
const topLevelTypeName = types[0].name;
|
|
324
403
|
if (firstElement.type === "ref") {
|
|
325
404
|
firstElement = this.getRefType(firstElement);
|
|
326
405
|
}
|
|
@@ -360,18 +439,32 @@ var XLRValidator = class {
|
|
|
360
439
|
} else {
|
|
361
440
|
effectiveType = {
|
|
362
441
|
...effectiveType,
|
|
363
|
-
or: effectiveType.or.map(
|
|
364
|
-
|
|
365
|
-
|
|
442
|
+
or: effectiveType.or.map((y) => {
|
|
443
|
+
const intersectedType = this.computeIntersectionType([
|
|
444
|
+
y,
|
|
445
|
+
typeToApply
|
|
446
|
+
]);
|
|
447
|
+
if (!intersectedType.name && topLevelTypeName) {
|
|
448
|
+
intersectedType.name = topLevelTypeName;
|
|
449
|
+
}
|
|
450
|
+
return intersectedType;
|
|
451
|
+
})
|
|
366
452
|
};
|
|
367
453
|
}
|
|
368
454
|
} else if (typeToApply.type === "or") {
|
|
369
455
|
if (effectiveType.type === "object") {
|
|
370
456
|
effectiveType = {
|
|
371
457
|
...typeToApply,
|
|
372
|
-
or: typeToApply.or.map(
|
|
373
|
-
|
|
374
|
-
|
|
458
|
+
or: typeToApply.or.map((y) => {
|
|
459
|
+
const intersectedType = this.computeIntersectionType([
|
|
460
|
+
y,
|
|
461
|
+
effectiveType
|
|
462
|
+
]);
|
|
463
|
+
if (!intersectedType.name && topLevelTypeName) {
|
|
464
|
+
intersectedType.name = topLevelTypeName;
|
|
465
|
+
}
|
|
466
|
+
return intersectedType;
|
|
467
|
+
})
|
|
375
468
|
};
|
|
376
469
|
} else {
|
|
377
470
|
throw new Error("unimplemented operation or x or projection");
|
|
@@ -382,6 +475,9 @@ var XLRValidator = class {
|
|
|
382
475
|
);
|
|
383
476
|
}
|
|
384
477
|
});
|
|
478
|
+
if (effectiveType.type === "or" && !effectiveType.name && topLevelTypeName) {
|
|
479
|
+
effectiveType.name = topLevelTypeName;
|
|
480
|
+
}
|
|
385
481
|
return effectiveType;
|
|
386
482
|
}
|
|
387
483
|
};
|
|
@@ -855,6 +951,7 @@ ${nodeText}`;
|
|
|
855
951
|
};
|
|
856
952
|
export {
|
|
857
953
|
BasicXLRRegistry,
|
|
954
|
+
ValidationSeverity,
|
|
858
955
|
XLRSDK,
|
|
859
956
|
simpleTransformGenerator,
|
|
860
957
|
xlrTransformWalker
|