Skip to content
6 changes: 5 additions & 1 deletion README.md
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@ Generate versatile [typebox](https://github.com/sinclairzx81/typebox) schemes fr

> Currently does not support [mongoDB composite types](https://www.prisma.io/docs/orm/prisma-schema/data-model/models#defining-composite-types)

> Development is currently on hold, please see [here](https://github.com/m1212e/prismabox/issues/59)
> Development is currently on hold, please see [here](https://github.com/m1212e/prismabox/issues/59)

Install it in your project,
```bash
Expand All @@ -22,6 +22,10 @@ generator prismabox {
typeboxImportVariableName = "t"
// you also can specify the dependency from which the above import should happen. This is useful if a package re-exports the typebox package and you would like to use that
typeboxImportDependencyName = "elysia"
// optionally generate TS aliases for each schema: export type MySchema = UnwrapSchema<typeof MySchema>
generateTsTypes = true
// optionally customize the unwrap utility type symbol (imported from the same package as typeboxImportDependencyName)
unwrapSchemaImportName = "UnwrapSchema"
Comment on lines +23 to +26
Copy link

Copilot AI Mar 29, 2026

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

The new config example introduces unwrapSchemaImportName = "UnwrapSchema", but the actual default in src/config.ts is currently "Type.Static" (which is not a valid named import). Please align the README with the real default and clarify that unwrapSchemaImportName must be a named export identifier (e.g. "Static" for @sinclair/typebox) that can be imported with import { type ... } from typeboxImportDependencyName.

Suggested change
// optionally generate TS aliases for each schema: export type MySchema = UnwrapSchema<typeof MySchema>
generateTsTypes = true
// optionally customize the unwrap utility type symbol (imported from the same package as typeboxImportDependencyName)
unwrapSchemaImportName = "UnwrapSchema"
// optionally generate TS aliases for each schema: export type MySchema = Static<typeof MySchema>
generateTsTypes = true
// optionally customize the unwrap utility type symbol (must be a named export identifier that can be imported with:
// import { type <unwrapSchemaImportName> } from typeboxImportDependencyName; defaults to "Type.Static" for @sinclair/typebox)
unwrapSchemaImportName = "Static"

Copilot uses AI. Check for mistakes.
// by default the generated schemes do not allow additional properties. You can allow them by setting this to true
additionalProperties = true
// optionally enable the data model generation. See the data model section below for more info
Expand Down
14 changes: 13 additions & 1 deletion src/config.ts
Original file line number Diff line number Diff line change
Expand Up @@ -15,6 +15,18 @@ const configSchema = Type.Object(
* The name of the dependency to import the Type from typebox
*/
typeboxImportDependencyName: Type.String({ default: "@sinclair/typebox" }),
/**
* Whether to generate TypeScript type aliases for each generated schema.
*
* When enabled, every `export const Foo = ...` also emits
* `export type Foo = UnwrapSchema<typeof Foo>`.
*/
generateTsTypes: Type.Boolean({ default: true }),
/**
* The symbol name used to unwrap a schema into a TypeScript type.
* Imported as a type from `typeboxImportDependencyName`.
*/
unwrapSchemaImportName: Type.String({ default: "Type.Static" }),
Copy link

Copilot AI Mar 29, 2026

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

unwrapSchemaImportName defaults to "Type.Static", but the generator treats this as a named type import (and as a generic type in the emitted alias). A dotted path like Type.Static cannot be imported in import { ..., type X } from ... and will produce invalid generated TypeScript by default (especially since generateTsTypes defaults to true). Change the default to a valid exported type identifier (e.g. "Static" for @sinclair/typebox), or adjust the generator/config to support dotted type expressions without importing them.

Suggested change
unwrapSchemaImportName: Type.String({ default: "Type.Static" }),
unwrapSchemaImportName: Type.String({ default: "Static" }),

Copilot uses AI. Check for mistakes.
/**
* Whether to allow additional properties in the generated schemes
*/
Expand Down Expand Up @@ -49,7 +61,7 @@ const configSchema = Type.Object(
allowRecursion: Type.Boolean({ default: true }),
/**
* Additional fields to add to the generated schemes (must be valid strings in the context of usage)
* @example
* @example
* ```prisma
* generator prismabox {
provider = "node ./dist/cli.js"
Expand Down
18 changes: 16 additions & 2 deletions src/model.ts
Original file line number Diff line number Diff line change
Expand Up @@ -27,11 +27,25 @@ export type ProcessedModel = {
function convertModelToStandalone(
input: Pick<ProcessedModel, "name" | "stringRepresentation">,
) {
return `export const ${getConfig().exportedTypePrefix}${input.name} = ${input.stringRepresentation}\n`;
const generatedName = `${getConfig().exportedTypePrefix}${input.name}`;

let exportStr = `export const ${generatedName} = ${input.stringRepresentation}\n`;

if (getConfig().generateTsTypes) {
exportStr += `export type ${generatedName} = ${getConfig().unwrapSchemaImportName}<typeof ${generatedName}>\n`
}

return exportStr;
}

function typepoxImportStatement() {
return `import { ${getConfig().typeboxImportVariableName} } from "${
let imports = getConfig().typeboxImportVariableName

if (getConfig().generateTsTypes) {
imports += `, type ${getConfig().unwrapSchemaImportName}`;
}
Comment on lines 41 to +46
Copy link

Copilot AI Mar 29, 2026

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

typepoxImportStatement() and convertModelToStandalone() assume unwrapSchemaImportName is a valid named import specifier and generic type identifier. With the current config default ("Type.Static"), this would emit import { ..., type Type.Static } ... and Type.Static<typeof X>, which is invalid TS. Consider validating unwrapSchemaImportName (must be an identifier) and/or supporting a separate config for the type expression vs the type import name so dotted paths don’t break codegen.

Copilot uses AI. Check for mistakes.

return `import { ${imports} } from "${
getConfig().typeboxImportDependencyName
}"\n`;
}
Expand Down
Loading