gcf-common-lib 0.5.4 → 0.5.5

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 (3) hide show
  1. package/index.js +9 -8
  2. package/index.ts +2 -2
  3. package/package.json +1 -1
package/index.js CHANGED
@@ -119,28 +119,29 @@ var GcfCommon = /** @class */ (function () {
119
119
  * @param {!Object} context Metadata for the event.
120
120
  */
121
121
  GcfCommon.getTopic = function (event, context) {
122
- var _a, _b;
122
+ var _a, _b, _c;
123
123
  return __awaiter(this, void 0, void 0, function () {
124
124
  var pubSub, topicName, storage, file, meta, topic;
125
- return __generator(this, function (_c) {
126
- switch (_c.label) {
125
+ return __generator(this, function (_d) {
126
+ switch (_d.label) {
127
127
  case 0:
128
128
  pubSub = new pubsub_1.PubSub();
129
- if (!(((_a = context === null || context === void 0 ? void 0 : context.resource) === null || _a === void 0 ? void 0 : _a.type) === 'storage#object')) return [3 /*break*/, 2];
129
+ topicName = (_a = event === null || event === void 0 ? void 0 : event.metadata) === null || _a === void 0 ? void 0 : _a.topic;
130
+ if (!(!topicName && ((_b = context === null || context === void 0 ? void 0 : context.resource) === null || _b === void 0 ? void 0 : _b.type) === 'storage#object')) return [3 /*break*/, 2];
130
131
  storage = new storage_1.Storage();
131
132
  file = storage.bucket(event.bucket).file(event.name);
132
133
  return [4 /*yield*/, file.getMetadata()];
133
134
  case 1:
134
- meta = (_c.sent())[0];
135
- topicName = (_b = meta === null || meta === void 0 ? void 0 : meta.metadata) === null || _b === void 0 ? void 0 : _b.topic;
135
+ meta = (_d.sent())[0];
136
+ topicName = (_c = meta === null || meta === void 0 ? void 0 : meta.metadata) === null || _c === void 0 ? void 0 : _c.topic;
136
137
  console.log('topic:', topicName);
137
- _c.label = 2;
138
+ _d.label = 2;
138
139
  case 2:
139
140
  if (!!(0, lodash_1.isEmpty)(topicName)) return [3 /*break*/, 4];
140
141
  topic = pubSub.topic(topicName);
141
142
  return [4 /*yield*/, topic.setMetadata({ labels: { date: topicName.split('__')[1] } })];
142
143
  case 3:
143
- _c.sent();
144
+ _d.sent();
144
145
  return [2 /*return*/, topic];
145
146
  case 4: return [2 /*return*/];
146
147
  }
package/index.ts CHANGED
@@ -50,9 +50,9 @@ export class GcfCommon {
50
50
  const pubSub = new PubSub();
51
51
 
52
52
  /** t_{GUID}__{YYYY-MM-DD} */
53
- let topicName: string | undefined;
53
+ let topicName: string | undefined = event?.metadata?.topic;
54
54
 
55
- if (context?.resource?.type === 'storage#object') {
55
+ if (!topicName && context?.resource?.type === 'storage#object') {
56
56
  const storage = new Storage();
57
57
  const file: File = storage.bucket(event.bucket).file(event.name);
58
58
  const [meta] = await file.getMetadata();
package/package.json CHANGED
@@ -1,7 +1,7 @@
1
1
  {
2
2
  "name": "gcf-common-lib",
3
3
  "description": "",
4
- "version": "0.5.4",
4
+ "version": "0.5.5",
5
5
  "publishConfig": { "access": "public", "branches": ["master"] },
6
6
  "engines": {},
7
7
  "scripts": {