@objectstack/metadata 0.8.1 → 0.8.2

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/CHANGELOG.md CHANGED
@@ -1,5 +1,14 @@
1
1
  # @objectstack/metadata
2
2
 
3
+ ## 0.8.2
4
+
5
+ ### Patch Changes
6
+
7
+ - Updated dependencies [555e6a7]
8
+ - @objectstack/spec@0.8.2
9
+ - @objectstack/core@0.8.2
10
+ - @objectstack/types@0.8.2
11
+
3
12
  ## 0.8.1
4
13
 
5
14
  ### Patch Changes
package/dist/index.d.ts CHANGED
@@ -4,6 +4,7 @@
4
4
  * Metadata loading, saving, and persistence for ObjectStack
5
5
  */
6
6
  export { MetadataManager, type WatchCallback } from './metadata-manager.js';
7
+ export { MetadataPlugin } from './plugin.js';
7
8
  export { type MetadataLoader } from './loaders/loader-interface.js';
8
9
  export { FilesystemLoader } from './loaders/filesystem-loader.js';
9
10
  export { type MetadataSerializer, type SerializeOptions } from './serializers/serializer-interface.js';
@@ -1 +1 @@
1
- {"version":3,"file":"index.d.ts","sourceRoot":"","sources":["../src/index.ts"],"names":[],"mappings":"AAAA;;;;GAIG;AAGH,OAAO,EAAE,eAAe,EAAE,KAAK,aAAa,EAAE,MAAM,uBAAuB,CAAC;AAG5E,OAAO,EAAE,KAAK,cAAc,EAAE,MAAM,+BAA+B,CAAC;AACpE,OAAO,EAAE,gBAAgB,EAAE,MAAM,gCAAgC,CAAC;AAGlE,OAAO,EAAE,KAAK,kBAAkB,EAAE,KAAK,gBAAgB,EAAE,MAAM,uCAAuC,CAAC;AACvG,OAAO,EAAE,cAAc,EAAE,MAAM,kCAAkC,CAAC;AAClE,OAAO,EAAE,cAAc,EAAE,MAAM,kCAAkC,CAAC;AAClE,OAAO,EAAE,oBAAoB,EAAE,MAAM,wCAAwC,CAAC;AAG9E,YAAY,EACV,cAAc,EACd,aAAa,EACb,mBAAmB,EACnB,mBAAmB,EACnB,qBAAqB,EACrB,qBAAqB,EACrB,kBAAkB,EAClB,kBAAkB,EAClB,kBAAkB,EAClB,sBAAsB,EACtB,sBAAsB,EACtB,qBAAqB,GACtB,MAAM,0BAA0B,CAAC"}
1
+ {"version":3,"file":"index.d.ts","sourceRoot":"","sources":["../src/index.ts"],"names":[],"mappings":"AAAA;;;;GAIG;AAGH,OAAO,EAAE,eAAe,EAAE,KAAK,aAAa,EAAE,MAAM,uBAAuB,CAAC;AAG5E,OAAO,EAAE,cAAc,EAAE,MAAM,aAAa,CAAC;AAG7C,OAAO,EAAE,KAAK,cAAc,EAAE,MAAM,+BAA+B,CAAC;AACpE,OAAO,EAAE,gBAAgB,EAAE,MAAM,gCAAgC,CAAC;AAGlE,OAAO,EAAE,KAAK,kBAAkB,EAAE,KAAK,gBAAgB,EAAE,MAAM,uCAAuC,CAAC;AACvG,OAAO,EAAE,cAAc,EAAE,MAAM,kCAAkC,CAAC;AAClE,OAAO,EAAE,cAAc,EAAE,MAAM,kCAAkC,CAAC;AAClE,OAAO,EAAE,oBAAoB,EAAE,MAAM,wCAAwC,CAAC;AAG9E,YAAY,EACV,cAAc,EACd,aAAa,EACb,mBAAmB,EACnB,mBAAmB,EACnB,qBAAqB,EACrB,qBAAqB,EACrB,kBAAkB,EAClB,kBAAkB,EAClB,kBAAkB,EAClB,sBAAsB,EACtB,sBAAsB,EACtB,qBAAqB,GACtB,MAAM,0BAA0B,CAAC"}
package/dist/index.js CHANGED
@@ -5,6 +5,8 @@
5
5
  */
6
6
  // Main Manager
7
7
  export { MetadataManager } from './metadata-manager.js';
8
+ // Plugin
9
+ export { MetadataPlugin } from './plugin.js';
8
10
  export { FilesystemLoader } from './loaders/filesystem-loader.js';
9
11
  export { JSONSerializer } from './serializers/json-serializer.js';
10
12
  export { YAMLSerializer } from './serializers/yaml-serializer.js';
@@ -0,0 +1,15 @@
1
+ import { Plugin, PluginContext } from '@objectstack/core';
2
+ export interface MetadataPluginOptions {
3
+ rootDir?: string;
4
+ watch?: boolean;
5
+ }
6
+ export declare class MetadataPlugin implements Plugin {
7
+ name: string;
8
+ version: string;
9
+ private manager;
10
+ private options;
11
+ constructor(options?: MetadataPluginOptions);
12
+ init(ctx: PluginContext): Promise<void>;
13
+ start(ctx: PluginContext): Promise<void>;
14
+ }
15
+ //# sourceMappingURL=plugin.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"plugin.d.ts","sourceRoot":"","sources":["../src/plugin.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,MAAM,EAAE,aAAa,EAAE,MAAM,mBAAmB,CAAC;AAI1D,MAAM,WAAW,qBAAqB;IAClC,OAAO,CAAC,EAAE,MAAM,CAAC;IACjB,KAAK,CAAC,EAAE,OAAO,CAAC;CACnB;AAED,qBAAa,cAAe,YAAW,MAAM;IACzC,IAAI,SAA8B;IAClC,OAAO,SAAW;IAElB,OAAO,CAAC,OAAO,CAAkB;IACjC,OAAO,CAAC,OAAO,CAAwB;gBAE3B,OAAO,GAAE,qBAA0B;IAezC,IAAI,CAAC,GAAG,EAAE,aAAa;IAQvB,KAAK,CAAC,GAAG,EAAE,aAAa;CAiDjC"}
package/dist/plugin.js ADDED
@@ -0,0 +1,71 @@
1
+ import { MetadataManager } from './metadata-manager.js';
2
+ import { ObjectStackDefinitionSchema } from '@objectstack/spec';
3
+ export class MetadataPlugin {
4
+ constructor(options = {}) {
5
+ this.name = 'com.objectstack.metadata';
6
+ this.version = '1.0.0';
7
+ this.options = {
8
+ watch: true,
9
+ ...options
10
+ };
11
+ const rootDir = this.options.rootDir || process.cwd();
12
+ this.manager = new MetadataManager({
13
+ rootDir,
14
+ watch: this.options.watch ?? true,
15
+ formats: ['yaml', 'json', 'typescript', 'javascript']
16
+ });
17
+ }
18
+ async init(ctx) {
19
+ ctx.logger.info('Initializing Metadata Manager', { root: this.options.rootDir || process.cwd() });
20
+ // Register Metadata Manager as a service
21
+ // This allows other plugins to query raw metadata or listen to changes
22
+ ctx.registerService('metadata', this.manager);
23
+ }
24
+ async start(ctx) {
25
+ ctx.logger.info('Loading metadata...');
26
+ // Define metadata types directly from the Protocol Definition
27
+ // This ensures the loader is always in sync with the Spec
28
+ const metadataTypes = Object.keys(ObjectStackDefinitionSchema.shape)
29
+ .filter(key => key !== 'manifest'); // Manifest is handled separately
30
+ for (const type of metadataTypes) {
31
+ try {
32
+ // Try to load metadata of this type
33
+ const items = await this.manager.loadMany(type, {
34
+ recursive: true
35
+ });
36
+ if (items.length > 0) {
37
+ ctx.logger.info(`Loaded ${items.length} ${type}`);
38
+ // Helper: Register with ObjectQL Registry
39
+ const ql = ctx.getService('objectql');
40
+ if (ql && ql.registry) {
41
+ items.forEach((item) => {
42
+ // Determine key field (id or name)
43
+ const keyField = item.id ? 'id' : 'name';
44
+ // Map plural type to singular/registry type if needed
45
+ // For now, we use the singular form for standard types:
46
+ // objects -> object, apps -> app, etc.
47
+ // But Registry seems to accept arbitrary strings.
48
+ // To match Protocol standard, we might want to normalize.
49
+ // Let's use the directory name (plural) as the type for now,
50
+ // OR map 'objects' -> 'object' specifically.
51
+ let registryType = type;
52
+ if (type === 'objects')
53
+ registryType = 'object';
54
+ if (type === 'apps')
55
+ registryType = 'app';
56
+ if (type === 'plugins')
57
+ registryType = 'plugin';
58
+ if (type === 'functions')
59
+ registryType = 'function';
60
+ ql.registry.registerItem(registryType, item, keyField);
61
+ });
62
+ }
63
+ }
64
+ }
65
+ catch (e) {
66
+ // Ignore missing directories or errors
67
+ // ctx.logger.debug(`No metadata found for type: ${type}`);
68
+ }
69
+ }
70
+ }
71
+ }
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@objectstack/metadata",
3
- "version": "0.8.1",
3
+ "version": "0.8.2",
4
4
  "description": "Metadata loading, saving, and persistence for ObjectStack",
5
5
  "main": "src/index.ts",
6
6
  "types": "src/index.ts",
@@ -16,9 +16,9 @@
16
16
  "js-yaml": "^4.1.0",
17
17
  "chokidar": "^3.5.3",
18
18
  "zod": "^4.3.6",
19
- "@objectstack/core": "0.8.1",
20
- "@objectstack/spec": "0.8.1",
21
- "@objectstack/types": "0.8.1"
19
+ "@objectstack/core": "0.8.2",
20
+ "@objectstack/spec": "0.8.2",
21
+ "@objectstack/types": "0.8.2"
22
22
  },
23
23
  "devDependencies": {
24
24
  "@types/js-yaml": "^4.0.9",
package/src/index.ts CHANGED
@@ -7,6 +7,9 @@
7
7
  // Main Manager
8
8
  export { MetadataManager, type WatchCallback } from './metadata-manager.js';
9
9
 
10
+ // Plugin
11
+ export { MetadataPlugin } from './plugin.js';
12
+
10
13
  // Loaders
11
14
  export { type MetadataLoader } from './loaders/loader-interface.js';
12
15
  export { FilesystemLoader } from './loaders/filesystem-loader.js';
package/src/plugin.ts ADDED
@@ -0,0 +1,89 @@
1
+ import { Plugin, PluginContext } from '@objectstack/core';
2
+ import { MetadataManager } from './metadata-manager.js';
3
+ import { ObjectStackDefinitionSchema } from '@objectstack/spec';
4
+
5
+ export interface MetadataPluginOptions {
6
+ rootDir?: string;
7
+ watch?: boolean;
8
+ }
9
+
10
+ export class MetadataPlugin implements Plugin {
11
+ name = 'com.objectstack.metadata';
12
+ version = '1.0.0';
13
+
14
+ private manager: MetadataManager;
15
+ private options: MetadataPluginOptions;
16
+
17
+ constructor(options: MetadataPluginOptions = {}) {
18
+ this.options = {
19
+ watch: true,
20
+ ...options
21
+ };
22
+
23
+ const rootDir = this.options.rootDir || process.cwd();
24
+
25
+ this.manager = new MetadataManager({
26
+ rootDir,
27
+ watch: this.options.watch ?? true,
28
+ formats: ['yaml', 'json', 'typescript', 'javascript']
29
+ });
30
+ }
31
+
32
+ async init(ctx: PluginContext) {
33
+ ctx.logger.info('Initializing Metadata Manager', { root: this.options.rootDir || process.cwd() });
34
+
35
+ // Register Metadata Manager as a service
36
+ // This allows other plugins to query raw metadata or listen to changes
37
+ ctx.registerService('metadata', this.manager);
38
+ }
39
+
40
+ async start(ctx: PluginContext) {
41
+ ctx.logger.info('Loading metadata...');
42
+
43
+ // Define metadata types directly from the Protocol Definition
44
+ // This ensures the loader is always in sync with the Spec
45
+ const metadataTypes = Object.keys(ObjectStackDefinitionSchema.shape)
46
+ .filter(key => key !== 'manifest'); // Manifest is handled separately
47
+
48
+ for (const type of metadataTypes) {
49
+ try {
50
+ // Try to load metadata of this type
51
+ const items = await this.manager.loadMany(type, {
52
+ recursive: true
53
+ });
54
+
55
+ if (items.length > 0) {
56
+ ctx.logger.info(`Loaded ${items.length} ${type}`);
57
+
58
+ // Helper: Register with ObjectQL Registry
59
+ const ql = ctx.getService('objectql') as any;
60
+ if (ql && ql.registry) {
61
+ items.forEach((item: any) => {
62
+ // Determine key field (id or name)
63
+ const keyField = item.id ? 'id' : 'name';
64
+
65
+ // Map plural type to singular/registry type if needed
66
+ // For now, we use the singular form for standard types:
67
+ // objects -> object, apps -> app, etc.
68
+ // But Registry seems to accept arbitrary strings.
69
+ // To match Protocol standard, we might want to normalize.
70
+ // Let's use the directory name (plural) as the type for now,
71
+ // OR map 'objects' -> 'object' specifically.
72
+
73
+ let registryType = type;
74
+ if (type === 'objects') registryType = 'object';
75
+ if (type === 'apps') registryType = 'app';
76
+ if (type === 'plugins') registryType = 'plugin';
77
+ if (type === 'functions') registryType = 'function';
78
+
79
+ ql.registry.registerItem(registryType, item, keyField);
80
+ });
81
+ }
82
+ }
83
+ } catch (e: any) {
84
+ // Ignore missing directories or errors
85
+ // ctx.logger.debug(`No metadata found for type: ${type}`);
86
+ }
87
+ }
88
+ }
89
+ }