@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/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 { ObjectStackDefinitionSchema } from '@objectstack/spec';
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
- // Define metadata types directly from the Protocol Definition
54
- // This ensures the loader is always in sync with the Spec
55
- const metadataTypes = Object.keys(ObjectStackDefinitionSchema.shape)
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 type of metadataTypes) {
63
+ for (const entry of sortedTypes) {
60
64
  try {
61
- // Try to load metadata of this type
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
- ctx.logger.info(`Loaded ${items.length} ${type} from file system`);
68
- totalLoaded += items.length;
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
- // Ignore missing directories or errors
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
- note: 'ObjectQL will sync these into its registry during its start phase'
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'),