diff --git a/packages/frontend-plugin-api/package.json b/packages/frontend-plugin-api/package.json index daee6ddbbd..91dbaa553c 100644 --- a/packages/frontend-plugin-api/package.json +++ b/packages/frontend-plugin-api/package.json @@ -48,6 +48,7 @@ "@backstage/filter-predicates": "workspace:^", "@backstage/types": "workspace:^", "@backstage/version-bridge": "workspace:^", + "@standard-schema/spec": "^1.1.0", "zod": "^3.25.76 || ^4.0.0", "zod-to-json-schema": "^3.25.1" }, diff --git a/packages/frontend-plugin-api/report-alpha.api.md b/packages/frontend-plugin-api/report-alpha.api.md index 82d9da2627..4df3233871 100644 --- a/packages/frontend-plugin-api/report-alpha.api.md +++ b/packages/frontend-plugin-api/report-alpha.api.md @@ -14,6 +14,7 @@ import { FilterPredicate } from '@backstage/filter-predicates'; import { JsonObject } from '@backstage/types'; import { JSX as JSX_2 } from 'react'; import { ReactNode } from 'react'; +import { StandardSchemaV1 } from '@standard-schema/spec'; import { z } from 'zod/v3'; import { ZodType } from 'zod/v3'; @@ -85,6 +86,11 @@ export interface AppTree { readonly root: AppNode; } +// @public +export type ConfigFieldSchema = + | StandardSchemaV1 + | ((zImpl: typeof z) => ZodType); + // @public (undocumented) export interface ConfigurableExtensionDataRef< TData, @@ -161,7 +167,6 @@ export interface ExtensionBlueprint< inputs: T['inputs']; params: T['params']; }>; - // Warning: (ae-forgotten-export) The symbol "ConfigFieldSchema" needs to be exported by the entry point alpha.d.ts makeWithOverrides< TName extends string | undefined, TExtensionConfigSchema extends { @@ -650,6 +655,8 @@ export interface RouteRef< readonly T: TParams; } +export { StandardSchemaV1 }; + // @public export interface SubRouteRef< TParams extends AnyRouteRefParams = AnyRouteRefParams, diff --git a/packages/frontend-plugin-api/report.api.md b/packages/frontend-plugin-api/report.api.md index 54023e5b08..b975da2e14 100644 --- a/packages/frontend-plugin-api/report.api.md +++ b/packages/frontend-plugin-api/report.api.md @@ -22,6 +22,7 @@ import { JSX as JSX_3 } from 'react/jsx-runtime'; import { Observable } from '@backstage/types'; import { PropsWithChildren } from 'react'; import { ReactNode } from 'react'; +import { StandardSchemaV1 } from '@standard-schema/spec'; import { SwappableComponentRef as SwappableComponentRef_2 } from '@backstage/frontend-plugin-api'; import { z } from 'zod/v3'; import { ZodType } from 'zod/v3'; @@ -2146,75 +2147,7 @@ export namespace SessionState { export type SignedOut = typeof SessionState.SignedOut; } -// @public -export interface StandardSchemaV1 { - // (undocumented) - readonly '~standard': StandardSchemaV1.Props; -} - -// @public (undocumented) -export namespace StandardSchemaV1 { - // (undocumented) - export interface FailureResult { - // (undocumented) - readonly issues: ReadonlyArray; - } - // (undocumented) - export type InferInput = NonNullable< - Schema['~standard']['types'] - >['input']; - // (undocumented) - export type InferOutput = NonNullable< - Schema['~standard']['types'] - >['output']; - // (undocumented) - export interface Issue { - // (undocumented) - readonly message: string; - // (undocumented) - readonly path?: ReadonlyArray | undefined; - } - // (undocumented) - export interface Options { - // (undocumented) - readonly libraryOptions?: Record | undefined; - } - // (undocumented) - export interface PathSegment { - // (undocumented) - readonly key: PropertyKey; - } - // (undocumented) - export interface Props { - // (undocumented) - readonly types?: Types | undefined; - // (undocumented) - readonly validate: ( - value: unknown, - options?: Options | undefined, - ) => Result | Promise>; - // (undocumented) - readonly vendor: string; - // (undocumented) - readonly version: 1; - } - // (undocumented) - export type Result = SuccessResult | FailureResult; - // (undocumented) - export interface SuccessResult { - // (undocumented) - readonly issues?: undefined; - // (undocumented) - readonly value: Output; - } - // (undocumented) - export interface Types { - // (undocumented) - readonly input: Input; - // (undocumented) - readonly output: Output; - } -} +export { StandardSchemaV1 }; // @public export interface StorageApi { diff --git a/packages/frontend-plugin-api/src/alpha.ts b/packages/frontend-plugin-api/src/alpha.ts index e822c13f88..08226a4013 100644 --- a/packages/frontend-plugin-api/src/alpha.ts +++ b/packages/frontend-plugin-api/src/alpha.ts @@ -47,7 +47,11 @@ export type { AppNodeSpec, AppTree, } from './apis'; -export type { PortableSchema } from './schema'; +export type { + PortableSchema, + StandardSchemaV1, + ConfigFieldSchema, +} from './schema'; export type { AnyRouteRefParams, RouteRef, diff --git a/packages/frontend-plugin-api/src/schema/createPortableSchema.ts b/packages/frontend-plugin-api/src/schema/createPortableSchema.ts index 6e83ceef97..eab87ad562 100644 --- a/packages/frontend-plugin-api/src/schema/createPortableSchema.ts +++ b/packages/frontend-plugin-api/src/schema/createPortableSchema.ts @@ -33,77 +33,12 @@ import { z as zodV3, type ZodType } from 'zod/v3'; import zodToJsonSchema from 'zod-to-json-schema'; import { PortableSchema } from './types'; -// --------------------------------------------------------------------------- -// Standard Schema V1 — inlined from https://standardschema.dev -// -// This is the cross-library interface implemented by zod v3.25+, zod v4, -// valibot, arktype, and others. It's designed to be inlined: "Libraries -// wishing to implement the spec can copy/paste the code block below into -// their codebase" — no npm dependency required. -// -// See: https://github.com/standard-schema/standard-schema -// --------------------------------------------------------------------------- - /** * The Standard Schema interface. * @public */ -export interface StandardSchemaV1 { - readonly '~standard': StandardSchemaV1.Props; -} - -/** - * @public - */ -// eslint-disable-next-line @typescript-eslint/no-namespace -export namespace StandardSchemaV1 { - export interface Props { - readonly version: 1; - readonly vendor: string; - readonly validate: ( - value: unknown, - options?: Options | undefined, - ) => Result | Promise>; - readonly types?: Types | undefined; - } - - export type Result = SuccessResult | FailureResult; - - export interface SuccessResult { - readonly value: Output; - readonly issues?: undefined; - } - - export interface Options { - readonly libraryOptions?: Record | undefined; - } - - export interface FailureResult { - readonly issues: ReadonlyArray; - } - - export interface Issue { - readonly message: string; - readonly path?: ReadonlyArray | undefined; - } - - export interface PathSegment { - readonly key: PropertyKey; - } - - export interface Types { - readonly input: Input; - readonly output: Output; - } - - export type InferInput = NonNullable< - Schema['~standard']['types'] - >['input']; - - export type InferOutput = NonNullable< - Schema['~standard']['types'] - >['output']; -} +export type { StandardSchemaV1 } from '@standard-schema/spec'; +import { type StandardSchemaV1 } from '@standard-schema/spec'; // --------------------------------------------------------------------------- // Public types diff --git a/yarn.lock b/yarn.lock index 821675739b..53a41c163d 100644 --- a/yarn.lock +++ b/yarn.lock @@ -3779,6 +3779,7 @@ __metadata: "@backstage/test-utils": "workspace:^" "@backstage/types": "workspace:^" "@backstage/version-bridge": "workspace:^" + "@standard-schema/spec": "npm:^1.1.0" "@testing-library/jest-dom": "npm:^6.0.0" "@testing-library/react": "npm:^16.0.0" "@types/react": "npm:^18.0.0" @@ -19062,7 +19063,7 @@ __metadata: languageName: node linkType: hard -"@standard-schema/spec@npm:^1.0.0": +"@standard-schema/spec@npm:^1.0.0, @standard-schema/spec@npm:^1.1.0": version: 1.1.0 resolution: "@standard-schema/spec@npm:1.1.0" checksum: 10/a209615c9e8b2ea535d7db0a5f6aa0f962fd4ab73ee86a46c100fb78116964af1f55a27c1794d4801e534a196794223daa25ff5135021e03c7828aa3d95e1763