Kaynağa Gözat

chore: Fix some code quality issues

Michael Bromley 8 ay önce
ebeveyn
işleme
2160eb396d

+ 7 - 1
packages/core/src/common/instrument-decorator.ts

@@ -4,6 +4,8 @@ export const ENABLE_INSTRUMENTATION_ENV_VAR = 'VENDURE_ENABLE_INSTRUMENTATION';
 
 const INSTRUMENTED_CLASS = Symbol('InstrumentedClassTarget');
 
+type Constructor<T = any> = new (...args: any[]) => T;
+
 /**
  * @description
  * This decorator is used to apply instrumentation to a class. It is intended to be used in conjunction
@@ -44,7 +46,11 @@ export function Instrument(): ClassDecorator {
         if (process.env[ENABLE_INSTRUMENTATION_ENV_VAR] == null) {
             return target;
         }
-        const InstrumentedClass = class extends (target as new (...args: any[]) => any) {
+        // Add type guard to ensure target is a constructor
+        if (typeof target !== 'function') {
+            return target;
+        }
+        const InstrumentedClass = class extends (target as Constructor<any>) {
             constructor(...args: any[]) {
                 // eslint-disable-next-line constructor-super
                 super(...args);

+ 1 - 1
packages/core/src/config/vendure-config.ts

@@ -1128,7 +1128,7 @@ export interface SystemOptions {
      * @default InMemoryCacheStrategy
      */
     cacheStrategy?: CacheStrategy;
-    instrumentationStrategy?: InstrumentationStrategy | undefined;
+    instrumentationStrategy?: InstrumentationStrategy;
 }
 
 /**

+ 0 - 2
packages/core/src/job-queue/job-queue.service.ts

@@ -95,8 +95,6 @@ export class JobQueueService implements OnModuleDestroy {
             if (!queue.started && this.shouldStartQueue(queue.name)) {
                 Logger.info(`Starting queue: ${queue.name}`, loggerCtx);
                 await queue.start();
-                // const span = getActiveSpan();
-                // span?.setAttribute('job-queue.name', queue.name);
             }
         }
     }

+ 1 - 1
packages/core/src/plugin/default-scheduler-plugin/default-scheduler-strategy.ts

@@ -28,7 +28,7 @@ export class DefaultSchedulerStrategy implements SchedulerStrategy {
     private connection: TransactionalConnection;
     private injector: Injector;
     private intervalRef: NodeJS.Timeout | undefined;
-    private tasks: Map<string, { task: ScheduledTask; isRegistered: boolean }> = new Map();
+    private readonly tasks: Map<string, { task: ScheduledTask; isRegistered: boolean }> = new Map();
     private pluginOptions: DefaultSchedulerPluginOptions;
     private runningTasks: ScheduledTask[] = [];
 

+ 3 - 3
packages/core/src/scheduler/scheduler.service.ts

@@ -33,11 +33,11 @@ export interface TaskInfo {
  */
 @Injectable()
 export class SchedulerService implements OnApplicationBootstrap, OnApplicationShutdown {
-    private jobs: Map<string, { task: ScheduledTask; job: Cron }> = new Map();
+    private readonly jobs: Map<string, { task: ScheduledTask; job: Cron }> = new Map();
     private shouldRunTasks = false;
     constructor(
-        private configService: ConfigService,
-        private processContext: ProcessContext,
+        private readonly configService: ConfigService,
+        private readonly processContext: ProcessContext,
     ) {}
 
     onApplicationBootstrap() {

+ 0 - 4
packages/core/src/service/services/channel.service.ts

@@ -265,16 +265,12 @@ export class ChannelService {
             // eslint-disable-next-line @typescript-eslint/no-non-null-assertion
             ctxOrToken instanceof RequestContext ? [ctxOrToken, token!] : [undefined, ctxOrToken];
 
-        // const span = getActiveSpan();
         const allChannels = await this.allChannels.value(ctx);
 
         if (allChannels.length === 1 || channelToken === '') {
             // there is only the default channel, so return it
-            // span?.setAttribute('channel.token', 'default');
             return this.getDefaultChannel(ctx);
         }
-
-        // span?.setAttribute('channel.token', channelToken);
         const channel = allChannels.find(c => c.token === channelToken);
         if (!channel) {
             throw new ChannelNotFoundError(channelToken);

+ 0 - 26
packages/core/src/service/services/facet.service.ts

@@ -193,9 +193,6 @@ export class FacetService {
     }
 
     async delete(ctx: RequestContext, id: ID, force: boolean = false): Promise<DeletionResponse> {
-        // const span = getActiveSpan();
-        // span?.setAttribute('force', force.toString());
-
         const facet = await this.connection.getEntityOrThrow(ctx, Facet, id, {
             relations: ['values'],
             channelId: ctx.channelId,
@@ -222,29 +219,14 @@ export class FacetService {
             await this.connection.getRepository(ctx, Facet).remove(facet);
             await this.eventBus.publish(new FacetEvent(ctx, deletedFacet, 'deleted', id));
             result = DeletionResult.DELETED;
-            // span?.addEvent('facet-deleted', {
-            //     facetCode: facet.code,
-            //     productCount,
-            //     variantCount,
-            // });
         } else if (force) {
             await this.connection.getRepository(ctx, Facet).remove(facet);
             await this.eventBus.publish(new FacetEvent(ctx, deletedFacet, 'deleted', id));
             message = ctx.translate('message.facet-force-deleted', i18nVars);
             result = DeletionResult.DELETED;
-            // span?.addEvent('facet-deleted', {
-            //     facetCode: facet.code,
-            //     productCount,
-            //     variantCount,
-            // });
         } else {
             message = ctx.translate('message.facet-used', i18nVars);
             result = DeletionResult.NOT_DELETED;
-            // span?.addEvent('facet-not-deleted', {
-            //     facetCode: facet.code,
-            //     productCount,
-            //     variantCount,
-            // });
         }
 
         return {
@@ -312,14 +294,6 @@ export class FacetService {
                 this.channelService.assignToChannels(ctx, FacetValue, value.id, [input.channelId]),
             ),
         ]);
-
-        // const span = getActiveSpan();
-
-        // span?.addEvent('facets-assigned-to-channel', {
-        //     facetIds: facetsToAssign.map(f => f.id).join(','),
-        //     channelId: input.channelId,
-        // });
-
         return this.connection
             .findByIdsInChannel(
                 ctx,