Files
GameList/wwwroot/js/api-client.generated.js

304 lines
8.7 KiB
JavaScript

// AUTO-GENERATED FILE. DO NOT EDIT.
// Source: scripts/generate-api-client.mjs and openapi/GameList.json
const defaultHeaders = { "Content-Type": "application/json" };
const rawBase = document.querySelector('meta[name="app-base"]')?.content || "";
const basePath = normalizeBase(rawBase);
const withBase = (routePath) => `${basePath}${routePath}`;
function normalizeBase(value) {
if (!value) return "";
if (!value.startsWith("/")) return `/${value}`;
return value.endsWith("/") ? value.slice(0, -1) : value;
}
function toApiError(res, fallbackMessage = `${res.status}`) {
const err = new Error(fallbackMessage);
err.status = res.status;
return err;
}
function buildPath(template, pathParameters = {}) {
return template.replace(/{([^}]+)}/g, (_, key) => {
const value = pathParameters[key];
if (value === undefined || value === null) {
throw new Error(
`Missing path parameter "${key}" for route ${template}`,
);
}
return encodeURIComponent(String(value));
});
}
async function parseApiError(res) {
try {
const data = await res.json();
const message =
data.error || data.detail || data.title || JSON.stringify(data);
return toApiError(res, message);
} catch {
return toApiError(res);
}
}
export const operations = Object.freeze({
CreateSuggestion: {
method: "POST",
path: "/api/suggestions",
hasBody: true,
pathParameters: [],
},
DeletePlayer: {
method: "DELETE",
path: "/api/admin/players/{playerId}",
hasBody: true,
pathParameters: ["playerId"],
},
DeleteSuggestion: {
method: "DELETE",
path: "/api/suggestions/{id}",
hasBody: false,
pathParameters: ["id"],
},
FactoryReset: {
method: "POST",
path: "/api/admin/factory-reset",
hasBody: true,
pathParameters: [],
},
GetAllSuggestions: {
method: "GET",
path: "/api/suggestions/all",
hasBody: false,
pathParameters: [],
},
GetAuthOptions: {
method: "GET",
path: "/api/auth/options",
hasBody: false,
pathParameters: [],
},
GetMe: {
method: "GET",
path: "/api/me",
hasBody: false,
pathParameters: [],
},
GetMySuggestions: {
method: "GET",
path: "/api/suggestions/mine",
hasBody: false,
pathParameters: [],
},
GetMyVotes: {
method: "GET",
path: "/api/votes/mine",
hasBody: false,
pathParameters: [],
},
GetResults: {
method: "GET",
path: "/api/results",
hasBody: false,
pathParameters: [],
},
GetState: {
method: "GET",
path: "/api/state",
hasBody: false,
pathParameters: [],
},
GetStateEvents: {
method: "GET",
path: "/api/events/state",
hasBody: false,
pathParameters: [],
},
GetVoteStatus: {
method: "GET",
path: "/api/admin/vote-status",
hasBody: false,
pathParameters: [],
},
GrantJoker: {
method: "POST",
path: "/api/admin/joker",
hasBody: true,
pathParameters: [],
},
LinkSuggestions: {
method: "POST",
path: "/api/admin/link-suggestions",
hasBody: true,
pathParameters: [],
},
Login: {
method: "POST",
path: "/api/auth/login",
hasBody: true,
pathParameters: [],
},
Logout: {
method: "POST",
path: "/api/auth/logout",
hasBody: false,
pathParameters: [],
},
NextPhase: {
method: "POST",
path: "/api/me/phase/next",
hasBody: false,
pathParameters: [],
},
PrevPhase: {
method: "POST",
path: "/api/me/phase/prev",
hasBody: false,
pathParameters: [],
},
Register: {
method: "POST",
path: "/api/auth/register",
hasBody: true,
pathParameters: [],
},
Reset: {
method: "POST",
path: "/api/admin/reset",
hasBody: true,
pathParameters: [],
},
SetPlayerAdmin: {
method: "POST",
path: "/api/admin/player-admin",
hasBody: true,
pathParameters: [],
},
SetPlayerPhase: {
method: "POST",
path: "/api/admin/player-phase",
hasBody: true,
pathParameters: [],
},
SetResultsOpen: {
method: "POST",
path: "/api/admin/results",
hasBody: true,
pathParameters: [],
},
SetVotesFinalized: {
method: "POST",
path: "/api/votes/finalize",
hasBody: true,
pathParameters: [],
},
UnlinkSuggestions: {
method: "POST",
path: "/api/admin/unlink-suggestions",
hasBody: true,
pathParameters: [],
},
UpdateSuggestion: {
method: "PUT",
path: "/api/suggestions/{id}",
hasBody: true,
pathParameters: ["id"],
},
UpsertVote: {
method: "POST",
path: "/api/votes",
hasBody: true,
pathParameters: [],
},
});
export function resolveOperationPath(operationId, pathParameters = {}) {
const operation = operations[operationId];
if (!operation) {
throw new Error(`Unknown operationId "${operationId}"`);
}
return withBase(buildPath(operation.path, pathParameters));
}
export async function requestOperation(
operationId,
{
pathParameters = {},
body,
headers = {},
raw = false,
acceptStatuses = [],
} = {},
) {
const operation = operations[operationId];
if (!operation) {
throw new Error(`Unknown operationId "${operationId}"`);
}
const response = await fetch(
resolveOperationPath(operationId, pathParameters),
{
method: operation.method,
credentials: "same-origin",
headers: { ...defaultHeaders, ...headers },
body: body === undefined ? undefined : JSON.stringify(body),
},
);
const acceptedStatusSet = new Set(acceptStatuses);
if (!response.ok && !acceptedStatusSet.has(response.status)) {
throw await parseApiError(response);
}
if (raw) return response;
if (response.status === 204) return null;
return response.json();
}
export const apiClient = Object.freeze({
getAuthOptions: (options = {}) =>
requestOperation("GetAuthOptions", options),
register: (options = {}) => requestOperation("Register", options),
login: (options = {}) => requestOperation("Login", options),
logout: (options = {}) => requestOperation("Logout", options),
getState: (options = {}) => requestOperation("GetState", options),
getStateEvents: (options = {}) =>
requestOperation("GetStateEvents", options),
getMe: (options = {}) => requestOperation("GetMe", options),
nextPhase: (options = {}) => requestOperation("NextPhase", options),
prevPhase: (options = {}) => requestOperation("PrevPhase", options),
getMySuggestions: (options = {}) =>
requestOperation("GetMySuggestions", options),
createSuggestion: (options = {}) =>
requestOperation("CreateSuggestion", options),
deleteSuggestion: (options = {}) =>
requestOperation("DeleteSuggestion", options),
updateSuggestion: (options = {}) =>
requestOperation("UpdateSuggestion", options),
getAllSuggestions: (options = {}) =>
requestOperation("GetAllSuggestions", options),
getMyVotes: (options = {}) => requestOperation("GetMyVotes", options),
upsertVote: (options = {}) => requestOperation("UpsertVote", options),
setVotesFinalized: (options = {}) =>
requestOperation("SetVotesFinalized", options),
getResults: (options = {}) => requestOperation("GetResults", options),
setResultsOpen: (options = {}) =>
requestOperation("SetResultsOpen", options),
getVoteStatus: (options = {}) => requestOperation("GetVoteStatus", options),
grantJoker: (options = {}) => requestOperation("GrantJoker", options),
setPlayerPhase: (options = {}) =>
requestOperation("SetPlayerPhase", options),
setPlayerAdmin: (options = {}) =>
requestOperation("SetPlayerAdmin", options),
deletePlayer: (options = {}) => requestOperation("DeletePlayer", options),
linkSuggestions: (options = {}) =>
requestOperation("LinkSuggestions", options),
unlinkSuggestions: (options = {}) =>
requestOperation("UnlinkSuggestions", options),
reset: (options = {}) => requestOperation("Reset", options),
factoryReset: (options = {}) => requestOperation("FactoryReset", options),
});