@webiny/data-migration 0.0.0-unstable.13771d80a8

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 (60) hide show
  1. package/LICENSE +21 -0
  2. package/MigrationRunner.d.ts +18 -0
  3. package/MigrationRunner.js +276 -0
  4. package/MigrationRunner.js.map +1 -0
  5. package/README.md +6 -0
  6. package/cli/getDuration.d.ts +5 -0
  7. package/cli/getDuration.js +21 -0
  8. package/cli/getDuration.js.map +1 -0
  9. package/cli/getMigrationStatus.d.ts +9 -0
  10. package/cli/getMigrationStatus.js +23 -0
  11. package/cli/getMigrationStatus.js.map +1 -0
  12. package/cli/index.d.ts +3 -0
  13. package/cli/index.js +38 -0
  14. package/cli/index.js.map +1 -0
  15. package/cli/printReport.d.ts +9 -0
  16. package/cli/printReport.js +57 -0
  17. package/cli/printReport.js.map +1 -0
  18. package/cli/runMigration.d.ts +13 -0
  19. package/cli/runMigration.js +85 -0
  20. package/cli/runMigration.js.map +1 -0
  21. package/createId.d.ts +1 -0
  22. package/createId.js +14 -0
  23. package/createId.js.map +1 -0
  24. package/createPinoLogger.d.ts +7 -0
  25. package/createPinoLogger.js +22 -0
  26. package/createPinoLogger.js.map +1 -0
  27. package/createTable.d.ts +7 -0
  28. package/createTable.js +29 -0
  29. package/createTable.js.map +1 -0
  30. package/executeWithRetry.d.ts +2 -0
  31. package/executeWithRetry.js +19 -0
  32. package/executeWithRetry.js.map +1 -0
  33. package/handlers/createDdbEsProjectMigration.d.ts +16 -0
  34. package/handlers/createDdbEsProjectMigration.js +79 -0
  35. package/handlers/createDdbEsProjectMigration.js.map +1 -0
  36. package/handlers/createDdbProjectMigration.d.ts +13 -0
  37. package/handlers/createDdbProjectMigration.js +75 -0
  38. package/handlers/createDdbProjectMigration.js.map +1 -0
  39. package/handlers/createPatternMatcher.d.ts +2 -0
  40. package/handlers/createPatternMatcher.js +17 -0
  41. package/handlers/createPatternMatcher.js.map +1 -0
  42. package/handlers/devVersionErrorResponse.d.ts +5 -0
  43. package/handlers/devVersionErrorResponse.js +14 -0
  44. package/handlers/devVersionErrorResponse.js.map +1 -0
  45. package/index.d.ts +7 -0
  46. package/index.js +71 -0
  47. package/index.js.map +1 -0
  48. package/package.json +60 -0
  49. package/repository/createStandardEntity.d.ts +5 -0
  50. package/repository/createStandardEntity.js +37 -0
  51. package/repository/createStandardEntity.js.map +1 -0
  52. package/repository/migrations.repository.d.ts +17 -0
  53. package/repository/migrations.repository.js +108 -0
  54. package/repository/migrations.repository.js.map +1 -0
  55. package/symbols.d.ts +7 -0
  56. package/symbols.js +20 -0
  57. package/symbols.js.map +1 -0
  58. package/types.d.ts +80 -0
  59. package/types.js +12 -0
  60. package/types.js.map +1 -0
package/package.json ADDED
@@ -0,0 +1,60 @@
1
+ {
2
+ "name": "@webiny/data-migration",
3
+ "version": "0.0.0-unstable.13771d80a8",
4
+ "main": "index.js",
5
+ "types": "types.ts",
6
+ "license": "MIT",
7
+ "repository": {
8
+ "type": "git",
9
+ "url": "https://github.com/webiny/webiny-js.git"
10
+ },
11
+ "description": "Tools to author and execute data migrations.",
12
+ "author": "Webiny Ltd.",
13
+ "dependencies": {
14
+ "@babel/runtime": "7.20.13",
15
+ "@elastic/elasticsearch": "7.12.0",
16
+ "@types/pino": "7.0.5",
17
+ "@webiny/db-dynamodb": "0.0.0-unstable.13771d80a8",
18
+ "@webiny/handler-aws": "0.0.0-unstable.13771d80a8",
19
+ "@webiny/ioc": "0.0.0-unstable.13771d80a8",
20
+ "center-align": "1.0.1",
21
+ "chalk": "4.1.2",
22
+ "dynamodb-toolbox": "0.3.5",
23
+ "mdbid": "1.0.0",
24
+ "minimatch": "5.1.6",
25
+ "p-retry": "4.6.2",
26
+ "pino": "8.11.0",
27
+ "pino-pretty": "9.4.0",
28
+ "semver": "6.3.0"
29
+ },
30
+ "devDependencies": {
31
+ "@babel/cli": "^7.19.3",
32
+ "@babel/core": "^7.19.3",
33
+ "@babel/preset-env": "^7.19.4",
34
+ "@types/center-align": "^1.0.0",
35
+ "@types/semver": "^7.3.4",
36
+ "@webiny/cli": "^0.0.0-unstable.13771d80a8",
37
+ "@webiny/project-utils": "^0.0.0-unstable.13771d80a8",
38
+ "jest": "^28.1.0",
39
+ "jest-dynalite": "^3.2.0",
40
+ "jest-mock-console": "^1.0.0",
41
+ "rimraf": "^3.0.2",
42
+ "typescript": "4.7.4"
43
+ },
44
+ "publishConfig": {
45
+ "access": "public",
46
+ "directory": "dist"
47
+ },
48
+ "scripts": {
49
+ "build": "yarn webiny run build",
50
+ "watch": "yarn webiny run watch"
51
+ },
52
+ "adio": {
53
+ "ignore": {
54
+ "dependencies": [
55
+ "@types/pino"
56
+ ]
57
+ }
58
+ },
59
+ "gitHead": "13771d80a8ae3195c9ea1485bf8c01f6667a129e"
60
+ }
@@ -0,0 +1,5 @@
1
+ import { Table, Entity } from "dynamodb-toolbox";
2
+ export declare const createStandardEntity: ({ table, name }: {
3
+ table: Table;
4
+ name: string;
5
+ }) => Entity<{}>;
@@ -0,0 +1,37 @@
1
+ "use strict";
2
+
3
+ Object.defineProperty(exports, "__esModule", {
4
+ value: true
5
+ });
6
+ exports.createStandardEntity = void 0;
7
+ var _dynamodbToolbox = require("dynamodb-toolbox");
8
+ const createStandardEntity = ({
9
+ table,
10
+ name
11
+ }) => {
12
+ return new _dynamodbToolbox.Entity({
13
+ name,
14
+ table,
15
+ attributes: {
16
+ PK: {
17
+ partitionKey: true
18
+ },
19
+ SK: {
20
+ sortKey: true
21
+ },
22
+ GSI1_PK: {
23
+ type: "string"
24
+ },
25
+ GSI1_SK: {
26
+ type: "string"
27
+ },
28
+ TYPE: {
29
+ type: "string"
30
+ },
31
+ data: {
32
+ type: "map"
33
+ }
34
+ }
35
+ });
36
+ };
37
+ exports.createStandardEntity = createStandardEntity;
@@ -0,0 +1 @@
1
+ {"version":3,"names":["createStandardEntity","table","name","Entity","attributes","PK","partitionKey","SK","sortKey","GSI1_PK","type","GSI1_SK","TYPE","data"],"sources":["createStandardEntity.ts"],"sourcesContent":["import { Table, Entity } from \"dynamodb-toolbox\";\n\nexport const createStandardEntity = ({ table, name }: { table: Table; name: string }) => {\n return new Entity({\n name,\n table,\n attributes: {\n PK: {\n partitionKey: true\n },\n SK: {\n sortKey: true\n },\n GSI1_PK: {\n type: \"string\"\n },\n GSI1_SK: {\n type: \"string\"\n },\n TYPE: {\n type: \"string\"\n },\n data: {\n type: \"map\"\n }\n }\n });\n};\n"],"mappings":";;;;;;AAAA;AAEO,MAAMA,oBAAoB,GAAG,CAAC;EAAEC,KAAK;EAAEC;AAAqC,CAAC,KAAK;EACrF,OAAO,IAAIC,uBAAM,CAAC;IACdD,IAAI;IACJD,KAAK;IACLG,UAAU,EAAE;MACRC,EAAE,EAAE;QACAC,YAAY,EAAE;MAClB,CAAC;MACDC,EAAE,EAAE;QACAC,OAAO,EAAE;MACb,CAAC;MACDC,OAAO,EAAE;QACLC,IAAI,EAAE;MACV,CAAC;MACDC,OAAO,EAAE;QACLD,IAAI,EAAE;MACV,CAAC;MACDE,IAAI,EAAE;QACFF,IAAI,EAAE;MACV,CAAC;MACDG,IAAI,EAAE;QACFH,IAAI,EAAE;MACV;IACJ;EACJ,CAAC,CAAC;AACN,CAAC;AAAC"}
@@ -0,0 +1,17 @@
1
+ import { Table } from "dynamodb-toolbox";
2
+ import { MigrationItem, MigrationRepository, MigrationRun } from "../types";
3
+ export declare class MigrationRepositoryImpl implements MigrationRepository {
4
+ private readonly run;
5
+ private readonly migration;
6
+ private readonly checkpoint;
7
+ constructor(table: Table);
8
+ getLastRun(): Promise<MigrationRun | null>;
9
+ saveRun(run: MigrationRun): Promise<void>;
10
+ listMigrations(params?: {
11
+ limit: number;
12
+ }): Promise<MigrationItem[]>;
13
+ logMigration(migration: MigrationItem): Promise<void>;
14
+ createCheckpoint(id: string, data: unknown): Promise<void>;
15
+ deleteCheckpoint(id: string): Promise<void>;
16
+ getCheckpoint(id: string): Promise<unknown | null>;
17
+ }
@@ -0,0 +1,108 @@
1
+ "use strict";
2
+
3
+ var _interopRequireDefault = require("@babel/runtime/helpers/interopRequireDefault").default;
4
+ Object.defineProperty(exports, "__esModule", {
5
+ value: true
6
+ });
7
+ exports.MigrationRepositoryImpl = void 0;
8
+ var _defineProperty2 = _interopRequireDefault(require("@babel/runtime/helpers/defineProperty"));
9
+ var _query = require("@webiny/db-dynamodb/utils/query");
10
+ var _ioc = require("@webiny/ioc");
11
+ var _symbols = require("../symbols");
12
+ var _createStandardEntity = require("./createStandardEntity");
13
+ class MigrationRepositoryImpl {
14
+ constructor(table) {
15
+ (0, _defineProperty2.default)(this, "run", void 0);
16
+ (0, _defineProperty2.default)(this, "migration", void 0);
17
+ (0, _defineProperty2.default)(this, "checkpoint", void 0);
18
+ this.run = (0, _createStandardEntity.createStandardEntity)({
19
+ table,
20
+ name: "MigrationRun"
21
+ });
22
+ this.migration = (0, _createStandardEntity.createStandardEntity)({
23
+ table,
24
+ name: "Migration"
25
+ });
26
+ this.checkpoint = (0, _createStandardEntity.createStandardEntity)({
27
+ table,
28
+ name: "MigrationCheckpoint"
29
+ });
30
+ }
31
+ async getLastRun() {
32
+ const result = await (0, _query.queryOne)({
33
+ entity: this.run,
34
+ partitionKey: "MIGRATION_RUNS",
35
+ options: {
36
+ index: "GSI1",
37
+ gt: " ",
38
+ reverse: true
39
+ }
40
+ });
41
+ return result ? result.data : null;
42
+ }
43
+ async saveRun(run) {
44
+ await this.run.put({
45
+ PK: `MIGRATION_RUN#${run.id}`,
46
+ SK: "A",
47
+ TYPE: "migration.run",
48
+ GSI1_PK: "MIGRATION_RUNS",
49
+ GSI1_SK: run.id,
50
+ data: run
51
+ });
52
+ }
53
+ async listMigrations(params) {
54
+ const {
55
+ limit
56
+ } = params || {};
57
+ const result = await (0, _query.queryAll)({
58
+ entity: this.migration,
59
+ partitionKey: "MIGRATIONS",
60
+ options: {
61
+ index: "GSI1",
62
+ gt: " ",
63
+ limit,
64
+ // Sort by GSI1_SK in descending order.
65
+ reverse: true
66
+ }
67
+ });
68
+ return result.map(item => item.data);
69
+ }
70
+ async logMigration(migration) {
71
+ await this.migration.put({
72
+ PK: `MIGRATION#${migration.id}`,
73
+ SK: "A",
74
+ TYPE: "migration",
75
+ GSI1_PK: "MIGRATIONS",
76
+ GSI1_SK: migration.id,
77
+ data: migration
78
+ });
79
+ }
80
+ async createCheckpoint(id, data) {
81
+ await this.checkpoint.put({
82
+ PK: `MIGRATION_CHECKPOINT#${id}`,
83
+ SK: "A",
84
+ TYPE: "migration.checkpoint",
85
+ GSI1_PK: "MIGRATION_CHECKPOINTS",
86
+ GSI1_SK: id,
87
+ data
88
+ });
89
+ }
90
+ deleteCheckpoint(id) {
91
+ return this.checkpoint.delete({
92
+ PK: `MIGRATION_CHECKPOINT#${id}`,
93
+ SK: "A"
94
+ });
95
+ }
96
+ async getCheckpoint(id) {
97
+ const record = await this.checkpoint.get({
98
+ PK: `MIGRATION_CHECKPOINT#${id}`,
99
+ SK: "A"
100
+ });
101
+ if (!record || !record.Item) {
102
+ return null;
103
+ }
104
+ return record.Item.data;
105
+ }
106
+ }
107
+ exports.MigrationRepositoryImpl = MigrationRepositoryImpl;
108
+ (0, _ioc.makeInjectable)(MigrationRepositoryImpl, [(0, _ioc.inject)(_symbols.PrimaryDynamoTableSymbol)]);
@@ -0,0 +1 @@
1
+ {"version":3,"names":["MigrationRepositoryImpl","constructor","table","run","createStandardEntity","name","migration","checkpoint","getLastRun","result","queryOne","entity","partitionKey","options","index","gt","reverse","data","saveRun","put","PK","id","SK","TYPE","GSI1_PK","GSI1_SK","listMigrations","params","limit","queryAll","map","item","logMigration","createCheckpoint","deleteCheckpoint","delete","getCheckpoint","record","get","Item","makeInjectable","inject","PrimaryDynamoTableSymbol"],"sources":["migrations.repository.ts"],"sourcesContent":["import { Table, Entity } from \"dynamodb-toolbox\";\nimport { queryAll, queryOne } from \"@webiny/db-dynamodb/utils/query\";\nimport { MigrationItem, MigrationRepository, MigrationRun } from \"~/types\";\nimport { inject, makeInjectable } from \"@webiny/ioc\";\nimport { PrimaryDynamoTableSymbol } from \"~/symbols\";\nimport { createStandardEntity } from \"./createStandardEntity\";\n\nexport class MigrationRepositoryImpl implements MigrationRepository {\n private readonly run: Entity<any>;\n private readonly migration: Entity<any>;\n private readonly checkpoint: Entity<any>;\n\n constructor(table: Table) {\n this.run = createStandardEntity({ table, name: \"MigrationRun\" });\n this.migration = createStandardEntity({ table, name: \"Migration\" });\n this.checkpoint = createStandardEntity({ table, name: \"MigrationCheckpoint\" });\n }\n\n async getLastRun(): Promise<MigrationRun | null> {\n const result = await queryOne<{ data: MigrationRun }>({\n entity: this.run,\n partitionKey: \"MIGRATION_RUNS\",\n options: {\n index: \"GSI1\",\n gt: \" \",\n reverse: true\n }\n });\n\n return result ? result.data : null;\n }\n\n async saveRun(run: MigrationRun): Promise<void> {\n await this.run.put({\n PK: `MIGRATION_RUN#${run.id}`,\n SK: \"A\",\n TYPE: \"migration.run\",\n GSI1_PK: \"MIGRATION_RUNS\",\n GSI1_SK: run.id,\n data: run\n });\n }\n\n async listMigrations(params?: { limit: number }): Promise<MigrationItem[]> {\n const { limit } = params || {};\n const result = await queryAll<{ data: MigrationItem }>({\n entity: this.migration,\n partitionKey: \"MIGRATIONS\",\n options: {\n index: \"GSI1\",\n gt: \" \",\n limit,\n // Sort by GSI1_SK in descending order.\n reverse: true\n }\n });\n\n return result.map(item => item.data);\n }\n\n async logMigration(migration: MigrationItem): Promise<void> {\n await this.migration.put({\n PK: `MIGRATION#${migration.id}`,\n SK: \"A\",\n TYPE: \"migration\",\n GSI1_PK: \"MIGRATIONS\",\n GSI1_SK: migration.id,\n data: migration\n });\n }\n\n async createCheckpoint(id: string, data: unknown): Promise<void> {\n await this.checkpoint.put({\n PK: `MIGRATION_CHECKPOINT#${id}`,\n SK: \"A\",\n TYPE: \"migration.checkpoint\",\n GSI1_PK: \"MIGRATION_CHECKPOINTS\",\n GSI1_SK: id,\n data\n });\n }\n\n deleteCheckpoint(id: string): Promise<void> {\n return this.checkpoint.delete({\n PK: `MIGRATION_CHECKPOINT#${id}`,\n SK: \"A\"\n });\n }\n\n async getCheckpoint(id: string): Promise<unknown | null> {\n const record = await this.checkpoint.get({\n PK: `MIGRATION_CHECKPOINT#${id}`,\n SK: \"A\"\n });\n\n if (!record || !record.Item) {\n return null;\n }\n return record.Item.data;\n }\n}\n\nmakeInjectable(MigrationRepositoryImpl, [inject(PrimaryDynamoTableSymbol)]);\n"],"mappings":"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"}
package/symbols.d.ts ADDED
@@ -0,0 +1,7 @@
1
+ export declare const LoggerSymbol: unique symbol;
2
+ export declare const MigrationSymbol: unique symbol;
3
+ export declare const MigrationRepositorySymbol: unique symbol;
4
+ export declare const ElasticsearchClientSymbol: unique symbol;
5
+ export declare const PrimaryDynamoTableSymbol: unique symbol;
6
+ export declare const ElasticsearchDynamoTableSymbol: unique symbol;
7
+ export declare const ExecutionTimeLimiterSymbol: unique symbol;
package/symbols.js ADDED
@@ -0,0 +1,20 @@
1
+ "use strict";
2
+
3
+ Object.defineProperty(exports, "__esModule", {
4
+ value: true
5
+ });
6
+ exports.PrimaryDynamoTableSymbol = exports.MigrationSymbol = exports.MigrationRepositorySymbol = exports.LoggerSymbol = exports.ExecutionTimeLimiterSymbol = exports.ElasticsearchDynamoTableSymbol = exports.ElasticsearchClientSymbol = void 0;
7
+ const LoggerSymbol = Symbol.for("PinoLogger");
8
+ exports.LoggerSymbol = LoggerSymbol;
9
+ const MigrationSymbol = Symbol.for("Migration");
10
+ exports.MigrationSymbol = MigrationSymbol;
11
+ const MigrationRepositorySymbol = Symbol.for("MigrationRepository");
12
+ exports.MigrationRepositorySymbol = MigrationRepositorySymbol;
13
+ const ElasticsearchClientSymbol = Symbol.for("ElasticsearchClient");
14
+ exports.ElasticsearchClientSymbol = ElasticsearchClientSymbol;
15
+ const PrimaryDynamoTableSymbol = Symbol.for("PrimaryDynamoTable");
16
+ exports.PrimaryDynamoTableSymbol = PrimaryDynamoTableSymbol;
17
+ const ElasticsearchDynamoTableSymbol = Symbol.for("ElasticsearchDynamoTable");
18
+ exports.ElasticsearchDynamoTableSymbol = ElasticsearchDynamoTableSymbol;
19
+ const ExecutionTimeLimiterSymbol = Symbol.for("ExecutionTimeLimiter");
20
+ exports.ExecutionTimeLimiterSymbol = ExecutionTimeLimiterSymbol;
package/symbols.js.map ADDED
@@ -0,0 +1 @@
1
+ {"version":3,"names":["LoggerSymbol","Symbol","for","MigrationSymbol","MigrationRepositorySymbol","ElasticsearchClientSymbol","PrimaryDynamoTableSymbol","ElasticsearchDynamoTableSymbol","ExecutionTimeLimiterSymbol"],"sources":["symbols.ts"],"sourcesContent":["export const LoggerSymbol = Symbol.for(\"PinoLogger\");\nexport const MigrationSymbol = Symbol.for(\"Migration\");\nexport const MigrationRepositorySymbol = Symbol.for(\"MigrationRepository\");\nexport const ElasticsearchClientSymbol = Symbol.for(\"ElasticsearchClient\");\nexport const PrimaryDynamoTableSymbol = Symbol.for(\"PrimaryDynamoTable\");\nexport const ElasticsearchDynamoTableSymbol = Symbol.for(\"ElasticsearchDynamoTable\");\nexport const ExecutionTimeLimiterSymbol = Symbol.for(\"ExecutionTimeLimiter\");\n"],"mappings":";;;;;;AAAO,MAAMA,YAAY,GAAGC,MAAM,CAACC,GAAG,CAAC,YAAY,CAAC;AAAC;AAC9C,MAAMC,eAAe,GAAGF,MAAM,CAACC,GAAG,CAAC,WAAW,CAAC;AAAC;AAChD,MAAME,yBAAyB,GAAGH,MAAM,CAACC,GAAG,CAAC,qBAAqB,CAAC;AAAC;AACpE,MAAMG,yBAAyB,GAAGJ,MAAM,CAACC,GAAG,CAAC,qBAAqB,CAAC;AAAC;AACpE,MAAMI,wBAAwB,GAAGL,MAAM,CAACC,GAAG,CAAC,oBAAoB,CAAC;AAAC;AAClE,MAAMK,8BAA8B,GAAGN,MAAM,CAACC,GAAG,CAAC,0BAA0B,CAAC;AAAC;AAC9E,MAAMM,0BAA0B,GAAGP,MAAM,CAACC,GAAG,CAAC,sBAAsB,CAAC;AAAC"}
package/types.d.ts ADDED
@@ -0,0 +1,80 @@
1
+ import { Logger } from "pino";
2
+ export { Logger };
3
+ export interface MigrationItem {
4
+ id: string;
5
+ description: string;
6
+ reason: string;
7
+ startedOn?: string;
8
+ finishedOn?: string;
9
+ }
10
+ export interface MigrationRun {
11
+ id: string;
12
+ startedOn: string;
13
+ finishedOn: string;
14
+ status: "init" | "running" | "pending" | "done" | "error";
15
+ migrations: MigrationRunItem[];
16
+ error?: {
17
+ message: string;
18
+ name?: string;
19
+ code?: string;
20
+ data?: Record<string, any>;
21
+ stack?: string;
22
+ };
23
+ }
24
+ export interface MigrationRunItem {
25
+ id: string;
26
+ status: "done" | "running" | "skipped" | "pending" | "not-applicable" | "error";
27
+ startedOn?: string;
28
+ finishedOn?: string;
29
+ }
30
+ export interface MigrationRepository {
31
+ getLastRun(): Promise<MigrationRun | null>;
32
+ saveRun(run: MigrationRun): Promise<void>;
33
+ listMigrations(params?: {
34
+ limit: number;
35
+ }): Promise<MigrationItem[]>;
36
+ logMigration(migration: MigrationItem): Promise<void>;
37
+ createCheckpoint(id: string, data: unknown): Promise<void>;
38
+ getCheckpoint(id: string): Promise<unknown>;
39
+ deleteCheckpoint(id: string): Promise<void>;
40
+ }
41
+ export interface DataMigrationContext<TCheckpoint = any> {
42
+ projectVersion: string;
43
+ logger: Logger;
44
+ checkpoint?: TCheckpoint;
45
+ runningOutOfTime: () => boolean;
46
+ createCheckpoint: (data: TCheckpoint) => void;
47
+ createCheckpointAndExit: (data: TCheckpoint) => void;
48
+ }
49
+ export interface DataMigration<TCheckpoint = any> {
50
+ getId(): string;
51
+ getDescription(): string;
52
+ shouldExecute(context: DataMigrationContext<TCheckpoint>): Promise<boolean>;
53
+ execute(context: DataMigrationContext<TCheckpoint>): Promise<void>;
54
+ }
55
+ /**
56
+ * Migration execution time limiter (in milliseconds).
57
+ */
58
+ export declare type ExecutionTimeLimiter = () => number;
59
+ export interface MigrationEventPayload {
60
+ command: "status" | "execute";
61
+ version?: string;
62
+ pattern?: string;
63
+ }
64
+ export declare type MigrationEventHandlerResponse = undefined | MigrationStatusResponse | MigrationInvocationErrorResponse;
65
+ export interface MigrationInvocationErrorResponse {
66
+ error: {
67
+ message: string;
68
+ };
69
+ data?: undefined;
70
+ }
71
+ export interface MigrationStatusRunItem extends MigrationRunItem {
72
+ description: string;
73
+ }
74
+ export interface MigrationStatus extends MigrationRun {
75
+ migrations: MigrationStatusRunItem[];
76
+ }
77
+ export interface MigrationStatusResponse {
78
+ data: MigrationStatus;
79
+ error?: undefined;
80
+ }
package/types.js ADDED
@@ -0,0 +1,12 @@
1
+ "use strict";
2
+
3
+ Object.defineProperty(exports, "__esModule", {
4
+ value: true
5
+ });
6
+ Object.defineProperty(exports, "Logger", {
7
+ enumerable: true,
8
+ get: function () {
9
+ return _pino.Logger;
10
+ }
11
+ });
12
+ var _pino = require("pino");
package/types.js.map ADDED
@@ -0,0 +1 @@
1
+ {"version":3,"names":[],"sources":["types.ts"],"sourcesContent":["import { Logger } from \"pino\";\n\nexport { Logger };\n\nexport interface MigrationItem {\n id: string;\n description: string;\n reason: string;\n startedOn?: string;\n finishedOn?: string;\n}\n\nexport interface MigrationRun {\n id: string;\n startedOn: string;\n finishedOn: string;\n status: \"init\" | \"running\" | \"pending\" | \"done\" | \"error\";\n migrations: MigrationRunItem[];\n error?: {\n message: string;\n name?: string;\n code?: string;\n data?: Record<string, any>;\n stack?: string;\n };\n}\n\nexport interface MigrationRunItem {\n id: string;\n status: \"done\" | \"running\" | \"skipped\" | \"pending\" | \"not-applicable\" | \"error\";\n startedOn?: string;\n finishedOn?: string;\n}\n\nexport interface MigrationRepository {\n getLastRun(): Promise<MigrationRun | null>;\n saveRun(run: MigrationRun): Promise<void>;\n listMigrations(params?: { limit: number }): Promise<MigrationItem[]>;\n logMigration(migration: MigrationItem): Promise<void>;\n createCheckpoint(id: string, data: unknown): Promise<void>;\n getCheckpoint(id: string): Promise<unknown>;\n deleteCheckpoint(id: string): Promise<void>;\n}\n\nexport interface DataMigrationContext<TCheckpoint = any> {\n projectVersion: string;\n logger: Logger;\n checkpoint?: TCheckpoint;\n runningOutOfTime: () => boolean;\n createCheckpoint: (data: TCheckpoint) => void;\n createCheckpointAndExit: (data: TCheckpoint) => void;\n}\n\nexport interface DataMigration<TCheckpoint = any> {\n getId(): string;\n getDescription(): string;\n // This function should check of the migration needs to apply some changes to the system.\n // Returning `false` means \"everything is ok, mark this migration as executed\".\n shouldExecute(context: DataMigrationContext<TCheckpoint>): Promise<boolean>;\n execute(context: DataMigrationContext<TCheckpoint>): Promise<void>;\n}\n\n/**\n * Migration execution time limiter (in milliseconds).\n */\nexport type ExecutionTimeLimiter = () => number;\n\nexport interface MigrationEventPayload {\n command: \"status\" | \"execute\";\n version?: string;\n pattern?: string;\n}\n\nexport type MigrationEventHandlerResponse =\n // When migration is triggered (via `Event` invocation type), it simply gets invoked, and returns nothing.\n | undefined\n // Last migration run state.\n | MigrationStatusResponse\n // If an unhandled error is thrown, return the error object.\n | MigrationInvocationErrorResponse;\n\nexport interface MigrationInvocationErrorResponse {\n error: { message: string };\n data?: undefined;\n}\n\nexport interface MigrationStatusRunItem extends MigrationRunItem {\n description: string;\n}\n\nexport interface MigrationStatus extends MigrationRun {\n migrations: MigrationStatusRunItem[];\n}\n\nexport interface MigrationStatusResponse {\n data: MigrationStatus;\n error?: undefined;\n}\n"],"mappings":";;;;;;;;;;;AAAA"}