@openzeppelin/ui-builder-adapter-stellar 0.10.0 → 0.10.1
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/index.cjs +36 -2
- package/dist/index.cjs.map +1 -1
- package/dist/index.js +36 -2
- package/dist/index.js.map +1 -1
- package/package.json +4 -4
- package/src/mapping/field-generator.ts +14 -1
- package/src/mapping/type-mapper.ts +7 -3
- package/src/transform/parsers/scval-converter.ts +22 -0
- package/src/utils/formatting.ts +3 -0
- package/src/utils/type-detection.ts +4 -0
package/dist/index.cjs
CHANGED
|
@@ -313,6 +313,9 @@ function isLikelyEnumType(parameterType) {
|
|
|
313
313
|
}
|
|
314
314
|
return enumPatterns.some((pattern) => pattern.test(parameterType));
|
|
315
315
|
}
|
|
316
|
+
function isBytesNType(parameterType) {
|
|
317
|
+
return /^BytesN<\d+>$/.test(parameterType);
|
|
318
|
+
}
|
|
316
319
|
|
|
317
320
|
// src/mapping/struct-fields.ts
|
|
318
321
|
function extractStructFields(entries, structName) {
|
|
@@ -759,6 +762,9 @@ function convertStellarTypeToScValType(stellarType) {
|
|
|
759
762
|
case "DataUrl":
|
|
760
763
|
return "bytes";
|
|
761
764
|
default:
|
|
765
|
+
if (/^BytesN<\d+>$/.test(stellarType)) {
|
|
766
|
+
return "bytes";
|
|
767
|
+
}
|
|
762
768
|
return stellarType.toLowerCase();
|
|
763
769
|
}
|
|
764
770
|
}
|
|
@@ -1007,6 +1013,21 @@ function valueToScVal(value, parameterType, paramSchema, parseInnerValue) {
|
|
|
1007
1013
|
if (parameterType === "Bool" || parameterType === "Bytes") {
|
|
1008
1014
|
return (0, import_stellar_sdk7.nativeToScVal)(value);
|
|
1009
1015
|
}
|
|
1016
|
+
if (isBytesNType(parameterType)) {
|
|
1017
|
+
const match = parameterType.match(/^BytesN<(\d+)>$/);
|
|
1018
|
+
if (!match) {
|
|
1019
|
+
throw new Error(`Invalid BytesN parameterType format: ${parameterType}`);
|
|
1020
|
+
}
|
|
1021
|
+
const expectedBytes = Number.parseInt(match[1], 10);
|
|
1022
|
+
const decoded = parsePrimitive(value, "Bytes");
|
|
1023
|
+
const bytesValue = decoded instanceof Uint8Array ? decoded : decoded ?? value;
|
|
1024
|
+
if (Number.isFinite(expectedBytes) && bytesValue instanceof Uint8Array && bytesValue.length !== expectedBytes) {
|
|
1025
|
+
throw new Error(
|
|
1026
|
+
`BytesN value must be exactly ${expectedBytes} bytes, received ${bytesValue.length}`
|
|
1027
|
+
);
|
|
1028
|
+
}
|
|
1029
|
+
return (0, import_stellar_sdk7.nativeToScVal)(bytesValue);
|
|
1030
|
+
}
|
|
1010
1031
|
const scValType = convertStellarTypeToScValType(parameterType);
|
|
1011
1032
|
const typeHint = Array.isArray(scValType) ? scValType[0] : scValType;
|
|
1012
1033
|
return (0, import_stellar_sdk7.nativeToScVal)(value, { type: typeHint });
|
|
@@ -3292,8 +3313,8 @@ function mapStellarParameterTypeToFieldType(parameterType) {
|
|
|
3292
3313
|
if (mappedType) {
|
|
3293
3314
|
return mappedType;
|
|
3294
3315
|
}
|
|
3295
|
-
if (parameterType
|
|
3296
|
-
return "
|
|
3316
|
+
if (isBytesNType(parameterType)) {
|
|
3317
|
+
return "bytes";
|
|
3297
3318
|
}
|
|
3298
3319
|
if (isLikelyEnumType(parameterType)) {
|
|
3299
3320
|
return "select";
|
|
@@ -3326,6 +3347,9 @@ function getStellarCompatibleFieldTypes(parameterType) {
|
|
|
3326
3347
|
}
|
|
3327
3348
|
return ["array", "textarea", "text"];
|
|
3328
3349
|
}
|
|
3350
|
+
if (isBytesNType(parameterType)) {
|
|
3351
|
+
return ["bytes", "textarea", "text"];
|
|
3352
|
+
}
|
|
3329
3353
|
if (parameterType === "Vec" || parameterType.startsWith("Vec<")) {
|
|
3330
3354
|
return ["array", "textarea", "text"];
|
|
3331
3355
|
}
|
|
@@ -3542,6 +3566,16 @@ function generateStellarDefaultField(parameter, contractSchema) {
|
|
|
3542
3566
|
width: "full",
|
|
3543
3567
|
options
|
|
3544
3568
|
};
|
|
3569
|
+
if (isBytesNType(parameter.type)) {
|
|
3570
|
+
const sizeMatch = parameter.type.match(/^BytesN<(\d+)>$/);
|
|
3571
|
+
const maxBytes = sizeMatch ? Number.parseInt(sizeMatch[1], 10) : void 0;
|
|
3572
|
+
if (!Number.isNaN(maxBytes) && Number.isFinite(maxBytes)) {
|
|
3573
|
+
baseField.metadata = {
|
|
3574
|
+
...baseField.metadata ?? {},
|
|
3575
|
+
maxBytes
|
|
3576
|
+
};
|
|
3577
|
+
}
|
|
3578
|
+
}
|
|
3545
3579
|
if (fieldType === "array") {
|
|
3546
3580
|
const elementType = extractVecElementType(parameter.type);
|
|
3547
3581
|
if (elementType) {
|