From e8e299387864c8e3b0c8b710eff1a58bba848f4e Mon Sep 17 00:00:00 2001 From: Craig Harshbarger Date: Sun, 16 Feb 2025 19:31:46 -0600 Subject: [PATCH 1/2] Add api docs --- docs/.vitepress/config.ts | 24 +- docs/api.md | 1 - docs/api/errors/EmitterTimeoutError.md | 69 ++++ docs/api/functions/createEmitter.md | 254 ++++++++++++++ docs/api/index.md | 20 ++ docs/api/typedoc-sidebar.json | 60 ++++ docs/api/types/EmitterEvents.md | 5 + docs/api/types/EmitterNextOptions.md | 13 + docs/api/types/EmitterOnOptions.md | 13 + docs/api/types/EmitterOnceOptions.md | 13 + docs/api/types/EmitterOptions.md | 13 + docs/api/types/EventHandler.md | 21 ++ docs/api/types/GlobalEventHandler.md | 21 ++ docs/api/types/GlobalEventHandlerResponse.md | 11 + package-lock.json | 329 +++++++++++++++++++ package.json | 6 +- scripts/api.js | 111 +++++++ src/errors.ts | 4 + typedoc.mjs | 31 ++ typedoc.tsconfig.json | 5 + 20 files changed, 1014 insertions(+), 10 deletions(-) delete mode 100644 docs/api.md create mode 100644 docs/api/errors/EmitterTimeoutError.md create mode 100644 docs/api/functions/createEmitter.md create mode 100644 docs/api/index.md create mode 100644 docs/api/typedoc-sidebar.json create mode 100644 docs/api/types/EmitterEvents.md create mode 100644 docs/api/types/EmitterNextOptions.md create mode 100644 docs/api/types/EmitterOnOptions.md create mode 100644 docs/api/types/EmitterOnceOptions.md create mode 100644 docs/api/types/EmitterOptions.md create mode 100644 docs/api/types/EventHandler.md create mode 100644 docs/api/types/GlobalEventHandler.md create mode 100644 docs/api/types/GlobalEventHandlerResponse.md create mode 100644 scripts/api.js create mode 100644 typedoc.mjs create mode 100644 typedoc.tsconfig.json diff --git a/docs/.vitepress/config.ts b/docs/.vitepress/config.ts index e6b6a50..013fbeb 100644 --- a/docs/.vitepress/config.ts +++ b/docs/.vitepress/config.ts @@ -1,4 +1,5 @@ import { defineConfig } from 'vitepress' +import typedocSidebar from '../api/typedoc-sidebar.json'; export default defineConfig({ title: "Kitbag Events | Simple lightweight event bus written in Typescript.", @@ -8,15 +9,22 @@ export default defineConfig({ logo: '/kitbag-logo-circle.svg', siteTitle: 'Kitbag Events', + editLink: { + pattern: 'https://github.com/kitbagjs/events/edit/main/docs/:path', + text: 'Suggest changes to this page', + }, + + nav: [ + { text: 'Guide', link: '/getting-started' }, + { text: 'API', link: '/api/index' } + ], + + search: { + provider: 'local' + }, + sidebar: { - '/api/': [ - { - text: 'packages', - items: [ - { text: '@kitbag/events', link: '/api/modules/kitbag' }, - ], - }, - ], + '/api/': typedocSidebar, '/': [ { text: 'Guide', diff --git a/docs/api.md b/docs/api.md deleted file mode 100644 index 5932792..0000000 --- a/docs/api.md +++ /dev/null @@ -1 +0,0 @@ -# API diff --git a/docs/api/errors/EmitterTimeoutError.md b/docs/api/errors/EmitterTimeoutError.md new file mode 100644 index 0000000..5d4dae3 --- /dev/null +++ b/docs/api/errors/EmitterTimeoutError.md @@ -0,0 +1,69 @@ +# Errors: EmitterTimeoutError + +An error thrown when a timeout occurs while waiting for an event to be emitted. + +## Extends + +- `Error` + +## Constructors + +### new EmitterTimeoutError() + +```ts +new EmitterTimeoutError(event, timeout): EmitterTimeoutError +``` + +#### Parameters + +| Parameter | Type | +| ------ | ------ | +| `event` | `string` | +| `timeout` | `number` | + +#### Returns + +[`EmitterTimeoutError`](EmitterTimeoutError.md) + +#### Overrides + +```ts +Error.constructor +``` + +## Methods + +### captureStackTrace() + +```ts +static captureStackTrace(targetObject, constructorOpt?): void +``` + +Create .stack property on a target object + +#### Parameters + +| Parameter | Type | +| ------ | ------ | +| `targetObject` | `object` | +| `constructorOpt`? | `Function` | + +#### Returns + +`void` + +#### Inherited from + +```ts +Error.captureStackTrace +``` + +## Properties + +| Property | Modifier | Type | Description | Inherited from | +| ------ | ------ | ------ | ------ | ------ | +| `message` | `public` | `string` | - | `Error.message` | +| `name` | `public` | `string` | - | `Error.name` | +| `stack?` | `public` | `string` | - | `Error.stack` | +| `prepareStackTrace?` | `static` | (`err`: `Error`, `stackTraces`: `CallSite`[]) => `any` | Optional override for formatting stack traces **See** https://v8.dev/docs/stack-trace-api#customizing-stack-traces | `Error.prepareStackTrace` | +| `stackTraceLimit` | `static` | `number` | - | `Error.stackTraceLimit` | diff --git a/docs/api/functions/createEmitter.md b/docs/api/functions/createEmitter.md new file mode 100644 index 0000000..e0156f8 --- /dev/null +++ b/docs/api/functions/createEmitter.md @@ -0,0 +1,254 @@ +# Functions: createEmitter() + +```ts +function createEmitter(options?): object +``` + +## Type Parameters + +| Type Parameter | +| ------ | +| `TEvents` *extends* [`EmitterEvents`](../types/EmitterEvents.md) | + +## Parameters + +| Parameter | Type | +| ------ | ------ | +| `options`? | [`EmitterOptions`](../types/EmitterOptions.md) | + +## Returns + +`object` + +### clear() + +```ts +clear: () => void; +``` + +#### Returns + +`void` + +### emit() + +```ts +emit: (event) => void(event, payload) => void; +``` + +#### Type Parameters + +| Type Parameter | +| ------ | +| `E` *extends* `string` \| `number` \| `symbol` | + +#### Parameters + +| Parameter | Type | +| ------ | ------ | +| `event` | `undefined` *extends* `EventPayload`\<`TEvents`, `E`\> ? `E` : `never` | + +#### Returns + +`void` + +#### Type Parameters + +| Type Parameter | +| ------ | +| `E` *extends* `string` \| `number` \| `symbol` | + +#### Parameters + +| Parameter | Type | +| ------ | ------ | +| `event` | `E` | +| `payload` | `EventPayload`\<`TEvents`, `E`\> | + +#### Returns + +`void` + +### next() + +```ts +next: (options?) => Promise>(event, options?) => Promise>; +``` + +#### Parameters + +| Parameter | Type | +| ------ | ------ | +| `options`? | [`EmitterNextOptions`](../types/EmitterNextOptions.md) | + +#### Returns + +`Promise`\<[`GlobalEventHandlerResponse`](../types/GlobalEventHandlerResponse.md)\<`TEvents`\>\> + +#### Type Parameters + +| Type Parameter | +| ------ | +| `E` *extends* `string` \| `number` \| `symbol` | + +#### Parameters + +| Parameter | Type | +| ------ | ------ | +| `event` | `E` | +| `options`? | [`EmitterNextOptions`](../types/EmitterNextOptions.md) | + +#### Returns + +`Promise`\<`EventPayload`\<`TEvents`, `E`\>\> + +### off() + +```ts +off: (globalEventHandler) => void(event) => void(event, handler) => void; +``` + +#### Parameters + +| Parameter | Type | +| ------ | ------ | +| `globalEventHandler` | [`GlobalEventHandler`](../types/GlobalEventHandler.md)\<`TEvents`\> | + +#### Returns + +`void` + +#### Type Parameters + +| Type Parameter | +| ------ | +| `E` *extends* `string` \| `number` \| `symbol` | + +#### Parameters + +| Parameter | Type | +| ------ | ------ | +| `event` | `E` | + +#### Returns + +`void` + +#### Type Parameters + +| Type Parameter | +| ------ | +| `E` *extends* `string` \| `number` \| `symbol` | + +#### Parameters + +| Parameter | Type | +| ------ | ------ | +| `event` | `E` | +| `handler` | [`EventHandler`](../types/EventHandler.md)\<`EventPayload`\<`TEvents`, `E`\>\> | + +#### Returns + +`void` + +### on() + +```ts +on: (globalEventHandler, options?) => () => void(event, handler, options?) => () => void; +``` + +#### Parameters + +| Parameter | Type | +| ------ | ------ | +| `globalEventHandler` | [`GlobalEventHandler`](../types/GlobalEventHandler.md)\<`TEvents`\> | +| `options`? | [`EmitterOnOptions`](../types/EmitterOnOptions.md) | + +#### Returns + +`Function` + +##### Returns + +`void` + +#### Type Parameters + +| Type Parameter | +| ------ | +| `E` *extends* `string` \| `number` \| `symbol` | + +#### Parameters + +| Parameter | Type | +| ------ | ------ | +| `event` | `E` | +| `handler` | [`EventHandler`](../types/EventHandler.md)\<`EventPayload`\<`TEvents`, `E`\>\> | +| `options`? | [`EmitterOnOptions`](../types/EmitterOnOptions.md) | + +#### Returns + +`Function` + +##### Returns + +`void` + +### once() + +```ts +once: (globalEventHandler, options?) => () => void(event, handler, options?) => () => void; +``` + +#### Parameters + +| Parameter | Type | +| ------ | ------ | +| `globalEventHandler` | [`GlobalEventHandler`](../types/GlobalEventHandler.md)\<`TEvents`\> | +| `options`? | [`EmitterOnceOptions`](../types/EmitterOnceOptions.md) | + +#### Returns + +`Function` + +##### Returns + +`void` + +#### Type Parameters + +| Type Parameter | +| ------ | +| `E` *extends* `string` \| `number` \| `symbol` | + +#### Parameters + +| Parameter | Type | +| ------ | ------ | +| `event` | `E` | +| `handler` | [`EventHandler`](../types/EventHandler.md)\<`EventPayload`\<`TEvents`, `E`\>\> | +| `options`? | [`EmitterOnceOptions`](../types/EmitterOnceOptions.md) | + +#### Returns + +`Function` + +##### Returns + +`void` + +### setOptions() + +```ts +setOptions: (options) => void; +``` + +#### Parameters + +| Parameter | Type | +| ------ | ------ | +| `options` | [`EmitterOptions`](../types/EmitterOptions.md) | + +#### Returns + +`void` diff --git a/docs/api/index.md b/docs/api/index.md new file mode 100644 index 0000000..9e3ea7f --- /dev/null +++ b/docs/api/index.md @@ -0,0 +1,20 @@ +# @kitbag/events + +## Errors + +- [EmitterTimeoutError](errors/EmitterTimeoutError.md) + +## Functions + +- [createEmitter](functions/createEmitter.md) + +## Types + +- [EmitterEvents](types/EmitterEvents.md) +- [EmitterNextOptions](types/EmitterNextOptions.md) +- [EmitterOnceOptions](types/EmitterOnceOptions.md) +- [EmitterOnOptions](types/EmitterOnOptions.md) +- [EmitterOptions](types/EmitterOptions.md) +- [EventHandler](types/EventHandler.md) +- [GlobalEventHandler](types/GlobalEventHandler.md) +- [GlobalEventHandlerResponse](types/GlobalEventHandlerResponse.md) diff --git a/docs/api/typedoc-sidebar.json b/docs/api/typedoc-sidebar.json new file mode 100644 index 0000000..1e07b45 --- /dev/null +++ b/docs/api/typedoc-sidebar.json @@ -0,0 +1,60 @@ +[ + { + "text": "Errors", + "collapsed": true, + "items": [ + { + "text": "EmitterTimeoutError", + "link": "/api/errors/EmitterTimeoutError.md" + } + ] + }, + { + "text": "Functions", + "collapsed": true, + "items": [ + { + "text": "createEmitter", + "link": "/api/functions/createEmitter.md" + } + ] + }, + { + "text": "Types", + "collapsed": true, + "items": [ + { + "text": "EmitterEvents", + "link": "/api/types/EmitterEvents.md" + }, + { + "text": "EmitterNextOptions", + "link": "/api/types/EmitterNextOptions.md" + }, + { + "text": "EmitterOnceOptions", + "link": "/api/types/EmitterOnceOptions.md" + }, + { + "text": "EmitterOnOptions", + "link": "/api/types/EmitterOnOptions.md" + }, + { + "text": "EmitterOptions", + "link": "/api/types/EmitterOptions.md" + }, + { + "text": "EventHandler", + "link": "/api/types/EventHandler.md" + }, + { + "text": "GlobalEventHandler", + "link": "/api/types/GlobalEventHandler.md" + }, + { + "text": "GlobalEventHandlerResponse", + "link": "/api/types/GlobalEventHandlerResponse.md" + } + ] + } +] \ No newline at end of file diff --git a/docs/api/types/EmitterEvents.md b/docs/api/types/EmitterEvents.md new file mode 100644 index 0000000..670e429 --- /dev/null +++ b/docs/api/types/EmitterEvents.md @@ -0,0 +1,5 @@ +# Types: EmitterEvents + +```ts +type EmitterEvents = Record; +``` diff --git a/docs/api/types/EmitterNextOptions.md b/docs/api/types/EmitterNextOptions.md new file mode 100644 index 0000000..cb14b1b --- /dev/null +++ b/docs/api/types/EmitterNextOptions.md @@ -0,0 +1,13 @@ +# Types: EmitterNextOptions + +```ts +type EmitterNextOptions = object; +``` + +## Type declaration + +### timeout? + +```ts +optional timeout: number; +``` diff --git a/docs/api/types/EmitterOnOptions.md b/docs/api/types/EmitterOnOptions.md new file mode 100644 index 0000000..20aa5ee --- /dev/null +++ b/docs/api/types/EmitterOnOptions.md @@ -0,0 +1,13 @@ +# Types: EmitterOnOptions + +```ts +type EmitterOnOptions = object; +``` + +## Type declaration + +### signal? + +```ts +optional signal: AbortSignal; +``` diff --git a/docs/api/types/EmitterOnceOptions.md b/docs/api/types/EmitterOnceOptions.md new file mode 100644 index 0000000..f715fde --- /dev/null +++ b/docs/api/types/EmitterOnceOptions.md @@ -0,0 +1,13 @@ +# Types: EmitterOnceOptions + +```ts +type EmitterOnceOptions = object; +``` + +## Type declaration + +### signal? + +```ts +optional signal: AbortSignal; +``` diff --git a/docs/api/types/EmitterOptions.md b/docs/api/types/EmitterOptions.md new file mode 100644 index 0000000..c3e06d8 --- /dev/null +++ b/docs/api/types/EmitterOptions.md @@ -0,0 +1,13 @@ +# Types: EmitterOptions + +```ts +type EmitterOptions = object; +``` + +## Type declaration + +### broadcastChannel? + +```ts +optional broadcastChannel: string; +``` diff --git a/docs/api/types/EventHandler.md b/docs/api/types/EventHandler.md new file mode 100644 index 0000000..25ad16a --- /dev/null +++ b/docs/api/types/EventHandler.md @@ -0,0 +1,21 @@ +# Types: EventHandler()\ + +```ts +type EventHandler = (...payload) => void; +``` + +## Type Parameters + +| Type Parameter | Default type | +| ------ | ------ | +| `T` | `any` | + +## Parameters + +| Parameter | Type | +| ------ | ------ | +| ...`payload` | `T`[] | + +## Returns + +`void` diff --git a/docs/api/types/GlobalEventHandler.md b/docs/api/types/GlobalEventHandler.md new file mode 100644 index 0000000..983fe9a --- /dev/null +++ b/docs/api/types/GlobalEventHandler.md @@ -0,0 +1,21 @@ +# Types: GlobalEventHandler()\ + +```ts +type GlobalEventHandler = (event) => void; +``` + +## Type Parameters + +| Type Parameter | +| ------ | +| `T` *extends* [`EmitterEvents`](EmitterEvents.md) | + +## Parameters + +| Parameter | Type | +| ------ | ------ | +| `event` | [`GlobalEventHandlerResponse`](GlobalEventHandlerResponse.md)\<`T`\> | + +## Returns + +`void` diff --git a/docs/api/types/GlobalEventHandlerResponse.md b/docs/api/types/GlobalEventHandlerResponse.md new file mode 100644 index 0000000..180fdd5 --- /dev/null +++ b/docs/api/types/GlobalEventHandlerResponse.md @@ -0,0 +1,11 @@ +# Types: GlobalEventHandlerResponse\ + +```ts +type GlobalEventHandlerResponse = { [K in keyof T]: { kind: K; payload: T[K] } }[keyof T]; +``` + +## Type Parameters + +| Type Parameter | +| ------ | +| `T` *extends* [`EmitterEvents`](EmitterEvents.md) | diff --git a/package-lock.json b/package-lock.json index ca3eeb6..ff8c4ac 100644 --- a/package-lock.json +++ b/package-lock.json @@ -8,6 +8,9 @@ "name": "@kitbag/events", "version": "0.2.0", "devDependencies": { + "typedoc": "^0.27.7", + "typedoc-plugin-markdown": "^4.4.2", + "typedoc-vitepress-theme": "^1.1.2", "typescript": "^5.0.2", "vite": "^6.1.0", "vite-plugin-dts": "^4.5.0", @@ -783,6 +786,40 @@ "node": ">=18" } }, + "node_modules/@gerrit0/mini-shiki": { + "version": "1.27.2", + "resolved": "https://registry.npmjs.org/@gerrit0/mini-shiki/-/mini-shiki-1.27.2.tgz", + "integrity": "sha512-GeWyHz8ao2gBiUW4OJnQDxXQnFgZQwwQk05t/CVVgNBN7/rK8XZ7xY6YhLVv9tH3VppWWmr9DCl3MwemB/i+Og==", + "dev": true, + "license": "MIT", + "dependencies": { + "@shikijs/engine-oniguruma": "^1.27.2", + "@shikijs/types": "^1.27.2", + "@shikijs/vscode-textmate": "^10.0.1" + } + }, + "node_modules/@gerrit0/mini-shiki/node_modules/@shikijs/engine-oniguruma": { + "version": "1.29.2", + "resolved": "https://registry.npmjs.org/@shikijs/engine-oniguruma/-/engine-oniguruma-1.29.2.tgz", + "integrity": "sha512-7iiOx3SG8+g1MnlzZVDYiaeHe7Ez2Kf2HrJzdmGwkRisT7r4rak0e655AcM/tF9JG/kg5fMNYlLLKglbN7gBqA==", + "dev": true, + "license": "MIT", + "dependencies": { + "@shikijs/types": "1.29.2", + "@shikijs/vscode-textmate": "^10.0.1" + } + }, + "node_modules/@gerrit0/mini-shiki/node_modules/@shikijs/types": { + "version": "1.29.2", + "resolved": "https://registry.npmjs.org/@shikijs/types/-/types-1.29.2.tgz", + "integrity": "sha512-VJjK0eIijTZf0QSTODEXCqinjBn0joAHQ+aPSBzrv4O2d/QSbsMw+ZeSRx03kV34Hy7NzUvV/7NqfYGRLrASmw==", + "dev": true, + "license": "MIT", + "dependencies": { + "@shikijs/vscode-textmate": "^10.0.1", + "@types/hast": "^3.0.4" + } + }, "node_modules/@iconify-json/simple-icons": { "version": "1.2.24", "resolved": "https://registry.npmjs.org/@iconify-json/simple-icons/-/simple-icons-1.2.24.tgz", @@ -2496,6 +2533,16 @@ "integrity": "sha512-Y+60/zizpJ3HRH8DCss+q95yr6145JXZo46OTpFvDZWLfRCE4qChOyk1b26nMaNpfHHgxagk9dXT5OP0Tfe+dQ==", "dev": true }, + "node_modules/linkify-it": { + "version": "5.0.0", + "resolved": "https://registry.npmjs.org/linkify-it/-/linkify-it-5.0.0.tgz", + "integrity": "sha512-5aHCbzQRADcdP+ATqnDuhhJ/MRIqDkZX5pyjFHRRysS8vZ5AbqGEoFIb6pYHPZ+L/OC2Lc+xT8uHVVR5CAK/wQ==", + "dev": true, + "license": "MIT", + "dependencies": { + "uc.micro": "^2.0.0" + } + }, "node_modules/local-pkg": { "version": "0.5.1", "resolved": "https://registry.npmjs.org/local-pkg/-/local-pkg-0.5.1.tgz", @@ -2540,6 +2587,13 @@ "node": ">=10" } }, + "node_modules/lunr": { + "version": "2.3.9", + "resolved": "https://registry.npmjs.org/lunr/-/lunr-2.3.9.tgz", + "integrity": "sha512-zTU3DaZaF3Rt9rhN3uBMGQD3dD2/vFQqnvZCDv4dl5iOzq2IZQqTxu90r4E5J+nP70J3ilqVCrbho2eWaeW8Ow==", + "dev": true, + "license": "MIT" + }, "node_modules/magic-string": { "version": "0.30.17", "resolved": "https://registry.npmjs.org/magic-string/-/magic-string-0.30.17.tgz", @@ -2556,6 +2610,31 @@ "integrity": "sha512-1I+1qpDt4idfgLQG+BNWmrqku+7/2bi5nLf4YwF8y8zXvmfiTBY3PV3ZibfrjBueCByROpuBjLLFCajqkgYoLQ==", "dev": true }, + "node_modules/markdown-it": { + "version": "14.1.0", + "resolved": "https://registry.npmjs.org/markdown-it/-/markdown-it-14.1.0.tgz", + "integrity": "sha512-a54IwgWPaeBCAAsv13YgmALOF1elABB08FxO9i+r4VFk5Vl4pKokRPeX8u5TCgSsPi6ec1otfLjdOpVcgbpshg==", + "dev": true, + "license": "MIT", + "dependencies": { + "argparse": "^2.0.1", + "entities": "^4.4.0", + "linkify-it": "^5.0.0", + "mdurl": "^2.0.0", + "punycode.js": "^2.3.1", + "uc.micro": "^2.1.0" + }, + "bin": { + "markdown-it": "bin/markdown-it.mjs" + } + }, + "node_modules/markdown-it/node_modules/argparse": { + "version": "2.0.1", + "resolved": "https://registry.npmjs.org/argparse/-/argparse-2.0.1.tgz", + "integrity": "sha512-8+9WqebbFzpX9OR+Wa6O29asIogeRMzcGtAINdpMHHyAg10f05aSFVBbcEqGf/PXw1EjAZ+q2/bEBg3DvurK3Q==", + "dev": true, + "license": "Python-2.0" + }, "node_modules/mdast-util-to-hast": { "version": "13.2.0", "resolved": "https://registry.npmjs.org/mdast-util-to-hast/-/mdast-util-to-hast-13.2.0.tgz", @@ -2578,6 +2657,13 @@ "url": "https://opencollective.com/unified" } }, + "node_modules/mdurl": { + "version": "2.0.0", + "resolved": "https://registry.npmjs.org/mdurl/-/mdurl-2.0.0.tgz", + "integrity": "sha512-Lf+9+2r+Tdp5wXDXC4PcIBjTDtq4UKjCPMQhKIuzpJNW0b96kVqSwW0bT7FhRSfmAiFYgP+SCRvdrDozfh0U5w==", + "dev": true, + "license": "MIT" + }, "node_modules/micromark-util-character": { "version": "2.1.1", "resolved": "https://registry.npmjs.org/micromark-util-character/-/micromark-util-character-2.1.1.tgz", @@ -2888,6 +2974,16 @@ "node": ">=6" } }, + "node_modules/punycode.js": { + "version": "2.3.1", + "resolved": "https://registry.npmjs.org/punycode.js/-/punycode.js-2.3.1.tgz", + "integrity": "sha512-uxFIHU0YlHYhDQtV4R9J6a52SLx28BCjT+4ieh7IGbgwVJWO+km431c4yRlREUAsAmt/uMjQUyQHNEPf0M39CA==", + "dev": true, + "license": "MIT", + "engines": { + "node": ">=6" + } + }, "node_modules/regex": { "version": "6.0.1", "resolved": "https://registry.npmjs.org/regex/-/regex-6.0.1.tgz", @@ -3244,6 +3340,78 @@ "url": "https://github.com/sponsors/wooorm" } }, + "node_modules/typedoc": { + "version": "0.27.7", + "resolved": "https://registry.npmjs.org/typedoc/-/typedoc-0.27.7.tgz", + "integrity": "sha512-K/JaUPX18+61W3VXek1cWC5gwmuLvYTOXJzBvD9W7jFvbPnefRnCHQCEPw7MSNrP/Hj7JJrhZtDDLKdcYm6ucg==", + "dev": true, + "license": "Apache-2.0", + "dependencies": { + "@gerrit0/mini-shiki": "^1.24.0", + "lunr": "^2.3.9", + "markdown-it": "^14.1.0", + "minimatch": "^9.0.5", + "yaml": "^2.6.1" + }, + "bin": { + "typedoc": "bin/typedoc" + }, + "engines": { + "node": ">= 18" + }, + "peerDependencies": { + "typescript": "5.0.x || 5.1.x || 5.2.x || 5.3.x || 5.4.x || 5.5.x || 5.6.x || 5.7.x" + } + }, + "node_modules/typedoc-plugin-markdown": { + "version": "4.4.2", + "resolved": "https://registry.npmjs.org/typedoc-plugin-markdown/-/typedoc-plugin-markdown-4.4.2.tgz", + "integrity": "sha512-kJVkU2Wd+AXQpyL6DlYXXRrfNrHrEIUgiABWH8Z+2Lz5Sq6an4dQ/hfvP75bbokjNDUskOdFlEEm/0fSVyC7eg==", + "dev": true, + "license": "MIT", + "engines": { + "node": ">= 18" + }, + "peerDependencies": { + "typedoc": "0.27.x" + } + }, + "node_modules/typedoc-vitepress-theme": { + "version": "1.1.2", + "resolved": "https://registry.npmjs.org/typedoc-vitepress-theme/-/typedoc-vitepress-theme-1.1.2.tgz", + "integrity": "sha512-hQvCZRr5uKDqY1bRuY1+eNTNn6d4TE4OP5pnw65Y7WGgajkJW9X1/lVJK2UJpcwCmwkdjw1QIO49H9JQlxWhhw==", + "dev": true, + "license": "MIT", + "peerDependencies": { + "typedoc-plugin-markdown": ">=4.4.0" + } + }, + "node_modules/typedoc/node_modules/brace-expansion": { + "version": "2.0.1", + "resolved": "https://registry.npmjs.org/brace-expansion/-/brace-expansion-2.0.1.tgz", + "integrity": "sha512-XnAIvQ8eM+kC6aULx6wuQiwVsnzsi9d3WxzV3FpWTGA19F621kwdbsAcFKXgKUHZWsy+mY6iL1sHTxWEFCytDA==", + "dev": true, + "license": "MIT", + "dependencies": { + "balanced-match": "^1.0.0" + } + }, + "node_modules/typedoc/node_modules/minimatch": { + "version": "9.0.5", + "resolved": "https://registry.npmjs.org/minimatch/-/minimatch-9.0.5.tgz", + "integrity": "sha512-G6T0ZX48xgozx7587koeX9Ys2NYy6Gmv//P89sEte9V9whIapMNF4idKxnW2QtCcLiTWlb/wfCabAtAFWhhBow==", + "dev": true, + "license": "ISC", + "dependencies": { + "brace-expansion": "^2.0.1" + }, + "engines": { + "node": ">=16 || 14 >=14.17" + }, + "funding": { + "url": "https://github.com/sponsors/isaacs" + } + }, "node_modules/typescript": { "version": "5.7.2", "resolved": "https://registry.npmjs.org/typescript/-/typescript-5.7.2.tgz", @@ -3258,6 +3426,13 @@ "node": ">=14.17" } }, + "node_modules/uc.micro": { + "version": "2.1.0", + "resolved": "https://registry.npmjs.org/uc.micro/-/uc.micro-2.1.0.tgz", + "integrity": "sha512-ARDJmphmdvUk6Glw7y9DQ2bFkKBHwQHLi2lsaH6PPmz/Ka9sFOBsBluozhDltWmnv9u/cF6Rt87znRTPV+yp/A==", + "dev": true, + "license": "MIT" + }, "node_modules/ufo": { "version": "1.5.4", "resolved": "https://registry.npmjs.org/ufo/-/ufo-1.5.4.tgz", @@ -4207,6 +4382,19 @@ "dev": true, "license": "ISC" }, + "node_modules/yaml": { + "version": "2.7.0", + "resolved": "https://registry.npmjs.org/yaml/-/yaml-2.7.0.tgz", + "integrity": "sha512-+hSoy/QHluxmC9kCIJyL/uyFmLmc+e5CFR5Wa+bpIhIj85LVb9ZH2nVnqrHoSvKogwODv0ClqZkmiSSaIH5LTA==", + "dev": true, + "license": "ISC", + "bin": { + "yaml": "bin.mjs" + }, + "engines": { + "node": ">= 14" + } + }, "node_modules/zwitch": { "version": "2.0.4", "resolved": "https://registry.npmjs.org/zwitch/-/zwitch-2.0.4.tgz", @@ -4630,6 +4818,39 @@ "dev": true, "optional": true }, + "@gerrit0/mini-shiki": { + "version": "1.27.2", + "resolved": "https://registry.npmjs.org/@gerrit0/mini-shiki/-/mini-shiki-1.27.2.tgz", + "integrity": "sha512-GeWyHz8ao2gBiUW4OJnQDxXQnFgZQwwQk05t/CVVgNBN7/rK8XZ7xY6YhLVv9tH3VppWWmr9DCl3MwemB/i+Og==", + "dev": true, + "requires": { + "@shikijs/engine-oniguruma": "^1.27.2", + "@shikijs/types": "^1.27.2", + "@shikijs/vscode-textmate": "^10.0.1" + }, + "dependencies": { + "@shikijs/engine-oniguruma": { + "version": "1.29.2", + "resolved": "https://registry.npmjs.org/@shikijs/engine-oniguruma/-/engine-oniguruma-1.29.2.tgz", + "integrity": "sha512-7iiOx3SG8+g1MnlzZVDYiaeHe7Ez2Kf2HrJzdmGwkRisT7r4rak0e655AcM/tF9JG/kg5fMNYlLLKglbN7gBqA==", + "dev": true, + "requires": { + "@shikijs/types": "1.29.2", + "@shikijs/vscode-textmate": "^10.0.1" + } + }, + "@shikijs/types": { + "version": "1.29.2", + "resolved": "https://registry.npmjs.org/@shikijs/types/-/types-1.29.2.tgz", + "integrity": "sha512-VJjK0eIijTZf0QSTODEXCqinjBn0joAHQ+aPSBzrv4O2d/QSbsMw+ZeSRx03kV34Hy7NzUvV/7NqfYGRLrASmw==", + "dev": true, + "requires": { + "@shikijs/vscode-textmate": "^10.0.1", + "@types/hast": "^3.0.4" + } + } + } + }, "@iconify-json/simple-icons": { "version": "1.2.24", "resolved": "https://registry.npmjs.org/@iconify-json/simple-icons/-/simple-icons-1.2.24.tgz", @@ -5812,6 +6033,15 @@ "integrity": "sha512-Y+60/zizpJ3HRH8DCss+q95yr6145JXZo46OTpFvDZWLfRCE4qChOyk1b26nMaNpfHHgxagk9dXT5OP0Tfe+dQ==", "dev": true }, + "linkify-it": { + "version": "5.0.0", + "resolved": "https://registry.npmjs.org/linkify-it/-/linkify-it-5.0.0.tgz", + "integrity": "sha512-5aHCbzQRADcdP+ATqnDuhhJ/MRIqDkZX5pyjFHRRysS8vZ5AbqGEoFIb6pYHPZ+L/OC2Lc+xT8uHVVR5CAK/wQ==", + "dev": true, + "requires": { + "uc.micro": "^2.0.0" + } + }, "local-pkg": { "version": "0.5.1", "resolved": "https://registry.npmjs.org/local-pkg/-/local-pkg-0.5.1.tgz", @@ -5843,6 +6073,12 @@ "yallist": "^4.0.0" } }, + "lunr": { + "version": "2.3.9", + "resolved": "https://registry.npmjs.org/lunr/-/lunr-2.3.9.tgz", + "integrity": "sha512-zTU3DaZaF3Rt9rhN3uBMGQD3dD2/vFQqnvZCDv4dl5iOzq2IZQqTxu90r4E5J+nP70J3ilqVCrbho2eWaeW8Ow==", + "dev": true + }, "magic-string": { "version": "0.30.17", "resolved": "https://registry.npmjs.org/magic-string/-/magic-string-0.30.17.tgz", @@ -5858,6 +6094,28 @@ "integrity": "sha512-1I+1qpDt4idfgLQG+BNWmrqku+7/2bi5nLf4YwF8y8zXvmfiTBY3PV3ZibfrjBueCByROpuBjLLFCajqkgYoLQ==", "dev": true }, + "markdown-it": { + "version": "14.1.0", + "resolved": "https://registry.npmjs.org/markdown-it/-/markdown-it-14.1.0.tgz", + "integrity": "sha512-a54IwgWPaeBCAAsv13YgmALOF1elABB08FxO9i+r4VFk5Vl4pKokRPeX8u5TCgSsPi6ec1otfLjdOpVcgbpshg==", + "dev": true, + "requires": { + "argparse": "^2.0.1", + "entities": "^4.4.0", + "linkify-it": "^5.0.0", + "mdurl": "^2.0.0", + "punycode.js": "^2.3.1", + "uc.micro": "^2.1.0" + }, + "dependencies": { + "argparse": { + "version": "2.0.1", + "resolved": "https://registry.npmjs.org/argparse/-/argparse-2.0.1.tgz", + "integrity": "sha512-8+9WqebbFzpX9OR+Wa6O29asIogeRMzcGtAINdpMHHyAg10f05aSFVBbcEqGf/PXw1EjAZ+q2/bEBg3DvurK3Q==", + "dev": true + } + } + }, "mdast-util-to-hast": { "version": "13.2.0", "resolved": "https://registry.npmjs.org/mdast-util-to-hast/-/mdast-util-to-hast-13.2.0.tgz", @@ -5875,6 +6133,12 @@ "vfile": "^6.0.0" } }, + "mdurl": { + "version": "2.0.0", + "resolved": "https://registry.npmjs.org/mdurl/-/mdurl-2.0.0.tgz", + "integrity": "sha512-Lf+9+2r+Tdp5wXDXC4PcIBjTDtq4UKjCPMQhKIuzpJNW0b96kVqSwW0bT7FhRSfmAiFYgP+SCRvdrDozfh0U5w==", + "dev": true + }, "micromark-util-character": { "version": "2.1.1", "resolved": "https://registry.npmjs.org/micromark-util-character/-/micromark-util-character-2.1.1.tgz", @@ -6058,6 +6322,12 @@ "integrity": "sha512-vYt7UD1U9Wg6138shLtLOvdAu+8DsC/ilFtEVHcH+wydcSpNE20AfSOduf6MkRFahL5FY7X1oU7nKVZFtfq8Fg==", "dev": true }, + "punycode.js": { + "version": "2.3.1", + "resolved": "https://registry.npmjs.org/punycode.js/-/punycode.js-2.3.1.tgz", + "integrity": "sha512-uxFIHU0YlHYhDQtV4R9J6a52SLx28BCjT+4ieh7IGbgwVJWO+km431c4yRlREUAsAmt/uMjQUyQHNEPf0M39CA==", + "dev": true + }, "regex": { "version": "6.0.1", "resolved": "https://registry.npmjs.org/regex/-/regex-6.0.1.tgz", @@ -6302,12 +6572,65 @@ "integrity": "sha512-kRj8B+YHZCc9kQYdWfJB2/oUl9rA99qbowYYBtr4ui4mZyAQ2JpvVBd/6U2YloATfqBhBTSMhTpgBHtU0Mf3Rg==", "dev": true }, + "typedoc": { + "version": "0.27.7", + "resolved": "https://registry.npmjs.org/typedoc/-/typedoc-0.27.7.tgz", + "integrity": "sha512-K/JaUPX18+61W3VXek1cWC5gwmuLvYTOXJzBvD9W7jFvbPnefRnCHQCEPw7MSNrP/Hj7JJrhZtDDLKdcYm6ucg==", + "dev": true, + "requires": { + "@gerrit0/mini-shiki": "^1.24.0", + "lunr": "^2.3.9", + "markdown-it": "^14.1.0", + "minimatch": "^9.0.5", + "yaml": "^2.6.1" + }, + "dependencies": { + "brace-expansion": { + "version": "2.0.1", + "resolved": "https://registry.npmjs.org/brace-expansion/-/brace-expansion-2.0.1.tgz", + "integrity": "sha512-XnAIvQ8eM+kC6aULx6wuQiwVsnzsi9d3WxzV3FpWTGA19F621kwdbsAcFKXgKUHZWsy+mY6iL1sHTxWEFCytDA==", + "dev": true, + "requires": { + "balanced-match": "^1.0.0" + } + }, + "minimatch": { + "version": "9.0.5", + "resolved": "https://registry.npmjs.org/minimatch/-/minimatch-9.0.5.tgz", + "integrity": "sha512-G6T0ZX48xgozx7587koeX9Ys2NYy6Gmv//P89sEte9V9whIapMNF4idKxnW2QtCcLiTWlb/wfCabAtAFWhhBow==", + "dev": true, + "requires": { + "brace-expansion": "^2.0.1" + } + } + } + }, + "typedoc-plugin-markdown": { + "version": "4.4.2", + "resolved": "https://registry.npmjs.org/typedoc-plugin-markdown/-/typedoc-plugin-markdown-4.4.2.tgz", + "integrity": "sha512-kJVkU2Wd+AXQpyL6DlYXXRrfNrHrEIUgiABWH8Z+2Lz5Sq6an4dQ/hfvP75bbokjNDUskOdFlEEm/0fSVyC7eg==", + "dev": true, + "requires": {} + }, + "typedoc-vitepress-theme": { + "version": "1.1.2", + "resolved": "https://registry.npmjs.org/typedoc-vitepress-theme/-/typedoc-vitepress-theme-1.1.2.tgz", + "integrity": "sha512-hQvCZRr5uKDqY1bRuY1+eNTNn6d4TE4OP5pnw65Y7WGgajkJW9X1/lVJK2UJpcwCmwkdjw1QIO49H9JQlxWhhw==", + "dev": true, + "requires": {} + }, "typescript": { "version": "5.7.2", "resolved": "https://registry.npmjs.org/typescript/-/typescript-5.7.2.tgz", "integrity": "sha512-i5t66RHxDvVN40HfDd1PsEThGNnlMCMT3jMUuoh9/0TaqWevNontacunWyN02LA9/fIbEWlcHZcgTKb9QoaLfg==", "dev": true }, + "uc.micro": { + "version": "2.1.0", + "resolved": "https://registry.npmjs.org/uc.micro/-/uc.micro-2.1.0.tgz", + "integrity": "sha512-ARDJmphmdvUk6Glw7y9DQ2bFkKBHwQHLi2lsaH6PPmz/Ka9sFOBsBluozhDltWmnv9u/cF6Rt87znRTPV+yp/A==", + "dev": true + }, "ufo": { "version": "1.5.4", "resolved": "https://registry.npmjs.org/ufo/-/ufo-1.5.4.tgz", @@ -6764,6 +7087,12 @@ "integrity": "sha512-3wdGidZyq5PB084XLES5TpOSRA3wjXAlIWMhum2kRcv/41Sn2emQ0dycQW4uZXLejwKvg6EsvbdlVL+FYEct7A==", "dev": true }, + "yaml": { + "version": "2.7.0", + "resolved": "https://registry.npmjs.org/yaml/-/yaml-2.7.0.tgz", + "integrity": "sha512-+hSoy/QHluxmC9kCIJyL/uyFmLmc+e5CFR5Wa+bpIhIj85LVb9ZH2nVnqrHoSvKogwODv0ClqZkmiSSaIH5LTA==", + "dev": true + }, "zwitch": { "version": "2.0.4", "resolved": "https://registry.npmjs.org/zwitch/-/zwitch-2.0.4.tgz", diff --git a/package.json b/package.json index fa66384..9d384c2 100644 --- a/package.json +++ b/package.json @@ -12,7 +12,8 @@ "types": "tsc --noEmit", "docs:dev": "vitepress dev docs", "docs:build": "vitepress build docs", - "docs:preview": "vitepress preview docs" + "docs:preview": "vitepress preview docs", + "docs:generate": "vite build && typedoc && sleep 5 && node ./scripts/api.js" }, "type": "module", "files": [ @@ -28,6 +29,9 @@ } }, "devDependencies": { + "typedoc": "^0.27.7", + "typedoc-plugin-markdown": "^4.4.2", + "typedoc-vitepress-theme": "^1.1.2", "typescript": "^5.0.2", "vite": "^6.1.0", "vite-plugin-dts": "^4.5.0", diff --git a/scripts/api.js b/scripts/api.js new file mode 100644 index 0000000..b03cafc --- /dev/null +++ b/scripts/api.js @@ -0,0 +1,111 @@ +import path from 'path'; +import fs from 'fs/promises'; + +async function renameTypeAliasesFolderToTypes() { + try { + const oldPath = path.join(process.cwd(), 'docs', 'api', 'type-aliases'); + const newPath = path.join(process.cwd(), 'docs', 'api', 'types'); + + // Check if old directory exists + await fs.access(oldPath); + + // Rename the directory + await fs.rename(oldPath, newPath); + + console.log('Successfully renamed type-aliases folder to types'); + } catch (error) { + if (error.code === 'ENOENT') { + console.error('Error: The type-aliases directory does not exist'); + } else { + console.error('Error renaming folder:', error); + } + process.exit(1); + } +} + +async function updateReferences(searchString, replaceString) { + try { + const apiDir = path.join(process.cwd(), 'docs', 'api'); + const entries = await fs.readdir(apiDir, { withFileTypes: true, recursive: true }); + + for (const entry of entries) { + if (entry.isFile() && (entry.name.endsWith('.md') || entry.name.endsWith('.json'))) { + const fullPath = path.join(entry.path || '', entry.name); + const content = await fs.readFile(fullPath, 'utf8'); + const updatedContent = content.replace(new RegExp(searchString, 'g'), replaceString); + + if (content !== updatedContent) { + await fs.writeFile(fullPath, updatedContent, 'utf8'); + console.log(`Updated references in: ${fullPath}`); + } + } + } + console.log(`Successfully updated all references from ${searchString} to ${replaceString}`); + } catch (error) { + console.error('Error updating references:', error); + throw error; + } +} + +async function organizeFilesByGroup() { + try { + const apiDir = path.join(process.cwd(), 'docs', 'api'); + const entries = await fs.readdir(apiDir, { withFileTypes: true, recursive: true }); + const changes = new Map(); // Track old paths to new paths + + // First pass: collect all the moves we need to make + for (const entry of entries) { + if (entry.isFile() && entry.name.endsWith('.md')) { + const fullPath = path.join(entry.path || '', entry.name); + const content = await fs.readFile(fullPath, 'utf8'); + + // Extract group from H1 heading + const match = content.match(/^# ([^:]+):/m); + if (match) { + const group = match[1].trim(); + const folderName = group.toLowerCase().replace(/\s+/g, '-'); + const targetDir = path.join(apiDir, folderName); + + // Create directory if it doesn't exist + try { + await fs.access(targetDir); + } catch { + await fs.mkdir(targetDir); + console.log(`Created new directory: ${targetDir}`); + } + + // Check if file needs to be moved + const currentDir = path.dirname(fullPath); + if (currentDir !== targetDir) { + const oldPath = path.relative(apiDir, fullPath); + const newPath = path.join(folderName, entry.name); + changes.set(oldPath, newPath); + } + } + } + } + + // Second pass: perform the moves + for (const [oldPath, newPath] of changes) { + const sourcePath = path.join(apiDir, oldPath); + const targetPath = path.join(apiDir, newPath); + await fs.rename(sourcePath, targetPath); + console.log(`Moved ${oldPath} to ${newPath}`); + } + + // Third pass: update all references for each move + for (const [oldPath, newPath] of changes) { + await updateReferences(oldPath, newPath); + } + + console.log('Successfully organized files by their groups and updated all references'); + } catch (error) { + console.error('Error organizing files:', error); + throw error; + } +} + +await renameTypeAliasesFolderToTypes(); +await updateReferences('type-aliases', 'types'); +await updateReferences('Type Aliases', 'Types'); +await organizeFilesByGroup(); \ No newline at end of file diff --git a/src/errors.ts b/src/errors.ts index 2a77b21..98fc3de 100644 --- a/src/errors.ts +++ b/src/errors.ts @@ -1,3 +1,7 @@ +/** + * An error thrown when a timeout occurs while waiting for an event to be emitted. + * @group Errors + */ export class EmitterTimeoutError extends Error { constructor(event: string, timeout: number) { super(`Timeout waiting for ${event} event after ${timeout}ms`) diff --git a/typedoc.mjs b/typedoc.mjs new file mode 100644 index 0000000..630997e --- /dev/null +++ b/typedoc.mjs @@ -0,0 +1,31 @@ +export default{ + $schema: "https://typedoc.org/schema.json", + entryPoints: ["./dist/kitbag-events.d.ts"], + plugin: [ + "typedoc-plugin-markdown", + "typedoc-vitepress-theme", + ], + out: "./docs/api", + docsRoot: "./docs/", + tsconfig: "./typedoc.tsconfig.json", + readme: "none", + parametersFormat: "table", + propertiesFormat: "table", + hideBreadcrumbs: true, + hidePageHeader: true, + hideGroupHeadings: true, + useCodeBlocks: true, + disableSources: true, + groupOrder: [ + "Types", + "Utilities", + "*", + "Errors", + ], + sidebar: { + pretty: true, + }, + pageTitleTemplates: { + member: (args) => `${args.group}: ${args.name}`, + } +} diff --git a/typedoc.tsconfig.json b/typedoc.tsconfig.json new file mode 100644 index 0000000..f79da92 --- /dev/null +++ b/typedoc.tsconfig.json @@ -0,0 +1,5 @@ +{ + "extends": "./tsconfig.json", + "include": ["dist/kitbag-events.d.ts"], + "exclude": ["node_modules"] +} \ No newline at end of file From 3c316e027e917aa7e42cbc310f41fbd2488b9a8a Mon Sep 17 00:00:00 2001 From: Craig Harshbarger Date: Sun, 16 Feb 2025 19:39:29 -0600 Subject: [PATCH 2/2] Fix warnings --- docs/api/functions/createEmitter.md | 12 ++++++------ docs/api/index.md | 9 +++++---- docs/api/typedoc-sidebar.json | 24 ++++++++++++++---------- docs/api/types/EventPayload.md | 12 ++++++++++++ src/main.ts | 1 + 5 files changed, 38 insertions(+), 20 deletions(-) create mode 100644 docs/api/types/EventPayload.md diff --git a/docs/api/functions/createEmitter.md b/docs/api/functions/createEmitter.md index e0156f8..9b4a0d6 100644 --- a/docs/api/functions/createEmitter.md +++ b/docs/api/functions/createEmitter.md @@ -46,7 +46,7 @@ emit: (event) => void(event, payload) => void; | Parameter | Type | | ------ | ------ | -| `event` | `undefined` *extends* `EventPayload`\<`TEvents`, `E`\> ? `E` : `never` | +| `event` | `undefined` *extends* [`EventPayload`](../types/EventPayload.md)\<`TEvents`, `E`\> ? `E` : `never` | #### Returns @@ -63,7 +63,7 @@ emit: (event) => void(event, payload) => void; | Parameter | Type | | ------ | ------ | | `event` | `E` | -| `payload` | `EventPayload`\<`TEvents`, `E`\> | +| `payload` | [`EventPayload`](../types/EventPayload.md)\<`TEvents`, `E`\> | #### Returns @@ -100,7 +100,7 @@ next: (options?) => Promise>(event, optio #### Returns -`Promise`\<`EventPayload`\<`TEvents`, `E`\>\> +`Promise`\<[`EventPayload`](../types/EventPayload.md)\<`TEvents`, `E`\>\> ### off() @@ -145,7 +145,7 @@ off: (globalEventHandler) => void(event) => void(event, handler) => void; | Parameter | Type | | ------ | ------ | | `event` | `E` | -| `handler` | [`EventHandler`](../types/EventHandler.md)\<`EventPayload`\<`TEvents`, `E`\>\> | +| `handler` | [`EventHandler`](../types/EventHandler.md)\<[`EventPayload`](../types/EventPayload.md)\<`TEvents`, `E`\>\> | #### Returns @@ -183,7 +183,7 @@ on: (globalEventHandler, options?) => () => void(event, handler, options?) => | Parameter | Type | | ------ | ------ | | `event` | `E` | -| `handler` | [`EventHandler`](../types/EventHandler.md)\<`EventPayload`\<`TEvents`, `E`\>\> | +| `handler` | [`EventHandler`](../types/EventHandler.md)\<[`EventPayload`](../types/EventPayload.md)\<`TEvents`, `E`\>\> | | `options`? | [`EmitterOnOptions`](../types/EmitterOnOptions.md) | #### Returns @@ -226,7 +226,7 @@ once: (globalEventHandler, options?) => () => void(event, handler, options?) | Parameter | Type | | ------ | ------ | | `event` | `E` | -| `handler` | [`EventHandler`](../types/EventHandler.md)\<`EventPayload`\<`TEvents`, `E`\>\> | +| `handler` | [`EventHandler`](../types/EventHandler.md)\<[`EventPayload`](../types/EventPayload.md)\<`TEvents`, `E`\>\> | | `options`? | [`EmitterOnceOptions`](../types/EmitterOnceOptions.md) | #### Returns diff --git a/docs/api/index.md b/docs/api/index.md index 9e3ea7f..9e6be21 100644 --- a/docs/api/index.md +++ b/docs/api/index.md @@ -1,9 +1,5 @@ # @kitbag/events -## Errors - -- [EmitterTimeoutError](errors/EmitterTimeoutError.md) - ## Functions - [createEmitter](functions/createEmitter.md) @@ -16,5 +12,10 @@ - [EmitterOnOptions](types/EmitterOnOptions.md) - [EmitterOptions](types/EmitterOptions.md) - [EventHandler](types/EventHandler.md) +- [EventPayload](types/EventPayload.md) - [GlobalEventHandler](types/GlobalEventHandler.md) - [GlobalEventHandlerResponse](types/GlobalEventHandlerResponse.md) + +## Errors + +- [EmitterTimeoutError](errors/EmitterTimeoutError.md) diff --git a/docs/api/typedoc-sidebar.json b/docs/api/typedoc-sidebar.json index 1e07b45..49a81a4 100644 --- a/docs/api/typedoc-sidebar.json +++ b/docs/api/typedoc-sidebar.json @@ -1,14 +1,4 @@ [ - { - "text": "Errors", - "collapsed": true, - "items": [ - { - "text": "EmitterTimeoutError", - "link": "/api/errors/EmitterTimeoutError.md" - } - ] - }, { "text": "Functions", "collapsed": true, @@ -47,6 +37,10 @@ "text": "EventHandler", "link": "/api/types/EventHandler.md" }, + { + "text": "EventPayload", + "link": "/api/types/EventPayload.md" + }, { "text": "GlobalEventHandler", "link": "/api/types/GlobalEventHandler.md" @@ -56,5 +50,15 @@ "link": "/api/types/GlobalEventHandlerResponse.md" } ] + }, + { + "text": "Errors", + "collapsed": true, + "items": [ + { + "text": "EmitterTimeoutError", + "link": "/api/errors/EmitterTimeoutError.md" + } + ] } ] \ No newline at end of file diff --git a/docs/api/types/EventPayload.md b/docs/api/types/EventPayload.md new file mode 100644 index 0000000..6857578 --- /dev/null +++ b/docs/api/types/EventPayload.md @@ -0,0 +1,12 @@ +# Types: EventPayload\ + +```ts +type EventPayload = TEvents[TEvent]; +``` + +## Type Parameters + +| Type Parameter | +| ------ | +| `TEvents` *extends* [`EmitterEvents`](EmitterEvents.md) | +| `TEvent` *extends* keyof `TEvents` | diff --git a/src/main.ts b/src/main.ts index 294590c..3e7ee85 100644 --- a/src/main.ts +++ b/src/main.ts @@ -1,6 +1,7 @@ export type { EmitterOptions, EmitterEvents, + EventPayload, EventHandler, GlobalEventHandler, EmitterOnOptions,