gcf-common-lib 0.25.53 → 0.25.54
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 +1 -1
- package/src/index.js +9 -9
- package/src/index.ts +15 -21
- package/src/types.ts +9 -8
package/package.json
CHANGED
package/src/index.js
CHANGED
|
@@ -90,36 +90,36 @@ class GcfCommon {
|
|
|
90
90
|
static publish(event, context, json, attributes) {
|
|
91
91
|
return __awaiter(this, void 0, void 0, function* () {
|
|
92
92
|
console.time('safeGetAttributes');
|
|
93
|
-
const { topic, exchange, queue,
|
|
93
|
+
const { topic, exchange, queue, consumer_id, request_id, app_id, env } = yield this.safeGetAttributes(event, context, ['consumer_id', 'topic', 'exchange', 'queue']);
|
|
94
94
|
console.timeEnd('safeGetAttributes');
|
|
95
95
|
//
|
|
96
96
|
console.time('publish');
|
|
97
97
|
if (topic && !(0, isEmpty_1.default)(topic)) {
|
|
98
|
-
console.log('send:', topic,
|
|
98
|
+
console.log('send:', topic, app_id, env, json, attributes);
|
|
99
99
|
yield exports.pubSub.topic(topic).publishMessage({
|
|
100
100
|
json: json !== null && json !== void 0 ? json : {},
|
|
101
|
-
attributes: Object.assign(Object.assign({}, (0, lodash_1.mapValues)(attributes !== null && attributes !== void 0 ? attributes : {}, v => '' + v)), {
|
|
101
|
+
attributes: Object.assign(Object.assign({}, (0, lodash_1.mapValues)(attributes !== null && attributes !== void 0 ? attributes : {}, v => '' + v)), { consumer_id: consumer_id !== null && consumer_id !== void 0 ? consumer_id : '', request_id: request_id !== null && request_id !== void 0 ? request_id : '', app_id: app_id !== null && app_id !== void 0 ? app_id : '', env: env !== null && env !== void 0 ? env : '' }),
|
|
102
102
|
});
|
|
103
103
|
}
|
|
104
104
|
if (exchange && !(0, isEmpty_1.default)(exchange)) {
|
|
105
|
-
console.log('send:', exchange, queue,
|
|
105
|
+
console.log('send:', exchange, queue, app_id, env, json, attributes);
|
|
106
106
|
yield (0, utils_1.withAmqpCh)((ch) => __awaiter(this, void 0, void 0, function* () {
|
|
107
107
|
yield ch.assertExchange(exchange, 'direct', this.amqpOptions.assertExchange);
|
|
108
|
-
yield (0, utils_1.publishAmqp)(ch, exchange, queue !== null && queue !== void 0 ? queue : '', json !== null && json !== void 0 ? json : {}, Object.assign(Object.assign({}, this.amqpOptions.publishOptions), { correlationId:
|
|
108
|
+
yield (0, utils_1.publishAmqp)(ch, exchange, queue !== null && queue !== void 0 ? queue : '', json !== null && json !== void 0 ? json : {}, Object.assign(Object.assign({}, this.amqpOptions.publishOptions), { correlationId: request_id }));
|
|
109
109
|
}), this.amqpOptions.url);
|
|
110
110
|
}
|
|
111
111
|
else if (queue && !(0, isEmpty_1.default)(queue)) {
|
|
112
|
-
console.log('send:', queue,
|
|
112
|
+
console.log('send:', queue, app_id, env, json, attributes);
|
|
113
113
|
yield (0, utils_1.withAmqpCh)((ch) => __awaiter(this, void 0, void 0, function* () {
|
|
114
114
|
yield ch.assertQueue(queue, this.amqpOptions.assertOptions);
|
|
115
|
-
yield (0, utils_1.publishAmqp)(ch, undefined, queue, json !== null && json !== void 0 ? json : {}, Object.assign(Object.assign({}, this.amqpOptions.publishOptions), { correlationId:
|
|
115
|
+
yield (0, utils_1.publishAmqp)(ch, undefined, queue, json !== null && json !== void 0 ? json : {}, Object.assign(Object.assign({}, this.amqpOptions.publishOptions), { correlationId: request_id }));
|
|
116
116
|
}), this.amqpOptions.url);
|
|
117
117
|
}
|
|
118
118
|
console.timeEnd('publish');
|
|
119
119
|
});
|
|
120
120
|
}
|
|
121
121
|
static safeGetAttributes(event, context, props) {
|
|
122
|
-
var _a, _b
|
|
122
|
+
var _a, _b;
|
|
123
123
|
return __awaiter(this, void 0, void 0, function* () {
|
|
124
124
|
let metaOrAttr = this.getMetadataOrAttribute(event, context);
|
|
125
125
|
// const everyPropIsNil = props.map(prop => get(metaOrAttr, prop)).every(v => isNil(v));
|
|
@@ -133,7 +133,7 @@ class GcfCommon {
|
|
|
133
133
|
metaOrAttr = (_b = meta === null || meta === void 0 ? void 0 : meta.metadata) !== null && _b !== void 0 ? _b : {};
|
|
134
134
|
}
|
|
135
135
|
}
|
|
136
|
-
return Object.assign(Object.assign({}, metaOrAttr), {
|
|
136
|
+
return Object.assign(Object.assign({}, metaOrAttr), { app_id: metaOrAttr.app_id, request_id: metaOrAttr.request_id });
|
|
137
137
|
});
|
|
138
138
|
}
|
|
139
139
|
static getOptions(event, context) {
|
package/src/index.ts
CHANGED
|
@@ -70,14 +70,11 @@ export class GcfCommon {
|
|
|
70
70
|
static async publish<E = TEvent>(event: E, context: TContext, json?: TResponse, attributes?: Dict<any>) {
|
|
71
71
|
console.time('safeGetAttributes');
|
|
72
72
|
|
|
73
|
-
const {
|
|
74
|
-
|
|
75
|
-
|
|
76
|
-
queue,
|
|
77
|
-
|
|
78
|
-
env,
|
|
79
|
-
'request-id': requestId,
|
|
80
|
-
} = await this.safeGetAttributes(event, context, ['topic', 'exchange', 'queue']);
|
|
73
|
+
const { topic, exchange, queue, consumer_id, request_id, app_id, env } = await this.safeGetAttributes(
|
|
74
|
+
event,
|
|
75
|
+
context,
|
|
76
|
+
['consumer_id', 'topic', 'exchange', 'queue'],
|
|
77
|
+
);
|
|
81
78
|
|
|
82
79
|
console.timeEnd('safeGetAttributes');
|
|
83
80
|
|
|
@@ -86,36 +83,35 @@ export class GcfCommon {
|
|
|
86
83
|
console.time('publish');
|
|
87
84
|
|
|
88
85
|
if (topic && !isEmpty(topic)) {
|
|
89
|
-
console.log('send:', topic,
|
|
86
|
+
console.log('send:', topic, app_id, env, json, attributes);
|
|
90
87
|
await pubSub.topic(topic).publishMessage({
|
|
91
88
|
json: json ?? {},
|
|
92
89
|
attributes: {
|
|
93
90
|
...mapValues(attributes ?? {}, v => '' + v),
|
|
94
|
-
|
|
95
|
-
|
|
96
|
-
|
|
97
|
-
appId: appId ?? '',
|
|
91
|
+
consumer_id: consumer_id ?? '',
|
|
92
|
+
request_id: request_id ?? '',
|
|
93
|
+
app_id: app_id ?? '',
|
|
98
94
|
env: env ?? '',
|
|
99
95
|
} as TMetadataOrAttributes,
|
|
100
96
|
});
|
|
101
97
|
}
|
|
102
98
|
|
|
103
99
|
if (exchange && !isEmpty(exchange)) {
|
|
104
|
-
console.log('send:', exchange, queue,
|
|
100
|
+
console.log('send:', exchange, queue, app_id, env, json, attributes);
|
|
105
101
|
await withAmqpCh(async ch => {
|
|
106
102
|
await ch.assertExchange(exchange, 'direct', this.amqpOptions.assertExchange);
|
|
107
103
|
await publishAmqp(ch, exchange, queue ?? '', json ?? {}, {
|
|
108
104
|
...this.amqpOptions.publishOptions,
|
|
109
|
-
correlationId:
|
|
105
|
+
correlationId: request_id,
|
|
110
106
|
});
|
|
111
107
|
}, this.amqpOptions.url as string);
|
|
112
108
|
} else if (queue && !isEmpty(queue)) {
|
|
113
|
-
console.log('send:', queue,
|
|
109
|
+
console.log('send:', queue, app_id, env, json, attributes);
|
|
114
110
|
await withAmqpCh(async ch => {
|
|
115
111
|
await ch.assertQueue(queue, this.amqpOptions.assertOptions);
|
|
116
112
|
await publishAmqp(ch, undefined, queue, json ?? {}, {
|
|
117
113
|
...this.amqpOptions.publishOptions,
|
|
118
|
-
correlationId:
|
|
114
|
+
correlationId: request_id,
|
|
119
115
|
});
|
|
120
116
|
}, this.amqpOptions.url as string);
|
|
121
117
|
}
|
|
@@ -140,10 +136,8 @@ export class GcfCommon {
|
|
|
140
136
|
|
|
141
137
|
return {
|
|
142
138
|
...metaOrAttr,
|
|
143
|
-
|
|
144
|
-
|
|
145
|
-
'request-id': metaOrAttr['request-id'] ?? (metaOrAttr as any).requestId,
|
|
146
|
-
requestId: metaOrAttr['request-id'] ?? (metaOrAttr as any).requestId,
|
|
139
|
+
app_id: metaOrAttr.app_id,
|
|
140
|
+
request_id: metaOrAttr.request_id,
|
|
147
141
|
} as TMetadataOrAttributes;
|
|
148
142
|
}
|
|
149
143
|
|
package/src/types.ts
CHANGED
|
@@ -31,26 +31,27 @@ export type TPSEvent<A = TMetadataOrAttributes> = {
|
|
|
31
31
|
export type TEvent = TGSEvent | TPSEvent;
|
|
32
32
|
|
|
33
33
|
export type TMetadataOrAttributes = {
|
|
34
|
-
|
|
34
|
+
request_id?: string; // for rpc response [GUID]
|
|
35
|
+
consumer_id?: string; // for rpc response [GUID]
|
|
35
36
|
topic?: string; // response PubSub topic [t_{GUID}__{YYYY-MM-DD}]
|
|
36
37
|
exchange?: string; // response amqp exchange
|
|
37
38
|
queue?: string; // response amqp queue
|
|
38
39
|
//
|
|
39
40
|
filename?: string;
|
|
40
41
|
referer?: string;
|
|
41
|
-
|
|
42
|
-
|
|
43
|
-
|
|
42
|
+
remote_address?: string;
|
|
43
|
+
upload_id?: string;
|
|
44
|
+
user_agent?: string;
|
|
44
45
|
timestamp?: string;
|
|
45
46
|
//
|
|
46
47
|
action?: string;
|
|
47
48
|
pipeline?: string;
|
|
48
49
|
options?: string;
|
|
49
|
-
|
|
50
|
-
|
|
51
|
-
|
|
50
|
+
job_uid?: string;
|
|
51
|
+
user_id?: string;
|
|
52
|
+
tenant_id?: string;
|
|
52
53
|
//
|
|
53
|
-
|
|
54
|
+
app_id?: string; // app id
|
|
54
55
|
env?: string; // app environment
|
|
55
56
|
};
|
|
56
57
|
|