TenantAtlas/apps/platform/.pnpm-store/v10/files/95/39fb8dbe6d9021cc1f13d6ac0e3174af88caa8e94bdca8587da0f3bc5749ca4db8400797aabf610f35f08002a85236bdbffc9b3bef9175108ccc7c60732cca
Ahmed Darrazi 9f74f7a658
Some checks failed
PR Fast Feedback / fast-feedback (pull_request) Failing after 51s
feat: compress governance operator outcomes
2026-04-19 14:15:11 +02:00

74 lines
1.9 KiB
Plaintext

import { entityKind } from "../entity.js";
import { TableName } from "../table.utils.js";
class ForeignKeyBuilder {
static [entityKind] = "GelForeignKeyBuilder";
/** @internal */
reference;
/** @internal */
_onUpdate = "no action";
/** @internal */
_onDelete = "no action";
constructor(config, actions) {
this.reference = () => {
const { name, columns, foreignColumns } = config();
return { name, columns, foreignTable: foreignColumns[0].table, foreignColumns };
};
if (actions) {
this._onUpdate = actions.onUpdate;
this._onDelete = actions.onDelete;
}
}
onUpdate(action) {
this._onUpdate = action === void 0 ? "no action" : action;
return this;
}
onDelete(action) {
this._onDelete = action === void 0 ? "no action" : action;
return this;
}
/** @internal */
build(table) {
return new ForeignKey(table, this);
}
}
class ForeignKey {
constructor(table, builder) {
this.table = table;
this.reference = builder.reference;
this.onUpdate = builder._onUpdate;
this.onDelete = builder._onDelete;
}
static [entityKind] = "GelForeignKey";
reference;
onUpdate;
onDelete;
getName() {
const { name, columns, foreignColumns } = this.reference();
const columnNames = columns.map((column) => column.name);
const foreignColumnNames = foreignColumns.map((column) => column.name);
const chunks = [
this.table[TableName],
...columnNames,
foreignColumns[0].table[TableName],
...foreignColumnNames
];
return name ?? `${chunks.join("_")}_fk`;
}
}
function foreignKey(config) {
function mappedConfig() {
const { name, columns, foreignColumns } = config;
return {
name,
columns,
foreignColumns
};
}
return new ForeignKeyBuilder(mappedConfig);
}
export {
ForeignKey,
ForeignKeyBuilder,
foreignKey
};
//# sourceMappingURL=foreign-keys.js.map