gcf-common-lib 0.14.3 → 0.15.3
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/index.js +11 -10
- package/index.ts +7 -5
- package/package.json +1 -1
package/index.js
CHANGED
|
@@ -56,44 +56,45 @@ class GcfCommon {
|
|
|
56
56
|
});
|
|
57
57
|
}
|
|
58
58
|
static publish(event, context, json, attributes) {
|
|
59
|
-
var _a, _b, _c;
|
|
60
59
|
return __awaiter(this, void 0, void 0, function* () {
|
|
61
|
-
const topic = yield this.getTopic(event, context);
|
|
60
|
+
const { topic, requestId } = yield this.getTopic(event, context);
|
|
62
61
|
console.log('publish:', topic === null || topic === void 0 ? void 0 : topic.name, json, attributes);
|
|
63
62
|
if (topic) {
|
|
64
63
|
return topic.publishMessage({
|
|
65
64
|
json,
|
|
66
|
-
attributes: Object.assign(Object.assign({}, attributes), { requestId:
|
|
65
|
+
attributes: Object.assign(Object.assign({}, attributes), { requestId: requestId !== null && requestId !== void 0 ? requestId : '', type: 'response', response: '1' }),
|
|
67
66
|
});
|
|
68
67
|
}
|
|
69
68
|
});
|
|
70
69
|
}
|
|
71
70
|
static getTopic(event, context) {
|
|
72
|
-
var _a, _b, _c, _d, _e, _f;
|
|
71
|
+
var _a, _b, _c, _d, _e, _f, _g, _h, _j, _k, _l;
|
|
73
72
|
return __awaiter(this, void 0, void 0, function* () {
|
|
74
73
|
/** t_{GUID}__{YYYY-MM-DD} */
|
|
75
74
|
let topicName;
|
|
75
|
+
let requestId;
|
|
76
76
|
switch (context === null || context === void 0 ? void 0 : context.eventType) {
|
|
77
77
|
case 'google.storage.object.finalize': {
|
|
78
78
|
const gsEvent = event;
|
|
79
79
|
topicName = (_a = gsEvent === null || gsEvent === void 0 ? void 0 : gsEvent.metadata) === null || _a === void 0 ? void 0 : _a.topic;
|
|
80
|
-
|
|
80
|
+
requestId = (_b = gsEvent === null || gsEvent === void 0 ? void 0 : gsEvent.metadata) === null || _b === void 0 ? void 0 : _b.requestId;
|
|
81
|
+
if (!topicName && ((_c = context === null || context === void 0 ? void 0 : context.resource) === null || _c === void 0 ? void 0 : _c.type) === 'storage#object') {
|
|
81
82
|
const file = exports.storage.bucket(gsEvent.bucket).file(gsEvent.name);
|
|
82
83
|
const [meta] = yield file.getMetadata();
|
|
83
|
-
topicName = (
|
|
84
|
+
topicName = (_d = meta === null || meta === void 0 ? void 0 : meta.metadata) === null || _d === void 0 ? void 0 : _d.topic;
|
|
85
|
+
requestId = (_e = meta === null || meta === void 0 ? void 0 : meta.metadata) === null || _e === void 0 ? void 0 : _e.requestId;
|
|
84
86
|
}
|
|
85
87
|
break;
|
|
86
88
|
}
|
|
87
89
|
case 'google.pubsub.topic.publish': {
|
|
88
90
|
const psEvent = event;
|
|
89
|
-
topicName = (
|
|
91
|
+
topicName = (_g = (_f = psEvent.attributes) === null || _f === void 0 ? void 0 : _f.topic) !== null && _g !== void 0 ? _g : (_h = psEvent.data) === null || _h === void 0 ? void 0 : _h.topic;
|
|
92
|
+
requestId = (_k = (_j = psEvent.attributes) === null || _j === void 0 ? void 0 : _j.requestId) !== null && _k !== void 0 ? _k : (_l = psEvent.data) === null || _l === void 0 ? void 0 : _l.requestId;
|
|
90
93
|
break;
|
|
91
94
|
}
|
|
92
95
|
}
|
|
93
96
|
console.log('topic:', topicName);
|
|
94
|
-
|
|
95
|
-
return exports.pubSub.topic(topicName);
|
|
96
|
-
}
|
|
97
|
+
return !(0, isEmpty_1.default)(topicName) ? { topic: exports.pubSub.topic(topicName), requestId } : {};
|
|
97
98
|
});
|
|
98
99
|
}
|
|
99
100
|
static getOptions(event, context) {
|
package/index.ts
CHANGED
|
@@ -95,7 +95,7 @@ export class GcfCommon {
|
|
|
95
95
|
}
|
|
96
96
|
|
|
97
97
|
static async publish(event: TEvent, context: TContext, json: TResponse, attributes?: any) {
|
|
98
|
-
const topic = await this.getTopic(event, context);
|
|
98
|
+
const {topic, requestId} = await this.getTopic(event, context);
|
|
99
99
|
console.log('publish:', topic?.name, json, attributes);
|
|
100
100
|
|
|
101
101
|
if (topic) {
|
|
@@ -103,7 +103,7 @@ export class GcfCommon {
|
|
|
103
103
|
json,
|
|
104
104
|
attributes: {
|
|
105
105
|
...attributes,
|
|
106
|
-
requestId:
|
|
106
|
+
requestId: requestId ?? '',
|
|
107
107
|
type: 'response',
|
|
108
108
|
response: '1',
|
|
109
109
|
},
|
|
@@ -115,30 +115,32 @@ export class GcfCommon {
|
|
|
115
115
|
|
|
116
116
|
/** t_{GUID}__{YYYY-MM-DD} */
|
|
117
117
|
let topicName: string;
|
|
118
|
+
let requestId: string;
|
|
118
119
|
|
|
119
120
|
switch (context?.eventType) {
|
|
120
121
|
case 'google.storage.object.finalize': {
|
|
121
122
|
const gsEvent = event as TGSEvent;
|
|
122
123
|
topicName = gsEvent?.metadata?.topic;
|
|
124
|
+
requestId = gsEvent?.metadata?.requestId;
|
|
123
125
|
if (!topicName && context?.resource?.type === 'storage#object') {
|
|
124
126
|
const file: File = storage.bucket(gsEvent.bucket).file(gsEvent.name);
|
|
125
127
|
const [meta] = await file.getMetadata();
|
|
126
128
|
topicName = meta?.metadata?.topic;
|
|
129
|
+
requestId = meta?.metadata?.requestId;
|
|
127
130
|
}
|
|
128
131
|
break;
|
|
129
132
|
}
|
|
130
133
|
case 'google.pubsub.topic.publish' : {
|
|
131
134
|
const psEvent = event as TPSEvent;
|
|
132
135
|
topicName = psEvent.attributes?.topic ?? (psEvent.data as any)?.topic;
|
|
136
|
+
requestId = psEvent.attributes?.requestId ?? (psEvent.data as any)?.requestId;
|
|
133
137
|
break;
|
|
134
138
|
}
|
|
135
139
|
}
|
|
136
140
|
|
|
137
141
|
console.log('topic:', topicName);
|
|
138
142
|
|
|
139
|
-
|
|
140
|
-
return pubSub.topic(topicName)
|
|
141
|
-
}
|
|
143
|
+
return !isEmpty(topicName) ? {topic: pubSub.topic(topicName), requestId} : {};
|
|
142
144
|
}
|
|
143
145
|
|
|
144
146
|
static async getOptions(event: TGSEvent, context: TContext) {
|