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

Function createStorageAPI

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

Source from the content-addressed store, hash-verified

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

Callers 2

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

Calls

no outgoing calls

Tested by

no test coverage detected