feat: create client way
refactor: formating using biome code
This commit is contained in:
parent
684b5b511a
commit
f44e830205
12 changed files with 347 additions and 279 deletions
14
biome.json
Normal file
14
biome.json
Normal file
|
@ -0,0 +1,14 @@
|
||||||
|
{
|
||||||
|
"files": {
|
||||||
|
"ignore": ["**/node_modules", "node_modules/"]
|
||||||
|
},
|
||||||
|
"vcs": {
|
||||||
|
"enabled": true,
|
||||||
|
"clientKind": "git"
|
||||||
|
},
|
||||||
|
"javascript": {
|
||||||
|
"formatter": {
|
||||||
|
"semicolons": "asNeeded"
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
BIN
bun.lockb
BIN
bun.lockb
Binary file not shown.
42
client.ts
Normal file
42
client.ts
Normal 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
21
entities/compose.d.ts
vendored
|
@ -81,7 +81,9 @@ export type Services = {
|
||||||
cgroup?: "host" | "private"
|
cgroup?: "host" | "private"
|
||||||
cpu_rt_period?: string
|
cpu_rt_period?: string
|
||||||
command?: Array<string> | string
|
command?: Array<string> | string
|
||||||
configs?: Array<string> | Array<{
|
configs?:
|
||||||
|
| Array<string>
|
||||||
|
| Array<{
|
||||||
source: string
|
source: string
|
||||||
target: string
|
target: string
|
||||||
uid: string
|
uid: string
|
||||||
|
@ -99,7 +101,9 @@ export type Services = {
|
||||||
dns_search?: string | Array<string>
|
dns_search?: string | Array<string>
|
||||||
entrypoint?: string | Array<string>
|
entrypoint?: string | Array<string>
|
||||||
tmpfs?: string | Array<string>
|
tmpfs?: string | Array<string>
|
||||||
env_file?: Array<string> | Array<{
|
env_file?:
|
||||||
|
| Array<string>
|
||||||
|
| Array<{
|
||||||
path: string
|
path: string
|
||||||
required: boolean
|
required: boolean
|
||||||
}>
|
}>
|
||||||
|
@ -115,7 +119,12 @@ export type Services = {
|
||||||
tty?: boolean
|
tty?: boolean
|
||||||
sysctl?: Label
|
sysctl?: Label
|
||||||
runtime: Runtimes
|
runtime: Runtimes
|
||||||
restart: "no" | "always" | "unless-stopped" | "on-failure" | { "on-failure": number }
|
restart:
|
||||||
|
| "no"
|
||||||
|
| "always"
|
||||||
|
| "unless-stopped"
|
||||||
|
| "on-failure"
|
||||||
|
| { "on-failure": number }
|
||||||
workdir?: string
|
workdir?: string
|
||||||
extra_hosts?: string
|
extra_hosts?: string
|
||||||
stdin_open?: boolean
|
stdin_open?: boolean
|
||||||
|
@ -190,9 +199,11 @@ type Configs = {
|
||||||
}
|
}
|
||||||
|
|
||||||
type Secrets = {
|
type Secrets = {
|
||||||
[name: string]: {
|
[name: string]:
|
||||||
|
| {
|
||||||
file?: string
|
file?: string
|
||||||
} | {
|
}
|
||||||
|
| {
|
||||||
token: {
|
token: {
|
||||||
environment: string
|
environment: string
|
||||||
}
|
}
|
||||||
|
|
2
entities/unit.d.ts
vendored
2
entities/unit.d.ts
vendored
|
@ -9,5 +9,3 @@ export type ComputingUnit = {
|
||||||
persistence: number | Unit
|
persistence: number | Unit
|
||||||
bandwitch: number | Unit
|
bandwitch: number | Unit
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
|
|
|
@ -7,5 +7,8 @@
|
||||||
},
|
},
|
||||||
"peerDependencies": {
|
"peerDependencies": {
|
||||||
"typescript": "^5.0.0"
|
"typescript": "^5.0.0"
|
||||||
|
},
|
||||||
|
"dependencies": {
|
||||||
|
"@biomejs/biome": "^1.8.3"
|
||||||
}
|
}
|
||||||
}
|
}
|
Loading…
Reference in a new issue