@lakimi/nestjs-external-schema
TypeScript icon, indicating that this package has built-in type declarations

0.0.14 • Public • Published

@lakimi/nestjs-external-schema

@lakimi/nestjs-external-schema is a library that integrates @lakimi/external-schema with NestJS using decorators and modules, making it easy to define and register external schema tools within a NestJS application.

🚀 Features

  • Seamless integration with NestJS using decorators and dependency injection.
  • Automatic discovery and registration of external schema functions.
  • Easy-to-define tools with input validation using JSONSchema.
  • Supports both synchronous and asynchronous configuration for the module.

📦 Installation

npm install @lakimi/nestjs-external-schema

Or with Yarn:

yarn add @lakimi/nestjs-external-schema

⚙️ Usage

Step 1: Register the Module

You can register the LakimiExternalSchemaModule in two ways: statically with predefined options or asynchronously using a factory function.

Static Registration

import { Module } from '@nestjs/common';
import { LakimiExternalSchemaModule } from '@lakimi/nestjs-external-schema';

@Module({
  imports: [
    LakimiExternalSchemaModule.forRoot({
      client: {
        clientId: 'your-client-id',
        secretKey: 'your-secret-key',
        environment: 'production',
        name: 'MyApp',
      },
    }),
  ],
})
export class AppModule {}

Asynchronous Registration

import { Module } from '@nestjs/common';
import { LakimiExternalSchemaModule } from '@lakimi/nestjs-external-schema';

@Module({
  imports: [
    LakimiExternalSchemaModule.forRootAsync({
      useFactory: async () => ({
        client: {
          clientId: 'your-client-id',
          secretKey: 'your-secret-key',
          environment: 'development',
          name: 'MyApp',
        },
      }),
    }),
  ],
})
export class AppModule {}

Step 2: Define External Schema Functions

You can use the @LakimiFunction decorator to define external schema tools. Each function must specify a name, description, input schema, and an optional set of constraints.

import { LakimiFunction } from '@lakimi/nestjs-external-schema';
import { JSONSchema7 } from 'json-schema';

export class MyService {
  @LakimiFunction({
    name: 'add_numbers',
    description: 'Adds two numbers and returns the result.',
    input_schema: {
      type: 'object',
      properties: {
        a: { type: 'number' },
        b: { type: 'number' },
      },
      required: ['a', 'b'],
    },
    constraints: {
      auth: true,
    },
  })
  async addNumbers(input: { a: number; b: number }): Promise<{ result: number }> {
    return { result: input.a + input.b };
  }
}

Step 3: Run Your Application

Once your module is configured and your functions are defined, start your NestJS application. The service will automatically discover and register all the external schema functions defined with the @LakimiFunction decorator.


📖 API Reference

LakimiExternalSchemaModule

  • forRoot(options: LakimiExternalSchemaOptions): DynamicModule: Registers the module with static options.
  • forRootAsync(options: { useFactory: Function, inject?: any[] }): DynamicModule: Registers the module with asynchronous options.

@LakimiFunction(metadata: LakimiFunctionMetadata)

Decorator to define an external schema function.


📝 License

ISC © 2025 Lakimi Solutions S.L.

Readme

Keywords

none

Package Sidebar

Install

npm i @lakimi/nestjs-external-schema

Weekly Downloads

20

Version

0.0.14

License

ISC

Unpacked Size

30.5 kB

Total Files

32

Last publish

Collaborators

  • bvadell