fix: migrate deprecated APIs and patch vulnerable dependencies
Use current Mongoose, NATS, React, and ESLint APIs. Upgrade Vite and other affected dependencies, restrict the compatibility plugin to resolved module IDs, and keep qs unchanged.
This commit is contained in:
1 parent
5882585f69
commit
9d7c888b0a
14 files changed
+952
-900
No files matched your search
@@ -1895,7 +1895,7 @@ describe('AuctionService', () => {
|
||||
expect(findOneAndUpdate).toHaveBeenCalledWith(
|
||||
{ matchId, 'chatMessages.id': { $ne: appended.message.id } },
|
||||
{ $push: { chatMessages: { $each: [appended.message], $slice: -200 } } },
|
||||
{ new: true },
|
||||
{ returnDocument: 'after' },
|
||||
);
|
||||
});
|
||||
|
||||
|
||||
@@ -706,7 +706,7 @@ export class AuctionService {
|
||||
},
|
||||
},
|
||||
},
|
||||
{ new: true },
|
||||
{ returnDocument: 'after' },
|
||||
);
|
||||
if (auction) return { auction, message, created: true };
|
||||
|
||||
|
||||
@@ -1,6 +1,5 @@
|
||||
import { Module } from '@nestjs/common';
|
||||
import { connect } from 'nats';
|
||||
import type { NatsConnection } from 'nats';
|
||||
import { connect, type NatsConnection } from '@nats-io/transport-node';
|
||||
import { SecretModule } from '../secret/secret.module';
|
||||
import { SecretService } from '../secret/secret.service';
|
||||
import { NATS_CLIENT } from './nats.constants';
|
||||
|
||||
@@ -2,20 +2,21 @@ import { Inject, Injectable, Logger, OnModuleDestroy } from '@nestjs/common';
|
||||
import {
|
||||
AckPolicy,
|
||||
DeliverPolicy,
|
||||
nanos,
|
||||
jetstream,
|
||||
jetstreamManager,
|
||||
ReplayPolicy,
|
||||
RetentionPolicy,
|
||||
StorageType,
|
||||
StringCodec,
|
||||
} from 'nats';
|
||||
import type {
|
||||
ConsumerMessages,
|
||||
JsMsg,
|
||||
Msg,
|
||||
NatsConnection,
|
||||
PubAck,
|
||||
Subscription,
|
||||
} from 'nats';
|
||||
type ConsumerMessages,
|
||||
type JsMsg,
|
||||
type PubAck,
|
||||
} from '@nats-io/jetstream';
|
||||
import {
|
||||
nanos,
|
||||
type Msg,
|
||||
type NatsConnection,
|
||||
type Subscription,
|
||||
} from '@nats-io/transport-node';
|
||||
import { NATS_CLIENT } from './nats.constants';
|
||||
|
||||
export type NatsMessageHandler<T = unknown> = (
|
||||
@@ -64,7 +65,6 @@ const JET_STREAM_CONSUMER_RESTART_DELAY_MILLISECONDS = 1_000;
|
||||
@Injectable()
|
||||
export class NatsService implements OnModuleDestroy {
|
||||
private readonly logger = new Logger(NatsService.name);
|
||||
private readonly stringCodec = StringCodec();
|
||||
private readonly subscriptions = new Set<Subscription>();
|
||||
private readonly jetStreamConsumers = new Set<ConsumerMessages>();
|
||||
private isDestroying = false;
|
||||
@@ -108,10 +108,7 @@ export class NatsService implements OnModuleDestroy {
|
||||
}
|
||||
|
||||
public async publish<T = unknown>(subject: string, data: T): Promise<void> {
|
||||
this.natsClient.publish(
|
||||
subject,
|
||||
this.stringCodec.encode(JSON.stringify(data)),
|
||||
);
|
||||
this.natsClient.publish(subject, JSON.stringify(data));
|
||||
await this.natsClient.flush();
|
||||
}
|
||||
|
||||
@@ -133,19 +130,16 @@ export class NatsService implements OnModuleDestroy {
|
||||
data: T,
|
||||
options?: { messageId?: string; timeoutMs?: number },
|
||||
): Promise<PubAck> {
|
||||
const ack = await this.natsClient
|
||||
.jetstream()
|
||||
.publish(subject, this.stringCodec.encode(JSON.stringify(data)), {
|
||||
msgID: options?.messageId,
|
||||
timeout: options?.timeoutMs ?? 5000,
|
||||
});
|
||||
return ack;
|
||||
return jetstream(this.natsClient).publish(subject, JSON.stringify(data), {
|
||||
msgID: options?.messageId,
|
||||
timeout: options?.timeoutMs ?? 5000,
|
||||
});
|
||||
}
|
||||
|
||||
public async ensureJetStreamStream(
|
||||
options: JetStreamStreamOptions,
|
||||
): Promise<void> {
|
||||
const manager = await this.natsClient.jetstreamManager();
|
||||
const manager = await jetstreamManager(this.natsClient);
|
||||
const config = {
|
||||
name: options.name,
|
||||
subjects: options.subjects,
|
||||
@@ -173,7 +167,7 @@ export class NatsService implements OnModuleDestroy {
|
||||
public async ensureJetStreamConsumer(
|
||||
options: JetStreamConsumerOptions,
|
||||
): Promise<void> {
|
||||
const manager = await this.natsClient.jetstreamManager();
|
||||
const manager = await jetstreamManager(this.natsClient);
|
||||
const config = {
|
||||
durable_name: options.durable,
|
||||
name: options.durable,
|
||||
@@ -206,9 +200,10 @@ export class NatsService implements OnModuleDestroy {
|
||||
): Promise<void> {
|
||||
while (!this.isDestroying) {
|
||||
try {
|
||||
const consumer = await this.natsClient
|
||||
.jetstream()
|
||||
.consumers.get(options.stream, options.durable);
|
||||
const consumer = await jetstream(this.natsClient).consumers.get(
|
||||
options.stream,
|
||||
options.durable,
|
||||
);
|
||||
const messages = await consumer.consume({
|
||||
max_messages: options.maxMessages ?? 10,
|
||||
expires: options.expiresMs ?? 30000,
|
||||
@@ -263,8 +258,7 @@ export class NatsService implements OnModuleDestroy {
|
||||
): Promise<void> {
|
||||
let data: T;
|
||||
try {
|
||||
const decoded = this.stringCodec.decode(msg.data);
|
||||
data = JSON.parse(decoded) as T;
|
||||
data = msg.json<T>();
|
||||
} catch (err) {
|
||||
this.logger.warn(
|
||||
`Failed to decode NATS message on subject="${msg.subject}": ${
|
||||
@@ -292,7 +286,7 @@ export class NatsService implements OnModuleDestroy {
|
||||
): Promise<void> {
|
||||
let data: T;
|
||||
try {
|
||||
data = JSON.parse(msg.string()) as T;
|
||||
data = msg.json<T>();
|
||||
} catch (err) {
|
||||
this.logger.warn(
|
||||
`Terminating undecodable JetStream message subject="${msg.subject}" stream="${options.stream}": ${
|
||||
|
||||
Reference in new issue
Block a user