Skip to content

Commit d4bbac0

Browse files
committed
feat(metadata): enhance filesystem loader and update schemas with new properties
1 parent 427bc7f commit d4bbac0

7 files changed

Lines changed: 47 additions & 14 deletions

File tree

packages/metadata/src/loaders/filesystem-loader.ts

Lines changed: 9 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -22,6 +22,13 @@ import type { MetadataSerializer } from '../serializers/serializer-interface.js'
2222
export class FilesystemLoader implements MetadataLoader {
2323
readonly contract: MetadataLoaderContract = {
2424
name: 'filesystem',
25+
protocol: 'file',
26+
capabilities: {
27+
read: true,
28+
write: true,
29+
watch: true,
30+
list: true,
31+
},
2532
supportedFormats: ['json', 'yaml', 'typescript', 'javascript'],
2633
supportsWatch: true,
2734
supportsWrite: true,
@@ -99,7 +106,7 @@ export class FilesystemLoader implements MetadataLoader {
99106

100107
// Load and deserialize
101108
const content = await fs.readFile(filePath, 'utf-8');
102-
const serializer = this.getSerializer(stats.format);
109+
const serializer = this.getSerializer(stats.format!);
103110

104111
if (!serializer) {
105112
throw new Error(`No serializer found for format: ${stats.format}`);
@@ -111,7 +118,7 @@ export class FilesystemLoader implements MetadataLoader {
111118
if (useCache) {
112119
this.cache.set(cacheKey, {
113120
data,
114-
etag: stats.etag,
121+
etag: stats.etag || '',
115122
timestamp: Date.now(),
116123
});
117124
}

packages/spec/json-schema/system/MetadataLoadResult.json

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -66,6 +66,9 @@
6666
},
6767
"notModified": {
6868
"type": "boolean"
69+
},
70+
"loadTime": {
71+
"type": "number"
6972
}
7073
},
7174
"additionalProperties": false

packages/spec/json-schema/system/MetadataLoaderContract.json

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -22,6 +22,12 @@
2222
"supportsWatch": {
2323
"type": "boolean"
2424
},
25+
"supportsWrite": {
26+
"type": "boolean"
27+
},
28+
"supportsCache": {
29+
"type": "boolean"
30+
},
2531
"capabilities": {
2632
"type": "object",
2733
"properties": {

packages/spec/json-schema/system/MetadataManagerConfig.json

Lines changed: 2 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -8,12 +8,10 @@
88
"type": "array"
99
},
1010
"watch": {
11-
"type": "boolean",
12-
"default": false
11+
"type": "boolean"
1312
},
1413
"cache": {
15-
"type": "boolean",
16-
"default": true
14+
"type": "boolean"
1715
},
1816
"basePath": {
1917
"type": "string"
@@ -38,9 +36,6 @@
3836
},
3937
"watchOptions": {}
4038
},
41-
"required": [
42-
"loaders"
43-
],
4439
"additionalProperties": false
4540
}
4641
},

packages/spec/json-schema/system/MetadataSaveResult.json

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -53,6 +53,12 @@
5353
},
5454
"size": {
5555
"type": "number"
56+
},
57+
"saveTime": {
58+
"type": "number"
59+
},
60+
"backupPath": {
61+
"type": "string"
5662
}
5763
},
5864
"required": [

packages/spec/json-schema/system/MetadataWatchEvent.json

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -18,6 +18,9 @@
1818
"path": {
1919
"type": "string"
2020
},
21+
"name": {
22+
"type": "string"
23+
},
2124
"stats": {
2225
"type": "object",
2326
"properties": {
@@ -58,6 +61,11 @@
5861
},
5962
"metadataType": {
6063
"type": "string"
64+
},
65+
"data": {},
66+
"timestamp": {
67+
"type": "string",
68+
"format": "date-time"
6169
}
6270
},
6371
"required": [

packages/spec/src/system/metadata-persistence.zod.ts

Lines changed: 13 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -103,9 +103,9 @@ export const MetadataStatsSchema = z.object({
103103
size: z.number().optional(),
104104
mtime: z.date().optional(),
105105
hash: z.string().optional(),
106-
etag: z.string().optional(),
106+
etag: z.string().optional(), // Required by local cache
107107
modifiedAt: z.date().optional(), // Alias for mtime
108-
format: MetadataFormatSchema.optional(),
108+
format: MetadataFormatSchema.optional(), // Required for serialization
109109
});
110110

111111
/**
@@ -118,6 +118,8 @@ export const MetadataLoaderContractSchema = z.object({
118118
description: z.string().optional(),
119119
supportedFormats: z.array(z.string()).optional(),
120120
supportsWatch: z.boolean().optional(),
121+
supportsWrite: z.boolean().optional(),
122+
supportsCache: z.boolean().optional(),
121123
capabilities: z.object({
122124
read: z.boolean().default(true),
123125
write: z.boolean().default(false),
@@ -153,6 +155,7 @@ export const MetadataLoadResultSchema = z.object({
153155
fromCache: z.boolean().optional(),
154156
etag: z.string().optional(),
155157
notModified: z.boolean().optional(),
158+
loadTime: z.number().optional(),
156159
});
157160

158161
/**
@@ -179,6 +182,8 @@ export const MetadataSaveResultSchema = z.object({
179182
stats: MetadataStatsSchema.optional(),
180183
etag: z.string().optional(),
181184
size: z.number().optional(),
185+
saveTime: z.number().optional(),
186+
backupPath: z.string().optional(),
182187
});
183188

184189
/**
@@ -187,8 +192,11 @@ export const MetadataSaveResultSchema = z.object({
187192
export const MetadataWatchEventSchema = z.object({
188193
type: z.enum(['add', 'change', 'unlink', 'added', 'changed', 'deleted']),
189194
path: z.string(),
195+
name: z.string().optional(),
190196
stats: MetadataStatsSchema.optional(),
191197
metadataType: z.string().optional(),
198+
data: z.any().optional(),
199+
timestamp: z.date().optional(),
192200
});
193201

194202
/**
@@ -220,9 +228,9 @@ export const MetadataImportOptionsSchema = z.object({
220228
* Metadata Manager Config
221229
*/
222230
export const MetadataManagerConfigSchema = z.object({
223-
loaders: z.array(z.any()),
224-
watch: z.boolean().default(false),
225-
cache: z.boolean().default(true),
231+
loaders: z.array(z.any()).optional(),
232+
watch: z.boolean().optional(),
233+
cache: z.boolean().optional(),
226234
basePath: z.string().optional(),
227235
rootDir: z.string().optional(),
228236
formats: z.array(MetadataFormatSchema).optional(),

0 commit comments

Comments
 (0)