@objectstack/metadata 2.0.7 → 3.0.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.
- package/.turbo/turbo-build.log +10 -10
- package/CHANGELOG.md +22 -0
- package/dist/index.d.mts +140 -20
- package/dist/index.d.ts +140 -20
- package/dist/index.js +542 -42
- package/dist/index.js.map +1 -1
- package/dist/index.mjs +542 -42
- package/dist/index.mjs.map +1 -1
- package/package.json +4 -4
- package/src/index.ts +24 -1
- package/src/metadata-manager.ts +680 -49
- package/src/metadata-service.test.ts +611 -0
- package/src/metadata.test.ts +15 -17
- package/src/plugin.ts +23 -14
- package/vitest.config.ts +2 -0
package/src/plugin.ts
CHANGED
|
@@ -2,11 +2,13 @@
|
|
|
2
2
|
|
|
3
3
|
import { Plugin, PluginContext } from '@objectstack/core';
|
|
4
4
|
import { NodeMetadataManager } from './node-metadata-manager.js';
|
|
5
|
-
import {
|
|
5
|
+
import { DEFAULT_METADATA_TYPE_REGISTRY } from '@objectstack/spec/kernel';
|
|
6
|
+
import type { MetadataPluginConfig } from '@objectstack/spec/kernel';
|
|
6
7
|
|
|
7
8
|
export interface MetadataPluginOptions {
|
|
8
9
|
rootDir?: string;
|
|
9
10
|
watch?: boolean;
|
|
11
|
+
config?: Partial<MetadataPluginConfig>;
|
|
10
12
|
}
|
|
11
13
|
|
|
12
14
|
export class MetadataPlugin implements Plugin {
|
|
@@ -30,6 +32,9 @@ export class MetadataPlugin implements Plugin {
|
|
|
30
32
|
watch: this.options.watch ?? true,
|
|
31
33
|
formats: ['yaml', 'json', 'typescript', 'javascript']
|
|
32
34
|
});
|
|
35
|
+
|
|
36
|
+
// Initialize with default type registry
|
|
37
|
+
this.manager.setTypeRegistry(DEFAULT_METADATA_TYPE_REGISTRY);
|
|
33
38
|
}
|
|
34
39
|
|
|
35
40
|
init = async (ctx: PluginContext) => {
|
|
@@ -43,39 +48,43 @@ export class MetadataPlugin implements Plugin {
|
|
|
43
48
|
ctx.registerService('metadata', this.manager);
|
|
44
49
|
ctx.logger.info('MetadataPlugin providing metadata service (primary mode)', {
|
|
45
50
|
mode: 'file-system',
|
|
46
|
-
features: ['watch', 'persistence', 'multi-format']
|
|
51
|
+
features: ['watch', 'persistence', 'multi-format', 'query', 'overlay', 'type-registry']
|
|
47
52
|
});
|
|
48
53
|
}
|
|
49
54
|
|
|
50
55
|
start = async (ctx: PluginContext) => {
|
|
51
56
|
ctx.logger.info('Loading metadata from file system...');
|
|
52
57
|
|
|
53
|
-
//
|
|
54
|
-
|
|
55
|
-
|
|
56
|
-
.filter(key => key !== 'manifest'); // Manifest is handled separately
|
|
58
|
+
// Use the type registry to discover metadata types (sorted by loadOrder)
|
|
59
|
+
const sortedTypes = [...DEFAULT_METADATA_TYPE_REGISTRY]
|
|
60
|
+
.sort((a, b) => a.loadOrder - b.loadOrder);
|
|
57
61
|
|
|
58
62
|
let totalLoaded = 0;
|
|
59
|
-
for (const
|
|
63
|
+
for (const entry of sortedTypes) {
|
|
60
64
|
try {
|
|
61
|
-
|
|
62
|
-
const items = await this.manager.loadMany(type, {
|
|
65
|
+
const items = await this.manager.loadMany(entry.type, {
|
|
63
66
|
recursive: true
|
|
64
67
|
});
|
|
65
68
|
|
|
66
69
|
if (items.length > 0) {
|
|
67
|
-
|
|
68
|
-
|
|
70
|
+
// Register loaded items in the in-memory registry
|
|
71
|
+
for (const item of items) {
|
|
72
|
+
const meta = item as any;
|
|
73
|
+
if (meta?.name) {
|
|
74
|
+
await this.manager.register(entry.type, meta.name, item);
|
|
75
|
+
}
|
|
76
|
+
}
|
|
77
|
+
ctx.logger.info(`Loaded ${items.length} ${entry.type} from file system`);
|
|
78
|
+
totalLoaded += items.length;
|
|
69
79
|
}
|
|
70
80
|
} catch (e: any) {
|
|
71
|
-
|
|
72
|
-
ctx.logger.debug(`No ${type} metadata found`, { error: e.message });
|
|
81
|
+
ctx.logger.debug(`No ${entry.type} metadata found`, { error: e.message });
|
|
73
82
|
}
|
|
74
83
|
}
|
|
75
84
|
|
|
76
85
|
ctx.logger.info('Metadata loading complete', {
|
|
77
86
|
totalItems: totalLoaded,
|
|
78
|
-
|
|
87
|
+
registeredTypes: sortedTypes.length,
|
|
79
88
|
});
|
|
80
89
|
}
|
|
81
90
|
}
|
package/vitest.config.ts
CHANGED
|
@@ -7,6 +7,8 @@ export default defineConfig({
|
|
|
7
7
|
resolve: {
|
|
8
8
|
alias: {
|
|
9
9
|
'@objectstack/core': path.resolve(__dirname, '../core/src/index.ts'),
|
|
10
|
+
'@objectstack/spec/contracts': path.resolve(__dirname, '../spec/src/contracts/index.ts'),
|
|
11
|
+
'@objectstack/spec/kernel': path.resolve(__dirname, '../spec/src/kernel/index.ts'),
|
|
10
12
|
'@objectstack/spec/system': path.resolve(__dirname, '../spec/src/system/index.ts'),
|
|
11
13
|
'@objectstack/spec': path.resolve(__dirname, '../spec/src/index.ts'),
|
|
12
14
|
'@objectstack/types': path.resolve(__dirname, '../types/src/index.ts'),
|