diff --git a/.eslintrc.js b/.eslintrc.js new file mode 100644 index 0000000..4598474 --- /dev/null +++ b/.eslintrc.js @@ -0,0 +1,15 @@ +const { + configure, + presets +} = require("eslint-kit"); + +module.exports = configure({ + allowDebug: process.env.NODE_ENV !== "production", + + presets: [ + presets.imports(), + presets.node(), + presets.prettier(), + presets.typescript() + ], +}); \ No newline at end of file diff --git a/.github/FUNDING.yml b/.github/FUNDING.yml new file mode 100644 index 0000000..b1f0f67 --- /dev/null +++ b/.github/FUNDING.yml @@ -0,0 +1,6 @@ +# These are supported funding model platforms + +github: [jassix] +patreon: jassix +open_collective: jassix +buy_me_a_coffee: jassix diff --git a/.github/dependabot.yml b/.github/dependabot.yml new file mode 100644 index 0000000..e7d6a19 --- /dev/null +++ b/.github/dependabot.yml @@ -0,0 +1,16 @@ +version: 2 +updates: + # GitHub Actions + - package-ecosystem: "github-actions" + directory: "/" + schedule: + interval: "daily" + commit-message: + prefix: ⬆ + # NodeJS + - package-ecosystem: "npm" + directory: "/" + schedule: + interval: "daily" + commit-message: + prefix: ⬆ \ No newline at end of file diff --git a/.gitignore b/.gitignore new file mode 100644 index 0000000..5a80e4d --- /dev/null +++ b/.gitignore @@ -0,0 +1,7 @@ +.DS_Store + +node_modules +.pnpm-debug.log +dist + +.vscode diff --git a/.npmignore b/.npmignore new file mode 100644 index 0000000..1dd0c9c --- /dev/null +++ b/.npmignore @@ -0,0 +1,27 @@ +.git +.github +.gitignore +.prettierrc +.cjs.swcrc +.es.swcrc +.idea +.vscode +bun.lockb + +node_modules +tsconfig.json +pnpm-lock.yaml +jest.config.js +nodemon.json + +example +tests +test +CHANGELOG.md +.eslintrc.js +tsconfig.cjs.json +tsconfig.esm.json +tsconfig.dts.json + +build.ts +src diff --git a/.prettierrc b/.prettierrc new file mode 100644 index 0000000..2e4bf83 --- /dev/null +++ b/.prettierrc @@ -0,0 +1,6 @@ +{ + "semi": false, + "singleQuote": true, + "tabWidth": 2, + "quoteProps": "consistent" +} \ No newline at end of file diff --git a/CHANGELOG.md b/CHANGELOG.md new file mode 100644 index 0000000..598410e --- /dev/null +++ b/CHANGELOG.md @@ -0,0 +1,2 @@ +# 1.0.0 - 7 Aug 2024 +Release diff --git a/LICENSE b/LICENSE new file mode 100644 index 0000000..c61fa0f --- /dev/null +++ b/LICENSE @@ -0,0 +1,21 @@ +MIT License + +Copyright (c) 2024 Mikita Pitunoŭ + +Permission is hereby granted, free of charge, to any person obtaining a copy +of this software and associated documentation files (the "Software"), to deal +in the Software without restriction, including without limitation the rights +to use, copy, modify, merge, publish, distribute, sublicense, and/or sell +copies of the Software, and to permit persons to whom the Software is +furnished to do so, subject to the following conditions: + +The above copyright notice and this permission notice shall be included in all +copies or substantial portions of the Software. + +THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR +IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, +FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE +AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER +LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, +OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE +SOFTWARE. \ No newline at end of file diff --git a/README.md b/README.md new file mode 100644 index 0000000..ff3f5a0 --- /dev/null +++ b/README.md @@ -0,0 +1,141 @@ +# elysia-cqrs +Plugin for [Elysia](https://github.com/elysiajs/elysia) for using [CQRS pattern](https://en.wikipedia.org/wiki/Command_Query_Responsibility_Segregation). + +CQRS Plugin for Elysia is a lightweight extension that implements the Command Query Responsibility Segregation pattern into your Elysia-based application. This plugin allows you to effectively separate read and write operations, providing better scalability, maintainability, and testability of your code. + +## Installation +```bash +bun add elysia-cqrs +``` + +## Example + +```typescript +// commands/create-user/command.ts (example) +import { ICommand } from 'elysia-cqrs' + +class CreateUserCommand extends ICommand { + constructor(public name: string) { + super() + } +} + +// commands/create-user/handler.ts (example) +import { ICommandHandler } from 'elysia-cqrs' +import { CreateUserCommand } from './command.ts' + +class CreateUserHandler implements ICommandHandler { + execute(command: CreateUserCommand) { + return `New user with name ${command.name} was created!` + } +} + +// index.ts (example) +import { Elysia } from 'elysia' +import { cqrs } from 'elysia-cqrs' +import { CreateUserCommand, CreateUserHandler } from '@/commands/create-user' + +const app = new Elysia() + .use(cqrs({ + commands: [ + [CreateUserCommand, new CreateUserHandler()] + ] + })) + .post('/user', ({ body: { name }, commandMediator }) => { + return commandMediator.send(new CreateUserCommand(name)) + }, { + body: t.Object({ + name: t.String(), + }) + }) + .listen(5000) +``` + +## API +This plugin decorates `commandMediator`, `eventMediator`, `queryMediator` into `Context`. + +### commandMediator +The `commandMediator` implements the `CommandMediator` class with these methods and properties: + +```typescript +class CommandMediator extends Mediator { + register( + command: Class, + handler: ICommandHandler, + ): void + + async send(command: ICommand): Promise +} +``` +###### * this is just a sample, not real code. + +*** + +### eventMediator +The `eventMediator` implements the `EventMediator` class with these methods and properties: + +```typescript +class EventMediator extends Mediator { + register(event: Class, handler: IEventHandler): void + send(event: IEvent): void +} +``` +###### * this is just a sample, not real code. + +*** + +### queryMediator +The `queryMediator` implements the `QueryMediator` class with these methods and properties: + +```typescript +class QueryMediator extends Mediator { + register( + query: Class, + handler: IQueryHandler + ): void + + async send(query: IQuery): Promise +} +``` +###### * this is just a sample, not real code. + +*** + +### Base Classes +The library features foundational abstract classes like `ICommand`, `IEvent`, and `IQuery`. These are essential for ensuring standardization and polymorphism. + +*** + +### Handler interfaces +The module additionally offers a range of handler interfaces, drawing inspiration from the @nestsjs/cqrs package. + +```typescript +interface ICommandHandler< + TCommand extends ICommand = never, + TResponse = never, +> { + execute(command: TCommand): TResponse +} + +interface IEventHandler { + handle(event: TEvent): void +} + +interface IQueryHandler< + TQuery extends IQuery = never, + TResponse = never, +> { + execute(query: TQuery): TResponse +} +``` + +## Config +Below is the configurable property for customizing the CQRS plugin. + +```typescript +interface CqrsPluginParams { + commands?: Array<[Class, ICommandHandler]> + events?: Array<[Class, IEventHandler]> + queries?: Array<[Class, IQueryHandler]> +} +``` \ No newline at end of file diff --git a/build.ts b/build.ts new file mode 100644 index 0000000..8d6fa9a --- /dev/null +++ b/build.ts @@ -0,0 +1,28 @@ +import { build, type Options } from 'tsup' + +const tsupConfig: Options = { + entry: ['src/**/*.ts'], + splitting: false, + sourcemap: false, + clean: true, + bundle: true, +} satisfies Options + +await Promise.all([ + // ? tsup esm + build({ + outDir: 'dist', + format: 'esm', + target: 'node20', + cjsInterop: false, + ...tsupConfig, + }), + // ? tsup cjs + build({ + outDir: 'dist/cjs', + format: 'cjs', + target: 'node20', + // dts: true, + ...tsupConfig, + }), +]) diff --git a/bun.lockb b/bun.lockb new file mode 100755 index 0000000..e032c56 Binary files /dev/null and b/bun.lockb differ diff --git a/example/index.ts b/example/index.ts new file mode 100644 index 0000000..aa19e1c --- /dev/null +++ b/example/index.ts @@ -0,0 +1,95 @@ +import { describe, expect, it } from 'bun:test' +import { Elysia, t } from 'elysia' +import { + cqrs, + ICommand, + ICommandHandler, + IEvent, + IEventHandler, + IQuery, + IQueryHandler, +} from '../src' + +// Command + +class CreateUserCommand extends ICommand { + constructor(public name: string) { + super() + } +} + +class CreateUserHandler implements ICommandHandler { + execute(command: CreateUserCommand): string { + return `User created "${command.name}"` + } +} + +// Query + +class ReceiveUserQuery extends IQuery { + constructor(public name: string) { + super() + } +} + +class ReceiveUserHandler implements IQueryHandler { + execute(query: ReceiveUserQuery): string { + return `Found user with name "${query.name}"` + } +} + +// Event + +const messageBuffer: string[] = [] + +class UserRegisteredEvent extends IEvent { + constructor(public name: string) { + super() + } +} + +class UserRegisteredHandler implements IEventHandler { + handle(event: UserRegisteredEvent) { + messageBuffer.push(`A new user registered with name "${event.name}"`) + } +} + +const app = new Elysia() + .use( + cqrs({ + commands: [[CreateUserCommand, new CreateUserHandler()]], + events: [[UserRegisteredEvent, new UserRegisteredHandler()]], + queries: [[ReceiveUserQuery, new ReceiveUserHandler()]], + }), + ) + .get( + '/user/:name', + ({ params: { name }, queryMediator }) => { + return queryMediator.send(new ReceiveUserQuery(name)) + }, + { + params: t.Object({ + name: t.String(), + }), + }, + ) + .post( + '/user', + ({ body: { name }, query, commandMediator, eventMediator }) => { + if (query.event) { + eventMediator.send(new UserRegisteredEvent(name)) + } + + return commandMediator.send(new CreateUserCommand(name)) + }, + { + body: t.Object({ + name: t.String(), + }), + + query: t.Object({ + event: t.Boolean({ default: false }), + }), + }, + ) + .listen(8080) diff --git a/package.json b/package.json new file mode 100644 index 0000000..17469f5 --- /dev/null +++ b/package.json @@ -0,0 +1,54 @@ +{ + "name": "elysia-cqrs", + "version": "1.0.0", + "description": "Plugin for Elysia for retrieving Bearer token", + "license": "MIT", + "main": "./dist/cjs/index.js", + "module": "./dist/index.mjs", + "types": "./dist/index.d.ts", + "exports": { + "./package.json": "./package.json", + ".": { + "types": "./dist/index.d.ts", + "import": "./dist/index.mjs", + "require": "./dist/cjs/index.js" + } + }, + "keywords": [ + "elysia", + "cqrs", + "pattern" + ], + "repository": { + "type": "git", + "url": "https://github.com/jassix/elysia-cqrs" + }, + "author": { + "name": "Mikita Pitunoŭ", + "url": "https://github.com/jassix", + "email": "jassix@pm.me" + }, + "homepage": "https://github.com/jassix/elysia-cqrs", + "bugs": "https://github.com/jassix/elysia-cqrs/issues", + "scripts": { + "dev": "bun run --watch example/index.ts", + "test": "bun test && npm run test:node", + "test:node": "npm install --prefix ./test/node/cjs/ && npm install --prefix ./test/node/esm/ && node ./test/node/cjs/index.js && node ./test/node/esm/index.js", + "build": "bun build.ts", + "release": "npm run build && npm run test && npm publish --access public", + "lint": "eslint \"src/**/*.{js,mjs,cjs,ts,mts}\"", + "lint:fix": "eslint \"src/**/*.{js,mjs,cjs,ts,mts}\" --fix" + }, + "peerDependencies": { + "elysia": ">= 1.1.0" + }, + "devDependencies": { + "elysia": ">= 1.1.0-rc.2", + "@types/bun": "1.1.6", + "eslint": "^8.57.0", + "eslint-kit": "^10.33.0", + "tsup": "^8.1.0", + "typescript": "^5.5.3", + "prettier": "^3.3.3" + } +} \ No newline at end of file diff --git a/src/command.ts b/src/command.ts new file mode 100644 index 0000000..e6fbc09 --- /dev/null +++ b/src/command.ts @@ -0,0 +1,33 @@ +import { Class, Mediator } from './mediator' + +export abstract class ICommand {} + +export interface ICommandHandler< + TCommand extends ICommand = never, + TResponse = never, +> { + execute(command: TCommand): TResponse +} + +export class CommandMediator extends Mediator { + constructor() { + super() + } + + register( + command: Class, + handler: ICommandHandler, + ): void { + this.handlers.set(command.name, handler.execute) + } + + async send(command: ICommand): Promise { + const handler = this.handlers.get(command.constructor.name) + + if (!handler) { + throw new Error(`Cant found handler for command: ${command}`) + } + + return handler(command) + } +} diff --git a/src/event.ts b/src/event.ts new file mode 100644 index 0000000..d3b7aba --- /dev/null +++ b/src/event.ts @@ -0,0 +1,27 @@ +import { Class, Mediator } from './mediator' + +export abstract class IEvent {} + +export interface IEventHandler { + handle(event: TEvent): void +} + +export class EventMediator extends Mediator { + constructor() { + super() + } + + register(event: Class, handler: IEventHandler): void { + this.handlers.set(event.name, handler.handle) + } + + send(event: IEvent): void { + const handler = this.handlers.get(event.constructor.name) + + if (!handler) { + throw new Error(`Cant found handler for event: ${event}`) + } + + return handler(event) + } +} diff --git a/src/index.ts b/src/index.ts new file mode 100644 index 0000000..7ae7a3b --- /dev/null +++ b/src/index.ts @@ -0,0 +1,43 @@ +import { Elysia } from 'elysia' +import { CommandMediator, ICommand, ICommandHandler } from './command' +import { EventMediator, IEvent, IEventHandler } from './event' +import { Class } from './mediator' +import { IQuery, IQueryHandler, QueryMediator } from './query' + +export interface CqrsPluginParams { + commands?: Array<[Class, ICommandHandler]> + events?: Array<[Class, IEventHandler]> + queries?: Array<[Class, IQueryHandler]> +} + +export const cqrs = ({ + commands = [], + events = [], + queries = [], +}: CqrsPluginParams) => { + const commandMediator = new CommandMediator() + const eventMediator = new EventMediator() + const queryMediator = new QueryMediator() + + for (const [command, handler] of commands) { + commandMediator.register(command, handler) + } + + for (const [event, handler] of events) { + eventMediator.register(event, handler) + } + + for (const [query, handler] of queries) { + queryMediator.register(query, handler) + } + + return new Elysia({ name: 'elysia-cqrs' }).derive({ as: 'global' }, () => ({ + commandMediator, + eventMediator, + queryMediator, + })) +} + +export * from './command' +export * from './event' +export * from './query' diff --git a/src/mediator.ts b/src/mediator.ts new file mode 100644 index 0000000..f35d596 --- /dev/null +++ b/src/mediator.ts @@ -0,0 +1,10 @@ +export type IMediatorHandler = (...args: any[]) => any + +// eslint-disable-next-line @typescript-eslint/ban-types +export interface Class extends Function { + new (...args: never[]): T +} + +export abstract class Mediator { + protected handlers: Map = new Map() +} diff --git a/src/query.ts b/src/query.ts new file mode 100644 index 0000000..2ca13ea --- /dev/null +++ b/src/query.ts @@ -0,0 +1,30 @@ +import { Class, Mediator } from './mediator' + +export abstract class IQuery {} + +export interface IQueryHandler< + TQuery extends IQuery = never, + TResponse = never, +> { + execute(query: TQuery): TResponse +} + +export class QueryMediator extends Mediator { + constructor() { + super() + } + + register(query: Class, handler: IQueryHandler): void { + this.handlers.set(query.name, handler.execute) + } + + async send(query: IQuery): Promise { + const handler = this.handlers.get(query.constructor.name) + + if (!handler) { + throw new Error(`Cant found handler for query: ${query}`) + } + + return handler(query) + } +} diff --git a/test/command.test.ts b/test/command.test.ts new file mode 100644 index 0000000..2e43a77 --- /dev/null +++ b/test/command.test.ts @@ -0,0 +1,27 @@ +import { describe, expect, it } from 'bun:test' +import { CommandMediator, ICommand, ICommandHandler } from '../src' + +class CreateUserCommand extends ICommand { + constructor(public name: string) { + super() + } +} + +class CreateUserHandler implements ICommandHandler { + execute(command: CreateUserCommand): string { + return `User created "${command.name}"` + } +} + +describe('register `CommandMediator` without Elysia', () => { + const mediator = new CommandMediator() + + mediator.register(CreateUserCommand, new CreateUserHandler()) + + it('should send data to mediator', async () => { + const command = new CreateUserCommand('Alex') + const mediatorResponse = await mediator.send(command) + + expect(mediatorResponse).toBe(new CreateUserHandler().execute(command)) + }) +}) diff --git a/test/elysia.test.ts b/test/elysia.test.ts new file mode 100644 index 0000000..1660f5e --- /dev/null +++ b/test/elysia.test.ts @@ -0,0 +1,142 @@ +import { describe, expect, it } from 'bun:test' +import { Elysia, t } from 'elysia' +import { + cqrs, + ICommand, + ICommandHandler, + IEvent, + IEventHandler, + IQuery, + IQueryHandler, +} from '../src' + +// Command + +class CreateUserCommand extends ICommand { + constructor(public name: string) { + super() + } +} + +class CreateUserHandler implements ICommandHandler { + execute(command: CreateUserCommand): string { + return `User created "${command.name}"` + } +} + +// Query + +class ReceiveUserQuery extends IQuery { + constructor(public name: string) { + super() + } +} + +class ReceiveUserHandler implements IQueryHandler { + execute(query: ReceiveUserQuery): string { + return `Found user with name "${query.name}"` + } +} + +// Event + +const messageBuffer: string[] = [] + +class UserRegisteredEvent extends IEvent { + constructor(public name: string) { + super() + } +} + +class UserRegisteredHandler implements IEventHandler { + handle(event: UserRegisteredEvent) { + messageBuffer.push(`A new user registered with name "${event.name}"`) + } +} + +// Elysia App + +const app = new Elysia() + .use( + cqrs({ + commands: [[CreateUserCommand, new CreateUserHandler()]], + events: [[UserRegisteredEvent, new UserRegisteredHandler()]], + queries: [[ReceiveUserQuery, new ReceiveUserHandler()]], + }), + ) + .get( + '/user/:name', + ({ params: { name }, queryMediator }) => { + return queryMediator.send(new ReceiveUserQuery(name)) + }, + { + params: t.Object({ + name: t.String(), + }), + }, + ) + .post( + '/user', + ({ body: { name }, query, commandMediator, eventMediator }) => { + if (query.event) { + eventMediator.send(new UserRegisteredEvent(name)) + } + + return commandMediator.send(new CreateUserCommand(name)) + }, + { + body: t.Object({ + name: t.String(), + }), + + query: t.Object({ + event: t.Boolean({ default: false }), + }), + }, + ) + .listen(8080) + +// Base request + +const sendRequest = (url: string, method = 'get', body?: string) => + new Request('http://localhost:5000'.concat(url), { + headers: { 'Content-Type': 'application/json' }, + method, + body, + }) + +// Tests + +describe('elysia test with cqrs module', () => { + it('should send GET /user/:name and receive identical result', async () => { + const name = 'alex' + + const res = await app + .handle(sendRequest(`/user/${name}`)) + .then((r) => r.text()) + + expect(res).toBe( + new ReceiveUserHandler().execute(new ReceiveUserQuery(name)), + ) + }) + + it('should send POST /user and receive identical result', async () => { + const command = new CreateUserCommand('alex') + + const res = await app + .handle(sendRequest(`/user`, 'post', JSON.stringify(command))) + .then((r) => r.text()) + + expect(res).toBe(new CreateUserHandler().execute(command)) + }) + + it('should send POST /user?event=true and receive identical result', async () => { + const command = new CreateUserCommand('alex') + + await app + .handle(sendRequest(`/user?event=true`, 'post', JSON.stringify(command))) + .then((r) => r.text()) + + expect(messageBuffer.length).toBe(1) + }) +}) diff --git a/test/event.test.ts b/test/event.test.ts new file mode 100644 index 0000000..b742d7a --- /dev/null +++ b/test/event.test.ts @@ -0,0 +1,31 @@ +import { describe, expect, it } from 'bun:test' +import { EventMediator, IEvent, IEventHandler } from '../src' + +const messageBuffer: string[] = [] + +class UserRegisteredEvent extends IEvent { + constructor(public name: string) { + super() + } +} + +class UserRegisteredHandler implements IEventHandler { + handle(event: UserRegisteredEvent) { + messageBuffer.push(`A new user registered with name "${event.name}"`) + } +} + +describe('register `EventMediator` without Elysia', () => { + const mediator = new EventMediator() + + mediator.register(UserRegisteredEvent, new UserRegisteredHandler()) + + it('should send data to mediator', async () => { + const event = new UserRegisteredEvent('Alex') + + new UserRegisteredHandler().handle(event) + mediator.send(event) + + expect(messageBuffer.length).toBe(2) + }) +}) diff --git a/test/node/.gitignore b/test/node/.gitignore new file mode 100644 index 0000000..3ea1bb5 --- /dev/null +++ b/test/node/.gitignore @@ -0,0 +1,2 @@ +node_modules/ +package-lock.json \ No newline at end of file diff --git a/test/node/cjs/index.js b/test/node/cjs/index.js new file mode 100644 index 0000000..6d1c1e1 --- /dev/null +++ b/test/node/cjs/index.js @@ -0,0 +1,11 @@ +if ('Bun' in globalThis) { + throw new Error('❌ Use Node.js to run this test!') +} + +const { cqrs } = require('elysia-cqrs') + +if (typeof cqrs !== 'function') { + throw new TypeError('❌ CommonJS Node.js failed') +} + +console.log('✅ CommonJS Node.js works!') diff --git a/test/node/cjs/package.json b/test/node/cjs/package.json new file mode 100644 index 0000000..738141b --- /dev/null +++ b/test/node/cjs/package.json @@ -0,0 +1,6 @@ +{ + "type": "commonjs", + "dependencies": { + "elysia-cqrs": "../../.." + } +} \ No newline at end of file diff --git a/test/node/esm/index.js b/test/node/esm/index.js new file mode 100644 index 0000000..d0d7a1d --- /dev/null +++ b/test/node/esm/index.js @@ -0,0 +1,11 @@ +import { cqrs } from 'elysia-cqrs' + +if ('Bun' in globalThis) { + throw new Error('❌ Use Node.js to run this test!') +} + +if (typeof cqrs !== 'function') { + throw new TypeError('❌ ESM Node.js failed') +} + +console.log('✅ ESM Node.js works!') diff --git a/test/node/esm/package.json b/test/node/esm/package.json new file mode 100644 index 0000000..cdfd903 --- /dev/null +++ b/test/node/esm/package.json @@ -0,0 +1,6 @@ +{ + "type": "module", + "dependencies": { + "elysia-cqrs": "../../.." + } +} \ No newline at end of file diff --git a/test/query.test.ts b/test/query.test.ts new file mode 100644 index 0000000..cdc02de --- /dev/null +++ b/test/query.test.ts @@ -0,0 +1,27 @@ +import { describe, expect, it } from 'bun:test' +import { IQuery, IQueryHandler, QueryMediator } from '../src' + +class ReceiveUserQuery extends IQuery { + constructor(public name: string) { + super() + } +} + +class ReceiveUserHandler implements IQueryHandler { + execute(query: ReceiveUserQuery): string { + return `Found user with name "${query.name}"` + } +} + +describe('register `EventMediator` without Elysia', () => { + const mediator = new QueryMediator() + + mediator.register(ReceiveUserQuery, new ReceiveUserHandler()) + + it('should send data to mediator', async () => { + const query = new ReceiveUserQuery('Alex') + const mediatorResponse = await mediator.send(query) + + expect(mediatorResponse).toBe(new ReceiveUserHandler().execute(query)) + }) +}) diff --git a/tsconfig.dts.json b/tsconfig.dts.json new file mode 100644 index 0000000..cd54e87 --- /dev/null +++ b/tsconfig.dts.json @@ -0,0 +1,106 @@ +{ + "compilerOptions": { + "preserveSymlinks": true, + /* Visit https://aka.ms/tsconfig to read more about this file */ + + /* Projects */ + // "incremental": true, /* Save .tsbuildinfo files to allow for incremental compilation of projects. */ + // "composite": true, /* Enable constraints that allow a TypeScript project to be used with project references. */ + // "tsBuildInfoFile": "./.tsbuildinfo", /* Specify the path to .tsbuildinfo incremental compilation file. */ + // "disableSourceOfProjectReferenceRedirect": true, /* Disable preferring source files instead of declaration files when referencing composite projects. */ + // "disableSolutionSearching": true, /* Opt a project out of multi-project reference checking when editing. */ + // "disableReferencedProjectLoad": true, /* Reduce the number of projects loaded automatically by TypeScript. */ + + /* Language and Environment */ + "target": "ES2021", /* Set the JavaScript language version for emitted JavaScript and include compatible library declarations. */ + "lib": ["ESNext"], /* Specify a set of bundled library declaration files that describe the target runtime environment. */ + // "jsx": "preserve", /* Specify what JSX code is generated. */ + // "experimentalDecorators": true, /* Enable experimental support for TC39 stage 2 draft decorators. */ + // "emitDecoratorMetadata": true, /* Emit design-type metadata for decorated declarations in source files. */ + // "jsxFactory": "", /* Specify the JSX factory function used when targeting React JSX emit, e.g. 'React.createElement' or 'h'. */ + // "jsxFragmentFactory": "", /* Specify the JSX Fragment reference used for fragments when targeting React JSX emit e.g. 'React.Fragment' or 'Fragment'. */ + // "jsxImportSource": "", /* Specify module specifier used to import the JSX factory functions when using 'jsx: react-jsx*'. */ + // "reactNamespace": "", /* Specify the object invoked for 'createElement'. This only applies when targeting 'react' JSX emit. */ + // "noLib": true, /* Disable including any library files, including the default lib.d.ts. */ + // "useDefineForClassFields": true, /* Emit ECMAScript-standard-compliant class fields. */ + // "moduleDetection": "auto", /* Control what method is used to detect module-format JS files. */ + + /* Modules */ + "module": "ES2022", /* Specify what module code is generated. */ + "rootDir": "./src", /* Specify the root folder within your source files. */ + "moduleResolution": "node", /* Specify how TypeScript looks up a file from a given module specifier. */ + // "baseUrl": "./src", /* Specify the base directory to resolve non-relative module names. */ + // "paths": {}, /* Specify a set of entries that re-map imports to additional lookup locations. */ + // "rootDirs": [], /* Allow multiple folders to be treated as one when resolving modules. */ + // "typeRoots": [], /* Specify multiple folders that act like './node_modules/@types'. */ + // "types": ["bun-types"], /* Specify type package names to be included without being referenced in a source file. */ + // "allowUmdGlobalAccess": true, /* Allow accessing UMD globals from modules. */ + // "moduleSuffixes": [], /* List of file name suffixes to search when resolving a module. */ + "resolveJsonModule": true, /* Enable importing .json files. */ + // "noResolve": true, /* Disallow 'import's, 'require's or ''s from expanding the number of files TypeScript should add to a project. */ + + /* JavaScript Support */ + // "allowJs": true, /* Allow JavaScript files to be a part of your program. Use the 'checkJS' option to get errors from these files. */ + // "checkJs": true, /* Enable error reporting in type-checked JavaScript files. */ + // "maxNodeModuleJsDepth": 1, /* Specify the maximum folder depth used for checking JavaScript files from 'node_modules'. Only applicable with 'allowJs'. */ + + /* Emit */ + "declaration": true, /* Generate .d.ts files from TypeScript and JavaScript files in your project. */ + // "declarationMap": true, /* Create sourcemaps for d.ts files. */ + "emitDeclarationOnly": true, /* Only output d.ts files and not JavaScript files. */ + // "sourceMap": true, /* Create source map files for emitted JavaScript files. */ + // "outFile": "./", /* Specify a file that bundles all outputs into one JavaScript file. If 'declaration' is true, also designates a file that bundles all .d.ts output. */ + "outDir": "./dist", /* Specify an output folder for all emitted files. */ + // "removeComments": true, /* Disable emitting comments. */ + // "noEmit": true, /* Disable emitting files from a compilation. */ + // "importHelpers": true, /* Allow importing helper functions from tslib once per project, instead of including them per-file. */ + // "importsNotUsedAsValues": "remove", /* Specify emit/checking behavior for imports that are only used for types. */ + // "downlevelIteration": true, /* Emit more compliant, but verbose and less performant JavaScript for iteration. */ + // "sourceRoot": "", /* Specify the root path for debuggers to find the reference source code. */ + // "mapRoot": "", /* Specify the location where debugger should locate map files instead of generated locations. */ + // "inlineSourceMap": true, /* Include sourcemap files inside the emitted JavaScript. */ + // "inlineSources": true, /* Include source code in the sourcemaps inside the emitted JavaScript. */ + // "emitBOM": true, /* Emit a UTF-8 Byte Order Mark (BOM) in the beginning of output files. */ + // "newLine": "crlf", /* Set the newline character for emitting files. */ + // "stripInternal": true, /* Disable emitting declarations that have '@internal' in their JSDoc comments. */ + // "noEmitHelpers": true, /* Disable generating custom helper functions like '__extends' in compiled output. */ + // "noEmitOnError": true, /* Disable emitting files if any type checking errors are reported. */ + // "preserveConstEnums": true, /* Disable erasing 'const enum' declarations in generated code. */ + // "declarationDir": "./", /* Specify the output directory for generated declaration files. */ + // "preserveValueImports": true, /* Preserve unused imported values in the JavaScript output that would otherwise be removed. */ + + /* Interop Constraints */ + // "isolatedModules": true, /* Ensure that each file can be safely transpiled without relying on other imports. */ + "allowSyntheticDefaultImports": true, /* Allow 'import x from y' when a module doesn't have a default export. */ + "esModuleInterop": true, /* Emit additional JavaScript to ease support for importing CommonJS modules. This enables 'allowSyntheticDefaultImports' for type compatibility. */ + // "preserveSymlinks": true, /* Disable resolving symlinks to their realpath. This correlates to the same flag in node. */ + "forceConsistentCasingInFileNames": true, /* Ensure that casing is correct in imports. */ + + /* Type Checking */ + "strict": true, /* Enable all strict type-checking options. */ + // "noImplicitAny": true, /* Enable error reporting for expressions and declarations with an implied 'any' type. */ + // "strictNullChecks": true, /* When type checking, take into account 'null' and 'undefined'. */ + // "strictFunctionTypes": true, /* When assigning functions, check to ensure parameters and the return values are subtype-compatible. */ + // "strictBindCallApply": true, /* Check that the arguments for 'bind', 'call', and 'apply' methods match the original function. */ + // "strictPropertyInitialization": true, /* Check for class properties that are declared but not set in the constructor. */ + // "noImplicitThis": true, /* Enable error reporting when 'this' is given the type 'any'. */ + // "useUnknownInCatchVariables": true, /* Default catch clause variables as 'unknown' instead of 'any'. */ + // "alwaysStrict": true, /* Ensure 'use strict' is always emitted. */ + // "noUnusedLocals": true, /* Enable error reporting when local variables aren't read. */ + // "noUnusedParameters": true, /* Raise an error when a function parameter isn't read. */ + // "exactOptionalPropertyTypes": true, /* Interpret optional property types as written, rather than adding 'undefined'. */ + // "noImplicitReturns": true, /* Enable error reporting for codepaths that do not explicitly return in a function. */ + // "noFallthroughCasesInSwitch": true, /* Enable error reporting for fallthrough cases in switch statements. */ + // "noUncheckedIndexedAccess": true, /* Add 'undefined' to a type when accessed using an index. */ + // "noImplicitOverride": true, /* Ensure overriding members in derived classes are marked with an override modifier. */ + // "noPropertyAccessFromIndexSignature": true, /* Enforces using indexed accessors for keys declared using an indexed type. */ + // "allowUnusedLabels": true, /* Disable error reporting for unused labels. */ + // "allowUnreachableCode": true, /* Disable error reporting for unreachable code. */ + + /* Completeness */ + // "skipDefaultLibCheck": true, /* Skip type checking .d.ts files that are included with TypeScript. */ + "skipLibCheck": true, /* Skip type checking all .d.ts files. */ + }, + "exclude": ["node_modules", "test", "example", "dist", "build.ts"] + // "include": ["src/**/*"] +} diff --git a/tsconfig.json b/tsconfig.json new file mode 100644 index 0000000..80b213d --- /dev/null +++ b/tsconfig.json @@ -0,0 +1,104 @@ +{ + "compilerOptions": { + /* Visit https://aka.ms/tsconfig to read more about this file */ + + /* Projects */ + // "incremental": true, /* Save .tsbuildinfo files to allow for incremental compilation of projects. */ + // "composite": true, /* Enable constraints that allow a TypeScript project to be used with project references. */ + // "tsBuildInfoFile": "./.tsbuildinfo", /* Specify the path to .tsbuildinfo incremental compilation file. */ + // "disableSourceOfProjectReferenceRedirect": true, /* Disable preferring source files instead of declaration files when referencing composite projects. */ + // "disableSolutionSearching": true, /* Opt a project out of multi-project reference checking when editing. */ + // "disableReferencedProjectLoad": true, /* Reduce the number of projects loaded automatically by TypeScript. */ + + /* Language and Environment */ + "target": "ES2020", /* Set the JavaScript language version for emitted JavaScript and include compatible library declarations. */ + "lib": ["ESNext", "DOM", "ScriptHost"], /* Specify a set of bundled library declaration files that describe the target runtime environment. */ + // "jsx": "preserve", /* Specify what JSX code is generated. */ + // "experimentalDecorators": true, /* Enable experimental support for TC39 stage 2 draft decorators. */ + // "emitDecoratorMetadata": true, /* Emit design-type metadata for decorated declarations in source files. */ + // "jsxFactory": "", /* Specify the JSX factory function used when targeting React JSX emit, e.g. 'React.createElement' or 'h'. */ + // "jsxFragmentFactory": "", /* Specify the JSX Fragment reference used for fragments when targeting React JSX emit e.g. 'React.Fragment' or 'Fragment'. */ + // "jsxImportSource": "", /* Specify module specifier used to import the JSX factory functions when using 'jsx: react-jsx*'. */ + // "reactNamespace": "", /* Specify the object invoked for 'createElement'. This only applies when targeting 'react' JSX emit. */ + // "noLib": true, /* Disable including any library files, including the default lib.d.ts. */ + // "useDefineForClassFields": true, /* Emit ECMAScript-standard-compliant class fields. */ + // "moduleDetection": "auto", /* Control what method is used to detect module-format JS files. */ + + /* Modules */ + "module": "ES2022", /* Specify what module code is generated. */ + // "rootDir": "./src", /* Specify the root folder within your source files. */ + "moduleResolution": "node", /* Specify how TypeScript looks up a file from a given module specifier. */ + // "baseUrl": "./src", /* Specify the base directory to resolve non-relative module names. */ + // "paths": {}, /* Specify a set of entries that re-map imports to additional lookup locations. */ + // "rootDirs": [], /* Allow multiple folders to be treated as one when resolving modules. */ + // "typeRoots": [], /* Specify multiple folders that act like './node_modules/@types'. */ + // "types": ["bun-types"], /* Specify type package names to be included without being referenced in a source file. */ + // "allowUmdGlobalAccess": true, /* Allow accessing UMD globals from modules. */ + // "moduleSuffixes": [], /* List of file name suffixes to search when resolving a module. */ + // "resolveJsonModule": true, /* Enable importing .json files. */ + // "noResolve": true, /* Disallow 'import's, 'require's or ''s from expanding the number of files TypeScript should add to a project. */ + + /* JavaScript Support */ + // "allowJs": true, /* Allow JavaScript files to be a part of your program. Use the 'checkJS' option to get errors from these files. */ + // "checkJs": true, /* Enable error reporting in type-checked JavaScript files. */ + // "maxNodeModuleJsDepth": 1, /* Specify the maximum folder depth used for checking JavaScript files from 'node_modules'. Only applicable with 'allowJs'. */ + + /* Emit */ + "declaration": true, /* Generate .d.ts files from TypeScript and JavaScript files in your project. */ + // "declarationMap": true, /* Create sourcemaps for d.ts files. */ + // "emitDeclarationOnly": true, /* Only output d.ts files and not JavaScript files. */ + // "sourceMap": true, /* Create source map files for emitted JavaScript files. */ + // "outFile": "./", /* Specify a file that bundles all outputs into one JavaScript file. If 'declaration' is true, also designates a file that bundles all .d.ts output. */ + // "outDir": "./dist", /* Specify an output folder for all emitted files. */ + // "removeComments": true, /* Disable emitting comments. */ + "noEmit": true, /* Disable emitting files from a compilation. */ + // "importHelpers": true, /* Allow importing helper functions from tslib once per project, instead of including them per-file. */ + // "importsNotUsedAsValues": "remove", /* Specify emit/checking behavior for imports that are only used for types. */ + // "downlevelIteration": true, /* Emit more compliant, but verbose and less performant JavaScript for iteration. */ + // "sourceRoot": "", /* Specify the root path for debuggers to find the reference source code. */ + // "mapRoot": "", /* Specify the location where debugger should locate map files instead of generated locations. */ + // "inlineSourceMap": true, /* Include sourcemap files inside the emitted JavaScript. */ + // "inlineSources": true, /* Include source code in the sourcemaps inside the emitted JavaScript. */ + // "emitBOM": true, /* Emit a UTF-8 Byte Order Mark (BOM) in the beginning of output files. */ + // "newLine": "crlf", /* Set the newline character for emitting files. */ + // "stripInternal": true, /* Disable emitting declarations that have '@internal' in their JSDoc comments. */ + // "noEmitHelpers": true, /* Disable generating custom helper functions like '__extends' in compiled output. */ + // "noEmitOnError": true, /* Disable emitting files if any type checking errors are reported. */ + // "preserveConstEnums": true, /* Disable erasing 'const enum' declarations in generated code. */ + // "declarationDir": "./", /* Specify the output directory for generated declaration files. */ + // "preserveValueImports": true, /* Preserve unused imported values in the JavaScript output that would otherwise be removed. */ + + /* Interop Constraints */ + // "isolatedModules": true, /* Ensure that each file can be safely transpiled without relying on other imports. */ + // "allowSyntheticDefaultImports": true, /* Allow 'import x from y' when a module doesn't have a default export. */ + "esModuleInterop": true, /* Emit additional JavaScript to ease support for importing CommonJS modules. This enables 'allowSyntheticDefaultImports' for type compatibility. */ + // "preserveSymlinks": true, /* Disable resolving symlinks to their realpath. This correlates to the same flag in node. */ + "forceConsistentCasingInFileNames": true, /* Ensure that casing is correct in imports. */ + + /* Type Checking */ + "strict": true, /* Enable all strict type-checking options. */ + // "noImplicitAny": true, /* Enable error reporting for expressions and declarations with an implied 'any' type. */ + // "strictNullChecks": true, /* When type checking, take into account 'null' and 'undefined'. */ + // "strictFunctionTypes": true, /* When assigning functions, check to ensure parameters and the return values are subtype-compatible. */ + // "strictBindCallApply": true, /* Check that the arguments for 'bind', 'call', and 'apply' methods match the original function. */ + // "strictPropertyInitialization": true, /* Check for class properties that are declared but not set in the constructor. */ + // "noImplicitThis": true, /* Enable error reporting when 'this' is given the type 'any'. */ + // "useUnknownInCatchVariables": true, /* Default catch clause variables as 'unknown' instead of 'any'. */ + // "alwaysStrict": true, /* Ensure 'use strict' is always emitted. */ + // "noUnusedLocals": true, /* Enable error reporting when local variables aren't read. */ + // "noUnusedParameters": true, /* Raise an error when a function parameter isn't read. */ + // "exactOptionalPropertyTypes": true, /* Interpret optional property types as written, rather than adding 'undefined'. */ + // "noImplicitReturns": true, /* Enable error reporting for codepaths that do not explicitly return in a function. */ + // "noFallthroughCasesInSwitch": true, /* Enable error reporting for fallthrough cases in switch statements. */ + // "noUncheckedIndexedAccess": true, /* Add 'undefined' to a type when accessed using an index. */ + // "noImplicitOverride": true, /* Ensure overriding members in derived classes are marked with an override modifier. */ + // "noPropertyAccessFromIndexSignature": true, /* Enforces using indexed accessors for keys declared using an indexed type. */ + // "allowUnusedLabels": true, /* Disable error reporting for unused labels. */ + // "allowUnreachableCode": true, /* Disable error reporting for unreachable code. */ + + /* Completeness */ + // "skipDefaultLibCheck": true, /* Skip type checking .d.ts files that are included with TypeScript. */ + "skipLibCheck": true, /* Skip type checking all .d.ts files. */ + }, + // "include": ["src/**/*"] +}