@palmares/drizzle-engine
Version:
This is the engine that wraps the hole drizzle interface in a way palmares can understand and have full control of
29 lines (27 loc) • 1.27 kB
JavaScript
var __defProp = Object.defineProperty;
var __name = (target, value) => __defProp(target, "name", { value, configurable: true });
// src/fields/utils.ts
function getBuilderArgs(builder, callback) {
const defaultOptions = callback([]);
return (customAttributesArgs, customAttributesOptions) => {
const customAttributesDefined = new Set(Object.keys(customAttributesOptions || {}));
const builderArgs = Object.entries(customAttributesOptions || {}).map(([method, args]) => {
return [
method,
args.map((arg) => typeof arg === "object" ? JSON.stringify(arg) : arg.toString()).join(", ")
];
});
for (const [method, args] of defaultOptions) if (!customAttributesDefined.has(method)) builderArgs.push([
method,
args
]);
const builderArguments = builderArgs.map(([method, args]) => {
return (args || []).length > 0 ? `.${method}(${args})` : `.${method}()`;
}).join("");
return `${builder.withoutD ? "" : "d."}${builder.type}('${builder.databaseName}'${customAttributesArgs !== void 0 || builder.args ? `, ${customAttributesArgs !== void 0 ? JSON.stringify(customAttributesArgs) : builder.args}` : ""})${builderArguments}`;
};
}
__name(getBuilderArgs, "getBuilderArgs");
export {
getBuilderArgs
};