@webiny/data-migration 0.0.0-unstable.98511f29f1 → 0.0.0-unstable.9bd236cf5e
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.
- package/MigrationRunner.d.ts +8 -4
- package/MigrationRunner.js +85 -19
- package/MigrationRunner.js.map +1 -1
- package/cli/CliMigrationRunReporter.d.ts +10 -0
- package/cli/CliMigrationRunReporter.js +55 -0
- package/cli/CliMigrationRunReporter.js.map +1 -0
- package/cli/InteractiveCliStatusReporter.d.ts +11 -0
- package/cli/InteractiveCliStatusReporter.js +74 -0
- package/cli/InteractiveCliStatusReporter.js.map +1 -0
- package/cli/LogReporter.d.ts +10 -0
- package/cli/LogReporter.js +43 -0
- package/cli/LogReporter.js.map +1 -0
- package/cli/LogStream.d.ts +10 -0
- package/cli/LogStream.js +58 -0
- package/cli/LogStream.js.map +1 -0
- package/cli/MigrationRunReporter.d.ts +4 -0
- package/cli/MigrationRunReporter.js +7 -0
- package/cli/MigrationRunReporter.js.map +1 -0
- package/cli/MigrationRunner.d.ts +45 -0
- package/cli/MigrationRunner.js +136 -0
- package/cli/MigrationRunner.js.map +1 -0
- package/cli/MigrationStatusReporter.d.ts +4 -0
- package/cli/MigrationStatusReporter.js +7 -0
- package/cli/MigrationStatusReporter.js.map +1 -0
- package/cli/NonInteractiveCliStatusReporter.d.ts +9 -0
- package/cli/NonInteractiveCliStatusReporter.js +42 -0
- package/cli/NonInteractiveCliStatusReporter.js.map +1 -0
- package/cli/VoidStatusReporter.d.ts +4 -0
- package/cli/VoidStatusReporter.js +14 -0
- package/cli/VoidStatusReporter.js.map +1 -0
- package/cli/getDuration.js +3 -1
- package/cli/getDuration.js.map +1 -1
- package/cli/index.d.ts +9 -2
- package/cli/index.js +92 -13
- package/cli/index.js.map +1 -1
- package/createPinoLogger.d.ts +4 -7
- package/createPinoLogger.js +7 -3
- package/createPinoLogger.js.map +1 -1
- package/createTable.d.ts +4 -4
- package/createTable.js +8 -4
- package/createTable.js.map +1 -1
- package/handlers/createDdbEsProjectMigration.d.ts +7 -7
- package/handlers/createDdbEsProjectMigration.js +21 -18
- package/handlers/createDdbEsProjectMigration.js.map +1 -1
- package/handlers/createDdbProjectMigration.d.ts +5 -5
- package/handlers/createDdbProjectMigration.js +19 -16
- package/handlers/createDdbProjectMigration.js.map +1 -1
- package/handlers/createPatternMatcher.d.ts +1 -1
- package/handlers/createPatternMatcher.js +3 -1
- package/handlers/createPatternMatcher.js.map +1 -1
- package/handlers/devVersionErrorResponse.js +3 -1
- package/handlers/devVersionErrorResponse.js.map +1 -1
- package/index.d.ts +0 -1
- package/index.js +3 -12
- package/index.js.map +1 -1
- package/package.json +17 -29
- package/repository/createStandardEntity.d.ts +50 -3
- package/repository/createStandardEntity.js +5 -3
- package/repository/createStandardEntity.js.map +1 -1
- package/repository/migrations.repository.d.ts +3 -3
- package/repository/migrations.repository.js +49 -36
- package/repository/migrations.repository.js.map +1 -1
- package/symbols.js +9 -14
- package/symbols.js.map +1 -1
- package/types.d.ts +9 -6
- package/types.js +2 -7
- package/types.js.map +1 -1
- package/cli/getMigrationStatus.d.ts +0 -9
- package/cli/getMigrationStatus.js +0 -27
- package/cli/getMigrationStatus.js.map +0 -1
- package/cli/printReport.d.ts +0 -9
- package/cli/printReport.js +0 -57
- package/cli/printReport.js.map +0 -1
- package/cli/runMigration.d.ts +0 -13
- package/cli/runMigration.js +0 -85
- package/cli/runMigration.js.map +0 -1
|
@@ -1,20 +1,16 @@
|
|
|
1
1
|
"use strict";
|
|
2
2
|
|
|
3
|
-
var _interopRequireDefault = require("@babel/runtime/helpers/interopRequireDefault").default;
|
|
4
3
|
Object.defineProperty(exports, "__esModule", {
|
|
5
4
|
value: true
|
|
6
5
|
});
|
|
7
6
|
exports.MigrationRepositoryImpl = void 0;
|
|
8
|
-
var _defineProperty2 = _interopRequireDefault(require("@babel/runtime/helpers/defineProperty"));
|
|
9
7
|
var _query = require("@webiny/db-dynamodb/utils/query");
|
|
10
8
|
var _ioc = require("@webiny/ioc");
|
|
11
9
|
var _symbols = require("../symbols");
|
|
12
10
|
var _createStandardEntity = require("./createStandardEntity");
|
|
11
|
+
var _dbDynamodb = require("@webiny/db-dynamodb");
|
|
13
12
|
class MigrationRepositoryImpl {
|
|
14
13
|
constructor(table) {
|
|
15
|
-
(0, _defineProperty2.default)(this, "run", void 0);
|
|
16
|
-
(0, _defineProperty2.default)(this, "migration", void 0);
|
|
17
|
-
(0, _defineProperty2.default)(this, "checkpoint", void 0);
|
|
18
14
|
this.run = (0, _createStandardEntity.createStandardEntity)({
|
|
19
15
|
table,
|
|
20
16
|
name: "MigrationRun"
|
|
@@ -41,13 +37,16 @@ class MigrationRepositoryImpl {
|
|
|
41
37
|
return result ? result.data : null;
|
|
42
38
|
}
|
|
43
39
|
async saveRun(run) {
|
|
44
|
-
await
|
|
45
|
-
|
|
46
|
-
|
|
47
|
-
|
|
48
|
-
|
|
49
|
-
|
|
50
|
-
|
|
40
|
+
await (0, _dbDynamodb.put)({
|
|
41
|
+
entity: this.run,
|
|
42
|
+
item: {
|
|
43
|
+
PK: `MIGRATION_RUN#${run.id}`,
|
|
44
|
+
SK: "A",
|
|
45
|
+
TYPE: "migration.run",
|
|
46
|
+
GSI1_PK: "MIGRATION_RUNS",
|
|
47
|
+
GSI1_SK: run.id,
|
|
48
|
+
data: run
|
|
49
|
+
}
|
|
51
50
|
});
|
|
52
51
|
}
|
|
53
52
|
async listMigrations(params) {
|
|
@@ -68,41 +67,55 @@ class MigrationRepositoryImpl {
|
|
|
68
67
|
return result.map(item => item.data);
|
|
69
68
|
}
|
|
70
69
|
async logMigration(migration) {
|
|
71
|
-
await
|
|
72
|
-
|
|
73
|
-
|
|
74
|
-
|
|
75
|
-
|
|
76
|
-
|
|
77
|
-
|
|
70
|
+
await (0, _dbDynamodb.put)({
|
|
71
|
+
entity: this.migration,
|
|
72
|
+
item: {
|
|
73
|
+
PK: `MIGRATION#${migration.id}`,
|
|
74
|
+
SK: "A",
|
|
75
|
+
TYPE: "migration",
|
|
76
|
+
GSI1_PK: "MIGRATIONS",
|
|
77
|
+
GSI1_SK: migration.id,
|
|
78
|
+
data: migration
|
|
79
|
+
}
|
|
78
80
|
});
|
|
79
81
|
}
|
|
80
82
|
async createCheckpoint(id, data) {
|
|
81
|
-
await
|
|
82
|
-
|
|
83
|
-
|
|
84
|
-
|
|
85
|
-
|
|
86
|
-
|
|
87
|
-
|
|
83
|
+
await (0, _dbDynamodb.put)({
|
|
84
|
+
entity: this.checkpoint,
|
|
85
|
+
item: {
|
|
86
|
+
PK: `MIGRATION_CHECKPOINT#${id}`,
|
|
87
|
+
SK: "A",
|
|
88
|
+
TYPE: "migration.checkpoint",
|
|
89
|
+
GSI1_PK: "MIGRATION_CHECKPOINTS",
|
|
90
|
+
GSI1_SK: id,
|
|
91
|
+
data
|
|
92
|
+
}
|
|
88
93
|
});
|
|
89
94
|
}
|
|
90
|
-
deleteCheckpoint(id) {
|
|
91
|
-
|
|
92
|
-
|
|
93
|
-
|
|
95
|
+
async deleteCheckpoint(id) {
|
|
96
|
+
await (0, _dbDynamodb.deleteItem)({
|
|
97
|
+
entity: this.checkpoint,
|
|
98
|
+
keys: {
|
|
99
|
+
PK: `MIGRATION_CHECKPOINT#${id}`,
|
|
100
|
+
SK: "A"
|
|
101
|
+
}
|
|
94
102
|
});
|
|
95
103
|
}
|
|
96
104
|
async getCheckpoint(id) {
|
|
97
|
-
const record = await
|
|
98
|
-
|
|
99
|
-
|
|
105
|
+
const record = await (0, _dbDynamodb.get)({
|
|
106
|
+
entity: this.checkpoint,
|
|
107
|
+
keys: {
|
|
108
|
+
PK: `MIGRATION_CHECKPOINT#${id}`,
|
|
109
|
+
SK: "A"
|
|
110
|
+
}
|
|
100
111
|
});
|
|
101
|
-
if (!record
|
|
112
|
+
if (!record) {
|
|
102
113
|
return null;
|
|
103
114
|
}
|
|
104
|
-
return record.
|
|
115
|
+
return record.data;
|
|
105
116
|
}
|
|
106
117
|
}
|
|
107
118
|
exports.MigrationRepositoryImpl = MigrationRepositoryImpl;
|
|
108
|
-
(0, _ioc.makeInjectable)(MigrationRepositoryImpl, [(0, _ioc.inject)(_symbols.PrimaryDynamoTableSymbol)]);
|
|
119
|
+
(0, _ioc.makeInjectable)(MigrationRepositoryImpl, [(0, _ioc.inject)(_symbols.PrimaryDynamoTableSymbol)]);
|
|
120
|
+
|
|
121
|
+
//# sourceMappingURL=migrations.repository.js.map
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"names":["_query","require","_ioc","_symbols","_createStandardEntity","MigrationRepositoryImpl","constructor","table","
|
|
1
|
+
{"version":3,"names":["_query","require","_ioc","_symbols","_createStandardEntity","_dbDynamodb","MigrationRepositoryImpl","constructor","table","run","createStandardEntity","name","migration","checkpoint","getLastRun","result","queryOne","entity","partitionKey","options","index","gt","reverse","data","saveRun","put","item","PK","id","SK","TYPE","GSI1_PK","GSI1_SK","listMigrations","params","limit","queryAll","map","logMigration","createCheckpoint","deleteCheckpoint","deleteItem","keys","getCheckpoint","record","get","exports","makeInjectable","inject","PrimaryDynamoTableSymbol"],"sources":["migrations.repository.ts"],"sourcesContent":["import type { Entity, Table } from \"@webiny/db-dynamodb/toolbox\";\nimport { queryAll, queryOne } from \"@webiny/db-dynamodb/utils/query\";\nimport type { MigrationItem, MigrationRepository, MigrationRun } from \"~/types\";\nimport { inject, makeInjectable } from \"@webiny/ioc\";\nimport { PrimaryDynamoTableSymbol } from \"~/symbols\";\nimport { createStandardEntity } from \"./createStandardEntity\";\nimport { deleteItem, get, put } from \"@webiny/db-dynamodb\";\n\ninterface MigrationCheckpoint {\n data: unknown;\n}\n\nexport class MigrationRepositoryImpl implements MigrationRepository {\n private readonly run: Entity<any>;\n private readonly migration: Entity<any>;\n private readonly checkpoint: Entity<any>;\n\n constructor(table: Table<string, string, string>) {\n this.run = createStandardEntity({ table, name: \"MigrationRun\" });\n this.migration = createStandardEntity({ table, name: \"Migration\" });\n this.checkpoint = createStandardEntity({ table, name: \"MigrationCheckpoint\" });\n }\n\n async getLastRun(): Promise<MigrationRun | null> {\n const result = await queryOne<{ data: MigrationRun }>({\n entity: this.run,\n partitionKey: \"MIGRATION_RUNS\",\n options: {\n index: \"GSI1\",\n gt: \" \",\n reverse: true\n }\n });\n\n return result ? result.data : null;\n }\n\n async saveRun(run: MigrationRun): Promise<void> {\n await put({\n entity: this.run,\n item: {\n PK: `MIGRATION_RUN#${run.id}`,\n SK: \"A\",\n TYPE: \"migration.run\",\n GSI1_PK: \"MIGRATION_RUNS\",\n GSI1_SK: run.id,\n data: run\n }\n });\n }\n\n async listMigrations(params?: { limit: number }): Promise<MigrationItem[]> {\n const { limit } = params || {};\n const result = await queryAll<{ data: MigrationItem }>({\n entity: this.migration,\n partitionKey: \"MIGRATIONS\",\n options: {\n index: \"GSI1\",\n gt: \" \",\n limit,\n // Sort by GSI1_SK in descending order.\n reverse: true\n }\n });\n\n return result.map(item => item.data);\n }\n\n async logMigration(migration: MigrationItem): Promise<void> {\n await put({\n entity: this.migration,\n item: {\n PK: `MIGRATION#${migration.id}`,\n SK: \"A\",\n TYPE: \"migration\",\n GSI1_PK: \"MIGRATIONS\",\n GSI1_SK: migration.id,\n data: migration\n }\n });\n }\n\n async createCheckpoint(id: string, data: unknown): Promise<void> {\n await put({\n entity: this.checkpoint,\n item: {\n PK: `MIGRATION_CHECKPOINT#${id}`,\n SK: \"A\",\n TYPE: \"migration.checkpoint\",\n GSI1_PK: \"MIGRATION_CHECKPOINTS\",\n GSI1_SK: id,\n data\n }\n });\n }\n\n async deleteCheckpoint(id: string): Promise<void> {\n await deleteItem({\n entity: this.checkpoint,\n keys: {\n PK: `MIGRATION_CHECKPOINT#${id}`,\n SK: \"A\"\n }\n });\n }\n\n async getCheckpoint(id: string): Promise<unknown | null> {\n const record = await get<MigrationCheckpoint>({\n entity: this.checkpoint,\n keys: {\n PK: `MIGRATION_CHECKPOINT#${id}`,\n SK: \"A\"\n }\n });\n\n if (!record) {\n return null;\n }\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MAAM,IAAAa,sBAAU,EAAC;MACbxB,MAAM,EAAE,IAAI,CAACJ,UAAU;MACvB6B,IAAI,EAAE;QACFf,EAAE,EAAE,wBAAwBC,EAAE,EAAE;QAChCC,EAAE,EAAE;MACR;IACJ,CAAC,CAAC;EACN;EAEA,MAAMc,aAAaA,CAACf,EAAU,EAA2B;IACrD,MAAMgB,MAAM,GAAG,MAAM,IAAAC,eAAG,EAAsB;MAC1C5B,MAAM,EAAE,IAAI,CAACJ,UAAU;MACvB6B,IAAI,EAAE;QACFf,EAAE,EAAE,wBAAwBC,EAAE,EAAE;QAChCC,EAAE,EAAE;MACR;IACJ,CAAC,CAAC;IAEF,IAAI,CAACe,MAAM,EAAE;MACT,OAAO,IAAI;IACf;IACA,OAAOA,MAAM,CAACrB,IAAI;EACtB;AACJ;AAACuB,OAAA,CAAAxC,uBAAA,GAAAA,uBAAA;AAED,IAAAyC,mBAAc,EAACzC,uBAAuB,EAAE,CAAC,IAAA0C,WAAM,EAACC,iCAAwB,CAAC,CAAC,CAAC","ignoreList":[]}
|
package/symbols.js
CHANGED
|
@@ -4,17 +4,12 @@ Object.defineProperty(exports, "__esModule", {
|
|
|
4
4
|
value: true
|
|
5
5
|
});
|
|
6
6
|
exports.PrimaryDynamoTableSymbol = exports.MigrationSymbol = exports.MigrationRepositorySymbol = exports.LoggerSymbol = exports.ExecutionTimeLimiterSymbol = exports.ElasticsearchDynamoTableSymbol = exports.ElasticsearchClientSymbol = void 0;
|
|
7
|
-
const LoggerSymbol = Symbol.for("PinoLogger");
|
|
8
|
-
exports.
|
|
9
|
-
const
|
|
10
|
-
exports.
|
|
11
|
-
const
|
|
12
|
-
exports.
|
|
13
|
-
const
|
|
14
|
-
|
|
15
|
-
|
|
16
|
-
exports.PrimaryDynamoTableSymbol = PrimaryDynamoTableSymbol;
|
|
17
|
-
const ElasticsearchDynamoTableSymbol = Symbol.for("ElasticsearchDynamoTable");
|
|
18
|
-
exports.ElasticsearchDynamoTableSymbol = ElasticsearchDynamoTableSymbol;
|
|
19
|
-
const ExecutionTimeLimiterSymbol = Symbol.for("ExecutionTimeLimiter");
|
|
20
|
-
exports.ExecutionTimeLimiterSymbol = ExecutionTimeLimiterSymbol;
|
|
7
|
+
const LoggerSymbol = exports.LoggerSymbol = Symbol.for("PinoLogger");
|
|
8
|
+
const MigrationSymbol = exports.MigrationSymbol = Symbol.for("Migration");
|
|
9
|
+
const MigrationRepositorySymbol = exports.MigrationRepositorySymbol = Symbol.for("MigrationRepository");
|
|
10
|
+
const ElasticsearchClientSymbol = exports.ElasticsearchClientSymbol = Symbol.for("ElasticsearchClient");
|
|
11
|
+
const PrimaryDynamoTableSymbol = exports.PrimaryDynamoTableSymbol = Symbol.for("PrimaryDynamoTable");
|
|
12
|
+
const ElasticsearchDynamoTableSymbol = exports.ElasticsearchDynamoTableSymbol = Symbol.for("ElasticsearchDynamoTable");
|
|
13
|
+
const ExecutionTimeLimiterSymbol = exports.ExecutionTimeLimiterSymbol = Symbol.for("ExecutionTimeLimiter");
|
|
14
|
+
|
|
15
|
+
//# sourceMappingURL=symbols.js.map
|
package/symbols.js.map
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"names":["LoggerSymbol","
|
|
1
|
+
{"version":3,"names":["LoggerSymbol","exports","Symbol","for","MigrationSymbol","MigrationRepositorySymbol","ElasticsearchClientSymbol","PrimaryDynamoTableSymbol","ElasticsearchDynamoTableSymbol","ExecutionTimeLimiterSymbol"],"sources":["symbols.ts"],"sourcesContent":["export const LoggerSymbol = Symbol.for(\"PinoLogger\");\nexport const MigrationSymbol = Symbol.for(\"Migration\");\nexport const MigrationRepositorySymbol = Symbol.for(\"MigrationRepository\");\nexport const ElasticsearchClientSymbol = Symbol.for(\"ElasticsearchClient\");\nexport const PrimaryDynamoTableSymbol = Symbol.for(\"PrimaryDynamoTable\");\nexport const ElasticsearchDynamoTableSymbol = Symbol.for(\"ElasticsearchDynamoTable\");\nexport const ExecutionTimeLimiterSymbol = Symbol.for(\"ExecutionTimeLimiter\");\n"],"mappings":";;;;;;AAAO,MAAMA,YAAY,GAAAC,OAAA,CAAAD,YAAA,GAAGE,MAAM,CAACC,GAAG,CAAC,YAAY,CAAC;AAC7C,MAAMC,eAAe,GAAAH,OAAA,CAAAG,eAAA,GAAGF,MAAM,CAACC,GAAG,CAAC,WAAW,CAAC;AAC/C,MAAME,yBAAyB,GAAAJ,OAAA,CAAAI,yBAAA,GAAGH,MAAM,CAACC,GAAG,CAAC,qBAAqB,CAAC;AACnE,MAAMG,yBAAyB,GAAAL,OAAA,CAAAK,yBAAA,GAAGJ,MAAM,CAACC,GAAG,CAAC,qBAAqB,CAAC;AACnE,MAAMI,wBAAwB,GAAAN,OAAA,CAAAM,wBAAA,GAAGL,MAAM,CAACC,GAAG,CAAC,oBAAoB,CAAC;AACjE,MAAMK,8BAA8B,GAAAP,OAAA,CAAAO,8BAAA,GAAGN,MAAM,CAACC,GAAG,CAAC,0BAA0B,CAAC;AAC7E,MAAMM,0BAA0B,GAAAR,OAAA,CAAAQ,0BAAA,GAAGP,MAAM,CAACC,GAAG,CAAC,sBAAsB,CAAC","ignoreList":[]}
|
package/types.d.ts
CHANGED
|
@@ -1,5 +1,5 @@
|
|
|
1
|
-
import { Logger } from "
|
|
2
|
-
export { Logger };
|
|
1
|
+
import type { Logger } from "@webiny/logger";
|
|
2
|
+
export type { Logger };
|
|
3
3
|
export interface MigrationItem {
|
|
4
4
|
id: string;
|
|
5
5
|
description: string;
|
|
@@ -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,9 +43,10 @@ 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
|
-
createCheckpoint: (data: TCheckpoint) => void
|
|
47
|
-
createCheckpointAndExit: (data: TCheckpoint) => void
|
|
48
|
+
createCheckpoint: (data: TCheckpoint) => Promise<void>;
|
|
49
|
+
createCheckpointAndExit: (data: TCheckpoint) => Promise<void>;
|
|
48
50
|
}
|
|
49
51
|
export interface DataMigration<TCheckpoint = any> {
|
|
50
52
|
getId(): string;
|
|
@@ -55,13 +57,14 @@ export interface DataMigration<TCheckpoint = any> {
|
|
|
55
57
|
/**
|
|
56
58
|
* Migration execution time limiter (in milliseconds).
|
|
57
59
|
*/
|
|
58
|
-
export
|
|
60
|
+
export type ExecutionTimeLimiter = () => number;
|
|
59
61
|
export interface MigrationEventPayload {
|
|
60
62
|
command: "status" | "execute";
|
|
61
63
|
version?: string;
|
|
62
64
|
pattern?: string;
|
|
65
|
+
force?: boolean;
|
|
63
66
|
}
|
|
64
|
-
export
|
|
67
|
+
export type MigrationEventHandlerResponse = undefined | MigrationStatusResponse | MigrationInvocationErrorResponse;
|
|
65
68
|
export interface MigrationInvocationErrorResponse {
|
|
66
69
|
error: {
|
|
67
70
|
message: string;
|
package/types.js
CHANGED
|
@@ -3,10 +3,5 @@
|
|
|
3
3
|
Object.defineProperty(exports, "__esModule", {
|
|
4
4
|
value: true
|
|
5
5
|
});
|
|
6
|
-
|
|
7
|
-
|
|
8
|
-
get: function () {
|
|
9
|
-
return _pino.Logger;
|
|
10
|
-
}
|
|
11
|
-
});
|
|
12
|
-
var _pino = require("pino");
|
|
6
|
+
|
|
7
|
+
//# sourceMappingURL=types.js.map
|
package/types.js.map
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"names":[
|
|
1
|
+
{"version":3,"names":[],"sources":["types.ts"],"sourcesContent":["import type { 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) => Promise<void>;\n createCheckpointAndExit: (data: TCheckpoint) => Promise<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 force?: boolean;\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":"","ignoreList":[]}
|
|
@@ -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,27 +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;
|
|
@@ -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"}
|
package/cli/printReport.d.ts
DELETED
|
@@ -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 {};
|
package/cli/printReport.js
DELETED
|
@@ -1,57 +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;
|
package/cli/printReport.js.map
DELETED
|
@@ -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,CAACC,QAAQ,CAAC,EAAE;IACnBM,OAAO,C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M,OAAA,CAAA5B,WAAA,GAAAA,WAAA"}
|
package/cli/runMigration.d.ts
DELETED
|
@@ -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 {};
|
package/cli/runMigration.js
DELETED
|
@@ -1,85 +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;
|
package/cli/runMigration.js.map
DELETED
|
@@ -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,GAAIC,IAAqB,IAAK;IAC5C,IAAI,CAACV,OAAO,CAACW,MAAM,CAACC,KAAK,IAAI,OAAOJ,cAAc,KAAK,UAAU,EAAE;MAC/D;IACJ;IAEAA,cAAc,CAACE,IAAI,CAAC;EACxB,CAAC;EAED,MAAMG,eAAe,GAAG,MAAAA,CAAA,KAAY;IAChC,MAAMC,QAAQ,GAAG,MAAMP,YAAY,CAC9BQ,MAAM,CAAC;MACJC,YAAY,EAAEV,YAAY;MAC1BW,cAAc,EAAE,OAAO;MACvBC,OAAO,EAAEC,IAAI,CAACC,SAAS,KAAAC,cAAA,CAAAC,OAAA,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