Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

[WIP] BREAKING CHANGE: refactor how annotations are exposed in generated TS #154

Closed
wants to merge 22 commits into from
Closed
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
18 changes: 13 additions & 5 deletions package-lock.json

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

2 changes: 1 addition & 1 deletion package.json
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
{
"name": "@creditkarma/thrift-typescript",
"version": "3.7.0-1",
"version": "4.0.0-8",
"description": "Generate TypeScript from Thrift IDL files",
"main": "./dist/main/index.js",
"types": "./dist/main/index.d.ts",
Expand Down
8 changes: 2 additions & 6 deletions src/main/bin/resolveOptions.ts
Original file line number Diff line number Diff line change
Expand Up @@ -31,16 +31,12 @@ export function resolveOptions(args: Array<string>): IMakeOptions {
break
} else {
throw new Error(
`Provided root directory "${
options.rootDir
}" isn't a directory`,
`Provided root directory "${options.rootDir}" isn't a directory`,
)
}
} catch (e) {
throw new Error(
`Provided root directory "${
options.rootDir
}" doesn't exist`,
`Provided root directory "${options.rootDir}" doesn't exist`,
)
}

Expand Down
38 changes: 15 additions & 23 deletions src/main/debugger/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -76,41 +76,33 @@ function printErrorForFile<T extends IErrorFile>(file: T): void {
}

console.log(
`Error generating file '${file.sourceFile.path}/${
file.sourceFile.name
}.thrift': ${file.errors.length} errors found:`,
`Error generating file '${file.sourceFile.path}/${file.sourceFile.name}.thrift': ${file.errors.length} errors found:`,
)
formattedErrors.forEach(
(err: IFormattedError): void => {
const prefix: string = `${err.line} | `
formattedErrors.forEach((err: IFormattedError): void => {
const prefix: string = `${err.line} | `

console.log()
console.log(`${errorType(err.type)}\n`)
console.log(`Message: ${err.message}`)
console.log()
console.log(`${prefix}${err.sourceLine}`)
console.log(padStart(prefix.length, err.locIndicator))
console.log()
},
)
console.log()
console.log(`${errorType(err.type)}\n`)
console.log(`Message: ${err.message}`)
console.log()
console.log(`${prefix}${err.sourceLine}`)
console.log(padStart(prefix.length, err.locIndicator))
console.log()
})
}

export function printErrorsForFiles<T extends IErrorFile>(
files: Array<T>,
): void {
files.forEach(
(next: T): void => {
printErrorForFile(next)
},
)
files.forEach((next: T): void => {
printErrorForFile(next)
})
}

export function printErrors(files: Array<INamespace>): void {
files.forEach((next: INamespace) => {
console.log(
`Errors encountered while generating namesapce: ${
next.namespace.name
}`,
`Errors encountered while generating namesapce: ${next.namespace.name}`,
)
console.log()
next.errors.forEach((err: IThriftError) => {
Expand Down
6 changes: 4 additions & 2 deletions src/main/render/apache/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -18,7 +18,6 @@ import { renderInterface } from './interface'
import {
renderArgsStruct,
renderClient,
renderHandlerInterface,
renderProcessor,
renderResultStruct,
} from './service'
Expand All @@ -29,6 +28,9 @@ import {
statementsUseInt64,
statementsUseThrift,
} from '../shared/includes'

import { renderHandlerInterface } from '../shared/service'

import { renderConst as _renderConst } from './const'
import { renderEnum as _renderEnum } from './enum'
import { renderInt64Import } from './includes'
Expand Down Expand Up @@ -112,7 +114,7 @@ export function renderService(
...renderArgsStruct(statement, state),
...renderResultStruct(statement, state),
renderClient(statement, state),
...renderHandlerInterface(statement, state),
...renderHandlerInterface(statement, typeNodeForFieldType, state),
renderProcessor(statement, state),
]
}
Expand Down
36 changes: 18 additions & 18 deletions src/main/render/apache/service/client.ts
Original file line number Diff line number Diff line change
Expand Up @@ -48,9 +48,9 @@ export function renderClient(
node: ServiceDefinition,
state: IRenderState,
): ts.ClassDeclaration {
// public _seqid: number;
const seqid: ts.PropertyDeclaration = createPublicProperty(
'_seqid',
// public _requestId: number;
const requestId: ts.PropertyDeclaration = createPublicProperty(
'_requestId',
createNumberType(),
)

Expand All @@ -74,7 +74,7 @@ export function renderClient(

/**
* constructor(output: TTransport, protocol: { new (trans: TTransport): TProtocol }) {
* this._seqid = 0;
* this._requestId = 0;
* this._reqs = {};
* }
*/
Expand All @@ -92,7 +92,7 @@ export function renderClient(
[
...createSuperCall(node),
createAssignmentStatement(
ts.createIdentifier('this._seqid'),
ts.createIdentifier('this._requestId'),
ts.createLiteral(0),
),
createAssignmentStatement(
Expand All @@ -110,11 +110,11 @@ export function renderClient(
], // body
)

const incrementSeqIdMethod: ts.MethodDeclaration = ts.createMethod(
const incrementRequestIdMethod: ts.MethodDeclaration = ts.createMethod(
undefined,
[ts.createToken(ts.SyntaxKind.PublicKeyword)],
undefined,
'incrementSeqId',
'incrementRequestId',
undefined,
undefined,
[],
Expand All @@ -123,7 +123,7 @@ export function renderClient(
[
ts.createReturn(
ts.createBinary(
ts.createIdentifier('this._seqid'),
ts.createIdentifier('this._requestId'),
ts.SyntaxKind.PlusEqualsToken,
ts.createLiteral(1),
),
Expand Down Expand Up @@ -186,12 +186,12 @@ export function renderClient(
[], // type parameters
heritage, // heritage
[
seqid,
requestId,
reqs,
output,
protocol,
ctor,
incrementSeqIdMethod,
incrementRequestIdMethod,
...baseMethods,
...sendMethods,
...recvMethods,
Expand Down Expand Up @@ -219,7 +219,7 @@ function createSuperCall(node: ServiceDefinition): Array<ts.Statement> {
}

// public {{name}}( {{#args}}{{fieldName}}: {{fieldType}}, {{/args}} ): Promise<{{typeName}}> {
// this._seqid = this.incrementSeqId()
// this._requestId = this.incrementRequestId()
// return new Promise<{{typeName}}>((resolve, reject) => {
// this._reqs[this.seqid()] = function(error, result) {
// if (error) {
Expand Down Expand Up @@ -248,12 +248,12 @@ function createBaseMethodForDefinition(
createPromiseType(typeNodeForFieldType(def.returnType, state)), // return type
ts.createBlock(
[
// this._seqid = this.incrementSeqId()
// this._requestId = this.incrementRequestId()
createConstStatement(
COMMON_IDENTIFIERS.requestId,
createNumberType(),
ts.createCall(
ts.createIdentifier('this.incrementSeqId'),
ts.createIdentifier('this.incrementRequestId'),
undefined,
[],
),
Expand Down Expand Up @@ -289,7 +289,7 @@ function createBaseMethodForDefinition(
undefined,
ts.createBlock(
[
// delete this._reqs[_seqid]
// delete this._reqs[_requestId]
ts.createStatement(
ts.createDelete(
ts.createElementAccess(
Expand Down Expand Up @@ -417,7 +417,7 @@ function createSendMethodForDefinition(
// output.writeMessageBegin("{{name}}", Thrift.MessageType.CALL, this.seqid())
createMethodCallStatement(
COMMON_IDENTIFIERS.output,
'writeMessageBegin',
COMMON_IDENTIFIERS.writeMessageBegin,
[
ts.createLiteral(def.name.value),
MESSAGE_TYPE.CALL,
Expand Down Expand Up @@ -447,7 +447,7 @@ function createSendMethodForDefinition(
// output.writeMessageEnd()
createMethodCallStatement(
COMMON_IDENTIFIERS.output,
'writeMessageEnd',
COMMON_IDENTIFIERS.writeMessageEnd,
),
// return this.output.flush()
ts.createStatement(
Expand Down Expand Up @@ -567,7 +567,7 @@ function createRecvMethodForDefinition(
),
createMethodCallStatement(
COMMON_IDENTIFIERS.input,
'readMessageEnd',
COMMON_IDENTIFIERS.readMessageEnd,
),
ts.createReturn(
ts.createCall(
Expand All @@ -587,7 +587,7 @@ function createRecvMethodForDefinition(
// input.readMessageEnd()
createMethodCallStatement(
COMMON_IDENTIFIERS.input,
'readMessageEnd',
COMMON_IDENTIFIERS.readMessageEnd,
),

createResultHandler(def),
Expand Down
Loading