@hamak/filesystem-server-spi 0.4.19 → 0.5.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.
@@ -23,5 +23,6 @@ Object.defineProperty(exports, "__esModule", { value: true });
23
23
  __exportStar(require("./spi/IFileSystemMiddleware"), exports);
24
24
  __exportStar(require("./spi/IPathResolver"), exports);
25
25
  __exportStar(require("./spi/IAccessControl"), exports);
26
+ __exportStar(require("./spi/IFileInfoEnricher"), exports);
26
27
  // Export SPI tokens
27
28
  __exportStar(require("./spi/tokens"), exports);
@@ -0,0 +1,8 @@
1
+ "use strict";
2
+ /**
3
+ * File Info Enricher Interface
4
+ *
5
+ * SPI for plugins that enrich FileInfo responses with additional data.
6
+ * Enrichers are called when specific query parameters are present.
7
+ */
8
+ Object.defineProperty(exports, "__esModule", { value: true });
@@ -5,7 +5,7 @@
5
5
  * Tokens for registering and resolving extension points
6
6
  */
7
7
  Object.defineProperty(exports, "__esModule", { value: true });
8
- exports.ACCESS_CONTROL_TOKEN = exports.PATH_RESOLVER_TOKEN = exports.FILESYSTEM_MIDDLEWARE_TOKEN = void 0;
8
+ exports.FILE_INFO_ENRICHER_TOKEN = exports.FILE_INFO_ENRICHER_REGISTRY_TOKEN = exports.ACCESS_CONTROL_TOKEN = exports.PATH_RESOLVER_TOKEN = exports.FILESYSTEM_MIDDLEWARE_TOKEN = void 0;
9
9
  /**
10
10
  * Token for custom FileSystem middleware
11
11
  * Can be registered multiple times for multiple middleware instances
@@ -21,3 +21,13 @@ exports.PATH_RESOLVER_TOKEN = Symbol('PathResolver');
21
21
  * Only one access control should be registered (replaces default)
22
22
  */
23
23
  exports.ACCESS_CONTROL_TOKEN = Symbol('AccessControl');
24
+ /**
25
+ * Token for FileInfo enricher registry
26
+ * Used to register enrichers that add extension data to FileInfo responses
27
+ */
28
+ exports.FILE_INFO_ENRICHER_REGISTRY_TOKEN = Symbol('FileInfoEnricherRegistry');
29
+ /**
30
+ * Token for individual FileInfo enrichers
31
+ * Can be registered multiple times for multiple enricher instances
32
+ */
33
+ exports.FILE_INFO_ENRICHER_TOKEN = Symbol('FileInfoEnricher');
package/dist/index.d.ts CHANGED
@@ -6,5 +6,6 @@
6
6
  export * from './spi/IFileSystemMiddleware';
7
7
  export * from './spi/IPathResolver';
8
8
  export * from './spi/IAccessControl';
9
+ export * from './spi/IFileInfoEnricher';
9
10
  export * from './spi/tokens';
10
11
  //# sourceMappingURL=index.d.ts.map
@@ -1 +1 @@
1
- {"version":3,"file":"index.d.ts","sourceRoot":"","sources":["../src/index.ts"],"names":[],"mappings":"AAAA;;;;GAIG;AAGH,cAAc,6BAA6B,CAAC;AAC5C,cAAc,qBAAqB,CAAC;AACpC,cAAc,sBAAsB,CAAC;AAGrC,cAAc,cAAc,CAAC"}
1
+ {"version":3,"file":"index.d.ts","sourceRoot":"","sources":["../src/index.ts"],"names":[],"mappings":"AAAA;;;;GAIG;AAGH,cAAc,6BAA6B,CAAC;AAC5C,cAAc,qBAAqB,CAAC;AACpC,cAAc,sBAAsB,CAAC;AACrC,cAAc,yBAAyB,CAAC;AAGxC,cAAc,cAAc,CAAC"}
package/dist/index.js CHANGED
@@ -7,5 +7,6 @@
7
7
  export * from './spi/IFileSystemMiddleware';
8
8
  export * from './spi/IPathResolver';
9
9
  export * from './spi/IAccessControl';
10
+ export * from './spi/IFileInfoEnricher';
10
11
  // Export SPI tokens
11
12
  export * from './spi/tokens';
@@ -0,0 +1,124 @@
1
+ /**
2
+ * File Info Enricher Interface
3
+ *
4
+ * SPI for plugins that enrich FileInfo responses with additional data.
5
+ * Enrichers are called when specific query parameters are present.
6
+ */
7
+ import { FileInfo } from '@hamak/shared-utils';
8
+ import { Request } from 'express';
9
+ /**
10
+ * Context provided to enrichers during file info enrichment
11
+ */
12
+ export interface EnricherContext {
13
+ /**
14
+ * The workspace identifier
15
+ */
16
+ workspace: string;
17
+ /**
18
+ * The path segments of the file/directory
19
+ */
20
+ pathSegments: string[];
21
+ /**
22
+ * The full resolved path on the filesystem
23
+ */
24
+ resolvedPath: string;
25
+ /**
26
+ * The Express request object (for accessing query params, headers, etc.)
27
+ */
28
+ request: Request;
29
+ /**
30
+ * The operation type
31
+ */
32
+ operation: 'list' | 'read' | 'get' | 'mkdir' | 'write' | 'delete';
33
+ }
34
+ /**
35
+ * Interface for file info enrichers
36
+ *
37
+ * Enrichers add extension data to FileInfo objects based on query parameters.
38
+ * For example, a git enricher might add git status when `?extensions=git` is present.
39
+ *
40
+ * @example
41
+ * ```typescript
42
+ * class GitEnricher implements IFileInfoEnricher {
43
+ * extensionKey = 'git';
44
+ *
45
+ * shouldEnrich(context: EnricherContext): boolean {
46
+ * const extensions = context.request.query.extensions;
47
+ * return extensions?.includes('git') ?? false;
48
+ * }
49
+ *
50
+ * async enrich(fileInfo: FileInfo, context: EnricherContext): Promise<FileInfo> {
51
+ * const gitStatus = await getGitStatus(context.resolvedPath);
52
+ * return {
53
+ * ...fileInfo,
54
+ * extensions: {
55
+ * ...fileInfo.extensions,
56
+ * [this.extensionKey]: gitStatus
57
+ * }
58
+ * };
59
+ * }
60
+ * }
61
+ * ```
62
+ */
63
+ export interface IFileInfoEnricher {
64
+ /**
65
+ * Unique key for this enricher (e.g., 'git', 'permissions')
66
+ * Used as the key in FileInfo.extensions
67
+ */
68
+ readonly extensionKey: string;
69
+ /**
70
+ * Priority for enricher execution order (lower = earlier)
71
+ * Default should be 100.
72
+ */
73
+ readonly priority?: number;
74
+ /**
75
+ * Determine if this enricher should process the request
76
+ *
77
+ * @param context The enricher context
78
+ * @returns true if this enricher should enrich the response
79
+ */
80
+ shouldEnrich(context: EnricherContext): boolean;
81
+ /**
82
+ * Enrich a single FileInfo with extension data
83
+ *
84
+ * @param fileInfo The FileInfo to enrich
85
+ * @param context The enricher context
86
+ * @returns The enriched FileInfo
87
+ */
88
+ enrich(fileInfo: FileInfo, context: EnricherContext): Promise<FileInfo>;
89
+ /**
90
+ * Enrich multiple FileInfo objects (for list operations)
91
+ * Default implementation calls enrich() for each item.
92
+ *
93
+ * @param fileInfos The FileInfo array to enrich
94
+ * @param context The enricher context
95
+ * @returns The enriched FileInfo array
96
+ */
97
+ enrichMany?(fileInfos: FileInfo[], context: EnricherContext): Promise<FileInfo[]>;
98
+ }
99
+ /**
100
+ * Registry for file info enrichers
101
+ */
102
+ export interface IFileInfoEnricherRegistry {
103
+ /**
104
+ * Register an enricher
105
+ */
106
+ register(enricher: IFileInfoEnricher): void;
107
+ /**
108
+ * Unregister an enricher by its extension key
109
+ */
110
+ unregister(extensionKey: string): void;
111
+ /**
112
+ * Get all registered enrichers sorted by priority
113
+ */
114
+ getEnrichers(): IFileInfoEnricher[];
115
+ /**
116
+ * Apply all applicable enrichers to a FileInfo
117
+ */
118
+ applyEnrichers(fileInfo: FileInfo, context: EnricherContext): Promise<FileInfo>;
119
+ /**
120
+ * Apply all applicable enrichers to multiple FileInfo objects
121
+ */
122
+ applyEnrichersMany(fileInfos: FileInfo[], context: EnricherContext): Promise<FileInfo[]>;
123
+ }
124
+ //# sourceMappingURL=IFileInfoEnricher.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"IFileInfoEnricher.d.ts","sourceRoot":"","sources":["../../src/spi/IFileInfoEnricher.ts"],"names":[],"mappings":"AAAA;;;;;GAKG;AAEH,OAAO,EAAE,QAAQ,EAAE,MAAM,qBAAqB,CAAC;AAC/C,OAAO,EAAE,OAAO,EAAE,MAAM,SAAS,CAAC;AAElC;;GAEG;AACH,MAAM,WAAW,eAAe;IAC9B;;OAEG;IACH,SAAS,EAAE,MAAM,CAAC;IAElB;;OAEG;IACH,YAAY,EAAE,MAAM,EAAE,CAAC;IAEvB;;OAEG;IACH,YAAY,EAAE,MAAM,CAAC;IAErB;;OAEG;IACH,OAAO,EAAE,OAAO,CAAC;IAEjB;;OAEG;IACH,SAAS,EAAE,MAAM,GAAG,MAAM,GAAG,KAAK,GAAG,OAAO,GAAG,OAAO,GAAG,QAAQ,CAAC;CACnE;AAED;;;;;;;;;;;;;;;;;;;;;;;;;;;;GA4BG;AACH,MAAM,WAAW,iBAAiB;IAChC;;;OAGG;IACH,QAAQ,CAAC,YAAY,EAAE,MAAM,CAAC;IAE9B;;;OAGG;IACH,QAAQ,CAAC,QAAQ,CAAC,EAAE,MAAM,CAAC;IAE3B;;;;;OAKG;IACH,YAAY,CAAC,OAAO,EAAE,eAAe,GAAG,OAAO,CAAC;IAEhD;;;;;;OAMG;IACH,MAAM,CAAC,QAAQ,EAAE,QAAQ,EAAE,OAAO,EAAE,eAAe,GAAG,OAAO,CAAC,QAAQ,CAAC,CAAC;IAExE;;;;;;;OAOG;IACH,UAAU,CAAC,CAAC,SAAS,EAAE,QAAQ,EAAE,EAAE,OAAO,EAAE,eAAe,GAAG,OAAO,CAAC,QAAQ,EAAE,CAAC,CAAC;CACnF;AAED;;GAEG;AACH,MAAM,WAAW,yBAAyB;IACxC;;OAEG;IACH,QAAQ,CAAC,QAAQ,EAAE,iBAAiB,GAAG,IAAI,CAAC;IAE5C;;OAEG;IACH,UAAU,CAAC,YAAY,EAAE,MAAM,GAAG,IAAI,CAAC;IAEvC;;OAEG;IACH,YAAY,IAAI,iBAAiB,EAAE,CAAC;IAEpC;;OAEG;IACH,cAAc,CAAC,QAAQ,EAAE,QAAQ,EAAE,OAAO,EAAE,eAAe,GAAG,OAAO,CAAC,QAAQ,CAAC,CAAC;IAEhF;;OAEG;IACH,kBAAkB,CAAC,SAAS,EAAE,QAAQ,EAAE,EAAE,OAAO,EAAE,eAAe,GAAG,OAAO,CAAC,QAAQ,EAAE,CAAC,CAAC;CAC1F"}
@@ -0,0 +1,7 @@
1
+ /**
2
+ * File Info Enricher Interface
3
+ *
4
+ * SPI for plugins that enrich FileInfo responses with additional data.
5
+ * Enrichers are called when specific query parameters are present.
6
+ */
7
+ export {};
@@ -18,4 +18,14 @@ export declare const PATH_RESOLVER_TOKEN: unique symbol;
18
18
  * Only one access control should be registered (replaces default)
19
19
  */
20
20
  export declare const ACCESS_CONTROL_TOKEN: unique symbol;
21
+ /**
22
+ * Token for FileInfo enricher registry
23
+ * Used to register enrichers that add extension data to FileInfo responses
24
+ */
25
+ export declare const FILE_INFO_ENRICHER_REGISTRY_TOKEN: unique symbol;
26
+ /**
27
+ * Token for individual FileInfo enrichers
28
+ * Can be registered multiple times for multiple enricher instances
29
+ */
30
+ export declare const FILE_INFO_ENRICHER_TOKEN: unique symbol;
21
31
  //# sourceMappingURL=tokens.d.ts.map
@@ -1 +1 @@
1
- {"version":3,"file":"tokens.d.ts","sourceRoot":"","sources":["../../src/spi/tokens.ts"],"names":[],"mappings":"AAAA;;;;GAIG;AAEH;;;GAGG;AACH,eAAO,MAAM,2BAA2B,eAAiC,CAAC;AAE1E;;;GAGG;AACH,eAAO,MAAM,mBAAmB,eAAyB,CAAC;AAE1D;;;GAGG;AACH,eAAO,MAAM,oBAAoB,eAA0B,CAAC"}
1
+ {"version":3,"file":"tokens.d.ts","sourceRoot":"","sources":["../../src/spi/tokens.ts"],"names":[],"mappings":"AAAA;;;;GAIG;AAEH;;;GAGG;AACH,eAAO,MAAM,2BAA2B,eAAiC,CAAC;AAE1E;;;GAGG;AACH,eAAO,MAAM,mBAAmB,eAAyB,CAAC;AAE1D;;;GAGG;AACH,eAAO,MAAM,oBAAoB,eAA0B,CAAC;AAE5D;;;GAGG;AACH,eAAO,MAAM,iCAAiC,eAAqC,CAAC;AAEpF;;;GAGG;AACH,eAAO,MAAM,wBAAwB,eAA6B,CAAC"}
@@ -18,3 +18,13 @@ export const PATH_RESOLVER_TOKEN = Symbol('PathResolver');
18
18
  * Only one access control should be registered (replaces default)
19
19
  */
20
20
  export const ACCESS_CONTROL_TOKEN = Symbol('AccessControl');
21
+ /**
22
+ * Token for FileInfo enricher registry
23
+ * Used to register enrichers that add extension data to FileInfo responses
24
+ */
25
+ export const FILE_INFO_ENRICHER_REGISTRY_TOKEN = Symbol('FileInfoEnricherRegistry');
26
+ /**
27
+ * Token for individual FileInfo enrichers
28
+ * Can be registered multiple times for multiple enricher instances
29
+ */
30
+ export const FILE_INFO_ENRICHER_TOKEN = Symbol('FileInfoEnricher');
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@hamak/filesystem-server-spi",
3
- "version": "0.4.19",
3
+ "version": "0.5.0",
4
4
  "private": false,
5
5
  "type": "module",
6
6
  "description": "FileSystem Server SPI - Backend filesystem server extension points",