gcf-common-lib 0.25.43 → 0.25.44
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.ts +6 -6
package/package.json
CHANGED
package/src/index.ts
CHANGED
|
@@ -40,10 +40,10 @@ export class GcfCommon {
|
|
|
40
40
|
* @param handler
|
|
41
41
|
* @param timeout Seconds
|
|
42
42
|
*/
|
|
43
|
-
static async process<T extends TResponse>(
|
|
44
|
-
event:
|
|
43
|
+
static async process<T extends TResponse, E = TEvent>(
|
|
44
|
+
event: E,
|
|
45
45
|
context: TContext,
|
|
46
|
-
handler: (event:
|
|
46
|
+
handler: (event: E, context: TContext) => Promise<T> = async (e, c) => e as any,
|
|
47
47
|
timeout = 535,
|
|
48
48
|
) {
|
|
49
49
|
return Promise.race([timeoutAfter(timeout), handler(event, context)])
|
|
@@ -67,7 +67,7 @@ export class GcfCommon {
|
|
|
67
67
|
} as TResponse;
|
|
68
68
|
}
|
|
69
69
|
|
|
70
|
-
static async publish(event:
|
|
70
|
+
static async publish<E = TEvent>(event: E, context: TContext, json?: TResponse, attributes?: Dict<any>) {
|
|
71
71
|
console.time('safeGetAttributes');
|
|
72
72
|
|
|
73
73
|
const { topic, exchange, queue, appId, env, requestId } = await this.safeGetAttributes(event, context, [
|
|
@@ -115,7 +115,7 @@ export class GcfCommon {
|
|
|
115
115
|
console.timeEnd('publish');
|
|
116
116
|
}
|
|
117
117
|
|
|
118
|
-
static async safeGetAttributes(event:
|
|
118
|
+
static async safeGetAttributes<E = TEvent>(event: E, context: TContext, props: string[]) {
|
|
119
119
|
let metaOrAttr = this.getMetadataOrAttribute(event, context);
|
|
120
120
|
// const everyPropIsNil = props.map(prop => get(metaOrAttr, prop)).every(v => isNil(v));
|
|
121
121
|
const someProp = props.map(prop => get(metaOrAttr, prop)).some(v => !isNil(v));
|
|
@@ -142,7 +142,7 @@ export class GcfCommon {
|
|
|
142
142
|
return JSON.parse(options ?? '{}');
|
|
143
143
|
}
|
|
144
144
|
|
|
145
|
-
static getMetadataOrAttribute(event:
|
|
145
|
+
static getMetadataOrAttribute<E = TEvent>(event: E, context: TContext) {
|
|
146
146
|
let metadataOrAttribute: TMetadataOrAttributes | undefined;
|
|
147
147
|
|
|
148
148
|
switch (context?.eventType) {
|