@oliasoft-open-source/node-json-migrator 4.6.0-beta-2 → 5.0.0

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 CHANGED
@@ -1,119 +1,114 @@
1
- import { ITask, IDatabase, IHelpers } from 'pg-promise';
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
- fileName: string;
10
- fileHash: string;
11
- sequence: string;
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
- fileName?: string;
18
- fileHash?: string;
19
- sequence?: string;
20
- isValidFileName?: boolean;
21
- fileHashFromPlan?: string;
22
- fileHashFromHistory?: string;
23
- skippedFileHashes?: string[];
24
- sequenceFromHistory?: string;
25
- script?: string;
26
- filePath?: string;
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
- id: number | string;
31
- name: string;
32
- created: string | Date;
33
- version: string;
34
- currentPlan?: TPlan;
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
- id: string;
39
- name: string;
40
- payload: string;
41
- etag?: string;
42
- version: string;
43
- created: string;
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
- directory: string;
60
- database?: IDatabase<unknown>;
61
- pgpHelpers?: IHelpers;
62
- entity?: string;
63
- entityTableName?: string;
64
- entityColumnNames?: TEntityColumnNames;
65
- version?: string;
66
- printPendingFileNames?: boolean;
67
- force?: boolean;
68
- dry?: boolean;
69
- importModule?: boolean;
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
- currentRecord: TRecord;
74
- transaction?: ITask<unknown>;
75
- dry: boolean;
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
- currentRecord: TRecord;
80
- nextRecord: TRecord;
81
- transaction?: ITask<unknown>;
82
- dry: boolean;
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
- id: string;
87
- name: string;
88
- created: string | Date;
89
- error: unknown;
90
- stackTrace?: string;
74
+ id: string;
75
+ name: string;
76
+ created: string | Date;
77
+ error: unknown;
78
+ stackTrace?: string;
91
79
  };
92
80
  type TOnMigrationErrorsPayload = {
93
- migrationErrors: TMigrationErrorPayload[];
94
- dry: boolean;
81
+ migrationErrors: TMigrationErrorPayload[];
82
+ dry: boolean;
95
83
  };
96
84
  type TOnMigrationErrors = (params: TOnMigrationErrorsPayload) => Promise<void>;
97
-
98
- declare const getPlannedMigrations: ({ config }: {
99
- config: TConfig;
85
+ //#endregion
86
+ //#region src/plan/plan.d.ts
87
+ declare const getPlannedMigrations: ({
88
+ config
89
+ }: {
90
+ config: TConfig;
100
91
  }) => Promise<{
101
- validatedPlan: {
102
- fileHash: string;
103
- fileName: string;
104
- sequence: string;
105
- }[];
106
- plannedMigrations: TMigration[] & {
107
- fileHash: string;
108
- migrator: (...args: unknown[]) => unknown;
109
- }[];
110
- nextVersion: string;
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
- declare const getPlannedVersion: ({ config }: {
114
- config: any;
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: ({ payload, config, metaData, }: {
125
- payload: TPayload;
126
- config: TConfig;
127
- metaData?: TMetaData;
119
+ declare const migrate: ({
120
+ payload,
121
+ config,
122
+ metaData
123
+ }: {
124
+ payload: TPayload;
125
+ config: TConfig;
126
+ metaData?: TMetaData;
128
127
  }) => Promise<{
129
- nextPayload: TPayload;
130
- nextVersion: string;
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: ({ config, beforeMigrateRecord, afterMigrateRecord, onMigrationErrors, }: {
137
- config: TConfig;
138
- beforeMigrateRecord: TBeforeMigrateRecord;
139
- afterMigrateRecord: TAfterMigrateRecord;
140
- onMigrationErrors: TOnMigrationErrors;
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 modified payload
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: ({ config }: {
161
- config: TConfig;
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 };