@oliasoft-open-source/node-json-migrator 4.6.0-beta-1 → 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/README.md +1 -1
- package/dist/index.d.mts +114 -105
- package/dist/index.mjs +4610 -7978
- package/package.json +22 -27
- package/dist/immer-CjiV9AMA.mjs +0 -1576
- package/dist/immer-ZZLkDBss.cjs +0 -1598
- package/dist/index.cjs +0 -8329
- package/dist/index.d.cts +0 -162
package/README.md
CHANGED
|
@@ -55,7 +55,7 @@ For example, after editing, the scripts might look like this:
|
|
|
55
55
|
**json-migrations/add-panda/add-panda.js** (adds a property to the payload)
|
|
56
56
|
|
|
57
57
|
```javascript
|
|
58
|
-
import produce from 'immer';
|
|
58
|
+
import { produce } from 'immer';
|
|
59
59
|
|
|
60
60
|
export default (payload) = produce(state, (draft) => {
|
|
61
61
|
draft.panda = 'Elliot';
|
package/dist/index.d.mts
CHANGED
|
@@ -1,116 +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
|
-
|
|
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;
|
|
108
102
|
}>;
|
|
109
|
-
|
|
110
|
-
|
|
111
|
-
|
|
112
|
-
|
|
113
|
-
|
|
103
|
+
//#endregion
|
|
104
|
+
//#region src/plan/planned-version.d.ts
|
|
105
|
+
declare const getPlannedVersion: ({
|
|
106
|
+
config
|
|
107
|
+
}: {
|
|
108
|
+
config: any;
|
|
109
|
+
}) => Promise<string>;
|
|
110
|
+
//#endregion
|
|
111
|
+
//#region src/migrate/migrate.d.ts
|
|
114
112
|
/**
|
|
115
113
|
* Migrates a payload
|
|
116
114
|
*
|
|
@@ -118,45 +116,56 @@ declare const getPlannedVersion: ({ config }: {
|
|
|
118
116
|
* i) function looks up the pending migrations for you (default)
|
|
119
117
|
* ii) pass in pre-fetched pending migrators via config.pending
|
|
120
118
|
*/
|
|
121
|
-
declare const migrate: ({
|
|
122
|
-
|
|
123
|
-
|
|
124
|
-
|
|
119
|
+
declare const migrate: ({
|
|
120
|
+
payload,
|
|
121
|
+
config,
|
|
122
|
+
metaData
|
|
123
|
+
}: {
|
|
124
|
+
payload: TPayload;
|
|
125
|
+
config: TConfig;
|
|
126
|
+
metaData?: TMetaData;
|
|
125
127
|
}) => Promise<{
|
|
126
|
-
|
|
127
|
-
|
|
128
|
+
nextPayload: TPayload;
|
|
129
|
+
nextVersion: string;
|
|
128
130
|
}>;
|
|
129
|
-
|
|
131
|
+
//#endregion
|
|
132
|
+
//#region src/migrate-all/migrate-all.d.ts
|
|
130
133
|
/**
|
|
131
134
|
* Migrate all records (only use via command line interface)
|
|
132
135
|
*/
|
|
133
|
-
declare const migrateAll: ({
|
|
134
|
-
|
|
135
|
-
|
|
136
|
-
|
|
137
|
-
|
|
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;
|
|
138
146
|
}) => Promise<void>;
|
|
139
|
-
|
|
147
|
+
//#endregion
|
|
148
|
+
//#region src/pipe/pipe.d.ts
|
|
140
149
|
/**
|
|
141
|
-
* Executes the pending migrators on a payload, returns
|
|
150
|
+
* Executes the pending migrators on a payload, returns a migrated payload
|
|
142
151
|
*
|
|
143
152
|
* Loosely based on:
|
|
144
153
|
* - Eric Elliott's pipe implementation https://medium.com/javascript-scene/reduce-composing-software-fe22f0c39a1d
|
|
145
154
|
* - lodash flow https://lodash.com/docs/4.17.15#flow
|
|
146
|
-
*
|
|
147
|
-
* Implementation includes exception handling to extend errors with the filename
|
|
148
|
-
* until native dynamic imports fix their stack trace handling (see OW-8879)
|
|
149
155
|
*/
|
|
150
156
|
declare const pipe: (migrations: TMigration[], payload: TPayload, metaData?: TMetaData) => TPayload;
|
|
151
|
-
|
|
157
|
+
//#endregion
|
|
158
|
+
//#region src/database/database.d.ts
|
|
152
159
|
declare const getVersions: (db: IDatabase<unknown>, entity: string) => Promise<any[]>;
|
|
153
|
-
|
|
160
|
+
//#endregion
|
|
161
|
+
//#region src/history/history.d.ts
|
|
154
162
|
/**
|
|
155
163
|
* Prints the version history of plan.json (for debugging)
|
|
156
164
|
*/
|
|
157
|
-
declare const printVersionHistory: ({
|
|
158
|
-
|
|
165
|
+
declare const printVersionHistory: ({
|
|
166
|
+
config
|
|
167
|
+
}: {
|
|
168
|
+
config: TConfig;
|
|
159
169
|
}) => Promise<void>;
|
|
160
|
-
|
|
161
|
-
export { createMigration, getPlannedMigrations, getPlannedVersion, getVersions, migrate, migrateAll, pipe, printVersionHistory };
|
|
162
|
-
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 };
|