@tsed/json-mapper 7.34.5 → 7.35.0-beta.2

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.
Files changed (50) hide show
  1. package/jest.config.js +2 -2
  2. package/lib/browser/json-mapper.umd.min.js +1 -1
  3. package/lib/browser/json-mapper.umd.min.js.map +1 -1
  4. package/lib/cjs/components/DateMapper.js +1 -1
  5. package/lib/cjs/components/DateMapper.js.map +1 -1
  6. package/lib/cjs/domain/JsonMapperCompiler.js +158 -0
  7. package/lib/cjs/domain/JsonMapperCompiler.js.map +1 -0
  8. package/lib/cjs/domain/JsonSerializer.js +218 -0
  9. package/lib/cjs/domain/JsonSerializer.js.map +1 -0
  10. package/lib/cjs/domain/JsonSerializerOptions.js +3 -0
  11. package/lib/cjs/domain/JsonSerializerOptions.js.map +1 -0
  12. package/lib/cjs/domain/Writer.js +111 -0
  13. package/lib/cjs/domain/Writer.js.map +1 -0
  14. package/lib/cjs/hooks/alterOnSerialize.js +8 -0
  15. package/lib/cjs/hooks/alterOnSerialize.js.map +1 -0
  16. package/lib/cjs/index.js +6 -0
  17. package/lib/cjs/index.js.map +1 -1
  18. package/lib/cjs/utils/getObjectProperties.js +9 -0
  19. package/lib/cjs/utils/getObjectProperties.js.map +1 -0
  20. package/lib/cjs/utils/serialize.js +5 -143
  21. package/lib/cjs/utils/serialize.js.map +1 -1
  22. package/lib/esm/components/DateMapper.js +1 -1
  23. package/lib/esm/components/DateMapper.js.map +1 -1
  24. package/lib/esm/domain/JsonMapperCompiler.js +154 -0
  25. package/lib/esm/domain/JsonMapperCompiler.js.map +1 -0
  26. package/lib/esm/domain/JsonSerializer.js +214 -0
  27. package/lib/esm/domain/JsonSerializer.js.map +1 -0
  28. package/lib/esm/domain/JsonSerializerOptions.js +2 -0
  29. package/lib/esm/domain/JsonSerializerOptions.js.map +1 -0
  30. package/lib/esm/domain/Writer.js +108 -0
  31. package/lib/esm/domain/Writer.js.map +1 -0
  32. package/lib/esm/hooks/alterOnSerialize.js +4 -0
  33. package/lib/esm/hooks/alterOnSerialize.js.map +1 -0
  34. package/lib/esm/index.js +6 -0
  35. package/lib/esm/index.js.map +1 -1
  36. package/lib/esm/utils/getObjectProperties.js +5 -0
  37. package/lib/esm/utils/getObjectProperties.js.map +1 -0
  38. package/lib/esm/utils/serialize.js +4 -141
  39. package/lib/esm/utils/serialize.js.map +1 -1
  40. package/lib/tsconfig.esm.tsbuildinfo +1 -1
  41. package/lib/tsconfig.tsbuildinfo +1 -1
  42. package/lib/types/domain/JsonMapperCompiler.d.ts +52 -0
  43. package/lib/types/domain/JsonSerializer.d.ts +20 -0
  44. package/lib/types/domain/JsonSerializerOptions.d.ts +13 -0
  45. package/lib/types/domain/Writer.d.ts +34 -0
  46. package/lib/types/hooks/alterOnSerialize.d.ts +2 -0
  47. package/lib/types/index.d.ts +6 -0
  48. package/lib/types/utils/getObjectProperties.d.ts +1 -0
  49. package/lib/types/utils/serialize.d.ts +2 -18
  50. package/package.json +11 -8
@@ -0,0 +1,52 @@
1
+ import { Type } from "@tsed/core";
2
+ import { JsonSchema } from "@tsed/schema";
3
+ export type JsonMapperCallback<Options> = (input: any, options?: Options) => any;
4
+ export type CachedJsonMapper<Options> = {
5
+ id: string;
6
+ fn: JsonMapperCallback<Options>;
7
+ };
8
+ export type CachedGroupsJsonMapper<Options> = Map<string, CachedJsonMapper<Options>>;
9
+ export declare abstract class JsonMapperCompiler<Options extends Record<string, any> = any> {
10
+ /**
11
+ * Cached mappers metadata
12
+ * @protected
13
+ */
14
+ protected cache: Map<string | Type<any>, CachedGroupsJsonMapper<Options>>;
15
+ /**
16
+ * Cached executable mappers by his id
17
+ * @protected
18
+ */
19
+ protected mappers: Record<string, JsonMapperCallback<Options>>;
20
+ /**
21
+ * Cached schemas
22
+ * @protected
23
+ */
24
+ protected schemes: Record<string, any>;
25
+ /**
26
+ * Global variables available in the mapper
27
+ * @protected
28
+ */
29
+ protected globals: Record<string, any>;
30
+ constructor();
31
+ addTypeMapper(model: Type<any> | string, fn: any): this;
32
+ removeTypeMapper(model: Type<any> | string): void;
33
+ addGlobal(key: string, value: any): this;
34
+ eval(mapper: string, { id, groupsId, model }: {
35
+ id: string;
36
+ model: Type<any>;
37
+ groupsId: string;
38
+ }): CachedJsonMapper<Options>;
39
+ createContext(options: Options): Options & {
40
+ cache: Map<string | Type<any>, CachedGroupsJsonMapper<Options>>;
41
+ };
42
+ compile(model: Type<any>, groups: false | string[]): CachedJsonMapper<Options>;
43
+ protected execMapper(id: string, value: any, options: Options): any;
44
+ protected abstract map(input: any, options: Options): any;
45
+ protected abstract alterValue(schemaId: string, value: any, options: Options): any;
46
+ protected abstract createMapper(model: Type<any>, id: string, groups: false | string[]): string;
47
+ protected getType(model: Type<any>): Type<any> | ArrayConstructor | MapConstructor | SetConstructor | ObjectConstructor;
48
+ protected alterIgnore(id: string, options: Options): any;
49
+ protected alterGroups(schema: JsonSchema, groups: false | string[]): any;
50
+ protected getGroupsId(groups: false | string[]): string;
51
+ protected getId(model: Type<any>, groupsId: string): string;
52
+ }
@@ -0,0 +1,20 @@
1
+ import { Type } from "@tsed/core";
2
+ import { JsonMapperCompiler } from "./JsonMapperCompiler";
3
+ import { JsonSerializerOptions } from "./JsonSerializerOptions";
4
+ export declare class JsonSerializer extends JsonMapperCompiler<JsonSerializerOptions> {
5
+ constructor();
6
+ map(input: any, options?: JsonSerializerOptions): any;
7
+ protected alterValue(schemaId: string, value: any, options: JsonSerializerOptions): any;
8
+ protected createMapper(model: Type<any>, id: string, groups: false | string[]): string;
9
+ private mapOptions;
10
+ private mapProperty;
11
+ private mapPrecondition;
12
+ private mapDiscriminator;
13
+ private mapAdditionalProperties;
14
+ private mapObject;
15
+ private mapSet;
16
+ private mapArray;
17
+ private mapMap;
18
+ private mapItem;
19
+ private mapJSON;
20
+ }
@@ -0,0 +1,13 @@
1
+ import { MetadataTypes, Type } from "@tsed/core";
2
+ import { JsonMapperMethods } from "../interfaces/JsonMapperMethods";
3
+ export interface JsonSerializerOptions<T = any, C = any> extends MetadataTypes<T, C> {
4
+ /**
5
+ * Types used to map complex types (Symbol, Number, String, etc...)
6
+ */
7
+ types?: Map<Type<any> | Symbol | string, JsonMapperMethods>;
8
+ /**
9
+ * useAlias mapping
10
+ */
11
+ useAlias?: boolean;
12
+ [key: string]: any;
13
+ }
@@ -0,0 +1,34 @@
1
+ export declare class Writer {
2
+ static object: {
3
+ assign(...args: string[]): string;
4
+ };
5
+ protected _root?: Writer;
6
+ protected body: (string | Writer)[];
7
+ private _indent;
8
+ constructor(root?: Writer);
9
+ static indent(lines: string[]): string[];
10
+ static mapper(mapperId: string, key: string, options: string): string;
11
+ static mapperFrom(key: string, options: string): string;
12
+ static options(...args: string[]): string;
13
+ add(...lines: (undefined | string | Writer)[]): this;
14
+ arrow(...args: string[]): Writer;
15
+ build(): string[];
16
+ callMapper(id: string, key: string, ...options: string[]): this;
17
+ const(name: string, line: string): this;
18
+ each(iterable: string, args?: string[]): Writer;
19
+ if(condition: string): IfWriter;
20
+ indent(indent: boolean): this;
21
+ new(indent?: boolean): Writer;
22
+ return(line: string): Writer;
23
+ root(): Writer;
24
+ set(left: string, right: string): this;
25
+ toString(): string;
26
+ }
27
+ declare class IfWriter extends Writer {
28
+ protected condition: string;
29
+ protected elseWriter?: Writer;
30
+ constructor(condition: string, root: Writer);
31
+ else(): Writer;
32
+ build(): string[];
33
+ }
34
+ export {};
@@ -0,0 +1,2 @@
1
+ import { JsonHookContext, JsonSchema } from "@tsed/schema";
2
+ export declare function alterOnSerialize(schema: JsonSchema, value: any, options: JsonHookContext): any;
@@ -12,11 +12,17 @@ export * from "./decorators/beforeDeserialize";
12
12
  export * from "./decorators/jsonMapper";
13
13
  export * from "./decorators/onDeserialize";
14
14
  export * from "./decorators/onSerialize";
15
+ export * from "./domain/JsonMapperCompiler";
15
16
  export * from "./domain/JsonMapperContext";
16
17
  export * from "./domain/JsonMapperSettings";
17
18
  export * from "./domain/JsonMapperTypesContainer";
19
+ export * from "./domain/JsonSerializer";
20
+ export * from "./domain/JsonSerializerOptions";
21
+ export * from "./domain/Writer";
18
22
  export * from "./hooks/alterAfterDeserialize";
19
23
  export * from "./hooks/alterBeforeDeserialize";
24
+ export * from "./hooks/alterOnSerialize";
20
25
  export * from "./interfaces/JsonMapperMethods";
21
26
  export * from "./utils/deserialize";
27
+ export * from "./utils/getObjectProperties";
22
28
  export * from "./utils/serialize";
@@ -0,0 +1 @@
1
+ export declare function getObjectProperties(obj: any): [string, any][];
@@ -1,21 +1,5 @@
1
- import { MetadataTypes, Type } from "@tsed/core";
2
- import "../components/ArrayMapper";
3
1
  import "../components/DateMapper";
4
- import "../components/MapMapper";
5
2
  import "../components/PrimitiveMapper";
6
- import "../components/SetMapper";
7
3
  import "../components/SymbolMapper";
8
- import { JsonMapperMethods } from "../interfaces/JsonMapperMethods";
9
- export interface JsonSerializerOptions<T = any, C = any> extends MetadataTypes<T, C> {
10
- /**
11
- * Types used to map complex types (Symbol, Array, Set, Map)
12
- */
13
- types?: Map<Type<any>, JsonMapperMethods>;
14
- /**
15
- * useAlias mapping
16
- */
17
- useAlias?: boolean;
18
- [key: string]: any;
19
- }
20
- export declare function classToPlainObject(obj: any, options: JsonSerializerOptions<any, any>): any;
21
- export declare function serialize(obj: any, { type, collectionType, groups, ...options }?: JsonSerializerOptions): any;
4
+ import { JsonSerializerOptions } from "../domain/JsonSerializerOptions";
5
+ export declare function serialize(input: any, options?: JsonSerializerOptions): any;
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@tsed/json-mapper",
3
- "version": "7.34.5",
3
+ "version": "7.35.0-beta.2",
4
4
  "description": "Json mapper module for Ts.ED Framework",
5
5
  "private": false,
6
6
  "source": "./src/index.ts",
@@ -41,15 +41,15 @@
41
41
  "tslib": "2.5.0"
42
42
  },
43
43
  "devDependencies": {
44
- "@tsed/core": "7.34.5",
45
- "@tsed/eslint": "7.34.5",
46
- "@tsed/schema": "7.34.5",
47
- "@tsed/typescript": "7.34.5",
44
+ "@tsed/core": "7.35.0-beta.2",
45
+ "@tsed/eslint": "7.35.0-beta.2",
46
+ "@tsed/schema": "7.35.0-beta.2",
47
+ "@tsed/typescript": "7.35.0-beta.2",
48
48
  "eslint": "^8.12.0"
49
49
  },
50
50
  "peerDependencies": {
51
- "@tsed/core": "^7.34.5",
52
- "@tsed/schema": "^7.34.5"
51
+ "@tsed/core": "^7.35.0-beta.2",
52
+ "@tsed/schema": "^7.35.0-beta.2"
53
53
  },
54
54
  "peerDependenciesMeta": {
55
55
  "@tsed/core": {
@@ -65,5 +65,8 @@
65
65
  },
66
66
  "homepage": "https://github.com/tsedio/tsed/tree/production/packages/specs/json-mapper",
67
67
  "author": "Romain Lenzotti",
68
- "license": "MIT"
68
+ "license": "MIT",
69
+ "publishConfig": {
70
+ "tag": "beta"
71
+ }
69
72
  }