@webiny/data-migration 0.0.0-unstable.99666aeb00 → 0.0.0-unstable.a9593f74dd

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 (74) hide show
  1. package/MigrationRunner.d.ts +3 -1
  2. package/MigrationRunner.js +29 -16
  3. package/MigrationRunner.js.map +1 -1
  4. package/cli/CliMigrationRunReporter.d.ts +10 -0
  5. package/cli/CliMigrationRunReporter.js +55 -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 +43 -0
  12. package/cli/LogReporter.js.map +1 -0
  13. package/cli/LogStream.d.ts +10 -0
  14. package/cli/LogStream.js +58 -0
  15. package/cli/LogStream.js.map +1 -0
  16. package/cli/MigrationRunReporter.d.ts +4 -0
  17. package/cli/MigrationRunReporter.js +7 -0
  18. package/cli/MigrationRunReporter.js.map +1 -0
  19. package/cli/MigrationRunner.d.ts +44 -0
  20. package/cli/MigrationRunner.js +136 -0
  21. package/cli/MigrationRunner.js.map +1 -0
  22. package/cli/MigrationStatusReporter.d.ts +4 -0
  23. package/cli/MigrationStatusReporter.js +7 -0
  24. package/cli/MigrationStatusReporter.js.map +1 -0
  25. package/cli/NonInteractiveCliStatusReporter.d.ts +9 -0
  26. package/cli/NonInteractiveCliStatusReporter.js +42 -0
  27. package/cli/NonInteractiveCliStatusReporter.js.map +1 -0
  28. package/cli/VoidStatusReporter.d.ts +4 -0
  29. package/cli/VoidStatusReporter.js +14 -0
  30. package/cli/VoidStatusReporter.js.map +1 -0
  31. package/cli/getDuration.js +3 -1
  32. package/cli/getDuration.js.map +1 -1
  33. package/cli/index.d.ts +8 -2
  34. package/cli/index.js +81 -13
  35. package/cli/index.js.map +1 -1
  36. package/createPinoLogger.d.ts +57 -4
  37. package/createPinoLogger.js +7 -3
  38. package/createPinoLogger.js.map +1 -1
  39. package/createTable.d.ts +4 -4
  40. package/createTable.js +9 -4
  41. package/createTable.js.map +1 -1
  42. package/handlers/createDdbEsProjectMigration.d.ts +3 -3
  43. package/handlers/createDdbEsProjectMigration.js +19 -17
  44. package/handlers/createDdbEsProjectMigration.js.map +1 -1
  45. package/handlers/createDdbProjectMigration.d.ts +2 -2
  46. package/handlers/createDdbProjectMigration.js +17 -15
  47. package/handlers/createDdbProjectMigration.js.map +1 -1
  48. package/handlers/createPatternMatcher.js +3 -1
  49. package/handlers/createPatternMatcher.js.map +1 -1
  50. package/handlers/devVersionErrorResponse.js +3 -1
  51. package/handlers/devVersionErrorResponse.js.map +1 -1
  52. package/index.js +3 -1
  53. package/index.js.map +1 -1
  54. package/package.json +15 -15
  55. package/repository/createStandardEntity.d.ts +49 -3
  56. package/repository/createStandardEntity.js +5 -3
  57. package/repository/createStandardEntity.js.map +1 -1
  58. package/repository/migrations.repository.d.ts +2 -2
  59. package/repository/migrations.repository.js +49 -36
  60. package/repository/migrations.repository.js.map +1 -1
  61. package/symbols.js +3 -1
  62. package/symbols.js.map +1 -1
  63. package/types.d.ts +6 -4
  64. package/types.js +2 -7
  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
@@ -1,11 +1,9 @@
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.createDdbEsProjectMigration = void 0;
8
- var _objectWithoutProperties2 = _interopRequireDefault(require("@babel/runtime/helpers/objectWithoutProperties"));
9
7
  var _handlerAws = require("@webiny/handler-aws");
10
8
  var _ioc = require("@webiny/ioc");
11
9
  var _symbols = require("../symbols");
@@ -14,24 +12,22 @@ var _migrations = require("../repository/migrations.repository");
14
12
  var _devVersionErrorResponse = require("./devVersionErrorResponse");
15
13
  var _createPatternMatcher = require("./createPatternMatcher");
16
14
  var _semver = require("semver");
17
- const _excluded = ["migrations", "elasticsearchClient", "primaryTable", "dynamoToEsTable", "isMigrationApplicable", "repository"];
18
- const createDdbEsProjectMigration = _ref => {
19
- let {
20
- migrations,
21
- elasticsearchClient,
22
- primaryTable,
23
- dynamoToEsTable,
24
- isMigrationApplicable = undefined,
25
- repository = undefined
26
- } = _ref,
27
- config = (0, _objectWithoutProperties2.default)(_ref, _excluded);
15
+ const createDdbEsProjectMigration = ({
16
+ migrations,
17
+ elasticsearchClient,
18
+ primaryTable,
19
+ dynamoToEsTable,
20
+ isMigrationApplicable = undefined,
21
+ repository = undefined,
22
+ ...config
23
+ }) => {
28
24
  return (0, _handlerAws.createRawEventHandler)(async ({
29
25
  payload,
30
26
  lambdaContext
31
27
  }) => {
32
- const projectVersion = String((payload === null || payload === void 0 ? void 0 : payload.version) || process.env.WEBINY_VERSION);
28
+ const projectVersion = String(payload?.version || process.env.WEBINY_VERSION);
33
29
  const version = (0, _semver.coerce)(projectVersion);
34
- if ((version === null || version === void 0 ? void 0 : version.version) === "0.0.0") {
30
+ if (version?.version === "0.0.0") {
35
31
  return (0, _devVersionErrorResponse.devVersionErrorResponse)();
36
32
  }
37
33
 
@@ -40,7 +36,7 @@ const createDdbEsProjectMigration = _ref => {
40
36
  container.bind(_symbols.PrimaryDynamoTableSymbol).toConstantValue(primaryTable);
41
37
  container.bind(_symbols.ElasticsearchDynamoTableSymbol).toConstantValue(dynamoToEsTable);
42
38
  container.bind(_symbols.ElasticsearchClientSymbol).toConstantValue(elasticsearchClient);
43
- const timeLimiter = config.timeLimiter || (lambdaContext === null || lambdaContext === void 0 ? void 0 : lambdaContext.getRemainingTimeInMillis) || (() => 0);
39
+ const timeLimiter = config.timeLimiter || lambdaContext?.getRemainingTimeInMillis || (() => 0);
44
40
  container.bind(_symbols.ExecutionTimeLimiterSymbol).toConstantValue(timeLimiter);
45
41
  if (repository) {
46
42
  // Repository implementation provided by the user.
@@ -62,6 +58,10 @@ const createDdbEsProjectMigration = _ref => {
62
58
  // Inject dependencies and execute.
63
59
  try {
64
60
  const runner = await container.resolve(_MigrationRunner.MigrationRunner);
61
+ runner.setContext({
62
+ logGroupName: process.env.AWS_LAMBDA_LOG_GROUP_NAME,
63
+ logStreamName: process.env.AWS_LAMBDA_LOG_STREAM_NAME
64
+ });
65
65
  if (payload.command === "execute") {
66
66
  await runner.execute(projectVersion, patternMatcher || isMigrationApplicable);
67
67
  return;
@@ -78,4 +78,6 @@ const createDdbEsProjectMigration = _ref => {
78
78
  }
79
79
  });
80
80
  };
81
- exports.createDdbEsProjectMigration = createDdbEsProjectMigration;
81
+ exports.createDdbEsProjectMigration = createDdbEsProjectMigration;
82
+
83
+ //# sourceMappingURL=createDdbEsProjectMigration.js.map
@@ -1 +1 @@
1
- {"version":3,"names":["createDdbEsProjectMigration","migrations","elasticsearchClient","primaryTable","dynamoToEsTable","isMigrationApplicable","undefined","repository","config","createRawEventHandler","payload","lambdaContext","projectVersion","String","version","process","env","WEBINY_VERSION","semverCoerce","devVersionErrorResponse","container","createContainer","bind","PrimaryDynamoTableSymbol","toConstantValue","ElasticsearchDynamoTableSymbol","ElasticsearchClientSymbol","timeLimiter","getRemainingTimeInMillis","ExecutionTimeLimiterSymbol","MigrationRepositorySymbol","to","MigrationRepositoryImpl","forEach","migration","MigrationSymbol","patternMatcher","pattern","createPatternMatcher","runner","resolve","MigrationRunner","command","execute","data","getStatus","err","error","message"],"sources":["createDdbEsProjectMigration.ts"],"sourcesContent":["import { Client as ElasticsearchClient } from \"@elastic/elasticsearch\";\nimport { Table } from \"dynamodb-toolbox\";\nimport { createRawEventHandler } from \"@webiny/handler-aws\";\nimport { Constructor, createContainer } from \"@webiny/ioc\";\nimport {\n DataMigration,\n ExecutionTimeLimiter,\n MigrationEventHandlerResponse,\n MigrationEventPayload,\n MigrationRepository\n} from \"~/types\";\nimport {\n ElasticsearchClientSymbol,\n ElasticsearchDynamoTableSymbol,\n ExecutionTimeLimiterSymbol,\n MigrationRepositorySymbol,\n MigrationSymbol,\n PrimaryDynamoTableSymbol\n} from \"~/symbols\";\nimport { IsMigrationApplicable, MigrationRunner } from \"~/MigrationRunner\";\nimport { MigrationRepositoryImpl } from \"~/repository/migrations.repository\";\nimport { devVersionErrorResponse } from \"~/handlers/devVersionErrorResponse\";\nimport { createPatternMatcher } from \"~/handlers/createPatternMatcher\";\nimport { coerce as semverCoerce } from \"semver\";\n\ninterface CreateDdbEsDataMigrationConfig {\n elasticsearchClient: ElasticsearchClient;\n primaryTable: Table;\n dynamoToEsTable: Table;\n migrations: Constructor<DataMigration>[];\n isMigrationApplicable?: IsMigrationApplicable;\n repository?: MigrationRepository;\n timeLimiter?: ExecutionTimeLimiter;\n}\n\nexport const createDdbEsProjectMigration = ({\n migrations,\n elasticsearchClient,\n primaryTable,\n dynamoToEsTable,\n isMigrationApplicable = undefined,\n repository = undefined,\n ...config\n}: CreateDdbEsDataMigrationConfig) => {\n return createRawEventHandler<MigrationEventPayload, any, MigrationEventHandlerResponse>(\n async ({ payload, lambdaContext }) => {\n const projectVersion = String(payload?.version || process.env.WEBINY_VERSION);\n\n const version = semverCoerce(projectVersion);\n if (version?.version === \"0.0.0\") {\n return devVersionErrorResponse();\n }\n\n // COMPOSITION ROOT\n const container = createContainer();\n container.bind(PrimaryDynamoTableSymbol).toConstantValue(primaryTable);\n container.bind(ElasticsearchDynamoTableSymbol).toConstantValue(dynamoToEsTable);\n container.bind(ElasticsearchClientSymbol).toConstantValue(elasticsearchClient);\n\n const timeLimiter: ExecutionTimeLimiter =\n config.timeLimiter || lambdaContext?.getRemainingTimeInMillis || (() => 0);\n container.bind(ExecutionTimeLimiterSymbol).toConstantValue(timeLimiter);\n\n if (repository) {\n // Repository implementation provided by the user.\n container.bind(MigrationRepositorySymbol).toConstantValue(repository);\n } else {\n // Default repository implementation.\n container.bind(MigrationRepositorySymbol).to(MigrationRepositoryImpl);\n }\n\n // Bind the provided migrations.\n migrations.forEach(migration => container.bind(MigrationSymbol).to(migration));\n\n // If handler was invoked with a `pattern`, filter migrations that match the pattern only.\n let patternMatcher;\n if (payload.pattern) {\n patternMatcher = createPatternMatcher(payload.pattern);\n }\n\n // Inject dependencies and execute.\n try {\n const runner = await container.resolve(MigrationRunner);\n\n if (payload.command === \"execute\") {\n await runner.execute(projectVersion, patternMatcher || isMigrationApplicable);\n return;\n }\n\n return { data: await runner.getStatus() };\n } catch (err) {\n return { error: { message: err.message } };\n }\n }\n );\n};\n"],"mappings":";;;;;;;;AAEA;AACA;AAQA;AAQA;AACA;AACA;AACA;AACA;AAAgD;AAYzC,MAAMA,2BAA2B,GAAG,QAQL;EAAA,IARM;MACxCC,UAAU;MACVC,mBAAmB;MACnBC,YAAY;MACZC,eAAe;MACfC,qBAAqB,GAAGC,SAAS;MACjCC,UAAU,GAAGD;IAEe,CAAC;IAD1BE,MAAM;EAET,OAAO,IAAAC,iCAAqB,EACxB,OAAO;IAAEC,OAAO;IAAEC;EAAc,CAAC,KAAK;IAClC,MAAMC,cAAc,GAAGC,MAAM,CAAC,CAAAH,OAAO,aAAPA,OAAO,uBAAPA,OAAO,CAAEI,OAAO,KAAIC,OAAO,CAACC,GAAG,CAACC,cAAc,CAAC;IAE7E,MAAMH,OAAO,GAAG,IAAAI,cAAY,EAACN,cAAc,CAAC;IAC5C,IAAI,CAAAE,OAAO,aAAPA,OAAO,uBAAPA,OAAO,CAAEA,OAAO,MAAK,OAAO,EAAE;MAC9B,OAAO,IAAAK,gDAAuB,GAAE;IACpC;;IAEA;IACA,MAAMC,SAAS,GAAG,IAAAC,oBAAe,GAAE;IACnCD,SAA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IAC7C,CAAC,CAAC,OAAOC,GAAG,EAAE;MACV,OAAO;QAAEC,KAAK,EAAE;UAAEC,OAAO,EAAEF,GAAG,CAACE;QAAQ;MAAE,CAAC;IAC9C;EACJ,CAAC,CACJ;AACL,CAAC;AAAC"}
1
+ {"version":3,"names":["_handlerAws","require","_ioc","_symbols","_MigrationRunner","_migrations","_devVersionErrorResponse","_createPatternMatcher","_semver","createDdbEsProjectMigration","migrations","elasticsearchClient","primaryTable","dynamoToEsTable","isMigrationApplicable","undefined","repository","config","createRawEventHandler","payload","lambdaContext","projectVersion","String","version","process","env","WEBINY_VERSION","semverCoerce","devVersionErrorResponse","container","createContainer","bind","PrimaryDynamoTableSymbol","toConstantValue","ElasticsearchDynamoTableSymbol","ElasticsearchClientSymbol","timeLimiter","getRemainingTimeInMillis","ExecutionTimeLimiterSymbol","MigrationRepositorySymbol","to","MigrationRepositoryImpl","forEach","migration","MigrationSymbol","patternMatcher","pattern","createPatternMatcher","runner","resolve","MigrationRunner","setContext","logGroupName","AWS_LAMBDA_LOG_GROUP_NAME","logStreamName","AWS_LAMBDA_LOG_STREAM_NAME","command","execute","data","getStatus","err","error","message","exports"],"sources":["createDdbEsProjectMigration.ts"],"sourcesContent":["import { Client as ElasticsearchClient } from \"@elastic/elasticsearch\";\nimport { Table } from \"@webiny/db-dynamodb/toolbox\";\nimport { createRawEventHandler } from \"@webiny/handler-aws\";\nimport { Constructor, createContainer } from \"@webiny/ioc\";\nimport {\n DataMigration,\n ExecutionTimeLimiter,\n MigrationEventHandlerResponse,\n MigrationEventPayload,\n MigrationRepository\n} from \"~/types\";\nimport {\n ElasticsearchClientSymbol,\n ElasticsearchDynamoTableSymbol,\n ExecutionTimeLimiterSymbol,\n MigrationRepositorySymbol,\n MigrationSymbol,\n PrimaryDynamoTableSymbol\n} from \"~/symbols\";\nimport { IsMigrationApplicable, MigrationRunner } from \"~/MigrationRunner\";\nimport { MigrationRepositoryImpl } from \"~/repository/migrations.repository\";\nimport { devVersionErrorResponse } from \"~/handlers/devVersionErrorResponse\";\nimport { createPatternMatcher } from \"~/handlers/createPatternMatcher\";\nimport { coerce as semverCoerce } from \"semver\";\n\ninterface CreateDdbEsDataMigrationConfig {\n elasticsearchClient: ElasticsearchClient;\n primaryTable: Table<string, string, string>;\n dynamoToEsTable: Table<string, string, string>;\n migrations: Constructor<DataMigration>[];\n isMigrationApplicable?: IsMigrationApplicable;\n repository?: MigrationRepository;\n timeLimiter?: ExecutionTimeLimiter;\n}\n\nexport const createDdbEsProjectMigration = ({\n migrations,\n elasticsearchClient,\n primaryTable,\n dynamoToEsTable,\n isMigrationApplicable = undefined,\n repository = undefined,\n ...config\n}: CreateDdbEsDataMigrationConfig) => {\n return createRawEventHandler<MigrationEventPayload, any, MigrationEventHandlerResponse>(\n async ({ payload, lambdaContext }) => {\n const projectVersion = String(payload?.version || process.env.WEBINY_VERSION);\n\n const version = semverCoerce(projectVersion);\n if (version?.version === \"0.0.0\") {\n return devVersionErrorResponse();\n }\n\n // COMPOSITION ROOT\n const container = createContainer();\n container.bind(PrimaryDynamoTableSymbol).toConstantValue(primaryTable);\n container.bind(ElasticsearchDynamoTableSymbol).toConstantValue(dynamoToEsTable);\n container.bind(ElasticsearchClientSymbol).toConstantValue(elasticsearchClient);\n\n const timeLimiter: ExecutionTimeLimiter =\n config.timeLimiter || lambdaContext?.getRemainingTimeInMillis || (() => 0);\n container.bind(ExecutionTimeLimiterSymbol).toConstantValue(timeLimiter);\n\n if (repository) {\n // Repository implementation provided by the user.\n container.bind(MigrationRepositorySymbol).toConstantValue(repository);\n } else {\n // Default repository implementation.\n container.bind(MigrationRepositorySymbol).to(MigrationRepositoryImpl);\n }\n\n // Bind the provided migrations.\n migrations.forEach(migration => container.bind(MigrationSymbol).to(migration));\n\n // If handler was invoked with a `pattern`, filter migrations that match the pattern only.\n let patternMatcher;\n if (payload.pattern) {\n patternMatcher = createPatternMatcher(payload.pattern);\n }\n\n // Inject dependencies and execute.\n try {\n const runner = await container.resolve(MigrationRunner);\n runner.setContext({\n logGroupName: process.env.AWS_LAMBDA_LOG_GROUP_NAME,\n logStreamName: process.env.AWS_LAMBDA_LOG_STREAM_NAME\n });\n\n if (payload.command === \"execute\") {\n await runner.execute(projectVersion, patternMatcher || isMigrationApplicable);\n return;\n }\n\n return { data: await runner.getStatus() };\n } catch (err) {\n return { error: { message: err.message } };\n }\n }\n );\n};\n"],"mappings":";;;;;;AAEA,IAAAA,WAAA,GAAAC,OAAA;AACA,IAAAC,IAAA,GAAAD,OAAA;AAQA,IAAAE,QAAA,GAAAF,OAAA;AAQA,IAAAG,gBAAA,GAAAH,OAAA;AACA,IAAAI,WAAA,GAAAJ,OAAA;AACA,IAAAK,wBAAA,GAAAL,OAAA;AACA,IAAAM,qBAAA,GAAAN,OAAA;AACA,IAAAO,OAAA,GAAAP,OAAA;AAYO,MAAMQ,2BAA2B,GAAGA,CAAC;EACxCC,UAAU;EACVC,mBAAmB;EACnBC,YAAY;EACZC,eAAe;EACfC,qBAAqB,GAAGC,SAAS;EACjCC,UAAU,GAAGD,SAAS;EACtB,GAAGE;AACyB,CAAC,KAAK;EAClC,OAAO,IAAAC,iCAAqB,EACxB,OAAO;IAAEC,OAAO;IAAEC;EAAc,CAAC,KAAK;IAClC,MAAMC,cAAc,GAAGC,MAAM,CAACH,OAAO,EAAEI,OAAO,IAAIC,OAAO,CAACC,GAAG,CAACC,cAAc,CAAC;IAE7E,MAAMH,OAAO,GAAG,IAAAI,cAAY,EAACN,cAAc,CAAC;IAC5C,IAAIE,OAAO,EAAEA,OAAO,KAAK,OAAO,EAAE;MAC9B,OAAO,IAAAK,gDAAuB,EAAC,CAAC;IACpC;;IAEA;IACA,MAAMC,SAAS,GAAG,IAAAC,oBAAe,EAAC,CAAC;IACnCD,SAAS,CAACE,IAAI,CAACC,iCAAwB,CAAC,CAACC,eAAe,CAACrB,YAAY,CAAC;IACtEiB,SAAS,CAACE,IAAI,CAACG,uCAA8B,CAAC,CAACD,eAAe,CAACpB,eA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7C,CAAC,CAAC,OAAOC,GAAG,EAAE;MACV,OAAO;QAAEC,KAAK,EAAE;UAAEC,OAAO,EAAEF,GAAG,CAACE;QAAQ;MAAE,CAAC;IAC9C;EACJ,CACJ,CAAC;AACL,CAAC;AAACC,OAAA,CAAAtD,2BAAA,GAAAA,2BAAA"}
@@ -1,10 +1,10 @@
1
- import { Table } from "dynamodb-toolbox";
1
+ import { Table } from "@webiny/db-dynamodb/toolbox";
2
2
  import { Constructor } from "@webiny/ioc";
3
3
  import { IsMigrationApplicable } from "../MigrationRunner";
4
4
  import { DataMigration, ExecutionTimeLimiter, MigrationEventHandlerResponse, MigrationEventPayload, MigrationRepository } from "../types";
5
5
  interface CreateDdbDataMigrationConfig {
6
6
  migrations: Constructor<DataMigration>[];
7
- primaryTable: Table;
7
+ primaryTable: Table<string, string, string>;
8
8
  repository?: MigrationRepository;
9
9
  isMigrationApplicable?: IsMigrationApplicable;
10
10
  timeLimiter?: ExecutionTimeLimiter;
@@ -1,11 +1,9 @@
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.createDdbProjectMigration = void 0;
8
- var _objectWithoutProperties2 = _interopRequireDefault(require("@babel/runtime/helpers/objectWithoutProperties"));
9
7
  var _handlerAws = require("@webiny/handler-aws");
10
8
  var _ioc = require("@webiny/ioc");
11
9
  var _MigrationRunner = require("../MigrationRunner");
@@ -14,29 +12,27 @@ var _migrations = require("../repository/migrations.repository");
14
12
  var _devVersionErrorResponse = require("./devVersionErrorResponse");
15
13
  var _createPatternMatcher = require("./createPatternMatcher");
16
14
  var _semver = require("semver");
17
- const _excluded = ["migrations", "primaryTable", "isMigrationApplicable", "repository"];
18
- const createDdbProjectMigration = _ref => {
19
- let {
20
- migrations,
21
- primaryTable,
22
- isMigrationApplicable = undefined,
23
- repository = undefined
24
- } = _ref,
25
- config = (0, _objectWithoutProperties2.default)(_ref, _excluded);
15
+ const createDdbProjectMigration = ({
16
+ migrations,
17
+ primaryTable,
18
+ isMigrationApplicable = undefined,
19
+ repository = undefined,
20
+ ...config
21
+ }) => {
26
22
  return (0, _handlerAws.createRawEventHandler)(async ({
27
23
  payload,
28
24
  lambdaContext
29
25
  }) => {
30
- const projectVersion = String((payload === null || payload === void 0 ? void 0 : payload.version) || process.env.WEBINY_VERSION);
26
+ const projectVersion = String(payload?.version || process.env.WEBINY_VERSION);
31
27
  const version = (0, _semver.coerce)(projectVersion);
32
- if ((version === null || version === void 0 ? void 0 : version.version) === "0.0.0") {
28
+ if (version?.version === "0.0.0") {
33
29
  return (0, _devVersionErrorResponse.devVersionErrorResponse)();
34
30
  }
35
31
 
36
32
  // COMPOSITION ROOT
37
33
  const container = (0, _ioc.createContainer)();
38
34
  container.bind(_symbols.PrimaryDynamoTableSymbol).toConstantValue(primaryTable);
39
- const timeLimiter = config.timeLimiter || (lambdaContext === null || lambdaContext === void 0 ? void 0 : lambdaContext.getRemainingTimeInMillis) || (() => 0);
35
+ const timeLimiter = config.timeLimiter || lambdaContext?.getRemainingTimeInMillis || (() => 0);
40
36
  container.bind(_symbols.ExecutionTimeLimiterSymbol).toConstantValue(timeLimiter);
41
37
  if (repository) {
42
38
  // Repository implementation provided by the user.
@@ -58,6 +54,10 @@ const createDdbProjectMigration = _ref => {
58
54
  // Inject dependencies and execute.
59
55
  try {
60
56
  const runner = await container.resolve(_MigrationRunner.MigrationRunner);
57
+ runner.setContext({
58
+ logGroupName: process.env.AWS_LAMBDA_LOG_GROUP_NAME,
59
+ logStreamName: process.env.AWS_LAMBDA_LOG_STREAM_NAME
60
+ });
61
61
  if (payload.command === "execute") {
62
62
  await runner.execute(projectVersion, patternMatcher || isMigrationApplicable);
63
63
  return;
@@ -74,4 +74,6 @@ const createDdbProjectMigration = _ref => {
74
74
  }
75
75
  });
76
76
  };
77
- exports.createDdbProjectMigration = createDdbProjectMigration;
77
+ exports.createDdbProjectMigration = createDdbProjectMigration;
78
+
79
+ //# sourceMappingURL=createDdbProjectMigration.js.map
@@ -1 +1 @@
1
- {"version":3,"names":["createDdbProjectMigration","migrations","primaryTable","isMigrationApplicable","undefined","repository","config","createRawEventHandler","payload","lambdaContext","projectVersion","String","version","process","env","WEBINY_VERSION","semverCoerce","devVersionErrorResponse","container","createContainer","bind","PrimaryDynamoTableSymbol","toConstantValue","timeLimiter","getRemainingTimeInMillis","ExecutionTimeLimiterSymbol","MigrationRepositorySymbol","to","MigrationRepositoryImpl","forEach","migration","MigrationSymbol","patternMatcher","pattern","createPatternMatcher","runner","resolve","MigrationRunner","command","execute","data","getStatus","err","error","message"],"sources":["createDdbProjectMigration.ts"],"sourcesContent":["import { Table } from \"dynamodb-toolbox\";\nimport { createRawEventHandler } from \"@webiny/handler-aws\";\nimport { Constructor, createContainer } from \"@webiny/ioc\";\nimport { IsMigrationApplicable, MigrationRunner } from \"~/MigrationRunner\";\nimport {\n ExecutionTimeLimiterSymbol,\n MigrationRepositorySymbol,\n MigrationSymbol,\n PrimaryDynamoTableSymbol\n} from \"~/symbols\";\nimport { MigrationRepositoryImpl } from \"~/repository/migrations.repository\";\nimport { devVersionErrorResponse } from \"./devVersionErrorResponse\";\nimport { createPatternMatcher } from \"./createPatternMatcher\";\nimport {\n DataMigration,\n ExecutionTimeLimiter,\n MigrationEventHandlerResponse,\n MigrationEventPayload,\n MigrationRepository\n} from \"~/types\";\nimport { coerce as semverCoerce } from \"semver\";\n\ninterface CreateDdbDataMigrationConfig {\n migrations: Constructor<DataMigration>[];\n primaryTable: Table;\n repository?: MigrationRepository;\n isMigrationApplicable?: IsMigrationApplicable;\n timeLimiter?: ExecutionTimeLimiter;\n}\n\nexport const createDdbProjectMigration = ({\n migrations,\n primaryTable,\n isMigrationApplicable = undefined,\n repository = undefined,\n ...config\n}: CreateDdbDataMigrationConfig) => {\n return createRawEventHandler<MigrationEventPayload, any, MigrationEventHandlerResponse>(\n async ({ payload, lambdaContext }) => {\n const projectVersion = String(payload?.version || process.env.WEBINY_VERSION);\n\n const version = semverCoerce(projectVersion);\n if (version?.version === \"0.0.0\") {\n return devVersionErrorResponse();\n }\n\n // COMPOSITION ROOT\n const container = createContainer();\n container.bind(PrimaryDynamoTableSymbol).toConstantValue(primaryTable);\n\n const timeLimiter: ExecutionTimeLimiter =\n config.timeLimiter || lambdaContext?.getRemainingTimeInMillis || (() => 0);\n container.bind(ExecutionTimeLimiterSymbol).toConstantValue(timeLimiter);\n\n if (repository) {\n // Repository implementation provided by the user.\n container.bind(MigrationRepositorySymbol).toConstantValue(repository);\n } else {\n // Default repository implementation.\n container.bind(MigrationRepositorySymbol).to(MigrationRepositoryImpl);\n }\n\n // Bind the provided migrations.\n migrations.forEach(migration => container.bind(MigrationSymbol).to(migration));\n\n // If handler was invoked with a `pattern`, filter migrations that match the pattern only.\n let patternMatcher;\n if (payload.pattern) {\n patternMatcher = createPatternMatcher(payload.pattern);\n }\n\n // Inject dependencies and execute.\n try {\n const runner = await container.resolve(MigrationRunner);\n\n if (payload.command === \"execute\") {\n await runner.execute(projectVersion, patternMatcher || isMigrationApplicable);\n return;\n }\n\n return { data: await runner.getStatus() };\n } catch (err) {\n return { error: { message: err.message } };\n }\n }\n );\n};\n"],"mappings":";;;;;;;;AACA;AACA;AACA;AACA;AAMA;AACA;AACA;AAQA;AAAgD;AAUzC,MAAMA,yBAAyB,GAAG,QAML;EAAA,IANM;MACtCC,UAAU;MACVC,YAAY;MACZC,qBAAqB,GAAGC,SAAS;MACjCC,UAAU,GAAGD;IAEa,CAAC;IADxBE,MAAM;EAET,OAAO,IAAAC,iCAAqB,EACxB,OAAO;IAAEC,OAAO;IAAEC;EAAc,CAAC,KAAK;IAClC,MAAMC,cAAc,GAAGC,MAAM,CAAC,CAAAH,OAAO,aAAPA,OAAO,uBAAPA,OAAO,CAAEI,OAAO,KAAIC,OAAO,CAACC,GAAG,CAACC,cAAc,CAAC;IAE7E,MAAMH,OAAO,GAAG,IAAAI,cAAY,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I,EAAE,MAAML,MAAM,CAACM,SAAS;MAAG,CAAC;IAC7C,CAAC,CAAC,OAAOC,GAAG,EAAE;MACV,OAAO;QAAEC,KAAK,EAAE;UAAEC,OAAO,EAAEF,GAAG,CAACE;QAAQ;MAAE,CAAC;IAC9C;EACJ,CAAC,CACJ;AACL,CAAC;AAAC"}
1
+ {"version":3,"names":["_handlerAws","require","_ioc","_MigrationRunner","_symbols","_migrations","_devVersionErrorResponse","_createPatternMatcher","_semver","createDdbProjectMigration","migrations","primaryTable","isMigrationApplicable","undefined","repository","config","createRawEventHandler","payload","lambdaContext","projectVersion","String","version","process","env","WEBINY_VERSION","semverCoerce","devVersionErrorResponse","container","createContainer","bind","PrimaryDynamoTableSymbol","toConstantValue","timeLimiter","getRemainingTimeInMillis","ExecutionTimeLimiterSymbol","MigrationRepositorySymbol","to","MigrationRepositoryImpl","forEach","migration","MigrationSymbol","patternMatcher","pattern","createPatternMatcher","runner","resolve","MigrationRunner","setContext","logGroupName","AWS_LAMBDA_LOG_GROUP_NAME","logStreamName","AWS_LAMBDA_LOG_STREAM_NAME","command","execute","data","getStatus","err","error","message","exports"],"sources":["createDdbProjectMigration.ts"],"sourcesContent":["import { Table } from \"@webiny/db-dynamodb/toolbox\";\nimport { createRawEventHandler } from \"@webiny/handler-aws\";\nimport { Constructor, createContainer } from \"@webiny/ioc\";\nimport { IsMigrationApplicable, MigrationRunner } from \"~/MigrationRunner\";\nimport {\n ExecutionTimeLimiterSymbol,\n MigrationRepositorySymbol,\n MigrationSymbol,\n PrimaryDynamoTableSymbol\n} from \"~/symbols\";\nimport { MigrationRepositoryImpl } from \"~/repository/migrations.repository\";\nimport { devVersionErrorResponse } from \"./devVersionErrorResponse\";\nimport { createPatternMatcher } from \"./createPatternMatcher\";\nimport {\n DataMigration,\n ExecutionTimeLimiter,\n MigrationEventHandlerResponse,\n MigrationEventPayload,\n MigrationRepository\n} from \"~/types\";\nimport { coerce as semverCoerce } from \"semver\";\n\ninterface CreateDdbDataMigrationConfig {\n migrations: Constructor<DataMigration>[];\n primaryTable: Table<string, string, string>;\n repository?: MigrationRepository;\n isMigrationApplicable?: IsMigrationApplicable;\n timeLimiter?: ExecutionTimeLimiter;\n}\n\nexport const createDdbProjectMigration = ({\n migrations,\n primaryTable,\n isMigrationApplicable = undefined,\n repository = undefined,\n ...config\n}: CreateDdbDataMigrationConfig) => {\n return createRawEventHandler<MigrationEventPayload, any, MigrationEventHandlerResponse>(\n async ({ payload, lambdaContext }) => {\n const projectVersion = String(payload?.version || process.env.WEBINY_VERSION);\n\n const version = semverCoerce(projectVersion);\n if (version?.version === \"0.0.0\") {\n return devVersionErrorResponse();\n }\n\n // COMPOSITION ROOT\n const container = createContainer();\n container.bind(PrimaryDynamoTableSymbol).toConstantValue(primaryTable);\n\n const timeLimiter: ExecutionTimeLimiter =\n config.timeLimiter || lambdaContext?.getRemainingTimeInMillis || (() => 0);\n container.bind(ExecutionTimeLimiterSymbol).toConstantValue(timeLimiter);\n\n if (repository) {\n // Repository implementation provided by the user.\n container.bind(MigrationRepositorySymbol).toConstantValue(repository);\n } else {\n // Default repository implementation.\n container.bind(MigrationRepositorySymbol).to(MigrationRepositoryImpl);\n }\n\n // Bind the provided migrations.\n migrations.forEach(migration => container.bind(MigrationSymbol).to(migration));\n\n // If handler was invoked with a `pattern`, filter migrations that match the pattern only.\n let patternMatcher;\n if (payload.pattern) {\n patternMatcher = createPatternMatcher(payload.pattern);\n }\n\n // Inject dependencies and execute.\n try {\n const runner = await container.resolve(MigrationRunner);\n runner.setContext({\n logGroupName: process.env.AWS_LAMBDA_LOG_GROUP_NAME,\n logStreamName: process.env.AWS_LAMBDA_LOG_STREAM_NAME\n });\n\n if (payload.command === \"execute\") {\n await runner.execute(projectVersion, patternMatcher || isMigrationApplicable);\n return;\n }\n\n return {\n data: await runner.getStatus()\n };\n } catch (err) {\n return { error: { message: err.message } };\n }\n }\n );\n};\n"],"mappings":";;;;;;AACA,IAAAA,WAAA,GAAAC,OAAA;AACA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zE;;IAEA;IACA3B,UAAU,CAAC4B,OAAO,CAACC,SAAS,IAAIZ,SAAS,CAACE,IAAI,CAACW,wBAAe,CAAC,CAACJ,EAAE,CAACG,SAAS,CAAC,CAAC;;IAE9E;IACA,IAAIE,cAAc;IAClB,IAAIxB,OAAO,CAACyB,OAAO,EAAE;MACjBD,cAAc,GAAG,IAAAE,0CAAoB,EAAC1B,OAAO,CAACyB,OAAO,CAAC;IAC1D;;IAEA;IACA,IAAI;MACA,MAAME,MAAM,GAAG,MAAMjB,SAAS,CAACkB,OAAO,CAACC,gCAAe,CAAC;MACvDF,MAAM,CAACG,UAAU,CAAC;QACdC,YAAY,EAAE1B,OAAO,CAACC,GAAG,CAAC0B,yBAAyB;QACnDC,aAAa,EAAE5B,OAAO,CAACC,GAAG,CAAC4B;MAC/B,CAAC,CAAC;MAEF,IAAIlC,OAAO,CAACmC,OAAO,KAAK,SAAS,EAAE;QAC/B,MAAMR,MAAM,CAACS,OAAO,CAAClC,cAAc,EAAEsB,cAAc,IAAI7B,qBAAqB,CAAC;QAC7E;MACJ;MAEA,OAAO;QACH0C,IAAI,EAAE,MAAMV,MAAM,CAACW,SAAS,CAAC;MACjC,CAAC;IACL,CAAC,CAAC,OAAOC,GAAG,EAAE;MACV,OAAO;QAAEC,KAAK,EAAE;UAAEC,OAAO,EAAEF,GAAG,CAACE;QAAQ;MAAE,CAAC;IAC9C;EACJ,CACJ,CAAC;AACL,CAAC;AAACC,OAAA,CAAAlD,yBAAA,GAAAA,yBAAA"}
@@ -14,4 +14,6 @@ const createPatternMatcher = pattern => {
14
14
  return migration.getId() === pattern;
15
15
  };
16
16
  };
17
- exports.createPatternMatcher = createPatternMatcher;
17
+ exports.createPatternMatcher = createPatternMatcher;
18
+
19
+ //# sourceMappingURL=createPatternMatcher.js.map
@@ -1 +1 @@
1
- {"version":3,"names":["createPatternMatcher","pattern","migration","includes","minimatch","getId"],"sources":["createPatternMatcher.ts"],"sourcesContent":["import minimatch from \"minimatch\";\nimport { IsMigrationApplicable } from \"~/MigrationRunner\";\n\nexport const createPatternMatcher = (pattern: string): IsMigrationApplicable => {\n return migration => {\n if (pattern.includes(\"*\")) {\n return minimatch(migration.getId(), pattern);\n }\n return migration.getId() === pattern;\n };\n};\n"],"mappings":";;;;;;;AAAA;AAGO,MAAMA,oBAAoB,GAAIC,OAAe,IAA4B;EAC5E,OAAOC,SAAS,IAAI;IAChB,IAAID,OAAO,CAACE,QAAQ,CAAC,GAAG,CAAC,EAAE;MACvB,OAAO,IAAAC,kBAAS,EAACF,SAAS,CAACG,KAAK,EAAE,EAAEJ,OAAO,CAAC;IAChD;IACA,OAAOC,SAAS,CAACG,KAAK,EAAE,KAAKJ,OAAO;EACxC,CAAC;AACL,CAAC;AAAC"}
1
+ {"version":3,"names":["_minimatch","_interopRequireDefault","require","createPatternMatcher","pattern","migration","includes","minimatch","getId","exports"],"sources":["createPatternMatcher.ts"],"sourcesContent":["import minimatch from \"minimatch\";\nimport { IsMigrationApplicable } from \"~/MigrationRunner\";\n\nexport const createPatternMatcher = (pattern: string): IsMigrationApplicable => {\n return migration => {\n if (pattern.includes(\"*\")) {\n return minimatch(migration.getId(), pattern);\n }\n return migration.getId() === pattern;\n };\n};\n"],"mappings":";;;;;;;AAAA,IAAAA,UAAA,GAAAC,sBAAA,CAAAC,OAAA;AAGO,MAAMC,oBAAoB,GAAIC,OAAe,IAA4B;EAC5E,OAAOC,SAAS,IAAI;IAChB,IAAID,OAAO,CAACE,QAAQ,CAAC,GAAG,CAAC,EAAE;MACvB,OAAO,IAAAC,kBAAS,EAACF,SAAS,CAACG,KAAK,CAAC,CAAC,EAAEJ,OAAO,CAAC;IAChD;IACA,OAAOC,SAAS,CAACG,KAAK,CAAC,CAAC,KAAKJ,OAAO;EACxC,CAAC;AACL,CAAC;AAACK,OAAA,CAAAN,oBAAA,GAAAA,oBAAA"}
@@ -11,4 +11,6 @@ const devVersionErrorResponse = () => {
11
11
  }
12
12
  };
13
13
  };
14
- exports.devVersionErrorResponse = devVersionErrorResponse;
14
+ exports.devVersionErrorResponse = devVersionErrorResponse;
15
+
16
+ //# sourceMappingURL=devVersionErrorResponse.js.map
@@ -1 +1 @@
1
- {"version":3,"names":["devVersionErrorResponse","error","message","join"],"sources":["devVersionErrorResponse.ts"],"sourcesContent":["export const devVersionErrorResponse = () => {\n return {\n error: {\n message: [\n `This project is using a development version 0.0.0!`,\n `Migrations cannot be executed using version 0.0.0, as that makes them all eligible for execution.`,\n `To trigger a particular set of migrations, set a WEBINY_VERSION variable in the .env file.`\n ].join(\" \")\n }\n };\n};\n"],"mappings":";;;;;;AAAO,MAAMA,uBAAuB,GAAG,MAAM;EACzC,OAAO;IACHC,KAAK,EAAE;MACHC,OAAO,EAAE,CACJ,oDAAmD,EACnD,mGAAkG,EAClG,4FAA2F,CAC/F,CAACC,IAAI,CAAC,GAAG;IACd;EACJ,CAAC;AACL,CAAC;AAAC"}
1
+ {"version":3,"names":["devVersionErrorResponse","error","message","join","exports"],"sources":["devVersionErrorResponse.ts"],"sourcesContent":["export const devVersionErrorResponse = () => {\n return {\n error: {\n message: [\n `This project is using a development version 0.0.0!`,\n `Migrations cannot be executed using version 0.0.0, as that makes them all eligible for execution.`,\n `To trigger a particular set of migrations, set a WEBINY_VERSION variable in the .env file.`\n ].join(\" \")\n }\n };\n};\n"],"mappings":";;;;;;AAAO,MAAMA,uBAAuB,GAAGA,CAAA,KAAM;EACzC,OAAO;IACHC,KAAK,EAAE;MACHC,OAAO,EAAE,CACJ,oDAAmD,EACnD,mGAAkG,EAClG,4FAA2F,CAC/F,CAACC,IAAI,CAAC,GAAG;IACd;EACJ,CAAC;AACL,CAAC;AAACC,OAAA,CAAAJ,uBAAA,GAAAA,uBAAA"}
package/index.js CHANGED
@@ -68,4 +68,6 @@ Object.keys(_createPinoLogger).forEach(function (key) {
68
68
  return _createPinoLogger[key];
69
69
  }
70
70
  });
71
- });
71
+ });
72
+
73
+ //# sourceMappingURL=index.js.map
package/index.js.map CHANGED
@@ -1 +1 @@
1
- {"version":3,"names":[],"sources":["index.ts"],"sourcesContent":["export * from \"./handlers/createDdbProjectMigration\";\nexport * from \"./handlers/createDdbEsProjectMigration\";\nexport * from \"./symbols\";\nexport * from \"./types\";\nexport * from \"./createTable\";\nexport * from \"./createPinoLogger\";\nexport * from \"./createPinoLogger\";\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;AACA;AAAA;EAAA;EAAA;EAAA;IAAA;IAAA;MAAA;IAAA;EAAA;AAAA;AACA;AAAA;EAAA;EAAA;EAAA;IAAA;IAAA;MAAA;IAAA;EAAA;AAAA;AACA;AACA;EAAA;EAAA;EAAA;IAAA;IAAA;MAAA;IAAA;EAAA;AAAA"}
1
+ {"version":3,"names":["_createDdbProjectMigration","require","Object","keys","forEach","key","exports","defineProperty","enumerable","get","_createDdbEsProjectMigration","_symbols","_types","_createTable","_createPinoLogger"],"sources":["index.ts"],"sourcesContent":["export * from \"./handlers/createDdbProjectMigration\";\nexport * from \"./handlers/createDdbEsProjectMigration\";\nexport * from \"./symbols\";\nexport * from \"./types\";\nexport * from \"./createTable\";\nexport * from \"./createPinoLogger\";\nexport * from \"./createPinoLogger\";\n"],"mappings":";;;;;AAAA,IAAAA,0BAAA,GAAAC,OAAA;AAAAC,MAAA,CAAAC,IAAA,CAAAH,0BAAA,EAAAI,OAAA,WAAAC,GAAA;EAAA,IAAAA,GAAA,kBAAAA,GAAA;EAAA,IAAAA,GAAA,IAAAC,OAAA,IAAAA,OAAA,CAAAD,GAAA,MAAAL,0BAAA,CAAAK,GAAA;EAAAH,MAAA,CAAAK,cAAA,CAAAD,OAAA,EAAAD,GAAA;IAAAG,UAAA;IAAAC,GAAA,WAAAA,CAAA;MAA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;EAAA,IAAAA,GAAA,kBAAAA,GAAA;EAAA,IAAAA,GAAA,IAAAC,OAAA,IAAAA,OAAA,CAAAD,GAAA,MAAAQ,YAAA,CAAAR,GAAA;EAAAH,MAAA,CAAAK,cAAA,CAAAD,OAAA,EAAAD,GAAA;IAAAG,UAAA;IAAAC,GAAA,WAAAA,CAAA;MAAA,OAAAI,YAAA,CAAAR,GAAA;IAAA;EAAA;AAAA;AACA,IAAAS,iBAAA,GAAAb,OAAA;AACAC,MAAA,CAAAC,IAAA,CAAAW,iBAAA,EAAAV,OAAA,WAAAC,GAAA;EAAA,IAAAA,GAAA,kBAAAA,GAAA;EAAA,IAAAA,GAAA,IAAAC,OAAA,IAAAA,OAAA,CAAAD,GAAA,MAAAS,iBAAA,CAAAT,GAAA;EAAAH,MAAA,CAAAK,cAAA,CAAAD,OAAA,EAAAD,GAAA;IAAAG,UAAA;IAAAC,GAAA,WAAAA,CAAA;MAAA,OAAAK,iBAAA,CAAAT,GAAA;IAAA;EAAA;AAAA"}
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@webiny/data-migration",
3
- "version": "0.0.0-unstable.99666aeb00",
3
+ "version": "0.0.0-unstable.a9593f74dd",
4
4
  "main": "index.js",
5
5
  "types": "types.ts",
6
6
  "license": "MIT",
@@ -11,29 +11,29 @@
11
11
  "description": "Tools to author and execute data migrations.",
12
12
  "author": "Webiny Ltd.",
13
13
  "dependencies": {
14
- "@babel/runtime": "7.20.13",
14
+ "@babel/runtime": "7.22.6",
15
15
  "@elastic/elasticsearch": "7.12.0",
16
16
  "@types/pino": "7.0.5",
17
- "@webiny/db-dynamodb": "0.0.0-unstable.99666aeb00",
18
- "@webiny/handler-aws": "0.0.0-unstable.99666aeb00",
19
- "@webiny/ioc": "0.0.0-unstable.99666aeb00",
20
- "@webiny/utils": "0.0.0-unstable.99666aeb00",
17
+ "@webiny/aws-sdk": "0.0.0-unstable.a9593f74dd",
18
+ "@webiny/db-dynamodb": "0.0.0-unstable.a9593f74dd",
19
+ "@webiny/handler-aws": "0.0.0-unstable.a9593f74dd",
20
+ "@webiny/ioc": "0.0.0-unstable.a9593f74dd",
21
+ "@webiny/logger": "0.0.0-unstable.a9593f74dd",
22
+ "@webiny/utils": "0.0.0-unstable.a9593f74dd",
21
23
  "center-align": "1.0.1",
22
24
  "chalk": "4.1.2",
23
- "dynamodb-toolbox": "0.3.5",
24
25
  "minimatch": "5.1.6",
25
- "pino": "8.11.0",
26
26
  "pino-pretty": "9.4.0",
27
- "semver": "6.3.0"
27
+ "semver": "7.5.4"
28
28
  },
29
29
  "devDependencies": {
30
- "@babel/cli": "7.20.7",
31
- "@babel/core": "7.20.12",
32
- "@babel/preset-env": "7.20.2",
30
+ "@babel/cli": "7.22.6",
31
+ "@babel/core": "7.22.8",
32
+ "@babel/preset-env": "7.22.7",
33
33
  "@types/center-align": "1.0.0",
34
34
  "@types/semver": "7.3.13",
35
- "@webiny/cli": "0.0.0-unstable.99666aeb00",
36
- "@webiny/project-utils": "0.0.0-unstable.99666aeb00",
35
+ "@webiny/cli": "0.0.0-unstable.a9593f74dd",
36
+ "@webiny/project-utils": "0.0.0-unstable.a9593f74dd",
37
37
  "jest": "29.5.0",
38
38
  "jest-dynalite": "3.6.1",
39
39
  "jest-mock-console": "1.3.0",
@@ -55,5 +55,5 @@
55
55
  ]
56
56
  }
57
57
  },
58
- "gitHead": "99666aeb00056c56292eeb5dbb6aba7fda2439e2"
58
+ "gitHead": "a9593f74ddf9ce93263eadb0ddc0807ed343f5ee"
59
59
  }
@@ -1,5 +1,51 @@
1
- import { Table, Entity } from "dynamodb-toolbox";
1
+ import { Entity, Table } from "@webiny/db-dynamodb/toolbox";
2
2
  export declare const createStandardEntity: ({ table, name }: {
3
- table: Table;
3
+ table: Table<string, string, string>;
4
4
  name: string;
5
- }) => Entity<{}>;
5
+ }) => Entity<string, import("dynamodb-toolbox/dist/cjs/classes/Entity").Overlay, import("dynamodb-toolbox/dist/cjs/classes/Entity").Overlay, Table<string, string, string>, boolean, boolean, boolean, string, string, string, boolean, {
6
+ PK: {
7
+ partitionKey: true;
8
+ };
9
+ SK: {
10
+ sortKey: true;
11
+ };
12
+ GSI1_PK: {
13
+ type: "string";
14
+ };
15
+ GSI1_SK: {
16
+ type: "string";
17
+ };
18
+ TYPE: {
19
+ type: "string";
20
+ };
21
+ data: {
22
+ type: "map";
23
+ };
24
+ }, {
25
+ PK: {
26
+ partitionKey: true;
27
+ };
28
+ SK: {
29
+ sortKey: true;
30
+ };
31
+ GSI1_PK: {
32
+ type: "string";
33
+ };
34
+ GSI1_SK: {
35
+ type: "string";
36
+ };
37
+ TYPE: {
38
+ type: "string";
39
+ };
40
+ data: {
41
+ type: "map";
42
+ };
43
+ }, import("dynamodb-toolbox/dist/cjs/classes/Entity").ParsedAttributes<import("ts-toolbelt/out/Any/Key").Key>, any, {
44
+ [x: string]: any;
45
+ [x: number]: any;
46
+ [x: symbol]: any;
47
+ }, {
48
+ [x: string]: any;
49
+ [x: number]: any;
50
+ [x: symbol]: any;
51
+ }>;
@@ -4,12 +4,12 @@ Object.defineProperty(exports, "__esModule", {
4
4
  value: true
5
5
  });
6
6
  exports.createStandardEntity = void 0;
7
- var _dynamodbToolbox = require("dynamodb-toolbox");
7
+ var _toolbox = require("@webiny/db-dynamodb/toolbox");
8
8
  const createStandardEntity = ({
9
9
  table,
10
10
  name
11
11
  }) => {
12
- return new _dynamodbToolbox.Entity({
12
+ return new _toolbox.Entity({
13
13
  name,
14
14
  table,
15
15
  attributes: {
@@ -34,4 +34,6 @@ const createStandardEntity = ({
34
34
  }
35
35
  });
36
36
  };
37
- exports.createStandardEntity = createStandardEntity;
37
+ exports.createStandardEntity = createStandardEntity;
38
+
39
+ //# sourceMappingURL=createStandardEntity.js.map
@@ -1 +1 @@
1
- {"version":3,"names":["createStandardEntity","table","name","Entity","attributes","PK","partitionKey","SK","sortKey","GSI1_PK","type","GSI1_SK","TYPE","data"],"sources":["createStandardEntity.ts"],"sourcesContent":["import { Table, Entity } from \"dynamodb-toolbox\";\n\nexport const createStandardEntity = ({ table, name }: { table: Table; name: string }) => {\n return new Entity({\n name,\n table,\n attributes: {\n PK: {\n partitionKey: true\n },\n SK: {\n sortKey: true\n },\n GSI1_PK: {\n type: \"string\"\n },\n GSI1_SK: {\n type: \"string\"\n },\n TYPE: {\n type: \"string\"\n },\n data: {\n type: \"map\"\n }\n }\n });\n};\n"],"mappings":";;;;;;AAAA;AAEO,MAAMA,oBAAoB,GAAG,CAAC;EAAEC,KAAK;EAAEC;AAAqC,CAAC,KAAK;EACrF,OAAO,IAAIC,uBAAM,CAAC;IACdD,IAAI;IACJD,KAAK;IACLG,UAAU,EAAE;MACRC,EAAE,EAAE;QACAC,YAAY,EAAE;MAClB,CAAC;MACDC,EAAE,EAAE;QACAC,OAAO,EAAE;MACb,CAAC;MACDC,OAAO,EAAE;QACLC,IAAI,EAAE;MACV,CAAC;MACDC,OAAO,EAAE;QACLD,IAAI,EAAE;MACV,CAAC;MACDE,IAAI,EAAE;QACFF,IAAI,EAAE;MACV,CAAC;MACDG,IAAI,EAAE;QACFH,IAAI,EAAE;MACV;IACJ;EACJ,CAAC,CAAC;AACN,CAAC;AAAC"}
1
+ {"version":3,"names":["_toolbox","require","createStandardEntity","table","name","Entity","attributes","PK","partitionKey","SK","sortKey","GSI1_PK","type","GSI1_SK","TYPE","data","exports"],"sources":["createStandardEntity.ts"],"sourcesContent":["import { Entity, Table } from \"@webiny/db-dynamodb/toolbox\";\n\nexport const createStandardEntity = ({\n table,\n name\n}: {\n table: Table<string, string, string>;\n name: string;\n}) => {\n return new Entity({\n name,\n table,\n attributes: {\n PK: {\n partitionKey: true\n },\n SK: {\n sortKey: true\n },\n GSI1_PK: {\n type: \"string\"\n },\n GSI1_SK: {\n type: \"string\"\n },\n TYPE: {\n type: \"string\"\n },\n data: {\n type: \"map\"\n }\n }\n });\n};\n"],"mappings":";;;;;;AAAA,IAAAA,QAAA,GAAAC,OAAA;AAEO,MAAMC,oBAAoB,GAAGA,CAAC;EACjCC,KAAK;EACLC;AAIJ,CAAC,KAAK;EACF,OAAO,IAAIC,eAAM,CAAC;IACdD,IAAI;IACJD,KAAK;IACLG,UAAU,EAAE;MACRC,EAAE,EAAE;QACAC,YAAY,EAAE;MAClB,CAAC;MACDC,EAAE,EAAE;QACAC,OAAO,EAAE;MACb,CAAC;MACDC,OAAO,EAAE;QACLC,IAAI,EAAE;MACV,CAAC;MACDC,OAAO,EAAE;QACLD,IAAI,EAAE;MACV,CAAC;MACDE,IAAI,EAAE;QACFF,IAAI,EAAE;MACV,CAAC;MACDG,IAAI,EAAE;QACFH,IAAI,EAAE;MACV;IACJ;EACJ,CAAC,CAAC;AACN,CAAC;AAACI,OAAA,CAAAd,oBAAA,GAAAA,oBAAA"}
@@ -1,10 +1,10 @@
1
- import { Table } from "dynamodb-toolbox";
1
+ import { Table } from "@webiny/db-dynamodb/toolbox";
2
2
  import { MigrationItem, MigrationRepository, MigrationRun } from "../types";
3
3
  export declare class MigrationRepositoryImpl implements MigrationRepository {
4
4
  private readonly run;
5
5
  private readonly migration;
6
6
  private readonly checkpoint;
7
- constructor(table: Table);
7
+ constructor(table: Table<string, string, string>);
8
8
  getLastRun(): Promise<MigrationRun | null>;
9
9
  saveRun(run: MigrationRun): Promise<void>;
10
10
  listMigrations(params?: {
@@ -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 this.run.put({
45
- PK: `MIGRATION_RUN#${run.id}`,
46
- SK: "A",
47
- TYPE: "migration.run",
48
- GSI1_PK: "MIGRATION_RUNS",
49
- GSI1_SK: run.id,
50
- data: run
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 this.migration.put({
72
- PK: `MIGRATION#${migration.id}`,
73
- SK: "A",
74
- TYPE: "migration",
75
- GSI1_PK: "MIGRATIONS",
76
- GSI1_SK: migration.id,
77
- data: migration
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 this.checkpoint.put({
82
- PK: `MIGRATION_CHECKPOINT#${id}`,
83
- SK: "A",
84
- TYPE: "migration.checkpoint",
85
- GSI1_PK: "MIGRATION_CHECKPOINTS",
86
- GSI1_SK: id,
87
- data
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
- return this.checkpoint.delete({
92
- PK: `MIGRATION_CHECKPOINT#${id}`,
93
- SK: "A"
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 this.checkpoint.get({
98
- PK: `MIGRATION_CHECKPOINT#${id}`,
99
- SK: "A"
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 || !record.Item) {
112
+ if (!record) {
102
113
  return null;
103
114
  }
104
- return record.Item.data;
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":["MigrationRepositoryImpl","constructor","table","run","createStandardEntity","name","migration","checkpoint","getLastRun","result","queryOne","entity","partitionKey","options","index","gt","reverse","data","saveRun","put","PK","id","SK","TYPE","GSI1_PK","GSI1_SK","listMigrations","params","limit","queryAll","map","item","logMigration","createCheckpoint","deleteCheckpoint","delete","getCheckpoint","record","get","Item","makeInjectable","inject","PrimaryDynamoTableSymbol"],"sources":["migrations.repository.ts"],"sourcesContent":["import { Table, Entity } from \"dynamodb-toolbox\";\nimport { queryAll, queryOne } from \"@webiny/db-dynamodb/utils/query\";\nimport { MigrationItem, MigrationRepository, MigrationRun } from \"~/types\";\nimport { inject, makeInjectable } from \"@webiny/ioc\";\nimport { PrimaryDynamoTableSymbol } from \"~/symbols\";\nimport { createStandardEntity } from \"./createStandardEntity\";\n\nexport class MigrationRepositoryImpl implements MigrationRepository {\n private readonly run: Entity<any>;\n private readonly migration: Entity<any>;\n private readonly checkpoint: Entity<any>;\n\n constructor(table: Table) {\n this.run = createStandardEntity({ table, name: \"MigrationRun\" });\n this.migration = createStandardEntity({ table, name: \"Migration\" });\n this.checkpoint = createStandardEntity({ table, name: \"MigrationCheckpoint\" });\n }\n\n async getLastRun(): Promise<MigrationRun | null> {\n const result = await queryOne<{ data: MigrationRun }>({\n entity: this.run,\n partitionKey: \"MIGRATION_RUNS\",\n options: {\n index: \"GSI1\",\n gt: \" \",\n reverse: true\n }\n });\n\n return result ? result.data : null;\n }\n\n async saveRun(run: MigrationRun): Promise<void> {\n await this.run.put({\n PK: `MIGRATION_RUN#${run.id}`,\n SK: \"A\",\n TYPE: \"migration.run\",\n GSI1_PK: \"MIGRATION_RUNS\",\n GSI1_SK: run.id,\n data: run\n });\n }\n\n async listMigrations(params?: { limit: number }): Promise<MigrationItem[]> {\n const { limit } = params || {};\n const result = await queryAll<{ data: MigrationItem }>({\n entity: this.migration,\n partitionKey: \"MIGRATIONS\",\n options: {\n index: \"GSI1\",\n gt: \" \",\n limit,\n // Sort by GSI1_SK in descending order.\n reverse: true\n }\n });\n\n return result.map(item => item.data);\n }\n\n async logMigration(migration: MigrationItem): Promise<void> {\n await this.migration.put({\n PK: `MIGRATION#${migration.id}`,\n SK: \"A\",\n TYPE: \"migration\",\n GSI1_PK: \"MIGRATIONS\",\n GSI1_SK: migration.id,\n data: migration\n });\n }\n\n async createCheckpoint(id: string, data: unknown): Promise<void> {\n await this.checkpoint.put({\n PK: `MIGRATION_CHECKPOINT#${id}`,\n SK: \"A\",\n TYPE: \"migration.checkpoint\",\n GSI1_PK: \"MIGRATION_CHECKPOINTS\",\n GSI1_SK: id,\n data\n });\n }\n\n deleteCheckpoint(id: string): Promise<void> {\n return this.checkpoint.delete({\n PK: `MIGRATION_CHECKPOINT#${id}`,\n SK: \"A\"\n });\n }\n\n async getCheckpoint(id: string): Promise<unknown | null> {\n const record = await this.checkpoint.get({\n PK: `MIGRATION_CHECKPOINT#${id}`,\n SK: \"A\"\n });\n\n if (!record || !record.Item) {\n return null;\n }\n return record.Item.data;\n }\n}\n\nmakeInjectable(MigrationRepositoryImpl, [inject(PrimaryDynamoTableSymbol)]);\n"],"mappings":";;;;;;;;AACA;AAEA;AACA;AACA;AAEO,MAAMA,uBAAuB,CAAgC;EAKhEC,WAAW,CAACC,KAAY,EAAE;IAAA;IAAA;IAAA;IACtB,IAAI,CAACC,GAAG,GAAG,IAAAC,0CAAoB,EAAC;MAAEF,KAAK;MAAEG,IAAI,EAAE;IAAe,CAAC,CAAC;IAChE,IAAI,CAACC,SAAS,GAAG,IAAAF,0CAAoB,EAAC;MAAEF,KAAK;MAAEG,IAAI,EAAE;IAAY,CAAC,CAAC;IACnE,IAAI,CAACE,UAAU,GAAG,IAAAH,0CAAoB,EAAC;MAAEF,KAAK;MAAEG,IAAI,EAAE;IAAsB,CAAC,CAAC;EAClF;EAEA,MAAMG,UAAU,GAAiC;IAC7C,MAAMC,MAAM,GAAG,MAAM,IAAAC,eAAQ,EAAyB;MAClDC,MAAM,EAAE,IAAI,CAACR,GAAG;MAChBS,YAAY,EAAE,gBAAgB;MAC9BC,OAAO,EAAE;QACLC,KAAK,EAAE,MAAM;QACbC,EAAE,EAAE,GAAG;QACPC,OAAO,EAAE;MACb;IACJ,CAAC,CAAC;IAEF,OAAOP,MAAM,GAAGA,MAAM,CAACQ,IAAI,GAAG,IAAI;EACtC;EAEA,MAAMC,OAAO,CAACf,GAAiB,EA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MAChCC,OAAO,EAAEJ,EAAE;MACXJ;IACJ,CAAC,CAAC;EACN;EAEAiB,gBAAgB,CAACb,EAAU,EAAiB;IACxC,OAAO,IAAI,CAACd,UAAU,CAAC4B,MAAM,CAAC;MAC1Bf,EAAE,EAAG,wBAAuBC,EAAG,EAAC;MAChCC,EAAE,EAAE;IACR,CAAC,CAAC;EACN;EAEA,MAAMc,aAAa,CAACf,EAAU,EAA2B;IACrD,MAAMgB,MAAM,GAAG,MAAM,IAAI,CAAC9B,UAAU,CAAC+B,GAAG,CAAC;MACrClB,EAAE,EAAG,wBAAuBC,EAAG,EAAC;MAChCC,EAAE,EAAE;IACR,CAAC,CAAC;IAEF,IAAI,CAACe,MAAM,IAAI,CAACA,MAAM,CAACE,IAAI,EAAE;MACzB,OAAO,IAAI;IACf;IACA,OAAOF,MAAM,CAACE,IAAI,CAACtB,IAAI;EAC3B;AACJ;AAAC;AAED,IAAAuB,mBAAc,EAACxC,uBAAuB,EAAE,CAAC,IAAAyC,WAAM,EAACC,iCAAwB,CAAC,CAAC,CAAC"}
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 { Entity, Table } from \"@webiny/db-dynamodb/toolbox\";\nimport { queryAll, queryOne } from \"@webiny/db-dynamodb/utils/query\";\nimport { MigrationItem, MigrationRepository, MigrationRun } from \"~/types\";\nimport { inject, makeInjectable } from \"@webiny/ioc\";\nimport { PrimaryDynamoTableSymbol } from \"~/symbols\";\nimport { createStandardEntity } from \"./createStandardEntity\";\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 }\n return record.data;\n }\n}\n\nmakeInjectable(MigrationRepositoryImpl, [inject(PrimaryDynamoTableSymbol)]);\n"],"mappings":";;;;;;AACA,IAAAA,MAAA,GAAAC,OAAA;AAEA,IAAAC,IAAA,GAAAD,OAAA;AACA,IAAAE,QAAA,GAAAF,OAAA;AACA,IAAAG,qBAAA,GAAAH,OAAA;AACA,IAAAI,WAAA,GAAAJ,OAAA;AAMO,MAAMK,uBAAuB,CAAgC;EAKhEC,WAAWA,CAACC,KAAoC,EAAE;IAC9C,IAAI,CAACC,GAAG,GAAG,IAAAC,0CAAoB,EAAC;MAAEF,KAAK;MAAEG,IAAI,EAAE;IAAe,CAAC,CAAC;IAChE,IAAI,CAACC,SAAS,GAAG,IAAAF,0CAAoB,EAAC;MAAEF,KAAK;MAAEG,IAAI,EAAE;IAAY,CAAC,CAAC;IACnE,IAAI,CAACE,UAAU,GAAG,IAAAH,0CAAoB,EAAC;MAAEF,KAAK;MAAEG,IAAI,EAAE;IAAsB,CAAC,CAAC;EAClF;EAEA,MAAMG,UAAUA,CAAA,EAAiC;IAC7C,MAAMC,MAAM,GAAG,MAAM,IAAAC,eAAQ,EAAyB;MAClDC,MAAM,EAAE,IAAI,CAACR,GAAG;MAChBS,YAAY,EAAE,gBAAgB;MAC9BC,OAAO,EAAE;QACLC,KAAK,EAAE,MAAM;QACbC,EAAE,EAAE,GAAG;QACPC,OAAO,EAAE;MACb;IACJ,CAAC,CAAC;IAEF,OAAOP,MAAM,GAAGA,MAAM,CAACQ,IAAI,GAAG,IAAI;EACtC;EAE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