@contentstack/studio-registry 1.2.0 → 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 +118 -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 +50 -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 +7 -7
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;
|
|
@@ -5459,6 +5528,27 @@ function retrievePropValue(args) {
|
|
|
5459
5528
|
}
|
|
5460
5529
|
else if (dataPath) {
|
|
5461
5530
|
resolvedData = get(data, dataPath, fallbackValue);
|
|
5531
|
+
// Handle primitive values in repeater context
|
|
5532
|
+
// When the array contains primitives (strings, numbers, etc.) instead of objects,
|
|
5533
|
+
// the binding path will be like: dataSources.repeater.{uid}.context.{fieldName}
|
|
5534
|
+
// But context IS the primitive value, so accessing context.fieldName returns undefined.
|
|
5535
|
+
// In this case, we should return the context itself.
|
|
5536
|
+
if (dataPath.includes("dataSources.repeater")) {
|
|
5537
|
+
const pathParts = dataPath.split(".");
|
|
5538
|
+
// Check if path is: dataSources.repeater.{uid}.context.{fieldName}
|
|
5539
|
+
if (pathParts.length >= 5 && pathParts[3] === "context") {
|
|
5540
|
+
// Try to get just the context (without the field name)
|
|
5541
|
+
const contextPath = pathParts.slice(0, 4).join("."); // dataSources.repeater.{uid}.context
|
|
5542
|
+
const contextValue = get(data, contextPath);
|
|
5543
|
+
// If context exists and is a primitive (not an object/array), return it
|
|
5544
|
+
if (contextValue !== undefined && contextValue !== null) {
|
|
5545
|
+
const isPrimitive = typeof contextValue !== "object" || contextValue === null;
|
|
5546
|
+
if (isPrimitive) {
|
|
5547
|
+
resolvedData = contextValue;
|
|
5548
|
+
}
|
|
5549
|
+
}
|
|
5550
|
+
}
|
|
5551
|
+
}
|
|
5462
5552
|
if (type === "choice") {
|
|
5463
5553
|
if (!prop.multiSelect) {
|
|
5464
5554
|
// we are explicitly checking for single select choice type to ensure we don't have a mismatch in the data type.
|
|
@@ -5483,12 +5573,34 @@ function retrievePropValue(args) {
|
|
|
5483
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.
|
|
5484
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?
|
|
5485
5575
|
//or it should happen in the data tab section. might require a revisit.
|
|
5486
|
-
if (!isDataMatchingPropType(resolvedData, type)
|
|
5487
|
-
|
|
5488
|
-
|
|
5489
|
-
|
|
5490
|
-
|
|
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,
|
|
5491
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
|
+
}
|
|
5492
5604
|
}
|
|
5493
5605
|
mappedData[field] = resolvedData;
|
|
5494
5606
|
if (type === "json_rte") {
|