@restorecommerce/facade 0.1.42 → 0.1.43
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 +15 -0
- package/dist/gql/protos/graphql.d.ts +1 -1
- package/dist/gql/protos/graphql.js +24 -7
- package/dist/gql/protos/registry.d.ts +5 -0
- package/dist/gql/protos/registry.js +78 -12
- package/dist/gql/protos/utils.d.ts +21 -0
- package/dist/gql/protos/utils.js +88 -1
- package/package.json +2 -2
package/CHANGELOG.md
CHANGED
@@ -3,6 +3,21 @@
|
|
3
3
|
All notable changes to this project will be documented in this file.
|
4
4
|
See [Conventional Commits](https://conventionalcommits.org) for commit guidelines.
|
5
5
|
|
6
|
+
## [0.1.43](https://github.com/restorecommerce/libs/compare/@restorecommerce/facade@0.1.42...@restorecommerce/facade@0.1.43) (2022-02-02)
|
7
|
+
|
8
|
+
|
9
|
+
### Bug Fixes
|
10
|
+
|
11
|
+
* **facade:** enum convert string to integer ([47127ef](https://github.com/restorecommerce/libs/commit/47127ef323f5853a4c6573b01dd36c3725074d4e))
|
12
|
+
* **facade:** fix for mutation resolvers to convert enums string values to integer ([28d0fea](https://github.com/restorecommerce/libs/commit/28d0fea912778b3cf4f748bc68b1e0fafaea60af))
|
13
|
+
* **facade:** fixed read operations to convert enums to number ([81083c0](https://github.com/restorecommerce/libs/commit/81083c0162d605d6a3c8394e06ba093d1e29948e))
|
14
|
+
* **facade:** move conversion of enum to int to utils ([72c9a1f](https://github.com/restorecommerce/libs/commit/72c9a1f0be269b68bc9b2501a38789ce7409453f))
|
15
|
+
* **facade:** recursive enum path fix ([244f7fc](https://github.com/restorecommerce/libs/commit/244f7fc782d10ffb5f774f0245174446288cacb5))
|
16
|
+
|
17
|
+
|
18
|
+
|
19
|
+
|
20
|
+
|
6
21
|
## [0.1.42](https://github.com/restorecommerce/libs/compare/@restorecommerce/facade@0.1.41...@restorecommerce/facade@0.1.42) (2022-01-28)
|
7
22
|
|
8
23
|
**Note:** Version bump only for package @restorecommerce/facade
|
@@ -15,7 +15,7 @@ declare type ServiceClient<Context extends Pick<Context, Key>, Key extends keyof
|
|
15
15
|
};
|
16
16
|
};
|
17
17
|
export declare const getGQLResolverFunctions: <T extends Record<string, any>, CTX extends ServiceClient<CTX, keyof CTX, T>, SRV = any, R = ResolverFn<any, any, ServiceClient<CTX, keyof CTX, T>, any>, B extends keyof T = any, NS extends keyof CTX = any>(service: ServiceDescriptorProto, key: NS, serviceKey: B, grpcClientConfig: GrpcClientConfig) => { [key in keyof SRV]: R; };
|
18
|
-
export declare const registerResolverFunction: <T extends Record<string, any>, CTX extends ServiceClient<CTX, keyof CTX, T>>(namespace: string, name: string, func: ResolverFn<any, any, ServiceClient<CTX, keyof CTX, T>, any>, mutation?: boolean, subspace?: string | undefined) => void;
|
18
|
+
export declare const registerResolverFunction: <T extends Record<string, any>, CTX extends ServiceClient<CTX, keyof CTX, T>>(namespace: string, name: string, func: ResolverFn<any, any, ServiceClient<CTX, keyof CTX, T>, any>, mutation?: boolean, subspace?: string | undefined, service?: ServiceDescriptorProto | undefined) => void;
|
19
19
|
export declare const generateResolver: (...namespaces: string[]) => any;
|
20
20
|
export declare const registerResolverSchema: (namespace: string, name: string, schema: Thunk<GraphQLFieldConfig<any, any>>, mutation?: boolean, subspace?: string | undefined) => void;
|
21
21
|
export declare const generateSchema: (setup: {
|
@@ -10,6 +10,7 @@ const stream = require("stream");
|
|
10
10
|
const _ = require("lodash");
|
11
11
|
const typeCache = new Map();
|
12
12
|
const Mutate = ['Create', 'Update', 'Upsert'];
|
13
|
+
const inputMethodType = new Map();
|
13
14
|
const getGQLSchema = (method) => {
|
14
15
|
const fields = {
|
15
16
|
// operationStatus: {
|
@@ -109,9 +110,8 @@ const getGQLResolverFunctions = (service, key, serviceKey, grpcClientConfig) =>
|
|
109
110
|
}
|
110
111
|
const defaults = typing.processor.fromPartial({});
|
111
112
|
let subjectField = null;
|
112
|
-
|
113
|
-
|
114
|
-
for (let field of inputTyping.meta.field) {
|
113
|
+
if (typing) {
|
114
|
+
for (let field of typing.meta.field) {
|
115
115
|
if (field.typeName === types_1.authSubjectType) {
|
116
116
|
subjectField = field.name;
|
117
117
|
break;
|
@@ -124,11 +124,13 @@ const getGQLResolverFunctions = (service, key, serviceKey, grpcClientConfig) =>
|
|
124
124
|
const service = client[serviceKey];
|
125
125
|
try {
|
126
126
|
const converted = await exports.recursiveUploadToBuffer(args.input, typing.input);
|
127
|
-
|
127
|
+
let req = {
|
128
128
|
// Fill defaults
|
129
129
|
...defaults,
|
130
130
|
...converted
|
131
131
|
};
|
132
|
+
// convert enum strings to integers
|
133
|
+
req = utils_1.convertEnumToInt(typing, req);
|
132
134
|
if (subjectField !== null) {
|
133
135
|
req.subject = registry_1.getTyping(types_1.authSubjectType).processor.fromPartial({});
|
134
136
|
const authToken = context.request.req.headers['authorization'];
|
@@ -251,6 +253,12 @@ const MutateResolver = async (req, ctx, schema) => {
|
|
251
253
|
else if (mode === 'UPSERT') {
|
252
254
|
method = 'Upsert';
|
253
255
|
}
|
256
|
+
const inputMethodTypeKey = module_name.toLowerCase() + '.' + key.toLowerCase() + '.' + method.toLowerCase();
|
257
|
+
const nsType = inputMethodType.get(inputMethodTypeKey);
|
258
|
+
if (nsType) {
|
259
|
+
const inputTyping = registry_1.getTyping(nsType);
|
260
|
+
utils_1.convertEnumToInt(inputTyping, input);
|
261
|
+
}
|
254
262
|
// check service object contains requested mode's method def
|
255
263
|
if (!service[method]) {
|
256
264
|
throw new Error(`Method ${method} not defined on ${module_name}`);
|
@@ -361,7 +369,7 @@ const MutateResolver = async (req, ctx, schema) => {
|
|
361
369
|
};
|
362
370
|
}
|
363
371
|
};
|
364
|
-
const registerResolverFunction = (namespace, name, func, mutation = false, subspace = undefined) => {
|
372
|
+
const registerResolverFunction = (namespace, name, func, mutation = false, subspace = undefined, service) => {
|
365
373
|
if (!namespaceResolverRegistry.has(namespace)) {
|
366
374
|
namespaceResolverRegistry.set(namespace, new Map());
|
367
375
|
}
|
@@ -383,6 +391,13 @@ const registerResolverFunction = (namespace, name, func, mutation = false, subsp
|
|
383
391
|
throw new Error(`Namespace "${namespace}" already contains a function: ${name} (mutation: ${mutation})`);
|
384
392
|
}
|
385
393
|
}
|
394
|
+
if (service) {
|
395
|
+
const key = (namespace === null || namespace === void 0 ? void 0 : namespace.toLocaleLowerCase()) + '.' + (subspace === null || subspace === void 0 ? void 0 : subspace.toLocaleLowerCase()) + '.' + (name === null || name === void 0 ? void 0 : name.toLocaleLowerCase());
|
396
|
+
const value = service.method.find((m) => m.name === name);
|
397
|
+
if (key && (value === null || value === void 0 ? void 0 : value.inputType)) {
|
398
|
+
inputMethodType.set(key, value.inputType);
|
399
|
+
}
|
400
|
+
}
|
386
401
|
// custom mutation resolver for create, update and upsert - Mutate
|
387
402
|
if (Mutate.indexOf(name) > -1) {
|
388
403
|
name = 'Mutate';
|
@@ -599,7 +614,7 @@ const getAndGenerateResolvers = (service, namespace, cfg, queryList, subspace =
|
|
599
614
|
const { mutations, queries } = exports.getWhitelistBlacklistConfig(service, queryList, cfg);
|
600
615
|
const func = exports.getGQLResolverFunctions(service, namespace, serviceKey || subspace || namespace, cfg.client);
|
601
616
|
Object.keys(func).forEach(k => {
|
602
|
-
exports.registerResolverFunction(namespace, k, func[k], !queries.has(k) && mutations.has(k), subspace);
|
617
|
+
exports.registerResolverFunction(namespace, k, func[k], !queries.has(k) && mutations.has(k), subspace, service);
|
603
618
|
});
|
604
619
|
return exports.generateResolver(namespace);
|
605
620
|
};
|
@@ -626,7 +641,9 @@ const generateSubServiceResolvers = (subServices, config, namespace) => {
|
|
626
641
|
const { mutations, queries } = exports.getWhitelistBlacklistConfig(sub.service, sub.queries, config);
|
627
642
|
const func = exports.getGQLResolverFunctions(sub.service, namespace, sub.name || namespace, config.client);
|
628
643
|
Object.keys(func).forEach(k => {
|
629
|
-
|
644
|
+
const regNamespace = config.root ? sub.name : namespace;
|
645
|
+
const regSubspace = config.root ? undefined : sub.name;
|
646
|
+
exports.registerResolverFunction(regNamespace, k, func[k], !queries.has(k) && mutations.has(k), regSubspace, sub.service);
|
630
647
|
});
|
631
648
|
});
|
632
649
|
if (config.root) {
|
@@ -8,8 +8,13 @@ export interface TypingData {
|
|
8
8
|
meta: DescriptorProto | EnumDescriptorProto;
|
9
9
|
processor?: any;
|
10
10
|
}
|
11
|
+
export declare const registeredTypings: Map<string, TypingData>;
|
12
|
+
export declare const scalarTypes: string[];
|
11
13
|
export declare const clearRegistry: () => void;
|
12
14
|
export declare const registerPackagesRecursive: (...protoMetadata: ProtoMetadata[]) => void;
|
15
|
+
export declare const getRegisteredEnumTypings: () => string[];
|
16
|
+
export declare const getNameSpaceTypeName: (typeName: string) => string | undefined;
|
17
|
+
export declare const recursiveEnumCheck: (typeName: string, enumMap: Map<string, string>, prevFieldName: string, traversedFields: string[]) => Map<string, string>;
|
13
18
|
export declare const registerTyping: (protoPackage: string, message: DescriptorProto, methodDef: MethodDescriptorProto[], opts?: Omit<Readonly<GraphQLObjectTypeConfig<any, any>>, "fields"> | undefined, inputOpts?: Omit<Readonly<GraphQLInputObjectTypeConfig>, "fields"> | undefined) => void;
|
14
19
|
export declare const registerEnumTyping: <T = {
|
15
20
|
[key: string]: any;
|
@@ -1,13 +1,17 @@
|
|
1
1
|
"use strict";
|
2
2
|
Object.defineProperty(exports, "__esModule", { value: true });
|
3
|
-
exports.getTyping = exports.registerEnumTyping = exports.registerTyping = exports.registerPackagesRecursive = exports.clearRegistry = void 0;
|
3
|
+
exports.getTyping = exports.registerEnumTyping = exports.registerTyping = exports.recursiveEnumCheck = exports.getNameSpaceTypeName = exports.getRegisteredEnumTypings = exports.registerPackagesRecursive = exports.clearRegistry = exports.scalarTypes = exports.registeredTypings = void 0;
|
4
4
|
const graphql_1 = require("graphql");
|
5
5
|
const definition_1 = require("graphql/type/definition");
|
6
6
|
const graphql_upload_1 = require("graphql-upload");
|
7
7
|
const utils_1 = require("./utils");
|
8
8
|
const types_1 = require("./types");
|
9
9
|
const descriptor_1 = require("ts-proto-descriptors/google/protobuf/descriptor");
|
10
|
-
const
|
10
|
+
const _ = require("lodash");
|
11
|
+
exports.registeredTypings = new Map();
|
12
|
+
exports.scalarTypes = ['Boolean', 'Int', 'Float', 'String', 'ID', 'Upload'];
|
13
|
+
const typeNameAndNameSpaceMapping = new Map();
|
14
|
+
const registeredEnumTypes = [];
|
11
15
|
const MapScalar = new definition_1.GraphQLScalarType({
|
12
16
|
name: 'MapScalar',
|
13
17
|
});
|
@@ -22,7 +26,7 @@ const TodoScalar = new definition_1.GraphQLScalarType({
|
|
22
26
|
}
|
23
27
|
});
|
24
28
|
const clearRegistry = () => {
|
25
|
-
registeredTypings.clear();
|
29
|
+
exports.registeredTypings.clear();
|
26
30
|
};
|
27
31
|
exports.clearRegistry = clearRegistry;
|
28
32
|
const registerPackagesRecursive = (...protoMetadata) => {
|
@@ -34,11 +38,70 @@ const registerPackagesRecursive = (...protoMetadata) => {
|
|
34
38
|
exports.registerEnumTyping(meta.fileDescriptor.package, m);
|
35
39
|
});
|
36
40
|
Object.keys(meta.references).forEach(key => {
|
37
|
-
registeredTypings.get(key).processor = meta.references[key];
|
41
|
+
exports.registeredTypings.get(key).processor = meta.references[key];
|
38
42
|
});
|
39
43
|
});
|
40
44
|
};
|
41
45
|
exports.registerPackagesRecursive = registerPackagesRecursive;
|
46
|
+
const getRegisteredEnumTypings = () => {
|
47
|
+
return registeredEnumTypes;
|
48
|
+
};
|
49
|
+
exports.getRegisteredEnumTypings = getRegisteredEnumTypings;
|
50
|
+
const getNameSpaceTypeName = (typeName) => {
|
51
|
+
return typeNameAndNameSpaceMapping.get(typeName);
|
52
|
+
};
|
53
|
+
exports.getNameSpaceTypeName = getNameSpaceTypeName;
|
54
|
+
// Iterate through the object and collect list of all enum types with their keys / paths
|
55
|
+
const recursiveEnumCheck = (typeName, enumMap, prevFieldName, traversedFields) => {
|
56
|
+
if (exports.scalarTypes.indexOf(typeName) <= -1) {
|
57
|
+
if (typeName && typeName.startsWith('[') && typeName.endsWith('!]')) {
|
58
|
+
typeName = typeName.substring(1, typeName.length - 2);
|
59
|
+
}
|
60
|
+
const objectNameSpace = exports.getNameSpaceTypeName(typeName);
|
61
|
+
if (objectNameSpace) {
|
62
|
+
const objectType = exports.getTyping(objectNameSpace);
|
63
|
+
if ((objectType === null || objectType === void 0 ? void 0 : objectType.input) && (registeredEnumTypes.indexOf(objectType.input.toString()) > -1)) {
|
64
|
+
enumMap.set(objectType === null || objectType === void 0 ? void 0 : objectType.input.toString(), prevFieldName);
|
65
|
+
prevFieldName = '';
|
66
|
+
}
|
67
|
+
else if (objectType === null || objectType === void 0 ? void 0 : objectType.input) {
|
68
|
+
// get nested fields from this object and check recursively
|
69
|
+
const gqlFields = objectType.input.getFields();
|
70
|
+
if (gqlFields) {
|
71
|
+
const fieldNames = Object.keys(gqlFields);
|
72
|
+
for (let fieldName of fieldNames) {
|
73
|
+
let fieldType = gqlFields[fieldName].type.toString();
|
74
|
+
// if fieldType is not basic type, get the object and make recursive check till no more objects are found
|
75
|
+
let skipLoop = false;
|
76
|
+
if (exports.scalarTypes.indexOf(fieldType) <= -1) {
|
77
|
+
// check if fieldName already exists in the enumMap (to avoid circular reference for infinite loop)
|
78
|
+
for (let [key, val] of enumMap) {
|
79
|
+
const valueArray = val.split('.');
|
80
|
+
// if fieldName already exists in enumMap, this field is a circular field ref
|
81
|
+
// ignore it as its already traversed and enums are kept track of
|
82
|
+
if (valueArray.indexOf(fieldName) > -1) {
|
83
|
+
skipLoop = true;
|
84
|
+
}
|
85
|
+
}
|
86
|
+
if (skipLoop) {
|
87
|
+
continue;
|
88
|
+
}
|
89
|
+
if (!prevFieldName || _.isEmpty(prevFieldName)) {
|
90
|
+
prevFieldName = fieldName;
|
91
|
+
}
|
92
|
+
if (prevFieldName && prevFieldName != fieldName) {
|
93
|
+
fieldName = prevFieldName + '.' + fieldName;
|
94
|
+
}
|
95
|
+
exports.recursiveEnumCheck(fieldType, enumMap, fieldName, traversedFields);
|
96
|
+
}
|
97
|
+
}
|
98
|
+
}
|
99
|
+
}
|
100
|
+
}
|
101
|
+
}
|
102
|
+
return enumMap;
|
103
|
+
};
|
104
|
+
exports.recursiveEnumCheck = recursiveEnumCheck;
|
42
105
|
const registerMessageTypesRecursive = (packageName, methodDef, ...types) => {
|
43
106
|
types.forEach(m => {
|
44
107
|
exports.registerTyping(packageName, m, methodDef);
|
@@ -78,7 +141,7 @@ const registerTyping = (protoPackage, message, methodDef, opts, inputOpts) => {
|
|
78
141
|
}
|
79
142
|
}
|
80
143
|
}
|
81
|
-
if (registeredTypings.has(type)) {
|
144
|
+
if (exports.registeredTypings.has(type)) {
|
82
145
|
// TODO Log debug "Typings for object are already registered"
|
83
146
|
return;
|
84
147
|
}
|
@@ -125,7 +188,8 @@ const registerTyping = (protoPackage, message, methodDef, opts, inputOpts) => {
|
|
125
188
|
...(inputOpts || { name: inputName }),
|
126
189
|
fields: inputFields,
|
127
190
|
});
|
128
|
-
|
191
|
+
typeNameAndNameSpaceMapping.set(resultInputObj.name, type);
|
192
|
+
exports.registeredTypings.set(type, {
|
129
193
|
output: resultObj,
|
130
194
|
input: resultInputObj,
|
131
195
|
meta: message
|
@@ -135,7 +199,7 @@ exports.registerTyping = registerTyping;
|
|
135
199
|
const registerEnumTyping = (protoPackage, message, opts) => {
|
136
200
|
var _a;
|
137
201
|
const type = (protoPackage.startsWith('.') ? '' : '.') + protoPackage + '.' + message.name;
|
138
|
-
if (registeredTypings.has(type)) {
|
202
|
+
if (exports.registeredTypings.has(type)) {
|
139
203
|
// TODO Log debug "Typings for enum are already registered"
|
140
204
|
return;
|
141
205
|
}
|
@@ -150,7 +214,9 @@ const registerEnumTyping = (protoPackage, message, opts) => {
|
|
150
214
|
...(opts || { name }),
|
151
215
|
values
|
152
216
|
});
|
153
|
-
|
217
|
+
registeredEnumTypes.push(name);
|
218
|
+
typeNameAndNameSpaceMapping.set(name, type);
|
219
|
+
exports.registeredTypings.set(type, {
|
154
220
|
output: result,
|
155
221
|
input: result,
|
156
222
|
meta: message
|
@@ -158,7 +224,7 @@ const registerEnumTyping = (protoPackage, message, opts) => {
|
|
158
224
|
};
|
159
225
|
exports.registerEnumTyping = registerEnumTyping;
|
160
226
|
const getTyping = (type) => {
|
161
|
-
return registeredTypings.get(type);
|
227
|
+
return exports.registeredTypings.get(type);
|
162
228
|
};
|
163
229
|
exports.getTyping = getTyping;
|
164
230
|
const resolveMeta = (key, field, rootObjType, objName, input) => {
|
@@ -173,17 +239,17 @@ const resolveMeta = (key, field, rootObjType, objName, input) => {
|
|
173
239
|
case descriptor_1.FieldDescriptorProto_Type.TYPE_ENUM:
|
174
240
|
case descriptor_1.FieldDescriptorProto_Type.TYPE_MESSAGE:
|
175
241
|
const objType = field.typeName;
|
176
|
-
if (!registeredTypings.has(objType)) {
|
242
|
+
if (!exports.registeredTypings.has(objType)) {
|
177
243
|
throw new Error("Typing '" + objType + "' not registered for key '" + key + "' in object: " + objName);
|
178
244
|
}
|
179
245
|
if (!input) {
|
180
|
-
result = registeredTypings.get(objType).output;
|
246
|
+
result = exports.registeredTypings.get(objType).output;
|
181
247
|
break;
|
182
248
|
}
|
183
249
|
if (objType === types_1.authSubjectType) {
|
184
250
|
return null;
|
185
251
|
}
|
186
|
-
result = registeredTypings.get(objType).input;
|
252
|
+
result = exports.registeredTypings.get(objType).input;
|
187
253
|
break;
|
188
254
|
case descriptor_1.FieldDescriptorProto_Type.TYPE_BYTES:
|
189
255
|
if (input) {
|
@@ -1,4 +1,25 @@
|
|
1
|
+
import { TypingData } from './registry';
|
1
2
|
export declare const capitalizeProtoName: (name: string) => string;
|
2
3
|
export declare const convertyCamelToSnakeCase: (entity: string) => string;
|
3
4
|
export declare const getKeys: (obj: any) => string[];
|
4
5
|
export declare const decodeBufferFields: (items: any, bufferFields: string[]) => any;
|
6
|
+
interface EnumMetaData {
|
7
|
+
name: string;
|
8
|
+
number: number;
|
9
|
+
options?: any;
|
10
|
+
}
|
11
|
+
/**
|
12
|
+
* recursively find the path and updates the object with given value, this function
|
13
|
+
* also takes care to handle if there is an array at any position in the path
|
14
|
+
* @param path path in dot notation
|
15
|
+
* @param val value to be updated in Object
|
16
|
+
* @param obj Object
|
17
|
+
*/
|
18
|
+
export declare const updateJSON: (path: string, val: EnumMetaData[], obj: any) => void;
|
19
|
+
/**
|
20
|
+
* converts enum string values to integers reading from the inputTyping
|
21
|
+
* @param TypingData input typing
|
22
|
+
* @param req request object from which the enum strings to be replaced
|
23
|
+
*/
|
24
|
+
export declare const convertEnumToInt: (inputTyping: TypingData, req: any) => any;
|
25
|
+
export {};
|
package/dist/gql/protos/utils.js
CHANGED
@@ -1,7 +1,8 @@
|
|
1
1
|
"use strict";
|
2
2
|
Object.defineProperty(exports, "__esModule", { value: true });
|
3
|
-
exports.decodeBufferFields = exports.getKeys = exports.convertyCamelToSnakeCase = exports.capitalizeProtoName = void 0;
|
3
|
+
exports.convertEnumToInt = exports.updateJSON = exports.decodeBufferFields = exports.getKeys = exports.convertyCamelToSnakeCase = exports.capitalizeProtoName = void 0;
|
4
4
|
const _ = require("lodash");
|
5
|
+
const registry_1 = require("./registry");
|
5
6
|
const capitalizeProtoName = (name) => {
|
6
7
|
return name.replace(/(?:\.|^|_)(\w)/g, v => v.toUpperCase()).replace(/[._]/g, '');
|
7
8
|
};
|
@@ -48,3 +49,89 @@ const decodeBufferFields = (items, bufferFields) => {
|
|
48
49
|
}
|
49
50
|
};
|
50
51
|
exports.decodeBufferFields = decodeBufferFields;
|
52
|
+
/**
|
53
|
+
* recursively find the path and updates the object with given value, this function
|
54
|
+
* also takes care to handle if there is an array at any position in the path
|
55
|
+
* @param path path in dot notation
|
56
|
+
* @param val value to be updated in Object
|
57
|
+
* @param obj Object
|
58
|
+
*/
|
59
|
+
const updateJSON = (path, val, obj) => {
|
60
|
+
let fields = path.split('.');
|
61
|
+
let result = obj;
|
62
|
+
let j = 0;
|
63
|
+
for (let i = 0, n = fields.length; i < n && result !== undefined; i++) {
|
64
|
+
let field = fields[i];
|
65
|
+
if (i === n - 1) {
|
66
|
+
// reset value finally after iterating to the position (only if value already exists)
|
67
|
+
if (result[field]) {
|
68
|
+
const foundElement = val.find((e) => e.name === result[field]);
|
69
|
+
result[field] = foundElement === null || foundElement === void 0 ? void 0 : foundElement.number;
|
70
|
+
}
|
71
|
+
}
|
72
|
+
else {
|
73
|
+
if (_.isArray(result[field])) {
|
74
|
+
// till i < n concat new fields
|
75
|
+
let newField = '';
|
76
|
+
for (let k = i + 1; k < n; k++) {
|
77
|
+
if (newField && !_.isEmpty(newField)) {
|
78
|
+
newField = newField + '.' + fields[k];
|
79
|
+
}
|
80
|
+
else {
|
81
|
+
newField = fields[k];
|
82
|
+
}
|
83
|
+
}
|
84
|
+
for (; j < result[field].length; j++) {
|
85
|
+
// recurisve call to update each element if its an array
|
86
|
+
exports.updateJSON(newField, val, result[field][j]);
|
87
|
+
}
|
88
|
+
}
|
89
|
+
else {
|
90
|
+
// update object till final path is reached
|
91
|
+
result = result[field];
|
92
|
+
}
|
93
|
+
}
|
94
|
+
}
|
95
|
+
};
|
96
|
+
exports.updateJSON = updateJSON;
|
97
|
+
/**
|
98
|
+
* converts enum string values to integers reading from the inputTyping
|
99
|
+
* @param TypingData input typing
|
100
|
+
* @param req request object from which the enum strings to be replaced
|
101
|
+
*/
|
102
|
+
const convertEnumToInt = (inputTyping, req) => {
|
103
|
+
let enumMap = new Map();
|
104
|
+
// enumMap populated with key as enum name space type and value as the path (to replace from request object)
|
105
|
+
if (inputTyping) {
|
106
|
+
const gqlInputObject = inputTyping.input;
|
107
|
+
const gqlFields = gqlInputObject.getFields();
|
108
|
+
if (gqlFields) {
|
109
|
+
const fieldNames = Object.keys(gqlFields);
|
110
|
+
for (let fieldName of fieldNames) {
|
111
|
+
// gql fieldName from input is of format [IIoRestorecommerceResourcebaseSort!]
|
112
|
+
// below check is to remove `[` and `!]`
|
113
|
+
let fieldType = gqlFields[fieldName].type.toString();
|
114
|
+
if (fieldType.startsWith('[') && fieldType.endsWith('!]')) {
|
115
|
+
fieldType = fieldType.substring(1, fieldType.length - 2);
|
116
|
+
}
|
117
|
+
// if fieldType is not basic type, then check if its fieldType belongs to Enum
|
118
|
+
// if not get the object and make recursive check till no more objects are found
|
119
|
+
if (registry_1.scalarTypes.indexOf(fieldType) <= -1) {
|
120
|
+
enumMap = registry_1.recursiveEnumCheck(fieldType, enumMap, fieldName, []);
|
121
|
+
}
|
122
|
+
}
|
123
|
+
}
|
124
|
+
}
|
125
|
+
for (let [key, val] of enumMap) {
|
126
|
+
const enumNameSpace = registry_1.getNameSpaceTypeName(key);
|
127
|
+
if (enumNameSpace && typeof enumNameSpace === 'string') {
|
128
|
+
const enumTyping = registry_1.getTyping(enumNameSpace);
|
129
|
+
const enumIntMapping = (enumTyping === null || enumTyping === void 0 ? void 0 : enumTyping.meta).value;
|
130
|
+
if (enumIntMapping && _.isArray(enumIntMapping) && enumIntMapping.length > 0) {
|
131
|
+
exports.updateJSON(val, enumIntMapping, req);
|
132
|
+
}
|
133
|
+
}
|
134
|
+
}
|
135
|
+
return req;
|
136
|
+
};
|
137
|
+
exports.convertEnumToInt = convertEnumToInt;
|
package/package.json
CHANGED
@@ -1,6 +1,6 @@
|
|
1
1
|
{
|
2
2
|
"name": "@restorecommerce/facade",
|
3
|
-
"version": "0.1.
|
3
|
+
"version": "0.1.43",
|
4
4
|
"description": "Facade for Restorecommerce microservices",
|
5
5
|
"main": "dist/index.js",
|
6
6
|
"typings": "dist/index.d.ts",
|
@@ -101,5 +101,5 @@
|
|
101
101
|
"publishConfig": {
|
102
102
|
"access": "public"
|
103
103
|
},
|
104
|
-
"gitHead": "
|
104
|
+
"gitHead": "2b4964c14cf0a66ecfaf1e0af2a6d88f9a47fba7"
|
105
105
|
}
|