1 | /**
|
2 | * ```ts
|
3 | * import type { ArangoSearchView } from "arangojs/view.js";
|
4 | * ```
|
5 | *
|
6 | * The "view" module provides View related types and interfaces for TypeScript.
|
7 | *
|
8 | * @packageDocumentation
|
9 | */
|
10 | import { ArangoApiResponse } from "./connection.js";
|
11 | import { Database } from "./database.js";
|
12 | /**
|
13 | * Indicates whether the given value represents a {@link View}.
|
14 | *
|
15 | * @param view - A value that might be a View.
|
16 | */
|
17 | export declare function isArangoView(view: any): view is View;
|
18 | /**
|
19 | * Sorting direction. Descending or ascending.
|
20 | */
|
21 | export type Direction = "desc" | "asc";
|
22 | /**
|
23 | * Policy to consolidate based on segment byte size and live document count as
|
24 | * dictated by the customization attributes.
|
25 | *
|
26 | * @deprecated The `bytes_accum` consolidation policy was deprecated in
|
27 | * ArangoDB 3.7 and should be replaced with the `tier` consolidation policy.
|
28 | */
|
29 | export type BytesAccumConsolidationPolicy = {
|
30 | /**
|
31 | * Type of consolidation policy.
|
32 | */
|
33 | type: "bytes_accum";
|
34 | /**
|
35 | * Must be in the range of `0.0` to `1.0`.
|
36 | */
|
37 | threshold?: number;
|
38 | };
|
39 | /**
|
40 | * Policy to consolidate if the sum of all candidate segment byte size is less
|
41 | * than the total segment byte size multiplied by a given threshold.
|
42 | */
|
43 | export type TierConsolidationPolicy = {
|
44 | /**
|
45 | * Type of consolidation policy.
|
46 | */
|
47 | type: "tier";
|
48 | /**
|
49 | * Size below which all segments are treated as equivalent.
|
50 | *
|
51 | * Default: `2097152` (2 MiB)
|
52 | */
|
53 | segmentsBytesFloor?: number;
|
54 | /**
|
55 | * Maximum allowed size of all consolidation segments.
|
56 | *
|
57 | * Default: `5368709120` (5 GiB)
|
58 | */
|
59 | segmentsBytesMax?: number;
|
60 | /**
|
61 | * Maximum number of segments that are evaluated as candidates for
|
62 | * consolidation.
|
63 | *
|
64 | * Default: `10`
|
65 | */
|
66 | segmentsMax?: number;
|
67 | /**
|
68 | * Minimum number of segments that are evaluated as candidates for
|
69 | * consolidation.
|
70 | *
|
71 | * Default: `1`
|
72 | */
|
73 | segmentsMin?: number;
|
74 | /**
|
75 | * Consolidation candidates with a score less than this value will be
|
76 | * filtered out.
|
77 | *
|
78 | * Default: `0`
|
79 | */
|
80 | minScore?: number;
|
81 | };
|
82 | /**
|
83 | * Compression for storing data.
|
84 | */
|
85 | export type Compression = "lz4" | "none";
|
86 | /**
|
87 | * Options for creating a View.
|
88 | */
|
89 | export type CreateViewOptions = CreateArangoSearchViewOptions | CreateSearchAliasViewOptions;
|
90 | /**
|
91 | * Options for replacing a View's properties.
|
92 | */
|
93 | export type ViewPropertiesOptions = ArangoSearchViewPropertiesOptions | SearchAliasViewPropertiesOptions;
|
94 | /**
|
95 | * Options for partially modifying a View's properties.
|
96 | */
|
97 | export type ViewPatchPropertiesOptions = ArangoSearchViewPropertiesOptions | SearchAliasViewPatchPropertiesOptions;
|
98 | /**
|
99 | * A link definition for an ArangoSearch View.
|
100 | */
|
101 | export type ArangoSearchViewLinkOptions = {
|
102 | /**
|
103 | * A list of names of Analyzers to apply to values of processed document
|
104 | * attributes.
|
105 | *
|
106 | * Default: `["identity"]`
|
107 | */
|
108 | analyzers?: string[];
|
109 | /**
|
110 | * An object mapping names of attributes to process for each document to
|
111 | * {@link ArangoSearchViewLinkOptions} definitions.
|
112 | */
|
113 | fields?: Record<string, ArangoSearchViewLinkOptions>;
|
114 | /**
|
115 | * If set to `true`, all document attributes will be processed, otherwise
|
116 | * only the attributes in `fields` will be processed.
|
117 | *
|
118 | * Default: `false`
|
119 | */
|
120 | includeAllFields?: boolean;
|
121 | /**
|
122 | * (Enterprise Edition only.) An object mapping attribute names to
|
123 | * {@link ArangoSearchViewLinkOptions} definitions to index sub-objects
|
124 | * stored in an array.
|
125 | */
|
126 | nested?: Record<string, ArangoSearchViewLinkOptions>;
|
127 | /**
|
128 | * If set to `true`, the position of values in array values will be tracked,
|
129 | * otherwise all values in an array will be treated as equal alternatives.
|
130 | */
|
131 | trackListPositions?: boolean;
|
132 | /**
|
133 | * Controls how the view should keep track of the attribute values.
|
134 | *
|
135 | * Default: `"none"`
|
136 | */
|
137 | storeValues?: "none" | "id";
|
138 | /**
|
139 | * If set to `true`, then no exclusive lock is used on the source collection
|
140 | * during View index creation, so that it remains basically available.
|
141 | *
|
142 | * Default: `false`
|
143 | */
|
144 | inBackground?: boolean;
|
145 | /**
|
146 | * (Enterprise Edition only.) If set to `true`, then field normalization
|
147 | * values will always be cached in memory.
|
148 | *
|
149 | * Default: `false`
|
150 | */
|
151 | cache?: boolean;
|
152 | };
|
153 | /**
|
154 | * Options for modifying the properties of an ArangoSearch View.
|
155 | */
|
156 | export type ArangoSearchViewPropertiesOptions = {
|
157 | /**
|
158 | * How many commits to wait between removing unused files.
|
159 | *
|
160 | * Default: `2`
|
161 | */
|
162 | cleanupIntervalStep?: number;
|
163 | /**
|
164 | * How long to wait between applying the `consolidationPolicy`.
|
165 | *
|
166 | * Default: `10000`
|
167 | */
|
168 | consolidationIntervalMsec?: number;
|
169 | /**
|
170 | * How long to wait between commiting View data store changes and making
|
171 | * documents visible to queries.
|
172 | *
|
173 | * Default: `1000`
|
174 | */
|
175 | commitIntervalMsec?: number;
|
176 | /**
|
177 | * Consolidation policy to apply for selecting which segments should be
|
178 | * merged.
|
179 | *
|
180 | * Default: `{ type: "tier" }`
|
181 | */
|
182 | consolidationPolicy?: TierConsolidationPolicy;
|
183 | /**
|
184 | * An object mapping names of linked collections to
|
185 | * {@link ArangoSearchViewLinkOptions} definitions.
|
186 | */
|
187 | links?: Record<string, Omit<ArangoSearchViewLinkOptions, "nested">>;
|
188 | };
|
189 | /**
|
190 | * Options for partially modifying the properties of an ArangoSearch View.
|
191 | */
|
192 | export type ArangoSearchViewPatchPropertiesOptions = ArangoSearchViewPropertiesOptions;
|
193 | /**
|
194 | * Options for creating a stored value in an ArangoSearch View.
|
195 | */
|
196 | export interface ArangoSearchViewStoredValueOptions {
|
197 | /**
|
198 | * Attribute paths for which values should be stored in the view index
|
199 | * in addition to those used for sorting via `primarySort`.
|
200 | */
|
201 | fields: string[];
|
202 | /**
|
203 | * How the attribute values should be compressed.
|
204 | *
|
205 | * Default: `"lz4"`
|
206 | */
|
207 | compression?: Compression;
|
208 | /**
|
209 | * (Enterprise Edition only.) If set to `true`, then stored values will
|
210 | * always be cached in memory.
|
211 | *
|
212 | * Default: `false`
|
213 | */
|
214 | cache?: boolean;
|
215 | }
|
216 | /**
|
217 | * Options for creating an ArangoSearch View.
|
218 | */
|
219 | export type CreateArangoSearchViewOptions = ArangoSearchViewPropertiesOptions & {
|
220 | /**
|
221 | * Type of the View.
|
222 | */
|
223 | type: "arangosearch";
|
224 | /**
|
225 | * Maximum number of writers cached in the pool.
|
226 | *
|
227 | * Default: `64`
|
228 | */
|
229 | writebufferIdle?: number;
|
230 | /**
|
231 | * Maximum number of concurrent active writers that perform a transaction.
|
232 | *
|
233 | * Default: `0`
|
234 | */
|
235 | writebufferActive?: number;
|
236 | /**
|
237 | * Maximum memory byte size per writer before a writer flush is triggered.
|
238 | *
|
239 | * Default: `33554432` (32 MiB)
|
240 | */
|
241 | writebufferSizeMax?: number;
|
242 | /**
|
243 | * Attribute path (`field`) for the value of each document that will be
|
244 | * used for sorting.
|
245 | *
|
246 | * If `direction` is set to `"asc"` or `asc` is set to `true`,
|
247 | * the primary sorting order will be ascending.
|
248 | *
|
249 | * If `direction` is set to `"desc"` or `asc` is set to `false`,
|
250 | * the primary sorting order will be descending.
|
251 | */
|
252 | primarySort?: ({
|
253 | /**
|
254 | * Attribute path for the value of each document to use for
|
255 | * sorting.
|
256 | */
|
257 | field: string;
|
258 | /**
|
259 | * If set to `"asc"`, the primary sorting order will be ascending.
|
260 | * If set to `"desc"`, the primary sorting order will be descending.
|
261 | */
|
262 | direction: Direction;
|
263 | } | {
|
264 | /**
|
265 | * Attribute path for the value of each document to use for
|
266 | * sorting.
|
267 | */
|
268 | field: string;
|
269 | /**
|
270 | * If set to `true`, the primary sorting order will be ascending.
|
271 | * If set to `false`, the primary sorting order will be descending.
|
272 | */
|
273 | asc: boolean;
|
274 | })[];
|
275 | /**
|
276 | * Compression to use for the primary sort data.
|
277 | *
|
278 | * Default: `"lz4"`
|
279 | */
|
280 | primarySortCompression?: Compression;
|
281 | /**
|
282 | * (Enterprise Edition only.) If set to `true`, then primary sort columns
|
283 | * will always be cached in memory.
|
284 | *
|
285 | * Default: `false`
|
286 | */
|
287 | primarySortCache?: boolean;
|
288 | /**
|
289 | * (Enterprise Edition only.) If set to `true`, then primary key columns
|
290 | * will always be cached in memory.
|
291 | *
|
292 | * Default: `false`
|
293 | */
|
294 | primaryKeyCache?: boolean;
|
295 | /**
|
296 | * Attribute paths for which values should be stored in the view index
|
297 | * in addition to those used for sorting via `primarySort`.
|
298 | */
|
299 | storedValues?: ArangoSearchViewStoredValueOptions[] | string[] | string[][];
|
300 | /**
|
301 | * An array of strings defining sort expressions to optimize.
|
302 | */
|
303 | optimizeTopK?: string[];
|
304 | };
|
305 | /**
|
306 | * Options defining an index used in a SearchAlias View.
|
307 | */
|
308 | export type SearchAliasViewIndexOptions = {
|
309 | /**
|
310 | * Name of a collection.
|
311 | */
|
312 | collection: string;
|
313 | /**
|
314 | * Name of an inverted index in the collection.
|
315 | */
|
316 | index: string;
|
317 | };
|
318 | /**
|
319 | * Options for modifying the properties of a SearchAlias View.
|
320 | */
|
321 | export type SearchAliasViewPropertiesOptions = {
|
322 | /**
|
323 | * An array of inverted indexes to add to the View.
|
324 | */
|
325 | indexes: SearchAliasViewIndexOptions[];
|
326 | };
|
327 | /**
|
328 | * Options defining an index to be modified in a SearchAlias View.
|
329 | */
|
330 | export type SearchAliasViewPatchIndexOptions = SearchAliasViewIndexOptions & {
|
331 | /**
|
332 | * Whether to add or remove the index.
|
333 | *
|
334 | * Default: `"add"`
|
335 | */
|
336 | operation?: "add" | "del";
|
337 | };
|
338 | /**
|
339 | * Options for partially modifying the properties of a SearchAlias View.
|
340 | */
|
341 | export type SearchAliasViewPatchPropertiesOptions = {
|
342 | /**
|
343 | * An array of inverted indexes to add to the View.
|
344 | */
|
345 | indexes: SearchAliasViewPatchIndexOptions[];
|
346 | };
|
347 | /**
|
348 | * Options for creating a SearchAlias View.
|
349 | */
|
350 | export type CreateSearchAliasViewOptions = SearchAliasViewPropertiesOptions & {
|
351 | /**
|
352 | * Type of the View.
|
353 | */
|
354 | type: "search-alias";
|
355 | };
|
356 | /**
|
357 | * Generic description of a View.
|
358 | */
|
359 | export type GenericViewDescription = {
|
360 | /**
|
361 | * A globally unique identifier for this View.
|
362 | */
|
363 | globallyUniqueId: string;
|
364 | /**
|
365 | * An identifier for this View.
|
366 | */
|
367 | id: string;
|
368 | /**
|
369 | * Name of the View.
|
370 | */
|
371 | name: string;
|
372 | };
|
373 | export type ViewDescription = ArangoSearchViewDescription | SearchAliasViewDescription;
|
374 | export type ArangoSearchViewDescription = GenericViewDescription & {
|
375 | type: "arangosearch";
|
376 | };
|
377 | export type SearchAliasViewDescription = GenericViewDescription & {
|
378 | type: "search-alias";
|
379 | };
|
380 | export type ViewProperties = ArangoSearchViewProperties | SearchAliasViewProperties;
|
381 | /**
|
382 | * A link definition for an ArangoSearch View.
|
383 | */
|
384 | export type ArangoSearchViewLink = {
|
385 | analyzers: string[];
|
386 | fields: Record<string, ArangoSearchViewLink>;
|
387 | includeAllFields: boolean;
|
388 | nested?: Record<string, ArangoSearchViewLink>;
|
389 | trackListPositions: boolean;
|
390 | storeValues: "none" | "id";
|
391 | cache: boolean;
|
392 | };
|
393 | /**
|
394 | * Properties of an ArangoSearch View.
|
395 | */
|
396 | export type ArangoSearchViewProperties = ArangoSearchViewDescription & {
|
397 | cleanupIntervalStep: number;
|
398 | consolidationIntervalMsec: number;
|
399 | commitIntervalMsec: number;
|
400 | writebufferIdle: number;
|
401 | writebufferActive: number;
|
402 | writebufferSizeMax: number;
|
403 | consolidationPolicy: TierConsolidationPolicy | BytesAccumConsolidationPolicy;
|
404 | primarySort: {
|
405 | field: string;
|
406 | direction: Direction;
|
407 | }[];
|
408 | primarySortCompression: Compression;
|
409 | primarySortCache: boolean;
|
410 | primaryKeyCache: boolean;
|
411 | storedValues: {
|
412 | fields: string[];
|
413 | compression: Compression;
|
414 | cache: boolean;
|
415 | }[];
|
416 | links: Record<string, Omit<ArangoSearchViewLink, "nested">>;
|
417 | optimizeTopK: string[];
|
418 | };
|
419 | /**
|
420 | * Properties of a SearchAlias View.
|
421 | */
|
422 | export type SearchAliasViewProperties = SearchAliasViewDescription & {
|
423 | indexes: {
|
424 | collection: string;
|
425 | index: string;
|
426 | }[];
|
427 | };
|
428 | /**
|
429 | * Represents a View in a {@link database.Database}.
|
430 | */
|
431 | export declare class View {
|
432 | protected _name: string;
|
433 | protected _db: Database;
|
434 | /**
|
435 | * @internal
|
436 | */
|
437 | constructor(db: Database, name: string);
|
438 | /**
|
439 | * @internal
|
440 | *
|
441 | * Indicates that this object represents an ArangoDB View.
|
442 | */
|
443 | get isArangoView(): true;
|
444 | /**
|
445 | * Name of the View.
|
446 | */
|
447 | get name(): string;
|
448 | /**
|
449 | * Retrieves general information about the View.
|
450 | *
|
451 | * @example
|
452 | * ```js
|
453 | * const db = new Database();
|
454 | * const view = db.view("some-view");
|
455 | * const data = await view.get();
|
456 | * // data contains general information about the View
|
457 | * ```
|
458 | */
|
459 | get(): Promise<ArangoApiResponse<ViewDescription>>;
|
460 | /**
|
461 | * Checks whether the View exists.
|
462 | *
|
463 | * @example
|
464 | * ```js
|
465 | * const db = new Database();
|
466 | * const view = db.view("some-view");
|
467 | * const exists = await view.exists();
|
468 | * console.log(exists); // indicates whether the View exists
|
469 | * ```
|
470 | */
|
471 | exists(): Promise<boolean>;
|
472 | /**
|
473 | * Creates a View with the given `options` and the instance's name.
|
474 | *
|
475 | * See also { database.Database#createView}.
|
476 | *
|
477 | *
|
478 | * ```js
|
479 | * const db = new Database();
|
480 | * const view = db.view("potatoes");
|
481 | * await view.create();
|
482 | * // the ArangoSearch View "potatoes" now exists
|
483 | * ```
|
484 | */
|
485 | create<Options extends CreateViewOptions>(options: CreateViewOptions): Promise<typeof options extends CreateArangoSearchViewOptions ? ArangoSearchViewDescription : Options extends CreateSearchAliasViewOptions ? SearchAliasViewDescription : ViewDescription>;
|
486 | /**
|
487 | * Renames the View and updates the instance's `name` to `newName`.
|
488 | *
|
489 | * Additionally removes the instance from the {@link database.Database}'s internal
|
490 | * cache.
|
491 | *
|
492 | * **Note**: Renaming Views may not be supported when ArangoDB is
|
493 | * running in a cluster configuration.
|
494 | *
|
495 | * @param newName - The new name of the View.
|
496 | *
|
497 | * @example
|
498 | * ```js
|
499 | * const db = new Database();
|
500 | * const view1 = db.view("some-view");
|
501 | * await view1.rename("other-view");
|
502 | * const view2 = db.view("some-view");
|
503 | * const view3 = db.view("other-view");
|
504 | * // Note all three View instances are different objects but
|
505 | * // view1 and view3 represent the same ArangoDB view!
|
506 | * ```
|
507 | */
|
508 | rename(newName: string): Promise<ArangoApiResponse<ViewDescription>>;
|
509 | /**
|
510 | * Retrieves the View's properties.
|
511 | *
|
512 | * @example
|
513 | * ```js
|
514 | * const db = new Database();
|
515 | * const view = db.view("some-view");
|
516 | * const data = await view.properties();
|
517 | * // data contains the View's properties
|
518 | * ```
|
519 | */
|
520 | properties(): Promise<ArangoApiResponse<ViewProperties>>;
|
521 | /**
|
522 | * Updates the properties of the View.
|
523 | *
|
524 | * @param properties - Properties of the View to update.
|
525 | *
|
526 | * @example
|
527 | * ```js
|
528 | * const db = new Database();
|
529 | * const view = db.view("some-view");
|
530 | * const result = await view.updateProperties({
|
531 | * consolidationIntervalMsec: 234
|
532 | * });
|
533 | * console.log(result.consolidationIntervalMsec); // 234
|
534 | * ```
|
535 | */
|
536 | updateProperties<Properties extends ViewPatchPropertiesOptions | undefined>(properties?: Properties): Promise<Properties extends ArangoSearchViewPatchPropertiesOptions ? ArangoSearchViewProperties : Properties extends SearchAliasViewPatchPropertiesOptions ? SearchAliasViewProperties : ViewProperties>;
|
537 | /**
|
538 | * Replaces the properties of the View.
|
539 | *
|
540 | * @param properties - New properties of the View.
|
541 | *
|
542 | * @example
|
543 | * ```js
|
544 | * const db = new Database();
|
545 | * const view = db.view("some-view");
|
546 | * const result = await view.replaceProperties({
|
547 | * consolidationIntervalMsec: 234
|
548 | * });
|
549 | * console.log(result.consolidationIntervalMsec); // 234
|
550 | * ```
|
551 | */
|
552 | replaceProperties<Properties extends ViewPropertiesOptions | undefined>(properties?: Properties): Promise<Properties extends ArangoSearchViewPropertiesOptions ? ArangoSearchViewProperties : Properties extends SearchAliasViewPropertiesOptions ? SearchAliasViewProperties : ViewProperties>;
|
553 | /**
|
554 | * Deletes the View from the database.
|
555 | *
|
556 | * @example
|
557 | *
|
558 | * ```js
|
559 | * const db = new Database();
|
560 | * const view = db.view("some-view");
|
561 | * await view.drop();
|
562 | * // the View "some-view" no longer exists
|
563 | * ```
|
564 | */
|
565 | drop(): Promise<boolean>;
|
566 | }
|
567 | //# sourceMappingURL=view.d.ts.map |
\ | No newline at end of file |