MCPcopy Create free account
hub / github.com/danielmiessler/Fabric / createStorageAPI

Function createStorageAPI

web/src/lib/api/base.ts:60–99  ·  view source on GitHub ↗
(entityType: string)

Source from the content-addressed store, hash-verified

58};
59
60export function createStorageAPI<T extends StorageEntity>(entityType: string) {
61 return {
62 async get(name: string): Promise<T> {
63 const response = await api.fetch<T>(`/${entityType}/${name}`);
64 if (response.error) throw new Error(response.error);
65 return response.data as T;
66 },
67
68 async getNames(): Promise<string[]> {
69 const response = await api.fetch<string[]>(`/${entityType}/names`);
70 if (response.error) throw new Error(response.error);
71 return response.data as [];
72 },
73
74 async delete(name: string): Promise<void> {
75 const response = await api.fetch(`/${entityType}/${name}`, { method: 'DELETE' });
76 if (response.error) throw new Error(response.error);
77 },
78
79 async exists(name: string): Promise<boolean> {
80 const response = await api.fetch<boolean>(`/${entityType}/exists/${name}`);
81 if (response.error) throw new Error(response.error);
82 return response.data as boolean;
83 },
84
85 async rename(oldName: string, newName: string): Promise<void> {
86 const response = await api.fetch(`/${entityType}/rename/${oldName}/${newName}`, { method: 'PUT' });
87 if (response.error) throw new Error(response.error);
88 },
89
90 async save(name: string, content: string | object): Promise<void> {
91 const response = await api.fetch(`/${entityType}/${name}`, {
92 method: 'POST',
93 body: JSON.stringify(content),
94 headers: { 'Content-Type': 'application/json' },
95 });
96 if (response.error) throw new Error(response.error);
97 },
98 };
99}

Callers 2

session-store.tsFile · 0.90
pattern-store.tsFile · 0.90

Calls

no outgoing calls

Tested by

no test coverage detected