@oliasoft-open-source/node-json-migrator 4.3.0-beta-1 → 4.3.0-beta-2

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
package/dist/index.cjs CHANGED
@@ -7683,19 +7683,17 @@ const getPlannedMigrations = async ({ config }) => {
7683
7683
  };
7684
7684
  const PlanModule = { getPlannedMigrations };
7685
7685
 
7686
- const templateMigrationFileLegacyRuleset = (entity) => `import produce from 'immer';
7686
+ const templateMigrationFileWithMetaDataLegacy = (entity) => `import produce from 'immer';
7687
7687
  //other imports not allowed
7688
7688
 
7689
7689
  export default (${entity}, metaData = {}) => produce(${entity}, (draft) => {
7690
- void metaData;
7691
7690
  // https://immerjs.github.io/immer/produce#example
7692
7691
  });
7693
7692
  `;
7694
- const templateMigrationFileRuleset = (entity) => `import { produce } from 'immer';
7693
+ const templateMigrationFileWithMetaData = (entity) => `import { produce } from 'immer';
7695
7694
  //other imports not allowed
7696
7695
 
7697
7696
  export default (${entity}, metaData = {}) => produce(${entity}, (draft) => {
7698
- void metaData;
7699
7697
  // https://immerjs.github.io/immer/produce#example
7700
7698
  });
7701
7699
  `;
@@ -7713,19 +7711,19 @@ export default (${entity}) => produce(${entity}, (draft) => {
7713
7711
  // https://immerjs.github.io/immer/produce#example
7714
7712
  });
7715
7713
  `;
7716
- const getTemplateMigrationFile = async (entity, type) => {
7717
- let template = type === "ruleset" ? templateMigrationFileLegacyRuleset(entity) : templateMigrationFileLegacy(entity);
7714
+ const getTemplateMigrationFile = async (entity, enableMetaData) => {
7715
+ let template = enableMetaData ? templateMigrationFileWithMetaDataLegacy(entity) : templateMigrationFileLegacy(entity);
7718
7716
  try {
7719
7717
  await Promise.resolve().then(function () { return require('./immer-BsT8CIGL.cjs'); }).then(({ produce }) => {
7720
7718
  if (produce) {
7721
- template = type === "ruleset" ? templateMigrationFileRuleset(entity) : templateMigrationFile(entity);
7719
+ template = enableMetaData ? templateMigrationFileWithMetaData(entity) : templateMigrationFile(entity);
7722
7720
  }
7723
7721
  });
7724
7722
  } catch (_error) {
7725
7723
  }
7726
7724
  return template;
7727
7725
  };
7728
- const templateTestFile = (fileName, entity, type) => `import test from 'node:test';
7726
+ const templateTestFile = (fileName, entity, enableMetaData) => `import test from 'node:test';
7729
7727
  import assert from 'node:assert/strict';
7730
7728
  import migrate from './${fileName}';
7731
7729
 
@@ -7735,13 +7733,13 @@ test('describe ${entity} change', async (t) => {
7735
7733
  const ${entity} = {};
7736
7734
 
7737
7735
  // act
7738
- const next${capitalize(entity)} = ${type === "ruleset" ? `migrate(${entity}, /* metaData */ {})` : `migrate(${entity})`};
7736
+ const next${capitalize(entity)} = ${enableMetaData ? `migrate(${entity}, /* metaData */ {})` : `migrate(${entity})`};
7739
7737
 
7740
7738
  // assert
7741
7739
  });
7742
7740
  });
7743
7741
  `;
7744
- const createMigration = async (directory, description, entity, type = "dataset") => {
7742
+ const createMigration = async (directory, description, entity, enableMetaData) => {
7745
7743
  if (!validateFileDescription(description)) {
7746
7744
  throw new Error("Invalid migration description");
7747
7745
  }
@@ -7754,14 +7752,14 @@ const createMigration = async (directory, description, entity, type = "dataset")
7754
7752
  await fs.promises.mkdir(directoryFullPath, { recursive: true });
7755
7753
  const templateMigrationScript = await getTemplateMigrationFile(
7756
7754
  entity,
7757
- type
7755
+ enableMetaData
7758
7756
  );
7759
7757
  await fs.promises.writeFile(filePath, templateMigrationScript, {
7760
7758
  encoding: "utf8"
7761
7759
  });
7762
7760
  await fs.promises.writeFile(
7763
7761
  testFilePath,
7764
- templateTestFile(fileName, entity, type),
7762
+ templateTestFile(fileName, entity, enableMetaData),
7765
7763
  {
7766
7764
  encoding: "utf8"
7767
7765
  }
package/dist/index.d.cts CHANGED
@@ -1,5 +1,10 @@
1
1
  import { IDatabase, IHelpers, ITask } from 'pg-promise';
2
2
 
3
+ /**
4
+ * Generate a new entity migration
5
+ */
6
+ declare const createMigration: (directory: string, description: string, entity: string, enableMetaData?: boolean) => Promise<void>;
7
+
3
8
  type TPlanEntry = {
4
9
  fileName: string;
5
10
  fileHash: string;
@@ -20,7 +25,6 @@ type TMigration = {
20
25
  script?: string;
21
26
  migrator?: (payload: TPayload, metaData?: TMetaData) => TPayload;
22
27
  };
23
- type TMigrationType = 'dataset' | 'ruleset';
24
28
  type TRecordDetails = {
25
29
  id: number | string;
26
30
  name: string;
@@ -90,11 +94,6 @@ type TOnMigrationErrorsPayload = {
90
94
  };
91
95
  type TOnMigrationErrors = (params: TOnMigrationErrorsPayload) => Promise<void>;
92
96
 
93
- /**
94
- * Generate a new entity migration
95
- */
96
- declare const createMigration: (directory: string, description: string, entity: string, type?: TMigrationType) => Promise<void>;
97
-
98
97
  declare const getPlannedMigrations: ({ config }: {
99
98
  config: TConfig;
100
99
  }) => Promise<{
@@ -159,4 +158,4 @@ declare const printVersionHistory: ({ config }: {
159
158
  config: TConfig;
160
159
  }) => Promise<void>;
161
160
 
162
- export { type TAfterMigrateRecord, type TAfterMigrateRecordPayload, type TBeforeMigrateRecord, type TBeforeMigrateRecordPayload, type TConfig, type TEntityColumnNames, type TMetaData, type TMigration, type TMigrationErrorPayload, type TMigrationType, type TOnMigrationErrors, type TOnMigrationErrorsPayload, type TPayload, type TPlan, type TPlanEntry, type TRecord, type TRecordDetails, type TRecordDetailsList, createMigration, getPlannedMigrations, getPlannedVersion, getVersions, migrate, migrateAll, pipe, printVersionHistory };
161
+ export { type TAfterMigrateRecord, type TAfterMigrateRecordPayload, type TBeforeMigrateRecord, type TBeforeMigrateRecordPayload, type TConfig, type TEntityColumnNames, type TMetaData, type TMigration, type TMigrationErrorPayload, type TOnMigrationErrors, type TOnMigrationErrorsPayload, type TPayload, type TPlan, type TPlanEntry, type TRecord, type TRecordDetails, type TRecordDetailsList, createMigration, getPlannedMigrations, getPlannedVersion, getVersions, migrate, migrateAll, pipe, printVersionHistory };
package/dist/index.d.mts CHANGED
@@ -1,5 +1,10 @@
1
1
  import { IDatabase, IHelpers, ITask } from 'pg-promise';
2
2
 
3
+ /**
4
+ * Generate a new entity migration
5
+ */
6
+ declare const createMigration: (directory: string, description: string, entity: string, enableMetaData?: boolean) => Promise<void>;
7
+
3
8
  type TPlanEntry = {
4
9
  fileName: string;
5
10
  fileHash: string;
@@ -20,7 +25,6 @@ type TMigration = {
20
25
  script?: string;
21
26
  migrator?: (payload: TPayload, metaData?: TMetaData) => TPayload;
22
27
  };
23
- type TMigrationType = 'dataset' | 'ruleset';
24
28
  type TRecordDetails = {
25
29
  id: number | string;
26
30
  name: string;
@@ -90,11 +94,6 @@ type TOnMigrationErrorsPayload = {
90
94
  };
91
95
  type TOnMigrationErrors = (params: TOnMigrationErrorsPayload) => Promise<void>;
92
96
 
93
- /**
94
- * Generate a new entity migration
95
- */
96
- declare const createMigration: (directory: string, description: string, entity: string, type?: TMigrationType) => Promise<void>;
97
-
98
97
  declare const getPlannedMigrations: ({ config }: {
99
98
  config: TConfig;
100
99
  }) => Promise<{
@@ -159,4 +158,4 @@ declare const printVersionHistory: ({ config }: {
159
158
  config: TConfig;
160
159
  }) => Promise<void>;
161
160
 
162
- export { type TAfterMigrateRecord, type TAfterMigrateRecordPayload, type TBeforeMigrateRecord, type TBeforeMigrateRecordPayload, type TConfig, type TEntityColumnNames, type TMetaData, type TMigration, type TMigrationErrorPayload, type TMigrationType, type TOnMigrationErrors, type TOnMigrationErrorsPayload, type TPayload, type TPlan, type TPlanEntry, type TRecord, type TRecordDetails, type TRecordDetailsList, createMigration, getPlannedMigrations, getPlannedVersion, getVersions, migrate, migrateAll, pipe, printVersionHistory };
161
+ export { type TAfterMigrateRecord, type TAfterMigrateRecordPayload, type TBeforeMigrateRecord, type TBeforeMigrateRecordPayload, type TConfig, type TEntityColumnNames, type TMetaData, type TMigration, type TMigrationErrorPayload, type TOnMigrationErrors, type TOnMigrationErrorsPayload, type TPayload, type TPlan, type TPlanEntry, type TRecord, type TRecordDetails, type TRecordDetailsList, createMigration, getPlannedMigrations, getPlannedVersion, getVersions, migrate, migrateAll, pipe, printVersionHistory };
package/dist/index.mjs CHANGED
@@ -7662,19 +7662,17 @@ const getPlannedMigrations = async ({ config }) => {
7662
7662
  };
7663
7663
  const PlanModule = { getPlannedMigrations };
7664
7664
 
7665
- const templateMigrationFileLegacyRuleset = (entity) => `import produce from 'immer';
7665
+ const templateMigrationFileWithMetaDataLegacy = (entity) => `import produce from 'immer';
7666
7666
  //other imports not allowed
7667
7667
 
7668
7668
  export default (${entity}, metaData = {}) => produce(${entity}, (draft) => {
7669
- void metaData;
7670
7669
  // https://immerjs.github.io/immer/produce#example
7671
7670
  });
7672
7671
  `;
7673
- const templateMigrationFileRuleset = (entity) => `import { produce } from 'immer';
7672
+ const templateMigrationFileWithMetaData = (entity) => `import { produce } from 'immer';
7674
7673
  //other imports not allowed
7675
7674
 
7676
7675
  export default (${entity}, metaData = {}) => produce(${entity}, (draft) => {
7677
- void metaData;
7678
7676
  // https://immerjs.github.io/immer/produce#example
7679
7677
  });
7680
7678
  `;
@@ -7692,19 +7690,19 @@ export default (${entity}) => produce(${entity}, (draft) => {
7692
7690
  // https://immerjs.github.io/immer/produce#example
7693
7691
  });
7694
7692
  `;
7695
- const getTemplateMigrationFile = async (entity, type) => {
7696
- let template = type === "ruleset" ? templateMigrationFileLegacyRuleset(entity) : templateMigrationFileLegacy(entity);
7693
+ const getTemplateMigrationFile = async (entity, enableMetaData) => {
7694
+ let template = enableMetaData ? templateMigrationFileWithMetaDataLegacy(entity) : templateMigrationFileLegacy(entity);
7697
7695
  try {
7698
7696
  await import('./immer-C8oEWD0M.mjs').then(({ produce }) => {
7699
7697
  if (produce) {
7700
- template = type === "ruleset" ? templateMigrationFileRuleset(entity) : templateMigrationFile(entity);
7698
+ template = enableMetaData ? templateMigrationFileWithMetaData(entity) : templateMigrationFile(entity);
7701
7699
  }
7702
7700
  });
7703
7701
  } catch (_error) {
7704
7702
  }
7705
7703
  return template;
7706
7704
  };
7707
- const templateTestFile = (fileName, entity, type) => `import test from 'node:test';
7705
+ const templateTestFile = (fileName, entity, enableMetaData) => `import test from 'node:test';
7708
7706
  import assert from 'node:assert/strict';
7709
7707
  import migrate from './${fileName}';
7710
7708
 
@@ -7714,13 +7712,13 @@ test('describe ${entity} change', async (t) => {
7714
7712
  const ${entity} = {};
7715
7713
 
7716
7714
  // act
7717
- const next${capitalize(entity)} = ${type === "ruleset" ? `migrate(${entity}, /* metaData */ {})` : `migrate(${entity})`};
7715
+ const next${capitalize(entity)} = ${enableMetaData ? `migrate(${entity}, /* metaData */ {})` : `migrate(${entity})`};
7718
7716
 
7719
7717
  // assert
7720
7718
  });
7721
7719
  });
7722
7720
  `;
7723
- const createMigration = async (directory, description, entity, type = "dataset") => {
7721
+ const createMigration = async (directory, description, entity, enableMetaData) => {
7724
7722
  if (!validateFileDescription(description)) {
7725
7723
  throw new Error("Invalid migration description");
7726
7724
  }
@@ -7733,14 +7731,14 @@ const createMigration = async (directory, description, entity, type = "dataset")
7733
7731
  await promises.mkdir(directoryFullPath, { recursive: true });
7734
7732
  const templateMigrationScript = await getTemplateMigrationFile(
7735
7733
  entity,
7736
- type
7734
+ enableMetaData
7737
7735
  );
7738
7736
  await promises.writeFile(filePath, templateMigrationScript, {
7739
7737
  encoding: "utf8"
7740
7738
  });
7741
7739
  await promises.writeFile(
7742
7740
  testFilePath,
7743
- templateTestFile(fileName, entity, type),
7741
+ templateTestFile(fileName, entity, enableMetaData),
7744
7742
  {
7745
7743
  encoding: "utf8"
7746
7744
  }
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@oliasoft-open-source/node-json-migrator",
3
- "version": "4.3.0-beta-1",
3
+ "version": "4.3.0-beta-2",
4
4
  "description": "A library for JSON migrations",
5
5
  "homepage": "https://oliasoft-open-source.gitlab.io/node-postgresql-migrator",
6
6
  "bugs": {