feat: add example

This commit is contained in:
2026-08-01 09:31:08 +03:00
parent 15805e28df
commit 26b59686a5
434 changed files with 34975 additions and 4995 deletions

View File

@@ -0,0 +1,14 @@
import { HttpClient } from '@biocad/{{name.kebabCase}}-rest-api-sdk'
import {
{{name.screamingSnakeCase}}_REST_API_BASE_URL,
{{name.screamingSnakeCase}}_REST_API_TIMEOUT_MS
} from './config/{{name.kebabCase}}-rest-api.config'
import { {{name.camelCase}}RestApiFetch } from './lib/{{name.kebabCase}}-rest-api-fetch'
/** Транспортный HTTP-клиент {{name.pascalCase}} REST API. */
export const {{name.camelCase}}HttpClient = new HttpClient({
baseUrl: {{name.screamingSnakeCase}}_REST_API_BASE_URL,
customFetch: {{name.camelCase}}RestApiFetch,
timeout: {{name.screamingSnakeCase}}_REST_API_TIMEOUT_MS
})

View File

@@ -0,0 +1,5 @@
/** Базовый URL {{name.pascalCase}} REST API. */
export const {{name.screamingSnakeCase}}_REST_API_BASE_URL = import.meta.env.VITE_{{name.screamingSnakeCase}}_REST_API_BASE_URL ?? ''
/** Максимальная длительность REST-запроса до автоматической отмены. */
export const {{name.screamingSnakeCase}}_REST_API_TIMEOUT_MS = 30_000

View File

@@ -0,0 +1,3 @@
export { ApiError as {{name.pascalCase}}RestApiError } from '@biocad/{{name.kebabCase}}-rest-api-sdk'
export { {{name.pascalCase}}RestApiTransportError } from './{{name.kebabCase}}-rest-api-transport.error'
export type { {{name.pascalCase}}RestApiTransportErrorCode } from './{{name.kebabCase}}-rest-api-transport.error'

View File

@@ -0,0 +1,20 @@
/**
* Причина сбоя непосредственно на transport-границе {{name.pascalCase}} REST API.
*/
export type {{name.pascalCase}}RestApiTransportErrorCode = 'NETWORK_UNAVAILABLE' | 'REQUEST_TIMEOUT'
/**
* Маркирует fetch failure, не смешивая его с TypeError из прикладного кода.
*/
export class {{name.pascalCase}}RestApiTransportError extends Error {
readonly code: {{name.pascalCase}}RestApiTransportErrorCode
readonly cause: unknown
constructor(code: {{name.pascalCase}}RestApiTransportErrorCode, cause: unknown) {
super(code)
this.name = '{{name.pascalCase}}RestApiTransportError'
this.code = code
this.cause = cause
}
}

View File

@@ -0,0 +1,3 @@
export { {{name.camelCase}}HttpClient } from './client'
export { {{name.pascalCase}}RestApiError, {{name.pascalCase}}RestApiTransportError } from './errors'
export { {{name.camelCase}}RestApi } from './rest-api'

View File

@@ -0,0 +1,14 @@
import { {{name.pascalCase}}RestApiTransportError } from '../errors'
/**
* Выполняет fetch с явной классификацией transport failure.
*/
export const {{name.camelCase}}RestApiFetch: typeof fetch = async (...params) => {
try {
return await fetch(...params)
} catch (error) {
const code = error instanceof DOMException && error.name === 'AbortError' ? 'REQUEST_TIMEOUT' : 'NETWORK_UNAVAILABLE'
throw new {{name.pascalCase}}RestApiTransportError(code, error)
}
}

View File

@@ -0,0 +1,7 @@
import { createApiClient } from '@biocad/{{name.kebabCase}}-rest-api-sdk/create-api-client'
import { operationsTree } from '@biocad/{{name.kebabCase}}-rest-api-sdk/operations-tree'
import { {{name.camelCase}}HttpClient } from './client'
/** Полный bound-клиент {{name.pascalCase}} REST API. */
export const {{name.camelCase}}RestApi = createApiClient({{name.camelCase}}HttpClient, operationsTree)