feat: implementing ActionRegistry service to register distributed actions
Signed-off-by: benjdlambert <ben@blam.sh>
This commit is contained in:
@@ -63,7 +63,8 @@
|
||||
"@types/express": "^4.17.6",
|
||||
"@types/luxon": "^3.0.0",
|
||||
"knex": "^3.0.0",
|
||||
"luxon": "^3.0.0"
|
||||
"luxon": "^3.0.0",
|
||||
"zod": "^3.22.4"
|
||||
},
|
||||
"devDependencies": {
|
||||
"@backstage/backend-test-utils": "workspace:^",
|
||||
|
||||
@@ -0,0 +1,66 @@
|
||||
/*
|
||||
* 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, ZodType } from 'zod';
|
||||
import { LoggerService } from './LoggerService';
|
||||
import { BackstageCredentials } from './AuthService';
|
||||
|
||||
export type ActionsRegistryActionContext<TInputSchema extends ZodType> = {
|
||||
input: z.infer<TInputSchema>;
|
||||
logger: LoggerService;
|
||||
credentials: BackstageCredentials;
|
||||
};
|
||||
|
||||
// todo: opaque type?
|
||||
export type ActionsRegistryAction<
|
||||
TInputSchema extends ZodType,
|
||||
TOutputSchema extends ZodType,
|
||||
> = {
|
||||
id: string;
|
||||
name: string;
|
||||
title: string;
|
||||
description: string;
|
||||
// todo: what about additional metadata?
|
||||
schema?: {
|
||||
input?: TInputSchema;
|
||||
output?: TOutputSchema;
|
||||
};
|
||||
action: (
|
||||
context: ActionsRegistryActionContext<TInputSchema>,
|
||||
) => Promise<TOutputSchema extends ZodType ? z.infer<TOutputSchema> : void>;
|
||||
};
|
||||
|
||||
export type ActionsRegistryActionOptions<
|
||||
TInputSchema extends ZodType,
|
||||
TOutputSchema extends ZodType,
|
||||
> = {
|
||||
name: string;
|
||||
title: string;
|
||||
description: string;
|
||||
// todo: what about additional metadata?
|
||||
schema?: {
|
||||
input?: (zod: typeof z) => TInputSchema;
|
||||
output?: (zod: typeof z) => TOutputSchema;
|
||||
};
|
||||
action: (
|
||||
context: ActionsRegistryActionContext<TInputSchema>,
|
||||
) => Promise<TOutputSchema extends ZodType ? z.infer<TOutputSchema> : void>;
|
||||
};
|
||||
|
||||
export interface ActionsRegistryService {
|
||||
register<TInputSchema extends ZodType, TOutputSchema extends ZodType>(
|
||||
options: ActionsRegistryActionOptions<TInputSchema, TOutputSchema>,
|
||||
): void;
|
||||
}
|
||||
@@ -35,6 +35,21 @@ export namespace coreServices {
|
||||
id: 'core.auth',
|
||||
});
|
||||
|
||||
/**
|
||||
* Service for registering and managing actions.
|
||||
*
|
||||
* See {@link ActionsRegistryService}
|
||||
* and {@link https://backstage.io/docs/backend-system/core-services/actions-registry | the service docs}
|
||||
* for more information.
|
||||
*
|
||||
* @public
|
||||
*/
|
||||
export const actionsRegistry = createServiceRef<
|
||||
import('./ActionsRegistryService').ActionsRegistryService
|
||||
>({
|
||||
id: 'core.actionsRegistry',
|
||||
});
|
||||
|
||||
/**
|
||||
* Authenticated user information retrieval.
|
||||
*
|
||||
|
||||
@@ -14,6 +14,12 @@
|
||||
* limitations under the License.
|
||||
*/
|
||||
|
||||
export type {
|
||||
ActionsRegistryService,
|
||||
ActionsRegistryActionOptions,
|
||||
ActionsRegistryActionContext,
|
||||
ActionsRegistryAction,
|
||||
} from './ActionsRegistryService';
|
||||
export type {
|
||||
AuditorService,
|
||||
AuditorServiceCreateEventOptions,
|
||||
|
||||
Reference in New Issue
Block a user