@contember/engine-system-api 2.0.0-alpha.32 → 2.0.0-alpha.35

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 (266) hide show
  1. package/dist/development/src/SystemContainer.cjs.map +1 -1
  2. package/dist/development/src/SystemContainer.js.map +1 -1
  3. package/dist/development/src/migrations/2020-03-27-130000-project-migrations.cjs.map +1 -1
  4. package/dist/development/src/migrations/2020-03-27-130000-project-migrations.js.map +1 -1
  5. package/dist/development/src/migrations/2020-05-06-150000-composed-primary.cjs.map +1 -1
  6. package/dist/development/src/migrations/2020-05-06-150000-composed-primary.js.map +1 -1
  7. package/dist/development/src/migrations/2020-06-01-103000-event-trigger-perf.cjs.map +1 -1
  8. package/dist/development/src/migrations/2020-06-01-103000-event-trigger-perf.js.map +1 -1
  9. package/dist/development/src/migrations/2021-05-07-155800-event-log-rework.cjs.map +1 -1
  10. package/dist/development/src/migrations/2021-05-07-155800-event-log-rework.js.map +1 -1
  11. package/dist/development/src/migrations/2021-05-19-1232000-event-log-fix-constraint.cjs.map +1 -1
  12. package/dist/development/src/migrations/2021-05-19-1232000-event-log-fix-constraint.js.map +1 -1
  13. package/dist/development/src/migrations/2022-10-03-110000-table-on-delete.cjs.map +1 -1
  14. package/dist/development/src/migrations/2022-10-03-110000-table-on-delete.js.map +1 -1
  15. package/dist/development/src/migrations/2023-09-11-174000-fix-on-delete.cjs.map +1 -1
  16. package/dist/development/src/migrations/2023-09-11-174000-fix-on-delete.js.map +1 -1
  17. package/dist/development/src/migrations/2023-10-19-173000-fix-unique.cjs.map +1 -1
  18. package/dist/development/src/migrations/2023-10-19-173000-fix-unique.js.map +1 -1
  19. package/dist/development/src/migrations/2024-06-28-153001-schema-init.cjs.map +1 -1
  20. package/dist/development/src/migrations/2024-06-28-153001-schema-init.js.map +1 -1
  21. package/dist/development/src/migrations/runner.cjs.map +1 -1
  22. package/dist/development/src/migrations/runner.js.map +1 -1
  23. package/dist/development/src/migrations/snapshot-factory.cjs.map +1 -1
  24. package/dist/development/src/migrations/snapshot-factory.js.map +1 -1
  25. package/dist/development/src/migrations/snapshot.cjs.map +1 -1
  26. package/dist/development/src/migrations/snapshot.js.map +1 -1
  27. package/dist/development/src/model/ProjectInitializer.cjs.map +1 -1
  28. package/dist/development/src/model/ProjectInitializer.js.map +1 -1
  29. package/dist/development/src/model/ProjectTruncateExecutor.cjs.map +1 -1
  30. package/dist/development/src/model/ProjectTruncateExecutor.js.map +1 -1
  31. package/dist/development/src/model/authorization/AuthorizationActions.cjs.map +1 -1
  32. package/dist/development/src/model/authorization/AuthorizationActions.js.map +1 -1
  33. package/dist/development/src/model/authorization/Identity.cjs.map +1 -1
  34. package/dist/development/src/model/authorization/Identity.js.map +1 -1
  35. package/dist/development/src/model/authorization/PermissionsFactory.cjs.map +1 -1
  36. package/dist/development/src/model/authorization/PermissionsFactory.js.map +1 -1
  37. package/dist/development/src/model/authorization/StagePermissionsFactory.cjs.map +1 -1
  38. package/dist/development/src/model/authorization/StagePermissionsFactory.js.map +1 -1
  39. package/dist/development/src/model/authorization/StageScope.cjs.map +1 -1
  40. package/dist/development/src/model/authorization/StageScope.js.map +1 -1
  41. package/dist/development/src/model/authorization/SwitchEvaluatorNode.cjs.map +1 -1
  42. package/dist/development/src/model/authorization/SwitchEvaluatorNode.js.map +1 -1
  43. package/dist/development/src/model/commands/CommandBus.cjs.map +1 -1
  44. package/dist/development/src/model/commands/CommandBus.js.map +1 -1
  45. package/dist/development/src/model/commands/events/TruncateEventsCommand.cjs.map +1 -1
  46. package/dist/development/src/model/commands/events/TruncateEventsCommand.js.map +1 -1
  47. package/dist/development/src/model/commands/migrations/DeleteMigrationCommand.cjs.map +1 -1
  48. package/dist/development/src/model/commands/migrations/DeleteMigrationCommand.js.map +1 -1
  49. package/dist/development/src/model/commands/migrations/ModifyMigrationCommand.cjs.map +1 -1
  50. package/dist/development/src/model/commands/migrations/ModifyMigrationCommand.js.map +1 -1
  51. package/dist/development/src/model/commands/migrations/SaveMigrationCommand.cjs.map +1 -1
  52. package/dist/development/src/model/commands/migrations/SaveMigrationCommand.js.map +1 -1
  53. package/dist/development/src/model/commands/schema/SaveSchemaCommand.cjs.map +1 -1
  54. package/dist/development/src/model/commands/schema/SaveSchemaCommand.js.map +1 -1
  55. package/dist/development/src/model/commands/stages/CreateStageCommand.cjs.map +1 -1
  56. package/dist/development/src/model/commands/stages/CreateStageCommand.js.map +1 -1
  57. package/dist/development/src/model/database/DatabaseContext.cjs.map +1 -1
  58. package/dist/development/src/model/database/DatabaseContext.js.map +1 -1
  59. package/dist/development/src/model/dtos/ExecutedMigration.cjs.map +1 -1
  60. package/dist/development/src/model/dtos/ExecutedMigration.js.map +1 -1
  61. package/dist/development/src/model/events/EventResponseBuilder.cjs.map +1 -1
  62. package/dist/development/src/model/events/EventResponseBuilder.js.map +1 -1
  63. package/dist/development/src/model/events/EventResponseHelper.cjs.map +1 -1
  64. package/dist/development/src/model/events/EventResponseHelper.js.map +1 -1
  65. package/dist/development/src/model/events/identityUtils.cjs.map +1 -1
  66. package/dist/development/src/model/events/identityUtils.js.map +1 -1
  67. package/dist/development/src/model/events/types.cjs.map +1 -1
  68. package/dist/development/src/model/events/types.js.map +1 -1
  69. package/dist/development/src/model/helpers/modelHelpers.cjs.map +1 -1
  70. package/dist/development/src/model/helpers/modelHelpers.js.map +1 -1
  71. package/dist/development/src/model/metadata/SchemaDatabaseMetadataResolverStore.cjs.map +1 -1
  72. package/dist/development/src/model/metadata/SchemaDatabaseMetadataResolverStore.js.map +1 -1
  73. package/dist/development/src/model/migrations/ExecutedMigrationsResolver.cjs.map +1 -1
  74. package/dist/development/src/model/migrations/ExecutedMigrationsResolver.js.map +1 -1
  75. package/dist/development/src/model/migrations/MigrationAlterer.cjs.map +1 -1
  76. package/dist/development/src/model/migrations/MigrationAlterer.js.map +1 -1
  77. package/dist/development/src/model/migrations/ProjectMigrator.cjs.map +1 -1
  78. package/dist/development/src/model/migrations/ProjectMigrator.js.map +1 -1
  79. package/dist/development/src/model/migrations/SchemaProvider.cjs.map +1 -1
  80. package/dist/development/src/model/migrations/SchemaProvider.js.map +1 -1
  81. package/dist/development/src/model/queries/events/EventQueryHelpers.cjs.map +1 -1
  82. package/dist/development/src/model/queries/events/EventQueryHelpers.js.map +1 -1
  83. package/dist/development/src/model/queries/events/EventsQuery.cjs.map +1 -1
  84. package/dist/development/src/model/queries/events/EventsQuery.js.map +1 -1
  85. package/dist/development/src/model/queries/events/LatestTransactionIdByStageQuery.cjs.map +1 -1
  86. package/dist/development/src/model/queries/events/LatestTransactionIdByStageQuery.js.map +1 -1
  87. package/dist/development/src/model/queries/events/OldValuesQuery.cjs.map +1 -1
  88. package/dist/development/src/model/queries/events/OldValuesQuery.js.map +1 -1
  89. package/dist/development/src/model/queries/migrations/ExecutedMigrationByVersionQuery.cjs.map +1 -1
  90. package/dist/development/src/model/queries/migrations/ExecutedMigrationByVersionQuery.js.map +1 -1
  91. package/dist/development/src/model/queries/migrations/ExecutedMigrationsQuery.cjs.map +1 -1
  92. package/dist/development/src/model/queries/migrations/ExecutedMigrationsQuery.js.map +1 -1
  93. package/dist/development/src/model/queries/schema/SchemaQuery.cjs.map +1 -1
  94. package/dist/development/src/model/queries/schema/SchemaQuery.js.map +1 -1
  95. package/dist/development/src/model/queries/stages/StageBySlugQuery.cjs.map +1 -1
  96. package/dist/development/src/model/queries/stages/StageBySlugQuery.js.map +1 -1
  97. package/dist/development/src/model/queries/stages/StagesQuery.cjs.map +1 -1
  98. package/dist/development/src/model/queries/stages/StagesQuery.js.map +1 -1
  99. package/dist/development/src/model/stages/StageCreator.cjs.map +1 -1
  100. package/dist/development/src/model/stages/StageCreator.js.map +1 -1
  101. package/dist/development/src/resolvers/ResolverFactory.cjs.map +1 -1
  102. package/dist/development/src/resolvers/ResolverFactory.js.map +1 -1
  103. package/dist/development/src/resolvers/SystemResolverContext.cjs.map +1 -1
  104. package/dist/development/src/resolvers/SystemResolverContext.js.map +1 -1
  105. package/dist/development/src/resolvers/mutation/MigrateMutationResolver.cjs.map +1 -1
  106. package/dist/development/src/resolvers/mutation/MigrateMutationResolver.js.map +1 -1
  107. package/dist/development/src/resolvers/mutation/MigrationAlterMutationResolver.cjs.map +1 -1
  108. package/dist/development/src/resolvers/mutation/MigrationAlterMutationResolver.js.map +1 -1
  109. package/dist/development/src/resolvers/mutation/TruncateMutationResolver.cjs.map +1 -1
  110. package/dist/development/src/resolvers/mutation/TruncateMutationResolver.js.map +1 -1
  111. package/dist/development/src/resolvers/query/EventsQueryResolver.cjs.map +1 -1
  112. package/dist/development/src/resolvers/query/EventsQueryResolver.js.map +1 -1
  113. package/dist/development/src/resolvers/query/ExecutedMigrationsQueryResolver.cjs.map +1 -1
  114. package/dist/development/src/resolvers/query/ExecutedMigrationsQueryResolver.js.map +1 -1
  115. package/dist/development/src/resolvers/query/SchemaQueryResolver.cjs.map +1 -1
  116. package/dist/development/src/resolvers/query/SchemaQueryResolver.js.map +1 -1
  117. package/dist/development/src/resolvers/query/StagesQueryResolver.cjs.map +1 -1
  118. package/dist/development/src/resolvers/query/StagesQueryResolver.js.map +1 -1
  119. package/dist/development/src/resolvers/types/EventOldValuesResolver.cjs.map +1 -1
  120. package/dist/development/src/resolvers/types/EventOldValuesResolver.js.map +1 -1
  121. package/dist/development/src/schema/dev.graphql.cjs.map +1 -1
  122. package/dist/development/src/schema/system.graphql.cjs.map +1 -1
  123. package/dist/development/src/utils/MapSet.cjs.map +1 -1
  124. package/dist/development/src/utils/MapSet.js.map +1 -1
  125. package/dist/development/src/utils/Response.cjs.map +1 -1
  126. package/dist/development/src/utils/Response.js.map +1 -1
  127. package/dist/development/src/utils/batchQuery.cjs.map +1 -1
  128. package/dist/development/src/utils/batchQuery.js.map +1 -1
  129. package/dist/production/src/SystemContainer.cjs.map +1 -1
  130. package/dist/production/src/SystemContainer.js.map +1 -1
  131. package/dist/production/src/migrations/2020-03-27-130000-project-migrations.cjs.map +1 -1
  132. package/dist/production/src/migrations/2020-03-27-130000-project-migrations.js.map +1 -1
  133. package/dist/production/src/migrations/2020-05-06-150000-composed-primary.cjs.map +1 -1
  134. package/dist/production/src/migrations/2020-05-06-150000-composed-primary.js.map +1 -1
  135. package/dist/production/src/migrations/2020-06-01-103000-event-trigger-perf.cjs.map +1 -1
  136. package/dist/production/src/migrations/2020-06-01-103000-event-trigger-perf.js.map +1 -1
  137. package/dist/production/src/migrations/2021-05-07-155800-event-log-rework.cjs.map +1 -1
  138. package/dist/production/src/migrations/2021-05-07-155800-event-log-rework.js.map +1 -1
  139. package/dist/production/src/migrations/2021-05-19-1232000-event-log-fix-constraint.cjs.map +1 -1
  140. package/dist/production/src/migrations/2021-05-19-1232000-event-log-fix-constraint.js.map +1 -1
  141. package/dist/production/src/migrations/2022-10-03-110000-table-on-delete.cjs.map +1 -1
  142. package/dist/production/src/migrations/2022-10-03-110000-table-on-delete.js.map +1 -1
  143. package/dist/production/src/migrations/2023-09-11-174000-fix-on-delete.cjs.map +1 -1
  144. package/dist/production/src/migrations/2023-09-11-174000-fix-on-delete.js.map +1 -1
  145. package/dist/production/src/migrations/2023-10-19-173000-fix-unique.cjs.map +1 -1
  146. package/dist/production/src/migrations/2023-10-19-173000-fix-unique.js.map +1 -1
  147. package/dist/production/src/migrations/2024-06-28-153001-schema-init.cjs.map +1 -1
  148. package/dist/production/src/migrations/2024-06-28-153001-schema-init.js.map +1 -1
  149. package/dist/production/src/migrations/runner.cjs.map +1 -1
  150. package/dist/production/src/migrations/runner.js.map +1 -1
  151. package/dist/production/src/migrations/snapshot-factory.cjs.map +1 -1
  152. package/dist/production/src/migrations/snapshot-factory.js.map +1 -1
  153. package/dist/production/src/migrations/snapshot.cjs.map +1 -1
  154. package/dist/production/src/migrations/snapshot.js.map +1 -1
  155. package/dist/production/src/model/ProjectInitializer.cjs.map +1 -1
  156. package/dist/production/src/model/ProjectInitializer.js.map +1 -1
  157. package/dist/production/src/model/ProjectTruncateExecutor.cjs.map +1 -1
  158. package/dist/production/src/model/ProjectTruncateExecutor.js.map +1 -1
  159. package/dist/production/src/model/authorization/AuthorizationActions.cjs.map +1 -1
  160. package/dist/production/src/model/authorization/AuthorizationActions.js.map +1 -1
  161. package/dist/production/src/model/authorization/Identity.cjs.map +1 -1
  162. package/dist/production/src/model/authorization/Identity.js.map +1 -1
  163. package/dist/production/src/model/authorization/PermissionsFactory.cjs.map +1 -1
  164. package/dist/production/src/model/authorization/PermissionsFactory.js.map +1 -1
  165. package/dist/production/src/model/authorization/StagePermissionsFactory.cjs.map +1 -1
  166. package/dist/production/src/model/authorization/StagePermissionsFactory.js.map +1 -1
  167. package/dist/production/src/model/authorization/StageScope.cjs.map +1 -1
  168. package/dist/production/src/model/authorization/StageScope.js.map +1 -1
  169. package/dist/production/src/model/authorization/SwitchEvaluatorNode.cjs.map +1 -1
  170. package/dist/production/src/model/authorization/SwitchEvaluatorNode.js.map +1 -1
  171. package/dist/production/src/model/commands/CommandBus.cjs.map +1 -1
  172. package/dist/production/src/model/commands/CommandBus.js.map +1 -1
  173. package/dist/production/src/model/commands/events/TruncateEventsCommand.cjs.map +1 -1
  174. package/dist/production/src/model/commands/events/TruncateEventsCommand.js.map +1 -1
  175. package/dist/production/src/model/commands/migrations/DeleteMigrationCommand.cjs.map +1 -1
  176. package/dist/production/src/model/commands/migrations/DeleteMigrationCommand.js.map +1 -1
  177. package/dist/production/src/model/commands/migrations/ModifyMigrationCommand.cjs.map +1 -1
  178. package/dist/production/src/model/commands/migrations/ModifyMigrationCommand.js.map +1 -1
  179. package/dist/production/src/model/commands/migrations/SaveMigrationCommand.cjs.map +1 -1
  180. package/dist/production/src/model/commands/migrations/SaveMigrationCommand.js.map +1 -1
  181. package/dist/production/src/model/commands/schema/SaveSchemaCommand.cjs.map +1 -1
  182. package/dist/production/src/model/commands/schema/SaveSchemaCommand.js.map +1 -1
  183. package/dist/production/src/model/commands/stages/CreateStageCommand.cjs.map +1 -1
  184. package/dist/production/src/model/commands/stages/CreateStageCommand.js.map +1 -1
  185. package/dist/production/src/model/database/DatabaseContext.cjs.map +1 -1
  186. package/dist/production/src/model/database/DatabaseContext.js.map +1 -1
  187. package/dist/production/src/model/dtos/ExecutedMigration.cjs.map +1 -1
  188. package/dist/production/src/model/dtos/ExecutedMigration.js.map +1 -1
  189. package/dist/production/src/model/events/EventResponseBuilder.cjs.map +1 -1
  190. package/dist/production/src/model/events/EventResponseBuilder.js.map +1 -1
  191. package/dist/production/src/model/events/EventResponseHelper.cjs.map +1 -1
  192. package/dist/production/src/model/events/EventResponseHelper.js.map +1 -1
  193. package/dist/production/src/model/events/identityUtils.cjs.map +1 -1
  194. package/dist/production/src/model/events/identityUtils.js.map +1 -1
  195. package/dist/production/src/model/events/types.cjs.map +1 -1
  196. package/dist/production/src/model/events/types.js.map +1 -1
  197. package/dist/production/src/model/helpers/modelHelpers.cjs.map +1 -1
  198. package/dist/production/src/model/helpers/modelHelpers.js.map +1 -1
  199. package/dist/production/src/model/metadata/SchemaDatabaseMetadataResolverStore.cjs.map +1 -1
  200. package/dist/production/src/model/metadata/SchemaDatabaseMetadataResolverStore.js.map +1 -1
  201. package/dist/production/src/model/migrations/ExecutedMigrationsResolver.cjs.map +1 -1
  202. package/dist/production/src/model/migrations/ExecutedMigrationsResolver.js.map +1 -1
  203. package/dist/production/src/model/migrations/MigrationAlterer.cjs.map +1 -1
  204. package/dist/production/src/model/migrations/MigrationAlterer.js.map +1 -1
  205. package/dist/production/src/model/migrations/ProjectMigrator.cjs.map +1 -1
  206. package/dist/production/src/model/migrations/ProjectMigrator.js.map +1 -1
  207. package/dist/production/src/model/migrations/SchemaProvider.cjs.map +1 -1
  208. package/dist/production/src/model/migrations/SchemaProvider.js.map +1 -1
  209. package/dist/production/src/model/queries/events/EventQueryHelpers.cjs.map +1 -1
  210. package/dist/production/src/model/queries/events/EventQueryHelpers.js.map +1 -1
  211. package/dist/production/src/model/queries/events/EventsQuery.cjs.map +1 -1
  212. package/dist/production/src/model/queries/events/EventsQuery.js.map +1 -1
  213. package/dist/production/src/model/queries/events/LatestTransactionIdByStageQuery.cjs.map +1 -1
  214. package/dist/production/src/model/queries/events/LatestTransactionIdByStageQuery.js.map +1 -1
  215. package/dist/production/src/model/queries/events/OldValuesQuery.cjs.map +1 -1
  216. package/dist/production/src/model/queries/events/OldValuesQuery.js.map +1 -1
  217. package/dist/production/src/model/queries/migrations/ExecutedMigrationByVersionQuery.cjs.map +1 -1
  218. package/dist/production/src/model/queries/migrations/ExecutedMigrationByVersionQuery.js.map +1 -1
  219. package/dist/production/src/model/queries/migrations/ExecutedMigrationsQuery.cjs.map +1 -1
  220. package/dist/production/src/model/queries/migrations/ExecutedMigrationsQuery.js.map +1 -1
  221. package/dist/production/src/model/queries/schema/SchemaQuery.cjs.map +1 -1
  222. package/dist/production/src/model/queries/schema/SchemaQuery.js.map +1 -1
  223. package/dist/production/src/model/queries/stages/StageBySlugQuery.cjs.map +1 -1
  224. package/dist/production/src/model/queries/stages/StageBySlugQuery.js.map +1 -1
  225. package/dist/production/src/model/queries/stages/StagesQuery.cjs.map +1 -1
  226. package/dist/production/src/model/queries/stages/StagesQuery.js.map +1 -1
  227. package/dist/production/src/model/stages/StageCreator.cjs.map +1 -1
  228. package/dist/production/src/model/stages/StageCreator.js.map +1 -1
  229. package/dist/production/src/resolvers/ResolverFactory.cjs.map +1 -1
  230. package/dist/production/src/resolvers/ResolverFactory.js.map +1 -1
  231. package/dist/production/src/resolvers/SystemResolverContext.cjs.map +1 -1
  232. package/dist/production/src/resolvers/SystemResolverContext.js.map +1 -1
  233. package/dist/production/src/resolvers/mutation/MigrateMutationResolver.cjs.map +1 -1
  234. package/dist/production/src/resolvers/mutation/MigrateMutationResolver.js.map +1 -1
  235. package/dist/production/src/resolvers/mutation/MigrationAlterMutationResolver.cjs.map +1 -1
  236. package/dist/production/src/resolvers/mutation/MigrationAlterMutationResolver.js.map +1 -1
  237. package/dist/production/src/resolvers/mutation/TruncateMutationResolver.cjs.map +1 -1
  238. package/dist/production/src/resolvers/mutation/TruncateMutationResolver.js.map +1 -1
  239. package/dist/production/src/resolvers/query/EventsQueryResolver.cjs.map +1 -1
  240. package/dist/production/src/resolvers/query/EventsQueryResolver.js.map +1 -1
  241. package/dist/production/src/resolvers/query/ExecutedMigrationsQueryResolver.cjs.map +1 -1
  242. package/dist/production/src/resolvers/query/ExecutedMigrationsQueryResolver.js.map +1 -1
  243. package/dist/production/src/resolvers/query/SchemaQueryResolver.cjs.map +1 -1
  244. package/dist/production/src/resolvers/query/SchemaQueryResolver.js.map +1 -1
  245. package/dist/production/src/resolvers/query/StagesQueryResolver.cjs.map +1 -1
  246. package/dist/production/src/resolvers/query/StagesQueryResolver.js.map +1 -1
  247. package/dist/production/src/resolvers/types/EventOldValuesResolver.cjs.map +1 -1
  248. package/dist/production/src/resolvers/types/EventOldValuesResolver.js.map +1 -1
  249. package/dist/production/src/schema/dev.graphql.cjs.map +1 -1
  250. package/dist/production/src/schema/system.graphql.cjs.map +1 -1
  251. package/dist/production/src/utils/MapSet.cjs.map +1 -1
  252. package/dist/production/src/utils/MapSet.js.map +1 -1
  253. package/dist/production/src/utils/Response.cjs.map +1 -1
  254. package/dist/production/src/utils/Response.js.map +1 -1
  255. package/dist/production/src/utils/batchQuery.cjs.map +1 -1
  256. package/dist/production/src/utils/batchQuery.js.map +1 -1
  257. package/dist/tests/tsconfig.tsbuildinfo +1 -1
  258. package/dist/types/tsconfig.tsbuildinfo +1 -1
  259. package/graphql.codegen.yml +1 -1
  260. package/package.json +13 -13
  261. package/tests/cases/migrations/2020-05-06-150000-composed-primary.test.ts +3 -2
  262. package/tests/cases/migrations/2020-06-01-103000-event-trigger-perf.test.ts +3 -2
  263. package/tests/cases/migrations/2022-10-03-110000-table-on-delete.test.ts +3 -2
  264. package/tests/cases/migrations/2023-09-11-174000-fix-on-delete.test.ts +5 -4
  265. package/tests/cases/migrations/2023-10-19-173000-fix-unique.test.ts +3 -2
  266. package/tests/cases/unit/eventsQuery.test.ts +12 -12
@@ -1 +1 @@
1
- {"version":3,"file":"ExecutedMigrationsResolver.js","sources":["../../../../../../packages/engine-system-api/src/model/migrations/ExecutedMigrationsResolver.ts"],"sourcesContent":["import { ExecutedMigration } from '../dtos'\nimport { ExecutedMigrationByVersionQuery, ExecutedMigrationsQuery } from '../queries'\nimport { DatabaseContext } from '../database'\n\nexport class ExecutedMigrationsResolver {\n\tasync getMigrations(db: DatabaseContext, afterVersion?: string): Promise<ExecutedMigration[]> {\n\t\treturn db.queryHandler.fetch(new ExecutedMigrationsQuery(afterVersion))\n\t}\n\n\tasync getMigrationByVersion(db: DatabaseContext, version: string): Promise<ExecutedMigration | null> {\n\t\treturn db.queryHandler.fetch(new ExecutedMigrationByVersionQuery(version))\n\t}\n}\n"],"names":[],"mappings":";;;;;AAIO,MAAM,2BAA2B;AAAA,EACvC,MAAM,cAAc,IAAqB,cAAqD;AAC7F,WAAO,GAAG,aAAa,MAAM,IAAI,wBAAwB,YAAY,CAAC;AAAA,EACvE;AAAA,EAEA,MAAM,sBAAsB,IAAqB,SAAoD;AACpG,WAAO,GAAG,aAAa,MAAM,IAAI,gCAAgC,OAAO,CAAC;AAAA,EAC1E;AACD;"}
1
+ {"version":3,"file":"ExecutedMigrationsResolver.js","sources":["../../../../../../packages/engine-system-api/src/model/migrations/ExecutedMigrationsResolver.ts"],"sourcesContent":["import { ExecutedMigration } from '../dtos'\nimport { ExecutedMigrationByVersionQuery, ExecutedMigrationsQuery } from '../queries'\nimport { DatabaseContext } from '../database'\n\nexport class ExecutedMigrationsResolver {\n\tasync getMigrations(db: DatabaseContext, afterVersion?: string): Promise<ExecutedMigration[]> {\n\t\treturn db.queryHandler.fetch(new ExecutedMigrationsQuery(afterVersion))\n\t}\n\n\tasync getMigrationByVersion(db: DatabaseContext, version: string): Promise<ExecutedMigration | null> {\n\t\treturn db.queryHandler.fetch(new ExecutedMigrationByVersionQuery(version))\n\t}\n}\n"],"names":[],"mappings":";;;;;AAIO,MAAM,2BAA2B;AAAA,EACvC,MAAM,cAAc,IAAqB,cAAqD;AAC7F,WAAO,GAAG,aAAa,MAAM,IAAI,wBAAwB,YAAY,CAAC;AAAA,EAAA;AAAA,EAGvE,MAAM,sBAAsB,IAAqB,SAAoD;AACpG,WAAO,GAAG,aAAa,MAAM,IAAI,gCAAgC,OAAO,CAAC;AAAA,EAAA;AAE3E;"}
@@ -1 +1 @@
1
- {"version":3,"file":"MigrationAlterer.cjs","sources":["../../../../../../packages/engine-system-api/src/model/migrations/MigrationAlterer.ts"],"sourcesContent":["import { DatabaseContext } from '../database'\nimport { DeleteMigrationCommand } from '../commands'\nimport { Response, ResponseError, ResponseOk } from '../../utils'\nimport { Migration } from '@contember/schema-migrations'\nimport { ModifyMigrationCommand } from '../commands/migrations/ModifyMigrationCommand'\nimport { SchemaProvider } from './SchemaProvider'\nimport { SaveSchemaCommand } from '../commands/schema/SaveSchemaCommand'\n\nexport class MigrationAlterer {\n\tconstructor(\n\t\tprivate readonly schemaProvider: SchemaProvider,\n\t) {\n\t}\n\n\tpublic async deleteMigration(\n\t\tdb: DatabaseContext,\n\t\tversion: string,\n\t): Promise<Response<undefined, DeleteMigrationErrorCode>> {\n\t\treturn await db.transaction(async db => {\n\t\t\tconst result = await db.commandBus.execute(new DeleteMigrationCommand(version))\n\t\t\tif (!result) {\n\t\t\t\tawait db.client.connection.rollback()\n\t\t\t\treturn new ResponseError(DeleteMigrationErrorCode.notFound, `Migration ${version} was not found`)\n\t\t\t}\n\t\t\tawait this.refreshSchema(db)\n\t\t\treturn new ResponseOk(undefined)\n\t\t})\n\t}\n\n\tpublic async modifyMigration(\n\t\tdb: DatabaseContext,\n\t\tversion: string,\n\t\tmigration: Partial<Migration>,\n\t): Promise<Response<undefined, UpdateMigrationErrorCode>> {\n\t\treturn await db.transaction(async db => {\n\t\t\tconst result = await db.commandBus.execute(new ModifyMigrationCommand(version, migration))\n\t\t\tif (!result) {\n\t\t\t\tawait db.client.connection.rollback()\n\t\t\t\treturn new ResponseError(UpdateMigrationErrorCode.notFound, `Migration ${version} was not found`)\n\t\t\t}\n\t\t\tawait this.refreshSchema(db)\n\t\t\treturn new ResponseOk(undefined)\n\t\t})\n\t}\n\n\tprivate async refreshSchema(db: DatabaseContext): Promise<void> {\n\t\tconst schemaWithMeta = await this.schemaProvider.buildSchemaFromMigrations(db)\n\t\tawait db.commandBus.execute(new SaveSchemaCommand(schemaWithMeta))\n\t}\n}\n\nexport enum DeleteMigrationErrorCode {\n\tnotFound = 'notFound',\n}\n\nexport enum UpdateMigrationErrorCode {\n\tnotFound = 'notFound',\n}\n"],"names":["db","DeleteMigrationCommand","ResponseError","ResponseOk","ModifyMigrationCommand","SaveSchemaCommand","DeleteMigrationErrorCode","UpdateMigrationErrorCode"],"mappings":";;;;;;;;;AAQO,MAAM,iBAAiB;AAAA,EAC7B,YACkB,gBAChB;AADgB,SAAA,iBAAA;AAAA,EAElB;AAAA,EAEA,MAAa,gBACZ,IACA,SACyD;AACzD,WAAO,MAAM,GAAG,YAAY,OAAMA,QAAM;AACjC,YAAA,SAAS,MAAMA,IAAG,WAAW,QAAQ,IAAIC,uBAAA,uBAAuB,OAAO,CAAC;AAC9E,UAAI,CAAC,QAAQ;AACND,cAAAA,IAAG,OAAO,WAAW,SAAS;AACpC,eAAO,IAAIE,SAAA,cAAc,YAAmC,aAAa,OAAO,gBAAgB;AAAA,MACjG;AACM,YAAA,KAAK,cAAcF,GAAE;AACpB,aAAA,IAAIG,SAAAA,WAAW,MAAS;AAAA,IAAA,CAC/B;AAAA,EACF;AAAA,EAEA,MAAa,gBACZ,IACA,SACA,WACyD;AACzD,WAAO,MAAM,GAAG,YAAY,OAAMH,QAAM;AACjC,YAAA,SAAS,MAAMA,IAAG,WAAW,QAAQ,IAAII,8CAAuB,SAAS,SAAS,CAAC;AACzF,UAAI,CAAC,QAAQ;AACNJ,cAAAA,IAAG,OAAO,WAAW,SAAS;AACpC,eAAO,IAAIE,SAAA,cAAc,YAAmC,aAAa,OAAO,gBAAgB;AAAA,MACjG;AACM,YAAA,KAAK,cAAcF,GAAE;AACpB,aAAA,IAAIG,SAAAA,WAAW,MAAS;AAAA,IAAA,CAC/B;AAAA,EACF;AAAA,EAEA,MAAc,cAAc,IAAoC;AAC/D,UAAM,iBAAiB,MAAM,KAAK,eAAe,0BAA0B,EAAE;AAC7E,UAAM,GAAG,WAAW,QAAQ,IAAIE,kBAAA,kBAAkB,cAAc,CAAC;AAAA,EAClE;AACD;AAEY,IAAA,6CAAAC,8BAAL;AACNA,4BAAA,UAAW,IAAA;AADAA,SAAAA;AAAA,GAAA,4BAAA,CAAA,CAAA;AAIA,IAAA,6CAAAC,8BAAL;AACNA,4BAAA,UAAW,IAAA;AADAA,SAAAA;AAAA,GAAA,4BAAA,CAAA,CAAA;;;;"}
1
+ {"version":3,"file":"MigrationAlterer.cjs","sources":["../../../../../../packages/engine-system-api/src/model/migrations/MigrationAlterer.ts"],"sourcesContent":["import { DatabaseContext } from '../database'\nimport { DeleteMigrationCommand } from '../commands'\nimport { Response, ResponseError, ResponseOk } from '../../utils'\nimport { Migration } from '@contember/schema-migrations'\nimport { ModifyMigrationCommand } from '../commands/migrations/ModifyMigrationCommand'\nimport { SchemaProvider } from './SchemaProvider'\nimport { SaveSchemaCommand } from '../commands/schema/SaveSchemaCommand'\n\nexport class MigrationAlterer {\n\tconstructor(\n\t\tprivate readonly schemaProvider: SchemaProvider,\n\t) {\n\t}\n\n\tpublic async deleteMigration(\n\t\tdb: DatabaseContext,\n\t\tversion: string,\n\t): Promise<Response<undefined, DeleteMigrationErrorCode>> {\n\t\treturn await db.transaction(async db => {\n\t\t\tconst result = await db.commandBus.execute(new DeleteMigrationCommand(version))\n\t\t\tif (!result) {\n\t\t\t\tawait db.client.connection.rollback()\n\t\t\t\treturn new ResponseError(DeleteMigrationErrorCode.notFound, `Migration ${version} was not found`)\n\t\t\t}\n\t\t\tawait this.refreshSchema(db)\n\t\t\treturn new ResponseOk(undefined)\n\t\t})\n\t}\n\n\tpublic async modifyMigration(\n\t\tdb: DatabaseContext,\n\t\tversion: string,\n\t\tmigration: Partial<Migration>,\n\t): Promise<Response<undefined, UpdateMigrationErrorCode>> {\n\t\treturn await db.transaction(async db => {\n\t\t\tconst result = await db.commandBus.execute(new ModifyMigrationCommand(version, migration))\n\t\t\tif (!result) {\n\t\t\t\tawait db.client.connection.rollback()\n\t\t\t\treturn new ResponseError(UpdateMigrationErrorCode.notFound, `Migration ${version} was not found`)\n\t\t\t}\n\t\t\tawait this.refreshSchema(db)\n\t\t\treturn new ResponseOk(undefined)\n\t\t})\n\t}\n\n\tprivate async refreshSchema(db: DatabaseContext): Promise<void> {\n\t\tconst schemaWithMeta = await this.schemaProvider.buildSchemaFromMigrations(db)\n\t\tawait db.commandBus.execute(new SaveSchemaCommand(schemaWithMeta))\n\t}\n}\n\nexport enum DeleteMigrationErrorCode {\n\tnotFound = 'notFound',\n}\n\nexport enum UpdateMigrationErrorCode {\n\tnotFound = 'notFound',\n}\n"],"names":["db","DeleteMigrationCommand","ResponseError","ResponseOk","ModifyMigrationCommand","SaveSchemaCommand","DeleteMigrationErrorCode","UpdateMigrationErrorCode"],"mappings":";;;;;;;;;AAQO,MAAM,iBAAiB;AAAA,EAC7B,YACkB,gBAChB;AADgB,SAAA,iBAAA;AAAA,EAAA;AAAA,EAIlB,MAAa,gBACZ,IACA,SACyD;AACzD,WAAO,MAAM,GAAG,YAAY,OAAMA,QAAM;AACjC,YAAA,SAAS,MAAMA,IAAG,WAAW,QAAQ,IAAIC,uBAAAA,uBAAuB,OAAO,CAAC;AAC9E,UAAI,CAAC,QAAQ;AACND,cAAAA,IAAG,OAAO,WAAW,SAAS;AACpC,eAAO,IAAIE,SAAA,cAAc,YAAmC,aAAa,OAAO,gBAAgB;AAAA,MAAA;AAE3F,YAAA,KAAK,cAAcF,GAAE;AACpB,aAAA,IAAIG,SAAAA,WAAW,MAAS;AAAA,IAAA,CAC/B;AAAA,EAAA;AAAA,EAGF,MAAa,gBACZ,IACA,SACA,WACyD;AACzD,WAAO,MAAM,GAAG,YAAY,OAAMH,QAAM;AACjC,YAAA,SAAS,MAAMA,IAAG,WAAW,QAAQ,IAAII,uBAAA,uBAAuB,SAAS,SAAS,CAAC;AACzF,UAAI,CAAC,QAAQ;AACNJ,cAAAA,IAAG,OAAO,WAAW,SAAS;AACpC,eAAO,IAAIE,SAAA,cAAc,YAAmC,aAAa,OAAO,gBAAgB;AAAA,MAAA;AAE3F,YAAA,KAAK,cAAcF,GAAE;AACpB,aAAA,IAAIG,SAAAA,WAAW,MAAS;AAAA,IAAA,CAC/B;AAAA,EAAA;AAAA,EAGF,MAAc,cAAc,IAAoC;AAC/D,UAAM,iBAAiB,MAAM,KAAK,eAAe,0BAA0B,EAAE;AAC7E,UAAM,GAAG,WAAW,QAAQ,IAAIE,kBAAA,kBAAkB,cAAc,CAAC;AAAA,EAAA;AAEnE;AAEY,IAAA,6CAAAC,8BAAL;AACNA,4BAAA,UAAW,IAAA;AADAA,SAAAA;AAAA,GAAA,4BAAA,CAAA,CAAA;AAIA,IAAA,6CAAAC,8BAAL;AACNA,4BAAA,UAAW,IAAA;AADAA,SAAAA;AAAA,GAAA,4BAAA,CAAA,CAAA;;;;"}
@@ -1 +1 @@
1
- {"version":3,"file":"MigrationAlterer.js","sources":["../../../../../../packages/engine-system-api/src/model/migrations/MigrationAlterer.ts"],"sourcesContent":["import { DatabaseContext } from '../database'\nimport { DeleteMigrationCommand } from '../commands'\nimport { Response, ResponseError, ResponseOk } from '../../utils'\nimport { Migration } from '@contember/schema-migrations'\nimport { ModifyMigrationCommand } from '../commands/migrations/ModifyMigrationCommand'\nimport { SchemaProvider } from './SchemaProvider'\nimport { SaveSchemaCommand } from '../commands/schema/SaveSchemaCommand'\n\nexport class MigrationAlterer {\n\tconstructor(\n\t\tprivate readonly schemaProvider: SchemaProvider,\n\t) {\n\t}\n\n\tpublic async deleteMigration(\n\t\tdb: DatabaseContext,\n\t\tversion: string,\n\t): Promise<Response<undefined, DeleteMigrationErrorCode>> {\n\t\treturn await db.transaction(async db => {\n\t\t\tconst result = await db.commandBus.execute(new DeleteMigrationCommand(version))\n\t\t\tif (!result) {\n\t\t\t\tawait db.client.connection.rollback()\n\t\t\t\treturn new ResponseError(DeleteMigrationErrorCode.notFound, `Migration ${version} was not found`)\n\t\t\t}\n\t\t\tawait this.refreshSchema(db)\n\t\t\treturn new ResponseOk(undefined)\n\t\t})\n\t}\n\n\tpublic async modifyMigration(\n\t\tdb: DatabaseContext,\n\t\tversion: string,\n\t\tmigration: Partial<Migration>,\n\t): Promise<Response<undefined, UpdateMigrationErrorCode>> {\n\t\treturn await db.transaction(async db => {\n\t\t\tconst result = await db.commandBus.execute(new ModifyMigrationCommand(version, migration))\n\t\t\tif (!result) {\n\t\t\t\tawait db.client.connection.rollback()\n\t\t\t\treturn new ResponseError(UpdateMigrationErrorCode.notFound, `Migration ${version} was not found`)\n\t\t\t}\n\t\t\tawait this.refreshSchema(db)\n\t\t\treturn new ResponseOk(undefined)\n\t\t})\n\t}\n\n\tprivate async refreshSchema(db: DatabaseContext): Promise<void> {\n\t\tconst schemaWithMeta = await this.schemaProvider.buildSchemaFromMigrations(db)\n\t\tawait db.commandBus.execute(new SaveSchemaCommand(schemaWithMeta))\n\t}\n}\n\nexport enum DeleteMigrationErrorCode {\n\tnotFound = 'notFound',\n}\n\nexport enum UpdateMigrationErrorCode {\n\tnotFound = 'notFound',\n}\n"],"names":["db","DeleteMigrationErrorCode","UpdateMigrationErrorCode"],"mappings":";;;;;;;AAQO,MAAM,iBAAiB;AAAA,EAC7B,YACkB,gBAChB;AADgB,SAAA,iBAAA;AAAA,EAElB;AAAA,EAEA,MAAa,gBACZ,IACA,SACyD;AACzD,WAAO,MAAM,GAAG,YAAY,OAAMA,QAAM;AACjC,YAAA,SAAS,MAAMA,IAAG,WAAW,QAAQ,IAAI,uBAAuB,OAAO,CAAC;AAC9E,UAAI,CAAC,QAAQ;AACNA,cAAAA,IAAG,OAAO,WAAW,SAAS;AACpC,eAAO,IAAI,cAAc,YAAmC,aAAa,OAAO,gBAAgB;AAAA,MACjG;AACM,YAAA,KAAK,cAAcA,GAAE;AACpB,aAAA,IAAI,WAAW,MAAS;AAAA,IAAA,CAC/B;AAAA,EACF;AAAA,EAEA,MAAa,gBACZ,IACA,SACA,WACyD;AACzD,WAAO,MAAM,GAAG,YAAY,OAAMA,QAAM;AACjC,YAAA,SAAS,MAAMA,IAAG,WAAW,QAAQ,IAAI,uBAAuB,SAAS,SAAS,CAAC;AACzF,UAAI,CAAC,QAAQ;AACNA,cAAAA,IAAG,OAAO,WAAW,SAAS;AACpC,eAAO,IAAI,cAAc,YAAmC,aAAa,OAAO,gBAAgB;AAAA,MACjG;AACM,YAAA,KAAK,cAAcA,GAAE;AACpB,aAAA,IAAI,WAAW,MAAS;AAAA,IAAA,CAC/B;AAAA,EACF;AAAA,EAEA,MAAc,cAAc,IAAoC;AAC/D,UAAM,iBAAiB,MAAM,KAAK,eAAe,0BAA0B,EAAE;AAC7E,UAAM,GAAG,WAAW,QAAQ,IAAI,kBAAkB,cAAc,CAAC;AAAA,EAClE;AACD;AAEY,IAAA,6CAAAC,8BAAL;AACNA,4BAAA,UAAW,IAAA;AADAA,SAAAA;AAAA,GAAA,4BAAA,CAAA,CAAA;AAIA,IAAA,6CAAAC,8BAAL;AACNA,4BAAA,UAAW,IAAA;AADAA,SAAAA;AAAA,GAAA,4BAAA,CAAA,CAAA;"}
1
+ {"version":3,"file":"MigrationAlterer.js","sources":["../../../../../../packages/engine-system-api/src/model/migrations/MigrationAlterer.ts"],"sourcesContent":["import { DatabaseContext } from '../database'\nimport { DeleteMigrationCommand } from '../commands'\nimport { Response, ResponseError, ResponseOk } from '../../utils'\nimport { Migration } from '@contember/schema-migrations'\nimport { ModifyMigrationCommand } from '../commands/migrations/ModifyMigrationCommand'\nimport { SchemaProvider } from './SchemaProvider'\nimport { SaveSchemaCommand } from '../commands/schema/SaveSchemaCommand'\n\nexport class MigrationAlterer {\n\tconstructor(\n\t\tprivate readonly schemaProvider: SchemaProvider,\n\t) {\n\t}\n\n\tpublic async deleteMigration(\n\t\tdb: DatabaseContext,\n\t\tversion: string,\n\t): Promise<Response<undefined, DeleteMigrationErrorCode>> {\n\t\treturn await db.transaction(async db => {\n\t\t\tconst result = await db.commandBus.execute(new DeleteMigrationCommand(version))\n\t\t\tif (!result) {\n\t\t\t\tawait db.client.connection.rollback()\n\t\t\t\treturn new ResponseError(DeleteMigrationErrorCode.notFound, `Migration ${version} was not found`)\n\t\t\t}\n\t\t\tawait this.refreshSchema(db)\n\t\t\treturn new ResponseOk(undefined)\n\t\t})\n\t}\n\n\tpublic async modifyMigration(\n\t\tdb: DatabaseContext,\n\t\tversion: string,\n\t\tmigration: Partial<Migration>,\n\t): Promise<Response<undefined, UpdateMigrationErrorCode>> {\n\t\treturn await db.transaction(async db => {\n\t\t\tconst result = await db.commandBus.execute(new ModifyMigrationCommand(version, migration))\n\t\t\tif (!result) {\n\t\t\t\tawait db.client.connection.rollback()\n\t\t\t\treturn new ResponseError(UpdateMigrationErrorCode.notFound, `Migration ${version} was not found`)\n\t\t\t}\n\t\t\tawait this.refreshSchema(db)\n\t\t\treturn new ResponseOk(undefined)\n\t\t})\n\t}\n\n\tprivate async refreshSchema(db: DatabaseContext): Promise<void> {\n\t\tconst schemaWithMeta = await this.schemaProvider.buildSchemaFromMigrations(db)\n\t\tawait db.commandBus.execute(new SaveSchemaCommand(schemaWithMeta))\n\t}\n}\n\nexport enum DeleteMigrationErrorCode {\n\tnotFound = 'notFound',\n}\n\nexport enum UpdateMigrationErrorCode {\n\tnotFound = 'notFound',\n}\n"],"names":["db","DeleteMigrationErrorCode","UpdateMigrationErrorCode"],"mappings":";;;;;;;AAQO,MAAM,iBAAiB;AAAA,EAC7B,YACkB,gBAChB;AADgB,SAAA,iBAAA;AAAA,EAAA;AAAA,EAIlB,MAAa,gBACZ,IACA,SACyD;AACzD,WAAO,MAAM,GAAG,YAAY,OAAMA,QAAM;AACjC,YAAA,SAAS,MAAMA,IAAG,WAAW,QAAQ,IAAI,uBAAuB,OAAO,CAAC;AAC9E,UAAI,CAAC,QAAQ;AACNA,cAAAA,IAAG,OAAO,WAAW,SAAS;AACpC,eAAO,IAAI,cAAc,YAAmC,aAAa,OAAO,gBAAgB;AAAA,MAAA;AAE3F,YAAA,KAAK,cAAcA,GAAE;AACpB,aAAA,IAAI,WAAW,MAAS;AAAA,IAAA,CAC/B;AAAA,EAAA;AAAA,EAGF,MAAa,gBACZ,IACA,SACA,WACyD;AACzD,WAAO,MAAM,GAAG,YAAY,OAAMA,QAAM;AACjC,YAAA,SAAS,MAAMA,IAAG,WAAW,QAAQ,IAAI,uBAAuB,SAAS,SAAS,CAAC;AACzF,UAAI,CAAC,QAAQ;AACNA,cAAAA,IAAG,OAAO,WAAW,SAAS;AACpC,eAAO,IAAI,cAAc,YAAmC,aAAa,OAAO,gBAAgB;AAAA,MAAA;AAE3F,YAAA,KAAK,cAAcA,GAAE;AACpB,aAAA,IAAI,WAAW,MAAS;AAAA,IAAA,CAC/B;AAAA,EAAA;AAAA,EAGF,MAAc,cAAc,IAAoC;AAC/D,UAAM,iBAAiB,MAAM,KAAK,eAAe,0BAA0B,EAAE;AAC7E,UAAM,GAAG,WAAW,QAAQ,IAAI,kBAAkB,cAAc,CAAC;AAAA,EAAA;AAEnE;AAEY,IAAA,6CAAAC,8BAAL;AACNA,4BAAA,UAAW,IAAA;AADAA,SAAAA;AAAA,GAAA,4BAAA,CAAA,CAAA;AAIA,IAAA,6CAAAC,8BAAL;AACNA,4BAAA,UAAW,IAAA;AADAA,SAAAA;AAAA,GAAA,4BAAA,CAAA,CAAA;"}
@@ -1 +1 @@
1
- {"version":3,"file":"ProjectMigrator.cjs","sources":["../../../../../../packages/engine-system-api/src/model/migrations/ProjectMigrator.ts"],"sourcesContent":["import { calculateMigrationChecksum, Migration, MigrationDescriber, MigrationVersionHelper } from '@contember/schema-migrations'\nimport { Client, DatabaseMetadata, QueryError, wrapIdentifier } from '@contember/database'\nimport { Schema } from '@contember/schema'\nimport { SaveMigrationCommand } from '../commands'\nimport { Stage } from '../dtos'\nimport { DatabaseContext } from '../database'\nimport { ExecutedMigrationsResolver } from './ExecutedMigrationsResolver'\nimport { MigrateErrorCode } from '../../schema'\nimport { calculateSchemaChecksum, SchemaValidator, SchemaValidatorSkippedErrors } from '@contember/schema-utils'\nimport { logger } from '@contember/logger'\nimport { MigrationsDatabaseMetadataResolverStoreFactory, SchemaDatabaseMetadataResolverStore } from '../metadata'\nimport { ContentMigrationQuery, MigrationInput } from './MigrationInput'\nimport { ContentQueryExecutor } from '../dependencies'\nimport { SchemaProvider } from './SchemaProvider'\nimport { SaveSchemaCommand } from '../commands/schema/SaveSchemaCommand'\nimport { ImplementationException } from '../../utils'\n\nexport class ProjectMigrator {\n\tconstructor(\n\t\tprivate readonly migrationDescriber: MigrationDescriber,\n\t\tprivate readonly schemaProvider: SchemaProvider,\n\t\tprivate readonly executedMigrationsResolver: ExecutedMigrationsResolver,\n\t\tprivate readonly migrationsDatabaseMetadataResolverStoreFactory: MigrationsDatabaseMetadataResolverStoreFactory,\n\t\tprivate readonly contentQueryExecutor: ContentQueryExecutor,\n\t) {}\n\n\tpublic async migrate({ db, project, identity, options: { ignoreOrder = false, skipExecuted = false }, migrationsToExecute, stages }: {\n\t\tdb: DatabaseContext\n\t\tproject: { slug: string; systemSchema: string }\n\t\tidentity: { id: string }\n\t\tstages: Stage[]\n\t\tmigrationsToExecute: readonly MigrationInput[]\n\t\toptions: {\n\t\t\tignoreOrder?: boolean\n\t\t\tskipExecuted?: boolean\n\t\t}\n\t}) {\n\t\tif (migrationsToExecute.length === 0) {\n\t\t\treturn\n\t\t}\n\t\tconst schemaWithMeta = await this.schemaProvider.fetch({ db })\n\t\tlet schema = schemaWithMeta.schema\n\t\tlet id = schemaWithMeta.meta.id\n\n\t\tconst validated = await this.validateMigrations(db, schema, schemaWithMeta.meta.version ?? null, migrationsToExecute, { ignoreOrder, skipExecuted })\n\t\tif (validated.length === 0) {\n\t\t\treturn\n\t\t}\n\n\t\tconst sorted = [...validated].sort((a, b) => a.version.localeCompare(b.version))\n\n\t\tconst metadataStore = this.migrationsDatabaseMetadataResolverStoreFactory.create(db)\n\n\t\tfor (const migration of sorted) {\n\n\t\t\tif (migration.type === 'schema') {\n\t\t\t\tconst formatVersion = migration.formatVersion\n\n\t\t\t\tfor (const modification of migration.modifications) {\n\t\t\t\t\t[schema] = await this.applyModification(\n\t\t\t\t\t\tdb.client,\n\t\t\t\t\t\tstages,\n\t\t\t\t\t\tschema,\n\t\t\t\t\t\tmodification,\n\t\t\t\t\t\tformatVersion,\n\t\t\t\t\t\tmigration.version,\n\t\t\t\t\t\tdb.client.schema,\n\t\t\t\t\t\tmetadataStore,\n\t\t\t\t\t)\n\t\t\t\t}\n\t\t\t} else if (migration.type === 'content') {\n\t\t\t\tif (!id) {\n\t\t\t\t\tthrow new FailedContentMigrationError(migration.version, `Cannot execute content migration without schema`)\n\t\t\t\t}\n\t\t\t\tfor (const query of migration.queries) {\n\t\t\t\t\tawait this.executeContentMigration({\n\t\t\t\t\t\tversion: migration.version,\n\t\t\t\t\t\tquery,\n\t\t\t\t\t\tdb,\n\t\t\t\t\t\tschema,\n\t\t\t\t\t\tschemaMeta: { id },\n\t\t\t\t\t\tstages,\n\t\t\t\t\t\tdatabaseMetadata: await metadataStore.getMetadata(db.client.schema),\n\t\t\t\t\t\tidentity,\n\t\t\t\t\t\tproject,\n\t\t\t\t\t})\n\t\t\t\t}\n\t\t\t\t// event log uses deferred constraint triggers, we need to fire them before ALTER\n\t\t\t\tawait db.client.query(`SET CONSTRAINTS ALL IMMEDIATE`)\n\t\t\t\tawait db.client.query(`SET CONSTRAINTS ALL DEFERRED`)\n\n\t\t\t}\n\t\t\tid = await db.commandBus.execute(new SaveMigrationCommand(migration))\n\t\t}\n\t\tif (!id) {\n\t\t\tthrow new ImplementationException()\n\t\t}\n\n\t\tawait db.commandBus.execute(new SaveSchemaCommand({\n\t\t\tschema,\n\t\t\tmeta: {\n\t\t\t\tid,\n\t\t\t\tupdatedAt: new Date(),\n\t\t\t\tversion: sorted[sorted.length - 1].version,\n\t\t\t\tchecksum: calculateSchemaChecksum(schema),\n\t\t\t},\n\t\t}))\n\t}\n\n\tprivate async executeContentMigration({ query, stages, version, ...ctx }: {\n\t\tversion: string\n\t\tdb: DatabaseContext\n\t\tquery: ContentMigrationQuery\n\t\tstages: Stage[]\n\t\tschema: Schema\n\t\tschemaMeta: { id: number }\n\t\tproject: { slug: string; systemSchema: string }\n\t\tidentity: { id: string }\n\t\tdatabaseMetadata: DatabaseMetadata\n\t}) {\n\t\tconst queryStages = query.stage ? stages.filter(it => it.slug === query.stage) : stages\n\t\tfor (const stage of queryStages) {\n\t\t\tconst response = await this.contentQueryExecutor.execute({\n\t\t\t\tstage,\n\t\t\t\t...ctx,\n\t\t\t}, query)\n\n\t\t\tif (!response.ok) {\n\t\t\t\tthrow new FailedContentMigrationError(version, response.errors.join(', '))\n\t\t\t}\n\t\t\tif (query.checkMutationResult !== false) {\n\t\t\t\tfor (const [key, value] of Object.entries(response.result.data ?? {})) {\n\t\t\t\t\tif (typeof value === 'object' && value !== null && 'ok' in value && !value.ok) {\n\t\t\t\t\t\tconst errorDetails = 'errorMessage' in value ? value.errorMessage : 'No details available. Please fetch errorMessage field.'\n\t\t\t\t\t\tthrow new NotSuccessfulContentMigrationError(version, `Mutation ${key} failed: ${errorDetails}`)\n\t\t\t\t\t}\n\t\t\t\t}\n\t\t\t}\n\t\t}\n\t}\n\n\tprivate async validateMigrations(\n\t\tdb: DatabaseContext,\n\t\tschema: Schema,\n\t\tversion: string | null,\n\t\tmigrationsToExecute: readonly MigrationInput[],\n\t\t{ ignoreOrder, skipExecuted }: {\n\t\t\tignoreOrder: boolean\n\t\t\tskipExecuted: boolean\n\t\t},\n\t): Promise<readonly MigrationInput[]> {\n\t\tconst executedMigrations = await this.executedMigrationsResolver.getMigrations(db)\n\t\tconst toExecute: MigrationInput[] = []\n\t\tlet skippedErrors: SchemaValidatorSkippedErrors[] = []\n\t\tfor (const migration of migrationsToExecute) {\n\t\t\tconst executedMigration = executedMigrations.find(it => it.version === migration.version)\n\t\t\tif (executedMigration) {\n\t\t\t\tif (skipExecuted && (migration.type !== 'schema' || executedMigration.checksum === calculateMigrationChecksum(migration))) {\n\t\t\t\t\tcontinue\n\t\t\t\t} else {\n\t\t\t\t\tthrow new AlreadyExecutedMigrationError(migration.version, `Migration is already executed`)\n\t\t\t\t}\n\t\t\t}\n\n\t\t\tif (version && migration.version < version && !ignoreOrder) {\n\t\t\t\tthrow new MustFollowLatestMigrationError(migration.version, `Must follow latest executed migration ${version}`)\n\t\t\t}\n\t\t\tif (migration.type === 'schema') {\n\t\t\t\tconst described = this.migrationDescriber.describeModifications(schema, migration)\n\t\t\t\tif (described.length === 0) {\n\t\t\t\t\tcontinue\n\t\t\t\t}\n\t\t\t\tconst latestModification = described[described.length - 1]\n\t\t\t\tschema = latestModification.schema\n\t\t\t\tskippedErrors = [\n\t\t\t\t\t...skippedErrors.filter(it => it.skipUntil && MigrationVersionHelper.extractVersion(it.skipUntil) >= migration.version),\n\t\t\t\t\t...migration.skippedErrors ?? [],\n\t\t\t\t]\n\t\t\t\tconst errors = SchemaValidator.validate(schema, skippedErrors)\n\t\t\t\tif (errors.length > 0) {\n\t\t\t\t\tthrow new InvalidSchemaError(\n\t\t\t\t\t\tmigration.version,\n\t\t\t\t\t\t'Migration generates invalid schema: \\n' +\n\t\t\t\t\t\terrors.map(it => `${it.path.join('.')}: [${it.code}] ${it.message}`).join('\\n'),\n\t\t\t\t\t)\n\t\t\t\t}\n\t\t\t}\n\n\t\t\ttoExecute.push(migration)\n\t\t}\n\t\t// intentionally not using skippedErrors here\n\t\tconst errors = SchemaValidator.validate(schema)\n\t\tif (errors.length > 0) {\n\t\t\tthrow new InvalidSchemaError(\n\t\t\t\ttoExecute[toExecute.length - 1].version,\n\t\t\t\t'Migration generates invalid schema: \\n' +\n\t\t\t\terrors.map(it => it.path.join('.') + ': ' + it.message).join('\\n'),\n\t\t\t)\n\t\t}\n\t\treturn toExecute\n\t}\n\n\tprivate async applyModification(\n\t\tdb: Client,\n\t\tstages: Stage[],\n\t\tschema: Schema,\n\t\tmodification: Migration.Modification,\n\t\tformatVersion: number,\n\t\tmigrationVersion: string,\n\t\tsystemSchema: string,\n\t\tmetadataStore: SchemaDatabaseMetadataResolverStore,\n\t): Promise<[Schema]> {\n\t\tconst {\n\t\t\tgetSql,\n\t\t\tschema: newSchema,\n\t\t} = this.migrationDescriber.describeModification(schema, modification, { formatVersion })\n\t\tfor (const stage of stages) {\n\t\t\tconst databaseMetadata = await metadataStore.getMetadata(stage.schema)\n\t\t\tconst sql = getSql({\n\t\t\t\tsystemSchema,\n\t\t\t\tdatabaseMetadata,\n\t\t\t\tinvalidateDatabaseMetadata: () => metadataStore.invalidate(stage.schema),\n\t\t\t})\n\t\t\tawait this.executeOnStage(db, stage, sql, migrationVersion)\n\t\t}\n\t\treturn [newSchema]\n\t}\n\n\tprivate async executeOnStage(db: Client, stage: Stage, sql: string, migrationVersion: string) {\n\t\tawait db.query('SET search_path TO ' + wrapIdentifier(stage.schema))\n\t\ttry {\n\t\t\tawait db.query(sql)\n\t\t} catch (e) {\n\t\t\tif (e instanceof QueryError) {\n\t\t\t\tlogger.error(e, { message: 'Migration failed' })\n\t\t\t\tthrow new MigrationFailedError(migrationVersion, e.message)\n\t\t\t}\n\t\t\tthrow e\n\t\t}\n\t}\n}\n\nexport abstract class MigrationError extends Error {\n\tpublic abstract code: MigrateErrorCode\n\n\tconstructor(public readonly version: string, public readonly migrationError: string) {\n\t\tsuper(`${version}: ${migrationError}`)\n\t}\n}\n\nexport class MustFollowLatestMigrationError extends MigrationError {\n\tcode = MigrateErrorCode.MustFollowLatest\n}\n\nexport class AlreadyExecutedMigrationError extends MigrationError {\n\tcode = MigrateErrorCode.AlreadyExecuted\n}\n\nexport class MigrationFailedError extends MigrationError {\n\tcode = MigrateErrorCode.MigrationFailed\n}\n\nexport class InvalidSchemaError extends MigrationError {\n\tcode = MigrateErrorCode.InvalidSchema\n}\n\nexport class FailedContentMigrationError extends MigrationError {\n\tcode = MigrateErrorCode.ContentMigrationFailed\n}\n\nexport class NotSuccessfulContentMigrationError extends MigrationError {\n\tcode = MigrateErrorCode.ContentMigrationNotSuccessful\n}\n"],"names":["SaveMigrationCommand","ImplementationException","SaveSchemaCommand","calculateSchemaChecksum","calculateMigrationChecksum","MigrationVersionHelper","errors","SchemaValidator","wrapIdentifier","QueryError","logger","MigrateErrorCode"],"mappings":";;;;;;;;;;;;;;;AAiBO,MAAM,gBAAgB;AAAA,EAC5B,YACkB,oBACA,gBACA,4BACA,gDACA,sBAChB;AALgB,SAAA,qBAAA;AACA,SAAA,iBAAA;AACA,SAAA,6BAAA;AACA,SAAA,iDAAA;AACA,SAAA,uBAAA;AAAA,EACf;AAAA,EAEH,MAAa,QAAQ,EAAE,IAAI,SAAS,UAAU,SAAS,EAAE,cAAc,OAAO,eAAe,MAAS,GAAA,qBAAqB,UAUxH;AACE,QAAA,oBAAoB,WAAW,GAAG;AACrC;AAAA,IACD;AACA,UAAM,iBAAiB,MAAM,KAAK,eAAe,MAAM,EAAE,IAAI;AAC7D,QAAI,SAAS,eAAe;AACxB,QAAA,KAAK,eAAe,KAAK;AAE7B,UAAM,YAAY,MAAM,KAAK,mBAAmB,IAAI,QAAQ,eAAe,KAAK,WAAW,MAAM,qBAAqB,EAAE,aAAa,aAAc,CAAA;AAC/I,QAAA,UAAU,WAAW,GAAG;AAC3B;AAAA,IACD;AAEA,UAAM,SAAS,CAAC,GAAG,SAAS,EAAE,KAAK,CAAC,GAAG,MAAM,EAAE,QAAQ,cAAc,EAAE,OAAO,CAAC;AAE/E,UAAM,gBAAgB,KAAK,+CAA+C,OAAO,EAAE;AAEnF,eAAW,aAAa,QAAQ;AAE3B,UAAA,UAAU,SAAS,UAAU;AAChC,cAAM,gBAAgB,UAAU;AAErB,mBAAA,gBAAgB,UAAU,eAAe;AAClD,WA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AAOA,MAAiB,iBAAA,sBAAA;AAAA,EAAA;AACzB;AAEO,MAAM,2CAA2C,eAAe;AAAA,EAAhE,cAAA;AAAA,UAAA,GAAA,SAAA;AACN,kBAAA,MAAA,QAAOA,MAAiB,iBAAA,6BAAA;AAAA,EAAA;AACzB;;;;;;;;;"}
1
+ {"version":3,"file":"ProjectMigrator.cjs","sources":["../../../../../../packages/engine-system-api/src/model/migrations/ProjectMigrator.ts"],"sourcesContent":["import { calculateMigrationChecksum, Migration, MigrationDescriber, MigrationVersionHelper } from '@contember/schema-migrations'\nimport { Client, DatabaseMetadata, QueryError, wrapIdentifier } from '@contember/database'\nimport { Schema } from '@contember/schema'\nimport { SaveMigrationCommand } from '../commands'\nimport { Stage } from '../dtos'\nimport { DatabaseContext } from '../database'\nimport { ExecutedMigrationsResolver } from './ExecutedMigrationsResolver'\nimport { MigrateErrorCode } from '../../schema'\nimport { calculateSchemaChecksum, SchemaValidator, SchemaValidatorSkippedErrors } from '@contember/schema-utils'\nimport { logger } from '@contember/logger'\nimport { MigrationsDatabaseMetadataResolverStoreFactory, SchemaDatabaseMetadataResolverStore } from '../metadata'\nimport { ContentMigrationQuery, MigrationInput } from './MigrationInput'\nimport { ContentQueryExecutor } from '../dependencies'\nimport { SchemaProvider } from './SchemaProvider'\nimport { SaveSchemaCommand } from '../commands/schema/SaveSchemaCommand'\nimport { ImplementationException } from '../../utils'\n\nexport class ProjectMigrator {\n\tconstructor(\n\t\tprivate readonly migrationDescriber: MigrationDescriber,\n\t\tprivate readonly schemaProvider: SchemaProvider,\n\t\tprivate readonly executedMigrationsResolver: ExecutedMigrationsResolver,\n\t\tprivate readonly migrationsDatabaseMetadataResolverStoreFactory: MigrationsDatabaseMetadataResolverStoreFactory,\n\t\tprivate readonly contentQueryExecutor: ContentQueryExecutor,\n\t) {}\n\n\tpublic async migrate({ db, project, identity, options: { ignoreOrder = false, skipExecuted = false }, migrationsToExecute, stages }: {\n\t\tdb: DatabaseContext\n\t\tproject: { slug: string; systemSchema: string }\n\t\tidentity: { id: string }\n\t\tstages: Stage[]\n\t\tmigrationsToExecute: readonly MigrationInput[]\n\t\toptions: {\n\t\t\tignoreOrder?: boolean\n\t\t\tskipExecuted?: boolean\n\t\t}\n\t}) {\n\t\tif (migrationsToExecute.length === 0) {\n\t\t\treturn\n\t\t}\n\t\tconst schemaWithMeta = await this.schemaProvider.fetch({ db })\n\t\tlet schema = schemaWithMeta.schema\n\t\tlet id = schemaWithMeta.meta.id\n\n\t\tconst validated = await this.validateMigrations(db, schema, schemaWithMeta.meta.version ?? null, migrationsToExecute, { ignoreOrder, skipExecuted })\n\t\tif (validated.length === 0) {\n\t\t\treturn\n\t\t}\n\n\t\tconst sorted = [...validated].sort((a, b) => a.version.localeCompare(b.version))\n\n\t\tconst metadataStore = this.migrationsDatabaseMetadataResolverStoreFactory.create(db)\n\n\t\tfor (const migration of sorted) {\n\n\t\t\tif (migration.type === 'schema') {\n\t\t\t\tconst formatVersion = migration.formatVersion\n\n\t\t\t\tfor (const modification of migration.modifications) {\n\t\t\t\t\t[schema] = await this.applyModification(\n\t\t\t\t\t\tdb.client,\n\t\t\t\t\t\tstages,\n\t\t\t\t\t\tschema,\n\t\t\t\t\t\tmodification,\n\t\t\t\t\t\tformatVersion,\n\t\t\t\t\t\tmigration.version,\n\t\t\t\t\t\tdb.client.schema,\n\t\t\t\t\t\tmetadataStore,\n\t\t\t\t\t)\n\t\t\t\t}\n\t\t\t} else if (migration.type === 'content') {\n\t\t\t\tif (!id) {\n\t\t\t\t\tthrow new FailedContentMigrationError(migration.version, `Cannot execute content migration without schema`)\n\t\t\t\t}\n\t\t\t\tfor (const query of migration.queries) {\n\t\t\t\t\tawait this.executeContentMigration({\n\t\t\t\t\t\tversion: migration.version,\n\t\t\t\t\t\tquery,\n\t\t\t\t\t\tdb,\n\t\t\t\t\t\tschema,\n\t\t\t\t\t\tschemaMeta: { id },\n\t\t\t\t\t\tstages,\n\t\t\t\t\t\tdatabaseMetadata: await metadataStore.getMetadata(db.client.schema),\n\t\t\t\t\t\tidentity,\n\t\t\t\t\t\tproject,\n\t\t\t\t\t})\n\t\t\t\t}\n\t\t\t\t// event log uses deferred constraint triggers, we need to fire them before ALTER\n\t\t\t\tawait db.client.query(`SET CONSTRAINTS ALL IMMEDIATE`)\n\t\t\t\tawait db.client.query(`SET CONSTRAINTS ALL DEFERRED`)\n\n\t\t\t}\n\t\t\tid = await db.commandBus.execute(new SaveMigrationCommand(migration))\n\t\t}\n\t\tif (!id) {\n\t\t\tthrow new ImplementationException()\n\t\t}\n\n\t\tawait db.commandBus.execute(new SaveSchemaCommand({\n\t\t\tschema,\n\t\t\tmeta: {\n\t\t\t\tid,\n\t\t\t\tupdatedAt: new Date(),\n\t\t\t\tversion: sorted[sorted.length - 1].version,\n\t\t\t\tchecksum: calculateSchemaChecksum(schema),\n\t\t\t},\n\t\t}))\n\t}\n\n\tprivate async executeContentMigration({ query, stages, version, ...ctx }: {\n\t\tversion: string\n\t\tdb: DatabaseContext\n\t\tquery: ContentMigrationQuery\n\t\tstages: Stage[]\n\t\tschema: Schema\n\t\tschemaMeta: { id: number }\n\t\tproject: { slug: string; systemSchema: string }\n\t\tidentity: { id: string }\n\t\tdatabaseMetadata: DatabaseMetadata\n\t}) {\n\t\tconst queryStages = query.stage ? stages.filter(it => it.slug === query.stage) : stages\n\t\tfor (const stage of queryStages) {\n\t\t\tconst response = await this.contentQueryExecutor.execute({\n\t\t\t\tstage,\n\t\t\t\t...ctx,\n\t\t\t}, query)\n\n\t\t\tif (!response.ok) {\n\t\t\t\tthrow new FailedContentMigrationError(version, response.errors.join(', '))\n\t\t\t}\n\t\t\tif (query.checkMutationResult !== false) {\n\t\t\t\tfor (const [key, value] of Object.entries(response.result.data ?? {})) {\n\t\t\t\t\tif (typeof value === 'object' && value !== null && 'ok' in value && !value.ok) {\n\t\t\t\t\t\tconst errorDetails = 'errorMessage' in value ? value.errorMessage : 'No details available. Please fetch errorMessage field.'\n\t\t\t\t\t\tthrow new NotSuccessfulContentMigrationError(version, `Mutation ${key} failed: ${errorDetails}`)\n\t\t\t\t\t}\n\t\t\t\t}\n\t\t\t}\n\t\t}\n\t}\n\n\tprivate async validateMigrations(\n\t\tdb: DatabaseContext,\n\t\tschema: Schema,\n\t\tversion: string | null,\n\t\tmigrationsToExecute: readonly MigrationInput[],\n\t\t{ ignoreOrder, skipExecuted }: {\n\t\t\tignoreOrder: boolean\n\t\t\tskipExecuted: boolean\n\t\t},\n\t): Promise<readonly MigrationInput[]> {\n\t\tconst executedMigrations = await this.executedMigrationsResolver.getMigrations(db)\n\t\tconst toExecute: MigrationInput[] = []\n\t\tlet skippedErrors: SchemaValidatorSkippedErrors[] = []\n\t\tfor (const migration of migrationsToExecute) {\n\t\t\tconst executedMigration = executedMigrations.find(it => it.version === migration.version)\n\t\t\tif (executedMigration) {\n\t\t\t\tif (skipExecuted && (migration.type !== 'schema' || executedMigration.checksum === calculateMigrationChecksum(migration))) {\n\t\t\t\t\tcontinue\n\t\t\t\t} else {\n\t\t\t\t\tthrow new AlreadyExecutedMigrationError(migration.version, `Migration is already executed`)\n\t\t\t\t}\n\t\t\t}\n\n\t\t\tif (version && migration.version < version && !ignoreOrder) {\n\t\t\t\tthrow new MustFollowLatestMigrationError(migration.version, `Must follow latest executed migration ${version}`)\n\t\t\t}\n\t\t\tif (migration.type === 'schema') {\n\t\t\t\tconst described = this.migrationDescriber.describeModifications(schema, migration)\n\t\t\t\tif (described.length === 0) {\n\t\t\t\t\tcontinue\n\t\t\t\t}\n\t\t\t\tconst latestModification = described[described.length - 1]\n\t\t\t\tschema = latestModification.schema\n\t\t\t\tskippedErrors = [\n\t\t\t\t\t...skippedErrors.filter(it => it.skipUntil && MigrationVersionHelper.extractVersion(it.skipUntil) >= migration.version),\n\t\t\t\t\t...migration.skippedErrors ?? [],\n\t\t\t\t]\n\t\t\t\tconst errors = SchemaValidator.validate(schema, skippedErrors)\n\t\t\t\tif (errors.length > 0) {\n\t\t\t\t\tthrow new InvalidSchemaError(\n\t\t\t\t\t\tmigration.version,\n\t\t\t\t\t\t'Migration generates invalid schema: \\n' +\n\t\t\t\t\t\terrors.map(it => `${it.path.join('.')}: [${it.code}] ${it.message}`).join('\\n'),\n\t\t\t\t\t)\n\t\t\t\t}\n\t\t\t}\n\n\t\t\ttoExecute.push(migration)\n\t\t}\n\t\t// intentionally not using skippedErrors here\n\t\tconst errors = SchemaValidator.validate(schema)\n\t\tif (errors.length > 0) {\n\t\t\tthrow new InvalidSchemaError(\n\t\t\t\ttoExecute[toExecute.length - 1].version,\n\t\t\t\t'Migration generates invalid schema: \\n' +\n\t\t\t\terrors.map(it => it.path.join('.') + ': ' + it.message).join('\\n'),\n\t\t\t)\n\t\t}\n\t\treturn toExecute\n\t}\n\n\tprivate async applyModification(\n\t\tdb: Client,\n\t\tstages: Stage[],\n\t\tschema: Schema,\n\t\tmodification: Migration.Modification,\n\t\tformatVersion: number,\n\t\tmigrationVersion: string,\n\t\tsystemSchema: string,\n\t\tmetadataStore: SchemaDatabaseMetadataResolverStore,\n\t): Promise<[Schema]> {\n\t\tconst {\n\t\t\tgetSql,\n\t\t\tschema: newSchema,\n\t\t} = this.migrationDescriber.describeModification(schema, modification, { formatVersion })\n\t\tfor (const stage of stages) {\n\t\t\tconst databaseMetadata = await metadataStore.getMetadata(stage.schema)\n\t\t\tconst sql = getSql({\n\t\t\t\tsystemSchema,\n\t\t\t\tdatabaseMetadata,\n\t\t\t\tinvalidateDatabaseMetadata: () => metadataStore.invalidate(stage.schema),\n\t\t\t})\n\t\t\tawait this.executeOnStage(db, stage, sql, migrationVersion)\n\t\t}\n\t\treturn [newSchema]\n\t}\n\n\tprivate async executeOnStage(db: Client, stage: Stage, sql: string, migrationVersion: string) {\n\t\tawait db.query('SET search_path TO ' + wrapIdentifier(stage.schema))\n\t\ttry {\n\t\t\tawait db.query(sql)\n\t\t} catch (e) {\n\t\t\tif (e instanceof QueryError) {\n\t\t\t\tlogger.error(e, { message: 'Migration failed' })\n\t\t\t\tthrow new MigrationFailedError(migrationVersion, e.message)\n\t\t\t}\n\t\t\tthrow e\n\t\t}\n\t}\n}\n\nexport abstract class MigrationError extends Error {\n\tpublic abstract code: MigrateErrorCode\n\n\tconstructor(public readonly version: string, public readonly migrationError: string) {\n\t\tsuper(`${version}: ${migrationError}`)\n\t}\n}\n\nexport class MustFollowLatestMigrationError extends MigrationError {\n\tcode = MigrateErrorCode.MustFollowLatest\n}\n\nexport class AlreadyExecutedMigrationError extends MigrationError {\n\tcode = MigrateErrorCode.AlreadyExecuted\n}\n\nexport class MigrationFailedError extends MigrationError {\n\tcode = MigrateErrorCode.MigrationFailed\n}\n\nexport class InvalidSchemaError extends MigrationError {\n\tcode = MigrateErrorCode.InvalidSchema\n}\n\nexport class FailedContentMigrationError extends MigrationError {\n\tcode = MigrateErrorCode.ContentMigrationFailed\n}\n\nexport class NotSuccessfulContentMigrationError extends MigrationError {\n\tcode = MigrateErrorCode.ContentMigrationNotSuccessful\n}\n"],"names":["SaveMigrationCommand","ImplementationException","SaveSchemaCommand","calculateSchemaChecksum","calculateMigrationChecksum","MigrationVersionHelper","errors","SchemaValidator","wrapIdentifier","QueryError","logger","MigrateErrorCode"],"mappings":";;;;;;;;;;;;;;;AAiBO,MAAM,gBAAgB;AAAA,EAC5B,YACkB,oBACA,gBACA,4BACA,gDACA,sBAChB;AALgB,SAAA,qBAAA;AACA,SAAA,iBAAA;AACA,SAAA,6BAAA;AACA,SAAA,iDAAA;AACA,SAAA,uBAAA;AAAA,EAAA;AAAA,EAGlB,MAAa,QAAQ,EAAE,IAAI,SAAS,UAAU,SAAS,EAAE,cAAc,OAAO,eAAe,MAAS,GAAA,qBAAqB,UAUxH;AACE,QAAA,oBAAoB,WAAW,GAAG;AACrC;AAAA,IAAA;AAED,UAAM,iBAAiB,MAAM,KAAK,eAAe,MAAM,EAAE,IAAI;AAC7D,QAAI,SAAS,eAAe;AACxB,QAAA,KAAK,eAAe,KAAK;AAE7B,UAAM,YAAY,MAAM,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SAAA;AACN,kBAAA,MAAA,QAAOA,MAAAA,iBAAiB,eAAA;AAAA,EAAA;AACzB;AAEO,MAAM,6BAA6B,eAAe;AAAA,EAAlD,cAAA;AAAA,UAAA,GAAA,SAAA;AACN,kBAAA,MAAA,QAAOA,MAAAA,iBAAiB,eAAA;AAAA,EAAA;AACzB;AAEO,MAAM,2BAA2B,eAAe;AAAA,EAAhD,cAAA;AAAA,UAAA,GAAA,SAAA;AACN,kBAAA,MAAA,QAAOA,MAAAA,iBAAiB,aAAA;AAAA,EAAA;AACzB;AAEO,MAAM,oCAAoC,eAAe;AAAA,EAAzD,cAAA;AAAA,UAAA,GAAA,SAAA;AACN,kBAAA,MAAA,QAAOA,MAAAA,iBAAiB,sBAAA;AAAA,EAAA;AACzB;AAEO,MAAM,2CAA2C,eAAe;AAAA,EAAhE,cAAA;AAAA,UAAA,GAAA,SAAA;AACN,kBAAA,MAAA,QAAOA,MAAAA,iBAAiB,6BAAA;AAAA,EAAA;AACzB;;;;;;;;;"}
@@ -1 +1 @@
1
- {"version":3,"file":"ProjectMigrator.js","sources":["../../../../../../packages/engine-system-api/src/model/migrations/ProjectMigrator.ts"],"sourcesContent":["import { calculateMigrationChecksum, Migration, MigrationDescriber, MigrationVersionHelper } from '@contember/schema-migrations'\nimport { Client, DatabaseMetadata, QueryError, wrapIdentifier } from '@contember/database'\nimport { Schema } from '@contember/schema'\nimport { SaveMigrationCommand } from '../commands'\nimport { Stage } from '../dtos'\nimport { DatabaseContext } from '../database'\nimport { ExecutedMigrationsResolver } from './ExecutedMigrationsResolver'\nimport { MigrateErrorCode } from '../../schema'\nimport { calculateSchemaChecksum, SchemaValidator, SchemaValidatorSkippedErrors } from '@contember/schema-utils'\nimport { logger } from '@contember/logger'\nimport { MigrationsDatabaseMetadataResolverStoreFactory, SchemaDatabaseMetadataResolverStore } from '../metadata'\nimport { ContentMigrationQuery, MigrationInput } from './MigrationInput'\nimport { ContentQueryExecutor } from '../dependencies'\nimport { SchemaProvider } from './SchemaProvider'\nimport { SaveSchemaCommand } from '../commands/schema/SaveSchemaCommand'\nimport { ImplementationException } from '../../utils'\n\nexport class ProjectMigrator {\n\tconstructor(\n\t\tprivate readonly migrationDescriber: MigrationDescriber,\n\t\tprivate readonly schemaProvider: SchemaProvider,\n\t\tprivate readonly executedMigrationsResolver: ExecutedMigrationsResolver,\n\t\tprivate readonly migrationsDatabaseMetadataResolverStoreFactory: MigrationsDatabaseMetadataResolverStoreFactory,\n\t\tprivate readonly contentQueryExecutor: ContentQueryExecutor,\n\t) {}\n\n\tpublic async migrate({ db, project, identity, options: { ignoreOrder = false, skipExecuted = false }, migrationsToExecute, stages }: {\n\t\tdb: DatabaseContext\n\t\tproject: { slug: string; systemSchema: string }\n\t\tidentity: { id: string }\n\t\tstages: Stage[]\n\t\tmigrationsToExecute: readonly MigrationInput[]\n\t\toptions: {\n\t\t\tignoreOrder?: boolean\n\t\t\tskipExecuted?: boolean\n\t\t}\n\t}) {\n\t\tif (migrationsToExecute.length === 0) {\n\t\t\treturn\n\t\t}\n\t\tconst schemaWithMeta = await this.schemaProvider.fetch({ db })\n\t\tlet schema = schemaWithMeta.schema\n\t\tlet id = schemaWithMeta.meta.id\n\n\t\tconst validated = await this.validateMigrations(db, schema, schemaWithMeta.meta.version ?? null, migrationsToExecute, { ignoreOrder, skipExecuted })\n\t\tif (validated.length === 0) {\n\t\t\treturn\n\t\t}\n\n\t\tconst sorted = [...validated].sort((a, b) => a.version.localeCompare(b.version))\n\n\t\tconst metadataStore = this.migrationsDatabaseMetadataResolverStoreFactory.create(db)\n\n\t\tfor (const migration of sorted) {\n\n\t\t\tif (migration.type === 'schema') {\n\t\t\t\tconst formatVersion = migration.formatVersion\n\n\t\t\t\tfor (const modification of migration.modifications) {\n\t\t\t\t\t[schema] = await this.applyModification(\n\t\t\t\t\t\tdb.client,\n\t\t\t\t\t\tstages,\n\t\t\t\t\t\tschema,\n\t\t\t\t\t\tmodification,\n\t\t\t\t\t\tformatVersion,\n\t\t\t\t\t\tmigration.version,\n\t\t\t\t\t\tdb.client.schema,\n\t\t\t\t\t\tmetadataStore,\n\t\t\t\t\t)\n\t\t\t\t}\n\t\t\t} else if (migration.type === 'content') {\n\t\t\t\tif (!id) {\n\t\t\t\t\tthrow new FailedContentMigrationError(migration.version, `Cannot execute content migration without schema`)\n\t\t\t\t}\n\t\t\t\tfor (const query of migration.queries) {\n\t\t\t\t\tawait this.executeContentMigration({\n\t\t\t\t\t\tversion: migration.version,\n\t\t\t\t\t\tquery,\n\t\t\t\t\t\tdb,\n\t\t\t\t\t\tschema,\n\t\t\t\t\t\tschemaMeta: { id },\n\t\t\t\t\t\tstages,\n\t\t\t\t\t\tdatabaseMetadata: await metadataStore.getMetadata(db.client.schema),\n\t\t\t\t\t\tidentity,\n\t\t\t\t\t\tproject,\n\t\t\t\t\t})\n\t\t\t\t}\n\t\t\t\t// event log uses deferred constraint triggers, we need to fire them before ALTER\n\t\t\t\tawait db.client.query(`SET CONSTRAINTS ALL IMMEDIATE`)\n\t\t\t\tawait db.client.query(`SET CONSTRAINTS ALL DEFERRED`)\n\n\t\t\t}\n\t\t\tid = await db.commandBus.execute(new SaveMigrationCommand(migration))\n\t\t}\n\t\tif (!id) {\n\t\t\tthrow new ImplementationException()\n\t\t}\n\n\t\tawait db.commandBus.execute(new SaveSchemaCommand({\n\t\t\tschema,\n\t\t\tmeta: {\n\t\t\t\tid,\n\t\t\t\tupdatedAt: new Date(),\n\t\t\t\tversion: sorted[sorted.length - 1].version,\n\t\t\t\tchecksum: calculateSchemaChecksum(schema),\n\t\t\t},\n\t\t}))\n\t}\n\n\tprivate async executeContentMigration({ query, stages, version, ...ctx }: {\n\t\tversion: string\n\t\tdb: DatabaseContext\n\t\tquery: ContentMigrationQuery\n\t\tstages: Stage[]\n\t\tschema: Schema\n\t\tschemaMeta: { id: number }\n\t\tproject: { slug: string; systemSchema: string }\n\t\tidentity: { id: string }\n\t\tdatabaseMetadata: DatabaseMetadata\n\t}) {\n\t\tconst queryStages = query.stage ? stages.filter(it => it.slug === query.stage) : stages\n\t\tfor (const stage of queryStages) {\n\t\t\tconst response = await this.contentQueryExecutor.execute({\n\t\t\t\tstage,\n\t\t\t\t...ctx,\n\t\t\t}, query)\n\n\t\t\tif (!response.ok) {\n\t\t\t\tthrow new FailedContentMigrationError(version, response.errors.join(', '))\n\t\t\t}\n\t\t\tif (query.checkMutationResult !== false) {\n\t\t\t\tfor (const [key, value] of Object.entries(response.result.data ?? {})) {\n\t\t\t\t\tif (typeof value === 'object' && value !== null && 'ok' in value && !value.ok) {\n\t\t\t\t\t\tconst errorDetails = 'errorMessage' in value ? value.errorMessage : 'No details available. Please fetch errorMessage field.'\n\t\t\t\t\t\tthrow new NotSuccessfulContentMigrationError(version, `Mutation ${key} failed: ${errorDetails}`)\n\t\t\t\t\t}\n\t\t\t\t}\n\t\t\t}\n\t\t}\n\t}\n\n\tprivate async validateMigrations(\n\t\tdb: DatabaseContext,\n\t\tschema: Schema,\n\t\tversion: string | null,\n\t\tmigrationsToExecute: readonly MigrationInput[],\n\t\t{ ignoreOrder, skipExecuted }: {\n\t\t\tignoreOrder: boolean\n\t\t\tskipExecuted: boolean\n\t\t},\n\t): Promise<readonly MigrationInput[]> {\n\t\tconst executedMigrations = await this.executedMigrationsResolver.getMigrations(db)\n\t\tconst toExecute: MigrationInput[] = []\n\t\tlet skippedErrors: SchemaValidatorSkippedErrors[] = []\n\t\tfor (const migration of migrationsToExecute) {\n\t\t\tconst executedMigration = executedMigrations.find(it => it.version === migration.version)\n\t\t\tif (executedMigration) {\n\t\t\t\tif (skipExecuted && (migration.type !== 'schema' || executedMigration.checksum === calculateMigrationChecksum(migration))) {\n\t\t\t\t\tcontinue\n\t\t\t\t} else {\n\t\t\t\t\tthrow new AlreadyExecutedMigrationError(migration.version, `Migration is already executed`)\n\t\t\t\t}\n\t\t\t}\n\n\t\t\tif (version && migration.version < version && !ignoreOrder) {\n\t\t\t\tthrow new MustFollowLatestMigrationError(migration.version, `Must follow latest executed migration ${version}`)\n\t\t\t}\n\t\t\tif (migration.type === 'schema') {\n\t\t\t\tconst described = this.migrationDescriber.describeModifications(schema, migration)\n\t\t\t\tif (described.length === 0) {\n\t\t\t\t\tcontinue\n\t\t\t\t}\n\t\t\t\tconst latestModification = described[described.length - 1]\n\t\t\t\tschema = latestModification.schema\n\t\t\t\tskippedErrors = [\n\t\t\t\t\t...skippedErrors.filter(it => it.skipUntil && MigrationVersionHelper.extractVersion(it.skipUntil) >= migration.version),\n\t\t\t\t\t...migration.skippedErrors ?? [],\n\t\t\t\t]\n\t\t\t\tconst errors = SchemaValidator.validate(schema, skippedErrors)\n\t\t\t\tif (errors.length > 0) {\n\t\t\t\t\tthrow new InvalidSchemaError(\n\t\t\t\t\t\tmigration.version,\n\t\t\t\t\t\t'Migration generates invalid schema: \\n' +\n\t\t\t\t\t\terrors.map(it => `${it.path.join('.')}: [${it.code}] ${it.message}`).join('\\n'),\n\t\t\t\t\t)\n\t\t\t\t}\n\t\t\t}\n\n\t\t\ttoExecute.push(migration)\n\t\t}\n\t\t// intentionally not using skippedErrors here\n\t\tconst errors = SchemaValidator.validate(schema)\n\t\tif (errors.length > 0) {\n\t\t\tthrow new InvalidSchemaError(\n\t\t\t\ttoExecute[toExecute.length - 1].version,\n\t\t\t\t'Migration generates invalid schema: \\n' +\n\t\t\t\terrors.map(it => it.path.join('.') + ': ' + it.message).join('\\n'),\n\t\t\t)\n\t\t}\n\t\treturn toExecute\n\t}\n\n\tprivate async applyModification(\n\t\tdb: Client,\n\t\tstages: Stage[],\n\t\tschema: Schema,\n\t\tmodification: Migration.Modification,\n\t\tformatVersion: number,\n\t\tmigrationVersion: string,\n\t\tsystemSchema: string,\n\t\tmetadataStore: SchemaDatabaseMetadataResolverStore,\n\t): Promise<[Schema]> {\n\t\tconst {\n\t\t\tgetSql,\n\t\t\tschema: newSchema,\n\t\t} = this.migrationDescriber.describeModification(schema, modification, { formatVersion })\n\t\tfor (const stage of stages) {\n\t\t\tconst databaseMetadata = await metadataStore.getMetadata(stage.schema)\n\t\t\tconst sql = getSql({\n\t\t\t\tsystemSchema,\n\t\t\t\tdatabaseMetadata,\n\t\t\t\tinvalidateDatabaseMetadata: () => metadataStore.invalidate(stage.schema),\n\t\t\t})\n\t\t\tawait this.executeOnStage(db, stage, sql, migrationVersion)\n\t\t}\n\t\treturn [newSchema]\n\t}\n\n\tprivate async executeOnStage(db: Client, stage: Stage, sql: string, migrationVersion: string) {\n\t\tawait db.query('SET search_path TO ' + wrapIdentifier(stage.schema))\n\t\ttry {\n\t\t\tawait db.query(sql)\n\t\t} catch (e) {\n\t\t\tif (e instanceof QueryError) {\n\t\t\t\tlogger.error(e, { message: 'Migration failed' })\n\t\t\t\tthrow new MigrationFailedError(migrationVersion, e.message)\n\t\t\t}\n\t\t\tthrow e\n\t\t}\n\t}\n}\n\nexport abstract class MigrationError extends Error {\n\tpublic abstract code: MigrateErrorCode\n\n\tconstructor(public readonly version: string, public readonly migrationError: string) {\n\t\tsuper(`${version}: ${migrationError}`)\n\t}\n}\n\nexport class MustFollowLatestMigrationError extends MigrationError {\n\tcode = MigrateErrorCode.MustFollowLatest\n}\n\nexport class AlreadyExecutedMigrationError extends MigrationError {\n\tcode = MigrateErrorCode.AlreadyExecuted\n}\n\nexport class MigrationFailedError extends MigrationError {\n\tcode = MigrateErrorCode.MigrationFailed\n}\n\nexport class InvalidSchemaError extends MigrationError {\n\tcode = MigrateErrorCode.InvalidSchema\n}\n\nexport class FailedContentMigrationError extends MigrationError {\n\tcode = MigrateErrorCode.ContentMigrationFailed\n}\n\nexport class NotSuccessfulContentMigrationError extends MigrationError {\n\tcode = MigrateErrorCode.ContentMigrationNotSuccessful\n}\n"],"names":["errors"],"mappings":";;;;;;;;;;;;;AAiBO,MAAM,gBAAgB;AAAA,EAC5B,YACkB,oBACA,gBACA,4BACA,gDACA,sBAChB;AALgB,SAAA,qBAAA;AACA,SAAA,iBAAA;AACA,SAAA,6BAAA;AACA,SAAA,iDAAA;AAC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SAAA,iBAAA;AAAA,EAE7D;AACD;AAEO,MAAM,uCAAuC,eAAe;AAAA,EAA5D,cAAA;AAAA,UAAA,GAAA,SAAA;AACN,kBAAA,MAAA,QAAO,iBAAiB,gBAAA;AAAA,EAAA;AACzB;AAEO,MAAM,sCAAsC,eAAe;AAAA,EAA3D,cAAA;AAAA,UAAA,GAAA,SAAA;AACN,kBAAA,MAAA,QAAO,iBAAiB,eAAA;AAAA,EAAA;AACzB;AAEO,MAAM,6BAA6B,eAAe;AAAA,EAAlD,cAAA;AAAA,UAAA,GAAA,SAAA;AACN,kBAAA,MAAA,QAAO,iBAAiB,eAAA;AAAA,EAAA;AACzB;AAEO,MAAM,2BAA2B,eAAe;AAAA,EAAhD,cAAA;AAAA,UAAA,GAAA,SAAA;AACN,kBAAA,MAAA,QAAO,iBAAiB,aAAA;AAAA,EAAA;AACzB;AAEO,MAAM,oCAAoC,eAAe;AAAA,EAAzD,cAAA;AAAA,UAAA,GAAA,SAAA;AACN,kBAAA,MAAA,QAAO,iBAAiB,sBAAA;AAAA,EAAA;AACzB;AAEO,MAAM,2CAA2C,eAAe;AAAA,EAAhE,cAAA;AAAA,UAAA,GAAA,SAAA;AACN,kBAAA,MAAA,QAAO,iBAAiB,6BAAA;AAAA,EAAA;AACzB;"}
1
+ {"version":3,"file":"ProjectMigrator.js","sources":["../../../../../../packages/engine-system-api/src/model/migrations/ProjectMigrator.ts"],"sourcesContent":["import { calculateMigrationChecksum, Migration, MigrationDescriber, MigrationVersionHelper } from '@contember/schema-migrations'\nimport { Client, DatabaseMetadata, QueryError, wrapIdentifier } from '@contember/database'\nimport { Schema } from '@contember/schema'\nimport { SaveMigrationCommand } from '../commands'\nimport { Stage } from '../dtos'\nimport { DatabaseContext } from '../database'\nimport { ExecutedMigrationsResolver } from './ExecutedMigrationsResolver'\nimport { MigrateErrorCode } from '../../schema'\nimport { calculateSchemaChecksum, SchemaValidator, SchemaValidatorSkippedErrors } from '@contember/schema-utils'\nimport { logger } from '@contember/logger'\nimport { MigrationsDatabaseMetadataResolverStoreFactory, SchemaDatabaseMetadataResolverStore } from '../metadata'\nimport { ContentMigrationQuery, MigrationInput } from './MigrationInput'\nimport { ContentQueryExecutor } from '../dependencies'\nimport { SchemaProvider } from './SchemaProvider'\nimport { SaveSchemaCommand } from '../commands/schema/SaveSchemaCommand'\nimport { ImplementationException } from '../../utils'\n\nexport class ProjectMigrator {\n\tconstructor(\n\t\tprivate readonly migrationDescriber: MigrationDescriber,\n\t\tprivate readonly schemaProvider: SchemaProvider,\n\t\tprivate readonly executedMigrationsResolver: ExecutedMigrationsResolver,\n\t\tprivate readonly migrationsDatabaseMetadataResolverStoreFactory: MigrationsDatabaseMetadataResolverStoreFactory,\n\t\tprivate readonly contentQueryExecutor: ContentQueryExecutor,\n\t) {}\n\n\tpublic async migrate({ db, project, identity, options: { ignoreOrder = false, skipExecuted = false }, migrationsToExecute, stages }: {\n\t\tdb: DatabaseContext\n\t\tproject: { slug: string; systemSchema: string }\n\t\tidentity: { id: string }\n\t\tstages: Stage[]\n\t\tmigrationsToExecute: readonly MigrationInput[]\n\t\toptions: {\n\t\t\tignoreOrder?: boolean\n\t\t\tskipExecuted?: boolean\n\t\t}\n\t}) {\n\t\tif (migrationsToExecute.length === 0) {\n\t\t\treturn\n\t\t}\n\t\tconst schemaWithMeta = await this.schemaProvider.fetch({ db })\n\t\tlet schema = schemaWithMeta.schema\n\t\tlet id = schemaWithMeta.meta.id\n\n\t\tconst validated = await this.validateMigrations(db, schema, schemaWithMeta.meta.version ?? null, migrationsToExecute, { ignoreOrder, skipExecuted })\n\t\tif (validated.length === 0) {\n\t\t\treturn\n\t\t}\n\n\t\tconst sorted = [...validated].sort((a, b) => a.version.localeCompare(b.version))\n\n\t\tconst metadataStore = this.migrationsDatabaseMetadataResolverStoreFactory.create(db)\n\n\t\tfor (const migration of sorted) {\n\n\t\t\tif (migration.type === 'schema') {\n\t\t\t\tconst formatVersion = migration.formatVersion\n\n\t\t\t\tfor (const modification of migration.modifications) {\n\t\t\t\t\t[schema] = await this.applyModification(\n\t\t\t\t\t\tdb.client,\n\t\t\t\t\t\tstages,\n\t\t\t\t\t\tschema,\n\t\t\t\t\t\tmodification,\n\t\t\t\t\t\tformatVersion,\n\t\t\t\t\t\tmigration.version,\n\t\t\t\t\t\tdb.client.schema,\n\t\t\t\t\t\tmetadataStore,\n\t\t\t\t\t)\n\t\t\t\t}\n\t\t\t} else if (migration.type === 'content') {\n\t\t\t\tif (!id) {\n\t\t\t\t\tthrow new FailedContentMigrationError(migration.version, `Cannot execute content migration without schema`)\n\t\t\t\t}\n\t\t\t\tfor (const query of migration.queries) {\n\t\t\t\t\tawait this.executeContentMigration({\n\t\t\t\t\t\tversion: migration.version,\n\t\t\t\t\t\tquery,\n\t\t\t\t\t\tdb,\n\t\t\t\t\t\tschema,\n\t\t\t\t\t\tschemaMeta: { id },\n\t\t\t\t\t\tstages,\n\t\t\t\t\t\tdatabaseMetadata: await metadataStore.getMetadata(db.client.schema),\n\t\t\t\t\t\tidentity,\n\t\t\t\t\t\tproject,\n\t\t\t\t\t})\n\t\t\t\t}\n\t\t\t\t// event log uses deferred constraint triggers, we need to fire them before ALTER\n\t\t\t\tawait db.client.query(`SET CONSTRAINTS ALL IMMEDIATE`)\n\t\t\t\tawait db.client.query(`SET CONSTRAINTS ALL DEFERRED`)\n\n\t\t\t}\n\t\t\tid = await db.commandBus.execute(new SaveMigrationCommand(migration))\n\t\t}\n\t\tif (!id) {\n\t\t\tthrow new ImplementationException()\n\t\t}\n\n\t\tawait db.commandBus.execute(new SaveSchemaCommand({\n\t\t\tschema,\n\t\t\tmeta: {\n\t\t\t\tid,\n\t\t\t\tupdatedAt: new Date(),\n\t\t\t\tversion: sorted[sorted.length - 1].version,\n\t\t\t\tchecksum: calculateSchemaChecksum(schema),\n\t\t\t},\n\t\t}))\n\t}\n\n\tprivate async executeContentMigration({ query, stages, version, ...ctx }: {\n\t\tversion: string\n\t\tdb: DatabaseContext\n\t\tquery: ContentMigrationQuery\n\t\tstages: Stage[]\n\t\tschema: Schema\n\t\tschemaMeta: { id: number }\n\t\tproject: { slug: string; systemSchema: string }\n\t\tidentity: { id: string }\n\t\tdatabaseMetadata: DatabaseMetadata\n\t}) {\n\t\tconst queryStages = query.stage ? stages.filter(it => it.slug === query.stage) : stages\n\t\tfor (const stage of queryStages) {\n\t\t\tconst response = await this.contentQueryExecutor.execute({\n\t\t\t\tstage,\n\t\t\t\t...ctx,\n\t\t\t}, query)\n\n\t\t\tif (!response.ok) {\n\t\t\t\tthrow new FailedContentMigrationError(version, response.errors.join(', '))\n\t\t\t}\n\t\t\tif (query.checkMutationResult !== false) {\n\t\t\t\tfor (const [key, value] of Object.entries(response.result.data ?? {})) {\n\t\t\t\t\tif (typeof value === 'object' && value !== null && 'ok' in value && !value.ok) {\n\t\t\t\t\t\tconst errorDetails = 'errorMessage' in value ? value.errorMessage : 'No details available. Please fetch errorMessage field.'\n\t\t\t\t\t\tthrow new NotSuccessfulContentMigrationError(version, `Mutation ${key} failed: ${errorDetails}`)\n\t\t\t\t\t}\n\t\t\t\t}\n\t\t\t}\n\t\t}\n\t}\n\n\tprivate async validateMigrations(\n\t\tdb: DatabaseContext,\n\t\tschema: Schema,\n\t\tversion: string | null,\n\t\tmigrationsToExecute: readonly MigrationInput[],\n\t\t{ ignoreOrder, skipExecuted }: {\n\t\t\tignoreOrder: boolean\n\t\t\tskipExecuted: boolean\n\t\t},\n\t): Promise<readonly MigrationInput[]> {\n\t\tconst executedMigrations = await this.executedMigrationsResolver.getMigrations(db)\n\t\tconst toExecute: MigrationInput[] = []\n\t\tlet skippedErrors: SchemaValidatorSkippedErrors[] = []\n\t\tfor (const migration of migrationsToExecute) {\n\t\t\tconst executedMigration = executedMigrations.find(it => it.version === migration.version)\n\t\t\tif (executedMigration) {\n\t\t\t\tif (skipExecuted && (migration.type !== 'schema' || executedMigration.checksum === calculateMigrationChecksum(migration))) {\n\t\t\t\t\tcontinue\n\t\t\t\t} else {\n\t\t\t\t\tthrow new AlreadyExecutedMigrationError(migration.version, `Migration is already executed`)\n\t\t\t\t}\n\t\t\t}\n\n\t\t\tif (version && migration.version < version && !ignoreOrder) {\n\t\t\t\tthrow new MustFollowLatestMigrationError(migration.version, `Must follow latest executed migration ${version}`)\n\t\t\t}\n\t\t\tif (migration.type === 'schema') {\n\t\t\t\tconst described = this.migrationDescriber.describeModifications(schema, migration)\n\t\t\t\tif (described.length === 0) {\n\t\t\t\t\tcontinue\n\t\t\t\t}\n\t\t\t\tconst latestModification = described[described.length - 1]\n\t\t\t\tschema = latestModification.schema\n\t\t\t\tskippedErrors = [\n\t\t\t\t\t...skippedErrors.filter(it => it.skipUntil && MigrationVersionHelper.extractVersion(it.skipUntil) >= migration.version),\n\t\t\t\t\t...migration.skippedErrors ?? [],\n\t\t\t\t]\n\t\t\t\tconst errors = SchemaValidator.validate(schema, skippedErrors)\n\t\t\t\tif (errors.length > 0) {\n\t\t\t\t\tthrow new InvalidSchemaError(\n\t\t\t\t\t\tmigration.version,\n\t\t\t\t\t\t'Migration generates invalid schema: \\n' +\n\t\t\t\t\t\terrors.map(it => `${it.path.join('.')}: [${it.code}] ${it.message}`).join('\\n'),\n\t\t\t\t\t)\n\t\t\t\t}\n\t\t\t}\n\n\t\t\ttoExecute.push(migration)\n\t\t}\n\t\t// intentionally not using skippedErrors here\n\t\tconst errors = SchemaValidator.validate(schema)\n\t\tif (errors.length > 0) {\n\t\t\tthrow new InvalidSchemaError(\n\t\t\t\ttoExecute[toExecute.length - 1].version,\n\t\t\t\t'Migration generates invalid schema: \\n' +\n\t\t\t\terrors.map(it => it.path.join('.') + ': ' + it.message).join('\\n'),\n\t\t\t)\n\t\t}\n\t\treturn toExecute\n\t}\n\n\tprivate async applyModification(\n\t\tdb: Client,\n\t\tstages: Stage[],\n\t\tschema: Schema,\n\t\tmodification: Migration.Modification,\n\t\tformatVersion: number,\n\t\tmigrationVersion: string,\n\t\tsystemSchema: string,\n\t\tmetadataStore: SchemaDatabaseMetadataResolverStore,\n\t): Promise<[Schema]> {\n\t\tconst {\n\t\t\tgetSql,\n\t\t\tschema: newSchema,\n\t\t} = this.migrationDescriber.describeModification(schema, modification, { formatVersion })\n\t\tfor (const stage of stages) {\n\t\t\tconst databaseMetadata = await metadataStore.getMetadata(stage.schema)\n\t\t\tconst sql = getSql({\n\t\t\t\tsystemSchema,\n\t\t\t\tdatabaseMetadata,\n\t\t\t\tinvalidateDatabaseMetadata: () => metadataStore.invalidate(stage.schema),\n\t\t\t})\n\t\t\tawait this.executeOnStage(db, stage, sql, migrationVersion)\n\t\t}\n\t\treturn [newSchema]\n\t}\n\n\tprivate async executeOnStage(db: Client, stage: Stage, sql: string, migrationVersion: string) {\n\t\tawait db.query('SET search_path TO ' + wrapIdentifier(stage.schema))\n\t\ttry {\n\t\t\tawait db.query(sql)\n\t\t} catch (e) {\n\t\t\tif (e instanceof QueryError) {\n\t\t\t\tlogger.error(e, { message: 'Migration failed' })\n\t\t\t\tthrow new MigrationFailedError(migrationVersion, e.message)\n\t\t\t}\n\t\t\tthrow e\n\t\t}\n\t}\n}\n\nexport abstract class MigrationError extends Error {\n\tpublic abstract code: MigrateErrorCode\n\n\tconstructor(public readonly version: string, public readonly migrationError: string) {\n\t\tsuper(`${version}: ${migrationError}`)\n\t}\n}\n\nexport class MustFollowLatestMigrationError extends MigrationError {\n\tcode = MigrateErrorCode.MustFollowLatest\n}\n\nexport class AlreadyExecutedMigrationError extends MigrationError {\n\tcode = MigrateErrorCode.AlreadyExecuted\n}\n\nexport class MigrationFailedError extends MigrationError {\n\tcode = MigrateErrorCode.MigrationFailed\n}\n\nexport class InvalidSchemaError extends MigrationError {\n\tcode = MigrateErrorCode.InvalidSchema\n}\n\nexport class FailedContentMigrationError extends MigrationError {\n\tcode = MigrateErrorCode.ContentMigrationFailed\n}\n\nexport class NotSuccessfulContentMigrationError extends MigrationError {\n\tcode = MigrateErrorCode.ContentMigrationNotSuccessful\n}\n"],"names":["errors"],"mappings":";;;;;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AErD,YAAA;AAAA,IAAA;AAAA,EACP;AAEF;AAEO,MAAe,uBAAuB,MAAM;AAAA,EAGlD,YAA4B,SAAiC,gBAAwB;AACpF,UAAM,GAAG,OAAO,KAAK,cAAc,EAAE;AADV,SAAA,UAAA;AAAiC,SAAA,iBAAA;AAAA,EAAA;AAG9D;AAEO,MAAM,uCAAuC,eAAe;AAAA,EAA5D,cAAA;AAAA,UAAA,GAAA,SAAA;AACN,kBAAA,MAAA,QAAO,iBAAiB,gBAAA;AAAA,EAAA;AACzB;AAEO,MAAM,sCAAsC,eAAe;AAAA,EAA3D,cAAA;AAAA,UAAA,GAAA,SAAA;AACN,kBAAA,MAAA,QAAO,iBAAiB,eAAA;AAAA,EAAA;AACzB;AAEO,MAAM,6BAA6B,eAAe;AAAA,EAAlD,cAAA;AAAA,UAAA,GAAA,SAAA;AACN,kBAAA,MAAA,QAAO,iBAAiB,eAAA;AAAA,EAAA;AACzB;AAEO,MAAM,2BAA2B,eAAe;AAAA,EAAhD,cAAA;AAAA,UAAA,GAAA,SAAA;AACN,kBAAA,MAAA,QAAO,iBAAiB,aAAA;AAAA,EAAA;AACzB;AAEO,MAAM,oCAAoC,eAAe;AAAA,EAAzD,cAAA;AAAA,UAAA,GAAA,SAAA;AACN,kBAAA,MAAA,QAAO,iBAAiB,sBAAA;AAAA,EAAA;AACzB;AAEO,MAAM,2CAA2C,eAAe;AAAA,EAAhE,cAAA;AAAA,UAAA,GAAA,SAAA;AACN,kBAAA,MAAA,QAAO,iBAAiB,6BAAA;AAAA,EAAA;AACzB;"}
@@ -1 +1 @@
1
- {"version":3,"file":"SchemaProvider.cjs","sources":["../../../../../../packages/engine-system-api/src/model/migrations/SchemaProvider.ts"],"sourcesContent":["import { SchemaQuery } from '../queries'\nimport { DatabaseContext } from '../database'\nimport { calculateSchemaChecksum, emptySchema, normalizeSchema } from '@contember/schema-utils'\nimport { ExecutedMigrationsResolver } from './ExecutedMigrationsResolver'\nimport { SchemaMigrator } from '@contember/schema-migrations'\nimport { Schema } from '@contember/schema'\n\nexport type SchemaMeta = {\n\tchecksum: string\n\tversion: string\n\tupdatedAt: Date\n\tid: number\n}\n\nexport const emptyVersionedSchema: SchemaWithMeta = {\n\tschema: emptySchema,\n\tmeta: {},\n}\n\nexport type SchemaWithMeta = {\n\tschema: Schema\n\tmeta: SchemaMeta | { [K in keyof SchemaMeta]?: undefined }\n}\n\nexport class SchemaProvider {\n\tconstructor(\n\t\tprivate readonly executedMigrationsResolver: ExecutedMigrationsResolver,\n\t\tprivate readonly schemaMigrator: SchemaMigrator,\n\t) {\n\t}\n\n\tasync buildSchemaFromMigrations(db: DatabaseContext): Promise<SchemaWithMeta> {\n\t\tconst newMigrations = (await this.executedMigrationsResolver.getMigrations(db))\n\n\t\tconst partialResult = newMigrations.reduce<SchemaWithMeta>(\n\t\t\t(schema, migration) => {\n\t\t\t\tif (migration.type !== 'schema') {\n\t\t\t\t\treturn schema\n\t\t\t\t}\n\t\t\t\treturn {\n\t\t\t\t\tschema: this.schemaMigrator.applyModifications(schema.schema, migration.modifications, migration.formatVersion),\n\t\t\t\t\tmeta: {\n\t\t\t\t\t\tversion: migration.version,\n\t\t\t\t\t\tid: migration.id,\n\t\t\t\t\t\tupdatedAt: migration.executedAt,\n\t\t\t\t\t\tchecksum: '',\n\t\t\t\t\t},\n\t\t\t\t}\n\t\t\t},\n\t\t\temptyVersionedSchema,\n\t\t)\n\n\t\tif (!partialResult.meta.version) {\n\t\t\treturn emptyVersionedSchema\n\t\t}\n\n\t\treturn {\n\t\t\tschema: partialResult.schema,\n\t\t\tmeta: {\n\t\t\t\t...partialResult.meta,\n\t\t\t\tchecksum: calculateSchemaChecksum(partialResult.schema),\n\t\t\t},\n\t\t}\n\t}\n\n\tpublic async fetch({ db, currentSchema }: {\n\t\tdb: DatabaseContext\n\t\tcurrentSchema?: SchemaWithMeta | null\n\t}): Promise<SchemaWithMeta> {\n\t\tconst newSchema = await db.queryHandler.fetch(new SchemaQuery(currentSchema?.meta.checksum))\n\t\tif (!newSchema) {\n\t\t\treturn currentSchema ?? emptyVersionedSchema\n\t\t}\n\n\t\treturn newSchema\n\t}\n}\n"],"names":["emptySchema","calculateSchemaChecksum","SchemaQuery"],"mappings":";;;;;;;;AAcO,MAAM,uBAAuC;AAAA,EACnD,QAAQA,YAAA;AAAA,EACR,MAAM,CAAC;AACR;AAOO,MAAM,eAAe;AAAA,EAC3B,YACkB,4BACA,gBAChB;AAFgB,SAAA,6BAAA;AACA,SAAA,iBAAA;AAAA,EAElB;AAAA,EAEA,MAAM,0BAA0B,IAA8C;AAC7E,UAAM,gBAAiB,MAAM,KAAK,2BAA2B,cAAc,EAAE;AAE7E,UAAM,gBAAgB,cAAc;AAAA,MACnC,CAAC,QAAQ,cAAc;AAClB,YAAA,UAAU,SAAS,UAAU;AACzB,iBAAA;AAAA,QACR;AACO,eAAA;AAAA,UACN,QAAQ,KAAK,eAAe,mBAAmB,OAAO,QAAQ,UAAU,eAAe,UAAU,aAAa;AAAA,UAC9G,MAAM;AAAA,YACL,SAAS,UAAU;AAAA,YACnB,IAAI,UAAU;AAAA,YACd,WAAW,UAAU;AAAA,YACrB,UAAU;AAAA,UACX;AAAA,QAAA;AAAA,MAEF;AAAA,MACA;AAAA,IAAA;AAGG,QAAA,CAAC,cAAc,KAAK,SAAS;AACzB,aAAA;AAAA,IACR;AAEO,WAAA;AAAA,MACN,QAAQ,cAAc;AAAA,MACtB,MAAM;AAAA,QACL,GAAG,cAAc;AAAA,QACjB,UAAUC,YAAAA,wBAAwB,cAAc,MAAM;AAAA,MACvD;AAAA,IAAA;AAAA,EAEF;AAAA,EAEA,MAAa,MAAM,EAAE,IAAI,iBAGG;AACrB,UAAA,YAAY,MAAM,GAAG,aAAa,MAAM,IAAIC,YAAY,YAAA,eAAe,KAAK,QAAQ,CAAC;AAC3F,QAAI,CAAC,WAAW;AACf,aAAO,iBAAiB;AAAA,IACzB;AAEO,WAAA;AAAA,EACR;AACD;;;"}
1
+ {"version":3,"file":"SchemaProvider.cjs","sources":["../../../../../../packages/engine-system-api/src/model/migrations/SchemaProvider.ts"],"sourcesContent":["import { SchemaQuery } from '../queries'\nimport { DatabaseContext } from '../database'\nimport { calculateSchemaChecksum, emptySchema, normalizeSchema } from '@contember/schema-utils'\nimport { ExecutedMigrationsResolver } from './ExecutedMigrationsResolver'\nimport { SchemaMigrator } from '@contember/schema-migrations'\nimport { Schema } from '@contember/schema'\n\nexport type SchemaMeta = {\n\tchecksum: string\n\tversion: string\n\tupdatedAt: Date\n\tid: number\n}\n\nexport const emptyVersionedSchema: SchemaWithMeta = {\n\tschema: emptySchema,\n\tmeta: {},\n}\n\nexport type SchemaWithMeta = {\n\tschema: Schema\n\tmeta: SchemaMeta | { [K in keyof SchemaMeta]?: undefined }\n}\n\nexport class SchemaProvider {\n\tconstructor(\n\t\tprivate readonly executedMigrationsResolver: ExecutedMigrationsResolver,\n\t\tprivate readonly schemaMigrator: SchemaMigrator,\n\t) {\n\t}\n\n\tasync buildSchemaFromMigrations(db: DatabaseContext): Promise<SchemaWithMeta> {\n\t\tconst newMigrations = (await this.executedMigrationsResolver.getMigrations(db))\n\n\t\tconst partialResult = newMigrations.reduce<SchemaWithMeta>(\n\t\t\t(schema, migration) => {\n\t\t\t\tif (migration.type !== 'schema') {\n\t\t\t\t\treturn schema\n\t\t\t\t}\n\t\t\t\treturn {\n\t\t\t\t\tschema: this.schemaMigrator.applyModifications(schema.schema, migration.modifications, migration.formatVersion),\n\t\t\t\t\tmeta: {\n\t\t\t\t\t\tversion: migration.version,\n\t\t\t\t\t\tid: migration.id,\n\t\t\t\t\t\tupdatedAt: migration.executedAt,\n\t\t\t\t\t\tchecksum: '',\n\t\t\t\t\t},\n\t\t\t\t}\n\t\t\t},\n\t\t\temptyVersionedSchema,\n\t\t)\n\n\t\tif (!partialResult.meta.version) {\n\t\t\treturn emptyVersionedSchema\n\t\t}\n\n\t\treturn {\n\t\t\tschema: partialResult.schema,\n\t\t\tmeta: {\n\t\t\t\t...partialResult.meta,\n\t\t\t\tchecksum: calculateSchemaChecksum(partialResult.schema),\n\t\t\t},\n\t\t}\n\t}\n\n\tpublic async fetch({ db, currentSchema }: {\n\t\tdb: DatabaseContext\n\t\tcurrentSchema?: SchemaWithMeta | null\n\t}): Promise<SchemaWithMeta> {\n\t\tconst newSchema = await db.queryHandler.fetch(new SchemaQuery(currentSchema?.meta.checksum))\n\t\tif (!newSchema) {\n\t\t\treturn currentSchema ?? emptyVersionedSchema\n\t\t}\n\n\t\treturn newSchema\n\t}\n}\n"],"names":["emptySchema","calculateSchemaChecksum","SchemaQuery"],"mappings":";;;;;;;;AAcO,MAAM,uBAAuC;AAAA,EACnD,QAAQA,YAAA;AAAA,EACR,MAAM,CAAA;AACP;AAOO,MAAM,eAAe;AAAA,EAC3B,YACkB,4BACA,gBAChB;AAFgB,SAAA,6BAAA;AACA,SAAA,iBAAA;AAAA,EAAA;AAAA,EAIlB,MAAM,0BAA0B,IAA8C;AAC7E,UAAM,gBAAiB,MAAM,KAAK,2BAA2B,cAAc,EAAE;AAE7E,UAAM,gBAAgB,cAAc;AAAA,MACnC,CAAC,QAAQ,cAAc;AAClB,YAAA,UAAU,SAAS,UAAU;AACzB,iBAAA;AAAA,QAAA;AAED,eAAA;AAAA,UACN,QAAQ,KAAK,eAAe,mBAAmB,OAAO,QAAQ,UAAU,eAAe,UAAU,aAAa;AAAA,UAC9G,MAAM;AAAA,YACL,SAAS,UAAU;AAAA,YACnB,IAAI,UAAU;AAAA,YACd,WAAW,UAAU;AAAA,YACrB,UAAU;AAAA,UAAA;AAAA,QAEZ;AAAA,MACD;AAAA,MACA;AAAA,IACD;AAEI,QAAA,CAAC,cAAc,KAAK,SAAS;AACzB,aAAA;AAAA,IAAA;AAGD,WAAA;AAAA,MACN,QAAQ,cAAc;AAAA,MACtB,MAAM;AAAA,QACL,GAAG,cAAc;AAAA,QACjB,UAAUC,YAAAA,wBAAwB,cAAc,MAAM;AAAA,MAAA;AAAA,IAExD;AAAA,EAAA;AAAA,EAGD,MAAa,MAAM,EAAE,IAAI,iBAGG;AACrB,UAAA,YAAY,MAAM,GAAG,aAAa,MAAM,IAAIC,YAAAA,YAAY,eAAe,KAAK,QAAQ,CAAC;AAC3F,QAAI,CAAC,WAAW;AACf,aAAO,iBAAiB;AAAA,IAAA;AAGlB,WAAA;AAAA,EAAA;AAET;;;"}
@@ -1 +1 @@
1
- {"version":3,"file":"SchemaProvider.js","sources":["../../../../../../packages/engine-system-api/src/model/migrations/SchemaProvider.ts"],"sourcesContent":["import { SchemaQuery } from '../queries'\nimport { DatabaseContext } from '../database'\nimport { calculateSchemaChecksum, emptySchema, normalizeSchema } from '@contember/schema-utils'\nimport { ExecutedMigrationsResolver } from './ExecutedMigrationsResolver'\nimport { SchemaMigrator } from '@contember/schema-migrations'\nimport { Schema } from '@contember/schema'\n\nexport type SchemaMeta = {\n\tchecksum: string\n\tversion: string\n\tupdatedAt: Date\n\tid: number\n}\n\nexport const emptyVersionedSchema: SchemaWithMeta = {\n\tschema: emptySchema,\n\tmeta: {},\n}\n\nexport type SchemaWithMeta = {\n\tschema: Schema\n\tmeta: SchemaMeta | { [K in keyof SchemaMeta]?: undefined }\n}\n\nexport class SchemaProvider {\n\tconstructor(\n\t\tprivate readonly executedMigrationsResolver: ExecutedMigrationsResolver,\n\t\tprivate readonly schemaMigrator: SchemaMigrator,\n\t) {\n\t}\n\n\tasync buildSchemaFromMigrations(db: DatabaseContext): Promise<SchemaWithMeta> {\n\t\tconst newMigrations = (await this.executedMigrationsResolver.getMigrations(db))\n\n\t\tconst partialResult = newMigrations.reduce<SchemaWithMeta>(\n\t\t\t(schema, migration) => {\n\t\t\t\tif (migration.type !== 'schema') {\n\t\t\t\t\treturn schema\n\t\t\t\t}\n\t\t\t\treturn {\n\t\t\t\t\tschema: this.schemaMigrator.applyModifications(schema.schema, migration.modifications, migration.formatVersion),\n\t\t\t\t\tmeta: {\n\t\t\t\t\t\tversion: migration.version,\n\t\t\t\t\t\tid: migration.id,\n\t\t\t\t\t\tupdatedAt: migration.executedAt,\n\t\t\t\t\t\tchecksum: '',\n\t\t\t\t\t},\n\t\t\t\t}\n\t\t\t},\n\t\t\temptyVersionedSchema,\n\t\t)\n\n\t\tif (!partialResult.meta.version) {\n\t\t\treturn emptyVersionedSchema\n\t\t}\n\n\t\treturn {\n\t\t\tschema: partialResult.schema,\n\t\t\tmeta: {\n\t\t\t\t...partialResult.meta,\n\t\t\t\tchecksum: calculateSchemaChecksum(partialResult.schema),\n\t\t\t},\n\t\t}\n\t}\n\n\tpublic async fetch({ db, currentSchema }: {\n\t\tdb: DatabaseContext\n\t\tcurrentSchema?: SchemaWithMeta | null\n\t}): Promise<SchemaWithMeta> {\n\t\tconst newSchema = await db.queryHandler.fetch(new SchemaQuery(currentSchema?.meta.checksum))\n\t\tif (!newSchema) {\n\t\t\treturn currentSchema ?? emptyVersionedSchema\n\t\t}\n\n\t\treturn newSchema\n\t}\n}\n"],"names":[],"mappings":";;;;;;AAcO,MAAM,uBAAuC;AAAA,EACnD,QAAQ;AAAA,EACR,MAAM,CAAC;AACR;AAOO,MAAM,eAAe;AAAA,EAC3B,YACkB,4BACA,gBAChB;AAFgB,SAAA,6BAAA;AACA,SAAA,iBAAA;AAAA,EAElB;AAAA,EAEA,MAAM,0BAA0B,IAA8C;AAC7E,UAAM,gBAAiB,MAAM,KAAK,2BAA2B,cAAc,EAAE;AAE7E,UAAM,gBAAgB,cAAc;AAAA,MACnC,CAAC,QAAQ,cAAc;AAClB,YAAA,UAAU,SAAS,UAAU;AACzB,iBAAA;AAAA,QACR;AACO,eAAA;AAAA,UACN,QAAQ,KAAK,eAAe,mBAAmB,OAAO,QAAQ,UAAU,eAAe,UAAU,aAAa;AAAA,UAC9G,MAAM;AAAA,YACL,SAAS,UAAU;AAAA,YACnB,IAAI,UAAU;AAAA,YACd,WAAW,UAAU;AAAA,YACrB,UAAU;AAAA,UACX;AAAA,QAAA;AAAA,MAEF;AAAA,MACA;AAAA,IAAA;AAGG,QAAA,CAAC,cAAc,KAAK,SAAS;AACzB,aAAA;AAAA,IACR;AAEO,WAAA;AAAA,MACN,QAAQ,cAAc;AAAA,MACtB,MAAM;AAAA,QACL,GAAG,cAAc;AAAA,QACjB,UAAU,wBAAwB,cAAc,MAAM;AAAA,MACvD;AAAA,IAAA;AAAA,EAEF;AAAA,EAEA,MAAa,MAAM,EAAE,IAAI,iBAGG;AACrB,UAAA,YAAY,MAAM,GAAG,aAAa,MAAM,IAAI,YAAY,eAAe,KAAK,QAAQ,CAAC;AAC3F,QAAI,CAAC,WAAW;AACf,aAAO,iBAAiB;AAAA,IACzB;AAEO,WAAA;AAAA,EACR;AACD;"}
1
+ {"version":3,"file":"SchemaProvider.js","sources":["../../../../../../packages/engine-system-api/src/model/migrations/SchemaProvider.ts"],"sourcesContent":["import { SchemaQuery } from '../queries'\nimport { DatabaseContext } from '../database'\nimport { calculateSchemaChecksum, emptySchema, normalizeSchema } from '@contember/schema-utils'\nimport { ExecutedMigrationsResolver } from './ExecutedMigrationsResolver'\nimport { SchemaMigrator } from '@contember/schema-migrations'\nimport { Schema } from '@contember/schema'\n\nexport type SchemaMeta = {\n\tchecksum: string\n\tversion: string\n\tupdatedAt: Date\n\tid: number\n}\n\nexport const emptyVersionedSchema: SchemaWithMeta = {\n\tschema: emptySchema,\n\tmeta: {},\n}\n\nexport type SchemaWithMeta = {\n\tschema: Schema\n\tmeta: SchemaMeta | { [K in keyof SchemaMeta]?: undefined }\n}\n\nexport class SchemaProvider {\n\tconstructor(\n\t\tprivate readonly executedMigrationsResolver: ExecutedMigrationsResolver,\n\t\tprivate readonly schemaMigrator: SchemaMigrator,\n\t) {\n\t}\n\n\tasync buildSchemaFromMigrations(db: DatabaseContext): Promise<SchemaWithMeta> {\n\t\tconst newMigrations = (await this.executedMigrationsResolver.getMigrations(db))\n\n\t\tconst partialResult = newMigrations.reduce<SchemaWithMeta>(\n\t\t\t(schema, migration) => {\n\t\t\t\tif (migration.type !== 'schema') {\n\t\t\t\t\treturn schema\n\t\t\t\t}\n\t\t\t\treturn {\n\t\t\t\t\tschema: this.schemaMigrator.applyModifications(schema.schema, migration.modifications, migration.formatVersion),\n\t\t\t\t\tmeta: {\n\t\t\t\t\t\tversion: migration.version,\n\t\t\t\t\t\tid: migration.id,\n\t\t\t\t\t\tupdatedAt: migration.executedAt,\n\t\t\t\t\t\tchecksum: '',\n\t\t\t\t\t},\n\t\t\t\t}\n\t\t\t},\n\t\t\temptyVersionedSchema,\n\t\t)\n\n\t\tif (!partialResult.meta.version) {\n\t\t\treturn emptyVersionedSchema\n\t\t}\n\n\t\treturn {\n\t\t\tschema: partialResult.schema,\n\t\t\tmeta: {\n\t\t\t\t...partialResult.meta,\n\t\t\t\tchecksum: calculateSchemaChecksum(partialResult.schema),\n\t\t\t},\n\t\t}\n\t}\n\n\tpublic async fetch({ db, currentSchema }: {\n\t\tdb: DatabaseContext\n\t\tcurrentSchema?: SchemaWithMeta | null\n\t}): Promise<SchemaWithMeta> {\n\t\tconst newSchema = await db.queryHandler.fetch(new SchemaQuery(currentSchema?.meta.checksum))\n\t\tif (!newSchema) {\n\t\t\treturn currentSchema ?? emptyVersionedSchema\n\t\t}\n\n\t\treturn newSchema\n\t}\n}\n"],"names":[],"mappings":";;;;;;AAcO,MAAM,uBAAuC;AAAA,EACnD,QAAQ;AAAA,EACR,MAAM,CAAA;AACP;AAOO,MAAM,eAAe;AAAA,EAC3B,YACkB,4BACA,gBAChB;AAFgB,SAAA,6BAAA;AACA,SAAA,iBAAA;AAAA,EAAA;AAAA,EAIlB,MAAM,0BAA0B,IAA8C;AAC7E,UAAM,gBAAiB,MAAM,KAAK,2BAA2B,cAAc,EAAE;AAE7E,UAAM,gBAAgB,cAAc;AAAA,MACnC,CAAC,QAAQ,cAAc;AAClB,YAAA,UAAU,SAAS,UAAU;AACzB,iBAAA;AAAA,QAAA;AAED,eAAA;AAAA,UACN,QAAQ,KAAK,eAAe,mBAAmB,OAAO,QAAQ,UAAU,eAAe,UAAU,aAAa;AAAA,UAC9G,MAAM;AAAA,YACL,SAAS,UAAU;AAAA,YACnB,IAAI,UAAU;AAAA,YACd,WAAW,UAAU;AAAA,YACrB,UAAU;AAAA,UAAA;AAAA,QAEZ;AAAA,MACD;AAAA,MACA;AAAA,IACD;AAEI,QAAA,CAAC,cAAc,KAAK,SAAS;AACzB,aAAA;AAAA,IAAA;AAGD,WAAA;AAAA,MACN,QAAQ,cAAc;AAAA,MACtB,MAAM;AAAA,QACL,GAAG,cAAc;AAAA,QACjB,UAAU,wBAAwB,cAAc,MAAM;AAAA,MAAA;AAAA,IAExD;AAAA,EAAA;AAAA,EAGD,MAAa,MAAM,EAAE,IAAI,iBAGG;AACrB,UAAA,YAAY,MAAM,GAAG,aAAa,MAAM,IAAI,YAAY,eAAe,KAAK,QAAQ,CAAC;AAC3F,QAAI,CAAC,WAAW;AACf,aAAO,iBAAiB;AAAA,IAAA;AAGlB,WAAA;AAAA,EAAA;AAET;"}
@@ -1 +1 @@
1
- {"version":3,"file":"EventQueryHelpers.cjs","sources":["../../../../../../../packages/engine-system-api/src/model/queries/events/EventQueryHelpers.ts"],"sourcesContent":["import { ContentEvent, CreateEvent, DeleteEvent, EventType, UpdateEvent } from '../../events'\nimport { assertNever } from '../../../utils'\n\nexport type EventRow = {\n\tid: string\n\ttype: EventType\n\ttable_name: string\n\trow_ids: string[]\n\tvalues: Record<string, any>\n\tcreated_at: Date\n\tapplied_at: Date\n\tidentity_id: string\n\ttransaction_id: string\n}\n\nexport const createEventsFromRows = (rows: EventRow[]): ContentEvent[] => {\n\treturn rows.map(event => {\n\t\tswitch (event.type) {\n\t\t\tcase EventType.create:\n\t\t\t\treturn new CreateEvent(\n\t\t\t\t\tevent.id,\n\t\t\t\t\tevent.created_at,\n\t\t\t\t\tevent.applied_at,\n\t\t\t\t\tevent.identity_id,\n\t\t\t\t\tevent.transaction_id,\n\t\t\t\t\tevent.row_ids,\n\t\t\t\t\tevent.table_name,\n\t\t\t\t\tevent.values,\n\t\t\t\t)\n\t\t\tcase EventType.update:\n\t\t\t\treturn new UpdateEvent(\n\t\t\t\t\tevent.id,\n\t\t\t\t\tevent.created_at,\n\t\t\t\t\tevent.applied_at,\n\t\t\t\t\tevent.identity_id,\n\t\t\t\t\tevent.transaction_id,\n\t\t\t\t\tevent.row_ids,\n\t\t\t\t\tevent.table_name,\n\t\t\t\t\tevent.values,\n\t\t\t\t)\n\t\t\tcase EventType.delete:\n\t\t\t\treturn new DeleteEvent(\n\t\t\t\t\tevent.id,\n\t\t\t\t\tevent.created_at,\n\t\t\t\t\tevent.applied_at,\n\t\t\t\t\tevent.identity_id,\n\t\t\t\t\tevent.transaction_id,\n\t\t\t\t\tevent.row_ids,\n\t\t\t\t\tevent.table_name,\n\t\t\t\t)\n\t\t\tdefault:\n\t\t\t\tassertNever(event.type)\n\t\t}\n\t})\n}\n"],"names":["EventType","CreateEvent","UpdateEvent","DeleteEvent","assertNever"],"mappings":";;;;;;AAea,MAAA,uBAAuB,CAAC,SAAqC;AAClE,SAAA,KAAK,IAAI,CAAS,UAAA;AACxB,YAAQ,MAAM,MAAM;AAAA,MACnB,KAAKA,MAAU,UAAA;AACd,eAAO,IAAIC,MAAA;AAAA,UACV,MAAM;AAAA,UACN,MAAM;AAAA,UACN,MAAM;AAAA,UACN,MAAM;AAAA,UACN,MAAM;AAAA,UACN,MAAM;AAAA,UACN,MAAM;AAAA,UACN,MAAM;AAAA,QAAA;AAAA,MAER,KAAKD,MAAU,UAAA;AACd,eAAO,IAAIE,MAAA;AAAA,UACV,MAAM;AAAA,UACN,MAAM;AAAA,UACN,MAAM;AAAA,UACN,MAAM;AAAA,UACN,MAAM;AAAA,UACN,MAAM;AAAA,UACN,MAAM;AAAA,UACN,MAAM;AAAA,QAAA;AAAA,MAER,KAAKF,MAAU,UAAA;AACd,eAAO,IAAIG,MAAA;AAAA,UACV,MAAM;AAAA,UACN,MAAM;AAAA,UACN,MAAM;AAAA,UACN,MAAM;AAAA,UACN,MAAM;AAAA,UACN,MAAM;AAAA,UACN,MAAM;AAAA,QAAA;AAAA,MAER;AACCC,gCAAY,MAAM,IAAI;AAAA,IACxB;AAAA,EAAA,CACA;AACF;;"}
1
+ {"version":3,"file":"EventQueryHelpers.cjs","sources":["../../../../../../../packages/engine-system-api/src/model/queries/events/EventQueryHelpers.ts"],"sourcesContent":["import { ContentEvent, CreateEvent, DeleteEvent, EventType, UpdateEvent } from '../../events'\nimport { assertNever } from '../../../utils'\n\nexport type EventRow = {\n\tid: string\n\ttype: EventType\n\ttable_name: string\n\trow_ids: string[]\n\tvalues: Record<string, any>\n\tcreated_at: Date\n\tapplied_at: Date\n\tidentity_id: string\n\ttransaction_id: string\n}\n\nexport const createEventsFromRows = (rows: EventRow[]): ContentEvent[] => {\n\treturn rows.map(event => {\n\t\tswitch (event.type) {\n\t\t\tcase EventType.create:\n\t\t\t\treturn new CreateEvent(\n\t\t\t\t\tevent.id,\n\t\t\t\t\tevent.created_at,\n\t\t\t\t\tevent.applied_at,\n\t\t\t\t\tevent.identity_id,\n\t\t\t\t\tevent.transaction_id,\n\t\t\t\t\tevent.row_ids,\n\t\t\t\t\tevent.table_name,\n\t\t\t\t\tevent.values,\n\t\t\t\t)\n\t\t\tcase EventType.update:\n\t\t\t\treturn new UpdateEvent(\n\t\t\t\t\tevent.id,\n\t\t\t\t\tevent.created_at,\n\t\t\t\t\tevent.applied_at,\n\t\t\t\t\tevent.identity_id,\n\t\t\t\t\tevent.transaction_id,\n\t\t\t\t\tevent.row_ids,\n\t\t\t\t\tevent.table_name,\n\t\t\t\t\tevent.values,\n\t\t\t\t)\n\t\t\tcase EventType.delete:\n\t\t\t\treturn new DeleteEvent(\n\t\t\t\t\tevent.id,\n\t\t\t\t\tevent.created_at,\n\t\t\t\t\tevent.applied_at,\n\t\t\t\t\tevent.identity_id,\n\t\t\t\t\tevent.transaction_id,\n\t\t\t\t\tevent.row_ids,\n\t\t\t\t\tevent.table_name,\n\t\t\t\t)\n\t\t\tdefault:\n\t\t\t\tassertNever(event.type)\n\t\t}\n\t})\n}\n"],"names":["EventType","CreateEvent","UpdateEvent","DeleteEvent","assertNever"],"mappings":";;;;;;AAea,MAAA,uBAAuB,CAAC,SAAqC;AAClE,SAAA,KAAK,IAAI,CAAS,UAAA;AACxB,YAAQ,MAAM,MAAM;AAAA,MACnB,KAAKA,MAAU,UAAA;AACd,eAAO,IAAIC,MAAA;AAAA,UACV,MAAM;AAAA,UACN,MAAM;AAAA,UACN,MAAM;AAAA,UACN,MAAM;AAAA,UACN,MAAM;AAAA,UACN,MAAM;AAAA,UACN,MAAM;AAAA,UACN,MAAM;AAAA,QACP;AAAA,MACD,KAAKD,MAAU,UAAA;AACd,eAAO,IAAIE,MAAA;AAAA,UACV,MAAM;AAAA,UACN,MAAM;AAAA,UACN,MAAM;AAAA,UACN,MAAM;AAAA,UACN,MAAM;AAAA,UACN,MAAM;AAAA,UACN,MAAM;AAAA,UACN,MAAM;AAAA,QACP;AAAA,MACD,KAAKF,MAAU,UAAA;AACd,eAAO,IAAIG,MAAA;AAAA,UACV,MAAM;AAAA,UACN,MAAM;AAAA,UACN,MAAM;AAAA,UACN,MAAM;AAAA,UACN,MAAM;AAAA,UACN,MAAM;AAAA,UACN,MAAM;AAAA,QACP;AAAA,MACD;AACCC,oBAAA,YAAY,MAAM,IAAI;AAAA,IAAA;AAAA,EACxB,CACA;AACF;;"}
@@ -1 +1 @@
1
- {"version":3,"file":"EventQueryHelpers.js","sources":["../../../../../../../packages/engine-system-api/src/model/queries/events/EventQueryHelpers.ts"],"sourcesContent":["import { ContentEvent, CreateEvent, DeleteEvent, EventType, UpdateEvent } from '../../events'\nimport { assertNever } from '../../../utils'\n\nexport type EventRow = {\n\tid: string\n\ttype: EventType\n\ttable_name: string\n\trow_ids: string[]\n\tvalues: Record<string, any>\n\tcreated_at: Date\n\tapplied_at: Date\n\tidentity_id: string\n\ttransaction_id: string\n}\n\nexport const createEventsFromRows = (rows: EventRow[]): ContentEvent[] => {\n\treturn rows.map(event => {\n\t\tswitch (event.type) {\n\t\t\tcase EventType.create:\n\t\t\t\treturn new CreateEvent(\n\t\t\t\t\tevent.id,\n\t\t\t\t\tevent.created_at,\n\t\t\t\t\tevent.applied_at,\n\t\t\t\t\tevent.identity_id,\n\t\t\t\t\tevent.transaction_id,\n\t\t\t\t\tevent.row_ids,\n\t\t\t\t\tevent.table_name,\n\t\t\t\t\tevent.values,\n\t\t\t\t)\n\t\t\tcase EventType.update:\n\t\t\t\treturn new UpdateEvent(\n\t\t\t\t\tevent.id,\n\t\t\t\t\tevent.created_at,\n\t\t\t\t\tevent.applied_at,\n\t\t\t\t\tevent.identity_id,\n\t\t\t\t\tevent.transaction_id,\n\t\t\t\t\tevent.row_ids,\n\t\t\t\t\tevent.table_name,\n\t\t\t\t\tevent.values,\n\t\t\t\t)\n\t\t\tcase EventType.delete:\n\t\t\t\treturn new DeleteEvent(\n\t\t\t\t\tevent.id,\n\t\t\t\t\tevent.created_at,\n\t\t\t\t\tevent.applied_at,\n\t\t\t\t\tevent.identity_id,\n\t\t\t\t\tevent.transaction_id,\n\t\t\t\t\tevent.row_ids,\n\t\t\t\t\tevent.table_name,\n\t\t\t\t)\n\t\t\tdefault:\n\t\t\t\tassertNever(event.type)\n\t\t}\n\t})\n}\n"],"names":[],"mappings":";;;;AAea,MAAA,uBAAuB,CAAC,SAAqC;AAClE,SAAA,KAAK,IAAI,CAAS,UAAA;AACxB,YAAQ,MAAM,MAAM;AAAA,MACnB,KAAK,UAAU;AACd,eAAO,IAAI;AAAA,UACV,MAAM;AAAA,UACN,MAAM;AAAA,UACN,MAAM;AAAA,UACN,MAAM;AAAA,UACN,MAAM;AAAA,UACN,MAAM;AAAA,UACN,MAAM;AAAA,UACN,MAAM;AAAA,QAAA;AAAA,MAER,KAAK,UAAU;AACd,eAAO,IAAI;AAAA,UACV,MAAM;AAAA,UACN,MAAM;AAAA,UACN,MAAM;AAAA,UACN,MAAM;AAAA,UACN,MAAM;AAAA,UACN,MAAM;AAAA,UACN,MAAM;AAAA,UACN,MAAM;AAAA,QAAA;AAAA,MAER,KAAK,UAAU;AACd,eAAO,IAAI;AAAA,UACV,MAAM;AAAA,UACN,MAAM;AAAA,UACN,MAAM;AAAA,UACN,MAAM;AAAA,UACN,MAAM;AAAA,UACN,MAAM;AAAA,UACN,MAAM;AAAA,QAAA;AAAA,MAER;AACC,oBAAY,MAAM,IAAI;AAAA,IACxB;AAAA,EAAA,CACA;AACF;"}
1
+ {"version":3,"file":"EventQueryHelpers.js","sources":["../../../../../../../packages/engine-system-api/src/model/queries/events/EventQueryHelpers.ts"],"sourcesContent":["import { ContentEvent, CreateEvent, DeleteEvent, EventType, UpdateEvent } from '../../events'\nimport { assertNever } from '../../../utils'\n\nexport type EventRow = {\n\tid: string\n\ttype: EventType\n\ttable_name: string\n\trow_ids: string[]\n\tvalues: Record<string, any>\n\tcreated_at: Date\n\tapplied_at: Date\n\tidentity_id: string\n\ttransaction_id: string\n}\n\nexport const createEventsFromRows = (rows: EventRow[]): ContentEvent[] => {\n\treturn rows.map(event => {\n\t\tswitch (event.type) {\n\t\t\tcase EventType.create:\n\t\t\t\treturn new CreateEvent(\n\t\t\t\t\tevent.id,\n\t\t\t\t\tevent.created_at,\n\t\t\t\t\tevent.applied_at,\n\t\t\t\t\tevent.identity_id,\n\t\t\t\t\tevent.transaction_id,\n\t\t\t\t\tevent.row_ids,\n\t\t\t\t\tevent.table_name,\n\t\t\t\t\tevent.values,\n\t\t\t\t)\n\t\t\tcase EventType.update:\n\t\t\t\treturn new UpdateEvent(\n\t\t\t\t\tevent.id,\n\t\t\t\t\tevent.created_at,\n\t\t\t\t\tevent.applied_at,\n\t\t\t\t\tevent.identity_id,\n\t\t\t\t\tevent.transaction_id,\n\t\t\t\t\tevent.row_ids,\n\t\t\t\t\tevent.table_name,\n\t\t\t\t\tevent.values,\n\t\t\t\t)\n\t\t\tcase EventType.delete:\n\t\t\t\treturn new DeleteEvent(\n\t\t\t\t\tevent.id,\n\t\t\t\t\tevent.created_at,\n\t\t\t\t\tevent.applied_at,\n\t\t\t\t\tevent.identity_id,\n\t\t\t\t\tevent.transaction_id,\n\t\t\t\t\tevent.row_ids,\n\t\t\t\t\tevent.table_name,\n\t\t\t\t)\n\t\t\tdefault:\n\t\t\t\tassertNever(event.type)\n\t\t}\n\t})\n}\n"],"names":[],"mappings":";;;;AAea,MAAA,uBAAuB,CAAC,SAAqC;AAClE,SAAA,KAAK,IAAI,CAAS,UAAA;AACxB,YAAQ,MAAM,MAAM;AAAA,MACnB,KAAK,UAAU;AACd,eAAO,IAAI;AAAA,UACV,MAAM;AAAA,UACN,MAAM;AAAA,UACN,MAAM;AAAA,UACN,MAAM;AAAA,UACN,MAAM;AAAA,UACN,MAAM;AAAA,UACN,MAAM;AAAA,UACN,MAAM;AAAA,QACP;AAAA,MACD,KAAK,UAAU;AACd,eAAO,IAAI;AAAA,UACV,MAAM;AAAA,UACN,MAAM;AAAA,UACN,MAAM;AAAA,UACN,MAAM;AAAA,UACN,MAAM;AAAA,UACN,MAAM;AAAA,UACN,MAAM;AAAA,UACN,MAAM;AAAA,QACP;AAAA,MACD,KAAK,UAAU;AACd,eAAO,IAAI;AAAA,UACV,MAAM;AAAA,UACN,MAAM;AAAA,UACN,MAAM;AAAA,UACN,MAAM;AAAA,UACN,MAAM;AAAA,UACN,MAAM;AAAA,UACN,MAAM;AAAA,QACP;AAAA,MACD;AACC,oBAAY,MAAM,IAAI;AAAA,IAAA;AAAA,EACxB,CACA;AACF;"}
@@ -1 +1 @@
1
- {"version":3,"file":"EventsQuery.cjs","sources":["../../../../../../../packages/engine-system-api/src/model/queries/events/EventsQuery.ts"],"sourcesContent":["import {\n\tConditionBuilder,\n\tDatabaseQuery,\n\tDatabaseQueryable,\n\tLiteral,\n\tOperator,\n\tSelectBuilder,\n\tSelectBuilderSpecification, Value,\n} from '@contember/database'\nimport { ContentEvent } from '../../events'\nimport { EventsFilter, EventsFilterDate, EventsOrder } from '../../../schema'\nimport { createEventsFromRows, EventRow } from './EventQueryHelpers'\n\nexport class EventsQuery extends DatabaseQuery<ContentEvent[]> {\n\tconstructor(\n\t\tprivate readonly filter: EventsFilter,\n\t\tprivate readonly order: EventsOrder,\n\t\tprivate readonly offset: number,\n\t\tprivate readonly limit: number,\n\t) {\n\t\tsuper()\n\t}\n\n\tasync fetch({ db }: DatabaseQueryable): Promise<ContentEvent[]> {\n\t\tconst createDateMatcher = (column: string, dateFilter: EventsFilterDate | undefined): SelectBuilderSpecification => qb => {\n\t\t\tif (!dateFilter) {\n\t\t\t\treturn qb\n\t\t\t}\n\t\t\tconst { from, to } = dateFilter\n\t\t\tif (from) {\n\t\t\t\tqb = qb.where(expr => expr.compare(column, Operator.gte, from))\n\t\t\t}\n\t\t\tif (to) {\n\t\t\t\tqb = qb.where(expr => expr.compare(column, Operator.lte, to))\n\t\t\t}\n\t\t\treturn qb\n\t\t}\n\t\tconst createInMatcher = (column: string | [string, string], values?: readonly Value[] | null): SelectBuilderSpecification => qb => {\n\t\t\tif (!values) {\n\t\t\t\treturn qb\n\t\t\t}\n\t\t\treturn qb.where(ConditionBuilder.create().in(column, values))\n\t\t}\n\n\t\tconst qb = SelectBuilder.create<EventRow>()\n\t\t\t.select('id')\n\t\t\t.select('type')\n\t\t\t.select('table_name')\n\t\t\t.select('row_ids')\n\t\t\t.select('values')\n\t\t\t.select('created_at')\n\t\t\t.select('applied_at')\n\t\t\t.select('identity_id')\n\t\t\t.select(['event_data', 'transaction_id'])\n\n\t\t\t.from('event_data')\n\t\t\t.join('stage_transaction', undefined, on =>\n\t\t\t\ton.columnsEq(['event_data', 'transaction_id'], ['stage_transaction', 'transaction_id']),\n\t\t\t)\n\t\t\t.match(qb => {\n\t\t\t\tswitch (this.order) {\n\t\t\t\t\tcase EventsOrder.AppliedAtAsc:\n\t\t\t\t\t\treturn qb.orderBy('applied_at', 'asc')\n\t\t\t\t\tcase EventsOrder.AppliedAtDesc:\n\t\t\t\t\t\treturn qb.orderBy('applied_at', 'desc')\n\t\t\t\t\tcase EventsOrder.CreatedAtAsc:\n\t\t\t\t\t\treturn qb.orderBy('created_at', 'asc')\n\t\t\t\t\tcase EventsOrder.CreatedAtDesc:\n\t\t\t\t\t\treturn qb.orderBy('created_at', 'desc')\n\t\t\t\t}\n\t\t\t})\n\t\t\t.match(createInMatcher('type', this.filter.types?.map(it => it.toLowerCase())))\n\t\t\t.match(createInMatcher('table_name', this.filter.tables))\n\t\t\t.match(createInMatcher('transaction_id', this.filter.transactions))\n\t\t\t.match(createInMatcher('identity_id', this.filter.identities))\n\t\t\t.match(createDateMatcher('created_at', this.filter.createdAt ?? undefined))\n\t\t\t.match(createDateMatcher('applied_at', this.filter.appliedAt ?? undefined))\n\t\t\t.match(qb => {\n\t\t\t\tif (!this.filter.rows) {\n\t\t\t\t\treturn qb\n\t\t\t\t}\n\n\t\t\t\tconst ors: Literal[] = this.filter.rows.map(row => {\n\t\t\t\t\tconst builder = ConditionBuilder.create()\n\t\t\t\t\t\t.compare('table_name', Operator.eq, row.tableName)\n\n\t\t\t\t\treturn row.primaryKey.reduce((expr, val, index) => {\n\t\t\t\t\t\tif (val === null) {\n\t\t\t\t\t\t\treturn expr\n\t\t\t\t\t\t}\n\t\t\t\t\t\treturn expr.raw(`\"row_ids\"->${index} = ?::jsonb`, JSON.stringify(val))\n\t\t\t\t\t}, builder).getSql()\n\t\t\t\t}).filter((it): it is Literal => it !== null)\n\n\t\t\t\treturn qb.where(ConditionBuilder.create().or(ConditionBuilder.create(ors)))\n\t\t\t})\n\n\t\t\t.limit(this.limit, this.offset)\n\n\t\treturn createEventsFromRows(await qb.getResult(db))\n\t}\n\n}\n"],"names":["DatabaseQuery","qb","Operator","ConditionBuilder","SelectBuilder","EventsOrder","createEventsFromRows"],"mappings":";;;;;;;AAaO,MAAM,oBAAoBA,SAAAA,cAA8B;AAAA,EAC9D,YACkB,QACA,OACA,QACA,OAChB;AACK;AALW,SAAA,SAAA;AACA,SAAA,QAAA;AACA,SAAA,SAAA;AACA,SA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ED;;"}
1
+ {"version":3,"file":"EventsQuery.cjs","sources":["../../../../../../../packages/engine-system-api/src/model/queries/events/EventsQuery.ts"],"sourcesContent":["import {\n\tConditionBuilder,\n\tDatabaseQuery,\n\tDatabaseQueryable,\n\tLiteral,\n\tOperator,\n\tSelectBuilder,\n\tSelectBuilderSpecification, Value,\n} from '@contember/database'\nimport { ContentEvent } from '../../events'\nimport { EventsFilter, EventsFilterDate, EventsOrder } from '../../../schema'\nimport { createEventsFromRows, EventRow } from './EventQueryHelpers'\n\nexport class EventsQuery extends DatabaseQuery<ContentEvent[]> {\n\tconstructor(\n\t\tprivate readonly filter: EventsFilter,\n\t\tprivate readonly order: EventsOrder,\n\t\tprivate readonly offset: number,\n\t\tprivate readonly limit: number,\n\t) {\n\t\tsuper()\n\t}\n\n\tasync fetch({ db }: DatabaseQueryable): Promise<ContentEvent[]> {\n\t\tconst createDateMatcher = (column: string, dateFilter: EventsFilterDate | undefined): SelectBuilderSpecification => qb => {\n\t\t\tif (!dateFilter) {\n\t\t\t\treturn qb\n\t\t\t}\n\t\t\tconst { from, to } = dateFilter\n\t\t\tif (from) {\n\t\t\t\tqb = qb.where(expr => expr.compare(column, Operator.gte, from))\n\t\t\t}\n\t\t\tif (to) {\n\t\t\t\tqb = qb.where(expr => expr.compare(column, Operator.lte, to))\n\t\t\t}\n\t\t\treturn qb\n\t\t}\n\t\tconst createInMatcher = (column: string | [string, string], values?: readonly Value[] | null): SelectBuilderSpecification => qb => {\n\t\t\tif (!values) {\n\t\t\t\treturn qb\n\t\t\t}\n\t\t\treturn qb.where(ConditionBuilder.create().in(column, values))\n\t\t}\n\n\t\tconst qb = SelectBuilder.create<EventRow>()\n\t\t\t.select('id')\n\t\t\t.select('type')\n\t\t\t.select('table_name')\n\t\t\t.select('row_ids')\n\t\t\t.select('values')\n\t\t\t.select('created_at')\n\t\t\t.select('applied_at')\n\t\t\t.select('identity_id')\n\t\t\t.select(['event_data', 'transaction_id'])\n\n\t\t\t.from('event_data')\n\t\t\t.join('stage_transaction', undefined, on =>\n\t\t\t\ton.columnsEq(['event_data', 'transaction_id'], ['stage_transaction', 'transaction_id']),\n\t\t\t)\n\t\t\t.match(qb => {\n\t\t\t\tswitch (this.order) {\n\t\t\t\t\tcase EventsOrder.AppliedAtAsc:\n\t\t\t\t\t\treturn qb.orderBy('applied_at', 'asc')\n\t\t\t\t\tcase EventsOrder.AppliedAtDesc:\n\t\t\t\t\t\treturn qb.orderBy('applied_at', 'desc')\n\t\t\t\t\tcase EventsOrder.CreatedAtAsc:\n\t\t\t\t\t\treturn qb.orderBy('created_at', 'asc')\n\t\t\t\t\tcase EventsOrder.CreatedAtDesc:\n\t\t\t\t\t\treturn qb.orderBy('created_at', 'desc')\n\t\t\t\t}\n\t\t\t})\n\t\t\t.match(createInMatcher('type', this.filter.types?.map(it => it.toLowerCase())))\n\t\t\t.match(createInMatcher('table_name', this.filter.tables))\n\t\t\t.match(createInMatcher('transaction_id', this.filter.transactions))\n\t\t\t.match(createInMatcher('identity_id', this.filter.identities))\n\t\t\t.match(createDateMatcher('created_at', this.filter.createdAt ?? undefined))\n\t\t\t.match(createDateMatcher('applied_at', this.filter.appliedAt ?? undefined))\n\t\t\t.match(qb => {\n\t\t\t\tif (!this.filter.rows) {\n\t\t\t\t\treturn qb\n\t\t\t\t}\n\n\t\t\t\tconst ors: Literal[] = this.filter.rows.map(row => {\n\t\t\t\t\tconst builder = ConditionBuilder.create()\n\t\t\t\t\t\t.compare('table_name', Operator.eq, row.tableName)\n\n\t\t\t\t\treturn row.primaryKey.reduce((expr, val, index) => {\n\t\t\t\t\t\tif (val === null) {\n\t\t\t\t\t\t\treturn expr\n\t\t\t\t\t\t}\n\t\t\t\t\t\treturn expr.raw(`\"row_ids\"->${index} = ?::jsonb`, JSON.stringify(val))\n\t\t\t\t\t}, builder).getSql()\n\t\t\t\t}).filter((it): it is Literal => it !== null)\n\n\t\t\t\treturn qb.where(ConditionBuilder.create().or(ConditionBuilder.create(ors)))\n\t\t\t})\n\n\t\t\t.limit(this.limit, this.offset)\n\n\t\treturn createEventsFromRows(await qb.getResult(db))\n\t}\n\n}\n"],"names":["DatabaseQuery","qb","Operator","ConditionBuilder","SelectBuilder","EventsOrder","createEventsFromRows"],"mappings":";;;;;;;AAaO,MAAM,oBAAoBA,SAAAA,cAA8B;AAAA,EAC9D,YACkB,QACA,OACA,QACA,OAChB;AACK,UAAA;AALW,SAAA,SAAA;AACA,SAAA,QAAA;AACA,SAAA,SAAA;AACA,SAAA,QAAA;AAAA,EAAA;AAAA,EAKlB,MAAM,MAAM,EAAE,MAAkD;AAC/D,UAAM,oBAAoB,CAAC,QAAgB,eAAyE,CAAAC,QAAM;AACzH,UAAI,CAAC,YAAY;AACTA,eAAAA;AAAAA,MAAA;AAEF,YAAA,EAAE,MAAM,GAAA,IAAO;AACrB,UAAI,MAAM;AACTA,cAAKA,IAAG,MAAM,CAAQ,SAAA,KAAK,QAAQ,QAAQC,SAAAA,SAAS,KAAK,IAAI,CAAC;AAAA,MAAA;AAE/D,UAAI,IAAI;AACPD,cAAKA,IAAG,MAAM,CAAQ,SAAA,KAAK,QAAQ,QAAQC,SAAAA,SAAS,KAAK,EAAE,CAAC;AAAA,MAAA;AAEtDD,aAAAA;AAAAA,IACR;AACA,UAAM,kBAAkB,CAAC,QAAmC,WAAiE,CAAAA,QAAM;AAClI,UAAI,CAAC,QAAQ;AACLA,eAAAA;AAAAA,MAAA;AAEDA,aAAAA,IAAG,MAAME,0BAAiB,SAAS,GAAG,QAAQ,MAAM,CAAC;AAAA,IAC7D;AAEA,UAAM,KAAKC,SAAAA,cAAc,OACvB,EAAA,OAAO,IAAI,EACX,OAAO,MAAM,EACb,OAAO,YAAY,EACnB,OAAO,SAAS,EAChB,OAAO,QAAQ,EACf,OAAO,YAAY,EACnB,OAAO,YAAY,EACnB,OAAO,aAAa,EACpB,OAAO,CAAC,cAAc,gBAAgB,CAAC,EAEvC,KAAK,YAAY,EACjB;AAAA,MAAK;AAAA,MAAqB;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AA,GACnE,OAAO,EAAE,OAAO;AAAA,MACnB,CAAA,EAAE,OAAO,CAAC,OAAsB,OAAO,IAAI;AAErCD,aAAAA,IAAG,MAAME,SAAAA,iBAAiB,OAAO,EAAE,GAAGA,0BAAiB,OAAO,GAAG,CAAC,CAAC;AAAA,IAC1E,CAAA,EAEA,MAAM,KAAK,OAAO,KAAK,MAAM;AAE/B,WAAOG,kBAAqB,qBAAA,MAAM,GAAG,UAAU,EAAE,CAAC;AAAA,EAAA;AAGpD;;"}
@@ -1 +1 @@
1
- {"version":3,"file":"EventsQuery.js","sources":["../../../../../../../packages/engine-system-api/src/model/queries/events/EventsQuery.ts"],"sourcesContent":["import {\n\tConditionBuilder,\n\tDatabaseQuery,\n\tDatabaseQueryable,\n\tLiteral,\n\tOperator,\n\tSelectBuilder,\n\tSelectBuilderSpecification, Value,\n} from '@contember/database'\nimport { ContentEvent } from '../../events'\nimport { EventsFilter, EventsFilterDate, EventsOrder } from '../../../schema'\nimport { createEventsFromRows, EventRow } from './EventQueryHelpers'\n\nexport class EventsQuery extends DatabaseQuery<ContentEvent[]> {\n\tconstructor(\n\t\tprivate readonly filter: EventsFilter,\n\t\tprivate readonly order: EventsOrder,\n\t\tprivate readonly offset: number,\n\t\tprivate readonly limit: number,\n\t) {\n\t\tsuper()\n\t}\n\n\tasync fetch({ db }: DatabaseQueryable): Promise<ContentEvent[]> {\n\t\tconst createDateMatcher = (column: string, dateFilter: EventsFilterDate | undefined): SelectBuilderSpecification => qb => {\n\t\t\tif (!dateFilter) {\n\t\t\t\treturn qb\n\t\t\t}\n\t\t\tconst { from, to } = dateFilter\n\t\t\tif (from) {\n\t\t\t\tqb = qb.where(expr => expr.compare(column, Operator.gte, from))\n\t\t\t}\n\t\t\tif (to) {\n\t\t\t\tqb = qb.where(expr => expr.compare(column, Operator.lte, to))\n\t\t\t}\n\t\t\treturn qb\n\t\t}\n\t\tconst createInMatcher = (column: string | [string, string], values?: readonly Value[] | null): SelectBuilderSpecification => qb => {\n\t\t\tif (!values) {\n\t\t\t\treturn qb\n\t\t\t}\n\t\t\treturn qb.where(ConditionBuilder.create().in(column, values))\n\t\t}\n\n\t\tconst qb = SelectBuilder.create<EventRow>()\n\t\t\t.select('id')\n\t\t\t.select('type')\n\t\t\t.select('table_name')\n\t\t\t.select('row_ids')\n\t\t\t.select('values')\n\t\t\t.select('created_at')\n\t\t\t.select('applied_at')\n\t\t\t.select('identity_id')\n\t\t\t.select(['event_data', 'transaction_id'])\n\n\t\t\t.from('event_data')\n\t\t\t.join('stage_transaction', undefined, on =>\n\t\t\t\ton.columnsEq(['event_data', 'transaction_id'], ['stage_transaction', 'transaction_id']),\n\t\t\t)\n\t\t\t.match(qb => {\n\t\t\t\tswitch (this.order) {\n\t\t\t\t\tcase EventsOrder.AppliedAtAsc:\n\t\t\t\t\t\treturn qb.orderBy('applied_at', 'asc')\n\t\t\t\t\tcase EventsOrder.AppliedAtDesc:\n\t\t\t\t\t\treturn qb.orderBy('applied_at', 'desc')\n\t\t\t\t\tcase EventsOrder.CreatedAtAsc:\n\t\t\t\t\t\treturn qb.orderBy('created_at', 'asc')\n\t\t\t\t\tcase EventsOrder.CreatedAtDesc:\n\t\t\t\t\t\treturn qb.orderBy('created_at', 'desc')\n\t\t\t\t}\n\t\t\t})\n\t\t\t.match(createInMatcher('type', this.filter.types?.map(it => it.toLowerCase())))\n\t\t\t.match(createInMatcher('table_name', this.filter.tables))\n\t\t\t.match(createInMatcher('transaction_id', this.filter.transactions))\n\t\t\t.match(createInMatcher('identity_id', this.filter.identities))\n\t\t\t.match(createDateMatcher('created_at', this.filter.createdAt ?? undefined))\n\t\t\t.match(createDateMatcher('applied_at', this.filter.appliedAt ?? undefined))\n\t\t\t.match(qb => {\n\t\t\t\tif (!this.filter.rows) {\n\t\t\t\t\treturn qb\n\t\t\t\t}\n\n\t\t\t\tconst ors: Literal[] = this.filter.rows.map(row => {\n\t\t\t\t\tconst builder = ConditionBuilder.create()\n\t\t\t\t\t\t.compare('table_name', Operator.eq, row.tableName)\n\n\t\t\t\t\treturn row.primaryKey.reduce((expr, val, index) => {\n\t\t\t\t\t\tif (val === null) {\n\t\t\t\t\t\t\treturn expr\n\t\t\t\t\t\t}\n\t\t\t\t\t\treturn expr.raw(`\"row_ids\"->${index} = ?::jsonb`, JSON.stringify(val))\n\t\t\t\t\t}, builder).getSql()\n\t\t\t\t}).filter((it): it is Literal => it !== null)\n\n\t\t\t\treturn qb.where(ConditionBuilder.create().or(ConditionBuilder.create(ors)))\n\t\t\t})\n\n\t\t\t.limit(this.limit, this.offset)\n\n\t\treturn createEventsFromRows(await qb.getResult(db))\n\t}\n\n}\n"],"names":["qb"],"mappings":";;;;;AAaO,MAAM,oBAAoB,cAA8B;AAAA,EAC9D,YACkB,QACA,OACA,QACA,OAChB;AACK;AALW,SAAA,SAAA;AACA,SAAA,QAAA;AACA,SAAA,SAAA;AACA,SAAA,QAAA;AAAA,EAGlB;AAAA,EAEA,MAAM,MAAM,EAAE,MAAkD;AAC/D,UAAM,oBAAoB,CAAC,QAAgB,eAAyE,CAAAA,QAAM;AACzH,UAAI,CAAC,YAAY;AACTA,eAAAA;AAAAA,MACR;AACM,YAAA,EAAE,MAAM,GAAO,IAAA;AACrB,UAAI,MAAM;AACTA,cAAKA,IAAG,MAAM,CAAQ,SAAA,KAAK,QAAQ,QAAQ,SAAS,KAAK,IAAI,CAAC;AAAA,MAC/D;AACA,UAAI,IAAI;AACPA,cAAKA,IAAG,MAAM,CAAQ,SAAA,KAAK,QAAQ,QAAQ,SAAS,KAAK,EAAE,CAAC;AAAA,MAC7D;AACOA,aAAAA;AAAAA,IAAA;AAER,UAAM,kBAAkB,CAAC,QAAmC,WAAiE,CAAAA,QAAM;AAClI,UAAI,CAAC,QAAQ;AACLA,eAAAA;AAAAA,MACR;AACOA,aAAAA,IAAG,MAAM,iBAAiB,SAAS,GAAG,QAAQ,MAAM,CAAC;AAAA,IAAA;AAG7D,UAAM,KAAK,cAAc,OACvB,EAAA,OAAO,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SAAS;AAElD,eAAO,IAAI,WAAW,OAAO,CAAC,MAAM,KAAK,UAAU;AAClD,cAAI,QAAQ,MAAM;AACV,mBAAA;AAAA,UACR;AACO,iBAAA,KAAK,IAAI,cAAc,KAAK,eAAe,KAAK,UAAU,GAAG,CAAC;AAAA,QAAA,GACnE,OAAO,EAAE;MACZ,CAAA,EAAE,OAAO,CAAC,OAAsB,OAAO,IAAI;AAErCA,aAAAA,IAAG,MAAM,iBAAiB,OAAO,EAAE,GAAG,iBAAiB,OAAO,GAAG,CAAC,CAAC;AAAA,IAAA,CAC1E,EAEA,MAAM,KAAK,OAAO,KAAK,MAAM;AAE/B,WAAO,qBAAqB,MAAM,GAAG,UAAU,EAAE,CAAC;AAAA,EACnD;AAED;"}
1
+ {"version":3,"file":"EventsQuery.js","sources":["../../../../../../../packages/engine-system-api/src/model/queries/events/EventsQuery.ts"],"sourcesContent":["import {\n\tConditionBuilder,\n\tDatabaseQuery,\n\tDatabaseQueryable,\n\tLiteral,\n\tOperator,\n\tSelectBuilder,\n\tSelectBuilderSpecification, Value,\n} from '@contember/database'\nimport { ContentEvent } from '../../events'\nimport { EventsFilter, EventsFilterDate, EventsOrder } from '../../../schema'\nimport { createEventsFromRows, EventRow } from './EventQueryHelpers'\n\nexport class EventsQuery extends DatabaseQuery<ContentEvent[]> {\n\tconstructor(\n\t\tprivate readonly filter: EventsFilter,\n\t\tprivate readonly order: EventsOrder,\n\t\tprivate readonly offset: number,\n\t\tprivate readonly limit: number,\n\t) {\n\t\tsuper()\n\t}\n\n\tasync fetch({ db }: DatabaseQueryable): Promise<ContentEvent[]> {\n\t\tconst createDateMatcher = (column: string, dateFilter: EventsFilterDate | undefined): SelectBuilderSpecification => qb => {\n\t\t\tif (!dateFilter) {\n\t\t\t\treturn qb\n\t\t\t}\n\t\t\tconst { from, to } = dateFilter\n\t\t\tif (from) {\n\t\t\t\tqb = qb.where(expr => expr.compare(column, Operator.gte, from))\n\t\t\t}\n\t\t\tif (to) {\n\t\t\t\tqb = qb.where(expr => expr.compare(column, Operator.lte, to))\n\t\t\t}\n\t\t\treturn qb\n\t\t}\n\t\tconst createInMatcher = (column: string | [string, string], values?: readonly Value[] | null): SelectBuilderSpecification => qb => {\n\t\t\tif (!values) {\n\t\t\t\treturn qb\n\t\t\t}\n\t\t\treturn qb.where(ConditionBuilder.create().in(column, values))\n\t\t}\n\n\t\tconst qb = SelectBuilder.create<EventRow>()\n\t\t\t.select('id')\n\t\t\t.select('type')\n\t\t\t.select('table_name')\n\t\t\t.select('row_ids')\n\t\t\t.select('values')\n\t\t\t.select('created_at')\n\t\t\t.select('applied_at')\n\t\t\t.select('identity_id')\n\t\t\t.select(['event_data', 'transaction_id'])\n\n\t\t\t.from('event_data')\n\t\t\t.join('stage_transaction', undefined, on =>\n\t\t\t\ton.columnsEq(['event_data', 'transaction_id'], ['stage_transaction', 'transaction_id']),\n\t\t\t)\n\t\t\t.match(qb => {\n\t\t\t\tswitch (this.order) {\n\t\t\t\t\tcase EventsOrder.AppliedAtAsc:\n\t\t\t\t\t\treturn qb.orderBy('applied_at', 'asc')\n\t\t\t\t\tcase EventsOrder.AppliedAtDesc:\n\t\t\t\t\t\treturn qb.orderBy('applied_at', 'desc')\n\t\t\t\t\tcase EventsOrder.CreatedAtAsc:\n\t\t\t\t\t\treturn qb.orderBy('created_at', 'asc')\n\t\t\t\t\tcase EventsOrder.CreatedAtDesc:\n\t\t\t\t\t\treturn qb.orderBy('created_at', 'desc')\n\t\t\t\t}\n\t\t\t})\n\t\t\t.match(createInMatcher('type', this.filter.types?.map(it => it.toLowerCase())))\n\t\t\t.match(createInMatcher('table_name', this.filter.tables))\n\t\t\t.match(createInMatcher('transaction_id', this.filter.transactions))\n\t\t\t.match(createInMatcher('identity_id', this.filter.identities))\n\t\t\t.match(createDateMatcher('created_at', this.filter.createdAt ?? undefined))\n\t\t\t.match(createDateMatcher('applied_at', this.filter.appliedAt ?? undefined))\n\t\t\t.match(qb => {\n\t\t\t\tif (!this.filter.rows) {\n\t\t\t\t\treturn qb\n\t\t\t\t}\n\n\t\t\t\tconst ors: Literal[] = this.filter.rows.map(row => {\n\t\t\t\t\tconst builder = ConditionBuilder.create()\n\t\t\t\t\t\t.compare('table_name', Operator.eq, row.tableName)\n\n\t\t\t\t\treturn row.primaryKey.reduce((expr, val, index) => {\n\t\t\t\t\t\tif (val === null) {\n\t\t\t\t\t\t\treturn expr\n\t\t\t\t\t\t}\n\t\t\t\t\t\treturn expr.raw(`\"row_ids\"->${index} = ?::jsonb`, JSON.stringify(val))\n\t\t\t\t\t}, builder).getSql()\n\t\t\t\t}).filter((it): it is Literal => it !== null)\n\n\t\t\t\treturn qb.where(ConditionBuilder.create().or(ConditionBuilder.create(ors)))\n\t\t\t})\n\n\t\t\t.limit(this.limit, this.offset)\n\n\t\treturn createEventsFromRows(await qb.getResult(db))\n\t}\n\n}\n"],"names":["qb"],"mappings":";;;;;AAaO,MAAM,oBAAoB,cAA8B;AAAA,EAC9D,YACkB,QACA,OACA,QACA,OAChB;AACK,UAAA;AALW,SAAA,SAAA;AACA,SAAA,QAAA;AACA,SAAA,SAAA;AACA,SAAA,QAAA;AAAA,EAAA;AAAA,EAKlB,MAAM,MAAM,EAAE,MAAkD;AAC/D,UAAM,oBAAoB,CAAC,QAAgB,eAAyE,CAAAA,QAAM;AACzH,UAAI,CAAC,YAAY;AACTA,eAAAA;AAAAA,MAAA;AAEF,YAAA,EAAE,MAAM,GAAA,IAAO;AACrB,UAAI,MAAM;AACTA,cAAKA,IAAG,MAAM,CAAQ,SAAA,KAAK,QAAQ,QAAQ,SAAS,KAAK,IAAI,CAAC;AAAA,MAAA;AAE/D,UAAI,IAAI;AACPA,cAAKA,IAAG,MAAM,CAAQ,SAAA,KAAK,QAAQ,QAAQ,SAAS,KAAK,EAAE,CAAC;AAAA,MAAA;AAEtDA,aAAAA;AAAAA,IACR;AACA,UAAM,kBAAkB,CAAC,QAAmC,WAAiE,CAAAA,QAAM;AAClI,UAAI,CAAC,QAAQ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ACfA,eAAAA;AAAAA,MAAA;AAGR,YAAM,MAAiB,KAAK,OAAO,KAAK,IAAI,CAAO,QAAA;AAC5C,cAAA,UAAU,iBAAiB,SAC/B,QAAQ,cAAc,SAAS,IAAI,IAAI,SAAS;AAElD,eAAO,IAAI,WAAW,OAAO,CAAC,MAAM,KAAK,UAAU;AAClD,cAAI,QAAQ,MAAM;AACV,mBAAA;AAAA,UAAA;AAED,iBAAA,KAAK,IAAI,cAAc,KAAK,eAAe,KAAK,UAAU,GAAG,CAAC;AAAA,QAAA,GACnE,OAAO,EAAE,OAAO;AAAA,MACnB,CAAA,EAAE,OAAO,CAAC,OAAsB,OAAO,IAAI;AAErCA,aAAAA,IAAG,MAAM,iBAAiB,OAAO,EAAE,GAAG,iBAAiB,OAAO,GAAG,CAAC,CAAC;AAAA,IAC1E,CAAA,EAEA,MAAM,KAAK,OAAO,KAAK,MAAM;AAE/B,WAAO,qBAAqB,MAAM,GAAG,UAAU,EAAE,CAAC;AAAA,EAAA;AAGpD;"}
@@ -1 +1 @@
1
- {"version":3,"file":"LatestTransactionIdByStageQuery.cjs","sources":["../../../../../../../packages/engine-system-api/src/model/queries/events/LatestTransactionIdByStageQuery.ts"],"sourcesContent":["import { DatabaseQuery, DatabaseQueryable, SelectBuilder } from '@contember/database'\nimport { ImplementationException } from '../../../utils'\n\nexport class LatestTransactionIdByStageQuery extends DatabaseQuery<string> {\n\tconstructor(private readonly stageId: string) {\n\t\tsuper()\n\t}\n\n\tasync fetch(queryable: DatabaseQueryable): Promise<string> {\n\t\tconst rows = await SelectBuilder.create<{ transaction_id: string }>()\n\t\t\t.from('stage_transaction')\n\t\t\t.select('transaction_id')\n\t\t\t.where({ stage_id: this.stageId })\n\t\t\t.orderBy('applied_at', 'desc')\n\t\t\t.limit(1)\n\t\t\t.getResult(queryable.db)\n\n\t\tif (rows.length !== 1) {\n\t\t\tthrow new ImplementationException()\n\t\t}\n\t\treturn rows[0].transaction_id\n\t}\n}\n"],"names":["DatabaseQuery","SelectBuilder","ImplementationException"],"mappings":";;;;AAGO,MAAM,wCAAwCA,SAAAA,cAAsB;AAAA,EAC1E,YAA6B,SAAiB;AACvC;AADsB,SAAA,UAAA;AAAA,EAE7B;AAAA,EAEA,MAAM,MAAM,WAA+C;AACpD,UAAA,OAAO,MAAMC,uBAAc,OAAmC,EAClE,KAAK,mBAAmB,EACxB,OAAO,gBAAgB,EACvB,MAAM,EAAE,UAAU,KAAK,SAAS,EAChC,QAAQ,cAAc,MAAM,EAC5B,MAAM,CAAC,EACP,UAAU,UAAU,EAAE;AAEpB,QAAA,KAAK,WAAW,GAAG;AACtB,YAAM,IAAIC,WAAwB,wBAAA;AAAA,IACnC;AACO,WAAA,KAAK,CAAC,EAAE;AAAA,EAChB;AACD;;"}
1
+ {"version":3,"file":"LatestTransactionIdByStageQuery.cjs","sources":["../../../../../../../packages/engine-system-api/src/model/queries/events/LatestTransactionIdByStageQuery.ts"],"sourcesContent":["import { DatabaseQuery, DatabaseQueryable, SelectBuilder } from '@contember/database'\nimport { ImplementationException } from '../../../utils'\n\nexport class LatestTransactionIdByStageQuery extends DatabaseQuery<string> {\n\tconstructor(private readonly stageId: string) {\n\t\tsuper()\n\t}\n\n\tasync fetch(queryable: DatabaseQueryable): Promise<string> {\n\t\tconst rows = await SelectBuilder.create<{ transaction_id: string }>()\n\t\t\t.from('stage_transaction')\n\t\t\t.select('transaction_id')\n\t\t\t.where({ stage_id: this.stageId })\n\t\t\t.orderBy('applied_at', 'desc')\n\t\t\t.limit(1)\n\t\t\t.getResult(queryable.db)\n\n\t\tif (rows.length !== 1) {\n\t\t\tthrow new ImplementationException()\n\t\t}\n\t\treturn rows[0].transaction_id\n\t}\n}\n"],"names":["DatabaseQuery","SelectBuilder","ImplementationException"],"mappings":";;;;AAGO,MAAM,wCAAwCA,SAAAA,cAAsB;AAAA,EAC1E,YAA6B,SAAiB;AACvC,UAAA;AADsB,SAAA,UAAA;AAAA,EAAA;AAAA,EAI7B,MAAM,MAAM,WAA+C;AACpD,UAAA,OAAO,MAAMC,uBAAc,SAC/B,KAAK,mBAAmB,EACxB,OAAO,gBAAgB,EACvB,MAAM,EAAE,UAAU,KAAK,QAAS,CAAA,EAChC,QAAQ,cAAc,MAAM,EAC5B,MAAM,CAAC,EACP,UAAU,UAAU,EAAE;AAEpB,QAAA,KAAK,WAAW,GAAG;AACtB,YAAM,IAAIC,WAAAA,wBAAwB;AAAA,IAAA;AAE5B,WAAA,KAAK,CAAC,EAAE;AAAA,EAAA;AAEjB;;"}
@@ -1 +1 @@
1
- {"version":3,"file":"LatestTransactionIdByStageQuery.js","sources":["../../../../../../../packages/engine-system-api/src/model/queries/events/LatestTransactionIdByStageQuery.ts"],"sourcesContent":["import { DatabaseQuery, DatabaseQueryable, SelectBuilder } from '@contember/database'\nimport { ImplementationException } from '../../../utils'\n\nexport class LatestTransactionIdByStageQuery extends DatabaseQuery<string> {\n\tconstructor(private readonly stageId: string) {\n\t\tsuper()\n\t}\n\n\tasync fetch(queryable: DatabaseQueryable): Promise<string> {\n\t\tconst rows = await SelectBuilder.create<{ transaction_id: string }>()\n\t\t\t.from('stage_transaction')\n\t\t\t.select('transaction_id')\n\t\t\t.where({ stage_id: this.stageId })\n\t\t\t.orderBy('applied_at', 'desc')\n\t\t\t.limit(1)\n\t\t\t.getResult(queryable.db)\n\n\t\tif (rows.length !== 1) {\n\t\t\tthrow new ImplementationException()\n\t\t}\n\t\treturn rows[0].transaction_id\n\t}\n}\n"],"names":[],"mappings":";;AAGO,MAAM,wCAAwC,cAAsB;AAAA,EAC1E,YAA6B,SAAiB;AACvC;AADsB,SAAA,UAAA;AAAA,EAE7B;AAAA,EAEA,MAAM,MAAM,WAA+C;AACpD,UAAA,OAAO,MAAM,cAAc,OAAmC,EAClE,KAAK,mBAAmB,EACxB,OAAO,gBAAgB,EACvB,MAAM,EAAE,UAAU,KAAK,SAAS,EAChC,QAAQ,cAAc,MAAM,EAC5B,MAAM,CAAC,EACP,UAAU,UAAU,EAAE;AAEpB,QAAA,KAAK,WAAW,GAAG;AACtB,YAAM,IAAI,wBAAwB;AAAA,IACnC;AACO,WAAA,KAAK,CAAC,EAAE;AAAA,EAChB;AACD;"}
1
+ {"version":3,"file":"LatestTransactionIdByStageQuery.js","sources":["../../../../../../../packages/engine-system-api/src/model/queries/events/LatestTransactionIdByStageQuery.ts"],"sourcesContent":["import { DatabaseQuery, DatabaseQueryable, SelectBuilder } from '@contember/database'\nimport { ImplementationException } from '../../../utils'\n\nexport class LatestTransactionIdByStageQuery extends DatabaseQuery<string> {\n\tconstructor(private readonly stageId: string) {\n\t\tsuper()\n\t}\n\n\tasync fetch(queryable: DatabaseQueryable): Promise<string> {\n\t\tconst rows = await SelectBuilder.create<{ transaction_id: string }>()\n\t\t\t.from('stage_transaction')\n\t\t\t.select('transaction_id')\n\t\t\t.where({ stage_id: this.stageId })\n\t\t\t.orderBy('applied_at', 'desc')\n\t\t\t.limit(1)\n\t\t\t.getResult(queryable.db)\n\n\t\tif (rows.length !== 1) {\n\t\t\tthrow new ImplementationException()\n\t\t}\n\t\treturn rows[0].transaction_id\n\t}\n}\n"],"names":[],"mappings":";;AAGO,MAAM,wCAAwC,cAAsB;AAAA,EAC1E,YAA6B,SAAiB;AACvC,UAAA;AADsB,SAAA,UAAA;AAAA,EAAA;AAAA,EAI7B,MAAM,MAAM,WAA+C;AACpD,UAAA,OAAO,MAAM,cAAc,SAC/B,KAAK,mBAAmB,EACxB,OAAO,gBAAgB,EACvB,MAAM,EAAE,UAAU,KAAK,QAAS,CAAA,EAChC,QAAQ,cAAc,MAAM,EAC5B,MAAM,CAAC,EACP,UAAU,UAAU,EAAE;AAEpB,QAAA,KAAK,WAAW,GAAG;AACtB,YAAM,IAAI,wBAAwB;AAAA,IAAA;AAE5B,WAAA,KAAK,CAAC,EAAE;AAAA,EAAA;AAEjB;"}
@@ -1 +1 @@
1
- {"version":3,"file":"OldValuesQuery.cjs","sources":["../../../../../../../packages/engine-system-api/src/model/queries/events/OldValuesQuery.ts"],"sourcesContent":["import { DatabaseQuery, DatabaseQueryable, Literal, Operator, SelectBuilder } from '@contember/database'\n\nexport class OldValuesQuery extends DatabaseQuery<Record<string, any>> {\n\tconstructor(private readonly ids: string[]) {\n\t\tsuper()\n\t}\n\n\tasync fetch(queryable: DatabaseQueryable): Promise<Record<string, any>> {\n\t\tconst qb = SelectBuilder.create()\n\t\t\t.select(expr => expr.raw('JSONB_OBJECT_AGG(values.key, values.value ORDER BY previous.created_at ASC)'), 'values')\n\t\t\t.select(['event_data', 'id'])\n\t\t\t.from('event_data')\n\t\t\t.join('event_data', 'previous', on => on\n\t\t\t\t.columnsEq(['event_data', 'row_ids'], ['previous', 'row_ids'])\n\t\t\t\t.compareColumns(['event_data', 'created_at'], Operator.gt, ['previous', 'created_at']),\n\t\t\t)\n\t\t\t.join(new Literal('JSONB_EACH(previous.values)'), 'values')\n\t\t\t.where(where => where.in(['event_data', 'id'], this.ids))\n\t\t\t.groupBy(['event_data', 'id'])\n\n\t\treturn Object.fromEntries((await qb.getResult(queryable.db)).map(it => [it.id, it.values]))\n\t}\n}\n"],"names":["DatabaseQuery","SelectBuilder","Operator","Literal"],"mappings":";;;AAEO,MAAM,uBAAuBA,SAAAA,cAAmC;AAAA,EACtE,YAA6B,KAAe;AACrC;AADsB,SAAA,MAAA;AAAA,EAE7B;AAAA,EAEA,MAAM,MAAM,WAA4D;AACjE,UAAA,KAAKC,uBAAc,OAAO,EAC9B,OAAO,CAAQ,SAAA,KAAK,IAAI,6EAA6E,GAAG,QAAQ,EAChH,OAAO,CAAC,cAAc,IAAI,CAAC,EAC3B,KAAK,YAAY,EACjB;AAAA,MAAK;AAAA,MAAc;AAAA,MAAY,CAAA,OAAM,GACpC,UAAU,CAAC,cAAc,SAAS,GAAG,CAAC,YAAY,SAAS,CAAC,EAC5D,eAAe,CAAC,cAAc,YAAY,GAAGC,kBAAS,IAAI,CAAC,YAAY,YAAY,CAAC;AAAA,IAAA,EAErF,KAAK,IAAIC,SAAQ,QAAA,6BAA6B,GAAG,QAAQ,EACzD,MAAM,CAAA,UAAS,MAAM,GAAG,CAAC,cAAc,IAAI,GAAG,KAAK,GAAG,CAAC,EACvD,QAAQ,CAAC,cAAc,IAAI,CAAC;AAE9B,WAAO,OAAO,aAAa,MAAM,GAAG,UAAU,UAAU,EAAE,GAAG,IAAI,CAAA,OAAM,CAAC,GAAG,IAAI,GAAG,MAAM,CAAC,CAAC;AAAA,EAC3F;AACD;;"}
1
+ {"version":3,"file":"OldValuesQuery.cjs","sources":["../../../../../../../packages/engine-system-api/src/model/queries/events/OldValuesQuery.ts"],"sourcesContent":["import { DatabaseQuery, DatabaseQueryable, Literal, Operator, SelectBuilder } from '@contember/database'\n\nexport class OldValuesQuery extends DatabaseQuery<Record<string, any>> {\n\tconstructor(private readonly ids: string[]) {\n\t\tsuper()\n\t}\n\n\tasync fetch(queryable: DatabaseQueryable): Promise<Record<string, any>> {\n\t\tconst qb = SelectBuilder.create()\n\t\t\t.select(expr => expr.raw('JSONB_OBJECT_AGG(values.key, values.value ORDER BY previous.created_at ASC)'), 'values')\n\t\t\t.select(['event_data', 'id'])\n\t\t\t.from('event_data')\n\t\t\t.join('event_data', 'previous', on => on\n\t\t\t\t.columnsEq(['event_data', 'row_ids'], ['previous', 'row_ids'])\n\t\t\t\t.compareColumns(['event_data', 'created_at'], Operator.gt, ['previous', 'created_at']),\n\t\t\t)\n\t\t\t.join(new Literal('JSONB_EACH(previous.values)'), 'values')\n\t\t\t.where(where => where.in(['event_data', 'id'], this.ids))\n\t\t\t.groupBy(['event_data', 'id'])\n\n\t\treturn Object.fromEntries((await qb.getResult(queryable.db)).map(it => [it.id, it.values]))\n\t}\n}\n"],"names":["DatabaseQuery","SelectBuilder","Operator","Literal"],"mappings":";;;AAEO,MAAM,uBAAuBA,SAAAA,cAAmC;AAAA,EACtE,YAA6B,KAAe;AACrC,UAAA;AADsB,SAAA,MAAA;AAAA,EAAA;AAAA,EAI7B,MAAM,MAAM,WAA4D;AACjE,UAAA,KAAKC,uBAAc,OAAO,EAC9B,OAAO,CAAQ,SAAA,KAAK,IAAI,6EAA6E,GAAG,QAAQ,EAChH,OAAO,CAAC,cAAc,IAAI,CAAC,EAC3B,KAAK,YAAY,EACjB;AAAA,MAAK;AAAA,MAAc;AAAA,MAAY,CAAA,OAAM,GACpC,UAAU,CAAC,cAAc,SAAS,GAAG,CAAC,YAAY,SAAS,CAAC,EAC5D,eAAe,CAAC,cAAc,YAAY,GAAGC,kBAAS,IAAI,CAAC,YAAY,YAAY,CAAC;AAAA,IAAA,EAErF,KAAK,IAAIC,SAAQ,QAAA,6BAA6B,GAAG,QAAQ,EACzD,MAAM,CAAA,UAAS,MAAM,GAAG,CAAC,cAAc,IAAI,GAAG,KAAK,GAAG,CAAC,EACvD,QAAQ,CAAC,cAAc,IAAI,CAAC;AAE9B,WAAO,OAAO,aAAa,MAAM,GAAG,UAAU,UAAU,EAAE,GAAG,IAAI,CAAA,OAAM,CAAC,GAAG,IAAI,GAAG,MAAM,CAAC,CAAC;AAAA,EAAA;AAE5F;;"}
@@ -1 +1 @@
1
- {"version":3,"file":"OldValuesQuery.js","sources":["../../../../../../../packages/engine-system-api/src/model/queries/events/OldValuesQuery.ts"],"sourcesContent":["import { DatabaseQuery, DatabaseQueryable, Literal, Operator, SelectBuilder } from '@contember/database'\n\nexport class OldValuesQuery extends DatabaseQuery<Record<string, any>> {\n\tconstructor(private readonly ids: string[]) {\n\t\tsuper()\n\t}\n\n\tasync fetch(queryable: DatabaseQueryable): Promise<Record<string, any>> {\n\t\tconst qb = SelectBuilder.create()\n\t\t\t.select(expr => expr.raw('JSONB_OBJECT_AGG(values.key, values.value ORDER BY previous.created_at ASC)'), 'values')\n\t\t\t.select(['event_data', 'id'])\n\t\t\t.from('event_data')\n\t\t\t.join('event_data', 'previous', on => on\n\t\t\t\t.columnsEq(['event_data', 'row_ids'], ['previous', 'row_ids'])\n\t\t\t\t.compareColumns(['event_data', 'created_at'], Operator.gt, ['previous', 'created_at']),\n\t\t\t)\n\t\t\t.join(new Literal('JSONB_EACH(previous.values)'), 'values')\n\t\t\t.where(where => where.in(['event_data', 'id'], this.ids))\n\t\t\t.groupBy(['event_data', 'id'])\n\n\t\treturn Object.fromEntries((await qb.getResult(queryable.db)).map(it => [it.id, it.values]))\n\t}\n}\n"],"names":[],"mappings":";AAEO,MAAM,uBAAuB,cAAmC;AAAA,EACtE,YAA6B,KAAe;AACrC;AADsB,SAAA,MAAA;AAAA,EAE7B;AAAA,EAEA,MAAM,MAAM,WAA4D;AACjE,UAAA,KAAK,cAAc,OAAO,EAC9B,OAAO,CAAQ,SAAA,KAAK,IAAI,6EAA6E,GAAG,QAAQ,EAChH,OAAO,CAAC,cAAc,IAAI,CAAC,EAC3B,KAAK,YAAY,EACjB;AAAA,MAAK;AAAA,MAAc;AAAA,MAAY,CAAA,OAAM,GACpC,UAAU,CAAC,cAAc,SAAS,GAAG,CAAC,YAAY,SAAS,CAAC,EAC5D,eAAe,CAAC,cAAc,YAAY,GAAG,SAAS,IAAI,CAAC,YAAY,YAAY,CAAC;AAAA,IAAA,EAErF,KAAK,IAAI,QAAQ,6BAA6B,GAAG,QAAQ,EACzD,MAAM,CAAA,UAAS,MAAM,GAAG,CAAC,cAAc,IAAI,GAAG,KAAK,GAAG,CAAC,EACvD,QAAQ,CAAC,cAAc,IAAI,CAAC;AAE9B,WAAO,OAAO,aAAa,MAAM,GAAG,UAAU,UAAU,EAAE,GAAG,IAAI,CAAA,OAAM,CAAC,GAAG,IAAI,GAAG,MAAM,CAAC,CAAC;AAAA,EAC3F;AACD;"}
1
+ {"version":3,"file":"OldValuesQuery.js","sources":["../../../../../../../packages/engine-system-api/src/model/queries/events/OldValuesQuery.ts"],"sourcesContent":["import { DatabaseQuery, DatabaseQueryable, Literal, Operator, SelectBuilder } from '@contember/database'\n\nexport class OldValuesQuery extends DatabaseQuery<Record<string, any>> {\n\tconstructor(private readonly ids: string[]) {\n\t\tsuper()\n\t}\n\n\tasync fetch(queryable: DatabaseQueryable): Promise<Record<string, any>> {\n\t\tconst qb = SelectBuilder.create()\n\t\t\t.select(expr => expr.raw('JSONB_OBJECT_AGG(values.key, values.value ORDER BY previous.created_at ASC)'), 'values')\n\t\t\t.select(['event_data', 'id'])\n\t\t\t.from('event_data')\n\t\t\t.join('event_data', 'previous', on => on\n\t\t\t\t.columnsEq(['event_data', 'row_ids'], ['previous', 'row_ids'])\n\t\t\t\t.compareColumns(['event_data', 'created_at'], Operator.gt, ['previous', 'created_at']),\n\t\t\t)\n\t\t\t.join(new Literal('JSONB_EACH(previous.values)'), 'values')\n\t\t\t.where(where => where.in(['event_data', 'id'], this.ids))\n\t\t\t.groupBy(['event_data', 'id'])\n\n\t\treturn Object.fromEntries((await qb.getResult(queryable.db)).map(it => [it.id, it.values]))\n\t}\n}\n"],"names":[],"mappings":";AAEO,MAAM,uBAAuB,cAAmC;AAAA,EACtE,YAA6B,KAAe;AACrC,UAAA;AADsB,SAAA,MAAA;AAAA,EAAA;AAAA,EAI7B,MAAM,MAAM,WAA4D;AACjE,UAAA,KAAK,cAAc,OAAO,EAC9B,OAAO,CAAQ,SAAA,KAAK,IAAI,6EAA6E,GAAG,QAAQ,EAChH,OAAO,CAAC,cAAc,IAAI,CAAC,EAC3B,KAAK,YAAY,EACjB;AAAA,MAAK;AAAA,MAAc;AAAA,MAAY,CAAA,OAAM,GACpC,UAAU,CAAC,cAAc,SAAS,GAAG,CAAC,YAAY,SAAS,CAAC,EAC5D,eAAe,CAAC,cAAc,YAAY,GAAG,SAAS,IAAI,CAAC,YAAY,YAAY,CAAC;AAAA,IAAA,EAErF,KAAK,IAAI,QAAQ,6BAA6B,GAAG,QAAQ,EACzD,MAAM,CAAA,UAAS,MAAM,GAAG,CAAC,cAAc,IAAI,GAAG,KAAK,GAAG,CAAC,EACvD,QAAQ,CAAC,cAAc,IAAI,CAAC;AAE9B,WAAO,OAAO,aAAa,MAAM,GAAG,UAAU,UAAU,EAAE,GAAG,IAAI,CAAA,OAAM,CAAC,GAAG,IAAI,GAAG,MAAM,CAAC,CAAC;AAAA,EAAA;AAE5F;"}
@@ -1 +1 @@
1
- {"version":3,"file":"ExecutedMigrationByVersionQuery.cjs","sources":["../../../../../../../packages/engine-system-api/src/model/queries/migrations/ExecutedMigrationByVersionQuery.ts"],"sourcesContent":["import { DatabaseQuery, DatabaseQueryable } from '@contember/database'\nimport { ExecutedMigration } from '../../dtos'\nimport { createExecutedMigrationDto, createExecutedMigrationQueryBuilder } from './ExecutedMigrationsQueryHelper'\n\nexport class ExecutedMigrationByVersionQuery extends DatabaseQuery<ExecutedMigration | null> {\n\tconstructor(private version: string) {\n\t\tsuper()\n\t}\n\n\tasync fetch(queryable: DatabaseQueryable): Promise<ExecutedMigration | null> {\n\t\tconst builder = createExecutedMigrationQueryBuilder().where({ version: this.version })\n\t\tconst rows = await builder.getResult(queryable.db)\n\t\tconst migration = await this.fetchOneOrNull(rows)\n\t\treturn migration ? createExecutedMigrationDto(migration) : null\n\t}\n}\n"],"names":["DatabaseQuery","createExecutedMigrationQueryBuilder","createExecutedMigrationDto"],"mappings":";;;;AAIO,MAAM,wCAAwCA,SAAAA,cAAwC;AAAA,EAC5F,YAAoB,SAAiB;AAC9B;AADa,SAAA,UAAA;AAAA,EAEpB;AAAA,EAEA,MAAM,MAAM,WAAiE;AACtE,UAAA,UAAUC,oEAAsC,MAAM,EAAE,SAAS,KAAK,SAAS;AACrF,UAAM,OAAO,MAAM,QAAQ,UAAU,UAAU,EAAE;AACjD,UAAM,YAAY,MAAM,KAAK,eAAe,IAAI;AACzC,WAAA,YAAYC,8BAAAA,2BAA2B,SAAS,IAAI;AAAA,EAC5D;AACD;;"}
1
+ {"version":3,"file":"ExecutedMigrationByVersionQuery.cjs","sources":["../../../../../../../packages/engine-system-api/src/model/queries/migrations/ExecutedMigrationByVersionQuery.ts"],"sourcesContent":["import { DatabaseQuery, DatabaseQueryable } from '@contember/database'\nimport { ExecutedMigration } from '../../dtos'\nimport { createExecutedMigrationDto, createExecutedMigrationQueryBuilder } from './ExecutedMigrationsQueryHelper'\n\nexport class ExecutedMigrationByVersionQuery extends DatabaseQuery<ExecutedMigration | null> {\n\tconstructor(private version: string) {\n\t\tsuper()\n\t}\n\n\tasync fetch(queryable: DatabaseQueryable): Promise<ExecutedMigration | null> {\n\t\tconst builder = createExecutedMigrationQueryBuilder().where({ version: this.version })\n\t\tconst rows = await builder.getResult(queryable.db)\n\t\tconst migration = await this.fetchOneOrNull(rows)\n\t\treturn migration ? createExecutedMigrationDto(migration) : null\n\t}\n}\n"],"names":["DatabaseQuery","createExecutedMigrationQueryBuilder","createExecutedMigrationDto"],"mappings":";;;;AAIO,MAAM,wCAAwCA,SAAAA,cAAwC;AAAA,EAC5F,YAAoB,SAAiB;AAC9B,UAAA;AADa,SAAA,UAAA;AAAA,EAAA;AAAA,EAIpB,MAAM,MAAM,WAAiE;AACtE,UAAA,UAAUC,8BAAAA,sCAAsC,MAAM,EAAE,SAAS,KAAK,SAAS;AACrF,UAAM,OAAO,MAAM,QAAQ,UAAU,UAAU,EAAE;AACjD,UAAM,YAAY,MAAM,KAAK,eAAe,IAAI;AACzC,WAAA,YAAYC,8BAAAA,2BAA2B,SAAS,IAAI;AAAA,EAAA;AAE7D;;"}
@@ -1 +1 @@
1
- {"version":3,"file":"ExecutedMigrationByVersionQuery.js","sources":["../../../../../../../packages/engine-system-api/src/model/queries/migrations/ExecutedMigrationByVersionQuery.ts"],"sourcesContent":["import { DatabaseQuery, DatabaseQueryable } from '@contember/database'\nimport { ExecutedMigration } from '../../dtos'\nimport { createExecutedMigrationDto, createExecutedMigrationQueryBuilder } from './ExecutedMigrationsQueryHelper'\n\nexport class ExecutedMigrationByVersionQuery extends DatabaseQuery<ExecutedMigration | null> {\n\tconstructor(private version: string) {\n\t\tsuper()\n\t}\n\n\tasync fetch(queryable: DatabaseQueryable): Promise<ExecutedMigration | null> {\n\t\tconst builder = createExecutedMigrationQueryBuilder().where({ version: this.version })\n\t\tconst rows = await builder.getResult(queryable.db)\n\t\tconst migration = await this.fetchOneOrNull(rows)\n\t\treturn migration ? createExecutedMigrationDto(migration) : null\n\t}\n}\n"],"names":[],"mappings":";;AAIO,MAAM,wCAAwC,cAAwC;AAAA,EAC5F,YAAoB,SAAiB;AAC9B;AADa,SAAA,UAAA;AAAA,EAEpB;AAAA,EAEA,MAAM,MAAM,WAAiE;AACtE,UAAA,UAAU,sCAAsC,MAAM,EAAE,SAAS,KAAK,SAAS;AACrF,UAAM,OAAO,MAAM,QAAQ,UAAU,UAAU,EAAE;AACjD,UAAM,YAAY,MAAM,KAAK,eAAe,IAAI;AACzC,WAAA,YAAY,2BAA2B,SAAS,IAAI;AAAA,EAC5D;AACD;"}
1
+ {"version":3,"file":"ExecutedMigrationByVersionQuery.js","sources":["../../../../../../../packages/engine-system-api/src/model/queries/migrations/ExecutedMigrationByVersionQuery.ts"],"sourcesContent":["import { DatabaseQuery, DatabaseQueryable } from '@contember/database'\nimport { ExecutedMigration } from '../../dtos'\nimport { createExecutedMigrationDto, createExecutedMigrationQueryBuilder } from './ExecutedMigrationsQueryHelper'\n\nexport class ExecutedMigrationByVersionQuery extends DatabaseQuery<ExecutedMigration | null> {\n\tconstructor(private version: string) {\n\t\tsuper()\n\t}\n\n\tasync fetch(queryable: DatabaseQueryable): Promise<ExecutedMigration | null> {\n\t\tconst builder = createExecutedMigrationQueryBuilder().where({ version: this.version })\n\t\tconst rows = await builder.getResult(queryable.db)\n\t\tconst migration = await this.fetchOneOrNull(rows)\n\t\treturn migration ? createExecutedMigrationDto(migration) : null\n\t}\n}\n"],"names":[],"mappings":";;AAIO,MAAM,wCAAwC,cAAwC;AAAA,EAC5F,YAAoB,SAAiB;AAC9B,UAAA;AADa,SAAA,UAAA;AAAA,EAAA;AAAA,EAIpB,MAAM,MAAM,WAAiE;AACtE,UAAA,UAAU,sCAAsC,MAAM,EAAE,SAAS,KAAK,SAAS;AACrF,UAAM,OAAO,MAAM,QAAQ,UAAU,UAAU,EAAE;AACjD,UAAM,YAAY,MAAM,KAAK,eAAe,IAAI;AACzC,WAAA,YAAY,2BAA2B,SAAS,IAAI;AAAA,EAAA;AAE7D;"}
@@ -1 +1 @@
1
- {"version":3,"file":"ExecutedMigrationsQuery.cjs","sources":["../../../../../../../packages/engine-system-api/src/model/queries/migrations/ExecutedMigrationsQuery.ts"],"sourcesContent":["import { DatabaseQuery, DatabaseQueryable, Operator } from '@contember/database'\nimport { ExecutedMigration } from '../../dtos'\nimport { createExecutedMigrationDto, createExecutedMigrationQueryBuilder } from './ExecutedMigrationsQueryHelper'\n\nexport class ExecutedMigrationsQuery extends DatabaseQuery<ExecutedMigration[]> {\n\tconstructor(private afterVersion?: string) {\n\t\tsuper()\n\t}\n\n\tasync fetch(queryable: DatabaseQueryable): Promise<ExecutedMigration[]> {\n\t\tconst builder = createExecutedMigrationQueryBuilder()\n\t\tconst afterVersion = this.afterVersion\n\t\tconst builderWithWhere = afterVersion\n\t\t\t? builder.where(expr => expr.compare('version', Operator.gt, afterVersion))\n\t\t\t: builder\n\n\t\tconst result = await builderWithWhere.getResult(queryable.db)\n\t\treturn result.map(createExecutedMigrationDto)\n\t}\n}\n"],"names":["DatabaseQuery","createExecutedMigrationQueryBuilder","Operator","createExecutedMigrationDto"],"mappings":";;;;AAIO,MAAM,gCAAgCA,SAAAA,cAAmC;AAAA,EAC/E,YAAoB,cAAuB;AACpC;AADa,SAAA,eAAA;AAAA,EAEpB;AAAA,EAEA,MAAM,MAAM,WAA4D;AACvE,UAAM,UAAUC,8BAAAA;AAChB,UAAM,eAAe,KAAK;AAC1B,UAAM,mBAAmB,eACtB,QAAQ,MAAM,CAAQ,SAAA,KAAK,QAAQ,WAAWC,SAAAA,SAAS,IAAI,YAAY,CAAC,IACxE;AAEH,UAAM,SAAS,MAAM,iBAAiB,UAAU,UAAU,EAAE;AACrD,WAAA,OAAO,IAAIC,8BAAAA,0BAA0B;AAAA,EAC7C;AACD;;"}
1
+ {"version":3,"file":"ExecutedMigrationsQuery.cjs","sources":["../../../../../../../packages/engine-system-api/src/model/queries/migrations/ExecutedMigrationsQuery.ts"],"sourcesContent":["import { DatabaseQuery, DatabaseQueryable, Operator } from '@contember/database'\nimport { ExecutedMigration } from '../../dtos'\nimport { createExecutedMigrationDto, createExecutedMigrationQueryBuilder } from './ExecutedMigrationsQueryHelper'\n\nexport class ExecutedMigrationsQuery extends DatabaseQuery<ExecutedMigration[]> {\n\tconstructor(private afterVersion?: string) {\n\t\tsuper()\n\t}\n\n\tasync fetch(queryable: DatabaseQueryable): Promise<ExecutedMigration[]> {\n\t\tconst builder = createExecutedMigrationQueryBuilder()\n\t\tconst afterVersion = this.afterVersion\n\t\tconst builderWithWhere = afterVersion\n\t\t\t? builder.where(expr => expr.compare('version', Operator.gt, afterVersion))\n\t\t\t: builder\n\n\t\tconst result = await builderWithWhere.getResult(queryable.db)\n\t\treturn result.map(createExecutedMigrationDto)\n\t}\n}\n"],"names":["DatabaseQuery","createExecutedMigrationQueryBuilder","Operator","createExecutedMigrationDto"],"mappings":";;;;AAIO,MAAM,gCAAgCA,SAAAA,cAAmC;AAAA,EAC/E,YAAoB,cAAuB;AACpC,UAAA;AADa,SAAA,eAAA;AAAA,EAAA;AAAA,EAIpB,MAAM,MAAM,WAA4D;AACvE,UAAM,UAAUC,8BAAAA,oCAAoC;AACpD,UAAM,eAAe,KAAK;AAC1B,UAAM,mBAAmB,eACtB,QAAQ,MAAM,CAAQ,SAAA,KAAK,QAAQ,WAAWC,SAAS,SAAA,IAAI,YAAY,CAAC,IACxE;AAEH,UAAM,SAAS,MAAM,iBAAiB,UAAU,UAAU,EAAE;AACrD,WAAA,OAAO,IAAIC,wDAA0B;AAAA,EAAA;AAE9C;;"}
@@ -1 +1 @@
1
- {"version":3,"file":"ExecutedMigrationsQuery.js","sources":["../../../../../../../packages/engine-system-api/src/model/queries/migrations/ExecutedMigrationsQuery.ts"],"sourcesContent":["import { DatabaseQuery, DatabaseQueryable, Operator } from '@contember/database'\nimport { ExecutedMigration } from '../../dtos'\nimport { createExecutedMigrationDto, createExecutedMigrationQueryBuilder } from './ExecutedMigrationsQueryHelper'\n\nexport class ExecutedMigrationsQuery extends DatabaseQuery<ExecutedMigration[]> {\n\tconstructor(private afterVersion?: string) {\n\t\tsuper()\n\t}\n\n\tasync fetch(queryable: DatabaseQueryable): Promise<ExecutedMigration[]> {\n\t\tconst builder = createExecutedMigrationQueryBuilder()\n\t\tconst afterVersion = this.afterVersion\n\t\tconst builderWithWhere = afterVersion\n\t\t\t? builder.where(expr => expr.compare('version', Operator.gt, afterVersion))\n\t\t\t: builder\n\n\t\tconst result = await builderWithWhere.getResult(queryable.db)\n\t\treturn result.map(createExecutedMigrationDto)\n\t}\n}\n"],"names":[],"mappings":";;AAIO,MAAM,gCAAgC,cAAmC;AAAA,EAC/E,YAAoB,cAAuB;AACpC;AADa,SAAA,eAAA;AAAA,EAEpB;AAAA,EAEA,MAAM,MAAM,WAA4D;AACvE,UAAM,UAAU;AAChB,UAAM,eAAe,KAAK;AAC1B,UAAM,mBAAmB,eACtB,QAAQ,MAAM,CAAQ,SAAA,KAAK,QAAQ,WAAW,SAAS,IAAI,YAAY,CAAC,IACxE;AAEH,UAAM,SAAS,MAAM,iBAAiB,UAAU,UAAU,EAAE;AACrD,WAAA,OAAO,IAAI,0BAA0B;AAAA,EAC7C;AACD;"}
1
+ {"version":3,"file":"ExecutedMigrationsQuery.js","sources":["../../../../../../../packages/engine-system-api/src/model/queries/migrations/ExecutedMigrationsQuery.ts"],"sourcesContent":["import { DatabaseQuery, DatabaseQueryable, Operator } from '@contember/database'\nimport { ExecutedMigration } from '../../dtos'\nimport { createExecutedMigrationDto, createExecutedMigrationQueryBuilder } from './ExecutedMigrationsQueryHelper'\n\nexport class ExecutedMigrationsQuery extends DatabaseQuery<ExecutedMigration[]> {\n\tconstructor(private afterVersion?: string) {\n\t\tsuper()\n\t}\n\n\tasync fetch(queryable: DatabaseQueryable): Promise<ExecutedMigration[]> {\n\t\tconst builder = createExecutedMigrationQueryBuilder()\n\t\tconst afterVersion = this.afterVersion\n\t\tconst builderWithWhere = afterVersion\n\t\t\t? builder.where(expr => expr.compare('version', Operator.gt, afterVersion))\n\t\t\t: builder\n\n\t\tconst result = await builderWithWhere.getResult(queryable.db)\n\t\treturn result.map(createExecutedMigrationDto)\n\t}\n}\n"],"names":[],"mappings":";;AAIO,MAAM,gCAAgC,cAAmC;AAAA,EAC/E,YAAoB,cAAuB;AACpC,UAAA;AADa,SAAA,eAAA;AAAA,EAAA;AAAA,EAIpB,MAAM,MAAM,WAA4D;AACvE,UAAM,UAAU,oCAAoC;AACpD,UAAM,eAAe,KAAK;AAC1B,UAAM,mBAAmB,eACtB,QAAQ,MAAM,CAAQ,SAAA,KAAK,QAAQ,WAAW,SAAS,IAAI,YAAY,CAAC,IACxE;AAEH,UAAM,SAAS,MAAM,iBAAiB,UAAU,UAAU,EAAE;AACrD,WAAA,OAAO,IAAI,0BAA0B;AAAA,EAAA;AAE9C;"}
@@ -1 +1 @@
1
- {"version":3,"file":"SchemaQuery.cjs","sources":["../../../../../../../packages/engine-system-api/src/model/queries/schema/SchemaQuery.ts"],"sourcesContent":["import { DatabaseQuery, DatabaseQueryable, Literal, SelectBuilder } from '@contember/database'\nimport { Schema } from '@contember/schema'\nimport { SchemaWithMeta } from '../../migrations'\n\nexport class SchemaQuery extends DatabaseQuery<SchemaWithMeta | null> {\n\n\tconstructor(\n\t\tprivate readonly currentHash?: string,\n\t) {\n\t\tsuper()\n\t}\n\n\n\tasync fetch(queryable: DatabaseQueryable): Promise<SchemaWithMeta | null> {\n\t\tconst query = SelectBuilder.create<{\n\t\t\tschema: Schema\n\t\t\tchecksum: string\n\t\t\tversion: string\n\t\t\tupdated_at: Date\n\t\t\tmigration_id: number\n\t\t}>()\n\t\t\t.from('schema')\n\t\t\t.select(new Literal('*'))\n\t\t\t.where({\n\t\t\t\tid: 'single',\n\t\t\t})\n\t\t\t.match(it => {\n\t\t\t\tif (!this.currentHash) {\n\t\t\t\t\treturn it\n\t\t\t\t}\n\t\t\t\treturn it.where(it => it.raw('checksum != ?', this.currentHash))\n\t\t\t})\n\n\t\tconst row = this.fetchOneOrNull(await query.getResult(queryable.db))\n\t\tif (!row) {\n\t\t\treturn null\n\t\t}\n\t\treturn {\n\t\t\tschema: row.schema,\n\t\t\tmeta: {\n\t\t\t\tchecksum: row.checksum,\n\t\t\t\tversion: row.version,\n\t\t\t\tupdatedAt: row.updated_at,\n\t\t\t\tid: row.migration_id,\n\t\t\t},\n\t\t}\n\t}\n}\n"],"names":["DatabaseQuery","SelectBuilder","Literal","it"],"mappings":";;;AAIO,MAAM,oBAAoBA,SAAAA,cAAqC;AAAA,EAErE,YACkB,aAChB;AACK;AAFW,SAAA,cAAA;AAAA,EAGlB;AAAA,EAGA,MAAM,MAAM,WAA8D;AACzE,UAAM,QAAQC,SAAAA,cAAc,OAMzB,EACD,KAAK,QAAQ,EACb,OAAO,IAAIC,SAAA,QAAQ,GAAG,CAAC,EACvB,MAAM;AAAA,MACN,IAAI;AAAA,IAAA,CACJ,EACA,MAAM,CAAM,OAAA;AACR,UAAA,CAAC,KAAK,aAAa;AACf,eAAA;AAAA,MACR;AACO,aAAA,GAAG,MAAM,CAAAC,QAAMA,IAAG,IAAI,iBAAiB,KAAK,WAAW,CAAC;AAAA,IAAA,CAC/D;AAEI,UAAA,MAAO,KAAK,eAAe,MAAM,MAAM,UAAU,UAAU,EAAE,CAAC;AACpE,QAAI,CAAC,KAAK;AACF,aAAA;AAAA,IACR;AACO,WAAA;AAAA,MACN,QAAQ,IAAI;AAAA,MACZ,MAAM;AAAA,QACL,UAAU,IAAI;AAAA,QACd,SAAS,IAAI;AAAA,QACb,WAAW,IAAI;AAAA,QACf,IAAI,IAAI;AAAA,MACT;AAAA,IAAA;AAAA,EAEF;AACD;;"}
1
+ {"version":3,"file":"SchemaQuery.cjs","sources":["../../../../../../../packages/engine-system-api/src/model/queries/schema/SchemaQuery.ts"],"sourcesContent":["import { DatabaseQuery, DatabaseQueryable, Literal, SelectBuilder } from '@contember/database'\nimport { Schema } from '@contember/schema'\nimport { SchemaWithMeta } from '../../migrations'\n\nexport class SchemaQuery extends DatabaseQuery<SchemaWithMeta | null> {\n\n\tconstructor(\n\t\tprivate readonly currentHash?: string,\n\t) {\n\t\tsuper()\n\t}\n\n\n\tasync fetch(queryable: DatabaseQueryable): Promise<SchemaWithMeta | null> {\n\t\tconst query = SelectBuilder.create<{\n\t\t\tschema: Schema\n\t\t\tchecksum: string\n\t\t\tversion: string\n\t\t\tupdated_at: Date\n\t\t\tmigration_id: number\n\t\t}>()\n\t\t\t.from('schema')\n\t\t\t.select(new Literal('*'))\n\t\t\t.where({\n\t\t\t\tid: 'single',\n\t\t\t})\n\t\t\t.match(it => {\n\t\t\t\tif (!this.currentHash) {\n\t\t\t\t\treturn it\n\t\t\t\t}\n\t\t\t\treturn it.where(it => it.raw('checksum != ?', this.currentHash))\n\t\t\t})\n\n\t\tconst row = this.fetchOneOrNull(await query.getResult(queryable.db))\n\t\tif (!row) {\n\t\t\treturn null\n\t\t}\n\t\treturn {\n\t\t\tschema: row.schema,\n\t\t\tmeta: {\n\t\t\t\tchecksum: row.checksum,\n\t\t\t\tversion: row.version,\n\t\t\t\tupdatedAt: row.updated_at,\n\t\t\t\tid: row.migration_id,\n\t\t\t},\n\t\t}\n\t}\n}\n"],"names":["DatabaseQuery","SelectBuilder","Literal","it"],"mappings":";;;AAIO,MAAM,oBAAoBA,SAAAA,cAAqC;AAAA,EAErE,YACkB,aAChB;AACK,UAAA;AAFW,SAAA,cAAA;AAAA,EAAA;AAAA,EAMlB,MAAM,MAAM,WAA8D;AACzE,UAAM,QAAQC,SAAAA,cAAc,OAMzB,EACD,KAAK,QAAQ,EACb,OAAO,IAAIC,SAAA,QAAQ,GAAG,CAAC,EACvB,MAAM;AAAA,MACN,IAAI;AAAA,IAAA,CACJ,EACA,MAAM,CAAM,OAAA;AACR,UAAA,CAAC,KAAK,aAAa;AACf,eAAA;AAAA,MAAA;AAED,aAAA,GAAG,MAAM,CAAAC,QAAMA,IAAG,IAAI,iBAAiB,KAAK,WAAW,CAAC;AAAA,IAAA,CAC/D;AAEI,UAAA,MAAO,KAAK,eAAe,MAAM,MAAM,UAAU,UAAU,EAAE,CAAC;AACpE,QAAI,CAAC,KAAK;AACF,aAAA;AAAA,IAAA;AAED,WAAA;AAAA,MACN,QAAQ,IAAI;AAAA,MACZ,MAAM;AAAA,QACL,UAAU,IAAI;AAAA,QACd,SAAS,IAAI;AAAA,QACb,WAAW,IAAI;AAAA,QACf,IAAI,IAAI;AAAA,MAAA;AAAA,IAEV;AAAA,EAAA;AAEF;;"}
@@ -1 +1 @@
1
- {"version":3,"file":"SchemaQuery.js","sources":["../../../../../../../packages/engine-system-api/src/model/queries/schema/SchemaQuery.ts"],"sourcesContent":["import { DatabaseQuery, DatabaseQueryable, Literal, SelectBuilder } from '@contember/database'\nimport { Schema } from '@contember/schema'\nimport { SchemaWithMeta } from '../../migrations'\n\nexport class SchemaQuery extends DatabaseQuery<SchemaWithMeta | null> {\n\n\tconstructor(\n\t\tprivate readonly currentHash?: string,\n\t) {\n\t\tsuper()\n\t}\n\n\n\tasync fetch(queryable: DatabaseQueryable): Promise<SchemaWithMeta | null> {\n\t\tconst query = SelectBuilder.create<{\n\t\t\tschema: Schema\n\t\t\tchecksum: string\n\t\t\tversion: string\n\t\t\tupdated_at: Date\n\t\t\tmigration_id: number\n\t\t}>()\n\t\t\t.from('schema')\n\t\t\t.select(new Literal('*'))\n\t\t\t.where({\n\t\t\t\tid: 'single',\n\t\t\t})\n\t\t\t.match(it => {\n\t\t\t\tif (!this.currentHash) {\n\t\t\t\t\treturn it\n\t\t\t\t}\n\t\t\t\treturn it.where(it => it.raw('checksum != ?', this.currentHash))\n\t\t\t})\n\n\t\tconst row = this.fetchOneOrNull(await query.getResult(queryable.db))\n\t\tif (!row) {\n\t\t\treturn null\n\t\t}\n\t\treturn {\n\t\t\tschema: row.schema,\n\t\t\tmeta: {\n\t\t\t\tchecksum: row.checksum,\n\t\t\t\tversion: row.version,\n\t\t\t\tupdatedAt: row.updated_at,\n\t\t\t\tid: row.migration_id,\n\t\t\t},\n\t\t}\n\t}\n}\n"],"names":["it"],"mappings":";AAIO,MAAM,oBAAoB,cAAqC;AAAA,EAErE,YACkB,aAChB;AACK;AAFW,SAAA,cAAA;AAAA,EAGlB;AAAA,EAGA,MAAM,MAAM,WAA8D;AACzE,UAAM,QAAQ,cAAc,OAMzB,EACD,KAAK,QAAQ,EACb,OAAO,IAAI,QAAQ,GAAG,CAAC,EACvB,MAAM;AAAA,MACN,IAAI;AAAA,IAAA,CACJ,EACA,MAAM,CAAM,OAAA;AACR,UAAA,CAAC,KAAK,aAAa;AACf,eAAA;AAAA,MACR;AACO,aAAA,GAAG,MAAM,CAAAA,QAAMA,IAAG,IAAI,iBAAiB,KAAK,WAAW,CAAC;AAAA,IAAA,CAC/D;AAEI,UAAA,MAAO,KAAK,eAAe,MAAM,MAAM,UAAU,UAAU,EAAE,CAAC;AACpE,QAAI,CAAC,KAAK;AACF,aAAA;AAAA,IACR;AACO,WAAA;AAAA,MACN,QAAQ,IAAI;AAAA,MACZ,MAAM;AAAA,QACL,UAAU,IAAI;AAAA,QACd,SAAS,IAAI;AAAA,QACb,WAAW,IAAI;AAAA,QACf,IAAI,IAAI;AAAA,MACT;AAAA,IAAA;AAAA,EAEF;AACD;"}
1
+ {"version":3,"file":"SchemaQuery.js","sources":["../../../../../../../packages/engine-system-api/src/model/queries/schema/SchemaQuery.ts"],"sourcesContent":["import { DatabaseQuery, DatabaseQueryable, Literal, SelectBuilder } from '@contember/database'\nimport { Schema } from '@contember/schema'\nimport { SchemaWithMeta } from '../../migrations'\n\nexport class SchemaQuery extends DatabaseQuery<SchemaWithMeta | null> {\n\n\tconstructor(\n\t\tprivate readonly currentHash?: string,\n\t) {\n\t\tsuper()\n\t}\n\n\n\tasync fetch(queryable: DatabaseQueryable): Promise<SchemaWithMeta | null> {\n\t\tconst query = SelectBuilder.create<{\n\t\t\tschema: Schema\n\t\t\tchecksum: string\n\t\t\tversion: string\n\t\t\tupdated_at: Date\n\t\t\tmigration_id: number\n\t\t}>()\n\t\t\t.from('schema')\n\t\t\t.select(new Literal('*'))\n\t\t\t.where({\n\t\t\t\tid: 'single',\n\t\t\t})\n\t\t\t.match(it => {\n\t\t\t\tif (!this.currentHash) {\n\t\t\t\t\treturn it\n\t\t\t\t}\n\t\t\t\treturn it.where(it => it.raw('checksum != ?', this.currentHash))\n\t\t\t})\n\n\t\tconst row = this.fetchOneOrNull(await query.getResult(queryable.db))\n\t\tif (!row) {\n\t\t\treturn null\n\t\t}\n\t\treturn {\n\t\t\tschema: row.schema,\n\t\t\tmeta: {\n\t\t\t\tchecksum: row.checksum,\n\t\t\t\tversion: row.version,\n\t\t\t\tupdatedAt: row.updated_at,\n\t\t\t\tid: row.migration_id,\n\t\t\t},\n\t\t}\n\t}\n}\n"],"names":["it"],"mappings":";AAIO,MAAM,oBAAoB,cAAqC;AAAA,EAErE,YACkB,aAChB;AACK,UAAA;AAFW,SAAA,cAAA;AAAA,EAAA;AAAA,EAMlB,MAAM,MAAM,WAA8D;AACzE,UAAM,QAAQ,cAAc,OAMzB,EACD,KAAK,QAAQ,EACb,OAAO,IAAI,QAAQ,GAAG,CAAC,EACvB,MAAM;AAAA,MACN,IAAI;AAAA,IAAA,CACJ,EACA,MAAM,CAAM,OAAA;AACR,UAAA,CAAC,KAAK,aAAa;AACf,eAAA;AAAA,MAAA;AAED,aAAA,GAAG,MAAM,CAAAA,QAAMA,IAAG,IAAI,iBAAiB,KAAK,WAAW,CAAC;AAAA,IAAA,CAC/D;AAEI,UAAA,MAAO,KAAK,eAAe,MAAM,MAAM,UAAU,UAAU,EAAE,CAAC;AACpE,QAAI,CAAC,KAAK;AACF,aAAA;AAAA,IAAA;AAED,WAAA;AAAA,MACN,QAAQ,IAAI;AAAA,MACZ,MAAM;AAAA,QACL,UAAU,IAAI;AAAA,QACd,SAAS,IAAI;AAAA,QACb,WAAW,IAAI;AAAA,QACf,IAAI,IAAI;AAAA,MAAA;AAAA,IAEV;AAAA,EAAA;AAEF;"}
@@ -1 +1 @@
1
- {"version":3,"file":"StageBySlugQuery.cjs","sources":["../../../../../../../packages/engine-system-api/src/model/queries/stages/StageBySlugQuery.ts"],"sourcesContent":["import { DatabaseQuery, DatabaseQueryable } from '@contember/database'\nimport { prepareStageQueryBuilder } from './StageQueryFactory'\nimport { Stage } from '../../dtos'\n\nclass StageBySlugQuery extends DatabaseQuery<StageBySlugQuery.Result> {\n\tconstructor(private readonly slug: string) {\n\t\tsuper()\n\t}\n\n\tasync fetch(queryable: DatabaseQueryable): Promise<StageBySlugQuery.Result> {\n\t\tlet selectBuilder = prepareStageQueryBuilder().where({ slug: this.slug })\n\n\t\tconst rows = await selectBuilder.getResult(queryable.db)\n\n\t\treturn this.fetchOneOrNull(rows)\n\t}\n}\n\nnamespace StageBySlugQuery {\n\texport type Result = null | Stage\n}\n\nexport { StageBySlugQuery }\n"],"names":["DatabaseQuery","prepareStageQueryBuilder"],"mappings":";;;;AAIA,MAAM,yBAAyBA,SAAAA,cAAuC;AAAA,EACrE,YAA6B,MAAc;AACpC;AADsB,SAAA,OAAA;AAAA,EAE7B;AAAA,EAEA,MAAM,MAAM,WAAgE;AACvE,QAAA,gBAAgBC,6CAA2B,MAAM,EAAE,MAAM,KAAK,MAAM;AAExE,UAAM,OAAO,MAAM,cAAc,UAAU,UAAU,EAAE;AAEhD,WAAA,KAAK,eAAe,IAAI;AAAA,EAChC;AACD;;"}
1
+ {"version":3,"file":"StageBySlugQuery.cjs","sources":["../../../../../../../packages/engine-system-api/src/model/queries/stages/StageBySlugQuery.ts"],"sourcesContent":["import { DatabaseQuery, DatabaseQueryable } from '@contember/database'\nimport { prepareStageQueryBuilder } from './StageQueryFactory'\nimport { Stage } from '../../dtos'\n\nclass StageBySlugQuery extends DatabaseQuery<StageBySlugQuery.Result> {\n\tconstructor(private readonly slug: string) {\n\t\tsuper()\n\t}\n\n\tasync fetch(queryable: DatabaseQueryable): Promise<StageBySlugQuery.Result> {\n\t\tlet selectBuilder = prepareStageQueryBuilder().where({ slug: this.slug })\n\n\t\tconst rows = await selectBuilder.getResult(queryable.db)\n\n\t\treturn this.fetchOneOrNull(rows)\n\t}\n}\n\nnamespace StageBySlugQuery {\n\texport type Result = null | Stage\n}\n\nexport { StageBySlugQuery }\n"],"names":["DatabaseQuery","prepareStageQueryBuilder"],"mappings":";;;;AAIA,MAAM,yBAAyBA,SAAAA,cAAuC;AAAA,EACrE,YAA6B,MAAc;AACpC,UAAA;AADsB,SAAA,OAAA;AAAA,EAAA;AAAA,EAI7B,MAAM,MAAM,WAAgE;AACvE,QAAA,gBAAgBC,kBAAAA,2BAA2B,MAAM,EAAE,MAAM,KAAK,MAAM;AAExE,UAAM,OAAO,MAAM,cAAc,UAAU,UAAU,EAAE;AAEhD,WAAA,KAAK,eAAe,IAAI;AAAA,EAAA;AAEjC;;"}
@@ -1 +1 @@
1
- {"version":3,"file":"StageBySlugQuery.js","sources":["../../../../../../../packages/engine-system-api/src/model/queries/stages/StageBySlugQuery.ts"],"sourcesContent":["import { DatabaseQuery, DatabaseQueryable } from '@contember/database'\nimport { prepareStageQueryBuilder } from './StageQueryFactory'\nimport { Stage } from '../../dtos'\n\nclass StageBySlugQuery extends DatabaseQuery<StageBySlugQuery.Result> {\n\tconstructor(private readonly slug: string) {\n\t\tsuper()\n\t}\n\n\tasync fetch(queryable: DatabaseQueryable): Promise<StageBySlugQuery.Result> {\n\t\tlet selectBuilder = prepareStageQueryBuilder().where({ slug: this.slug })\n\n\t\tconst rows = await selectBuilder.getResult(queryable.db)\n\n\t\treturn this.fetchOneOrNull(rows)\n\t}\n}\n\nnamespace StageBySlugQuery {\n\texport type Result = null | Stage\n}\n\nexport { StageBySlugQuery }\n"],"names":[],"mappings":";;AAIA,MAAM,yBAAyB,cAAuC;AAAA,EACrE,YAA6B,MAAc;AACpC;AADsB,SAAA,OAAA;AAAA,EAE7B;AAAA,EAEA,MAAM,MAAM,WAAgE;AACvE,QAAA,gBAAgB,2BAA2B,MAAM,EAAE,MAAM,KAAK,MAAM;AAExE,UAAM,OAAO,MAAM,cAAc,UAAU,UAAU,EAAE;AAEhD,WAAA,KAAK,eAAe,IAAI;AAAA,EAChC;AACD;"}
1
+ {"version":3,"file":"StageBySlugQuery.js","sources":["../../../../../../../packages/engine-system-api/src/model/queries/stages/StageBySlugQuery.ts"],"sourcesContent":["import { DatabaseQuery, DatabaseQueryable } from '@contember/database'\nimport { prepareStageQueryBuilder } from './StageQueryFactory'\nimport { Stage } from '../../dtos'\n\nclass StageBySlugQuery extends DatabaseQuery<StageBySlugQuery.Result> {\n\tconstructor(private readonly slug: string) {\n\t\tsuper()\n\t}\n\n\tasync fetch(queryable: DatabaseQueryable): Promise<StageBySlugQuery.Result> {\n\t\tlet selectBuilder = prepareStageQueryBuilder().where({ slug: this.slug })\n\n\t\tconst rows = await selectBuilder.getResult(queryable.db)\n\n\t\treturn this.fetchOneOrNull(rows)\n\t}\n}\n\nnamespace StageBySlugQuery {\n\texport type Result = null | Stage\n}\n\nexport { StageBySlugQuery }\n"],"names":[],"mappings":";;AAIA,MAAM,yBAAyB,cAAuC;AAAA,EACrE,YAA6B,MAAc;AACpC,UAAA;AADsB,SAAA,OAAA;AAAA,EAAA;AAAA,EAI7B,MAAM,MAAM,WAAgE;AACvE,QAAA,gBAAgB,2BAA2B,MAAM,EAAE,MAAM,KAAK,MAAM;AAExE,UAAM,OAAO,MAAM,cAAc,UAAU,UAAU,EAAE;AAEhD,WAAA,KAAK,eAAe,IAAI;AAAA,EAAA;AAEjC;"}
@@ -1 +1 @@
1
- {"version":3,"file":"StagesQuery.cjs","sources":["../../../../../../../packages/engine-system-api/src/model/queries/stages/StagesQuery.ts"],"sourcesContent":["import { DatabaseQuery, DatabaseQueryable } from '@contember/database'\nimport { prepareStageQueryBuilder } from './StageQueryFactory'\nimport { Stage } from '../../dtos'\n\nclass StagesQuery extends DatabaseQuery<Stage[]> {\n\tasync fetch(queryable: DatabaseQueryable): Promise<Stage[]> {\n\t\tconst select = prepareStageQueryBuilder()\n\n\t\treturn await select.getResult(queryable.db)\n\t}\n}\n\nexport { StagesQuery }\n"],"names":["DatabaseQuery","prepareStageQueryBuilder"],"mappings":";;;;AAIA,MAAM,oBAAoBA,SAAAA,cAAuB;AAAA,EAChD,MAAM,MAAM,WAAgD;AAC3D,UAAM,SAASC,kBAAAA;AAEf,WAAO,MAAM,OAAO,UAAU,UAAU,EAAE;AAAA,EAC3C;AACD;;"}
1
+ {"version":3,"file":"StagesQuery.cjs","sources":["../../../../../../../packages/engine-system-api/src/model/queries/stages/StagesQuery.ts"],"sourcesContent":["import { DatabaseQuery, DatabaseQueryable } from '@contember/database'\nimport { prepareStageQueryBuilder } from './StageQueryFactory'\nimport { Stage } from '../../dtos'\n\nclass StagesQuery extends DatabaseQuery<Stage[]> {\n\tasync fetch(queryable: DatabaseQueryable): Promise<Stage[]> {\n\t\tconst select = prepareStageQueryBuilder()\n\n\t\treturn await select.getResult(queryable.db)\n\t}\n}\n\nexport { StagesQuery }\n"],"names":["DatabaseQuery","prepareStageQueryBuilder"],"mappings":";;;;AAIA,MAAM,oBAAoBA,SAAAA,cAAuB;AAAA,EAChD,MAAM,MAAM,WAAgD;AAC3D,UAAM,SAASC,kBAAAA,yBAAyB;AAExC,WAAO,MAAM,OAAO,UAAU,UAAU,EAAE;AAAA,EAAA;AAE5C;;"}
@@ -1 +1 @@
1
- {"version":3,"file":"StagesQuery.js","sources":["../../../../../../../packages/engine-system-api/src/model/queries/stages/StagesQuery.ts"],"sourcesContent":["import { DatabaseQuery, DatabaseQueryable } from '@contember/database'\nimport { prepareStageQueryBuilder } from './StageQueryFactory'\nimport { Stage } from '../../dtos'\n\nclass StagesQuery extends DatabaseQuery<Stage[]> {\n\tasync fetch(queryable: DatabaseQueryable): Promise<Stage[]> {\n\t\tconst select = prepareStageQueryBuilder()\n\n\t\treturn await select.getResult(queryable.db)\n\t}\n}\n\nexport { StagesQuery }\n"],"names":[],"mappings":";;AAIA,MAAM,oBAAoB,cAAuB;AAAA,EAChD,MAAM,MAAM,WAAgD;AAC3D,UAAM,SAAS;AAEf,WAAO,MAAM,OAAO,UAAU,UAAU,EAAE;AAAA,EAC3C;AACD;"}
1
+ {"version":3,"file":"StagesQuery.js","sources":["../../../../../../../packages/engine-system-api/src/model/queries/stages/StagesQuery.ts"],"sourcesContent":["import { DatabaseQuery, DatabaseQueryable } from '@contember/database'\nimport { prepareStageQueryBuilder } from './StageQueryFactory'\nimport { Stage } from '../../dtos'\n\nclass StagesQuery extends DatabaseQuery<Stage[]> {\n\tasync fetch(queryable: DatabaseQueryable): Promise<Stage[]> {\n\t\tconst select = prepareStageQueryBuilder()\n\n\t\treturn await select.getResult(queryable.db)\n\t}\n}\n\nexport { StagesQuery }\n"],"names":[],"mappings":";;AAIA,MAAM,oBAAoB,cAAuB;AAAA,EAChD,MAAM,MAAM,WAAgD;AAC3D,UAAM,SAAS,yBAAyB;AAExC,WAAO,MAAM,OAAO,UAAU,UAAU,EAAE;AAAA,EAAA;AAE5C;"}
@@ -1 +1 @@
1
- {"version":3,"file":"StageCreator.cjs","sources":["../../../../../../packages/engine-system-api/src/model/stages/StageCreator.ts"],"sourcesContent":["import { CreateStageCommand } from '../commands'\nimport { StageBySlugQuery } from '../queries'\nimport { StageConfig } from '../../types'\nimport { DatabaseContext } from '../database'\n\nclass StageCreator {\n\tconstructor() {}\n\n\tpublic async createStage(\n\t\tdb: DatabaseContext,\n\t\tstage: StageConfig,\n\t): Promise<boolean> {\n\t\tconst stageRow = await db.queryHandler.fetch(new StageBySlugQuery(stage.slug))\n\t\tif (stageRow) {\n\t\t\treturn false\n\t\t}\n\t\tawait db.commandBus.execute(new CreateStageCommand(stage))\n\t\treturn true\n\t}\n}\n\nexport { StageCreator }\n"],"names":["StageBySlugQuery","CreateStageCommand"],"mappings":";;;;;;;;AAKA,MAAM,aAAa;AAAA,EAClB,cAAc;AAAA,EAAC;AAAA,EAEf,MAAa,YACZ,IACA,OACmB;AACb,UAAA,WAAW,MAAM,GAAG,aAAa,MAAM,IAAIA,kCAAiB,MAAM,IAAI,CAAC;AAC7E,QAAI,UAAU;AACN,aAAA;AAAA,IACR;AACA,UAAM,GAAG,WAAW,QAAQ,IAAIC,mBAAA,mBAAmB,KAAK,CAAC;AAClD,WAAA;AAAA,EACR;AACD;;"}
1
+ {"version":3,"file":"StageCreator.cjs","sources":["../../../../../../packages/engine-system-api/src/model/stages/StageCreator.ts"],"sourcesContent":["import { CreateStageCommand } from '../commands'\nimport { StageBySlugQuery } from '../queries'\nimport { StageConfig } from '../../types'\nimport { DatabaseContext } from '../database'\n\nclass StageCreator {\n\tconstructor() {}\n\n\tpublic async createStage(\n\t\tdb: DatabaseContext,\n\t\tstage: StageConfig,\n\t): Promise<boolean> {\n\t\tconst stageRow = await db.queryHandler.fetch(new StageBySlugQuery(stage.slug))\n\t\tif (stageRow) {\n\t\t\treturn false\n\t\t}\n\t\tawait db.commandBus.execute(new CreateStageCommand(stage))\n\t\treturn true\n\t}\n}\n\nexport { StageCreator }\n"],"names":["StageBySlugQuery","CreateStageCommand"],"mappings":";;;;;;;;AAKA,MAAM,aAAa;AAAA,EAClB,cAAc;AAAA,EAAA;AAAA,EAEd,MAAa,YACZ,IACA,OACmB;AACb,UAAA,WAAW,MAAM,GAAG,aAAa,MAAM,IAAIA,iBAAA,iBAAiB,MAAM,IAAI,CAAC;AAC7E,QAAI,UAAU;AACN,aAAA;AAAA,IAAA;AAER,UAAM,GAAG,WAAW,QAAQ,IAAIC,mBAAA,mBAAmB,KAAK,CAAC;AAClD,WAAA;AAAA,EAAA;AAET;;"}
@@ -1 +1 @@
1
- {"version":3,"file":"StageCreator.js","sources":["../../../../../../packages/engine-system-api/src/model/stages/StageCreator.ts"],"sourcesContent":["import { CreateStageCommand } from '../commands'\nimport { StageBySlugQuery } from '../queries'\nimport { StageConfig } from '../../types'\nimport { DatabaseContext } from '../database'\n\nclass StageCreator {\n\tconstructor() {}\n\n\tpublic async createStage(\n\t\tdb: DatabaseContext,\n\t\tstage: StageConfig,\n\t): Promise<boolean> {\n\t\tconst stageRow = await db.queryHandler.fetch(new StageBySlugQuery(stage.slug))\n\t\tif (stageRow) {\n\t\t\treturn false\n\t\t}\n\t\tawait db.commandBus.execute(new CreateStageCommand(stage))\n\t\treturn true\n\t}\n}\n\nexport { StageCreator }\n"],"names":[],"mappings":";;;;;;AAKA,MAAM,aAAa;AAAA,EAClB,cAAc;AAAA,EAAC;AAAA,EAEf,MAAa,YACZ,IACA,OACmB;AACb,UAAA,WAAW,MAAM,GAAG,aAAa,MAAM,IAAI,iBAAiB,MAAM,IAAI,CAAC;AAC7E,QAAI,UAAU;AACN,aAAA;AAAA,IACR;AACA,UAAM,GAAG,WAAW,QAAQ,IAAI,mBAAmB,KAAK,CAAC;AAClD,WAAA;AAAA,EACR;AACD;"}
1
+ {"version":3,"file":"StageCreator.js","sources":["../../../../../../packages/engine-system-api/src/model/stages/StageCreator.ts"],"sourcesContent":["import { CreateStageCommand } from '../commands'\nimport { StageBySlugQuery } from '../queries'\nimport { StageConfig } from '../../types'\nimport { DatabaseContext } from '../database'\n\nclass StageCreator {\n\tconstructor() {}\n\n\tpublic async createStage(\n\t\tdb: DatabaseContext,\n\t\tstage: StageConfig,\n\t): Promise<boolean> {\n\t\tconst stageRow = await db.queryHandler.fetch(new StageBySlugQuery(stage.slug))\n\t\tif (stageRow) {\n\t\t\treturn false\n\t\t}\n\t\tawait db.commandBus.execute(new CreateStageCommand(stage))\n\t\treturn true\n\t}\n}\n\nexport { StageCreator }\n"],"names":[],"mappings":";;;;;;AAKA,MAAM,aAAa;AAAA,EAClB,cAAc;AAAA,EAAA;AAAA,EAEd,MAAa,YACZ,IACA,OACmB;AACb,UAAA,WAAW,MAAM,GAAG,aAAa,MAAM,IAAI,iBAAiB,MAAM,IAAI,CAAC;AAC7E,QAAI,UAAU;AACN,aAAA;AAAA,IAAA;AAER,UAAM,GAAG,WAAW,QAAQ,IAAI,mBAAmB,KAAK,CAAC;AAClD,WAAA;AAAA,EAAA;AAET;"}
@@ -1 +1 @@
1
- {"version":3,"file":"ResolverFactory.cjs","sources":["../../../../../packages/engine-system-api/src/resolvers/ResolverFactory.ts"],"sourcesContent":["import { EventsQueryResolver, ExecutedMigrationsQueryResolver, StagesQueryResolver } from './query'\nimport { Event, EventType, Resolvers } from '../schema'\nimport { assertNever } from '../utils'\nimport { MigrateMutationResolver, MigrationAlterMutationResolver, TruncateMutationResolver } from './mutation'\nimport { DateTimeType, JSONType, createJsonLikeType } from '@contember/graphql-utils'\nimport { EventOldValuesResolver } from './types'\nimport { GraphQLError, GraphQLScalarType, Kind } from 'graphql'\nimport { SchemaQueryResolver } from './query/SchemaQueryResolver'\n\nexport class ResolverFactory {\n\tpublic constructor(\n\t\tprivate readonly stagesQueryResolver: StagesQueryResolver,\n\t\tprivate readonly executedMigrationsQueryResolver: ExecutedMigrationsQueryResolver,\n\t\tprivate readonly migrateMutationResolver: MigrateMutationResolver,\n\t\tprivate readonly truncateMutationResolver: TruncateMutationResolver,\n\t\tprivate readonly migrationAlterMutationResolver: MigrationAlterMutationResolver,\n\t\tprivate readonly eventsQueryResolver: EventsQueryResolver,\n\t\tprivate readonly eventOldValuesResolver: EventOldValuesResolver,\n\t\tprivate readonly schemaQueryResolver: SchemaQueryResolver,\n\t) {}\n\n\tcreate(debugMode: boolean): Resolvers {\n\t\tconst resolvers: Resolvers & Required<Pick<Resolvers, 'Mutation'>> = {\n\t\t\tDateTime: DateTimeType,\n\t\t\tJson: JSONType,\n\t\t\tPrimaryKey: PrimaryKeyType,\n\t\t\tSchema: SchemaType,\n\t\t\tEvent: {\n\t\t\t\t__resolveType: (obj: Event) => {\n\t\t\t\t\tswitch (obj.type) {\n\t\t\t\t\t\tcase EventType.Create:\n\t\t\t\t\t\t\treturn 'CreateEvent'\n\t\t\t\t\t\tcase EventType.Update:\n\t\t\t\t\t\t\treturn 'UpdateEvent'\n\t\t\t\t\t\tcase EventType.Delete:\n\t\t\t\t\t\t\treturn 'DeleteEvent'\n\t\t\t\t\t\tcase null:\n\t\t\t\t\t\tcase undefined:\n\t\t\t\t\t\t\treturn null\n\t\t\t\t\t\tdefault:\n\t\t\t\t\t\t\treturn assertNever(obj.type)\n\t\t\t\t\t}\n\t\t\t\t},\n\t\t\t},\n\t\t\tQuery: {\n\t\t\t\tstages: this.stagesQueryResolver.stages.bind(this.stagesQueryResolver),\n\t\t\t\texecutedMigrations: this.executedMigrationsQueryResolver.executedMigrations.bind(this.executedMigrationsQueryResolver),\n\t\t\t\tevents: this.eventsQueryResolver.events.bind(this.eventsQueryResolver),\n\t\t\t\tschema: this.schemaQueryResolver.schema.bind(this.schemaQueryResolver),\n\t\t\t},\n\t\t\tMutation: {\n\t\t\t\tmigrate: this.migrateMutationResolver.migrate.bind(this.migrateMutationResolver),\n\t\t\t},\n\t\t\tDeleteEvent: {\n\t\t\t\toldValues: this.eventOldValuesResolver.oldValues.bind(this.eventOldValuesResolver),\n\t\t\t},\n\t\t\tUpdateEvent: {\n\t\t\t\toldValues: this.eventOldValuesResolver.oldValues.bind(this.eventOldValuesResolver),\n\t\t\t},\n\t\t}\n\t\tif (debugMode) {\n\t\t\tresolvers.Mutation.truncate = this.truncateMutationResolver.truncate.bind(this.truncateMutationResolver)\n\t\t\tresolvers.Mutation.migrationDelete = this.migrationAlterMutationResolver.migrationDelete.bind(this.migrationAlterMutationResolver)\n\t\t\tresolvers.Mutation.migrationModify = this.migrationAlterMutationResolver.migrationModify.bind(this.migrationAlterMutationResolver)\n\t\t\tresolvers.Mutation.forceMigrate = this.migrateMutationResolver.migrateForce.bind(this.migrateMutationResolver)\n\t\t}\n\t\treturn resolvers\n\t}\n}\n\nconst parseValue = (value: any) => {\n\tif ((typeof value === 'string' && value !== '') || typeof value === 'number' && isFinite(value) && Math.floor(value) === value) {\n\t\treturn value\n\t}\n\tthrow new GraphQLError('PrimaryKey cannot represent value: ' + JSON.stringify(value))\n}\n\nconst SchemaType = createJsonLikeType('Schema', 'Content schema custom scalar type')\n\n\nexport const PrimaryKeyType = new GraphQLScalarType({\n\tname: 'PrimaryKey',\n\tdescription: 'PrimaryKey custom scalar type. Can be Int or String',\n\tserialize: parseValue,\n\tparseValue: parseValue,\n\tparseLiteral(ast) {\n\t\tif (ast.kind === Kind.STRING) {\n\t\t\treturn ast.value\n\t\t}\n\t\tif (ast.kind === Kind.INT) {\n\t\t\treturn Number.parseInt(ast.value, 10)\n\t\t}\n\t\treturn null\n\t},\n})\n"],"names":["DateTimeType","JSONType","EventType","assertNever","GraphQLError","createJsonLikeType","GraphQLScalarType","Kind"],"mappings":";;;;;;;;AASO,MAAM,gBAAgB;AAAA,EACrB,YACW,qBACA,iCACA,yBACA,0BACA,gCACA,qBACA,wBACA,qBAChB;AARgB,SAAA,sBAAA;AACA,SAAA,kCAAA;AACA,SAAA,0BAAA;AACA,SAAA,2BAAA;AACA,SAAA,iCAAA;AACA,SAAA,sBAAA;AACA,SAAA,yBAAA;AACA,SAAA,sBAAA;AAAA,EACf;AAAA,EAEH,OAAO,WAA+B;AACrC,UAAM,YAA+D;AAAA,MACpE,UAAUA,aAAA;AAAA,MACV,MAAMC,aAAA;AAAA,MACN,YAAY;AAAA,MACZ,QAAQ;AAAA,MACR,OAAO;AAAA,QACN,eAAe,CAAC,QAAe;AAC9B,kBAAQ,IAAI,MAAM;AAAA,YACjB,KAAKC,MAAU,UAAA;AACP,qBAAA;AAAA,YACR,KAAKA,MAAU,UAAA;AACP,qBAAA;AAAA,YACR,KAAKA,MAAU,UAAA;AACP,qBAAA;AAAA,YACR,KAAK;AAAA,YACL,KAAK;AACG,qBAAA;AAAA,YACR;AACQ,qBAAAC,YAAA,YAAY,IAAI,IAAI;AAAA,UAC7B;AAAA,QACD;AAAA,MACD;AAAA,MACA,OAAO;AAAA,QACN,QAAQ,KAAK,oBAAoB,OAAO,KAAK,KAAK,mBAAmB;AAAA,QACrE,oBA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AQ;AAC7B,aAAO,IAAI;AAAA,IACZ;AACI,QAAA,IAAI,SAASA,QAAA,KAAK,KAAK;AAC1B,aAAO,OAAO,SAAS,IAAI,OAAO,EAAE;AAAA,IACrC;AACO,WAAA;AAAA,EACR;AACD,CAAC;;;"}
1
+ {"version":3,"file":"ResolverFactory.cjs","sources":["../../../../../packages/engine-system-api/src/resolvers/ResolverFactory.ts"],"sourcesContent":["import { EventsQueryResolver, ExecutedMigrationsQueryResolver, StagesQueryResolver } from './query'\nimport { Event, EventType, Resolvers } from '../schema'\nimport { assertNever } from '../utils'\nimport { MigrateMutationResolver, MigrationAlterMutationResolver, TruncateMutationResolver } from './mutation'\nimport { DateTimeType, JSONType, createJsonLikeType } from '@contember/graphql-utils'\nimport { EventOldValuesResolver } from './types'\nimport { GraphQLError, GraphQLScalarType, Kind } from 'graphql'\nimport { SchemaQueryResolver } from './query/SchemaQueryResolver'\n\nexport class ResolverFactory {\n\tpublic constructor(\n\t\tprivate readonly stagesQueryResolver: StagesQueryResolver,\n\t\tprivate readonly executedMigrationsQueryResolver: ExecutedMigrationsQueryResolver,\n\t\tprivate readonly migrateMutationResolver: MigrateMutationResolver,\n\t\tprivate readonly truncateMutationResolver: TruncateMutationResolver,\n\t\tprivate readonly migrationAlterMutationResolver: MigrationAlterMutationResolver,\n\t\tprivate readonly eventsQueryResolver: EventsQueryResolver,\n\t\tprivate readonly eventOldValuesResolver: EventOldValuesResolver,\n\t\tprivate readonly schemaQueryResolver: SchemaQueryResolver,\n\t) {}\n\n\tcreate(debugMode: boolean): Resolvers {\n\t\tconst resolvers: Resolvers & Required<Pick<Resolvers, 'Mutation'>> = {\n\t\t\tDateTime: DateTimeType,\n\t\t\tJson: JSONType,\n\t\t\tPrimaryKey: PrimaryKeyType,\n\t\t\tSchema: SchemaType,\n\t\t\tEvent: {\n\t\t\t\t__resolveType: (obj: Event) => {\n\t\t\t\t\tswitch (obj.type) {\n\t\t\t\t\t\tcase EventType.Create:\n\t\t\t\t\t\t\treturn 'CreateEvent'\n\t\t\t\t\t\tcase EventType.Update:\n\t\t\t\t\t\t\treturn 'UpdateEvent'\n\t\t\t\t\t\tcase EventType.Delete:\n\t\t\t\t\t\t\treturn 'DeleteEvent'\n\t\t\t\t\t\tcase null:\n\t\t\t\t\t\tcase undefined:\n\t\t\t\t\t\t\treturn null\n\t\t\t\t\t\tdefault:\n\t\t\t\t\t\t\treturn assertNever(obj.type)\n\t\t\t\t\t}\n\t\t\t\t},\n\t\t\t},\n\t\t\tQuery: {\n\t\t\t\tstages: this.stagesQueryResolver.stages.bind(this.stagesQueryResolver),\n\t\t\t\texecutedMigrations: this.executedMigrationsQueryResolver.executedMigrations.bind(this.executedMigrationsQueryResolver),\n\t\t\t\tevents: this.eventsQueryResolver.events.bind(this.eventsQueryResolver),\n\t\t\t\tschema: this.schemaQueryResolver.schema.bind(this.schemaQueryResolver),\n\t\t\t},\n\t\t\tMutation: {\n\t\t\t\tmigrate: this.migrateMutationResolver.migrate.bind(this.migrateMutationResolver),\n\t\t\t},\n\t\t\tDeleteEvent: {\n\t\t\t\toldValues: this.eventOldValuesResolver.oldValues.bind(this.eventOldValuesResolver),\n\t\t\t},\n\t\t\tUpdateEvent: {\n\t\t\t\toldValues: this.eventOldValuesResolver.oldValues.bind(this.eventOldValuesResolver),\n\t\t\t},\n\t\t}\n\t\tif (debugMode) {\n\t\t\tresolvers.Mutation.truncate = this.truncateMutationResolver.truncate.bind(this.truncateMutationResolver)\n\t\t\tresolvers.Mutation.migrationDelete = this.migrationAlterMutationResolver.migrationDelete.bind(this.migrationAlterMutationResolver)\n\t\t\tresolvers.Mutation.migrationModify = this.migrationAlterMutationResolver.migrationModify.bind(this.migrationAlterMutationResolver)\n\t\t\tresolvers.Mutation.forceMigrate = this.migrateMutationResolver.migrateForce.bind(this.migrateMutationResolver)\n\t\t}\n\t\treturn resolvers\n\t}\n}\n\nconst parseValue = (value: any) => {\n\tif ((typeof value === 'string' && value !== '') || typeof value === 'number' && isFinite(value) && Math.floor(value) === value) {\n\t\treturn value\n\t}\n\tthrow new GraphQLError('PrimaryKey cannot represent value: ' + JSON.stringify(value))\n}\n\nconst SchemaType = createJsonLikeType('Schema', 'Content schema custom scalar type')\n\n\nexport const PrimaryKeyType = new GraphQLScalarType({\n\tname: 'PrimaryKey',\n\tdescription: 'PrimaryKey custom scalar type. Can be Int or String',\n\tserialize: parseValue,\n\tparseValue: parseValue,\n\tparseLiteral(ast) {\n\t\tif (ast.kind === Kind.STRING) {\n\t\t\treturn ast.value\n\t\t}\n\t\tif (ast.kind === Kind.INT) {\n\t\t\treturn Number.parseInt(ast.value, 10)\n\t\t}\n\t\treturn null\n\t},\n})\n"],"names":["DateTimeType","JSONType","EventType","assertNever","GraphQLError","createJsonLikeType","GraphQLScalarType","Kind"],"mappings":";;;;;;;;AASO,MAAM,gBAAgB;AAAA,EACrB,YACW,qBACA,iCACA,yBACA,0BACA,gCACA,qBACA,wBACA,qBAChB;AARgB,SAAA,sBAAA;AACA,SAAA,kCAAA;AACA,SAAA,0BAAA;AACA,SAAA,2BAAA;AACA,SAAA,iCAAA;AACA,SAAA,sBAAA;AACA,SAAA,yBAAA;AACA,SAAA,sBAAA;AAAA,EAAA;AAAA,EAGlB,OAAO,WAA+B;AACrC,UAAM,YAA+D;AAAA,MACpE,UAAUA,aAAA;AAAA,MACV,MAAMC,aAAA;AAAA,MACN,YAAY;AAAA,MACZ,QAAQ;AAAA,MACR,OAAO;AAAA,QACN,eAAe,CAAC,QAAe;AAC9B,kBAAQ,IAAI,MAAM;AAAA,YACjB,KAAKC,MAAU,UAAA;AACP,qBAAA;AAAA,YACR,KAAKA,MAAU,UAAA;AACP,qBAAA;AAAA,YACR,KAAKA,MAAU,UAAA;AACP,qBAAA;AAAA,YACR,KAAK;AAAA,YACL,KAAK;AACG,qBAAA;AAAA,YACR;AACQ,qBAAAC,YAAA,YAAY,IAAI,IAAI;AAAA,UAAA;AAAA,QAC7B;AAAA,MAEF;AAAA,MACA,OAAO;AAA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