@contember/migrations-client 1.4.0-alpha.5

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
Files changed (80) hide show
  1. package/dist/src/JsLoader.d.ts +10 -0
  2. package/dist/src/JsLoader.d.ts.map +1 -0
  3. package/dist/src/JsLoader.js +33 -0
  4. package/dist/src/JsLoader.js.map +1 -0
  5. package/dist/src/JsonLoader.d.ts +9 -0
  6. package/dist/src/JsonLoader.d.ts.map +1 -0
  7. package/dist/src/JsonLoader.js +37 -0
  8. package/dist/src/JsonLoader.js.map +1 -0
  9. package/dist/src/MigrationCreator.d.ts +21 -0
  10. package/dist/src/MigrationCreator.d.ts.map +1 -0
  11. package/dist/src/MigrationCreator.js +47 -0
  12. package/dist/src/MigrationCreator.js.map +1 -0
  13. package/dist/src/MigrationExecuteHelper.d.ts +13 -0
  14. package/dist/src/MigrationExecuteHelper.d.ts.map +1 -0
  15. package/dist/src/MigrationExecuteHelper.js +61 -0
  16. package/dist/src/MigrationExecuteHelper.js.map +1 -0
  17. package/dist/src/MigrationFile.d.ts +36 -0
  18. package/dist/src/MigrationFile.d.ts.map +1 -0
  19. package/dist/src/MigrationFile.js +6 -0
  20. package/dist/src/MigrationFile.js.map +1 -0
  21. package/dist/src/MigrationFileLoader.d.ts +5 -0
  22. package/dist/src/MigrationFileLoader.d.ts.map +1 -0
  23. package/dist/src/MigrationFileLoader.js +3 -0
  24. package/dist/src/MigrationFileLoader.js.map +1 -0
  25. package/dist/src/MigrationFilesManager.d.ts +18 -0
  26. package/dist/src/MigrationFilesManager.d.ts.map +1 -0
  27. package/dist/src/MigrationFilesManager.js +114 -0
  28. package/dist/src/MigrationFilesManager.js.map +1 -0
  29. package/dist/src/MigrationParser.d.ts +6 -0
  30. package/dist/src/MigrationParser.d.ts.map +1 -0
  31. package/dist/src/MigrationParser.js +33 -0
  32. package/dist/src/MigrationParser.js.map +1 -0
  33. package/dist/src/MigrationsResolver.d.ts +14 -0
  34. package/dist/src/MigrationsResolver.d.ts.map +1 -0
  35. package/dist/src/MigrationsResolver.js +37 -0
  36. package/dist/src/MigrationsResolver.js.map +1 -0
  37. package/dist/src/SchemaVersionBuilder.d.ts +13 -0
  38. package/dist/src/SchemaVersionBuilder.d.ts.map +1 -0
  39. package/dist/src/SchemaVersionBuilder.js +26 -0
  40. package/dist/src/SchemaVersionBuilder.js.map +1 -0
  41. package/dist/src/SystemClient.d.ts +29 -0
  42. package/dist/src/SystemClient.d.ts.map +1 -0
  43. package/dist/src/SystemClient.js +117 -0
  44. package/dist/src/SystemClient.js.map +1 -0
  45. package/dist/src/index.d.ts +14 -0
  46. package/dist/src/index.d.ts.map +1 -0
  47. package/dist/src/index.js +37 -0
  48. package/dist/src/index.js.map +1 -0
  49. package/dist/src/migrations.d.ts +56 -0
  50. package/dist/src/migrations.d.ts.map +1 -0
  51. package/dist/src/migrations.js +87 -0
  52. package/dist/src/migrations.js.map +1 -0
  53. package/dist/src/tsconfig.tsbuildinfo +1 -0
  54. package/dist/src/utils/assertNever.d.ts +2 -0
  55. package/dist/src/utils/assertNever.d.ts.map +1 -0
  56. package/dist/src/utils/assertNever.js +8 -0
  57. package/dist/src/utils/assertNever.js.map +1 -0
  58. package/dist/src/utils/json.d.ts +7 -0
  59. package/dist/src/utils/json.d.ts.map +1 -0
  60. package/dist/src/utils/json.js +3 -0
  61. package/dist/src/utils/json.js.map +1 -0
  62. package/package.json +24 -0
  63. package/src/JsLoader.ts +39 -0
  64. package/src/JsonLoader.ts +18 -0
  65. package/src/MigrationCreator.ts +60 -0
  66. package/src/MigrationExecuteHelper.ts +79 -0
  67. package/src/MigrationFile.ts +52 -0
  68. package/src/MigrationFileLoader.ts +5 -0
  69. package/src/MigrationFilesManager.ts +102 -0
  70. package/src/MigrationParser.ts +32 -0
  71. package/src/MigrationsResolver.ts +44 -0
  72. package/src/SchemaVersionBuilder.ts +33 -0
  73. package/src/SystemClient.ts +150 -0
  74. package/src/index.ts +23 -0
  75. package/src/migrations.ts +157 -0
  76. package/src/tsconfig.json +13 -0
  77. package/src/utils/assertNever.ts +3 -0
  78. package/src/utils/json.ts +4 -0
  79. package/tsconfig.json +5 -0
  80. package/tsconfig.settings.json +3 -0
@@ -0,0 +1,26 @@
1
+ "use strict";
2
+ Object.defineProperty(exports, "__esModule", { value: true });
3
+ exports.SchemaVersionBuilder = void 0;
4
+ const schema_utils_1 = require("@contember/schema-utils");
5
+ class SchemaVersionBuilder {
6
+ constructor(migrationsResolver, schemaMigrator) {
7
+ this.migrationsResolver = migrationsResolver;
8
+ this.schemaMigrator = schemaMigrator;
9
+ }
10
+ async buildSchema(targetVersion) {
11
+ return this.buildSchemaAdvanced(schema_utils_1.emptySchema, version => !targetVersion || version <= targetVersion);
12
+ }
13
+ async buildSchemaUntil(targetVersion) {
14
+ return this.buildSchemaAdvanced(schema_utils_1.emptySchema, version => version < targetVersion);
15
+ }
16
+ async continue(schema, previousVersion, targetVersion) {
17
+ return this.buildSchemaAdvanced(schema, version => version <= targetVersion && version > (previousVersion || ''));
18
+ }
19
+ async buildSchemaAdvanced(initialSchema, condition) {
20
+ return (await this.migrationsResolver.getSchemaMigrations())
21
+ .filter(({ version }) => condition(version))
22
+ .reduce((schema, { modifications, formatVersion }) => this.schemaMigrator.applyModifications(schema, modifications, formatVersion), initialSchema);
23
+ }
24
+ }
25
+ exports.SchemaVersionBuilder = SchemaVersionBuilder;
26
+ //# sourceMappingURL=SchemaVersionBuilder.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"SchemaVersionBuilder.js","sourceRoot":"","sources":["../../src/SchemaVersionBuilder.ts"],"names":[],"mappings":";;;AACA,0DAAqD;AAIrD,MAAa,oBAAoB;IAChC,YACkB,kBAAsC,EACtC,cAA8B;QAD9B,uBAAkB,GAAlB,kBAAkB,CAAoB;QACtC,mBAAc,GAAd,cAAc,CAAgB;IAC7C,CAAC;IAEJ,KAAK,CAAC,WAAW,CAAC,aAAsB;QACvC,OAAO,IAAI,CAAC,mBAAmB,CAAC,0BAAW,EAAE,OAAO,CAAC,EAAE,CAAC,CAAC,aAAa,IAAI,OAAO,IAAI,aAAa,CAAC,CAAA;IACpG,CAAC;IAED,KAAK,CAAC,gBAAgB,CAAC,aAAqB;QAC3C,OAAO,IAAI,CAAC,mBAAmB,CAAC,0BAAW,EAAE,OAAO,CAAC,EAAE,CAAC,OAAO,GAAG,aAAa,CAAC,CAAA;IACjF,CAAC;IAED,KAAK,CAAC,QAAQ,CAAC,MAAc,EAAE,eAA8B,EAAE,aAAqB;QACnF,OAAO,IAAI,CAAC,mBAAmB,CAAC,MAAM,EAAE,OAAO,CAAC,EAAE,CAAC,OAAO,IAAI,aAAa,IAAI,OAAO,GAAG,CAAC,eAAe,IAAI,EAAE,CAAC,CAAC,CAAA;IAClH,CAAC;IAEM,KAAK,CAAC,mBAAmB,CAAC,aAAqB,EAAE,SAAuC;QAC9F,OAAO,CAAC,MAAM,IAAI,CAAC,kBAAkB,CAAC,mBAAmB,EAAE,CAAC;aAC1D,MAAM,CAAC,CAAC,EAAE,OAAO,EAAE,EAAE,EAAE,CAAC,SAAS,CAAC,OAAO,CAAC,CAAC;aAC3C,MAAM,CACN,CAAC,MAAM,EAAE,EAAE,aAAa,EAAE,aAAa,EAAE,EAAE,EAAE,CAC5C,IAAI,CAAC,cAAc,CAAC,kBAAkB,CAAC,MAAM,EAAE,aAAa,EAAE,aAAa,CAAC,EAC7E,aAAa,CACb,CAAA;IACH,CAAC;CACD;AA3BD,oDA2BC"}
@@ -0,0 +1,29 @@
1
+ import { GraphQLClient } from 'graphql-request';
2
+ import { ExecutedMigration, ExecutedMigrationInfo } from './migrations';
3
+ export type MigrateError = {
4
+ readonly code: MigrateErrorCode;
5
+ readonly migration: string;
6
+ readonly message: string;
7
+ };
8
+ export declare enum MigrateErrorCode {
9
+ MustFollowLatest = "MUST_FOLLOW_LATEST",
10
+ AlreadyExecuted = "ALREADY_EXECUTED",
11
+ InvalidFormat = "INVALID_FORMAT",
12
+ InvalidSchema = "INVALID_SCHEMA",
13
+ MigrationFailed = "MIGRATION_FAILED"
14
+ }
15
+ export type MigrateResponse = {
16
+ readonly ok: boolean;
17
+ readonly errors: MigrateError[];
18
+ };
19
+ export declare class SystemClient {
20
+ private readonly apiClient;
21
+ constructor(apiClient: GraphQLClient);
22
+ static create(baseUrl: string, projectName: string, apiToken: string): SystemClient;
23
+ migrate(migrations: any[], force?: boolean): Promise<void>;
24
+ migrationDelete(version: string): Promise<void>;
25
+ migrationModify(version: string, modification: Partial<any>): Promise<void>;
26
+ listExecutedMigrations(): Promise<ExecutedMigrationInfo[]>;
27
+ getExecutedMigration(version: string): Promise<ExecutedMigration>;
28
+ }
29
+ //# sourceMappingURL=SystemClient.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"SystemClient.d.ts","sourceRoot":"","sources":["../../src/SystemClient.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,aAAa,EAAE,MAAM,iBAAiB,CAAA;AAC/C,OAAO,EAAE,iBAAiB,EAAE,qBAAqB,EAAE,MAAM,cAAc,CAAA;AAEvE,MAAM,MAAM,YAAY,GAAG;IAC1B,QAAQ,CAAC,IAAI,EAAE,gBAAgB,CAAA;IAC/B,QAAQ,CAAC,SAAS,EAAE,MAAM,CAAA;IAC1B,QAAQ,CAAC,OAAO,EAAE,MAAM,CAAA;CACxB,CAAA;AAED,oBAAY,gBAAgB;IAC3B,gBAAgB,uBAAuB;IACvC,eAAe,qBAAqB;IACpC,aAAa,mBAAmB;IAChC,aAAa,mBAAmB;IAChC,eAAe,qBAAqB;CACpC;AAED,MAAM,MAAM,eAAe,GAAG;IAC7B,QAAQ,CAAC,EAAE,EAAE,OAAO,CAAA;IACpB,QAAQ,CAAC,MAAM,EAAE,YAAY,EAAE,CAAA;CAC/B,CAAA;AAED,qBAAa,YAAY;IACZ,OAAO,CAAC,QAAQ,CAAC,SAAS;gBAAT,SAAS,EAAE,aAAa;WAEvC,MAAM,CAAC,OAAO,EAAE,MAAM,EAAE,WAAW,EAAE,MAAM,EAAE,QAAQ,EAAE,MAAM,GAAG,YAAY;IAS7E,OAAO,CAAC,UAAU,EAAE,GAAG,EAAE,EAAE,KAAK,UAAQ,GAAG,OAAO,CAAC,IAAI,CAAC;IAyBxD,eAAe,CAAC,OAAO,EAAE,MAAM,GAAG,OAAO,CAAC,IAAI,CAAC;IAuB/C,eAAe,CAAC,OAAO,EAAE,MAAM,EAAE,YAAY,EAAE,OAAO,CAAC,GAAG,CAAC,GAAG,OAAO,CAAC,IAAI,CAAC;IAwB3E,sBAAsB,IAAI,OAAO,CAAC,qBAAqB,EAAE,CAAC;IAiB1D,oBAAoB,CAAC,OAAO,EAAE,MAAM,GAAG,OAAO,CAAC,iBAAiB,CAAC;CAmB9E"}
@@ -0,0 +1,117 @@
1
+ "use strict";
2
+ Object.defineProperty(exports, "__esModule", { value: true });
3
+ exports.SystemClient = exports.MigrateErrorCode = void 0;
4
+ const graphql_request_1 = require("graphql-request");
5
+ var MigrateErrorCode;
6
+ (function (MigrateErrorCode) {
7
+ MigrateErrorCode["MustFollowLatest"] = "MUST_FOLLOW_LATEST";
8
+ MigrateErrorCode["AlreadyExecuted"] = "ALREADY_EXECUTED";
9
+ MigrateErrorCode["InvalidFormat"] = "INVALID_FORMAT";
10
+ MigrateErrorCode["InvalidSchema"] = "INVALID_SCHEMA";
11
+ MigrateErrorCode["MigrationFailed"] = "MIGRATION_FAILED";
12
+ })(MigrateErrorCode || (exports.MigrateErrorCode = MigrateErrorCode = {}));
13
+ class SystemClient {
14
+ constructor(apiClient) {
15
+ this.apiClient = apiClient;
16
+ }
17
+ static create(baseUrl, projectName, apiToken) {
18
+ const graphqlClient = new graphql_request_1.GraphQLClient(createSystemUrl(baseUrl, projectName), {
19
+ headers: {
20
+ Authorization: `Bearer ${apiToken}`,
21
+ },
22
+ });
23
+ return new SystemClient(graphqlClient);
24
+ }
25
+ async migrate(migrations, force = false) {
26
+ const query = `
27
+ mutation($migrations: [Migration!]!) {
28
+ migrate: ${force ? 'forceMigrate' : 'migrate'}(migrations: $migrations) {
29
+ ok
30
+ errors {
31
+ code
32
+ migration
33
+ message: developerMessage
34
+ }
35
+ }
36
+ }
37
+ `;
38
+ const result = (await this.apiClient.request(query, {
39
+ migrations,
40
+ })).migrate;
41
+ if (!result.ok) {
42
+ throw result.errors;
43
+ }
44
+ }
45
+ async migrationDelete(version) {
46
+ var _a;
47
+ const query = `
48
+ mutation($version: String!) {
49
+ migrationDelete(migration: $version) {
50
+ ok
51
+ error {
52
+ developerMessage
53
+ }
54
+ }
55
+ }
56
+ `;
57
+ const result = (await this.apiClient.request(query, {
58
+ version,
59
+ })).migrationDelete;
60
+ if (!result.ok) {
61
+ throw (_a = result.error) === null || _a === void 0 ? void 0 : _a.developerMessage;
62
+ }
63
+ }
64
+ async migrationModify(version, modification) {
65
+ var _a;
66
+ const query = `
67
+ mutation($version: String!, $modification: MigrationModification!) {
68
+ migrationModify(migration: $version, modification: $modification) {
69
+ ok
70
+ error {
71
+ developerMessage
72
+ }
73
+ }
74
+ }
75
+ `;
76
+ const result = (await this.apiClient.request(query, {
77
+ version,
78
+ modification,
79
+ })).migrationModify;
80
+ if (!result.ok) {
81
+ throw (_a = result.error) === null || _a === void 0 ? void 0 : _a.developerMessage;
82
+ }
83
+ }
84
+ async listExecutedMigrations() {
85
+ const query = `query {
86
+ executedMigrations {
87
+ name
88
+ version
89
+ formatVersion
90
+ checksum
91
+ executedAt
92
+ }
93
+ }`;
94
+ return (await this.apiClient.request(query, {})).executedMigrations.map(it => ({ ...it, executedAt: new Date(it.executedAt) }));
95
+ }
96
+ async getExecutedMigration(version) {
97
+ const query = `query($version: String!) {
98
+ executedMigrations(version: $version) {
99
+ name
100
+ version
101
+ formatVersion
102
+ checksum
103
+ executedAt
104
+ modifications
105
+ }
106
+ }`;
107
+ return ((await this.apiClient.request(query, { version })).executedMigrations.map(it => ({ ...it, executedAt: new Date(it.executedAt) }))[0] || null);
108
+ }
109
+ }
110
+ exports.SystemClient = SystemClient;
111
+ const createSystemUrl = (baseUrl, projectName) => {
112
+ if (baseUrl.endsWith('/')) {
113
+ baseUrl = baseUrl.substring(0, baseUrl.length - 1);
114
+ }
115
+ return baseUrl + '/system/' + projectName;
116
+ };
117
+ //# sourceMappingURL=SystemClient.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"SystemClient.js","sourceRoot":"","sources":["../../src/SystemClient.ts"],"names":[],"mappings":";;;AAAA,qDAA+C;AAS/C,IAAY,gBAMX;AAND,WAAY,gBAAgB;IAC3B,2DAAuC,CAAA;IACvC,wDAAoC,CAAA;IACpC,oDAAgC,CAAA;IAChC,oDAAgC,CAAA;IAChC,wDAAoC,CAAA;AACrC,CAAC,EANW,gBAAgB,gCAAhB,gBAAgB,QAM3B;AAOD,MAAa,YAAY;IACxB,YAA6B,SAAwB;QAAxB,cAAS,GAAT,SAAS,CAAe;IAAG,CAAC;IAElD,MAAM,CAAC,MAAM,CAAC,OAAe,EAAE,WAAmB,EAAE,QAAgB;QAC1E,MAAM,aAAa,GAAG,IAAI,+BAAa,CAAC,eAAe,CAAC,OAAO,EAAE,WAAW,CAAC,EAAE;YAC9E,OAAO,EAAE;gBACR,aAAa,EAAE,UAAU,QAAQ,EAAE;aACnC;SACD,CAAC,CAAA;QACF,OAAO,IAAI,YAAY,CAAC,aAAa,CAAC,CAAA;IACvC,CAAC;IAEM,KAAK,CAAC,OAAO,CAAC,UAAiB,EAAE,KAAK,GAAG,KAAK;QACpD,MAAM,KAAK,GAAG;;YAEJ,KAAK,CAAC,CAAC,CAAC,cAAc,CAAC,CAAC,CAAC,SAAS;;;;;;;;;CAS7C,CAAA;QACC,MAAM,MAAM,GAAG,CACd,MAAM,IAAI,CAAC,SAAS,CAAC,OAAO,CAEzB,KAAK,EAAE;YACT,UAAU;SACV,CAAC,CACF,CAAC,OAAO,CAAA;QACT,IAAI,CAAC,MAAM,CAAC,EAAE,EAAE;YACf,MAAM,MAAM,CAAC,MAAM,CAAA;SACnB;I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AAG,CAAC,EAAE,CAAC,EAAE,CAAC,CAAC,EAAE,GAAG,EAAE,EAAE,UAAU,EAAE,IAAI,IAAI,CAAC,EAAE,CAAC,UAAU,CAAC,EAAE,CAAC,CAAC,CAAC,CAAC,CAAC,IAAI,IAAI,CAC3F,CAAA;IACF,CAAC;CACD;AAxHD,oCAwHC;AAED,MAAM,eAAe,GAAG,CAAC,OAAe,EAAE,WAAmB,EAAE,EAAE;IAChE,IAAI,OAAO,CAAC,QAAQ,CAAC,GAAG,CAAC,EAAE;QAC1B,OAAO,GAAG,OAAO,CAAC,SAAS,CAAC,CAAC,EAAE,OAAO,CAAC,MAAM,GAAG,CAAC,CAAC,CAAA;KAClD;IACD,OAAO,OAAO,GAAG,UAAU,GAAG,WAAW,CAAA;AAC1C,CAAC,CAAA"}
@@ -0,0 +1,14 @@
1
+ export { Migration, MigrationDescriber, MigrationInfo, ModificationHandlerFactory, SchemaDiffer, SchemaMigrator, VERSION_LATEST, calculateMigrationChecksum, } from '@contember/schema-migrations';
2
+ export * from './JsLoader';
3
+ export * from './JsonLoader';
4
+ export * from './MigrationCreator';
5
+ export * from './MigrationExecuteHelper';
6
+ export * from './MigrationFile';
7
+ export * from './MigrationFileLoader';
8
+ export * from './MigrationFilesManager';
9
+ export * from './MigrationParser';
10
+ export * from './migrations';
11
+ export * from './MigrationsResolver';
12
+ export * from './SchemaVersionBuilder';
13
+ export * from './SystemClient';
14
+ //# sourceMappingURL=index.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"index.d.ts","sourceRoot":"","sources":["../../src/index.ts"],"names":[],"mappings":"AAAA,OAAO,EACN,SAAS,EACT,kBAAkB,EAClB,aAAa,EACb,0BAA0B,EAC1B,YAAY,EACZ,cAAc,EACd,cAAc,EACd,0BAA0B,GAC1B,MAAM,8BAA8B,CAAA;AAErC,cAAc,YAAY,CAAA;AAC1B,cAAc,cAAc,CAAA;AAC5B,cAAc,oBAAoB,CAAA;AAClC,cAAc,0BAA0B,CAAA;AACxC,cAAc,iBAAiB,CAAA;AAC/B,cAAc,uBAAuB,CAAA;AACrC,cAAc,yBAAyB,CAAA;AACvC,cAAc,mBAAmB,CAAA;AACjC,cAAc,cAAc,CAAA;AAC5B,cAAc,sBAAsB,CAAA;AACpC,cAAc,wBAAwB,CAAA;AACtC,cAAc,gBAAgB,CAAA"}
@@ -0,0 +1,37 @@
1
+ "use strict";
2
+ var __createBinding = (this && this.__createBinding) || (Object.create ? (function(o, m, k, k2) {
3
+ if (k2 === undefined) k2 = k;
4
+ var desc = Object.getOwnPropertyDescriptor(m, k);
5
+ if (!desc || ("get" in desc ? !m.__esModule : desc.writable || desc.configurable)) {
6
+ desc = { enumerable: true, get: function() { return m[k]; } };
7
+ }
8
+ Object.defineProperty(o, k2, desc);
9
+ }) : (function(o, m, k, k2) {
10
+ if (k2 === undefined) k2 = k;
11
+ o[k2] = m[k];
12
+ }));
13
+ var __exportStar = (this && this.__exportStar) || function(m, exports) {
14
+ for (var p in m) if (p !== "default" && !Object.prototype.hasOwnProperty.call(exports, p)) __createBinding(exports, m, p);
15
+ };
16
+ Object.defineProperty(exports, "__esModule", { value: true });
17
+ exports.calculateMigrationChecksum = exports.VERSION_LATEST = exports.SchemaMigrator = exports.SchemaDiffer = exports.ModificationHandlerFactory = exports.MigrationDescriber = void 0;
18
+ var schema_migrations_1 = require("@contember/schema-migrations");
19
+ Object.defineProperty(exports, "MigrationDescriber", { enumerable: true, get: function () { return schema_migrations_1.MigrationDescriber; } });
20
+ Object.defineProperty(exports, "ModificationHandlerFactory", { enumerable: true, get: function () { return schema_migrations_1.ModificationHandlerFactory; } });
21
+ Object.defineProperty(exports, "SchemaDiffer", { enumerable: true, get: function () { return schema_migrations_1.SchemaDiffer; } });
22
+ Object.defineProperty(exports, "SchemaMigrator", { enumerable: true, get: function () { return schema_migrations_1.SchemaMigrator; } });
23
+ Object.defineProperty(exports, "VERSION_LATEST", { enumerable: true, get: function () { return schema_migrations_1.VERSION_LATEST; } });
24
+ Object.defineProperty(exports, "calculateMigrationChecksum", { enumerable: true, get: function () { return schema_migrations_1.calculateMigrationChecksum; } });
25
+ __exportStar(require("./JsLoader"), exports);
26
+ __exportStar(require("./JsonLoader"), exports);
27
+ __exportStar(require("./MigrationCreator"), exports);
28
+ __exportStar(require("./MigrationExecuteHelper"), exports);
29
+ __exportStar(require("./MigrationFile"), exports);
30
+ __exportStar(require("./MigrationFileLoader"), exports);
31
+ __exportStar(require("./MigrationFilesManager"), exports);
32
+ __exportStar(require("./MigrationParser"), exports);
33
+ __exportStar(require("./migrations"), exports);
34
+ __exportStar(require("./MigrationsResolver"), exports);
35
+ __exportStar(require("./SchemaVersionBuilder"), exports);
36
+ __exportStar(require("./SystemClient"), exports);
37
+ //# sourceMappingURL=index.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"index.js","sourceRoot":"","sources":["../../src/index.ts"],"names":[],"mappings":";;;;;;;;;;;;;;;;;AAAA,kEASqC;AAPpC,uHAAA,kBAAkB,OAAA;AAElB,+HAAA,0BAA0B,OAAA;AAC1B,iHAAA,YAAY,OAAA;AACZ,mHAAA,cAAc,OAAA;AACd,mHAAA,cAAc,OAAA;AACd,+HAAA,0BAA0B,OAAA;AAG3B,6CAA0B;AAC1B,+CAA4B;AAC5B,qDAAkC;AAClC,2DAAwC;AACxC,kDAA+B;AAC/B,wDAAqC;AACrC,0DAAuC;AACvC,oDAAiC;AACjC,+CAA4B;AAC5B,uDAAoC;AACpC,yDAAsC;AACtC,iDAA8B"}
@@ -0,0 +1,56 @@
1
+ import { Migration, MigrationInfo } from '@contember/schema-migrations';
2
+ import { MigrationFile } from './MigrationFile';
3
+ export interface ExecutedMigrationInfo extends MigrationInfo {
4
+ readonly executedAt: Date;
5
+ readonly checksum: string;
6
+ }
7
+ export interface ExecutedMigration extends Migration {
8
+ readonly executedAt: Date;
9
+ readonly checksum: string;
10
+ }
11
+ export declare enum MigrationState {
12
+ TO_EXECUTE_OK = "to_execute_ok",
13
+ TO_EXECUTE_ERROR = "to_execute_error",
14
+ EXECUTED_OK = "executed_ok",
15
+ EXECUTED_ERROR = "executed_error",
16
+ EXECUTED_MISSING = "executed_missing"
17
+ }
18
+ export interface MigrationStatusBase<S extends MigrationState> {
19
+ state: S;
20
+ version: string;
21
+ name: string;
22
+ }
23
+ export interface MigrationToExecuteOkStatus extends MigrationStatusBase<MigrationState.TO_EXECUTE_OK> {
24
+ localMigration: MigrationFile;
25
+ }
26
+ interface MigrationToExecuteInvalidStatus extends MigrationStatusBase<MigrationState.TO_EXECUTE_ERROR> {
27
+ localMigration: MigrationFile;
28
+ errorMessage: string;
29
+ }
30
+ interface MigrationExecutedOkStatus extends MigrationStatusBase<MigrationState.EXECUTED_OK> {
31
+ executedMigration: ExecutedMigrationInfo;
32
+ localMigration: MigrationFile;
33
+ }
34
+ interface MigrationExecutedMissingStatus extends MigrationStatusBase<MigrationState.EXECUTED_MISSING> {
35
+ executedMigration: ExecutedMigrationInfo;
36
+ errorMessage: string;
37
+ }
38
+ interface MigrationExecutedErrorStatus extends MigrationStatusBase<MigrationState.EXECUTED_ERROR> {
39
+ executedMigration: ExecutedMigrationInfo;
40
+ localMigration: MigrationFile;
41
+ errorMessage: string;
42
+ }
43
+ export type ErrorMigrationStatus = MigrationToExecuteInvalidStatus | MigrationExecutedMissingStatus | MigrationExecutedErrorStatus;
44
+ export type AnyMigrationStatus = ErrorMigrationStatus | MigrationToExecuteOkStatus | MigrationExecutedOkStatus;
45
+ export declare const sortMigrations: <M extends {
46
+ version: string;
47
+ }>(migrations: M[]) => M[];
48
+ export declare class MigrationsStatusResolver {
49
+ getMigrationsStatus(executedMigrations: ExecutedMigrationInfo[], localMigrations: MigrationFile[], force?: boolean): Promise<{
50
+ allMigrations: AnyMigrationStatus[];
51
+ errorMigrations: ErrorMigrationStatus[];
52
+ migrationsToExecute: MigrationToExecuteOkStatus[];
53
+ }>;
54
+ }
55
+ export {};
56
+ //# sourceMappingURL=migrations.d.ts.map
@@ -0,0 +1 @@
1
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AAM,CAAA;CACpB;AAED,UAAU,4BAA6B,SAAQ,mBAAmB,CAAC,cAAc,CAAC,cAAc,CAAC;IAChG,iBAAiB,EAAE,qBAAqB,CAAA;IACxC,cAAc,EAAE,aAAa,CAAA;IAC7B,YAAY,EAAE,MAAM,CAAA;CACpB;AAED,MAAM,MAAM,oBAAoB,GAC7B,+BAA+B,GAC/B,8BAA8B,GAC9B,4BAA4B,CAAA;AAE/B,MAAM,MAAM,kBAAkB,GAC3B,oBAAoB,GACpB,0BAA0B,GAC1B,yBAAyB,CAAA;AAO5B,eAAO,MAAM,cAAc;aAAyB,MAAM;0BAEzD,CAAA;AAED,qBAAa,wBAAwB;IAE9B,mBAAmB,CACxB,kBAAkB,EAAE,qBAAqB,EAAE,EAC3C,eAAe,EAAE,aAAa,EAAE,EAChC,KAAK,GAAE,OAAe,GACpB,OAAO,CAAC;QACV,aAAa,EAAE,kBAAkB,EAAE,CAAA;QACnC,eAAe,EAAE,oBAAoB,EAAE,CAAA;QACvC,mBAAmB,EAAE,0BAA0B,EAAE,CAAA;KACjD,CAAC;CA2EF"}
@@ -0,0 +1,87 @@
1
+ "use strict";
2
+ Object.defineProperty(exports, "__esModule", { value: true });
3
+ exports.MigrationsStatusResolver = exports.sortMigrations = exports.MigrationState = void 0;
4
+ const schema_migrations_1 = require("@contember/schema-migrations");
5
+ const MigrationFile_1 = require("./MigrationFile");
6
+ var MigrationState;
7
+ (function (MigrationState) {
8
+ MigrationState["TO_EXECUTE_OK"] = "to_execute_ok";
9
+ MigrationState["TO_EXECUTE_ERROR"] = "to_execute_error";
10
+ MigrationState["EXECUTED_OK"] = "executed_ok";
11
+ MigrationState["EXECUTED_ERROR"] = "executed_error";
12
+ MigrationState["EXECUTED_MISSING"] = "executed_missing";
13
+ })(MigrationState || (exports.MigrationState = MigrationState = {}));
14
+ const isErrorMigrationStatus = (migration) => [MigrationState.EXECUTED_ERROR, MigrationState.EXECUTED_MISSING, MigrationState.TO_EXECUTE_ERROR].includes(migration.state);
15
+ const sortMigrations = (migrations) => {
16
+ return [...migrations].sort((a, b) => a.version.localeCompare(b.version));
17
+ };
18
+ exports.sortMigrations = sortMigrations;
19
+ class MigrationsStatusResolver {
20
+ async getMigrationsStatus(executedMigrations, localMigrations, force = false) {
21
+ const sortedExecuted = (0, exports.sortMigrations)(executedMigrations);
22
+ const allMigrations = [];
23
+ for (const executed of sortedExecuted) {
24
+ const localMigration = localMigrations.find(it => it.version === executed.version);
25
+ if (!localMigration) {
26
+ allMigrations.push({
27
+ state: MigrationState.EXECUTED_MISSING,
28
+ executedMigration: executed,
29
+ version: executed.version,
30
+ name: executed.name,
31
+ errorMessage: `Migration ${executed.name} is missing locally`,
32
+ });
33
+ continue;
34
+ }
35
+ const migrationContent = await localMigration.getContent();
36
+ const localChecksum = !(0, MigrationFile_1.isSchemaMigration)(migrationContent) ? null : (0, schema_migrations_1.calculateMigrationChecksum)(migrationContent);
37
+ if (localChecksum !== executed.checksum) {
38
+ allMigrations.push({
39
+ state: MigrationState.EXECUTED_ERROR,
40
+ executedMigration: executed,
41
+ version: executed.version,
42
+ name: executed.name,
43
+ localMigration,
44
+ errorMessage: `Checksum of executed migration "${executed.checksum}" does not match "${localChecksum}"`,
45
+ });
46
+ continue;
47
+ }
48
+ allMigrations.push({
49
+ state: MigrationState.EXECUTED_OK,
50
+ executedMigration: executed,
51
+ version: executed.version,
52
+ name: executed.name,
53
+ localMigration,
54
+ });
55
+ }
56
+ const latestExecuted = sortedExecuted.length > 0 ? sortedExecuted[sortedExecuted.length - 1] : null;
57
+ for (const localMigration of localMigrations) {
58
+ if (allMigrations.find(it => it.version === localMigration.version)) {
59
+ continue;
60
+ }
61
+ if (latestExecuted && latestExecuted.version > localMigration.version) {
62
+ allMigrations.push({
63
+ state: MigrationState.TO_EXECUTE_ERROR,
64
+ localMigration,
65
+ version: localMigration.version,
66
+ name: localMigration.name,
67
+ errorMessage: `Must follow latest executed migration ${latestExecuted.name}`,
68
+ });
69
+ continue;
70
+ }
71
+ allMigrations.push({
72
+ state: MigrationState.TO_EXECUTE_OK,
73
+ localMigration,
74
+ version: localMigration.version,
75
+ name: localMigration.name,
76
+ });
77
+ }
78
+ const allMigrationsSorted = (0, exports.sortMigrations)(allMigrations);
79
+ return {
80
+ allMigrations: allMigrationsSorted,
81
+ errorMigrations: allMigrationsSorted.filter(isErrorMigrationStatus),
82
+ migrationsToExecute: allMigrationsSorted.filter((it) => it.state === MigrationState.TO_EXECUTE_OK || (force && it.state === MigrationState.TO_EXECUTE_ERROR)),
83
+ };
84
+ }
85
+ }
86
+ exports.MigrationsStatusResolver = MigrationsStatusResolver;
87
+ //# sourceMappingURL=migrations.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"migrations.js","sourceRoot":"","sources":["../../src/migrations.ts"],"names":[],"mappings":";;;AAAA,oEAAmG;AACnG,mDAAkE;AAYlE,IAAY,cAMX;AAND,WAAY,cAAc;IACzB,iDAA+B,CAAA;IAC/B,uDAAqC,CAAA;IACrC,6CAA2B,CAAA;IAC3B,mDAAiC,CAAA;IACjC,uDAAqC,CAAA;AACtC,CAAC,EANW,cAAc,8BAAd,cAAc,QAMzB;AA2CD,MAAM,sBAAsB,GAAG,CAAC,SAA6B,EAAqC,EAAE,CACnG,CAAC,cAAc,CAAC,cAAc,EAAE,cAAc,CAAC,gBAAgB,EAAE,cAAc,CAAC,gBAAgB,CAAC,CAAC,QAAQ,CACzG,SAAS,CAAC,KAAK,CACf,CAAA;AAEK,MAAM,cAAc,GAAG,CAAgC,UAAe,EAAO,EAAE;IACrF,OAAO,CAAC,GAAG,UAAU,CAAC,CAAC,IAAI,CAAC,CAAC,CAAC,EAAE,CAAC,EAAE,EAAE,CAAC,CAAC,CAAC,OAAO,CAAC,aAAa,CAAC,CAAC,CAAC,OAAO,CAAC,CAAC,CAAA;AAC1E,CAAC,CAAA;AAFY,QAAA,cAAc,kBAE1B;AAED,MAAa,wBAAwB;IAEpC,KAAK,CAAC,mBAAmB,CACxB,kBAA2C,EA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