@twin.org/entity-storage-models 0.0.3-next.21 → 0.0.3-next.23
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/es/factories/schemaMigrationFactory.js +17 -0
- package/dist/es/factories/schemaMigrationFactory.js.map +1 -0
- package/dist/es/helpers/entityStorageHelper.js +42 -1
- package/dist/es/helpers/entityStorageHelper.js.map +1 -1
- package/dist/es/helpers/migrationHelper.js +102 -129
- package/dist/es/helpers/migrationHelper.js.map +1 -1
- package/dist/es/index.js +4 -1
- package/dist/es/index.js.map +1 -1
- package/dist/es/models/IResolvedMigrationStep.js +2 -0
- package/dist/es/models/IResolvedMigrationStep.js.map +1 -0
- package/dist/es/models/ISchemaMigration.js +2 -0
- package/dist/es/models/ISchemaMigration.js.map +1 -0
- package/dist/types/factories/schemaMigrationFactory.d.ts +14 -0
- package/dist/types/helpers/entityStorageHelper.d.ts +20 -1
- package/dist/types/helpers/migrationHelper.d.ts +36 -43
- package/dist/types/index.d.ts +3 -0
- package/dist/types/models/IResolvedMigrationStep.d.ts +36 -0
- package/dist/types/models/ISchemaMigration.d.ts +27 -0
- package/docs/changelog.md +14 -0
- package/docs/reference/classes/EntityStorageHelper.md +74 -0
- package/docs/reference/classes/MigrationHelper.md +62 -152
- package/docs/reference/index.md +3 -0
- package/docs/reference/interfaces/IResolvedMigrationStep.md +82 -0
- package/docs/reference/interfaces/ISchemaMigration.md +65 -0
- package/docs/reference/variables/SchemaMigrationFactory.md +13 -0
- package/locales/en.json +4 -0
- package/package.json +1 -1
|
@@ -1,10 +1,12 @@
|
|
|
1
|
-
import { type IContextIds } from "@twin.org/context";
|
|
2
1
|
import { type IEntitySchemaDiff } from "@twin.org/entity";
|
|
3
2
|
import type { IEntityStorageConnector } from "../models/IEntityStorageConnector.js";
|
|
4
3
|
import type { IEntityStorageMigrationConnector } from "../models/IEntityStorageMigrationConnector.js";
|
|
5
4
|
import type { IMigrationOptions } from "../models/IMigrationOptions.js";
|
|
5
|
+
import type { IResolvedMigrationStep } from "../models/IResolvedMigrationStep.js";
|
|
6
6
|
/**
|
|
7
|
-
* Helper class for performing schema migrations between two connectors.
|
|
7
|
+
* Helper class for performing entity schema migrations between two connectors.
|
|
8
|
+
* The chain-based API (migrateWithChain / applyEntityChain) is the single migration
|
|
9
|
+
* path: a chain of one step covers the same case as a traditional single-step migration.
|
|
8
10
|
*/
|
|
9
11
|
export declare class MigrationHelper {
|
|
10
12
|
/**
|
|
@@ -12,50 +14,41 @@ export declare class MigrationHelper {
|
|
|
12
14
|
*/
|
|
13
15
|
static readonly CLASS_NAME: string;
|
|
14
16
|
/**
|
|
15
|
-
*
|
|
16
|
-
*
|
|
17
|
-
* @param targetEntitySchemaName The name of the new entity schema.
|
|
18
|
-
* @param renames An optional list of property renames to apply during migration.
|
|
19
|
-
* @param options Options controlling migration behaviour.
|
|
20
|
-
* @param loggingComponentType An optional logging component type to use for bootstrapping and starting connectors if necessary.
|
|
21
|
-
* @returns The connector for the new schema and the number of entities successfully migrated, the sourceConnector will no longer be usable, finalConnector will be undefined if no migration was necessary.
|
|
22
|
-
*/
|
|
23
|
-
static migrate<T, U>(sourceConnector: IEntityStorageMigrationConnector<T>, targetEntitySchemaName: string, renames?: {
|
|
24
|
-
from: string;
|
|
25
|
-
to: string;
|
|
26
|
-
}[], options?: IMigrationOptions<T, U>, loggingComponentType?: string): Promise<{
|
|
27
|
-
finalConnector?: IEntityStorageConnector<U>;
|
|
28
|
-
migrated: number;
|
|
29
|
-
}>;
|
|
30
|
-
/**
|
|
31
|
-
* Generic per-partition migration loop.
|
|
32
|
-
* @param source Connector to read from (current schema, already bootstrapped).
|
|
33
|
-
* @param target Connector to write to (new schema, already bootstrapped).
|
|
34
|
-
* @param partitionContextIds The context ids to use for the migration, used for partitioning and can be used in the transform function when `options.transformEntityProperty` is provided.
|
|
35
|
-
* @param schemaDiff The schema diff.
|
|
36
|
-
* @param options Optional migration controls (batchSize, transformEntity, onProgress).
|
|
37
|
-
* @returns The number of entities successfully migrated.
|
|
38
|
-
*/
|
|
39
|
-
static migrateEntities<T = unknown, U = T>(source: IEntityStorageMigrationConnector<T>, target: IEntityStorageConnector<U>, partitionContextIds: IContextIds[], schemaDiff: IEntitySchemaDiff<T, U>, options?: IMigrationOptions<T, U>): Promise<number>;
|
|
40
|
-
/**
|
|
41
|
-
* Generic per-partition migration loop.
|
|
42
|
-
* @param source Connector to read from (current schema, already bootstrapped).
|
|
43
|
-
* @param target Connector to write to (new schema, already bootstrapped).
|
|
44
|
-
* @param partitionTotal The total number of partitions to migrate, used for progress reporting.
|
|
45
|
-
* @param partitionIndex The index of the current partition being migrated, used for progress reporting.
|
|
46
|
-
* @param schemaDiff Schema diff used to add nullable defaults and drop removed fields when `options.transformEntity` is not provided.
|
|
47
|
-
* @param options Optional migration controls (batchSize, transformEntity, onProgress).
|
|
48
|
-
* @returns The number of entities successfully migrated.
|
|
49
|
-
*/
|
|
50
|
-
static migratePartition<T = unknown, U = unknown>(source: IEntityStorageConnector<T>, target: IEntityStorageConnector<U>, partitionTotal: number, partitionIndex: number, schemaDiff: IEntitySchemaDiff<T, U>, options?: IMigrationOptions<T, U>): Promise<number>;
|
|
51
|
-
/**
|
|
52
|
-
* Applies the entity transformation for migration, using the provided options and schema diff.
|
|
17
|
+
* Applies the entity transformation for a single diff, handling added, removed, and
|
|
18
|
+
* modified properties according to the provided schema diff and optional transform hook.
|
|
53
19
|
* @param entity The entity to transform.
|
|
54
20
|
* @param schemaDiff The schema diff between the old and new schemas.
|
|
55
|
-
* @param
|
|
21
|
+
* @param transformEntityProperty Optional per-property transform hook for object/array properties.
|
|
56
22
|
* @returns The transformed entity ready to be written to the new schema.
|
|
57
|
-
* @throws GeneralError if a transformation is required for an object or array property but no
|
|
23
|
+
* @throws GeneralError if a transformation is required for an object or array property but no transformEntityProperty function is provided.
|
|
58
24
|
* @throws GeneralError if coercion of a modified property results in undefined for a non-optional target property.
|
|
59
25
|
*/
|
|
60
|
-
static applyEntityTransform<T = unknown, U = unknown>(entity: Partial<T>, schemaDiff: IEntitySchemaDiff<T, U>,
|
|
26
|
+
static applyEntityTransform<T = unknown, U = unknown>(entity: Partial<T>, schemaDiff: IEntitySchemaDiff<T, U>, transformEntityProperty?: IMigrationOptions<T, U>["transformEntityProperty"]): U;
|
|
27
|
+
/**
|
|
28
|
+
* Transforms a single entity through an ordered chain of fully-resolved migration steps.
|
|
29
|
+
* For each step the method diffs fromProperties against toProperties, then applies
|
|
30
|
+
* applyEntityTransform. Each step's output feeds the next step's input so that
|
|
31
|
+
* per-step transformEntityProperty hooks are honoured throughout the chain.
|
|
32
|
+
* @param entity The entity to transform (at the shape described by steps[0].fromProperties).
|
|
33
|
+
* @param steps Ordered, fully-resolved migration steps from stored version to current version.
|
|
34
|
+
* Each step's fromProperties and toProperties are resolved by the caller before invocation.
|
|
35
|
+
* @returns The entity transformed to the shape described by steps[last].toProperties.
|
|
36
|
+
*/
|
|
37
|
+
static applyEntityChain(entity: unknown, steps: IResolvedMigrationStep[]): unknown;
|
|
38
|
+
/**
|
|
39
|
+
* Performs a chain migration in a single connector swap, regardless of how many version
|
|
40
|
+
* steps the chain spans. Creates one target connector, reads all source entities, applies
|
|
41
|
+
* applyEntityChain to each, writes them to the target, then finalizes the migration.
|
|
42
|
+
* A chain of one step is equivalent to a traditional single-step migration.
|
|
43
|
+
* @param sourceConnector The connector holding data at the stored schema version.
|
|
44
|
+
* @param targetSchemaName The schema name for the current version (used to create the target connector).
|
|
45
|
+
* @param steps Ordered, fully-resolved migration steps from stored to current version.
|
|
46
|
+
* @param loggingComponentType An optional logging component type for connector startup.
|
|
47
|
+
* @param batchSize Number of entities to read and write per batch. Defaults to 100.
|
|
48
|
+
* @returns The finalized connector and the count of migrated entities.
|
|
49
|
+
*/
|
|
50
|
+
static migrateWithChain(sourceConnector: IEntityStorageMigrationConnector, targetSchemaName: string, steps: IResolvedMigrationStep[], loggingComponentType?: string, batchSize?: number): Promise<{
|
|
51
|
+
finalConnector: IEntityStorageConnector;
|
|
52
|
+
migrated: number;
|
|
53
|
+
}>;
|
|
61
54
|
}
|
package/dist/types/index.d.ts
CHANGED
|
@@ -1,4 +1,5 @@
|
|
|
1
1
|
export * from "./factories/entityStorageConnectorFactory.js";
|
|
2
|
+
export * from "./factories/schemaMigrationFactory.js";
|
|
2
3
|
export * from "./helpers/entityStorageHelper.js";
|
|
3
4
|
export * from "./helpers/migrationHelper.js";
|
|
4
5
|
export * from "./models/api/IEntityStorageCountRequest.js";
|
|
@@ -16,3 +17,5 @@ export * from "./models/IEntityStorageComponent.js";
|
|
|
16
17
|
export * from "./models/IEntityStorageConnector.js";
|
|
17
18
|
export * from "./models/IEntityStorageMigrationConnector.js";
|
|
18
19
|
export * from "./models/IMigrationOptions.js";
|
|
20
|
+
export * from "./models/IResolvedMigrationStep.js";
|
|
21
|
+
export * from "./models/ISchemaMigration.js";
|
|
@@ -0,0 +1,36 @@
|
|
|
1
|
+
import type { IEntitySchemaProperty } from "@twin.org/entity";
|
|
2
|
+
import type { IMigrationOptions } from "./IMigrationOptions.js";
|
|
3
|
+
/**
|
|
4
|
+
* A fully-resolved single migration step used by MigrationHelper.
|
|
5
|
+
* The SchemaVersionService builds these by looking up versioned schema classes
|
|
6
|
+
* from EntitySchemaFactory (e.g. MyEntityV0, MyEntityV1) before invoking the helper,
|
|
7
|
+
* keeping factory knowledge out of the helper itself.
|
|
8
|
+
* @template T The entity type. Defaults to `unknown`. Use a concrete entity type
|
|
9
|
+
* when the step's source and target schemas are known at the call site.
|
|
10
|
+
*/
|
|
11
|
+
export interface IResolvedMigrationStep<T = unknown, U = unknown> {
|
|
12
|
+
/**
|
|
13
|
+
* The property list of the entity at the start of this step (the "old" shape).
|
|
14
|
+
* Sourced from the versioned schema class registered in EntitySchemaFactory,
|
|
15
|
+
* e.g. EntitySchemaFactory.get("MyEntityV0").properties.
|
|
16
|
+
*/
|
|
17
|
+
fromProperties: IEntitySchemaProperty<T>[];
|
|
18
|
+
/**
|
|
19
|
+
* The property list of the entity at the end of this step (the "new" shape).
|
|
20
|
+
* For the final step this is the live current schema's properties.
|
|
21
|
+
*/
|
|
22
|
+
toProperties: IEntitySchemaProperty<U>[];
|
|
23
|
+
/**
|
|
24
|
+
* Optional property renames for this step, forwarded to EntitySchemaDiffHelper.diff.
|
|
25
|
+
*/
|
|
26
|
+
renames?: {
|
|
27
|
+
from: string;
|
|
28
|
+
to: string;
|
|
29
|
+
}[];
|
|
30
|
+
/**
|
|
31
|
+
* Optional per-property transformer for object/array properties that the structural
|
|
32
|
+
* diff cannot handle automatically. Sourced from an ISchemaMigration override when
|
|
33
|
+
* one is registered in SchemaMigrationFactory for this step.
|
|
34
|
+
*/
|
|
35
|
+
transformEntityProperty?: IMigrationOptions<T, U>["transformEntityProperty"];
|
|
36
|
+
}
|
|
@@ -0,0 +1,27 @@
|
|
|
1
|
+
import type { IMigrationOptions } from "./IMigrationOptions.js";
|
|
2
|
+
/**
|
|
3
|
+
* Optional per-step override for a single version-to-version migration.
|
|
4
|
+
* Only register an entry in SchemaMigrationFactory when a step requires property
|
|
5
|
+
* renames or a custom object/array transform. For purely structural changes
|
|
6
|
+
* (add/remove/type-change fields) no entry is needed — the runner diffs the two
|
|
7
|
+
* versioned schema classes (e.g. MyEntityV0 vs MyEntityV1) from EntitySchemaFactory
|
|
8
|
+
* automatically.
|
|
9
|
+
*
|
|
10
|
+
* Register under the key "<BaseSchemaName>_<fromVersion>_<toVersion>"
|
|
11
|
+
* e.g. "MyEntity_0_1" for the step that migrates from version 0 to version 1.
|
|
12
|
+
* The key itself encodes the version pair; no version field is needed on the object.
|
|
13
|
+
*/
|
|
14
|
+
export interface ISchemaMigration<T = unknown, U = unknown> {
|
|
15
|
+
/**
|
|
16
|
+
* Optional property renames to apply during this step.
|
|
17
|
+
*/
|
|
18
|
+
renames?: {
|
|
19
|
+
from: string;
|
|
20
|
+
to: string;
|
|
21
|
+
}[];
|
|
22
|
+
/**
|
|
23
|
+
* Optional per-property transformer for object/array properties that cannot be
|
|
24
|
+
* automatically coerced. T is the source entity type, U is the target entity type.
|
|
25
|
+
*/
|
|
26
|
+
transformEntityProperty?: IMigrationOptions<T, U>["transformEntityProperty"];
|
|
27
|
+
}
|
package/docs/changelog.md
CHANGED
|
@@ -1,5 +1,19 @@
|
|
|
1
1
|
# Changelog
|
|
2
2
|
|
|
3
|
+
## [0.0.3-next.23](https://github.com/iotaledger/twin-entity-storage/compare/entity-storage-models-v0.0.3-next.22...entity-storage-models-v0.0.3-next.23) (2026-06-08)
|
|
4
|
+
|
|
5
|
+
|
|
6
|
+
### Features
|
|
7
|
+
|
|
8
|
+
* entity storage conditions ([#115](https://github.com/iotaledger/twin-entity-storage/issues/115)) ([7a53884](https://github.com/iotaledger/twin-entity-storage/commit/7a53884f6acb856d77733e4e0f23ec1c00b74cb4))
|
|
9
|
+
|
|
10
|
+
## [0.0.3-next.22](https://github.com/iotaledger/twin-entity-storage/compare/entity-storage-models-v0.0.3-next.21...entity-storage-models-v0.0.3-next.22) (2026-06-08)
|
|
11
|
+
|
|
12
|
+
|
|
13
|
+
### Features
|
|
14
|
+
|
|
15
|
+
* add ISchemaMigration chain, SchemaVersionMigrator runner and version store ([#110](https://github.com/iotaledger/twin-entity-storage/issues/110)) ([2dac924](https://github.com/iotaledger/twin-entity-storage/commit/2dac9244a752cb58304d1649ff03c3a2469783dd))
|
|
16
|
+
|
|
3
17
|
## [0.0.3-next.21](https://github.com/iotaledger/twin-entity-storage/compare/entity-storage-models-v0.0.3-next.20...entity-storage-models-v0.0.3-next.21) (2026-06-01)
|
|
4
18
|
|
|
5
19
|
|
|
@@ -107,6 +107,80 @@ The entity with undefined and null values handled.
|
|
|
107
107
|
|
|
108
108
|
***
|
|
109
109
|
|
|
110
|
+
### validateSortProperties() {#validatesortproperties}
|
|
111
|
+
|
|
112
|
+
> `static` **validateSortProperties**\<`T`\>(`schema`, `sortProperties?`): `void`
|
|
113
|
+
|
|
114
|
+
Validate that every sort property in the list is indexed in the schema (isPrimary, isSecondary,
|
|
115
|
+
or has a default sortDirection), throwing sortNotIndexed for the first violation found.
|
|
116
|
+
|
|
117
|
+
#### Type Parameters
|
|
118
|
+
|
|
119
|
+
##### T
|
|
120
|
+
|
|
121
|
+
`T`
|
|
122
|
+
|
|
123
|
+
#### Parameters
|
|
124
|
+
|
|
125
|
+
##### schema
|
|
126
|
+
|
|
127
|
+
`IEntitySchema`\<`T`\>
|
|
128
|
+
|
|
129
|
+
The entity schema to validate against.
|
|
130
|
+
|
|
131
|
+
##### sortProperties?
|
|
132
|
+
|
|
133
|
+
`object`[]
|
|
134
|
+
|
|
135
|
+
The sort properties to check.
|
|
136
|
+
|
|
137
|
+
#### Returns
|
|
138
|
+
|
|
139
|
+
`void`
|
|
140
|
+
|
|
141
|
+
#### Throws
|
|
142
|
+
|
|
143
|
+
GeneralError If a sort property is not indexed in the schema.
|
|
144
|
+
|
|
145
|
+
***
|
|
146
|
+
|
|
147
|
+
### validateProperties() {#validateproperties}
|
|
148
|
+
|
|
149
|
+
> `static` **validateProperties**\<`T`\>(`schema`, `properties?`): `void`
|
|
150
|
+
|
|
151
|
+
Validate that every property in the list exists in the schema, throwing propertyNotInSchema
|
|
152
|
+
for the first property that is not found.
|
|
153
|
+
|
|
154
|
+
#### Type Parameters
|
|
155
|
+
|
|
156
|
+
##### T
|
|
157
|
+
|
|
158
|
+
`T`
|
|
159
|
+
|
|
160
|
+
#### Parameters
|
|
161
|
+
|
|
162
|
+
##### schema
|
|
163
|
+
|
|
164
|
+
`IEntitySchema`\<`T`\>
|
|
165
|
+
|
|
166
|
+
The entity schema to validate against.
|
|
167
|
+
|
|
168
|
+
##### properties?
|
|
169
|
+
|
|
170
|
+
keyof `T`[]
|
|
171
|
+
|
|
172
|
+
The properties to check.
|
|
173
|
+
|
|
174
|
+
#### Returns
|
|
175
|
+
|
|
176
|
+
`void`
|
|
177
|
+
|
|
178
|
+
#### Throws
|
|
179
|
+
|
|
180
|
+
GeneralError If a property does not exist in the schema.
|
|
181
|
+
|
|
182
|
+
***
|
|
183
|
+
|
|
110
184
|
### normalizeConditionValues() {#normalizeconditionvalues}
|
|
111
185
|
|
|
112
186
|
> `static` **normalizeConditionValues**\<`T`\>(`condition`): `EntityCondition`\<`T`\>
|
|
@@ -1,6 +1,8 @@
|
|
|
1
1
|
# Class: MigrationHelper
|
|
2
2
|
|
|
3
|
-
Helper class for performing schema migrations between two connectors.
|
|
3
|
+
Helper class for performing entity schema migrations between two connectors.
|
|
4
|
+
The chain-based API (migrateWithChain / applyEntityChain) is the single migration
|
|
5
|
+
path: a chain of one step covers the same case as a traditional single-step migration.
|
|
4
6
|
|
|
5
7
|
## Constructors
|
|
6
8
|
|
|
@@ -22,67 +24,12 @@ Runtime name for the class.
|
|
|
22
24
|
|
|
23
25
|
## Methods
|
|
24
26
|
|
|
25
|
-
###
|
|
26
|
-
|
|
27
|
-
> `static` **migrate**\<`T`, `U`\>(`sourceConnector`, `targetEntitySchemaName`, `renames?`, `options?`, `loggingComponentType?`): `Promise`\<\{ `finalConnector?`: [`IEntityStorageConnector`](../interfaces/IEntityStorageConnector.md)\<`U`\>; `migrated`: `number`; \}\>
|
|
28
|
-
|
|
29
|
-
Performs a migration between two connectors, using the provided options and schema diff to control the migration behaviour.
|
|
30
|
-
|
|
31
|
-
#### Type Parameters
|
|
32
|
-
|
|
33
|
-
##### T
|
|
34
|
-
|
|
35
|
-
`T`
|
|
36
|
-
|
|
37
|
-
##### U
|
|
38
|
-
|
|
39
|
-
`U`
|
|
40
|
-
|
|
41
|
-
#### Parameters
|
|
42
|
-
|
|
43
|
-
##### sourceConnector
|
|
44
|
-
|
|
45
|
-
[`IEntityStorageMigrationConnector`](../interfaces/IEntityStorageMigrationConnector.md)\<`T`\>
|
|
46
|
-
|
|
47
|
-
The connector to migrate from to allow the migration helper to create the new connector and finalize the migration.
|
|
48
|
-
|
|
49
|
-
##### targetEntitySchemaName
|
|
50
|
-
|
|
51
|
-
`string`
|
|
52
|
-
|
|
53
|
-
The name of the new entity schema.
|
|
54
|
-
|
|
55
|
-
##### renames?
|
|
56
|
-
|
|
57
|
-
`object`[]
|
|
58
|
-
|
|
59
|
-
An optional list of property renames to apply during migration.
|
|
60
|
-
|
|
61
|
-
##### options?
|
|
62
|
-
|
|
63
|
-
[`IMigrationOptions`](../interfaces/IMigrationOptions.md)\<`T`, `U`\>
|
|
64
|
-
|
|
65
|
-
Options controlling migration behaviour.
|
|
66
|
-
|
|
67
|
-
##### loggingComponentType?
|
|
68
|
-
|
|
69
|
-
`string`
|
|
70
|
-
|
|
71
|
-
An optional logging component type to use for bootstrapping and starting connectors if necessary.
|
|
72
|
-
|
|
73
|
-
#### Returns
|
|
74
|
-
|
|
75
|
-
`Promise`\<\{ `finalConnector?`: [`IEntityStorageConnector`](../interfaces/IEntityStorageConnector.md)\<`U`\>; `migrated`: `number`; \}\>
|
|
76
|
-
|
|
77
|
-
The connector for the new schema and the number of entities successfully migrated, the sourceConnector will no longer be usable, finalConnector will be undefined if no migration was necessary.
|
|
78
|
-
|
|
79
|
-
***
|
|
80
|
-
|
|
81
|
-
### migrateEntities() {#migrateentities}
|
|
27
|
+
### applyEntityTransform() {#applyentitytransform}
|
|
82
28
|
|
|
83
|
-
> `static` **
|
|
29
|
+
> `static` **applyEntityTransform**\<`T`, `U`\>(`entity`, `schemaDiff`, `transformEntityProperty?`): `U`
|
|
84
30
|
|
|
85
|
-
|
|
31
|
+
Applies the entity transformation for a single diff, handling added, removed, and
|
|
32
|
+
modified properties according to the provided schema diff and optional transform hook.
|
|
86
33
|
|
|
87
34
|
#### Type Parameters
|
|
88
35
|
|
|
@@ -92,156 +39,119 @@ Generic per-partition migration loop.
|
|
|
92
39
|
|
|
93
40
|
##### U
|
|
94
41
|
|
|
95
|
-
`U` = `
|
|
42
|
+
`U` = `unknown`
|
|
96
43
|
|
|
97
44
|
#### Parameters
|
|
98
45
|
|
|
99
|
-
#####
|
|
100
|
-
|
|
101
|
-
[`IEntityStorageMigrationConnector`](../interfaces/IEntityStorageMigrationConnector.md)\<`T`\>
|
|
102
|
-
|
|
103
|
-
Connector to read from (current schema, already bootstrapped).
|
|
104
|
-
|
|
105
|
-
##### target
|
|
106
|
-
|
|
107
|
-
[`IEntityStorageConnector`](../interfaces/IEntityStorageConnector.md)\<`U`\>
|
|
108
|
-
|
|
109
|
-
Connector to write to (new schema, already bootstrapped).
|
|
110
|
-
|
|
111
|
-
##### partitionContextIds
|
|
46
|
+
##### entity
|
|
112
47
|
|
|
113
|
-
`
|
|
48
|
+
`Partial`\<`T`\>
|
|
114
49
|
|
|
115
|
-
The
|
|
50
|
+
The entity to transform.
|
|
116
51
|
|
|
117
52
|
##### schemaDiff
|
|
118
53
|
|
|
119
54
|
`IEntitySchemaDiff`\<`T`, `U`\>
|
|
120
55
|
|
|
121
|
-
The schema diff.
|
|
56
|
+
The schema diff between the old and new schemas.
|
|
122
57
|
|
|
123
|
-
#####
|
|
58
|
+
##### transformEntityProperty?
|
|
124
59
|
|
|
125
|
-
|
|
60
|
+
(`schema1Property`, `schemaProperty2`, `value`) => `unknown`
|
|
126
61
|
|
|
127
|
-
Optional
|
|
62
|
+
Optional per-property transform hook for object/array properties.
|
|
128
63
|
|
|
129
64
|
#### Returns
|
|
130
65
|
|
|
131
|
-
`
|
|
132
|
-
|
|
133
|
-
The number of entities successfully migrated.
|
|
66
|
+
`U`
|
|
134
67
|
|
|
135
|
-
|
|
68
|
+
The transformed entity ready to be written to the new schema.
|
|
136
69
|
|
|
137
|
-
|
|
70
|
+
#### Throws
|
|
138
71
|
|
|
139
|
-
|
|
72
|
+
GeneralError if a transformation is required for an object or array property but no transformEntityProperty function is provided.
|
|
140
73
|
|
|
141
|
-
|
|
74
|
+
#### Throws
|
|
142
75
|
|
|
143
|
-
|
|
76
|
+
GeneralError if coercion of a modified property results in undefined for a non-optional target property.
|
|
144
77
|
|
|
145
|
-
|
|
78
|
+
***
|
|
146
79
|
|
|
147
|
-
|
|
80
|
+
### applyEntityChain() {#applyentitychain}
|
|
148
81
|
|
|
149
|
-
|
|
82
|
+
> `static` **applyEntityChain**(`entity`, `steps`): `unknown`
|
|
150
83
|
|
|
151
|
-
|
|
84
|
+
Transforms a single entity through an ordered chain of fully-resolved migration steps.
|
|
85
|
+
For each step the method diffs fromProperties against toProperties, then applies
|
|
86
|
+
applyEntityTransform. Each step's output feeds the next step's input so that
|
|
87
|
+
per-step transformEntityProperty hooks are honoured throughout the chain.
|
|
152
88
|
|
|
153
89
|
#### Parameters
|
|
154
90
|
|
|
155
|
-
#####
|
|
156
|
-
|
|
157
|
-
[`IEntityStorageConnector`](../interfaces/IEntityStorageConnector.md)\<`T`\>
|
|
158
|
-
|
|
159
|
-
Connector to read from (current schema, already bootstrapped).
|
|
160
|
-
|
|
161
|
-
##### target
|
|
162
|
-
|
|
163
|
-
[`IEntityStorageConnector`](../interfaces/IEntityStorageConnector.md)\<`U`\>
|
|
164
|
-
|
|
165
|
-
Connector to write to (new schema, already bootstrapped).
|
|
166
|
-
|
|
167
|
-
##### partitionTotal
|
|
168
|
-
|
|
169
|
-
`number`
|
|
170
|
-
|
|
171
|
-
The total number of partitions to migrate, used for progress reporting.
|
|
172
|
-
|
|
173
|
-
##### partitionIndex
|
|
174
|
-
|
|
175
|
-
`number`
|
|
176
|
-
|
|
177
|
-
The index of the current partition being migrated, used for progress reporting.
|
|
178
|
-
|
|
179
|
-
##### schemaDiff
|
|
91
|
+
##### entity
|
|
180
92
|
|
|
181
|
-
`
|
|
93
|
+
`unknown`
|
|
182
94
|
|
|
183
|
-
|
|
95
|
+
The entity to transform (at the shape described by steps[0].fromProperties).
|
|
184
96
|
|
|
185
|
-
#####
|
|
97
|
+
##### steps
|
|
186
98
|
|
|
187
|
-
[`
|
|
99
|
+
[`IResolvedMigrationStep`](../interfaces/IResolvedMigrationStep.md)\<`unknown`, `unknown`\>[]
|
|
188
100
|
|
|
189
|
-
|
|
101
|
+
Ordered, fully-resolved migration steps from stored version to current version.
|
|
102
|
+
Each step's fromProperties and toProperties are resolved by the caller before invocation.
|
|
190
103
|
|
|
191
104
|
#### Returns
|
|
192
105
|
|
|
193
|
-
`
|
|
106
|
+
`unknown`
|
|
194
107
|
|
|
195
|
-
The
|
|
108
|
+
The entity transformed to the shape described by steps[last].toProperties.
|
|
196
109
|
|
|
197
110
|
***
|
|
198
111
|
|
|
199
|
-
###
|
|
112
|
+
### migrateWithChain() {#migratewithchain}
|
|
200
113
|
|
|
201
|
-
> `static` **
|
|
114
|
+
> `static` **migrateWithChain**(`sourceConnector`, `targetSchemaName`, `steps`, `loggingComponentType?`, `batchSize?`): `Promise`\<\{ `finalConnector`: [`IEntityStorageConnector`](../interfaces/IEntityStorageConnector.md); `migrated`: `number`; \}\>
|
|
202
115
|
|
|
203
|
-
|
|
116
|
+
Performs a chain migration in a single connector swap, regardless of how many version
|
|
117
|
+
steps the chain spans. Creates one target connector, reads all source entities, applies
|
|
118
|
+
applyEntityChain to each, writes them to the target, then finalizes the migration.
|
|
119
|
+
A chain of one step is equivalent to a traditional single-step migration.
|
|
204
120
|
|
|
205
|
-
####
|
|
206
|
-
|
|
207
|
-
##### T
|
|
208
|
-
|
|
209
|
-
`T` = `unknown`
|
|
210
|
-
|
|
211
|
-
##### U
|
|
121
|
+
#### Parameters
|
|
212
122
|
|
|
213
|
-
|
|
123
|
+
##### sourceConnector
|
|
214
124
|
|
|
215
|
-
|
|
125
|
+
[`IEntityStorageMigrationConnector`](../interfaces/IEntityStorageMigrationConnector.md)
|
|
216
126
|
|
|
217
|
-
|
|
127
|
+
The connector holding data at the stored schema version.
|
|
218
128
|
|
|
219
|
-
|
|
129
|
+
##### targetSchemaName
|
|
220
130
|
|
|
221
|
-
|
|
131
|
+
`string`
|
|
222
132
|
|
|
223
|
-
|
|
133
|
+
The schema name for the current version (used to create the target connector).
|
|
224
134
|
|
|
225
|
-
|
|
135
|
+
##### steps
|
|
226
136
|
|
|
227
|
-
|
|
137
|
+
[`IResolvedMigrationStep`](../interfaces/IResolvedMigrationStep.md)\<`unknown`, `unknown`\>[]
|
|
228
138
|
|
|
229
|
-
|
|
139
|
+
Ordered, fully-resolved migration steps from stored to current version.
|
|
230
140
|
|
|
231
|
-
|
|
141
|
+
##### loggingComponentType?
|
|
232
142
|
|
|
233
|
-
|
|
143
|
+
`string`
|
|
234
144
|
|
|
235
|
-
|
|
145
|
+
An optional logging component type for connector startup.
|
|
236
146
|
|
|
237
|
-
|
|
147
|
+
##### batchSize?
|
|
238
148
|
|
|
239
|
-
|
|
149
|
+
`number` = `100`
|
|
240
150
|
|
|
241
|
-
|
|
151
|
+
Number of entities to read and write per batch. Defaults to 100.
|
|
242
152
|
|
|
243
|
-
|
|
153
|
+
#### Returns
|
|
244
154
|
|
|
245
|
-
|
|
155
|
+
`Promise`\<\{ `finalConnector`: [`IEntityStorageConnector`](../interfaces/IEntityStorageConnector.md); `migrated`: `number`; \}\>
|
|
246
156
|
|
|
247
|
-
|
|
157
|
+
The finalized connector and the count of migrated entities.
|
package/docs/reference/index.md
CHANGED
|
@@ -11,6 +11,8 @@
|
|
|
11
11
|
- [IEntityStorageConnector](interfaces/IEntityStorageConnector.md)
|
|
12
12
|
- [IEntityStorageMigrationConnector](interfaces/IEntityStorageMigrationConnector.md)
|
|
13
13
|
- [IMigrationOptions](interfaces/IMigrationOptions.md)
|
|
14
|
+
- [IResolvedMigrationStep](interfaces/IResolvedMigrationStep.md)
|
|
15
|
+
- [ISchemaMigration](interfaces/ISchemaMigration.md)
|
|
14
16
|
- [IEntityStorageCountRequest](interfaces/IEntityStorageCountRequest.md)
|
|
15
17
|
- [IEntityStorageCountResponse](interfaces/IEntityStorageCountResponse.md)
|
|
16
18
|
- [IEntityStorageEmptyRequest](interfaces/IEntityStorageEmptyRequest.md)
|
|
@@ -26,3 +28,4 @@
|
|
|
26
28
|
## Variables
|
|
27
29
|
|
|
28
30
|
- [EntityStorageConnectorFactory](variables/EntityStorageConnectorFactory.md)
|
|
31
|
+
- [SchemaMigrationFactory](variables/SchemaMigrationFactory.md)
|
|
@@ -0,0 +1,82 @@
|
|
|
1
|
+
# Interface: IResolvedMigrationStep\<T, U\>
|
|
2
|
+
|
|
3
|
+
A fully-resolved single migration step used by MigrationHelper.
|
|
4
|
+
The SchemaVersionService builds these by looking up versioned schema classes
|
|
5
|
+
from EntitySchemaFactory (e.g. MyEntityV0, MyEntityV1) before invoking the helper,
|
|
6
|
+
keeping factory knowledge out of the helper itself.
|
|
7
|
+
|
|
8
|
+
## Type Parameters
|
|
9
|
+
|
|
10
|
+
### T
|
|
11
|
+
|
|
12
|
+
`T` = `unknown`
|
|
13
|
+
|
|
14
|
+
The entity type. Defaults to `unknown`. Use a concrete entity type
|
|
15
|
+
when the step's source and target schemas are known at the call site.
|
|
16
|
+
|
|
17
|
+
### U
|
|
18
|
+
|
|
19
|
+
`U` = `unknown`
|
|
20
|
+
|
|
21
|
+
## Properties
|
|
22
|
+
|
|
23
|
+
### fromProperties {#fromproperties}
|
|
24
|
+
|
|
25
|
+
> **fromProperties**: `IEntitySchemaProperty`\<`T`\>[]
|
|
26
|
+
|
|
27
|
+
The property list of the entity at the start of this step (the "old" shape).
|
|
28
|
+
Sourced from the versioned schema class registered in EntitySchemaFactory,
|
|
29
|
+
e.g. EntitySchemaFactory.get("MyEntityV0").properties.
|
|
30
|
+
|
|
31
|
+
***
|
|
32
|
+
|
|
33
|
+
### toProperties {#toproperties}
|
|
34
|
+
|
|
35
|
+
> **toProperties**: `IEntitySchemaProperty`\<`U`\>[]
|
|
36
|
+
|
|
37
|
+
The property list of the entity at the end of this step (the "new" shape).
|
|
38
|
+
For the final step this is the live current schema's properties.
|
|
39
|
+
|
|
40
|
+
***
|
|
41
|
+
|
|
42
|
+
### renames? {#renames}
|
|
43
|
+
|
|
44
|
+
> `optional` **renames?**: `object`[]
|
|
45
|
+
|
|
46
|
+
Optional property renames for this step, forwarded to EntitySchemaDiffHelper.diff.
|
|
47
|
+
|
|
48
|
+
#### from
|
|
49
|
+
|
|
50
|
+
> **from**: `string`
|
|
51
|
+
|
|
52
|
+
#### to
|
|
53
|
+
|
|
54
|
+
> **to**: `string`
|
|
55
|
+
|
|
56
|
+
***
|
|
57
|
+
|
|
58
|
+
### transformEntityProperty? {#transformentityproperty}
|
|
59
|
+
|
|
60
|
+
> `optional` **transformEntityProperty?**: (`schema1Property`, `schemaProperty2`, `value`) => `unknown`
|
|
61
|
+
|
|
62
|
+
Optional per-property transformer for object/array properties that the structural
|
|
63
|
+
diff cannot handle automatically. Sourced from an ISchemaMigration override when
|
|
64
|
+
one is registered in SchemaMigrationFactory for this step.
|
|
65
|
+
|
|
66
|
+
#### Parameters
|
|
67
|
+
|
|
68
|
+
##### schema1Property
|
|
69
|
+
|
|
70
|
+
`IEntitySchemaProperty`\<`T`\>
|
|
71
|
+
|
|
72
|
+
##### schemaProperty2
|
|
73
|
+
|
|
74
|
+
`IEntitySchemaProperty`\<`U`\>
|
|
75
|
+
|
|
76
|
+
##### value
|
|
77
|
+
|
|
78
|
+
`unknown`
|
|
79
|
+
|
|
80
|
+
#### Returns
|
|
81
|
+
|
|
82
|
+
`unknown`
|