@goatlab/fluent 0.7.39 → 0.7.41

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
Files changed (276) hide show
  1. package/dist/BaseConnector.d.ts +112 -0
  2. package/dist/BaseConnector.js +347 -0
  3. package/dist/BaseConnector.js.map +1 -0
  4. package/dist/Fluent.d.ts +11 -0
  5. package/dist/Fluent.js +27 -0
  6. package/dist/Fluent.js.map +1 -0
  7. package/dist/FluentConnectorInterface.d.ts +17 -0
  8. package/dist/FluentConnectorInterface.js +3 -0
  9. package/dist/FluentConnectorInterface.js.map +1 -0
  10. package/dist/FluentEntity.d.ts +7 -0
  11. package/dist/FluentEntity.js +34 -0
  12. package/dist/FluentEntity.js.map +1 -0
  13. package/dist/TypeOrmConnector/TypeOrmConnector.d.ts +123 -0
  14. package/dist/TypeOrmConnector/TypeOrmConnector.js +765 -0
  15. package/dist/TypeOrmConnector/TypeOrmConnector.js.map +1 -0
  16. package/dist/TypeOrmConnector/queryBuilder/mongodb/getMongoBaseAggregations.d.ts +12 -0
  17. package/dist/TypeOrmConnector/queryBuilder/mongodb/getMongoBaseAggregations.js +167 -0
  18. package/dist/TypeOrmConnector/queryBuilder/mongodb/getMongoBaseAggregations.js.map +1 -0
  19. package/dist/TypeOrmConnector/queryBuilder/mongodb/getMongoFindAggregatedQuery.d.ts +11 -0
  20. package/dist/TypeOrmConnector/queryBuilder/mongodb/getMongoFindAggregatedQuery.js +52 -0
  21. package/dist/TypeOrmConnector/queryBuilder/mongodb/getMongoFindAggregatedQuery.js.map +1 -0
  22. package/dist/TypeOrmConnector/queryBuilder/mongodb/getMongoOrderBy.d.ts +4 -0
  23. package/dist/TypeOrmConnector/queryBuilder/mongodb/getMongoOrderBy.js +20 -0
  24. package/dist/TypeOrmConnector/queryBuilder/mongodb/getMongoOrderBy.js.map +1 -0
  25. package/dist/TypeOrmConnector/queryBuilder/mongodb/getMongoSelect.d.ts +7 -0
  26. package/dist/TypeOrmConnector/queryBuilder/mongodb/getMongoSelect.js +19 -0
  27. package/dist/TypeOrmConnector/queryBuilder/mongodb/getMongoSelect.js.map +1 -0
  28. package/dist/TypeOrmConnector/queryBuilder/mongodb/getMongoWhere.d.ts +11 -0
  29. package/dist/TypeOrmConnector/queryBuilder/mongodb/getMongoWhere.js +173 -0
  30. package/dist/TypeOrmConnector/queryBuilder/mongodb/getMongoWhere.js.map +1 -0
  31. package/dist/TypeOrmConnector/queryBuilder/sql/getQueryBuilderWhere.d.ts +13 -0
  32. package/dist/TypeOrmConnector/queryBuilder/sql/getQueryBuilderWhere.js +207 -0
  33. package/dist/TypeOrmConnector/queryBuilder/sql/getQueryBuilderWhere.js.map +1 -0
  34. package/dist/TypeOrmConnector/queryBuilder/sql/getTypeOrmWhere.d.ts +11 -0
  35. package/dist/TypeOrmConnector/queryBuilder/sql/getTypeOrmWhere.js +214 -0
  36. package/dist/TypeOrmConnector/queryBuilder/sql/getTypeOrmWhere.js.map +1 -0
  37. package/dist/TypeOrmConnector/test/advanced/typeOrm.entity.d.ts +44 -0
  38. package/dist/TypeOrmConnector/test/advanced/typeOrm.entity.js +87 -0
  39. package/dist/TypeOrmConnector/test/advanced/typeOrm.entity.js.map +1 -0
  40. package/dist/TypeOrmConnector/test/basic/goat.entity.d.ts +38 -0
  41. package/dist/TypeOrmConnector/test/basic/goat.entity.js +82 -0
  42. package/dist/TypeOrmConnector/test/basic/goat.entity.js.map +1 -0
  43. package/dist/TypeOrmConnector/test/flock.d.ts +4 -0
  44. package/dist/TypeOrmConnector/test/flock.js +26 -0
  45. package/dist/TypeOrmConnector/test/flock.js.map +1 -0
  46. package/dist/TypeOrmConnector/util/clearEmpties.d.ts +7 -0
  47. package/dist/TypeOrmConnector/util/clearEmpties.js +33 -0
  48. package/dist/TypeOrmConnector/util/clearEmpties.js.map +1 -0
  49. package/dist/TypeOrmConnector/util/extractConditions.d.ts +12 -0
  50. package/dist/TypeOrmConnector/util/extractConditions.js +89 -0
  51. package/dist/TypeOrmConnector/util/extractConditions.js.map +1 -0
  52. package/dist/TypeOrmConnector/util/extractInclude.d.ts +2 -0
  53. package/dist/TypeOrmConnector/util/extractInclude.js +26 -0
  54. package/dist/TypeOrmConnector/util/extractInclude.js.map +1 -0
  55. package/dist/TypeOrmConnector/util/extractMetadataFromKeys.d.ts +12 -0
  56. package/dist/TypeOrmConnector/util/extractMetadataFromKeys.js +49 -0
  57. package/dist/TypeOrmConnector/util/extractMetadataFromKeys.js.map +1 -0
  58. package/dist/TypeOrmConnector/util/extractOrderBy.d.ts +2 -0
  59. package/dist/TypeOrmConnector/util/extractOrderBy.js +24 -0
  60. package/dist/TypeOrmConnector/util/extractOrderBy.js.map +1 -0
  61. package/dist/TypeOrmConnector/util/getRelationsFromModelGenerator.d.ts +19 -0
  62. package/dist/TypeOrmConnector/util/getRelationsFromModelGenerator.js +27 -0
  63. package/dist/TypeOrmConnector/util/getRelationsFromModelGenerator.js.map +1 -0
  64. package/dist/TypeOrmConnector/util/getSelectedKeysFromRawSql.d.ts +6 -0
  65. package/dist/TypeOrmConnector/util/getSelectedKeysFromRawSql.js +29 -0
  66. package/dist/TypeOrmConnector/util/getSelectedKeysFromRawSql.js.map +1 -0
  67. package/dist/TypeOrmConnector/util/isAnyObject.d.ts +1 -0
  68. package/dist/TypeOrmConnector/util/isAnyObject.js +8 -0
  69. package/dist/TypeOrmConnector/util/isAnyObject.js.map +1 -0
  70. package/dist/TypeOrmConnector/util/nestQueryResults.d.ts +2 -0
  71. package/dist/TypeOrmConnector/util/nestQueryResults.js +38 -0
  72. package/dist/TypeOrmConnector/util/nestQueryResults.js.map +1 -0
  73. package/dist/core/Loopback/build-schema.d.ts +148 -0
  74. package/dist/core/Loopback/build-schema.js +443 -0
  75. package/dist/core/Loopback/build-schema.js.map +1 -0
  76. package/dist/core/Loopback/common-types.d.ts +96 -0
  77. package/dist/core/Loopback/common-types.js +24 -0
  78. package/dist/core/Loopback/common-types.js.map +1 -0
  79. package/dist/core/Loopback/json-to-schema.d.ts +41 -0
  80. package/dist/core/Loopback/json-to-schema.js +113 -0
  81. package/dist/core/Loopback/json-to-schema.js.map +1 -0
  82. package/dist/core/Loopback/mapValues.js +2280 -0
  83. package/dist/core/Loopback/metadata.d.ts +16 -0
  84. package/dist/core/Loopback/metadata.js +49 -0
  85. package/dist/core/Loopback/metadata.js.map +1 -0
  86. package/dist/core/Loopback/model.d.ts +233 -0
  87. package/dist/core/Loopback/model.js +394 -0
  88. package/dist/core/Loopback/model.js.map +1 -0
  89. package/dist/core/Loopback/query.d.ts +394 -0
  90. package/dist/core/Loopback/query.js +484 -0
  91. package/dist/core/Loopback/query.js.map +1 -0
  92. package/dist/core/Loopback/relation.types.d.ts +141 -0
  93. package/dist/core/Loopback/relation.types.js +18 -0
  94. package/dist/core/Loopback/relation.types.js.map +1 -0
  95. package/dist/core/Loopback/type-resolver.d.ts +42 -0
  96. package/dist/core/Loopback/type-resolver.js +60 -0
  97. package/dist/core/Loopback/type-resolver.js.map +1 -0
  98. package/dist/core/Loopback/type.d.ts +38 -0
  99. package/dist/core/Loopback/type.js +7 -0
  100. package/dist/core/Loopback/type.js.map +1 -0
  101. package/dist/core/Nestjs/applyDecorators.d.ts +10 -0
  102. package/dist/core/Nestjs/applyDecorators.js +26 -0
  103. package/dist/core/Nestjs/applyDecorators.js.map +1 -0
  104. package/dist/core/Nestjs/types/common.d.ts +16 -0
  105. package/dist/core/Nestjs/types/common.js +38 -0
  106. package/dist/core/Nestjs/types/common.js.map +1 -0
  107. package/dist/core/Nestjs/types/decorators/api-hide-property.decorator.d.ts +1 -0
  108. package/dist/core/Nestjs/types/decorators/api-hide-property.decorator.js +8 -0
  109. package/dist/core/Nestjs/types/decorators/api-hide-property.decorator.js.map +1 -0
  110. package/dist/core/Nestjs/types/decorators/api-property.decorator.d.ts +27 -0
  111. package/dist/core/Nestjs/types/decorators/api-property.decorator.js +66 -0
  112. package/dist/core/Nestjs/types/decorators/api-property.decorator.js.map +1 -0
  113. package/dist/core/Nestjs/types/decorators/apply-is-optional.decorator.d.ts +5 -0
  114. package/dist/core/Nestjs/types/decorators/apply-is-optional.decorator.js +136 -0
  115. package/dist/core/Nestjs/types/decorators/apply-is-optional.decorator.js.map +1 -0
  116. package/dist/core/Nestjs/types/decorators/args-type.decorator.d.ts +4 -0
  117. package/dist/core/Nestjs/types/decorators/args-type.decorator.js +24 -0
  118. package/dist/core/Nestjs/types/decorators/args-type.decorator.js.map +1 -0
  119. package/dist/core/Nestjs/types/decorators/create-property.decorator.d.ts +2 -0
  120. package/dist/core/Nestjs/types/decorators/create-property.decorator.js +55 -0
  121. package/dist/core/Nestjs/types/decorators/create-property.decorator.js.map +1 -0
  122. package/dist/core/Nestjs/types/decorators/directive.decorator.d.ts +4 -0
  123. package/dist/core/Nestjs/types/decorators/directive.decorator.js +39 -0
  124. package/dist/core/Nestjs/types/decorators/directive.decorator.js.map +1 -0
  125. package/dist/core/Nestjs/types/decorators/extensions.decorator.d.ts +4 -0
  126. package/dist/core/Nestjs/types/decorators/extensions.decorator.js +28 -0
  127. package/dist/core/Nestjs/types/decorators/extensions.decorator.js.map +1 -0
  128. package/dist/core/Nestjs/types/decorators/field.decorator.d.ts +48 -0
  129. package/dist/core/Nestjs/types/decorators/field.decorator.js +63 -0
  130. package/dist/core/Nestjs/types/decorators/field.decorator.js.map +1 -0
  131. package/dist/core/Nestjs/types/decorators/input-type.decorator.d.ts +25 -0
  132. package/dist/core/Nestjs/types/decorators/input-type.decorator.js +29 -0
  133. package/dist/core/Nestjs/types/decorators/input-type.decorator.js.map +1 -0
  134. package/dist/core/Nestjs/types/decorators/interface-type.decorator.d.ts +33 -0
  135. package/dist/core/Nestjs/types/decorators/interface-type.decorator.js +35 -0
  136. package/dist/core/Nestjs/types/decorators/interface-type.decorator.js.map +1 -0
  137. package/dist/core/Nestjs/types/decorators/partial-type.helper.d.ts +3 -0
  138. package/dist/core/Nestjs/types/decorators/partial-type.helper.js +46 -0
  139. package/dist/core/Nestjs/types/decorators/partial-type.helper.js.map +1 -0
  140. package/dist/core/Nestjs/types/errors/cannot-determine-host-type.error.d.ts +3 -0
  141. package/dist/core/Nestjs/types/errors/cannot-determine-host-type.error.js +10 -0
  142. package/dist/core/Nestjs/types/errors/cannot-determine-host-type.error.js.map +1 -0
  143. package/dist/core/Nestjs/types/errors/directive-parsing.error.d.ts +3 -0
  144. package/dist/core/Nestjs/types/errors/directive-parsing.error.js +10 -0
  145. package/dist/core/Nestjs/types/errors/directive-parsing.error.js.map +1 -0
  146. package/dist/core/Nestjs/types/errors/unable-to-find-fields.error.d.ts +3 -0
  147. package/dist/core/Nestjs/types/errors/unable-to-find-fields.error.js +10 -0
  148. package/dist/core/Nestjs/types/errors/unable-to-find-fields.error.js.map +1 -0
  149. package/dist/core/Nestjs/types/errors/undefined-type.error.d.ts +3 -0
  150. package/dist/core/Nestjs/types/errors/undefined-type.error.js +11 -0
  151. package/dist/core/Nestjs/types/errors/undefined-type.error.js.map +1 -0
  152. package/dist/core/Nestjs/types/interfaces/add-class-type-metadata.util.d.ts +3 -0
  153. package/dist/core/Nestjs/types/interfaces/add-class-type-metadata.util.js +11 -0
  154. package/dist/core/Nestjs/types/interfaces/add-class-type-metadata.util.js.map +1 -0
  155. package/dist/core/Nestjs/types/interfaces/base-type-options.interface.d.ts +11 -0
  156. package/dist/core/Nestjs/types/interfaces/base-type-options.interface.js +3 -0
  157. package/dist/core/Nestjs/types/interfaces/base-type-options.interface.js.map +1 -0
  158. package/dist/core/Nestjs/types/interfaces/class-decorator-factory.interface.d.ts +5 -0
  159. package/dist/core/Nestjs/types/interfaces/class-decorator-factory.interface.js +3 -0
  160. package/dist/core/Nestjs/types/interfaces/class-decorator-factory.interface.js.map +1 -0
  161. package/dist/core/Nestjs/types/interfaces/complexity.interface.d.ts +11 -0
  162. package/dist/core/Nestjs/types/interfaces/complexity.interface.js +3 -0
  163. package/dist/core/Nestjs/types/interfaces/complexity.interface.js.map +1 -0
  164. package/dist/core/Nestjs/types/interfaces/field-middleware.interface.d.ts +15 -0
  165. package/dist/core/Nestjs/types/interfaces/field-middleware.interface.js +3 -0
  166. package/dist/core/Nestjs/types/interfaces/field-middleware.interface.js.map +1 -0
  167. package/dist/core/Nestjs/types/interfaces/open-api-spec.interface.d.ts +239 -0
  168. package/dist/core/Nestjs/types/interfaces/open-api-spec.interface.js +7 -0
  169. package/dist/core/Nestjs/types/interfaces/open-api-spec.interface.js.map +1 -0
  170. package/dist/core/Nestjs/types/interfaces/resolve-type-fn.interface.d.ts +2 -0
  171. package/dist/core/Nestjs/types/interfaces/resolve-type-fn.interface.js +3 -0
  172. package/dist/core/Nestjs/types/interfaces/resolve-type-fn.interface.js.map +1 -0
  173. package/dist/core/Nestjs/types/interfaces/return-type-func.interface.d.ts +5 -0
  174. package/dist/core/Nestjs/types/interfaces/return-type-func.interface.js +3 -0
  175. package/dist/core/Nestjs/types/interfaces/return-type-func.interface.js.map +1 -0
  176. package/dist/core/Nestjs/types/interfaces/schema-object-metadata.interface.d.ts +9 -0
  177. package/dist/core/Nestjs/types/interfaces/schema-object-metadata.interface.js +3 -0
  178. package/dist/core/Nestjs/types/interfaces/schema-object-metadata.interface.js.map +1 -0
  179. package/dist/core/Nestjs/types/interfaces/type-options.interface.d.ts +5 -0
  180. package/dist/core/Nestjs/types/interfaces/type-options.interface.js +3 -0
  181. package/dist/core/Nestjs/types/interfaces/type-options.interface.js.map +1 -0
  182. package/dist/core/Nestjs/types/lazy-metadata.storage.d.ts +15 -0
  183. package/dist/core/Nestjs/types/lazy-metadata.storage.js +66 -0
  184. package/dist/core/Nestjs/types/lazy-metadata.storage.js.map +1 -0
  185. package/dist/core/Nestjs/types/metadata/class.metadata.d.ts +11 -0
  186. package/dist/core/Nestjs/types/metadata/class.metadata.js +3 -0
  187. package/dist/core/Nestjs/types/metadata/class.metadata.js.map +1 -0
  188. package/dist/core/Nestjs/types/metadata/directive.metadata.d.ts +8 -0
  189. package/dist/core/Nestjs/types/metadata/directive.metadata.js +3 -0
  190. package/dist/core/Nestjs/types/metadata/directive.metadata.js.map +1 -0
  191. package/dist/core/Nestjs/types/metadata/enum.metadata.d.ts +11 -0
  192. package/dist/core/Nestjs/types/metadata/enum.metadata.js +3 -0
  193. package/dist/core/Nestjs/types/metadata/enum.metadata.js.map +1 -0
  194. package/dist/core/Nestjs/types/metadata/extensions.metadata.d.ts +8 -0
  195. package/dist/core/Nestjs/types/metadata/extensions.metadata.js +3 -0
  196. package/dist/core/Nestjs/types/metadata/extensions.metadata.js.map +1 -0
  197. package/dist/core/Nestjs/types/metadata/index.d.ts +8 -0
  198. package/dist/core/Nestjs/types/metadata/index.js +12 -0
  199. package/dist/core/Nestjs/types/metadata/index.js.map +1 -0
  200. package/dist/core/Nestjs/types/metadata/interface.metadata.d.ts +6 -0
  201. package/dist/core/Nestjs/types/metadata/interface.metadata.js +3 -0
  202. package/dist/core/Nestjs/types/metadata/interface.metadata.js.map +1 -0
  203. package/dist/core/Nestjs/types/metadata/object-type.metadata.d.ts +4 -0
  204. package/dist/core/Nestjs/types/metadata/object-type.metadata.js +3 -0
  205. package/dist/core/Nestjs/types/metadata/object-type.metadata.js.map +1 -0
  206. package/dist/core/Nestjs/types/metadata/param.metadata.d.ts +18 -0
  207. package/dist/core/Nestjs/types/metadata/param.metadata.js +3 -0
  208. package/dist/core/Nestjs/types/metadata/param.metadata.js.map +1 -0
  209. package/dist/core/Nestjs/types/metadata/property.metadata.d.ts +20 -0
  210. package/dist/core/Nestjs/types/metadata/property.metadata.js +3 -0
  211. package/dist/core/Nestjs/types/metadata/property.metadata.js.map +1 -0
  212. package/dist/core/Nestjs/types/metadata/resolver.metadata.d.ts +34 -0
  213. package/dist/core/Nestjs/types/metadata/resolver.metadata.js +3 -0
  214. package/dist/core/Nestjs/types/metadata/resolver.metadata.js.map +1 -0
  215. package/dist/core/Nestjs/types/metadata/union.metadata.d.ts +9 -0
  216. package/dist/core/Nestjs/types/metadata/union.metadata.js +3 -0
  217. package/dist/core/Nestjs/types/metadata/union.metadata.js.map +1 -0
  218. package/dist/core/Nestjs/types/object-type.decorator.d.ts +32 -0
  219. package/dist/core/Nestjs/types/object-type.decorator.js +33 -0
  220. package/dist/core/Nestjs/types/object-type.decorator.js.map +1 -0
  221. package/dist/core/Nestjs/types/omit-type.d.ts +2 -0
  222. package/dist/core/Nestjs/types/omit-type.js +34 -0
  223. package/dist/core/Nestjs/types/omit-type.js.map +1 -0
  224. package/dist/core/Nestjs/types/reflection.utils.d.ts +15 -0
  225. package/dist/core/Nestjs/types/reflection.utils.js +65 -0
  226. package/dist/core/Nestjs/types/reflection.utils.js.map +1 -0
  227. package/dist/core/Nestjs/types/set-metadata.decorator.d.ts +20 -0
  228. package/dist/core/Nestjs/types/set-metadata.decorator.js +33 -0
  229. package/dist/core/Nestjs/types/set-metadata.decorator.js.map +1 -0
  230. package/dist/core/Nestjs/types/type-metadata.storage.d.ts +73 -0
  231. package/dist/core/Nestjs/types/type-metadata.storage.js +349 -0
  232. package/dist/core/Nestjs/types/type-metadata.storage.js.map +1 -0
  233. package/dist/core/Nestjs/types/utils/enum.utils.d.ts +3 -0
  234. package/dist/core/Nestjs/types/utils/enum.utils.js +31 -0
  235. package/dist/core/Nestjs/types/utils/enum.utils.js.map +1 -0
  236. package/dist/core/Nestjs/types/utils/get-fields-and-decorator.util.d.ts +13 -0
  237. package/dist/core/Nestjs/types/utils/get-fields-and-decorator.util.js +72 -0
  238. package/dist/core/Nestjs/types/utils/get-fields-and-decorator.util.js.map +1 -0
  239. package/dist/core/Nestjs/types/utils/mapped-types.utils.d.ts +2 -0
  240. package/dist/core/Nestjs/types/utils/mapped-types.utils.js +38 -0
  241. package/dist/core/Nestjs/types/utils/mapped-types.utils.js.map +1 -0
  242. package/dist/core/Nestjs/types/utils/model-properties-accessor.d.ts +6 -0
  243. package/dist/core/Nestjs/types/utils/model-properties-accessor.js +37 -0
  244. package/dist/core/Nestjs/types/utils/model-properties-accessor.js.map +1 -0
  245. package/dist/core/Nestjs/types/utils/type-helpers.utils.d.ts +2 -0
  246. package/dist/core/Nestjs/types/utils/type-helpers.utils.js +16 -0
  247. package/dist/core/Nestjs/types/utils/type-helpers.utils.js.map +1 -0
  248. package/dist/core/types.d.ts +23 -0
  249. package/dist/core/types.js +31 -0
  250. package/dist/core/types.js.map +1 -0
  251. package/dist/decorators.d.ts +92 -0
  252. package/dist/decorators.js +163 -0
  253. package/dist/decorators.js.map +1 -0
  254. package/dist/generatorDatasource.d.ts +2 -0
  255. package/dist/generatorDatasource.js +13 -0
  256. package/dist/generatorDatasource.js.map +1 -0
  257. package/dist/index.d.ts +34 -0
  258. package/dist/index.js +59 -0
  259. package/dist/index.js.map +1 -0
  260. package/dist/loadRelations.d.ts +12 -0
  261. package/dist/loadRelations.js +139 -0
  262. package/dist/loadRelations.js.map +1 -0
  263. package/dist/outputKeys.d.ts +2 -0
  264. package/dist/outputKeys.js +18 -0
  265. package/dist/outputKeys.js.map +1 -0
  266. package/dist/testing/genericUnifiedTestSuite.d.ts +21 -0
  267. package/dist/testing/genericUnifiedTestSuite.js +256 -0
  268. package/dist/testing/genericUnifiedTestSuite.js.map +1 -0
  269. package/dist/testing/unifiedTestFactory.d.ts +38 -0
  270. package/dist/testing/unifiedTestFactory.js +297 -0
  271. package/dist/testing/unifiedTestFactory.js.map +1 -0
  272. package/dist/tsconfig.tsbuildinfo +1 -0
  273. package/dist/types.d.ts +104 -0
  274. package/dist/types.js +23 -0
  275. package/dist/types.js.map +1 -0
  276. package/package.json +48 -24
@@ -0,0 +1,16 @@
1
+ import { InspectionOptions, MetadataAccessor, MetadataMap } from '@loopback/metadata';
2
+ import { ModelDefinition, ModelDefinitionSyntax, PropertyDefinition } from './model';
3
+ export declare const MODEL_KEY: MetadataAccessor<Partial<ModelDefinitionSyntax>, ClassDecorator>;
4
+ export declare const MODEL_PROPERTIES_KEY: MetadataAccessor<PropertyDefinition, PropertyDecorator>;
5
+ export declare const MODEL_WITH_PROPERTIES_KEY: MetadataAccessor<ModelDefinition, ClassDecorator>;
6
+ export type PropertyMap = MetadataMap<Partial<PropertyDefinition>>;
7
+ export declare class ModelMetadataHelper {
8
+ /**
9
+ * A utility function to simplify retrieving metadata from a target model and
10
+ * its properties.
11
+ * @param target - The class from which to retrieve metadata.
12
+ * @param options - An options object for the MetadataInspector to customize
13
+ * the output of the metadata retrieval functions.
14
+ */
15
+ static getModelMetadata(target: Function, options?: InspectionOptions): ModelDefinition | {};
16
+ }
@@ -0,0 +1,49 @@
1
+ "use strict";
2
+ // Copyright IBM Corp. 2017,2020. All Rights Reserved.
3
+ // Node module: @loopback/repository
4
+ // This file is licensed under the MIT License.
5
+ // License text available at https://opensource.org/licenses/MIT
6
+ Object.defineProperty(exports, "__esModule", { value: true });
7
+ exports.ModelMetadataHelper = exports.MODEL_WITH_PROPERTIES_KEY = exports.MODEL_PROPERTIES_KEY = exports.MODEL_KEY = void 0;
8
+ const metadata_1 = require("@loopback/metadata");
9
+ const model_1 = require("./model");
10
+ const RELATIONS_KEY = 'loopback:relations';
11
+ exports.MODEL_KEY = metadata_1.MetadataAccessor.create('loopback:model');
12
+ exports.MODEL_PROPERTIES_KEY = metadata_1.MetadataAccessor.create('loopback:model-properties');
13
+ exports.MODEL_WITH_PROPERTIES_KEY = metadata_1.MetadataAccessor.create('loopback:model-and-properties');
14
+ class ModelMetadataHelper {
15
+ /**
16
+ * A utility function to simplify retrieving metadata from a target model and
17
+ * its properties.
18
+ * @param target - The class from which to retrieve metadata.
19
+ * @param options - An options object for the MetadataInspector to customize
20
+ * the output of the metadata retrieval functions.
21
+ */
22
+ static getModelMetadata(target, options) {
23
+ const classDef = metadata_1.MetadataInspector.getClassMetadata(exports.MODEL_WITH_PROPERTIES_KEY, target,
24
+ // https://github.com/loopbackio/loopback-next/issues/4721
25
+ // The `target` can be a subclass for a base model
26
+ { ...options, ownMetadataOnly: true });
27
+ // Return the cached value, if it exists.
28
+ // XXX(kjdelisle): If we're going to support dynamic updates, then this
29
+ // will be problematic in the future, since it will never update.
30
+ if (classDef) {
31
+ return classDef;
32
+ }
33
+ const modelMeta = metadata_1.MetadataInspector.getClassMetadata(exports.MODEL_KEY, target, options);
34
+ if (!modelMeta) {
35
+ return {};
36
+ }
37
+ // sets the metadata to a dedicated key if cached value does not exist
38
+ // set ModelDefinition properties if they don't already exist
39
+ const meta = new model_1.ModelDefinition({ ...modelMeta });
40
+ // set properties lost from creating instance of ModelDefinition
41
+ Object.assign(meta, modelMeta);
42
+ meta.properties = Object.assign(meta.properties, metadata_1.MetadataInspector.getAllPropertyMetadata(exports.MODEL_PROPERTIES_KEY, target.prototype, options));
43
+ meta.relations = Object.assign(meta.relations, metadata_1.MetadataInspector.getAllPropertyMetadata(RELATIONS_KEY, target.prototype, options));
44
+ metadata_1.MetadataInspector.defineMetadata(exports.MODEL_WITH_PROPERTIES_KEY.key, meta, target);
45
+ return meta;
46
+ }
47
+ }
48
+ exports.ModelMetadataHelper = ModelMetadataHelper;
49
+ //# sourceMappingURL=metadata.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"metadata.js","sourceRoot":"","sources":["../../../src/core/Loopback/metadata.ts"],"names":[],"mappings":";AAAA,sDAAsD;AACtD,oCAAoC;AACpC,+CAA+C;AAC/C,gEAAgE;;;AAEhE,iDAK2B;AAC3B,mCAKgB;AAEhB,MAAM,aAAa,GAAG,oBAAoB,CAAA;AAE7B,QAAA,SAAS,GAAG,2BAAgB,CAAC,MAAM,CAG9C,gBAAgB,CAAC,CAAA;AAEN,QAAA,oBAAoB,GAAG,2BAAgB,CAAC,MAAM,CAGzD,2BAA2B,CAAC,CAAA;AAEjB,QAAA,yBAAyB,GAAG,2BAAgB,CAAC,MAAM,CAG9D,+BAA+B,CAAC,CAAA;AAIlC,MAAa,mBAAmB;IAC9B;;;;;;OAMG;IACH,MAAM,CAAC,gBAAgB,CACrB,MAAgB,EAChB,OAA2B;QAE3B,MAAM,QAAQ,GAAG,4BAAiB,CAAC,gBAAgB,CACjD,iCAAyB,EACzB,MAAM;QACN,0DAA0D;QAC1D,kDAAkD;QAClD,EAAE,GAAG,OAAO,EAAE,eAAe,EAAE,IAAI,EAAE,CACtC,CAAA;QACD,yCAAyC;QACzC,uEAAuE;QACvE,iEAAiE;QACjE,IAAI,QAAQ,EAAE,CAAC;YACb,OAAO,QAAQ,CAAA;QACjB,CAAC;QACD,MAAM,SAAS,GAAG,4BAAiB,CAAC,gBAAgB,CAClD,iBAAS,EACT,MAAM,EACN,OAAO,CACR,CAAA;QACD,IAAI,CAAC,SAAS,EAAE,CAAC;YACf,OAAO,EAAE,CAAA;QACX,CAAC;QACD,sEAAsE;QAEtE,6DAA6D;QAC7D,MAAM,IAAI,GAAG,IAAI,uBAAe,CAAC,EAAE,GAAG,SAAS,EAAE,CAAC,CAAA;QAElD,gEAAgE;QAChE,MAAM,CAAC,MAAM,CAAC,IAAI,EAAE,SAAS,CAAC,CAAA;QAE9B,IAAI,CAAC,UAAU,GAAG,MAAM,CAAC,MAAM,CAChB,IAAI,CAAC,UAAU,EAC5B,4BAAiB,CAAC,sBAAsB,CACtC,4BAAoB,EACpB,MAAM,CAAC,SAAS,EAChB,OAAO,CACR,CACF,CAAA;QAED,IAAI,CAAC,SAAS,GAAG,MAAM,CAAC,MAAM,CACL,IAAI,CAAC,SAAS,EACrC,4BAAiB,CAAC,sBAAsB,CACtC,aAAa,EACb,MAAM,CAAC,SAAS,EAChB,OAAO,CACR,CACF,CAAA;QAED,4BAAiB,CAAC,cAAc,CAC9B,iCAAyB,CAAC,GAAG,EAC7B,IAAI,EACJ,MAAM,CACP,CAAA;QACD,OAAO,IAAI,CAAA;IACb,CAAC;CACF;AAlED,kDAkEC"}
@@ -0,0 +1,233 @@
1
+ import { SchemaObject as JsonSchema } from 'openapi3-ts/oas30';
2
+ import { AnyObject, DataObject, Options, PrototypeOf } from './common-types';
3
+ import { BelongsToDefinition, HasManyDefinition, HasOneDefinition, RelationMetadata } from './relation.types';
4
+ import { TypeResolver } from './type-resolver';
5
+ import { Type } from './type';
6
+ /**
7
+ * This module defines the key classes representing building blocks for Domain
8
+ * Driven Design.
9
+ * See https://en.wikipedia.org/wiki/Domain-driven_design#Building_blocks
10
+ */
11
+ export interface JsonSchemaWithExtensions extends JsonSchema {
12
+ [attributes: string]: any;
13
+ }
14
+ export type PropertyType = string | Function | object | Type<any> | TypeResolver<Model>;
15
+ /**
16
+ * Property definition for a model
17
+ */
18
+ export interface PropertyDefinition {
19
+ type: PropertyType;
20
+ id?: boolean | number;
21
+ /**
22
+ * Used to hide this property from the response body,
23
+ * adding this property to the hiddenProperties array
24
+ */
25
+ hidden?: boolean;
26
+ json?: PropertyForm;
27
+ jsonSchema?: JsonSchemaWithExtensions;
28
+ store?: PropertyForm;
29
+ itemType?: PropertyType;
30
+ [attribute: string]: any;
31
+ }
32
+ /**
33
+ * Defining the settings for a model
34
+ * See https://loopback.io/doc/en/lb4/Model.html#supported-entries-of-model-definition
35
+ */
36
+ export interface ModelSettings {
37
+ /**
38
+ * Description of the model
39
+ */
40
+ description?: string;
41
+ /**
42
+ * Prevent clients from setting the auto-generated ID value manually
43
+ */
44
+ forceId?: boolean;
45
+ /**
46
+ * Hides properties from response bodies
47
+ */
48
+ hiddenProperties?: string[];
49
+ /**
50
+ * Scope enables you to set a scope that will apply to every query made by the model's repository
51
+ */
52
+ scope?: object;
53
+ /**
54
+ * Specifies whether the model accepts only predefined properties or not
55
+ */
56
+ strict?: boolean | 'filter';
57
+ [name: string]: any;
58
+ }
59
+ /**
60
+ * See https://github.com/loopbackio/loopback-datasource-juggler/issues/432
61
+ */
62
+ export interface PropertyForm {
63
+ in?: boolean;
64
+ out?: boolean;
65
+ name?: string;
66
+ }
67
+ /**
68
+ * A key-value map describing model relations.
69
+ * A relation name is used as the key, a relation definition is the value.
70
+ */
71
+ export type RelationDefinitionMap = {
72
+ [relationName: string]: RelationMetadata;
73
+ };
74
+ /**
75
+ * DSL for building a model definition.
76
+ */
77
+ export interface ModelDefinitionSyntax {
78
+ name: string;
79
+ properties?: {
80
+ [name: string]: PropertyDefinition | PropertyType;
81
+ };
82
+ settings?: ModelSettings;
83
+ relations?: RelationDefinitionMap;
84
+ jsonSchema?: JsonSchemaWithExtensions;
85
+ [attribute: string]: any;
86
+ }
87
+ /**
88
+ * Definition for a model
89
+ */
90
+ export declare class ModelDefinition {
91
+ readonly name: string;
92
+ properties: {
93
+ [name: string]: PropertyDefinition;
94
+ };
95
+ settings: ModelSettings;
96
+ relations: RelationDefinitionMap;
97
+ [attribute: string]: any;
98
+ constructor(nameOrDef: string | ModelDefinitionSyntax);
99
+ /**
100
+ * Add a property
101
+ * @param name - Property definition or name (string)
102
+ * @param definitionOrType - Definition or property type
103
+ */
104
+ addProperty(name: string, definitionOrType: PropertyDefinition | PropertyType): this;
105
+ /**
106
+ * Add a setting
107
+ * @param name - Setting name
108
+ * @param value - Setting value
109
+ */
110
+ addSetting(name: string, value: any): this;
111
+ /**
112
+ * Define a new relation.
113
+ * @param definition - The definition of the new relation.
114
+ */
115
+ addRelation(definition: RelationMetadata): this;
116
+ /**
117
+ * Define a new belongsTo relation.
118
+ * @param name - The name of the belongsTo relation.
119
+ * @param definition - The definition of the belongsTo relation.
120
+ */
121
+ belongsTo(name: string, definition: Omit<BelongsToDefinition, 'name' | 'type' | 'targetsMany'>): this;
122
+ /**
123
+ * Define a new hasOne relation.
124
+ * @param name - The name of the hasOne relation.
125
+ * @param definition - The definition of the hasOne relation.
126
+ */
127
+ hasOne(name: string, definition: Omit<HasOneDefinition, 'name' | 'type' | 'targetsMany'>): this;
128
+ /**
129
+ * Define a new hasMany relation.
130
+ * @param name - The name of the hasMany relation.
131
+ * @param definition - The definition of the hasMany relation.
132
+ */
133
+ hasMany(name: string, definition: Omit<HasManyDefinition, 'name' | 'type' | 'targetsMany'>): this;
134
+ /**
135
+ * Get an array of names of ID properties, which are specified in
136
+ * the model settings or properties with `id` attribute.
137
+ *
138
+ * @example
139
+ * ```ts
140
+ * {
141
+ * settings: {
142
+ * id: ['id']
143
+ * }
144
+ * properties: {
145
+ * id: {
146
+ * type: 'string',
147
+ * id: true
148
+ * }
149
+ * }
150
+ * }
151
+ * ```
152
+ */
153
+ idProperties(): string[];
154
+ }
155
+ /**
156
+ * Base class for models
157
+ */
158
+ export declare class Model {
159
+ static get modelName(): string;
160
+ static definition: ModelDefinition;
161
+ /**
162
+ * Serialize into a plain JSON object
163
+ */
164
+ toJSON(): Object;
165
+ /**
166
+ * Convert to a plain object as DTO
167
+ *
168
+ * If `ignoreUnknownProperty` is set to false, convert all properties in the
169
+ * model instance, otherwise only convert the ones defined in the model
170
+ * definitions.
171
+ *
172
+ * See function `asObject` for each property's conversion rules.
173
+ */
174
+ toObject(options?: Options): Object;
175
+ constructor(data?: DataObject<Model>);
176
+ }
177
+ export interface Persistable {
178
+ }
179
+ /**
180
+ * Base class for value objects - An object that contains attributes but has no
181
+ * conceptual identity. They should be treated as immutable.
182
+ */
183
+ export declare abstract class ValueObject extends Model implements Persistable {
184
+ }
185
+ /**
186
+ * Base class for entities which have unique ids
187
+ */
188
+ export declare class Entity extends Model implements Persistable {
189
+ /**
190
+ * Get the names of identity properties (primary keys).
191
+ */
192
+ static getIdProperties(): string[];
193
+ /**
194
+ * Get the identity value for a given entity instance or entity data object.
195
+ *
196
+ * @param entityOrData - The data object for which to determine the identity
197
+ * value.
198
+ */
199
+ static getIdOf(entityOrData: AnyObject): any;
200
+ /**
201
+ * Get the identity value. If the identity is a composite key, returns
202
+ * an object.
203
+ */
204
+ getId(): any;
205
+ /**
206
+ * Get the identity as an object, such as `{id: 1}` or
207
+ * `{schoolId: 1, studentId: 2}`
208
+ */
209
+ getIdObject(): Object;
210
+ /**
211
+ * Build the where object for the given id
212
+ * @param id - The id value
213
+ */
214
+ static buildWhereForId(id: any): any;
215
+ }
216
+ /**
217
+ * Domain events
218
+ */
219
+ export declare class Event {
220
+ source: any;
221
+ type: string;
222
+ }
223
+ export type EntityData = DataObject<Entity>;
224
+ export type EntityResolver<T extends Entity> = TypeResolver<T, typeof Entity>;
225
+ /**
226
+ * Check model data for navigational properties linking to related models.
227
+ * Throw a descriptive error if any such property is found.
228
+ *
229
+ * @param modelClass Model constructor, e.g. `Product`.
230
+ * @param entityData Model instance or a plain-data object,
231
+ * e.g. `{name: 'pen'}`.
232
+ */
233
+ export declare function rejectNavigationalPropertiesInData<M extends typeof Entity>(modelClass: M, data: DataObject<PrototypeOf<M>>): void;
@@ -0,0 +1,394 @@
1
+ "use strict";
2
+ Object.defineProperty(exports, "__esModule", { value: true });
3
+ exports.Event = exports.Entity = exports.ValueObject = exports.Model = exports.ModelDefinition = void 0;
4
+ exports.rejectNavigationalPropertiesInData = rejectNavigationalPropertiesInData;
5
+ const relation_types_1 = require("./relation.types");
6
+ /**
7
+ * Definition for a model
8
+ */
9
+ class ModelDefinition {
10
+ name;
11
+ properties;
12
+ settings;
13
+ relations;
14
+ constructor(nameOrDef) {
15
+ if (typeof nameOrDef === 'string') {
16
+ nameOrDef = { name: nameOrDef };
17
+ }
18
+ const { name, properties, settings, relations } = nameOrDef;
19
+ this.name = name;
20
+ this.properties = {};
21
+ if (properties) {
22
+ for (const p in properties) {
23
+ const prop = properties[p];
24
+ if (prop !== undefined) {
25
+ this.addProperty(p, prop);
26
+ }
27
+ }
28
+ }
29
+ this.settings = settings ?? new Map();
30
+ this.relations = relations ?? {};
31
+ }
32
+ /**
33
+ * Add a property
34
+ * @param name - Property definition or name (string)
35
+ * @param definitionOrType - Definition or property type
36
+ */
37
+ addProperty(name, definitionOrType) {
38
+ const definition = definitionOrType.type
39
+ ? definitionOrType
40
+ : { type: definitionOrType };
41
+ if (definition.id === true &&
42
+ definition.generated === true &&
43
+ definition.type !== undefined &&
44
+ definition.useDefaultIdType === undefined) {
45
+ definition.useDefaultIdType = false;
46
+ }
47
+ this.properties[name] = definition;
48
+ return this;
49
+ }
50
+ /**
51
+ * Add a setting
52
+ * @param name - Setting name
53
+ * @param value - Setting value
54
+ */
55
+ addSetting(name, value) {
56
+ this.settings[name] = value;
57
+ return this;
58
+ }
59
+ /**
60
+ * Define a new relation.
61
+ * @param definition - The definition of the new relation.
62
+ */
63
+ addRelation(definition) {
64
+ this.relations[definition.name] = definition;
65
+ return this;
66
+ }
67
+ /**
68
+ * Define a new belongsTo relation.
69
+ * @param name - The name of the belongsTo relation.
70
+ * @param definition - The definition of the belongsTo relation.
71
+ */
72
+ belongsTo(name, definition) {
73
+ const meta = {
74
+ ...definition,
75
+ name,
76
+ type: relation_types_1.RelationType.belongsTo,
77
+ targetsMany: false
78
+ };
79
+ return this.addRelation(meta);
80
+ }
81
+ /**
82
+ * Define a new hasOne relation.
83
+ * @param name - The name of the hasOne relation.
84
+ * @param definition - The definition of the hasOne relation.
85
+ */
86
+ hasOne(name, definition) {
87
+ const meta = {
88
+ ...definition,
89
+ name,
90
+ type: relation_types_1.RelationType.hasOne,
91
+ targetsMany: false
92
+ };
93
+ return this.addRelation(meta);
94
+ }
95
+ /**
96
+ * Define a new hasMany relation.
97
+ * @param name - The name of the hasMany relation.
98
+ * @param definition - The definition of the hasMany relation.
99
+ */
100
+ hasMany(name, definition) {
101
+ const meta = {
102
+ ...definition,
103
+ name,
104
+ type: relation_types_1.RelationType.hasMany,
105
+ targetsMany: true
106
+ };
107
+ return this.addRelation(meta);
108
+ }
109
+ /**
110
+ * Get an array of names of ID properties, which are specified in
111
+ * the model settings or properties with `id` attribute.
112
+ *
113
+ * @example
114
+ * ```ts
115
+ * {
116
+ * settings: {
117
+ * id: ['id']
118
+ * }
119
+ * properties: {
120
+ * id: {
121
+ * type: 'string',
122
+ * id: true
123
+ * }
124
+ * }
125
+ * }
126
+ * ```
127
+ */
128
+ idProperties() {
129
+ if (typeof this.settings.id === 'string') {
130
+ return [this.settings.id];
131
+ }
132
+ if (Array.isArray(this.settings.id)) {
133
+ return this.settings.id;
134
+ }
135
+ const idProps = Object.keys(this.properties).filter(prop => this.properties[prop]?.id);
136
+ return idProps;
137
+ }
138
+ }
139
+ exports.ModelDefinition = ModelDefinition;
140
+ function asJSON(value) {
141
+ if (value == null)
142
+ return value;
143
+ if (typeof value.toJSON === 'function') {
144
+ return value.toJSON();
145
+ }
146
+ // Handle arrays
147
+ if (Array.isArray(value)) {
148
+ return value.map(item => asJSON(item));
149
+ }
150
+ return value;
151
+ }
152
+ /**
153
+ * Convert a value to a plain object as DTO.
154
+ *
155
+ * - The prototype of the value in primitive types are preserved,
156
+ * like `Date`, `ObjectId`.
157
+ * - If the value is an instance of custom model, call `toObject` to convert.
158
+ * - If the value is an array, convert each element recursively.
159
+ *
160
+ * @param value the value to convert
161
+ * @param options the options
162
+ */
163
+ function asObject(value, options) {
164
+ if (value == null)
165
+ return value;
166
+ if (typeof value.toObject === 'function') {
167
+ return value.toObject(options);
168
+ }
169
+ if (Array.isArray(value)) {
170
+ return value.map(item => asObject(item, options));
171
+ }
172
+ return value;
173
+ }
174
+ /**
175
+ * Base class for models
176
+ */
177
+ // tslint:disable-next-line: max-classes-per-file
178
+ class Model {
179
+ static get modelName() {
180
+ return this.definition?.name || this.name;
181
+ }
182
+ static definition;
183
+ /**
184
+ * Serialize into a plain JSON object
185
+ */
186
+ toJSON() {
187
+ const def = this.constructor.definition;
188
+ if (def == null || def.settings.strict === false) {
189
+ return this.toObject({ ignoreUnknownProperties: false });
190
+ }
191
+ const copyPropertyAsJson = (key) => {
192
+ const val = asJSON(this[key]);
193
+ if (val !== undefined) {
194
+ json[key] = val;
195
+ }
196
+ };
197
+ const json = {};
198
+ const hiddenProperties = def.settings.hiddenProperties || [];
199
+ for (const p in def.properties) {
200
+ if (p in this && !hiddenProperties.includes(p)) {
201
+ copyPropertyAsJson(p);
202
+ }
203
+ }
204
+ for (const r in def.relations) {
205
+ const rel = def.relations[r];
206
+ if (!rel)
207
+ continue;
208
+ const relName = rel.name;
209
+ if (relName in this) {
210
+ copyPropertyAsJson(relName);
211
+ }
212
+ }
213
+ return json;
214
+ }
215
+ /**
216
+ * Convert to a plain object as DTO
217
+ *
218
+ * If `ignoreUnknownProperty` is set to false, convert all properties in the
219
+ * model instance, otherwise only convert the ones defined in the model
220
+ * definitions.
221
+ *
222
+ * See function `asObject` for each property's conversion rules.
223
+ */
224
+ toObject(options) {
225
+ const def = this.constructor.definition;
226
+ const obj = {};
227
+ if (options?.ignoreUnknownProperties === false) {
228
+ const hiddenProperties = def?.settings.hiddenProperties || [];
229
+ for (const p in this) {
230
+ if (!hiddenProperties.includes(p)) {
231
+ const val = this[p];
232
+ obj[p] = asObject(val, options);
233
+ }
234
+ }
235
+ return obj;
236
+ }
237
+ if (def?.relations) {
238
+ // tslint:disable-next-line: forin
239
+ for (const r in def.relations) {
240
+ const rel = def.relations[r];
241
+ if (!rel)
242
+ continue;
243
+ const relName = rel.name;
244
+ if (relName in this) {
245
+ obj[relName] = asObject(this[relName], {
246
+ ...options,
247
+ ignoreUnknownProperties: false
248
+ });
249
+ }
250
+ }
251
+ }
252
+ const props = def.properties;
253
+ const keys = Object.keys(props);
254
+ // tslint:disable-next-line: forin
255
+ for (const i in keys) {
256
+ const propertyName = keys[i];
257
+ if (!propertyName)
258
+ continue;
259
+ const val = this[propertyName];
260
+ if (val === undefined)
261
+ continue;
262
+ obj[propertyName] = asObject(val, options);
263
+ }
264
+ return obj;
265
+ }
266
+ constructor(data) {
267
+ Object.assign(this, data);
268
+ }
269
+ }
270
+ exports.Model = Model;
271
+ /**
272
+ * Base class for value objects - An object that contains attributes but has no
273
+ * conceptual identity. They should be treated as immutable.
274
+ */
275
+ class ValueObject extends Model {
276
+ }
277
+ exports.ValueObject = ValueObject;
278
+ /**
279
+ * Base class for entities which have unique ids
280
+ */
281
+ class Entity extends Model {
282
+ /**
283
+ * Get the names of identity properties (primary keys).
284
+ */
285
+ static getIdProperties() {
286
+ return this.definition.idProperties();
287
+ }
288
+ /**
289
+ * Get the identity value for a given entity instance or entity data object.
290
+ *
291
+ * @param entityOrData - The data object for which to determine the identity
292
+ * value.
293
+ */
294
+ static getIdOf(entityOrData) {
295
+ if (typeof entityOrData.getId === 'function') {
296
+ return entityOrData.getId();
297
+ }
298
+ const idName = this.getIdProperties()[0];
299
+ if (!idName)
300
+ return undefined;
301
+ return entityOrData[idName];
302
+ }
303
+ /**
304
+ * Get the identity value. If the identity is a composite key, returns
305
+ * an object.
306
+ */
307
+ getId() {
308
+ const { definition } = this.constructor;
309
+ const idProps = definition.idProperties();
310
+ if (idProps.length === 1) {
311
+ const firstId = idProps[0];
312
+ if (!firstId)
313
+ return undefined;
314
+ return this[firstId];
315
+ }
316
+ if (!idProps.length) {
317
+ throw new Error(`Invalid Entity ${this.constructor.name}:` +
318
+ 'missing primary key (id) property');
319
+ }
320
+ return this.getIdObject();
321
+ }
322
+ /**
323
+ * Get the identity as an object, such as `{id: 1}` or
324
+ * `{schoolId: 1, studentId: 2}`
325
+ */
326
+ getIdObject() {
327
+ const { definition } = this.constructor;
328
+ const idProps = definition.idProperties();
329
+ const idObj = {};
330
+ for (const idProp of idProps) {
331
+ idObj[idProp] = this[idProp];
332
+ }
333
+ return idObj;
334
+ }
335
+ /**
336
+ * Build the where object for the given id
337
+ * @param id - The id value
338
+ */
339
+ static buildWhereForId(id) {
340
+ const where = {};
341
+ const idProps = this.definition.idProperties();
342
+ if (idProps.length === 1) {
343
+ const firstId = idProps[0];
344
+ if (firstId) {
345
+ where[firstId] = id;
346
+ }
347
+ }
348
+ else {
349
+ for (const idProp of idProps) {
350
+ where[idProp] = id[idProp];
351
+ }
352
+ }
353
+ return where;
354
+ }
355
+ }
356
+ exports.Entity = Entity;
357
+ /**
358
+ * Domain events
359
+ */
360
+ class Event {
361
+ source;
362
+ type;
363
+ }
364
+ exports.Event = Event;
365
+ /**
366
+ * Check model data for navigational properties linking to related models.
367
+ * Throw a descriptive error if any such property is found.
368
+ *
369
+ * @param modelClass Model constructor, e.g. `Product`.
370
+ * @param entityData Model instance or a plain-data object,
371
+ * e.g. `{name: 'pen'}`.
372
+ */
373
+ function rejectNavigationalPropertiesInData(modelClass, data) {
374
+ const def = modelClass.definition;
375
+ const props = def.properties;
376
+ for (const r in def.relations) {
377
+ const rel = def.relations[r];
378
+ if (!rel)
379
+ continue;
380
+ const relName = rel.name;
381
+ if (!(relName in data))
382
+ continue;
383
+ let msg = 'Navigational properties are not allowed in model data ' +
384
+ `(model "${modelClass.modelName}" property "${relName}"), ` +
385
+ 'please remove it.';
386
+ if (relName in props) {
387
+ msg +=
388
+ ' The error might be invoked by belongsTo relations, please make' +
389
+ ' sure the relation name is not the same as the property name.';
390
+ }
391
+ throw new Error(msg);
392
+ }
393
+ }
394
+ //# sourceMappingURL=model.js.map