@oliasoft-open-source/node-json-migrator 3.1.0-beta-2 → 3.1.0-beta-4

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.cjs CHANGED
@@ -9027,7 +9027,7 @@ const getVersions = async (db, entity) => {
9027
9027
  };
9028
9028
  return db.any(query, params);
9029
9029
  };
9030
- const getRecordList = async (db, entity, entityColumnNames, latestVersion, latestVersionPlanLength) => {
9030
+ const getRecordList = async (db, entity, entityTableName, entityColumnNames, latestVersion, latestVersionPlanLength) => {
9031
9031
  const query = `
9032
9032
  SELECT
9033
9033
  $(entityIdColumn:name) AS id,
@@ -9053,7 +9053,7 @@ const getRecordList = async (db, entity, entityColumnNames, latestVersion, lates
9053
9053
  )
9054
9054
  `;
9055
9055
  const params = {
9056
- entityTable: entity,
9056
+ entityTable: entityTableName,
9057
9057
  entityVersionsTable: `${entity}_versions`,
9058
9058
  entityIdColumn: entityColumnNames.id,
9059
9059
  entityCreatedColumn: entityColumnNames.created,
@@ -9062,20 +9062,20 @@ const getRecordList = async (db, entity, entityColumnNames, latestVersion, lates
9062
9062
  };
9063
9063
  return db.any(query, params);
9064
9064
  };
9065
- const getRecord = async (t, entity, entityColumnNames, entityId) => {
9065
+ const getRecord = async (t, entityTableName, entityColumnNames, entityId) => {
9066
9066
  const query = `
9067
9067
  SELECT *
9068
9068
  FROM $(entityTable:name)
9069
9069
  WHERE $(entityIdColumn:name) = $(entityId)
9070
9070
  `;
9071
9071
  const params = {
9072
- entityTable: entity,
9072
+ entityTable: entityTableName,
9073
9073
  entityId,
9074
9074
  entityIdColumn: entityColumnNames.id
9075
9075
  };
9076
9076
  return t.one(query, params);
9077
9077
  };
9078
- const updateRecord = async (t, entity, entityColumnNames, entityId, currentVersion, nextData, nextVersion, etag) => {
9078
+ const updateRecord = async (t, entityTableName, entityColumnNames, entityId, currentVersion, nextData, nextVersion, etag) => {
9079
9079
  const useEtag = typeof etag === "number";
9080
9080
  const query = `
9081
9081
  UPDATE $(entityTable:name)
@@ -9088,7 +9088,7 @@ const updateRecord = async (t, entity, entityColumnNames, entityId, currentVersi
9088
9088
  RETURNING *
9089
9089
  `;
9090
9090
  const params = {
9091
- entityTable: entity,
9091
+ entityTable: entityTableName,
9092
9092
  entityId,
9093
9093
  entityIdColumn: entityColumnNames.id,
9094
9094
  currentVersion,
@@ -9672,13 +9672,14 @@ const migrateRecord = async ({
9672
9672
  await config.database.tx(async (transaction) => {
9673
9673
  const currentRecord = await getRecord(
9674
9674
  transaction,
9675
- config.entity,
9675
+ config.entityTableName,
9676
9676
  config.entityColumnNames,
9677
9677
  record.id
9678
9678
  );
9679
9679
  const { data, etag, version: currentVersion } = currentRecord;
9680
9680
  await beforeMigrateRecord({
9681
9681
  currentRecord,
9682
+ transaction,
9682
9683
  dry
9683
9684
  });
9684
9685
  const { nextPayload: nextData, nextVersion } = await migrate({
@@ -9692,8 +9693,8 @@ const migrateRecord = async ({
9692
9693
  if (!dry) {
9693
9694
  const nextRecord = await updateRecord(
9694
9695
  transaction,
9695
- config?.entity,
9696
- config.entityColumnNames,
9696
+ config?.entityTableName,
9697
+ config?.entityColumnNames,
9697
9698
  record.id,
9698
9699
  currentVersion,
9699
9700
  nextData,
@@ -9786,6 +9787,7 @@ const migrateAll = async ({
9786
9787
  const recordList = await getRecordList(
9787
9788
  config?.database,
9788
9789
  config?.entity,
9790
+ config?.entityTableName,
9789
9791
  config?.entityColumnNames,
9790
9792
  latestVersion,
9791
9793
  latestVersionPlanLength
package/dist/index.d.cts CHANGED
@@ -34,8 +34,8 @@ type TConfig = {
34
34
  database?: IDatabase<unknown>;
35
35
  pgpHelpers?: IHelpers;
36
36
  entity?: string;
37
- entityColumnNames: TEntityColumnNames;
38
- entityIdColumnName?: string;
37
+ entityTableName?: string;
38
+ entityColumnNames?: TEntityColumnNames;
39
39
  version?: string;
40
40
  printPendingFileNames?: boolean;
41
41
  force?: boolean;
@@ -45,6 +45,7 @@ type TConfig = {
45
45
  };
46
46
  type TBeforeMigrateRecordPayload = {
47
47
  currentRecord: TRecord;
48
+ transaction?: ITask<unknown>;
48
49
  dry: boolean;
49
50
  };
50
51
  type TBeforeMigrateRecord = (params: TBeforeMigrateRecordPayload) => Promise<void>;
package/dist/index.d.mts CHANGED
@@ -34,8 +34,8 @@ type TConfig = {
34
34
  database?: IDatabase<unknown>;
35
35
  pgpHelpers?: IHelpers;
36
36
  entity?: string;
37
- entityColumnNames: TEntityColumnNames;
38
- entityIdColumnName?: string;
37
+ entityTableName?: string;
38
+ entityColumnNames?: TEntityColumnNames;
39
39
  version?: string;
40
40
  printPendingFileNames?: boolean;
41
41
  force?: boolean;
@@ -45,6 +45,7 @@ type TConfig = {
45
45
  };
46
46
  type TBeforeMigrateRecordPayload = {
47
47
  currentRecord: TRecord;
48
+ transaction?: ITask<unknown>;
48
49
  dry: boolean;
49
50
  };
50
51
  type TBeforeMigrateRecord = (params: TBeforeMigrateRecordPayload) => Promise<void>;
package/dist/index.mjs CHANGED
@@ -9006,7 +9006,7 @@ const getVersions = async (db, entity) => {
9006
9006
  };
9007
9007
  return db.any(query, params);
9008
9008
  };
9009
- const getRecordList = async (db, entity, entityColumnNames, latestVersion, latestVersionPlanLength) => {
9009
+ const getRecordList = async (db, entity, entityTableName, entityColumnNames, latestVersion, latestVersionPlanLength) => {
9010
9010
  const query = `
9011
9011
  SELECT
9012
9012
  $(entityIdColumn:name) AS id,
@@ -9032,7 +9032,7 @@ const getRecordList = async (db, entity, entityColumnNames, latestVersion, lates
9032
9032
  )
9033
9033
  `;
9034
9034
  const params = {
9035
- entityTable: entity,
9035
+ entityTable: entityTableName,
9036
9036
  entityVersionsTable: `${entity}_versions`,
9037
9037
  entityIdColumn: entityColumnNames.id,
9038
9038
  entityCreatedColumn: entityColumnNames.created,
@@ -9041,20 +9041,20 @@ const getRecordList = async (db, entity, entityColumnNames, latestVersion, lates
9041
9041
  };
9042
9042
  return db.any(query, params);
9043
9043
  };
9044
- const getRecord = async (t, entity, entityColumnNames, entityId) => {
9044
+ const getRecord = async (t, entityTableName, entityColumnNames, entityId) => {
9045
9045
  const query = `
9046
9046
  SELECT *
9047
9047
  FROM $(entityTable:name)
9048
9048
  WHERE $(entityIdColumn:name) = $(entityId)
9049
9049
  `;
9050
9050
  const params = {
9051
- entityTable: entity,
9051
+ entityTable: entityTableName,
9052
9052
  entityId,
9053
9053
  entityIdColumn: entityColumnNames.id
9054
9054
  };
9055
9055
  return t.one(query, params);
9056
9056
  };
9057
- const updateRecord = async (t, entity, entityColumnNames, entityId, currentVersion, nextData, nextVersion, etag) => {
9057
+ const updateRecord = async (t, entityTableName, entityColumnNames, entityId, currentVersion, nextData, nextVersion, etag) => {
9058
9058
  const useEtag = typeof etag === "number";
9059
9059
  const query = `
9060
9060
  UPDATE $(entityTable:name)
@@ -9067,7 +9067,7 @@ const updateRecord = async (t, entity, entityColumnNames, entityId, currentVersi
9067
9067
  RETURNING *
9068
9068
  `;
9069
9069
  const params = {
9070
- entityTable: entity,
9070
+ entityTable: entityTableName,
9071
9071
  entityId,
9072
9072
  entityIdColumn: entityColumnNames.id,
9073
9073
  currentVersion,
@@ -9651,13 +9651,14 @@ const migrateRecord = async ({
9651
9651
  await config.database.tx(async (transaction) => {
9652
9652
  const currentRecord = await getRecord(
9653
9653
  transaction,
9654
- config.entity,
9654
+ config.entityTableName,
9655
9655
  config.entityColumnNames,
9656
9656
  record.id
9657
9657
  );
9658
9658
  const { data, etag, version: currentVersion } = currentRecord;
9659
9659
  await beforeMigrateRecord({
9660
9660
  currentRecord,
9661
+ transaction,
9661
9662
  dry
9662
9663
  });
9663
9664
  const { nextPayload: nextData, nextVersion } = await migrate({
@@ -9671,8 +9672,8 @@ const migrateRecord = async ({
9671
9672
  if (!dry) {
9672
9673
  const nextRecord = await updateRecord(
9673
9674
  transaction,
9674
- config?.entity,
9675
- config.entityColumnNames,
9675
+ config?.entityTableName,
9676
+ config?.entityColumnNames,
9676
9677
  record.id,
9677
9678
  currentVersion,
9678
9679
  nextData,
@@ -9765,6 +9766,7 @@ const migrateAll = async ({
9765
9766
  const recordList = await getRecordList(
9766
9767
  config?.database,
9767
9768
  config?.entity,
9769
+ config?.entityTableName,
9768
9770
  config?.entityColumnNames,
9769
9771
  latestVersion,
9770
9772
  latestVersionPlanLength
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@oliasoft-open-source/node-json-migrator",
3
- "version": "3.1.0-beta-2",
3
+ "version": "3.1.0-beta-4",
4
4
  "description": "A library for JSON migrations",
5
5
  "homepage": "https://oliasoft-open-source.gitlab.io/node-postgresql-migrator",
6
6
  "bugs": {