@contentstack/studio-registry 1.2.1 → 1.3.0
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 +97 -6
- package/dist/cjs/index.cjs.map +1 -1
- package/dist/esm/component-registry/registry.js +17 -1
- package/dist/esm/component-registry/registry.js.map +1 -1
- package/dist/esm/data-binder/retrieve-data.js +29 -5
- package/dist/esm/data-binder/retrieve-data.js.map +1 -1
- package/dist/esm/utils/registry-error-messages.default.js +22 -0
- package/dist/esm/utils/registry-error-messages.default.js.map +1 -0
- package/dist/esm/utils/registry-error-messages.js +40 -0
- package/dist/esm/utils/registry-error-messages.js.map +1 -0
- package/package.json +6 -6
package/dist/cjs/index.cjs
CHANGED
|
@@ -2,6 +2,61 @@
|
|
|
2
2
|
|
|
3
3
|
var studioMessenger = require('@contentstack/studio-messenger');
|
|
4
4
|
|
|
5
|
+
/**
|
|
6
|
+
* Keys for registry error message lookup. Use these constants instead of string literals.
|
|
7
|
+
* @internal
|
|
8
|
+
*/
|
|
9
|
+
const RegistryErrorMessageKey = {
|
|
10
|
+
DATA_BINDING_TYPE_MISMATCH: "DATA_BINDING_TYPE_MISMATCH",
|
|
11
|
+
DATA_BINDING_TYPE_MISMATCH_EDITOR: "DATA_BINDING_TYPE_MISMATCH_EDITOR",
|
|
12
|
+
PROP_VALIDATION_FAILED: "PROP_VALIDATION_FAILED",
|
|
13
|
+
};
|
|
14
|
+
/**
|
|
15
|
+
* Default (en) error message templates for studio-registry. Single source of truth.
|
|
16
|
+
* Use getRegistryErrorMessage() with RegistryErrorMessageKey constants.
|
|
17
|
+
* @internal
|
|
18
|
+
*/
|
|
19
|
+
const defaultRegistryErrorMessages = {
|
|
20
|
+
[RegistryErrorMessageKey.DATA_BINDING_TYPE_MISMATCH]: 'Data binding type mismatch in component "{component}": Expected prop "{field}" to be {expectedType} but received {receivedType}. Path: {dataPath}',
|
|
21
|
+
[RegistryErrorMessageKey.DATA_BINDING_TYPE_MISMATCH_EDITOR]: "Expected prop type {expectedType} but received {receivedType} in the component registry. Remove the binding and bind with correct data.",
|
|
22
|
+
[RegistryErrorMessageKey.PROP_VALIDATION_FAILED]: 'Prop validation failed for "{prop}" in component "{component}": {validationError}',
|
|
23
|
+
};
|
|
24
|
+
|
|
25
|
+
/**
|
|
26
|
+
* Error message lookup for studio-registry. Messages are defined in registry-error-messages.default.ts.
|
|
27
|
+
* Use getRegistryErrorMessage with RegistryErrorMessageKey constants (no string literals).
|
|
28
|
+
* @internal
|
|
29
|
+
*/
|
|
30
|
+
/**
|
|
31
|
+
* Returns the message string for the given key, substituting placeholders with params.
|
|
32
|
+
* Placeholders: {component}, {field}, {expectedType}, {receivedType}, {dataPath}, {prop}, {validationError}
|
|
33
|
+
* @internal
|
|
34
|
+
*/
|
|
35
|
+
function getRegistryErrorMessage(key, params) {
|
|
36
|
+
let template = defaultRegistryErrorMessages[key];
|
|
37
|
+
if (template == null) {
|
|
38
|
+
return String(key);
|
|
39
|
+
}
|
|
40
|
+
if (!params) {
|
|
41
|
+
return template;
|
|
42
|
+
}
|
|
43
|
+
const replacements = [
|
|
44
|
+
["component", params.component],
|
|
45
|
+
["field", params.field],
|
|
46
|
+
["expectedType", params.expectedType],
|
|
47
|
+
["receivedType", params.receivedType],
|
|
48
|
+
["dataPath", params.dataPath],
|
|
49
|
+
["prop", params.prop],
|
|
50
|
+
["validationError", params.validationError],
|
|
51
|
+
];
|
|
52
|
+
for (const [placeholder, value] of replacements) {
|
|
53
|
+
if (value !== undefined) {
|
|
54
|
+
template = template.replace(new RegExp(`\\{${placeholder}\\}`, "g"), String(value));
|
|
55
|
+
}
|
|
56
|
+
}
|
|
57
|
+
return template;
|
|
58
|
+
}
|
|
59
|
+
|
|
5
60
|
const DATA_SOURCES_PREFIX = "dataSources";
|
|
6
61
|
const DATA_SOURCES = {
|
|
7
62
|
COMPONENT_PROPS: "component_props",
|
|
@@ -4234,7 +4289,21 @@ class ComponentRegistry {
|
|
|
4234
4289
|
if (!propValidator) {
|
|
4235
4290
|
return true;
|
|
4236
4291
|
}
|
|
4237
|
-
|
|
4292
|
+
const result = propValidator(value);
|
|
4293
|
+
// Log validation failures
|
|
4294
|
+
if (result !== true) {
|
|
4295
|
+
console.warn(getRegistryErrorMessage(RegistryErrorMessageKey.PROP_VALIDATION_FAILED, {
|
|
4296
|
+
component: componentName,
|
|
4297
|
+
prop: propName,
|
|
4298
|
+
validationError: String(result),
|
|
4299
|
+
}), {
|
|
4300
|
+
component: componentName,
|
|
4301
|
+
prop: propName,
|
|
4302
|
+
value: value,
|
|
4303
|
+
validationError: result,
|
|
4304
|
+
});
|
|
4305
|
+
}
|
|
4306
|
+
return result;
|
|
4238
4307
|
}
|
|
4239
4308
|
getComponentName(node) {
|
|
4240
4309
|
const { type } = node;
|
|
@@ -5504,12 +5573,34 @@ function retrievePropValue(args) {
|
|
|
5504
5573
|
// TODO: @ravencolevol: In case of the missing string value, we are providing a placeholder component, failing this check. We have to revisit the placeholder component logic.
|
|
5505
5574
|
//NOTE: This is the error message that is sent to the parent on the render is it a good idea to send the error message here?
|
|
5506
5575
|
//or it should happen in the data tab section. might require a revisit.
|
|
5507
|
-
if (!isDataMatchingPropType(resolvedData, type)
|
|
5508
|
-
|
|
5509
|
-
|
|
5510
|
-
|
|
5511
|
-
|
|
5576
|
+
if (!isDataMatchingPropType(resolvedData, type)) {
|
|
5577
|
+
const receivedType = getDataType(resolvedData);
|
|
5578
|
+
const errorMessage = getRegistryErrorMessage(RegistryErrorMessageKey.DATA_BINDING_TYPE_MISMATCH, {
|
|
5579
|
+
component: node.type,
|
|
5580
|
+
field,
|
|
5581
|
+
expectedType: type,
|
|
5582
|
+
receivedType,
|
|
5583
|
+
dataPath,
|
|
5512
5584
|
});
|
|
5585
|
+
if (isCompositionBeingEdited) {
|
|
5586
|
+
// In editor mode: Send to Visual Builder
|
|
5587
|
+
studioMessenger.composableStudioEventManager?.send(studioMessenger.POST_MESSAGE_EVENTS.UPDATE_BINDING_ERRORS, {
|
|
5588
|
+
propKey: `${node.uid}-${field}`,
|
|
5589
|
+
errorMessage: getRegistryErrorMessage(RegistryErrorMessageKey.DATA_BINDING_TYPE_MISMATCH_EDITOR, { expectedType: type, receivedType }),
|
|
5590
|
+
});
|
|
5591
|
+
}
|
|
5592
|
+
else {
|
|
5593
|
+
// In production mode: Console warning
|
|
5594
|
+
console.warn(errorMessage, {
|
|
5595
|
+
component: node.type,
|
|
5596
|
+
componentUid: node.uid,
|
|
5597
|
+
prop: field,
|
|
5598
|
+
expectedType: type,
|
|
5599
|
+
receivedType: getDataType(resolvedData),
|
|
5600
|
+
receivedValue: resolvedData,
|
|
5601
|
+
dataPath: dataPath,
|
|
5602
|
+
});
|
|
5603
|
+
}
|
|
5513
5604
|
}
|
|
5514
5605
|
mappedData[field] = resolvedData;
|
|
5515
5606
|
if (type === "json_rte") {
|