1 | import { DataInterface, DataInterfaceForEachOptions, DataInterfaceGetIdsOptions, DataInterfaceGetOptions, DataInterfaceGetOptionsArray, DataInterfaceGetOptionsObject, DataInterfaceMapOptions, DeepPartial, FullItem, Id, PartItem, UpdateItem } from "./data-interface";
|
2 | import { Queue, QueueOptions } from "./queue";
|
3 | import { DataSetPart } from "./data-set-part";
|
4 | import { DataStream } from "./data-stream";
|
5 |
|
6 |
|
7 |
|
8 |
|
9 |
|
10 | export interface DataSetInitialOptions<IdProp extends string> {
|
11 | |
12 |
|
13 |
|
14 | fieldId?: IdProp;
|
15 | |
16 |
|
17 |
|
18 |
|
19 |
|
20 | queue?: QueueOptions | false;
|
21 | }
|
22 |
|
23 | export interface DataSetOptions {
|
24 | |
25 |
|
26 |
|
27 |
|
28 |
|
29 |
|
30 | queue?: Queue | QueueOptions | false;
|
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 | export declare class DataSet<Item extends PartItem<IdProp>, IdProp extends string = "id"> extends DataSetPart<Item, IdProp> implements DataInterface<Item, IdProp> {
|
92 |
|
93 | flush?: () => void;
|
94 |
|
95 | length: number;
|
96 |
|
97 | get idProp(): IdProp;
|
98 | private readonly _options;
|
99 | private readonly _data;
|
100 | private readonly _idProp;
|
101 | private _queue;
|
102 | |
103 |
|
104 |
|
105 | constructor(options?: DataSetInitialOptions<IdProp>);
|
106 | /**
|
107 | * @param data - An initial set of items for the new instance.
|
108 | * @param options - DataSet configuration.
|
109 | */
|
110 | constructor(data: Item[], options?: DataSetInitialOptions<IdProp>);
|
111 | /**
|
112 | * Set new options.
|
113 | *
|
114 | * @param options - The new options.
|
115 | */
|
116 | setOptions(options?: DataSetOptions): void;
|
117 | /**
|
118 | * Add a data item or an array with items.
|
119 | *
|
120 | * After the items are added to the DataSet, the DataSet will trigger an event `add`. When a `senderId` is provided, this id will be passed with the triggered event to all subscribers.
|
121 | *
|
122 | * ## Example
|
123 | *
|
124 | * ```javascript
|
125 | * // create a DataSet
|
126 | * const data = new vis.DataSet()
|
127 | *
|
128 | * // add items
|
129 | * const ids = data.add([
|
130 | * { id: 1, text: 'item 1' },
|
131 | * { id: 2, text: 'item 2' },
|
132 | * { text: 'item without an id' }
|
133 | * ])
|
134 | *
|
135 | * console.log(ids) // [1, 2, '<UUIDv4>']
|
136 | * ```
|
137 | *
|
138 | * @param data - Items to be added (ids will be generated if missing).
|
139 | * @param senderId - Sender id.
|
140 | * @returns addedIds - Array with the ids (generated if not present) of the added items.
|
141 | * @throws When an item with the same id as any of the added items already exists.
|
142 | */
|
143 | add(data: Item | Item[], senderId?: Id | null): (string | number)[];
|
144 | /**
|
145 | * Update existing items. When an item does not exist, it will be created.
|
146 | *
|
147 | * @remarks
|
148 | * The provided properties will be merged in the existing item. When an item does not exist, it will be created.
|
149 | *
|
150 | * After the items are updated, the DataSet will trigger an event `add` for the added items, and an event `update`. When a `senderId` is provided, this id will be passed with the triggered event to all subscribers.
|
151 | *
|
152 | * ## Example
|
153 | *
|
154 | * ```javascript
|
155 | * // create a DataSet
|
156 | * const data = new vis.DataSet([
|
157 | * { id: 1, text: 'item 1' },
|
158 | * { id: 2, text: 'item 2' },
|
159 | * { id: 3, text: 'item 3' }
|
160 | * ])
|
161 | *
|
162 | * // update items
|
163 | * const ids = data.update([
|
164 | * { id: 2, text: 'item 2 (updated)' },
|
165 | * { id: 4, text: 'item 4 (new)' }
|
166 | * ])
|
167 | *
|
168 | * console.log(ids) // [2, 4]
|
169 | * ```
|
170 | *
|
171 | * ## Warning for TypeScript users
|
172 | * This method may introduce partial items into the data set. Use add or updateOnly instead for better type safety.
|
173 | * @param data - Items to be updated (if the id is already present) or added (if the id is missing).
|
174 | * @param senderId - Sender id.
|
175 | * @returns updatedIds - The ids of the added (these may be newly generated if there was no id in the item from the data) or updated items.
|
176 | * @throws When the supplied data is neither an item nor an array of items.
|
177 | */
|
178 | update(data: DeepPartial<Item> | DeepPartial<Item>[], senderId?: Id | null): Id[];
|
179 | /**
|
180 | * Update existing items. When an item does not exist, an error will be thrown.
|
181 | *
|
182 | * @remarks
|
183 | * The provided properties will be deeply merged into the existing item.
|
184 | * When an item does not exist (id not present in the data set or absent), an error will be thrown and nothing will be changed.
|
185 | *
|
186 | * After the items are updated, the DataSet will trigger an event `update`.
|
187 | * When a `senderId` is provided, this id will be passed with the triggered event to all subscribers.
|
188 | *
|
189 | * ## Example
|
190 | *
|
191 | * ```javascript
|
192 | * // create a DataSet
|
193 | * const data = new vis.DataSet([
|
194 | * { id: 1, text: 'item 1' },
|
195 | * { id: 2, text: 'item 2' },
|
196 | * { id: 3, text: 'item 3' },
|
197 | * ])
|
198 | *
|
199 | * // update items
|
200 | * const ids = data.update([
|
201 | * { id: 2, text: 'item 2 (updated)' },
|
202 | *
|
203 | *
|
204 | * ])
|
205 | *
|
206 | * console.log(ids) // [2]
|
207 | * ```
|
208 | * @param data - Updates (the id and optionally other props) to the items in this data set.
|
209 | * @param senderId - Sender id.
|
210 | * @returns updatedIds - The ids of the updated items.
|
211 | * @throws When the supplied data is neither an item nor an array of items, when the ids are missing.
|
212 | */
|
213 | updateOnly(data: UpdateItem<Item, IdProp> | UpdateItem<Item, IdProp>[], senderId?: Id | null): Id[];
|
214 | /** @inheritDoc */
|
215 | get(): FullItem<Item, IdProp>[];
|
216 | /** @inheritDoc */
|
217 | get(options: DataInterfaceGetOptionsArray<Item>): FullItem<Item, IdProp>[];
|
218 | /** @inheritDoc */
|
219 | get(options: DataInterfaceGetOptionsObject<Item>): Record<Id, FullItem<Item, IdProp>>;
|
220 | /** @inheritDoc */
|
221 | get(options: DataInterfaceGetOptions<Item>): FullItem<Item, IdProp>[] | Record<Id, FullItem<Item, IdProp>>;
|
222 | /** @inheritDoc */
|
223 | get(id: Id): null | FullItem<Item, IdProp>;
|
224 | /** @inheritDoc */
|
225 | get(id: Id, options: DataInterfaceGetOptionsArray<Item>): null | FullItem<Item, IdProp>;
|
226 | /** @inheritDoc */
|
227 | get(id: Id, options: DataInterfaceGetOptionsObject<Item>): Record<Id, FullItem<Item, IdProp>>;
|
228 | /** @inheritDoc */
|
229 | get(id: Id, options: DataInterfaceGetOptions<Item>): null | FullItem<Item, IdProp> | Record<Id, FullItem<Item, IdProp>>;
|
230 | /** @inheritDoc */
|
231 | get(ids: Id[]): FullItem<Item, IdProp>[];
|
232 | /** @inheritDoc */
|
233 | get(ids: Id[], options: DataInterfaceGetOptionsArray<Item>): FullItem<Item, IdProp>[];
|
234 | /** @inheritDoc */
|
235 | get(ids: Id[], options: DataInterfaceGetOptionsObject<Item>): Record<Id, FullItem<Item, IdProp>>;
|
236 | /** @inheritDoc */
|
237 | get(ids: Id[], options: DataInterfaceGetOptions<Item>): FullItem<Item, IdProp>[] | Record<Id, FullItem<Item, IdProp>>;
|
238 | /** @inheritDoc */
|
239 | get(ids: Id | Id[], options?: DataInterfaceGetOptions<Item>): null | FullItem<Item, IdProp> | FullItem<Item, IdProp>[] | Record<Id, FullItem<Item, IdProp>>;
|
240 | /** @inheritDoc */
|
241 | getIds(options?: DataInterfaceGetIdsOptions<Item>): Id[];
|
242 | /** @inheritDoc */
|
243 | getDataSet(): DataSet<Item, IdProp>;
|
244 | /** @inheritDoc */
|
245 | forEach(callback: (item: Item, id: Id) => void, options?: DataInterfaceForEachOptions<Item>): void;
|
246 | /** @inheritDoc */
|
247 | map<T>(callback: (item: Item, id: Id) => T, options?: DataInterfaceMapOptions<Item, T>): T[];
|
248 | private _filterFields;
|
249 | /**
|
250 | * Sort the provided array with items.
|
251 | *
|
252 | * @param items - Items to be sorted in place.
|
253 | * @param order - A field name or custom sort function.
|
254 | * @typeParam T - The type of the items in the items array.
|
255 | */
|
256 | private _sort;
|
257 | /**
|
258 | * Remove an item or multiple items by “reference” (only the id is used) or by id.
|
259 | *
|
260 | * The method ignores removal of non-existing items, and returns an array containing the ids of the items which are actually removed from the DataSet.
|
261 | *
|
262 | * After the items are removed, the DataSet will trigger an event `remove` for the removed items. When a `senderId` is provided, this id will be passed with the triggered event to all subscribers.
|
263 | *
|
264 | * ## Example
|
265 | * ```javascript
|
266 | * // create a DataSet
|
267 | * const data = new vis.DataSet([
|
268 | * { id: 1, text: 'item 1' },
|
269 | * { id: 2, text: 'item 2' },
|
270 | * { id: 3, text: 'item 3' }
|
271 | * ])
|
272 | *
|
273 | * // remove items
|
274 | * const ids = data.remove([2, { id: 3 }, 4])
|
275 | *
|
276 | * console.log(ids) // [2, 3]
|
277 | * ```
|
278 | *
|
279 | * @param id - One or more items or ids of items to be removed.
|
280 | * @param senderId - Sender id.
|
281 | * @returns The ids of the removed items.
|
282 | */
|
283 | remove(id: Id | Item | (Id | Item)[], senderId?: Id | null): Id[];
|
284 | /**
|
285 | * Remove an item by its id or reference.
|
286 | *
|
287 | * @param id - Id of an item or the item itself.
|
288 | * @returns The removed item if removed, null otherwise.
|
289 | */
|
290 | private _remove;
|
291 | /**
|
292 | * Clear the entire data set.
|
293 | *
|
294 | * After the items are removed, the {@link DataSet} will trigger an event `remove` for all removed items. When a `senderId` is provided, this id will be passed with the triggered event to all subscribers.
|
295 | *
|
296 | * @param senderId - Sender id.
|
297 | * @returns removedIds - The ids of all removed items.
|
298 | */
|
299 | clear(senderId?: Id | null): Id[];
|
300 | /**
|
301 | * Find the item with maximum value of a specified field.
|
302 | *
|
303 | * @param field - Name of the property that should be searched for max value.
|
304 | * @returns Item containing max value, or null if no items.
|
305 | */
|
306 | max(field: keyof Item): Item | null;
|
307 | /**
|
308 | * Find the item with minimum value of a specified field.
|
309 | *
|
310 | * @param field - Name of the property that should be searched for min value.
|
311 | * @returns Item containing min value, or null if no items.
|
312 | */
|
313 | min(field: keyof Item): Item | null;
|
314 | distinct<T extends keyof Item>(prop: T): Item[T][];
|
315 | distinct(prop: string): unknown[];
|
316 | /**
|
317 | * Add a single item. Will fail when an item with the same id already exists.
|
318 | *
|
319 | * @param item - A new item to be added.
|
320 | * @returns Added item's id. An id is generated when it is not present in the item.
|
321 | */
|
322 | private _addItem;
|
323 | /**
|
324 | * Update a single item: merge with existing item.
|
325 | * Will fail when the item has no id, or when there does not exist an item with the same id.
|
326 | *
|
327 | * @param update - The new item
|
328 | * @returns The id of the updated item.
|
329 | */
|
330 | private _updateItem;
|
331 | /** @inheritDoc */
|
332 | stream(ids?: Iterable<Id>): DataStream<Item>;
|
333 | get testLeakData(): Map<Id, FullItem<Item, IdProp>>;
|
334 | get testLeakIdProp(): IdProp;
|
335 | get testLeakOptions(): DataSetInitialOptions<IdProp>;
|
336 | get testLeakQueue(): Queue<this> | null;
|
337 | set testLeakQueue(v: Queue<this> | null);
|
338 | }
|
339 | //# sourceMappingURL=data-set.d.ts.map |
\ | No newline at end of file |