@embeddable.com/sdk-react 2.2.23 → 2.2.25
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/lib/index.esm.js +53 -2
- package/lib/index.esm.js.map +1 -1
- package/lib/index.js +53 -2
- package/lib/index.js.map +1 -1
- package/package.json +1 -1
package/lib/index.esm.js
CHANGED
|
@@ -506,8 +506,15 @@ const componentMetaSchema = z
|
|
|
506
506
|
}
|
|
507
507
|
});
|
|
508
508
|
|
|
509
|
+
const getObjectProperty = (value) => value.object.name + "." + value.property.name;
|
|
509
510
|
// @ts-ignore
|
|
510
511
|
const babelTraverse = traverse.default;
|
|
512
|
+
const parseAndTraverse = (code, visitor) => {
|
|
513
|
+
const ast = parse(code || "", {
|
|
514
|
+
sourceType: "module",
|
|
515
|
+
});
|
|
516
|
+
babelTraverse(ast, visitor);
|
|
517
|
+
};
|
|
511
518
|
const componentMetaValidator = (metaInfo) => {
|
|
512
519
|
const result = componentMetaSchema.safeParse(metaInfo.meta);
|
|
513
520
|
if (!result.success)
|
|
@@ -515,14 +522,58 @@ const componentMetaValidator = (metaInfo) => {
|
|
|
515
522
|
let moduleNameErrors = validateModuleName(metaInfo);
|
|
516
523
|
const variableErrors = validateVariables(metaInfo.meta);
|
|
517
524
|
const eventErrors = validateComponentEvents(metaInfo);
|
|
518
|
-
|
|
525
|
+
const loadDataErrors = validateComponentProps(metaInfo);
|
|
526
|
+
return [
|
|
527
|
+
...moduleNameErrors,
|
|
528
|
+
...variableErrors,
|
|
529
|
+
...eventErrors,
|
|
530
|
+
...loadDataErrors,
|
|
531
|
+
];
|
|
532
|
+
};
|
|
533
|
+
const validateComponentProps = (metaInfo) => {
|
|
534
|
+
const errors = [];
|
|
535
|
+
parseAndTraverse(metaInfo.moduleInfo.code, {
|
|
536
|
+
ExportDefaultDeclaration: (path) => {
|
|
537
|
+
var _a, _b, _c;
|
|
538
|
+
const componentConfig = path.node.declaration
|
|
539
|
+
.arguments[2];
|
|
540
|
+
const propsNode = (_a = componentConfig.properties) === null || _a === void 0 ? void 0 : _a.find((x) => { var _a; return ((_a = x.key) === null || _a === void 0 ? void 0 : _a.name) === "props"; });
|
|
541
|
+
// There is no props defined
|
|
542
|
+
if (!propsNode)
|
|
543
|
+
return;
|
|
544
|
+
const propsReturnStatement = propsNode.value.body.body.find((x) => x.type === "ReturnStatement");
|
|
545
|
+
const results = (_b = propsReturnStatement === null || propsReturnStatement === void 0 ? void 0 : propsReturnStatement.argument) === null || _b === void 0 ? void 0 : _b.properties.find((x) => { var _a; return ((_a = x === null || x === void 0 ? void 0 : x.key) === null || _a === void 0 ? void 0 : _a.name) === "results"; });
|
|
546
|
+
// There is no results defined inside props
|
|
547
|
+
if (results === undefined) {
|
|
548
|
+
return;
|
|
549
|
+
}
|
|
550
|
+
const loadDataProperties = (_c = results === null || results === void 0 ? void 0 : results.value) === null || _c === void 0 ? void 0 : _c.arguments[0].properties;
|
|
551
|
+
const dimensions = loadDataProperties.find((prop) => prop.key.name === "dimensions");
|
|
552
|
+
const timeDimensions = loadDataProperties.find((prop) => prop.key.name === "timeDimensions");
|
|
553
|
+
// There is no missuse of dimensions and timeDimensions
|
|
554
|
+
if (!dimensions || !timeDimensions)
|
|
555
|
+
return;
|
|
556
|
+
const usedDimensions = dimensions.value.elements.map((x) => getObjectProperty(x));
|
|
557
|
+
const usedTimeDimensions = timeDimensions.value.elements
|
|
558
|
+
.map((x) => x.properties)
|
|
559
|
+
.flatMap((group) => group
|
|
560
|
+
.filter((property) => property.key.name === "dimension")
|
|
561
|
+
.map((property) => getObjectProperty(property.value.object)));
|
|
562
|
+
usedDimensions.forEach((dimension) => {
|
|
563
|
+
if (usedTimeDimensions.includes(dimension)) {
|
|
564
|
+
errors.push(`Dimension ${dimension} should not be requested as both a dimension and a timeDimension.`);
|
|
565
|
+
}
|
|
566
|
+
});
|
|
567
|
+
},
|
|
568
|
+
});
|
|
569
|
+
return errors;
|
|
519
570
|
};
|
|
520
571
|
const validateComponentEvents = (metaInfo) => {
|
|
521
572
|
var _a, _b;
|
|
522
573
|
const definedEvents = (_b = (_a = metaInfo.meta.events) === null || _a === void 0 ? void 0 : _a.map((e) => e.name)) !== null && _b !== void 0 ? _b : [];
|
|
523
574
|
let implementedEvents = [];
|
|
524
575
|
const errors = [];
|
|
525
|
-
|
|
576
|
+
parseAndTraverse(metaInfo.moduleInfo.code, {
|
|
526
577
|
ExportDefaultDeclaration: (path) => {
|
|
527
578
|
var _a, _b, _c, _d;
|
|
528
579
|
const componentConfig = path.node.declaration
|