@oliasoft-open-source/node-json-migrator 3.0.0 → 3.1.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 +451 -237
- package/dist/index.d.cts +50 -2
- package/dist/index.d.mts +50 -2
- package/dist/index.mjs +452 -239
- package/package.json +15 -15
package/dist/index.d.cts
CHANGED
|
@@ -1,4 +1,4 @@
|
|
|
1
|
-
import { IDatabase, IHelpers } from 'pg-promise';
|
|
1
|
+
import { IDatabase, IHelpers, ITask } from 'pg-promise';
|
|
2
2
|
|
|
3
3
|
/**
|
|
4
4
|
* Generate a new dataset migration
|
|
@@ -17,11 +17,25 @@ type TMigration = {
|
|
|
17
17
|
script?: string;
|
|
18
18
|
migrator?: (payload: unknown) => unknown;
|
|
19
19
|
};
|
|
20
|
+
type TEntityColumnNames = {
|
|
21
|
+
id: string;
|
|
22
|
+
created: string;
|
|
23
|
+
};
|
|
24
|
+
type TRecord<T extends TEntityColumnNames = TEntityColumnNames> = {
|
|
25
|
+
name: string;
|
|
26
|
+
version: string;
|
|
27
|
+
} & {
|
|
28
|
+
[K in T['id']]: number | string;
|
|
29
|
+
} & {
|
|
30
|
+
[K in T['created']]: string | Date;
|
|
31
|
+
};
|
|
20
32
|
type TConfig = {
|
|
21
33
|
directory: string;
|
|
22
34
|
database?: IDatabase<unknown>;
|
|
23
35
|
pgpHelpers?: IHelpers;
|
|
24
36
|
entity?: string;
|
|
37
|
+
entityColumnNames: TEntityColumnNames;
|
|
38
|
+
entityIdColumnName?: string;
|
|
25
39
|
version?: string;
|
|
26
40
|
printPendingFileNames?: boolean;
|
|
27
41
|
force?: boolean;
|
|
@@ -29,6 +43,30 @@ type TConfig = {
|
|
|
29
43
|
importModule?: boolean;
|
|
30
44
|
autoInitializeTable?: boolean;
|
|
31
45
|
};
|
|
46
|
+
type TBeforeMigrateRecordPayload = {
|
|
47
|
+
currentRecord: TRecord;
|
|
48
|
+
dry: boolean;
|
|
49
|
+
};
|
|
50
|
+
type TBeforeMigrateRecord = (params: TBeforeMigrateRecordPayload) => Promise<void>;
|
|
51
|
+
type TAfterMigrateRecordPayload = {
|
|
52
|
+
currentRecord: TRecord;
|
|
53
|
+
nextRecord: TRecord;
|
|
54
|
+
transaction?: ITask<unknown>;
|
|
55
|
+
dry: boolean;
|
|
56
|
+
};
|
|
57
|
+
type TAfterMigrateRecord = (params: TAfterMigrateRecordPayload) => Promise<void>;
|
|
58
|
+
type TMigrationErrorPayload = {
|
|
59
|
+
id: string;
|
|
60
|
+
name: string;
|
|
61
|
+
created: string | Date;
|
|
62
|
+
error: unknown;
|
|
63
|
+
stackTrace?: string;
|
|
64
|
+
};
|
|
65
|
+
type TOnMigrationErrorsPayload = {
|
|
66
|
+
migrationErrors: TMigrationErrorPayload[];
|
|
67
|
+
dry: boolean;
|
|
68
|
+
};
|
|
69
|
+
type TOnMigrationErrors = (params: TOnMigrationErrorsPayload) => Promise<void>;
|
|
32
70
|
|
|
33
71
|
declare const getPlannedMigrations: ({ config }: {
|
|
34
72
|
config: TConfig;
|
|
@@ -56,6 +94,16 @@ declare const migrate: ({ payload, config, }: {
|
|
|
56
94
|
nextVersion: string;
|
|
57
95
|
}>;
|
|
58
96
|
|
|
97
|
+
/**
|
|
98
|
+
* Migrate all records (only use via command line interface)
|
|
99
|
+
*/
|
|
100
|
+
declare const migrateAll: ({ config, beforeMigrateRecord, afterMigrateRecord, onMigrationErrors, }: {
|
|
101
|
+
config: TConfig;
|
|
102
|
+
beforeMigrateRecord: TBeforeMigrateRecord;
|
|
103
|
+
afterMigrateRecord: TAfterMigrateRecord;
|
|
104
|
+
onMigrationErrors: TOnMigrationErrors;
|
|
105
|
+
}) => Promise<void>;
|
|
106
|
+
|
|
59
107
|
/**
|
|
60
108
|
* Executes the pending migrators on a payload, returns modified payload
|
|
61
109
|
*
|
|
@@ -78,4 +126,4 @@ declare const printVersionHistory: ({ config }: {
|
|
|
78
126
|
config: TConfig;
|
|
79
127
|
}) => Promise<void>;
|
|
80
128
|
|
|
81
|
-
export { createMigration, getPlannedMigrations, getPlannedVersion, getVersions, migrate, pipe, printVersionHistory };
|
|
129
|
+
export { type TAfterMigrateRecord, type TAfterMigrateRecordPayload, type TBeforeMigrateRecord, type TBeforeMigrateRecordPayload, type TConfig, type TEntityColumnNames, type TMigration, type TMigrationErrorPayload, type TOnMigrationErrors, type TOnMigrationErrorsPayload, type TRecord, createMigration, getPlannedMigrations, getPlannedVersion, getVersions, migrate, migrateAll, pipe, printVersionHistory };
|
package/dist/index.d.mts
CHANGED
|
@@ -1,4 +1,4 @@
|
|
|
1
|
-
import { IDatabase, IHelpers } from 'pg-promise';
|
|
1
|
+
import { IDatabase, IHelpers, ITask } from 'pg-promise';
|
|
2
2
|
|
|
3
3
|
/**
|
|
4
4
|
* Generate a new dataset migration
|
|
@@ -17,11 +17,25 @@ type TMigration = {
|
|
|
17
17
|
script?: string;
|
|
18
18
|
migrator?: (payload: unknown) => unknown;
|
|
19
19
|
};
|
|
20
|
+
type TEntityColumnNames = {
|
|
21
|
+
id: string;
|
|
22
|
+
created: string;
|
|
23
|
+
};
|
|
24
|
+
type TRecord<T extends TEntityColumnNames = TEntityColumnNames> = {
|
|
25
|
+
name: string;
|
|
26
|
+
version: string;
|
|
27
|
+
} & {
|
|
28
|
+
[K in T['id']]: number | string;
|
|
29
|
+
} & {
|
|
30
|
+
[K in T['created']]: string | Date;
|
|
31
|
+
};
|
|
20
32
|
type TConfig = {
|
|
21
33
|
directory: string;
|
|
22
34
|
database?: IDatabase<unknown>;
|
|
23
35
|
pgpHelpers?: IHelpers;
|
|
24
36
|
entity?: string;
|
|
37
|
+
entityColumnNames: TEntityColumnNames;
|
|
38
|
+
entityIdColumnName?: string;
|
|
25
39
|
version?: string;
|
|
26
40
|
printPendingFileNames?: boolean;
|
|
27
41
|
force?: boolean;
|
|
@@ -29,6 +43,30 @@ type TConfig = {
|
|
|
29
43
|
importModule?: boolean;
|
|
30
44
|
autoInitializeTable?: boolean;
|
|
31
45
|
};
|
|
46
|
+
type TBeforeMigrateRecordPayload = {
|
|
47
|
+
currentRecord: TRecord;
|
|
48
|
+
dry: boolean;
|
|
49
|
+
};
|
|
50
|
+
type TBeforeMigrateRecord = (params: TBeforeMigrateRecordPayload) => Promise<void>;
|
|
51
|
+
type TAfterMigrateRecordPayload = {
|
|
52
|
+
currentRecord: TRecord;
|
|
53
|
+
nextRecord: TRecord;
|
|
54
|
+
transaction?: ITask<unknown>;
|
|
55
|
+
dry: boolean;
|
|
56
|
+
};
|
|
57
|
+
type TAfterMigrateRecord = (params: TAfterMigrateRecordPayload) => Promise<void>;
|
|
58
|
+
type TMigrationErrorPayload = {
|
|
59
|
+
id: string;
|
|
60
|
+
name: string;
|
|
61
|
+
created: string | Date;
|
|
62
|
+
error: unknown;
|
|
63
|
+
stackTrace?: string;
|
|
64
|
+
};
|
|
65
|
+
type TOnMigrationErrorsPayload = {
|
|
66
|
+
migrationErrors: TMigrationErrorPayload[];
|
|
67
|
+
dry: boolean;
|
|
68
|
+
};
|
|
69
|
+
type TOnMigrationErrors = (params: TOnMigrationErrorsPayload) => Promise<void>;
|
|
32
70
|
|
|
33
71
|
declare const getPlannedMigrations: ({ config }: {
|
|
34
72
|
config: TConfig;
|
|
@@ -56,6 +94,16 @@ declare const migrate: ({ payload, config, }: {
|
|
|
56
94
|
nextVersion: string;
|
|
57
95
|
}>;
|
|
58
96
|
|
|
97
|
+
/**
|
|
98
|
+
* Migrate all records (only use via command line interface)
|
|
99
|
+
*/
|
|
100
|
+
declare const migrateAll: ({ config, beforeMigrateRecord, afterMigrateRecord, onMigrationErrors, }: {
|
|
101
|
+
config: TConfig;
|
|
102
|
+
beforeMigrateRecord: TBeforeMigrateRecord;
|
|
103
|
+
afterMigrateRecord: TAfterMigrateRecord;
|
|
104
|
+
onMigrationErrors: TOnMigrationErrors;
|
|
105
|
+
}) => Promise<void>;
|
|
106
|
+
|
|
59
107
|
/**
|
|
60
108
|
* Executes the pending migrators on a payload, returns modified payload
|
|
61
109
|
*
|
|
@@ -78,4 +126,4 @@ declare const printVersionHistory: ({ config }: {
|
|
|
78
126
|
config: TConfig;
|
|
79
127
|
}) => Promise<void>;
|
|
80
128
|
|
|
81
|
-
export { createMigration, getPlannedMigrations, getPlannedVersion, getVersions, migrate, pipe, printVersionHistory };
|
|
129
|
+
export { type TAfterMigrateRecord, type TAfterMigrateRecordPayload, type TBeforeMigrateRecord, type TBeforeMigrateRecordPayload, type TConfig, type TEntityColumnNames, type TMigration, type TMigrationErrorPayload, type TOnMigrationErrors, type TOnMigrationErrorsPayload, type TRecord, createMigration, getPlannedMigrations, getPlannedVersion, getVersions, migrate, migrateAll, pipe, printVersionHistory };
|