gcf-common-lib 0.25.38 → 0.25.40

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/package.json CHANGED
@@ -1,7 +1,7 @@
1
1
  {
2
2
  "name": "gcf-common-lib",
3
3
  "description": "",
4
- "version": "0.25.38",
4
+ "version": "0.25.40",
5
5
  "publishConfig": {
6
6
  "access": "public",
7
7
  "branches": [
@@ -21,7 +21,7 @@
21
21
  "url": "https://github.com/TopTechnologies/gcf-common.git"
22
22
  },
23
23
  "dependencies": {
24
- "@google-cloud/pubsub": "^4.0.0",
24
+ "@google-cloud/pubsub": "^4.0.1",
25
25
  "@google-cloud/secret-manager": "^5.0.0",
26
26
  "@google-cloud/storage": "^7.0.1",
27
27
  "amqplib": "^0.10.3",
package/src/index.js CHANGED
@@ -89,11 +89,14 @@ class GcfCommon {
89
89
  }
90
90
  static publish(event, context, json, attributes) {
91
91
  return __awaiter(this, void 0, void 0, function* () {
92
+ console.time('safeGetAttributes');
92
93
  const { topic, exchange, queue, appId, env, requestId } = yield this.safeGetAttributes(event, context, [
93
94
  'topic',
94
95
  'exchange',
95
96
  'queue',
96
97
  ]);
98
+ console.timeEnd('safeGetAttributes');
99
+ console.time('publish');
97
100
  if (topic && !(0, isEmpty_1.default)(topic)) {
98
101
  console.log('publish:', topic, appId, env, json, attributes);
99
102
  return exports.pubSub.topic(topic).publishMessage({
@@ -117,15 +120,17 @@ class GcfCommon {
117
120
  yield (0, utils_1.publishAmqp)(ch, exchange, queue !== null && queue !== void 0 ? queue : '', json !== null && json !== void 0 ? json : {}, this.amqpOptions.publishOptions);
118
121
  }), this.amqpOptions.url);
119
122
  }
123
+ console.timeEnd('publish');
120
124
  });
121
125
  }
122
126
  static safeGetAttributes(event, context, props) {
123
127
  var _a, _b, _c, _d;
124
128
  return __awaiter(this, void 0, void 0, function* () {
125
129
  let metaOrAttr = this.getMetadataOrAttribute(event, context);
126
- const everyPropIsNil = props.map(prop => (0, lodash_1.get)(metaOrAttr, prop)).every(v => (0, lodash_1.isNil)(v));
130
+ // const everyPropIsNil = props.map(prop => get(metaOrAttr, prop)).every(v => isNil(v));
131
+ const someProp = props.map(prop => (0, lodash_1.get)(metaOrAttr, prop)).some(v => !(0, lodash_1.isNil)(v));
127
132
  // if no prop then check file metadata
128
- if (everyPropIsNil && ((_a = context === null || context === void 0 ? void 0 : context.resource) === null || _a === void 0 ? void 0 : _a.type) === 'storage#object') {
133
+ if (!someProp && ((_a = context === null || context === void 0 ? void 0 : context.resource) === null || _a === void 0 ? void 0 : _a.type) === 'storage#object') {
129
134
  console.log('get metadata from file');
130
135
  if ((context === null || context === void 0 ? void 0 : context.eventType) === 'google.storage.object.finalize') {
131
136
  const gsEvent = event;
package/src/index.ts CHANGED
@@ -68,11 +68,15 @@ export class GcfCommon {
68
68
  }
69
69
 
70
70
  static async publish(event: TEvent, context: TContext, json?: TResponse, attributes?: Dict<any>) {
71
+ console.time('safeGetAttributes');
71
72
  const { topic, exchange, queue, appId, env, requestId } = await this.safeGetAttributes(event, context, [
72
73
  'topic',
73
74
  'exchange',
74
75
  'queue',
75
76
  ]);
77
+ console.timeEnd('safeGetAttributes');
78
+
79
+ console.time('publish');
76
80
 
77
81
  if (topic && !isEmpty(topic)) {
78
82
  console.log('publish:', topic, appId, env, json, attributes);
@@ -105,14 +109,17 @@ export class GcfCommon {
105
109
  await publishAmqp(ch, exchange, queue ?? '', json ?? {}, this.amqpOptions.publishOptions);
106
110
  }, this.amqpOptions.url as string);
107
111
  }
112
+
113
+ console.timeEnd('publish');
108
114
  }
109
115
 
110
116
  static async safeGetAttributes(event: TEvent, context: TContext, props: string[]) {
111
117
  let metaOrAttr = this.getMetadataOrAttribute(event, context);
112
- const everyPropIsNil = props.map(prop => get(metaOrAttr, prop)).every(v => isNil(v));
118
+ // const everyPropIsNil = props.map(prop => get(metaOrAttr, prop)).every(v => isNil(v));
119
+ const someProp = props.map(prop => get(metaOrAttr, prop)).some(v => !isNil(v));
113
120
 
114
121
  // if no prop then check file metadata
115
- if (everyPropIsNil && context?.resource?.type === 'storage#object') {
122
+ if (!someProp && context?.resource?.type === 'storage#object') {
116
123
  console.log('get metadata from file');
117
124
  if (context?.eventType === 'google.storage.object.finalize') {
118
125
  const gsEvent = event as TGSEvent;