@forge/resolver
1.7.11.8.0-next.0
out/index.d.ts~
out/index.d.tsModified+35−1
Index: package/out/index.d.ts
===================================================================
--- package/out/index.d.ts
+++ package/out/index.d.ts
@@ -15,14 +15,48 @@
declare type DefinitionsHandler = (payload: InvokePayload<unknown>, backendRuntimePayload?: Record<string, any>) => Promise<unknown>;
export default class Resolver {
private functions;
constructor();
- define(functionKey: string, cb: ResolverFunction<never, unknown>): this;
+ define(functionKey: string, cb: ResolverFunction<any, any>): this;
+ /**
+ * Defines a resolver with explicit payload and return types.
+ *
+ * The first generic is the payload shape and the second generic is the return type.
+ *
+ * @example
+ * type Payload = { name: string };
+ * type Response = { message: string };
+ * resolver.define<Payload, Response>('greet', ({ payload }) => ({
+ * message: `Hello ${payload.name}`
+ * }));
+ */
+ define<Payload, Result = Response>(functionKey: string, cb: ResolverFunction<Payload, Result>): this;
+ /**
+ * Defines a resolver using the return-only generic form.
+ *
+ * The single type argument is the return type.
+ *
+ * @example
+ * type Response = { message: string };
+ * resolver.define<Response>('greet', () => ({ message: 'ok' }));
+ */
+ define<Result = Response>(functionKey: string, cb: ResolverFunction<any, Result>): this;
private getFunction;
private sanitizeObject;
getDefinitions(): DefinitionsHandler;
}
+/**
+ * Given a type specialising Definitions shared between frontend and backend,
+ * Handlers will return a type for a record of resolver functions that are
+ * needed to implement this on the backend.
+ */
export declare type Handlers<D extends Definitions> = {
[Def in keyof D & string]: ResolverFunction<DefArgument<D, Def>, DefResult<D, Def>>;
};
+/**
+ * Creates resolver definitions corresponding to a given Definitions type.
+ *
+ * @param handlers Resolver functions implementing the definitions
+ * @returns Resolver definitions
+ */
export declare function makeResolver<D extends Definitions>(handlers: Handlers<D>): DefinitionsHandler;
//# sourceMappingURL=index.d.ts.map
\ No newline at end of file