Skip to content
Snippets Groups Projects
Schema.ts 848 B
Newer Older
Frank Bessou's avatar
Frank Bessou committed
export const yams = {
  String: () => ({ type: "String" }),
  Date: () => ({ type: "Date" }),
  Float: () => ({ type: "Float" }),
  Int: () => ({ type: "Int" }),
} as const;

export type BuildObj = ReturnType<typeof yams[keyof typeof yams]>;

export type Cardinality = "*" | "1" | "?" | "+";

export type CardinalityPair = `${Cardinality}${Cardinality}`;

export type Relationships<E> = Record<
  string,
  {
    cardinality: CardinalityPair;
    subject: Array<keyof E>;
    object: Array<keyof E>;
Frank Bessou's avatar
Frank Bessou committed
  }
>;

export type ETypes = {
  [etypeName: string]: {
    [attributeName: string]: BuildObj;
  };
};

// eslint-disable-next-line @typescript-eslint/no-explicit-any
export type Schema<E extends ETypes = any, R extends Relationships<E> = any> = {
  etypes: E;
  relationships: R;
};

export type ETypesNames<S extends Schema> = keyof S["etypes"];