@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 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 { 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[] & any[];
107
- 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;
108
102
  }>;
109
-
110
- declare const getPlannedVersion: ({ config }: {
111
- config: any;
112
- }) => Promise<any>;
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: ({ payload, config, metaData, }: {
122
- payload: TPayload;
123
- config: TConfig;
124
- metaData?: TMetaData;
119
+ declare const migrate: ({
120
+ payload,
121
+ config,
122
+ metaData
123
+ }: {
124
+ payload: TPayload;
125
+ config: TConfig;
126
+ metaData?: TMetaData;
125
127
  }) => Promise<{
126
- nextPayload: TPayload;
127
- nextVersion: string;
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: ({ config, beforeMigrateRecord, afterMigrateRecord, onMigrationErrors, }: {
134
- config: TConfig;
135
- beforeMigrateRecord: TBeforeMigrateRecord;
136
- afterMigrateRecord: TAfterMigrateRecord;
137
- 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;
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 modified payload
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: ({ config }: {
158
- config: TConfig;
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 };