Monorepo containing core modules of Zeichen.
You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.

61 lines
1.2 KiB

  1. import {
  2. DataType,
  3. INTEGER,
  4. STRING,
  5. TEXT,
  6. DATE,
  7. DATEONLY,
  8. UUIDV4,
  9. } from 'sequelize'
  10. type ModelAttribute = {
  11. allowNull?: boolean,
  12. primaryKey?: boolean,
  13. type: DataType,
  14. }
  15. export type Model = {
  16. tableName?: string,
  17. modelName?: string,
  18. options?: {
  19. timestamps?: boolean,
  20. paranoid?: boolean,
  21. createdAt?: string | boolean,
  22. updatedAt?: string | boolean,
  23. deletedAt?: string | boolean,
  24. },
  25. attributes: Record<string, ModelAttribute>,
  26. }
  27. type IntegerType = typeof INTEGER | ReturnType<typeof INTEGER>
  28. type NumberType = IntegerType
  29. type VarcharType = typeof STRING
  30. type TextType = typeof TEXT | ReturnType<typeof TEXT>
  31. type StringType = VarcharType | TextType
  32. type DateTimeType = typeof DATE
  33. type DateOnlyType = typeof DATEONLY
  34. type DateType = DateTimeType | DateOnlyType
  35. type InferType<V extends DataType> = (
  36. V extends NumberType ? number :
  37. V extends StringType ? string :
  38. V extends DateType ? Date :
  39. V extends typeof UUIDV4 ? string :
  40. unknown
  41. )
  42. export type InferModel<M extends Model> = {
  43. [K in keyof M['attributes']]-?: InferType<M['attributes'][K]['type']>
  44. }
  45. export {
  46. INTEGER,
  47. STRING,
  48. TEXT,
  49. DATEONLY,
  50. DATE,
  51. UUIDV4,
  52. }