diff --git a/src/_internal.ts b/src/_internal.ts index f0bf834..fd40910 100644 --- a/src/_internal.ts +++ b/src/_internal.ts @@ -1,40 +1,4 @@ -import type { Interaction } from 'discord.js'; -import { mergeMap, merge, concatMap } from 'rxjs'; -import { PayloadType } from './core/structures/enums'; -import { shouldHandle } from './core/module-loading' -import { - isAutocomplete, - isCommand, - isMessageComponent, - isModal, - sharedEventStream, - SernError, - filterTap, - resultPayload, - type _Module, -} from './core/_internal'; -import { createInteractionHandler, executeModule, makeModuleExecutor } from './handlers/event-utils'; -import type { Emitter, ErrorHandling, Logging } from './core/interfaces' -function interactionHandler(client: Emitter, - emitter: Emitter, - log: Logging, - err: ErrorHandling, - modules: Map) { - const interactionStream$ = sharedEventStream(client, 'interactionCreate'); - const handle = createInteractionHandler(interactionStream$, modules); - const interactionHandler$ = merge(handle(isMessageComponent), - handle(isAutocomplete), - handle(isCommand), - handle(isModal)); - return interactionHandler$ - .pipe(filterTap(e => emitter.emit('warning', resultPayload(PayloadType.Warning, undefined, e))), - concatMap(makeModuleExecutor(module => - emitter.emit('module.activate', resultPayload(PayloadType.Failure, module, SernError.PluginFailure)))), - mergeMap(payload => executeModule(emitter, log, err, payload))); -} -export const __start = (entryPoint: string, wrapper: { defaultPrefix?: string }) => { -} diff --git a/src/core/module-loading.ts b/src/core/module-loading.ts index b2be6ab..14e620f 100644 --- a/src/core/module-loading.ts +++ b/src/core/module-loading.ts @@ -3,10 +3,10 @@ import assert from 'assert'; import { existsSync } from 'fs'; -export const parseCallsite = (fpath: string) => { - const pathobj = path.parse(fpath.replace(/file:\\?/, "") - .split(path.sep) - .join(path.posix.sep)) +export const parseCallsite = (site: string) => { + const pathobj = path.parse(site.replace(/file:\\?/, "") + .split(path.sep) + .join(path.posix.sep)) return { name: pathobj.name, absPath : path.posix.format(pathobj) } } @@ -16,7 +16,7 @@ export const shouldHandle = (pth: string, filenam: string) => { let newPath = path.join(path.dirname(pth), file_name) .replace(/file:\\?/, ""); return { exists: existsSync(newPath), - path: 'file:///'+newPath }; + path: 'file://'+newPath }; } diff --git a/src/sern.ts b/src/sern.ts index e3a41c0..70fe15e 100644 --- a/src/sern.ts +++ b/src/sern.ts @@ -1,8 +1,7 @@ import callsites from 'callsites'; import * as Files from './core/module-loading'; import { Services } from './core/ioc'; - - +import type { DependencyList } from './types/ioc'; interface Wrapper { commands?: string; @@ -10,6 +9,16 @@ interface Wrapper { events?: string; } +const __start = (entryPoint: string, + wrapper: { defaultPrefix?: string }, + dependencies: DependencyList) => { + console.log(entryPoint) + import(entryPoint) + .then(({ __commands, __events=new Map() }) => { + console.log(__commands, __events) + }) + .catch(err => dependencies[2]?.error({ message: err })); +} /** * @since 1.0.0 * @param wrapper Options to pass into sern. @@ -28,10 +37,10 @@ export function init(wrapper: Wrapper) { const initCallsite = callsites()[1].getFileName(); const handlerModule = Files.shouldHandle(initCallsite!, "handler"); + console.log(handlerModule) if(!handlerModule.exists) { - throw Error("Cannot locate handler file. Did you run sern build?"); + throw Error("Could not find handler module, did you run sern build?") } - import(handlerModule.path) - .then(({ start }) => start(initCallsite, wrapper)) - .catch(err => dependencies[2].error({ message: err })) + __start(handlerModule.path, wrapper, dependencies); } + diff --git a/test/core/contracts.test.ts b/test/core/contracts.test.ts index 6797c50..1ecb461 100644 --- a/test/core/contracts.test.ts +++ b/test/core/contracts.test.ts @@ -1,6 +1,6 @@ import { assertType, describe, it } from 'vitest'; -import { __Services } from '../../src/core/structures'; +import * as __Services from '../../src/core/structures/default-services'; import * as Contracts from '../../src/core/interfaces'; describe('default contracts', () => { diff --git a/test/core/ioc.test.ts b/test/core/ioc.test.ts index 5c84dfb..46cd0c0 100644 --- a/test/core/ioc.test.ts +++ b/test/core/ioc.test.ts @@ -2,7 +2,7 @@ import { beforeEach, describe, expect, it, vi } from 'vitest'; import { CoreContainer } from '../../src/core/ioc/container'; import { EventEmitter } from 'events'; import { Disposable, Emitter, Init, Logging } from '../../src/core/interfaces'; -import { __Services } from '../../src/core/structures' +import * as __Services from '../../src/core/structures/default-services' import { CoreDependencies } from '../../src/types/ioc'; describe('ioc container', () => { diff --git a/test/core/presence.test.ts b/test/core/presence.test.ts index 904b863..f9a590b 100644 --- a/test/core/presence.test.ts +++ b/test/core/presence.test.ts @@ -5,7 +5,7 @@ import { Presence } from '../../src'; // Example test suite for the module function describe('module function', () => { it('should return a valid configuration', () => { - const config: Presence.Config<['dependency1', 'dependency2']> = Presence.module({ + const config = Presence.module({ inject: ['dependency1', 'dependency2'], execute: vi.fn(), }); diff --git a/test/core/services.test.ts b/test/core/services.test.ts index 148fdf6..09cea94 100644 --- a/test/core/services.test.ts +++ b/test/core/services.test.ts @@ -1,6 +1,6 @@ import { SpyInstance, afterAll, beforeEach, describe, expect, it, vi } from 'vitest'; import { CoreContainer } from '../../src/core/ioc/container'; -import { __Services } from '../../src/core/structures/'; +import * as __Services from '../../src/core/structures/default-services'; import { faker } from '@faker-js/faker'; import { commandModule, CommandType } from '../../src'; diff --git a/test/handlers/dispatchers.test.ts b/test/handlers/dispatchers.test.ts index bcb701d..a5ce406 100644 --- a/test/handlers/dispatchers.test.ts +++ b/test/handlers/dispatchers.test.ts @@ -1,8 +1,8 @@ import { beforeEach, describe, expect, vi, it } from 'vitest'; -import { eventDispatcher } from '../../src/handlers/dispatchers'; +import { eventDispatcher } from '../../src/handlers/event-utils'; import { faker } from '@faker-js/faker'; import { Module } from '../../src/types/core-modules'; -import { Processed } from '../../src/handlers/types'; +import { Processed } from '../../src/types/core-modules'; import { CommandType } from '../../src/core/structures/enums'; import { EventEmitter } from 'events'; diff --git a/test/handlers/id.test.ts b/test/handlers/id.test.ts deleted file mode 100644 index d830690..0000000 --- a/test/handlers/id.test.ts +++ /dev/null @@ -1,47 +0,0 @@ -import { describe, expect, it, vi } from 'vitest'; -import * as Id from '../../src/core/id'; -import { faker } from '@faker-js/faker'; -import { CommandModule, CommandType, commandModule } from '../../src'; - -function createRandomCommandModules() { - const randomCommandType = [ - CommandType.Text, - CommandType.Both, - CommandType.CtxMsg, - CommandType.CtxUser, - CommandType.Modal, - CommandType.ChannelSelect, - CommandType.RoleSelect, - CommandType.UserSelect, - CommandType.StringSelect, - CommandType.Button, - ]; - return commandModule({ - type: faker.helpers.uniqueArray(randomCommandType, 1)[0], - description: faker.string.alpha(), - name: faker.string.alpha(), - execute: () => {}, - }); -} -function createMetadata(c: CommandModule) { - return { - fullPath: faker.system.filePath(), - id: Id.create(c.name, c.type), - isClass: Boolean(Math.floor(Math.random())), - }; -} -const appBitField = 0b000000001111; - -describe('id resolution', () => { - it('should resolve application commands correctly', () => { - const modules = faker.helpers.multiple(createRandomCommandModules, { - count: 20, - }); - const metadata = modules.map(createMetadata); - metadata.forEach((meta, idx) => { - const associatedModule = modules[idx]; - const uid = Id.create(associatedModule.name!, associatedModule.type!); - expect(meta.id).toBe(uid); - }); - }); -}); diff --git a/tsconfig.json b/tsconfig.json index abc01ec..61d0910 100644 --- a/tsconfig.json +++ b/tsconfig.json @@ -4,7 +4,7 @@ "strict": true, "esModuleInterop": true, "strictNullChecks": true, - "moduleResolution": "node", + "moduleResolution": "node16", "skipLibCheck": true, "declaration": true, "preserveSymlinks": true, @@ -12,8 +12,9 @@ "forceConsistentCasingInFileNames": true, "isolatedModules": true, "outDir": "dist", - "module": "commonjs", - "target": "esnext" + "module": "node16", + "target": "esnext", + "sourceMap": true }, "exclude": ["node_modules", "dist"], "include": ["./src", "./src/**/*.d.ts"]