Skip to content

Command

Command wraps SvelteKit command(...) and makes the callable client-side surface return Effect.

ts
import { Command } from "svelte-effect-runtime";

Signatures

ts
type EffectCommand<Input, Output, Error = never> =
  ((arg: OptionalArgument<Input>) =>
    Effect.Effect<Output, RemoteFailure<Error>, never>) & {
      native: RemoteCommand<Input, Output>;
      readonly pending: number;
    };
ts
interface EffectCommandFactory {
  <Output, ErrorType, Requirements>(
    fn: () => Effect.Effect<Output, ErrorType, Requirements>
  ): EffectCommand<void, Output, ErrorType>;

  <Input, Output, ErrorType, Requirements>(
    validate: "unchecked",
    fn: (arg: Input) => Effect.Effect<Output, ErrorType, Requirements>
  ): EffectCommand<Input, Output, ErrorType>;

  <SchemaType extends EffectSchema, Output, ErrorType, Requirements>(
    validate: SchemaType,
    fn: (arg: SchemaOutput<SchemaType>) =>
      Effect.Effect<Output, ErrorType, Requirements>
  ): EffectCommand<SchemaInput<SchemaType>, Output, ErrorType>;
}

Semantics

  • Same validator and schema model as Query.
  • Exposes pending from the native command.
  • Exposes .native(...) to access the underlying native command behavior.

BSD-3-Clause