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

Function createStorageAPI

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

Source from the content-addressed store, hash-verified

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

Callers 2

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

Calls

no outgoing calls

Tested by

no test coverage detected