Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,7 @@ import MemberDescription from '@site/src/components/MemberDescription';

## cacheLife

<GenerationInfo sourceFile="packages/cache/src/use-cache.ts" sourceLine="245" packageName="@commandkit/cache" />
<GenerationInfo sourceFile="packages/cache/src/use-cache.ts" sourceLine="232" packageName="@commandkit/cache" />

Sets the TTL for the current cache operation

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,7 @@ import MemberDescription from '@site/src/components/MemberDescription';

## cacheTag

<GenerationInfo sourceFile="packages/cache/src/use-cache.ts" sourceLine="219" packageName="@commandkit/cache" />
<GenerationInfo sourceFile="packages/cache/src/use-cache.ts" sourceLine="206" packageName="@commandkit/cache" />

Sets a custom identifier for the current cache operation

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,7 @@ import MemberDescription from '@site/src/components/MemberDescription';

## cleanup

<GenerationInfo sourceFile="packages/cache/src/use-cache.ts" sourceLine="302" packageName="@commandkit/cache" />
<GenerationInfo sourceFile="packages/cache/src/use-cache.ts" sourceLine="289" packageName="@commandkit/cache" />

Cleans up stale cache entries.

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,7 @@ import MemberDescription from '@site/src/components/MemberDescription';

## isCachedFunction

<GenerationInfo sourceFile="packages/cache/src/use-cache.ts" sourceLine="294" packageName="@commandkit/cache" />
<GenerationInfo sourceFile="packages/cache/src/use-cache.ts" sourceLine="281" packageName="@commandkit/cache" />

Checks if a function is wrapped with cache functionality

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,7 @@ import MemberDescription from '@site/src/components/MemberDescription';

## revalidateTag

<GenerationInfo sourceFile="packages/cache/src/use-cache.ts" sourceLine="267" packageName="@commandkit/cache" />
<GenerationInfo sourceFile="packages/cache/src/use-cache.ts" sourceLine="254" packageName="@commandkit/cache" />

Marks cache entries for invalidation by their tag. The invalidation only happens when the path is next visited.

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,7 @@ import MemberDescription from '@site/src/components/MemberDescription';

## CacheContext

<GenerationInfo sourceFile="packages/cache/src/use-cache.ts" sourceLine="42" packageName="@commandkit/cache" />
<GenerationInfo sourceFile="packages/cache/src/use-cache.ts" sourceLine="36" packageName="@commandkit/cache" />

Context for managing cache operations within an async scope

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,7 @@ import MemberDescription from '@site/src/components/MemberDescription';

## CacheMetadata

<GenerationInfo sourceFile="packages/cache/src/use-cache.ts" sourceLine="55" packageName="@commandkit/cache" />
<GenerationInfo sourceFile="packages/cache/src/use-cache.ts" sourceLine="49" packageName="@commandkit/cache" />

Configuration options for cache behavior

Expand Down

This file was deleted.

Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,7 @@ import MemberDescription from '@site/src/components/MemberDescription';

## createCommandKitError

<GenerationInfo sourceFile="packages/commandkit/src/utils/error-codes.ts" sourceLine="33" packageName="commandkit" />
<GenerationInfo sourceFile="packages/commandkit/src/utils/error-codes.ts" sourceLine="37" packageName="commandkit" />

Creates a new CommandKit error with the specified code.

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,7 @@ import MemberDescription from '@site/src/components/MemberDescription';

## createElement

<GenerationInfo sourceFile="packages/commandkit/src/components/common/element.ts" sourceLine="99" packageName="commandkit" />
<GenerationInfo sourceFile="packages/commandkit/src/components/common/element.ts" sourceLine="97" packageName="commandkit" />

The createElement function is used to create CommandKit elements.

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,7 @@ import MemberDescription from '@site/src/components/MemberDescription';

## createProxy

<GenerationInfo sourceFile="packages/commandkit/src/utils/utilities.ts" sourceLine="220" packageName="commandkit" />
<GenerationInfo sourceFile="packages/commandkit/src/utils/utilities.ts" sourceLine="189" packageName="commandkit" />

Creates a simple proxy object that mirrors the target object.

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,7 @@ import MemberDescription from '@site/src/components/MemberDescription';

## exitMiddleware

<GenerationInfo sourceFile="packages/commandkit/src/app/middleware/signals.ts" sourceLine="13" packageName="commandkit" />
<GenerationInfo sourceFile="packages/commandkit/src/app/interrupt/signals.ts" sourceLine="14" packageName="commandkit" />

Cancel upcoming middleware execution.
If this is called inside pre-stage middleware, the next run will be the actual command, skipping all other pre-stage middlewares.
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,7 @@ import MemberDescription from '@site/src/components/MemberDescription';

## isCommandKitError

<GenerationInfo sourceFile="packages/commandkit/src/utils/error-codes.ts" sourceLine="46" packageName="commandkit" />
<GenerationInfo sourceFile="packages/commandkit/src/utils/error-codes.ts" sourceLine="50" packageName="commandkit" />

Checks if the given error is a CommandKit error.

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,7 @@ import MemberDescription from '@site/src/components/MemberDescription';

## isErrorType

<GenerationInfo sourceFile="packages/commandkit/src/utils/error-codes.ts" sourceLine="64" packageName="commandkit" />
<GenerationInfo sourceFile="packages/commandkit/src/utils/error-codes.ts" sourceLine="68" packageName="commandkit" />

Checks if the given error is of a specific CommandKit error type.

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,7 @@ import MemberDescription from '@site/src/components/MemberDescription';

## redirect

<GenerationInfo sourceFile="packages/commandkit/src/app/middleware/signals.ts" sourceLine="28" packageName="commandkit" />
<GenerationInfo sourceFile="packages/commandkit/src/app/interrupt/signals.ts" sourceLine="37" packageName="commandkit" />

Stops current command assuming it has been redirected to another command.

Expand Down
17 changes: 16 additions & 1 deletion apps/website/docs/api-reference/commandkit/functions/rethrow.mdx
Original file line number Diff line number Diff line change
Expand Up @@ -13,10 +13,25 @@ import MemberDescription from '@site/src/components/MemberDescription';

## rethrow

<GenerationInfo sourceFile="packages/commandkit/src/app/middleware/signals.ts" sourceLine="21" packageName="commandkit" />
<GenerationInfo sourceFile="packages/commandkit/src/app/interrupt/signals.ts" sourceLine="30" packageName="commandkit" />

Rethrow the error if it is a CommandKit error.



*Example*

```ts
try {
doSomething();
} catch(e) {
// do something

// throw the error if it's a commandkit error
rethrow(e)
}
```

```ts title="Signature"
function rethrow(error: unknown): void
```
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,7 @@ import MemberDescription from '@site/src/components/MemberDescription';

## stopEvents

<GenerationInfo sourceFile="packages/commandkit/src/utils/utilities.ts" sourceLine="192" packageName="commandkit" />
<GenerationInfo sourceFile="packages/commandkit/src/app/interrupt/signals.ts" sourceLine="53" packageName="commandkit" />

Stops event propagation. This function should be called inside an event handler
to prevent further event handling.
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,7 @@ import MemberDescription from '@site/src/components/MemberDescription';

## SimpleProxy

<GenerationInfo sourceFile="packages/commandkit/src/utils/utilities.ts" sourceLine="203" packageName="commandkit" />
<GenerationInfo sourceFile="packages/commandkit/src/utils/utilities.ts" sourceLine="172" packageName="commandkit" />

Represents a simple proxy object that mirrors a target object.

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,7 @@ import MemberDescription from '@site/src/components/MemberDescription';

## CommandKitError

<GenerationInfo sourceFile="packages/commandkit/src/utils/error-codes.ts" sourceLine="26" packageName="commandkit" />
<GenerationInfo sourceFile="packages/commandkit/src/utils/error-codes.ts" sourceLine="30" packageName="commandkit" />

The type for CommandKit errors.

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,7 @@ import MemberDescription from '@site/src/components/MemberDescription';

## I18nPlugin

<GenerationInfo sourceFile="packages/i18n/src/i18n.ts" sourceLine="146" packageName="@commandkit/i18n" />
<GenerationInfo sourceFile="packages/i18n/src/i18n.ts" sourceLine="149" packageName="@commandkit/i18n" />



Expand Down
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
---
title: "GetI18n"
title: "UseI18n"
isDefaultIndex: false
generated: true
---
Expand All @@ -11,9 +11,9 @@ import MemberDescription from '@site/src/components/MemberDescription';
<!-- This file was generated from the CommandKit source. Do not modify. Instead, re-run the "docgen" script -->


## getI18n
## useI18n

<GenerationInfo sourceFile="packages/i18n/src/i18n.ts" sourceLine="136" packageName="@commandkit/i18n" />
<GenerationInfo sourceFile="packages/i18n/src/i18n.ts" sourceLine="137" packageName="@commandkit/i18n" />

Retrieves the i18n instance from the commandkit store.

Expand All @@ -22,17 +22,17 @@ Retrieves the i18n instance from the commandkit store.
*Example*

```ts
import { getI18n } from '@commandkit/i18n';
import { useI18n } from '@commandkit/i18n';
import { commandkit } from 'commandkit';

const i18n = getI18n(commandkit);
const i18n = useI18n(commandkit);

// Use the i18n instance
i18n.t('key');
```

```ts title="Signature"
function getI18n(commandkit: CommandKit): i18n
function useI18n(commandkit?: CommandKit): i18n
```
Parameters

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,7 @@ import MemberDescription from '@site/src/components/MemberDescription';

## CommandLocalizationContext

<GenerationInfo sourceFile="packages/i18n/src/i18n.ts" sourceLine="68" packageName="@commandkit/i18n" />
<GenerationInfo sourceFile="packages/i18n/src/i18n.ts" sourceLine="69" packageName="@commandkit/i18n" />



Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,7 @@ import MemberDescription from '@site/src/components/MemberDescription';

## LocalizationPluginOptions

<GenerationInfo sourceFile="packages/i18n/src/i18n.ts" sourceLine="55" packageName="@commandkit/i18n" />
<GenerationInfo sourceFile="packages/i18n/src/i18n.ts" sourceLine="56" packageName="@commandkit/i18n" />

Options for the localization plugin.
This interface defines the options that can be passed to the localization plugin.
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,7 @@ import MemberDescription from '@site/src/components/MemberDescription';

## DynamicLocalizationModule

<GenerationInfo sourceFile="packages/i18n/src/i18n.ts" sourceLine="48" packageName="@commandkit/i18n" />
<GenerationInfo sourceFile="packages/i18n/src/i18n.ts" sourceLine="49" packageName="@commandkit/i18n" />

Represents a dynamic localization module that can be used with the i18next plugin.

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,7 @@ import MemberDescription from '@site/src/components/MemberDescription';

## LocalizationModule

<GenerationInfo sourceFile="packages/i18n/src/i18n.ts" sourceLine="40" packageName="@commandkit/i18n" />
<GenerationInfo sourceFile="packages/i18n/src/i18n.ts" sourceLine="41" packageName="@commandkit/i18n" />

Represents a localization module that can be used with the i18next plugin.

Expand Down
6 changes: 3 additions & 3 deletions packages/i18n/src/hooks.ts
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
import type { Locale } from 'discord.js';
import { getI18n, type CommandLocalizationContext } from './i18n';
import { useI18n, type CommandLocalizationContext } from './i18n';
import {
useEnvironment,
eventWorkerContext,
Expand Down Expand Up @@ -29,7 +29,7 @@ export function locale(locale?: Locale): CommandLocalizationContext {

const commandkit = context.commandkit;

const i18n = getI18n(commandkit);
const i18n = useI18n(commandkit);
const detectedLocale: Locale = locale || commandkit.config.defaultLocale;

return {
Expand Down Expand Up @@ -64,5 +64,5 @@ export function fetchT(
ns?: string | null,
keyPrefix?: string,
): TFunction {
return locale().i18n.getFixedT(lng, ns, keyPrefix);
return useI18n().getFixedT(lng, ns, keyPrefix);
}
9 changes: 6 additions & 3 deletions packages/i18n/src/i18n.ts
Original file line number Diff line number Diff line change
Expand Up @@ -18,6 +18,7 @@ import CommandKit, {
PreparedAppCommandExecution,
CommandBuilderLike,
CommandKitHMREvent,
getCommandKit,
} from 'commandkit';
import FsBackend from 'i18next-fs-backend';
import { basename, extname, join } from 'path';
Expand Down Expand Up @@ -124,16 +125,18 @@ NativeContext.prototype.locale = function (locale?: Locale) {
* @throws Error if the i18n instance is not found in the store.
* @example
* ```ts
* import { getI18n } from '@commandkit/i18n';
* import { useI18n } from '@commandkit/i18n';
* import { commandkit } from 'commandkit';
*
* const i18n = getI18n(commandkit);
* const i18n = useI18n(commandkit);
*
* // Use the i18n instance
* i18n.t('key');
* ```
*/
export function getI18n(commandkit: CommandKit): i18n {
export function useI18n(commandkit?: CommandKit): i18n {
commandkit ??= getCommandKit(true);

const i18n = commandkit.store.get('i18n:plugin:instance') as i18n;

if (!i18n) {
Expand Down
Loading