Some checks failed
Release Workflow / determine-release-type (push) Has been cancelled
Release Workflow / checks (push) Has been cancelled
Release Workflow / e2e-tests (push) Has been cancelled
Release Workflow / build-images (push) Has been cancelled
Release Workflow / publish-release (push) Has been cancelled
* chore(deps): bump the minor-patch group with 6 updates Bumps the minor-patch group with 6 updates: | Package | From | To | | --- | --- | --- | | @scalar/hono-api-reference | `0.9.44` | `0.9.45` | | @tanstack/react-router | `1.162.8` | `1.162.9` | | @tanstack/react-router-ssr-query | `1.162.8` | `1.162.9` | | @tanstack/react-start | `1.162.8` | `1.162.9` | | @hey-api/openapi-ts | `0.92.4` | `0.93.0` | | oxlint-tsgolint | `0.14.2` | `0.15.0` | Updates `@scalar/hono-api-reference` from 0.9.44 to 0.9.45 Updates `@tanstack/react-router` from 1.162.8 to 1.162.9 Updates `@tanstack/react-router-ssr-query` from 1.162.8 to 1.162.9 Updates `@tanstack/react-start` from 1.162.8 to 1.162.9 Updates `@hey-api/openapi-ts` from 0.92.4 to 0.93.0 Updates `oxlint-tsgolint` from 0.14.2 to 0.15.0 --- updated-dependencies: - dependency-name: "@scalar/hono-api-reference" dependency-version: 0.9.45 dependency-type: direct:production update-type: version-update:semver-patch dependency-group: minor-patch - dependency-name: "@tanstack/react-router" dependency-version: 1.162.9 dependency-type: direct:production update-type: version-update:semver-patch dependency-group: minor-patch - dependency-name: "@tanstack/react-router-ssr-query" dependency-version: 1.162.9 dependency-type: direct:production update-type: version-update:semver-patch dependency-group: minor-patch - dependency-name: "@tanstack/react-start" dependency-version: 1.162.9 dependency-type: direct:production update-type: version-update:semver-patch dependency-group: minor-patch - dependency-name: "@hey-api/openapi-ts" dependency-version: 0.93.0 dependency-type: direct:development update-type: version-update:semver-minor dependency-group: minor-patch - dependency-name: oxlint-tsgolint dependency-version: 0.15.0 dependency-type: direct:development update-type: version-update:semver-minor dependency-group: minor-patch ... Signed-off-by: dependabot[bot] <support@github.com> * chore: gen-api client --------- Signed-off-by: dependabot[bot] <support@github.com> Co-authored-by: dependabot[bot] <49699333+dependabot[bot]@users.noreply.github.com> Co-authored-by: Nicolas Meienberger <github@thisprops.com>
170 lines
3.5 KiB
TypeScript
170 lines
3.5 KiB
TypeScript
// @ts-nocheck
|
|
// This file is auto-generated by @hey-api/openapi-ts
|
|
|
|
type Slot = "body" | "headers" | "path" | "query";
|
|
|
|
export type Field =
|
|
| {
|
|
in: Exclude<Slot, "body">;
|
|
/**
|
|
* Field name. This is the name we want the user to see and use.
|
|
*/
|
|
key: string;
|
|
/**
|
|
* Field mapped name. This is the name we want to use in the request.
|
|
* If omitted, we use the same value as `key`.
|
|
*/
|
|
map?: string;
|
|
}
|
|
| {
|
|
in: Extract<Slot, "body">;
|
|
/**
|
|
* Key isn't required for bodies.
|
|
*/
|
|
key?: string;
|
|
map?: string;
|
|
}
|
|
| {
|
|
/**
|
|
* Field name. This is the name we want the user to see and use.
|
|
*/
|
|
key: string;
|
|
/**
|
|
* Field mapped name. This is the name we want to use in the request.
|
|
* If `in` is omitted, `map` aliases `key` to the transport layer.
|
|
*/
|
|
map: Slot;
|
|
};
|
|
|
|
export interface Fields {
|
|
allowExtra?: Partial<Record<Slot, boolean>>;
|
|
args?: ReadonlyArray<Field>;
|
|
}
|
|
|
|
export type FieldsConfig = ReadonlyArray<Field | Fields>;
|
|
|
|
const extraPrefixesMap: Record<string, Slot> = {
|
|
$body_: "body",
|
|
$headers_: "headers",
|
|
$path_: "path",
|
|
$query_: "query",
|
|
};
|
|
const extraPrefixes = Object.entries(extraPrefixesMap);
|
|
|
|
type KeyMap = Map<
|
|
string,
|
|
| {
|
|
in: Slot;
|
|
map?: string;
|
|
}
|
|
| {
|
|
in?: never;
|
|
map: Slot;
|
|
}
|
|
>;
|
|
|
|
const buildKeyMap = (fields: FieldsConfig, map?: KeyMap): KeyMap => {
|
|
if (!map) {
|
|
map = new Map();
|
|
}
|
|
|
|
for (const config of fields) {
|
|
if ("in" in config) {
|
|
if (config.key) {
|
|
map.set(config.key, {
|
|
in: config.in,
|
|
map: config.map,
|
|
});
|
|
}
|
|
} else if ("key" in config) {
|
|
map.set(config.key, {
|
|
map: config.map,
|
|
});
|
|
} else if (config.args) {
|
|
buildKeyMap(config.args, map);
|
|
}
|
|
}
|
|
|
|
return map;
|
|
};
|
|
|
|
interface Params {
|
|
body: unknown;
|
|
headers: Record<string, unknown>;
|
|
path: Record<string, unknown>;
|
|
query: Record<string, unknown>;
|
|
}
|
|
|
|
const stripEmptySlots = (params: Params) => {
|
|
for (const [slot, value] of Object.entries(params)) {
|
|
if (value && typeof value === "object" && !Object.keys(value).length) {
|
|
delete params[slot as Slot];
|
|
}
|
|
}
|
|
};
|
|
|
|
export const buildClientParams = (args: ReadonlyArray<unknown>, fields: FieldsConfig) => {
|
|
const params: Params = {
|
|
body: {},
|
|
headers: {},
|
|
path: {},
|
|
query: {},
|
|
};
|
|
|
|
const map = buildKeyMap(fields);
|
|
|
|
let config: FieldsConfig[number] | undefined;
|
|
|
|
for (const [index, arg] of args.entries()) {
|
|
if (fields[index]) {
|
|
config = fields[index];
|
|
}
|
|
|
|
if (!config) {
|
|
continue;
|
|
}
|
|
|
|
if ("in" in config) {
|
|
if (config.key) {
|
|
const field = map.get(config.key)!;
|
|
const name = field.map || config.key;
|
|
if (field.in) {
|
|
(params[field.in] as Record<string, unknown>)[name] = arg;
|
|
}
|
|
} else {
|
|
params.body = arg;
|
|
}
|
|
} else {
|
|
for (const [key, value] of Object.entries(arg ?? {})) {
|
|
const field = map.get(key);
|
|
|
|
if (field) {
|
|
if (field.in) {
|
|
const name = field.map || key;
|
|
(params[field.in] as Record<string, unknown>)[name] = value;
|
|
} else {
|
|
params[field.map] = value;
|
|
}
|
|
} else {
|
|
const extra = extraPrefixes.find(([prefix]) => key.startsWith(prefix));
|
|
|
|
if (extra) {
|
|
const [prefix, slot] = extra;
|
|
(params[slot] as Record<string, unknown>)[key.slice(prefix.length)] = value;
|
|
} else if ("allowExtra" in config && config.allowExtra) {
|
|
for (const [slot, allowed] of Object.entries(config.allowExtra)) {
|
|
if (allowed) {
|
|
(params[slot as Slot] as Record<string, unknown>)[key] = value;
|
|
break;
|
|
}
|
|
}
|
|
}
|
|
}
|
|
}
|
|
}
|
|
}
|
|
|
|
stripEmptySlots(params);
|
|
|
|
return params;
|
|
};
|