@oliasoft-open-source/node-json-migrator 4.2.1 → 4.3.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.cjs +40 -15
- package/dist/index.d.cts +7 -6
- package/dist/index.d.mts +7 -6
- package/dist/index.mjs +40 -15
- package/package.json +1 -1
package/dist/index.cjs
CHANGED
|
@@ -7683,6 +7683,22 @@ const getPlannedMigrations = async ({ config }) => {
|
|
|
7683
7683
|
};
|
|
7684
7684
|
const PlanModule = { getPlannedMigrations };
|
|
7685
7685
|
|
|
7686
|
+
const templateMigrationFileLegacyRuleset = (entity) => `import produce from 'immer';
|
|
7687
|
+
//other imports not allowed
|
|
7688
|
+
|
|
7689
|
+
export default (${entity}, metaData = {}) => produce(${entity}, (draft) => {
|
|
7690
|
+
void metaData;
|
|
7691
|
+
// https://immerjs.github.io/immer/produce#example
|
|
7692
|
+
});
|
|
7693
|
+
`;
|
|
7694
|
+
const templateMigrationFileRuleset = (entity) => `import { produce } from 'immer';
|
|
7695
|
+
//other imports not allowed
|
|
7696
|
+
|
|
7697
|
+
export default (${entity}, metaData = {}) => produce(${entity}, (draft) => {
|
|
7698
|
+
void metaData;
|
|
7699
|
+
// https://immerjs.github.io/immer/produce#example
|
|
7700
|
+
});
|
|
7701
|
+
`;
|
|
7686
7702
|
const templateMigrationFileLegacy = (entity) => `import produce from 'immer';
|
|
7687
7703
|
//other imports not allowed
|
|
7688
7704
|
|
|
@@ -7697,33 +7713,35 @@ export default (${entity}) => produce(${entity}, (draft) => {
|
|
|
7697
7713
|
// https://immerjs.github.io/immer/produce#example
|
|
7698
7714
|
});
|
|
7699
7715
|
`;
|
|
7700
|
-
const getTemplateMigrationFile = async (entity) => {
|
|
7701
|
-
let template = templateMigrationFileLegacy(entity);
|
|
7716
|
+
const getTemplateMigrationFile = async (entity, type) => {
|
|
7717
|
+
let template = type === "ruleset" ? templateMigrationFileLegacyRuleset(entity) : templateMigrationFileLegacy(entity);
|
|
7702
7718
|
try {
|
|
7703
7719
|
await Promise.resolve().then(function () { return require('./immer-BsT8CIGL.cjs'); }).then(({ produce }) => {
|
|
7704
7720
|
if (produce) {
|
|
7705
|
-
template = templateMigrationFile(entity);
|
|
7721
|
+
template = type === "ruleset" ? templateMigrationFileRuleset(entity) : templateMigrationFile(entity);
|
|
7706
7722
|
}
|
|
7707
7723
|
});
|
|
7708
7724
|
} catch (_error) {
|
|
7709
7725
|
}
|
|
7710
7726
|
return template;
|
|
7711
7727
|
};
|
|
7712
|
-
const templateTestFile = (fileName, entity) => `import
|
|
7728
|
+
const templateTestFile = (fileName, entity, type) => `import test from 'node:test';
|
|
7729
|
+
import assert from 'node:assert/strict';
|
|
7730
|
+
import migrate from './${fileName}';
|
|
7713
7731
|
|
|
7714
|
-
|
|
7715
|
-
test('describe test', () => {
|
|
7716
|
-
//arrange
|
|
7732
|
+
test('describe ${entity} change', async (t) => {
|
|
7733
|
+
await t.test('describe test', async () => {
|
|
7734
|
+
// arrange
|
|
7717
7735
|
const ${entity} = {};
|
|
7718
7736
|
|
|
7719
|
-
//act
|
|
7720
|
-
const next${capitalize(entity)} = migrate(${entity});
|
|
7737
|
+
// act
|
|
7738
|
+
const next${capitalize(entity)} = ${type === "ruleset" ? `migrate(${entity}, /* metaData */ {})` : `migrate(${entity})`};
|
|
7721
7739
|
|
|
7722
|
-
//assert
|
|
7740
|
+
// assert
|
|
7723
7741
|
});
|
|
7724
7742
|
});
|
|
7725
7743
|
`;
|
|
7726
|
-
const createMigration = async (directory, description, entity) => {
|
|
7744
|
+
const createMigration = async (directory, description, entity, type = "dataset") => {
|
|
7727
7745
|
if (!validateFileDescription(description)) {
|
|
7728
7746
|
throw new Error("Invalid migration description");
|
|
7729
7747
|
}
|
|
@@ -7734,13 +7752,20 @@ const createMigration = async (directory, description, entity) => {
|
|
|
7734
7752
|
const filePath = path$1.resolve(directoryFullPath, fileName);
|
|
7735
7753
|
const testFilePath = path$1.resolve(directoryFullPath, testFileName);
|
|
7736
7754
|
await fs.promises.mkdir(directoryFullPath, { recursive: true });
|
|
7737
|
-
const templateMigrationScript = await getTemplateMigrationFile(
|
|
7755
|
+
const templateMigrationScript = await getTemplateMigrationFile(
|
|
7756
|
+
entity,
|
|
7757
|
+
type
|
|
7758
|
+
);
|
|
7738
7759
|
await fs.promises.writeFile(filePath, templateMigrationScript, {
|
|
7739
7760
|
encoding: "utf8"
|
|
7740
7761
|
});
|
|
7741
|
-
await fs.promises.writeFile(
|
|
7742
|
-
|
|
7743
|
-
|
|
7762
|
+
await fs.promises.writeFile(
|
|
7763
|
+
testFilePath,
|
|
7764
|
+
templateTestFile(fileName, entity, type),
|
|
7765
|
+
{
|
|
7766
|
+
encoding: "utf8"
|
|
7767
|
+
}
|
|
7768
|
+
);
|
|
7744
7769
|
const rawPlan = await readPlan(directory);
|
|
7745
7770
|
const plannedMigrations = parsePlan$1(rawPlan);
|
|
7746
7771
|
const nextPlannedMigrations = plannedMigrations.concat({
|
package/dist/index.d.cts
CHANGED
|
@@ -1,10 +1,5 @@
|
|
|
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) => Promise<void>;
|
|
7
|
-
|
|
8
3
|
type TPlanEntry = {
|
|
9
4
|
fileName: string;
|
|
10
5
|
fileHash: string;
|
|
@@ -25,6 +20,7 @@ type TMigration = {
|
|
|
25
20
|
script?: string;
|
|
26
21
|
migrator?: (payload: TPayload, metaData?: TMetaData) => TPayload;
|
|
27
22
|
};
|
|
23
|
+
type TMigrationType = 'dataset' | 'ruleset';
|
|
28
24
|
type TRecordDetails = {
|
|
29
25
|
id: number | string;
|
|
30
26
|
name: string;
|
|
@@ -94,6 +90,11 @@ type TOnMigrationErrorsPayload = {
|
|
|
94
90
|
};
|
|
95
91
|
type TOnMigrationErrors = (params: TOnMigrationErrorsPayload) => Promise<void>;
|
|
96
92
|
|
|
93
|
+
/**
|
|
94
|
+
* Generate a new entity migration
|
|
95
|
+
*/
|
|
96
|
+
declare const createMigration: (directory: string, description: string, entity: string, type?: TMigrationType) => Promise<void>;
|
|
97
|
+
|
|
97
98
|
declare const getPlannedMigrations: ({ config }: {
|
|
98
99
|
config: TConfig;
|
|
99
100
|
}) => Promise<{
|
|
@@ -158,4 +159,4 @@ declare const printVersionHistory: ({ config }: {
|
|
|
158
159
|
config: TConfig;
|
|
159
160
|
}) => Promise<void>;
|
|
160
161
|
|
|
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 };
|
|
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 };
|
package/dist/index.d.mts
CHANGED
|
@@ -1,10 +1,5 @@
|
|
|
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) => Promise<void>;
|
|
7
|
-
|
|
8
3
|
type TPlanEntry = {
|
|
9
4
|
fileName: string;
|
|
10
5
|
fileHash: string;
|
|
@@ -25,6 +20,7 @@ type TMigration = {
|
|
|
25
20
|
script?: string;
|
|
26
21
|
migrator?: (payload: TPayload, metaData?: TMetaData) => TPayload;
|
|
27
22
|
};
|
|
23
|
+
type TMigrationType = 'dataset' | 'ruleset';
|
|
28
24
|
type TRecordDetails = {
|
|
29
25
|
id: number | string;
|
|
30
26
|
name: string;
|
|
@@ -94,6 +90,11 @@ type TOnMigrationErrorsPayload = {
|
|
|
94
90
|
};
|
|
95
91
|
type TOnMigrationErrors = (params: TOnMigrationErrorsPayload) => Promise<void>;
|
|
96
92
|
|
|
93
|
+
/**
|
|
94
|
+
* Generate a new entity migration
|
|
95
|
+
*/
|
|
96
|
+
declare const createMigration: (directory: string, description: string, entity: string, type?: TMigrationType) => Promise<void>;
|
|
97
|
+
|
|
97
98
|
declare const getPlannedMigrations: ({ config }: {
|
|
98
99
|
config: TConfig;
|
|
99
100
|
}) => Promise<{
|
|
@@ -158,4 +159,4 @@ declare const printVersionHistory: ({ config }: {
|
|
|
158
159
|
config: TConfig;
|
|
159
160
|
}) => Promise<void>;
|
|
160
161
|
|
|
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 };
|
|
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 };
|
package/dist/index.mjs
CHANGED
|
@@ -7662,6 +7662,22 @@ const getPlannedMigrations = async ({ config }) => {
|
|
|
7662
7662
|
};
|
|
7663
7663
|
const PlanModule = { getPlannedMigrations };
|
|
7664
7664
|
|
|
7665
|
+
const templateMigrationFileLegacyRuleset = (entity) => `import produce from 'immer';
|
|
7666
|
+
//other imports not allowed
|
|
7667
|
+
|
|
7668
|
+
export default (${entity}, metaData = {}) => produce(${entity}, (draft) => {
|
|
7669
|
+
void metaData;
|
|
7670
|
+
// https://immerjs.github.io/immer/produce#example
|
|
7671
|
+
});
|
|
7672
|
+
`;
|
|
7673
|
+
const templateMigrationFileRuleset = (entity) => `import { produce } from 'immer';
|
|
7674
|
+
//other imports not allowed
|
|
7675
|
+
|
|
7676
|
+
export default (${entity}, metaData = {}) => produce(${entity}, (draft) => {
|
|
7677
|
+
void metaData;
|
|
7678
|
+
// https://immerjs.github.io/immer/produce#example
|
|
7679
|
+
});
|
|
7680
|
+
`;
|
|
7665
7681
|
const templateMigrationFileLegacy = (entity) => `import produce from 'immer';
|
|
7666
7682
|
//other imports not allowed
|
|
7667
7683
|
|
|
@@ -7676,33 +7692,35 @@ export default (${entity}) => produce(${entity}, (draft) => {
|
|
|
7676
7692
|
// https://immerjs.github.io/immer/produce#example
|
|
7677
7693
|
});
|
|
7678
7694
|
`;
|
|
7679
|
-
const getTemplateMigrationFile = async (entity) => {
|
|
7680
|
-
let template = templateMigrationFileLegacy(entity);
|
|
7695
|
+
const getTemplateMigrationFile = async (entity, type) => {
|
|
7696
|
+
let template = type === "ruleset" ? templateMigrationFileLegacyRuleset(entity) : templateMigrationFileLegacy(entity);
|
|
7681
7697
|
try {
|
|
7682
7698
|
await import('./immer-C8oEWD0M.mjs').then(({ produce }) => {
|
|
7683
7699
|
if (produce) {
|
|
7684
|
-
template = templateMigrationFile(entity);
|
|
7700
|
+
template = type === "ruleset" ? templateMigrationFileRuleset(entity) : templateMigrationFile(entity);
|
|
7685
7701
|
}
|
|
7686
7702
|
});
|
|
7687
7703
|
} catch (_error) {
|
|
7688
7704
|
}
|
|
7689
7705
|
return template;
|
|
7690
7706
|
};
|
|
7691
|
-
const templateTestFile = (fileName, entity) => `import
|
|
7707
|
+
const templateTestFile = (fileName, entity, type) => `import test from 'node:test';
|
|
7708
|
+
import assert from 'node:assert/strict';
|
|
7709
|
+
import migrate from './${fileName}';
|
|
7692
7710
|
|
|
7693
|
-
|
|
7694
|
-
test('describe test', () => {
|
|
7695
|
-
//arrange
|
|
7711
|
+
test('describe ${entity} change', async (t) => {
|
|
7712
|
+
await t.test('describe test', async () => {
|
|
7713
|
+
// arrange
|
|
7696
7714
|
const ${entity} = {};
|
|
7697
7715
|
|
|
7698
|
-
//act
|
|
7699
|
-
const next${capitalize(entity)} = migrate(${entity});
|
|
7716
|
+
// act
|
|
7717
|
+
const next${capitalize(entity)} = ${type === "ruleset" ? `migrate(${entity}, /* metaData */ {})` : `migrate(${entity})`};
|
|
7700
7718
|
|
|
7701
|
-
//assert
|
|
7719
|
+
// assert
|
|
7702
7720
|
});
|
|
7703
7721
|
});
|
|
7704
7722
|
`;
|
|
7705
|
-
const createMigration = async (directory, description, entity) => {
|
|
7723
|
+
const createMigration = async (directory, description, entity, type = "dataset") => {
|
|
7706
7724
|
if (!validateFileDescription(description)) {
|
|
7707
7725
|
throw new Error("Invalid migration description");
|
|
7708
7726
|
}
|
|
@@ -7713,13 +7731,20 @@ const createMigration = async (directory, description, entity) => {
|
|
|
7713
7731
|
const filePath = path$1.resolve(directoryFullPath, fileName);
|
|
7714
7732
|
const testFilePath = path$1.resolve(directoryFullPath, testFileName);
|
|
7715
7733
|
await promises.mkdir(directoryFullPath, { recursive: true });
|
|
7716
|
-
const templateMigrationScript = await getTemplateMigrationFile(
|
|
7734
|
+
const templateMigrationScript = await getTemplateMigrationFile(
|
|
7735
|
+
entity,
|
|
7736
|
+
type
|
|
7737
|
+
);
|
|
7717
7738
|
await promises.writeFile(filePath, templateMigrationScript, {
|
|
7718
7739
|
encoding: "utf8"
|
|
7719
7740
|
});
|
|
7720
|
-
await promises.writeFile(
|
|
7721
|
-
|
|
7722
|
-
|
|
7741
|
+
await promises.writeFile(
|
|
7742
|
+
testFilePath,
|
|
7743
|
+
templateTestFile(fileName, entity, type),
|
|
7744
|
+
{
|
|
7745
|
+
encoding: "utf8"
|
|
7746
|
+
}
|
|
7747
|
+
);
|
|
7723
7748
|
const rawPlan = await readPlan(directory);
|
|
7724
7749
|
const plannedMigrations = parsePlan$1(rawPlan);
|
|
7725
7750
|
const nextPlannedMigrations = plannedMigrations.concat({
|
package/package.json
CHANGED