1 | "use strict";
|
2 | Object.defineProperty(exports, "__esModule", { value: true });
|
3 | exports.TypeDefinitionsStorage = void 0;
|
4 | const tslib_1 = require("tslib");
|
5 | const common_1 = require("@nestjs/common");
|
6 | let TypeDefinitionsStorage = class TypeDefinitionsStorage {
|
7 | constructor() {
|
8 | this.interfaceTypeDefinitions = new Map();
|
9 | this.enumTypeDefinitions = new Map();
|
10 | this.unionTypeDefinitions = new Map();
|
11 | this.objectTypeDefinitions = new Map();
|
12 | this.inputTypeDefinitions = new Map();
|
13 | }
|
14 | addEnums(enumDefs) {
|
15 | enumDefs.forEach((item) => this.enumTypeDefinitions.set(item.enumRef, item));
|
16 | }
|
17 | getEnumByObject(obj) {
|
18 | return this.enumTypeDefinitions.get(obj);
|
19 | }
|
20 | getAllEnumTypeDefinitions() {
|
21 | return Array.from(this.enumTypeDefinitions.values());
|
22 | }
|
23 | addUnions(unionDefs) {
|
24 | unionDefs.forEach((item) => this.unionTypeDefinitions.set(item.id, item));
|
25 | }
|
26 | getUnionBySymbol(key) {
|
27 | return this.unionTypeDefinitions.get(key);
|
28 | }
|
29 | addInterfaces(interfaceDefs) {
|
30 | interfaceDefs.forEach((item) => this.interfaceTypeDefinitions.set(item.target, item));
|
31 | }
|
32 | getInterfaceByTarget(type) {
|
33 | return this.interfaceTypeDefinitions.get(type);
|
34 | }
|
35 | getAllInterfaceDefinitions() {
|
36 | return Array.from(this.interfaceTypeDefinitions.values());
|
37 | }
|
38 | addInputTypes(inputDefs) {
|
39 | inputDefs.forEach((item) => this.inputTypeDefinitions.set(item.target, item));
|
40 | }
|
41 | getInputTypeByTarget(type) {
|
42 | return this.inputTypeDefinitions.get(type);
|
43 | }
|
44 | getAllInputTypeDefinitions() {
|
45 | return Array.from(this.inputTypeDefinitions.values());
|
46 | }
|
47 | addObjectTypes(objectDefs) {
|
48 | objectDefs.forEach((item) => this.objectTypeDefinitions.set(item.target, item));
|
49 | }
|
50 | getObjectTypeByTarget(type) {
|
51 | return this.objectTypeDefinitions.get(type);
|
52 | }
|
53 | getAllObjectTypeDefinitions() {
|
54 | return Array.from(this.objectTypeDefinitions.values());
|
55 | }
|
56 | getInputTypeAndExtract(key) {
|
57 | if (!this.inputTypeDefinitionsLinks) {
|
58 | this.inputTypeDefinitionsLinks = new Map([
|
59 | ...this.enumTypeDefinitions.entries(),
|
60 | ...this.inputTypeDefinitions.entries(),
|
61 | ]);
|
62 | }
|
63 | const definition = this.inputTypeDefinitionsLinks.get(key);
|
64 | if (definition) {
|
65 | return definition.type;
|
66 | }
|
67 | return;
|
68 | }
|
69 | getOutputTypeAndExtract(key) {
|
70 | if (!this.outputTypeDefinitionsLinks) {
|
71 | this.outputTypeDefinitionsLinks = new Map([
|
72 | ...this.objectTypeDefinitions.entries(),
|
73 | ...this.interfaceTypeDefinitions.entries(),
|
74 | ...this.enumTypeDefinitions.entries(),
|
75 | ...this.unionTypeDefinitions.entries(),
|
76 | ]);
|
77 | }
|
78 | const definition = this.outputTypeDefinitionsLinks.get(key);
|
79 | if (definition) {
|
80 | return definition.type;
|
81 | }
|
82 | return;
|
83 | }
|
84 | };
|
85 | exports.TypeDefinitionsStorage = TypeDefinitionsStorage;
|
86 | exports.TypeDefinitionsStorage = TypeDefinitionsStorage = tslib_1.__decorate([
|
87 | (0, common_1.Injectable)()
|
88 | ], TypeDefinitionsStorage);
|