Skip to content

Commit

Permalink
move stuff, refactor, deprecate
Browse files Browse the repository at this point in the history
  • Loading branch information
jacoobes committed Feb 7, 2024
1 parent 2c0d341 commit 945df85
Show file tree
Hide file tree
Showing 11 changed files with 36 additions and 39 deletions.
3 changes: 3 additions & 0 deletions package.json
Original file line number Diff line number Diff line change
Expand Up @@ -94,5 +94,8 @@
"type": "git",
"url": "git+https://github.com/sern-handler/handler.git"
},
"engines": {
"node": ">= 18.16.x"
},
"homepage": "https://sern.dev"
}
9 changes: 0 additions & 9 deletions src/core/contracts/disposable.ts

This file was deleted.

16 changes: 16 additions & 0 deletions src/core/contracts/hooks.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,16 @@

/**
* Represents an initialization contract.
* Let dependencies implement this to initiate some logic.
*/
export interface Init {
init(): unknown;
}

/**
* Represents a Disposable contract.
* Let dependencies implement this to dispose and cleanup.
*/
export interface Disposable {
dispose(): unknown;
}
3 changes: 1 addition & 2 deletions src/core/contracts/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,5 @@ export * from './error-handling';
export * from './logging';
export * from './module-manager';
export * from './module-store';
export * from './init';
export * from './hooks';
export * from './emitter';
export * from './disposable'
8 changes: 0 additions & 8 deletions src/core/contracts/init.ts

This file was deleted.

15 changes: 6 additions & 9 deletions src/core/ioc/base.ts
Original file line number Diff line number Diff line change
Expand Up @@ -40,9 +40,8 @@ const dependencyBuilder = (container: any, excluded: string[] ) => {
* Supply the correct key and dependency
*/
add(key: keyof Dependencies, v: Insertable) {
Result
.wrap(() => container.add({ [key]: v}))
.expect("Failed to add " + key);
Result.wrap(() => container.add({ [key]: v}))
.expect("Failed to add " + key);
},
/**
* Exclude any dependencies from being added.
Expand All @@ -58,9 +57,8 @@ const dependencyBuilder = (container: any, excluded: string[] ) => {
* Swap out a preexisting dependency.
*/
swap(key: keyof Dependencies, v: Insertable) {
Result
.wrap(() => container.upsert({ [key]: v }))
.expect("Failed to update " + key);
Result.wrap(() => container.upsert({ [key]: v }))
.expect("Failed to update " + key);
},
/**
* @param key the key of the dependency
Expand All @@ -72,9 +70,8 @@ const dependencyBuilder = (container: any, excluded: string[] ) => {
* Swap out a preexisting dependency.
*/
addDisposer(key: keyof Dependencies, cleanup: AnyFunction) {
Result
.wrap(() => container.addDisposer({ [key] : cleanup }))
.expect("Failed to addDisposer for" + key);
Result.wrap(() => container.addDisposer({ [key] : cleanup }))
.expect("Failed to addDisposer for" + key);
}
};
};
Expand Down
6 changes: 2 additions & 4 deletions src/core/ioc/container.ts
Original file line number Diff line number Diff line change
Expand Up @@ -41,16 +41,14 @@ export class CoreContainer<T extends Partial<Dependencies>> extends Container<T,
}

override async disposeAll() {

const otherDisposables = Object
.entries(this._context)
.flatMap(([key, value]) =>
'dispose' in value ? [key] : []);

for(const key of otherDisposables) {
otherDisposables.forEach(key => {
//possible source of bug: dispose is a property.
this.addDisposer({ [key]: (dep: Disposable) => dep.dispose() } as never);
}
})
await super.disposeAll();
}

Expand Down
3 changes: 1 addition & 2 deletions src/core/operators.ts
Original file line number Diff line number Diff line change
Expand Up @@ -71,8 +71,7 @@ export function handleError<C>(crashHandler: ErrorHandling, logging?: Logging) {
}
// Temporary until i get rxjs operators working on ts-results-es
export const filterTap = <K, R>(onErr: (e: R) => void): OperatorFunction<Result<K, R>, K> =>
pipe(
concatMap(result => {
pipe(concatMap(result => {
if(result.isOk()) {
return of(result.value)
}
Expand Down
5 changes: 2 additions & 3 deletions src/core/structures/module-store.ts
Original file line number Diff line number Diff line change
@@ -1,12 +1,11 @@
import { CommandMeta, Module } from '../../types/core-modules';
import { CoreModuleStore } from '../contracts';

/*
* @internal
* @deprecated
* Version 4.0.0 will internalize this api. Please refrain from using ModuleStore!
* For interacting with modules, use the ModuleManager instead.
*/
export class ModuleStore implements CoreModuleStore {
export class ModuleStore {
metadata = new WeakMap<Module, CommandMeta>();
commands = new Map<string, string>();
}
3 changes: 1 addition & 2 deletions src/handlers/event-utils.ts
Original file line number Diff line number Diff line change
Expand Up @@ -86,8 +86,7 @@ export function createInteractionHandler<T extends Interaction>(
module: payload.module,
event,
})));
},
);
});
}

export function createMessageHandler(
Expand Down
4 changes: 4 additions & 0 deletions src/types/ioc.ts
Original file line number Diff line number Diff line change
Expand Up @@ -27,6 +27,10 @@ export type DependencyList = [
export interface CoreDependencies {
'@sern/client': () => Contracts.Emitter;
'@sern/emitter': () => Contracts.Emitter;
/**
* @deprecated
* Will be removed and turned internal
*/
'@sern/store': () => Contracts.CoreModuleStore;
'@sern/modules': () => Contracts.ModuleManager;
'@sern/errors': () => Contracts.ErrorHandling;
Expand Down

0 comments on commit 945df85

Please sign in to comment.