Skip to content

[slash-commands] Upgrade to Inversify 7 #28

Description

@dustinlacewell

This is an AI generated report, use as a heuristic only:

Migration Summary for pkgs/slash-commands

This summary outlines the necessary changes to migrate pkgs/slash-commands to Inversify v7, based on the analysis from the provided history.

container.resolve

container.resolve is used in pkgs/slash-commands.

pkgs/slash-commands/src/services/SlashCommandService/index.ts

In getCommandRegistrationMeta, this.container.resolve is used:

const resolver = this.container.resolve(
    arg.choicesResolver,
);

This should be changed to:

const resolver = this.container.get(
    arg.choicesResolver,
    { autobind: true },
);

pkgs/slash-commands/src/services/SlashCommandFactory/SlashCommandFactory.ts

In complete, di.resolve is used:

const completer = di.resolve(argMeta.choicesCompleter!);

This should be changed to:

const completer = di.get(argMeta.choicesCompleter!, { autobind: true });

Custom metadata and middlewares

The Custom metadata and middlewares feature was removed in Inversify v7.

This change requires manual review of the codebase to determine if it was used. There is no reliable way to search for this feature automatically.

isBound-like Methods

isBoundNamed is used in pkgs/slash-commands.

pkgs/slash-commands/src/services/SlashCommandFactory/SlashArgInstaller.ts

In executeValidators, di.isBoundNamed and di.getAllNamed are used:

if (di.isBoundNamed(Validator, this.property)) {
    const validators = di.getAllNamed(Validator, this.property);
    for (const validator of validators) {
        await validator.validate(value);
    }
}

This should be changed to:

if (di.isBound(Validator, { name: this.property })) {
    const validators = di.getAll(Validator, { name: this.property });
    for (const validator of validators) {
        await validator.validate(value);
    }
}

Parent and Child Containers

createChild() is used in pkgs/slash-commands to create child containers.

pkgs/slash-commands/src/services/SlashCommandFactory/SlashCommandFactory.ts

In both createSubContainer and complete, createChild is used:

const di = this.parentContainer.createChild({
    skipBaseClassChecks: true,
});

This should be changed to use the Container constructor:

const di = new Container({
    parent: this.parentContainer,
    skipBaseClassChecks: true,
});

Removed interfaces namespace

The interfaces namespace is used and should be removed.

pkgs/slash-commands/src/builtins/decorators/args/channel.ts

The interfaces namespace is imported but not used. The import can be removed.

import { interfaces } from "inversify";

pkgs/slash-commands/src/services/SlashCommandFactory/SlashCommandFactory.ts

interfaces is used to type a service identifier.

import type { Container, interfaces } from "inversify";
// ...
// bind the command class
di.bind(this.meta.target as interfaces.ServiceIdentifier).toSelf();
// ...
// resolve command instance
const inst = subContainer.get<SlashCommand>(
    this.meta.target as interfaces.ServiceIdentifier<SlashCommand>,
);

The import should be changed to import type { Container, ServiceIdentifier } from "inversify"; and the usages updated accordingly.

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type
    No fields configured for issues without a type.

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions