@webiny/data-migration 5.37.3-beta.1 → 5.37.3-beta.2

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 (59) hide show
  1. package/MigrationRunner.d.ts +2 -0
  2. package/MigrationRunner.js +18 -5
  3. package/MigrationRunner.js.map +1 -1
  4. package/cli/CliMigrationRunReporter.d.ts +10 -0
  5. package/cli/CliMigrationRunReporter.js +58 -0
  6. package/cli/CliMigrationRunReporter.js.map +1 -0
  7. package/cli/InteractiveCliStatusReporter.d.ts +11 -0
  8. package/cli/InteractiveCliStatusReporter.js +74 -0
  9. package/cli/InteractiveCliStatusReporter.js.map +1 -0
  10. package/cli/LogReporter.d.ts +10 -0
  11. package/cli/LogReporter.js +45 -0
  12. package/cli/LogReporter.js.map +1 -0
  13. package/cli/LogStream.d.ts +10 -0
  14. package/cli/LogStream.js +62 -0
  15. package/cli/LogStream.js.map +1 -0
  16. package/cli/MigrationRunReporter.d.ts +4 -0
  17. package/cli/MigrationRunReporter.js +5 -0
  18. package/cli/MigrationRunReporter.js.map +1 -0
  19. package/cli/MigrationRunner.d.ts +44 -0
  20. package/cli/MigrationRunner.js +133 -0
  21. package/cli/MigrationRunner.js.map +1 -0
  22. package/cli/MigrationStatusReporter.d.ts +4 -0
  23. package/cli/MigrationStatusReporter.js +5 -0
  24. package/cli/MigrationStatusReporter.js.map +1 -0
  25. package/cli/NonInteractiveCliStatusReporter.d.ts +9 -0
  26. package/cli/NonInteractiveCliStatusReporter.js +43 -0
  27. package/cli/NonInteractiveCliStatusReporter.js.map +1 -0
  28. package/cli/VoidStatusReporter.d.ts +4 -0
  29. package/cli/VoidStatusReporter.js +12 -0
  30. package/cli/VoidStatusReporter.js.map +1 -0
  31. package/cli/getDuration.js +1 -3
  32. package/cli/index.d.ts +8 -2
  33. package/cli/index.js +78 -14
  34. package/cli/index.js.map +1 -1
  35. package/createPinoLogger.js +1 -3
  36. package/createTable.js +1 -3
  37. package/handlers/createDdbEsProjectMigration.js +5 -3
  38. package/handlers/createDdbEsProjectMigration.js.map +1 -1
  39. package/handlers/createDdbProjectMigration.js +5 -3
  40. package/handlers/createDdbProjectMigration.js.map +1 -1
  41. package/handlers/createPatternMatcher.js +1 -3
  42. package/handlers/devVersionErrorResponse.js +1 -3
  43. package/index.js +1 -3
  44. package/package.json +9 -9
  45. package/repository/createStandardEntity.js +1 -3
  46. package/repository/migrations.repository.js +1 -3
  47. package/symbols.js +1 -3
  48. package/types.d.ts +2 -0
  49. package/types.js +1 -3
  50. package/types.js.map +1 -1
  51. package/cli/getMigrationStatus.d.ts +0 -9
  52. package/cli/getMigrationStatus.js +0 -29
  53. package/cli/getMigrationStatus.js.map +0 -1
  54. package/cli/printReport.d.ts +0 -9
  55. package/cli/printReport.js +0 -59
  56. package/cli/printReport.js.map +0 -1
  57. package/cli/runMigration.d.ts +0 -13
  58. package/cli/runMigration.js +0 -87
  59. package/cli/runMigration.js.map +0 -1
@@ -105,6 +105,4 @@ class MigrationRepositoryImpl {
105
105
  }
106
106
  }
107
107
  exports.MigrationRepositoryImpl = MigrationRepositoryImpl;
108
- (0, _ioc.makeInjectable)(MigrationRepositoryImpl, [(0, _ioc.inject)(_symbols.PrimaryDynamoTableSymbol)]);
109
-
110
- //# sourceMappingURL=migrations.repository.js.map
108
+ (0, _ioc.makeInjectable)(MigrationRepositoryImpl, [(0, _ioc.inject)(_symbols.PrimaryDynamoTableSymbol)]);
package/symbols.js CHANGED
@@ -17,6 +17,4 @@ exports.PrimaryDynamoTableSymbol = PrimaryDynamoTableSymbol;
17
17
  const ElasticsearchDynamoTableSymbol = Symbol.for("ElasticsearchDynamoTable");
18
18
  exports.ElasticsearchDynamoTableSymbol = ElasticsearchDynamoTableSymbol;
19
19
  const ExecutionTimeLimiterSymbol = Symbol.for("ExecutionTimeLimiter");
20
- exports.ExecutionTimeLimiterSymbol = ExecutionTimeLimiterSymbol;
21
-
22
- //# sourceMappingURL=symbols.js.map
20
+ exports.ExecutionTimeLimiterSymbol = ExecutionTimeLimiterSymbol;
package/types.d.ts CHANGED
@@ -13,6 +13,7 @@ export interface MigrationRun {
13
13
  finishedOn: string;
14
14
  status: "init" | "running" | "pending" | "done" | "error";
15
15
  migrations: MigrationRunItem[];
16
+ context?: Record<string, any>;
16
17
  error?: {
17
18
  message: string;
18
19
  name?: string;
@@ -42,6 +43,7 @@ export interface DataMigrationContext<TCheckpoint = any> {
42
43
  projectVersion: string;
43
44
  logger: Logger;
44
45
  checkpoint?: TCheckpoint;
46
+ forceExecute: boolean;
45
47
  runningOutOfTime: () => boolean;
46
48
  createCheckpoint: (data: TCheckpoint) => void;
47
49
  createCheckpointAndExit: (data: TCheckpoint) => void;
package/types.js CHANGED
@@ -2,6 +2,4 @@
2
2
 
3
3
  Object.defineProperty(exports, "__esModule", {
4
4
  value: true
5
- });
6
-
7
- //# sourceMappingURL=types.js.map
5
+ });
package/types.js.map CHANGED
@@ -1 +1 @@
1
- {"version":3,"names":[],"sources":["types.ts"],"sourcesContent":["import { Logger } from \"@webiny/logger\";\n\nexport type { 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":""}
1
+ {"version":3,"names":[],"sources":["types.ts"],"sourcesContent":["import { Logger } from \"@webiny/logger\";\n\nexport type { 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 context?: Record<string, any>;\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 forceExecute: boolean;\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":""}
@@ -1,9 +0,0 @@
1
- import LambdaClient from "aws-sdk/clients/lambda";
2
- import { MigrationEventHandlerResponse } from "../types";
3
- interface GetMigrationStatusParams {
4
- lambdaClient: LambdaClient;
5
- functionName: string;
6
- payload?: Record<string, any>;
7
- }
8
- export declare const getMigrationStatus: ({ payload, functionName, lambdaClient }: GetMigrationStatusParams) => Promise<MigrationEventHandlerResponse>;
9
- export {};
@@ -1,29 +0,0 @@
1
- "use strict";
2
-
3
- var _interopRequireDefault = require("@babel/runtime/helpers/interopRequireDefault").default;
4
- Object.defineProperty(exports, "__esModule", {
5
- value: true
6
- });
7
- exports.getMigrationStatus = void 0;
8
- var _objectSpread2 = _interopRequireDefault(require("@babel/runtime/helpers/objectSpread2"));
9
- var _utils = require("@webiny/utils");
10
- const getMigrationStatus = async ({
11
- payload,
12
- functionName,
13
- lambdaClient
14
- }) => {
15
- const getStatus = () => {
16
- return lambdaClient.invoke({
17
- FunctionName: functionName,
18
- InvocationType: "RequestResponse",
19
- Payload: JSON.stringify((0, _objectSpread2.default)((0, _objectSpread2.default)({}, payload), {}, {
20
- command: "status"
21
- }))
22
- }).promise();
23
- };
24
- const response = await (0, _utils.executeWithRetry)(getStatus);
25
- return JSON.parse(response.Payload);
26
- };
27
- exports.getMigrationStatus = getMigrationStatus;
28
-
29
- //# sourceMappingURL=getMigrationStatus.js.map
@@ -1 +0,0 @@
1
- {"version":3,"names":["_utils","require","getMigrationStatus","payload","functionName","lambdaClient","getStatus","invoke","FunctionName","InvocationType","Payload","JSON","stringify","_objectSpread2","default","command","promise","response","executeWithRetry","parse","exports"],"sources":["getMigrationStatus.ts"],"sourcesContent":["import { executeWithRetry } from \"@webiny/utils\";\nimport LambdaClient from \"aws-sdk/clients/lambda\";\nimport { MigrationEventHandlerResponse } from \"~/types\";\n\ninterface GetMigrationStatusParams {\n lambdaClient: LambdaClient;\n functionName: string;\n payload?: Record<string, any>;\n}\n\nexport const getMigrationStatus = async ({\n payload,\n functionName,\n lambdaClient\n}: GetMigrationStatusParams) => {\n const getStatus = () => {\n return lambdaClient\n .invoke({\n FunctionName: functionName,\n InvocationType: \"RequestResponse\",\n Payload: JSON.stringify({ ...payload, command: \"status\" })\n })\n .promise();\n };\n\n const response = await executeWithRetry(getStatus);\n\n return JSON.parse(response.Payload as string) as MigrationEventHandlerResponse;\n};\n"],"mappings":";;;;;;;;AAAA,IAAAA,MAAA,GAAAC,OAAA;AAUO,MAAMC,kBAAkB,GAAG,MAAAA,CAAO;EACrCC,OAAO;EACPC,YAAY;EACZC;AACsB,CAAC,KAAK;EAC5B,MAAMC,SAAS,GAAGA,CAAA,KAAM;IACpB,OAAOD,YAAY,CACdE,MAAM,CAAC;MACJC,YAAY,EAAEJ,YAAY;MAC1BK,cAAc,EAAE,iBAAiB;MACjCC,OAAO,EAAEC,IAAI,CAACC,SAAS,KAAAC,cAAA,CAAAC,OAAA,MAAAD,cAAA,CAAAC,OAAA,MAAMX,OAAO;QAAEY,OAAO,EAAE;MAAQ,EAAE;IAC7D,CAAC,CAAC,CACDC,OAAO,CAAC,CAAC;EAClB,CAAC;EAED,MAAMC,QAAQ,GAAG,MAAM,IAAAC,uBAAgB,EAACZ,SAAS,CAAC;EAElD,OAAOK,IAAI,CAACQ,KAAK,CAACF,QAAQ,CAACP,OAAiB,CAAC;AACjD,CAAC;AAACU,OAAA,CAAAlB,kBAAA,GAAAA,kBAAA"}
@@ -1,9 +0,0 @@
1
- import { CliContext } from "@webiny/cli/types";
2
- import { MigrationEventHandlerResponse } from "../types";
3
- interface ReportParams {
4
- response: MigrationEventHandlerResponse;
5
- migrationLambdaArn: string;
6
- context: CliContext;
7
- }
8
- export declare const printReport: ({ response, migrationLambdaArn, context }: ReportParams) => void;
9
- export {};
@@ -1,59 +0,0 @@
1
- "use strict";
2
-
3
- var _interopRequireDefault = require("@babel/runtime/helpers/interopRequireDefault").default;
4
- Object.defineProperty(exports, "__esModule", {
5
- value: true
6
- });
7
- exports.printReport = void 0;
8
- var _objectWithoutProperties2 = _interopRequireDefault(require("@babel/runtime/helpers/objectWithoutProperties"));
9
- var _centerAlign = _interopRequireDefault(require("center-align"));
10
- const _excluded = ["migrations"];
11
- const isError = response => {
12
- if (!response) {
13
- return false;
14
- }
15
- return "error" in response;
16
- };
17
- const makeEven = str => {
18
- if (str.length % 2 > 0) {
19
- return str + " ";
20
- }
21
- return str;
22
- };
23
- const printReport = ({
24
- response,
25
- migrationLambdaArn,
26
- context
27
- }) => {
28
- if (!response) {
29
- return;
30
- }
31
- if (isError(response)) {
32
- context.error(response.error.message);
33
- return;
34
- }
35
- const functionName = migrationLambdaArn.split(":").pop();
36
- context.success(`Data migration Lambda %s executed successfully!`, functionName);
37
- const _response$data = response.data,
38
- {
39
- migrations
40
- } = _response$data,
41
- run = (0, _objectWithoutProperties2.default)(_response$data, _excluded);
42
- if (!migrations.length) {
43
- context.info(`No applicable migrations were found!`);
44
- return;
45
- }
46
- const maxLength = Math.max(...migrations.map(mig => mig.status.length)) + 2;
47
- context.info(`Migration run: %s`, run.id);
48
- context.info(`Status: %s`, run.status);
49
- context.info(`Started on: %s`, run.startedOn);
50
- if (run.status === "done") {
51
- context.info(`Finished on: %s`, run.finishedOn);
52
- }
53
- for (const migration of migrations) {
54
- context.info(...[`[%s] %s: ${migration.description}`, (0, _centerAlign.default)(makeEven(migration.status), maxLength), migration.id]);
55
- }
56
- };
57
- exports.printReport = printReport;
58
-
59
- //# sourceMappingURL=printReport.js.map
@@ -1 +0,0 @@
1
- {"version":3,"names":["_centerAlign","_interopRequireDefault","require","_excluded","isError","response","makeEven","str","length","printReport","migrationLambdaArn","context","error","message","functionName","split","pop","success","_response$data","data","migrations","run","_objectWithoutProperties2","default","info","maxLength","Math","max","map","mig","status","id","startedOn","finishedOn","migration","description","center","exports"],"sources":["printReport.ts"],"sourcesContent":["import { CliContext } from \"@webiny/cli/types\";\nimport { MigrationEventHandlerResponse, MigrationInvocationErrorResponse } from \"~/types\";\nimport center from \"center-align\";\n\ninterface ReportParams {\n response: MigrationEventHandlerResponse;\n migrationLambdaArn: string;\n context: CliContext;\n}\n\nconst isError = (\n response: MigrationEventHandlerResponse\n): response is MigrationInvocationErrorResponse => {\n if (!response) {\n return false;\n }\n\n return \"error\" in response;\n};\n\nconst makeEven = (str: string) => {\n if (str.length % 2 > 0) {\n return str + \" \";\n }\n return str;\n};\n\nexport const printReport = ({ response, migrationLambdaArn, context }: ReportParams) => {\n if (!response) {\n return;\n }\n\n if (isError(response)) {\n context.error(response.error.message);\n return;\n }\n\n const functionName = migrationLambdaArn.split(\":\").pop();\n context.success(`Data migration Lambda %s executed successfully!`, functionName);\n\n const { migrations, ...run } = response.data;\n if (!migrations.length) {\n context.info(`No applicable migrations were found!`);\n return;\n }\n\n const maxLength = Math.max(...migrations.map(mig => mig.status.length)) + 2;\n context.info(`Migration run: %s`, run.id);\n context.info(`Status: %s`, run.status);\n context.info(`Started on: %s`, run.startedOn);\n if (run.status === \"done\") {\n context.info(`Finished on: %s`, run.finishedOn);\n }\n for (const migration of migrations) {\n context.info(\n ...[\n `[%s] %s: ${migration.description}`,\n center(makeEven(migration.status), maxLength),\n migration.id\n ]\n );\n }\n};\n"],"mappings":";;;;;;;;AAEA,IAAAA,YAAA,GAAAC,sBAAA,CAAAC,OAAA;AAAkC,MAAAC,SAAA;AAQlC,MAAMC,OAAO,GACTC,QAAuC,IACQ;EAC/C,IAAI,CAACA,QAAQ,EAAE;IACX,OAAO,KAAK;EAChB;EAEA,OAAO,OAAO,IAAIA,QAAQ;AAC9B,CAAC;AAED,MAAMC,QAAQ,GAAIC,GAAW,IAAK;EAC9B,IAAIA,GAAG,CAACC,MAAM,GAAG,CAAC,GAAG,CAAC,EAAE;IACpB,OAAOD,GAAG,GAAG,GAAG;EACpB;EACA,OAAOA,GAAG;AACd,CAAC;AAEM,MAAME,WAAW,GAAGA,CAAC;EAAEJ,QAAQ;EAAEK,kBAAkB;EAAEC;AAAsB,CAAC,KAAK;EACpF,IAAI,CAACN,QAAQ,EAAE;IACX;EACJ;EAEA,IAAID,OAAO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,EAAE,CAEpB,CAAC;EACL;AACJ,CAAC;AAACM,OAAA,CAAA5B,WAAA,GAAAA,WAAA"}
@@ -1,13 +0,0 @@
1
- import LambdaClient from "aws-sdk/clients/lambda";
2
- import { MigrationInvocationErrorResponse, MigrationRun, MigrationStatusResponse } from "../types";
3
- interface RunMigrationParams {
4
- lambdaClient: LambdaClient;
5
- functionName: string;
6
- payload?: Record<string, any>;
7
- statusCallback?: (status: MigrationRun) => void;
8
- }
9
- /**
10
- * Run the migration Lambda, and re-run when resuming is requested.
11
- */
12
- export declare const runMigration: ({ payload, functionName, lambdaClient, statusCallback }: RunMigrationParams) => Promise<MigrationStatusResponse | MigrationInvocationErrorResponse>;
13
- export {};
@@ -1,87 +0,0 @@
1
- "use strict";
2
-
3
- var _interopRequireDefault = require("@babel/runtime/helpers/interopRequireDefault").default;
4
- Object.defineProperty(exports, "__esModule", {
5
- value: true
6
- });
7
- exports.runMigration = void 0;
8
- var _objectSpread2 = _interopRequireDefault(require("@babel/runtime/helpers/objectSpread2"));
9
- var _getMigrationStatus = require("./getMigrationStatus");
10
- const getMigrationStatusReportInterval = () => {
11
- const envKey = "MIGRATION_STATUS_REPORT_INTERVAL";
12
- if (envKey in process.env) {
13
- return parseInt(String(process.env[envKey]));
14
- }
15
- return 2000;
16
- };
17
-
18
- /**
19
- * Run the migration Lambda, and re-run when resuming is requested.
20
- */
21
- const runMigration = async ({
22
- payload,
23
- functionName,
24
- lambdaClient,
25
- statusCallback
26
- }) => {
27
- // We don't report status, if `stdout` is not TTY (usually in CIs, and child processes spawned programmatically).
28
- const reportStatus = data => {
29
- if (!process.stdout.isTTY || typeof statusCallback !== "function") {
30
- return;
31
- }
32
- statusCallback(data);
33
- };
34
- const invokeMigration = async () => {
35
- const response = await lambdaClient.invoke({
36
- FunctionName: functionName,
37
- InvocationType: "Event",
38
- Payload: JSON.stringify((0, _objectSpread2.default)((0, _objectSpread2.default)({}, payload), {}, {
39
- command: "execute"
40
- }))
41
- }).promise();
42
- return response.StatusCode;
43
- };
44
-
45
- // Execute migration function.
46
- await invokeMigration();
47
-
48
- // Poll for status and re-execute when migration is in "pending" state.
49
- let response;
50
- while (true) {
51
- await new Promise(resolve => setTimeout(resolve, getMigrationStatusReportInterval()));
52
- response = await (0, _getMigrationStatus.getMigrationStatus)({
53
- payload,
54
- functionName,
55
- lambdaClient
56
- });
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 response;
68
- }
69
- switch (data.status) {
70
- case "init":
71
- reportStatus(data);
72
- continue;
73
- case "pending":
74
- await invokeMigration();
75
- break;
76
- case "running":
77
- reportStatus(data);
78
- break;
79
- case "done":
80
- default:
81
- return response;
82
- }
83
- }
84
- };
85
- exports.runMigration = runMigration;
86
-
87
- //# sourceMappingURL=runMigration.js.map
@@ -1 +0,0 @@
1
- {"version":3,"names":["_getMigrationStatus","require","getMigrationStatusReportInterval","envKey","process","env","parseInt","String","runMigration","payload","functionName","lambdaClient","statusCallback","reportStatus","data","stdout","isTTY","invokeMigration","response","invoke","FunctionName","InvocationType","Payload","JSON","stringify","_objectSpread2","default","command","promise","StatusCode","Promise","resolve","setTimeout","getMigrationStatus","error","status","exports"],"sources":["runMigration.ts"],"sourcesContent":["import LambdaClient from \"aws-sdk/clients/lambda\";\nimport {\n MigrationEventHandlerResponse,\n MigrationInvocationErrorResponse,\n MigrationRun,\n MigrationStatus,\n MigrationStatusResponse\n} from \"~/types\";\nimport { getMigrationStatus } from \"./getMigrationStatus\";\n\ninterface RunMigrationParams {\n lambdaClient: LambdaClient;\n functionName: string;\n payload?: Record<string, any>;\n statusCallback?: (status: MigrationRun) => void;\n}\n\nconst 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/**\n * Run the migration Lambda, and re-run when resuming is requested.\n */\nexport const runMigration = async ({\n payload,\n functionName,\n lambdaClient,\n statusCallback\n}: RunMigrationParams): Promise<MigrationStatusResponse | MigrationInvocationErrorResponse> => {\n // We don't report status, if `stdout` is not TTY (usually in CIs, and child processes spawned programmatically).\n const reportStatus = (data: MigrationStatus) => {\n if (!process.stdout.isTTY || typeof statusCallback !== \"function\") {\n return;\n }\n\n statusCallback(data);\n };\n\n const invokeMigration = async () => {\n const response = await lambdaClient\n .invoke({\n FunctionName: functionName,\n InvocationType: \"Event\",\n Payload: JSON.stringify({ ...payload, command: \"execute\" })\n })\n .promise();\n\n return response.StatusCode;\n };\n\n // Execute migration function.\n await invokeMigration();\n\n // Poll for status and re-execute when migration is in \"pending\" state.\n let response: MigrationEventHandlerResponse;\n while (true) {\n await new Promise(resolve => setTimeout(resolve, getMigrationStatusReportInterval()));\n\n response = await getMigrationStatus({\n payload,\n functionName,\n lambdaClient\n });\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 response;\n }\n\n switch (data.status) {\n case \"init\":\n reportStatus(data);\n continue;\n case \"pending\":\n await invokeMigration();\n break;\n case \"running\":\n reportStatus(data);\n break;\n case \"done\":\n default:\n return response;\n }\n }\n};\n"],"mappings":";;;;;;;;AAQA,IAAAA,mBAAA,GAAAC,OAAA;AASA,MAAMC,gCAAgC,GAAGA,CAAA,KAAM;EAC3C,MAAMC,MAAM,GAAG,kCAAkC;EACjD,IAAIA,MAAM,IAAIC,OAAO,CAACC,GAAG,EAAE;IACvB,OAAOC,QAAQ,CAACC,MAAM,CAACH,OAAO,CAACC,GAAG,CAACF,MAAM,CAAC,CAAC,CAAC;EAChD;EACA,OAAO,IAAI;AACf,CAAC;;AAED;AACA;AACA;AACO,MAAMK,YAAY,GAAG,MAAAA,CAAO;EAC/BC,OAAO;EACPC,YAAY;EACZC,YAAY;EACZC;AACgB,CAAC,KAA0E;EAC3F;EACA,MAAMC,YAAY,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