### Start Development Server Source: https://github.com/forestadmin/agent-nodejs/blob/main/packages/_example/README.md Execute this command to launch the ForestAdmin example agent development server. ```bash yarn start ``` -------------------------------- ### Initialize AgentBuilder with Options Source: https://github.com/forestadmin/agent-nodejs/wiki/@forestadmin.agent.default Instantiate the AgentBuilder with specific options. If options are missing, default values will be applied. This example demonstrates adding a datasource and starting the agent. ```javascript new AgentBuilder(options) .addDatasource(new Datasource()) .start(); ``` -------------------------------- ### Install Dependencies Source: https://github.com/forestadmin/agent-nodejs/blob/main/README.md Run this command to install and bootstrap the project dependencies. ```bash yarn install && yarn bootstrap ``` -------------------------------- ### Install Dependencies and Bootstrap Project Source: https://github.com/forestadmin/agent-nodejs/blob/main/packages/_example/README.md Run these commands in the agent-nodejs directory to install all project dependencies and auto-link packages. ```bash yarn && yarn bootstrap ``` -------------------------------- ### Install @forestadmin/agent-testing Source: https://github.com/forestadmin/agent-nodejs/blob/main/packages/agent-testing/README.md Install the agent-testing package as a development dependency. ```bash npm install --save-dev @forestadmin/agent-testing ``` -------------------------------- ### Navigate to Example Directory Source: https://github.com/forestadmin/agent-nodejs/blob/main/packages/_example/README.md Change the current directory to the _example package to perform example-specific operations. ```bash cd packages/_example ``` -------------------------------- ### Install Dependencies Source: https://github.com/forestadmin/agent-nodejs/blob/main/CLAUDE.md Installs project dependencies using Yarn. ```bash yarn ``` -------------------------------- ### Run Standalone MCP Server (Package) Source: https://github.com/forestadmin/agent-nodejs/blob/main/packages/mcp-server/README.md Starts the MCP server from the package directory. Use `yarn start:dev` for development with automatic .env file loading. ```bash yarn start # Production yarn start:dev # Development (loads .env file automatically) ``` -------------------------------- ### Create a New Forest Admin Agent Source: https://github.com/forestadmin/agent-nodejs/wiki/@forestadmin.agent.default Use AgentBuilder to create a new Forest Admin agent from scratch. This example shows the minimal code required to add a datasource and start the agent. ```javascript new AgentBuilder(options) .addDatasource(new SomeDatasource()) .start(); ``` -------------------------------- ### Restrict Tools Example Source: https://github.com/forestadmin/agent-nodejs/blob/main/packages/mcp-server/README.md Demonstrates how to restrict the available tools for the MCP server, for example, to enable a read-only mode. ```APIDOC ## Restrict Tools ### With Forest Admin Agent (TypeScript) ```typescript agent.mountAiMcpServer({ enabledTools: ['describeCollection', 'list', 'listRelated'], }); ``` ### Standalone (Environment Variable) ```bash export FOREST_MCP_ENABLED_TOOLS="describeCollection,list,listRelated" npx forest-mcp-server ``` **Note:** `describeCollection` is always enabled as it is required for the MCP server to function. ``` -------------------------------- ### Start the Forest Admin Agent Source: https://github.com/forestadmin/agent-nodejs/wiki/@forestadmin.agent.default Initiates the Forest Admin agent process. ```typescript start(): Promise ``` -------------------------------- ### Spin Up Databases with Docker Compose Source: https://github.com/forestadmin/agent-nodejs/blob/main/packages/_example/README.md Use this command to start all required databases in Docker containers in detached mode. ```bash docker compose up -d ``` -------------------------------- ### Quick Start: Test Forest Admin Agent Source: https://github.com/forestadmin/agent-nodejs/blob/main/packages/agent-testing/README.md Set up a local sandbox and test client to run agent tests. Ensure your agent is configured to point to the sandbox and provide necessary environment secrets. ```typescript import { createAgentTestClient, createForestServerSandbox, } from '@forestadmin/agent-testing'; describe('My Agent', () => { let sandbox, client; beforeAll(async () => { // 1. Start a local sandbox that replaces Forest Admin servers sandbox = await createForestServerSandbox(3001); // 2. Start your agent pointing to the sandbox // FOREST_SERVER_URL=http://localhost:3001 node your-agent.js // 3. Connect the test client client = await createAgentTestClient({ serverUrl: 'http://localhost:3001', agentUrl: 'http://localhost:3310', agentSchemaPath: './.forestadmin-schema.json', agentForestEnvSecret: process.env.FOREST_ENV_SECRET, agentForestAuthSecret: process.env.FOREST_AUTH_SECRET, }); }); afterAll(async () => { await sandbox?.close(); }); it('should list users', async () => { const users = await client.collection('users').list(); expect(users.length).toBeGreaterThan(0); }); }); ``` -------------------------------- ### Run Standalone MCP Server with Inline Variables Source: https://github.com/forestadmin/agent-nodejs/blob/main/packages/mcp-server/README.md Starts the standalone MCP server by setting environment variables directly in the command line. This avoids the need for a separate `.env` file. ```bash FOREST_ENV_SECRET="your-env-secret" FOREST_AUTH_SECRET="your-auth-secret" npx forest-mcp-server ``` -------------------------------- ### Install Linear MCP Server Source: https://github.com/forestadmin/agent-nodejs/blob/main/CLAUDE.md Adds the Linear MCP server to your Claude Code configuration using a specific command. ```bash claude mcp add linear-server npx -- -y @anthropic/linear-mcp-server ``` -------------------------------- ### DataSource Methods Source: https://github.com/forestadmin/agent-nodejs/wiki/@forestadmin.datasource-toolkit.DataSource This section details the methods available for the DataSource interface, including adding, getting, and rendering charts for collections. ```APIDOC ## DataSource Methods ### addCollection ▸ **addCollection**(`collection`): `void` #### Parameters | Name | Type | | :------ | :------ | | `collection` | [`Collection`](../wiki/@forestadmin.datasource-toolkit.Collection) | #### Returns `void` #### Defined in [packages/datasource-toolkit/src/interfaces/collection.ts:16](https://github.com/ForestAdmin/agent-nodejs/blob/39d6ac7/packages/datasource-toolkit/src/interfaces/collection.ts#L16) --- ### getCollection ▸ **getCollection**(`name`): [`Collection`](../wiki/@forestadmin.datasource-toolkit.Collection) #### Parameters | Name | Type | | :------ | :------ | | `name` | `string` | #### Returns [`Collection`](../wiki/@forestadmin.datasource-toolkit.Collection) #### Defined in [packages/datasource-toolkit/src/interfaces/collection.ts:15](https://github.com/ForestAdmin/agent-nodejs/blob/39d6ac7/packages/datasource-toolkit/src/interfaces/collection.ts#L15) --- ### renderChart ▸ **renderChart**(`caller`, `name`): `Promise`<`unknown`> #### Parameters | Name | Type | | :------ | :------ | | `caller` | [`Caller`](../wiki/@forestadmin.datasource-toolkit#caller-1) | | `name` | `string` | #### Returns `Promise`<`unknown`> #### Defined in [packages/datasource-toolkit/src/interfaces/collection.ts:18](https://github.com/ForestAdmin/agent-nodejs/blob/39d6ac7/packages/datasource-toolkit/src/interfaces/collection.ts#L18) ``` -------------------------------- ### Strong Assertion Example Source: https://github.com/forestadmin/agent-nodejs/blob/main/CLAUDE.md Demonstrates a strong assertion in Jest that verifies a function was called with exact arguments. ```javascript expect(mock).toHaveBeenCalledWith({ host: 'localhost', port: 3000 }) ``` -------------------------------- ### Partial Match Assertion Example Source: https://github.com/forestadmin/agent-nodejs/blob/main/CLAUDE.md Demonstrates a Jest assertion using `expect.objectContaining` for partial matching of arguments, useful when some values are dynamic. ```javascript expect(mock).toHaveBeenCalledWith(expect.objectContaining({ host: 'localhost' })) ``` -------------------------------- ### Restrict MCP Server Tools (Standalone) Source: https://github.com/forestadmin/agent-nodejs/blob/main/packages/mcp-server/README.md Enables a specific set of tools for the standalone MCP server using the `FOREST_MCP_ENABLED_TOOLS` environment variable. This example restricts access to read-only operations. ```bash # Standalone export FOREST_MCP_ENABLED_TOOLS="describeCollection,list,listRelated" npx forest-mcp-server ``` -------------------------------- ### Restrict MCP Server Tools (Agent) Source: https://github.com/forestadmin/agent-nodejs/blob/main/packages/mcp-server/README.md Configures the MCP server within the Forest Admin agent to expose only specific tools. This example sets up a read-only mode by enabling only 'describeCollection', 'list', and 'listRelated'. ```typescript // With Forest Admin Agent — read-only example agent.mountAiMcpServer({ enabledTools: ['describeCollection', 'list', 'listRelated'], }); ``` -------------------------------- ### Seed Databases Source: https://github.com/forestadmin/agent-nodejs/blob/main/packages/_example/README.md Run this command to populate the databases with initial data. ```bash yarn db:seed ``` -------------------------------- ### Build All Packages Source: https://github.com/forestadmin/agent-nodejs/blob/main/CLAUDE.md Builds all packages within the monorepo. ```bash yarn build ``` -------------------------------- ### CollectionUtils.getThroughTarget Source: https://github.com/forestadmin/agent-nodejs/wiki/@forestadmin.datasource-toolkit.CollectionUtils Gets the target field name for a through relation. ```APIDOC ## Static Method: getThroughTarget ### Description Gets the target field name for a through relation. ### Method `Static` ### Endpoint N/A (This is a utility method, not an API endpoint) ### Parameters #### Path Parameters None #### Query Parameters None #### Request Body None ### Parameters - **collection** (Collection) - The collection. - **relationName** (string) - The name of the relation. ### Returns `string` - The target field name. ### Defined in `packages/datasource-toolkit/src/utils/collection.ts:94` ``` -------------------------------- ### CollectionUtils.getThroughOrigin Source: https://github.com/forestadmin/agent-nodejs/wiki/@forestadmin.datasource-toolkit.CollectionUtils Gets the origin field name for a through relation. ```APIDOC ## Static Method: getThroughOrigin ### Description Gets the origin field name for a through relation. ### Method `Static` ### Endpoint N/A (This is a utility method, not an API endpoint) ### Parameters #### Path Parameters None #### Query Parameters None #### Request Body None ### Parameters - **collection** (Collection) - The collection. - **relationName** (string) - The name of the relation. ### Returns `string` - The origin field name. ### Defined in `packages/datasource-toolkit/src/utils/collection.ts:75` ``` -------------------------------- ### CollectionUtils.getInverseRelation Source: https://github.com/forestadmin/agent-nodejs/wiki/@forestadmin.datasource-toolkit.CollectionUtils Gets the name of the inverse relation for a given relation. ```APIDOC ## Static Method: getInverseRelation ### Description Gets the name of the inverse relation for a given relation. ### Method `Static` ### Endpoint N/A (This is a utility method, not an API endpoint) ### Parameters #### Path Parameters None #### Query Parameters None #### Request Body None ### Parameters - **collection** (Collection) - The collection. - **relationName** (string) - The name of the relation. ### Returns `string` - The name of the inverse relation. ### Defined in `packages/datasource-toolkit/src/utils/collection.ts:43` ``` -------------------------------- ### Collection Get Form API Source: https://github.com/forestadmin/agent-nodejs/wiki/@forestadmin.datasource-toolkit.BaseCollection Retrieves the form definition for a collection. ```APIDOC ## getForm ### Description Retrieves the form definition for a collection. ### Method (No specific method type provided, likely public) ### Returns Promise ### Implementation of Collection.getForm ### Defined in packages/datasource-toolkit/src/base-collection.ts:89 ``` -------------------------------- ### Build Project with Watch Mode Source: https://github.com/forestadmin/agent-nodejs/blob/main/packages/_example/README.md Execute this command to build the project and enable watching for file changes, which automatically recompiles the code. ```bash yarn build:watch ``` -------------------------------- ### Get Array Values Iterator Source: https://github.com/forestadmin/agent-nodejs/wiki/@forestadmin.datasource-toolkit.Sort Returns an iterable iterator for the values in the array. ```typescript values(): IterableIterator<{ ascending: boolean; field: string; }> ``` -------------------------------- ### Configure Standalone MCP Server with .env Source: https://github.com/forestadmin/agent-nodejs/blob/main/packages/mcp-server/README.md Sets up environment variables for the standalone MCP server by creating a `.env` file. Required variables include `FOREST_ENV_SECRET` and `FOREST_AUTH_SECRET`. ```bash FOREST_ENV_SECRET="your-env-secret" FOREST_AUTH_SECRET="your-auth-secret" ``` -------------------------------- ### Collection Get Form API Source: https://github.com/forestadmin/agent-nodejs/wiki/@forestadmin.datasource-toolkit.OperatorsEmulateCollectionDecorator Retrieves the form configuration for a specific action within a collection. ```APIDOC ## GET /api/collections/:collectionName/forms/:actionName ### Description Retrieves the form definition for a given action within a collection. This is useful for dynamically rendering forms based on action requirements. ### Method GET ### Endpoint /api/collections/:collectionName/forms/:actionName ### Parameters #### Query Parameters - **caller** (Caller) - Required - The caller object for authentication and context. - **name** (string) - Required - The name of the action for which to retrieve the form. - **data** (RecordData) - Optional - Data associated with the form context. - **filter** (Filter) - Optional - A filter to apply to the form retrieval. ### Response #### Success Response (200) - **result** (ActionField[]) - An array of ActionField objects defining the form structure. #### Response Example ```json { "result": [ { "label": "Field Label", "field": "fieldName", "type": "string" } ] } ``` ``` -------------------------------- ### Run Standalone MCP Server (CLI) Source: https://github.com/forestadmin/agent-nodejs/blob/main/packages/mcp-server/README.md Launches the MCP server as a standalone service using Node.js. This is useful for environments where the Forest Admin agent is not directly integrated. ```bash npx forest-mcp-server ``` -------------------------------- ### Get Form for Action Source: https://github.com/forestadmin/agent-nodejs/wiki/@forestadmin.datasource-toolkit.JointureCollectionDecorator Retrieves the form schema for a given action. Optional data and filter can be provided. ```APIDOC ## getForm ### Description Retrieves the form schema for a given action. ### Method `getForm` ### Parameters - **name** (string) - Required - The name of the action. - **data** (RecordData) - Optional - Data to pre-fill the form. - **filter** (Filter) - Optional - A filter to apply when getting the form. ### Returns `Promise` - A promise that resolves to an array of form fields. ### Inherited from CollectionDecorator.getForm ### Defined in packages/datasource-toolkit/src/decorators/collection-decorator.ts:43 ``` -------------------------------- ### Lint All Packages Source: https://github.com/forestadmin/agent-nodejs/blob/main/CLAUDE.md Runs ESLint to check for code style issues across all packages. ```bash yarn lint ``` -------------------------------- ### Get Form for Action Source: https://github.com/forestadmin/agent-nodejs/wiki/@forestadmin.datasource-toolkit.ComputedCollectionDecorator Retrieves the form schema for a specific action, which defines the fields required for the action. ```APIDOC ## GET /api/collections/:collectionId/forms/:actionName ### Description Retrieves the form definition for a given action, specifying the fields and their properties. ### Method GET ### Endpoint `/api/collections/:collectionId/forms/:actionName` ### Parameters #### Path Parameters - **collectionId** (string) - Required - The ID of the collection. - **actionName** (string) - Required - The name of the action for which to get the form. #### Query Parameters - **data** (RecordData) - Optional - Data to pre-fill the form. - **filter** (Filter) - Optional - A filter to apply when generating the form. ### Response #### Success Response (200) - **ActionField** (Array) - An array of form field definitions. #### Response Example ```json [ { "name": "fieldName", "type": "string", "label": "Field Label", "isRequired": true } ] ``` ``` -------------------------------- ### SequelizeCollection Constructor Source: https://github.com/forestadmin/agent-nodejs/wiki/@forestadmin.datasource-sequelize.SequelizeCollection Initializes a new instance of the SequelizeCollection class. ```APIDOC ## new SequelizeCollection() ### Description Initializes a new instance of the SequelizeCollection class. ### Parameters #### Path Parameters - **name** (string) - Required - The name of the collection. - **datasource** (DataSource) - Required - The data source instance. - **model** (ModelDefined) - Required - The Sequelize model definition. - **logger?** (Logger) - Optional - The logger instance. ### Overrides BaseCollection.constructor ### Defined in [packages/datasource-sequelize/src/collection.ts:31](https://github.com/ForestAdmin/agent-nodejs/blob/39d6ac7/packages/datasource-sequelize/src/collection.ts#L31) ``` -------------------------------- ### Weak Assertion Example Source: https://github.com/forestadmin/agent-nodejs/blob/main/CLAUDE.md Demonstrates a weak assertion in Jest that only checks if a function was called, without verifying arguments. ```javascript expect(mock).toHaveBeenCalled() ``` -------------------------------- ### Run Tests with Coverage Source: https://github.com/forestadmin/agent-nodejs/blob/main/CLAUDE.md Runs all tests and generates a code coverage report. ```bash yarn test:coverage ``` -------------------------------- ### Array.prototype.unshift Source: https://github.com/forestadmin/agent-nodejs/wiki/@forestadmin.datasource-toolkit.Projection Inserts new elements at the start of an array, and returns the new length of the array. This method is inherited from Array.unshift. ```APIDOC ## Array.prototype.unshift ### Description Inserts new elements at the start of an array, and returns the new length of the array. ### Method `unshift` ### Parameters #### Request Body - **items** (string[]) - Required - Elements to insert at the start of the array. ### Returns `number` ### Inherited from Array.unshift ### Defined in node_modules/typescript/lib/lib.es5.d.ts:1359 ``` -------------------------------- ### Collection Constructor Source: https://github.com/forestadmin/agent-nodejs/wiki/@forestadmin.agent.Collection Initializes a new Collection instance. This is the foundational step for defining a collection within the ForestAdmin agent. ```APIDOC ## new Collection(stack, name) ### Description Initializes a new Collection instance. ### Parameters #### Path Parameters - **stack** (default) - Required - The stack context for the collection. - **name** (string) - Required - The name of the collection. ### Defined in packages/agent/src/builder/collection.ts:35 ``` -------------------------------- ### Collection Get Form API Source: https://github.com/forestadmin/agent-nodejs/wiki/@forestadmin.datasource-toolkit.SortEmulateCollectionDecorator Retrieves the form configuration for a specific action on a collection. This method is inherited from CollectionDecorator. ```APIDOC ## Get Form API ### Description Retrieves the form configuration for a specific action on a collection. ### Method Not specified (likely internal or part of a class method) ### Endpoint Not specified ### Parameters - **caller** (Caller) - Description not specified - **name** (string) - The name of the action for which to get the form. - **data** (RecordData, optional) - Data associated with the form. - **filter** (Filter, optional) - Filter criteria for the form. ### Returns `Promise`<[`ActionField`](../wiki/@forestadmin.datasource-toolkit.ActionField)[] ### Defined in `packages/datasource-toolkit/src/decorators/collection-decorator.ts:49` ``` -------------------------------- ### Run All Tests Source: https://github.com/forestadmin/agent-nodejs/blob/main/CLAUDE.md Executes all unit and integration tests using Jest. ```bash yarn test ``` -------------------------------- ### Unshift Array - Add Elements to Start Source: https://github.com/forestadmin/agent-nodejs/wiki/@forestadmin.datasource-toolkit.Projection Inserts new elements at the beginning of an array and returns the new length of the array. ```typescript number ``` -------------------------------- ### ConditionTree Constructors Source: https://github.com/forestadmin/agent-nodejs/wiki/@forestadmin.datasource-toolkit.ConditionTree Initializes a new instance of the ConditionTree class. ```APIDOC ## new ConditionTree() ### Description Initializes a new instance of the ConditionTree class. ### Constructor `new ConditionTree()` ``` -------------------------------- ### Page Class Constructor Source: https://github.com/forestadmin/agent-nodejs/wiki/@forestadmin.datasource-toolkit.Page Initializes a new Page object with optional skip and limit values. ```APIDOC ## new Page(skip?, limit?) ### Description Initializes a new Page object. ### Parameters #### Path Parameters - **skip** (number) - Optional - The number of records to skip. - **limit** (number) - Optional - The maximum number of records to return. ### Defined in packages/datasource-toolkit/src/interfaces/query/page.ts:9 ``` -------------------------------- ### nest Method Source: https://github.com/forestadmin/agent-nodejs/wiki/@forestadmin.datasource-toolkit.ConditionTreeBranch Creates a new ConditionTree with a prefix applied to all field names. ```APIDOC ## nest ### Description Creates a new ConditionTree with a prefix applied to all field names. ### Method `nest(prefix: string): ConditionTree` ### Parameters #### Parameters - **prefix** (string) - The prefix to apply to field names. ### Returns A new `ConditionTree` instance with the applied prefix. ### Inherited from [ConditionTree.nest](../wiki/@forestadmin.datasource-toolkit.ConditionTree#nest-1) ### Defined in [packages/datasource-toolkit/src/interfaces/query/condition-tree/nodes/base.ts:36](https://github.com/ForestAdmin/agent-nodejs/blob/39d6ac7/packages/datasource-toolkit/src/interfaces/query/condition-tree/nodes/base.ts#L36) ``` -------------------------------- ### AgentBuilder Constructor Source: https://github.com/forestadmin/agent-nodejs/wiki/@forestadmin.agent.default Initializes a new Forest Admin Agent Builder. Provides default options if not specified. ```APIDOC ## new default(options) ### Description Create a new Agent Builder. If any options are missing, the default will be applied: ``` clientId: null, forestServerUrl: 'https://api.forestadmin.com', logger: (level, data) => console.error(OptionsUtils.loggerPrefix[level], data), prefix: '/forest', schemaPath: '.forestadmin-schema.json', permissionsCacheDurationInSeconds: 15 * 60, ``` ### Parameters #### Path Parameters - **options** (AgentOptions) - Required - options ### Request Example ```javascript new AgentBuilder(options) .addDatasource(new Datasource()) .start(); ``` ``` -------------------------------- ### Splice Array (Remove Elements) Source: https://github.com/forestadmin/agent-nodejs/wiki/@forestadmin.datasource-toolkit.Sort Removes a specified number of elements from an array starting at a given index. Returns the deleted elements. ```typescript splice(start, deleteCount?): { ascending: boolean; field: string; }[] ``` -------------------------------- ### SequelizeDataSource Constructor Source: https://github.com/forestadmin/agent-nodejs/wiki/@forestadmin.datasource-sequelize.SequelizeDataSource Initializes a new instance of the SequelizeDataSource class. ```APIDOC ## new SequelizeDataSource(sequelize, logger?) ### Description Initializes a new instance of the SequelizeDataSource class. ### Parameters #### Path Parameters - **sequelize** (Sequelize) - Required - The Sequelize instance to use. - **logger?** (Logger) - Optional - A logger instance. ### Defined in `packages/datasource-sequelize/src/datasource.ts:15` ``` -------------------------------- ### slice Method Source: https://github.com/forestadmin/agent-nodejs/wiki/@forestadmin.datasource-toolkit.Sort Returns a copy of a section of an array. For both start and end, a negative index can be used to indicate an offset from the end of the array. ```APIDOC ## slice(start?, end?): { ascending: boolean; field: string }[] ### Description Returns a copy of a section of an array. For both start and end, a negative index can be used to indicate an offset from the end of the array. For example, -2 refers to the second to last element of the array. ### Parameters #### start * `number` - Optional - The beginning index of the specified portion of the array. If start is undefined, then the slice begins at index 0. #### end * `number` - Optional - The end index of the specified portion of the array. This is exclusive of the element at the index 'end'. If end is undefined, then the slice extends to the end of the array. ### Returns * { `ascending`: `boolean` ; `field`: `string` }[] - A new array containing the specified portion of the original array. ### Inherited from Array.slice ### Defined in node_modules/typescript/lib/lib.es5.d.ts:1328 ``` -------------------------------- ### Splice Array - Remove Elements Source: https://github.com/forestadmin/agent-nodejs/wiki/@forestadmin.datasource-toolkit.Projection Removes a specified number of elements from an array starting at a given index. Returns the deleted elements. ```typescript string[] ``` -------------------------------- ### BaseCollection Constructor Source: https://github.com/forestadmin/agent-nodejs/wiki/@forestadmin.datasource-toolkit.BaseCollection Initializes a new instance of the BaseCollection class. ```APIDOC ## new BaseCollection(name, datasource) ### Description Initializes a new instance of the BaseCollection class. ### Parameters #### Path Parameters - **name** (string) - Required - The name of the collection. - **datasource** (DataSource) - Required - The DataSource instance associated with this collection. ### Defined in `packages/datasource-toolkit/src/base-collection.ts:16` ``` -------------------------------- ### Array.fill Source: https://github.com/forestadmin/agent-nodejs/wiki/@forestadmin.datasource-toolkit.Sort Changes all array elements from start to end index to a static value and returns the modified array. This method is inherited from Array.prototype.fill. ```APIDOC ## POST /api/array/fill ### Description Changes all array elements from `start` to `end` index to a static `value` and returns the modified array. ### Method POST ### Endpoint /api/array/fill ### Parameters #### Request Body - **value** (object) - Required - The value to fill the array section with. It should contain `ascending` (boolean) and `field` (string). - **start** (number) - Optional - Index to start filling the array at. If negative, it's treated as `length + start`. - **end** (number) - Optional - Index to stop filling the array at. If negative, it's treated as `length + end`. ### Response #### Success Response (200) - **result** (array) - The modified array. #### Response Example ```json { "result": [ { "field": "name", "ascending": true }, { "field": "name", "ascending": true } ] } ``` ``` -------------------------------- ### Mount MCP Server with Forest Admin Agent Source: https://github.com/forestadmin/agent-nodejs/blob/main/packages/mcp-server/README.md Integrates the MCP server into an existing Forest Admin agent instance. Ensure the agent is created and data sources are added before mounting the MCP server. ```typescript import { createAgent, } from '@forestadmin/agent'; const agent = createAgent(options) .addDataSource(myDataSource) .mountAiMcpServer(); agent.mountOnExpress(app); agent.start(); ``` -------------------------------- ### Get HTTP Callback for Node.js Server Source: https://github.com/forestadmin/agent-nodejs/wiki/@forestadmin.agent.default Retrieve the native Node.js HttpCallback object to integrate the agent with an existing HTTP server. ```typescript import http from 'http'; ... const server = http.createServer(agent.httpCallback); ``` -------------------------------- ### Filter Constructor Source: https://github.com/forestadmin/agent-nodejs/wiki/@forestadmin.datasource-toolkit.Filter Details on how to instantiate the Filter class. ```APIDOC ## Constructors ### constructor • **new Filter**(`parts`) #### Parameters | Name | Type | | :------ | :----------------------------------------------- | | `parts` | [`FilterComponents`](../wiki/@forestadmin.datasource-toolkit#filtercomponents-1) | #### Defined in [packages/datasource-toolkit/src/interfaces/query/filter/unpaginated.ts:31](https://github.com/ForestAdmin/agent-nodejs/blob/39d6ac7/packages/datasource-toolkit/src/interfaces/query/filter/unpaginated.ts#L31) ``` -------------------------------- ### Get Form Schema Source: https://github.com/forestadmin/agent-nodejs/wiki/@forestadmin.datasource-sequelize.SequelizeCollection Retrieves the form schema for the collection, which defines the fields and their properties for creating or editing records. This method is inherited from the BaseCollection. ```APIDOC ## GET /api/forms ### Description Retrieves the form schema for the collection. ### Method GET ### Endpoint /api/forms ``` -------------------------------- ### ConditionTreeBranch Constructor Source: https://github.com/forestadmin/agent-nodejs/wiki/@forestadmin.datasource-toolkit.ConditionTreeBranch Initializes a new instance of the ConditionTreeBranch class. ```APIDOC ## new ConditionTreeBranch(aggregator, conditions) ### Description Initializes a new instance of the `ConditionTreeBranch` class. ### Parameters #### Parameters - **aggregator** (Aggregator) - The aggregator to use for this branch. - **conditions** (ConditionTree[]) - An array of `ConditionTree` nodes that form the conditions within this branch. ### Overrides `ConditionTree.constructor` ``` -------------------------------- ### Agent Methods Source: https://github.com/forestadmin/agent-nodejs/wiki/@forestadmin.agent.default This section details the core methods available on the ForestAdmin agent instance for managing data sources, customizing collections, and controlling the agent's lifecycle. ```APIDOC ## POST /api/agent/addDatasource ### Description Add a datasource to the ForestAdmin agent. ### Method POST ### Endpoint /api/agent/addDatasource ### Parameters #### Request Body - **datasource** (DataSource) - Required - The datasource configuration object to add. ### Response #### Success Response (200) - **agent** (default) - The updated agent instance. ### Request Example ```json { "datasource": { "name": "my_db", "type": "postgres", "host": "localhost", "port": 5432, "database": "mydb", "user": "user", "password": "password" } } ``` ### Response Example ```json { "agent": "[Agent Instance]" } ``` ``` ```APIDOC ## POST /api/agent/customizeCollection ### Description Allow to interact with a decorated collection. This method enables customization of specific collections within the ForestAdmin agent. ### Method POST ### Endpoint /api/agent/customizeCollection ### Parameters #### Request Body - **name** (string) - Required - The name of the collection to manipulate. - **handle** (function) - Required - A function that provides a collection builder on the given collection name. This function receives the collection builder as an argument. ### Request Example ```javascript agent.customizeCollection('books', books => books.renameField('oldName', 'newName')) ``` ### Response #### Success Response (200) - **agent** (default) - The updated agent instance. ### Response Example ```json { "agent": "[Agent Instance]" } ``` ``` ```APIDOC ## POST /api/agent/start ### Description Start the ForestAdmin agent. ### Method POST ### Endpoint /api/agent/start ### Response #### Success Response (200) - **message** (string) - Indicates that the agent has started successfully. ### Response Example ```json { "message": "Agent started successfully." } ``` ``` ```APIDOC ## POST /api/agent/stop ### Description Stop the ForestAdmin agent gracefully. ### Method POST ### Endpoint /api/agent/stop ### Response #### Success Response (200) - **message** (string) - Indicates that the agent has stopped successfully. ### Response Example ```json { "message": "Agent stopped gracefully." } ``` ``` -------------------------------- ### ConditionTreeLeaf Constructor Source: https://github.com/forestadmin/agent-nodejs/wiki/@forestadmin.datasource-toolkit.ConditionTreeLeaf Initializes a new instance of the ConditionTreeLeaf class. ```APIDOC ## new ConditionTreeLeaf(field, operator, value?) ### Description Constructs a new ConditionTreeLeaf. ### Parameters #### Path Parameters - **field** (string) - Required - The field to apply the condition to. - **operator** (string) - Required - The operator to use for the condition. Must be one of the allowed operator strings. - **value** (unknown) - Optional - The value to compare against the field. ### Request Example ```json { "field": "name", "operator": "Contains", "value": "John" } ``` ### Response #### Success Response (200) - **ConditionTreeLeaf** (object) - An instance of the ConditionTreeLeaf class. #### Response Example ```json { "field": "name", "operator": "Contains", "value": "John" } ``` ``` -------------------------------- ### Array.slice Method Source: https://github.com/forestadmin/agent-nodejs/wiki/@forestadmin.datasource-toolkit.Projection The slice method returns a shallow copy of a portion of an array into a new array object. It accepts optional start and end indices, which can be negative to indicate offsets from the end of the array. ```APIDOC ## slice ### Description Returns a copy of a section of an array. For both start and end, a negative index can be used to indicate an offset from the end of the array. ### Method `slice` ### Parameters - **start** (`number`) - Optional - The beginning index of the specified portion of the array. If start is undefined, then the slice begins at index 0. - **end** (`number`) - Optional - The end index of the specified portion of the array. This is exclusive of the element at the index 'end'. If end is undefined, then the slice extends to the end of the array. ### Returns `string[]` - A new array containing the selected elements. ### Inherited from `Array.slice` ### Defined in `node_modules/typescript/lib/lib.es5.d.ts:1328` ``` -------------------------------- ### ConditionTreeFactory Methods Source: https://github.com/forestadmin/agent-nodejs/wiki/@forestadmin.datasource-toolkit.ConditionTreeFactory Provides static methods for creating and combining ConditionTree objects. ```APIDOC ## Static Methods ### `constructor()` Initializes a new instance of ConditionTreeFactory. ### `MatchAll` Represents a ConditionTree that matches all records. Static property. ### `MatchNone` Represents a ConditionTree that matches no records. Static property. ### `fromPlainObject(json: GenericTree): ConditionTree` Creates a ConditionTree from a plain JavaScript object. #### Parameters - `json` (GenericTree) - The plain object representation of the ConditionTree. #### Returns - `ConditionTree` - The constructed ConditionTree object. ### `intersect(...trees: ConditionTree[]): ConditionTree` Creates a new ConditionTree that is the intersection of the provided trees. #### Parameters - `...trees` (ConditionTree[]) - An array of ConditionTree objects to intersect. #### Returns - `ConditionTree` - A new ConditionTree representing the intersection. ### `matchIds(schema: CollectionSchema, ids: CompositeId[]): ConditionTree` Creates a ConditionTree that matches records with the specified IDs. #### Parameters - `schema` (CollectionSchema) - The schema of the collection. - `ids` (CompositeId[]) - An array of composite IDs to match. #### Returns - `ConditionTree` - A new ConditionTree matching the specified IDs. ### `matchRecords(schema: CollectionSchema, records: RecordData[]): ConditionTree` Creates a ConditionTree that matches the specified records. #### Parameters - `schema` (CollectionSchema) - The schema of the collection. - `records` (RecordData[]) - An array of records to match. #### Returns - `ConditionTree` - A new ConditionTree matching the specified records. ### `union(...trees: ConditionTree[]): ConditionTree` Creates a new ConditionTree that is the union of the provided trees. #### Parameters - `...trees` (ConditionTree[]) - An array of ConditionTree objects to union. #### Returns - `ConditionTree` - A new ConditionTree representing the union. ``` -------------------------------- ### DataSourceDecorator Constructor Source: https://github.com/forestadmin/agent-nodejs/wiki/@forestadmin.datasource-toolkit.DataSourceDecorator Initializes a new instance of the DataSourceDecorator class. It takes a child data source and a collection decorator constructor as arguments. ```APIDOC ## new DataSourceDecorator(childDataSource, CollectionDecoratorCtor) ### Description Initializes a new instance of the DataSourceDecorator class. ### Parameters #### Path Parameters None #### Query Parameters None #### Request Body None ### Parameters - **childDataSource** (DataSource) - The underlying data source to decorate. - **CollectionDecoratorCtor** (CollectionDecoratorConstructor) - The constructor for the collection decorator. ### Request Example ```json { "childDataSource": "...", "CollectionDecoratorCtor": "..." } ``` ### Response #### Success Response (200) None (Constructor) #### Response Example None ``` -------------------------------- ### Array Access Methods Source: https://github.com/forestadmin/agent-nodejs/wiki/@forestadmin.datasource-toolkit.Projection Documentation for array access methods inherited from Array. ```APIDOC ## GET /at ### Description Retrieves an item from the array at a specified index, supporting both positive and negative integers for indexing. ### Method GET ### Endpoint /at ### Parameters #### Query Parameters - **index** (number) - Required - The integer index of the item to retrieve. Negative integers count from the end of the array. ### Response #### Success Response (200) - **string** - The item at the specified index. ### Response Example ```json "example_string" ``` ``` ```APIDOC ## GET /entries ### Description Returns an iterable of key-value pairs for each entry in the array. ### Method GET ### Endpoint /entries ### Returns `IterableIterator<[number, string]>` - An iterator yielding pairs of index and value. ### Response Example ```json { "value": [0, "example_string"], "done": false } ``` ``` -------------------------------- ### Array.forEach Source: https://github.com/forestadmin/agent-nodejs/wiki/@forestadmin.datasource-toolkit.Projection Performs the specified action for each element in an array. ```APIDOC ## forEach ### Description Performs the specified action for each element in an array. ### Method forEach ### Parameters #### Path Parameters - `callbackfn` (function) - Required - A function that accepts up to three arguments. forEach calls the callbackfn function one time for each element in the array. - `thisArg` (any) - Optional - An object to which the this keyword can refer in the callbackfn function. If thisArg is omitted, undefined is used as the this value. ### Returns `void` ### Inherited from Array.forEach ### Defined in node_modules/typescript/lib/lib.es5.d.ts:1404 ``` -------------------------------- ### Condition Tree Node Methods Source: https://github.com/forestadmin/agent-nodejs/wiki/@forestadmin.datasource-toolkit.ConditionTreeLeaf Documentation for core methods of the ConditionTree node, including applying conditions, iterating over leaves, inverting conditions, matching records, and nesting conditions. ```APIDOC ## Methods ### apply ▸ **apply**(`records`, `collection`, `timezone`): [`RecordData`](../wiki/@forestadmin.datasource-toolkit#recorddata-1)[] #### Parameters | Name | Type | | :------ | :------ | | `records` | [`RecordData`](../wiki/@forestadmin.datasource-toolkit#recorddata-1)[] | | `collection` | [`Collection`](../wiki/@forestadmin.datasource-toolkit.Collection) | | `timezone` | `string` | #### Returns [`RecordData`](../wiki/@forestadmin.datasource-toolkit#recorddata-1)[] #### Inherited from [ConditionTree](../wiki/@forestadmin.datasource-toolkit.ConditionTree).[apply](../wiki/@forestadmin.datasource-toolkit.ConditionTree#apply-1) #### Defined in [packages/datasource-toolkit/src/interfaces/query/condition-tree/nodes/base.ts:32](https://github.com/ForestAdmin/agent-nodejs/blob/39d6ac7/packages/datasource-toolkit/src/interfaces/query/condition-tree/nodes/base.ts#L32) --- ### everyLeaf ▸ **everyLeaf**(`handler`): `boolean` #### Parameters | Name | Type | | :------ | :------ | | `handler` | [`LeafTester`](../wiki/@forestadmin.datasource-toolkit#leaftester-1) | #### Returns `boolean` #### Overrides [ConditionTree](../wiki/@forestadmin.datasource-toolkit.ConditionTree).[everyLeaf](../wiki/@forestadmin.datasource-toolkit.ConditionTree#everyleaf-1) #### Defined in [packages/datasource-toolkit/src/interfaces/query/condition-tree/nodes/leaf.ts:52](https://github.com/ForestAdmin/agent-nodejs/blob/39d6ac7/packages/datasource-toolkit/src/interfaces/query/condition-tree/nodes/leaf.ts#L52) --- ### forEachLeaf ▸ **forEachLeaf**(`handler`): `void` #### Parameters | Name | Type | | :------ | :------ | | `handler` | [`LeafCallback`](../wiki/@forestadmin.datasource-toolkit#leafcallback-1) | #### Returns `void` #### Overrides [ConditionTree](../wiki/@forestadmin.datasource-toolkit.ConditionTree).[forEachLeaf](../wiki/@forestadmin.datasource-toolkit.ConditionTree#foreachleaf-1) #### Defined in [packages/datasource-toolkit/src/interfaces/query/condition-tree/nodes/leaf.ts:48](https://github.com/ForestAdmin/agent-nodejs/blob/39d6ac7/packages/datasource-toolkit/src/interfaces/query/condition-tree/nodes/leaf.ts#L48) --- ### inverse ▸ **inverse**(): [`ConditionTree`](../wiki/@forestadmin.datasource-toolkit.ConditionTree) #### Returns [`ConditionTree`](../wiki/@forestadmin.datasource-toolkit.ConditionTree) #### Overrides [ConditionTree](../wiki/@forestadmin.datasource-toolkit.ConditionTree).[inverse](../wiki/@forestadmin.datasource-toolkit.ConditionTree#inverse-1) #### Defined in [packages/datasource-toolkit/src/interfaces/query/condition-tree/nodes/leaf.ts:60](https://github.com/ForestAdmin/agent-nodejs/blob/39d6ac7/packages/datasource-toolkit/src/interfaces/query/condition-tree/nodes/leaf.ts#L60) --- ### match ▸ **match**(`record`, `collection`, `timezone`): `boolean` #### Parameters | Name | Type | | :------ | :------ | | `record` | [`RecordData`](../wiki/@forestadmin.datasource-toolkit#recorddata-1) | | `collection` | [`Collection`](../wiki/@forestadmin.datasource-toolkit.Collection) | | `timezone` | `string` | #### Returns `boolean` #### Overrides [ConditionTree](../wiki/@forestadmin.datasource-toolkit.ConditionTree).[match](../wiki/@forestadmin.datasource-toolkit.ConditionTree#match-1) #### Defined in [packages/datasource-toolkit/src/interfaces/query/condition-tree/nodes/leaf.ts:91](https://github.com/ForestAdmin/agent-nodejs/blob/39d6ac7/packages/datasource-toolkit/src/interfaces/query/condition-tree/nodes/leaf.ts#L91) --- ### nest ▸ **nest**(`prefix`): [`ConditionTree`](../wiki/@forestadmin.datasource-toolkit.ConditionTree) #### Parameters | Name | Type | | :------ | :------ | | `prefix` | `string` | #### Returns [`ConditionTree`](../wiki/@forestadmin.datasource-toolkit.ConditionTree) #### Inherited from [ConditionTree](../wiki/@forestadmin.datasource-toolkit.ConditionTree).[nest](../wiki/@forestadmin.datasource-toolkit.ConditionTree#nest-1) ``` -------------------------------- ### createAgent Function Source: https://github.com/forestadmin/agent-nodejs/wiki/@forestadmin.agent Initializes and returns a new Forest Admin agent instance with the provided options. ```APIDOC ## POST /forest/agent ### Description Creates and configures a Forest Admin agent instance. ### Method POST ### Endpoint `/forest/agent` ### Parameters #### Request Body - **options** (`AgentOptions`) - Required - An object containing the configuration options for the agent, as defined in the `AgentOptions` type. ### Request Example ```json { "authSecret": "YOUR_AUTH_SECRET", "envSecret": "YOUR_ENV_SECRET", "isProduction": true, "forestServerUrl": "https://my-forest-server.com", "loggerLevel": "info" } ``` ### Response #### Success Response (200) - **agent** (`Agent`) - The initialized Forest Admin agent instance. #### Response Example ```json { "agent": { /* Agent instance details */ } } ``` ### Defined in `packages/agent/src/index.ts:10` ``` -------------------------------- ### Array.forEach Method Source: https://github.com/forestadmin/agent-nodejs/wiki/@forestadmin.datasource-toolkit.Sort Performs the specified action for each element in an array. ```APIDOC ## forEach ### Description Performs the specified action for each element in an array. ### Method `forEach` ### Parameters #### Path Parameters - None #### Query Parameters - None #### Request Body - None ### Parameters - **callbackfn** (`value`: { `ascending`: `boolean` ; `field`: `string` }, `index`: `number`, `array`: { `ascending`: `boolean` ; `field`: `string` }[]) => `void` - Required - A function that accepts up to three arguments. forEach calls the callbackfn function one time for each element in the array. - **thisArg?** (`any`) - Optional - An object to which the this keyword can refer in the callbackfn function. If thisArg is omitted, undefined is used as the this value. ### Request Example ```json { "example": "Not applicable for this method." } ``` ### Response #### Success Response (200) - **void** - This method does not return a value. #### Response Example ```json { "example": "No response body." } ``` ``` -------------------------------- ### SearchCollectionDecorator Constructor Source: https://github.com/forestadmin/agent-nodejs/wiki/@forestadmin.datasource-toolkit.SearchCollectionDecorator Initializes a new instance of the SearchCollectionDecorator class. ```APIDOC ## new SearchCollectionDecorator(childCollection, dataSource) ### Description Initializes a new instance of the `SearchCollectionDecorator` class. ### Parameters #### Path Parameters - **childCollection** (Collection) - Required - The child collection to decorate. - **dataSource** (DataSource) - Required - The data source associated with the collection. ``` -------------------------------- ### ActionCollectionDecorator Constructor Source: https://github.com/forestadmin/agent-nodejs/wiki/@forestadmin.datasource-toolkit.ActionCollectionDecorator Initializes a new instance of the ActionCollectionDecorator class. ```APIDOC ## ActionCollectionDecorator Constructor ### Description Initializes a new instance of the `ActionCollectionDecorator` class. ### Parameters #### Parameters - **childCollection** (`Collection`) - The child collection to decorate. - **dataSource** (`DataSource`) - The data source associated with this collection. ```