Skip to content

Commit

Permalink
Fix some out-of-date comments and examples (#466)
Browse files Browse the repository at this point in the history
## Summary
<!-- Succinctly describe your change, providing context, what you've
changed, and why. -->

Fix some out-of-date comments and examples.

## Checklist
<!-- Tick these items off as you progress. -->
<!-- If an item isn't applicable, ideally please strikeout the item by
wrapping it in "~~"" and suffix it with "N/A My reason for skipping
this." -->
<!-- e.g. "- [ ] ~~Added tests~~ N/A Only touches docs" -->

- [ ] ~~Added a [docs PR](https://github.com/inngest/website) that
references this PR~~ N/A
- [ ] ~~Added unit/integration tests~~ N/A
- [x] Added changesets if applicable
  • Loading branch information
jpwilliams committed Jan 16, 2024
1 parent c449efe commit ecde5b6
Show file tree
Hide file tree
Showing 7 changed files with 80 additions and 59 deletions.
5 changes: 5 additions & 0 deletions .changeset/smooth-panthers-change.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
---
"inngest": patch
---

Fix some out-of-date comments and examples
6 changes: 3 additions & 3 deletions packages/inngest/etc/inngest.api.md

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

8 changes: 4 additions & 4 deletions packages/inngest/src/components/EventSchemas.ts
Original file line number Diff line number Diff line change
Expand Up @@ -201,7 +201,7 @@ export type Combine<
*
* ```ts
* export const inngest = new Inngest({
* name: "My App",
* id: "my-app",
* schemas: new EventSchemas().fromZod({
* "app/user.created": {
* data: z.object({
Expand Down Expand Up @@ -235,7 +235,7 @@ export class EventSchemas<
*
* ```ts
* export const inngest = new Inngest({
* name: "My App",
* id: "my-app",
* schemas: new EventSchemas().fromRecord<{
* "app/user.created": {
* data: {
Expand Down Expand Up @@ -276,7 +276,7 @@ export class EventSchemas<
* type Events = AccountCreated | AccountDeleted;
*
* export const inngest = new Inngest({
* name: "My App",
* id: "my-app",
* schemas: new EventSchemas().fromUnion<Events>(),
* });
* ```
Expand All @@ -299,7 +299,7 @@ export class EventSchemas<
*
* ```ts
* export const inngest = new Inngest({
* name: "My App",
* id: "my-app",
* schemas: new EventSchemas().fromZod({
* "app/user.created": {
* data: z.object({
Expand Down
103 changes: 59 additions & 44 deletions packages/inngest/src/components/InngestCommHandler.ts
Original file line number Diff line number Diff line change
Expand Up @@ -120,35 +120,31 @@ interface InngestCommHandlerOptions<
functions: readonly InngestFunction.Any[];

/**
* The `handler` is the function your framework requires to handle a
* request. For example, this is most commonly a function that is given a
* `Request` and must return a `Response`.
* The `handler` is the function that will be called with your framework's
* request arguments and returns a set of functions that the SDK will use to
* access various parts of the request, such as the body, headers, and query
* string parameters.
*
* The handler must map out any incoming parameters, then return a
* strictly-typed object to assess what kind of request is being made,
* collecting any relevant data as we go.
* It also defines how to transform a response from the SDK into a response
* that your framework can understand, ensuring headers, status codes, and
* body are all set correctly.
*
* @example
* ```
* return {
* register: () => { ... },
* run: () => { ... },
* view: () => { ... }
* ```ts
* function handler (req: Request, res: Response) {
* return {
* method: () => req.method,
* body: () => req.json(),
* headers: (key) => req.headers.get(key),
* url: () => req.url,
* transformResponse: ({ body, headers, status }) => {
* return new Response(body, { status, headers });
* },
* };
* };
* ```
*
* Every key must be specified and must be a function that either returns
* a strictly-typed payload or `undefined` if the request is not for that
* purpose.
*
* This gives handlers freedom to choose how their platform of choice will
* trigger differing actions, whilst also ensuring all required information
* is given for each request type.
*
* See any existing handler for a full example.
*
* This should never be defined by the user; a {@link ServeHandler} should
* abstract this.
*/
handler: Handler<Input, Output, StreamOutput>;
}
Expand Down Expand Up @@ -177,25 +173,34 @@ const registerResSchema = z.object({
* this class; the exposed `serve` function will - most commonly - create an
* instance of `InngestCommHandler` and then return `instance.createHandler()`.
*
* Two critical parameters required are the `handler` and the `transformRes`
* function. See individual parameter details for more information, or see the
* See individual parameter details for more information, or see the
* source code for an existing handler, e.g.
* {@link https://github.com/inngest/inngest-js/blob/main/src/next.ts}
*
* @example
* ```
* // my-custom-handler.ts
* import { InngestCommHandler, ServeHandler } from "inngest";
* import {
* InngestCommHandler,
* type ServeHandlerOptions,
* } from "./components/InngestCommHandler";
*
* export const serve: ServeHandler = (nameOrInngest, fns, opts) => {
* const handler = new InngestCommHandler(
* "my-custom-handler",
* nameOrInngest,
* fns,
* opts,
* () => { ... },
* () => { ... }
* );
* export const serve = (options: ServeHandlerOptions) => {
* const handler = new InngestCommHandler({
* frameworkName: "my-custom-handler",
* ...options,
* handler: (req: Request) => {
* return {
* body: () => req.json(),
* headers: (key) => req.headers.get(key),
* method: () => req.method,
* url: () => new URL(req.url, `https://${req.headers.get("host") || ""}`),
* transformResponse: ({ body, status, headers }) => {
* return new Response(body, { status, headers });
* },
* };
* },
* });
*
* return handler.createHandler();
* };
Expand Down Expand Up @@ -451,17 +456,27 @@ export class InngestCommHandler<
* @example
* ```
* // my-custom-handler.ts
* import { InngestCommHandler, ServeHandler } from "inngest";
* import {
* InngestCommHandler,
* type ServeHandlerOptions,
* } from "./components/InngestCommHandler";
*
* export const serve: ServeHandler = (nameOrInngest, fns, opts) => {
* const handler = new InngestCommHandler(
* "my-custom-handler",
* nameOrInngest,
* fns,
* opts,
* () => { ... },
* () => { ... }
* );
* export const serve = (options: ServeHandlerOptions) => {
* const handler = new InngestCommHandler({
* frameworkName: "my-custom-handler",
* ...options,
* handler: (req: Request) => {
* return {
* body: () => req.json(),
* headers: (key) => req.headers.get(key),
* method: () => req.method,
* url: () => new URL(req.url, `https://${req.headers.get("host") || ""}`),
* transformResponse: ({ body, status, headers }) => {
* return new Response(body, { status, headers });
* },
* };
* },
* });
*
* return handler.createHandler();
* };
Expand Down
9 changes: 5 additions & 4 deletions packages/inngest/src/components/InngestStepTools.ts
Original file line number Diff line number Diff line change
Expand Up @@ -165,11 +165,12 @@ export const createStepTools = <
*
* @example
* ```ts
* await step.sendEvent("app/user.created", { data: { id: 123 } });
* await step.sendEvent("emit-user-creation", {
* name: "app/user.created",
* data: { id: 123 },
* });
*
* await step.sendEvent({ name: "app/user.created", data: { id: 123 } });
*
* await step.sendEvent([
* await step.sendEvent("emit-user-updates", [
* {
* name: "app/user.created",
* data: { id: 123 },
Expand Down
4 changes: 2 additions & 2 deletions packages/inngest/src/test/functions/handler.ts
Original file line number Diff line number Diff line change
Expand Up @@ -10,9 +10,9 @@ import { InngestCommHandler, type ServeHandlerOptions } from "inngest";
* @example
* ```ts
* import { serve } from "./my-handler";
* import fns from "~/inngest";
* import { client, functions } from "~/inngest";
*
* export const handler = serve("My App", fns);
* export const handler = serve({ client, functions });
* ```
*
* We export a `serve` function that uses the `ServeHandler` type to match the
Expand Down
4 changes: 2 additions & 2 deletions packages/inngest/src/types.ts
Original file line number Diff line number Diff line change
Expand Up @@ -35,7 +35,7 @@ import { type Logger } from "./middleware/logger";
* import { EventSchemas, Inngest, type GetEvents } from "inngest";
*
* export const inngest = new Inngest({
* name: "Example App",
* id: "example-app",
* schemas: new EventSchemas().fromRecord<{
* "app/user.created": { data: { userId: string } };
* }>(),
Expand Down Expand Up @@ -544,7 +544,7 @@ export interface ClientOptions {
*
* ```ts
* export const inngest = new Inngest({
* name: "My App",
* id: "my-app",
* schemas: new EventSchemas().fromZod({
* "app/user.created": {
* data: z.object({
Expand Down

0 comments on commit ecde5b6

Please sign in to comment.