relation-definition.d.ts 4.7 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254
  1. import {RelationType} from './relation-type';
  2. /**
  3. * Relation definition.
  4. *
  5. * @example Available options.
  6. * ```ts
  7. * {
  8. * type: RelationType;
  9. * model?: string;
  10. * foreignKey?: string;
  11. * polymorphic?: boolean | string;
  12. * discriminator?: string;
  13. * }
  14. * ```
  15. */
  16. export declare type RelationDefinition =
  17. // belongsTo
  18. | BelongsToDefinition
  19. | PolyBelongsToDefinition
  20. // hasOne
  21. | HasOneDefinition
  22. | PolyHasOneDefinitionWithTargetRelationName
  23. | PolyHasOneDefinitionWithTargetKeys
  24. // hasMany
  25. | HasManyDefinition
  26. | PolyHasManyDefinitionWithTargetRelationName
  27. | PolyHasManyDefinitionWithTargetKeys
  28. // referencesMany
  29. | ReferencesManyDefinition;
  30. /**
  31. * The regular "belongsTo" relation.
  32. *
  33. * @example Required options only.
  34. * ```
  35. * {
  36. * type: RelationType.BELONGS_TO,
  37. * model: 'model',
  38. * }
  39. * ```
  40. *
  41. * @example Verbose definition.
  42. * ```
  43. * {
  44. * type: RelationType.BELONGS_TO,
  45. * model: 'model',
  46. * foreignKey: 'modelId',
  47. * }
  48. * ```
  49. */
  50. export declare type BelongsToDefinition = {
  51. type: RelationType.BELONGS_TO;
  52. polymorphic?: false;
  53. model: string;
  54. foreignKey?: string;
  55. };
  56. /**
  57. * The polymorphic "belongsTo" relation.
  58. *
  59. * @example Required fields only.
  60. * ```
  61. * {
  62. * type: RelationType.BELONGS_TO,
  63. * polymorphic: true,
  64. * }
  65. * ```
  66. *
  67. * @example Verbose definition.
  68. * ```
  69. * {
  70. * type: RelationType.BELONGS_TO,
  71. * polymorphic: true,
  72. * foreignKey: 'referenceId',
  73. * discriminator: 'referenceType,
  74. * }
  75. * ```
  76. */
  77. export declare type PolyBelongsToDefinition = {
  78. type: RelationType.BELONGS_TO;
  79. polymorphic: true;
  80. foreignKey?: string;
  81. discriminator?: string;
  82. };
  83. /**
  84. * The regular "hasOne" relation.
  85. *
  86. * @example
  87. * ```ts
  88. * {
  89. * type: RelationType.HAS_ONE,
  90. * model: 'model',
  91. * foreignKey: 'modelId',
  92. * }
  93. * ```
  94. */
  95. export declare type HasOneDefinition = {
  96. type: RelationType.HAS_ONE;
  97. model: string;
  98. polymorphic?: false;
  99. foreignKey?: string;
  100. discriminator?: undefined;
  101. };
  102. /**
  103. * The polymorphic "hasOne" relation with a target relation name.
  104. *
  105. * @example
  106. * ```ts
  107. * {
  108. * type: RelationType.HAS_ONE,
  109. * model: 'model',
  110. * polymorphic: 'reference',
  111. * }
  112. * ```
  113. */
  114. export declare type PolyHasOneDefinitionWithTargetRelationName = {
  115. type: RelationType.HAS_ONE;
  116. model: string;
  117. polymorphic: string;
  118. foreignKey?: undefined;
  119. discriminator?: undefined;
  120. };
  121. /**
  122. * The polymorphic "hasOne" relation with target relation keys.
  123. *
  124. * @example Required options only.
  125. * ```
  126. * {
  127. * type: RelationType.HAS_ONE,
  128. * model: 'model',
  129. * polymorphic: true,
  130. * }
  131. * ```
  132. *
  133. * @example Verbose definition.
  134. * ```
  135. * {
  136. * type: RelationType.HAS_ONE,
  137. * model: 'model',
  138. * polymorphic: true,
  139. * foreignKey: 'referenceId',
  140. * discriminator: 'referenceType,
  141. * }
  142. * ```
  143. */
  144. export declare type PolyHasOneDefinitionWithTargetKeys = {
  145. type: RelationType.HAS_ONE;
  146. model: string;
  147. polymorphic: true;
  148. foreignKey?: string;
  149. discriminator?: string;
  150. };
  151. /**
  152. * The regular "hasMany" relation.
  153. *
  154. * @example
  155. * ```ts
  156. * {
  157. * type: RelationType.HAS_MANY,
  158. * model: 'model',
  159. * foreignKey: 'modelId',
  160. * }
  161. * ```
  162. */
  163. export declare type HasManyDefinition = {
  164. type: RelationType.HAS_MANY;
  165. model: string;
  166. polymorphic?: false;
  167. foreignKey?: string;
  168. discriminator?: undefined;
  169. };
  170. /**
  171. * The polymorphic "hasMany" relation with a target relation name.
  172. *
  173. * @example
  174. * ```ts
  175. * {
  176. * type: RelationType.HAS_MANY,
  177. * model: 'model',
  178. * polymorphic: 'reference',
  179. * }
  180. * ```
  181. */
  182. export declare type PolyHasManyDefinitionWithTargetRelationName = {
  183. type: RelationType.HAS_MANY;
  184. model: string;
  185. polymorphic: string;
  186. foreignKey?: undefined;
  187. discriminator?: undefined;
  188. };
  189. /**
  190. * The polymorphic "hasMany" relation with target relation keys.
  191. *
  192. * @example Required options only.
  193. * ```
  194. * {
  195. * type: RelationType.HAS_MANY,
  196. * model: 'model',
  197. * polymorphic: true,
  198. * }
  199. * ```
  200. *
  201. * @example Verbose definition.
  202. * ```
  203. * {
  204. * type: RelationType.HAS_MANY,
  205. * model: 'model',
  206. * polymorphic: true,
  207. * foreignKey: 'referenceId',
  208. * discriminator: 'referenceType,
  209. * }
  210. * ```
  211. */
  212. export declare type PolyHasManyDefinitionWithTargetKeys = {
  213. type: RelationType.HAS_MANY;
  214. model: string;
  215. polymorphic: true;
  216. foreignKey?: string;
  217. discriminator?: string;
  218. };
  219. /**
  220. * The regular "referencesMany" relation.
  221. *
  222. * @example Required options only.
  223. * ```
  224. * {
  225. * type: RelationType.REFERENCES_MANY,
  226. * model: 'model',
  227. * }
  228. * ```
  229. *
  230. * @example Verbose definition.
  231. * ```
  232. * {
  233. * type: RelationType.REFERENCES_MANY,
  234. * model: 'model',
  235. * foreignKey: 'modelIds',
  236. * }
  237. * ```
  238. */
  239. export declare type ReferencesManyDefinition = {
  240. type: RelationType.REFERENCES_MANY;
  241. model: string;
  242. foreignKey?: string;
  243. discriminator?: undefined;
  244. };