@backstage/frontend-plugin-api 0.6.8-next.0 → 0.6.8-next.1
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/CHANGELOG.md +66 -0
- package/dist/apis/definitions/AppTreeApi.esm.js.map +1 -1
- package/dist/components/ExtensionBoundary.esm.js +2 -0
- package/dist/components/ExtensionBoundary.esm.js.map +1 -1
- package/dist/extensions/IconBundleBlueprint.esm.js +11 -3
- package/dist/extensions/IconBundleBlueprint.esm.js.map +1 -1
- package/dist/index.d.ts +271 -88
- package/dist/schema/createSchemaFromZod.esm.js.map +1 -1
- package/dist/wiring/createExtension.esm.js +19 -10
- package/dist/wiring/createExtension.esm.js.map +1 -1
- package/dist/wiring/createExtensionBlueprint.esm.js +13 -8
- package/dist/wiring/createExtensionBlueprint.esm.js.map +1 -1
- package/dist/wiring/createExtensionDataRef.esm.js +21 -14
- package/dist/wiring/createExtensionDataRef.esm.js.map +1 -1
- package/dist/wiring/createExtensionInput.esm.js +20 -0
- package/dist/wiring/createExtensionInput.esm.js.map +1 -1
- package/dist/wiring/createExtensionOverrides.esm.js.map +1 -1
- package/dist/wiring/createPlugin.esm.js.map +1 -1
- package/dist/wiring/resolveExtensionDefinition.esm.js +1 -1
- package/dist/wiring/resolveExtensionDefinition.esm.js.map +1 -1
- package/package.json +5 -5
package/dist/index.d.ts
CHANGED
|
@@ -4,9 +4,9 @@ import * as _backstage_core_plugin_api from '@backstage/core-plugin-api';
|
|
|
4
4
|
import { ApiRef, AnyApiRef, AnyApiFactory, IconComponent as IconComponent$1, SignInPageProps, AppTheme } from '@backstage/core-plugin-api';
|
|
5
5
|
export { AlertApi, AlertMessage, AnyApiFactory, AnyApiRef, ApiFactory, ApiHolder, ApiRef, ApiRefConfig, AppTheme, AppThemeApi, AuthProviderInfo, AuthRequestOptions, BackstageIdentityApi, BackstageIdentityResponse, BackstageUserIdentity, ConfigApi, DiscoveryApi, ErrorApi, ErrorApiError, ErrorApiErrorContext, FeatureFlag, FeatureFlagState, FeatureFlagsApi, FeatureFlagsSaveOptions, FetchApi, IdentityApi, OAuthApi, OAuthRequestApi, OAuthRequester, OAuthRequesterOptions, OAuthScope, OpenIdConnectApi, PendingOAuthRequest, ProfileInfo, ProfileInfoApi, SessionApi, SessionState, StorageApi, StorageValueSnapshot, TypesToApiRefs, alertApiRef, appThemeApiRef, atlassianAuthApiRef, bitbucketAuthApiRef, bitbucketServerAuthApiRef, configApiRef, createApiFactory, createApiRef, discoveryApiRef, errorApiRef, featureFlagsApiRef, fetchApiRef, githubAuthApiRef, gitlabAuthApiRef, googleAuthApiRef, identityApiRef, microsoftAuthApiRef, oauthRequestApiRef, oktaAuthApiRef, oneloginAuthApiRef, storageApiRef, useApi, useApiHolder, vmwareCloudAuthApiRef, withApis } from '@backstage/core-plugin-api';
|
|
6
6
|
import { JsonObject } from '@backstage/types';
|
|
7
|
+
import { z, ZodSchema, ZodTypeDef } from 'zod';
|
|
7
8
|
import { TranslationResource, TranslationMessages } from '@backstage/core-plugin-api/alpha';
|
|
8
9
|
export { TranslationMessages, TranslationMessagesOptions, TranslationRef, TranslationRefOptions, TranslationResource, TranslationResourceOptions, createTranslationMessages, createTranslationRef, createTranslationResource, useTranslationRef } from '@backstage/core-plugin-api/alpha';
|
|
9
|
-
import { z, ZodSchema, ZodTypeDef } from 'zod';
|
|
10
10
|
|
|
11
11
|
/**
|
|
12
12
|
* Common analytics context attributes.
|
|
@@ -232,50 +232,66 @@ declare function useRouteRef<TParams extends AnyRouteRefParams>(routeRef: RouteR
|
|
|
232
232
|
*/
|
|
233
233
|
declare function useRouteRefParams<Params extends AnyRouteRefParams>(_routeRef: RouteRef<Params> | SubRouteRef<Params>): Params;
|
|
234
234
|
|
|
235
|
+
/** @public */
|
|
236
|
+
type ExtensionDataValue<TData, TId extends string> = {
|
|
237
|
+
readonly $$type: '@backstage/ExtensionDataValue';
|
|
238
|
+
readonly id: TId;
|
|
239
|
+
readonly value: TData;
|
|
240
|
+
};
|
|
235
241
|
/** @public */
|
|
236
242
|
type ExtensionDataRef<TData, TId extends string = string, TConfig extends {
|
|
237
243
|
optional?: true;
|
|
238
244
|
} = {}> = {
|
|
239
|
-
|
|
240
|
-
|
|
241
|
-
|
|
242
|
-
|
|
245
|
+
readonly $$type: '@backstage/ExtensionDataRef';
|
|
246
|
+
readonly id: TId;
|
|
247
|
+
readonly T: TData;
|
|
248
|
+
readonly config: TConfig;
|
|
243
249
|
};
|
|
244
250
|
/** @public */
|
|
245
|
-
|
|
251
|
+
type ExtensionDataRefToValue<TDataRef extends AnyExtensionDataRef> = TDataRef extends ExtensionDataRef<infer IData, infer IId, any> ? ExtensionDataValue<IData, IId> : never;
|
|
252
|
+
/** @public */
|
|
253
|
+
type AnyExtensionDataRef = ExtensionDataRef<unknown, string, {
|
|
254
|
+
optional?: true;
|
|
255
|
+
}>;
|
|
256
|
+
/** @public */
|
|
257
|
+
interface ConfigurableExtensionDataRef<TData, TId extends string, TConfig extends {
|
|
246
258
|
optional?: true;
|
|
247
259
|
} = {}> extends ExtensionDataRef<TData, TId, TConfig> {
|
|
248
|
-
optional(): ConfigurableExtensionDataRef<
|
|
260
|
+
optional(): ConfigurableExtensionDataRef<TData, TId, TData & {
|
|
249
261
|
optional: true;
|
|
250
262
|
}>;
|
|
263
|
+
(t: TData): ExtensionDataValue<TData, TId>;
|
|
251
264
|
}
|
|
252
265
|
/**
|
|
253
266
|
* @public
|
|
254
267
|
* @deprecated Use the following form instead: `createExtensionDataRef<Type>().with({ id: 'core.foo' })`
|
|
255
268
|
*/
|
|
256
|
-
declare function createExtensionDataRef<TData>(id: string): ConfigurableExtensionDataRef<
|
|
269
|
+
declare function createExtensionDataRef<TData>(id: string): ConfigurableExtensionDataRef<TData, string>;
|
|
257
270
|
/** @public */
|
|
258
271
|
declare function createExtensionDataRef<TData>(): {
|
|
259
272
|
with<TId extends string>(options: {
|
|
260
273
|
id: TId;
|
|
261
|
-
}): ConfigurableExtensionDataRef<
|
|
274
|
+
}): ConfigurableExtensionDataRef<TData, TId>;
|
|
262
275
|
};
|
|
263
276
|
|
|
264
277
|
/** @public */
|
|
265
278
|
declare const coreExtensionData: {
|
|
266
|
-
reactElement: ConfigurableExtensionDataRef<"core.reactElement",
|
|
267
|
-
routePath: ConfigurableExtensionDataRef<"core.routing.path",
|
|
268
|
-
routeRef: ConfigurableExtensionDataRef<"core.routing.ref",
|
|
279
|
+
reactElement: ConfigurableExtensionDataRef<JSX$1.Element, "core.reactElement", {}>;
|
|
280
|
+
routePath: ConfigurableExtensionDataRef<string, "core.routing.path", {}>;
|
|
281
|
+
routeRef: ConfigurableExtensionDataRef<RouteRef<AnyRouteRefParams>, "core.routing.ref", {}>;
|
|
269
282
|
};
|
|
270
283
|
|
|
271
284
|
/** @public */
|
|
272
|
-
type PortableSchema<TOutput> = {
|
|
273
|
-
parse: (input:
|
|
285
|
+
type PortableSchema<TOutput, TInput = TOutput> = {
|
|
286
|
+
parse: (input: TInput) => TOutput;
|
|
274
287
|
schema: JsonObject;
|
|
275
288
|
};
|
|
276
289
|
|
|
277
|
-
/**
|
|
278
|
-
|
|
290
|
+
/**
|
|
291
|
+
* @public
|
|
292
|
+
* @deprecated Use the `config.schema` option of `createExtension` instead, or use `createExtensionBlueprint`.
|
|
293
|
+
*/
|
|
294
|
+
declare function createSchemaFromZod<TOutput, TInput>(schemaCreator: (zImpl: typeof z) => ZodSchema<TOutput, ZodTypeDef, TInput>): PortableSchema<TOutput, TInput>;
|
|
279
295
|
|
|
280
296
|
/**
|
|
281
297
|
* Utility type to expand type aliases into their equivalent type.
|
|
@@ -298,32 +314,63 @@ type CoreErrorBoundaryFallbackProps = {
|
|
|
298
314
|
};
|
|
299
315
|
|
|
300
316
|
/** @public */
|
|
301
|
-
interface ExtensionInput<TExtensionData extends
|
|
317
|
+
interface ExtensionInput<TExtensionData extends ExtensionDataRef<unknown, string, {
|
|
318
|
+
optional?: true;
|
|
319
|
+
}>, TConfig extends {
|
|
302
320
|
singleton: boolean;
|
|
303
321
|
optional: boolean;
|
|
304
322
|
}> {
|
|
305
323
|
$$type: '@backstage/ExtensionInput';
|
|
306
|
-
extensionData: TExtensionData
|
|
324
|
+
extensionData: Array<TExtensionData>;
|
|
307
325
|
config: TConfig;
|
|
308
326
|
}
|
|
327
|
+
/**
|
|
328
|
+
* @public
|
|
329
|
+
* @deprecated This type will be removed. Use `ExtensionInput` instead.
|
|
330
|
+
*/
|
|
331
|
+
interface LegacyExtensionInput<TExtensionDataMap extends AnyExtensionDataMap, TConfig extends {
|
|
332
|
+
singleton: boolean;
|
|
333
|
+
optional: boolean;
|
|
334
|
+
}> {
|
|
335
|
+
$$type: '@backstage/ExtensionInput';
|
|
336
|
+
extensionData: TExtensionDataMap;
|
|
337
|
+
config: TConfig;
|
|
338
|
+
}
|
|
339
|
+
/**
|
|
340
|
+
* @public
|
|
341
|
+
* @deprecated Use the following form instead: `createExtensionInput([dataRef1, dataRef2])`
|
|
342
|
+
*/
|
|
343
|
+
declare function createExtensionInput<TExtensionDataMap extends AnyExtensionDataMap, TConfig extends {
|
|
344
|
+
singleton?: boolean;
|
|
345
|
+
optional?: boolean;
|
|
346
|
+
}>(extensionData: TExtensionDataMap, config?: TConfig): LegacyExtensionInput<TExtensionDataMap, {
|
|
347
|
+
singleton: TConfig['singleton'] extends true ? true : false;
|
|
348
|
+
optional: TConfig['optional'] extends true ? true : false;
|
|
349
|
+
}>;
|
|
309
350
|
/** @public */
|
|
310
|
-
declare function createExtensionInput<
|
|
351
|
+
declare function createExtensionInput<UExtensionData extends ExtensionDataRef<unknown, string, {
|
|
352
|
+
optional?: true;
|
|
353
|
+
}>, TConfig extends {
|
|
311
354
|
singleton?: boolean;
|
|
312
355
|
optional?: boolean;
|
|
313
|
-
}>(extensionData:
|
|
356
|
+
}>(extensionData: Array<UExtensionData>, config?: TConfig): ExtensionInput<UExtensionData, {
|
|
314
357
|
singleton: TConfig['singleton'] extends true ? true : false;
|
|
315
358
|
optional: TConfig['optional'] extends true ? true : false;
|
|
316
359
|
}>;
|
|
317
360
|
|
|
318
|
-
/**
|
|
361
|
+
/**
|
|
362
|
+
* @public
|
|
363
|
+
* @deprecated Extension data maps will be removed.
|
|
364
|
+
*/
|
|
319
365
|
type AnyExtensionDataMap = {
|
|
320
|
-
[name in string]:
|
|
321
|
-
optional?: true;
|
|
322
|
-
}>;
|
|
366
|
+
[name in string]: AnyExtensionDataRef;
|
|
323
367
|
};
|
|
324
|
-
/**
|
|
368
|
+
/**
|
|
369
|
+
* @public
|
|
370
|
+
* @deprecated This type will be removed.
|
|
371
|
+
*/
|
|
325
372
|
type AnyExtensionInputMap = {
|
|
326
|
-
[inputName in string]:
|
|
373
|
+
[inputName in string]: LegacyExtensionInput<AnyExtensionDataMap, {
|
|
327
374
|
optional: boolean;
|
|
328
375
|
singleton: boolean;
|
|
329
376
|
}>;
|
|
@@ -331,6 +378,7 @@ type AnyExtensionInputMap = {
|
|
|
331
378
|
/**
|
|
332
379
|
* Converts an extension data map into the matching concrete data values type.
|
|
333
380
|
* @public
|
|
381
|
+
* @deprecated Extension data maps will be removed.
|
|
334
382
|
*/
|
|
335
383
|
type ExtensionDataValues<TExtensionData extends AnyExtensionDataMap> = {
|
|
336
384
|
[DataName in keyof TExtensionData as TExtensionData[DataName]['config'] extends {
|
|
@@ -341,25 +389,36 @@ type ExtensionDataValues<TExtensionData extends AnyExtensionDataMap> = {
|
|
|
341
389
|
optional: true;
|
|
342
390
|
} ? DataName : never]?: TExtensionData[DataName]['T'];
|
|
343
391
|
};
|
|
392
|
+
/** @public */
|
|
393
|
+
type ExtensionDataContainer<UExtensionData extends AnyExtensionDataRef> = {
|
|
394
|
+
get<TId extends UExtensionData['id']>(ref: ExtensionDataRef<any, TId, any>): UExtensionData extends ExtensionDataRef<infer IData, TId, infer IConfig> ? IConfig['optional'] extends true ? IData | undefined : IData : never;
|
|
395
|
+
};
|
|
344
396
|
/**
|
|
345
397
|
* Convert a single extension input into a matching resolved input.
|
|
346
398
|
* @public
|
|
347
399
|
*/
|
|
348
|
-
type ResolvedExtensionInput<
|
|
400
|
+
type ResolvedExtensionInput<TExtensionInput extends ExtensionInput<any, any>> = TExtensionInput['extensionData'] extends Array<AnyExtensionDataRef> ? {
|
|
349
401
|
node: AppNode;
|
|
350
|
-
|
|
351
|
-
|
|
402
|
+
} & ExtensionDataContainer<TExtensionInput['extensionData'][number]> : TExtensionInput['extensionData'] extends AnyExtensionDataMap ? {
|
|
403
|
+
node: AppNode;
|
|
404
|
+
output: ExtensionDataValues<TExtensionInput['extensionData']>;
|
|
405
|
+
} : never;
|
|
352
406
|
/**
|
|
353
407
|
* Converts an extension input map into a matching collection of resolved inputs.
|
|
354
408
|
* @public
|
|
355
409
|
*/
|
|
356
410
|
type ResolvedExtensionInputs<TInputs extends {
|
|
357
|
-
[name in string]: ExtensionInput<any, any>;
|
|
411
|
+
[name in string]: ExtensionInput<any, any> | LegacyExtensionInput<any, any>;
|
|
358
412
|
}> = {
|
|
359
|
-
[InputName in keyof TInputs]: false extends TInputs[InputName]['config']['singleton'] ? Array<Expand<ResolvedExtensionInput<TInputs[InputName]
|
|
413
|
+
[InputName in keyof TInputs]: false extends TInputs[InputName]['config']['singleton'] ? Array<Expand<ResolvedExtensionInput<TInputs[InputName]>>> : false extends TInputs[InputName]['config']['optional'] ? Expand<ResolvedExtensionInput<TInputs[InputName]>> : Expand<ResolvedExtensionInput<TInputs[InputName]> | undefined>;
|
|
360
414
|
};
|
|
361
|
-
/**
|
|
362
|
-
|
|
415
|
+
/**
|
|
416
|
+
* @public
|
|
417
|
+
* @deprecated This way of structuring the options is deprecated, this type will be removed in the future
|
|
418
|
+
*/
|
|
419
|
+
interface LegacyCreateExtensionOptions<TOutput extends AnyExtensionDataMap, TInputs extends AnyExtensionInputMap, TConfig, TConfigInput, TConfigSchema extends {
|
|
420
|
+
[key: string]: (zImpl: typeof z) => z.ZodType;
|
|
421
|
+
}> {
|
|
363
422
|
kind?: string;
|
|
364
423
|
namespace?: string;
|
|
365
424
|
name?: string;
|
|
@@ -370,15 +429,57 @@ interface CreateExtensionOptions<TOutput extends AnyExtensionDataMap, TInputs ex
|
|
|
370
429
|
disabled?: boolean;
|
|
371
430
|
inputs?: TInputs;
|
|
372
431
|
output: TOutput;
|
|
373
|
-
|
|
432
|
+
/** @deprecated - use `config.schema` instead */
|
|
433
|
+
configSchema?: PortableSchema<TConfig, TConfigInput>;
|
|
434
|
+
config?: {
|
|
435
|
+
schema: TConfigSchema;
|
|
436
|
+
};
|
|
374
437
|
factory(context: {
|
|
375
438
|
node: AppNode;
|
|
376
|
-
config: TConfig
|
|
439
|
+
config: TConfig & (string extends keyof TConfigSchema ? {} : {
|
|
440
|
+
[key in keyof TConfigSchema]: z.infer<ReturnType<TConfigSchema[key]>>;
|
|
441
|
+
});
|
|
377
442
|
inputs: Expand<ResolvedExtensionInputs<TInputs>>;
|
|
378
443
|
}): Expand<ExtensionDataValues<TOutput>>;
|
|
379
444
|
}
|
|
445
|
+
/** @ignore */
|
|
446
|
+
type VerifyExtensionFactoryOutput<UDeclaredOutput extends AnyExtensionDataRef, UFactoryOutput extends ExtensionDataValue<any, any>> = (UDeclaredOutput extends any ? UDeclaredOutput['config']['optional'] extends true ? never : UDeclaredOutput['id'] : never) extends infer IRequiredOutputIds ? [IRequiredOutputIds] extends [UFactoryOutput['id']] ? {} : {
|
|
447
|
+
'Error: The extension factory is missing the following outputs': Exclude<IRequiredOutputIds, UFactoryOutput['id']>;
|
|
448
|
+
} : never;
|
|
449
|
+
/** @public */
|
|
450
|
+
type CreateExtensionOptions<UOutput extends AnyExtensionDataRef, TInputs extends {
|
|
451
|
+
[inputName in string]: ExtensionInput<AnyExtensionDataRef, {
|
|
452
|
+
optional: boolean;
|
|
453
|
+
singleton: boolean;
|
|
454
|
+
}>;
|
|
455
|
+
}, TConfig, TConfigInput, TConfigSchema extends {
|
|
456
|
+
[key: string]: (zImpl: typeof z) => z.ZodType;
|
|
457
|
+
}, UFactoryOutput extends ExtensionDataValue<any, any>> = {
|
|
458
|
+
kind?: string;
|
|
459
|
+
namespace?: string;
|
|
460
|
+
name?: string;
|
|
461
|
+
attachTo: {
|
|
462
|
+
id: string;
|
|
463
|
+
input: string;
|
|
464
|
+
};
|
|
465
|
+
disabled?: boolean;
|
|
466
|
+
inputs?: TInputs;
|
|
467
|
+
output: Array<UOutput>;
|
|
468
|
+
/** @deprecated - use `config.schema` instead */
|
|
469
|
+
configSchema?: PortableSchema<TConfig, TConfigInput>;
|
|
470
|
+
config?: {
|
|
471
|
+
schema: TConfigSchema;
|
|
472
|
+
};
|
|
473
|
+
factory(context: {
|
|
474
|
+
node: AppNode;
|
|
475
|
+
config: TConfig & (string extends keyof TConfigSchema ? {} : {
|
|
476
|
+
[key in keyof TConfigSchema]: z.infer<ReturnType<TConfigSchema[key]>>;
|
|
477
|
+
});
|
|
478
|
+
inputs: Expand<ResolvedExtensionInputs<TInputs>>;
|
|
479
|
+
}): Iterable<UFactoryOutput>;
|
|
480
|
+
} & VerifyExtensionFactoryOutput<UOutput, UFactoryOutput>;
|
|
380
481
|
/** @public */
|
|
381
|
-
interface ExtensionDefinition<TConfig> {
|
|
482
|
+
interface ExtensionDefinition<TConfig, TConfigInput = TConfig> {
|
|
382
483
|
$$type: '@backstage/ExtensionDefinition';
|
|
383
484
|
readonly kind?: string;
|
|
384
485
|
readonly namespace?: string;
|
|
@@ -388,13 +489,35 @@ interface ExtensionDefinition<TConfig> {
|
|
|
388
489
|
input: string;
|
|
389
490
|
};
|
|
390
491
|
readonly disabled: boolean;
|
|
391
|
-
readonly configSchema?: PortableSchema<TConfig>;
|
|
492
|
+
readonly configSchema?: PortableSchema<TConfig, TConfigInput>;
|
|
392
493
|
}
|
|
393
494
|
/** @public */
|
|
394
|
-
declare function createExtension<
|
|
495
|
+
declare function createExtension<UOutput extends AnyExtensionDataRef, TInputs extends {
|
|
496
|
+
[inputName in string]: ExtensionInput<AnyExtensionDataRef, {
|
|
497
|
+
optional: boolean;
|
|
498
|
+
singleton: boolean;
|
|
499
|
+
}>;
|
|
500
|
+
}, TConfig, TConfigInput, TConfigSchema extends {
|
|
501
|
+
[key: string]: (zImpl: typeof z) => z.ZodType;
|
|
502
|
+
}, UFactoryOutput extends ExtensionDataValue<any, any>>(options: CreateExtensionOptions<UOutput, TInputs, TConfig, TConfigInput, TConfigSchema, UFactoryOutput>): ExtensionDefinition<TConfig & (string extends keyof TConfigSchema ? {} : {
|
|
503
|
+
[key in keyof TConfigSchema]: z.infer<ReturnType<TConfigSchema[key]>>;
|
|
504
|
+
}), TConfigInput & (string extends keyof TConfigSchema ? {} : z.input<z.ZodObject<{
|
|
505
|
+
[key in keyof TConfigSchema]: ReturnType<TConfigSchema[key]>;
|
|
506
|
+
}>>)>;
|
|
507
|
+
/**
|
|
508
|
+
* @public
|
|
509
|
+
* @deprecated - use the array format of `output` instead, see TODO-doc-link
|
|
510
|
+
*/
|
|
511
|
+
declare function createExtension<TOutput extends AnyExtensionDataMap, TInputs extends AnyExtensionInputMap, TConfig, TConfigInput, TConfigSchema extends {
|
|
512
|
+
[key: string]: (zImpl: typeof z) => z.ZodType;
|
|
513
|
+
}>(options: LegacyCreateExtensionOptions<TOutput, TInputs, TConfig, TConfigInput, TConfigSchema>): ExtensionDefinition<TConfig & (string extends keyof TConfigSchema ? {} : {
|
|
514
|
+
[key in keyof TConfigSchema]: z.infer<ReturnType<TConfigSchema[key]>>;
|
|
515
|
+
}), TConfigInput & (string extends keyof TConfigSchema ? {} : z.input<z.ZodObject<{
|
|
516
|
+
[key in keyof TConfigSchema]: ReturnType<TConfigSchema[key]>;
|
|
517
|
+
}>>)>;
|
|
395
518
|
|
|
396
519
|
/** @public */
|
|
397
|
-
interface Extension<TConfig> {
|
|
520
|
+
interface Extension<TConfig, TConfigInput = TConfig> {
|
|
398
521
|
$$type: '@backstage/Extension';
|
|
399
522
|
readonly id: string;
|
|
400
523
|
readonly attachTo: {
|
|
@@ -402,7 +525,7 @@ interface Extension<TConfig> {
|
|
|
402
525
|
input: string;
|
|
403
526
|
};
|
|
404
527
|
readonly disabled: boolean;
|
|
405
|
-
readonly configSchema?: PortableSchema<TConfig>;
|
|
528
|
+
readonly configSchema?: PortableSchema<TConfig, TConfigInput>;
|
|
406
529
|
}
|
|
407
530
|
|
|
408
531
|
/**
|
|
@@ -441,7 +564,7 @@ interface PluginOptions<Routes extends AnyRoutes, ExternalRoutes extends AnyExte
|
|
|
441
564
|
id: string;
|
|
442
565
|
routes?: Routes;
|
|
443
566
|
externalRoutes?: ExternalRoutes;
|
|
444
|
-
extensions?: ExtensionDefinition<
|
|
567
|
+
extensions?: ExtensionDefinition<any, any>[];
|
|
445
568
|
featureFlags?: FeatureFlagConfig[];
|
|
446
569
|
}
|
|
447
570
|
/** @public */
|
|
@@ -449,7 +572,7 @@ declare function createPlugin<Routes extends AnyRoutes = {}, ExternalRoutes exte
|
|
|
449
572
|
|
|
450
573
|
/** @public */
|
|
451
574
|
interface ExtensionOverridesOptions {
|
|
452
|
-
extensions: ExtensionDefinition<
|
|
575
|
+
extensions: ExtensionDefinition<any, any>[];
|
|
453
576
|
featureFlags?: FeatureFlagConfig[];
|
|
454
577
|
}
|
|
455
578
|
/** @public */
|
|
@@ -458,7 +581,16 @@ declare function createExtensionOverrides(options: ExtensionOverridesOptions): E
|
|
|
458
581
|
/**
|
|
459
582
|
* @public
|
|
460
583
|
*/
|
|
461
|
-
|
|
584
|
+
type CreateExtensionBlueprintOptions<TParams, UOutput extends AnyExtensionDataRef, TInputs extends {
|
|
585
|
+
[inputName in string]: ExtensionInput<AnyExtensionDataRef, {
|
|
586
|
+
optional: boolean;
|
|
587
|
+
singleton: boolean;
|
|
588
|
+
}>;
|
|
589
|
+
}, TConfigSchema extends {
|
|
590
|
+
[key in string]: (zImpl: typeof z) => z.ZodType;
|
|
591
|
+
}, UFactoryOutput extends ExtensionDataValue<any, any>, TDataRefs extends {
|
|
592
|
+
[name in string]: AnyExtensionDataRef;
|
|
593
|
+
}> = {
|
|
462
594
|
kind: string;
|
|
463
595
|
namespace?: string;
|
|
464
596
|
attachTo: {
|
|
@@ -467,19 +599,34 @@ interface CreateExtensionBlueprintOptions<TParams, TInputs extends AnyExtensionI
|
|
|
467
599
|
};
|
|
468
600
|
disabled?: boolean;
|
|
469
601
|
inputs?: TInputs;
|
|
470
|
-
output:
|
|
471
|
-
|
|
602
|
+
output: Array<UOutput>;
|
|
603
|
+
config?: {
|
|
604
|
+
schema: TConfigSchema;
|
|
605
|
+
};
|
|
472
606
|
factory(params: TParams, context: {
|
|
473
607
|
node: AppNode;
|
|
474
|
-
config:
|
|
608
|
+
config: {
|
|
609
|
+
[key in keyof TConfigSchema]: z.infer<ReturnType<TConfigSchema[key]>>;
|
|
610
|
+
};
|
|
475
611
|
inputs: Expand<ResolvedExtensionInputs<TInputs>>;
|
|
476
|
-
}):
|
|
612
|
+
}): Iterable<UFactoryOutput>;
|
|
477
613
|
dataRefs?: TDataRefs;
|
|
478
|
-
}
|
|
614
|
+
} & VerifyExtensionFactoryOutput<UOutput, UFactoryOutput>;
|
|
479
615
|
/**
|
|
480
616
|
* @public
|
|
481
617
|
*/
|
|
482
|
-
interface ExtensionBlueprint<TParams,
|
|
618
|
+
interface ExtensionBlueprint<TParams, UOutput extends AnyExtensionDataRef, TInputs extends {
|
|
619
|
+
[inputName in string]: ExtensionInput<AnyExtensionDataRef, {
|
|
620
|
+
optional: boolean;
|
|
621
|
+
singleton: boolean;
|
|
622
|
+
}>;
|
|
623
|
+
}, UExtraOutput extends AnyExtensionDataRef, TConfig extends {
|
|
624
|
+
[key in string]: unknown;
|
|
625
|
+
}, TConfigInput extends {
|
|
626
|
+
[key in string]: unknown;
|
|
627
|
+
}, TDataRefs extends {
|
|
628
|
+
[name in string]: AnyExtensionDataRef;
|
|
629
|
+
}> {
|
|
483
630
|
dataRefs: TDataRefs;
|
|
484
631
|
/**
|
|
485
632
|
* Creates a new extension from the blueprint.
|
|
@@ -487,7 +634,9 @@ interface ExtensionBlueprint<TParams, TInputs extends AnyExtensionInputMap, TOut
|
|
|
487
634
|
* You must either pass `params` directly, or define a `factory` that can
|
|
488
635
|
* optionally call the original factory with the same params.
|
|
489
636
|
*/
|
|
490
|
-
make
|
|
637
|
+
make<TExtensionConfigSchema extends {
|
|
638
|
+
[key in string]: (zImpl: typeof z) => z.ZodType;
|
|
639
|
+
}, UFactoryOutput extends ExtensionDataValue<any, any>>(args: {
|
|
491
640
|
namespace?: string;
|
|
492
641
|
name?: string;
|
|
493
642
|
attachTo?: {
|
|
@@ -496,20 +645,30 @@ interface ExtensionBlueprint<TParams, TInputs extends AnyExtensionInputMap, TOut
|
|
|
496
645
|
};
|
|
497
646
|
disabled?: boolean;
|
|
498
647
|
inputs?: TInputs;
|
|
499
|
-
output?:
|
|
500
|
-
|
|
501
|
-
|
|
648
|
+
output?: Array<UExtraOutput>;
|
|
649
|
+
config?: {
|
|
650
|
+
schema: TExtensionConfigSchema & {
|
|
651
|
+
[KName in keyof TConfig]?: `Error: Config key '${KName & string}' is already defined in parent schema`;
|
|
652
|
+
};
|
|
653
|
+
};
|
|
654
|
+
} & (({
|
|
502
655
|
factory(originalFactory: (params: TParams, context?: {
|
|
503
656
|
config?: TConfig;
|
|
504
657
|
inputs?: Expand<ResolvedExtensionInputs<TInputs>>;
|
|
505
|
-
}) =>
|
|
658
|
+
}) => Iterable<ExtensionDataRefToValue<UOutput>>, context: {
|
|
506
659
|
node: AppNode;
|
|
507
|
-
config: TConfig
|
|
660
|
+
config: TConfig & {
|
|
661
|
+
[key in keyof TExtensionConfigSchema]: z.infer<ReturnType<TExtensionConfigSchema[key]>>;
|
|
662
|
+
};
|
|
508
663
|
inputs: Expand<ResolvedExtensionInputs<TInputs>>;
|
|
509
|
-
}):
|
|
510
|
-
} | {
|
|
664
|
+
}): Iterable<UFactoryOutput>;
|
|
665
|
+
} & VerifyExtensionFactoryOutput<UOutput & UExtraOutput, UFactoryOutput>) | {
|
|
511
666
|
params: TParams;
|
|
512
|
-
})): ExtensionDefinition<
|
|
667
|
+
})): ExtensionDefinition<{
|
|
668
|
+
[key in keyof TExtensionConfigSchema]: z.infer<ReturnType<TExtensionConfigSchema[key]>>;
|
|
669
|
+
} & TConfig, z.input<z.ZodObject<{
|
|
670
|
+
[key in keyof TExtensionConfigSchema]: ReturnType<TExtensionConfigSchema[key]>;
|
|
671
|
+
}>> & TConfigInput>;
|
|
513
672
|
}
|
|
514
673
|
/**
|
|
515
674
|
* A simpler replacement for wrapping up `createExtension` inside a kind or type. This allows for a cleaner API for creating
|
|
@@ -517,7 +676,20 @@ interface ExtensionBlueprint<TParams, TInputs extends AnyExtensionInputMap, TOut
|
|
|
517
676
|
*
|
|
518
677
|
* @public
|
|
519
678
|
*/
|
|
520
|
-
declare function createExtensionBlueprint<TParams,
|
|
679
|
+
declare function createExtensionBlueprint<TParams, UOutput extends AnyExtensionDataRef, TInputs extends {
|
|
680
|
+
[inputName in string]: ExtensionInput<AnyExtensionDataRef, {
|
|
681
|
+
optional: boolean;
|
|
682
|
+
singleton: boolean;
|
|
683
|
+
}>;
|
|
684
|
+
}, UExtraOutput extends AnyExtensionDataRef, TConfigSchema extends {
|
|
685
|
+
[key in string]: (zImpl: typeof z) => z.ZodType;
|
|
686
|
+
}, UFactoryOutput extends ExtensionDataValue<any, any>, TDataRefs extends {
|
|
687
|
+
[name in string]: AnyExtensionDataRef;
|
|
688
|
+
} = never>(options: CreateExtensionBlueprintOptions<TParams, UOutput, TInputs, TConfigSchema, UFactoryOutput, TDataRefs>): ExtensionBlueprint<TParams, UOutput, TInputs, UExtraOutput, string extends keyof TConfigSchema ? {} : {
|
|
689
|
+
[key in keyof TConfigSchema]: z.infer<ReturnType<TConfigSchema[key]>>;
|
|
690
|
+
}, string extends keyof TConfigSchema ? {} : z.input<z.ZodObject<{
|
|
691
|
+
[key in keyof TConfigSchema]: ReturnType<TConfigSchema[key]>;
|
|
692
|
+
}>>, TDataRefs>;
|
|
521
693
|
|
|
522
694
|
/**
|
|
523
695
|
* The specification for this {@link AppNode} in the {@link AppTree}.
|
|
@@ -534,7 +706,7 @@ interface AppNodeSpec {
|
|
|
534
706
|
id: string;
|
|
535
707
|
input: string;
|
|
536
708
|
};
|
|
537
|
-
readonly extension: Extension<unknown>;
|
|
709
|
+
readonly extension: Extension<unknown, unknown>;
|
|
538
710
|
readonly disabled: boolean;
|
|
539
711
|
readonly config?: unknown;
|
|
540
712
|
readonly source?: BackstagePlugin;
|
|
@@ -861,10 +1033,10 @@ declare function createApiExtension<TConfig extends {}, TInputs extends AnyExten
|
|
|
861
1033
|
}) & {
|
|
862
1034
|
configSchema?: PortableSchema<TConfig>;
|
|
863
1035
|
inputs?: TInputs;
|
|
864
|
-
}): ExtensionDefinition<TConfig>;
|
|
1036
|
+
}): ExtensionDefinition<TConfig & {}, TConfig & {}>;
|
|
865
1037
|
/** @public */
|
|
866
1038
|
declare namespace createApiExtension {
|
|
867
|
-
const factoryDataRef: ConfigurableExtensionDataRef<"core.api.factory",
|
|
1039
|
+
const factoryDataRef: ConfigurableExtensionDataRef<AnyApiFactory, "core.api.factory", {}>;
|
|
868
1040
|
}
|
|
869
1041
|
|
|
870
1042
|
/**
|
|
@@ -913,9 +1085,9 @@ declare function createAppRootWrapperExtension<TConfig extends {}, TInputs exten
|
|
|
913
1085
|
}): ExtensionDefinition<TConfig>;
|
|
914
1086
|
/** @public */
|
|
915
1087
|
declare namespace createAppRootWrapperExtension {
|
|
916
|
-
const componentDataRef: ConfigurableExtensionDataRef<
|
|
1088
|
+
const componentDataRef: ConfigurableExtensionDataRef<React.ComponentType<{
|
|
917
1089
|
children?: React.ReactNode;
|
|
918
|
-
}>, {}>;
|
|
1090
|
+
}>, "app.root.wrapper", {}>;
|
|
919
1091
|
}
|
|
920
1092
|
|
|
921
1093
|
/**
|
|
@@ -942,9 +1114,9 @@ declare function createRouterExtension<TConfig extends {}, TInputs extends AnyEx
|
|
|
942
1114
|
}): ExtensionDefinition<TConfig>;
|
|
943
1115
|
/** @public */
|
|
944
1116
|
declare namespace createRouterExtension {
|
|
945
|
-
const componentDataRef: ConfigurableExtensionDataRef<
|
|
1117
|
+
const componentDataRef: ConfigurableExtensionDataRef<React.ComponentType<{
|
|
946
1118
|
children?: React.ReactNode;
|
|
947
|
-
}>, {}>;
|
|
1119
|
+
}>, "app.router.wrapper", {}>;
|
|
948
1120
|
}
|
|
949
1121
|
|
|
950
1122
|
/**
|
|
@@ -986,14 +1158,16 @@ declare function createNavItemExtension(options: {
|
|
|
986
1158
|
icon: IconComponent$1;
|
|
987
1159
|
}): ExtensionDefinition<{
|
|
988
1160
|
title: string;
|
|
1161
|
+
}, {
|
|
1162
|
+
title?: string | undefined;
|
|
989
1163
|
}>;
|
|
990
1164
|
/** @public */
|
|
991
1165
|
declare namespace createNavItemExtension {
|
|
992
|
-
const targetDataRef: ConfigurableExtensionDataRef<
|
|
1166
|
+
const targetDataRef: ConfigurableExtensionDataRef<{
|
|
993
1167
|
title: string;
|
|
994
1168
|
icon: IconComponent$1;
|
|
995
1169
|
routeRef: RouteRef<undefined>;
|
|
996
|
-
}, {}>;
|
|
1170
|
+
}, "core.nav-item.target", {}>;
|
|
997
1171
|
}
|
|
998
1172
|
|
|
999
1173
|
/**
|
|
@@ -1005,13 +1179,13 @@ declare function createNavLogoExtension(options: {
|
|
|
1005
1179
|
namespace?: string;
|
|
1006
1180
|
logoIcon: JSX.Element;
|
|
1007
1181
|
logoFull: JSX.Element;
|
|
1008
|
-
}): ExtensionDefinition<
|
|
1182
|
+
}): ExtensionDefinition<{}, {}>;
|
|
1009
1183
|
/** @public */
|
|
1010
1184
|
declare namespace createNavLogoExtension {
|
|
1011
|
-
const logoElementsDataRef: ConfigurableExtensionDataRef<
|
|
1185
|
+
const logoElementsDataRef: ConfigurableExtensionDataRef<{
|
|
1012
1186
|
logoIcon?: JSX.Element | undefined;
|
|
1013
1187
|
logoFull?: JSX.Element | undefined;
|
|
1014
|
-
}, {}>;
|
|
1188
|
+
}, "core.nav-logo.logo-elements", {}>;
|
|
1015
1189
|
}
|
|
1016
1190
|
|
|
1017
1191
|
/**
|
|
@@ -1035,14 +1209,14 @@ declare function createSignInPageExtension<TConfig extends {}, TInputs extends A
|
|
|
1035
1209
|
}): ExtensionDefinition<TConfig>;
|
|
1036
1210
|
/** @public */
|
|
1037
1211
|
declare namespace createSignInPageExtension {
|
|
1038
|
-
const componentDataRef: ConfigurableExtensionDataRef<"core.sign-in-page.component",
|
|
1212
|
+
const componentDataRef: ConfigurableExtensionDataRef<React.ComponentType<SignInPageProps>, "core.sign-in-page.component", {}>;
|
|
1039
1213
|
}
|
|
1040
1214
|
|
|
1041
1215
|
/** @public */
|
|
1042
|
-
declare function createThemeExtension(theme: AppTheme): ExtensionDefinition<
|
|
1216
|
+
declare function createThemeExtension(theme: AppTheme): ExtensionDefinition<{}, {}>;
|
|
1043
1217
|
/** @public */
|
|
1044
1218
|
declare namespace createThemeExtension {
|
|
1045
|
-
const themeDataRef: ConfigurableExtensionDataRef<"core.theme.theme",
|
|
1219
|
+
const themeDataRef: ConfigurableExtensionDataRef<AppTheme, "core.theme.theme", {}>;
|
|
1046
1220
|
}
|
|
1047
1221
|
|
|
1048
1222
|
/** @public */
|
|
@@ -1063,25 +1237,25 @@ declare function createComponentExtension<TProps extends {}, TConfig extends {},
|
|
|
1063
1237
|
inputs: Expand<ResolvedExtensionInputs<TInputs>>;
|
|
1064
1238
|
}) => ComponentType<TProps>;
|
|
1065
1239
|
};
|
|
1066
|
-
}): ExtensionDefinition<TConfig>;
|
|
1240
|
+
}): ExtensionDefinition<TConfig & {}, TConfig & {}>;
|
|
1067
1241
|
/** @public */
|
|
1068
1242
|
declare namespace createComponentExtension {
|
|
1069
|
-
const componentDataRef: ConfigurableExtensionDataRef<
|
|
1243
|
+
const componentDataRef: ConfigurableExtensionDataRef<{
|
|
1070
1244
|
ref: ComponentRef;
|
|
1071
1245
|
impl: ComponentType;
|
|
1072
|
-
}, {}>;
|
|
1246
|
+
}, "core.component.component", {}>;
|
|
1073
1247
|
}
|
|
1074
1248
|
|
|
1075
1249
|
/** @public */
|
|
1076
1250
|
declare function createTranslationExtension(options: {
|
|
1077
1251
|
name?: string;
|
|
1078
1252
|
resource: TranslationResource | TranslationMessages;
|
|
1079
|
-
}): ExtensionDefinition<
|
|
1253
|
+
}): ExtensionDefinition<{}, {}>;
|
|
1080
1254
|
/** @public */
|
|
1081
1255
|
declare namespace createTranslationExtension {
|
|
1082
|
-
const translationDataRef: ConfigurableExtensionDataRef<
|
|
1256
|
+
const translationDataRef: ConfigurableExtensionDataRef<TranslationResource<string> | TranslationMessages<string, {
|
|
1083
1257
|
[x: string]: string;
|
|
1084
|
-
}, boolean>, {}>;
|
|
1258
|
+
}, boolean>, "core.translation.translation", {}>;
|
|
1085
1259
|
}
|
|
1086
1260
|
|
|
1087
1261
|
/** @public */
|
|
@@ -1089,14 +1263,23 @@ declare const IconBundleBlueprint: ExtensionBlueprint<{
|
|
|
1089
1263
|
icons: {
|
|
1090
1264
|
[x: string]: IconComponent;
|
|
1091
1265
|
};
|
|
1092
|
-
},
|
|
1093
|
-
|
|
1094
|
-
|
|
1095
|
-
|
|
1096
|
-
|
|
1097
|
-
|
|
1266
|
+
}, ConfigurableExtensionDataRef<{
|
|
1267
|
+
[x: string]: IconComponent;
|
|
1268
|
+
}, "core.icons", {}>, {
|
|
1269
|
+
[x: string]: ExtensionInput<AnyExtensionDataRef, {
|
|
1270
|
+
optional: boolean;
|
|
1271
|
+
singleton: boolean;
|
|
1272
|
+
}>;
|
|
1273
|
+
}, AnyExtensionDataRef, {
|
|
1274
|
+
icons: string;
|
|
1275
|
+
test: string;
|
|
1276
|
+
}, {
|
|
1277
|
+
test: string;
|
|
1278
|
+
icons?: string | undefined;
|
|
1279
|
+
}, {
|
|
1280
|
+
icons: ConfigurableExtensionDataRef<{
|
|
1098
1281
|
[x: string]: IconComponent;
|
|
1099
|
-
}, {}>;
|
|
1282
|
+
}, "core.icons", {}>;
|
|
1100
1283
|
}>;
|
|
1101
1284
|
|
|
1102
|
-
export { type AnalyticsApi, AnalyticsContext, type AnalyticsContextValue, type AnalyticsEvent, type AnalyticsEventAttributes, type AnalyticsTracker, type AnyExtensionDataMap, type AnyExtensionInputMap, type AnyExternalRoutes, type AnyRouteRefParams, type AnyRoutes, type AppNode, type AppNodeEdges, type AppNodeInstance, type AppNodeSpec, type AppTree, type AppTreeApi, type BackstagePlugin, type CommonAnalyticsContext, type ComponentRef, type ComponentsApi, type ConfigurableExtensionDataRef, type CoreErrorBoundaryFallbackProps, type CoreNotFoundErrorPageProps, type CoreProgressProps, type CreateExtensionBlueprintOptions, type CreateExtensionOptions, type Extension, type ExtensionBlueprint, ExtensionBoundary, type ExtensionBoundaryProps, type ExtensionDataRef, type ExtensionDataValues, type ExtensionDefinition, type ExtensionInput, type ExtensionOverrides, type ExtensionOverridesOptions, type ExternalRouteRef, type FeatureFlagConfig, type FrontendFeature, IconBundleBlueprint, type IconComponent, type IconsApi, type PluginOptions, type PortableSchema, type ResolvedExtensionInput, type ResolvedExtensionInputs, type RouteFunc, type RouteRef, type RouteResolutionApi, type RouteResolutionApiResolveOptions, type SubRouteRef, analyticsApiRef, appTreeApiRef, componentsApiRef, coreComponentRefs, coreExtensionData, createApiExtension, createAppRootElementExtension, createAppRootWrapperExtension, createComponentExtension, createComponentRef, createExtension, createExtensionBlueprint, createExtensionDataRef, createExtensionInput, createExtensionOverrides, createExternalRouteRef, createNavItemExtension, createNavLogoExtension, createPageExtension, createPlugin, createRouteRef, createRouterExtension, createSchemaFromZod, createSignInPageExtension, createSubRouteRef, createThemeExtension, createTranslationExtension, iconsApiRef, routeResolutionApiRef, useAnalytics, useComponentRef, useRouteRef, useRouteRefParams };
|
|
1285
|
+
export { type AnalyticsApi, AnalyticsContext, type AnalyticsContextValue, type AnalyticsEvent, type AnalyticsEventAttributes, type AnalyticsTracker, type AnyExtensionDataMap, type AnyExtensionDataRef, type AnyExtensionInputMap, type AnyExternalRoutes, type AnyRouteRefParams, type AnyRoutes, type AppNode, type AppNodeEdges, type AppNodeInstance, type AppNodeSpec, type AppTree, type AppTreeApi, type BackstagePlugin, type CommonAnalyticsContext, type ComponentRef, type ComponentsApi, type ConfigurableExtensionDataRef, type CoreErrorBoundaryFallbackProps, type CoreNotFoundErrorPageProps, type CoreProgressProps, type CreateExtensionBlueprintOptions, type CreateExtensionOptions, type Extension, type ExtensionBlueprint, ExtensionBoundary, type ExtensionBoundaryProps, type ExtensionDataContainer, type ExtensionDataRef, type ExtensionDataRefToValue, type ExtensionDataValue, type ExtensionDataValues, type ExtensionDefinition, type ExtensionInput, type ExtensionOverrides, type ExtensionOverridesOptions, type ExternalRouteRef, type FeatureFlagConfig, type FrontendFeature, IconBundleBlueprint, type IconComponent, type IconsApi, type LegacyCreateExtensionOptions, type LegacyExtensionInput, type PluginOptions, type PortableSchema, type ResolvedExtensionInput, type ResolvedExtensionInputs, type RouteFunc, type RouteRef, type RouteResolutionApi, type RouteResolutionApiResolveOptions, type SubRouteRef, analyticsApiRef, appTreeApiRef, componentsApiRef, coreComponentRefs, coreExtensionData, createApiExtension, createAppRootElementExtension, createAppRootWrapperExtension, createComponentExtension, createComponentRef, createExtension, createExtensionBlueprint, createExtensionDataRef, createExtensionInput, createExtensionOverrides, createExternalRouteRef, createNavItemExtension, createNavLogoExtension, createPageExtension, createPlugin, createRouteRef, createRouterExtension, createSchemaFromZod, createSignInPageExtension, createSubRouteRef, createThemeExtension, createTranslationExtension, iconsApiRef, routeResolutionApiRef, useAnalytics, useComponentRef, useRouteRef, useRouteRefParams };
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"createSchemaFromZod.esm.js","sources":["../../src/schema/createSchemaFromZod.ts"],"sourcesContent":["/*\n * Copyright 2023 The Backstage Authors\n *\n * Licensed under the Apache License, Version 2.0 (the \"License\");\n * you may not use this file except in compliance with the License.\n * You may obtain a copy of the License at\n *\n * http://www.apache.org/licenses/LICENSE-2.0\n *\n * Unless required by applicable law or agreed to in writing, software\n * distributed under the License is distributed on an \"AS IS\" BASIS,\n * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.\n * See the License for the specific language governing permissions and\n * limitations under the License.\n */\n\nimport { JsonObject } from '@backstage/types';\nimport { z, ZodSchema, ZodTypeDef } from 'zod';\nimport zodToJsonSchema from 'zod-to-json-schema';\nimport { PortableSchema } from './types';\n\n
|
|
1
|
+
{"version":3,"file":"createSchemaFromZod.esm.js","sources":["../../src/schema/createSchemaFromZod.ts"],"sourcesContent":["/*\n * Copyright 2023 The Backstage Authors\n *\n * Licensed under the Apache License, Version 2.0 (the \"License\");\n * you may not use this file except in compliance with the License.\n * You may obtain a copy of the License at\n *\n * http://www.apache.org/licenses/LICENSE-2.0\n *\n * Unless required by applicable law or agreed to in writing, software\n * distributed under the License is distributed on an \"AS IS\" BASIS,\n * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.\n * See the License for the specific language governing permissions and\n * limitations under the License.\n */\n\nimport { JsonObject } from '@backstage/types';\nimport { z, ZodSchema, ZodTypeDef } from 'zod';\nimport zodToJsonSchema from 'zod-to-json-schema';\nimport { PortableSchema } from './types';\n\n/**\n * @public\n * @deprecated Use the `config.schema` option of `createExtension` instead, or use `createExtensionBlueprint`.\n */\nexport function createSchemaFromZod<TOutput, TInput>(\n schemaCreator: (zImpl: typeof z) => ZodSchema<TOutput, ZodTypeDef, TInput>,\n): PortableSchema<TOutput, TInput> {\n const schema = schemaCreator(z);\n return {\n // TODO: Types allow z.array etc here but it will break stuff\n parse: input => {\n const result = schema.safeParse(input);\n if (result.success) {\n return result.data;\n }\n\n throw new Error(result.error.issues.map(formatIssue).join('; '));\n },\n // TODO: Verify why we are not compatible with the latest zodToJsonSchema.\n schema: zodToJsonSchema(schema) as JsonObject,\n };\n}\n\nfunction formatIssue(issue: z.ZodIssue): string {\n if (issue.code === 'invalid_union') {\n return formatIssue(issue.unionErrors[0].issues[0]);\n }\n let message = issue.message;\n if (message === 'Required') {\n message = `Missing required value`;\n }\n if (issue.path.length) {\n message += ` at '${issue.path.join('.')}'`;\n }\n return message;\n}\n"],"names":[],"mappings":";;;AAyBO,SAAS,oBACd,aACiC,EAAA;AACjC,EAAM,MAAA,MAAA,GAAS,cAAc,CAAC,CAAA,CAAA;AAC9B,EAAO,OAAA;AAAA;AAAA,IAEL,OAAO,CAAS,KAAA,KAAA;AACd,MAAM,MAAA,MAAA,GAAS,MAAO,CAAA,SAAA,CAAU,KAAK,CAAA,CAAA;AACrC,MAAA,IAAI,OAAO,OAAS,EAAA;AAClB,QAAA,OAAO,MAAO,CAAA,IAAA,CAAA;AAAA,OAChB;AAEA,MAAM,MAAA,IAAI,KAAM,CAAA,MAAA,CAAO,KAAM,CAAA,MAAA,CAAO,IAAI,WAAW,CAAA,CAAE,IAAK,CAAA,IAAI,CAAC,CAAA,CAAA;AAAA,KACjE;AAAA;AAAA,IAEA,MAAA,EAAQ,gBAAgB,MAAM,CAAA;AAAA,GAChC,CAAA;AACF,CAAA;AAEA,SAAS,YAAY,KAA2B,EAAA;AAC9C,EAAI,IAAA,KAAA,CAAM,SAAS,eAAiB,EAAA;AAClC,IAAA,OAAO,YAAY,KAAM,CAAA,WAAA,CAAY,CAAC,CAAE,CAAA,MAAA,CAAO,CAAC,CAAC,CAAA,CAAA;AAAA,GACnD;AACA,EAAA,IAAI,UAAU,KAAM,CAAA,OAAA,CAAA;AACpB,EAAA,IAAI,YAAY,UAAY,EAAA;AAC1B,IAAU,OAAA,GAAA,CAAA,sBAAA,CAAA,CAAA;AAAA,GACZ;AACA,EAAI,IAAA,KAAA,CAAM,KAAK,MAAQ,EAAA;AACrB,IAAA,OAAA,IAAW,CAAQ,KAAA,EAAA,KAAA,CAAM,IAAK,CAAA,IAAA,CAAK,GAAG,CAAC,CAAA,CAAA,CAAA,CAAA;AAAA,GACzC;AACA,EAAO,OAAA,OAAA,CAAA;AACT;;;;"}
|