From 08efed9160a4cf7f60fb99d04d3c8512ad6de6ad Mon Sep 17 00:00:00 2001 From: blam Date: Tue, 11 Feb 2025 13:42:38 +0100 Subject: [PATCH] chore: fix changesets Signed-off-by: blam t p --- .changeset/curvy-numbers-grin.md | 7 --- .changeset/dull-olives-itch.md | 69 ++++++++++++++++++++- plugins/scaffolder-node/src/actions/util.ts | 5 +- 3 files changed, 71 insertions(+), 10 deletions(-) delete mode 100644 .changeset/curvy-numbers-grin.md diff --git a/.changeset/curvy-numbers-grin.md b/.changeset/curvy-numbers-grin.md deleted file mode 100644 index 1f786335c0..0000000000 --- a/.changeset/curvy-numbers-grin.md +++ /dev/null @@ -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. diff --git a/.changeset/dull-olives-itch.md b/.changeset/dull-olives-itch.md index b886906849..679ed584d7 100644 --- a/.changeset/dull-olives-itch.md +++ b/.changeset/dull-olives-itch.md @@ -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()); + }); + }, +}); +``` diff --git a/plugins/scaffolder-node/src/actions/util.ts b/plugins/scaffolder-node/src/actions/util.ts index 038d199d3b..64728d9cd0 100644 --- a/plugins/scaffolder-node/src/actions/util.ts +++ b/plugins/scaffolder-node/src/actions/util.ts @@ -174,5 +174,8 @@ export const parseSchemas = (action: TemplateActionOptions) => { }; } - throw new Error('Invalid schema provided'); + return { + inputSchema: action.schema.input, + outputSchema: action.schema.output, + }; };