@gati-framework/runtime
Version:
Gati runtime execution engine for running handler-based applications
116 lines • 3.85 kB
JavaScript
/**
* @module runtime/storage/in-memory-storage
* @description In-memory storage implementation (default)
*
* Fast, zero-dependency storage for development and testing.
* No persistence - data is lost on restart.
*/
/**
* In-memory storage implementation
*/
export class InMemoryStorage {
manifests = new Map();
hookManifests = new Map();
gtypes = new Map();
transformers = new Map();
versionGraphs = new Map();
timescapeMetadata = new Map();
async storeManifest(manifest) {
if (!this.manifests.has(manifest.handlerId)) {
this.manifests.set(manifest.handlerId, new Map());
}
this.manifests.get(manifest.handlerId).set(manifest.version, manifest);
}
async getManifest(id, version) {
const versions = this.manifests.get(id);
if (!versions)
return undefined;
if (version)
return versions.get(version);
const allVersions = Array.from(versions.values());
if (allVersions.length === 0)
return undefined;
return allVersions.sort((a, b) => b.createdAt - a.createdAt)[0];
}
async getAllManifestVersions(id) {
const versions = this.manifests.get(id);
if (!versions)
return [];
return Array.from(versions.values()).sort((a, b) => a.createdAt - b.createdAt);
}
async storeHookManifest(manifest) {
this.hookManifests.set(manifest.handlerId, manifest);
}
async getHookManifest(handlerId) {
return this.hookManifests.get(handlerId) || null;
}
async listHookManifests() {
return Array.from(this.hookManifests.values());
}
async storeGType(gtype) {
this.gtypes.set(gtype.ref, gtype);
}
async getGType(ref) {
return this.gtypes.get(ref);
}
async storeTransformer(transformer) {
this.transformers.set(transformer.id, transformer);
}
async getTransformer(id) {
return this.transformers.get(id);
}
async getTransformersForVersions(handlerId, fromVersion, toVersion) {
const results = [];
for (const transformer of this.transformers.values()) {
if (transformer.handlerId === handlerId &&
transformer.fromVersion === fromVersion &&
transformer.toVersion === toVersion) {
results.push(transformer);
}
}
return results;
}
async storeVersionGraph(graph) {
this.versionGraphs.set(graph.handlerId, graph);
}
async getVersionGraph(handlerId) {
return this.versionGraphs.get(handlerId);
}
async storeTimescapeMetadata(metadata) {
const key = `${metadata.handlerId}:${metadata.version}`;
this.timescapeMetadata.set(key, metadata);
}
async getTimescapeMetadata(handlerId, version) {
const key = `${handlerId}:${version}`;
return this.timescapeMetadata.get(key);
}
async clear() {
this.manifests.clear();
this.hookManifests.clear();
this.gtypes.clear();
this.transformers.clear();
this.versionGraphs.clear();
this.timescapeMetadata.clear();
}
getStats() {
let manifestCount = 0;
for (const versions of this.manifests.values()) {
manifestCount += versions.size;
}
return {
manifestCount,
gtypeCount: this.gtypes.size,
transformerCount: this.transformers.size,
versionGraphCount: this.versionGraphs.size,
timescapeMetadataCount: this.timescapeMetadata.size,
hookManifestCount: this.hookManifests.size,
};
}
}
/**
* Create in-memory storage instance
*/
export function createInMemoryStorage() {
return new InMemoryStorage();
}
//# sourceMappingURL=in-memory-storage.js.map