MCPcopy Create free account
hub / github.com/6174/comflowyspace / JSONDBDatabase

Class JSONDBDatabase

packages/common/storage/document-database.ts:10–104  ·  view source on GitHub ↗

Source from the content-addressed store, hash-verified

8import { useAppStore } from '../store/app-state';
9
10export class JSONDBDatabase {
11 documents: JSONDBClient<PersistedFullWorkflow>
12 constructor() {
13 this.documents = new JSONDBClient<PersistedFullWorkflow>("workflows");
14 }
15
16 async getDocs(): Promise<PersistedFullWorkflow[]> {
17 const ret = await this.documents.getDocuments();
18 if (ret.success) {
19 return ret.data
20 } else {
21 throw new Error("Get docs failed" + ret.error);
22 }
23 }
24
25 async getDoc(id: string): Promise<PersistedFullWorkflow> {
26 const ret = await this.documents.getDocument(id);
27 if (ret.success) {
28 return ret.data
29 } else {
30 throw new Error("Get Doc failed: " + ret.error);
31 }
32 }
33
34 async createDoc(docMeta: PersistedFullWorkflow) {
35 const ret = await this.documents.createDocument(docMeta.id, docMeta);
36 if (!ret.success) {
37 throw new Error("Create Doc failed: " + ret.error);
38 }
39 }
40
41 async updateDoc(docMeta: PersistedFullWorkflow) {
42 const ret = await this.documents.updateDocument(docMeta.id, docMeta);
43 if (!ret.success) {
44 throw new Error("Update failed" + ret.error);
45 }
46 }
47
48 async deleteDocSoft(docId: string) {
49 const ret = await this.documents.updateDocument(docId, {
50 deleted: true,
51 deleted_time: +(new Date())
52 });
53 if (!ret.success) {
54 throw new Error("Delete failed: " + ret.error);
55 }
56 }
57
58 async deleteDoc(docId: string) {
59 const ret = await this.documents.deleteDocument(docId);
60 if (!ret.success) {
61 throw new Error("Delete failed_: " + ret.error);
62
63 }
64 }
65
66 async createDocFromTemplate(key: string = "default"): Promise<PersistedFullWorkflow> {
67 const template = getWorkflowTemplate(key);

Callers

nothing calls this directly

Calls

no outgoing calls

Tested by

no test coverage detected