Skip to content

Commit

Permalink
feat: bump nestjs to 10
Browse files Browse the repository at this point in the history
  • Loading branch information
p-fedyukovich committed Sep 3, 2023
1 parent 1a9a5d9 commit 4bddf86
Show file tree
Hide file tree
Showing 14 changed files with 13,207 additions and 7,028 deletions.
51 changes: 18 additions & 33 deletions .circleci/config.yml
Original file line number Diff line number Diff line change
@@ -1,46 +1,37 @@
version: 2
version: 2.1

aliases:
- &restore-cache
restore_cache:
key: dependency-cache-{{ checksum "package.json" }}
- &install-deps
run:
name: Install dependencies
command: yarn install --frozen-lockfile
- &build-packages
run:
name: Build
command: yarn build
orbs:
node: circleci/node@5.1.0

jobs:
build:
working_directory: ~/nestjs-google-pubsub-microservice
docker:
- image: circleci/node:12
executor: node/default
steps:
- checkout
- run:
name: Update NPM version
command: 'sudo npm install -g npm@latest'
- *restore-cache
- *install-deps
- save_cache:
key: dependency-cache-{{ checksum "package.json" }}
paths:
- ./node_modules
- *build-packages
- node/install-packages
- run:
name: Build
command: npm run build
- run:
name: Unit tests
command: yarn test
command: npm run test
- persist_to_workspace:
root: .
paths:
- .

integration_tests:
working_directory: ~/nestjs-google-pubsub-microservice
machine: true
environment:
PUBSUB_EMULATOR_HOST: localhost:8681
steps:
- checkout
- attach_workspace:
at: .
- run:
name: Prepare nvm
command: |
Expand All @@ -49,20 +40,15 @@ jobs:
- run:
name: Upgrade Node.js
command: |
nvm install v12
nvm install v18
node -v
nvm alias default v12
- run:
name: Install Yarn
command: npm install yarn -g
nvm alias default v18
- run:
name: Install Docker Compose
command: |
curl -L https://github.com/docker/compose/releases/download/1.19.0/docker-compose-`uname -s`-`uname -m` > ~/docker-compose
chmod +x ~/docker-compose
sudo mv ~/docker-compose /usr/local/bin/docker-compose
- *restore-cache
- *install-deps
- run:
name: Prepare
command: |
Expand All @@ -73,10 +59,9 @@ jobs:
command: docker ps
- run:
name: e2e tests
command: yarn test:e2e
command: npm run test:e2e

workflows:
version: 2
build-and-test:
jobs:
- build
Expand Down
1 change: 1 addition & 0 deletions .eslintrc.js
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,7 @@ module.exports = {
parser: '@typescript-eslint/parser',
parserOptions: {
project: 'tsconfig.json',
tsconfigRootDir: __dirname,
sourceType: 'module',
},
plugins: ['@typescript-eslint/eslint-plugin'],
Expand Down
7 changes: 5 additions & 2 deletions docker-compose.yml
Original file line number Diff line number Diff line change
@@ -1,7 +1,10 @@
version: "3"
version: '3.3'

services:
pubsub:
image: messagebird/gcloud-pubsub-emulator:latest
image: gcr.io/google.com/cloudsdktool/cloud-sdk:416.0.0-emulators
entrypoint: gcloud
command: ["beta", "emulators", "pubsub", "start", "--host-port=0.0.0.0:8681"]
ports:
- '8681:8681'
restart: always
4 changes: 2 additions & 2 deletions lib/gc-pubsub.client.ts
Original file line number Diff line number Diff line change
Expand Up @@ -4,9 +4,9 @@ import {
PubSub,
Subscription,
Topic,
PublishOptions,
SubscriberOptions,
} from '@google-cloud/pubsub';
import { PublishOptions } from '@google-cloud/pubsub/build/src/publisher';
import { SubscriberOptions } from '@google-cloud/pubsub/build/src/subscriber';
import { Logger } from '@nestjs/common';
import {
ClientProxy,
Expand Down
12 changes: 7 additions & 5 deletions lib/gc-pubsub.context.ts
Original file line number Diff line number Diff line change
@@ -1,24 +1,26 @@
import { Message } from '@google-cloud/pubsub';
import { BaseRpcContext } from '@nestjs/microservices/ctx-host/base-rpc.context';

type GCPubSubContextArgs = [Message, string];
type GCPubSubContextArgs<P> = [Message, P];

export class GCPubSubContext extends BaseRpcContext<GCPubSubContextArgs> {
constructor(args: GCPubSubContextArgs) {
export class GCPubSubContext<P = string> extends BaseRpcContext<
GCPubSubContextArgs<P>
> {
constructor(args: GCPubSubContextArgs<P>) {
super(args);
}

/**
* Returns the original message (with properties, fields, and content).
*/
getMessage() {
getMessage(): Message {
return this.args[0];
}

/**
* Returns the name of the pattern.
*/
getPattern() {
getPattern(): P {
return this.args[1];
}
}
8 changes: 5 additions & 3 deletions lib/gc-pubsub.interface.ts
Original file line number Diff line number Diff line change
@@ -1,7 +1,9 @@
import { ClientConfig } from '@google-cloud/pubsub';
import {
ClientConfig,
PublishOptions,
SubscriberOptions,
} from '@google-cloud/pubsub';
import { Deserializer, Serializer } from '@nestjs/microservices';
import { PublishOptions } from '@google-cloud/pubsub/build/src/publisher';
import { SubscriberOptions } from '@google-cloud/pubsub/build/src/subscriber';

export interface GCPubSubOptions {
client?: ClientConfig;
Expand Down
4 changes: 1 addition & 3 deletions lib/gc-pubsub.server.spec.ts
Original file line number Diff line number Diff line change
Expand Up @@ -219,9 +219,7 @@ describe('GCPubSubServer', () => {
const correlationId = '0';

await server.sendMessage(message, replyTo, correlationId);
expect(Array.from(server['replyTopics'].values())).to.deep.eq([
'my-keytest',
]);
expect(Array.from(server['replyTopics'].values())).to.deep.eq(['test']);
});
});
});
Expand Down
6 changes: 2 additions & 4 deletions lib/gc-pubsub.server.ts
Original file line number Diff line number Diff line change
@@ -1,11 +1,11 @@
import {
ClientConfig,
Message,
PublishOptions,
PubSub,
SubscriberOptions,
Subscription,
} from '@google-cloud/pubsub';
import { PublishOptions } from '@google-cloud/pubsub/build/src/publisher';
import { SubscriberOptions } from '@google-cloud/pubsub/build/src/subscriber';
import { Observable } from 'rxjs';
import {
CustomTransportStrategy,
Expand Down Expand Up @@ -210,8 +210,6 @@ export class GCPubSubServer extends Server implements CustomTransportStrategy {
message as unknown as OutgoingResponse,
);

replyTo = `${this.scopedEnvKey}${replyTo}`;

this.replyTopics.add(replyTo);

await this.client
Expand Down
Loading

0 comments on commit 4bddf86

Please sign in to comment.