@contember/migrations-client 2.1.0-alpha.37 → 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.
- package/dist/development/index.cjs +53 -0
- package/dist/development/index.cjs.map +1 -0
- package/dist/development/index.js +35 -0
- package/dist/development/index.js.map +1 -0
- package/dist/development/src/JsLoader.cjs +30 -0
- package/dist/development/src/JsLoader.cjs.map +1 -0
- package/dist/development/src/JsLoader.js +30 -0
- package/dist/development/src/JsLoader.js.map +1 -0
- package/dist/development/src/JsonLoader.cjs +33 -0
- package/dist/development/src/JsonLoader.cjs.map +1 -0
- package/dist/development/src/JsonLoader.js +16 -0
- package/dist/development/src/JsonLoader.js.map +1 -0
- package/dist/development/src/MigrationCreator.cjs +46 -0
- package/dist/development/src/MigrationCreator.cjs.map +1 -0
- package/dist/development/src/MigrationCreator.js +46 -0
- package/dist/development/src/MigrationCreator.js.map +1 -0
- package/dist/development/src/MigrationExecuteHelper.cjs +71 -0
- package/dist/development/src/MigrationExecuteHelper.cjs.map +1 -0
- package/dist/development/src/MigrationExecuteHelper.js +71 -0
- package/dist/development/src/MigrationExecuteHelper.js.map +1 -0
- package/dist/development/src/MigrationFile.cjs +5 -0
- package/dist/development/src/MigrationFile.cjs.map +1 -0
- package/dist/development/src/MigrationFile.js +5 -0
- package/dist/development/src/MigrationFile.js.map +1 -0
- package/dist/development/src/MigrationFilesManager.cjs +106 -0
- package/dist/development/src/MigrationFilesManager.cjs.map +1 -0
- package/dist/development/src/MigrationFilesManager.js +89 -0
- package/dist/development/src/MigrationFilesManager.js.map +1 -0
- package/dist/development/src/MigrationParser.cjs +31 -0
- package/dist/development/src/MigrationParser.cjs.map +1 -0
- package/dist/development/src/MigrationParser.js +31 -0
- package/dist/development/src/MigrationParser.js.map +1 -0
- package/dist/development/src/MigrationsResolver.cjs +34 -0
- package/dist/development/src/MigrationsResolver.cjs.map +1 -0
- package/dist/development/src/MigrationsResolver.js +34 -0
- package/dist/development/src/MigrationsResolver.js.map +1 -0
- package/dist/development/src/SchemaVersionBuilder.cjs +26 -0
- package/dist/development/src/SchemaVersionBuilder.cjs.map +1 -0
- package/dist/development/src/SchemaVersionBuilder.js +26 -0
- package/dist/development/src/SchemaVersionBuilder.js.map +1 -0
- package/dist/development/src/SystemClient.cjs +117 -0
- package/dist/development/src/SystemClient.cjs.map +1 -0
- package/dist/development/src/SystemClient.js +117 -0
- package/dist/development/src/SystemClient.js.map +1 -0
- package/dist/development/src/migrations.cjs +108 -0
- package/dist/development/src/migrations.cjs.map +1 -0
- package/dist/development/src/migrations.js +108 -0
- package/dist/development/src/migrations.js.map +1 -0
- package/dist/development/src/utils/assertNever.cjs +7 -0
- package/dist/development/src/utils/assertNever.cjs.map +1 -0
- package/dist/development/src/utils/assertNever.js +7 -0
- package/dist/development/src/utils/assertNever.js.map +1 -0
- package/dist/production/index.cjs +53 -0
- package/dist/production/index.cjs.map +1 -0
- package/dist/production/index.js +35 -0
- package/dist/production/index.js.map +1 -0
- package/dist/production/src/JsLoader.cjs +30 -0
- package/dist/production/src/JsLoader.cjs.map +1 -0
- package/dist/production/src/JsLoader.js +30 -0
- package/dist/production/src/JsLoader.js.map +1 -0
- package/dist/production/src/JsonLoader.cjs +33 -0
- package/dist/production/src/JsonLoader.cjs.map +1 -0
- package/dist/production/src/JsonLoader.js +16 -0
- package/dist/production/src/JsonLoader.js.map +1 -0
- package/dist/production/src/MigrationCreator.cjs +46 -0
- package/dist/production/src/MigrationCreator.cjs.map +1 -0
- package/dist/production/src/MigrationCreator.js +46 -0
- package/dist/production/src/MigrationCreator.js.map +1 -0
- package/dist/production/src/MigrationExecuteHelper.cjs +71 -0
- package/dist/production/src/MigrationExecuteHelper.cjs.map +1 -0
- package/dist/production/src/MigrationExecuteHelper.js +71 -0
- package/dist/production/src/MigrationExecuteHelper.js.map +1 -0
- package/dist/production/src/MigrationFile.cjs +5 -0
- package/dist/production/src/MigrationFile.cjs.map +1 -0
- package/dist/production/src/MigrationFile.js +5 -0
- package/dist/production/src/MigrationFile.js.map +1 -0
- package/dist/production/src/MigrationFilesManager.cjs +106 -0
- package/dist/production/src/MigrationFilesManager.cjs.map +1 -0
- package/dist/production/src/MigrationFilesManager.js +89 -0
- package/dist/production/src/MigrationFilesManager.js.map +1 -0
- package/dist/production/src/MigrationParser.cjs +31 -0
- package/dist/production/src/MigrationParser.cjs.map +1 -0
- package/dist/production/src/MigrationParser.js +31 -0
- package/dist/production/src/MigrationParser.js.map +1 -0
- package/dist/production/src/MigrationsResolver.cjs +34 -0
- package/dist/production/src/MigrationsResolver.cjs.map +1 -0
- package/dist/production/src/MigrationsResolver.js +34 -0
- package/dist/production/src/MigrationsResolver.js.map +1 -0
- package/dist/production/src/SchemaVersionBuilder.cjs +26 -0
- package/dist/production/src/SchemaVersionBuilder.cjs.map +1 -0
- package/dist/production/src/SchemaVersionBuilder.js +26 -0
- package/dist/production/src/SchemaVersionBuilder.js.map +1 -0
- package/dist/production/src/SystemClient.cjs +117 -0
- package/dist/production/src/SystemClient.cjs.map +1 -0
- package/dist/production/src/SystemClient.js +117 -0
- package/dist/production/src/SystemClient.js.map +1 -0
- package/dist/production/src/migrations.cjs +108 -0
- package/dist/production/src/migrations.cjs.map +1 -0
- package/dist/production/src/migrations.js +108 -0
- package/dist/production/src/migrations.js.map +1 -0
- package/dist/production/src/utils/assertNever.cjs +7 -0
- package/dist/production/src/utils/assertNever.cjs.map +1 -0
- package/dist/production/src/utils/assertNever.js +7 -0
- package/dist/production/src/utils/assertNever.js.map +1 -0
- package/dist/types/JsLoader.d.ts +10 -0
- package/dist/types/JsLoader.d.ts.map +1 -0
- package/dist/types/JsonLoader.d.ts +9 -0
- package/dist/types/JsonLoader.d.ts.map +1 -0
- package/dist/types/MigrationCreator.d.ts +21 -0
- package/dist/types/MigrationCreator.d.ts.map +1 -0
- package/dist/types/MigrationExecuteHelper.d.ts +13 -0
- package/dist/types/MigrationExecuteHelper.d.ts.map +1 -0
- package/dist/types/MigrationFile.d.ts +39 -0
- package/dist/types/MigrationFile.d.ts.map +1 -0
- package/dist/types/MigrationFileLoader.d.ts +5 -0
- package/dist/types/MigrationFileLoader.d.ts.map +1 -0
- package/dist/types/MigrationFilesManager.d.ts +18 -0
- package/dist/types/MigrationFilesManager.d.ts.map +1 -0
- package/dist/types/MigrationParser.d.ts +6 -0
- package/dist/types/MigrationParser.d.ts.map +1 -0
- package/dist/types/MigrationsResolver.d.ts +14 -0
- package/dist/types/MigrationsResolver.d.ts.map +1 -0
- package/dist/types/SchemaVersionBuilder.d.ts +13 -0
- package/dist/types/SchemaVersionBuilder.d.ts.map +1 -0
- package/dist/types/SystemClient.d.ts +29 -0
- package/dist/types/SystemClient.d.ts.map +1 -0
- package/dist/types/index.d.ts +15 -0
- package/dist/types/index.d.ts.map +1 -0
- package/dist/types/migrations.d.ts +60 -0
- package/dist/types/migrations.d.ts.map +1 -0
- package/dist/types/tsconfig.tsbuildinfo +1 -0
- package/dist/types/utils/assertNever.d.ts +2 -0
- package/dist/types/utils/assertNever.d.ts.map +1 -0
- package/dist/types/utils/json.d.ts +7 -0
- package/dist/types/utils/json.d.ts.map +1 -0
- package/package.json +7 -7
|
@@ -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,S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6C,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,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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
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"SchemaVersionBuilder.js","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":[],"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,oBAAoB,aAAa,aAAW,CAAC,iBAAiB,WAAW,aAAa;AAAA,EACnG;AAAA,EAEA,MAAM,iBAAiB,eAAwC;AAC9D,WAAO,KAAK,oBAAoB,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,117 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
Object.defineProperty(exports, Symbol.toStringTag, { value: "Module" });
|
|
3
|
+
const graphqlClient = require("@contember/graphql-client");
|
|
4
|
+
var MigrateErrorCode = /* @__PURE__ */ ((MigrateErrorCode2) => {
|
|
5
|
+
MigrateErrorCode2["MustFollowLatest"] = "MUST_FOLLOW_LATEST";
|
|
6
|
+
MigrateErrorCode2["AlreadyExecuted"] = "ALREADY_EXECUTED";
|
|
7
|
+
MigrateErrorCode2["InvalidFormat"] = "INVALID_FORMAT";
|
|
8
|
+
MigrateErrorCode2["InvalidSchema"] = "INVALID_SCHEMA";
|
|
9
|
+
MigrateErrorCode2["MigrationFailed"] = "MIGRATION_FAILED";
|
|
10
|
+
return MigrateErrorCode2;
|
|
11
|
+
})(MigrateErrorCode || {});
|
|
12
|
+
class SystemClient {
|
|
13
|
+
constructor(apiClient) {
|
|
14
|
+
this.apiClient = apiClient;
|
|
15
|
+
}
|
|
16
|
+
static create(baseUrl, projectName, apiToken) {
|
|
17
|
+
const graphqlClient$1 = new graphqlClient.GraphQlClient({ url: createSystemUrl(baseUrl, projectName), apiToken });
|
|
18
|
+
return new SystemClient(graphqlClient$1);
|
|
19
|
+
}
|
|
20
|
+
async migrate(migrations, force = false) {
|
|
21
|
+
const query = `
|
|
22
|
+
mutation($migrations: [Migration!]!) {
|
|
23
|
+
migrate: ${force ? "forceMigrate" : "migrate"}(migrations: $migrations) {
|
|
24
|
+
ok
|
|
25
|
+
errors {
|
|
26
|
+
code
|
|
27
|
+
migration
|
|
28
|
+
message: developerMessage
|
|
29
|
+
}
|
|
30
|
+
}
|
|
31
|
+
}
|
|
32
|
+
`;
|
|
33
|
+
const result = (await this.apiClient.execute(query, {
|
|
34
|
+
variables: {
|
|
35
|
+
migrations
|
|
36
|
+
}
|
|
37
|
+
})).migrate;
|
|
38
|
+
if (!result.ok) {
|
|
39
|
+
throw result.errors;
|
|
40
|
+
}
|
|
41
|
+
}
|
|
42
|
+
async migrationDelete(version) {
|
|
43
|
+
const query = `
|
|
44
|
+
mutation($version: String!) {
|
|
45
|
+
migrationDelete(migration: $version) {
|
|
46
|
+
ok
|
|
47
|
+
error {
|
|
48
|
+
developerMessage
|
|
49
|
+
}
|
|
50
|
+
}
|
|
51
|
+
}
|
|
52
|
+
`;
|
|
53
|
+
const result = (await this.apiClient.execute(query, {
|
|
54
|
+
variables: {
|
|
55
|
+
version
|
|
56
|
+
}
|
|
57
|
+
})).migrationDelete;
|
|
58
|
+
if (!result.ok) {
|
|
59
|
+
throw result.error?.developerMessage;
|
|
60
|
+
}
|
|
61
|
+
}
|
|
62
|
+
async migrationModify(version, modification) {
|
|
63
|
+
const query = `
|
|
64
|
+
mutation($version: String!, $modification: MigrationModification!) {
|
|
65
|
+
migrationModify(migration: $version, modification: $modification) {
|
|
66
|
+
ok
|
|
67
|
+
error {
|
|
68
|
+
developerMessage
|
|
69
|
+
}
|
|
70
|
+
}
|
|
71
|
+
}
|
|
72
|
+
`;
|
|
73
|
+
const result = (await this.apiClient.execute(query, {
|
|
74
|
+
variables: {
|
|
75
|
+
version,
|
|
76
|
+
modification
|
|
77
|
+
}
|
|
78
|
+
})).migrationModify;
|
|
79
|
+
if (!result.ok) {
|
|
80
|
+
throw result.error?.developerMessage;
|
|
81
|
+
}
|
|
82
|
+
}
|
|
83
|
+
async listExecutedMigrations() {
|
|
84
|
+
const query = `query {
|
|
85
|
+
executedMigrations {
|
|
86
|
+
name
|
|
87
|
+
version
|
|
88
|
+
formatVersion
|
|
89
|
+
checksum
|
|
90
|
+
executedAt
|
|
91
|
+
}
|
|
92
|
+
}`;
|
|
93
|
+
return (await this.apiClient.execute(query, {})).executedMigrations.map((it) => ({ ...it, executedAt: new Date(it.executedAt) }));
|
|
94
|
+
}
|
|
95
|
+
async getExecutedMigration(version) {
|
|
96
|
+
const query = `query($version: String!) {
|
|
97
|
+
executedMigrations(version: $version) {
|
|
98
|
+
name
|
|
99
|
+
version
|
|
100
|
+
formatVersion
|
|
101
|
+
checksum
|
|
102
|
+
executedAt
|
|
103
|
+
modifications
|
|
104
|
+
}
|
|
105
|
+
}`;
|
|
106
|
+
return (await this.apiClient.execute(query, { variables: { version } })).executedMigrations.map((it) => ({ ...it, executedAt: new Date(it.executedAt) }))[0] || null;
|
|
107
|
+
}
|
|
108
|
+
}
|
|
109
|
+
const createSystemUrl = (baseUrl, projectName) => {
|
|
110
|
+
if (baseUrl.endsWith("/")) {
|
|
111
|
+
baseUrl = baseUrl.substring(0, baseUrl.length - 1);
|
|
112
|
+
}
|
|
113
|
+
return baseUrl + "/system/" + projectName;
|
|
114
|
+
};
|
|
115
|
+
exports.MigrateErrorCode = MigrateErrorCode;
|
|
116
|
+
exports.SystemClient = SystemClient;
|
|
117
|
+
//# sourceMappingURL=SystemClient.cjs.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"SystemClient.cjs","sources":["../../../../packages/migrations-client/src/SystemClient.ts"],"sourcesContent":["import { GraphQlClient } from '@contember/graphql-client'\nimport { ExecutedMigration, ExecutedMigrationInfo } from './migrations'\n\nexport type MigrateError = {\n\treadonly code: MigrateErrorCode\n\treadonly migration: string\n\treadonly message: string\n}\n\nexport enum MigrateErrorCode {\n\tMustFollowLatest = 'MUST_FOLLOW_LATEST',\n\tAlreadyExecuted = 'ALREADY_EXECUTED',\n\tInvalidFormat = 'INVALID_FORMAT',\n\tInvalidSchema = 'INVALID_SCHEMA',\n\tMigrationFailed = 'MIGRATION_FAILED',\n}\n\nexport type MigrateResponse = {\n\treadonly ok: boolean\n\treadonly errors: MigrateError[]\n}\n\nexport class SystemClient {\n\tconstructor(private readonly apiClient: GraphQlClient) {}\n\n\tpublic static create(baseUrl: string, projectName: string, apiToken: string): SystemClient {\n\t\tconst graphqlClient = new GraphQlClient({ url: createSystemUrl(baseUrl, projectName), apiToken })\n\t\treturn new SystemClient(graphqlClient)\n\t}\n\n\tpublic async migrate(migrations: any[], force = false): Promise<void> {\n\t\tconst query = `\nmutation($migrations: [Migration!]!) {\n\tmigrate: ${force ? 'forceMigrate' : 'migrate'}(migrations: $migrations) {\n\t\tok\n\t\terrors {\n\t\t\tcode\n\t\t\tmigration\n\t\t\tmessage: developerMessage\n\t\t}\n\t}\n}\n`\n\t\tconst result = (\n\t\t\tawait this.apiClient.execute<{\n\t\t\t\tmigrate: { ok: boolean; errors: { code: MigrateErrorCode; migration: string; message: string }[] }\n\t\t\t}>(query, {\n\t\t\t\tvariables: {\n\t\t\t\t\tmigrations,\n\t\t\t\t},\n\t\t\t})\n\t\t).migrate\n\t\tif (!result.ok) {\n\t\t\tthrow result.errors\n\t\t}\n\t}\n\n\tpublic async migrationDelete(version: string): Promise<void> {\n\t\tconst query = `\nmutation($version: String!) {\n\tmigrationDelete(migration: $version) {\n\t\tok\n\t\terror {\n\t\t\tdeveloperMessage\n\t\t}\n\t}\n}\n`\n\t\tconst result = (\n\t\t\tawait this.apiClient.execute<{\n\t\t\t\tmigrationDelete: { ok: boolean; error?: { developerMessage: string } }\n\t\t\t}>(query, {\n\t\t\t\tvariables: {\n\t\t\t\t\tversion,\n\t\t\t\t},\n\t\t\t})\n\t\t).migrationDelete\n\t\tif (!result.ok) {\n\t\t\tthrow result.error?.developerMessage\n\t\t}\n\t}\n\n\tpublic async migrationModify(version: string, modification: Partial<any>): Promise<void> {\n\t\tconst query = `\nmutation($version: String!, $modification: MigrationModification!) {\n\tmigrationModify(migration: $version, modification: $modification) {\n\t\tok\n\t\terror {\n\t\t\tdeveloperMessage\n\t\t}\n\t}\n}\n`\n\t\tconst result = (\n\t\t\tawait this.apiClient.execute<{\n\t\t\t\tmigrationModify: { ok: boolean; error?: { developerMessage: string } }\n\t\t\t}>(query, {\n\t\t\t\tvariables: {\n\t\t\t\t\tversion,\n\t\t\t\t\tmodification,\n\t\t\t\t},\n\t\t\t})\n\t\t).migrationModify\n\t\tif (!result.ok) {\n\t\t\tthrow result.error?.developerMessage\n\t\t}\n\t}\n\n\tpublic async listExecutedMigrations(): Promise<ExecutedMigrationInfo[]> {\n\t\tconst query = `query {\n\texecutedMigrations {\n\t\tname\n\t\tversion\n\t\tformatVersion\n\t\tchecksum\n\t\texecutedAt\n\t}\n}`\n\t\treturn (\n\t\t\tawait this.apiClient.execute<{\n\t\t\t\texecutedMigrations: ExecutedMigrationInfo[]\n\t\t\t}>(query, {})\n\t\t).executedMigrations.map(it => ({ ...it, executedAt: new Date(it.executedAt) }))\n\t}\n\n\tpublic async getExecutedMigration(version: string): Promise<ExecutedMigration> {\n\t\tconst query = `query($version: String!) {\n\texecutedMigrations(version: $version) {\n\t\tname\n\t\tversion\n\t\tformatVersion\n\t\tchecksum\n\t\texecutedAt\n\t\tmodifications\n\t}\n}`\n\t\treturn (\n\t\t\t(\n\t\t\t\tawait this.apiClient.execute<{\n\t\t\t\t\texecutedMigrations: ExecutedMigration[]\n\t\t\t\t}>(query, { variables: { version } })\n\t\t\t).executedMigrations.map(it => ({ ...it, executedAt: new Date(it.executedAt) }))[0] || null\n\t\t)\n\t}\n}\n\nconst createSystemUrl = (baseUrl: string, projectName: string) => {\n\tif (baseUrl.endsWith('/')) {\n\t\tbaseUrl = baseUrl.substring(0, baseUrl.length - 1)\n\t}\n\treturn baseUrl + '/system/' + projectName\n}\n"],"names":["MigrateErrorCode","graphqlClient","GraphQlClient"],"mappings":";;;AASO,IAAK,qCAAAA,sBAAL;AACNA,oBAAA,kBAAA,IAAmB;AACnBA,oBAAA,iBAAA,IAAkB;AAClBA,oBAAA,eAAA,IAAgB;AAChBA,oBAAA,eAAA,IAAgB;AAChBA,oBAAA,iBAAA,IAAkB;AALP,SAAAA;AAAA,GAAA,oBAAA,CAAA,CAAA;AAaL,MAAM,aAAa;AAAA,EACzB,YAA6B,WAA0B;AAA1B,SAAA,YAAA;AAAA,EAA2B;AAAA,EAExD,OAAc,OAAO,SAAiB,aAAqB,UAAgC;AAC1F,UAAMC,kBAAgB,IAAIC,cAAAA,cAAc,EAAE,KAAK,gBAAgB,SAAS,WAAW,GAAG,UAAU;AAChG,WAAO,IAAI,aAAaD,eAAa;AAAA,EACtC;AAAA,EAEA,MAAa,QAAQ,YAAmB,QAAQ,OAAsB;AACrE,UAAM,QAAQ;AAAA;AAAA,YAEJ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OAAO,EAAE,WAAW,EAAE,UAAQ,CAAG,GACnC,mBAAmB,IAAI,CAAA,QAAO,EAAE,GAAG,IAAI,YAAY,IAAI,KAAK,GAAG,UAAU,EAAA,EAAI,EAAE,CAAC,KAAK;AAAA,EAEzF;AACD;AAEA,MAAM,kBAAkB,CAAC,SAAiB,gBAAwB;AACjE,MAAI,QAAQ,SAAS,GAAG,GAAG;AAC1B,cAAU,QAAQ,UAAU,GAAG,QAAQ,SAAS,CAAC;AAAA,EAClD;AACA,SAAO,UAAU,aAAa;AAC/B;;;"}
|
|
@@ -0,0 +1,117 @@
|
|
|
1
|
+
import { GraphQlClient } from "@contember/graphql-client";
|
|
2
|
+
var MigrateErrorCode = /* @__PURE__ */ ((MigrateErrorCode2) => {
|
|
3
|
+
MigrateErrorCode2["MustFollowLatest"] = "MUST_FOLLOW_LATEST";
|
|
4
|
+
MigrateErrorCode2["AlreadyExecuted"] = "ALREADY_EXECUTED";
|
|
5
|
+
MigrateErrorCode2["InvalidFormat"] = "INVALID_FORMAT";
|
|
6
|
+
MigrateErrorCode2["InvalidSchema"] = "INVALID_SCHEMA";
|
|
7
|
+
MigrateErrorCode2["MigrationFailed"] = "MIGRATION_FAILED";
|
|
8
|
+
return MigrateErrorCode2;
|
|
9
|
+
})(MigrateErrorCode || {});
|
|
10
|
+
class SystemClient {
|
|
11
|
+
constructor(apiClient) {
|
|
12
|
+
this.apiClient = apiClient;
|
|
13
|
+
}
|
|
14
|
+
static create(baseUrl, projectName, apiToken) {
|
|
15
|
+
const graphqlClient = new GraphQlClient({ url: createSystemUrl(baseUrl, projectName), apiToken });
|
|
16
|
+
return new SystemClient(graphqlClient);
|
|
17
|
+
}
|
|
18
|
+
async migrate(migrations, force = false) {
|
|
19
|
+
const query = `
|
|
20
|
+
mutation($migrations: [Migration!]!) {
|
|
21
|
+
migrate: ${force ? "forceMigrate" : "migrate"}(migrations: $migrations) {
|
|
22
|
+
ok
|
|
23
|
+
errors {
|
|
24
|
+
code
|
|
25
|
+
migration
|
|
26
|
+
message: developerMessage
|
|
27
|
+
}
|
|
28
|
+
}
|
|
29
|
+
}
|
|
30
|
+
`;
|
|
31
|
+
const result = (await this.apiClient.execute(query, {
|
|
32
|
+
variables: {
|
|
33
|
+
migrations
|
|
34
|
+
}
|
|
35
|
+
})).migrate;
|
|
36
|
+
if (!result.ok) {
|
|
37
|
+
throw result.errors;
|
|
38
|
+
}
|
|
39
|
+
}
|
|
40
|
+
async migrationDelete(version) {
|
|
41
|
+
const query = `
|
|
42
|
+
mutation($version: String!) {
|
|
43
|
+
migrationDelete(migration: $version) {
|
|
44
|
+
ok
|
|
45
|
+
error {
|
|
46
|
+
developerMessage
|
|
47
|
+
}
|
|
48
|
+
}
|
|
49
|
+
}
|
|
50
|
+
`;
|
|
51
|
+
const result = (await this.apiClient.execute(query, {
|
|
52
|
+
variables: {
|
|
53
|
+
version
|
|
54
|
+
}
|
|
55
|
+
})).migrationDelete;
|
|
56
|
+
if (!result.ok) {
|
|
57
|
+
throw result.error?.developerMessage;
|
|
58
|
+
}
|
|
59
|
+
}
|
|
60
|
+
async migrationModify(version, modification) {
|
|
61
|
+
const query = `
|
|
62
|
+
mutation($version: String!, $modification: MigrationModification!) {
|
|
63
|
+
migrationModify(migration: $version, modification: $modification) {
|
|
64
|
+
ok
|
|
65
|
+
error {
|
|
66
|
+
developerMessage
|
|
67
|
+
}
|
|
68
|
+
}
|
|
69
|
+
}
|
|
70
|
+
`;
|
|
71
|
+
const result = (await this.apiClient.execute(query, {
|
|
72
|
+
variables: {
|
|
73
|
+
version,
|
|
74
|
+
modification
|
|
75
|
+
}
|
|
76
|
+
})).migrationModify;
|
|
77
|
+
if (!result.ok) {
|
|
78
|
+
throw result.error?.developerMessage;
|
|
79
|
+
}
|
|
80
|
+
}
|
|
81
|
+
async listExecutedMigrations() {
|
|
82
|
+
const query = `query {
|
|
83
|
+
executedMigrations {
|
|
84
|
+
name
|
|
85
|
+
version
|
|
86
|
+
formatVersion
|
|
87
|
+
checksum
|
|
88
|
+
executedAt
|
|
89
|
+
}
|
|
90
|
+
}`;
|
|
91
|
+
return (await this.apiClient.execute(query, {})).executedMigrations.map((it) => ({ ...it, executedAt: new Date(it.executedAt) }));
|
|
92
|
+
}
|
|
93
|
+
async getExecutedMigration(version) {
|
|
94
|
+
const query = `query($version: String!) {
|
|
95
|
+
executedMigrations(version: $version) {
|
|
96
|
+
name
|
|
97
|
+
version
|
|
98
|
+
formatVersion
|
|
99
|
+
checksum
|
|
100
|
+
executedAt
|
|
101
|
+
modifications
|
|
102
|
+
}
|
|
103
|
+
}`;
|
|
104
|
+
return (await this.apiClient.execute(query, { variables: { version } })).executedMigrations.map((it) => ({ ...it, executedAt: new Date(it.executedAt) }))[0] || null;
|
|
105
|
+
}
|
|
106
|
+
}
|
|
107
|
+
const createSystemUrl = (baseUrl, projectName) => {
|
|
108
|
+
if (baseUrl.endsWith("/")) {
|
|
109
|
+
baseUrl = baseUrl.substring(0, baseUrl.length - 1);
|
|
110
|
+
}
|
|
111
|
+
return baseUrl + "/system/" + projectName;
|
|
112
|
+
};
|
|
113
|
+
export {
|
|
114
|
+
MigrateErrorCode,
|
|
115
|
+
SystemClient
|
|
116
|
+
};
|
|
117
|
+
//# sourceMappingURL=SystemClient.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"SystemClient.js","sources":["../../../../packages/migrations-client/src/SystemClient.ts"],"sourcesContent":["import { GraphQlClient } from '@contember/graphql-client'\nimport { ExecutedMigration, ExecutedMigrationInfo } from './migrations'\n\nexport type MigrateError = {\n\treadonly code: MigrateErrorCode\n\treadonly migration: string\n\treadonly message: string\n}\n\nexport enum MigrateErrorCode {\n\tMustFollowLatest = 'MUST_FOLLOW_LATEST',\n\tAlreadyExecuted = 'ALREADY_EXECUTED',\n\tInvalidFormat = 'INVALID_FORMAT',\n\tInvalidSchema = 'INVALID_SCHEMA',\n\tMigrationFailed = 'MIGRATION_FAILED',\n}\n\nexport type MigrateResponse = {\n\treadonly ok: boolean\n\treadonly errors: MigrateError[]\n}\n\nexport class SystemClient {\n\tconstructor(private readonly apiClient: GraphQlClient) {}\n\n\tpublic static create(baseUrl: string, projectName: string, apiToken: string): SystemClient {\n\t\tconst graphqlClient = new GraphQlClient({ url: createSystemUrl(baseUrl, projectName), apiToken })\n\t\treturn new SystemClient(graphqlClient)\n\t}\n\n\tpublic async migrate(migrations: any[], force = false): Promise<void> {\n\t\tconst query = `\nmutation($migrations: [Migration!]!) {\n\tmigrate: ${force ? 'forceMigrate' : 'migrate'}(migrations: $migrations) {\n\t\tok\n\t\terrors {\n\t\t\tcode\n\t\t\tmigration\n\t\t\tmessage: developerMessage\n\t\t}\n\t}\n}\n`\n\t\tconst result = (\n\t\t\tawait this.apiClient.execute<{\n\t\t\t\tmigrate: { ok: boolean; errors: { code: MigrateErrorCode; migration: string; message: string }[] }\n\t\t\t}>(query, {\n\t\t\t\tvariables: {\n\t\t\t\t\tmigrations,\n\t\t\t\t},\n\t\t\t})\n\t\t).migrate\n\t\tif (!result.ok) {\n\t\t\tthrow result.errors\n\t\t}\n\t}\n\n\tpublic async migrationDelete(version: string): Promise<void> {\n\t\tconst query = `\nmutation($version: String!) {\n\tmigrationDelete(migration: $version) {\n\t\tok\n\t\terror {\n\t\t\tdeveloperMessage\n\t\t}\n\t}\n}\n`\n\t\tconst result = (\n\t\t\tawait this.apiClient.execute<{\n\t\t\t\tmigrationDelete: { ok: boolean; error?: { developerMessage: string } }\n\t\t\t}>(query, {\n\t\t\t\tvariables: {\n\t\t\t\t\tversion,\n\t\t\t\t},\n\t\t\t})\n\t\t).migrationDelete\n\t\tif (!result.ok) {\n\t\t\tthrow result.error?.developerMessage\n\t\t}\n\t}\n\n\tpublic async migrationModify(version: string, modification: Partial<any>): Promise<void> {\n\t\tconst query = `\nmutation($version: String!, $modification: MigrationModification!) {\n\tmigrationModify(migration: $version, modification: $modification) {\n\t\tok\n\t\terror {\n\t\t\tdeveloperMessage\n\t\t}\n\t}\n}\n`\n\t\tconst result = (\n\t\t\tawait this.apiClient.execute<{\n\t\t\t\tmigrationModify: { ok: boolean; error?: { developerMessage: string } }\n\t\t\t}>(query, {\n\t\t\t\tvariables: {\n\t\t\t\t\tversion,\n\t\t\t\t\tmodification,\n\t\t\t\t},\n\t\t\t})\n\t\t).migrationModify\n\t\tif (!result.ok) {\n\t\t\tthrow result.error?.developerMessage\n\t\t}\n\t}\n\n\tpublic async listExecutedMigrations(): Promise<ExecutedMigrationInfo[]> {\n\t\tconst query = `query {\n\texecutedMigrations {\n\t\tname\n\t\tversion\n\t\tformatVersion\n\t\tchecksum\n\t\texecutedAt\n\t}\n}`\n\t\treturn (\n\t\t\tawait this.apiClient.execute<{\n\t\t\t\texecutedMigrations: ExecutedMigrationInfo[]\n\t\t\t}>(query, {})\n\t\t).executedMigrations.map(it => ({ ...it, executedAt: new Date(it.executedAt) }))\n\t}\n\n\tpublic async getExecutedMigration(version: string): Promise<ExecutedMigration> {\n\t\tconst query = `query($version: String!) {\n\texecutedMigrations(version: $version) {\n\t\tname\n\t\tversion\n\t\tformatVersion\n\t\tchecksum\n\t\texecutedAt\n\t\tmodifications\n\t}\n}`\n\t\treturn (\n\t\t\t(\n\t\t\t\tawait this.apiClient.execute<{\n\t\t\t\t\texecutedMigrations: ExecutedMigration[]\n\t\t\t\t}>(query, { variables: { version } })\n\t\t\t).executedMigrations.map(it => ({ ...it, executedAt: new Date(it.executedAt) }))[0] || null\n\t\t)\n\t}\n}\n\nconst createSystemUrl = (baseUrl: string, projectName: string) => {\n\tif (baseUrl.endsWith('/')) {\n\t\tbaseUrl = baseUrl.substring(0, baseUrl.length - 1)\n\t}\n\treturn baseUrl + '/system/' + projectName\n}\n"],"names":["MigrateErrorCode"],"mappings":";AASO,IAAK,qCAAAA,sBAAL;AACNA,oBAAA,kBAAA,IAAmB;AACnBA,oBAAA,iBAAA,IAAkB;AAClBA,oBAAA,eAAA,IAAgB;AAChBA,oBAAA,eAAA,IAAgB;AAChBA,oBAA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