Simplify generics after #16910 was merged

Signed-off-by: Andreas Berger <andreas@berger-ecommerce.com>
This commit is contained in:
Andreas Berger
2023-03-28 15:52:57 +02:00
parent 439e2986be
commit a6cb0629bd
6 changed files with 111 additions and 100 deletions
@@ -16,6 +16,9 @@ export const createGitlabGroupEnsureExistsAction: (options: {
token?: string | undefined;
} & {
path: string[];
},
{
groupId?: number | undefined;
}
>;
@@ -25,13 +28,16 @@ export const createGitlabProjectAccessTokenAction: (options: {
}) => TemplateAction<
{
repoUrl: string;
projectId: string | number;
name: string;
accessLevel: number;
scopes: string[];
token?: string | undefined;
} & {
projectId: string | number;
name?: string | undefined;
accessLevel?: string | undefined;
scopes?: string[] | undefined;
},
JsonObject
{
access_token: string;
}
>;
// @public
@@ -40,13 +46,17 @@ export const createGitlabProjectDeployTokenAction: (options: {
}) => TemplateAction<
{
repoUrl: string;
projectId: string | number;
name: string;
username: string;
scopes: string[];
token?: string | undefined;
} & {
name: string;
projectId: string | number;
username?: string | undefined;
scopes?: string[] | undefined;
},
JsonObject
{
user: string;
deploy_token: string;
}
>;
// @public
@@ -65,8 +75,7 @@ export const createGitlabProjectVariableAction: (options: {
masked?: boolean | undefined;
raw?: boolean | undefined;
environmentScope?: string | undefined;
}
,
},
JsonObject
>;
```
@@ -22,20 +22,6 @@ import commonGitlabConfig from '../commonGitlabConfig';
import { getToken } from '../util';
import { z } from 'zod';
const input = commonGitlabConfig.and(
z.object({
path: z
.array(z.string(), {
description: 'A path of group names that is ensured to exist',
})
.min(1),
}),
);
const output = z.object({
groupId: z.string({ description: 'The id of the innermost sub-group' }),
});
/**
* Creates an `gitlab:group:ensureExists` Scaffolder action.
*
@@ -46,10 +32,25 @@ export const createGitlabGroupEnsureExistsAction = (options: {
}) => {
const { integrations } = options;
return createTemplateAction<z.infer<typeof input>>({
return createTemplateAction({
id: 'gitlab:group:ensureExists',
description: 'Ensures a Gitlab group exists',
schema: { input, output },
schema: {
input: commonGitlabConfig.and(
z.object({
path: z
.array(z.string(), {
description: 'A path of group names that is ensured to exist',
})
.min(1),
}),
),
output: z.object({
groupId: z
.number({ description: 'The id of the innermost sub-group' })
.optional(),
}),
},
async handler(ctx) {
const { path } = ctx.input;
const { token, integrationConfig } = getToken(ctx.input, integrations);
@@ -20,21 +20,6 @@ import commonGitlabConfig from '../commonGitlabConfig';
import { getToken } from '../util';
import { z } from 'zod';
const input = commonGitlabConfig.and(
z.object({
projectId: z.union([z.number(), z.string()], { description: 'Project ID' }),
name: z.string({ description: 'Deploy Token Name' }).optional(),
accessLevel: z
.string({ description: 'Access Level of the Token' })
.optional(),
scopes: z.array(z.string(), { description: 'Scopes' }).optional(),
}),
);
const output = z.object({
access_token: z.string({ description: 'Access Token' }),
});
/**
* Creates a `gitlab:projectAccessToken:create` Scaffolder action.
*
@@ -45,9 +30,25 @@ export const createGitlabProjectAccessTokenAction = (options: {
integrations: ScmIntegrationRegistry;
}) => {
const { integrations } = options;
return createTemplateAction<z.infer<typeof input>>({
return createTemplateAction({
id: 'gitlab:projectAccessToken:create',
schema: { input, output },
schema: {
input: commonGitlabConfig.and(
z.object({
projectId: z.union([z.number(), z.string()], {
description: 'Project ID',
}),
name: z.string({ description: 'Deploy Token Name' }).optional(),
accessLevel: z
.string({ description: 'Access Level of the Token' })
.optional(),
scopes: z.array(z.string(), { description: 'Scopes' }).optional(),
}),
),
output: z.object({
access_token: z.string({ description: 'Access Token' }),
}),
},
async handler(ctx) {
ctx.logger.info(`Creating Token for Project "${ctx.input.projectId}"`);
const { projectId, name, accessLevel, scopes } = ctx.input;
@@ -23,20 +23,6 @@ import { getToken } from '../util';
import { InputError } from '@backstage/errors';
import { z } from 'zod';
const input = commonGitlabConfig.and(
z.object({
projectId: z.union([z.number(), z.string()], { description: 'Project ID' }),
name: z.string({ description: 'Deploy Token Name' }),
username: z.string({ description: 'Deploy Token Username' }).optional(),
scopes: z.array(z.string(), { description: 'Scopes' }).optional(),
}),
);
const output = z.object({
deploy_token: z.string({ description: 'Deploy Token' }),
user: z.string({ description: 'User' }),
});
/**
* Creates a `gitlab:projectDeployToken:create` Scaffolder action.
*
@@ -47,9 +33,26 @@ export const createGitlabProjectDeployTokenAction = (options: {
integrations: ScmIntegrationRegistry;
}) => {
const { integrations } = options;
return createTemplateAction<z.infer<typeof input>>({
return createTemplateAction({
id: 'gitlab:projectDeployToken:create',
schema: { input, output },
schema: {
input: commonGitlabConfig.and(
z.object({
projectId: z.union([z.number(), z.string()], {
description: 'Project ID',
}),
name: z.string({ description: 'Deploy Token Name' }),
username: z
.string({ description: 'Deploy Token Username' })
.optional(),
scopes: z.array(z.string(), { description: 'Scopes' }).optional(),
}),
),
output: z.object({
deploy_token: z.string({ description: 'Deploy Token' }),
user: z.string({ description: 'User' }),
}),
},
async handler(ctx) {
ctx.logger.info(`Creating Token for Project "${ctx.input.projectId}"`);
const { projectId, name, username, scopes } = ctx.input;
@@ -21,36 +21,6 @@ import { getToken } from '../util';
import commonGitlabConfig from '../commonGitlabConfig';
import { z } from 'zod';
const input = commonGitlabConfig.and(
z.object({
projectId: z.union([z.number(), z.string()], { description: 'Project ID' }),
key: z
.string({
description:
'The key of a variable; must have no more than 255 characters; only A-Z, a-z, 0-9, and _ are allowed',
})
.regex(/^[A-Za-z0-9_]{1,255}$/),
value: z.string({ description: 'The value of a variable' }),
variableType: z.string({ description: 'Variable Type (env_var or file)' }),
variableProtected: z
.boolean({ description: 'Whether the variable is protected' })
.default(false)
.optional(),
masked: z
.boolean({ description: 'Whether the variable is masked' })
.default(false)
.optional(),
raw: z
.boolean({ description: 'Whether the variable is expandable' })
.default(false)
.optional(),
environmentScope: z
.string({ description: 'The environment_scope of the variable' })
.default('*')
.optional(),
}),
);
/**
* Creates a `gitlab:projectVariable:create` Scaffolder action.
*
@@ -61,9 +31,43 @@ export const createGitlabProjectVariableAction = (options: {
integrations: ScmIntegrationRegistry;
}) => {
const { integrations } = options;
return createTemplateAction<z.infer<typeof input>>({
return createTemplateAction({
id: 'gitlab:projectVariable:create',
schema: { input },
schema: {
input: commonGitlabConfig.and(
z.object({
projectId: z.union([z.number(), z.string()], {
description: 'Project ID',
}),
key: z
.string({
description:
'The key of a variable; must have no more than 255 characters; only A-Z, a-z, 0-9, and _ are allowed',
})
.regex(/^[A-Za-z0-9_]{1,255}$/),
value: z.string({ description: 'The value of a variable' }),
variableType: z.string({
description: 'Variable Type (env_var or file)',
}),
variableProtected: z
.boolean({ description: 'Whether the variable is protected' })
.default(false)
.optional(),
masked: z
.boolean({ description: 'Whether the variable is masked' })
.default(false)
.optional(),
raw: z
.boolean({ description: 'Whether the variable is expandable' })
.default(false)
.optional(),
environmentScope: z
.string({ description: 'The environment_scope of the variable' })
.default('*')
.optional(),
}),
),
},
async handler(ctx) {
const {
projectId,
-7
View File
@@ -40594,13 +40594,6 @@ __metadata:
languageName: node
linkType: hard
"zod@npm:^3.21.4":
version: 3.21.4
resolution: "zod@npm:3.21.4"
checksum: f185ba87342ff16f7a06686767c2b2a7af41110c7edf7c1974095d8db7a73792696bcb4a00853de0d2edeb34a5b2ea6a55871bc864227dace682a0a28de33e1f
languageName: node
linkType: hard
"zod@npm:~3.18.0":
version: 3.18.0
resolution: "zod@npm:3.18.0"