UNPKG

2.3 kBTypeScriptView Raw
1import { DeepPartial, SeederCollection, LogFn } from './common';
2import { SeederCollectionReadingOptions, SeederConfig } from './config';
3export * from './config';
4export * from './helpers';
5/**
6 * Allows to seed database. It is a main Mongo Seeding class.
7 */
8export declare class Seeder {
9 /**
10 * Transformer functions for collections before data import.
11 */
12 static Transformers: {
13 replaceDocumentIdWithUnderscoreId: (collection: SeederCollection) => SeederCollection;
14 setCreatedAtTimestamp: (collection: SeederCollection) => SeederCollection;
15 setUpdatedAtTimestamp: (collection: SeederCollection) => SeederCollection;
16 };
17 /**
18 * Logger instance
19 */
20 log: LogFn;
21 /**
22 * Configuration for seeding database.
23 */
24 config: SeederConfig;
25 /**
26 * Constructs a new `Seeder` instance and loads configuration for data import.
27 *
28 * @param config Optional partial object with database seeding configuration. The object is merged with the default configuration object. To use all default settings, simply omit this parameter.
29 */
30 constructor(config?: DeepPartial<SeederConfig>);
31 /**
32 * Populates collections and their documents from given path.
33 * The path has to contain file structure described on https://github.com/pkosiec/mongo-seeding/blob/main/docs/import-data-definition.md.
34 *
35 * @param path File path
36 * @param partialConfig Optional partial collection reading configuration object. It is merged with default configuration object. To use all default settings, simply omit this parameter.
37 */
38 readCollectionsFromPath: (path: string, partialConfig?: DeepPartial<SeederCollectionReadingOptions> | undefined) => SeederCollection[];
39 /**
40 * Connects to a database and imports all collections.
41 *
42 * @param collections Array of collection definitions
43 * @param partialConfig Optional partial configuration object. Ita allows to change the database seeding configuration for single data import. It is merged with default configuration object. To use the configuration provided in `Seeder` constructor, simply omit this parameter.
44 */
45 import: (collections: SeederCollection[], partialConfig?: DeepPartial<SeederConfig> | undefined) => Promise<void>;
46}