@compas/code-gen
Version:
Generate various boring parts of your server
37 lines (29 loc) • 606 B
JavaScript
import { buildOrInfer } from "./utils.js";
export class RelationType {
constructor(subType, ownKey, reference, referencedKey) {
this.data = {
type: "relation",
subType,
ownKey,
referencedKey,
isOptional: false,
};
this.reference = reference;
}
/**
* @returns {RelationType}
*/
optional() {
this.data.isOptional = true;
return this;
}
/**
* @returns {Record<string, any>}
*/
build() {
const result = { ...this.data };
// @ts-expect-error
result.reference = buildOrInfer(this.reference);
return result;
}
}