fork of hey-api/openapi-ts because I need some additional things
0
fork

Configure Feed

Select the types of activity you want to include in your feed.

Merge pull request #2360 from hey-api/refactor/compiler-tsc

refactor: rename compiler export to tsc

authored by

Lubos and committed by
GitHub
1c32240f 4389c5df

+1593 -1603
+4
docs/openapi-ts/community/contributing/building.md
··· 21 21 - contain a clean history of small, incremental, logically separate commits, with no merge commits 22 22 - use clear commit messages 23 23 - be possible to merge automatically 24 + 25 + ## Start `@hey-api/openapi-ts` 26 + 27 + Run `pnpm --filter @hey-api/openapi-ts dev`.
packages/openapi-ts/src/compiler/classes.ts packages/openapi-ts/src/tsc/classes.ts
packages/openapi-ts/src/compiler/convert.ts packages/openapi-ts/src/tsc/convert.ts
+4 -1
packages/openapi-ts/src/compiler/index.ts packages/openapi-ts/src/tsc/index.ts
··· 11 11 export type { FunctionParameter } from './types'; 12 12 export type { Comments } from './utils'; 13 13 14 - export const compiler = { 14 + export const tsc = { 15 15 anonymousFunction: types.createAnonymousFunction, 16 16 arrayLiteralExpression: types.createArrayLiteralExpression, 17 17 arrowFunction: types.createArrowFunction, ··· 81 81 typeUnionNode: typedef.createTypeUnionNode, 82 82 valueToExpression: types.toExpression, 83 83 }; 84 + 85 + /** @deprecated use tsc */ 86 + export const compiler = tsc;
packages/openapi-ts/src/compiler/module.ts packages/openapi-ts/src/tsc/module.ts
packages/openapi-ts/src/compiler/return.ts packages/openapi-ts/src/tsc/return.ts
packages/openapi-ts/src/compiler/transform.ts packages/openapi-ts/src/tsc/transform.ts
packages/openapi-ts/src/compiler/typedef.ts packages/openapi-ts/src/tsc/typedef.ts
+2 -1
packages/openapi-ts/src/compiler/types.ts packages/openapi-ts/src/tsc/types.ts
··· 178 178 }; 179 179 180 180 /** 181 - * Convert parameters to the declaration array expected by compiler API. 181 + * Convert parameters to the declaration array expected by TypeScript 182 + * Compiler API. 182 183 * @param parameters - the parameters to convert to declarations 183 184 * @returns ts.ParameterDeclaration[] 184 185 */
packages/openapi-ts/src/compiler/utils.ts packages/openapi-ts/src/tsc/utils.ts
+1 -1
packages/openapi-ts/src/generate/client.ts
··· 4 4 5 5 import ts from 'typescript'; 6 6 7 - import type { ImportExportItemObject } from '../compiler/utils'; 8 7 import type { Client } from '../plugins/@hey-api/client-core/types'; 9 8 import { getClientPlugin } from '../plugins/@hey-api/client-core/utils'; 10 9 import type { DefinePlugin } from '../plugins/types'; 10 + import type { ImportExportItemObject } from '../tsc/utils'; 11 11 import type { Config } from '../types/config'; 12 12 import { ensureDirSync, relativeModulePath } from './utils'; 13 13
+5 -8
packages/openapi-ts/src/generate/file/index.ts
··· 3 3 4 4 import ts from 'typescript'; 5 5 6 - import { compiler } from '../../compiler'; 7 - import { 8 - type ImportExportItemObject, 9 - tsNodeToString, 10 - } from '../../compiler/utils'; 11 6 import type { IR } from '../../ir/types'; 12 7 import { getUniqueComponentName } from '../../openApi/shared/transforms/utils'; 13 8 import { ensureValidIdentifier } from '../../openApi/shared/utils/identifier'; 9 + import { tsc } from '../../tsc'; 10 + import { type ImportExportItemObject, tsNodeToString } from '../../tsc/utils'; 14 11 import type { StringCase } from '../../types/case'; 15 12 import { stringCase } from '../../utils/stringCase'; 16 13 import { ensureDirSync } from '../utils'; ··· 199 196 public getNode(id: string): NodeInfo { 200 197 if (!this.nodes[id]) { 201 198 this.nodes[id] = { 202 - node: compiler.typeReferenceNode({ typeName: '' }), 199 + node: tsc.typeReferenceNode({ typeName: '' }), 203 200 }; 204 201 } 205 202 return this.nodes[id]!; ··· 382 379 } 383 380 } 384 381 385 - const node = compiler.namedImportDeclarations({ 382 + const node = tsc.namedImportDeclarations({ 386 383 imports, 387 384 module: resolvedModule, 388 385 }); ··· 421 418 components: Object.values(this.names), 422 419 }); 423 420 this.names[id] = name; 424 - const node = compiler.typeReferenceNode({ typeName: name }); 421 + const node = tsc.typeReferenceNode({ typeName: name }); 425 422 // update node 426 423 if (!this.nodes[id]) { 427 424 this.nodes[id] = { node };
+8 -8
packages/openapi-ts/src/generate/legacy/indexFile.ts
··· 1 - import { compiler } from '../../compiler'; 2 1 import { getClientPlugin } from '../../plugins/@hey-api/client-core/utils'; 2 + import { tsc } from '../../tsc'; 3 3 import type { Files } from '../../types/utils'; 4 4 import { getConfig, legacyNameFromConfig } from '../../utils/config'; 5 5 import { GeneratedFile } from '../file'; ··· 15 15 16 16 if (legacyNameFromConfig(config)) { 17 17 files.index.add( 18 - compiler.exportNamedDeclaration({ 18 + tsc.exportNamedDeclaration({ 19 19 exports: legacyNameFromConfig(config)!, 20 20 module: `./${legacyNameFromConfig(config)}`, 21 21 }), ··· 24 24 25 25 if (config.exportCore) { 26 26 files.index.add( 27 - compiler.exportNamedDeclaration({ 27 + tsc.exportNamedDeclaration({ 28 28 exports: 'ApiError', 29 29 module: './core/ApiError', 30 30 }), 31 31 ); 32 32 if (config.plugins['@hey-api/sdk']?.config.response === 'response') { 33 33 files.index.add( 34 - compiler.exportNamedDeclaration({ 34 + tsc.exportNamedDeclaration({ 35 35 exports: { asType: true, name: 'ApiResult' }, 36 36 module: './core/ApiResult', 37 37 }), ··· 39 39 } 40 40 if (legacyNameFromConfig(config)) { 41 41 files.index.add( 42 - compiler.exportNamedDeclaration({ 42 + tsc.exportNamedDeclaration({ 43 43 exports: 'BaseHttpRequest', 44 44 module: './core/BaseHttpRequest', 45 45 }), ··· 48 48 const clientPlugin = getClientPlugin(config); 49 49 if (clientPlugin.name !== 'legacy/angular') { 50 50 files.index.add( 51 - compiler.exportNamedDeclaration({ 51 + tsc.exportNamedDeclaration({ 52 52 exports: ['CancelablePromise', 'CancelError'], 53 53 module: './core/CancelablePromise', 54 54 }), 55 55 ); 56 56 } 57 57 files.index.add( 58 - compiler.exportNamedDeclaration({ 58 + tsc.exportNamedDeclaration({ 59 59 exports: ['OpenAPI', { asType: true, name: 'OpenAPIConfig' }], 60 60 module: './core/OpenAPI', 61 61 }), ··· 73 73 74 74 if (file.exportFromIndex) { 75 75 files.index!.add( 76 - compiler.exportAllDeclaration({ 76 + tsc.exportAllDeclaration({ 77 77 module: `./${file.nameWithoutExtension()}`, 78 78 }), 79 79 );
+2 -4
packages/openapi-ts/src/generate/output.ts
··· 2 2 3 3 import ts from 'typescript'; 4 4 5 - import { compiler } from '../compiler'; 6 5 import type { IR } from '../ir/types'; 7 6 import { getClientPlugin } from '../plugins/@hey-api/client-core/utils'; 7 + import { tsc } from '../tsc'; 8 8 import { generateClientBundle } from './client'; 9 9 import { findTsConfigPath, loadTsConfig } from './tsConfig'; 10 10 import { removeDirSync } from './utils'; ··· 70 70 } 71 71 // TODO: parser - add export method for more granular control over 72 72 // what's exported so we can support named exports 73 - indexFile.add( 74 - compiler.exportAllDeclaration({ module: resolvedModule }), 75 - ); 73 + indexFile.add(tsc.exportAllDeclaration({ module: resolvedModule })); 76 74 } 77 75 78 76 file.write('\n\n', tsConfig);
+1 -1
packages/openapi-ts/src/index.ts
··· 118 118 export const defineConfig = async (config: Configs): Promise<UserConfig> => 119 119 typeof config === 'function' ? await config() : config; 120 120 121 - export { compiler } from './compiler'; 122 121 export { defaultPaginationKeywords } from './config/parser'; 123 122 export { defaultPlugins } from './config/plugins'; 124 123 export type { IR } from './ir/types'; ··· 140 139 export type { ExpressionTransformer } from './plugins/@hey-api/transformers/expressions'; 141 140 export { definePluginConfig } from './plugins/shared/utils/config'; 142 141 export type { DefinePlugin, Plugin } from './plugins/types'; 142 + export { compiler, tsc } from './tsc'; 143 143 export type { UserConfig } from './types/config'; 144 144 export type { LegacyIR } from './types/types'; 145 145 export { utils } from './utils/exports';
+7 -7
packages/openapi-ts/src/plugins/@hey-api/client-core/client.ts
··· 1 - import { compiler } from '../../../compiler'; 2 1 import { clientModulePath } from '../../../generate/client'; 2 + import { tsc } from '../../../tsc'; 3 3 import { parseUrl } from '../../../utils/url'; 4 4 import { typesId } from '../typescript/ref'; 5 5 import type { PluginHandler } from './types'; ··· 93 93 } 94 94 95 95 const createConfigParameters = [ 96 - compiler.callExpression({ 96 + tsc.callExpression({ 97 97 functionName: createConfig.name, 98 98 parameters: defaultValues.length 99 - ? [compiler.objectExpression({ obj: defaultValues })] 99 + ? [tsc.objectExpression({ obj: defaultValues })] 100 100 : undefined, 101 101 types: clientOptions.name 102 - ? [compiler.typeReferenceNode({ typeName: clientOptions.name })] 102 + ? [tsc.typeReferenceNode({ typeName: clientOptions.name })] 103 103 : undefined, 104 104 }), 105 105 ]; 106 106 107 - const statement = compiler.constVariable({ 107 + const statement = tsc.constVariable({ 108 108 exportConst: true, 109 - expression: compiler.callExpression({ 109 + expression: tsc.callExpression({ 110 110 functionName: createClient.name, 111 111 parameters: createClientConfig 112 112 ? [ 113 - compiler.callExpression({ 113 + tsc.callExpression({ 114 114 functionName: createClientConfig.name, 115 115 parameters: createConfigParameters, 116 116 }),
+12 -12
packages/openapi-ts/src/plugins/@hey-api/client-core/createClientConfig.ts
··· 1 - import { compiler } from '../../../compiler'; 2 1 import { clientModulePath } from '../../../generate/client'; 2 + import { tsc } from '../../../tsc'; 3 3 import { clientId } from '../client-core/utils'; 4 4 import { typesId } from '../typescript/ref'; 5 5 import type { PluginHandler } from './types'; ··· 34 34 name: 'ClientOptions', 35 35 }); 36 36 37 - const defaultClientOptionsType = compiler.typeReferenceNode({ 37 + const defaultClientOptionsType = tsc.typeReferenceNode({ 38 38 typeName: defaultClientOptions.name, 39 39 }); 40 - const tType = compiler.typeReferenceNode({ typeName: 'T' }); 40 + const tType = tsc.typeReferenceNode({ typeName: 'T' }); 41 41 42 - const typeCreateClientConfig = compiler.typeAliasDeclaration({ 42 + const typeCreateClientConfig = tsc.typeAliasDeclaration({ 43 43 comment: [ 44 44 'The `createClientConfig()` function will be called on client initialization', 45 45 "and the returned object will become the client's initial configuration.", ··· 50 50 ], 51 51 exportType: true, 52 52 name: 'CreateClientConfig', 53 - type: compiler.functionTypeNode({ 53 + type: tsc.functionTypeNode({ 54 54 parameters: [ 55 - compiler.parameterDeclaration({ 55 + tsc.parameterDeclaration({ 56 56 name: 'override', 57 57 required: false, 58 - type: compiler.typeReferenceNode({ 58 + type: tsc.typeReferenceNode({ 59 59 typeArguments: [ 60 - compiler.typeIntersectionNode({ 60 + tsc.typeIntersectionNode({ 61 61 types: [defaultClientOptionsType, tType], 62 62 }), 63 63 ], ··· 65 65 }), 66 66 }), 67 67 ], 68 - returnType: compiler.typeReferenceNode({ 68 + returnType: tsc.typeReferenceNode({ 69 69 typeArguments: [ 70 - compiler.typeIntersectionNode({ 70 + tsc.typeIntersectionNode({ 71 71 types: [ 72 - compiler.typeReferenceNode({ 72 + tsc.typeReferenceNode({ 73 73 typeArguments: [defaultClientOptionsType], 74 74 typeName: 'Required', 75 75 }), ··· 83 83 typeParameters: [ 84 84 { 85 85 default: clientOptions.name 86 - ? compiler.typeReferenceNode({ typeName: clientOptions.name }) 86 + ? tsc.typeReferenceNode({ typeName: clientOptions.name }) 87 87 : undefined, 88 88 extends: defaultClientOptionsType, 89 89 name: 'T',
+3 -3
packages/openapi-ts/src/plugins/@hey-api/schemas/plugin-legacy.ts
··· 1 - import { compiler } from '../../../compiler'; 2 1 import { GeneratedFile } from '../../../generate/file'; 3 2 import type { OpenApiV2Schema, OpenApiV3Schema } from '../../../openApi'; 4 3 import { ensureValidTypeScriptJavaScriptIdentifier } from '../../../openApi'; 4 + import { tsc } from '../../../tsc'; 5 5 import { getConfig } from '../../../utils/config'; 6 6 import type { HeyApiSchemasPlugin } from './types'; 7 7 ··· 93 93 schema: OpenApiV2Schema | OpenApiV3Schema, 94 94 ) => { 95 95 const obj = ensureValidSchemaOutput(schema); 96 - const expression = compiler.objectExpression({ obj }); 97 - const statement = compiler.constVariable({ 96 + const expression = tsc.objectExpression({ obj }); 97 + const statement = tsc.constVariable({ 98 98 assertion: 'const', 99 99 exportConst: true, 100 100 expression,
+7 -7
packages/openapi-ts/src/plugins/@hey-api/schemas/plugin.ts
··· 1 - import { compiler } from '../../../compiler'; 2 1 import type { IR } from '../../../ir/types'; 3 2 import type { OpenApiV2_0_XTypes } from '../../../openApi/2.0.x'; 4 3 import type { OpenApiV3_0_XTypes } from '../../../openApi/3.0.x'; 5 4 import type { OpenApiV3_1_XTypes } from '../../../openApi/3.1.x'; 6 5 import { ensureValidIdentifier } from '../../../openApi/shared/utils/identifier'; 7 6 import type { OpenApi } from '../../../openApi/types'; 7 + import { tsc } from '../../../tsc'; 8 8 import type { HeyApiSchemasPlugin } from './types'; 9 9 10 10 const schemasId = 'schemas'; ··· 373 373 plugin, 374 374 schema, 375 375 }); 376 - const statement = compiler.constVariable({ 376 + const statement = tsc.constVariable({ 377 377 assertion: 'const', 378 378 exportConst: true, 379 - expression: compiler.objectExpression({ obj }), 379 + expression: tsc.objectExpression({ obj }), 380 380 name: schemaName({ name, plugin, schema }), 381 381 }); 382 382 context.file({ id: schemasId })!.add(statement); ··· 401 401 plugin, 402 402 schema, 403 403 }); 404 - const statement = compiler.constVariable({ 404 + const statement = tsc.constVariable({ 405 405 assertion: 'const', 406 406 exportConst: true, 407 - expression: compiler.objectExpression({ obj }), 407 + expression: tsc.objectExpression({ obj }), 408 408 name: schemaName({ name, plugin, schema }), 409 409 }); 410 410 context.file({ id: schemasId })!.add(statement); ··· 429 429 plugin, 430 430 schema, 431 431 }); 432 - const statement = compiler.constVariable({ 432 + const statement = tsc.constVariable({ 433 433 assertion: 'const', 434 434 exportConst: true, 435 - expression: compiler.objectExpression({ obj }), 435 + expression: tsc.objectExpression({ obj }), 436 436 name: schemaName({ name, plugin, schema }), 437 437 }); 438 438 context.file({ id: schemasId })!.add(statement);
+25 -25
packages/openapi-ts/src/plugins/@hey-api/sdk/operation.ts
··· 1 1 import type ts from 'typescript'; 2 2 3 - import { compiler } from '../../../compiler'; 4 - import type { FunctionParameter, ObjectValue } from '../../../compiler/types'; 5 3 import { clientApi, clientModulePath } from '../../../generate/client'; 6 4 import type { GeneratedFile } from '../../../generate/file'; 7 5 import { statusCodeToGroup } from '../../../ir/operation'; 8 6 import type { IR } from '../../../ir/types'; 9 7 import { sanitizeNamespaceIdentifier } from '../../../openApi'; 10 8 import { ensureValidIdentifier } from '../../../openApi/shared/utils/identifier'; 9 + import { tsc } from '../../../tsc'; 10 + import type { FunctionParameter, ObjectValue } from '../../../tsc/types'; 11 11 import { reservedJavaScriptKeywordsRegExp } from '../../../utils/regexp'; 12 12 import { stringCase } from '../../../utils/stringCase'; 13 13 import { transformClassName } from '../../../utils/transform'; ··· 584 584 if (auth.length) { 585 585 requestOptions.push({ 586 586 key: 'security', 587 - value: compiler.arrayLiteralExpression({ elements: auth }), 587 + value: tsc.arrayLiteralExpression({ elements: auth }), 588 588 }); 589 589 } 590 590 ··· 603 603 const args: Array<unknown> = []; 604 604 const config: Array<unknown> = []; 605 605 for (const argName of opParameters.argNames) { 606 - args.push(compiler.identifier({ text: argName })); 606 + args.push(tsc.identifier({ text: argName })); 607 607 } 608 608 for (const field of opParameters.fields) { 609 609 const obj: Array<Record<string, unknown>> = []; ··· 625 625 }); 626 626 } 627 627 } 628 - config.push(compiler.objectExpression({ obj })); 628 + config.push(tsc.objectExpression({ obj })); 629 629 } 630 630 const imported = file.import({ 631 631 module: clientModulePath({ ··· 635 635 name: 'buildClientParams', 636 636 }); 637 637 statements.push( 638 - compiler.constVariable({ 639 - expression: compiler.callExpression({ 638 + tsc.constVariable({ 639 + expression: tsc.callExpression({ 640 640 functionName: imported.name, 641 641 parameters: [ 642 - compiler.arrayLiteralExpression({ elements: args }), 643 - compiler.arrayLiteralExpression({ elements: config }), 642 + tsc.arrayLiteralExpression({ elements: args }), 643 + tsc.arrayLiteralExpression({ elements: config }), 644 644 ], 645 645 }), 646 646 name: 'params', ··· 664 664 : operation.body.mediaType, 665 665 }, 666 666 { 667 - spread: compiler.propertyAccessExpression({ 668 - expression: compiler.identifier({ text: 'options' }), 667 + spread: tsc.propertyAccessExpression({ 668 + expression: tsc.identifier({ text: 'options' }), 669 669 isOptional: !isRequiredOptions, 670 670 name: 'headers', 671 671 }), ··· 673 673 ]; 674 674 if (hasParams) { 675 675 headersValue.push({ 676 - spread: compiler.propertyAccessExpression({ 677 - expression: compiler.identifier({ text: 'params' }), 676 + spread: tsc.propertyAccessExpression({ 677 + expression: tsc.identifier({ text: 'params' }), 678 678 name: 'headers', 679 679 }), 680 680 }); ··· 700 700 }) 701 701 : undefined; 702 702 703 - const optionsClient = compiler.propertyAccessExpression({ 704 - expression: compiler.identifier({ text: 'options' }), 703 + const optionsClient = tsc.propertyAccessExpression({ 704 + expression: tsc.identifier({ text: 'options' }), 705 705 isOptional: !isRequiredOptions, 706 706 name: 'client', 707 707 }); ··· 709 709 let clientExpression: ts.Expression; 710 710 711 711 if (plugin.config.instance) { 712 - clientExpression = compiler.binaryExpression({ 712 + clientExpression = tsc.binaryExpression({ 713 713 left: optionsClient, 714 714 operator: '??', 715 - right: compiler.propertyAccessExpression({ 716 - expression: compiler.this(), 715 + right: tsc.propertyAccessExpression({ 716 + expression: tsc.this(), 717 717 name: '_client', 718 718 }), 719 719 }); 720 720 } else if (heyApiClient?.name) { 721 - clientExpression = compiler.binaryExpression({ 721 + clientExpression = tsc.binaryExpression({ 722 722 left: optionsClient, 723 723 operator: '??', 724 - right: compiler.identifier({ text: heyApiClient.name }), 724 + right: tsc.identifier({ text: heyApiClient.name }), 725 725 }); 726 726 } else { 727 727 clientExpression = optionsClient; ··· 740 740 } 741 741 742 742 if (plugin.config.responseStyle === 'data') { 743 - types.push(compiler.stringLiteral({ text: plugin.config.responseStyle })); 743 + types.push(tsc.stringLiteral({ text: plugin.config.responseStyle })); 744 744 } 745 745 746 746 statements.push( 747 - compiler.returnFunctionCall({ 747 + tsc.returnFunctionCall({ 748 748 args: [ 749 - compiler.objectExpression({ 749 + tsc.objectExpression({ 750 750 identifiers: ['responseTransformer'], 751 751 obj: requestOptions, 752 752 }), 753 753 ], 754 - name: compiler.propertyAccessExpression({ 754 + name: tsc.propertyAccessExpression({ 755 755 expression: clientExpression, 756 - name: compiler.identifier({ text: operation.method }), 756 + name: tsc.identifier({ text: operation.method }), 757 757 }), 758 758 types, 759 759 }),
+26 -29
packages/openapi-ts/src/plugins/@hey-api/sdk/plugin-legacy.ts
··· 1 1 import type ts from 'typescript'; 2 2 3 - import type { Comments, FunctionParameter } from '../../../compiler'; 4 - import { compiler } from '../../../compiler'; 5 - import type { 6 - FunctionTypeParameter, 7 - ObjectValue, 8 - } from '../../../compiler/types'; 9 3 import { clientApi, clientModulePath } from '../../../generate/client'; 10 4 import { GeneratedFile } from '../../../generate/file'; 11 5 import type { IR } from '../../../ir/types'; 12 6 import { isOperationParameterRequired } from '../../../openApi'; 7 + import type { Comments, FunctionParameter } from '../../../tsc'; 8 + import { tsc } from '../../../tsc'; 9 + import type { FunctionTypeParameter, ObjectValue } from '../../../tsc/types'; 13 10 import type { 14 11 Client, 15 12 Model, ··· 178 175 const toOperationReturnType = (client: Client, operation: Operation) => { 179 176 const config = getConfig(); 180 177 181 - let returnType = compiler.typeNode('void'); 178 + let returnType = tsc.typeNode('void'); 182 179 183 180 const successResponses = operation.responses.filter((response) => 184 181 response.responseTypes.includes('success'), ··· 198 195 }, 199 196 nameTransformer: operationResponseTypeName, 200 197 }); 201 - returnType = compiler.typeUnionNode({ 198 + returnType = tsc.typeUnionNode({ 202 199 types: [importedType], 203 200 }); 204 201 } ··· 207 204 config.useOptions && 208 205 config.plugins['@hey-api/sdk']?.config.response === 'response' 209 206 ) { 210 - returnType = compiler.typeNode('ApiResult', [returnType]); 207 + returnType = tsc.typeNode('ApiResult', [returnType]); 211 208 } 212 209 213 210 const clientPlugin = getClientPlugin(config); 214 211 if (clientPlugin.name === 'legacy/angular') { 215 - returnType = compiler.typeNode('Observable', [returnType]); 212 + returnType = tsc.typeNode('Observable', [returnType]); 216 213 } else { 217 - returnType = compiler.typeNode('CancelablePromise', [returnType]); 214 + returnType = tsc.typeNode('CancelablePromise', [returnType]); 218 215 } 219 216 220 217 return returnType; ··· 383 380 ]; 384 381 } 385 382 386 - return compiler.objectExpression({ 383 + return tsc.objectExpression({ 387 384 identifiers: ['responseTransformer'], 388 385 obj, 389 386 }); ··· 471 468 obj.errors = errors; 472 469 } 473 470 474 - return compiler.objectExpression({ 471 + return tsc.objectExpression({ 475 472 identifiers: [ 476 473 'body', 477 474 'cookies', ··· 555 552 }).name 556 553 : 'void'; 557 554 return [ 558 - compiler.returnFunctionCall({ 555 + tsc.returnFunctionCall({ 559 556 args: [options], 560 557 name: `(options?.client ?? client).${operation.method.toLocaleLowerCase()}`, 561 558 types: ··· 572 569 573 570 if (legacyNameFromConfig(config)) { 574 571 return [ 575 - compiler.returnFunctionCall({ 572 + tsc.returnFunctionCall({ 576 573 args: [options], 577 574 name: 'this.httpRequest.request', 578 575 }), ··· 582 579 const clientPlugin = getClientPlugin(config); 583 580 if (clientPlugin.name === 'legacy/angular') { 584 581 return [ 585 - compiler.returnFunctionCall({ 582 + tsc.returnFunctionCall({ 586 583 args: ['OpenAPI', 'this.http', options], 587 584 name: '__request', 588 585 }), ··· 590 587 } 591 588 592 589 return [ 593 - compiler.returnFunctionCall({ 590 + tsc.returnFunctionCall({ 594 591 args: ['OpenAPI', options], 595 592 name: '__request', 596 593 }), ··· 691 688 }; 692 689 const expression = 693 690 clientPlugin.name === 'legacy/angular' 694 - ? compiler.anonymousFunction(compileFunctionParams) 695 - : compiler.arrowFunction(compileFunctionParams); 696 - const statement = compiler.constVariable({ 691 + ? tsc.anonymousFunction(compileFunctionParams) 692 + : tsc.arrowFunction(compileFunctionParams); 693 + const statement = tsc.constVariable({ 697 694 comment: toOperationComment(operation), 698 695 exportConst: true, 699 696 expression, ··· 710 707 } 711 708 712 709 let members: ts.ClassElement[] = service.operations.map((operation) => { 713 - const node = compiler.methodDeclaration({ 710 + const node = tsc.methodDeclaration({ 714 711 accessLevel: 'public', 715 712 comment: toOperationComment(operation), 716 713 isStatic: ··· 743 740 // Push constructor to front if needed 744 741 if (legacyNameFromConfig(config)) { 745 742 members = [ 746 - compiler.constructorDeclaration({ 743 + tsc.constructorDeclaration({ 747 744 multiLine: false, 748 745 parameters: [ 749 746 { ··· 758 755 ]; 759 756 } else if (clientPlugin.name === 'legacy/angular') { 760 757 members = [ 761 - compiler.constructorDeclaration({ 758 + tsc.constructorDeclaration({ 762 759 multiLine: false, 763 760 parameters: [ 764 761 { ··· 778 775 // add newline between each class member 779 776 if (index) { 780 777 // @ts-expect-error 781 - _members.push(compiler.identifier({ text: '\n' })); 778 + _members.push(tsc.identifier({ text: '\n' })); 782 779 } 783 780 784 781 _members.push(member); 785 782 }); 786 783 787 - const statement = compiler.classDeclaration({ 784 + const statement = tsc.classDeclaration({ 788 785 decorator: 789 786 clientPlugin.name === 'legacy/angular' 790 787 ? { args: [{ providedIn: 'root' }], name: 'Injectable' } ··· 890 887 // define client first 891 888 if (!isLegacy) { 892 889 const clientPlugin = getClientPlugin(config); 893 - const statement = compiler.constVariable({ 890 + const statement = tsc.constVariable({ 894 891 exportConst: true, 895 - expression: compiler.callExpression({ 892 + expression: tsc.callExpression({ 896 893 functionName: 'createClient', 897 894 parameters: [ 898 - compiler.callExpression({ 895 + tsc.callExpression({ 899 896 functionName: 'createConfig', 900 897 parameters: [ 901 898 'throwOnError' in clientPlugin && clientPlugin.throwOnError 902 - ? compiler.objectExpression({ 899 + ? tsc.objectExpression({ 903 900 obj: [ 904 901 { 905 902 key: 'throwOnError',
+39 -39
packages/openapi-ts/src/plugins/@hey-api/sdk/plugin.ts
··· 1 1 import ts from 'typescript'; 2 2 3 - import { compiler } from '../../../compiler'; 4 3 import { clientApi, clientModulePath } from '../../../generate/client'; 4 + import { tsc } from '../../../tsc'; 5 5 import { stringCase } from '../../../utils/stringCase'; 6 6 import { 7 7 createOperationComment, ··· 24 24 }: { 25 25 plugin: HeyApiSdkPlugin['Instance']; 26 26 }): ReadonlyArray<ts.ClassElement> => { 27 - const clientAssignmentStatement = compiler.expressionToStatement({ 28 - expression: compiler.binaryExpression({ 29 - left: compiler.propertyAccessExpression({ 30 - expression: compiler.this(), 27 + const clientAssignmentStatement = tsc.expressionToStatement({ 28 + expression: tsc.binaryExpression({ 29 + left: tsc.propertyAccessExpression({ 30 + expression: tsc.this(), 31 31 name: '_client', 32 32 }), 33 33 operator: '=', 34 - right: compiler.propertyAccessExpression({ 35 - expression: compiler.identifier({ text: 'args' }), 34 + right: tsc.propertyAccessExpression({ 35 + expression: tsc.identifier({ text: 'args' }), 36 36 name: 'client', 37 37 }), 38 38 }), 39 39 }); 40 40 41 41 return [ 42 - compiler.propertyDeclaration({ 42 + tsc.propertyDeclaration({ 43 43 initializer: plugin.config.client 44 - ? compiler.identifier({ text: '_heyApiClient' }) 44 + ? tsc.identifier({ text: '_heyApiClient' }) 45 45 : undefined, 46 46 modifier: 'protected', 47 47 name: '_client', 48 48 type: ts.factory.createTypeReferenceNode('Client'), 49 49 }), 50 50 // @ts-expect-error 51 - compiler.identifier({ text: '\n' }), 52 - compiler.constructorDeclaration({ 51 + tsc.identifier({ text: '\n' }), 52 + tsc.constructorDeclaration({ 53 53 multiLine: true, 54 54 parameters: [ 55 55 { 56 56 isRequired: !plugin.config.client, 57 57 name: 'args', 58 - type: compiler.typeInterfaceNode({ 58 + type: tsc.typeInterfaceNode({ 59 59 properties: [ 60 60 { 61 61 isRequired: !plugin.config.client, ··· 70 70 statements: [ 71 71 !plugin.config.client 72 72 ? clientAssignmentStatement 73 - : compiler.ifStatement({ 74 - expression: compiler.propertyAccessExpression({ 75 - expression: compiler.identifier({ text: 'args' }), 73 + : tsc.ifStatement({ 74 + expression: tsc.propertyAccessExpression({ 75 + expression: tsc.identifier({ text: 'args' }), 76 76 isOptional: true, 77 77 name: 'client', 78 78 }), 79 - thenStatement: compiler.block({ 79 + thenStatement: tsc.block({ 80 80 statements: [clientAssignmentStatement], 81 81 }), 82 82 }), ··· 193 193 operation, 194 194 plugin, 195 195 }); 196 - const functionNode = compiler.methodDeclaration({ 196 + const functionNode = tsc.methodDeclaration({ 197 197 accessLevel: 'public', 198 198 comment: createOperationComment({ operation }), 199 199 isStatic: !plugin.config.instance, ··· 204 204 types: isNuxtClient 205 205 ? [ 206 206 { 207 - // default: compiler.ots.string('$fetch'), 208 - extends: compiler.typeNode('Composable'), 207 + // default: tsc.ots.string('$fetch'), 208 + extends: tsc.typeNode('Composable'), 209 209 name: nuxtTypeComposable, 210 210 }, 211 211 { 212 212 default: responseImport.name 213 - ? compiler.typeReferenceNode({ 213 + ? tsc.typeReferenceNode({ 214 214 typeName: responseImport.name, 215 215 }) 216 - : compiler.typeNode('undefined'), 216 + : tsc.typeNode('undefined'), 217 217 extends: responseImport.name 218 - ? compiler.typeReferenceNode({ 218 + ? tsc.typeReferenceNode({ 219 219 typeName: responseImport.name, 220 220 }) 221 221 : undefined, ··· 239 239 } else { 240 240 currentClass.nodes.push( 241 241 // @ts-expect-error 242 - compiler.identifier({ text: '\n' }), 242 + tsc.identifier({ text: '\n' }), 243 243 functionNode, 244 244 ); 245 245 } ··· 262 262 generateClass(childClass); 263 263 264 264 currentClass.nodes.push( 265 - compiler.propertyDeclaration({ 265 + tsc.propertyDeclaration({ 266 266 initializer: plugin.config.instance 267 - ? compiler.newExpression({ 267 + ? tsc.newExpression({ 268 268 argumentsArray: plugin.config.instance 269 269 ? [ 270 - compiler.objectExpression({ 270 + tsc.objectExpression({ 271 271 multiLine: false, 272 272 obj: [ 273 273 { 274 274 key: 'client', 275 - value: compiler.propertyAccessExpression({ 276 - expression: compiler.this(), 275 + value: tsc.propertyAccessExpression({ 276 + expression: tsc.this(), 277 277 name: '_client', 278 278 }), 279 279 }, ··· 281 281 }), 282 282 ] 283 283 : [], 284 - expression: compiler.identifier({ 284 + expression: tsc.identifier({ 285 285 text: childClass.className, 286 286 }), 287 287 }) 288 - : compiler.identifier({ text: childClass.className }), 288 + : tsc.identifier({ text: childClass.className }), 289 289 modifier: plugin.config.instance ? undefined : 'static', 290 290 name: stringCase({ 291 291 case: 'camelCase', ··· 296 296 } 297 297 } 298 298 299 - const node = compiler.classDeclaration({ 299 + const node = tsc.classDeclaration({ 300 300 exportClass: currentClass.root, 301 301 extendedClasses: plugin.config.instance ? ['_HeyApiClient'] : undefined, 302 302 name: currentClass.className, ··· 307 307 }; 308 308 309 309 if (clientClassNodes.length) { 310 - const node = compiler.classDeclaration({ 310 + const node = tsc.classDeclaration({ 311 311 exportClass: false, 312 312 name: '_HeyApiClient', 313 313 nodes: clientClassNodes, ··· 357 357 operation, 358 358 plugin, 359 359 }); 360 - const node = compiler.constVariable({ 360 + const node = tsc.constVariable({ 361 361 comment: createOperationComment({ operation }), 362 362 exportConst: true, 363 - expression: compiler.arrowFunction({ 363 + expression: tsc.arrowFunction({ 364 364 parameters: opParameters.parameters, 365 365 returnType: undefined, 366 366 statements, 367 367 types: isNuxtClient 368 368 ? [ 369 369 { 370 - // default: compiler.ots.string('$fetch'), 371 - extends: compiler.typeNode('Composable'), 370 + // default: tsc.ots.string('$fetch'), 371 + extends: tsc.typeNode('Composable'), 372 372 name: nuxtTypeComposable, 373 373 }, 374 374 { 375 375 default: responseImport.name 376 - ? compiler.typeReferenceNode({ 376 + ? tsc.typeReferenceNode({ 377 377 typeName: responseImport.name, 378 378 }) 379 - : compiler.typeNode('undefined'), 379 + : tsc.typeNode('undefined'), 380 380 extends: responseImport.name 381 - ? compiler.typeReferenceNode({ 381 + ? tsc.typeReferenceNode({ 382 382 typeName: responseImport.name, 383 383 }) 384 384 : undefined,
+30 -30
packages/openapi-ts/src/plugins/@hey-api/sdk/typeOptions.ts
··· 1 - import { compiler } from '../../../compiler'; 2 1 import { clientModulePath } from '../../../generate/client'; 3 2 import type { FileImportResult } from '../../../generate/file/types'; 3 + import { tsc } from '../../../tsc'; 4 4 import { getClientPlugin } from '../client-core/utils'; 5 5 import { nuxtTypeDefault, nuxtTypeResponse, sdkId } from './constants'; 6 6 import type { HeyApiSdkPlugin } from './types'; ··· 31 31 name: 'Client', 32 32 }); 33 33 34 - const typeOptions = compiler.typeAliasDeclaration({ 34 + const typeOptions = tsc.typeAliasDeclaration({ 35 35 exportType: true, 36 36 name: 'Options', 37 - type: compiler.typeIntersectionNode({ 37 + type: tsc.typeIntersectionNode({ 38 38 types: [ 39 - compiler.typeReferenceNode({ 39 + tsc.typeReferenceNode({ 40 40 typeArguments: isNuxtClient 41 41 ? [ 42 - compiler.typeReferenceNode({ typeName: 'TComposable' }), 43 - compiler.typeReferenceNode({ typeName: 'TData' }), 44 - compiler.typeReferenceNode({ typeName: nuxtTypeResponse }), 45 - compiler.typeReferenceNode({ typeName: nuxtTypeDefault }), 42 + tsc.typeReferenceNode({ typeName: 'TComposable' }), 43 + tsc.typeReferenceNode({ typeName: 'TData' }), 44 + tsc.typeReferenceNode({ typeName: nuxtTypeResponse }), 45 + tsc.typeReferenceNode({ typeName: nuxtTypeDefault }), 46 46 ] 47 47 : [ 48 - compiler.typeReferenceNode({ typeName: 'TData' }), 49 - compiler.typeReferenceNode({ typeName: 'ThrowOnError' }), 48 + tsc.typeReferenceNode({ typeName: 'TData' }), 49 + tsc.typeReferenceNode({ typeName: 'ThrowOnError' }), 50 50 ], 51 51 typeName: clientOptions.name, 52 52 }), 53 - compiler.typeInterfaceNode({ 53 + tsc.typeInterfaceNode({ 54 54 properties: [ 55 55 { 56 56 comment: [ ··· 60 60 ], 61 61 isRequired: !plugin.config.client, 62 62 name: 'client', 63 - type: compiler.typeReferenceNode({ typeName: clientType.name }), 63 + type: tsc.typeReferenceNode({ typeName: clientType.name }), 64 64 }, 65 65 { 66 66 comment: [ ··· 69 69 ], 70 70 isRequired: false, 71 71 name: 'meta', 72 - type: compiler.typeReferenceNode({ 72 + type: tsc.typeReferenceNode({ 73 73 typeArguments: [ 74 - compiler.keywordTypeNode({ keyword: 'string' }), 75 - compiler.keywordTypeNode({ keyword: 'unknown' }), 74 + tsc.keywordTypeNode({ keyword: 'string' }), 75 + tsc.keywordTypeNode({ keyword: 'unknown' }), 76 76 ], 77 77 typeName: 'Record', 78 78 }), ··· 84 84 }), 85 85 typeParameters: isNuxtClient 86 86 ? [ 87 - compiler.typeParameterDeclaration({ 88 - constraint: compiler.typeReferenceNode({ typeName: 'Composable' }), 87 + tsc.typeParameterDeclaration({ 88 + constraint: tsc.typeReferenceNode({ typeName: 'Composable' }), 89 89 name: 'TComposable', 90 90 }), 91 - compiler.typeParameterDeclaration({ 92 - constraint: compiler.typeReferenceNode({ 91 + tsc.typeParameterDeclaration({ 92 + constraint: tsc.typeReferenceNode({ 93 93 typeName: tDataShape.name, 94 94 }), 95 - defaultType: compiler.typeReferenceNode({ 95 + defaultType: tsc.typeReferenceNode({ 96 96 typeName: tDataShape.name, 97 97 }), 98 98 name: 'TData', 99 99 }), 100 - compiler.typeParameterDeclaration({ 101 - defaultType: compiler.keywordTypeNode({ keyword: 'unknown' }), 100 + tsc.typeParameterDeclaration({ 101 + defaultType: tsc.keywordTypeNode({ keyword: 'unknown' }), 102 102 name: nuxtTypeResponse, 103 103 }), 104 - compiler.typeParameterDeclaration({ 105 - defaultType: compiler.keywordTypeNode({ keyword: 'undefined' }), 104 + tsc.typeParameterDeclaration({ 105 + defaultType: tsc.keywordTypeNode({ keyword: 'undefined' }), 106 106 name: nuxtTypeDefault, 107 107 }), 108 108 ] 109 109 : [ 110 - compiler.typeParameterDeclaration({ 111 - constraint: compiler.typeReferenceNode({ 110 + tsc.typeParameterDeclaration({ 111 + constraint: tsc.typeReferenceNode({ 112 112 typeName: tDataShape.name, 113 113 }), 114 - defaultType: compiler.typeReferenceNode({ 114 + defaultType: tsc.typeReferenceNode({ 115 115 typeName: tDataShape.name, 116 116 }), 117 117 name: 'TData', 118 118 }), 119 - compiler.typeParameterDeclaration({ 120 - constraint: compiler.keywordTypeNode({ keyword: 'boolean' }), 121 - defaultType: compiler.keywordTypeNode({ keyword: 'boolean' }), 119 + tsc.typeParameterDeclaration({ 120 + constraint: tsc.keywordTypeNode({ keyword: 'boolean' }), 121 + defaultType: tsc.keywordTypeNode({ keyword: 'boolean' }), 122 122 name: 'ThrowOnError', 123 123 }), 124 124 ],
+10 -10
packages/openapi-ts/src/plugins/@hey-api/transformers/expressions.ts
··· 1 1 import type ts from 'typescript'; 2 2 3 - import { compiler } from '../../../compiler'; 4 3 import type { GeneratedFile } from '../../../generate/file'; 5 4 import type { IR } from '../../../ir/types'; 5 + import { tsc } from '../../../tsc'; 6 6 import type { UserConfig } from './types'; 7 7 8 8 export type ExpressionTransformer = ({ ··· 27 27 28 28 const bigIntCallExpression = 29 29 dataExpression !== undefined 30 - ? compiler.callExpression({ 30 + ? tsc.callExpression({ 31 31 functionName: 'BigInt', 32 32 parameters: [ 33 - compiler.callExpression({ 34 - functionName: compiler.propertyAccessExpression({ 33 + tsc.callExpression({ 34 + functionName: tsc.propertyAccessExpression({ 35 35 expression: dataExpression, 36 36 name: 'toString', 37 37 }), ··· 47 47 48 48 if (dataExpression) { 49 49 return [ 50 - compiler.assignment({ 50 + tsc.assignment({ 51 51 left: dataExpression, 52 52 right: bigIntCallExpression, 53 53 }), ··· 69 69 return; 70 70 } 71 71 72 - const identifierDate = compiler.identifier({ text: 'Date' }); 72 + const identifierDate = tsc.identifier({ text: 'Date' }); 73 73 74 74 if (typeof dataExpression === 'string') { 75 75 return [ 76 - compiler.newExpression({ 77 - argumentsArray: [compiler.identifier({ text: dataExpression })], 76 + tsc.newExpression({ 77 + argumentsArray: [tsc.identifier({ text: dataExpression })], 78 78 expression: identifierDate, 79 79 }), 80 80 ]; ··· 82 82 83 83 if (dataExpression) { 84 84 return [ 85 - compiler.assignment({ 85 + tsc.assignment({ 86 86 left: dataExpression, 87 - right: compiler.newExpression({ 87 + right: tsc.newExpression({ 88 88 argumentsArray: [dataExpression], 89 89 expression: identifierDate, 90 90 }),
+17 -17
packages/openapi-ts/src/plugins/@hey-api/transformers/plugin-legacy.ts
··· 1 1 import type ts from 'typescript'; 2 2 3 - import { compiler } from '../../../compiler'; 4 3 import { createOperationKey } from '../../../ir/operation'; 4 + import { tsc } from '../../../tsc'; 5 5 import type { ModelMeta, OperationResponse } from '../../../types/client'; 6 6 import { getConfig } from '../../../utils/config'; 7 7 import { isModelDate, unsetUniqueTypeName } from '../../../utils/type'; ··· 92 92 } 93 93 94 94 return [ 95 - compiler.transformArrayMutation({ 95 + tsc.transformArrayMutation({ 96 96 path: props.path, 97 97 transformerName: nameModelResponseTransformer, 98 98 }), ··· 107 107 model.link.properties.find((property) => isModelDate(property))) 108 108 ) { 109 109 return [ 110 - compiler.transformArrayMap({ 110 + tsc.transformArrayMap({ 111 111 path: props.path, 112 - transformExpression: compiler.conditionalExpression({ 113 - condition: compiler.identifier({ text: 'item' }), 114 - whenFalse: compiler.identifier({ text: 'item' }), 115 - whenTrue: compiler.transformNewDate({ 112 + transformExpression: tsc.conditionalExpression({ 113 + condition: tsc.identifier({ text: 'item' }), 114 + whenFalse: tsc.identifier({ text: 'item' }), 115 + whenTrue: tsc.transformNewDate({ 116 116 parameterName: 'item', 117 117 }), 118 118 }), ··· 133 133 model.export !== 'array' && 134 134 isModelDate(model) 135 135 ) { 136 - return [compiler.transformDateMutation({ path })]; 136 + return [tsc.transformDateMutation({ path })]; 137 137 } 138 138 139 139 // otherwise we recurse in case it's an object/array, and if it's not that will just bail with [] ··· 172 172 173 173 return model.in === 'response' 174 174 ? [ 175 - compiler.expressionToStatement({ 176 - expression: compiler.callExpression({ 175 + tsc.expressionToStatement({ 176 + expression: tsc.callExpression({ 177 177 functionName: nameModelResponseTransformer, 178 178 parameters: [dataVariableName], 179 179 }), 180 180 }), 181 181 ] 182 - : compiler.transformFunctionMutation({ 182 + : tsc.transformFunctionMutation({ 183 183 path: props.path, 184 184 transformerName: nameModelResponseTransformer, 185 185 }); ··· 218 218 return result; 219 219 } 220 220 221 - const expression = compiler.arrowFunction({ 221 + const expression = tsc.arrowFunction({ 222 222 async, 223 223 multiLine: true, 224 224 parameters: [ ··· 228 228 ], 229 229 statements: [ 230 230 ...statements, 231 - compiler.returnVariable({ 231 + tsc.returnVariable({ 232 232 expression: dataVariableName, 233 233 }), 234 234 ], 235 235 }); 236 - const statement = compiler.constVariable({ 236 + const statement = tsc.constVariable({ 237 237 exportConst: true, 238 238 expression, 239 239 name, ··· 318 318 } 319 319 320 320 return [ 321 - compiler.ifStatement({ 322 - expression: compiler.safeAccessExpression(['data']), 323 - thenStatement: compiler.block({ statements }), 321 + tsc.ifStatement({ 322 + expression: tsc.safeAccessExpression(['data']), 323 + thenStatement: tsc.block({ statements }), 324 324 }), 325 325 ]; 326 326 })
+28 -28
packages/openapi-ts/src/plugins/@hey-api/transformers/plugin.ts
··· 1 1 import ts from 'typescript'; 2 2 3 - import { compiler } from '../../../compiler'; 4 3 import { 5 4 createOperationKey, 6 5 operationResponsesMap, 7 6 } from '../../../ir/operation'; 8 7 import type { IR } from '../../../ir/types'; 8 + import { tsc } from '../../../tsc'; 9 9 import { stringCase } from '../../../utils/stringCase'; 10 10 import { typesId } from '../typescript/ref'; 11 11 import { bigIntExpressions, dateExpressions } from './expressions'; ··· 79 79 nodes.map((node) => 80 80 ts.isStatement(node) 81 81 ? node 82 - : compiler.expressionToStatement({ expression: node }), 82 + : tsc.expressionToStatement({ expression: node }), 83 83 ); 84 84 85 85 const isNodeReturnStatement = ({ ··· 95 95 plugin: HeyApiTransformersPlugin['Instance']; 96 96 schema: IR.SchemaObject; 97 97 }): Array<ts.Expression | ts.Statement> => { 98 - const identifierData = compiler.identifier({ text: dataVariableName }); 98 + const identifierData = tsc.identifier({ text: dataVariableName }); 99 99 const nodes = processSchemaType({ 100 100 dataExpression: identifierData, 101 101 plugin, ··· 106 106 nodes.length && 107 107 !isNodeReturnStatement({ node: nodes[nodes.length - 1]! }) 108 108 ) { 109 - nodes.push(compiler.returnStatement({ expression: identifierData })); 109 + nodes.push(tsc.returnStatement({ expression: identifierData })); 110 110 } 111 111 return nodes; 112 112 }; ··· 139 139 schema: refSchema, 140 140 }); 141 141 if (nodes.length) { 142 - const node = compiler.constVariable({ 143 - expression: compiler.arrowFunction({ 142 + const node = tsc.constVariable({ 143 + expression: tsc.arrowFunction({ 144 144 async: false, 145 145 multiLine: true, 146 146 parameters: [ 147 147 { 148 148 name: dataVariableName, 149 149 // TODO: parser - add types, generate types without transforms 150 - type: compiler.keywordTypeNode({ keyword: 'any' }), 150 + type: tsc.keywordTypeNode({ keyword: 'any' }), 151 151 }, 152 152 ], 153 153 statements: ensureStatements(nodes), ··· 166 166 } 167 167 168 168 if (identifier.name) { 169 - const callExpression = compiler.callExpression({ 169 + const callExpression = tsc.callExpression({ 170 170 functionName: identifier.name, 171 171 parameters: [dataExpression], 172 172 }); ··· 175 175 // In a map callback, the item needs to be returned, not just the transformation result 176 176 if (typeof dataExpression === 'string' && dataExpression === 'item') { 177 177 return [ 178 - compiler.returnStatement({ 178 + tsc.returnStatement({ 179 179 expression: callExpression, 180 180 }), 181 181 ]; ··· 184 184 return [ 185 185 typeof dataExpression === 'string' 186 186 ? callExpression 187 - : compiler.assignment({ 187 + : tsc.assignment({ 188 188 left: dataExpression, 189 189 right: callExpression, 190 190 }), ··· 226 226 227 227 if (!hasReturnStatement) { 228 228 mapCallbackStatements.push( 229 - compiler.returnStatement({ 230 - expression: compiler.identifier({ text: 'item' }), 229 + tsc.returnStatement({ 230 + expression: tsc.identifier({ text: 'item' }), 231 231 }), 232 232 ); 233 233 } 234 234 235 235 return [ 236 - compiler.assignment({ 236 + tsc.assignment({ 237 237 left: dataExpression, 238 - right: compiler.callExpression({ 239 - functionName: compiler.propertyAccessExpression({ 238 + right: tsc.callExpression({ 239 + functionName: tsc.propertyAccessExpression({ 240 240 expression: dataExpression, 241 241 name: 'map', 242 242 }), 243 243 parameters: [ 244 - compiler.arrowFunction({ 244 + tsc.arrowFunction({ 245 245 multiLine: true, 246 246 parameters: [ 247 247 { ··· 263 263 264 264 for (const name in schema.properties) { 265 265 const property = schema.properties[name]!; 266 - const propertyAccessExpression = compiler.propertyAccessExpression({ 266 + const propertyAccessExpression = tsc.propertyAccessExpression({ 267 267 expression: dataExpression || dataVariableName, 268 268 name, 269 269 }); ··· 288 288 // todo: Probably, it would make more sense to go with if(x !== undefined && x !== null) instead of if(x) 289 289 // this place influences all underlying transformers, while it's not exactly transformer itself 290 290 // Keep in mind that !!0 === false, so it already makes output for Bigint undesirable 291 - compiler.ifStatement({ 291 + tsc.ifStatement({ 292 292 expression: propertyAccessExpression, 293 - thenStatement: compiler.block({ 293 + thenStatement: tsc.block({ 294 294 statements: ensureStatements(propertyNodes), 295 295 }), 296 296 }), ··· 329 329 if (dataExpression) { 330 330 arrayNodes = arrayNodes.concat(nodes); 331 331 } else { 332 - const identifierItem = compiler.identifier({ text: 'item' }); 332 + const identifierItem = tsc.identifier({ text: 'item' }); 333 333 // processed means the item was transformed 334 334 arrayNodes.push( 335 - compiler.ifStatement({ 335 + tsc.ifStatement({ 336 336 expression: identifierItem, 337 - thenStatement: compiler.block({ 337 + thenStatement: tsc.block({ 338 338 statements: ensureStatements(nodes), 339 339 }), 340 340 }), 341 - compiler.returnStatement({ expression: identifierItem }), 341 + tsc.returnStatement({ expression: identifierItem }), 342 342 ); 343 343 } 344 344 } ··· 446 446 }), 447 447 name: responseName, 448 448 }); 449 - const responseTransformerNode = compiler.constVariable({ 449 + const responseTransformerNode = tsc.constVariable({ 450 450 exportConst: true, 451 - expression: compiler.arrowFunction({ 451 + expression: tsc.arrowFunction({ 452 452 async: true, 453 453 multiLine: true, 454 454 parameters: [ 455 455 { 456 456 name: dataVariableName, 457 457 // TODO: parser - add types, generate types without transforms 458 - type: compiler.keywordTypeNode({ keyword: 'any' }), 458 + type: tsc.keywordTypeNode({ keyword: 'any' }), 459 459 }, 460 460 ], 461 - returnType: compiler.typeReferenceNode({ 461 + returnType: tsc.typeReferenceNode({ 462 462 typeArguments: [ 463 - compiler.typeReferenceNode({ 463 + tsc.typeReferenceNode({ 464 464 typeName: responseName, 465 465 }), 466 466 ],
+9 -9
packages/openapi-ts/src/plugins/@hey-api/typescript/clientOptions.ts
··· 1 1 import ts from 'typescript'; 2 2 3 - import { compiler } from '../../../compiler'; 4 3 import type { NodeInfo } from '../../../generate/file/types'; 5 4 import type { IR } from '../../../ir/types'; 5 + import { tsc } from '../../../tsc'; 6 6 import { parseUrl } from '../../../utils/url'; 7 7 import { getClientBaseUrlKey, getClientPlugin } from '../client-core/utils'; 8 8 import { typesId } from './ref'; 9 9 import type { HeyApiTypeScriptPlugin } from './types'; 10 10 11 - const stringType = compiler.keywordTypeNode({ keyword: 'string' }); 11 + const stringType = tsc.keywordTypeNode({ keyword: 'string' }); 12 12 13 13 const serverToBaseUrlType = ({ server }: { server: IR.ServerObject }) => { 14 14 const url = parseUrl(server.url); 15 15 16 16 if (url.protocol && url.host) { 17 - return compiler.literalTypeNode({ 18 - literal: compiler.stringLiteral({ text: server.url }), 17 + return tsc.literalTypeNode({ 18 + literal: tsc.stringLiteral({ text: server.url }), 19 19 }); 20 20 } 21 21 22 - return compiler.templateLiteralType({ 22 + return tsc.templateLiteralType({ 23 23 value: [ 24 24 url.protocol || stringType, 25 25 '://', ··· 53 53 !('strictBaseUrl' in client.config && client.config.strictBaseUrl) 54 54 ) { 55 55 types.push( 56 - compiler.typeIntersectionNode({ 56 + tsc.typeIntersectionNode({ 57 57 types: [stringType, ts.factory.createTypeLiteralNode([])], 58 58 }), 59 59 ); 60 60 } 61 61 62 - const type = compiler.typeInterfaceNode({ 62 + const type = tsc.typeInterfaceNode({ 63 63 properties: [ 64 64 { 65 65 name: getClientBaseUrlKey(plugin.context.config), 66 - type: compiler.typeUnionNode({ types }), 66 + type: tsc.typeUnionNode({ types }), 67 67 }, 68 68 ], 69 69 useLegacyResolution: false, 70 70 }); 71 - const node = compiler.typeAliasDeclaration({ 71 + const node = tsc.typeAliasDeclaration({ 72 72 exportType: nodeInfo.exported, 73 73 name: nodeInfo.node, 74 74 type,
+8 -8
packages/openapi-ts/src/plugins/@hey-api/typescript/operation.ts
··· 1 1 import ts from 'typescript'; 2 2 3 - import { compiler } from '../../../compiler'; 4 3 import { operationResponsesMap } from '../../../ir/operation'; 5 4 import { deduplicateSchema } from '../../../ir/schema'; 6 5 import type { IR } from '../../../ir/types'; 7 6 import { buildName } from '../../../openApi/shared/utils/name'; 7 + import { tsc } from '../../../tsc'; 8 8 import { schemaToType } from './plugin'; 9 9 import { typesId } from './ref'; 10 10 import type { HeyApiTypeScriptPlugin, PluginState } from './types'; ··· 142 142 schema: data, 143 143 state, 144 144 }); 145 - const node = compiler.typeAliasDeclaration({ 145 + const node = tsc.typeAliasDeclaration({ 146 146 exportType: nodeInfo.exported, 147 147 name: nodeInfo.node, 148 148 type, ··· 184 184 schema: errors, 185 185 state, 186 186 }); 187 - const node = compiler.typeAliasDeclaration({ 187 + const node = tsc.typeAliasDeclaration({ 188 188 exportType: nodeInfo.exported, 189 189 name: nodeInfo.node, 190 190 type, ··· 206 206 name, 207 207 }, 208 208 ); 209 - const type = compiler.indexedAccessTypeNode({ 209 + const type = tsc.indexedAccessTypeNode({ 210 210 indexType: ts.factory.createTypeOperatorNode( 211 211 ts.SyntaxKind.KeyOfKeyword, 212 212 nodeInfo.node, 213 213 ), 214 214 objectType: nodeInfo.node, 215 215 }); 216 - const node = compiler.typeAliasDeclaration({ 216 + const node = tsc.typeAliasDeclaration({ 217 217 exportType: errorNodeInfo.exported, 218 218 name: errorNodeInfo.node, 219 219 type, ··· 240 240 schema: responses, 241 241 state, 242 242 }); 243 - const node = compiler.typeAliasDeclaration({ 243 + const node = tsc.typeAliasDeclaration({ 244 244 exportType: nodeInfo.exported, 245 245 name: nodeInfo.node, 246 246 type, ··· 262 262 name, 263 263 }, 264 264 ); 265 - const type = compiler.indexedAccessTypeNode({ 265 + const type = tsc.indexedAccessTypeNode({ 266 266 indexType: ts.factory.createTypeOperatorNode( 267 267 ts.SyntaxKind.KeyOfKeyword, 268 268 nodeInfo.node, 269 269 ), 270 270 objectType: nodeInfo.node, 271 271 }); 272 - const node = compiler.typeAliasDeclaration({ 272 + const node = tsc.typeAliasDeclaration({ 273 273 exportType: responseNodeInfo.exported, 274 274 name: responseNodeInfo.node, 275 275 type,
+9 -9
packages/openapi-ts/src/plugins/@hey-api/typescript/plugin-legacy.ts
··· 1 1 import type ts from 'typescript'; 2 2 3 - import { type Comments, compiler } from '../../../compiler'; 4 3 import { GeneratedFile } from '../../../generate/file'; 5 4 import { isOperationParameterRequired } from '../../../openApi'; 5 + import { type Comments, tsc } from '../../../tsc'; 6 6 import type { 7 7 Client, 8 8 Method, ··· 61 61 obj, 62 62 onNode, 63 63 ...setUniqueTypeNameArgs 64 - }: Omit<Parameters<typeof compiler.enumDeclaration>[0], 'name'> & 64 + }: Omit<Parameters<typeof tsc.enumDeclaration>[0], 'name'> & 65 65 Pick<Parameters<typeof setUniqueTypeName>[0], 'client' | 'nameTransformer'> & 66 66 Pick<Model, 'meta'> & 67 67 Pick<TypesProps, 'onNode'>) => { ··· 76 76 ...setUniqueTypeNameArgs, 77 77 }); 78 78 if (created) { 79 - const node = compiler.enumDeclaration({ 79 + const node = tsc.enumDeclaration({ 80 80 comments, 81 81 leadingComment, 82 82 name, ··· 93 93 onNode, 94 94 type, 95 95 ...setUniqueTypeNameArgs 96 - }: Omit<Parameters<typeof compiler.typeAliasDeclaration>[0], 'name'> & 96 + }: Omit<Parameters<typeof tsc.typeAliasDeclaration>[0], 'name'> & 97 97 Pick<Parameters<typeof setUniqueTypeName>[0], 'client' | 'nameTransformer'> & 98 98 Pick<Model, 'meta'> & 99 99 Pick<TypesProps, 'onNode'> & { ··· 114 114 }); 115 115 const { created, name } = result; 116 116 if (created) { 117 - const node = compiler.typeAliasDeclaration({ 117 + const node = tsc.typeAliasDeclaration({ 118 118 comment, 119 119 exportType: true, 120 120 name, ··· 144 144 145 145 if (enumDeclarations.length) { 146 146 props.onNode( 147 - compiler.namespaceDeclaration({ 147 + tsc.namespaceDeclaration({ 148 148 name: props.model.name, 149 149 statements: enumDeclarations, 150 150 }), ··· 202 202 pluginTypeScript.config.enums.enabled && 203 203 pluginTypeScript.config.enums.mode === 'javascript' 204 204 ) { 205 - const expression = compiler.objectExpression({ 205 + const expression = tsc.objectExpression({ 206 206 multiLine: true, 207 207 obj: Object.entries(properties).map(([key, value]) => ({ 208 208 comments: comments[key], ··· 211 211 })), 212 212 unescape: true, 213 213 }); 214 - const node = compiler.constVariable({ 214 + const node = tsc.constVariable({ 215 215 assertion: 'const', 216 216 comment, 217 217 exportConst: true, ··· 238 238 } 239 239 }); 240 240 onNode( 241 - compiler.enumDeclaration({ 241 + tsc.enumDeclaration({ 242 242 comments, 243 243 leadingComment: [ 244 244 model.description && escapeComment(model.description),
+51 -53
packages/openapi-ts/src/plugins/@hey-api/typescript/plugin.ts
··· 1 1 import ts from 'typescript'; 2 2 3 - import type { Property } from '../../../compiler'; 4 - import { compiler } from '../../../compiler'; 5 3 import { deduplicateSchema } from '../../../ir/schema'; 6 4 import type { IR } from '../../../ir/types'; 7 5 import { ensureValidIdentifier } from '../../../openApi/shared/utils/identifier'; 8 6 import { buildName } from '../../../openApi/shared/utils/name'; 7 + import type { Property } from '../../../tsc'; 8 + import { tsc } from '../../../tsc'; 9 9 import { refToName } from '../../../utils/ref'; 10 10 import { numberRegExp } from '../../../utils/regexp'; 11 11 import { stringCase } from '../../../utils/stringCase'; ··· 106 106 state: PluginState; 107 107 }): ts.TypeNode => { 108 108 if (!schema.items) { 109 - return compiler.typeArrayNode( 110 - compiler.keywordTypeNode({ 109 + return tsc.typeArrayNode( 110 + tsc.keywordTypeNode({ 111 111 keyword: 'unknown', 112 112 }), 113 113 ); ··· 128 128 } 129 129 130 130 if (itemTypes.length === 1) { 131 - return compiler.typeArrayNode(itemTypes[0]!); 131 + return tsc.typeArrayNode(itemTypes[0]!); 132 132 } 133 133 134 134 if (schema.logicalOperator === 'and') { 135 - return compiler.typeArrayNode( 136 - compiler.typeIntersectionNode({ types: itemTypes }), 137 - ); 135 + return tsc.typeArrayNode(tsc.typeIntersectionNode({ types: itemTypes })); 138 136 } 139 137 140 - return compiler.typeArrayNode(compiler.typeUnionNode({ types: itemTypes })); 138 + return tsc.typeArrayNode(tsc.typeUnionNode({ types: itemTypes })); 141 139 }; 142 140 143 141 const booleanTypeToIdentifier = ({ ··· 146 144 schema: SchemaWithType<'boolean'>; 147 145 }): ts.TypeNode => { 148 146 if (schema.const !== undefined) { 149 - return compiler.literalTypeNode({ 150 - literal: compiler.ots.boolean(schema.const as boolean), 147 + return tsc.literalTypeNode({ 148 + literal: tsc.ots.boolean(schema.const as boolean), 151 149 }); 152 150 } 153 151 154 - return compiler.keywordTypeNode({ 152 + return tsc.keywordTypeNode({ 155 153 keyword: 'boolean', 156 154 }); 157 155 }; ··· 187 185 schema: SchemaWithType<'integer' | 'number'>; 188 186 }): ts.TypeNode => { 189 187 if (schema.const !== undefined) { 190 - return compiler.literalTypeNode({ 191 - literal: compiler.ots.number(schema.const as number), 188 + return tsc.literalTypeNode({ 189 + literal: tsc.ots.number(schema.const as number), 192 190 }); 193 191 } 194 192 195 193 if (schema.type === 'integer' && schema.format === 'int64') { 196 194 // TODO: parser - add ability to skip type transformers 197 195 if (plugin.getPlugin('@hey-api/transformers')?.config.bigInt) { 198 - return compiler.typeReferenceNode({ typeName: 'bigint' }); 196 + return tsc.typeReferenceNode({ typeName: 'bigint' }); 199 197 } 200 198 } 201 199 202 - return compiler.keywordTypeNode({ 200 + return tsc.keywordTypeNode({ 203 201 keyword: 'number', 204 202 }); 205 203 }; ··· 291 289 } 292 290 } 293 291 294 - return compiler.typeInterfaceNode({ 292 + return tsc.typeInterfaceNode({ 295 293 indexKey, 296 294 indexProperty, 297 295 properties: schemaProperties, ··· 309 307 state: PluginState; 310 308 }): ts.TypeNode => { 311 309 if (schema.const !== undefined) { 312 - return compiler.literalTypeNode({ 313 - literal: compiler.stringLiteral({ text: schema.const as string }), 310 + return tsc.literalTypeNode({ 311 + literal: tsc.stringLiteral({ text: schema.const as string }), 314 312 }); 315 313 } 316 314 317 315 if (schema.format) { 318 316 if (schema.format === 'binary') { 319 - return compiler.typeUnionNode({ 317 + return tsc.typeUnionNode({ 320 318 types: [ 321 - compiler.typeReferenceNode({ 319 + tsc.typeReferenceNode({ 322 320 typeName: 'Blob', 323 321 }), 324 - compiler.typeReferenceNode({ 322 + tsc.typeReferenceNode({ 325 323 typeName: 'File', 326 324 }), 327 325 ], ··· 331 329 if (schema.format === 'date-time' || schema.format === 'date') { 332 330 // TODO: parser - add ability to skip type transformers 333 331 if (plugin.getPlugin('@hey-api/transformers')?.config.dates) { 334 - return compiler.typeReferenceNode({ typeName: 'Date' }); 332 + return tsc.typeReferenceNode({ typeName: 'Date' }); 335 333 } 336 334 } 337 335 ··· 346 344 value: type + '_id', 347 345 }), 348 346 ); 349 - return compiler.typeReferenceNode({ 347 + return tsc.typeReferenceNode({ 350 348 typeName, 351 349 }); 352 350 } 353 351 } 354 352 355 - return compiler.keywordTypeNode({ 353 + return tsc.keywordTypeNode({ 356 354 keyword: 'string', 357 355 }); 358 356 }; ··· 372 370 373 371 if (schema.const && Array.isArray(schema.const)) { 374 372 itemTypes = schema.const.map((value) => { 375 - const expression = compiler.valueToExpression({ value }); 376 - return expression ?? compiler.identifier({ text: 'unknown' }); 373 + const expression = tsc.valueToExpression({ value }); 374 + return expression ?? tsc.identifier({ text: 'unknown' }); 377 375 }); 378 376 } else if (schema.items) { 379 377 for (const item of schema.items) { ··· 387 385 } 388 386 } 389 387 390 - return compiler.typeTupleNode({ 388 + return tsc.typeTupleNode({ 391 389 types: itemTypes, 392 390 }); 393 391 }; ··· 429 427 schema: schema as SchemaWithType<'integer' | 'number'>, 430 428 }); 431 429 case 'never': 432 - return compiler.keywordTypeNode({ 430 + return tsc.keywordTypeNode({ 433 431 keyword: 'never', 434 432 }); 435 433 case 'null': 436 - return compiler.literalTypeNode({ 437 - literal: compiler.null(), 434 + return tsc.literalTypeNode({ 435 + literal: tsc.null(), 438 436 }); 439 437 case 'object': 440 438 return objectTypeToIdentifier({ ··· 457 455 state, 458 456 }); 459 457 case 'undefined': 460 - return compiler.keywordTypeNode({ 458 + return tsc.keywordTypeNode({ 461 459 keyword: 'undefined', 462 460 }); 463 461 case 'unknown': 464 - return compiler.keywordTypeNode({ 462 + return tsc.keywordTypeNode({ 465 463 keyword: 'unknown', 466 464 }); 467 465 case 'void': 468 - return compiler.keywordTypeNode({ 466 + return tsc.keywordTypeNode({ 469 467 keyword: 'void', 470 468 }); 471 469 } ··· 511 509 } 512 510 513 511 return schema.logicalOperator === 'and' 514 - ? compiler.typeIntersectionNode({ types: itemTypes }) 515 - : compiler.typeUnionNode({ types: itemTypes }); 512 + ? tsc.typeIntersectionNode({ types: itemTypes }) 513 + : tsc.typeUnionNode({ types: itemTypes }); 516 514 } 517 515 518 516 return schemaToType({ onRef, plugin, schema, state }); ··· 557 555 enumObject.obj = enumObject.obj.filter((item) => item.value !== null); 558 556 } 559 557 560 - const objectNode = compiler.constVariable({ 558 + const objectNode = tsc.constVariable({ 561 559 assertion: 'const', 562 560 comment: createSchemaComment({ schema }), 563 561 exportConst: nodeInfo.exported, 564 - expression: compiler.objectExpression({ 562 + expression: tsc.objectExpression({ 565 563 multiLine: true, 566 564 obj: enumObject.obj, 567 565 }), ··· 570 568 file.add(objectNode); 571 569 572 570 // TODO: https://github.com/hey-api/openapi-ts/issues/2289 573 - const typeofType = compiler.typeOfExpression({ 571 + const typeofType = tsc.typeOfExpression({ 574 572 text: nodeInfo.node.typeName as unknown as string, 575 573 }) as unknown as ts.TypeNode; 576 574 const keyofType = ts.factory.createTypeOperatorNode( 577 575 ts.SyntaxKind.KeyOfKeyword, 578 576 typeofType, 579 577 ); 580 - const node = compiler.typeAliasDeclaration({ 578 + const node = tsc.typeAliasDeclaration({ 581 579 comment: createSchemaComment({ schema }), 582 580 exportType: nodeInfo.exported, 583 581 name: nodeInfo.node, 584 - type: compiler.indexedAccessTypeNode({ 582 + type: tsc.indexedAccessTypeNode({ 585 583 indexType: keyofType, 586 584 objectType: typeofType, 587 585 }), ··· 594 592 (type) => type !== 'number' && type !== 'string', 595 593 ); 596 594 if (shouldCreateTypeScriptEnum) { 597 - const enumNode = compiler.enumDeclaration({ 595 + const enumNode = tsc.enumDeclaration({ 598 596 leadingComment: createSchemaComment({ schema }), 599 597 name: nodeInfo.node, 600 598 obj: enumObject.obj, ··· 605 603 } 606 604 } 607 605 608 - const node = compiler.typeAliasDeclaration({ 606 + const node = tsc.typeAliasDeclaration({ 609 607 comment: createSchemaComment({ schema }), 610 608 exportType: nodeInfo.exported, 611 609 name: nodeInfo.node, ··· 708 706 ); 709 707 710 708 if (state.usedTypeIDs.size) { 711 - const typeParameter = compiler.typeParameterDeclaration({ 712 - constraint: compiler.keywordTypeNode({ 709 + const typeParameter = tsc.typeParameterDeclaration({ 710 + constraint: tsc.keywordTypeNode({ 713 711 keyword: 'string', 714 712 }), 715 713 name: 'T', 716 714 }); 717 - const node = compiler.typeAliasDeclaration({ 715 + const node = tsc.typeAliasDeclaration({ 718 716 exportType: true, 719 717 name: 'TypeID', 720 - type: compiler.templateLiteralType({ 718 + type: tsc.templateLiteralType({ 721 719 value: [ 722 - compiler.typeReferenceNode({ 720 + tsc.typeReferenceNode({ 723 721 typeName: 'T', 724 722 }), 725 723 '_', 726 - compiler.keywordTypeNode({ 724 + tsc.keywordTypeNode({ 727 725 keyword: 'string', 728 726 }), 729 727 ], ··· 739 737 value: name + '_id', 740 738 }), 741 739 ); 742 - const node = compiler.typeAliasDeclaration({ 740 + const node = tsc.typeAliasDeclaration({ 743 741 exportType: true, 744 742 name: typeName, 745 - type: compiler.typeReferenceNode({ 743 + type: tsc.typeReferenceNode({ 746 744 typeArguments: [ 747 - compiler.literalTypeNode({ 748 - literal: compiler.stringLiteral({ text: name }), 745 + tsc.literalTypeNode({ 746 + literal: tsc.stringLiteral({ text: name }), 749 747 }), 750 748 ], 751 749 typeName: 'TypeID',
+78 -78
packages/openapi-ts/src/plugins/@tanstack/query-core/infiniteQueryOptions.ts
··· 1 1 import ts from 'typescript'; 2 2 3 - import { compiler } from '../../../compiler'; 4 - import { tsNodeToString } from '../../../compiler/utils'; 5 3 import { clientApi } from '../../../generate/client'; 6 4 import { operationPagination } from '../../../ir/operation'; 7 5 import type { IR } from '../../../ir/types'; 6 + import { tsc } from '../../../tsc'; 7 + import { tsNodeToString } from '../../../tsc/utils'; 8 8 import { 9 9 createOperationComment, 10 10 isOperationOptionsRequired, ··· 36 36 namespace: 'value', 37 37 }); 38 38 39 - const fn = compiler.constVariable({ 40 - expression: compiler.arrowFunction({ 39 + const fn = tsc.constVariable({ 40 + expression: tsc.arrowFunction({ 41 41 multiLine: true, 42 42 parameters: [ 43 43 { 44 44 name: 'queryKey', 45 - type: compiler.typeReferenceNode({ 45 + type: tsc.typeReferenceNode({ 46 46 typeName: `QueryKey<${clientApi.Options.name}>`, 47 47 }), 48 48 }, 49 49 { 50 50 name: 'page', 51 - type: compiler.typeReferenceNode({ typeName: 'K' }), 51 + type: tsc.typeReferenceNode({ typeName: 'K' }), 52 52 }, 53 53 ], 54 54 statements: [ 55 - compiler.constVariable({ 56 - expression: compiler.objectExpression({ 55 + tsc.constVariable({ 56 + expression: tsc.objectExpression({ 57 57 obj: [ 58 58 { 59 - spread: compiler.propertyAccessExpression({ 59 + spread: tsc.propertyAccessExpression({ 60 60 expression: 'queryKey', 61 61 name: 0, 62 62 }), ··· 65 65 }), 66 66 name: 'params', 67 67 }), 68 - compiler.ifStatement({ 69 - expression: compiler.propertyAccessExpression({ 70 - expression: compiler.identifier({ 68 + tsc.ifStatement({ 69 + expression: tsc.propertyAccessExpression({ 70 + expression: tsc.identifier({ 71 71 text: 'page', 72 72 }), 73 - name: compiler.identifier({ text: 'body' }), 73 + name: tsc.identifier({ text: 'body' }), 74 74 }), 75 - thenStatement: compiler.block({ 75 + thenStatement: tsc.block({ 76 76 statements: [ 77 - compiler.expressionToStatement({ 78 - expression: compiler.binaryExpression({ 79 - left: compiler.propertyAccessExpression({ 77 + tsc.expressionToStatement({ 78 + expression: tsc.binaryExpression({ 79 + left: tsc.propertyAccessExpression({ 80 80 expression: 'params', 81 81 name: 'body', 82 82 }), 83 - right: compiler.objectExpression({ 83 + right: tsc.objectExpression({ 84 84 multiLine: true, 85 85 obj: [ 86 86 { ··· 98 98 ], 99 99 }), 100 100 }), 101 - compiler.ifStatement({ 102 - expression: compiler.propertyAccessExpression({ 103 - expression: compiler.identifier({ 101 + tsc.ifStatement({ 102 + expression: tsc.propertyAccessExpression({ 103 + expression: tsc.identifier({ 104 104 text: 'page', 105 105 }), 106 - name: compiler.identifier({ text: 'headers' }), 106 + name: tsc.identifier({ text: 'headers' }), 107 107 }), 108 - thenStatement: compiler.block({ 108 + thenStatement: tsc.block({ 109 109 statements: [ 110 - compiler.expressionToStatement({ 111 - expression: compiler.binaryExpression({ 112 - left: compiler.propertyAccessExpression({ 110 + tsc.expressionToStatement({ 111 + expression: tsc.binaryExpression({ 112 + left: tsc.propertyAccessExpression({ 113 113 expression: 'params', 114 114 name: 'headers', 115 115 }), 116 - right: compiler.objectExpression({ 116 + right: tsc.objectExpression({ 117 117 multiLine: true, 118 118 obj: [ 119 119 { ··· 129 129 ], 130 130 }), 131 131 }), 132 - compiler.ifStatement({ 133 - expression: compiler.propertyAccessExpression({ 134 - expression: compiler.identifier({ 132 + tsc.ifStatement({ 133 + expression: tsc.propertyAccessExpression({ 134 + expression: tsc.identifier({ 135 135 text: 'page', 136 136 }), 137 - name: compiler.identifier({ text: 'path' }), 137 + name: tsc.identifier({ text: 'path' }), 138 138 }), 139 - thenStatement: compiler.block({ 139 + thenStatement: tsc.block({ 140 140 statements: [ 141 - compiler.expressionToStatement({ 142 - expression: compiler.binaryExpression({ 143 - left: compiler.propertyAccessExpression({ 141 + tsc.expressionToStatement({ 142 + expression: tsc.binaryExpression({ 143 + left: tsc.propertyAccessExpression({ 144 144 expression: 'params', 145 145 name: 'path', 146 146 }), 147 - right: compiler.objectExpression({ 147 + right: tsc.objectExpression({ 148 148 multiLine: true, 149 149 obj: [ 150 150 { ··· 162 162 ], 163 163 }), 164 164 }), 165 - compiler.ifStatement({ 166 - expression: compiler.propertyAccessExpression({ 167 - expression: compiler.identifier({ 165 + tsc.ifStatement({ 166 + expression: tsc.propertyAccessExpression({ 167 + expression: tsc.identifier({ 168 168 text: 'page', 169 169 }), 170 - name: compiler.identifier({ text: 'query' }), 170 + name: tsc.identifier({ text: 'query' }), 171 171 }), 172 - thenStatement: compiler.block({ 172 + thenStatement: tsc.block({ 173 173 statements: [ 174 - compiler.expressionToStatement({ 175 - expression: compiler.binaryExpression({ 176 - left: compiler.propertyAccessExpression({ 174 + tsc.expressionToStatement({ 175 + expression: tsc.binaryExpression({ 176 + left: tsc.propertyAccessExpression({ 177 177 expression: 'params', 178 178 name: 'query', 179 179 }), 180 - right: compiler.objectExpression({ 180 + right: tsc.objectExpression({ 181 181 multiLine: true, 182 182 obj: [ 183 183 { ··· 195 195 ], 196 196 }), 197 197 }), 198 - compiler.returnVariable({ 199 - expression: compiler.asExpression({ 200 - expression: compiler.asExpression({ 201 - expression: compiler.identifier({ text: 'params' }), 202 - type: compiler.keywordTypeNode({ keyword: 'unknown' }), 198 + tsc.returnVariable({ 199 + expression: tsc.asExpression({ 200 + expression: tsc.asExpression({ 201 + expression: tsc.identifier({ text: 'params' }), 202 + type: tsc.keywordTypeNode({ keyword: 'unknown' }), 203 203 }), 204 204 type: ts.factory.createTypeQueryNode( 205 - compiler.identifier({ text: 'page' }), 205 + tsc.identifier({ text: 'page' }), 206 206 ), 207 207 }), 208 208 }), 209 209 ], 210 210 types: [ 211 211 { 212 - extends: compiler.typeReferenceNode({ 213 - typeName: compiler.identifier({ 212 + extends: tsc.typeReferenceNode({ 213 + typeName: tsc.identifier({ 214 214 text: `Pick<QueryKey<${clientApi.Options.name}>[0], 'body' | 'headers' | 'path' | 'query'>`, 215 215 }), 216 216 }), ··· 294 294 const typePageObjectParam = `Pick<${typeQueryKey}[0], 'body' | 'headers' | 'path' | 'query'>`; 295 295 const pluginTypeScript = plugin.getPlugin('@hey-api/typescript')!; 296 296 // TODO: parser - this is a bit clunky, need to compile type to string because 297 - // `compiler.returnFunctionCall()` accepts only strings, should be cleaned up 297 + // `tsc.returnFunctionCall()` accepts only strings, should be cleaned up 298 298 const typescriptState = { 299 299 usedTypeIDs: new Set<string>(), 300 300 }; ··· 324 324 namespace: 'value', 325 325 }); 326 326 327 - const awaitSdkExpression = compiler.awaitExpression({ 328 - expression: compiler.callExpression({ 327 + const awaitSdkExpression = tsc.awaitExpression({ 328 + expression: tsc.callExpression({ 329 329 functionName: queryFn, 330 330 parameters: [ 331 - compiler.objectExpression({ 331 + tsc.objectExpression({ 332 332 multiLine: true, 333 333 obj: [ 334 334 { ··· 340 340 { 341 341 key: 'signal', 342 342 shorthand: true, 343 - value: compiler.identifier({ 343 + value: tsc.identifier({ 344 344 text: 'signal', 345 345 }), 346 346 }, ··· 362 362 }); 363 363 364 364 const statements: Array<ts.Statement> = [ 365 - compiler.constVariable({ 365 + tsc.constVariable({ 366 366 comment: [ 367 367 { 368 368 jsdoc: false, 369 369 lines: ['@ts-ignore'], 370 370 }, 371 371 ], 372 - expression: compiler.conditionalExpression({ 373 - condition: compiler.binaryExpression({ 374 - left: compiler.typeOfExpression({ 372 + expression: tsc.conditionalExpression({ 373 + condition: tsc.binaryExpression({ 374 + left: tsc.typeOfExpression({ 375 375 text: 'pageParam', 376 376 }), 377 377 operator: '===', 378 - right: compiler.ots.string('object'), 378 + right: tsc.ots.string('object'), 379 379 }), 380 - whenFalse: compiler.objectExpression({ 380 + whenFalse: tsc.objectExpression({ 381 381 multiLine: true, 382 382 obj: [ 383 383 { 384 384 key: pagination.in, 385 - value: compiler.objectExpression({ 385 + value: tsc.objectExpression({ 386 386 multiLine: true, 387 387 obj: [ 388 388 { 389 389 key: pagination.name, 390 - value: compiler.identifier({ 390 + value: tsc.identifier({ 391 391 text: 'pageParam', 392 392 }), 393 393 }, ··· 396 396 }, 397 397 ], 398 398 }), 399 - whenTrue: compiler.identifier({ 399 + whenTrue: tsc.identifier({ 400 400 text: 'pageParam', 401 401 }), 402 402 }), 403 403 name: 'page', 404 404 typeName: typePageObjectParam, 405 405 }), 406 - compiler.constVariable({ 407 - expression: compiler.callExpression({ 406 + tsc.constVariable({ 407 + expression: tsc.callExpression({ 408 408 functionName: identifierCreateInfiniteParams.name || '', 409 409 parameters: ['queryKey', 'page'], 410 410 }), ··· 414 414 415 415 if (plugin.getPlugin('@hey-api/sdk')?.config.responseStyle === 'data') { 416 416 statements.push( 417 - compiler.returnVariable({ 417 + tsc.returnVariable({ 418 418 expression: awaitSdkExpression, 419 419 }), 420 420 ); 421 421 } else { 422 422 statements.push( 423 - compiler.constVariable({ 423 + tsc.constVariable({ 424 424 destructure: true, 425 425 expression: awaitSdkExpression, 426 426 name: 'data', 427 427 }), 428 - compiler.returnVariable({ 428 + tsc.returnVariable({ 429 429 expression: 'data', 430 430 }), 431 431 ); ··· 440 440 namespace: 'value', 441 441 }); 442 442 443 - const statement = compiler.constVariable({ 443 + const statement = tsc.constVariable({ 444 444 comment: plugin.config.comments 445 445 ? createOperationComment({ operation }) 446 446 : undefined, 447 447 exportConst: true, 448 - expression: compiler.arrowFunction({ 448 + expression: tsc.arrowFunction({ 449 449 parameters: [ 450 450 { 451 451 isRequired: isRequiredOptions, ··· 454 454 }, 455 455 ], 456 456 statements: [ 457 - compiler.returnFunctionCall({ 457 + tsc.returnFunctionCall({ 458 458 args: [ 459 - compiler.objectExpression({ 459 + tsc.objectExpression({ 460 460 comments: [ 461 461 { 462 462 jsdoc: false, ··· 466 466 obj: [ 467 467 { 468 468 key: 'queryFn', 469 - value: compiler.arrowFunction({ 469 + value: tsc.arrowFunction({ 470 470 async: true, 471 471 multiLine: true, 472 472 parameters: [ ··· 489 489 }, 490 490 { 491 491 key: 'queryKey', 492 - value: compiler.callExpression({ 492 + value: tsc.callExpression({ 493 493 functionName: identifierInfiniteQueryKey.name || '', 494 494 parameters: ['options'], 495 495 }),
+13 -13
packages/openapi-ts/src/plugins/@tanstack/query-core/mutationOptions.ts
··· 1 1 import type ts from 'typescript'; 2 2 3 - import { compiler } from '../../../compiler'; 4 3 import type { IR } from '../../../ir/types'; 4 + import { tsc } from '../../../tsc'; 5 5 import { createOperationComment } from '../../shared/utils/operation'; 6 6 import type { PluginInstance, PluginState } from './types'; 7 7 import { useTypeData, useTypeError, useTypeResponse } from './useType'; ··· 57 57 // TODO: better types syntax 58 58 const mutationType = `${mutationsType}<${typeResponse}, ${typeError.name}, ${typeData}>`; 59 59 60 - const awaitSdkExpression = compiler.awaitExpression({ 61 - expression: compiler.callExpression({ 60 + const awaitSdkExpression = tsc.awaitExpression({ 61 + expression: tsc.callExpression({ 62 62 functionName: queryFn, 63 63 parameters: [ 64 - compiler.objectExpression({ 64 + tsc.objectExpression({ 65 65 multiLine: true, 66 66 obj: [ 67 67 { ··· 84 84 85 85 if (plugin.getPlugin('@hey-api/sdk')?.config.responseStyle === 'data') { 86 86 statements.push( 87 - compiler.returnVariable({ 87 + tsc.returnVariable({ 88 88 expression: awaitSdkExpression, 89 89 }), 90 90 ); 91 91 } else { 92 92 statements.push( 93 - compiler.constVariable({ 93 + tsc.constVariable({ 94 94 destructure: true, 95 95 expression: awaitSdkExpression, 96 96 name: 'data', 97 97 }), 98 - compiler.returnVariable({ 98 + tsc.returnVariable({ 99 99 expression: 'data', 100 100 }), 101 101 ); ··· 110 110 namespace: 'value', 111 111 }); 112 112 113 - const expression = compiler.arrowFunction({ 113 + const expression = tsc.arrowFunction({ 114 114 parameters: [ 115 115 { 116 116 isRequired: false, ··· 120 120 ], 121 121 returnType: mutationType, 122 122 statements: [ 123 - compiler.constVariable({ 124 - expression: compiler.objectExpression({ 123 + tsc.constVariable({ 124 + expression: tsc.objectExpression({ 125 125 obj: [ 126 126 { 127 127 key: 'mutationFn', 128 - value: compiler.arrowFunction({ 128 + value: tsc.arrowFunction({ 129 129 async: true, 130 130 multiLine: true, 131 131 parameters: [ ··· 141 141 name: mutationOptionsFn, 142 142 typeName: mutationType, 143 143 }), 144 - compiler.returnVariable({ 144 + tsc.returnVariable({ 145 145 expression: mutationOptionsFn, 146 146 }), 147 147 ], 148 148 }); 149 - const statement = compiler.constVariable({ 149 + const statement = tsc.constVariable({ 150 150 comment: plugin.config.comments 151 151 ? createOperationComment({ operation }) 152 152 : undefined,
+170 -176
packages/openapi-ts/src/plugins/@tanstack/query-core/plugin-legacy.ts
··· 1 1 import ts from 'typescript'; 2 2 3 - import { compiler, type Property } from '../../../compiler'; 4 - import type { ImportExportItem } from '../../../compiler/module'; 5 - import type { ImportExportItemObject } from '../../../compiler/utils'; 6 3 import { clientApi, clientModulePath } from '../../../generate/client'; 7 4 import { relativeModulePath } from '../../../generate/utils'; 8 5 import { createOperationKey } from '../../../ir/operation'; 9 6 import { getPaginationKeywordsRegExp } from '../../../ir/pagination'; 10 7 import type { IR } from '../../../ir/types'; 11 8 import { isOperationParameterRequired } from '../../../openApi'; 9 + import { type Property, tsc } from '../../../tsc'; 10 + import type { ImportExportItem } from '../../../tsc/module'; 11 + import type { ImportExportItemObject } from '../../../tsc/utils'; 12 12 import type { 13 13 Client, 14 14 Method, ··· 108 108 }: { 109 109 file: Files[keyof Files]; 110 110 }) => { 111 - const fn = compiler.constVariable({ 112 - expression: compiler.arrowFunction({ 111 + const fn = tsc.constVariable({ 112 + expression: tsc.arrowFunction({ 113 113 multiLine: true, 114 114 parameters: [ 115 115 { 116 116 name: 'queryKey', 117 - type: compiler.typeNode( 118 - `QueryKey<${clientApi.OptionsLegacyParser.name}>`, 119 - ), 117 + type: tsc.typeNode(`QueryKey<${clientApi.OptionsLegacyParser.name}>`), 120 118 }, 121 119 { 122 120 name: 'page', 123 - type: compiler.typeNode('K'), 121 + type: tsc.typeNode('K'), 124 122 }, 125 123 ], 126 124 statements: [ 127 - compiler.constVariable({ 128 - expression: compiler.identifier({ 125 + tsc.constVariable({ 126 + expression: tsc.identifier({ 129 127 text: 'queryKey[0]', 130 128 }), 131 129 name: 'params', 132 130 }), 133 - compiler.ifStatement({ 134 - expression: compiler.propertyAccessExpression({ 135 - expression: compiler.identifier({ 131 + tsc.ifStatement({ 132 + expression: tsc.propertyAccessExpression({ 133 + expression: tsc.identifier({ 136 134 text: 'page', 137 135 }), 138 - name: compiler.identifier({ text: 'body' }), 136 + name: tsc.identifier({ text: 'body' }), 139 137 }), 140 - thenStatement: compiler.block({ 138 + thenStatement: tsc.block({ 141 139 statements: [ 142 - compiler.expressionToStatement({ 143 - expression: compiler.binaryExpression({ 144 - left: compiler.propertyAccessExpression({ 140 + tsc.expressionToStatement({ 141 + expression: tsc.binaryExpression({ 142 + left: tsc.propertyAccessExpression({ 145 143 expression: 'params', 146 144 name: 'body', 147 145 }), 148 - right: compiler.objectExpression({ 146 + right: tsc.objectExpression({ 149 147 multiLine: true, 150 148 obj: [ 151 149 { ··· 163 161 ], 164 162 }), 165 163 }), 166 - compiler.ifStatement({ 167 - expression: compiler.propertyAccessExpression({ 168 - expression: compiler.identifier({ 164 + tsc.ifStatement({ 165 + expression: tsc.propertyAccessExpression({ 166 + expression: tsc.identifier({ 169 167 text: 'page', 170 168 }), 171 - name: compiler.identifier({ text: 'headers' }), 169 + name: tsc.identifier({ text: 'headers' }), 172 170 }), 173 - thenStatement: compiler.block({ 171 + thenStatement: tsc.block({ 174 172 statements: [ 175 - compiler.expressionToStatement({ 176 - expression: compiler.binaryExpression({ 177 - left: compiler.propertyAccessExpression({ 173 + tsc.expressionToStatement({ 174 + expression: tsc.binaryExpression({ 175 + left: tsc.propertyAccessExpression({ 178 176 expression: 'params', 179 177 name: 'headers', 180 178 }), 181 - right: compiler.objectExpression({ 179 + right: tsc.objectExpression({ 182 180 multiLine: true, 183 181 obj: [ 184 182 { ··· 194 192 ], 195 193 }), 196 194 }), 197 - compiler.ifStatement({ 198 - expression: compiler.propertyAccessExpression({ 199 - expression: compiler.identifier({ 195 + tsc.ifStatement({ 196 + expression: tsc.propertyAccessExpression({ 197 + expression: tsc.identifier({ 200 198 text: 'page', 201 199 }), 202 - name: compiler.identifier({ text: 'path' }), 200 + name: tsc.identifier({ text: 'path' }), 203 201 }), 204 - thenStatement: compiler.block({ 202 + thenStatement: tsc.block({ 205 203 statements: [ 206 - compiler.expressionToStatement({ 207 - expression: compiler.binaryExpression({ 208 - left: compiler.propertyAccessExpression({ 204 + tsc.expressionToStatement({ 205 + expression: tsc.binaryExpression({ 206 + left: tsc.propertyAccessExpression({ 209 207 expression: 'params', 210 208 name: 'path', 211 209 }), 212 - right: compiler.objectExpression({ 210 + right: tsc.objectExpression({ 213 211 multiLine: true, 214 212 obj: [ 215 213 { ··· 225 223 ], 226 224 }), 227 225 }), 228 - compiler.ifStatement({ 229 - expression: compiler.propertyAccessExpression({ 230 - expression: compiler.identifier({ 226 + tsc.ifStatement({ 227 + expression: tsc.propertyAccessExpression({ 228 + expression: tsc.identifier({ 231 229 text: 'page', 232 230 }), 233 - name: compiler.identifier({ text: 'query' }), 231 + name: tsc.identifier({ text: 'query' }), 234 232 }), 235 - thenStatement: compiler.block({ 233 + thenStatement: tsc.block({ 236 234 statements: [ 237 - compiler.expressionToStatement({ 238 - expression: compiler.binaryExpression({ 239 - left: compiler.propertyAccessExpression({ 235 + tsc.expressionToStatement({ 236 + expression: tsc.binaryExpression({ 237 + left: tsc.propertyAccessExpression({ 240 238 expression: 'params', 241 239 name: 'query', 242 240 }), 243 - right: compiler.objectExpression({ 241 + right: tsc.objectExpression({ 244 242 multiLine: true, 245 243 obj: [ 246 244 { ··· 256 254 ], 257 255 }), 258 256 }), 259 - compiler.returnVariable({ 257 + tsc.returnVariable({ 260 258 expression: ts.factory.createAsExpression( 261 259 ts.factory.createAsExpression( 262 - compiler.identifier({ text: 'params' }), 260 + tsc.identifier({ text: 'params' }), 263 261 ts.factory.createKeywordTypeNode(ts.SyntaxKind.UnknownKeyword), 264 262 ), 265 - ts.factory.createTypeQueryNode( 266 - compiler.identifier({ text: 'page' }), 267 - ), 263 + ts.factory.createTypeQueryNode(tsc.identifier({ text: 'page' })), 268 264 ), 269 265 }), 270 266 ], 271 267 types: [ 272 268 { 273 - extends: compiler.typeReferenceNode({ 274 - typeName: compiler.identifier({ 269 + extends: tsc.typeReferenceNode({ 270 + typeName: tsc.identifier({ 275 271 text: `Pick<QueryKey<${clientApi.OptionsLegacyParser.name}>[0], 'body' | 'headers' | 'path' | 'query'>`, 276 272 }), 277 273 }), ··· 285 281 }; 286 282 287 283 const createQueryKeyFunction = ({ file }: { file: Files[keyof Files] }) => { 288 - const returnType = compiler.indexedAccessTypeNode({ 289 - indexType: compiler.typeNode(0), 290 - objectType: compiler.typeNode(queryKeyName, [ 291 - compiler.typeNode(TOptionsType), 292 - ]), 284 + const returnType = tsc.indexedAccessTypeNode({ 285 + indexType: tsc.typeNode(0), 286 + objectType: tsc.typeNode(queryKeyName, [tsc.typeNode(TOptionsType)]), 293 287 }); 294 288 295 - const infiniteIdentifier = compiler.identifier({ text: 'infinite' }); 289 + const infiniteIdentifier = tsc.identifier({ text: 'infinite' }); 296 290 const baseUrlKey = getClientBaseUrlKey(getConfig()); 297 291 298 - const fn = compiler.constVariable({ 299 - expression: compiler.arrowFunction({ 292 + const fn = tsc.constVariable({ 293 + expression: tsc.arrowFunction({ 300 294 multiLine: true, 301 295 parameters: [ 302 296 { 303 297 name: 'id', 304 - type: compiler.typeNode('string'), 298 + type: tsc.typeNode('string'), 305 299 }, 306 300 { 307 301 isRequired: false, 308 302 name: 'options', 309 - type: compiler.typeNode(TOptionsType), 303 + type: tsc.typeNode(TOptionsType), 310 304 }, 311 305 { 312 306 isRequired: false, 313 307 name: 'infinite', 314 - type: compiler.typeNode('boolean'), 308 + type: tsc.typeNode('boolean'), 315 309 }, 316 310 ], 317 311 returnType, 318 312 statements: [ 319 - compiler.constVariable({ 313 + tsc.constVariable({ 320 314 assertion: returnType, 321 - expression: compiler.objectExpression({ 315 + expression: tsc.objectExpression({ 322 316 multiLine: false, 323 317 obj: [ 324 318 { 325 319 key: '_id', 326 - value: compiler.identifier({ text: 'id' }), 320 + value: tsc.identifier({ text: 'id' }), 327 321 }, 328 322 { 329 323 key: baseUrlKey, 330 - value: compiler.identifier({ 324 + value: tsc.identifier({ 331 325 text: `options?.${baseUrlKey} || (options?.client ?? _heyApiClient).getConfig().${baseUrlKey}`, 332 326 }), 333 327 }, ··· 336 330 name: 'params', 337 331 typeName: returnType, 338 332 }), 339 - compiler.ifStatement({ 333 + tsc.ifStatement({ 340 334 expression: infiniteIdentifier, 341 - thenStatement: compiler.block({ 335 + thenStatement: tsc.block({ 342 336 statements: [ 343 - compiler.expressionToStatement({ 344 - expression: compiler.binaryExpression({ 345 - left: compiler.propertyAccessExpression({ 337 + tsc.expressionToStatement({ 338 + expression: tsc.binaryExpression({ 339 + left: tsc.propertyAccessExpression({ 346 340 expression: 'params', 347 341 name: '_infinite', 348 342 }), ··· 352 346 ], 353 347 }), 354 348 }), 355 - compiler.ifStatement({ 356 - expression: compiler.propertyAccessExpression({ 357 - expression: compiler.identifier({ text: 'options' }), 349 + tsc.ifStatement({ 350 + expression: tsc.propertyAccessExpression({ 351 + expression: tsc.identifier({ text: 'options' }), 358 352 isOptional: true, 359 - name: compiler.identifier({ text: 'body' }), 353 + name: tsc.identifier({ text: 'body' }), 360 354 }), 361 - thenStatement: compiler.block({ 355 + thenStatement: tsc.block({ 362 356 statements: [ 363 - compiler.expressionToStatement({ 364 - expression: compiler.binaryExpression({ 365 - left: compiler.propertyAccessExpression({ 357 + tsc.expressionToStatement({ 358 + expression: tsc.binaryExpression({ 359 + left: tsc.propertyAccessExpression({ 366 360 expression: 'params', 367 361 name: 'body', 368 362 }), 369 - right: compiler.propertyAccessExpression({ 363 + right: tsc.propertyAccessExpression({ 370 364 expression: 'options', 371 365 name: 'body', 372 366 }), ··· 375 369 ], 376 370 }), 377 371 }), 378 - compiler.ifStatement({ 379 - expression: compiler.propertyAccessExpression({ 380 - expression: compiler.identifier({ text: 'options' }), 372 + tsc.ifStatement({ 373 + expression: tsc.propertyAccessExpression({ 374 + expression: tsc.identifier({ text: 'options' }), 381 375 isOptional: true, 382 - name: compiler.identifier({ text: 'headers' }), 376 + name: tsc.identifier({ text: 'headers' }), 383 377 }), 384 - thenStatement: compiler.block({ 378 + thenStatement: tsc.block({ 385 379 statements: [ 386 - compiler.expressionToStatement({ 387 - expression: compiler.binaryExpression({ 388 - left: compiler.propertyAccessExpression({ 380 + tsc.expressionToStatement({ 381 + expression: tsc.binaryExpression({ 382 + left: tsc.propertyAccessExpression({ 389 383 expression: 'params', 390 384 name: 'headers', 391 385 }), 392 - right: compiler.propertyAccessExpression({ 386 + right: tsc.propertyAccessExpression({ 393 387 expression: 'options', 394 388 name: 'headers', 395 389 }), ··· 398 392 ], 399 393 }), 400 394 }), 401 - compiler.ifStatement({ 402 - expression: compiler.propertyAccessExpression({ 403 - expression: compiler.identifier({ text: 'options' }), 395 + tsc.ifStatement({ 396 + expression: tsc.propertyAccessExpression({ 397 + expression: tsc.identifier({ text: 'options' }), 404 398 isOptional: true, 405 - name: compiler.identifier({ text: 'path' }), 399 + name: tsc.identifier({ text: 'path' }), 406 400 }), 407 - thenStatement: compiler.block({ 401 + thenStatement: tsc.block({ 408 402 statements: [ 409 - compiler.expressionToStatement({ 410 - expression: compiler.binaryExpression({ 411 - left: compiler.propertyAccessExpression({ 403 + tsc.expressionToStatement({ 404 + expression: tsc.binaryExpression({ 405 + left: tsc.propertyAccessExpression({ 412 406 expression: 'params', 413 407 name: 'path', 414 408 }), 415 - right: compiler.propertyAccessExpression({ 409 + right: tsc.propertyAccessExpression({ 416 410 expression: 'options', 417 411 name: 'path', 418 412 }), ··· 421 415 ], 422 416 }), 423 417 }), 424 - compiler.ifStatement({ 425 - expression: compiler.propertyAccessExpression({ 426 - expression: compiler.identifier({ text: 'options' }), 418 + tsc.ifStatement({ 419 + expression: tsc.propertyAccessExpression({ 420 + expression: tsc.identifier({ text: 'options' }), 427 421 isOptional: true, 428 - name: compiler.identifier({ text: 'query' }), 422 + name: tsc.identifier({ text: 'query' }), 429 423 }), 430 - thenStatement: compiler.block({ 424 + thenStatement: tsc.block({ 431 425 statements: [ 432 - compiler.expressionToStatement({ 433 - expression: compiler.binaryExpression({ 434 - left: compiler.propertyAccessExpression({ 426 + tsc.expressionToStatement({ 427 + expression: tsc.binaryExpression({ 428 + left: tsc.propertyAccessExpression({ 435 429 expression: 'params', 436 430 name: 'query', 437 431 }), 438 - right: compiler.propertyAccessExpression({ 432 + right: tsc.propertyAccessExpression({ 439 433 expression: 'options', 440 434 name: 'query', 441 435 }), ··· 444 438 ], 445 439 }), 446 440 }), 447 - compiler.returnVariable({ 441 + tsc.returnVariable({ 448 442 expression: 'params', 449 443 }), 450 444 ], 451 445 types: [ 452 446 { 453 - extends: compiler.typeReferenceNode({ 454 - typeName: compiler.identifier({ 447 + extends: tsc.typeReferenceNode({ 448 + typeName: tsc.identifier({ 455 449 text: clientApi.OptionsLegacyParser.name, 456 450 }), 457 451 }), ··· 468 462 const properties: Property[] = [ 469 463 { 470 464 name: '_id', 471 - type: compiler.keywordTypeNode({ 465 + type: tsc.keywordTypeNode({ 472 466 keyword: 'string', 473 467 }), 474 468 }, 475 469 { 476 470 isRequired: false, 477 471 name: '_infinite', 478 - type: compiler.keywordTypeNode({ 472 + type: tsc.keywordTypeNode({ 479 473 keyword: 'boolean', 480 474 }), 481 475 }, 482 476 ]; 483 477 484 - const queryKeyType = compiler.typeAliasDeclaration({ 478 + const queryKeyType = tsc.typeAliasDeclaration({ 485 479 name: queryKeyName, 486 - type: compiler.typeTupleNode({ 480 + type: tsc.typeTupleNode({ 487 481 types: [ 488 - compiler.typeIntersectionNode({ 482 + tsc.typeIntersectionNode({ 489 483 types: [ 490 - compiler.typeReferenceNode({ 484 + tsc.typeReferenceNode({ 491 485 typeName: `Pick<${TOptionsType}, '${getClientBaseUrlKey(getConfig())}' | 'body' | 'headers' | 'path' | 'query'>`, 492 486 }), 493 - compiler.typeInterfaceNode({ 487 + tsc.typeInterfaceNode({ 494 488 properties, 495 489 useLegacyResolution: true, 496 490 }), ··· 500 494 }), 501 495 typeParameters: [ 502 496 { 503 - extends: compiler.typeReferenceNode({ 504 - typeName: compiler.identifier({ 497 + extends: tsc.typeReferenceNode({ 498 + typeName: tsc.identifier({ 505 499 text: clientApi.OptionsLegacyParser.name, 506 500 }), 507 501 }), ··· 652 646 id: string; 653 647 isInfinite?: boolean; 654 648 }) => { 655 - const queryKeyLiteral = compiler.arrayLiteralExpression({ 649 + const queryKeyLiteral = tsc.arrayLiteralExpression({ 656 650 elements: [ 657 - compiler.callExpression({ 651 + tsc.callExpression({ 658 652 functionName: createQueryKeyFn, 659 653 parameters: [ 660 - compiler.ots.string(id), 654 + tsc.ots.string(id), 661 655 'options', 662 - isInfinite ? compiler.ots.boolean(true) : undefined, 656 + isInfinite ? tsc.ots.boolean(true) : undefined, 663 657 ], 664 658 }), 665 659 ], ··· 770 764 771 765 const isRequired = isOperationParameterRequired(operation.parameters); 772 766 773 - const queryKeyStatement = compiler.constVariable({ 767 + const queryKeyStatement = tsc.constVariable({ 774 768 exportConst: true, 775 - expression: compiler.arrowFunction({ 769 + expression: tsc.arrowFunction({ 776 770 parameters: [ 777 771 { 778 772 isRequired, ··· 792 786 }); 793 787 file.add(queryKeyStatement); 794 788 795 - const statement = compiler.constVariable({ 789 + const statement = tsc.constVariable({ 796 790 // TODO: describe options, same as the actual function call 797 791 comment: [], 798 792 exportConst: true, 799 - expression: compiler.arrowFunction({ 793 + expression: tsc.arrowFunction({ 800 794 parameters: [ 801 795 { 802 796 isRequired, ··· 805 799 }, 806 800 ], 807 801 statements: [ 808 - compiler.returnFunctionCall({ 802 + tsc.returnFunctionCall({ 809 803 args: [ 810 - compiler.objectExpression({ 804 + tsc.objectExpression({ 811 805 obj: [ 812 806 { 813 807 key: 'queryFn', 814 - value: compiler.arrowFunction({ 808 + value: tsc.arrowFunction({ 815 809 async: true, 816 810 multiLine: true, 817 811 parameters: [ ··· 827 821 }, 828 822 ], 829 823 statements: [ 830 - compiler.constVariable({ 824 + tsc.constVariable({ 831 825 destructure: true, 832 - expression: compiler.awaitExpression({ 833 - expression: compiler.callExpression({ 826 + expression: tsc.awaitExpression({ 827 + expression: tsc.callExpression({ 834 828 functionName: queryFn, 835 829 parameters: [ 836 - compiler.objectExpression({ 830 + tsc.objectExpression({ 837 831 multiLine: true, 838 832 obj: [ 839 833 { ··· 845 839 { 846 840 key: 'signal', 847 841 shorthand: true, 848 - value: compiler.identifier({ 842 + value: tsc.identifier({ 849 843 text: 'signal', 850 844 }), 851 845 }, ··· 860 854 }), 861 855 name: 'data', 862 856 }), 863 - compiler.returnVariable({ 857 + tsc.returnVariable({ 864 858 expression: 'data', 865 859 }), 866 860 ], ··· 868 862 }, 869 863 { 870 864 key: 'queryKey', 871 - value: compiler.callExpression({ 865 + value: tsc.callExpression({ 872 866 functionName: toQueryKeyName({ 873 867 config, 874 868 id: operation.name, ··· 1000 994 const typePageObjectParam = `Pick<${typeQueryKey}[0], 'body' | 'headers' | 'path' | 'query'>`; 1001 995 const typePageParam = `${paginationField.base} | ${typePageObjectParam}`; 1002 996 1003 - const queryKeyStatement = compiler.constVariable({ 997 + const queryKeyStatement = tsc.constVariable({ 1004 998 exportConst: true, 1005 - expression: compiler.arrowFunction({ 999 + expression: tsc.arrowFunction({ 1006 1000 parameters: [ 1007 1001 { 1008 1002 isRequired, ··· 1025 1019 }); 1026 1020 file.add(queryKeyStatement); 1027 1021 1028 - const statement = compiler.constVariable({ 1022 + const statement = tsc.constVariable({ 1029 1023 // TODO: describe options, same as the actual function call 1030 1024 comment: [], 1031 1025 exportConst: true, 1032 - expression: compiler.arrowFunction({ 1026 + expression: tsc.arrowFunction({ 1033 1027 parameters: [ 1034 1028 { 1035 1029 isRequired, ··· 1038 1032 }, 1039 1033 ], 1040 1034 statements: [ 1041 - compiler.returnFunctionCall({ 1035 + tsc.returnFunctionCall({ 1042 1036 args: [ 1043 - compiler.objectExpression({ 1037 + tsc.objectExpression({ 1044 1038 comments: [ 1045 1039 { 1046 1040 jsdoc: false, ··· 1050 1044 obj: [ 1051 1045 { 1052 1046 key: 'queryFn', 1053 - value: compiler.arrowFunction({ 1047 + value: tsc.arrowFunction({ 1054 1048 async: true, 1055 1049 multiLine: true, 1056 1050 parameters: [ ··· 1069 1063 }, 1070 1064 ], 1071 1065 statements: [ 1072 - compiler.constVariable({ 1066 + tsc.constVariable({ 1073 1067 comment: [ 1074 1068 { 1075 1069 jsdoc: false, 1076 1070 lines: ['@ts-ignore'], 1077 1071 }, 1078 1072 ], 1079 - expression: compiler.conditionalExpression({ 1080 - condition: compiler.binaryExpression({ 1081 - left: compiler.typeOfExpression({ 1073 + expression: tsc.conditionalExpression({ 1074 + condition: tsc.binaryExpression({ 1075 + left: tsc.typeOfExpression({ 1082 1076 text: 'pageParam', 1083 1077 }), 1084 1078 operator: '===', 1085 - right: compiler.ots.string('object'), 1079 + right: tsc.ots.string('object'), 1086 1080 }), 1087 - whenFalse: compiler.objectExpression({ 1081 + whenFalse: tsc.objectExpression({ 1088 1082 multiLine: true, 1089 1083 obj: [ 1090 1084 { 1091 1085 key: getPaginationIn( 1092 1086 paginationParameter, 1093 1087 ), 1094 - value: compiler.objectExpression({ 1088 + value: tsc.objectExpression({ 1095 1089 multiLine: true, 1096 1090 obj: [ 1097 1091 { 1098 1092 key: paginationField.name, 1099 - value: compiler.identifier({ 1093 + value: tsc.identifier({ 1100 1094 text: 'pageParam', 1101 1095 }), 1102 1096 }, ··· 1105 1099 }, 1106 1100 ], 1107 1101 }), 1108 - whenTrue: compiler.identifier({ 1102 + whenTrue: tsc.identifier({ 1109 1103 text: 'pageParam', 1110 1104 }), 1111 1105 }), 1112 1106 name: 'page', 1113 1107 typeName: typePageObjectParam, 1114 1108 }), 1115 - compiler.constVariable({ 1116 - expression: compiler.callExpression({ 1109 + tsc.constVariable({ 1110 + expression: tsc.callExpression({ 1117 1111 functionName: 'createInfiniteParams', 1118 1112 parameters: ['queryKey', 'page'], 1119 1113 }), 1120 1114 name: 'params', 1121 1115 }), 1122 - compiler.constVariable({ 1116 + tsc.constVariable({ 1123 1117 destructure: true, 1124 - expression: compiler.awaitExpression({ 1125 - expression: compiler.callExpression({ 1118 + expression: tsc.awaitExpression({ 1119 + expression: tsc.callExpression({ 1126 1120 functionName: queryFn, 1127 1121 parameters: [ 1128 - compiler.objectExpression({ 1122 + tsc.objectExpression({ 1129 1123 multiLine: true, 1130 1124 obj: [ 1131 1125 { ··· 1137 1131 { 1138 1132 key: 'signal', 1139 1133 shorthand: true, 1140 - value: compiler.identifier({ 1134 + value: tsc.identifier({ 1141 1135 text: 'signal', 1142 1136 }), 1143 1137 }, ··· 1152 1146 }), 1153 1147 name: 'data', 1154 1148 }), 1155 - compiler.returnVariable({ 1149 + tsc.returnVariable({ 1156 1150 expression: 'data', 1157 1151 }), 1158 1152 ], ··· 1160 1154 }, 1161 1155 { 1162 1156 key: 'queryKey', 1163 - value: compiler.callExpression({ 1157 + value: tsc.callExpression({ 1164 1158 functionName: toQueryKeyName({ 1165 1159 config, 1166 1160 id: operation.name, ··· 1230 1224 typesModulePath, 1231 1225 }); 1232 1226 1233 - const expression = compiler.arrowFunction({ 1227 + const expression = tsc.arrowFunction({ 1234 1228 parameters: [ 1235 1229 { 1236 1230 isRequired: false, ··· 1239 1233 }, 1240 1234 ], 1241 1235 statements: [ 1242 - compiler.constVariable({ 1243 - expression: compiler.objectExpression({ 1236 + tsc.constVariable({ 1237 + expression: tsc.objectExpression({ 1244 1238 obj: [ 1245 1239 { 1246 1240 key: 'mutationFn', 1247 - value: compiler.arrowFunction({ 1241 + value: tsc.arrowFunction({ 1248 1242 async: true, 1249 1243 multiLine: true, 1250 1244 parameters: [ ··· 1253 1247 }, 1254 1248 ], 1255 1249 statements: [ 1256 - compiler.constVariable({ 1250 + tsc.constVariable({ 1257 1251 destructure: true, 1258 - expression: compiler.awaitExpression({ 1259 - expression: compiler.callExpression({ 1252 + expression: tsc.awaitExpression({ 1253 + expression: tsc.callExpression({ 1260 1254 functionName: queryFn, 1261 1255 parameters: [ 1262 - compiler.objectExpression({ 1256 + tsc.objectExpression({ 1263 1257 multiLine: true, 1264 1258 obj: [ 1265 1259 { ··· 1279 1273 }), 1280 1274 name: 'data', 1281 1275 }), 1282 - compiler.returnVariable({ 1276 + tsc.returnVariable({ 1283 1277 expression: 'data', 1284 1278 }), 1285 1279 ], ··· 1291 1285 // TODO: better types syntax 1292 1286 typeName: `${mutationsType}<${typeResponse}, ${typeError.name}, ${typeData}>`, 1293 1287 }), 1294 - compiler.returnVariable({ 1288 + tsc.returnVariable({ 1295 1289 expression: mutationOptionsFn, 1296 1290 }), 1297 1291 ], 1298 1292 }); 1299 - const statement = compiler.constVariable({ 1293 + const statement = tsc.constVariable({ 1300 1294 // TODO: describe options, same as the actual function call 1301 1295 comment: [], 1302 1296 exportConst: true,
+74 -74
packages/openapi-ts/src/plugins/@tanstack/query-core/queryKey.ts
··· 1 - import { compiler, type Property } from '../../../compiler'; 2 1 import { clientApi } from '../../../generate/client'; 3 2 import { hasOperationDataRequired } from '../../../ir/operation'; 4 3 import type { IR } from '../../../ir/types'; 4 + import { type Property, tsc } from '../../../tsc'; 5 5 import { getClientBaseUrlKey } from '../../@hey-api/client-core/utils'; 6 6 import type { PluginInstance } from './types'; 7 7 import { useTypeData } from './useType'; ··· 10 10 export const queryKeyName = 'QueryKey'; 11 11 const TOptionsType = 'TOptions'; 12 12 13 - const infiniteIdentifier = compiler.identifier({ text: 'infinite' }); 14 - const optionsIdentifier = compiler.identifier({ text: 'options' }); 13 + const infiniteIdentifier = tsc.identifier({ text: 'infinite' }); 14 + const optionsIdentifier = tsc.identifier({ text: 'options' }); 15 15 16 16 export const createQueryKeyFunction = ({ 17 17 plugin, ··· 29 29 }); 30 30 31 31 if (identifierCreateQueryKey.name) { 32 - const returnType = compiler.indexedAccessTypeNode({ 33 - indexType: compiler.literalTypeNode({ 34 - literal: compiler.ots.number(0), 32 + const returnType = tsc.indexedAccessTypeNode({ 33 + indexType: tsc.literalTypeNode({ 34 + literal: tsc.ots.number(0), 35 35 }), 36 - objectType: compiler.typeReferenceNode({ 37 - typeArguments: [compiler.typeReferenceNode({ typeName: TOptionsType })], 36 + objectType: tsc.typeReferenceNode({ 37 + typeArguments: [tsc.typeReferenceNode({ typeName: TOptionsType })], 38 38 typeName: queryKeyName, 39 39 }), 40 40 }); 41 41 42 42 const baseUrlKey = getClientBaseUrlKey(plugin.context.config); 43 43 44 - const fn = compiler.constVariable({ 45 - expression: compiler.arrowFunction({ 44 + const fn = tsc.constVariable({ 45 + expression: tsc.arrowFunction({ 46 46 multiLine: true, 47 47 parameters: [ 48 48 { 49 49 name: 'id', 50 - type: compiler.typeReferenceNode({ typeName: 'string' }), 50 + type: tsc.typeReferenceNode({ typeName: 'string' }), 51 51 }, 52 52 { 53 53 isRequired: false, 54 54 name: 'options', 55 - type: compiler.typeReferenceNode({ typeName: TOptionsType }), 55 + type: tsc.typeReferenceNode({ typeName: TOptionsType }), 56 56 }, 57 57 { 58 58 isRequired: false, 59 59 name: 'infinite', 60 - type: compiler.typeReferenceNode({ typeName: 'boolean' }), 60 + type: tsc.typeReferenceNode({ typeName: 'boolean' }), 61 61 }, 62 62 ], 63 - returnType: compiler.typeTupleNode({ 63 + returnType: tsc.typeTupleNode({ 64 64 types: [returnType], 65 65 }), 66 66 statements: [ 67 - compiler.constVariable({ 67 + tsc.constVariable({ 68 68 assertion: returnType, 69 - expression: compiler.objectExpression({ 69 + expression: tsc.objectExpression({ 70 70 multiLine: false, 71 71 obj: [ 72 72 { 73 73 key: '_id', 74 - value: compiler.identifier({ text: 'id' }), 74 + value: tsc.identifier({ text: 'id' }), 75 75 }, 76 76 { 77 77 key: baseUrlKey, 78 - value: compiler.identifier({ 78 + value: tsc.identifier({ 79 79 text: `options?.${baseUrlKey} || (options?.client ?? _heyApiClient).getConfig().${baseUrlKey}`, 80 80 }), 81 81 }, ··· 84 84 name: 'params', 85 85 typeName: returnType, 86 86 }), 87 - compiler.ifStatement({ 87 + tsc.ifStatement({ 88 88 expression: infiniteIdentifier, 89 - thenStatement: compiler.block({ 89 + thenStatement: tsc.block({ 90 90 statements: [ 91 - compiler.expressionToStatement({ 92 - expression: compiler.binaryExpression({ 93 - left: compiler.propertyAccessExpression({ 91 + tsc.expressionToStatement({ 92 + expression: tsc.binaryExpression({ 93 + left: tsc.propertyAccessExpression({ 94 94 expression: 'params', 95 95 name: '_infinite', 96 96 }), ··· 100 100 ], 101 101 }), 102 102 }), 103 - compiler.ifStatement({ 104 - expression: compiler.propertyAccessExpression({ 103 + tsc.ifStatement({ 104 + expression: tsc.propertyAccessExpression({ 105 105 expression: optionsIdentifier, 106 106 isOptional: true, 107 - name: compiler.identifier({ text: 'body' }), 107 + name: tsc.identifier({ text: 'body' }), 108 108 }), 109 - thenStatement: compiler.block({ 109 + thenStatement: tsc.block({ 110 110 statements: [ 111 - compiler.expressionToStatement({ 112 - expression: compiler.binaryExpression({ 113 - left: compiler.propertyAccessExpression({ 111 + tsc.expressionToStatement({ 112 + expression: tsc.binaryExpression({ 113 + left: tsc.propertyAccessExpression({ 114 114 expression: 'params', 115 115 name: 'body', 116 116 }), 117 - right: compiler.propertyAccessExpression({ 117 + right: tsc.propertyAccessExpression({ 118 118 expression: 'options', 119 119 name: 'body', 120 120 }), ··· 123 123 ], 124 124 }), 125 125 }), 126 - compiler.ifStatement({ 127 - expression: compiler.propertyAccessExpression({ 126 + tsc.ifStatement({ 127 + expression: tsc.propertyAccessExpression({ 128 128 expression: optionsIdentifier, 129 129 isOptional: true, 130 - name: compiler.identifier({ text: 'headers' }), 130 + name: tsc.identifier({ text: 'headers' }), 131 131 }), 132 - thenStatement: compiler.block({ 132 + thenStatement: tsc.block({ 133 133 statements: [ 134 - compiler.expressionToStatement({ 135 - expression: compiler.binaryExpression({ 136 - left: compiler.propertyAccessExpression({ 134 + tsc.expressionToStatement({ 135 + expression: tsc.binaryExpression({ 136 + left: tsc.propertyAccessExpression({ 137 137 expression: 'params', 138 138 name: 'headers', 139 139 }), 140 - right: compiler.propertyAccessExpression({ 140 + right: tsc.propertyAccessExpression({ 141 141 expression: 'options', 142 142 name: 'headers', 143 143 }), ··· 146 146 ], 147 147 }), 148 148 }), 149 - compiler.ifStatement({ 150 - expression: compiler.propertyAccessExpression({ 149 + tsc.ifStatement({ 150 + expression: tsc.propertyAccessExpression({ 151 151 expression: optionsIdentifier, 152 152 isOptional: true, 153 - name: compiler.identifier({ text: 'path' }), 153 + name: tsc.identifier({ text: 'path' }), 154 154 }), 155 - thenStatement: compiler.block({ 155 + thenStatement: tsc.block({ 156 156 statements: [ 157 - compiler.expressionToStatement({ 158 - expression: compiler.binaryExpression({ 159 - left: compiler.propertyAccessExpression({ 157 + tsc.expressionToStatement({ 158 + expression: tsc.binaryExpression({ 159 + left: tsc.propertyAccessExpression({ 160 160 expression: 'params', 161 161 name: 'path', 162 162 }), 163 - right: compiler.propertyAccessExpression({ 163 + right: tsc.propertyAccessExpression({ 164 164 expression: 'options', 165 165 name: 'path', 166 166 }), ··· 169 169 ], 170 170 }), 171 171 }), 172 - compiler.ifStatement({ 173 - expression: compiler.propertyAccessExpression({ 172 + tsc.ifStatement({ 173 + expression: tsc.propertyAccessExpression({ 174 174 expression: optionsIdentifier, 175 175 isOptional: true, 176 - name: compiler.identifier({ text: 'query' }), 176 + name: tsc.identifier({ text: 'query' }), 177 177 }), 178 - thenStatement: compiler.block({ 178 + thenStatement: tsc.block({ 179 179 statements: [ 180 - compiler.expressionToStatement({ 181 - expression: compiler.binaryExpression({ 182 - left: compiler.propertyAccessExpression({ 180 + tsc.expressionToStatement({ 181 + expression: tsc.binaryExpression({ 182 + left: tsc.propertyAccessExpression({ 183 183 expression: 'params', 184 184 name: 'query', 185 185 }), 186 - right: compiler.propertyAccessExpression({ 186 + right: tsc.propertyAccessExpression({ 187 187 expression: 'options', 188 188 name: 'query', 189 189 }), ··· 192 192 ], 193 193 }), 194 194 }), 195 - compiler.returnStatement({ 196 - expression: compiler.arrayLiteralExpression({ 197 - elements: [compiler.identifier({ text: 'params' })], 195 + tsc.returnStatement({ 196 + expression: tsc.arrayLiteralExpression({ 197 + elements: [tsc.identifier({ text: 'params' })], 198 198 }), 199 199 }), 200 200 ], 201 201 types: [ 202 202 { 203 - extends: compiler.typeReferenceNode({ 204 - typeName: compiler.identifier({ 203 + extends: tsc.typeReferenceNode({ 204 + typeName: tsc.identifier({ 205 205 text: clientApi.Options.name, 206 206 }), 207 207 }), ··· 231 231 case: plugin.config.case, 232 232 namespace: 'value', 233 233 }); 234 - const createQueryKeyCallExpression = compiler.callExpression({ 234 + const createQueryKeyCallExpression = tsc.callExpression({ 235 235 functionName: identifierCreateQueryKey.name || '', 236 236 parameters: [ 237 - compiler.ots.string(id), 237 + tsc.ots.string(id), 238 238 'options', 239 - isInfinite ? compiler.ots.boolean(true) : undefined, 239 + isInfinite ? tsc.ots.boolean(true) : undefined, 240 240 ], 241 241 }); 242 242 return createQueryKeyCallExpression; ··· 248 248 const properties: Array<Property> = [ 249 249 { 250 250 name: '_id', 251 - type: compiler.keywordTypeNode({ 251 + type: tsc.keywordTypeNode({ 252 252 keyword: 'string', 253 253 }), 254 254 }, 255 255 { 256 256 isRequired: false, 257 257 name: '_infinite', 258 - type: compiler.keywordTypeNode({ 258 + type: tsc.keywordTypeNode({ 259 259 keyword: 'boolean', 260 260 }), 261 261 }, 262 262 ]; 263 263 264 - const queryKeyType = compiler.typeAliasDeclaration({ 264 + const queryKeyType = tsc.typeAliasDeclaration({ 265 265 exportType: true, 266 266 name: queryKeyName, 267 - type: compiler.typeTupleNode({ 267 + type: tsc.typeTupleNode({ 268 268 types: [ 269 - compiler.typeIntersectionNode({ 269 + tsc.typeIntersectionNode({ 270 270 types: [ 271 - compiler.typeReferenceNode({ 271 + tsc.typeReferenceNode({ 272 272 typeName: `Pick<${TOptionsType}, '${getClientBaseUrlKey(plugin.context.config)}' | 'body' | 'headers' | 'path' | 'query'>`, 273 273 }), 274 - compiler.typeInterfaceNode({ 274 + tsc.typeInterfaceNode({ 275 275 properties, 276 276 useLegacyResolution: true, 277 277 }), ··· 281 281 }), 282 282 typeParameters: [ 283 283 { 284 - extends: compiler.typeReferenceNode({ 285 - typeName: compiler.identifier({ 284 + extends: tsc.typeReferenceNode({ 285 + typeName: tsc.identifier({ 286 286 text: clientApi.Options.name, 287 287 }), 288 288 }), ··· 323 323 nameTransformer: plugin.config.queryKeys.name, 324 324 namespace: 'value', 325 325 }); 326 - const statement = compiler.constVariable({ 326 + const statement = tsc.constVariable({ 327 327 exportConst: true, 328 - expression: compiler.arrowFunction({ 328 + expression: tsc.arrowFunction({ 329 329 parameters: [ 330 330 { 331 331 isRequired: hasOperationDataRequired(operation),
+14 -14
packages/openapi-ts/src/plugins/@tanstack/query-core/queryOptions.ts
··· 1 1 import type ts from 'typescript'; 2 2 3 - import { compiler } from '../../../compiler'; 4 3 import type { IR } from '../../../ir/types'; 4 + import { tsc } from '../../../tsc'; 5 5 import { 6 6 createOperationComment, 7 7 isOperationOptionsRequired, ··· 76 76 namespace: 'value', 77 77 }); 78 78 79 - const awaitSdkExpression = compiler.awaitExpression({ 80 - expression: compiler.callExpression({ 79 + const awaitSdkExpression = tsc.awaitExpression({ 80 + expression: tsc.callExpression({ 81 81 functionName: queryFn, 82 82 parameters: [ 83 - compiler.objectExpression({ 83 + tsc.objectExpression({ 84 84 multiLine: true, 85 85 obj: [ 86 86 { ··· 92 92 { 93 93 key: 'signal', 94 94 shorthand: true, 95 - value: compiler.identifier({ 95 + value: tsc.identifier({ 96 96 text: 'signal', 97 97 }), 98 98 }, ··· 110 110 111 111 if (plugin.getPlugin('@hey-api/sdk')?.config.responseStyle === 'data') { 112 112 statements.push( 113 - compiler.returnVariable({ 113 + tsc.returnVariable({ 114 114 expression: awaitSdkExpression, 115 115 }), 116 116 ); 117 117 } else { 118 118 statements.push( 119 - compiler.constVariable({ 119 + tsc.constVariable({ 120 120 destructure: true, 121 121 expression: awaitSdkExpression, 122 122 name: 'data', 123 123 }), 124 - compiler.returnVariable({ 124 + tsc.returnVariable({ 125 125 expression: 'data', 126 126 }), 127 127 ); ··· 136 136 namespace: 'value', 137 137 }); 138 138 139 - const statement = compiler.constVariable({ 139 + const statement = tsc.constVariable({ 140 140 comment: plugin.config.comments 141 141 ? createOperationComment({ operation }) 142 142 : undefined, 143 143 exportConst: true, 144 - expression: compiler.arrowFunction({ 144 + expression: tsc.arrowFunction({ 145 145 parameters: [ 146 146 { 147 147 isRequired: isRequiredOptions, ··· 150 150 }, 151 151 ], 152 152 statements: [ 153 - compiler.returnFunctionCall({ 153 + tsc.returnFunctionCall({ 154 154 args: [ 155 - compiler.objectExpression({ 155 + tsc.objectExpression({ 156 156 obj: [ 157 157 { 158 158 key: 'queryFn', 159 - value: compiler.arrowFunction({ 159 + value: tsc.arrowFunction({ 160 160 async: true, 161 161 multiLine: true, 162 162 parameters: [ ··· 176 176 }, 177 177 { 178 178 key: 'queryKey', 179 - value: compiler.callExpression({ 179 + value: tsc.callExpression({ 180 180 functionName: identifierQueryKey.name || '', 181 181 parameters: ['options'], 182 182 }),
+1 -1
packages/openapi-ts/src/plugins/@tanstack/query-core/types.d.ts
··· 1 - import type { ImportExportItem } from '../../../compiler/module'; 1 + import type { ImportExportItem } from '../../../tsc/module'; 2 2 import type { TanStackAngularQueryPlugin } from '../angular-query-experimental/types'; 3 3 import type { TanStackReactQueryPlugin } from '../react-query/types'; 4 4 import type { TanStackSolidQueryPlugin } from '../solid-query/types';
+1 -1
packages/openapi-ts/src/plugins/@tanstack/query-core/useType.ts
··· 1 - import type { ImportExportItemObject } from '../../../compiler/utils'; 2 1 import type { IR } from '../../../ir/types'; 2 + import type { ImportExportItemObject } from '../../../tsc/utils'; 3 3 import { getClientPlugin } from '../../@hey-api/client-core/utils'; 4 4 import { operationOptionsType } from '../../@hey-api/sdk/operation'; 5 5 import { typesId } from '../../@hey-api/typescript/ref';
+16 -16
packages/openapi-ts/src/plugins/fastify/plugin.ts
··· 1 1 import type ts from 'typescript'; 2 2 3 - import { compiler, type Property } from '../../compiler'; 4 3 import { operationResponsesMap } from '../../ir/operation'; 5 4 import { hasParameterGroupObjectRequired } from '../../ir/parameter'; 6 5 import type { IR } from '../../ir/types'; 6 + import { type Property, tsc } from '../../tsc'; 7 7 import { typesId } from '../@hey-api/typescript/ref'; 8 8 import type { FastifyPlugin } from './types'; 9 9 ··· 118 118 }), 119 119 name: errorName, 120 120 }); 121 - errorsTypeReference = compiler.typeReferenceNode({ 121 + errorsTypeReference = tsc.typeReferenceNode({ 122 122 typeName: errorName, 123 123 }); 124 124 } else if (keys.length > 1) { ··· 130 130 }), 131 131 name: errorName, 132 132 }); 133 - const errorsType = compiler.typeReferenceNode({ 133 + const errorsType = tsc.typeReferenceNode({ 134 134 typeName: errorName, 135 135 }); 136 - const defaultType = compiler.literalTypeNode({ 137 - literal: compiler.stringLiteral({ text: 'default' }), 136 + const defaultType = tsc.literalTypeNode({ 137 + literal: tsc.stringLiteral({ text: 'default' }), 138 138 }); 139 - errorsTypeReference = compiler.typeReferenceNode({ 139 + errorsTypeReference = tsc.typeReferenceNode({ 140 140 typeArguments: [errorsType, defaultType], 141 141 typeName: 'Omit', 142 142 }); ··· 161 161 }), 162 162 name: responseName, 163 163 }); 164 - responsesTypeReference = compiler.typeReferenceNode({ 164 + responsesTypeReference = tsc.typeReferenceNode({ 165 165 typeName: responseName, 166 166 }); 167 167 } else if (keys.length > 1) { ··· 173 173 }), 174 174 name: responseName, 175 175 }); 176 - const responsesType = compiler.typeReferenceNode({ 176 + const responsesType = tsc.typeReferenceNode({ 177 177 typeName: responseName, 178 178 }); 179 - const defaultType = compiler.literalTypeNode({ 180 - literal: compiler.stringLiteral({ text: 'default' }), 179 + const defaultType = tsc.literalTypeNode({ 180 + literal: tsc.stringLiteral({ text: 'default' }), 181 181 }); 182 - responsesTypeReference = compiler.typeReferenceNode({ 182 + responsesTypeReference = tsc.typeReferenceNode({ 183 183 typeArguments: [responsesType, defaultType], 184 184 typeName: 'Omit', 185 185 }); ··· 193 193 if (replyTypes.length) { 194 194 properties.push({ 195 195 name: 'Reply', 196 - type: compiler.typeIntersectionNode({ 196 + type: tsc.typeIntersectionNode({ 197 197 types: replyTypes, 198 198 }), 199 199 }); ··· 205 205 206 206 const routeHandler: Property = { 207 207 name: operation.id, 208 - type: compiler.typeNode('RouteHandler', [ 209 - compiler.typeInterfaceNode({ 208 + type: tsc.typeNode('RouteHandler', [ 209 + tsc.typeInterfaceNode({ 210 210 properties, 211 211 useLegacyResolution: false, 212 212 }), ··· 249 249 } 250 250 251 251 file.add( 252 - compiler.typeAliasDeclaration({ 252 + tsc.typeAliasDeclaration({ 253 253 exportType: true, 254 254 name: identifier.name, 255 - type: compiler.typeInterfaceNode({ 255 + type: tsc.typeInterfaceNode({ 256 256 properties: routeHandlers, 257 257 useLegacyResolution: false, 258 258 }),
+1 -1
packages/openapi-ts/src/plugins/shared/utils/operation.ts
··· 1 - import type { Comments } from '../../../compiler'; 2 1 import { hasOperationDataRequired } from '../../../ir/operation'; 3 2 import type { IR } from '../../../ir/types'; 3 + import type { Comments } from '../../../tsc'; 4 4 import { escapeComment } from '../../../utils/escape'; 5 5 import { getClientPlugin } from '../../@hey-api/client-core/utils'; 6 6
+1 -1
packages/openapi-ts/src/plugins/shared/utils/schema.ts
··· 1 - import type { Comments } from '../../../compiler'; 2 1 import type { IR } from '../../../ir/types'; 2 + import type { Comments } from '../../../tsc'; 3 3 import { escapeComment } from '../../../utils/escape'; 4 4 5 5 export const createSchemaComment = ({
+15 -15
packages/openapi-ts/src/plugins/valibot/api.ts
··· 1 1 import type ts from 'typescript'; 2 2 3 - import { compiler } from '../../compiler'; 4 3 import type { GeneratedFile } from '../../generate/file'; 5 4 import type { IR } from '../../ir/types'; 5 + import { tsc } from '../../tsc'; 6 6 import { identifiers, valibotId } from './constants'; 7 7 import type { ValibotPlugin } from './types'; 8 8 ··· 44 44 45 45 const dataParameterName = 'data'; 46 46 47 - return compiler.arrowFunction({ 47 + return tsc.arrowFunction({ 48 48 async: true, 49 49 parameters: [ 50 50 { ··· 52 52 }, 53 53 ], 54 54 statements: [ 55 - compiler.returnStatement({ 56 - expression: compiler.awaitExpression({ 57 - expression: compiler.callExpression({ 58 - functionName: compiler.propertyAccessExpression({ 55 + tsc.returnStatement({ 56 + expression: tsc.awaitExpression({ 57 + expression: tsc.callExpression({ 58 + functionName: tsc.propertyAccessExpression({ 59 59 expression: identifiers.v, 60 60 name: identifiers.async.parseAsync, 61 61 }), 62 62 parameters: [ 63 - compiler.identifier({ text: schemaIdentifier.name }), 64 - compiler.identifier({ text: dataParameterName }), 63 + tsc.identifier({ text: schemaIdentifier.name }), 64 + tsc.identifier({ text: dataParameterName }), 65 65 ], 66 66 }), 67 67 }), ··· 108 108 109 109 const dataParameterName = 'data'; 110 110 111 - return compiler.arrowFunction({ 111 + return tsc.arrowFunction({ 112 112 async: true, 113 113 parameters: [ 114 114 { ··· 116 116 }, 117 117 ], 118 118 statements: [ 119 - compiler.returnStatement({ 120 - expression: compiler.awaitExpression({ 121 - expression: compiler.callExpression({ 122 - functionName: compiler.propertyAccessExpression({ 119 + tsc.returnStatement({ 120 + expression: tsc.awaitExpression({ 121 + expression: tsc.callExpression({ 122 + functionName: tsc.propertyAccessExpression({ 123 123 expression: identifiers.v, 124 124 name: identifiers.async.parseAsync, 125 125 }), 126 126 parameters: [ 127 - compiler.identifier({ text: schemaIdentifier.name }), 128 - compiler.identifier({ text: dataParameterName }), 127 + tsc.identifier({ text: schemaIdentifier.name }), 128 + tsc.identifier({ text: dataParameterName }), 129 129 ], 130 130 }), 131 131 }),
+226 -226
packages/openapi-ts/src/plugins/valibot/constants.ts
··· 1 - import { compiler } from '../../compiler'; 1 + import { tsc } from '../../tsc'; 2 2 3 3 export const identifiers = { 4 4 /** 5 5 * {@link https://valibot.dev/api/#actions Actions} 6 6 */ 7 7 actions: { 8 - args: compiler.identifier({ text: 'args' }), 9 - base64: compiler.identifier({ text: 'base64' }), 10 - bic: compiler.identifier({ text: 'bic' }), 11 - brand: compiler.identifier({ text: 'brand' }), 12 - bytes: compiler.identifier({ text: 'bytes' }), 13 - check: compiler.identifier({ text: 'check' }), 14 - checkItems: compiler.identifier({ text: 'checkItems' }), 15 - creditCard: compiler.identifier({ text: 'creditCard' }), 16 - cuid2: compiler.identifier({ text: 'cuid2' }), 17 - decimal: compiler.identifier({ text: 'decimal' }), 18 - description: compiler.identifier({ text: 'description' }), 19 - digits: compiler.identifier({ text: 'digits' }), 20 - email: compiler.identifier({ text: 'email' }), 21 - emoji: compiler.identifier({ text: 'emoji' }), 22 - empty: compiler.identifier({ text: 'empty' }), 23 - endsWith: compiler.identifier({ text: 'endsWith' }), 24 - entries: compiler.identifier({ text: 'entries' }), 25 - everyItem: compiler.identifier({ text: 'everyItem' }), 26 - excludes: compiler.identifier({ text: 'excludes' }), 27 - filterItems: compiler.identifier({ text: 'filterItems' }), 28 - findItem: compiler.identifier({ text: 'findItem' }), 29 - finite: compiler.identifier({ text: 'finite' }), 30 - flavor: compiler.identifier({ text: 'flavor' }), 31 - graphemes: compiler.identifier({ text: 'graphemes' }), 32 - gtValue: compiler.identifier({ text: 'gtValue' }), 33 - hash: compiler.identifier({ text: 'hash' }), 34 - hexColor: compiler.identifier({ text: 'hexColor' }), 35 - hexadecimal: compiler.identifier({ text: 'hexadecimal' }), 36 - imei: compiler.identifier({ text: 'imei' }), 37 - includes: compiler.identifier({ text: 'includes' }), 38 - integer: compiler.identifier({ text: 'integer' }), 39 - ip: compiler.identifier({ text: 'ip' }), 40 - ipv4: compiler.identifier({ text: 'ipv4' }), 41 - ipv6: compiler.identifier({ text: 'ipv6' }), 42 - isoDate: compiler.identifier({ text: 'isoDate' }), 43 - isoDateTime: compiler.identifier({ text: 'isoDateTime' }), 44 - isoTime: compiler.identifier({ text: 'isoTime' }), 45 - isoTimeSecond: compiler.identifier({ text: 'isoTimeSecond' }), 46 - isoTimestamp: compiler.identifier({ text: 'isoTimestamp' }), 47 - isoWeek: compiler.identifier({ text: 'isoWeek' }), 48 - length: compiler.identifier({ text: 'length' }), 49 - ltValue: compiler.identifier({ text: 'ltValue' }), 50 - mac: compiler.identifier({ text: 'mac' }), 51 - mac48: compiler.identifier({ text: 'mac48' }), 52 - mac64: compiler.identifier({ text: 'mac64' }), 53 - mapItems: compiler.identifier({ text: 'mapItems' }), 54 - maxBytes: compiler.identifier({ text: 'maxBytes' }), 55 - maxEntries: compiler.identifier({ text: 'maxEntries' }), 56 - maxGraphemes: compiler.identifier({ text: 'maxGraphemes' }), 57 - maxLength: compiler.identifier({ text: 'maxLength' }), 58 - maxSize: compiler.identifier({ text: 'maxSize' }), 59 - maxValue: compiler.identifier({ text: 'maxValue' }), 60 - maxWords: compiler.identifier({ text: 'maxWords' }), 61 - metadata: compiler.identifier({ text: 'metadata' }), 62 - mimeType: compiler.identifier({ text: 'mimeType' }), 63 - minBytes: compiler.identifier({ text: 'minBytes' }), 64 - minEntries: compiler.identifier({ text: 'minEntries' }), 65 - minGraphemes: compiler.identifier({ text: 'minGraphemes' }), 66 - minLength: compiler.identifier({ text: 'minLength' }), 67 - minSize: compiler.identifier({ text: 'minSize' }), 68 - minValue: compiler.identifier({ text: 'minValue' }), 69 - minWords: compiler.identifier({ text: 'minWords' }), 70 - multipleOf: compiler.identifier({ text: 'multipleOf' }), 71 - nanoid: compiler.identifier({ text: 'nanoid' }), 72 - nonEmpty: compiler.identifier({ text: 'nonEmpty' }), 73 - normalize: compiler.identifier({ text: 'normalize' }), 74 - notBytes: compiler.identifier({ text: 'notBytes' }), 75 - notEntries: compiler.identifier({ text: 'notEntries' }), 76 - notGraphemes: compiler.identifier({ text: 'notGraphemes' }), 77 - notLength: compiler.identifier({ text: 'notLength' }), 78 - notSize: compiler.identifier({ text: 'notSize' }), 79 - notValue: compiler.identifier({ text: 'notValue' }), 80 - notValues: compiler.identifier({ text: 'notValues' }), 81 - notWords: compiler.identifier({ text: 'notWords' }), 82 - octal: compiler.identifier({ text: 'octal' }), 83 - parseJson: compiler.identifier({ text: 'parseJson' }), 84 - partialCheck: compiler.identifier({ text: 'partialCheck' }), 85 - rawCheck: compiler.identifier({ text: 'rawCheck' }), 86 - rawTransform: compiler.identifier({ text: 'rawTransform' }), 87 - readonly: compiler.identifier({ text: 'readonly' }), 88 - reduceItems: compiler.identifier({ text: 'reduceItems' }), 89 - regex: compiler.identifier({ text: 'regex' }), 90 - returns: compiler.identifier({ text: 'returns' }), 91 - rfcEmail: compiler.identifier({ text: 'rfcEmail' }), 92 - safeInteger: compiler.identifier({ text: 'safeInteger' }), 93 - size: compiler.identifier({ text: 'size' }), 94 - slug: compiler.identifier({ text: 'slug' }), 95 - someItem: compiler.identifier({ text: 'someItem' }), 96 - sortItems: compiler.identifier({ text: 'sortItems' }), 97 - startsWith: compiler.identifier({ text: 'startsWith' }), 98 - stringifyJson: compiler.identifier({ text: 'stringifyJson' }), 99 - title: compiler.identifier({ text: 'title' }), 100 - toLowerCase: compiler.identifier({ text: 'toLowerCase' }), 101 - toMaxValue: compiler.identifier({ text: 'toMaxValue' }), 102 - toMinValue: compiler.identifier({ text: 'toMinValue' }), 103 - toUpperCase: compiler.identifier({ text: 'toUpperCase' }), 104 - transform: compiler.identifier({ text: 'transform' }), 105 - trim: compiler.identifier({ text: 'trim' }), 106 - trimEnd: compiler.identifier({ text: 'trimEnd' }), 107 - trimStart: compiler.identifier({ text: 'trimStart' }), 108 - ulid: compiler.identifier({ text: 'ulid' }), 109 - url: compiler.identifier({ text: 'url' }), 110 - uuid: compiler.identifier({ text: 'uuid' }), 111 - value: compiler.identifier({ text: 'value' }), 112 - values: compiler.identifier({ text: 'values' }), 113 - words: compiler.identifier({ text: 'words' }), 8 + args: tsc.identifier({ text: 'args' }), 9 + base64: tsc.identifier({ text: 'base64' }), 10 + bic: tsc.identifier({ text: 'bic' }), 11 + brand: tsc.identifier({ text: 'brand' }), 12 + bytes: tsc.identifier({ text: 'bytes' }), 13 + check: tsc.identifier({ text: 'check' }), 14 + checkItems: tsc.identifier({ text: 'checkItems' }), 15 + creditCard: tsc.identifier({ text: 'creditCard' }), 16 + cuid2: tsc.identifier({ text: 'cuid2' }), 17 + decimal: tsc.identifier({ text: 'decimal' }), 18 + description: tsc.identifier({ text: 'description' }), 19 + digits: tsc.identifier({ text: 'digits' }), 20 + email: tsc.identifier({ text: 'email' }), 21 + emoji: tsc.identifier({ text: 'emoji' }), 22 + empty: tsc.identifier({ text: 'empty' }), 23 + endsWith: tsc.identifier({ text: 'endsWith' }), 24 + entries: tsc.identifier({ text: 'entries' }), 25 + everyItem: tsc.identifier({ text: 'everyItem' }), 26 + excludes: tsc.identifier({ text: 'excludes' }), 27 + filterItems: tsc.identifier({ text: 'filterItems' }), 28 + findItem: tsc.identifier({ text: 'findItem' }), 29 + finite: tsc.identifier({ text: 'finite' }), 30 + flavor: tsc.identifier({ text: 'flavor' }), 31 + graphemes: tsc.identifier({ text: 'graphemes' }), 32 + gtValue: tsc.identifier({ text: 'gtValue' }), 33 + hash: tsc.identifier({ text: 'hash' }), 34 + hexColor: tsc.identifier({ text: 'hexColor' }), 35 + hexadecimal: tsc.identifier({ text: 'hexadecimal' }), 36 + imei: tsc.identifier({ text: 'imei' }), 37 + includes: tsc.identifier({ text: 'includes' }), 38 + integer: tsc.identifier({ text: 'integer' }), 39 + ip: tsc.identifier({ text: 'ip' }), 40 + ipv4: tsc.identifier({ text: 'ipv4' }), 41 + ipv6: tsc.identifier({ text: 'ipv6' }), 42 + isoDate: tsc.identifier({ text: 'isoDate' }), 43 + isoDateTime: tsc.identifier({ text: 'isoDateTime' }), 44 + isoTime: tsc.identifier({ text: 'isoTime' }), 45 + isoTimeSecond: tsc.identifier({ text: 'isoTimeSecond' }), 46 + isoTimestamp: tsc.identifier({ text: 'isoTimestamp' }), 47 + isoWeek: tsc.identifier({ text: 'isoWeek' }), 48 + length: tsc.identifier({ text: 'length' }), 49 + ltValue: tsc.identifier({ text: 'ltValue' }), 50 + mac: tsc.identifier({ text: 'mac' }), 51 + mac48: tsc.identifier({ text: 'mac48' }), 52 + mac64: tsc.identifier({ text: 'mac64' }), 53 + mapItems: tsc.identifier({ text: 'mapItems' }), 54 + maxBytes: tsc.identifier({ text: 'maxBytes' }), 55 + maxEntries: tsc.identifier({ text: 'maxEntries' }), 56 + maxGraphemes: tsc.identifier({ text: 'maxGraphemes' }), 57 + maxLength: tsc.identifier({ text: 'maxLength' }), 58 + maxSize: tsc.identifier({ text: 'maxSize' }), 59 + maxValue: tsc.identifier({ text: 'maxValue' }), 60 + maxWords: tsc.identifier({ text: 'maxWords' }), 61 + metadata: tsc.identifier({ text: 'metadata' }), 62 + mimeType: tsc.identifier({ text: 'mimeType' }), 63 + minBytes: tsc.identifier({ text: 'minBytes' }), 64 + minEntries: tsc.identifier({ text: 'minEntries' }), 65 + minGraphemes: tsc.identifier({ text: 'minGraphemes' }), 66 + minLength: tsc.identifier({ text: 'minLength' }), 67 + minSize: tsc.identifier({ text: 'minSize' }), 68 + minValue: tsc.identifier({ text: 'minValue' }), 69 + minWords: tsc.identifier({ text: 'minWords' }), 70 + multipleOf: tsc.identifier({ text: 'multipleOf' }), 71 + nanoid: tsc.identifier({ text: 'nanoid' }), 72 + nonEmpty: tsc.identifier({ text: 'nonEmpty' }), 73 + normalize: tsc.identifier({ text: 'normalize' }), 74 + notBytes: tsc.identifier({ text: 'notBytes' }), 75 + notEntries: tsc.identifier({ text: 'notEntries' }), 76 + notGraphemes: tsc.identifier({ text: 'notGraphemes' }), 77 + notLength: tsc.identifier({ text: 'notLength' }), 78 + notSize: tsc.identifier({ text: 'notSize' }), 79 + notValue: tsc.identifier({ text: 'notValue' }), 80 + notValues: tsc.identifier({ text: 'notValues' }), 81 + notWords: tsc.identifier({ text: 'notWords' }), 82 + octal: tsc.identifier({ text: 'octal' }), 83 + parseJson: tsc.identifier({ text: 'parseJson' }), 84 + partialCheck: tsc.identifier({ text: 'partialCheck' }), 85 + rawCheck: tsc.identifier({ text: 'rawCheck' }), 86 + rawTransform: tsc.identifier({ text: 'rawTransform' }), 87 + readonly: tsc.identifier({ text: 'readonly' }), 88 + reduceItems: tsc.identifier({ text: 'reduceItems' }), 89 + regex: tsc.identifier({ text: 'regex' }), 90 + returns: tsc.identifier({ text: 'returns' }), 91 + rfcEmail: tsc.identifier({ text: 'rfcEmail' }), 92 + safeInteger: tsc.identifier({ text: 'safeInteger' }), 93 + size: tsc.identifier({ text: 'size' }), 94 + slug: tsc.identifier({ text: 'slug' }), 95 + someItem: tsc.identifier({ text: 'someItem' }), 96 + sortItems: tsc.identifier({ text: 'sortItems' }), 97 + startsWith: tsc.identifier({ text: 'startsWith' }), 98 + stringifyJson: tsc.identifier({ text: 'stringifyJson' }), 99 + title: tsc.identifier({ text: 'title' }), 100 + toLowerCase: tsc.identifier({ text: 'toLowerCase' }), 101 + toMaxValue: tsc.identifier({ text: 'toMaxValue' }), 102 + toMinValue: tsc.identifier({ text: 'toMinValue' }), 103 + toUpperCase: tsc.identifier({ text: 'toUpperCase' }), 104 + transform: tsc.identifier({ text: 'transform' }), 105 + trim: tsc.identifier({ text: 'trim' }), 106 + trimEnd: tsc.identifier({ text: 'trimEnd' }), 107 + trimStart: tsc.identifier({ text: 'trimStart' }), 108 + ulid: tsc.identifier({ text: 'ulid' }), 109 + url: tsc.identifier({ text: 'url' }), 110 + uuid: tsc.identifier({ text: 'uuid' }), 111 + value: tsc.identifier({ text: 'value' }), 112 + values: tsc.identifier({ text: 'values' }), 113 + words: tsc.identifier({ text: 'words' }), 114 114 }, 115 115 /** 116 116 * {@link https://valibot.dev/api/#async Async} 117 117 */ 118 118 async: { 119 - argsAsync: compiler.identifier({ text: 'argsAsync' }), 120 - arrayAsync: compiler.identifier({ text: 'arrayAsync' }), 121 - awaitAsync: compiler.identifier({ text: 'awaitAsync' }), 122 - checkAsync: compiler.identifier({ text: 'checkAsync' }), 123 - checkItemsAsync: compiler.identifier({ text: 'checkItemsAsync' }), 124 - customAsync: compiler.identifier({ text: 'customAsync' }), 125 - exactOptionalAsync: compiler.identifier({ text: 'exactOptionalAsync' }), 126 - fallbackAsync: compiler.identifier({ text: 'fallbackAsync' }), 127 - forwardAsync: compiler.identifier({ text: 'forwardAsync' }), 128 - getDefaultsAsync: compiler.identifier({ text: 'getDefaultsAsync' }), 129 - getFallbacksAsync: compiler.identifier({ text: 'getFallbacksAsync' }), 130 - intersectAsync: compiler.identifier({ text: 'intersectAsync' }), 131 - lazyAsync: compiler.identifier({ text: 'lazyAsync' }), 132 - looseObjectAsync: compiler.identifier({ text: 'looseObjectAsync' }), 133 - looseTupleAsync: compiler.identifier({ text: 'looseTupleAsync' }), 134 - mapAsync: compiler.identifier({ text: 'mapAsync' }), 135 - nonNullableAsync: compiler.identifier({ text: 'nonNullableAsync' }), 136 - nonNullishAsync: compiler.identifier({ text: 'nonNullishAsync' }), 137 - nonOptionalAsync: compiler.identifier({ text: 'nonOptionalAsync' }), 138 - nullableAsync: compiler.identifier({ text: 'nullableAsync' }), 139 - nullishAsync: compiler.identifier({ text: 'nullishAsync' }), 140 - objectAsync: compiler.identifier({ text: 'objectAsync' }), 141 - objectWithRestAsync: compiler.identifier({ text: 'objectWithRestAsync' }), 142 - optionalAsync: compiler.identifier({ text: 'optionalAsync' }), 143 - parseAsync: compiler.identifier({ text: 'parseAsync' }), 144 - parserAsync: compiler.identifier({ text: 'parserAsync' }), 145 - partialAsync: compiler.identifier({ text: 'partialAsync' }), 146 - partialCheckAsync: compiler.identifier({ text: 'partialCheckAsync' }), 147 - pipeAsync: compiler.identifier({ text: 'pipeAsync' }), 148 - rawCheckAsync: compiler.identifier({ text: 'rawCheckAsync' }), 149 - rawTransformAsync: compiler.identifier({ text: 'rawTransformAsync' }), 150 - recordAsync: compiler.identifier({ text: 'recordAsync' }), 151 - requiredAsync: compiler.identifier({ text: 'requiredAsync' }), 152 - returnsAsync: compiler.identifier({ text: 'returnsAsync' }), 153 - safeParseAsync: compiler.identifier({ text: 'safeParseAsync' }), 154 - safeParserAsync: compiler.identifier({ text: 'safeParserAsync' }), 155 - setAsync: compiler.identifier({ text: 'setAsync' }), 156 - strictObjectAsync: compiler.identifier({ text: 'strictObjectAsync' }), 157 - strictTupleAsync: compiler.identifier({ text: 'strictTupleAsync' }), 158 - transformAsync: compiler.identifier({ text: 'transformAsync' }), 159 - tupleAsync: compiler.identifier({ text: 'tupleAsync' }), 160 - tupleWithRestAsync: compiler.identifier({ text: 'tupleWithRestAsync' }), 161 - undefinedableAsync: compiler.identifier({ text: 'undefinedableAsync' }), 162 - unionAsync: compiler.identifier({ text: 'unionAsync' }), 163 - variantAsync: compiler.identifier({ text: 'variantAsync' }), 119 + argsAsync: tsc.identifier({ text: 'argsAsync' }), 120 + arrayAsync: tsc.identifier({ text: 'arrayAsync' }), 121 + awaitAsync: tsc.identifier({ text: 'awaitAsync' }), 122 + checkAsync: tsc.identifier({ text: 'checkAsync' }), 123 + checkItemsAsync: tsc.identifier({ text: 'checkItemsAsync' }), 124 + customAsync: tsc.identifier({ text: 'customAsync' }), 125 + exactOptionalAsync: tsc.identifier({ text: 'exactOptionalAsync' }), 126 + fallbackAsync: tsc.identifier({ text: 'fallbackAsync' }), 127 + forwardAsync: tsc.identifier({ text: 'forwardAsync' }), 128 + getDefaultsAsync: tsc.identifier({ text: 'getDefaultsAsync' }), 129 + getFallbacksAsync: tsc.identifier({ text: 'getFallbacksAsync' }), 130 + intersectAsync: tsc.identifier({ text: 'intersectAsync' }), 131 + lazyAsync: tsc.identifier({ text: 'lazyAsync' }), 132 + looseObjectAsync: tsc.identifier({ text: 'looseObjectAsync' }), 133 + looseTupleAsync: tsc.identifier({ text: 'looseTupleAsync' }), 134 + mapAsync: tsc.identifier({ text: 'mapAsync' }), 135 + nonNullableAsync: tsc.identifier({ text: 'nonNullableAsync' }), 136 + nonNullishAsync: tsc.identifier({ text: 'nonNullishAsync' }), 137 + nonOptionalAsync: tsc.identifier({ text: 'nonOptionalAsync' }), 138 + nullableAsync: tsc.identifier({ text: 'nullableAsync' }), 139 + nullishAsync: tsc.identifier({ text: 'nullishAsync' }), 140 + objectAsync: tsc.identifier({ text: 'objectAsync' }), 141 + objectWithRestAsync: tsc.identifier({ text: 'objectWithRestAsync' }), 142 + optionalAsync: tsc.identifier({ text: 'optionalAsync' }), 143 + parseAsync: tsc.identifier({ text: 'parseAsync' }), 144 + parserAsync: tsc.identifier({ text: 'parserAsync' }), 145 + partialAsync: tsc.identifier({ text: 'partialAsync' }), 146 + partialCheckAsync: tsc.identifier({ text: 'partialCheckAsync' }), 147 + pipeAsync: tsc.identifier({ text: 'pipeAsync' }), 148 + rawCheckAsync: tsc.identifier({ text: 'rawCheckAsync' }), 149 + rawTransformAsync: tsc.identifier({ text: 'rawTransformAsync' }), 150 + recordAsync: tsc.identifier({ text: 'recordAsync' }), 151 + requiredAsync: tsc.identifier({ text: 'requiredAsync' }), 152 + returnsAsync: tsc.identifier({ text: 'returnsAsync' }), 153 + safeParseAsync: tsc.identifier({ text: 'safeParseAsync' }), 154 + safeParserAsync: tsc.identifier({ text: 'safeParserAsync' }), 155 + setAsync: tsc.identifier({ text: 'setAsync' }), 156 + strictObjectAsync: tsc.identifier({ text: 'strictObjectAsync' }), 157 + strictTupleAsync: tsc.identifier({ text: 'strictTupleAsync' }), 158 + transformAsync: tsc.identifier({ text: 'transformAsync' }), 159 + tupleAsync: tsc.identifier({ text: 'tupleAsync' }), 160 + tupleWithRestAsync: tsc.identifier({ text: 'tupleWithRestAsync' }), 161 + undefinedableAsync: tsc.identifier({ text: 'undefinedableAsync' }), 162 + unionAsync: tsc.identifier({ text: 'unionAsync' }), 163 + variantAsync: tsc.identifier({ text: 'variantAsync' }), 164 164 }, 165 165 /** 166 166 * {@link https://valibot.dev/api/#methods Methods} 167 167 */ 168 168 methods: { 169 - assert: compiler.identifier({ text: 'assert' }), 170 - config: compiler.identifier({ text: 'config' }), 171 - fallback: compiler.identifier({ text: 'fallback' }), 172 - flatten: compiler.identifier({ text: 'flatten' }), 173 - forward: compiler.identifier({ text: 'forward' }), 174 - getDefault: compiler.identifier({ text: 'getDefault' }), 175 - getDefaults: compiler.identifier({ text: 'getDefaults' }), 176 - getDescription: compiler.identifier({ text: 'getDescription' }), 177 - getFallback: compiler.identifier({ text: 'getFallback' }), 178 - getFallbacks: compiler.identifier({ text: 'getFallbacks' }), 179 - getMetadata: compiler.identifier({ text: 'getMetadata' }), 180 - getTitle: compiler.identifier({ text: 'getTitle' }), 181 - is: compiler.identifier({ text: 'is' }), 182 - keyof: compiler.identifier({ text: 'keyof' }), 183 - message: compiler.identifier({ text: 'message' }), 184 - omit: compiler.identifier({ text: 'omit' }), 185 - parse: compiler.identifier({ text: 'parse' }), 186 - parser: compiler.identifier({ text: 'parser' }), 187 - partial: compiler.identifier({ text: 'partial' }), 188 - pick: compiler.identifier({ text: 'pick' }), 189 - pipe: compiler.identifier({ text: 'pipe' }), 190 - required: compiler.identifier({ text: 'required' }), 191 - safeParse: compiler.identifier({ text: 'safeParse' }), 192 - safeParser: compiler.identifier({ text: 'safeParser' }), 193 - summarize: compiler.identifier({ text: 'summarize' }), 194 - unwrap: compiler.identifier({ text: 'unwrap' }), 169 + assert: tsc.identifier({ text: 'assert' }), 170 + config: tsc.identifier({ text: 'config' }), 171 + fallback: tsc.identifier({ text: 'fallback' }), 172 + flatten: tsc.identifier({ text: 'flatten' }), 173 + forward: tsc.identifier({ text: 'forward' }), 174 + getDefault: tsc.identifier({ text: 'getDefault' }), 175 + getDefaults: tsc.identifier({ text: 'getDefaults' }), 176 + getDescription: tsc.identifier({ text: 'getDescription' }), 177 + getFallback: tsc.identifier({ text: 'getFallback' }), 178 + getFallbacks: tsc.identifier({ text: 'getFallbacks' }), 179 + getMetadata: tsc.identifier({ text: 'getMetadata' }), 180 + getTitle: tsc.identifier({ text: 'getTitle' }), 181 + is: tsc.identifier({ text: 'is' }), 182 + keyof: tsc.identifier({ text: 'keyof' }), 183 + message: tsc.identifier({ text: 'message' }), 184 + omit: tsc.identifier({ text: 'omit' }), 185 + parse: tsc.identifier({ text: 'parse' }), 186 + parser: tsc.identifier({ text: 'parser' }), 187 + partial: tsc.identifier({ text: 'partial' }), 188 + pick: tsc.identifier({ text: 'pick' }), 189 + pipe: tsc.identifier({ text: 'pipe' }), 190 + required: tsc.identifier({ text: 'required' }), 191 + safeParse: tsc.identifier({ text: 'safeParse' }), 192 + safeParser: tsc.identifier({ text: 'safeParser' }), 193 + summarize: tsc.identifier({ text: 'summarize' }), 194 + unwrap: tsc.identifier({ text: 'unwrap' }), 195 195 }, 196 196 /** 197 197 * {@link https://valibot.dev/api/#schemas Schemas} 198 198 */ 199 199 schemas: { 200 - any: compiler.identifier({ text: 'any' }), 201 - array: compiler.identifier({ text: 'array' }), 202 - bigInt: compiler.identifier({ text: 'bigint' }), 203 - blob: compiler.identifier({ text: 'blob' }), 204 - boolean: compiler.identifier({ text: 'boolean' }), 205 - custom: compiler.identifier({ text: 'custom' }), 206 - date: compiler.identifier({ text: 'date' }), 207 - enum: compiler.identifier({ text: 'enum' }), 208 - exactOptional: compiler.identifier({ text: 'exactOptional' }), 209 - file: compiler.identifier({ text: 'file' }), 210 - function: compiler.identifier({ text: 'function' }), 211 - instance: compiler.identifier({ text: 'instance' }), 212 - intersect: compiler.identifier({ text: 'intersect' }), 213 - lazy: compiler.identifier({ text: 'lazy' }), 214 - literal: compiler.identifier({ text: 'literal' }), 215 - looseObject: compiler.identifier({ text: 'looseObject' }), 216 - looseTuple: compiler.identifier({ text: 'looseTuple' }), 217 - map: compiler.identifier({ text: 'map' }), 218 - nan: compiler.identifier({ text: 'nan' }), 219 - never: compiler.identifier({ text: 'never' }), 220 - nonNullable: compiler.identifier({ text: 'nonNullable' }), 221 - nonNullish: compiler.identifier({ text: 'nonNullish' }), 222 - nonOptional: compiler.identifier({ text: 'nonOptional' }), 223 - null: compiler.identifier({ text: 'null' }), 224 - nullable: compiler.identifier({ text: 'nullable' }), 225 - nullish: compiler.identifier({ text: 'nullish' }), 226 - number: compiler.identifier({ text: 'number' }), 227 - object: compiler.identifier({ text: 'object' }), 228 - objectWithRest: compiler.identifier({ text: 'objectWithRest' }), 229 - optional: compiler.identifier({ text: 'optional' }), 230 - picklist: compiler.identifier({ text: 'picklist' }), 231 - promise: compiler.identifier({ text: 'promise' }), 232 - record: compiler.identifier({ text: 'record' }), 233 - set: compiler.identifier({ text: 'set' }), 234 - strictObject: compiler.identifier({ text: 'strictObject' }), 235 - strictTuple: compiler.identifier({ text: 'strictTuple' }), 236 - string: compiler.identifier({ text: 'string' }), 237 - symbol: compiler.identifier({ text: 'symbol' }), 238 - tuple: compiler.identifier({ text: 'tuple' }), 239 - tupleWithRest: compiler.identifier({ text: 'tupleWithRest' }), 240 - undefined: compiler.identifier({ text: 'undefined' }), 241 - undefinedable: compiler.identifier({ text: 'undefinedable' }), 242 - union: compiler.identifier({ text: 'union' }), 243 - unknown: compiler.identifier({ text: 'unknown' }), 244 - variant: compiler.identifier({ text: 'variant' }), 245 - void: compiler.identifier({ text: 'void' }), 200 + any: tsc.identifier({ text: 'any' }), 201 + array: tsc.identifier({ text: 'array' }), 202 + bigInt: tsc.identifier({ text: 'bigint' }), 203 + blob: tsc.identifier({ text: 'blob' }), 204 + boolean: tsc.identifier({ text: 'boolean' }), 205 + custom: tsc.identifier({ text: 'custom' }), 206 + date: tsc.identifier({ text: 'date' }), 207 + enum: tsc.identifier({ text: 'enum' }), 208 + exactOptional: tsc.identifier({ text: 'exactOptional' }), 209 + file: tsc.identifier({ text: 'file' }), 210 + function: tsc.identifier({ text: 'function' }), 211 + instance: tsc.identifier({ text: 'instance' }), 212 + intersect: tsc.identifier({ text: 'intersect' }), 213 + lazy: tsc.identifier({ text: 'lazy' }), 214 + literal: tsc.identifier({ text: 'literal' }), 215 + looseObject: tsc.identifier({ text: 'looseObject' }), 216 + looseTuple: tsc.identifier({ text: 'looseTuple' }), 217 + map: tsc.identifier({ text: 'map' }), 218 + nan: tsc.identifier({ text: 'nan' }), 219 + never: tsc.identifier({ text: 'never' }), 220 + nonNullable: tsc.identifier({ text: 'nonNullable' }), 221 + nonNullish: tsc.identifier({ text: 'nonNullish' }), 222 + nonOptional: tsc.identifier({ text: 'nonOptional' }), 223 + null: tsc.identifier({ text: 'null' }), 224 + nullable: tsc.identifier({ text: 'nullable' }), 225 + nullish: tsc.identifier({ text: 'nullish' }), 226 + number: tsc.identifier({ text: 'number' }), 227 + object: tsc.identifier({ text: 'object' }), 228 + objectWithRest: tsc.identifier({ text: 'objectWithRest' }), 229 + optional: tsc.identifier({ text: 'optional' }), 230 + picklist: tsc.identifier({ text: 'picklist' }), 231 + promise: tsc.identifier({ text: 'promise' }), 232 + record: tsc.identifier({ text: 'record' }), 233 + set: tsc.identifier({ text: 'set' }), 234 + strictObject: tsc.identifier({ text: 'strictObject' }), 235 + strictTuple: tsc.identifier({ text: 'strictTuple' }), 236 + string: tsc.identifier({ text: 'string' }), 237 + symbol: tsc.identifier({ text: 'symbol' }), 238 + tuple: tsc.identifier({ text: 'tuple' }), 239 + tupleWithRest: tsc.identifier({ text: 'tupleWithRest' }), 240 + undefined: tsc.identifier({ text: 'undefined' }), 241 + undefinedable: tsc.identifier({ text: 'undefinedable' }), 242 + union: tsc.identifier({ text: 'union' }), 243 + unknown: tsc.identifier({ text: 'unknown' }), 244 + variant: tsc.identifier({ text: 'variant' }), 245 + void: tsc.identifier({ text: 'void' }), 246 246 }, 247 247 /** 248 248 * {@link https://valibot.dev/api/#storages Storages} ··· 255 255 */ 256 256 types: { 257 257 // TODO: implement if necessary 258 - GenericSchema: compiler.identifier({ text: 'GenericSchema' }), 258 + GenericSchema: tsc.identifier({ text: 'GenericSchema' }), 259 259 }, 260 260 /** 261 261 * {@link https://valibot.dev/api/#utils Utils} ··· 263 263 utils: { 264 264 // TODO: implement if necessary 265 265 }, 266 - v: compiler.identifier({ text: 'v' }), 266 + v: tsc.identifier({ text: 'v' }), 267 267 }; 268 268 269 269 export const valibotId = 'valibot';
+3 -3
packages/openapi-ts/src/plugins/valibot/number-helpers.ts
··· 1 - import { compiler } from '../../compiler'; 1 + import { tsc } from '../../tsc'; 2 2 3 3 // Integer format ranges and properties 4 4 export const INTEGER_FORMATS = { ··· 76 76 isBigInt: boolean; 77 77 value: unknown; 78 78 }) => { 79 - const expression = compiler.valueToExpression({ value }); 79 + const expression = tsc.valueToExpression({ value }); 80 80 81 81 if ( 82 82 isBigInt && ··· 85 85 typeof value === 'string' || 86 86 typeof value === 'boolean') 87 87 ) { 88 - return compiler.callExpression({ 88 + return tsc.callExpression({ 89 89 functionName: 'BigInt', 90 90 parameters: [expression], 91 91 });
+156 -156
packages/openapi-ts/src/plugins/valibot/plugin.ts
··· 1 1 import ts from 'typescript'; 2 2 3 - import { compiler } from '../../compiler'; 4 3 import type { Identifier } from '../../generate/file/types'; 5 4 import { deduplicateSchema } from '../../ir/schema'; 6 5 import type { IR } from '../../ir/types'; 6 + import { tsc } from '../../tsc'; 7 7 import type { StringCase, StringName } from '../../types/case'; 8 8 import { numberRegExp } from '../../utils/regexp'; 9 9 import { createSchemaComment } from '../shared/utils/schema'; ··· 34 34 return pipes[0]!; 35 35 } 36 36 37 - const expression = compiler.callExpression({ 38 - functionName: compiler.propertyAccessExpression({ 37 + const expression = tsc.callExpression({ 38 + functionName: tsc.propertyAccessExpression({ 39 39 expression: identifiers.v, 40 40 name: identifiers.methods.pipe, 41 41 }), ··· 53 53 schema: SchemaWithType<'array'>; 54 54 state: State; 55 55 }): ts.Expression => { 56 - const functionName = compiler.propertyAccessExpression({ 56 + const functionName = tsc.propertyAccessExpression({ 57 57 expression: identifiers.v, 58 58 name: identifiers.schemas.array, 59 59 }); ··· 61 61 const pipes: Array<ts.CallExpression> = []; 62 62 63 63 if (!schema.items) { 64 - const expression = compiler.callExpression({ 64 + const expression = tsc.callExpression({ 65 65 functionName, 66 66 parameters: [ 67 67 unknownTypeToValibotSchema({ ··· 86 86 }); 87 87 88 88 if (itemExpressions.length === 1) { 89 - const expression = compiler.callExpression({ 89 + const expression = tsc.callExpression({ 90 90 functionName, 91 91 parameters: itemExpressions, 92 92 }); ··· 94 94 } else { 95 95 if (schema.logicalOperator === 'and') { 96 96 // TODO: parser - handle intersection 97 - // return compiler.typeArrayNode( 98 - // compiler.typeIntersectionNode({ types: itemExpressions }), 97 + // return tsc.typeArrayNode( 98 + // tsc.typeIntersectionNode({ types: itemExpressions }), 99 99 // ); 100 100 } 101 101 102 102 // TODO: parser - handle union 103 - // return compiler.typeArrayNode(compiler.typeUnionNode({ types: itemExpressions })); 103 + // return tsc.typeArrayNode(tsc.typeUnionNode({ types: itemExpressions })); 104 104 105 - const expression = compiler.callExpression({ 105 + const expression = tsc.callExpression({ 106 106 functionName, 107 107 parameters: [ 108 108 unknownTypeToValibotSchema({ ··· 117 117 } 118 118 119 119 if (schema.minItems === schema.maxItems && schema.minItems !== undefined) { 120 - const expression = compiler.callExpression({ 121 - functionName: compiler.propertyAccessExpression({ 120 + const expression = tsc.callExpression({ 121 + functionName: tsc.propertyAccessExpression({ 122 122 expression: identifiers.v, 123 123 name: identifiers.actions.length, 124 124 }), 125 - parameters: [compiler.valueToExpression({ value: schema.minItems })], 125 + parameters: [tsc.valueToExpression({ value: schema.minItems })], 126 126 }); 127 127 pipes.push(expression); 128 128 } else { 129 129 if (schema.minItems !== undefined) { 130 - const expression = compiler.callExpression({ 131 - functionName: compiler.propertyAccessExpression({ 130 + const expression = tsc.callExpression({ 131 + functionName: tsc.propertyAccessExpression({ 132 132 expression: identifiers.v, 133 133 name: identifiers.actions.minLength, 134 134 }), 135 - parameters: [compiler.valueToExpression({ value: schema.minItems })], 135 + parameters: [tsc.valueToExpression({ value: schema.minItems })], 136 136 }); 137 137 pipes.push(expression); 138 138 } 139 139 140 140 if (schema.maxItems !== undefined) { 141 - const expression = compiler.callExpression({ 142 - functionName: compiler.propertyAccessExpression({ 141 + const expression = tsc.callExpression({ 142 + functionName: tsc.propertyAccessExpression({ 143 143 expression: identifiers.v, 144 144 name: identifiers.actions.maxLength, 145 145 }), 146 - parameters: [compiler.valueToExpression({ value: schema.maxItems })], 146 + parameters: [tsc.valueToExpression({ value: schema.maxItems })], 147 147 }); 148 148 pipes.push(expression); 149 149 } ··· 158 158 schema: SchemaWithType<'boolean'>; 159 159 }) => { 160 160 if (typeof schema.const === 'boolean') { 161 - const expression = compiler.callExpression({ 162 - functionName: compiler.propertyAccessExpression({ 161 + const expression = tsc.callExpression({ 162 + functionName: tsc.propertyAccessExpression({ 163 163 expression: identifiers.v, 164 164 name: identifiers.schemas.literal, 165 165 }), 166 - parameters: [compiler.ots.boolean(schema.const)], 166 + parameters: [tsc.ots.boolean(schema.const)], 167 167 }); 168 168 return expression; 169 169 } 170 170 171 - const expression = compiler.callExpression({ 172 - functionName: compiler.propertyAccessExpression({ 171 + const expression = tsc.callExpression({ 172 + functionName: tsc.propertyAccessExpression({ 173 173 expression: identifiers.v, 174 174 name: identifiers.schemas.boolean, 175 175 }), ··· 190 190 // Zod supports only string enums 191 191 if (item.type === 'string' && typeof item.const === 'string') { 192 192 enumMembers.push( 193 - compiler.stringLiteral({ 193 + tsc.stringLiteral({ 194 194 text: item.const, 195 195 }), 196 196 ); ··· 207 207 }); 208 208 } 209 209 210 - let resultExpression = compiler.callExpression({ 211 - functionName: compiler.propertyAccessExpression({ 210 + let resultExpression = tsc.callExpression({ 211 + functionName: tsc.propertyAccessExpression({ 212 212 expression: identifiers.v, 213 213 name: identifiers.schemas.picklist, 214 214 }), 215 215 parameters: [ 216 - compiler.arrayLiteralExpression({ 216 + tsc.arrayLiteralExpression({ 217 217 elements: enumMembers, 218 218 multiLine: false, 219 219 }), ··· 221 221 }); 222 222 223 223 if (isNullable) { 224 - resultExpression = compiler.callExpression({ 225 - functionName: compiler.propertyAccessExpression({ 224 + resultExpression = tsc.callExpression({ 225 + functionName: tsc.propertyAccessExpression({ 226 226 expression: identifiers.v, 227 227 name: identifiers.schemas.nullable, 228 228 }), ··· 237 237 const neverTypeToValibotSchema = (_props: { 238 238 schema: SchemaWithType<'never'>; 239 239 }) => { 240 - const expression = compiler.callExpression({ 241 - functionName: compiler.propertyAccessExpression({ 240 + const expression = tsc.callExpression({ 241 + functionName: tsc.propertyAccessExpression({ 242 242 expression: identifiers.v, 243 243 name: identifiers.schemas.never, 244 244 }), ··· 250 250 const nullTypeToValibotSchema = (_props: { 251 251 schema: SchemaWithType<'null'>; 252 252 }) => { 253 - const expression = compiler.callExpression({ 254 - functionName: compiler.propertyAccessExpression({ 253 + const expression = tsc.callExpression({ 254 + functionName: tsc.propertyAccessExpression({ 255 255 expression: identifiers.v, 256 256 name: identifiers.schemas.null, 257 257 }), ··· 276 276 277 277 // Case 1: Number with no format -> generate literal with the number 278 278 if (typeof constValue === 'number' && !format) { 279 - literalValue = compiler.ots.number(constValue); 279 + literalValue = tsc.ots.number(constValue); 280 280 } 281 281 // Case 2: Number with format -> check if format needs BigInt, generate appropriate literal 282 282 else if (typeof constValue === 'number' && format) { 283 283 if (isBigInt) { 284 284 // Format requires BigInt, convert number to BigInt 285 - literalValue = compiler.callExpression({ 285 + literalValue = tsc.callExpression({ 286 286 functionName: 'BigInt', 287 - parameters: [compiler.ots.string(constValue.toString())], 287 + parameters: [tsc.ots.string(constValue.toString())], 288 288 }); 289 289 } else { 290 290 // Regular format, use number as-is 291 - literalValue = compiler.ots.number(constValue); 291 + literalValue = tsc.ots.number(constValue); 292 292 } 293 293 } 294 294 // Case 3: Format that allows string -> generate BigInt literal (for int64/uint64 formats) ··· 297 297 const cleanString = constValue.endsWith('n') 298 298 ? constValue.slice(0, -1) 299 299 : constValue; 300 - literalValue = compiler.callExpression({ 300 + literalValue = tsc.callExpression({ 301 301 functionName: 'BigInt', 302 - parameters: [compiler.ots.string(cleanString)], 302 + parameters: [tsc.ots.string(cleanString)], 303 303 }); 304 304 } 305 305 // Case 4: Const is typeof bigint (literal) -> transform from literal to BigInt() ··· 309 309 const cleanString = bigintString.endsWith('n') 310 310 ? bigintString.slice(0, -1) 311 311 : bigintString; 312 - literalValue = compiler.callExpression({ 312 + literalValue = tsc.callExpression({ 313 313 functionName: 'BigInt', 314 - parameters: [compiler.ots.string(cleanString)], 314 + parameters: [tsc.ots.string(cleanString)], 315 315 }); 316 316 } 317 317 // Default case: use value as-is for other types 318 318 else { 319 - literalValue = compiler.valueToExpression({ value: constValue }); 319 + literalValue = tsc.valueToExpression({ value: constValue }); 320 320 } 321 321 322 - return compiler.callExpression({ 323 - functionName: compiler.propertyAccessExpression({ 322 + return tsc.callExpression({ 323 + functionName: tsc.propertyAccessExpression({ 324 324 expression: identifiers.v, 325 325 name: identifiers.schemas.literal, 326 326 }), ··· 332 332 333 333 // For bigint formats (int64, uint64), create union of number, string, and bigint with transform 334 334 if (isBigInt) { 335 - const unionExpression = compiler.callExpression({ 336 - functionName: compiler.propertyAccessExpression({ 335 + const unionExpression = tsc.callExpression({ 336 + functionName: tsc.propertyAccessExpression({ 337 337 expression: identifiers.v, 338 338 name: identifiers.schemas.union, 339 339 }), 340 340 parameters: [ 341 - compiler.arrayLiteralExpression({ 341 + tsc.arrayLiteralExpression({ 342 342 elements: [ 343 - compiler.callExpression({ 344 - functionName: compiler.propertyAccessExpression({ 343 + tsc.callExpression({ 344 + functionName: tsc.propertyAccessExpression({ 345 345 expression: identifiers.v, 346 346 name: identifiers.schemas.number, 347 347 }), 348 348 }), 349 - compiler.callExpression({ 350 - functionName: compiler.propertyAccessExpression({ 349 + tsc.callExpression({ 350 + functionName: tsc.propertyAccessExpression({ 351 351 expression: identifiers.v, 352 352 name: identifiers.schemas.string, 353 353 }), 354 354 }), 355 - compiler.callExpression({ 356 - functionName: compiler.propertyAccessExpression({ 355 + tsc.callExpression({ 356 + functionName: tsc.propertyAccessExpression({ 357 357 expression: identifiers.v, 358 358 name: identifiers.schemas.bigInt, 359 359 }), ··· 366 366 pipes.push(unionExpression); 367 367 368 368 // Add transform to convert to BigInt 369 - const transformExpression = compiler.callExpression({ 370 - functionName: compiler.propertyAccessExpression({ 369 + const transformExpression = tsc.callExpression({ 370 + functionName: tsc.propertyAccessExpression({ 371 371 expression: identifiers.v, 372 372 name: identifiers.actions.transform, 373 373 }), 374 374 parameters: [ 375 - compiler.arrowFunction({ 375 + tsc.arrowFunction({ 376 376 parameters: [{ name: 'x' }], 377 - statements: compiler.callExpression({ 377 + statements: tsc.callExpression({ 378 378 functionName: 'BigInt', 379 - parameters: [compiler.identifier({ text: 'x' })], 379 + parameters: [tsc.identifier({ text: 'x' })], 380 380 }), 381 381 }), 382 382 ], ··· 384 384 pipes.push(transformExpression); 385 385 } else { 386 386 // For regular number formats, use number schema 387 - const expression = compiler.callExpression({ 388 - functionName: compiler.propertyAccessExpression({ 387 + const expression = tsc.callExpression({ 388 + functionName: tsc.propertyAccessExpression({ 389 389 expression: identifiers.v, 390 390 name: identifiers.schemas.number, 391 391 }), ··· 395 395 396 396 // Add integer validation for integer types (except when using bigint union) 397 397 if (!isBigInt && isInteger) { 398 - const expression = compiler.callExpression({ 399 - functionName: compiler.propertyAccessExpression({ 398 + const expression = tsc.callExpression({ 399 + functionName: tsc.propertyAccessExpression({ 400 400 expression: identifiers.v, 401 401 name: identifiers.actions.integer, 402 402 }), ··· 412 412 const maxErrorMessage = formatInfo.maxError; 413 413 414 414 // Add minimum value validation 415 - const minExpression = compiler.callExpression({ 416 - functionName: compiler.propertyAccessExpression({ 415 + const minExpression = tsc.callExpression({ 416 + functionName: tsc.propertyAccessExpression({ 417 417 expression: identifiers.v, 418 418 name: identifiers.actions.minValue, 419 419 }), 420 420 parameters: [ 421 421 isBigInt 422 - ? compiler.callExpression({ 422 + ? tsc.callExpression({ 423 423 functionName: 'BigInt', 424 - parameters: [compiler.ots.string(minValue.toString())], 424 + parameters: [tsc.ots.string(minValue.toString())], 425 425 }) 426 - : compiler.ots.number(minValue as number), 427 - compiler.ots.string(minErrorMessage), 426 + : tsc.ots.number(minValue as number), 427 + tsc.ots.string(minErrorMessage), 428 428 ], 429 429 }); 430 430 pipes.push(minExpression); 431 431 432 432 // Add maximum value validation 433 - const maxExpression = compiler.callExpression({ 434 - functionName: compiler.propertyAccessExpression({ 433 + const maxExpression = tsc.callExpression({ 434 + functionName: tsc.propertyAccessExpression({ 435 435 expression: identifiers.v, 436 436 name: identifiers.actions.maxValue, 437 437 }), 438 438 parameters: [ 439 439 isBigInt 440 - ? compiler.callExpression({ 440 + ? tsc.callExpression({ 441 441 functionName: 'BigInt', 442 - parameters: [compiler.ots.string(maxValue.toString())], 442 + parameters: [tsc.ots.string(maxValue.toString())], 443 443 }) 444 - : compiler.ots.number(maxValue as number), 445 - compiler.ots.string(maxErrorMessage), 444 + : tsc.ots.number(maxValue as number), 445 + tsc.ots.string(maxErrorMessage), 446 446 ], 447 447 }); 448 448 pipes.push(maxExpression); 449 449 } 450 450 451 451 if (schema.exclusiveMinimum !== undefined) { 452 - const expression = compiler.callExpression({ 453 - functionName: compiler.propertyAccessExpression({ 452 + const expression = tsc.callExpression({ 453 + functionName: tsc.propertyAccessExpression({ 454 454 expression: identifiers.v, 455 455 name: identifiers.actions.gtValue, 456 456 }), ··· 460 460 }); 461 461 pipes.push(expression); 462 462 } else if (schema.minimum !== undefined) { 463 - const expression = compiler.callExpression({ 464 - functionName: compiler.propertyAccessExpression({ 463 + const expression = tsc.callExpression({ 464 + functionName: tsc.propertyAccessExpression({ 465 465 expression: identifiers.v, 466 466 name: identifiers.actions.minValue, 467 467 }), ··· 471 471 } 472 472 473 473 if (schema.exclusiveMaximum !== undefined) { 474 - const expression = compiler.callExpression({ 475 - functionName: compiler.propertyAccessExpression({ 474 + const expression = tsc.callExpression({ 475 + functionName: tsc.propertyAccessExpression({ 476 476 expression: identifiers.v, 477 477 name: identifiers.actions.ltValue, 478 478 }), ··· 482 482 }); 483 483 pipes.push(expression); 484 484 } else if (schema.maximum !== undefined) { 485 - const expression = compiler.callExpression({ 486 - functionName: compiler.propertyAccessExpression({ 485 + const expression = tsc.callExpression({ 486 + functionName: tsc.propertyAccessExpression({ 487 487 expression: identifiers.v, 488 488 name: identifiers.actions.maxValue, 489 489 }), ··· 543 543 propertyName = `'${name}'`; 544 544 } 545 545 properties.push( 546 - compiler.propertyAssignment({ 546 + tsc.propertyAssignment({ 547 547 initializer: pipesToExpression(schemaPipes), 548 548 name: propertyName, 549 549 }), ··· 560 560 schema: schema.additionalProperties, 561 561 state, 562 562 }); 563 - const expression = compiler.callExpression({ 564 - functionName: compiler.propertyAccessExpression({ 563 + const expression = tsc.callExpression({ 564 + functionName: tsc.propertyAccessExpression({ 565 565 expression: identifiers.v, 566 566 name: identifiers.schemas.record, 567 567 }), 568 568 parameters: [ 569 - compiler.callExpression({ 570 - functionName: compiler.propertyAccessExpression({ 569 + tsc.callExpression({ 570 + functionName: tsc.propertyAccessExpression({ 571 571 expression: identifiers.v, 572 572 name: identifiers.schemas.string, 573 573 }), ··· 582 582 }; 583 583 } 584 584 585 - const expression = compiler.callExpression({ 586 - functionName: compiler.propertyAccessExpression({ 585 + const expression = tsc.callExpression({ 586 + functionName: tsc.propertyAccessExpression({ 587 587 expression: identifiers.v, 588 588 name: identifiers.schemas.object, 589 589 }), ··· 602 602 schema: SchemaWithType<'string'>; 603 603 }) => { 604 604 if (typeof schema.const === 'string') { 605 - const expression = compiler.callExpression({ 606 - functionName: compiler.propertyAccessExpression({ 605 + const expression = tsc.callExpression({ 606 + functionName: tsc.propertyAccessExpression({ 607 607 expression: identifiers.v, 608 608 name: identifiers.schemas.literal, 609 609 }), 610 - parameters: [compiler.ots.string(schema.const)], 610 + parameters: [tsc.ots.string(schema.const)], 611 611 }); 612 612 return expression; 613 613 } 614 614 615 615 const pipes: Array<ts.CallExpression> = []; 616 616 617 - const expression = compiler.callExpression({ 618 - functionName: compiler.propertyAccessExpression({ 617 + const expression = tsc.callExpression({ 618 + functionName: tsc.propertyAccessExpression({ 619 619 expression: identifiers.v, 620 620 name: identifiers.schemas.string, 621 621 }), ··· 626 626 switch (schema.format) { 627 627 case 'date': 628 628 pipes.push( 629 - compiler.callExpression({ 630 - functionName: compiler.propertyAccessExpression({ 629 + tsc.callExpression({ 630 + functionName: tsc.propertyAccessExpression({ 631 631 expression: identifiers.v, 632 632 name: identifiers.actions.isoDate, 633 633 }), ··· 636 636 break; 637 637 case 'date-time': 638 638 pipes.push( 639 - compiler.callExpression({ 640 - functionName: compiler.propertyAccessExpression({ 639 + tsc.callExpression({ 640 + functionName: tsc.propertyAccessExpression({ 641 641 expression: identifiers.v, 642 642 name: identifiers.actions.isoTimestamp, 643 643 }), ··· 647 647 case 'ipv4': 648 648 case 'ipv6': 649 649 pipes.push( 650 - compiler.callExpression({ 651 - functionName: compiler.propertyAccessExpression({ 650 + tsc.callExpression({ 651 + functionName: tsc.propertyAccessExpression({ 652 652 expression: identifiers.v, 653 653 name: identifiers.actions.ip, 654 654 }), ··· 657 657 break; 658 658 case 'uri': 659 659 pipes.push( 660 - compiler.callExpression({ 661 - functionName: compiler.propertyAccessExpression({ 660 + tsc.callExpression({ 661 + functionName: tsc.propertyAccessExpression({ 662 662 expression: identifiers.v, 663 663 name: identifiers.actions.url, 664 664 }), ··· 669 669 case 'time': 670 670 case 'uuid': 671 671 pipes.push( 672 - compiler.callExpression({ 673 - functionName: compiler.propertyAccessExpression({ 672 + tsc.callExpression({ 673 + functionName: tsc.propertyAccessExpression({ 674 674 expression: identifiers.v, 675 - name: compiler.identifier({ text: schema.format }), 675 + name: tsc.identifier({ text: schema.format }), 676 676 }), 677 677 }), 678 678 ); ··· 681 681 } 682 682 683 683 if (schema.minLength === schema.maxLength && schema.minLength !== undefined) { 684 - const expression = compiler.callExpression({ 685 - functionName: compiler.propertyAccessExpression({ 684 + const expression = tsc.callExpression({ 685 + functionName: tsc.propertyAccessExpression({ 686 686 expression: identifiers.v, 687 687 name: identifiers.actions.length, 688 688 }), 689 - parameters: [compiler.valueToExpression({ value: schema.minLength })], 689 + parameters: [tsc.valueToExpression({ value: schema.minLength })], 690 690 }); 691 691 pipes.push(expression); 692 692 } else { 693 693 if (schema.minLength !== undefined) { 694 - const expression = compiler.callExpression({ 695 - functionName: compiler.propertyAccessExpression({ 694 + const expression = tsc.callExpression({ 695 + functionName: tsc.propertyAccessExpression({ 696 696 expression: identifiers.v, 697 697 name: identifiers.actions.minLength, 698 698 }), 699 - parameters: [compiler.valueToExpression({ value: schema.minLength })], 699 + parameters: [tsc.valueToExpression({ value: schema.minLength })], 700 700 }); 701 701 pipes.push(expression); 702 702 } 703 703 704 704 if (schema.maxLength !== undefined) { 705 - const expression = compiler.callExpression({ 706 - functionName: compiler.propertyAccessExpression({ 705 + const expression = tsc.callExpression({ 706 + functionName: tsc.propertyAccessExpression({ 707 707 expression: identifiers.v, 708 708 name: identifiers.actions.maxLength, 709 709 }), 710 - parameters: [compiler.valueToExpression({ value: schema.maxLength })], 710 + parameters: [tsc.valueToExpression({ value: schema.maxLength })], 711 711 }); 712 712 pipes.push(expression); 713 713 } 714 714 } 715 715 716 716 if (schema.pattern) { 717 - const expression = compiler.callExpression({ 718 - functionName: compiler.propertyAccessExpression({ 717 + const expression = tsc.callExpression({ 718 + functionName: tsc.propertyAccessExpression({ 719 719 expression: identifiers.v, 720 720 name: identifiers.actions.regex, 721 721 }), 722 - parameters: [compiler.regularExpressionLiteral({ text: schema.pattern })], 722 + parameters: [tsc.regularExpressionLiteral({ text: schema.pattern })], 723 723 }); 724 724 pipes.push(expression); 725 725 } ··· 738 738 }) => { 739 739 if (schema.const && Array.isArray(schema.const)) { 740 740 const tupleElements = schema.const.map((value) => 741 - compiler.callExpression({ 742 - functionName: compiler.propertyAccessExpression({ 741 + tsc.callExpression({ 742 + functionName: tsc.propertyAccessExpression({ 743 743 expression: identifiers.v, 744 744 name: identifiers.schemas.literal, 745 745 }), 746 - parameters: [compiler.valueToExpression({ value })], 746 + parameters: [tsc.valueToExpression({ value })], 747 747 }), 748 748 ); 749 - const expression = compiler.callExpression({ 750 - functionName: compiler.propertyAccessExpression({ 749 + const expression = tsc.callExpression({ 750 + functionName: tsc.propertyAccessExpression({ 751 751 expression: identifiers.v, 752 752 name: identifiers.schemas.tuple, 753 753 }), 754 754 parameters: [ 755 - compiler.arrayLiteralExpression({ 755 + tsc.arrayLiteralExpression({ 756 756 elements: tupleElements, 757 757 }), 758 758 ], ··· 769 769 }); 770 770 return pipesToExpression(schemaPipes); 771 771 }); 772 - const expression = compiler.callExpression({ 773 - functionName: compiler.propertyAccessExpression({ 772 + const expression = tsc.callExpression({ 773 + functionName: tsc.propertyAccessExpression({ 774 774 expression: identifiers.v, 775 775 name: identifiers.schemas.tuple, 776 776 }), 777 777 parameters: [ 778 - compiler.arrayLiteralExpression({ 778 + tsc.arrayLiteralExpression({ 779 779 elements: tupleElements, 780 780 }), 781 781 ], ··· 794 794 const undefinedTypeToValibotSchema = (_props: { 795 795 schema: SchemaWithType<'undefined'>; 796 796 }) => { 797 - const expression = compiler.callExpression({ 798 - functionName: compiler.propertyAccessExpression({ 797 + const expression = tsc.callExpression({ 798 + functionName: tsc.propertyAccessExpression({ 799 799 expression: identifiers.v, 800 800 name: identifiers.schemas.undefined, 801 801 }), ··· 807 807 const unknownTypeToValibotSchema = (_props: { 808 808 schema: SchemaWithType<'unknown'>; 809 809 }) => { 810 - const expression = compiler.callExpression({ 811 - functionName: compiler.propertyAccessExpression({ 810 + const expression = tsc.callExpression({ 811 + functionName: tsc.propertyAccessExpression({ 812 812 expression: identifiers.v, 813 813 name: identifiers.schemas.unknown, 814 814 }), ··· 820 820 const voidTypeToValibotSchema = (_props: { 821 821 schema: SchemaWithType<'void'>; 822 822 }) => { 823 - const expression = compiler.callExpression({ 824 - functionName: compiler.propertyAccessExpression({ 823 + const expression = tsc.callExpression({ 824 + functionName: tsc.propertyAccessExpression({ 825 825 expression: identifiers.v, 826 826 name: identifiers.schemas.void, 827 827 }), ··· 1006 1006 1007 1007 // if `identifierRef.name` is falsy, we already set expression above 1008 1008 if (identifierRef.name) { 1009 - const refIdentifier = compiler.identifier({ text: identifierRef.name }); 1009 + const refIdentifier = tsc.identifier({ text: identifierRef.name }); 1010 1010 if (isCircularReference) { 1011 - const lazyExpression = compiler.callExpression({ 1012 - functionName: compiler.propertyAccessExpression({ 1011 + const lazyExpression = tsc.callExpression({ 1012 + functionName: tsc.propertyAccessExpression({ 1013 1013 expression: identifiers.v, 1014 1014 name: identifiers.schemas.lazy, 1015 1015 }), 1016 1016 parameters: [ 1017 - compiler.arrowFunction({ 1017 + tsc.arrowFunction({ 1018 1018 statements: [ 1019 - compiler.returnStatement({ 1019 + tsc.returnStatement({ 1020 1020 expression: refIdentifier, 1021 1021 }), 1022 1022 ], ··· 1035 1035 pipes.push(valibotSchema.expression); 1036 1036 1037 1037 if (plugin.config.metadata && schema.description) { 1038 - const expression = compiler.callExpression({ 1039 - functionName: compiler.propertyAccessExpression({ 1038 + const expression = tsc.callExpression({ 1039 + functionName: tsc.propertyAccessExpression({ 1040 1040 expression: identifiers.v, 1041 1041 name: identifiers.actions.metadata, 1042 1042 }), 1043 1043 parameters: [ 1044 - compiler.objectExpression({ 1044 + tsc.objectExpression({ 1045 1045 obj: [ 1046 1046 { 1047 1047 key: 'description', 1048 - value: compiler.stringLiteral({ text: schema.description }), 1048 + value: tsc.stringLiteral({ text: schema.description }), 1049 1049 }, 1050 1050 ], 1051 1051 }), ··· 1067 1067 }); 1068 1068 1069 1069 if (schema.logicalOperator === 'and') { 1070 - const intersectExpression = compiler.callExpression({ 1071 - functionName: compiler.propertyAccessExpression({ 1070 + const intersectExpression = tsc.callExpression({ 1071 + functionName: tsc.propertyAccessExpression({ 1072 1072 expression: identifiers.v, 1073 1073 name: identifiers.schemas.intersect, 1074 1074 }), 1075 1075 parameters: [ 1076 - compiler.arrayLiteralExpression({ 1076 + tsc.arrayLiteralExpression({ 1077 1077 elements: itemTypes, 1078 1078 }), 1079 1079 ], 1080 1080 }); 1081 1081 pipes.push(intersectExpression); 1082 1082 } else { 1083 - const unionExpression = compiler.callExpression({ 1084 - functionName: compiler.propertyAccessExpression({ 1083 + const unionExpression = tsc.callExpression({ 1084 + functionName: tsc.propertyAccessExpression({ 1085 1085 expression: identifiers.v, 1086 1086 name: identifiers.schemas.union, 1087 1087 }), 1088 1088 parameters: [ 1089 - compiler.arrayLiteralExpression({ 1089 + tsc.arrayLiteralExpression({ 1090 1090 elements: itemTypes, 1091 1091 }), 1092 1092 ], ··· 1120 1120 1121 1121 if (pipes.length) { 1122 1122 if (schema.accessScope === 'read') { 1123 - const readonlyExpression = compiler.callExpression({ 1124 - functionName: compiler.propertyAccessExpression({ 1123 + const readonlyExpression = tsc.callExpression({ 1124 + functionName: tsc.propertyAccessExpression({ 1125 1125 expression: identifiers.v, 1126 1126 name: identifiers.actions.readonly, 1127 1127 }), ··· 1138 1138 callParameter = numberParameter({ isBigInt, value: schema.default }); 1139 1139 if (callParameter) { 1140 1140 pipes = [ 1141 - compiler.callExpression({ 1142 - functionName: compiler.propertyAccessExpression({ 1141 + tsc.callExpression({ 1142 + functionName: tsc.propertyAccessExpression({ 1143 1143 expression: identifiers.v, 1144 1144 name: identifiers.schemas.optional, 1145 1145 }), ··· 1151 1151 1152 1152 if (optional && !callParameter) { 1153 1153 pipes = [ 1154 - compiler.callExpression({ 1155 - functionName: compiler.propertyAccessExpression({ 1154 + tsc.callExpression({ 1155 + functionName: tsc.propertyAccessExpression({ 1156 1156 expression: identifiers.v, 1157 1157 name: identifiers.schemas.optional, 1158 1158 }), ··· 1164 1164 1165 1165 // emit nodes only if $ref points to a reusable component 1166 1166 if (identifier && identifier.name && identifier.created) { 1167 - const statement = compiler.constVariable({ 1167 + const statement = tsc.constVariable({ 1168 1168 comment: plugin.config.comments 1169 1169 ? createSchemaComment({ schema }) 1170 1170 : undefined, ··· 1172 1172 expression: pipesToExpression(pipes), 1173 1173 name: identifier.name, 1174 1174 typeName: state.hasCircularReference 1175 - ? (compiler.propertyAccessExpression({ 1175 + ? (tsc.propertyAccessExpression({ 1176 1176 expression: identifiers.v, 1177 1177 name: anyType || identifiers.types.GenericSchema.text, 1178 1178 }) as unknown as ts.TypeNode)
+15 -15
packages/openapi-ts/src/plugins/zod/api.ts
··· 1 1 import type ts from 'typescript'; 2 2 3 - import { compiler } from '../../compiler'; 4 3 import type { GeneratedFile } from '../../generate/file'; 5 4 import type { IR } from '../../ir/types'; 5 + import { tsc } from '../../tsc'; 6 6 import { identifiers, zodId } from './constants'; 7 7 import type { ZodPlugin } from './types'; 8 8 ··· 29 29 30 30 const dataParameterName = 'data'; 31 31 32 - return compiler.arrowFunction({ 32 + return tsc.arrowFunction({ 33 33 async: true, 34 34 parameters: [ 35 35 { ··· 37 37 }, 38 38 ], 39 39 statements: [ 40 - compiler.returnStatement({ 41 - expression: compiler.awaitExpression({ 42 - expression: compiler.callExpression({ 43 - functionName: compiler.propertyAccessExpression({ 44 - expression: compiler.identifier({ text: name }), 40 + tsc.returnStatement({ 41 + expression: tsc.awaitExpression({ 42 + expression: tsc.callExpression({ 43 + functionName: tsc.propertyAccessExpression({ 44 + expression: tsc.identifier({ text: name }), 45 45 name: identifiers.parseAsync, 46 46 }), 47 - parameters: [compiler.identifier({ text: dataParameterName })], 47 + parameters: [tsc.identifier({ text: dataParameterName })], 48 48 }), 49 49 }), 50 50 }), ··· 77 77 78 78 const dataParameterName = 'data'; 79 79 80 - return compiler.arrowFunction({ 80 + return tsc.arrowFunction({ 81 81 async: true, 82 82 parameters: [ 83 83 { ··· 85 85 }, 86 86 ], 87 87 statements: [ 88 - compiler.returnStatement({ 89 - expression: compiler.awaitExpression({ 90 - expression: compiler.callExpression({ 91 - functionName: compiler.propertyAccessExpression({ 92 - expression: compiler.identifier({ text: name }), 88 + tsc.returnStatement({ 89 + expression: tsc.awaitExpression({ 90 + expression: tsc.callExpression({ 91 + functionName: tsc.propertyAccessExpression({ 92 + expression: tsc.identifier({ text: name }), 93 93 name: identifiers.parseAsync, 94 94 }), 95 - parameters: [compiler.identifier({ text: dataParameterName })], 95 + parameters: [tsc.identifier({ text: dataParameterName })], 96 96 }), 97 97 }), 98 98 }),
+56 -56
packages/openapi-ts/src/plugins/zod/constants.ts
··· 1 - import { compiler } from '../../compiler'; 1 + import { tsc } from '../../tsc'; 2 2 3 3 export const identifiers = { 4 - ZodMiniOptional: compiler.identifier({ text: 'ZodMiniOptional' }), 5 - ZodOptional: compiler.identifier({ text: 'ZodOptional' }), 6 - _default: compiler.identifier({ text: '_default' }), 7 - and: compiler.identifier({ text: 'and' }), 8 - array: compiler.identifier({ text: 'array' }), 9 - bigint: compiler.identifier({ text: 'bigint' }), 10 - boolean: compiler.identifier({ text: 'boolean' }), 11 - check: compiler.identifier({ text: 'check' }), 12 - coerce: compiler.identifier({ text: 'coerce' }), 13 - date: compiler.identifier({ text: 'date' }), 14 - datetime: compiler.identifier({ text: 'datetime' }), 15 - default: compiler.identifier({ text: 'default' }), 16 - describe: compiler.identifier({ text: 'describe' }), 17 - email: compiler.identifier({ text: 'email' }), 18 - enum: compiler.identifier({ text: 'enum' }), 19 - globalRegistry: compiler.identifier({ text: 'globalRegistry' }), 20 - gt: compiler.identifier({ text: 'gt' }), 21 - gte: compiler.identifier({ text: 'gte' }), 22 - infer: compiler.identifier({ text: 'infer' }), 23 - int: compiler.identifier({ text: 'int' }), 24 - intersection: compiler.identifier({ text: 'intersection' }), 25 - ip: compiler.identifier({ text: 'ip' }), 26 - ipv4: compiler.identifier({ text: 'ipv4' }), 27 - ipv6: compiler.identifier({ text: 'ipv6' }), 28 - iso: compiler.identifier({ text: 'iso' }), 29 - lazy: compiler.identifier({ text: 'lazy' }), 30 - length: compiler.identifier({ text: 'length' }), 31 - literal: compiler.identifier({ text: 'literal' }), 32 - lt: compiler.identifier({ text: 'lt' }), 33 - lte: compiler.identifier({ text: 'lte' }), 34 - max: compiler.identifier({ text: 'max' }), 35 - maxLength: compiler.identifier({ text: 'maxLength' }), 36 - min: compiler.identifier({ text: 'min' }), 37 - minLength: compiler.identifier({ text: 'minLength' }), 38 - never: compiler.identifier({ text: 'never' }), 39 - null: compiler.identifier({ text: 'null' }), 40 - nullable: compiler.identifier({ text: 'nullable' }), 41 - number: compiler.identifier({ text: 'number' }), 42 - object: compiler.identifier({ text: 'object' }), 43 - optional: compiler.identifier({ text: 'optional' }), 44 - parseAsync: compiler.identifier({ text: 'parseAsync' }), 45 - readonly: compiler.identifier({ text: 'readonly' }), 46 - record: compiler.identifier({ text: 'record' }), 47 - regex: compiler.identifier({ text: 'regex' }), 48 - register: compiler.identifier({ text: 'register' }), 49 - string: compiler.identifier({ text: 'string' }), 50 - time: compiler.identifier({ text: 'time' }), 51 - tuple: compiler.identifier({ text: 'tuple' }), 52 - undefined: compiler.identifier({ text: 'undefined' }), 53 - union: compiler.identifier({ text: 'union' }), 54 - unknown: compiler.identifier({ text: 'unknown' }), 55 - url: compiler.identifier({ text: 'url' }), 56 - uuid: compiler.identifier({ text: 'uuid' }), 57 - void: compiler.identifier({ text: 'void' }), 58 - z: compiler.identifier({ text: 'z' }), 4 + ZodMiniOptional: tsc.identifier({ text: 'ZodMiniOptional' }), 5 + ZodOptional: tsc.identifier({ text: 'ZodOptional' }), 6 + _default: tsc.identifier({ text: '_default' }), 7 + and: tsc.identifier({ text: 'and' }), 8 + array: tsc.identifier({ text: 'array' }), 9 + bigint: tsc.identifier({ text: 'bigint' }), 10 + boolean: tsc.identifier({ text: 'boolean' }), 11 + check: tsc.identifier({ text: 'check' }), 12 + coerce: tsc.identifier({ text: 'coerce' }), 13 + date: tsc.identifier({ text: 'date' }), 14 + datetime: tsc.identifier({ text: 'datetime' }), 15 + default: tsc.identifier({ text: 'default' }), 16 + describe: tsc.identifier({ text: 'describe' }), 17 + email: tsc.identifier({ text: 'email' }), 18 + enum: tsc.identifier({ text: 'enum' }), 19 + globalRegistry: tsc.identifier({ text: 'globalRegistry' }), 20 + gt: tsc.identifier({ text: 'gt' }), 21 + gte: tsc.identifier({ text: 'gte' }), 22 + infer: tsc.identifier({ text: 'infer' }), 23 + int: tsc.identifier({ text: 'int' }), 24 + intersection: tsc.identifier({ text: 'intersection' }), 25 + ip: tsc.identifier({ text: 'ip' }), 26 + ipv4: tsc.identifier({ text: 'ipv4' }), 27 + ipv6: tsc.identifier({ text: 'ipv6' }), 28 + iso: tsc.identifier({ text: 'iso' }), 29 + lazy: tsc.identifier({ text: 'lazy' }), 30 + length: tsc.identifier({ text: 'length' }), 31 + literal: tsc.identifier({ text: 'literal' }), 32 + lt: tsc.identifier({ text: 'lt' }), 33 + lte: tsc.identifier({ text: 'lte' }), 34 + max: tsc.identifier({ text: 'max' }), 35 + maxLength: tsc.identifier({ text: 'maxLength' }), 36 + min: tsc.identifier({ text: 'min' }), 37 + minLength: tsc.identifier({ text: 'minLength' }), 38 + never: tsc.identifier({ text: 'never' }), 39 + null: tsc.identifier({ text: 'null' }), 40 + nullable: tsc.identifier({ text: 'nullable' }), 41 + number: tsc.identifier({ text: 'number' }), 42 + object: tsc.identifier({ text: 'object' }), 43 + optional: tsc.identifier({ text: 'optional' }), 44 + parseAsync: tsc.identifier({ text: 'parseAsync' }), 45 + readonly: tsc.identifier({ text: 'readonly' }), 46 + record: tsc.identifier({ text: 'record' }), 47 + regex: tsc.identifier({ text: 'regex' }), 48 + register: tsc.identifier({ text: 'register' }), 49 + string: tsc.identifier({ text: 'string' }), 50 + time: tsc.identifier({ text: 'time' }), 51 + tuple: tsc.identifier({ text: 'tuple' }), 52 + undefined: tsc.identifier({ text: 'undefined' }), 53 + union: tsc.identifier({ text: 'union' }), 54 + unknown: tsc.identifier({ text: 'unknown' }), 55 + url: tsc.identifier({ text: 'url' }), 56 + uuid: tsc.identifier({ text: 'uuid' }), 57 + void: tsc.identifier({ text: 'void' }), 58 + z: tsc.identifier({ text: 'z' }), 59 59 }; 60 60 61 61 export const zodId = 'zod';
+10 -10
packages/openapi-ts/src/plugins/zod/export.ts
··· 1 1 import type ts from 'typescript'; 2 2 3 - import { compiler } from '../../compiler'; 4 3 import type { IR } from '../../ir/types'; 4 + import { tsc } from '../../tsc'; 5 5 import { createSchemaComment } from '../shared/utils/schema'; 6 6 import { identifiers, zodId } from './constants'; 7 7 import type { ZodSchema } from './shared/types'; ··· 22 22 }) => { 23 23 const file = plugin.context.file({ id: zodId })!; 24 24 const node = file.addNodeReference(schemaId, { 25 - factory: (typeName) => compiler.typeReferenceNode({ typeName }), 25 + factory: (typeName) => tsc.typeReferenceNode({ typeName }), 26 26 }); 27 - const statement = compiler.constVariable({ 27 + const statement = tsc.constVariable({ 28 28 comment: plugin.config.comments 29 29 ? createSchemaComment({ schema }) 30 30 : undefined, ··· 32 32 expression: zodSchema.expression, 33 33 name: node, 34 34 typeName: zodSchema.typeName 35 - ? (compiler.propertyAccessExpression({ 35 + ? (tsc.propertyAccessExpression({ 36 36 expression: identifiers.z, 37 37 name: zodSchema.typeName, 38 38 }) as unknown as ts.TypeNode) ··· 42 42 43 43 if (typeInferId) { 44 44 const inferNode = file.addNodeReference(typeInferId, { 45 - factory: (typeName) => compiler.typeReferenceNode({ typeName }), 45 + factory: (typeName) => tsc.typeReferenceNode({ typeName }), 46 46 }); 47 47 const nodeIdentifier = file.addNodeReference(schemaId, { 48 - factory: (text) => compiler.identifier({ text }), 48 + factory: (text) => tsc.identifier({ text }), 49 49 }); 50 - const inferType = compiler.typeAliasDeclaration({ 50 + const inferType = tsc.typeAliasDeclaration({ 51 51 exportType: true, 52 52 name: inferNode, 53 - type: compiler.typeReferenceNode({ 53 + type: tsc.typeReferenceNode({ 54 54 typeArguments: [ 55 - compiler.typeOfExpression({ 55 + tsc.typeOfExpression({ 56 56 text: nodeIdentifier, 57 57 }) as unknown as ts.TypeNode, 58 58 ], 59 - typeName: compiler.propertyAccessExpression({ 59 + typeName: tsc.propertyAccessExpression({ 60 60 expression: identifiers.z, 61 61 name: identifiers.infer, 62 62 }) as unknown as string,
+147 -149
packages/openapi-ts/src/plugins/zod/mini/plugin.ts
··· 1 1 import ts from 'typescript'; 2 2 3 - import { compiler } from '../../../compiler'; 4 3 import { deduplicateSchema } from '../../../ir/schema'; 5 4 import type { IR } from '../../../ir/types'; 6 5 import { buildName } from '../../../openApi/shared/utils/name'; 6 + import { tsc } from '../../../tsc'; 7 7 import { refToName } from '../../../utils/ref'; 8 8 import { numberRegExp } from '../../../utils/regexp'; 9 9 import { identifiers, zodId } from '../constants'; ··· 24 24 }): Omit<ZodSchema, 'typeName'> => { 25 25 const result: Partial<Omit<ZodSchema, 'typeName'>> = {}; 26 26 27 - const functionName = compiler.propertyAccessExpression({ 27 + const functionName = tsc.propertyAccessExpression({ 28 28 expression: identifiers.z, 29 29 name: identifiers.array, 30 30 }); 31 31 32 32 if (!schema.items) { 33 - result.expression = compiler.callExpression({ 33 + result.expression = tsc.callExpression({ 34 34 functionName, 35 35 parameters: [ 36 36 unknownTypeToZodSchema({ ··· 57 57 }); 58 58 59 59 if (itemExpressions.length === 1) { 60 - result.expression = compiler.callExpression({ 60 + result.expression = tsc.callExpression({ 61 61 functionName, 62 62 parameters: itemExpressions, 63 63 }); 64 64 } else { 65 65 if (schema.logicalOperator === 'and') { 66 66 // TODO: parser - handle intersection 67 - // return compiler.typeArrayNode( 68 - // compiler.typeIntersectionNode({ types: itemExpressions }), 67 + // return tsc.typeArrayNode( 68 + // tsc.typeIntersectionNode({ types: itemExpressions }), 69 69 // ); 70 70 } 71 71 72 - result.expression = compiler.callExpression({ 73 - functionName: compiler.propertyAccessExpression({ 72 + result.expression = tsc.callExpression({ 73 + functionName: tsc.propertyAccessExpression({ 74 74 expression: identifiers.z, 75 75 name: identifiers.array, 76 76 }), 77 77 parameters: [ 78 - compiler.callExpression({ 79 - functionName: compiler.propertyAccessExpression({ 78 + tsc.callExpression({ 79 + functionName: tsc.propertyAccessExpression({ 80 80 expression: identifiers.z, 81 81 name: identifiers.union, 82 82 }), 83 83 parameters: [ 84 - compiler.arrayLiteralExpression({ 84 + tsc.arrayLiteralExpression({ 85 85 elements: itemExpressions, 86 86 }), 87 87 ], ··· 95 95 96 96 if (schema.minItems === schema.maxItems && schema.minItems !== undefined) { 97 97 checks.push( 98 - compiler.callExpression({ 99 - functionName: compiler.propertyAccessExpression({ 98 + tsc.callExpression({ 99 + functionName: tsc.propertyAccessExpression({ 100 100 expression: identifiers.z, 101 101 name: identifiers.length, 102 102 }), 103 - parameters: [compiler.valueToExpression({ value: schema.minItems })], 103 + parameters: [tsc.valueToExpression({ value: schema.minItems })], 104 104 }), 105 105 ); 106 106 } else { 107 107 if (schema.minItems !== undefined) { 108 108 checks.push( 109 - compiler.callExpression({ 110 - functionName: compiler.propertyAccessExpression({ 109 + tsc.callExpression({ 110 + functionName: tsc.propertyAccessExpression({ 111 111 expression: identifiers.z, 112 112 name: identifiers.minLength, 113 113 }), 114 - parameters: [compiler.valueToExpression({ value: schema.minItems })], 114 + parameters: [tsc.valueToExpression({ value: schema.minItems })], 115 115 }), 116 116 ); 117 117 } 118 118 119 119 if (schema.maxItems !== undefined) { 120 120 checks.push( 121 - compiler.callExpression({ 122 - functionName: compiler.propertyAccessExpression({ 121 + tsc.callExpression({ 122 + functionName: tsc.propertyAccessExpression({ 123 123 expression: identifiers.z, 124 124 name: identifiers.maxLength, 125 125 }), 126 - parameters: [compiler.valueToExpression({ value: schema.maxItems })], 126 + parameters: [tsc.valueToExpression({ value: schema.maxItems })], 127 127 }), 128 128 ); 129 129 } 130 130 } 131 131 132 132 if (checks.length) { 133 - result.expression = compiler.callExpression({ 134 - functionName: compiler.propertyAccessExpression({ 133 + result.expression = tsc.callExpression({ 134 + functionName: tsc.propertyAccessExpression({ 135 135 expression: result.expression, 136 136 name: identifiers.check, 137 137 }), ··· 150 150 const result: Partial<Omit<ZodSchema, 'typeName'>> = {}; 151 151 152 152 if (typeof schema.const === 'boolean') { 153 - result.expression = compiler.callExpression({ 154 - functionName: compiler.propertyAccessExpression({ 153 + result.expression = tsc.callExpression({ 154 + functionName: tsc.propertyAccessExpression({ 155 155 expression: identifiers.z, 156 156 name: identifiers.literal, 157 157 }), 158 - parameters: [compiler.ots.boolean(schema.const)], 158 + parameters: [tsc.ots.boolean(schema.const)], 159 159 }); 160 160 return result as Omit<ZodSchema, 'typeName'>; 161 161 } 162 162 163 - result.expression = compiler.callExpression({ 164 - functionName: compiler.propertyAccessExpression({ 163 + result.expression = tsc.callExpression({ 164 + functionName: tsc.propertyAccessExpression({ 165 165 expression: identifiers.z, 166 166 name: identifiers.boolean, 167 167 }), ··· 184 184 // Zod supports only string enums 185 185 if (item.type === 'string' && typeof item.const === 'string') { 186 186 enumMembers.push( 187 - compiler.stringLiteral({ 187 + tsc.stringLiteral({ 188 188 text: item.const, 189 189 }), 190 190 ); ··· 201 201 }); 202 202 } 203 203 204 - result.expression = compiler.callExpression({ 205 - functionName: compiler.propertyAccessExpression({ 204 + result.expression = tsc.callExpression({ 205 + functionName: tsc.propertyAccessExpression({ 206 206 expression: identifiers.z, 207 207 name: identifiers.enum, 208 208 }), 209 209 parameters: [ 210 - compiler.arrayLiteralExpression({ 210 + tsc.arrayLiteralExpression({ 211 211 elements: enumMembers, 212 212 multiLine: false, 213 213 }), ··· 215 215 }); 216 216 217 217 if (isNullable) { 218 - result.expression = compiler.callExpression({ 219 - functionName: compiler.propertyAccessExpression({ 218 + result.expression = tsc.callExpression({ 219 + functionName: tsc.propertyAccessExpression({ 220 220 expression: identifiers.z, 221 221 name: identifiers.nullable, 222 222 }), ··· 232 232 schema: SchemaWithType<'never'>; 233 233 }): Omit<ZodSchema, 'typeName'> => { 234 234 const result: Partial<Omit<ZodSchema, 'typeName'>> = {}; 235 - result.expression = compiler.callExpression({ 236 - functionName: compiler.propertyAccessExpression({ 235 + result.expression = tsc.callExpression({ 236 + functionName: tsc.propertyAccessExpression({ 237 237 expression: identifiers.z, 238 238 name: identifiers.never, 239 239 }), ··· 246 246 schema: SchemaWithType<'null'>; 247 247 }): Omit<ZodSchema, 'typeName'> => { 248 248 const result: Partial<Omit<ZodSchema, 'typeName'>> = {}; 249 - result.expression = compiler.callExpression({ 250 - functionName: compiler.propertyAccessExpression({ 249 + result.expression = tsc.callExpression({ 250 + functionName: tsc.propertyAccessExpression({ 251 251 expression: identifiers.z, 252 252 name: identifiers.null, 253 253 }), ··· 262 262 isBigInt: boolean; 263 263 value: unknown; 264 264 }): ts.Expression | undefined => { 265 - const expression = compiler.valueToExpression({ value }); 265 + const expression = tsc.valueToExpression({ value }); 266 266 267 267 if ( 268 268 isBigInt && ··· 271 271 typeof value === 'string' || 272 272 typeof value === 'boolean') 273 273 ) { 274 - return compiler.callExpression({ 274 + return tsc.callExpression({ 275 275 functionName: 'BigInt', 276 276 parameters: [expression], 277 277 }); ··· 291 291 292 292 if (typeof schema.const === 'number') { 293 293 // TODO: parser - handle bigint constants 294 - result.expression = compiler.callExpression({ 295 - functionName: compiler.propertyAccessExpression({ 294 + result.expression = tsc.callExpression({ 295 + functionName: tsc.propertyAccessExpression({ 296 296 expression: identifiers.z, 297 297 name: identifiers.literal, 298 298 }), 299 - parameters: [compiler.ots.number(schema.const)], 299 + parameters: [tsc.ots.number(schema.const)], 300 300 }); 301 301 return result as Omit<ZodSchema, 'typeName'>; 302 302 } 303 303 304 - result.expression = compiler.callExpression({ 304 + result.expression = tsc.callExpression({ 305 305 functionName: isBigInt 306 - ? compiler.propertyAccessExpression({ 307 - expression: compiler.propertyAccessExpression({ 306 + ? tsc.propertyAccessExpression({ 307 + expression: tsc.propertyAccessExpression({ 308 308 expression: identifiers.z, 309 309 name: identifiers.coerce, 310 310 }), 311 311 name: identifiers.bigint, 312 312 }) 313 - : compiler.propertyAccessExpression({ 313 + : tsc.propertyAccessExpression({ 314 314 expression: identifiers.z, 315 315 name: identifiers.number, 316 316 }), 317 317 }); 318 318 319 319 if (!isBigInt && schema.type === 'integer') { 320 - result.expression = compiler.callExpression({ 321 - functionName: compiler.propertyAccessExpression({ 320 + result.expression = tsc.callExpression({ 321 + functionName: tsc.propertyAccessExpression({ 322 322 expression: identifiers.z, 323 323 name: identifiers.int, 324 324 }), ··· 329 329 330 330 if (schema.exclusiveMinimum !== undefined) { 331 331 checks.push( 332 - compiler.callExpression({ 333 - functionName: compiler.propertyAccessExpression({ 332 + tsc.callExpression({ 333 + functionName: tsc.propertyAccessExpression({ 334 334 expression: identifiers.z, 335 335 name: identifiers.gt, 336 336 }), ··· 341 341 ); 342 342 } else if (schema.minimum !== undefined) { 343 343 checks.push( 344 - compiler.callExpression({ 345 - functionName: compiler.propertyAccessExpression({ 344 + tsc.callExpression({ 345 + functionName: tsc.propertyAccessExpression({ 346 346 expression: identifiers.z, 347 347 name: identifiers.gte, 348 348 }), ··· 353 353 354 354 if (schema.exclusiveMaximum !== undefined) { 355 355 checks.push( 356 - compiler.callExpression({ 357 - functionName: compiler.propertyAccessExpression({ 356 + tsc.callExpression({ 357 + functionName: tsc.propertyAccessExpression({ 358 358 expression: identifiers.z, 359 359 name: identifiers.lt, 360 360 }), ··· 365 365 ); 366 366 } else if (schema.maximum !== undefined) { 367 367 checks.push( 368 - compiler.callExpression({ 369 - functionName: compiler.propertyAccessExpression({ 368 + tsc.callExpression({ 369 + functionName: tsc.propertyAccessExpression({ 370 370 expression: identifiers.z, 371 371 name: identifiers.lte, 372 372 }), ··· 376 376 } 377 377 378 378 if (checks.length) { 379 - result.expression = compiler.callExpression({ 380 - functionName: compiler.propertyAccessExpression({ 379 + result.expression = tsc.callExpression({ 380 + functionName: tsc.propertyAccessExpression({ 381 381 expression: result.expression, 382 382 name: identifiers.check, 383 383 }), ··· 441 441 442 442 if (propertySchema.hasCircularReference) { 443 443 properties.push( 444 - compiler.getAccessorDeclaration({ 444 + tsc.getAccessorDeclaration({ 445 445 name: propertyName, 446 446 // @ts-expect-error 447 447 returnType: propertySchema.typeName 448 - ? compiler.propertyAccessExpression({ 448 + ? tsc.propertyAccessExpression({ 449 449 expression: identifiers.z, 450 450 name: propertySchema.typeName, 451 451 }) 452 452 : undefined, 453 453 statements: [ 454 - compiler.returnStatement({ 454 + tsc.returnStatement({ 455 455 expression: propertySchema.expression, 456 456 }), 457 457 ], ··· 459 459 ); 460 460 } else { 461 461 properties.push( 462 - compiler.propertyAssignment({ 462 + tsc.propertyAssignment({ 463 463 initializer: propertySchema.expression, 464 464 name: propertyName, 465 465 }), ··· 477 477 schema: schema.additionalProperties, 478 478 state, 479 479 }); 480 - result.expression = compiler.callExpression({ 481 - functionName: compiler.propertyAccessExpression({ 480 + result.expression = tsc.callExpression({ 481 + functionName: tsc.propertyAccessExpression({ 482 482 expression: identifiers.z, 483 483 name: identifiers.record, 484 484 }), 485 485 parameters: [ 486 - compiler.callExpression({ 487 - functionName: compiler.propertyAccessExpression({ 486 + tsc.callExpression({ 487 + functionName: tsc.propertyAccessExpression({ 488 488 expression: identifiers.z, 489 489 name: identifiers.string, 490 490 }), ··· 499 499 return result as Omit<ZodSchema, 'typeName'>; 500 500 } 501 501 502 - result.expression = compiler.callExpression({ 503 - functionName: compiler.propertyAccessExpression({ 502 + result.expression = tsc.callExpression({ 503 + functionName: tsc.propertyAccessExpression({ 504 504 expression: identifiers.z, 505 505 name: identifiers.object, 506 506 }), ··· 520 520 const result: Partial<Omit<ZodSchema, 'typeName'>> = {}; 521 521 522 522 if (typeof schema.const === 'string') { 523 - result.expression = compiler.callExpression({ 524 - functionName: compiler.propertyAccessExpression({ 523 + result.expression = tsc.callExpression({ 524 + functionName: tsc.propertyAccessExpression({ 525 525 expression: identifiers.z, 526 526 name: identifiers.literal, 527 527 }), 528 - parameters: [compiler.ots.string(schema.const)], 528 + parameters: [tsc.ots.string(schema.const)], 529 529 }); 530 530 return result as Omit<ZodSchema, 'typeName'>; 531 531 } 532 532 533 - result.expression = compiler.callExpression({ 534 - functionName: compiler.propertyAccessExpression({ 533 + result.expression = tsc.callExpression({ 534 + functionName: tsc.propertyAccessExpression({ 535 535 expression: identifiers.z, 536 536 name: identifiers.string, 537 537 }), ··· 540 540 if (schema.format) { 541 541 switch (schema.format) { 542 542 case 'date': 543 - result.expression = compiler.callExpression({ 544 - functionName: compiler.propertyAccessExpression({ 545 - expression: compiler.propertyAccessExpression({ 543 + result.expression = tsc.callExpression({ 544 + functionName: tsc.propertyAccessExpression({ 545 + expression: tsc.propertyAccessExpression({ 546 546 expression: identifiers.z, 547 547 name: identifiers.iso, 548 548 }), ··· 551 551 }); 552 552 break; 553 553 case 'date-time': 554 - result.expression = compiler.callExpression({ 555 - functionName: compiler.propertyAccessExpression({ 556 - expression: compiler.propertyAccessExpression({ 554 + result.expression = tsc.callExpression({ 555 + functionName: tsc.propertyAccessExpression({ 556 + expression: tsc.propertyAccessExpression({ 557 557 expression: identifiers.z, 558 558 name: identifiers.iso, 559 559 }), ··· 561 561 }), 562 562 parameters: plugin.config.dates.offset 563 563 ? [ 564 - compiler.objectExpression({ 564 + tsc.objectExpression({ 565 565 obj: [ 566 566 { 567 567 key: 'offset', ··· 574 574 }); 575 575 break; 576 576 case 'email': 577 - result.expression = compiler.callExpression({ 578 - functionName: compiler.propertyAccessExpression({ 577 + result.expression = tsc.callExpression({ 578 + functionName: tsc.propertyAccessExpression({ 579 579 expression: identifiers.z, 580 580 name: identifiers.email, 581 581 }), 582 582 }); 583 583 break; 584 584 case 'ipv4': 585 - result.expression = compiler.callExpression({ 586 - functionName: compiler.propertyAccessExpression({ 585 + result.expression = tsc.callExpression({ 586 + functionName: tsc.propertyAccessExpression({ 587 587 expression: identifiers.z, 588 588 name: identifiers.ipv4, 589 589 }), 590 590 }); 591 591 break; 592 592 case 'ipv6': 593 - result.expression = compiler.callExpression({ 594 - functionName: compiler.propertyAccessExpression({ 593 + result.expression = tsc.callExpression({ 594 + functionName: tsc.propertyAccessExpression({ 595 595 expression: identifiers.z, 596 596 name: identifiers.ipv6, 597 597 }), 598 598 }); 599 599 break; 600 600 case 'time': 601 - result.expression = compiler.callExpression({ 602 - functionName: compiler.propertyAccessExpression({ 603 - expression: compiler.propertyAccessExpression({ 601 + result.expression = tsc.callExpression({ 602 + functionName: tsc.propertyAccessExpression({ 603 + expression: tsc.propertyAccessExpression({ 604 604 expression: identifiers.z, 605 605 name: identifiers.iso, 606 606 }), ··· 609 609 }); 610 610 break; 611 611 case 'uri': 612 - result.expression = compiler.callExpression({ 613 - functionName: compiler.propertyAccessExpression({ 612 + result.expression = tsc.callExpression({ 613 + functionName: tsc.propertyAccessExpression({ 614 614 expression: identifiers.z, 615 615 name: identifiers.url, 616 616 }), 617 617 }); 618 618 break; 619 619 case 'uuid': 620 - result.expression = compiler.callExpression({ 621 - functionName: compiler.propertyAccessExpression({ 620 + result.expression = tsc.callExpression({ 621 + functionName: tsc.propertyAccessExpression({ 622 622 expression: identifiers.z, 623 623 name: identifiers.uuid, 624 624 }), ··· 631 631 632 632 if (schema.minLength === schema.maxLength && schema.minLength !== undefined) { 633 633 checks.push( 634 - compiler.callExpression({ 635 - functionName: compiler.propertyAccessExpression({ 634 + tsc.callExpression({ 635 + functionName: tsc.propertyAccessExpression({ 636 636 expression: identifiers.z, 637 637 name: identifiers.length, 638 638 }), 639 - parameters: [compiler.valueToExpression({ value: schema.minLength })], 639 + parameters: [tsc.valueToExpression({ value: schema.minLength })], 640 640 }), 641 641 ); 642 642 } else { 643 643 if (schema.minLength !== undefined) { 644 644 checks.push( 645 - compiler.callExpression({ 646 - functionName: compiler.propertyAccessExpression({ 645 + tsc.callExpression({ 646 + functionName: tsc.propertyAccessExpression({ 647 647 expression: identifiers.z, 648 648 name: identifiers.minLength, 649 649 }), 650 - parameters: [compiler.valueToExpression({ value: schema.minLength })], 650 + parameters: [tsc.valueToExpression({ value: schema.minLength })], 651 651 }), 652 652 ); 653 653 } 654 654 655 655 if (schema.maxLength !== undefined) { 656 656 checks.push( 657 - compiler.callExpression({ 658 - functionName: compiler.propertyAccessExpression({ 657 + tsc.callExpression({ 658 + functionName: tsc.propertyAccessExpression({ 659 659 expression: identifiers.z, 660 660 name: identifiers.maxLength, 661 661 }), 662 - parameters: [compiler.valueToExpression({ value: schema.maxLength })], 662 + parameters: [tsc.valueToExpression({ value: schema.maxLength })], 663 663 }), 664 664 ); 665 665 } ··· 667 667 668 668 if (schema.pattern) { 669 669 checks.push( 670 - compiler.callExpression({ 671 - functionName: compiler.propertyAccessExpression({ 670 + tsc.callExpression({ 671 + functionName: tsc.propertyAccessExpression({ 672 672 expression: identifiers.z, 673 673 name: identifiers.regex, 674 674 }), 675 - parameters: [ 676 - compiler.regularExpressionLiteral({ text: schema.pattern }), 677 - ], 675 + parameters: [tsc.regularExpressionLiteral({ text: schema.pattern })], 678 676 }), 679 677 ); 680 678 } 681 679 682 680 if (checks.length) { 683 - result.expression = compiler.callExpression({ 684 - functionName: compiler.propertyAccessExpression({ 681 + result.expression = tsc.callExpression({ 682 + functionName: tsc.propertyAccessExpression({ 685 683 expression: result.expression, 686 684 name: identifiers.check, 687 685 }), ··· 705 703 706 704 if (schema.const && Array.isArray(schema.const)) { 707 705 const tupleElements = schema.const.map((value) => 708 - compiler.callExpression({ 709 - functionName: compiler.propertyAccessExpression({ 706 + tsc.callExpression({ 707 + functionName: tsc.propertyAccessExpression({ 710 708 expression: identifiers.z, 711 709 name: identifiers.literal, 712 710 }), 713 - parameters: [compiler.valueToExpression({ value })], 711 + parameters: [tsc.valueToExpression({ value })], 714 712 }), 715 713 ); 716 - result.expression = compiler.callExpression({ 717 - functionName: compiler.propertyAccessExpression({ 714 + result.expression = tsc.callExpression({ 715 + functionName: tsc.propertyAccessExpression({ 718 716 expression: identifiers.z, 719 717 name: identifiers.tuple, 720 718 }), 721 719 parameters: [ 722 - compiler.arrayLiteralExpression({ 720 + tsc.arrayLiteralExpression({ 723 721 elements: tupleElements, 724 722 }), 725 723 ], ··· 742 740 } 743 741 } 744 742 745 - result.expression = compiler.callExpression({ 746 - functionName: compiler.propertyAccessExpression({ 743 + result.expression = tsc.callExpression({ 744 + functionName: tsc.propertyAccessExpression({ 747 745 expression: identifiers.z, 748 746 name: identifiers.tuple, 749 747 }), 750 748 parameters: [ 751 - compiler.arrayLiteralExpression({ 749 + tsc.arrayLiteralExpression({ 752 750 elements: tupleElements, 753 751 }), 754 752 ], ··· 762 760 schema: SchemaWithType<'undefined'>; 763 761 }): Omit<ZodSchema, 'typeName'> => { 764 762 const result: Partial<Omit<ZodSchema, 'typeName'>> = {}; 765 - result.expression = compiler.callExpression({ 766 - functionName: compiler.propertyAccessExpression({ 763 + result.expression = tsc.callExpression({ 764 + functionName: tsc.propertyAccessExpression({ 767 765 expression: identifiers.z, 768 766 name: identifiers.undefined, 769 767 }), ··· 776 774 schema: SchemaWithType<'unknown'>; 777 775 }): Omit<ZodSchema, 'typeName'> => { 778 776 const result: Partial<Omit<ZodSchema, 'typeName'>> = {}; 779 - result.expression = compiler.callExpression({ 780 - functionName: compiler.propertyAccessExpression({ 777 + result.expression = tsc.callExpression({ 778 + functionName: tsc.propertyAccessExpression({ 781 779 expression: identifiers.z, 782 780 name: identifiers.unknown, 783 781 }), ··· 790 788 schema: SchemaWithType<'void'>; 791 789 }): Omit<ZodSchema, 'typeName'> => { 792 790 const result: Partial<Omit<ZodSchema, 'typeName'>> = {}; 793 - result.expression = compiler.callExpression({ 794 - functionName: compiler.propertyAccessExpression({ 791 + result.expression = tsc.callExpression({ 792 + functionName: tsc.propertyAccessExpression({ 795 793 expression: identifiers.z, 796 794 name: identifiers.void, 797 795 }), ··· 900 898 901 899 if (isCircularReference) { 902 900 const expression = file.addNodeReference(id, { 903 - factory: (text) => compiler.identifier({ text }), 901 + factory: (text) => tsc.identifier({ text }), 904 902 }); 905 903 if (isSelfReference) { 906 - zodSchema.expression = compiler.callExpression({ 907 - functionName: compiler.propertyAccessExpression({ 904 + zodSchema.expression = tsc.callExpression({ 905 + functionName: tsc.propertyAccessExpression({ 908 906 expression: identifiers.z, 909 907 name: identifiers.lazy, 910 908 }), 911 909 parameters: [ 912 - compiler.arrowFunction({ 913 - returnType: compiler.keywordTypeNode({ keyword: 'any' }), 914 - statements: [compiler.returnStatement({ expression })], 910 + tsc.arrowFunction({ 911 + returnType: tsc.keywordTypeNode({ keyword: 'any' }), 912 + statements: [tsc.returnStatement({ expression })], 915 913 }), 916 914 ], 917 915 }); ··· 934 932 935 933 if (!isCircularReference) { 936 934 const expression = file.addNodeReference(id, { 937 - factory: (text) => compiler.identifier({ text }), 935 + factory: (text) => tsc.identifier({ text }), 938 936 }); 939 937 zodSchema.expression = expression; 940 938 } ··· 947 945 zodSchema.hasCircularReference = zSchema.hasCircularReference; 948 946 949 947 if (plugin.config.metadata && schema.description) { 950 - zodSchema.expression = compiler.callExpression({ 951 - functionName: compiler.propertyAccessExpression({ 948 + zodSchema.expression = tsc.callExpression({ 949 + functionName: tsc.propertyAccessExpression({ 952 950 expression: zodSchema.expression, 953 951 name: identifiers.register, 954 952 }), 955 953 parameters: [ 956 - compiler.propertyAccessExpression({ 954 + tsc.propertyAccessExpression({ 957 955 expression: identifiers.z, 958 956 name: identifiers.globalRegistry, 959 957 }), 960 - compiler.objectExpression({ 958 + tsc.objectExpression({ 961 959 obj: [ 962 960 { 963 961 key: 'description', 964 - value: compiler.stringLiteral({ text: schema.description }), 962 + value: tsc.stringLiteral({ text: schema.description }), 965 963 }, 966 964 ], 967 965 }), ··· 990 988 firstSchema.logicalOperator === 'or' || 991 989 (firstSchema.type && firstSchema.type !== 'object') 992 990 ) { 993 - zodSchema.expression = compiler.callExpression({ 994 - functionName: compiler.propertyAccessExpression({ 991 + zodSchema.expression = tsc.callExpression({ 992 + functionName: tsc.propertyAccessExpression({ 995 993 expression: identifiers.z, 996 994 name: identifiers.intersection, 997 995 }), ··· 1000 998 } else { 1001 999 zodSchema.expression = itemTypes[0]; 1002 1000 itemTypes.slice(1).forEach((item) => { 1003 - zodSchema.expression = compiler.callExpression({ 1004 - functionName: compiler.propertyAccessExpression({ 1001 + zodSchema.expression = tsc.callExpression({ 1002 + functionName: tsc.propertyAccessExpression({ 1005 1003 expression: identifiers.z, 1006 1004 name: identifiers.intersection, 1007 1005 }), ··· 1010 1008 }); 1011 1009 } 1012 1010 } else { 1013 - zodSchema.expression = compiler.callExpression({ 1014 - functionName: compiler.propertyAccessExpression({ 1011 + zodSchema.expression = tsc.callExpression({ 1012 + functionName: tsc.propertyAccessExpression({ 1015 1013 expression: identifiers.z, 1016 1014 name: identifiers.union, 1017 1015 }), 1018 1016 parameters: [ 1019 - compiler.arrayLiteralExpression({ 1017 + tsc.arrayLiteralExpression({ 1020 1018 elements: itemTypes, 1021 1019 }), 1022 1020 ], ··· 1039 1037 1040 1038 if (zodSchema.expression) { 1041 1039 if (schema.accessScope === 'read') { 1042 - zodSchema.expression = compiler.callExpression({ 1043 - functionName: compiler.propertyAccessExpression({ 1040 + zodSchema.expression = tsc.callExpression({ 1041 + functionName: tsc.propertyAccessExpression({ 1044 1042 expression: identifiers.z, 1045 1043 name: identifiers.readonly, 1046 1044 }), ··· 1049 1047 } 1050 1048 1051 1049 if (optional) { 1052 - zodSchema.expression = compiler.callExpression({ 1053 - functionName: compiler.propertyAccessExpression({ 1050 + zodSchema.expression = tsc.callExpression({ 1051 + functionName: tsc.propertyAccessExpression({ 1054 1052 expression: identifiers.z, 1055 1053 name: identifiers.optional, 1056 1054 }), ··· 1066 1064 value: schema.default, 1067 1065 }); 1068 1066 if (callParameter) { 1069 - zodSchema.expression = compiler.callExpression({ 1070 - functionName: compiler.propertyAccessExpression({ 1067 + zodSchema.expression = tsc.callExpression({ 1068 + functionName: tsc.propertyAccessExpression({ 1071 1069 expression: identifiers.z, 1072 1070 name: identifiers._default, 1073 1071 }),
+128 -128
packages/openapi-ts/src/plugins/zod/v3/plugin.ts
··· 1 1 import ts from 'typescript'; 2 2 3 - import { compiler } from '../../../compiler'; 4 3 import { deduplicateSchema } from '../../../ir/schema'; 5 4 import type { IR } from '../../../ir/types'; 6 5 import { buildName } from '../../../openApi/shared/utils/name'; 6 + import { tsc } from '../../../tsc'; 7 7 import { refToName } from '../../../utils/ref'; 8 8 import { numberRegExp } from '../../../utils/regexp'; 9 9 import { identifiers, zodId } from '../constants'; ··· 22 22 schema: SchemaWithType<'array'>; 23 23 state: State; 24 24 }): ts.CallExpression => { 25 - const functionName = compiler.propertyAccessExpression({ 25 + const functionName = tsc.propertyAccessExpression({ 26 26 expression: identifiers.z, 27 27 name: identifiers.array, 28 28 }); ··· 30 30 let arrayExpression: ts.CallExpression | undefined; 31 31 32 32 if (!schema.items) { 33 - arrayExpression = compiler.callExpression({ 33 + arrayExpression = tsc.callExpression({ 34 34 functionName, 35 35 parameters: [ 36 36 unknownTypeToZodSchema({ ··· 54 54 ); 55 55 56 56 if (itemExpressions.length === 1) { 57 - arrayExpression = compiler.callExpression({ 57 + arrayExpression = tsc.callExpression({ 58 58 functionName, 59 59 parameters: itemExpressions, 60 60 }); 61 61 } else { 62 62 if (schema.logicalOperator === 'and') { 63 63 // TODO: parser - handle intersection 64 - // return compiler.typeArrayNode( 65 - // compiler.typeIntersectionNode({ types: itemExpressions }), 64 + // return tsc.typeArrayNode( 65 + // tsc.typeIntersectionNode({ types: itemExpressions }), 66 66 // ); 67 67 } 68 68 69 - arrayExpression = compiler.callExpression({ 70 - functionName: compiler.propertyAccessExpression({ 69 + arrayExpression = tsc.callExpression({ 70 + functionName: tsc.propertyAccessExpression({ 71 71 expression: identifiers.z, 72 72 name: identifiers.array, 73 73 }), 74 74 parameters: [ 75 - compiler.callExpression({ 76 - functionName: compiler.propertyAccessExpression({ 75 + tsc.callExpression({ 76 + functionName: tsc.propertyAccessExpression({ 77 77 expression: identifiers.z, 78 78 name: identifiers.union, 79 79 }), 80 80 parameters: [ 81 - compiler.arrayLiteralExpression({ 81 + tsc.arrayLiteralExpression({ 82 82 elements: itemExpressions, 83 83 }), 84 84 ], ··· 89 89 } 90 90 91 91 if (schema.minItems === schema.maxItems && schema.minItems !== undefined) { 92 - arrayExpression = compiler.callExpression({ 93 - functionName: compiler.propertyAccessExpression({ 92 + arrayExpression = tsc.callExpression({ 93 + functionName: tsc.propertyAccessExpression({ 94 94 expression: arrayExpression, 95 95 name: identifiers.length, 96 96 }), 97 - parameters: [compiler.valueToExpression({ value: schema.minItems })], 97 + parameters: [tsc.valueToExpression({ value: schema.minItems })], 98 98 }); 99 99 } else { 100 100 if (schema.minItems !== undefined) { 101 - arrayExpression = compiler.callExpression({ 102 - functionName: compiler.propertyAccessExpression({ 101 + arrayExpression = tsc.callExpression({ 102 + functionName: tsc.propertyAccessExpression({ 103 103 expression: arrayExpression, 104 104 name: identifiers.min, 105 105 }), 106 - parameters: [compiler.valueToExpression({ value: schema.minItems })], 106 + parameters: [tsc.valueToExpression({ value: schema.minItems })], 107 107 }); 108 108 } 109 109 110 110 if (schema.maxItems !== undefined) { 111 - arrayExpression = compiler.callExpression({ 112 - functionName: compiler.propertyAccessExpression({ 111 + arrayExpression = tsc.callExpression({ 112 + functionName: tsc.propertyAccessExpression({ 113 113 expression: arrayExpression, 114 114 name: identifiers.max, 115 115 }), 116 - parameters: [compiler.valueToExpression({ value: schema.maxItems })], 116 + parameters: [tsc.valueToExpression({ value: schema.maxItems })], 117 117 }); 118 118 } 119 119 } ··· 127 127 schema: SchemaWithType<'boolean'>; 128 128 }) => { 129 129 if (typeof schema.const === 'boolean') { 130 - const expression = compiler.callExpression({ 131 - functionName: compiler.propertyAccessExpression({ 130 + const expression = tsc.callExpression({ 131 + functionName: tsc.propertyAccessExpression({ 132 132 expression: identifiers.z, 133 133 name: identifiers.literal, 134 134 }), 135 - parameters: [compiler.ots.boolean(schema.const)], 135 + parameters: [tsc.ots.boolean(schema.const)], 136 136 }); 137 137 return expression; 138 138 } 139 139 140 - const expression = compiler.callExpression({ 141 - functionName: compiler.propertyAccessExpression({ 140 + const expression = tsc.callExpression({ 141 + functionName: tsc.propertyAccessExpression({ 142 142 expression: identifiers.z, 143 143 name: identifiers.boolean, 144 144 }), ··· 159 159 // Zod supports only string enums 160 160 if (item.type === 'string' && typeof item.const === 'string') { 161 161 enumMembers.push( 162 - compiler.stringLiteral({ 162 + tsc.stringLiteral({ 163 163 text: item.const, 164 164 }), 165 165 ); ··· 176 176 }); 177 177 } 178 178 179 - let enumExpression = compiler.callExpression({ 180 - functionName: compiler.propertyAccessExpression({ 179 + let enumExpression = tsc.callExpression({ 180 + functionName: tsc.propertyAccessExpression({ 181 181 expression: identifiers.z, 182 182 name: identifiers.enum, 183 183 }), 184 184 parameters: [ 185 - compiler.arrayLiteralExpression({ 185 + tsc.arrayLiteralExpression({ 186 186 elements: enumMembers, 187 187 multiLine: false, 188 188 }), ··· 190 190 }); 191 191 192 192 if (isNullable) { 193 - enumExpression = compiler.callExpression({ 194 - functionName: compiler.propertyAccessExpression({ 193 + enumExpression = tsc.callExpression({ 194 + functionName: tsc.propertyAccessExpression({ 195 195 expression: enumExpression, 196 196 name: identifiers.nullable, 197 197 }), ··· 203 203 204 204 // eslint-disable-next-line @typescript-eslint/no-unused-vars 205 205 const neverTypeToZodSchema = (_props: { schema: SchemaWithType<'never'> }) => { 206 - const expression = compiler.callExpression({ 207 - functionName: compiler.propertyAccessExpression({ 206 + const expression = tsc.callExpression({ 207 + functionName: tsc.propertyAccessExpression({ 208 208 expression: identifiers.z, 209 209 name: identifiers.never, 210 210 }), ··· 214 214 215 215 // eslint-disable-next-line @typescript-eslint/no-unused-vars 216 216 const nullTypeToZodSchema = (_props: { schema: SchemaWithType<'null'> }) => { 217 - const expression = compiler.callExpression({ 218 - functionName: compiler.propertyAccessExpression({ 217 + const expression = tsc.callExpression({ 218 + functionName: tsc.propertyAccessExpression({ 219 219 expression: identifiers.z, 220 220 name: identifiers.null, 221 221 }), ··· 230 230 isBigInt: boolean; 231 231 value: unknown; 232 232 }) => { 233 - const expression = compiler.valueToExpression({ value }); 233 + const expression = tsc.valueToExpression({ value }); 234 234 235 235 if ( 236 236 isBigInt && ··· 239 239 typeof value === 'string' || 240 240 typeof value === 'boolean') 241 241 ) { 242 - return compiler.callExpression({ 242 + return tsc.callExpression({ 243 243 functionName: 'BigInt', 244 244 parameters: [expression], 245 245 }); ··· 257 257 258 258 if (typeof schema.const === 'number') { 259 259 // TODO: parser - handle bigint constants 260 - const expression = compiler.callExpression({ 261 - functionName: compiler.propertyAccessExpression({ 260 + const expression = tsc.callExpression({ 261 + functionName: tsc.propertyAccessExpression({ 262 262 expression: identifiers.z, 263 263 name: identifiers.literal, 264 264 }), 265 - parameters: [compiler.ots.number(schema.const)], 265 + parameters: [tsc.ots.number(schema.const)], 266 266 }); 267 267 return expression; 268 268 } 269 269 270 - let numberExpression = compiler.callExpression({ 270 + let numberExpression = tsc.callExpression({ 271 271 functionName: isBigInt 272 - ? compiler.propertyAccessExpression({ 273 - expression: compiler.propertyAccessExpression({ 272 + ? tsc.propertyAccessExpression({ 273 + expression: tsc.propertyAccessExpression({ 274 274 expression: identifiers.z, 275 275 name: identifiers.coerce, 276 276 }), 277 277 name: identifiers.bigint, 278 278 }) 279 - : compiler.propertyAccessExpression({ 279 + : tsc.propertyAccessExpression({ 280 280 expression: identifiers.z, 281 281 name: identifiers.number, 282 282 }), 283 283 }); 284 284 285 285 if (!isBigInt && schema.type === 'integer') { 286 - numberExpression = compiler.callExpression({ 287 - functionName: compiler.propertyAccessExpression({ 286 + numberExpression = tsc.callExpression({ 287 + functionName: tsc.propertyAccessExpression({ 288 288 expression: numberExpression, 289 289 name: identifiers.int, 290 290 }), ··· 292 292 } 293 293 294 294 if (schema.exclusiveMinimum !== undefined) { 295 - numberExpression = compiler.callExpression({ 296 - functionName: compiler.propertyAccessExpression({ 295 + numberExpression = tsc.callExpression({ 296 + functionName: tsc.propertyAccessExpression({ 297 297 expression: numberExpression, 298 298 name: identifiers.gt, 299 299 }), ··· 302 302 ], 303 303 }); 304 304 } else if (schema.minimum !== undefined) { 305 - numberExpression = compiler.callExpression({ 306 - functionName: compiler.propertyAccessExpression({ 305 + numberExpression = tsc.callExpression({ 306 + functionName: tsc.propertyAccessExpression({ 307 307 expression: numberExpression, 308 308 name: identifiers.gte, 309 309 }), ··· 312 312 } 313 313 314 314 if (schema.exclusiveMaximum !== undefined) { 315 - numberExpression = compiler.callExpression({ 316 - functionName: compiler.propertyAccessExpression({ 315 + numberExpression = tsc.callExpression({ 316 + functionName: tsc.propertyAccessExpression({ 317 317 expression: numberExpression, 318 318 name: identifiers.lt, 319 319 }), ··· 322 322 ], 323 323 }); 324 324 } else if (schema.maximum !== undefined) { 325 - numberExpression = compiler.callExpression({ 326 - functionName: compiler.propertyAccessExpression({ 325 + numberExpression = tsc.callExpression({ 326 + functionName: tsc.propertyAccessExpression({ 327 327 expression: numberExpression, 328 328 name: identifiers.lte, 329 329 }), ··· 382 382 propertyName = `'${name}'`; 383 383 } 384 384 properties.push( 385 - compiler.propertyAssignment({ 385 + tsc.propertyAssignment({ 386 386 initializer: propertyExpression, 387 387 name: propertyName, 388 388 }), ··· 399 399 schema: schema.additionalProperties, 400 400 state, 401 401 }).expression; 402 - const expression = compiler.callExpression({ 403 - functionName: compiler.propertyAccessExpression({ 402 + const expression = tsc.callExpression({ 403 + functionName: tsc.propertyAccessExpression({ 404 404 expression: identifiers.z, 405 405 name: identifiers.record, 406 406 }), ··· 412 412 }; 413 413 } 414 414 415 - const expression = compiler.callExpression({ 416 - functionName: compiler.propertyAccessExpression({ 415 + const expression = tsc.callExpression({ 416 + functionName: tsc.propertyAccessExpression({ 417 417 expression: identifiers.z, 418 418 name: identifiers.object, 419 419 }), ··· 433 433 schema: SchemaWithType<'string'>; 434 434 }) => { 435 435 if (typeof schema.const === 'string') { 436 - const expression = compiler.callExpression({ 437 - functionName: compiler.propertyAccessExpression({ 436 + const expression = tsc.callExpression({ 437 + functionName: tsc.propertyAccessExpression({ 438 438 expression: identifiers.z, 439 439 name: identifiers.literal, 440 440 }), 441 - parameters: [compiler.ots.string(schema.const)], 441 + parameters: [tsc.ots.string(schema.const)], 442 442 }); 443 443 return expression; 444 444 } 445 445 446 - let stringExpression = compiler.callExpression({ 447 - functionName: compiler.propertyAccessExpression({ 446 + let stringExpression = tsc.callExpression({ 447 + functionName: tsc.propertyAccessExpression({ 448 448 expression: identifiers.z, 449 449 name: identifiers.string, 450 450 }), ··· 453 453 if (schema.format) { 454 454 switch (schema.format) { 455 455 case 'date': 456 - stringExpression = compiler.callExpression({ 457 - functionName: compiler.propertyAccessExpression({ 456 + stringExpression = tsc.callExpression({ 457 + functionName: tsc.propertyAccessExpression({ 458 458 expression: stringExpression, 459 459 name: identifiers.date, 460 460 }), 461 461 }); 462 462 break; 463 463 case 'date-time': 464 - stringExpression = compiler.callExpression({ 465 - functionName: compiler.propertyAccessExpression({ 464 + stringExpression = tsc.callExpression({ 465 + functionName: tsc.propertyAccessExpression({ 466 466 expression: stringExpression, 467 467 name: identifiers.datetime, 468 468 }), 469 469 parameters: plugin.config.dates.offset 470 470 ? [ 471 - compiler.objectExpression({ 471 + tsc.objectExpression({ 472 472 obj: [ 473 473 { 474 474 key: 'offset', ··· 481 481 }); 482 482 break; 483 483 case 'email': 484 - stringExpression = compiler.callExpression({ 485 - functionName: compiler.propertyAccessExpression({ 484 + stringExpression = tsc.callExpression({ 485 + functionName: tsc.propertyAccessExpression({ 486 486 expression: stringExpression, 487 487 name: identifiers.email, 488 488 }), ··· 490 490 break; 491 491 case 'ipv4': 492 492 case 'ipv6': 493 - stringExpression = compiler.callExpression({ 494 - functionName: compiler.propertyAccessExpression({ 493 + stringExpression = tsc.callExpression({ 494 + functionName: tsc.propertyAccessExpression({ 495 495 expression: stringExpression, 496 496 name: identifiers.ip, 497 497 }), 498 498 }); 499 499 break; 500 500 case 'time': 501 - stringExpression = compiler.callExpression({ 502 - functionName: compiler.propertyAccessExpression({ 501 + stringExpression = tsc.callExpression({ 502 + functionName: tsc.propertyAccessExpression({ 503 503 expression: stringExpression, 504 504 name: identifiers.time, 505 505 }), 506 506 }); 507 507 break; 508 508 case 'uri': 509 - stringExpression = compiler.callExpression({ 510 - functionName: compiler.propertyAccessExpression({ 509 + stringExpression = tsc.callExpression({ 510 + functionName: tsc.propertyAccessExpression({ 511 511 expression: stringExpression, 512 512 name: identifiers.url, 513 513 }), 514 514 }); 515 515 break; 516 516 case 'uuid': 517 - stringExpression = compiler.callExpression({ 518 - functionName: compiler.propertyAccessExpression({ 517 + stringExpression = tsc.callExpression({ 518 + functionName: tsc.propertyAccessExpression({ 519 519 expression: stringExpression, 520 520 name: identifiers.uuid, 521 521 }), ··· 525 525 } 526 526 527 527 if (schema.minLength === schema.maxLength && schema.minLength !== undefined) { 528 - stringExpression = compiler.callExpression({ 529 - functionName: compiler.propertyAccessExpression({ 528 + stringExpression = tsc.callExpression({ 529 + functionName: tsc.propertyAccessExpression({ 530 530 expression: stringExpression, 531 531 name: identifiers.length, 532 532 }), 533 - parameters: [compiler.valueToExpression({ value: schema.minLength })], 533 + parameters: [tsc.valueToExpression({ value: schema.minLength })], 534 534 }); 535 535 } else { 536 536 if (schema.minLength !== undefined) { 537 - stringExpression = compiler.callExpression({ 538 - functionName: compiler.propertyAccessExpression({ 537 + stringExpression = tsc.callExpression({ 538 + functionName: tsc.propertyAccessExpression({ 539 539 expression: stringExpression, 540 540 name: identifiers.min, 541 541 }), 542 - parameters: [compiler.valueToExpression({ value: schema.minLength })], 542 + parameters: [tsc.valueToExpression({ value: schema.minLength })], 543 543 }); 544 544 } 545 545 546 546 if (schema.maxLength !== undefined) { 547 - stringExpression = compiler.callExpression({ 548 - functionName: compiler.propertyAccessExpression({ 547 + stringExpression = tsc.callExpression({ 548 + functionName: tsc.propertyAccessExpression({ 549 549 expression: stringExpression, 550 550 name: identifiers.max, 551 551 }), 552 - parameters: [compiler.valueToExpression({ value: schema.maxLength })], 552 + parameters: [tsc.valueToExpression({ value: schema.maxLength })], 553 553 }); 554 554 } 555 555 } 556 556 557 557 if (schema.pattern) { 558 - stringExpression = compiler.callExpression({ 559 - functionName: compiler.propertyAccessExpression({ 558 + stringExpression = tsc.callExpression({ 559 + functionName: tsc.propertyAccessExpression({ 560 560 expression: stringExpression, 561 561 name: identifiers.regex, 562 562 }), 563 - parameters: [compiler.regularExpressionLiteral({ text: schema.pattern })], 563 + parameters: [tsc.regularExpressionLiteral({ text: schema.pattern })], 564 564 }); 565 565 } 566 566 ··· 578 578 }) => { 579 579 if (schema.const && Array.isArray(schema.const)) { 580 580 const tupleElements = schema.const.map((value) => 581 - compiler.callExpression({ 582 - functionName: compiler.propertyAccessExpression({ 581 + tsc.callExpression({ 582 + functionName: tsc.propertyAccessExpression({ 583 583 expression: identifiers.z, 584 584 name: identifiers.literal, 585 585 }), 586 - parameters: [compiler.valueToExpression({ value })], 586 + parameters: [tsc.valueToExpression({ value })], 587 587 }), 588 588 ); 589 - const expression = compiler.callExpression({ 590 - functionName: compiler.propertyAccessExpression({ 589 + const expression = tsc.callExpression({ 590 + functionName: tsc.propertyAccessExpression({ 591 591 expression: identifiers.z, 592 592 name: identifiers.tuple, 593 593 }), 594 594 parameters: [ 595 - compiler.arrayLiteralExpression({ 595 + tsc.arrayLiteralExpression({ 596 596 elements: tupleElements, 597 597 }), 598 598 ], ··· 612 612 ); 613 613 } 614 614 615 - const expression = compiler.callExpression({ 616 - functionName: compiler.propertyAccessExpression({ 615 + const expression = tsc.callExpression({ 616 + functionName: tsc.propertyAccessExpression({ 617 617 expression: identifiers.z, 618 618 name: identifiers.tuple, 619 619 }), 620 620 parameters: [ 621 - compiler.arrayLiteralExpression({ 621 + tsc.arrayLiteralExpression({ 622 622 elements: tupleElements, 623 623 }), 624 624 ], ··· 630 630 const undefinedTypeToZodSchema = (_props: { 631 631 schema: SchemaWithType<'undefined'>; 632 632 }) => { 633 - const expression = compiler.callExpression({ 634 - functionName: compiler.propertyAccessExpression({ 633 + const expression = tsc.callExpression({ 634 + functionName: tsc.propertyAccessExpression({ 635 635 expression: identifiers.z, 636 636 name: identifiers.undefined, 637 637 }), ··· 643 643 const unknownTypeToZodSchema = (_props: { 644 644 schema: SchemaWithType<'unknown'>; 645 645 }) => { 646 - const expression = compiler.callExpression({ 647 - functionName: compiler.propertyAccessExpression({ 646 + const expression = tsc.callExpression({ 647 + functionName: tsc.propertyAccessExpression({ 648 648 expression: identifiers.z, 649 649 name: identifiers.unknown, 650 650 }), ··· 654 654 655 655 // eslint-disable-next-line @typescript-eslint/no-unused-vars 656 656 const voidTypeToZodSchema = (_props: { schema: SchemaWithType<'void'> }) => { 657 - const expression = compiler.callExpression({ 658 - functionName: compiler.propertyAccessExpression({ 657 + const expression = tsc.callExpression({ 658 + functionName: tsc.propertyAccessExpression({ 659 659 expression: identifiers.z, 660 660 name: identifiers.void, 661 661 }), ··· 788 788 789 789 if (isCircularReference) { 790 790 const expression = file.addNodeReference(id, { 791 - factory: (text) => compiler.identifier({ text }), 791 + factory: (text) => tsc.identifier({ text }), 792 792 }); 793 - zodSchema.expression = compiler.callExpression({ 794 - functionName: compiler.propertyAccessExpression({ 793 + zodSchema.expression = tsc.callExpression({ 794 + functionName: tsc.propertyAccessExpression({ 795 795 expression: identifiers.z, 796 796 name: identifiers.lazy, 797 797 }), 798 798 parameters: [ 799 - compiler.arrowFunction({ 800 - statements: [compiler.returnStatement({ expression })], 799 + tsc.arrowFunction({ 800 + statements: [tsc.returnStatement({ expression })], 801 801 }), 802 802 ], 803 803 }); ··· 817 817 818 818 if (!isCircularReference) { 819 819 const expression = file.addNodeReference(id, { 820 - factory: (text) => compiler.identifier({ text }), 820 + factory: (text) => tsc.identifier({ text }), 821 821 }); 822 822 zodSchema.expression = expression; 823 823 } ··· 830 830 zodSchema.typeName = zSchema.anyType; 831 831 832 832 if (plugin.config.metadata && schema.description) { 833 - zodSchema.expression = compiler.callExpression({ 834 - functionName: compiler.propertyAccessExpression({ 833 + zodSchema.expression = tsc.callExpression({ 834 + functionName: tsc.propertyAccessExpression({ 835 835 expression: zodSchema.expression, 836 836 name: identifiers.describe, 837 837 }), 838 - parameters: [compiler.stringLiteral({ text: schema.description })], 838 + parameters: [tsc.stringLiteral({ text: schema.description })], 839 839 }); 840 840 } 841 841 } else if (schema.items) { ··· 860 860 firstSchema.logicalOperator === 'or' || 861 861 (firstSchema.type && firstSchema.type !== 'object') 862 862 ) { 863 - zodSchema.expression = compiler.callExpression({ 864 - functionName: compiler.propertyAccessExpression({ 863 + zodSchema.expression = tsc.callExpression({ 864 + functionName: tsc.propertyAccessExpression({ 865 865 expression: identifiers.z, 866 866 name: identifiers.intersection, 867 867 }), ··· 870 870 } else { 871 871 zodSchema.expression = itemTypes[0]; 872 872 itemTypes.slice(1).forEach((item) => { 873 - zodSchema.expression = compiler.callExpression({ 874 - functionName: compiler.propertyAccessExpression({ 873 + zodSchema.expression = tsc.callExpression({ 874 + functionName: tsc.propertyAccessExpression({ 875 875 expression: zodSchema.expression!, 876 876 name: identifiers.and, 877 877 }), ··· 880 880 }); 881 881 } 882 882 } else { 883 - zodSchema.expression = compiler.callExpression({ 884 - functionName: compiler.propertyAccessExpression({ 883 + zodSchema.expression = tsc.callExpression({ 884 + functionName: tsc.propertyAccessExpression({ 885 885 expression: identifiers.z, 886 886 name: identifiers.union, 887 887 }), 888 888 parameters: [ 889 - compiler.arrayLiteralExpression({ 889 + tsc.arrayLiteralExpression({ 890 890 elements: itemTypes, 891 891 }), 892 892 ], ··· 910 910 911 911 if (zodSchema.expression) { 912 912 if (schema.accessScope === 'read') { 913 - zodSchema.expression = compiler.callExpression({ 914 - functionName: compiler.propertyAccessExpression({ 913 + zodSchema.expression = tsc.callExpression({ 914 + functionName: tsc.propertyAccessExpression({ 915 915 expression: zodSchema.expression, 916 916 name: identifiers.readonly, 917 917 }), ··· 919 919 } 920 920 921 921 if (optional) { 922 - zodSchema.expression = compiler.callExpression({ 923 - functionName: compiler.propertyAccessExpression({ 922 + zodSchema.expression = tsc.callExpression({ 923 + functionName: tsc.propertyAccessExpression({ 924 924 expression: zodSchema.expression, 925 925 name: identifiers.optional, 926 926 }), ··· 934 934 value: schema.default, 935 935 }); 936 936 if (callParameter) { 937 - zodSchema.expression = compiler.callExpression({ 938 - functionName: compiler.propertyAccessExpression({ 937 + zodSchema.expression = tsc.callExpression({ 938 + functionName: tsc.propertyAccessExpression({ 939 939 expression: zodSchema.expression, 940 940 name: identifiers.default, 941 941 }),
+141 -141
packages/openapi-ts/src/plugins/zod/v4/plugin.ts
··· 1 1 import ts from 'typescript'; 2 2 3 - import { compiler } from '../../../compiler'; 4 3 import { deduplicateSchema } from '../../../ir/schema'; 5 4 import type { IR } from '../../../ir/types'; 6 5 import { buildName } from '../../../openApi/shared/utils/name'; 6 + import { tsc } from '../../../tsc'; 7 7 import { refToName } from '../../../utils/ref'; 8 8 import { numberRegExp } from '../../../utils/regexp'; 9 9 import { identifiers, zodId } from '../constants'; ··· 24 24 }): Omit<ZodSchema, 'typeName'> => { 25 25 const result: Partial<Omit<ZodSchema, 'typeName'>> = {}; 26 26 27 - const functionName = compiler.propertyAccessExpression({ 27 + const functionName = tsc.propertyAccessExpression({ 28 28 expression: identifiers.z, 29 29 name: identifiers.array, 30 30 }); 31 31 32 32 if (!schema.items) { 33 - result.expression = compiler.callExpression({ 33 + result.expression = tsc.callExpression({ 34 34 functionName, 35 35 parameters: [ 36 36 unknownTypeToZodSchema({ ··· 57 57 }); 58 58 59 59 if (itemExpressions.length === 1) { 60 - result.expression = compiler.callExpression({ 60 + result.expression = tsc.callExpression({ 61 61 functionName, 62 62 parameters: itemExpressions, 63 63 }); 64 64 } else { 65 65 if (schema.logicalOperator === 'and') { 66 66 // TODO: parser - handle intersection 67 - // return compiler.typeArrayNode( 68 - // compiler.typeIntersectionNode({ types: itemExpressions }), 67 + // return tsc.typeArrayNode( 68 + // tsc.typeIntersectionNode({ types: itemExpressions }), 69 69 // ); 70 70 } 71 71 72 - result.expression = compiler.callExpression({ 73 - functionName: compiler.propertyAccessExpression({ 72 + result.expression = tsc.callExpression({ 73 + functionName: tsc.propertyAccessExpression({ 74 74 expression: identifiers.z, 75 75 name: identifiers.array, 76 76 }), 77 77 parameters: [ 78 - compiler.callExpression({ 79 - functionName: compiler.propertyAccessExpression({ 78 + tsc.callExpression({ 79 + functionName: tsc.propertyAccessExpression({ 80 80 expression: identifiers.z, 81 81 name: identifiers.union, 82 82 }), 83 83 parameters: [ 84 - compiler.arrayLiteralExpression({ 84 + tsc.arrayLiteralExpression({ 85 85 elements: itemExpressions, 86 86 }), 87 87 ], ··· 92 92 } 93 93 94 94 if (schema.minItems === schema.maxItems && schema.minItems !== undefined) { 95 - result.expression = compiler.callExpression({ 96 - functionName: compiler.propertyAccessExpression({ 95 + result.expression = tsc.callExpression({ 96 + functionName: tsc.propertyAccessExpression({ 97 97 expression: result.expression, 98 98 name: identifiers.length, 99 99 }), 100 - parameters: [compiler.valueToExpression({ value: schema.minItems })], 100 + parameters: [tsc.valueToExpression({ value: schema.minItems })], 101 101 }); 102 102 } else { 103 103 if (schema.minItems !== undefined) { 104 - result.expression = compiler.callExpression({ 105 - functionName: compiler.propertyAccessExpression({ 104 + result.expression = tsc.callExpression({ 105 + functionName: tsc.propertyAccessExpression({ 106 106 expression: result.expression, 107 107 name: identifiers.min, 108 108 }), 109 - parameters: [compiler.valueToExpression({ value: schema.minItems })], 109 + parameters: [tsc.valueToExpression({ value: schema.minItems })], 110 110 }); 111 111 } 112 112 113 113 if (schema.maxItems !== undefined) { 114 - result.expression = compiler.callExpression({ 115 - functionName: compiler.propertyAccessExpression({ 114 + result.expression = tsc.callExpression({ 115 + functionName: tsc.propertyAccessExpression({ 116 116 expression: result.expression, 117 117 name: identifiers.max, 118 118 }), 119 - parameters: [compiler.valueToExpression({ value: schema.maxItems })], 119 + parameters: [tsc.valueToExpression({ value: schema.maxItems })], 120 120 }); 121 121 } 122 122 } ··· 132 132 const result: Partial<Omit<ZodSchema, 'typeName'>> = {}; 133 133 134 134 if (typeof schema.const === 'boolean') { 135 - result.expression = compiler.callExpression({ 136 - functionName: compiler.propertyAccessExpression({ 135 + result.expression = tsc.callExpression({ 136 + functionName: tsc.propertyAccessExpression({ 137 137 expression: identifiers.z, 138 138 name: identifiers.literal, 139 139 }), 140 - parameters: [compiler.ots.boolean(schema.const)], 140 + parameters: [tsc.ots.boolean(schema.const)], 141 141 }); 142 142 return result as Omit<ZodSchema, 'typeName'>; 143 143 } 144 144 145 - result.expression = compiler.callExpression({ 146 - functionName: compiler.propertyAccessExpression({ 145 + result.expression = tsc.callExpression({ 146 + functionName: tsc.propertyAccessExpression({ 147 147 expression: identifiers.z, 148 148 name: identifiers.boolean, 149 149 }), ··· 166 166 // Zod supports only string enums 167 167 if (item.type === 'string' && typeof item.const === 'string') { 168 168 enumMembers.push( 169 - compiler.stringLiteral({ 169 + tsc.stringLiteral({ 170 170 text: item.const, 171 171 }), 172 172 ); ··· 183 183 }); 184 184 } 185 185 186 - result.expression = compiler.callExpression({ 187 - functionName: compiler.propertyAccessExpression({ 186 + result.expression = tsc.callExpression({ 187 + functionName: tsc.propertyAccessExpression({ 188 188 expression: identifiers.z, 189 189 name: identifiers.enum, 190 190 }), 191 191 parameters: [ 192 - compiler.arrayLiteralExpression({ 192 + tsc.arrayLiteralExpression({ 193 193 elements: enumMembers, 194 194 multiLine: false, 195 195 }), ··· 197 197 }); 198 198 199 199 if (isNullable) { 200 - result.expression = compiler.callExpression({ 201 - functionName: compiler.propertyAccessExpression({ 200 + result.expression = tsc.callExpression({ 201 + functionName: tsc.propertyAccessExpression({ 202 202 expression: identifiers.z, 203 203 name: identifiers.nullable, 204 204 }), ··· 214 214 schema: SchemaWithType<'never'>; 215 215 }): Omit<ZodSchema, 'typeName'> => { 216 216 const result: Partial<Omit<ZodSchema, 'typeName'>> = {}; 217 - result.expression = compiler.callExpression({ 218 - functionName: compiler.propertyAccessExpression({ 217 + result.expression = tsc.callExpression({ 218 + functionName: tsc.propertyAccessExpression({ 219 219 expression: identifiers.z, 220 220 name: identifiers.never, 221 221 }), ··· 228 228 schema: SchemaWithType<'null'>; 229 229 }): Omit<ZodSchema, 'typeName'> => { 230 230 const result: Partial<Omit<ZodSchema, 'typeName'>> = {}; 231 - result.expression = compiler.callExpression({ 232 - functionName: compiler.propertyAccessExpression({ 231 + result.expression = tsc.callExpression({ 232 + functionName: tsc.propertyAccessExpression({ 233 233 expression: identifiers.z, 234 234 name: identifiers.null, 235 235 }), ··· 244 244 isBigInt: boolean; 245 245 value: unknown; 246 246 }): ts.Expression | undefined => { 247 - const expression = compiler.valueToExpression({ value }); 247 + const expression = tsc.valueToExpression({ value }); 248 248 249 249 if ( 250 250 isBigInt && ··· 253 253 typeof value === 'string' || 254 254 typeof value === 'boolean') 255 255 ) { 256 - return compiler.callExpression({ 256 + return tsc.callExpression({ 257 257 functionName: 'BigInt', 258 258 parameters: [expression], 259 259 }); ··· 273 273 274 274 if (typeof schema.const === 'number') { 275 275 // TODO: parser - handle bigint constants 276 - result.expression = compiler.callExpression({ 277 - functionName: compiler.propertyAccessExpression({ 276 + result.expression = tsc.callExpression({ 277 + functionName: tsc.propertyAccessExpression({ 278 278 expression: identifiers.z, 279 279 name: identifiers.literal, 280 280 }), 281 - parameters: [compiler.ots.number(schema.const)], 281 + parameters: [tsc.ots.number(schema.const)], 282 282 }); 283 283 return result as Omit<ZodSchema, 'typeName'>; 284 284 } 285 285 286 - result.expression = compiler.callExpression({ 286 + result.expression = tsc.callExpression({ 287 287 functionName: isBigInt 288 - ? compiler.propertyAccessExpression({ 289 - expression: compiler.propertyAccessExpression({ 288 + ? tsc.propertyAccessExpression({ 289 + expression: tsc.propertyAccessExpression({ 290 290 expression: identifiers.z, 291 291 name: identifiers.coerce, 292 292 }), 293 293 name: identifiers.bigint, 294 294 }) 295 - : compiler.propertyAccessExpression({ 295 + : tsc.propertyAccessExpression({ 296 296 expression: identifiers.z, 297 297 name: identifiers.number, 298 298 }), 299 299 }); 300 300 301 301 if (!isBigInt && schema.type === 'integer') { 302 - result.expression = compiler.callExpression({ 303 - functionName: compiler.propertyAccessExpression({ 302 + result.expression = tsc.callExpression({ 303 + functionName: tsc.propertyAccessExpression({ 304 304 expression: identifiers.z, 305 305 name: identifiers.int, 306 306 }), ··· 308 308 } 309 309 310 310 if (schema.exclusiveMinimum !== undefined) { 311 - result.expression = compiler.callExpression({ 312 - functionName: compiler.propertyAccessExpression({ 311 + result.expression = tsc.callExpression({ 312 + functionName: tsc.propertyAccessExpression({ 313 313 expression: result.expression, 314 314 name: identifiers.gt, 315 315 }), ··· 318 318 ], 319 319 }); 320 320 } else if (schema.minimum !== undefined) { 321 - result.expression = compiler.callExpression({ 322 - functionName: compiler.propertyAccessExpression({ 321 + result.expression = tsc.callExpression({ 322 + functionName: tsc.propertyAccessExpression({ 323 323 expression: result.expression, 324 324 name: identifiers.gte, 325 325 }), ··· 328 328 } 329 329 330 330 if (schema.exclusiveMaximum !== undefined) { 331 - result.expression = compiler.callExpression({ 332 - functionName: compiler.propertyAccessExpression({ 331 + result.expression = tsc.callExpression({ 332 + functionName: tsc.propertyAccessExpression({ 333 333 expression: result.expression, 334 334 name: identifiers.lt, 335 335 }), ··· 338 338 ], 339 339 }); 340 340 } else if (schema.maximum !== undefined) { 341 - result.expression = compiler.callExpression({ 342 - functionName: compiler.propertyAccessExpression({ 341 + result.expression = tsc.callExpression({ 342 + functionName: tsc.propertyAccessExpression({ 343 343 expression: result.expression, 344 344 name: identifiers.lte, 345 345 }), ··· 403 403 404 404 if (propertySchema.hasCircularReference) { 405 405 properties.push( 406 - compiler.getAccessorDeclaration({ 406 + tsc.getAccessorDeclaration({ 407 407 name: propertyName, 408 408 // @ts-expect-error 409 409 returnType: propertySchema.typeName 410 - ? compiler.propertyAccessExpression({ 410 + ? tsc.propertyAccessExpression({ 411 411 expression: identifiers.z, 412 412 name: propertySchema.typeName, 413 413 }) 414 414 : undefined, 415 415 statements: [ 416 - compiler.returnStatement({ 416 + tsc.returnStatement({ 417 417 expression: propertySchema.expression, 418 418 }), 419 419 ], ··· 421 421 ); 422 422 } else { 423 423 properties.push( 424 - compiler.propertyAssignment({ 424 + tsc.propertyAssignment({ 425 425 initializer: propertySchema.expression, 426 426 name: propertyName, 427 427 }), ··· 439 439 schema: schema.additionalProperties, 440 440 state, 441 441 }); 442 - result.expression = compiler.callExpression({ 443 - functionName: compiler.propertyAccessExpression({ 442 + result.expression = tsc.callExpression({ 443 + functionName: tsc.propertyAccessExpression({ 444 444 expression: identifiers.z, 445 445 name: identifiers.record, 446 446 }), 447 447 parameters: [ 448 - compiler.callExpression({ 449 - functionName: compiler.propertyAccessExpression({ 448 + tsc.callExpression({ 449 + functionName: tsc.propertyAccessExpression({ 450 450 expression: identifiers.z, 451 451 name: identifiers.string, 452 452 }), ··· 461 461 return result as Omit<ZodSchema, 'typeName'>; 462 462 } 463 463 464 - result.expression = compiler.callExpression({ 465 - functionName: compiler.propertyAccessExpression({ 464 + result.expression = tsc.callExpression({ 465 + functionName: tsc.propertyAccessExpression({ 466 466 expression: identifiers.z, 467 467 name: identifiers.object, 468 468 }), ··· 482 482 const result: Partial<Omit<ZodSchema, 'typeName'>> = {}; 483 483 484 484 if (typeof schema.const === 'string') { 485 - result.expression = compiler.callExpression({ 486 - functionName: compiler.propertyAccessExpression({ 485 + result.expression = tsc.callExpression({ 486 + functionName: tsc.propertyAccessExpression({ 487 487 expression: identifiers.z, 488 488 name: identifiers.literal, 489 489 }), 490 - parameters: [compiler.ots.string(schema.const)], 490 + parameters: [tsc.ots.string(schema.const)], 491 491 }); 492 492 return result as Omit<ZodSchema, 'typeName'>; 493 493 } 494 494 495 - result.expression = compiler.callExpression({ 496 - functionName: compiler.propertyAccessExpression({ 495 + result.expression = tsc.callExpression({ 496 + functionName: tsc.propertyAccessExpression({ 497 497 expression: identifiers.z, 498 498 name: identifiers.string, 499 499 }), ··· 502 502 if (schema.format) { 503 503 switch (schema.format) { 504 504 case 'date': 505 - result.expression = compiler.callExpression({ 506 - functionName: compiler.propertyAccessExpression({ 507 - expression: compiler.propertyAccessExpression({ 505 + result.expression = tsc.callExpression({ 506 + functionName: tsc.propertyAccessExpression({ 507 + expression: tsc.propertyAccessExpression({ 508 508 expression: identifiers.z, 509 509 name: identifiers.iso, 510 510 }), ··· 513 513 }); 514 514 break; 515 515 case 'date-time': 516 - result.expression = compiler.callExpression({ 517 - functionName: compiler.propertyAccessExpression({ 518 - expression: compiler.propertyAccessExpression({ 516 + result.expression = tsc.callExpression({ 517 + functionName: tsc.propertyAccessExpression({ 518 + expression: tsc.propertyAccessExpression({ 519 519 expression: identifiers.z, 520 520 name: identifiers.iso, 521 521 }), ··· 523 523 }), 524 524 parameters: plugin.config.dates.offset 525 525 ? [ 526 - compiler.objectExpression({ 526 + tsc.objectExpression({ 527 527 obj: [ 528 528 { 529 529 key: 'offset', ··· 536 536 }); 537 537 break; 538 538 case 'email': 539 - result.expression = compiler.callExpression({ 540 - functionName: compiler.propertyAccessExpression({ 539 + result.expression = tsc.callExpression({ 540 + functionName: tsc.propertyAccessExpression({ 541 541 expression: identifiers.z, 542 542 name: identifiers.email, 543 543 }), 544 544 }); 545 545 break; 546 546 case 'ipv4': 547 - result.expression = compiler.callExpression({ 548 - functionName: compiler.propertyAccessExpression({ 547 + result.expression = tsc.callExpression({ 548 + functionName: tsc.propertyAccessExpression({ 549 549 expression: identifiers.z, 550 550 name: identifiers.ipv4, 551 551 }), 552 552 }); 553 553 break; 554 554 case 'ipv6': 555 - result.expression = compiler.callExpression({ 556 - functionName: compiler.propertyAccessExpression({ 555 + result.expression = tsc.callExpression({ 556 + functionName: tsc.propertyAccessExpression({ 557 557 expression: identifiers.z, 558 558 name: identifiers.ipv6, 559 559 }), 560 560 }); 561 561 break; 562 562 case 'time': 563 - result.expression = compiler.callExpression({ 564 - functionName: compiler.propertyAccessExpression({ 565 - expression: compiler.propertyAccessExpression({ 563 + result.expression = tsc.callExpression({ 564 + functionName: tsc.propertyAccessExpression({ 565 + expression: tsc.propertyAccessExpression({ 566 566 expression: identifiers.z, 567 567 name: identifiers.iso, 568 568 }), ··· 571 571 }); 572 572 break; 573 573 case 'uri': 574 - result.expression = compiler.callExpression({ 575 - functionName: compiler.propertyAccessExpression({ 574 + result.expression = tsc.callExpression({ 575 + functionName: tsc.propertyAccessExpression({ 576 576 expression: identifiers.z, 577 577 name: identifiers.url, 578 578 }), 579 579 }); 580 580 break; 581 581 case 'uuid': 582 - result.expression = compiler.callExpression({ 583 - functionName: compiler.propertyAccessExpression({ 582 + result.expression = tsc.callExpression({ 583 + functionName: tsc.propertyAccessExpression({ 584 584 expression: identifiers.z, 585 585 name: identifiers.uuid, 586 586 }), ··· 590 590 } 591 591 592 592 if (schema.minLength === schema.maxLength && schema.minLength !== undefined) { 593 - result.expression = compiler.callExpression({ 594 - functionName: compiler.propertyAccessExpression({ 593 + result.expression = tsc.callExpression({ 594 + functionName: tsc.propertyAccessExpression({ 595 595 expression: result.expression, 596 596 name: identifiers.length, 597 597 }), 598 - parameters: [compiler.valueToExpression({ value: schema.minLength })], 598 + parameters: [tsc.valueToExpression({ value: schema.minLength })], 599 599 }); 600 600 } else { 601 601 if (schema.minLength !== undefined) { 602 - result.expression = compiler.callExpression({ 603 - functionName: compiler.propertyAccessExpression({ 602 + result.expression = tsc.callExpression({ 603 + functionName: tsc.propertyAccessExpression({ 604 604 expression: result.expression, 605 605 name: identifiers.min, 606 606 }), 607 - parameters: [compiler.valueToExpression({ value: schema.minLength })], 607 + parameters: [tsc.valueToExpression({ value: schema.minLength })], 608 608 }); 609 609 } 610 610 611 611 if (schema.maxLength !== undefined) { 612 - result.expression = compiler.callExpression({ 613 - functionName: compiler.propertyAccessExpression({ 612 + result.expression = tsc.callExpression({ 613 + functionName: tsc.propertyAccessExpression({ 614 614 expression: result.expression, 615 615 name: identifiers.max, 616 616 }), 617 - parameters: [compiler.valueToExpression({ value: schema.maxLength })], 617 + parameters: [tsc.valueToExpression({ value: schema.maxLength })], 618 618 }); 619 619 } 620 620 } 621 621 622 622 if (schema.pattern) { 623 - result.expression = compiler.callExpression({ 624 - functionName: compiler.propertyAccessExpression({ 623 + result.expression = tsc.callExpression({ 624 + functionName: tsc.propertyAccessExpression({ 625 625 expression: result.expression, 626 626 name: identifiers.regex, 627 627 }), 628 - parameters: [compiler.regularExpressionLiteral({ text: schema.pattern })], 628 + parameters: [tsc.regularExpressionLiteral({ text: schema.pattern })], 629 629 }); 630 630 } 631 631 ··· 645 645 646 646 if (schema.const && Array.isArray(schema.const)) { 647 647 const tupleElements = schema.const.map((value) => 648 - compiler.callExpression({ 649 - functionName: compiler.propertyAccessExpression({ 648 + tsc.callExpression({ 649 + functionName: tsc.propertyAccessExpression({ 650 650 expression: identifiers.z, 651 651 name: identifiers.literal, 652 652 }), 653 - parameters: [compiler.valueToExpression({ value })], 653 + parameters: [tsc.valueToExpression({ value })], 654 654 }), 655 655 ); 656 - result.expression = compiler.callExpression({ 657 - functionName: compiler.propertyAccessExpression({ 656 + result.expression = tsc.callExpression({ 657 + functionName: tsc.propertyAccessExpression({ 658 658 expression: identifiers.z, 659 659 name: identifiers.tuple, 660 660 }), 661 661 parameters: [ 662 - compiler.arrayLiteralExpression({ 662 + tsc.arrayLiteralExpression({ 663 663 elements: tupleElements, 664 664 }), 665 665 ], ··· 682 682 } 683 683 } 684 684 685 - result.expression = compiler.callExpression({ 686 - functionName: compiler.propertyAccessExpression({ 685 + result.expression = tsc.callExpression({ 686 + functionName: tsc.propertyAccessExpression({ 687 687 expression: identifiers.z, 688 688 name: identifiers.tuple, 689 689 }), 690 690 parameters: [ 691 - compiler.arrayLiteralExpression({ 691 + tsc.arrayLiteralExpression({ 692 692 elements: tupleElements, 693 693 }), 694 694 ], ··· 702 702 schema: SchemaWithType<'undefined'>; 703 703 }): Omit<ZodSchema, 'typeName'> => { 704 704 const result: Partial<Omit<ZodSchema, 'typeName'>> = {}; 705 - result.expression = compiler.callExpression({ 706 - functionName: compiler.propertyAccessExpression({ 705 + result.expression = tsc.callExpression({ 706 + functionName: tsc.propertyAccessExpression({ 707 707 expression: identifiers.z, 708 708 name: identifiers.undefined, 709 709 }), ··· 716 716 schema: SchemaWithType<'unknown'>; 717 717 }): Omit<ZodSchema, 'typeName'> => { 718 718 const result: Partial<Omit<ZodSchema, 'typeName'>> = {}; 719 - result.expression = compiler.callExpression({ 720 - functionName: compiler.propertyAccessExpression({ 719 + result.expression = tsc.callExpression({ 720 + functionName: tsc.propertyAccessExpression({ 721 721 expression: identifiers.z, 722 722 name: identifiers.unknown, 723 723 }), ··· 730 730 schema: SchemaWithType<'void'>; 731 731 }): Omit<ZodSchema, 'typeName'> => { 732 732 const result: Partial<Omit<ZodSchema, 'typeName'>> = {}; 733 - result.expression = compiler.callExpression({ 734 - functionName: compiler.propertyAccessExpression({ 733 + result.expression = tsc.callExpression({ 734 + functionName: tsc.propertyAccessExpression({ 735 735 expression: identifiers.z, 736 736 name: identifiers.void, 737 737 }), ··· 840 840 841 841 if (isCircularReference) { 842 842 const expression = file.addNodeReference(id, { 843 - factory: (text) => compiler.identifier({ text }), 843 + factory: (text) => tsc.identifier({ text }), 844 844 }); 845 845 if (isSelfReference) { 846 - zodSchema.expression = compiler.callExpression({ 847 - functionName: compiler.propertyAccessExpression({ 846 + zodSchema.expression = tsc.callExpression({ 847 + functionName: tsc.propertyAccessExpression({ 848 848 expression: identifiers.z, 849 849 name: identifiers.lazy, 850 850 }), 851 851 parameters: [ 852 - compiler.arrowFunction({ 853 - returnType: compiler.keywordTypeNode({ keyword: 'any' }), 854 - statements: [compiler.returnStatement({ expression })], 852 + tsc.arrowFunction({ 853 + returnType: tsc.keywordTypeNode({ keyword: 'any' }), 854 + statements: [tsc.returnStatement({ expression })], 855 855 }), 856 856 ], 857 857 }); ··· 874 874 875 875 if (!isCircularReference) { 876 876 const expression = file.addNodeReference(id, { 877 - factory: (text) => compiler.identifier({ text }), 877 + factory: (text) => tsc.identifier({ text }), 878 878 }); 879 879 zodSchema.expression = expression; 880 880 } ··· 887 887 zodSchema.hasCircularReference = zSchema.hasCircularReference; 888 888 889 889 if (plugin.config.metadata && schema.description) { 890 - zodSchema.expression = compiler.callExpression({ 891 - functionName: compiler.propertyAccessExpression({ 890 + zodSchema.expression = tsc.callExpression({ 891 + functionName: tsc.propertyAccessExpression({ 892 892 expression: zodSchema.expression, 893 893 name: identifiers.register, 894 894 }), 895 895 parameters: [ 896 - compiler.propertyAccessExpression({ 896 + tsc.propertyAccessExpression({ 897 897 expression: identifiers.z, 898 898 name: identifiers.globalRegistry, 899 899 }), 900 - compiler.objectExpression({ 900 + tsc.objectExpression({ 901 901 obj: [ 902 902 { 903 903 key: 'description', 904 - value: compiler.stringLiteral({ text: schema.description }), 904 + value: tsc.stringLiteral({ text: schema.description }), 905 905 }, 906 906 ], 907 907 }), ··· 930 930 firstSchema.logicalOperator === 'or' || 931 931 (firstSchema.type && firstSchema.type !== 'object') 932 932 ) { 933 - zodSchema.expression = compiler.callExpression({ 934 - functionName: compiler.propertyAccessExpression({ 933 + zodSchema.expression = tsc.callExpression({ 934 + functionName: tsc.propertyAccessExpression({ 935 935 expression: identifiers.z, 936 936 name: identifiers.intersection, 937 937 }), ··· 940 940 } else { 941 941 zodSchema.expression = itemTypes[0]; 942 942 itemTypes.slice(1).forEach((item) => { 943 - zodSchema.expression = compiler.callExpression({ 944 - functionName: compiler.propertyAccessExpression({ 943 + zodSchema.expression = tsc.callExpression({ 944 + functionName: tsc.propertyAccessExpression({ 945 945 expression: zodSchema.expression!, 946 946 name: identifiers.and, 947 947 }), ··· 950 950 }); 951 951 } 952 952 } else { 953 - zodSchema.expression = compiler.callExpression({ 954 - functionName: compiler.propertyAccessExpression({ 953 + zodSchema.expression = tsc.callExpression({ 954 + functionName: tsc.propertyAccessExpression({ 955 955 expression: identifiers.z, 956 956 name: identifiers.union, 957 957 }), 958 958 parameters: [ 959 - compiler.arrayLiteralExpression({ 959 + tsc.arrayLiteralExpression({ 960 960 elements: itemTypes, 961 961 }), 962 962 ], ··· 979 979 980 980 if (zodSchema.expression) { 981 981 if (schema.accessScope === 'read') { 982 - zodSchema.expression = compiler.callExpression({ 983 - functionName: compiler.propertyAccessExpression({ 982 + zodSchema.expression = tsc.callExpression({ 983 + functionName: tsc.propertyAccessExpression({ 984 984 expression: zodSchema.expression, 985 985 name: identifiers.readonly, 986 986 }), ··· 988 988 } 989 989 990 990 if (optional) { 991 - zodSchema.expression = compiler.callExpression({ 992 - functionName: compiler.propertyAccessExpression({ 991 + zodSchema.expression = tsc.callExpression({ 992 + functionName: tsc.propertyAccessExpression({ 993 993 expression: identifiers.z, 994 994 name: identifiers.optional, 995 995 }), ··· 1005 1005 value: schema.default, 1006 1006 }); 1007 1007 if (callParameter) { 1008 - zodSchema.expression = compiler.callExpression({ 1009 - functionName: compiler.propertyAccessExpression({ 1008 + zodSchema.expression = tsc.callExpression({ 1009 + functionName: tsc.propertyAccessExpression({ 1010 1010 expression: zodSchema.expression, 1011 1011 name: identifiers.default, 1012 1012 }),
+19 -19
packages/openapi-ts/src/utils/type.ts
··· 1 1 import type ts from 'typescript'; 2 2 3 - import { compiler, type Property } from '../compiler'; 4 3 import type { Model } from '../openApi'; 5 4 import { sanitizeOperationParameterName } from '../openApi'; 5 + import { type Property, tsc } from '../tsc'; 6 6 import type { Client } from '../types/client'; 7 7 import { getConfig, isLegacyClient } from './config'; 8 8 import { refSchemasPartial } from './const'; ··· 20 20 const config = getConfig(); 21 21 22 22 if (model.base === 'binary') { 23 - return compiler.typeUnionNode({ 23 + return tsc.typeUnionNode({ 24 24 types: ['Blob', 'File'], 25 25 }); 26 26 } ··· 29 29 config.plugins['@hey-api/transformers']?.config.dates && 30 30 isModelDate(model) 31 31 ) { 32 - return compiler.typeNode('Date'); 32 + return tsc.typeNode('Date'); 33 33 } 34 34 35 - return compiler.typeNode(model.base); 35 + return tsc.typeNode(model.base); 36 36 }; 37 37 38 38 const typeReference = (model: Model) => { ··· 48 48 if (model.export === 'reference' && model.$refs.length === 1) { 49 49 if (model.$refs[0]!.startsWith(refSchemasPartial)) { 50 50 const meta = getSchemasMeta(model.base); 51 - typeNode = compiler.typeNode(meta.name); 51 + typeNode = tsc.typeNode(meta.name); 52 52 } 53 53 } 54 - const unionNode = compiler.typeUnionNode({ 54 + const unionNode = tsc.typeUnionNode({ 55 55 isNullable, 56 56 types: [typeNode], 57 57 }); ··· 63 63 // We treat an array of `model.link` as constant size array definition. 64 64 if (Array.isArray(model.link)) { 65 65 const types = model.link.map((m) => toType(m)); 66 - const tuple = compiler.typeTupleNode({ 66 + const tuple = tsc.typeTupleNode({ 67 67 isNullable: model.isNullable, 68 68 types, 69 69 }); ··· 79 79 model.maxItems <= 100 80 80 ) { 81 81 const types = Array(model.maxItems).fill(toType(model.link)); 82 - const tuple = compiler.typeTupleNode({ 82 + const tuple = tsc.typeTupleNode({ 83 83 isNullable: model.isNullable, 84 84 types, 85 85 }); 86 86 return tuple; 87 87 } 88 88 89 - return compiler.typeArrayNode([toType(model.link)], model.isNullable); 89 + return tsc.typeArrayNode([toType(model.link)], model.isNullable); 90 90 } 91 91 92 - return compiler.typeArrayNode([base(model)], model.isNullable); 92 + return tsc.typeArrayNode([base(model)], model.isNullable); 93 93 }; 94 94 95 95 const typeEnum = (model: Model) => { 96 96 const values = model.enum.map((enumerator) => enumValue(enumerator.value)); 97 - return compiler.typeUnionNode({ 97 + return tsc.typeUnionNode({ 98 98 isNullable: model.isNullable, 99 99 types: values, 100 100 }); ··· 103 103 const typeDict = (model: Model) => { 104 104 const type = 105 105 model.link && !Array.isArray(model.link) ? toType(model.link) : base(model); 106 - return compiler.typeRecordNode(['string'], [type], model.isNullable, true); 106 + return tsc.typeRecordNode(['string'], [type], model.isNullable, true); 107 107 }; 108 108 109 109 const typeUnionOrIntersection = ({ ··· 115 115 }) => { 116 116 const types = model.properties 117 117 .map((model) => { 118 - const str = compiler.nodeToString({ 118 + const str = tsc.nodeToString({ 119 119 node: toType(model), 120 120 unescape: true, 121 121 }); ··· 125 125 126 126 const node = 127 127 style === 'union' 128 - ? compiler.typeUnionNode({ 128 + ? tsc.typeUnionNode({ 129 129 // avoid printing duplicate null statements 130 130 isNullable: 131 131 model.isNullable && 132 132 !model.properties.find((property) => property.isNullable), 133 133 types, 134 134 }) 135 - : compiler.typeIntersectionNode({ 135 + : tsc.typeIntersectionNode({ 136 136 isNullable: model.isNullable, 137 137 types, 138 138 }); ··· 142 142 return node; 143 143 } 144 144 145 - return compiler.typeParenthesizedNode({ 145 + return tsc.typeParenthesizedNode({ 146 146 type: node, 147 147 }); 148 148 }; 149 149 150 150 const typeInterface = (model: Model) => { 151 151 if (!model.properties.length) { 152 - return compiler.typeNode('unknown'); 152 + return tsc.typeNode('unknown'); 153 153 } 154 154 155 155 const config = getConfig(); ··· 172 172 name = property.name; 173 173 if (maybeRequired) { 174 174 maybeRequired = ''; 175 - value = compiler.typeUnionNode({ 175 + value = tsc.typeUnionNode({ 176 176 types: [value, 'undefined'], 177 177 }); 178 178 } ··· 189 189 }; 190 190 }); 191 191 192 - return compiler.typeInterfaceNode({ 192 + return tsc.typeInterfaceNode({ 193 193 isNullable: model.isNullable, 194 194 properties, 195 195 useLegacyResolution: true,