@twin.org/entity-storage-service 0.0.3-next.3 → 0.0.3-next.31

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 (45) hide show
  1. package/README.md +2 -2
  2. package/dist/es/entities/schemaVersion.js +39 -0
  3. package/dist/es/entities/schemaVersion.js.map +1 -0
  4. package/dist/es/entityStorageRoutes.js +176 -4
  5. package/dist/es/entityStorageRoutes.js.map +1 -1
  6. package/dist/es/entityStorageService.js +44 -49
  7. package/dist/es/entityStorageService.js.map +1 -1
  8. package/dist/es/index.js +6 -1
  9. package/dist/es/index.js.map +1 -1
  10. package/dist/es/models/IEntityStorageRoutesExamples.js.map +1 -1
  11. package/dist/es/models/ISchemaVersionServiceConfig.js +4 -0
  12. package/dist/es/models/ISchemaVersionServiceConfig.js.map +1 -0
  13. package/dist/es/models/ISchemaVersionServiceConstructorOptions.js +2 -0
  14. package/dist/es/models/ISchemaVersionServiceConstructorOptions.js.map +1 -0
  15. package/dist/es/schema.js +11 -0
  16. package/dist/es/schema.js.map +1 -0
  17. package/dist/es/schemaVersionService.js +356 -0
  18. package/dist/es/schemaVersionService.js.map +1 -0
  19. package/dist/types/entities/schemaVersion.d.ts +19 -0
  20. package/dist/types/entityStorageRoutes.d.ts +33 -1
  21. package/dist/types/entityStorageService.d.ts +38 -3
  22. package/dist/types/index.d.ts +6 -1
  23. package/dist/types/models/IEntityStorageRoutesExamples.d.ts +8 -1
  24. package/dist/types/models/ISchemaVersionServiceConfig.d.ts +9 -0
  25. package/dist/types/models/ISchemaVersionServiceConstructorOptions.d.ts +15 -0
  26. package/dist/types/schema.d.ts +4 -0
  27. package/dist/types/schemaVersionService.d.ts +52 -0
  28. package/docs/changelog.md +567 -47
  29. package/docs/examples.md +77 -1
  30. package/docs/open-api/spec.json +447 -37
  31. package/docs/reference/classes/EntityStorageService.md +123 -9
  32. package/docs/reference/classes/SchemaVersion.md +39 -0
  33. package/docs/reference/classes/SchemaVersionService.md +103 -0
  34. package/docs/reference/functions/entityStorageCount.md +31 -0
  35. package/docs/reference/functions/entityStorageEmpty.md +31 -0
  36. package/docs/reference/functions/entityStorageRemoveBatch.md +31 -0
  37. package/docs/reference/functions/entityStorageSetBatch.md +31 -0
  38. package/docs/reference/functions/initSchema.md +9 -0
  39. package/docs/reference/index.md +9 -0
  40. package/docs/reference/interfaces/IEntityStorageRoutesExamples.md +24 -8
  41. package/docs/reference/interfaces/IEntityStorageServiceConstructorOptions.md +3 -3
  42. package/docs/reference/interfaces/ISchemaVersionServiceConfig.md +11 -0
  43. package/docs/reference/interfaces/ISchemaVersionServiceConstructorOptions.md +25 -0
  44. package/locales/en.json +17 -2
  45. package/package.json +6 -5
@@ -0,0 +1,52 @@
1
+ import { type IComponent } from "@twin.org/core";
2
+ import type { ISchemaVersionServiceConstructorOptions } from "./models/ISchemaVersionServiceConstructorOptions.js";
3
+ /**
4
+ * Service that checks and applies entity schema migrations at every node start-up.
5
+ *
6
+ * This service must be the first entry in coreTypeInitialisers.json. The engine iterates that
7
+ * array in order to determine start sequence — there is no engine-level priority mechanism, so
8
+ * registration position is the only guarantee that start() runs before any other service.
9
+ * By the time start() is called, all component bootstraps have completed (every table already
10
+ * exists) and EntitySchemaFactory / EntityStorageConnectorFactory are fully populated with every
11
+ * registered schema and connector.
12
+ *
13
+ * Migration mechanics: old schema versions are registered in EntitySchemaFactory by naming
14
+ * convention — current schema = "MyEntity", first history = "MyEntityV0", second = "MyEntityV1".
15
+ * The service groups schemas by base name (strips the trailing V number suffix) and resolves the
16
+ * migration chain automatically by diffing consecutive versioned schemas. For steps that require
17
+ * property renames or a custom transform hook, register an optional ISchemaMigration entry in
18
+ * SchemaMigrationFactory under the key "Base_from_to" (e.g. "MyEntity_0_1").
19
+ *
20
+ * Crash-window note: finalizeMigration and the subsequent version-record write are two
21
+ * separate operations. If the process dies between them the next boot re-runs the chain
22
+ * over already-migrated data. applyEntityTransform is NOT idempotent for structural changes
23
+ * (newly-added optional fields would be dropped on re-run). A transaction spanning both
24
+ * writes is a precondition for production; track this in the concurrency follow-up.
25
+ */
26
+ export declare class SchemaVersionService implements IComponent {
27
+ /**
28
+ * Runtime name for the class.
29
+ */
30
+ static readonly CLASS_NAME: string;
31
+ /**
32
+ * Create a new SchemaVersionService.
33
+ * @param options Optional constructor options.
34
+ */
35
+ constructor(options?: ISchemaVersionServiceConstructorOptions);
36
+ /**
37
+ * Returns the class name.
38
+ * @returns The class name.
39
+ */
40
+ className(): string;
41
+ /**
42
+ * Reads all registered entity schemas, groups versioned schemas by base name, reads the
43
+ * full schemaVersion table in one pass, then orchestrates chain migrations for any schema
44
+ * whose stored version is behind the current version declared in EntitySchemaFactory.
45
+ * SchemaVersion itself is processed first so the version store is migrated before any
46
+ * version records are written for other schemas.
47
+ *
48
+ * Runs after all component bootstraps, so every managed table already exists.
49
+ * @param nodeLoggingComponentType An optional logging component type.
50
+ */
51
+ start(nodeLoggingComponentType?: string): Promise<void>;
52
+ }