@twin.org/entity-storage-models 0.0.3-next.24 → 0.0.3-next.26
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/helpers/migrationHelper.js +125 -86
- package/dist/es/helpers/migrationHelper.js.map +1 -1
- package/dist/es/index.js +1 -3
- package/dist/es/index.js.map +1 -1
- package/dist/es/models/IEntityStorageMigrationConnector.js.map +1 -1
- package/dist/es/models/IMigrationOptions.js.map +1 -1
- package/dist/es/models/IResolvedMigrationStep.js.map +1 -1
- package/dist/es/models/ISchemaMigration.js.map +1 -1
- package/dist/es/models/entityPropertyTransformer.js +2 -0
- package/dist/es/models/entityPropertyTransformer.js.map +1 -0
- package/dist/types/helpers/migrationHelper.d.ts +34 -26
- package/dist/types/index.d.ts +1 -3
- package/dist/types/models/IEntityStorageMigrationConnector.d.ts +2 -2
- package/dist/types/models/IMigrationOptions.d.ts +6 -21
- package/dist/types/models/IResolvedMigrationStep.d.ts +7 -5
- package/dist/types/models/ISchemaMigration.d.ts +7 -4
- package/dist/types/models/entityPropertyTransformer.d.ts +6 -0
- package/docs/changelog.md +14 -0
- package/docs/reference/classes/MigrationHelper.md +91 -50
- package/docs/reference/index.md +4 -6
- package/docs/reference/interfaces/IEntityStorageMigrationConnector.md +2 -2
- package/docs/reference/interfaces/IMigrationOptions.md +9 -79
- package/docs/reference/interfaces/IResolvedMigrationStep.md +9 -13
- package/docs/reference/interfaces/ISchemaMigration.md +9 -12
- package/docs/reference/type-aliases/EntityPropertyTransformer.md +34 -0
- package/locales/en.json +8 -7
- package/package.json +2 -1
- package/dist/es/entities/schemaVersion.js +0 -39
- package/dist/es/entities/schemaVersion.js.map +0 -1
- package/dist/es/schema.js +0 -11
- package/dist/es/schema.js.map +0 -1
- package/dist/es/services/schemaVersionService.js +0 -265
- package/dist/es/services/schemaVersionService.js.map +0 -1
- package/dist/types/entities/schemaVersion.d.ts +0 -19
- package/dist/types/schema.d.ts +0 -4
- package/dist/types/services/schemaVersionService.d.ts +0 -60
- package/docs/reference/classes/SchemaVersion.md +0 -39
- package/docs/reference/classes/SchemaVersionService.md +0 -130
- package/docs/reference/functions/initSchema.md +0 -9
|
@@ -1,4 +1,4 @@
|
|
|
1
|
-
import type {
|
|
1
|
+
import type { EntityPropertyTransformer } from "./entityPropertyTransformer.js";
|
|
2
2
|
/**
|
|
3
3
|
* Optional per-step override for a single version-to-version migration.
|
|
4
4
|
* Only register an entry in SchemaMigrationFactory when a step requires property
|
|
@@ -20,8 +20,11 @@ export interface ISchemaMigration<T = unknown, U = unknown> {
|
|
|
20
20
|
to: string;
|
|
21
21
|
}[];
|
|
22
22
|
/**
|
|
23
|
-
* Optional
|
|
24
|
-
*
|
|
23
|
+
* Optional transformation for properties, usually only called for object and array types.
|
|
24
|
+
* @param schema1Property The property schema in the old schema.
|
|
25
|
+
* @param schemaProperty2 The property schema in the new schema.
|
|
26
|
+
* @param value The value of the property in the old schema.
|
|
27
|
+
* @returns The transformed value to match the new schema.
|
|
25
28
|
*/
|
|
26
|
-
transformEntityProperty?:
|
|
29
|
+
transformEntityProperty?: EntityPropertyTransformer<T, U>;
|
|
27
30
|
}
|
|
@@ -0,0 +1,6 @@
|
|
|
1
|
+
import type { IEntitySchemaProperty } from "@twin.org/entity";
|
|
2
|
+
/**
|
|
3
|
+
* Type for the optional transformEntityProperty function.
|
|
4
|
+
* Used in migration steps for custom property transformations.
|
|
5
|
+
*/
|
|
6
|
+
export type EntityPropertyTransformer<T = unknown, U = unknown> = (schema1Property: IEntitySchemaProperty<T>, schemaProperty2: IEntitySchemaProperty<U>, value: unknown) => unknown;
|
package/docs/changelog.md
CHANGED
|
@@ -1,5 +1,19 @@
|
|
|
1
1
|
# Changelog
|
|
2
2
|
|
|
3
|
+
## [0.0.3-next.26](https://github.com/iotaledger/twin-entity-storage/compare/entity-storage-models-v0.0.3-next.25...entity-storage-models-v0.0.3-next.26) (2026-06-11)
|
|
4
|
+
|
|
5
|
+
|
|
6
|
+
### Miscellaneous Chores
|
|
7
|
+
|
|
8
|
+
* **entity-storage-models:** Synchronize repo versions
|
|
9
|
+
|
|
10
|
+
## [0.0.3-next.25](https://github.com/iotaledger/twin-entity-storage/compare/entity-storage-models-v0.0.3-next.24...entity-storage-models-v0.0.3-next.25) (2026-06-09)
|
|
11
|
+
|
|
12
|
+
|
|
13
|
+
### Features
|
|
14
|
+
|
|
15
|
+
* migration progress ([#121](https://github.com/iotaledger/twin-entity-storage/issues/121)) ([d032162](https://github.com/iotaledger/twin-entity-storage/commit/d032162768b6b7d4ccca7e39b80f8bc3ba46440e))
|
|
16
|
+
|
|
3
17
|
## [0.0.3-next.24](https://github.com/iotaledger/twin-entity-storage/compare/entity-storage-models-v0.0.3-next.23...entity-storage-models-v0.0.3-next.24) (2026-06-08)
|
|
4
18
|
|
|
5
19
|
|
|
@@ -24,56 +24,93 @@ Runtime name for the class.
|
|
|
24
24
|
|
|
25
25
|
## Methods
|
|
26
26
|
|
|
27
|
-
###
|
|
27
|
+
### migrateWithChain() {#migratewithchain}
|
|
28
28
|
|
|
29
|
-
> `static` **
|
|
29
|
+
> `static` **migrateWithChain**(`sourceConnector`, `targetSchemaName`, `steps`, `options?`, `loggingComponentType?`): `Promise`\<\{ `finalConnector`: [`IEntityStorageConnector`](../interfaces/IEntityStorageConnector.md); `migrated`: `number`; \}\>
|
|
30
30
|
|
|
31
|
-
|
|
32
|
-
|
|
31
|
+
Performs a chain migration in a single connector swap, regardless of how many version
|
|
32
|
+
steps the chain spans. Creates one target connector, reads all source entities, applies
|
|
33
|
+
applyEntityChain to each, writes them to the target, then finalizes the migration.
|
|
34
|
+
A chain of one step is equivalent to a traditional single-step migration.
|
|
33
35
|
|
|
34
|
-
####
|
|
36
|
+
#### Parameters
|
|
35
37
|
|
|
36
|
-
#####
|
|
38
|
+
##### sourceConnector
|
|
37
39
|
|
|
38
|
-
`
|
|
40
|
+
[`IEntityStorageMigrationConnector`](../interfaces/IEntityStorageMigrationConnector.md)
|
|
39
41
|
|
|
40
|
-
|
|
42
|
+
The connector holding data at the stored schema version.
|
|
41
43
|
|
|
42
|
-
|
|
44
|
+
##### targetSchemaName
|
|
43
45
|
|
|
44
|
-
|
|
46
|
+
`string`
|
|
45
47
|
|
|
46
|
-
|
|
48
|
+
The schema name for the current version (used to create the target connector).
|
|
47
49
|
|
|
48
|
-
|
|
50
|
+
##### steps
|
|
49
51
|
|
|
50
|
-
|
|
52
|
+
[`IResolvedMigrationStep`](../interfaces/IResolvedMigrationStep.md)\<`unknown`, `unknown`\>[]
|
|
51
53
|
|
|
52
|
-
|
|
54
|
+
Ordered, fully-resolved migration steps from stored to current version.
|
|
53
55
|
|
|
54
|
-
|
|
56
|
+
##### options?
|
|
55
57
|
|
|
56
|
-
|
|
58
|
+
[`IMigrationOptions`](../interfaces/IMigrationOptions.md)
|
|
57
59
|
|
|
58
|
-
|
|
60
|
+
Optional migration options.
|
|
59
61
|
|
|
60
|
-
|
|
62
|
+
##### loggingComponentType?
|
|
61
63
|
|
|
62
|
-
|
|
64
|
+
`string`
|
|
65
|
+
|
|
66
|
+
The optional component type to use for logging the migration progress.
|
|
63
67
|
|
|
64
68
|
#### Returns
|
|
65
69
|
|
|
66
|
-
`
|
|
70
|
+
`Promise`\<\{ `finalConnector`: [`IEntityStorageConnector`](../interfaces/IEntityStorageConnector.md); `migrated`: `number`; \}\>
|
|
67
71
|
|
|
68
|
-
The
|
|
72
|
+
The finalized connector and the count of migrated entities.
|
|
69
73
|
|
|
70
|
-
|
|
74
|
+
***
|
|
71
75
|
|
|
72
|
-
|
|
76
|
+
### migratePartitionWithChain() {#migratepartitionwithchain}
|
|
73
77
|
|
|
74
|
-
|
|
78
|
+
> `static` **migratePartitionWithChain**(`source`, `target`, `steps`, `options?`): `Promise`\<`number`\>
|
|
75
79
|
|
|
76
|
-
|
|
80
|
+
Reads all entities from one partition of the source connector, applies the migration
|
|
81
|
+
chain to each entity, and writes the results to the target connector.
|
|
82
|
+
|
|
83
|
+
#### Parameters
|
|
84
|
+
|
|
85
|
+
##### source
|
|
86
|
+
|
|
87
|
+
[`IEntityStorageMigrationConnector`](../interfaces/IEntityStorageMigrationConnector.md)
|
|
88
|
+
|
|
89
|
+
The connector to read from (already bootstrapped).
|
|
90
|
+
|
|
91
|
+
##### target
|
|
92
|
+
|
|
93
|
+
[`IEntityStorageConnector`](../interfaces/IEntityStorageConnector.md)
|
|
94
|
+
|
|
95
|
+
The connector to write to (already bootstrapped).
|
|
96
|
+
|
|
97
|
+
##### steps
|
|
98
|
+
|
|
99
|
+
[`IResolvedMigrationStep`](../interfaces/IResolvedMigrationStep.md)\<`unknown`, `unknown`\>[]
|
|
100
|
+
|
|
101
|
+
Ordered, fully-resolved migration steps.
|
|
102
|
+
|
|
103
|
+
##### options?
|
|
104
|
+
|
|
105
|
+
[`IMigrationOptions`](../interfaces/IMigrationOptions.md)
|
|
106
|
+
|
|
107
|
+
Optional migration options (batchSize, progress callbacks, transformEntityProperty).
|
|
108
|
+
|
|
109
|
+
#### Returns
|
|
110
|
+
|
|
111
|
+
`Promise`\<`number`\>
|
|
112
|
+
|
|
113
|
+
The number of entities migrated.
|
|
77
114
|
|
|
78
115
|
***
|
|
79
116
|
|
|
@@ -109,49 +146,53 @@ The entity transformed to the shape described by steps[last].toProperties.
|
|
|
109
146
|
|
|
110
147
|
***
|
|
111
148
|
|
|
112
|
-
###
|
|
113
|
-
|
|
114
|
-
> `static` **migrateWithChain**(`sourceConnector`, `targetSchemaName`, `steps`, `loggingComponentType?`, `batchSize?`): `Promise`\<\{ `finalConnector`: [`IEntityStorageConnector`](../interfaces/IEntityStorageConnector.md); `migrated`: `number`; \}\>
|
|
149
|
+
### applyEntityTransform() {#applyentitytransform}
|
|
115
150
|
|
|
116
|
-
|
|
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.
|
|
151
|
+
> `static` **applyEntityTransform**\<`T`, `U`\>(`entity`, `schemaDiff`, `transformEntityProperty?`): `U`
|
|
120
152
|
|
|
121
|
-
|
|
153
|
+
Applies the entity transformation for a single diff, handling added, removed, and
|
|
154
|
+
modified properties according to the provided schema diff and optional transform hook.
|
|
122
155
|
|
|
123
|
-
|
|
156
|
+
#### Type Parameters
|
|
124
157
|
|
|
125
|
-
|
|
158
|
+
##### T
|
|
126
159
|
|
|
127
|
-
|
|
160
|
+
`T` = `unknown`
|
|
128
161
|
|
|
129
|
-
#####
|
|
162
|
+
##### U
|
|
130
163
|
|
|
131
|
-
`
|
|
164
|
+
`U` = `unknown`
|
|
132
165
|
|
|
133
|
-
|
|
166
|
+
#### Parameters
|
|
134
167
|
|
|
135
|
-
#####
|
|
168
|
+
##### entity
|
|
136
169
|
|
|
137
|
-
|
|
170
|
+
`Partial`\<`T`\>
|
|
138
171
|
|
|
139
|
-
|
|
172
|
+
The entity to transform.
|
|
140
173
|
|
|
141
|
-
#####
|
|
174
|
+
##### schemaDiff
|
|
142
175
|
|
|
143
|
-
`
|
|
176
|
+
`IEntitySchemaDiff`\<`T`, `U`\>
|
|
144
177
|
|
|
145
|
-
|
|
178
|
+
The schema diff between the old and new schemas.
|
|
146
179
|
|
|
147
|
-
#####
|
|
180
|
+
##### transformEntityProperty?
|
|
148
181
|
|
|
149
|
-
`
|
|
182
|
+
[`EntityPropertyTransformer`](../type-aliases/EntityPropertyTransformer.md)\<`T`, `U`\>
|
|
150
183
|
|
|
151
|
-
|
|
184
|
+
Optional per-property transform hook for object/array properties.
|
|
152
185
|
|
|
153
186
|
#### Returns
|
|
154
187
|
|
|
155
|
-
`
|
|
188
|
+
`U`
|
|
156
189
|
|
|
157
|
-
The
|
|
190
|
+
The transformed entity ready to be written to the new schema.
|
|
191
|
+
|
|
192
|
+
#### Throws
|
|
193
|
+
|
|
194
|
+
GeneralError if a transformation is required for an object or array property but no transformEntityProperty function is provided.
|
|
195
|
+
|
|
196
|
+
#### Throws
|
|
197
|
+
|
|
198
|
+
GeneralError if coercion of a modified property results in undefined for a non-optional target property.
|
package/docs/reference/index.md
CHANGED
|
@@ -2,10 +2,8 @@
|
|
|
2
2
|
|
|
3
3
|
## Classes
|
|
4
4
|
|
|
5
|
-
- [SchemaVersion](classes/SchemaVersion.md)
|
|
6
5
|
- [EntityStorageHelper](classes/EntityStorageHelper.md)
|
|
7
6
|
- [MigrationHelper](classes/MigrationHelper.md)
|
|
8
|
-
- [SchemaVersionService](classes/SchemaVersionService.md)
|
|
9
7
|
|
|
10
8
|
## Interfaces
|
|
11
9
|
|
|
@@ -27,11 +25,11 @@
|
|
|
27
25
|
- [IEntityStorageSetBatchRequest](interfaces/IEntityStorageSetBatchRequest.md)
|
|
28
26
|
- [IEntityStorageSetRequest](interfaces/IEntityStorageSetRequest.md)
|
|
29
27
|
|
|
28
|
+
## Type Aliases
|
|
29
|
+
|
|
30
|
+
- [EntityPropertyTransformer](type-aliases/EntityPropertyTransformer.md)
|
|
31
|
+
|
|
30
32
|
## Variables
|
|
31
33
|
|
|
32
34
|
- [EntityStorageConnectorFactory](variables/EntityStorageConnectorFactory.md)
|
|
33
35
|
- [SchemaMigrationFactory](variables/SchemaMigrationFactory.md)
|
|
34
|
-
|
|
35
|
-
## Functions
|
|
36
|
-
|
|
37
|
-
- [initSchema](functions/initSchema.md)
|
|
@@ -345,7 +345,7 @@ The target connector to finalize the migration with.
|
|
|
345
345
|
|
|
346
346
|
##### options?
|
|
347
347
|
|
|
348
|
-
[`IMigrationOptions`](IMigrationOptions.md)
|
|
348
|
+
[`IMigrationOptions`](IMigrationOptions.md)
|
|
349
349
|
|
|
350
350
|
The options to control how the migration is finalized.
|
|
351
351
|
|
|
@@ -385,7 +385,7 @@ The target connector to cleanup the migration with.
|
|
|
385
385
|
|
|
386
386
|
##### options?
|
|
387
387
|
|
|
388
|
-
[`IMigrationOptions`](IMigrationOptions.md)
|
|
388
|
+
[`IMigrationOptions`](IMigrationOptions.md)
|
|
389
389
|
|
|
390
390
|
The options to control how the migration is cleaned up.
|
|
391
391
|
|
|
@@ -1,17 +1,7 @@
|
|
|
1
|
-
# Interface: IMigrationOptions
|
|
1
|
+
# Interface: IMigrationOptions
|
|
2
2
|
|
|
3
3
|
Options controlling how a schema migration is executed.
|
|
4
4
|
|
|
5
|
-
## Type Parameters
|
|
6
|
-
|
|
7
|
-
### T
|
|
8
|
-
|
|
9
|
-
`T`
|
|
10
|
-
|
|
11
|
-
### U
|
|
12
|
-
|
|
13
|
-
`U`
|
|
14
|
-
|
|
15
5
|
## Properties
|
|
16
6
|
|
|
17
7
|
### batchSize? {#batchsize}
|
|
@@ -28,91 +18,31 @@ Number of entities to read and write per batch.
|
|
|
28
18
|
|
|
29
19
|
***
|
|
30
20
|
|
|
31
|
-
###
|
|
32
|
-
|
|
33
|
-
> `optional` **transformEntityProperty?**: (`schema1Property`, `schemaProperty2`, `value`) => `unknown`
|
|
34
|
-
|
|
35
|
-
Optional transformation for properties, usually only called for object and array types.
|
|
36
|
-
|
|
37
|
-
#### Parameters
|
|
38
|
-
|
|
39
|
-
##### schema1Property
|
|
40
|
-
|
|
41
|
-
`IEntitySchemaProperty`\<`T`\>
|
|
42
|
-
|
|
43
|
-
The property schema in the old schema.
|
|
44
|
-
|
|
45
|
-
##### schemaProperty2
|
|
46
|
-
|
|
47
|
-
`IEntitySchemaProperty`\<`U`\>
|
|
48
|
-
|
|
49
|
-
The property schema in the new schema.
|
|
50
|
-
|
|
51
|
-
##### value
|
|
52
|
-
|
|
53
|
-
`unknown`
|
|
54
|
-
|
|
55
|
-
The value of the property in the old schema.
|
|
56
|
-
|
|
57
|
-
#### Returns
|
|
58
|
-
|
|
59
|
-
`unknown`
|
|
60
|
-
|
|
61
|
-
The transformed value to match the new schema.
|
|
62
|
-
|
|
63
|
-
***
|
|
64
|
-
|
|
65
|
-
### onPartitionProgress? {#onpartitionprogress}
|
|
66
|
-
|
|
67
|
-
> `optional` **onPartitionProgress?**: (`rowTotal`, `rowIndex`) => `Promise`\<`void`\>
|
|
68
|
-
|
|
69
|
-
Called for each partition for progress tracking.
|
|
70
|
-
|
|
71
|
-
#### Parameters
|
|
72
|
-
|
|
73
|
-
##### rowTotal
|
|
74
|
-
|
|
75
|
-
`number`
|
|
76
|
-
|
|
77
|
-
The total number of rows to migrate.
|
|
78
|
-
|
|
79
|
-
##### rowIndex
|
|
80
|
-
|
|
81
|
-
`number`
|
|
82
|
-
|
|
83
|
-
The number of rows migrated so far.
|
|
84
|
-
|
|
85
|
-
#### Returns
|
|
86
|
-
|
|
87
|
-
`Promise`\<`void`\>
|
|
88
|
-
|
|
89
|
-
***
|
|
90
|
-
|
|
91
|
-
### onStepProgress? {#onstepprogress}
|
|
21
|
+
### onProgress? {#onprogress}
|
|
92
22
|
|
|
93
|
-
> `optional` **
|
|
23
|
+
> `optional` **onProgress?**: (`progressItem`, `itemTotal`, `itemIndex`) => `Promise`\<`void`\>
|
|
94
24
|
|
|
95
|
-
Called for
|
|
25
|
+
Called for progress tracking.
|
|
96
26
|
|
|
97
27
|
#### Parameters
|
|
98
28
|
|
|
99
|
-
#####
|
|
29
|
+
##### progressItem
|
|
100
30
|
|
|
101
|
-
`
|
|
31
|
+
`"partitionStart"` \| `"partitionProgress"` \| `"partitionEnd"` \| `"partitionItemsStart"` \| `"partitionItemsProgress"` \| `"partitionItemsEnd"`
|
|
102
32
|
|
|
103
|
-
The
|
|
33
|
+
The item progress being updated.
|
|
104
34
|
|
|
105
35
|
##### itemTotal
|
|
106
36
|
|
|
107
37
|
`number`
|
|
108
38
|
|
|
109
|
-
The total number of
|
|
39
|
+
The total number of rows to migrate.
|
|
110
40
|
|
|
111
41
|
##### itemIndex
|
|
112
42
|
|
|
113
43
|
`number`
|
|
114
44
|
|
|
115
|
-
The number of
|
|
45
|
+
The number of rows migrated so far.
|
|
116
46
|
|
|
117
47
|
#### Returns
|
|
118
48
|
|
|
@@ -57,26 +57,22 @@ Optional property renames for this step, forwarded to EntitySchemaDiffHelper.dif
|
|
|
57
57
|
|
|
58
58
|
### transformEntityProperty? {#transformentityproperty}
|
|
59
59
|
|
|
60
|
-
> `optional` **transformEntityProperty?**:
|
|
60
|
+
> `optional` **transformEntityProperty?**: [`EntityPropertyTransformer`](../type-aliases/EntityPropertyTransformer.md)\<`T`, `U`\>
|
|
61
61
|
|
|
62
|
-
Optional
|
|
63
|
-
diff cannot handle automatically. Sourced from an ISchemaMigration override when
|
|
64
|
-
one is registered in SchemaMigrationFactory for this step.
|
|
62
|
+
Optional transformation for properties, usually only called for object and array types.
|
|
65
63
|
|
|
66
|
-
####
|
|
64
|
+
#### Param
|
|
67
65
|
|
|
68
|
-
|
|
66
|
+
The property schema in the old schema.
|
|
69
67
|
|
|
70
|
-
|
|
68
|
+
#### Param
|
|
71
69
|
|
|
72
|
-
|
|
70
|
+
The property schema in the new schema.
|
|
73
71
|
|
|
74
|
-
|
|
72
|
+
#### Param
|
|
75
73
|
|
|
76
|
-
|
|
77
|
-
|
|
78
|
-
`unknown`
|
|
74
|
+
The value of the property in the old schema.
|
|
79
75
|
|
|
80
76
|
#### Returns
|
|
81
77
|
|
|
82
|
-
|
|
78
|
+
The transformed value to match the new schema.
|
|
@@ -41,25 +41,22 @@ Optional property renames to apply during this step.
|
|
|
41
41
|
|
|
42
42
|
### transformEntityProperty? {#transformentityproperty}
|
|
43
43
|
|
|
44
|
-
> `optional` **transformEntityProperty?**:
|
|
44
|
+
> `optional` **transformEntityProperty?**: [`EntityPropertyTransformer`](../type-aliases/EntityPropertyTransformer.md)\<`T`, `U`\>
|
|
45
45
|
|
|
46
|
-
Optional
|
|
47
|
-
automatically coerced. T is the source entity type, U is the target entity type.
|
|
46
|
+
Optional transformation for properties, usually only called for object and array types.
|
|
48
47
|
|
|
49
|
-
####
|
|
48
|
+
#### Param
|
|
50
49
|
|
|
51
|
-
|
|
50
|
+
The property schema in the old schema.
|
|
52
51
|
|
|
53
|
-
|
|
52
|
+
#### Param
|
|
54
53
|
|
|
55
|
-
|
|
54
|
+
The property schema in the new schema.
|
|
56
55
|
|
|
57
|
-
|
|
56
|
+
#### Param
|
|
58
57
|
|
|
59
|
-
|
|
60
|
-
|
|
61
|
-
`unknown`
|
|
58
|
+
The value of the property in the old schema.
|
|
62
59
|
|
|
63
60
|
#### Returns
|
|
64
61
|
|
|
65
|
-
|
|
62
|
+
The transformed value to match the new schema.
|
|
@@ -0,0 +1,34 @@
|
|
|
1
|
+
# Type Alias: EntityPropertyTransformer\<T, U\>
|
|
2
|
+
|
|
3
|
+
> **EntityPropertyTransformer**\<`T`, `U`\> = (`schema1Property`, `schemaProperty2`, `value`) => `unknown`
|
|
4
|
+
|
|
5
|
+
Type for the optional transformEntityProperty function.
|
|
6
|
+
Used in migration steps for custom property transformations.
|
|
7
|
+
|
|
8
|
+
## Type Parameters
|
|
9
|
+
|
|
10
|
+
### T
|
|
11
|
+
|
|
12
|
+
`T` = `unknown`
|
|
13
|
+
|
|
14
|
+
### U
|
|
15
|
+
|
|
16
|
+
`U` = `unknown`
|
|
17
|
+
|
|
18
|
+
## Parameters
|
|
19
|
+
|
|
20
|
+
### schema1Property
|
|
21
|
+
|
|
22
|
+
`IEntitySchemaProperty`\<`T`\>
|
|
23
|
+
|
|
24
|
+
### schemaProperty2
|
|
25
|
+
|
|
26
|
+
`IEntitySchemaProperty`\<`U`\>
|
|
27
|
+
|
|
28
|
+
### value
|
|
29
|
+
|
|
30
|
+
`unknown`
|
|
31
|
+
|
|
32
|
+
## Returns
|
|
33
|
+
|
|
34
|
+
`unknown`
|
package/locales/en.json
CHANGED
|
@@ -5,15 +5,16 @@
|
|
|
5
5
|
"propertyNotInSchema": "The property \"{property}\" does not exist in the schema and cannot be used for projection"
|
|
6
6
|
},
|
|
7
7
|
"migrationHelper": {
|
|
8
|
-
"
|
|
8
|
+
"migrateSchemaFailed": "Migration failed for schema \"{schemaName}\".",
|
|
9
9
|
"transformRequiredForProperty": "A transformation function is required to migrate property \"{from}\" to \"{to}\" of type \"{type}\"",
|
|
10
10
|
"coercionProducedUndefined": "Coercion of property \"{property}\" to type \"{type}\" produced undefined but the property is not optional"
|
|
11
|
-
}
|
|
12
|
-
|
|
13
|
-
|
|
14
|
-
|
|
15
|
-
"
|
|
16
|
-
"
|
|
11
|
+
}
|
|
12
|
+
},
|
|
13
|
+
"info": {
|
|
14
|
+
"migrationHelper": {
|
|
15
|
+
"migrateSchemaStarting": "Migrating schema \"{schemaName}\"",
|
|
16
|
+
"migrateSchemaFinalizing": "Finalizing migration of schema \"{schemaName}\"",
|
|
17
|
+
"migrateSchemaComplete": "Migration of schema \"{schemaName}\" complete"
|
|
17
18
|
}
|
|
18
19
|
}
|
|
19
20
|
}
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@twin.org/entity-storage-models",
|
|
3
|
-
"version": "0.0.3-next.
|
|
3
|
+
"version": "0.0.3-next.26",
|
|
4
4
|
"description": "Shared models for storage contracts, requests, responses and connector capabilities.",
|
|
5
5
|
"repository": {
|
|
6
6
|
"type": "git",
|
|
@@ -17,6 +17,7 @@
|
|
|
17
17
|
"@twin.org/context": "next",
|
|
18
18
|
"@twin.org/core": "next",
|
|
19
19
|
"@twin.org/entity": "next",
|
|
20
|
+
"@twin.org/logging-models": "next",
|
|
20
21
|
"@twin.org/nameof": "next"
|
|
21
22
|
},
|
|
22
23
|
"main": "./dist/es/index.js",
|
|
@@ -1,39 +0,0 @@
|
|
|
1
|
-
// Copyright 2026 IOTA Stiftung.
|
|
2
|
-
// SPDX-License-Identifier: Apache-2.0.
|
|
3
|
-
import { entity, property } from "@twin.org/entity";
|
|
4
|
-
/**
|
|
5
|
-
* Tracks the currently applied schema version for each managed entity schema.
|
|
6
|
-
* One record per schema name. Written once on first boot, then updated after
|
|
7
|
-
* each successful migration.
|
|
8
|
-
*/
|
|
9
|
-
let SchemaVersion = class SchemaVersion {
|
|
10
|
-
/**
|
|
11
|
-
* The entity schema type name — primary key.
|
|
12
|
-
*/
|
|
13
|
-
schemaName;
|
|
14
|
-
/**
|
|
15
|
-
* The currently deployed version of this schema.
|
|
16
|
-
*/
|
|
17
|
-
version;
|
|
18
|
-
/**
|
|
19
|
-
* ISO 8601 timestamp of the last version write.
|
|
20
|
-
*/
|
|
21
|
-
updatedAt;
|
|
22
|
-
};
|
|
23
|
-
__decorate([
|
|
24
|
-
property({ type: "string", isPrimary: true }),
|
|
25
|
-
__metadata("design:type", String)
|
|
26
|
-
], SchemaVersion.prototype, "schemaName", void 0);
|
|
27
|
-
__decorate([
|
|
28
|
-
property({ type: "integer" }),
|
|
29
|
-
__metadata("design:type", Number)
|
|
30
|
-
], SchemaVersion.prototype, "version", void 0);
|
|
31
|
-
__decorate([
|
|
32
|
-
property({ type: "string", format: "date-time" }),
|
|
33
|
-
__metadata("design:type", String)
|
|
34
|
-
], SchemaVersion.prototype, "updatedAt", void 0);
|
|
35
|
-
SchemaVersion = __decorate([
|
|
36
|
-
entity()
|
|
37
|
-
], SchemaVersion);
|
|
38
|
-
export { SchemaVersion };
|
|
39
|
-
//# sourceMappingURL=schemaVersion.js.map
|
|
@@ -1 +0,0 @@
|
|
|
1
|
-
{"version":3,"file":"schemaVersion.js","sourceRoot":"","sources":["../../../src/entities/schemaVersion.ts"],"names":[],"mappings":"AAAA,gCAAgC;AAChC,uCAAuC;AACvC,OAAO,EAAE,MAAM,EAAE,QAAQ,EAAE,MAAM,kBAAkB,CAAC;AAEpD;;;;GAIG;AAEI,IAAM,aAAa,GAAnB,MAAM,aAAa;IACzB;;OAEG;IAEI,UAAU,CAAU;IAE3B;;OAEG;IAEI,OAAO,CAAU;IAExB;;OAEG;IAEI,SAAS,CAAU;CAC1B,CAAA;AAbO;IADN,QAAQ,CAAC,EAAE,IAAI,EAAE,QAAQ,EAAE,SAAS,EAAE,IAAI,EAAE,CAAC;;iDACnB;AAMpB;IADN,QAAQ,CAAC,EAAE,IAAI,EAAE,SAAS,EAAE,CAAC;;8CACN;AAMjB;IADN,QAAQ,CAAC,EAAE,IAAI,EAAE,QAAQ,EAAE,MAAM,EAAE,WAAW,EAAE,CAAC;;gDACxB;AAjBd,aAAa;IADzB,MAAM,EAAE;GACI,aAAa,CAkBzB","sourcesContent":["// Copyright 2026 IOTA Stiftung.\n// SPDX-License-Identifier: Apache-2.0.\nimport { entity, property } from \"@twin.org/entity\";\n\n/**\n * Tracks the currently applied schema version for each managed entity schema.\n * One record per schema name. Written once on first boot, then updated after\n * each successful migration.\n */\n@entity()\nexport class SchemaVersion {\n\t/**\n\t * The entity schema type name — primary key.\n\t */\n\t@property({ type: \"string\", isPrimary: true })\n\tpublic schemaName!: string;\n\n\t/**\n\t * The currently deployed version of this schema.\n\t */\n\t@property({ type: \"integer\" })\n\tpublic version!: number;\n\n\t/**\n\t * ISO 8601 timestamp of the last version write.\n\t */\n\t@property({ type: \"string\", format: \"date-time\" })\n\tpublic updatedAt!: string;\n}\n"]}
|
package/dist/es/schema.js
DELETED
|
@@ -1,11 +0,0 @@
|
|
|
1
|
-
// Copyright 2026 IOTA Stiftung.
|
|
2
|
-
// SPDX-License-Identifier: Apache-2.0.
|
|
3
|
-
import { EntitySchemaFactory, EntitySchemaHelper } from "@twin.org/entity";
|
|
4
|
-
import { SchemaVersion } from "./entities/schemaVersion.js";
|
|
5
|
-
/**
|
|
6
|
-
* Initialize the schema for the entity storage models.
|
|
7
|
-
*/
|
|
8
|
-
export function initSchema() {
|
|
9
|
-
EntitySchemaFactory.register("SchemaVersion", () => EntitySchemaHelper.getSchema(SchemaVersion));
|
|
10
|
-
}
|
|
11
|
-
//# sourceMappingURL=schema.js.map
|
package/dist/es/schema.js.map
DELETED
|
@@ -1 +0,0 @@
|
|
|
1
|
-
{"version":3,"file":"schema.js","sourceRoot":"","sources":["../../src/schema.ts"],"names":[],"mappings":"AAAA,gCAAgC;AAChC,uCAAuC;AACvC,OAAO,EAAE,mBAAmB,EAAE,kBAAkB,EAAE,MAAM,kBAAkB,CAAC;AAE3E,OAAO,EAAE,aAAa,EAAE,MAAM,6BAA6B,CAAC;AAE5D;;GAEG;AACH,MAAM,UAAU,UAAU;IACzB,mBAAmB,CAAC,QAAQ,kBAA0B,GAAG,EAAE,CAC1D,kBAAkB,CAAC,SAAS,CAAC,aAAa,CAAC,CAC3C,CAAC;AACH,CAAC","sourcesContent":["// Copyright 2026 IOTA Stiftung.\n// SPDX-License-Identifier: Apache-2.0.\nimport { EntitySchemaFactory, EntitySchemaHelper } from \"@twin.org/entity\";\nimport { nameof } from \"@twin.org/nameof\";\nimport { SchemaVersion } from \"./entities/schemaVersion.js\";\n\n/**\n * Initialize the schema for the entity storage models.\n */\nexport function initSchema(): void {\n\tEntitySchemaFactory.register(nameof<SchemaVersion>(), () =>\n\t\tEntitySchemaHelper.getSchema(SchemaVersion)\n\t);\n}\n"]}
|