-
Notifications
You must be signed in to change notification settings - Fork 6
Expand file tree
/
Copy pathmemory-metadata.ts
More file actions
63 lines (60 loc) · 2.42 KB
/
Copy pathmemory-metadata.ts
File metadata and controls
63 lines (60 loc) · 2.42 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
// Copyright (c) 2025 ObjectStack. Licensed under the Apache-2.0 license.
/**
* In-memory metadata service fallback.
*
* Implements the IMetadataService contract with a simple Map-of-Maps store.
* Used by ObjectKernel as an automatic fallback when no real metadata plugin
* (e.g. MetadataPlugin with file-system persistence) is registered.
*/
export function createMemoryMetadata() {
// type -> name -> data
const store = new Map<string, Map<string, any>>();
function getTypeMap(type: string): Map<string, any> {
let map = store.get(type);
if (!map) {
map = new Map();
store.set(type, map);
}
return map;
}
return {
_fallback: true, _serviceName: 'metadata',
async register(type: string, name: string, data: any): Promise<void> {
getTypeMap(type).set(name, data);
},
// Mirror MetadataManager.registerInMemory (synchronous, no persistence).
// AppPlugin gates code-defined-datasource / stack-RBAC registration on
// `typeof metadata.registerInMemory === 'function'` (it must register
// GitOps-managed artefacts *listably* but never persist them). Without this
// method the guard was false on the host-config / standalone boot path —
// where this fallback (not MetadataPlugin) provides the `metadata` service —
// so `defineStack({ datasources })` entries silently never reached the
// registry and were absent from GET /api/v1/datasources and
// GET /api/v1/meta/datasource (ADR-0015 §18). This store is already
// in-memory only, so registerInMemory and register share an implementation.
registerInMemory(type: string, name: string, data: any): void {
getTypeMap(type).set(name, data);
},
async get(type: string, name: string): Promise<any> {
return getTypeMap(type).get(name);
},
async list(type: string): Promise<any[]> {
return Array.from(getTypeMap(type).values());
},
async unregister(type: string, name: string): Promise<void> {
getTypeMap(type).delete(name);
},
async exists(type: string, name: string): Promise<boolean> {
return getTypeMap(type).has(name);
},
async listNames(type: string): Promise<string[]> {
return Array.from(getTypeMap(type).keys());
},
async getObject(name: string): Promise<any> {
return getTypeMap('object').get(name);
},
async listObjects(): Promise<any[]> {
return Array.from(getTypeMap('object').values());
},
};
}