1- import { type IMetadataSource , MapMetadataSource , type Metadata } from './MetadataSource' ;
2- import { type GlobalMetadataCacheItem , type MapMetadataCacheItem } from './MetadataCacheItem' ;
1+ import { type IMetadataSource , FilePathMetadataSource , type Metadata } from './MetadataSource' ;
2+ import {
3+ type GlobalMetadataCacheItem ,
4+ type FilePathMetadataCacheItem ,
5+ type IMetadataCacheItem ,
6+ } from './MetadataCacheItem' ;
37import { type MetadataManager } from './MetadataManager' ;
48import { type BindTargetDeclaration } from '../parsers/bindTargetParser/BindTargetDeclaration' ;
59import { type PropPath } from '../utils/prop/PropPath' ;
610import { type IMetadataSubscription } from './IMetadataSubscription' ;
711import { PropUtils } from '../utils/prop/PropUtils' ;
812import { ErrorLevel , MetaBindInternalError } from '../utils/errors/MetaBindErrors' ;
13+ import { type ParsingResultNode } from '../parsers/nomParsers/GeneralNomParsers' ;
14+ import { type BindTargetParser } from '../parsers/bindTargetParser/BindTargetParser' ;
15+ import { ParsingValidationError } from '../parsers/ParsingError' ;
16+ import { type BindTargetScope } from './BindTargetScope' ;
917
10- export class InternalMetadataSource extends MapMetadataSource < MapMetadataCacheItem > {
11- public getDefaultCacheItem ( storagePath : string ) : MapMetadataCacheItem {
18+ export class InternalMetadataSource extends FilePathMetadataSource < FilePathMetadataCacheItem > {
19+ public getDefaultCacheItem ( storagePath : string ) : FilePathMetadataCacheItem {
1220 return {
1321 data : { } ,
1422 storagePath : storagePath ,
1523 ...this . manager . getDefaultCacheItem ( ) ,
1624 } ;
1725 }
1826
19- public async syncExternal ( _cacheItem : MapMetadataCacheItem ) : Promise < void > {
27+ public async syncExternal ( _cacheItem : FilePathMetadataCacheItem ) : Promise < void > {
2028 // Do nothing
2129 }
2230}
@@ -36,6 +44,32 @@ export class GlobalMetadataSource implements IMetadataSource<GlobalMetadataCache
3644 } ;
3745 }
3846
47+ public validateStoragePath (
48+ storagePath : ParsingResultNode ,
49+ hadStoragePath : boolean ,
50+ bindTargetDeclaration : string ,
51+ _parser : BindTargetParser ,
52+ ) : string {
53+ if ( hadStoragePath ) {
54+ throw new ParsingValidationError (
55+ ErrorLevel . ERROR ,
56+ 'Bind Target Validator' ,
57+ `Failed to parse bind target. Bind target storage type 'global_memory' does not support a storage path.` ,
58+ bindTargetDeclaration ,
59+ storagePath . position ,
60+ ) ;
61+ }
62+ return '' ;
63+ }
64+
65+ public resolveBindTargetScope (
66+ bindTargetDeclaration : BindTargetDeclaration ,
67+ _scope : BindTargetScope | undefined ,
68+ _parser : BindTargetParser ,
69+ ) : BindTargetDeclaration {
70+ return bindTargetDeclaration ;
71+ }
72+
3973 public delete ( _cacheItem : GlobalMetadataCacheItem ) : void {
4074 // noop
4175 }
@@ -101,3 +135,131 @@ export class GlobalMetadataSource implements IMetadataSource<GlobalMetadataCache
101135 return cacheItem . data ;
102136 }
103137}
138+
139+ export class ScopeMetadataSource implements IMetadataSource < IMetadataCacheItem > {
140+ public readonly id : string ;
141+ public readonly manager : MetadataManager ;
142+
143+ constructor ( id : string , manager : MetadataManager ) {
144+ this . id = id ;
145+ this . manager = manager ;
146+ }
147+
148+ public validateStoragePath (
149+ storagePath : ParsingResultNode ,
150+ hadStoragePath : boolean ,
151+ bindTargetDeclaration : string ,
152+ _parser : BindTargetParser ,
153+ ) : string {
154+ if ( hadStoragePath ) {
155+ throw new ParsingValidationError (
156+ ErrorLevel . ERROR ,
157+ 'Bind Target Validator' ,
158+ `Failed to parse bind target. Bind target storage type 'scope' does not support a storage path.` ,
159+ bindTargetDeclaration ,
160+ storagePath . position ,
161+ ) ;
162+ }
163+ return '' ;
164+ }
165+
166+ public resolveBindTargetScope (
167+ bindTargetDeclaration : BindTargetDeclaration ,
168+ scope : BindTargetScope | undefined ,
169+ parser : BindTargetParser ,
170+ ) : BindTargetDeclaration {
171+ return parser . resolveScope ( bindTargetDeclaration , scope ) ;
172+ }
173+
174+ public delete ( _cacheItem : IMetadataCacheItem ) : void {
175+ throw new MetaBindInternalError ( {
176+ errorLevel : ErrorLevel . CRITICAL ,
177+ effect : 'action not permitted' ,
178+ cause : `source 'scope' should have no cache items or subscriptions` ,
179+ } ) ;
180+ }
181+
182+ public getCacheItemForStoragePath ( _storagePath : string ) : IMetadataCacheItem | undefined {
183+ throw new MetaBindInternalError ( {
184+ errorLevel : ErrorLevel . CRITICAL ,
185+ effect : 'action not permitted' ,
186+ cause : `source 'scope' should have no cache items or subscriptions` ,
187+ } ) ;
188+ }
189+
190+ public iterateCacheItems ( ) : IterableIterator < IMetadataCacheItem > {
191+ return [ ] [ Symbol . iterator ] ( ) ;
192+ }
193+
194+ public onCycle ( _cacheItem : IMetadataCacheItem ) : void {
195+ // noop
196+ }
197+
198+ public readCache ( _bindTarget : BindTargetDeclaration ) : unknown {
199+ throw new MetaBindInternalError ( {
200+ errorLevel : ErrorLevel . CRITICAL ,
201+ effect : 'action not permitted' ,
202+ cause : `source 'scope' should have no cache items or subscriptions` ,
203+ } ) ;
204+ }
205+
206+ public readCacheItem ( _cacheItem : IMetadataCacheItem , _propPath : PropPath ) : unknown {
207+ throw new MetaBindInternalError ( {
208+ errorLevel : ErrorLevel . CRITICAL ,
209+ effect : 'action not permitted' ,
210+ cause : `source 'scope' should have no cache items or subscriptions` ,
211+ } ) ;
212+ }
213+
214+ public shouldDelete ( _cacheItem : IMetadataCacheItem ) : boolean {
215+ throw new MetaBindInternalError ( {
216+ errorLevel : ErrorLevel . CRITICAL ,
217+ effect : 'action not permitted' ,
218+ cause : `source 'scope' should have no cache items or subscriptions` ,
219+ } ) ;
220+ }
221+
222+ public subscribe ( _subscription : IMetadataSubscription ) : IMetadataCacheItem {
223+ throw new MetaBindInternalError ( {
224+ errorLevel : ErrorLevel . CRITICAL ,
225+ effect : 'action not permitted' ,
226+ cause : `source 'scope' should have no cache items or subscriptions` ,
227+ } ) ;
228+ }
229+
230+ public syncExternal ( _cacheItem : IMetadataCacheItem ) : void {
231+ // noop
232+ }
233+
234+ public unsubscribe ( _subscription : IMetadataSubscription ) : IMetadataCacheItem {
235+ throw new MetaBindInternalError ( {
236+ errorLevel : ErrorLevel . CRITICAL ,
237+ effect : 'action not permitted' ,
238+ cause : `source 'scope' should have no cache items or subscriptions` ,
239+ } ) ;
240+ }
241+
242+ public update ( _value : unknown , _subscription : IMetadataSubscription ) : IMetadataCacheItem {
243+ throw new MetaBindInternalError ( {
244+ errorLevel : ErrorLevel . CRITICAL ,
245+ effect : 'action not permitted' ,
246+ cause : `source 'scope' should have no cache items or subscriptions` ,
247+ } ) ;
248+ }
249+
250+ public updateEntireCache ( _value : Metadata , _cacheItem : IMetadataCacheItem ) : void {
251+ throw new MetaBindInternalError ( {
252+ errorLevel : ErrorLevel . CRITICAL ,
253+ effect : 'action not permitted' ,
254+ cause : `source 'scope' should have no cache items or subscriptions` ,
255+ } ) ;
256+ }
257+
258+ public readEntireCacheItem ( _cacheItem : IMetadataCacheItem ) : Metadata {
259+ throw new MetaBindInternalError ( {
260+ errorLevel : ErrorLevel . CRITICAL ,
261+ effect : 'action not permitted' ,
262+ cause : `source 'scope' should have no cache items or subscriptions` ,
263+ } ) ;
264+ }
265+ }
0 commit comments