Skip to content

Commit

Permalink
docs: fix tsdoc annotations
Browse files Browse the repository at this point in the history
  • Loading branch information
cyberglot committed Oct 10, 2024
1 parent f79de60 commit f1d0672
Show file tree
Hide file tree
Showing 16 changed files with 136 additions and 157 deletions.
2 changes: 1 addition & 1 deletion packages/client-react-hooks/src/logging.ts
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,6 @@ import debug from "debug";

/**
* `Log` is a debug logger that can be used to log messages to the console.
* @param message: string
* @param message - string
*/
export const Log = debug("nillion:react-hooks");
60 changes: 29 additions & 31 deletions packages/client-react-hooks/src/nil-hook-base.ts
Original file line number Diff line number Diff line change
@@ -1,12 +1,11 @@
import { UseMutationResult } from "@tanstack/react-query";

/**
* NilHookState is a set of states that a NilHook can be in:
* - Idle: waiting to receive a request
* - Loading: waiting for the request to complete
* - Success: the request was successful
* - Error: the request had an error
@enum
* `NilHookState` is a set of states that a NilHook can be in:
* - Idle: Waiting to receive a request
* - Loading: Waiting for the request to complete
* - Success: The request was successful
* - Error: The request had an error
*/
export const NilHookState = {
Idle: {
Expand Down Expand Up @@ -41,7 +40,6 @@ export const NilHookState = {

/**
* `UseNilHook` is a hook that allows you to execute a NilHook operation, and check its status.
* @type
*/
export type UseNilHook<ExecuteArgs, ExecuteResult> = NilHookBaseResult<
ExecuteArgs,
Expand All @@ -56,8 +54,8 @@ export type UseNilHook<ExecuteArgs, ExecuteResult> = NilHookBaseResult<

/**
* NilHookBaseResult is a set of functions that a NilHook can use.
* @property execute - A function that executes the NilHook.
* @property executeAsync - A function that executes the NilHook asynchronously.
* execute - A function that executes the NilHook.
* executeAsync - A function that executes the NilHook asynchronously.
*/
export interface NilHookBaseResult<ExecuteArgs, ExecuteResult> {
execute: (args: ExecuteArgs) => void;
Expand All @@ -66,11 +64,11 @@ export interface NilHookBaseResult<ExecuteArgs, ExecuteResult> {

/**
* NilHookIdleResult is a set of states that a NilHook can be in when it is idle.
* @property status - The status of the NilHook.
* @property isLoading - Whether the NilHook is loading.
* @property isSuccess - Whether the NilHook is successful.
* @property isError - Whether the NilHook has an error.
* @property isIdle - Whether the NilHook is idle.
* status - The status of the NilHook.
* isLoading - Whether the NilHook is loading.
* isSuccess - Whether the NilHook is successful.
* isError - Whether the NilHook has an error.
* isIdle - Whether the NilHook is idle.
*/
export interface NilHookIdleResult {
status: "idle";
Expand All @@ -82,11 +80,11 @@ export interface NilHookIdleResult {

/**
* NilHookLoadingResult is a set of states that a NilHook can be in when it is loading.
* @property status - The status of the NilHook.
* @property isLoading - Whether the NilHook is loading.
* @property isSuccess - Whether the NilHook is successful.
* @property isError - Whether the NilHook has an error.
* @property isIdle - Whether the NilHook is idle.
* status - The status of the NilHook, namely "loading".
* isLoading - Whether the NilHook is loading.
* isSuccess - Whether the NilHook is successful.
* isError - Whether the NilHook has an error.
* isIdle - Whether the NilHook is idle.
*/
export interface NilHookLoadingResult {
status: "loading";
Expand All @@ -98,12 +96,12 @@ export interface NilHookLoadingResult {

/**
* NilHookSuccessResult is a set of states that a NilHook can be in when it is successful.
* @property status - The status of the NilHook.
* @property data - The data of the NilHook.
* @property isLoading - Whether the NilHook is loading.
* @property isSuccess - Whether the NilHook is successful.
* @property isError - Whether the NilHook has an error.
* @property isIdle - Whether the NilHook is idle.
* status - The status of the NilHook namely "success".
* data - The data of the NilHook.
* isLoading - Whether the NilHook is loading.
* isSuccess - Whether the NilHook is successful.
* isError - Whether the NilHook has an error.
* isIdle - Whether the NilHook is idle.
*/
export interface NilHookSuccessResult<R> {
status: "success";
Expand All @@ -116,12 +114,12 @@ export interface NilHookSuccessResult<R> {

/**
* NilHookErrorResult is a set of states that a NilHook can be in when it has an error.
* @property status - The status of the NilHook.
* @property error - The error of the NilHook.
* @property isLoading - Whether the NilHook is loading.
* @property isSuccess - Whether the NilHook is successful.
* @property isError - Whether the NilHook has an error.
* @property isIdle - Whether the NilHook is idle.
* status - The status of the NilHook namely "error".
* error - The error of the NilHook.
* isLoading - Whether the NilHook is loading.
* isSuccess - Whether the NilHook is successful.
* isError - Whether the NilHook has an error.
* isIdle - Whether the NilHook is idle.
*/
export interface NilHookErrorResult {
status: "error";
Expand Down
49 changes: 24 additions & 25 deletions packages/client-react-hooks/src/nillion-provider.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -25,63 +25,62 @@ import { NetworkConfig, NillionClient } from "@nillion/client-vms";
import { Log } from "./logging";

/**
* WithConfigProps
* @property config is a ProviderNetworkConfig
* @property network is a NamedNetwork
* @property client is not allowed
* `WithConfigProps`
* `config` is a ProviderNetworkConfig
* `network` is a NamedNetwork
* `client` is not allowed
**/
export interface WithConfigProps {
interface WithConfigProps {
config?: ProviderNetworkConfig;
network?: NamedNetwork;
client?: never;
}

/**
* ProviderNetworkConfig
* @property bootnodes is an array of Multiaddr or string
* @property clusterId is a ClusterId or string
* @property nilChainId is a ChainId or string
* @property nilChainEndpoint is a Url or string
* `ProviderNetworkConfig`
* `bootnodes` is an array of Multiaddr or string
* `clusterId` is a ClusterId or string
* `nilChainId` is a ChainId or string
* `nilChainEndpoint` is a Url or string
*/
export interface ProviderNetworkConfig {
interface ProviderNetworkConfig {
bootnodes?: (Multiaddr | string)[];
clusterId?: ClusterId | string;
nilChainId?: ChainId | string;
nilChainEndpoint?: Url | string;
}

/**
* WithClientProps
* @property client is a NillionClient
* @property config is not allowed
* @property network is not allowed
* `WithClientProps`
* `client` is a `NillionClient`
* `config` is not allowed
* `network` is not allowed
*/
export interface WithClientProps {
interface WithClientProps {
client: NillionClient;
config?: never;
network?: never;
}

/**
* NillionProviderProps
* @type Alias for either WithConfigProps or WithClientProps
* `NillionProviderProps`
* Alias for either WithConfigProps or WithClientProps
*/
export type NillionProviderProps = WithConfigProps | WithClientProps;

/**
* NillionContext
* @property client is a NillionClient
* @property logout is a function that returns a Promise<void>
* @interface
* `NillionContext`
* `client` is a NillionClient
* `logout` is a function that returns a Promise<void>
*/
export interface NillionContext {
client: NillionClient;
logout: () => Promise<void>;
}

/**
* NillionContext
* @type React.Context<NillionContext | undefined>
* `NillionContext`
* It provides a `NillionClient` context
*/
export const NillionContext = createContext<NillionContext | undefined>(
undefined,
Expand All @@ -92,7 +91,7 @@ const client = NillionClient.create();

/**
* NillionProvider
* @param NillionProviderProps & { children: ReactNode }
* @param NillionProviderProps - expects provider props or a `ReactNode`
* @returns ReactNode
*/
export const NillionProvider: React.FC<
Expand Down
10 changes: 4 additions & 6 deletions packages/client-react-hooks/src/use-nil-compute-output.ts
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,7 @@ import { useNillion } from "./use-nillion";

/**
* `ExecuteArgs` is an interface that can be passed to the `execute` function.
* @param id: `ComputeOutputId` or `string`
* @param id - `ComputeOutputId` or `string`
*/
interface ExecuteArgs {
id: ComputeOutputId | string;
Expand All @@ -17,16 +17,14 @@ type ExecuteResult = Record<string, NadaPrimitiveValue>;

/**
* `UseNilComputeOutput` is a hook that allows you to execute a compute output.
* @property execute - It executes the NilHook synchronously, allowing the user to check for its status via {@link isSuccess} and {@link isError}.
* @property executeAsync - It executes the NilHook asynchronously, allowing the usage of `async/await` or `.then()`.
* @type
* execute - It executes the NilHook synchronously, allowing the user to check for its status via {@link isSuccess} and {@link isError}.
* executeAsync - It executes the NilHook asynchronously, allowing the usage of `async/await` or `.then()`.
*/
export type UseNilComputeOutput = UseNilHook<ExecuteArgs, ExecuteResult>;
type UseNilComputeOutput = UseNilHook<ExecuteArgs, ExecuteResult>;

/**
* `useNilComputeOutput` is a hook that allows you to execute a compute output.
* @returns {@link UseNilComputeOutput}
* @interface
*/
export const useNilComputeOutput = (): UseNilComputeOutput => {
const { client: nilClient } = useNillion();
Expand Down
16 changes: 7 additions & 9 deletions packages/client-react-hooks/src/use-nil-compute.ts
Original file line number Diff line number Diff line change
Expand Up @@ -11,11 +11,11 @@ import { nilHookBaseResult, UseNilHook } from "./nil-hook-base";
import { useNillion } from "./use-nillion";

/** ExecuteArgs is an interface that can be passed to the `execute` function.
* @param bindings: `ProgramBindings`
* @param values?: `NadaValues`
* @param storeIds?: array of `StoreId`s or strings
* @param bindings - `ProgramBindings`
* @param values - `NadaValues`
* @param storeIds - array of `StoreId`s or strings
*/
export interface ExecuteArgs {
interface ExecuteArgs {
bindings: ProgramBindings;
values?: NadaValues;
storeIds?: (StoreId | string)[];
Expand All @@ -24,16 +24,14 @@ type ExecuteResult = ComputeOutputId;

/**
* `UseNilCompute` is a hook that allows you to execute a compute operation on Nillion.
* @property execute - It executes the NilHook synchronously, allowing the user to check for its status via {@link isSuccess} and {@link isError}.
* @property executeAsync - It executes the NilHook asynchronously, allowing the usage of `async/await` or `.then()`.
* @type
* execute - It executes the NilHook synchronously, allowing the user to check for its status via {@link isSuccess} and {@link isError}.
* executeAsync - It executes the NilHook asynchronously, allowing the usage of `async/await` or `.then()`.
*/
export type UseNilCompute = UseNilHook<ExecuteArgs, ExecuteResult>;
type UseNilCompute = UseNilHook<ExecuteArgs, ExecuteResult>;

/**
* `useNilCompute` is a hook that allows you to execute a compute.
* @returns {@link UseNilCompute}
* @interface
*/
export const useNilCompute = (): UseNilCompute => {
const { client: nilClient } = useNillion();
Expand Down
12 changes: 5 additions & 7 deletions packages/client-react-hooks/src/use-nil-delete-value.ts
Original file line number Diff line number Diff line change
Expand Up @@ -9,26 +9,24 @@ import { useNillion } from "./use-nillion";

/**
* `ExecuteArgs` is an interface that can be passed to the `execute` function
* @param id: `StoreId` or `string`
* @param id - `StoreId` or `string`
*/
export interface ExecuteArgs {
interface ExecuteArgs {
id: StoreId | string;
}

type ExecuteResult = StoreId;

/**
* `UseNilDeleteValue` is a hook that allows you to delete a value from a store.
* @property execute - It executes the NilHook synchronously, allowing the user to check for its status via {@link isSuccess} and {@link isError}.
* @property executeAsync - It executes the NilHook asynchronously, allowing the usage of `async/await` or `.then()`.
* @interface
* execute - It executes the NilHook synchronously, allowing the user to check for its status via {@link isSuccess} and {@link isError}.
* executeAsync - It executes the NilHook asynchronously, allowing the usage of `async/await` or `.then()`.
*/
export type UseNilDeleteValue = UseNilHook<ExecuteArgs, ExecuteResult>;
type UseNilDeleteValue = UseNilHook<ExecuteArgs, ExecuteResult>;

/**
* `useNilDeleteValue` is a hook that allows you to delete a value from a store.
* @returns {@link UseNilDeleteValue}
* @interface
*/
export const useNilDeleteValue = (): UseNilDeleteValue => {
const { client: nilClient } = useNillion();
Expand Down
12 changes: 5 additions & 7 deletions packages/client-react-hooks/src/use-nil-fetch-store-acl.ts
Original file line number Diff line number Diff line change
Expand Up @@ -7,25 +7,23 @@ import { useNillion } from "./use-nillion";

/**
* `ExecuteArgs` is an interface that can be passed to the `execute` function.
* @param id: `StoreId` or `string`
* @param id - `StoreId` or `string`
*/
export interface ExecuteArgs {
interface ExecuteArgs {
id: StoreId | string;
}
type ExecuteResult = StoreAcl;

/**
* `UseNilFetchStoreAcl` is a hook that allows you to fetch a store acl.
* @property execute executes the NilHook synchronously, allowing the user to check for its status via {@link isSuccess} and {@link isError}.
* @property executeAsync executes the NilHook asynchronously, allowing the usage of `async/await` or `.then()`.
* @interface
* execute - executes the NilHook synchronously, allowing the user to check for its status via {@link isSuccess} and {@link isError}.
* executeAsync - executes the NilHook asynchronously, allowing the usage of `async/await` or `.then()`.
*/
export type UseNilFetchStoreAcl = UseNilHook<ExecuteArgs, ExecuteResult>;
type UseNilFetchStoreAcl = UseNilHook<ExecuteArgs, ExecuteResult>;

/**
* `useNilFetchStoreAcl` is a hook that allows you to fetch a store acl.
* @returns {@link UseNilFetchStoreAcl}
* @interface
*/
export const useNilFetchStoreAcl = (): UseNilFetchStoreAcl => {
const { client } = useNillion();
Expand Down
19 changes: 9 additions & 10 deletions packages/client-react-hooks/src/use-nil-fetch-value.ts
Original file line number Diff line number Diff line change
Expand Up @@ -15,32 +15,31 @@ import { useNillion } from "./use-nillion";

/**
* `Options` is an interface that can be passed to the `useNilFetchValue` hook.
* @param type: `NadaValueType`
* @param staleAfter?: `number`
* @param type - `NadaValueType`
* @param staleAfter - `number`
*/
export interface Options {
interface Options {
type: NadaValueType;
staleAfter?: number;
}

/**
* `ExecuteArgs` is an interface that can be passed to the `execute` function.
* @param id: `StoreId` or `string`
* @param name: `NamedValue` or `string`
* @param id - `StoreId` or `string`
* @param name - `NamedValue` or `string`
*/
export interface ExecuteArgs {
interface ExecuteArgs {
id: StoreId | string;
name: NamedValue | string;
}
type ExecuteResult = NadaPrimitiveValue;

/**
* `UseNilFetchValue` is a hook that allows you to fetch a value from a store.
* @property execute - It executes the NilHook synchronously, allowing the user to check for its status via {@link isSuccess} and {@link isError}.
* @property executeAsync - It executes the NilHook asynchronously, allowing the usage of `async/await` or `.then()`.
* @interface
* execute - It executes the NilHook synchronously, allowing the user to check for its status via {@link isSuccess} and {@link isError}.
* executeAsync - It executes the NilHook asynchronously, allowing the usage of `async/await` or `.then()`.
*/
export type UseNilFetchValue = UseNilHook<ExecuteArgs, ExecuteResult>;
type UseNilFetchValue = UseNilHook<ExecuteArgs, ExecuteResult>;

/**
* `useNilFetchValue` is a hook that allows you to fetch a value from a store.
Expand Down
Loading

0 comments on commit f1d0672

Please sign in to comment.