diff --git a/packages/sdk/src/index.gen.ts b/packages/sdk/src/index.gen.ts index 6fe375b93..5ea59a07b 100644 --- a/packages/sdk/src/index.gen.ts +++ b/packages/sdk/src/index.gen.ts @@ -26,7 +26,7 @@ import { Interlinkv1beta1 } from '@scaleway/sdk-interlink' import { Iotv1 } from '@scaleway/sdk-iot' import { Ipamv1 } from '@scaleway/sdk-ipam' import { Jobsv1alpha1 } from '@scaleway/sdk-jobs' -import { K8sv1 } from '@scaleway/sdk-k8s' +import { K8Sv1 } from '@scaleway/sdk-k8s' import { KeyManagerv1alpha1 } from '@scaleway/sdk-key-manager' import { Lbv1 } from '@scaleway/sdk-lb' import { Marketplacev2 } from '@scaleway/sdk-marketplace' @@ -37,7 +37,7 @@ import { Qaasv1alpha1 } from '@scaleway/sdk-qaas' import { Rdbv1 } from '@scaleway/sdk-rdb' import { Redisv1 } from '@scaleway/sdk-redis' import { Registryv1 } from '@scaleway/sdk-registry' -import { S2sVpnv1alpha1 } from '@scaleway/sdk-s2s-vpn' +import { S2SVpnv1alpha1 } from '@scaleway/sdk-s2s-vpn' import { Secretv1beta1 } from '@scaleway/sdk-secret' import { ServerlessSqldbv1alpha1 } from '@scaleway/sdk-serverless-sqldb' import { Temv1alpha1 } from '@scaleway/sdk-tem' @@ -246,9 +246,9 @@ export const Jobs = { /** * @deprecated Direct version exports are deprecated. Use the 'K8s' namespace instead (e.g., K8s.v1). */ -export { K8sv1 } +export { K8Sv1 } export const K8s = { - v1: K8sv1, + v1: K8Sv1, } /** @@ -335,9 +335,9 @@ export const Registry = { /** * @deprecated Direct version exports are deprecated. Use the 'S2sVpn' namespace instead (e.g., S2sVpn.v1). */ -export { S2sVpnv1alpha1 } +export { S2SVpnv1alpha1 } export const S2sVpn = { - v1alpha1: S2sVpnv1alpha1, + v1alpha1: S2SVpnv1alpha1, } /** diff --git a/packages_generated/k8s/src/index.gen.ts b/packages_generated/k8s/src/index.gen.ts index ae7759ec8..d8ff060c6 100644 --- a/packages_generated/k8s/src/index.gen.ts +++ b/packages_generated/k8s/src/index.gen.ts @@ -3,4 +3,4 @@ * PLEASE DO NOT EDIT HERE */ -export * as K8sv1 from './v1/index' +export * as K8Sv1 from './v1/index' diff --git a/packages_generated/s2s_vpn/src/index.gen.ts b/packages_generated/s2s_vpn/src/index.gen.ts index b98c2003d..3dd7c20db 100644 --- a/packages_generated/s2s_vpn/src/index.gen.ts +++ b/packages_generated/s2s_vpn/src/index.gen.ts @@ -3,4 +3,4 @@ * PLEASE DO NOT EDIT HERE */ -export * as S2sVpnv1alpha1 from './v1alpha1/index.gen' +export * as S2SVpnv1alpha1 from './v1alpha1/index.gen' diff --git a/packages_generated/webhosting/src/v1/marshalling.gen.ts b/packages_generated/webhosting/src/v1/marshalling.gen.ts index 8ecd185dc..5f0a9b626 100644 --- a/packages_generated/webhosting/src/v1/marshalling.gen.ts +++ b/packages_generated/webhosting/src/v1/marshalling.gen.ts @@ -418,6 +418,7 @@ const unmarshalOffer = (data: unknown): Offer => { options: unmarshalArrayOfObject(data.options, unmarshalOfferOption), price: data.price ? unmarshalMoney(data.price) : undefined, quotaWarning: data.quota_warning, + region: data.region, } as Offer } diff --git a/packages_generated/webhosting/src/v1/types.gen.ts b/packages_generated/webhosting/src/v1/types.gen.ts index 69a751832..3a6291ccd 100644 --- a/packages_generated/webhosting/src/v1/types.gen.ts +++ b/packages_generated/webhosting/src/v1/types.gen.ts @@ -420,6 +420,10 @@ export interface Offer { * Defines a warning if the maximum value for an option in the offer is exceeded. */ quotaWarning: OfferOptionWarning + /** + * Region where the offer is hosted. + */ + region: ScwRegion } export interface Platform { diff --git a/scripts/generateAlias.ts b/scripts/generateAlias.ts index de0f55c3c..cb693e26d 100644 --- a/scripts/generateAlias.ts +++ b/scripts/generateAlias.ts @@ -1,4 +1,10 @@ -import { appendFileSync, readdirSync, statSync, writeFileSync } from 'node:fs' +import { + appendFileSync, + readdirSync, + readFileSync, + statSync, + writeFileSync, +} from 'node:fs' import { join } from 'node:path' const GENERATED_PATH = 'packages_generated' @@ -12,6 +18,28 @@ const toPascal = (s: string) => const toSlug = (s: string) => s.replace(/_/g, '-') +/** + * Extract real export names from package's index.gen.ts + * This ensures we use the exact same names as exported by the package + */ +const getExportsFromPackage = (packagePath: string): string[] => { + const indexPath = join(packagePath, 'src', 'index.gen.ts') + try { + const content = readFileSync(indexPath, 'utf8') + const exportPattern = /export \* as (\w+) from/g + const exports: string[] = [] + let match + + while ((match = exportPattern.exec(content)) !== null) { + exports.push(match[1]) + } + + return exports + } catch (err: unknown) { + throw new Error(`Error reading exports from ${indexPath}: ${err.message}`) + } +} + const services = readdirSync(GENERATED_PATH).filter(folder => { const fullPath = join(GENERATED_PATH, folder) @@ -29,34 +57,38 @@ let importsOutput = '' for (const service of services) { const slug = toSlug(service) const pascal = toPascal(service) - const srcPath = join(GENERATED_PATH, service, 'src') + const packagePath = join(GENERATED_PATH, service) - let versions: string[] = [] + // Get real exports from the package + let exportedNames: string[] = [] try { - versions = readdirSync(srcPath).filter(vFolder => { - const vPath = join(srcPath, vFolder) - - return statSync(vPath).isDirectory() && /^v[0-9a-z]+$/i.test(vFolder) - }) + exportedNames = getExportsFromPackage(packagePath) } catch (err: unknown) { throw new Error( - `Error: missing or unreadable 'src' folder for package '${service}': ${err.message}`, + `Error getting exports for package '${service}': ${err.message}`, ) } writeFileSync(OUTPUT_PATH, AUTO_GENERATE_MESSAGE) - if (versions.length > 0) { + if (exportedNames.length > 0) { const imports: string[] = [] const versionsImport: string[] = [] const mappings: string[] = [] - for (const version of versions) { - const importName = `${pascal}${version}` - versionsImport.push(`${importName}`) - mappings.push(` ${version}: ${importName},`) + for (const exportName of exportedNames) { + // Extract version from export name (e.g., K8Sv1 -> v1, S2SVpnv1alpha1 -> v1alpha1) + // Version must start with lowercase 'v' followed by digits + const versionMatch = exportName.match(/(v\d+[a-z]*\d*)$/) + if (versionMatch) { + const version = versionMatch[1] + versionsImport.push(exportName) + mappings.push(` ${version}: ${exportName},`) + } } - imports.push(`import { ${versionsImport} } from '@scaleway/sdk-${slug}'`) + imports.push( + `import { ${versionsImport.join(', ')} } from '@scaleway/sdk-${slug}'`, + ) importsOutput += `${imports.join('\n')}\n` const importedNames = imports