chore: wip
Signed-off-by: blam <ben@blam.sh> Signed-off-by: benjdlambert <ben@blam.sh>
This commit is contained in:
@@ -0,0 +1,19 @@
|
||||
---
|
||||
'@backstage/plugin-scaffolder-backend-module-confluence-to-markdown': patch
|
||||
'@backstage/plugin-scaffolder-backend-module-bitbucket-cloud': patch
|
||||
'@backstage/plugin-scaffolder-backend-module-notifications': patch
|
||||
'@backstage/plugin-scaffolder-backend-module-cookiecutter': patch
|
||||
'@backstage/plugin-scaffolder-backend-module-bitbucket': patch
|
||||
'@backstage/plugin-scaffolder-backend-module-gerrit': patch
|
||||
'@backstage/plugin-scaffolder-backend-module-github': patch
|
||||
'@backstage/plugin-scaffolder-backend-module-gitlab': patch
|
||||
'@backstage/plugin-scaffolder-backend-module-sentry': patch
|
||||
'@backstage/plugin-scaffolder-backend-module-yeoman': patch
|
||||
'@backstage/plugin-scaffolder-backend-module-azure': patch
|
||||
'@backstage/plugin-scaffolder-backend-module-gitea': patch
|
||||
'@backstage/plugin-scaffolder-backend-module-rails': patch
|
||||
'@backstage/plugin-scaffolder-backend-module-gcp': patch
|
||||
'@backstage/plugin-scaffolder-node-test-utils': patch
|
||||
---
|
||||
|
||||
Re-export types
|
||||
@@ -1,5 +1,7 @@
|
||||
---
|
||||
'@backstage/plugin-scaffolder-node': minor
|
||||
'@backstage/plugin-scaffolder-backend': minor
|
||||
'@backstage/plugin-scaffolder-node-test-utils': minor
|
||||
---
|
||||
|
||||
**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`.
|
||||
|
||||
@@ -97,7 +97,7 @@
|
||||
"globby": "^11.0.0",
|
||||
"isbinaryfile": "^5.0.0",
|
||||
"isolated-vm": "^5.0.1",
|
||||
"jsonschema": "^1.2.6",
|
||||
"json-schema": "^0.4.0",
|
||||
"knex": "^3.0.0",
|
||||
"lodash": "^4.17.21",
|
||||
"logform": "^2.3.2",
|
||||
|
||||
@@ -18,7 +18,7 @@ import { Config, readDurationFromConfig } from '@backstage/config';
|
||||
import { HumanDuration } from '@backstage/types';
|
||||
|
||||
import { isArray } from 'lodash';
|
||||
import { Schema } from 'jsonschema';
|
||||
import { JSONSchema7 } from 'json-schema';
|
||||
|
||||
/**
|
||||
* Returns true if the input is not `false`, `undefined`, `null`, `""`, `0`, or
|
||||
@@ -29,7 +29,7 @@ export function isTruthy(value: any): boolean {
|
||||
return isArray(value) ? value.length > 0 : !!value;
|
||||
}
|
||||
|
||||
export function generateExampleOutput(schema: Schema): unknown {
|
||||
export function generateExampleOutput(schema: JSONSchema7): unknown {
|
||||
const { examples } = schema as { examples?: unknown };
|
||||
if (examples && Array.isArray(examples)) {
|
||||
return examples[0];
|
||||
@@ -38,13 +38,13 @@ export function generateExampleOutput(schema: Schema): unknown {
|
||||
return Object.fromEntries(
|
||||
Object.entries(schema.properties ?? {}).map(([key, value]) => [
|
||||
key,
|
||||
generateExampleOutput(value),
|
||||
generateExampleOutput(value as JSONSchema7),
|
||||
]),
|
||||
);
|
||||
} else if (schema.type === 'array') {
|
||||
const [firstSchema] = [schema.items]?.flat();
|
||||
if (firstSchema) {
|
||||
return [generateExampleOutput(firstSchema)];
|
||||
return [generateExampleOutput(firstSchema as JSONSchema7)];
|
||||
}
|
||||
return [];
|
||||
} else if (schema.type === 'string') {
|
||||
|
||||
@@ -64,7 +64,7 @@
|
||||
"fs-extra": "^11.2.0",
|
||||
"globby": "^11.0.0",
|
||||
"isomorphic-git": "^1.23.0",
|
||||
"jsonschema": "^1.2.6",
|
||||
"json-schema": "^0.4.0",
|
||||
"p-limit": "^3.1.0",
|
||||
"tar": "^6.1.12",
|
||||
"winston": "^3.2.1",
|
||||
|
||||
@@ -16,7 +16,7 @@
|
||||
|
||||
import { ActionContext, TemplateAction } from './types';
|
||||
import { z } from 'zod';
|
||||
import { Schema } from 'jsonschema';
|
||||
import { JSONSchema7 } from 'json-schema';
|
||||
import { Expand, JsonObject } from '@backstage/types';
|
||||
import { parseSchemas } from './util';
|
||||
|
||||
@@ -31,13 +31,13 @@ export type TemplateActionOptions<
|
||||
TActionInput extends JsonObject = {},
|
||||
TActionOutput extends JsonObject = {},
|
||||
TInputSchema extends
|
||||
| Schema
|
||||
| JSONSchema7
|
||||
| z.ZodType
|
||||
| { [key in string]: (zImpl: typeof z) => z.ZodType } = Schema,
|
||||
| { [key in string]: (zImpl: typeof z) => z.ZodType } = JSONSchema7,
|
||||
TOutputSchema extends
|
||||
| Schema
|
||||
| JSONSchema7
|
||||
| z.ZodType
|
||||
| { [key in string]: (zImpl: typeof z) => z.ZodType } = Schema,
|
||||
| { [key in string]: (zImpl: typeof z) => z.ZodType } = JSONSchema7,
|
||||
TSchemaType extends 'v1' | 'v2' = 'v1' | 'v2',
|
||||
> = {
|
||||
id: string;
|
||||
@@ -71,8 +71,8 @@ type FlattenOptionalProperties<T extends { [key in string]: unknown }> = Expand<
|
||||
export function createTemplateAction<
|
||||
TInputParams extends JsonObject = JsonObject,
|
||||
TOutputParams extends JsonObject = JsonObject,
|
||||
TInputSchema extends Schema = Schema,
|
||||
TOutputSchema extends Schema = Schema,
|
||||
TInputSchema extends JSONSchema7 = JSONSchema7,
|
||||
TOutputSchema extends JSONSchema7 = JSONSchema7,
|
||||
TActionInput extends JsonObject = TInputParams,
|
||||
TActionOutput extends JsonObject = TOutputParams,
|
||||
>(
|
||||
@@ -137,11 +137,11 @@ export function createTemplateAction<
|
||||
TInputParams extends JsonObject = JsonObject,
|
||||
TOutputParams extends JsonObject = JsonObject,
|
||||
TInputSchema extends
|
||||
| Schema
|
||||
| JSONSchema7
|
||||
| z.ZodType
|
||||
| { [key in string]: (zImpl: typeof z) => z.ZodType } = {},
|
||||
TOutputSchema extends
|
||||
| Schema
|
||||
| JSONSchema7
|
||||
| z.ZodType
|
||||
| { [key in string]: (zImpl: typeof z) => z.ZodType } = {},
|
||||
TActionInput extends JsonObject = TInputSchema extends z.ZodType<
|
||||
@@ -180,14 +180,16 @@ export function createTemplateAction<
|
||||
? 'v2'
|
||||
: 'v1'
|
||||
> {
|
||||
const { inputSchema, outputSchema } = parseSchemas(action);
|
||||
const { inputSchema, outputSchema } = parseSchemas(
|
||||
action as TemplateActionOptions<any, any, any>,
|
||||
);
|
||||
|
||||
return {
|
||||
...action,
|
||||
schema: {
|
||||
...action.schema,
|
||||
input: inputSchema as TInputSchema,
|
||||
output: outputSchema as TOutputSchema,
|
||||
input: inputSchema,
|
||||
output: outputSchema,
|
||||
},
|
||||
};
|
||||
}
|
||||
|
||||
@@ -20,7 +20,7 @@ import { JsonObject, JsonValue } from '@backstage/types';
|
||||
import { TaskSecrets } from '../tasks';
|
||||
import { TemplateInfo } from '@backstage/plugin-scaffolder-common';
|
||||
import { UserEntity } from '@backstage/catalog-model';
|
||||
import { Schema } from 'jsonschema';
|
||||
import { JSONSchema7 } from 'json-schema';
|
||||
import {
|
||||
BackstageCredentials,
|
||||
LoggerService,
|
||||
@@ -175,8 +175,8 @@ export type TemplateAction<
|
||||
examples?: { description: string; example: string }[];
|
||||
supportsDryRun?: boolean;
|
||||
schema?: {
|
||||
input?: Schema;
|
||||
output?: Schema;
|
||||
input?: JSONSchema7;
|
||||
output?: JSONSchema7;
|
||||
};
|
||||
handler: (
|
||||
ctx: ActionContext<TActionInput, TActionOutput, TSchemaType>,
|
||||
|
||||
@@ -21,6 +21,7 @@ import { ScmIntegrationRegistry } from '@backstage/integration';
|
||||
import { TemplateActionOptions } from './createTemplateAction';
|
||||
import zodToJsonSchema from 'zod-to-json-schema';
|
||||
import { z } from 'zod';
|
||||
import { JSONSchema7 } from 'json-schema';
|
||||
|
||||
/**
|
||||
* @public
|
||||
@@ -142,16 +143,18 @@ const isNativeZodSchema = (
|
||||
);
|
||||
};
|
||||
|
||||
export const parseSchemas = (action: TemplateActionOptions<any, any, any>) => {
|
||||
export const parseSchemas = (
|
||||
action: TemplateActionOptions,
|
||||
): { inputSchema?: JSONSchema7; outputSchema?: JSONSchema7 } => {
|
||||
if (!action.schema) {
|
||||
return { inputSchema: undefined, outputSchema: undefined };
|
||||
}
|
||||
|
||||
if (isZodSchema(action.schema.input)) {
|
||||
return {
|
||||
inputSchema: zodToJsonSchema(action.schema.input),
|
||||
inputSchema: zodToJsonSchema(action.schema.input) as JSONSchema7,
|
||||
outputSchema: isZodSchema(action.schema.output)
|
||||
? zodToJsonSchema(action.schema.output)
|
||||
? (zodToJsonSchema(action.schema.output) as JSONSchema7)
|
||||
: undefined,
|
||||
};
|
||||
}
|
||||
@@ -164,15 +167,15 @@ export const parseSchemas = (action: TemplateActionOptions<any, any, any>) => {
|
||||
);
|
||||
|
||||
return {
|
||||
inputSchema: zodToJsonSchema(input),
|
||||
inputSchema: zodToJsonSchema(input) as JSONSchema7,
|
||||
outputSchema: isNativeZodSchema(action.schema.output)
|
||||
? zodToJsonSchema(
|
||||
? (zodToJsonSchema(
|
||||
z.object(
|
||||
Object.fromEntries(
|
||||
Object.entries(action.schema.output).map(([k, v]) => [k, v(z)]),
|
||||
),
|
||||
),
|
||||
)
|
||||
) as JSONSchema7)
|
||||
: undefined,
|
||||
};
|
||||
}
|
||||
|
||||
@@ -7716,7 +7716,7 @@ __metadata:
|
||||
globby: ^11.0.0
|
||||
isbinaryfile: ^5.0.0
|
||||
isolated-vm: ^5.0.1
|
||||
jsonschema: ^1.2.6
|
||||
json-schema: ^0.4.0
|
||||
knex: ^3.0.0
|
||||
lodash: ^4.17.21
|
||||
logform: ^2.3.2
|
||||
@@ -7794,7 +7794,7 @@ __metadata:
|
||||
fs-extra: ^11.2.0
|
||||
globby: ^11.0.0
|
||||
isomorphic-git: ^1.23.0
|
||||
jsonschema: ^1.2.6
|
||||
json-schema: ^0.4.0
|
||||
p-limit: ^3.1.0
|
||||
tar: ^6.1.12
|
||||
winston: ^3.2.1
|
||||
|
||||
Reference in New Issue
Block a user