Skip to content

Commit

Permalink
chore: update CHANGELOG
Browse files Browse the repository at this point in the history
  • Loading branch information
kevin-greene-ck committed Mar 5, 2019
1 parent f52879c commit 446d804
Show file tree
Hide file tree
Showing 2 changed files with 16 additions and 4 deletions.
8 changes: 8 additions & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,14 @@

All notable changes to this project will be documented in this file.

<a name="3.2.2"></a>
# [3.2.2](https://github.com/creditkarma/thrift-typescript/compare/v3.1.1...v3.2.2) (2019-03-05)

### Features

* Add support for strict unions ([30c5d3](https://github.com/creditkarma/thrift-typescript/commit/30c5d3))
* Allow service method returns types as defined by `IHandler` to be loose types ([44e474](https://github.com/creditkarma/thrift-typescript/commit/44e474))

<a name="3.0.2"></a>
# [3.0.2](https://github.com/creditkarma/thrift-typescript/compare/v3.0.1...v3.0.2) (2018-11-26)

Expand Down
12 changes: 8 additions & 4 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -373,7 +373,7 @@ struct Profile {
}
```

There is something of a difference between how we want to handle things in TypeScript and how data is going to be sent over the wire. Because of this when we generate interfaces for these structs we generate two interfaces for each struct, one is an exact representation of the Thrift, the other is something looser that more represents how the data will be worked with in TypeScript.
There is something of a difference between how we want to handle things in TypeScript and how data is going to be sent over the wire. Because of this when we generate interfaces for these structs we generate two interfaces for each struct, one is an exact representation of the Thrift, the other is something looser that more represents how the data will be worked with in the TypeScript application source.

The main difference is that fields marked as `i64` can be represented as either `number` or an `Int64` object and `binary` can be represented as either a `string` or a `Buffer` object.

Expand All @@ -400,7 +400,7 @@ interface IProfileArgs {

The names of loose interfaces just append `Args` onto the end of the interface name. The reason for this is these interfaces will most often be used as arguments in your code.

Where are the loose interfaces used? The loose interfaces can be passed to client methods.
Where are the loose interfaces used? The loose interfaces can be used anywhere you as the application developer are giving data to the generated code, either as the arguments to a client method or the return value of a service handler.

If we had this service:

Expand All @@ -418,14 +418,18 @@ namespace ProfileService {
constructor(connection: thrift.IThriftConnection<Context>) {
// ...
}
getProfileForUser(user: IUserArgs): Promise<Profile> {
getProfileForUser(user: IUserArgs, context?: Context): Promise<Profile> {
// ...
}
}
// Handler, Processor
export interface IHandler<Context> {
getProfileForUser(user: IUser, context: Context): Promise<IProfileArgs>
}
}
```

As you can see from this sketch of generated types when data leave application code and crossed the boundary into the generated code you can pass loose values, when the data comes from generated code it will always be of the strict types.

We can use a `User` object where the `id` is a `number` without having to wrap it in `Int64`. These conversions are handled for us, similarly `string` data can be passed to a `binary` field and the conversion to `Buffer` is handled under the hood. This are just convinience interfaces to make handling the Thrift objects in TypeScript a little easier. You will notice service methods always return an object of the more strict interface. Also, the more strict interface can always be passed where the loose interface is expected.

#### Sending Data Over the Wire
Expand Down

0 comments on commit 446d804

Please sign in to comment.