@oliasoft-open-source/node-json-migrator 4.6.0-beta-2 → 5.0.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.d.mts +113 -107
- package/dist/index.mjs +4537 -4400
- package/package.json +15 -21
- package/dist/index.cjs +0 -4824
- package/dist/index.d.cts +0 -165
package/dist/index.d.mts
CHANGED
|
@@ -1,119 +1,114 @@
|
|
|
1
|
-
import {
|
|
1
|
+
import { IDatabase, IHelpers, ITask } from "pg-promise";
|
|
2
2
|
|
|
3
|
+
//#region src/create/create.d.ts
|
|
3
4
|
/**
|
|
4
5
|
* Generate a new entity migration
|
|
5
6
|
*/
|
|
6
7
|
declare const createMigration: (directory: string, description: string, entity: string, enableMetaData?: boolean) => Promise<void>;
|
|
7
|
-
|
|
8
|
+
//#endregion
|
|
9
|
+
//#region src/types.d.ts
|
|
8
10
|
type TPlanEntry = {
|
|
9
|
-
|
|
10
|
-
|
|
11
|
-
|
|
11
|
+
fileName: string;
|
|
12
|
+
fileHash: string;
|
|
13
|
+
sequence: string;
|
|
12
14
|
};
|
|
13
15
|
type TPlan = TPlanEntry[];
|
|
14
16
|
type TPayload = Record<string, unknown>;
|
|
15
17
|
type TMetaData = Record<string, unknown>;
|
|
16
18
|
type TMigration = {
|
|
17
|
-
|
|
18
|
-
|
|
19
|
-
|
|
20
|
-
|
|
21
|
-
|
|
22
|
-
|
|
23
|
-
|
|
24
|
-
|
|
25
|
-
|
|
26
|
-
|
|
27
|
-
migrator?: (payload: TPayload, metaData?: TMetaData) => TPayload;
|
|
19
|
+
fileName?: string;
|
|
20
|
+
fileHash?: string;
|
|
21
|
+
sequence?: string;
|
|
22
|
+
isValidFileName?: boolean;
|
|
23
|
+
fileHashFromPlan?: string;
|
|
24
|
+
fileHashFromHistory?: string;
|
|
25
|
+
skippedFileHashes?: string[];
|
|
26
|
+
sequenceFromHistory?: string;
|
|
27
|
+
script?: string;
|
|
28
|
+
migrator?: (payload: TPayload, metaData?: TMetaData) => TPayload;
|
|
28
29
|
};
|
|
29
30
|
type TRecordDetails = {
|
|
30
|
-
|
|
31
|
-
|
|
32
|
-
|
|
33
|
-
|
|
34
|
-
|
|
31
|
+
id: number | string;
|
|
32
|
+
name: string;
|
|
33
|
+
created: string | Date;
|
|
34
|
+
version: string;
|
|
35
|
+
currentPlan?: TPlan;
|
|
35
36
|
};
|
|
36
37
|
type TRecordDetailsList = TRecordDetails[];
|
|
37
38
|
type TEntityColumnNames = {
|
|
38
|
-
|
|
39
|
-
|
|
40
|
-
|
|
41
|
-
|
|
42
|
-
|
|
43
|
-
|
|
44
|
-
};
|
|
45
|
-
type TRecord<T extends TEntityColumnNames = TEntityColumnNames, TData = TPayload> = {
|
|
46
|
-
[K in T['id']]: number | string;
|
|
47
|
-
} & {
|
|
48
|
-
[K in T['name']]: string;
|
|
49
|
-
} & {
|
|
50
|
-
[K in T['payload']]: TData;
|
|
51
|
-
} & (T['etag'] extends string ? {
|
|
52
|
-
[K in T['etag']]?: string;
|
|
53
|
-
} : Record<never, never>) & {
|
|
54
|
-
[K in T['version']]: string;
|
|
55
|
-
} & {
|
|
56
|
-
[K in T['created']]: string | Date;
|
|
39
|
+
id: string;
|
|
40
|
+
name: string;
|
|
41
|
+
payload: string;
|
|
42
|
+
etag?: string;
|
|
43
|
+
version: string;
|
|
44
|
+
created: string;
|
|
57
45
|
};
|
|
46
|
+
type TRecord<T extends TEntityColumnNames = TEntityColumnNames, TData = TPayload> = { [K in T['id']]: number | string } & { [K in T['name']]: string } & { [K in T['payload']]: TData } & (T['etag'] extends string ? { [K in T['etag']]?: string } : Record<never, never>) & { [K in T['version']]: string } & { [K in T['created']]: string | Date };
|
|
58
47
|
type TConfig = {
|
|
59
|
-
|
|
60
|
-
|
|
61
|
-
|
|
62
|
-
|
|
63
|
-
|
|
64
|
-
|
|
65
|
-
|
|
66
|
-
|
|
67
|
-
|
|
68
|
-
|
|
69
|
-
|
|
70
|
-
autoInitializeTable?: boolean;
|
|
48
|
+
directory: string;
|
|
49
|
+
database?: IDatabase<unknown>;
|
|
50
|
+
pgpHelpers?: IHelpers;
|
|
51
|
+
entity?: string;
|
|
52
|
+
entityTableName?: string;
|
|
53
|
+
entityColumnNames?: TEntityColumnNames;
|
|
54
|
+
version?: string;
|
|
55
|
+
printPendingFileNames?: boolean;
|
|
56
|
+
force?: boolean;
|
|
57
|
+
dry?: boolean;
|
|
58
|
+
autoInitializeTable?: boolean;
|
|
71
59
|
};
|
|
72
60
|
type TBeforeMigrateRecordPayload = {
|
|
73
|
-
|
|
74
|
-
|
|
75
|
-
|
|
61
|
+
currentRecord: TRecord;
|
|
62
|
+
transaction?: ITask<unknown>;
|
|
63
|
+
dry: boolean;
|
|
76
64
|
};
|
|
77
65
|
type TBeforeMigrateRecord = (params: TBeforeMigrateRecordPayload) => Promise<void>;
|
|
78
66
|
type TAfterMigrateRecordPayload = {
|
|
79
|
-
|
|
80
|
-
|
|
81
|
-
|
|
82
|
-
|
|
67
|
+
currentRecord: TRecord;
|
|
68
|
+
nextRecord: TRecord;
|
|
69
|
+
transaction?: ITask<unknown>;
|
|
70
|
+
dry: boolean;
|
|
83
71
|
};
|
|
84
72
|
type TAfterMigrateRecord = (params: TAfterMigrateRecordPayload) => Promise<void>;
|
|
85
73
|
type TMigrationErrorPayload = {
|
|
86
|
-
|
|
87
|
-
|
|
88
|
-
|
|
89
|
-
|
|
90
|
-
|
|
74
|
+
id: string;
|
|
75
|
+
name: string;
|
|
76
|
+
created: string | Date;
|
|
77
|
+
error: unknown;
|
|
78
|
+
stackTrace?: string;
|
|
91
79
|
};
|
|
92
80
|
type TOnMigrationErrorsPayload = {
|
|
93
|
-
|
|
94
|
-
|
|
81
|
+
migrationErrors: TMigrationErrorPayload[];
|
|
82
|
+
dry: boolean;
|
|
95
83
|
};
|
|
96
84
|
type TOnMigrationErrors = (params: TOnMigrationErrorsPayload) => Promise<void>;
|
|
97
|
-
|
|
98
|
-
|
|
99
|
-
|
|
85
|
+
//#endregion
|
|
86
|
+
//#region src/plan/plan.d.ts
|
|
87
|
+
declare const getPlannedMigrations: ({
|
|
88
|
+
config
|
|
89
|
+
}: {
|
|
90
|
+
config: TConfig;
|
|
100
91
|
}) => Promise<{
|
|
101
|
-
|
|
102
|
-
|
|
103
|
-
|
|
104
|
-
|
|
105
|
-
|
|
106
|
-
|
|
107
|
-
|
|
108
|
-
|
|
109
|
-
|
|
110
|
-
|
|
92
|
+
validatedPlan: {
|
|
93
|
+
fileHash: string;
|
|
94
|
+
fileName: string;
|
|
95
|
+
sequence: string;
|
|
96
|
+
}[];
|
|
97
|
+
plannedMigrations: TMigration[] & {
|
|
98
|
+
fileHash: string;
|
|
99
|
+
migrator: (payload: unknown, metaData?: unknown) => unknown;
|
|
100
|
+
}[];
|
|
101
|
+
nextVersion: string;
|
|
111
102
|
}>;
|
|
112
|
-
|
|
113
|
-
|
|
114
|
-
|
|
103
|
+
//#endregion
|
|
104
|
+
//#region src/plan/planned-version.d.ts
|
|
105
|
+
declare const getPlannedVersion: ({
|
|
106
|
+
config
|
|
107
|
+
}: {
|
|
108
|
+
config: any;
|
|
115
109
|
}) => Promise<string>;
|
|
116
|
-
|
|
110
|
+
//#endregion
|
|
111
|
+
//#region src/migrate/migrate.d.ts
|
|
117
112
|
/**
|
|
118
113
|
* Migrates a payload
|
|
119
114
|
*
|
|
@@ -121,45 +116,56 @@ declare const getPlannedVersion: ({ config }: {
|
|
|
121
116
|
* i) function looks up the pending migrations for you (default)
|
|
122
117
|
* ii) pass in pre-fetched pending migrators via config.pending
|
|
123
118
|
*/
|
|
124
|
-
declare const migrate: ({
|
|
125
|
-
|
|
126
|
-
|
|
127
|
-
|
|
119
|
+
declare const migrate: ({
|
|
120
|
+
payload,
|
|
121
|
+
config,
|
|
122
|
+
metaData
|
|
123
|
+
}: {
|
|
124
|
+
payload: TPayload;
|
|
125
|
+
config: TConfig;
|
|
126
|
+
metaData?: TMetaData;
|
|
128
127
|
}) => Promise<{
|
|
129
|
-
|
|
130
|
-
|
|
128
|
+
nextPayload: TPayload;
|
|
129
|
+
nextVersion: string;
|
|
131
130
|
}>;
|
|
132
|
-
|
|
131
|
+
//#endregion
|
|
132
|
+
//#region src/migrate-all/migrate-all.d.ts
|
|
133
133
|
/**
|
|
134
134
|
* Migrate all records (only use via command line interface)
|
|
135
135
|
*/
|
|
136
|
-
declare const migrateAll: ({
|
|
137
|
-
|
|
138
|
-
|
|
139
|
-
|
|
140
|
-
|
|
136
|
+
declare const migrateAll: ({
|
|
137
|
+
config,
|
|
138
|
+
beforeMigrateRecord,
|
|
139
|
+
afterMigrateRecord,
|
|
140
|
+
onMigrationErrors
|
|
141
|
+
}: {
|
|
142
|
+
config: TConfig;
|
|
143
|
+
beforeMigrateRecord: TBeforeMigrateRecord;
|
|
144
|
+
afterMigrateRecord: TAfterMigrateRecord;
|
|
145
|
+
onMigrationErrors: TOnMigrationErrors;
|
|
141
146
|
}) => Promise<void>;
|
|
142
|
-
|
|
147
|
+
//#endregion
|
|
148
|
+
//#region src/pipe/pipe.d.ts
|
|
143
149
|
/**
|
|
144
|
-
* Executes the pending migrators on a payload, returns
|
|
150
|
+
* Executes the pending migrators on a payload, returns a migrated payload
|
|
145
151
|
*
|
|
146
152
|
* Loosely based on:
|
|
147
153
|
* - Eric Elliott's pipe implementation https://medium.com/javascript-scene/reduce-composing-software-fe22f0c39a1d
|
|
148
154
|
* - lodash flow https://lodash.com/docs/4.17.15#flow
|
|
149
|
-
*
|
|
150
|
-
* Implementation includes exception handling to extend errors with the filename
|
|
151
|
-
* until native dynamic imports fix their stack trace handling (see OW-8879)
|
|
152
155
|
*/
|
|
153
156
|
declare const pipe: (migrations: TMigration[], payload: TPayload, metaData?: TMetaData) => TPayload;
|
|
154
|
-
|
|
157
|
+
//#endregion
|
|
158
|
+
//#region src/database/database.d.ts
|
|
155
159
|
declare const getVersions: (db: IDatabase<unknown>, entity: string) => Promise<any[]>;
|
|
156
|
-
|
|
160
|
+
//#endregion
|
|
161
|
+
//#region src/history/history.d.ts
|
|
157
162
|
/**
|
|
158
163
|
* Prints the version history of plan.json (for debugging)
|
|
159
164
|
*/
|
|
160
|
-
declare const printVersionHistory: ({
|
|
161
|
-
|
|
165
|
+
declare const printVersionHistory: ({
|
|
166
|
+
config
|
|
167
|
+
}: {
|
|
168
|
+
config: TConfig;
|
|
162
169
|
}) => Promise<void>;
|
|
163
|
-
|
|
164
|
-
export { createMigration, getPlannedMigrations, getPlannedVersion, getVersions, migrate, migrateAll, pipe, printVersionHistory };
|
|
165
|
-
export type { TAfterMigrateRecord, TAfterMigrateRecordPayload, TBeforeMigrateRecord, TBeforeMigrateRecordPayload, TConfig, TEntityColumnNames, TMetaData, TMigration, TMigrationErrorPayload, TOnMigrationErrors, TOnMigrationErrorsPayload, TPayload, TPlan, TPlanEntry, TRecord, TRecordDetails, TRecordDetailsList };
|
|
170
|
+
//#endregion
|
|
171
|
+
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 };
|