Skip to content

Commit

Permalink
feat(zui): Typescript transforms updates, remove all dependencies (#340)
Browse files Browse the repository at this point in the history
  • Loading branch information
charlescatta authored Jun 26, 2024
1 parent cf1ff88 commit 6c9af87
Show file tree
Hide file tree
Showing 21 changed files with 223 additions and 2,457 deletions.
5 changes: 1 addition & 4 deletions zui/package.json
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
{
"name": "@bpinternal/zui",
"version": "0.8.12",
"version": "0.9.0",
"description": "An extension of Zod for working nicely with UIs and JSON Schemas",
"type": "module",
"source": "./src/index.ts",
Expand Down Expand Up @@ -31,7 +31,6 @@
"@types/benchmark": "^2.1.5",
"@types/jest": "^29.5.12",
"@types/json-schema": "^7.0.15",
"@types/lodash": "^4.17.0",
"@types/node": "^20.12.6",
"@types/react": "^18.2.48",
"@vitejs/plugin-react-swc": "^3.6.0",
Expand All @@ -52,8 +51,6 @@
"vitest": "1.5.2"
},
"dependencies": {
"@apidevtools/json-schema-ref-parser": "^11.5.5",
"lodash": "^4.17.21"
},
"peerDependencies": {
"react": "^18.2.0"
Expand Down
43 changes: 0 additions & 43 deletions zui/pnpm-lock.yaml

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

5 changes: 0 additions & 5 deletions zui/src/index.ts
Original file line number Diff line number Diff line change
@@ -1,7 +1,6 @@
import { jsonSchemaToZui } from './transforms/json-schema-to-zui'
import { zuiToJsonSchema } from './transforms/zui-to-json-schema'
import { objectToZui } from './transforms/object-to-zui'
import { toTypescriptTypings } from './transforms/zui-to-typescript'
import {
toTypescript,
UntitledDeclarationError,
Expand Down Expand Up @@ -29,10 +28,6 @@ export const transforms = {
zuiToJsonSchema,
objectToZui,
toTypescript,
/**
* @deprecated use toTypescript instead
*/
zuiToTypescriptTypings: toTypescriptTypings,
}

export { UntitledDeclarationError, type TypescriptGenerationOptions }
8 changes: 3 additions & 5 deletions zui/src/transforms/zui-to-typescript-next/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -56,7 +56,7 @@ class Declaration {

export type TypescriptGenerationOptions = {
declaration?: boolean
formatters?: ((typing: string) => string)[]
formatter?: (typing: string) => string
}

type SchemaTypes = z.Schema | KeyValue | FnParameters | Declaration | null
Expand Down Expand Up @@ -84,10 +84,8 @@ export function toTypescript(schema: z.Schema, options?: TypescriptGenerationOpt

let dts = sUnwrapZod(wrappedSchema, { ...options })

if (options.formatters?.length) {
for (const formatter of options.formatters) {
dts = formatter(dts)
}
if (options.formatter) {
dts = options.formatter(dts)
}

return dts
Expand Down
7 changes: 4 additions & 3 deletions zui/src/transforms/zui-to-typescript-next/utils.ts
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
import _ from 'lodash'
import { camelCase, deburr } from '../../ui/utils'

export function escapeString(str: string) {
if (typeof str !== 'string') {
return ''
Expand Down Expand Up @@ -35,12 +36,12 @@ export const getMultilineComment = (description?: string) => {
}

export const toValidFunctionName = (str: string) => {
let name = _.deburr(str)
let name = deburr(str)
name = name.replace(/[^a-zA-Z0-9_$]/g, '')

if (!/^[a-zA-Z_$]/.test(name)) {
name = `_${name}`
}

return _.camelCase(name)
return camelCase(name)
}
Loading

0 comments on commit 6c9af87

Please sign in to comment.