@causa/runtime-google 0.35.1 → 0.35.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.
@@ -1,9 +1,8 @@
1
1
  import { type ObjectSerializer } from '@causa/runtime';
2
- import { BaseEventHandlerInterceptor, type ParsedEventRequest } from '@causa/runtime/nestjs';
2
+ import { BaseEventHandlerInterceptor, Logger, type ParsedEventRequest } from '@causa/runtime/nestjs';
3
3
  import { type ExecutionContext, type Type } from '@nestjs/common';
4
4
  import { Reflector } from '@nestjs/core';
5
5
  import type { Request } from 'express';
6
- import { PinoLogger } from 'nestjs-pino';
7
6
  /**
8
7
  * The ID of the Pub/Sub event handler interceptor, that can passed to the `UseEventHandler` decorator.
9
8
  */
@@ -35,7 +34,7 @@ declare class PubSubMessage {
35
34
  */
36
35
  export declare class PubSubEventHandlerInterceptor extends BaseEventHandlerInterceptor {
37
36
  protected readonly serializer: ObjectSerializer;
38
- constructor(serializer: ObjectSerializer, reflector: Reflector, logger: PinoLogger);
37
+ constructor(serializer: ObjectSerializer, reflector: Reflector, logger: Logger);
39
38
  /**
40
39
  * Parses the given request as the payload of a Pub/Sub push request.
41
40
  *
@@ -9,11 +9,10 @@ var __metadata = (this && this.__metadata) || function (k, v) {
9
9
  };
10
10
  var PubSubEventHandlerInterceptor_1;
11
11
  import { AllowMissing, IsDateType, ValidateNestedType, ValidationError, parseObject, validateObject, } from '@causa/runtime';
12
- import { BadRequestError, BaseEventHandlerInterceptor, } from '@causa/runtime/nestjs';
12
+ import { BadRequestError, BaseEventHandlerInterceptor, Logger, } from '@causa/runtime/nestjs';
13
13
  import { Injectable } from '@nestjs/common';
14
14
  import { Reflector } from '@nestjs/core';
15
15
  import { IsBase64, IsObject, IsString } from 'class-validator';
16
- import { PinoLogger } from 'nestjs-pino';
17
16
  /**
18
17
  * The ID of the Pub/Sub event handler interceptor, that can passed to the `UseEventHandler` decorator.
19
18
  */
@@ -86,6 +85,7 @@ let PubSubEventHandlerInterceptor = PubSubEventHandlerInterceptor_1 = class PubS
86
85
  constructor(serializer, reflector, logger) {
87
86
  super(PUBSUB_EVENT_HANDLER_ID, reflector, logger);
88
87
  this.serializer = serializer;
88
+ this.logger.setContext(PubSubEventHandlerInterceptor_1.name);
89
89
  }
90
90
  /**
91
91
  * Parses the given request as the payload of a Pub/Sub push request.
@@ -148,7 +148,7 @@ let PubSubEventHandlerInterceptor = PubSubEventHandlerInterceptor_1 = class PubS
148
148
  };
149
149
  PubSubEventHandlerInterceptorWithSerializer = __decorate([
150
150
  Injectable(),
151
- __metadata("design:paramtypes", [Reflector, PinoLogger])
151
+ __metadata("design:paramtypes", [Reflector, Logger])
152
152
  ], PubSubEventHandlerInterceptorWithSerializer);
153
153
  return PubSubEventHandlerInterceptorWithSerializer;
154
154
  }
@@ -156,6 +156,6 @@ let PubSubEventHandlerInterceptor = PubSubEventHandlerInterceptor_1 = class PubS
156
156
  PubSubEventHandlerInterceptor = PubSubEventHandlerInterceptor_1 = __decorate([
157
157
  Injectable(),
158
158
  __metadata("design:paramtypes", [Object, Reflector,
159
- PinoLogger])
159
+ Logger])
160
160
  ], PubSubEventHandlerInterceptor);
161
161
  export { PubSubEventHandlerInterceptor };
@@ -110,29 +110,30 @@ export class PubSubPublisher {
110
110
  ? topicOrPreparedEvent
111
111
  : await this.prepare(topicOrPreparedEvent, event, options);
112
112
  const pubSubTopic = this.getTopic(topic);
113
- const baseLogData = {
113
+ const messageInfo = {
114
114
  topic,
115
115
  pubSubTopic: pubSubTopic.name,
116
116
  };
117
117
  if (attributes && 'eventId' in attributes) {
118
- baseLogData.eventId = attributes.eventId;
118
+ messageInfo.eventId = attributes.eventId;
119
119
  }
120
120
  try {
121
- const pubSubMessageId = await pubSubTopic.publishMessage({
121
+ const messageId = await pubSubTopic.publishMessage({
122
122
  data,
123
123
  attributes,
124
124
  orderingKey: key,
125
125
  });
126
- this.logger.info({ ...baseLogData, pubSubMessageId }, 'Published message to Pub/Sub.');
126
+ this.logger.info({ publishedMessage: { ...messageInfo, messageId } }, 'Published message to Pub/Sub.');
127
127
  }
128
128
  catch (error) {
129
129
  this.logger.error({
130
- ...baseLogData,
131
- pubSubMessage: data.toString('base64'),
132
- pubSubAttributes: attributes,
133
- pubSubOrderingKey: key,
134
- errorMessage: error.message,
135
- errorStack: error.stack,
130
+ failedMessage: {
131
+ ...messageInfo,
132
+ data: data.toString('base64'),
133
+ attributes,
134
+ key,
135
+ },
136
+ error: error.stack,
136
137
  }, 'Failed to publish message to Pub/Sub.');
137
138
  throw error;
138
139
  }
@@ -1,3 +1,4 @@
1
+ import { Logger } from '@causa/runtime/nestjs';
1
2
  import { Database, Spanner } from '@google-cloud/spanner';
2
3
  import { type OnApplicationShutdown } from '@nestjs/common';
3
4
  /**
@@ -7,6 +8,7 @@ import { type OnApplicationShutdown } from '@nestjs/common';
7
8
  export declare class SpannerLifecycleService implements OnApplicationShutdown {
8
9
  private readonly spanner;
9
10
  private readonly database;
10
- constructor(spanner: Spanner, database: Database);
11
+ private readonly logger;
12
+ constructor(spanner: Spanner, database: Database, logger: Logger);
11
13
  onApplicationShutdown(): Promise<void>;
12
14
  }
@@ -7,7 +7,9 @@ var __decorate = (this && this.__decorate) || function (decorators, target, key,
7
7
  var __metadata = (this && this.__metadata) || function (k, v) {
8
8
  if (typeof Reflect === "object" && typeof Reflect.metadata === "function") return Reflect.metadata(k, v);
9
9
  };
10
+ import { Logger } from '@causa/runtime/nestjs';
10
11
  import { Database, Spanner } from '@google-cloud/spanner';
12
+ import { SessionLeakError } from '@google-cloud/spanner/build/src/session-pool.js';
11
13
  import { Injectable } from '@nestjs/common';
12
14
  /**
13
15
  * A private service that handles the graceful shutdown of the Spanner Database.
@@ -16,18 +18,29 @@ import { Injectable } from '@nestjs/common';
16
18
  let SpannerLifecycleService = class SpannerLifecycleService {
17
19
  spanner;
18
20
  database;
19
- constructor(spanner, database) {
21
+ logger;
22
+ constructor(spanner, database, logger) {
20
23
  this.spanner = spanner;
21
24
  this.database = database;
25
+ this.logger = logger;
22
26
  }
23
27
  async onApplicationShutdown() {
24
- await this.database.close();
25
- this.spanner.close();
28
+ try {
29
+ await this.database.close();
30
+ this.spanner.close();
31
+ }
32
+ catch (error) {
33
+ this.logger.error({
34
+ error: error.stack,
35
+ spannerLeaks: error instanceof SessionLeakError ? error.messages : undefined,
36
+ }, 'Failed to close Spanner client.');
37
+ }
26
38
  }
27
39
  };
28
40
  SpannerLifecycleService = __decorate([
29
41
  Injectable(),
30
42
  __metadata("design:paramtypes", [Spanner,
31
- Database])
43
+ Database,
44
+ Logger])
32
45
  ], SpannerLifecycleService);
33
46
  export { SpannerLifecycleService };
@@ -15,5 +15,5 @@ export type SpannerOutboxTransaction = SpannerTransaction<OutboxEventTransaction
15
15
  export declare class SpannerOutboxTransactionRunner extends OutboxTransactionRunner<SpannerOutboxTransaction> {
16
16
  readonly entityManager: SpannerEntityManager;
17
17
  constructor(entityManager: SpannerEntityManager, outboxEventType: Type<OutboxEvent>, sender: SpannerOutboxSender, logger: Logger);
18
- protected runStateTransaction<RT>(eventTransaction: OutboxEventTransaction, runFn: (transaction: SpannerOutboxTransaction) => Promise<RT>): Promise<RT>;
18
+ protected runStateTransaction<RT>(eventTransactionFactory: () => OutboxEventTransaction, runFn: (transaction: SpannerOutboxTransaction) => Promise<RT>): Promise<RT>;
19
19
  }
@@ -15,9 +15,10 @@ export class SpannerOutboxTransactionRunner extends OutboxTransactionRunner {
15
15
  super(outboxEventType, sender, logger);
16
16
  this.entityManager = entityManager;
17
17
  }
18
- async runStateTransaction(eventTransaction, runFn) {
18
+ async runStateTransaction(eventTransactionFactory, runFn) {
19
19
  return await this.entityManager.transaction(async (dbTransaction) => {
20
20
  const stateTransaction = new SpannerStateTransaction(this.entityManager, dbTransaction);
21
+ const eventTransaction = eventTransactionFactory();
21
22
  const transaction = new SpannerTransaction(stateTransaction, eventTransaction);
22
23
  try {
23
24
  return await runFn(transaction);
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@causa/runtime-google",
3
- "version": "0.35.1",
3
+ "version": "0.35.3",
4
4
  "description": "An extension to the Causa runtime SDK (`@causa/runtime`), providing Google-specific features.",
5
5
  "repository": "github:causa-io/runtime-typescript-google",
6
6
  "license": "ISC",
@@ -29,15 +29,15 @@
29
29
  "test:cov": "npm run test -- --coverage"
30
30
  },
31
31
  "dependencies": {
32
- "@causa/runtime": ">= 0.24.1 < 1.0.0",
32
+ "@causa/runtime": ">= 0.25.0 < 1.0.0",
33
33
  "@google-cloud/precise-date": "^4.0.0",
34
34
  "@google-cloud/pubsub": "^4.9.0",
35
35
  "@google-cloud/spanner": "^7.16.0",
36
36
  "@google-cloud/tasks": "^5.5.1",
37
- "@grpc/grpc-js": "^1.12.2",
38
- "@nestjs/common": "^10.4.12",
37
+ "@grpc/grpc-js": "^1.12.3",
38
+ "@nestjs/common": "^10.4.13",
39
39
  "@nestjs/config": "^3.3.0",
40
- "@nestjs/core": "^10.4.12",
40
+ "@nestjs/core": "^10.4.13",
41
41
  "@nestjs/passport": "^10.0.3",
42
42
  "@nestjs/terminus": "^10.2.3",
43
43
  "class-transformer": "^0.5.1",
@@ -45,14 +45,13 @@
45
45
  "express": "^4.21.1",
46
46
  "firebase-admin": "^13.0.1",
47
47
  "jsonwebtoken": "^9.0.2",
48
- "nestjs-pino": "^4.1.0",
49
48
  "passport-http-bearer": "^1.0.1",
50
49
  "pino": "^9.5.0",
51
50
  "reflect-metadata": "^0.2.2"
52
51
  },
53
52
  "devDependencies": {
54
- "@nestjs/testing": "^10.4.12",
55
- "@swc/core": "^1.9.3",
53
+ "@nestjs/testing": "^10.4.13",
54
+ "@swc/core": "^1.10.0",
56
55
  "@swc/jest": "^0.2.37",
57
56
  "@tsconfig/node22": "^22.0.0",
58
57
  "@types/jest": "^29.5.14",
@@ -61,7 +60,7 @@
61
60
  "@types/passport-http-bearer": "^1.0.41",
62
61
  "@types/supertest": "^6.0.2",
63
62
  "@types/uuid": "^10.0.0",
64
- "dotenv": "^16.4.5",
63
+ "dotenv": "^16.4.7",
65
64
  "eslint": "^9.16.0",
66
65
  "eslint-config-prettier": "^9.1.0",
67
66
  "eslint-plugin-prettier": "^5.2.1",
@@ -72,7 +71,7 @@
72
71
  "ts-jest": "^29.2.5",
73
72
  "ts-node": "^10.9.2",
74
73
  "typescript": "^5.7.2",
75
- "typescript-eslint": "^8.16.0",
74
+ "typescript-eslint": "^8.17.0",
76
75
  "uuid": "^11.0.3"
77
76
  }
78
77
  }