@google-cloud/pubsub 5.1.0 → 5.2.1

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 (44) hide show
  1. package/README.md +2 -1
  2. package/build/protos/protos.d.ts +519 -5
  3. package/build/protos/protos.js +1695 -22
  4. package/build/protos/protos.json +201 -23
  5. package/build/src/exponential-retry.js +3 -3
  6. package/build/src/exponential-retry.js.map +1 -1
  7. package/build/src/index.d.ts +1 -1
  8. package/build/src/index.js +2 -1
  9. package/build/src/index.js.map +1 -1
  10. package/build/src/lease-manager.d.ts +18 -0
  11. package/build/src/lease-manager.js +52 -2
  12. package/build/src/lease-manager.js.map +1 -1
  13. package/build/src/logs.d.ts +9 -0
  14. package/build/src/logs.js +26 -0
  15. package/build/src/logs.js.map +1 -0
  16. package/build/src/message-queues.d.ts +25 -1
  17. package/build/src/message-queues.js +55 -5
  18. package/build/src/message-queues.js.map +1 -1
  19. package/build/src/message-stream.d.ts +8 -0
  20. package/build/src/message-stream.js +37 -14
  21. package/build/src/message-stream.js.map +1 -1
  22. package/build/src/publisher/message-batch.d.ts +26 -1
  23. package/build/src/publisher/message-batch.js +41 -6
  24. package/build/src/publisher/message-batch.js.map +1 -1
  25. package/build/src/publisher/message-queues.d.ts +22 -5
  26. package/build/src/publisher/message-queues.js +52 -19
  27. package/build/src/publisher/message-queues.js.map +1 -1
  28. package/build/src/pubsub.d.ts +25 -6
  29. package/build/src/pubsub.js.map +1 -1
  30. package/build/src/subscriber.d.ts +70 -4
  31. package/build/src/subscriber.js +154 -9
  32. package/build/src/subscriber.js.map +1 -1
  33. package/build/src/subscription.d.ts +11 -13
  34. package/build/src/subscription.js +2 -1
  35. package/build/src/subscription.js.map +1 -1
  36. package/build/src/telemetry-tracing.js +2 -2
  37. package/build/src/telemetry-tracing.js.map +1 -1
  38. package/build/src/temporal.d.ts +66 -4
  39. package/build/src/temporal.js +104 -4
  40. package/build/src/temporal.js.map +1 -1
  41. package/build/src/util.d.ts +22 -0
  42. package/build/src/util.js +36 -0
  43. package/build/src/util.js.map +1 -1
  44. package/package.json +4 -4
@@ -6,14 +6,27 @@ export interface DurationLike {
6
6
  hours?: number;
7
7
  minutes?: number;
8
8
  seconds?: number;
9
+ milliseconds?: number;
10
+ /**
11
+ * tc39 has renamed this to milliseconds.
12
+ *
13
+ * @deprecated
14
+ */
9
15
  millis?: number;
10
16
  }
11
17
  /**
12
18
  * Simplified list of values to pass to Duration.totalOf(). This
13
19
  * list is taken from the tc39 Temporal.Duration proposal, but
14
- * larger and smaller units have been left off.
20
+ * larger and smaller units have been left off. The latest tc39 spec
21
+ * allows for both singular and plural forms.
22
+ */
23
+ export type TotalOfUnit = 'hour' | 'minute' | 'second' | 'millisecond' | 'hours' | 'minutes' | 'seconds' | 'milliseconds';
24
+ /**
25
+ * Is it a Duration or a DurationLike?
26
+ *
27
+ * @private
15
28
  */
16
- export type TotalOfUnit = 'hour' | 'minute' | 'second' | 'millisecond';
29
+ export declare function isDurationObject(value: unknown): value is Duration;
17
30
  /**
18
31
  * Duration class with an interface similar to the tc39 Temporal
19
32
  * proposal. Since it's not fully finalized, and polyfills have
@@ -21,9 +34,10 @@ export type TotalOfUnit = 'hour' | 'minute' | 'second' | 'millisecond';
21
34
  * used to set durations in Pub/Sub.
22
35
  *
23
36
  * This class will remain here for at least the next major version,
24
- * eventually to be replaced by the tc39 Temporal built-in.
37
+ * eventually to be replaced by the tc39 Temporal.Duration built-in.
25
38
  *
26
39
  * https://tc39.es/proposal-temporal/docs/duration.html
40
+ * https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/Temporal/Duration
27
41
  */
28
42
  export declare class Duration {
29
43
  private millis;
@@ -34,12 +48,60 @@ export declare class Duration {
34
48
  /**
35
49
  * Calculates the total number of units of type 'totalOf' that would
36
50
  * fit inside this duration.
51
+ *
52
+ * No longer part of the tc39 spec, superseded by total().
53
+ *
54
+ * @deprecated
37
55
  */
38
56
  totalOf(totalOf: TotalOfUnit): number;
57
+ /**
58
+ * Calculates the total number of units of type 'totalOf' that would
59
+ * fit inside this duration. The tc39 `options` parameter is not supported.
60
+ */
61
+ total(totalOf: TotalOfUnit): number;
62
+ /**
63
+ * Equivalent to `total('hour')`.
64
+ */
65
+ get hours(): number;
66
+ /**
67
+ * Equivalent to `total('minute')`.
68
+ */
69
+ get minutes(): number;
70
+ /**
71
+ * Equivalent to `total('second')`.
72
+ */
73
+ get seconds(): number;
74
+ /**
75
+ * Equivalent to `total('millisecond')`.
76
+ */
77
+ get milliseconds(): number;
78
+ /**
79
+ * Adds another Duration to this one and returns a new Duration.
80
+ *
81
+ * @param other A Duration or Duration-like object, like from() takes.
82
+ * @returns A new Duration.
83
+ */
84
+ add(other: DurationLike | Duration): Duration;
85
+ /**
86
+ * Subtracts another Duration from this one and returns a new Duration.
87
+ *
88
+ * @param other A Duration or Duration-like object, like from() takes.
89
+ * @returns A new Duration.
90
+ */
91
+ subtract(other: DurationLike | Duration): Duration;
39
92
  /**
40
93
  * Creates a Duration from a DurationLike, which is an object
41
94
  * containing zero or more of the following: hours, seconds,
42
95
  * minutes, millis.
43
96
  */
44
- static from(durationLike: DurationLike): Duration;
97
+ static from(durationLike: DurationLike | Duration): Duration;
98
+ /**
99
+ * Compare two Duration objects. Returns -1 if the first is less than the
100
+ * second, zero if they are equal, 1 if the first is greater than the second.
101
+ *
102
+ * Unlike tc39, this version does not accept options for relativeTo.
103
+ */
104
+ static compare(first: Duration, second: Duration): 0 | 1 | -1;
45
105
  }
106
+ export declare const atLeast: (d: Duration, min: Duration) => Duration;
107
+ export declare const atMost: (d: Duration, max: Duration) => Duration;
@@ -13,7 +13,16 @@
13
13
  // See the License for the specific language governing permissions and
14
14
  // limitations under the License.
15
15
  Object.defineProperty(exports, "__esModule", { value: true });
16
- exports.Duration = void 0;
16
+ exports.atMost = exports.atLeast = exports.Duration = void 0;
17
+ exports.isDurationObject = isDurationObject;
18
+ /**
19
+ * Is it a Duration or a DurationLike?
20
+ *
21
+ * @private
22
+ */
23
+ function isDurationObject(value) {
24
+ return typeof value === 'object' && !!value.total;
25
+ }
17
26
  /**
18
27
  * Duration class with an interface similar to the tc39 Temporal
19
28
  * proposal. Since it's not fully finalized, and polyfills have
@@ -21,9 +30,10 @@ exports.Duration = void 0;
21
30
  * used to set durations in Pub/Sub.
22
31
  *
23
32
  * This class will remain here for at least the next major version,
24
- * eventually to be replaced by the tc39 Temporal built-in.
33
+ * eventually to be replaced by the tc39 Temporal.Duration built-in.
25
34
  *
26
35
  * https://tc39.es/proposal-temporal/docs/duration.html
36
+ * https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/Temporal/Duration
27
37
  */
28
38
  class Duration {
29
39
  millis;
@@ -36,33 +46,123 @@ class Duration {
36
46
  /**
37
47
  * Calculates the total number of units of type 'totalOf' that would
38
48
  * fit inside this duration.
49
+ *
50
+ * No longer part of the tc39 spec, superseded by total().
51
+ *
52
+ * @deprecated
39
53
  */
40
54
  totalOf(totalOf) {
55
+ return this.total(totalOf);
56
+ }
57
+ /**
58
+ * Calculates the total number of units of type 'totalOf' that would
59
+ * fit inside this duration. The tc39 `options` parameter is not supported.
60
+ */
61
+ total(totalOf) {
41
62
  switch (totalOf) {
42
63
  case 'hour':
64
+ case 'hours':
43
65
  return this.millis / Duration.hourInMillis;
44
66
  case 'minute':
67
+ case 'minutes':
45
68
  return this.millis / Duration.minuteInMillis;
46
69
  case 'second':
70
+ case 'seconds':
47
71
  return this.millis / Duration.secondInMillis;
48
72
  case 'millisecond':
73
+ case 'milliseconds':
49
74
  return this.millis;
50
75
  default:
51
- throw new Error(`Invalid unit in call to totalOf(): ${totalOf}`);
76
+ throw new Error(`Invalid unit in call to total(): ${totalOf}`);
52
77
  }
53
78
  }
79
+ /**
80
+ * Equivalent to `total('hour')`.
81
+ */
82
+ get hours() {
83
+ return this.total('hour');
84
+ }
85
+ /**
86
+ * Equivalent to `total('minute')`.
87
+ */
88
+ get minutes() {
89
+ return this.total('minute');
90
+ }
91
+ /**
92
+ * Equivalent to `total('second')`.
93
+ */
94
+ get seconds() {
95
+ return this.total('second');
96
+ }
97
+ /**
98
+ * Equivalent to `total('millisecond')`.
99
+ */
100
+ get milliseconds() {
101
+ return this.total('millisecond');
102
+ }
103
+ /**
104
+ * Adds another Duration to this one and returns a new Duration.
105
+ *
106
+ * @param other A Duration or Duration-like object, like from() takes.
107
+ * @returns A new Duration.
108
+ */
109
+ add(other) {
110
+ const otherDuration = Duration.from(other);
111
+ return Duration.from({
112
+ millis: this.milliseconds + otherDuration.milliseconds,
113
+ });
114
+ }
115
+ /**
116
+ * Subtracts another Duration from this one and returns a new Duration.
117
+ *
118
+ * @param other A Duration or Duration-like object, like from() takes.
119
+ * @returns A new Duration.
120
+ */
121
+ subtract(other) {
122
+ const otherDuration = Duration.from(other);
123
+ return Duration.from({
124
+ millis: this.milliseconds - otherDuration.milliseconds,
125
+ });
126
+ }
54
127
  /**
55
128
  * Creates a Duration from a DurationLike, which is an object
56
129
  * containing zero or more of the following: hours, seconds,
57
130
  * minutes, millis.
58
131
  */
59
132
  static from(durationLike) {
60
- let millis = durationLike.millis ?? 0;
133
+ if (isDurationObject(durationLike)) {
134
+ const d = durationLike;
135
+ return new Duration(d.milliseconds);
136
+ }
137
+ let millis = durationLike.milliseconds ?? durationLike.millis ?? 0;
61
138
  millis += (durationLike.seconds ?? 0) * Duration.secondInMillis;
62
139
  millis += (durationLike.minutes ?? 0) * Duration.minuteInMillis;
63
140
  millis += (durationLike.hours ?? 0) * Duration.hourInMillis;
64
141
  return new Duration(millis);
65
142
  }
143
+ /**
144
+ * Compare two Duration objects. Returns -1 if the first is less than the
145
+ * second, zero if they are equal, 1 if the first is greater than the second.
146
+ *
147
+ * Unlike tc39, this version does not accept options for relativeTo.
148
+ */
149
+ static compare(first, second) {
150
+ const diffMs = first.total('millisecond') - second.total('millisecond');
151
+ if (diffMs < 0) {
152
+ return -1;
153
+ }
154
+ if (diffMs > 0) {
155
+ return 1;
156
+ }
157
+ return 0;
158
+ }
66
159
  }
67
160
  exports.Duration = Duration;
161
+ // Simple accessors that can be used independent of the class. These are
162
+ // functions and not methods because we don't want to add to what's in
163
+ // the tc39 spec.
164
+ const atLeast = (d, min) => Duration.compare(d, min) < 0 ? min : d;
165
+ exports.atLeast = atLeast;
166
+ const atMost = (d, max) => Duration.compare(d, max) > 0 ? max : d;
167
+ exports.atMost = atMost;
68
168
  //# sourceMappingURL=temporal.js.map
@@ -1 +1 @@
1
- {"version":3,"file":"temporal.js","sourceRoot":"","sources":["../../src/temporal.ts"],"names":[],"mappings":";AAAA,4BAA4B;AAC5B,EAAE;AACF,kEAAkE;AAClE,mEAAmE;AACnE,0CAA0C;AAC1C,EAAE;AACF,kDAAkD;AAClD,EAAE;AACF,sEAAsE;AACtE,oEAAoE;AACpE,2EAA2E;AAC3E,sEAAsE;AACtE,iCAAiC;;;AA6BjC;;;;;;;;;;GAUG;AACH,MAAa,QAAQ;IACX,MAAM,CAAS;IAEf,MAAM,CAAC,cAAc,GAAG,IAAI,CAAC;IAC7B,MAAM,CAAC,cAAc,GAAG,QAAQ,CAAC,cAAc,GAAG,EAAE,CAAC;IACrD,MAAM,CAAC,YAAY,GAAG,QAAQ,CAAC,cAAc,GAAG,EAAE,CAAC;IAE3D,YAAoB,MAAc;QAChC,IAAI,CAAC,MAAM,GAAG,MAAM,CAAC;IACvB,CAAC;IAED;;;OAGG;IACH,OAAO,CAAC,OAAoB;QAC1B,QAAQ,OAAO,EAAE,CAAC;YAChB,KAAK,MAAM;gBACT,OAAO,IAAI,CAAC,MAAM,GAAG,QAAQ,CAAC,YAAY,CAAC;YAC7C,KAAK,QAAQ;gBACX,OAAO,IAAI,CAAC,MAAM,GAAG,QAAQ,CAAC,cAAc,CAAC;YAC/C,KAAK,QAAQ;gBACX,OAAO,IAAI,CAAC,MAAM,GAAG,QAAQ,CAAC,cAAc,CAAC;YAC/C,KAAK,aAAa;gBAChB,OAAO,IAAI,CAAC,MAAM,CA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AAI,MAAM,GAAG,CAAC,EAAE,CAAC;YACf,OAAO,CAAC,CAAC;QACX,CAAC;QACD,OAAO,CAAC,CAAC;IACX,CAAC;;AAtIH,4BAuIC;AAED,wEAAwE;AACxE,sEAAsE;AACtE,iBAAiB;AACV,MAAM,OAAO,GAAG,CAAC,CAAW,EAAE,GAAa,EAAE,EAAE,CACpD,QAAQ,CAAC,OAAO,CAAC,CAAC,EAAE,GAAG,CAAC,GAAG,CAAC,CAAC,CAAC,CAAC,GAAG,CAAC,CAAC,CAAC,CAAC,CAAC;AAD5B,QAAA,OAAO,WACqB;AAClC,MAAM,MAAM,GAAG,CAAC,CAAW,EAAE,GAAa,EAAE,EAAE,CACnD,QAAQ,CAAC,OAAO,CAAC,CAAC,EAAE,GAAG,CAAC,GAAG,CAAC,CAAC,CAAC,CAAC,GAAG,CAAC,CAAC,CAAC,CAAC,CAAC;AAD5B,QAAA,MAAM,UACsB"}
@@ -14,6 +14,7 @@
14
14
  * limitations under the License.
15
15
  */
16
16
  import { PromisifyOptions } from '@google-cloud/promisify';
17
+ import { Duration } from './temporal';
17
18
  /**
18
19
  * This replaces usage of promisifyAll(), going forward. Instead of opting
19
20
  * some methods out, you will need to opt methods in. Additionally, this
@@ -49,3 +50,24 @@ export declare class Throttler {
49
50
  * @private
50
51
  */
51
52
  export declare function addToBucket<T, U>(map: Map<T, U[]>, bucket: T, item: U): void;
53
+ /**
54
+ * Return value from `awaitWithTimeout`. There are several variations on what
55
+ * might happen here, so this bundles it all up into a "report".
56
+ */
57
+ export interface TimeoutReturn<T> {
58
+ returnedValue?: T;
59
+ exception?: Error;
60
+ timedOut: boolean;
61
+ }
62
+ /**
63
+ * Awaits on Promise with a timeout. Resolves on the passed promise resolving or
64
+ * rejecting, or on timeout.
65
+ *
66
+ * @param promise An existing Promise returning type T.
67
+ * @param timeout A timeout value as a Duration; if the timeout is exceeded while
68
+ * waiting for the promise, the Promise this function returns will resolve, but
69
+ * with `timedOut` set.
70
+ * @returns A TimeoutReturn with the returned value, if applicable, an exception if
71
+ * the promise rejected, or the timedOut set to true if it timed out.
72
+ */
73
+ export declare function awaitWithTimeout<T>(promise: Promise<T>, timeout: Duration): Promise<TimeoutReturn<T>>;
package/build/src/util.js CHANGED
@@ -19,6 +19,7 @@ exports.Throttler = void 0;
19
19
  exports.promisifySome = promisifySome;
20
20
  exports.noop = noop;
21
21
  exports.addToBucket = addToBucket;
22
+ exports.awaitWithTimeout = awaitWithTimeout;
22
23
  const promisify_1 = require("@google-cloud/promisify");
23
24
  /**
24
25
  * This replaces usage of promisifyAll(), going forward. Instead of opting
@@ -76,4 +77,39 @@ function addToBucket(map, bucket, item) {
76
77
  items.push(item);
77
78
  map.set(bucket, items);
78
79
  }
80
+ const timeoutToken = Symbol('pubsub promise timeout');
81
+ /**
82
+ * Awaits on Promise with a timeout. Resolves on the passed promise resolving or
83
+ * rejecting, or on timeout.
84
+ *
85
+ * @param promise An existing Promise returning type T.
86
+ * @param timeout A timeout value as a Duration; if the timeout is exceeded while
87
+ * waiting for the promise, the Promise this function returns will resolve, but
88
+ * with `timedOut` set.
89
+ * @returns A TimeoutReturn with the returned value, if applicable, an exception if
90
+ * the promise rejected, or the timedOut set to true if it timed out.
91
+ */
92
+ async function awaitWithTimeout(promise, timeout) {
93
+ let timeoutId;
94
+ const timeoutPromise = new Promise((_, rej) => {
95
+ timeoutId = setTimeout(() => rej(timeoutToken), timeout.milliseconds);
96
+ });
97
+ try {
98
+ const value = await Promise.race([timeoutPromise, promise]);
99
+ clearTimeout(timeoutId);
100
+ return {
101
+ returnedValue: value,
102
+ timedOut: false,
103
+ };
104
+ }
105
+ catch (e) {
106
+ const err = e;
107
+ // The timeout passed or the promise rejected.
108
+ clearTimeout(timeoutId);
109
+ return {
110
+ exception: (err !== timeoutToken ? err : undefined),
111
+ timedOut: err === timeoutToken,
112
+ };
113
+ }
114
+ }
79
115
  //# sourceMappingURL=util.js.map
@@ -1 +1 @@
1
- {"version":3,"file":"util.js","sourceRoot":"","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CAAC,IAAI,EAAE,CAAC;IACpC,KAAK,CAAC,IAAI,CAAC,IAAI,CAAC,CAAC;IACjB,GAAG,CAAC,GAAG,CAAC,MAAM,EAAE,KAAK,CAAC,CAAC;AACzB,CAAC;AAED,MAAM,YAAY,GAAkB,MAAM,CAAC,wBAAwB,CAAC,CAAC;AAYrE;;;;;;;;;;GAUG;AACI,KAAK,UAAU,gBAAgB,CACpC,OAAmB,EACnB,OAAiB;IAEjB,IAAI,SAAqC,CAAC;IAC1C,MAAM,cAAc,GAAG,IAAI,OAAO,CAAI,CAAC,CAAC,EAAE,GAAG,EAAE,EAAE;QAC/C,SAAS,GAAG,UAAU,CAAC,GAAG,EAAE,CAAC,GAAG,CAAC,YAAY,CAAC,EAAE,OAAO,CAAC,YAAY,CAAC,CAAC;IACxE,CAAC,CAAC,CAAC;IACH,IAAI,CAAC;QACH,MAAM,KAAK,GAAG,MAAM,OAAO,CAAC,IAAI,CAAC,CAAC,cAAc,EAAE,OAAO,CAAC,CAAC,CAAC;QAC5D,YAAY,CAAC,SAAS,CAAC,CAAC;QACxB,OAAO;YACL,aAAa,EAAE,KAAK;YACpB,QAAQ,EAAE,KAAK;SAChB,CAAC;IACJ,CAAC;IAAC,OAAO,CAAC,EAAE,CAAC;QACX,MAAM,GAAG,GAAmB,CAA8B,CAAC;QAC3D,8CAA8C;QAC9C,YAAY,CAAC,SAAS,CAAC,CAAC;QACxB,OAAO;YACL,SAAS,EAAE,CAAC,GAAG,KAAK,YAAY,CAAC,CAAC,CAAC,GAAG,CAAC,CAAC,CAAC,SAAS,CAAsB;YACxE,QAAQ,EAAE,GAAG,KAAK,YAAY;SAC/B,CAAC;IACJ,CAAC;AACH,CAAC"}
package/package.json CHANGED
@@ -1,7 +1,7 @@
1
1
  {
2
2
  "name": "@google-cloud/pubsub",
3
3
  "description": "Cloud Pub/Sub Client Library for Node.js",
4
- "version": "5.1.0",
4
+ "version": "5.2.1",
5
5
  "license": "Apache-2.0",
6
6
  "author": "Google Inc.",
7
7
  "engines": {
@@ -57,15 +57,15 @@
57
57
  "@opentelemetry/semantic-conventions": "~1.34.0",
58
58
  "arrify": "^2.0.0",
59
59
  "extend": "^3.0.2",
60
- "google-auth-library": "^10.0.0-rc.1",
61
- "google-gax": "^5.0.1-rc.0",
60
+ "google-auth-library": "^10.5.0",
61
+ "google-gax": "^5.0.5",
62
62
  "heap-js": "^2.6.0",
63
63
  "is-stream-ended": "^0.1.4",
64
64
  "lodash.snakecase": "^4.1.1",
65
65
  "p-defer": "^3.0.0"
66
66
  },
67
67
  "devDependencies": {
68
- "@grpc/proto-loader": "^0.7.13",
68
+ "@grpc/proto-loader": "^0.8.0",
69
69
  "@opentelemetry/sdk-trace-base": "^1.17.0",
70
70
  "@types/duplexify": "^3.6.4",
71
71
  "@types/extend": "^3.0.4",