@contember/migrations-client 2.1.0-alpha.3 → 2.1.0-alpha.35
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/package.json +13 -8
- package/src/JsLoader.ts +3 -9
- package/src/MigrationExecuteHelper.ts +5 -4
- package/src/MigrationFile.ts +5 -2
- package/src/MigrationFilesManager.ts +1 -1
- package/src/MigrationsResolver.ts +1 -4
- package/src/SchemaVersionBuilder.ts +1 -2
- package/src/index.ts +2 -5
- package/src/migrations.ts +20 -7
- package/dist/development/index.cjs +0 -53
- package/dist/development/index.cjs.map +0 -1
- package/dist/development/index.js +0 -35
- package/dist/development/index.js.map +0 -1
- package/dist/development/src/JsLoader.cjs +0 -30
- package/dist/development/src/JsLoader.cjs.map +0 -1
- package/dist/development/src/JsLoader.js +0 -30
- package/dist/development/src/JsLoader.js.map +0 -1
- package/dist/development/src/JsonLoader.cjs +0 -33
- package/dist/development/src/JsonLoader.cjs.map +0 -1
- package/dist/development/src/JsonLoader.js +0 -16
- package/dist/development/src/JsonLoader.js.map +0 -1
- package/dist/development/src/MigrationCreator.cjs +0 -46
- package/dist/development/src/MigrationCreator.cjs.map +0 -1
- package/dist/development/src/MigrationCreator.js +0 -46
- package/dist/development/src/MigrationCreator.js.map +0 -1
- package/dist/development/src/MigrationExecuteHelper.cjs +0 -68
- package/dist/development/src/MigrationExecuteHelper.cjs.map +0 -1
- package/dist/development/src/MigrationExecuteHelper.js +0 -68
- package/dist/development/src/MigrationExecuteHelper.js.map +0 -1
- package/dist/development/src/MigrationFile.cjs +0 -5
- package/dist/development/src/MigrationFile.cjs.map +0 -1
- package/dist/development/src/MigrationFile.js +0 -5
- package/dist/development/src/MigrationFile.js.map +0 -1
- package/dist/development/src/MigrationFilesManager.cjs +0 -106
- package/dist/development/src/MigrationFilesManager.cjs.map +0 -1
- package/dist/development/src/MigrationFilesManager.js +0 -89
- package/dist/development/src/MigrationFilesManager.js.map +0 -1
- package/dist/development/src/MigrationParser.cjs +0 -31
- package/dist/development/src/MigrationParser.cjs.map +0 -1
- package/dist/development/src/MigrationParser.js +0 -31
- package/dist/development/src/MigrationParser.js.map +0 -1
- package/dist/development/src/MigrationsResolver.cjs +0 -36
- package/dist/development/src/MigrationsResolver.cjs.map +0 -1
- package/dist/development/src/MigrationsResolver.js +0 -36
- package/dist/development/src/MigrationsResolver.js.map +0 -1
- package/dist/development/src/SchemaVersionBuilder.cjs +0 -26
- package/dist/development/src/SchemaVersionBuilder.cjs.map +0 -1
- package/dist/development/src/SchemaVersionBuilder.js +0 -26
- package/dist/development/src/SchemaVersionBuilder.js.map +0 -1
- package/dist/development/src/SystemClient.cjs +0 -117
- package/dist/development/src/SystemClient.cjs.map +0 -1
- package/dist/development/src/SystemClient.js +0 -117
- package/dist/development/src/SystemClient.js.map +0 -1
- package/dist/development/src/migrations.cjs +0 -97
- package/dist/development/src/migrations.cjs.map +0 -1
- package/dist/development/src/migrations.js +0 -97
- package/dist/development/src/migrations.js.map +0 -1
- package/dist/development/src/utils/assertNever.cjs +0 -7
- package/dist/development/src/utils/assertNever.cjs.map +0 -1
- package/dist/development/src/utils/assertNever.js +0 -7
- package/dist/development/src/utils/assertNever.js.map +0 -1
- package/dist/production/index.cjs +0 -53
- package/dist/production/index.cjs.map +0 -1
- package/dist/production/index.js +0 -35
- package/dist/production/index.js.map +0 -1
- package/dist/production/src/JsLoader.cjs +0 -30
- package/dist/production/src/JsLoader.cjs.map +0 -1
- package/dist/production/src/JsLoader.js +0 -30
- package/dist/production/src/JsLoader.js.map +0 -1
- package/dist/production/src/JsonLoader.cjs +0 -33
- package/dist/production/src/JsonLoader.cjs.map +0 -1
- package/dist/production/src/JsonLoader.js +0 -16
- package/dist/production/src/JsonLoader.js.map +0 -1
- package/dist/production/src/MigrationCreator.cjs +0 -46
- package/dist/production/src/MigrationCreator.cjs.map +0 -1
- package/dist/production/src/MigrationCreator.js +0 -46
- package/dist/production/src/MigrationCreator.js.map +0 -1
- package/dist/production/src/MigrationExecuteHelper.cjs +0 -68
- package/dist/production/src/MigrationExecuteHelper.cjs.map +0 -1
- package/dist/production/src/MigrationExecuteHelper.js +0 -68
- package/dist/production/src/MigrationExecuteHelper.js.map +0 -1
- package/dist/production/src/MigrationFile.cjs +0 -5
- package/dist/production/src/MigrationFile.cjs.map +0 -1
- package/dist/production/src/MigrationFile.js +0 -5
- package/dist/production/src/MigrationFile.js.map +0 -1
- package/dist/production/src/MigrationFilesManager.cjs +0 -106
- package/dist/production/src/MigrationFilesManager.cjs.map +0 -1
- package/dist/production/src/MigrationFilesManager.js +0 -89
- package/dist/production/src/MigrationFilesManager.js.map +0 -1
- package/dist/production/src/MigrationParser.cjs +0 -31
- package/dist/production/src/MigrationParser.cjs.map +0 -1
- package/dist/production/src/MigrationParser.js +0 -31
- package/dist/production/src/MigrationParser.js.map +0 -1
- package/dist/production/src/MigrationsResolver.cjs +0 -36
- package/dist/production/src/MigrationsResolver.cjs.map +0 -1
- package/dist/production/src/MigrationsResolver.js +0 -36
- package/dist/production/src/MigrationsResolver.js.map +0 -1
- package/dist/production/src/SchemaVersionBuilder.cjs +0 -26
- package/dist/production/src/SchemaVersionBuilder.cjs.map +0 -1
- package/dist/production/src/SchemaVersionBuilder.js +0 -26
- package/dist/production/src/SchemaVersionBuilder.js.map +0 -1
- package/dist/production/src/SystemClient.cjs +0 -117
- package/dist/production/src/SystemClient.cjs.map +0 -1
- package/dist/production/src/SystemClient.js +0 -117
- package/dist/production/src/SystemClient.js.map +0 -1
- package/dist/production/src/migrations.cjs +0 -97
- package/dist/production/src/migrations.cjs.map +0 -1
- package/dist/production/src/migrations.js +0 -97
- package/dist/production/src/migrations.js.map +0 -1
- package/dist/production/src/utils/assertNever.cjs +0 -7
- package/dist/production/src/utils/assertNever.cjs.map +0 -1
- package/dist/production/src/utils/assertNever.js +0 -7
- package/dist/production/src/utils/assertNever.js.map +0 -1
- package/dist/types/JsLoader.d.ts +0 -10
- package/dist/types/JsLoader.d.ts.map +0 -1
- package/dist/types/JsonLoader.d.ts +0 -9
- package/dist/types/JsonLoader.d.ts.map +0 -1
- package/dist/types/MigrationCreator.d.ts +0 -21
- package/dist/types/MigrationCreator.d.ts.map +0 -1
- package/dist/types/MigrationExecuteHelper.d.ts +0 -13
- package/dist/types/MigrationExecuteHelper.d.ts.map +0 -1
- package/dist/types/MigrationFile.d.ts +0 -36
- package/dist/types/MigrationFile.d.ts.map +0 -1
- package/dist/types/MigrationFileLoader.d.ts +0 -5
- package/dist/types/MigrationFileLoader.d.ts.map +0 -1
- package/dist/types/MigrationFilesManager.d.ts +0 -18
- package/dist/types/MigrationFilesManager.d.ts.map +0 -1
- package/dist/types/MigrationParser.d.ts +0 -6
- package/dist/types/MigrationParser.d.ts.map +0 -1
- package/dist/types/MigrationsResolver.d.ts +0 -14
- package/dist/types/MigrationsResolver.d.ts.map +0 -1
- package/dist/types/SchemaVersionBuilder.d.ts +0 -13
- package/dist/types/SchemaVersionBuilder.d.ts.map +0 -1
- package/dist/types/SystemClient.d.ts +0 -29
- package/dist/types/SystemClient.d.ts.map +0 -1
- package/dist/types/index.d.ts +0 -15
- package/dist/types/index.d.ts.map +0 -1
- package/dist/types/migrations.d.ts +0 -56
- package/dist/types/migrations.d.ts.map +0 -1
- package/dist/types/tsconfig.tsbuildinfo +0 -1
- package/dist/types/utils/assertNever.d.ts +0 -2
- package/dist/types/utils/assertNever.d.ts.map +0 -1
- package/dist/types/utils/json.d.ts +0 -7
- package/dist/types/utils/json.d.ts.map +0 -1
|
@@ -1,30 +0,0 @@
|
|
|
1
|
-
class JsLoader {
|
|
2
|
-
constructor(migrationParser, jsExecutor) {
|
|
3
|
-
this.migrationParser = migrationParser;
|
|
4
|
-
this.jsExecutor = jsExecutor;
|
|
5
|
-
}
|
|
6
|
-
async load(file) {
|
|
7
|
-
const exports = await this.jsExecutor(file.path);
|
|
8
|
-
if (!("default" in exports) && !("query" in exports) && !("queries" in exports)) {
|
|
9
|
-
throw `export "default" or "query" is required in ${file.path}`;
|
|
10
|
-
}
|
|
11
|
-
if (typeof exports.default !== "function") {
|
|
12
|
-
return this.migrationParser.parse(file, exports.default || exports);
|
|
13
|
-
}
|
|
14
|
-
return {
|
|
15
|
-
type: "factory",
|
|
16
|
-
factory: async () => {
|
|
17
|
-
const result = await exports.default();
|
|
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
|
|
@@ -1 +0,0 @@
|
|
|
1
|
-
{"version":3,"file":"JsLoader.js","sources":["../../../../packages/migrations-client/src/JsLoader.ts"],"sourcesContent":["import { MigrationFileLoader } from './MigrationFileLoader'\nimport { MigrationParser } from './MigrationParser'\nimport { ContentMigration, 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\n\tpublic async load(file: MigrationFile): Promise<MigrationContent> {\n\n\t\t// const code = await buildJs(file.path)\n\t\t// const fn = new Function(`var module = {}; ((module) => { ${code} })(module); return module`)\n\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 (): Promise<ContentMigration> => {\n\t\t\t\tconst result = await exports.default()\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\n\t\t}\n\t}\n}\n"],"names":[],"mappings":"AAIO,MAAM,SAAwC;AAAA,EACpD,YACkB,iBACA,YAChB;AAFgB,SAAA,kBAAA;AACA,SAAA,aAAA;AAAA,EAAA;AAAA,EAKlB,MAAa,KAAK,MAAgD;AAKjE,UAAM,UAAU,MAAM,KAAK,WAAW,KAAK,IAAI;AAC3C,QAAA,EAAE,aAAa,YAAY,EAAE,WAAW,YAAY,EAAE,aAAa,UAAU;AAC1E,YAAA,8CAA8C,KAAK,IAAI;AAAA,IAAA;AAE1D,QAAA,OAAO,QAAQ,YAAY,YAAY;AAC1C,aAAO,KAAK,gBAAgB,MAAM,MAAM,QAAQ,WAAW,OAAO;AAAA,IAAA;AAG5D,WAAA;AAAA,MACN,MAAM;AAAA,MACN,SAAS,YAAuC;AACzC,cAAA,SAAS,MAAM,QAAQ,QAAQ;AAC/B,cAAA,YAAY,KAAK,gBAAgB,MAAM,MAAM,UAAU,EAAE,SAAS,CAAA,GAAI;AACxE,YAAA,UAAU,SAAS,WAAW;AACjC,gBAAM,IAAI,MAAM;AAAA,QAAA;AAEV,eAAA;AAAA,MAAA;AAAA,IAGT;AAAA,EAAA;AAEF;"}
|
|
@@ -1,33 +0,0 @@
|
|
|
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
|
|
@@ -1 +0,0 @@
|
|
|
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,EAAA;AAAA,EAIlB,MAAa,KAAK,MAAqB;AACtC,WAAO,KAAK,gBAAgB;AAAA,MAC3B;AAAA,MACA,KAAK,MAAM,MAAMA,cAAG,SAAS,KAAK,MAAM,EAAE,UAAU,QAAQ,CAAC;AAAA,IAC9D;AAAA,EAAA;AAEF;;"}
|
|
@@ -1,16 +0,0 @@
|
|
|
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
|
|
@@ -1 +0,0 @@
|
|
|
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,EAAA;AAAA,EAIlB,MAAa,KAAK,MAAqB;AACtC,WAAO,KAAK,gBAAgB;AAAA,MAC3B;AAAA,MACA,KAAK,MAAM,MAAM,GAAG,SAAS,KAAK,MAAM,EAAE,UAAU,QAAQ,CAAC;AAAA,IAC9D;AAAA,EAAA;AAEF;"}
|
|
@@ -1,46 +0,0 @@
|
|
|
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
|
|
@@ -1 +0,0 @@
|
|
|
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,EAAA;AAAA,EAGlB,MAAM,yBAAyB,eAAuB,QAAiC;AACtF,QAAI,CAAC,KAAK,eAAe,eAAe,MAAM,GAAG;AAChD,YAAM,IAAI,MAAM,kBAAkB,MAAM,EAAE;AAAA,IAAA;AAErC,UAAA,KAAK,sBAAsB,oBAAoB;AACrD,UAAM,CAAG,EAAA,QAAQ,IAAIA,oCAAuB,cAAc,aAAa;AACjE,UAAA,WAAW,MAAM,KAAK,sBAAsB,WAAW,KAAK,eAAe,MAAM,GAAG,UAAU,MAAM;AAEnG,WAAA;AAAA,EAAA;AAAA,EAGR,MAAM,iBACL,eACA,WACA,eACA,EAAE,8BAA8B,MAAqD,IAAA,IACnB;AAC5D,UAAA,KAAK,sBAAsB,oBAAoB;AAE/C,UAAA,gBAAgB,KAAK,aAAa,YAAY,eAAe,WAAW,EAAE,6BAA6B;AACzG,QAAA,cAAc,WAAW,GAAG;AACxB,aAAA;AAAA,IAAA;AAGR,UAAM,YAAY,KAAK,gBAAgB,eAAe,aAAa;AAE5D,WAAA,EAAE,eAAe,UAAU;AAAA,EAAA;AAAA,EAGnC,MAAM,cAAc,WAAuC;AACpD,UAAA,WAAW,iBAAiB,cAAc,SAAS;AACzD,UAAM,WAAW,MAAM,KAAK,sBAAsB,WAAW,UAAU,UAAU,IAAI;AAC9E,WAAA;AAAA,EAAA;AAAA,EAGR,MAAM,gBAAgB,MAA6B;AAC5C,UAAA,KAAK,sBAAsB,WAAW,IAAI;AAAA,EAAA;AAAA,EAGzC,gBAAgB,eAAyC,MAAyB;AACzF,UAAM,CAAC,SAAS,QAAQ,IAAIA,aAAAA,uBAAuB,cAAc,IAAI;AACrE,WAAO,EAAE,eAAeC,iBAAA,gBAAgB,eAAe,SAAS,MAAM,SAAS;AAAA,EAAA;AAAA,EAGhF,OAAc,cAAc,EAAE,eAAe,iBAAoC;AACzE,WAAA,KAAK,UAAU,EAAE,eAAe,iBAAiB,QAAW,GAAI,IAAI;AAAA,EAAA;AAE7E;;"}
|
|
@@ -1,46 +0,0 @@
|
|
|
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
|
|
@@ -1 +0,0 @@
|
|
|
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,i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AAe,iBAAiB,QAAW,GAAI,IAAI;AAAA,EAAA;AAE7E;"}
|
|
@@ -1,68 +0,0 @@
|
|
|
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(contentMigrationFactoryArgs);
|
|
57
|
-
migrationsToRun.push(result);
|
|
58
|
-
await executeMigrations();
|
|
59
|
-
} else {
|
|
60
|
-
migrationsToRun.push(migrationContent);
|
|
61
|
-
}
|
|
62
|
-
}
|
|
63
|
-
await executeMigrations();
|
|
64
|
-
log("Migration executed");
|
|
65
|
-
}
|
|
66
|
-
}
|
|
67
|
-
exports.MigrationExecutor = MigrationExecutor;
|
|
68
|
-
//# sourceMappingURL=MigrationExecuteHelper.cjs.map
|
|
@@ -1 +0,0 @@
|
|
|
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\n\nexport class MigrationExecutor {\n\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: ContentMigrationFactoryArgs\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(contentMigrationFactoryArgs)\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":";;;AAMO,MAAM,kBAAkB;AAAA,EAE9B,MAAM,kBAAkB;AAAA,IACvB;AAAA,IACA;AAAA,IACA;AAAA,IACA;AAAA,IACA,MAAM,MAAM;AAAA,EAAA,GAOK;AACb,QAAA,WAAW,WAAW,GAAG;AAC5B;AAAA,IAAA;AAED,QAAI,kBAA8C,CAAC;AAEnD,UAAM,oBAAoB,YAAY;AACjC,UAAA,gBAAgB,WAAW,GAAG;AACjC;AAAA,MAAA;AAED,YAAM,OAAO;AAAA,QACZ,gBAAgB,IAAI,CAAM,OAAA;AACrB,cAAA,GAAG,SAAS,UAAU;AAClB,mBAAA;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,YAEpB;AAAA,UAAA;AAEG,cAAA,GAAG,SAAS,WAAW;AACnB,mBAAA;AAAA,cACN,SAAS,GAAG;AAAA,cACZ,MAAM,GAAG;AAAA,cACT,MAAM;AAAA,cACN,kBAAkB,GAAG;AAAA,YACtB;AAAA,UAAA;AAED,iBAAOA,wBAAc;AAAA,QAAA,CACrB;AAAA,QACD;AAAA,MACD;AACA,sBAAgB,QAAQ,CAAM,OAAA;AAC7B,YAAI,GAAG,IAAI;AAAA,MAAA,CACX;AACD,wBAAkB,CAAC;AAAA,IACpB;AAEA,QAAI,cAAc;AAElB,eAAW,aAAa,YAAY;AACnC,YAAM,mBAAmB,MAAM,UAAU,eAAe,WAAW;AAC/D,UAAA,iBAAiB,SAAS,WAAW;AACxC,cAAM,kBAAkB;AACxB,cAAM,SAAS,MAAM,iBAAiB,QAAQ,2BAA2B;AACzE,wBAAgB,KAAK,MAAM;AAC3B,cAAM,kBAAkB;AAAA,MAAA,OAClB;AACN,wBAAgB,KAAK,gBAAgB;AAAA,MAAA;AAAA,IACtC;AAED,UAAM,kBAAkB;AACxB,QAAI,oBAAoB;AAAA,EAAA;AAE1B;;"}
|
|
@@ -1,68 +0,0 @@
|
|
|
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(contentMigrationFactoryArgs);
|
|
55
|
-
migrationsToRun.push(result);
|
|
56
|
-
await executeMigrations();
|
|
57
|
-
} else {
|
|
58
|
-
migrationsToRun.push(migrationContent);
|
|
59
|
-
}
|
|
60
|
-
}
|
|
61
|
-
await executeMigrations();
|
|
62
|
-
log("Migration executed");
|
|
63
|
-
}
|
|
64
|
-
}
|
|
65
|
-
export {
|
|
66
|
-
MigrationExecutor
|
|
67
|
-
};
|
|
68
|
-
//# sourceMappingURL=MigrationExecuteHelper.js.map
|
|
@@ -1 +0,0 @@
|
|
|
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\n\nexport class MigrationExecutor {\n\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: ContentMigrationFactoryArgs\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(contentMigrationFactoryArgs)\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":";AAMO,MAAM,kBAAkB;AAAA,EAE9B,MAAM,kBAAkB;AAAA,IACvB;AAAA,IACA;AAAA,IACA;AAAA,IACA;AAAA,IACA,MAAM,MAAM;AAAA,EAAA,GAOK;AACb,QAAA,WAAW,WAAW,GAAG;AAC5B;AAAA,IAAA;AAED,QAAI,kBAA8C,CAAC;AAEnD,UAAM,oBAAoB,YAAY;AACjC,UAAA,gBAAgB,WAAW,GAAG;AACjC;AAAA,MAAA;AAED,YAAM,OAAO;AAAA,QACZ,gBAAgB,IAAI,CAAM,OAAA;AACrB,cAAA,GAAG,SAAS,UAAU;AAClB,mBAAA;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,YAEpB;AAAA,UAAA;AAEG,cAAA,GAAG,SAAS,WAAW;AACnB,mBAAA;AAAA,cACN,SAAS,GAAG;AAAA,cACZ,MAAM,GAAG;AAAA,cACT,MAAM;AAAA,cACN,kBAAkB,GAAG;AAAA,YACtB;AAAA,UAAA;AAED,iBAAO,YAAc;AAAA,QAAA,CACrB;AAAA,QACD;AAAA,MACD;AACA,sBAAgB,QAAQ,CAAM,OAAA;AAC7B,YAAI,GAAG,IAAI;AAAA,MAAA,CACX;AACD,wBAAkB,CAAC;AAAA,IACpB;AAEA,QAAI,cAAc;AAElB,eAAW,aAAa,YAAY;AACnC,YAAM,mBAAmB,MAAM,UAAU,eAAe,WAAW;AAC/D,UAAA,iBAAiB,SAAS,WAAW;AACxC,cAAM,kBAAkB;AACxB,cAAM,SAAS,MAAM,iBAAiB,QAAQ,2BAA2B;AACzE,wBAAgB,KAAK,MAAM;AAC3B,cAAM,kBAAkB;AAAA,MAAA,OAClB;AACN,wBAAgB,KAAK,gBAAgB;AAAA,MAAA;AAAA,IACtC;AAED,UAAM,kBAAkB;AACxB,QAAI,oBAAoB;AAAA,EAAA;AAE1B;"}
|
|
@@ -1,5 +0,0 @@
|
|
|
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
|
|
@@ -1 +0,0 @@
|
|
|
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'\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 => typeof 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}\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\n"],"names":[],"mappings":";;AAWO,MAAM,oBAAoB,CAAC,YAA0D,OAAO,YAAY,cAAc,mBAAmB;;"}
|
|
@@ -1 +0,0 @@
|
|
|
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'\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 => typeof 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}\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\n"],"names":[],"mappings":"AAWO,MAAM,oBAAoB,CAAC,YAA0D,OAAO,YAAY,cAAc,mBAAmB;"}
|
|
@@ -1,106 +0,0 @@
|
|
|
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
|
|
@@ -1 +0,0 @@
|
|
|
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,EAAA;AAAA,EAOtD,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;AAC/C,WAAA,MAAMA,cAAG,SAAS,IAAI;AAAA,EAAA;AAAA,EAG9B,MAAa,WAAW,MAAc;AACrC,SAAK,aAAa;AACZ,UAAA,OAAO,KAAK,WAAW,IAAI;AAC3B,UAAAA,cAAG,OAAO,IAAI;AAAA,EAAA;AAAA,EAGrB,MAAa,SAAS,SAAiB,SAAiB;AACvD,SAAK,aAAa;AACZ,UAAAA,cAAG,OAAO,KAAK,WAAW,OAAO,GAAG,KAAK,WAAW,OAAO,CAAC;AAAA,EAAA;AAAA,EAGnE,MAAa,sBAAqC;AAC7C,QAAA;AACG,YAAAA,cAAG,MAAM,KAAK,SAAS;AAAA,aACrB,GAAG;AACP,UAAA,EAAE,aAAa,UAAU,EAAE,UAAU,MAAO,EAAU,SAAS,UAAU;AACtE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GAAG,OAAA,CAAQ,EACxB,IAAI,CAAM,OAAA,GAAG,IAAI,EACjB,OAAO,QAAM,GAAG,MAAM,KAAK,CAAC;AAAA,IAC/B;AAEA,WAAO,cAAc,KAAK;AAAA,EAAA;AAAA,EAGnB,WAAW,SAAiB,YAAY,QAAgB;AAC/D,UAAM,WAAW,GAAG,OAAO,IAAI,SAAS;AACxC,UAAM,OAAO,GAAG,KAAK,SAAS,IAAI,QAAQ;AACnC,WAAA;AAAA,EAAA;AAET;;"}
|
|
@@ -1,89 +0,0 @@
|
|
|
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
|
|
@@ -1 +0,0 @@
|
|
|
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\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