Skip to content

Commit 2dffe73

Browse files
committed
feat: allow for interceptor meta to be inlined
1 parent 22f9247 commit 2dffe73

File tree

14 files changed

+1867
-1749
lines changed

14 files changed

+1867
-1749
lines changed

.github/workflows/ci.yml

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -38,7 +38,7 @@ jobs:
3838
with:
3939
node-version: 20.x
4040
- name: Install pnpm
41-
run: npm i -g pnpm@^8
41+
run: npm i -g pnpm@^9
4242
- name: Install deps
4343
run: pnpm i
4444
- name: Collect Test Coverage

docker-compose.yml

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,3 @@
1-
version: '3.3'
21
services:
32
mqtt:
43
image: eclipse-mosquitto

integration/test/gql.spec.ts

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -13,7 +13,7 @@ import { suite } from 'uvu';
1313
import { is } from 'uvu/assert';
1414

1515
import { GqlModule } from '../src/gql/gql.module';
16-
import { createTestModule, reportValues, serviceOptionsFactory, toBeALogObject } from './utils';
16+
import { createTestModule, reportValues, toBeALogObject } from './utils';
1717

1818
for (const { adapter, server, parser, driver } of [
1919
{
@@ -51,7 +51,7 @@ for (const { adapter, server, parser, driver } of [
5151
try {
5252
const modRef = await createTestModule(
5353
GqlModule.forFeature(driver),
54-
serviceOptionsFactory(`GraphQL ${server}`),
54+
{ application: `GraphQL ${server}` },
5555
[parser],
5656
);
5757
context.app = modRef.createNestApplication(adapter);

integration/test/grpc.spec.ts

Lines changed: 2 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -12,13 +12,7 @@ import { is } from 'uvu/assert';
1212

1313
import { GrpcClientModule } from '../src/grpc/client/grpc-client.module';
1414
import { GrpcServerModule } from '../src/grpc/server/grpc-server.module';
15-
import {
16-
createTestModule,
17-
hello,
18-
reportValues,
19-
serviceOptionsFactory,
20-
toBeALogObject,
21-
} from './utils';
15+
import { createTestModule, hello, reportValues, toBeALogObject } from './utils';
2216

2317
const GrpcParserSuite = suite<{
2418
logs: Parameters<OgmaInterceptor['log']>[];
@@ -32,7 +26,7 @@ const GrpcParserSuite = suite<{
3226
rpcServer: undefined,
3327
});
3428
GrpcParserSuite.before(async (context) => {
35-
const modRef = await createTestModule(GrpcServerModule, serviceOptionsFactory('gRPC Server'), [
29+
const modRef = await createTestModule(GrpcServerModule, { application: 'gRPC Server' }, [
3630
GrpcParser,
3731
]);
3832
const rpcServer = modRef.createNestMicroservice<MicroserviceOptions>({

integration/test/http.spec.ts

Lines changed: 2 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -11,13 +11,7 @@ import { suite } from 'uvu';
1111
import { is } from 'uvu/assert';
1212

1313
import { HttpServerModule } from '../src/http/http-server.module';
14-
import {
15-
createTestModule,
16-
hello,
17-
reportValues,
18-
serviceOptionsFactory,
19-
toBeALogObject,
20-
} from './utils';
14+
import { createTestModule, hello, reportValues, toBeALogObject } from './utils';
2115

2216
const expectRequestId = (spy: Stub<OgmaInterceptor['log']> | Stub<OgmaFilterService['doLog']>) => {
2317
is(typeof spy.firstCall.args[2], 'string');
@@ -58,9 +52,7 @@ for (const { adapter, server, parser } of [
5852
filterSpy: undefined,
5953
});
6054
HttpSuite.before(async (context) => {
61-
const modRef = await createTestModule(HttpServerModule, serviceOptionsFactory(server), [
62-
parser,
63-
]);
55+
const modRef = await createTestModule(HttpServerModule, { application: server }, [parser]);
6456
context.app = modRef.createNestApplication(adapter);
6557
const interceptor = context.app.get(OgmaInterceptor);
6658
const filterService = context.app.get(OgmaFilterService);

integration/test/rpc.spec.ts

Lines changed: 2 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -23,13 +23,7 @@ import { is } from 'uvu/assert';
2323

2424
import { RpcClientModule } from '../src/rpc/client/rpc-client.module';
2525
import { RpcServerModule } from '../src/rpc/server/rpc-server.module';
26-
import {
27-
createTestModule,
28-
hello,
29-
reportValues,
30-
serviceOptionsFactory,
31-
toBeALogObject,
32-
} from './utils';
26+
import { createTestModule, hello, reportValues, toBeALogObject } from './utils';
3327

3428
const tcpOptions: TcpOptions['options'] = {};
3529
const mqttOptions: MqttOptions['options'] = { url: 'mqtt://localhost:1883', reconnectPeriod: 0 };
@@ -99,10 +93,7 @@ for (const { server, transport, options, protocol, parser } of [
9993
const modRef = await createTestModule(
10094
RpcServerModule,
10195
{
102-
service: serviceOptionsFactory(server),
103-
interceptor: {
104-
rpc: parser,
105-
},
96+
application: server,
10697
},
10798
[parser],
10899
);

integration/test/utils/index.ts

Lines changed: 1 addition & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -1,19 +1,10 @@
1-
import {
2-
OgmaFilterService,
3-
OgmaInterceptor,
4-
OgmaService,
5-
OgmaServiceOptions,
6-
} from '@ogma/nestjs-module';
1+
import { OgmaFilterService, OgmaInterceptor, OgmaService } from '@ogma/nestjs-module';
72

8-
const stream = process.stdout;
93
process.stdout.getColorDepth = () => 8;
104
export * from './createModule';
115
export * from './matcher';
126
export * from './ws-promise';
137
export const hello = { hello: 'world' };
14-
export const serviceOptionsFactory = (app: string, json = false): OgmaServiceOptions => {
15-
return { application: app, stream, json };
16-
};
178

189
export const reportValues = (
1910
ogma: OgmaService,

integration/test/utils/matcher.ts

Lines changed: 6 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -109,7 +109,7 @@ const doTest = (
109109
return { pass, message };
110110
};
111111
export const toBeALogObject = (
112-
received: string | LogObject,
112+
received: string | LogObject | unknown,
113113
method: string,
114114
endpoint: string,
115115
protocol: string,
@@ -125,7 +125,7 @@ export const toBeALogObject = (
125125
if (typeof received === 'string') {
126126
[recIp, , recMethod, recEndpoint, recProto, recStatus, recTime, , recSize] =
127127
received.split(' ');
128-
} else {
128+
} else if (isLogObject(received)) {
129129
let callerAddress: string | string[], responseTime: number, contentLength: number;
130130
({
131131
callerAddress,
@@ -157,3 +157,7 @@ export const toBeALogObject = (
157157
);
158158
ok(result.pass, result.message);
159159
};
160+
161+
const isLogObject = (received: unknown): received is LogObject => {
162+
return typeof received === 'object' && 'callerAddress' in received;
163+
};

integration/test/ws.spec.ts

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -13,7 +13,7 @@ import { is } from 'uvu/assert';
1313
import WebSocket from 'ws';
1414

1515
import { WsModule } from '../src/ws/ws.module';
16-
import { makeWs, reportValues, serviceOptionsFactory, toBeALogObject } from './utils';
16+
import { makeWs, reportValues, toBeALogObject } from './utils';
1717

1818
for (const { adapter, server, parser, client, protocol, sendMethod, serializer } of [
1919
{
@@ -52,7 +52,7 @@ for (const { adapter, server, parser, client, protocol, sendMethod, serializer }
5252
});
5353
WsSuite.before(async (context) => {
5454
const modRef = await Test.createTestingModule({
55-
imports: [WsModule.register(serviceOptionsFactory(server))],
55+
imports: [WsModule.register({ application: server })],
5656
providers: [parser],
5757
}).compile();
5858
context.app = modRef.createNestApplication();

package.json

Lines changed: 17 additions & 18 deletions
Original file line numberDiff line numberDiff line change
@@ -56,23 +56,23 @@
5656
"@docsearch/css": "^3.5.2",
5757
"@docsearch/react": "^3.5.2",
5858
"@graphql-tools/schema": "10.0.0",
59-
"@graphql-tools/utils": "^10.0.7",
59+
"@graphql-tools/utils": "^10.8.6",
6060
"@grpc/grpc-js": "^1.9.6",
6161
"@grpc/proto-loader": "0.7.10",
6262
"@mdx-js/react": "2.3.0",
63-
"@mercuriusjs/gateway": "^2.0.0",
64-
"@nestjs/apollo": "^13.0.2",
65-
"@nestjs/common": "^11.0.7",
66-
"@nestjs/core": "^11.0.7",
67-
"@nestjs/graphql": "^13.0.2",
68-
"@nestjs/mercurius": "^12.2.2",
69-
"@nestjs/microservices": "^11.0.7",
70-
"@nestjs/platform-express": "^11.0.7",
71-
"@nestjs/platform-fastify": "^11.0.7",
72-
"@nestjs/platform-socket.io": "^11.0.7",
73-
"@nestjs/platform-ws": "^11.0.7",
74-
"@nestjs/testing": "^11.0.7",
75-
"@nestjs/websockets": "^11.0.7",
63+
"@mercuriusjs/gateway": "^5.0.0",
64+
"@nestjs/apollo": "^13.0.3",
65+
"@nestjs/common": "^11.0.11",
66+
"@nestjs/core": "^11.0.11",
67+
"@nestjs/graphql": "^13.0.3",
68+
"@nestjs/mercurius": "^13.0.3",
69+
"@nestjs/microservices": "^11.0.11",
70+
"@nestjs/platform-express": "^11.0.11",
71+
"@nestjs/platform-fastify": "^11.0.11",
72+
"@nestjs/platform-socket.io": "^11.0.11",
73+
"@nestjs/platform-ws": "^11.0.11",
74+
"@nestjs/testing": "^11.0.11",
75+
"@nestjs/websockets": "^11.0.11",
7676
"@nrwl/devkit": "19.2.0",
7777
"@nrwl/eslint-plugin-nx": "19.2.0",
7878
"@nrwl/js": "19.2.0",
@@ -123,7 +123,7 @@
123123
"eslint-plugin-simple-import-sort": "10.0.0",
124124
"express": "^4.18.2",
125125
"fast-safe-stringify": "^2.1.1",
126-
"fastify": "4.18.0",
126+
"fastify": "5.2.1",
127127
"graphql": "^16.8.1",
128128
"hanbi": "^1.0.1",
129129
"hastscript": "^8.0.0",
@@ -132,11 +132,10 @@
132132
"kafkajs": "2.2.4",
133133
"lcov-result-merger": "^4.1.0",
134134
"lint-staged": "15.0.1",
135-
"mercurius": "13.1.0",
136-
"mercusius^13": "link:@nestjs/mercusius^13",
135+
"mercurius": "16.1.0",
137136
"module-alias": "^2.2.3",
138137
"morgan": "^1.10.0",
139-
"mqtt": "^4.3.7",
138+
"mqtt": "^5.10.4",
140139
"nats": "^2.17.0",
141140
"nest-commander": "^3.12.0",
142141
"nest-commander-testing": "3.3.0",

0 commit comments

Comments
 (0)