Skip to content

Commit

Permalink
feat: use the agent to create typings (#1021)
Browse files Browse the repository at this point in the history
* feat: use the agent to create typings

* test: fix test

---------

Co-authored-by: Nicolas Moreau <nicolas.moreau76@gmail.com>
  • Loading branch information
realSpok and Nicolas Moreau committed Feb 19, 2024
1 parent 2cdbd18 commit 663dec1
Show file tree
Hide file tree
Showing 2 changed files with 28 additions and 0 deletions.
12 changes: 12 additions & 0 deletions packages/agent/src/agent.ts
Original file line number Diff line number Diff line change
Expand Up @@ -109,6 +109,18 @@ export default class Agent<S extends TSchema = TSchema> extends FrameworkMounter
return this;
}

/**
* Update the typings files generated from your datasources
* @param typingsPath the path at which to write the new file
* @param typingsMaxDepth the max depth of relation typings
* @see {@link https://docs.forestadmin.com/developer-guide-agents-nodejs/getting-started/install/autocompletion-and-typings Documentation Link}
*/
async updateTypesOnFileSystem(typingsPath: string, typingsMaxDepth: number): Promise<void> {
const { logger } = this.options;
await this.customizer.getDataSource(logger);
this.customizer.updateTypesOnFileSystem(typingsPath, typingsMaxDepth);
}

/**
* Create a new API chart
* @param name name of the chart
Expand Down
16 changes: 16 additions & 0 deletions packages/agent/test/agent.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -25,6 +25,7 @@ const mockCustomizer = {
addChart: jest.fn(),
customizeCollection: jest.fn(),
updateTypesOnFileSystem: jest.fn(),
getDataSource: jest.fn(),
use: jest.fn(),
getFactory: jest.fn(),
removeCollection: jest.fn(),
Expand Down Expand Up @@ -309,4 +310,19 @@ describe('Agent', () => {
expect(options.forestAdminClient.close).toHaveBeenCalledTimes(1);
});
});

describe('updateTypesOnFileSystem', () => {
test('should write/update the typings file if apimap has changed', async () => {
const options = factories.forestAdminHttpDriverOptions.build();
const agent = new Agent(options);

await agent.updateTypesOnFileSystem('the/path/to/typings.d.ts', 42);

expect(mockCustomizer.getDataSource).toHaveBeenCalledOnceWith(options.logger);
expect(mockCustomizer.updateTypesOnFileSystem).toHaveBeenCalledOnceWith(
'the/path/to/typings.d.ts',
42,
);
});
});
});

0 comments on commit 663dec1

Please sign in to comment.