or run

npx @tessl/cli init
Log in

Version

Tile

Overview

Evals

Files

docs

application.mdauthentication.mderror-handling.mdindex.mdrest-transport.mdservices.mdsocketio-transport.md
tile.json

application.mddocs/

Application Management

Core application factory function and application management functionality for creating and configuring FeathersJS client instances with service registration, hooks, and configuration management.

Capabilities

Application Factory

Creates a new FeathersJS application instance that serves as the central container for services, configuration, and transport layers.

/**
 * Creates a new FeathersJS application instance
 * @returns Application instance with service registry and configuration
 */
function feathers<T = any, S = any>(): Application<T, S>;

Usage Example:

import feathers from "@feathersjs/client";

// Create application instance
const app = feathers();

// Application is ready for configuration
console.log(app.version); // FeathersJS version

Application Configuration

Configure the application with plugins, settings, and transport layers.

/**
 * Configure the application with a plugin or configuration function
 * @param callback - Configuration function that receives the app instance
 * @returns Application instance for method chaining
 */
configure(callback: (app: Application) => void): this;

/**
 * Get application setting value
 * @param name - Setting name to retrieve
 * @returns Setting value
 */
get<L extends keyof Settings>(name: L): Settings[L];

/**
 * Set application setting value
 * @param name - Setting name to set
 * @param value - Setting value
 * @returns Application instance for method chaining
 */
set<L extends keyof Settings>(name: L, value: Settings[L]): this;

Usage Examples:

import feathers from "@feathersjs/client";
import { authentication, rest } from "@feathersjs/client";

const app = feathers();

// Configure with plugins
app.configure(authentication());
app.configure(rest("http://localhost:3030").fetch(fetch));

// Set application settings
app.set("host", "localhost");
app.set("port", 3030);

// Get application settings
const host = app.get("host"); // "localhost"

Service Registration

Register and manage services within the application.

/**
 * Register a service at the given path
 * @param path - Service path/name
 * @param service - Service instance or application
 * @param options - Service configuration options
 * @returns Application instance for method chaining
 */
use<L extends keyof S>(path: L, service: ServiceInterface | Application, options?: ServiceOptions): this;

/**
 * Unregister a service at the given path
 * @param path - Service path to remove
 * @returns Promise resolving to the removed service
 */
unuse<L extends keyof S>(path: L): Promise<FeathersService>;

/**
 * Get a service instance by path
 * @param path - Service path to retrieve
 * @returns Service instance with CRUD methods
 */
service<L extends keyof S>(path: L): FeathersService<T>;

/**
 * Create default service instance for a location
 * @param location - Service location/path
 * @returns Default service implementation
 */
defaultService(location: string): ServiceInterface;

Usage Examples:

// Register a custom service
app.use("custom", {
  async find(params) {
    return [{ id: 1, name: "test" }];
  }
});

// Get service instance
const userService = app.service("users");
const customService = app.service("custom");

// Use service methods
const users = await userService.find();
const customData = await customService.find();

// Unregister service
await app.unuse("custom");

Application Lifecycle

Manage application initialization and cleanup.

/**
 * Initialize the application and all registered services
 * @param server - Optional server instance
 * @returns Promise resolving to the application
 */
setup(server?: any): Promise<Application>;

/**
 * Tear down the application and clean up resources
 * @param server - Optional server instance
 * @returns Promise resolving to the application
 */
teardown(server?: any): Promise<Application>;

Usage Examples:

// Initialize application
await app.setup();

// Application is ready for use
const users = await app.service("users").find();

// Clean up when done
await app.teardown();

Hook System

Register application-level hooks that run before and after service method calls.

/**
 * Register application-level hooks
 * @param map - Hook configuration mapping hook types to functions
 * @returns Application instance for method chaining
 */
hooks(map: ApplicationHookOptions): this;

interface ApplicationHookOptions {
  before?: {
    all?: HookFunction[];
    find?: HookFunction[];
    get?: HookFunction[];
    create?: HookFunction[];
    update?: HookFunction[];
    patch?: HookFunction[];
    remove?: HookFunction[];
    [key: string]: HookFunction[];
  };
  after?: {
    all?: HookFunction[];
    find?: HookFunction[];
    get?: HookFunction[];
    create?: HookFunction[];
    update?: HookFunction[];
    patch?: HookFunction[];
    remove?: HookFunction[];
    [key: string]: HookFunction[];
  };
  error?: {
    all?: HookFunction[];
    find?: HookFunction[];
    get?: HookFunction[];
    create?: HookFunction[];
    update?: HookFunction[];
    patch?: HookFunction[];
    remove?: HookFunction[];
    [key: string]: HookFunction[];
  };
}

type HookFunction<A = Application, S = any> = (context: HookContext<A, S>) => Promise<HookContext<A, S>> | HookContext<A, S> | void;

Usage Examples:

// Register application-level hooks
app.hooks({
  before: {
    all: [
      async (context) => {
        console.log(`Before ${context.method} on ${context.path}`);
        return context;
      }
    ]
  },
  after: {
    all: [
      async (context) => {
        console.log(`After ${context.method} on ${context.path}`);
        return context;
      }
    ]
  },
  error: {
    all: [
      async (context) => {
        console.error(`Error in ${context.method} on ${context.path}:`, context.error);
        return context;
      }
    ]
  }
});

Application Properties

Access application state and registry information.

interface Application<T = any, S = any> {
  /** FeathersJS version string */
  version: string;
  
  /** Service registry containing all registered services */
  services: Services;
  
  /** Application settings object */
  settings: Settings;
  
  /** Array of service mixins */
  mixins: ServiceMixin[];
  
  /** Setup state flag */
  _isSetup: boolean;
  
  /** Socket.io connection (when using socketio transport) */
  io?: Socket;
  
  /** Authentication client instance (when using authentication) */
  authentication?: AuthenticationClient;
  
  /** Authenticate method (added by authentication plugin) */
  authenticate?: (data?: AuthenticationRequest, params?: Params) => Promise<AuthenticationResult>;
  
  /** Re-authenticate method (added by authentication plugin) */
  reAuthenticate?: (force?: boolean, strategy?: string, params?: Params) => Promise<AuthenticationResult>;
  
  /** Logout method (added by authentication plugin) */
  logout?: () => Promise<AuthenticationResult | null>;
}

interface Services {
  [path: string]: FeathersService;
}

interface Settings {
  [key: string]: any;
}

interface ServiceMixin {
  (service: any, location: string, options: ServiceOptions): void;
}

Usage Examples:

// Check version
console.log(app.version); // "5.0.34"

// Access services registry
console.log(Object.keys(app.services)); // ["users", "messages"]

// Check setup state
if (app._isSetup) {
  console.log("Application is initialized");
}

// Access settings
const allSettings = app.settings;

Type Definitions

interface ServiceOptions {
  methods?: string[];
  events?: string[];
  multi?: boolean | string[];
  paginate?: false | { default?: number; max?: number };
}

interface HookContext<A = Application, S = any> {
  app: A;
  service: S;
  path: string;
  method: string;
  type: HookType;
  params: Params;
  id?: Id;
  data?: any;
  result?: any;
  error?: any;
}

type HookType = "before" | "after" | "error" | "around";