From 251c19438a4b24d50675717f37f42eba3ce2e76a Mon Sep 17 00:00:00 2001 From: Patrik Oldsberg Date: Tue, 12 Sep 2023 12:43:27 +0200 Subject: [PATCH] core-app,plugin-api: update API reports + fixes Signed-off-by: Patrik Oldsberg --- packages/core-app-api/alpha-api-report.md | 63 +------- packages/core-app-api/api-report.md | 18 +-- .../core-app-api/src/app/AppManager.test.tsx | 4 +- packages/core-app-api/src/app/AppManager.tsx | 2 +- packages/core-app-api/src/app/types.ts | 1 - packages/core-plugin-api/alpha-api-report.md | 152 +++++++++++++++--- 6 files changed, 144 insertions(+), 96 deletions(-) diff --git a/packages/core-app-api/alpha-api-report.md b/packages/core-app-api/alpha-api-report.md index f35adfdbaa..9b6ffea91e 100644 --- a/packages/core-app-api/alpha-api-report.md +++ b/packages/core-app-api/alpha-api-report.md @@ -5,32 +5,18 @@ ```ts import { AppTranslationApi } from '@backstage/core-plugin-api/alpha'; import { i18n } from 'i18next'; +import { TranslationMessages } from '@backstage/core-plugin-api/alpha'; import { TranslationRef } from '@backstage/core-plugin-api/alpha'; +import { TranslationResource } from '@backstage/core-plugin-api/alpha'; // @alpha (undocumented) export class AppTranslationApiImpl implements AppTranslationApi { // (undocumented) - addLazyResources>( - translationRef: TranslationRef, - initResources?: Record< - string, - () => Promise<{ - messages: TranslationMessages; - }> - >, - ): void; + addLazyResources(resource: TranslationResource): void; // (undocumented) - addResources>( - translationRef: TranslationRef, - initResources?: Record< - string, - TranslationMessages> - >, - ): void; + addMessages(messages: TranslationMessages): void; // (undocumented) - addResourcesByRef>( - translationRef: TranslationRef, - ): void; + addResource(translationRef: TranslationRef): void; // (undocumented) static create(options?: ExperimentalI18n): AppTranslationApiImpl; // (undocumented) @@ -39,47 +25,12 @@ export class AppTranslationApiImpl implements AppTranslationApi { initMessages(options?: ExperimentalI18n): void; } -// @alpha (undocumented) -export function createTranslationResource(options: { - ref: T; - messages?: Record>; - lazyMessages: Record< - string, - () => Promise<{ - messages: TranslationMessages; - }> - >; -}): { - ref: T; - messages?: Record> | undefined; - lazyMessages: Record< - string, - () => Promise<{ - messages: TranslationMessages; - }> - >; -}; - // @alpha (undocumented) export type ExperimentalI18n = { - supportedLanguages: string[]; fallbackLanguage?: string | string[]; - messages?: Array<{ - ref: TranslationRef; - messages?: Record>; - lazyMessages: Record< - string, - () => Promise<{ - messages: TranslationMessages; - }> - >; - }>; + supportedLanguages?: string[]; + resources?: Array; }; -// @alpha (undocumented) -export type TranslationMessages = T extends TranslationRef - ? Partial - : never; - // (No @packageDocumentation comment for this package) ``` diff --git a/packages/core-app-api/api-report.md b/packages/core-app-api/api-report.md index e53d2eed83..1b5a5b4798 100644 --- a/packages/core-app-api/api-report.md +++ b/packages/core-app-api/api-report.md @@ -64,7 +64,8 @@ import { SessionState } from '@backstage/core-plugin-api'; import { StorageApi } from '@backstage/core-plugin-api'; import { StorageValueSnapshot } from '@backstage/core-plugin-api'; import { SubRouteRef } from '@backstage/core-plugin-api'; -import { TranslationRef } from '@backstage/core-plugin-api/alpha'; +import { TranslationMessages } from '@backstage/core-plugin-api/alpha'; +import { TranslationResource } from '@backstage/core-plugin-api/alpha'; // @public export class AlertApiForwarder implements AlertApi { @@ -221,19 +222,10 @@ export type AppOptions = { themes: (Partial & Omit)[]; configLoader?: AppConfigLoader; bindRoutes?(context: { bind: AppRouteBinder }): void; - __experimentalI18n?: { - supportedLanguages: string[]; + __experimentalTranslations?: { fallbackLanguage?: string | string[]; - messages?: Array<{ - ref: TranslationRef; - messages?: Record>; - lazyMessages: Record< - string, - () => Promise<{ - messages: TranslationMessages; - }> - >; - }>; + supportedLanguages?: string[]; + resources?: Array; }; }; diff --git a/packages/core-app-api/src/app/AppManager.test.tsx b/packages/core-app-api/src/app/AppManager.test.tsx index 1b68cfd6ca..2eddcfc3ae 100644 --- a/packages/core-app-api/src/app/AppManager.test.tsx +++ b/packages/core-app-api/src/app/AppManager.test.tsx @@ -260,7 +260,7 @@ describe('Integration Test', () => { expect(screen.getByText('extLink4: ')).toBeInTheDocument(); }); - it('runs success with __experimentalI18n', async () => { + it('runs success with __experimentalTranslations', async () => { const app = new AppManager({ apis: [noOpAnalyticsApi], defaultApis: [], @@ -275,7 +275,7 @@ describe('Integration Test', () => { extRouteRef2: plugin2RouteRef, }); }, - __experimentalI18n: { + __experimentalTranslations: { supportedLanguages: ['en'], }, }); diff --git a/packages/core-app-api/src/app/AppManager.tsx b/packages/core-app-api/src/app/AppManager.tsx index 0bd495c03b..bd6a1ba3d0 100644 --- a/packages/core-app-api/src/app/AppManager.tsx +++ b/packages/core-app-api/src/app/AppManager.tsx @@ -179,7 +179,7 @@ export class AppManager implements BackstageApp { this.bindRoutes = options.bindRoutes; this.apiFactoryRegistry = new ApiFactoryRegistry(); this.appTranslationApi = AppTranslationApiImpl.create( - options.__experimentalI18n, + options.__experimentalTranslations, ); } diff --git a/packages/core-app-api/src/app/types.ts b/packages/core-app-api/src/app/types.ts index ea51723d21..0adb93cfd1 100644 --- a/packages/core-app-api/src/app/types.ts +++ b/packages/core-app-api/src/app/types.ts @@ -29,7 +29,6 @@ import { import { AppConfig } from '@backstage/config'; import { TranslationMessages, - TranslationRef, TranslationResource, } from '@backstage/core-plugin-api/alpha'; diff --git a/packages/core-plugin-api/alpha-api-report.md b/packages/core-plugin-api/alpha-api-report.md index 119f5c570e..f186c36b7f 100644 --- a/packages/core-plugin-api/alpha-api-report.md +++ b/packages/core-plugin-api/alpha-api-report.md @@ -7,27 +7,64 @@ import { ApiRef } from '@backstage/core-plugin-api'; import { BackstagePlugin } from '@backstage/core-plugin-api'; import { i18n } from 'i18next'; import { ReactNode } from 'react'; +import { TranslationMessages as TranslationMessages_2 } from '@backstage/core-plugin-api/alpha'; +import { TranslationRef as TranslationRef_2 } from '@backstage/core-plugin-api/alpha'; // @alpha (undocumented) export type AppTranslationApi = { getI18n(): i18n; - addResourcesByRef>( - translationRef: TranslationRef, - ): void; + addResource(resource: TranslationRef): void; }; // @alpha (undocumented) export const appTranslationApiRef: ApiRef; -// @alpha (undocumented) -export function createTranslationRef< +// @alpha +export function createTranslationMessages< + TId extends string, TMessages extends { [key in string]: string; }, - TId extends string = string, + TFull extends boolean, >( - config: TranslationRefOptions, -): TranslationRef; + options: TranslationMessagesOptions, +): TranslationMessages; + +// @alpha (undocumented) +export function createTranslationRef< + TId extends string, + TMessages extends { + [key in string]: string; + }, + TTranslations extends { + [language in string]: () => Promise<{ + default: { + [key in keyof TMessages]: string | null; + }; + }>; + }, +>( + config: TranslationRefOptions, +): TranslationRef; + +// @alpha (undocumented) +export function createTranslationResource< + TId extends string, + TMessages extends { + [key in string]: string; + }, + TTranslations extends { + [language in string]: () => Promise<{ + default: + | TranslationMessages_2 + | { + [key in keyof TMessages]: string | null; + }; + }>; + }, +>( + options: TranslationResourceOptions, +): TranslationResource; // @alpha export interface PluginOptionsProviderProps { @@ -40,17 +77,56 @@ export interface PluginOptionsProviderProps { // @alpha export const PluginProvider: (props: PluginOptionsProviderProps) => JSX.Element; -// @alpha (undocumented) -export interface TranslationOptions {} - -// @alpha (undocumented) -export interface TranslationRef< +// @alpha +export interface TranslationMessages< + TId extends string = string, TMessages extends { [key in string]: string; } = { [key in string]: string; }, + TFull extends boolean = boolean, +> { + // (undocumented) + $$type: '@backstage/TranslationMessages'; + full: TFull; + id: TId; + messages: TMessages; +} + +// @alpha +export interface TranslationMessagesOptions< + TId extends string, + TMessages extends { + [key in string]: string; + }, + TFull extends boolean, +> { + // (undocumented) + full?: TFull; + // (undocumented) + messages: false extends TFull + ? { + [key in keyof TMessages]?: string | null; + } + : { + [key in keyof TMessages]: string | null; + }; + // (undocumented) + ref: TranslationRef_2; +} + +// @alpha (undocumented) +export interface TranslationOptions {} + +// @alpha (undocumented) +export interface TranslationRef< TId extends string = string, + TMessages extends { + [key in string]: string; + } = { + [key in string]: string; + }, > { // (undocumented) $$type: '@backstage/TranslationRef'; @@ -62,24 +138,54 @@ export interface TranslationRef< // @alpha (undocumented) export interface TranslationRefOptions< + TId extends string, TMessages extends { [key in string]: string; }, - TId extends string = string, + TTranslations extends { + [language in string]: () => Promise<{ + default: { + [key in keyof TMessages]: string | null; + }; + }>; + }, > { // (undocumented) id: TId; // (undocumented) - lazyResources?: Record< - string, - () => Promise<{ - messages: TMessages; - }> - >; - // (undocumented) messages: TMessages; // (undocumented) - resources?: Record; + translations?: TTranslations; +} + +// @alpha (undocumented) +export interface TranslationResource { + // (undocumented) + $$type: '@backstage/TranslationResource'; + // (undocumented) + id: TId; +} + +// @alpha (undocumented) +export interface TranslationResourceOptions< + TId extends string, + TMessages extends { + [key in string]: string; + }, + TTranslations extends { + [language in string]: () => Promise<{ + default: + | TranslationMessages_2 + | { + [key in keyof TMessages]: string | null; + }; + }>; + }, +> { + // (undocumented) + ref: TranslationRef_2; + // (undocumented) + translations: TTranslations; } // @alpha @@ -93,7 +199,7 @@ export const useTranslationRef: < [x: string]: string; }, >( - translationRef: TranslationRef, + translationRef: TranslationRef, ) => ( key: TKey, options?: TranslationOptions,