-
Notifications
You must be signed in to change notification settings - Fork 7
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
Showing
156 changed files
with
3,303 additions
and
3,378 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,4 +1,6 @@ | ||
export * from './getUnionType' | ||
export * from './zod/getUnionType' | ||
export * from './zod/stripOptionalFromZodObject' | ||
export * from './parseReadmeToHtml' | ||
export * from './createZodObjectFromInputSchema' | ||
export * from './parseToApiSchema' | ||
export * from './shared' |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,2 +1,22 @@ | ||
import _ from 'lodash' | ||
|
||
export const is_numeric = (val: unknown): boolean => | ||
typeof val === 'number' && !Number.isNaN(val) | ||
|
||
type RemoveUndefined<T> = { | ||
[K in keyof T]-?: Exclude<T[K], undefined> | ||
} | ||
|
||
/** | ||
* Checks if all values in the object are defined and refines the type. | ||
* @param data - The object to check. | ||
* @returns True if all values are defined; false otherwise. | ||
*/ | ||
export const areAllValuesDefined = <T extends Record<string, unknown>>( | ||
data: T, | ||
): data is RemoveUndefined<T> => { | ||
if (_.isEmpty(data)) { | ||
return false | ||
} | ||
return Object.values(data).every(value => value !== undefined) | ||
} |
File renamed without changes.
File renamed without changes.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,23 @@ | ||
import { z, ZodTypeAny } from 'zod' | ||
|
||
/** | ||
* Removes all optional types from a Zod object schema. | ||
* @param schema - The Zod object schema to process. | ||
* @returns A new Zod object schema with optional types removed. | ||
*/ | ||
export const stripOptionalFromZodObject = <T extends z.ZodObject<any>>( | ||
schema: T, | ||
): z.ZodObject<any> => { | ||
const shape = schema.shape // Get the shape of the Zod object schema | ||
|
||
const strippedShape: Record<string, ZodTypeAny> = Object.fromEntries( | ||
Object.entries(shape).map(([key, value]) => { | ||
if (value instanceof z.ZodOptional) { | ||
return [key, value.unwrap()] // Unwrap optional types | ||
} | ||
return [key, value] | ||
}), | ||
) | ||
|
||
return z.object(strippedShape) // Return a new Zod object schema | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.