@webiny/data-migration 0.0.0-unstable.06b2ede40f

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 (72) hide show
  1. package/LICENSE +21 -0
  2. package/MigrationRunner.d.ts +22 -0
  3. package/MigrationRunner.js +341 -0
  4. package/MigrationRunner.js.map +1 -0
  5. package/README.md +6 -0
  6. package/cli/CliMigrationRunReporter.d.ts +10 -0
  7. package/cli/CliMigrationRunReporter.js +55 -0
  8. package/cli/CliMigrationRunReporter.js.map +1 -0
  9. package/cli/InteractiveCliStatusReporter.d.ts +11 -0
  10. package/cli/InteractiveCliStatusReporter.js +74 -0
  11. package/cli/InteractiveCliStatusReporter.js.map +1 -0
  12. package/cli/LogReporter.d.ts +10 -0
  13. package/cli/LogReporter.js +43 -0
  14. package/cli/LogReporter.js.map +1 -0
  15. package/cli/LogStream.d.ts +10 -0
  16. package/cli/LogStream.js +58 -0
  17. package/cli/LogStream.js.map +1 -0
  18. package/cli/MigrationRunReporter.d.ts +4 -0
  19. package/cli/MigrationRunReporter.js +7 -0
  20. package/cli/MigrationRunReporter.js.map +1 -0
  21. package/cli/MigrationRunner.d.ts +45 -0
  22. package/cli/MigrationRunner.js +136 -0
  23. package/cli/MigrationRunner.js.map +1 -0
  24. package/cli/MigrationStatusReporter.d.ts +4 -0
  25. package/cli/MigrationStatusReporter.js +7 -0
  26. package/cli/MigrationStatusReporter.js.map +1 -0
  27. package/cli/NonInteractiveCliStatusReporter.d.ts +9 -0
  28. package/cli/NonInteractiveCliStatusReporter.js +42 -0
  29. package/cli/NonInteractiveCliStatusReporter.js.map +1 -0
  30. package/cli/VoidStatusReporter.d.ts +4 -0
  31. package/cli/VoidStatusReporter.js +14 -0
  32. package/cli/VoidStatusReporter.js.map +1 -0
  33. package/cli/getDuration.d.ts +5 -0
  34. package/cli/getDuration.js +23 -0
  35. package/cli/getDuration.js.map +1 -0
  36. package/cli/index.d.ts +10 -0
  37. package/cli/index.js +117 -0
  38. package/cli/index.js.map +1 -0
  39. package/createPinoLogger.d.ts +4 -0
  40. package/createPinoLogger.js +26 -0
  41. package/createPinoLogger.js.map +1 -0
  42. package/createTable.d.ts +7 -0
  43. package/createTable.js +33 -0
  44. package/createTable.js.map +1 -0
  45. package/handlers/createDdbEsProjectMigration.d.ts +16 -0
  46. package/handlers/createDdbEsProjectMigration.js +84 -0
  47. package/handlers/createDdbEsProjectMigration.js.map +1 -0
  48. package/handlers/createDdbProjectMigration.d.ts +13 -0
  49. package/handlers/createDdbProjectMigration.js +80 -0
  50. package/handlers/createDdbProjectMigration.js.map +1 -0
  51. package/handlers/createPatternMatcher.d.ts +2 -0
  52. package/handlers/createPatternMatcher.js +19 -0
  53. package/handlers/createPatternMatcher.js.map +1 -0
  54. package/handlers/devVersionErrorResponse.d.ts +5 -0
  55. package/handlers/devVersionErrorResponse.js +16 -0
  56. package/handlers/devVersionErrorResponse.js.map +1 -0
  57. package/index.d.ts +6 -0
  58. package/index.js +62 -0
  59. package/index.js.map +1 -0
  60. package/package.json +47 -0
  61. package/repository/createStandardEntity.d.ts +52 -0
  62. package/repository/createStandardEntity.js +39 -0
  63. package/repository/createStandardEntity.js.map +1 -0
  64. package/repository/migrations.repository.d.ts +17 -0
  65. package/repository/migrations.repository.js +121 -0
  66. package/repository/migrations.repository.js.map +1 -0
  67. package/symbols.d.ts +7 -0
  68. package/symbols.js +15 -0
  69. package/symbols.js.map +1 -0
  70. package/types.d.ts +83 -0
  71. package/types.js +7 -0
  72. package/types.js.map +1 -0
@@ -0,0 +1,43 @@
1
+ "use strict";
2
+
3
+ Object.defineProperty(exports, "__esModule", {
4
+ value: true
5
+ });
6
+ exports.LogReporter = void 0;
7
+ var _LogStream = require("./LogStream");
8
+ class LogReporter {
9
+ logStreams = new Set();
10
+ constructor(functionName) {
11
+ const baseName = functionName.split(":").pop();
12
+ this.logGroupName = `/aws/lambda/${baseName}`;
13
+ this.logsCreatedSince = Date.now();
14
+ }
15
+ async printLogs(logStreamName) {
16
+ const logStream = this.initializeStream(logStreamName);
17
+ await logStream.printLogsSince(this.logsCreatedSince);
18
+ }
19
+ printLogStreamLinks() {
20
+ if (this.logStreams.size === 0) {
21
+ return;
22
+ }
23
+ const logStreams = Array.from(this.logStreams);
24
+ if (this.logStreams.size === 1) {
25
+ process.stdout.write(`\nTo view detailed logs, visit the following AWS CloudWatch log stream:\n`);
26
+ process.stdout.write(logStreams[0].getLogStreamLink());
27
+ } else {
28
+ process.stdout.write(`\nTo view detailed logs, visit the following AWS CloudWatch log streams:\n`);
29
+ for (const logStream of logStreams) {
30
+ process.stdout.write(`- ${logStream.getLogStreamLink()}`);
31
+ }
32
+ }
33
+ process.stdout.write("\n");
34
+ }
35
+ initializeStream(name) {
36
+ const logStream = _LogStream.LogStream.create(this.logGroupName, name);
37
+ this.logStreams.add(logStream);
38
+ return logStream;
39
+ }
40
+ }
41
+ exports.LogReporter = LogReporter;
42
+
43
+ //# sourceMappingURL=LogReporter.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"names":["_LogStream","require","LogReporter","logStreams","Set","constructor","functionName","baseName","split","pop","logGroupName","logsCreatedSince","Date","now","printLogs","logStreamName","logStream","initializeStream","printLogsSince","printLogStreamLinks","size","Array","from","process","stdout","write","getLogStreamLink","name","LogStream","create","add","exports"],"sources":["LogReporter.ts"],"sourcesContent":["import { LogStream } from \"./LogStream\";\n\nexport class LogReporter {\n private readonly logGroupName: string;\n private readonly logsCreatedSince: number;\n private readonly logStreams = new Set<LogStream>();\n\n constructor(functionName: string) {\n const baseName = functionName.split(\":\").pop();\n this.logGroupName = `/aws/lambda/${baseName}`;\n this.logsCreatedSince = Date.now();\n }\n\n public async printLogs(logStreamName: string) {\n const logStream = this.initializeStream(logStreamName);\n await logStream.printLogsSince(this.logsCreatedSince);\n }\n\n public printLogStreamLinks() {\n if (this.logStreams.size === 0) {\n return;\n }\n\n const logStreams = Array.from(this.logStreams);\n\n if (this.logStreams.size === 1) {\n process.stdout.write(\n `\\nTo view detailed logs, visit the following AWS CloudWatch log stream:\\n`\n );\n process.stdout.write(logStreams[0].getLogStreamLink());\n } else {\n process.stdout.write(\n `\\nTo view detailed logs, visit the following AWS CloudWatch log streams:\\n`\n );\n\n for (const logStream of logStreams) {\n process.stdout.write(`- ${logStream.getLogStreamLink()}`);\n }\n }\n\n process.stdout.write(\"\\n\");\n }\n\n public initializeStream(name: string) {\n const logStream = LogStream.create(this.logGroupName, name);\n this.logStreams.add(logStream);\n return logStream;\n }\n}\n"],"mappings":";;;;;;AAAA,IAAAA,UAAA,GAAAC,OAAA;AAEO,MAAMC,WAAW,CAAC;EAGJC,UAAU,GAAG,IAAIC,GAAG,CAAY,CAAC;EAElDC,WAAWA,CAACC,YAAoB,EAAE;IAC9B,MAAMC,QAAQ,GAAGD,YAAY,CAACE,KAAK,CAAC,GAAG,CAAC,CAACC,GAAG,CAAC,CAAC;IAC9C,IAAI,CAACC,YAAY,GAAG,eAAeH,QAAQ,EAAE;IAC7C,IAAI,CAACI,gBAAgB,GAAGC,IAAI,CAACC,GAAG,CAAC,CAAC;EACtC;EAEA,MAAaC,SAASA,CAACC,aAAqB,EAAE;IAC1C,MAAMC,SAAS,GAAG,IAAI,CAACC,gBAAgB,CAACF,aAAa,CAAC;IACtD,MAAMC,SAAS,CAACE,cAAc,CAAC,IAAI,CAACP,gBAAgB,CAAC;EACzD;EAEOQ,mBAAmBA,CAAA,EAAG;IACzB,IAAI,IAAI,CAAChB,UAAU,CAACiB,IAAI,KAAK,CAAC,EAAE;MAC5B;IACJ;IAEA,MAAMjB,UAAU,GAAGkB,KAAK,CAACC,IAAI,CAAC,IAAI,CAACnB,UAAU,CAAC;IAE9C,IAAI,IAAI,CAACA,UAAU,CAACiB,IAAI,KAAK,CAAC,EAAE;MAC5BG,OAAO,CAACC,MAAM,CAACC,KAAK,CAChB,2EACJ,CAAC;MACDF,OAAO,CAACC,MAAM,CAACC,KAAK,CAACtB,UAAU,CAAC,CAAC,CAAC,CAACuB,gBAAgB,CAAC,CAAC,CAAC;IAC1D,CAAC,MAAM;MACHH,OAAO,CAACC,MAAM,CAACC,KAAK,CAChB,4EACJ,CAAC;MAED,KAAK,MAAMT,SAAS,IAAIb,UAAU,EAAE;QAChCoB,OAAO,CAACC,MAAM,CAACC,KAAK,CAAC,KAAKT,SAAS,CAACU,gBAAgB,CAAC,CAAC,EAAE,CAAC;MAC7D;IACJ;IAEAH,OAAO,CAACC,MAAM,CAACC,KAAK,CAAC,IAAI,CAAC;EAC9B;EAEOR,gBAAgBA,CAACU,IAAY,EAAE;IAClC,MAAMX,SAAS,GAAGY,oBAAS,CAACC,MAAM,CAAC,IAAI,CAACnB,YAAY,EAAEiB,IAAI,CAAC;IAC3D,IAAI,CAACxB,UAAU,CAAC2B,GAAG,CAACd,SAAS,CAAC;IAC9B,OAAOA,SAAS;EACpB;AACJ;AAACe,OAAA,CAAA7B,WAAA,GAAAA,WAAA","ignoreList":[]}
@@ -0,0 +1,10 @@
1
+ export declare class LogStream {
2
+ private readonly logGroupName;
3
+ private readonly logStreamName;
4
+ private readonly cloudWatchLogs;
5
+ private nextPage;
6
+ private constructor();
7
+ getLogStreamLink(): string;
8
+ printLogsSince(startTime: number): Promise<void>;
9
+ static create(logGroupName: string, logStreamName: string): LogStream;
10
+ }
@@ -0,0 +1,58 @@
1
+ "use strict";
2
+
3
+ Object.defineProperty(exports, "__esModule", {
4
+ value: true
5
+ });
6
+ exports.LogStream = void 0;
7
+ var _clientCloudwatch = require("@webiny/aws-sdk/client-cloudwatch");
8
+ const cache = new Map();
9
+ class LogStream {
10
+ constructor(logGroupName, logStreamName) {
11
+ this.logGroupName = logGroupName;
12
+ this.logStreamName = logStreamName;
13
+ this.cloudWatchLogs = new _clientCloudwatch.CloudWatchLogs();
14
+ }
15
+ getLogStreamLink() {
16
+ const replacements = [[/\$/g, "$2524"], [/\//g, "$252F"], [/\[/g, "$255B"], [/]/g, "$255D"]];
17
+ const replacer = (value, replacement) => {
18
+ return value.replace(replacement[0], replacement[1]);
19
+ };
20
+ return [`https://${process.env.AWS_REGION}.console.aws.amazon.com/cloudwatch/home?region=${process.env.AWS_REGION}#logsV2:log-groups/log-group/`, replacements.reduce(replacer, this.logGroupName), "/log-events/", replacements.reduce(replacer, this.logStreamName)].join("");
21
+ }
22
+ async printLogsSince(startTime) {
23
+ const params = {
24
+ logStreamName: this.logStreamName,
25
+ logGroupName: this.logGroupName,
26
+ nextToken: this.nextPage,
27
+ startFromHead: true,
28
+ startTime,
29
+ unmask: true
30
+ };
31
+ try {
32
+ const {
33
+ events,
34
+ nextForwardToken
35
+ } = await this.cloudWatchLogs.getLogEvents(params);
36
+ this.nextPage = nextForwardToken;
37
+ if (events) {
38
+ events.forEach(event => {
39
+ process.stdout.write(String(event.message));
40
+ });
41
+ }
42
+ } catch (err) {
43
+ console.log(`Couldn't fetch logs: ${err.message}`);
44
+ }
45
+ }
46
+ static create(logGroupName, logStreamName) {
47
+ const cacheId = `${logGroupName}:${logStreamName}`;
48
+ if (cache.has(cacheId)) {
49
+ return cache.get(cacheId);
50
+ }
51
+ const logStream = new LogStream(logGroupName, logStreamName);
52
+ cache.set(cacheId, logStream);
53
+ return logStream;
54
+ }
55
+ }
56
+ exports.LogStream = LogStream;
57
+
58
+ //# sourceMappingURL=LogStream.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"names":["_clientCloudwatch","require","cache","Map","LogStream","constructor","logGroupName","logStreamName","cloudWatchLogs","CloudWatchLogs","getLogStreamLink","replacements","replacer","value","replacement","replace","process","env","AWS_REGION","reduce","join","printLogsSince","startTime","params","nextToken","nextPage","startFromHead","unmask","events","nextForwardToken","getLogEvents","forEach","event","stdout","write","String","message","err","console","log","create","cacheId","has","get","logStream","set","exports"],"sources":["LogStream.ts"],"sourcesContent":["import type { GetLogEventsRequest } from \"@webiny/aws-sdk/client-cloudwatch\";\nimport { CloudWatchLogs } from \"@webiny/aws-sdk/client-cloudwatch\";\n\nconst cache = new Map<string, LogStream>();\n\nexport class LogStream {\n private readonly logGroupName: string;\n private readonly logStreamName: string;\n private readonly cloudWatchLogs: CloudWatchLogs;\n private nextPage: string | undefined;\n\n private constructor(logGroupName: string, logStreamName: string) {\n this.logGroupName = logGroupName;\n this.logStreamName = logStreamName;\n this.cloudWatchLogs = new CloudWatchLogs();\n }\n\n getLogStreamLink() {\n const replacements = [\n [/\\$/g, \"$2524\"],\n [/\\//g, \"$252F\"],\n [/\\[/g, \"$255B\"],\n [/]/g, \"$255D\"]\n ];\n\n const replacer = (value: string, replacement: (string | RegExp)[]) => {\n return value.replace(replacement[0], replacement[1] as string);\n };\n\n return [\n `https://${process.env.AWS_REGION}.console.aws.amazon.com/cloudwatch/home?region=${process.env.AWS_REGION}#logsV2:log-groups/log-group/`,\n replacements.reduce(replacer, this.logGroupName),\n \"/log-events/\",\n replacements.reduce(replacer, this.logStreamName)\n ].join(\"\");\n }\n\n async printLogsSince(startTime: number): Promise<void> {\n const params: GetLogEventsRequest = {\n logStreamName: this.logStreamName,\n logGroupName: this.logGroupName,\n nextToken: this.nextPage,\n startFromHead: true,\n startTime,\n unmask: true\n };\n\n try {\n const { events, nextForwardToken } = await this.cloudWatchLogs.getLogEvents(params);\n\n this.nextPage = nextForwardToken;\n\n if (events) {\n events.forEach(event => {\n process.stdout.write(String(event.message));\n });\n }\n } catch (err) {\n console.log(`Couldn't fetch logs: ${err.message}`);\n }\n }\n\n public static create(logGroupName: string, logStreamName: string) {\n const cacheId = `${logGroupName}:${logStreamName}`;\n\n if (cache.has(cacheId)) {\n return cache.get(cacheId) as LogStream;\n }\n\n const logStream = new LogStream(logGroupName, logStreamName);\n cache.set(cacheId, logStream);\n\n return logStream;\n }\n}\n"],"mappings":";;;;;;AACA,IAAAA,iBAAA,GAAAC,OAAA;AAEA,MAAMC,KAAK,GAAG,IAAIC,GAAG,CAAoB,CAAC;AAEnC,MAAMC,SAAS,CAAC;EAMXC,WAAWA,CAACC,YAAoB,EAAEC,aAAqB,EAAE;IAC7D,IAAI,CAACD,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AM,CAACG,OAAO,CAACC,KAAK,IAAI;UACpBhB,OAAO,CAACiB,MAAM,CAACC,KAAK,CAACC,MAAM,CAACH,KAAK,CAACI,OAAO,CAAC,CAAC;QAC/C,CAAC,CAAC;MACN;IACJ,CAAC,CAAC,OAAOC,GAAG,EAAE;MACVC,OAAO,CAACC,GAAG,CAAC,wBAAwBF,GAAG,CAACD,OAAO,EAAE,CAAC;IACtD;EACJ;EAEA,OAAcI,MAAMA,CAAClC,YAAoB,EAAEC,aAAqB,EAAE;IAC9D,MAAMkC,OAAO,GAAG,GAAGnC,YAAY,IAAIC,aAAa,EAAE;IAElD,IAAIL,KAAK,CAACwC,GAAG,CAACD,OAAO,CAAC,EAAE;MACpB,OAAOvC,KAAK,CAACyC,GAAG,CAACF,OAAO,CAAC;IAC7B;IAEA,MAAMG,SAAS,GAAG,IAAIxC,SAAS,CAACE,YAAY,EAAEC,aAAa,CAAC;IAC5DL,KAAK,CAAC2C,GAAG,CAACJ,OAAO,EAAEG,SAAS,CAAC;IAE7B,OAAOA,SAAS;EACpB;AACJ;AAACE,OAAA,CAAA1C,SAAA,GAAAA,SAAA","ignoreList":[]}
@@ -0,0 +1,4 @@
1
+ import type { MigrationRunnerResult } from "./MigrationRunner";
2
+ export interface MigrationRunReporter {
3
+ report(result: MigrationRunnerResult): void | Promise<void>;
4
+ }
@@ -0,0 +1,7 @@
1
+ "use strict";
2
+
3
+ Object.defineProperty(exports, "__esModule", {
4
+ value: true
5
+ });
6
+
7
+ //# sourceMappingURL=MigrationRunReporter.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"names":[],"sources":["MigrationRunReporter.ts"],"sourcesContent":["import type { MigrationRunnerResult } from \"~/cli/MigrationRunner\";\n\nexport interface MigrationRunReporter {\n report(result: MigrationRunnerResult): void | Promise<void>;\n}\n"],"mappings":"","ignoreList":[]}
@@ -0,0 +1,45 @@
1
+ import type { LambdaClient } from "@webiny/aws-sdk/client-lambda";
2
+ import type { MigrationStatusReporter } from "./MigrationStatusReporter";
3
+ import type { MigrationInvocationErrorResponse, MigrationStatusResponse } from "../types";
4
+ interface MigrationRunnerConfig {
5
+ lambdaClient: LambdaClient;
6
+ functionName: string;
7
+ statusReporter?: MigrationStatusReporter;
8
+ }
9
+ interface MigrationPayload {
10
+ version: string;
11
+ pattern?: string;
12
+ force?: boolean;
13
+ }
14
+ interface SuccessResultHandler {
15
+ (result: MigrationStatusResponse["data"]): void | Promise<void>;
16
+ }
17
+ interface ErrorResultHandler {
18
+ (error: MigrationInvocationErrorResponse["error"]): void | Promise<void>;
19
+ }
20
+ export declare class MigrationRunnerResult {
21
+ private readonly functionName;
22
+ private readonly result;
23
+ private readonly successBranch;
24
+ private readonly errorBranch;
25
+ constructor(functionName: string, result: MigrationStatusResponse | MigrationInvocationErrorResponse);
26
+ getFunctionName(): string;
27
+ onSuccess(cb: SuccessResultHandler): void;
28
+ onError(cb: ErrorResultHandler): void;
29
+ process(): Promise<void>;
30
+ }
31
+ export declare class MigrationRunner {
32
+ private readonly lambdaClient;
33
+ private readonly functionName;
34
+ private statusReporter;
35
+ static create(params: MigrationRunnerConfig): MigrationRunner;
36
+ private constructor();
37
+ setStatusReporter(reporter: MigrationStatusReporter): void;
38
+ runMigration(payload: MigrationPayload): Promise<MigrationRunnerResult>;
39
+ private reportStatus;
40
+ private invokeMigration;
41
+ private getResult;
42
+ private getStatus;
43
+ private getMigrationStatusReportInterval;
44
+ }
45
+ export {};
@@ -0,0 +1,136 @@
1
+ "use strict";
2
+
3
+ Object.defineProperty(exports, "__esModule", {
4
+ value: true
5
+ });
6
+ exports.MigrationRunnerResult = exports.MigrationRunner = void 0;
7
+ var _clientLambda = require("@webiny/aws-sdk/client-lambda");
8
+ var _utils = require("@webiny/utils");
9
+ var _VoidStatusReporter = require("./VoidStatusReporter");
10
+ class MigrationRunnerResult {
11
+ successBranch = [];
12
+ errorBranch = [];
13
+ constructor(functionName, result) {
14
+ this.functionName = functionName;
15
+ this.result = result;
16
+ }
17
+ getFunctionName() {
18
+ return this.functionName;
19
+ }
20
+ onSuccess(cb) {
21
+ this.successBranch.push(cb);
22
+ }
23
+ onError(cb) {
24
+ this.errorBranch.push(cb);
25
+ }
26
+ async process() {
27
+ if (this.result.error) {
28
+ for (const handler of this.errorBranch) {
29
+ await handler(this.result.error);
30
+ }
31
+ return;
32
+ }
33
+ for (const handler of this.successBranch) {
34
+ await handler(this.result.data);
35
+ }
36
+ }
37
+ }
38
+ exports.MigrationRunnerResult = MigrationRunnerResult;
39
+ class MigrationRunner {
40
+ statusReporter = new _VoidStatusReporter.VoidStatusReporter();
41
+ static create(params) {
42
+ const runner = new MigrationRunner(params.lambdaClient, params.functionName);
43
+ if (params.statusReporter) {
44
+ runner.setStatusReporter(params.statusReporter);
45
+ }
46
+ return runner;
47
+ }
48
+ constructor(lambdaClient, functionName) {
49
+ this.lambdaClient = lambdaClient;
50
+ this.functionName = functionName;
51
+ }
52
+ setStatusReporter(reporter) {
53
+ this.statusReporter = reporter;
54
+ }
55
+ async runMigration(payload) {
56
+ // Execute migration function.
57
+ await this.invokeMigration(payload);
58
+
59
+ // Poll for status and re-execute when migration is in "pending" state.
60
+ let response;
61
+ while (true) {
62
+ await new Promise(resolve => setTimeout(resolve, this.getMigrationStatusReportInterval()));
63
+ response = await this.getStatus(payload);
64
+ if (!response) {
65
+ continue;
66
+ }
67
+ const {
68
+ data,
69
+ error
70
+ } = response;
71
+
72
+ // If we received an error, it must be an unrecoverable error, and we don't retry.
73
+ if (error) {
74
+ return this.getResult(response);
75
+ }
76
+ switch (data.status) {
77
+ case "init":
78
+ await this.reportStatus(data);
79
+ continue;
80
+ case "pending":
81
+ await this.invokeMigration(payload);
82
+ break;
83
+ case "running":
84
+ await this.reportStatus(data);
85
+ break;
86
+ case "done":
87
+ await this.reportStatus(data);
88
+ return this.getResult(response);
89
+ default:
90
+ return this.getResult(response);
91
+ }
92
+ }
93
+ }
94
+ async reportStatus(data) {
95
+ await this.statusReporter.report(data);
96
+ }
97
+ async invokeMigration(payload) {
98
+ const response = await this.lambdaClient.send(new _clientLambda.InvokeCommand({
99
+ FunctionName: this.functionName,
100
+ InvocationType: "Event",
101
+ Payload: JSON.stringify({
102
+ ...payload,
103
+ command: "execute"
104
+ })
105
+ }));
106
+ return response.StatusCode;
107
+ }
108
+ getResult(response) {
109
+ return new MigrationRunnerResult(this.functionName, response);
110
+ }
111
+ async getStatus(payload) {
112
+ const getStatus = () => {
113
+ return this.lambdaClient.send(new _clientLambda.InvokeCommand({
114
+ FunctionName: this.functionName,
115
+ InvocationType: "RequestResponse",
116
+ Payload: JSON.stringify({
117
+ ...payload,
118
+ command: "status"
119
+ })
120
+ }));
121
+ };
122
+ const response = await (0, _utils.executeWithRetry)(getStatus);
123
+ const decoder = new TextDecoder("utf-8");
124
+ return JSON.parse(decoder.decode(response.Payload));
125
+ }
126
+ getMigrationStatusReportInterval() {
127
+ const envKey = "MIGRATION_STATUS_REPORT_INTERVAL";
128
+ if (envKey in process.env) {
129
+ return parseInt(String(process.env[envKey]));
130
+ }
131
+ return 2000;
132
+ }
133
+ }
134
+ exports.MigrationRunner = MigrationRunner;
135
+
136
+ //# sourceMappingURL=MigrationRunner.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"names":["_clientLambda","require","_utils","_VoidStatusReporter","MigrationRunnerResult","successBranch","errorBranch","constructor","functionName","result","getFunctionName","onSuccess","cb","push","onError","process","error","handler","data","exports","MigrationRunner","statusReporter","VoidStatusReporter","create","params","runner","lambdaClient","setStatusReporter","reporter","runMigration","payload","invokeMigration","response","Promise","resolve","setTimeout","getMigrationStatusReportInterval","getStatus","getResult","status","reportStatus","report","send","InvokeCommand","FunctionName","InvocationType","Payload","JSON","stringify","command","StatusCode","executeWithRetry","decoder","TextDecoder","parse","decode","envKey","env","parseInt","String"],"sources":["MigrationRunner.ts"],"sourcesContent":["import type { LambdaClient } from \"@webiny/aws-sdk/client-lambda\";\nimport { InvokeCommand } from \"@webiny/aws-sdk/client-lambda\";\nimport type { MigrationStatusReporter } from \"~/cli/MigrationStatusReporter\";\nimport type {\n MigrationEventHandlerResponse,\n MigrationInvocationErrorResponse,\n MigrationStatus,\n MigrationStatusResponse\n} from \"~/types\";\nimport { executeWithRetry } from \"@webiny/utils\";\nimport { VoidStatusReporter } from \"./VoidStatusReporter\";\n\ninterface MigrationRunnerConfig {\n lambdaClient: LambdaClient;\n functionName: string;\n statusReporter?: MigrationStatusReporter;\n}\n\ninterface MigrationPayload {\n version: string;\n pattern?: string;\n force?: boolean;\n}\n\ninterface SuccessResultHandler {\n (result: MigrationStatusResponse[\"data\"]): void | Promise<void>;\n}\n\ninterface ErrorResultHandler {\n (error: MigrationInvocationErrorResponse[\"error\"]): void | Promise<void>;\n}\n\nexport class MigrationRunnerResult {\n private readonly functionName: string;\n private readonly result: MigrationStatusResponse | MigrationInvocationErrorResponse;\n private readonly successBranch: SuccessResultHandler[] = [];\n private readonly errorBranch: ErrorResultHandler[] = [];\n\n constructor(\n functionName: string,\n result: MigrationStatusResponse | MigrationInvocationErrorResponse\n ) {\n this.functionName = functionName;\n this.result = result;\n }\n\n getFunctionName() {\n return this.functionName;\n }\n\n onSuccess(cb: SuccessResultHandler) {\n this.successBranch.push(cb);\n }\n\n onError(cb: ErrorResultHandler) {\n this.errorBranch.push(cb);\n }\n\n async process(): Promise<void> {\n if (this.result.error) {\n for (const handler of this.errorBranch) {\n await handler(this.result.error);\n }\n return;\n }\n\n for (const handler of this.successBranch) {\n await handler(this.result.data);\n }\n }\n}\n\nexport class MigrationRunner {\n private readonly lambdaClient: LambdaClient;\n private readonly functionName: string;\n private statusReporter: MigrationStatusReporter = new VoidStatusReporter();\n\n public static create(params: MigrationRunnerConfig) {\n const runner = new MigrationRunner(params.lambdaClient, params.functionName);\n if (params.statusReporter) {\n runner.setStatusReporter(params.statusReporter);\n }\n return runner;\n }\n\n private constructor(lambdaClient: LambdaClient, functionName: string) {\n this.lambdaClient = lambdaClient;\n this.functionName = functionName;\n }\n\n public setStatusReporter(reporter: MigrationStatusReporter) {\n this.statusReporter = reporter;\n }\n\n async runMigration(payload: MigrationPayload): Promise<MigrationRunnerResult> {\n // Execute migration function.\n await this.invokeMigration(payload);\n\n // Poll for status and re-execute when migration is in \"pending\" state.\n let response: MigrationEventHandlerResponse;\n\n while (true) {\n await new Promise(resolve =>\n setTimeout(resolve, this.getMigrationStatusReportInterval())\n );\n\n response = await this.getStatus(payload);\n\n if (!response) {\n continue;\n }\n\n const { data, error } = response;\n\n // If we received an error, it must be an unrecoverable error, and we don't retry.\n if (error) {\n return this.getResult(response);\n }\n\n switch (data.status) {\n case \"init\":\n await this.reportStatus(data);\n continue;\n case \"pending\":\n await this.invokeMigration(payload);\n break;\n case \"running\":\n await this.reportStatus(data);\n break;\n case \"done\":\n await this.reportStatus(data);\n return this.getResult(response);\n default:\n return this.getResult(response);\n }\n }\n }\n\n private async reportStatus(data: MigrationStatus) {\n await this.statusReporter.report(data);\n }\n\n private async invokeMigration(payload: MigrationPayload) {\n const response = await this.lambdaClient.send(\n new InvokeCommand({\n FunctionName: this.functionName,\n InvocationType: \"Event\",\n Payload: JSON.stringify({ ...payload, command: \"execute\" })\n })\n );\n\n return response.StatusCode;\n }\n\n private getResult(response: MigrationStatusResponse | MigrationInvocationErrorResponse) {\n return new MigrationRunnerResult(this.functionName, response);\n }\n\n private async getStatus(payload: Record<string, any>) {\n const getStatus = () => {\n return this.lambdaClient.send(\n new InvokeCommand({\n FunctionName: this.functionName,\n InvocationType: \"RequestResponse\",\n Payload: JSON.stringify({ ...payload, command: \"status\" })\n })\n );\n };\n\n const response = await executeWithRetry(getStatus);\n\n const decoder = new TextDecoder(\"utf-8\");\n return JSON.parse(decoder.decode(response.Payload)) as MigrationEventHandlerResponse;\n }\n\n private getMigrationStatusReportInterval() {\n const envKey = \"MIGRATION_STATUS_REPORT_INTERVAL\";\n if (envKey in process.env) {\n return parseInt(String(process.env[envKey]));\n }\n return 2000;\n }\n}\n"],"mappings":";;;;;;AACA,IAAAA,aAAA,GAAAC,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C,GAAG,EAAE;MACvB,OAAOC,QAAQ,CAACC,MAAM,CAAC5C,OAAO,CAAC0C,GAAG,CAACD,MAAM,CAAC,CAAC,CAAC;IAChD;IACA,OAAO,IAAI;EACf;AACJ;AAACrC,OAAA,CAAAC,eAAA,GAAAA,eAAA","ignoreList":[]}
@@ -0,0 +1,4 @@
1
+ import type { MigrationStatus } from "../types";
2
+ export interface MigrationStatusReporter {
3
+ report(status: MigrationStatus): void;
4
+ }
@@ -0,0 +1,7 @@
1
+ "use strict";
2
+
3
+ Object.defineProperty(exports, "__esModule", {
4
+ value: true
5
+ });
6
+
7
+ //# sourceMappingURL=MigrationStatusReporter.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"names":[],"sources":["MigrationStatusReporter.ts"],"sourcesContent":["import type { MigrationStatus } from \"~/types\";\n\nexport interface MigrationStatusReporter {\n report(status: MigrationStatus): void;\n}\n"],"mappings":"","ignoreList":[]}
@@ -0,0 +1,9 @@
1
+ import type { MigrationStatusReporter } from "./MigrationStatusReporter";
2
+ import type { MigrationStatus } from "../types";
3
+ import type { LogReporter } from "./LogReporter";
4
+ export declare class NonInteractiveCliStatusReporter implements MigrationStatusReporter {
5
+ private logReporter;
6
+ private firstCall;
7
+ constructor(logReporter: LogReporter);
8
+ report(migrationStatus: MigrationStatus): Promise<void>;
9
+ }
@@ -0,0 +1,42 @@
1
+ "use strict";
2
+
3
+ Object.defineProperty(exports, "__esModule", {
4
+ value: true
5
+ });
6
+ exports.NonInteractiveCliStatusReporter = void 0;
7
+ class NonInteractiveCliStatusReporter {
8
+ firstCall = true;
9
+ constructor(logReporter) {
10
+ this.logReporter = logReporter;
11
+ console.log(`Using "NonInteractiveCliStatusReporter".`);
12
+ }
13
+ async report(migrationStatus) {
14
+ const {
15
+ status,
16
+ context
17
+ } = migrationStatus;
18
+ const currentLogStreamName = context?.logStreamName;
19
+ if (currentLogStreamName) {
20
+ this.logReporter.initializeStream(currentLogStreamName);
21
+ if (this.firstCall) {
22
+ this.logReporter.printLogStreamLinks();
23
+ process.stdout.write(`\n---------- MIGRATION LOGS START ----------\n\n`);
24
+ }
25
+ await this.logReporter.printLogs(currentLogStreamName);
26
+ }
27
+ if (["done", "error"].includes(status)) {
28
+ // We want to give AWS some time for the latest log events to become available.
29
+ await new Promise(resolve => {
30
+ setTimeout(resolve, 10000);
31
+ });
32
+ if (currentLogStreamName) {
33
+ await this.logReporter.printLogs(currentLogStreamName);
34
+ process.stdout.write(`\n---------- MIGRATION LOGS END ----------\n`);
35
+ }
36
+ }
37
+ this.firstCall = false;
38
+ }
39
+ }
40
+ exports.NonInteractiveCliStatusReporter = NonInteractiveCliStatusReporter;
41
+
42
+ //# sourceMappingURL=NonInteractiveCliStatusReporter.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"names":["NonInteractiveCliStatusReporter","firstCall","constructor","logReporter","console","log","report","migrationStatus","status","context","currentLogStreamName","logStreamName","initializeStream","printLogStreamLinks","process","stdout","write","printLogs","includes","Promise","resolve","setTimeout","exports"],"sources":["NonInteractiveCliStatusReporter.ts"],"sourcesContent":["import type { MigrationStatusReporter } from \"~/cli/MigrationStatusReporter\";\nimport type { MigrationStatus } from \"~/types\";\nimport type { LogReporter } from \"~/cli/LogReporter\";\n\nexport class NonInteractiveCliStatusReporter implements MigrationStatusReporter {\n private logReporter: LogReporter;\n private firstCall = true;\n\n constructor(logReporter: LogReporter) {\n this.logReporter = logReporter;\n console.log(`Using \"NonInteractiveCliStatusReporter\".`);\n }\n\n async report(migrationStatus: MigrationStatus) {\n const { status, context } = migrationStatus;\n\n const currentLogStreamName = context?.logStreamName;\n\n if (currentLogStreamName) {\n this.logReporter.initializeStream(currentLogStreamName);\n if (this.firstCall) {\n this.logReporter.printLogStreamLinks();\n process.stdout.write(`\\n---------- MIGRATION LOGS START ----------\\n\\n`);\n }\n await this.logReporter.printLogs(currentLogStreamName);\n }\n\n if ([\"done\", \"error\"].includes(status)) {\n // We want to give AWS some time for the latest log events to become available.\n await new Promise(resolve => {\n setTimeout(resolve, 10000);\n });\n\n if (currentLogStreamName) {\n await this.logReporter.printLogs(currentLogStreamName);\n process.stdout.write(`\\n---------- MIGRATION LOGS END ----------\\n`);\n }\n }\n\n this.firstCall = false;\n }\n}\n"],"mappings":";;;;;;AAIO,MAAMA,+BAA+B,CAAoC;EAEpEC,SAAS,GAAG,IAAI;EAExBC,WAAWA,CAACC,WAAwB,EAAE;IAClC,IAAI,CAACA,WAAW,GAAGA,WAAW;IAC9BC,OAAO,CAACC,GAAG,CAAC,0CAA0C,CAAC;EAC3D;EAEA,MAAMC,MAAMA,CAACC,eAAgC,EAAE;IAC3C,MAAM;MAAEC,MAAM;MAAEC;IAAQ,CAAC,GAAGF,eAAe;IAE3C,MAAMG,oBAAoB,GAAGD,OAAO,EAAEE,aAAa;IAEnD,IAAID,oBAAoB,EAAE;MACtB,IAAI,CAACP,WAAW,CAACS,gBAAgB,CAACF,oBAAoB,CAAC;MACvD,IAAI,IAAI,CAACT,SAAS,EAAE;QAChB,IAAI,CAACE,WAAW,CAACU,mBAAmB,CAAC,CAAC;QACtCC,OAAO,CAACC,MAAM,CAACC,KAAK,CAAC,kDAAkD,CAAC;MAC5E;MACA,MAAM,IAAI,CAACb,WAAW,CAACc,SAAS,CAACP,oBAAoB,CAAC;IAC1D;IAEA,IAAI,CAAC,MAAM,EAAE,OAAO,CAAC,CAACQ,QAAQ,CAACV,MAAM,CAAC,EAAE;MACpC;MACA,MAAM,IAAIW,OAAO,CAACC,OAAO,IAAI;QACzBC,UAAU,CAACD,OAAO,EAAE,KAAK,CAAC;MAC9B,CAAC,CAAC;MAEF,IAAIV,oBAAoB,EAAE;QACtB,MAAM,IAAI,CAACP,WAAW,CAACc,SAAS,CAACP,oBAAoB,CAAC;QACtDI,OAAO,CAACC,MAAM,CAACC,KAAK,CAAC,8CAA8C,CAAC;MACxE;IACJ;IAEA,IAAI,CAACf,SAAS,GAAG,KAAK;EAC1B;AACJ;AAACqB,OAAA,CAAAtB,+BAAA,GAAAA,+BAAA","ignoreList":[]}
@@ -0,0 +1,4 @@
1
+ import type { MigrationStatusReporter } from "./MigrationStatusReporter";
2
+ export declare class VoidStatusReporter implements MigrationStatusReporter {
3
+ report(): void;
4
+ }
@@ -0,0 +1,14 @@
1
+ "use strict";
2
+
3
+ Object.defineProperty(exports, "__esModule", {
4
+ value: true
5
+ });
6
+ exports.VoidStatusReporter = void 0;
7
+ class VoidStatusReporter {
8
+ report() {
9
+ // This is a void reporter.
10
+ }
11
+ }
12
+ exports.VoidStatusReporter = VoidStatusReporter;
13
+
14
+ //# sourceMappingURL=VoidStatusReporter.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"names":["VoidStatusReporter","report","exports"],"sources":["VoidStatusReporter.ts"],"sourcesContent":["import type { MigrationStatusReporter } from \"./MigrationStatusReporter\";\n\nexport class VoidStatusReporter implements MigrationStatusReporter {\n report(): void {\n // This is a void reporter.\n }\n}\n"],"mappings":";;;;;;AAEO,MAAMA,kBAAkB,CAAoC;EAC/DC,MAAMA,CAAA,EAAS;IACX;EAAA;AAER;AAACC,OAAA,CAAAF,kBAAA,GAAAA,kBAAA","ignoreList":[]}
@@ -0,0 +1,5 @@
1
+ /**
2
+ * Get duration since the given ISO timestamp.
3
+ * @param string since
4
+ */
5
+ export declare const getDuration: (since: string) => string;
@@ -0,0 +1,23 @@
1
+ "use strict";
2
+
3
+ Object.defineProperty(exports, "__esModule", {
4
+ value: true
5
+ });
6
+ exports.getDuration = void 0;
7
+ /**
8
+ * Get duration since the given ISO timestamp.
9
+ * @param string since
10
+ */
11
+ const getDuration = since => {
12
+ const ms = new Date().getTime() - new Date(since).getTime();
13
+ let seconds = Math.floor(ms / 1000);
14
+ let minutes = undefined;
15
+ if (seconds > 60) {
16
+ minutes = Math.floor(seconds / 60);
17
+ seconds = Math.floor(seconds % 60);
18
+ }
19
+ return minutes ? `${minutes}m ${seconds}s` : `${seconds}s`;
20
+ };
21
+ exports.getDuration = getDuration;
22
+
23
+ //# sourceMappingURL=getDuration.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"names":["getDuration","since","ms","Date","getTime","seconds","Math","floor","minutes","undefined","exports"],"sources":["getDuration.ts"],"sourcesContent":["/**\n * Get duration since the given ISO timestamp.\n * @param string since\n */\nexport const getDuration = (since: string) => {\n const ms = new Date().getTime() - new Date(since).getTime();\n let seconds = Math.floor(ms / 1000);\n let minutes = undefined;\n if (seconds > 60) {\n minutes = Math.floor(seconds / 60);\n seconds = Math.floor(seconds % 60);\n }\n\n return minutes ? `${minutes}m ${seconds}s` : `${seconds}s`;\n};\n"],"mappings":";;;;;;AAAA;AACA;AACA;AACA;AACO,MAAMA,WAAW,GAAIC,KAAa,IAAK;EAC1C,MAAMC,EAAE,GAAG,IAAIC,IAAI,CAAC,CAAC,CAACC,OAAO,CAAC,CAAC,GAAG,IAAID,IAAI,CAACF,KAAK,CAAC,CAACG,OAAO,CAAC,CAAC;EAC3D,IAAIC,OAAO,GAAGC,IAAI,CAACC,KAAK,CAACL,EAAE,GAAG,IAAI,CAAC;EACnC,IAAIM,OAAO,GAAGC,SAAS;EACvB,IAAIJ,OAAO,GAAG,EAAE,EAAE;IACdG,OAAO,GAAGF,IAAI,CAACC,KAAK,CAACF,OAAO,GAAG,EAAE,CAAC;IAClCA,OAAO,GAAGC,IAAI,CAACC,KAAK,CAACF,OAAO,GAAG,EAAE,CAAC;EACtC;EAEA,OAAOG,OAAO,GAAG,GAAGA,OAAO,KAAKH,OAAO,GAAG,GAAG,GAAGA,OAAO,GAAG;AAC9D,CAAC;AAACK,OAAA,CAAAV,WAAA,GAAAA,WAAA","ignoreList":[]}
package/cli/index.d.ts ADDED
@@ -0,0 +1,10 @@
1
+ export * from "./getDuration";
2
+ export * from "./MigrationRunner";
3
+ export * from "./MigrationStatusReporter";
4
+ export * from "./MigrationRunReporter";
5
+ export * from "./InteractiveCliStatusReporter";
6
+ export * from "./NonInteractiveCliStatusReporter";
7
+ export * from "./VoidStatusReporter";
8
+ export * from "./CliMigrationRunReporter";
9
+ export * from "./LogStream";
10
+ export * from "./LogReporter";
package/cli/index.js ADDED
@@ -0,0 +1,117 @@
1
+ "use strict";
2
+
3
+ Object.defineProperty(exports, "__esModule", {
4
+ value: true
5
+ });
6
+ var _getDuration = require("./getDuration");
7
+ Object.keys(_getDuration).forEach(function (key) {
8
+ if (key === "default" || key === "__esModule") return;
9
+ if (key in exports && exports[key] === _getDuration[key]) return;
10
+ Object.defineProperty(exports, key, {
11
+ enumerable: true,
12
+ get: function () {
13
+ return _getDuration[key];
14
+ }
15
+ });
16
+ });
17
+ var _MigrationRunner = require("./MigrationRunner");
18
+ Object.keys(_MigrationRunner).forEach(function (key) {
19
+ if (key === "default" || key === "__esModule") return;
20
+ if (key in exports && exports[key] === _MigrationRunner[key]) return;
21
+ Object.defineProperty(exports, key, {
22
+ enumerable: true,
23
+ get: function () {
24
+ return _MigrationRunner[key];
25
+ }
26
+ });
27
+ });
28
+ var _MigrationStatusReporter = require("./MigrationStatusReporter");
29
+ Object.keys(_MigrationStatusReporter).forEach(function (key) {
30
+ if (key === "default" || key === "__esModule") return;
31
+ if (key in exports && exports[key] === _MigrationStatusReporter[key]) return;
32
+ Object.defineProperty(exports, key, {
33
+ enumerable: true,
34
+ get: function () {
35
+ return _MigrationStatusReporter[key];
36
+ }
37
+ });
38
+ });
39
+ var _MigrationRunReporter = require("./MigrationRunReporter");
40
+ Object.keys(_MigrationRunReporter).forEach(function (key) {
41
+ if (key === "default" || key === "__esModule") return;
42
+ if (key in exports && exports[key] === _MigrationRunReporter[key]) return;
43
+ Object.defineProperty(exports, key, {
44
+ enumerable: true,
45
+ get: function () {
46
+ return _MigrationRunReporter[key];
47
+ }
48
+ });
49
+ });
50
+ var _InteractiveCliStatusReporter = require("./InteractiveCliStatusReporter");
51
+ Object.keys(_InteractiveCliStatusReporter).forEach(function (key) {
52
+ if (key === "default" || key === "__esModule") return;
53
+ if (key in exports && exports[key] === _InteractiveCliStatusReporter[key]) return;
54
+ Object.defineProperty(exports, key, {
55
+ enumerable: true,
56
+ get: function () {
57
+ return _InteractiveCliStatusReporter[key];
58
+ }
59
+ });
60
+ });
61
+ var _NonInteractiveCliStatusReporter = require("./NonInteractiveCliStatusReporter");
62
+ Object.keys(_NonInteractiveCliStatusReporter).forEach(function (key) {
63
+ if (key === "default" || key === "__esModule") return;
64
+ if (key in exports && exports[key] === _NonInteractiveCliStatusReporter[key]) return;
65
+ Object.defineProperty(exports, key, {
66
+ enumerable: true,
67
+ get: function () {
68
+ return _NonInteractiveCliStatusReporter[key];
69
+ }
70
+ });
71
+ });
72
+ var _VoidStatusReporter = require("./VoidStatusReporter");
73
+ Object.keys(_VoidStatusReporter).forEach(function (key) {
74
+ if (key === "default" || key === "__esModule") return;
75
+ if (key in exports && exports[key] === _VoidStatusReporter[key]) return;
76
+ Object.defineProperty(exports, key, {
77
+ enumerable: true,
78
+ get: function () {
79
+ return _VoidStatusReporter[key];
80
+ }
81
+ });
82
+ });
83
+ var _CliMigrationRunReporter = require("./CliMigrationRunReporter");
84
+ Object.keys(_CliMigrationRunReporter).forEach(function (key) {
85
+ if (key === "default" || key === "__esModule") return;
86
+ if (key in exports && exports[key] === _CliMigrationRunReporter[key]) return;
87
+ Object.defineProperty(exports, key, {
88
+ enumerable: true,
89
+ get: function () {
90
+ return _CliMigrationRunReporter[key];
91
+ }
92
+ });
93
+ });
94
+ var _LogStream = require("./LogStream");
95
+ Object.keys(_LogStream).forEach(function (key) {
96
+ if (key === "default" || key === "__esModule") return;
97
+ if (key in exports && exports[key] === _LogStream[key]) return;
98
+ Object.defineProperty(exports, key, {
99
+ enumerable: true,
100
+ get: function () {
101
+ return _LogStream[key];
102
+ }
103
+ });
104
+ });
105
+ var _LogReporter = require("./LogReporter");
106
+ Object.keys(_LogReporter).forEach(function (key) {
107
+ if (key === "default" || key === "__esModule") return;
108
+ if (key in exports && exports[key] === _LogReporter[key]) return;
109
+ Object.defineProperty(exports, key, {
110
+ enumerable: true,
111
+ get: function () {
112
+ return _LogReporter[key];
113
+ }
114
+ });
115
+ });
116
+
117
+ //# sourceMappingURL=index.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"names":["_getDuration","require","Object","keys","forEach","key","exports","defineProperty","enumerable","get","_MigrationRunner","_MigrationStatusReporter","_MigrationRunReporter","_InteractiveCliStatusReporter","_NonInteractiveCliStatusReporter","_VoidStatusReporter","_CliMigrationRunReporter","_LogStream","_LogReporter"],"sources":["index.ts"],"sourcesContent":["export * from \"./getDuration\";\nexport * from \"./MigrationRunner\";\nexport * from \"./MigrationStatusReporter\";\nexport * from \"./MigrationRunReporter\";\nexport * from \"./InteractiveCliStatusReporter\";\nexport * from \"./NonInteractiveCliStatusReporter\";\nexport * from \"./VoidStatusReporter\";\nexport * from \"./CliMigrationRunReporter\";\nexport * from \"./LogStream\";\nexport * from \"./LogReporter\";\n"],"mappings":";;;;;AAAA,IAAAA,YAAA,GAAAC,OAAA;AAAAC,MAAA,CAAAC,IAAA,CAAAH,YAAA,EAAAI,OAAA,WAAAC,GAAA;EAAA,IAAAA,GAAA,kBAAAA,GAAA;EAAA,IAAAA,GAAA,IAAAC,OAAA,IAAAA,OAAA,CAAAD,GAAA,MAAAL,YAAA,CAAAK,GAAA;EAAAH,MAAA,CAAAK,cAAA,CAAAD,OAAA,EAAAD,GAAA;IAAAG,UAAA;IAAAC,GAAA,WAAAA,CAAA;MAAA,OAAAT,YAAA,CAAAK,GAAA;IAAA;EAAA;AAAA;AACA,IAAAK,gBAAA,GAAAT,OAAA;AAAAC,MAAA,CAAAC,IAAA,CAAAO,gBAAA,EAAAN,OAAA,WAAAC,GAAA;EAAA,IAAAA,GAAA,kBAAAA,GAAA;EAAA,IAAAA,GAAA,IAAAC,OAAA,IAAAA,OAAA,CAAAD,GAAA,MAAAK,gBAAA,CAAAL,GAAA;EAAAH,MAAA,CAAAK,cAAA,CAAAD,OAAA,EAAAD,GAAA;IAAAG,UAAA;IAAAC,GAAA,WAAAA,CAAA;MAAA,OAAAC,gBAAA,CAAAL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CAAAD,OAAA,EAAAD,GAAA;IAAAG,UAAA;IAAAC,GAAA,WAAAA,CAAA;MAAA,OAAAQ,UAAA,CAAAZ,GAAA;IAAA;EAAA;AAAA;AACA,IAAAa,YAAA,GAAAjB,OAAA;AAAAC,MAAA,CAAAC,IAAA,CAAAe,YAAA,EAAAd,OAAA,WAAAC,GAAA;EAAA,IAAAA,GAAA,kBAAAA,GAAA;EAAA,IAAAA,GAAA,IAAAC,OAAA,IAAAA,OAAA,CAAAD,GAAA,MAAAa,YAAA,CAAAb,GAAA;EAAAH,MAAA,CAAAK,cAAA,CAAAD,OAAA,EAAAD,GAAA;IAAAG,UAAA;IAAAC,GAAA,WAAAA,CAAA;MAAA,OAAAS,YAAA,CAAAb,GAAA;IAAA;EAAA;AAAA","ignoreList":[]}
@@ -0,0 +1,4 @@
1
+ import type { DataMigration } from "./types";
2
+ import type { Logger } from "@webiny/logger";
3
+ export declare const createPinoLogger: () => Logger;
4
+ export declare const getChildLogger: (logger: Logger, migration: DataMigration) => import("pino").default.Logger<never>;