@oliasoft-open-source/node-json-migrator 5.2.3 → 5.4.0-beta-1

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/dist/index.d.mts CHANGED
@@ -100,6 +100,7 @@ declare const getPlannedMigrations: ({
100
100
  }[];
101
101
  nextVersion: string;
102
102
  }>;
103
+ type TPreparedPlan = Awaited<ReturnType<typeof getPlannedMigrations>>;
103
104
  //#endregion
104
105
  //#region src/plan/planned-version.d.ts
105
106
  declare const getPlannedVersion: ({
@@ -114,16 +115,18 @@ declare const getPlannedVersion: ({
114
115
  *
115
116
  * There are two ways to use this function:
116
117
  * i) function looks up the pending migrations for you (default)
117
- * ii) pass in pre-fetched pending migrators via config.pending
118
+ * ii) reuse a prepared plan while resolving pending migrations for the current payload version
118
119
  */
119
120
  declare const migrate: ({
120
121
  payload,
121
122
  config,
122
- metaData
123
+ metaData,
124
+ preparedPlan
123
125
  }: {
124
126
  payload: TPayload;
125
127
  config: TConfig;
126
128
  metaData?: TMetaData;
129
+ preparedPlan?: TPreparedPlan;
127
130
  }) => Promise<{
128
131
  nextPayload: TPayload;
129
132
  nextVersion: string;
package/dist/index.mjs CHANGED
@@ -4749,9 +4749,9 @@ const getPendingMigrations = ({ plannedMigrations, executedMigrations, printPend
4749
4749
  migrator: m.migrator
4750
4750
  }));
4751
4751
  };
4752
- const getPendingMigrators = async ({ config }) => {
4752
+ const getPendingMigrators = async ({ config, preparedPlan }) => {
4753
4753
  const { directory, database, pgpHelpers, entity, version, printPendingFileNames, force } = config;
4754
- const { plannedMigrations, nextVersion } = await PlanModule.getPlannedMigrations({ config });
4754
+ const { plannedMigrations, nextVersion } = preparedPlan ?? await PlanModule.getPlannedMigrations({ config });
4755
4755
  const executedMigrations = database ? await getExecutedMigrationsFromVersion(database, pgpHelpers, entity, directory, version, nextVersion, plannedMigrations) : [];
4756
4756
  return {
4757
4757
  pendingMigrators: getPendingMigrations({
@@ -4770,10 +4770,13 @@ const getPendingMigrators = async ({ config }) => {
4770
4770
  *
4771
4771
  * There are two ways to use this function:
4772
4772
  * i) function looks up the pending migrations for you (default)
4773
- * ii) pass in pre-fetched pending migrators via config.pending
4773
+ * ii) reuse a prepared plan while resolving pending migrations for the current payload version
4774
4774
  */
4775
- const migrate = async ({ payload, config, metaData }) => {
4776
- const { pendingMigrators, nextVersion } = await getPendingMigrators({ config });
4775
+ const migrate = async ({ payload, config, metaData, preparedPlan }) => {
4776
+ const { pendingMigrators, nextVersion } = await getPendingMigrators({
4777
+ config,
4778
+ preparedPlan
4779
+ });
4777
4780
  return {
4778
4781
  nextPayload: pendingMigrators.length ? PipeModule.pipe(pendingMigrators, payload, metaData) : payload,
4779
4782
  nextVersion
@@ -4785,7 +4788,7 @@ const MAX_ATTEMPTS = 3;
4785
4788
  /**
4786
4789
  * Migrate an entity record in the database
4787
4790
  */
4788
- const migrateRecord = async ({ record, config, beforeMigrateRecord, afterMigrateRecord }) => {
4791
+ const migrateRecord = async ({ record, config, preparedPlan, beforeMigrateRecord, afterMigrateRecord }) => {
4789
4792
  const { dry } = config;
4790
4793
  console.log(chalk.gray(` ${record.name}`));
4791
4794
  try {
@@ -4799,6 +4802,7 @@ const migrateRecord = async ({ record, config, beforeMigrateRecord, afterMigrate
4799
4802
  });
4800
4803
  const { nextPayload: nextData, nextVersion } = await migrate({
4801
4804
  payload,
4805
+ preparedPlan,
4802
4806
  config: {
4803
4807
  ...config,
4804
4808
  version: currentVersion,
@@ -4830,7 +4834,7 @@ const migrateRecord = async ({ record, config, beforeMigrateRecord, afterMigrate
4830
4834
  return migrationErrorPayload;
4831
4835
  }
4832
4836
  };
4833
- const migrateRecords = async ({ recordList, config, beforeMigrateRecord, afterMigrateRecord, onMigrationErrors }) => {
4837
+ const migrateRecords = async ({ recordList, config, preparedPlan, beforeMigrateRecord, afterMigrateRecord, onMigrationErrors }) => {
4834
4838
  const { dry } = config;
4835
4839
  const migrationErrors = [];
4836
4840
  if (recordList.length) {
@@ -4843,6 +4847,7 @@ const migrateRecords = async ({ recordList, config, beforeMigrateRecord, afterMi
4843
4847
  const migrationErrorPayload = await migrateRecord({
4844
4848
  record,
4845
4849
  config,
4850
+ preparedPlan,
4846
4851
  beforeMigrateRecord,
4847
4852
  afterMigrateRecord
4848
4853
  });
@@ -4867,9 +4872,11 @@ const migrateRecords = async ({ recordList, config, beforeMigrateRecord, afterMi
4867
4872
  * Migrate all records (only use via command line interface)
4868
4873
  */
4869
4874
  const migrateAll = async ({ config, beforeMigrateRecord, afterMigrateRecord, onMigrationErrors }) => {
4870
- const { validatedPlan: latestPlan, nextVersion: latestVersion } = await getPlannedMigrations({ config });
4875
+ const preparedPlan = await getPlannedMigrations({ config });
4876
+ const { validatedPlan: latestPlan, nextVersion: latestVersion } = preparedPlan;
4871
4877
  await migrateRecords({
4872
4878
  config,
4879
+ preparedPlan,
4873
4880
  recordList: await getRecordList(config?.database, config?.entity, config?.entityTableName, config?.entityColumnNames, latestVersion, latestPlan),
4874
4881
  beforeMigrateRecord,
4875
4882
  afterMigrateRecord,
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@oliasoft-open-source/node-json-migrator",
3
- "version": "5.2.3",
3
+ "version": "5.4.0-beta-1",
4
4
  "description": "A library for JSON migrations",
5
5
  "homepage": "https://oliasoft-open-source.gitlab.io/node-json-migrator",
6
6
  "bugs": {
@@ -41,8 +41,8 @@
41
41
  "husky": "^9.1.7",
42
42
  "lint-staged": "^16.4.0",
43
43
  "mock-fs": "^5.5.0",
44
- "oxfmt": "^0.61.0",
45
- "oxlint": "^1.56.0",
44
+ "oxfmt": "^0.64.0",
45
+ "oxlint": "^1.79.0",
46
46
  "pg-mem": "^3.0.14",
47
47
  "strip-ansi": "^7.2.0",
48
48
  "tsdown": "^0.21.4",
@@ -54,8 +54,8 @@
54
54
  },
55
55
  "lint-staged": {
56
56
  "*": [
57
- "oxlint --fix",
58
- "oxfmt"
57
+ "oxlint --fix --no-error-on-unmatched-pattern",
58
+ "oxfmt --no-error-on-unmatched-pattern"
59
59
  ]
60
60
  },
61
61
  "devEngines": {