feat: create client way

refactor: formating using biome code
This commit is contained in:
Konrad Geletey 2024-09-08 23:15:54 +03:00
parent 684b5b511a
commit f44e830205
No known key found for this signature in database
GPG key ID: 862B98E2204889CE
12 changed files with 347 additions and 279 deletions

14
biome.json Normal file
View file

@ -0,0 +1,14 @@
{
"files": {
"ignore": ["**/node_modules", "node_modules/"]
},
"vcs": {
"enabled": true,
"clientKind": "git"
},
"javascript": {
"formatter": {
"semicolons": "asNeeded"
}
}
}

BIN
bun.lockb

Binary file not shown.

42
client.ts Normal file
View file

@ -0,0 +1,42 @@
type Headers = {
"Content-Type": string
"X-Version": string
Authorization?: string
}
async function createClient<T>(config: {
baseUrl: string
token: string
version: string
method: string
publicKey: string
}): Promise<T> {
const version = config.version ?? "1.0.1"
const method = config.method ?? "GET"
const headers: Headers = {
"Content-Type": "application/json",
"X-Version": version,
}
if (config.token !== undefined) {
headers.Authorization = `Bearer ${config.token}`
const response = await fetch(config.baseUrl, { method: method, headers })
if (!response.ok) {
throw new Error(response.statusText)
}
return (await response.json()) as T
}
const response = await fetch(`${config.baseUrl}/token`, {
method: "POST",
headers,
body: JSON.stringify({
publicKey: config.publicKey,
}),
})
if (!response.ok) {
throw new Error(response.statusText)
}
return (await response.json()) as T
}

21
entities/compose.d.ts vendored
View file

@ -81,7 +81,9 @@ export type Services = {
cgroup?: "host" | "private"
cpu_rt_period?: string
command?: Array<string> | string
configs?: Array<string> | Array<{
configs?:
| Array<string>
| Array<{
source: string
target: string
uid: string
@ -99,7 +101,9 @@ export type Services = {
dns_search?: string | Array<string>
entrypoint?: string | Array<string>
tmpfs?: string | Array<string>
env_file?: Array<string> | Array<{
env_file?:
| Array<string>
| Array<{
path: string
required: boolean
}>
@ -115,7 +119,12 @@ export type Services = {
tty?: boolean
sysctl?: Label
runtime: Runtimes
restart: "no" | "always" | "unless-stopped" | "on-failure" | { "on-failure": number }
restart:
| "no"
| "always"
| "unless-stopped"
| "on-failure"
| { "on-failure": number }
workdir?: string
extra_hosts?: string
stdin_open?: boolean
@ -190,9 +199,11 @@ type Configs = {
}
type Secrets = {
[name: string]: {
[name: string]:
| {
file?: string
} | {
}
| {
token: {
environment: string
}

2
entities/unit.d.ts vendored
View file

@ -9,5 +9,3 @@ export type ComputingUnit = {
persistence: number | Unit
bandwitch: number | Unit
}

View file

@ -7,5 +7,8 @@
},
"peerDependencies": {
"typescript": "^5.0.0"
},
"dependencies": {
"@biomejs/biome": "^1.8.3"
}
}