@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,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
@@ -0,0 +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,MAAa,YAAsC;AAClD,WAAO,KAAK,eAAL,KAAK,aAAe,KAAK;EACjC;AAAA,EAEA,MAAa,iBAA2C;AACvD,UAAM,SAAS,MAAM,KAAK,UAAA,GAAa,IAAI,CAAA,QAAO;AAAA,MACjD,UAAU;AAAA,MACV,SAASC,aAAAA,uBAAuB,eAAe,EAAE;AAAA,IAAA,EAChD;AAEF,WAAO,MAAM,IAAI,CAAC,EAAE,SAAS,eAA8B;AAC1D,YAAM,MAAM,SAAS,UAAU,SAAS,YAAY,GAAG,IAAI,CAAC;AAC5D,YAAM,OAAOC,UAAAA,KAAK,KAAK,WAAW,QAAQ;AAC1C,UAAI,UAA4C;AAChD,YAAM,OAAsB;AAAA,QAC3B;AAAA,QACA;AAAA,QACA,MAAMD,aAAAA,uBAAuB,YAAY,KAAK,UAAU,KAAK,YAAY,GAAG,IAAI,CAAC,CAAC;AAAA,QAClF,YAAY,MAAM;AACjB,sBAAA,UAAY,KAAK,QAAQ,GAAG,EAAE,KAAK,IAAI;AACvC,iBAAO;AAAA,QACR;AAAA,MAAA;AAED,aAAO;AAAA,IACR,CAAC;AAAA,EACF;AAAA,EAEA,MAAc,aAAgC;AAC7C,QAAI;AACH,aAAO,MAAMD,cAAG,QAAQ,KAAK,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;;"}
@@ -0,0 +1,89 @@
1
+ import { MigrationVersionHelper } from "@contember/engine-common";
2
+ import * as fs from "node:fs/promises";
3
+ import { join } from "node:path";
4
+ var __defProp = Object.defineProperty;
5
+ var __defNormalProp = (obj, key, value) => key in obj ? __defProp(obj, key, { enumerable: true, configurable: true, writable: true, value }) : obj[key] = value;
6
+ var __publicField = (obj, key, value) => __defNormalProp(obj, key + "", value);
7
+ class MigrationFilesManager {
8
+ constructor(directory, loaders) {
9
+ this.directory = directory;
10
+ this.loaders = loaders;
11
+ __publicField(this, "migrations", null);
12
+ }
13
+ async createFile(content, name, extension = "json") {
14
+ this.migrations = null;
15
+ const path = this.formatPath(name, extension);
16
+ await fs.writeFile(path, content, { encoding: "utf8" });
17
+ return await fs.realpath(path);
18
+ }
19
+ async removeFile(name) {
20
+ this.migrations = null;
21
+ const path = this.formatPath(name);
22
+ await fs.unlink(path);
23
+ }
24
+ async moveFile(oldName, newName) {
25
+ this.migrations = null;
26
+ await fs.rename(this.formatPath(oldName), this.formatPath(newName));
27
+ }
28
+ async createDirIfNotExist() {
29
+ try {
30
+ await fs.mkdir(this.directory);
31
+ } catch (e) {
32
+ if (!(e instanceof Error) || !("code" in e) || e.code !== "EEXIST") {
33
+ throw e;
34
+ }
35
+ }
36
+ }
37
+ async readFiles() {
38
+ return this.migrations ?? (this.migrations = this.forceReadFiles());
39
+ }
40
+ async forceReadFiles() {
41
+ const files = (await this.listFiles()).map((it) => ({
42
+ filename: it,
43
+ version: MigrationVersionHelper.extractVersion(it)
44
+ }));
45
+ return files.map(({ version, filename }) => {
46
+ const ext = filename.substring(filename.lastIndexOf(".") + 1);
47
+ const path = join(this.directory, filename);
48
+ let content = null;
49
+ const file = {
50
+ path,
51
+ version,
52
+ name: MigrationVersionHelper.extractName(path.substring(path.lastIndexOf("/") + 1)),
53
+ getContent: () => {
54
+ content ?? (content = this.loaders[ext].load(file));
55
+ return content;
56
+ }
57
+ };
58
+ return file;
59
+ });
60
+ }
61
+ async tryReadDir() {
62
+ try {
63
+ return await fs.readdir(this.directory, { withFileTypes: true });
64
+ } catch (e) {
65
+ if (e instanceof Error && "code" in e && e.code === "ENOENT") {
66
+ return [];
67
+ }
68
+ throw e;
69
+ }
70
+ }
71
+ async listFiles() {
72
+ const files = await this.tryReadDir();
73
+ const extensions = Object.keys(this.loaders).join("|");
74
+ const regex = new RegExp("^\\d{4}-\\d{2}-\\d{2}-\\d{6}-[\\w-]+\\.(" + extensions + ")$");
75
+ const filteredFiles = await Promise.all(
76
+ files.filter((it) => it.isFile()).map((it) => it.name).filter((it) => it.match(regex))
77
+ );
78
+ return filteredFiles.sort();
79
+ }
80
+ formatPath(version, extension = "json") {
81
+ const filename = `${version}.${extension}`;
82
+ const path = `${this.directory}/${filename}`;
83
+ return path;
84
+ }
85
+ }
86
+ export {
87
+ MigrationFilesManager
88
+ };
89
+ //# sourceMappingURL=MigrationFilesManager.js.map
@@ -0,0 +1 @@
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'\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,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;AAAA,MACP;AAAA,IACD;AAAA,EACD;AAAA,EAEA,MAAa,YAAsC;AAClD,WAAO,KAAK,eAAL,KAAK,aAAe,KAAK;EACjC;AAAA,EAEA,MAAa,iBAA2C;AACvD,UAAM,SAAS,MAAM,KAAK,UAAA,GAAa,IAAI,CAAA,QAAO;AAAA,MACjD,UAAU;AAAA,MACV,SAAS,uBAAuB,eAAe,EAAE;AAAA,IAAA,EAChD;AAEF,WAAO,MAAM,IAAI,CAAC,EAAE,SAAS,eAA8B;AAC1D,YAAM,MAAM,SAAS,UAAU,SAAS,YAAY,GAAG,IAAI,CAAC;AAC5D,YAAM,OAAO,KAAK,KAAK,WAAW,QAAQ;AAC1C,UAAI,UAA4C;AAChD,YAAM,OAAsB;AAAA,QAC3B;AAAA,QACA;AAAA,QACA,MAAM,uBAAuB,YAAY,KAAK,UAAU,KAAK,YAAY,GAAG,IAAI,CAAC,CAAC;AAAA,QAClF,YAAY,MAAM;AACjB,sBAAA,UAAY,KAAK,QAAQ,GAAG,EAAE,KAAK,IAAI;AACvC,iBAAO;AAAA,QACR;AAAA,MAAA;AAED,aAAO;AAAA,IACR,CAAC;AAAA,EACF;AAAA,EAEA,MAAc,aAAgC;AAC7C,QAAI;AACH,aAAO,MAAM,GAAG,QAAQ,KAAK,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;"}
@@ -0,0 +1,31 @@
1
+ "use strict";
2
+ Object.defineProperty(exports, Symbol.toStringTag, { value: "Module" });
3
+ const schemaMigrations = require("@contember/schema-migrations");
4
+ class MigrationParser {
5
+ parse(migrationFile, content) {
6
+ if (typeof content !== "object" || content === null) {
7
+ throw new Error("Invalid migration");
8
+ }
9
+ if ("modifications" in content) {
10
+ const validated = content;
11
+ return {
12
+ type: "schema",
13
+ version: migrationFile.version,
14
+ name: migrationFile.name,
15
+ formatVersion: validated.formatVersion || schemaMigrations.VERSION_INITIAL,
16
+ modifications: validated.modifications,
17
+ ...validated.skippedErrors ? { skippedErrors: validated.skippedErrors } : {}
18
+ };
19
+ } else if ("queries" in content || "query" in content) {
20
+ return {
21
+ type: "content",
22
+ version: migrationFile.version,
23
+ name: migrationFile.name,
24
+ queries: "queries" in content ? content.queries : [content]
25
+ };
26
+ }
27
+ throw new Error("Invalid migration content");
28
+ }
29
+ }
30
+ exports.MigrationParser = MigrationParser;
31
+ //# sourceMappingURL=MigrationParser.cjs.map
@@ -0,0 +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;;"}
@@ -0,0 +1,31 @@
1
+ import { VERSION_INITIAL } from "@contember/schema-migrations";
2
+ class MigrationParser {
3
+ parse(migrationFile, content) {
4
+ if (typeof content !== "object" || content === null) {
5
+ throw new Error("Invalid migration");
6
+ }
7
+ if ("modifications" in content) {
8
+ const validated = content;
9
+ return {
10
+ type: "schema",
11
+ version: migrationFile.version,
12
+ name: migrationFile.name,
13
+ formatVersion: validated.formatVersion || VERSION_INITIAL,
14
+ modifications: validated.modifications,
15
+ ...validated.skippedErrors ? { skippedErrors: validated.skippedErrors } : {}
16
+ };
17
+ } else if ("queries" in content || "query" in content) {
18
+ return {
19
+ type: "content",
20
+ version: migrationFile.version,
21
+ name: migrationFile.name,
22
+ queries: "queries" in content ? content.queries : [content]
23
+ };
24
+ }
25
+ throw new Error("Invalid migration content");
26
+ }
27
+ }
28
+ export {
29
+ MigrationParser
30
+ };
31
+ //# sourceMappingURL=MigrationParser.js.map
@@ -0,0 +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;"}
@@ -0,0 +1,34 @@
1
+ "use strict";
2
+ Object.defineProperty(exports, Symbol.toStringTag, { value: "Module" });
3
+ const MigrationFile = require("./MigrationFile.cjs");
4
+ const engineCommon = require("@contember/engine-common");
5
+ class MigrationsResolver {
6
+ constructor(migrationFilesManager) {
7
+ this.migrationFilesManager = migrationFilesManager;
8
+ }
9
+ get directory() {
10
+ return this.migrationFilesManager.directory;
11
+ }
12
+ async getMigrationFiles() {
13
+ return await this.migrationFilesManager.readFiles();
14
+ }
15
+ async getSchemaMigrations() {
16
+ const migrationFiles = await this.getMigrationFiles();
17
+ const migrations = await Promise.all(migrationFiles.map(this.convertMigrationFileToSchemaMigration));
18
+ return migrations.filter((it) => it !== null);
19
+ }
20
+ async findLatestSchemaMigration() {
21
+ const migrations = await this.getSchemaMigrations();
22
+ return migrations.length > 0 ? migrations[migrations.length - 1] : null;
23
+ }
24
+ async findSchemaMigrationByVersion(version) {
25
+ const migrations = await this.getSchemaMigrations();
26
+ return migrations.find((it) => engineCommon.MigrationVersionHelper.extractVersion(it.version) === engineCommon.MigrationVersionHelper.extractVersion(version)) ?? null;
27
+ }
28
+ async convertMigrationFileToSchemaMigration(file) {
29
+ const result = await file.getContent();
30
+ return MigrationFile.isSchemaMigration(result) ? result : null;
31
+ }
32
+ }
33
+ exports.MigrationsResolver = MigrationsResolver;
34
+ //# sourceMappingURL=MigrationsResolver.cjs.map
@@ -0,0 +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;;"}
@@ -0,0 +1,34 @@
1
+ import { isSchemaMigration } from "./MigrationFile.js";
2
+ import { MigrationVersionHelper } from "@contember/engine-common";
3
+ class MigrationsResolver {
4
+ constructor(migrationFilesManager) {
5
+ this.migrationFilesManager = migrationFilesManager;
6
+ }
7
+ get directory() {
8
+ return this.migrationFilesManager.directory;
9
+ }
10
+ async getMigrationFiles() {
11
+ return await this.migrationFilesManager.readFiles();
12
+ }
13
+ async getSchemaMigrations() {
14
+ const migrationFiles = await this.getMigrationFiles();
15
+ const migrations = await Promise.all(migrationFiles.map(this.convertMigrationFileToSchemaMigration));
16
+ return migrations.filter((it) => it !== null);
17
+ }
18
+ async findLatestSchemaMigration() {
19
+ const migrations = await this.getSchemaMigrations();
20
+ return migrations.length > 0 ? migrations[migrations.length - 1] : null;
21
+ }
22
+ async findSchemaMigrationByVersion(version) {
23
+ const migrations = await this.getSchemaMigrations();
24
+ return migrations.find((it) => MigrationVersionHelper.extractVersion(it.version) === MigrationVersionHelper.extractVersion(version)) ?? null;
25
+ }
26
+ async convertMigrationFileToSchemaMigration(file) {
27
+ const result = await file.getContent();
28
+ return isSchemaMigration(result) ? result : null;
29
+ }
30
+ }
31
+ export {
32
+ MigrationsResolver
33
+ };
34
+ //# sourceMappingURL=MigrationsResolver.js.map
@@ -0,0 +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;"}
@@ -0,0 +1,26 @@
1
+ "use strict";
2
+ Object.defineProperty(exports, Symbol.toStringTag, { value: "Module" });
3
+ const schemaUtils = require("@contember/schema-utils");
4
+ class SchemaVersionBuilder {
5
+ constructor(migrationsResolver, schemaMigrator) {
6
+ this.migrationsResolver = migrationsResolver;
7
+ this.schemaMigrator = schemaMigrator;
8
+ }
9
+ async buildSchema(targetVersion) {
10
+ return this.buildSchemaAdvanced(schemaUtils.emptySchema, (version) => !targetVersion || version <= targetVersion);
11
+ }
12
+ async buildSchemaUntil(targetVersion) {
13
+ return this.buildSchemaAdvanced(schemaUtils.emptySchema, (version) => version < targetVersion);
14
+ }
15
+ async continue(schema, previousVersion, targetVersion) {
16
+ return this.buildSchemaAdvanced(schema, (version) => version <= targetVersion && version > (previousVersion || ""));
17
+ }
18
+ async buildSchemaAdvanced(initialSchema, condition) {
19
+ return (await this.migrationsResolver.getSchemaMigrations()).filter(({ version }) => condition(version)).reduce(
20
+ (schema, { modifications, formatVersion }) => this.schemaMigrator.applyModifications(schema, modifications, formatVersion),
21
+ initialSchema
22
+ );
23
+ }
24
+ }
25
+ exports.SchemaVersionBuilder = SchemaVersionBuilder;
26
+ //# sourceMappingURL=SchemaVersionBuilder.cjs.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"SchemaVersionBuilder.cjs","sources":["../../../../packages/migrations-client/src/SchemaVersionBuilder.ts"],"sourcesContent":["import { Schema } from '@contember/schema'\nimport { emptySchema } from '@contember/schema-utils'\nimport { SchemaMigrator } from '@contember/schema-migrations'\nimport { MigrationsResolver } from './MigrationsResolver'\n\nexport class SchemaVersionBuilder {\n\tconstructor(\n\t\tprivate readonly migrationsResolver: MigrationsResolver,\n\t\tprivate readonly schemaMigrator: SchemaMigrator,\n\t) {}\n\n\tasync buildSchema(targetVersion?: string): Promise<Schema> {\n\t\treturn this.buildSchemaAdvanced(emptySchema, version => !targetVersion || version <= targetVersion)\n\t}\n\n\tasync buildSchemaUntil(targetVersion: string): Promise<Schema> {\n\t\treturn this.buildSchemaAdvanced(emptySchema, version => version < targetVersion)\n\t}\n\n\tasync continue(schema: Schema, previousVersion: string | null, targetVersion: string): Promise<Schema> {\n\t\treturn this.buildSchemaAdvanced(schema, version => version <= targetVersion && version > (previousVersion || ''))\n\t}\n\n\tpublic async buildSchemaAdvanced(initialSchema: Schema, condition: (version: string) => boolean): Promise<Schema> {\n\t\treturn (await this.migrationsResolver.getSchemaMigrations())\n\t\t\t.filter(({ version }) => condition(version))\n\t\t\t.reduce<Schema>(\n\t\t\t\t(schema, { modifications, formatVersion }) => this.schemaMigrator.applyModifications(schema, modifications, formatVersion),\n\t\t\t\tinitialSchema,\n\t\t\t)\n\t}\n}\n"],"names":["emptySchema"],"mappings":";;;AAKO,MAAM,qBAAqB;AAAA,EACjC,YACkB,oBACA,gBAChB;AAFgB,SAAA,qBAAA;AACA,SAAA,iBAAA;AAAA,EACf;AAAA,EAEH,MAAM,YAAY,eAAyC;AAC1D,WAAO,KAAK,oBAAoBA,yBAAa,aAAW,CAAC,iBAAiB,WAAW,aAAa;AAAA,EACnG;AAAA,EAEA,MAAM,iBAAiB,eAAwC;AAC9D,WAAO,KAAK,oBAAoBA,YAAAA,aAAa,CAAA,YAAW,UAAU,aAAa;AAAA,EAChF;AAAA,EAEA,MAAM,SAAS,QAAgB,iBAAgC,eAAwC;AACtG,WAAO,KAAK,oBAAoB,QAAQ,CAAA,YAAW,WAAW,iBAAiB,WAAW,mBAAmB,GAAG;AAAA,EACjH;AAAA,EAEA,MAAa,oBAAoB,eAAuB,WAA0D;AACjH,YAAQ,MAAM,KAAK,mBAAmB,oBAAA,GACpC,OAAO,CAAC,EAAE,QAAA,MAAc,UAAU,OAAO,CAAC,EAC1C;AAAA,MACA,CAAC,QAAQ,EAAE,eAAe,oBAAoB,KAAK,eAAe,mBAAmB,QAAQ,eAAe,aAAa;AAAA,MACzH;AAAA,IAAA;AAAA,EAEH;AACD;;"}
@@ -0,0 +1,26 @@
1
+ import { emptySchema } from "@contember/schema-utils";
2
+ class SchemaVersionBuilder {
3
+ constructor(migrationsResolver, schemaMigrator) {
4
+ this.migrationsResolver = migrationsResolver;
5
+ this.schemaMigrator = schemaMigrator;
6
+ }
7
+ async buildSchema(targetVersion) {
8
+ return this.buildSchemaAdvanced(emptySchema, (version) => !targetVersion || version <= targetVersion);
9
+ }
10
+ async buildSchemaUntil(targetVersion) {
11
+ return this.buildSchemaAdvanced(emptySchema, (version) => version < targetVersion);
12
+ }
13
+ async continue(schema, previousVersion, targetVersion) {
14
+ return this.buildSchemaAdvanced(schema, (version) => version <= targetVersion && version > (previousVersion || ""));
15
+ }
16
+ async buildSchemaAdvanced(initialSchema, condition) {
17
+ return (await this.migrationsResolver.getSchemaMigrations()).filter(({ version }) => condition(version)).reduce(
18
+ (schema, { modifications, formatVersion }) => this.schemaMigrator.applyModifications(schema, modifications, formatVersion),
19
+ initialSchema
20
+ );
21
+ }
22
+ }
23
+ export {
24
+ SchemaVersionBuilder
25
+ };
26
+ //# sourceMappingURL=SchemaVersionBuilder.js.map