Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Separate Zod typing from library #350

Merged
merged 5 commits into from
Oct 9, 2023
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
5 changes: 5 additions & 0 deletions .changeset/wicked-ties-laugh.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
---
"inngest": patch
---

Separate Zod typing from library, enabling minor-agnostic versioning support
6 changes: 4 additions & 2 deletions packages/inngest/etc/inngest.api.md
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@

import { Jsonify } from 'type-fest';
import { Simplify } from 'type-fest';
import { z } from 'zod';
import { z as z_2 } from 'zod';

// @public
export interface ClientOptions {
Expand Down Expand Up @@ -78,7 +78,7 @@ export type FailureEventPayload<P extends EventPayload = EventPayload> = {
data: {
function_id: string;
run_id: string;
error: z.output<typeof failureEventErrorSchema>;
error: z_2.output<typeof failureEventErrorSchema>;
event: P;
};
};
Expand Down Expand Up @@ -230,6 +230,8 @@ export enum internalEvents {
// @internal
export type IsStringLiteral<T extends string> = string extends T ? false : true;

// Warning: (ae-forgotten-export) The symbol "z" needs to be exported by the entry point index.d.ts
//
// @public
export type LiteralZodEventSchema = z.ZodObject<{
name: z.ZodLiteral<string>;
Expand Down
4 changes: 2 additions & 2 deletions packages/inngest/src/components/EventSchemas.ts
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
import { type Simplify } from "type-fest";
import { type z } from "zod";
import { type IsEmptyObject, type IsStringLiteral } from "../helpers/types";
import type * as z from "../helpers/validators/zod";
import { type EventPayload } from "../types";

/**
Expand Down Expand Up @@ -104,7 +104,7 @@ export type PickLiterals<T> = {
*
* @public
*/
export type GetName<T> = T extends z.ZodObject<infer U extends z.ZodRawShape>
export type GetName<T> = T extends z.ZodObject<infer U>
? U extends { name: z.ZodLiteral<infer S extends string> }
? S
: never
Expand Down
38 changes: 38 additions & 0 deletions packages/inngest/src/helpers/validators/zod.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,38 @@
/* eslint-disable @typescript-eslint/no-explicit-any */
/**
* Shim for Zod types to ensure hopeful compatibility between minor versions;
* let developers the latest version of Zod without having to have Inngest match
* the same version.
*
* Feels weird to be using internal properties like this, but types break across
* minors anyway, so at least with this we rely on fewer fields staying the
* same.
*/
export type ZodLiteral<TValue = any> = {
get value(): TValue;
_def: {
typeName: "ZodLiteral";
};
};

export type ZodTypeAny = {
_type: any;
_output: any;
_input: any;
_def: any;
};

export type ZodObject<TShape = { [k: string]: ZodTypeAny }> = {
get shape(): TShape;
_def: {
typeName: "ZodObject";
};
};

export type AnyZodObject = ZodObject<any>;

export type ZodAny = {
_any: true;
};

export type infer<T extends ZodTypeAny> = T["_output"];