@contember/migrations-client 2.1.0-beta.2 → 2.2.0-alpha.2

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 (136) hide show
  1. package/dist/development/index.cjs +4 -0
  2. package/dist/development/index.cjs.map +1 -1
  3. package/dist/development/index.js +4 -0
  4. package/dist/development/index.js.map +1 -1
  5. package/dist/development/src/JsLoader.cjs.map +1 -1
  6. package/dist/development/src/JsLoader.js.map +1 -1
  7. package/dist/development/src/JsonLoader.cjs.map +1 -1
  8. package/dist/development/src/JsonLoader.js.map +1 -1
  9. package/dist/development/src/MigrationCreator.cjs +2 -2
  10. package/dist/development/src/MigrationCreator.cjs.map +1 -1
  11. package/dist/development/src/MigrationCreator.js +2 -2
  12. package/dist/development/src/MigrationCreator.js.map +1 -1
  13. package/dist/development/src/MigrationExecuteHelper.cjs +14 -5
  14. package/dist/development/src/MigrationExecuteHelper.cjs.map +1 -1
  15. package/dist/development/src/MigrationExecuteHelper.js +14 -5
  16. package/dist/development/src/MigrationExecuteHelper.js.map +1 -1
  17. package/dist/development/src/MigrationFile.cjs.map +1 -1
  18. package/dist/development/src/MigrationFile.js.map +1 -1
  19. package/dist/development/src/MigrationFilesManager.cjs +11 -11
  20. package/dist/development/src/MigrationFilesManager.cjs.map +1 -1
  21. package/dist/development/src/MigrationFilesManager.js.map +1 -1
  22. package/dist/development/src/MigrationParser.cjs.map +1 -1
  23. package/dist/development/src/MigrationParser.js.map +1 -1
  24. package/dist/development/src/MigrationsResolver.cjs.map +1 -1
  25. package/dist/development/src/MigrationsResolver.js.map +1 -1
  26. package/dist/development/src/SchemaStateManager.cjs +82 -0
  27. package/dist/development/src/SchemaStateManager.cjs.map +1 -0
  28. package/dist/development/src/SchemaStateManager.js +64 -0
  29. package/dist/development/src/SchemaStateManager.js.map +1 -0
  30. package/dist/development/src/SchemaVersionBuilder.cjs +8 -2
  31. package/dist/development/src/SchemaVersionBuilder.cjs.map +1 -1
  32. package/dist/development/src/SchemaVersionBuilder.js +8 -2
  33. package/dist/development/src/SchemaVersionBuilder.js.map +1 -1
  34. package/dist/development/src/SnapshotManager.cjs +46 -0
  35. package/dist/development/src/SnapshotManager.cjs.map +1 -0
  36. package/dist/development/src/SnapshotManager.js +29 -0
  37. package/dist/development/src/SnapshotManager.js.map +1 -0
  38. package/dist/development/src/SystemClient.cjs +29 -4
  39. package/dist/development/src/SystemClient.cjs.map +1 -1
  40. package/dist/development/src/SystemClient.js +29 -4
  41. package/dist/development/src/SystemClient.js.map +1 -1
  42. package/dist/development/src/migrations.cjs.map +1 -1
  43. package/dist/development/src/migrations.js.map +1 -1
  44. package/dist/production/index.cjs +4 -0
  45. package/dist/production/index.cjs.map +1 -1
  46. package/dist/production/index.js +4 -0
  47. package/dist/production/index.js.map +1 -1
  48. package/dist/production/src/JsLoader.cjs.map +1 -1
  49. package/dist/production/src/JsLoader.js.map +1 -1
  50. package/dist/production/src/JsonLoader.cjs.map +1 -1
  51. package/dist/production/src/JsonLoader.js.map +1 -1
  52. package/dist/production/src/MigrationCreator.cjs +2 -2
  53. package/dist/production/src/MigrationCreator.cjs.map +1 -1
  54. package/dist/production/src/MigrationCreator.js +2 -2
  55. package/dist/production/src/MigrationCreator.js.map +1 -1
  56. package/dist/production/src/MigrationExecuteHelper.cjs +14 -5
  57. package/dist/production/src/MigrationExecuteHelper.cjs.map +1 -1
  58. package/dist/production/src/MigrationExecuteHelper.js +14 -5
  59. package/dist/production/src/MigrationExecuteHelper.js.map +1 -1
  60. package/dist/production/src/MigrationFile.cjs.map +1 -1
  61. package/dist/production/src/MigrationFile.js.map +1 -1
  62. package/dist/production/src/MigrationFilesManager.cjs +11 -11
  63. package/dist/production/src/MigrationFilesManager.cjs.map +1 -1
  64. package/dist/production/src/MigrationFilesManager.js.map +1 -1
  65. package/dist/production/src/MigrationParser.cjs.map +1 -1
  66. package/dist/production/src/MigrationParser.js.map +1 -1
  67. package/dist/production/src/MigrationsResolver.cjs.map +1 -1
  68. package/dist/production/src/MigrationsResolver.js.map +1 -1
  69. package/dist/production/src/SchemaStateManager.cjs +82 -0
  70. package/dist/production/src/SchemaStateManager.cjs.map +1 -0
  71. package/dist/production/src/SchemaStateManager.js +64 -0
  72. package/dist/production/src/SchemaStateManager.js.map +1 -0
  73. package/dist/production/src/SchemaVersionBuilder.cjs +8 -2
  74. package/dist/production/src/SchemaVersionBuilder.cjs.map +1 -1
  75. package/dist/production/src/SchemaVersionBuilder.js +8 -2
  76. package/dist/production/src/SchemaVersionBuilder.js.map +1 -1
  77. package/dist/production/src/SnapshotManager.cjs +46 -0
  78. package/dist/production/src/SnapshotManager.cjs.map +1 -0
  79. package/dist/production/src/SnapshotManager.js +29 -0
  80. package/dist/production/src/SnapshotManager.js.map +1 -0
  81. package/dist/production/src/SystemClient.cjs +29 -4
  82. package/dist/production/src/SystemClient.cjs.map +1 -1
  83. package/dist/production/src/SystemClient.js +29 -4
  84. package/dist/production/src/SystemClient.js.map +1 -1
  85. package/dist/production/src/migrations.cjs.map +1 -1
  86. package/dist/production/src/migrations.js.map +1 -1
  87. package/dist/types/JsLoader.d.ts +3 -3
  88. package/dist/types/JsLoader.d.ts.map +1 -1
  89. package/dist/types/JsonLoader.d.ts +4 -4
  90. package/dist/types/JsonLoader.d.ts.map +1 -1
  91. package/dist/types/MigrationCreator.d.ts +4 -2
  92. package/dist/types/MigrationCreator.d.ts.map +1 -1
  93. package/dist/types/MigrationExecuteHelper.d.ts +6 -4
  94. package/dist/types/MigrationExecuteHelper.d.ts.map +1 -1
  95. package/dist/types/MigrationFile.d.ts +2 -2
  96. package/dist/types/MigrationFile.d.ts.map +1 -1
  97. package/dist/types/MigrationFileLoader.d.ts +1 -1
  98. package/dist/types/MigrationFileLoader.d.ts.map +1 -1
  99. package/dist/types/MigrationFilesManager.d.ts +2 -2
  100. package/dist/types/MigrationFilesManager.d.ts.map +1 -1
  101. package/dist/types/MigrationParser.d.ts +2 -2
  102. package/dist/types/MigrationParser.d.ts.map +1 -1
  103. package/dist/types/MigrationsResolver.d.ts +2 -2
  104. package/dist/types/MigrationsResolver.d.ts.map +1 -1
  105. package/dist/types/SchemaStateManager.d.ts +19 -0
  106. package/dist/types/SchemaStateManager.d.ts.map +1 -0
  107. package/dist/types/SchemaVersionBuilder.d.ts +4 -2
  108. package/dist/types/SchemaVersionBuilder.d.ts.map +1 -1
  109. package/dist/types/SnapshotManager.d.ts +31 -0
  110. package/dist/types/SnapshotManager.d.ts.map +1 -0
  111. package/dist/types/SystemClient.d.ts +11 -3
  112. package/dist/types/SystemClient.d.ts.map +1 -1
  113. package/dist/types/index.d.ts +14 -12
  114. package/dist/types/index.d.ts.map +1 -1
  115. package/dist/types/migrations.d.ts +1 -1
  116. package/dist/types/migrations.d.ts.map +1 -1
  117. package/dist/types/tsconfig.tsbuildinfo +1 -1
  118. package/package.json +6 -6
  119. package/src/JsLoader.ts +3 -3
  120. package/src/JsonLoader.ts +3 -3
  121. package/src/MigrationCreator.ts +7 -3
  122. package/src/MigrationExecuteHelper.ts +19 -8
  123. package/src/MigrationFile.ts +2 -2
  124. package/src/MigrationFileLoader.ts +1 -1
  125. package/src/MigrationFilesManager.ts +2 -2
  126. package/src/MigrationParser.ts +2 -2
  127. package/src/MigrationsResolver.ts +2 -2
  128. package/src/SchemaStateManager.ts +75 -0
  129. package/src/SchemaVersionBuilder.ts +9 -2
  130. package/src/SnapshotManager.ts +52 -0
  131. package/src/SystemClient.ts +41 -4
  132. package/src/index.ts +14 -12
  133. package/src/migrations.ts +1 -1
  134. package/tests/cases/unit/SchemaStateManager.test.ts +96 -0
  135. package/tests/cases/unit/SchemaVersionBuilder.test.ts +58 -0
  136. package/tests/cases/unit/SnapshotManager.test.ts +64 -0
@@ -1 +1 @@
1
- {"version":3,"file":"JsonLoader.js","sources":["../../../../packages/migrations-client/src/JsonLoader.ts"],"sourcesContent":["import { MigrationFileLoader } from './MigrationFileLoader'\nimport * as fs from 'node:fs/promises'\nimport { MigrationParser } from './MigrationParser'\nimport { MigrationFile } from './MigrationFile'\n\nexport class JsonLoader implements MigrationFileLoader {\n\tconstructor(\n\t\tprivate readonly migrationParser: MigrationParser,\n\t) {\n\t}\n\n\tpublic async load(file: MigrationFile) {\n\t\treturn this.migrationParser.parse(\n\t\t\tfile,\n\t\t\tJSON.parse(await fs.readFile(file.path, { encoding: 'utf8' })),\n\t\t)\n\t}\n}\n"],"names":[],"mappings":";AAKO,MAAM,WAA0C;AAAA,EACtD,YACkB,iBAChB;AADgB,SAAA,kBAAA;AAAA,EAElB;AAAA,EAEA,MAAa,KAAK,MAAqB;AACtC,WAAO,KAAK,gBAAgB;AAAA,MAC3B;AAAA,MACA,KAAK,MAAM,MAAM,GAAG,SAAS,KAAK,MAAM,EAAE,UAAU,QAAQ,CAAC;AAAA,IAAA;AAAA,EAE/D;AACD;"}
1
+ {"version":3,"file":"JsonLoader.js","sources":["../../../../packages/migrations-client/src/JsonLoader.ts"],"sourcesContent":["import { MigrationFileLoader } from './MigrationFileLoader.js'\nimport * as fs from 'node:fs/promises'\nimport { MigrationParser } from './MigrationParser.js'\nimport { MigrationFile } from './MigrationFile.js'\n\nexport class JsonLoader implements MigrationFileLoader {\n\tconstructor(\n\t\tprivate readonly migrationParser: MigrationParser,\n\t) {\n\t}\n\n\tpublic async load(file: MigrationFile) {\n\t\treturn this.migrationParser.parse(\n\t\t\tfile,\n\t\t\tJSON.parse(await fs.readFile(file.path, { encoding: 'utf8' })),\n\t\t)\n\t}\n}\n"],"names":[],"mappings":";AAKO,MAAM,WAA0C;AAAA,EACtD,YACkB,iBAChB;AADgB,SAAA,kBAAA;AAAA,EAElB;AAAA,EAEA,MAAa,KAAK,MAAqB;AACtC,WAAO,KAAK,gBAAgB;AAAA,MAC3B;AAAA,MACA,KAAK,MAAM,MAAM,GAAG,SAAS,KAAK,MAAM,EAAE,UAAU,QAAQ,CAAC;AAAA,IAAA;AAAA,EAE/D;AACD;"}
@@ -17,9 +17,9 @@ class MigrationCreator {
17
17
  const filename = await this.migrationFilesManager.createFile(this.emptyTemplates[format], fullName, format);
18
18
  return filename;
19
19
  }
20
- async prepareMigration(initialSchema, newSchema, migrationName, { skipInitialSchemaValidation = false } = {}) {
20
+ async prepareMigration(initialSchema, newSchema, migrationName, { skipInitialSchemaValidation = false, skipNonModelDiffers = false, recreateViews = false } = {}) {
21
21
  await this.migrationFilesManager.createDirIfNotExist();
22
- const modifications = this.schemaDiffer.diffSchemas(initialSchema, newSchema, { skipInitialSchemaValidation });
22
+ const modifications = this.schemaDiffer.diffSchemas(initialSchema, newSchema, { skipInitialSchemaValidation, skipNonModelDiffers, recreateViews });
23
23
  if (modifications.length === 0) {
24
24
  return null;
25
25
  }
@@ -1 +1 @@
1
- {"version":3,"file":"MigrationCreator.cjs","sources":["../../../../packages/migrations-client/src/MigrationCreator.ts"],"sourcesContent":["import { MigrationFilesManager } from './MigrationFilesManager'\nimport { Schema } from '@contember/schema'\nimport { Migration, SchemaDiffer, VERSION_LATEST } from '@contember/schema-migrations'\nimport { MigrationVersionHelper } from '@contember/engine-common'\n\nexport class MigrationCreator {\n\tconstructor(\n\t\tprivate readonly migrationFilesManager: MigrationFilesManager,\n\t\tprivate readonly schemaDiffer: SchemaDiffer,\n\t\tprivate readonly emptyTemplates: Record<string, string> = {},\n\t) {}\n\n\tasync createEmptyMigrationFile(migrationName: string, format: string): Promise<string> {\n\t\tif (!this.emptyTemplates.hasOwnProperty(format)) {\n\t\t\tthrow new Error(`Unknown format ${format}`)\n\t\t}\n\t\tawait this.migrationFilesManager.createDirIfNotExist()\n\t\tconst [, fullName] = MigrationVersionHelper.createVersion(migrationName)\n\t\tconst filename = await this.migrationFilesManager.createFile(this.emptyTemplates[format], fullName, format)\n\n\t\treturn filename\n\t}\n\n\tasync prepareMigration(\n\t\tinitialSchema: Schema,\n\t\tnewSchema: Schema,\n\t\tmigrationName: string,\n\t\t{ skipInitialSchemaValidation = false }: { skipInitialSchemaValidation?: boolean } = {},\n\t): Promise<{ migration: Migration; initialSchema: Schema } | null> {\n\t\tawait this.migrationFilesManager.createDirIfNotExist()\n\n\t\tconst modifications = this.schemaDiffer.diffSchemas(initialSchema, newSchema, { skipInitialSchemaValidation })\n\t\tif (modifications.length === 0) {\n\t\t\treturn null\n\t\t}\n\n\t\tconst migration = this.createMigration(modifications, migrationName)\n\n\t\treturn { initialSchema, migration }\n\t}\n\n\tasync saveMigration(migration: Migration): Promise<string> {\n\t\tconst jsonDiff = MigrationCreator.createContent(migration)\n\t\tconst filename = await this.migrationFilesManager.createFile(jsonDiff, migration.name)\n\t\treturn filename\n\t}\n\n\tasync removeMigration(name: string): Promise<void> {\n\t\tawait this.migrationFilesManager.removeFile(name)\n\t}\n\n\tprivate createMigration(modifications: Migration.Modification[], name: string): Migration {\n\t\tconst [version, fullName] = MigrationVersionHelper.createVersion(name)\n\t\treturn { formatVersion: VERSION_LATEST, modifications, version, name: fullName }\n\t}\n\n\tpublic static createContent({ modifications, formatVersion }: Migration): string {\n\t\treturn JSON.stringify({ formatVersion, modifications }, undefined, '\\t') + '\\n'\n\t}\n}\n"],"names":["MigrationVersionHelper","VERSION_LATEST"],"mappings":";;;;AAKO,MAAM,iBAAiB;AAAA,EAC7B,YACkB,uBACA,cACA,iBAAyC,CAAA,GACzD;AAHgB,SAAA,wBAAA;AACA,SAAA,eAAA;AACA,SAAA,iBAAA;AAAA,EACf;AAAA,EAEH,MAAM,yBAAyB,eAAuB,QAAiC;AACtF,QAAI,CAAC,KAAK,eAAe,eAAe,MAAM,GAAG;AAChD,YAAM,IAAI,MAAM,kBAAkB,MAAM,EAAE;AAAA,IAC3C;AACA,UAAM,KAAK,sBAAsB,oBAAA;AACjC,UAAM,CAAA,EAAG,QAAQ,IAAIA,oCAAuB,cAAc,aAAa;AACvE,UAAM,WAAW,MAAM,KAAK,sBAAsB,WAAW,KAAK,eAAe,MAAM,GAAG,UAAU,MAAM;AAE1G,WAAO;AAAA,EACR;AAAA,EAEA,MAAM,iBACL,eACA,WACA,eACA,EAAE,8BAA8B,MAAA,IAAqD,IACnB;AAClE,UAAM,KAAK,sBAAsB,oBAAA;AAEjC,UAAM,gBAAgB,KAAK,aAAa,YAAY,eAAe,WAAW,EAAE,6BAA6B;AAC7G,QAAI,cAAc,WAAW,GAAG;AAC/B,aAAO;AAAA,IACR;AAEA,UAAM,YAAY,KAAK,gBAAgB,eAAe,aAAa;AAEnE,WAAO,EAAE,eAAe,UAAA;AAAA,EACzB;AAAA,EAEA,MAAM,cAAc,WAAuC;AAC1D,UAAM,WAAW,iBAAiB,cAAc,SAAS;AACzD,UAAM,WAAW,MAAM,KAAK,sBAAsB,WAAW,UAAU,UAAU,IAAI;AACrF,WAAO;AAAA,EACR;AAAA,EAEA,MAAM,gBAAgB,MAA6B;AAClD,UAAM,KAAK,sBAAsB,WAAW,IAAI;AAAA,EACjD;AAAA,EAEQ,gBAAgB,eAAyC,MAAyB;AACzF,UAAM,CAAC,SAAS,QAAQ,IAAIA,aAAAA,uBAAuB,cAAc,IAAI;AACrE,WAAO,EAAE,eAAeC,iBAAAA,gBAAgB,eAAe,SAAS,MAAM,SAAA;AAAA,EACvE;AAAA,EAEA,OAAc,cAAc,EAAE,eAAe,iBAAoC;AAChF,WAAO,KAAK,UAAU,EAAE,eAAe,iBAAiB,QAAW,GAAI,IAAI;AAAA,EAC5E;AACD;;"}
1
+ {"version":3,"file":"MigrationCreator.cjs","sources":["../../../../packages/migrations-client/src/MigrationCreator.ts"],"sourcesContent":["import { MigrationFilesManager } from './MigrationFilesManager.js'\nimport { Schema } from '@contember/schema'\nimport { Migration, SchemaDiffer, VERSION_LATEST } from '@contember/schema-migrations'\nimport { MigrationVersionHelper } from '@contember/engine-common'\n\nexport class MigrationCreator {\n\tconstructor(\n\t\tprivate readonly migrationFilesManager: MigrationFilesManager,\n\t\tprivate readonly schemaDiffer: SchemaDiffer,\n\t\tprivate readonly emptyTemplates: Record<string, string> = {},\n\t) {}\n\n\tasync createEmptyMigrationFile(migrationName: string, format: string): Promise<string> {\n\t\tif (!this.emptyTemplates.hasOwnProperty(format)) {\n\t\t\tthrow new Error(`Unknown format ${format}`)\n\t\t}\n\t\tawait this.migrationFilesManager.createDirIfNotExist()\n\t\tconst [, fullName] = MigrationVersionHelper.createVersion(migrationName)\n\t\tconst filename = await this.migrationFilesManager.createFile(this.emptyTemplates[format], fullName, format)\n\n\t\treturn filename\n\t}\n\n\tasync prepareMigration(\n\t\tinitialSchema: Schema,\n\t\tnewSchema: Schema,\n\t\tmigrationName: string,\n\t\t{ skipInitialSchemaValidation = false, skipNonModelDiffers = false, recreateViews = false }: {\n\t\t\tskipInitialSchemaValidation?: boolean\n\t\t\tskipNonModelDiffers?: boolean\n\t\t\trecreateViews?: boolean\n\t\t} = {},\n\t): Promise<{ migration: Migration; initialSchema: Schema } | null> {\n\t\tawait this.migrationFilesManager.createDirIfNotExist()\n\n\t\tconst modifications = this.schemaDiffer.diffSchemas(initialSchema, newSchema, { skipInitialSchemaValidation, skipNonModelDiffers, recreateViews })\n\t\tif (modifications.length === 0) {\n\t\t\treturn null\n\t\t}\n\n\t\tconst migration = this.createMigration(modifications, migrationName)\n\n\t\treturn { initialSchema, migration }\n\t}\n\n\tasync saveMigration(migration: Migration): Promise<string> {\n\t\tconst jsonDiff = MigrationCreator.createContent(migration)\n\t\tconst filename = await this.migrationFilesManager.createFile(jsonDiff, migration.name)\n\t\treturn filename\n\t}\n\n\tasync removeMigration(name: string): Promise<void> {\n\t\tawait this.migrationFilesManager.removeFile(name)\n\t}\n\n\tprivate createMigration(modifications: Migration.Modification[], name: string): Migration {\n\t\tconst [version, fullName] = MigrationVersionHelper.createVersion(name)\n\t\treturn { formatVersion: VERSION_LATEST, modifications, version, name: fullName }\n\t}\n\n\tpublic static createContent({ modifications, formatVersion }: Migration): string {\n\t\treturn JSON.stringify({ formatVersion, modifications }, undefined, '\\t') + '\\n'\n\t}\n}\n"],"names":["MigrationVersionHelper","VERSION_LATEST"],"mappings":";;;;AAKO,MAAM,iBAAiB;AAAA,EAC7B,Y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AAAA,EAEA,OAAc,cAAc,EAAE,eAAe,iBAAoC;AAChF,WAAO,KAAK,UAAU,EAAE,eAAe,iBAAiB,QAAW,GAAI,IAAI;AAAA,EAC5E;AACD;;"}
@@ -15,9 +15,9 @@ class MigrationCreator {
15
15
  const filename = await this.migrationFilesManager.createFile(this.emptyTemplates[format], fullName, format);
16
16
  return filename;
17
17
  }
18
- async prepareMigration(initialSchema, newSchema, migrationName, { skipInitialSchemaValidation = false } = {}) {
18
+ async prepareMigration(initialSchema, newSchema, migrationName, { skipInitialSchemaValidation = false, skipNonModelDiffers = false, recreateViews = false } = {}) {
19
19
  await this.migrationFilesManager.createDirIfNotExist();
20
- const modifications = this.schemaDiffer.diffSchemas(initialSchema, newSchema, { skipInitialSchemaValidation });
20
+ const modifications = this.schemaDiffer.diffSchemas(initialSchema, newSchema, { skipInitialSchemaValidation, skipNonModelDiffers, recreateViews });
21
21
  if (modifications.length === 0) {
22
22
  return null;
23
23
  }
@@ -1 +1 @@
1
- {"version":3,"file":"MigrationCreator.js","sources":["../../../../packages/migrations-client/src/MigrationCreator.ts"],"sourcesContent":["import { MigrationFilesManager } from './MigrationFilesManager'\nimport { Schema } from '@contember/schema'\nimport { Migration, SchemaDiffer, VERSION_LATEST } from '@contember/schema-migrations'\nimport { MigrationVersionHelper } from '@contember/engine-common'\n\nexport class MigrationCreator {\n\tconstructor(\n\t\tprivate readonly migrationFilesManager: MigrationFilesManager,\n\t\tprivate readonly schemaDiffer: SchemaDiffer,\n\t\tprivate readonly emptyTemplates: Record<string, string> = {},\n\t) {}\n\n\tasync createEmptyMigrationFile(migrationName: string, format: string): Promise<string> {\n\t\tif (!this.emptyTemplates.hasOwnProperty(format)) {\n\t\t\tthrow new Error(`Unknown format ${format}`)\n\t\t}\n\t\tawait this.migrationFilesManager.createDirIfNotExist()\n\t\tconst [, fullName] = MigrationVersionHelper.createVersion(migrationName)\n\t\tconst filename = await this.migrationFilesManager.createFile(this.emptyTemplates[format], fullName, format)\n\n\t\treturn filename\n\t}\n\n\tasync prepareMigration(\n\t\tinitialSchema: Schema,\n\t\tnewSchema: Schema,\n\t\tmigrationName: string,\n\t\t{ skipInitialSchemaValidation = false }: { skipInitialSchemaValidation?: boolean } = {},\n\t): Promise<{ migration: Migration; initialSchema: Schema } | null> {\n\t\tawait this.migrationFilesManager.createDirIfNotExist()\n\n\t\tconst modifications = this.schemaDiffer.diffSchemas(initialSchema, newSchema, { skipInitialSchemaValidation })\n\t\tif (modifications.length === 0) {\n\t\t\treturn null\n\t\t}\n\n\t\tconst migration = this.createMigration(modifications, migrationName)\n\n\t\treturn { initialSchema, migration }\n\t}\n\n\tasync saveMigration(migration: Migration): Promise<string> {\n\t\tconst jsonDiff = MigrationCreator.createContent(migration)\n\t\tconst filename = await this.migrationFilesManager.createFile(jsonDiff, migration.name)\n\t\treturn filename\n\t}\n\n\tasync removeMigration(name: string): Promise<void> {\n\t\tawait this.migrationFilesManager.removeFile(name)\n\t}\n\n\tprivate createMigration(modifications: Migration.Modification[], name: string): Migration {\n\t\tconst [version, fullName] = MigrationVersionHelper.createVersion(name)\n\t\treturn { formatVersion: VERSION_LATEST, modifications, version, name: fullName }\n\t}\n\n\tpublic static createContent({ modifications, formatVersion }: Migration): string {\n\t\treturn JSON.stringify({ formatVersion, modifications }, undefined, '\\t') + '\\n'\n\t}\n}\n"],"names":[],"mappings":";;AAKO,MAAM,iBAAiB;AAAA,EAC7B,YACkB,uBACA,cACA,iBAAyC,CAAA,GACzD;AAHgB,SAAA,wBAAA;AACA,SAAA,eAAA;AACA,SAAA,iBAAA;AAAA,EACf;AAAA,EAEH,MAAM,yBAAyB,eAAuB,QAAiC;AACtF,QAAI,CAAC,KAAK,eAAe,eAAe,MAAM,GAAG;AAChD,YAAM,IAAI,MAAM,kBAAkB,MAAM,EAAE;AAAA,IAC3C;AACA,UAAM,KAAK,sBAAsB,oBAAA;AACjC,UAAM,CAAA,EAAG,QAAQ,IAAI,uBAAuB,cAAc,aAAa;AACvE,UAAM,WAAW,MAAM,KAAK,sBAAsB,WAAW,KAAK,eAAe,MAAM,GAAG,UAAU,MAAM;AAE1G,WAAO;AAAA,EACR;AAAA,EAEA,MAAM,iBACL,eACA,WACA,eACA,EAAE,8BAA8B,MAAA,IAAqD,IACnB;AAClE,UAAM,KAAK,sBAAsB,oBAAA;AAEjC,UAAM,gBAAgB,KAAK,aAAa,YAAY,eAAe,WAAW,EAAE,6BAA6B;AAC7G,QAAI,cAAc,WAAW,GAAG;AAC/B,aAAO;AAAA,IACR;AAEA,UAAM,YAAY,KAAK,gBAAgB,eAAe,aAAa;AAEnE,WAAO,EAAE,eAAe,UAAA;AAAA,EACzB;AAAA,EAEA,MAAM,cAAc,WAAuC;AAC1D,UAAM,WAAW,iBAAiB,cAAc,SAAS;AACzD,UAAM,WAAW,MAAM,KAAK,sBAAsB,WAAW,UAAU,UAAU,IAAI;AACrF,WAAO;AAAA,EACR;AAAA,EAEA,MAAM,gBAAgB,MAA6B;AAClD,UAAM,KAAK,sBAAsB,WAAW,IAAI;AAAA,EACjD;AAAA,EAEQ,gBAAgB,eAAyC,MAAyB;AACzF,UAAM,CAAC,SAAS,QAAQ,IAAI,uBAAuB,cAAc,IAAI;AACrE,WAAO,EAAE,eAAe,gBAAgB,eAAe,SAAS,MAAM,SAAA;AAAA,EACvE;AAAA,EAEA,OAAc,cAAc,EAAE,eAAe,iBAAoC;AAChF,WAAO,KAAK,UAAU,EAAE,eAAe,iBAAiB,QAAW,GAAI,IAAI;AAAA,EAC5E;AACD;"}
1
+ {"version":3,"file":"MigrationCreator.js","sources":["../../../../packages/migrations-client/src/MigrationCreator.ts"],"sourcesContent":["import { MigrationFilesManager } from './MigrationFilesManager.js'\nimport { Schema } from '@contember/schema'\nimport { Migration, SchemaDiffer, VERSION_LATEST } from '@contember/schema-migrations'\nimport { MigrationVersionHelper } from '@contember/engine-common'\n\nexport class MigrationCreator {\n\tconstructor(\n\t\tprivate readonly migrationFilesManager: MigrationFilesManager,\n\t\tprivate readonly schemaDiffer: SchemaDiffer,\n\t\tprivate readonly emptyTemplates: Record<string, string> = {},\n\t) {}\n\n\tasync createEmptyMigrationFile(migrationName: string, format: string): Promise<string> {\n\t\tif (!this.emptyTemplates.hasOwnProperty(format)) {\n\t\t\tthrow new Error(`Unknown format ${format}`)\n\t\t}\n\t\tawait this.migrationFilesManager.createDirIfNotExist()\n\t\tconst [, fullName] = MigrationVersionHelper.createVersion(migrationName)\n\t\tconst filename = await this.migrationFilesManager.createFile(this.emptyTemplates[format], fullName, format)\n\n\t\treturn filename\n\t}\n\n\tasync prepareMigration(\n\t\tinitialSchema: Schema,\n\t\tnewSchema: Schema,\n\t\tmigrationName: string,\n\t\t{ skipInitialSchemaValidation = false, skipNonModelDiffers = false, recreateViews = false }: {\n\t\t\tskipInitialSchemaValidation?: boolean\n\t\t\tskipNonModelDiffers?: boolean\n\t\t\trecreateViews?: boolean\n\t\t} = {},\n\t): Promise<{ migration: Migration; initialSchema: Schema } | null> {\n\t\tawait this.migrationFilesManager.createDirIfNotExist()\n\n\t\tconst modifications = this.schemaDiffer.diffSchemas(initialSchema, newSchema, { skipInitialSchemaValidation, skipNonModelDiffers, recreateViews })\n\t\tif (modifications.length === 0) {\n\t\t\treturn null\n\t\t}\n\n\t\tconst migration = this.createMigration(modifications, migrationName)\n\n\t\treturn { initialSchema, migration }\n\t}\n\n\tasync saveMigration(migration: Migration): Promise<string> {\n\t\tconst jsonDiff = MigrationCreator.createContent(migration)\n\t\tconst filename = await this.migrationFilesManager.createFile(jsonDiff, migration.name)\n\t\treturn filename\n\t}\n\n\tasync removeMigration(name: string): Promise<void> {\n\t\tawait this.migrationFilesManager.removeFile(name)\n\t}\n\n\tprivate createMigration(modifications: Migration.Modification[], name: string): Migration {\n\t\tconst [version, fullName] = MigrationVersionHelper.createVersion(name)\n\t\treturn { formatVersion: VERSION_LATEST, modifications, version, name: fullName }\n\t}\n\n\tpublic static createContent({ modifications, formatVersion }: Migration): string {\n\t\treturn JSON.stringify({ formatV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AI;AACrE,WAAO,EAAE,eAAe,gBAAgB,eAAe,SAAS,MAAM,SAAA;AAAA,EACvE;AAAA,EAEA,OAAc,cAAc,EAAE,eAAe,iBAAoC;AAChF,WAAO,KAAK,UAAU,EAAE,eAAe,iBAAiB,QAAW,GAAI,IAAI;AAAA,EAC5E;AACD;"}
@@ -7,14 +7,16 @@ class MigrationExecutor {
7
7
  migrations,
8
8
  contentMigrationFactoryArgs,
9
9
  force,
10
+ schemaState,
10
11
  log = () => null
11
12
  }) {
12
- if (migrations.length === 0) {
13
+ if (migrations.length === 0 && !schemaState) {
13
14
  return;
14
15
  }
15
16
  let migrationsToRun = [];
17
+ let batchSchemaState;
16
18
  const executeMigrations = async () => {
17
- if (migrationsToRun.length === 0) {
19
+ if (migrationsToRun.length === 0 && !batchSchemaState) {
18
20
  return;
19
21
  }
20
22
  await client.migrate(
@@ -41,14 +43,18 @@ class MigrationExecutor {
41
43
  }
42
44
  return assertNever.assertNever();
43
45
  }),
44
- force
46
+ force,
47
+ batchSchemaState
45
48
  );
46
49
  migrationsToRun.forEach((it) => {
47
50
  log(it.name);
48
51
  });
49
52
  migrationsToRun = [];
53
+ batchSchemaState = void 0;
50
54
  };
51
- log("Executing...");
55
+ if (migrations.length > 0) {
56
+ log("Executing...");
57
+ }
52
58
  for (const migration of migrations) {
53
59
  const migrationContent = await migration.localMigration.getContent();
54
60
  if (migrationContent.type === "factory") {
@@ -63,8 +69,11 @@ class MigrationExecutor {
63
69
  migrationsToRun.push(migrationContent);
64
70
  }
65
71
  }
72
+ batchSchemaState = schemaState;
66
73
  await executeMigrations();
67
- log("Migration executed");
74
+ if (migrations.length > 0) {
75
+ log("Migration executed");
76
+ }
68
77
  }
69
78
  }
70
79
  exports.MigrationExecutor = MigrationExecutor;
@@ -1 +1 @@
1
- {"version":3,"file":"MigrationExecuteHelper.cjs","sources":["../../../../packages/migrations-client/src/MigrationExecuteHelper.ts"],"sourcesContent":["import { MigrationToExecuteOkStatus } from './migrations'\nimport { ContentMigrationFactoryArgs, ResolvedMigrationContent } from './MigrationFile'\nimport { assertNever } from './utils/assertNever'\nimport { SystemClient } from './SystemClient'\n\nexport class MigrationExecutor {\n\tasync executeMigrations({\n\t\tclient,\n\t\tmigrations,\n\t\tcontentMigrationFactoryArgs,\n\t\tforce,\n\t\tlog = () => null,\n\t}: {\n\t\tclient: SystemClient\n\t\tmigrations: MigrationToExecuteOkStatus[]\n\t\tcontentMigrationFactoryArgs: Omit<ContentMigrationFactoryArgs, 'migration'>\n\t\tlog: (message: string) => void\n\t\tforce?: boolean\n\t}): Promise<void> {\n\t\tif (migrations.length === 0) {\n\t\t\treturn\n\t\t}\n\t\tlet migrationsToRun: ResolvedMigrationContent[] = []\n\n\t\tconst executeMigrations = async () => {\n\t\t\tif (migrationsToRun.length === 0) {\n\t\t\t\treturn\n\t\t\t}\n\t\t\tawait client.migrate(\n\t\t\t\tmigrationsToRun.map(it => {\n\t\t\t\t\tif (it.type === 'schema') {\n\t\t\t\t\t\treturn {\n\t\t\t\t\t\t\tversion: it.version,\n\t\t\t\t\t\t\tname: it.name,\n\t\t\t\t\t\t\ttype: 'SCHEMA',\n\t\t\t\t\t\t\tschemaMigration: {\n\t\t\t\t\t\t\t\tformatVersion: it.formatVersion,\n\t\t\t\t\t\t\t\tmodifications: it.modifications,\n\t\t\t\t\t\t\t\tskippedErrors: it.skippedErrors,\n\t\t\t\t\t\t\t},\n\t\t\t\t\t\t}\n\t\t\t\t\t}\n\t\t\t\t\tif (it.type === 'content') {\n\t\t\t\t\t\treturn {\n\t\t\t\t\t\t\tversion: it.version,\n\t\t\t\t\t\t\tname: it.name,\n\t\t\t\t\t\t\ttype: 'CONTENT',\n\t\t\t\t\t\t\tcontentMigration: it.queries,\n\t\t\t\t\t\t}\n\t\t\t\t\t}\n\t\t\t\t\treturn assertNever(it)\n\t\t\t\t}),\n\t\t\t\tforce,\n\t\t\t)\n\t\t\tmigrationsToRun.forEach(it => {\n\t\t\t\tlog(it.name)\n\t\t\t})\n\t\t\tmigrationsToRun = []\n\t\t}\n\n\t\tlog('Executing...')\n\n\t\tfor (const migration of migrations) {\n\t\t\tconst migrationContent = await migration.localMigration.getContent()\n\t\t\tif (migrationContent.type === 'factory') {\n\t\t\t\tawait executeMigrations()\n\t\t\t\tconst result = await migrationContent.factory({\n\t\t\t\t\t...contentMigrationFactoryArgs,\n\t\t\t\t\tmigration: migration.localMigration,\n\t\t\t\t})\n\t\t\t\tmigrationsToRun.push(result)\n\t\t\t\tawait executeMigrations()\n\t\t\t} else {\n\t\t\t\tmigrationsToRun.push(migrationContent)\n\t\t\t}\n\t\t}\n\t\tawait executeMigrations()\n\t\tlog('Migration executed')\n\t}\n}\n"],"names":["assertNever"],"mappings":";;;AAKO,MAAM,kBAAkB;AAAA,EAC9B,MAAM,kBAAkB;AAAA,IACvB;AAAA,IACA;AAAA,IACA;AAAA,IACA;AAAA,IACA,MAAM,MAAM;AAAA,EAAA,GAOK;AACjB,QAAI,WAAW,WAAW,GAAG;AAC5B;AAAA,IACD;AACA,QAAI,kBAA8C,CAAA;AAElD,UAAM,oBAAoB,YAAY;AACrC,UAAI,gBAAgB,WAAW,GAAG;AACjC;AAAA,MACD;AACA,YAAM,OAAO;AAAA,QACZ,gBAAgB,IAAI,CAAA,OAAM;AACzB,cAAI,GAAG,SAAS,UAAU;AACzB,mBAAO;AAAA,cACN,SAAS,GAAG;AAAA,cACZ,MAAM,GAAG;AAAA,cACT,MAAM;AAAA,cACN,iBAAiB;AAAA,gBAChB,eAAe,GAAG;AAAA,gBAClB,eAAe,GAAG;AAAA,gBAClB,eAAe,GAAG;AAAA,cAAA;AAAA,YACnB;AAAA,UAEF;AACA,cAAI,GAAG,SAAS,WAAW;AAC1B,mBAAO;AAAA,cACN,SAAS,GAAG;AAAA,cACZ,MAAM,GAAG;AAAA,cACT,MAAM;AAAA,cACN,kBAAkB,GAAG;AAAA,YAAA;AAAA,UAEvB;AACA,iBAAOA,YAAAA,YAAc;AAAA,QACtB,CAAC;AAAA,QACD;AAAA,MAAA;AAED,sBAAgB,QAAQ,CAAA,OAAM;AAC7B,YAAI,GAAG,IAAI;AAAA,MACZ,CAAC;AACD,wBAAkB,CAAA;AAAA,IACnB;AAEA,QAAI,cAAc;AAElB,eAAW,aAAa,YAAY;AACnC,YAAM,mBAAmB,MAAM,UAAU,eAAe,WAAA;AACxD,UAAI,iBAAiB,SAAS,WAAW;AACxC,cAAM,kBAAA;AACN,cAAM,SAAS,MAAM,iBAAiB,QAAQ;AAAA,UAC7C,GAAG;AAAA,UACH,WAAW,UAAU;AAAA,QAAA,CACrB;AACD,wBAAgB,KAAK,MAAM;AAC3B,cAAM,kBAAA;AAAA,MACP,OAAO;AACN,wBAAgB,KAAK,gBAAgB;AAAA,MACtC;AAAA,IACD;AACA,UAAM,kBAAA;AACN,QAAI,oBAAoB;AAAA,EACzB;AACD;;"}
1
+ {"version":3,"file":"MigrationExecuteHelper.cjs","sources":["../../../../packages/migrations-client/src/MigrationExecuteHelper.ts"],"sourcesContent":["import { MigrationToExecuteOkStatus } from './migrations.js'\nimport { ContentMigrationFactoryArgs, ResolvedMigrationContent } from './MigrationFile.js'\nimport { assertNever } from './utils/assertNever.js'\nimport { SystemClient } from './SystemClient.js'\nimport { SchemaState } from './SchemaStateManager.js'\n\nexport class MigrationExecutor {\n\tasync executeMigrations({\n\t\tclient,\n\t\tmigrations,\n\t\tcontentMigrationFactoryArgs,\n\t\tforce,\n\t\tschemaState,\n\t\tlog = () => null,\n\t}: {\n\t\tclient: SystemClient\n\t\tmigrations: MigrationToExecuteOkStatus[]\n\t\tcontentMigrationFactoryArgs: Omit<ContentMigrationFactoryArgs, 'migration'>\n\t\tlog: (message: string) => void\n\t\tforce?: boolean\n\t\tschemaState?: SchemaState\n\t}): Promise<void> {\n\t\tif (migrations.length === 0 && !schemaState) {\n\t\t\treturn\n\t\t}\n\t\tlet migrationsToRun: ResolvedMigrationContent[] = []\n\t\tlet batchSchemaState: SchemaState | undefined\n\n\t\tconst executeMigrations = async () => {\n\t\t\tif (migrationsToRun.length === 0 && !batchSchemaState) {\n\t\t\t\treturn\n\t\t\t}\n\t\t\tawait client.migrate(\n\t\t\t\tmigrationsToRun.map(it => {\n\t\t\t\t\tif (it.type === 'schema') {\n\t\t\t\t\t\treturn {\n\t\t\t\t\t\t\tversion: it.version,\n\t\t\t\t\t\t\tname: it.name,\n\t\t\t\t\t\t\ttype: 'SCHEMA',\n\t\t\t\t\t\t\tschemaMigration: {\n\t\t\t\t\t\t\t\tformatVersion: it.formatVersion,\n\t\t\t\t\t\t\t\tmodifications: it.modifications,\n\t\t\t\t\t\t\t\tskippedErrors: it.skippedErrors,\n\t\t\t\t\t\t\t},\n\t\t\t\t\t\t}\n\t\t\t\t\t}\n\t\t\t\t\tif (it.type === 'content') {\n\t\t\t\t\t\treturn {\n\t\t\t\t\t\t\tversion: it.version,\n\t\t\t\t\t\t\tname: it.name,\n\t\t\t\t\t\t\ttype: 'CONTENT',\n\t\t\t\t\t\t\tcontentMigration: it.queries,\n\t\t\t\t\t\t}\n\t\t\t\t\t}\n\t\t\t\t\treturn assertNever(it)\n\t\t\t\t}),\n\t\t\t\tforce,\n\t\t\t\tbatchSchemaState,\n\t\t\t)\n\t\t\tmigrationsToRun.forEach(it => {\n\t\t\t\tlog(it.name)\n\t\t\t})\n\t\t\tmigrationsToRun = []\n\t\t\tbatchSchemaState = undefined\n\t\t}\n\n\t\tif (migrations.length > 0) {\n\t\t\tlog('Executing...')\n\t\t}\n\n\t\tfor (const migration of migrations) {\n\t\t\tconst migrationContent = await migration.localMigration.getContent()\n\t\t\tif (migrationContent.type === 'factory') {\n\t\t\t\tawait executeMigrations()\n\t\t\t\tconst result = await migrationContent.factory({\n\t\t\t\t\t...contentMigrationFactoryArgs,\n\t\t\t\t\tmigration: migration.localMigration,\n\t\t\t\t})\n\t\t\t\tmigrationsToRun.push(result)\n\t\t\t\tawait executeMigrations()\n\t\t\t} else {\n\t\t\t\tmigrationsToRun.push(migrationContent)\n\t\t\t}\n\t\t}\n\t\tbatchSchemaState = schemaState\n\t\tawait executeMigrations()\n\t\tif (migrations.length > 0) {\n\t\t\tlog('Migration executed')\n\t\t}\n\t}\n}\n"],"names":["assertNever"],"mappings":";;;AAMO,MAAM,kBAAkB;AAAA,EAC9B,MAAM,kBAAkB;AAAA,IACvB;AAAA,IACA;AAAA,IACA;AAAA,IACA;AAAA,IACA;AAAA,IACA,MAAM,MAAM;AAAA,EAAA,GAQK;AACjB,QAAI,WAAW,WAAW,KAAK,CAAC,aAAa;AAC5C;AAAA,IACD;AACA,QAAI,kBAA8C,CAAA;AAClD,QAAI;AAEJ,UAAM,oBAAoB,YAAY;AACrC,UAAI,gBAAgB,WAAW,KAAK,CAAC,kBAAkB;AACtD;AAAA,MACD;AACA,YAAM,OAAO;AAAA,QACZ,gBAAgB,IAAI,CAAA,OAAM;AACzB,cAAI,GAAG,SAAS,UAAU;AACzB,mBAAO;AAAA,cACN,SAAS,GAAG;AAAA,cACZ,MAAM,GAAG;AAAA,cACT,MAAM;AAAA,cACN,iBAAiB;AAAA,gBAChB,eAAe,GAAG;AAAA,gBAClB,eAAe,GAAG;AAAA,gBAClB,eAAe,GAAG;AAAA,cAAA;AAAA,YACnB;AAAA,UAEF;AACA,cAAI,GAAG,SAAS,WAAW;AAC1B,mBAAO;AAAA,cACN,SAAS,GAAG;AAAA,cACZ,MAAM,GAAG;AAAA,cACT,MAAM;AAAA,cACN,kBAAkB,GAAG;AAAA,YAAA;AAAA,UAEvB;AACA,iBAAOA,YAAAA,YAAc;AAAA,QACtB,CAAC;AAAA,QACD;AAAA,QACA;AAAA,MAAA;AAED,sBAAgB,QAAQ,CAAA,OAAM;AAC7B,YAAI,GAAG,IAAI;AAAA,MACZ,CAAC;AACD,wBAAkB,CAAA;AAClB,yBAAmB;AAAA,IACpB;AAEA,QAAI,WAAW,SAAS,GAAG;AAC1B,UAAI,cAAc;AAAA,IACnB;AAEA,eAAW,aAAa,YAAY;AACnC,YAAM,mBAAmB,MAAM,UAAU,eAAe,WAAA;AACxD,UAAI,iBAAiB,SAAS,WAAW;AACxC,cAAM,kBAAA;AACN,cAAM,SAAS,MAAM,iBAAiB,QAAQ;AAAA,UAC7C,GAAG;AAAA,UACH,WAAW,UAAU;AAAA,QAAA,CACrB;AACD,wBAAgB,KAAK,MAAM;AAC3B,cAAM,kBAAA;AAAA,MACP,OAAO;AACN,wBAAgB,KAAK,gBAAgB;AAAA,MACtC;AAAA,IACD;AACA,uBAAmB;AACnB,UAAM,kBAAA;AACN,QAAI,WAAW,SAAS,GAAG;AAC1B,UAAI,oBAAoB;AAAA,IACzB;AAAA,EACD;AACD;;"}
@@ -5,14 +5,16 @@ class MigrationExecutor {
5
5
  migrations,
6
6
  contentMigrationFactoryArgs,
7
7
  force,
8
+ schemaState,
8
9
  log = () => null
9
10
  }) {
10
- if (migrations.length === 0) {
11
+ if (migrations.length === 0 && !schemaState) {
11
12
  return;
12
13
  }
13
14
  let migrationsToRun = [];
15
+ let batchSchemaState;
14
16
  const executeMigrations = async () => {
15
- if (migrationsToRun.length === 0) {
17
+ if (migrationsToRun.length === 0 && !batchSchemaState) {
16
18
  return;
17
19
  }
18
20
  await client.migrate(
@@ -39,14 +41,18 @@ class MigrationExecutor {
39
41
  }
40
42
  return assertNever();
41
43
  }),
42
- force
44
+ force,
45
+ batchSchemaState
43
46
  );
44
47
  migrationsToRun.forEach((it) => {
45
48
  log(it.name);
46
49
  });
47
50
  migrationsToRun = [];
51
+ batchSchemaState = void 0;
48
52
  };
49
- log("Executing...");
53
+ if (migrations.length > 0) {
54
+ log("Executing...");
55
+ }
50
56
  for (const migration of migrations) {
51
57
  const migrationContent = await migration.localMigration.getContent();
52
58
  if (migrationContent.type === "factory") {
@@ -61,8 +67,11 @@ class MigrationExecutor {
61
67
  migrationsToRun.push(migrationContent);
62
68
  }
63
69
  }
70
+ batchSchemaState = schemaState;
64
71
  await executeMigrations();
65
- log("Migration executed");
72
+ if (migrations.length > 0) {
73
+ log("Migration executed");
74
+ }
66
75
  }
67
76
  }
68
77
  export {
@@ -1 +1 @@
1
- {"version":3,"file":"MigrationExecuteHelper.js","sources":["../../../../packages/migrations-client/src/MigrationExecuteHelper.ts"],"sourcesContent":["import { MigrationToExecuteOkStatus } from './migrations'\nimport { ContentMigrationFactoryArgs, ResolvedMigrationContent } from './MigrationFile'\nimport { assertNever } from './utils/assertNever'\nimport { SystemClient } from './SystemClient'\n\nexport class MigrationExecutor {\n\tasync executeMigrations({\n\t\tclient,\n\t\tmigrations,\n\t\tcontentMigrationFactoryArgs,\n\t\tforce,\n\t\tlog = () => null,\n\t}: {\n\t\tclient: SystemClient\n\t\tmigrations: MigrationToExecuteOkStatus[]\n\t\tcontentMigrationFactoryArgs: Omit<ContentMigrationFactoryArgs, 'migration'>\n\t\tlog: (message: string) => void\n\t\tforce?: boolean\n\t}): Promise<void> {\n\t\tif (migrations.length === 0) {\n\t\t\treturn\n\t\t}\n\t\tlet migrationsToRun: ResolvedMigrationContent[] = []\n\n\t\tconst executeMigrations = async () => {\n\t\t\tif (migrationsToRun.length === 0) {\n\t\t\t\treturn\n\t\t\t}\n\t\t\tawait client.migrate(\n\t\t\t\tmigrationsToRun.map(it => {\n\t\t\t\t\tif (it.type === 'schema') {\n\t\t\t\t\t\treturn {\n\t\t\t\t\t\t\tversion: it.version,\n\t\t\t\t\t\t\tname: it.name,\n\t\t\t\t\t\t\ttype: 'SCHEMA',\n\t\t\t\t\t\t\tschemaMigration: {\n\t\t\t\t\t\t\t\tformatVersion: it.formatVersion,\n\t\t\t\t\t\t\t\tmodifications: it.modifications,\n\t\t\t\t\t\t\t\tskippedErrors: it.skippedErrors,\n\t\t\t\t\t\t\t},\n\t\t\t\t\t\t}\n\t\t\t\t\t}\n\t\t\t\t\tif (it.type === 'content') {\n\t\t\t\t\t\treturn {\n\t\t\t\t\t\t\tversion: it.version,\n\t\t\t\t\t\t\tname: it.name,\n\t\t\t\t\t\t\ttype: 'CONTENT',\n\t\t\t\t\t\t\tcontentMigration: it.queries,\n\t\t\t\t\t\t}\n\t\t\t\t\t}\n\t\t\t\t\treturn assertNever(it)\n\t\t\t\t}),\n\t\t\t\tforce,\n\t\t\t)\n\t\t\tmigrationsToRun.forEach(it => {\n\t\t\t\tlog(it.name)\n\t\t\t})\n\t\t\tmigrationsToRun = []\n\t\t}\n\n\t\tlog('Executing...')\n\n\t\tfor (const migration of migrations) {\n\t\t\tconst migrationContent = await migration.localMigration.getContent()\n\t\t\tif (migrationContent.type === 'factory') {\n\t\t\t\tawait executeMigrations()\n\t\t\t\tconst result = await migrationContent.factory({\n\t\t\t\t\t...contentMigrationFactoryArgs,\n\t\t\t\t\tmigration: migration.localMigration,\n\t\t\t\t})\n\t\t\t\tmigrationsToRun.push(result)\n\t\t\t\tawait executeMigrations()\n\t\t\t} else {\n\t\t\t\tmigrationsToRun.push(migrationContent)\n\t\t\t}\n\t\t}\n\t\tawait executeMigrations()\n\t\tlog('Migration executed')\n\t}\n}\n"],"names":[],"mappings":";AAKO,MAAM,kBAAkB;AAAA,EAC9B,MAAM,kBAAkB;AAAA,IACvB;AAAA,IACA;AAAA,IACA;AAAA,IACA;AAAA,IACA,MAAM,MAAM;AAAA,EAAA,GAOK;AACjB,QAAI,WAAW,WAAW,GAAG;AAC5B;AAAA,IACD;AACA,QAAI,kBAA8C,CAAA;AAElD,UAAM,oBAAoB,YAAY;AACrC,UAAI,gBAAgB,WAAW,GAAG;AACjC;AAAA,MACD;AACA,YAAM,OAAO;AAAA,QACZ,gBAAgB,IAAI,CAAA,OAAM;AACzB,cAAI,GAAG,SAAS,UAAU;AACzB,mBAAO;AAAA,cACN,SAAS,GAAG;AAAA,cACZ,MAAM,GAAG;AAAA,cACT,MAAM;AAAA,cACN,iBAAiB;AAAA,gBAChB,eAAe,GAAG;AAAA,gBAClB,eAAe,GAAG;AAAA,gBAClB,eAAe,GAAG;AAAA,cAAA;AAAA,YACnB;AAAA,UAEF;AACA,cAAI,GAAG,SAAS,WAAW;AAC1B,mBAAO;AAAA,cACN,SAAS,GAAG;AAAA,cACZ,MAAM,GAAG;AAAA,cACT,MAAM;AAAA,cACN,kBAAkB,GAAG;AAAA,YAAA;AAAA,UAEvB;AACA,iBAAO,YAAc;AAAA,QACtB,CAAC;AAAA,QACD;AAAA,MAAA;AAED,sBAAgB,QAAQ,CAAA,OAAM;AAC7B,YAAI,GAAG,IAAI;AAAA,MACZ,CAAC;AACD,wBAAkB,CAAA;AAAA,IACnB;AAEA,QAAI,cAAc;AAElB,eAAW,aAAa,YAAY;AACnC,YAAM,mBAAmB,MAAM,UAAU,eAAe,WAAA;AACxD,UAAI,iBAAiB,SAAS,WAAW;AACxC,cAAM,kBAAA;AACN,cAAM,SAAS,MAAM,iBAAiB,QAAQ;AAAA,UAC7C,GAAG;AAAA,UACH,WAAW,UAAU;AAAA,QAAA,CACrB;AACD,wBAAgB,KAAK,MAAM;AAC3B,cAAM,kBAAA;AAAA,MACP,OAAO;AACN,wBAAgB,KAAK,gBAAgB;AAAA,MACtC;AAAA,IACD;AACA,UAAM,kBAAA;AACN,QAAI,oBAAoB;AAAA,EACzB;AACD;"}
1
+ {"version":3,"file":"MigrationExecuteHelper.js","sources":["../../../../packages/migrations-client/src/MigrationExecuteHelper.ts"],"sourcesContent":["import { MigrationToExecuteOkStatus } from './migrations.js'\nimport { ContentMigrationFactoryArgs, ResolvedMigrationContent } from './MigrationFile.js'\nimport { assertNever } from './utils/assertNever.js'\nimport { SystemClient } from './SystemClient.js'\nimport { SchemaState } from './SchemaStateManager.js'\n\nexport class MigrationExecutor {\n\tasync executeMigrations({\n\t\tclient,\n\t\tmigrations,\n\t\tcontentMigrationFactoryArgs,\n\t\tforce,\n\t\tschemaState,\n\t\tlog = () => null,\n\t}: {\n\t\tclient: SystemClient\n\t\tmigrations: MigrationToExecuteOkStatus[]\n\t\tcontentMigrationFactoryArgs: Omit<ContentMigrationFactoryArgs, 'migration'>\n\t\tlog: (message: string) => void\n\t\tforce?: boolean\n\t\tschemaState?: SchemaState\n\t}): Promise<void> {\n\t\tif (migrations.length === 0 && !schemaState) {\n\t\t\treturn\n\t\t}\n\t\tlet migrationsToRun: ResolvedMigrationContent[] = []\n\t\tlet batchSchemaState: SchemaState | undefined\n\n\t\tconst executeMigrations = async () => {\n\t\t\tif (migrationsToRun.length === 0 && !batchSchemaState) {\n\t\t\t\treturn\n\t\t\t}\n\t\t\tawait client.migrate(\n\t\t\t\tmigrationsToRun.map(it => {\n\t\t\t\t\tif (it.type === 'schema') {\n\t\t\t\t\t\treturn {\n\t\t\t\t\t\t\tversion: it.version,\n\t\t\t\t\t\t\tname: it.name,\n\t\t\t\t\t\t\ttype: 'SCHEMA',\n\t\t\t\t\t\t\tschemaMigration: {\n\t\t\t\t\t\t\t\tformatVersion: it.formatVersion,\n\t\t\t\t\t\t\t\tmodifications: it.modifications,\n\t\t\t\t\t\t\t\tskippedErrors: it.skippedErrors,\n\t\t\t\t\t\t\t},\n\t\t\t\t\t\t}\n\t\t\t\t\t}\n\t\t\t\t\tif (it.type === 'content') {\n\t\t\t\t\t\treturn {\n\t\t\t\t\t\t\tversion: it.version,\n\t\t\t\t\t\t\tname: it.name,\n\t\t\t\t\t\t\ttype: 'CONTENT',\n\t\t\t\t\t\t\tcontentMigration: it.queries,\n\t\t\t\t\t\t}\n\t\t\t\t\t}\n\t\t\t\t\treturn assertNever(it)\n\t\t\t\t}),\n\t\t\t\tforce,\n\t\t\t\tbatchSchemaState,\n\t\t\t)\n\t\t\tmigrationsToRun.forEach(it => {\n\t\t\t\tlog(it.name)\n\t\t\t})\n\t\t\tmigrationsToRun = []\n\t\t\tbatchSchemaState = undefined\n\t\t}\n\n\t\tif (migrations.length > 0) {\n\t\t\tlog('Executing...')\n\t\t}\n\n\t\tfor (const migration of migrations) {\n\t\t\tconst migrationContent = await migration.localMigration.getContent()\n\t\t\tif (migrationContent.type === 'factory') {\n\t\t\t\tawait executeMigrations()\n\t\t\t\tconst result = await migrationContent.factory({\n\t\t\t\t\t...contentMigrationFactoryArgs,\n\t\t\t\t\tmigration: migration.localMigration,\n\t\t\t\t})\n\t\t\t\tmigrationsToRun.push(result)\n\t\t\t\tawait executeMigrations()\n\t\t\t} else {\n\t\t\t\tmigrationsToRun.push(migrationContent)\n\t\t\t}\n\t\t}\n\t\tbatchSchemaState = schemaState\n\t\tawait executeMigrations()\n\t\tif (migrations.length > 0) {\n\t\t\tlog('Migration executed')\n\t\t}\n\t}\n}\n"],"names":[],"mappings":";AAMO,MAAM,kBAAkB;AAAA,EAC9B,MAAM,kBAAkB;AAAA,IACvB;AAAA,IACA;AAAA,IACA;AAAA,IACA;AAAA,IACA;AAAA,IACA,MAAM,MAAM;AAAA,EAAA,GAQK;AACjB,QAAI,WAAW,WAAW,KAAK,CAAC,aAAa;AAC5C;AAAA,IACD;AACA,QAAI,kBAA8C,CAAA;AAClD,QAAI;AAEJ,UAAM,oBAAoB,YAAY;AACrC,UAAI,gBAAgB,WAAW,KAAK,CAAC,kBAAkB;AACtD;AAAA,MACD;AACA,YAAM,OAAO;AAAA,QACZ,gBAAgB,IAAI,CAAA,OAAM;AACzB,cAAI,GAAG,SAAS,UAAU;AACzB,mBAAO;AAAA,cACN,SAAS,GAAG;AAAA,cACZ,MAAM,GAAG;AAAA,cACT,MAAM;AAAA,cACN,iBAAiB;AAAA,gBAChB,eAAe,GAAG;AAAA,gBAClB,eAAe,GAAG;AAAA,gBAClB,eAAe,GAAG;AAAA,cAAA;AAAA,YACnB;AAAA,UAEF;AACA,cAAI,GAAG,SAAS,WAAW;AAC1B,mBAAO;AAAA,cACN,SAAS,GAAG;AAAA,cACZ,MAAM,GAAG;AAAA,cACT,MAAM;AAAA,cACN,kBAAkB,GAAG;AAAA,YAAA;AAAA,UAEvB;AACA,iBAAO,YAAc;AAAA,QACtB,CAAC;AAAA,QACD;AAAA,QACA;AAAA,MAAA;AAED,sBAAgB,QAAQ,CAAA,OAAM;AAC7B,YAAI,GAAG,IAAI;AAAA,MACZ,CAAC;AACD,wBAAkB,CAAA;AAClB,yBAAmB;AAAA,IACpB;AAEA,QAAI,WAAW,SAAS,GAAG;AAC1B,UAAI,cAAc;AAAA,IACnB;AAEA,eAAW,aAAa,YAAY;AACnC,YAAM,mBAAmB,MAAM,UAAU,eAAe,WAAA;AACxD,UAAI,iBAAiB,SAAS,WAAW;AACxC,cAAM,kBAAA;AACN,cAAM,SAAS,MAAM,iBAAiB,QAAQ;AAAA,UAC7C,GAAG;AAAA,UACH,WAAW,UAAU;AAAA,QAAA,CACrB;AACD,wBAAgB,KAAK,MAAM;AAC3B,cAAM,kBAAA;AAAA,MACP,OAAO;AACN,wBAAgB,KAAK,gBAAgB;AAAA,MACtC;AAAA,IACD;AACA,uBAAmB;AACnB,UAAM,kBAAA;AACN,QAAI,WAAW,SAAS,GAAG;AAC1B,UAAI,oBAAoB;AAAA,IACzB;AAAA,EACD;AACD;"}
@@ -1 +1 @@
1
- {"version":3,"file":"MigrationFile.cjs","sources":["../../../../packages/migrations-client/src/MigrationFile.ts"],"sourcesContent":["import { Migration } from '@contember/schema-migrations'\nimport { JSONObject } from './utils/json'\nimport { SchemaVersionBuilder } from './SchemaVersionBuilder'\n\nexport interface MigrationFile {\n\tpath: string\n\tversion: string\n\tname: string\n\n\tgetContent: () => Promise<MigrationContent>\n}\n\nexport const isSchemaMigration = (content: MigrationContent): content is SchemaMigration =>\n\ttypeof content !== 'function' && 'modifications' in content\n\nexport type ResolvedMigrationContent =\n\t| SchemaMigration\n\t| ContentMigration\n\nexport type MigrationContent =\n\t| ResolvedMigrationContent\n\t| ContentMigrationFactory\n\nexport type SchemaMigration =\n\t& {\n\t\ttype: 'schema'\n\t}\n\t& Migration\n\nexport type ContentMigration = {\n\ttype: 'content'\n\tversion: string\n\tname: string\n\tqueries: ContentMigrationQuery[]\n}\n\nexport type ContentMigrationFactoryArgs = {\n\tapiBaseUrl: string\n\tprojectName: string\n\tapiToken: string\n\tmigration: MigrationFile\n\tschemaVersionBuilder: SchemaVersionBuilder\n}\n\nexport type ContentMigrationFactory = {\n\ttype: 'factory'\n\tfactory: (args: ContentMigrationFactoryArgs) => Promise<ContentMigration>\n}\n\nexport type ContentMigrationQuery = {\n\tquery: string\n\tvariables?: JSONObject\n\tstage?: string\n\tcheckMutationResult?: boolean\n}\n"],"names":[],"mappings":";;AAYO,MAAM,oBAAoB,CAAC,YACjC,OAAO,YAAY,cAAc,mBAAmB;;"}
1
+ {"version":3,"file":"MigrationFile.cjs","sources":["../../../../packages/migrations-client/src/MigrationFile.ts"],"sourcesContent":["import { Migration } from '@contember/schema-migrations'\nimport { JSONObject } from './utils/json.js'\nimport { SchemaVersionBuilder } from './SchemaVersionBuilder.js'\n\nexport interface MigrationFile {\n\tpath: string\n\tversion: string\n\tname: string\n\n\tgetContent: () => Promise<MigrationContent>\n}\n\nexport const isSchemaMigration = (content: MigrationContent): content is SchemaMigration =>\n\ttypeof content !== 'function' && 'modifications' in content\n\nexport type ResolvedMigrationContent =\n\t| SchemaMigration\n\t| ContentMigration\n\nexport type MigrationContent =\n\t| ResolvedMigrationContent\n\t| ContentMigrationFactory\n\nexport type SchemaMigration =\n\t& {\n\t\ttype: 'schema'\n\t}\n\t& Migration\n\nexport type ContentMigration = {\n\ttype: 'content'\n\tversion: string\n\tname: string\n\tqueries: ContentMigrationQuery[]\n}\n\nexport type ContentMigrationFactoryArgs = {\n\tapiBaseUrl: string\n\tprojectName: string\n\tapiToken: string\n\tmigration: MigrationFile\n\tschemaVersionBuilder: SchemaVersionBuilder\n}\n\nexport type ContentMigrationFactory = {\n\ttype: 'factory'\n\tfactory: (args: ContentMigrationFactoryArgs) => Promise<ContentMigration>\n}\n\nexport type ContentMigrationQuery = {\n\tquery: string\n\tvariables?: JSONObject\n\tstage?: string\n\tcheckMutationResult?: boolean\n}\n"],"names":[],"mappings":";;AAYO,MAAM,oBAAoB,CAAC,YACjC,OAAO,YAAY,cAAc,mBAAmB;;"}
@@ -1 +1 @@
1
- {"version":3,"file":"MigrationFile.js","sources":["../../../../packages/migrations-client/src/MigrationFile.ts"],"sourcesContent":["import { Migration } from '@contember/schema-migrations'\nimport { JSONObject } from './utils/json'\nimport { SchemaVersionBuilder } from './SchemaVersionBuilder'\n\nexport interface MigrationFile {\n\tpath: string\n\tversion: string\n\tname: string\n\n\tgetContent: () => Promise<MigrationContent>\n}\n\nexport const isSchemaMigration = (content: MigrationContent): content is SchemaMigration =>\n\ttypeof content !== 'function' && 'modifications' in content\n\nexport type ResolvedMigrationContent =\n\t| SchemaMigration\n\t| ContentMigration\n\nexport type MigrationContent =\n\t| ResolvedMigrationContent\n\t| ContentMigrationFactory\n\nexport type SchemaMigration =\n\t& {\n\t\ttype: 'schema'\n\t}\n\t& Migration\n\nexport type ContentMigration = {\n\ttype: 'content'\n\tversion: string\n\tname: string\n\tqueries: ContentMigrationQuery[]\n}\n\nexport type ContentMigrationFactoryArgs = {\n\tapiBaseUrl: string\n\tprojectName: string\n\tapiToken: string\n\tmigration: MigrationFile\n\tschemaVersionBuilder: SchemaVersionBuilder\n}\n\nexport type ContentMigrationFactory = {\n\ttype: 'factory'\n\tfactory: (args: ContentMigrationFactoryArgs) => Promise<ContentMigration>\n}\n\nexport type ContentMigrationQuery = {\n\tquery: string\n\tvariables?: JSONObject\n\tstage?: string\n\tcheckMutationResult?: boolean\n}\n"],"names":[],"mappings":"AAYO,MAAM,oBAAoB,CAAC,YACjC,OAAO,YAAY,cAAc,mBAAmB;"}
1
+ {"version":3,"file":"MigrationFile.js","sources":["../../../../packages/migrations-client/src/MigrationFile.ts"],"sourcesContent":["import { Migration } from '@contember/schema-migrations'\nimport { JSONObject } from './utils/json.js'\nimport { SchemaVersionBuilder } from './SchemaVersionBuilder.js'\n\nexport interface MigrationFile {\n\tpath: string\n\tversion: string\n\tname: string\n\n\tgetContent: () => Promise<MigrationContent>\n}\n\nexport const isSchemaMigration = (content: MigrationContent): content is SchemaMigration =>\n\ttypeof content !== 'function' && 'modifications' in content\n\nexport type ResolvedMigrationContent =\n\t| SchemaMigration\n\t| ContentMigration\n\nexport type MigrationContent =\n\t| ResolvedMigrationContent\n\t| ContentMigrationFactory\n\nexport type SchemaMigration =\n\t& {\n\t\ttype: 'schema'\n\t}\n\t& Migration\n\nexport type ContentMigration = {\n\ttype: 'content'\n\tversion: string\n\tname: string\n\tqueries: ContentMigrationQuery[]\n}\n\nexport type ContentMigrationFactoryArgs = {\n\tapiBaseUrl: string\n\tprojectName: string\n\tapiToken: string\n\tmigration: MigrationFile\n\tschemaVersionBuilder: SchemaVersionBuilder\n}\n\nexport type ContentMigrationFactory = {\n\ttype: 'factory'\n\tfactory: (args: ContentMigrationFactoryArgs) => Promise<ContentMigration>\n}\n\nexport type ContentMigrationQuery = {\n\tquery: string\n\tvariables?: JSONObject\n\tstage?: string\n\tcheckMutationResult?: boolean\n}\n"],"names":[],"mappings":"AAYO,MAAM,oBAAoB,CAAC,YACjC,OAAO,YAAY,cAAc,mBAAmB;"}
@@ -2,7 +2,7 @@
2
2
  Object.defineProperty(exports, Symbol.toStringTag, { value: "Module" });
3
3
  const engineCommon = require("@contember/engine-common");
4
4
  const fs = require("node:fs/promises");
5
- const node_path = require("node:path");
5
+ const path = require("node:path");
6
6
  function _interopNamespaceDefault(e) {
7
7
  const n = Object.create(null, { [Symbol.toStringTag]: { value: "Module" } });
8
8
  if (e) {
@@ -31,14 +31,14 @@ class MigrationFilesManager {
31
31
  }
32
32
  async createFile(content, name, extension = "json") {
33
33
  this.migrations = null;
34
- const path = this.formatPath(name, extension);
35
- await fs__namespace.writeFile(path, content, { encoding: "utf8" });
36
- return await fs__namespace.realpath(path);
34
+ const path2 = this.formatPath(name, extension);
35
+ await fs__namespace.writeFile(path2, content, { encoding: "utf8" });
36
+ return await fs__namespace.realpath(path2);
37
37
  }
38
38
  async removeFile(name) {
39
39
  this.migrations = null;
40
- const path = this.formatPath(name);
41
- await fs__namespace.unlink(path);
40
+ const path2 = this.formatPath(name);
41
+ await fs__namespace.unlink(path2);
42
42
  }
43
43
  async moveFile(oldName, newName) {
44
44
  this.migrations = null;
@@ -63,12 +63,12 @@ class MigrationFilesManager {
63
63
  }));
64
64
  return files.map(({ version, filename }) => {
65
65
  const ext = filename.substring(filename.lastIndexOf(".") + 1);
66
- const path = node_path.join(this.directory, filename);
66
+ const path$1 = path.join(this.directory, filename);
67
67
  let content = null;
68
68
  const file = {
69
- path,
69
+ path: path$1,
70
70
  version,
71
- name: engineCommon.MigrationVersionHelper.extractName(path.substring(path.lastIndexOf("/") + 1)),
71
+ name: engineCommon.MigrationVersionHelper.extractName(path$1.substring(path$1.lastIndexOf("/") + 1)),
72
72
  getContent: () => {
73
73
  content ?? (content = this.loaders[ext].load(file));
74
74
  return content;
@@ -98,8 +98,8 @@ class MigrationFilesManager {
98
98
  }
99
99
  formatPath(version, extension = "json") {
100
100
  const filename = `${version}.${extension}`;
101
- const path = `${this.directory}/${filename}`;
102
- return path;
101
+ const path2 = `${this.directory}/${filename}`;
102
+ return path2;
103
103
  }
104
104
  }
105
105
  exports.MigrationFilesManager = MigrationFilesManager;
@@ -1 +1 @@
1
- {"version":3,"file":"MigrationFilesManager.cjs","sources":["../../../../packages/migrations-client/src/MigrationFilesManager.ts"],"sourcesContent":["import { MigrationVersionHelper } from '@contember/engine-common'\nimport * as fs from 'node:fs/promises'\nimport { MigrationFileLoader } from './MigrationFileLoader'\nimport { MigrationContent, MigrationFile } from './MigrationFile'\nimport { join } from 'node:path'\nimport { Dirent } from 'node:fs'\n\nexport class MigrationFilesManager {\n\tprivate migrations: null | Promise<MigrationFile[]> = null\n\n\tconstructor(\n\t\tpublic readonly directory: string,\n\t\tprivate readonly loaders: Record<string, MigrationFileLoader>,\n\t) {}\n\n\tpublic async createFile(content: string, name: string, extension = 'json'): Promise<string> {\n\t\tthis.migrations = null\n\t\tconst path = this.formatPath(name, extension)\n\t\tawait fs.writeFile(path, content, { encoding: 'utf8' })\n\t\treturn await fs.realpath(path)\n\t}\n\n\tpublic async removeFile(name: string) {\n\t\tthis.migrations = null\n\t\tconst path = this.formatPath(name)\n\t\tawait fs.unlink(path)\n\t}\n\n\tpublic async moveFile(oldName: string, newName: string) {\n\t\tthis.migrations = null\n\t\tawait fs.rename(this.formatPath(oldName), this.formatPath(newName))\n\t}\n\n\tpublic async createDirIfNotExist(): Promise<void> {\n\t\ttry {\n\t\t\tawait fs.mkdir(this.directory)\n\t\t} catch (e) {\n\t\t\tif (!(e instanceof Error) || !('code' in e) || (e as any).code !== 'EEXIST') {\n\t\t\t\tthrow e\n\t\t\t}\n\t\t}\n\t}\n\n\tpublic async readFiles(): Promise<MigrationFile[]> {\n\t\treturn this.migrations ??= this.forceReadFiles()\n\t}\n\n\tpublic async forceReadFiles(): Promise<MigrationFile[]> {\n\t\tconst files = (await this.listFiles()).map(it => ({\n\t\t\tfilename: it,\n\t\t\tversion: MigrationVersionHelper.extractVersion(it),\n\t\t}))\n\n\t\treturn files.map(({ version, filename }): MigrationFile => {\n\t\t\tconst ext = filename.substring(filename.lastIndexOf('.') + 1)\n\t\t\tconst path = join(this.directory, filename)\n\t\t\tlet content: Promise<MigrationContent> | null = null\n\t\t\tconst file: MigrationFile = {\n\t\t\t\tpath: path,\n\t\t\t\tversion: version,\n\t\t\t\tname: MigrationVersionHelper.extractName(path.substring(path.lastIndexOf('/') + 1)),\n\t\t\t\tgetContent: () => {\n\t\t\t\t\tcontent ??= this.loaders[ext].load(file)\n\t\t\t\t\treturn content\n\t\t\t\t},\n\t\t\t}\n\t\t\treturn file\n\t\t})\n\t}\n\n\tprivate async tryReadDir(): Promise<Dirent[]> {\n\t\ttry {\n\t\t\treturn await fs.readdir(this.directory, { withFileTypes: true })\n\t\t} catch (e) {\n\t\t\tif (e instanceof Error && 'code' in e && (e as any).code === 'ENOENT') {\n\t\t\t\treturn []\n\t\t\t}\n\t\t\tthrow e\n\t\t}\n\t}\n\n\tprivate async listFiles(): Promise<string[]> {\n\t\tconst files = await this.tryReadDir()\n\n\t\tconst extensions = Object.keys(this.loaders).join('|')\n\t\tconst regex = new RegExp('^\\\\d{4}-\\\\d{2}-\\\\d{2}-\\\\d{6}-[\\\\w-]+\\\\.(' + extensions + ')$')\n\t\tconst filteredFiles = await Promise.all(\n\t\t\tfiles\n\t\t\t\t.filter(it => it.isFile())\n\t\t\t\t.map(it => it.name)\n\t\t\t\t.filter(it => it.match(regex)),\n\t\t)\n\n\t\treturn filteredFiles.sort()\n\t}\n\n\tprivate formatPath(version: string, extension = 'json'): string {\n\t\tconst filename = `${version}.${extension}`\n\t\tconst path = `${this.directory}/${filename}`\n\t\treturn path\n\t}\n}\n"],"names":["fs","MigrationVersionHelper","join"],"mappings":";;;;;;;;;;;;;;;;;;;;;;;;;AAOO,MAAM,sBAAsB;AAAA,EAGlC,YACiB,WACC,SAChB;AAFe,SAAA,YAAA;AACC,SAAA,UAAA;AAJlB,kBAAA,MAAQ,cAA8C,IAAA;AAAA,EAKnD;AAAA,EAEH,MAAa,WAAW,SAAiB,MAAc,YAAY,QAAyB;AAC3F,SAAK,aAAa;AAClB,UAAM,OAAO,KAAK,WAAW,MAAM,SAAS;AAC5C,UAAMA,cAAG,UAAU,MAAM,SAAS,EAAE,UAAU,QAAQ;AACtD,WAAO,MAAMA,cAAG,SAAS,IAAI;AAAA,EAC9B;AAAA,EAEA,MAAa,WAAW,MAAc;AACrC,SAAK,aAAa;AAClB,UAAM,OAAO,KAAK,WAAW,IAAI;AACjC,UAAMA,cAAG,OAAO,IAAI;AAAA,EACrB;AAAA,EAEA,MAAa,SAAS,SAAiB,SAAiB;AACvD,SAAK,aAAa;AAClB,UAAMA,cAAG,OAAO,KAAK,WAAW,OAAO,GAAG,KAAK,WAAW,OAAO,CAAC;AAAA,EACnE;AAAA,EAEA,MAAa,sBAAqC;AACjD,QAAI;AACH,YAAMA,cAAG,MAAM,KAAK,SAAS;AAAA,IAC9B,SAAS,GAAG;AACX,UAAI,EAAE,aAAa,UAAU,EAAE,UAAU,MAAO,EAAU,SAAS,UAAU;AAC5E,cAAM;AAAA,MACP;AAAA,IACD;AAAA,EACD;AAAA,EAEA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,IAAI,EACjB,OAAO,QAAM,GAAG,MAAM,KAAK,CAAC;AAAA,IAAA;AAG/B,WAAO,cAAc,KAAA;AAAA,EACtB;AAAA,EAEQ,WAAW,SAAiB,YAAY,QAAgB;AAC/D,UAAM,WAAW,GAAG,OAAO,IAAI,SAAS;AACxC,UAAM,OAAO,GAAG,KAAK,SAAS,IAAI,QAAQ;AAC1C,WAAO;AAAA,EACR;AACD;;"}
1
+ {"version":3,"file":"MigrationFilesManager.cjs","sources":["../../../../packages/migrations-client/src/MigrationFilesManager.ts"],"sourcesContent":["import { MigrationVersionHelper } from '@contember/engine-common'\nimport * as fs from 'node:fs/promises'\nimport { MigrationFileLoader } from './MigrationFileLoader.js'\nimport { MigrationContent, MigrationFile } from './MigrationFile.js'\nimport { join } from 'node:path'\nimport { Dirent } from 'node:fs'\n\nexport class MigrationFilesManager {\n\tprivate migrations: null | Promise<MigrationFile[]> = null\n\n\tconstructor(\n\t\tpublic readonly directory: string,\n\t\tprivate readonly loaders: Record<string, MigrationFileLoader>,\n\t) {}\n\n\tpublic async createFile(content: string, name: string, extension = 'json'): Promise<string> {\n\t\tthis.migrations = null\n\t\tconst path = this.formatPath(name, extension)\n\t\tawait fs.writeFile(path, content, { encoding: 'utf8' })\n\t\treturn await fs.realpath(path)\n\t}\n\n\tpublic async removeFile(name: string) {\n\t\tthis.migrations = null\n\t\tconst path = this.formatPath(name)\n\t\tawait fs.unlink(path)\n\t}\n\n\tpublic async moveFile(oldName: string, newName: string) {\n\t\tthis.migrations = null\n\t\tawait fs.rename(this.formatPath(oldName), this.formatPath(newName))\n\t}\n\n\tpublic async createDirIfNotExist(): Promise<void> {\n\t\ttry {\n\t\t\tawait fs.mkdir(this.directory)\n\t\t} catch (e) {\n\t\t\tif (!(e instanceof Error) || !('code' in e) || (e as any).code !== 'EEXIST') {\n\t\t\t\tthrow e\n\t\t\t}\n\t\t}\n\t}\n\n\tpublic async readFiles(): Promise<MigrationFile[]> {\n\t\treturn this.migrations ??= this.forceReadFiles()\n\t}\n\n\tpublic async forceReadFiles(): Promise<MigrationFile[]> {\n\t\tconst files = (await this.listFiles()).map(it => ({\n\t\t\tfilename: it,\n\t\t\tversion: MigrationVersionHelper.extractVersion(it),\n\t\t}))\n\n\t\treturn files.map(({ version, filename }): MigrationFile => {\n\t\t\tconst ext = filename.substring(filename.lastIndexOf('.') + 1)\n\t\t\tconst path = join(this.directory, filename)\n\t\t\tlet content: Promise<MigrationContent> | null = null\n\t\t\tconst file: MigrationFile = {\n\t\t\t\tpath: path,\n\t\t\t\tversion: version,\n\t\t\t\tname: MigrationVersionHelper.extractName(path.substring(path.lastIndexOf('/') + 1)),\n\t\t\t\tgetContent: () => {\n\t\t\t\t\tcontent ??= this.loaders[ext].load(file)\n\t\t\t\t\treturn content\n\t\t\t\t},\n\t\t\t}\n\t\t\treturn file\n\t\t})\n\t}\n\n\tprivate async tryReadDir(): Promise<Dirent[]> {\n\t\ttry {\n\t\t\treturn await fs.readdir(this.directory, { withFileTypes: true })\n\t\t} catch (e) {\n\t\t\tif (e instanceof Error && 'code' in e && (e as any).code === 'ENOENT') {\n\t\t\t\treturn []\n\t\t\t}\n\t\t\tthrow e\n\t\t}\n\t}\n\n\tprivate async listFiles(): Promise<string[]> {\n\t\tconst files = await this.tryReadDir()\n\n\t\tconst extensions = Object.keys(this.loaders).join('|')\n\t\tconst regex = new RegExp('^\\\\d{4}-\\\\d{2}-\\\\d{2}-\\\\d{6}-[\\\\w-]+\\\\.(' + extensions + ')$')\n\t\tconst filteredFiles = await Promise.all(\n\t\t\tfiles\n\t\t\t\t.filter(it => it.isFile())\n\t\t\t\t.map(it => it.name)\n\t\t\t\t.filter(it => it.match(regex)),\n\t\t)\n\n\t\treturn filteredFiles.sort()\n\t}\n\n\tprivate formatPath(version: string, extension = 'json'): string {\n\t\tconst filename = `${version}.${extension}`\n\t\tconst path = `${this.directory}/${filename}`\n\t\treturn path\n\t}\n}\n"],"names":["path","fs","MigrationVersionHelper","join"],"mappings":";;;;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ts"],"sourcesContent":["import { MigrationVersionHelper } from '@contember/engine-common'\nimport * as fs from 'node:fs/promises'\nimport { MigrationFileLoader } from './MigrationFileLoader'\nimport { MigrationContent, MigrationFile } from './MigrationFile'\nimport { join } from 'node:path'\nimport { Dirent } from 'node:fs'\n\nexport class MigrationFilesManager {\n\tprivate migrations: null | Promise<MigrationFile[]> = null\n\n\tconstructor(\n\t\tpublic readonly directory: string,\n\t\tprivate readonly loaders: Record<string, MigrationFileLoader>,\n\t) {}\n\n\tpublic async createFile(content: string, name: string, extension = 'json'): Promise<string> {\n\t\tthis.migrations = null\n\t\tconst path = this.formatPath(name, extension)\n\t\tawait fs.writeFile(path, content, { encoding: 'utf8' })\n\t\treturn await fs.realpath(path)\n\t}\n\n\tpublic async removeFile(name: string) {\n\t\tthis.migrations = null\n\t\tconst path = this.formatPath(name)\n\t\tawait fs.unlink(path)\n\t}\n\n\tpublic async moveFile(oldName: string, newName: string) {\n\t\tthis.migrations = null\n\t\tawait fs.rename(this.formatPath(oldName), this.formatPath(newName))\n\t}\n\n\tpublic async createDirIfNotExist(): Promise<void> {\n\t\ttry {\n\t\t\tawait fs.mkdir(this.directory)\n\t\t} catch (e) {\n\t\t\tif (!(e instanceof Error) || !('code' in e) || (e as any).code !== 'EEXIST') {\n\t\t\t\tthrow e\n\t\t\t}\n\t\t}\n\t}\n\n\tpublic async readFiles(): Promise<MigrationFile[]> {\n\t\treturn this.migrations ??= this.forceReadFiles()\n\t}\n\n\tpublic async forceReadFiles(): Promise<MigrationFile[]> {\n\t\tconst files = (await this.listFiles()).map(it => ({\n\t\t\tfilename: it,\n\t\t\tversion: MigrationVersionHelper.extractVersion(it),\n\t\t}))\n\n\t\treturn files.map(({ version, filename }): MigrationFile => {\n\t\t\tconst ext = filename.substring(filename.lastIndexOf('.') + 1)\n\t\t\tconst path = join(this.directory, filename)\n\t\t\tlet content: Promise<MigrationContent> | null = null\n\t\t\tconst file: MigrationFile = {\n\t\t\t\tpath: path,\n\t\t\t\tversion: version,\n\t\t\t\tname: MigrationVersionHelper.extractName(path.substring(path.lastIndexOf('/') + 1)),\n\t\t\t\tgetContent: () => {\n\t\t\t\t\tcontent ??= this.loaders[ext].load(file)\n\t\t\t\t\treturn content\n\t\t\t\t},\n\t\t\t}\n\t\t\treturn file\n\t\t})\n\t}\n\n\tprivate async tryReadDir(): Promise<Dirent[]> {\n\t\ttry {\n\t\t\treturn await fs.readdir(this.directory, { withFileTypes: true })\n\t\t} catch (e) {\n\t\t\tif (e instanceof Error && 'code' in e && (e as any).code === 'ENOENT') {\n\t\t\t\treturn []\n\t\t\t}\n\t\t\tthrow e\n\t\t}\n\t}\n\n\tprivate async listFiles(): Promise<string[]> {\n\t\tconst files = await this.tryReadDir()\n\n\t\tconst extensions = Object.keys(this.loaders).join('|')\n\t\tconst regex = new RegExp('^\\\\d{4}-\\\\d{2}-\\\\d{2}-\\\\d{6}-[\\\\w-]+\\\\.(' + extensions + ')$')\n\t\tconst filteredFiles = await Promise.all(\n\t\t\tfiles\n\t\t\t\t.filter(it => it.isFile())\n\t\t\t\t.map(it => it.name)\n\t\t\t\t.filter(it => it.match(regex)),\n\t\t)\n\n\t\treturn filteredFiles.sort()\n\t}\n\n\tprivate formatPath(version: string, extension = 'json'): string {\n\t\tconst filename = `${version}.${extension}`\n\t\tconst path = `${this.directory}/${filename}`\n\t\treturn path\n\t}\n}\n"],"names":[],"mappings":";;;;;;AAOO,MAAM,sBAAsB;AAAA,EAGlC,YACiB,WACC,SAChB;AAFe,SAAA,YAAA;AACC,SAAA,UAAA;AAJlB,kBAAA,MAAQ,cAA8C,IAAA;AAAA,EAKnD;AAAA,EAEH,MAAa,WAAW,SAAiB,MAAc,YAAY,QAAyB;AAC3F,SAAK,aAAa;AAClB,UAAM,OAAO,KAAK,WAAW,MAAM,SAAS;AAC5C,UAAM,GAAG,UAAU,MAAM,SAAS,EAAE,UAAU,QAAQ;AACtD,WAAO,MAAM,GAAG,SAAS,IAAI;AAAA,EAC9B;AAAA,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WAAW,EAAE,eAAe,MAAM;AAAA,IAChE,SAAS,GAAG;AACX,UAAI,aAAa,SAAS,UAAU,KAAM,EAAU,SAAS,UAAU;AACtE,eAAO,CAAA;AAAA,MACR;AACA,YAAM;AAAA,IACP;AAAA,EACD;AAAA,EAEA,MAAc,YAA+B;AAC5C,UAAM,QAAQ,MAAM,KAAK,WAAA;AAEzB,UAAM,aAAa,OAAO,KAAK,KAAK,OAAO,EAAE,KAAK,GAAG;AACrD,UAAM,QAAQ,IAAI,OAAO,6CAA6C,aAAa,IAAI;AACvF,UAAM,gBAAgB,MAAM,QAAQ;AAAA,MACnC,MACE,OAAO,CAAA,OAAM,GAAG,OAAA,CAAQ,EACxB,IAAI,CAAA,OAAM,GAAG,IAAI,EACjB,OAAO,QAAM,GAAG,MAAM,KAAK,CAAC;AAAA,IAAA;AAG/B,WAAO,cAAc,KAAA;AAAA,EACtB;AAAA,EAEQ,WAAW,SAAiB,YAAY,QAAgB;AAC/D,UAAM,WAAW,GAAG,OAAO,IAAI,SAAS;AACxC,UAAM,OAAO,GAAG,KAAK,SAAS,IAAI,QAAQ;AAC1C,WAAO;AAAA,EACR;AACD;"}
1
+ {"version":3,"file":"MigrationFilesManager.js","sources":["../../../../packages/migrations-client/src/MigrationFilesManager.ts"],"sourcesContent":["import { MigrationVersionHelper } from '@contember/engine-common'\nimport * as fs from 'node:fs/promises'\nimport { MigrationFileLoader } from './MigrationFileLoader.js'\nimport { MigrationContent, MigrationFile } from './MigrationFile.js'\nimport { join } from 'node:path'\nimport { Dirent } from 'node:fs'\n\nexport class MigrationFilesManager {\n\tprivate migrations: null | Promise<MigrationFile[]> = null\n\n\tconstructor(\n\t\tpublic readonly directory: string,\n\t\tprivate readonly loaders: Record<string, MigrationFileLoader>,\n\t) {}\n\n\tpublic async createFile(content: string, name: string, extension = 'json'): Promise<string> {\n\t\tthis.migrations = null\n\t\tconst path = this.formatPath(name, extension)\n\t\tawait fs.writeFile(path, content, { encoding: 'utf8' })\n\t\treturn await fs.realpath(path)\n\t}\n\n\tpublic async removeFile(name: string) {\n\t\tthis.migrations = null\n\t\tconst path = this.formatPath(name)\n\t\tawait fs.unlink(path)\n\t}\n\n\tpublic async moveFile(oldName: string, newName: string) {\n\t\tthis.migrations = null\n\t\tawait fs.rename(this.formatPath(oldName), this.formatPath(newName))\n\t}\n\n\tpublic async createDirIfNotExist(): Promise<void> {\n\t\ttry {\n\t\t\tawait fs.mkdir(this.directory)\n\t\t} catch (e) {\n\t\t\tif (!(e instanceof Error) || !('code' in e) || (e as any).code !== 'EEXIST') {\n\t\t\t\tthrow e\n\t\t\t}\n\t\t}\n\t}\n\n\tpublic async readFiles(): Promise<MigrationFile[]> {\n\t\treturn this.migrations ??= this.forceReadFiles()\n\t}\n\n\tpublic async forceReadFiles(): Promise<MigrationFile[]> {\n\t\tconst files = (await this.listFiles()).map(it => ({\n\t\t\tfilename: it,\n\t\t\tversion: MigrationVersionHelper.extractVersion(it),\n\t\t}))\n\n\t\treturn files.map(({ version, filename }): MigrationFile => {\n\t\t\tconst ext = filename.substring(filename.lastIndexOf('.') + 1)\n\t\t\tconst path = join(this.directory, filename)\n\t\t\tlet content: Promise<MigrationContent> | null = null\n\t\t\tconst file: MigrationFile = {\n\t\t\t\tpath: path,\n\t\t\t\tversion: version,\n\t\t\t\tname: MigrationVersionHelper.extractName(path.substring(path.lastIndexOf('/') + 1)),\n\t\t\t\tgetContent: () => {\n\t\t\t\t\tcontent ??= this.loaders[ext].load(file)\n\t\t\t\t\treturn content\n\t\t\t\t},\n\t\t\t}\n\t\t\treturn file\n\t\t})\n\t}\n\n\tprivate async tryReadDir(): Promise<Dirent[]> {\n\t\ttry {\n\t\t\treturn await fs.readdir(this.directory, { withFileTypes: true })\n\t\t} catch (e) {\n\t\t\tif (e instanceof Error && 'code' in e && (e as any).code === 'ENOENT') {\n\t\t\t\treturn []\n\t\t\t}\n\t\t\tthrow e\n\t\t}\n\t}\n\n\tprivate async listFiles(): Promise<string[]> {\n\t\tconst files = await this.tryReadDir()\n\n\t\tconst extensions = Object.keys(this.loaders).join('|')\n\t\tconst regex = new RegExp('^\\\\d{4}-\\\\d{2}-\\\\d{2}-\\\\d{6}-[\\\\w-]+\\\\.(' + extensions + ')$')\n\t\tconst filteredFiles = await Promise.all(\n\t\t\tfiles\n\t\t\t\t.filter(it => it.isFile())\n\t\t\t\t.map(it => it.name)\n\t\t\t\t.filter(it => it.match(regex)),\n\t\t)\n\n\t\treturn filteredFiles.sort()\n\t}\n\n\tprivate formatPath(version: string, extension = 'json'): string {\n\t\tconst filename = `${version}.${extension}`\n\t\tconst path = `${this.directory}/${filename}`\n\t\treturn path\n\t}\n}\n"],"names":[],"mappings":";;;;;;AAOO,MAAM,sBAAsB;AAAA,EAGlC,YACiB,WACC,SAChB;AAFe,SAAA,YAAA;AACC,SAAA,UAAA;AAJlB,kBAAA,MAAQ,cAA8C,IAAA;AAAA,EAKnD;AAAA,EAEH,MAAa,WAAW,SAAiB,MAAc,YAAY,QAAyB;AAC3F,SAAK,aAAa;AAClB,UAAM,OAAO,KAAK,WAAW,MAAM,SAAS;AAC5C,UAAM,GAAG,UAAU,MAAM,SAAS,EAAE,UAAU,QAAQ;AACtD,WAAO,MAAM,GAAG,SAAS,IAAI;AAAA,EAC9B;AAAA,EAEA,MAAa,WAAW,MAAc;AACrC,SAAK,aAAa;AAClB,UAAM,OAAO,KAAK,WAAW,IAAI;AACjC,UAAM,GAAG,OAAO,IAAI;AAAA,EACrB;AAAA,EAEA,MAAa,SAAS,SAAiB,SAAiB;AACvD,SAAK,aAAa;AAClB,UAAM,GAAG,OAAO,KAAK,WAAW,OAAO,GAAG,KAAK,WAAW,OAAO,CAAC;AAAA,EACnE;AAAA,EAEA,MAAa,sBAAqC;AACjD,QAAI;AACH,YAAM,GAAG,MAAM,KAAK,SAAS;AAAA,IAC9B,SAAS,GAAG;AACX,UAAI,EAAE,aAAa,UAAU,EAAE,UAAU,MAAO,EAAU,SAAS,UAAU;AAC5E,cAAM;AAA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AA,OAAM,GAAG,IAAI,EACjB,OAAO,QAAM,GAAG,MAAM,KAAK,CAAC;AAAA,IAAA;AAG/B,WAAO,cAAc,KAAA;AAAA,EACtB;AAAA,EAEQ,WAAW,SAAiB,YAAY,QAAgB;AAC/D,UAAM,WAAW,GAAG,OAAO,IAAI,SAAS;AACxC,UAAM,OAAO,GAAG,KAAK,SAAS,IAAI,QAAQ;AAC1C,WAAO;AAAA,EACR;AACD;"}
@@ -1 +1 @@
1
- {"version":3,"file":"MigrationParser.cjs","sources":["../../../../packages/migrations-client/src/MigrationParser.ts"],"sourcesContent":["import { Migration, VERSION_INITIAL } from '@contember/schema-migrations'\nimport { ContentMigrationQuery, MigrationFile, ResolvedMigrationContent } from './MigrationFile'\nimport { JSONValue } from './utils/json'\n\nexport class MigrationParser {\n\tpublic parse(migrationFile: MigrationFile, content: JSONValue): ResolvedMigrationContent {\n\t\tif (typeof content !== 'object' || content === null) {\n\t\t\tthrow new Error('Invalid migration')\n\t\t}\n\n\t\tif ('modifications' in content) {\n\t\t\tconst validated = content as Migration // todo validate\n\n\t\t\treturn {\n\t\t\t\ttype: 'schema',\n\t\t\t\tversion: migrationFile.version,\n\t\t\t\tname: migrationFile.name,\n\t\t\t\tformatVersion: validated.formatVersion || VERSION_INITIAL,\n\t\t\t\tmodifications: validated.modifications,\n\t\t\t\t...(validated.skippedErrors ? { skippedErrors: validated.skippedErrors } : {}),\n\t\t\t}\n\t\t} else if ('queries' in content || 'query' in content) {\n\t\t\treturn {\n\t\t\t\ttype: 'content',\n\t\t\t\tversion: migrationFile.version,\n\t\t\t\tname: migrationFile.name,\n\t\t\t\tqueries: ('queries' in content ? content.queries : [content]) as ContentMigrationQuery[],\n\t\t\t}\n\t\t}\n\t\tthrow new Error('Invalid migration content')\n\t}\n}\n"],"names":["VERSION_INITIAL"],"mappings":";;;AAIO,MAAM,gBAAgB;AAAA,EACrB,MAAM,eAA8B,SAA8C;AACxF,QAAI,OAAO,YAAY,YAAY,YAAY,MAAM;AACpD,YAAM,IAAI,MAAM,mBAAmB;AAAA,IACpC;AAEA,QAAI,mBAAmB,SAAS;AAC/B,YAAM,YAAY;AAElB,aAAO;AAAA,QACN,MAAM;AAAA,QACN,SAAS,cAAc;AAAA,QACvB,MAAM,cAAc;AAAA,QACpB,eAAe,UAAU,iBAAiBA,iBAAAA;AAAAA,QAC1C,eAAe,UAAU;AAAA,QACzB,GAAI,UAAU,gBAAgB,EAAE,eAAe,UAAU,cAAA,IAAkB,CAAA;AAAA,MAAC;AAAA,IAE9E,WAAW,aAAa,WAAW,WAAW,SAAS;AACtD,aAAO;AAAA,QACN,MAAM;AAAA,QACN,SAAS,cAAc;AAAA,QACvB,MAAM,cAAc;AAAA,QACpB,SAAU,aAAa,UAAU,QAAQ,UAAU,CAAC,OAAO;AAAA,MAAA;AAAA,IAE7D;AACA,UAAM,IAAI,MAAM,2BAA2B;AAAA,EAC5C;AACD;;"}
1
+ {"version":3,"file":"MigrationParser.cjs","sources":["../../../../packages/migrations-client/src/MigrationParser.ts"],"sourcesContent":["import { Migration, VERSION_INITIAL } from '@contember/schema-migrations'\nimport { ContentMigrationQuery, MigrationFile, ResolvedMigrationContent } from './MigrationFile.js'\nimport { JSONValue } from './utils/json.js'\n\nexport class MigrationParser {\n\tpublic parse(migrationFile: MigrationFile, content: JSONValue): ResolvedMigrationContent {\n\t\tif (typeof content !== 'object' || content === null) {\n\t\t\tthrow new Error('Invalid migration')\n\t\t}\n\n\t\tif ('modifications' in content) {\n\t\t\tconst validated = content as Migration // todo validate\n\n\t\t\treturn {\n\t\t\t\ttype: 'schema',\n\t\t\t\tversion: migrationFile.version,\n\t\t\t\tname: migrationFile.name,\n\t\t\t\tformatVersion: validated.formatVersion || VERSION_INITIAL,\n\t\t\t\tmodifications: validated.modifications,\n\t\t\t\t...(validated.skippedErrors ? { skippedErrors: validated.skippedErrors } : {}),\n\t\t\t}\n\t\t} else if ('queries' in content || 'query' in content) {\n\t\t\treturn {\n\t\t\t\ttype: 'content',\n\t\t\t\tversion: migrationFile.version,\n\t\t\t\tname: migrationFile.name,\n\t\t\t\tqueries: ('queries' in content ? content.queries : [content]) as ContentMigrationQuery[],\n\t\t\t}\n\t\t}\n\t\tthrow new Error('Invalid migration content')\n\t}\n}\n"],"names":["VERSION_INITIAL"],"mappings":";;;AAIO,MAAM,gBAAgB;AAAA,EACrB,MAAM,eAA8B,SAA8C;AACxF,QAAI,OAAO,YAAY,YAAY,YAAY,MAAM;AACpD,YAAM,IAAI,MAAM,mBAAmB;AAAA,IACpC;AAEA,QAAI,mBAAmB,SAAS;AAC/B,YAAM,YAAY;AAElB,aAAO;AAAA,QACN,MAAM;AAAA,QACN,SAAS,cAAc;AAAA,QACvB,MAAM,cAAc;AAAA,QACpB,eAAe,UAAU,iBAAiBA,iBAAAA;AAAAA,QAC1C,eAAe,UAAU;AAAA,QACzB,GAAI,UAAU,gBAAgB,EAAE,eAAe,UAAU,cAAA,IAAkB,CAAA;AAAA,MAAC;AAAA,IAE9E,WAAW,aAAa,WAAW,WAAW,SAAS;AACtD,aAAO;AAAA,QACN,MAAM;AAAA,QACN,SAAS,cAAc;AAAA,QACvB,MAAM,cAAc;AAAA,QACpB,SAAU,aAAa,UAAU,QAAQ,UAAU,CAAC,OAAO;AAAA,MAAA;AAAA,IAE7D;AACA,UAAM,IAAI,MAAM,2BAA2B;AAAA,EAC5C;AACD;;"}
@@ -1 +1 @@
1
- {"version":3,"file":"MigrationParser.js","sources":["../../../../packages/migrations-client/src/MigrationParser.ts"],"sourcesContent":["import { Migration, VERSION_INITIAL } from '@contember/schema-migrations'\nimport { ContentMigrationQuery, MigrationFile, ResolvedMigrationContent } from './MigrationFile'\nimport { JSONValue } from './utils/json'\n\nexport class MigrationParser {\n\tpublic parse(migrationFile: MigrationFile, content: JSONValue): ResolvedMigrationContent {\n\t\tif (typeof content !== 'object' || content === null) {\n\t\t\tthrow new Error('Invalid migration')\n\t\t}\n\n\t\tif ('modifications' in content) {\n\t\t\tconst validated = content as Migration // todo validate\n\n\t\t\treturn {\n\t\t\t\ttype: 'schema',\n\t\t\t\tversion: migrationFile.version,\n\t\t\t\tname: migrationFile.name,\n\t\t\t\tformatVersion: validated.formatVersion || VERSION_INITIAL,\n\t\t\t\tmodifications: validated.modifications,\n\t\t\t\t...(validated.skippedErrors ? { skippedErrors: validated.skippedErrors } : {}),\n\t\t\t}\n\t\t} else if ('queries' in content || 'query' in content) {\n\t\t\treturn {\n\t\t\t\ttype: 'content',\n\t\t\t\tversion: migrationFile.version,\n\t\t\t\tname: migrationFile.name,\n\t\t\t\tqueries: ('queries' in content ? content.queries : [content]) as ContentMigrationQuery[],\n\t\t\t}\n\t\t}\n\t\tthrow new Error('Invalid migration content')\n\t}\n}\n"],"names":[],"mappings":";AAIO,MAAM,gBAAgB;AAAA,EACrB,MAAM,eAA8B,SAA8C;AACxF,QAAI,OAAO,YAAY,YAAY,YAAY,MAAM;AACpD,YAAM,IAAI,MAAM,mBAAmB;AAAA,IACpC;AAEA,QAAI,mBAAmB,SAAS;AAC/B,YAAM,YAAY;AAElB,aAAO;AAAA,QACN,MAAM;AAAA,QACN,SAAS,cAAc;AAAA,QACvB,MAAM,cAAc;AAAA,QACpB,eAAe,UAAU,iBAAiB;AAAA,QAC1C,eAAe,UAAU;AAAA,QACzB,GAAI,UAAU,gBAAgB,EAAE,eAAe,UAAU,cAAA,IAAkB,CAAA;AAAA,MAAC;AAAA,IAE9E,WAAW,aAAa,WAAW,WAAW,SAAS;AACtD,aAAO;AAAA,QACN,MAAM;AAAA,QACN,SAAS,cAAc;AAAA,QACvB,MAAM,cAAc;AAAA,QACpB,SAAU,aAAa,UAAU,QAAQ,UAAU,CAAC,OAAO;AAAA,MAAA;AAAA,IAE7D;AACA,UAAM,IAAI,MAAM,2BAA2B;AAAA,EAC5C;AACD;"}
1
+ {"version":3,"file":"MigrationParser.js","sources":["../../../../packages/migrations-client/src/MigrationParser.ts"],"sourcesContent":["import { Migration, VERSION_INITIAL } from '@contember/schema-migrations'\nimport { ContentMigrationQuery, MigrationFile, ResolvedMigrationContent } from './MigrationFile.js'\nimport { JSONValue } from './utils/json.js'\n\nexport class MigrationParser {\n\tpublic parse(migrationFile: MigrationFile, content: JSONValue): ResolvedMigrationContent {\n\t\tif (typeof content !== 'object' || content === null) {\n\t\t\tthrow new Error('Invalid migration')\n\t\t}\n\n\t\tif ('modifications' in content) {\n\t\t\tconst validated = content as Migration // todo validate\n\n\t\t\treturn {\n\t\t\t\ttype: 'schema',\n\t\t\t\tversion: migrationFile.version,\n\t\t\t\tname: migrationFile.name,\n\t\t\t\tformatVersion: validated.formatVersion || VERSION_INITIAL,\n\t\t\t\tmodifications: validated.modifications,\n\t\t\t\t...(validated.skippedErrors ? { skippedErrors: validated.skippedErrors } : {}),\n\t\t\t}\n\t\t} else if ('queries' in content || 'query' in content) {\n\t\t\treturn {\n\t\t\t\ttype: 'content',\n\t\t\t\tversion: migrationFile.version,\n\t\t\t\tname: migrationFile.name,\n\t\t\t\tqueries: ('queries' in content ? content.queries : [content]) as ContentMigrationQuery[],\n\t\t\t}\n\t\t}\n\t\tthrow new Error('Invalid migration content')\n\t}\n}\n"],"names":[],"mappings":";AAIO,MAAM,gBAAgB;AAAA,EACrB,MAAM,eAA8B,SAA8C;AACxF,QAAI,OAAO,YAAY,YAAY,YAAY,MAAM;AACpD,YAAM,IAAI,MAAM,mBAAmB;AAAA,IACpC;AAEA,QAAI,mBAAmB,SAAS;AAC/B,YAAM,YAAY;AAElB,aAAO;AAAA,QACN,MAAM;AAAA,QACN,SAAS,cAAc;AAAA,QACvB,MAAM,cAAc;AAAA,QACpB,eAAe,UAAU,iBAAiB;AAAA,QAC1C,eAAe,UAAU;AAAA,QACzB,GAAI,UAAU,gBAAgB,EAAE,eAAe,UAAU,cAAA,IAAkB,CAAA;AAAA,MAAC;AAAA,IAE9E,WAAW,aAAa,WAAW,WAAW,SAAS;AACtD,aAAO;AAAA,QACN,MAAM;AAAA,QACN,SAAS,cAAc;AAAA,QACvB,MAAM,cAAc;AAAA,QACpB,SAAU,aAAa,UAAU,QAAQ,UAAU,CAAC,OAAO;AAAA,MAAA;AAAA,IAE7D;AACA,UAAM,IAAI,MAAM,2BAA2B;AAAA,EAC5C;AACD;"}
@@ -1 +1 @@
1
- {"version":3,"file":"MigrationsResolver.cjs","sources":["../../../../packages/migrations-client/src/MigrationsResolver.ts"],"sourcesContent":["import { MigrationFilesManager } from './MigrationFilesManager'\nimport { Migration } from '@contember/schema-migrations'\nimport { isSchemaMigration, MigrationFile } from './MigrationFile'\nimport { MigrationVersionHelper } from '@contember/engine-common'\n\nexport class MigrationsResolver {\n\tconstructor(private readonly migrationFilesManager: MigrationFilesManager) {}\n\n\tpublic get directory(): string {\n\t\treturn this.migrationFilesManager.directory\n\t}\n\n\tpublic async getMigrationFiles(): Promise<MigrationFile[]> {\n\t\treturn await this.migrationFilesManager.readFiles()\n\t}\n\n\tpublic async getSchemaMigrations(): Promise<Migration[]> {\n\t\tconst migrationFiles = await this.getMigrationFiles()\n\n\t\tconst migrations = await Promise.all(migrationFiles.map(this.convertMigrationFileToSchemaMigration))\n\n\t\treturn migrations.filter((it): it is Migration => it !== null)\n\t}\n\n\tpublic async findLatestSchemaMigration(): Promise<Migration | null> {\n\t\tconst migrations = await this.getSchemaMigrations()\n\t\treturn migrations.length > 0 ? migrations[migrations.length - 1] : null\n\t}\n\n\tpublic async findSchemaMigrationByVersion(version: string): Promise<Migration | null> {\n\t\tconst migrations = await this.getSchemaMigrations()\n\t\treturn migrations\n\t\t\t.find(it => MigrationVersionHelper.extractVersion(it.version) === MigrationVersionHelper.extractVersion(version))\n\t\t\t?? null\n\t}\n\n\tprivate async convertMigrationFileToSchemaMigration(file: MigrationFile): Promise<Migration | null> {\n\t\tconst result = await file.getContent()\n\t\treturn isSchemaMigration(result) ? result : null\n\t}\n}\n"],"names":["MigrationVersionHelper","isSchemaMigration"],"mappings":";;;;AAKO,MAAM,mBAAmB;AAAA,EAC/B,YAA6B,uBAA8C;AAA9C,SAAA,wBAAA;AAAA,EAA+C;AAAA,EAE5E,IAAW,YAAoB;AAC9B,WAAO,KAAK,sBAAsB;AAAA,EACnC;AAAA,EAEA,MAAa,oBAA8C;AAC1D,WAAO,MAAM,KAAK,sBAAsB,UAAA;AAAA,EACzC;AAAA,EAEA,MAAa,sBAA4C;AACxD,UAAM,iBAAiB,MAAM,KAAK,kBAAA;AAElC,UAAM,aAAa,MAAM,QAAQ,IAAI,eAAe,IAAI,KAAK,qCAAqC,CAAC;AAEnG,WAAO,WAAW,OAAO,CAAC,OAAwB,OAAO,IAAI;AAAA,EAC9D;AAAA,EAEA,MAAa,4BAAuD;AACnE,UAAM,aAAa,MAAM,KAAK,oBAAA;AAC9B,WAAO,WAAW,SAAS,IAAI,WAAW,WAAW,SAAS,CAAC,IAAI;AAAA,EACpE;AAAA,EAEA,MAAa,6BAA6B,SAA4C;AACrF,UAAM,aAAa,MAAM,KAAK,oBAAA;AAC9B,WAAO,WACL,KAAK,CAAA,OAAMA,aAAAA,uBAAuB,eAAe,GAAG,OAAO,MAAMA,aAAAA,uBAAuB,eAAe,OAAO,CAAC,KAC7G;AAAA,EACL;AAAA,EAEA,MAAc,sCAAsC,MAAgD;AACnG,UAAM,SAAS,MAAM,KAAK,WAAA;AAC1B,WAAOC,gCAAkB,MAAM,IAAI,SAAS;AAAA,EAC7C;AACD;;"}
1
+ {"version":3,"file":"MigrationsResolver.cjs","sources":["../../../../packages/migrations-client/src/MigrationsResolver.ts"],"sourcesContent":["import { MigrationFilesManager } from './MigrationFilesManager.js'\nimport { Migration } from '@contember/schema-migrations'\nimport { isSchemaMigration, MigrationFile } from './MigrationFile.js'\nimport { MigrationVersionHelper } from '@contember/engine-common'\n\nexport class MigrationsResolver {\n\tconstructor(private readonly migrationFilesManager: MigrationFilesManager) {}\n\n\tpublic get directory(): string {\n\t\treturn this.migrationFilesManager.directory\n\t}\n\n\tpublic async getMigrationFiles(): Promise<MigrationFile[]> {\n\t\treturn await this.migrationFilesManager.readFiles()\n\t}\n\n\tpublic async getSchemaMigrations(): Promise<Migration[]> {\n\t\tconst migrationFiles = await this.getMigrationFiles()\n\n\t\tconst migrations = await Promise.all(migrationFiles.map(this.convertMigrationFileToSchemaMigration))\n\n\t\treturn migrations.filter((it): it is Migration => it !== null)\n\t}\n\n\tpublic async findLatestSchemaMigration(): Promise<Migration | null> {\n\t\tconst migrations = await this.getSchemaMigrations()\n\t\treturn migrations.length > 0 ? migrations[migrations.length - 1] : null\n\t}\n\n\tpublic async findSchemaMigrationByVersion(version: string): Promise<Migration | null> {\n\t\tconst migrations = await this.getSchemaMigrations()\n\t\treturn migrations\n\t\t\t.find(it => MigrationVersionHelper.extractVersion(it.version) === MigrationVersionHelper.extractVersion(version))\n\t\t\t?? null\n\t}\n\n\tprivate async convertMigrationFileToSchemaMigration(file: MigrationFile): Promise<Migration | null> {\n\t\tconst result = await file.getContent()\n\t\treturn isSchemaMigration(result) ? result : null\n\t}\n}\n"],"names":["MigrationVersionHelper","isSchemaMigration"],"mappings":";;;;AAKO,MAAM,mBAAmB;AAAA,EAC/B,YAA6B,uBAA8C;AAA9C,SAAA,wBAAA;AAAA,EAA+C;AAAA,EAE5E,IAAW,YAAoB;AAC9B,WAAO,KAAK,sBAAsB;AAAA,EACnC;AAAA,EAEA,MAAa,oBAA8C;AAC1D,WAAO,MAAM,KAAK,sBAAsB,UAAA;AAAA,EACzC;AAAA,EAEA,MAAa,sBAA4C;AACxD,UAAM,iBAAiB,MAAM,KAAK,kBAAA;AAElC,UAAM,aAAa,MAAM,QAAQ,IAAI,eAAe,IAAI,KAAK,qCAAqC,CAAC;AAEnG,WAAO,WAAW,OAAO,CAAC,OAAwB,OAAO,IAAI;AAAA,EAC9D;AAAA,EAEA,MAAa,4BAAuD;AACnE,UAAM,aAAa,MAAM,KAAK,oBAAA;AAC9B,WAAO,WAAW,SAAS,IAAI,WAAW,WAAW,SAAS,CAAC,IAAI;AAAA,EACpE;AAAA,EAEA,MAAa,6BAA6B,SAA4C;AACrF,UAAM,aAAa,MAAM,KAAK,oBAAA;AAC9B,WAAO,WACL,KAAK,CAAA,OAAMA,aAAAA,uBAAuB,eAAe,GAAG,OAAO,MAAMA,aAAAA,uBAAuB,eAAe,OAAO,CAAC,KAC7G;AAAA,EACL;AAAA,EAEA,MAAc,sCAAsC,MAAgD;AACnG,UAAM,SAAS,MAAM,KAAK,WAAA;AAC1B,WAAOC,gCAAkB,MAAM,IAAI,SAAS;AAAA,EAC7C;AACD;;"}
@@ -1 +1 @@
1
- {"version":3,"file":"MigrationsResolver.js","sources":["../../../../packages/migrations-client/src/MigrationsResolver.ts"],"sourcesContent":["import { MigrationFilesManager } from './MigrationFilesManager'\nimport { Migration } from '@contember/schema-migrations'\nimport { isSchemaMigration, MigrationFile } from './MigrationFile'\nimport { MigrationVersionHelper } from '@contember/engine-common'\n\nexport class MigrationsResolver {\n\tconstructor(private readonly migrationFilesManager: MigrationFilesManager) {}\n\n\tpublic get directory(): string {\n\t\treturn this.migrationFilesManager.directory\n\t}\n\n\tpublic async getMigrationFiles(): Promise<MigrationFile[]> {\n\t\treturn await this.migrationFilesManager.readFiles()\n\t}\n\n\tpublic async getSchemaMigrations(): Promise<Migration[]> {\n\t\tconst migrationFiles = await this.getMigrationFiles()\n\n\t\tconst migrations = await Promise.all(migrationFiles.map(this.convertMigrationFileToSchemaMigration))\n\n\t\treturn migrations.filter((it): it is Migration => it !== null)\n\t}\n\n\tpublic async findLatestSchemaMigration(): Promise<Migration | null> {\n\t\tconst migrations = await this.getSchemaMigrations()\n\t\treturn migrations.length > 0 ? migrations[migrations.length - 1] : null\n\t}\n\n\tpublic async findSchemaMigrationByVersion(version: string): Promise<Migration | null> {\n\t\tconst migrations = await this.getSchemaMigrations()\n\t\treturn migrations\n\t\t\t.find(it => MigrationVersionHelper.extractVersion(it.version) === MigrationVersionHelper.extractVersion(version))\n\t\t\t?? null\n\t}\n\n\tprivate async convertMigrationFileToSchemaMigration(file: MigrationFile): Promise<Migration | null> {\n\t\tconst result = await file.getContent()\n\t\treturn isSchemaMigration(result) ? result : null\n\t}\n}\n"],"names":[],"mappings":";;AAKO,MAAM,mBAAmB;AAAA,EAC/B,YAA6B,uBAA8C;AAA9C,SAAA,wBAAA;AAAA,EAA+C;AAAA,EAE5E,IAAW,YAAoB;AAC9B,WAAO,KAAK,sBAAsB;AAAA,EACnC;AAAA,EAEA,MAAa,oBAA8C;AAC1D,WAAO,MAAM,KAAK,sBAAsB,UAAA;AAAA,EACzC;AAAA,EAEA,MAAa,sBAA4C;AACxD,UAAM,iBAAiB,MAAM,KAAK,kBAAA;AAElC,UAAM,aAAa,MAAM,QAAQ,IAAI,eAAe,IAAI,KAAK,qCAAqC,CAAC;AAEnG,WAAO,WAAW,OAAO,CAAC,OAAwB,OAAO,IAAI;AAAA,EAC9D;AAAA,EAEA,MAAa,4BAAuD;AACnE,UAAM,aAAa,MAAM,KAAK,oBAAA;AAC9B,WAAO,WAAW,SAAS,IAAI,WAAW,WAAW,SAAS,CAAC,IAAI;AAAA,EACpE;AAAA,EAEA,MAAa,6BAA6B,SAA4C;AACrF,UAAM,aAAa,MAAM,KAAK,oBAAA;AAC9B,WAAO,WACL,KAAK,CAAA,OAAM,uBAAuB,eAAe,GAAG,OAAO,MAAM,uBAAuB,eAAe,OAAO,CAAC,KAC7G;AAAA,EACL;AAAA,EAEA,MAAc,sCAAsC,MAAgD;AACnG,UAAM,SAAS,MAAM,KAAK,WAAA;AAC1B,WAAO,kBAAkB,MAAM,IAAI,SAAS;AAAA,EAC7C;AACD;"}
1
+ {"version":3,"file":"MigrationsResolver.js","sources":["../../../../packages/migrations-client/src/MigrationsResolver.ts"],"sourcesContent":["import { MigrationFilesManager } from './MigrationFilesManager.js'\nimport { Migration } from '@contember/schema-migrations'\nimport { isSchemaMigration, MigrationFile } from './MigrationFile.js'\nimport { MigrationVersionHelper } from '@contember/engine-common'\n\nexport class MigrationsResolver {\n\tconstructor(private readonly migrationFilesManager: MigrationFilesManager) {}\n\n\tpublic get directory(): string {\n\t\treturn this.migrationFilesManager.directory\n\t}\n\n\tpublic async getMigrationFiles(): Promise<MigrationFile[]> {\n\t\treturn await this.migrationFilesManager.readFiles()\n\t}\n\n\tpublic async getSchemaMigrations(): Promise<Migration[]> {\n\t\tconst migrationFiles = await this.getMigrationFiles()\n\n\t\tconst migrations = await Promise.all(migrationFiles.map(this.convertMigrationFileToSchemaMigration))\n\n\t\treturn migrations.filter((it): it is Migration => it !== null)\n\t}\n\n\tpublic async findLatestSchemaMigration(): Promise<Migration | null> {\n\t\tconst migrations = await this.getSchemaMigrations()\n\t\treturn migrations.length > 0 ? migrations[migrations.length - 1] : null\n\t}\n\n\tpublic async findSchemaMigrationByVersion(version: string): Promise<Migration | null> {\n\t\tconst migrations = await this.getSchemaMigrations()\n\t\treturn migrations\n\t\t\t.find(it => MigrationVersionHelper.extractVersion(it.version) === MigrationVersionHelper.extractVersion(version))\n\t\t\t?? null\n\t}\n\n\tprivate async convertMigrationFileToSchemaMigration(file: MigrationFile): Promise<Migration | null> {\n\t\tconst result = await file.getContent()\n\t\treturn isSchemaMigration(result) ? result : null\n\t}\n}\n"],"names":[],"mappings":";;AAKO,MAAM,mBAAmB;AAAA,EAC/B,YAA6B,uBAA8C;AAA9C,SAAA,wBAAA;AAAA,EAA+C;AAAA,EAE5E,IAAW,YAAoB;AAC9B,WAAO,KAAK,sBAAsB;AAAA,EACnC;AAAA,EAEA,MAAa,oBAA8C;AAC1D,WAAO,MAAM,KAAK,sBAAsB,UAAA;AAAA,EACzC;AAAA,EAEA,MAAa,sBAA4C;AACxD,UAAM,iBAAiB,MAAM,KAAK,kBAAA;AAElC,UAAM,aAAa,MAAM,QAAQ,IAAI,eAAe,IAAI,KAAK,qCAAqC,CAAC;AAEnG,WAAO,WAAW,OAAO,CAAC,OAAwB,OAAO,IAAI;AAAA,EAC9D;AAAA,EAEA,MAAa,4BAAuD;AACnE,UAAM,aAAa,MAAM,KAAK,oBAAA;AAC9B,WAAO,WAAW,SAAS,IAAI,WAAW,WAAW,SAAS,CAAC,IAAI;AAAA,EACpE;AAAA,EAEA,MAAa,6BAA6B,SAA4C;AACrF,UAAM,aAAa,MAAM,KAAK,oBAAA;AAC9B,WAAO,WACL,KAAK,CAAA,OAAM,uBAAuB,eAAe,GAAG,OAAO,MAAM,uBAAuB,eAAe,OAAO,CAAC,KAC7G;AAAA,EACL;AAAA,EAEA,MAAc,sCAAsC,MAAgD;AACnG,UAAM,SAAS,MAAM,KAAK,WAAA;AAC1B,WAAO,kBAAkB,MAAM,IAAI,SAAS;AAAA,EAC7C;AACD;"}
@@ -0,0 +1,82 @@
1
+ "use strict";
2
+ Object.defineProperty(exports, Symbol.toStringTag, { value: "Module" });
3
+ const fs = require("node:fs/promises");
4
+ const path = require("node:path");
5
+ function _interopNamespaceDefault(e) {
6
+ const n = Object.create(null, { [Symbol.toStringTag]: { value: "Module" } });
7
+ if (e) {
8
+ for (const k in e) {
9
+ if (k !== "default") {
10
+ const d = Object.getOwnPropertyDescriptor(e, k);
11
+ Object.defineProperty(n, k, d.get ? d : {
12
+ enumerable: true,
13
+ get: () => e[k]
14
+ });
15
+ }
16
+ }
17
+ }
18
+ n.default = e;
19
+ return Object.freeze(n);
20
+ }
21
+ const fs__namespace = /* @__PURE__ */ _interopNamespaceDefault(fs);
22
+ const path__namespace = /* @__PURE__ */ _interopNamespaceDefault(path);
23
+ const stateFiles = ["acl", "validation", "actions", "settings"];
24
+ class SchemaStateManager {
25
+ constructor(stateDir) {
26
+ this.stateDir = stateDir;
27
+ }
28
+ async isStateMode() {
29
+ try {
30
+ const stat = await fs__namespace.stat(this.stateDir);
31
+ return stat.isDirectory();
32
+ } catch {
33
+ return false;
34
+ }
35
+ }
36
+ async readState() {
37
+ const state = {};
38
+ for (const key of stateFiles) {
39
+ const filePath = path__namespace.join(this.stateDir, `${key}.json`);
40
+ try {
41
+ const content = await fs__namespace.readFile(filePath, "utf8");
42
+ state[key] = JSON.parse(content);
43
+ } catch (e) {
44
+ throw new Error(`Failed to read schema state file ${filePath}: ${e instanceof Error ? e.message : e}`);
45
+ }
46
+ }
47
+ return state;
48
+ }
49
+ async writeState(state, { dryRun = false } = {}) {
50
+ let changed = false;
51
+ for (const key of stateFiles) {
52
+ const filePath = path__namespace.join(this.stateDir, `${key}.json`);
53
+ const newContent = JSON.stringify(state[key], void 0, " ") + "\n";
54
+ let currentContent = null;
55
+ try {
56
+ currentContent = await fs__namespace.readFile(filePath, "utf8");
57
+ } catch {
58
+ }
59
+ if (currentContent !== newContent) {
60
+ if (!dryRun) {
61
+ await fs__namespace.writeFile(filePath, newContent, "utf8");
62
+ }
63
+ changed = true;
64
+ }
65
+ }
66
+ return changed;
67
+ }
68
+ async extractState(schema) {
69
+ await fs__namespace.mkdir(this.stateDir, { recursive: true });
70
+ await this.writeState(SchemaStateManager.schemaStateFromSchema(schema));
71
+ }
72
+ static schemaStateFromSchema(schema) {
73
+ return {
74
+ acl: schema.acl,
75
+ validation: schema.validation,
76
+ actions: schema.actions,
77
+ settings: schema.settings
78
+ };
79
+ }
80
+ }
81
+ exports.SchemaStateManager = SchemaStateManager;
82
+ //# sourceMappingURL=SchemaStateManager.cjs.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"SchemaStateManager.cjs","sources":["../../../../packages/migrations-client/src/SchemaStateManager.ts"],"sourcesContent":["import { Acl, Actions, Schema, Settings, Validation } from '@contember/schema'\nimport * as fs from 'node:fs/promises'\nimport * as path from 'node:path'\n\nexport type SchemaState = {\n\tacl: Acl.Schema\n\tvalidation: Validation.Schema\n\tactions: Actions.Schema\n\tsettings: Settings.Schema\n}\n\nconst stateFiles = ['acl', 'validation', 'actions', 'settings'] as const\ntype StateKey = typeof stateFiles[number]\n\nexport class SchemaStateManager {\n\tconstructor(private readonly stateDir: string) {}\n\n\tasync isStateMode(): Promise<boolean> {\n\t\ttry {\n\t\t\tconst stat = await fs.stat(this.stateDir)\n\t\t\treturn stat.isDirectory()\n\t\t} catch {\n\t\t\treturn false\n\t\t}\n\t}\n\n\tasync readState(): Promise<SchemaState> {\n\t\tconst state: Partial<SchemaState> = {}\n\t\tfor (const key of stateFiles) {\n\t\t\tconst filePath = path.join(this.stateDir, `${key}.json`)\n\t\t\ttry {\n\t\t\t\tconst content = await fs.readFile(filePath, 'utf8')\n\t\t\t\tstate[key] = JSON.parse(content)\n\t\t\t} catch (e) {\n\t\t\t\tthrow new Error(`Failed to read schema state file ${filePath}: ${e instanceof Error ? e.message : e}`)\n\t\t\t}\n\t\t}\n\t\treturn state as SchemaState\n\t}\n\n\tasync writeState(state: SchemaState, { dryRun = false }: { dryRun?: boolean } = {}): Promise<boolean> {\n\t\tlet changed = false\n\t\tfor (const key of stateFiles) {\n\t\t\tconst filePath = path.join(this.stateDir, `${key}.json`)\n\t\t\tconst newContent = JSON.stringify(state[key], undefined, '\\t') + '\\n'\n\t\t\tlet currentContent: string | null = null\n\t\t\ttry {\n\t\t\t\tcurrentContent = await fs.readFile(filePath, 'utf8')\n\t\t\t} catch {\n\t\t\t\t// file doesn't exist yet\n\t\t\t}\n\t\t\tif (currentContent !== newContent) {\n\t\t\t\tif (!dryRun) {\n\t\t\t\t\tawait fs.writeFile(filePath, newContent, 'utf8')\n\t\t\t\t}\n\t\t\t\tchanged = true\n\t\t\t}\n\t\t}\n\t\treturn changed\n\t}\n\n\tasync extractState(schema: Schema): Promise<void> {\n\t\tawait fs.mkdir(this.stateDir, { recursive: true })\n\t\tawait this.writeState(SchemaStateManager.schemaStateFromSchema(schema))\n\t}\n\n\tstatic schemaStateFromSchema(schema: Schema): SchemaState {\n\t\treturn {\n\t\t\tacl: schema.acl,\n\t\t\tvalidation: schema.validation,\n\t\t\tactions: schema.actions,\n\t\t\tsettings: schema.settings,\n\t\t}\n\t}\n}\n"],"names":["fs","path"],"mappings":";;;;;;;;;;;;;;;;;;;;;;AAWA,MAAM,aAAa,CAAC,OAAO,cAAc,WAAW,UAAU;AAGvD,MAAM,mBAAmB;AAAA,EAC/B,YAA6B,UAAkB;AAAlB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AA,EACvE;AAAA,EAEA,OAAO,sBAAsB,QAA6B;AACzD,WAAO;AAAA,MACN,KAAK,OAAO;AAAA,MACZ,YAAY,OAAO;AAAA,MACnB,SAAS,OAAO;AAAA,MAChB,UAAU,OAAO;AAAA,IAAA;AAAA,EAEnB;AACD;;"}
@@ -0,0 +1,64 @@
1
+ import * as fs from "node:fs/promises";
2
+ import * as path from "node:path";
3
+ const stateFiles = ["acl", "validation", "actions", "settings"];
4
+ class SchemaStateManager {
5
+ constructor(stateDir) {
6
+ this.stateDir = stateDir;
7
+ }
8
+ async isStateMode() {
9
+ try {
10
+ const stat = await fs.stat(this.stateDir);
11
+ return stat.isDirectory();
12
+ } catch {
13
+ return false;
14
+ }
15
+ }
16
+ async readState() {
17
+ const state = {};
18
+ for (const key of stateFiles) {
19
+ const filePath = path.join(this.stateDir, `${key}.json`);
20
+ try {
21
+ const content = await fs.readFile(filePath, "utf8");
22
+ state[key] = JSON.parse(content);
23
+ } catch (e) {
24
+ throw new Error(`Failed to read schema state file ${filePath}: ${e instanceof Error ? e.message : e}`);
25
+ }
26
+ }
27
+ return state;
28
+ }
29
+ async writeState(state, { dryRun = false } = {}) {
30
+ let changed = false;
31
+ for (const key of stateFiles) {
32
+ const filePath = path.join(this.stateDir, `${key}.json`);
33
+ const newContent = JSON.stringify(state[key], void 0, " ") + "\n";
34
+ let currentContent = null;
35
+ try {
36
+ currentContent = await fs.readFile(filePath, "utf8");
37
+ } catch {
38
+ }
39
+ if (currentContent !== newContent) {
40
+ if (!dryRun) {
41
+ await fs.writeFile(filePath, newContent, "utf8");
42
+ }
43
+ changed = true;
44
+ }
45
+ }
46
+ return changed;
47
+ }
48
+ async extractState(schema) {
49
+ await fs.mkdir(this.stateDir, { recursive: true });
50
+ await this.writeState(SchemaStateManager.schemaStateFromSchema(schema));
51
+ }
52
+ static schemaStateFromSchema(schema) {
53
+ return {
54
+ acl: schema.acl,
55
+ validation: schema.validation,
56
+ actions: schema.actions,
57
+ settings: schema.settings
58
+ };
59
+ }
60
+ }
61
+ export {
62
+ SchemaStateManager
63
+ };
64
+ //# sourceMappingURL=SchemaStateManager.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"SchemaStateManager.js","sources":["../../../../packages/migrations-client/src/SchemaStateManager.ts"],"sourcesContent":["import { Acl, Actions, Schema, Settings, Validation } from '@contember/schema'\nimport * as fs from 'node:fs/promises'\nimport * as path from 'node:path'\n\nexport type SchemaState = {\n\tacl: Acl.Schema\n\tvalidation: Validation.Schema\n\tactions: Actions.Schema\n\tsettings: Settings.Schema\n}\n\nconst stateFiles = ['acl', 'validation', 'actions', 'settings'] as const\ntype StateKey = typeof stateFiles[number]\n\nexport class SchemaStateManager {\n\tconstructor(private readonly stateDir: string) {}\n\n\tasync isStateMode(): Promise<boolean> {\n\t\ttry {\n\t\t\tconst stat = await fs.stat(this.stateDir)\n\t\t\treturn stat.isDirectory()\n\t\t} catch {\n\t\t\treturn false\n\t\t}\n\t}\n\n\tasync readState(): Promise<SchemaState> {\n\t\tconst state: Partial<SchemaState> = {}\n\t\tfor (const key of stateFiles) {\n\t\t\tconst filePath = path.join(this.stateDir, `${key}.json`)\n\t\t\ttry {\n\t\t\t\tconst content = await fs.readFile(filePath, 'utf8')\n\t\t\t\tstate[key] = JSON.parse(content)\n\t\t\t} catch (e) {\n\t\t\t\tthrow new Error(`Failed to read schema state file ${filePath}: ${e instanceof Error ? e.message : e}`)\n\t\t\t}\n\t\t}\n\t\treturn state as SchemaState\n\t}\n\n\tasync writeState(state: SchemaState, { dryRun = false }: { dryRun?: boolean } = {}): Promise<boolean> {\n\t\tlet changed = false\n\t\tfor (const key of stateFiles) {\n\t\t\tconst filePath = path.join(this.stateDir, `${key}.json`)\n\t\t\tconst newContent = JSON.stringify(state[key], undefined, '\\t') + '\\n'\n\t\t\tlet currentContent: string | null = null\n\t\t\ttry {\n\t\t\t\tcurrentContent = await fs.readFile(filePath, 'utf8')\n\t\t\t} catch {\n\t\t\t\t// file doesn't exist yet\n\t\t\t}\n\t\t\tif (currentContent !== newContent) {\n\t\t\t\tif (!dryRun) {\n\t\t\t\t\tawait fs.writeFile(filePath, newContent, 'utf8')\n\t\t\t\t}\n\t\t\t\tchanged = true\n\t\t\t}\n\t\t}\n\t\treturn changed\n\t}\n\n\tasync extractState(schema: Schema): Promise<void> {\n\t\tawait fs.mkdir(this.stateDir, { recursive: true })\n\t\tawait this.writeState(SchemaStateManager.schemaStateFromSchema(schema))\n\t}\n\n\tstatic schemaStateFromSchema(schema: Schema): SchemaState {\n\t\treturn {\n\t\t\tacl: schema.acl,\n\t\t\tvalidation: schema.validation,\n\t\t\tactions: schema.actions,\n\t\t\tsettings: schema.settings,\n\t\t}\n\t}\n}\n"],"names":[],"mappings":";;AAWA,MAAM,aAAa,CAAC,OAAO,cAAc,WAAW,UAAU;AAGvD,MAAM,mBAAmB;AAAA,EAC/B,YAA6B,UAAkB;AAAlB,SAAA,WAAA;AAAA,EAAmB;AAAA,EAEhD,MAAM,cAAgC;AACrC,QAAI;AACH,YAAM,OAAO,MAAM,GAAG,KAAK,KAAK,QAAQ;AACxC,aAAO,KAAK,YAAA;AAAA,IACb,QAAQ;AACP,aAAO;AAAA,IACR;AAAA,EACD;AAAA,EAEA,MAAM,YAAkC;AACvC,UAAM,QAA8B,CAAA;AACpC,eAAW,OAAO,YAAY;AAC7B,YAAM,WAAW,KAAK,KAAK,KAAK,UAAU,GAAG,GAAG,OAAO;AACvD,UAAI;AACH,cAAM,UAAU,MAAM,GAAG,SAAS,UAAU,MAAM;AAClD,cAAM,GAAG,IAAI,KAAK,MAAM,OAAO;AAAA,MAChC,SAAS,GAAG;AACX,cAAM,IAAI,MAAM,oCAAoC,QAAQ,KAAK,aAAa,QAAQ,EAAE,UAAU,CAAC,EAAE;AAAA,MACtG;AAAA,IACD;AACA,WAAO;AAAA,EACR;AAAA,EAEA,MAAM,WAAW,OAAoB,EAAE,SAAS,MAAA,IAAgC,CAAA,GAAsB;AACrG,QAAI,UAAU;AACd,eAAW,OAAO,YAAY;AAC7B,YAAM,WAAW,KAAK,KAAK,KAAK,UAAU,GAAG,GAAG,OAAO;AACvD,YAAM,aAAa,KAAK,UAAU,MAAM,GAAG,GAAG,QAAW,GAAI,IAAI;AACjE,UAAI,iBAAgC;AACpC,UAAI;AACH,yBAAiB,MAAM,GAAG,SAAS,UAAU,MAAM;AAAA,MACpD,QAAQ;AAAA,MAER;AACA,UAAI,mBAAmB,YAAY;AAClC,YAAI,CAAC,QAAQ;AACZ,gBAAM,GAAG,UAAU,UAAU,YAAY,MAAM;AAAA,QAChD;AACA,kBAAU;AAAA,MACX;AAAA,IACD;AACA,WAAO;AAAA,EACR;AAAA,EAEA,MAAM,aAAa,QAA+B;AACjD,UAAM,GAAG,MAAM,KAAK,UAAU,EAAE,WAAW,MAAM;AACjD,UAAM,KAAK,WAAW,mBAAmB,sBAAsB,MAAM,CAAC;AAAA,EACvE;AAAA,EAEA,OAAO,sBAAsB,QAA6B;AACzD,WAAO;AAAA,MACN,KAAK,OAAO;AAAA,MACZ,YAAY,OAAO;AAAA,MACnB,SAAS,OAAO;AAAA,MAChB,UAAU,OAAO;AAAA,IAAA;AAAA,EAEnB;AACD;"}
@@ -2,12 +2,18 @@
2
2
  Object.defineProperty(exports, Symbol.toStringTag, { value: "Module" });
3
3
  const schemaUtils = require("@contember/schema-utils");
4
4
  class SchemaVersionBuilder {
5
- constructor(migrationsResolver, schemaMigrator) {
5
+ constructor(migrationsResolver, schemaMigrator, schemaStateManager) {
6
6
  this.migrationsResolver = migrationsResolver;
7
7
  this.schemaMigrator = schemaMigrator;
8
+ this.schemaStateManager = schemaStateManager;
8
9
  }
9
10
  async buildSchema(targetVersion) {
10
- return this.buildSchemaAdvanced(schemaUtils.emptySchema, (version) => !targetVersion || version <= targetVersion);
11
+ let schema = await this.buildSchemaAdvanced(schemaUtils.emptySchema, (version) => !targetVersion || version <= targetVersion);
12
+ if (!targetVersion && await this.schemaStateManager.isStateMode()) {
13
+ const state = await this.schemaStateManager.readState();
14
+ schema = { ...schema, ...state };
15
+ }
16
+ return schema;
11
17
  }
12
18
  async buildSchemaUntil(targetVersion) {
13
19
  return this.buildSchemaAdvanced(schemaUtils.emptySchema, (version) => version < targetVersion);