Skip to content

Commit

Permalink
Separate Zod typing from library (#350)
Browse files Browse the repository at this point in the history
## Summary
<!-- Succinctly describe your change, providing context, what you've
changed, and why. -->

Separates Zod typing requirements from the Zod library itself, hopefully
allowing us to support multiple client versions.

## 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 Bug fix
- [ ] ~~Added unit/integration tests~~ N/A Exists already
- [x] Added changesets if applicable

## Related
<!-- A space for any related links, issues, or PRs. -->
<!-- Linear issues are autolinked. -->
<!-- e.g. - INN-123 -->
<!-- GitHub issues/PRs can be linked using shorthand. -->
<!-- e.g. "- inngest/inngest#123" -->
<!-- Feel free to remove this section if there are no applicable related
links.-->
- Alternative to #336
  • Loading branch information
jpwilliams committed Oct 9, 2023
1 parent b5f0532 commit 933b998
Show file tree
Hide file tree
Showing 4 changed files with 49 additions and 4 deletions.
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 @@ -234,6 +234,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"];

0 comments on commit 933b998

Please sign in to comment.