@objectstack/metadata 3.3.0 → 4.0.0

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 (38) hide show
  1. package/dist/index.cjs +2197 -0
  2. package/dist/index.cjs.map +1 -0
  3. package/dist/index.js +42 -82
  4. package/dist/index.js.map +1 -1
  5. package/dist/node.cjs +2201 -0
  6. package/dist/node.cjs.map +1 -0
  7. package/dist/node.d.cts +65 -0
  8. package/dist/node.d.ts +65 -0
  9. package/dist/{index.mjs → node.js} +3 -1
  10. package/package.json +22 -17
  11. package/.turbo/turbo-build.log +0 -22
  12. package/CHANGELOG.md +0 -504
  13. package/ROADMAP.md +0 -224
  14. package/src/index.ts +0 -68
  15. package/src/loaders/database-loader.test.ts +0 -559
  16. package/src/loaders/database-loader.ts +0 -352
  17. package/src/loaders/filesystem-loader.ts +0 -420
  18. package/src/loaders/loader-interface.ts +0 -89
  19. package/src/loaders/memory-loader.ts +0 -103
  20. package/src/loaders/remote-loader.ts +0 -140
  21. package/src/metadata-manager.ts +0 -1168
  22. package/src/metadata-service.test.ts +0 -965
  23. package/src/metadata.test.ts +0 -431
  24. package/src/migration/executor.ts +0 -54
  25. package/src/migration/index.ts +0 -3
  26. package/src/node-metadata-manager.ts +0 -126
  27. package/src/node.ts +0 -11
  28. package/src/objects/sys-metadata.object.ts +0 -188
  29. package/src/plugin.ts +0 -102
  30. package/src/serializers/json-serializer.ts +0 -73
  31. package/src/serializers/serializer-interface.ts +0 -65
  32. package/src/serializers/serializers.test.ts +0 -74
  33. package/src/serializers/typescript-serializer.ts +0 -127
  34. package/src/serializers/yaml-serializer.ts +0 -49
  35. package/tsconfig.json +0 -9
  36. package/vitest.config.ts +0 -23
  37. /package/dist/{index.d.mts → index.d.cts} +0 -0
  38. /package/dist/{index.mjs.map → node.js.map} +0 -0
package/ROADMAP.md DELETED
@@ -1,224 +0,0 @@
1
- # @objectstack/metadata — Roadmap
2
-
3
- > **Last Updated:** 2026-02-18
4
- > Development roadmap for the ObjectStack Metadata Service.
5
-
6
- ## Current Status (v3.0)
7
-
8
- ### ✅ Implemented
9
-
10
- | Feature | Description |
11
- |:---------------------------------|:-----------------------------------------------|
12
- | `MetadataManager` | Core orchestrator implementing `IMetadataService` |
13
- | `IMetadataService` contract | Full async service interface (30+ methods) |
14
- | `FilesystemLoader` | File I/O with glob, caching, ETag, atomic writes |
15
- | `MemoryLoader` | In-memory storage for tests and overrides |
16
- | `RemoteLoader` | HTTP API loader with Bearer auth |
17
- | `DatabaseLoader` | Datasource-backed persistence via `IDataDriver` |
18
- | JSON / YAML / TypeScript serializers | Multi-format metadata serialization |
19
- | Overlay system (in-memory) | Three-scope delta patches (system/platform/user) |
20
- | Query / Search | Filtering, pagination, sorting by type/scope/state |
21
- | Bulk operations | `bulkRegister` / `bulkUnregister` with error handling |
22
- | Import / Export | Portable bundles with conflict resolution |
23
- | Type registry | 26 built-in metadata types across 6 domains |
24
- | Dependency tracking | Cross-reference analysis between metadata items |
25
- | Watch / Subscribe | Real-time change notification via callbacks |
26
- | File watching (Node.js) | Chokidar-based hot-reload for development |
27
- | Kernel plugin | `MetadataPlugin` for ObjectStack kernel integration |
28
- | Migration executor | ChangeSet-based DDL operations |
29
- | Structural validation | Basic name/type/label validation |
30
-
31
- ### 🟡 Partially Implemented
32
-
33
- | Feature | Status |
34
- |:-----------------------|:-------------------------------------------------|
35
- | Overlay persistence | In-memory only — not persisted to database yet |
36
- | Migration executor | `modify_field` and `rename_object` not complete |
37
- | Schema-level validation | Basic structural checks only — no Zod schema dispatch |
38
-
39
- ---
40
-
41
- ## Phase 1: DatabaseLoader — Datasource-Backed Persistence ✅
42
-
43
- **Goal**: Enable metadata read/write via any configured `IDataDriver`, so that platform-scope and user-scope metadata can be stored in a database.
44
-
45
- **Background**: The spec already defines `MetadataManagerConfig.datasource` (referencing a `DatasourceSchema.name`) and `MetadataRecordSchema` (the DB persistence envelope in `metadata-persistence.zod.ts`). The missing piece is the `DatabaseLoader` that bridges `IMetadataService` ↔ `IDataDriver`.
46
-
47
- ### Tasks
48
-
49
- - [x] **Implement `DatabaseLoader`** (`src/loaders/database-loader.ts`)
50
- - Implement `MetadataLoader` interface with protocol `datasource:`
51
- - Accept an `IDataDriver` instance (injected at initialization)
52
- - Read/write to the `sys_metadata` table (configurable via `MetadataManagerConfig.tableName`)
53
- - Map metadata operations to `IDataDriver` CRUD methods (`find`, `findOne`, `create`, `update`, `delete`)
54
- - Serialize metadata payload to the `MetadataRecordSchema` envelope
55
- - Support multi-tenant isolation via `tenantId` filter
56
- - Support optimistic concurrency via `version` field
57
- - Support `scope` filtering (system/platform/user)
58
- - Implement `list()` with type filtering and pagination
59
- - Implement `exists()` and `stat()` via driver queries
60
- - Implement `save()` with upsert semantics (create or update)
61
- - Declare capabilities: `{ read: true, write: true, watch: false, list: true }`
62
-
63
- - [x] **Integrate DatabaseLoader into MetadataManager**
64
- - Auto-configure `DatabaseLoader` when `config.datasource` + `config.driver` is set
65
- - `setDatabaseDriver(driver)` for deferred setup via kernel service registry
66
- - Loader priority: DatabaseLoader for platform/user scope, FilesystemLoader for system scope
67
-
68
- - [x] **Schema bootstrapping**
69
- - Auto-create `sys_metadata` table on first use via `IDataDriver.syncSchema()`
70
- - Define column schema: `id`, `name`, `type`, `namespace`, `scope`, `metadata` (JSON), `state`, `version`, `tenant_id`, audit fields
71
- - Idempotent — only calls syncSchema once per loader instance
72
-
73
- - [x] **Tests**
74
- - Unit tests with mock IDataDriver (31 tests)
75
- - Integration tests for MetadataManager + DatabaseLoader (9 tests)
76
- - Error handling and fallback behavior tests
77
-
78
- ### Spec Dependencies (Already Defined)
79
-
80
- | Spec | What It Provides |
81
- |:----------------------------------|:-----------------------------------------|
82
- | `MetadataManagerConfigSchema` | `datasource`, `tableName`, `fallback` fields |
83
- | `MetadataRecordSchema` | DB record envelope with scope, state, version |
84
- | `MetadataLoaderContractSchema` | Protocol `datasource:` declaration |
85
- | `IDataDriver` | `find`, `findOne`, `create`, `update`, `delete` |
86
- | `ISchemaDriver` | `createCollection`, `addColumn` for DDL |
87
- | `DatasourceSchema` | Connection config with pool, SSL, retry |
88
-
89
- ---
90
-
91
- ## Phase 2: Overlay Persistence & UI Metadata Support 🔴
92
-
93
- **Goal**: Persist overlay customizations to the database so that admin and user customizations survive restarts, and expose APIs that the Studio UI can consume.
94
-
95
- ### Tasks
96
-
97
- - [ ] **Persist overlays to database**
98
- - Store overlays as `MetadataRecord` entries with `scope: 'platform'` or `scope: 'user'`
99
- - Use `extends` field to reference the base system metadata
100
- - Use `strategy` field ('merge' or 'replace') to control overlay application
101
- - Add `managedBy` tracking ('package', 'platform', 'user')
102
-
103
- - [ ] **Implement `getEffective()` with database-backed resolution**
104
- - Load base (system, from filesystem) → merge platform overlay (from DB) → merge user overlay (from DB)
105
- - Cache effective results with invalidation on overlay changes
106
- - Support conflict detection when base metadata is upgraded
107
-
108
- - [ ] **REST API for metadata CRUD**
109
- - `GET /api/metadata/:type` — list metadata items by type
110
- - `GET /api/metadata/:type/:name` — get metadata item
111
- - `GET /api/metadata/:type/:name/effective` — get merged effective metadata
112
- - `PUT /api/metadata/:type/:name` — create/update metadata (platform scope)
113
- - `DELETE /api/metadata/:type/:name` — remove metadata
114
- - `GET /api/metadata/:type/:name/overlays` — list overlays
115
- - `PUT /api/metadata/:type/:name/overlays/:scope` — save overlay
116
- - `POST /api/metadata/query` — query with filters, pagination
117
- - `POST /api/metadata/import` / `GET /api/metadata/export` — bulk operations
118
-
119
- - [ ] **Permission integration**
120
- - Scope-based access control: system (read-only), platform (admin), user (self)
121
- - Integrate with `IAuthService` for permission checks
122
- - Validate `owner` field for user-scope metadata
123
-
124
- - [ ] **Watch / Events for database changes**
125
- - Implement polling-based change detection for DatabaseLoader
126
- - Emit `MetadataWatchEvent` when database records change
127
- - Support webhook notifications for external consumers
128
-
129
- ---
130
-
131
- ## Phase 3: Schema Validation & Zod Dispatch 🔴
132
-
133
- **Goal**: Full schema validation by dispatching to the correct Zod schema based on metadata type.
134
-
135
- ### Tasks
136
-
137
- - [ ] **Zod schema registry**
138
- - Map metadata type → Zod schema (e.g., `object` → `ObjectSchema`, `view` → `ViewSchema`)
139
- - Register schemas from `@objectstack/spec` automatically
140
- - Support plugin-contributed custom type schemas
141
-
142
- - [ ] **Enhanced `validate()` method**
143
- - Dispatch to the correct Zod schema per metadata type
144
- - Return structured errors with path, message, expected/received
145
- - Support `strict` mode (reject unknown fields) and `lenient` mode (warn only)
146
- - Validate cross-references (e.g., view references a valid object)
147
-
148
- - [ ] **Validation on write**
149
- - Optionally validate metadata on `register()` and `save()`
150
- - Configurable via `MetadataManagerConfig.validation.strict`
151
-
152
- ---
153
-
154
- ## Phase 4: Advanced Features 🔴
155
-
156
- ### 4a. Metadata Versioning & History
157
-
158
- - [ ] Track metadata change history in the database
159
- - [ ] Support `version` field with auto-increment on save
160
- - [ ] Implement `getHistory(type, name)` to retrieve version timeline
161
- - [ ] Implement `rollback(type, name, version)` to restore a previous version
162
- - [ ] Add `checksum` field for change detection
163
-
164
- ### 4b. Package Upgrade & Three-Way Merge
165
-
166
- - [ ] Implement three-way merge when upgrading package-delivered metadata
167
- - Base: previous package version
168
- - Ours: current platform customizations (overlays)
169
- - Theirs: new package version
170
- - [ ] Merge conflict detection and resolution UI support
171
- - [ ] Leverage `MergeStrategyConfigSchema` from spec (keep-custom, accept-incoming, three-way-merge)
172
-
173
- ### 4c. Metadata Sync & Distribution
174
-
175
- - [ ] `pull` — download metadata from a remote ObjectStack instance
176
- - [ ] `push` — upload local metadata to a remote instance
177
- - [ ] Selective sync by type, namespace, or package
178
- - [ ] Conflict detection across instances
179
-
180
- ### 4d. S3/Cloud Loader
181
-
182
- - [ ] Implement `S3Loader` for cloud-native metadata storage
183
- - [ ] Support `s3:` protocol in `MetadataLoaderContract`
184
- - [ ] Integrate with object storage for large metadata bundles
185
-
186
- ---
187
-
188
- ## Phase 5: Performance & Production Readiness 🔴
189
-
190
- - [ ] **Caching layer**
191
- - Implement TTL-based cache with configurable `maxSize`
192
- - Cache invalidation on write/overlay changes
193
- - Support distributed cache (Redis) for multi-instance deployments
194
- - [ ] **Connection pooling**
195
- - Reuse `IDataDriver` connections efficiently
196
- - Handle connection failures gracefully with retry policy
197
- - [ ] **Batch loading optimization**
198
- - Load multiple types in a single query where possible
199
- - Implement DataLoader-style batching for N+1 prevention
200
- - [ ] **Metrics & observability**
201
- - Track load/save latency, cache hit rates, loader usage
202
- - Expose metrics via kernel observability contract
203
-
204
- ---
205
-
206
- ## Milestone Summary
207
-
208
- | Phase | Target | Description | Status |
209
- |:------|:--------|:----------------------------------------------|:-------|
210
- | — | v3.0 | Core MetadataManager, Filesystem/Memory/Remote | ✅ Done |
211
- | 1 | v3.1 | DatabaseLoader — datasource-backed persistence | 🔴 Planned |
212
- | 2 | v3.2 | Overlay persistence, REST API, UI support | 🔴 Planned |
213
- | 3 | v3.3 | Schema validation & Zod dispatch | 🔴 Planned |
214
- | 4 | v4.0 | Versioning, merge, sync, S3 loader | 🔴 Planned |
215
- | 5 | v4.1 | Caching, pooling, observability | 🔴 Planned |
216
-
217
- ---
218
-
219
- ## Related Documents
220
-
221
- - [Root ROADMAP](../../ROADMAP.md) — Full platform evolution (v3.0 → v5.0)
222
- - [Studio ROADMAP](../../apps/studio/ROADMAP.md) — Visual IDE development phases
223
- - [Metadata Service Protocol](../../content/docs/protocol/objectos/metadata-service.mdx) — Detailed protocol documentation
224
- - [DX ROADMAP](../../docs/DX_ROADMAP.md) — Developer experience improvements
package/src/index.ts DELETED
@@ -1,68 +0,0 @@
1
- // Copyright (c) 2025 ObjectStack. Licensed under the Apache-2.0 license.
2
-
3
- /**
4
- * @objectstack/metadata
5
- *
6
- * Metadata loading, saving, and persistence for ObjectStack.
7
- * Implements the IMetadataService contract from @objectstack/spec.
8
- */
9
-
10
- // Main Manager
11
- export { MetadataManager, type WatchCallback, type MetadataManagerOptions } from './metadata-manager.js';
12
-
13
- // Plugin
14
- export { MetadataPlugin } from './plugin.js';
15
-
16
- // Loaders
17
- export { type MetadataLoader } from './loaders/loader-interface.js';
18
- export { MemoryLoader } from './loaders/memory-loader.js';
19
- export { RemoteLoader } from './loaders/remote-loader.js';
20
- export { DatabaseLoader, type DatabaseLoaderOptions } from './loaders/database-loader.js';
21
-
22
- // Objects
23
- export { SysMetadataObject } from './objects/sys-metadata.object.js';
24
-
25
- // Serializers
26
- export { type MetadataSerializer, type SerializeOptions } from './serializers/serializer-interface.js';
27
- export { JSONSerializer } from './serializers/json-serializer.js';
28
- export { YAMLSerializer } from './serializers/yaml-serializer.js';
29
- export * as Migration from './migration/index.js';
30
- export { TypeScriptSerializer } from './serializers/typescript-serializer.js';
31
-
32
- // Re-export types from spec
33
- export type {
34
- MetadataFormat,
35
- MetadataStats,
36
- MetadataLoadOptions,
37
- MetadataSaveOptions,
38
- MetadataExportOptions,
39
- MetadataImportOptions,
40
- MetadataLoadResult,
41
- MetadataSaveResult,
42
- MetadataWatchEvent,
43
- MetadataCollectionInfo,
44
- MetadataLoaderContract,
45
- MetadataManagerConfig,
46
- } from '@objectstack/spec/system';
47
-
48
- // Re-export IMetadataService contract
49
- export type {
50
- IMetadataService,
51
- MetadataWatchCallback,
52
- MetadataWatchHandle,
53
- MetadataTypeInfo,
54
- MetadataImportResult,
55
- } from '@objectstack/spec/contracts';
56
-
57
- // Re-export kernel types for plugin protocol
58
- export type {
59
- MetadataType,
60
- MetadataTypeRegistryEntry,
61
- MetadataPluginConfig,
62
- MetadataPluginManifest,
63
- MetadataQuery,
64
- MetadataQueryResult,
65
- MetadataValidationResult,
66
- MetadataBulkResult,
67
- MetadataDependency,
68
- } from '@objectstack/spec/kernel';