@convo-lang/convo-lang
Version:
The language of AI
37 lines • 1.28 kB
JavaScript
;
Object.defineProperty(exports, "__esModule", { value: true });
exports.ConvoLocalStorageGraphStore = void 0;
const ConvoMemoryGraphStore_1 = require("./ConvoMemoryGraphStore");
const defaultStoreKey = 'convo-graph-store';
class ConvoLocalStorageGraphStore extends ConvoMemoryGraphStore_1.ConvoMemoryGraphStore {
storeKey;
constructor({ storeKey, ...options }) {
super(options);
if (!storeKey) {
storeKey = defaultStoreKey + '::' + options.graphId;
}
this.storeKey = storeKey;
const json = globalThis.localStorage?.getItem(storeKey);
if (json) {
try {
this.db = JSON.parse(json);
if (!this.db.inputs) {
this.db.inputs = [];
}
}
catch (ex) {
console.error('Invalid convo graph json', ex);
}
}
this.onDbChange.subscribe(() => this.save());
}
save() {
globalThis.localStorage.setItem(this.storeKey, JSON.stringify(this.db));
}
saveChangesAsync() {
this.save();
return Promise.resolve();
}
}
exports.ConvoLocalStorageGraphStore = ConvoLocalStorageGraphStore;
//# sourceMappingURL=ConvoLocalStorageGraphStore.js.map