feat: small refactor to move some logic out of the index files and move to using .args() and .returns() as it's cleaner

Signed-off-by: benjdlambert <ben@blam.sh>
This commit is contained in:
benjdlambert
2025-03-21 11:07:00 +01:00
parent d48525c9f8
commit 3cfc7f06d1
21 changed files with 230 additions and 148 deletions
@@ -14,11 +14,8 @@
* limitations under the License.
*/
import {
CreatedTemplateFilter,
TemplateFilterExample,
ZodFunctionSchema,
} from './types';
import { ZodFunctionSchema } from '../types';
import { CreatedTemplateFilter, TemplateFilterExample } from './types';
import { z } from 'zod';
/**
@@ -14,6 +14,7 @@
* limitations under the License.
*/
import { z } from 'zod';
import { ZodFunctionSchema } from '../types';
export type { TemplateFilter } from '../../types';
@@ -24,21 +25,6 @@ export type TemplateFilterExample = {
notes?: string;
};
/**
* Type for template filter schema functions that supports both Zod function definition methods:
* @alpha
*/
export type ZodFunctionSchema<
TFunctionArgs extends [z.ZodTypeAny, ...z.ZodTypeAny[]],
TReturnType extends z.ZodTypeAny,
> = (
zod: typeof z,
) =>
| z.ZodFunction<z.ZodTuple<TFunctionArgs, null>, TReturnType>
| z.ZodType<
(...args: z.infer<z.ZodTuple<TFunctionArgs>>) => z.infer<TReturnType>
>;
/** @alpha */
export type CreatedTemplateFilter<
TFunctionArgs extends [z.ZodTypeAny, ...z.ZodTypeAny[]],
@@ -20,7 +20,7 @@ import {
CreatedTemplateGlobalValue,
TemplateGlobalFunctionExample,
} from './types';
import { ZodFunctionSchema } from '../filters';
import { ZodFunctionSchema } from '../types';
/**
* This function is used to create new template global values in type-safe manner.
@@ -15,7 +15,7 @@
*/
import { JsonValue } from '@backstage/types';
import { z } from 'zod';
import { ZodFunctionSchema } from '../filters/types';
import { ZodFunctionSchema } from '../types';
export type { TemplateGlobal } from '../../types';
@@ -27,6 +27,7 @@ import { CreatedTemplateGlobal } from './globals';
export * from '../tasks/alpha';
export * from './filters';
export * from './globals';
export * from './types';
/**
* Extension point for managing scaffolder actions.
@@ -0,0 +1,30 @@
/*
* Copyright 2025 The Backstage Authors
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
* You may obtain a copy of the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
* See the License for the specific language governing permissions and
* limitations under the License.
*/
import { z } from 'zod';
/**
* @alpha
*/
export type ZodFunctionSchema<
TFunctionArgs extends [z.ZodTypeAny, ...z.ZodTypeAny[]],
TReturnType extends z.ZodTypeAny,
> = (
zod: typeof z,
) =>
| z.ZodFunction<z.ZodTuple<TFunctionArgs, null>, TReturnType>
| z.ZodType<
(...args: z.infer<z.ZodTuple<TFunctionArgs>>) => z.infer<TReturnType>
>;