@contember/migrations-client 2.1.0-alpha.36 → 2.1.0-alpha.39

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 +53 -0
  2. package/dist/development/index.cjs.map +1 -0
  3. package/dist/development/index.js +35 -0
  4. package/dist/development/index.js.map +1 -0
  5. package/dist/development/src/JsLoader.cjs +30 -0
  6. package/dist/development/src/JsLoader.cjs.map +1 -0
  7. package/dist/development/src/JsLoader.js +30 -0
  8. package/dist/development/src/JsLoader.js.map +1 -0
  9. package/dist/development/src/JsonLoader.cjs +33 -0
  10. package/dist/development/src/JsonLoader.cjs.map +1 -0
  11. package/dist/development/src/JsonLoader.js +16 -0
  12. package/dist/development/src/JsonLoader.js.map +1 -0
  13. package/dist/development/src/MigrationCreator.cjs +46 -0
  14. package/dist/development/src/MigrationCreator.cjs.map +1 -0
  15. package/dist/development/src/MigrationCreator.js +46 -0
  16. package/dist/development/src/MigrationCreator.js.map +1 -0
  17. package/dist/development/src/MigrationExecuteHelper.cjs +71 -0
  18. package/dist/development/src/MigrationExecuteHelper.cjs.map +1 -0
  19. package/dist/development/src/MigrationExecuteHelper.js +71 -0
  20. package/dist/development/src/MigrationExecuteHelper.js.map +1 -0
  21. package/dist/development/src/MigrationFile.cjs +5 -0
  22. package/dist/development/src/MigrationFile.cjs.map +1 -0
  23. package/dist/development/src/MigrationFile.js +5 -0
  24. package/dist/development/src/MigrationFile.js.map +1 -0
  25. package/dist/development/src/MigrationFilesManager.cjs +106 -0
  26. package/dist/development/src/MigrationFilesManager.cjs.map +1 -0
  27. package/dist/development/src/MigrationFilesManager.js +89 -0
  28. package/dist/development/src/MigrationFilesManager.js.map +1 -0
  29. package/dist/development/src/MigrationParser.cjs +31 -0
  30. package/dist/development/src/MigrationParser.cjs.map +1 -0
  31. package/dist/development/src/MigrationParser.js +31 -0
  32. package/dist/development/src/MigrationParser.js.map +1 -0
  33. package/dist/development/src/MigrationsResolver.cjs +34 -0
  34. package/dist/development/src/MigrationsResolver.cjs.map +1 -0
  35. package/dist/development/src/MigrationsResolver.js +34 -0
  36. package/dist/development/src/MigrationsResolver.js.map +1 -0
  37. package/dist/development/src/SchemaVersionBuilder.cjs +26 -0
  38. package/dist/development/src/SchemaVersionBuilder.cjs.map +1 -0
  39. package/dist/development/src/SchemaVersionBuilder.js +26 -0
  40. package/dist/development/src/SchemaVersionBuilder.js.map +1 -0
  41. package/dist/development/src/SystemClient.cjs +117 -0
  42. package/dist/development/src/SystemClient.cjs.map +1 -0
  43. package/dist/development/src/SystemClient.js +117 -0
  44. package/dist/development/src/SystemClient.js.map +1 -0
  45. package/dist/development/src/migrations.cjs +108 -0
  46. package/dist/development/src/migrations.cjs.map +1 -0
  47. package/dist/development/src/migrations.js +108 -0
  48. package/dist/development/src/migrations.js.map +1 -0
  49. package/dist/development/src/utils/assertNever.cjs +7 -0
  50. package/dist/development/src/utils/assertNever.cjs.map +1 -0
  51. package/dist/development/src/utils/assertNever.js +7 -0
  52. package/dist/development/src/utils/assertNever.js.map +1 -0
  53. package/dist/production/index.cjs +53 -0
  54. package/dist/production/index.cjs.map +1 -0
  55. package/dist/production/index.js +35 -0
  56. package/dist/production/index.js.map +1 -0
  57. package/dist/production/src/JsLoader.cjs +30 -0
  58. package/dist/production/src/JsLoader.cjs.map +1 -0
  59. package/dist/production/src/JsLoader.js +30 -0
  60. package/dist/production/src/JsLoader.js.map +1 -0
  61. package/dist/production/src/JsonLoader.cjs +33 -0
  62. package/dist/production/src/JsonLoader.cjs.map +1 -0
  63. package/dist/production/src/JsonLoader.js +16 -0
  64. package/dist/production/src/JsonLoader.js.map +1 -0
  65. package/dist/production/src/MigrationCreator.cjs +46 -0
  66. package/dist/production/src/MigrationCreator.cjs.map +1 -0
  67. package/dist/production/src/MigrationCreator.js +46 -0
  68. package/dist/production/src/MigrationCreator.js.map +1 -0
  69. package/dist/production/src/MigrationExecuteHelper.cjs +71 -0
  70. package/dist/production/src/MigrationExecuteHelper.cjs.map +1 -0
  71. package/dist/production/src/MigrationExecuteHelper.js +71 -0
  72. package/dist/production/src/MigrationExecuteHelper.js.map +1 -0
  73. package/dist/production/src/MigrationFile.cjs +5 -0
  74. package/dist/production/src/MigrationFile.cjs.map +1 -0
  75. package/dist/production/src/MigrationFile.js +5 -0
  76. package/dist/production/src/MigrationFile.js.map +1 -0
  77. package/dist/production/src/MigrationFilesManager.cjs +106 -0
  78. package/dist/production/src/MigrationFilesManager.cjs.map +1 -0
  79. package/dist/production/src/MigrationFilesManager.js +89 -0
  80. package/dist/production/src/MigrationFilesManager.js.map +1 -0
  81. package/dist/production/src/MigrationParser.cjs +31 -0
  82. package/dist/production/src/MigrationParser.cjs.map +1 -0
  83. package/dist/production/src/MigrationParser.js +31 -0
  84. package/dist/production/src/MigrationParser.js.map +1 -0
  85. package/dist/production/src/MigrationsResolver.cjs +34 -0
  86. package/dist/production/src/MigrationsResolver.cjs.map +1 -0
  87. package/dist/production/src/MigrationsResolver.js +34 -0
  88. package/dist/production/src/MigrationsResolver.js.map +1 -0
  89. package/dist/production/src/SchemaVersionBuilder.cjs +26 -0
  90. package/dist/production/src/SchemaVersionBuilder.cjs.map +1 -0
  91. package/dist/production/src/SchemaVersionBuilder.js +26 -0
  92. package/dist/production/src/SchemaVersionBuilder.js.map +1 -0
  93. package/dist/production/src/SystemClient.cjs +117 -0
  94. package/dist/production/src/SystemClient.cjs.map +1 -0
  95. package/dist/production/src/SystemClient.js +117 -0
  96. package/dist/production/src/SystemClient.js.map +1 -0
  97. package/dist/production/src/migrations.cjs +108 -0
  98. package/dist/production/src/migrations.cjs.map +1 -0
  99. package/dist/production/src/migrations.js +108 -0
  100. package/dist/production/src/migrations.js.map +1 -0
  101. package/dist/production/src/utils/assertNever.cjs +7 -0
  102. package/dist/production/src/utils/assertNever.cjs.map +1 -0
  103. package/dist/production/src/utils/assertNever.js +7 -0
  104. package/dist/production/src/utils/assertNever.js.map +1 -0
  105. package/dist/types/JsLoader.d.ts +10 -0
  106. package/dist/types/JsLoader.d.ts.map +1 -0
  107. package/dist/types/JsonLoader.d.ts +9 -0
  108. package/dist/types/JsonLoader.d.ts.map +1 -0
  109. package/dist/types/MigrationCreator.d.ts +21 -0
  110. package/dist/types/MigrationCreator.d.ts.map +1 -0
  111. package/dist/types/MigrationExecuteHelper.d.ts +13 -0
  112. package/dist/types/MigrationExecuteHelper.d.ts.map +1 -0
  113. package/dist/types/MigrationFile.d.ts +39 -0
  114. package/dist/types/MigrationFile.d.ts.map +1 -0
  115. package/dist/types/MigrationFileLoader.d.ts +5 -0
  116. package/dist/types/MigrationFileLoader.d.ts.map +1 -0
  117. package/dist/types/MigrationFilesManager.d.ts +18 -0
  118. package/dist/types/MigrationFilesManager.d.ts.map +1 -0
  119. package/dist/types/MigrationParser.d.ts +6 -0
  120. package/dist/types/MigrationParser.d.ts.map +1 -0
  121. package/dist/types/MigrationsResolver.d.ts +14 -0
  122. package/dist/types/MigrationsResolver.d.ts.map +1 -0
  123. package/dist/types/SchemaVersionBuilder.d.ts +13 -0
  124. package/dist/types/SchemaVersionBuilder.d.ts.map +1 -0
  125. package/dist/types/SystemClient.d.ts +29 -0
  126. package/dist/types/SystemClient.d.ts.map +1 -0
  127. package/dist/types/index.d.ts +15 -0
  128. package/dist/types/index.d.ts.map +1 -0
  129. package/dist/types/migrations.d.ts +60 -0
  130. package/dist/types/migrations.d.ts.map +1 -0
  131. package/dist/types/tsconfig.tsbuildinfo +1 -0
  132. package/dist/types/utils/assertNever.d.ts +2 -0
  133. package/dist/types/utils/assertNever.d.ts.map +1 -0
  134. package/dist/types/utils/json.d.ts +7 -0
  135. package/dist/types/utils/json.d.ts.map +1 -0
  136. package/package.json +7 -7
@@ -0,0 +1,53 @@
1
+ "use strict";
2
+ Object.defineProperty(exports, Symbol.toStringTag, { value: "Module" });
3
+ const schemaMigrations = require("@contember/schema-migrations");
4
+ const JsLoader = require("./src/JsLoader.cjs");
5
+ const JsonLoader = require("./src/JsonLoader.cjs");
6
+ const MigrationCreator = require("./src/MigrationCreator.cjs");
7
+ const MigrationExecuteHelper = require("./src/MigrationExecuteHelper.cjs");
8
+ const MigrationFile = require("./src/MigrationFile.cjs");
9
+ const MigrationFilesManager = require("./src/MigrationFilesManager.cjs");
10
+ const MigrationParser = require("./src/MigrationParser.cjs");
11
+ const migrations = require("./src/migrations.cjs");
12
+ const MigrationsResolver = require("./src/MigrationsResolver.cjs");
13
+ const SchemaVersionBuilder = require("./src/SchemaVersionBuilder.cjs");
14
+ const SystemClient = require("./src/SystemClient.cjs");
15
+ Object.defineProperty(exports, "MigrationDescriber", {
16
+ enumerable: true,
17
+ get: () => schemaMigrations.MigrationDescriber
18
+ });
19
+ Object.defineProperty(exports, "ModificationHandlerFactory", {
20
+ enumerable: true,
21
+ get: () => schemaMigrations.ModificationHandlerFactory
22
+ });
23
+ Object.defineProperty(exports, "SchemaDiffer", {
24
+ enumerable: true,
25
+ get: () => schemaMigrations.SchemaDiffer
26
+ });
27
+ Object.defineProperty(exports, "SchemaMigrator", {
28
+ enumerable: true,
29
+ get: () => schemaMigrations.SchemaMigrator
30
+ });
31
+ Object.defineProperty(exports, "VERSION_LATEST", {
32
+ enumerable: true,
33
+ get: () => schemaMigrations.VERSION_LATEST
34
+ });
35
+ Object.defineProperty(exports, "calculateMigrationChecksum", {
36
+ enumerable: true,
37
+ get: () => schemaMigrations.calculateMigrationChecksum
38
+ });
39
+ exports.JsLoader = JsLoader.JsLoader;
40
+ exports.JsonLoader = JsonLoader.JsonLoader;
41
+ exports.MigrationCreator = MigrationCreator.MigrationCreator;
42
+ exports.MigrationExecutor = MigrationExecuteHelper.MigrationExecutor;
43
+ exports.isSchemaMigration = MigrationFile.isSchemaMigration;
44
+ exports.MigrationFilesManager = MigrationFilesManager.MigrationFilesManager;
45
+ exports.MigrationParser = MigrationParser.MigrationParser;
46
+ exports.MigrationState = migrations.MigrationState;
47
+ exports.MigrationsStatusResolver = migrations.MigrationsStatusResolver;
48
+ exports.sortMigrations = migrations.sortMigrations;
49
+ exports.MigrationsResolver = MigrationsResolver.MigrationsResolver;
50
+ exports.SchemaVersionBuilder = SchemaVersionBuilder.SchemaVersionBuilder;
51
+ exports.MigrateErrorCode = SystemClient.MigrateErrorCode;
52
+ exports.SystemClient = SystemClient.SystemClient;
53
+ //# sourceMappingURL=index.cjs.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"index.cjs","sources":[],"sourcesContent":[],"names":[],"mappings":";;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;"}
@@ -0,0 +1,35 @@
1
+ import { MigrationDescriber, ModificationHandlerFactory, SchemaDiffer, SchemaMigrator, VERSION_LATEST, calculateMigrationChecksum } from "@contember/schema-migrations";
2
+ import { JsLoader } from "./src/JsLoader.js";
3
+ import { JsonLoader } from "./src/JsonLoader.js";
4
+ import { MigrationCreator } from "./src/MigrationCreator.js";
5
+ import { MigrationExecutor } from "./src/MigrationExecuteHelper.js";
6
+ import { isSchemaMigration } from "./src/MigrationFile.js";
7
+ import { MigrationFilesManager } from "./src/MigrationFilesManager.js";
8
+ import { MigrationParser } from "./src/MigrationParser.js";
9
+ import { MigrationState, MigrationsStatusResolver, sortMigrations } from "./src/migrations.js";
10
+ import { MigrationsResolver } from "./src/MigrationsResolver.js";
11
+ import { SchemaVersionBuilder } from "./src/SchemaVersionBuilder.js";
12
+ import { MigrateErrorCode, SystemClient } from "./src/SystemClient.js";
13
+ export {
14
+ JsLoader,
15
+ JsonLoader,
16
+ MigrateErrorCode,
17
+ MigrationCreator,
18
+ MigrationDescriber,
19
+ MigrationExecutor,
20
+ MigrationFilesManager,
21
+ MigrationParser,
22
+ MigrationState,
23
+ MigrationsResolver,
24
+ MigrationsStatusResolver,
25
+ ModificationHandlerFactory,
26
+ SchemaDiffer,
27
+ SchemaMigrator,
28
+ SchemaVersionBuilder,
29
+ SystemClient,
30
+ VERSION_LATEST,
31
+ calculateMigrationChecksum,
32
+ isSchemaMigration,
33
+ sortMigrations
34
+ };
35
+ //# sourceMappingURL=index.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"index.js","sources":[],"sourcesContent":[],"names":[],"mappings":";;;;;;;;;;;;"}
@@ -0,0 +1,30 @@
1
+ "use strict";
2
+ Object.defineProperty(exports, Symbol.toStringTag, { value: "Module" });
3
+ class JsLoader {
4
+ constructor(migrationParser, jsExecutor) {
5
+ this.migrationParser = migrationParser;
6
+ this.jsExecutor = jsExecutor;
7
+ }
8
+ async load(file) {
9
+ const exports$1 = await this.jsExecutor(file.path);
10
+ if (!("default" in exports$1) && !("query" in exports$1) && !("queries" in exports$1)) {
11
+ throw `export "default" or "query" is required in ${file.path}`;
12
+ }
13
+ if (typeof exports$1.default !== "function") {
14
+ return this.migrationParser.parse(file, exports$1.default || exports$1);
15
+ }
16
+ return {
17
+ type: "factory",
18
+ factory: async (args) => {
19
+ const result = await exports$1.default(args);
20
+ const migration = this.migrationParser.parse(file, result ?? { queries: [] });
21
+ if (migration.type !== "content") {
22
+ throw new Error();
23
+ }
24
+ return migration;
25
+ }
26
+ };
27
+ }
28
+ }
29
+ exports.JsLoader = JsLoader;
30
+ //# sourceMappingURL=JsLoader.cjs.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"JsLoader.cjs","sources":["../../../../packages/migrations-client/src/JsLoader.ts"],"sourcesContent":["import { MigrationFileLoader } from './MigrationFileLoader'\nimport { MigrationParser } from './MigrationParser'\nimport { ContentMigration, ContentMigrationFactoryArgs, MigrationContent, MigrationFile } from './MigrationFile'\n\nexport class JsLoader implements MigrationFileLoader {\n\tconstructor(\n\t\tprivate readonly migrationParser: MigrationParser,\n\t\tprivate readonly jsExecutor: (file: string) => Promise<any>,\n\t) {\n\t}\n\n\tpublic async load(file: MigrationFile): Promise<MigrationContent> {\n\t\tconst exports = await this.jsExecutor(file.path)\n\t\tif (!('default' in exports) && !('query' in exports) && !('queries' in exports)) {\n\t\t\tthrow `export \"default\" or \"query\" is required in ${file.path}`\n\t\t}\n\t\tif (typeof exports.default !== 'function') {\n\t\t\treturn this.migrationParser.parse(file, exports.default || exports)\n\t\t}\n\n\t\treturn {\n\t\t\ttype: 'factory',\n\t\t\tfactory: async (args: ContentMigrationFactoryArgs): Promise<ContentMigration> => {\n\t\t\t\tconst result = await exports.default(args)\n\t\t\t\tconst migration = this.migrationParser.parse(file, result ?? { queries: [] })\n\t\t\t\tif (migration.type !== 'content') {\n\t\t\t\t\tthrow new Error()\n\t\t\t\t}\n\t\t\t\treturn migration\n\t\t\t},\n\t\t}\n\t}\n}\n"],"names":["exports"],"mappings":";;AAIO,MAAM,SAAwC;AAAA,EACpD,YACkB,iBACA,YAChB;AAFgB,SAAA,kBAAA;AACA,SAAA,aAAA;AAAA,EAElB;AAAA,EAEA,MAAa,KAAK,MAAgD;AACjE,UAAMA,YAAU,MAAM,KAAK,WAAW,KAAK,IAAI;AAC/C,QAAI,EAAE,aAAaA,cAAY,EAAE,WAAWA,cAAY,EAAE,aAAaA,YAAU;AAChF,YAAM,8CAA8C,KAAK,IAAI;AAAA,IAC9D;AACA,QAAI,OAAOA,UAAQ,YAAY,YAAY;AAC1C,aAAO,KAAK,gBAAgB,MAAM,MAAMA,UAAQ,WAAWA,SAAO;AAAA,IACnE;AAEA,WAAO;AAAA,MACN,MAAM;AAAA,MACN,SAAS,OAAO,SAAiE;AAChF,cAAM,SAAS,MAAMA,UAAQ,QAAQ,IAAI;AACzC,cAAM,YAAY,KAAK,gBAAgB,MAAM,MAAM,UAAU,EAAE,SAAS,CAAA,GAAI;AAC5E,YAAI,UAAU,SAAS,WAAW;AACjC,gBAAM,IAAI,MAAA;AAAA,QACX;AACA,eAAO;AAAA,MACR;AAAA,IAAA;AAAA,EAEF;AACD;;"}
@@ -0,0 +1,30 @@
1
+ class JsLoader {
2
+ constructor(migrationParser, jsExecutor) {
3
+ this.migrationParser = migrationParser;
4
+ this.jsExecutor = jsExecutor;
5
+ }
6
+ async load(file) {
7
+ const exports$1 = await this.jsExecutor(file.path);
8
+ if (!("default" in exports$1) && !("query" in exports$1) && !("queries" in exports$1)) {
9
+ throw `export "default" or "query" is required in ${file.path}`;
10
+ }
11
+ if (typeof exports$1.default !== "function") {
12
+ return this.migrationParser.parse(file, exports$1.default || exports$1);
13
+ }
14
+ return {
15
+ type: "factory",
16
+ factory: async (args) => {
17
+ const result = await exports$1.default(args);
18
+ const migration = this.migrationParser.parse(file, result ?? { queries: [] });
19
+ if (migration.type !== "content") {
20
+ throw new Error();
21
+ }
22
+ return migration;
23
+ }
24
+ };
25
+ }
26
+ }
27
+ export {
28
+ JsLoader
29
+ };
30
+ //# sourceMappingURL=JsLoader.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"JsLoader.js","sources":["../../../../packages/migrations-client/src/JsLoader.ts"],"sourcesContent":["import { MigrationFileLoader } from './MigrationFileLoader'\nimport { MigrationParser } from './MigrationParser'\nimport { ContentMigration, ContentMigrationFactoryArgs, MigrationContent, MigrationFile } from './MigrationFile'\n\nexport class JsLoader implements MigrationFileLoader {\n\tconstructor(\n\t\tprivate readonly migrationParser: MigrationParser,\n\t\tprivate readonly jsExecutor: (file: string) => Promise<any>,\n\t) {\n\t}\n\n\tpublic async load(file: MigrationFile): Promise<MigrationContent> {\n\t\tconst exports = await this.jsExecutor(file.path)\n\t\tif (!('default' in exports) && !('query' in exports) && !('queries' in exports)) {\n\t\t\tthrow `export \"default\" or \"query\" is required in ${file.path}`\n\t\t}\n\t\tif (typeof exports.default !== 'function') {\n\t\t\treturn this.migrationParser.parse(file, exports.default || exports)\n\t\t}\n\n\t\treturn {\n\t\t\ttype: 'factory',\n\t\t\tfactory: async (args: ContentMigrationFactoryArgs): Promise<ContentMigration> => {\n\t\t\t\tconst result = await exports.default(args)\n\t\t\t\tconst migration = this.migrationParser.parse(file, result ?? { queries: [] })\n\t\t\t\tif (migration.type !== 'content') {\n\t\t\t\t\tthrow new Error()\n\t\t\t\t}\n\t\t\t\treturn migration\n\t\t\t},\n\t\t}\n\t}\n}\n"],"names":["exports"],"mappings":"AAIO,MAAM,SAAwC;AAAA,EACpD,YACkB,iBACA,YAChB;AAFgB,SAAA,kBAAA;AACA,SAAA,aAAA;AAAA,EAElB;AAAA,EAEA,MAAa,KAAK,MAAgD;AACjE,UAAMA,YAAU,MAAM,KAAK,WAAW,KAAK,IAAI;AAC/C,QAAI,EAAE,aAAaA,cAAY,EAAE,WAAWA,cAAY,EAAE,aAAaA,YAAU;AAChF,YAAM,8CAA8C,KAAK,IAAI;AAAA,IAC9D;AACA,QAAI,OAAOA,UAAQ,YAAY,YAAY;AAC1C,aAAO,KAAK,gBAAgB,MAAM,MAAMA,UAAQ,WAAWA,SAAO;AAAA,IACnE;AAEA,WAAO;AAAA,MACN,MAAM;AAAA,MACN,SAAS,OAAO,SAAiE;AAChF,cAAM,SAAS,MAAMA,UAAQ,QAAQ,IAAI;AACzC,cAAM,YAAY,KAAK,gBAAgB,MAAM,MAAM,UAAU,EAAE,SAAS,CAAA,GAAI;AAC5E,YAAI,UAAU,SAAS,WAAW;AACjC,gBAAM,IAAI,MAAA;AAAA,QACX;AACA,eAAO;AAAA,MACR;AAAA,IAAA;AAAA,EAEF;AACD;"}
@@ -0,0 +1,33 @@
1
+ "use strict";
2
+ Object.defineProperty(exports, Symbol.toStringTag, { value: "Module" });
3
+ const fs = require("node:fs/promises");
4
+ function _interopNamespaceDefault(e) {
5
+ const n = Object.create(null, { [Symbol.toStringTag]: { value: "Module" } });
6
+ if (e) {
7
+ for (const k in e) {
8
+ if (k !== "default") {
9
+ const d = Object.getOwnPropertyDescriptor(e, k);
10
+ Object.defineProperty(n, k, d.get ? d : {
11
+ enumerable: true,
12
+ get: () => e[k]
13
+ });
14
+ }
15
+ }
16
+ }
17
+ n.default = e;
18
+ return Object.freeze(n);
19
+ }
20
+ const fs__namespace = /* @__PURE__ */ _interopNamespaceDefault(fs);
21
+ class JsonLoader {
22
+ constructor(migrationParser) {
23
+ this.migrationParser = migrationParser;
24
+ }
25
+ async load(file) {
26
+ return this.migrationParser.parse(
27
+ file,
28
+ JSON.parse(await fs__namespace.readFile(file.path, { encoding: "utf8" }))
29
+ );
30
+ }
31
+ }
32
+ exports.JsonLoader = JsonLoader;
33
+ //# sourceMappingURL=JsonLoader.cjs.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"JsonLoader.cjs","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":["fs"],"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,MAAMA,cAAG,SAAS,KAAK,MAAM,EAAE,UAAU,QAAQ,CAAC;AAAA,IAAA;AAAA,EAE/D;AACD;;"}
@@ -0,0 +1,16 @@
1
+ import * as fs from "node:fs/promises";
2
+ class JsonLoader {
3
+ constructor(migrationParser) {
4
+ this.migrationParser = migrationParser;
5
+ }
6
+ async load(file) {
7
+ return this.migrationParser.parse(
8
+ file,
9
+ JSON.parse(await fs.readFile(file.path, { encoding: "utf8" }))
10
+ );
11
+ }
12
+ }
13
+ export {
14
+ JsonLoader
15
+ };
16
+ //# sourceMappingURL=JsonLoader.js.map
@@ -0,0 +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;"}
@@ -0,0 +1,46 @@
1
+ "use strict";
2
+ Object.defineProperty(exports, Symbol.toStringTag, { value: "Module" });
3
+ const schemaMigrations = require("@contember/schema-migrations");
4
+ const engineCommon = require("@contember/engine-common");
5
+ class MigrationCreator {
6
+ constructor(migrationFilesManager, schemaDiffer, emptyTemplates = {}) {
7
+ this.migrationFilesManager = migrationFilesManager;
8
+ this.schemaDiffer = schemaDiffer;
9
+ this.emptyTemplates = emptyTemplates;
10
+ }
11
+ async createEmptyMigrationFile(migrationName, format) {
12
+ if (!this.emptyTemplates.hasOwnProperty(format)) {
13
+ throw new Error(`Unknown format ${format}`);
14
+ }
15
+ await this.migrationFilesManager.createDirIfNotExist();
16
+ const [, fullName] = engineCommon.MigrationVersionHelper.createVersion(migrationName);
17
+ const filename = await this.migrationFilesManager.createFile(this.emptyTemplates[format], fullName, format);
18
+ return filename;
19
+ }
20
+ async prepareMigration(initialSchema, newSchema, migrationName, { skipInitialSchemaValidation = false } = {}) {
21
+ await this.migrationFilesManager.createDirIfNotExist();
22
+ const modifications = this.schemaDiffer.diffSchemas(initialSchema, newSchema, { skipInitialSchemaValidation });
23
+ if (modifications.length === 0) {
24
+ return null;
25
+ }
26
+ const migration = this.createMigration(modifications, migrationName);
27
+ return { initialSchema, migration };
28
+ }
29
+ async saveMigration(migration) {
30
+ const jsonDiff = MigrationCreator.createContent(migration);
31
+ const filename = await this.migrationFilesManager.createFile(jsonDiff, migration.name);
32
+ return filename;
33
+ }
34
+ async removeMigration(name) {
35
+ await this.migrationFilesManager.removeFile(name);
36
+ }
37
+ createMigration(modifications, name) {
38
+ const [version, fullName] = engineCommon.MigrationVersionHelper.createVersion(name);
39
+ return { formatVersion: schemaMigrations.VERSION_LATEST, modifications, version, name: fullName };
40
+ }
41
+ static createContent({ modifications, formatVersion }) {
42
+ return JSON.stringify({ formatVersion, modifications }, void 0, " ") + "\n";
43
+ }
44
+ }
45
+ exports.MigrationCreator = MigrationCreator;
46
+ //# sourceMappingURL=MigrationCreator.cjs.map
@@ -0,0 +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;;"}
@@ -0,0 +1,46 @@
1
+ import { VERSION_LATEST } from "@contember/schema-migrations";
2
+ import { MigrationVersionHelper } from "@contember/engine-common";
3
+ class MigrationCreator {
4
+ constructor(migrationFilesManager, schemaDiffer, emptyTemplates = {}) {
5
+ this.migrationFilesManager = migrationFilesManager;
6
+ this.schemaDiffer = schemaDiffer;
7
+ this.emptyTemplates = emptyTemplates;
8
+ }
9
+ async createEmptyMigrationFile(migrationName, format) {
10
+ if (!this.emptyTemplates.hasOwnProperty(format)) {
11
+ throw new Error(`Unknown format ${format}`);
12
+ }
13
+ await this.migrationFilesManager.createDirIfNotExist();
14
+ const [, fullName] = MigrationVersionHelper.createVersion(migrationName);
15
+ const filename = await this.migrationFilesManager.createFile(this.emptyTemplates[format], fullName, format);
16
+ return filename;
17
+ }
18
+ async prepareMigration(initialSchema, newSchema, migrationName, { skipInitialSchemaValidation = false } = {}) {
19
+ await this.migrationFilesManager.createDirIfNotExist();
20
+ const modifications = this.schemaDiffer.diffSchemas(initialSchema, newSchema, { skipInitialSchemaValidation });
21
+ if (modifications.length === 0) {
22
+ return null;
23
+ }
24
+ const migration = this.createMigration(modifications, migrationName);
25
+ return { initialSchema, migration };
26
+ }
27
+ async saveMigration(migration) {
28
+ const jsonDiff = MigrationCreator.createContent(migration);
29
+ const filename = await this.migrationFilesManager.createFile(jsonDiff, migration.name);
30
+ return filename;
31
+ }
32
+ async removeMigration(name) {
33
+ await this.migrationFilesManager.removeFile(name);
34
+ }
35
+ createMigration(modifications, name) {
36
+ const [version, fullName] = MigrationVersionHelper.createVersion(name);
37
+ return { formatVersion: VERSION_LATEST, modifications, version, name: fullName };
38
+ }
39
+ static createContent({ modifications, formatVersion }) {
40
+ return JSON.stringify({ formatVersion, modifications }, void 0, " ") + "\n";
41
+ }
42
+ }
43
+ export {
44
+ MigrationCreator
45
+ };
46
+ //# sourceMappingURL=MigrationCreator.js.map
@@ -0,0 +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;"}
@@ -0,0 +1,71 @@
1
+ "use strict";
2
+ Object.defineProperty(exports, Symbol.toStringTag, { value: "Module" });
3
+ const assertNever = require("./utils/assertNever.cjs");
4
+ class MigrationExecutor {
5
+ async executeMigrations({
6
+ client,
7
+ migrations,
8
+ contentMigrationFactoryArgs,
9
+ force,
10
+ log = () => null
11
+ }) {
12
+ if (migrations.length === 0) {
13
+ return;
14
+ }
15
+ let migrationsToRun = [];
16
+ const executeMigrations = async () => {
17
+ if (migrationsToRun.length === 0) {
18
+ return;
19
+ }
20
+ await client.migrate(
21
+ migrationsToRun.map((it) => {
22
+ if (it.type === "schema") {
23
+ return {
24
+ version: it.version,
25
+ name: it.name,
26
+ type: "SCHEMA",
27
+ schemaMigration: {
28
+ formatVersion: it.formatVersion,
29
+ modifications: it.modifications,
30
+ skippedErrors: it.skippedErrors
31
+ }
32
+ };
33
+ }
34
+ if (it.type === "content") {
35
+ return {
36
+ version: it.version,
37
+ name: it.name,
38
+ type: "CONTENT",
39
+ contentMigration: it.queries
40
+ };
41
+ }
42
+ return assertNever.assertNever();
43
+ }),
44
+ force
45
+ );
46
+ migrationsToRun.forEach((it) => {
47
+ log(it.name);
48
+ });
49
+ migrationsToRun = [];
50
+ };
51
+ log("Executing...");
52
+ for (const migration of migrations) {
53
+ const migrationContent = await migration.localMigration.getContent();
54
+ if (migrationContent.type === "factory") {
55
+ await executeMigrations();
56
+ const result = await migrationContent.factory({
57
+ ...contentMigrationFactoryArgs,
58
+ migration: migration.localMigration
59
+ });
60
+ migrationsToRun.push(result);
61
+ await executeMigrations();
62
+ } else {
63
+ migrationsToRun.push(migrationContent);
64
+ }
65
+ }
66
+ await executeMigrations();
67
+ log("Migration executed");
68
+ }
69
+ }
70
+ exports.MigrationExecutor = MigrationExecutor;
71
+ //# sourceMappingURL=MigrationExecuteHelper.cjs.map
@@ -0,0 +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;;"}
@@ -0,0 +1,71 @@
1
+ import { assertNever } from "./utils/assertNever.js";
2
+ class MigrationExecutor {
3
+ async executeMigrations({
4
+ client,
5
+ migrations,
6
+ contentMigrationFactoryArgs,
7
+ force,
8
+ log = () => null
9
+ }) {
10
+ if (migrations.length === 0) {
11
+ return;
12
+ }
13
+ let migrationsToRun = [];
14
+ const executeMigrations = async () => {
15
+ if (migrationsToRun.length === 0) {
16
+ return;
17
+ }
18
+ await client.migrate(
19
+ migrationsToRun.map((it) => {
20
+ if (it.type === "schema") {
21
+ return {
22
+ version: it.version,
23
+ name: it.name,
24
+ type: "SCHEMA",
25
+ schemaMigration: {
26
+ formatVersion: it.formatVersion,
27
+ modifications: it.modifications,
28
+ skippedErrors: it.skippedErrors
29
+ }
30
+ };
31
+ }
32
+ if (it.type === "content") {
33
+ return {
34
+ version: it.version,
35
+ name: it.name,
36
+ type: "CONTENT",
37
+ contentMigration: it.queries
38
+ };
39
+ }
40
+ return assertNever();
41
+ }),
42
+ force
43
+ );
44
+ migrationsToRun.forEach((it) => {
45
+ log(it.name);
46
+ });
47
+ migrationsToRun = [];
48
+ };
49
+ log("Executing...");
50
+ for (const migration of migrations) {
51
+ const migrationContent = await migration.localMigration.getContent();
52
+ if (migrationContent.type === "factory") {
53
+ await executeMigrations();
54
+ const result = await migrationContent.factory({
55
+ ...contentMigrationFactoryArgs,
56
+ migration: migration.localMigration
57
+ });
58
+ migrationsToRun.push(result);
59
+ await executeMigrations();
60
+ } else {
61
+ migrationsToRun.push(migrationContent);
62
+ }
63
+ }
64
+ await executeMigrations();
65
+ log("Migration executed");
66
+ }
67
+ }
68
+ export {
69
+ MigrationExecutor
70
+ };
71
+ //# sourceMappingURL=MigrationExecuteHelper.js.map
@@ -0,0 +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;"}
@@ -0,0 +1,5 @@
1
+ "use strict";
2
+ Object.defineProperty(exports, Symbol.toStringTag, { value: "Module" });
3
+ const isSchemaMigration = (content) => typeof content !== "function" && "modifications" in content;
4
+ exports.isSchemaMigration = isSchemaMigration;
5
+ //# sourceMappingURL=MigrationFile.cjs.map
@@ -0,0 +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;;"}
@@ -0,0 +1,5 @@
1
+ const isSchemaMigration = (content) => typeof content !== "function" && "modifications" in content;
2
+ export {
3
+ isSchemaMigration
4
+ };
5
+ //# sourceMappingURL=MigrationFile.js.map
@@ -0,0 +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;"}
@@ -0,0 +1,106 @@
1
+ "use strict";
2
+ Object.defineProperty(exports, Symbol.toStringTag, { value: "Module" });
3
+ const engineCommon = require("@contember/engine-common");
4
+ const fs = require("node:fs/promises");
5
+ const node_path = require("node:path");
6
+ function _interopNamespaceDefault(e) {
7
+ const n = Object.create(null, { [Symbol.toStringTag]: { value: "Module" } });
8
+ if (e) {
9
+ for (const k in e) {
10
+ if (k !== "default") {
11
+ const d = Object.getOwnPropertyDescriptor(e, k);
12
+ Object.defineProperty(n, k, d.get ? d : {
13
+ enumerable: true,
14
+ get: () => e[k]
15
+ });
16
+ }
17
+ }
18
+ }
19
+ n.default = e;
20
+ return Object.freeze(n);
21
+ }
22
+ const fs__namespace = /* @__PURE__ */ _interopNamespaceDefault(fs);
23
+ var __defProp = Object.defineProperty;
24
+ var __defNormalProp = (obj, key, value) => key in obj ? __defProp(obj, key, { enumerable: true, configurable: true, writable: true, value }) : obj[key] = value;
25
+ var __publicField = (obj, key, value) => __defNormalProp(obj, key + "", value);
26
+ class MigrationFilesManager {
27
+ constructor(directory, loaders) {
28
+ this.directory = directory;
29
+ this.loaders = loaders;
30
+ __publicField(this, "migrations", null);
31
+ }
32
+ async createFile(content, name, extension = "json") {
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);
37
+ }
38
+ async removeFile(name) {
39
+ this.migrations = null;
40
+ const path = this.formatPath(name);
41
+ await fs__namespace.unlink(path);
42
+ }
43
+ async moveFile(oldName, newName) {
44
+ this.migrations = null;
45
+ await fs__namespace.rename(this.formatPath(oldName), this.formatPath(newName));
46
+ }
47
+ async createDirIfNotExist() {
48
+ try {
49
+ await fs__namespace.mkdir(this.directory);
50
+ } catch (e) {
51
+ if (!(e instanceof Error) || !("code" in e) || e.code !== "EEXIST") {
52
+ throw e;
53
+ }
54
+ }
55
+ }
56
+ async readFiles() {
57
+ return this.migrations ?? (this.migrations = this.forceReadFiles());
58
+ }
59
+ async forceReadFiles() {
60
+ const files = (await this.listFiles()).map((it) => ({
61
+ filename: it,
62
+ version: engineCommon.MigrationVersionHelper.extractVersion(it)
63
+ }));
64
+ return files.map(({ version, filename }) => {
65
+ const ext = filename.substring(filename.lastIndexOf(".") + 1);
66
+ const path = node_path.join(this.directory, filename);
67
+ let content = null;
68
+ const file = {
69
+ path,
70
+ version,
71
+ name: engineCommon.MigrationVersionHelper.extractName(path.substring(path.lastIndexOf("/") + 1)),
72
+ getContent: () => {
73
+ content ?? (content = this.loaders[ext].load(file));
74
+ return content;
75
+ }
76
+ };
77
+ return file;
78
+ });
79
+ }
80
+ async tryReadDir() {
81
+ try {
82
+ return await fs__namespace.readdir(this.directory, { withFileTypes: true });
83
+ } catch (e) {
84
+ if (e instanceof Error && "code" in e && e.code === "ENOENT") {
85
+ return [];
86
+ }
87
+ throw e;
88
+ }
89
+ }
90
+ async listFiles() {
91
+ const files = await this.tryReadDir();
92
+ const extensions = Object.keys(this.loaders).join("|");
93
+ const regex = new RegExp("^\\d{4}-\\d{2}-\\d{2}-\\d{6}-[\\w-]+\\.(" + extensions + ")$");
94
+ const filteredFiles = await Promise.all(
95
+ files.filter((it) => it.isFile()).map((it) => it.name).filter((it) => it.match(regex))
96
+ );
97
+ return filteredFiles.sort();
98
+ }
99
+ formatPath(version, extension = "json") {
100
+ const filename = `${version}.${extension}`;
101
+ const path = `${this.directory}/${filename}`;
102
+ return path;
103
+ }
104
+ }
105
+ exports.MigrationFilesManager = MigrationFilesManager;
106
+ //# sourceMappingURL=MigrationFilesManager.cjs.map