@oliasoft-open-source/node-json-migrator 4.2.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 +38 -15
- package/dist/index.d.cts +1 -1
- package/dist/index.d.mts +1 -1
- package/dist/index.mjs +38 -15
- package/package.json +1 -1
package/dist/index.cjs
CHANGED
|
@@ -7683,6 +7683,20 @@ const getPlannedMigrations = async ({ config }) => {
|
|
|
7683
7683
|
};
|
|
7684
7684
|
const PlanModule = { getPlannedMigrations };
|
|
7685
7685
|
|
|
7686
|
+
const templateMigrationFileWithMetaDataLegacy = (entity) => `import produce from 'immer';
|
|
7687
|
+
//other imports not allowed
|
|
7688
|
+
|
|
7689
|
+
export default (${entity}, metaData = {}) => produce(${entity}, (draft) => {
|
|
7690
|
+
// https://immerjs.github.io/immer/produce#example
|
|
7691
|
+
});
|
|
7692
|
+
`;
|
|
7693
|
+
const templateMigrationFileWithMetaData = (entity) => `import { produce } from 'immer';
|
|
7694
|
+
//other imports not allowed
|
|
7695
|
+
|
|
7696
|
+
export default (${entity}, metaData = {}) => produce(${entity}, (draft) => {
|
|
7697
|
+
// https://immerjs.github.io/immer/produce#example
|
|
7698
|
+
});
|
|
7699
|
+
`;
|
|
7686
7700
|
const templateMigrationFileLegacy = (entity) => `import produce from 'immer';
|
|
7687
7701
|
//other imports not allowed
|
|
7688
7702
|
|
|
@@ -7697,33 +7711,35 @@ export default (${entity}) => produce(${entity}, (draft) => {
|
|
|
7697
7711
|
// https://immerjs.github.io/immer/produce#example
|
|
7698
7712
|
});
|
|
7699
7713
|
`;
|
|
7700
|
-
const getTemplateMigrationFile = async (entity) => {
|
|
7701
|
-
let template = templateMigrationFileLegacy(entity);
|
|
7714
|
+
const getTemplateMigrationFile = async (entity, enableMetaData) => {
|
|
7715
|
+
let template = enableMetaData ? templateMigrationFileWithMetaDataLegacy(entity) : templateMigrationFileLegacy(entity);
|
|
7702
7716
|
try {
|
|
7703
7717
|
await Promise.resolve().then(function () { return require('./immer-BsT8CIGL.cjs'); }).then(({ produce }) => {
|
|
7704
7718
|
if (produce) {
|
|
7705
|
-
template = templateMigrationFile(entity);
|
|
7719
|
+
template = enableMetaData ? templateMigrationFileWithMetaData(entity) : templateMigrationFile(entity);
|
|
7706
7720
|
}
|
|
7707
7721
|
});
|
|
7708
7722
|
} catch (_error) {
|
|
7709
7723
|
}
|
|
7710
7724
|
return template;
|
|
7711
7725
|
};
|
|
7712
|
-
const templateTestFile = (fileName, entity) => `import
|
|
7726
|
+
const templateTestFile = (fileName, entity, enableMetaData) => `import test from 'node:test';
|
|
7727
|
+
import assert from 'node:assert/strict';
|
|
7728
|
+
import migrate from './${fileName}';
|
|
7713
7729
|
|
|
7714
|
-
|
|
7715
|
-
test('describe test', () => {
|
|
7716
|
-
//arrange
|
|
7730
|
+
test('describe ${entity} change', async (t) => {
|
|
7731
|
+
await t.test('describe test', async () => {
|
|
7732
|
+
// arrange
|
|
7717
7733
|
const ${entity} = {};
|
|
7718
7734
|
|
|
7719
|
-
//act
|
|
7720
|
-
const next${capitalize(entity)} = migrate(${entity});
|
|
7735
|
+
// act
|
|
7736
|
+
const next${capitalize(entity)} = ${enableMetaData ? `migrate(${entity}, /* metaData */ {})` : `migrate(${entity})`};
|
|
7721
7737
|
|
|
7722
|
-
//assert
|
|
7738
|
+
// assert
|
|
7723
7739
|
});
|
|
7724
7740
|
});
|
|
7725
7741
|
`;
|
|
7726
|
-
const createMigration = async (directory, description, entity) => {
|
|
7742
|
+
const createMigration = async (directory, description, entity, enableMetaData) => {
|
|
7727
7743
|
if (!validateFileDescription(description)) {
|
|
7728
7744
|
throw new Error("Invalid migration description");
|
|
7729
7745
|
}
|
|
@@ -7734,13 +7750,20 @@ const createMigration = async (directory, description, entity) => {
|
|
|
7734
7750
|
const filePath = path$1.resolve(directoryFullPath, fileName);
|
|
7735
7751
|
const testFilePath = path$1.resolve(directoryFullPath, testFileName);
|
|
7736
7752
|
await fs.promises.mkdir(directoryFullPath, { recursive: true });
|
|
7737
|
-
const templateMigrationScript = await getTemplateMigrationFile(
|
|
7753
|
+
const templateMigrationScript = await getTemplateMigrationFile(
|
|
7754
|
+
entity,
|
|
7755
|
+
enableMetaData
|
|
7756
|
+
);
|
|
7738
7757
|
await fs.promises.writeFile(filePath, templateMigrationScript, {
|
|
7739
7758
|
encoding: "utf8"
|
|
7740
7759
|
});
|
|
7741
|
-
await fs.promises.writeFile(
|
|
7742
|
-
|
|
7743
|
-
|
|
7760
|
+
await fs.promises.writeFile(
|
|
7761
|
+
testFilePath,
|
|
7762
|
+
templateTestFile(fileName, entity, enableMetaData),
|
|
7763
|
+
{
|
|
7764
|
+
encoding: "utf8"
|
|
7765
|
+
}
|
|
7766
|
+
);
|
|
7744
7767
|
const rawPlan = await readPlan(directory);
|
|
7745
7768
|
const plannedMigrations = parsePlan$1(rawPlan);
|
|
7746
7769
|
const nextPlannedMigrations = plannedMigrations.concat({
|
package/dist/index.d.cts
CHANGED
|
@@ -3,7 +3,7 @@ import { IDatabase, IHelpers, ITask } from 'pg-promise';
|
|
|
3
3
|
/**
|
|
4
4
|
* Generate a new entity migration
|
|
5
5
|
*/
|
|
6
|
-
declare const createMigration: (directory: string, description: string, entity: string) => Promise<void>;
|
|
6
|
+
declare const createMigration: (directory: string, description: string, entity: string, enableMetaData?: boolean) => Promise<void>;
|
|
7
7
|
|
|
8
8
|
type TPlanEntry = {
|
|
9
9
|
fileName: string;
|
package/dist/index.d.mts
CHANGED
|
@@ -3,7 +3,7 @@ import { IDatabase, IHelpers, ITask } from 'pg-promise';
|
|
|
3
3
|
/**
|
|
4
4
|
* Generate a new entity migration
|
|
5
5
|
*/
|
|
6
|
-
declare const createMigration: (directory: string, description: string, entity: string) => Promise<void>;
|
|
6
|
+
declare const createMigration: (directory: string, description: string, entity: string, enableMetaData?: boolean) => Promise<void>;
|
|
7
7
|
|
|
8
8
|
type TPlanEntry = {
|
|
9
9
|
fileName: string;
|
package/dist/index.mjs
CHANGED
|
@@ -7662,6 +7662,20 @@ const getPlannedMigrations = async ({ config }) => {
|
|
|
7662
7662
|
};
|
|
7663
7663
|
const PlanModule = { getPlannedMigrations };
|
|
7664
7664
|
|
|
7665
|
+
const templateMigrationFileWithMetaDataLegacy = (entity) => `import produce from 'immer';
|
|
7666
|
+
//other imports not allowed
|
|
7667
|
+
|
|
7668
|
+
export default (${entity}, metaData = {}) => produce(${entity}, (draft) => {
|
|
7669
|
+
// https://immerjs.github.io/immer/produce#example
|
|
7670
|
+
});
|
|
7671
|
+
`;
|
|
7672
|
+
const templateMigrationFileWithMetaData = (entity) => `import { produce } from 'immer';
|
|
7673
|
+
//other imports not allowed
|
|
7674
|
+
|
|
7675
|
+
export default (${entity}, metaData = {}) => produce(${entity}, (draft) => {
|
|
7676
|
+
// https://immerjs.github.io/immer/produce#example
|
|
7677
|
+
});
|
|
7678
|
+
`;
|
|
7665
7679
|
const templateMigrationFileLegacy = (entity) => `import produce from 'immer';
|
|
7666
7680
|
//other imports not allowed
|
|
7667
7681
|
|
|
@@ -7676,33 +7690,35 @@ export default (${entity}) => produce(${entity}, (draft) => {
|
|
|
7676
7690
|
// https://immerjs.github.io/immer/produce#example
|
|
7677
7691
|
});
|
|
7678
7692
|
`;
|
|
7679
|
-
const getTemplateMigrationFile = async (entity) => {
|
|
7680
|
-
let template = templateMigrationFileLegacy(entity);
|
|
7693
|
+
const getTemplateMigrationFile = async (entity, enableMetaData) => {
|
|
7694
|
+
let template = enableMetaData ? templateMigrationFileWithMetaDataLegacy(entity) : templateMigrationFileLegacy(entity);
|
|
7681
7695
|
try {
|
|
7682
7696
|
await import('./immer-C8oEWD0M.mjs').then(({ produce }) => {
|
|
7683
7697
|
if (produce) {
|
|
7684
|
-
template = templateMigrationFile(entity);
|
|
7698
|
+
template = enableMetaData ? templateMigrationFileWithMetaData(entity) : templateMigrationFile(entity);
|
|
7685
7699
|
}
|
|
7686
7700
|
});
|
|
7687
7701
|
} catch (_error) {
|
|
7688
7702
|
}
|
|
7689
7703
|
return template;
|
|
7690
7704
|
};
|
|
7691
|
-
const templateTestFile = (fileName, entity) => `import
|
|
7705
|
+
const templateTestFile = (fileName, entity, enableMetaData) => `import test from 'node:test';
|
|
7706
|
+
import assert from 'node:assert/strict';
|
|
7707
|
+
import migrate from './${fileName}';
|
|
7692
7708
|
|
|
7693
|
-
|
|
7694
|
-
test('describe test', () => {
|
|
7695
|
-
//arrange
|
|
7709
|
+
test('describe ${entity} change', async (t) => {
|
|
7710
|
+
await t.test('describe test', async () => {
|
|
7711
|
+
// arrange
|
|
7696
7712
|
const ${entity} = {};
|
|
7697
7713
|
|
|
7698
|
-
//act
|
|
7699
|
-
const next${capitalize(entity)} = migrate(${entity});
|
|
7714
|
+
// act
|
|
7715
|
+
const next${capitalize(entity)} = ${enableMetaData ? `migrate(${entity}, /* metaData */ {})` : `migrate(${entity})`};
|
|
7700
7716
|
|
|
7701
|
-
//assert
|
|
7717
|
+
// assert
|
|
7702
7718
|
});
|
|
7703
7719
|
});
|
|
7704
7720
|
`;
|
|
7705
|
-
const createMigration = async (directory, description, entity) => {
|
|
7721
|
+
const createMigration = async (directory, description, entity, enableMetaData) => {
|
|
7706
7722
|
if (!validateFileDescription(description)) {
|
|
7707
7723
|
throw new Error("Invalid migration description");
|
|
7708
7724
|
}
|
|
@@ -7713,13 +7729,20 @@ const createMigration = async (directory, description, entity) => {
|
|
|
7713
7729
|
const filePath = path$1.resolve(directoryFullPath, fileName);
|
|
7714
7730
|
const testFilePath = path$1.resolve(directoryFullPath, testFileName);
|
|
7715
7731
|
await promises.mkdir(directoryFullPath, { recursive: true });
|
|
7716
|
-
const templateMigrationScript = await getTemplateMigrationFile(
|
|
7732
|
+
const templateMigrationScript = await getTemplateMigrationFile(
|
|
7733
|
+
entity,
|
|
7734
|
+
enableMetaData
|
|
7735
|
+
);
|
|
7717
7736
|
await promises.writeFile(filePath, templateMigrationScript, {
|
|
7718
7737
|
encoding: "utf8"
|
|
7719
7738
|
});
|
|
7720
|
-
await promises.writeFile(
|
|
7721
|
-
|
|
7722
|
-
|
|
7739
|
+
await promises.writeFile(
|
|
7740
|
+
testFilePath,
|
|
7741
|
+
templateTestFile(fileName, entity, enableMetaData),
|
|
7742
|
+
{
|
|
7743
|
+
encoding: "utf8"
|
|
7744
|
+
}
|
|
7745
|
+
);
|
|
7723
7746
|
const rawPlan = await readPlan(directory);
|
|
7724
7747
|
const plannedMigrations = parsePlan$1(rawPlan);
|
|
7725
7748
|
const nextPlannedMigrations = plannedMigrations.concat({
|
package/package.json
CHANGED