@restorecommerce/facade 0.3.11 → 0.3.14

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 CHANGED
@@ -3,6 +3,37 @@
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.3.14](https://github.com/restorecommerce/libs/compare/@restorecommerce/facade@0.3.13...@restorecommerce/facade@0.3.14) (2022-04-01)
7
+
8
+
9
+ ### Bug Fixes
10
+
11
+ * **facade:** fix to convert google.protobuf.timestamp to DateTime scalar type and convert it to JS Date object for create / update operation. ([ced5ecf](https://github.com/restorecommerce/libs/commit/ced5ecfae25eb928691a6a17eb32683ae9650a68))
12
+ * **facade:** renamed preprocess and postprocess GQL function name ([ef0f5f0](https://github.com/restorecommerce/libs/commit/ef0f5f02dcd605067b6399d4afa525248ce64417))
13
+
14
+
15
+
16
+
17
+
18
+ ## [0.3.13](https://github.com/restorecommerce/libs/compare/@restorecommerce/facade@0.3.12...@restorecommerce/facade@0.3.13) (2022-03-29)
19
+
20
+ **Note:** Version bump only for package @restorecommerce/facade
21
+
22
+
23
+
24
+
25
+
26
+ ## [0.3.12](https://github.com/restorecommerce/libs/compare/@restorecommerce/facade@0.3.11...@restorecommerce/facade@0.3.12) (2022-03-23)
27
+
28
+
29
+ ### Bug Fixes
30
+
31
+ * **facade:** include scope for traversal operation as well ([cf57b73](https://github.com/restorecommerce/libs/commit/cf57b733f1788fd07d8a63ca0c9614c954b577d9))
32
+
33
+
34
+
35
+
36
+
6
37
  ## [0.3.11](https://github.com/restorecommerce/libs/compare/@restorecommerce/facade@0.3.10...@restorecommerce/facade@0.3.11) (2022-03-15)
7
38
 
8
39
 
@@ -5,8 +5,8 @@ import { MethodDescriptorProto, ServiceDescriptorProto } from "ts-proto-descript
5
5
  import { GrpcClientConfig } from "@restorecommerce/grpc-client";
6
6
  export declare const getGQLSchema: <TSource, TContext>(method: MethodDescriptorProto) => GraphQLFieldConfig<TSource, TContext, any>;
7
7
  export declare const getGQLSchemas: <TSource, TContext>(service: ServiceDescriptorProto) => GraphQLFieldConfigMap<TSource, TContext>;
8
- export declare const recursiveUploadToBuffer: (data: any, model: GraphQLInputObjectType | GraphQLEnumType | GraphQLInputField | GraphQLInputType) => Promise<any>;
9
- export declare const recursiveBufferToValue: (data: any, model: GraphQLOutputType) => any;
8
+ export declare const preprocessGQLInput: (data: any, model: GraphQLInputObjectType | GraphQLEnumType | GraphQLInputField | GraphQLInputType) => Promise<any>;
9
+ export declare const postProcessGQLValue: (data: any, model: GraphQLOutputType) => any;
10
10
  export declare type ResolverFn<TResult, TParent, TContext, TArgs> = (parent: TParent, args: TArgs, context: TContext, info: GraphQLResolveInfo) => Promise<TResult> | TResult;
11
11
  declare type ServiceClient<Context extends Pick<Context, Key>, Key extends keyof Context, T extends Record<string, any>> = {
12
12
  [V in Key]: {
@@ -1,6 +1,6 @@
1
1
  "use strict";
2
2
  Object.defineProperty(exports, "__esModule", { value: true });
3
- exports.generateSubServiceResolvers = exports.generateSubServiceSchemas = exports.getAndGenerateResolvers = exports.getAndGenerateSchema = exports.getWhitelistBlacklistConfig = exports.generateSchema = exports.registerResolverSchema = exports.generateResolver = exports.registerResolverFunction = exports.getGQLResolverFunctions = exports.recursiveBufferToValue = exports.recursiveUploadToBuffer = exports.getGQLSchemas = exports.getGQLSchema = void 0;
3
+ exports.generateSubServiceResolvers = exports.generateSubServiceSchemas = exports.getAndGenerateResolvers = exports.getAndGenerateSchema = exports.getWhitelistBlacklistConfig = exports.generateSchema = exports.registerResolverSchema = exports.generateResolver = exports.registerResolverFunction = exports.getGQLResolverFunctions = exports.postProcessGQLValue = exports.preprocessGQLInput = exports.getGQLSchemas = exports.getGQLSchema = void 0;
4
4
  const graphql_1 = require("graphql");
5
5
  const definition_1 = require("graphql/type/definition");
6
6
  const types_1 = require("./types");
@@ -57,7 +57,7 @@ const getGQLSchemas = (service) => {
57
57
  }, {});
58
58
  };
59
59
  exports.getGQLSchemas = getGQLSchemas;
60
- const recursiveUploadToBuffer = async (data, model) => {
60
+ const preprocessGQLInput = async (data, model) => {
61
61
  if (model instanceof definition_1.GraphQLEnumType) {
62
62
  return data;
63
63
  }
@@ -80,17 +80,22 @@ const recursiveUploadToBuffer = async (data, model) => {
80
80
  const fields = model.getFields();
81
81
  for (let key of Object.keys(fields)) {
82
82
  if (data && key in data) {
83
- data[key] = await (0, exports.recursiveUploadToBuffer)(data[key], fields[key].type);
83
+ data[key] = await (0, exports.preprocessGQLInput)(data[key], fields[key].type);
84
84
  }
85
85
  }
86
86
  }
87
87
  }
88
+ if (model instanceof definition_1.GraphQLScalarType) {
89
+ if (model.name === 'IDateTime') {
90
+ return new Date(data);
91
+ }
92
+ }
88
93
  if (model instanceof graphql_1.GraphQLNonNull) {
89
- return await (0, exports.recursiveUploadToBuffer)(data, model.ofType);
94
+ return await (0, exports.preprocessGQLInput)(data, model.ofType);
90
95
  }
91
96
  if (model instanceof graphql_1.GraphQLList) {
92
97
  for (let i = 0; i < data.length; i++) {
93
- data[i] = await (0, exports.recursiveUploadToBuffer)(data[i], model.ofType);
98
+ data[i] = await (0, exports.preprocessGQLInput)(data[i], model.ofType);
94
99
  }
95
100
  }
96
101
  if (model instanceof definition_1.GraphQLScalarType) {
@@ -111,8 +116,8 @@ const recursiveUploadToBuffer = async (data, model) => {
111
116
  }
112
117
  return data;
113
118
  };
114
- exports.recursiveUploadToBuffer = recursiveUploadToBuffer;
115
- const recursiveBufferToValue = (data, model) => {
119
+ exports.preprocessGQLInput = preprocessGQLInput;
120
+ const postProcessGQLValue = (data, model) => {
116
121
  if (model instanceof definition_1.GraphQLEnumType) {
117
122
  return data;
118
123
  }
@@ -129,22 +134,22 @@ const recursiveBufferToValue = (data, model) => {
129
134
  const fields = model.getFields();
130
135
  for (let key of Object.keys(fields)) {
131
136
  if (data && key in data) {
132
- data[key] = (0, exports.recursiveBufferToValue)(data[key], fields[key].type);
137
+ data[key] = (0, exports.postProcessGQLValue)(data[key], fields[key].type);
133
138
  }
134
139
  }
135
140
  }
136
141
  }
137
142
  if (model instanceof graphql_1.GraphQLNonNull) {
138
- return (0, exports.recursiveBufferToValue)(data, model.ofType);
143
+ return (0, exports.postProcessGQLValue)(data, model.ofType);
139
144
  }
140
145
  if (model instanceof graphql_1.GraphQLList) {
141
146
  for (let i = 0; i < data.length; i++) {
142
- data[i] = (0, exports.recursiveBufferToValue)(data[i], model.ofType);
147
+ data[i] = (0, exports.postProcessGQLValue)(data[i], model.ofType);
143
148
  }
144
149
  }
145
150
  return data;
146
151
  };
147
- exports.recursiveBufferToValue = recursiveBufferToValue;
152
+ exports.postProcessGQLValue = postProcessGQLValue;
148
153
  const getGQLResolverFunctions = (service, key, serviceKey, grpcClientConfig) => {
149
154
  if (!service.method) {
150
155
  return {};
@@ -182,7 +187,7 @@ const getGQLResolverFunctions = (service, key, serviceKey, grpcClientConfig) =>
182
187
  const client = context[key].client;
183
188
  const service = client[serviceKey];
184
189
  try {
185
- const converted = await (0, exports.recursiveUploadToBuffer)(args.input, typing.input);
190
+ const converted = await (0, exports.preprocessGQLInput)(args.input, typing.input);
186
191
  const scope = (_a = args === null || args === void 0 ? void 0 : args.input) === null || _a === void 0 ? void 0 : _a.scope;
187
192
  let req = typing.processor.fromPartial(converted);
188
193
  // convert enum strings to integers
@@ -214,7 +219,7 @@ const getGQLResolverFunctions = (service, key, serviceKey, grpcClientConfig) =>
214
219
  }
215
220
  }
216
221
  const rawResult = await service[realMethod](req);
217
- const result = (0, exports.recursiveBufferToValue)(rawResult, outputTyping.output);
222
+ const result = (0, exports.postProcessGQLValue)(rawResult, outputTyping.output);
218
223
  const bufferFields = (0, utils_1.getKeys)(grpcClientConfig === null || grpcClientConfig === void 0 ? void 0 : grpcClientConfig.bufferFields);
219
224
  if (result instanceof stream.Readable) {
220
225
  let operationStatus = { code: 0, message: '' };
@@ -1,10 +1,10 @@
1
1
  import { GraphQLEnumTypeConfig, GraphQLInputObjectTypeConfig, GraphQLObjectType, GraphQLObjectTypeConfig } from "graphql";
2
- import { GraphQLEnumType, GraphQLInputObjectType } from "graphql/type/definition";
2
+ import { GraphQLEnumType, GraphQLInputObjectType, GraphQLScalarType } from "graphql/type/definition";
3
3
  import { ProtoMetadata } from "./types";
4
4
  import { DescriptorProto, EnumDescriptorProto, MethodDescriptorProto } from "ts-proto-descriptors";
5
5
  export interface TypingData {
6
- output: GraphQLObjectType | GraphQLEnumType;
7
- input: GraphQLInputObjectType | GraphQLEnumType;
6
+ output: GraphQLObjectType | GraphQLEnumType | GraphQLScalarType;
7
+ input: GraphQLInputObjectType | GraphQLEnumType | GraphQLScalarType;
8
8
  meta: DescriptorProto | EnumDescriptorProto;
9
9
  processor?: any;
10
10
  }
@@ -33,9 +33,24 @@ exports.IGoogleProtobufAny = new definition_1.GraphQLInputObjectType({
33
33
  name: 'IGoogleProtobufAny',
34
34
  fields: protobufAnyFields
35
35
  });
36
+ const DateTime = new definition_1.GraphQLScalarType({
37
+ name: 'DateTime',
38
+ description: `A date-time string at UTC, such as 2007-12-03T10:15:30Z,
39
+ compliant with the date-time format outlined in section 5.6 of
40
+ the RFC 3339 profile of the ISO 8601 standard for representation
41
+ of dates and times using the Gregorian calendar.`,
42
+ });
43
+ const IDateTime = new definition_1.GraphQLScalarType({
44
+ name: 'IDateTime',
45
+ description: `A date-time string at UTC, such as 2007-12-03T10:15:30Z,
46
+ compliant with the date-time format outlined in section 5.6 of
47
+ the RFC 3339 profile of the ISO 8601 standard for representation
48
+ of dates and times using the Gregorian calendar.`,
49
+ });
36
50
  const googleProtobufAnyName = '.google.protobuf.Any';
51
+ const googleProtobufTimestampName = '.google.protobuf.Timestamp';
37
52
  const Mutate = ['Create', 'Update', 'Upsert'];
38
- const CRUD_OPERATION_NAMES = ['Cretae', 'Update', 'Upsert', 'Delete', 'Read'];
53
+ const CRUD_TRAVERSAL_OP_NAMES = ['Cretae', 'Update', 'Upsert', 'Delete', 'Read', 'Traversal'];
39
54
  const TodoScalar = new definition_1.GraphQLScalarType({
40
55
  name: 'TodoScalar',
41
56
  serialize: () => {
@@ -150,7 +165,7 @@ const registerTyping = (protoPackage, message, methodDef, opts, inputOpts) => {
150
165
  insertMode = true;
151
166
  }
152
167
  // add scope
153
- if ((CRUD_OPERATION_NAMES.indexOf(method.name) > -1) && type === method.inputType) {
168
+ if ((CRUD_TRAVERSAL_OP_NAMES.indexOf(method.name) > -1) && type === method.inputType) {
154
169
  crudOperation = true;
155
170
  }
156
171
  }
@@ -164,6 +179,14 @@ const registerTyping = (protoPackage, message, methodDef, opts, inputOpts) => {
164
179
  meta: message
165
180
  });
166
181
  }
182
+ if (type === googleProtobufTimestampName) {
183
+ typeNameAndNameSpaceMapping.set(DateTime.name, type);
184
+ exports.registeredTypings.set(type, {
185
+ output: DateTime,
186
+ input: IDateTime,
187
+ meta: message
188
+ });
189
+ }
167
190
  if (exports.registeredTypings.has(type)) {
168
191
  // TODO Log debug "Typings for object are already registered"
169
192
  return;
@@ -280,6 +303,14 @@ const resolveMeta = (key, field, rootObjType, objName, input) => {
280
303
  result = GoogleProtobufAny;
281
304
  break;
282
305
  }
306
+ if (objType === googleProtobufTimestampName) {
307
+ if (input) {
308
+ result = IDateTime;
309
+ break;
310
+ }
311
+ result = DateTime;
312
+ break;
313
+ }
283
314
  if (!exports.registeredTypings.has(objType)) {
284
315
  throw new Error("Typing '" + objType + "' not registered for key '" + key + "' in object: " + objName);
285
316
  }
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@restorecommerce/facade",
3
- "version": "0.3.11",
3
+ "version": "0.3.14",
4
4
  "description": "Facade for Restorecommerce microservices",
5
5
  "main": "dist/index.js",
6
6
  "typings": "dist/index.d.ts",
@@ -27,7 +27,7 @@
27
27
  "@restorecommerce/grpc-client": "^0.3.1",
28
28
  "@restorecommerce/kafka-client": "^0.3.1",
29
29
  "@restorecommerce/logger": "^0.12.1",
30
- "@restorecommerce/rc-grpc-clients": "^0.4.3",
30
+ "@restorecommerce/rc-grpc-clients": "^0.4.4",
31
31
  "@restorecommerce/service-config": "^0.4.25",
32
32
  "apollo-server-core": "^3.6.3",
33
33
  "apollo-server-koa": "^3.6.3",
@@ -108,5 +108,5 @@
108
108
  "publishConfig": {
109
109
  "access": "public"
110
110
  },
111
- "gitHead": "ff981ea7aa6e49d8437468a26611395f8447d5ab"
111
+ "gitHead": "5077b6ef727b438d0379979d6d80029b2783c1f4"
112
112
  }