@@ -1,7 +0,0 @@
|
||||
---
|
||||
'@backstage/types': minor
|
||||
---
|
||||
|
||||
feat: feat(scaffolder): add first class citizen support for zod
|
||||
|
||||
Added `Prettify` utility type to enhance readability of hover overlays (type hints) for object types. This type simplifies complex object intersections, making them more legible in editor tooltips.
|
||||
@@ -2,6 +2,71 @@
|
||||
'@backstage/plugin-scaffolder-node': minor
|
||||
---
|
||||
|
||||
feat(scaffolder): add first class citizen support for zod
|
||||
**DEPRECATION**: We've deprecated the old way of defining actions using `createTemplateAction` with raw `JSONSchema` and type parameters, as well as using `zod` through an import. You can now use the new format to define `createTemplateActions` with `zod` provided by the framework. This change also removes support for `logStream` in the `context` as well as moving the `logger` to an instance of `LoggerService`.
|
||||
|
||||
This change introduces a new way to define template actions using Zod schemas for type safety. The existing `createTemplateAction` function is now renamed to `oldCreateTemplateAction` to maintain backwards compatibility. A new `createTemplateAction` function is introduced which acts as an overload, supporting both the old style (using JSON Schema or string schemas) via `oldCreateTemplateAction` and the new style (using Zod schemas) via `newCreateTemplateAction`. This new function, `newCreateTemplateAction`, provides direct support for Zod, simplifying action definition and enhancing type checking.
|
||||
Before:
|
||||
|
||||
```ts
|
||||
createTemplateAction<{ repoUrl: string }, { test: string }>({
|
||||
id: 'test',
|
||||
schema: {
|
||||
input: {
|
||||
type: 'object',
|
||||
required: ['repoUrl'],
|
||||
properties: {
|
||||
repoUrl: { type: 'string' },
|
||||
},
|
||||
},
|
||||
output: {
|
||||
type: 'object',
|
||||
required: ['test'],
|
||||
properties: {
|
||||
test: { type: 'string' },
|
||||
},
|
||||
},
|
||||
},
|
||||
handler: async ctx => {
|
||||
ctx.logStream.write('blob');
|
||||
},
|
||||
});
|
||||
|
||||
// or
|
||||
|
||||
createTemplateAction({
|
||||
id: 'test',
|
||||
schema: {
|
||||
input: z.object({
|
||||
repoUrl: z.string(),
|
||||
}),
|
||||
output: z.object({
|
||||
test: z.string(),
|
||||
}),
|
||||
},
|
||||
handler: async ctx => {
|
||||
ctx.logStream.write('something');
|
||||
},
|
||||
});
|
||||
```
|
||||
|
||||
After:
|
||||
|
||||
```ts
|
||||
createTemplateAction({
|
||||
id: 'test',
|
||||
schema: {
|
||||
input: {
|
||||
repoUrl: d => d.string(),
|
||||
},
|
||||
output: {
|
||||
test: d => d.string(),
|
||||
},
|
||||
},
|
||||
handler: async ctx => {
|
||||
// you can just use ctx.logger.log('...'), or if you really need a log stream you can do this:
|
||||
const logStream = new PassThrough();
|
||||
logStream.on('data', chunk => {
|
||||
ctx.logger.info(chunk.toString());
|
||||
});
|
||||
},
|
||||
});
|
||||
```
|
||||
|
||||
@@ -174,5 +174,8 @@ export const parseSchemas = (action: TemplateActionOptions<any, any, any>) => {
|
||||
};
|
||||
}
|
||||
|
||||
throw new Error('Invalid schema provided');
|
||||
return {
|
||||
inputSchema: action.schema.input,
|
||||
outputSchema: action.schema.output,
|
||||
};
|
||||
};
|
||||
|
||||
Reference in New Issue
Block a user