@devisfuture/mega-collection 2.4.1 → 2.4.3
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/README.md +1 -75
- package/package.json +1 -1
package/README.md
CHANGED
|
@@ -9,7 +9,6 @@ If this package saved you some time, a ⭐ on GitHub would be much appreciated.
|
|
|
9
9
|
## Table of Contents
|
|
10
10
|
|
|
11
11
|
- [What does this package solve](#what-does-this-package-solve) – what problem this package helps with
|
|
12
|
-
- [Features](#features) – what the package can do
|
|
13
12
|
- [How it works](#how-it-works) – plain-English explanation of how each engine works internally
|
|
14
13
|
- [Benchmarks](#benchmarks) – performance numbers and how to run them
|
|
15
14
|
- [React demo](#react-demo) – example project and live demo
|
|
@@ -33,8 +32,6 @@ If this package saved you some time, a ⭐ on GitHub would be much appreciated.
|
|
|
33
32
|
- [`TextSearchEngine<T>`](#textsearchenginet-search-module) – engine for text search
|
|
34
33
|
- [`FilterEngine<T>`](#filterenginet-filter-module) – engine for filtering
|
|
35
34
|
- [`SortEngine<T>`](#sortenginet-sort-module) – engine for sorting
|
|
36
|
-
- [Types](#types) – TypeScript types you can import
|
|
37
|
-
- [Build](#build) – commands for build and development
|
|
38
35
|
- [Contributing](#contributing) – contribution rules
|
|
39
36
|
- [Security](#security) – security policy
|
|
40
37
|
- [License](#license) – license information
|
|
@@ -62,17 +59,6 @@ Each engine has its own entry point: `/search`, `/filter`, `/sort`.
|
|
|
62
59
|
If you import only `@devisfuture/mega-collection/search`, only search code goes into the bundle.
|
|
63
60
|
Unused modules are not included.
|
|
64
61
|
|
|
65
|
-
## Features
|
|
66
|
-
|
|
67
|
-
| Capability | Strategy | Complexity |
|
|
68
|
-
| ---------------------------- | ------------------------------------------ | ---------------------------------- |
|
|
69
|
-
| **Indexed filter** | Hash-Map index (`Map<value, T[]>`) | **O(1)** |
|
|
70
|
-
| **Multi-value filter** | Index intersection + `Set` membership | **O(k)** indexed / **O(n)** linear |
|
|
71
|
-
| **Nested collection filter** | Pre-built nested index + `Set` lookup | **O(k)** indexed / **O(n)** linear |
|
|
72
|
-
| **Text search** (contains) | N-gram (2–3 chars) inverted index + verify | **O(candidates)** |
|
|
73
|
-
| **Nested collection search** | Nested n-gram index + verify | **O(candidates)** |
|
|
74
|
-
| **Sorting** | Pre-sorted index (cached) / radix sort | **O(n)** cached / **O(n log n)** |
|
|
75
|
-
|
|
76
62
|
## How it works
|
|
77
63
|
|
|
78
64
|
### Search
|
|
@@ -118,13 +104,7 @@ The first sort call builds this index. Subsequent calls just read it in O(n). Th
|
|
|
118
104
|
|
|
119
105
|
## Benchmarks
|
|
120
106
|
|
|
121
|
-
Benchmarks for `TextSearchEngine`, `FilterEngine`, and `SortEngine` are collected in [
|
|
122
|
-
|
|
123
|
-
Run the benchmark scripts locally to regenerate the numbers:
|
|
124
|
-
|
|
125
|
-
- `npm run search-bench`
|
|
126
|
-
- `npm run filter-bench`
|
|
127
|
-
- `npm run sort-bench`
|
|
107
|
+
Benchmarks for `TextSearchEngine`, `FilterEngine`, and `SortEngine` are collected in [BENCHMARKS](./BENCHMARKS.md).
|
|
128
108
|
|
|
129
109
|
## React demo
|
|
130
110
|
|
|
@@ -341,12 +321,6 @@ Use `update(...)` when you need to replace one stored item by a unique field suc
|
|
|
341
321
|
- `update(...)` replaces only the matched item in stored data.
|
|
342
322
|
- configured indexes or caches refresh only the affected item instead of rebuilding the whole dataset.
|
|
343
323
|
|
|
344
|
-
> **Notes on `update()`:**
|
|
345
|
-
>
|
|
346
|
-
> - The lookup field value in `data[field]` must already exist in the stored dataset. If it is `null`, `undefined`, or not found, `update()` is a silent no-op — no error is thrown and no data is changed.
|
|
347
|
-
> - The lookup field value must not change between the old and new item. For example, calling `update({ field: 'id', data: { id: 99, ... } })` when no item has `id: 99` will do nothing. Always use the current value of the lookup field.
|
|
348
|
-
> - When using `FilterEngine` with `filterByPreviousResult: true`, every `update()` resets the sequential criteria cache, so the next `filter()` will re-evaluate from the full dataset.
|
|
349
|
-
|
|
350
324
|
```ts
|
|
351
325
|
import { MergeEngines } from "@devisfuture/mega-collection";
|
|
352
326
|
import { TextSearchEngine } from "@devisfuture/mega-collection/search";
|
|
@@ -690,11 +664,6 @@ One class that combines search, filter, and sort for the same dataset.
|
|
|
690
664
|
| `clearIndexes(module)` | Clear indexes for one module (`"search"`, `"sort"`, `"filter"`) |
|
|
691
665
|
| `clearData(module)` | Clear the shared stored dataset through one imported module (`"search"`, `"sort"`, `"filter"`) |
|
|
692
666
|
|
|
693
|
-
If `filter.mutableExcludeField` is configured, `filter([{ field, exclude }])` on that field removes items from the stored filter dataset with swap-pop.
|
|
694
|
-
This changes the stored filter dataset and does not preserve order.
|
|
695
|
-
|
|
696
|
-
`filter.filterByPreviousResult` is not supported inside `MergeEngines`. Use the root `filterByPreviousResult` option instead.
|
|
697
|
-
|
|
698
667
|
---
|
|
699
668
|
|
|
700
669
|
### `TextSearchEngine<T>` (search module)
|
|
@@ -769,49 +738,6 @@ Sort methods return plain arrays.
|
|
|
769
738
|
|
|
770
739
|
---
|
|
771
740
|
|
|
772
|
-
**Note on `data` method:** Calling `data` updates the stored dataset. It also rebuilds configured indexes and resets internal state when needed, so usually you do not need to call `clearIndexes` before it.
|
|
773
|
-
|
|
774
|
-
## Types
|
|
775
|
-
|
|
776
|
-
All types are exported from the root package and from each sub-module:
|
|
777
|
-
|
|
778
|
-
```ts
|
|
779
|
-
import type {
|
|
780
|
-
CollectionItem,
|
|
781
|
-
IndexableKey,
|
|
782
|
-
FilterCriterion,
|
|
783
|
-
SortDescriptor,
|
|
784
|
-
SortDirection,
|
|
785
|
-
UpdateDescriptor,
|
|
786
|
-
MergeEnginesOptions,
|
|
787
|
-
} from "@devisfuture/mega-collection";
|
|
788
|
-
```
|
|
789
|
-
|
|
790
|
-
You can also import them from individual sub-modules:
|
|
791
|
-
|
|
792
|
-
```ts
|
|
793
|
-
import type {
|
|
794
|
-
CollectionItem,
|
|
795
|
-
IndexableKey,
|
|
796
|
-
} from "@devisfuture/mega-collection/search";
|
|
797
|
-
import type { FilterCriterion } from "@devisfuture/mega-collection/filter";
|
|
798
|
-
import type {
|
|
799
|
-
SortDescriptor,
|
|
800
|
-
SortDirection,
|
|
801
|
-
} from "@devisfuture/mega-collection/sort";
|
|
802
|
-
```
|
|
803
|
-
|
|
804
|
-
---
|
|
805
|
-
|
|
806
|
-
## Build
|
|
807
|
-
|
|
808
|
-
```bash
|
|
809
|
-
npm install
|
|
810
|
-
npm run build # Build ESM + declarations
|
|
811
|
-
npm run typecheck # Type-check without emitting
|
|
812
|
-
npm run dev # Watch mode
|
|
813
|
-
```
|
|
814
|
-
|
|
815
741
|
## Contributing
|
|
816
742
|
|
|
817
743
|
See [CONTRIBUTING.md](CONTRIBUTING.md) for guidelines.
|