58 lines
1.7 KiB
JavaScript
58 lines
1.7 KiB
JavaScript
/**
|
|
* @typedef {{
|
|
* method: string,
|
|
* path: string,
|
|
* operationId: string,
|
|
* auth: "none" | "external-session",
|
|
* timeoutMs: number | null,
|
|
* idempotency: "safe" | "keyed" | "none",
|
|
* retry: "runtime" | "never",
|
|
* requestSource: "search" | "body" | "none",
|
|
* requestSchema: string,
|
|
* responseSchema: string,
|
|
* owner: string
|
|
* }} ApiOperation
|
|
*/
|
|
|
|
/** @param {ApiOperation} definition */
|
|
const operation = (definition) => Object.freeze(definition);
|
|
|
|
export const API_OPERATIONS = Object.freeze({
|
|
LIST_SAMPLE_RESOURCES: operation({
|
|
method: "GET",
|
|
path: "/api/sample/resources",
|
|
operationId: "LIST_SAMPLE_RESOURCES",
|
|
auth: "external-session",
|
|
timeoutMs: null,
|
|
idempotency: "safe",
|
|
retry: "runtime",
|
|
requestSource: "search",
|
|
requestSchema: "SampleResourceListQuery",
|
|
responseSchema: "SampleResourceListPayload",
|
|
owner: "feature-sample-feature-slice-contract-fixture",
|
|
}),
|
|
CREATE_SAMPLE_RESOURCE: operation({
|
|
method: "POST",
|
|
path: "/api/sample/resources",
|
|
operationId: "CREATE_SAMPLE_RESOURCE",
|
|
auth: "external-session",
|
|
timeoutMs: null,
|
|
idempotency: "keyed",
|
|
retry: "runtime",
|
|
requestSource: "body",
|
|
requestSchema: "CreateSampleResourceCommand",
|
|
responseSchema: "SampleResourcePayload",
|
|
owner: "feature-sample-feature-slice-contract-fixture",
|
|
}),
|
|
});
|
|
|
|
/** @param {string} operationId */
|
|
export function getApiOperation(operationId) {
|
|
const registry = /** @type {Record<string, ApiOperation>} */ (API_OPERATIONS);
|
|
const selected = registry[operationId];
|
|
if (!selected) {
|
|
throw new Error(`Unregistered API operation: ${operationId}`);
|
|
}
|
|
return selected;
|
|
}
|