mirror of
https://github.com/Start9Labs/start-sdk.git
synced 2026-04-01 21:13:11 +00:00
chore: Getting in the action builder
This commit is contained in:
43
lib/actions/createAction.ts
Normal file
43
lib/actions/createAction.ts
Normal file
@@ -0,0 +1,43 @@
|
||||
import {
|
||||
ActionMetaData,
|
||||
ActionResult,
|
||||
Effects,
|
||||
ExportedAction,
|
||||
} from "../types";
|
||||
import { Utils, utils } from "../util";
|
||||
|
||||
export class CreatedAction<WrapperData, Input> {
|
||||
private constructor(
|
||||
readonly metaData: ActionMetaData,
|
||||
readonly fn: (options: {
|
||||
effects: Effects;
|
||||
utils: Utils<WrapperData>;
|
||||
input: Input;
|
||||
}) => Promise<ActionResult>,
|
||||
) {}
|
||||
|
||||
static of<WrapperData, Input>(
|
||||
metaData: ActionMetaData,
|
||||
fn: (options: {
|
||||
effects: Effects;
|
||||
utils: Utils<WrapperData>;
|
||||
input: Input;
|
||||
}) => Promise<ActionResult>,
|
||||
) {
|
||||
return new CreatedAction<WrapperData, Input>(metaData, fn);
|
||||
}
|
||||
|
||||
exportedAction: ExportedAction = ({ effects, input }) => {
|
||||
return this.fn({
|
||||
effects,
|
||||
utils: utils<WrapperData>(effects),
|
||||
input: input as Input,
|
||||
});
|
||||
};
|
||||
|
||||
async exportAction(effects: Effects) {
|
||||
await effects.exportAction(this.metaData);
|
||||
}
|
||||
}
|
||||
|
||||
export const createAction = CreatedAction.of;
|
||||
Reference in New Issue
Block a user