@dipscope/type-manager 4.0.0 → 4.0.3
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/CHANGELOG.md +29 -0
- package/README.md +28 -22
- package/core/fn.d.ts +11 -11
- package/core/generic-argument.d.ts +1 -1
- package/core/generic-metadata.d.ts +1 -1
- package/core/index.d.ts +1 -0
- package/core/index.js +2 -2
- package/core/log.d.ts +6 -6
- package/core/metadata.d.ts +3 -3
- package/core/property-metadata.d.ts +24 -4
- package/core/property-options.d.ts +2 -2
- package/core/serializer-context-options.d.ts +4 -4
- package/core/serializer-context.d.ts +6 -6
- package/core/type-ctor.d.ts +1 -1
- package/core/type-metadata-symbol.d.ts +6 -0
- package/core/type-metadata.d.ts +12 -4
- package/core/type-options.d.ts +2 -2
- package/factories/index.d.ts +1 -1
- package/factories/index.js +2 -2
- package/factories/{type.factory.d.ts → type-factory.d.ts} +0 -0
- package/index.js +2 -2
- package/injectors/index.d.ts +1 -1
- package/injectors/index.js +2 -2
- package/injectors/{singleton.injector.d.ts → singleton-injector.d.ts} +0 -0
- package/naming-conventions/{camel-case.naming-convention.d.ts → camel-case-naming-convention.d.ts} +1 -1
- package/naming-conventions/{flat-case.naming-convention.d.ts → flat-case-naming-convention.d.ts} +1 -1
- package/naming-conventions/{flat-upper-case.naming-convention.d.ts → flat-upper-case-naming-convention.d.ts} +1 -1
- package/naming-conventions/index.d.ts +8 -8
- package/naming-conventions/index.js +2 -2
- package/naming-conventions/{kebab-case.naming-convention.d.ts → kebab-case-naming-convention.d.ts} +1 -1
- package/naming-conventions/{kebab-upper-case.naming-convention.d.ts → kebab-upper-case-naming-convention.d.ts} +1 -1
- package/naming-conventions/{pascal-case.naming-convention.d.ts → pascal-case-naming-convention.d.ts} +1 -1
- package/naming-conventions/{snake-case.naming-convention.d.ts → snake-case-naming-convention.d.ts} +1 -1
- package/naming-conventions/{snake-upper-case.naming-convention.d.ts → snake-upper-case-naming-convention.d.ts} +1 -1
- package/package.json +1 -1
- package/property.d.ts +3 -3
- package/reference-handlers/{direct.reference-handler.d.ts → direct-reference-handler.d.ts} +0 -0
- package/reference-handlers/index.d.ts +3 -3
- package/reference-handlers/index.js +2 -2
- package/reference-handlers/{lead.reference-handler.d.ts → lead-reference-handler.d.ts} +0 -0
- package/reference-handlers/{path.reference-handler.d.ts → path-reference-handler.d.ts} +22 -6
- package/serializers/{array-buffer.serializer.d.ts → array-buffer-serializer.d.ts} +0 -0
- package/serializers/{array.serializer.d.ts → array-serializer.d.ts} +0 -0
- package/serializers/{boolean.serializer.d.ts → boolean-serializer.d.ts} +0 -0
- package/serializers/{data-view.serializer.d.ts → data-view-serializer.d.ts} +0 -0
- package/serializers/{date.serializer.d.ts → date-serializer.d.ts} +0 -0
- package/serializers/{float-32-array.serializer.d.ts → float-32-array-serializer.d.ts} +0 -0
- package/serializers/{float-64-array.serializer.d.ts → float-64-array-serializer.d.ts} +0 -0
- package/serializers/index.d.ts +19 -19
- package/serializers/index.js +2 -2
- package/serializers/{int-16-array.serializer.d.ts → int-16-array-serializer.d.ts} +0 -0
- package/serializers/{int-32-array.serializer.d.ts → int-32-array-serializer.d.ts} +0 -0
- package/serializers/{int-8-array.serializer.d.ts → int-8-array-serializer.d.ts} +0 -0
- package/serializers/{map.serializer.d.ts → map-serializer.d.ts} +0 -0
- package/serializers/{number.serializer.d.ts → number-serializer.d.ts} +0 -0
- package/serializers/{set.serializer.d.ts → set-serializer.d.ts} +0 -0
- package/serializers/{string.serializer.d.ts → string-serializer.d.ts} +0 -0
- package/serializers/{type.serializer.d.ts → type-serializer.d.ts} +0 -0
- package/serializers/{uint-16-array.serializer.d.ts → uint-16-array-serializer.d.ts} +0 -0
- package/serializers/{uint-32-array.serializer.d.ts → uint-32-array-serializer.d.ts} +0 -0
- package/serializers/{uint-8-array.serializer.d.ts → uint-8-array-serializer.d.ts} +0 -0
- package/serializers/{uint-8-clamped-array.serializer.d.ts → uint-8-clamped-array-serializer.d.ts} +0 -0
- package/type-manager.d.ts +10 -16
package/CHANGELOG.md
CHANGED
|
@@ -5,6 +5,35 @@ All notable changes to this project will be documented in this file.
|
|
|
5
5
|
The format is based on [Keep a Changelog](https://keepachangelog.com/en/1.0.0/),
|
|
6
6
|
and this project adheres to [Semantic Versioning](https://semver.org/spec/v2.0.0.html).
|
|
7
7
|
|
|
8
|
+
## [4.0.3] - 2022-05-07
|
|
9
|
+
|
|
10
|
+
### Added
|
|
11
|
+
|
|
12
|
+
- Getters of serialized and deserialized property names for property metadata.
|
|
13
|
+
|
|
14
|
+
### Removed
|
|
15
|
+
|
|
16
|
+
- Definition logic of serialized and deserialized property names from type serializer.
|
|
17
|
+
|
|
18
|
+
### Fixed
|
|
19
|
+
|
|
20
|
+
- Serialized property name was displayed in log messages.
|
|
21
|
+
|
|
22
|
+
## [4.0.2] - 2022-05-01
|
|
23
|
+
|
|
24
|
+
### Changed
|
|
25
|
+
|
|
26
|
+
- Used symbol instead of string based key to store type metadata.
|
|
27
|
+
- Avoid complete reset of custom data by providing `null` as argument.
|
|
28
|
+
- Code style improvements.
|
|
29
|
+
|
|
30
|
+
## [4.0.1] - 2021-08-01
|
|
31
|
+
|
|
32
|
+
### Changed
|
|
33
|
+
|
|
34
|
+
- Custom data options are now behave like built in configure options.
|
|
35
|
+
- Path reference handler is now using path traversal instead of direct evaluation for resolving references.
|
|
36
|
+
|
|
8
37
|
## [4.0.0] - 2021-03-24
|
|
9
38
|
|
|
10
39
|
### Added
|
package/README.md
CHANGED
|
@@ -4,6 +4,12 @@
|
|
|
4
4
|
|
|
5
5
|
Type manager is a parsing package for `TypeScript` which will help you to transform JSON strings or plain objects into `JavaScript` object instances. It supports [decorators](https://www.typescriptlang.org/docs/handbook/decorators.html) or declarative configuration and allows you to configure parsing of your or 3rd party classes easily.
|
|
6
6
|
|
|
7
|
+
We recommend to use our [official website](https://dipscope.com/type-manager/what-issues-it-solves) to navigate through available features. You can also use the latest documentation described below.
|
|
8
|
+
|
|
9
|
+
## Give a star :star:
|
|
10
|
+
|
|
11
|
+
If you like or are using this project please give it a star. Thanks!
|
|
12
|
+
|
|
7
13
|
## Table of contents
|
|
8
14
|
|
|
9
15
|
* [What issues it solves?](#what-issues-it-solves)
|
|
@@ -94,7 +100,7 @@ export class User
|
|
|
94
100
|
|
|
95
101
|
public constructor(id: number, name: string)
|
|
96
102
|
{
|
|
97
|
-
this.id
|
|
103
|
+
this.id = id;
|
|
98
104
|
this.name = name;
|
|
99
105
|
|
|
100
106
|
return;
|
|
@@ -197,7 +203,7 @@ export class User
|
|
|
197
203
|
|
|
198
204
|
TypeManager.configureTypeOptions(User, {
|
|
199
205
|
propertyOptionsMap: new Map<PropertyName, PropertyOptions<any>>([
|
|
200
|
-
['name',
|
|
206
|
+
['name', { typeArgument: String }],
|
|
201
207
|
['email', { typeArgument: String }],
|
|
202
208
|
])
|
|
203
209
|
});
|
|
@@ -211,7 +217,7 @@ No matter what style of configuration you have chosen the next step is to call s
|
|
|
211
217
|
import { TypeManager } from '@dipscope/type-manager';
|
|
212
218
|
|
|
213
219
|
const userObject = TypeManager.serialize(User, new User());
|
|
214
|
-
const user
|
|
220
|
+
const user = TypeManager.deserialize(User, userObject);
|
|
215
221
|
|
|
216
222
|
user instanceof User; // True.
|
|
217
223
|
```
|
|
@@ -222,7 +228,7 @@ Calling serialize creates a plain object and deserialize creates an instance of
|
|
|
222
228
|
import { TypeManager } from '@dipscope/type-manager';
|
|
223
229
|
|
|
224
230
|
const userJson = TypeManager.stringify(User, new User());
|
|
225
|
-
const user
|
|
231
|
+
const user = TypeManager.parse(User, userJson);
|
|
226
232
|
|
|
227
233
|
user instanceof User; // True.
|
|
228
234
|
```
|
|
@@ -235,8 +241,8 @@ Static functions are not the only way to work with a `TypeManager`. You can also
|
|
|
235
241
|
import { TypeManager } from '@dipscope/type-manager';
|
|
236
242
|
|
|
237
243
|
const userManager = new TypeManager(User);
|
|
238
|
-
const userObject
|
|
239
|
-
const user
|
|
244
|
+
const userObject = userManager.serialize(new User());
|
|
245
|
+
const user = userManager.deserialize(userObject);
|
|
240
246
|
|
|
241
247
|
user instanceof User; // True.
|
|
242
248
|
```
|
|
@@ -515,9 +521,9 @@ export enum UserPriorityNumeric
|
|
|
515
521
|
|
|
516
522
|
export enum UserPriorityTextual
|
|
517
523
|
{
|
|
518
|
-
Low
|
|
524
|
+
Low = 'Low',
|
|
519
525
|
Medium = 'Medium',
|
|
520
|
-
High
|
|
526
|
+
High = 'High'
|
|
521
527
|
}
|
|
522
528
|
|
|
523
529
|
@Type()
|
|
@@ -542,9 +548,9 @@ export enum UserPriorityNumeric
|
|
|
542
548
|
|
|
543
549
|
export enum UserPriorityTextual
|
|
544
550
|
{
|
|
545
|
-
Low
|
|
551
|
+
Low = 'Low',
|
|
546
552
|
Medium = 'Medium',
|
|
547
|
-
High
|
|
553
|
+
High = 'High'
|
|
548
554
|
}
|
|
549
555
|
|
|
550
556
|
@Type()
|
|
@@ -1317,7 +1323,7 @@ It uses 2 special configurable type options:
|
|
|
1317
1323
|
|
|
1318
1324
|
This options have default values if you have not configured them explicitly.
|
|
1319
1325
|
|
|
1320
|
-
* Default value of discriminator is a
|
|
1326
|
+
* Default value of discriminator is a `$type`. During deserialization `TypeManager` expects such property to be present inside a polymorphic object.
|
|
1321
1327
|
* Default value of discriminant is a `ClassName` which determined based on the type function.
|
|
1322
1328
|
|
|
1323
1329
|
For proper deserialization of polymorphic types you have to provide such information inside your JSON.
|
|
@@ -1326,18 +1332,18 @@ For proper deserialization of polymorphic types you have to provide such informa
|
|
|
1326
1332
|
{
|
|
1327
1333
|
"shapes": [
|
|
1328
1334
|
{
|
|
1329
|
-
"
|
|
1335
|
+
"$type": "Rectangle",
|
|
1330
1336
|
"title": "Cool rectangle",
|
|
1331
1337
|
"width": 10,
|
|
1332
1338
|
"height": 10
|
|
1333
1339
|
},
|
|
1334
1340
|
{
|
|
1335
|
-
"
|
|
1341
|
+
"$type": "Square",
|
|
1336
1342
|
"title": "Perfect square",
|
|
1337
1343
|
"width": 10
|
|
1338
1344
|
},
|
|
1339
1345
|
{
|
|
1340
|
-
"
|
|
1346
|
+
"$type": "Circle",
|
|
1341
1347
|
"title": "Simple circle",
|
|
1342
1348
|
"radius": 6
|
|
1343
1349
|
}
|
|
@@ -1347,7 +1353,7 @@ For proper deserialization of polymorphic types you have to provide such informa
|
|
|
1347
1353
|
|
|
1348
1354
|
Now your JSON will be handled properly and you will get `Rectangle`, `Square` and `Circle` class instances in return.
|
|
1349
1355
|
|
|
1350
|
-
In
|
|
1356
|
+
In some cases your `Discriminator` or `Discriminant` values will not match to our default ones. For example library like [Json.NET](https://www.newtonsoft.com/json) can be used on the backend side to send a response from your API. It uses `$type` property as `Discriminator` and full name of class as `Discriminant`. In such scenario our JSON may look like this.
|
|
1351
1357
|
|
|
1352
1358
|
```json
|
|
1353
1359
|
{
|
|
@@ -1379,7 +1385,7 @@ import { TypeManagerOptions } from '@dipscope/type-manager';
|
|
|
1379
1385
|
import { TypeOptionsBase } from '@dipscope/type-manager/core';
|
|
1380
1386
|
|
|
1381
1387
|
const typeOptionsBase: TypeOptionsBase<any> = {
|
|
1382
|
-
discriminator: '$
|
|
1388
|
+
discriminator: '$customType'
|
|
1383
1389
|
};
|
|
1384
1390
|
|
|
1385
1391
|
const typeManagerOptions: TypeManagerOptions = {
|
|
@@ -1608,7 +1614,7 @@ Somewhere in code you have such a logic:
|
|
|
1608
1614
|
```typescript
|
|
1609
1615
|
import { TypeManager } from '@dipscope/type-manager';
|
|
1610
1616
|
|
|
1611
|
-
const user
|
|
1617
|
+
const user = new User();
|
|
1612
1618
|
const company = new Company();
|
|
1613
1619
|
|
|
1614
1620
|
user.company = company;
|
|
@@ -1675,7 +1681,7 @@ This allows you to get it later in serializers, factories, injectors or your cod
|
|
|
1675
1681
|
import { TypeManager } from '@dipscope/type-manager';
|
|
1676
1682
|
|
|
1677
1683
|
const userMetadata = TypeManager.extractTypeMetadata(User);
|
|
1678
|
-
const customData
|
|
1684
|
+
const customData = userMetadata.customData;
|
|
1679
1685
|
|
|
1680
1686
|
// Do something with type custom data...
|
|
1681
1687
|
|
|
@@ -1836,7 +1842,7 @@ export class CustomTypeFactory extends TypeFactory
|
|
|
1836
1842
|
|
|
1837
1843
|
// Resolve custom data.
|
|
1838
1844
|
const typeMetadata = typeContext.typeMetadata;
|
|
1839
|
-
const customData
|
|
1845
|
+
const customData = typeMetadata.customData;
|
|
1840
1846
|
|
|
1841
1847
|
// Process custom data.
|
|
1842
1848
|
for (const propertyName in customData)
|
|
@@ -1988,11 +1994,11 @@ Polymorphic types are supported. In most cases additional configuration is requi
|
|
|
1988
1994
|
|
|
1989
1995
|
See information about breaking changes, release notes and migration steps between versions [here](https://github.com/dipscope/TypeManager.TS/blob/master/CHANGELOG.md).
|
|
1990
1996
|
|
|
1991
|
-
Thanks for checking this package.
|
|
1997
|
+
Thanks for checking this package.
|
|
1992
1998
|
|
|
1993
|
-
|
|
1999
|
+
Feel free to create an issue if you find any mistakes in documentation or have any improvements in mind.
|
|
1994
2000
|
|
|
1995
|
-
|
|
2001
|
+
We wish you good luck and happy coding!
|
|
1996
2002
|
|
|
1997
2003
|
## License
|
|
1998
2004
|
|
package/core/fn.d.ts
CHANGED
|
@@ -51,7 +51,7 @@ export declare class Fn {
|
|
|
51
51
|
*
|
|
52
52
|
* @returns {boolean} True when value is function. False otherwise.
|
|
53
53
|
*/
|
|
54
|
-
static isFunction(x: any): x is (...args: any
|
|
54
|
+
static isFunction(x: any): x is (...args: Array<any>) => any;
|
|
55
55
|
/**
|
|
56
56
|
* Checks if value is an arrow function.
|
|
57
57
|
*
|
|
@@ -59,7 +59,7 @@ export declare class Fn {
|
|
|
59
59
|
*
|
|
60
60
|
* @returns {boolean} True when value is an arrow function. False otherwise.
|
|
61
61
|
*/
|
|
62
|
-
static isArrowFunction(x: any): x is (...args: any
|
|
62
|
+
static isArrowFunction(x: any): x is (...args: Array<any>) => any;
|
|
63
63
|
/**
|
|
64
64
|
* Checks if value is a constructor.
|
|
65
65
|
*
|
|
@@ -67,7 +67,7 @@ export declare class Fn {
|
|
|
67
67
|
*
|
|
68
68
|
* @returns {boolean} True when value is a constructor. False otherwise.
|
|
69
69
|
*/
|
|
70
|
-
static isCtor(x: any): x is new (...args: any
|
|
70
|
+
static isCtor(x: any): x is new (...args: Array<any>) => any;
|
|
71
71
|
/**
|
|
72
72
|
* Checks if value is string.
|
|
73
73
|
*
|
|
@@ -107,7 +107,7 @@ export declare class Fn {
|
|
|
107
107
|
*
|
|
108
108
|
* @returns {boolean} True when value is array. False otherwise.
|
|
109
109
|
*/
|
|
110
|
-
static isArray(x: any): x is any
|
|
110
|
+
static isArray(x: any): x is Array<any>;
|
|
111
111
|
/**
|
|
112
112
|
* Checks if value is date.
|
|
113
113
|
*
|
|
@@ -248,7 +248,7 @@ export declare class Fn {
|
|
|
248
248
|
* Performs deep assignment and returns target object.
|
|
249
249
|
*
|
|
250
250
|
* @param {Record<string, any>} target Target object.
|
|
251
|
-
* @param {Record<string, any
|
|
251
|
+
* @param {Array<Record<string, any>>} sources Source objects.
|
|
252
252
|
*
|
|
253
253
|
* @returns {Record<string, any>} Target object.
|
|
254
254
|
*/
|
|
@@ -268,25 +268,25 @@ export declare class Fn {
|
|
|
268
268
|
*
|
|
269
269
|
* @param {string} x String.
|
|
270
270
|
*
|
|
271
|
-
* @returns {string
|
|
271
|
+
* @returns {Array<string>} Array with the words of provided string.
|
|
272
272
|
*/
|
|
273
|
-
static unicodeWords(x: string): string
|
|
273
|
+
static unicodeWords(x: string): Array<string>;
|
|
274
274
|
/**
|
|
275
275
|
* Splits a ASCII string into an array of its words.
|
|
276
276
|
*
|
|
277
277
|
* @param {string} x String.
|
|
278
278
|
*
|
|
279
|
-
* @returns {string
|
|
279
|
+
* @returns {Array<string>} Array with the words of provided string.
|
|
280
280
|
*/
|
|
281
|
-
static asciiWords(x: string): string
|
|
281
|
+
static asciiWords(x: string): Array<string>;
|
|
282
282
|
/**
|
|
283
283
|
* Splits string into an array of its words.
|
|
284
284
|
*
|
|
285
285
|
* @param {string} x String.
|
|
286
286
|
*
|
|
287
|
-
* @returns {string
|
|
287
|
+
* @returns {Array<string>} Array with the words of provided string.
|
|
288
288
|
*/
|
|
289
|
-
static words(x: string): string
|
|
289
|
+
static words(x: string): Array<string>;
|
|
290
290
|
/**
|
|
291
291
|
* Checks if reflect metadata is supported.
|
|
292
292
|
*
|
|
@@ -4,4 +4,4 @@ import { TypeArgument } from './type-argument';
|
|
|
4
4
|
*
|
|
5
5
|
* @type {GenericArgument<TType>}
|
|
6
6
|
*/
|
|
7
|
-
export declare type GenericArgument<TType> = TypeArgument<TType> | [TypeArgument<TType>, GenericArgument<any
|
|
7
|
+
export declare type GenericArgument<TType> = TypeArgument<TType> | [TypeArgument<TType>, Array<GenericArgument<any>>];
|
|
@@ -4,4 +4,4 @@ import { TypeMetadata } from './type-metadata';
|
|
|
4
4
|
*
|
|
5
5
|
* @type {GenericMetadata<TType>}
|
|
6
6
|
*/
|
|
7
|
-
export declare type GenericMetadata<TType> = [TypeMetadata<TType>, GenericMetadata<any
|
|
7
|
+
export declare type GenericMetadata<TType> = [TypeMetadata<TType>, Array<GenericMetadata<any>>];
|
package/core/index.d.ts
CHANGED
|
@@ -34,6 +34,7 @@ export * from './type-ctor';
|
|
|
34
34
|
export * from './type-fn';
|
|
35
35
|
export * from './type-like';
|
|
36
36
|
export * from './type-metadata-resolver';
|
|
37
|
+
export * from './type-metadata-symbol';
|
|
37
38
|
export * from './type-metadata';
|
|
38
39
|
export * from './type-name';
|
|
39
40
|
export * from './type-options-base';
|