@backstage/frontend-plugin-api 0.17.3 → 0.18.0
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 +16 -0
- package/dist/alpha.d.ts +1 -2
- package/dist/alpha.esm.js +0 -2
- package/dist/alpha.esm.js.map +1 -1
- package/dist/blueprints/AnalyticsImplementationBlueprint.esm.js +0 -2
- package/dist/blueprints/AnalyticsImplementationBlueprint.esm.js.map +1 -1
- package/dist/blueprints/ApiBlueprint.esm.js +0 -2
- package/dist/blueprints/ApiBlueprint.esm.js.map +1 -1
- package/dist/blueprints/AppRootElementBlueprint.esm.js +0 -2
- package/dist/blueprints/AppRootElementBlueprint.esm.js.map +1 -1
- package/dist/blueprints/PageBlueprint.esm.js +3 -5
- package/dist/blueprints/PageBlueprint.esm.js.map +1 -1
- package/dist/blueprints/PluginHeaderActionBlueprint.esm.js +0 -2
- package/dist/blueprints/PluginHeaderActionBlueprint.esm.js.map +1 -1
- package/dist/blueprints/PluginWrapperBlueprint.esm.js +0 -2
- package/dist/blueprints/PluginWrapperBlueprint.esm.js.map +1 -1
- package/dist/blueprints/SubPageBlueprint.esm.js +3 -5
- package/dist/blueprints/SubPageBlueprint.esm.js.map +1 -1
- package/dist/components/ExtensionBoundary.esm.js +0 -2
- package/dist/components/ExtensionBoundary.esm.js.map +1 -1
- package/dist/index.d.ts +2 -3
- package/dist/routing/SubRouteRef.esm.js +10 -8
- package/dist/routing/SubRouteRef.esm.js.map +1 -1
- package/dist/schema/assertNoLegacyConfigSchema.esm.js +10 -0
- package/dist/schema/assertNoLegacyConfigSchema.esm.js.map +1 -0
- package/dist/schema/createPortableSchema.esm.js +5 -70
- package/dist/schema/createPortableSchema.esm.js.map +1 -1
- package/dist/schema/optionalStringSchema.esm.js +33 -0
- package/dist/schema/optionalStringSchema.esm.js.map +1 -0
- package/dist/types/{alpha.d-BScvftwR.d.ts → alpha.d-gY8B1WFX.d.ts} +3 -194
- package/dist/wiring/createExtension.esm.js +5 -18
- package/dist/wiring/createExtension.esm.js.map +1 -1
- package/dist/wiring/createExtensionBlueprint.esm.js +3 -12
- package/dist/wiring/createExtensionBlueprint.esm.js.map +1 -1
- package/package.json +8 -9
|
@@ -1,13 +1,3 @@
|
|
|
1
|
-
import { z } from 'zod/v3';
|
|
2
|
-
import zodToJsonSchema from 'zod-to-json-schema';
|
|
3
|
-
|
|
4
|
-
function createDeprecatedConfigSchema(fields) {
|
|
5
|
-
const resolved = {};
|
|
6
|
-
for (const [key, field] of Object.entries(fields)) {
|
|
7
|
-
resolved[key] = resolveZodField(key, field(z));
|
|
8
|
-
}
|
|
9
|
-
return buildPortableSchema(resolved);
|
|
10
|
-
}
|
|
11
1
|
function createConfigSchema(fields) {
|
|
12
2
|
const resolved = {};
|
|
13
3
|
for (const [key, field] of Object.entries(fields)) {
|
|
@@ -15,21 +5,6 @@ function createConfigSchema(fields) {
|
|
|
15
5
|
}
|
|
16
6
|
return buildPortableSchema(resolved);
|
|
17
7
|
}
|
|
18
|
-
function mergePortableSchemas(a, b) {
|
|
19
|
-
if (!a && !b) {
|
|
20
|
-
return void 0;
|
|
21
|
-
}
|
|
22
|
-
if (!a) {
|
|
23
|
-
return b;
|
|
24
|
-
}
|
|
25
|
-
if (!b) {
|
|
26
|
-
return a;
|
|
27
|
-
}
|
|
28
|
-
return buildPortableSchema({
|
|
29
|
-
...a._fields,
|
|
30
|
-
...b._fields
|
|
31
|
-
});
|
|
32
|
-
}
|
|
33
8
|
function buildPortableSchema(fields) {
|
|
34
9
|
function parse(input) {
|
|
35
10
|
if (input !== void 0 && input !== null && (typeof input !== "object" || Array.isArray(input))) {
|
|
@@ -38,23 +13,23 @@ function buildPortableSchema(fields) {
|
|
|
38
13
|
);
|
|
39
14
|
}
|
|
40
15
|
const inputObj = input ?? {};
|
|
41
|
-
const
|
|
16
|
+
const result = {};
|
|
42
17
|
const errors = [];
|
|
43
18
|
for (const [key, field] of Object.entries(fields)) {
|
|
44
19
|
const validated = field.validate(inputObj[key]);
|
|
45
20
|
if ("errors" in validated) {
|
|
46
21
|
errors.push(...validated.errors);
|
|
47
22
|
} else if (validated.value !== void 0 || key in inputObj) {
|
|
48
|
-
|
|
23
|
+
result[key] = validated.value;
|
|
49
24
|
}
|
|
50
25
|
}
|
|
51
26
|
if (errors.length > 0) {
|
|
52
27
|
throw new Error(errors.join("; "));
|
|
53
28
|
}
|
|
54
|
-
return
|
|
29
|
+
return result;
|
|
55
30
|
}
|
|
56
31
|
let cached;
|
|
57
|
-
|
|
32
|
+
return {
|
|
58
33
|
parse,
|
|
59
34
|
schema() {
|
|
60
35
|
if (!cached) {
|
|
@@ -63,11 +38,6 @@ function buildPortableSchema(fields) {
|
|
|
63
38
|
return cached;
|
|
64
39
|
}
|
|
65
40
|
};
|
|
66
|
-
Object.defineProperty(result, "_fields", {
|
|
67
|
-
value: fields,
|
|
68
|
-
enumerable: false
|
|
69
|
-
});
|
|
70
|
-
return result;
|
|
71
41
|
}
|
|
72
42
|
function resolveField(key, schema) {
|
|
73
43
|
if (isZodV3Type(schema)) {
|
|
@@ -87,23 +57,6 @@ function resolveField(key, schema) {
|
|
|
87
57
|
`Config schema for field '${key}' is not a valid Standard Schema`
|
|
88
58
|
);
|
|
89
59
|
}
|
|
90
|
-
function resolveZodField(key, schema) {
|
|
91
|
-
const wrapper = z.object({ [key]: schema });
|
|
92
|
-
return {
|
|
93
|
-
validate(value) {
|
|
94
|
-
const result = wrapper.safeParse({ [key]: value });
|
|
95
|
-
if (result.success) {
|
|
96
|
-
return { value: result.data[key] };
|
|
97
|
-
}
|
|
98
|
-
return { errors: result.error.issues.map(formatZodIssue) };
|
|
99
|
-
},
|
|
100
|
-
toJsonSchema() {
|
|
101
|
-
const wholeJsonSchema = zodToJsonSchema(wrapper);
|
|
102
|
-
return wholeJsonSchema.properties?.[key] ?? {};
|
|
103
|
-
},
|
|
104
|
-
required: !schema.isOptional()
|
|
105
|
-
};
|
|
106
|
-
}
|
|
107
60
|
function resolveStandardField(key, schema) {
|
|
108
61
|
const required = isFieldRequired(schema);
|
|
109
62
|
return {
|
|
@@ -167,19 +120,6 @@ function isFieldRequired(schema) {
|
|
|
167
120
|
}
|
|
168
121
|
return (result.issues?.length ?? 0) > 0;
|
|
169
122
|
}
|
|
170
|
-
function formatZodIssue(issue) {
|
|
171
|
-
if (issue.code === "invalid_union" && issue.unionErrors?.[0]?.issues?.[0]) {
|
|
172
|
-
return formatZodIssue(issue.unionErrors[0].issues[0]);
|
|
173
|
-
}
|
|
174
|
-
let message = issue.message;
|
|
175
|
-
if (message === "Required") {
|
|
176
|
-
message = "Missing required value";
|
|
177
|
-
}
|
|
178
|
-
if (issue.path.length) {
|
|
179
|
-
message += ` at '${issue.path.join(".")}'`;
|
|
180
|
-
}
|
|
181
|
-
return message;
|
|
182
|
-
}
|
|
183
123
|
function formatStandardIssue(fieldKey, issue) {
|
|
184
124
|
let message = issue.message;
|
|
185
125
|
if (message === "Required") {
|
|
@@ -190,11 +130,6 @@ function formatStandardIssue(fieldKey, issue) {
|
|
|
190
130
|
).join(".")}` : fieldKey;
|
|
191
131
|
return `${message} at '${path}'`;
|
|
192
132
|
}
|
|
193
|
-
function warnConfigSchemaPropDeprecation(callSite) {
|
|
194
|
-
console.warn(
|
|
195
|
-
`DEPRECATION WARNING: The \`config.schema\` option for extension config is deprecated. Use the \`configSchema\` option instead with Standard Schema values, for example \`configSchema: { title: z.string() }\` using the \`zod\` v4 package (\`zod@^4.0.0\`). Declared at ${callSite}`
|
|
196
|
-
);
|
|
197
|
-
}
|
|
198
133
|
|
|
199
|
-
export { createConfigSchema
|
|
134
|
+
export { createConfigSchema };
|
|
200
135
|
//# sourceMappingURL=createPortableSchema.esm.js.map
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"createPortableSchema.esm.js","sources":["../../src/schema/createPortableSchema.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 as zodV3, type ZodType } from 'zod/v3';\nimport zodToJsonSchema from 'zod-to-json-schema';\nimport { PortableSchema } from './types';\n\n/**\n * The Standard Schema interface.\n * @public\n */\nexport type { StandardSchemaV1 } from '@standard-schema/spec';\nimport { type StandardSchemaV1 } from '@standard-schema/spec';\n\n/** @internal */\nexport function createDeprecatedConfigSchema(\n fields: Record<string, (zImpl: typeof zodV3) => ZodType>,\n): MergeablePortableSchema {\n const resolved: Record<string, ResolvedField> = {};\n\n for (const [key, field] of Object.entries(fields)) {\n resolved[key] = resolveZodField(key, field(zodV3));\n }\n\n return buildPortableSchema(resolved);\n}\n\n/**\n * Per-field resolved schema — validation is eager, JSON Schema is lazy.\n * @internal\n */\ninterface ResolvedField {\n validate(value: unknown): { value: unknown } | { errors: string[] };\n toJsonSchema(): JsonObject;\n required: boolean;\n}\n\n/**\n * Internal representation that carries per-field resolvers alongside the\n * public PortableSchema surface, enabling schema merging.\n * @internal\n */\nexport interface MergeablePortableSchema<TOutput = any, TInput = any>\n extends PortableSchema<TOutput, TInput> {\n /** @internal */\n readonly _fields: Record<string, ResolvedField>;\n}\n\n/**\n * Resolves each field, eagerly validates JSON Schema support, and returns\n * a PortableSchema whose JSON Schema conversion is lazy.\n * @internal\n */\nexport function createConfigSchema(\n fields: Record<string, StandardSchemaV1>,\n): MergeablePortableSchema {\n const resolved: Record<string, ResolvedField> = {};\n\n for (const [key, field] of Object.entries(fields)) {\n resolved[key] = resolveField(key, field);\n }\n\n return buildPortableSchema(resolved);\n}\n\n/**\n * Combines schemas from different sources for blueprint + override\n * composition. Each source may use a completely different schema library.\n * Because we track per-field resolvers, merging is just combining the\n * field maps.\n * @internal\n */\nexport function mergePortableSchemas<A, B>(\n a: MergeablePortableSchema<A> | undefined,\n b: MergeablePortableSchema<B> | undefined,\n): MergeablePortableSchema<A & B> | undefined {\n if (!a && !b) {\n return undefined;\n }\n if (!a) {\n return b as MergeablePortableSchema<A & B>;\n }\n if (!b) {\n return a as MergeablePortableSchema<A & B>;\n }\n\n return buildPortableSchema<A & B>({\n ...a._fields,\n ...b._fields,\n });\n}\n\n/**\n * Assembles resolved fields into a PortableSchema with per-field\n * validation (eager) and lazy JSON Schema generation.\n */\nfunction buildPortableSchema<TOutput = unknown>(\n fields: Record<string, ResolvedField>,\n): MergeablePortableSchema<TOutput> {\n function parse(input: unknown) {\n if (\n input !== undefined &&\n input !== null &&\n (typeof input !== 'object' || Array.isArray(input))\n ) {\n throw new Error(\n `Invalid config input, expected object but got ${\n Array.isArray(input) ? 'array' : typeof input\n }`,\n );\n }\n const inputObj = (input ?? {}) as Record<string, unknown>;\n const result: Record<string, unknown> = {};\n const errors: string[] = [];\n\n for (const [key, field] of Object.entries(fields)) {\n const validated = field.validate(inputObj[key]);\n if ('errors' in validated) {\n errors.push(...validated.errors);\n } else if (validated.value !== undefined || key in inputObj) {\n result[key] = validated.value;\n }\n }\n\n if (errors.length > 0) {\n throw new Error(errors.join('; '));\n }\n\n return result as TOutput;\n }\n\n let cached: { schema: JsonObject } | undefined;\n\n const result: MergeablePortableSchema<TOutput> = {\n parse,\n schema() {\n if (!cached) {\n cached = { schema: buildObjectJsonSchema(fields) };\n }\n return cached;\n },\n } as MergeablePortableSchema<TOutput>;\n\n Object.defineProperty(result, '_fields', {\n value: fields,\n enumerable: false,\n });\n\n return result;\n}\n\n/**\n * Wraps a single schema into a ResolvedField. Eagerly validates that\n * JSON Schema conversion will be possible, but defers the actual\n * conversion until toJsonSchema() is called.\n */\nfunction resolveField(key: string, schema: unknown): ResolvedField {\n if (isZodV3Type(schema)) {\n throw new Error(\n `Config schema for field '${key}' uses a Zod v3 schema, which is ` +\n `not supported by the \\`configSchema\\` option. Upgrade to the ` +\n `\\`zod\\` v4 package (\\`zod@^4.0.0\\`). Note that the \\`zod/v4\\` ` +\n `subpath export from the zod v3 package is also not supported, ` +\n `as it does not include JSON Schema conversion.`,\n );\n }\n if (isStandardSchema(schema)) {\n if (!hasJsonSchemaConverter(schema)) {\n throw new Error(\n `Config schema for field '${key}' does not support JSON Schema ` +\n `conversion. Use a schema library that implements the Standard ` +\n `JSON Schema interface (like zod v4+).`,\n );\n }\n return resolveStandardField(key, schema);\n }\n throw new Error(\n `Config schema for field '${key}' is not a valid Standard Schema`,\n );\n}\n\nfunction resolveZodField(key: string, schema: ZodType): ResolvedField {\n const wrapper = zodV3.object({ [key]: schema });\n\n return {\n validate(value) {\n const result = wrapper.safeParse({ [key]: value });\n if (result.success) {\n return { value: result.data[key] };\n }\n return { errors: result.error.issues.map(formatZodIssue) };\n },\n toJsonSchema() {\n const wholeJsonSchema = zodToJsonSchema(wrapper) as Record<string, any>;\n return (wholeJsonSchema.properties?.[key] ?? {}) as JsonObject;\n },\n required: !schema.isOptional(),\n };\n}\n\nfunction resolveStandardField(\n key: string,\n schema: StandardSchemaV1 & {\n '~standard': { jsonSchema: { input: Function } };\n },\n): ResolvedField {\n const required = isFieldRequired(schema);\n\n return {\n validate(value) {\n const result = schema['~standard'].validate(value);\n if (result instanceof Promise) {\n throw new Error(\n `Config schema for '${key}' returned a Promise — async schemas are not supported`,\n );\n }\n if (result.issues) {\n return {\n errors: Array.from(result.issues).map(issue =>\n formatStandardIssue(key, issue),\n ),\n };\n }\n return { value: result.value };\n },\n toJsonSchema() {\n const raw = schema['~standard'].jsonSchema.input({ target: 'draft-07' });\n const { $schema: _, ...rest } = raw;\n return rest as JsonObject;\n },\n required,\n };\n}\n\n/** Assembles per-field JSON Schemas into a single object-level JSON Schema. */\nfunction buildObjectJsonSchema(\n fields: Record<string, ResolvedField>,\n): JsonObject {\n const properties: Record<string, JsonObject> = {};\n const required: string[] = [];\n\n for (const [key, field] of Object.entries(fields)) {\n properties[key] = field.toJsonSchema();\n if (field.required) {\n required.push(key);\n }\n }\n\n const schema: Record<string, unknown> = {\n type: 'object',\n properties,\n additionalProperties: false,\n };\n\n if (required.length > 0) {\n schema.required = required;\n }\n\n return schema as JsonObject;\n}\n\nfunction isZodV3Type(value: unknown): value is ZodType {\n return (\n typeof value === 'object' &&\n value !== null &&\n typeof (value as any)._parse === 'function' &&\n '_def' in value\n );\n}\n\nfunction isStandardSchema(value: unknown): value is StandardSchemaV1 {\n return (\n typeof value === 'object' &&\n value !== null &&\n '~standard' in value &&\n typeof (value as any)['~standard']?.validate === 'function'\n );\n}\n\nfunction hasJsonSchemaConverter(\n schema: StandardSchemaV1,\n): schema is StandardSchemaV1 & {\n '~standard': { jsonSchema: { input: Function } };\n} {\n const std = schema['~standard'] as any;\n return typeof std?.jsonSchema?.input === 'function';\n}\n\nfunction isFieldRequired(schema: StandardSchemaV1): boolean {\n const result = schema['~standard'].validate(undefined);\n if (result instanceof Promise) {\n return true;\n }\n return (result.issues?.length ?? 0) > 0;\n}\n\nfunction formatZodIssue(issue: {\n code: string;\n message: string;\n path: Array<string | number>;\n unionErrors?: Array<{ issues: Array<any> }>;\n}): string {\n if (issue.code === 'invalid_union' && issue.unionErrors?.[0]?.issues?.[0]) {\n return formatZodIssue(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\nfunction formatStandardIssue(\n fieldKey: string,\n issue: StandardSchemaV1.Issue,\n): string {\n let message = issue.message;\n if (message === 'Required') {\n message = 'Missing required value';\n }\n const path = issue.path?.length\n ? `${fieldKey}.${issue.path\n .map((p: PropertyKey | StandardSchemaV1.PathSegment) =>\n typeof p === 'object' ? p.key : p,\n )\n .join('.')}`\n : fieldKey;\n return `${message} at '${path}'`;\n}\n\n/** @internal */\nexport function warnConfigSchemaPropDeprecation(callSite: string) {\n // eslint-disable-next-line no-console\n console.warn(\n `DEPRECATION WARNING: The \\`config.schema\\` option for extension config is deprecated. ` +\n `Use the \\`configSchema\\` option instead with Standard Schema values, for example ` +\n `\\`configSchema: { title: z.string() }\\` using the \\`zod\\` v4 package ` +\n `(\\`zod@^4.0.0\\`). Declared at ${callSite}`,\n );\n}\n"],"names":["zodV3","result"],"mappings":";;;AA6BO,SAAS,6BACd,MAAA,EACyB;AACzB,EAAA,MAAM,WAA0C,EAAC;AAEjD,EAAA,KAAA,MAAW,CAAC,GAAA,EAAK,KAAK,KAAK,MAAA,CAAO,OAAA,CAAQ,MAAM,CAAA,EAAG;AACjD,IAAA,QAAA,CAAS,GAAG,CAAA,GAAI,eAAA,CAAgB,GAAA,EAAK,KAAA,CAAMA,CAAK,CAAC,CAAA;AAAA,EACnD;AAEA,EAAA,OAAO,oBAAoB,QAAQ,CAAA;AACrC;AA4BO,SAAS,mBACd,MAAA,EACyB;AACzB,EAAA,MAAM,WAA0C,EAAC;AAEjD,EAAA,KAAA,MAAW,CAAC,GAAA,EAAK,KAAK,KAAK,MAAA,CAAO,OAAA,CAAQ,MAAM,CAAA,EAAG;AACjD,IAAA,QAAA,CAAS,GAAG,CAAA,GAAI,YAAA,CAAa,GAAA,EAAK,KAAK,CAAA;AAAA,EACzC;AAEA,EAAA,OAAO,oBAAoB,QAAQ,CAAA;AACrC;AASO,SAAS,oBAAA,CACd,GACA,CAAA,EAC4C;AAC5C,EAAA,IAAI,CAAC,CAAA,IAAK,CAAC,CAAA,EAAG;AACZ,IAAA,OAAO,MAAA;AAAA,EACT;AACA,EAAA,IAAI,CAAC,CAAA,EAAG;AACN,IAAA,OAAO,CAAA;AAAA,EACT;AACA,EAAA,IAAI,CAAC,CAAA,EAAG;AACN,IAAA,OAAO,CAAA;AAAA,EACT;AAEA,EAAA,OAAO,mBAAA,CAA2B;AAAA,IAChC,GAAG,CAAA,CAAE,OAAA;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,IAAI,CAAA,CAAA,CAAA;AAC/B;AAGO,SAAS,gCAAgC,QAAA,EAAkB;AAEhE,EAAA,OAAA,CAAQ,IAAA;AAAA,IACN,6QAGmC,QAAQ,CAAA;AAAA,GAC7C;AACF;;;;"}
|
|
1
|
+
{"version":3,"file":"createPortableSchema.esm.js","sources":["../../src/schema/createPortableSchema.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 { PortableSchema } from './types';\n\n/**\n * The Standard Schema interface.\n * @public\n */\nexport type { StandardSchemaV1 } from '@standard-schema/spec';\nimport { type StandardSchemaV1 } from '@standard-schema/spec';\n\n/**\n * Per-field resolved schema — validation is eager, JSON Schema is lazy.\n * @internal\n */\ninterface ResolvedField {\n validate(value: unknown): { value: unknown } | { errors: string[] };\n toJsonSchema(): JsonObject;\n required: boolean;\n}\n\n/**\n * Resolves each field, eagerly validates JSON Schema support, and returns\n * a PortableSchema whose JSON Schema conversion is lazy.\n * @internal\n */\nexport function createConfigSchema(\n fields: Record<string, StandardSchemaV1>,\n): PortableSchema {\n const resolved: Record<string, ResolvedField> = {};\n\n for (const [key, field] of Object.entries(fields)) {\n resolved[key] = resolveField(key, field);\n }\n\n return buildPortableSchema(resolved);\n}\n\n/**\n * Assembles resolved fields into a PortableSchema with per-field\n * validation (eager) and lazy JSON Schema generation.\n */\nfunction buildPortableSchema<TOutput = unknown>(\n fields: Record<string, ResolvedField>,\n): PortableSchema<TOutput> {\n function parse(input: unknown) {\n if (\n input !== undefined &&\n input !== null &&\n (typeof input !== 'object' || Array.isArray(input))\n ) {\n throw new Error(\n `Invalid config input, expected object but got ${\n Array.isArray(input) ? 'array' : typeof input\n }`,\n );\n }\n const inputObj = (input ?? {}) as Record<string, unknown>;\n const result: Record<string, unknown> = {};\n const errors: string[] = [];\n\n for (const [key, field] of Object.entries(fields)) {\n const validated = field.validate(inputObj[key]);\n if ('errors' in validated) {\n errors.push(...validated.errors);\n } else if (validated.value !== undefined || key in inputObj) {\n result[key] = validated.value;\n }\n }\n\n if (errors.length > 0) {\n throw new Error(errors.join('; '));\n }\n\n return result as TOutput;\n }\n\n let cached: { schema: JsonObject } | undefined;\n\n return {\n parse,\n schema() {\n if (!cached) {\n cached = { schema: buildObjectJsonSchema(fields) };\n }\n return cached;\n },\n };\n}\n\n/**\n * Wraps a single schema into a ResolvedField. Eagerly validates that\n * JSON Schema conversion will be possible, but defers the actual\n * conversion until toJsonSchema() is called.\n */\nfunction resolveField(key: string, schema: unknown): ResolvedField {\n if (isZodV3Type(schema)) {\n throw new Error(\n `Config schema for field '${key}' uses a Zod v3 schema, which is ` +\n `not supported by the \\`configSchema\\` option. Upgrade to the ` +\n `\\`zod\\` v4 package (\\`zod@^4.0.0\\`). Note that the \\`zod/v4\\` ` +\n `subpath export from the zod v3 package is also not supported, ` +\n `as it does not include JSON Schema conversion.`,\n );\n }\n if (isStandardSchema(schema)) {\n if (!hasJsonSchemaConverter(schema)) {\n throw new Error(\n `Config schema for field '${key}' does not support JSON Schema ` +\n `conversion. Use a schema library that implements the Standard ` +\n `JSON Schema interface (like zod v4+).`,\n );\n }\n return resolveStandardField(key, schema);\n }\n throw new Error(\n `Config schema for field '${key}' is not a valid Standard Schema`,\n );\n}\n\nfunction resolveStandardField(\n key: string,\n schema: StandardSchemaV1 & {\n '~standard': { jsonSchema: { input: Function } };\n },\n): ResolvedField {\n const required = isFieldRequired(schema);\n\n return {\n validate(value) {\n const result = schema['~standard'].validate(value);\n if (result instanceof Promise) {\n throw new Error(\n `Config schema for '${key}' returned a Promise — async schemas are not supported`,\n );\n }\n if (result.issues) {\n return {\n errors: Array.from(result.issues).map(issue =>\n formatStandardIssue(key, issue),\n ),\n };\n }\n return { value: result.value };\n },\n toJsonSchema() {\n const raw = schema['~standard'].jsonSchema.input({ target: 'draft-07' });\n const { $schema: _, ...rest } = raw;\n return rest as JsonObject;\n },\n required,\n };\n}\n\n/** Assembles per-field JSON Schemas into a single object-level JSON Schema. */\nfunction buildObjectJsonSchema(\n fields: Record<string, ResolvedField>,\n): JsonObject {\n const properties: Record<string, JsonObject> = {};\n const required: string[] = [];\n\n for (const [key, field] of Object.entries(fields)) {\n properties[key] = field.toJsonSchema();\n if (field.required) {\n required.push(key);\n }\n }\n\n const schema: Record<string, unknown> = {\n type: 'object',\n properties,\n additionalProperties: false,\n };\n\n if (required.length > 0) {\n schema.required = required;\n }\n\n return schema as JsonObject;\n}\n\nfunction isZodV3Type(value: unknown): boolean {\n return (\n typeof value === 'object' &&\n value !== null &&\n typeof (value as any)._parse === 'function' &&\n '_def' in value\n );\n}\n\nfunction isStandardSchema(value: unknown): value is StandardSchemaV1 {\n return (\n typeof value === 'object' &&\n value !== null &&\n '~standard' in value &&\n typeof (value as any)['~standard']?.validate === 'function'\n );\n}\n\nfunction hasJsonSchemaConverter(\n schema: StandardSchemaV1,\n): schema is StandardSchemaV1 & {\n '~standard': { jsonSchema: { input: Function } };\n} {\n const std = schema['~standard'] as any;\n return typeof std?.jsonSchema?.input === 'function';\n}\n\nfunction isFieldRequired(schema: StandardSchemaV1): boolean {\n const result = schema['~standard'].validate(undefined);\n if (result instanceof Promise) {\n return true;\n }\n return (result.issues?.length ?? 0) > 0;\n}\n\nfunction formatStandardIssue(\n fieldKey: string,\n issue: StandardSchemaV1.Issue,\n): string {\n let message = issue.message;\n if (message === 'Required') {\n message = 'Missing required value';\n }\n const path = issue.path?.length\n ? `${fieldKey}.${issue.path\n .map((p: PropertyKey | StandardSchemaV1.PathSegment) =>\n typeof p === 'object' ? p.key : p,\n )\n .join('.')}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ACJ,EAAA,OAAO,CAAA,EAAG,OAAO,CAAA,KAAA,EAAQ,IAAI,CAAA,CAAA,CAAA;AAC/B;;;;"}
|
|
@@ -0,0 +1,33 @@
|
|
|
1
|
+
const optionalStringSchema = {
|
|
2
|
+
"~standard": {
|
|
3
|
+
version: 1,
|
|
4
|
+
vendor: "backstage",
|
|
5
|
+
validate(value) {
|
|
6
|
+
if (typeof value === "string" || value === void 0) {
|
|
7
|
+
return { value };
|
|
8
|
+
}
|
|
9
|
+
let receivedType = typeof value;
|
|
10
|
+
if (value === null) {
|
|
11
|
+
receivedType = "null";
|
|
12
|
+
} else if (Array.isArray(value)) {
|
|
13
|
+
receivedType = "array";
|
|
14
|
+
}
|
|
15
|
+
return {
|
|
16
|
+
issues: [
|
|
17
|
+
{ message: `Expected a string, but received ${receivedType}` }
|
|
18
|
+
]
|
|
19
|
+
};
|
|
20
|
+
},
|
|
21
|
+
jsonSchema: {
|
|
22
|
+
input() {
|
|
23
|
+
return { type: "string" };
|
|
24
|
+
},
|
|
25
|
+
output() {
|
|
26
|
+
return { type: "string" };
|
|
27
|
+
}
|
|
28
|
+
}
|
|
29
|
+
}
|
|
30
|
+
};
|
|
31
|
+
|
|
32
|
+
export { optionalStringSchema };
|
|
33
|
+
//# sourceMappingURL=optionalStringSchema.esm.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"optionalStringSchema.esm.js","sources":["../../src/schema/optionalStringSchema.ts"],"sourcesContent":["/*\n * Copyright 2026 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 type {\n StandardJSONSchemaV1,\n StandardSchemaV1,\n} from '@standard-schema/spec';\n\nexport const optionalStringSchema: StandardSchemaV1<string | undefined> &\n StandardJSONSchemaV1<string | undefined> = {\n '~standard': {\n version: 1,\n vendor: 'backstage',\n validate(value) {\n if (typeof value === 'string' || value === undefined) {\n return { value };\n }\n let receivedType: string = typeof value;\n if (value === null) {\n receivedType = 'null';\n } else if (Array.isArray(value)) {\n receivedType = 'array';\n }\n return {\n issues: [\n { message: `Expected a string, but received ${receivedType}` },\n ],\n };\n },\n jsonSchema: {\n input() {\n return { type: 'string' };\n },\n output() {\n return { type: 'string' };\n },\n },\n },\n};\n"],"names":[],"mappings":"AAqBO,MAAM,oBAAA,GACgC;AAAA,EAC3C,WAAA,EAAa;AAAA,IACX,OAAA,EAAS,CAAA;AAAA,IACT,MAAA,EAAQ,WAAA;AAAA,IACR,SAAS,KAAA,EAAO;AACd,MAAA,IAAI,OAAO,KAAA,KAAU,QAAA,IAAY,KAAA,KAAU,MAAA,EAAW;AACpD,QAAA,OAAO,EAAE,KAAA,EAAM;AAAA,MACjB;AACA,MAAA,IAAI,eAAuB,OAAO,KAAA;AAClC,MAAA,IAAI,UAAU,IAAA,EAAM;AAClB,QAAA,YAAA,GAAe,MAAA;AAAA,MACjB,CAAA,MAAA,IAAW,KAAA,CAAM,OAAA,CAAQ,KAAK,CAAA,EAAG;AAC/B,QAAA,YAAA,GAAe,OAAA;AAAA,MACjB;AACA,MAAA,OAAO;AAAA,QACL,MAAA,EAAQ;AAAA,UACN,EAAE,OAAA,EAAS,CAAA,gCAAA,EAAmC,YAAY,CAAA,CAAA;AAAG;AAC/D,OACF;AAAA,IACF,CAAA;AAAA,IACA,UAAA,EAAY;AAAA,MACV,KAAA,GAAQ;AACN,QAAA,OAAO,EAAE,MAAM,QAAA,EAAS;AAAA,MAC1B,CAAA;AAAA,MACA,MAAA,GAAS;AACP,QAAA,OAAO,EAAE,MAAM,QAAA,EAAS;AAAA,MAC1B;AAAA;AACF;AAEJ;;;;"}
|
|
@@ -2,7 +2,6 @@ import * as _backstage_frontend_plugin_api from '@backstage/frontend-plugin-api'
|
|
|
2
2
|
import { JSX, ComponentType, ReactNode } from 'react';
|
|
3
3
|
import { Expand, JsonObject } from '@backstage/types';
|
|
4
4
|
import { FilterPredicate } from '@backstage/filter-predicates';
|
|
5
|
-
import { z } from 'zod/v3';
|
|
6
5
|
import { StandardSchemaV1 } from '@standard-schema/spec';
|
|
7
6
|
|
|
8
7
|
/**
|
|
@@ -345,7 +344,7 @@ type ExtensionArrayToMap<T extends ExtensionDefinition[], TId extends string, TO
|
|
|
345
344
|
type MakeSortedExtensionsMap<UExtensions extends ExtensionDefinition, TId extends string> = ExtensionArrayToMap<SortExtensions<UnionToArray<UExtensions>>, TId>;
|
|
346
345
|
|
|
347
346
|
/**
|
|
348
|
-
* Descriptor of a route relative to
|
|
347
|
+
* Descriptor of a route relative to a {@link RouteRef} or another sub-route.
|
|
349
348
|
*
|
|
350
349
|
* @remarks
|
|
351
350
|
*
|
|
@@ -407,7 +406,7 @@ type MakeSubRouteRef<Params extends {
|
|
|
407
406
|
*/
|
|
408
407
|
declare function createSubRouteRef<Path extends string, ParentParams extends AnyRouteRefParams = never>(config: {
|
|
409
408
|
path: Path;
|
|
410
|
-
parent: RouteRef<ParentParams>;
|
|
409
|
+
parent: RouteRef<ParentParams> | SubRouteRef<ParentParams>;
|
|
411
410
|
}): MakeSubRouteRef<PathParams<Path>, ParentParams>;
|
|
412
411
|
|
|
413
412
|
/**
|
|
@@ -733,8 +732,6 @@ declare function createExtensionBlueprintParams<T extends object = object>(param
|
|
|
733
732
|
*/
|
|
734
733
|
type CreateExtensionBlueprintOptions<TKind extends string, TParams extends object | ExtensionBlueprintDefineParams, UOutput extends ExtensionDataRef, TInputs extends {
|
|
735
734
|
[inputName in string]: ExtensionInput;
|
|
736
|
-
}, TConfigSchema extends {
|
|
737
|
-
[key in string]: (zImpl: typeof z) => z.ZodType;
|
|
738
735
|
}, UFactoryOutput extends ExtensionDataValue<any, any>, TDataRefs extends {
|
|
739
736
|
[name in string]: ExtensionDataRef;
|
|
740
737
|
}, UParentInputs extends ExtensionDataRef, TNewConfigSchema extends {
|
|
@@ -747,15 +744,6 @@ type CreateExtensionBlueprintOptions<TKind extends string, TParams extends objec
|
|
|
747
744
|
inputs?: TInputs;
|
|
748
745
|
output: Array<UOutput>;
|
|
749
746
|
configSchema?: TNewConfigSchema;
|
|
750
|
-
/**
|
|
751
|
-
* @deprecated Use {@link CreateExtensionBlueprintOptions.configSchema} instead.
|
|
752
|
-
*/
|
|
753
|
-
config?: {
|
|
754
|
-
/**
|
|
755
|
-
* @deprecated Use {@link CreateExtensionBlueprintOptions.configSchema} instead.
|
|
756
|
-
*/
|
|
757
|
-
schema: TConfigSchema;
|
|
758
|
-
};
|
|
759
747
|
/**
|
|
760
748
|
* This option is used to further refine the blueprint params. When this
|
|
761
749
|
* option is used, the blueprint will require params to be passed in callback
|
|
@@ -800,8 +788,6 @@ type CreateExtensionBlueprintOptions<TKind extends string, TParams extends objec
|
|
|
800
788
|
apis: ApiHolder;
|
|
801
789
|
config: {
|
|
802
790
|
[key in keyof TNewConfigSchema]: StandardSchemaV1.InferOutput<TNewConfigSchema[key]>;
|
|
803
|
-
} & {
|
|
804
|
-
[key in keyof TConfigSchema]: z.infer<ReturnType<((...args: any[]) => any) & TConfigSchema[key]>>;
|
|
805
791
|
};
|
|
806
792
|
inputs: Expand<ResolvedExtensionInputs<TInputs>>;
|
|
807
793
|
}): Iterable<UFactoryOutput>;
|
|
@@ -901,52 +887,6 @@ interface ExtensionBlueprint<T extends ExtensionBlueprintParameters = ExtensionB
|
|
|
901
887
|
name: string | undefined extends TName ? undefined : TName;
|
|
902
888
|
params: T['params'];
|
|
903
889
|
}>;
|
|
904
|
-
/**
|
|
905
|
-
* @deprecated Use the `configSchema` option instead of `config.schema`.
|
|
906
|
-
*/
|
|
907
|
-
makeWithOverrides<TName extends string | undefined, TExtensionConfigSchema extends {
|
|
908
|
-
[key in string]: (zImpl: typeof z) => z.ZodType;
|
|
909
|
-
}, UFactoryOutput extends ExtensionDataValue<any, any>, UNewOutput extends ExtensionDataRef, UParentInputs extends ExtensionDataRef, TExtraInputs extends {
|
|
910
|
-
[inputName in string]: ExtensionInput;
|
|
911
|
-
} = {}>(args: {
|
|
912
|
-
name?: TName;
|
|
913
|
-
attachTo?: ExtensionDefinitionAttachTo<UParentInputs> & VerifyExtensionAttachTo<ExtensionDataRef extends UNewOutput ? NonNullable<T['output']> : UNewOutput, UParentInputs>;
|
|
914
|
-
disabled?: boolean;
|
|
915
|
-
if?: FilterPredicate;
|
|
916
|
-
inputs?: TExtraInputs & {
|
|
917
|
-
[KName in keyof T['inputs']]?: `Error: Input '${KName & string}' is already defined in parent definition`;
|
|
918
|
-
};
|
|
919
|
-
output?: Array<UNewOutput>;
|
|
920
|
-
configSchema?: never;
|
|
921
|
-
config?: {
|
|
922
|
-
schema: TExtensionConfigSchema & {
|
|
923
|
-
[KName in keyof T['config']]?: `Error: Config key '${KName & string}' is already defined in parent schema`;
|
|
924
|
-
};
|
|
925
|
-
};
|
|
926
|
-
factory(originalFactory: <TParamsInput extends AnyParamsInput$1<NonNullable<T['params']>>>(params: TParamsInput extends ExtensionBlueprintDefineParams ? TParamsInput : T['params'] extends ExtensionBlueprintDefineParams ? 'Error: This blueprint uses advanced parameter types and requires you to pass parameters as using the following callback syntax: `originalFactory(defineParams => defineParams(<params>))`' : T['params'], context?: {
|
|
927
|
-
config?: T['config'];
|
|
928
|
-
inputs?: ResolvedInputValueOverrides<NonNullable<T['inputs']>>;
|
|
929
|
-
}) => ExtensionDataContainer<NonNullable<T['output']>>, context: {
|
|
930
|
-
node: AppNode;
|
|
931
|
-
apis: ApiHolder;
|
|
932
|
-
config: T['config'] & {
|
|
933
|
-
[key in keyof TExtensionConfigSchema]: z.infer<ReturnType<((...args: any[]) => any) & TExtensionConfigSchema[key]>>;
|
|
934
|
-
};
|
|
935
|
-
inputs: Expand<ResolvedExtensionInputs<T['inputs'] & TExtraInputs>>;
|
|
936
|
-
}): Iterable<UFactoryOutput> & VerifyExtensionFactoryOutput<ExtensionDataRef extends UNewOutput ? NonNullable<T['output']> : UNewOutput, UFactoryOutput>;
|
|
937
|
-
}): OverridableExtensionDefinition<{
|
|
938
|
-
config: Expand<(string extends keyof TExtensionConfigSchema ? {} : {
|
|
939
|
-
[key in keyof TExtensionConfigSchema]: z.infer<ReturnType<((...args: any[]) => any) & TExtensionConfigSchema[key]>>;
|
|
940
|
-
}) & T['config']>;
|
|
941
|
-
configInput: Expand<(string extends keyof TExtensionConfigSchema ? {} : z.input<z.ZodObject<{
|
|
942
|
-
[key in keyof TExtensionConfigSchema]: ReturnType<((...args: any[]) => any) & TExtensionConfigSchema[key]>;
|
|
943
|
-
}>>) & T['configInput']>;
|
|
944
|
-
output: ExtensionDataRef extends UNewOutput ? T['output'] : UNewOutput;
|
|
945
|
-
inputs: Expand<T['inputs'] & TExtraInputs>;
|
|
946
|
-
kind: T['kind'];
|
|
947
|
-
name: string | undefined extends TName ? undefined : TName;
|
|
948
|
-
params: T['params'];
|
|
949
|
-
}>;
|
|
950
890
|
}
|
|
951
891
|
/**
|
|
952
892
|
* Creates a new extension blueprint that encapsulates the creation of
|
|
@@ -1010,7 +950,6 @@ declare function createExtensionBlueprint<TParams extends object | ExtensionBlue
|
|
|
1010
950
|
if?: FilterPredicate;
|
|
1011
951
|
inputs?: TInputs;
|
|
1012
952
|
output: Array<UOutput>;
|
|
1013
|
-
config?: never;
|
|
1014
953
|
configSchema?: TNewConfigSchema;
|
|
1015
954
|
defineParams?: TParams extends ExtensionBlueprintDefineParams ? TParams : 'The defineParams option must be a function if provided, see the docs for details';
|
|
1016
955
|
factory(params: TParams extends ExtensionBlueprintDefineParams ? ReturnType<TParams>['T'] : TParams, context: {
|
|
@@ -1035,50 +974,6 @@ declare function createExtensionBlueprint<TParams extends object | ExtensionBlue
|
|
|
1035
974
|
};
|
|
1036
975
|
dataRefs: TDataRefs;
|
|
1037
976
|
}>;
|
|
1038
|
-
/**
|
|
1039
|
-
* @deprecated Use the top-level `configSchema` option instead of `config.schema`.
|
|
1040
|
-
* @public
|
|
1041
|
-
*/
|
|
1042
|
-
declare function createExtensionBlueprint<TParams extends object | ExtensionBlueprintDefineParams, UOutput extends ExtensionDataRef, TInputs extends {
|
|
1043
|
-
[inputName in string]: ExtensionInput;
|
|
1044
|
-
}, TConfigSchema extends {
|
|
1045
|
-
[key in string]: (zImpl: typeof z) => z.ZodType;
|
|
1046
|
-
}, UFactoryOutput extends ExtensionDataValue<any, any>, TKind extends string, UParentInputs extends ExtensionDataRef, TDataRefs extends {
|
|
1047
|
-
[name in string]: ExtensionDataRef;
|
|
1048
|
-
} = never>(options: {
|
|
1049
|
-
kind: TKind;
|
|
1050
|
-
attachTo: ExtensionDefinitionAttachTo<UParentInputs> & VerifyExtensionAttachTo<UOutput, UParentInputs>;
|
|
1051
|
-
disabled?: boolean;
|
|
1052
|
-
if?: FilterPredicate;
|
|
1053
|
-
inputs?: TInputs;
|
|
1054
|
-
output: Array<UOutput>;
|
|
1055
|
-
configSchema?: never;
|
|
1056
|
-
config?: {
|
|
1057
|
-
schema: TConfigSchema;
|
|
1058
|
-
};
|
|
1059
|
-
defineParams?: TParams extends ExtensionBlueprintDefineParams ? TParams : 'The defineParams option must be a function if provided, see the docs for details';
|
|
1060
|
-
factory(params: TParams extends ExtensionBlueprintDefineParams ? ReturnType<TParams>['T'] : TParams, context: {
|
|
1061
|
-
node: AppNode;
|
|
1062
|
-
apis: ApiHolder;
|
|
1063
|
-
config: {
|
|
1064
|
-
[key in keyof TConfigSchema]: z.infer<ReturnType<((...args: any[]) => any) & TConfigSchema[key]>>;
|
|
1065
|
-
};
|
|
1066
|
-
inputs: Expand<ResolvedExtensionInputs<TInputs>>;
|
|
1067
|
-
}): Iterable<UFactoryOutput>;
|
|
1068
|
-
dataRefs?: TDataRefs;
|
|
1069
|
-
} & VerifyExtensionFactoryOutput<UOutput, UFactoryOutput>): ExtensionBlueprint<{
|
|
1070
|
-
kind: TKind;
|
|
1071
|
-
params: TParams;
|
|
1072
|
-
output: UOutput extends ExtensionDataRef<infer IData, infer IId, infer IConfig> ? ExtensionDataRef<IData, IId, IConfig> : never;
|
|
1073
|
-
inputs: string extends keyof TInputs ? {} : TInputs;
|
|
1074
|
-
config: string extends keyof TConfigSchema ? {} : {
|
|
1075
|
-
[key in keyof TConfigSchema]: z.infer<ReturnType<((...args: any[]) => any) & TConfigSchema[key]>>;
|
|
1076
|
-
};
|
|
1077
|
-
configInput: string extends keyof TConfigSchema ? {} : z.input<z.ZodObject<{
|
|
1078
|
-
[key in keyof TConfigSchema]: ReturnType<((...args: any[]) => any) & TConfigSchema[key]>;
|
|
1079
|
-
}>>;
|
|
1080
|
-
dataRefs: TDataRefs;
|
|
1081
|
-
}>;
|
|
1082
977
|
|
|
1083
978
|
/** @ignore */
|
|
1084
979
|
type ResolvedExtensionInput<TExtensionInput extends ExtensionInput> = TExtensionInput['extensionData'] extends Array<ExtensionDataRef> ? {
|
|
@@ -1146,8 +1041,6 @@ type ExtensionDefinitionAttachTo<UParentInputs extends ExtensionDataRef = Extens
|
|
|
1146
1041
|
/** @public */
|
|
1147
1042
|
type CreateExtensionOptions<TKind extends string | undefined, TName extends string | undefined, UOutput extends ExtensionDataRef, TInputs extends {
|
|
1148
1043
|
[inputName in string]: ExtensionInput;
|
|
1149
|
-
}, TConfigSchema extends {
|
|
1150
|
-
[key: string]: (zImpl: typeof z) => z.ZodType;
|
|
1151
1044
|
}, UFactoryOutput extends ExtensionDataValue<any, any>, UParentInputs extends ExtensionDataRef, TNewConfigSchema extends {
|
|
1152
1045
|
[key: string]: StandardSchemaV1;
|
|
1153
1046
|
} = {}> = {
|
|
@@ -1159,22 +1052,11 @@ type CreateExtensionOptions<TKind extends string | undefined, TName extends stri
|
|
|
1159
1052
|
inputs?: TInputs;
|
|
1160
1053
|
output: Array<UOutput>;
|
|
1161
1054
|
configSchema?: TNewConfigSchema;
|
|
1162
|
-
/**
|
|
1163
|
-
* @deprecated Use {@link CreateExtensionOptions.configSchema} instead.
|
|
1164
|
-
*/
|
|
1165
|
-
config?: {
|
|
1166
|
-
/**
|
|
1167
|
-
* @deprecated Use {@link CreateExtensionOptions.configSchema} instead.
|
|
1168
|
-
*/
|
|
1169
|
-
schema: TConfigSchema;
|
|
1170
|
-
};
|
|
1171
1055
|
factory(context: {
|
|
1172
1056
|
node: AppNode;
|
|
1173
1057
|
apis: ApiHolder;
|
|
1174
1058
|
config: {
|
|
1175
1059
|
[key in keyof TNewConfigSchema]: StandardSchemaV1.InferOutput<TNewConfigSchema[key]>;
|
|
1176
|
-
} & {
|
|
1177
|
-
[key in keyof TConfigSchema]: z.infer<ReturnType<((...args: any[]) => any) & TConfigSchema[key]>>;
|
|
1178
1060
|
};
|
|
1179
1061
|
inputs: Expand<ResolvedExtensionInputs<TInputs>>;
|
|
1180
1062
|
}): Iterable<UFactoryOutput>;
|
|
@@ -1257,54 +1139,6 @@ interface OverridableExtensionDefinition<T extends ExtensionDefinitionParameters
|
|
|
1257
1139
|
[key in keyof TNewExtensionConfigSchema]?: StandardSchemaV1.InferInput<TNewExtensionConfigSchema[key]>;
|
|
1258
1140
|
};
|
|
1259
1141
|
}>;
|
|
1260
|
-
/**
|
|
1261
|
-
* @deprecated Use the `configSchema` option instead of `config.schema`.
|
|
1262
|
-
*/
|
|
1263
|
-
override<TExtensionConfigSchema extends {
|
|
1264
|
-
[key in string]: (zImpl: typeof z) => z.ZodType;
|
|
1265
|
-
}, UFactoryOutput extends ExtensionDataValue<any, any>, UNewOutput extends ExtensionDataRef, TExtraInputs extends {
|
|
1266
|
-
[inputName in string]: ExtensionInput;
|
|
1267
|
-
}, TParamsInput extends AnyParamsInput<NonNullable<T['params']>>, UParentInputs extends ExtensionDataRef>(args: Expand<{
|
|
1268
|
-
attachTo?: ExtensionDefinitionAttachTo<UParentInputs> & VerifyExtensionAttachTo<ExtensionDataRef extends UNewOutput ? NonNullable<T['output']> : UNewOutput, UParentInputs>;
|
|
1269
|
-
disabled?: boolean;
|
|
1270
|
-
if?: FilterPredicate;
|
|
1271
|
-
inputs?: TExtraInputs & {
|
|
1272
|
-
[KName in keyof T['inputs']]?: `Error: Input '${KName & string}' is already defined in parent definition`;
|
|
1273
|
-
};
|
|
1274
|
-
output?: Array<UNewOutput>;
|
|
1275
|
-
configSchema?: never;
|
|
1276
|
-
config?: {
|
|
1277
|
-
schema: TExtensionConfigSchema & {
|
|
1278
|
-
[KName in keyof T['config']]?: `Error: Config key '${KName & string}' is already defined in parent schema`;
|
|
1279
|
-
};
|
|
1280
|
-
};
|
|
1281
|
-
factory?(originalFactory: <TFactoryParamsReturn extends AnyParamsInput<NonNullable<T['params']>>>(context?: Expand<{
|
|
1282
|
-
config?: T['config'];
|
|
1283
|
-
inputs?: ResolvedInputValueOverrides<NonNullable<T['inputs']>>;
|
|
1284
|
-
} & ([T['params']] extends [never] ? {} : {
|
|
1285
|
-
params?: TFactoryParamsReturn extends ExtensionBlueprintDefineParams ? TFactoryParamsReturn : T['params'] extends ExtensionBlueprintDefineParams ? 'Error: This blueprint uses advanced parameter types and requires you to pass parameters as using the following callback syntax: `originalFactory(defineParams => defineParams(<params>))`' : Partial<T['params']>;
|
|
1286
|
-
})>) => ExtensionDataContainer<NonNullable<T['output']>>, context: {
|
|
1287
|
-
node: AppNode;
|
|
1288
|
-
apis: ApiHolder;
|
|
1289
|
-
config: T['config'] & {
|
|
1290
|
-
[key in keyof TExtensionConfigSchema]: z.infer<ReturnType<((...args: any[]) => any) & TExtensionConfigSchema[key]>>;
|
|
1291
|
-
};
|
|
1292
|
-
inputs: Expand<ResolvedExtensionInputs<T['inputs'] & TExtraInputs>>;
|
|
1293
|
-
}): Iterable<UFactoryOutput>;
|
|
1294
|
-
} & ([T['params']] extends [never] ? {} : {
|
|
1295
|
-
params?: TParamsInput extends ExtensionBlueprintDefineParams ? TParamsInput : T['params'] extends ExtensionBlueprintDefineParams ? 'Error: This blueprint uses advanced parameter types and requires you to pass parameters as using the following callback syntax: `originalFactory(defineParams => defineParams(<params>))`' : Partial<T['params']>;
|
|
1296
|
-
})> & VerifyExtensionFactoryOutput<ExtensionDataRef extends UNewOutput ? NonNullable<T['output']> : UNewOutput, UFactoryOutput>): OverridableExtensionDefinition<{
|
|
1297
|
-
kind: T['kind'];
|
|
1298
|
-
name: T['name'];
|
|
1299
|
-
output: ExtensionDataRef extends UNewOutput ? T['output'] : UNewOutput;
|
|
1300
|
-
inputs: T['inputs'] & TExtraInputs;
|
|
1301
|
-
config: T['config'] & {
|
|
1302
|
-
[key in keyof TExtensionConfigSchema]: z.infer<ReturnType<((...args: any[]) => any) & TExtensionConfigSchema[key]>>;
|
|
1303
|
-
};
|
|
1304
|
-
configInput: T['configInput'] & z.input<z.ZodObject<{
|
|
1305
|
-
[key in keyof TExtensionConfigSchema]: ReturnType<((...args: any[]) => any) & TExtensionConfigSchema[key]>;
|
|
1306
|
-
}>>;
|
|
1307
|
-
}>;
|
|
1308
1142
|
}
|
|
1309
1143
|
/**
|
|
1310
1144
|
* Creates a new extension definition for installation in a Backstage app.
|
|
@@ -1345,9 +1179,7 @@ declare function createExtension<UOutput extends ExtensionDataRef, TInputs exten
|
|
|
1345
1179
|
[inputName in string]: ExtensionInput;
|
|
1346
1180
|
}, UFactoryOutput extends ExtensionDataValue<any, any>, const TKind extends string | undefined = undefined, const TName extends string | undefined = undefined, UParentInputs extends ExtensionDataRef = ExtensionDataRef, TNewConfigSchema extends {
|
|
1347
1181
|
[key: string]: StandardSchemaV1;
|
|
1348
|
-
} = {}>(options: CreateExtensionOptions<TKind, TName, UOutput, TInputs,
|
|
1349
|
-
config?: never;
|
|
1350
|
-
}): OverridableExtensionDefinition<{
|
|
1182
|
+
} = {}>(options: CreateExtensionOptions<TKind, TName, UOutput, TInputs, UFactoryOutput, UParentInputs, TNewConfigSchema>): OverridableExtensionDefinition<{
|
|
1351
1183
|
config: {
|
|
1352
1184
|
[key in keyof TNewConfigSchema]: StandardSchemaV1.InferOutput<TNewConfigSchema[key]>;
|
|
1353
1185
|
};
|
|
@@ -1360,29 +1192,6 @@ declare function createExtension<UOutput extends ExtensionDataRef, TInputs exten
|
|
|
1360
1192
|
kind: string | undefined extends TKind ? undefined : TKind;
|
|
1361
1193
|
name: string | undefined extends TName ? undefined : TName;
|
|
1362
1194
|
}>;
|
|
1363
|
-
/**
|
|
1364
|
-
* @deprecated Use the top-level `configSchema` option instead of `config.schema`.
|
|
1365
|
-
* @public
|
|
1366
|
-
*/
|
|
1367
|
-
declare function createExtension<UOutput extends ExtensionDataRef, TInputs extends {
|
|
1368
|
-
[inputName in string]: ExtensionInput;
|
|
1369
|
-
}, TConfigSchema extends {
|
|
1370
|
-
[key: string]: (zImpl: typeof z) => z.ZodType;
|
|
1371
|
-
}, UFactoryOutput extends ExtensionDataValue<any, any>, const TKind extends string | undefined = undefined, const TName extends string | undefined = undefined, UParentInputs extends ExtensionDataRef = ExtensionDataRef>(options: CreateExtensionOptions<TKind, TName, UOutput, TInputs, TConfigSchema, UFactoryOutput, UParentInputs, {}> & {
|
|
1372
|
-
configSchema?: never;
|
|
1373
|
-
}): OverridableExtensionDefinition<{
|
|
1374
|
-
config: string extends keyof TConfigSchema ? {} : {
|
|
1375
|
-
[key in keyof TConfigSchema]: z.infer<ReturnType<((...args: any[]) => any) & TConfigSchema[key]>>;
|
|
1376
|
-
};
|
|
1377
|
-
configInput: string extends keyof TConfigSchema ? {} : z.input<z.ZodObject<{
|
|
1378
|
-
[key in keyof TConfigSchema]: ReturnType<((...args: any[]) => any) & TConfigSchema[key]>;
|
|
1379
|
-
}>>;
|
|
1380
|
-
output: UOutput extends ExtensionDataRef<infer IData, infer IId, infer IConfig> ? ExtensionDataRef<IData, IId, IConfig> : never;
|
|
1381
|
-
inputs: TInputs;
|
|
1382
|
-
params: never;
|
|
1383
|
-
kind: string | undefined extends TKind ? undefined : TKind;
|
|
1384
|
-
name: string | undefined extends TName ? undefined : TName;
|
|
1385
|
-
}>;
|
|
1386
1195
|
|
|
1387
1196
|
/**
|
|
1388
1197
|
* The specification for this {@link AppNode} in the {@link AppTree}.
|
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
import { resolveInputOverrides } from './resolveInputOverrides.esm.js';
|
|
2
|
-
import {
|
|
3
|
-
import {
|
|
2
|
+
import { createConfigSchema } from '../schema/createPortableSchema.esm.js';
|
|
3
|
+
import { assertNoLegacyConfigSchema } from '../schema/assertNoLegacyConfigSchema.esm.js';
|
|
4
4
|
import { OpaqueExtensionDefinition } from '../frontend-internal/src/wiring/InternalExtensionDefinition.esm.js';
|
|
5
5
|
import { createExtensionDataContainer } from '../frontend-internal/src/wiring/createExtensionDataContainer.esm.js';
|
|
6
6
|
import { OpaqueExtensionInput } from '../frontend-internal/src/wiring/InternalExtensionInput.esm.js';
|
|
@@ -24,13 +24,8 @@ function bindInputs(inputs, kind, name) {
|
|
|
24
24
|
);
|
|
25
25
|
}
|
|
26
26
|
function createExtension(options) {
|
|
27
|
-
|
|
28
|
-
|
|
29
|
-
}
|
|
30
|
-
const resolvedConfigSchema = mergePortableSchemas(
|
|
31
|
-
options.config?.schema ? createDeprecatedConfigSchema(options.config.schema) : void 0,
|
|
32
|
-
options.configSchema ? createConfigSchema(options.configSchema) : void 0
|
|
33
|
-
);
|
|
27
|
+
assertNoLegacyConfigSchema(options);
|
|
28
|
+
const resolvedConfigSchema = options.configSchema ? createConfigSchema(options.configSchema) : void 0;
|
|
34
29
|
return OpaqueExtensionDefinition.createInstance("v2", {
|
|
35
30
|
T: void 0,
|
|
36
31
|
kind: options.kind,
|
|
@@ -85,14 +80,12 @@ function createExtension(options) {
|
|
|
85
80
|
return `ExtensionDefinition{${parts.join(",")}}`;
|
|
86
81
|
},
|
|
87
82
|
override(overrideOptions) {
|
|
83
|
+
assertNoLegacyConfigSchema(overrideOptions);
|
|
88
84
|
if (!Array.isArray(options.output)) {
|
|
89
85
|
throw new Error(
|
|
90
86
|
"Cannot override an extension that is not declared using the new format with outputs as an array"
|
|
91
87
|
);
|
|
92
88
|
}
|
|
93
|
-
if (overrideOptions.config?.schema) {
|
|
94
|
-
warnConfigSchemaPropDeprecation(describeParentCallSite());
|
|
95
|
-
}
|
|
96
89
|
if (overrideOptions.output && !overrideOptions.factory) {
|
|
97
90
|
throw new Error(
|
|
98
91
|
"Refused to override output without also overriding factory"
|
|
@@ -122,12 +115,6 @@ function createExtension(options) {
|
|
|
122
115
|
options.name
|
|
123
116
|
),
|
|
124
117
|
output: overrideOptions.output ?? options.output,
|
|
125
|
-
config: options.config?.schema || overrideOptions.config?.schema ? {
|
|
126
|
-
schema: {
|
|
127
|
-
...options.config?.schema,
|
|
128
|
-
...overrideOptions.config?.schema
|
|
129
|
-
}
|
|
130
|
-
} : void 0,
|
|
131
118
|
configSchema: options.configSchema || overrideOptions.configSchema ? {
|
|
132
119
|
...options.configSchema,
|
|
133
120
|
...overrideOptions.configSchema
|