-
Notifications
You must be signed in to change notification settings - Fork 2
Expand file tree
/
Copy pathindex.d.ts
More file actions
276 lines (237 loc) · 7.02 KB
/
index.d.ts
File metadata and controls
276 lines (237 loc) · 7.02 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
// TypeScript definitions for node-es-transformer
// Project: https://github.com/walterra/node-es-transformer
// Definitions by: Walter Rafelsberger <https://github.com/walterra>
/// <reference types="node" />
import { Client as ElasticsearchClient } from 'es9';
import { ClientOptions } from 'es9';
import { MappingProperty } from 'es9/lib/api/types';
import { QueryDslQueryContainer } from 'es9/lib/api/types';
import { Readable } from 'stream';
import { EventEmitter } from 'events';
/**
* Elasticsearch mapping properties
*/
export interface Mappings {
properties: Record<string, MappingProperty>;
}
/**
* Transform function context (optional second parameter)
*/
export interface TransformContext {
fileName?: string;
}
/**
* CSV parser options (subset of csv-parse options plus passthrough support)
*/
export interface CsvOptions {
delimiter?: string;
quote?: string;
escape?: string;
columns?: boolean | string[] | ((header: string[]) => string[]);
bom?: boolean;
trim?: boolean;
skip_empty_lines?: boolean;
from_line?: number;
[key: string]: any;
}
/**
* Mapping inference options for _text_structure/find_structure
*/
export interface InferMappingsOptions {
sampleBytes?: number;
lines_to_sample?: number;
timeout?: string;
charset?: string;
delimiter?: string;
quote?: string;
has_header_row?: boolean;
[key: string]: any;
}
/**
* Transform function that processes each document
* @param doc - The source document
* @param context - Optional context information
* @returns Transformed document(s), or null/undefined to skip
*/
export type TransformFunction = (
doc: any,
context?: TransformContext
) => any | any[] | null | undefined;
/**
* Optional logger interface (Pino-compatible)
*/
export interface TransformerLogger {
trace?: (obj: unknown, msg?: string, ...args: any[]) => void;
debug?: (obj: unknown, msg?: string, ...args: any[]) => void;
info?: (obj: unknown, msg?: string, ...args: any[]) => void;
warn?: (obj: unknown, msg?: string, ...args: any[]) => void;
error?: (obj: unknown, msg?: string, ...args: any[]) => void;
fatal?: (obj: unknown, msg?: string, ...args: any[]) => void;
child?: (bindings: Record<string, unknown>) => TransformerLogger;
}
/**
* Configuration options for node-es-transformer
*/
export interface TransformerOptions {
/**
* Target Elasticsearch index name (required)
*/
targetIndexName: string;
/**
* Delete the target index if it exists before starting
* @default false
*/
deleteIndex?: boolean;
/**
* Pre-instantiated Elasticsearch client for source operations
* If provided, sourceClientConfig is ignored
*/
sourceClient?: ElasticsearchClient;
/**
* Pre-instantiated Elasticsearch client for target operations
* If not provided, uses sourceClient or creates from sourceClientConfig
*/
targetClient?: ElasticsearchClient;
/**
* Elasticsearch client configuration for source operations
* @default { node: 'http://localhost:9200' }
*/
sourceClientConfig?: ClientOptions;
/**
* Elasticsearch client configuration for target operations
* If not provided, uses sourceClientConfig
* @default { node: 'http://localhost:9200' }
*/
targetClientConfig?: ClientOptions;
/**
* Force specific Elasticsearch client version for source (8 or 9)
* If not provided, version is auto-detected
*/
sourceClientVersion?: 8 | 9;
/**
* Force specific Elasticsearch client version for target (8 or 9)
* If not provided, version is auto-detected
*/
targetClientVersion?: 8 | 9;
/**
* Buffer size threshold in KBytes for bulk indexing
* @default 5120
*/
bufferSize?: number;
/**
* Number of documents to fetch per search request when reindexing
* @default 100
*/
searchSize?: number;
/**
* Source filename to ingest (supports wildcards)
* Cannot be used with sourceIndexName or stream
*/
fileName?: string;
/**
* Node.js readable stream to ingest from
* Cannot be used with fileName or sourceIndexName
*/
stream?: Readable;
/**
* Source format for file/stream ingestion
* @default 'ndjson'
*/
sourceFormat?: 'ndjson' | 'csv' | 'parquet' | 'arrow';
/**
* CSV parser options when sourceFormat is 'csv'
*/
csvOptions?: CsvOptions;
/**
* Regular expression to split lines in file/stream
* Used only when sourceFormat is 'ndjson'
* @default /\n/
*/
splitRegex?: RegExp;
/**
* Source Elasticsearch index name to reindex from
* Cannot be used with fileName or stream
*/
sourceIndexName?: string;
/**
* Elasticsearch document mappings for the target index
* If reindexing and not provided, mappings are copied from source index
*/
mappings?: Mappings;
/**
* Apply mappings on top of source index mappings when reindexing
* @default false
*/
mappingsOverride?: boolean;
/**
* Infer mappings for file sources via _text_structure/find_structure
* Supported for sourceFormat 'ndjson' and 'csv' only
* Ignored when mappings is explicitly provided
* If inference returns an ingest pipeline and pipeline is not explicitly set,
* the inferred pipeline is created and applied as default index pipeline.
* @default false
*/
inferMappings?: boolean;
/**
* Options for mapping inference via _text_structure/find_structure
*/
inferMappingsOptions?: InferMappingsOptions;
/**
* Field limit for target index (index.mapping.total_fields.limit setting)
*/
indexMappingTotalFieldsLimit?: number;
/**
* Ingest pipeline name to use during indexing
*/
pipeline?: string;
/**
* Fetch sample documents to identify which fields are actually populated
* Useful for optimizing indices with many mapped but unused fields
* @default false
*/
populatedFields?: boolean;
/**
* Elasticsearch query to filter documents from source index
*/
query?: QueryDslQueryContainer;
/**
* Skip header line for file/stream ingestion
* - NDJSON: skips the first non-empty line
* - CSV: skips the first data line only when csvOptions.columns does not consume headers
* - Parquet/Arrow: ignored
* @default false
*/
skipHeader?: boolean;
/**
* Transform function to modify documents during ingestion
*/
transform?: TransformFunction;
/**
* Enable verbose logging and progress bars when using the default logger.
* If LOG_LEVEL is set, that level takes precedence.
* @default true
*/
verbose?: boolean;
/**
* Optional custom logger (Pino-compatible). If not provided, an internal
* Pino logger is created.
*/
logger?: TransformerLogger;
}
/**
* Result returned by the transformer function
*/
export interface TransformerResult {
/**
* Event emitter for monitoring ingestion progress
* Events: 'queued', 'indexed', 'complete', 'error'
*/
events: EventEmitter;
}
/**
* Main transformer function
* @param options - Configuration options
* @returns Promise that resolves when ingestion is complete
*/
declare function transformer(options: TransformerOptions): Promise<TransformerResult>;
export default transformer;