@oliasoft-open-source/node-json-migrator 4.3.0-beta-1 → 4.3.0-beta-3
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 +13 -14
- package/dist/index.d.cts +6 -7
- package/dist/index.d.mts +6 -7
- package/dist/index.mjs +13 -14
- package/package.json +1 -1
package/dist/index.cjs
CHANGED
|
@@ -7683,19 +7683,17 @@ const getPlannedMigrations = async ({ config }) => {
|
|
|
7683
7683
|
};
|
|
7684
7684
|
const PlanModule = { getPlannedMigrations };
|
|
7685
7685
|
|
|
7686
|
-
const
|
|
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
|
|
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,35 +7711,36 @@ export default (${entity}) => produce(${entity}, (draft) => {
|
|
|
7713
7711
|
// https://immerjs.github.io/immer/produce#example
|
|
7714
7712
|
});
|
|
7715
7713
|
`;
|
|
7716
|
-
const getTemplateMigrationFile = async (entity,
|
|
7717
|
-
let template =
|
|
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 =
|
|
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,
|
|
7726
|
+
const templateTestFile = (fileName, entity, enableMetaData) => `import { describe, test } from 'node:test';
|
|
7729
7727
|
import assert from 'node:assert/strict';
|
|
7730
7728
|
import migrate from './${fileName}';
|
|
7731
7729
|
|
|
7732
|
-
|
|
7733
|
-
|
|
7730
|
+
describe('${entity} change', () => {
|
|
7731
|
+
test('should migrate an empty ${entity}', () => {
|
|
7734
7732
|
// arrange
|
|
7735
7733
|
const ${entity} = {};
|
|
7736
7734
|
|
|
7737
7735
|
// act
|
|
7738
|
-
const next${capitalize(entity)} = ${
|
|
7736
|
+
const next${capitalize(entity)} = ${enableMetaData ? `migrate(${entity}, /* metaData */ {})` : `migrate(${entity})`};
|
|
7739
7737
|
|
|
7740
7738
|
// assert
|
|
7739
|
+
assert.ok(next${capitalize(entity)});
|
|
7741
7740
|
});
|
|
7742
7741
|
});
|
|
7743
7742
|
`;
|
|
7744
|
-
const createMigration = async (directory, description, entity,
|
|
7743
|
+
const createMigration = async (directory, description, entity, enableMetaData) => {
|
|
7745
7744
|
if (!validateFileDescription(description)) {
|
|
7746
7745
|
throw new Error("Invalid migration description");
|
|
7747
7746
|
}
|
|
@@ -7754,14 +7753,14 @@ const createMigration = async (directory, description, entity, type = "dataset")
|
|
|
7754
7753
|
await fs.promises.mkdir(directoryFullPath, { recursive: true });
|
|
7755
7754
|
const templateMigrationScript = await getTemplateMigrationFile(
|
|
7756
7755
|
entity,
|
|
7757
|
-
|
|
7756
|
+
enableMetaData
|
|
7758
7757
|
);
|
|
7759
7758
|
await fs.promises.writeFile(filePath, templateMigrationScript, {
|
|
7760
7759
|
encoding: "utf8"
|
|
7761
7760
|
});
|
|
7762
7761
|
await fs.promises.writeFile(
|
|
7763
7762
|
testFilePath,
|
|
7764
|
-
templateTestFile(fileName, entity,
|
|
7763
|
+
templateTestFile(fileName, entity, enableMetaData),
|
|
7765
7764
|
{
|
|
7766
7765
|
encoding: "utf8"
|
|
7767
7766
|
}
|
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
|
|
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
|
|
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
|
|
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
|
|
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,35 +7690,36 @@ export default (${entity}) => produce(${entity}, (draft) => {
|
|
|
7692
7690
|
// https://immerjs.github.io/immer/produce#example
|
|
7693
7691
|
});
|
|
7694
7692
|
`;
|
|
7695
|
-
const getTemplateMigrationFile = async (entity,
|
|
7696
|
-
let template =
|
|
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 =
|
|
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,
|
|
7705
|
+
const templateTestFile = (fileName, entity, enableMetaData) => `import { describe, test } from 'node:test';
|
|
7708
7706
|
import assert from 'node:assert/strict';
|
|
7709
7707
|
import migrate from './${fileName}';
|
|
7710
7708
|
|
|
7711
|
-
|
|
7712
|
-
|
|
7709
|
+
describe('${entity} change', () => {
|
|
7710
|
+
test('should migrate an empty ${entity}', () => {
|
|
7713
7711
|
// arrange
|
|
7714
7712
|
const ${entity} = {};
|
|
7715
7713
|
|
|
7716
7714
|
// act
|
|
7717
|
-
const next${capitalize(entity)} = ${
|
|
7715
|
+
const next${capitalize(entity)} = ${enableMetaData ? `migrate(${entity}, /* metaData */ {})` : `migrate(${entity})`};
|
|
7718
7716
|
|
|
7719
7717
|
// assert
|
|
7718
|
+
assert.ok(next${capitalize(entity)});
|
|
7720
7719
|
});
|
|
7721
7720
|
});
|
|
7722
7721
|
`;
|
|
7723
|
-
const createMigration = async (directory, description, entity,
|
|
7722
|
+
const createMigration = async (directory, description, entity, enableMetaData) => {
|
|
7724
7723
|
if (!validateFileDescription(description)) {
|
|
7725
7724
|
throw new Error("Invalid migration description");
|
|
7726
7725
|
}
|
|
@@ -7733,14 +7732,14 @@ const createMigration = async (directory, description, entity, type = "dataset")
|
|
|
7733
7732
|
await promises.mkdir(directoryFullPath, { recursive: true });
|
|
7734
7733
|
const templateMigrationScript = await getTemplateMigrationFile(
|
|
7735
7734
|
entity,
|
|
7736
|
-
|
|
7735
|
+
enableMetaData
|
|
7737
7736
|
);
|
|
7738
7737
|
await promises.writeFile(filePath, templateMigrationScript, {
|
|
7739
7738
|
encoding: "utf8"
|
|
7740
7739
|
});
|
|
7741
7740
|
await promises.writeFile(
|
|
7742
7741
|
testFilePath,
|
|
7743
|
-
templateTestFile(fileName, entity,
|
|
7742
|
+
templateTestFile(fileName, entity, enableMetaData),
|
|
7744
7743
|
{
|
|
7745
7744
|
encoding: "utf8"
|
|
7746
7745
|
}
|
package/package.json
CHANGED