Files
Jordi Enric fa7c223209 fix(studio): use Compute management endpoints FUNC-896 (#50393)
## Problem

Studio still called the legacy `/workers` Management API routes and used
the old `project_worker` response contract, so Compute instances could
not be listed or retrieved after the API rename. The production API type
check also detected drift in the v1 and platform declarations.

## Fix

- Regenerate the v1, v2, and platform API declarations from the deployed
schemas.
- Update Studio list and detail queries to `/compute`.
- Align typed fixtures with the Compute response schemas and
`project_compute_instance` resource type.
- Update platform response type references to the generated `_Output`
schema names.

## How to test

- Run `pnpm api:verify-types`.
- Run `pnpm --filter api-types test`.
- Run `pnpm --filter studio test data/compute/compute.utils.test.ts
"tests/pages/project/[ref]/compute/index.test.tsx"`.
- Run `pnpm --filter studio typecheck`.
- Run `pnpm --filter common typecheck`.
- Run `pnpm --filter studio lint:ratchet`.

Expected result: production API declarations are synchronized, and
Studio requests the `/compute` list and detail endpoints and renders
`project_compute_instance` responses successfully.

<!-- This is an auto-generated comment: release notes by coderabbit.ai
-->

## Summary by CodeRabbit

* **Improvements**
* Updated API response handling across profiles, backups, notifications,
integrations, warehouses, access tokens, payments, and other Studio
workflows for more accurate serialized data.
* Compute instance pages and queries now use the compute-specific API
endpoints and response data.
* Improved feature-flag type handling when disabled feature data is
unavailable.

* **Tests**
* Updated automated coverage and fixtures to reflect current compute and
API response formats.

<!-- end of auto-generated comment: release notes by coderabbit.ai -->
2026-09-15 12:50:56 +02:00

73 lines
2.3 KiB
TypeScript

import type { components } from 'api-types'
import enabledFeaturesRaw from './enabled-features.json' with { type: 'json' }
const enabledFeaturesStaticObj = enabledFeaturesRaw as Omit<typeof enabledFeaturesRaw, '$schema'>
type Profile = components['schemas']['ProfileResponse_Output']
export type Feature =
| NonNullable<Profile['disabled_features']>[number]
| keyof typeof enabledFeaturesStaticObj
const disabledFeaturesStaticArray = Object.entries(enabledFeaturesStaticObj)
.filter(([_, value]) => !value)
.map(([key]) => key as Feature)
function checkFeature(feature: Feature, features: Set<Feature>) {
return !features.has(feature)
}
type SnakeToCamelCase<S extends string> = S extends `${infer First}_${infer Rest}`
? `${First}${SnakeToCamelCase<Capitalize<Rest>>}`
: S
type FeatureToCamelCase<S extends Feature> = S extends `${infer P}:${infer R}`
? `${SnakeToCamelCase<P>}${Capitalize<SnakeToCamelCase<R>>}`
: SnakeToCamelCase<S>
function featureToCamelCase(feature: Feature) {
return feature
.replace(/:/g, '_')
.split('_')
.map((word, index) => (index === 0 ? word : word[0].toUpperCase() + word.slice(1)))
.join('') as FeatureToCamelCase<typeof feature>
}
function isFeatureEnabled<T extends Feature[]>(
features: T,
runtimeDisabledFeatures?: Feature[]
): { [key in FeatureToCamelCase<T[number]>]: boolean }
function isFeatureEnabled(features: Feature, runtimeDisabledFeatures?: Feature[]): boolean
function isFeatureEnabled<T extends Feature | Feature[]>(
features: T,
runtimeDisabledFeatures?: Feature[]
) {
// Override is used to produce a filtered version of the docs search index
// using the same sync setup as our normal search index
if (process.env.ENABLED_FEATURES_OVERRIDE_DISABLE_ALL === 'true') {
if (Array.isArray(features)) {
return Object.fromEntries(features.map((feature) => [featureToCamelCase(feature), false]))
}
return false
}
const disabledFeatures = new Set([
...(runtimeDisabledFeatures ?? []),
...disabledFeaturesStaticArray,
])
if (Array.isArray(features)) {
return Object.fromEntries(
features.map((feature) => [
featureToCamelCase(feature),
checkFeature(feature, disabledFeatures),
])
)
}
return checkFeature(features, disabledFeatures)
}
export { isFeatureEnabled }