### Install Companion Agent Skill Source: https://github.com/arthurfiorette/prisma-json-types-generator/blob/main/README.md Install the companion agent skill for prisma-json-types-generator using npx. ```bash npx skills add arthurfiorette/prisma-json-types-generator ``` -------------------------------- ### Install prisma-json-types-generator with pnpm Source: https://github.com/arthurfiorette/prisma-json-types-generator/blob/main/skills/prisma-json-types-generator/references/setup.md Install the package as a development dependency using pnpm. ```bash pnpm add -D prisma-json-types-generator ``` -------------------------------- ### Install prisma-json-types-generator with npm Source: https://github.com/arthurfiorette/prisma-json-types-generator/blob/main/skills/prisma-json-types-generator/references/setup.md Install the package as a development dependency using npm. ```bash npm install -D prisma-json-types-generator ``` -------------------------------- ### Install prisma-json-types-generator with yarn Source: https://github.com/arthurfiorette/prisma-json-types-generator/blob/main/skills/prisma-json-types-generator/references/setup.md Install the package as a development dependency using yarn. ```bash yarn add -D prisma-json-types-generator ``` -------------------------------- ### Prisma Generator Example Usage Source: https://github.com/arthurfiorette/prisma-json-types-generator/blob/main/_autodocs/api-reference-core-generator.md Illustrates how to configure and run the Prisma JSON Types Generator within a `schema.prisma` file. This setup is automatically invoked by the Prisma generator system. ```prisma // This is automatically called by the Prisma generator system // when using generatorHandler from @prisma/generator-helper // In schema.prisma: // generator json { // provider = "prisma-json-types-generator" // namespace = "PrismaJson" // } // Then run: // npx prisma generate ``` -------------------------------- ### Install Command for Version Compatibility Source: https://github.com/arthurfiorette/prisma-json-types-generator/blob/main/_autodocs/errors.md Command to install compatible versions of Prisma and TypeScript to resolve version mismatch warnings. ```bash npm install --save-dev prisma@^7.8.0 typescript@^6.0.3 ``` -------------------------------- ### Basic Generator Setup Source: https://github.com/arthurfiorette/prisma-json-types-generator/blob/main/_autodocs/configuration.md This is the most basic configuration, using all default settings. It expects types to be generated within the `PrismaJson` namespace. ```prisma generator json { provider = "prisma-json-types-generator" } ``` -------------------------------- ### Minimal Prisma Generator Setup Source: https://github.com/arthurfiorette/prisma-json-types-generator/blob/main/skills/prisma-json-types-generator/references/setup.md Configure the minimal generator setup in your Prisma schema file. This includes the 'client' generator and the 'json' generator from prisma-json-types-generator. ```prisma generator client { provider = "prisma-client" } generator json { provider = "prisma-json-types-generator" namespace = "PrismaJson" } ``` -------------------------------- ### Example PrismaJsonTypesGeneratorConfig Source: https://github.com/arthurfiorette/prisma-json-types-generator/blob/main/_autodocs/api-reference-utilities.md An example of how to define a configuration object using the PrismaJsonTypesGeneratorConfig interface. This shows default values for optional properties. ```typescript const config: PrismaJsonTypesGeneratorConfig = { namespace: 'PrismaJson', clientOutput: undefined, useType: undefined, allowAny: false } ``` -------------------------------- ### Prisma Generator Manifest Example Output Source: https://github.com/arthurfiorette/prisma-json-types-generator/blob/main/_autodocs/api-reference-core-generator.md An example of the metadata object returned by the `onManifest` function, which includes version information, default output directory, and a user-friendly name for the generator. ```typescript { version: "5.1.0", defaultOutput: "./", prettyName: "Prisma Json Types Generator" } ``` -------------------------------- ### PrismaEntity Example Usage Source: https://github.com/arthurfiorette/prisma-json-types-generator/blob/main/_autodocs/api-reference-type-parsing.md Illustrates how to instantiate a PrismaEntity object. Shows the expected format for name, type, fields, and regexps properties. ```typescript const entity: PrismaEntity = { name: 'User', type: 'model', fields: [ { name: 'id', type: 'Int', ... }, { name: 'profile', type: 'Json', documentation: '/// [UserProfile]', ... } ], regexps: [ /^UserGroup$/, /^UserGroupByOutputType$/ // ... more patterns ] } ``` -------------------------------- ### Example Usage of parseConfig Source: https://github.com/arthurfiorette/prisma-json-types-generator/blob/main/_autodocs/api-reference-utilities.md Demonstrates how the parseConfig function processes raw configuration from schema.prisma. It shows the conversion of string values to their appropriate types and the application of default values. ```typescript // From schema.prisma: // generator json { // provider = "prisma-json-types-generator" // namespace = "MyTypes" // allowAny = "true" // } const rawConfig = { provider: 'prisma-json-types-generator', namespace: 'MyTypes', allowAny: 'true' }; const parsed = parseConfig(rawConfig); // Result: { // namespace: 'MyTypes', // clientOutput: undefined, // useType: undefined, // allowAny: true // } ``` -------------------------------- ### Parse Type Syntax Examples Source: https://github.com/arthurfiorette/prisma-json-types-generator/blob/main/_autodocs/types.md Demonstrates how to use the `parseTypeSyntax` function with different input formats to extract type information. ```typescript parseTypeSyntax('[UserProfile]') // { literal: false, type: 'UserProfile' } parseTypeSyntax('!["draft" | "published"]') // { literal: true, type: '"draft" | "published"' } parseTypeSyntax('[{ width: number }]') // { literal: false, type: '{ width: number }' } ``` -------------------------------- ### Schema Configuration for No Client Generator Found Source: https://github.com/arthurfiorette/prisma-json-types-generator/blob/main/_autodocs/errors.md This example demonstrates the correct schema.prisma configuration when the client generator is not found. It shows the placement of the client generator and the json generator. ```prisma generator client { provider = "prisma-client-js" // or "prisma-client" for v7+ } generator json { provider = "prisma-json-types-generator" } ``` -------------------------------- ### Prisma Schema Configuration Example Source: https://github.com/arthurfiorette/prisma-json-types-generator/blob/main/_autodocs/architecture-overview.md Example of how to configure the Prisma schema to use the generator and define custom types for JSON fields using type comments or inline type literals. ```prisma generator { provider = "prisma-json-types-generator" } model User { id Int @id profile /// [UserProfile] ← marks Json field with custom type settings /// ![Type] ← inline type literal syntax } ``` -------------------------------- ### Client Discovery Process Source: https://github.com/arthurfiorette/prisma-json-types-generator/blob/main/_autodocs/architecture-overview.md Shows the flow for discovering Prisma client generators and extracting their output directories. This is crucial for multi-client setups. ```plaintext otherGenerators[] → findPrismaClientGenerators() → GeneratorWithOutput[] ↓ Locates prisma-client-js or prisma-client Extracts output directory ``` -------------------------------- ### Generator Configuration Example Source: https://github.com/arthurfiorette/prisma-json-types-generator/blob/main/_autodocs/architecture-overview.md Illustrates the configuration object structure parsed by the generator. This configuration influences how JSON types are handled. ```plaintext Generator Config → parseConfig() → PrismaJsonTypesGeneratorConfig { namespace: "PrismaJson", allowAny: false, clientOutput: undefined, useType: undefined } ``` -------------------------------- ### Prisma Schema Example with JSON and Array Fields Source: https://github.com/arthurfiorette/prisma-json-types-generator/blob/main/skills/prisma-json-types-generator/references/setup.md Demonstrates how to define models with Json, Json[], String, and String[] fields using specific AST comments for type generation. ```prisma model Product { /// [ProductMeta] meta Json? /// [Tag] tags Json[] /// !['physical' | 'digital'] kind String /// [StringArrayType] labels String[] } ``` -------------------------------- ### Create TextDiff Example Source: https://github.com/arthurfiorette/prisma-json-types-generator/blob/main/_autodocs/types.md Illustrates how to create a `TextDiff` object to specify a text replacement within a larger content. ```typescript const diff: TextDiff = { start: 150, end: 165, text: 'CustomType' }; // Replaces characters 150-164 (15 chars) with 'CustomType' ``` -------------------------------- ### Example Usage of applyTextChanges Source: https://github.com/arthurfiorette/prisma-json-types-generator/blob/main/_autodocs/api-reference-utilities.md Demonstrates how to use the applyTextChanges function with multiple replacements. Note that change positions refer to the original content. ```typescript const content = 'Hello World Foo Bar'; const changes: TextDiff[] = [ { start: 6, end: 11, text: 'JavaScript' }, // Replace 'World' { start: 12, end: 15, text: 'Type' } // Replace 'Foo' ]; const result = applyTextChanges(content, changes); // Result: 'Hello JavaScript Type Bar' // Note: positions refer to original content, changes are sorted and applied ``` -------------------------------- ### Prisma Client Usage with Typed JSON Source: https://github.com/arthurfiorette/prisma-json-types-generator/blob/main/_autodocs/architecture-overview.md Demonstrates how to use the Prisma client with JSON fields that have been type-safely enhanced by the generator. This example shows a typical create operation. ```typescript await prisma.user.create({ data: { profile: { /* typed as UserProfile */ } } }) ``` -------------------------------- ### Example Usage of handlePrismaModule Source: https://github.com/arthurfiorette/prisma-json-types-generator/blob/main/_autodocs/api-reference-handlers.md Demonstrates how to use handlePrismaModule within an onGenerate function. It iterates through module declarations and calls handlePrismaModule for the Prisma module. ```typescript // Inside onGenerate: const tsSource = ts.createSourceFile(...); tsSource.forEachChild((child) => { if (child.kind === ts.SyntaxKind.ModuleDeclaration) { handlePrismaModule( child as ts.ModuleDeclaration, writer, modelMap, knownNoOps, typeToNameMap, config ); } }); ``` -------------------------------- ### Statement Processing Example Source: https://github.com/arthurfiorette/prisma-json-types-generator/blob/main/_autodocs/api-reference-handlers.md Demonstrates how handleStatement processes different types of statements within the Prisma namespace, routing payload types to handleModelPayload and others to replaceObject. ```typescript // Given these statements in Prisma namespace: // type $UserPayload = { ... } // type UserCreateInput = { ... } // handleStatement will: // 1. For $UserPayload: call handleModelPayload() // 2. For UserCreateInput: call replaceObject() ``` -------------------------------- ### Get Namespace Prelude Source: https://github.com/arthurfiorette/prisma-json-types-generator/blob/main/_autodocs/api-reference-declaration-writer.md Reads and formats the namespace prelude template. Use this to generate the initial structure for your type definitions, including necessary imports and global namespace declarations. ```typescript async function getNamespacePrelude({ namespace, isNewClient, dotExt }: { namespace: string isNewClient: boolean dotExt: string }): Promise ``` ```typescript const prelude = await getNamespacePrelude({ namespace: 'PrismaJson', isNewClient: true, dotExt: '.js' }); // Result includes: // import * as Prisma from './internal/prismaNamespace.js'; // declare global { // namespace PrismaJson { ... } // } ``` -------------------------------- ### Catching File Not Found Error Source: https://github.com/arthurfiorette/prisma-json-types-generator/blob/main/_autodocs/errors.md Example of how to catch and handle a 'File Not Found' error, accessing the filepath associated with the error. ```typescript try { await writer.load(); } catch (error) { if (error instanceof PrismaJsonTypesGeneratorError) { console.error(`Declaration file not found at: ${error.filepath}`); } } ``` -------------------------------- ### DeclarationWriter Usage Example Source: https://github.com/arthurfiorette/prisma-json-types-generator/blob/main/_autodocs/api-reference-declaration-writer.md Demonstrates how to use the DeclarationWriter to load, parse, modify, and save TypeScript content. This pattern is useful for programmatically generating or transforming declaration files. ```typescript async function processFile(filePath: string, config: PrismaJsonTypesGeneratorConfig) { const writer = new DeclarationWriter( filePath, { namespace: config.namespace }, false, 'js' ); // Load the file await writer.load(); // Parse and make changes const ast = ts.createSourceFile( writer.filepath, writer.content, ts.ScriptTarget.ESNext, true, ts.ScriptKind.TS ); // ... traverse AST and find types to replace ... // Stack changes writer.replace(100, 150, 'CustomType'); writer.replace(200, 250, 'AnotherType'); // Write everything at once await writer.save(); } ``` -------------------------------- ### Example Usage of extractPrismaModels Source: https://github.com/arthurfiorette/prisma-json-types-generator/blob/main/_autodocs/types.md Demonstrates how to use the results from `extractPrismaModels` to retrieve model names, entity definitions, and check for no-operation types. ```typescript const { typeToNameMap, modelMap, knownNoOps } = extractPrismaModels(dmmf); const modelName = typeToNameMap.get('UserCreateInput'); // Returns: 'User' const entity = modelMap.get('User'); // Returns: PrismaEntity const skip = knownNoOps.has('Post'); // Returns: true/false ``` -------------------------------- ### Prisma Payload Structure Example Source: https://github.com/arthurfiorette/prisma-json-types-generator/blob/main/_autodocs/api-reference-handlers.md Illustrates the nested structure of Prisma's $Payload type, highlighting the 'scalars' field containing model fields. ```typescript type $UserPayload = { name: string scalars: { id: number profile: JsonValue // This is what we replace } objects: { ... } } ``` ```typescript type $UserPayload = { scalars: $Extensions.GetResult<{ ... }, ...> } ``` -------------------------------- ### Consumer Code Error Handling Source: https://github.com/arthurfiorette/prisma-json-types-generator/blob/main/_autodocs/errors.md Example of how consumer code should handle runtime errors from Prisma Client after generation. Generator errors are compile-time and do not reach this catch block. ```typescript import { PrismaJsonTypesGeneratorError } from 'prisma-json-types-generator'; try { // Use generated Prisma client const user = await prisma.user.create({ data: { profile: { theme: 'dark' } // Must match typed schema } }); } catch (error) { // Generator errors don't reach here (compile-time only) // Catch runtime errors from Prisma if (error instanceof Prisma.PrismaClientKnownRequestError) { console.error('Database error:', error); } } ``` -------------------------------- ### Update User Profile with Typed JSON Source: https://github.com/arthurfiorette/prisma-json-types-generator/blob/main/README.md Example of updating a user's profile using PrismaClient. The `profile` field is now strongly typed as `UserProfile` after running `npx prisma generate`. ```typescript import { PrismaClient } from '@prisma/client'; const prisma = new PrismaClient(); async function updateUserProfile() { const user = await prisma.user.update({ where: { id: 1 }, data: { profile: { theme: 'dark' // twitterHandle is optional } } }); // user.profile is now fully typed as UserProfile! console.log(user.profile.theme); // 'dark' } ``` -------------------------------- ### Run Prisma Generate Command Source: https://github.com/arthurfiorette/prisma-json-types-generator/blob/main/skills/prisma-json-types-generator/references/setup.md After setting up the generator in your schema, run this command to generate the Prisma client and apply the types. ```bash npx prisma generate ``` -------------------------------- ### Simple JSON Field Transformation Source: https://github.com/arthurfiorette/prisma-json-types-generator/blob/main/_autodocs/api-reference-type-parsing.md Example of transforming a basic 'JsonValue' field to a custom type. ```typescript // Simple JSON field findNewSignature('JsonValue', 'PrismaJson.UserProfile', 'User', 'profile') ``` -------------------------------- ### Array Field Transformation Source: https://github.com/arthurfiorette/prisma-json-types-generator/blob/main/_autodocs/api-reference-type-parsing.md Example of transforming an array field like 'InputJsonValue[]' to a custom type array. ```typescript // Array field findNewSignature('InputJsonValue[]', 'PrismaJson.Tag', 'Product', 'tags') ``` -------------------------------- ### Throwing a Custom Error with Context Source: https://github.com/arthurfiorette/prisma-json-types-generator/blob/main/_autodocs/api-reference-utilities.md Example of how to throw a `PrismaJsonTypesGeneratorError` with a specific message and additional context data for debugging. ```typescript throw new PrismaJsonTypesGeneratorError( 'Could not find signature type', { type: 'User', field: 'profile', signature: 'JsonValue' } ); // Error will have properties: // - message: 'Could not find signature type' // - type: 'User' // - field: 'profile' // - signature: 'JsonValue' ``` -------------------------------- ### Nullable Field Transformation Source: https://github.com/arthurfiorette/prisma-json-types-generator/blob/main/_autodocs/api-reference-type-parsing.md Example of transforming a nullable 'JsonValue | null' field to a custom type with nullability preserved. ```typescript // Nullable field findNewSignature('JsonValue | null', 'PrismaJson.Status', 'Post', 'status') ``` -------------------------------- ### Prisma Generator Entry Point Source: https://github.com/arthurfiorette/prisma-json-types-generator/blob/main/_autodocs/README.md This file serves as the entry point for the Prisma generator system. ```typescript src/ generator.ts [Entry point for Prisma system] ``` -------------------------------- ### Configure Client Output Path Source: https://github.com/arthurfiorette/prisma-json-types-generator/blob/main/skills/prisma-json-types-generator/references/setup.md Specify a custom output path for the generated Prisma client. Use this when auto-detection is insufficient. ```prisma generator json { provider = "prisma-json-types-generator" clientOutput = "../generated/prisma" } ``` -------------------------------- ### Define TextDiff Interface Source: https://github.com/arthurfiorette/prisma-json-types-generator/blob/main/_autodocs/types.md Defines the structure for representing text changes, including start and end positions and the replacement text. ```typescript interface TextDiff { start: number end: number text: string } ``` -------------------------------- ### Schema Configuration for Client Output Not Found Source: https://github.com/arthurfiorette/prisma-json-types-generator/blob/main/_autodocs/errors.md This snippet illustrates the required schema.prisma configuration when the client output path is not found. It specifies the 'output' path for the client generator. ```prisma generator client { provider = "prisma-client-js" output = "./node_modules/@prisma/client" // or default location } ``` -------------------------------- ### Declare Untyped JsonMap Source: https://github.com/arthurfiorette/prisma-json-types-generator/blob/main/_autodocs/configuration.md Use `useType` to start with untyped JSON fields. This declaration sets up the global namespace for Prisma JSON types. ```typescript declare global { namespace PrismaJson { type JsonMap = { [K: string]: unknown } } } ``` -------------------------------- ### load() Source: https://github.com/arthurfiorette/prisma-json-types-generator/blob/main/_autodocs/api-reference-declaration-writer.md Reads the declaration file from disk into the `content` property. This method must be called before any modifications can be made. It will throw an error if the file does not exist or if changes have already been stacked. ```APIDOC ## load() ### Description Reads the declaration file from disk into the `content` property. Must be called before any modifications. Throws if the file doesn't exist or if changes have already been stacked. ### Method `async load(): Promise` ### Parameters None ### Return Type Promise that resolves when file is loaded ### Throws - `PrismaJsonTypesGeneratorError` — if file doesn't exist or already has pending changes ### Example ```typescript const writer = new DeclarationWriter( '/path/to/index.d.ts', { namespace: 'PrismaJson' }, false, undefined ); await writer.load(); console.log(writer.content.length); // length of loaded file ``` ``` -------------------------------- ### Apply Text Changes to Content Source: https://github.com/arthurfiorette/prisma-json-types-generator/blob/main/_autodocs/index.md Applies a series of text replacements to a string content efficiently, based on provided start, end, and text definitions. ```typescript interface TextDiff { start: number end: number text: string } function applyTextChanges(content: string, changes: TextDiff[]): string // Applies multiple text replacements efficiently ``` -------------------------------- ### Minimal Prisma Schema for Testing Source: https://github.com/arthurfiorette/prisma-json-types-generator/blob/main/_autodocs/errors.md Create a minimal `schema.prisma` file to isolate issues. This helps in identifying if the problem lies within your schema definition or the generator's processing. ```prisma datasource db { provider = "sqlite" url = "file:./test.db" } generator client { provider = "prisma-client-js" } generator json { provider = "prisma-json-types-generator" } model Test { id Int @id /// ![1 | 2 | 3] status Int } ``` -------------------------------- ### Prisma Namespace Entry Point Source: https://github.com/arthurfiorette/prisma-json-types-generator/blob/main/_autodocs/README.md Defines the entry point for the Prisma namespace. ```typescript src/handler/ module.ts [Prisma namespace entry point] ``` -------------------------------- ### DeclarationWriter Constructor Source: https://github.com/arthurfiorette/prisma-json-types-generator/blob/main/_autodocs/api-reference-declaration-writer.md Initializes a new instance of the DeclarationWriter class. It requires the file path, configuration options including the namespace, a boolean indicating multi-file mode, and an optional import file extension. ```APIDOC ## Class: DeclarationWriter ### Constructor ```typescript constructor( readonly filepath: string, private readonly options: Pick, readonly multifile: boolean, private readonly importFileExtension: string | undefined ) ``` ### Constructor Parameters #### Path Parameters - **filepath** (string) - Required - Absolute path to the declaration file (typically `index.d.ts` or a model file path) - **options** ({ namespace: string }) - Required - Configuration object containing the namespace name where custom types are defined - **multifile** (boolean) - Required - Whether this file is part of a multi-file declaration structure (Prisma v7+) - **importFileExtension** (string | undefined) - Optional - File extension for imports (e.g., "js", "ts"). Affects import statement generation in templates ``` -------------------------------- ### Source Path Utility Source: https://github.com/arthurfiorette/prisma-json-types-generator/blob/main/_autodocs/README.md Locates declaration files within the project. ```typescript src/util/ source-path.ts [Locate declaration files] ``` -------------------------------- ### Enum Filter Transformation Source: https://github.com/arthurfiorette/prisma-json-types-generator/blob/main/_autodocs/api-reference-type-parsing.md Example of transforming a string filter pattern ('StringFilter<"Model"> | string') to a custom typed filter, including namespace and replacement. ```typescript // Enum filter findNewSignature( 'StringFilter<"Post"> | string', 'PrismaJson.Status', 'Post', 'status', true, true, 'PJTG.' ) ``` -------------------------------- ### template() Source: https://github.com/arthurfiorette/prisma-json-types-generator/blob/main/_autodocs/api-reference-declaration-writer.md Generates the template header that will be prepended to the file. This header includes imports for the namespace and type definitions. It adapts based on whether multi-file or single-file mode is used. ```APIDOC ## template() ### Description Generates the template header that will be prepended to the file. The header includes imports for the namespace and type definitions. For multi-file mode, imports from the `pjtg.ts` file; for single-file mode, includes inline namespace declarations. ### Method `async template(): Promise` ### Parameters None ### Return Type Promise resolving to the template header string ### Implementation Detail Preserves leading comments (like `@ts-nocheck`) by finding the first non-comment code and inserting the header after it. ``` -------------------------------- ### Monorepo Client Configuration Source: https://github.com/arthurfiorette/prisma-json-types-generator/blob/main/_autodocs/index.md Specify `clientOutput` to manage multiple clients within a monorepo. This directs the generator to the correct Prisma client output path. ```prisma generator json { provider = "prisma-json-types-generator" clientOutput = "../../packages/database/node_modules/@prisma/client" } ``` -------------------------------- ### Find First Code Index in Source Source: https://github.com/arthurfiorette/prisma-json-types-generator/blob/main/_autodocs/index.md Finds the starting index of the first non-comment code character within a given source string. This is useful for parsing code content. ```typescript function findFirstCodeIndex(source: string): number ``` -------------------------------- ### Create Type: Multi-line Documentation Parsing Source: https://github.com/arthurfiorette/prisma-json-types-generator/blob/main/_autodocs/api-reference-type-parsing.md Parses multi-line descriptions, extracting the first valid type annotation found, even if it's not on the first line. ```typescript createType(`Some description [UserProfile] More text`, { namespace: 'PrismaJson' }) // Returns: 'PrismaJson.UserProfile' ``` -------------------------------- ### Legacy Codebase Migration Configuration Source: https://github.com/arthurfiorette/prisma-json-types-generator/blob/main/_autodocs/configuration.md Enables gradual migration for legacy codebases by treating untyped fields as `any`. This setting allows for a smoother transition when integrating the generator. ```prisma generator json { provider = "prisma-json-types-generator" namespace = "PrismaJson" allowAny = true } ``` -------------------------------- ### Inspect Generated Files Source: https://github.com/arthurfiorette/prisma-json-types-generator/blob/main/_autodocs/errors.md After encountering errors, check the generated files for partial modifications or unexpected content. Use `cat` and `grep` to search for specific patterns or `head` to view the beginning of the file. ```bash # Check if types were partially modified cat node_modules/.prisma/client/index.d.ts | grep "PrismaJson" ``` ```bash # Verify namespace template was added head -20 node_modules/.prisma/client/index.d.ts ``` -------------------------------- ### buildTypesFilePath Source: https://github.com/arthurfiorette/prisma-json-types-generator/blob/main/_autodocs/api-reference-utilities.md Determines the full path to the Prisma Client declaration file (`index.d.ts` or equivalent). It handles various output directory structures and allows for custom overrides. ```APIDOC ## buildTypesFilePath() ### Description Determines the full path to the Prisma Client declaration file (`index.d.ts` or equivalent). Handles various output directory structures including monorepos and different package manager layouts (npm, yarn, pnpm). ### Parameters #### Path Parameters - **clientOutput** (string) - Required - The output directory from Prisma client generator config - **overrideTarget** (string) - Optional - Custom path to override auto-detection - **schemaTarget** (string) - Optional - Full path to schema.prisma (used for relative path resolution) ### Return Type `string` — Absolute path to the declaration file ### Example ```typescript // Standard npm/pnpm setup buildTypesFilePath('./node_modules/.prisma/client') // Returns: '/path/to/node_modules/.prisma/client/index.d.ts' // Custom output buildTypesFilePath('./custom', '../types/prisma.d.ts', '/project/schema.prisma') // Returns: '/project/types/prisma.d.ts' // Monorepo with explicit override buildTypesFilePath('./generated', './prisma-client.d.ts', '/workspace/api/schema.prisma') // Returns: '/workspace/api/prisma-client.d.ts' ``` ``` -------------------------------- ### Example of replaceObject Usage Source: https://github.com/arthurfiorette/prisma-json-types-generator/blob/main/_autodocs/api-reference-handlers.md Illustrates how replaceObject transforms a TypeScript type literal by replacing a JsonValue with a custom type based on schema comment documentation. It finds the property, parses the comment, and replaces the type. ```typescript // Given a TypeScript type literal: // type User = { name: string; profile: JsonValue } // And a model field with documentation: /// [UserProfile] // replaceObject will: // 1. Find the 'profile' property // 2. Parse the documentation to get 'UserProfile' // 3. Replace JsonValue with PrismaJson.UserProfile ``` -------------------------------- ### Field-Level Multi-line Documentation Source: https://github.com/arthurfiorette/prisma-json-types-generator/blob/main/_autodocs/configuration.md Allows for multi-line documentation comments on schema fields, where the generator scans all lines for type syntax. The first matching type syntax is used. ```prisma model Document { /// This field stores custom metadata. /// [DocumentMetadata] /// It should be validated at runtime. data Json } ``` -------------------------------- ### Entry Point for Prisma Namespace Processing Source: https://github.com/arthurfiorette/prisma-json-types-generator/blob/main/_autodocs/index.md Initiates the processing of the Prisma TypeScript namespace, routing module declarations to specific handlers. ```typescript function handlePrismaModule( child: ts.ModuleDeclaration, writer: DeclarationWriter, modelMap: Map, knownNoOps: Set, typeToNameMap: Map, config: PrismaJsonTypesGeneratorConfig ): void // Entry point for Prisma namespace processing ``` -------------------------------- ### getNamespacePrelude Source: https://github.com/arthurfiorette/prisma-json-types-generator/blob/main/_autodocs/api-reference-declaration-writer.md Reads the namespace template, replaces a placeholder, and adds necessary imports for newer Prisma clients. It returns the formatted namespace prelude as a string. ```APIDOC ## Function: getNamespacePrelude() ### Description Reads the namespace template from `assets/namespace.d.ts`, replaces the `$$NAMESPACE$$` placeholder with the provided namespace, and adds imports for newer Prisma client if needed. ### Parameters #### Path Parameters - **namespace** (string) - Required - The namespace name to inject into the template (e.g., "PrismaJson") - **isNewClient** (boolean) - Required - Whether using Prisma v7+ client format (affects import paths) - **dotExt** (string) - Required - File extension prefix for imports, empty or prefixed with dot (e.g., "", ".js", ".ts") ### Return Type Promise ### Example ```typescript const prelude = await getNamespacePrelude({ namespace: 'PrismaJson', isNewClient: true, dotExt: '.js' }); // Result includes: // import * as Prisma from './internal/prismaNamespace.js'; // declare global { // namespace PrismaJson { ... } // } ``` ``` -------------------------------- ### Signature Creation Utility Source: https://github.com/arthurfiorette/prisma-json-types-generator/blob/main/_autodocs/README.md Builds custom type references and signatures. ```typescript src/util/ create-signature.ts [Build custom type references] ``` -------------------------------- ### save() Source: https://github.com/arthurfiorette/prisma-json-types-generator/blob/main/_autodocs/api-reference-declaration-writer.md Applies all stacked changes to the content, appends the namespace template header, and writes the modified content back to disk. The changes array is cleared after writing. ```APIDOC ## save() ### Description Applies all stacked changes to content, appends the namespace template header, and writes the modified content back to disk. Clears the changes array after writing. ### Method `async save(): Promise` ### Parameters None ### Return Type Promise that resolves when file is written ### Throws Any filesystem errors from `fs.writeFile()` ### Example ```typescript // ... make changes with replace() ... await writer.save(); console.log('File written successfully'); ``` ``` -------------------------------- ### Global Type Map Configuration Source: https://github.com/arthurfiorette/prisma-json-types-generator/blob/main/_autodocs/index.md Utilize `useType = "JsonMap"` for advanced global type mapping. This allows for custom type definitions across your project. ```prisma generator json { provider = "prisma-json-types-generator" useType = "JsonMap" } ``` -------------------------------- ### Specify Client Output Path Source: https://github.com/arthurfiorette/prisma-json-types-generator/blob/main/_autodocs/configuration.md Explicitly set the 'clientOutput' option in your Prisma schema to ensure the generator modifies the correct '@prisma/client' instance when multiple are present. ```prisma clientOutput = "../../packages/api/node_modules/@prisma/client" ``` -------------------------------- ### onManifest Function Source: https://github.com/arthurfiorette/prisma-json-types-generator/blob/main/_autodocs/api-reference-core-generator.md Returns metadata about the generator for Prisma's UI and performs version compatibility checks between the generator, Prisma, and TypeScript. Incompatible versions are logged as warnings. ```APIDOC ## onManifest Function ### Description Returns metadata about the generator for Prisma's UI. Also performs version compatibility checks between the generator, Prisma, and TypeScript. Logs warnings to console if incompatible versions are detected. ### Signature ```typescript function onManifest(): GeneratorManifest ``` ### Parameters None ### Request Example None ### Response #### Success Response (200) Returns `GeneratorManifest` object. #### Response Example ```typescript { version: "5.1.0", defaultOutput: "./", prettyName: "Prisma Json Types Generator" } ``` ### Return Type ```typescript GeneratorManifest { version?: string defaultOutput: './' prettyName: 'Prisma Json Types Generator' } ``` ``` -------------------------------- ### Import Paths for Prisma JSON Types Generator Source: https://github.com/arthurfiorette/prisma-json-types-generator/blob/main/_autodocs/types.md Lists the import paths for various utility and helper modules used in the Prisma JSON Types Generator project. These imports cover configuration, DMMF processing, type parsing, error handling, and more. ```typescript // Configuration import { parseConfig, type PrismaJsonTypesGeneratorConfig } from './util/config' // DMMF Processing import { extractPrismaModels, type PrismaEntity } from './helpers/dmmf' // Type Parsing import { parseTypeSyntax } from './helpers/type-parser' import { createType } from './util/create-signature' // Error Handling import { PrismaJsonTypesGeneratorError } from './util/error' // Declaration Writing import { DeclarationWriter, getNamespacePrelude } from './util/declaration-writer' // Text Transformation import { applyTextChanges, type TextDiff } from './util/text-changes' // Signature Replacement import { findNewSignature } from './helpers/find-signature' // Prisma Utilities import { findPrismaClientGenerators, type GeneratorWithOutput } from './util/prisma-generator' ``` -------------------------------- ### Configure Allow Any for Untyped JSON Source: https://github.com/arthurfiorette/prisma-json-types-generator/blob/main/skills/prisma-json-types-generator/references/setup.md Control the fallback type for untyped JSON fields. Setting `allowAny` to `false` (default) uses `unknown`, while `true` uses `any`. ```prisma generator json { provider = "prisma-json-types-generator" allowAny = false } ``` -------------------------------- ### Schema to Type Transformation Flow Source: https://github.com/arthurfiorette/prisma-json-types-generator/blob/main/_autodocs/architecture-overview.md Illustrates the step-by-step process from a Prisma schema definition with a JSON type to the final generated TypeScript type signature. This flow involves DMMF parsing, type syntax processing, and file writing. ```text schema.prisma ├─ generator { namespace = "PrismaJson"; allowAny = false } └─ model User { profile Json /// [UserProfile] } ↓ DMMF Field { type: 'Json', documentation: '[UserProfile]' } ↓ parseTypeSyntax() { literal: false, type: 'UserProfile' } ↓ createType() 'PrismaJson.UserProfile' ↓ findNewSignature() Replace 'JsonValue' with 'PrismaJson.UserProfile' ↓ writer.replace() Queue change [pos, end, 'PrismaJson.UserProfile'] ↓ writer.save() Apply to index.d.ts ``` -------------------------------- ### Load Declaration File Source: https://github.com/arthurfiorette/prisma-json-types-generator/blob/main/_autodocs/api-reference-declaration-writer.md Reads the declaration file from disk. Must be called before modifications. Throws if the file doesn't exist or has pending changes. ```typescript const writer = new DeclarationWriter( '/path/to/index.d.ts', { namespace: 'PrismaJson' }, false, undefined ); await writer.load(); console.log(writer.content.length); // length of loaded file ``` -------------------------------- ### onGenerate Function Source: https://github.com/arthurfiorette/prisma-json-types-generator/blob/main/_autodocs/api-reference-core-generator.md The main entry point for the Prisma generator hook. It executes when `npx prisma generate` is run, processing type modifications for Prisma clients in parallel. Errors are logged but do not halt the generation process. ```APIDOC ## onGenerate Function ### Description Main entry point for the Prisma generator hook. Executes when `npx prisma generate` is run. Parses the generator configuration, locates all Prisma client generators (both `prisma-client-js` and new `prisma-client`), and processes type modifications for each client in parallel. The function wraps execution in a try-catch to prevent crashes that would break the Prisma generation process. Any errors are logged to console but don't halt the overall generation. ### Signature ```typescript async function onGenerate(options: GeneratorOptions): Promise ``` ### Parameters #### Path Parameters None #### Query Parameters None #### Request Body None ### Parameters - **options** (`GeneratorOptions`) - Required - Contains generator configuration, schema path, DMMF document, and other Prisma generators ### Request Example ```typescript // This is automatically called by the Prisma generator system // when using generatorHandler from @prisma/generator-helper // In schema.prisma: // generator json { // provider = "prisma-json-types-generator" // namespace = "PrismaJson" // } // Then run: // npx prisma generate ``` ### Response #### Success Response (200) Returns `void` on success. #### Response Example None ### Throws/Errors No exceptions thrown. Errors are caught and logged to `console.error()`. ``` -------------------------------- ### createRegexForType Source: https://github.com/arthurfiorette/prisma-json-types-generator/blob/main/_autodocs/api-reference-utilities.md Generates an array of regex patterns that match all Prisma-generated type names for a given model. This is crucial for identifying which types in the Abstract Syntax Tree (AST) correspond to a specific model for further processing. ```APIDOC ## Function: createRegexForType ### Description Generates an array of regex patterns that match all Prisma-generated type names for a given model. Used to identify which types in the AST correspond to a specific model for processing. ### Parameters #### Path Parameters - **name** (string) - Required - The model name (e.g., "User", "Post") ### Return Type RegExp[] — Array of regex patterns ### Patterns Generated: - `Group` — GroupBy result type - `GroupByOutputType` — GroupBy metadata - `OrderByWithRelationInput` — Sort with relations - `OrderByWithAggregationInput` — Sort with aggregates - `(?:Unchecked)?CreateWithout(?:\[^\\\]+?)Input` — Create without relation - `(?:Unchecked)?CreateMany(?:\[^\\\]+?)Input` — Batch create input - `(?:Unchecked)?UpdateWithout(?:\[^\\\]+?)Input` — Update without relation - `(?:Unchecked)?UpdateManyWithout(?:\[^\\\]+?)Input` — Batch update input ### Example: ```typescript const patterns = createRegexForType('User'); // Generates regexes matching: UserGroup, UserGroupByOutputType, // UserOrderByWithRelationInput, UserCreateWithoutProfileInput, etc. patterns[0].test('UserGroup') // true patterns[0].test('PostGroup') // false ``` ``` -------------------------------- ### Prisma Generator onGenerate Hook Source: https://github.com/arthurfiorette/prisma-json-types-generator/blob/main/_autodocs/api-reference-core-generator.md The main entry point for the Prisma generator hook, executed during `npx prisma generate`. It handles parsing configuration, locating Prisma client generators, and processing type modifications in parallel. Errors are logged but do not halt the generation process. ```typescript async function onGenerate(options: GeneratorOptions): Promise ``` -------------------------------- ### replace() Source: https://github.com/arthurfiorette/prisma-json-types-generator/blob/main/_autodocs/api-reference-declaration-writer.md Stacks a text replacement operation to be applied before saving. Multiple replacements are queued and applied in order during `save()`, allowing for safe concurrent position tracking without immediate application of changes. ```APIDOC ## replace(start: number, end: number, text: string) ### Description Stacks a text replacement operation to be applied before save. Multiple replacements are queued and applied in order during `save()`. This allows safe concurrent position tracking without applying changes immediately. ### Method `replace(start: number, end: number, text: string): void` ### Parameters #### Path Parameters - **start** (`number`) - Required - Start character position in the original content - **end** (`number`) - Required - End character position (exclusive) in the original content - **text** (`string`) - Required - Replacement text to insert ### Return Type void ### Example ```typescript // Replace the type at position 150-200 with 'MyCustomType' writer.replace(150, 200, 'MyCustomType'); // Replace another section writer.replace(250, 300, 'AnotherType'); // Changes are applied when save() is called await writer.save(); ``` ``` -------------------------------- ### Entry Point for Statement Processing Source: https://github.com/arthurfiorette/prisma-json-types-generator/blob/main/_autodocs/api-reference-handlers.md Serves as the main entry point for processing individual statements within the Prisma namespace. It filters for type alias declarations and routes them to the appropriate handler based on the type name. ```typescript function handleStatement( statement: ts.Statement, writer: DeclarationWriter, modelMap: Map, typeToNameMap: Map, knownNoOps: Set, config: PrismaJsonTypesGeneratorConfig ): void ``` -------------------------------- ### Prisma Manifest File Source: https://github.com/arthurfiorette/prisma-json-types-generator/blob/main/_autodocs/README.md Handles metadata and version checks for the generator. ```typescript src/ on-manifest.ts [Metadata and version checks] ``` -------------------------------- ### Type Transformation for Fields with Type Comments Source: https://github.com/arthurfiorette/prisma-json-types-generator/blob/main/_autodocs/architecture-overview.md Demonstrates how field types are transformed based on their documentation comments, converting generic JSON types to specific Prisma JSON types. ```plaintext Field Documentation: "/// [UserProfile]" ↓ parseTypeSyntax() { literal: false, type: "UserProfile" } ↓ createType() "PrismaJson.UserProfile" ↓ findNewSignature() "JsonValue" → "PrismaJson.UserProfile" "JsonValue | null" → "PrismaJson.UserProfile | null" "JsonValue[]" → "PrismaJson.UserProfile[]" ``` -------------------------------- ### Find Prisma Client Generators Source: https://github.com/arthurfiorette/prisma-json-types-generator/blob/main/_autodocs/api-reference-utilities.md Searches a list of generator configurations for Prisma client generators, supporting both classic and modern provider names. It validates that each found client generator has an output path configured. ```typescript function findPrismaClientGenerators( generators: GeneratorConfig[] ): GeneratorWithOutput[] ``` ```typescript const allGenerators = options.otherGenerators; // [ // { provider: { value: 'prisma-client-js' }, output: { value: './node_modules/.prisma/client' }, ... }, // { provider: { value: 'prisma-dbml-generator' }, ... } // ] const clients = findPrismaClientGenerators(allGenerators); // Returns: [ // { provider: { value: 'prisma-client-js' }, output: { value: './node_modules/.prisma/client' }, ... } // ] // Iterates through each found client for (const client of clients) { await generateClient(client, config, options); } ``` -------------------------------- ### On Manifest Hook Source: https://github.com/arthurfiorette/prisma-json-types-generator/blob/main/_autodocs/index.md Provides metadata about the generator, including its version and capabilities, for Prisma's internal use. ```typescript export function onManifest(): GeneratorManifest ``` -------------------------------- ### DeclarationWriter Constructor Source: https://github.com/arthurfiorette/prisma-json-types-generator/blob/main/_autodocs/api-reference-declaration-writer.md Initializes a new instance of DeclarationWriter. Requires the filepath, configuration options (including namespace), a boolean indicating multi-file mode, and an optional import file extension. ```typescript constructor( readonly filepath: string, private readonly options: Pick, readonly multifile: boolean, private readonly importFileExtension: string | undefined ) ``` -------------------------------- ### Configure Use Type for Untyped JSON Fallback Source: https://github.com/arthurfiorette/prisma-json-types-generator/blob/main/skills/prisma-json-types-generator/references/setup.md Set a root type to be used as a fallback for unannotated JSON fields. This adds an index signature and is not the strictest option. ```prisma generator json { provider = "prisma-json-types-generator" useType = "MyOwnType" } ``` -------------------------------- ### Configuration Parser Utility Source: https://github.com/arthurfiorette/prisma-json-types-generator/blob/main/_autodocs/README.md Parses generator configuration options. ```typescript src/util/ config.ts [Parse configuration] ``` -------------------------------- ### Monorepo Client Output Configuration Source: https://github.com/arthurfiorette/prisma-json-types-generator/blob/main/_autodocs/configuration.md Specifies the output location for the Prisma client, which is useful in monorepo structures. This ensures the generated types are correctly linked within the monorepo. ```prisma generator json { provider = "prisma-json-types-generator" namespace = "PrismaJson" clientOutput = "../../packages/database/node_modules/@prisma/client" } ``` -------------------------------- ### Create Type: Undefined Description Source: https://github.com/arthurfiorette/prisma-json-types-generator/blob/main/_autodocs/api-reference-type-parsing.md When no description is provided, createType returns 'unknown'. This is the default behavior for fields without documentation. ```typescript createType(undefined, { namespace: 'PrismaJson' }) // Returns: 'unknown' ``` -------------------------------- ### Signature Finder Helper Source: https://github.com/arthurfiorette/prisma-json-types-generator/blob/main/_autodocs/README.md Maps Prisma types to custom defined types. ```typescript src/helpers/ find-signature.ts [Map Prisma types to custom types] ``` -------------------------------- ### Prisma Generator Utility Source: https://github.com/arthurfiorette/prisma-json-types-generator/blob/main/_autodocs/README.md Finds and interacts with Prisma clients. ```typescript src/util/ prisma-generator.ts [Find Prisma clients] ``` -------------------------------- ### Declaration Writer Utility Source: https://github.com/arthurfiorette/prisma-json-types-generator/blob/main/_autodocs/README.md Handles file I/O and Abstract Syntax Tree (AST) management for declarations. ```typescript src/util/ declaration-writer.ts [File I/O and AST management] ``` -------------------------------- ### Use a Global Fallback Type for All JSON Fields Source: https://github.com/arthurfiorette/prisma-json-types-generator/blob/main/_autodocs/configuration.md Enable a 'typed any' pattern by specifying a global fallback type for all JSON fields. This allows for a unified indexing strategy and easier customization of field types. ```prisma generator json { provider = "prisma-json-types-generator" namespace = "PrismaJson" useType = "GlobalType" } ``` -------------------------------- ### Configure Prisma Schema Source: https://github.com/arthurfiorette/prisma-json-types-generator/blob/main/_autodocs/index.md Add the generator to your schema.prisma file. You can optionally specify a custom namespace and control whether untyped fields default to 'any'. ```prisma generator client { provider = "prisma-client-js" } generator json { provider = "prisma-json-types-generator" namespace = "PrismaJson" # optional, defaults to "PrismaJson" allowAny = false # optional, defaults to false } ``` -------------------------------- ### Prisma Main Processing Hook Source: https://github.com/arthurfiorette/prisma-json-types-generator/blob/main/_autodocs/README.md This file contains the main processing hook for the generator. ```typescript src/ on-generate.ts [Main processing hook] ``` -------------------------------- ### Route Statements for Handling Source: https://github.com/arthurfiorette/prisma-json-types-generator/blob/main/_autodocs/index.md Directs different TypeScript AST statements to their appropriate handler functions based on their type and context. ```typescript function handleStatement( statement: ts.Statement, writer: DeclarationWriter, modelMap: Map, typeToNameMap: Map, knownNoOps: Set, config: PrismaJsonTypesGeneratorConfig ): void // Routes statements to appropriate handler ``` -------------------------------- ### Configure Namespace Option Source: https://github.com/arthurfiorette/prisma-json-types-generator/blob/main/skills/prisma-json-types-generator/references/setup.md Set the global namespace for Prisma JSON types. This must match the namespace used in your TypeScript files. ```prisma generator json { provider = "prisma-json-types-generator" namespace = "PrismaJson" } ``` -------------------------------- ### Generator Handler Entry Point Source: https://github.com/arthurfiorette/prisma-json-types-generator/blob/main/_autodocs/index.md The main entry point for the generator, responsible for registering its lifecycle hooks. ```typescript generatorHandler({ onManifest, onGenerate }) ``` -------------------------------- ### Create Regex Patterns for Prisma Types Source: https://github.com/arthurfiorette/prisma-json-types-generator/blob/main/_autodocs/api-reference-utilities.md Generates an array of regex patterns to match Prisma-generated type names for a given model. Useful for identifying AST types related to a specific model. ```typescript function createRegexForType(name: string): RegExp[] ``` ```typescript const patterns = createRegexForType('User'); // Generates regexes matching: UserGroup, UserGroupByOutputType, // UserOrderByWithRelationInput, UserCreateWithoutProfileInput, etc. patterns[0].test('UserGroup') // true patterns[0].test('PostGroup') // false ``` -------------------------------- ### Prisma Generator onManifest Function Source: https://github.com/arthurfiorette/prisma-json-types-generator/blob/main/_autodocs/api-reference-core-generator.md Returns metadata for the generator, including its version, default output path, and pretty name, for use in Prisma's UI. It also performs version compatibility checks with Prisma and TypeScript, logging warnings for any detected incompatibilities. ```typescript function onManifest(): GeneratorManifest ``` -------------------------------- ### Declaration File Processing Flow Source: https://github.com/arthurfiorette/prisma-json-types-generator/blob/main/_autodocs/architecture-overview.md Outlines the process of loading, parsing, and modifying declaration files (.d.ts) to handle Prisma namespaces and model payloads. ```plaintext Declaration File (.d.ts) ↓ Load content: string ↓ Parse with TypeScript compiler SourceFile AST ↓ Walk tree ModuleDeclaration (Prisma namespace) ├─ handlePrismaModule() │ └─ forEachChild(statement) │ └─ handleStatement() │ ├─ Type is $Payload? → handleModelPayload() │ └─ Type is model type? → replaceObject() │ └─ For each field: │ ├─ parseTypeSyntax() [extract type comment] │ ├─ createType() [build custom type] │ ├─ findNewSignature() [transform] │ └─ writer.replace() [queue change] ├─ Apply all queued changes ├─ Append namespace template └─ Write modified content to disk ``` -------------------------------- ### Basic JSON/String Type Transformation Source: https://github.com/arthurfiorette/prisma-json-types-generator/blob/main/_autodocs/architecture-overview.md Demonstrates the transformation of basic JSON types (`JsonValue`, `InputJsonValue`) and primitive types (`string`, `number`) into custom types. This is used for direct JSON values, string enums, and numeric literals. ```text - `JsonValue` → custom type - `InputJsonValue` → custom type - `string` → custom type (for enums) - `number` → custom type (for numeric literals) ``` -------------------------------- ### Determine Prisma Client Types File Path Source: https://github.com/arthurfiorette/prisma-json-types-generator/blob/main/_autodocs/api-reference-utilities.md Resolves the path to the Prisma Client declaration file, supporting various project structures and custom overrides. It handles absolute and relative paths, appending the default filename if necessary. ```typescript function buildTypesFilePath( clientOutput: string, overrideTarget?: string, schemaTarget?: string ): string ``` ```typescript // Standard npm/pnpm setup buildTypesFilePath('./node_modules/.prisma/client') // Returns: '/path/to/node_modules/.prisma/client/index.d.ts' ``` ```typescript // Custom output buildTypesFilePath('./custom', '../types/prisma.d.ts', '/project/schema.prisma') // Returns: '/project/types/prisma.d.ts' ``` ```typescript // Monorepo with explicit override buildTypesFilePath('./generated', './prisma-client.d.ts', '/workspace/api/schema.prisma') // Returns: '/workspace/api/prisma-client.d.ts' ``` -------------------------------- ### Statement Handler Source: https://github.com/arthurfiorette/prisma-json-types-generator/blob/main/_autodocs/README.md Routes statements to the appropriate handlers. ```typescript src/handler/ statement.ts [Route statements to handlers] ```