appwrite-utils
Version:
19 lines (18 loc) • 802 B
JavaScript
import { attributeSchema } from "../schemas/attribute.js";
export const parseAttribute = (attribute) => {
const attributeToParse = { ...attribute };
// Normalize default into xdefault for compatibility with Appwrite SDK
if ("default" in attributeToParse) {
if (attributeToParse.default !== null && attributeToParse.default !== undefined) {
attributeToParse.xdefault = attributeToParse.default;
}
delete attributeToParse.default;
}
if (attributeToParse.type === "string" &&
typeof attributeToParse.format === "string" &&
attributeToParse.format.length > 0) {
attributeToParse.type = attributeToParse.format.toLowerCase();
delete attributeToParse.format;
}
return attributeSchema.parse(attributeToParse);
};