@twin.org/entity-storage-service 0.0.3-next.9 → 0.9.0-next.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.
Files changed (42) hide show
  1. package/dist/es/entities/schemaVersion.js +39 -0
  2. package/dist/es/entities/schemaVersion.js.map +1 -0
  3. package/dist/es/entityStorageRoutes.js +176 -4
  4. package/dist/es/entityStorageRoutes.js.map +1 -1
  5. package/dist/es/entityStorageService.js +44 -49
  6. package/dist/es/entityStorageService.js.map +1 -1
  7. package/dist/es/index.js +6 -1
  8. package/dist/es/index.js.map +1 -1
  9. package/dist/es/models/IEntityStorageRoutesExamples.js.map +1 -1
  10. package/dist/es/models/ISchemaVersionServiceConfig.js +4 -0
  11. package/dist/es/models/ISchemaVersionServiceConfig.js.map +1 -0
  12. package/dist/es/models/ISchemaVersionServiceConstructorOptions.js +2 -0
  13. package/dist/es/models/ISchemaVersionServiceConstructorOptions.js.map +1 -0
  14. package/dist/es/schema.js +11 -0
  15. package/dist/es/schema.js.map +1 -0
  16. package/dist/es/schemaVersionService.js +356 -0
  17. package/dist/es/schemaVersionService.js.map +1 -0
  18. package/dist/types/entities/schemaVersion.d.ts +19 -0
  19. package/dist/types/entityStorageRoutes.d.ts +33 -1
  20. package/dist/types/entityStorageService.d.ts +38 -3
  21. package/dist/types/index.d.ts +6 -1
  22. package/dist/types/models/IEntityStorageRoutesExamples.d.ts +8 -1
  23. package/dist/types/models/ISchemaVersionServiceConfig.d.ts +9 -0
  24. package/dist/types/models/ISchemaVersionServiceConstructorOptions.d.ts +15 -0
  25. package/dist/types/schema.d.ts +4 -0
  26. package/dist/types/schemaVersionService.d.ts +52 -0
  27. package/docs/changelog.md +546 -52
  28. package/docs/open-api/spec.json +439 -1
  29. package/docs/reference/classes/EntityStorageService.md +117 -3
  30. package/docs/reference/classes/SchemaVersion.md +39 -0
  31. package/docs/reference/classes/SchemaVersionService.md +103 -0
  32. package/docs/reference/functions/entityStorageCount.md +31 -0
  33. package/docs/reference/functions/entityStorageEmpty.md +31 -0
  34. package/docs/reference/functions/entityStorageRemoveBatch.md +31 -0
  35. package/docs/reference/functions/entityStorageSetBatch.md +31 -0
  36. package/docs/reference/functions/initSchema.md +9 -0
  37. package/docs/reference/index.md +9 -0
  38. package/docs/reference/interfaces/IEntityStorageRoutesExamples.md +16 -0
  39. package/docs/reference/interfaces/ISchemaVersionServiceConfig.md +11 -0
  40. package/docs/reference/interfaces/ISchemaVersionServiceConstructorOptions.md +25 -0
  41. package/locales/en.json +17 -2
  42. package/package.json +10 -9
@@ -0,0 +1,103 @@
1
+ # Class: SchemaVersionService
2
+
3
+ Service that checks and applies entity schema migrations at every node start-up.
4
+
5
+ This service must be the first entry in coreTypeInitialisers.json. The engine iterates that
6
+ array in order to determine start sequence — there is no engine-level priority mechanism, so
7
+ registration position is the only guarantee that start() runs before any other service.
8
+ By the time start() is called, all component bootstraps have completed (every table already
9
+ exists) and EntitySchemaFactory / EntityStorageConnectorFactory are fully populated with every
10
+ registered schema and connector.
11
+
12
+ Migration mechanics: old schema versions are registered in EntitySchemaFactory by naming
13
+ convention — current schema = "MyEntity", first history = "MyEntityV0", second = "MyEntityV1".
14
+ The service groups schemas by base name (strips the trailing V number suffix) and resolves the
15
+ migration chain automatically by diffing consecutive versioned schemas. For steps that require
16
+ property renames or a custom transform hook, register an optional ISchemaMigration entry in
17
+ SchemaMigrationFactory under the key "Base_from_to" (e.g. "MyEntity_0_1").
18
+
19
+ Crash-window note: finalizeMigration and the subsequent version-record write are two
20
+ separate operations. If the process dies between them the next boot re-runs the chain
21
+ over already-migrated data. applyEntityTransform is NOT idempotent for structural changes
22
+ (newly-added optional fields would be dropped on re-run). A transaction spanning both
23
+ writes is a precondition for production; track this in the concurrency follow-up.
24
+
25
+ ## Implements
26
+
27
+ - `IComponent`
28
+
29
+ ## Constructors
30
+
31
+ ### Constructor
32
+
33
+ > **new SchemaVersionService**(`options?`): `SchemaVersionService`
34
+
35
+ Create a new SchemaVersionService.
36
+
37
+ #### Parameters
38
+
39
+ ##### options?
40
+
41
+ [`ISchemaVersionServiceConstructorOptions`](../interfaces/ISchemaVersionServiceConstructorOptions.md)
42
+
43
+ Optional constructor options.
44
+
45
+ #### Returns
46
+
47
+ `SchemaVersionService`
48
+
49
+ ## Properties
50
+
51
+ ### CLASS\_NAME {#class_name}
52
+
53
+ > `readonly` `static` **CLASS\_NAME**: `string`
54
+
55
+ Runtime name for the class.
56
+
57
+ ## Methods
58
+
59
+ ### className() {#classname}
60
+
61
+ > **className**(): `string`
62
+
63
+ Returns the class name.
64
+
65
+ #### Returns
66
+
67
+ `string`
68
+
69
+ The class name.
70
+
71
+ #### Implementation of
72
+
73
+ `IComponent.className`
74
+
75
+ ***
76
+
77
+ ### start() {#start}
78
+
79
+ > **start**(`nodeLoggingComponentType?`): `Promise`\<`void`\>
80
+
81
+ Reads all registered entity schemas, groups versioned schemas by base name, reads the
82
+ full schemaVersion table in one pass, then orchestrates chain migrations for any schema
83
+ whose stored version is behind the current version declared in EntitySchemaFactory.
84
+ SchemaVersion itself is processed first so the version store is migrated before any
85
+ version records are written for other schemas.
86
+
87
+ Runs after all component bootstraps, so every managed table already exists.
88
+
89
+ #### Parameters
90
+
91
+ ##### nodeLoggingComponentType?
92
+
93
+ `string`
94
+
95
+ An optional logging component type.
96
+
97
+ #### Returns
98
+
99
+ `Promise`\<`void`\>
100
+
101
+ #### Implementation of
102
+
103
+ `IComponent.start`
@@ -0,0 +1,31 @@
1
+ # Function: entityStorageCount()
2
+
3
+ > **entityStorageCount**(`httpRequestContext`, `componentName`, `request`): `Promise`\<`IEntityStorageCountResponse`\>
4
+
5
+ Count the entries in entity storage.
6
+
7
+ ## Parameters
8
+
9
+ ### httpRequestContext
10
+
11
+ `IHttpRequestContext`
12
+
13
+ The request context for the API.
14
+
15
+ ### componentName
16
+
17
+ `string`
18
+
19
+ The name of the component to use in the routes.
20
+
21
+ ### request
22
+
23
+ `IEntityStorageCountRequest`
24
+
25
+ The request.
26
+
27
+ ## Returns
28
+
29
+ `Promise`\<`IEntityStorageCountResponse`\>
30
+
31
+ The response object with additional http response properties.
@@ -0,0 +1,31 @@
1
+ # Function: entityStorageEmpty()
2
+
3
+ > **entityStorageEmpty**(`httpRequestContext`, `componentName`, `request`): `Promise`\<`INoContentResponse`\>
4
+
5
+ Remove all entries from entity storage.
6
+
7
+ ## Parameters
8
+
9
+ ### httpRequestContext
10
+
11
+ `IHttpRequestContext`
12
+
13
+ The request context for the API.
14
+
15
+ ### componentName
16
+
17
+ `string`
18
+
19
+ The name of the component to use in the routes.
20
+
21
+ ### request
22
+
23
+ `IEntityStorageEmptyRequest`
24
+
25
+ The request.
26
+
27
+ ## Returns
28
+
29
+ `Promise`\<`INoContentResponse`\>
30
+
31
+ The response object with additional http response properties.
@@ -0,0 +1,31 @@
1
+ # Function: entityStorageRemoveBatch()
2
+
3
+ > **entityStorageRemoveBatch**(`httpRequestContext`, `componentName`, `request`): `Promise`\<`INoContentResponse`\>
4
+
5
+ Remove multiple entries from entity storage by id.
6
+
7
+ ## Parameters
8
+
9
+ ### httpRequestContext
10
+
11
+ `IHttpRequestContext`
12
+
13
+ The request context for the API.
14
+
15
+ ### componentName
16
+
17
+ `string`
18
+
19
+ The name of the component to use in the routes.
20
+
21
+ ### request
22
+
23
+ `IEntityStorageRemoveBatchRequest`
24
+
25
+ The request.
26
+
27
+ ## Returns
28
+
29
+ `Promise`\<`INoContentResponse`\>
30
+
31
+ The response object with additional http response properties.
@@ -0,0 +1,31 @@
1
+ # Function: entityStorageSetBatch()
2
+
3
+ > **entityStorageSetBatch**(`httpRequestContext`, `componentName`, `request`): `Promise`\<`INoContentResponse`\>
4
+
5
+ Set multiple entries in entity storage.
6
+
7
+ ## Parameters
8
+
9
+ ### httpRequestContext
10
+
11
+ `IHttpRequestContext`
12
+
13
+ The request context for the API.
14
+
15
+ ### componentName
16
+
17
+ `string`
18
+
19
+ The name of the component to use in the routes.
20
+
21
+ ### request
22
+
23
+ `IEntityStorageSetBatchRequest`
24
+
25
+ The request.
26
+
27
+ ## Returns
28
+
29
+ `Promise`\<`INoContentResponse`\>
30
+
31
+ The response object with additional http response properties.
@@ -0,0 +1,9 @@
1
+ # Function: initSchema()
2
+
3
+ > **initSchema**(): `void`
4
+
5
+ Initialize the schema for the entity storage models.
6
+
7
+ ## Returns
8
+
9
+ `void`
@@ -2,13 +2,17 @@
2
2
 
3
3
  ## Classes
4
4
 
5
+ - [SchemaVersion](classes/SchemaVersion.md)
5
6
  - [EntityStorageService](classes/EntityStorageService.md)
7
+ - [SchemaVersionService](classes/SchemaVersionService.md)
6
8
 
7
9
  ## Interfaces
8
10
 
9
11
  - [IEntityStorageRoutesExamples](interfaces/IEntityStorageRoutesExamples.md)
10
12
  - [IEntityStorageServiceConfig](interfaces/IEntityStorageServiceConfig.md)
11
13
  - [IEntityStorageServiceConstructorOptions](interfaces/IEntityStorageServiceConstructorOptions.md)
14
+ - [ISchemaVersionServiceConfig](interfaces/ISchemaVersionServiceConfig.md)
15
+ - [ISchemaVersionServiceConstructorOptions](interfaces/ISchemaVersionServiceConstructorOptions.md)
12
16
 
13
17
  ## Variables
14
18
 
@@ -19,6 +23,11 @@
19
23
 
20
24
  - [generateRestRoutesEntityStorage](functions/generateRestRoutesEntityStorage.md)
21
25
  - [entityStorageSet](functions/entityStorageSet.md)
26
+ - [entityStorageSetBatch](functions/entityStorageSetBatch.md)
27
+ - [entityStorageEmpty](functions/entityStorageEmpty.md)
22
28
  - [entityStorageGet](functions/entityStorageGet.md)
23
29
  - [entityStorageRemove](functions/entityStorageRemove.md)
24
30
  - [entityStorageList](functions/entityStorageList.md)
31
+ - [entityStorageCount](functions/entityStorageCount.md)
32
+ - [entityStorageRemoveBatch](functions/entityStorageRemoveBatch.md)
33
+ - [initSchema](functions/initSchema.md)
@@ -57,3 +57,19 @@ Examples for the list route.
57
57
  #### responseExamples
58
58
 
59
59
  > **responseExamples**: `IRestRouteResponseExample`\<`IEntityStorageListResponse`\>[]
60
+
61
+ ***
62
+
63
+ ### count? {#count}
64
+
65
+ > `optional` **count?**: `object`
66
+
67
+ Examples for the count route.
68
+
69
+ #### requestExamples
70
+
71
+ > **requestExamples**: `IRestRouteRequestExample`\<`IEntityStorageCountRequest`\>[]
72
+
73
+ #### responseExamples
74
+
75
+ > **responseExamples**: `IRestRouteResponseExample`\<`IEntityStorageCountResponse`\>[]
@@ -0,0 +1,11 @@
1
+ # Interface: ISchemaVersionServiceConfig
2
+
3
+ Constructor options config for SchemaVersionService.
4
+
5
+ ## Properties
6
+
7
+ ### batchSize? {#batchsize}
8
+
9
+ > `optional` **batchSize?**: `number`
10
+
11
+ The batch size for processing schema versions.
@@ -0,0 +1,25 @@
1
+ # Interface: ISchemaVersionServiceConstructorOptions
2
+
3
+ Constructor options for SchemaVersionService.
4
+
5
+ ## Properties
6
+
7
+ ### schemaVersionStorageType? {#schemaversionstoragetype}
8
+
9
+ > `optional` **schemaVersionStorageType?**: `string`
10
+
11
+ The version storage type.
12
+
13
+ #### Default
14
+
15
+ ```ts
16
+ schema-version
17
+ ```
18
+
19
+ ***
20
+
21
+ ### config? {#config}
22
+
23
+ > `optional` **config?**: [`ISchemaVersionServiceConfig`](ISchemaVersionServiceConfig.md)
24
+
25
+ Optional config.
package/locales/en.json CHANGED
@@ -1,7 +1,22 @@
1
1
  {
2
2
  "error": {
3
- "entityStorageService": {
4
- "entityNotFound": "Could not find entity with id \"{notFoundId}\""
3
+ "schemaVersionService": {
4
+ "storedVersionNewer": "Stored schema version ({stored}) for \"{schemaName}\" is newer than the current version ({current}). Downgrade is not supported.",
5
+ "noMigrationStep": "No migration step from version {missingFromVersion} to {missingToVersion} found for \"{schemaName}\". Cannot complete migration from {stored} to {current}. Register the versioned schema class \"{schemaName}V{missingFromVersion}\" in EntitySchemaFactory.",
6
+ "noMigrationStepTarget": "No target schema for migration step {missingFromVersion} to {missingToVersion} found for \"{schemaName}\". Cannot complete migration from {stored} to {current}. Register the versioned schema class \"{schemaName}V{missingToVersion}\" in EntitySchemaFactory.",
7
+ "connectorNotMigrationCapable": "Schema \"{schemaName}\" needs migration from version {stored} to {current} but its connector does not support automatic migration. Please migrate the schema manually before starting the node."
8
+ }
9
+ },
10
+ "info": {
11
+ "schemaVersionService": {
12
+ "noMigrationRequired": "No migration required for schema \"{schemaName}\", version {version}.",
13
+ "migrationRequired": "Migration required for schema \"{schemaName}\" from version {from} to {to}.",
14
+ "partitionStart": "Starting migration of {itemTotal} partitions.",
15
+ "partitionProgress": "Migrating partition {itemIndex} of {itemTotal}.",
16
+ "partitionEnd": "Completed migration of {itemTotal} partitions.",
17
+ "partitionItemsStart": "Starting migration of {itemTotal} items in current partition.",
18
+ "partitionItemsProgress": "Migrating items in current partition: {itemIndex} of {itemTotal} processed.",
19
+ "partitionItemsEnd": "Completed migration of {itemTotal} items in current partition."
5
20
  }
6
21
  }
7
22
  }
package/package.json CHANGED
@@ -1,10 +1,10 @@
1
1
  {
2
2
  "name": "@twin.org/entity-storage-service",
3
- "version": "0.0.3-next.9",
3
+ "version": "0.9.0-next.1",
4
4
  "description": "Service layer exposing storage contracts and REST endpoint definitions.",
5
5
  "repository": {
6
6
  "type": "git",
7
- "url": "git+https://github.com/twinfoundation/entity-storage.git",
7
+ "url": "git+https://github.com/iotaledger/twin-entity-storage.git",
8
8
  "directory": "packages/entity-storage-service"
9
9
  },
10
10
  "author": "martyn.janes@iota.org",
@@ -14,12 +14,13 @@
14
14
  "node": ">=20.0.0"
15
15
  },
16
16
  "dependencies": {
17
- "@twin.org/api-models": "next",
18
- "@twin.org/core": "next",
19
- "@twin.org/entity": "next",
20
- "@twin.org/entity-storage-models": "0.0.3-next.9",
21
- "@twin.org/nameof": "next",
22
- "@twin.org/web": "next"
17
+ "@twin.org/api-models": "0.9.0-next.1",
18
+ "@twin.org/core": "0.9.0-next.1",
19
+ "@twin.org/entity": "0.9.0-next.1",
20
+ "@twin.org/entity-storage-models": "0.9.0-next.1",
21
+ "@twin.org/logging-models": "0.9.0-next.1",
22
+ "@twin.org/nameof": "0.9.0-next.1",
23
+ "@twin.org/web": "0.9.0-next.1"
23
24
  },
24
25
  "main": "./dist/es/index.js",
25
26
  "types": "./dist/types/index.d.ts",
@@ -53,7 +54,7 @@
53
54
  "business-logic"
54
55
  ],
55
56
  "bugs": {
56
- "url": "git+https://github.com/twinfoundation/entity-storage/issues"
57
+ "url": "git+https://github.com/iotaledger/twin-entity-storage/issues"
57
58
  },
58
59
  "homepage": "https://twindev.org"
59
60
  }