@webiny/data-migration 0.0.0-unstable.aa00eecd97 → 0.0.0-unstable.ac6ebf63c6

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/MigrationRunner.d.ts +8 -4
  2. package/MigrationRunner.js +109 -50
  3. package/MigrationRunner.js.map +1 -1
  4. package/README.md +9 -4
  5. package/cli/CliMigrationRunReporter.d.ts +13 -0
  6. package/cli/CliMigrationRunReporter.js +50 -0
  7. package/cli/CliMigrationRunReporter.js.map +1 -0
  8. package/cli/InteractiveCliStatusReporter.d.ts +11 -0
  9. package/cli/InteractiveCliStatusReporter.js +66 -0
  10. package/cli/InteractiveCliStatusReporter.js.map +1 -0
  11. package/cli/LogReporter.d.ts +10 -0
  12. package/cli/LogReporter.js +36 -0
  13. package/cli/LogReporter.js.map +1 -0
  14. package/cli/LogStream.d.ts +10 -0
  15. package/cli/LogStream.js +51 -0
  16. package/cli/LogStream.js.map +1 -0
  17. package/cli/MigrationRunReporter.d.ts +4 -0
  18. package/cli/MigrationRunReporter.js +3 -0
  19. package/cli/MigrationRunReporter.js.map +1 -0
  20. package/cli/MigrationRunner.d.ts +45 -0
  21. package/cli/MigrationRunner.js +128 -0
  22. package/cli/MigrationRunner.js.map +1 -0
  23. package/cli/MigrationStatusReporter.d.ts +4 -0
  24. package/cli/MigrationStatusReporter.js +3 -0
  25. package/cli/MigrationStatusReporter.js.map +1 -0
  26. package/cli/NonInteractiveCliStatusReporter.d.ts +9 -0
  27. package/cli/NonInteractiveCliStatusReporter.js +35 -0
  28. package/cli/NonInteractiveCliStatusReporter.js.map +1 -0
  29. package/cli/VoidStatusReporter.d.ts +4 -0
  30. package/cli/VoidStatusReporter.js +7 -0
  31. package/cli/VoidStatusReporter.js.map +1 -0
  32. package/cli/getDuration.js +3 -8
  33. package/cli/getDuration.js.map +1 -1
  34. package/cli/index.d.ts +10 -3
  35. package/cli/index.js +11 -37
  36. package/cli/index.js.map +1 -1
  37. package/createPinoLogger.d.ts +4 -7
  38. package/createPinoLogger.js +11 -16
  39. package/createPinoLogger.js.map +1 -1
  40. package/createTable.d.ts +4 -4
  41. package/createTable.js +8 -11
  42. package/createTable.js.map +1 -1
  43. package/handlers/createDdbEsProjectMigration.d.ts +7 -7
  44. package/handlers/createDdbEsProjectMigration.js +41 -45
  45. package/handlers/createDdbEsProjectMigration.js.map +1 -1
  46. package/handlers/createDdbProjectMigration.d.ts +5 -5
  47. package/handlers/createDdbProjectMigration.js +37 -41
  48. package/handlers/createDdbProjectMigration.js.map +1 -1
  49. package/handlers/createPatternMatcher.d.ts +1 -1
  50. package/handlers/createPatternMatcher.js +5 -11
  51. package/handlers/createPatternMatcher.js.map +1 -1
  52. package/handlers/devVersionErrorResponse.js +3 -8
  53. package/handlers/devVersionErrorResponse.js.map +1 -1
  54. package/index.d.ts +6 -7
  55. package/index.js +7 -70
  56. package/index.js.map +1 -1
  57. package/package.json +19 -35
  58. package/repository/migrations.repository.d.ts +3 -3
  59. package/repository/migrations.repository.js +18 -31
  60. package/repository/migrations.repository.js.map +1 -1
  61. package/symbols.js +8 -19
  62. package/symbols.js.map +1 -1
  63. package/types.d.ts +9 -6
  64. package/types.js +2 -11
  65. package/types.js.map +1 -1
  66. package/cli/getMigrationStatus.d.ts +0 -9
  67. package/cli/getMigrationStatus.js +0 -27
  68. package/cli/getMigrationStatus.js.map +0 -1
  69. package/cli/printReport.d.ts +0 -9
  70. package/cli/printReport.js +0 -57
  71. package/cli/printReport.js.map +0 -1
  72. package/cli/runMigration.d.ts +0 -13
  73. package/cli/runMigration.js +0 -85
  74. package/cli/runMigration.js.map +0 -1
  75. package/createId.d.ts +0 -1
  76. package/createId.js +0 -14
  77. package/createId.js.map +0 -1
  78. package/repository/createStandardEntity.d.ts +0 -5
  79. package/repository/createStandardEntity.js +0 -37
  80. package/repository/createStandardEntity.js.map +0 -1
@@ -0,0 +1,36 @@
1
+ import { LogStream } from "./LogStream.js";
2
+ export class LogReporter {
3
+ logStreams = new Set();
4
+ constructor(functionName) {
5
+ const baseName = functionName.split(":").pop();
6
+ this.logGroupName = `/aws/lambda/${baseName}`;
7
+ this.logsCreatedSince = Date.now();
8
+ }
9
+ async printLogs(logStreamName) {
10
+ const logStream = this.initializeStream(logStreamName);
11
+ await logStream.printLogsSince(this.logsCreatedSince);
12
+ }
13
+ printLogStreamLinks() {
14
+ if (this.logStreams.size === 0) {
15
+ return;
16
+ }
17
+ const logStreams = Array.from(this.logStreams);
18
+ if (this.logStreams.size === 1) {
19
+ process.stdout.write(`\nTo view detailed logs, visit the following AWS CloudWatch log stream:\n`);
20
+ process.stdout.write(logStreams[0].getLogStreamLink());
21
+ } else {
22
+ process.stdout.write(`\nTo view detailed logs, visit the following AWS CloudWatch log streams:\n`);
23
+ for (const logStream of logStreams) {
24
+ process.stdout.write(`- ${logStream.getLogStreamLink()}`);
25
+ }
26
+ }
27
+ process.stdout.write("\n");
28
+ }
29
+ initializeStream(name) {
30
+ const logStream = LogStream.create(this.logGroupName, name);
31
+ this.logStreams.add(logStream);
32
+ return logStream;
33
+ }
34
+ }
35
+
36
+ //# sourceMappingURL=LogReporter.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"names":["LogStream","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","create","add"],"sources":["LogReporter.ts"],"sourcesContent":["import { LogStream } from \"./LogStream.js\";\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,SAASA,SAAS;AAElB,OAAO,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,GAAGf,SAAS,CAAC2B,MAAM,CAAC,IAAI,CAAClB,YAAY,EAAEiB,IAAI,CAAC;IAC3D,IAAI,CAACxB,UAAU,CAAC0B,GAAG,CAACb,SAAS,CAAC;IAC9B,OAAOA,SAAS;EACpB;AACJ","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,51 @@
1
+ import { CloudWatchLogs } from "@webiny/aws-sdk/client-cloudwatch/index.js";
2
+ const cache = new Map();
3
+ export class LogStream {
4
+ constructor(logGroupName, logStreamName) {
5
+ this.logGroupName = logGroupName;
6
+ this.logStreamName = logStreamName;
7
+ this.cloudWatchLogs = new CloudWatchLogs();
8
+ }
9
+ getLogStreamLink() {
10
+ const replacements = [[/\$/g, "$2524"], [/\//g, "$252F"], [/\[/g, "$255B"], [/]/g, "$255D"]];
11
+ const replacer = (value, replacement) => {
12
+ return value.replace(replacement[0], replacement[1]);
13
+ };
14
+ 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("");
15
+ }
16
+ async printLogsSince(startTime) {
17
+ const params = {
18
+ logStreamName: this.logStreamName,
19
+ logGroupName: this.logGroupName,
20
+ nextToken: this.nextPage,
21
+ startFromHead: true,
22
+ startTime,
23
+ unmask: true
24
+ };
25
+ try {
26
+ const {
27
+ events,
28
+ nextForwardToken
29
+ } = await this.cloudWatchLogs.getLogEvents(params);
30
+ this.nextPage = nextForwardToken;
31
+ if (events) {
32
+ events.forEach(event => {
33
+ process.stdout.write(String(event.message));
34
+ });
35
+ }
36
+ } catch (err) {
37
+ console.log(`Couldn't fetch logs: ${err.message}`);
38
+ }
39
+ }
40
+ static create(logGroupName, logStreamName) {
41
+ const cacheId = `${logGroupName}:${logStreamName}`;
42
+ if (cache.has(cacheId)) {
43
+ return cache.get(cacheId);
44
+ }
45
+ const logStream = new LogStream(logGroupName, logStreamName);
46
+ cache.set(cacheId, logStream);
47
+ return logStream;
48
+ }
49
+ }
50
+
51
+ //# sourceMappingURL=LogStream.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"names":["CloudWatchLogs","cache","Map","LogStream","constructor","logGroupName","logStreamName","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"],"sources":["LogStream.ts"],"sourcesContent":["import type { GetLogEventsRequest } from \"@webiny/aws-sdk/client-cloudwatch/index.js\";\nimport { CloudWatchLogs } from \"@webiny/aws-sdk/client-cloudwatch/index.js\";\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,SAASA,cAAc,QAAQ,4CAA4C;AAE3E,MAAMC,KAAK,GAAG,IAAIC,GAAG,CAAoB,CAAC;AAE1C,OAAO,MAAMC,SAAS,CAAC;EAMXC,WAAWA,CAACC,YAAoB,EAAEC,aAAqB,EAAE;IAC7D,IAAI,CAACD,YAAY,GAAGA,YAAY;IAChC,IAAI,CAACC,aAAa,GAAGA,aAAa;IAClC,IAA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C,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,CAACjC,YAAoB,EAAEC,aAAqB,EAAE;IAC9D,MAAMiC,OAAO,GAAG,GAAGlC,YAAY,IAAIC,aAAa,EAAE;IAElD,IAAIL,KAAK,CAACuC,GAAG,CAACD,OAAO,CAAC,EAAE;MACpB,OAAOtC,KAAK,CAACwC,GAAG,CAACF,OAAO,CAAC;IAC7B;IAEA,MAAMG,SAAS,GAAG,IAAIvC,SAAS,CAACE,YAAY,EAAEC,aAAa,CAAC;IAC5DL,KAAK,CAAC0C,GAAG,CAACJ,OAAO,EAAEG,SAAS,CAAC;IAE7B,OAAOA,SAAS;EACpB;AACJ","ignoreList":[]}
@@ -0,0 +1,4 @@
1
+ import type { MigrationRunnerResult } from "../cli/MigrationRunner.js";
2
+ export interface MigrationRunReporter {
3
+ report(result: MigrationRunnerResult): void | Promise<void>;
4
+ }
@@ -0,0 +1,3 @@
1
+ export {};
2
+
3
+ //# sourceMappingURL=MigrationRunReporter.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"names":[],"sources":["MigrationRunReporter.ts"],"sourcesContent":["import type { MigrationRunnerResult } from \"~/cli/MigrationRunner.js\";\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/index.js";
2
+ import type { MigrationStatusReporter } from "../cli/MigrationStatusReporter.js";
3
+ import type { MigrationInvocationErrorResponse, MigrationStatusResponse } from "../types.js";
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,128 @@
1
+ import { InvokeCommand } from "@webiny/aws-sdk/client-lambda/index.js";
2
+ import { executeWithRetry } from "@webiny/utils";
3
+ import { VoidStatusReporter } from "./VoidStatusReporter.js";
4
+ export class MigrationRunnerResult {
5
+ successBranch = [];
6
+ errorBranch = [];
7
+ constructor(functionName, result) {
8
+ this.functionName = functionName;
9
+ this.result = result;
10
+ }
11
+ getFunctionName() {
12
+ return this.functionName;
13
+ }
14
+ onSuccess(cb) {
15
+ this.successBranch.push(cb);
16
+ }
17
+ onError(cb) {
18
+ this.errorBranch.push(cb);
19
+ }
20
+ async process() {
21
+ if (this.result.error) {
22
+ for (const handler of this.errorBranch) {
23
+ await handler(this.result.error);
24
+ }
25
+ return;
26
+ }
27
+ for (const handler of this.successBranch) {
28
+ await handler(this.result.data);
29
+ }
30
+ }
31
+ }
32
+ export class MigrationRunner {
33
+ statusReporter = new VoidStatusReporter();
34
+ static create(params) {
35
+ const runner = new MigrationRunner(params.lambdaClient, params.functionName);
36
+ if (params.statusReporter) {
37
+ runner.setStatusReporter(params.statusReporter);
38
+ }
39
+ return runner;
40
+ }
41
+ constructor(lambdaClient, functionName) {
42
+ this.lambdaClient = lambdaClient;
43
+ this.functionName = functionName;
44
+ }
45
+ setStatusReporter(reporter) {
46
+ this.statusReporter = reporter;
47
+ }
48
+ async runMigration(payload) {
49
+ // Execute migration function.
50
+ await this.invokeMigration(payload);
51
+
52
+ // Poll for status and re-execute when migration is in "pending" state.
53
+ let response;
54
+ while (true) {
55
+ await new Promise(resolve => setTimeout(resolve, this.getMigrationStatusReportInterval()));
56
+ response = await this.getStatus(payload);
57
+ if (!response) {
58
+ continue;
59
+ }
60
+ const {
61
+ data,
62
+ error
63
+ } = response;
64
+
65
+ // If we received an error, it must be an unrecoverable error, and we don't retry.
66
+ if (error) {
67
+ return this.getResult(response);
68
+ }
69
+ switch (data.status) {
70
+ case "init":
71
+ await this.reportStatus(data);
72
+ continue;
73
+ case "pending":
74
+ await this.invokeMigration(payload);
75
+ break;
76
+ case "running":
77
+ await this.reportStatus(data);
78
+ break;
79
+ case "done":
80
+ await this.reportStatus(data);
81
+ return this.getResult(response);
82
+ default:
83
+ return this.getResult(response);
84
+ }
85
+ }
86
+ }
87
+ async reportStatus(data) {
88
+ await this.statusReporter.report(data);
89
+ }
90
+ async invokeMigration(payload) {
91
+ const response = await this.lambdaClient.send(new InvokeCommand({
92
+ FunctionName: this.functionName,
93
+ InvocationType: "Event",
94
+ Payload: JSON.stringify({
95
+ ...payload,
96
+ command: "execute"
97
+ })
98
+ }));
99
+ return response.StatusCode;
100
+ }
101
+ getResult(response) {
102
+ return new MigrationRunnerResult(this.functionName, response);
103
+ }
104
+ async getStatus(payload) {
105
+ const getStatus = () => {
106
+ return this.lambdaClient.send(new InvokeCommand({
107
+ FunctionName: this.functionName,
108
+ InvocationType: "RequestResponse",
109
+ Payload: JSON.stringify({
110
+ ...payload,
111
+ command: "status"
112
+ })
113
+ }));
114
+ };
115
+ const response = await executeWithRetry(getStatus);
116
+ const decoder = new TextDecoder("utf-8");
117
+ return JSON.parse(decoder.decode(response.Payload));
118
+ }
119
+ getMigrationStatusReportInterval() {
120
+ const envKey = "MIGRATION_STATUS_REPORT_INTERVAL";
121
+ if (envKey in process.env) {
122
+ return parseInt(String(process.env[envKey]));
123
+ }
124
+ return 2000;
125
+ }
126
+ }
127
+
128
+ //# sourceMappingURL=MigrationRunner.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"names":["InvokeCommand","executeWithRetry","VoidStatusReporter","MigrationRunnerResult","successBranch","errorBranch","constructor","functionName","result","getFunctionName","onSuccess","cb","push","onError","process","error","handler","data","MigrationRunner","statusReporter","create","params","runner","lambdaClient","setStatusReporter","reporter","runMigration","payload","invokeMigration","response","Promise","resolve","setTimeout","getMigrationStatusReportInterval","getStatus","getResult","status","reportStatus","report","send","FunctionName","InvocationType","Payload","JSON","stringify","command","StatusCode","decoder","TextDecoder","parse","decode","envKey","env","parseInt","String"],"sources":["MigrationRunner.ts"],"sourcesContent":["import type { LambdaClient } from \"@webiny/aws-sdk/client-lambda/index.js\";\nimport { InvokeCommand } from \"@webiny/aws-sdk/client-lambda/index.js\";\nimport type { MigrationStatusReporter } from \"~/cli/MigrationStatusReporter.js\";\nimport type {\n MigrationEventHandlerResponse,\n MigrationInvocationErrorResponse,\n MigrationStatus,\n MigrationStatusResponse\n} from \"~/types.js\";\nimport { executeWithRetry } from \"@webiny/utils\";\nimport { VoidStatusReporter } from \"./VoidStatusReporter.js\";\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,SAASA,aAAa,QAAQ,wCAAwC;AAQtE,SAASC,gBAAgB,QAAQ,eAAe;AAChD,SAASC,kBAAkB;AAsB3B,OAAO,MAAMC,qBAAqB,CAAC;EAGdC,aAAa,GAA2B,EAAE;EAC1CC,WAAW,GAAyB,EAAE;EAEvDC,WAAWA,CACPC,YAAoB,EACpBC,MAAkE,EACpE;IACE,IAAI,CAACD,YAAY,GAAGA,YAAY;IAChC,IAAI,CAACC,MAAM,GAAGA,MAAM;EACxB;EAEAC,eAAeA,CAAA,EAAG;IACd,OAAO,IAAI,CAACF,YAAY;EAC5B;EAE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C9D,CAAC,CACL,CAAC;IAED,OAAOhB,QAAQ,CAACiB,UAAU;EAC9B;EAEQX,SAASA,CAACN,QAAoE,EAAE;IACpF,OAAO,IAAI1B,qBAAqB,CAAC,IAAI,CAACI,YAAY,EAAEsB,QAAQ,CAAC;EACjE;EAEA,MAAcK,SAASA,CAACP,OAA4B,EAAE;IAClD,MAAMO,SAAS,GAAGA,CAAA,KAAM;MACpB,OAAO,IAAI,CAACX,YAAY,CAACgB,IAAI,CACzB,IAAIvC,aAAa,CAAC;QACdwC,YAAY,EAAE,IAAI,CAACjC,YAAY;QAC/BkC,cAAc,EAAE,iBAAiB;QACjCC,OAAO,EAAEC,IAAI,CAACC,SAAS,CAAC;UAAE,GAAGjB,OAAO;UAAEkB,OAAO,EAAE;QAAS,CAAC;MAC7D,CAAC,CACL,CAAC;IACL,CAAC;IAED,MAAMhB,QAAQ,GAAG,MAAM5B,gBAAgB,CAACiC,SAAS,CAAC;IAElD,MAAMa,OAAO,GAAG,IAAIC,WAAW,CAAC,OAAO,CAAC;IACxC,OAAOL,IAAI,CAACM,KAAK,CAACF,OAAO,CAACG,MAAM,CAACrB,QAAQ,CAACa,OAAO,CAAC,CAAC;EACvD;EAEQT,gCAAgCA,CAAA,EAAG;IACvC,MAAMkB,MAAM,GAAG,kCAAkC;IACjD,IAAIA,MAAM,IAAIrC,OAAO,CAACsC,GAAG,EAAE;MACvB,OAAOC,QAAQ,CAACC,MAAM,CAACxC,OAAO,CAACsC,GAAG,CAACD,MAAM,CAAC,CAAC,CAAC;IAChD;IACA,OAAO,IAAI;EACf;AACJ","ignoreList":[]}
@@ -0,0 +1,4 @@
1
+ import type { MigrationStatus } from "../types.js";
2
+ export interface MigrationStatusReporter {
3
+ report(status: MigrationStatus): void;
4
+ }
@@ -0,0 +1,3 @@
1
+ export {};
2
+
3
+ //# sourceMappingURL=MigrationStatusReporter.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"names":[],"sources":["MigrationStatusReporter.ts"],"sourcesContent":["import type { MigrationStatus } from \"~/types.js\";\n\nexport interface MigrationStatusReporter {\n report(status: MigrationStatus): void;\n}\n"],"mappings":"","ignoreList":[]}
@@ -0,0 +1,9 @@
1
+ import type { MigrationStatusReporter } from "../cli/MigrationStatusReporter.js";
2
+ import type { MigrationStatus } from "../types.js";
3
+ import type { LogReporter } from "../cli/LogReporter.js";
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,35 @@
1
+ export class NonInteractiveCliStatusReporter {
2
+ firstCall = true;
3
+ constructor(logReporter) {
4
+ this.logReporter = logReporter;
5
+ console.log(`Using "NonInteractiveCliStatusReporter".`);
6
+ }
7
+ async report(migrationStatus) {
8
+ const {
9
+ status,
10
+ context
11
+ } = migrationStatus;
12
+ const currentLogStreamName = context?.logStreamName;
13
+ if (currentLogStreamName) {
14
+ this.logReporter.initializeStream(currentLogStreamName);
15
+ if (this.firstCall) {
16
+ this.logReporter.printLogStreamLinks();
17
+ process.stdout.write(`\n---------- MIGRATION LOGS START ----------\n\n`);
18
+ }
19
+ await this.logReporter.printLogs(currentLogStreamName);
20
+ }
21
+ if (["done", "error"].includes(status)) {
22
+ // We want to give AWS some time for the latest log events to become available.
23
+ await new Promise(resolve => {
24
+ setTimeout(resolve, 10000);
25
+ });
26
+ if (currentLogStreamName) {
27
+ await this.logReporter.printLogs(currentLogStreamName);
28
+ process.stdout.write(`\n---------- MIGRATION LOGS END ----------\n`);
29
+ }
30
+ }
31
+ this.firstCall = false;
32
+ }
33
+ }
34
+
35
+ //# 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"],"sources":["NonInteractiveCliStatusReporter.ts"],"sourcesContent":["import type { MigrationStatusReporter } from \"~/cli/MigrationStatusReporter.js\";\nimport type { MigrationStatus } from \"~/types.js\";\nimport type { LogReporter } from \"~/cli/LogReporter.js\";\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":"AAIA,OAAO,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","ignoreList":[]}
@@ -0,0 +1,4 @@
1
+ import type { MigrationStatusReporter } from "./MigrationStatusReporter.js";
2
+ export declare class VoidStatusReporter implements MigrationStatusReporter {
3
+ report(): void;
4
+ }
@@ -0,0 +1,7 @@
1
+ export class VoidStatusReporter {
2
+ report() {
3
+ // This is a void reporter.
4
+ }
5
+ }
6
+
7
+ //# sourceMappingURL=VoidStatusReporter.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"names":["VoidStatusReporter","report"],"sources":["VoidStatusReporter.ts"],"sourcesContent":["import type { MigrationStatusReporter } from \"./MigrationStatusReporter.js\";\n\nexport class VoidStatusReporter implements MigrationStatusReporter {\n report(): void {\n // This is a void reporter.\n }\n}\n"],"mappings":"AAEA,OAAO,MAAMA,kBAAkB,CAAoC;EAC/DC,MAAMA,CAAA,EAAS;IACX;EAAA;AAER","ignoreList":[]}
@@ -1,14 +1,8 @@
1
- "use strict";
2
-
3
- Object.defineProperty(exports, "__esModule", {
4
- value: true
5
- });
6
- exports.getDuration = void 0;
7
1
  /**
8
2
  * Get duration since the given ISO timestamp.
9
3
  * @param string since
10
4
  */
11
- const getDuration = since => {
5
+ export const getDuration = since => {
12
6
  const ms = new Date().getTime() - new Date(since).getTime();
13
7
  let seconds = Math.floor(ms / 1000);
14
8
  let minutes = undefined;
@@ -18,4 +12,5 @@ const getDuration = since => {
18
12
  }
19
13
  return minutes ? `${minutes}m ${seconds}s` : `${seconds}s`;
20
14
  };
21
- exports.getDuration = getDuration;
15
+
16
+ //# sourceMappingURL=getDuration.js.map
@@ -1 +1 @@
1
- {"version":3,"names":["getDuration","since","ms","Date","getTime","seconds","Math","floor","minutes","undefined"],"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,EAAE,CAACC,OAAO,EAAE,GAAG,IAAID,IAAI,CAACF,KAAK,CAAC,CAACG,OAAO,EAAE;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,GAAI,GAAEA,OAAQ,KAAIH,OAAQ,GAAE,GAAI,GAAEA,OAAQ,GAAE;AAC9D,CAAC;AAAC"}
1
+ {"version":3,"names":["getDuration","since","ms","Date","getTime","seconds","Math","floor","minutes","undefined"],"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;AACA,OAAO,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","ignoreList":[]}
package/cli/index.d.ts CHANGED
@@ -1,3 +1,10 @@
1
- export * from "./printReport";
2
- export * from "./runMigration";
3
- export * from "./getDuration";
1
+ export * from "./getDuration.js";
2
+ export * from "./MigrationRunner.js";
3
+ export * from "./MigrationStatusReporter.js";
4
+ export * from "./MigrationRunReporter.js";
5
+ export * from "./InteractiveCliStatusReporter.js";
6
+ export * from "./NonInteractiveCliStatusReporter.js";
7
+ export * from "./VoidStatusReporter.js";
8
+ export * from "./CliMigrationRunReporter.js";
9
+ export * from "./LogStream.js";
10
+ export * from "./LogReporter.js";
package/cli/index.js CHANGED
@@ -1,38 +1,12 @@
1
- "use strict";
1
+ export * from "./getDuration.js";
2
+ export * from "./MigrationRunner.js";
3
+ export * from "./MigrationStatusReporter.js";
4
+ export * from "./MigrationRunReporter.js";
5
+ export * from "./InteractiveCliStatusReporter.js";
6
+ export * from "./NonInteractiveCliStatusReporter.js";
7
+ export * from "./VoidStatusReporter.js";
8
+ export * from "./CliMigrationRunReporter.js";
9
+ export * from "./LogStream.js";
10
+ export * from "./LogReporter.js";
2
11
 
3
- Object.defineProperty(exports, "__esModule", {
4
- value: true
5
- });
6
- var _printReport = require("./printReport");
7
- Object.keys(_printReport).forEach(function (key) {
8
- if (key === "default" || key === "__esModule") return;
9
- if (key in exports && exports[key] === _printReport[key]) return;
10
- Object.defineProperty(exports, key, {
11
- enumerable: true,
12
- get: function () {
13
- return _printReport[key];
14
- }
15
- });
16
- });
17
- var _runMigration = require("./runMigration");
18
- Object.keys(_runMigration).forEach(function (key) {
19
- if (key === "default" || key === "__esModule") return;
20
- if (key in exports && exports[key] === _runMigration[key]) return;
21
- Object.defineProperty(exports, key, {
22
- enumerable: true,
23
- get: function () {
24
- return _runMigration[key];
25
- }
26
- });
27
- });
28
- var _getDuration = require("./getDuration");
29
- Object.keys(_getDuration).forEach(function (key) {
30
- if (key === "default" || key === "__esModule") return;
31
- if (key in exports && exports[key] === _getDuration[key]) return;
32
- Object.defineProperty(exports, key, {
33
- enumerable: true,
34
- get: function () {
35
- return _getDuration[key];
36
- }
37
- });
38
- });
12
+ //# sourceMappingURL=index.js.map
package/cli/index.js.map CHANGED
@@ -1 +1 @@
1
- {"version":3,"names":[],"sources":["index.ts"],"sourcesContent":["export * from \"./printReport\";\nexport * from \"./runMigration\";\nexport * from \"./getDuration\";\n"],"mappings":";;;;;AAAA;AAAA;EAAA;EAAA;EAAA;IAAA;IAAA;MAAA;IAAA;EAAA;AAAA;AACA;AAAA;EAAA;EAAA;EAAA;IAAA;IAAA;MAAA;IAAA;EAAA;AAAA;AACA;AAAA;EAAA;EAAA;EAAA;IAAA;IAAA;MAAA;IAAA;EAAA;AAAA"}
1
+ {"version":3,"names":[],"sources":["index.ts"],"sourcesContent":["export * from \"./getDuration.js\";\nexport * from \"./MigrationRunner.js\";\nexport * from \"./MigrationStatusReporter.js\";\nexport * from \"./MigrationRunReporter.js\";\nexport * from \"./InteractiveCliStatusReporter.js\";\nexport * from \"./NonInteractiveCliStatusReporter.js\";\nexport * from \"./VoidStatusReporter.js\";\nexport * from \"./CliMigrationRunReporter.js\";\nexport * from \"./LogStream.js\";\nexport * from \"./LogReporter.js\";\n"],"mappings":"AAAA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA","ignoreList":[]}
@@ -1,7 +1,4 @@
1
- import { pino, Logger } from "pino";
2
- import pinoPretty from "pino-pretty";
3
- import { DataMigration } from "./types";
4
- export declare const createPinoLogger: () => Logger<pinoPretty.PrettyStream>;
5
- export declare const getChildLogger: (logger: Logger, migration: DataMigration) => pino.Logger<import("pino").LoggerOptions & {
6
- msgPrefix: string;
7
- }>;
1
+ import type { DataMigration } from "./types.js";
2
+ import type { Logger } from "@webiny/logger";
3
+ export declare const createPinoLogger: () => Logger;
4
+ export declare const getChildLogger: (logger: Logger, migration: DataMigration) => Logger<never, boolean>;
@@ -1,22 +1,17 @@
1
- "use strict";
2
-
3
- var _interopRequireDefault = require("@babel/runtime/helpers/interopRequireDefault").default;
4
- Object.defineProperty(exports, "__esModule", {
5
- value: true
6
- });
7
- exports.getChildLogger = exports.createPinoLogger = void 0;
8
- var _chalk = _interopRequireDefault(require("chalk"));
9
- var _pino = require("pino");
10
- var _pinoPretty = _interopRequireDefault(require("pino-pretty"));
11
- const createPinoLogger = () => {
12
- return (0, _pino.pino)((0, _pinoPretty.default)({
1
+ import chalk from "chalk";
2
+ import pinoPretty from "pino-pretty";
3
+ import { createPinoLogger as baseCreatePinoLogger, getLogLevel } from "@webiny/logger";
4
+ export const createPinoLogger = () => {
5
+ return baseCreatePinoLogger({
6
+ level: getLogLevel(process.env.MIGRATIONS_LOG_LEVEL, "trace")
7
+ }, pinoPretty({
13
8
  ignore: "pid,hostname"
14
9
  }));
15
10
  };
16
- exports.createPinoLogger = createPinoLogger;
17
- const getChildLogger = (logger, migration) => {
11
+ export const getChildLogger = (logger, migration) => {
18
12
  return logger.child({}, {
19
- msgPrefix: _chalk.default.blueBright(`[${migration.getId()}]`) + " "
13
+ msgPrefix: chalk.blueBright(`[${migration.getId()}]`) + " "
20
14
  });
21
15
  };
22
- exports.getChildLogger = getChildLogger;
16
+
17
+ //# sourceMappingURL=createPinoLogger.js.map
@@ -1 +1 @@
1
- {"version":3,"names":["createPinoLogger","pino","pinoPretty","ignore","getChildLogger","logger","migration","child","msgPrefix","chalk","blueBright","getId"],"sources":["createPinoLogger.ts"],"sourcesContent":["import chalk from \"chalk\";\nimport { pino, Logger } from \"pino\";\nimport pinoPretty from \"pino-pretty\";\nimport { DataMigration } from \"~/types\";\n\nexport const createPinoLogger = () => {\n return pino(\n pinoPretty({\n ignore: \"pid,hostname\"\n })\n );\n};\n\nexport const getChildLogger = (logger: Logger, migration: DataMigration) => {\n return logger.child({}, { msgPrefix: chalk.blueBright(`[${migration.getId()}]`) + \" \" });\n};\n"],"mappings":";;;;;;;AAAA;AACA;AACA;AAGO,MAAMA,gBAAgB,GAAG,MAAM;EAClC,OAAO,IAAAC,UAAI,EACP,IAAAC,mBAAU,EAAC;IACPC,MAAM,EAAE;EACZ,CAAC,CAAC,CACL;AACL,CAAC;AAAC;AAEK,MAAMC,cAAc,GAAG,CAACC,MAAc,EAAEC,SAAwB,KAAK;EACxE,OAAOD,MAAM,CAACE,KAAK,CAAC,CAAC,CAAC,EAAE;IAAEC,SAAS,EAAEC,cAAK,CAACC,UAAU,CAAE,IAAGJ,SAAS,CAACK,KAAK,EAAG,GAAE,CAAC,GAAG;EAAI,CAAC,CAAC;AAC5F,CAAC;AAAC"}
1
+ {"version":3,"names":["chalk","pinoPretty","createPinoLogger","baseCreatePinoLogger","getLogLevel","level","process","env","MIGRATIONS_LOG_LEVEL","ignore","getChildLogger","logger","migration","child","msgPrefix","blueBright","getId"],"sources":["createPinoLogger.ts"],"sourcesContent":["import chalk from \"chalk\";\nimport pinoPretty from \"pino-pretty\";\nimport type { DataMigration } from \"~/types.js\";\nimport type { Logger } from \"@webiny/logger\";\nimport { createPinoLogger as baseCreatePinoLogger, getLogLevel } from \"@webiny/logger\";\n\nexport const createPinoLogger = () => {\n return baseCreatePinoLogger(\n {\n level: getLogLevel(process.env.MIGRATIONS_LOG_LEVEL, \"trace\")\n },\n pinoPretty({\n ignore: \"pid,hostname\"\n })\n );\n};\n\nexport const getChildLogger = (logger: Logger, migration: DataMigration) => {\n return logger.child({}, { msgPrefix: chalk.blueBright(`[${migration.getId()}]`) + \" \" });\n};\n"],"mappings":"AAAA,OAAOA,KAAK,MAAM,OAAO;AACzB,OAAOC,UAAU,MAAM,aAAa;AAGpC,SAASC,gBAAgB,IAAIC,oBAAoB,EAAEC,WAAW,QAAQ,gBAAgB;AAEtF,OAAO,MAAMF,gBAAgB,GAAGA,CAAA,KAAM;EAClC,OAAOC,oBAAoB,CACvB;IACIE,KAAK,EAAED,WAAW,CAACE,OAAO,CAACC,GAAG,CAACC,oBAAoB,EAAE,OAAO;EAChE,CAAC,EACDP,UAAU,CAAC;IACPQ,MAAM,EAAE;EACZ,CAAC,CACL,CAAC;AACL,CAAC;AAED,OAAO,MAAMC,cAAc,GAAGA,CAACC,MAAc,EAAEC,SAAwB,KAAK;EACxE,OAAOD,MAAM,CAACE,KAAK,CAAC,CAAC,CAAC,EAAE;IAAEC,SAAS,EAAEd,KAAK,CAACe,UAAU,CAAC,IAAIH,SAAS,CAACI,KAAK,CAAC,CAAC,GAAG,CAAC,GAAG;EAAI,CAAC,CAAC;AAC5F,CAAC","ignoreList":[]}
package/createTable.d.ts CHANGED
@@ -1,7 +1,7 @@
1
- import { DocumentClient } from "aws-sdk/clients/dynamodb";
2
- import { Table } from "dynamodb-toolbox";
1
+ import type { DynamoDBDocument } from "@webiny/aws-sdk/client-dynamodb/index.js";
2
+ import { Table } from "@webiny/db-dynamodb/toolbox.js";
3
3
  export interface CreateTableParams {
4
4
  name: string;
5
- documentClient: DocumentClient;
5
+ documentClient: DynamoDBDocument;
6
6
  }
7
- export declare const createTable: ({ name, documentClient }: CreateTableParams) => Table;
7
+ export declare const createTable: ({ name, documentClient }: CreateTableParams) => Table<string, "PK", "SK">;
package/createTable.js CHANGED
@@ -1,15 +1,9 @@
1
- "use strict";
2
-
3
- Object.defineProperty(exports, "__esModule", {
4
- value: true
5
- });
6
- exports.createTable = void 0;
7
- var _dynamodbToolbox = require("dynamodb-toolbox");
8
- const createTable = ({
1
+ import { Table } from "@webiny/db-dynamodb/toolbox.js";
2
+ export const createTable = ({
9
3
  name,
10
4
  documentClient
11
5
  }) => {
12
- return new _dynamodbToolbox.Table({
6
+ return new Table({
13
7
  name,
14
8
  partitionKey: "PK",
15
9
  sortKey: "SK",
@@ -23,7 +17,10 @@ const createTable = ({
23
17
  // partitionKey: "GSI2_PK",
24
18
  // sortKey: "GSI2_SK"
25
19
  // }
26
- }
20
+ },
21
+ autoExecute: true,
22
+ autoParse: true
27
23
  });
28
24
  };
29
- exports.createTable = createTable;
25
+
26
+ //# sourceMappingURL=createTable.js.map