Skip to content

Commit ab093a3

Browse files
merge: release 0.4.0 (#593)
2 parents 16a0506 + a101300 commit ab093a3

17 files changed

+1655
-2326
lines changed

.github/dependabot.yml

+3-1
Original file line numberDiff line numberDiff line change
@@ -10,4 +10,6 @@ updates:
1010
versioning-strategy: increase
1111
commit-message:
1212
prefix: build
13-
include: scope
13+
include: scope
14+
ignore:
15+
- dependency-name: "husky"
Original file line numberDiff line numberDiff line change
@@ -1,11 +1,23 @@
1-
name: Auto approve PRs
1+
name: Dependabot auto-merge
22
on:
33
pull_request
44
jobs:
55
dependabot:
66
runs-on: ubuntu-latest
7+
if: github.actor == 'dependabot[bot]'
78
steps:
8-
- uses: hmarr/auto-approve[email protected]
9-
if: github.actor == 'dependabot[bot]'
9+
- name: 'Auto approve PR by Dependabot'
10+
uses: hmarr/[email protected]
1011
with:
11-
github-token: "${{ secrets.GITHUB_TOKEN }}"
12+
github-token: "${{ secrets.TYPESTACK_BOT_TOKEN }}"
13+
- name: 'Comment merge command'
14+
uses: actions/github-script@v3
15+
with:
16+
github-token: ${{secrets.TYPESTACK_BOT_TOKEN }}
17+
script: |
18+
await github.issues.createComment({
19+
owner: context.repo.owner,
20+
repo: context.repo.repo,
21+
issue_number: context.issue.number,
22+
body: '@dependabot squash and merge'
23+
})

CHANGELOG.md

+41-1
Original file line numberDiff line numberDiff line change
@@ -2,7 +2,45 @@
22

33
_This changelog follows the [keep a changelog][keep-a-changelog]_ format to maintain a human readable changelog.
44

5-
### [0.3.2][v0.3.2] - 2021-01-14
5+
### [0.4.0][v0.4.0] [BREAKING CHANGE] - 2021-02-14
6+
7+
#### Breaking Changes
8+
9+
See the breaking changes from `0.3.2` release. It was accidentally released as patch version.
10+
11+
#### Added
12+
13+
- add option to ignore unset properties
14+
- `group` information is exposed in the `@Transform` handler
15+
- transformation options are exposed in the `@Transform` handler
16+
17+
#### Fixed
18+
19+
- fixed TypeError when `discriminator.subTypes` is not defined
20+
21+
#### Changed
22+
23+
- various dev-dependencies has been updated
24+
25+
### [0.3.2][v0.3.2] [BREAKING CHANGE] - 2021-01-14
26+
27+
#### Breaking Changes
28+
29+
**Signature change for `@Transform` decorator**
30+
From this version the `@Transform` decorator receives the transformation parameters in a a wrapper object. You need to
31+
destructure the values you are interested in.
32+
33+
Old way:
34+
35+
```ts
36+
@Transform((value, obj, type) => /* Do some stuff with value here. */)
37+
```
38+
39+
New way with wrapper object:
40+
41+
```ts
42+
@Transform(({ value, key, obj, type }) => /* Do some stuff with value here. */)
43+
```
644

745
#### Added
846

@@ -161,6 +199,8 @@ This version has introduced a breaking-change when this library is used with cla
161199
- Library has changed its name from `serializer.ts` to `constructor-utils`.
162200
- Added `constructor-utils` namespace.
163201

202+
[v0.4.0]: https://github.com/typestack/class-transformer/compare/v0.3.2...v0.4.0
203+
[v0.3.2]: https://github.com/typestack/class-transformer/compare/v0.3.1...v0.3.2
164204
[v0.3.1]: https://github.com/typestack/class-transformer/compare/v0.2.3...v0.3.1
165205
[v0.2.3]: https://github.com/typestack/class-transformer/compare/v0.2.2...v0.2.3
166206
[v0.2.2]: https://github.com/typestack/class-transformer/compare/v0.2.1...v0.2.2

README.md

+29-27
Original file line numberDiff line numberDiff line change
@@ -4,7 +4,7 @@
44
[![codecov](https://codecov.io/gh/typestack/class-transformer/branch/develop/graph/badge.svg)](https://codecov.io/gh/typestack/class-transformer)
55
[![npm version](https://badge.fury.io/js/class-transformer.svg)](https://badge.fury.io/js/class-transformer)
66

7-
Its ES6 and Typescript era. Nowadays you are working with classes and constructor objects more then ever.
7+
Its ES6 and Typescript era. Nowadays you are working with classes and constructor objects more than ever.
88
Class-transformer allows you to transform plain object to some instance of class and versa.
99
Also it allows to serialize / deserialize object based on criteria.
1010
This tool is super useful on both frontend and backend.
@@ -131,17 +131,17 @@ So what to do? How to make a `users` array of instances of `User` objects instea
131131
Solution is to create new instances of User object and manually copy all properties to new objects.
132132
But things may go wrong very fast once you have a more complex object hierarchy.
133133

134-
Alternatives? Yes, you can use class-transformer. Purpose of this library is to help you to map you plain javascript
134+
Alternatives? Yes, you can use class-transformer. Purpose of this library is to help you to map your plain javascript
135135
objects to the instances of classes you have.
136136

137137
This library also great for models exposed in your APIs,
138138
because it provides a great tooling to control what your models are exposing in your API.
139-
Here is example how it will look like:
139+
Here is an example how it will look like:
140140

141141
```typescript
142142
fetch('users.json').then((users: Object[]) => {
143143
const realUsers = plainToClass(User, users);
144-
// now each user in realUsers is instance of User class
144+
// now each user in realUsers is an instance of User class
145145
});
146146
```
147147

@@ -226,7 +226,7 @@ let users = plainToClass(User, userJson); // to convert user plain object a sing
226226

227227
### plainToClassFromExist[](#table-of-contents)
228228

229-
This method transforms a plain object into a instance using a already filled Object which is a instance from the target class.
229+
This method transforms a plain object into an instance using an already filled Object which is an instance of the target class.
230230

231231
```typescript
232232
const defaultUser = new User();
@@ -246,19 +246,19 @@ let photo = classToPlain(photo);
246246

247247
### classToClass[](#table-of-contents)
248248

249-
This method transforms your class object into new instance of the class object.
250-
This maybe treated as deep clone of your objects.
249+
This method transforms your class object into a new instance of the class object.
250+
This may be treated as deep clone of your objects.
251251

252252
```typescript
253253
import { classToClass } from 'class-transformer';
254254
let photo = classToClass(photo);
255255
```
256256

257-
You can also use a `ignoreDecorators` option in transformation options to ignore all decorators you classes is using.
257+
You can also use an `ignoreDecorators` option in transformation options to ignore all decorators you classes is using.
258258

259259
### serialize[](#table-of-contents)
260260

261-
You can serialize your model right to the json using `serialize` method:
261+
You can serialize your model right to json using `serialize` method:
262262

263263
```typescript
264264
import { serialize } from 'class-transformer';
@@ -269,14 +269,14 @@ let photo = serialize(photo);
269269

270270
### deserialize and deserializeArray[](#table-of-contents)
271271

272-
You can deserialize your model to from a json using `deserialize` method:
272+
You can deserialize your model from json using the `deserialize` method:
273273

274274
```typescript
275275
import { deserialize } from 'class-transformer';
276276
let photo = deserialize(Photo, photo);
277277
```
278278

279-
To make deserialization to work with arrays use `deserializeArray` method:
279+
To make deserialization work with arrays, use the `deserializeArray` method:
280280

281281
```typescript
282282
import { deserializeArray } from 'class-transformer';
@@ -342,7 +342,7 @@ console.log(plainToClass(User, fromPlainUser, { excludeExtraneousValues: true })
342342
## Working with nested objects[](#table-of-contents)
343343

344344
When you are trying to transform objects that have nested objects,
345-
its required to known what type of object you are trying to transform.
345+
it's required to known what type of object you are trying to transform.
346346
Since Typescript does not have good reflection abilities yet,
347347
we should implicitly specify what type of object each property contain.
348348
This is done using `@Type` decorator.
@@ -374,8 +374,8 @@ let album = plainToClass(Album, albumJson);
374374
### Providing more than one type option[](#table-of-contents)
375375

376376
In case the nested object can be of different types, you can provide an additional options object,
377-
that specifies a discriminator. The discriminator option must define a `property` that holds the sub
378-
type name for the object and the possible `subTypes`, the nested object can converted to. A sub type
377+
that specifies a discriminator. The discriminator option must define a `property` that holds the subtype
378+
name for the object and the possible `subTypes` that the nested object can converted to. A sub type
379379
has a `value`, that holds the constructor of the Type and the `name`, that can match with the `property`
380380
of the discriminator.
381381

@@ -444,7 +444,7 @@ in the options to keep the discriminator property also inside your resulting cla
444444

445445
## Exposing getters and method return values[](#table-of-contents)
446446

447-
You can expose what your getter or method return by setting a `@Expose()` decorator to those getters or methods:
447+
You can expose what your getter or method return by setting an `@Expose()` decorator to those getters or methods:
448448

449449
```typescript
450450
import { Expose } from 'class-transformer';
@@ -469,8 +469,8 @@ export class User {
469469

470470
## Exposing properties with different names[](#table-of-contents)
471471

472-
If you want to expose some of properties with a different name,
473-
you can do it by specifying a `name` option to `@Expose` decorator:
472+
If you want to expose some of the properties with a different name,
473+
you can do that by specifying a `name` option to `@Expose` decorator:
474474

475475
```typescript
476476
import { Expose } from 'class-transformer';
@@ -511,7 +511,7 @@ export class User {
511511
}
512512
```
513513

514-
Now when you transform a User, `password` property will be skipped and not be included in the transformed result.
514+
Now when you transform a User, the `password` property will be skipped and not be included in the transformed result.
515515

516516
## Skipping depend of operation[](#table-of-contents)
517517

@@ -530,7 +530,7 @@ export class User {
530530
}
531531
```
532532

533-
Now `password` property will be excluded only during `classToPlain` operation. Oppositely, use `toClassOnly` option.
533+
Now `password` property will be excluded only during `classToPlain` operation. Vice versa, use the `toClassOnly` option.
534534

535535
## Skipping all properties of the class[](#table-of-contents)
536536

@@ -760,7 +760,7 @@ export class Photo {
760760
id: number;
761761

762762
@Type(() => Date)
763-
@Transform(value => moment(value), { toClassOnly: true })
763+
@Transform(({ value }) => moment(value), { toClassOnly: true })
764764
date: Moment;
765765
}
766766
```
@@ -773,15 +773,17 @@ it will convert a date value in your photo object to moment date.
773773

774774
The `@Transform` decorator is given more arguments to let you configure how you want the transformation to be done.
775775

776-
```
777-
@Transform((value, obj, type) => value)
776+
```ts
777+
@Transform(({ value, key, obj, type }) => value)
778778
```
779779

780-
| Argument | Description |
781-
| -------- | --------------------------------------------- |
782-
| `value` | The property value before the transformation. |
783-
| `obj` | The transformation source object. |
784-
| `type` | The transformation type. |
780+
| Argument | Description |
781+
| --------- | ------------------------------------------------------- |
782+
| `value` | The property value before the transformation. |
783+
| `key` | The name of the transformed property. |
784+
| `obj` | The transformation source object. |
785+
| `type` | The transformation type. |
786+
| `options` | The options object passed to the transformation method. |
785787

786788
## Other decorators[](#table-of-contents)
787789

jest.config.js

+1-1
Original file line numberDiff line numberDiff line change
@@ -4,7 +4,7 @@ module.exports = {
44
collectCoverageFrom: ['src/**/*.ts', '!src/**/index.ts', '!src/**/*.interface.ts'],
55
globals: {
66
'ts-jest': {
7-
tsConfig: 'tsconfig.spec.json',
7+
tsconfig: 'tsconfig.spec.json',
88
},
99
},
1010
};

0 commit comments

Comments
 (0)