|
|
@@ -0,0 +1,79 @@
|
|
|
+import { resolve } from '$app/paths';
|
|
|
+
|
|
|
+import type { StackCR } from '$lib/types/custom-resources/stack';
|
|
|
+import type { Stack } from '$lib/types/entities';
|
|
|
+
|
|
|
+import { handleResponse } from './types';
|
|
|
+
|
|
|
+const list = (workspaceId: string, fetch = globalThis.fetch): Promise<Stack[]> =>
|
|
|
+ fetch(
|
|
|
+ resolve('/api/workspaces/[workspaceId]/[resource=resource]', {
|
|
|
+ workspaceId,
|
|
|
+ resource: 'stacks',
|
|
|
+ }),
|
|
|
+ ).then(handleResponse<Stack[]>);
|
|
|
+
|
|
|
+const get = (workspaceId: string, id: string, fetch = globalThis.fetch): Promise<Stack> =>
|
|
|
+ fetch(
|
|
|
+ resolve('/api/workspaces/[workspaceId]/[resource=resource]/[id]', {
|
|
|
+ workspaceId,
|
|
|
+ resource: 'stacks',
|
|
|
+ id,
|
|
|
+ }),
|
|
|
+ ).then(handleResponse<Stack>);
|
|
|
+
|
|
|
+const getStatus = (
|
|
|
+ workspaceId: string,
|
|
|
+ id: string,
|
|
|
+ fetch = globalThis.fetch,
|
|
|
+): Promise<StackCR['status']> =>
|
|
|
+ fetch(
|
|
|
+ resolve('/api/workspaces/[workspaceId]/[resource=resource]/[id]/status', {
|
|
|
+ workspaceId,
|
|
|
+ resource: 'stacks',
|
|
|
+ id,
|
|
|
+ }),
|
|
|
+ ).then(handleResponse<StackCR['status']>);
|
|
|
+
|
|
|
+const create = (workspaceId: string, stack: Stack, fetch = globalThis.fetch): Promise<Stack> =>
|
|
|
+ fetch(
|
|
|
+ resolve('/api/workspaces/[workspaceId]/[resource=resource]', {
|
|
|
+ workspaceId,
|
|
|
+ resource: 'stacks',
|
|
|
+ }),
|
|
|
+ {
|
|
|
+ method: 'POST',
|
|
|
+ headers: { 'Content-Type': 'application/json' },
|
|
|
+ body: JSON.stringify(stack),
|
|
|
+ },
|
|
|
+ ).then(handleResponse<Stack>);
|
|
|
+
|
|
|
+const update = (workspaceId: string, stack: Stack, fetch = globalThis.fetch): Promise<Stack> =>
|
|
|
+ fetch(
|
|
|
+ resolve('/api/workspaces/[workspaceId]/[resource=resource]/[id]', {
|
|
|
+ workspaceId,
|
|
|
+ resource: 'stacks',
|
|
|
+ id: stack.id,
|
|
|
+ }),
|
|
|
+ {
|
|
|
+ method: 'PUT',
|
|
|
+ headers: { 'Content-Type': 'application/json' },
|
|
|
+ body: JSON.stringify(stack),
|
|
|
+ },
|
|
|
+ ).then(handleResponse<Stack>);
|
|
|
+
|
|
|
+const remove = (workspaceId: string, id: string, fetch = globalThis.fetch): Promise<void> =>
|
|
|
+ fetch(
|
|
|
+ resolve('/api/workspaces/[workspaceId]/[resource=resource]/[id]', {
|
|
|
+ workspaceId,
|
|
|
+ resource: 'stacks',
|
|
|
+ id,
|
|
|
+ }),
|
|
|
+ {
|
|
|
+ method: 'DELETE',
|
|
|
+ },
|
|
|
+ ).then(async (res) => {
|
|
|
+ if (!res.ok) await handleResponse<void>(res);
|
|
|
+ });
|
|
|
+
|
|
|
+export { create, get, getStatus, list, remove, update };
|