@shushed/helpers 0.0.227 → 0.0.228

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.
@@ -83,35 +83,36 @@ class PubSubHelper extends runtime_1.default {
83
83
  const messageIds = [];
84
84
  for (let i = 0; i < batches.length; i++) {
85
85
  const batch = batches[i];
86
- const results = await Promise.allSettled(batch.map((x) => {
86
+ const results = await Promise.allSettled(batch.map((x, index) => {
87
87
  if (options.attributesGenerator) {
88
- nextAttributes = Object.fromEntries(Object.entries(options.attributesGenerator(x)).filter(([_, v]) => v !== undefined && v !== null).map(([k, v]) => [k, typeof v === 'boolean' ? (v ? 'yes' : 'no') : `${v}`]));
88
+ nextAttributes = Object.fromEntries(Object.entries(options.attributesGenerator(x, index)).filter(([_, v]) => v !== undefined && v !== null).map(([k, v]) => [k, typeof v === 'boolean' ? (v ? 'yes' : 'no') : `${v}`]));
89
89
  }
90
90
  if (typeof options.extraAttributes === 'function') {
91
- nextAttributes = Object.fromEntries(Object.entries(options.extraAttributes ? Object.assign({}, nextAttributes, options.extraAttributes(x)) : nextAttributes).filter(([_, v]) => v !== undefined && v !== null).map(([k, v]) => [k, typeof v === 'boolean' ? (v ? 'yes' : 'no') : `${v}`]));
91
+ nextAttributes = Object.fromEntries(Object.entries(options.extraAttributes ? Object.assign({}, nextAttributes, options.extraAttributes(x, index)) : nextAttributes).filter(([_, v]) => v !== undefined && v !== null).map(([k, v]) => [k, typeof v === 'boolean' ? (v ? 'yes' : 'no') : `${v}`]));
92
92
  }
93
93
  else if (typeof options.extraAttributes === 'object') {
94
- for (const key in options.extraAttributes) {
95
- let resultForKey;
96
- if (typeof options.extraAttributes[key] === 'function') {
97
- resultForKey = options.extraAttributes[key](x);
98
- }
99
- else {
100
- resultForKey = options.extraAttributes[key];
101
- }
102
- if (typeof resultForKey === 'boolean') {
103
- nextAttributes[key] = resultForKey ? 'yes' : 'no';
104
- }
105
- else {
106
- nextAttributes[key] = `${resultForKey}`;
107
- }
94
+ nextAttributes = Object.assign({}, nextAttributes, options.extraAttributes);
95
+ }
96
+ for (const key in nextAttributes) {
97
+ let resultForKey;
98
+ if (typeof nextAttributes[key] === 'function') {
99
+ resultForKey = nextAttributes[key](x, index);
100
+ }
101
+ else {
102
+ resultForKey = nextAttributes[key];
103
+ }
104
+ if (typeof resultForKey === 'boolean') {
105
+ nextAttributes[key] = resultForKey ? 'yes' : 'no';
106
+ }
107
+ else {
108
+ nextAttributes[key] = `${resultForKey}`;
108
109
  }
109
- nextAttributes = Object.assign(nextAttributes, {
110
- source_system: options.sourceSystem,
111
- target_system: options.targetSystem,
112
- buildship_id: this.systemEnvName + '-' + this.workflowId + '-' + this.triggerId,
113
- });
114
110
  }
111
+ nextAttributes = Object.assign(nextAttributes, {
112
+ source_system: options.sourceSystem,
113
+ target_system: options.targetSystem,
114
+ buildship_id: this.systemEnvName + '-' + this.workflowId + '-' + this.triggerId,
115
+ });
115
116
  return topic.publishMessage({
116
117
  data: Buffer.from(JSON.stringify(x)),
117
118
  attributes: nextAttributes
@@ -5,7 +5,7 @@ declare global {
5
5
  var HUSH_PUBSUB_PUBLISH_TOPICS: Record<string, Topic>;
6
6
  }
7
7
  export declare function isSubscriptionBigQuery(opts: SubscriptionOptionsBigQuery | SubscriptionOptionsPull): opts is SubscriptionOptionsBigQuery;
8
- type PublishAttributesGenerator<T> = (payload: any) => T;
8
+ type PublishAttributesGenerator<T> = (payload: any, index: number) => T;
9
9
  type PublishAttributes = PublishAttributesGenerator<Record<string, string>> | Record<string, string> | Record<string, PublishAttributesGenerator<string | boolean | number> | boolean | number>;
10
10
  export type Message = {
11
11
  buildshipId: string;
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@shushed/helpers",
3
- "version": "0.0.227",
3
+ "version": "0.0.228",
4
4
  "author": "",
5
5
  "license": "UNLICENSED",
6
6
  "description": "",